Ejemplo n.º 1
0
        private List <BHC.Construction> ReadConstructions(BHX.GBXML gbx, List <string> ids = null)
        {
            List <BHC.Construction> constructions = new List <BHC.Construction>();

            if (gbx.Construction != null)
            {
                if (gbx.Layer != null)
                {
                    foreach (BHX.Construction c in gbx.Construction)
                    {
                        BHX.Layer gbLayer = gbx.Layer.Where(x => x.ID == c.LayerID.LayerIDRef).FirstOrDefault();
                        if (gbLayer != null && gbLayer.MaterialID != null)
                        {
                            List <BHX.Material> gbMaterials = gbx.Material.Where(x => gbLayer.MaterialID.Where(y => y.MaterialIDRef == x.ID).FirstOrDefault() != null).ToList();
                            if (gbMaterials.Count > 0)
                            {
                                List <BHC.Layer> layers = gbMaterials.Select(x => x.FromGBXML()).ToList();
                                constructions.Add(c.FromGBXML(layers));
                            }
                        }
                    }
                }
            }

            return(constructions);
        }
Ejemplo n.º 2
0
        public static BHX.Layer ToGBXML(this List <BHX.Material> materials)
        {
            BHX.Layer l = new BHX.Layer();

            l.ID = "layer";// + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 10);

            List <BHX.MaterialID> materialIDs = new List <BHX.MaterialID>();

            foreach (BHX.Material m in materials)
            {
                l.ID += "-" + m.Name.CleanName();
                BHX.MaterialID id = new BHX.MaterialID();
                id.MaterialIDRef = m.ID;
                materialIDs.Add(id);
            }

            l.MaterialID = materialIDs.ToArray();

            return(l);
        }
Ejemplo n.º 3
0
        private List <BHE.Panel> ReadPanels(BHX.GBXML gbx, List <string> ids = null)
        {
            List <BHE.Panel> panels = new List <BHE.Panel>();

            if (gbx.Campus != null && gbx.Campus.Surface != null)
            {
                foreach (BHX.Surface s in gbx.Campus.Surface)
                {
                    BHE.Panel p = s.FromGBXML();
                    if (gbx.Construction != null)
                    {
                        BHX.Construction c = gbx.Construction.Where(x => x.ID == s.ConstructionIDRef).FirstOrDefault();
                        if (c != null)
                        {
                            BHX.Layer gbLayer = gbx.Layer.Where(x => x.ID == c.LayerID.LayerIDRef).FirstOrDefault();
                            if (gbLayer != null && gbLayer.MaterialID != null)
                            {
                                List <BHX.Material> gbMaterials = gbx.Material.Where(x => gbLayer.MaterialID.Where(y => y.MaterialIDRef == x.ID).FirstOrDefault() != null).ToList();
                                if (gbMaterials.Count > 0)
                                {
                                    List <BHC.Layer> layers = gbMaterials.Select(x => x.FromGBXML()).ToList();
                                    p.Construction = c.FromGBXML(layers);
                                }
                            }
                        }
                    }

                    foreach (BHX.Opening gbxOpening in s.Opening)
                    {
                        p.Openings.Add(gbxOpening.FromGBXML());
                    }
                    panels.Add(p);
                }
            }

            return(panels);
        }
