Пример #1
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public static void SerializeLevels(List <BH.oM.Architecture.Elements.Level> levels, List <List <Panel> > spaces, BH.oM.XML.GBXML gbx, XMLSettings settings)
        {
            List <BH.oM.XML.BuildingStorey> xmlLevels = new List <BuildingStorey>();

            foreach (BH.oM.Architecture.Elements.Level level in levels)
            {
                string levelName = "";
                if (level.Name == "")
                {
                    levelName = level.Elevation.ToString();
                }
                else
                {
                    levelName = level.Name;
                }

                BuildingStorey storey         = BH.Engine.XML.Convert.ToGBXML(level);
                Polyline       storeyGeometry = BH.Engine.Environment.Query.StoreyGeometry(level, spaces);
                if (storeyGeometry == null)
                {
                    continue;
                }
                storey.PlanarGeometry.PolyLoop = BH.Engine.XML.Convert.ToGBXML(storeyGeometry);
                storey.PlanarGeometry.ID       = "LevelPlanarGeometry-" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 10);
                storey.Name  = levelName;
                storey.Level = (float)level.Elevation;
                storey.ID    = "Level-" + levelName.Replace(" ", "").ToLower();

                xmlLevels.Add(storey);
            }

            gbx.Campus.Building[0].BuildingStorey = xmlLevels.ToArray();
        }
        public static BuildingStorey TogbXML(this Level level, double tolerance = Core.Tolerance.MicroDistance)
        {
            if (level == null)
            {
                return(null);
            }

            BuildingStorey buildingStorey = new BuildingStorey();

            buildingStorey.id    = Core.gbXML.Query.Id(level, typeof(BuildingStorey));
            buildingStorey.Level = Core.Query.Round(level.Elevation, tolerance).ToString();
            buildingStorey.Name  = level.Name;

            return(buildingStorey);
        }
        public ContainmentRelation(IfcStore model, BuildingStorey relatingStructure, List <IModelObject> relatedElements)
        {
            this.relatingStructure = relatingStructure;

            this.relatedElements = relatedElements;


            var resultingRelation = model.Instances.New <IfcRelContainedInSpatialStructure>(rel =>
            {
                foreach (IModelObject entity in relatedElements)
                {
                    rel.RelatedElements.Add(entity.IfcProduct);
                }
                rel.RelatingStructure = relatingStructure.IfcBuildingStorey;
            });
        }
        //same but from a series of Vector Cartesian Coordinates
        public static BuildingStorey MakeStorey(int levelnum, List <Vector.MemorySafe_CartCoord> points)
        {
            BuildingStorey bs = new BuildingStorey();

            bs.id    = "bldg-story-" + levelnum;
            bs.Name  = "Level " + levelnum;
            bs.Level = (levelnum - 1).ToString();

            //there is only one plane per storey
            PlanarGeometry pg = new PlanarGeometry();

            //make polyloop with points
            pg.PolyLoop = new PolyLoop();
            //uses just a simple set of points = List<List<double>>
            pg.PolyLoop = prod.MakePolyLoops(pg.PolyLoop, points);
            //add polyloop to the building storey object
            bs.PlanarGeo = pg;
            return(bs);
        }
        public static List <BuildingStorey> MakeStories(List <List <Vector.MemorySafe_CartCoord> > pointslist)
        {
            List <BuildingStorey> stories = new List <BuildingStorey>();

            for (int i = 1; i <= pointslist.Count(); i++)
            {
                BuildingStorey bs = new BuildingStorey();
                bs.id    = "bldg-story-" + i;
                bs.Name  = "Level " + i;
                bs.Level = (i - 1).ToString();

                //there is only one plane per storey
                PlanarGeometry pg = new PlanarGeometry();
                //make polyloop with points
                pg.PolyLoop = new PolyLoop();
                //uses just a simple set of points = List<List<double>>
                pg.PolyLoop = prod.MakePolyLoops(pg.PolyLoop, pointslist[i]);
                //add polyloop to the building storey object
                bs.PlanarGeo = pg;
                stories.Add(bs);
            }
            return(stories);
        }
