Example #1
0
        public static Polygon3D ToSAM(this TBD.Polygon polygon)
        {
            if (polygon == null)
            {
                return(null);
            }

            List <Point3D> point3Ds = new List <Point3D>();

            int index = 0;

            TBD.TasPoint tasPoint = polygon.GetPoint(index);
            while (tasPoint != null)
            {
                Point3D point3D = tasPoint.ToSAM();
                if (point3D != null)
                {
                    point3Ds.Add(point3D);
                }
                index++;

                tasPoint = polygon.GetPoint(index);
            }

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

            return(Spatial.Create.Polygon3D(point3Ds));
        }
Example #2
0
        public static TBD.Polygon ToTBD(this Polygon3D polygon3D)
        {
            if (polygon3D == null)
            {
                return(null);
            }

            TBD.Polygon result = new TBD.Polygon();

            List <Point3D> point3Ds = polygon3D.GetPoints();

            if (point3Ds != null)
            {
                foreach (Point3D point3D in point3Ds)
                {
                    if (point3D == null)
                    {
                        continue;
                    }

                    result.AddCoordinate(System.Convert.ToSingle(point3D.X), System.Convert.ToSingle(point3D.Y), System.Convert.ToSingle(point3D.Z));
                }
            }

            return(result);
        }
Example #3
0
        public static BHG.Polyline FromTAS(this TBD.Polygon tbdPolygon)
        {
            List <BHG.Point> pnts = new List <BHG.Point>();

            int pIndex = 0;

            TBD.TasPoint tPt = null;

            try
            {
                while ((tPt = tbdPolygon.GetPoint(pIndex)) != null)
                {
                    pnts.Add(tPt.FromTAS());
                    pIndex++;
                }

                //if(pnts.First().Distance(pnts.Last()) > BHG.Tolerance.Distance)
                if (pnts.First() != pnts.Last())
                {
                    pnts.Add(pnts[0]); //Close the polyline
                }
            }
            catch (Exception ex)
            {
                BH.Engine.Base.Compute.RecordError(ex.ToString());
            }

            return(new BHG.Polyline {
                ControlPoints = pnts
            });
        }
Example #4
0
        public static TBD.Perimeter ToTBD_Perimeter(this Polygon3D polygon3D)
        {
            if (polygon3D == null)
            {
                return(null);
            }

            TBD.Perimeter result  = new TBD.Perimeter();
            TBD.Polygon   polygon = result.CreateFace();

            List <Point3D> point3Ds = polygon3D.GetPoints();

            if (point3Ds != null)
            {
                foreach (Point3D point3D in point3Ds)
                {
                    if (point3D == null)
                    {
                        continue;
                    }

                    polygon.AddCoordinate(System.Convert.ToSingle(point3D.X), System.Convert.ToSingle(point3D.Y), System.Convert.ToSingle(point3D.Z));
                }
            }



            return(result);
        }
Example #5
0
        public static TBD.Perimeter ToTAS(this BHG.Polyline polyline, TBD.Perimeter tbdPerimeter)
        {
            if (polyline == null)
            {
                return(tbdPerimeter);
            }

            TBD.Polygon poly = tbdPerimeter.CreateFace();
            poly = polyline.ToTASPolygon(poly);

            return(tbdPerimeter);
        }
