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

Redo TypedConverters to have one converstion interface #454

Closed
wants to merge 5 commits into from
Closed
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
Expand Up @@ -21,7 +21,7 @@ namespace Speckle.Connectors.Autocad.Operations.Receive;
/// <para>Expects to be a scoped dependency per receive operation.</para>
/// </summary>
public class AutocadHostObjectBuilder(
IRootToHostConverter converter,
IHostConverter converter,
AutocadLayerBaker layerBaker,
AutocadGroupBaker groupBaker,
AutocadInstanceBaker instanceBaker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Speckle.Connectors.Autocad.Operations.Send;

public abstract class AutocadRootObjectBaseBuilder : RootObjectBuilderBase<AutocadRootObject>
{
private readonly IRootToSpeckleConverter _converter;
private readonly ISpeckleConverter _converter;
private readonly string[] _documentPathSeparator = ["\\"];
private readonly ISendConversionCache _sendConversionCache;
private readonly AutocadInstanceUnpacker _instanceUnpacker;
Expand All @@ -29,7 +29,7 @@ public abstract class AutocadRootObjectBaseBuilder : RootObjectBuilderBase<Autoc
private readonly ISdkActivityFactory _activityFactory;

protected AutocadRootObjectBaseBuilder(
IRootToSpeckleConverter converter,
ISpeckleConverter converter,
ISendConversionCache sendConversionCache,
AutocadInstanceUnpacker instanceObjectManager,
AutocadMaterialUnpacker materialUnpacker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public sealed class AutocadRootObjectBuilder : AutocadRootObjectBaseBuilder

public AutocadRootObjectBuilder(
AutocadLayerUnpacker layerUnpacker,
IRootToSpeckleConverter converter,
ISpeckleConverter converter,
ISendConversionCache sendConversionCache,
AutocadInstanceUnpacker instanceObjectManager,
AutocadMaterialUnpacker materialUnpacker,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,39 @@
using Autodesk.AutoCAD.DatabaseServices;
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Converters.Common.Registration;
using Speckle.Sdk.Common.Exceptions;
using Speckle.Sdk.Models;

namespace Speckle.Converters.Autocad;

public class AutocadRootToSpeckleConverter : IRootToSpeckleConverter
public class AutocadRootToSpeckleConverter : SpeckleConverter
{
private readonly IConverterManager<IToSpeckleTopLevelConverter> _toSpeckle;
private readonly IConverterSettingsStore<AutocadConversionSettings> _settingsStore;

public AutocadRootToSpeckleConverter(
IConverterManager<IToSpeckleTopLevelConverter> toSpeckle,
IConverterManager toSpeckle,
IConverterSettingsStore<AutocadConversionSettings> settingsStore
)
) : base(toSpeckle)
{
_toSpeckle = toSpeckle;
_settingsStore = settingsStore;
}

public Base Convert(object target)
public override Base Convert(object target)
{
if (target is not DBObject dbObject)

if (target is not DBObject)
{
Type type = target.GetType();
throw new ValidationException(
$"Conversion of {target.GetType().Name} to Speckle is not supported. Only objects that inherit from DBObject are."
$"Conversion of {type.Name} to Speckle is not supported. Only objects that inherit from DBObject are."
);
}

Type type = dbObject.GetType();

using (var l = _settingsStore.Current.Document.LockDocument())
{
using (var tr = _settingsStore.Current.Document.Database.TransactionManager.StartTransaction())
{
var objectConverter = _toSpeckle.ResolveConverter(type);

var convertedObject = objectConverter.Convert(dbObject);
var convertedObject= base.Convert(target);
tr.Commit();
return convertedObject;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@
<Compile Include="$(MSBuildThisFileDirectory)GlobalUsings.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToHost\Raw\PointToHostRawConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToHost\Geometry\PointToHostConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Geometry\ArcToSpeckleConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Geometry\RegionToSpeckleConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Geometry\SurfaceToSpeckleConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Geometry\Solid3dToSpeckleConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Raw\BrepToSpeckleRawConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Raw\CircularArc2dToSpeckleRawConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Raw\DBArcToSpeckleRawConverter.cs" />
Expand All @@ -53,15 +51,10 @@
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Raw\DBBodyToSpeckleRawConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Raw\DBSolid3dToSpeckleRawConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Raw\DBCurveToSpeckleRawConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Geometry\CircleToSpeckleConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Geometry\EllipseToSpeckleConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Geometry\LineToSpeckleConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Geometry\PointToSpeckleConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Geometry\PolyfaceMeshToSpeckleConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Geometry\Polyline2dToSpeckleConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Geometry\Polyline3dToSpeckleConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Geometry\PolylineToSpeckleConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Geometry\SplineToSpeckleConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Geometry\SubDMeshToSpeckleConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Raw\BoxToSpeckleRawConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Raw\CircularArc3dToSpeckleRawConverter.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Sdk.Models;

namespace Speckle.Converters.Autocad.ToHost.Geometry;

[NameAndRankValue(typeof(SOG.Arc), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)]
public class ArcToHostConverter : IToHostTopLevelConverter, ITypedConverter<SOG.Arc, ADB.Arc>
public class ArcToHostConverter : ITypedConverter<SOG.Arc, ADB.Arc>
{
private readonly ITypedConverter<SOG.Arc, AG.CircularArc3d> _arcConverter;
private readonly ITypedConverter<SOG.Plane, AG.Plane> _planeConverter;
Expand All @@ -22,8 +21,6 @@ IConverterSettingsStore<AutocadConversionSettings> settingsStore
_settingsStore = settingsStore;
}

public object Convert(Base target) => Convert((SOG.Arc)target);

public ADB.Arc Convert(SOG.Arc target)
{
// the most reliable method to convert to autocad convention is to calculate from start, end, and midpoint
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Objects.Geometry.Autocad;
using Speckle.Sdk.Common.Exceptions;
using Speckle.Sdk.Models;

namespace Speckle.Converters.Autocad2023.ToHost.Geometry;

[NameAndRankValue(typeof(SOG.Autocad.AutocadPolycurve), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)]
public class AutocadPolycurveToHostConverter : IToHostTopLevelConverter
public class AutocadPolycurveToHostConverter : ITypedConverter<SOG.Autocad.AutocadPolycurve, object>
{
private readonly ITypedConverter<SOG.Autocad.AutocadPolycurve, ADB.Polyline> _polylineConverter;
private readonly ITypedConverter<SOG.Autocad.AutocadPolycurve, ADB.Polyline2d> _polyline2dConverter;
Expand All @@ -22,10 +23,10 @@ public AutocadPolycurveToHostConverter(
_polyline2dConverter = polyline2dConverter;
_polyline3dConverter = polyline3dConverter;
}


public object Convert(Base target)
public object Convert(AutocadPolycurve polycurve)
{
SOG.Autocad.AutocadPolycurve polycurve = (SOG.Autocad.AutocadPolycurve)target;

switch (polycurve.polyType)
{
Expand All @@ -47,4 +48,6 @@ public object Convert(Base target)
throw new ValidationException("Unknown poly type for AutocadPolycurve");
}
}

public object Convert(Base target) => Convert( (SOG.Autocad.AutocadPolycurve)target);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Speckle.Converters.Autocad.ToHost.Geometry;

[NameAndRankValue(typeof(SOG.Circle), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)]
public class CircleToHostConverter : IToHostTopLevelConverter, ITypedConverter<SOG.Circle, ADB.Circle>
public class CircleToHostConverter : ITypedConverter<SOG.Circle, ADB.Circle>
{
private readonly ITypedConverter<SOG.Point, AG.Point3d> _pointConverter;
private readonly ITypedConverter<SOG.Vector, AG.Vector3d> _vectorConverter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Speckle.Converters.AutocadShared.ToHost.Geometry;

[NameAndRankValue(typeof(SOG.Curve), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)]
public class CurveToHostConverter : IToHostTopLevelConverter, ITypedConverter<SOG.Curve, ADB.Curve>
public class CurveToHostConverter : ITypedConverter<SOG.Curve, ADB.Curve>
{
private readonly ITypedConverter<SOG.Curve, AG.NurbCurve3d> _curveConverter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Speckle.Converters.Autocad.ToHost.Geometry;

[NameAndRankValue(typeof(SOG.Ellipse), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)]
public class EllipseToHostConverter : IToHostTopLevelConverter, ITypedConverter<SOG.Ellipse, ADB.Ellipse>
public class EllipseToHostConverter : ITypedConverter<SOG.Ellipse, ADB.Ellipse>
{
private readonly ITypedConverter<SOG.Point, AG.Point3d> _pointConverter;
private readonly ITypedConverter<SOG.Vector, AG.Vector3d> _vectorConverter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Speckle.Converters.Autocad.ToHost.Geometry;

[NameAndRankValue(typeof(SOG.Line), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)]
public class LineToHostConverter : IToHostTopLevelConverter, ITypedConverter<SOG.Line, ADB.Line>
public class LineToHostConverter : ITypedConverter<SOG.Line, ADB.Line>
{
private readonly ITypedConverter<SOG.Point, AG.Point3d> _pointConverter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Speckle.Converters.Autocad.Geometry;

[NameAndRankValue(typeof(SOG.Mesh), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)]
public class MeshToHostConverter : IToHostTopLevelConverter, ITypedConverter<SOG.Mesh, ADB.PolyFaceMesh>
public class MeshToHostConverter : ITypedConverter<SOG.Mesh, ADB.PolyFaceMesh>
{
private readonly ITypedConverter<SOG.Point, AG.Point3d> _pointConverter;
private readonly IConverterSettingsStore<AutocadConversionSettings> _settingsStore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Speckle.Converters.Autocad.ToHost.Geometry;

[NameAndRankValue(typeof(SOG.Point), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)]
public class PointToHostConverter : IToHostTopLevelConverter, ITypedConverter<SOG.Point, ADB.DBPoint>
public class PointToHostConverter : ITypedConverter<SOG.Point, ADB.DBPoint>
{
private readonly ITypedConverter<SOG.Point, AG.Point3d> _pointConverter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Sdk.Models;

namespace Speckle.Converters.AutocadShared.ToHost.Geometry;

Expand All @@ -10,7 +9,7 @@ namespace Speckle.Converters.AutocadShared.ToHost.Geometry;
/// Otherwise we convert it as spline (list of ADB.Entity) that switch cases according to each segment type.
/// </summary>
[NameAndRankValue(typeof(SOG.Polycurve), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)]
public class PolycurveToHostConverter : IToHostTopLevelConverter
public class PolycurveToHostConverter : ITypedConverter<SOG.Polycurve, object>
{
private readonly ITypedConverter<SOG.Polycurve, ADB.Polyline> _polylineConverter;
private readonly ITypedConverter<SOG.Polycurve, List<ADB.Entity>> _splineConverter;
Expand All @@ -24,9 +23,8 @@ public PolycurveToHostConverter(
_splineConverter = splineConverter;
}

public object Convert(Base target)
public object Convert( SOG.Polycurve polycurve)
{
SOG.Polycurve polycurve = (SOG.Polycurve)target;
bool convertAsSpline = polycurve.segments.Any(s => s is not SOG.Line and not SOG.Arc);
bool isPlanar = IsPolycurvePlanar(polycurve);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Speckle.Converters.Autocad.ToHost.Geometry;

[NameAndRankValue(typeof(SOG.Polyline), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)]
public class PolylineToHostConverter : IToHostTopLevelConverter, ITypedConverter<SOG.Polyline, ADB.Polyline3d>
public class PolylineToHostConverter : ITypedConverter<SOG.Polyline, ADB.Polyline3d>
{
private readonly ITypedConverter<SOG.Point, AG.Point3d> _pointConverter;

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Autodesk.AutoCAD.Geometry;
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Sdk.Models;

namespace Speckle.Converters.Autocad.Geometry;

Expand All @@ -12,7 +11,7 @@ namespace Speckle.Converters.Autocad.Geometry;
/// The IToSpeckleTopLevelConverter inheritance should only expect database-resident <see cref="ADB.PolyFaceMesh"/> objects. IRawConversion inheritance can expect non database-resident objects, when generated from other converters.
/// </remarks>
[NameAndRankValue(typeof(ADB.PolyFaceMesh), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)]
public class DBPolyfaceMeshToSpeckleConverter : IToSpeckleTopLevelConverter
public class DBPolyfaceMeshToSpeckleConverter : ITypedConverter<ADB.PolyFaceMesh, SOG.Mesh>
{
private readonly ITypedConverter<AG.Point3d, SOG.Point> _pointConverter;
private readonly ITypedConverter<ADB.Extents3d, SOG.Box> _boxConverter;
Expand All @@ -28,10 +27,8 @@ IConverterSettingsStore<AutocadConversionSettings> settingsStore
_boxConverter = boxConverter;
_settingsStore = settingsStore;
}

public Base Convert(object target) => RawConvert((ADB.PolyFaceMesh)target);

public SOG.Mesh RawConvert(ADB.PolyFaceMesh target)

public SOG.Mesh Convert(ADB.PolyFaceMesh target)
{
List<Point3d> dbVertices = new();
List<int> faces = new();
Expand Down
Loading
Loading