Skip to content

Commit

Permalink
Merge pull request #178 from ADAPT/develop
Browse files Browse the repository at this point in the history
Merge to master for release
  • Loading branch information
Stuart Rhea authored Jun 8, 2022
2 parents 5c5730c + 4d7c89d commit 3f12539
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 61 deletions.
2 changes: 1 addition & 1 deletion ISOv4Plugin/ISOv4Plugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AgGatewayADAPTFramework" Version="2.8.2" />
<PackageReference Include="AgGatewayADAPTFramework" Version="2.8.3" />
</ItemGroup>

<ItemGroup>
Expand Down
76 changes: 21 additions & 55 deletions ISOv4Plugin/Mappers/GuidancePatternMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
* ISO standards can be purchased through the ANSI webstore at https://webstore.ansi.org
*/

using AgGateway.ADAPT.ISOv4Plugin.ExtensionMethods;
using AgGateway.ADAPT.ISOv4Plugin.ISOModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AgGateway.ADAPT.ApplicationDataModel.Guidance;
using AgGateway.ADAPT.ApplicationDataModel.Logistics;
using AgGateway.ADAPT.ApplicationDataModel.Representations;
using AgGateway.ADAPT.ApplicationDataModel.Shapes;
using AgGateway.ADAPT.ISOv4Plugin.ExtensionMethods;
using AgGateway.ADAPT.ISOv4Plugin.ISOEnumerations;
using AgGateway.ADAPT.ApplicationDataModel.Guidance;
using AgGateway.ADAPT.ApplicationDataModel.Representations;
using AgGateway.ADAPT.ISOv4Plugin.ISOModels;
using AgGateway.ADAPT.Representation.UnitSystem;