Example #6
0
        public static BHE.Opening FromTASOpening(this TBD.Polygon tbdPolygon, TBD.RoomSurface roomSurface, TASSettings tasSettings)
        {
            BHE.Opening opening = new oM.Environment.Elements.Opening();
            //roomSurface.parentSurface

            if (roomSurface != null)
            {
                TBD.zoneSurface     tbdSurface = roomSurface.zoneSurface;
                TBD.buildingElement tbdElement = tbdSurface.buildingElement;

                //EnvironmentContextProperties
                BH.oM.Environment.Fragments.OriginContextFragment environmentContextProperties = new oM.Environment.Fragments.OriginContextFragment();
                environmentContextProperties.ElementID   = tbdSurface.GUID.RemoveBrackets();
                environmentContextProperties.Description = tbdSurface.buildingElement.name + " - " + tbdSurface.buildingElement.GUID.RemoveBrackets();
                environmentContextProperties.TypeName    = tbdSurface.buildingElement.name;
                opening.Fragments.Add(environmentContextProperties);

                opening.Name = environmentContextProperties.TypeName;
                opening.Type = ((TBD.BuildingElementType)tbdElement.BEType).FromTASOpeningType().FixBuildingElementType(tbdElement, tbdSurface);
                opening.OpeningConstruction = tbdElement.GetConstruction().FromTAS();

                //BuildingElementAnalyticalProperties
                BH.oM.Environment.Fragments.PanelAnalyticalFragment buildingElementAnalyticalProperties = new oM.Environment.Fragments.PanelAnalyticalFragment();
                buildingElementAnalyticalProperties.Altitude      = tbdSurface.altitude.Round();
                buildingElementAnalyticalProperties.AltitudeRange = tbdSurface.altitudeRange.Round();
                buildingElementAnalyticalProperties.Inclination   = tbdSurface.inclination.Round();
                buildingElementAnalyticalProperties.Orientation   = tbdSurface.orientation.Round();
                buildingElementAnalyticalProperties.GValue        = tbdElement.GValue().Round();
                buildingElementAnalyticalProperties.LTValue       = tbdElement.LTValue().Round();
                buildingElementAnalyticalProperties.UValue        = tbdElement.UValue().Round();
                opening.Fragments.Add(buildingElementAnalyticalProperties);

                if (tbdPolygon != null)
                {
                    opening.Edges = tbdPolygon.FromTAS().CleanPolyline(tasSettings.AngleTolerance, tasSettings.MinimumSegmentLength).ToEdges();
                }
                else
                {
                    opening.Edges = roomSurface.GetPerimeter().FromTAS().CleanPolyline(tasSettings.AngleTolerance, tasSettings.MinimumSegmentLength).ToEdges();
                }

                if (roomSurface.parentSurface != null && roomSurface.parentSurface.zoneSurface != null && roomSurface.parentSurface.zoneSurface.buildingElement != null)
                {
                    TASOpeningData tasData = new TASOpeningData();
                    tasData.ParentGUID = roomSurface.parentSurface.zoneSurface.GUID.RemoveBrackets();
                    tasData.ParentName = roomSurface.parentSurface.zoneSurface.buildingElement.name;
                    opening.Fragments.Add(tasData);
                }
            }

            return(opening);
        }
Example #7
0
        public static TBD.Polygon ToTASPolygon(this BHG.Polyline polyline, TBD.Polygon tbdPolygon)
        {
            if (polyline == null)
            {
                return(tbdPolygon);
            }

            foreach (BHG.Point pt in polyline.ControlPoints)
            {
                TBD.TasPoint p = tbdPolygon.AddPoint();
                p = pt.ToTAS(p);
            }

            return(tbdPolygon);
        }
Example #8
0
        /***************************************************/

        public static float MinElevation(TBD.Perimeter tbdPerimeter)
        {
            TBD.Polygon tbdPolygon   = tbdPerimeter.GetFace();
            int         indexepoints = 0;
            float       aZvalue      = float.MaxValue;

            TBD.TasPoint TasPoint = tbdPolygon.GetPoint(indexepoints);
            while (TasPoint != null)
            {
                if (TasPoint.z < aZvalue)
                {
                    aZvalue = TasPoint.z;
                }
                indexepoints++;
                TasPoint = tbdPolygon.GetPoint(indexepoints);
            }

            return(aZvalue);
        }
Example #9
0
        public static List <TBD.Polygon> Holes(this TBD.Perimeter perimeter)
        {
            if (perimeter == null)
            {
                return(null);
            }

            List <TBD.Polygon> result = new List <TBD.Polygon>();

            int index = 0;

            TBD.Polygon polygon = perimeter.GetHole(index);
            while (polygon != null)
            {
                result.Add(polygon);
                index++;

                polygon = perimeter.GetHole(index);
            }

            return(result);
        }
Example #10
0
 public static TBD.Polygon ToTAS(this BHE.Opening opening, TBD.Polygon tbdPolygon)
 {
     //TODO:Add properties for Opening
     tbdPolygon = opening.Polyline().ToTASPolygon(tbdPolygon);
     return(tbdPolygon);
 }
