예제 #1
0
        public static List <Autodesk.Revit.DB.Mechanical.Space> ToRevit(this AdjacencyCluster adjacencyCluster, SpaceSimulationResult spaceSimulationResult, Document document, ConvertSettings convertSettings)
        {
            if (spaceSimulationResult == null)
            {
                return(null);
            }

            List <Autodesk.Revit.DB.Mechanical.Space> result = convertSettings?.GetObjects <Autodesk.Revit.DB.Mechanical.Space>(spaceSimulationResult.Guid);

            if (result != null)
            {
                return(result);
            }

            List <Autodesk.Revit.DB.Mechanical.Space> spaces_Revit = new FilteredElementCollector(document).OfCategory(BuiltInCategory.OST_MEPSpaces).Cast <Autodesk.Revit.DB.Mechanical.Space>().ToList();

            if (adjacencyCluster != null)
            {
                List <Space> spaces_SAM = adjacencyCluster.GetRelatedObjects <Space>(spaceSimulationResult);
                if (spaces_SAM != null)
                {
                    foreach (Space space_SAM in spaces_SAM)
                    {
                        Autodesk.Revit.DB.Mechanical.Space space_Revit = Core.Revit.Query.Element <Autodesk.Revit.DB.Mechanical.Space>(document, spaceSimulationResult);

                        if (space_Revit == null)
                        {
                            space_Revit = Core.Revit.Query.Element <Autodesk.Revit.DB.Mechanical.Space>(document, space_SAM);
                        }

                        if (space_Revit == null)
                        {
                            space_Revit = spaces_Revit?.Find(x => x.get_Parameter(BuiltInParameter.ROOM_NAME)?.AsString() == space_SAM.Name);
                        }

                        if (space_Revit == null)
                        {
                            space_Revit = spaces_Revit?.Find(x => space_SAM.Name.EndsWith(x.get_Parameter(BuiltInParameter.ROOM_NAME)?.AsString()) && space_SAM.Name.StartsWith(x.get_Parameter(BuiltInParameter.ROOM_NUMBER)?.AsString()));
                        }

                        if (space_Revit == null)
                        {
                            continue;
                        }

                        if (result == null)
                        {
                            result = new List <Autodesk.Revit.DB.Mechanical.Space>();
                        }

                        result.Add(space_Revit);
                    }
                }
            }

            if (result == null)
            {
                Autodesk.Revit.DB.Mechanical.Space space_Revit = Core.Revit.Query.Element <Autodesk.Revit.DB.Mechanical.Space>(document, spaceSimulationResult);
                if (space_Revit == null)
                {
                    space_Revit = spaces_Revit?.Find(x => x.get_Parameter(BuiltInParameter.ROOM_NAME)?.AsString() == spaceSimulationResult.Name);
                }

                if (space_Revit != null)
                {
                    result = new List <Autodesk.Revit.DB.Mechanical.Space>()
                    {
                        space_Revit
                    }
                }
                ;
            }

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

            if (convertSettings.ConvertParameters)
            {
                foreach (Autodesk.Revit.DB.Mechanical.Space space in result)
                {
                    Core.Revit.Modify.SetValues(space, spaceSimulationResult);
                    Core.Revit.Modify.SetValues(space, spaceSimulationResult, ActiveSetting.Setting);
                    Modify.SetValues(space, spaceSimulationResult, ActiveSetting.Setting, spaceSimulationResult.LoadType(), convertSettings?.GetParameters());
                }
            }

            convertSettings?.Add(spaceSimulationResult.Guid, result);

            return(result);
        }
    }
