From 957a4ed8147d53ef9f87548e13bbc6ffdbb3536d Mon Sep 17 00:00:00 2001 From: KatKatKateryna <89912278+KatKatKateryna@users.noreply.github.com> Date: Tue, 10 Sep 2024 13:27:13 +0100 Subject: [PATCH] Agis fix required units (#224) * fix arcgis units * usings * correct units --------- Co-authored-by: Jedd Morgan <45512892+JR-Morgan@users.noreply.github.com> --- .../Raw/MultipatchListToHostConverter.cs | 3 +- .../Raw/GisFeatureToSpeckleConverter.cs | 11 +++--- .../MultipatchFeatureToSpeckleConverter.cs | 36 ++++++++++++++----- .../Raw/PolygonFeatureToSpeckleConverter.cs | 14 ++++++-- 4 files changed, 48 insertions(+), 16 deletions(-) diff --git a/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToHost/Raw/MultipatchListToHostConverter.cs b/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToHost/Raw/MultipatchListToHostConverter.cs index ef2ce095b..14cf4c965 100644 --- a/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToHost/Raw/MultipatchListToHostConverter.cs +++ b/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToHost/Raw/MultipatchListToHostConverter.cs @@ -1,6 +1,5 @@ using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Sdk.Common; namespace Speckle.Converters.ArcGIS3.ToHost.Raw; @@ -27,7 +26,7 @@ public ACG.Multipatch Convert(List target) { newPatch.AddPoint( _pointConverter.Convert( - new SOG.Point(part.vertices[i * 3], part.vertices[i * 3 + 1], part.vertices[i * 3 + 2], Units.Meters) //TODO: this can't be right (units) + new SOG.Point(part.vertices[i * 3], part.vertices[i * 3 + 1], part.vertices[i * 3 + 2], part.units) ) ); } diff --git a/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToSpeckle/Raw/GisFeatureToSpeckleConverter.cs b/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToSpeckle/Raw/GisFeatureToSpeckleConverter.cs index 7db4fba6b..94c537ad5 100644 --- a/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToSpeckle/Raw/GisFeatureToSpeckleConverter.cs +++ b/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToSpeckle/Raw/GisFeatureToSpeckleConverter.cs @@ -1,8 +1,8 @@ using ArcGIS.Core.Data; using Speckle.Converters.ArcGIS3.Utils; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Objects; -using Speckle.Sdk.Common; using Speckle.Sdk.Models; namespace Speckle.Converters.ArcGIS3.ToSpeckle.Raw; @@ -15,6 +15,7 @@ public class GisFeatureToSpeckleConverter : ITypedConverter<(Row, string), IGisF private readonly ITypedConverter> _polygonConverter; private readonly ITypedConverter> _multipatchConverter; private readonly ITypedConverter _attributeConverter; + private readonly IConversionContextStack _contextStack; public GisFeatureToSpeckleConverter( ITypedConverter pointConverter, @@ -22,7 +23,8 @@ public GisFeatureToSpeckleConverter( ITypedConverter> polylineConverter, ITypedConverter> polygonConverter, ITypedConverter> multipatchConverter, - ITypedConverter attributeConverter + ITypedConverter attributeConverter, + IConversionContextStack contextStack ) { _pointConverter = pointConverter; @@ -31,6 +33,7 @@ ITypedConverter attributeConverter _polygonConverter = polygonConverter; _multipatchConverter = multipatchConverter; _attributeConverter = attributeConverter; + _contextStack = contextStack; } private List GetPolygonDisplayMeshes(List polygons) @@ -60,7 +63,7 @@ ITypedConverter attributeConverter { vertices = boundaryPts.SelectMany(x => new List { x.x, x.y, x.z }).ToList(), faces = faces, - units = Units.Meters, //TODO: This can't be right + units = _contextStack.Current.Document.ActiveCRSoffsetRotation.SpeckleUnitString }; displayVal.Add(mesh); } @@ -78,7 +81,7 @@ ITypedConverter attributeConverter { vertices = geo.vertices, faces = geo.faces, - units = Units.Meters //TODO: This can't be right + units = _contextStack.Current.Document.ActiveCRSoffsetRotation.SpeckleUnitString }; displayVal.Add(displayMesh); } diff --git a/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToSpeckle/Raw/MultipatchFeatureToSpeckleConverter.cs b/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToSpeckle/Raw/MultipatchFeatureToSpeckleConverter.cs index c36ad6c6e..e814f2c75 100644 --- a/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToSpeckle/Raw/MultipatchFeatureToSpeckleConverter.cs +++ b/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToSpeckle/Raw/MultipatchFeatureToSpeckleConverter.cs @@ -26,7 +26,8 @@ public IReadOnlyList Convert(ACG.Multipatch target) { List converted = new(); // placeholder, needs to be declared in order to be used in the Ring patch type - SGIS.PolygonGeometry3d polygonGeom = new() { }; + SGIS.PolygonGeometry3d polygonGeom = + new() { units = _contextStack.Current.Document.ActiveCRSoffsetRotation.SpeckleUnitString }; // convert and store all multipatch points per Part List> allPoints = new(); @@ -52,19 +53,19 @@ public IReadOnlyList Convert(ACG.Multipatch target) if (patchType == ACG.PatchType.TriangleStrip) { SGIS.GisMultipatchGeometry multipatch = target.CompleteMultipatchTriangleStrip(allPoints, idx); - multipatch.units = _contextStack.Current.SpeckleUnits; + multipatch.units = _contextStack.Current.Document.ActiveCRSoffsetRotation.SpeckleUnitString; converted.Add(multipatch); } else if (patchType == ACG.PatchType.Triangles) { SGIS.GisMultipatchGeometry multipatch = target.CompleteMultipatchTriangles(allPoints, idx); - multipatch.units = _contextStack.Current.SpeckleUnits; + multipatch.units = _contextStack.Current.Document.ActiveCRSoffsetRotation.SpeckleUnitString; converted.Add(multipatch); } else if (patchType == ACG.PatchType.TriangleFan) { SGIS.GisMultipatchGeometry multipatch = target.CompleteMultipatchTriangleFan(allPoints, idx); - multipatch.units = _contextStack.Current.SpeckleUnits; + multipatch.units = _contextStack.Current.Document.ActiveCRSoffsetRotation.SpeckleUnitString; converted.Add(multipatch); } // in case of RingMultipatch - return PolygonGeometry3d @@ -78,10 +79,19 @@ public IReadOnlyList Convert(ACG.Multipatch target) } // first ring means a start of a new PolygonGeometry3d - polygonGeom = new() { voids = new List() }; + polygonGeom = new() + { + voids = new List(), + units = _contextStack.Current.Document.ActiveCRSoffsetRotation.SpeckleUnitString + }; List pointCoords = allPoints[idx].SelectMany(x => new List() { x.x, x.y, x.z }).ToList(); - SOG.Polyline polyline = new() { value = pointCoords, units = _contextStack.Current.SpeckleUnits }; + SOG.Polyline polyline = + new() + { + value = pointCoords, + units = _contextStack.Current.Document.ActiveCRSoffsetRotation.SpeckleUnitString + }; polygonGeom.boundary = polyline; // if it's already the last part, add to list @@ -93,7 +103,12 @@ public IReadOnlyList Convert(ACG.Multipatch target) else if (patchType == ACG.PatchType.Ring) { List pointCoords = allPoints[idx].SelectMany(x => new List() { x.x, x.y, x.z }).ToList(); - SOG.Polyline polyline = new() { value = pointCoords, units = _contextStack.Current.SpeckleUnits }; + SOG.Polyline polyline = + new() + { + value = pointCoords, + units = _contextStack.Current.Document.ActiveCRSoffsetRotation.SpeckleUnitString + }; // every outer ring is oriented clockwise bool isClockwise = polyline.IsClockwisePolygon(); @@ -106,7 +121,12 @@ public IReadOnlyList Convert(ACG.Multipatch target) { // add existing polygon to list, start a new polygon with a boundary converted.Add(polygonGeom); - polygonGeom = new() { voids = new List(), boundary = polyline }; + polygonGeom = new() + { + voids = new List(), + boundary = polyline, + units = _contextStack.Current.Document.ActiveCRSoffsetRotation.SpeckleUnitString + }; } // if it's already the last part, add to list if (idx == target.PartCount - 1) diff --git a/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToSpeckle/Raw/PolygonFeatureToSpeckleConverter.cs b/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToSpeckle/Raw/PolygonFeatureToSpeckleConverter.cs index 75c1958e5..51b810c2a 100644 --- a/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToSpeckle/Raw/PolygonFeatureToSpeckleConverter.cs +++ b/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToSpeckle/Raw/PolygonFeatureToSpeckleConverter.cs @@ -7,10 +7,15 @@ namespace Speckle.Converters.ArcGIS3.ToSpeckle.Raw; public class PolygonFeatureToSpeckleConverter : ITypedConverter> { private readonly ITypedConverter _segmentConverter; + private readonly IConversionContextStack _contextStack; - public PolygonFeatureToSpeckleConverter(ITypedConverter segmentConverter) + public PolygonFeatureToSpeckleConverter( + ITypedConverter segmentConverter, + IConversionContextStack contextStack + ) { _segmentConverter = segmentConverter; + _contextStack = contextStack; } public IReadOnlyList Convert(ACG.Polygon target) @@ -35,7 +40,12 @@ public IReadOnlyList Convert(ACG.Polygon target) bool isExteriorRing = target.IsExteriorRing(idx); if (isExteriorRing) { - polygon = new() { boundary = polyline, voids = new List() }; + polygon = new() + { + boundary = polyline, + voids = new List(), + units = _contextStack.Current.Document.ActiveCRSoffsetRotation.SpeckleUnitString + }; polygonList.Add(polygon); } else // interior part