Example #11
0
        public static TBD.Perimeter ToTBD(this Face3D face3D, TBD.RoomSurface roomSurface = null)
        {
            if (face3D == null)
            {
                return(null);
            }

            IClosedPlanar3D externalEdge3D = face3D.GetExternalEdge3D();

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

            ISegmentable3D segmentable3D = externalEdge3D as ISegmentable3D;

            if (segmentable3D == null)
            {
                throw new System.NotImplementedException();
            }

            TBD.Perimeter result = roomSurface?.CreatePerimeter();
            if (result == null)
            {
                result = new TBD.Perimeter();
            }

            TBD.Polygon polygon = result.CreateFace();

            List <Point3D> point3Ds = segmentable3D.GetPoints();

            if (point3Ds != null)
            {
                foreach (Point3D point3D in point3Ds)
                {
                    if (point3D == null)
                    {
                        continue;
                    }

                    polygon.AddCoordinate(System.Convert.ToSingle(point3D.X), System.Convert.ToSingle(point3D.Y), System.Convert.ToSingle(point3D.Z));
                }
            }

            List <IClosedPlanar3D> internalEdge3Ds = face3D.GetInternalEdge3Ds();

            if (internalEdge3Ds != null && internalEdge3Ds.Count != 0)
            {
                foreach (IClosedPlanar3D closedPlanar3D in internalEdge3Ds)
                {
                    if (closedPlanar3D == null)
                    {
                        continue;
                    }

                    segmentable3D = closedPlanar3D as ISegmentable3D;
                    if (segmentable3D == null)
                    {
                        throw new System.NotImplementedException();
                    }

                    polygon = result.AddHole();

                    point3Ds = segmentable3D.GetPoints();
                    if (point3Ds != null)
                    {
                        foreach (Point3D point3D in point3Ds)
                        {
                            if (point3D == null)
                            {
                                continue;
                            }

                            polygon.AddCoordinate(System.Convert.ToSingle(point3D.X), System.Convert.ToSingle(point3D.Y), System.Convert.ToSingle(point3D.Z));
                        }
                    }
                }
            }

            return(result);
        }