Пример #6
0
        static void Main(string[] args)
        {
            //CHANGE PATH HERE.
            string path = @"C:\Users\Scorias\Desktop\IFC trails";

            var editor = new XbimEditorCredentials
            {
                ApplicationDevelopersName = "xBIM Team",
                ApplicationFullName       = "xBIM Toolkit",
                ApplicationIdentifier     = "xBIM",
                ApplicationVersion        = "4.0",
                EditorsFamilyName         = "MoSalah",
                EditorsGivenName          = "sane",
                EditorsOrganisationName   = "Independent"
            };

            RevitSeeker seeker;

            string filename = "RF";
            string filepath = @"C:\Users\Scorias\Desktop\IFC trails";

            using (var stepModel = IfcStore.Open($"{filepath}\\{filename}.ifc"))
            {
                seeker = new RevitSeeker(stepModel);
            }



            using (IfcStore model = IfcStore.Create(editor, IfcSchemaVersion.Ifc2X3, XbimStoreType.InMemoryModel))
            {
                using (var txn = model.BeginTransaction("Initialise Model"))
                {
                    Environment  env    = Environment.Create(model);
                    ModelOptions option = new ModelOptions(model, env);



                    //Local placement of the main storey.
                    LocalPlacement storeyPlacement = new LocalPlacement(model, env.Building.LocalPlacement, env.ProjectAxis);
                    BuildingStorey storey          = new BuildingStorey(model, "Story", storeyPlacement, IfcElementCompositionEnum.ELEMENT, 0);
                    env.AddStorey(model, storey);


                    //Assigning the material and the main column.
                    Material material = new Material(model, "S235JR");


                    var RevitColumns = seeker.RevitColumns;
                    List <TeklaPlate> StoryComponants = new List <TeklaPlate>();
                    TeklaPlatePlacementInitializer plateInitializer;

                    foreach (var rColumn in RevitColumns)
                    {
                        List <RevitPlate> rColumnComp = rColumn.Components;
                        foreach (var revitPlate in rColumnComp)
                        {
                            plateInitializer = new TeklaPlatePlacementInitializer(model, env, revitPlate.Origin, revitPlate.Axis, revitPlate.ReffDirection);
                            TeklaPlate plate = new TeklaPlate(option, plateInitializer.LocalPlacement, revitPlate.OverallWidth, revitPlate.OverallDepth, revitPlate.Height);
                            StoryComponants.Add(plate);
                            plate.AssignMaterial(material);
                        }
                    }
                    storey.AddModelObject(StoryComponants.ToArray());
                    txn.Commit();
                }
                model.SaveAs($"{path}\\TheRealMindWurks.ifcxml");
            }
        }
        public static bool CreateSerial(string filepath)
        {
            //place an in memory object here that represents your class representation of the building
            List <EPObj.MemorySafe_Spaces> myspace = new List <EPObj.MemorySafe_Spaces>();

            myspace = EnergyPlusClass.EPlusSpacestoObjectList(@"C:\Users\Chiensi\Documents\C\Buro Happold\Oregon Sustainability Center\Run 1 + Daylighting Only\Run 1 new.idf");

            gb.gbci = new CultureInfo(String.Empty);

            bool ret = false;

            //the basics
            //constructor to define the basics
            gbXML gbx = new gbXML();

            gbx.lengthUnit      = lengthUnitEnum.Feet;
            gbx.temperatureUnit = temperatureUnitEnum.F;
            string id  = "cmps-1";
            Campus cmp = CreateCampus(id);

            cmp.Buildings = new Building[10000];
            gbx.Campus    = cmp;

            //where does this location information from?  it could be smartly inferred somehow, but otherwise specified by the user/programmer
            Location zeloc = new Location();

            zeloc.Name      = "San Francisco, CA";
            zeloc.Latitude  = "37.795";
            zeloc.Longitude = "-122.394";
            //end the basics
            //tie location and campus back to the gbXML file
            cmp.Location = zeloc;

            //Define the building(s) on the site
            //CHarriman Septempber 19 2013
            cmp.Buildings[0] = MakeBuilding(2000, "bldg-1", buildingTypeEnum.DiningBarLoungeOrLeisure);

            //CHarriman September 19 2013
            //define the stories for each building
            //several ways to do this
            List <List <double> > points = prod.MakeFakeList(5);
            BuildingStorey        bs     = MakeStorey(1, points);

            //CHarriman Jan 15 2014
            //define the spaces for each building (these come from a space object elsewhere
            List <Space> gbSpaces = new List <Space>();

            gbSpaces = MakeSpacesFromEPObj(myspace);


            for (int spacecount = 0; spacecount < gbSpaces.Count(); spacecount++)
            {
                cmp.Buildings[0].Spaces[spacecount] = gbSpaces[spacecount];
            }


            //after making all the spaces, I make the surfaces
            cmp.Surface = new Surface[uniquesurfaces.Count()];
            int surfcount = 0;

            foreach (KeyValuePair <string, Surface> pair in uniquesurfaces)
            {
                Surface surf = new Surface();
                surf.id = pair.Key;
                //this is a hard one, how to deal with this?  For now, everything is external, and idf can sort of tell me
                surf.surfaceType       = pair.Value.surfaceType;
                surf.constructionIdRef = pair.Value.constructionIdRef;
                surf.Name = pair.Value.Name;
                AdjacentSpaceId[] adjspaces = new AdjacentSpaceId[pair.Value.AdjacentSpaceId.Count()];
                int counter = 0;
                foreach (AdjacentSpaceId adj in pair.Value.AdjacentSpaceId)
                {
                    adjspaces[counter] = adj;
                    counter++;
                }
                surf.AdjacentSpaceId = adjspaces;
                RectangularGeometry rg = new RectangularGeometry();
                rg = pair.Value.RectangularGeometry;
                surf.RectangularGeometry = rg;
                surf.PlanarGeometry      = pair.Value.PlanarGeometry;
                cmp.Surface[surfcount]   = surf;
                surfcount++;
            }


            cmp.Buildings[0].bldgStories[0] = bs;

            //write xml to the file
            XmlSerializer szer = new XmlSerializer(typeof(gbXML));
            TextWriter    tw   = new StreamWriter(filepath);

            szer.Serialize(tw, gbx);
            tw.Close();

            return(ret);
        }
