Пример #1
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="dataAccess">
        /// The DA object is used to retrieve from inputs and store in outputs.
        /// </param>
        protected override void SolveInstance(IGH_DataAccess dataAccess)
        {
            AdjacencyCluster adjacencyCluster = null;

            if (!dataAccess.GetData(0, ref adjacencyCluster))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            SAMObject sAMObject = null;

            if (!dataAccess.GetData(1, ref sAMObject))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            IEnumerable <SAMObject> result = null;

            if (sAMObject is Space)
            {
                result = adjacencyCluster.GetPanels((Space)sAMObject);
            }
            else if (sAMObject is Panel)
            {
                result = adjacencyCluster.GetSpaces((Panel)sAMObject);
            }

            if (result == null)
            {
                dataAccess.SetDataList(0, null);
                return;
            }

            if (result.Count() == 0)
            {
                dataAccess.SetDataList(0, result);
                return;
            }

            dataAccess.SetDataList(0, result.ToList().ConvertAll(x => new GooJSAMObject <SAMObject>(x)));
        }
Пример #2
0
        public static Log Log(this AdjacencyCluster adjacencyCluster, Document document)
        {
            if (adjacencyCluster == null || document == null)
            {
                return(null);
            }

            Log result = new Log();

            foreach (Construction construction in adjacencyCluster.GetConstructions())
            {
                result.AddRange(Log(construction, document));
            }

            foreach (ApertureConstruction apertureConstruction in adjacencyCluster.ApertureConstructions())
            {
                result.AddRange(Log(apertureConstruction, document));
            }

            List <Panel> panels = adjacencyCluster.GetPanels();

            panels?.ForEach(x => Core.Modify.AddRange(result, Core.Revit.Create.Log(x, document)));

            List <Architectural.Level> levels = Architectural.Create.Levels(panels);

            if (levels == null || levels.Count == 0)
            {
                result.Add("Could not find proper levels in AdjacencyCluster", LogRecordType.Error);
            }
            else
            {
                result.AddRange(Architectural.Revit.Create.Log(levels, document));
            }

            foreach (Space space in adjacencyCluster.GetSpaces())
            {
                Core.Modify.AddRange(result, Log(space, document));
            }

            return(result);
        }
Пример #3
0
        public static AdjacencyCluster AdjacencyCluster(IEnumerable <Space> spaces, IEnumerable <Panel> panels, out List <Topology> topologies, out List <Panel> redundantPanels, double minArea = Tolerance.MacroDistance, bool updatePanels = true, bool tryCellComplexByCells = true, Log log = null, double silverSpacing = Tolerance.MacroDistance, double tolerance = Tolerance.Distance)
        {
            Core.Modify.Add(log, "Method Name: {0}, Tolerance: {1}, Update Panels: {2}", "SAM.Analytical.Topologic.Create.AdjacencyCluster", tolerance, updatePanels);

            topologies      = null;
            redundantPanels = null;

            AdjacencyCluster result = new AdjacencyCluster();

            result.AddObjects(spaces);
            result.AddObjects(panels);

            List <Face> faces = new List <Face>();

            int index = 1;

            foreach (Panel panel in result.GetObjects <Panel>())
            {
                if (panel == null)
                {
                    continue;
                }

                Face face = Convert.ToTopologic(panel);
                if (face == null)
                {
                    continue;
                }

                faces.Add(face);
                Core.Modify.Add(log, "Face {0:D4} added. Panel [{1}]", index, panel.Guid);
                index++;
            }

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

            topologies = new List <Topology>();
            List <Cell> cells = null;

            if (tryCellComplexByCells)
            {
                try
                {
                    Core.Modify.Add(log, "Trying to make CellComplex By Cells");
                    Cluster cluster = Cluster.ByTopologies(faces as IList <Topology>);
                    Core.Modify.Add(log, "Cluster.ByTopologies Done");
                    Topology topology = cluster.SelfMerge();
                    Core.Modify.Add(log, "Cluster SelfMerge Done");
                    if (topology.Cells != null && topology.Cells.Count != 0)
                    {
                        cells = topology.Cells?.ToList();
                        CellComplex cellComplex = null;
                        try
                        {
                            cellComplex = CellComplex.ByCells(cells);
                        }
                        catch (Exception exception)
                        {
                            Core.Modify.Add(log, "Cells could not be taken from CellComplex");
                            Core.Modify.Add(log, "Exception Message: {0}", exception.Message);
                        }

                        if (cellComplex != null && cellComplex.Cells != null && cellComplex.Cells.Count != 0)
                        {
                            topologies.Add(cellComplex);

                            cells = cellComplex.Cells?.ToList();
                        }
                        else
                        {
                            topologies.Add(topology);
                            Core.Modify.Add(log, "Cells taken from Cluster");
                        }
                    }
                }
                catch (Exception exception)
                {
                    Core.Modify.Add(log, "Cannot create CellComplex By Cells or Cells form Cluster SelfMerge");
                    Core.Modify.Add(log, "Exception Message: {0}", exception.Message);
                    cells = null;
                }
            }

            if (cells == null)
            {
                try
                {
                    Core.Modify.Add(log, "Trying to make CellComplex By Faces");
                    CellComplex cellComplex = CellComplex.ByFaces(faces, tolerance);
                    topologies.Add(cellComplex);
                    cells = cellComplex.Cells?.ToList();
                    Core.Modify.Add(log, "CellComplex By Faces Created");
                }
                catch (Exception exception)
                {
                    Core.Modify.Add(log, "Cannot create CellComplex By Faces");
                    Core.Modify.Add(log, "Exception Message: {0}", exception.Message);

                    cells = null;
                }
            }

            if (cells == null || cells.Count == 0)
            {
                Core.Modify.Add(log, "No cells found");
                return(null);
            }

            List <Geometry.Spatial.Shell> shells = cells.ToSAM();

            Core.Modify.Add(log, "Single CellComplex converted to shells");

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

            //Matching spaces with shells
            Dictionary <Geometry.Spatial.Shell, List <Space> > dictionary_Spaces = new Dictionary <Geometry.Spatial.Shell, List <Space> >();

            if (spaces != null)
            {
                foreach (Space space in spaces)
                {
                    if (space == null || space.Location == null || !space.IsPlaced())
                    {
                        continue;
                    }

                    List <Geometry.Spatial.Shell> shells_Temp = Analytical.Query.SpaceShells(shells, space.Location, silverSpacing, tolerance);
                    if (shells_Temp == null || shells_Temp.Count == 0)
                    {
                        continue;
                    }

                    foreach (Geometry.Spatial.Shell shell in shells_Temp)
                    {
                        if (!dictionary_Spaces.TryGetValue(shell, out List <Space> spaces_Shell))
                        {
                            spaces_Shell             = new List <Space>();
                            dictionary_Spaces[shell] = spaces_Shell;
                        }
                        spaces_Shell.Add(space);
                    }
                }
            }

            HashSet <Guid> guids_Updated = new HashSet <Guid>();

            Dictionary <Panel, Face3D> dictionary_Panel_Face3D = new Dictionary <Panel, Face3D>();

            result.GetObjects <Panel>().ForEach(x => dictionary_Panel_Face3D[x] = x.GetFace3D());

            index = 1;
            List <Tuple <Panel, Point3D> > tuples_InternalPoint3D = new List <Tuple <Panel, Point3D> >();

            for (int i = 0; i < shells.Count; i++)
            {
                Geometry.Spatial.Shell shell = shells[i];
                if (shell == null)
                {
                    return(null);
                }

                Core.Modify.Add(log, "Simplifying shell");
                //shell.Simplify(tolerance); // Low tolerance cause of rounding issues
                shell.Simplify();

                Core.Modify.Add(log, "Extracting faces from shell");
                List <Face3D> face3Ds = shell?.Face3Ds;
                if (face3Ds == null)
                {
                    Core.Modify.Add(log, "No face2Ds found in Shell");
                    continue;
                }

                dictionary_Spaces.TryGetValue(shell, out List <Space> spaces_Shell);

                if (spaces_Shell == null || spaces_Shell.Count == 0)
                {
                    Core.Modify.Add(log, "Creating new Space");

                    Point3D location = shell.CalculatedInternalPoint3D(silverSpacing, tolerance);
                    if (location == null)
                    {
                        continue;
                    }

                    Space space = new Space("Cell " + index, location);
                    index++;

                    if (!result.AddObject(space))
                    {
                        continue;
                    }

                    spaces_Shell = new List <Space>()
                    {
                        space
                    };
                    dictionary_Spaces[shell] = spaces_Shell;
                }

                if (spaces_Shell == null || spaces_Shell.Count == 0)
                {
                    continue;
                }

                double volume = double.NaN;
                if (cells[i] != null)
                {
                    Core.Modify.Add(log, "Calculating Volume");
                    volume = CellUtility.Volume(cells[i]);

                    foreach (Space space_Shell in spaces_Shell)
                    {
                        space_Shell.SetValue(SpaceParameter.Volume, volume);
                    }
                }

                Core.Modify.Add(log, "Upadting Panels");
                foreach (Face3D face3D in face3Ds)
                {
                    if (minArea != 0 && face3D.GetArea() <= minArea)
                    {
                        Core.Modify.Add(log, "Face3D is too small");
                        continue;
                    }

                    Core.Modify.Add(log, "Looking for existing Panel");
                    Tuple <Panel, Point3D> tuple_InternalPoint3D = tuples_InternalPoint3D.Find(x => face3D.Inside(x.Item2, tolerance));
                    if (tuple_InternalPoint3D != null)
                    {
                        Core.Modify.Add(log, "Existing Panel found: {0}", tuple_InternalPoint3D.Item1.Guid);
                        foreach (Space space in spaces_Shell)
                        {
                            if (result.AddRelation(space, tuple_InternalPoint3D.Item1))
                            {
                                Core.Modify.Add(log, "Space [{0}] and Panel [{1}] relation added", space.Guid, tuple_InternalPoint3D.Item1.Guid);
                            }
                        }
                        continue;
                    }

                    Core.Modify.Add(log, "Looking for old Panel");
                    //Panel panel_Old = Query.SimilarPanel(face3D, dictionary_Panel_Face3D);
                    //if (panel_Old == null)
                    //    continue;

                    List <Panel> panels_Old = Query.SimilarPanels(face3D, dictionary_Panel_Face3D);
                    if (panels_Old == null || panels_Old.Count == 0)
                    {
                        continue;
                    }

                    Panel panel_Old = panels_Old.First();
                    if (panels_Old.Count > 1)
                    {
                        if (redundantPanels == null)
                        {
                            redundantPanels = new List <Panel>();
                        }

                        panels_Old.RemoveAt(0);
                        redundantPanels.AddRange(panels_Old);
                    }

                    Core.Modify.Add(log, "Old Panel found: {0}", panel_Old.Guid);

                    Panel panel_New = null;

                    if (updatePanels)
                    {
                        if (guids_Updated.Contains(panel_Old.Guid))
                        {
                            panel_New = Analytical.Create.Panel(Guid.NewGuid(), panel_Old, face3D);
                            Core.Modify.Add(log, "Creating new Panel for Old Panel [{0}]. New Panel [{1}]", panel_Old.Guid, panel_New.Guid);
                        }
                        else
                        {
                            panel_New = Analytical.Create.Panel(panel_Old.Guid, panel_Old, face3D);
                            guids_Updated.Add(panel_Old.Guid);
                            Core.Modify.Add(log, "Updating Panel [{0}] with new geometry", panel_New.Guid);
                        }

                        result.AddObject(panel_New);
                    }
                    else
                    {
                        panel_New = Analytical.Create.Panel(panel_Old.Guid, panel_Old, face3D);
                        Core.Modify.Add(log, "Creating temporary Panel for Panel [{0}]", panel_New.Guid);
                    }

                    if (panel_New == null)
                    {
                        continue;
                    }

                    tuples_InternalPoint3D.Add(new Tuple <Panel, Point3D>(panel_New, face3D.InternalPoint3D(tolerance)));

                    foreach (Space space in spaces_Shell)
                    {
                        if (result.AddRelation(space, panel_New))
                        {
                            Core.Modify.Add(log, "Space [{0}] and Panel [{1}] relation added", space.Guid, panel_New.Guid);
                        }
                    }

                    Core.Modify.Add(log, "Adding face finished");
                }
            }

            if (redundantPanels != null && redundantPanels.Count != 0)
            {
                Core.Modify.Add(log, "Solving Redundant Panels");
                foreach (Panel panel in redundantPanels)
                {
                    result.RemoveObject <Panel>(panel.Guid);
                }
            }

            List <Panel> panels_Shading = Analytical.Query.CutShading(result.GetPanels(), panels, tolerance);

            if (panels_Shading != null || panels_Shading.Count != 0)
            {
                foreach (Panel panel_Shading in panels_Shading)
                {
                    result.AddObject(panel_Shading);
                }
            }

            Core.Modify.Add(log, "AdjacencyCluster verification");
            Log log_AdjacencyCluster = Analytical.Create.Log(result);

            if (log != null)
            {
                log.AddRange(log_AdjacencyCluster);
            }

            Core.Modify.Add(log, "Process completed");
            return(result);
        }
