Пример #1
0
        public static Room ToLadybugTools(this Space space, BuildingModel buildingModel, double silverSpacing = Core.Tolerance.MacroDistance, double tolerance = Core.Tolerance.Distance)
        {
            if (space == null || buildingModel == null)
            {
                return(null);
            }

            List <Face> faces = null;

            List <IPartition> partitions = buildingModel.OrientedPartitions(space, false, silverSpacing, tolerance);

            if (partitions != null)
            {
                faces = new List <Face>();
                foreach (IPartition partition in partitions)
                {
                    Face face = partition?.ToLadybugTools_Face(buildingModel, space);
                    if (face == null)
                    {
                        continue;
                    }

                    faces.Add(face);
                }
            }

            string uniqueName = Core.LadybugTools.Query.UniqueName(space);

            RoomPropertiesAbridged roomPropertiesAbridged = new RoomPropertiesAbridged();

            Room result = new Room(uniqueName, faces, roomPropertiesAbridged, space.Name);

            InternalCondition internalCondition = space.InternalCondition;

            if (internalCondition != null)
            {
                string uniqueName_InternalCondition = Core.LadybugTools.Query.UniqueName(internalCondition);
                if (!string.IsNullOrWhiteSpace(uniqueName_InternalCondition))
                {
                    roomPropertiesAbridged = result.Properties;
                    RoomEnergyPropertiesAbridged roomEnergyPropertiesAbridged = roomPropertiesAbridged.Energy;
                    if (roomEnergyPropertiesAbridged == null)
                    {
                        roomEnergyPropertiesAbridged = new RoomEnergyPropertiesAbridged(programType: uniqueName_InternalCondition);
                    }

                    result.Properties.Energy = roomEnergyPropertiesAbridged;
                }
            }

            return(result);
        }
        public static Brep SetRoomEnergyProperties(Brep roomBrep, RoomEnergyPropertiesAbridged roomEnergyProperties)
        {
            var geo = roomBrep.DuplicateBrep();
            var ent = geo.TryGetRoomEntity();

            if (!ent.IsValid)
            {
                throw new ArgumentException("Non valid honeybee room brep!");
            }

            ent.SetEnergyProp(roomEnergyProperties);
            return(geo);
        }
        public void updateRoomPanel(RoomEntity hbObjEntity)
        {
            var room   = hbObjEntity.HBObject;
            var layout = new DynamicLayout {
            };

            layout.Spacing        = new Size(5, 5);
            layout.Padding        = new Padding(10);
            layout.DefaultSpacing = new Size(2, 2);


            layout.AddSeparateRow(new Label {
                Text = $"ID: {room.Name}"
            });

            layout.AddSeparateRow(new Label {
                Text = "Name:"
            });
            var modelNameTextBox = new TextBox()
            {
            };

            room.DisplayName = room.DisplayName ?? string.Empty;
            modelNameTextBox.TextBinding.Bind(room, m => m.DisplayName);
            layout.AddSeparateRow(modelNameTextBox);


            layout.AddSeparateRow(new Label {
                Text = "Properties:"
            });
            var rmPropBtn = new Button {
                Text = "Room Energy Properties"
            };

            rmPropBtn.Click += (s, e) => RmPropBtn_Click(hbObjEntity);
            layout.AddSeparateRow(rmPropBtn);


            var facesListBox = new ListBox();

            facesListBox.Height = 120;
            var faces = hbObjEntity.HBFaces;

            if (faces != null)
            {
                var faceItems = faces.Select(_ => new ListItem()
                {
                    Text = _.DisplayName ?? _.Name, Tag = _
                });
                facesListBox.Items.AddRange(faceItems);
            }
            layout.AddSeparateRow(new Label {
                Text = $"Faces: (total: {room.Faces.Count})"
            });
            layout.AddSeparateRow(facesListBox);


            layout.AddSeparateRow(new Label {
                Text = "IndoorShades:"
            });
            var inShadesListBox = new ListBox();

            inShadesListBox.Height = 50;
            var inShds = room.IndoorShades;

            if (inShds != null)
            {
                var idShds = inShds.Select(_ => new ListItem()
                {
                    Text = _.DisplayName ?? _.Name, Tag = _
                });
                inShadesListBox.Items.AddRange(idShds);
            }
            layout.AddSeparateRow(inShadesListBox);

            layout.AddSeparateRow(new Label {
                Text = "OutdoorShades:"
            });
            var outShadesListBox = new ListBox();

            outShadesListBox.Height = 50;
            var outShds = room.OutdoorShades;

            if (outShds != null)
            {
                var outShdItems = outShds.Select(_ => new ListItem()
                {
                    Text = _.DisplayName ?? _.Name, Tag = _
                });
                outShadesListBox.Items.AddRange(outShdItems);
            }
            layout.AddSeparateRow(outShadesListBox);


            layout.AddSeparateRow(new Label {
                Text = "Multiplier:"
            });
            var multiplierNum = new NumericMaskedTextBox <int>()
            {
            };

            multiplierNum.TextBinding.Bind(Binding.Delegate(() => room.Multiplier.ToString(), v => room.Multiplier = CheckIfNum(v)));
            int CheckIfNum(string numString)
            {
                var isNum = int.TryParse(numString, out int numValue);

                return(isNum ? numValue : 0);
            }

            layout.AddSeparateRow(multiplierNum);



            layout.Add(null);
            var data_button = new Button {
                Text = "Honeybee Data"
            };

            data_button.Click += (sender, e) => Dialogs.ShowEditBox("Honeybee Data", "Honeybee Data can be shared across all platforms.", room.ToJson(), true, out string outJson);
            layout.AddSeparateRow(data_button, null);


            this.Content = layout;
            //layout.up

            void RmPropBtn_Click(Entities.RoomEntity roomEnt)
            {
                var roomEnergyProperties = RoomEnergyPropertiesAbridged.FromJson(roomEnt.GetEnergyProp().ToJson());
                var dialog = new UI.Dialog_RoomEnergyProperty(roomEnergyProperties);

                dialog.RestorePosition();
                var dialog_rc = dialog.ShowModal(RhinoEtoApp.MainWindow);

                dialog.SavePosition();
                if (dialog_rc != null)
                {
                    //replace brep in order to add an undo history
                    var undo = Rhino.RhinoDoc.ActiveDoc.BeginUndoRecord("Set Honeybee room energy properties");

                    var dup = roomEnt.HostObjRef.Brep().DuplicateBrep();
                    dup.TryGetRoomEntity().HBObject.Properties.Energy = dialog_rc;
                    Rhino.RhinoDoc.ActiveDoc.Objects.Replace(roomEnt.HostObjRef.ObjectId, dup);

                    Rhino.RhinoDoc.ActiveDoc.EndUndoRecord(undo);
                }
            }
        }
