Exemple #1
0
        public static global::OpenStudio.Model CreateModel(List <List <BHE.Panel> > panelsAsSpaces, global::OpenStudio.Model modelReference)
        {
            List <BHC.Construction> uniqueConstructions = panelsAsSpaces.UniqueConstructions();

            //Create a curtain wall construction
            BHC.Construction curtainWallConstruction = new BHC.Construction();
            curtainWallConstruction.Name = "Curtain Wall Construction Replacement";

            BHC.Layer curtainWallLayer = new BHC.Layer();
            curtainWallLayer.Thickness = 0.1;

            BHM.Material curtainWallMaterial = new BHM.Material();
            curtainWallMaterial.Name = "Curtain Wall Construction Replacement";

            BHEM.SolidMaterial curtainWallMaterialProperties = new BHEM.SolidMaterial();
            curtainWallMaterialProperties.Roughness                = BHEM.Roughness.VerySmooth;
            curtainWallMaterialProperties.SpecificHeat             = 101;
            curtainWallMaterialProperties.Conductivity             = 0.1;
            curtainWallMaterialProperties.EmissivityExternal       = 0.1;
            curtainWallMaterialProperties.SolarReflectanceExternal = 0.1;
            curtainWallMaterialProperties.LightReflectanceExternal = 0.1;
            curtainWallMaterialProperties.Density = 0.1;

            curtainWallMaterial.Properties.Add(curtainWallMaterialProperties);
            curtainWallLayer.Material = curtainWallMaterial;
            curtainWallConstruction.Layers.Add(curtainWallLayer);

            Dictionary <string, Construction> osmConstructions = new Dictionary <string, Construction>();

            foreach (BHC.Construction c in uniqueConstructions)
            {
                osmConstructions.Add(c.UniqueConstructionName(), c.ToOSM(modelReference));
            }

            osmConstructions.Add("CurtainWallReplacementConstruction", curtainWallConstruction.ToOSM(modelReference));

            foreach (List <BHE.Panel> space in panelsAsSpaces)
            {
                ThermalZone osmZone  = new ThermalZone(modelReference);
                Space       osmSpace = new Space(modelReference);
                osmSpace.setThermalZone(osmZone);

                foreach (BHE.Panel be in space)
                {
                    string conName = be.Construction.UniqueConstructionName();

                    //be.ToOSM(modelReference, osmSpace, (conName == "" ? null : osmConstructions[conName]));
                    Surface host = be.ToOSM(modelReference, osmSpace, osmConstructions, be.OutsideBoundaryCondition(be.AdjacentSpaces(panelsAsSpaces)));

                    foreach (BHE.Opening o in be.Openings)
                    {
                        conName = o.OpeningConstruction.UniqueConstructionName();

                        o.ToOSM(host, (conName == "" ? null : osmConstructions[conName]), modelReference);
                    }
                }
            }

            return(modelReference);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        public static BHPC.Construction FromTAS(this TBD.Construction tbdConstruction)
        {
            if (tbdConstruction == null)
            {
                return(null);
            }

            BHPC.Construction construction = new BHPC.Construction();
            construction.Name = tbdConstruction.name;

            int mIndex = 1;

            TBD.material tbdMaterial = null;
            double       thickness   = 0;

            while ((tbdMaterial = tbdConstruction.materials(mIndex)) != null)
            {
                construction.Layers.Add(tbdMaterial.FromTAS(tbdConstruction));
                (construction.Layers.Last()).Thickness = (tbdConstruction.materialWidth[mIndex] == 0 ? (construction.Layers.Last()).Thickness : tbdConstruction.materialWidth[mIndex]); // temp solution set material thickness as value from construction.material.thickness
                thickness += construction.Layers.Last().Thickness;
                mIndex++;
            }

            //construction.FFactor = tbdConstruction.FFactor;


            TASDescription tasData = new TASDescription();

            tasData.Description = tbdConstruction.description.RemoveBrackets();
            construction.Fragments.Add(tasData);

            return(construction);
        }
Exemple #4
0
        public static BHC.Construction ToBHoM(this BHX.Construction gbConstruction, List <BHC.Layer> layers)
        {
            BHC.Construction construction = new BHC.Construction();
            construction.Name   = gbConstruction.Name;
            construction.Layers = layers;

            return(construction);
        }
Exemple #5
0
        public static global::OpenStudio.Construction ToOSM(this BHP.Construction construction, global::OpenStudio.Model modelReference)
        {
            global::OpenStudio.Construction osmConstruction = new Construction(modelReference);
            osmConstruction.setName(construction.Name);

            MaterialVector materialLayer = new MaterialVector();

            foreach (BHP.Layer layer in construction.Layers)
            {
                materialLayer.Add(layer.Material.ToOSM(modelReference));
            }

            //foreach (BHM.Material material in construction.Materials)
            //materialLayer.Add(material.ToOSM(construction.Roughness, modelReference, (construction.ConstructionType == BHE.ConstructionType.Transparent)));

            osmConstruction.setLayers(materialLayer);
            return(osmConstruction);
        }
Exemple #6
0
        public static List <IEnergyPlusClass> ToEnergyPlus(this BHP.Construction construction)
        {
            List <IEnergyPlusClass> classes           = new List <IEnergyPlusClass>();
            EPConstruction          eplusConstruction = new EPConstruction();
            string constructionName = construction.Name == "" ? construction.BHoM_Guid.ToString() : construction.Name;

            eplusConstruction.Name = constructionName;

            foreach (Layer layer in construction.Layers)
            {
                IEnergyPlusClass cls = layer.ToEnergyPlus();
                classes.Add(cls);
                eplusConstruction.Layers.Add(cls.Name);
            }

            classes.Add(eplusConstruction);

            return(classes);
        }
Exemple #7
0
        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 static string ConstructionID(this BHC.Construction construction)
        {
            //Method for constructing an ID based on the name of the property - this allows the same string ID to be generated for the same property for consistency in finding string IDs

            //Originally we used the GUID and got the combinations below - but each name is unique so each returned string ID will be unique anyway - but the following comment line is being left in as a nice little factoid for the next person... (//TD)
            //Using the first 8 digits of the GUID gives 218,340,105,584,896 possible combinations of IDs, so the liklihood of 2 different GUIDs producing the same result from this function is fairly small...

            if (construction.Name == "")
            {
                return(null);
            }

            String rtnID = construction.Name[0].ToString();

            for (int x = 1; x < construction.Name.Length; x++)
            {
                rtnID += ((int)construction.Name[x]).ToString();
            }

            return(rtnID);
        }
Exemple #9
0
        /***************************************************/
        /**** 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;
        }
Exemple #10
0
        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();
        }
Exemple #11
0
        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);
        }
Exemple #12
0
        public static TBD.Construction ToTAS(this BHPC.Construction construction, TBD.Construction tbdConstruction)
        {
            if (construction == null)
            {
                return(tbdConstruction);
            }
            if (construction.Layers == null)
            {
                return(tbdConstruction);
            }
            if (tbdConstruction == null)
            {
                return(tbdConstruction);
            }

            tbdConstruction.name = construction.Name;
            //tbdConstruction.additionalHeatTransfer = (float)construction.AdditionalHeatTransfer();
            //tbdConstruction.FFactor = (float)construction.FFactor; //ToDo: Fix these from the fragment after fragment implementation

            if (construction.Layers.Count > 0 && construction.Layers[0].Material != null)
            {
                if (construction.Layers[0].Material.IsTransparent())
                {
                    tbdConstruction.type = TBD.ConstructionTypes.tcdTransparentConstruction;
                }
                else
                {
                    tbdConstruction.type = TBD.ConstructionTypes.tcdOpaqueConstruction;
                }
            }

            //tbdConstruction.GUID = construction.BHoM_Guid.ToString();

            foreach (BH.oM.Physical.Constructions.Layer layer in construction.Layers)
            {
                layer.ToTAS(tbdConstruction.AddMaterial());
            }

            ////copy construction thickness to material thickness
            //if (tbdConstruction.type == TBD.ConstructionTypes.tcdOpaqueConstruction)
            //{
            //    int mIndex = 1;
            //    TBD.material m = null;
            //    while ((m = tbdConstruction.materials(mIndex)) != null)
            //    {
            //        tbdConstruction.materials = tbdConstruction.materialWidth[mIndex];
            //        //tbdConstruction.materialWidth[mIndex] = (float)((construction.Materials.Where(x => x.Name == m.name).FirstOrDefault() as BHM.Material).Thickness);
            //        mIndex++;
            //    }
            //}

            //if (tbdConstruction.type == TBD.ConstructionTypes.tcdOpaqueConstruction)
            //{
            int mIndex = 1;

            TBD.material m = null;
            while ((m = tbdConstruction.materials(mIndex)) != null)
            {
                if (construction.Layers.Where(x => x.Material.Name == m.name).FirstOrDefault() != null)
                {
                    tbdConstruction.materialWidth[mIndex] = (float)(construction.Layers.Where(x => x.Material.Name == m.name).FirstOrDefault().Thickness);
                }

                mIndex++;
            }

            TASDescription tasFragment = construction.FindFragment <TASDescription>(typeof(TASDescription));

            if (tasFragment != null)
            {
                tbdConstruction.description = tasFragment.Description;
            }

            return(tbdConstruction);
        }