diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/ArcToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/ArcToHostConverter.cs index 0068c38ef2..73840337de 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/ArcToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/ArcToHostConverter.cs @@ -1,34 +1,36 @@ using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; /// /// Converts a SpeckleArcRaw object to a Rhino.Geometry.Arc object or Rhino.Geometry.ArcCurve object. /// -public class ArcToHostConverter : ITypedConverter, ITypedConverter +public class ArcToHostConverter : ITypedConverter, ITypedConverter { - private readonly ITypedConverter _pointConverter; - private readonly ITypedConverter _intervalConverter; + private readonly ITypedConverter _pointConverter; + private readonly ITypedConverter _intervalConverter; + private readonly IRhinoArcFactory _rhinoArcFactory; public ArcToHostConverter( - ITypedConverter pointConverter, - ITypedConverter intervalConverter - ) + ITypedConverter pointConverter, + ITypedConverter intervalConverter, IRhinoArcFactory rhinoArcFactory) { _pointConverter = pointConverter; this._intervalConverter = intervalConverter; + _rhinoArcFactory = rhinoArcFactory; } /// - /// Converts a object to a object. + /// Converts a object to a object. /// /// The Speckle Arc object to convert. - /// The converted object. + /// The converted object. /// ⚠️ This conversion does NOT perform scaling. ///
⚠️ This method does not preserve the original curve domain
- public RG.Arc Convert(SOG.Arc target) + public IRhinoArc Convert(SOG.Arc target) { - var rhinoArc = new RG.Arc( + var rhinoArc = _rhinoArcFactory.Create( _pointConverter.Convert(target.startPoint), _pointConverter.Convert(target.midPoint), _pointConverter.Convert(target.endPoint) @@ -39,16 +41,16 @@ public RG.Arc Convert(SOG.Arc target) // POC: CNX-9271 Potential code-smell by directly implementing the interface. We should discuss this further but // since we're using the interfaces instead of the direct type, this may not be an issue. /// - /// Converts a object to a object. + /// Converts a object to a object. /// /// The object to convert. - /// The converted object. + /// The converted object. /// ⚠️ This conversion does NOT perform scaling. - ///
⚠️ Converting to instead of preserves the domain of the curve.
- RG.ArcCurve ITypedConverter.Convert(SOG.Arc target) + ///
⚠️ Converting to instead of preserves the domain of the curve.
+ IRhinoArcCurve ITypedConverter.Convert(SOG.Arc target) { var rhinoArc = Convert(target); - var arcCurve = new RG.ArcCurve(rhinoArc) { Domain = _intervalConverter.Convert(target.domain) }; + var arcCurve = _rhinoArcFactory.Create(rhinoArc, _intervalConverter.Convert(target.domain)); return arcCurve; } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/CircleToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/CircleToHostConverter.cs index 1431d3fc1a..a55bb72f6b 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/CircleToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/CircleToHostConverter.cs @@ -1,46 +1,48 @@ using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; /// -/// This class is responsible for converting a into and objects. +/// This class is responsible for converting a into and objects. /// Implements the interface, -/// providing implementation for to and conversion. +/// providing implementation for to and conversion. /// -public class CircleToHostConverter : ITypedConverter, ITypedConverter +public class CircleToHostConverter : ITypedConverter, ITypedConverter { - private readonly ITypedConverter _planeConverter; - private readonly ITypedConverter _intervalConverter; + private readonly ITypedConverter _planeConverter; + private readonly ITypedConverter _intervalConverter; + private readonly IRhinoCircleFactory _rhinoCircleFactory; /// /// Constructs a new instance of the class. /// /// - /// An implementation of used to convert into . + /// An implementation of used to convert into . /// /// - /// An implementation of used to convert into . + /// An implementation of used to convert into . /// public CircleToHostConverter( - ITypedConverter intervalConverter, - ITypedConverter planeConverter - ) + ITypedConverter intervalConverter, + ITypedConverter planeConverter, IRhinoCircleFactory rhinoCircleFactory) { _intervalConverter = intervalConverter; _planeConverter = planeConverter; + _rhinoCircleFactory = rhinoCircleFactory; } /// - /// Converts the given object into a object. + /// Converts the given object into a object. /// /// The object to convert. - /// The resulting object. + /// The resulting object. /// /// Thrown when the radius of the given object is null. /// /// ⚠️ This conversion does NOT perform scaling. - ///
⚠️ This conversion does not preserve the curve domain. If you need it preserved you must request a conversion to conversion instead
- public RG.Circle Convert(SOG.Circle target) + ///
⚠️ This conversion does not preserve the curve domain. If you need it preserved you must request a conversion to conversion instead
+ public IRhinoCircle Convert(SOG.Circle target) { if (target.radius == null) { @@ -50,9 +52,9 @@ public RG.Circle Convert(SOG.Circle target) var plane = _planeConverter.Convert(target.plane); var radius = target.radius.Value; - return new RG.Circle(plane, radius); + return _rhinoCircleFactory.Create(plane, radius); } - RG.ArcCurve ITypedConverter.Convert(SOG.Circle target) => - new(Convert(target)) { Domain = _intervalConverter.Convert(target.domain) }; + IRhinoArcCurve ITypedConverter.Convert(SOG.Circle target) => + _rhinoCircleFactory.Create(Convert(target), _intervalConverter.Convert(target.domain)); } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/EllipseToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/EllipseToHostConverter.cs index 74f309a61f..a74da6774f 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/EllipseToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/EllipseToHostConverter.cs @@ -1,49 +1,51 @@ using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; public class EllipseToHostConverter - : ITypedConverter, - ITypedConverter + : ITypedConverter, + ITypedConverter { - private readonly ITypedConverter _planeConverter; - private readonly ITypedConverter _intervalConverter; + private readonly ITypedConverter _planeConverter; + private readonly ITypedConverter _intervalConverter; + private readonly IRhinoEllipseFactory _rhinoEllipseFactory; public EllipseToHostConverter( - ITypedConverter planeConverter, - ITypedConverter intervalConverter - ) + ITypedConverter planeConverter, + ITypedConverter intervalConverter, IRhinoEllipseFactory rhinoEllipseFactory) { _planeConverter = planeConverter; _intervalConverter = intervalConverter; + _rhinoEllipseFactory = rhinoEllipseFactory; } /// - /// Converts an instance of to an while preserving geometric properties. + /// Converts an instance of to an while preserving geometric properties. /// /// The instance to be converted. - /// The resulting after conversion. + /// The resulting after conversion. /// Thrown when or properties are null. /// ⚠️ This conversion does NOT perform scaling. - ///
⚠️ This conversion does not preserve the curve domain. If you need it preserved you must request a conversion to conversion instead
- public RG.Ellipse Convert(SOG.Ellipse target) + ///
⚠️ This conversion does not preserve the curve domain. If you need it preserved you must request a conversion to conversion instead
+ public IRhinoEllipse Convert(SOG.Ellipse target) { if (!target.firstRadius.HasValue || !target.secondRadius.HasValue) { throw new InvalidOperationException($"Ellipses cannot have null radii"); } - return new RG.Ellipse(_planeConverter.Convert(target.plane), target.firstRadius.Value, target.secondRadius.Value); + return _rhinoEllipseFactory.Create(_planeConverter.Convert(target.plane), target.firstRadius.Value, target.secondRadius.Value); } /// - /// Converts the provided into a representation. + /// Converts the provided into a representation. /// /// The to convert. /// - /// A that represents the provided . + /// A that represents the provided . /// - RG.NurbsCurve ITypedConverter.Convert(SOG.Ellipse target) + IRhinoNurbsCurve ITypedConverter.Convert(SOG.Ellipse target) { var rhinoEllipse = Convert(target); var rhinoNurbsEllipse = rhinoEllipse.ToNurbsCurve(); diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/FlatPointListToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/FlatPointListToHostConverter.cs index f0363a387d..97c2786b44 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/FlatPointListToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/FlatPointListToHostConverter.cs @@ -1,14 +1,21 @@ -using Rhino.Collections; -using Speckle.Converters.Common.Objects; +using Speckle.Converters.Common.Objects; using Speckle.Core.Logging; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; /// /// Converts a flat list of raw double values to a Point3dList. /// -public class FlatPointListToHostConverter : ITypedConverter, Point3dList> +public class FlatPointListToHostConverter : ITypedConverter, IRhinoPoint3dList> { + private readonly IRhinoPointFactory _rhinoPointFactory; + + public FlatPointListToHostConverter(IRhinoPointFactory rhinoPointFactory) + { + _rhinoPointFactory = rhinoPointFactory; + } + /// /// Converts a flat list of raw double values to a Point3dList. /// @@ -19,20 +26,20 @@ public class FlatPointListToHostConverter : ITypedConverter /// Throws when the input list count is not a multiple of 3. - public Point3dList Convert(IReadOnlyList target) + public IRhinoPoint3dList Convert(IReadOnlyList target) { if (target.Count % 3 != 0) { throw new SpeckleException("Array malformed: length%3 != 0."); } - var points = new List(target.Count / 3); + var points = new List(target.Count / 3); for (int i = 2; i < target.Count; i += 3) { - points.Add(new RG.Point3d(target[i - 2], target[i - 1], target[i])); + points.Add(_rhinoPointFactory.Create(target[i - 2], target[i - 1], target[i])); } - return new Point3dList(points); + return _rhinoPointFactory.Create(points); } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/IntervalToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/IntervalToHostConverter.cs index f201283ebd..ddaa476970 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/IntervalToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/IntervalToHostConverter.cs @@ -1,9 +1,17 @@ using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class IntervalToHostConverter : ITypedConverter +public class IntervalToHostConverter : ITypedConverter { + private readonly IRhinoIntervalFactory _rhinoIntervalFactory; + + public IntervalToHostConverter(IRhinoIntervalFactory rhinoIntervalFactory) + { + _rhinoIntervalFactory = rhinoIntervalFactory; + } + /// /// Converts a Speckle Interval object to a Rhino.Geometry.Interval object. /// @@ -11,13 +19,13 @@ public class IntervalToHostConverter : ITypedConverterThe converted Rhino.Geometry.Interval object. /// Thrown when the start or end value of the Interval is null. /// ⚠️ This conversion does NOT perform scaling. - public RG.Interval Convert(SOP.Interval target) + public IRhinoInterval Convert(SOP.Interval target) { if (!target.start.HasValue || !target.end.HasValue) // POC: CNX-9272 Interval start and end being nullable makes no sense. { throw new ArgumentException("Interval start/end cannot be null"); } - return new RG.Interval(target.start.Value, target.end.Value); + return _rhinoIntervalFactory.Create(target.start.Value, target.end.Value); } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/LineToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/LineToHostConverter.cs index c549e96741..cfb2fcc66c 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/LineToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/LineToHostConverter.cs @@ -1,14 +1,17 @@ using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class LineToHostConverter : ITypedConverter, ITypedConverter +public class LineToHostConverter : ITypedConverter, ITypedConverter { - private readonly ITypedConverter _pointConverter; + private readonly ITypedConverter _pointConverter; + private readonly IRhinoLineFactory _rhinoLineFactory; - public LineToHostConverter(ITypedConverter pointConverter) + public LineToHostConverter(ITypedConverter pointConverter, IRhinoLineFactory rhinoLineFactory) { _pointConverter = pointConverter; + _rhinoLineFactory = rhinoLineFactory; } /// @@ -20,15 +23,15 @@ public LineToHostConverter(ITypedConverter pointConverter /// ///
⚠️ This conversion does not preserve the curve domain. /// If you need it preserved you must request a conversion to - /// conversion instead + /// conversion instead ///
- public RG.Line Convert(SOG.Line target) => - new(_pointConverter.Convert(target.start), _pointConverter.Convert(target.end)); + public IRhinoLine Convert(SOG.Line target) => + _rhinoLineFactory.Create(_pointConverter.Convert(target.start), _pointConverter.Convert(target.end)); /// /// Converts a Speckle Line object to a Rhino LineCurve object. /// /// The Speckle Line object to convert. /// Returns the resulting Rhino LineCurve object. - RG.LineCurve ITypedConverter.Convert(SOG.Line target) => new(Convert(target)); + IRhinoLineCurve ITypedConverter.Convert(SOG.Line target) => _rhinoLineFactory.Create(Convert(target)); } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/NurbsCurveToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/NurbsCurveToHostConverter.cs index 9f9bf52811..291fd4c5dc 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/NurbsCurveToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/NurbsCurveToHostConverter.cs @@ -1,15 +1,20 @@ using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class NurbsCurveToHostConverter : ITypedConverter +public class NurbsCurveToHostConverter : ITypedConverter { - private readonly ITypedConverter _intervalConverter; + private readonly IRhinoPointFactory _rhinoPointFactory; + private readonly IRhinoCurveFactory _rhinoCurveFactory; + private readonly ITypedConverter _intervalConverter; - public NurbsCurveToHostConverter(ITypedConverter intervalConverter) + public NurbsCurveToHostConverter(ITypedConverter intervalConverter, IRhinoCurveFactory rhinoCurveFactory, IRhinoPointFactory rhinoPointFactory) { _intervalConverter = intervalConverter; + _rhinoCurveFactory = rhinoCurveFactory; + _rhinoPointFactory = rhinoPointFactory; } /// @@ -19,14 +24,14 @@ public NurbsCurveToHostConverter(ITypedConverter inte /// The converted Rhino NurbsCurve object. /// Thrown when the conversion fails. /// ⚠️ This conversion does NOT perform scaling. - public RG.NurbsCurve Convert(SOG.Curve target) + public IRhinoNurbsCurve Convert(SOG.Curve target) { - RG.NurbsCurve nurbsCurve = new(target.degree, target.points.Count / 3); + IRhinoNurbsCurve nurbsCurve = _rhinoCurveFactory.Create(target.degree, target.points.Count / 3); // Hyper optimised curve control point conversion for (int i = 2, j = 0; i < target.points.Count; i += 3, j++) { - var pt = new RG.Point3d(target.points[i - 2], target.points[i - 1], target.points[i]); // Skip the point converter for performance + var pt = _rhinoPointFactory.Create(target.points[i - 2], target.points[i - 1], target.points[i]); // Skip the point converter for performance nurbsCurve.Points.SetPoint(j, pt, target.weights[j]); } @@ -37,11 +42,11 @@ public RG.NurbsCurve Convert(SOG.Curve target) { if (extraKnots == 2) { - nurbsCurve.Knots[j] = target.knots[j + 1]; + nurbsCurve.Knots.SetKnot(j, target.knots[j + 1]); } else { - nurbsCurve.Knots[j] = target.knots[j]; + nurbsCurve.Knots.SetKnot(j, target.knots[j]); } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PlaneToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PlaneToHostConverter.cs index 49e10ab69e..6856178a40 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PlaneToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PlaneToHostConverter.cs @@ -1,19 +1,21 @@ using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class PlaneToHostConverter : ITypedConverter +public class PlaneToHostConverter : ITypedConverter { - private readonly ITypedConverter _pointConverter; - private readonly ITypedConverter _vectorConverter; + private readonly ITypedConverter _pointConverter; + private readonly ITypedConverter _vectorConverter; + private readonly IRhinoPlaneFactory _rhinoPlaneFactory; public PlaneToHostConverter( - ITypedConverter pointConverter, - ITypedConverter vectorConverter - ) + ITypedConverter pointConverter, + ITypedConverter vectorConverter, IRhinoPlaneFactory rhinoPlaneFactory) { _pointConverter = pointConverter; _vectorConverter = vectorConverter; + _rhinoPlaneFactory = rhinoPlaneFactory; } /// @@ -22,8 +24,8 @@ public PlaneToHostConverter( /// The Speckle Plane object to be converted. /// The converted Rhino Plane object. /// ⚠️ This conversion does NOT perform scaling. - public RG.Plane Convert(SOG.Plane target) => - new( + public IRhinoPlane Convert(SOG.Plane target) => + _rhinoPlaneFactory.Create( _pointConverter.Convert(target.origin), _vectorConverter.Convert(target.xdir), _vectorConverter.Convert(target.ydir) diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PointCloudToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PointCloudToHostConverter.cs index a6d749b15c..7f59009710 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PointCloudToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PointCloudToHostConverter.cs @@ -1,16 +1,18 @@ using System.Drawing; -using Rhino.Collections; using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class PointCloudToHostConverter : ITypedConverter +public class PointCloudToHostConverter : ITypedConverter { - private readonly ITypedConverter, Point3dList> _pointListConverter; + private readonly ITypedConverter, IRhinoPoint3dList> _pointListConverter; + private readonly IRhinoPointCloudFactory _rhinoPointCloudFactory; - public PointCloudToHostConverter(ITypedConverter, Point3dList> pointListConverter) + public PointCloudToHostConverter(ITypedConverter, IRhinoPoint3dList> pointListConverter, IRhinoPointCloudFactory rhinoPointCloudFactory) { _pointListConverter = pointListConverter; + _rhinoPointCloudFactory = rhinoPointCloudFactory; } /// @@ -19,10 +21,10 @@ public PointCloudToHostConverter(ITypedConverter, Point3dL /// The raw Speckle Pointcloud object to convert. /// The converted Rhino PointCloud object. /// ⚠️ This conversion does NOT perform scaling. - public RG.PointCloud Convert(SOG.Pointcloud target) + public IRhinoPointCloud Convert(SOG.Pointcloud target) { var rhinoPoints = _pointListConverter.Convert(target.points); - var rhinoPointCloud = new RG.PointCloud(rhinoPoints); + var rhinoPointCloud = _rhinoPointCloudFactory.Create(rhinoPoints); if (target.colors.Count == rhinoPoints.Count) { diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PointToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PointToHostConverter.cs index 8ce40bcb59..edc4a3d7cb 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PointToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PointToHostConverter.cs @@ -1,16 +1,24 @@ using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class PointToHostConverter : ITypedConverter, ITypedConverter +public class PointToHostConverter : ITypedConverter, ITypedConverter { + private readonly IRhinoPointFactory _rhinoPointFactory; + + public PointToHostConverter(IRhinoPointFactory rhinoPointFactory) + { + _rhinoPointFactory = rhinoPointFactory; + } + /// /// Converts a Speckle Point object to a Rhino Point3d object. /// /// The Speckle Point object to convert. /// The converted Rhino Point3d object. /// ⚠️ This conversion does NOT perform scaling. - public RG.Point3d Convert(SOG.Point target) => new(target.x, target.y, target.z); + public IRhinoPoint3d Convert(SOG.Point target) => _rhinoPointFactory.Create(target.x, target.y, target.z); /// /// Converts a Speckle Point object to a Rhino Point object. @@ -18,5 +26,5 @@ public class PointToHostConverter : ITypedConverter, ITyp /// The Speckle Point object to convert. /// The converted Rhino Point object. /// ⚠️ This conversion does NOT perform scaling. - RG.Point ITypedConverter.Convert(SOG.Point target) => new(Convert(target)); + IRhinoPoint ITypedConverter.Convert(SOG.Point target) => _rhinoPointFactory.Create(Convert(target)); } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PolyCurveToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PolyCurveToHostConverter.cs index 3f35905090..effbce9847 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PolyCurveToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PolyCurveToHostConverter.cs @@ -1,19 +1,21 @@ using Objects; -using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Core.Kits; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class PolyCurveToHostConverter : ITypedConverter +public class PolyCurveToHostConverter : ITypedConverter { - public ITypedConverter? CurveConverter { get; set; } // POC: CNX-9311 Circular dependency injected by the container using property. + private readonly ITypedConverter _curveConverter; + private readonly ITypedConverter _intervalConverter; + private readonly IRhinoCurveFactory _rhinoCurveFactory; - private readonly ITypedConverter _intervalConverter; - - public PolyCurveToHostConverter(ITypedConverter intervalConverter) + public PolyCurveToHostConverter(ITypedConverter intervalConverter, ITypedConverter curveConverter, IRhinoCurveFactory rhinoCurveFactory) { _intervalConverter = intervalConverter; + _curveConverter = curveConverter; + _rhinoCurveFactory = rhinoCurveFactory; } /// @@ -22,13 +24,13 @@ public PolyCurveToHostConverter(ITypedConverter inter /// The SpecklePolyCurve object to convert. /// The converted Rhino PolyCurve object. /// ⚠️ This conversion does NOT perform scaling. - public RG.PolyCurve Convert(SOG.Polycurve target) + public IRhinoPolyCurve Convert(SOG.Polycurve target) { - RG.PolyCurve result = new(); + IRhinoPolyCurve result = _rhinoCurveFactory.Create(); foreach (var segment in target.segments) { - var childCurve = CurveConverter.NotNull().Convert(segment); + var childCurve = _curveConverter.Convert(segment); bool success = result.AppendSegment(childCurve); if (!success) { diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PolylineToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PolylineToHostConverter.cs index 5abe48fed5..4d1adff489 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PolylineToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PolylineToHostConverter.cs @@ -1,22 +1,23 @@ -using Rhino.Collections; -using Speckle.Converters.Common.Objects; +using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; public class PolylineToHostConverter - : ITypedConverter, - ITypedConverter + : ITypedConverter, + ITypedConverter { - private readonly ITypedConverter, Point3dList> _pointListConverter; - private readonly ITypedConverter _intervalConverter; + private readonly ITypedConverter, IRhinoPoint3dList> _pointListConverter; + private readonly ITypedConverter _intervalConverter; + private readonly IRhinoLineFactory _rhinoLineFactory; public PolylineToHostConverter( - ITypedConverter, Point3dList> pointListConverter, - ITypedConverter intervalConverter - ) + ITypedConverter, IRhinoPoint3dList> pointListConverter, + ITypedConverter intervalConverter, IRhinoLineFactory rhinoLineFactory) { _pointListConverter = pointListConverter; _intervalConverter = intervalConverter; + _rhinoLineFactory = rhinoLineFactory; } /// @@ -28,9 +29,9 @@ public PolylineToHostConverter( /// ///
⚠️ This conversion does not preserve the curve domain. /// If you need it preserved you must request a conversion to - /// conversion instead + /// conversion instead ///
- public RG.Polyline Convert(SOG.Polyline target) + public IRhinoPolyline Convert(SOG.Polyline target) { var points = _pointListConverter.Convert(target.value); @@ -39,7 +40,7 @@ public RG.Polyline Convert(SOG.Polyline target) points.Add(points[0]); } - var poly = new RG.Polyline(points); + var poly = _rhinoLineFactory.Create(points); return poly; } @@ -52,7 +53,7 @@ public RG.Polyline Convert(SOG.Polyline target) /// The Speckle polyline object to be converted. /// The converted Rhino Polyline object. /// ⚠️ This conversion does NOT perform scaling. - RG.PolylineCurve ITypedConverter.Convert(SOG.Polyline target) + IRhinoPolylineCurve ITypedConverter.Convert(SOG.Polyline target) { var poly = Convert(target).ToPolylineCurve(); poly.Domain = _intervalConverter.Convert(target.domain); diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/SpiralToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/SpiralToHostConverter.cs index cb7f5a8745..c3cc3532ce 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/SpiralToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/SpiralToHostConverter.cs @@ -1,15 +1,16 @@ using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class SpiralToHostConverter : ITypedConverter +public class SpiralToHostConverter : ITypedConverter { - private readonly ITypedConverter _polylineConverter; - private readonly ITypedConverter _intervalConverter; + private readonly ITypedConverter _polylineConverter; + private readonly ITypedConverter _intervalConverter; public SpiralToHostConverter( - ITypedConverter polylineConverter, - ITypedConverter intervalConverter + ITypedConverter polylineConverter, + ITypedConverter intervalConverter ) { _polylineConverter = polylineConverter; @@ -22,7 +23,7 @@ public SpiralToHostConverter( /// The Speckle Spiral object to be converted. /// A Rhino PolylineCurve object. /// ⚠️ This conversion does NOT perform scaling. - public RG.PolylineCurve Convert(SOG.Spiral target) + public IRhinoPolylineCurve Convert(SOG.Spiral target) { var result = _polylineConverter.Convert(target.displayValue); result.Domain = _intervalConverter.Convert(target.domain); diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/SurfaceToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/SurfaceToHostConverter.cs index 91da44ec59..d945c3da8f 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/SurfaceToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/SurfaceToHostConverter.cs @@ -1,21 +1,29 @@ using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class SurfaceToHostConverter : ITypedConverter +public class SurfaceToHostConverter : ITypedConverter { + private readonly IRhinoSurfaceFactory _rhinoSurfaceFactory; + + public SurfaceToHostConverter(IRhinoSurfaceFactory rhinoSurfaceFactory) + { + _rhinoSurfaceFactory = rhinoSurfaceFactory; + } + /// /// Converts a raw Speckle surface to a Rhino NURBS surface. /// /// The raw Speckle surface to convert. /// The converted Rhino NURBS surface. /// ⚠️ This conversion does NOT perform scaling. - public RG.NurbsSurface Convert(SOG.Surface target) + public IRhinoNurbsSurface Convert(SOG.Surface target) { // Create rhino surface var points = target.GetControlPoints().ToList(); - var result = RG.NurbsSurface.Create( + var result = _rhinoSurfaceFactory.Create( 3, target.rational, target.degreeU + 1, @@ -28,13 +36,13 @@ public RG.NurbsSurface Convert(SOG.Surface target) var correctUKnots = GetCorrectKnots(target.knotsU, target.countU, target.degreeU); for (int i = 0; i < correctUKnots.Count; i++) { - result.KnotsU[i] = correctUKnots[i]; + result.KnotsU.SetKnot(i, correctUKnots[i]); } var correctVKnots = GetCorrectKnots(target.knotsV, target.countV, target.degreeV); for (int i = 0; i < correctVKnots.Count; i++) { - result.KnotsV[i] = correctVKnots[i]; + result.KnotsV.SetKnot(i, correctVKnots[i]); } // Set control points diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/VectorToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/VectorToHostConverter.cs index 77e017f0fd..85ff17692c 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/VectorToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/VectorToHostConverter.cs @@ -1,14 +1,22 @@ using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class VectorToHostConverter : ITypedConverter +public class VectorToHostConverter : ITypedConverter { + private readonly IRhinoVectorFactory _rhinoVectorFactory; + + public VectorToHostConverter(IRhinoVectorFactory rhinoVectorFactory) + { + _rhinoVectorFactory = rhinoVectorFactory; + } + /// /// Converts a Speckle.Vector object to a Rhino Vector3d object. /// /// The Speckle.Vector to be converted. /// The converted Rhino Vector3d object. /// ⚠️ This conversion does NOT perform scaling. - public RG.Vector3d Convert(SOG.Vector target) => new(target.x, target.y, target.z); + public IRhinoVector3d Convert(SOG.Vector target) => _rhinoVectorFactory.Create(target.x, target.y, target.z); } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/BrepObjectToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/BrepObjectToSpeckleTopLevelConverter.cs index 7520c1bd83..cce82c29e9 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/BrepObjectToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/BrepObjectToSpeckleTopLevelConverter.cs @@ -1,23 +1,23 @@ -using Rhino.DocObjects; -using Speckle.Converters.Common; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Core.Models; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.TopLevel; -[NameAndRankValue(nameof(BrepObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +[NameAndRankValue(nameof(IRhinoBrepObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] public class BrepObjectToSpeckleTopLevelConverter : IToSpeckleTopLevelConverter { - private readonly ITypedConverter _curveConverter; + private readonly ITypedConverter _curveConverter; - public BrepObjectToSpeckleTopLevelConverter(ITypedConverter curveConverter) + public BrepObjectToSpeckleTopLevelConverter(ITypedConverter curveConverter) { _curveConverter = curveConverter; } public Base Convert(object target) { - var curveObject = (BrepObject)target; + var curveObject = (IRhinoBrepObject)target; var speckleCurve = _curveConverter.Convert(curveObject.BrepGeometry); return speckleCurve; } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/CurveObjectToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/CurveObjectToSpeckleTopLevelConverter.cs index a8214a0c97..2ff6020bc1 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/CurveObjectToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/CurveObjectToSpeckleTopLevelConverter.cs @@ -1,15 +1,15 @@ -using Rhino.DocObjects; -using Speckle.Converters.Common; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Core.Models; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.TopLevel; -[NameAndRankValue(nameof(CurveObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public class CurveObjectToSpeckleTopLevelConverter : RhinoObjectToSpeckleTopLevelConverter +[NameAndRankValue(nameof(IRhinoCurveObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +public class CurveObjectToSpeckleTopLevelConverter : RhinoObjectToSpeckleTopLevelConverter { - public CurveObjectToSpeckleTopLevelConverter(ITypedConverter conversion) + public CurveObjectToSpeckleTopLevelConverter(ITypedConverter conversion) : base(conversion) { } - protected override RG.Curve GetTypedGeometry(CurveObject input) => input.CurveGeometry; + protected override IRhinoCurve GetTypedGeometry(IRhinoCurveObject input) => input.CurveGeometry; } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/ExtrusionObjectToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/ExtrusionObjectToSpeckleTopLevelConverter.cs index 46d2c27586..cc59b338af 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/ExtrusionObjectToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/ExtrusionObjectToSpeckleTopLevelConverter.cs @@ -1,23 +1,23 @@ -using Rhino.DocObjects; -using Speckle.Converters.Common; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Core.Models; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.TopLevel; -[NameAndRankValue(nameof(ExtrusionObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +[NameAndRankValue(nameof(IRhinoExtrusionObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] public class ExtrusionObjectToSpeckleTopLevelConverter : IToSpeckleTopLevelConverter { - private readonly ITypedConverter _curveConverter; + private readonly ITypedConverter _curveConverter; - public ExtrusionObjectToSpeckleTopLevelConverter(ITypedConverter curveConverter) + public ExtrusionObjectToSpeckleTopLevelConverter(ITypedConverter curveConverter) { _curveConverter = curveConverter; } public Base Convert(object target) { - var curveObject = (ExtrusionObject)target; + var curveObject = (IRhinoExtrusionObject)target; var speckleCurve = _curveConverter.Convert(curveObject.ExtrusionGeometry.ToBrep()); return speckleCurve; } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/MeshObjectToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/MeshObjectToSpeckleTopLevelConverter.cs index f1c9675a04..4a4b5978ee 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/MeshObjectToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/MeshObjectToSpeckleTopLevelConverter.cs @@ -1,14 +1,14 @@ -using Rhino.DocObjects; -using Speckle.Converters.Common; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.TopLevel; -[NameAndRankValue(nameof(MeshObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public class MeshObjectToSpeckleTopLevelConverter : RhinoObjectToSpeckleTopLevelConverter +[NameAndRankValue(nameof(IRhinoMeshObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +public class MeshObjectToSpeckleTopLevelConverter : RhinoObjectToSpeckleTopLevelConverter { - public MeshObjectToSpeckleTopLevelConverter(ITypedConverter conversion) + public MeshObjectToSpeckleTopLevelConverter(ITypedConverter conversion) : base(conversion) { } - protected override RG.Mesh GetTypedGeometry(MeshObject input) => input.MeshGeometry; + protected override IRhinoMesh GetTypedGeometry(IRhinoMeshObject input) => input.MeshGeometry; } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/PointCloudObjectToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/PointCloudObjectToSpeckleTopLevelConverter.cs index e741e38e49..b25c80d190 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/PointCloudObjectToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/PointCloudObjectToSpeckleTopLevelConverter.cs @@ -1,15 +1,15 @@ -using Rhino.DocObjects; -using Speckle.Converters.Common; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.TopLevel; -[NameAndRankValue(nameof(PointCloudObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +[NameAndRankValue(nameof(IRhinoPointCloudObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] public class PointCloudObjectToSpeckleTopLevelConverter - : RhinoObjectToSpeckleTopLevelConverter + : RhinoObjectToSpeckleTopLevelConverter { - public PointCloudObjectToSpeckleTopLevelConverter(ITypedConverter conversion) + public PointCloudObjectToSpeckleTopLevelConverter(ITypedConverter conversion) : base(conversion) { } - protected override RG.PointCloud GetTypedGeometry(PointCloudObject input) => input.PointCloudGeometry; + protected override IRhinoPointCloud GetTypedGeometry(IRhinoPointCloudObject input) => input.PointCloudGeometry; } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/PointObjectToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/PointObjectToSpeckleTopLevelConverter.cs index 7d9c750b64..d127aa0266 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/PointObjectToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/PointObjectToSpeckleTopLevelConverter.cs @@ -1,15 +1,15 @@ -using Rhino.DocObjects; -using Speckle.Converters.Common; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.TopLevel; -[NameAndRankValue(nameof(PointObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +[NameAndRankValue(nameof(IRhinoPointObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] public class PointObjectToSpeckleTopLevelConverter - : RhinoObjectToSpeckleTopLevelConverter + : RhinoObjectToSpeckleTopLevelConverter { - public PointObjectToSpeckleTopLevelConverter(ITypedConverter conversion) + public PointObjectToSpeckleTopLevelConverter(ITypedConverter conversion) : base(conversion) { } - protected override RG.Point GetTypedGeometry(PointObject input) => input.PointGeometry; + protected override IRhinoPoint GetTypedGeometry(IRhinoPointObject input) => input.PointGeometry; } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/RhinoObjectToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/RhinoObjectToSpeckleTopLevelConverter.cs index edff24473a..c21065cd68 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/RhinoObjectToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/RhinoObjectToSpeckleTopLevelConverter.cs @@ -4,8 +4,8 @@ namespace Speckle.Converters.Rhino7.ToSpeckle.TopLevel; public abstract class RhinoObjectToSpeckleTopLevelConverter : IToSpeckleTopLevelConverter - where TTopLevelIn : Rhino.DocObjects.RhinoObject - where TInRaw : RG.GeometryBase + where TTopLevelIn : notnull + where TInRaw : notnull where TOutRaw : Base { public ITypedConverter Conversion { get; }