Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agis receive hatches #102

Draft
wants to merge 4 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Speckle.Converters.ArcGIS3.Utils;
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;

Expand All @@ -21,13 +22,37 @@ public ACG.Polygon Convert(List<SGIS.PolygonGeometry> target)
List<ACG.Polygon> polyList = new();
foreach (SGIS.PolygonGeometry poly in target)
{
ACG.Polyline boundary = _polylineConverter.Convert(poly.boundary);
ACG.PolygonBuilderEx polyOuterRing = new(boundary);
ACG.Polyline? boundary = _polylineConverter.Convert(poly.boundary);

// enforce clockwise outer ring orientation: https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic72904.html
if (!boundary.IsClockwisePolygon())
{
boundary = ACG.GeometryEngine.Instance.ReverseOrientation(boundary) as ACG.Polyline;
}

if (boundary is null)
{
throw new SpeckleConversionException("Hatch conversion of boundary curve failed");
}

ACG.PolygonBuilderEx polyOuterRing = new(boundary.Parts.SelectMany(x => x), ACG.AttributeFlags.HasZ);

// adding inner loops: https://github.com/esri/arcgis-pro-sdk/wiki/ProSnippets-Geometry#build-a-donut-polygon
foreach (SOG.Polyline loop in poly.voids)
{
// adding inner loops: https://github.com/esri/arcgis-pro-sdk/wiki/ProSnippets-Geometry#build-a-donut-polygon
ACG.Polyline loopNative = _polylineConverter.Convert(loop);
ACG.Polyline? loopNative = _polylineConverter.Convert(loop);

// enforce clockwise outer ring orientation
if (loopNative.IsClockwisePolygon())
{
loopNative = ACG.GeometryEngine.Instance.ReverseOrientation(loopNative) as ACG.Polyline;
}

if (loopNative is null)
{
throw new SpeckleConversionException("Hatch conversion of inner loop failed");
}

polyOuterRing.AddPart(loopNative.Copy3DCoordinatesToList());
}
ACG.Polygon polygon = polyOuterRing.ToGeometry();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using Speckle.Converters.ArcGIS3.Utils;
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Objects.Other;
using Speckle.Sdk.Models;

namespace Speckle.Converters.ArcGIS3.ToHost.TopLevel;

[NameAndRankValue(nameof(Hatch), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)]
public class HatchToHostConverter : IToHostTopLevelConverter, ITypedConverter<Hatch, ACG.Polygon>
{
private readonly IRootToHostConverter _converter;

public HatchToHostConverter(IRootToHostConverter converter)
{
_converter = converter;
}

public object Convert(Base target) => Convert((Hatch)target);

public ACG.Polygon Convert(Hatch target)
{
HatchLoop? boundarySpeckle = target.loops.FirstOrDefault(x => x.Type == HatchLoopType.Outer);
if (boundarySpeckle is null && target.loops.Count == 1)
{
boundarySpeckle = target.loops[0];
}

if (boundarySpeckle is null)
{
throw new SpeckleConversionException("Invalid Hatch provided");
}

List<HatchLoop> voidsSpeckle = target.loops.Where(x => x.Type == HatchLoopType.Inner).ToList();

ACG.Polyline? boundary = (ACG.Polyline)_converter.Convert((Base)boundarySpeckle.Curve);

// enforce clockwise outer ring orientation: https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic72904.html
if (!boundary.IsClockwisePolygon())
{
boundary = ACG.GeometryEngine.Instance.ReverseOrientation(boundary) as ACG.Polyline;
}

if (boundary is null)
{
throw new SpeckleConversionException("Hatch conversion of boundary curve failed");
}

ACG.PolygonBuilderEx polyOuterRing = new(boundary.Parts.SelectMany(x => x), ACG.AttributeFlags.HasZ);

// adding inner loops: https://github.com/esri/arcgis-pro-sdk/wiki/ProSnippets-Geometry#build-a-donut-polygon
foreach (HatchLoop loop in voidsSpeckle)
{
ACG.Polyline? loopNative = (ACG.Polyline)_converter.Convert((Base)loop.Curve);

// enforce clockwise outer ring orientation
if (loopNative.IsClockwisePolygon())
{
loopNative = ACG.GeometryEngine.Instance.ReverseOrientation(loopNative) as ACG.Polyline;
}

if (loopNative is null)
{
throw new SpeckleConversionException("Hatch conversion of inner loop failed");
}

polyOuterRing.AddPart(loopNative.Parts.SelectMany(x => x.ToList()));
}

var resultPolygon = polyOuterRing.ToGeometry();
return resultPolygon;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,30 @@ public static bool IsClockwisePolygon(this SOG.Polyline polyline)
return isClockwise;
}

public static bool IsClockwisePolygon(this ACG.Polyline polyline)
{
bool isClockwise;
double sum = 0;

List<ACG.MapPoint> points = polyline.Points.ToList();

if (points.Count < 3)
{
throw new ArgumentException("Not enough points for polygon orientation check");
}
if (points[0] != points[^1])
{
points.Add(points[0]);
}

for (int i = 0; i < points.Count - 1; i++)
{
sum += (points[i + 1].X - points[i].X) * (points[i + 1].Y + points[i].Y);
}
isClockwise = sum > 0;
return isClockwise;
}

public static SGIS.GisMultipatchGeometry CompleteMultipatchTriangleStrip(
this ACG.Multipatch target,
List<List<SOG.Point>> allPoints,
Expand Down
Loading