From d2eef5e337f8895ac9e3b2a5dfd2004e5d81f4d9 Mon Sep 17 00:00:00 2001 From: Claire Kuang Date: Mon, 1 Jul 2024 15:12:48 +0100 Subject: [PATCH] adds missing autocad converters --- All.sln | 74 ++++----- ...Speckle.Converters.AutocadShared.projitems | 7 +- .../Geometry/ArcToSpeckleConverter.cs | 49 +----- .../Geometry/CircleToSpeckleConverter.cs | 24 +-- .../Geometry/EllipseToSpeckleConverter.cs | 34 +--- .../Geometry/LineToSpeckleConverter.cs | 28 +--- .../Geometry/Polyline2dToSpeckleConverter.cs | 8 +- .../Geometry/Polyline3dToSpeckleConverter.cs | 8 +- .../Geometry/SplineToSpeckleConverter.cs | 146 +---------------- .../Raw/DBArcToSpeckleRawConverter.cs | 58 +++++++ .../Raw/DBCircleToSpeckleRawConverter.cs | 35 ++++ .../Raw/DBCurveToSpeckleRawConverter.cs | 21 +-- .../Raw/DBEllipseToSpeckleRawConverter.cs | 45 +++++ .../Raw/DBLineToSpeckleRawConverter.cs | 37 +++++ ...r.cs => DBSolid3dToSpeckleRawConverter.cs} | 2 + .../Raw/DBSplineToSpeckleRawConverter.cs | 155 ++++++++++++++++++ .../Civil3dConverterModule.cs | 1 + .../ContainerRegistration.cs | 1 - 18 files changed, 420 insertions(+), 313 deletions(-) create mode 100644 DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBArcToSpeckleRawConverter.cs create mode 100644 DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBCircleToSpeckleRawConverter.cs create mode 100644 DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBEllipseToSpeckleRawConverter.cs create mode 100644 DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBLineToSpeckleRawConverter.cs rename DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/{Solid3dToSpeckleRawConverter.cs => DBSolid3dToSpeckleRawConverter.cs} (98%) create mode 100644 DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBSplineToSpeckleRawConverter.cs diff --git a/All.sln b/All.sln index 615f0712aa..3b3db3fa67 100644 --- a/All.sln +++ b/All.sln @@ -563,15 +563,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Speckle.Connectors.Civil3d2 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Speckle.Converters.Autocad2024", "DUI3-DX\Converters\Autocad\Speckle.Converters.Autocad2024\Speckle.Converters.Autocad2024.csproj", "{C9C28F31-1367-438C-83B0-049C3B3A3E3B}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Speckle.Converters.Autocad2024.DependencyInjection", "DUI3-DX\Converters\Autocad\Speckle.Converters.Autocad2024.DependencyInjection\Speckle.Converters.Autocad2024.DependencyInjection.csproj", "{06082BAA-98E8-49B1-9D33-252B126A0561}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Civil3d", "Civil3d", "{34A6BB15-A030-4C5B-94B2-1A1DFE49334A}" EndProject Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Speckle.Converters.Civil3dShared", "DUI3-DX\Converters\Civil3d\Speckle.Converters.Civil3dShared\Speckle.Converters.Civil3dShared.shproj", "{35175682-DA83-4C0A-A49D-B191F5885D8E}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Speckle.Converters.Civil3d2024", "DUI3-DX\Converters\Civil3d\Speckle.Converters.Civil3d2024\Speckle.Converters.Civil3d2024.csproj", "{E7FA6A25-A224-4207-846B-75CE8236228D}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Speckle.Converters.Civil3d2024.DependencyInjection", "DUI3-DX\Converters\Civil3d\Speckle.Converters.Civil3d2024.DependencyInjection\Speckle.Converters.Civil3d2024.DependencyInjection.csproj", "{D6EBC116-8113-4F43-B5E5-35A3272D7ADE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Speckle.Converters.Civil3d2024.DependencyInjection", "DUI3-DX\Converters\Civil3d\Speckle.Converters.Civil3d2024.DependencyInjection\Speckle.Converters.Civil3d2024.DependencyInjection.csproj", "{9BCE88BA-1E01-44EE-BF9D-2CB906E63E34}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Speckle.Converters.Autocad2024.DependencyInjection", "DUI3-DX\Converters\Autocad\Speckle.Converters.Autocad2024.DependencyInjection\Speckle.Converters.Autocad2024.DependencyInjection.csproj", "{2C587020-5F9F-40E1-8AF8-772FE3FC256A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -2871,22 +2871,6 @@ Global {C9C28F31-1367-438C-83B0-049C3B3A3E3B}.Release|Any CPU.Build.0 = Release|Any CPU {C9C28F31-1367-438C-83B0-049C3B3A3E3B}.Release|x64.ActiveCfg = Release|Any CPU {C9C28F31-1367-438C-83B0-049C3B3A3E3B}.Release|x64.Build.0 = Release|Any CPU - {06082BAA-98E8-49B1-9D33-252B126A0561}.Debug Mac|Any CPU.ActiveCfg = Debug|Any CPU - {06082BAA-98E8-49B1-9D33-252B126A0561}.Debug Mac|Any CPU.Build.0 = Debug|Any CPU - {06082BAA-98E8-49B1-9D33-252B126A0561}.Debug Mac|x64.ActiveCfg = Debug|Any CPU - {06082BAA-98E8-49B1-9D33-252B126A0561}.Debug Mac|x64.Build.0 = Debug|Any CPU - {06082BAA-98E8-49B1-9D33-252B126A0561}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {06082BAA-98E8-49B1-9D33-252B126A0561}.Debug|Any CPU.Build.0 = Debug|Any CPU - {06082BAA-98E8-49B1-9D33-252B126A0561}.Debug|x64.ActiveCfg = Debug|Any CPU - {06082BAA-98E8-49B1-9D33-252B126A0561}.Debug|x64.Build.0 = Debug|Any CPU - {06082BAA-98E8-49B1-9D33-252B126A0561}.Release Mac|Any CPU.ActiveCfg = Release|Any CPU - {06082BAA-98E8-49B1-9D33-252B126A0561}.Release Mac|Any CPU.Build.0 = Release|Any CPU - {06082BAA-98E8-49B1-9D33-252B126A0561}.Release Mac|x64.ActiveCfg = Release|Any CPU - {06082BAA-98E8-49B1-9D33-252B126A0561}.Release Mac|x64.Build.0 = Release|Any CPU - {06082BAA-98E8-49B1-9D33-252B126A0561}.Release|Any CPU.ActiveCfg = Release|Any CPU - {06082BAA-98E8-49B1-9D33-252B126A0561}.Release|Any CPU.Build.0 = Release|Any CPU - {06082BAA-98E8-49B1-9D33-252B126A0561}.Release|x64.ActiveCfg = Release|Any CPU - {06082BAA-98E8-49B1-9D33-252B126A0561}.Release|x64.Build.0 = Release|Any CPU {E7FA6A25-A224-4207-846B-75CE8236228D}.Debug Mac|Any CPU.ActiveCfg = Debug|Any CPU {E7FA6A25-A224-4207-846B-75CE8236228D}.Debug Mac|Any CPU.Build.0 = Debug|Any CPU {E7FA6A25-A224-4207-846B-75CE8236228D}.Debug Mac|x64.ActiveCfg = Debug|Any CPU @@ -2903,22 +2887,38 @@ Global {E7FA6A25-A224-4207-846B-75CE8236228D}.Release|Any CPU.Build.0 = Release|Any CPU {E7FA6A25-A224-4207-846B-75CE8236228D}.Release|x64.ActiveCfg = Release|Any CPU {E7FA6A25-A224-4207-846B-75CE8236228D}.Release|x64.Build.0 = Release|Any CPU - {D6EBC116-8113-4F43-B5E5-35A3272D7ADE}.Debug Mac|Any CPU.ActiveCfg = Debug|Any CPU - {D6EBC116-8113-4F43-B5E5-35A3272D7ADE}.Debug Mac|Any CPU.Build.0 = Debug|Any CPU - {D6EBC116-8113-4F43-B5E5-35A3272D7ADE}.Debug Mac|x64.ActiveCfg = Debug|Any CPU - {D6EBC116-8113-4F43-B5E5-35A3272D7ADE}.Debug Mac|x64.Build.0 = Debug|Any CPU - {D6EBC116-8113-4F43-B5E5-35A3272D7ADE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D6EBC116-8113-4F43-B5E5-35A3272D7ADE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D6EBC116-8113-4F43-B5E5-35A3272D7ADE}.Debug|x64.ActiveCfg = Debug|Any CPU - {D6EBC116-8113-4F43-B5E5-35A3272D7ADE}.Debug|x64.Build.0 = Debug|Any CPU - {D6EBC116-8113-4F43-B5E5-35A3272D7ADE}.Release Mac|Any CPU.ActiveCfg = Release|Any CPU - {D6EBC116-8113-4F43-B5E5-35A3272D7ADE}.Release Mac|Any CPU.Build.0 = Release|Any CPU - {D6EBC116-8113-4F43-B5E5-35A3272D7ADE}.Release Mac|x64.ActiveCfg = Release|Any CPU - {D6EBC116-8113-4F43-B5E5-35A3272D7ADE}.Release Mac|x64.Build.0 = Release|Any CPU - {D6EBC116-8113-4F43-B5E5-35A3272D7ADE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D6EBC116-8113-4F43-B5E5-35A3272D7ADE}.Release|Any CPU.Build.0 = Release|Any CPU - {D6EBC116-8113-4F43-B5E5-35A3272D7ADE}.Release|x64.ActiveCfg = Release|Any CPU - {D6EBC116-8113-4F43-B5E5-35A3272D7ADE}.Release|x64.Build.0 = Release|Any CPU + {9BCE88BA-1E01-44EE-BF9D-2CB906E63E34}.Debug Mac|Any CPU.ActiveCfg = Debug|Any CPU + {9BCE88BA-1E01-44EE-BF9D-2CB906E63E34}.Debug Mac|Any CPU.Build.0 = Debug|Any CPU + {9BCE88BA-1E01-44EE-BF9D-2CB906E63E34}.Debug Mac|x64.ActiveCfg = Debug|Any CPU + {9BCE88BA-1E01-44EE-BF9D-2CB906E63E34}.Debug Mac|x64.Build.0 = Debug|Any CPU + {9BCE88BA-1E01-44EE-BF9D-2CB906E63E34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9BCE88BA-1E01-44EE-BF9D-2CB906E63E34}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9BCE88BA-1E01-44EE-BF9D-2CB906E63E34}.Debug|x64.ActiveCfg = Debug|Any CPU + {9BCE88BA-1E01-44EE-BF9D-2CB906E63E34}.Debug|x64.Build.0 = Debug|Any CPU + {9BCE88BA-1E01-44EE-BF9D-2CB906E63E34}.Release Mac|Any CPU.ActiveCfg = Release|Any CPU + {9BCE88BA-1E01-44EE-BF9D-2CB906E63E34}.Release Mac|Any CPU.Build.0 = Release|Any CPU + {9BCE88BA-1E01-44EE-BF9D-2CB906E63E34}.Release Mac|x64.ActiveCfg = Release|Any CPU + {9BCE88BA-1E01-44EE-BF9D-2CB906E63E34}.Release Mac|x64.Build.0 = Release|Any CPU + {9BCE88BA-1E01-44EE-BF9D-2CB906E63E34}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9BCE88BA-1E01-44EE-BF9D-2CB906E63E34}.Release|Any CPU.Build.0 = Release|Any CPU + {9BCE88BA-1E01-44EE-BF9D-2CB906E63E34}.Release|x64.ActiveCfg = Release|Any CPU + {9BCE88BA-1E01-44EE-BF9D-2CB906E63E34}.Release|x64.Build.0 = Release|Any CPU + {2C587020-5F9F-40E1-8AF8-772FE3FC256A}.Debug Mac|Any CPU.ActiveCfg = Debug|Any CPU + {2C587020-5F9F-40E1-8AF8-772FE3FC256A}.Debug Mac|Any CPU.Build.0 = Debug|Any CPU + {2C587020-5F9F-40E1-8AF8-772FE3FC256A}.Debug Mac|x64.ActiveCfg = Debug|Any CPU + {2C587020-5F9F-40E1-8AF8-772FE3FC256A}.Debug Mac|x64.Build.0 = Debug|Any CPU + {2C587020-5F9F-40E1-8AF8-772FE3FC256A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2C587020-5F9F-40E1-8AF8-772FE3FC256A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2C587020-5F9F-40E1-8AF8-772FE3FC256A}.Debug|x64.ActiveCfg = Debug|Any CPU + {2C587020-5F9F-40E1-8AF8-772FE3FC256A}.Debug|x64.Build.0 = Debug|Any CPU + {2C587020-5F9F-40E1-8AF8-772FE3FC256A}.Release Mac|Any CPU.ActiveCfg = Release|Any CPU + {2C587020-5F9F-40E1-8AF8-772FE3FC256A}.Release Mac|Any CPU.Build.0 = Release|Any CPU + {2C587020-5F9F-40E1-8AF8-772FE3FC256A}.Release Mac|x64.ActiveCfg = Release|Any CPU + {2C587020-5F9F-40E1-8AF8-772FE3FC256A}.Release Mac|x64.Build.0 = Release|Any CPU + {2C587020-5F9F-40E1-8AF8-772FE3FC256A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2C587020-5F9F-40E1-8AF8-772FE3FC256A}.Release|Any CPU.Build.0 = Release|Any CPU + {2C587020-5F9F-40E1-8AF8-772FE3FC256A}.Release|x64.ActiveCfg = Release|Any CPU + {2C587020-5F9F-40E1-8AF8-772FE3FC256A}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -3134,11 +3134,11 @@ Global {95E23A97-E5EA-4506-A52C-D3DA9012DA02} = {2E00592E-558D-492D-88F9-3ECEE4C0C7DA} {DDBBA313-69A6-40DE-AB3A-79EE5BF32A7E} = {743489BF-1941-43D5-8AF9-35C56D0DCC34} {C9C28F31-1367-438C-83B0-049C3B3A3E3B} = {804E065F-914C-414A-AF84-009312C3CFF6} - {06082BAA-98E8-49B1-9D33-252B126A0561} = {804E065F-914C-414A-AF84-009312C3CFF6} {34A6BB15-A030-4C5B-94B2-1A1DFE49334A} = {1FE3C60E-7865-40A5-9794-55ECB64F6489} {35175682-DA83-4C0A-A49D-B191F5885D8E} = {34A6BB15-A030-4C5B-94B2-1A1DFE49334A} {E7FA6A25-A224-4207-846B-75CE8236228D} = {34A6BB15-A030-4C5B-94B2-1A1DFE49334A} - {D6EBC116-8113-4F43-B5E5-35A3272D7ADE} = {34A6BB15-A030-4C5B-94B2-1A1DFE49334A} + {9BCE88BA-1E01-44EE-BF9D-2CB906E63E34} = {34A6BB15-A030-4C5B-94B2-1A1DFE49334A} + {2C587020-5F9F-40E1-8AF8-772FE3FC256A} = {804E065F-914C-414A-AF84-009312C3CFF6} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {1D43D91B-4F01-4A78-8250-CC6F9BD93A14} diff --git a/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/Speckle.Converters.AutocadShared.projitems b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/Speckle.Converters.AutocadShared.projitems index aa19038457..8fb784a3af 100644 --- a/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/Speckle.Converters.AutocadShared.projitems +++ b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/Speckle.Converters.AutocadShared.projitems @@ -39,7 +39,11 @@ - + + + + + @@ -57,6 +61,7 @@ + \ No newline at end of file diff --git a/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/ArcToSpeckleConverter.cs b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/ArcToSpeckleConverter.cs index 36d7b796f6..c437aa04e0 100644 --- a/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/ArcToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/ArcToSpeckleConverter.cs @@ -5,55 +5,16 @@ namespace Speckle.Converters.Autocad.ToSpeckle.Geometry; [NameAndRankValue(nameof(ADB.Arc), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public class DBArcToSpeckleConverter : IToSpeckleTopLevelConverter, ITypedConverter +public class DBArcToSpeckleConverter : IToSpeckleTopLevelConverter { - private readonly ITypedConverter _pointConverter; - private readonly ITypedConverter _planeConverter; - private readonly ITypedConverter _boxConverter; - private readonly IConversionContextStack _contextStack; + private readonly ITypedConverter _arcConverter; - public DBArcToSpeckleConverter( - ITypedConverter pointConverter, - ITypedConverter planeConverter, - ITypedConverter boxConverter, - IConversionContextStack contextStack - ) + public DBArcToSpeckleConverter(ITypedConverter arcConverter) { - _pointConverter = pointConverter; - _planeConverter = planeConverter; - _boxConverter = boxConverter; - _contextStack = contextStack; + _arcConverter = arcConverter; } public Base Convert(object target) => Convert((ADB.Arc)target); - public SOG.Arc Convert(ADB.Arc target) - { - SOG.Plane plane = _planeConverter.Convert(target.GetPlane()); - SOG.Point start = _pointConverter.Convert(target.StartPoint); - SOG.Point end = _pointConverter.Convert(target.EndPoint); - SOG.Point mid = _pointConverter.Convert(target.GetPointAtDist(target.Length / 2.0)); - SOP.Interval domain = new(target.StartParam, target.EndParam); - SOG.Box bbox = _boxConverter.Convert(target.GeometricExtents); - - SOG.Arc arc = - new( - plane, - target.Radius, - target.StartAngle, - target.EndAngle, - target.TotalAngle, - _contextStack.Current.SpeckleUnits - ) - { - startPoint = start, - endPoint = end, - midPoint = mid, - domain = domain, - length = target.Length, - bbox = bbox - }; - - return arc; - } + public SOG.Arc Convert(ADB.Arc target) => _arcConverter.Convert(target); } diff --git a/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/CircleToSpeckleConverter.cs b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/CircleToSpeckleConverter.cs index 18b45a8daf..16b1a2bd26 100644 --- a/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/CircleToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/CircleToSpeckleConverter.cs @@ -7,30 +7,14 @@ namespace Speckle.Converters.Autocad.ToSpeckle.Geometry; [NameAndRankValue(nameof(ADB.Circle), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] public class DBCircleToSpeckleConverter : IToSpeckleTopLevelConverter { - private readonly ITypedConverter _planeConverter; - private readonly ITypedConverter _boxConverter; - private readonly IConversionContextStack _contextStack; + private readonly ITypedConverter _circleConverter; - public DBCircleToSpeckleConverter( - ITypedConverter planeConverter, - ITypedConverter boxConverter, - IConversionContextStack contextStack - ) + public DBCircleToSpeckleConverter(ITypedConverter circleConverter) { - _planeConverter = planeConverter; - _boxConverter = boxConverter; - _contextStack = contextStack; + _circleConverter = circleConverter; } public Base Convert(object target) => RawConvert((ADB.Circle)target); - public SOG.Circle RawConvert(ADB.Circle target) - { - SOG.Plane plane = _planeConverter.Convert(target.GetPlane()); - SOG.Box bbox = _boxConverter.Convert(target.GeometricExtents); - SOG.Circle circle = - new(plane, target.Radius, _contextStack.Current.SpeckleUnits) { length = target.Circumference, bbox = bbox }; - - return circle; - } + public SOG.Circle RawConvert(ADB.Circle target) => _circleConverter.Convert(target); } diff --git a/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/EllipseToSpeckleConverter.cs b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/EllipseToSpeckleConverter.cs index 524e1a1d8c..53d3d7e5b7 100644 --- a/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/EllipseToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/EllipseToSpeckleConverter.cs @@ -7,40 +7,14 @@ namespace Speckle.Converters.Autocad.ToSpeckle.Geometry; [NameAndRankValue(nameof(ADB.Ellipse), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] public class DBEllipseToSpeckleConverter : IToSpeckleTopLevelConverter { - private readonly ITypedConverter _planeConverter; - private readonly ITypedConverter _boxConverter; - private readonly IConversionContextStack _contextStack; + private readonly ITypedConverter _ellipseConverter; - public DBEllipseToSpeckleConverter( - ITypedConverter planeConverter, - ITypedConverter boxConverter, - IConversionContextStack contextStack - ) + public DBEllipseToSpeckleConverter(ITypedConverter ellipseConverter) { - _planeConverter = planeConverter; - _boxConverter = boxConverter; - _contextStack = contextStack; + _ellipseConverter = ellipseConverter; } public Base Convert(object target) => RawConvert((ADB.Ellipse)target); - public SOG.Ellipse RawConvert(ADB.Ellipse target) - { - SOG.Plane plane = _planeConverter.Convert(new AG.Plane(target.Center, target.MajorAxis, target.MinorAxis)); - SOG.Box bbox = _boxConverter.Convert(target.GeometricExtents); - - // the start and end param corresponds to start and end angle in radians - SOP.Interval trim = new(target.StartAngle, target.EndAngle); - - SOG.Ellipse ellipse = - new(plane, target.MajorRadius, target.MinorRadius, _contextStack.Current.SpeckleUnits) - { - domain = new(0, Math.PI * 2), - trimDomain = trim, - length = target.GetDistanceAtParameter(target.EndParam), - bbox = bbox - }; - - return ellipse; - } + public SOG.Ellipse RawConvert(ADB.Ellipse target) => _ellipseConverter.Convert(target); } diff --git a/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/LineToSpeckleConverter.cs b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/LineToSpeckleConverter.cs index 22787e2290..710a607f9e 100644 --- a/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/LineToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/LineToSpeckleConverter.cs @@ -5,34 +5,16 @@ namespace Speckle.Converters.Autocad.ToSpeckle.Geometry; [NameAndRankValue(nameof(ADB.Line), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public class LineToSpeckleConverter : IToSpeckleTopLevelConverter, ITypedConverter +public class LineToSpeckleConverter : IToSpeckleTopLevelConverter { - private readonly ITypedConverter _pointConverter; - private readonly ITypedConverter _boxConverter; - private readonly IConversionContextStack _contextStack; + private readonly ITypedConverter _lineConverter; - public LineToSpeckleConverter( - ITypedConverter pointConverter, - ITypedConverter boxConverter, - IConversionContextStack contextStack - ) + public LineToSpeckleConverter(ITypedConverter lineConverter) { - _pointConverter = pointConverter; - _boxConverter = boxConverter; - _contextStack = contextStack; + _lineConverter = lineConverter; } public Base Convert(object target) => Convert((ADB.Line)target); - public SOG.Line Convert(ADB.Line target) => - new( - _pointConverter.Convert(target.StartPoint), - _pointConverter.Convert(target.EndPoint), - _contextStack.Current.SpeckleUnits - ) - { - length = target.Length, - domain = new SOP.Interval(0, target.Length), - bbox = _boxConverter.Convert(target.GeometricExtents) - }; + public SOG.Line Convert(ADB.Line target) => _lineConverter.Convert(target); } diff --git a/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/Polyline2dToSpeckleConverter.cs b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/Polyline2dToSpeckleConverter.cs index 330d832cba..e0b053c12c 100644 --- a/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/Polyline2dToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/Polyline2dToSpeckleConverter.cs @@ -15,7 +15,9 @@ namespace Speckle.Converters.Autocad.Geometry; /// The IToSpeckleTopLevelConverter inheritance should only expect database-resident objects. IRawConversion inheritance can expect non database-resident objects, when generated from other converters. /// [NameAndRankValue(nameof(ADB.Polyline2d), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public class Polyline2dToSpeckleConverter : IToSpeckleTopLevelConverter +public class Polyline2dToSpeckleConverter + : IToSpeckleTopLevelConverter, + ITypedConverter { private readonly ITypedConverter _arcConverter; private readonly ITypedConverter _lineConverter; @@ -44,9 +46,9 @@ public Polyline2dToSpeckleConverter( _contextStack = contextStack; } - public Base Convert(object target) => RawConvert((ADB.Polyline2d)target); + public Base Convert(object target) => Convert((ADB.Polyline2d)target); - public SOG.Autocad.AutocadPolycurve RawConvert(ADB.Polyline2d target) + public SOG.Autocad.AutocadPolycurve Convert(ADB.Polyline2d target) { // get the poly type var polyType = SOG.Autocad.AutocadPolyType.Unknown; diff --git a/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/Polyline3dToSpeckleConverter.cs b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/Polyline3dToSpeckleConverter.cs index fdef5bd478..87b90ad1e9 100644 --- a/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/Polyline3dToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/Polyline3dToSpeckleConverter.cs @@ -14,7 +14,9 @@ namespace Speckle.Converters.Autocad.Geometry; /// The IToSpeckleTopLevelConverter inheritance should only expect database-resident Polyline2d objects. IRawConversion inheritance can expect non database-resident objects, when generated from other converters. /// [NameAndRankValue(nameof(ADB.Polyline3d), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public class Polyline3dToSpeckleConverter : IToSpeckleTopLevelConverter +public class Polyline3dToSpeckleConverter + : IToSpeckleTopLevelConverter, + ITypedConverter { private readonly ITypedConverter _pointConverter; private readonly ITypedConverter _splineConverter; @@ -34,9 +36,9 @@ public Polyline3dToSpeckleConverter( _contextStack = contextStack; } - public Base Convert(object target) => RawConvert((ADB.Polyline3d)target); + public Base Convert(object target) => Convert((ADB.Polyline3d)target); - public SOG.Autocad.AutocadPolycurve RawConvert(ADB.Polyline3d target) + public SOG.Autocad.AutocadPolycurve Convert(ADB.Polyline3d target) { // get the poly type var polyType = SOG.Autocad.AutocadPolyType.Unknown; diff --git a/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/SplineToSpeckleConverter.cs b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/SplineToSpeckleConverter.cs index 059f92f033..d182376cd7 100644 --- a/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/SplineToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Geometry/SplineToSpeckleConverter.cs @@ -1,5 +1,3 @@ -using Autodesk.AutoCAD.Geometry; -using Speckle.Converters.Autocad.Extensions; using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Core.Models; @@ -7,150 +5,16 @@ namespace Speckle.Converters.Autocad.ToSpeckle.Geometry; [NameAndRankValue(nameof(ADB.Spline), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public class SplineToSpeckleConverter : IToSpeckleTopLevelConverter, ITypedConverter +public class SplineToSpeckleConverter : IToSpeckleTopLevelConverter { - private readonly ITypedConverter _intervalConverter; - private readonly ITypedConverter _boxConverter; - private readonly IConversionContextStack _contextStack; + private readonly ITypedConverter _splineConverter; - public SplineToSpeckleConverter( - ITypedConverter intervalConverter, - ITypedConverter boxConverter, - IConversionContextStack contextStack - ) + public SplineToSpeckleConverter(ITypedConverter splineConverter) { - _intervalConverter = intervalConverter; - _boxConverter = boxConverter; - _contextStack = contextStack; + _splineConverter = splineConverter; } public Base Convert(object target) => Convert((ADB.Spline)target); - public SOG.Curve Convert(ADB.Spline target) - { - // get nurbs and geo data - ADB.NurbsData data = target.NurbsData; - - // POC: HACK: check for incorrectly closed periodic curves (this seems like acad bug, has resulted from receiving rhino curves) - bool periodicClosed = false; - double length = 0; - SOP.Interval domain = new(); - if (target.GetGeCurve() is NurbCurve3d nurbs) - { - length = nurbs.GetLength(nurbs.StartParameter, nurbs.EndParameter, 0.001); - domain = _intervalConverter.Convert(nurbs.GetInterval()); - if (nurbs.Knots.Count < nurbs.NumberOfControlPoints + nurbs.Degree + 1 && target.IsPeriodic) - { - periodicClosed = true; - } - } - - // get points - List points = new(); - foreach (Point3d point in data.GetControlPoints().OfType()) - { - points.Add(point); - } - - // NOTE: for closed periodic splines, autocad does not track last #degree points. - // Add the first #degree control points to the list if so. - if (periodicClosed) - { - points.AddRange(points.GetRange(0, target.Degree)); - } - - // get knots - // NOTE: for closed periodic splines, autocad has #control points + 1 knots. - // Add #degree extra knots to beginning and end with #degree - 1 multiplicity for first and last - var knots = data.GetKnots().OfType().ToList(); - if (periodicClosed) - { - double interval = knots[1] - knots[0]; //knot interval - - for (int i = 0; i < data.Degree; i++) - { - if (i < 2) - { - knots.Insert(knots.Count, knots[^1] + interval); - knots.Insert(0, knots[0] - interval); - } - else - { - knots.Insert(knots.Count, knots[^1]); - knots.Insert(0, knots[0]); - } - } - } - - // get weights - // NOTE: autocad assigns unweighted points a value of -1, and will return an empty list in the spline's nurbsdata if no points are weighted - // NOTE: for closed periodic splines, autocad does not track last #degree points. Add the first #degree weights to the list if so. - List weights = new(); - for (int i = 0; i < target.NumControlPoints; i++) - { - double weight = target.WeightAt(i); - weights.Add(weight <= 0 ? 1 : weight); - } - - if (periodicClosed) - { - weights.AddRange(weights.GetRange(0, target.Degree)); - } - - // set nurbs curve info - var curve = new SOG.Curve - { - points = points.SelectMany(o => o.ToArray()).ToList(), - knots = knots, - weights = weights, - degree = target.Degree, - periodic = target.IsPeriodic, - rational = target.IsRational, - closed = periodicClosed || target.Closed, - length = length, - domain = domain, - bbox = _boxConverter.Convert(target.GeometricExtents), - units = _contextStack.Current.SpeckleUnits - }; - - // POC: get display value if this is a database-resident spline - // POC: if this is called by another converter that has created a spline, assumes the display value is set by that converter - if (target.Database is not null) - { - curve.displayValue = GetDisplayValue(target); - } - - return curve; - } - - // POC: we might have DisplayValue converter/mapper? - private SOG.Polyline GetDisplayValue(ADB.Spline spline) - { - ADB.Curve polySpline = spline.ToPolylineWithPrecision(10, false, false); - List verticesList = new(); - switch (polySpline) - { - case ADB.Polyline2d o: - verticesList = o.GetSubEntities( - ADB.OpenMode.ForRead, - _contextStack.Current.Document.TransactionManager.TopTransaction - ) - .Where(e => e.VertexType != ADB.Vertex2dType.SplineControlVertex) // POC: not validated yet! - .SelectMany(o => o.Position.ToArray()) - .ToList(); - - break; - case ADB.Polyline3d o: - verticesList = o.GetSubEntities( - ADB.OpenMode.ForRead, - _contextStack.Current.Document.TransactionManager.TopTransaction - ) - .Where(e => e.VertexType != ADB.Vertex3dType.ControlVertex) - .SelectMany(o => o.Position.ToArray()) - .ToList(); - break; - } - - return verticesList.ConvertToSpecklePolyline(_contextStack.Current.SpeckleUnits); - } + public SOG.Curve Convert(ADB.Spline target) => _splineConverter.Convert(target); } diff --git a/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBArcToSpeckleRawConverter.cs b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBArcToSpeckleRawConverter.cs new file mode 100644 index 0000000000..8b45be3de3 --- /dev/null +++ b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBArcToSpeckleRawConverter.cs @@ -0,0 +1,58 @@ +using Speckle.Converters.Common; +using Speckle.Converters.Common.Objects; +using Speckle.Core.Models; + +namespace Speckle.Converters.Autocad.ToSpeckle.Raw; + +public class DBArcToSpeckleRawConverter : ITypedConverter +{ + private readonly ITypedConverter _pointConverter; + private readonly ITypedConverter _planeConverter; + private readonly ITypedConverter _boxConverter; + private readonly IConversionContextStack _contextStack; + + public DBArcToSpeckleRawConverter( + ITypedConverter pointConverter, + ITypedConverter planeConverter, + ITypedConverter boxConverter, + IConversionContextStack contextStack + ) + { + _pointConverter = pointConverter; + _planeConverter = planeConverter; + _boxConverter = boxConverter; + _contextStack = contextStack; + } + + public Base Convert(object target) => Convert((ADB.Arc)target); + + public SOG.Arc Convert(ADB.Arc target) + { + SOG.Plane plane = _planeConverter.Convert(target.GetPlane()); + SOG.Point start = _pointConverter.Convert(target.StartPoint); + SOG.Point end = _pointConverter.Convert(target.EndPoint); + SOG.Point mid = _pointConverter.Convert(target.GetPointAtDist(target.Length / 2.0)); + SOP.Interval domain = new(target.StartParam, target.EndParam); + SOG.Box bbox = _boxConverter.Convert(target.GeometricExtents); + + SOG.Arc arc = + new( + plane, + target.Radius, + target.StartAngle, + target.EndAngle, + target.TotalAngle, + _contextStack.Current.SpeckleUnits + ) + { + startPoint = start, + endPoint = end, + midPoint = mid, + domain = domain, + length = target.Length, + bbox = bbox + }; + + return arc; + } +} diff --git a/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBCircleToSpeckleRawConverter.cs b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBCircleToSpeckleRawConverter.cs new file mode 100644 index 0000000000..06f4cf6877 --- /dev/null +++ b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBCircleToSpeckleRawConverter.cs @@ -0,0 +1,35 @@ +using Speckle.Converters.Common; +using Speckle.Converters.Common.Objects; +using Speckle.Core.Models; + +namespace Speckle.Converters.Autocad.ToSpeckle.Raw; + +public class DBCircleToSpeckleRawConverter : ITypedConverter +{ + private readonly ITypedConverter _planeConverter; + private readonly ITypedConverter _boxConverter; + private readonly IConversionContextStack _contextStack; + + public DBCircleToSpeckleRawConverter( + ITypedConverter planeConverter, + ITypedConverter boxConverter, + IConversionContextStack contextStack + ) + { + _planeConverter = planeConverter; + _boxConverter = boxConverter; + _contextStack = contextStack; + } + + public Base Convert(object target) => Convert((ADB.Circle)target); + + public SOG.Circle Convert(ADB.Circle target) + { + SOG.Plane plane = _planeConverter.Convert(target.GetPlane()); + SOG.Box bbox = _boxConverter.Convert(target.GeometricExtents); + SOG.Circle circle = + new(plane, target.Radius, _contextStack.Current.SpeckleUnits) { length = target.Circumference, bbox = bbox }; + + return circle; + } +} diff --git a/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBCurveToSpeckleRawConverter.cs b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBCurveToSpeckleRawConverter.cs index 2853b3246a..ef392923be 100644 --- a/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBCurveToSpeckleRawConverter.cs +++ b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBCurveToSpeckleRawConverter.cs @@ -2,18 +2,19 @@ using Speckle.Converters.Common.Objects; using Speckle.Core.Models; -namespace Speckle.Converters.Autocad.ToSpeckle.Geometry.Raw; +namespace Speckle.Converters.Autocad.ToSpeckle.Raw; public class DBCurveToSpeckleRawConverter : ITypedConverter, ITypedConverter { private readonly ITypedConverter _lineConverter; + private readonly ITypedConverter _polylineConverter; private readonly ITypedConverter _polyline2dConverter; private readonly ITypedConverter _polyline3dConverter; private readonly ITypedConverter _arcConverter; - private readonly ITypedConverter _circleConverter; - private readonly ITypedConverter _ellipseConverter; - private readonly ITypedConverter _splineConverter; + private readonly ITypedConverter _circleConverter; + private readonly ITypedConverter _ellipseConverter; + private readonly ITypedConverter _splineConverter; private readonly IConversionContextStack _contextStack; public DBCurveToSpeckleRawConverter( @@ -22,9 +23,9 @@ public DBCurveToSpeckleRawConverter( ITypedConverter polyline2dConverter, ITypedConverter polyline3dConverter, ITypedConverter arcConverter, - ITypedConverter circleConverter, - ITypedConverter ellipseConverter, - ITypedConverter splineConverter, + ITypedConverter circleConverter, + ITypedConverter ellipseConverter, + ITypedConverter splineConverter, IConversionContextStack contextStack ) { @@ -52,9 +53,9 @@ public Objects.ICurve Convert(ADB.Curve target) => target switch { ADB.Line line => _lineConverter.Convert(line), - ADB.Polyline polyline => _polylineConverter.Convert(polyline), - ADB.Polyline2d polyline2d => _polyline2dConverter.Convert(polyline2d), - ADB.Polyline3d polyline3d => _polyline3dConverter.Convert(polyline3d), + //ADB.Polyline polyline => _polylineConverter.Convert(polyline), + //ADB.Polyline2d polyline2d => _polyline2dConverter.Convert(polyline2d), + //ADB.Polyline3d polyline3d => _polyline3dConverter.Convert(polyline3d), ADB.Arc arc => _arcConverter.Convert(arc), ADB.Circle circle => _circleConverter.Convert(circle), ADB.Ellipse ellipse => _ellipseConverter.Convert(ellipse), diff --git a/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBEllipseToSpeckleRawConverter.cs b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBEllipseToSpeckleRawConverter.cs new file mode 100644 index 0000000000..c763bb0e66 --- /dev/null +++ b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBEllipseToSpeckleRawConverter.cs @@ -0,0 +1,45 @@ +using Speckle.Converters.Common; +using Speckle.Converters.Common.Objects; +using Speckle.Core.Models; + +namespace Speckle.Converters.Autocad.ToSpeckle.Raw; + +public class DBEllipseToSpeckleRawConverter : ITypedConverter +{ + private readonly ITypedConverter _planeConverter; + private readonly ITypedConverter _boxConverter; + private readonly IConversionContextStack _contextStack; + + public DBEllipseToSpeckleRawConverter( + ITypedConverter planeConverter, + ITypedConverter boxConverter, + IConversionContextStack contextStack + ) + { + _planeConverter = planeConverter; + _boxConverter = boxConverter; + _contextStack = contextStack; + } + + public Base Convert(object target) => Convert((ADB.Ellipse)target); + + public SOG.Ellipse Convert(ADB.Ellipse target) + { + SOG.Plane plane = _planeConverter.Convert(new AG.Plane(target.Center, target.MajorAxis, target.MinorAxis)); + SOG.Box bbox = _boxConverter.Convert(target.GeometricExtents); + + // the start and end param corresponds to start and end angle in radians + SOP.Interval trim = new(target.StartAngle, target.EndAngle); + + SOG.Ellipse ellipse = + new(plane, target.MajorRadius, target.MinorRadius, _contextStack.Current.SpeckleUnits) + { + domain = new(0, Math.PI * 2), + trimDomain = trim, + length = target.GetDistanceAtParameter(target.EndParam), + bbox = bbox + }; + + return ellipse; + } +} diff --git a/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBLineToSpeckleRawConverter.cs b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBLineToSpeckleRawConverter.cs new file mode 100644 index 0000000000..b4a083c8e3 --- /dev/null +++ b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBLineToSpeckleRawConverter.cs @@ -0,0 +1,37 @@ +using Speckle.Converters.Common; +using Speckle.Converters.Common.Objects; +using Speckle.Core.Models; + +namespace Speckle.Converters.Autocad.ToSpeckle.Raw; + +public class DBLineToSpeckleRawConverter : ITypedConverter +{ + private readonly ITypedConverter _pointConverter; + private readonly ITypedConverter _boxConverter; + private readonly IConversionContextStack _contextStack; + + public DBLineToSpeckleRawConverter( + ITypedConverter pointConverter, + ITypedConverter boxConverter, + IConversionContextStack contextStack + ) + { + _pointConverter = pointConverter; + _boxConverter = boxConverter; + _contextStack = contextStack; + } + + public Base Convert(object target) => Convert((ADB.Line)target); + + public SOG.Line Convert(ADB.Line target) => + new( + _pointConverter.Convert(target.StartPoint), + _pointConverter.Convert(target.EndPoint), + _contextStack.Current.SpeckleUnits + ) + { + length = target.Length, + domain = new SOP.Interval(0, target.Length), + bbox = _boxConverter.Convert(target.GeometricExtents) + }; +} diff --git a/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/Solid3dToSpeckleRawConverter.cs b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBSolid3dToSpeckleRawConverter.cs similarity index 98% rename from DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/Solid3dToSpeckleRawConverter.cs rename to DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBSolid3dToSpeckleRawConverter.cs index c4a1a5dc12..45c2d531a4 100644 --- a/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/Solid3dToSpeckleRawConverter.cs +++ b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBSolid3dToSpeckleRawConverter.cs @@ -58,6 +58,8 @@ public SOG.Mesh Convert(ADB.Solid3d target) faceList.Add(faceIndices[i]); } + faces.AddRange(faceList); + e.Dispose(); } diff --git a/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBSplineToSpeckleRawConverter.cs b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBSplineToSpeckleRawConverter.cs new file mode 100644 index 0000000000..d46b9de0a7 --- /dev/null +++ b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBSplineToSpeckleRawConverter.cs @@ -0,0 +1,155 @@ +using Autodesk.AutoCAD.Geometry; +using Speckle.Converters.Autocad.Extensions; +using Speckle.Converters.Common; +using Speckle.Converters.Common.Objects; +using Speckle.Core.Models; + +namespace Speckle.Converters.Autocad.ToSpeckle.Raw; + +public class DBSplineToSpeckleRawConverter : ITypedConverter +{ + private readonly ITypedConverter _intervalConverter; + private readonly ITypedConverter _boxConverter; + private readonly IConversionContextStack _contextStack; + + public DBSplineToSpeckleRawConverter( + ITypedConverter intervalConverter, + ITypedConverter boxConverter, + IConversionContextStack contextStack + ) + { + _intervalConverter = intervalConverter; + _boxConverter = boxConverter; + _contextStack = contextStack; + } + + public Base Convert(object target) => Convert((ADB.Spline)target); + + public SOG.Curve Convert(ADB.Spline target) + { + // get nurbs and geo data + ADB.NurbsData data = target.NurbsData; + + // POC: HACK: check for incorrectly closed periodic curves (this seems like acad bug, has resulted from receiving rhino curves) + bool periodicClosed = false; + double length = 0; + SOP.Interval domain = new(); + if (target.GetGeCurve() is NurbCurve3d nurbs) + { + length = nurbs.GetLength(nurbs.StartParameter, nurbs.EndParameter, 0.001); + domain = _intervalConverter.Convert(nurbs.GetInterval()); + if (nurbs.Knots.Count < nurbs.NumberOfControlPoints + nurbs.Degree + 1 && target.IsPeriodic) + { + periodicClosed = true; + } + } + + // get points + List points = new(); + foreach (Point3d point in data.GetControlPoints().OfType()) + { + points.Add(point); + } + + // NOTE: for closed periodic splines, autocad does not track last #degree points. + // Add the first #degree control points to the list if so. + if (periodicClosed) + { + points.AddRange(points.GetRange(0, target.Degree)); + } + + // get knots + // NOTE: for closed periodic splines, autocad has #control points + 1 knots. + // Add #degree extra knots to beginning and end with #degree - 1 multiplicity for first and last + var knots = data.GetKnots().OfType().ToList(); + if (periodicClosed) + { + double interval = knots[1] - knots[0]; //knot interval + + for (int i = 0; i < data.Degree; i++) + { + if (i < 2) + { + knots.Insert(knots.Count, knots[^1] + interval); + knots.Insert(0, knots[0] - interval); + } + else + { + knots.Insert(knots.Count, knots[^1]); + knots.Insert(0, knots[0]); + } + } + } + + // get weights + // NOTE: autocad assigns unweighted points a value of -1, and will return an empty list in the spline's nurbsdata if no points are weighted + // NOTE: for closed periodic splines, autocad does not track last #degree points. Add the first #degree weights to the list if so. + List weights = new(); + for (int i = 0; i < target.NumControlPoints; i++) + { + double weight = target.WeightAt(i); + weights.Add(weight <= 0 ? 1 : weight); + } + + if (periodicClosed) + { + weights.AddRange(weights.GetRange(0, target.Degree)); + } + + // set nurbs curve info + var curve = new SOG.Curve + { + points = points.SelectMany(o => o.ToArray()).ToList(), + knots = knots, + weights = weights, + degree = target.Degree, + periodic = target.IsPeriodic, + rational = target.IsRational, + closed = periodicClosed || target.Closed, + length = length, + domain = domain, + bbox = _boxConverter.Convert(target.GeometricExtents), + units = _contextStack.Current.SpeckleUnits + }; + + // POC: get display value if this is a database-resident spline + // POC: if this is called by another converter that has created a spline, assumes the display value is set by that converter + if (target.Database is not null) + { + curve.displayValue = GetDisplayValue(target); + } + + return curve; + } + + // POC: we might have DisplayValue converter/mapper? + private SOG.Polyline GetDisplayValue(ADB.Spline spline) + { + ADB.Curve polySpline = spline.ToPolylineWithPrecision(10, false, false); + List verticesList = new(); + switch (polySpline) + { + case ADB.Polyline2d o: + verticesList = o.GetSubEntities( + ADB.OpenMode.ForRead, + _contextStack.Current.Document.TransactionManager.TopTransaction + ) + .Where(e => e.VertexType != ADB.Vertex2dType.SplineControlVertex) // POC: not validated yet! + .SelectMany(o => o.Position.ToArray()) + .ToList(); + + break; + case ADB.Polyline3d o: + verticesList = o.GetSubEntities( + ADB.OpenMode.ForRead, + _contextStack.Current.Document.TransactionManager.TopTransaction + ) + .Where(e => e.VertexType != ADB.Vertex3dType.ControlVertex) + .SelectMany(o => o.Position.ToArray()) + .ToList(); + break; + } + + return verticesList.ConvertToSpecklePolyline(_contextStack.Current.SpeckleUnits); + } +} diff --git a/DUI3-DX/Converters/Civil3d/Speckle.Converters.Civil3d2024.DependencyInjection/Civil3dConverterModule.cs b/DUI3-DX/Converters/Civil3d/Speckle.Converters.Civil3d2024.DependencyInjection/Civil3dConverterModule.cs index 290b5c5464..193648613b 100644 --- a/DUI3-DX/Converters/Civil3d/Speckle.Converters.Civil3d2024.DependencyInjection/Civil3dConverterModule.cs +++ b/DUI3-DX/Converters/Civil3d/Speckle.Converters.Civil3d2024.DependencyInjection/Civil3dConverterModule.cs @@ -19,5 +19,6 @@ public void Load(SpeckleContainerBuilder builder) builder.AddApplicationConverters(); builder.AddApplicationConverters(); builder.AddScoped, Civil3dConversionContextStack>(); + builder.AddScoped, AutocadConversionContextStack>(); } } diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/ContainerRegistration.cs b/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/ContainerRegistration.cs index f005d320b4..5da578819f 100644 --- a/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/ContainerRegistration.cs +++ b/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/ContainerRegistration.cs @@ -26,7 +26,6 @@ This will require consolidating across other connectors. builder.AddScoped(); - builder.RegisterRawConverters(); builder.InjectNamedTypes(); builder.InjectNamedTypes(); }