public new static FaceEntity TryGetFrom(GeometryBase rhinoGeo)
        {
            var rc = new FaceEntity();

            if (!rhinoGeo.IsValid)
            {
                return(rc);
            }

            if (rhinoGeo is BrepFace brepFace)
            {
                //var ent = brepFace.Brep.Surfaces[brepFace.SurfaceIndex].UserData.Find(typeof(FaceEntity)) as FaceEntity;
                var ent = brepFace.UnderlyingSurface().TryGetFaceEntity();
                return(ent == null ? rc : ent);
            }
            else if (rhinoGeo is Surface surface)
            {
                var ent = surface.UserData.Find(typeof(FaceEntity)) as FaceEntity;
                return(ent == null ? rc : ent);
            }
            else
            {
                var ent = (rhinoGeo as Rhino.Geometry.Brep).Surfaces[0].UserData.Find(typeof(FaceEntity)) as FaceEntity;
                return(ent == null ? rc : ent);
            }
        }
        //This is used in subselection, in which need to replace entire geometry after property changes
        public static FaceEntity TryGetFrom(ObjRef roomHostObjRef, ComponentIndex componentIndex)
        {
            var roomHostObject = roomHostObjRef.Brep();
            var rc             = new FaceEntity();

            if (roomHostObject == null)
            {
                return(rc);
            }
            if (componentIndex.ComponentIndexType != ComponentIndexType.BrepFace)
            {
                return(rc);
            }

            var face = roomHostObject.Faces[componentIndex.Index];
            var ent  = face.TryGetFaceEntity();

            if (!ent.IsValid)
            {
                return(rc);
            }

            //updates hostObjRef to its room's host
            ent.RoomHostObjRef = roomHostObjRef;
            ent.ComponentIndex = componentIndex;
            return(ent);
        }
 public void UpdateID_CopyFrom(FaceEntity otherFaceEntity)
 {
     if (otherFaceEntity.IsValid)
     {
         this.Duplicate(otherFaceEntity);
         this.HBObject.Name = "Face_" + Guid.NewGuid().ToString();
     }
     else
     {
         //throw new ArgumentNullException("OtherFaceEntity is null");
     }
 }
示例#4
0
 public static FaceEntity TryGetFaceEntity(this Surface rhinoRef) => FaceEntity.TryGetFrom(rhinoRef);
示例#5
0
 public static FaceEntity TryGetFaceEntity(this ObjRef roomHostRef, ComponentIndex componentIndex) => FaceEntity.TryGetFrom(roomHostRef, componentIndex);
示例#6
0
 public static FaceEntity TryGetOrphanedFaceEntity(this ObjRef roomHostRef) => FaceEntity.TryGetFrom(roomHostRef.Geometry());
示例#7
0
        //ObjRef to ObjRef
        public static Brep ToRoomBrepObj(ObjRef roomBrepObj, double maxRoofFloorAngle = 30, double tolerance = 0.0001)
        {
            //check if Null, valid, solid
            if (!CheckIfBrepObjectValid(roomBrepObj))
            {
                throw new ArgumentException("Input geometry is not a valid object to convert to honeybee room!");
            }

            //create new room
            //Create honeybee room object here.
            var closedBrep = roomBrepObj.Brep().DuplicateBrep();
            var dupBrep    = closedBrep.ToAllPlaneBrep(tolerance);
            var subFaces   = dupBrep.Faces;

            var hbFaces = subFaces.Select(_ => _.ToHBFace(maxRoofFloorAngle)).ToList();

            for (int i = 0; i < hbFaces.Count; i++)
            {
                var faceEnt = new FaceEntity(hbFaces[i]);
                var bFace   = dupBrep.Surfaces[i];
                bFace.UserData.Add(faceEnt);
            }

            var id        = roomBrepObj.ObjectId;
            var newObjRef = new ObjRef(id);
            var room      = new HoneybeeSchema.Room($"Room_{id}", hbFaces, new HoneybeeSchema.RoomPropertiesAbridged());

            room.DisplayName = $"My Room {id.ToString().Substring(0, 5)}";
            var ent = new RoomEntity(room, newObjRef);

            //Add this RoomEntity to brep's userdata at the end.
            dupBrep.UserData.Add(ent);


#if DEBUG
            if (!dupBrep.TryGetRoomEntity().IsValid)
            {
                throw new ArgumentException("Failed to convert to honeybee room!");
            }
#endif

            return(dupBrep);


            //Local method
            bool CheckIfBrepObjectValid(ObjRef roomObj)
            {
                if (roomObj == null)
                {
                    throw new NullReferenceException();
                }

                var brep = roomObj.Brep();

                if (brep == null)
                {
                    throw new NullReferenceException();
                }
                if (!brep.IsValid)
                {
                    throw new ArgumentException("Input geometry is not a valid object to convert to honeybee room!");
                }

                if (!brep.IsSolid)
                {
                    throw new ArgumentException("This rhino object is not a water-tight solid!");
                }

                brep.DeleteHBEntity(duplicate: false);

                return(true);
            }
        }
 public void Duplicate(FaceEntity otherFaceEntityToCopyFrom)
 {
     this.OnDuplicate(otherFaceEntityToCopyFrom);
 }