public static TBD.buildingElement ToTAS(this BHE.Panel buildingElement, TBD.buildingElement tbdBuildingElement, TBD.Construction tbdConstruction) { if (buildingElement == null) { return(tbdBuildingElement); } tbdBuildingElement.name = buildingElement.Name; BHP.OriginContextFragment envContextProperties = buildingElement.FindFragment <BHP.OriginContextFragment>(typeof(BHP.OriginContextFragment)); if (envContextProperties != null) { tbdBuildingElement.GUID = envContextProperties.ElementID; tbdBuildingElement.description = envContextProperties.Description; } tbdBuildingElement.BEType = (int)buildingElement.Type.ToTAS(); TBD.Construction construction = buildingElement.Construction.ToTAS(tbdConstruction); tbdBuildingElement.AssignConstruction(construction); return(tbdBuildingElement); //TODO: Make Colour, GUID work for Pushing. Assign Construction. //TODO:Number of BuildingElements on the TAS Building Summary is too high //TODO:BuildingElements are showing up as duplicated in the TAS folder //TODO:What about ApertureType, FeatureShading, SubstituteElement? //BHP.BuildingElementContextProperties BEContextProperties = buildingElement.ContextProperties() as BHP.BuildingElementContextProperties; //if (BEContextProperties != null) /*tbdBuildingElement.colour = BEContextProperties.Colour(); *///BH.Engine.Environment.Query.GetRGB((uint)BEContextProperties.Colour); }
public static BHX.WindowType ToGBXMLWindow(this BHC.Construction construction, BHE.Opening opening) { BHX.WindowType window = new BHX.WindowType(); BHP.PanelAnalyticalFragment extraProperties = opening.FindFragment <BHP.PanelAnalyticalFragment>(typeof(BHP.PanelAnalyticalFragment)); BHP.OriginContextFragment contextProperties = opening.FindFragment <BHP.OriginContextFragment>(typeof(BHP.OriginContextFragment)); window.ID = "window-" + (contextProperties == null ? construction.Name.CleanName() : contextProperties.TypeName.CleanName()); window.Name = (contextProperties == null ? construction.Name : contextProperties.TypeName); window.UValue.Value = (extraProperties == null || extraProperties.UValue == 0 ? construction.UValue().ToString() : extraProperties.UValue.ToString()); window.Transmittance.Value = (extraProperties == null ? "0" : extraProperties.LTValue.ToString()); window.SolarHeatGainCoefficient.Value = (extraProperties == null ? "0" : extraProperties.GValue.ToString()); if (construction.Layers.Count > 0) { window.InternalGlaze = (construction.Layers[0]).ToGBXGlazed(); } if (construction.Layers.Count > 1) { window.Gap = (construction.Layers[1]).ToGBXGap(); } if (construction.Layers.Count > 2) { window.ExternalGlaze = (construction.Layers[2]).ToGBXGlazed(); } return(window); }
public static BHE.Opening ToBHoM(this BHX.Opening gbOpening) { BHE.Opening opening = new BHE.Opening(); BHG.Polyline pLine = gbOpening.PlanarGeometry.PolyLoop.ToBHoM(); opening.Edges = pLine.ToEdges(); string[] cadSplit = gbOpening.CADObjectID.Split('['); if (cadSplit.Length > 0) { opening.Name = cadSplit[0].Trim(); } if (cadSplit.Length > 1) { BHP.OriginContextFragment envContext = new BHP.OriginContextFragment(); envContext.ElementID = cadSplit[1].Split(']')[0].Trim(); envContext.TypeName = opening.Name; if (opening.Fragments == null) { opening.Fragments = new List <IBHoMFragment>(); } opening.Fragments.Add(envContext); } opening.Type = gbOpening.OpeningType.ToBHoMOpeningType(); return(opening); }
public static BHX.Opening ToGBXML(this BHE.Opening opening, List <BHE.Panel> space) { BHX.Opening gbOpening = opening.ToGBXML(); BHG.Polyline pLine = opening.Polyline(); if (pLine.NormalAwayFromSpace(space)) { gbOpening.PlanarGeometry.PolyLoop = pLine.Flip().ToGBXML(); } BHP.OriginContextFragment contextProperties = opening.FindFragment <BHP.OriginContextFragment>(typeof(BHP.OriginContextFragment)); if (contextProperties != null) { string elementID = contextProperties.ElementID; string familyName = contextProperties.TypeName; gbOpening.CADObjectID = opening.CADObjectID(); gbOpening.OpeningType = opening.Type.ToGBXML(); if (familyName == "System Panel") //No SAM_BuildingElementType for this one atm { gbOpening.OpeningType = "FixedWindow"; } if (gbOpening.OpeningType.Contains("Window") && opening.OpeningConstruction.Name.Contains("SLD")) //Change windows with SLD construction into doors { gbOpening.OpeningType = "NonSlidingDoor"; } } return(gbOpening); }
/***************************************************/ public static string CADObjectID(this BHE.Opening opening) { BHP.OriginContextFragment contextProp = opening.FindFragment <BHP.OriginContextFragment>(typeof(BHP.OriginContextFragment)); if (contextProp == null) { return("WinInst: SIM_EXT_GLZ [000000]"); } string cadID = ""; if (contextProp.TypeName == "") { cadID += "WinInst: SIM_EXT_GLZ"; } else { cadID += contextProp.TypeName; } cadID += " ["; if (contextProp.ElementID == "") { cadID += "000000"; } else { cadID += contextProp.ElementID; } cadID += "]"; return(cadID); }
public static BHX.Surface ToGBXML(this BHE.Panel element) { BHP.OriginContextFragment contextProperties = element.FindFragment <BHP.OriginContextFragment>(typeof(BHP.OriginContextFragment)); BHX.Surface surface = new BHX.Surface(); surface.CADObjectID = element.CADObjectID(); surface.ConstructionIDRef = (contextProperties == null ? element.ConstructionID() : contextProperties.TypeName.CleanName()); BHX.RectangularGeometry geom = element.ToGBXMLGeometry(); BHX.PlanarGeometry planarGeom = new BHX.PlanarGeometry(); planarGeom.ID = "PlanarGeometry-" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 10); BHG.Polyline pLine = element.Polyline(); planarGeom.PolyLoop = pLine.ToGBXML(); surface.PlanarGeometry = planarGeom; surface.RectangularGeometry = geom; surface.Opening = new BHX.Opening[element.Openings.Count]; for (int x = 0; x < element.Openings.Count; x++) { if (element.Openings[x].Polyline().IControlPoints().Count != 0) { surface.Opening[x] = element.Openings[x].ToGBXML(); } } return(surface); }
/***************************************************/ public static string CADObjectID(this BHE.Space space) { BHP.OriginContextFragment contextProp = space.FindFragment <BHP.OriginContextFragment>(typeof(BHP.OriginContextFragment)); if (contextProp == null) { return(""); } return(contextProp.TypeName + " [" + contextProp.ElementID + "]"); }
public static BHE.Building FromTAS(this TBD.Building tbdBuilding) { BHE.Building building = new BHE.Building(); building.Name = tbdBuilding.name; building.Location.Latitude = tbdBuilding.latitude; building.Location.Longitude = tbdBuilding.longitude; building.Elevation = tbdBuilding.maxBuildingAltitude; //building.Elevation = tbdBuilding.GetWeatherYear().altitude; //Consider switching to this if maxBuildingAltitude does not work //EnvironmentContextProperties BHP.OriginContextFragment environmentContextProperties = new BHP.OriginContextFragment(); environmentContextProperties.ElementID = tbdBuilding.GUID.RemoveBrackets(); environmentContextProperties.Description = tbdBuilding.description; environmentContextProperties.TypeName = tbdBuilding.name; building.Fragments.Add(environmentContextProperties); //BuildingAnalyticalProperties BHP.BuildingAnalyticalFragment buildingAnalyticalProperties = new BHP.BuildingAnalyticalFragment(); buildingAnalyticalProperties.NorthAngle = tbdBuilding.northAngle; //North Angle (degrees) Measured clockwise with respect to the Y - axis of the building plan. buildingAnalyticalProperties.Year = tbdBuilding.year; buildingAnalyticalProperties.GMTOffset = tbdBuilding.timeZone; building.Fragments.Add(buildingAnalyticalProperties); //BuildingContextProperties TBD.WeatherYear weatherYear = tbdBuilding.GetWeatherYear(); if (weatherYear != null) { BHP.BuildingContextFragment buildingContextProperties = new BHP.BuildingContextFragment(); buildingContextProperties.PlaceName = weatherYear.name; buildingContextProperties.WeatherStation = weatherYear.description; building.Fragments.Add(buildingContextProperties); } //BuildingResultsProperties BHP.BuildingResultFragment buildingResultsProperties = new BHP.BuildingResultFragment(); buildingResultsProperties.PeakCooling = tbdBuilding.peakCooling; buildingResultsProperties.PeakHeating = tbdBuilding.peakHeating; building.Fragments.Add(buildingResultsProperties); //Extended Properties TASBuilding tasData = new TASBuilding(); tasData.ID = tbdBuilding.GUID.RemoveBrackets(); tasData.TASID = tbdBuilding.TBDGUID; tasData.PathFile = tbdBuilding.path3DFile; building.Fragments.Add(tasData); return(building); }
public static TBD.Building ToTAS(this BHE.Building building, TBD.Building tbdBuilding) { //TODO:Add BuildingHeightAdjustmentFactor, MeanHeightOfSurroundings, TerrainType, NumberOfPreconditioningDays, GroundSolarReflectance, ExternalPollutant //TODO:Check if Longitude, Latitude, NorthAngle, Timezone, Path3Dfile, BuildingYear is pushed if (building == null) { return(tbdBuilding); } tbdBuilding.name = building.Name; tbdBuilding.latitude = (float)building.Location.Latitude; tbdBuilding.longitude = (float)building.Location.Longitude; tbdBuilding.maxBuildingAltitude = (float)building.Elevation; TASBuilding tasFragment = building.FindFragment <TASBuilding>(typeof(TASBuilding)); if (tasFragment != null) { tbdBuilding.GUID = tasFragment.ID; tbdBuilding.TBDGUID = tasFragment.TASID; tbdBuilding.path3DFile = tasFragment.PathFile; } BHP.OriginContextFragment environmentContextFragment = new BHP.OriginContextFragment(); if (environmentContextFragment != null) { tbdBuilding.description = environmentContextFragment.Description; } BHP.BuildingResultFragment buildingResultsFragment = building.FindFragment <BHP.BuildingResultFragment>(typeof(BHP.BuildingResultFragment)); if (buildingResultsFragment != null) { tbdBuilding.peakCooling = (float)System.Convert.ToDouble(buildingResultsFragment.PeakCooling); tbdBuilding.peakHeating = (float)System.Convert.ToDouble(buildingResultsFragment.PeakHeating); } BHP.BuildingAnalyticalFragment analyticalFragment = building.FindFragment <BHP.BuildingAnalyticalFragment>(typeof(BHP.BuildingAnalyticalFragment)); if (analyticalFragment != null) { tbdBuilding.northAngle = (float)System.Convert.ToDouble(analyticalFragment.NorthAngle); tbdBuilding.timeZone = (float)System.Convert.ToDouble(analyticalFragment.GMTOffset); } return(tbdBuilding); }
public static BHX.Surface ToGBXMLShade(this BHE.Panel element, GBXMLSettings settings) { BHP.OriginContextFragment envContextProperties = element.FindFragment <BHP.OriginContextFragment>(typeof(BHP.OriginContextFragment)); BHX.Surface gbSrf = new BHX.Surface(); gbSrf.CADObjectID = element.CADObjectID(); gbSrf.ConstructionIDRef = (envContextProperties == null ? element.ConstructionID() : envContextProperties.TypeName.CleanName()); BHX.RectangularGeometry geom = element.ToGBXMLGeometry(settings); BHX.PlanarGeometry planarGeom = new BHX.PlanarGeometry(); planarGeom.ID = "PlanarGeometry-" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 10); BHG.Polyline pLine = element.Polyline(); planarGeom.PolyLoop = pLine.ToGBXML(settings); gbSrf.PlanarGeometry = planarGeom; gbSrf.RectangularGeometry = geom; gbSrf.Opening = new BHX.Opening[element.Openings.Count]; for (int x = 0; x < element.Openings.Count; x++) { if (element.Openings[x].Polyline().IControlPoints().Count != 0) { gbSrf.Opening[x] = element.Openings[x].ToGBXML(element, settings); } } string idName = "Panel_" + element.BHoM_Guid.ToString().Replace(" ", "").Replace("-", "").Substring(0, 10); gbSrf.ID = idName; gbSrf.Name = idName; gbSrf.SurfaceType = "Shade"; gbSrf.ExposedToSun = BH.Engine.Environment.Query.ExposedToSun(element).ToString().ToLower(); if (settings.IncludeConstructions) { gbSrf.ConstructionIDRef = element.ConstructionID(); } else //We have to force null otherwise Construction will be created { gbSrf.ConstructionIDRef = null; } return(gbSrf); }
public static BHE.Panel ToBHoM(this BHX.Surface surface) { BHE.Panel panel = new BHE.Panel(); surface.Opening = surface.Opening ?? new List <BHX.Opening>().ToArray(); panel.ExternalEdges = surface.PlanarGeometry.PolyLoop.ToBHoM().ToEdges(); foreach (BHX.Opening opening in surface.Opening) { panel.Openings.Add(opening.ToBHoM()); } string[] cadSplit = surface.CADObjectID.Split('['); if (cadSplit.Length > 0) { panel.Name = cadSplit[0].Trim(); } if (cadSplit.Length > 1) { BHP.OriginContextFragment envContext = new BHP.OriginContextFragment(); envContext.ElementID = cadSplit[1].Split(']')[0].Trim(); envContext.TypeName = panel.Name; if (panel.Fragments == null) { panel.Fragments = new List <IBHoMFragment>(); } panel.Fragments.Add(envContext); } panel.Type = surface.SurfaceType.ToBHoMPanelType(); panel.ConnectedSpaces = new List <string>(); if (surface.AdjacentSpaceID != null) { foreach (BHX.AdjacentSpaceId adjacent in surface.AdjacentSpaceID) { panel.ConnectedSpaces.Add(adjacent.SpaceIDRef); } } return(panel); }
public static BHX.Construction ToGBXML(this BHC.Construction construction, BHE.Panel element = null) { BHX.Construction gbConstruction = new BHX.Construction(); BHP.OriginContextFragment contextProperties = null; BHP.PanelAnalyticalFragment analysisProperties = null; if (element != null) { contextProperties = element.FindFragment <BHP.OriginContextFragment>(typeof(BHP.OriginContextFragment)); analysisProperties = element.FindFragment <BHP.PanelAnalyticalFragment>(typeof(BHP.PanelAnalyticalFragment)); } gbConstruction.ID = (contextProperties == null ? construction.ConstructionID() : contextProperties.TypeName.CleanName().Replace(" ", "-")); gbConstruction.Absorptance.Value = construction.Absorptance().ToString(); gbConstruction.Name = (contextProperties == null ? construction.Name : contextProperties.TypeName); gbConstruction.Roughness = construction.Roughness().ToGBXML(); gbConstruction.UValue.Value = (analysisProperties == null || analysisProperties.UValue == 0 ? construction.UValue() : analysisProperties.UValue).ToString(); return(gbConstruction); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static List <BH.oM.XML.Opening> SerializeOpenings(IEnumerable <BH.oM.Environment.Elements.Opening> openings, List <Panel> space, List <Panel> allElements, List <List <Panel> > spaces, BH.oM.XML.GBXML gbx, XMLSettings settings) { List <BH.oM.XML.Opening> gbOpenings = new List <oM.XML.Opening>(); foreach (BH.oM.Environment.Elements.Opening opening in openings) { Polyline openingPoly = opening.Polyline(); if (openingPoly == null || openingPoly.CleanPolyline(distanceTolerance: settings.DistanceTolerance) == null) { continue; } openingPoly = openingPoly.CleanPolyline(distanceTolerance: settings.DistanceTolerance); BH.oM.XML.Opening gbOpening = BH.Engine.XML.Convert.ToGBXML(opening); //Normals away from space if (!BH.Engine.Environment.Query.NormalAwayFromSpace(openingPoly, space)) { gbOpening.PlanarGeometry.PolyLoop = BH.Engine.XML.Convert.ToGBXML(openingPoly.Flip()); } Panel buildingElement = new Panel(); ; BHP.OriginContextFragment contextProperties = opening.FindFragment <BHP.OriginContextFragment>(typeof(BHP.OriginContextFragment)); string elementID = ""; string familyName = ""; if (contextProperties != null) { elementID = contextProperties.ElementID; familyName = contextProperties.TypeName; } gbOpening.CADObjectID = opening.CADObjectID(); gbOpening.OpeningType = opening.Type.ToGBXML(); if (gbOpening.OpeningType.ToLower() == "fixedwindow" && contextProperties != null && contextProperties.TypeName.ToLower().Contains("skylight")) { gbOpening.OpeningType = "FixedSkylight"; } if (familyName == "System Panel") //No SAM_BuildingElementType for this one atm { gbOpening.OpeningType = "FixedWindow"; } if (settings.ReplaceSolidOpeningsIntoDoors && gbOpening.OpeningType.Contains("Window") && (opening.OpeningConstruction != null && opening.OpeningConstruction.Name.Contains("SLD"))) //Change windows with SLD construction into doors for IES { gbOpening.OpeningType = "NonSlidingDoor"; } if (settings.IncludeConstructions) { gbOpening.WindowTypeIDRef = "window-" + (contextProperties != null? contextProperties.TypeName.CleanName() : (opening.OpeningConstruction != null ? opening.OpeningConstruction.Name.CleanName() : "")); } else { gbOpening.WindowTypeIDRef = null; } gbOpening.ConstructionIDRef = null; //ToDo review having this property on an opening? gbOpenings.Add(gbOpening); } return(gbOpenings); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static string CADObjectID(this BHE.Panel element, bool replaceCurtainWalls = false) { string CADObjectID = ""; if (element == null) { return(CADObjectID); } BHP.OriginContextFragment contextProperties = element.FindFragment <BHP.OriginContextFragment>(typeof(BHP.OriginContextFragment)); if (contextProperties != null && contextProperties.ElementID != "") { // change only Basic Wall and keep Curtain as it is if (replaceCurtainWalls && element.Name.Contains("GLZ") && (element.Name.Contains("Basic Wall") || element.Name.Contains("Floor") || element.Name.Contains("Roof"))) { element.Name = "Curtain " + element.Name; } CADObjectID = element.Name + " [" + contextProperties.ElementID + "]"; } else { //Use a default object ID switch (element.Type) { case BHE.PanelType.Ceiling: CADObjectID += "Compound Ceiling: SIM_INT_SLD"; break; case BHE.PanelType.CurtainWall: if (element.ConnectedSpaces.Count == 2) { CADObjectID += "Curtain Wall: SIM_INT_GLZ"; } else { CADObjectID += "Curtain Wall: SIM_EXT_GLZ"; } break; case BHE.PanelType.Floor: case BHE.PanelType.FloorInternal: CADObjectID += "Floor: SIM_INT_SLD"; break; case BHE.PanelType.FloorExposed: case BHE.PanelType.FloorRaised: CADObjectID += "Floor: SIM_EXT_SLD"; break; case BHE.PanelType.Roof: CADObjectID += "Basic Roof: SIM_EXT_SLD"; break; case BHE.PanelType.Shade: CADObjectID += "Basic Roof: SIM_EXT_SHD_Roof"; break; case BHE.PanelType.SlabOnGrade: CADObjectID += "Floor: SIM_EXT_GRD"; break; case BHE.PanelType.UndergroundCeiling: CADObjectID += "Floor: SIM_INT_SLD_Parking"; break; case BHE.PanelType.UndergroundSlab: CADObjectID += "Floor: SIM_EXT_GRD"; break; case BHE.PanelType.UndergroundWall: CADObjectID += "Basic Wall: SIM_EXT_GRD"; break; case BHE.PanelType.Wall: case BHE.PanelType.WallExternal: CADObjectID += "Basic Wall: SIM_EXT_SLD"; break; case BHE.PanelType.WallInternal: CADObjectID += "Basic Wall: SIM_INT_SLD"; break; default: CADObjectID += "Undefined"; break; } CADObjectID += " BHoM [000000]"; } return(CADObjectID); }
public static void SerializeCollection(IEnumerable <Panel> inputElements, BH.oM.XML.GBXML gbx, XMLSettings settings) { //For serializing shade elements List <Panel> buildingElements = inputElements.ToList(); List <BH.oM.XML.Construction> usedConstructions = new List <oM.XML.Construction>(gbx.Construction); List <BH.oM.XML.Material> usedMaterials = new List <Material>(gbx.Material); List <BH.oM.XML.Layer> usedLayers = new List <Layer>(gbx.Layer); foreach (Panel be in buildingElements) { Surface gbSrf = be.ToGBXML(); gbSrf.ID = "Panel-" + gbx.Campus.Surface.Count.ToString().Replace(" ", "").Replace("-", ""); gbSrf.Name = "Panel" + gbx.Campus.Surface.Count.ToString().Replace(" ", "").Replace("-", ""); gbSrf.SurfaceType = "Shade"; gbSrf.ExposedToSun = BH.Engine.XML.Query.ExposedToSun(gbSrf.SurfaceType).ToString().ToLower(); gbSrf.CADObjectID = be.CADObjectID(); if (settings.IncludeConstructions) { BHP.OriginContextFragment envContextProperties = be.FindFragment <BHP.OriginContextFragment>(typeof(BHP.OriginContextFragment)); gbSrf.ConstructionIDRef = (envContextProperties != null ? envContextProperties.TypeName.CleanName() : be.ConstructionID()); BH.oM.XML.Construction conc = be.ToGBXMLConstruction(); BH.oM.XML.Construction test = usedConstructions.Where(y => y.ID == conc.ID).FirstOrDefault(); if (test == null) { List <BH.oM.XML.Material> materials = new List <Material>(); BHC.Construction construction = be.Construction as BHC.Construction; foreach (BHC.Layer l in construction.Layers) { materials.Add(l.ToGBXML()); } BH.oM.XML.Layer layer = materials.ToGBXML(); conc.LayerID.LayerIDRef = layer.ID; usedConstructions.Add(conc); if (usedLayers.Where(y => y.ID == layer.ID).FirstOrDefault() == null) { usedLayers.Add(layer); } foreach (BH.oM.XML.Material mat in materials) { if (usedMaterials.Where(y => y.ID == mat.ID).FirstOrDefault() == null) { usedMaterials.Add(mat); } } } } else //We have to force null otherwise Construction will be created { gbSrf.ConstructionIDRef = null; } gbx.Campus.Surface.Add(gbSrf); } gbx.Construction = usedConstructions.ToArray(); gbx.Layer = usedLayers.ToArray(); gbx.Material = usedMaterials.ToArray(); }
public static BHX.Surface ToGBXML(this BHE.Panel element, GBXMLSettings settings, List <BHE.Panel> space = null) { BHE.Panel panel = element.DeepClone <BHE.Panel>(); BHP.OriginContextFragment contextProperties = panel.FindFragment <BHP.OriginContextFragment>(typeof(BHP.OriginContextFragment)); BHX.Surface surface = new BHX.Surface(); string idName = "Panel-" + panel.BHoM_Guid.ToString().Replace(" ", "").Replace("-", "").Substring(0, 10); surface.ID = idName; surface.Name = idName; surface.SurfaceType = panel.Type.ToGBXML(); surface.ExposedToSun = BH.Engine.Environment.Query.ExposedToSun(panel).ToString().ToLower(); surface.CADObjectID = panel.CADObjectID(settings.ReplaceCurtainWalls); if (settings.IncludeConstructions) { surface.ConstructionIDRef = panel.ConstructionID(); } else { surface.ConstructionIDRef = null; } BHX.RectangularGeometry geom = panel.ToGBXMLGeometry(settings); BHX.PlanarGeometry planarGeom = new BHX.PlanarGeometry(); planarGeom.ID = "PlanarGeometry-" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 10); surface.RectangularGeometry = geom; BHG.Polyline pLine = panel.Polyline(); if (space != null && panel.ConnectedSpaces[0] == space.ConnectedSpaceName() && !pLine.NormalAwayFromSpace(space, settings.PlanarTolerance)) { pLine = pLine.Flip(); surface.PlanarGeometry.PolyLoop = pLine.ToGBXML(settings); surface.RectangularGeometry.Tilt = Math.Round(pLine.Tilt(settings.AngleTolerance), settings.RoundingSettings.GeometryTilt); surface.RectangularGeometry.Azimuth = Math.Round(pLine.Azimuth(BHG.Vector.YAxis), settings.RoundingSettings.GeometryAzimuth); } planarGeom.PolyLoop = pLine.ToGBXML(settings); surface.PlanarGeometry = planarGeom; if (settings.ReplaceCurtainWalls) { //If the surface is a basic Wall: SIM_EXT_GLZ so Curtain Wall after CADObjectID translation add the wall as an opening if (surface.CADObjectID.Contains("Curtain") && surface.CADObjectID.Contains("GLZ")) { List <BHG.Polyline> newOpeningBounds = new List <oM.Geometry.Polyline>(); if (panel.Openings.Count > 0) { //This surface already has openings - cut them out of the new opening List <BHG.Polyline> refRegion = panel.Openings.Where(y => y.Polyline() != null).ToList().Select(z => z.Polyline()).ToList(); newOpeningBounds.AddRange(BH.Engine.Geometry.Triangulation.Compute.DelaunayTriangulation(panel.Polyline(), refRegion, conformingDelaunay: false)); BHG.Polyline outer = panel.Polyline(); double outerArea = panel.Area(); for (int z = 0; z > panel.Openings.Count; z++) { BHG.Polyline poly = outer.BooleanDifference(new List <BHG.Polyline> { panel.Openings[z].Polyline() })[0]; if (poly.Area() != outerArea) { panel.Openings[z].Edges = panel.Openings[z].Polyline().Offset(settings.OffsetDistance).ToEdges(); } } } else { newOpeningBounds.Add(panel.Polyline()); } foreach (BHG.Polyline b in newOpeningBounds) { BH.oM.Environment.Elements.Opening curtainWallOpening = new BHE.Opening() { Edges = b.ToEdges() }; curtainWallOpening.Name = panel.Name; BHP.OriginContextFragment curtainWallProperties = new BHP.OriginContextFragment(); if (contextProperties != null) { curtainWallProperties.ElementID = contextProperties.ElementID; curtainWallProperties.TypeName = contextProperties.TypeName; } curtainWallOpening.Type = BHE.OpeningType.CurtainWall; curtainWallOpening.OpeningConstruction = panel.Construction; curtainWallOpening.Fragments.Add(curtainWallProperties); panel.Openings.Add(curtainWallOpening); } //Update the host elements element type surface.SurfaceType = (panel.ConnectedSpaces.Count == 1 ? BHE.PanelType.WallExternal : BHE.PanelType.WallInternal).ToGBXML(); surface.ExposedToSun = BH.Engine.Adapters.XML.Query.ExposedToSun(surface.SurfaceType).ToString().ToLower(); } } else { //Fix surface type for curtain walls if (panel.Type == BHE.PanelType.CurtainWall) { surface.SurfaceType = (panel.ConnectedSpaces.Count == 1 ? BHE.PanelType.WallExternal : BHE.PanelType.WallInternal).ToGBXML(); surface.ExposedToSun = BH.Engine.Adapters.XML.Query.ExposedToSun(surface.SurfaceType).ToString().ToLower(); } } if (settings.FixIncorrectAirTypes && panel.Type == BHE.PanelType.Undefined && panel.ConnectedSpaces.Count == 1) { //Fix external air types if (panel.Tilt(settings.AngleTolerance) == 0) { surface.SurfaceType = BHE.PanelType.Roof.ToGBXML(); } else if (panel.Tilt(settings.AngleTolerance) == 90) { surface.SurfaceType = BHE.PanelType.WallExternal.ToGBXML(); } else if (panel.Tilt(settings.AngleTolerance) == 180) { surface.SurfaceType = BHE.PanelType.SlabOnGrade.ToGBXML(); } } surface.Opening = new BHX.Opening[panel.Openings.Count]; for (int x = 0; x < panel.Openings.Count; x++) { if (panel.Openings[x].Polyline().IControlPoints().Count != 0) { surface.Opening[x] = panel.Openings[x].ToGBXML(panel, settings); } } List <BHX.AdjacentSpaceID> adjIDs = new List <BHX.AdjacentSpaceID>(); foreach (string s in panel.ConnectedSpaces) { BHX.AdjacentSpaceID adjId = new BHX.AdjacentSpaceID(); adjId.SpaceIDRef = "Space" + s.Replace(" ", "").Replace("-", ""); adjIDs.Add(adjId); } surface.AdjacentSpaceID = adjIDs.ToArray(); return(surface); }
public static BHE.Space FromTAS(this TBD.zone tbdSpace, TBD.TBDDocument tbdDocument) { BHE.Space space = new BHE.Space(); space.Name = tbdSpace.name + tbdSpace.number.ToString(); BHP.LoadFragment loads = new BHP.LoadFragment(); loads.CoolingLoad = tbdSpace.maxCoolingLoad; loads.HeatingLoad = tbdSpace.maxHeatingLoad; space.Fragments.Add(loads); //Adding data to Extended Poroperties-------------------------------------------------------------------------------------------------------------- //EnvironmentContextProperties BHP.OriginContextFragment environmentContextProperties = new BHP.OriginContextFragment(); environmentContextProperties.ElementID = tbdSpace.GUID.RemoveBrackets(); environmentContextProperties.Description = tbdSpace.description; environmentContextProperties.TypeName = tbdSpace.name; space.Fragments.Add(environmentContextProperties); //SpaceContextProperties BHP.SpaceContextFragment spaceContextProperties = new BHP.SpaceContextFragment(); spaceContextProperties.Colour = BH.Engine.Adapters.TAS.Query.GetRGB(tbdSpace.colour).ToString(); spaceContextProperties.IsExternal = tbdSpace.external != 0; //spaceContextProperties.ConnectedElements = tbdSpace.external != 0; space.Fragments.Add(spaceContextProperties); //SpaceAnalyticalProperties BHP.SpaceAnalyticalFragment spaceAnalyticalProperties = new BHP.SpaceAnalyticalFragment(); spaceAnalyticalProperties.DaylightFactor = tbdSpace.daylightFactor; spaceAnalyticalProperties.FacadeLength = tbdSpace.facadeLength; spaceAnalyticalProperties.FixedConvectionCoefficient = tbdSpace.fixedConvectionCoefficient; spaceAnalyticalProperties.SizeCoolingMethod = ((TBD.SizingType)tbdSpace.sizeCooling).FromTAS(); spaceAnalyticalProperties.SizeHeatingMethod = ((TBD.SizingType)tbdSpace.sizeCooling).FromTAS(); space.Fragments.Add(spaceAnalyticalProperties); //Extended Properties TASSpaceData tasData = new TASSpaceData(); tasData.Colour = System.Convert.ToUInt32(tbdSpace.colour); tasData.DaylightFactor = tbdSpace.daylightFactor; tasData.ExposedPerimeter = tbdSpace.exposedPerimeter; tasData.External = tbdSpace.external; tasData.FacadeLength = tbdSpace.facadeLength; tasData.FixedConvectionCoefficient = tbdSpace.fixedConvectionCoefficient; tasData.FloorArea = tbdSpace.floorArea; tasData.TASID = tbdSpace.GUID.RemoveBrackets(); tasData.Length = tbdSpace.length; tasData.SizeCooling = tbdSpace.sizeCooling; tasData.SizeHeating = tbdSpace.sizeHeating; tasData.Volume = tbdSpace.volume; tasData.WallFloorAreaRatio = tbdSpace.wallFloorAreaRatio; TASDescription tasDescription = new TASDescription(); tasDescription.Description = tbdSpace.description; //Proces to extract Number of people directly into space if needed //double[] YearlyPeopleSensibleSepcificGain = Query.GetNumberOfPeople(tbdDocument, tbdSpace); //double MaxSpecificSensibleGain = YearlyPeopleSensibleSepcificGain.Max(); //double[] YearlyPeopleLatenteSepcificGain = Query.GetNumberOfPeople(tbdDocument, tbdSpace, TBD.Profiles.ticOLG); //double MaxSpecificLatentGain = YearlyPeopleLatenteSepcificGain.Max(); //double NumberOfPeople = PeopleDesity / tbdSpace.floorArea; space.Fragments.Add(tasData); space.Fragments.Add(tasDescription); return(space); }
public static BHX.Opening ToGBXML(this BHE.Opening opening, BHE.Panel hostPanel, GBXMLSettings settings) { BHX.Opening gbOpening = new BHX.Opening(); BHG.Polyline pLine = opening.Polyline(); gbOpening.Name = opening.Name; gbOpening.ID = "opening" + opening.BHoM_Guid.ToString().Replace("-", "").Substring(0, 5); gbOpening.PlanarGeometry.PolyLoop = pLine.ToGBXML(settings); gbOpening.PlanarGeometry.ID = "openingPGeom-" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 5); gbOpening.RectangularGeometry.CartesianPoint = BH.Engine.Geometry.Query.Centroid(pLine).ToGBXML(settings); gbOpening.RectangularGeometry.Height = Math.Round(opening.Height(), settings.RoundingSettings.GeometryHeight); //TODO: temporary solution to get valid file to be replaced with correct height if (opening.Height() == 0) { gbOpening.RectangularGeometry.Height = 0.1; } gbOpening.RectangularGeometry.Width = Math.Round(opening.Width(), settings.RoundingSettings.GeometryWidth); gbOpening.RectangularGeometry.ID = "rGeomOpening-" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 5); pLine = pLine.CleanPolyline(minimumSegmentLength: settings.DistanceTolerance); double openingArea = pLine.Area(); double panelArea = hostPanel.Polyline().Area(); if (openingArea >= panelArea) { pLine = BH.Engine.Geometry.Modify.Offset(pLine, settings.OffsetDistance); if (pLine == null) { pLine = opening.Polyline(); //Reset the polyline if something went wrong with the offset } gbOpening.PlanarGeometry.PolyLoop = pLine.ToGBXML(settings); } //Normals away from space //if (!BH.Engine.Environment.Query.NormalAwayFromSpace(pLine, hostSpace, settings.PlanarTolerance)) //gbOpening.PlanarGeometry.PolyLoop = pLine.Flip().ToGBXML(); gbOpening.CADObjectID = opening.CADObjectID(); gbOpening.OpeningType = opening.Type.ToGBXML(); BHP.OriginContextFragment contextProperties = opening.FindFragment <BHP.OriginContextFragment>(typeof(BHP.OriginContextFragment)); string elementID = ""; string familyName = ""; if (contextProperties != null) { elementID = contextProperties.ElementID; familyName = contextProperties.TypeName; } if (gbOpening.OpeningType.ToLower() == "fixedwindow" && contextProperties != null && contextProperties.TypeName.ToLower().Contains("skylight")) { gbOpening.OpeningType = "FixedSkylight"; } if (familyName == "System Panel") //No SAM_BuildingElementType for this one atm { gbOpening.OpeningType = "FixedWindow"; } if (settings.ReplaceSolidOpeningsIntoDoors && gbOpening.OpeningType.Contains("Window") && (opening.OpeningConstruction != null && opening.OpeningConstruction.Name.Contains("SLD"))) //Change windows with SLD construction into doors for IES { gbOpening.OpeningType = "NonSlidingDoor"; } if (settings.IncludeConstructions) { gbOpening.WindowTypeIDRef = "window-" + (contextProperties != null ? contextProperties.TypeName.CleanName() : (opening.OpeningConstruction != null ? opening.OpeningConstruction.Name.CleanName() : "")); } else { gbOpening.WindowTypeIDRef = null; } gbOpening.ConstructionIDRef = null; //ToDo review having this property on an opening? return(gbOpening); }
public static BHE.Panel FromTAS(this TBD.buildingElement tbdElement, TBD.zoneSurface tbdSurface, TASSettings tasSettings) { BHE.Panel element = new BHE.Panel(); TBD.BuildingElementType tbdElementType = ((TBD.BuildingElementType)tbdElement.BEType); TASPanelData tasData = new TASPanelData(); tasData.PanelIsOpening = tbdElementType.ElementIsOpening(); //Add a flag on the element for the final read if (tbdElementType.ElementIsOpening()) { //Find out what the fix was - frame or pane? BHE.OpeningType fixedOpeningType = tbdElementType.FromTASOpeningType().FixBuildingElementType(tbdElement, tbdSurface); tasData.OpeningIsFrame = fixedOpeningType.OpeningIsFrame(); } BHE.PanelType elementType = ((TBD.BuildingElementType)tbdElement.BEType).FromTAS(); BHPC.Construction elementConstruction = tbdElement.GetConstruction().FromTAS(); element.Name = tbdElement.name; element.Type = elementType; element.Construction = elementConstruction; element.Fragments.Add(tasData); //EnvironmentContextProperties BHP.OriginContextFragment environmentContextProperties = new BHP.OriginContextFragment(); environmentContextProperties.ElementID = tbdSurface.GUID.RemoveBrackets(); environmentContextProperties.Description = tbdElement.description; environmentContextProperties.TypeName = tbdSurface.buildingElement.name; element.Fragments.Add(environmentContextProperties); //BuildingElementContextProperties BHP.PanelContextFragment buildingElementContextProperties = new BHP.PanelContextFragment(); element.ConnectedSpaces.Add(tbdSurface.zone.name); if ((int)tbdSurface.type == 3) { element.ConnectedSpaces.Add(tbdSurface.linkSurface.zone.name); } else { element.ConnectedSpaces.Add("-1"); } buildingElementContextProperties.IsAir = tbdElement.ghost != 0; buildingElementContextProperties.IsGround = tbdElement.ground != 0; buildingElementContextProperties.Colour = BH.Engine.Adapters.TAS.Query.GetRGB(tbdElement.colour).ToString(); buildingElementContextProperties.Reversed = tbdSurface.reversed != 0; element.Fragments.Add(buildingElementContextProperties); //BuildingElementAnalyticalProperties BHP.PanelAnalyticalFragment buildingElementAnalyticalProperties = new BHP.PanelAnalyticalFragment(); buildingElementAnalyticalProperties.Altitude = tbdSurface.altitude.Round(); buildingElementAnalyticalProperties.AltitudeRange = tbdSurface.altitudeRange.Round(); buildingElementAnalyticalProperties.Inclination = tbdSurface.inclination.Round(); buildingElementAnalyticalProperties.Orientation = tbdSurface.orientation.Round(); buildingElementAnalyticalProperties.GValue = tbdElement.GValue().Round(); buildingElementAnalyticalProperties.LTValue = tbdElement.LTValue().Round(); buildingElementAnalyticalProperties.UValue = tbdElement.UValue().Round(); element.Fragments.Add(buildingElementAnalyticalProperties); List <BHG.Polyline> panelCurve = new List <BHG.Polyline>(); int surfaceIndex = 0; TBD.RoomSurface roomSurface = null; while ((roomSurface = tbdSurface.GetRoomSurface(surfaceIndex)) != null) { TBD.Perimeter tbdPerimeter = roomSurface.GetPerimeter(); if (tbdPerimeter != null) { panelCurve.Add(tbdPerimeter.FromTAS()); //Add openings int openingIndex = 0; TBD.Polygon openingPolygon = null; while ((openingPolygon = tbdPerimeter.GetHole(openingIndex)) != null) { element.Openings.Add(openingPolygon.FromTASOpening(roomSurface, tasSettings)); openingIndex++; } } surfaceIndex++; } if (panelCurve.Count == 1) { element.ExternalEdges = panelCurve.First().CleanPolyline(tasSettings.AngleTolerance, tasSettings.MinimumSegmentLength).ToEdges(); } else { try { List <BHG.Polyline> polylines = Geometry.Compute.BooleanUnion(panelCurve, 1e-3); if (polylines.Count == 1) { element.ExternalEdges = polylines.First().CleanPolyline(tasSettings.AngleTolerance, tasSettings.MinimumSegmentLength).ToEdges(); } else { element.ExternalEdges = Geometry.Create.PolyCurve(polylines).ICollapseToPolyline(BH.oM.Geometry.Tolerance.Angle).CleanPolyline(tasSettings.AngleTolerance, tasSettings.MinimumSegmentLength).ToEdges(); } } catch (Exception e) { BH.Engine.Base.Compute.RecordWarning("An error occurred in building buildingElement ID - " + element.BHoM_Guid + " - error was: " + e.ToString()); element.ExternalEdges = Geometry.Create.PolyCurve(panelCurve).ICollapseToPolyline(BH.oM.Geometry.Tolerance.Angle).CleanPolyline(tasSettings.AngleTolerance, tasSettings.MinimumSegmentLength).ToEdges(); } } tasData.TASID = tbdSurface.GUID.RemoveBrackets(); tasData.TASName = "Z_" + tbdSurface.zone.number + "_" + tbdSurface.number + "_" + tbdSurface.zone.name; tasData.Type = System.Convert.ToString(tbdSurface.type); tasData.Area = tbdSurface.area.Round(); tasData.InternalArea = tbdSurface.internalArea.Round(); tasData.Width = tbdElement.width.Round(); tasData.MaterialLayersThickness = tbdElement.GetConstruction().ConstructionThickness().Round(); element.Fragments.Add(tasData); //AddingExtended Properties for a frame BHE.OpeningType elementOpeningType = tbdElementType.FromTASOpeningType().FixBuildingElementType(tbdElement, tbdSurface); if (elementOpeningType == BHE.OpeningType.RooflightWithFrame || elementOpeningType == BHE.OpeningType.WindowWithFrame) { if (element.Openings.FirstOrDefault() != null) { element.Openings[0].FrameConstruction = elementConstruction; } } return(element); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static void SerializeCollection(IEnumerable <IEnumerable <Panel> > inputElements, List <Level> levels, List <Panel> openings, BH.oM.XML.GBXML gbx, XMLSettings settings) { List <List <Panel> > elementsAsSpaces = new List <List <Panel> >(); foreach (IEnumerable <Panel> input in inputElements) { elementsAsSpaces.Add(input.ToList()); } List <Panel> uniqueBuildingElements = elementsAsSpaces.UniquePanels(); List <Panel> allElements = new List <Panel>(uniqueBuildingElements); allElements.AddRange(openings); //List<BH.oM.Environment.Elements.Space> spaces = elementsAsSpaces.Spaces(); List <Panel> usedBEs = new List <Panel>(); List <BH.oM.XML.Construction> usedConstructions = new List <BH.oM.XML.Construction>(); List <BH.oM.XML.Material> usedMaterials = new List <Material>(); List <BH.oM.XML.Layer> usedLayers = new List <Layer>(); List <string> usedSpaceNames = new List <string>(); List <BH.oM.XML.WindowType> usedWindows = new List <WindowType>(); foreach (List <Panel> space in elementsAsSpaces) { //For each collection of BuildingElements that define a space, convert the panels to XML surfaces and add to the GBXML List <Surface> spaceSurfaces = new List <Surface>(); for (int x = 0; x < space.Count; x++) { if (usedBEs.Where(i => i.BHoM_Guid == space[x].BHoM_Guid).FirstOrDefault() != null) { continue; } //Fix panel type //if(space[x].Type == PanelType.WallExternal && space[x].ConnectedSpaces.Count == 2) //space[x].Type = PanelType.WallInternal; BHP.OriginContextFragment envContextProperties = space[x].FindFragment <BHP.OriginContextFragment>(typeof(BHP.OriginContextFragment)); List <List <Panel> > adjacentSpaces = BH.Engine.Environment.Query.AdjacentSpaces(space[x], elementsAsSpaces); Surface srf = space[x].ToGBXML(adjacentSpaces, space); srf.ID = "Panel-" + gbx.Campus.Surface.Count.ToString().Replace(" ", "").Replace("-", ""); srf.Name = "Panel" + gbx.Campus.Surface.Count.ToString().Replace(" ", "").Replace("-", ""); if (space[x] != null) { srf.CADObjectID = BH.Engine.XML.Query.CADObjectID(space[x], settings.ReplaceCurtainWalls); } if (settings.IncludeConstructions) { srf.ConstructionIDRef = (envContextProperties != null ? envContextProperties.TypeName.CleanName() : space[x].ConstructionID()); } else { srf.ConstructionIDRef = null; } if (settings.ReplaceCurtainWalls) { //If the surface is a basic Wall: SIM_EXT_GLZ so Curtain Wall after CADObjectID translation add the wall as an opening if (srf.CADObjectID.Contains("Curtain") && srf.CADObjectID.Contains("GLZ")) { List <BHG.Polyline> newOpeningBounds = new List <oM.Geometry.Polyline>(); if (space[x].Openings.Count > 0) { //This surface already has openings - cut them out of the new opening List <BHG.Polyline> refRegion = space[x].Openings.Where(y => y.Polyline() != null).ToList().Select(z => z.Polyline()).ToList(); newOpeningBounds.AddRange((new List <BHG.Polyline> { space[x].Polyline() }).BooleanDifference(refRegion, 0.01)); } else { newOpeningBounds.Add(space[x].Polyline()); } BH.oM.Environment.Elements.Opening curtainWallOpening = BH.Engine.Environment.Create.Opening(externalEdges: newOpeningBounds.ToEdges()); curtainWallOpening.Name = space[x].Name; BHP.OriginContextFragment curtainWallProperties = new BHP.OriginContextFragment(); if (envContextProperties != null) { curtainWallProperties.ElementID = envContextProperties.ElementID; curtainWallProperties.TypeName = envContextProperties.TypeName; } curtainWallOpening.Type = OpeningType.CurtainWall; curtainWallOpening.OpeningConstruction = space[x].Construction; curtainWallOpening.Fragments.Add(curtainWallProperties); space[x].Openings.Add(curtainWallOpening); //Update the host elements element type srf.SurfaceType = (adjacentSpaces.Count == 1 ? PanelType.WallExternal : PanelType.WallInternal).ToGBXML(); srf.ExposedToSun = BH.Engine.XML.Query.ExposedToSun(srf.SurfaceType).ToString().ToLower(); } } else { //Fix surface type for curtain walls if (space[x].Type == PanelType.CurtainWall) { srf.SurfaceType = (adjacentSpaces.Count == 1 ? PanelType.WallExternal : PanelType.WallInternal).ToGBXML(); srf.ExposedToSun = BH.Engine.XML.Query.ExposedToSun(srf.SurfaceType).ToString().ToLower(); } } if (settings.FixIncorrectAirTypes && space[x].Type == PanelType.Undefined && space[x].ConnectedSpaces.Count == 1) { //Fix external air types if (space[x].Tilt() == 0) { srf.SurfaceType = PanelType.Roof.ToGBXML(); } else if (space[x].Tilt() == 90) { srf.SurfaceType = PanelType.WallExternal.ToGBXML(); } else if (space[x].Tilt() == 180) { srf.SurfaceType = PanelType.SlabOnGrade.ToGBXML(); } } //Openings if (space[x].Openings.Count > 0) { srf.Opening = SerializeOpenings(space[x].Openings, space, allElements, elementsAsSpaces, gbx, settings).ToArray(); foreach (BH.oM.Environment.Elements.Opening o in space[x].Openings) { string nameCheck = ""; BHP.OriginContextFragment openingEnvContextProperties = o.FindFragment <BHP.OriginContextFragment>(typeof(BHP.OriginContextFragment)); if (openingEnvContextProperties != null) { nameCheck = openingEnvContextProperties.TypeName; } else if (o.OpeningConstruction != null) { nameCheck = o.OpeningConstruction.Name; } var t = usedWindows.Where(a => a.Name == nameCheck).FirstOrDefault(); if (t == null && o.OpeningConstruction != null) { usedWindows.Add(o.OpeningConstruction.ToGBXMLWindow(o)); } } } gbx.Campus.Surface.Add(srf); usedBEs.Add(space[x]); if (settings.IncludeConstructions && space[x].Construction != null) { BH.oM.XML.Construction conc = space[x].ToGBXMLConstruction(); BH.oM.XML.Construction test = usedConstructions.Where(y => y.ID == conc.ID).FirstOrDefault(); if (test == null) { List <BH.oM.XML.Material> materials = new List <Material>(); BHC.Construction construction = space[x].Construction as BHC.Construction; foreach (BHC.Layer l in construction.Layers) { materials.Add(l.ToGBXML()); } BH.oM.XML.Layer layer = materials.ToGBXML(); conc.LayerID.LayerIDRef = layer.ID; usedConstructions.Add(conc); if (usedLayers.Where(y => y.ID == layer.ID).FirstOrDefault() == null) { usedLayers.Add(layer); } foreach (BH.oM.XML.Material mat in materials) { if (usedMaterials.Where(y => y.ID == mat.ID).FirstOrDefault() == null) { usedMaterials.Add(mat); } } } } } BH.oM.XML.Space xmlSpace = new oM.XML.Space(); xmlSpace.Name = space.ConnectedSpaceName(); xmlSpace.ID = "Space" + xmlSpace.Name.Replace(" ", "").Replace("-", ""); xmlSpace.CADObjectID = BH.Engine.XML.Query.CADObjectID(space); xmlSpace.ShellGeometry.ClosedShell.PolyLoop = BH.Engine.XML.Query.ClosedShellGeometry(space).ToArray(); xmlSpace.ShellGeometry.ID = "SpaceShellGeometry-" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 10); xmlSpace.SpaceBoundary = BH.Engine.XML.Query.SpaceBoundaries(space, uniqueBuildingElements); xmlSpace.PlanarGeoemtry.ID = "SpacePlanarGeometry-" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 10); if (BH.Engine.Environment.Query.FloorGeometry(space) != null) { xmlSpace.PlanarGeoemtry.PolyLoop = BH.Engine.XML.Convert.ToGBXML(BH.Engine.Environment.Query.FloorGeometry(space)); xmlSpace.Area = BH.Engine.Environment.Query.FloorGeometry(space).Area(); xmlSpace.Volume = space.Volume(); } Level spaceLevel = space.Level(levels); if (spaceLevel != null) { string levelName = ""; if (spaceLevel.Name == "") { levelName = spaceLevel.Elevation.ToString(); } else { levelName = spaceLevel.Name; } xmlSpace.BuildingStoreyIDRef = "Level-" + levelName.Replace(" ", "").ToLower(); } gbx.Campus.Building[0].Space.Add(xmlSpace); usedSpaceNames.Add(xmlSpace.Name); } //Reorder the spaces gbx.Campus.Building[0].Space = gbx.Campus.Building[0].Space.OrderBy(x => x.Name).ToList(); gbx.Construction = usedConstructions.ToArray(); gbx.Layer = usedLayers.ToArray(); gbx.Material = usedMaterials.ToArray(); if (settings.IncludeConstructions) { gbx.WindowType = usedWindows.ToArray(); } else //We have to force null otherwise WindowType will be created { gbx.WindowType = null; } //Set the building area List <Panel> floorElements = allElements.Where(x => x.Type == PanelType.Floor || x.Type == PanelType.FloorExposed || x.Type == PanelType.FloorInternal || x.Type == PanelType.FloorRaised || x.Type == PanelType.SlabOnGrade || x.Type == PanelType.UndergroundSlab).ToList(); double buildingFloorArea = 0; foreach (Panel be in floorElements) { buildingFloorArea += be.Area(); } gbx.Campus.Building[0].Area = buildingFloorArea; }
public static global::OpenStudio.Surface ToOSM(this BHE.Panel panel, global::OpenStudio.Model modelReference, global::OpenStudio.Space osmSpace, Dictionary <string, global::OpenStudio.Construction> uniqueConstructions, string outsideBoundaryCondition) { Surface osmElement = new Surface(panel.Polyline().ToOSM(), modelReference); osmElement.setName(panel.Name); osmElement.setSpace(osmSpace); if (outsideBoundaryCondition != "") { osmElement.setOutsideBoundaryCondition(outsideBoundaryCondition); } osmElement.setSurfaceType(panel.Type.ToOSMSurfaceType()); osmElement.setConstruction(uniqueConstructions[panel.Construction.UniqueConstructionName()]); BHP.OriginContextFragment envContextProperties = panel.FindFragment <BHP.OriginContextFragment>(typeof(BHP.OriginContextFragment)); //Fix curtain wall if (panel.Type == BHE.PanelType.CurtainWall) { osmElement.setConstruction(uniqueConstructions["CurtainWallReplacementConstruction"]); //No need for construction on a curtain wall as the opening will handle it List <BHG.Polyline> newOpeningBounds = new List <BHG.Polyline>(); if (panel.Openings.Count > 0) { //This surface already has openings - cut them out of the new opening List <BHG.Polyline> refRegion = panel.Openings.Where(y => y.Polyline() != null).ToList().Select(z => z.Polyline()).ToList(); newOpeningBounds.AddRange((panel.Polyline().BooleanDifference(refRegion, 0.01))); } else { newOpeningBounds.Add(panel.Polyline()); } BHE.Opening curtainWallOpening = new BHE.Opening() { Edges = BH.Engine.Geometry.Create.PolyCurve(newOpeningBounds).ICollapseToPolyline(BH.oM.Geometry.Tolerance.Angle).ToEdges() }; //Scale the bounding curve to comply with IDF rules BHG.Polyline crv = curtainWallOpening.Polyline(); curtainWallOpening.Edges = crv.Scale(crv.Centre(), BH.Engine.Geometry.Create.Vector(0.95, 0.95, 0.95)).ToEdges(); curtainWallOpening.Name = panel.Name; BHP.OriginContextFragment curtainWallProperties = new BHP.OriginContextFragment(); if (envContextProperties != null) { curtainWallProperties.ElementID = envContextProperties.ElementID; curtainWallProperties.TypeName = envContextProperties.TypeName; } curtainWallOpening.Type = BHE.OpeningType.CurtainWall; curtainWallOpening.OpeningConstruction = panel.Construction; panel.Openings = new List <BHE.Opening> { curtainWallOpening }; } return(osmElement); }