Skip to content

Commit

Permalink
added ICUrve converter (not used yet); added check for sequential Pol…
Browse files Browse the repository at this point in the history
…ycurve
  • Loading branch information
KatKatKateryna committed Jul 1, 2024
1 parent fc8ca65 commit 7666608
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Objects;
using Speckle.Converters.Common.Objects;

namespace Speckle.Converters.ArcGIS3.ToHost.Raw;

public class CurveToHostConverter : ITypedConverter<ICurve, ACG.Polyline>
{
private readonly ITypedConverter<SOG.Line, ACG.Polyline> _lineConverter;
private readonly ITypedConverter<SOG.Arc, ACG.Polyline> _arcConverter;
private readonly ITypedConverter<SOG.Ellipse, ACG.Polyline> _ellipseConverter;
private readonly ITypedConverter<SOG.Circle, ACG.Polyline> _circleConverter;
private readonly ITypedConverter<SOG.Polyline, ACG.Polyline> _polylineConverter;
private readonly ITypedConverter<SOG.Polycurve, ACG.Polyline> _polyCurveConverter;

public CurveToHostConverter(
ITypedConverter<SOG.Line, ACG.Polyline> lineConverter,
ITypedConverter<SOG.Arc, ACG.Polyline> arcConverter,
ITypedConverter<SOG.Ellipse, ACG.Polyline> ellipseConverter,
ITypedConverter<SOG.Circle, ACG.Polyline> circleConverter,
ITypedConverter<SOG.Polyline, ACG.Polyline> polylineConverter,
ITypedConverter<SOG.Polycurve, ACG.Polyline> polyCurveConverter
)
{
_lineConverter = lineConverter;
_arcConverter = arcConverter;
_ellipseConverter = ellipseConverter;
_circleConverter = circleConverter;
_polylineConverter = polylineConverter;
_polyCurveConverter = polyCurveConverter;
}

/// <summary>
/// Converts a given ICurve object to an ACG.Polyline object.
/// </summary>
/// <param name="target">The ICurve object to convert.</param>
/// <returns>The converted RG.Curve object.</returns>
/// <exception cref="NotSupportedException">Thrown when the conversion is not supported for the given type of curve.</exception>
/// <remarks>⚠️ This conversion does NOT perform scaling.</remarks>
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}")
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,20 @@ public PolycurveToHostConverter(

public ACG.Polyline Convert(SOG.Polycurve target)
{
List<ACG.MapPoint> pointsToCheckOrientation = new();
ACG.MapPoint? lastConvertedPt = null;
List<ACG.Polyline> 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<ACG.MapPoint> 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);
}

Expand Down

0 comments on commit 7666608

Please sign in to comment.