Пример #4
0
        public static Model ToLadybugTools(this AnalyticalModel analyticalModel, double silverSpacing = Tolerance.MacroDistance, double tolerance = Tolerance.Distance)
        {
            if (analyticalModel == null)
            {
                return(null);
            }

            AnalyticalModel analyticalModel_Temp = new AnalyticalModel(analyticalModel);

            analyticalModel_Temp.OffsetAperturesOnEdge(0.1, tolerance);
            analyticalModel_Temp.ReplaceTransparentPanels(0.1);

            string uniqueName = Core.LadybugTools.Query.UniqueName(analyticalModel_Temp);

            AdjacencyCluster adjacencyCluster = analyticalModel_Temp.AdjacencyCluster;

            List <Room> rooms = null;
            List <AnyOf <IdealAirSystemAbridged, VAV, PVAV, PSZ, PTAC, ForcedAirFurnace, FCUwithDOASAbridged, WSHPwithDOASAbridged, VRFwithDOASAbridged, FCU, WSHP, VRF, Baseboard, EvaporativeCooler, Residential, WindowAC, GasUnitHeater> > hvacs = null;

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

            if (spaces != null)
            {
                hvacs = new List <AnyOf <IdealAirSystemAbridged, VAV, PVAV, PSZ, PTAC, ForcedAirFurnace, FCUwithDOASAbridged, WSHPwithDOASAbridged, VRFwithDOASAbridged, FCU, WSHP, VRF, Baseboard, EvaporativeCooler, Residential, WindowAC, GasUnitHeater> >();
                rooms = new List <Room>();

                Dictionary <double, List <Panel> > dictionary_elevations = Analytical.Query.MinElevationDictionary(adjacencyCluster.GetPanels(), true);
                List <Level> levels = dictionary_elevations?.Keys.ToList().ConvertAll(x => Architectural.Create.Level(x));

                for (int i = 0; i < spaces.Count; i++)
                {
                    Space space = spaces[i];
                    if (space == null)
                    {
                        continue;
                    }

                    Room room = space.ToLadybugTools(analyticalModel_Temp, silverSpacing, tolerance);
                    if (room == null)
                    {
                        continue;
                    }

                    if (levels != null && levels.Count > 0)
                    {
                        double elevation_Min = space.MinElevation(adjacencyCluster);
                        if (!double.IsNaN(elevation_Min))
                        {
                            double difference_Min = double.MaxValue;
                            Level  level_Min      = null;
                            foreach (Level level in levels)
                            {
                                double difference = System.Math.Abs(elevation_Min - level.Elevation);
                                if (difference < difference_Min)
                                {
                                    difference_Min = difference;
                                    level_Min      = level;
                                }
                            }

                            room.Story = level_Min.Name;
                        }
                    }

                    InternalCondition internalCondition = space.InternalCondition;
                    if (internalCondition != null)
                    {
                        //Michal Idea of filtering Uncondition Spaces
                        string name_InternalCondition = internalCondition.Name;

                        if (name_InternalCondition == null || (name_InternalCondition != null && !name_InternalCondition.ToLower().Contains("unconditioned") && !name_InternalCondition.ToLower().Contains("external")))
                        {
                            IdealAirSystemAbridged idealAirSystemAbridged = new IdealAirSystemAbridged(string.Format("{0}__{1}", i.ToString(), "IdealAir"), string.Format("Ideal Air System Abridged {0}", space.Name));
                            hvacs.Add(idealAirSystemAbridged);

                            if (room.Properties == null)
                            {
                                room.Properties = new RoomPropertiesAbridged();
                            }

                            if (room.Properties.Energy == null)
                            {
                                room.Properties.Energy = new RoomEnergyPropertiesAbridged();
                            }

                            room.Properties.Energy.Hvac = idealAirSystemAbridged.Identifier;
                        }
                    }

                    rooms.Add(room);
                }
            }

            List <Shade> shades         = null;
            List <Face>  faces_Orphaned = null;

            List <Panel> panels_Shading = adjacencyCluster.GetShadingPanels();

            if (panels_Shading != null)
            {
                foreach (Panel panel_Shading in panels_Shading)
                {
                    if (panels_Shading == null)
                    {
                        continue;
                    }

                    if (panel_Shading.PanelType == PanelType.Shade)
                    {
                        Shade shade = panel_Shading.ToLadybugTools_Shade();
                        if (shade == null)
                        {
                            continue;
                        }

                        if (shades == null)
                        {
                            shades = new List <Shade>();
                        }

                        shades.Add(shade);
                    }
                    else
                    {
                        Face face_Orphaned = panel_Shading.ToLadybugTools_Face();
                        if (face_Orphaned == null)
                        {
                            continue;
                        }

                        if (faces_Orphaned == null)
                        {
                            faces_Orphaned = new List <Face>();
                        }

                        faces_Orphaned.Add(face_Orphaned);
                    }
                }
            }

            MaterialLibrary materialLibrary = analyticalModel_Temp?.MaterialLibrary;

            List <Construction>         constructions_AdjacencyCluster         = adjacencyCluster.GetConstructions();
            List <ApertureConstruction> apertureConstructions_AdjacencyCluster = adjacencyCluster.GetApertureConstructions();

            ConstructionSetAbridged constructionSetAbridged = Core.LadybugTools.Query.DefaultConstructionSetAbridged();
            List <HoneybeeSchema.AnyOf <ConstructionSetAbridged, ConstructionSet> > constructionSets = new List <HoneybeeSchema.AnyOf <ConstructionSetAbridged, ConstructionSet> >();// { constructionSetAbridged  };

            List <AnyOf <OpaqueConstructionAbridged, WindowConstructionAbridged, WindowConstructionShadeAbridged, AirBoundaryConstructionAbridged, OpaqueConstruction, WindowConstruction, WindowConstructionShade, WindowConstructionDynamicAbridged, WindowConstructionDynamic, AirBoundaryConstruction, ShadeConstruction> > constructions = new List <AnyOf <OpaqueConstructionAbridged, WindowConstructionAbridged, WindowConstructionShadeAbridged, AirBoundaryConstructionAbridged, OpaqueConstruction, WindowConstruction, WindowConstructionShade, WindowConstructionDynamicAbridged, WindowConstructionDynamic, AirBoundaryConstruction, ShadeConstruction> >();

            Dictionary <string, HoneybeeSchema.Energy.IMaterial> dictionary_Materials = new Dictionary <string, HoneybeeSchema.Energy.IMaterial>();

            if (constructions_AdjacencyCluster != null)
            {
                foreach (Construction construction in constructions_AdjacencyCluster)
                {
                    List <ConstructionLayer> constructionLayers = construction.ConstructionLayers;
                    if (constructionLayers == null)
                    {
                        continue;
                    }

                    constructions.Add(construction.ToLadybugTools());
                    constructions.Add(construction.ToLadybugTools(false));

                    foreach (ConstructionLayer constructionLayer in constructionLayers)
                    {
                        IMaterial material = constructionLayer.Material(materialLibrary);
                        if (material == null)
                        {
                            continue;
                        }

                        if (dictionary_Materials.ContainsKey(material.Name))
                        {
                            continue;
                        }

                        if (material is GasMaterial)
                        {
                            List <Panel>  panels = Analytical.Query.Panels(adjacencyCluster, construction);
                            List <double> tilts  = panels.ConvertAll(x => Analytical.Query.Tilt(x).Round(Tolerance.MacroDistance));
                            double        tilt   = tilts.Distinct().ToList().Average();

                            tilt = Units.Convert.ToRadians(tilt);

                            dictionary_Materials[material.Name] = ((GasMaterial)material).ToLadybugTools(tilt, constructionLayer.Thickness);
                        }
                        else if (material is OpaqueMaterial)
                        {
                            EnergyMaterial energyMaterial = ((OpaqueMaterial)material).ToLadybugTools();
                            dictionary_Materials[material.Name] = energyMaterial;
                            if (!double.IsNaN(constructionLayer.Thickness))
                            {
                                energyMaterial.Thickness = constructionLayer.Thickness;
                            }
                        }
                    }
                }
            }

            if (apertureConstructions_AdjacencyCluster != null)
            {
                foreach (ApertureConstruction apertureConstruction in apertureConstructions_AdjacencyCluster)
                {
                    List <ConstructionLayer> constructionLayers = null;

                    constructionLayers = apertureConstruction.PaneConstructionLayers;
                    if (constructionLayers != null)
                    {
                        MaterialType materialType = Analytical.Query.MaterialType(constructionLayers, materialLibrary);
                        if (materialType != MaterialType.Undefined && materialType != MaterialType.Gas)
                        {
                            if (materialType == MaterialType.Opaque)
                            {
                                constructions.Add(apertureConstruction.ToLadybugTools());
                                constructions.Add(apertureConstruction.ToLadybugTools(false));
                            }
                            else
                            {
                                constructions.Add(apertureConstruction.ToLadybugTools_WindowConstructionAbridged());
                                constructions.Add(apertureConstruction.ToLadybugTools_WindowConstructionAbridged(false));
                            }

                            foreach (ConstructionLayer constructionLayer in constructionLayers)
                            {
                                IMaterial material = constructionLayer.Material(materialLibrary);
                                if (material == null)
                                {
                                    continue;
                                }

                                string name = material.Name;

                                if (dictionary_Materials.ContainsKey(name))
                                {
                                    continue;
                                }

                                if (material is TransparentMaterial)
                                {
                                    dictionary_Materials[name] = ((TransparentMaterial)material).ToLadybugTools();
                                }
                                else if (material is GasMaterial)
                                {
                                    dictionary_Materials[name] = ((GasMaterial)material).ToLadybugTools_EnergyWindowMaterialGas();
                                }
                                else
                                {
                                    dictionary_Materials[name] = ((OpaqueMaterial)material).ToLadybugTools();
                                }
                            }
                        }
                    }
                }
            }


            ProfileLibrary profileLibrary = analyticalModel.ProfileLibrary;

            Dictionary <System.Guid, ProgramType> dictionary_InternalConditions = new Dictionary <System.Guid, ProgramType>();

            if (spaces != null)
            {
                foreach (Space space in spaces)
                {
                    InternalCondition internalCondition = space?.InternalCondition;
                    if (internalCondition == null)
                    {
                        continue;
                    }

                    if (dictionary_InternalConditions.ContainsKey(internalCondition.Guid))
                    {
                        continue;
                    }

                    ProgramType programType = space.ToLadybugTools(adjacencyCluster, profileLibrary);
                    if (programType != null)
                    {
                        dictionary_InternalConditions[internalCondition.Guid] = programType;
                    }
                }
            }

            List <AnyOf <EnergyMaterial, EnergyMaterialNoMass, EnergyWindowMaterialGas, EnergyWindowMaterialGasCustom, EnergyWindowMaterialGasMixture, EnergyWindowMaterialSimpleGlazSys, EnergyWindowMaterialBlind, EnergyWindowMaterialGlazing, EnergyWindowMaterialShade> > materials = new List <AnyOf <EnergyMaterial, EnergyMaterialNoMass, EnergyWindowMaterialGas, EnergyWindowMaterialGasCustom, EnergyWindowMaterialGasMixture, EnergyWindowMaterialSimpleGlazSys, EnergyWindowMaterialBlind, EnergyWindowMaterialGlazing, EnergyWindowMaterialShade> >();

            HoneybeeSchema.Helper.EnergyLibrary.DefaultMaterials?.ToList().ForEach(x => materials.Add(x as dynamic));
            dictionary_Materials.Values.ToList().ForEach(x => materials.Add(x as dynamic));

            List <AnyOf <ScheduleRulesetAbridged, ScheduleFixedIntervalAbridged, ScheduleRuleset, ScheduleFixedInterval> > schedules = new List <AnyOf <ScheduleRulesetAbridged, ScheduleFixedIntervalAbridged, ScheduleRuleset, ScheduleFixedInterval> >();

            HoneybeeSchema.Helper.EnergyLibrary.DefaultScheduleRuleset?.ToList().ForEach(x => schedules.Add(x));

            List <HoneybeeSchema.AnyOf <ProgramTypeAbridged, ProgramType> > programTypes = new List <HoneybeeSchema.AnyOf <ProgramTypeAbridged, ProgramType> >();

            HoneybeeSchema.Helper.EnergyLibrary.DefaultProgramTypes?.ToList().ForEach(x => programTypes.Add(x));
            dictionary_InternalConditions.Values.ToList().ForEach(x => programTypes.Add(x));

            List <ScheduleTypeLimit> scheduleTypeLimits = new List <ScheduleTypeLimit>();

            HoneybeeSchema.Helper.EnergyLibrary.DefaultScheduleTypeLimit?.ToList().ForEach(x => scheduleTypeLimits.Add(x));

            constructionSets.RemoveAll(x => x == null);
            constructions.RemoveAll(x => x == null);
            materials.RemoveAll(x => x == null);

            ModelEnergyProperties modelEnergyProperties = new ModelEnergyProperties(constructionSets, constructions, materials, hvacs, null, programTypes, schedules, scheduleTypeLimits);

            ModelProperties modelProperties = new ModelProperties(modelEnergyProperties);

            Model model = new Model(uniqueName, modelProperties, adjacencyCluster.Name, null, rooms, faces_Orphaned, shades);

            model.AngleTolerance = Units.Convert.ToDegrees(Tolerance.Angle);// 2;
            model.Tolerance      = Tolerance.MacroDistance;

            return(model);
        }