namespace AgGateway.ADAPT.ISOv4Plugin.Mappers
Expand Down Expand Up @@ -59,64 +57,32 @@ public ISOGuidancePattern ExportGuidancePattern(GuidancePattern adaptGuidancePat
gpn.PropagationDirection = ExportPropagationDirection(adaptGuidancePattern.PropagationDirection);
gpn.Extension = ExportExtension(adaptGuidancePattern.Extension);
gpn.Heading = ExportHeading(adaptGuidancePattern);
gpn.GNSSMethod = ExportGNSSMethod(adaptGuidancePattern.GpsSource.SourceType);
if (adaptGuidancePattern.GpsSource.HorizontalAccuracy != null)
if (adaptGuidancePattern.GpsSource != null)
{
gpn.HorizontalAccuracy = (decimal)adaptGuidancePattern.GpsSource.HorizontalAccuracy.AsConvertedDouble("m").Value;
}
if (adaptGuidancePattern.GpsSource.VerticalAccuracy != null)
{
gpn.VerticalAccuracy = (decimal)adaptGuidancePattern.GpsSource.VerticalAccuracy.AsConvertedDouble("m").Value;
gpn.GNSSMethod = ExportGNSSMethod(adaptGuidancePattern.GpsSource.SourceType);
if (adaptGuidancePattern.GpsSource.HorizontalAccuracy != null)
{
gpn.HorizontalAccuracy = (decimal)adaptGuidancePattern.GpsSource.HorizontalAccuracy.AsConvertedDouble("m").Value;
}
if (adaptGuidancePattern.GpsSource.VerticalAccuracy != null)
{
gpn.VerticalAccuracy = (decimal)adaptGuidancePattern.GpsSource.VerticalAccuracy.AsConvertedDouble("m").Value;
}
}
gpn.OriginalSRID = adaptGuidancePattern.OriginalEpsgCode;
gpn.NumberOfSwathsLeft = (uint?)adaptGuidancePattern.NumbersOfSwathsLeft;
gpn.NumberOfSwathsRight = (uint?)adaptGuidancePattern.NumbersOfSwathsRight;

//Pattern
LineStringMapper lineStringMapper = new LineStringMapper(TaskDataMapper);
switch (adaptGuidancePattern.GuidancePatternType)
{
case GuidancePatternTypeEnum.AbCurve:
AbCurve curve = adaptGuidancePattern as AbCurve;
gpn.LineString = lineStringMapper.ExportLineString(curve.Shape[0], ISOLineStringType.GuidancePattern); //Only first linestring used.
break;
gpn.LineString = lineStringMapper.ExportGuidancePattern(adaptGuidancePattern);

case GuidancePatternTypeEnum.AbLine:
AbLine abLine = adaptGuidancePattern as AbLine;
LineString line = new LineString { Points = new List<Point>() };
line.Points.Add(abLine.A);
line.Points.Add(abLine.B);
gpn.LineString = lineStringMapper.ExportLineString(line, ISOLineStringType.GuidancePattern);
break;
case GuidancePatternTypeEnum.APlus:
APlus aPlus = adaptGuidancePattern as APlus;
LineString aPlusLine = new LineString { Points = new List<Point>() };
aPlusLine.Points.Add(aPlus.Point);
gpn.LineString = lineStringMapper.ExportLineString(aPlusLine, ISOLineStringType.GuidancePattern);
break;
case GuidancePatternTypeEnum.CenterPivot:
PivotGuidancePattern pivot = adaptGuidancePattern as PivotGuidancePattern;
LineString pivotLine = new LineString { Points = new List<Point>() };
pivotLine.Points.Add(pivot.Center);
if (pivot.DefinitionMethod == PivotGuidanceDefinitionEnum.PivotGuidancePatternStartEndCenter &&
pivot.StartPoint != null &&
pivot.EndPoint != null)
{
pivotLine.Points.Add(pivot.StartPoint);
pivotLine.Points.Add(pivot.EndPoint);
}
else if (pivot.DefinitionMethod == PivotGuidanceDefinitionEnum.PivotGuidancePatternCenterRadius &&
pivot.Radius != null)
{
gpn.Radius = (uint)pivot.Radius.AsConvertedInt("mm").Value;
gpn.GuidancePatternOptions = ISOGuidancePatternOption.FullCircle;
}
gpn.LineString = lineStringMapper.ExportLineString(pivotLine, ISOLineStringType.GuidancePattern);
break;
case GuidancePatternTypeEnum.Spiral:
Spiral spiral = adaptGuidancePattern as Spiral;
gpn.LineString = lineStringMapper.ExportLineString(spiral.Shape, ISOLineStringType.GuidancePattern);
break;
if (adaptGuidancePattern is PivotGuidancePattern pivot &&
pivot.DefinitionMethod == PivotGuidanceDefinitionEnum.PivotGuidancePatternCenterRadius &&
pivot.Radius != null)
{
gpn.Radius = (uint)pivot.Radius.AsConvertedInt("mm").Value;
gpn.GuidancePatternOptions = ISOGuidancePatternOption.FullCircle;
}

//Boundary
Expand Down
69 changes: 64 additions & 5 deletions ISOv4Plugin/Mappers/LineStringMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
* ISO standards can be purchased through the ANSI webstore at https://webstore.ansi.org
*/

using AgGateway.ADAPT.ISOv4Plugin.ExtensionMethods;
using AgGateway.ADAPT.ISOv4Plugin.ISOModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AgGateway.ADAPT.ApplicationDataModel.Logistics;
using AgGateway.ADAPT.ApplicationDataModel.Guidance;
using AgGateway.ADAPT.ApplicationDataModel.Shapes;
using AgGateway.ADAPT.ISOv4Plugin.ISOEnumerations;
using AgGateway.ADAPT.ISOv4Plugin.ISOModels;

namespace AgGateway.ADAPT.ISOv4Plugin.Mappers
{
Expand All @@ -22,6 +19,7 @@ public interface ILineStringMapper
IEnumerable<AttributeShape> ImportAttributeLineStrings(IEnumerable<ISOLineString> isoLineStrings);
IEnumerable<ISOLineString> ExportLinearRings(IEnumerable<LinearRing> adaptLinearRings, ISOLineStringType lsgType);
IEnumerable<LinearRing> ImportLinearRings(IEnumerable<ISOLineString> isoLineStrings);
ISOLineString ExportGuidancePattern(GuidancePattern adaptGuidancePattern);
}

public class LineStringMapper : BaseMapper, ILineStringMapper
Expand Down Expand Up @@ -71,6 +69,67 @@ public ISOLineString ExportLineString(LineString adaptLineString, ISOLineStringT
return lineString;
}

public ISOLineString ExportGuidancePattern(GuidancePattern adaptGuidancePattern)
{
ISOLineString lineString = new ISOLineString(TaskDataMapper.Version);
lineString.LineStringType = ISOLineStringType.GuidancePattern;

PointMapper pointMapper = new PointMapper(TaskDataMapper);

List<Point> adaptPoints;
switch (adaptGuidancePattern.GuidancePatternType)
{
case GuidancePatternTypeEnum.AbCurve:
AbCurve curve = adaptGuidancePattern as AbCurve;
adaptPoints = curve.Shape[0].Points; //Only first linestring used.
break;

case GuidancePatternTypeEnum.AbLine:
AbLine abLine = adaptGuidancePattern as AbLine;
adaptPoints = new List<Point>();
adaptPoints.Add(abLine.A);
adaptPoints.Add(abLine.B);
break;
case GuidancePatternTypeEnum.APlus:
APlus aPlus = adaptGuidancePattern as APlus;
adaptPoints = new List<Point>();
adaptPoints.Add(aPlus.Point);
break;
case GuidancePatternTypeEnum.CenterPivot:
PivotGuidancePattern pivot = adaptGuidancePattern as PivotGuidancePattern;
adaptPoints = new List<Point>();
lineString.Points.Add(pointMapper.ExportPoint(pivot.Center, ISOPointType.GuidanceReferenceCenter));

if (pivot.DefinitionMethod == PivotGuidanceDefinitionEnum.PivotGuidancePatternStartEndCenter &&
pivot.StartPoint != null &&
pivot.EndPoint != null)
{
adaptPoints.Add(pivot.StartPoint);
adaptPoints.Add(pivot.EndPoint);
}
break;
case GuidancePatternTypeEnum.Spiral:
Spiral spiral = adaptGuidancePattern as Spiral;
adaptPoints = spiral.Shape.Points;
break;
default:
return null;
}

for (int i = 0; i < adaptPoints.Count; i++)
{
ISOPointType pointType = i == 0
? ISOPointType.GuidanceReferenceA
: (i == adaptPoints.Count - 1
? ISOPointType.GuidanceReferenceB
: ISOPointType.GuidancePoint);

lineString.Points.Add(pointMapper.ExportPoint(adaptPoints[i], pointType));
}

return lineString;
}

public IEnumerable<ISOLineString> ExportLinearRings(IEnumerable<LinearRing> adaptRings, ISOLineStringType lsgType)
{
List<ISOLineString> lineStrings = new List<ISOLineString>();
Expand Down
1 change: 1 addition & 0 deletions ISOv4Plugin/Mappers/ProductMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ private List<ProductComponent> ImportProductComponents(ISOProduct isoProduct)
if (adaptProduct == null)
{
adaptProduct = ImportProduct(isoComponent);
DataModel.Catalog.Products.Add(adaptProduct);
}

//Create a component for this ingredient
Expand Down

0 comments on commit 3f12539

Please sign in to comment.