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);
                }
            }
        }
Пример #2
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);
            }
        }