Пример #5
0
        protected override void TrySolveInstance(IGH_DataAccess dataAccess)
        {
            int index            = -1;
            int index_Elements   = -1;
            int index_Successful = -1;

            index_Successful = Params.IndexOfOutputParam("successful");
            if (index_Successful != -1)
            {
                dataAccess.SetData(index_Successful, false);
            }

            index_Elements = Params.IndexOfOutputParam("elements");
            if (index_Elements != -1)
            {
                dataAccess.SetData(index_Elements, null);
            }

            bool run = false;

            index = Params.IndexOfInputParam("_run");
            if (index == -1 || !dataAccess.GetData(index, ref run) || !run)
            {
                return;
            }

            ConvertSettings convertSettings = null;

            index = Params.IndexOfInputParam("_convertSettings_");
            if (index != -1)
            {
                dataAccess.GetData(index, ref convertSettings);
            }

            convertSettings = this.UpdateSolutionEndEventHandler(convertSettings);

            SAMObject sAMObject = null;

            index = Params.IndexOfInputParam("_analytical");
            if (index == -1 || !dataAccess.GetData(index, ref sAMObject))
            {
                return;
            }

            Document document = RhinoInside.Revit.Revit.ActiveDBDocument;

            StartTransaction(document);

            if (!(sAMObject is Panel) && !(sAMObject is Aperture) && !(sAMObject is Space) && !(sAMObject is AdjacencyCluster) && !(sAMObject is AnalyticalModel))
            {
                return;
            }

            AdjacencyCluster adjacencyCluster = null;

            if (sAMObject is AdjacencyCluster)
            {
                adjacencyCluster = (AdjacencyCluster)sAMObject;
                convertSettings.AddParameter("AdjacencyCluster", adjacencyCluster);
            }
            else if (sAMObject is AnalyticalModel)
            {
                adjacencyCluster = ((AnalyticalModel)sAMObject).AdjacencyCluster;
                convertSettings.AddParameter("AnalyticalModel", (AnalyticalModel)sAMObject);
            }


            if (adjacencyCluster != null)
            {
                adjacencyCluster.GetPanels()?.ForEach(x => Core.Revit.Modify.RemoveExisting(convertSettings, document, x));
                adjacencyCluster.GetSpaces()?.ForEach(x => Core.Revit.Modify.RemoveExisting(convertSettings, document, x));
            }
            else
            {
                Core.Revit.Modify.RemoveExisting(convertSettings, document, sAMObject);
            }


            object @object = Analytical.Revit.Convert.ToRevit(sAMObject as dynamic, document, convertSettings);

            IEnumerable <Element> elements = null;

            if (@object is IEnumerable)
            {
                elements = ((IEnumerable)@object).Cast <Element>();
            }
            else
            {
                elements = new List <Element>()
                {
                    @object as Element
                }
            };

            //if(elements != null)
            //{
            //    foreach(Element element in elements)
            //    {
            //        ElementId elementId = element.Id;
            //        if (elementId == null)
            //            continue;

            //        elementIds.Add(elementId);
            //    }
            //}

            if (index_Elements != -1)
            {
                dataAccess.SetDataList(index_Elements, elements);
            }

            if (index_Successful != -1)
            {
                dataAccess.SetData(index_Successful, elements != null && elements.Count() > 0);
            }
        }

        //protected override void OnAfterStart(Document document, string strTransactionName)
        //{
        //    base.OnAfterStart(document, strTransactionName);

        //    elementIds = new HashSet<ElementId>();
        //}

        //protected override void OnBeforeCommit(Document document, string strTransactionName)
        //{
        //    base.OnBeforeCommit(document, strTransactionName);

        //    if(elementIds != null && elementIds.Count != 0)
        //    {
        //        List<Wall> walls = new FilteredElementCollector(document, elementIds).OfClass(typeof(Wall)).Cast<Wall>().ToList();
        //        if(walls != null && walls.Count != 0)
        //        {
        //            Dictionary<Wall, int> dictionary = new Dictionary<Wall, int>();
        //            walls.ForEach(x => dictionary[x] = x.get_Parameter(BuiltInParameter.WALL_ATTR_ROOM_BOUNDING).AsInteger());

        //            using (SubTransaction subTransaction = new SubTransaction(document))
        //            {
        //                subTransaction.Start();

        //                foreach (Wall wall in dictionary.Keys)
        //                    wall.get_Parameter(BuiltInParameter.WALL_ATTR_ROOM_BOUNDING).Set(0);

        //                document.Regenerate();

        //                subTransaction.Commit();

        //                subTransaction.Start();

        //                foreach (KeyValuePair<Wall, int> keyValuePair in dictionary)
        //                    keyValuePair.Key.get_Parameter(BuiltInParameter.WALL_ATTR_ROOM_BOUNDING).Set(keyValuePair.Value);

        //                subTransaction.Commit();
        //            }
        //        }
        //    }
        //}
    }
