public static BHX.Polyloop ToGBXML(this BHG.Polyline pLine, GBXMLSettings settings, double tolerance = BHG.Tolerance.Distance) { BHX.Polyloop polyloop = new BHX.Polyloop(); pLine = pLine.CleanPolyline(minimumSegmentLength: tolerance); List <BHG.Point> pts = pLine.DiscontinuityPoints(); if (pts.Count == 0) { return(polyloop); } int count = ((pts.First().SquareDistance(pts.Last()) < (tolerance * tolerance)) ? pts.Count - 1 : pts.Count); List <BHX.CartesianPoint> cartpoint = new List <BHX.CartesianPoint>(); for (int i = 0; i < count; i++) { BHX.CartesianPoint cpt = pts[i].ToGBXML(settings); List <string> coord = new List <string>(); cartpoint.Add(cpt); } polyloop.CartesianPoint = cartpoint.ToArray(); return(polyloop); }
public static BHX.Opening ToGBXML(this BHE.Opening opening, BHE.Panel hostPanel, GBXMLSettings settings) { BHX.Opening gbOpening = new BHX.Opening(); BHG.Polyline pLine = opening.Polyline(); gbOpening.Name = opening.Name; gbOpening.ID = "opening" + opening.BHoM_Guid.ToString().Replace("-", "").Substring(0, 5); gbOpening.PlanarGeometry.PolyLoop = pLine.ToGBXML(settings); gbOpening.PlanarGeometry.ID = "openingPGeom-" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 5); gbOpening.RectangularGeometry.CartesianPoint = BH.Engine.Geometry.Query.Centroid(pLine).ToGBXML(settings); gbOpening.RectangularGeometry.Height = Math.Round(opening.Height(), settings.RoundingSettings.GeometryHeight); //TODO: temporary solution to get valid file to be replaced with correct height if (opening.Height() == 0) { gbOpening.RectangularGeometry.Height = 0.1; } gbOpening.RectangularGeometry.Width = Math.Round(opening.Width(), settings.RoundingSettings.GeometryWidth); gbOpening.RectangularGeometry.ID = "rGeomOpening-" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 5); pLine = pLine.CleanPolyline(minimumSegmentLength: settings.DistanceTolerance); double openingArea = pLine.Area(); double panelArea = hostPanel.Polyline().Area(); if (openingArea >= panelArea) { pLine = BH.Engine.Geometry.Modify.Offset(pLine, settings.OffsetDistance); if (pLine == null) { pLine = opening.Polyline(); //Reset the polyline if something went wrong with the offset } gbOpening.PlanarGeometry.PolyLoop = pLine.ToGBXML(settings); } //Normals away from space //if (!BH.Engine.Environment.Query.NormalAwayFromSpace(pLine, hostSpace, settings.PlanarTolerance)) //gbOpening.PlanarGeometry.PolyLoop = pLine.Flip().ToGBXML(); gbOpening.CADObjectID = opening.CADObjectID(); gbOpening.OpeningType = opening.Type.ToGBXML(); BHP.OriginContextFragment contextProperties = opening.FindFragment <BHP.OriginContextFragment>(typeof(BHP.OriginContextFragment)); string elementID = ""; string familyName = ""; if (contextProperties != null) { elementID = contextProperties.ElementID; familyName = contextProperties.TypeName; } if (gbOpening.OpeningType.ToLower() == "fixedwindow" && contextProperties != null && contextProperties.TypeName.ToLower().Contains("skylight")) { gbOpening.OpeningType = "FixedSkylight"; } if (familyName == "System Panel") //No SAM_BuildingElementType for this one atm { gbOpening.OpeningType = "FixedWindow"; } if (settings.ReplaceSolidOpeningsIntoDoors && gbOpening.OpeningType.Contains("Window") && (opening.OpeningConstruction != null && opening.OpeningConstruction.Name.Contains("SLD"))) //Change windows with SLD construction into doors for IES { gbOpening.OpeningType = "NonSlidingDoor"; } if (settings.IncludeConstructions) { gbOpening.WindowTypeIDRef = "window-" + (contextProperties != null ? contextProperties.TypeName.CleanName() : (opening.OpeningConstruction != null ? opening.OpeningConstruction.Name.CleanName() : "")); } else { gbOpening.WindowTypeIDRef = null; } gbOpening.ConstructionIDRef = null; //ToDo review having this property on an opening? return(gbOpening); }