Пример #8
0
        public static Building TogbXML(this AdjacencyCluster adjacencyCluster, string name, string description, double tolerance = Tolerance.MicroDistance)
        {
            List <Panel> panels = adjacencyCluster?.GetPanels();

            if (panels == null || panels.Count == 0)
            {
                return(null);
            }

            List <Space> spaces = adjacencyCluster.GetSpaces();

            if (spaces == null)
            {
                return(null);
            }

            //Dictionary of Minimal Elevations and List of Panels
            Dictionary <double, List <Panel> > dictionary_MinElevations = Analytical.Query.MinElevationDictionary(panels, true, Tolerance.MacroDistance);

            //Dictionary of gbXML BuildingStoreys and its elevations
            Dictionary <BuildingStorey, double> dictionary_buildingStoreys = new Dictionary <BuildingStorey, double>();

            //Dictionary of SAM Panels related buildingSorey, minimal elevation and maximal elevation
            Dictionary <Panel, Tuple <BuildingStorey, double, double, double> > dictionary_Panels = new Dictionary <Panel, Tuple <BuildingStorey, double, double, double> >();

            foreach (KeyValuePair <double, List <Panel> > keyValuePair in dictionary_MinElevations)
            {
                BuildingStorey buildingStorey = Architectural.Create.Level(keyValuePair.Key).TogbXML(tolerance);
                dictionary_buildingStoreys[buildingStorey] = keyValuePair.Key;
                foreach (Panel panel in keyValuePair.Value)
                {
                    dictionary_Panels[panel] = new Tuple <BuildingStorey, double, double, double> (buildingStorey, keyValuePair.Key, panel.MinElevation(), panel.MaxElevation());
                }
            }

            List <gbXMLSerializer.Space>     spaces_gbXML = new List <gbXMLSerializer.Space>();
            Dictionary <Guid, SpaceBoundary> dictionary   = new Dictionary <Guid, SpaceBoundary>();

            foreach (Space space in spaces)
            {
                List <Panel> panels_Space = adjacencyCluster.GetRelatedObjects <Panel>(space);
                if (panels_Space == null || panels_Space.Count == 0)
                {
                    continue;
                }

                double         elevation_Level = panels_Space.ConvertAll(x => dictionary_Panels[x].Item2).Min();
                double         elevation_Min   = panels_Space.ConvertAll(x => dictionary_Panels[x].Item3).Min();
                double         elevation_Max   = panels_Space.ConvertAll(x => dictionary_Panels[x].Item4).Max();
                BuildingStorey buildingStorey  = null;
                foreach (KeyValuePair <BuildingStorey, double> keyValuePair in dictionary_buildingStoreys)
                {
                    if (keyValuePair.Value.Equals(elevation_Level))
                    {
                        buildingStorey = keyValuePair.Key;
                        break;
                    }
                }

                if (buildingStorey == null)
                {
                    continue;
                }

                List <Panel> panels_PlanarGeometry = panels_Space.FindAll(x => x.PanelType.PanelGroup() == PanelGroup.Floor || (x.Normal.AlmostSimilar(Vector3D.WorldZ.GetNegated()) && dictionary_Panels[x].Item3 == elevation_Min));
                panels_PlanarGeometry = panels_PlanarGeometry?.MergeCoplanarPanels(Tolerance.MacroDistance, false, false, Tolerance.MacroDistance);
                if (panels_PlanarGeometry == null || panels_PlanarGeometry.Count == 0)
                {
                    continue;
                }

                panels_PlanarGeometry.Sort((x, y) => y.GetArea().CompareTo(x.GetArea()));

                Face3D face3D = panels_PlanarGeometry.First().PlanarBoundary3D?.GetFace3D();
                if (face3D == null)
                {
                    continue;
                }

                double area = face3D.GetArea();
                if (area < Tolerance.MacroDistance)
                {
                    continue;
                }

                double volume = Math.Abs(elevation_Max - elevation_Min) * area;
                if (volume < Tolerance.MacroDistance)
                {
                    continue;
                }

                List <SpaceBoundary> spaceBoundaries = new List <SpaceBoundary>();
                foreach (Panel panel in panels_Space)
                {
                    if (panel == null)
                    {
                        continue;
                    }

                    SpaceBoundary spaceBoundary = null;
                    if (!dictionary.TryGetValue(panel.Guid, out spaceBoundary))
                    {
                        spaceBoundary          = panel.TogbXML_SpaceBoundary(tolerance);
                        dictionary[panel.Guid] = spaceBoundary;
                    }

                    spaceBoundaries.Add(spaceBoundary);
                }

                gbXMLSerializer.Space space_gbXML = new gbXMLSerializer.Space();
                space_gbXML.Name      = space.Name;
                space_gbXML.spacearea = new Area()
                {
                    val = area.ToString()
                };
                space_gbXML.spacevol = new Volume()
                {
                    val = volume.ToString()
                };
                space_gbXML.buildingStoreyIdRef = buildingStorey.id;
                space_gbXML.cadid = new CADObjectId()
                {
                    id = space.Guid.ToString()
                };
                space_gbXML.PlanarGeo = face3D.TogbXML(tolerance);
                space_gbXML.id        = Core.gbXML.Query.Id(space, typeof(gbXMLSerializer.Space));
                space_gbXML.spbound   = spaceBoundaries.ToArray();
                space_gbXML.ShellGeo  = panels_Space.TogbXML(space, tolerance);

                spaces_gbXML.Add(space_gbXML);
            }

            Building building = new Building();

            building.id           = Core.gbXML.Query.Id(adjacencyCluster, typeof(Building));
            building.Name         = name;
            building.Description  = description;
            building.bldgStories  = dictionary_buildingStoreys.Keys.ToArray();
            building.Area         = Analytical.Query.Area(panels, PanelGroup.Floor);
            building.buildingType = buildingTypeEnum.Office;
            building.Spaces       = spaces_gbXML.ToArray();

            return(building);
        }