Пример #6
0
        public static List <SAMType> UpdateConstructions(this TBDDocument tBDDocument, AnalyticalModel analyticalModel)
        {
            if (tBDDocument == null || analyticalModel == null)
            {
                return(null);
            }

            Building building = tBDDocument.Building;

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

            AdjacencyCluster adjacencyCluster = analyticalModel.AdjacencyCluster;

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

            adjacencyCluster.SetConstructionsDefaultPanelType();

            List <SAMType> result = new List <SAMType>();

            Dictionary <System.Guid, Construction> dictionary_Construction = new Dictionary <System.Guid, Construction>();

            foreach (Panel panel in adjacencyCluster.GetPanels())
            {
                if (panel == null || panel.PanelType == PanelType.Air)
                {
                    continue;
                }

                Construction construction = panel.Construction;
                if (construction == null)
                {
                    continue;
                }

                dictionary_Construction[construction.Guid] = construction;
            }

            if (dictionary_Construction != null && dictionary_Construction.Count != 0)
            {
                List <Construction> constructions = UpdateConstructions(building, dictionary_Construction.Values, analyticalModel.MaterialLibrary);
                if (constructions != null && constructions.Count != 0)
                {
                    constructions.ForEach(x => result.Add(x));
                }
            }

            List <ApertureConstruction> apertureConstructions = analyticalModel.AdjacencyCluster?.GetApertureConstructions();

            if (apertureConstructions != null && apertureConstructions.Count != 0)
            {
                apertureConstructions = UpdateConstructions(building, apertureConstructions, analyticalModel.MaterialLibrary);
                if (apertureConstructions != null && apertureConstructions.Count != 0)
                {
                    apertureConstructions.ForEach(x => result.Add(x));
                }
            }

            return(result);
        }
Пример #7
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="dataAccess">
        /// The DA object is used to retrieve from inputs and store in outputs.
        /// </param>
        protected override void SolveInstance(IGH_DataAccess dataAccess)
        {
            bool run = false;

            if (!dataAccess.GetData(6, ref run))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                dataAccess.SetData(2, false);
                return;
            }
            if (!run)
            {
                return;
            }

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

            if (!dataAccess.GetDataList(0, panels) || panels == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                dataAccess.SetData(2, false);
                return;
            }

            List <Space> spaces = new List <Space>();

            dataAccess.GetDataList(1, spaces);

            double tolerance = double.NaN;

            if (!dataAccess.GetData(2, ref tolerance) || double.IsNaN(tolerance))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                dataAccess.SetData(2, false);
                return;
            }

            bool tryCellComplexByCells = false;

            if (!dataAccess.GetData(3, ref tryCellComplexByCells))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                dataAccess.SetData(2, false);
                return;
            }

            //string reportPath = null;
            //if (dataAccess.GetData(4, ref reportPath))
            //{
            //    if (System.IO.File.Exists(reportPath))
            //        System.IO.File.Delete(reportPath);
            //}

            double minArea = Tolerance.MacroDistance;

            dataAccess.GetData(4, ref minArea);

            double silverSpacing = Tolerance.MacroDistance;

            dataAccess.GetData(5, ref silverSpacing);

            List <Topology> topologies = null;
            Log             log        = new Log();

            List <Panel>     panels_Redundant = null;
            AdjacencyCluster adjacencyCluster = Analytical.Topologic.Create.AdjacencyCluster(spaces, panels, out topologies, out panels_Redundant, minArea, true, tryCellComplexByCells, log, silverSpacing, tolerance);

            if (adjacencyCluster != null)
            {
                List <Space> spaces_Temp = adjacencyCluster.GetSpaces();
                if (spaces_Temp == null || spaces_Temp.Count == 0)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No spaces have been detected");
                }
                else
                {
                    List <Point3D> locations = spaces_Temp.ConvertAll(x => x.Location);

                    if (locations.RemoveAll(x => x == null) > 0)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "There are spaces without Location Points");
                    }

                    List <Space> spaces_Unbounded = new List <Space>();
                    List <Space> spaces_Multiple  = new List <Space>();

                    HashSet <int>        indexes_Multiple     = new HashSet <int>();
                    List <List <Space> > spacesList_Locations = adjacencyCluster.GetSpaces(locations);
                    for (int i = 0; i < spacesList_Locations.Count; i++)
                    {
                        List <Space> spaces_Locations = spacesList_Locations[i];
                        Point3D      point3D_Location = locations[i];

                        if (spaces_Locations == null)
                        {
                            spaces_Unbounded.Add(spaces_Temp.Find(x => point3D_Location.AlmostEquals(x.Location)));
                            continue;
                        }

                        if (spacesList_Locations.Count > 2)
                        {
                            indexes_Multiple.Add(i);
                        }
                    }

                    foreach (Space space in spaces_Unbounded)
                    {
                        string text = "There are unbounded spaces in topology model";
                        if (!string.IsNullOrWhiteSpace(space.Name))
                        {
                            text += " " + space.Name;
                        }

                        text += " " + "Guid: " + space.Guid;

                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, text);
                    }

                    foreach (Space space in spaces_Multiple)
                    {
                        string text = "There are multiple spaces in topology cell";
                        if (!string.IsNullOrWhiteSpace(space.Name))
                        {
                            text += " " + space.Name;
                        }

                        text += " " + "Guid: " + space.Guid;

                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, text);
                    }
                }

                dataAccess.SetData(0, new GooAdjacencyCluster(adjacencyCluster));
            }
            else
            {
                dataAccess.SetData(0, null);
            }

            dataAccess.SetDataList(1, topologies);
            dataAccess.SetDataList(2, adjacencyCluster?.GetPanels());
            dataAccess.SetDataList(3, adjacencyCluster?.GetSpaces());
            dataAccess.SetDataList(4, adjacencyCluster?.GetInternalPanels());
            dataAccess.SetDataList(5, adjacencyCluster?.GetExternalPanels());
            dataAccess.SetDataList(6, adjacencyCluster?.GetShadingPanels());
            dataAccess.SetDataList(7, panels_Redundant);
            dataAccess.SetData(8, new GooLog(log));
            dataAccess.SetData(9, adjacencyCluster != null);
        }