Пример #4
0
        public static Room ToLadybugTools(this Space space, AnalyticalModel analyticalModel = null, double silverSpacing = Core.Tolerance.MacroDistance, double tolerance = Core.Tolerance.Distance)
        {
            if (space == null)
            {
                return(null);
            }

            int          index  = -1;
            List <Panel> panels = null;

            AdjacencyCluster adjacencyCluster = analyticalModel?.AdjacencyCluster;

            if (adjacencyCluster != null)
            {
                index  = adjacencyCluster.GetIndex(space);
                panels = adjacencyCluster.UpdateNormals(space, false, silverSpacing, tolerance);
            }

            if (panels == null || panels.Count == 0)
            {
                return(null);
            }

            string uniqueName = Query.UniqueName(space);

            List <Face> faces = null;

            if (panels != null)
            {
                faces = new List <Face>();
                foreach (Panel panel in panels)
                {
                    if (panel == null)
                    {
                        continue;
                    }

                    bool reverse = true;

                    List <Space> spaces = adjacencyCluster?.GetSpaces(panel);
                    if (spaces != null && spaces.Count > 1)
                    {
                        reverse = adjacencyCluster.GetIndex(spaces[0]) != index;
                    }

                    Face face = panel.ToLadybugTools_Face(analyticalModel, index, reverse);
                    if (face == null)
                    {
                        continue;
                    }

                    faces.Add(face);
                }
            }

            RoomPropertiesAbridged roomPropertiesAbridged = new RoomPropertiesAbridged();

            Room result = new Room(uniqueName, faces, roomPropertiesAbridged, space.Name);

            InternalCondition internalCondition = space.InternalCondition;

            if (internalCondition != null)
            {
                string uniqueName_InternalCondition = Core.LadybugTools.Query.UniqueName(internalCondition);
                if (!string.IsNullOrWhiteSpace(uniqueName_InternalCondition))
                {
                    roomPropertiesAbridged = result.Properties;
                    RoomEnergyPropertiesAbridged roomEnergyPropertiesAbridged = roomPropertiesAbridged.Energy;
                    if (roomEnergyPropertiesAbridged == null)
                    {
                        roomEnergyPropertiesAbridged = new RoomEnergyPropertiesAbridged(programType: uniqueName_InternalCondition);
                    }

                    result.Properties.Energy = roomEnergyPropertiesAbridged;
                }
            }

            return(result);
        }
Пример #5
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
#if RELEASE
            Rhino.UI.Dialogs.ShowMessage("Good try, I have disabled this. This is only used for development!", "Honeybee");
            return(Result.Failure);
#endif


            var rc = Result.Cancel;
            RoomEnergyPropertiesAbridged roomEnergyProperties = new RoomEnergyPropertiesAbridged();

            if (mode == RunMode.Interactive)
            {
                var dialog = new UI.Dialog_RoomEnergyProperty(roomEnergyProperties);
                dialog.RestorePosition();
                var dialog_rc = dialog.ShowSemiModal(doc, RhinoEtoApp.MainWindow);
                dialog.SavePosition();
                if (dialog_rc != null)
                {
                    roomEnergyProperties = dialog_rc;
                    rc = Result.Success;
                }
            }
            else
            {
                var msg = string.Format($"Scriptable version of {EnglishName} command not implemented.");
                RhinoApp.WriteLine(msg);
            }

            if (roomEnergyProperties == null)
            {
                RhinoApp.WriteLine("No valid room energy property was set!");
                return(Result.Nothing);
            }

            //Get honeybee rooms
            using (var go = new GetObject())
            {
                go.SetCommandPrompt("Please select Honeybee Rooms to set its energy properties");

                go.GeometryFilter = ObjectType.Brep;
                go.GetMultiple(1, 0);
                if (go.CommandResult() != Result.Success)
                {
                    return(go.CommandResult());
                }

                if (go.ObjectCount == 0)
                {
                    return(Result.Nothing);
                }

                //get all Room Entities.
                var roomEnts = go.Objects().Select(_ => _.Geometry().TryGetRoomEntity()).Where(_ => _.IsValid);
                if (go.Objects().Length > roomEnts.Count())
                {
                    RhinoApp.WriteLine("Some selected geometries are not Honeybee room, please use MassToRoom to create rooms first!");
                    return(Result.Failure);
                }

                //Assign program types
                foreach (var item in go.Objects())
                {
                    var geo = item.Brep();
                    geo = HoneybeeRhino.SetRoomEnergyProperties(geo, roomEnergyProperties);
                    doc.Objects.Replace(item.ObjectId, geo);
                }

                doc.Views.Redraw();
                return(Result.Success);
            }
        }