public List <Brep> CreateWallBrep() { double offsetDistance1 = this.thickness / 2 + offset; double offsetDistance2 = this.thickness / 2 - offset; List <Brep> solids = new List <Brep>(); Brep solid = new Brep(); for (int i = 0; i < this.wall.Surfaces.Count; i++) { Surface offsetSurface1 = this.wall.Surfaces[i].Offset(offsetDistance1, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance); Surface offsetSurface2 = this.wall.Surfaces[i].Offset(-1 * offsetDistance2, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance); List <Brep> solidBreps = new List <Brep>(); Brep wallBrep1 = offsetSurface1.ToBrep(); BrepEdgeList brepEdges1 = wallBrep1.Edges; Brep wallBrep2 = offsetSurface2.ToBrep(); BrepEdgeList brepEdges2 = wallBrep2.Edges; solidBreps.Add(wallBrep1); solidBreps.Add(wallBrep2); BrepFace wallSurface = wallBrep1.Faces[0]; solids.Add(Brep.CreateFromOffsetFace(wallSurface, -1 * this.thickness, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance, false, true)); } return(solids); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { DA.GetDataTree("nodal_coordinates", out GH_Structure <GH_Number> _r); var r = _r.Branches; var surfaces = new List <Brep>(); DA.GetDataList("S", surfaces); var rigid = new GH_Structure <GH_Number>(); for (int i = 0; i < surfaces.Count; i++) { var surf = surfaces[i]; var face = surf.Faces[0]; var solid = Brep.CreateFromOffsetFace(face, 0.1, 5e-3, true, true); var nodes = new List <GH_Number>(); for (int j = 0; j < r.Count; j++) { var p = new Point3d(r[j][0].Value, r[j][1].Value, r[j][2].Value); if (solid.IsPointInside(p, 5e-3, false) == true) { nodes.Add(new GH_Number(j)); } } rigid.AppendRange(nodes, new GH_Path(i)); } DA.SetDataTree(0, rigid); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { ///Gather GHA inputs Curve boundary = null; DA.GetData <Curve>(0, ref boundary); string osmFilePath = string.Empty; DA.GetData <string>("OSM Data Location", ref osmFilePath); //string userSRStext = "WGS84"; //DA.GetData<string>(2, ref userSRStext); List <string> filterWords = new List <string>(); DA.GetDataList <string>(2, filterWords); List <string> filterKeyValue = new List <string>(); DA.GetDataList <string>(3, filterKeyValue); Transform xformToMetric = new Transform(Rhino.RhinoMath.UnitScale(RhinoDoc.ActiveDoc.ModelUnitSystem, Rhino.UnitSystem.Meters)); Transform xformFromMetric = new Transform(Rhino.RhinoMath.UnitScale(Rhino.UnitSystem.Meters, RhinoDoc.ActiveDoc.ModelUnitSystem)); ///Declare trees Rectangle3d recs = new Rectangle3d(); GH_Structure <GH_String> fieldNames = new GH_Structure <GH_String>(); GH_Structure <GH_String> fieldValues = new GH_Structure <GH_String>(); GH_Structure <IGH_GeometricGoo> geometryGoo = new GH_Structure <IGH_GeometricGoo>(); GH_Structure <IGH_GeometricGoo> buildingGoo = new GH_Structure <IGH_GeometricGoo>(); Point3d max = new Point3d(); Point3d min = new Point3d(); if (boundary != null) { Point3d maxM = boundary.GetBoundingBox(true).Corner(true, false, true); max = Heron.Convert.XYZToWGS(maxM); Point3d minM = boundary.GetBoundingBox(true).Corner(false, true, true); min = Heron.Convert.XYZToWGS(minM); } /// get extents (why is this not part of OsmSharp?) System.Xml.Linq.XDocument xdoc = System.Xml.Linq.XDocument.Load(osmFilePath); if (xdoc.Root.Element("bounds") != null) { double minlat = System.Convert.ToDouble(xdoc.Root.Element("bounds").Attribute("minlat").Value); double minlon = System.Convert.ToDouble(xdoc.Root.Element("bounds").Attribute("minlon").Value); double maxlat = System.Convert.ToDouble(xdoc.Root.Element("bounds").Attribute("maxlat").Value); double maxlon = System.Convert.ToDouble(xdoc.Root.Element("bounds").Attribute("maxlon").Value); Point3d boundsMin = Heron.Convert.WGSToXYZ(new Point3d(minlon, minlat, 0)); Point3d boundsMax = Heron.Convert.WGSToXYZ(new Point3d(maxlon, maxlat, 0)); recs = new Rectangle3d(Plane.WorldXY, boundsMin, boundsMax); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Cannot determine the extents of the OSM file. A 'bounds' element may not be present in the file."); } using (var fileStreamSource = File.OpenRead(osmFilePath)) { /// create a source. OsmSharp.Streams.XmlOsmStreamSource source = new OsmSharp.Streams.XmlOsmStreamSource(fileStreamSource); /// filter by bounding box OsmSharp.Streams.OsmStreamSource sourceClipped = source; if (clipped) { sourceClipped = source.FilterBox((float)max.X, (float)max.Y, (float)min.X, (float)min.Y, true); } /// create a dictionary of elements OsmSharp.Db.Impl.MemorySnapshotDb sourceMem = new OsmSharp.Db.Impl.MemorySnapshotDb(sourceClipped); /// filter the source var filtered = from osmGeos in sourceClipped where osmGeos.Tags != null select osmGeos; if (filterWords.Any()) { filtered = from osmGeos in filtered where osmGeos.Tags.ContainsAnyKey(filterWords) select osmGeos; } if (filterKeyValue.Any()) { List <Tag> tags = new List <Tag>(); foreach (string term in filterKeyValue) { string[] kv = term.Split(','); Tag tag = new Tag(kv[0], kv[1]); tags.Add(tag); } filtered = from osmGeos in filtered where osmGeos.Tags.Intersect(tags).Any() select osmGeos; } source.Dispose(); /// loop over all objects and count them. int nodes = 0, ways = 0, relations = 0; foreach (OsmSharp.OsmGeo osmGeo in filtered) { //NODES if (osmGeo.Type == OsmGeoType.Node) { OsmSharp.Node n = (OsmSharp.Node)osmGeo; GH_Path nodesPath = new GH_Path(0, nodes); //populate Fields and Values for each node fieldNames.AppendRange(GetKeys(osmGeo), nodesPath); fieldValues.AppendRange(GetValues(osmGeo), nodesPath); //get geometry for node Point3d nPoint = Heron.Convert.WGSToXYZ(new Point3d((double)n.Longitude, (double)n.Latitude, 0)); geometryGoo.Append(new GH_Point(nPoint), nodesPath); //increment nodes nodes++; } //////////////////////////////////////////////////////////// //WAYS if (osmGeo.Type == OsmGeoType.Way) { OsmSharp.Way w = (OsmSharp.Way)osmGeo; GH_Path waysPath = new GH_Path(1, ways); //populate Fields and Values for each way fieldNames.AppendRange(GetKeys(osmGeo), waysPath); fieldValues.AppendRange(GetValues(osmGeo), waysPath); //get polyline geometry for way List <Point3d> wayNodes = new List <Point3d>(); foreach (long j in w.Nodes) { OsmSharp.Node n = (OsmSharp.Node)sourceMem.Get(OsmGeoType.Node, j); wayNodes.Add(Heron.Convert.WGSToXYZ(new Point3d((double)n.Longitude, (double)n.Latitude, 0))); } PolylineCurve pL = new PolylineCurve(wayNodes); if (pL.IsClosed) { //create base surface Brep[] breps = Brep.CreatePlanarBreps(pL, DocumentTolerance()); geometryGoo.Append(new GH_Brep(breps[0]), waysPath); } else { geometryGoo.Append(new GH_Curve(pL), waysPath); } //building massing if (w.Tags.ContainsKey("building") || w.Tags.ContainsKey("building:part")) { if (pL.IsClosed) { CurveOrientation orient = pL.ClosedCurveOrientation(Plane.WorldXY); if (orient != CurveOrientation.CounterClockwise) { pL.Reverse(); } Vector3d hVec = new Vector3d(0, 0, GetBldgHeight(osmGeo)); hVec.Transform(xformFromMetric); Extrusion ex = Extrusion.Create(pL, hVec.Z, true); IGH_GeometricGoo bldgGoo = GH_Convert.ToGeometricGoo(ex); buildingGoo.Append(bldgGoo, waysPath); } } //increment ways ways++; } /////////////////////////////////////////////////////////// //RELATIONS if (osmGeo.Type == OsmGeoType.Relation) { OsmSharp.Relation r = (OsmSharp.Relation)osmGeo; GH_Path relationPath = new GH_Path(2, relations); //populate Fields and Values for each relation fieldNames.AppendRange(GetKeys(osmGeo), relationPath); fieldValues.AppendRange(GetValues(osmGeo), relationPath); List <Curve> pLines = new List <Curve>(); // start members loop for (int mem = 0; mem < r.Members.Length; mem++) { GH_Path memberPath = new GH_Path(2, relations, mem); OsmSharp.RelationMember rMem = r.Members[mem]; OsmSharp.OsmGeo rMemGeo = sourceMem.Get(rMem.Type, rMem.Id); if (rMemGeo != null) { //get geometry for node if (rMemGeo.Type == OsmGeoType.Node) { long memNodeId = rMem.Id; OsmSharp.Node memN = (OsmSharp.Node)sourceMem.Get(rMem.Type, rMem.Id); Point3d memPoint = Heron.Convert.WGSToXYZ(new Point3d((double)memN.Longitude, (double)memN.Latitude, 0)); geometryGoo.Append(new GH_Point(memPoint), memberPath); } //get geometry for way if (rMem.Type == OsmGeoType.Way) { long memWayId = rMem.Id; OsmSharp.Way memWay = (OsmSharp.Way)rMemGeo; //get polyline geometry for way List <Point3d> memNodes = new List <Point3d>(); foreach (long memNodeId in memWay.Nodes) { OsmSharp.Node memNode = (OsmSharp.Node)sourceMem.Get(OsmGeoType.Node, memNodeId); memNodes.Add(Heron.Convert.WGSToXYZ(new Point3d((double)memNode.Longitude, (double)memNode.Latitude, 0))); } PolylineCurve memPolyline = new PolylineCurve(memNodes); geometryGoo.Append(new GH_Curve(memPolyline.ToNurbsCurve()), memberPath); CurveOrientation orient = memPolyline.ClosedCurveOrientation(Plane.WorldXY); if (orient != CurveOrientation.CounterClockwise) { memPolyline.Reverse(); } pLines.Add(memPolyline.ToNurbsCurve()); } //get nested relations if (rMem.Type == OsmGeoType.Relation) { ///not sure if this is needed } } } //end members loop bool allClosed = true; foreach (Curve pc in pLines) { if (!pc.IsClosed) { allClosed = false; } } if (pLines.Count > 0 && allClosed) { //create base surface Brep[] breps = Brep.CreatePlanarBreps(pLines, DocumentTolerance()); geometryGoo.RemovePath(relationPath); foreach (Brep b in breps) { geometryGoo.Append(new GH_Brep(b), relationPath); //building massing if (r.Tags.ContainsKey("building") || r.Tags.ContainsKey("building:part")) { Vector3d hVec = new Vector3d(0, 0, GetBldgHeight(osmGeo)); hVec.Transform(xformFromMetric); //create extrusion from base surface buildingGoo.Append(new GH_Brep(Brep.CreateFromOffsetFace(b.Faces[0], hVec.Z, DocumentTolerance(), false, true)), relationPath); } } } //increment relations relations++; } ///end relation loop } ///end filtered loop } ///end osm source loop if (recs.IsValid) { DA.SetData(0, recs); } DA.SetDataTree(1, fieldNames); DA.SetDataTree(2, fieldValues); DA.SetDataTree(3, geometryGoo); DA.SetDataTree(4, buildingGoo); } ///end SolveInstance
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { ///Gather GHA inputs Curve boundary = null; DA.GetData <Curve>(0, ref boundary); string osmFilePath = string.Empty; DA.GetData <string>("OSM Data Location", ref osmFilePath); //string userSRStext = "WGS84"; //DA.GetData<string>(2, ref userSRStext); List <string> filterWords = new List <string>(); DA.GetDataList <string>(2, filterWords); List <string> filterKeyValue = new List <string>(); DA.GetDataList <string>(3, filterKeyValue); Transform xformToMetric = new Transform(scaleToMetric); Transform xformFromMetric = new Transform(scaleFromMetric); ///Declare trees Rectangle3d recs = new Rectangle3d(); GH_Structure <GH_String> fieldNames = new GH_Structure <GH_String>(); GH_Structure <GH_String> fieldValues = new GH_Structure <GH_String>(); GH_Structure <IGH_GeometricGoo> geometryGoo = new GH_Structure <IGH_GeometricGoo>(); GH_Structure <IGH_GeometricGoo> buildingGoo = new GH_Structure <IGH_GeometricGoo>(); Point3d max = new Point3d(); Point3d min = new Point3d(); if (boundary != null) { Point3d maxM = boundary.GetBoundingBox(true).Corner(true, false, true); max = Heron.Convert.XYZToWGS(maxM); Point3d minM = boundary.GetBoundingBox(true).Corner(false, true, true); min = Heron.Convert.XYZToWGS(minM); } /// get extents (why is this not part of OsmSharp?) System.Xml.Linq.XDocument xdoc = System.Xml.Linq.XDocument.Load(osmFilePath); if (xdoc.Root.Element("bounds") != null) { double minlat = System.Convert.ToDouble(xdoc.Root.Element("bounds").Attribute("minlat").Value); double minlon = System.Convert.ToDouble(xdoc.Root.Element("bounds").Attribute("minlon").Value); double maxlat = System.Convert.ToDouble(xdoc.Root.Element("bounds").Attribute("maxlat").Value); double maxlon = System.Convert.ToDouble(xdoc.Root.Element("bounds").Attribute("maxlon").Value); Point3d boundsMin = Heron.Convert.WGSToXYZ(new Point3d(minlon, minlat, 0)); Point3d boundsMax = Heron.Convert.WGSToXYZ(new Point3d(maxlon, maxlat, 0)); recs = new Rectangle3d(Plane.WorldXY, boundsMin, boundsMax); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Cannot determine the extents of the OSM file. A 'bounds' element may not be present in the file. " + "Try turning off clipping in this component's menu."); } using (var fileStreamSource = File.OpenRead(osmFilePath)) { /// create a source. OsmSharp.Streams.XmlOsmStreamSource source = new OsmSharp.Streams.XmlOsmStreamSource(fileStreamSource); /// filter by bounding box OsmSharp.Streams.OsmStreamSource sourceClipped = source; if (clipped) { sourceClipped = source.FilterBox((float)max.X, (float)max.Y, (float)min.X, (float)min.Y, true); } /// create a dictionary of elements OsmSharp.Db.Impl.MemorySnapshotDb sourceMem = new OsmSharp.Db.Impl.MemorySnapshotDb(sourceClipped); /// filter the source var filtered = from osmGeos in sourceClipped where osmGeos.Tags != null select osmGeos; if (filterWords.Any()) { filtered = from osmGeos in filtered where osmGeos.Tags.ContainsAnyKey(filterWords) select osmGeos; } if (filterKeyValue.Any()) { List <Tag> tags = new List <Tag>(); foreach (string term in filterKeyValue) { string[] kv = term.Split(','); Tag tag = new Tag(kv[0], kv[1]); tags.Add(tag); } filtered = from osmGeos in filtered where osmGeos.Tags.Intersect(tags).Any() select osmGeos; } source.Dispose(); /// loop over all objects and count them. int nodes = 0, ways = 0, relations = 0; Dictionary <PolylineCurve, GH_Path> bldgOutlines = new Dictionary <PolylineCurve, GH_Path>(); List <BuildingPart> buildingParts = new List <BuildingPart>(); foreach (OsmSharp.OsmGeo osmGeo in filtered) { //NODES if (osmGeo.Type == OsmGeoType.Node) { OsmSharp.Node n = (OsmSharp.Node)osmGeo; GH_Path nodesPath = new GH_Path(0, nodes); //populate Fields and Values for each node fieldNames.AppendRange(GetKeys(osmGeo), nodesPath); fieldValues.AppendRange(GetValues(osmGeo), nodesPath); //get geometry for node Point3d nPoint = Heron.Convert.WGSToXYZ(new Point3d((double)n.Longitude, (double)n.Latitude, 0)); geometryGoo.Append(new GH_Point(nPoint), nodesPath); //increment nodes nodes++; } //////////////////////////////////////////////////////////// //WAYS if (osmGeo.Type == OsmGeoType.Way) { OsmSharp.Way w = (OsmSharp.Way)osmGeo; GH_Path waysPath = new GH_Path(1, ways); //populate Fields and Values for each way fieldNames.AppendRange(GetKeys(osmGeo), waysPath); fieldValues.AppendRange(GetValues(osmGeo), waysPath); //get polyline geometry for way List <Point3d> wayNodes = new List <Point3d>(); foreach (long j in w.Nodes) { OsmSharp.Node n = (OsmSharp.Node)sourceMem.Get(OsmGeoType.Node, j); wayNodes.Add(Heron.Convert.WGSToXYZ(new Point3d((double)n.Longitude, (double)n.Latitude, 0))); } PolylineCurve pL = new PolylineCurve(wayNodes); if (pL.IsClosed) { //create base surface Brep[] breps = Brep.CreatePlanarBreps(pL, DocumentTolerance()); geometryGoo.Append(new GH_Brep(breps[0]), waysPath); } else { geometryGoo.Append(new GH_Curve(pL), waysPath); } //building massing if ((w.Tags.ContainsKey("building") || w.Tags.ContainsKey("building:part")))// && !w.Tags.ContainsKey("construction")) { if (pL.IsClosed) { ///Populate dictionary for sorting building parts later if (w.Tags.ContainsKey("building")) { bldgOutlines.Add(pL, waysPath); } CurveOrientation orient = pL.ClosedCurveOrientation(Plane.WorldXY); if (orient != CurveOrientation.CounterClockwise) { pL.Reverse(); } ///Move polylines to min height double minHeightWay = GetMinBldgHeight(osmGeo); Vector3d minVec = new Vector3d(0, 0, minHeightWay); //minVec.Transform(xformFromMetric); if (minHeightWay > 0.0) { var minHeightTranslate = Transform.Translation(minVec); pL.Transform(minHeightTranslate); } Vector3d hVec = new Vector3d(0, 0, GetBldgHeight(osmGeo) - minHeightWay); //hVec.Transform(xformFromMetric); Extrusion ex = Extrusion.Create(pL, hVec.Z, true); IGH_GeometricGoo bldgGoo = GH_Convert.ToGeometricGoo(ex); ///Save building parts for sorting later and remove part from geometry goo tree if (w.Tags.ContainsKey("building:part")) { BuildingPart bldgPart = new BuildingPart(pL, bldgGoo, fieldNames[waysPath], fieldValues[waysPath], osmGeo); buildingParts.Add(bldgPart); fieldNames.RemovePath(waysPath); fieldValues.RemovePath(waysPath); geometryGoo.RemovePath(waysPath); ways = ways - 1; } else { buildingGoo.Append(bldgGoo, waysPath); } } } //increment ways ways++; } /////////////////////////////////////////////////////////// //RELATIONS if (osmGeo.Type == OsmGeoType.Relation) { OsmSharp.Relation r = (OsmSharp.Relation)osmGeo; GH_Path relationPath = new GH_Path(2, relations); //populate Fields and Values for each relation fieldNames.AppendRange(GetKeys(osmGeo), relationPath); fieldValues.AppendRange(GetValues(osmGeo), relationPath); List <Curve> pLines = new List <Curve>(); // start members loop for (int mem = 0; mem < r.Members.Length; mem++) { GH_Path memberPath = new GH_Path(2, relations, mem); OsmSharp.RelationMember rMem = r.Members[mem]; OsmSharp.OsmGeo rMemGeo = sourceMem.Get(rMem.Type, rMem.Id); if (rMemGeo != null) { //get geometry for node if (rMemGeo.Type == OsmGeoType.Node) { long memNodeId = rMem.Id; OsmSharp.Node memN = (OsmSharp.Node)sourceMem.Get(rMem.Type, rMem.Id); Point3d memPoint = Heron.Convert.WGSToXYZ(new Point3d((double)memN.Longitude, (double)memN.Latitude, 0)); geometryGoo.Append(new GH_Point(memPoint), memberPath); } //get geometry for way if (rMem.Type == OsmGeoType.Way) { long memWayId = rMem.Id; OsmSharp.Way memWay = (OsmSharp.Way)rMemGeo; //get polyline geometry for way List <Point3d> memNodes = new List <Point3d>(); foreach (long memNodeId in memWay.Nodes) { OsmSharp.Node memNode = (OsmSharp.Node)sourceMem.Get(OsmGeoType.Node, memNodeId); memNodes.Add(Heron.Convert.WGSToXYZ(new Point3d((double)memNode.Longitude, (double)memNode.Latitude, 0))); } PolylineCurve memPolyline = new PolylineCurve(memNodes); geometryGoo.Append(new GH_Curve(memPolyline.ToNurbsCurve()), memberPath); CurveOrientation orient = memPolyline.ClosedCurveOrientation(Plane.WorldXY); if (orient != CurveOrientation.CounterClockwise) { memPolyline.Reverse(); } pLines.Add(memPolyline.ToNurbsCurve()); } //get nested relations if (rMem.Type == OsmGeoType.Relation) { ///not sure if this is needed } } } //end members loop bool allClosed = true; foreach (Curve pc in pLines) { if (!pc.IsClosed) { allClosed = false; } } if (pLines.Count > 0 && allClosed) { ///Move polylines to min height double minHeight = GetMinBldgHeight(osmGeo); if (minHeight > 0.0) { Vector3d minVec = new Vector3d(0, 0, minHeight); //minVec.Transform(xformFromMetric); var minHeightTranslate = Transform.Translation(minVec); for (int i = 0; i < pLines.Count; i++) { pLines[i].Transform(minHeightTranslate); } } ///Create base surface Brep[] breps = Brep.CreatePlanarBreps(pLines, DocumentTolerance()); geometryGoo.RemovePath(relationPath); foreach (Brep b in breps) { geometryGoo.Append(new GH_Brep(b), relationPath); ///Building massing if (r.Tags.ContainsKey("building") || r.Tags.ContainsKey("building:part")) { Vector3d hVec = new Vector3d(0, 0, GetBldgHeight(osmGeo) - minHeight); //hVec.Transform(xformFromMetric); ///Create extrusion from base surface buildingGoo.Append(new GH_Brep(Brep.CreateFromOffsetFace(b.Faces[0], hVec.Z, DocumentTolerance(), false, true)), relationPath); } } } ///Increment relations relations++; } ///End relation loop } ///End filtered loop ///Add building parts to sub-branches under main building for (int partIndex = 0; partIndex < buildingParts.Count; partIndex++) { BuildingPart bldgPart = buildingParts[partIndex]; Point3d partPoint = bldgPart.PartFootprint.PointAtStart; partPoint.Z = 0; bool replaceBuidingMass = false; GH_Path mainBuildingMassPath = new GH_Path(); PolylineCurve massOutline = new PolylineCurve(); bool isRoof = bldgPart.PartOsmGeo.Tags.TryGetValue("roof:shape", out string isRoofString); if (isRoof) { bldgPart.PartGoo = BldgPartToRoof(bldgPart); } foreach (KeyValuePair <PolylineCurve, GH_Path> pair in bldgOutlines) { PointContainment pc = pair.Key.Contains(partPoint, Plane.WorldXY, DocumentTolerance()); if (pc != PointContainment.Outside) { ///Create new sub-branch int numSubBranches = 0; GH_Path partPath = pair.Value.AppendElement(numSubBranches); while (buildingGoo.PathExists(partPath)) { numSubBranches++; partPath = pair.Value.AppendElement(numSubBranches); } ///Add data to sub-branch fieldNames.AppendRange(bldgPart.PartFieldNames, partPath); fieldValues.AppendRange(bldgPart.PartFieldValues, partPath); buildingGoo.Append(bldgPart.PartGoo, partPath); ///Remove the main building mass replaceBuidingMass = true; mainBuildingMassPath = pair.Value; massOutline = pair.Key; } } ///Remove the main building mass if (replaceBuidingMass) { buildingGoo.RemovePath(mainBuildingMassPath); buildingGoo.Append(new GH_Curve(massOutline), mainBuildingMassPath); } else { GH_Path extrasPath = new GH_Path(3, partIndex); buildingGoo.Append(bldgPart.PartGoo, extrasPath); fieldNames.AppendRange(bldgPart.PartFieldNames, extrasPath); fieldValues.AppendRange(bldgPart.PartFieldValues, extrasPath); } } } ///end osm source loop if (recs.IsValid) { DA.SetData(0, recs); } DA.SetDataTree(1, fieldNames); DA.SetDataTree(2, fieldValues); DA.SetDataTree(3, geometryGoo); DA.SetDataTree(4, buildingGoo); } ///end SolveInstance
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { DA.GetDataTree("nodal_coordinates", out GH_Structure <GH_Number> _r); var r = _r.Branches; DA.GetDataTree("reaction force", out GH_Structure <GH_Number> _reac_f); var reac_f = _reac_f.Branches; var C = new Point3d(); DA.GetData("C", ref C); var A = 0.0; DA.GetData("A", ref A); var Zx1 = 0.0; DA.GetData("Zx1", ref Zx1); var Zx2 = 0.0; DA.GetData("Zx2", ref Zx2); var Zy1 = 0.0; DA.GetData("Zy1", ref Zy1); var Zy2 = 0.0; DA.GetData("Zy2", ref Zy2); var Zx = Zx1; var Zy = Zy1; Brep surf = new Brep(); DA.GetData("S", ref surf); var face = surf.Faces[0]; var solid = Brep.CreateFromOffsetFace(face, 0.1, 5e-3, true, true); var N = 0.0; var NX = 0.0; var NY = 0.0; var Nlist = new List <string>(); var Xlist = new List <string>(); var Ylist = new List <string>(); var nlist = new List <string>(); for (int e = 0; e < reac_f.Count; e++) { int i = (int)reac_f[e][0].Value; var p = new Point3d(r[i][0].Value, r[i][1].Value, r[i][2].Value); if (solid.IsPointInside(p, 5e-3, false) == true) { N += reac_f[e][3].Value; NX += reac_f[e][3].Value * p[0]; NY += reac_f[e][3].Value * p[1]; if (on_off == 1) { nlist.Add(((int)reac_f[e][0].Value).ToString()); Nlist.Add(Math.Round(reac_f[e][3].Value, 2).ToString()); Xlist.Add(Math.Round(p[0], 2).ToString()); Ylist.Add(Math.Round(p[1], 2).ToString()); } } } var X = NX / N; var Y = NY / N; var CX = C[0]; var CY = C[1]; var C2 = new Point3d(X, Y, C[2]); if (X < CX) { Zy = Zy2; } if (Y < CY) { Zx = Zx2; } var ex = Math.Abs(X - CX); var ey = Math.Abs(Y - CY); var MY = N * ex; var MX = N * ey; DA.SetData("C1", C); DA.SetData("C2", C2); var M_Z = Math.Sqrt(Math.Pow(MX / Zx, 2) + Math.Pow(MY / Zy, 2)); var N_A = N / A; DA.SetData("N", N); DA.SetData("MX", MX); DA.SetData("MY", MY); DA.SetData("N/A+M/Z", N_A + M_Z); DA.SetData("N/A-M/Z", N_A - M_Z); if (on_off_1 == 1) { _p1.Add(C); } if (on_off_2 == 1) { _p2.Add(C2); } if (on_off == 1) { var Pa = 0.0; DA.GetData("Pa", ref Pa); var pdfname = "SolidBaseCheck"; DA.GetData("outputname", ref pdfname); // フォントリゾルバーのグローバル登録 if (PdfCreate.JapaneseFontResolver.fontset == 0) { PdfSharp.Fonts.GlobalFontSettings.FontResolver = fontresolver; PdfCreate.JapaneseFontResolver.fontset = 1; } // PDFドキュメントを作成。 PdfDocument document = new PdfDocument(); document.Info.Title = pdfname; document.Info.Author = "Shinnosuke Fujita, Assoc. Prof., The Univ. of Kitakyushu"; // フォントを作成。 XFont font = new XFont("Gen Shin Gothic", 8, XFontStyle.Regular); XFont fontbold = new XFont("Gen Shin Gothic", 8, XFontStyle.Bold); var pen = XPens.Black; var label1 = new List <string>(); var label2 = new List <string>(); var label3 = new List <string>(); var label4 = new List <string>(); label1.Add("節点番号"); label2.Add("X[m]"); label3.Add("Y[m]"); label4.Add("軸力N[kN]"); for (int e = 0; e < Nlist.Count; e++) { label1.Add(nlist[e]); label2.Add(Xlist[e]); label3.Add(Ylist[e]); label4.Add(Nlist[e]); } label1.Add("∑N[kN]"); label3.Add(Math.Round(N, 0).ToString()); label2.Add(""); label4.Add(""); label1.Add("A[m2]"); label3.Add(Math.Round(A, 2).ToString()); label2.Add(""); label4.Add(""); label1.Add("N/A[kN/m2]"); label3.Add(Math.Round(N_A, 2).ToString()); label2.Add(""); label4.Add(""); label1.Add("重心座標X[m]"); label2.Add("重心座標Y[m]"); label3.Add(Math.Round(X, 2).ToString()); label4.Add(Math.Round(Y, 2).ToString()); label1.Add("図心座標X[m]"); label2.Add("図心座標Y[m]"); label3.Add(Math.Round(CX, 2).ToString()); label4.Add(Math.Round(CY, 2).ToString()); label1.Add("偏心距離ex[m]"); label2.Add("偏心距離ey[m]"); label3.Add(Math.Round(ex, 2).ToString()); label4.Add(Math.Round(ey, 2).ToString()); label1.Add("偏心Mx[kNm]"); label2.Add("偏心My[kNm]"); label3.Add(Math.Round(MX, 2).ToString()); label4.Add(Math.Round(MY, 2).ToString()); label1.Add("断面係数Zx[m3]"); label2.Add("断面係数Zy[m3]"); label3.Add(Math.Round(Zx, 2).ToString()); label4.Add(Math.Round(Zy, 2).ToString()); label1.Add("N/A+M/Z[kN/m2]"); label2.Add("N/A-M/Z[kN/m2]"); label3.Add(Math.Round(N_A + M_Z, 2).ToString()); label4.Add(Math.Round(N_A - M_Z, 2).ToString()); label1.Add("長期地耐力[kN/m2]"); label2.Add("検定比"); label3.Add(Math.Round(Pa, 2).ToString()); if ((N_A + M_Z) / Pa <= 1) { label4.Add(Math.Round((N_A + M_Z) / Pa, 2).ToString() + ":O.K."); } else { label4.Add(Math.Round((N_A + M_Z) / Pa, 2).ToString() + ":N.G."); } var label_width = 100; var offset_x = 25; var offset_y = 25; var pitchy = 13; PdfPage page = new PdfPage(); page.Size = PageSize.A4; for (int i = 0; i < label1.Count; i++) { var color1 = XBrushes.Black; var color2 = XBrushes.Black; var color3 = XBrushes.Black; var color4 = XBrushes.Black; if (i % 50 == 0) { page = document.AddPage(); // 空白ページを作成。 gfx = XGraphics.FromPdfPage(page); // 描画するためにXGraphicsオブジェクトを取得。 if (i > reac_f.Count && i < reac_f.Count + 4) { gfx.DrawLine(pen, offset_x, offset_y + pitchy * i, offset_x + label_width * 4, offset_y + pitchy * i); //横線 gfx.DrawLine(pen, offset_x + label_width * 0, offset_y + pitchy * i, offset_x + label_width * 0, offset_y + pitchy * (i + 1)); //縦線 gfx.DrawLine(pen, offset_x + label_width * 1, offset_y + pitchy * i, offset_x + label_width * 1, offset_y + pitchy * (i + 1)); //縦線 gfx.DrawLine(pen, offset_x + label_width * 4, offset_y + pitchy * i, offset_x + label_width * 4, offset_y + pitchy * (i + 1)); //縦線 } else if (i > 1 && i < reac_f.Count + 1) { gfx.DrawLine(pen, offset_x + label_width * 0, offset_y + pitchy * i, offset_x + label_width * 0, offset_y + pitchy * (i + 1)); //縦線 gfx.DrawLine(pen, offset_x + label_width * 1, offset_y + pitchy * i, offset_x + label_width * 1, offset_y + pitchy * (i + 1)); //縦線 gfx.DrawLine(pen, offset_x + label_width * 2, offset_y + pitchy * i, offset_x + label_width * 2, offset_y + pitchy * (i + 1)); //縦線 gfx.DrawLine(pen, offset_x + label_width * 3, offset_y + pitchy * i, offset_x + label_width * 3, offset_y + pitchy * (i + 1)); //縦線 gfx.DrawLine(pen, offset_x + label_width * 4, offset_y + pitchy * i, offset_x + label_width * 4, offset_y + pitchy * (i + 1)); //縦線 } else { gfx.DrawLine(pen, offset_x, offset_y + pitchy * i, offset_x + label_width * 4, offset_y + pitchy * i); //横線 gfx.DrawLine(pen, offset_x + label_width * 0, offset_y + pitchy * i, offset_x + label_width * 0, offset_y + pitchy * (i + 1)); //縦線 gfx.DrawLine(pen, offset_x + label_width * 1, offset_y + pitchy * i, offset_x + label_width * 1, offset_y + pitchy * (i + 1)); //縦線 gfx.DrawLine(pen, offset_x + label_width * 2, offset_y + pitchy * i, offset_x + label_width * 2, offset_y + pitchy * (i + 1)); //縦線 gfx.DrawLine(pen, offset_x + label_width * 3, offset_y + pitchy * i, offset_x + label_width * 3, offset_y + pitchy * (i + 1)); //縦線 gfx.DrawLine(pen, offset_x + label_width * 4, offset_y + pitchy * i, offset_x + label_width * 4, offset_y + pitchy * (i + 1)); //縦線 } } gfx.DrawString(label1[i], font, color1, new XRect(offset_x + label_width * 0, offset_y + pitchy * i, label_width, offset_y + pitchy * (i + 1)), XStringFormats.TopCenter); gfx.DrawString(label2[i], font, color1, new XRect(offset_x + label_width * 1, offset_y + pitchy * i, label_width, offset_y + pitchy * (i + 1)), XStringFormats.TopCenter); gfx.DrawString(label3[i], font, color1, new XRect(offset_x + label_width * 2, offset_y + pitchy * i, label_width, offset_y + pitchy * (i + 1)), XStringFormats.TopCenter); gfx.DrawString(label4[i], font, color1, new XRect(offset_x + label_width * 3, offset_y + pitchy * i, label_width, offset_y + pitchy * (i + 1)), XStringFormats.TopCenter); if (i > reac_f.Count && i < reac_f.Count + 4) { gfx.DrawLine(pen, offset_x, offset_y + pitchy * i, offset_x + label_width * 4, offset_y + pitchy * i); //横線 gfx.DrawLine(pen, offset_x + label_width * 0, offset_y + pitchy * i, offset_x + label_width * 0, offset_y + pitchy * (i + 1)); //縦線 gfx.DrawLine(pen, offset_x + label_width * 1, offset_y + pitchy * i, offset_x + label_width * 1, offset_y + pitchy * (i + 1)); //縦線 gfx.DrawLine(pen, offset_x + label_width * 4, offset_y + pitchy * i, offset_x + label_width * 4, offset_y + pitchy * (i + 1)); //縦線 } else if (i > 1 && i < reac_f.Count + 1) { gfx.DrawLine(pen, offset_x + label_width * 0, offset_y + pitchy * i, offset_x + label_width * 0, offset_y + pitchy * (i + 1)); //縦線 gfx.DrawLine(pen, offset_x + label_width * 1, offset_y + pitchy * i, offset_x + label_width * 1, offset_y + pitchy * (i + 1)); //縦線 gfx.DrawLine(pen, offset_x + label_width * 2, offset_y + pitchy * i, offset_x + label_width * 2, offset_y + pitchy * (i + 1)); //縦線 gfx.DrawLine(pen, offset_x + label_width * 3, offset_y + pitchy * i, offset_x + label_width * 3, offset_y + pitchy * (i + 1)); //縦線 gfx.DrawLine(pen, offset_x + label_width * 4, offset_y + pitchy * i, offset_x + label_width * 4, offset_y + pitchy * (i + 1)); //縦線 } else { gfx.DrawLine(pen, offset_x, offset_y + pitchy * i, offset_x + label_width * 4, offset_y + pitchy * i); //横線 gfx.DrawLine(pen, offset_x + label_width * 0, offset_y + pitchy * i, offset_x + label_width * 0, offset_y + pitchy * (i + 1)); //縦線 gfx.DrawLine(pen, offset_x + label_width * 1, offset_y + pitchy * i, offset_x + label_width * 1, offset_y + pitchy * (i + 1)); //縦線 gfx.DrawLine(pen, offset_x + label_width * 2, offset_y + pitchy * i, offset_x + label_width * 2, offset_y + pitchy * (i + 1)); //縦線 gfx.DrawLine(pen, offset_x + label_width * 3, offset_y + pitchy * i, offset_x + label_width * 3, offset_y + pitchy * (i + 1)); //縦線 gfx.DrawLine(pen, offset_x + label_width * 4, offset_y + pitchy * i, offset_x + label_width * 4, offset_y + pitchy * (i + 1)); //縦線 } if (i == label1.Count - 1) { gfx.DrawLine(pen, offset_x, offset_y + pitchy * (i + 1), offset_x + label_width * 4, offset_y + pitchy * (i + 1));//横線 } } var dir = Path.GetDirectoryName(Rhino.RhinoDoc.ActiveDoc.Path); // ドキュメントを保存。 var filename = dir + "/" + pdfname + ".pdf"; document.Save(filename); // ビューアを起動。 Process.Start(filename); } }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { InputChecker inputChecker = new InputChecker(this); #region GetIputFromCanvas GH_Structure <GH_Brep> inGhBreps = new GH_Structure <GH_Brep>(); bool areBrepsOk = DA.GetDataTree(0, out inGhBreps); inputChecker.StopIfConversionIsFailed(areBrepsOk); inGhBreps.Graft(GH_GraftMode.GraftAll); inGhBreps.Simplify(GH_SimplificationMode.CollapseAllOverlaps); GH_Structure <GH_Number> inGhDistances = new GH_Structure <GH_Number>(); bool areDistancesOk = DA.GetDataTree(1, out inGhDistances); inputChecker.StopIfConversionIsFailed(areDistancesOk); GH_Structure <GH_Number> ghDistances = new GH_Structure <GH_Number>(); ghDistances = ValuesAllocator.NumbersDSFromBreps(inGhBreps, inGhDistances, ghDistances); GH_Structure <GH_Boolean> inGhBothSides = new GH_Structure <GH_Boolean>(); bool areBoolBothSidesOk = DA.GetDataTree(2, out inGhBothSides); inputChecker.StopIfConversionIsFailed(areBoolBothSidesOk); GH_Structure <GH_Boolean> ghBothSides = new GH_Structure <GH_Boolean>(); ghBothSides = ValuesAllocator.BoolDSFromBreps(inGhBreps, inGhBothSides, ghBothSides); GH_Structure <GH_Boolean> inGhFlipNormals = new GH_Structure <GH_Boolean>(); bool areBoolFlipNormalsOk = DA.GetDataTree(3, out inGhFlipNormals); inputChecker.StopIfConversionIsFailed(areBoolFlipNormalsOk); GH_Structure <GH_Boolean> ghFlipNormals = new GH_Structure <GH_Boolean>(); ghFlipNormals = ValuesAllocator.BoolDSFromBreps(inGhBreps, inGhFlipNormals, ghFlipNormals); bool useParallel = false; DA.GetData <bool>(4, ref useParallel); double docTollerance = DocumentTolerance(); #endregion GH_Structure <GH_Brep> ghSolidBreps = new GH_Structure <GH_Brep>(); if (useParallel) { this.Message = Constants.Constants.PARALLEL_MESSAGE; this.AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, Constants.Constants.PARALLEL_WARNING); int processorCount = Environment.ProcessorCount - 1; //WORK IN PARALLEL ConcurrentDictionary <GH_Path, Brep> solidBrepsPA = new ConcurrentDictionary <GH_Path, Brep>(); Parallel.ForEach(inGhBreps.Paths, new ParallelOptions { MaxDegreeOfParallelism = processorCount }, path => { Brep brepToSolidify = inGhBreps.get_DataItem(path, 0).Value; bool flipTheNormal = ghFlipNormals.get_DataItem(path, 0).Value; bool bothSide = ghBothSides.get_DataItem(path, 0).Value; double distance = ghDistances.get_DataItem(path, 0).Value; if (flipTheNormal) { distance *= -1; } foreach (var brepFace in brepToSolidify.Faces) { solidBrepsPA[path] = Brep.CreateFromOffsetFace(brepFace, distance, docTollerance, bothSide, true); } }); foreach (KeyValuePair <GH_Path, Brep> keyValueBrep in solidBrepsPA) { GH_Brep ghBrep = null; if (GH_Convert.ToGHBrep(keyValueBrep.Value, GH_Conversion.Both, ref ghBrep)) { ghSolidBreps.Append(ghBrep, keyValueBrep.Key); } else { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Conversion Failed"); return; } } }//End Parallel Computation else { this.Message = Constants.Constants.SERIAL_MESSAGE; foreach (GH_Path path in inGhBreps.Paths) { Brep brepToSolidify = inGhBreps.get_DataItem(path, 0).Value; bool flipTheNormal = ghFlipNormals.get_DataItem(path, 0).Value; bool bothSide = ghBothSides.get_DataItem(path, 0).Value; double distance = ghDistances.get_DataItem(path, 0).Value; if (flipTheNormal) { distance *= -1; } foreach (var brepFace in brepToSolidify.Faces) { Brep solidBrep = Brep.CreateFromOffsetFace(brepFace, distance, docTollerance, bothSide, true); GH_Brep ghBrep = null; if (GH_Convert.ToGHBrep(solidBrep, GH_Conversion.Both, ref ghBrep)) { ghSolidBreps.Append(ghBrep, path); } else { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Conversion Failed"); return; } } } }//End Serial Computation #region SendDataToCanvas ghSolidBreps.Simplify(GH_SimplificationMode.CollapseAllOverlaps); DA.SetDataTree(0, ghSolidBreps); #endregion }//end SolveInstance