Пример #8
0
        public static double InfiltrationAirFlowPerExteriorArea(this AdjacencyCluster adjacencyCluster, Space space)
        {
            if (adjacencyCluster == null || space == null)
            {
                return(double.NaN);
            }

            double volume = double.NaN;

            space.TryGetValue(SpaceParameter.Volume, out volume);
            if (double.IsNaN(volume))
            {
                return(double.NaN);
            }

            InternalCondition internalCondintion = space.InternalCondition;

            if (internalCondintion == null)
            {
                return(double.NaN);
            }

            double airFlow = Analytical.Query.CalculatedInfiltrationAirFlow(space);

            if (double.IsNaN(airFlow))
            {
                return(double.NaN);
            }

            if (airFlow == 0)
            {
                return(0);
            }

            List <Panel> panels = adjacencyCluster.GetPanels(space);

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

            panels.RemoveAll(x => !adjacencyCluster.ExposedToSun(x));

            double area = 0;

            foreach (Panel panel in panels)
            {
                double area_Temp = panel.GetArea();
                if (!double.IsNaN(area_Temp))
                {
                    area += area_Temp;
                }
            }

            if (area == 0)
            {
                return(0);
            }

            return(airFlow / area);
        }
Пример #9
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);
        }
Пример #10
0
        public static Dictionary <Panel, double> UpdateThermalParameters(this AdjacencyCluster adjacencyCluster, TBD.Building building)
        {
            List <TBD.Construction> constructions_TBD = building?.Constructions();

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

            List <Panel> panels = adjacencyCluster.GetPanels();

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

            Dictionary <Panel, double> result = new Dictionary <Panel, double>();

            foreach (Panel panel in panels)
            {
                Construction construction = panel?.Construction;
                if (construction == null)
                {
                    continue;
                }

                string name = construction.Name;

                TBD.Construction construction_TBD = constructions_TBD.Find(x => x.name == name);
                if (construction_TBD == null)
                {
                    name             = Analytical.Query.UniqueName(panel.PanelType, name);
                    construction_TBD = constructions_TBD.Find(x => x.name == name);
                }

                if (construction_TBD == null)
                {
                    continue;
                }

                double thermalTransmittance = Query.ThermalTransmittance(construction_TBD, panel.PanelType);
                if (!double.IsNaN(thermalTransmittance))
                {
                    panel.SetValue(PanelParameter.ThermalTransmittance, thermalTransmittance);
                }

                Query.GlazingValues(construction_TBD,
                                    out double lightTransmittance,
                                    out double lightReflectance,
                                    out double directSolarEnergyTransmittance,
                                    out double directSolarEnergyReflectance,
                                    out double directSolarEnergyAbsorptance,
                                    out double totalSolarEnergyTransmittance,
                                    out double pilkingtonShortWavelengthCoefficient,
                                    out double pilkingtonLongWavelengthCoefficient);

                if (!double.IsNaN(lightTransmittance))
                {
                    panel.SetValue(PanelParameter.LightTransmittance, lightTransmittance);
                }

                if (!double.IsNaN(lightReflectance))
                {
                    panel.SetValue(PanelParameter.LightReflectance, lightReflectance);
                }

                if (!double.IsNaN(directSolarEnergyTransmittance))
                {
                    panel.SetValue(PanelParameter.DirectSolarEnergyTransmittance, directSolarEnergyTransmittance);
                }

                if (!double.IsNaN(directSolarEnergyReflectance))
                {
                    panel.SetValue(PanelParameter.DirectSolarEnergyReflectance, directSolarEnergyReflectance);
                }

                if (!double.IsNaN(directSolarEnergyAbsorptance))
                {
                    panel.SetValue(PanelParameter.DirectSolarEnergyAbsorptance, directSolarEnergyAbsorptance);
                }

                if (!double.IsNaN(totalSolarEnergyTransmittance))
                {
                    panel.SetValue(PanelParameter.TotalSolarEnergyTransmittance, totalSolarEnergyTransmittance);
                }

                if (!double.IsNaN(pilkingtonShortWavelengthCoefficient))
                {
                    panel.SetValue(PanelParameter.PilkingtonShadingShortWavelengthCoefficient, pilkingtonShortWavelengthCoefficient);
                }

                if (!double.IsNaN(pilkingtonLongWavelengthCoefficient))
                {
                    panel.SetValue(PanelParameter.PilkingtonShadingLongWavelengthCoefficient, pilkingtonLongWavelengthCoefficient);
                }


                adjacencyCluster.AddObject(panel);
                result[panel] = thermalTransmittance;
            }

            return(result);
        }
