diff --git a/DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToHost/Raw/CurveToHostConverter.cs b/DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToHost/Raw/CurveToHostConverter.cs new file mode 100644 index 0000000000..57bd7b3c83 --- /dev/null +++ b/DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToHost/Raw/CurveToHostConverter.cs @@ -0,0 +1,52 @@ +using Objects; +using Speckle.Converters.Common.Objects; + +namespace Speckle.Converters.ArcGIS3.ToHost.Raw; + +public class CurveToHostConverter : ITypedConverter +{ + private readonly ITypedConverter _lineConverter; + private readonly ITypedConverter _arcConverter; + private readonly ITypedConverter _ellipseConverter; + private readonly ITypedConverter _circleConverter; + private readonly ITypedConverter _polylineConverter; + private readonly ITypedConverter _polyCurveConverter; + + public CurveToHostConverter( + ITypedConverter lineConverter, + ITypedConverter arcConverter, + ITypedConverter ellipseConverter, + ITypedConverter circleConverter, + ITypedConverter polylineConverter, + ITypedConverter polyCurveConverter + ) + { + _lineConverter = lineConverter; + _arcConverter = arcConverter; + _ellipseConverter = ellipseConverter; + _circleConverter = circleConverter; + _polylineConverter = polylineConverter; + _polyCurveConverter = polyCurveConverter; + } + + /// + /// Converts a given ICurve object to an ACG.Polyline object. + /// + /// The ICurve object to convert. + /// The converted RG.Curve object. + /// Thrown when the conversion is not supported for the given type of curve. + /// ⚠️ This conversion does NOT perform scaling. + public ACG.Polyline Convert(ICurve target) => + target switch + { + SOG.Line line => _lineConverter.Convert(line), + SOG.Arc arc => _arcConverter.Convert(arc), + SOG.Circle circle => _circleConverter.Convert(circle), + SOG.Ellipse ellipse => _ellipseConverter.Convert(ellipse), + SOG.Spiral spiral => _polylineConverter.Convert(spiral.displayValue), + SOG.Polyline polyline => _polylineConverter.Convert(polyline), + SOG.Curve curve => _polylineConverter.Convert(curve.displayValue), + SOG.Polycurve polyCurve => _polyCurveConverter.Convert(polyCurve), + _ => throw new NotSupportedException($"Unable to convert curves of type {target.GetType().Name}") + }; +} diff --git a/DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToHost/TopLevel/PolycurveToHostConverter.cs b/DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToHost/TopLevel/PolycurveToHostConverter.cs index 3b97f43886..f6912aee8f 100644 --- a/DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToHost/TopLevel/PolycurveToHostConverter.cs +++ b/DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToHost/TopLevel/PolycurveToHostConverter.cs @@ -26,27 +26,20 @@ public PolycurveToHostConverter( public ACG.Polyline Convert(SOG.Polycurve target) { - List pointsToCheckOrientation = new(); + ACG.MapPoint? lastConvertedPt = null; List segments = new(); foreach (var segment in target.segments) { - ACG.Polyline converted = (ACG.Polyline)_converter.Convert((Base)segment); + ACG.Polyline converted = (ACG.Polyline)_converter.Convert((Base)segment); //CurveConverter.NotNull().Convert(segment); List segmentPts = converted.Points.ToList(); - // reverse new segment if needed - if ( - pointsToCheckOrientation.Count > 0 - && segmentPts.Count > 0 - && pointsToCheckOrientation[^1] != segmentPts[0] - && pointsToCheckOrientation[^1] == segmentPts[^1] - ) + if (lastConvertedPt != null && segmentPts.Count > 0 && lastConvertedPt != segmentPts[0]) { - segmentPts.Reverse(); - ACG.Geometry reversedLine = ACG.GeometryEngine.Instance.ReverseOrientation(converted); - converted = (ACG.Polyline)reversedLine; + throw new SpeckleConversionException("Polycurve segments are not in a correct sequence/orientation"); } - pointsToCheckOrientation.AddRange(segmentPts); + + lastConvertedPt = segmentPts[^1]; segments.Add(converted); }