Example #12
0
        public static BHE.Panel FromTAS(this TBD.buildingElement tbdElement, TBD.zoneSurface tbdSurface, TASSettings tasSettings)
        {
            BHE.Panel element = new BHE.Panel();

            TBD.BuildingElementType tbdElementType = ((TBD.BuildingElementType)tbdElement.BEType);
            TASPanelData            tasData        = new TASPanelData();

            tasData.PanelIsOpening = tbdElementType.ElementIsOpening();

            //Add a flag on the element for the final read
            if (tbdElementType.ElementIsOpening())
            {
                //Find out what the fix was - frame or pane?
                BHE.OpeningType fixedOpeningType = tbdElementType.FromTASOpeningType().FixBuildingElementType(tbdElement, tbdSurface);
                tasData.OpeningIsFrame = fixedOpeningType.OpeningIsFrame();
            }

            BHE.PanelType     elementType         = ((TBD.BuildingElementType)tbdElement.BEType).FromTAS();
            BHPC.Construction elementConstruction = tbdElement.GetConstruction().FromTAS();

            element.Name         = tbdElement.name;
            element.Type         = elementType;
            element.Construction = elementConstruction;

            element.Fragments.Add(tasData);

            //EnvironmentContextProperties
            BHP.OriginContextFragment environmentContextProperties = new BHP.OriginContextFragment();
            environmentContextProperties.ElementID   = tbdSurface.GUID.RemoveBrackets();
            environmentContextProperties.Description = tbdElement.description;
            environmentContextProperties.TypeName    = tbdSurface.buildingElement.name;
            element.Fragments.Add(environmentContextProperties);

            //BuildingElementContextProperties
            BHP.PanelContextFragment buildingElementContextProperties = new BHP.PanelContextFragment();
            element.ConnectedSpaces.Add(tbdSurface.zone.name);
            if ((int)tbdSurface.type == 3)
            {
                element.ConnectedSpaces.Add(tbdSurface.linkSurface.zone.name);
            }
            else
            {
                element.ConnectedSpaces.Add("-1");
            }

            buildingElementContextProperties.IsAir    = tbdElement.ghost != 0;
            buildingElementContextProperties.IsGround = tbdElement.ground != 0;
            buildingElementContextProperties.Colour   = BH.Engine.Adapters.TAS.Query.GetRGB(tbdElement.colour).ToString();
            buildingElementContextProperties.Reversed = tbdSurface.reversed != 0;
            element.Fragments.Add(buildingElementContextProperties);

            //BuildingElementAnalyticalProperties
            BHP.PanelAnalyticalFragment buildingElementAnalyticalProperties = new BHP.PanelAnalyticalFragment();
            buildingElementAnalyticalProperties.Altitude      = tbdSurface.altitude.Round();
            buildingElementAnalyticalProperties.AltitudeRange = tbdSurface.altitudeRange.Round();
            buildingElementAnalyticalProperties.Inclination   = tbdSurface.inclination.Round();
            buildingElementAnalyticalProperties.Orientation   = tbdSurface.orientation.Round();
            buildingElementAnalyticalProperties.GValue        = tbdElement.GValue().Round();
            buildingElementAnalyticalProperties.LTValue       = tbdElement.LTValue().Round();
            buildingElementAnalyticalProperties.UValue        = tbdElement.UValue().Round();
            element.Fragments.Add(buildingElementAnalyticalProperties);

            List <BHG.Polyline> panelCurve = new List <BHG.Polyline>();
            int surfaceIndex = 0;

            TBD.RoomSurface roomSurface = null;

            while ((roomSurface = tbdSurface.GetRoomSurface(surfaceIndex)) != null)
            {
                TBD.Perimeter tbdPerimeter = roomSurface.GetPerimeter();
                if (tbdPerimeter != null)
                {
                    panelCurve.Add(tbdPerimeter.FromTAS());

                    //Add openings
                    int         openingIndex   = 0;
                    TBD.Polygon openingPolygon = null;
                    while ((openingPolygon = tbdPerimeter.GetHole(openingIndex)) != null)
                    {
                        element.Openings.Add(openingPolygon.FromTASOpening(roomSurface, tasSettings));
                        openingIndex++;
                    }
                }

                surfaceIndex++;
            }

            if (panelCurve.Count == 1)
            {
                element.ExternalEdges = panelCurve.First().CleanPolyline(tasSettings.AngleTolerance, tasSettings.MinimumSegmentLength).ToEdges();
            }
            else
            {
                try
                {
                    List <BHG.Polyline> polylines = Geometry.Compute.BooleanUnion(panelCurve, 1e-3);
                    if (polylines.Count == 1)
                    {
                        element.ExternalEdges = polylines.First().CleanPolyline(tasSettings.AngleTolerance, tasSettings.MinimumSegmentLength).ToEdges();
                    }
                    else
                    {
                        element.ExternalEdges = Geometry.Create.PolyCurve(polylines).ICollapseToPolyline(BH.oM.Geometry.Tolerance.Angle).CleanPolyline(tasSettings.AngleTolerance, tasSettings.MinimumSegmentLength).ToEdges();
                    }
                }
                catch (Exception e)
                {
                    BH.Engine.Base.Compute.RecordWarning("An error occurred in building buildingElement ID - " + element.BHoM_Guid + " - error was: " + e.ToString());
                    element.ExternalEdges = Geometry.Create.PolyCurve(panelCurve).ICollapseToPolyline(BH.oM.Geometry.Tolerance.Angle).CleanPolyline(tasSettings.AngleTolerance, tasSettings.MinimumSegmentLength).ToEdges();
                }
            }

            tasData.TASID                   = tbdSurface.GUID.RemoveBrackets();
            tasData.TASName                 = "Z_" + tbdSurface.zone.number + "_" + tbdSurface.number + "_" + tbdSurface.zone.name;
            tasData.Type                    = System.Convert.ToString(tbdSurface.type);
            tasData.Area                    = tbdSurface.area.Round();
            tasData.InternalArea            = tbdSurface.internalArea.Round();
            tasData.Width                   = tbdElement.width.Round();
            tasData.MaterialLayersThickness = tbdElement.GetConstruction().ConstructionThickness().Round();

            element.Fragments.Add(tasData);

            //AddingExtended Properties for a frame
            BHE.OpeningType elementOpeningType = tbdElementType.FromTASOpeningType().FixBuildingElementType(tbdElement, tbdSurface);
            if (elementOpeningType == BHE.OpeningType.RooflightWithFrame || elementOpeningType == BHE.OpeningType.WindowWithFrame)
            {
                if (element.Openings.FirstOrDefault() != null)
                {
                    element.Openings[0].FrameConstruction = elementConstruction;
                }
            }

            return(element);
        }