Пример #11
0
        public static AnalyticalModel UpdateT3D(this AnalyticalModel analyticalModel, T3DDocument t3DDocument)
        {
            if (analyticalModel == null)
            {
                return(null);
            }


            Building building = t3DDocument?.Building;

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

            Modify.RemoveUnsusedZones(building);

            double northAngle = double.NaN;

            if (analyticalModel.TryGetValue(AnalyticalModelParameter.NorthAngle, out northAngle))
            {
                building.northAngle = global::System.Math.Round(Units.Convert.ToDegrees(northAngle), 1);
            }

            Location location = analyticalModel.Location;

            if (location != null)
            {
                building.longitude = location.Longitude;
                building.latitude  = location.Latitude;

                if (location.TryGetValue(LocationParameter.TimeZone, out string timeZone))
                {
                    double @double = Core.Query.Double(Core.Query.UTC(timeZone));
                    if (!double.IsNaN(@double))
                    {
                        building.timeZone = global::System.Convert.ToSingle(@double);
                    }
                }
            }

            AdjacencyCluster adjacencyCluster = analyticalModel?.AdjacencyCluster;

            if (adjacencyCluster != null)
            {
                //Zones -> Spaces
                Dictionary <string, Space> spaces = adjacencyCluster.SpaceDictionary();
                if (spaces != null)
                {
                    Dictionary <string, TAS3D.Zone> zones = building.ZoneDictionary();
                    if (zones != null)
                    {
                        foreach (KeyValuePair <string, TAS3D.Zone> keyValuePair in zones)
                        {
                            Space space;
                            if (!spaces.TryGetValue(keyValuePair.Key, out space))
                            {
                                continue;
                            }

                            if (space == null)
                            {
                                continue;
                            }

                            //TODO: Update Zone
                            Space space_New = space.Clone();
                            space_New.Add(Create.ParameterSet(ActiveSetting.Setting, keyValuePair.Value));
                            adjacencyCluster.AddObject(space_New);
                        }
                    }
                }

                //Elements -> Constructions
                List <Construction> constructions = adjacencyCluster.GetConstructions();
                if (constructions != null)
                {
                    List <Element> elements = building.Elements();
                    if (elements != null)
                    {
                        foreach (Element element in elements)
                        {
                            Construction construction = element.Match(constructions);
                            if (construction == null)
                            {
                                continue;
                            }

                            //Update Element

                            //Thickness
                            double thickness = construction.GetValue <double>(ConstructionParameter.DefaultThickness);
                            if (double.IsNaN(thickness) || thickness == 0)
                            {
                                thickness = construction.GetThickness();
                            }

                            if (!double.IsNaN(thickness))
                            {
                                element.width = thickness;
                            }

                            //if (Core.Query.TryGetValue(construction, Analytical.Query.ParameterName_Thickness(), out thickness, true))
                            //    element.width= thickness;

                            //Colour
                            System.Drawing.Color color = global::System.Drawing.Color.Empty;
                            if (construction.TryGetValue(ConstructionParameter.Color, out color))
                            {
                                element.colour = Core.Convert.ToUint(color);
                            }


                            //Transparent
                            bool         transparent  = false;
                            MaterialType materialType = Analytical.Query.MaterialType(construction.ConstructionLayers, analyticalModel.MaterialLibrary);
                            if (materialType == MaterialType.Undefined)
                            {
                                materialType = MaterialType.Opaque;
                                if (construction.TryGetValue(ConstructionParameter.Transparent, out transparent))
                                {
                                    element.transparent = transparent;
                                }
                            }
                            else
                            {
                                element.transparent = materialType == MaterialType.Transparent;
                            }

                            //InternalShadows
                            bool internalShadows = false;
                            if (construction.TryGetValue(ConstructionParameter.IsInternalShadow, out internalShadows))
                            {
                                element.internalShadows = internalShadows;
                            }
                            else
                            {
                                element.internalShadows = element.transparent;
                            }


                            //BEType
                            string string_BEType = null;

                            PanelType panelType = construction.PanelType();
                            if (panelType != Analytical.PanelType.Undefined)
                            {
                                string_BEType = panelType.Text();
                            }
                            else
                            {
                                if (!construction.TryGetValue(ConstructionParameter.DefaultPanelType, out string_BEType))
                                {
                                    string_BEType = null;
                                }
                            }

                            if (!string.IsNullOrEmpty(string_BEType))
                            {
                                int bEType = BEType(string_BEType);
                                if (bEType != -1)
                                {
                                    element.BEType = bEType;
                                    panelType      = PanelType(bEType);
                                }
                            }
                            else
                            {
                                panelType = Analytical.PanelType.Undefined;

                                List <Panel> panels_Construction = adjacencyCluster.GetPanels(construction);
                                if (panels_Construction != null && panels_Construction.Count > 0)
                                {
                                    Panel panel = panels_Construction.Find(x => x.PanelType != Analytical.PanelType.Undefined);
                                    if (panel != null)
                                    {
                                        panelType = panel.PanelType;
                                    }
                                }
                            }

                            if (panelType == Analytical.PanelType.Undefined)
                            {
                                List <Panel> panels_Construction = adjacencyCluster.GetPanels(construction);
                                if (panels_Construction != null && panels_Construction.Count != 0)
                                {
                                    element.zoneFloorArea = panels_Construction.Find(x => x.PanelType.PanelGroup() == PanelGroup.Floor) != null;
                                }
                            }

                            if (panelType.PanelGroup() == PanelGroup.Floor)
                            {
                                element.zoneFloorArea = true;
                            }

                            //Ground
                            bool ground = false;
                            if (construction.TryGetValue(ConstructionParameter.IsGround, out ground))
                            {
                                element.ground = ground;
                            }

                            //Air
                            bool air = false;
                            if (construction.TryGetValue(ConstructionParameter.IsAir, out air))
                            {
                                element.ghost = air;
                            }

                            List <Panel> panels = adjacencyCluster.GetPanels(construction);
                            if (panels != null && panels.Count > 0)
                            {
                                ParameterSet parameterSet = Create.ParameterSet(ActiveSetting.Setting, element);
                                construction.Add(parameterSet);

                                foreach (Panel panel in panels)
                                {
                                    Panel panel_New = Analytical.Create.Panel(panel, construction);
                                    adjacencyCluster.AddObject(panel_New);
                                }
                            }
                        }
                    }
                }

                //Windows -> ApertureConstruction
                List <ApertureConstruction> apertureConstructions = adjacencyCluster.GetApertureConstructions();
                if (apertureConstructions != null)
                {
                    List <window> windows = building.Windows();
                    if (windows != null)
                    {
                        foreach (window window in windows)
                        {
                            if (window == null)
                            {
                                continue;
                            }

                            ApertureConstruction apertureConstruction = window.Match(apertureConstructions);
                            if (apertureConstruction == null)
                            {
                                continue;
                            }

                            //Colour
                            System.Drawing.Color color = global::System.Drawing.Color.Empty;
                            if (!apertureConstruction.TryGetValue(ApertureConstructionParameter.Color, out color))
                            {
                                color = Analytical.Query.Color(apertureConstruction.ApertureType);
                            }

                            if (color != global::System.Drawing.Color.Empty)
                            {
                                window.colour = Core.Convert.ToUint(color);
                            }


                            //Transparent
                            List <ConstructionLayer> constructionLayers = null;
                            if (true)
                            {
                                constructionLayers = apertureConstruction.PaneConstructionLayers;
                            }
                            else
                            {
                                constructionLayers = apertureConstruction.FrameConstructionLayers;
                            }

                            window.transparent = false; //Requested by Michal 2021.03.01
                            bool         transparent  = false;
                            MaterialType materialType = Analytical.Query.MaterialType(constructionLayers, analyticalModel.MaterialLibrary);
                            if (materialType == MaterialType.Undefined)
                            {
                                materialType = MaterialType.Opaque;
                                if (apertureConstruction.TryGetValue(ApertureConstructionParameter.Transparent, out transparent))
                                {
                                    window.transparent = transparent;
                                }
                            }
                            else
                            {
                                window.transparent = materialType == MaterialType.Transparent;
                            }


                            if (window.transparent)
                            {
                                //InternalShadows
                                window.internalShadows = false; //Requested by Michal 2021.03.01
                                bool internalShadows = false;
                                if (apertureConstruction.TryGetValue(ApertureConstructionParameter.IsInternalShadow, out internalShadows))
                                {
                                    window.internalShadows = internalShadows;
                                }
                                else
                                {
                                    List <Panel> panels = adjacencyCluster.GetPanels(apertureConstruction);
                                    if (panels != null && panels.Count != 0)
                                    {
                                        window.internalShadows = panels.TrueForAll(x => adjacencyCluster.External(x));
                                    }
                                }
                            }

                            //FrameWidth
                            double frameWidth = double.NaN;
                            if (apertureConstruction.TryGetValue(ApertureConstructionParameter.DefaultFrameWidth, out frameWidth))
                            {
                                window.frameWidth = frameWidth;
                            }
                        }
                    }
                }
            }

            AnalyticalModel result = new AnalyticalModel(analyticalModel, adjacencyCluster);

            return(result);
        }
Пример #12
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);
        }
Пример #13
0
        protected override void TrySolveInstance(IGH_DataAccess dataAccess)
        {
            bool run = false;

            if (!dataAccess.GetData(2, ref run) || !run)
            {
                return;
            }

            ConvertSettings convertSettings = null;

            dataAccess.GetData(1, ref convertSettings);
            convertSettings = this.UpdateSolutionEndEventHandler(convertSettings);

            SAMObject sAMObject = null;

            if (!dataAccess.GetData(0, ref sAMObject))
            {
                return;
            }

            Document document = RhinoInside.Revit.Revit.ActiveDBDocument;

            if (sAMObject is AnalyticalModel)
            {
                sAMObject = ((AnalyticalModel)sAMObject).AdjacencyCluster;
            }

            if (!(sAMObject is Panel) && !(sAMObject is Aperture) && !(sAMObject is Space) && !(sAMObject is AdjacencyCluster))
            {
                dataAccess.SetData(0, null);
                return;
            }

            if (sAMObject is AdjacencyCluster)
            {
                AdjacencyCluster adjacencyCluster = (AdjacencyCluster)sAMObject;
                adjacencyCluster.GetPanels()?.ForEach(x => Core.Revit.Modify.RemoveExisting(convertSettings, document, x));
                adjacencyCluster.GetSpaces()?.ForEach(x => Core.Revit.Modify.RemoveExisting(convertSettings, document, x));
            }
            else
            {
                Core.Revit.Modify.RemoveExisting(convertSettings, document, sAMObject);
            }

            object @object = Analytical.Revit.Convert.ToRevit(sAMObject as dynamic, document, convertSettings);

            IEnumerable <Element> elements = null;

            if (@object is IEnumerable)
            {
                elements = ((IEnumerable)@object).Cast <Element>();
            }
            else
            {
                elements = new List <Element>()
                {
                    @object as Element
                }
            };

            dataAccess.SetDataList(0, elements);
        }
    }