Ejemplo n.º 4
0
        public static GBXML.GBXML ToGBXML(this List <IBHoMObject> objs, GBXMLSettings settings)
        {
            List <Panel>    panels    = objs.Panels();
            List <Space>    spaces    = objs.Spaces();
            List <Level>    levels    = objs.Levels();
            List <Building> buildings = objs.Buildings();

            if (buildings.Count > 1)
            {
                BH.Engine.Reflection.Compute.RecordWarning("More than 1 building has been supplied. Space information will be assigned to the first building but all buildings will be serialised");
            }
            else if (buildings.Count == 0)
            {
                BH.Engine.Reflection.Compute.RecordWarning("No building was supplied, generic empty building is being used to group the data");
                buildings.Add(new Building());
            }

            List <Panel> shadingElements = panels.FilterPanelsByType(PanelType.Shade).Item1;

            panels = panels.FilterPanelsByType(PanelType.Shade).Item2; //Remove shading if it exists

            List <List <Panel> > panelsAsSpaces      = panels.ToSpaces();
            List <Construction>  constructions       = panels.Where(x => x.Construction != null).Select(x => x.Construction as Construction).ToList();
            List <Construction>  windowConstructions = panels.OpeningsFromElements().UniqueConstructions();

            List <GBXML.Building>       xmlBuildings     = buildings.Select(x => x.ToGBXML()).ToList();
            List <GBXML.BuildingStorey> xmlLevels        = levels.Where(x => x.StoreyGeometry(panelsAsSpaces) != null).Select(x => x.ToGBXML(x.StoreyGeometry(panelsAsSpaces), settings)).ToList();
            List <GBXML.Space>          xmlSpaces        = panelsAsSpaces.Select(x => x.ToGBXML(x.Level(levels), settings)).OrderBy(x => x.Name).ToList();
            List <GBXML.Surface>        xmlSurfaces      = new List <GBXML.Surface>();
            List <GBXML.Construction>   xmlConstructions = new List <GBXML.Construction>();
            List <GBXML.Layer>          xmlLayers        = new List <GBXML.Layer>();
            List <GBXML.Material>       xmlMaterials     = new List <GBXML.Material>();
            List <GBXML.WindowType>     xmlWindows       = new List <GBXML.WindowType>();

            List <Panel> usedPanels = new List <Panel>();

            foreach (List <Panel> space in panelsAsSpaces)
            {
                foreach (Panel p in space)
                {
                    if (usedPanels.Where(x => x.BHoM_Guid == p.BHoM_Guid).FirstOrDefault() != null)
                    {
                        continue;
                    }

                    xmlSurfaces.Add(p.ToGBXML(settings, space));
                    usedPanels.Add(p);
                }
            }

            //Check we haven't missed any panels (such as shading) and include them
            foreach (Panel p in panels)
            {
                if (usedPanels.Where(x => x.BHoM_Guid == p.BHoM_Guid).FirstOrDefault() != null)
                {
                    continue;
                }

                xmlSurfaces.Add(p.ToGBXML(settings));
                usedPanels.Add(p);
            }

            //Include shading
            foreach (Panel p in shadingElements)
            {
                if (usedPanels.Where(x => x.BHoM_Guid == p.BHoM_Guid).FirstOrDefault() != null)
                {
                    continue;
                }

                xmlSurfaces.Add(p.ToGBXMLShade(settings));
                usedPanels.Add(p);
            }

            foreach (Construction c in constructions)
            {
                if (c == null)
                {
                    continue;
                }

                GBXML.Construction xmlConc = c.ToGBXML();
                if (xmlConstructions.Where(x => x.ID == xmlConc.ID).FirstOrDefault() != null)
                {
                    continue; //Don't add the same construction twice
                }
                List <GBXML.Material> layerMaterials = new List <GBXML.Material>();
                foreach (Layer l in c.Layers)
                {
                    layerMaterials.Add(l.ToGBXML(settings));
                }

                xmlMaterials.AddRange(layerMaterials);

                GBXML.Layer layer = layerMaterials.ToGBXML();
                xmlLayers.Add(layer);

                xmlConc.LayerID.LayerIDRef = layer.ID;
                xmlConstructions.Add(xmlConc);
            }

            foreach (Opening o in panels.OpeningsFromElements())
            {
                OriginContextFragment openingEnvContextProperties = o.FindFragment <OriginContextFragment>(typeof(OriginContextFragment));

                string nameCheck = "";
                if (openingEnvContextProperties != null)
                {
                    nameCheck = openingEnvContextProperties.TypeName;
                }
                else if (o.OpeningConstruction != null)
                {
                    nameCheck = o.OpeningConstruction.Name;
                }

                var t = xmlWindows.Where(a => a.Name == nameCheck).FirstOrDefault();
                if (t == null && o.OpeningConstruction != null)
                {
                    xmlWindows.Add(o.OpeningConstruction.ToGBXMLWindow(settings, o));
                }
            }

            GBXML.GBXML gbx = new GBXML.GBXML();

            gbx.Campus.Building = xmlBuildings.ToArray();
            gbx.Campus.Location = buildings[0].ToGBXMLLocation(settings);
            gbx.Campus.Building[0].BuildingStorey = xmlLevels.ToArray();
            gbx.Campus.Building[0].Space          = xmlSpaces;
            gbx.Campus.Surface = xmlSurfaces;

            if (settings.IncludeConstructions)
            {
                gbx.Construction = xmlConstructions.ToArray();
                gbx.Layer        = xmlLayers.ToArray();
                gbx.Material     = xmlMaterials.ToArray();
                gbx.WindowType   = xmlWindows.ToArray();
            }
            else
            {
                gbx.WindowType = null;
            }

            //Set the building area
            List <Panel> floorElements = panels.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 p in floorElements)
            {
                buildingFloorArea += p.Area();
            }

            gbx.Campus.Building[0].Area = buildingFloorArea;

            //Document History
            GBXML.DocumentHistory DocumentHistory = new GBXML.DocumentHistory();
            DocumentHistory.CreatedBy.Date = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss");
            gbx.DocumentHistory            = DocumentHistory;

            //Unit set up
            gbx.TemperatureUnit      = settings.UnitSetUp.TemperatureUnit.ToGBX();
            gbx.LengthUnit           = settings.UnitSetUp.LengthUnit.ToGBX();
            gbx.AreaUnit             = settings.UnitSetUp.AreaUnit.ToGBX();
            gbx.VolumeUnit           = settings.UnitSetUp.VolumeUnit.ToGBX();
            gbx.UseSIUnitsForResults = (settings.ResultsUnitType == oM.Adapters.XML.Enums.UnitType.SI ? "true" : "false");

            return(gbx);
        }