Beispiel #1
0
        //public static RoomEntity TryGetFrom(RhinoObject obj)
        //{
        //    return TryGetFrom(obj.Geometry);
        //}

        public new static RoomEntity TryGetFrom(Rhino.Geometry.GeometryBase roomGeo)
        {
            var rc = new RoomEntity();

            if (roomGeo == null)
            {
                return(rc);
            }

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

            var ent = roomGeo.UserData.Find(typeof(RoomEntity)) as RoomEntity;

            return(ent == null ? rc : ent);
        }
Beispiel #2
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);
            }
        }
Beispiel #3
0
 public static RoomEntity TryGetRoomEntity(this GeometryBase rhinoRef) => RoomEntity.TryGetFrom(rhinoRef);
Beispiel #4
0
 public static RoomEntity TryGetRoomEntity(this ObjRef rhinoRef) => RoomEntity.TryGetFrom(rhinoRef.Geometry());
Beispiel #5
0
 public void Duplicate(RoomEntity otherRoomEntityToCopyFrom)
 {
     this.OnDuplicate(otherRoomEntityToCopyFrom);
 }