Пример #14
0
        public static List <Element> ToRevit(this AdjacencyCluster adjacencyCluster, Document document, ConvertSettings convertSettings)
        {
            if (adjacencyCluster == null || document == null)
            {
                return(null);
            }

            List <Element> result = convertSettings?.GetObjects <Element>(adjacencyCluster.Guid);

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

            Dictionary <Space, Shell> dictionary_Shell = adjacencyCluster.ShellDictionary();

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

            //List<Level> levels = new FilteredElementCollector(document).OfClass(typeof(Level)).Cast<Level>().ToList();
            //if (levels == null || levels.Count == 0)
            //    return null;

            Dictionary <ElementId, Element> dictionary_Element = new Dictionary <ElementId, Element>();

            HashSet <System.Guid> guids = new HashSet <System.Guid>();

            foreach (KeyValuePair <Space, Shell> keyValuePair in dictionary_Shell)
            {
                Space space = keyValuePair.Key;

                List <Panel> panels_Space = adjacencyCluster.GetPanels(space);
                if (panels_Space != null && panels_Space.Count != 0)
                {
                    foreach (Panel panel in panels_Space)
                    {
                        if (guids.Contains(panel.Guid))
                        {
                            continue;
                        }

                        guids.Add(panel.Guid);

                        HostObject hostObject = panel.ToRevit(document, convertSettings);
                        if (hostObject == null)
                        {
                            continue;
                        }

                        dictionary_Element[hostObject.Id] = hostObject;
                    }
                }

                Autodesk.Revit.DB.Mechanical.Space space_Revit = space.ToRevit(document, convertSettings);
                if (space_Revit == null)
                {
                    continue;
                }

                dictionary_Element[space_Revit.Id] = space_Revit;

                BoundingBox3D boundingBox3D = keyValuePair.Value.GetBoundingBox();
                if (boundingBox3D == null)
                {
                    continue;
                }

                Parameter parameter;

                parameter = space_Revit.get_Parameter(BuiltInParameter.ROOM_UPPER_LEVEL);
                Level level = document.ClosestLevel(boundingBox3D.Max.Z);
                if (level == null)
                {
                    continue;
                }

                parameter.Set(level.Id);

                if (level.Id != space_Revit.LevelId && level.Elevation > (document.GetElement(space_Revit.LevelId) as Level).Elevation)
                {
                    parameter = space_Revit.get_Parameter(BuiltInParameter.ROOM_UPPER_OFFSET);
                    parameter.Set(0);
                }
            }

            List <Panel> panels = adjacencyCluster.GetShadingPanels();

            if (panels != null && panels.Count != 0)
            {
                foreach (Panel panel in panels)
                {
                    HostObject hostObject = panel.ToRevit(document, convertSettings);
                    if (hostObject == null)
                    {
                        continue;
                    }

                    dictionary_Element[hostObject.Id] = hostObject;
                }
            }

            List <Zone> zones = adjacencyCluster.GetObjects <Zone>();

            if (zones != null)
            {
                foreach (Zone zone in zones)
                {
                    List <Autodesk.Revit.DB.Mechanical.Space> spaces = ToRevit(adjacencyCluster, zone, document, convertSettings);
                    spaces?.ForEach(x => dictionary_Element[x.Id] = x);
                }
            }

            List <ZoneSimulationResult> zoneSimulationResults = adjacencyCluster.GetObjects <ZoneSimulationResult>();

            if (zoneSimulationResults != null)
            {
                foreach (ZoneSimulationResult zoneSimulationResult in zoneSimulationResults)
                {
                    List <Autodesk.Revit.DB.Mechanical.Space> spaces = ToRevit(adjacencyCluster, zoneSimulationResult, document, convertSettings);
                    spaces?.ForEach(x => dictionary_Element[x.Id] = x);
                }
            }

            List <SpaceSimulationResult> spaceSimulationResults = adjacencyCluster.GetObjects <SpaceSimulationResult>();

            if (zoneSimulationResults != null)
            {
                foreach (SpaceSimulationResult spaceSimulationResult in spaceSimulationResults)
                {
                    List <Autodesk.Revit.DB.Mechanical.Space> spaces = ToRevit(adjacencyCluster, spaceSimulationResult, document, convertSettings);
                    spaces?.ForEach(x => dictionary_Element[x.Id] = x);
                }
            }

            List <AdjacencyClusterSimulationResult> adjacencyClusterSimulationResults = adjacencyCluster.GetObjects <AdjacencyClusterSimulationResult>();

            if (adjacencyClusterSimulationResults != null)
            {
                foreach (AdjacencyClusterSimulationResult adjacencyClusterSimulationResult in adjacencyClusterSimulationResults)
                {
                    ProjectInfo projectInfo = ToRevit(adjacencyClusterSimulationResult, document, convertSettings);
                    if (projectInfo != null)
                    {
                        dictionary_Element[projectInfo.Id] = projectInfo;
                    }
                }
            }

            result = dictionary_Element.Values.ToList();

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

            return(result);
        }