예제 #2
0
        public static Campus TogbXML_Campus(this AnalyticalModel analyticalModel, double silverSpacing = Core.Tolerance.MacroDistance, double tolerance = Core.Tolerance.Distance)
        {
            if (analyticalModel == null)
            {
                return(null);
            }

            Campus campus = new Campus();

            campus.id       = Core.gbXML.Query.Id(analyticalModel, typeof(Campus));
            campus.Location = Core.gbXML.Convert.TogbXML(analyticalModel.Location, analyticalModel.Address, tolerance);

            AdjacencyCluster adjacencyCluster = analyticalModel.AdjacencyCluster;

            if (adjacencyCluster != null)
            {
                adjacencyCluster = adjacencyCluster.SplitByInternalEdges(tolerance);
                adjacencyCluster = adjacencyCluster.UpdateNormals(false, silverSpacing, tolerance);

                campus.Buildings = new Building[] { adjacencyCluster.TogbXML(analyticalModel.Name, analyticalModel.Description, tolerance) };
                List <Panel> panels = adjacencyCluster.GetPanels();
                if (panels != null)
                {
                    int            count_opening = 1;
                    List <Surface> surfaces      = new List <Surface>();
                    for (int i = 0; i < panels.Count; i++)
                    {
                        Panel panel = panels[i];
                        if (panel == null)
                        {
                            continue;
                        }

                        List <Space> spaces = adjacencyCluster.GetRelatedObjects <Space>(panel);
                        if (spaces != null && spaces.Count > 1)
                        {
                            //Spaces have to be in correct order!
                            //https://www.gbxml.org/schema_doc/6.01/GreenBuildingXML_Ver6.01.html#Link7

                            SortedDictionary <int, Space> sortedDictionary = new SortedDictionary <int, Space>();
                            spaces.ForEach(x => sortedDictionary[adjacencyCluster.GetIndex(x)] = x);
                            spaces = sortedDictionary.Values.ToList();
                        }

                        Surface surface = panel.TogbXML(spaces, i + 1, count_opening, tolerance);
                        if (surface != null)
                        {
                            surfaces.Add(surface);
                        }

                        if (surface.Opening != null)
                        {
                            count_opening += surface.Opening.Length;
                        }
                    }
                    campus.Surface = surfaces.ToArray();
                }
            }

            return(campus);
        }
예제 #3
0
        public static List <Autodesk.Revit.DB.Mechanical.Space> ToRevit(this AdjacencyCluster adjacencyCluster, ZoneSimulationResult zoneSimulationResult, Document document, ConvertSettings convertSettings)
        {
            if (adjacencyCluster == null || zoneSimulationResult == null)
            {
                return(null);
            }

            List <Autodesk.Revit.DB.Mechanical.Space> result = convertSettings?.GetObjects <Autodesk.Revit.DB.Mechanical.Space>(zoneSimulationResult.Guid);

            if (result != null)
            {
                return(result);
            }

            ZoneSimulationResult zoneSimulationResult_Temp = adjacencyCluster.GetObject <ZoneSimulationResult>(zoneSimulationResult.Guid);

            if (zoneSimulationResult_Temp == null)
            {
                zoneSimulationResult_Temp = zoneSimulationResult;
            }

            List <Zone> zones = adjacencyCluster.GetRelatedObjects <Zone>(zoneSimulationResult_Temp);

            if (zones != null && zones.Count != 0)
            {
                if (convertSettings.ConvertParameters)
                {
                    foreach (Zone zone in zones)
                    {
                        List <Space> spaces = adjacencyCluster.GetSpaces(zone);
                        if (spaces != null)
                        {
                            List <Autodesk.Revit.DB.Mechanical.Space> spaces_Revit = new FilteredElementCollector(document).OfCategory(BuiltInCategory.OST_MEPSpaces).Cast <Autodesk.Revit.DB.Mechanical.Space>().ToList();

                            foreach (Space space in spaces)
                            {
                                Autodesk.Revit.DB.Mechanical.Space space_Revit = Core.Revit.Query.Element <Autodesk.Revit.DB.Mechanical.Space>(document, space);
                                if (space_Revit == null)
                                {
                                    string name = space.Name;
                                    if (name != null)
                                    {
                                        space_Revit = spaces_Revit?.Find(x => x.get_Parameter(BuiltInParameter.ROOM_NAME)?.AsString() == name);
                                    }
                                }

                                if (space_Revit == null)
                                {
                                    continue;
                                }

                                Core.Revit.Modify.SetValues(space_Revit, zoneSimulationResult);
                                Core.Revit.Modify.SetValues(space_Revit, zoneSimulationResult, ActiveSetting.Setting);
                                Modify.SetValues(space_Revit, zoneSimulationResult, ActiveSetting.Setting, zoneSimulationResult.LoadType());
                            }
                        }
                    }
                }
            }

            convertSettings?.Add(zoneSimulationResult.Guid, result);

            return(result);
        }
예제 #4
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);
        }