public void updateFacePanel(FaceEntity hbObjEntity) { var face = 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: {face.Name}" }); layout.AddSeparateRow(new Label { Text = "Name:" }); var nameTBox = new TextBox() { }; face.DisplayName = face.DisplayName ?? string.Empty; nameTBox.TextBinding.Bind(face, m => m.DisplayName); layout.AddSeparateRow(nameTBox); layout.AddSeparateRow(new Label { Text = "Face Type:" }); var terrainTypeDP = new EnumDropDown <Face.FaceTypeEnum>(); terrainTypeDP.SelectedValueBinding.Bind(Binding.Delegate(() => face.FaceType, v => face.FaceType = v)); layout.AddSeparateRow(terrainTypeDP); layout.AddSeparateRow(new Label { Text = "Boundary Condition: (WIP)" }); var bcTBox = new TextBox() { }; bcTBox.Enabled = false; bcTBox.TextBinding.Bind(face, m => m.BoundaryCondition.Obj.GetType().Name); layout.AddSeparateRow(bcTBox); layout.AddSeparateRow(new Label { Text = "Properties:" }); var faceRadPropBtn = new Button { Text = "Radiance Properties (WIP)" }; faceRadPropBtn.Click += (s, e) => Dialogs.ShowMessage("Work in progress", "Honeybee"); layout.AddSeparateRow(faceRadPropBtn); var faceEngPropBtn = new Button { Text = "Energy Properties" }; faceEngPropBtn.Click += (s, e) => FacePropBtn_Click(hbObjEntity); layout.AddSeparateRow(faceEngPropBtn); var apertureLBox = new ListBox(); apertureLBox.Height = 100; var apertures = hbObjEntity.ApertureObjRefsWithoutHistory; var faceCount = 0; if (apertures.Any()) { var validApertures = apertures; faceCount = validApertures.Count(); //Check if displace name is null, in case this hb object is not created from rhino. var faceItems = validApertures.Select(_ => _.TryGetApertureEntity().HBObject).Select(_ => new ListItem() { Text = _.DisplayName ?? _.Name, Tag = _ }); apertureLBox.Items.AddRange(faceItems); } layout.AddSeparateRow(new Label { Text = $"Apertures: (total: {faceCount})" }); layout.AddSeparateRow(apertureLBox); var doorLBox = new ListBox(); doorLBox.Height = 50; var doors = hbObjEntity.DoorObjRefsWithoutHistory; if (doors.Any()) { //Check if displace name is null, in case this hb object is not created from rhino. var faceItems = doors.Select(_ => _.TryGetDoorEntity().HBObject).Select(_ => new ListItem() { Text = _.DisplayName ?? _.Name, Tag = _ }); doorLBox.Items.AddRange(faceItems); } layout.AddSeparateRow(new Label { Text = $"Doors:" }); layout.AddSeparateRow(doorLBox); layout.AddSeparateRow(new Label { Text = "IndoorShades:" }); var inShadesListBox = new ListBox(); inShadesListBox.Height = 50; var inShds = face.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 = face.OutdoorShades; if (outShds != null) { var outShdItems = outShds.Select(_ => new ListItem() { Text = _.DisplayName ?? _.Name, Tag = _ }); outShadesListBox.Items.AddRange(outShdItems); } layout.AddSeparateRow(outShadesListBox); 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.", face.ToJson(), true, out string outJson); layout.AddSeparateRow(data_button, null); this.Content = layout; //layout.up void FacePropBtn_Click(Entities.FaceEntity ent) { var energyProp = ent.HBObject.Properties.Energy ?? new FaceEnergyPropertiesAbridged(); energyProp = FaceEnergyPropertiesAbridged.FromJson(energyProp.ToJson()); var dialog = new UI.Dialog_FaceEnergyProperty(energyProp); 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 face energy properties"); //Dup entire room for replacement var dupRoomHost = ent.RoomHostObjRef.Brep().DuplicateBrep(); //get face entity with subsurface component index var dupEnt = dupRoomHost.Faces[ent.ComponentIndex.Index].TryGetFaceEntity(); //update properties dupEnt.HBObject.Properties.Energy = dialog_rc; Rhino.RhinoDoc.ActiveDoc.Objects.Replace(ent.RoomHostObjRef.ObjectId, dupRoomHost); Rhino.RhinoDoc.ActiveDoc.EndUndoRecord(undo); } } }
public static Face ToLadybugTools_Face(this Panel panel, AnalyticalModel analyticalModel = null, int index = -1, bool reverse = true) { if (panel == null || panel.PanelType == PanelType.Shade) { return(null); } Face3D face3D = panel.PlanarBoundary3D.ToLadybugTools(); if (face3D == null) { return(null); } AdjacencyCluster adjacencyCluster = analyticalModel?.AdjacencyCluster; Space space_Adjacent = null; int index_Adjacent = -1; if (adjacencyCluster != null && index != -1) { List <Space> spaces = adjacencyCluster.GetSpaces(panel); if (spaces != null && spaces.Count != 0) { foreach (Space space in spaces) { int index_Temp = adjacencyCluster.GetIndex(space); if (!index_Temp.Equals(index)) { space_Adjacent = space; index_Adjacent = index_Temp; break; } } } } string adjacentPanelUniqueName = null; string adjacentSpaceUniqueName = null; if (space_Adjacent != null && index_Adjacent != -1) { adjacentPanelUniqueName = Query.UniqueName(panel, index_Adjacent); adjacentSpaceUniqueName = Query.UniqueName(space_Adjacent); } AnyOf <Ground, Outdoors, Adiabatic, Surface> boundaryCondition = panel.ToLadybugTools_BoundaryCondition(adjacentPanelUniqueName, adjacentSpaceUniqueName); FaceType faceType; PanelType panelType = panel.PanelType; PanelGroup panelGroup = panelType.PanelGroup(); if (panelGroup == PanelGroup.Floor && Analytical.Query.PanelType(panel.Normal) == PanelType.Roof) { faceType = FaceType.RoofCeiling; } else { faceType = Query.FaceTypeEnum(panelType); } FaceEnergyPropertiesAbridged faceEnergyPropertiesAbridged = new FaceEnergyPropertiesAbridged(); if (faceType != FaceType.AirBoundary) { faceEnergyPropertiesAbridged.Construction = Query.UniqueName(panel.Construction, reverse); } Face face = new Face(Query.UniqueName(panel, index), face3D, faceType, boundaryCondition, new FacePropertiesAbridged(faceEnergyPropertiesAbridged), panel.Name); List <Aperture> apertures = panel.Apertures;//Analytical.Query.OffsetAperturesOnEdge(panel, 0.1); if (apertures != null && apertures.Count > 0) { MaterialLibrary materialLibrary = analyticalModel?.MaterialLibrary; face.Apertures = apertures.ConvertAll(x => x.ToLadybugTools(materialLibrary, index, index_Adjacent, adjacentPanelUniqueName, adjacentSpaceUniqueName)).FindAll(x => x != null); face.Doors = apertures.ConvertAll(x => x.ToLadybugTools_Door(materialLibrary, index, index_Adjacent, adjacentPanelUniqueName, adjacentSpaceUniqueName)).FindAll(x => x != null); } return(face); }
public void Test_TestSampleModel() { //var sampleModel = @"D:\Dev\Test\HB\model_energy_shoe_box.json"; var bbox = new BoundingBox(new Point3d(0, 0, 0), new Point3d(10, 10, 3)); var box = new Box(bbox).ToBrep(); var hbFaces = box.Faces.Select(_ => _.ToHBFace(maxRoofFloorAngle: 30)).ToList(); var room = new Room($"Room_{Guid.NewGuid()}", hbFaces, new RoomPropertiesAbridged(energy: new RoomEnergyPropertiesAbridged())); var modelProp = new ModelProperties(energy: ModelEnergyProperties.Default); var stone = new EnergyMaterial( name: "Thick Stone", thickness: 0.3, conductivity: 2.31, density: 2322, specificHeat: 832, roughness: EnergyMaterial.RoughnessEnum.Rough, thermalAbsorptance: 0.95, solarAbsorptance: 0.75, visibleAbsorptance: 0.8 ); modelProp.Energy.Materials.Add(stone); var thermalMassConstr = new OpaqueConstructionAbridged("Thermal Mass Floor", new List <string>() { stone.Name }); modelProp.Energy.Constructions.Add(thermalMassConstr); var faceEnergyProp = new FaceEnergyPropertiesAbridged(); faceEnergyProp.Construction = thermalMassConstr.Name; room.Faces[0].Properties.Energy = faceEnergyProp; var model = new Model( "modelName", modelProp, "a new displace name" ); model.Rooms = new List <HoneybeeSchema.Room>(); model.Rooms.Add(room); var json = model.ToJson(); var modelPath = @"D:\Dev\test\HB\model.json"; File.WriteAllText(modelPath, json); var studyFolder = @"D:\Dev\test\HB"; var simuParPath = @"D:\Dev\test\HB\simPar.json"; Runner.RunOpenStudio(studyFolder, modelPath, simuParPath); //TestContext.WriteLine(room.ToJson()); Assert.AreEqual(room.Faces.Count, 6); }
public static Face ToLadybugTools_Face(this IPartition partition, BuildingModel buildingModel, Space space) { Face3D face3D = Geometry.LadybugTools.Convert.ToLadybugTools(partition?.Face3D); if (face3D == null) { return(null); } FaceType?faceType = partition.FaceType(); if (faceType == null || !faceType.HasValue) { return(null); } int index = -1; int index_Adjacent = -1; bool reverse = true; List <Space> spaces = buildingModel.GetSpaces(partition); if (spaces != null && spaces.Count != 0) { index = spaces.FindIndex(x => x.Guid == space.Guid); index = buildingModel.UniqueIndex(spaces[index]); index_Adjacent = spaces.FindIndex(x => x.Guid != space.Guid); index_Adjacent = buildingModel.UniqueIndex(spaces[index_Adjacent]); reverse = buildingModel.UniqueIndex(spaces[0]) != index; } AnyOf <Ground, Outdoors, Adiabatic, Surface> boundaryCondition = partition.ToLadybugTools_BoundaryCondition(buildingModel, space); FaceEnergyPropertiesAbridged faceEnergyPropertiesAbridged = new FaceEnergyPropertiesAbridged(); if (partition is IHostPartition) { faceEnergyPropertiesAbridged.Construction = Query.UniqueName(((IHostPartition)partition).Type(), reverse); } Face face = new Face(Query.UniqueName(partition, index), face3D, faceType.Value, boundaryCondition, new FacePropertiesAbridged(faceEnergyPropertiesAbridged), partition.Name); if (partition is IHostPartition) { List <IOpening> openings = ((IHostPartition)partition).GetOpenings(); if (openings != null && openings.Count != 0) { List <HoneybeeSchema.Aperture> apertures = new List <HoneybeeSchema.Aperture>(); List <HoneybeeSchema.Door> doors = new List <HoneybeeSchema.Door>(); foreach (IOpening opening in openings) { MaterialType materialType = MaterialType.Opaque; OpeningType openingType = opening.Type(); if (openingType != null) { materialType = buildingModel.GetMaterialType(openingType.PaneMaterialLayers); } if (opening is Window && materialType != MaterialType.Opaque) { HoneybeeSchema.Aperture aperture = ((Window)opening).ToLadybugTools(buildingModel, space); if (aperture != null) { apertures.Add(aperture); } } else { HoneybeeSchema.Door door = opening.ToLadybugTools(buildingModel, space); if (door != null) { doors.Add(door); } } } if (apertures != null && apertures.Count != 0) { face.Apertures = apertures; } if (doors != null && doors.Count != 0) { face.Doors = doors; } } } return(face); }