Пример #15
0
        public static TBD.Building ToTBD(this AnalyticalModel analyticalModel, TBD.TBDDocument tBDDocument)
        {
            if (analyticalModel == null)
            {
                return(null);
            }

            TBD.Building result = tBDDocument.Building;
            if (result == null)
            {
                return(null);
            }

            AdjacencyCluster adjacencyCluster = analyticalModel.AdjacencyCluster;

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

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

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

            MaterialLibrary materialLibrary = analyticalModel.MaterialLibrary;

            Plane plane = Plane.WorldXY;

            List <TBD.DaysShade> daysShades = new List <TBD.DaysShade>();

            result.ClearShadingData();

            Dictionary <System.Guid, List <TBD.zoneSurface> > dictionary_Panel    = new Dictionary <System.Guid, List <TBD.zoneSurface> >();
            Dictionary <System.Guid, List <TBD.zoneSurface> > dictionary_Aperture = new Dictionary <System.Guid, List <TBD.zoneSurface> >();

            foreach (Space space in spaces)
            {
                Shell shell = adjacencyCluster.Shell(space);
                if (shell == null)
                {
                    return(null);
                }

                TBD.zone zone = result.AddZone();
                zone.name   = space.Name;
                zone.volume = System.Convert.ToSingle(shell.Volume());

                if (space.TryGetValue(SpaceParameter.Color, out SAMColor sAMColor) && sAMColor != null)
                {
                    zone.colour = Core.Convert.ToUint(sAMColor.ToColor());
                }

                List <Face3D> face3Ds = Geometry.Spatial.Query.Section(shell, 0.01, false);
                if (face3Ds != null && face3Ds.Count != 0)
                {
                    face3Ds.RemoveAll(x => x == null || !x.IsValid());
                    zone.floorArea        = System.Convert.ToSingle(face3Ds.ConvertAll(x => x.GetArea()).Sum());
                    zone.exposedPerimeter = System.Convert.ToSingle(face3Ds.ConvertAll(x => Geometry.Planar.Query.Perimeter(x.ExternalEdge2D)).Sum());
                    zone.length           = System.Convert.ToSingle(face3Ds.ConvertAll(x => Geometry.Tas.Query.Length(x)).Sum());
                }

                TBD.room room = zone.AddRoom();

                List <TBD.buildingElement> buildingElements = result.BuildingElements();
                List <TBD.Construction>    constructions    = result.Constructions();

                List <Panel> panels = adjacencyCluster?.GetPanels(space);
                if (panels != null || panels.Count != 0)
                {
                    foreach (Panel panel in panels)
                    {
                        string name_Panel = panel.Name;
                        if (string.IsNullOrWhiteSpace(name_Panel))
                        {
                            continue;
                        }

                        Face3D face3D_Panel = panel.Face3D;
                        if (face3D_Panel == null)
                        {
                            continue;
                        }

                        BoundingBox3D boundingBox3D_Panel = face3D_Panel.GetBoundingBox();

                        TBD.zoneSurface zoneSurface_Panel = zone.AddSurface();
                        zoneSurface_Panel.orientation = System.Convert.ToSingle(Geometry.Spatial.Query.Azimuth(panel, Vector3D.WorldY));
                        zoneSurface_Panel.inclination = System.Convert.ToSingle(Geometry.Spatial.Query.Tilt(panel));

                        zoneSurface_Panel.altitude              = System.Convert.ToSingle(boundingBox3D_Panel.GetCentroid().Z);
                        zoneSurface_Panel.altitudeRange         = System.Convert.ToSingle(boundingBox3D_Panel.Max.Z - boundingBox3D_Panel.Min.Z);
                        zoneSurface_Panel.area                  = System.Convert.ToSingle(face3D_Panel.GetArea());
                        zoneSurface_Panel.planHydraulicDiameter = System.Convert.ToSingle(Geometry.Tas.Query.HydraulicDiameter(face3D_Panel));

                        TBD.RoomSurface roomSurface_Panel = room.AddSurface();
                        roomSurface_Panel.area        = zoneSurface_Panel.area;
                        roomSurface_Panel.zoneSurface = zoneSurface_Panel;

                        Geometry.SolarCalculator.SolarFaceSimulationResult solarFaceSimulationResult = analyticalModel.GetResults <Geometry.SolarCalculator.SolarFaceSimulationResult>(panel)?.FirstOrDefault();
                        if (solarFaceSimulationResult != null)
                        {
                            List <TBD.SurfaceShade> surfaceShades = Modify.UpdateSurfaceShades(result, daysShades, zoneSurface_Panel, analyticalModel, solarFaceSimulationResult);
                        }

                        TBD.Perimeter perimeter_Panel = Geometry.Tas.Convert.ToTBD(panel.GetFace3D(true), roomSurface_Panel);
                        if (perimeter_Panel == null)
                        {
                            continue;
                        }

                        PanelType panelType = panel.PanelType;

                        TBD.buildingElement buildingElement_Panel = buildingElements.Find(x => x.name == name_Panel);
                        if (buildingElement_Panel == null)
                        {
                            TBD.Construction construction_TBD = null;

                            Construction construction = panel.Construction;
                            if (construction != null)
                            {
                                construction_TBD = constructions.Find(x => x.name == construction.Name);
                                if (construction_TBD == null)
                                {
                                    construction_TBD      = result.AddConstruction(null);
                                    construction_TBD.name = construction.Name;

                                    if (construction.Transparent(materialLibrary))
                                    {
                                        construction_TBD.type = TBD.ConstructionTypes.tcdTransparentConstruction;
                                    }

                                    List <ConstructionLayer> constructionLayers = construction.ConstructionLayers;
                                    if (constructionLayers != null && constructionLayers.Count != 0)
                                    {
                                        int index = 1;
                                        foreach (ConstructionLayer constructionLayer in constructionLayers)
                                        {
                                            Material material = analyticalModel?.MaterialLibrary?.GetMaterial(constructionLayer.Name) as Core.Material;
                                            if (material == null)
                                            {
                                                continue;
                                            }

                                            TBD.material material_TBD = construction_TBD.AddMaterial(material);
                                            if (material_TBD != null)
                                            {
                                                material_TBD.width = System.Convert.ToSingle(constructionLayer.Thickness);
                                                construction_TBD.materialWidth[index] = System.Convert.ToSingle(constructionLayer.Thickness);
                                                index++;
                                            }
                                        }
                                    }

                                    constructions.Add(construction_TBD);
                                }

                                if (panelType == PanelType.Undefined && construction != null)
                                {
                                    panelType = construction.PanelType();
                                    if (panelType == PanelType.Undefined && construction.TryGetValue(ConstructionParameter.DefaultPanelType, out string panelTypeString))
                                    {
                                        panelType = Core.Query.Enum <PanelType>(panelTypeString);
                                    }
                                }
                            }

                            buildingElement_Panel        = result.AddBuildingElement();
                            buildingElement_Panel.name   = name_Panel;
                            buildingElement_Panel.colour = Core.Convert.ToUint(Analytical.Query.Color(panelType));
                            buildingElement_Panel.BEType = Query.BEType(panelType.Text());
                            buildingElement_Panel.AssignConstruction(construction_TBD);
                            buildingElements.Add(buildingElement_Panel);
                        }

                        if (buildingElement_Panel != null)
                        {
                            zoneSurface_Panel.buildingElement = buildingElement_Panel;
                        }

                        zoneSurface_Panel.type = TBD.SurfaceType.tbdExposed;

                        List <Aperture> apertures = panel.Apertures;
                        if (apertures != null && apertures.Count != 0)
                        {
                            bool @internal = adjacencyCluster.Internal(panel);

                            foreach (Aperture aperture in apertures)
                            {
                                string name_Aperture = aperture.Name;
                                if (string.IsNullOrWhiteSpace(name_Aperture))
                                {
                                    continue;
                                }

                                name_Aperture = string.Format("{0} -pane", aperture.Name);

                                Face3D face3D_Aperture = aperture.Face3D;
                                if (face3D_Aperture == null)
                                {
                                    continue;
                                }

                                BoundingBox3D boundingBox3D_Aperture = face3D_Aperture.GetBoundingBox();

                                float area = System.Convert.ToSingle(face3D_Aperture.GetArea());

                                TBD.zoneSurface zoneSurface_Aperture = zoneSurface_Panel.AddChildSurface(area);
                                if (zoneSurface_Aperture == null)
                                {
                                    continue;
                                }

                                zoneSurface_Aperture.orientation           = zoneSurface_Panel.orientation;
                                zoneSurface_Aperture.inclination           = zoneSurface_Panel.inclination;
                                zoneSurface_Aperture.altitude              = System.Convert.ToSingle(boundingBox3D_Aperture.GetCentroid().Z);
                                zoneSurface_Aperture.altitudeRange         = System.Convert.ToSingle(boundingBox3D_Aperture.Max.Z - boundingBox3D_Aperture.Min.Z);
                                zoneSurface_Aperture.planHydraulicDiameter = System.Convert.ToSingle(Geometry.Tas.Query.HydraulicDiameter(face3D_Aperture));
                                //zoneSurface_Aperture.area = System.Convert.ToSingle(face3D_Aperture.GetArea());

                                zoneSurface_Aperture.type = @internal ? TBD.SurfaceType.tbdLink : zoneSurface_Panel.type;

                                TBD.RoomSurface roomSurface_Aperture = room.AddSurface();
                                roomSurface_Aperture.area        = zoneSurface_Aperture.area;
                                roomSurface_Aperture.zoneSurface = zoneSurface_Aperture;

                                TBD.Perimeter perimeter_Aperture = Geometry.Tas.Convert.ToTBD(face3D_Aperture, roomSurface_Aperture);
                                if (perimeter_Aperture == null)
                                {
                                    continue;
                                }

                                TBD.buildingElement buildingElement_Aperture = buildingElements.Find(x => x.name == name_Aperture);
                                if (buildingElement_Aperture == null)
                                {
                                    TBD.Construction construction_TBD = null;

                                    ApertureConstruction apertureConstruction = aperture.ApertureConstruction;
                                    if (apertureConstruction != null)
                                    {
                                        construction_TBD = constructions.Find(x => x.name == apertureConstruction.Name);
                                        if (construction_TBD == null)
                                        {
                                            construction_TBD      = result.AddConstruction(null);
                                            construction_TBD.name = name_Aperture;

                                            if (apertureConstruction.Transparent(materialLibrary))
                                            {
                                                construction_TBD.type = TBD.ConstructionTypes.tcdTransparentConstruction;
                                            }

                                            List <ConstructionLayer> constructionLayers = apertureConstruction.PaneConstructionLayers;
                                            if (constructionLayers != null && constructionLayers.Count != 0)
                                            {
                                                int index = 1;
                                                foreach (ConstructionLayer constructionLayer in constructionLayers)
                                                {
                                                    Core.Material material = materialLibrary?.GetMaterial(constructionLayer.Name) as Material;
                                                    if (material == null)
                                                    {
                                                        continue;
                                                    }

                                                    TBD.material material_TBD = construction_TBD.AddMaterial(material);
                                                    if (material_TBD != null)
                                                    {
                                                        material_TBD.width = System.Convert.ToSingle(constructionLayer.Thickness);
                                                        construction_TBD.materialWidth[index] = System.Convert.ToSingle(constructionLayer.Thickness);
                                                        index++;
                                                    }
                                                }
                                            }

                                            constructions.Add(construction_TBD);
                                        }
                                    }

                                    ApertureType apertureType = aperture.ApertureType;

                                    buildingElement_Aperture        = result.AddBuildingElement();
                                    buildingElement_Aperture.name   = name_Aperture;
                                    buildingElement_Aperture.colour = Core.Convert.ToUint(Analytical.Query.Color(apertureType));
                                    buildingElement_Aperture.BEType = Query.BEType(apertureType, false);
                                    buildingElement_Aperture.AssignConstruction(construction_TBD);
                                    buildingElements.Add(buildingElement_Aperture);
                                }

                                if (buildingElement_Aperture != null)
                                {
                                    zoneSurface_Aperture.buildingElement = buildingElement_Aperture;
                                }

                                if (!dictionary_Aperture.TryGetValue(aperture.Guid, out List <TBD.zoneSurface> zoneSurfaces_Aperture) || zoneSurfaces_Aperture == null)
                                {
                                    zoneSurfaces_Aperture = new List <TBD.zoneSurface>();
                                    dictionary_Aperture[aperture.Guid] = zoneSurfaces_Aperture;
                                }

                                zoneSurfaces_Aperture.Add(zoneSurface_Aperture);
                            }
                        }

                        zoneSurface_Panel.type = Query.SurfaceType(panelType);

                        if (!dictionary_Panel.TryGetValue(panel.Guid, out List <TBD.zoneSurface> zoneSurfaces_Panel) || zoneSurfaces_Panel == null)
                        {
                            zoneSurfaces_Panel           = new List <TBD.zoneSurface>();
                            dictionary_Panel[panel.Guid] = zoneSurfaces_Panel;
                        }

                        zoneSurfaces_Panel.Add(zoneSurface_Panel);
                    }
                }
            }

            foreach (KeyValuePair <System.Guid, List <TBD.zoneSurface> > keyValuePair in dictionary_Panel)
            {
                if (keyValuePair.Value == null || keyValuePair.Value.Count <= 1)
                {
                    continue;
                }

                keyValuePair.Value[1].linkSurface = keyValuePair.Value[0];
                keyValuePair.Value[0].linkSurface = keyValuePair.Value[1];

                if (keyValuePair.Value[0].inclination == 0 || keyValuePair.Value[0].inclination == 180)
                {
                    float inclination = keyValuePair.Value[1].inclination;
                    inclination -= 180;
                    if (inclination < 0)
                    {
                        inclination += 360;
                    }

                    keyValuePair.Value[1].inclination = inclination;
                    keyValuePair.Value[1].reversed    = 1;
                }
                else
                {
                    float orientation = keyValuePair.Value[1].orientation;
                    orientation += 180;
                    if (orientation >= 360)
                    {
                        orientation -= 360;
                    }

                    keyValuePair.Value[1].orientation = orientation;
                    keyValuePair.Value[1].reversed    = 1;

                    float inclination = keyValuePair.Value[1].inclination;
                    if (inclination > 180)
                    {
                        inclination -= 180;
                    }
                    keyValuePair.Value[1].inclination = inclination;
                }
            }

            foreach (KeyValuePair <System.Guid, List <TBD.zoneSurface> > keyValuePair in dictionary_Aperture)
            {
                if (keyValuePair.Value == null || keyValuePair.Value.Count <= 1)
                {
                    continue;
                }

                keyValuePair.Value[1].linkSurface = keyValuePair.Value[0];
                keyValuePair.Value[0].linkSurface = keyValuePair.Value[1];

                if (keyValuePair.Value[0].inclination == 0 || keyValuePair.Value[0].inclination == 180)
                {
                    float inclination = keyValuePair.Value[0].inclination;
                    inclination -= 180;
                    if (inclination < 0)
                    {
                        inclination += 360;
                    }

                    keyValuePair.Value[0].inclination = inclination;
                    keyValuePair.Value[0].reversed    = 1;
                }
                else
                {
                    float orientation = keyValuePair.Value[1].orientation;
                    orientation += 180;
                    if (orientation >= 360)
                    {
                        orientation -= 360;
                    }

                    keyValuePair.Value[1].orientation = orientation;
                    keyValuePair.Value[1].reversed    = 1;
                }
            }

            return(result);
        }