From 8f181f0ef8bb029009b3dfd6d588e153787f99a8 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Wed, 12 Jun 2024 09:32:02 +0100 Subject: [PATCH 01/25] Initial commit from converter-tests --- All.sln | 25 +- DUI3-DX.slnf | 1 + .../Speckle.Connectors.Revit2023.csproj | 1 - .../Bindings/BasicConnectorBindingRevit.cs | 2 +- .../Bindings/RevitBaseBinding.cs | 2 +- .../Bindings/RevitSendBinding.cs | 2 +- .../Bindings/SelectionBinding.cs | 2 +- .../DependencyInjection/ProxyMap.cs | 39 ++ .../RevitConnectorModule.cs | 3 + .../GlobalUsings.cs | 1 + .../HostApp/RevitDocumentStore.cs | 2 +- .../Operations/Send/RevitRootObjectBuilder.cs | 11 +- .../Plugin/RevitIdleManager.cs | 2 +- .../Plugin/RevitPlugin.cs | 2 +- .../Speckle.Connectors.RevitShared.projitems | 2 + .../RevitContext.cs | 4 +- .../RevitConversionContextStack.cs | 41 ++ .../RevitConverterModule.cs | 26 +- ...rters.Revit2023.DependencyInjection.csproj | 3 + .../LocationConversionToSpeckleTests.cs | 84 +++ .../Speckle.Converters.Revit2023.Tests.csproj | 28 + .../packages.lock.json | 581 ++++++++++++++++++ .../RevitVersionConversionHelper.cs | 19 - .../Speckle.Converters.Revit2023.csproj | 3 +- .../Extensions/CategoryExtensions.cs | 8 +- .../Extensions/DefinitionExtensions.cs | 8 +- .../Extensions/ElementExtensions.cs | 23 +- .../Extensions/ForgeTypeIdExtensions.cs | 14 +- .../Extensions/ParameterExtensions.cs | 13 +- .../GlobalUsings.cs | 4 +- .../Helpers/DisplayValueExtractor.cs | 108 ++-- .../Helpers/IRevitConversionContextStack.cs | 13 - .../Helpers/ISlopeArrowExtractor.cs | 10 - .../Helpers/ParameterObjectAssigner.cs | 33 +- .../Helpers/ParameterObjectBuilder.cs | 50 -- .../Helpers/ParameterValueExtractor.cs | 128 ++-- .../Helpers/RevitCategories.cs | 150 ----- .../Helpers/RevitCategoryInfo.cs | 65 -- .../Helpers/RevitConversionContextStack.cs | 28 - .../Helpers/SendSelection.cs | 17 - .../Helpers/SlopeArrowExtractor.cs | 69 ++- .../Helpers/ToSpeckleConvertedObjectsCache.cs | 25 - .../IReferencePointConverter.cs | 6 - .../IRevitVersionConversionHelper.cs | 6 - .../Raw/BeamConversionToSpeckle.cs | 36 +- .../Raw/BoundarySegmentConversionToSpeckle.cs | 13 +- .../Raw/BraceToSpeckleConverter.cs | 15 +- .../Raw/ColumnConversionToSpeckle.cs | 56 +- .../Raw/Geometry/ArcToSpeckleConverter.cs | 44 +- .../BoundingBoxXYZToSpeckleConverter.cs | 28 +- .../Raw/Geometry/CircleToSpeckleConverter.cs | 26 +- ...urveArrArrayToSpecklePolycurveConverter.cs | 27 +- .../Geometry/CurveArrayConversionToSpeckle.cs | 33 +- .../Raw/Geometry/CurveConversionToSpeckle.cs | 45 +- .../Raw/Geometry/EllipseToSpeckleConverter.cs | 34 +- .../HermiteSplineToSpeckleConverter.cs | 20 +- .../Raw/Geometry/LineConversionToSpeckle.cs | 23 +- .../MeshByMaterialDictionaryToSpeckle.cs | 43 +- .../Raw/Geometry/MeshConversionToSpeckle.cs | 39 +- .../Geometry/NurbsSplineToSpeckleConverter.cs | 29 +- .../Raw/Geometry/PlaneToSpeckleConverter.cs | 21 +- .../Geometry/PointCloudToSpeckleConverter.cs | 43 +- .../Raw/Geometry/PointConversionToSpeckle.cs | 13 +- .../Geometry/PolylineToSpeckleConverter.cs | 17 +- .../Raw/Geometry/SolidConversionToSpeckle.cs | 42 +- .../Raw/Geometry/VectorToSpeckleConverter.cs | 15 +- .../Raw/Geometry/XyzConversionToPoint.cs | 18 +- .../Raw/LevelConversionToSpeckle.cs | 13 +- .../Raw/LocationConversionToSpeckle.cs | 26 +- .../Raw/MaterialConversionToSpeckle.cs | 7 +- .../ModelCurveArrArrayConverterToSpeckle.cs | 30 + .../ModelCurveArrArrayToSpeckleConverter.cs | 28 - .../Raw/ModelCurveArrayToSpeckleConverter.cs | 31 +- .../Raw/ParameterConversionToSpeckle.cs | 27 +- .../Raw/RevitVersionConversionHelper.cs | 23 + .../RevitConstants.cs | 6 + .../RevitConversionSettings.cs | 19 - .../RevitRootToHostConverter.cs | 3 +- .../{ => Services}/ReferencePointConverter.cs | 77 ++- .../Services/RevitToSpeckleUnitConverter.cs | 27 +- .../Services/ScalingServiceToSpeckle.cs | 25 +- .../Speckle.Converters.RevitShared.projitems | 68 +- .../BaseTopLevelConverterToSpeckle.cs | 4 +- .../CeilingTopLevelConverterToSpeckle.cs | 29 +- .../DirectShapeTopLevelConverterToSpeckle.cs | 20 +- .../ElementTopLevelConverterToSpeckle.cs | 22 +- ...ExtrusionRoofToSpeckleTopLevelConverter.cs | 61 +- ...amilyInstanceTopLevelConverterToSpeckle.cs | 34 +- .../FloorTopLevelConverterToSpeckle.cs | 50 +- ...FootPrintRoofToSpeckleTopLevelConverter.cs | 55 +- .../HostedElementConversionToSpeckle.cs | 22 +- .../ModelCurveToSpeckleTopLevelConverter.cs | 21 +- ...fBaseToSpeckleTopLevelTopLevelConverter.cs | 33 +- .../RoomTopLevelConverterToSpeckle.cs | 41 +- .../TopographyTopLevelConverterToSpeckle.cs | 10 +- .../WallTopLevelConverterToSpeckle.cs | 79 +-- .../ISpeckleContainerContext.cs | 7 + .../SpeckleContainerBuilder.cs | 36 ++ .../ContainerRegistration.cs | 2 +- .../NamedTypeInjector.cs | 22 +- .../RawConversionRegisterer.cs | 23 +- .../ContextWrapper.cs | 2 +- .../ConversionContext.cs | 8 +- .../ConversionContextStack.cs | 9 +- .../Speckle.Converters.Common/IProxyMap.cs | 23 + .../IRootToSpeckleConverter.cs | 10 +- 106 files changed, 2002 insertions(+), 1375 deletions(-) create mode 100644 DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs create mode 100644 DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/GlobalUsings.cs rename DUI3-DX/Converters/Revit/{Speckle.Converters.RevitShared/Helpers => Speckle.Converters.Revit2023.DependencyInjection}/RevitContext.cs (78%) create mode 100644 DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConversionContextStack.cs create mode 100644 DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/LocationConversionToSpeckleTests.cs create mode 100644 DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/Speckle.Converters.Revit2023.Tests.csproj create mode 100644 DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/packages.lock.json delete mode 100644 DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/RevitVersionConversionHelper.cs delete mode 100644 DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/IRevitConversionContextStack.cs delete mode 100644 DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ISlopeArrowExtractor.cs delete mode 100644 DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterObjectBuilder.cs delete mode 100644 DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/RevitCategories.cs delete mode 100644 DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/RevitCategoryInfo.cs delete mode 100644 DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/RevitConversionContextStack.cs delete mode 100644 DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/SendSelection.cs delete mode 100644 DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ToSpeckleConvertedObjectsCache.cs delete mode 100644 DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/IReferencePointConverter.cs delete mode 100644 DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/IRevitVersionConversionHelper.cs create mode 100644 DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ModelCurveArrArrayConverterToSpeckle.cs delete mode 100644 DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ModelCurveArrArrayToSpeckleConverter.cs create mode 100644 DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/RevitVersionConversionHelper.cs create mode 100644 DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitConstants.cs delete mode 100644 DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitConversionSettings.cs rename DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/{ => Services}/ReferencePointConverter.cs (50%) create mode 100644 DUI3-DX/Sdk/Speckle.Autofac/DependencyInjection/ISpeckleContainerContext.cs create mode 100644 DUI3-DX/Sdk/Speckle.Converters.Common/IProxyMap.cs diff --git a/All.sln b/All.sln index d62369f249..ff3a26c713 100644 --- a/All.sln +++ b/All.sln @@ -347,6 +347,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution CodeMetricsConfig.txt = CodeMetricsConfig.txt Directory.Build.props = Directory.Build.props Directory.Build.targets = Directory.Build.targets + global.json = global.json EndProjectSection EndProject Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "ConnectorAutocadCivilShared", "ConnectorAutocadCivil\ConnectorAutocadCivil\ConnectorAutocadCivilShared.shproj", "{B47492D9-2EDA-4016-A930-7FA708C85C3D}" @@ -536,7 +537,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Workflows", "Workflows", "{ ProjectSection(SolutionItems) = preProject .github\workflows\ci.yml = .github\workflows\ci.yml .github\workflows\main.yml = .github\workflows\main.yml - .github\workflows\test.yml = .github\workflows\test.yml EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RevitSharedResources2025", "ConnectorRevit\RevitSharedResources2025\RevitSharedResources2025.csproj", "{7B02BACC-D9B6-4FFE-A450-7ECB5F71F209}" @@ -553,6 +553,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConnectorCivil2025", "Conne EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConverterCivil2025", "Objects\Converters\ConverterAutocadCivil\ConverterCivil2025\ConverterCivil2025.csproj", "{F06E4C37-4076-4272-9CA6-FB505E02CD31}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{B1324D25-C601-40F2-8AE2-6131F492B911}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Speckle.Converters.Revit2023.Tests", "DUI3-DX\Converters\Revit\Speckle.Converters.Revit2023.Tests\Speckle.Converters.Revit2023.Tests.csproj", "{AEC26A0B-25F3-4544-A9D6-A427BFF79250}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug Mac|Any CPU = Debug Mac|Any CPU @@ -2787,6 +2791,22 @@ Global {F06E4C37-4076-4272-9CA6-FB505E02CD31}.Release|Any CPU.Build.0 = Release|Any CPU {F06E4C37-4076-4272-9CA6-FB505E02CD31}.Release|x64.ActiveCfg = Release|Any CPU {F06E4C37-4076-4272-9CA6-FB505E02CD31}.Release|x64.Build.0 = Release|Any CPU + {AEC26A0B-25F3-4544-A9D6-A427BFF79250}.Debug Mac|Any CPU.ActiveCfg = Debug|Any CPU + {AEC26A0B-25F3-4544-A9D6-A427BFF79250}.Debug Mac|Any CPU.Build.0 = Debug|Any CPU + {AEC26A0B-25F3-4544-A9D6-A427BFF79250}.Debug Mac|x64.ActiveCfg = Debug|Any CPU + {AEC26A0B-25F3-4544-A9D6-A427BFF79250}.Debug Mac|x64.Build.0 = Debug|Any CPU + {AEC26A0B-25F3-4544-A9D6-A427BFF79250}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AEC26A0B-25F3-4544-A9D6-A427BFF79250}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AEC26A0B-25F3-4544-A9D6-A427BFF79250}.Debug|x64.ActiveCfg = Debug|Any CPU + {AEC26A0B-25F3-4544-A9D6-A427BFF79250}.Debug|x64.Build.0 = Debug|Any CPU + {AEC26A0B-25F3-4544-A9D6-A427BFF79250}.Release Mac|Any CPU.ActiveCfg = Debug|Any CPU + {AEC26A0B-25F3-4544-A9D6-A427BFF79250}.Release Mac|Any CPU.Build.0 = Debug|Any CPU + {AEC26A0B-25F3-4544-A9D6-A427BFF79250}.Release Mac|x64.ActiveCfg = Debug|Any CPU + {AEC26A0B-25F3-4544-A9D6-A427BFF79250}.Release Mac|x64.Build.0 = Debug|Any CPU + {AEC26A0B-25F3-4544-A9D6-A427BFF79250}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AEC26A0B-25F3-4544-A9D6-A427BFF79250}.Release|Any CPU.Build.0 = Release|Any CPU + {AEC26A0B-25F3-4544-A9D6-A427BFF79250}.Release|x64.ActiveCfg = Release|Any CPU + {AEC26A0B-25F3-4544-A9D6-A427BFF79250}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -2964,7 +2984,6 @@ Global {2E00592E-558D-492D-88F9-3ECEE4C0C7DA} = {9DB74760-01DE-4AC1-A81B-BC7784351D22} {01F98733-7352-47AD-A594-537D979DE3DE} = {4838C66E-8677-4FBD-9609-25376042E981} {DC570FFF-6FE5-47BD-8BC1-B471A6067786} = {4838C66E-8677-4FBD-9609-25376042E981} - {E1C43415-3200-45F4-8BF9-A4DD7D7F2ED6} = {D92751C8-1039-4005-90B2-913E55E0B8BD} {83EAD6F0-3CB3-456A-AD81-072127D0DE0E} = {D92751C8-1039-4005-90B2-913E55E0B8BD} {26391930-F86F-47E0-A5F6-B89919E38CE1} = {D92751C8-1039-4005-90B2-913E55E0B8BD} {D81C0B87-F0C1-4297-A147-02F001FB7E1E} = {FD4D6594-D81E-456F-8F2E-35B09E04A755} @@ -2998,6 +3017,8 @@ Global {829688CD-CECE-4F6C-A5A0-032BB39CD9E0} = {BE521908-7944-46F3-98BF-B47D34509934} {70DEAA13-6DC8-44A0-B287-9E806A8054F1} = {890F3257-FCC2-4ED8-9180-22B3641B494C} {F06E4C37-4076-4272-9CA6-FB505E02CD31} = {BE521908-7944-46F3-98BF-B47D34509934} + {E1C43415-3200-45F4-8BF9-A4DD7D7F2ED6} = {D92751C8-1039-4005-90B2-913E55E0B8BD} + {AEC26A0B-25F3-4544-A9D6-A427BFF79250} = {D92751C8-1039-4005-90B2-913E55E0B8BD} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {1D43D91B-4F01-4A78-8250-CC6F9BD93A14} diff --git a/DUI3-DX.slnf b/DUI3-DX.slnf index bd01603c29..80e74b0b65 100644 --- a/DUI3-DX.slnf +++ b/DUI3-DX.slnf @@ -20,6 +20,7 @@ "DUI3-DX\\Converters\\Autocad\\Speckle.Converters.Autocad2023\\Speckle.Converters.Autocad2023.csproj", "DUI3-DX\\Converters\\Autocad\\Speckle.Converters.AutocadShared\\Speckle.Converters.AutocadShared.shproj", "DUI3-DX\\Converters\\Revit\\Speckle.Converters.Revit2023.DependencyInjection\\Speckle.Converters.Revit2023.DependencyInjection.csproj", + "DUI3-DX\\Converters\\Revit\\Speckle.Converters.Revit2023.Tests\\Speckle.Converters.Revit2023.Tests.csproj", "DUI3-DX\\Converters\\Revit\\Speckle.Converters.Revit2023\\Speckle.Converters.Revit2023.csproj", "DUI3-DX\\Converters\\Revit\\Speckle.Converters.RevitShared\\Speckle.Converters.RevitShared.shproj", "DUI3-DX\\Converters\\Rhino\\Speckle.Converters.Rhino7.DependencyInjection\\Speckle.Converters.Rhino7.DependencyInjection.csproj", diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.Revit2023/Speckle.Connectors.Revit2023.csproj b/DUI3-DX/Connectors/Revit/Speckle.Connectors.Revit2023/Speckle.Connectors.Revit2023.csproj index a24cfec381..be91998c4f 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.Revit2023/Speckle.Connectors.Revit2023.csproj +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.Revit2023/Speckle.Connectors.Revit2023.csproj @@ -31,7 +31,6 @@ - diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/BasicConnectorBindingRevit.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/BasicConnectorBindingRevit.cs index 3aa6be233f..697f29a5bd 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/BasicConnectorBindingRevit.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/BasicConnectorBindingRevit.cs @@ -7,7 +7,7 @@ using Speckle.Connectors.DUI.Models.Card; using Speckle.Connectors.Revit.Plugin; using Speckle.Connectors.Utils; -using Speckle.Converters.RevitShared.Helpers; +using Speckle.Converters.Revit2023.DependencyInjection; using Speckle.Core.Logging; namespace Speckle.Connectors.DUI.Bindings; diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitBaseBinding.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitBaseBinding.cs index 1a18f5ac53..b8fdd6424b 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitBaseBinding.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitBaseBinding.cs @@ -1,7 +1,7 @@ using Speckle.Connectors.DUI.Bindings; using Speckle.Connectors.DUI.Bridge; using Speckle.Connectors.DUI.Models; -using Speckle.Converters.RevitShared.Helpers; +using Speckle.Converters.Revit2023.DependencyInjection; namespace Speckle.Connectors.Revit.Bindings; diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitSendBinding.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitSendBinding.cs index bbfa2a815b..fd7bc3c8e0 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitSendBinding.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitSendBinding.cs @@ -4,7 +4,6 @@ using Speckle.Connectors.DUI.Bridge; using Speckle.Connectors.Revit.Plugin; using Speckle.Connectors.Utils; -using Speckle.Converters.RevitShared.Helpers; using Speckle.Connectors.DUI.Models.Card; using Speckle.Connectors.DUI.Bindings; using Speckle.Autofac.DependencyInjection; @@ -12,6 +11,7 @@ using Speckle.Connectors.DUI.Models; using Speckle.Connectors.Utils.Caching; using Speckle.Connectors.Utils.Operations; +using Speckle.Converters.Revit2023.DependencyInjection; namespace Speckle.Connectors.Revit.Bindings; diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/SelectionBinding.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/SelectionBinding.cs index 9cbf1bcc15..d7a4a1fc8b 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/SelectionBinding.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/SelectionBinding.cs @@ -3,7 +3,7 @@ using Speckle.Connectors.DUI.Models; using Speckle.Connectors.Revit.Plugin; using Speckle.Converters.Common; -using Speckle.Converters.RevitShared.Helpers; +using Speckle.Converters.Revit2023.DependencyInjection; namespace Speckle.Connectors.Revit.Bindings; diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs new file mode 100644 index 0000000000..b54b9850ee --- /dev/null +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs @@ -0,0 +1,39 @@ +using System.Collections.Concurrent; +using System.Diagnostics.CodeAnalysis; +using Speckle.Converters.Common; +using Speckle.Revit.Api; +using Speckle.Revit.Interfaces; + +namespace Speckle.Connectors.Revit2023.Converters; + +[SuppressMessage("Performance", "CA1810:Initialize reference type static fields inline")] +public class ProxyMap : IProxyMap +{ + private static readonly ConcurrentDictionary s_typeMaps = new(); + private static readonly ConcurrentDictionary> s_proxyFactory = new(); + + static ProxyMap() + { + Add(x => new ElementProxy(x)); + Add(x => new FamilyInstanceProxy(x)); + } + + private static void Add(Func f) + where T : class + where TProxy : notnull + { + s_typeMaps.TryAdd(typeof(T), typeof(TProxy)); + s_proxyFactory.TryAdd(typeof(TProxy), w => f((T)w)); + } + + public Type? GetMappedType(Type type) + { + if (s_typeMaps.TryGetValue(type, out var t)) + { + return t; + } + return null; + } + + public object CreateProxy(Type type, object toWrap) => s_proxyFactory[type](toWrap); +} diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/RevitConnectorModule.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/RevitConnectorModule.cs index ec1bcb5566..b50683124c 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/RevitConnectorModule.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/RevitConnectorModule.cs @@ -10,10 +10,12 @@ using Speckle.Connectors.Revit.HostApp; using Speckle.Connectors.Revit.Operations.Send; using Speckle.Connectors.Revit.Plugin; +using Speckle.Connectors.Revit2023.Converters; using Speckle.Connectors.Utils; using Speckle.Connectors.Utils.Builders; using Speckle.Connectors.Utils.Caching; using Speckle.Connectors.Utils.Operations; +using Speckle.Converters.Common; namespace Speckle.Connectors.Revit.DependencyInjection; @@ -64,5 +66,6 @@ public void Load(SpeckleContainerBuilder builder) // register send conversion cache builder.AddSingleton(); + builder.AddSingleton(); } } diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/GlobalUsings.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/GlobalUsings.cs new file mode 100644 index 0000000000..dec8635815 --- /dev/null +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/GlobalUsings.cs @@ -0,0 +1 @@ +global using DB = Autodesk.Revit.DB; diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/HostApp/RevitDocumentStore.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/HostApp/RevitDocumentStore.cs index 6d31480be2..478c46b1b4 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/HostApp/RevitDocumentStore.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/HostApp/RevitDocumentStore.cs @@ -7,7 +7,7 @@ using Speckle.Connectors.DUI.Models; using Speckle.Connectors.Revit.Plugin; using Speckle.Connectors.Utils; -using Speckle.Converters.RevitShared.Helpers; +using Speckle.Converters.Revit2023.DependencyInjection; using Speckle.Core.Logging; using Speckle.Newtonsoft.Json; diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Operations/Send/RevitRootObjectBuilder.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Operations/Send/RevitRootObjectBuilder.cs index b22ef0a3ca..63c2144e76 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Operations/Send/RevitRootObjectBuilder.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Operations/Send/RevitRootObjectBuilder.cs @@ -3,12 +3,13 @@ using Speckle.Core.Models; using Autodesk.Revit.DB; using Speckle.Connectors.DUI.Exceptions; -using Speckle.Converters.RevitShared.Helpers; using Speckle.Connectors.Utils.Builders; using Speckle.Connectors.Utils.Caching; using Speckle.Connectors.Utils.Conversion; using Speckle.Connectors.Utils.Operations; using Speckle.Core.Logging; +using Speckle.Revit.Api; +using Speckle.Revit.Interfaces; namespace Speckle.Connectors.Revit.Operations.Send; @@ -16,14 +17,14 @@ public class RevitRootObjectBuilder : IRootObjectBuilder { // POC: SendSelection and RevitConversionContextStack should be interfaces, former needs interfaces private readonly IRootToSpeckleConverter _converter; - private readonly IRevitConversionContextStack _contextStack; + private readonly IConversionContextStack _contextStack; private readonly Dictionary _collectionCache; private readonly Collection _rootObject; private readonly ISendConversionCache _sendConversionCache; public RevitRootObjectBuilder( IRootToSpeckleConverter converter, - IRevitConversionContextStack contextStack, + IConversionContextStack contextStack, ISendConversionCache sendConversionCache ) { @@ -45,7 +46,7 @@ public RootObjectBuilderResult Build( CancellationToken ct = default ) { - var doc = _contextStack.Current.Document; + var doc = ((DocumentProxy)_contextStack.Current.Document)._Instance; if (doc.IsFamilyDocument) { @@ -56,7 +57,7 @@ public RootObjectBuilderResult Build( foreach (var id in objects) { - var el = _contextStack.Current.Document.GetElement(id); + var el = doc.GetElement(id); if (el != null) { revitElements.Add(el); diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitIdleManager.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitIdleManager.cs index 79bd4408a6..facf64131b 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitIdleManager.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitIdleManager.cs @@ -1,7 +1,7 @@ using System.Collections.Concurrent; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Events; -using Speckle.Converters.RevitShared.Helpers; +using Speckle.Converters.Revit2023.DependencyInjection; namespace Speckle.Connectors.Revit.Plugin; diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitPlugin.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitPlugin.cs index 13d3500b2f..e38d4cc161 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitPlugin.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitPlugin.cs @@ -5,12 +5,12 @@ using Speckle.Connectors.DUI.Bridge; using Speckle.Connectors.DUI.Bindings; using System.Diagnostics; -using Speckle.Converters.RevitShared.Helpers; using Speckle.Core.Logging; using System.Reflection; using System.Windows.Media.Imaging; using System.Windows.Media; using System.IO; +using Speckle.Converters.Revit2023.DependencyInjection; namespace Speckle.Connectors.Revit.Plugin; diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Speckle.Connectors.RevitShared.projitems b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Speckle.Connectors.RevitShared.projitems index 8a671aefc9..a17b3594c9 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Speckle.Connectors.RevitShared.projitems +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Speckle.Connectors.RevitShared.projitems @@ -21,6 +21,8 @@ + + diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/RevitContext.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitContext.cs similarity index 78% rename from DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/RevitContext.cs rename to DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitContext.cs index 59c3892a75..c6f90fadd0 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/RevitContext.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitContext.cs @@ -1,6 +1,6 @@ -using Autodesk.Revit.UI; +using Autodesk.Revit.UI; -namespace Speckle.Converters.RevitShared.Helpers; +namespace Speckle.Converters.Revit2023.DependencyInjection; public class RevitContext { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConversionContextStack.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConversionContextStack.cs new file mode 100644 index 0000000000..02ca3b09e2 --- /dev/null +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConversionContextStack.cs @@ -0,0 +1,41 @@ +using Autodesk.Revit.DB; +using Speckle.Converters.Common; +using Speckle.Revit.Api; +using Speckle.Revit.Interfaces; + +namespace Speckle.Converters.Revit2023.DependencyInjection; + +[System.Diagnostics.CodeAnalysis.SuppressMessage( + "Naming", + "CA1711:Identifiers should not have incorrect suffix", + Justification = "See base class justification" +)] +// POC: so this should *probably* be Document and NOT UI.UIDocument, the former is Conversion centric +// and the latter is more for connector +public class RevitConversionContextStack + : ConversionContextStack, + IConversionContextStack +{ + public RevitConversionContextStack(RevitContext context, IHostToSpeckleUnitConverter unitConverter) + : base( + // POC: we probably should not get here without a valid document + // so should this perpetuate or do we assume this is valid? + // relting on the context.UIApplication?.ActiveUIDocument is not right + // this should be some IActiveDocument I suspect? + new DocumentProxy( + context.UIApplication?.ActiveUIDocument?.Document + ?? throw new SpeckleConversionException("Active UI document could not be determined") + ), + new ForgeTypeIdProxy( + context.UIApplication.ActiveUIDocument.Document.GetUnits().GetFormatOptions(SpecTypeId.Length).GetUnitTypeId() + ), + unitConverter + ) { } + + IConversionContext IConversionContextStack.Current => + new ConversionContext(base.Current.Document, base.Current.SpeckleUnits); + + ContextWrapper IConversionContextStack.Push( + string speckleUnit + ) => throw new NotImplementedException(); +} diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs index d4e6d197ac..e8bec81475 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs @@ -1,11 +1,11 @@ -using Autodesk.Revit.DB; using Speckle.Autofac.DependencyInjection; using Speckle.Converters.Common; using Speckle.Converters.Common.DependencyInjection; -using Speckle.Converters.RevitShared; +using Speckle.Converters.Revit2023.ToSpeckle; using Speckle.Converters.RevitShared.Helpers; using Speckle.Converters.RevitShared.Services; -using Speckle.Converters.RevitShared.ToSpeckle; +using Speckle.Revit.Api; +using Speckle.Revit.Interfaces; namespace Speckle.Converters.Revit2023.DependencyInjection; @@ -13,26 +13,28 @@ public class RevitConverterModule : ISpeckleModule { public void Load(SpeckleContainerBuilder builder) { - builder.AddConverterCommon(); + builder.AddConverterCommon(); builder.AddSingleton(new RevitContext()); // POC: do we need ToSpeckleScalingService as is, do we need to interface it out? - builder.AddScoped(); + builder.AddScoped(); // POC: the concrete type can come out if we remove all the reference to it - builder.AddScoped(); + builder.AddScoped, RevitConversionContextStack>(); builder.AddScoped(); - builder.AddScoped(); + builder.AddScoped(); builder.AddScoped(); - builder.AddScoped(); - builder.AddScoped(); - builder.AddScoped(); - builder.AddScoped(); + builder.AddScoped(); + builder.AddScoped(); + builder.AddScoped(); + builder.AddScoped(); builder.AddScoped(); builder.AddScoped(); - builder.AddScoped(); + //builder.AddScoped(); + + builder.ScanAssemblyOfType(); } } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/Speckle.Converters.Revit2023.DependencyInjection.csproj b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/Speckle.Converters.Revit2023.DependencyInjection.csproj index 704fef95ed..5e73505906 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/Speckle.Converters.Revit2023.DependencyInjection.csproj +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/Speckle.Converters.Revit2023.DependencyInjection.csproj @@ -5,6 +5,9 @@ x64 + + + diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/LocationConversionToSpeckleTests.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/LocationConversionToSpeckleTests.cs new file mode 100644 index 0000000000..e4fced21cd --- /dev/null +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/LocationConversionToSpeckleTests.cs @@ -0,0 +1,84 @@ +using Moq; +using NUnit.Framework; +using Objects; +using Speckle.Converters.Common; +using Speckle.Converters.Common.Objects; +using Shouldly; +using Speckle.Converters.RevitShared.Services; +using Speckle.Revit.Interfaces; + +namespace Speckle.Converters.Revit2023.Tests; + +public class ModelCurveArrayToSpeckleConverterTests +{ + private readonly MockRepository _repository = new(MockBehavior.Strict); + + private readonly Mock> _revitConversionContextStack; + private readonly Mock _scalingServiceToSpeckle; + private readonly Mock> _curveConverter; + + public ModelCurveArrayToSpeckleConverterTests() + { + _revitConversionContextStack = _repository.Create>(); + _scalingServiceToSpeckle = _repository.Create(); + _curveConverter = _repository.Create>(); + } + + [TearDown] + public void Verify() => _repository.VerifyAll(); + + [Test] + public void Convert_Empty() + { + var sut = new ModelCurveArrayToSpeckleConverter( + _revitConversionContextStack.Object, + _scalingServiceToSpeckle.Object, + _curveConverter.Object + ); + Assert.Throws(() => sut.Convert(new List())); + } + + [Test] + public void Convert() + { + var endpoint1 = _repository.Create(); + var geometry1 = _repository.Create(); + var curve1 = _repository.Create(); + curve1.Setup(x => x.GeometryCurve).Returns(geometry1.Object); + geometry1.Setup(x => x.Length).Returns(2); + geometry1.Setup(x => x.GetEndPoint(0)).Returns(endpoint1.Object); + + var endpoint2 = _repository.Create(); + var geometry2 = _repository.Create(); + var curve2 = _repository.Create(); + curve2.Setup(x => x.GeometryCurve).Returns(geometry2.Object); + geometry2.Setup(x => x.Length).Returns(3); + geometry2.Setup(x => x.GetEndPoint(1)).Returns(endpoint2.Object); + + var context = _repository.Create>(); + _revitConversionContextStack.Setup(x => x.Current).Returns(context.Object); + + var units = "units"; + context.Setup(x => x.SpeckleUnits).Returns(units); + + var scaleLength = 2.2; + _scalingServiceToSpeckle.Setup(x => x.ScaleLength(2 + 3)).Returns(scaleLength); + + endpoint1.Setup(x => x.DistanceTo(endpoint2.Object)).Returns(4.4); + + _curveConverter.Setup(x => x.Convert(geometry1.Object)).Returns(_repository.Create().Object); + _curveConverter.Setup(x => x.Convert(geometry2.Object)).Returns(_repository.Create().Object); + + var sut = new ModelCurveArrayToSpeckleConverter( + _revitConversionContextStack.Object, + _scalingServiceToSpeckle.Object, + _curveConverter.Object + ); + var polycurve = sut.Convert(new List() { curve1.Object, curve2.Object }); + + polycurve.units.ShouldBe(units); + polycurve.closed.ShouldBeFalse(); + polycurve.length.ShouldBe(scaleLength); + polycurve.segments.Count.ShouldBe(2); + } +} diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/Speckle.Converters.Revit2023.Tests.csproj b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/Speckle.Converters.Revit2023.Tests.csproj new file mode 100644 index 0000000000..0d58315a39 --- /dev/null +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/Speckle.Converters.Revit2023.Tests.csproj @@ -0,0 +1,28 @@ + + + + net48 + x64 + false + true + + + + + + + + + + + + + + + + + + + + + diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/packages.lock.json b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/packages.lock.json new file mode 100644 index 0000000000..978bc4bd9c --- /dev/null +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/packages.lock.json @@ -0,0 +1,581 @@ +{ + "version": 1, + "dependencies": { + ".NETFramework,Version=v4.8": { + "coverlet.collector": { + "type": "Direct", + "requested": "[6.0.2, )", + "resolved": "6.0.2", + "contentHash": "bJShQ6uWRTQ100ZeyiMqcFlhP7WJ+bCuabUs885dJiBEzMsJMSFr7BOyeCw4rgvQokteGi5rKQTlkhfQPUXg2A==" + }, + "Microsoft.NET.Test.Sdk": { + "type": "Direct", + "requested": "[17.10.0, )", + "resolved": "17.10.0", + "contentHash": "0/2HeACkaHEYU3wc83YlcD2Fi4LMtECJjqrtvw0lPi9DCEa35zSPt1j4fuvM8NagjDqJuh1Ja35WcRtn1Um6/A==", + "dependencies": { + "Microsoft.CodeCoverage": "17.10.0" + } + }, + "Moq": { + "type": "Direct", + "requested": "[4.20.70, )", + "resolved": "4.20.70", + "contentHash": "4rNnAwdpXJBuxqrOCzCyICXHSImOTRktCgCWXWykuF1qwoIsVvEnR7PjbMk/eLOxWvhmj5Kwt+kDV3RGUYcNwg==", + "dependencies": { + "Castle.Core": "5.1.1", + "System.Threading.Tasks.Extensions": "4.5.4" + } + }, + "NUnit": { + "type": "Direct", + "requested": "[4.1.0, )", + "resolved": "4.1.0", + "contentHash": "MT/DpAhjtiytzhTgTqIhBuWx4y26PKfDepYUHUM+5uv4TsryHC2jwFo5e6NhWkApCm/G6kZ80dRjdJFuAxq3rg==", + "dependencies": { + "System.Threading.Tasks.Extensions": "4.5.4" + } + }, + "NUnit.Analyzers": { + "type": "Direct", + "requested": "[4.2.0, )", + "resolved": "4.2.0", + "contentHash": "4fJojPkzdoa4nB2+p6U+fITvPnVvwWSnsmiJ/Dl30xqiL3oxNbYvfeSLVd91hOmEjoUqSwN3Z7j1aFedjqWbUA==" + }, + "PolySharp": { + "type": "Direct", + "requested": "[1.14.1, )", + "resolved": "1.14.1", + "contentHash": "mOOmFYwad3MIOL14VCjj02LljyF1GNw1wP0YVlxtcPvqdxjGGMNdNJJxHptlry3MOd8b40Flm8RPOM8JOlN2sQ==" + }, + "Shouldly": { + "type": "Direct", + "requested": "[4.2.1, )", + "resolved": "4.2.1", + "contentHash": "dKAKiSuhLKqD2TXwLKtqNg1nwzJcIKOOMncZjk9LYe4W+h+SCftpWdxwR79YZUIHMH+3Vu9s0s0UHNrgICLwRQ==", + "dependencies": { + "DiffEngine": "11.3.0", + "EmptyFiles": "4.4.0", + "Microsoft.CSharp": "4.7.0" + } + }, + "Speckle.InterfaceGenerator": { + "type": "Direct", + "requested": "[0.9.5, )", + "resolved": "0.9.5", + "contentHash": "oU/L7pN1R7q8KkbrpQ3WJnHirPHqn+9DEA7asOcUiggV5dzVg1A/VYs7GOSusD24njxXh03tE3a2oTLOjt3cVg==" + }, + "Speckle.Revit2023.Interfaces": { + "type": "Direct", + "requested": "[0.1.1-preview.0.16, )", + "resolved": "0.1.1-preview.0.16", + "contentHash": "AsKpt0cQ6OdhL31DGgfyp2DhLSJxHrY7pQscrrvWHVTl+l/lrgZgrnCZIqUCVMnhv6NvXmGNm7G7zPOpsKDCnw==" + }, + "Castle.Core": { + "type": "Transitive", + "resolved": "5.1.1", + "contentHash": "rpYtIczkzGpf+EkZgDr9CClTdemhsrwA/W5hMoPjLkRFnXzH44zDLoovXeKtmxb1ykXK9aJVODSpiJml8CTw2g==" + }, + "DiffEngine": { + "type": "Transitive", + "resolved": "11.3.0", + "contentHash": "k0ZgZqd09jLZQjR8FyQbSQE86Q7QZnjEzq1LPHtj1R2AoWO8sjV5x+jlSisL7NZAbUOI4y+7Bog8gkr9WIRBGw==", + "dependencies": { + "EmptyFiles": "4.4.0", + "System.Management": "6.0.1" + } + }, + "EmptyFiles": { + "type": "Transitive", + "resolved": "4.4.0", + "contentHash": "gwJEfIGS7FhykvtZoscwXj/XwW+mJY6UbAZk+qtLKFUGWC95kfKXnj8VkxsZQnWBxJemM/q664rGLN5nf+OHZw==", + "dependencies": { + "System.Memory": "4.5.5", + "System.ValueTuple": "4.5.0" + } + }, + "GraphQL.Client": { + "type": "Transitive", + "resolved": "6.0.0", + "contentHash": "8yPNBbuVBpTptivyAlak4GZvbwbUcjeQTL4vN1HKHRuOykZ4r7l5fcLS6vpyPyLn0x8FsL31xbOIKyxbmR9rbA==", + "dependencies": { + "GraphQL.Client.Abstractions": "6.0.0", + "GraphQL.Client.Abstractions.Websocket": "6.0.0", + "System.Net.WebSockets.Client.Managed": "1.0.22", + "System.Reactive": "5.0.0" + } + }, + "GraphQL.Client.Abstractions": { + "type": "Transitive", + "resolved": "6.0.0", + "contentHash": "h7uzWFORHZ+CCjwr/ThAyXMr0DPpzEANDa4Uo54wqCQ+j7qUKwqYTgOrb1W40sqbvNaZm9v/X7It31SUw0maHA==", + "dependencies": { + "GraphQL.Primitives": "6.0.0" + } + }, + "GraphQL.Client.Abstractions.Websocket": { + "type": "Transitive", + "resolved": "6.0.0", + "contentHash": "Nr9bPf8gIOvLuXpqEpqr9z9jslYFJOvd0feHth3/kPqeR3uMbjF5pjiwh4jxyMcxHdr8Pb6QiXkV3hsSyt0v7A==", + "dependencies": { + "GraphQL.Client.Abstractions": "6.0.0" + } + }, + "GraphQL.Primitives": { + "type": "Transitive", + "resolved": "6.0.0", + "contentHash": "yg72rrYDapfsIUrul7aF6wwNnTJBOFvuA9VdDTQpPa8AlAriHbufeXYLBcodKjfUdkCnaiggX1U/nEP08Zb5GA==" + }, + "Microsoft.Bcl.AsyncInterfaces": { + "type": "Transitive", + "resolved": "7.0.0", + "contentHash": "3aeMZ1N0lJoSyzqiP03hqemtb1BijhsJADdobn/4nsMJ8V1H+CrpuduUe4hlRdx+ikBQju1VGjMD1GJ3Sk05Eg==", + "dependencies": { + "System.Threading.Tasks.Extensions": "4.5.4" + } + }, + "Microsoft.CodeCoverage": { + "type": "Transitive", + "resolved": "17.10.0", + "contentHash": "yC7oSlnR54XO5kOuHlVOKtxomNNN1BWXX8lK1G2jaPXT9sUok7kCOoA4Pgs0qyFaCtMrNsprztYMeoEGqCm4uA==" + }, + "Microsoft.CSharp": { + "type": "Transitive", + "resolved": "4.7.0", + "contentHash": "pTj+D3uJWyN3My70i2Hqo+OXixq3Os2D1nJ2x92FFo6sk8fYS1m1WLNTs0Dc1uPaViH0YvEEwvzddQ7y4rhXmA==" + }, + "Microsoft.Data.Sqlite": { + "type": "Transitive", + "resolved": "7.0.5", + "contentHash": "KGxbPeWsQMnmQy43DSBxAFtHz3l2JX8EWBSGUCvT3CuZ8KsuzbkqMIJMDOxWtG8eZSoCDI04aiVQjWuuV8HmSw==", + "dependencies": { + "Microsoft.Data.Sqlite.Core": "7.0.5", + "SQLitePCLRaw.bundle_e_sqlite3": "2.1.4" + } + }, + "Microsoft.Data.Sqlite.Core": { + "type": "Transitive", + "resolved": "7.0.5", + "contentHash": "FTerRmQPqHrCrnoUzhBu+E+1DNGwyrAMLqHkAqOOOu5pGfyMOj8qQUBxI/gDtWtG11p49UxSfWmBzRNlwZqfUg==", + "dependencies": { + "SQLitePCLRaw.core": "2.1.4" + } + }, + "Microsoft.Extensions.DependencyInjection": { + "type": "Transitive", + "resolved": "7.0.0", + "contentHash": "elNeOmkeX3eDVG6pYVeV82p29hr+UKDaBhrZyWvWLw/EVZSYEkZlQdkp0V39k/Xehs2Qa0mvoCvkVj3eQxNQ1Q==", + "dependencies": { + "Microsoft.Bcl.AsyncInterfaces": "7.0.0", + "Microsoft.Extensions.DependencyInjection.Abstractions": "7.0.0", + "System.Threading.Tasks.Extensions": "4.5.4" + } + }, + "Microsoft.Extensions.DependencyInjection.Abstractions": { + "type": "Transitive", + "resolved": "7.0.0", + "contentHash": "h3j/QfmFN4S0w4C2A6X7arXij/M/OVw3uQHSOFxnND4DyAzO1F9eMX7Eti7lU/OkSthEE0WzRsfT/Dmx86jzCw==", + "dependencies": { + "Microsoft.Bcl.AsyncInterfaces": "7.0.0", + "System.Threading.Tasks.Extensions": "4.5.4" + } + }, + "Microsoft.Extensions.Logging": { + "type": "Transitive", + "resolved": "7.0.0", + "contentHash": "Nw2muoNrOG5U5qa2ZekXwudUn2BJcD41e65zwmDHb1fQegTX66UokLWZkJRpqSSHXDOWZ5V0iqhbxOEky91atA==", + "dependencies": { + "Microsoft.Bcl.AsyncInterfaces": "7.0.0", + "Microsoft.Extensions.DependencyInjection": "7.0.0", + "Microsoft.Extensions.DependencyInjection.Abstractions": "7.0.0", + "Microsoft.Extensions.Logging.Abstractions": "7.0.0", + "Microsoft.Extensions.Options": "7.0.0", + "System.Diagnostics.DiagnosticSource": "7.0.0", + "System.ValueTuple": "4.5.0" + } + }, + "Microsoft.Extensions.Logging.Abstractions": { + "type": "Transitive", + "resolved": "7.0.0", + "contentHash": "kmn78+LPVMOWeITUjIlfxUPDsI0R6G0RkeAMBmQxAJ7vBJn4q2dTva7pWi65ceN5vPGjJ9q/Uae2WKgvfktJAw==", + "dependencies": { + "System.Buffers": "4.5.1", + "System.Memory": "4.5.5" + } + }, + "Microsoft.Extensions.Options": { + "type": "Transitive", + "resolved": "7.0.0", + "contentHash": "lP1yBnTTU42cKpMozuafbvNtQ7QcBjr/CcK3bYOGEMH55Fjt+iecXjT6chR7vbgCMqy3PG3aNQSZgo/EuY/9qQ==", + "dependencies": { + "Microsoft.Extensions.DependencyInjection.Abstractions": "7.0.0", + "Microsoft.Extensions.Primitives": "7.0.0" + } + }, + "Microsoft.Extensions.Primitives": { + "type": "Transitive", + "resolved": "7.0.0", + "contentHash": "um1KU5kxcRp3CNuI8o/GrZtD4AIOXDk+RLsytjZ9QPok3ttLUelLKpilVPuaFT3TFjOhSibUAso0odbOaCDj3Q==", + "dependencies": { + "System.Memory": "4.5.5", + "System.Runtime.CompilerServices.Unsafe": "6.0.0" + } + }, + "Polly": { + "type": "Transitive", + "resolved": "7.2.3", + "contentHash": "DeCY0OFbNdNxsjntr1gTXHJ5pKUwYzp04Er2LLeN3g6pWhffsGuKVfMBLe1lw7x76HrPkLxKEFxBlpRxS2nDEQ==" + }, + "Polly.Contrib.WaitAndRetry": { + "type": "Transitive", + "resolved": "1.1.1", + "contentHash": "1MUQLiSo4KDkQe6nzQRhIU05lm9jlexX5BVsbuw0SL82ynZ+GzAHQxJVDPVBboxV37Po3SG077aX8DuSy8TkaA==" + }, + "Polly.Extensions.Http": { + "type": "Transitive", + "resolved": "3.0.0", + "contentHash": "drrG+hB3pYFY7w1c3BD+lSGYvH2oIclH8GRSehgfyP5kjnFnHKQuuBhuHLv+PWyFuaTDyk/vfRpnxOzd11+J8g==", + "dependencies": { + "Polly": "7.1.0" + } + }, + "Sentry": { + "type": "Transitive", + "resolved": "3.33.0", + "contentHash": "8vbD2o6IR2wrRrkSiRbnodWGWUOqIlwYtzpjvPNOb5raJdOf+zxMwfS8f6nx9bmrTTfDj7KrCB8C/5OuicAc8A==", + "dependencies": { + "System.Reflection.Metadata": "5.0.0", + "System.Runtime.InteropServices.RuntimeInformation": "4.3.0", + "System.Text.Json": "5.0.2" + } + }, + "Sentry.Serilog": { + "type": "Transitive", + "resolved": "3.33.0", + "contentHash": "V8BU7QGWg2qLYfNPqtuTBhC1opysny5l+Ifp6J6PhOeAxU0FssR7nYfbJVetrnLIoh2rd3DlJ6hHYYQosQYcUQ==", + "dependencies": { + "Sentry": "3.33.0", + "Serilog": "2.7.1" + } + }, + "Serilog": { + "type": "Transitive", + "resolved": "2.12.0", + "contentHash": "xaiJLIdu6rYMKfQMYUZgTy8YK7SMZjB4Yk50C/u//Z4OsvxkUfSPJy4nknfvwAC34yr13q7kcyh4grbwhSxyZg==" + }, + "Serilog.Enrichers.ClientInfo": { + "type": "Transitive", + "resolved": "1.3.0", + "contentHash": "mTc7PM+wC9Hr7LWSwqt5mmnlAr7RJs+eTb3PGPRhwdOackk95MkhUZognuxXEdlW19HAFNmEBTSBY5DfLwM8jQ==", + "dependencies": { + "Serilog": "2.4.0" + } + }, + "Serilog.Enrichers.GlobalLogContext": { + "type": "Transitive", + "resolved": "3.0.0", + "contentHash": "IIZcj5mAUVhIl/NTA+YI2KC+sPDzcwvs0ZMHH42jsPfl1a4LVX7ohVpw5UK+e3GxuV3Nv239Il5oM2peUIl44g==", + "dependencies": { + "Serilog": "2.12.0" + } + }, + "Serilog.Exceptions": { + "type": "Transitive", + "resolved": "8.4.0", + "contentHash": "nc/+hUw3lsdo0zCj0KMIybAu7perMx79vu72w0za9Nsi6mWyNkGXxYxakAjWB7nEmYL6zdmhEQRB4oJ2ALUeug==", + "dependencies": { + "Serilog": "2.8.0" + } + }, + "Serilog.Extensions.Logging": { + "type": "Transitive", + "resolved": "7.0.0", + "contentHash": "9faU0zNQqU7I6soVhLUMYaGNpgWv6cKlKb2S5AnS8gXxzW/em5Ladm/6FMrWTnX41cdbdGPOWNAo6adi4WaJ6A==", + "dependencies": { + "Microsoft.Extensions.Logging": "7.0.0", + "Serilog": "2.12.0" + } + }, + "Serilog.Formatting.Compact": { + "type": "Transitive", + "resolved": "1.1.0", + "contentHash": "pNroKVjo+rDqlxNG5PXkRLpfSCuDOBY0ri6jp9PLe505ljqwhwZz8ospy2vWhQlFu5GkIesh3FcDs4n7sWZODA==", + "dependencies": { + "Serilog": "2.8.0" + } + }, + "Serilog.Sinks.Console": { + "type": "Transitive", + "resolved": "4.1.0", + "contentHash": "K6N5q+5fetjnJPvCmkWOpJ/V8IEIoMIB1s86OzBrbxwTyHxdx3pmz4H+8+O/Dc/ftUX12DM1aynx/dDowkwzqg==", + "dependencies": { + "Serilog": "2.10.0" + } + }, + "Serilog.Sinks.File": { + "type": "Transitive", + "resolved": "5.0.0", + "contentHash": "uwV5hdhWPwUH1szhO8PJpFiahqXmzPzJT/sOijH/kFgUx+cyoDTMM8MHD0adw9+Iem6itoibbUXHYslzXsLEAg==", + "dependencies": { + "Serilog": "2.10.0" + } + }, + "Serilog.Sinks.PeriodicBatching": { + "type": "Transitive", + "resolved": "3.1.0", + "contentHash": "NDWR7m3PalVlGEq3rzoktrXikjFMLmpwF0HI4sowo8YDdU+gqPlTHlDQiOGxHfB0sTfjPA9JjA7ctKG9zqjGkw==", + "dependencies": { + "Serilog": "2.0.0" + } + }, + "Serilog.Sinks.Seq": { + "type": "Transitive", + "resolved": "5.2.2", + "contentHash": "1Csmo5ua7NKUe0yXUx+zsRefjAniPWcXFhUXxXG8pwo0iMiw2gjn9SOkgYnnxbgWqmlGv236w0N/dHc2v5XwMg==", + "dependencies": { + "Serilog": "2.12.0", + "Serilog.Formatting.Compact": "1.1.0", + "Serilog.Sinks.File": "5.0.0", + "Serilog.Sinks.PeriodicBatching": "3.1.0" + } + }, + "SerilogTimings": { + "type": "Transitive", + "resolved": "3.0.1", + "contentHash": "Zs28eTgszAMwpIrbBnWHBI50yuxL50p/dmAUWmy75+axdZYK/Sjm5/5m1N/CisR8acJUhTVcjPZrsB1P5iv0Uw==", + "dependencies": { + "Serilog": "2.10.0" + } + }, + "Speckle.Newtonsoft.Json": { + "type": "Transitive", + "resolved": "13.0.2", + "contentHash": "g1BejUZwax5PRfL6xHgLEK23sqHWOgOj9hE7RvfRRlN00AGt8GnPYt8HedSK7UB3HiRW8zCA9Pn0iiYxCK24BA==" + }, + "SQLitePCLRaw.bundle_e_sqlite3": { + "type": "Transitive", + "resolved": "2.1.4", + "contentHash": "EWI1olKDjFEBMJu0+3wuxwziIAdWDVMYLhuZ3Qs84rrz+DHwD00RzWPZCa+bLnHCf3oJwuFZIRsHT5p236QXww==", + "dependencies": { + "SQLitePCLRaw.lib.e_sqlite3": "2.1.4", + "SQLitePCLRaw.provider.dynamic_cdecl": "2.1.4" + } + }, + "SQLitePCLRaw.core": { + "type": "Transitive", + "resolved": "2.1.4", + "contentHash": "inBjvSHo9UDKneGNzfUfDjK08JzlcIhn1+SP5Y3m6cgXpCxXKCJDy6Mka7LpgSV+UZmKSnC8rTwB0SQ0xKu5pA==", + "dependencies": { + "System.Memory": "4.5.3" + } + }, + "SQLitePCLRaw.lib.e_sqlite3": { + "type": "Transitive", + "resolved": "2.1.4", + "contentHash": "2C9Q9eX7CPLveJA0rIhf9RXAvu+7nWZu1A2MdG6SD/NOu26TakGgL1nsbc0JAspGijFOo3HoN79xrx8a368fBg==" + }, + "SQLitePCLRaw.provider.dynamic_cdecl": { + "type": "Transitive", + "resolved": "2.1.4", + "contentHash": "ZsaKKhgYF9B1fvcnOGKl3EycNAwd9CRWX7v0rEfuPWhQQ5Jjpvf2VEHahiLIGHio3hxi3EIKFJw9KvyowWOUAw==", + "dependencies": { + "SQLitePCLRaw.core": "2.1.4" + } + }, + "System.Buffers": { + "type": "Transitive", + "resolved": "4.5.1", + "contentHash": "Rw7ijyl1qqRS0YQD/WycNst8hUUMgrMH4FCn1nNm27M4VxchZ1js3fVjQaANHO5f3sN4isvP4a+Met9Y4YomAg==" + }, + "System.CodeDom": { + "type": "Transitive", + "resolved": "6.0.0", + "contentHash": "CPc6tWO1LAer3IzfZufDBRL+UZQcj5uS207NHALQzP84Vp/z6wF0Aa0YZImOQY8iStY0A2zI/e3ihKNPfUm8XA==" + }, + "System.Collections.Immutable": { + "type": "Transitive", + "resolved": "5.0.0", + "contentHash": "FXkLXiK0sVVewcso0imKQoOxjoPAj42R8HtjjbSjVPAzwDfzoyoznWxgA3c38LDbN9SJux1xXoXYAhz98j7r2g==", + "dependencies": { + "System.Memory": "4.5.4" + } + }, + "System.Diagnostics.DiagnosticSource": { + "type": "Transitive", + "resolved": "7.0.0", + "contentHash": "9W0ewWDuAyDqS2PigdTxk6jDKonfgscY/hP8hm7VpxYhNHZHKvZTdRckberlFk3VnCmr3xBUyMBut12Q+T2aOw==", + "dependencies": { + "System.Memory": "4.5.5", + "System.Runtime.CompilerServices.Unsafe": "6.0.0" + } + }, + "System.DoubleNumerics": { + "type": "Transitive", + "resolved": "3.1.3", + "contentHash": "KRKEM/L3KBodjA9VOg3EifFVWUY6EOqaMB05UvPEDm7Zeby/kZW+4kdWUEPzW6xtkwf46p661L9NrbeeQhtLzw==", + "dependencies": { + "NETStandard.Library": "1.6.1" + } + }, + "System.Management": { + "type": "Transitive", + "resolved": "6.0.1", + "contentHash": "10J1D0h/lioojphfJ4Fuh5ZUThT/xOVHdV9roGBittKKNP2PMjrvibEdbVTGZcPra1399Ja3tqIJLyQrc5Wmhg==", + "dependencies": { + "System.CodeDom": "6.0.0" + } + }, + "System.Memory": { + "type": "Transitive", + "resolved": "4.5.5", + "contentHash": "XIWiDvKPXaTveaB7HVganDlOCRoj03l+jrwNvcge/t8vhGYKvqV+dMv6G4SAX2NoNmN0wZfVPTAlFwZcZvVOUw==", + "dependencies": { + "System.Buffers": "4.5.1", + "System.Numerics.Vectors": "4.5.0", + "System.Runtime.CompilerServices.Unsafe": "4.5.3" + } + }, + "System.Net.WebSockets.Client.Managed": { + "type": "Transitive", + "resolved": "1.0.22", + "contentHash": "WqEOxPlXjuZrIjUtXNE9NxEfU/n5E35iV2PtoZdJSUC4tlrqwHnTee+wvMIM4OUaJWmwrymeqcgYrE0IkGAgLA==", + "dependencies": { + "System.Buffers": "4.4.0", + "System.Numerics.Vectors": "4.4.0" + } + }, + "System.Numerics.Vectors": { + "type": "Transitive", + "resolved": "4.5.0", + "contentHash": "QQTlPTl06J/iiDbJCiepZ4H//BVraReU4O4EoRw1U02H5TLUIT7xn3GnDp9AXPSlJUDyFs4uWjWafNX6WrAojQ==" + }, + "System.Reactive": { + "type": "Transitive", + "resolved": "5.0.0", + "contentHash": "erBZjkQHWL9jpasCE/0qKAryzVBJFxGHVBAvgRN1bzM0q2s1S4oYREEEL0Vb+1kA/6BKb5FjUZMp5VXmy+gzkQ==", + "dependencies": { + "System.Threading.Tasks.Extensions": "4.5.4" + } + }, + "System.Reflection.Metadata": { + "type": "Transitive", + "resolved": "5.0.0", + "contentHash": "5NecZgXktdGg34rh1OenY1rFNDCI8xSjFr+Z4OU4cU06AQHUdRnIIEeWENu3Wl4YowbzkymAIMvi3WyK9U53pQ==", + "dependencies": { + "System.Collections.Immutable": "5.0.0" + } + }, + "System.Runtime.CompilerServices.Unsafe": { + "type": "Transitive", + "resolved": "6.0.0", + "contentHash": "/iUeP3tq1S0XdNNoMz5C9twLSrM/TH+qElHkXWaPvuNOt+99G75NrV0OS2EqHx5wMN7popYjpc8oTjC1y16DLg==" + }, + "System.Runtime.InteropServices.RuntimeInformation": { + "type": "Transitive", + "resolved": "4.3.0", + "contentHash": "cbz4YJMqRDR7oLeMRbdYv7mYzc++17lNhScCX0goO2XpGWdvAt60CGN+FHdePUEHCe/Jy9jUlvNAiNdM+7jsOw==" + }, + "System.Text.Encodings.Web": { + "type": "Transitive", + "resolved": "5.0.1", + "contentHash": "KmJ+CJXizDofbq6mpqDoRRLcxgOd2z9X3XoFNULSbvbqVRZkFX3istvr+MUjL6Zw1RT+RNdoI4GYidIINtgvqQ==", + "dependencies": { + "System.Buffers": "4.5.1", + "System.Memory": "4.5.4" + } + }, + "System.Text.Json": { + "type": "Transitive", + "resolved": "5.0.2", + "contentHash": "I47dVIGiV6SfAyppphxqupertT/5oZkYLDCX6vC3HpOI4ZLjyoKAreUoem2ie6G0RbRuFrlqz/PcTQjfb2DOfQ==", + "dependencies": { + "Microsoft.Bcl.AsyncInterfaces": "5.0.0", + "System.Buffers": "4.5.1", + "System.Memory": "4.5.4", + "System.Numerics.Vectors": "4.5.0", + "System.Runtime.CompilerServices.Unsafe": "5.0.0", + "System.Text.Encodings.Web": "5.0.1", + "System.Threading.Tasks.Extensions": "4.5.4", + "System.ValueTuple": "4.5.0" + } + }, + "System.Threading.Tasks.Extensions": { + "type": "Transitive", + "resolved": "4.5.4", + "contentHash": "zteT+G8xuGu6mS+mzDzYXbzS7rd3K6Fjb9RiZlYlJPam2/hU7JCBZBVEcywNuR+oZ1ncTvc/cq0faRr3P01OVg==", + "dependencies": { + "System.Runtime.CompilerServices.Unsafe": "4.5.3" + } + }, + "System.ValueTuple": { + "type": "Transitive", + "resolved": "4.5.0", + "contentHash": "okurQJO6NRE/apDIP23ajJ0hpiNmJ+f0BwOlB/cSqTLQlw5upkf+5+96+iG2Jw40G1fCVCyPz/FhIABUjMR+RQ==" + }, + "speckle.autofac": { + "type": "Project", + "dependencies": { + "Microsoft.Extensions.Logging.Abstractions": "[7.0.0, )", + "Speckle.Core": "[2.0.999-local, )" + } + }, + "speckle.connectors.utils": { + "type": "Project", + "dependencies": { + "Serilog.Extensions.Logging": "[7.0.0, )", + "Speckle.Autofac": "[2.0.999-local, )", + "Speckle.Core": "[2.0.999-local, )" + } + }, + "speckle.converters.common": { + "type": "Project", + "dependencies": { + "Speckle.Autofac": "[2.0.999-local, )", + "Speckle.Objects": "[2.0.999-local, )" + } + }, + "speckle.converters.common.dependencyinjection": { + "type": "Project", + "dependencies": { + "Speckle.Autofac": "[2.0.999-local, )", + "Speckle.Converters.Common": "[2.0.999-local, )" + } + }, + "speckle.converters.revit2023": { + "type": "Project", + "dependencies": { + "Speckle.Converters.Common": "[2.0.999-local, )", + "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.16, )" + } + }, + "Speckle.Core": { + "type": "Project", + "dependencies": { + "GraphQL.Client": "[6.0.0, )", + "Microsoft.CSharp": "[4.7.0, )", + "Microsoft.Data.Sqlite": "[7.0.5, )", + "Polly": "[7.2.3, )", + "Polly.Contrib.WaitAndRetry": "[1.1.1, )", + "Polly.Extensions.Http": "[3.0.0, )", + "Sentry": "[3.33.0, )", + "Sentry.Serilog": "[3.33.0, )", + "Serilog": "[2.12.0, )", + "Serilog.Enrichers.ClientInfo": "[1.3.0, )", + "Serilog.Enrichers.GlobalLogContext": "[3.0.0, )", + "Serilog.Exceptions": "[8.4.0, )", + "Serilog.Sinks.Console": "[4.1.0, )", + "Serilog.Sinks.Seq": "[5.2.2, )", + "SerilogTimings": "[3.0.1, )", + "Speckle.Newtonsoft.Json": "[13.0.2, )", + "System.DoubleNumerics": "[3.1.3, )" + } + }, + "Speckle.Objects": { + "type": "Project", + "dependencies": { + "Speckle.Core": "[2.0.999-local, )" + } + } + } + } +} \ No newline at end of file diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/RevitVersionConversionHelper.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/RevitVersionConversionHelper.cs deleted file mode 100644 index 515c2e057f..0000000000 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/RevitVersionConversionHelper.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Speckle.Converters.RevitShared; - -namespace Speckle.Converters.Revit2023; - -public class RevitVersionConversionHelper : IRevitVersionConversionHelper -{ - public bool IsCurveClosed(DB.NurbSpline nurbsSpline) - { - try - { - return nurbsSpline.IsClosed; - } - catch (Autodesk.Revit.Exceptions.ApplicationException) - { - // POC: is this actually a good assumption? - return true; - } - } -} diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/Speckle.Converters.Revit2023.csproj b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/Speckle.Converters.Revit2023.csproj index d304c7cfec..3f7d7c8eec 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/Speckle.Converters.Revit2023.csproj +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/Speckle.Converters.Revit2023.csproj @@ -3,12 +3,13 @@ net48 x64 + false - + diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Extensions/CategoryExtensions.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Extensions/CategoryExtensions.cs index 9083375a2e..c0acca23c8 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Extensions/CategoryExtensions.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Extensions/CategoryExtensions.cs @@ -1,10 +1,10 @@ -using Autodesk.Revit.DB; +using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared.Extensions; public static class CategoryExtensions { - public static SOBR.RevitCategory GetSchemaBuilderCategoryFromBuiltIn(this DB.BuiltInCategory builtInCategory) + public static SOBR.RevitCategory GetSchemaBuilderCategoryFromBuiltIn(this RevitBuiltInCategory builtInCategory) { // Clean up built-in name "OST_Walls" to be just "WALLS" var cleanName = builtInCategory @@ -23,9 +23,9 @@ public static SOBR.RevitCategory GetSchemaBuilderCategoryFromBuiltIn(this DB.Bui return cat; } - public static BuiltInCategory GetBuiltInCategory(this Category category) + public static RevitBuiltInCategory GetBuiltInCategory(this IRevitCategory category) { - return (BuiltInCategory)category.Id.IntegerValue; + return (RevitBuiltInCategory)category.Id.IntegerValue; } public static string GetBuiltInFromSchemaBuilderCategory(this SOBR.RevitCategory c) diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Extensions/DefinitionExtensions.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Extensions/DefinitionExtensions.cs index 77aff9d11b..1b3a22beda 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Extensions/DefinitionExtensions.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Extensions/DefinitionExtensions.cs @@ -1,16 +1,12 @@ -using Autodesk.Revit.DB; +using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared.Extensions; public static class DefinitionExtensions { // POC: can we just interface these specialisations out and thereby avoid this kind of BS :D - public static string GetUnitTypeString(this Definition definition) + public static string GetUnitTypeString(this IRevitDefinition definition) { -#if REVIT2020 || REVIT2021 - return definition.UnitType.ToString(); -#else return definition.GetDataType().TypeId; -#endif } } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Extensions/ElementExtensions.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Extensions/ElementExtensions.cs index 468a98fd0f..e8553e34cb 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Extensions/ElementExtensions.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Extensions/ElementExtensions.cs @@ -1,30 +1,31 @@ -using Autodesk.Revit.DB; +using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared.Extensions; public static class ElementExtensions { // POC: should this be an injected service? - public static IList GetHostedElementIds(this Element host) + public static IList GetHostedElementIds(this IRevitElement host, IRevitFilterFactory filterFactory) { - IList ids; - if (host is HostObject hostObject) + IList ids; + var hostObject = host.ToHostObject(); + if (hostObject is not null) { ids = hostObject.FindInserts(true, false, false, false); } else { - var typeFilter = new ElementIsElementTypeFilter(true); - var categoryFilter = new ElementMulticategoryFilter( - new List() + var typeFilter = filterFactory.CreateElementIsElementTypeFilter(true); + var categoryFilter = filterFactory.CreateElementMulticategoryFilter( + new List() { - BuiltInCategory.OST_CLines, - BuiltInCategory.OST_SketchLines, - BuiltInCategory.OST_WeakDims + RevitBuiltInCategory.OST_CLines, + RevitBuiltInCategory.OST_SketchLines, + RevitBuiltInCategory.OST_WeakDims }, true ); - ids = host.GetDependentElements(new LogicalAndFilter(typeFilter, categoryFilter)); + ids = host.GetDependentElements(filterFactory.CreateLogicalAndFilter(typeFilter, categoryFilter)); } // dont include host elementId diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Extensions/ForgeTypeIdExtensions.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Extensions/ForgeTypeIdExtensions.cs index 790e92a07a..1c9d03b5a1 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Extensions/ForgeTypeIdExtensions.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Extensions/ForgeTypeIdExtensions.cs @@ -1,25 +1,25 @@ -using Autodesk.Revit.DB; +using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared.Extensions; public static class ForgeTypeIdExtensions { - public static string? GetSymbol(this ForgeTypeId forgeTypeId) + public static string? GetSymbol(this IRevitForgeTypeId forgeTypeId, IRevitFormatOptionsUtils formatOptionsUtils) { - if (!FormatOptions.CanHaveSymbol(forgeTypeId)) + if (!formatOptionsUtils.CanHaveSymbol(forgeTypeId)) { return null; } - var validSymbols = FormatOptions.GetValidSymbols(forgeTypeId); + var validSymbols = formatOptionsUtils.GetValidSymbols(forgeTypeId); var typeId = validSymbols.Where(x => !x.Empty()); - foreach (DB.ForgeTypeId symbolId in typeId) + foreach (var symbolId in typeId) { - return LabelUtils.GetLabelForSymbol(symbolId); + return formatOptionsUtils.GetLabelForSymbol(symbolId); } return null; } - public static string ToUniqueString(this ForgeTypeId forgeTypeId) + public static string ToUniqueString(this IRevitForgeTypeId forgeTypeId) { return forgeTypeId.TypeId; } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Extensions/ParameterExtensions.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Extensions/ParameterExtensions.cs index c8ac6f92e8..704eb40484 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Extensions/ParameterExtensions.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Extensions/ParameterExtensions.cs @@ -1,4 +1,5 @@ -using Autodesk.Revit.DB; +using Speckle.Converters.Common; +using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared.Extensions; @@ -10,7 +11,7 @@ public static class ParameterExtensions /// /// /// - public static string GetInternalName(this DB.Parameter rp) + public static string GetInternalName(this IRevitParameter rp) { if (rp.IsShared) { @@ -18,8 +19,8 @@ public static string GetInternalName(this DB.Parameter rp) } else { - var def = (InternalDefinition)rp.Definition; - if (def.BuiltInParameter == BuiltInParameter.INVALID) + var def = rp.Definition.ToInternal().NotNull(); + if (def.BuiltInParameter == RevitBuiltInParameter.INVALID) { return def.Name; } @@ -28,9 +29,9 @@ public static string GetInternalName(this DB.Parameter rp) } } - public static BuiltInParameter? GetBuiltInParameter(this Parameter rp) + public static RevitBuiltInParameter? GetBuiltInParameter(this IRevitParameter rp) { - var def = rp.Definition as InternalDefinition; + var def = rp.Definition.ToInternal(); return def?.BuiltInParameter; } } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/GlobalUsings.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/GlobalUsings.cs index 5a7a8f20bd..a4a6c2cf0d 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/GlobalUsings.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/GlobalUsings.cs @@ -1,5 +1,3 @@ -global using DB = Autodesk.Revit.DB; -global using DBA = Autodesk.Revit.DB.Architecture; -global using SOG = Objects.Geometry; +global using SOG = Objects.Geometry; global using SOBR = Objects.BuiltElements.Revit; global using SOBE = Objects.BuiltElements; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/DisplayValueExtractor.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/DisplayValueExtractor.cs index cd65fb5f90..28163ace7d 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/DisplayValueExtractor.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/DisplayValueExtractor.cs @@ -1,31 +1,45 @@ +using System.Diagnostics.CodeAnalysis; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Core.Logging; +using Speckle.InterfaceGenerator; +using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared.Helpers; // POC: needs breaking down https://spockle.atlassian.net/browse/CNX-9354 -public sealed class DisplayValueExtractor +[GenerateAutoInterface] +public sealed class DisplayValueExtractor : IDisplayValueExtractor { - private readonly ITypedConverter>, List> _meshByMaterialConverter; + private readonly ITypedConverter< + Dictionary>, + List + > _meshByMaterialConverter; + private readonly IRevitOptionsFactory _revitOptionsFactory; + private readonly IRevitSolidUtils _revitSolidUtils; public DisplayValueExtractor( - ITypedConverter>, List> meshByMaterialConverter + ITypedConverter>, List> meshByMaterialConverter, + IRevitOptionsFactory revitOptionsFactory, + IRevitSolidUtils revitSolidUtils ) { _meshByMaterialConverter = meshByMaterialConverter; + _revitOptionsFactory = revitOptionsFactory; + _revitSolidUtils = revitSolidUtils; } public List GetDisplayValue( - DB.Element element, - DB.Options? options = null, + IRevitElement element, + IRevitOptions? options = null, // POC: should this be part of the context? - DB.Transform? transform = null + IRevitTransform? transform = null ) { var displayMeshes = new List(); // test if the element is a group first - if (element is DB.Group g) + if (element is IRevitGroup g) { foreach (var id in g.GetMemberIds()) { @@ -42,18 +56,18 @@ public DisplayValueExtractor( return _meshByMaterialConverter.Convert(meshesByMaterial); } - private static Dictionary> GetMeshesByMaterial( - List meshes, - List solids + private static Dictionary> GetMeshesByMaterial( + List meshes, + List solids ) { - var meshesByMaterial = new Dictionary>(); + var meshesByMaterial = new Dictionary>(); foreach (var mesh in meshes) { var materialId = mesh.MaterialElementId; - if (!meshesByMaterial.TryGetValue(materialId, out List? value)) + if (!meshesByMaterial.TryGetValue(materialId, out List? value)) { - value = new List(); + value = new List(); meshesByMaterial[materialId] = value; } @@ -62,12 +76,12 @@ public DisplayValueExtractor( foreach (var solid in solids) { - foreach (DB.Face face in solid.Faces) + foreach (IRevitFace face in solid.Faces) { var materialId = face.MaterialElementId; - if (!meshesByMaterial.TryGetValue(materialId, out List? value)) + if (!meshesByMaterial.TryGetValue(materialId, out List? value)) { - value = new List(); + value = new List(); meshesByMaterial[materialId] = value; } @@ -78,29 +92,30 @@ public DisplayValueExtractor( return meshesByMaterial; } - private (List, List) GetSolidsAndMeshesFromElement( - DB.Element element, - DB.Options? options, - DB.Transform? transform = null + [SuppressMessage("Design", "CA1031:Do not catch general exception types")] + private (List, List) GetSolidsAndMeshesFromElement( + IRevitElement element, + IRevitOptions? options, + IRevitTransform? transform = null ) { //options = ViewSpecificOptions ?? options ?? new Options() { DetailLevel = DetailLevelSetting }; - options ??= new DB.Options { DetailLevel = DB.ViewDetailLevel.Fine }; + options ??= _revitOptionsFactory.Create(RevitViewDetailLevel.Fine); - DB.GeometryElement geom; + IRevitGeometryElement geom; try { - geom = element.get_Geometry(options); + geom = element.GetGeometry(options); } // POC: should we be trying to continue? - catch (Autodesk.Revit.Exceptions.ArgumentException) + catch (Exception) { options.ComputeReferences = false; - geom = element.get_Geometry(options); + geom = element.GetGeometry(options); } - var solids = new List(); - var meshes = new List(); + var solids = new List(); + var meshes = new List(); if (geom != null) { @@ -128,11 +143,11 @@ public DisplayValueExtractor( /// /// private void SortGeometry( - DB.Element element, - List solids, - List meshes, - DB.GeometryElement geom, - DB.Transform? inverseTransform = null + IRevitElement element, + List solids, + List meshes, + IRevitGeometryElement geom, + IRevitTransform? inverseTransform = null ) { var topLevelSolidsCount = 0; @@ -141,16 +156,16 @@ private void SortGeometry( var topLevelGeomInstanceCount = 0; bool hasSymbolGeometry = false; - foreach (DB.GeometryObject geomObj in geom) + foreach (IRevitGeometryObject geomObj in geom) { // POC: switch could possibly become factory and IIndex<,> pattern and move conversions to // separate IComeConversionInterfaces switch (geomObj) { - case DB.Solid solid: + case IRevitSolid solid: // skip invalid solid if ( - solid.Faces.Size == 0 + solid.Faces.Count == 0 || Math.Abs(solid.SurfaceArea) == 0 || IsSkippableGraphicStyle(solid.GraphicsStyleId, element.Document) ) @@ -161,12 +176,12 @@ private void SortGeometry( if (inverseTransform != null) { topLevelSolidsCount++; - solid = DB.SolidUtils.CreateTransformed(solid, inverseTransform); + solid = _revitSolidUtils.CreateTransformed(solid, inverseTransform); } solids.Add(solid); break; - case DB.Mesh mesh: + case IRevitMesh mesh: if (IsSkippableGraphicStyle(mesh.GraphicsStyleId, element.Document)) { continue; @@ -175,12 +190,12 @@ private void SortGeometry( if (inverseTransform != null) { topLevelMeshesCount++; - mesh = mesh.get_Transformed(inverseTransform); + mesh = mesh.GetTransformed(inverseTransform); } meshes.Add(mesh); break; - case DB.GeometryInstance instance: + case IRevitGeometryInstance instance: // element transforms should not be carried down into nested geometryInstances. // Nested geomInstances should have their geom retreived with GetInstanceGeom, not GetSymbolGeom if (inverseTransform != null) @@ -197,7 +212,7 @@ private void SortGeometry( SortGeometry(element, solids, meshes, instance.GetInstanceGeometry()); } break; - case DB.GeometryElement geometryElement: + case IRevitGeometryElement geometryElement: if (inverseTransform != null) { topLevelGeomElementCount++; @@ -221,7 +236,7 @@ private void SortGeometry( // POC: should be hoovered up with the new reporting, logging, exception philosophy private static void LogInstanceMeshRetrievalWarnings( - DB.Element element, + IRevitElement element, int topLevelSolidsCount, int topLevelMeshesCount, int topLevelGeomElementCount, @@ -263,26 +278,23 @@ bool hasSymbolGeom /// /// We're caching a dictionary of graphic styles and their ids as it can be a costly operation doing Document.GetElement(solid.GraphicsStyleId) for every solid /// - private readonly Dictionary _graphicStyleCache = new(); + private readonly Dictionary _graphicStyleCache = new(); /// /// Exclude light source cones and potentially other geometries by their graphic style /// - /// - /// - /// - private bool IsSkippableGraphicStyle(DB.ElementId id, DB.Document doc) + private bool IsSkippableGraphicStyle(IRevitElementId id, IRevitDocument doc) { if (!_graphicStyleCache.ContainsKey(id.ToString())) { - _graphicStyleCache.Add(id.ToString(), (DB.GraphicsStyle)doc.GetElement(id)); + _graphicStyleCache.Add(id.ToString(), doc.GetElement(id).ToGraphicsStyle().NotNull()); } var graphicStyle = _graphicStyleCache[id.ToString()]; if ( graphicStyle != null - && graphicStyle.GraphicsStyleCategory.Id.IntegerValue == (int)DB.BuiltInCategory.OST_LightingFixtureSource + && graphicStyle.GraphicsStyleCategory.Id.IntegerValue == (int)RevitBuiltInCategory.OST_LightingFixtureSource ) { return true; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/IRevitConversionContextStack.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/IRevitConversionContextStack.cs deleted file mode 100644 index 1cf5d4b80c..0000000000 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/IRevitConversionContextStack.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Autodesk.Revit.DB; -using Speckle.Converters.Common; - -namespace Speckle.Converters.RevitShared.Helpers; - -[System.Diagnostics.CodeAnalysis.SuppressMessage( - "Naming", - "CA1711:Identifiers should not have incorrect suffix", - Justification = "See base class justification" -)] -// POC: so this should *probably* be Document and NOT UI.UIDocument, the former is Conversion centric -// and the latter is more for connector -public interface IRevitConversionContextStack : IConversionContextStack { } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ISlopeArrowExtractor.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ISlopeArrowExtractor.cs deleted file mode 100644 index 750f4d1073..0000000000 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ISlopeArrowExtractor.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Speckle.Converters.RevitShared.Helpers; - -public interface ISlopeArrowExtractor -{ - DB.ModelLine? GetSlopeArrow(DB.Element element); - SOG.Point GetSlopeArrowHead(DB.ModelLine slopeArrow); - SOG.Point GetSlopeArrowTail(DB.ModelLine slopeArrow); - double GetSlopeArrowTailOffset(DB.ModelLine slopeArrow); - double GetSlopeArrowHeadOffset(DB.ModelLine slopeArrow, double tailOffset, out double slope); -} diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterObjectAssigner.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterObjectAssigner.cs index 2c4f3b2112..746af2eddb 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterObjectAssigner.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterObjectAssigner.cs @@ -1,41 +1,46 @@ -using Autodesk.Revit.DB; -using Speckle.Converters.Common; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Core.Logging; using Speckle.Core.Models; +using Speckle.InterfaceGenerator; +using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared.Helpers; // POC: rationalise whether this and ParameterObjectBuilder are sufficiently different?? // did it go away? -public sealed class ParameterObjectAssigner +[GenerateAutoInterface] +public sealed class ParameterObjectAssigner : IParameterObjectAssigner { - private readonly ITypedConverter _paramConverter; - private readonly ParameterValueExtractor _parameterValueExtractor; + private readonly ITypedConverter _paramConverter; + private readonly IParameterValueExtractor _parameterValueExtractor; + private readonly IRevitElementIdUtils _revitElementIdUtils; public ParameterObjectAssigner( - ITypedConverter paramConverter, - ParameterValueExtractor parameterValueExtractor + ITypedConverter paramConverter, + IParameterValueExtractor parameterValueExtractor, + IRevitElementIdUtils revitElementIdUtils ) { _paramConverter = paramConverter; _parameterValueExtractor = parameterValueExtractor; + _revitElementIdUtils = revitElementIdUtils; } - public void AssignParametersToBase(Element target, Base @base) + public void AssignParametersToBase(IRevitElement target, Base @base) { - Dictionary instanceParameters = _parameterValueExtractor.GetAllRemainingParams(target); - ElementId elementId = target.GetTypeId(); + var instanceParameters = _parameterValueExtractor.GetAllRemainingParams(target); + IRevitElementId elementId = target.GetTypeId(); Base paramBase = new(); AssignSpeckleParamToBaseObject(instanceParameters, paramBase); // POC: Some elements can have an invalid element type ID, I don't think we want to continue here. - if (elementId != ElementId.InvalidElementId && target is not Level) //ignore type props of levels..! + if (elementId != _revitElementIdUtils.InvalidElementId && target is not SOBE.Level) //ignore type props of levels..! { var elementType = target.Document.GetElement(elementId); // I don't think we should be adding the type parameters to the object like this - Dictionary typeParameters = _parameterValueExtractor.GetAllRemainingParams(elementType); + var typeParameters = _parameterValueExtractor.GetAllRemainingParams(elementType); AssignSpeckleParamToBaseObject(typeParameters, paramBase, true); } @@ -46,7 +51,7 @@ public void AssignParametersToBase(Element target, Base @base) } private void AssignSpeckleParamToBaseObject( - IEnumerable> parameters, + IEnumerable> parameters, Base paramBase, bool isTypeParameter = false ) @@ -56,7 +61,7 @@ private void AssignSpeckleParamToBaseObject( { try { - SOBR.Parameter speckleParam = _paramConverter.Convert(kv.Value); + var speckleParam = _paramConverter.Convert(kv.Value); speckleParam.isTypeParameter = isTypeParameter; paramBase[kv.Key] = speckleParam; } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterObjectBuilder.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterObjectBuilder.cs deleted file mode 100644 index 71cf930224..0000000000 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterObjectBuilder.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using Autodesk.Revit.DB; -using Speckle.Converters.Common.Objects; -using Speckle.Core.Logging; -using Speckle.Core.Models; - -namespace Speckle.Converters.RevitShared.Helpers; - -public sealed class ParameterObjectAssigner -{ - private readonly IRawConversion _paramConverter; - private readonly ParameterValueExtractor _parameterValueExtractor; - - public ParameterObjectAssigner( - IRawConversion paramConverter, - ParameterValueExtractor parameterValueExtractor - ) - { - _paramConverter = paramConverter; - _parameterValueExtractor = parameterValueExtractor; - } - - public void AssignParametersToBase(Element target, Base @base) - { - Dictionary allParams = _parameterValueExtractor.GetAllRemainingParams(target); - Base paramBase = new(); - //sort by key - foreach (var kv in allParams.OrderBy(x => x.Key)) - { - try - { - paramBase[kv.Key] = _paramConverter.RawConvert(kv.Value); - } - catch (InvalidPropNameException) - { - //ignore - } - catch (SpeckleException ex) - { - SpeckleLog.Logger.Warning(ex, "Error thrown when trying to set property named {propName}", kv.Key); - } - } - - if (paramBase.GetMembers(DynamicBaseMemberType.Dynamic).Count > 0) - { - @base["parameters"] = paramBase; - } - } -} diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs index cdc8e69243..bfd8880264 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs @@ -1,7 +1,9 @@ -using Autodesk.Revit.DB; +using System.Diagnostics.CodeAnalysis; using Speckle.Converters.Common; using Speckle.Converters.RevitShared.Extensions; using Speckle.Converters.RevitShared.Services; +using Speckle.InterfaceGenerator; +using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared.Helpers; @@ -9,17 +11,18 @@ namespace Speckle.Converters.RevitShared.Helpers; // really if we have to edit a switch statement... // maybe also better as an extension method, but maybe is fine? // POC: there are a lot of public methods here. Maybe consider consolodating -public class ParameterValueExtractor +[GenerateAutoInterface] +public class ParameterValueExtractor : IParameterValueExtractor { - private readonly ScalingServiceToSpeckle _scalingService; - private readonly Dictionary> _uniqueIdToUsedParameterSetMap = new(); + private readonly IScalingServiceToSpeckle _scalingService; + private readonly Dictionary> _uniqueIdToUsedParameterSetMap = new(); - public ParameterValueExtractor(ScalingServiceToSpeckle scalingService) + public ParameterValueExtractor(IScalingServiceToSpeckle scalingService) { _scalingService = scalingService; } - public object? GetValue(Parameter parameter) + public object? GetValue(IRevitParameter parameter) { if (!parameter.HasValue) { @@ -28,32 +31,36 @@ public ParameterValueExtractor(ScalingServiceToSpeckle scalingService) return parameter.StorageType switch { - StorageType.Double => GetValueAsDouble(parameter), - StorageType.Integer => GetValueAsInt(parameter), - StorageType.String => GetValueAsString(parameter), - StorageType.ElementId => GetValueAsElementId(parameter)?.ToString(), - StorageType.None + IRevitStorageType.Double => GetValueAsDouble(parameter), + IRevitStorageType.Integer => GetValueAsInt(parameter), + IRevitStorageType.String => GetValueAsString(parameter), + IRevitStorageType.ElementId => GetValueAsElementId(parameter)?.ToString(), + IRevitStorageType.None or _ => throw new SpeckleConversionException($"Unsupported parameter storage type {parameter.StorageType}") }; } - public double GetValueAsDouble(Element element, BuiltInParameter builtInParameter) + public double GetValueAsDouble(IRevitElement element, RevitBuiltInParameter builtInParameter) { if (!TryGetValueAsDouble(element, builtInParameter, out double? value)) { throw new SpeckleConversionException($"Failed to get {builtInParameter} as double."); } - return value!.Value; // If TryGet returns true, we succeeded in obtaining the value, and it will not be null. + return value.Value; // If TryGet returns true, we succeeded in obtaining the value, and it will not be null. } - public bool TryGetValueAsDouble(Element element, BuiltInParameter builtInParameter, out double? value) + public bool TryGetValueAsDouble( + IRevitElement element, + RevitBuiltInParameter builtInParameter, + [NotNullWhen(true)] out double? value + ) { var number = GetValueGeneric( element, builtInParameter, - StorageType.Double, + IRevitStorageType.Double, (parameter) => _scalingService.Scale(parameter.AsDouble(), parameter.GetUnitTypeId()) ); if (number.HasValue) @@ -66,66 +73,75 @@ public bool TryGetValueAsDouble(Element element, BuiltInParameter builtInParamet return false; } - private double? GetValueAsDouble(Parameter parameter) + private double? GetValueAsDouble(IRevitParameter parameter) { return GetValueGeneric( parameter, - StorageType.Double, + IRevitStorageType.Double, (parameter) => _scalingService.Scale(parameter.AsDouble(), parameter.GetUnitTypeId()) ); } - public int GetValueAsInt(Element element, BuiltInParameter builtInParameter) + public int GetValueAsInt(IRevitElement element, RevitBuiltInParameter builtInParameter) { - return GetValueGeneric(element, builtInParameter, StorageType.Integer, (parameter) => parameter.AsInteger()) + return GetValueGeneric( + element, + builtInParameter, + IRevitStorageType.Integer, + (parameter) => parameter.AsInteger() + ) ?? throw new SpeckleConversionException( $"Expected int but got null for property {builtInParameter} on element of type {element.GetType()}" ); } - private int? GetValueAsInt(Parameter parameter) + private int? GetValueAsInt(IRevitParameter parameter) { - return GetValueGeneric(parameter, StorageType.Integer, (parameter) => parameter.AsInteger()); + return GetValueGeneric(parameter, IRevitStorageType.Integer, (parameter) => parameter.AsInteger()); } - public bool? GetValueAsBool(Element element, BuiltInParameter builtInParameter) + public bool? GetValueAsBool(IRevitElement element, RevitBuiltInParameter builtInParameter) { var intVal = GetValueGeneric( element, builtInParameter, - StorageType.Integer, + IRevitStorageType.Integer, (parameter) => parameter.AsInteger() ); return intVal.HasValue ? Convert.ToBoolean(intVal.Value) : null; } - public string? GetValueAsString(Element element, BuiltInParameter builtInParameter) + public string? GetValueAsString(IRevitElement element, RevitBuiltInParameter builtInParameter) { - return GetValueGeneric(element, builtInParameter, StorageType.String, (parameter) => parameter.AsString()); + return GetValueGeneric(element, builtInParameter, IRevitStorageType.String, (parameter) => parameter.AsString()); } - private string? GetValueAsString(Parameter parameter) + private string? GetValueAsString(IRevitParameter parameter) { - return GetValueGeneric(parameter, StorageType.String, (parameter) => parameter.AsString()); + return GetValueGeneric(parameter, IRevitStorageType.String, (parameter) => parameter.AsString()); } - public ElementId GetValueAsElementId(Element element, BuiltInParameter builtInParameter) + public IRevitElementId GetValueAsElementId(IRevitElement element, RevitBuiltInParameter builtInParameter) { if (TryGetValueAsElementId(element, builtInParameter, out var elementId)) { - return elementId!; + return elementId; } throw new SpeckleConversionException( $"Failed to get {builtInParameter} on element of type {element.GetType()} as ElementId" ); } - public bool TryGetValueAsElementId(Element element, BuiltInParameter builtInParameter, out ElementId? elementId) + public bool TryGetValueAsElementId( + IRevitElement element, + RevitBuiltInParameter builtInParameter, + [NotNullWhen(true)] out IRevitElementId? elementId + ) { if ( - GetValueGeneric(element, builtInParameter, StorageType.ElementId, (parameter) => parameter.AsElementId()) - is ElementId elementIdNotNull + GetValueGeneric(element, builtInParameter, IRevitStorageType.ElementId, (parameter) => parameter.AsElementId()) + is IRevitElementId elementIdNotNull ) { elementId = elementIdNotNull; @@ -136,12 +152,16 @@ is ElementId elementIdNotNull return false; } - public ElementId? GetValueAsElementId(Parameter parameter) + public IRevitElementId? GetValueAsElementId(IRevitParameter parameter) { - return GetValueGeneric(parameter, StorageType.ElementId, (parameter) => parameter.AsElementId()); + return GetValueGeneric(parameter, IRevitStorageType.ElementId, (parameter) => parameter.AsElementId()); } - public bool TryGetValueAsDocumentObject(Element element, BuiltInParameter builtInParameter, out T? value) + public bool TryGetValueAsDocumentObject( + IRevitElement element, + RevitBuiltInParameter builtInParameter, + [NotNullWhen(true)] out T? value + ) { if (!TryGetValueAsElementId(element, builtInParameter, out var elementId)) { @@ -149,7 +169,7 @@ public bool TryGetValueAsDocumentObject(Element element, BuiltInParameter bui return false; } - Element paramElement = element.Document.GetElement(elementId); + IRevitElement paramElement = element.Document.GetElement(elementId); if (paramElement is not T typedElement) { value = default; @@ -160,7 +180,7 @@ public bool TryGetValueAsDocumentObject(Element element, BuiltInParameter bui return true; } - public T GetValueAsDocumentObject(Element element, BuiltInParameter builtInParameter) + public T GetValueAsDocumentObject(IRevitElement element, RevitBuiltInParameter builtInParameter) where T : class { if (!TryGetValueAsDocumentObject(element, builtInParameter, out var value)) @@ -168,30 +188,32 @@ public T GetValueAsDocumentObject(Element element, BuiltInParameter builtInPa throw new SpeckleConversionException($"Failed to get {builtInParameter} as an element of type {typeof(T)}"); } - return value!; // If TryGet returns true, we succeeded in obtaining the value, and it will not be null. + return value; // If TryGet returns true, we succeeded in obtaining the value, and it will not be null. } private TResult? GetValueGeneric( - Element element, - BuiltInParameter builtInParameter, - StorageType expectedStorageType, - Func getParamValue + IRevitElement element, + RevitBuiltInParameter builtInParameter, + IRevitStorageType expectedStorageType, + Func getParamValue ) { - if (!_uniqueIdToUsedParameterSetMap.TryGetValue(element.UniqueId, out HashSet usedParameters)) + if ( + !_uniqueIdToUsedParameterSetMap.TryGetValue(element.UniqueId, out HashSet usedParameters) + ) { usedParameters = new(); _uniqueIdToUsedParameterSetMap[element.UniqueId] = usedParameters; } usedParameters.Add(builtInParameter); - var parameter = element.get_Parameter(builtInParameter); + var parameter = element.GetParameter(builtInParameter).NotNull(); return GetValueGeneric(parameter, expectedStorageType, getParamValue); } private TResult? GetValueGeneric( - Parameter parameter, - StorageType expectedStorageType, - Func getParamValue + IRevitParameter parameter, + IRevitStorageType expectedStorageType, + Func getParamValue ) { if (parameter == null || !parameter.HasValue) @@ -209,20 +231,20 @@ public T GetValueAsDocumentObject(Element element, BuiltInParameter builtInPa return getParamValue(parameter); } - public Dictionary GetAllRemainingParams(DB.Element revitElement) + public Dictionary GetAllRemainingParams(IRevitElement revitElement) { - var allParams = new Dictionary(); + var allParams = new Dictionary(); AddElementParamsToDict(revitElement, allParams); return allParams; } - private void AddElementParamsToDict(DB.Element element, Dictionary paramDict) + private void AddElementParamsToDict(IRevitElement element, Dictionary paramDict) { - _uniqueIdToUsedParameterSetMap.TryGetValue(element.UniqueId, out HashSet? usedParameters); + _uniqueIdToUsedParameterSetMap.TryGetValue(element.UniqueId, out HashSet? usedParameters); using var parameters = element.Parameters; - foreach (DB.Parameter param in parameters) + foreach (IRevitParameter param in parameters) { var internalName = param.GetInternalName(); if (paramDict.ContainsKey(internalName)) @@ -230,7 +252,7 @@ private void AddElementParamsToDict(DB.Element element, Dictionary -/// Contains predefined categories of revit objects as well as the types that make up the elements -/// in that category -/// -/// -// POC: is quite a messy looking thing, need some review -// might be legit or maybe a bette/cleaner pattern rather than the dictionary of pain, but maybe not -// some whitespace between each at the least! -public static class RevitCategories -{ - public static Dictionary All { get; } - - static RevitCategories() - { - All = new(StringComparer.OrdinalIgnoreCase) - { - { nameof(CableTray), CableTray }, - { nameof(Ceiling), Ceiling }, - { nameof(Column), Column }, - { nameof(Conduit), Conduit }, - { nameof(Door), Door }, - { nameof(Duct), Duct }, - { nameof(FamilyInstance), FamilyInstance }, - { nameof(Floor), Floor }, - { nameof(Furniture), Furniture }, - { nameof(Pipe), Pipe }, - { nameof(PlumbingFixture), PlumbingFixture }, - { nameof(Roof), Roof }, - { nameof(Railing), Railing }, - { nameof(StructuralFraming), StructuralFraming }, - { nameof(Wall), Wall }, - { nameof(Window), Window }, - { nameof(Wire), Wire }, - { nameof(Undefined), Undefined }, - }; - } - - public static RevitCategoryInfo CableTray { get; } = - new( - nameof(CableTray), - typeof(DB.Electrical.CableTray), - typeof(DB.Electrical.CableTrayType), - new List() - ); - public static RevitCategoryInfo Ceiling { get; } = - new(nameof(Ceiling), typeof(DB.Ceiling), typeof(CeilingType), new List()); - public static RevitCategoryInfo Column { get; } = - new( - nameof(Column), - typeof(FamilyInstance), - typeof(FamilySymbol), - new List { BuiltInCategory.OST_Columns, BuiltInCategory.OST_StructuralColumns } - ); - public static RevitCategoryInfo Conduit { get; } = - new(nameof(Conduit), typeof(DB.Electrical.Conduit), typeof(DB.Electrical.ConduitType), new List()); - public static RevitCategoryInfo Door { get; } = - new( - nameof(Door), - typeof(DB.FamilyInstance), - typeof(DB.FamilySymbol), - new List { BuiltInCategory.OST_Doors } - ); - public static RevitCategoryInfo Duct { get; } = - new( - nameof(Duct), - typeof(DB.Mechanical.Duct), - typeof(DB.MEPCurveType), - new List { BuiltInCategory.OST_DuctCurves, BuiltInCategory.OST_FlexDuctCurves } - ); - public static RevitCategoryInfo FamilyInstance { get; } = - new(nameof(FamilyInstance), typeof(DB.FamilyInstance), typeof(DB.FamilySymbol), new List()); - public static RevitCategoryInfo Floor { get; } = - new( - nameof(Floor), - typeof(DB.Floor), - typeof(DB.FloorType), - new List { BuiltInCategory.OST_Floors } - ); - public static RevitCategoryInfo Furniture { get; } = - new( - nameof(Furniture), - typeof(DB.FamilyInstance), - typeof(DB.FamilySymbol), - new List { BuiltInCategory.OST_Furniture } - ); - - //public static RevitCategoryInfo Material { get; } = new( - // nameof(Material), - // typeof(DB.Material), - // null, - // new List - // { - // BuiltInCategory.OST_Materials, - // BuiltInCategory.OST_PipeMaterials, - // BuiltInCategory.OST_WireMaterials - // }); - public static RevitCategoryInfo Pipe { get; } = - new( - nameof(Pipe), - typeof(DB.Plumbing.Pipe), - typeof(DB.MEPCurveType), - new List { BuiltInCategory.OST_PipeCurves, BuiltInCategory.OST_FlexPipeCurves } - ); - public static RevitCategoryInfo PlumbingFixture { get; } = - new( - nameof(PlumbingFixture), - typeof(DB.FamilyInstance), - typeof(DB.FamilySymbol), - new List { BuiltInCategory.OST_PlumbingFixtures } - ); - public static RevitCategoryInfo Roof { get; } = - new( - nameof(Roof), - typeof(DB.RoofBase), - typeof(DB.RoofType), - new List { BuiltInCategory.OST_Roofs, } - ); - public static RevitCategoryInfo Railing { get; } = - new( - nameof(Railing), - typeof(DB.Architecture.Railing), - typeof(DB.Architecture.RailingType), - new List() - ); - public static RevitCategoryInfo StructuralFraming { get; } = - new( - nameof(StructuralFraming), - typeof(DB.FamilyInstance), - typeof(DB.FamilySymbol), - new List { BuiltInCategory.OST_StructuralFraming }, - new List { "beam", "brace", "framing" } - ); - public static RevitCategoryInfo Wall { get; } = - new(nameof(Wall), typeof(DB.Wall), typeof(DB.WallType), new List { BuiltInCategory.OST_Walls }); - public static RevitCategoryInfo Window { get; } = - new( - nameof(Window), - typeof(DB.FamilyInstance), - typeof(DB.FamilySymbol), - new List { BuiltInCategory.OST_Windows } - ); - public static RevitCategoryInfo Wire { get; } = - new(nameof(Wire), typeof(DB.Electrical.Wire), typeof(DB.Electrical.WireType), new List()); - public static RevitCategoryInfo Undefined { get; } = - new(nameof(Undefined), typeof(RevitCategoryInfo), typeof(RevitCategoryInfo), new List()); -} diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/RevitCategoryInfo.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/RevitCategoryInfo.cs deleted file mode 100644 index f883f7c9e8..0000000000 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/RevitCategoryInfo.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using Autodesk.Revit.DB; - -namespace Speckle.Converters.RevitShared.Helpers; - -// review, maybe it doesn't need injecting, or maybe we inject a factory? -public class RevitCategoryInfo -{ - public RevitCategoryInfo( - string name, - Type instanceType, - Type familyType, - List categories, - List? categoryAliases = null - ) - { - CategoryName = name; - ElementInstanceType = instanceType; - ElementTypeType = familyType; - BuiltInCategories = categories; - CategoryAliases = categoryAliases ?? new List(); - } - - public string CategoryName { get; } - public Type ElementInstanceType { get; } - public Type ElementTypeType { get; } - public ICollection BuiltInCategories { get; } - public List CategoryAliases { get; } - - public bool ContainsRevitCategory(Category category) - { - return BuiltInCategories.Select(x => (int)x).Contains(category.Id.IntegerValue); - } - - public List GetElementTypes(Document document) - { - return GetElementTypes(document); - } - - [SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope")] - public List GetElementTypes(Document document) - where T : ElementType - { - // POC: why is this disabled? surely a using statement is golden here? - var collector = new FilteredElementCollector(document); - - if (BuiltInCategories.Count > 0) - { - using var filter = new ElementMulticategoryFilter(BuiltInCategories); - collector = collector.WherePasses(filter); - } - if (ElementTypeType != null) - { - collector = collector.OfClass(ElementTypeType); - } - var elementTypes = collector.WhereElementIsElementType().Cast().ToList(); - collector.Dispose(); - return elementTypes; - } - - public string GetCategorySpecificTypeName(string typeName) - { - return CategoryName + "_" + typeName; - } -} diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/RevitConversionContextStack.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/RevitConversionContextStack.cs deleted file mode 100644 index ce43a88901..0000000000 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/RevitConversionContextStack.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Autodesk.Revit.DB; -using Speckle.Converters.Common; - -namespace Speckle.Converters.RevitShared.Helpers; - -[System.Diagnostics.CodeAnalysis.SuppressMessage( - "Naming", - "CA1711:Identifiers should not have incorrect suffix", - Justification = "See base class justification" -)] -// POC: so this should *probably* be Document and NOT UI.UIDocument, the former is Conversion centric -// and the latter is more for connector -public class RevitConversionContextStack : ConversionContextStack, IRevitConversionContextStack -{ - public const double TOLERANCE = 0.0164042; // 5mm in ft - - public RevitConversionContextStack(RevitContext context, IHostToSpeckleUnitConverter unitConverter) - : base( - // POC: we probably should not get here without a valid document - // so should this perpetuate or do we assume this is valid? - // relting on the context.UIApplication?.ActiveUIDocument is not right - // this should be some IActiveDocument I suspect? - context.UIApplication?.ActiveUIDocument?.Document - ?? throw new SpeckleConversionException("Active UI document could not be determined"), - context.UIApplication.ActiveUIDocument.Document.GetUnits().GetFormatOptions(SpecTypeId.Length).GetUnitTypeId(), - unitConverter - ) { } -} diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/SendSelection.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/SendSelection.cs deleted file mode 100644 index c6b4590a6d..0000000000 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/SendSelection.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Speckle.Converters.RevitShared.Helpers; - -// POC: why do we need this send selection? -// why does conversion need to know about selection in this way? -public class SendSelection -{ - private readonly HashSet _selectedItemIds; - - public SendSelection(IEnumerable selectedItemIds) - { - _selectedItemIds = new HashSet(selectedItemIds); - } - - public bool Contains(string elementId) => _selectedItemIds.Contains(elementId); - - public IReadOnlyCollection SelectedItems => _selectedItemIds.ToList().AsReadOnly(); -} diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/SlopeArrowExtractor.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/SlopeArrowExtractor.cs index 9db6d14583..d5f69d29d3 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/SlopeArrowExtractor.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/SlopeArrowExtractor.cs @@ -1,43 +1,51 @@ +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; +using Speckle.InterfaceGenerator; +using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared.Helpers; +[GenerateAutoInterface] public class SlopeArrowExtractor : ISlopeArrowExtractor { - private readonly ITypedConverter _pointConverter; + private readonly ITypedConverter _pointConverter; private readonly ParameterValueExtractor _parameterValueExtractor; + private readonly IRevitFilterFactory _revitFilterFactory; public SlopeArrowExtractor( - ITypedConverter pointConverter, - ParameterValueExtractor parameterValueExtractor + ITypedConverter pointConverter, + ParameterValueExtractor parameterValueExtractor, + IRevitFilterFactory revitFilterFactory ) { _pointConverter = pointConverter; _parameterValueExtractor = parameterValueExtractor; + _revitFilterFactory = revitFilterFactory; } - public DB.ModelLine? GetSlopeArrow(DB.Element element) + public IRevitModelLine? GetSlopeArrow(IRevitElement element) { - IList? elementIds = null; - if (element is DB.Floor floor) + IList? elementIds = null; + if (element is IRevitFloor floor) { - elementIds = ((DB.Sketch)floor.Document.GetElement(floor.SketchId)).GetAllElements(); + elementIds = (floor.Document.GetElement(floor.SketchId).ToSketch().NotNull()).GetAllElements(); } if (elementIds == null) { - using var modelLineFilter = new DB.ElementCategoryFilter(DB.BuiltInCategory.OST_SketchLines); + using var modelLineFilter = _revitFilterFactory.CreateElementCategoryFilter(RevitBuiltInCategory.OST_SketchLines); elementIds = element.GetDependentElements(modelLineFilter); } foreach (var elementId in elementIds) { - if (element.Document.GetElement(elementId) is not DB.ModelLine line) + var line = element.Document.GetElement(elementId).ToModelLine(); + if (line is null) { continue; } - var offsetAtTailParameter = line.get_Parameter(DB.BuiltInParameter.SLOPE_START_HEIGHT); + var offsetAtTailParameter = line.GetParameter(RevitBuiltInParameter.SLOPE_START_HEIGHT); if (offsetAtTailParameter != null) { return line; @@ -46,26 +54,29 @@ ParameterValueExtractor parameterValueExtractor return null; } - public SOG.Point GetSlopeArrowHead(DB.ModelLine slopeArrow) + public SOG.Point GetSlopeArrowHead(IRevitModelLine slopeArrow) { - return _pointConverter.Convert(((DB.LocationCurve)slopeArrow.Location).Curve.GetEndPoint(1)); + return _pointConverter.Convert((slopeArrow.Location.ToLocationCurve().NotNull()).Curve.GetEndPoint(1)); } - public SOG.Point GetSlopeArrowTail(DB.ModelLine slopeArrow) + public SOG.Point GetSlopeArrowTail(IRevitModelLine slopeArrow) { - return _pointConverter.Convert(((DB.LocationCurve)slopeArrow.Location).Curve.GetEndPoint(0)); + return _pointConverter.Convert((slopeArrow.Location.ToLocationCurve().NotNull()).Curve.GetEndPoint(0)); } - public double GetSlopeArrowTailOffset(DB.ModelLine slopeArrow) + public double GetSlopeArrowTailOffset(IRevitModelLine slopeArrow) { - return _parameterValueExtractor.GetValueAsDouble(slopeArrow, DB.BuiltInParameter.SLOPE_START_HEIGHT); + return _parameterValueExtractor.GetValueAsDouble(slopeArrow, RevitBuiltInParameter.SLOPE_START_HEIGHT); } - public double GetSlopeArrowHeadOffset(DB.ModelLine slopeArrow, double tailOffset, out double slope) + public double GetSlopeArrowHeadOffset(IRevitModelLine slopeArrow, double tailOffset, out double slope) { - var specifyOffset = _parameterValueExtractor.GetValueAsInt(slopeArrow, DB.BuiltInParameter.SPECIFY_SLOPE_OR_OFFSET); + var specifyOffset = _parameterValueExtractor.GetValueAsInt( + slopeArrow, + RevitBuiltInParameter.SPECIFY_SLOPE_OR_OFFSET + ); - var lineLength = _parameterValueExtractor.GetValueAsDouble(slopeArrow, DB.BuiltInParameter.CURVE_ELEM_LENGTH); + var lineLength = _parameterValueExtractor.GetValueAsDouble(slopeArrow, RevitBuiltInParameter.CURVE_ELEM_LENGTH); slope = 0; double headOffset = 0; @@ -73,12 +84,12 @@ public double GetSlopeArrowHeadOffset(DB.ModelLine slopeArrow, double tailOffset if (specifyOffset == 1) { // in this scenario, slope is returned as a percentage. Divide by 100 to get the unitless form - slope = _parameterValueExtractor.GetValueAsDouble(slopeArrow, DB.BuiltInParameter.ROOF_SLOPE) / 100d; + slope = _parameterValueExtractor.GetValueAsDouble(slopeArrow, RevitBuiltInParameter.ROOF_SLOPE) / 100d; headOffset = tailOffset + lineLength * Math.Sin(Math.Atan(slope)); } else if (specifyOffset == 0) // 0 corrospondes to the "height at tail" option { - headOffset = _parameterValueExtractor.GetValueAsDouble(slopeArrow, DB.BuiltInParameter.SLOPE_END_HEIGHT); + headOffset = _parameterValueExtractor.GetValueAsDouble(slopeArrow, RevitBuiltInParameter.SLOPE_END_HEIGHT); slope = (headOffset - tailOffset) / lineLength; } @@ -86,3 +97,19 @@ public double GetSlopeArrowHeadOffset(DB.ModelLine slopeArrow, double tailOffset return headOffset; } } + +// POC: why do we need this send selection? +// why does conversion need to know about selection in this way? +public class SendSelection +{ + private readonly HashSet _selectedItemIds; + + public SendSelection(IEnumerable selectedItemIds) + { + _selectedItemIds = new HashSet(selectedItemIds); + } + + public bool Contains(string elementId) => _selectedItemIds.Contains(elementId); + + public IReadOnlyCollection SelectedItems => _selectedItemIds.ToList().AsReadOnly(); +} diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ToSpeckleConvertedObjectsCache.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ToSpeckleConvertedObjectsCache.cs deleted file mode 100644 index c4c91d9fb8..0000000000 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ToSpeckleConvertedObjectsCache.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Speckle.Core.Models; - -namespace Speckle.Converters.RevitShared.Helpers; - -// POC: review the cache? should this be a common class? -// Does caching work this way everywhere, i.e, string key and base value? -public sealed class ToSpeckleConvertedObjectsCache -{ - private readonly Dictionary _uniqueIdToConvertedBaseDict = new(); - - public void AddConvertedBase(string revitUniqueId, Base b) - { - _uniqueIdToConvertedBaseDict.Add(revitUniqueId, b); - } - - public bool ContainsBaseConvertedFromId(string revitUniqueId) - { - return _uniqueIdToConvertedBaseDict.ContainsKey(revitUniqueId); - } - - public bool TryGetConvertedBase(string revitUniqueId, out Base? value) - { - return _uniqueIdToConvertedBaseDict.TryGetValue(revitUniqueId, out value); - } -} diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/IReferencePointConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/IReferencePointConverter.cs deleted file mode 100644 index f526412336..0000000000 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/IReferencePointConverter.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Speckle.Converters.RevitShared; - -public interface IReferencePointConverter -{ - DB.XYZ ConvertToExternalCoordindates(DB.XYZ inbound, bool isPoint); -} diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/IRevitVersionConversionHelper.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/IRevitVersionConversionHelper.cs deleted file mode 100644 index 18a593cbbd..0000000000 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/IRevitVersionConversionHelper.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Speckle.Converters.RevitShared; - -public interface IRevitVersionConversionHelper -{ - bool IsCurveClosed(DB.NurbSpline nurbsSpline); -} diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BeamConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BeamConversionToSpeckle.cs index d6ee746e43..1e3608c4f3 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BeamConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BeamConversionToSpeckle.cs @@ -1,29 +1,30 @@ -using Objects; +using Objects; using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Converters.RevitShared.Helpers; using Speckle.Core.Models; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023; // POC: There is no validation on this converter to prevent conversion from "not a Revit Beam" to a Speckle Beam. // This will definitely explode if we tried. Goes back to the `CanConvert` functionality conversation. // As-is, what we are saying is that it can take "any Family Instance" and turn it into a Speckle.RevitBeam, which is far from correct. // CNX-9312 -public class BeamConversionToSpeckle : ITypedConverter +public class BeamConversionToSpeckle : ITypedConverter { - private readonly ITypedConverter _locationConverter; - private readonly ITypedConverter _levelConverter; - private readonly ParameterValueExtractor _parameterValueExtractor; - private readonly DisplayValueExtractor _displayValueExtractor; - private readonly ParameterObjectAssigner _parameterObjectAssigner; + private readonly ITypedConverter _locationConverter; + private readonly ITypedConverter _levelConverter; + private readonly IParameterValueExtractor _parameterValueExtractor; + private readonly IDisplayValueExtractor _displayValueExtractor; + private readonly IParameterObjectAssigner _parameterObjectAssigner; public BeamConversionToSpeckle( - ITypedConverter locationConverter, - ITypedConverter levelConverter, - ParameterValueExtractor parameterValueExtractor, - DisplayValueExtractor displayValueExtractor, - ParameterObjectAssigner parameterObjectAssigner + ITypedConverter locationConverter, + ITypedConverter levelConverter, + IParameterValueExtractor parameterValueExtractor, + IDisplayValueExtractor displayValueExtractor, + IParameterObjectAssigner parameterObjectAssigner ) { _locationConverter = locationConverter; @@ -33,7 +34,7 @@ ParameterObjectAssigner parameterObjectAssigner _parameterObjectAssigner = parameterObjectAssigner; } - public SOBR.RevitBeam Convert(DB.FamilyInstance target) + public SOBR.RevitBeam Convert(IRevitFamilyInstance target) { var baseGeometry = _locationConverter.Convert(target.Location); if (baseGeometry is not ICurve baseCurve) @@ -42,7 +43,8 @@ public SOBR.RevitBeam Convert(DB.FamilyInstance target) $"Beam location conversion did not yield an ICurve, instead it yielded an object of type {baseGeometry.GetType()}" ); } - var symbol = (DB.FamilySymbol)target.Document.GetElement(target.GetTypeId()); + + var symbol = target.Document.GetElement(target.GetTypeId()).ToFamilySymbol().NotNull(); SOBR.RevitBeam speckleBeam = new() @@ -52,9 +54,9 @@ public SOBR.RevitBeam Convert(DB.FamilyInstance target) baseLine = baseCurve }; - var level = _parameterValueExtractor.GetValueAsDocumentObject( + var level = _parameterValueExtractor.GetValueAsDocumentObject( target, - DB.BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM + RevitBuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM ); speckleBeam.level = _levelConverter.Convert(level); diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BoundarySegmentConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BoundarySegmentConversionToSpeckle.cs index 8f02d4c345..87c416bc6d 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BoundarySegmentConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BoundarySegmentConversionToSpeckle.cs @@ -1,18 +1,19 @@ using Objects; using Speckle.Converters.Common.Objects; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023; -public class BoundarySegmentConversionToSpeckle : ITypedConverter, SOG.Polycurve> +public class BoundarySegmentConversionToSpeckle : ITypedConverter, SOG.Polycurve> { - private readonly ITypedConverter _curveConverter; + private readonly ITypedConverter _curveConverter; - public BoundarySegmentConversionToSpeckle(ITypedConverter curveConverter) + public BoundarySegmentConversionToSpeckle(ITypedConverter curveConverter) { _curveConverter = curveConverter; } - public SOG.Polycurve Convert(IList target) + public SOG.Polycurve Convert(IList target) { if (target.Count == 0) { @@ -22,7 +23,7 @@ public SOG.Polycurve Convert(IList target) var poly = new SOG.Polycurve(); foreach (var segment in target) { - DB.Curve revitCurve = segment.GetCurve(); + IRevitCurve revitCurve = segment.GetCurve(); var curve = _curveConverter.Convert(revitCurve); // POC: We used to attach the `elementID` of every curve in a PolyCurve as a dynamic property. diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BraceToSpeckleConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BraceToSpeckleConverter.cs index ccae249fe5..b16eacfb2a 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BraceToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BraceToSpeckleConverter.cs @@ -1,24 +1,25 @@ -using Speckle.Converters.Common.Objects; +using Speckle.Converters.Common.Objects; using Speckle.Core.Models; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023; // POC: There is no validation on this converter to prevent conversion from "not a Revit Beam" to a Speckle Beam. // This will definitely explode if we tried. Goes back to the `CanConvert` functionality conversation. // As-is, what we are saying is that it can take "any Family Instance" and turn it into a Speckle.RevitBeam, which is far from correct. // CNX-9312 -public class BraceToSpeckleConverter : ITypedConverter +public class BraceToSpeckleConverter : ITypedConverter { - private readonly ITypedConverter _beamConverter; + private readonly ITypedConverter _beamConverter; - public BraceToSpeckleConverter(ITypedConverter beamConverter) + public BraceToSpeckleConverter(ITypedConverter beamConverter) { _beamConverter = beamConverter; } - public SOBR.RevitBrace Convert(DB.FamilyInstance target) + public SOBR.RevitBrace Convert(IRevitFamilyInstance target) { - // POC: we might want some easy one-liner here to FamilyMatchesOrThrow(target, DB.Structure.StructuralType.Brace) or similar + // POC: we might want some easy one-liner here to FamilyMatchesOrThrow(target, IRevitStructure.StructuralType.Brace) or similar // and added in each Convert // POC: this and the beam lost the notes we were returning, though this seems against even the original pattern diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs index 3c5b738aa9..e729e75630 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs @@ -1,31 +1,30 @@ -using Autodesk.Revit.DB; -using Objects; -using Objects.BuiltElements.Revit; +using Objects; using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Converters.RevitShared.Helpers; using Speckle.Core.Models; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023; // POC: There is no validation on this converter to prevent conversion from "not a Revit Beam" to a Speckle Beam. // This will definitely explode if we tried. Goes back to the `CanConvert` functionality conversation. -public class ColumnConversionToSpeckle : ITypedConverter +public class ColumnConversionToSpeckle : ITypedConverter { - private readonly ITypedConverter _locationConverter; - private readonly ITypedConverter _levelConverter; - private readonly ParameterValueExtractor _parameterValueExtractor; - private readonly DisplayValueExtractor _displayValueExtractor; - private readonly IRevitConversionContextStack _contextStack; - private readonly ParameterObjectAssigner _parameterObjectAssigner; + private readonly ITypedConverter _locationConverter; + private readonly ITypedConverter _levelConverter; + private readonly IParameterValueExtractor _parameterValueExtractor; + private readonly IDisplayValueExtractor _displayValueExtractor; + private readonly IConversionContextStack _contextStack; + private readonly IParameterObjectAssigner _parameterObjectAssigner; public ColumnConversionToSpeckle( - ITypedConverter locationConverter, - ITypedConverter levelConverter, - ParameterValueExtractor parameterValueExtractor, - DisplayValueExtractor displayValueExtractor, - IRevitConversionContextStack contextStack, - ParameterObjectAssigner parameterObjectAssigner + ITypedConverter locationConverter, + ITypedConverter levelConverter, + IParameterValueExtractor parameterValueExtractor, + IDisplayValueExtractor displayValueExtractor, + IConversionContextStack contextStack, + IParameterObjectAssigner parameterObjectAssigner ) { _locationConverter = locationConverter; @@ -36,40 +35,41 @@ ParameterObjectAssigner parameterObjectAssigner _parameterObjectAssigner = parameterObjectAssigner; } - public RevitColumn Convert(DB.FamilyInstance target) + public SOBR.RevitColumn Convert(IRevitFamilyInstance target) { - FamilySymbol symbol = (FamilySymbol)target.Document.GetElement(target.GetTypeId()); + var symbol = target.Document.GetElement(target.GetTypeId()).ToFamilySymbol().NotNull(); - RevitColumn speckleColumn = + SOBR.RevitColumn speckleColumn = new() { family = symbol.FamilyName, type = target.Document.GetElement(target.GetTypeId()).Name }; - Level level = _parameterValueExtractor.GetValueAsDocumentObject( + var level = _parameterValueExtractor.GetValueAsDocumentObject( target, - BuiltInParameter.FAMILY_BASE_LEVEL_PARAM + RevitBuiltInParameter.FAMILY_BASE_LEVEL_PARAM ); speckleColumn.level = _levelConverter.Convert(level); - Level topLevel = _parameterValueExtractor.GetValueAsDocumentObject( + var topLevel = _parameterValueExtractor.GetValueAsDocumentObject( target, - BuiltInParameter.FAMILY_TOP_LEVEL_PARAM + RevitBuiltInParameter.FAMILY_TOP_LEVEL_PARAM ); speckleColumn.topLevel = _levelConverter.Convert(topLevel); speckleColumn.baseOffset = _parameterValueExtractor.GetValueAsDouble( target, - DB.BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM + RevitBuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM ); speckleColumn.topOffset = _parameterValueExtractor.GetValueAsDouble( target, - DB.BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM + RevitBuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM ); speckleColumn.facingFlipped = target.FacingFlipped; speckleColumn.handFlipped = target.HandFlipped; speckleColumn.isSlanted = target.IsSlantedColumn; - if (target.Location is LocationPoint locationPoint) + var locationPoint = target.Location.ToLocationPoint(); + if (locationPoint is not null) { speckleColumn.rotation = locationPoint.Rotation; } @@ -85,7 +85,7 @@ public RevitColumn Convert(DB.FamilyInstance target) return speckleColumn; } - private ICurve? GetBaseCurve(DB.FamilyInstance target, double topLevelElevation, double topLevelOffset) + private ICurve? GetBaseCurve(IRevitFamilyInstance target, double topLevelElevation, double topLevelOffset) { Base baseGeometry = _locationConverter.Convert(target.Location); ICurve? baseCurve = baseGeometry as ICurve; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/ArcToSpeckleConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/ArcToSpeckleConverter.cs index d6774a710b..a74724e53a 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/ArcToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/ArcToSpeckleConverter.cs @@ -1,42 +1,46 @@ -using Objects.Primitive; +using Objects.Primitive; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Converters.RevitShared.Helpers; using Speckle.Converters.RevitShared.Services; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023.ToSpeckle; -public class ArcToSpeckleConverter : ITypedConverter +public class ArcToSpeckleConverter : ITypedConverter { - private readonly IRevitConversionContextStack _contextStack; - private readonly ITypedConverter _xyzToPointConverter; - private readonly ITypedConverter _planeConverter; - private readonly ScalingServiceToSpeckle _scalingService; + private readonly IConversionContextStack _contextStack; + private readonly ITypedConverter _xyzToPointConverter; + private readonly ITypedConverter _planeConverter; + private readonly IScalingServiceToSpeckle _scalingService; + private readonly IRevitPlaneUtils _revitPlaneUtils; public ArcToSpeckleConverter( - IRevitConversionContextStack contextStack, - ITypedConverter xyzToPointConverter, - ITypedConverter planeConverter, - ScalingServiceToSpeckle scalingService + IConversionContextStack contextStack, + ITypedConverter xyzToPointConverter, + ITypedConverter planeConverter, + IScalingServiceToSpeckle scalingService, + IRevitPlaneUtils revitPlaneUtils ) { _contextStack = contextStack; _xyzToPointConverter = xyzToPointConverter; _planeConverter = planeConverter; _scalingService = scalingService; + _revitPlaneUtils = revitPlaneUtils; } - public SOG.Arc Convert(DB.Arc target) + public SOG.Arc Convert(IRevitArc target) { // see https://forums.autodesk.com/t5/revit-api-forum/how-to-retrieve-startangle-and-endangle-of-arc-object/td-p/7637128 - var arcPlane = DB.Plane.CreateByOriginAndBasis(target.Center, target.XDirection, target.YDirection); - DB.XYZ center = target.Center; + var arcPlane = _revitPlaneUtils.CreateByOriginAndBasis(target.Center, target.XDirection, target.YDirection); + IRevitXYZ center = target.Center; - DB.XYZ dir0 = (target.GetEndPoint(0) - center).Normalize(); - DB.XYZ dir1 = (target.GetEndPoint(1) - center).Normalize(); + IRevitXYZ dir0 = (target.GetEndPoint(0).Subtract(center)).Normalize(); + IRevitXYZ dir1 = (target.GetEndPoint(1).Subtract(center)).Normalize(); - DB.XYZ start = target.Evaluate(0, true); - DB.XYZ end = target.Evaluate(1, true); - DB.XYZ mid = target.Evaluate(0.5, true); + IRevitXYZ start = target.Evaluate(0, true); + IRevitXYZ end = target.Evaluate(1, true); + IRevitXYZ mid = target.Evaluate(0.5, true); double startAngle = target.XDirection.AngleOnPlaneTo(dir0, target.Normal); double endAngle = target.XDirection.AngleOnPlaneTo(dir1, target.Normal); diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/BoundingBoxXYZToSpeckleConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/BoundingBoxXYZToSpeckleConverter.cs index a891579ad5..b8d88bbe1f 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/BoundingBoxXYZToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/BoundingBoxXYZToSpeckleConverter.cs @@ -1,27 +1,31 @@ -using Objects.Primitive; +using Objects.Primitive; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Converters.RevitShared.Helpers; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023.ToSpeckle; -public class BoundingBoxXYZToSpeckleConverter : ITypedConverter +public class BoundingBoxXYZToSpeckleConverter : ITypedConverter { - private readonly IRevitConversionContextStack _contextStack; - private readonly ITypedConverter _xyzToPointConverter; - private readonly ITypedConverter _planeConverter; + private readonly IConversionContextStack _contextStack; + private readonly ITypedConverter _xyzToPointConverter; + private readonly ITypedConverter _planeConverter; + private readonly IRevitPlaneUtils _revitPlaneUtils; public BoundingBoxXYZToSpeckleConverter( - IRevitConversionContextStack contextStack, - ITypedConverter xyzToPointConverter, - ITypedConverter planeConverter + IConversionContextStack contextStack, + ITypedConverter xyzToPointConverter, + ITypedConverter planeConverter, + IRevitPlaneUtils revitPlaneUtils ) { _contextStack = contextStack; _xyzToPointConverter = xyzToPointConverter; _planeConverter = planeConverter; + _revitPlaneUtils = revitPlaneUtils; } - public SOG.Box Convert(DB.BoundingBoxXYZ target) + public SOG.Box Convert(IRevitBoundingBoxXYZ target) { // convert min and max pts to speckle first var min = _xyzToPointConverter.Convert(target.Min); @@ -29,7 +33,7 @@ public SOG.Box Convert(DB.BoundingBoxXYZ target) // get the base plane of the bounding box from the transform var transform = target.Transform; - var plane = DB.Plane.CreateByOriginAndBasis( + var plane = _revitPlaneUtils.CreateByOriginAndBasis( transform.Origin, transform.BasisX.Normalize(), transform.BasisY.Normalize() diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CircleToSpeckleConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CircleToSpeckleConverter.cs index 7abdc08cfc..f36fd115ea 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CircleToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CircleToSpeckleConverter.cs @@ -1,32 +1,36 @@ +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Converters.RevitShared.Helpers; using Speckle.Converters.RevitShared.Services; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023.ToSpeckle; -public class CircleToSpeckleConverter : ITypedConverter +public class CircleToSpeckleConverter : ITypedConverter { - private readonly IRevitConversionContextStack _contextStack; - private readonly ITypedConverter _planeConverter; - private readonly ScalingServiceToSpeckle _scalingService; + private readonly IConversionContextStack _contextStack; + private readonly ITypedConverter _planeConverter; + private readonly IScalingServiceToSpeckle _scalingService; + private readonly IRevitPlaneUtils _revitPlaneUtils; public CircleToSpeckleConverter( - IRevitConversionContextStack contextStack, - ITypedConverter planeConverter, - ScalingServiceToSpeckle scalingService + IConversionContextStack contextStack, + ITypedConverter planeConverter, + IScalingServiceToSpeckle scalingService, + IRevitPlaneUtils revitPlaneUtils ) { _contextStack = contextStack; _planeConverter = planeConverter; _scalingService = scalingService; + _revitPlaneUtils = revitPlaneUtils; } - public SOG.Circle Convert(DB.Arc target) + public SOG.Circle Convert(IRevitArc target) { // POC: should we check for arc of 360 and throw? Original CircleToSpeckle did not do this. // see https://forums.autodesk.com/t5/revit-api-forum/how-to-retrieve-startangle-and-endangle-of-arc-object/td-p/7637128 - var arcPlane = DB.Plane.CreateByNormalAndOrigin(target.Normal, target.Center); + var arcPlane = _revitPlaneUtils.CreateByNormalAndOrigin(target.Normal, target.Center); var c = new SOG.Circle() { plane = _planeConverter.Convert(arcPlane), diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveArrArrayToSpecklePolycurveConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveArrArrayToSpecklePolycurveConverter.cs index 4644bc1435..5236040a30 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveArrArrayToSpecklePolycurveConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveArrArrayToSpecklePolycurveConverter.cs @@ -1,34 +1,25 @@ -using Autodesk.Revit.DB; -using Objects.Geometry; -using Speckle.Converters.Common.Objects; +using Speckle.Converters.Common.Objects; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.Raw; +namespace Speckle.Converters.Revit2023.ToSpeckle; -internal sealed class CurveArrArrayToSpecklePolycurveConverter : ITypedConverter> +public sealed class CurveArrArrayToSpecklePolycurveConverter : ITypedConverter> { - private readonly ITypedConverter _curveArrayConverter; + private readonly ITypedConverter _curveArrayConverter; - public CurveArrArrayToSpecklePolycurveConverter(ITypedConverter curveArrayConverter) + public CurveArrArrayToSpecklePolycurveConverter(ITypedConverter curveArrayConverter) { _curveArrayConverter = curveArrayConverter; } - public List Convert(CurveArrArray target) + public List Convert(IRevitCurveArrArray target) { - List polycurves = new(); - foreach (var curveArray in GetCurveArrays(target)) + List polycurves = new(target.Count); + foreach (var curveArray in target) { polycurves.Add(_curveArrayConverter.Convert(curveArray)); } return polycurves; } - - private IEnumerable GetCurveArrays(DB.CurveArrArray curveArrArray) - { - for (var i = 0; i < curveArrArray.Size; i++) - { - yield return curveArrArray.get_Item(i); - } - } } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveArrayConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveArrayConversionToSpeckle.cs index 8ec80fe9f7..be3bb98162 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveArrayConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveArrayConversionToSpeckle.cs @@ -1,22 +1,22 @@ -using Autodesk.Revit.DB; -using Objects; -using Objects.Geometry; +using Objects; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Converters.RevitShared.Helpers; +using Speckle.Converters.RevitShared; using Speckle.Converters.RevitShared.Services; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023.ToSpeckle; -public sealed class CurveArrayConversionToSpeckle : ITypedConverter +public sealed class CurveArrayConversionToSpeckle : ITypedConverter { - private readonly IRevitConversionContextStack _contextStack; - private readonly ScalingServiceToSpeckle _scalingService; - private readonly ITypedConverter _curveConverter; + private readonly IConversionContextStack _contextStack; + private readonly IScalingServiceToSpeckle _scalingService; + private readonly ITypedConverter _curveConverter; public CurveArrayConversionToSpeckle( - IRevitConversionContextStack contextStack, - ScalingServiceToSpeckle scalingService, - ITypedConverter curveConverter + IConversionContextStack contextStack, + IScalingServiceToSpeckle scalingService, + ITypedConverter curveConverter ) { _contextStack = contextStack; @@ -24,15 +24,14 @@ public CurveArrayConversionToSpeckle( _curveConverter = curveConverter; } - public Polycurve Convert(CurveArray target) + public SOG.Polycurve Convert(IRevitCurveArray target) { - List curves = target.Cast().ToList(); + List curves = target.Cast().ToList(); - return new Polycurve() + return new SOG.Polycurve() { units = _contextStack.Current.SpeckleUnits, - closed = - curves.First().GetEndPoint(0).DistanceTo(curves.Last().GetEndPoint(1)) < RevitConversionContextStack.TOLERANCE, + closed = curves.First().GetEndPoint(0).DistanceTo(curves.Last().GetEndPoint(1)) < RevitConstants.TOLERANCE, length = _scalingService.ScaleLength(curves.Sum(x => x.Length)), segments = curves.Select(x => _curveConverter.Convert(x)).ToList() }; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveConversionToSpeckle.cs index 0b034a779c..3798e42cbf 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveConversionToSpeckle.cs @@ -1,25 +1,26 @@ -using Objects; -using Speckle.Converters.Common.Objects; +using Objects; using Speckle.Converters.Common; +using Speckle.Converters.Common.Objects; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023.ToSpeckle; -public class CurveConversionToSpeckle : ITypedConverter +public class CurveConversionToSpeckle : ITypedConverter { - private readonly ITypedConverter _lineConverter; - private readonly ITypedConverter _arcConverter; - private readonly ITypedConverter _circleConverter; - private readonly ITypedConverter _ellipseConverter; - private readonly ITypedConverter _nurbsConverter; - private readonly ITypedConverter _hermiteConverter; // POC: should this be ICurve? + private readonly ITypedConverter _lineConverter; + private readonly ITypedConverter _arcConverter; + private readonly ITypedConverter _circleConverter; + private readonly ITypedConverter _ellipseConverter; + private readonly ITypedConverter _nurbsConverter; + private readonly ITypedConverter _hermiteConverter; // POC: should this be ICurve? public CurveConversionToSpeckle( - ITypedConverter lineConverter, - ITypedConverter arcConverter, - ITypedConverter circleConverter, - ITypedConverter ellipseConverter, - ITypedConverter nurbsConverter, - ITypedConverter hermiteConverter + ITypedConverter lineConverter, + ITypedConverter arcConverter, + ITypedConverter circleConverter, + ITypedConverter ellipseConverter, + ITypedConverter nurbsConverter, + ITypedConverter hermiteConverter ) { _lineConverter = lineConverter; @@ -30,16 +31,16 @@ public CurveConversionToSpeckle( _hermiteConverter = hermiteConverter; } - public ICurve Convert(DB.Curve target) + public ICurve Convert(IRevitCurve target) { return target switch { - DB.Line line => _lineConverter.Convert(line), + IRevitLine line => _lineConverter.Convert(line), // POC: are maybe arc.IsCyclic ? - DB.Arc arc => arc.IsClosed ? _circleConverter.Convert(arc) : _arcConverter.Convert(arc), - DB.Ellipse ellipse => _ellipseConverter.Convert(ellipse), - DB.NurbSpline nurbs => _nurbsConverter.Convert(nurbs), - DB.HermiteSpline hermite => _hermiteConverter.Convert(hermite), + IRevitArc arc => arc.IsClosed ? _circleConverter.Convert(arc) : _arcConverter.Convert(arc), + IRevitEllipse ellipse => _ellipseConverter.Convert(ellipse), + IRevitNurbSpline nurbs => _nurbsConverter.Convert(nurbs), + IRevitHermiteSpline hermite => _hermiteConverter.Convert(hermite), _ => throw new SpeckleConversionException($"Unsupported curve type {target.GetType()}") }; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/EllipseToSpeckleConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/EllipseToSpeckleConverter.cs index 96ca62f8f1..4cd4943bea 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/EllipseToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/EllipseToSpeckleConverter.cs @@ -1,30 +1,40 @@ -using Objects.Primitive; +using Objects.Primitive; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Converters.RevitShared.Helpers; using Speckle.Converters.RevitShared.Services; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023.ToSpeckle; -public class EllipseToSpeckleConverter : ITypedConverter +public class EllipseToSpeckleConverter : ITypedConverter { - private readonly IRevitConversionContextStack _contextStack; - private readonly ITypedConverter _planeConverter; - private readonly ScalingServiceToSpeckle _scalingService; + private readonly IConversionContextStack _contextStack; + private readonly ITypedConverter _planeConverter; + private readonly IScalingServiceToSpeckle _scalingService; + private readonly IRevitPlaneUtils _revitPlaneUtils; public EllipseToSpeckleConverter( - IRevitConversionContextStack contextStack, - ITypedConverter planeConverter, - ScalingServiceToSpeckle scalingService + IConversionContextStack contextStack, + ITypedConverter planeConverter, + IScalingServiceToSpeckle scalingService, + IRevitPlaneUtils revitPlaneUtils ) { _contextStack = contextStack; _planeConverter = planeConverter; _scalingService = scalingService; + _revitPlaneUtils = revitPlaneUtils; } - public SOG.Ellipse Convert(DB.Ellipse target) + public SOG.Ellipse Convert(IRevitEllipse target) { - using (DB.Plane basePlane = DB.Plane.CreateByOriginAndBasis(target.Center, target.XDirection, target.YDirection)) + using ( + IRevitPlane basePlane = _revitPlaneUtils.CreateByOriginAndBasis( + target.Center, + target.XDirection, + target.YDirection + ) + ) { var trim = target.IsBound ? new Interval(target.GetEndParameter(0), target.GetEndParameter(1)) : null; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/HermiteSplineToSpeckleConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/HermiteSplineToSpeckleConverter.cs index 5aa2a07ed2..9c5285dc98 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/HermiteSplineToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/HermiteSplineToSpeckleConverter.cs @@ -1,19 +1,25 @@ -using Speckle.Converters.Common.Objects; +using Speckle.Converters.Common.Objects; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023.ToSpeckle; -public class HerminteSplitToSpeckleConverter : ITypedConverter +public class HermiteSplineToSpeckleConverter : ITypedConverter { - private readonly ITypedConverter _splineConverter; + private readonly ITypedConverter _splineConverter; + private readonly IRevitNurbSplineUtils _revitNurbSplineUtils; - public HerminteSplitToSpeckleConverter(ITypedConverter splineConverter) + public HermiteSplineToSpeckleConverter( + ITypedConverter splineConverter, + IRevitNurbSplineUtils revitNurbSplineUtils + ) { _splineConverter = splineConverter; + _revitNurbSplineUtils = revitNurbSplineUtils; } - public SOG.Curve Convert(DB.HermiteSpline target) + public SOG.Curve Convert(IRevitHermiteSpline target) { - var nurbs = DB.NurbSpline.Create(target); + var nurbs = _revitNurbSplineUtils.Create(target); return _splineConverter.Convert(nurbs); } } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/LineConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/LineConversionToSpeckle.cs index 2405cf0b22..d50873233c 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/LineConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/LineConversionToSpeckle.cs @@ -1,20 +1,21 @@ -using Objects.Primitive; +using Objects.Primitive; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Converters.RevitShared.Helpers; using Speckle.Converters.RevitShared.Services; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023.ToSpeckle; -public class LineConversionToSpeckle : ITypedConverter +public class LineConversionToSpeckle : ITypedConverter { - private readonly IRevitConversionContextStack _contextStack; - private readonly ITypedConverter _xyzToPointConverter; - private readonly ScalingServiceToSpeckle _scalingService; + private readonly IConversionContextStack _contextStack; + private readonly ITypedConverter _xyzToPointConverter; + private readonly IScalingServiceToSpeckle _scalingService; public LineConversionToSpeckle( - IRevitConversionContextStack contextStack, - ITypedConverter xyzToPointConverter, - ScalingServiceToSpeckle scalingService + IConversionContextStack contextStack, + ITypedConverter xyzToPointConverter, + IScalingServiceToSpeckle scalingService ) { _contextStack = contextStack; @@ -22,7 +23,7 @@ ScalingServiceToSpeckle scalingService _scalingService = scalingService; } - public SOG.Line Convert(DB.Line target) => + public SOG.Line Convert(IRevitLine target) => new() { units = _contextStack.Current.SpeckleUnits, diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/MeshByMaterialDictionaryToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/MeshByMaterialDictionaryToSpeckle.cs index 29b0bd9f98..0df626be74 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/MeshByMaterialDictionaryToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/MeshByMaterialDictionaryToSpeckle.cs @@ -1,20 +1,21 @@ using Objects.Other; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Converters.RevitShared.Helpers; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023.ToSpeckle; public class MeshByMaterialDictionaryToSpeckle - : ITypedConverter>, List> + : ITypedConverter>, List> { - private readonly IRevitConversionContextStack _contextStack; - private readonly ITypedConverter _xyzToPointConverter; - private readonly ITypedConverter _materialConverter; + private readonly IConversionContextStack _contextStack; + private readonly ITypedConverter _xyzToPointConverter; + private readonly ITypedConverter _materialConverter; public MeshByMaterialDictionaryToSpeckle( - ITypedConverter materialConverter, - IRevitConversionContextStack contextStack, - ITypedConverter xyzToPointConverter + ITypedConverter materialConverter, + IConversionContextStack contextStack, + ITypedConverter xyzToPointConverter ) { _materialConverter = materialConverter; @@ -25,24 +26,24 @@ public MeshByMaterialDictionaryToSpeckle( /// /// Converts a dictionary of Revit meshes, where key is MaterialId, into a list of Speckle meshes. /// - /// A dictionary with DB.ElementId keys and List of DB.Mesh values. + /// A dictionary with IRevitElementId keys and List of IRevitMesh values. /// /// Returns a list of objects where each mesh represents one unique material in the input dictionary. /// /// /// Be aware that this method internally creates a new instance of for each unique material in the input dictionary. /// These meshes are created with an initial capacity based on the size of the vertex and face arrays to avoid unnecessary resizing. - /// Also note that, for each unique material, the method tries to retrieve the related DB.Material from the current document and convert it. If the conversion is successful, + /// Also note that, for each unique material, the method tries to retrieve the related IRevitMaterial from the current document and convert it. If the conversion is successful, /// the material is added to the corresponding Speckle mesh. If the conversion fails, the operation simply continues without the material. /// - public List Convert(Dictionary> target) + public List Convert(Dictionary> target) { var result = new List(target.Keys.Count); foreach (var meshData in target) { - DB.ElementId materialId = meshData.Key; - List meshes = meshData.Value; + IRevitElementId materialId = meshData.Key; + List meshes = meshData.Value; // We compute the final size of the arrays to prevent unnecessary resizing. (int verticesSize, int facesSize) = GetVertexAndFaceListSize(meshes); @@ -55,7 +56,7 @@ public MeshByMaterialDictionaryToSpeckle( ); var doc = _contextStack.Current.Document; - if (doc.GetElement(materialId) is DB.Material material) + if (doc.GetElement(materialId) is IRevitMaterial material) { speckleMesh["renderMaterial"] = _materialConverter.Convert(material); } @@ -72,7 +73,7 @@ public MeshByMaterialDictionaryToSpeckle( return result; } - private void AppendToSpeckleMesh(DB.Mesh mesh, SOG.Mesh speckleMesh) + private void AppendToSpeckleMesh(IRevitMesh mesh, SOG.Mesh speckleMesh) { int faceIndexOffset = speckleMesh.vertices.Count / 3; @@ -86,16 +87,16 @@ private void AppendToSpeckleMesh(DB.Mesh mesh, SOG.Mesh speckleMesh) for (int i = 0; i < mesh.NumTriangles; i++) { - var triangle = mesh.get_Triangle(i); + var triangle = mesh.GetTriangle(i); speckleMesh.faces.Add(3); // TRIANGLE flag - speckleMesh.faces.Add((int)triangle.get_Index(0) + faceIndexOffset); - speckleMesh.faces.Add((int)triangle.get_Index(1) + faceIndexOffset); - speckleMesh.faces.Add((int)triangle.get_Index(2) + faceIndexOffset); + speckleMesh.faces.Add((int)triangle.GetIndex(0) + faceIndexOffset); + speckleMesh.faces.Add((int)triangle.GetIndex(1) + faceIndexOffset); + speckleMesh.faces.Add((int)triangle.GetIndex(2) + faceIndexOffset); } } - private static (int vertexCount, int) GetVertexAndFaceListSize(List meshes) + private static (int vertexCount, int) GetVertexAndFaceListSize(List meshes) { int numberOfVertices = 0; int numberOfFaces = 0; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/MeshConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/MeshConversionToSpeckle.cs index 2f6c494ba0..8321d14ca2 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/MeshConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/MeshConversionToSpeckle.cs @@ -1,19 +1,20 @@ using Objects.Other; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Converters.RevitShared.Helpers; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023.ToSpeckle; -public class MeshConversionToSpeckle : ITypedConverter +public class MeshConversionToSpeckle : ITypedConverter { - private readonly ITypedConverter _xyzToPointConverter; - private readonly ITypedConverter _materialConverter; - private readonly IRevitConversionContextStack _contextStack; + private readonly ITypedConverter _xyzToPointConverter; + private readonly ITypedConverter _materialConverter; + private readonly IConversionContextStack _contextStack; public MeshConversionToSpeckle( - IRevitConversionContextStack contextStack, - ITypedConverter xyzToPointConverter, - ITypedConverter materialConverter + IConversionContextStack contextStack, + ITypedConverter xyzToPointConverter, + ITypedConverter materialConverter ) { _contextStack = contextStack; @@ -21,15 +22,17 @@ public MeshConversionToSpeckle( _materialConverter = materialConverter; } - public SOG.Mesh Convert(DB.Mesh target) + public SOG.Mesh Convert(IRevitMesh target) { var doc = _contextStack.Current.Document; List vertices = GetSpeckleMeshVertexData(target); List faces = GetSpeckleMeshFaceData(target); + var element = doc.GetElement(target.MaterialElementId); + var revitMaterial = element.ToMaterial(); RenderMaterial? speckleMaterial = null; - if (doc.GetElement(target.MaterialElementId) is DB.Material revitMaterial) + if (revitMaterial is not null) { speckleMaterial = _materialConverter.Convert(revitMaterial); } @@ -40,7 +43,7 @@ public SOG.Mesh Convert(DB.Mesh target) }; } - private List GetSpeckleMeshVertexData(DB.Mesh target) + private List GetSpeckleMeshVertexData(IRevitMesh target) { var vertices = new List(target.Vertices.Count * 3); @@ -52,12 +55,12 @@ private List GetSpeckleMeshVertexData(DB.Mesh target) return vertices; } - private List GetSpeckleMeshFaceData(DB.Mesh target) + private List GetSpeckleMeshFaceData(IRevitMesh target) { var faces = new List(target.NumTriangles * 4); for (int i = 0; i < target.NumTriangles; i++) { - var triangle = target.get_Triangle(i); + var triangle = target.GetTriangle(i); faces.AddRange(GetMeshTriangleData(triangle)); } @@ -73,12 +76,12 @@ private List GetSpeckleMeshFaceData(DB.Mesh target) /// Output format is a 4 item list with format [3, v1, v2, v3]; where the first item is the triangle flag (for speckle) /// and the 3 following numbers are the indices of each vertex in the vertex list. /// - private IReadOnlyList GetMeshTriangleData(DB.MeshTriangle triangle) => + private IReadOnlyList GetMeshTriangleData(IRevitMeshTriangle triangle) => new[] { 3, // The TRIANGLE flag in speckle - (int)triangle.get_Index(0), - (int)triangle.get_Index(1), - (int)triangle.get_Index(2) + (int)triangle.GetIndex(0), + (int)triangle.GetIndex(1), + (int)triangle.GetIndex(2) }; } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/NurbsSplineToSpeckleConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/NurbsSplineToSpeckleConverter.cs index 7229f639e3..539aebc888 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/NurbsSplineToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/NurbsSplineToSpeckleConverter.cs @@ -1,22 +1,23 @@ -using Objects.Primitive; +using Objects.Primitive; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Converters.RevitShared.Helpers; using Speckle.Converters.RevitShared.Services; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023.ToSpeckle; -public class NurbsSplineToSpeckleConverter : ITypedConverter +public class NurbsSplineToSpeckleConverter : ITypedConverter { private readonly IRevitVersionConversionHelper _conversionHelper; - private readonly IRevitConversionContextStack _contextStack; - private readonly ITypedConverter _xyzToPointConverter; - private readonly ScalingServiceToSpeckle _scalingService; + private readonly IConversionContextStack _contextStack; + private readonly ITypedConverter _xyzToPointConverter; + private readonly IScalingServiceToSpeckle _scalingService; public NurbsSplineToSpeckleConverter( IRevitVersionConversionHelper conversionHelper, - IRevitConversionContextStack contextStack, - ITypedConverter xyzToPointConverter, - ScalingServiceToSpeckle scalingService + IConversionContextStack contextStack, + ITypedConverter xyzToPointConverter, + IScalingServiceToSpeckle scalingService ) { _conversionHelper = conversionHelper; @@ -25,7 +26,7 @@ ScalingServiceToSpeckle scalingService _scalingService = scalingService; } - public SOG.Curve Convert(DB.NurbSpline target) + public SOG.Curve Convert(IRevitNurbSpline target) { var units = _contextStack.Current.SpeckleUnits; @@ -40,12 +41,12 @@ public SOG.Curve Convert(DB.NurbSpline target) return new SOG.Curve() { - weights = target.Weights.Cast().ToList(), + weights = target.Weights.ToList(), points = points, - knots = target.Knots.Cast().ToList(), + knots = target.Knots.ToList(), degree = target.Degree, //speckleCurve.periodic = revitCurve.Period; // POC: already commented out, remove? - rational = target.isRational, + rational = target.IsRational, closed = _conversionHelper.IsCurveClosed(target), units = units, domain = new Interval(target.GetEndParameter(0), target.GetEndParameter(1)), diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PlaneToSpeckleConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PlaneToSpeckleConverter.cs index 27cef7bab6..0b4f090663 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PlaneToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PlaneToSpeckleConverter.cs @@ -1,18 +1,19 @@ +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Converters.RevitShared.Helpers; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023.ToSpeckle; -public class PlaneToSpeckleConverter : ITypedConverter +public class PlaneToSpeckleConverter : ITypedConverter { - private readonly IRevitConversionContextStack _contextStack; - private readonly ITypedConverter _xyzToPointConverter; - private readonly ITypedConverter _xyzToVectorConverter; + private readonly IConversionContextStack _contextStack; + private readonly ITypedConverter _xyzToPointConverter; + private readonly ITypedConverter _xyzToVectorConverter; public PlaneToSpeckleConverter( - IRevitConversionContextStack contextStack, - ITypedConverter xyzToPointConverter, - ITypedConverter xyzToVectorConverter + IConversionContextStack contextStack, + ITypedConverter xyzToPointConverter, + ITypedConverter xyzToVectorConverter ) { _contextStack = contextStack; @@ -20,7 +21,7 @@ public PlaneToSpeckleConverter( _xyzToVectorConverter = xyzToVectorConverter; } - public SOG.Plane Convert(DB.Plane target) + public SOG.Plane Convert(IRevitPlane target) { var origin = _xyzToPointConverter.Convert(target.Origin); var normal = _xyzToVectorConverter.Convert(target.Normal); diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PointCloudToSpeckleConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PointCloudToSpeckleConverter.cs index ab86301cd2..a66caa3b62 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PointCloudToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PointCloudToSpeckleConverter.cs @@ -1,39 +1,52 @@ +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Converters.RevitShared.Helpers; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023.ToSpeckle; -public class PointCloudToSpeckleConverter : ITypedConverter +public class PointCloudToSpeckleConverter : ITypedConverter { - private readonly IRevitConversionContextStack _contextStack; - private readonly ITypedConverter _xyzToPointConverter; - private readonly ITypedConverter _boundingBoxConverter; + private readonly IConversionContextStack _contextStack; + private readonly ITypedConverter _xyzToPointConverter; + private readonly ITypedConverter _boundingBoxConverter; + private readonly IRevitPlaneUtils _revitPlaneUtils; + private readonly IRevitXYZUtils _revitxyzUtils; + private readonly IRevitFilterFactory _revitFilterFactory; public PointCloudToSpeckleConverter( - IRevitConversionContextStack contextStack, - ITypedConverter xyzToPointConverter, - ITypedConverter boundingBoxConverter + IConversionContextStack contextStack, + ITypedConverter xyzToPointConverter, + ITypedConverter boundingBoxConverter, + IRevitPlaneUtils revitPlaneUtils, + IRevitXYZUtils revitxyzUtils, + IRevitFilterFactory revitFilterFactory ) { _contextStack = contextStack; _xyzToPointConverter = xyzToPointConverter; _boundingBoxConverter = boundingBoxConverter; + _revitPlaneUtils = revitPlaneUtils; + _revitxyzUtils = revitxyzUtils; + _revitFilterFactory = revitFilterFactory; } - public SOG.Pointcloud Convert(DB.PointCloudInstance target) + public SOG.Pointcloud Convert(IRevitPointCloudInstance target) { - var boundingBox = target.get_BoundingBox(null); - using DB.Transform transform = target.GetTransform(); + var boundingBox = target.GetBoundingBox(); + using IRevitTransform transform = target.GetTransform(); { - var minPlane = DB.Plane.CreateByNormalAndOrigin(DB.XYZ.BasisZ, transform.OfPoint(boundingBox.Min)); - var filter = DB.PointClouds.PointCloudFilterFactory.CreateMultiPlaneFilter(new List() { minPlane }); + var minPlane = _revitPlaneUtils.CreateByNormalAndOrigin( + _revitxyzUtils.BasisZ, + transform.OfPoint(boundingBox.Min) + ); + var filter = _revitFilterFactory.CreateMultiPlaneFilter(minPlane); var points = target.GetPoints(filter, 0.0001, 999999); // max limit is 1 mil but 1000000 throws error // POC: complaining about nullability var specklePointCloud = new SOG.Pointcloud { points = points - .Select(o => _xyzToPointConverter.Convert(transform.OfPoint(o))) + .Select(o => _xyzToPointConverter.Convert(transform.OfPoint(o.ToXYZ()))) .SelectMany(o => new List() { o.x, o.y, o.z }) .ToList(), colors = points.Select(o => o.Color).ToList(), diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PointConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PointConversionToSpeckle.cs index 8f6ca703db..328283066c 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PointConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PointConversionToSpeckle.cs @@ -1,15 +1,16 @@ -using Speckle.Converters.Common.Objects; +using Speckle.Converters.Common.Objects; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023.ToSpeckle; -public class PointConversionToSpeckle : ITypedConverter +public class PointConversionToSpeckle : ITypedConverter { - private readonly ITypedConverter _xyzToPointConverter; + private readonly ITypedConverter _xyzToPointConverter; - public PointConversionToSpeckle(ITypedConverter xyzToPointConverter) + public PointConversionToSpeckle(ITypedConverter xyzToPointConverter) { _xyzToPointConverter = xyzToPointConverter; } - public SOG.Point Convert(DB.Point target) => _xyzToPointConverter.Convert(target.Coord); + public SOG.Point Convert(IRevitPoint target) => _xyzToPointConverter.Convert(target.Coord); } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PolylineToSpeckleConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PolylineToSpeckleConverter.cs index 5efb22e278..b84f63a3ea 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PolylineToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PolylineToSpeckleConverter.cs @@ -1,23 +1,24 @@ +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Converters.RevitShared.Helpers; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023.ToSpeckle; -public class PolylineToSpeckleConverter : ITypedConverter +public class PolylineToSpeckleConverter : ITypedConverter { - private readonly IRevitConversionContextStack _contextStack; - private readonly ITypedConverter _xyzToPointConverter; + private readonly IConversionContextStack _contextStack; + private readonly ITypedConverter _xyzToPointConverter; public PolylineToSpeckleConverter( - IRevitConversionContextStack contextStack, - ITypedConverter xyzToPointConverter + IConversionContextStack contextStack, + ITypedConverter xyzToPointConverter ) { _contextStack = contextStack; _xyzToPointConverter = xyzToPointConverter; } - public SOG.Polyline Convert(DB.PolyLine target) + public SOG.Polyline Convert(IRevitPolyLine target) { var coords = target.GetCoordinates().SelectMany(coord => _xyzToPointConverter.Convert(coord).ToList()).ToList(); return new SOG.Polyline(coords, _contextStack.Current.SpeckleUnits); diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/SolidConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/SolidConversionToSpeckle.cs index e848d3a843..80996f470d 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/SolidConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/SolidConversionToSpeckle.cs @@ -1,53 +1,53 @@ -using Speckle.Converters.Common.Objects; -using Speckle.Converters.RevitShared.Helpers; +using Speckle.Converters.Common.Objects; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023.ToSpeckle; /// /// Solid conversion is a one->many. For each material used in the solid, a mesh will be returned to reduce the amount of instances created. /// -public class SolidConversionToSpeckle : IRawConversion> +public class SolidConversionToSpeckle : ITypedConverter> { - private readonly RevitConversionContextStack _contextStack; - private readonly IRawConversion>, List> _meshByMaterialConverter; + private readonly ITypedConverter< + Dictionary>, + List + > _meshByMaterialConverter; public SolidConversionToSpeckle( - RevitConversionContextStack contextStack, - IRawConversion>, List> meshByMaterialConverter + ITypedConverter>, List> meshByMaterialConverter ) { - _contextStack = contextStack; _meshByMaterialConverter = meshByMaterialConverter; } /// - /// Converts the input object into a list of . + /// Converts the input object into a list of . /// - /// The input object to be converted. + /// The input object to be converted. /// - /// A list of objects that represent the input object. Each mesh in the list corresponds to a different material in the original solid. + /// A list of objects that represent the input object. Each mesh in the list corresponds to a different material in the original solid. /// /// /// This conversion process first triangulates the input solid by material, and then converts the result to raw meshes individually. /// Be aware that this operation might be computationally intensive for complex solids, due to the need for triangulation. /// - public List RawConvert(DB.Solid target) + public List Convert(IRevitSolid target) { var meshesByMaterial = GetTriangulatedMeshesFromSolidByMaterial(target); - return _meshByMaterialConverter.RawConvert(meshesByMaterial); + return _meshByMaterialConverter.Convert(meshesByMaterial); } - private Dictionary> GetTriangulatedMeshesFromSolidByMaterial(DB.Solid solid) + private Dictionary> GetTriangulatedMeshesFromSolidByMaterial(IRevitSolid solid) { - var result = new Dictionary>(); - foreach (DB.Face face in solid.Faces) + var result = new Dictionary>(); + foreach (IRevitFace face in solid.Faces) { - if (!result.ContainsKey(face.MaterialElementId)) + if (!result.TryGetValue(face.MaterialElementId, out var mat)) { - result[face.MaterialElementId] = new List(); + mat = new List(); + result[face.MaterialElementId] = mat; } - - result[face.MaterialElementId].Add(face.Triangulate()); + mat.Add(face.Triangulate()); } return result; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/VectorToSpeckleConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/VectorToSpeckleConverter.cs index e97cf962f4..1f151a5e84 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/VectorToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/VectorToSpeckleConverter.cs @@ -1,27 +1,28 @@ -using Speckle.Converters.Common.Objects; +using Speckle.Converters.Common.Objects; using Speckle.Converters.RevitShared.Services; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023.ToSpeckle; -public class VectorToSpeckleConverter : ITypedConverter +public class VectorToSpeckleConverter : ITypedConverter { private readonly IReferencePointConverter _referencePointConverter; - private readonly ScalingServiceToSpeckle _scalingService; + private readonly IScalingServiceToSpeckle _scalingService; public VectorToSpeckleConverter( IReferencePointConverter referencePointConverter, - ScalingServiceToSpeckle scalingService + IScalingServiceToSpeckle scalingService ) { _referencePointConverter = referencePointConverter; _scalingService = scalingService; } - public SOG.Vector Convert(DB.XYZ target) + public SOG.Vector Convert(IRevitXYZ target) { // POC: originally had a concept of not transforming, but this was // optional arg defaulting to false - removing the argument appeared to break nothing - DB.XYZ extPt = _referencePointConverter.ConvertToExternalCoordindates(target, false); + var extPt = _referencePointConverter.ConvertToExternalCoordindates(target, false); var pointToSpeckle = new SOG.Vector( _scalingService.ScaleLength(extPt.X), _scalingService.ScaleLength(extPt.Y), diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/XyzConversionToPoint.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/XyzConversionToPoint.cs index bf250d06c3..962c13156a 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/XyzConversionToPoint.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/XyzConversionToPoint.cs @@ -1,24 +1,26 @@ +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Converters.RevitShared.Helpers; using Speckle.Converters.RevitShared.Services; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +#pragma warning disable IDE0130 +namespace Speckle.Converters.Revit2023.ToSpeckle; -public class XyzConversionToPoint : ITypedConverter +public class XyzConversionToPoint : ITypedConverter { - private readonly ScalingServiceToSpeckle _toSpeckleScalingService; - private readonly IRevitConversionContextStack _contextStack; + private readonly IScalingServiceToSpeckle _toSpeckleScalingService; + private readonly IConversionContextStack _contextStack; public XyzConversionToPoint( - ScalingServiceToSpeckle toSpeckleScalingService, - IRevitConversionContextStack contextStack + IScalingServiceToSpeckle toSpeckleScalingService, + IConversionContextStack contextStack ) { _toSpeckleScalingService = toSpeckleScalingService; _contextStack = contextStack; } - public SOG.Point Convert(DB.XYZ target) + public SOG.Point Convert(IRevitXYZ target) { var pointToSpeckle = new SOG.Point( _toSpeckleScalingService.ScaleLength(target.X), diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LevelConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LevelConversionToSpeckle.cs index 33e1d7fea2..e2af3a7e55 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LevelConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LevelConversionToSpeckle.cs @@ -1,18 +1,19 @@ -using Speckle.Converters.Common.Objects; +using Speckle.Converters.Common.Objects; using Speckle.Converters.RevitShared.Services; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023; -public class LevelConversionToSpeckle : ITypedConverter +public class LevelConversionToSpeckle : ITypedConverter { - private readonly ScalingServiceToSpeckle _scalingService; + private readonly IScalingServiceToSpeckle _scalingService; - public LevelConversionToSpeckle(ScalingServiceToSpeckle scalingService) + public LevelConversionToSpeckle(IScalingServiceToSpeckle scalingService) { _scalingService = scalingService; } - public SOBR.RevitLevel Convert(DB.Level target) + public SOBR.RevitLevel Convert(IRevitLevel target) { SOBR.RevitLevel level = new() diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LocationConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LocationConversionToSpeckle.cs index 29d3378103..e3dfae8ef2 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LocationConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LocationConversionToSpeckle.cs @@ -1,33 +1,37 @@ -using Objects; -using Speckle.Converters.Common.Objects; +using Objects; using Speckle.Converters.Common; +using Speckle.Converters.Common.Objects; using Speckle.Core.Models; +using Speckle.Revit.Interfaces; + +#pragma warning disable IDE0130 +namespace Speckle.Converters.Revit2023; -namespace Speckle.Converters.RevitShared.ToSpeckle; +#pragma warning restore IDE0130 -public class LocationConversionToSpeckle : ITypedConverter +public class LocationConversionToSpeckle : ITypedConverter { - private readonly ITypedConverter _curveConverter; - private readonly ITypedConverter _xyzConverter; + private readonly ITypedConverter _curveConverter; + private readonly ITypedConverter _xyzConverter; // POC: review IRawConversion which always returns a Base, this is ToSpeckle, so... this breaks // the meaning of IRawConversion, it could be IToSpeckleRawConversion // also a factory type public LocationConversionToSpeckle( - ITypedConverter curveConverter, - ITypedConverter xyzConverter + ITypedConverter curveConverter, + ITypedConverter xyzConverter ) { _curveConverter = curveConverter; _xyzConverter = xyzConverter; } - public Base Convert(DB.Location target) + public Base Convert(IRevitLocation target) { return target switch { - DB.LocationCurve curve => (_curveConverter.Convert(curve.Curve) as Base)!, // POC: ICurve and Base are not related but we know they must be, had to soft cast and then !. - DB.LocationPoint point => _xyzConverter.Convert(point.Point), + IRevitLocationCurve curve => (_curveConverter.Convert(curve.Curve) as Base).NotNull(), // POC: ICurve and Base are not related but we know they must be, had to soft cast and then !. + IRevitLocationPoint point => _xyzConverter.Convert(point.Point), _ => throw new SpeckleConversionException($"Unexpected location type {target.GetType()}") }; } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/MaterialConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/MaterialConversionToSpeckle.cs index f7f48974f7..ddabe2f856 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/MaterialConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/MaterialConversionToSpeckle.cs @@ -1,11 +1,12 @@ using Objects.Other; using Speckle.Converters.Common.Objects; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023; -public class MaterialConversionToSpeckle : ITypedConverter +public class MaterialConversionToSpeckle : ITypedConverter { - public RenderMaterial Convert(DB.Material target) => + public RenderMaterial Convert(IRevitMaterial target) => // POC: not sure we should be pulling in System.Drawing - // maybe this isn't a problem as it's part of the netstandard Fwk // ideally we'd have serialiser of our own colour class, i.e. to serialise to an uint diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ModelCurveArrArrayConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ModelCurveArrArrayConverterToSpeckle.cs new file mode 100644 index 0000000000..272d81927e --- /dev/null +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ModelCurveArrArrayConverterToSpeckle.cs @@ -0,0 +1,30 @@ +using Objects.Geometry; +using Speckle.Converters.Common.Objects; +using Speckle.Revit.Interfaces; +#pragma warning disable IDE0130 +namespace Speckle.Converters.Revit2023; + +internal sealed class ModelCurveArrArrayConverterToSpeckle : ITypedConverter +{ + private readonly ITypedConverter _modelCurveArrayConverter; + + public ModelCurveArrArrayConverterToSpeckle( + ITypedConverter modelCurveArrayConverter + ) + { + _modelCurveArrayConverter = modelCurveArrayConverter; + } + + public Objects.Geometry.Polycurve[] Convert(IRevitModelCurveArrArray target) + { + var polycurves = new Objects.Geometry.Polycurve[target.Count]; + var revitArrays = target.ToArray(); + + for (int i = 0; i < polycurves.Length; i++) + { + polycurves[i] = _modelCurveArrayConverter.Convert(revitArrays[i]); + } + + return polycurves; + } +} diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ModelCurveArrArrayToSpeckleConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ModelCurveArrArrayToSpeckleConverter.cs deleted file mode 100644 index d294360b2d..0000000000 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ModelCurveArrArrayToSpeckleConverter.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Autodesk.Revit.DB; -using Objects.Geometry; -using Speckle.Converters.Common.Objects; - -namespace Speckle.Converters.RevitShared.Raw; - -internal sealed class ModelCurveArrArrayConverterToSpeckle : ITypedConverter -{ - private readonly ITypedConverter _modelCurveArrayConverter; - - public ModelCurveArrArrayConverterToSpeckle(ITypedConverter modelCurveArrayConverter) - { - _modelCurveArrayConverter = modelCurveArrayConverter; - } - - public SOG.Polycurve[] Convert(ModelCurveArrArray target) - { - var polycurves = new Polycurve[target.Size]; - var revitArrays = target.Cast().ToArray(); - - for (int i = 0; i < polycurves.Length; i++) - { - polycurves[i] = _modelCurveArrayConverter.Convert(revitArrays[i]); - } - - return polycurves; - } -} diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ModelCurveArrayToSpeckleConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ModelCurveArrayToSpeckleConverter.cs index 5bfd4d11bb..d96398960d 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ModelCurveArrayToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ModelCurveArrayToSpeckleConverter.cs @@ -1,21 +1,22 @@ -using Objects; +using Objects; using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Converters.RevitShared.Helpers; +using Speckle.Converters.RevitShared; using Speckle.Converters.RevitShared.Services; +using Speckle.Revit.Interfaces; +#pragma warning disable IDE0130 +namespace Speckle.Converters.Revit2023; -namespace Speckle.Converters.RevitShared.Raw; - -internal sealed class ModelCurveArrayToSpeckleConverter : ITypedConverter +public sealed class ModelCurveArrayToSpeckleConverter : ITypedConverter { - private readonly IRevitConversionContextStack _contextStack; - private readonly ScalingServiceToSpeckle _scalingService; - private readonly ITypedConverter _curveConverter; + private readonly IConversionContextStack _contextStack; + private readonly IScalingServiceToSpeckle _scalingService; + private readonly ITypedConverter _curveConverter; public ModelCurveArrayToSpeckleConverter( - IRevitConversionContextStack contextStack, - ScalingServiceToSpeckle scalingService, - ITypedConverter curveConverter + IConversionContextStack contextStack, + IScalingServiceToSpeckle scalingService, + ITypedConverter curveConverter ) { _contextStack = contextStack; @@ -23,10 +24,12 @@ public ModelCurveArrayToSpeckleConverter( _curveConverter = curveConverter; } - public SOG.Polycurve Convert(DB.ModelCurveArray target) + public SOG.Polycurve Convert(IRevitModelCurveArray target) => Convert((IReadOnlyList)target); + + public SOG.Polycurve Convert(IReadOnlyList target) { SOG.Polycurve polycurve = new(); - var curves = target.Cast().Select(mc => mc.GeometryCurve).ToArray(); + var curves = target.Select(mc => mc.GeometryCurve).ToArray(); if (curves.Length == 0) { @@ -36,7 +39,7 @@ public SOG.Polycurve Convert(DB.ModelCurveArray target) var start = curves[0].GetEndPoint(0); var end = curves[^1].GetEndPoint(1); polycurve.units = _contextStack.Current.SpeckleUnits; - polycurve.closed = start.DistanceTo(end) < RevitConversionContextStack.TOLERANCE; + polycurve.closed = start.DistanceTo(end) < RevitConstants.TOLERANCE; polycurve.length = _scalingService.ScaleLength(curves.Sum(x => x.Length)); polycurve.segments.AddRange(curves.Select(x => _curveConverter.Convert(x))); diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ParameterConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ParameterConversionToSpeckle.cs index a0b1f01da5..3aa9e156fb 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ParameterConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ParameterConversionToSpeckle.cs @@ -1,30 +1,35 @@ -using Autodesk.Revit.DB; -using Speckle.Converters.Common.Objects; +using Speckle.Converters.Common.Objects; using Speckle.Converters.RevitShared.Extensions; using Speckle.Converters.RevitShared.Helpers; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023; -public class ParameterConversionToSpeckle : ITypedConverter +public class ParameterConversionToSpeckle : ITypedConverter { - private readonly ParameterValueExtractor _valueExtractor; + private readonly IParameterValueExtractor _valueExtractor; + private readonly IRevitFormatOptionsUtils _revitFormatOptionsUtils; - public ParameterConversionToSpeckle(ParameterValueExtractor valueExtractor) + public ParameterConversionToSpeckle( + IParameterValueExtractor valueExtractor, + IRevitFormatOptionsUtils revitFormatOptionsUtils + ) { _valueExtractor = valueExtractor; + _revitFormatOptionsUtils = revitFormatOptionsUtils; } - public SOBR.Parameter Convert(Parameter target) + public SOBR.Parameter Convert(IRevitParameter target) { string internalName = target.GetInternalName(); - ForgeTypeId? unitTypeId = null; - if (target.StorageType is StorageType.Double) + IRevitForgeTypeId? unitTypeId = null; + if (target.StorageType is IRevitStorageType.Double) { // according to the api documentation, this method will throw if the storage type is not a VALUE type // however, I've found that it will still throw if StorageType == StorageType.Integer unitTypeId = target.GetUnitTypeId(); } - Definition definition = target.Definition; + IRevitDefinition definition = target.Definition; return new SOBR.Parameter() { @@ -33,7 +38,7 @@ public SOBR.Parameter Convert(Parameter target) isShared = target.IsShared, isReadOnly = target.IsReadOnly, name = definition.Name, - units = unitTypeId?.GetSymbol() ?? "None", + units = unitTypeId?.GetSymbol(_revitFormatOptionsUtils) ?? "None", value = _valueExtractor.GetValue(target) }; } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/RevitVersionConversionHelper.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/RevitVersionConversionHelper.cs new file mode 100644 index 0000000000..b85e017ba1 --- /dev/null +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/RevitVersionConversionHelper.cs @@ -0,0 +1,23 @@ +using System.Diagnostics.CodeAnalysis; +using Speckle.InterfaceGenerator; +using Speckle.Revit.Interfaces; + +namespace Speckle.Converters.Revit2023; + +[GenerateAutoInterface] +public class RevitVersionConversionHelper : IRevitVersionConversionHelper +{ + [SuppressMessage("Design", "CA1031:Do not catch general exception types")] + public bool IsCurveClosed(IRevitNurbSpline nurbsSpline) + { + try + { + return nurbsSpline.IsClosed; + } + catch (Exception) + { + // POC: is this actually a good assumption? + return true; + } + } +} diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitConstants.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitConstants.cs new file mode 100644 index 0000000000..79a6ef167a --- /dev/null +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitConstants.cs @@ -0,0 +1,6 @@ +namespace Speckle.Converters.RevitShared; + +public static class RevitConstants +{ + public const double TOLERANCE = 0.0164042; // 5mm in ft +} diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitConversionSettings.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitConversionSettings.cs deleted file mode 100644 index 3fb4466120..0000000000 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitConversionSettings.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace Speckle.Converters.RevitShared; - -// POC: probably NOT the right place, probably needs passing in with the send/rcv operation -// not clear how this should get configured or if we should have it, the shape probably needs to change -// this was dragged in because it (or something like it) is required for reference point conversion. -// have made it a strongly typed thing encapsulating a dictionary so as not to rely on injecting a weak type. -// relates to https://spockle.atlassian.net/browse/CNX-9357 -public class RevitConversionSettings -{ - private Dictionary Settings { get; } = new Dictionary(); - - public bool TryGetSettingString(string key, out string value) => Settings.TryGetValue(key, out value); - - public string this[string key] - { - get => Settings[key]; - set => Settings[key] = value; - } -} diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitRootToHostConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitRootToHostConverter.cs index 78790ee19e..46964b9074 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitRootToHostConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitRootToHostConverter.cs @@ -2,6 +2,7 @@ using Speckle.Converters.Common.Objects; using Speckle.Core.Models; using Speckle.Converters.RevitShared.Helpers; +using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared; @@ -37,7 +38,7 @@ public Base Convert(object target) // POC : where should logic common to most objects go? // shouldn't target ALWAYS be DB.Element? - if (target is DB.Element element) + if (target is IRevitElement element) { // POC: is this the right place? result.applicationId = element.UniqueId; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ReferencePointConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/ReferencePointConverter.cs similarity index 50% rename from DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ReferencePointConverter.cs rename to DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/ReferencePointConverter.cs index 901c5c5572..450ee5e16e 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ReferencePointConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/ReferencePointConverter.cs @@ -1,12 +1,25 @@ using System.Diagnostics.CodeAnalysis; -using Speckle.Converters.RevitShared.Helpers; +using Speckle.Converters.Common; +using Speckle.InterfaceGenerator; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared; +namespace Speckle.Converters.Revit2023; -// POC: this could perhaps becomes some RevitDocumentService but also... -// This reference point feature needs review. We could do with knowing whether this feature is widely used. -// there's also some bogus disposal happening -// https://spockle.atlassian.net/browse/CNX-9357 +[GenerateAutoInterface] +public class RevitConversionSettings : IRevitConversionSettings +{ + private Dictionary Settings { get; } = new(); + + public bool TryGetSettingString(string key, out string value) => Settings.TryGetValue(key, out value); + + public string this[string key] + { + get => Settings[key]; + set => Settings[key] = value; + } +} + +[GenerateAutoInterface] public class ReferencePointConverter : IReferencePointConverter { // POC: probably not the best place for this @@ -14,21 +27,33 @@ public class ReferencePointConverter : IReferencePointConverter private const string REFPOINT_PROJECT_BASE = "Project Base"; private const string REFPOINT_SURVEY = "Survey"; - private readonly RevitConversionSettings _revitSettings; - private readonly IRevitConversionContextStack _contextStack; - - private readonly Dictionary _docTransforms = new(); - - public ReferencePointConverter(IRevitConversionContextStack contextStack, RevitConversionSettings revitSettings) + private readonly IRevitConversionSettings _revitSettings; + private readonly IConversionContextStack _contextStack; + private readonly IRevitTransformUtils _transformUtils; + private readonly IRevitFilterFactory _revitFilterFactory; + private readonly IRevitXYZUtils _revitXyzUtils; + + private readonly Dictionary _docTransforms = new(); + + public ReferencePointConverter( + IConversionContextStack contextStack, + IRevitConversionSettings revitSettings, + IRevitFilterFactory revitFilterFactory, + IRevitTransformUtils transformUtils, + IRevitXYZUtils revitXyzUtils + ) { _contextStack = contextStack; _revitSettings = revitSettings; + _revitFilterFactory = revitFilterFactory; + _transformUtils = transformUtils; + _revitXyzUtils = revitXyzUtils; } // POC: the original allowed for the document to be passed in // if required, we would probably need to push the stack with a new document if the // doc can change during the lifeycycle of the conversions. This may need some looking into - public DB.XYZ ConvertToExternalCoordindates(DB.XYZ inbound, bool isPoint) + public IRevitXYZ ConvertToExternalCoordindates(IRevitXYZ inbound, bool isPoint) { var rpt = GetDocReferencePointTransform(_contextStack.Current.Document); return isPoint ? rpt.OfPoint(inbound) : rpt.OfVector(inbound); @@ -36,13 +61,13 @@ public DB.XYZ ConvertToExternalCoordindates(DB.XYZ inbound, bool isPoint) // POC: this might be better in some RevitDocumentService // we could probably return that instance instead of the Doc from the context, maybe... - public DB.Transform GetDocReferencePointTransform(DB.Document doc) + public IRevitTransform GetDocReferencePointTransform(IRevitDocument doc) { //linked files are always saved to disc and will have a path name //if the current doc is unsaved it will not, but then it'll be the only one :) var id = doc.PathName; - if (!_docTransforms.TryGetValue(id, out DB.Transform? transform)) + if (!_docTransforms.TryGetValue(id, out IRevitTransform? transform)) { // get from settings var referencePointSetting = _revitSettings.TryGetSettingString("reference-point", out string value) @@ -56,25 +81,25 @@ public DB.Transform GetDocReferencePointTransform(DB.Document doc) } [SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope")] - public DB.Transform GetReferencePointTransform(string referencePointSetting) + public IRevitTransform GetReferencePointTransform(string referencePointSetting) { // first get the main doc base points and reference setting transform - var referencePointTransform = DB.Transform.Identity; + var referencePointTransform = _transformUtils.Identity; // POC: bogus disposal below - var points = new DB.FilteredElementCollector(_contextStack.Current.Document) - .OfClass(typeof(DB.BasePoint)) - .Cast() + var points = _revitFilterFactory + .CreateFilteredElementCollector(_contextStack.Current.Document) + .OfClass() .ToList(); - var projectPoint = points.FirstOrDefault(o => o.IsShared == false); - var surveyPoint = points.FirstOrDefault(o => o.IsShared); + var projectPoint = NotNullExtensions.NotNull(points.FirstOrDefault(o => o.IsShared == false), "No projectPoint"); + var surveyPoint = NotNullExtensions.NotNull(points.FirstOrDefault(o => o.IsShared), "No surveyPoint"); // POC: it's not clear what support is needed for this switch (referencePointSetting) { case REFPOINT_PROJECT_BASE: // note that the project base (ui) rotation is registered on the survey pt, not on the base point - referencePointTransform = DB.Transform.CreateTranslation(projectPoint.Position); + referencePointTransform = _transformUtils.CreateTranslation(projectPoint.Position); break; case REFPOINT_SURVEY: @@ -82,12 +107,12 @@ public DB.Transform GetReferencePointTransform(string referencePointSetting) // retrieve the survey point rotation from the project point // POC: should a null angle resolve to 0? - var angle = projectPoint.get_Parameter(DB.BuiltInParameter.BASEPOINT_ANGLETON_PARAM)?.AsDouble() ?? 0; + var angle = projectPoint.GetParameter(RevitBuiltInParameter.BASEPOINT_ANGLETON_PARAM)?.AsDouble() ?? 0; // POC: following disposed incorrectly or early or maybe a false negative? - referencePointTransform = DB.Transform + referencePointTransform = _transformUtils .CreateTranslation(surveyPoint.Position) - .Multiply(DB.Transform.CreateRotation(DB.XYZ.BasisZ, angle)); + .Multiply(_transformUtils.CreateRotation(_revitXyzUtils.BasisZ, angle)); break; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/RevitToSpeckleUnitConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/RevitToSpeckleUnitConverter.cs index e1d7a7a62b..e6de0840fa 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/RevitToSpeckleUnitConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/RevitToSpeckleUnitConverter.cs @@ -1,29 +1,30 @@ using Speckle.Converters.Common; using Speckle.Core.Kits; using Speckle.Core.Logging; +using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared.Services; -public sealed class RevitToSpeckleUnitConverter : IHostToSpeckleUnitConverter +public sealed class RevitToSpeckleUnitConverter : IHostToSpeckleUnitConverter { - private readonly Dictionary _unitMapping = new(); + private readonly Dictionary _unitMapping = new(); - public RevitToSpeckleUnitConverter() + public RevitToSpeckleUnitConverter(IRevitUnitUtils revitUnitUtils) { - _unitMapping[DB.UnitTypeId.Millimeters] = Units.Millimeters; - _unitMapping[DB.UnitTypeId.Centimeters] = Units.Centimeters; - _unitMapping[DB.UnitTypeId.Meters] = Units.Meters; - _unitMapping[DB.UnitTypeId.MetersCentimeters] = Units.Meters; - _unitMapping[DB.UnitTypeId.Inches] = Units.Inches; - _unitMapping[DB.UnitTypeId.FractionalInches] = Units.Inches; - _unitMapping[DB.UnitTypeId.Feet] = Units.Feet; - _unitMapping[DB.UnitTypeId.FeetFractionalInches] = Units.Feet; + _unitMapping[revitUnitUtils.Millimeters.TypeId] = Units.Millimeters; + _unitMapping[revitUnitUtils.Centimeters.TypeId] = Units.Centimeters; + _unitMapping[revitUnitUtils.Meters.TypeId] = Units.Meters; + _unitMapping[revitUnitUtils.MetersCentimeters.TypeId] = Units.Meters; + _unitMapping[revitUnitUtils.Inches.TypeId] = Units.Inches; + _unitMapping[revitUnitUtils.FractionalInches.TypeId] = Units.Inches; + _unitMapping[revitUnitUtils.Feet.TypeId] = Units.Feet; + _unitMapping[revitUnitUtils.FeetFractionalInches.TypeId] = Units.Feet; } // POC: maybe just convert, it's not a Try method - public string ConvertOrThrow(DB.ForgeTypeId hostUnit) + public string ConvertOrThrow(IRevitForgeTypeId hostUnit) { - if (_unitMapping.TryGetValue(hostUnit, out string value)) + if (_unitMapping.TryGetValue(hostUnit.TypeId, out string value)) { return value; } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/ScalingServiceToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/ScalingServiceToSpeckle.cs index a0c2779048..57ba7be5f2 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/ScalingServiceToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/ScalingServiceToSpeckle.cs @@ -1,20 +1,27 @@ -using Autodesk.Revit.DB; -using Speckle.Converters.RevitShared.Helpers; +using Speckle.Converters.Common; +using Speckle.InterfaceGenerator; +using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared.Services; // POC: feels like this is a context thing and we should be calculating this occasionally? // needs some thought as to how it could be be done, could leave as is for now -public sealed class ScalingServiceToSpeckle +[GenerateAutoInterface] +public sealed class ScalingServiceToSpeckle : IScalingServiceToSpeckle { private readonly double _defaultLengthConversionFactor; + private readonly IRevitUnitUtils _revitUnitUtils; // POC: this seems like the reverse relationship - public ScalingServiceToSpeckle(IRevitConversionContextStack contextStack) + public ScalingServiceToSpeckle( + IConversionContextStack contextStack, + IRevitUnitUtils revitUnitUtils + ) { + _revitUnitUtils = revitUnitUtils; // POC: this is accurate for the current context stack - Units documentUnits = contextStack.Current.Document.GetUnits(); - FormatOptions formatOptions = documentUnits.GetFormatOptions(SpecTypeId.Length); + var documentUnits = contextStack.Current.Document.GetUnits(); + var formatOptions = documentUnits.GetFormatOptions(_revitUnitUtils.Length); var lengthUnitsTypeId = formatOptions.GetUnitTypeId(); _defaultLengthConversionFactor = ScaleStatic(1, lengthUnitsTypeId); } @@ -26,14 +33,14 @@ public ScalingServiceToSpeckle(IRevitConversionContextStack contextStack) public double ScaleLength(double length) => length * _defaultLengthConversionFactor; // POC: not sure about this??? - public double Scale(double value, ForgeTypeId forgeTypeId) + public double Scale(double value, IRevitForgeTypeId forgeTypeId) { return ScaleStatic(value, forgeTypeId); } // POC: not sure why this is needed??? - private static double ScaleStatic(double value, ForgeTypeId forgeTypeId) + private double ScaleStatic(double value, IRevitForgeTypeId forgeTypeId) { - return UnitUtils.ConvertFromInternalUnits(value, forgeTypeId); + return _revitUnitUtils.ConvertFromInternalUnits(value, forgeTypeId); } } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Speckle.Converters.RevitShared.projitems b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Speckle.Converters.RevitShared.projitems index 5e5d29480e..575c0093e6 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Speckle.Converters.RevitShared.projitems +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Speckle.Converters.RevitShared.projitems @@ -9,72 +9,6 @@ Speckle.Converters.RevitShared - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/BaseTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/BaseTopLevelConverterToSpeckle.cs index f7a94c8d1f..394990c507 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/BaseTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/BaseTopLevelConverterToSpeckle.cs @@ -1,8 +1,8 @@ -using Speckle.Converters.Common; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Core.Models; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023.ToSpeckle; // POC: maybe but could be generic abstract Converters.Common? // or maybe it's not actually doing very much now and can come out diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs index c3de2636aa..5e2bd504d1 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs @@ -1,18 +1,20 @@ -using Autodesk.Revit.DB; -using Objects; +using Objects; using Objects.BuiltElements.Revit; using Objects.Geometry; using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; +using Speckle.Converters.Revit2023.ToSpeckle; using Speckle.Converters.RevitShared.Helpers; +using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared.ToSpeckle; -[NameAndRankValue(nameof(DB.Ceiling), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -internal sealed class CeilingTopLevelConverterToSpeckle : BaseTopLevelConverterToSpeckle +[NameAndRankValue(nameof(IRevitCeiling), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +internal sealed class CeilingTopLevelConverterToSpeckle + : BaseTopLevelConverterToSpeckle { - private readonly ITypedConverter> _curveArrArrayConverter; - private readonly ITypedConverter _levelConverter; + private readonly ITypedConverter> _curveArrArrayConverter; + private readonly ITypedConverter _levelConverter; private readonly ParameterValueExtractor _parameterValueExtractor; private readonly ParameterObjectAssigner _parameterObjectAssigner; private readonly DisplayValueExtractor _displayValueExtractor; @@ -20,8 +22,8 @@ internal sealed class CeilingTopLevelConverterToSpeckle : BaseTopLevelConverterT //private readonly HostedElementConversionToSpeckle _hostedElementConverter; public CeilingTopLevelConverterToSpeckle( - ITypedConverter> curveArrArrayConverter, - ITypedConverter levelConverter, + ITypedConverter> curveArrArrayConverter, + ITypedConverter levelConverter, ParameterValueExtractor parameterValueExtractor, ParameterObjectAssigner parameterObjectAssigner, DisplayValueExtractor displayValueExtractor @@ -34,14 +36,14 @@ DisplayValueExtractor displayValueExtractor _displayValueExtractor = displayValueExtractor; } - public override RevitCeiling Convert(DB.Ceiling target) + public override RevitCeiling Convert(IRevitCeiling target) { - var sketch = (Sketch)target.Document.GetElement(target.SketchId); + var sketch = target.Document.GetElement(target.SketchId).ToSketch().NotNull(); List profiles = _curveArrArrayConverter.Convert(sketch.Profile); var speckleCeiling = new RevitCeiling(); - var elementType = (ElementType)target.Document.GetElement(target.GetTypeId()); + var elementType = target.Document.GetElement(target.GetTypeId()).ToType().NotNull(); speckleCeiling.type = elementType.Name; speckleCeiling.family = elementType.FamilyName; @@ -58,7 +60,10 @@ public override RevitCeiling Convert(DB.Ceiling target) // POC: our existing receive operation is checking the "slopeDirection" prop, // but it is never being set. We should be setting it - var level = _parameterValueExtractor.GetValueAsDocumentObject(target, DB.BuiltInParameter.LEVEL_PARAM); + var level = _parameterValueExtractor.GetValueAsDocumentObject( + target, + RevitBuiltInParameter.LEVEL_PARAM + ); speckleCeiling.level = _levelConverter.Convert(level); _parameterObjectAssigner.AssignParametersToBase(target, speckleCeiling); diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/DirectShapeTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/DirectShapeTopLevelConverterToSpeckle.cs index c9c9ca5e14..0aa1d5fab7 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/DirectShapeTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/DirectShapeTopLevelConverterToSpeckle.cs @@ -1,22 +1,22 @@ using Speckle.Converters.Common; using Speckle.Converters.RevitShared.Extensions; using Speckle.Converters.RevitShared.Helpers; -using Speckle.Converters.RevitShared.ToSpeckle; using Speckle.Core.Models; +using Speckle.Revit.Interfaces; namespace Speckle.Converters.Revit2023.ToSpeckle; -[NameAndRankValue(nameof(DB.DirectShape), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public class DirectShapeTopLevelConverterToSpeckle : BaseTopLevelConverterToSpeckle +[NameAndRankValue(nameof(IRevitDirectShape), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +public class DirectShapeTopLevelConverterToSpeckle : BaseTopLevelConverterToSpeckle { - private readonly IRevitConversionContextStack _contextStack; - private readonly ParameterObjectAssigner _parameterObjectAssigner; - private readonly DisplayValueExtractor _displayValueExtractor; + private readonly IConversionContextStack _contextStack; + private readonly IParameterObjectAssigner _parameterObjectAssigner; + private readonly IDisplayValueExtractor _displayValueExtractor; public DirectShapeTopLevelConverterToSpeckle( - ParameterObjectAssigner parameterObjectAssigner, - IRevitConversionContextStack contextStack, - DisplayValueExtractor displayValueExtractor + IParameterObjectAssigner parameterObjectAssigner, + IConversionContextStack contextStack, + IDisplayValueExtractor displayValueExtractor ) { _parameterObjectAssigner = parameterObjectAssigner; @@ -24,7 +24,7 @@ DisplayValueExtractor displayValueExtractor _displayValueExtractor = displayValueExtractor; } - public override SOBR.DirectShape Convert(DB.DirectShape target) + public override SOBR.DirectShape Convert(IRevitDirectShape target) { var category = target.Category.GetBuiltInCategory().GetSchemaBuilderCategoryFromBuiltIn(); diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ElementTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ElementTopLevelConverterToSpeckle.cs index c3b96c9001..4595f9b2d1 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ElementTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ElementTopLevelConverterToSpeckle.cs @@ -1,25 +1,27 @@ -using Speckle.Converters.Common; -using Objects.BuiltElements.Revit; +using Speckle.Converters.Common; using Speckle.Converters.RevitShared.Helpers; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023.ToSpeckle; // POC: not currently used? clearly some missing pieces -[NameAndRankValue(nameof(DB.Element), 0)] -public class ElementTopLevelConverterToSpeckle : BaseTopLevelConverterToSpeckle +[NameAndRankValue(nameof(IRevitElement), 0)] +public class ElementTopLevelConverterToSpeckle : BaseTopLevelConverterToSpeckle { - private readonly DisplayValueExtractor _displayValueExtractor; + private readonly IDisplayValueExtractor _displayValueExtractor; - public ElementTopLevelConverterToSpeckle(DisplayValueExtractor displayValueExtractor) + public ElementTopLevelConverterToSpeckle(IDisplayValueExtractor displayValueExtractor) { _displayValueExtractor = displayValueExtractor; } - public override RevitElement Convert(DB.Element target) + public override SOBR.RevitElement Convert(IRevitElement target) { - RevitElement speckleElement = new(); + SOBR.RevitElement speckleElement = new(); - if (target.Document.GetElement(target.GetTypeId()) is DB.FamilySymbol symbol) + var element = target.Document.GetElement(target.GetTypeId()); + var symbol = element.ToFamilySymbol(); + if (symbol is not null) { speckleElement.family = symbol.FamilyName; speckleElement.type = symbol.Name; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ExtrusionRoofToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ExtrusionRoofToSpeckleTopLevelConverter.cs index d46c93794f..db49dd9884 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ExtrusionRoofToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ExtrusionRoofToSpeckleTopLevelConverter.cs @@ -1,32 +1,34 @@ -using Objects.BuiltElements.Revit.RevitRoof; -using Speckle.Converters.Common.Objects; +using Objects.BuiltElements.Revit.RevitRoof; using Speckle.Converters.Common; -using Speckle.Converters.RevitShared.Helpers; - +using Speckle.Converters.Common.Objects; using Speckle.Converters.RevitShared.Extensions; +using Speckle.Converters.RevitShared.Helpers; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023.ToSpeckle; -[NameAndRankValue(nameof(DB.ExtrusionRoof), 0)] +[NameAndRankValue(nameof(IRevitExtrusionRoof), 0)] public class ExtrusionRoofToSpeckleTopLevelConverter - : BaseTopLevelConverterToSpeckle + : BaseTopLevelConverterToSpeckle { - private readonly ITypedConverter _levelConverter; - private readonly ITypedConverter _modelCurveArrayConverter; - private readonly ITypedConverter _pointConverter; - private readonly ParameterValueExtractor _parameterValueExtractor; - private readonly DisplayValueExtractor _displayValueExtractor; - private readonly HostedElementConversionToSpeckle _hostedElementConverter; - private readonly ParameterObjectAssigner _parameterObjectAssigner; + private readonly ITypedConverter _levelConverter; + private readonly ITypedConverter _modelCurveArrayConverter; + private readonly ITypedConverter _pointConverter; + private readonly IParameterValueExtractor _parameterValueExtractor; + private readonly IDisplayValueExtractor _displayValueExtractor; + private readonly IHostedElementConversionToSpeckle _hostedElementConverter; + private readonly IParameterObjectAssigner _parameterObjectAssigner; + private readonly IRevitFilterFactory _revitFilterFactory; public ExtrusionRoofToSpeckleTopLevelConverter( - ITypedConverter levelConverter, - ITypedConverter modelCurveArrayConverter, - ITypedConverter pointConverter, - ParameterValueExtractor parameterValueExtractor, - DisplayValueExtractor displayValueExtractor, - HostedElementConversionToSpeckle hostedElementConverter, - ParameterObjectAssigner parameterObjectAssigner + ITypedConverter levelConverter, + ITypedConverter modelCurveArrayConverter, + ITypedConverter pointConverter, + IParameterValueExtractor parameterValueExtractor, + IDisplayValueExtractor displayValueExtractor, + IHostedElementConversionToSpeckle hostedElementConverter, + IParameterObjectAssigner parameterObjectAssigner, + IRevitFilterFactory revitFilterFactory ) { _levelConverter = levelConverter; @@ -36,35 +38,36 @@ ParameterObjectAssigner parameterObjectAssigner _displayValueExtractor = displayValueExtractor; _hostedElementConverter = hostedElementConverter; _parameterObjectAssigner = parameterObjectAssigner; + _revitFilterFactory = revitFilterFactory; } - public override RevitExtrusionRoof Convert(DB.ExtrusionRoof target) + public override RevitExtrusionRoof Convert(IRevitExtrusionRoof target) { var speckleExtrusionRoof = new RevitExtrusionRoof { - start = _parameterValueExtractor.GetValueAsDouble(target, DB.BuiltInParameter.EXTRUSION_START_PARAM), - end = _parameterValueExtractor.GetValueAsDouble(target, DB.BuiltInParameter.EXTRUSION_END_PARAM) + start = _parameterValueExtractor.GetValueAsDouble(target, RevitBuiltInParameter.EXTRUSION_START_PARAM), + end = _parameterValueExtractor.GetValueAsDouble(target, RevitBuiltInParameter.EXTRUSION_END_PARAM) }; - var plane = target.GetProfile().get_Item(0).SketchPlane.GetPlane(); + var plane = target.GetProfile()[0].SketchPlane.GetPlane(); speckleExtrusionRoof.referenceLine = new SOG.Line( _pointConverter.Convert(plane.Origin.Add(plane.XVec.Normalize().Negate())), _pointConverter.Convert(plane.Origin) ); - var level = _parameterValueExtractor.GetValueAsDocumentObject( + var level = _parameterValueExtractor.GetValueAsDocumentObject( target, - DB.BuiltInParameter.ROOF_CONSTRAINT_LEVEL_PARAM + RevitBuiltInParameter.ROOF_CONSTRAINT_LEVEL_PARAM ); speckleExtrusionRoof.level = _levelConverter.Convert(level); speckleExtrusionRoof.outline = _modelCurveArrayConverter.Convert(target.GetProfile()); - var elementType = (DB.ElementType)target.Document.GetElement(target.GetTypeId()); + var elementType = (IRevitElementType)target.Document.GetElement(target.GetTypeId()); speckleExtrusionRoof.type = elementType.Name; speckleExtrusionRoof.family = elementType.FamilyName; _parameterObjectAssigner.AssignParametersToBase(target, speckleExtrusionRoof); speckleExtrusionRoof.displayValue = _displayValueExtractor.GetDisplayValue(target); speckleExtrusionRoof.elements = _hostedElementConverter - .ConvertHostedElements(target.GetHostedElementIds()) + .ConvertHostedElements(target.GetHostedElementIds(_revitFilterFactory)) .ToList(); return speckleExtrusionRoof; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FamilyInstanceTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FamilyInstanceTopLevelConverterToSpeckle.cs index 446dcd4383..0cbdc994d9 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FamilyInstanceTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FamilyInstanceTopLevelConverterToSpeckle.cs @@ -1,24 +1,26 @@ -using Speckle.Converters.Common; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Core.Models; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023.ToSpeckle; // POC: bin for now? This is also a parent child relationship and may need a pattern for this // so we don't end up with some god FamilyInstanceTopLevelConverterToSpeckle converter -[NameAndRankValue(nameof(DB.FamilyInstance), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public sealed class FamilyInstanceTopLevelConverterToSpeckle : BaseTopLevelConverterToSpeckle +[NameAndRankValue(nameof(IRevitFamilyInstance), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +public sealed class FamilyInstanceTopLevelConverterToSpeckle + : BaseTopLevelConverterToSpeckle { - private readonly ITypedConverter _elementConverter; - private readonly ITypedConverter _beamConversion; - private readonly ITypedConverter _columnConversion; - private readonly ITypedConverter _braceConversion; + private readonly ITypedConverter _elementConverter; + private readonly ITypedConverter _beamConversion; + private readonly ITypedConverter _columnConversion; + private readonly ITypedConverter _braceConversion; public FamilyInstanceTopLevelConverterToSpeckle( - ITypedConverter elementConverter, - ITypedConverter beamConversion, - ITypedConverter columnConversion, - ITypedConverter braceConversion + ITypedConverter elementConverter, + ITypedConverter beamConversion, + ITypedConverter columnConversion, + ITypedConverter braceConversion ) { _elementConverter = elementConverter; @@ -27,13 +29,13 @@ public FamilyInstanceTopLevelConverterToSpeckle( _braceConversion = braceConversion; } - public override Base Convert(DB.FamilyInstance target) + public override Base Convert(IRevitFamilyInstance target) { return target.StructuralType switch { - DB.Structure.StructuralType.Beam => _beamConversion.Convert(target), - DB.Structure.StructuralType.Column => _columnConversion.Convert(target), - DB.Structure.StructuralType.Brace => _braceConversion.Convert(target), + RevitStructuralType.Beam => _beamConversion.Convert(target), + RevitStructuralType.Column => _columnConversion.Convert(target), + RevitStructuralType.Brace => _braceConversion.Convert(target), // POC: return generic element conversion or throw? // diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs index 13d0d3086f..3e6c868601 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs @@ -1,32 +1,33 @@ -using Objects; +using Objects; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Converters.RevitShared.Helpers; -using Speckle.Converters.RevitShared.ToSpeckle; using Speckle.Core.Models; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Common; +namespace Speckle.Converters.Revit2023.ToSpeckle; // POC: reminder - writing classes and creating interfaces is a bit like organising your space // if you have a structure for organising things, your interfaces, then finding your stuff, your classes & methods, becomes easy // having a lack of interfaces or large interfaces is a bit like lacking structure, when all of your stuff, your classes & methods // clould be anywhere or all in once place - rooting through box 274 for something you need, when said box has a miriad different // and unrelated items, is no fun. Plus when you need that item, you end up bringing out the whole box/ -[NameAndRankValue(nameof(DB.Floor), 0)] -public class FloorTopLevelConverterToSpeckle : BaseTopLevelConverterToSpeckle +[NameAndRankValue(nameof(IRevitFloor), 0)] +public class FloorTopLevelConverterToSpeckle : BaseTopLevelConverterToSpeckle { - private readonly ITypedConverter> _curveArrArrayConverter; - private readonly ITypedConverter _levelConverter; - private readonly ParameterValueExtractor _parameterValueExtractor; - private readonly ParameterObjectAssigner _parameterObjectAssigner; - private readonly DisplayValueExtractor _displayValueExtractor; + private readonly ITypedConverter> _curveArrArrayConverter; + private readonly ITypedConverter _levelConverter; + private readonly IParameterValueExtractor _parameterValueExtractor; + private readonly IParameterObjectAssigner _parameterObjectAssigner; + private readonly IDisplayValueExtractor _displayValueExtractor; private readonly ISlopeArrowExtractor _slopeArrowExtractor; public FloorTopLevelConverterToSpeckle( - ITypedConverter> curveArrArrayConverter, - ITypedConverter levelConverter, - ParameterValueExtractor parameterValueExtractor, - ParameterObjectAssigner parameterObjectAssigner, - DisplayValueExtractor displayValueExtractor, + ITypedConverter> curveArrArrayConverter, + ITypedConverter levelConverter, + IParameterValueExtractor parameterValueExtractor, + IParameterObjectAssigner parameterObjectAssigner, + IDisplayValueExtractor displayValueExtractor, ISlopeArrowExtractor slopeArrowExtractor ) { @@ -38,14 +39,14 @@ ISlopeArrowExtractor slopeArrowExtractor _slopeArrowExtractor = slopeArrowExtractor; } - public override SOBR.RevitFloor Convert(DB.Floor target) + public override SOBR.RevitFloor Convert(IRevitFloor target) { SOBR.RevitFloor speckleFloor = new(); - var sketch = (DB.Sketch)target.Document.GetElement(target.SketchId); + var sketch = (IRevitSketch)target.Document.GetElement(target.SketchId); List profiles = _curveArrArrayConverter.Convert(sketch.Profile); - DB.ElementType type = (DB.ElementType)target.Document.GetElement(target.GetTypeId()); + IRevitElementType type = (IRevitElementType)target.Document.GetElement(target.GetTypeId()); speckleFloor.family = type.FamilyName; speckleFloor.type = type.Name; @@ -61,13 +62,16 @@ public override SOBR.RevitFloor Convert(DB.Floor target) speckleFloor.voids = profiles.Skip(1).ToList(); } - var level = _parameterValueExtractor.GetValueAsDocumentObject(target, DB.BuiltInParameter.LEVEL_PARAM); + var level = _parameterValueExtractor.GetValueAsDocumentObject( + target, + RevitBuiltInParameter.LEVEL_PARAM + ); speckleFloor.level = _levelConverter.Convert(level); speckleFloor.structural = - _parameterValueExtractor.GetValueAsBool(target, DB.BuiltInParameter.FLOOR_PARAM_IS_STRUCTURAL) ?? false; + _parameterValueExtractor.GetValueAsBool(target, RevitBuiltInParameter.FLOOR_PARAM_IS_STRUCTURAL) ?? false; double? slopeParam = null; - if (_parameterValueExtractor.TryGetValueAsDouble(target, DB.BuiltInParameter.ROOF_SLOPE, out var slope)) + if (_parameterValueExtractor.TryGetValueAsDouble(target, RevitBuiltInParameter.ROOF_SLOPE, out var slope)) { // Divide by 100 to convert from percentage to unitless ratio (rise over run) slopeParam = slope / 100d; @@ -83,9 +87,9 @@ public override SOBR.RevitFloor Convert(DB.Floor target) return speckleFloor; } - private void TryAssignSlopeFromSlopeArrow(DB.Floor target, SOBR.RevitFloor speckleFloor, double? slopeParam) + private void TryAssignSlopeFromSlopeArrow(IRevitFloor target, SOBR.RevitFloor speckleFloor, double? slopeParam) { - if (_slopeArrowExtractor.GetSlopeArrow(target) is not DB.ModelLine slopeArrow) + if (_slopeArrowExtractor.GetSlopeArrow(target) is not IRevitModelLine slopeArrow) { return; } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FootPrintRoofToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FootPrintRoofToSpeckleTopLevelConverter.cs index 1c8e74bb04..6cb002e42c 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FootPrintRoofToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FootPrintRoofToSpeckleTopLevelConverter.cs @@ -1,33 +1,33 @@ -using Autodesk.Revit.DB; -using Objects; -using Objects.BuiltElements.Revit; +using Objects; using Objects.BuiltElements.Revit.RevitRoof; -using Objects.Geometry; using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Converters.RevitShared.Extensions; using Speckle.Converters.RevitShared.Helpers; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023.ToSpeckle; -[NameAndRankValue(nameof(DB.FootPrintRoof), 0)] +[NameAndRankValue(nameof(IRevitFootPrintRoof), 0)] public class FootPrintRoofToSpeckleTopLevelConverter - : BaseTopLevelConverterToSpeckle + : BaseTopLevelConverterToSpeckle { - private readonly ITypedConverter _levelConverter; - private readonly ITypedConverter _modelCurveArrArrayConverter; - private readonly ParameterValueExtractor _parameterValueExtractor; - private readonly DisplayValueExtractor _displayValueExtractor; - private readonly HostedElementConversionToSpeckle _hostedElementConverter; - private readonly ParameterObjectAssigner _parameterObjectAssigner; + private readonly ITypedConverter _levelConverter; + private readonly ITypedConverter _modelCurveArrArrayConverter; + private readonly IParameterValueExtractor _parameterValueExtractor; + private readonly IDisplayValueExtractor _displayValueExtractor; + private readonly IHostedElementConversionToSpeckle _hostedElementConverter; + private readonly IParameterObjectAssigner _parameterObjectAssigner; + private readonly IRevitFilterFactory _revitFilterFactory; public FootPrintRoofToSpeckleTopLevelConverter( - ITypedConverter levelConverter, - ITypedConverter modelCurveArrArrayConverter, - ParameterValueExtractor parameterValueExtractor, - DisplayValueExtractor displayValueExtractor, - HostedElementConversionToSpeckle hostedElementConverter, - ParameterObjectAssigner parameterObjectAssigner + ITypedConverter levelConverter, + ITypedConverter modelCurveArrArrayConverter, + IParameterValueExtractor parameterValueExtractor, + IDisplayValueExtractor displayValueExtractor, + IHostedElementConversionToSpeckle hostedElementConverter, + IParameterObjectAssigner parameterObjectAssigner, + IRevitFilterFactory revitFilterFactory ) { _levelConverter = levelConverter; @@ -36,25 +36,26 @@ ParameterObjectAssigner parameterObjectAssigner _displayValueExtractor = displayValueExtractor; _hostedElementConverter = hostedElementConverter; _parameterObjectAssigner = parameterObjectAssigner; + _revitFilterFactory = revitFilterFactory; } - public override RevitFootprintRoof Convert(FootPrintRoof target) + public override RevitFootprintRoof Convert(IRevitFootPrintRoof target) { - var baseLevel = _parameterValueExtractor.GetValueAsDocumentObject( + var baseLevel = _parameterValueExtractor.GetValueAsDocumentObject( target, - DB.BuiltInParameter.ROOF_BASE_LEVEL_PARAM + RevitBuiltInParameter.ROOF_BASE_LEVEL_PARAM ); // We don't currently validate the success of this TryGet, it is assumed some Roofs don't have a top-level. - _parameterValueExtractor.TryGetValueAsDocumentObject( + _parameterValueExtractor.TryGetValueAsDocumentObject( target, - DB.BuiltInParameter.ROOF_UPTO_LEVEL_PARAM, + RevitBuiltInParameter.ROOF_UPTO_LEVEL_PARAM, out var topLevel ); //POC: CNX-9403 can be null if the sides have different slopes. //We currently don't validate the success or failure of this TryGet as it's not necessary, but will be once we start the above ticket. - _parameterValueExtractor.TryGetValueAsDouble(target, DB.BuiltInParameter.ROOF_SLOPE, out var slope); + _parameterValueExtractor.TryGetValueAsDouble(target, RevitBuiltInParameter.ROOF_SLOPE, out var slope); RevitFootprintRoof speckleFootprintRoof = new() @@ -72,7 +73,7 @@ out var topLevel speckleFootprintRoof.outline = profiles.FirstOrDefault(); speckleFootprintRoof.voids = profiles.Skip(1).ToList(); - var elementType = (ElementType)target.Document.GetElement(target.GetTypeId()); + var elementType = target.Document.GetElement(target.GetTypeId()).ToType().NotNull(); speckleFootprintRoof.type = elementType.Name; speckleFootprintRoof.family = elementType.FamilyName; @@ -81,7 +82,7 @@ out var topLevel _parameterObjectAssigner.AssignParametersToBase(target, speckleFootprintRoof); speckleFootprintRoof.displayValue = _displayValueExtractor.GetDisplayValue(target); speckleFootprintRoof.elements = _hostedElementConverter - .ConvertHostedElements(target.GetHostedElementIds()) + .ConvertHostedElements(target.GetHostedElementIds(_revitFilterFactory)) .ToList(); return speckleFootprintRoof; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/HostedElementConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/HostedElementConversionToSpeckle.cs index 53eef628a9..13c804d77b 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/HostedElementConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/HostedElementConversionToSpeckle.cs @@ -1,36 +1,34 @@ -using Autodesk.Revit.DB; -using Speckle.Converters.Common; -using Speckle.Converters.RevitShared.Helpers; +using Speckle.Converters.Common; using Speckle.Core.Models; +using Speckle.InterfaceGenerator; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023.ToSpeckle; // POC: do we need to see the blocks investigation outcome? Does the current logic hold? // opportunity to rethink or confirm hosted element handling? Should this be a connector responsibiliy? // No interfacing out however... // CNX-9414 Re-evaluate hosted element conversions -public class HostedElementConversionToSpeckle +[GenerateAutoInterface] +public class HostedElementConversionToSpeckle : IHostedElementConversionToSpeckle { - private readonly ToSpeckleConvertedObjectsCache _convertedObjectsCache; private readonly IRootToSpeckleConverter _converter; - private readonly IRevitConversionContextStack _contextStack; + private readonly IConversionContextStack _contextStack; public HostedElementConversionToSpeckle( - ToSpeckleConvertedObjectsCache convertedObjectsCache, IRootToSpeckleConverter converter, - IRevitConversionContextStack contextStack + IConversionContextStack contextStack ) { - _convertedObjectsCache = convertedObjectsCache; _converter = converter; _contextStack = contextStack; } - public IEnumerable ConvertHostedElements(IEnumerable hostedElementIds) + public IEnumerable ConvertHostedElements(IEnumerable hostedElementIds) { foreach (var elemId in hostedElementIds) { - Element element = _contextStack.Current.Document.GetElement(elemId); + IRevitElement element = _contextStack.Current.Document.GetElement(elemId); Base @base; try diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ModelCurveToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ModelCurveToSpeckleTopLevelConverter.cs index 240cbe4713..a2e7357337 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ModelCurveToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ModelCurveToSpeckleTopLevelConverter.cs @@ -1,28 +1,29 @@ -using Objects; +using Objects; using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Converters.RevitShared.Helpers; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023.ToSpeckle; // POC: ModelCurve looks a bit bogus and we may wish to revise what that is and how it inherits // see https://spockle.atlassian.net/browse/CNX-9381 -[NameAndRankValue(nameof(DB.ModelCurve), 0)] -public class ModelCurveToSpeckleTopLevelConverter : BaseTopLevelConverterToSpeckle +[NameAndRankValue(nameof(IRevitModelCurve), 0)] +public class ModelCurveToSpeckleTopLevelConverter + : BaseTopLevelConverterToSpeckle { - private readonly ITypedConverter _curveConverter; - private readonly IRevitConversionContextStack _conversionContext; + private readonly ITypedConverter _curveConverter; + private readonly IConversionContextStack _conversionContext; public ModelCurveToSpeckleTopLevelConverter( - ITypedConverter curveConverter, - IRevitConversionContextStack conversionContext + ITypedConverter curveConverter, + IConversionContextStack conversionContext ) { _curveConverter = curveConverter; _conversionContext = conversionContext; } - public override SOBR.Curve.ModelCurve Convert(DB.ModelCurve target) + public override SOBR.Curve.ModelCurve Convert(IRevitModelCurve target) { var modelCurve = new SOBR.Curve.ModelCurve() { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/RoofBaseToSpeckleTopLevelTopLevelConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/RoofBaseToSpeckleTopLevelTopLevelConverter.cs index 77f9ce831c..c7853c9939 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/RoofBaseToSpeckleTopLevelTopLevelConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/RoofBaseToSpeckleTopLevelTopLevelConverter.cs @@ -1,40 +1,45 @@ -using Autodesk.Revit.DB; -using Objects.BuiltElements.Revit.RevitRoof; +using Objects.BuiltElements.Revit.RevitRoof; using Speckle.Converters.Common; using Speckle.Converters.RevitShared.Extensions; using Speckle.Converters.RevitShared.Helpers; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023.ToSpeckle; -[NameAndRankValue(nameof(DB.RoofBase), 0)] +[NameAndRankValue(nameof(IRevitRoofBase), 0)] internal sealed class RoofBaseToSpeckleTopLevelTopLevelConverter - : BaseTopLevelConverterToSpeckle + : BaseTopLevelConverterToSpeckle { - private readonly DisplayValueExtractor _displayValueExtractor; - private readonly HostedElementConversionToSpeckle _hostedElementConverter; - private readonly ParameterObjectAssigner _parameterObjectAssigner; + private readonly IDisplayValueExtractor _displayValueExtractor; + private readonly IHostedElementConversionToSpeckle _hostedElementConverter; + private readonly IParameterObjectAssigner _parameterObjectAssigner; + private readonly IRevitFilterFactory _revitFilterFactory; public RoofBaseToSpeckleTopLevelTopLevelConverter( - DisplayValueExtractor displayValueExtractor, - HostedElementConversionToSpeckle hostedElementConverter, - ParameterObjectAssigner parameterObjectAssigner + IDisplayValueExtractor displayValueExtractor, + IHostedElementConversionToSpeckle hostedElementConverter, + IParameterObjectAssigner parameterObjectAssigner, + IRevitFilterFactory revitFilterFactory ) { _displayValueExtractor = displayValueExtractor; _hostedElementConverter = hostedElementConverter; _parameterObjectAssigner = parameterObjectAssigner; + _revitFilterFactory = revitFilterFactory; } - public override RevitRoof Convert(RoofBase target) + public override RevitRoof Convert(IRevitRoofBase target) { RevitRoof revitRoof = new(); - var elementType = (ElementType)target.Document.GetElement(target.GetTypeId()); + var elementType = target.Document.GetElement(target.GetTypeId()).ToType().NotNull(); revitRoof.type = elementType.Name; revitRoof.family = elementType.FamilyName; _parameterObjectAssigner.AssignParametersToBase(target, revitRoof); revitRoof.displayValue = _displayValueExtractor.GetDisplayValue(target); - revitRoof.elements = _hostedElementConverter.ConvertHostedElements(target.GetHostedElementIds()).ToList(); + revitRoof.elements = _hostedElementConverter + .ConvertHostedElements(target.GetHostedElementIds(_revitFilterFactory)) + .ToList(); return revitRoof; } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/RoomTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/RoomTopLevelConverterToSpeckle.cs index 6e4e1f91cb..9082b3fec3 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/RoomTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/RoomTopLevelConverterToSpeckle.cs @@ -3,26 +3,27 @@ using Speckle.Converters.Common.Objects; using Speckle.Converters.RevitShared.Helpers; using Speckle.Core.Models; +using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023.ToSpeckle; -[NameAndRankValue(nameof(DBA.Room), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public class RoomTopLevelConverterToSpeckle : BaseTopLevelConverterToSpeckle +[NameAndRankValue(nameof(IRevitRoom), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +public class RoomTopLevelConverterToSpeckle : BaseTopLevelConverterToSpeckle { - private readonly DisplayValueExtractor _displayValueExtractor; - private readonly ParameterObjectAssigner _parameterObjectAssigner; - private readonly ITypedConverter _levelConverter; - private readonly ParameterValueExtractor _parameterValueExtractor; - private readonly ITypedConverter _locationConverter; - private readonly ITypedConverter, SOG.Polycurve> _boundarySegmentConverter; + private readonly IDisplayValueExtractor _displayValueExtractor; + private readonly IParameterObjectAssigner _parameterObjectAssigner; + private readonly ITypedConverter _levelConverter; + private readonly IParameterValueExtractor _parameterValueExtractor; + private readonly ITypedConverter _locationConverter; + private readonly ITypedConverter, SOG.Polycurve> _boundarySegmentConverter; public RoomTopLevelConverterToSpeckle( - DisplayValueExtractor displayValueExtractor, - ParameterObjectAssigner parameterObjectAssigner, - ITypedConverter levelConverter, - ParameterValueExtractor parameterValueExtractor, - ITypedConverter locationConverter, - ITypedConverter, SOG.Polycurve> boundarySegmentConverter + IDisplayValueExtractor displayValueExtractor, + IParameterObjectAssigner parameterObjectAssigner, + ITypedConverter levelConverter, + IParameterValueExtractor parameterValueExtractor, + ITypedConverter locationConverter, + ITypedConverter, SOG.Polycurve> boundarySegmentConverter ) { _displayValueExtractor = displayValueExtractor; @@ -33,19 +34,19 @@ public RoomTopLevelConverterToSpeckle( _boundarySegmentConverter = boundarySegmentConverter; } - public override SOBE.Room Convert(DBA.Room target) + public override SOBE.Room Convert(IRevitRoom target) { var number = target.Number; - var name = _parameterValueExtractor.GetValueAsString(target, DB.BuiltInParameter.ROOM_NAME); - var area = _parameterValueExtractor.GetValueAsDouble(target, DB.BuiltInParameter.ROOM_AREA); + var name = _parameterValueExtractor.GetValueAsString(target, RevitBuiltInParameter.ROOM_NAME); + var area = _parameterValueExtractor.GetValueAsDouble(target, RevitBuiltInParameter.ROOM_AREA); var displayValue = _displayValueExtractor.GetDisplayValue(target); var basePoint = (SOG.Point)_locationConverter.Convert(target.Location); var level = _levelConverter.Convert(target.Level); var profiles = target - .GetBoundarySegments(new DB.SpatialElementBoundaryOptions()) - .Select(c => (ICurve)_boundarySegmentConverter.Convert(c)) + .GetBoundarySegments() + .Select(c => (ICurve)_boundarySegmentConverter.Convert(c.ToList())) .ToList(); var outline = profiles.First(); diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/TopographyTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/TopographyTopLevelConverterToSpeckle.cs index eea4ea51c9..eb3d11afb5 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/TopographyTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/TopographyTopLevelConverterToSpeckle.cs @@ -1,13 +1,15 @@ -using Speckle.Converters.Common; +using Speckle.Converters.Common; +using Speckle.Converters.Revit2023.ToSpeckle; using Speckle.Converters.RevitShared.Helpers; +using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared.ToSpeckle; // POC: needs review feels, BIG, feels like it could be broken down.. // i.e. GetParams(), GetGeom()? feels like it's doing too much -[NameAndRankValue(nameof(DBA.TopographySurface), 0)] +[NameAndRankValue(nameof(IRevitTopographySurface), 0)] public class TopographyTopLevelConverterToSpeckle - : BaseTopLevelConverterToSpeckle + : BaseTopLevelConverterToSpeckle { private readonly DisplayValueExtractor _displayValueExtractor; private readonly ParameterObjectAssigner _parameterObjectAssigner; @@ -21,7 +23,7 @@ ParameterObjectAssigner parameterObjectAssigner _parameterObjectAssigner = parameterObjectAssigner; } - public override SOBR.RevitTopography Convert(DBA.TopographySurface target) + public override SOBR.RevitTopography Convert(IRevitTopographySurface target) { var speckleTopo = new SOBR.RevitTopography { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs index 8e0cce3ba9..7f5bb281b4 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs @@ -1,4 +1,4 @@ -using Speckle.Converters.Common.Objects; +using Speckle.Converters.Common.Objects; using Speckle.Converters.Common; using Objects; using Speckle.Converters.RevitShared.Helpers; @@ -6,32 +6,36 @@ using Speckle.Core.Models.Extensions; using Speckle.Converters.RevitShared.Extensions; using Objects.BuiltElements.Revit; +using Speckle.Converters.Revit2023.ToSpeckle; +using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared.ToSpeckle; // POC: needs review feels, BIG, feels like it could be broken down.. // i.e. GetParams(), GetGeom()? feels like it's doing too much -[NameAndRankValue(nameof(DB.Wall), 0)] -public class WallTopLevelConverterToSpeckle : BaseTopLevelConverterToSpeckle +[NameAndRankValue(nameof(IRevitWall), 0)] +public class WallTopLevelConverterToSpeckle : BaseTopLevelConverterToSpeckle { - private readonly ITypedConverter _curveConverter; - private readonly ITypedConverter _levelConverter; - private readonly ITypedConverter> _curveArrArrayConverter; - private readonly ParameterValueExtractor _parameterValueExtractor; - private readonly IRevitConversionContextStack _contextStack; - private readonly DisplayValueExtractor _displayValueExtractor; - private readonly ParameterObjectAssigner _parameterObjectAssigner; + private readonly ITypedConverter _curveConverter; + private readonly ITypedConverter _levelConverter; + private readonly ITypedConverter> _curveArrArrayConverter; + private readonly IParameterValueExtractor _parameterValueExtractor; + private readonly IConversionContextStack _contextStack; + private readonly IDisplayValueExtractor _displayValueExtractor; + private readonly IParameterObjectAssigner _parameterObjectAssigner; private readonly IRootToSpeckleConverter _converter; + private readonly IRevitFilterFactory _revitFilterFactory; public WallTopLevelConverterToSpeckle( - ITypedConverter curveConverter, - ITypedConverter levelConverter, - ITypedConverter> curveArrArrayConverter, - IRevitConversionContextStack contextStack, - ParameterValueExtractor parameterValueExtractor, - DisplayValueExtractor displayValueExtractor, - ParameterObjectAssigner parameterObjectAssigner, - IRootToSpeckleConverter converter + ITypedConverter curveConverter, + ITypedConverter levelConverter, + ITypedConverter> curveArrArrayConverter, + IConversionContextStack contextStack, + IParameterValueExtractor parameterValueExtractor, + IDisplayValueExtractor displayValueExtractor, + IParameterObjectAssigner parameterObjectAssigner, + IRootToSpeckleConverter converter, + IRevitFilterFactory revitFilterFactory ) { _curveConverter = curveConverter; @@ -42,9 +46,10 @@ IRootToSpeckleConverter converter _displayValueExtractor = displayValueExtractor; _parameterObjectAssigner = parameterObjectAssigner; _converter = converter; + _revitFilterFactory = revitFilterFactory; } - public override SOBR.RevitWall Convert(DB.Wall target) + public override SOBR.RevitWall Convert(IRevitWall target) { SOBR.RevitWall speckleWall = new() { family = target.WallType.FamilyName.ToString(), type = target.WallType.Name }; @@ -57,9 +62,9 @@ public override SOBR.RevitWall Convert(DB.Wall target) return speckleWall; } - private void AssignSpecificParameters(DB.Wall target, RevitWall speckleWall) + private void AssignSpecificParameters(IRevitWall target, RevitWall speckleWall) { - if (target.Location is not DB.LocationCurve locationCurve) + if (target.Location is not IRevitLocationCurve locationCurve) { throw new SpeckleConversionException( "Incorrect assumption was made that all Revit Wall location properties would be of type \"LocationCurve\"" @@ -68,46 +73,46 @@ private void AssignSpecificParameters(DB.Wall target, RevitWall speckleWall) speckleWall.baseLine = _curveConverter.Convert(locationCurve.Curve); - var level = _parameterValueExtractor.GetValueAsDocumentObject( + var level = _parameterValueExtractor.GetValueAsDocumentObject( target, - DB.BuiltInParameter.WALL_BASE_CONSTRAINT + RevitBuiltInParameter.WALL_BASE_CONSTRAINT ); speckleWall.level = _levelConverter.Convert(level); - var topLevel = _parameterValueExtractor.GetValueAsDocumentObject( + var topLevel = _parameterValueExtractor.GetValueAsDocumentObject( target, - DB.BuiltInParameter.WALL_BASE_CONSTRAINT + RevitBuiltInParameter.WALL_BASE_CONSTRAINT ); speckleWall.topLevel = _levelConverter.Convert(topLevel); // POC : what to do if these parameters are unset (instead of assigning default) _ = _parameterValueExtractor.TryGetValueAsDouble( target, - DB.BuiltInParameter.WALL_USER_HEIGHT_PARAM, + RevitBuiltInParameter.WALL_USER_HEIGHT_PARAM, out double? height ); speckleWall.height = height ?? 0; _ = _parameterValueExtractor.TryGetValueAsDouble( target, - DB.BuiltInParameter.WALL_BASE_OFFSET, + RevitBuiltInParameter.WALL_BASE_OFFSET, out double? baseOffset ); speckleWall.baseOffset = baseOffset ?? 0; _ = _parameterValueExtractor.TryGetValueAsDouble( target, - DB.BuiltInParameter.WALL_TOP_OFFSET, + RevitBuiltInParameter.WALL_TOP_OFFSET, out double? topOffset ); speckleWall.topOffset = topOffset ?? 0; speckleWall.structural = - _parameterValueExtractor.GetValueAsBool(target, DB.BuiltInParameter.WALL_STRUCTURAL_SIGNIFICANT) ?? false; + _parameterValueExtractor.GetValueAsBool(target, RevitBuiltInParameter.WALL_STRUCTURAL_SIGNIFICANT) ?? false; speckleWall.flipped = target.Flipped; } - private List GetChildElements(DB.Wall target) + private List GetChildElements(IRevitWall target) { List wallChildren = new(); - if (target.CurtainGrid is DB.CurtainGrid grid) + if (target.CurtainGrid is IRevitCurtainGrid grid) { wallChildren.AddRange(ConvertElements(grid.GetMullionIds())); wallChildren.AddRange(ConvertElements(grid.GetPanelIds())); @@ -116,19 +121,19 @@ private List GetChildElements(DB.Wall target) { wallChildren.AddRange(ConvertElements(target.GetStackedWallMemberIds())); } - wallChildren.AddRange(ConvertElements(target.GetHostedElementIds())); + wallChildren.AddRange(ConvertElements(target.GetHostedElementIds(_revitFilterFactory))); return wallChildren; } - private IEnumerable ConvertElements(IEnumerable elementIds) + private IEnumerable ConvertElements(IEnumerable elementIds) { - foreach (DB.ElementId elementId in elementIds) + foreach (IRevitElementId elementId in elementIds) { yield return _converter.Convert(_contextStack.Current.Document.GetElement(elementId)); } } - private void AssignDisplayValue(DB.Wall target, RevitWall speckleWall) + private void AssignDisplayValue(IRevitWall target, RevitWall speckleWall) { if (target.CurtainGrid is null) { @@ -159,9 +164,9 @@ private void AssignHostedElements(SOBR.RevitWall speckleWall, List hostedO } } - private void AssignVoids(DB.Wall target, SOBR.RevitWall speckleWall) + private void AssignVoids(IRevitWall target, SOBR.RevitWall speckleWall) { - DB.CurveArrArray? profile = ((DB.Sketch)target.Document.GetElement(target.SketchId))?.Profile; + IRevitCurveArrArray? profile = ((IRevitSketch)target.Document.GetElement(target.SketchId))?.Profile; if (profile is null) { return; diff --git a/DUI3-DX/Sdk/Speckle.Autofac/DependencyInjection/ISpeckleContainerContext.cs b/DUI3-DX/Sdk/Speckle.Autofac/DependencyInjection/ISpeckleContainerContext.cs new file mode 100644 index 0000000000..a65698422a --- /dev/null +++ b/DUI3-DX/Sdk/Speckle.Autofac/DependencyInjection/ISpeckleContainerContext.cs @@ -0,0 +1,7 @@ +namespace Speckle.Autofac.DependencyInjection; + +public interface ISpeckleContainerContext +{ + T Resolve() + where T : notnull; +} diff --git a/DUI3-DX/Sdk/Speckle.Autofac/DependencyInjection/SpeckleContainerBuilder.cs b/DUI3-DX/Sdk/Speckle.Autofac/DependencyInjection/SpeckleContainerBuilder.cs index 45c162f3ae..ee71d941e6 100644 --- a/DUI3-DX/Sdk/Speckle.Autofac/DependencyInjection/SpeckleContainerBuilder.cs +++ b/DUI3-DX/Sdk/Speckle.Autofac/DependencyInjection/SpeckleContainerBuilder.cs @@ -9,6 +9,19 @@ namespace Speckle.Autofac.DependencyInjection; public class SpeckleContainerBuilder { + private readonly struct SpeckleContainerContext : ISpeckleContainerContext + { + private readonly IComponentContext _componentContext; + + public SpeckleContainerContext(IComponentContext componentContext) + { + _componentContext = componentContext; + } + + public T Resolve() + where T : notnull => _componentContext.Resolve(); + } + private static readonly Type s_moduleType = typeof(ISpeckleModule); private readonly IStorageInfo _storageInfo; @@ -161,6 +174,13 @@ public SpeckleContainerBuilder AddScoped() return this; } + public SpeckleContainerBuilder AddScoped(Func action) + where T : notnull + { + ContainerBuilder.Register(c => action(new SpeckleContainerContext(c))).InstancePerLifetimeScope(); + return this; + } + public SpeckleContainerBuilder AddScoped() where T : class { @@ -183,6 +203,22 @@ public SpeckleContainerBuilder AddTransient() return this; } + //Scans assembly for classes that implement the same name interface and registers as transient + public SpeckleContainerBuilder ScanAssembly(Assembly assembly) + { + ContainerBuilder + .RegisterAssemblyTypes(assembly) + .Where(t => t.IsClass) + .As(GetInterfacesWithNameName) + .InstancePerDependency(); + return this; + } + + public SpeckleContainerBuilder ScanAssemblyOfType() => ScanAssembly(typeof(T).Assembly); + + private static IEnumerable GetInterfacesWithNameName(Type type) => + type.GetInterfaces().Where(i => i.Name == "I" + type.Name); + public SpeckleContainer Build() { var container = ContainerBuilder.Build(); diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/ContainerRegistration.cs b/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/ContainerRegistration.cs index 6a5fb37913..189bbcc6e7 100644 --- a/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/ContainerRegistration.cs +++ b/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/ContainerRegistration.cs @@ -29,7 +29,7 @@ This will require consolidating across other connectors. builder.AddScoped(); - builder.RegisterRawConversions(); + builder.RegisterConverters(); builder.InjectNamedTypes(); builder.InjectNamedTypes(); } diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/NamedTypeInjector.cs b/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/NamedTypeInjector.cs index c4a0800ce7..1c701cc642 100644 --- a/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/NamedTypeInjector.cs +++ b/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/NamedTypeInjector.cs @@ -7,6 +7,8 @@ namespace Speckle.Converters.Common.DependencyInjection; public static class ConversionTypesInjector { + private record NamedType(string Name, int Rank, Type Type); + public static void InjectNamedTypes(this SpeckleContainerBuilder containerBuilder) where T : notnull { @@ -19,33 +21,33 @@ public static void InjectNamedTypes(this SpeckleContainerBuilder containerBui { var nameAndRank = x.GetCustomAttribute(); - return (name: nameAndRank.Name, rank: nameAndRank.Rank, type: x); + return new NamedType(Name: nameAndRank.Name, Rank: nameAndRank.Rank, Type: x); }) .ToList(); // we'll register the types accordingly - var names = byName.Select(x => x.name).Distinct(); + var names = byName.Select(x => x.Name).Distinct(); foreach (string name in names) { - var namedTypes = byName.Where(x => x.name == name).OrderByDescending(y => y.rank).ToList(); + var namedTypes = byName.Where(x => x.Name == name).OrderByDescending(y => y.Rank).ToList(); // first type found var first = namedTypes[0]; // POC: may need to be instance per lifecycle scope - containerBuilder.ContainerBuilder.RegisterType(first.type).Keyed(first.name).InstancePerLifetimeScope(); + containerBuilder.ContainerBuilder.RegisterType(first.Type).Keyed(first.Name).InstancePerLifetimeScope(); // POC: not sure yet if... // * This should be an array of types // * Whether the scope should be modified or modifiable // * Whether this is in the write project... hmmm // POC: IsAssignableFrom() - var secondaryType = first.type.GetInterface(typeof(ITypedConverter<,>).Name); + var secondaryType = first.Type.GetInterface(typeof(ITypedConverter<,>).Name); // POC: should we explode if no found? if (secondaryType != null) { containerBuilder.ContainerBuilder - .RegisterType(first.type) + .RegisterType(first.Type) .As(secondaryType) .PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies) .InstancePerLifetimeScope(); @@ -57,8 +59,8 @@ public static void InjectNamedTypes(this SpeckleContainerBuilder containerBui { // POC: is this the right scope? containerBuilder.ContainerBuilder - .RegisterType(other.type) - .Keyed($"{other.name}|{other.rank}") + .RegisterType(other.Type) + .Keyed($"{other.Name}|{other.Rank}") .InstancePerLifetimeScope(); // POC: not sure yet if... @@ -67,11 +69,11 @@ public static void InjectNamedTypes(this SpeckleContainerBuilder containerBui // * Whether this is in the write project... hmmm // POC: IsAssignableFrom() // NOT very DRY - secondaryType = first.type.GetInterface(typeof(ITypedConverter<,>).Name); + secondaryType = first.Type.GetInterface(typeof(ITypedConverter<,>).Name); // POC: should we explode if no found? if (secondaryType != null) { - containerBuilder.ContainerBuilder.RegisterType(first.type).As(secondaryType).InstancePerLifetimeScope(); + containerBuilder.ContainerBuilder.RegisterType(first.Type).As(secondaryType).InstancePerLifetimeScope(); } } } diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/RawConversionRegisterer.cs b/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/RawConversionRegisterer.cs index 73745af1f7..7b8743151e 100644 --- a/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/RawConversionRegisterer.cs +++ b/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/RawConversionRegisterer.cs @@ -6,22 +6,29 @@ namespace Speckle.Converters.Common.DependencyInjection; // POC: review and see if it can be made more generic, related to the // NameAndRankAttribute work that needs doing -public static class RawConversionRegisterer +public static class ConverterRegistration { - public static void RegisterRawConversions(this SpeckleContainerBuilder containerBuilder) + public static void RegisterConverters(this SpeckleContainerBuilder containerBuilder) { // POC: hard-coding speckle... :/ foreach (Type speckleType in containerBuilder.SpeckleTypes) { - RegisterRawConversionsForType(containerBuilder.ContainerBuilder, speckleType); + foreach (var conversionInterface in RegisterConversionsForType(speckleType)) + { + containerBuilder.ContainerBuilder + .RegisterType(speckleType) + .As(conversionInterface) + .PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies) + .InstancePerLifetimeScope(); + } } } - private static void RegisterRawConversionsForType(ContainerBuilder containerBuilder, Type type) + private static IEnumerable RegisterConversionsForType(Type type) { if (!type.IsClass || type.IsAbstract) { - return; + yield break; } var rawConversionInterfaces = type.GetInterfaces() @@ -29,11 +36,7 @@ private static void RegisterRawConversionsForType(ContainerBuilder containerBuil foreach (var conversionInterface in rawConversionInterfaces) { - containerBuilder - .RegisterType(type) - .As(conversionInterface) - .PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies) - .InstancePerLifetimeScope(); + yield return conversionInterface.NotNull(); } } } diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common/ContextWrapper.cs b/DUI3-DX/Sdk/Speckle.Converters.Common/ContextWrapper.cs index 02088f06bb..97d77a3389 100644 --- a/DUI3-DX/Sdk/Speckle.Converters.Common/ContextWrapper.cs +++ b/DUI3-DX/Sdk/Speckle.Converters.Common/ContextWrapper.cs @@ -5,7 +5,7 @@ public class ContextWrapper : IDisposable { private IConversionContextStack? _stack; - public ConversionContext? Context { get; private set; } + public IConversionContext? Context { get; private set; } public ContextWrapper(IConversionContextStack stack) { diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common/ConversionContext.cs b/DUI3-DX/Sdk/Speckle.Converters.Common/ConversionContext.cs index 723877d0b9..c4423c1cc2 100644 --- a/DUI3-DX/Sdk/Speckle.Converters.Common/ConversionContext.cs +++ b/DUI3-DX/Sdk/Speckle.Converters.Common/ConversionContext.cs @@ -1,7 +1,9 @@ -namespace Speckle.Converters.Common; +using Speckle.InterfaceGenerator; -// POC: record? -public class ConversionContext +namespace Speckle.Converters.Common; + +[GenerateAutoInterface] +public class ConversionContext : IConversionContext where TDocument : class { public ConversionContext(TDocument doc, string speckleUnits) diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common/ConversionContextStack.cs b/DUI3-DX/Sdk/Speckle.Converters.Common/ConversionContextStack.cs index 918a29d3c1..4575c4da49 100644 --- a/DUI3-DX/Sdk/Speckle.Converters.Common/ConversionContextStack.cs +++ b/DUI3-DX/Sdk/Speckle.Converters.Common/ConversionContextStack.cs @@ -28,9 +28,9 @@ IHostToSpeckleUnitConverter unitConverter _stack.Push(new ConversionContext(_document, _unitConverter.ConvertOrThrow(hostUnit))); } - private readonly Stack> _stack = new(); + private readonly Stack> _stack = new(); - public ConversionContext Current => _stack.Peek(); + public IConversionContext Current => _stack.Peek(); public ContextWrapper Push(string speckleUnit) { @@ -39,10 +39,7 @@ public ContextWrapper Push(string speckleUnit) return new ContextWrapper(this); } - public ContextWrapper Push(THostUnit hostUnit) - { - return Push(_unitConverter.ConvertOrThrow(hostUnit)); - } + public ContextWrapper Push(THostUnit hostUnit) => Push(_unitConverter.ConvertOrThrow(hostUnit)); public void Pop() => _stack.Pop(); } diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common/IProxyMap.cs b/DUI3-DX/Sdk/Speckle.Converters.Common/IProxyMap.cs new file mode 100644 index 0000000000..f73d0fadda --- /dev/null +++ b/DUI3-DX/Sdk/Speckle.Converters.Common/IProxyMap.cs @@ -0,0 +1,23 @@ +namespace Speckle.Converters.Common; + +public interface IProxyMap +{ + Type? GetMappedType(Type type); + + object CreateProxy(Type type, object toWrap); +} + +// ghetto default interface implementation :( +public static class ProxyMapExtensions +{ + public static (Type, object)? WrapIfExists(this IProxyMap proxyMap, Type target, object toWrap) + { + var proxyType = proxyMap.GetMappedType(target); + if (proxyType is not null) + { + return (proxyType, proxyMap.CreateProxy(proxyType, toWrap)); + } + + return null; + } +} diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common/IRootToSpeckleConverter.cs b/DUI3-DX/Sdk/Speckle.Converters.Common/IRootToSpeckleConverter.cs index 6a19ebb13a..10b10ed8af 100644 --- a/DUI3-DX/Sdk/Speckle.Converters.Common/IRootToSpeckleConverter.cs +++ b/DUI3-DX/Sdk/Speckle.Converters.Common/IRootToSpeckleConverter.cs @@ -9,16 +9,22 @@ namespace Speckle.Converters.Common; public class RootToSpeckleConverter : IRootToSpeckleConverter { private readonly IFactory _toSpeckle; + private readonly IProxyMap _proxyMap; - public RootToSpeckleConverter(IFactory toSpeckle) + public RootToSpeckleConverter(IFactory toSpeckle, IProxyMap proxyMap) { _toSpeckle = toSpeckle; + _proxyMap = proxyMap; } public Base Convert(object target) { Type type = target.GetType(); - + var wrapper = _proxyMap.WrapIfExists(type, target); + if (wrapper is not null) + { + (type, target) = wrapper.Value; + } try { var objectConverter = _toSpeckle.ResolveInstance(type.Name); //poc: would be nice to have supertypes resolve From 907e7eeb2978679dd679e5e0c5158cab96a5b422 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Wed, 12 Jun 2024 09:53:34 +0100 Subject: [PATCH 02/25] tests now run --- Build/Consts.cs | 1 + Build/Program.cs | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Build/Consts.cs b/Build/Consts.cs index 9c1eab1ff5..48a14139b0 100644 --- a/Build/Consts.cs +++ b/Build/Consts.cs @@ -5,6 +5,7 @@ namespace Build; public static class Consts { public static readonly string[] Solutions = { "DUI3-DX.slnf" }; + public static readonly string[] TestProjects = { "Speckle.Converters.Revit2023.Tests" }; public static readonly InstallerProject[] InstallerManifests = { diff --git a/Build/Program.cs b/Build/Program.cs index 37675e3a64..815a086a70 100644 --- a/Build/Program.cs +++ b/Build/Program.cs @@ -117,14 +117,15 @@ void RemoveDirectory(string d) Target( TEST, DependsOn(BUILD), - () => + Consts.TestProjects, + t => { IEnumerable GetFiles(string d) { return Glob.Files(".", d); } - foreach (var file in GetFiles("**/*.Test.csproj")) + foreach (var file in GetFiles($"**/{t}.csproj")) { Run("dotnet", $"test {file} -c Release --no-restore --verbosity=normal"); } From f7de9ace489e4745eba7e40c28bc551001f0973c Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Wed, 12 Jun 2024 10:14:04 +0100 Subject: [PATCH 03/25] adding more to proxy map --- .../DependencyInjection/ProxyMap.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs index b54b9850ee..570451a6fe 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs @@ -16,6 +16,14 @@ static ProxyMap() { Add(x => new ElementProxy(x)); Add(x => new FamilyInstanceProxy(x)); + Add(x => new CurveProxy(x)); + Add(x => new BoundarySegmentProxy(x)); + Add(x => new LevelProxy(x)); + Add(x => new LocationProxy(x)); + Add(x => new MaterialProxy(x)); + Add(x => new ModelCurveArrayProxy(x)); + Add(x => new ModelCurveArrArrayProxy(x)); + Add(x => new ParameterProxy(x)); } private static void Add(Func f) From b430010a9c2e6306ba4dd6f5cdfb02424d72f664 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Wed, 12 Jun 2024 10:31:08 +0100 Subject: [PATCH 04/25] switch to FluentAssertions --- .../LocationConversionToSpeckleTests.cs | 12 ++--- .../Speckle.Converters.Revit2023.Tests.csproj | 2 +- .../packages.lock.json | 51 ++++--------------- 3 files changed, 16 insertions(+), 49 deletions(-) diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/LocationConversionToSpeckleTests.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/LocationConversionToSpeckleTests.cs index e4fced21cd..f791320afa 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/LocationConversionToSpeckleTests.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/LocationConversionToSpeckleTests.cs @@ -1,9 +1,9 @@ -using Moq; +using FluentAssertions; +using Moq; using NUnit.Framework; using Objects; using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Shouldly; using Speckle.Converters.RevitShared.Services; using Speckle.Revit.Interfaces; @@ -76,9 +76,9 @@ public void Convert() ); var polycurve = sut.Convert(new List() { curve1.Object, curve2.Object }); - polycurve.units.ShouldBe(units); - polycurve.closed.ShouldBeFalse(); - polycurve.length.ShouldBe(scaleLength); - polycurve.segments.Count.ShouldBe(2); + polycurve.units.Should().Be(units); + polycurve.closed.Should().BeFalse(); + polycurve.length.Should().Be(scaleLength); + polycurve.segments.Count.Should().Be(2); } } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/Speckle.Converters.Revit2023.Tests.csproj b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/Speckle.Converters.Revit2023.Tests.csproj index 0d58315a39..77ecc0132a 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/Speckle.Converters.Revit2023.Tests.csproj +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/Speckle.Converters.Revit2023.Tests.csproj @@ -8,12 +8,12 @@ + - diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/packages.lock.json b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/packages.lock.json index 978bc4bd9c..43739bd4af 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/packages.lock.json +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/packages.lock.json @@ -8,6 +8,15 @@ "resolved": "6.0.2", "contentHash": "bJShQ6uWRTQ100ZeyiMqcFlhP7WJ+bCuabUs885dJiBEzMsJMSFr7BOyeCw4rgvQokteGi5rKQTlkhfQPUXg2A==" }, + "FluentAssertions": { + "type": "Direct", + "requested": "[6.12.0, )", + "resolved": "6.12.0", + "contentHash": "ZXhHT2YwP9lajrwSKbLlFqsmCCvFJMoRSK9t7sImfnCyd0OB3MhgxdoMcVqxbq1iyxD6mD2fiackWmBb7ayiXQ==", + "dependencies": { + "System.Threading.Tasks.Extensions": "4.5.0" + } + }, "Microsoft.NET.Test.Sdk": { "type": "Direct", "requested": "[17.10.0, )", @@ -48,17 +57,6 @@ "resolved": "1.14.1", "contentHash": "mOOmFYwad3MIOL14VCjj02LljyF1GNw1wP0YVlxtcPvqdxjGGMNdNJJxHptlry3MOd8b40Flm8RPOM8JOlN2sQ==" }, - "Shouldly": { - "type": "Direct", - "requested": "[4.2.1, )", - "resolved": "4.2.1", - "contentHash": "dKAKiSuhLKqD2TXwLKtqNg1nwzJcIKOOMncZjk9LYe4W+h+SCftpWdxwR79YZUIHMH+3Vu9s0s0UHNrgICLwRQ==", - "dependencies": { - "DiffEngine": "11.3.0", - "EmptyFiles": "4.4.0", - "Microsoft.CSharp": "4.7.0" - } - }, "Speckle.InterfaceGenerator": { "type": "Direct", "requested": "[0.9.5, )", @@ -76,24 +74,6 @@ "resolved": "5.1.1", "contentHash": "rpYtIczkzGpf+EkZgDr9CClTdemhsrwA/W5hMoPjLkRFnXzH44zDLoovXeKtmxb1ykXK9aJVODSpiJml8CTw2g==" }, - "DiffEngine": { - "type": "Transitive", - "resolved": "11.3.0", - "contentHash": "k0ZgZqd09jLZQjR8FyQbSQE86Q7QZnjEzq1LPHtj1R2AoWO8sjV5x+jlSisL7NZAbUOI4y+7Bog8gkr9WIRBGw==", - "dependencies": { - "EmptyFiles": "4.4.0", - "System.Management": "6.0.1" - } - }, - "EmptyFiles": { - "type": "Transitive", - "resolved": "4.4.0", - "contentHash": "gwJEfIGS7FhykvtZoscwXj/XwW+mJY6UbAZk+qtLKFUGWC95kfKXnj8VkxsZQnWBxJemM/q664rGLN5nf+OHZw==", - "dependencies": { - "System.Memory": "4.5.5", - "System.ValueTuple": "4.5.0" - } - }, "GraphQL.Client": { "type": "Transitive", "resolved": "6.0.0", @@ -387,11 +367,6 @@ "resolved": "4.5.1", "contentHash": "Rw7ijyl1qqRS0YQD/WycNst8hUUMgrMH4FCn1nNm27M4VxchZ1js3fVjQaANHO5f3sN4isvP4a+Met9Y4YomAg==" }, - "System.CodeDom": { - "type": "Transitive", - "resolved": "6.0.0", - "contentHash": "CPc6tWO1LAer3IzfZufDBRL+UZQcj5uS207NHALQzP84Vp/z6wF0Aa0YZImOQY8iStY0A2zI/e3ihKNPfUm8XA==" - }, "System.Collections.Immutable": { "type": "Transitive", "resolved": "5.0.0", @@ -417,14 +392,6 @@ "NETStandard.Library": "1.6.1" } }, - "System.Management": { - "type": "Transitive", - "resolved": "6.0.1", - "contentHash": "10J1D0h/lioojphfJ4Fuh5ZUThT/xOVHdV9roGBittKKNP2PMjrvibEdbVTGZcPra1399Ja3tqIJLyQrc5Wmhg==", - "dependencies": { - "System.CodeDom": "6.0.0" - } - }, "System.Memory": { "type": "Transitive", "resolved": "4.5.5", From c95677eea5ecf2c50f25ade95ba7ba31159ef806 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Wed, 12 Jun 2024 13:47:38 +0100 Subject: [PATCH 05/25] fix IRevitLevel conversions --- .../Helpers/ParameterValueExtractor.cs | 32 ++++--------------- .../Raw/BeamConversionToSpeckle.cs | 4 +-- .../Raw/ColumnConversionToSpeckle.cs | 8 ++--- .../CeilingTopLevelConverterToSpeckle.cs | 4 +-- ...ExtrusionRoofToSpeckleTopLevelConverter.cs | 4 +-- .../FloorTopLevelConverterToSpeckle.cs | 4 +-- ...FootPrintRoofToSpeckleTopLevelConverter.cs | 9 +++--- .../WallTopLevelConverterToSpeckle.cs | 8 ++--- 8 files changed, 26 insertions(+), 47 deletions(-) diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs index bfd8880264..e7270073c3 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs @@ -1,4 +1,4 @@ -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; using Speckle.Converters.Common; using Speckle.Converters.RevitShared.Extensions; using Speckle.Converters.RevitShared.Services; @@ -156,39 +156,19 @@ is IRevitElementId elementIdNotNull { return GetValueGeneric(parameter, IRevitStorageType.ElementId, (parameter) => parameter.AsElementId()); } - - public bool TryGetValueAsDocumentObject( + + public IRevitLevel? GetValueAsRevitLevel( IRevitElement element, - RevitBuiltInParameter builtInParameter, - [NotNullWhen(true)] out T? value + RevitBuiltInParameter builtInParameter ) { if (!TryGetValueAsElementId(element, builtInParameter, out var elementId)) { - value = default; - return false; + throw new SpeckleConversionException(); } IRevitElement paramElement = element.Document.GetElement(elementId); - if (paramElement is not T typedElement) - { - value = default; - return false; - } - - value = typedElement; - return true; - } - - public T GetValueAsDocumentObject(IRevitElement element, RevitBuiltInParameter builtInParameter) - where T : class - { - if (!TryGetValueAsDocumentObject(element, builtInParameter, out var value)) - { - throw new SpeckleConversionException($"Failed to get {builtInParameter} as an element of type {typeof(T)}"); - } - - return value; // If TryGet returns true, we succeeded in obtaining the value, and it will not be null. + return paramElement.ToLevel(); } private TResult? GetValueGeneric( diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BeamConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BeamConversionToSpeckle.cs index 1e3608c4f3..27b7ed1961 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BeamConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BeamConversionToSpeckle.cs @@ -54,11 +54,11 @@ public SOBR.RevitBeam Convert(IRevitFamilyInstance target) baseLine = baseCurve }; - var level = _parameterValueExtractor.GetValueAsDocumentObject( + var level = _parameterValueExtractor.GetValueAsRevitLevel( target, RevitBuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM ); - speckleBeam.level = _levelConverter.Convert(level); + speckleBeam.level = _levelConverter.Convert(level.NotNull()); speckleBeam.displayValue = _displayValueExtractor.GetDisplayValue(target); diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs index e729e75630..5a910e5b71 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs @@ -42,18 +42,18 @@ public SOBR.RevitColumn Convert(IRevitFamilyInstance target) SOBR.RevitColumn speckleColumn = new() { family = symbol.FamilyName, type = target.Document.GetElement(target.GetTypeId()).Name }; - var level = _parameterValueExtractor.GetValueAsDocumentObject( + var level = _parameterValueExtractor.GetValueAsRevitLevel( target, RevitBuiltInParameter.FAMILY_BASE_LEVEL_PARAM ); - speckleColumn.level = _levelConverter.Convert(level); + speckleColumn.level = _levelConverter.Convert(level.NotNull()); - var topLevel = _parameterValueExtractor.GetValueAsDocumentObject( + var topLevel = _parameterValueExtractor.GetValueAsRevitLevel( target, RevitBuiltInParameter.FAMILY_TOP_LEVEL_PARAM ); - speckleColumn.topLevel = _levelConverter.Convert(topLevel); + speckleColumn.topLevel = _levelConverter.Convert(topLevel.NotNull()); speckleColumn.baseOffset = _parameterValueExtractor.GetValueAsDouble( target, RevitBuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs index 5e2bd504d1..805137ac39 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs @@ -60,11 +60,11 @@ public override RevitCeiling Convert(IRevitCeiling target) // POC: our existing receive operation is checking the "slopeDirection" prop, // but it is never being set. We should be setting it - var level = _parameterValueExtractor.GetValueAsDocumentObject( + var level = _parameterValueExtractor.GetValueAsRevitLevel( target, RevitBuiltInParameter.LEVEL_PARAM ); - speckleCeiling.level = _levelConverter.Convert(level); + speckleCeiling.level = _levelConverter.Convert(level.NotNull()); _parameterObjectAssigner.AssignParametersToBase(target, speckleCeiling); speckleCeiling.displayValue = _displayValueExtractor.GetDisplayValue(target); diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ExtrusionRoofToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ExtrusionRoofToSpeckleTopLevelConverter.cs index db49dd9884..b0e2b89422 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ExtrusionRoofToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ExtrusionRoofToSpeckleTopLevelConverter.cs @@ -53,11 +53,11 @@ public override RevitExtrusionRoof Convert(IRevitExtrusionRoof target) _pointConverter.Convert(plane.Origin.Add(plane.XVec.Normalize().Negate())), _pointConverter.Convert(plane.Origin) ); - var level = _parameterValueExtractor.GetValueAsDocumentObject( + var level = _parameterValueExtractor.GetValueAsRevitLevel( target, RevitBuiltInParameter.ROOF_CONSTRAINT_LEVEL_PARAM ); - speckleExtrusionRoof.level = _levelConverter.Convert(level); + speckleExtrusionRoof.level = _levelConverter.Convert(level.NotNull()); speckleExtrusionRoof.outline = _modelCurveArrayConverter.Convert(target.GetProfile()); var elementType = (IRevitElementType)target.Document.GetElement(target.GetTypeId()); diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs index 3e6c868601..874c9e9b5f 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs @@ -62,11 +62,11 @@ public override SOBR.RevitFloor Convert(IRevitFloor target) speckleFloor.voids = profiles.Skip(1).ToList(); } - var level = _parameterValueExtractor.GetValueAsDocumentObject( + var level = _parameterValueExtractor.GetValueAsRevitLevel( target, RevitBuiltInParameter.LEVEL_PARAM ); - speckleFloor.level = _levelConverter.Convert(level); + speckleFloor.level = _levelConverter.Convert(level.NotNull()); speckleFloor.structural = _parameterValueExtractor.GetValueAsBool(target, RevitBuiltInParameter.FLOOR_PARAM_IS_STRUCTURAL) ?? false; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FootPrintRoofToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FootPrintRoofToSpeckleTopLevelConverter.cs index 6cb002e42c..9f9faa856c 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FootPrintRoofToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FootPrintRoofToSpeckleTopLevelConverter.cs @@ -41,16 +41,15 @@ IRevitFilterFactory revitFilterFactory public override RevitFootprintRoof Convert(IRevitFootPrintRoof target) { - var baseLevel = _parameterValueExtractor.GetValueAsDocumentObject( + var baseLevel = _parameterValueExtractor.GetValueAsRevitLevel( target, RevitBuiltInParameter.ROOF_BASE_LEVEL_PARAM ); // We don't currently validate the success of this TryGet, it is assumed some Roofs don't have a top-level. - _parameterValueExtractor.TryGetValueAsDocumentObject( + var topLevel = _parameterValueExtractor.GetValueAsRevitLevel( target, - RevitBuiltInParameter.ROOF_UPTO_LEVEL_PARAM, - out var topLevel + RevitBuiltInParameter.ROOF_UPTO_LEVEL_PARAM ); //POC: CNX-9403 can be null if the sides have different slopes. @@ -60,7 +59,7 @@ out var topLevel RevitFootprintRoof speckleFootprintRoof = new() { - level = _levelConverter.Convert(baseLevel), + level = _levelConverter.Convert(baseLevel.NotNull()), cutOffLevel = topLevel is not null ? _levelConverter.Convert(topLevel) : null, slope = slope }; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs index 7f5bb281b4..501ee4ef3f 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs @@ -73,17 +73,17 @@ private void AssignSpecificParameters(IRevitWall target, RevitWall speckleWall) speckleWall.baseLine = _curveConverter.Convert(locationCurve.Curve); - var level = _parameterValueExtractor.GetValueAsDocumentObject( + var level = _parameterValueExtractor.GetValueAsRevitLevel( target, RevitBuiltInParameter.WALL_BASE_CONSTRAINT ); - speckleWall.level = _levelConverter.Convert(level); + speckleWall.level = _levelConverter.Convert(level.NotNull()); - var topLevel = _parameterValueExtractor.GetValueAsDocumentObject( + var topLevel = _parameterValueExtractor.GetValueAsRevitLevel( target, RevitBuiltInParameter.WALL_BASE_CONSTRAINT ); - speckleWall.topLevel = _levelConverter.Convert(topLevel); + speckleWall.topLevel = _levelConverter.Convert(topLevel.NotNull()); // POC : what to do if these parameters are unset (instead of assigning default) _ = _parameterValueExtractor.TryGetValueAsDouble( From 4b5fbf2c8da036a54fa0d96388300935e1e9f709 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Wed, 12 Jun 2024 16:32:24 +0100 Subject: [PATCH 06/25] more cast handling --- .../Helpers/SlopeArrowExtractor.cs | 4 +-- .../Raw/ColumnConversionToSpeckle.cs | 2 +- .../Raw/Geometry/CurveConversionToSpeckle.cs | 34 ++++++++++++++----- .../WallTopLevelConverterToSpeckle.cs | 3 +- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/SlopeArrowExtractor.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/SlopeArrowExtractor.cs index d5f69d29d3..114ecc8fbd 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/SlopeArrowExtractor.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/SlopeArrowExtractor.cs @@ -56,12 +56,12 @@ IRevitFilterFactory revitFilterFactory public SOG.Point GetSlopeArrowHead(IRevitModelLine slopeArrow) { - return _pointConverter.Convert((slopeArrow.Location.ToLocationCurve().NotNull()).Curve.GetEndPoint(1)); + return _pointConverter.Convert((slopeArrow.GetLocationAsLocationCurve().NotNull()).Curve.GetEndPoint(1)); } public SOG.Point GetSlopeArrowTail(IRevitModelLine slopeArrow) { - return _pointConverter.Convert((slopeArrow.Location.ToLocationCurve().NotNull()).Curve.GetEndPoint(0)); + return _pointConverter.Convert((slopeArrow.GetLocationAsLocationCurve().NotNull()).Curve.GetEndPoint(0)); } public double GetSlopeArrowTailOffset(IRevitModelLine slopeArrow) diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs index 5a910e5b71..4c7277b09d 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs @@ -68,7 +68,7 @@ public SOBR.RevitColumn Convert(IRevitFamilyInstance target) speckleColumn.handFlipped = target.HandFlipped; speckleColumn.isSlanted = target.IsSlantedColumn; - var locationPoint = target.Location.ToLocationPoint(); + var locationPoint = target.GetLocationAsLocationPoint(); if (locationPoint is not null) { speckleColumn.rotation = locationPoint.Rotation; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveConversionToSpeckle.cs index 3798e42cbf..5cf220c982 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveConversionToSpeckle.cs @@ -33,16 +33,32 @@ public CurveConversionToSpeckle( public ICurve Convert(IRevitCurve target) { - return target switch + var line = target.ToLine(); + if (line is not null) { - IRevitLine line => _lineConverter.Convert(line), - // POC: are maybe arc.IsCyclic ? - IRevitArc arc => arc.IsClosed ? _circleConverter.Convert(arc) : _arcConverter.Convert(arc), - IRevitEllipse ellipse => _ellipseConverter.Convert(ellipse), - IRevitNurbSpline nurbs => _nurbsConverter.Convert(nurbs), - IRevitHermiteSpline hermite => _hermiteConverter.Convert(hermite), + return _lineConverter.Convert(line); + } + var arc = target.ToArc(); + if (arc is not null) + { + return arc.IsClosed ? _circleConverter.Convert(arc) : _arcConverter.Convert(arc); + } + var ellipse = target.ToEllipse(); + if (ellipse is not null) + { + return _ellipseConverter.Convert(ellipse); + } + var nurbs = target.ToNurbSpline(); + if (nurbs is not null) + { + return _nurbsConverter.Convert(nurbs); + } + var hermite = target.ToHermiteSpline(); + if (hermite is not null) + { + return _hermiteConverter.Convert(hermite); + } - _ => throw new SpeckleConversionException($"Unsupported curve type {target.GetType()}") - }; + throw new SpeckleConversionException($"Unsupported curve type {target.GetType()}"); } } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs index 501ee4ef3f..fdfb0593ca 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs @@ -64,7 +64,8 @@ public override SOBR.RevitWall Convert(IRevitWall target) private void AssignSpecificParameters(IRevitWall target, RevitWall speckleWall) { - if (target.Location is not IRevitLocationCurve locationCurve) + var locationCurve = target.GetLocationAsLocationCurve(); + if (locationCurve is null) { throw new SpeckleConversionException( "Incorrect assumption was made that all Revit Wall location properties would be of type \"LocationCurve\"" From 6153576a4106d3dc5d3c4412bbeb04e4aac28a42 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Thu, 13 Jun 2024 08:32:36 +0100 Subject: [PATCH 07/25] use proxymap for ofclass --- .../DependencyInjection/ProxyMap.cs | 13 +++++++++-- .../RevitConnectorModule.cs | 2 +- .../RevitConversionContextStack.cs | 3 --- .../Services/ReferencePointConverter.cs | 7 +++--- .../Speckle.Converters.Common/IProxyMap.cs | 23 ------------------- .../IRootToSpeckleConverter.cs | 1 + 6 files changed, 17 insertions(+), 32 deletions(-) delete mode 100644 DUI3-DX/Sdk/Speckle.Converters.Common/IProxyMap.cs diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs index 570451a6fe..d810eda5f6 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs @@ -1,6 +1,5 @@ using System.Collections.Concurrent; using System.Diagnostics.CodeAnalysis; -using Speckle.Converters.Common; using Speckle.Revit.Api; using Speckle.Revit.Interfaces; @@ -10,6 +9,7 @@ namespace Speckle.Connectors.Revit2023.Converters; public class ProxyMap : IProxyMap { private static readonly ConcurrentDictionary s_typeMaps = new(); + private static readonly ConcurrentDictionary s_reverseMaps = new(); private static readonly ConcurrentDictionary> s_proxyFactory = new(); static ProxyMap() @@ -24,6 +24,7 @@ static ProxyMap() Add(x => new ModelCurveArrayProxy(x)); Add(x => new ModelCurveArrArrayProxy(x)); Add(x => new ParameterProxy(x)); + Add(x => new BasePointProxy(x)); } private static void Add(Func f) @@ -32,6 +33,7 @@ private static void Add(Func f) { s_typeMaps.TryAdd(typeof(T), typeof(TProxy)); s_proxyFactory.TryAdd(typeof(TProxy), w => f((T)w)); + s_reverseMaps.TryAdd(typeof(TProxy), typeof(T)); } public Type? GetMappedType(Type type) @@ -42,6 +44,13 @@ private static void Add(Func f) } return null; } - + public Type? UnmapType(Type type) + { + if (s_reverseMaps.TryGetValue(type, out var t)) + { + return t; + } + return null; + } public object CreateProxy(Type type, object toWrap) => s_proxyFactory[type](toWrap); } diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/RevitConnectorModule.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/RevitConnectorModule.cs index b50683124c..bc2e05a284 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/RevitConnectorModule.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/RevitConnectorModule.cs @@ -15,7 +15,7 @@ using Speckle.Connectors.Utils.Builders; using Speckle.Connectors.Utils.Caching; using Speckle.Connectors.Utils.Operations; -using Speckle.Converters.Common; +using Speckle.Revit.Interfaces; namespace Speckle.Connectors.Revit.DependencyInjection; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConversionContextStack.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConversionContextStack.cs index 02ca3b09e2..42bfb48aeb 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConversionContextStack.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConversionContextStack.cs @@ -32,9 +32,6 @@ public RevitConversionContextStack(RevitContext context, IHostToSpeckleUnitConve unitConverter ) { } - IConversionContext IConversionContextStack.Current => - new ConversionContext(base.Current.Document, base.Current.SpeckleUnits); - ContextWrapper IConversionContextStack.Push( string speckleUnit ) => throw new NotImplementedException(); diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/ReferencePointConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/ReferencePointConverter.cs index 450ee5e16e..75ede14395 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/ReferencePointConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/ReferencePointConverter.cs @@ -32,6 +32,7 @@ public class ReferencePointConverter : IReferencePointConverter private readonly IRevitTransformUtils _transformUtils; private readonly IRevitFilterFactory _revitFilterFactory; private readonly IRevitXYZUtils _revitXyzUtils; + private readonly IProxyMap _proxyMap; private readonly Dictionary _docTransforms = new(); @@ -40,14 +41,14 @@ public ReferencePointConverter( IRevitConversionSettings revitSettings, IRevitFilterFactory revitFilterFactory, IRevitTransformUtils transformUtils, - IRevitXYZUtils revitXyzUtils - ) + IRevitXYZUtils revitXyzUtils, IProxyMap proxyMap) { _contextStack = contextStack; _revitSettings = revitSettings; _revitFilterFactory = revitFilterFactory; _transformUtils = transformUtils; _revitXyzUtils = revitXyzUtils; + _proxyMap = proxyMap; } // POC: the original allowed for the document to be passed in @@ -89,7 +90,7 @@ public IRevitTransform GetReferencePointTransform(string referencePointSetting) // POC: bogus disposal below var points = _revitFilterFactory .CreateFilteredElementCollector(_contextStack.Current.Document) - .OfClass() + .OfClass(_proxyMap) .ToList(); var projectPoint = NotNullExtensions.NotNull(points.FirstOrDefault(o => o.IsShared == false), "No projectPoint"); diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common/IProxyMap.cs b/DUI3-DX/Sdk/Speckle.Converters.Common/IProxyMap.cs deleted file mode 100644 index f73d0fadda..0000000000 --- a/DUI3-DX/Sdk/Speckle.Converters.Common/IProxyMap.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace Speckle.Converters.Common; - -public interface IProxyMap -{ - Type? GetMappedType(Type type); - - object CreateProxy(Type type, object toWrap); -} - -// ghetto default interface implementation :( -public static class ProxyMapExtensions -{ - public static (Type, object)? WrapIfExists(this IProxyMap proxyMap, Type target, object toWrap) - { - var proxyType = proxyMap.GetMappedType(target); - if (proxyType is not null) - { - return (proxyType, proxyMap.CreateProxy(proxyType, toWrap)); - } - - return null; - } -} diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common/IRootToSpeckleConverter.cs b/DUI3-DX/Sdk/Speckle.Converters.Common/IRootToSpeckleConverter.cs index 10b10ed8af..83e3285f31 100644 --- a/DUI3-DX/Sdk/Speckle.Converters.Common/IRootToSpeckleConverter.cs +++ b/DUI3-DX/Sdk/Speckle.Converters.Common/IRootToSpeckleConverter.cs @@ -2,6 +2,7 @@ using Speckle.Converters.Common.Objects; using Speckle.Core.Models; using Speckle.InterfaceGenerator; +using Speckle.Revit.Interfaces; namespace Speckle.Converters.Common; From 11e51deee773b728048bb8ec6b2a41916c9195a5 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Thu, 13 Jun 2024 09:02:15 +0100 Subject: [PATCH 08/25] update revit interfaces --- .../DependencyInjection/ProxyMap.cs | 2 ++ ...le.Converters.Revit2023.DependencyInjection.csproj | 2 +- .../Speckle.Converters.Revit2023.Tests.csproj | 2 +- .../packages.lock.json | 11 ++++++----- .../Speckle.Converters.Revit2023.csproj | 2 +- .../Speckle.Converters.Common.csproj | 4 +++- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs index d810eda5f6..3f454e208a 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs @@ -25,6 +25,8 @@ static ProxyMap() Add(x => new ModelCurveArrArrayProxy(x)); Add(x => new ParameterProxy(x)); Add(x => new BasePointProxy(x)); + Add(x => new WallProxy(x)); + Add(x => new PanelProxy(x)); } private static void Add(Func f) diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/Speckle.Converters.Revit2023.DependencyInjection.csproj b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/Speckle.Converters.Revit2023.DependencyInjection.csproj index 5e73505906..5cd7d827cb 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/Speckle.Converters.Revit2023.DependencyInjection.csproj +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/Speckle.Converters.Revit2023.DependencyInjection.csproj @@ -6,7 +6,7 @@ - + diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/Speckle.Converters.Revit2023.Tests.csproj b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/Speckle.Converters.Revit2023.Tests.csproj index 77ecc0132a..f82da26310 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/Speckle.Converters.Revit2023.Tests.csproj +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/Speckle.Converters.Revit2023.Tests.csproj @@ -14,7 +14,7 @@ - + diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/packages.lock.json b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/packages.lock.json index 43739bd4af..393b4d48d6 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/packages.lock.json +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/packages.lock.json @@ -65,9 +65,9 @@ }, "Speckle.Revit2023.Interfaces": { "type": "Direct", - "requested": "[0.1.1-preview.0.16, )", - "resolved": "0.1.1-preview.0.16", - "contentHash": "AsKpt0cQ6OdhL31DGgfyp2DhLSJxHrY7pQscrrvWHVTl+l/lrgZgrnCZIqUCVMnhv6NvXmGNm7G7zPOpsKDCnw==" + "requested": "[0.1.1-preview.0.18, )", + "resolved": "0.1.1-preview.0.18", + "contentHash": "6YcocyBY9cLHwdKqpy7VY3amlT4/m+7dw74tglta8pGYfVfMzWq8Rtq4CBywXcxIxtimcjYceJ/le5Q0VVao7w==" }, "Castle.Core": { "type": "Transitive", @@ -498,7 +498,8 @@ "type": "Project", "dependencies": { "Speckle.Autofac": "[2.0.999-local, )", - "Speckle.Objects": "[2.0.999-local, )" + "Speckle.Objects": "[2.0.999-local, )", + "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.18, )" } }, "speckle.converters.common.dependencyinjection": { @@ -512,7 +513,7 @@ "type": "Project", "dependencies": { "Speckle.Converters.Common": "[2.0.999-local, )", - "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.16, )" + "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.18, )" } }, "Speckle.Core": { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/Speckle.Converters.Revit2023.csproj b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/Speckle.Converters.Revit2023.csproj index 3f7d7c8eec..c127965904 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/Speckle.Converters.Revit2023.csproj +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/Speckle.Converters.Revit2023.csproj @@ -9,7 +9,7 @@ - + diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common/Speckle.Converters.Common.csproj b/DUI3-DX/Sdk/Speckle.Converters.Common/Speckle.Converters.Common.csproj index 7c611c401a..daff575890 100644 --- a/DUI3-DX/Sdk/Speckle.Converters.Common/Speckle.Converters.Common.csproj +++ b/DUI3-DX/Sdk/Speckle.Converters.Common/Speckle.Converters.Common.csproj @@ -3,7 +3,9 @@ netstandard2.0 - + + + From 9895c118c338d744a81a73793ded526bb1689d77 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Thu, 13 Jun 2024 09:02:50 +0100 Subject: [PATCH 09/25] fmt --- .../DependencyInjection/ProxyMap.cs | 2 ++ .../Helpers/ParameterValueExtractor.cs | 7 ++----- .../Raw/ColumnConversionToSpeckle.cs | 10 ++-------- .../Raw/Geometry/CurveConversionToSpeckle.cs | 6 +++--- .../Services/ReferencePointConverter.cs | 4 +++- .../ToSpeckle/CeilingTopLevelConverterToSpeckle.cs | 5 +---- .../ToSpeckle/FloorTopLevelConverterToSpeckle.cs | 5 +---- .../FootPrintRoofToSpeckleTopLevelConverter.cs | 10 ++-------- .../ToSpeckle/WallTopLevelConverterToSpeckle.cs | 10 ++-------- 9 files changed, 18 insertions(+), 41 deletions(-) diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs index 3f454e208a..5b961a0ccb 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs @@ -46,6 +46,7 @@ private static void Add(Func f) } return null; } + public Type? UnmapType(Type type) { if (s_reverseMaps.TryGetValue(type, out var t)) @@ -54,5 +55,6 @@ private static void Add(Func f) } return null; } + public object CreateProxy(Type type, object toWrap) => s_proxyFactory[type](toWrap); } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs index e7270073c3..47e2bb905f 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs @@ -156,11 +156,8 @@ is IRevitElementId elementIdNotNull { return GetValueGeneric(parameter, IRevitStorageType.ElementId, (parameter) => parameter.AsElementId()); } - - public IRevitLevel? GetValueAsRevitLevel( - IRevitElement element, - RevitBuiltInParameter builtInParameter - ) + + public IRevitLevel? GetValueAsRevitLevel(IRevitElement element, RevitBuiltInParameter builtInParameter) { if (!TryGetValueAsElementId(element, builtInParameter, out var elementId)) { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs index 4c7277b09d..149b382834 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs @@ -42,16 +42,10 @@ public SOBR.RevitColumn Convert(IRevitFamilyInstance target) SOBR.RevitColumn speckleColumn = new() { family = symbol.FamilyName, type = target.Document.GetElement(target.GetTypeId()).Name }; - var level = _parameterValueExtractor.GetValueAsRevitLevel( - target, - RevitBuiltInParameter.FAMILY_BASE_LEVEL_PARAM - ); + var level = _parameterValueExtractor.GetValueAsRevitLevel(target, RevitBuiltInParameter.FAMILY_BASE_LEVEL_PARAM); speckleColumn.level = _levelConverter.Convert(level.NotNull()); - var topLevel = _parameterValueExtractor.GetValueAsRevitLevel( - target, - RevitBuiltInParameter.FAMILY_TOP_LEVEL_PARAM - ); + var topLevel = _parameterValueExtractor.GetValueAsRevitLevel(target, RevitBuiltInParameter.FAMILY_TOP_LEVEL_PARAM); speckleColumn.topLevel = _levelConverter.Convert(topLevel.NotNull()); speckleColumn.baseOffset = _parameterValueExtractor.GetValueAsDouble( diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveConversionToSpeckle.cs index 5cf220c982..148da296e8 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveConversionToSpeckle.cs @@ -46,17 +46,17 @@ public ICurve Convert(IRevitCurve target) var ellipse = target.ToEllipse(); if (ellipse is not null) { - return _ellipseConverter.Convert(ellipse); + return _ellipseConverter.Convert(ellipse); } var nurbs = target.ToNurbSpline(); if (nurbs is not null) { - return _nurbsConverter.Convert(nurbs); + return _nurbsConverter.Convert(nurbs); } var hermite = target.ToHermiteSpline(); if (hermite is not null) { - return _hermiteConverter.Convert(hermite); + return _hermiteConverter.Convert(hermite); } throw new SpeckleConversionException($"Unsupported curve type {target.GetType()}"); diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/ReferencePointConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/ReferencePointConverter.cs index 75ede14395..d3d3e2384f 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/ReferencePointConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/ReferencePointConverter.cs @@ -41,7 +41,9 @@ public ReferencePointConverter( IRevitConversionSettings revitSettings, IRevitFilterFactory revitFilterFactory, IRevitTransformUtils transformUtils, - IRevitXYZUtils revitXyzUtils, IProxyMap proxyMap) + IRevitXYZUtils revitXyzUtils, + IProxyMap proxyMap + ) { _contextStack = contextStack; _revitSettings = revitSettings; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs index 805137ac39..b106fb0181 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs @@ -60,10 +60,7 @@ public override RevitCeiling Convert(IRevitCeiling target) // POC: our existing receive operation is checking the "slopeDirection" prop, // but it is never being set. We should be setting it - var level = _parameterValueExtractor.GetValueAsRevitLevel( - target, - RevitBuiltInParameter.LEVEL_PARAM - ); + var level = _parameterValueExtractor.GetValueAsRevitLevel(target, RevitBuiltInParameter.LEVEL_PARAM); speckleCeiling.level = _levelConverter.Convert(level.NotNull()); _parameterObjectAssigner.AssignParametersToBase(target, speckleCeiling); diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs index 874c9e9b5f..cd461f269d 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs @@ -62,10 +62,7 @@ public override SOBR.RevitFloor Convert(IRevitFloor target) speckleFloor.voids = profiles.Skip(1).ToList(); } - var level = _parameterValueExtractor.GetValueAsRevitLevel( - target, - RevitBuiltInParameter.LEVEL_PARAM - ); + var level = _parameterValueExtractor.GetValueAsRevitLevel(target, RevitBuiltInParameter.LEVEL_PARAM); speckleFloor.level = _levelConverter.Convert(level.NotNull()); speckleFloor.structural = _parameterValueExtractor.GetValueAsBool(target, RevitBuiltInParameter.FLOOR_PARAM_IS_STRUCTURAL) ?? false; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FootPrintRoofToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FootPrintRoofToSpeckleTopLevelConverter.cs index 9f9faa856c..15d89f984f 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FootPrintRoofToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FootPrintRoofToSpeckleTopLevelConverter.cs @@ -41,16 +41,10 @@ IRevitFilterFactory revitFilterFactory public override RevitFootprintRoof Convert(IRevitFootPrintRoof target) { - var baseLevel = _parameterValueExtractor.GetValueAsRevitLevel( - target, - RevitBuiltInParameter.ROOF_BASE_LEVEL_PARAM - ); + var baseLevel = _parameterValueExtractor.GetValueAsRevitLevel(target, RevitBuiltInParameter.ROOF_BASE_LEVEL_PARAM); // We don't currently validate the success of this TryGet, it is assumed some Roofs don't have a top-level. - var topLevel = _parameterValueExtractor.GetValueAsRevitLevel( - target, - RevitBuiltInParameter.ROOF_UPTO_LEVEL_PARAM - ); + var topLevel = _parameterValueExtractor.GetValueAsRevitLevel(target, RevitBuiltInParameter.ROOF_UPTO_LEVEL_PARAM); //POC: CNX-9403 can be null if the sides have different slopes. //We currently don't validate the success or failure of this TryGet as it's not necessary, but will be once we start the above ticket. diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs index fdfb0593ca..84aa5bd7a6 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs @@ -74,16 +74,10 @@ private void AssignSpecificParameters(IRevitWall target, RevitWall speckleWall) speckleWall.baseLine = _curveConverter.Convert(locationCurve.Curve); - var level = _parameterValueExtractor.GetValueAsRevitLevel( - target, - RevitBuiltInParameter.WALL_BASE_CONSTRAINT - ); + var level = _parameterValueExtractor.GetValueAsRevitLevel(target, RevitBuiltInParameter.WALL_BASE_CONSTRAINT); speckleWall.level = _levelConverter.Convert(level.NotNull()); - var topLevel = _parameterValueExtractor.GetValueAsRevitLevel( - target, - RevitBuiltInParameter.WALL_BASE_CONSTRAINT - ); + var topLevel = _parameterValueExtractor.GetValueAsRevitLevel(target, RevitBuiltInParameter.WALL_BASE_CONSTRAINT); speckleWall.topLevel = _levelConverter.Convert(topLevel.NotNull()); // POC : what to do if these parameters are unset (instead of assigning default) From 1ca2756cd137237b0c7ae1c99311f4a31df295b5 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Thu, 13 Jun 2024 11:20:33 +0100 Subject: [PATCH 10/25] add more proxies --- .../DependencyInjection/ProxyMap.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs index 5b961a0ccb..a8b662b32d 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs @@ -27,6 +27,11 @@ static ProxyMap() Add(x => new BasePointProxy(x)); Add(x => new WallProxy(x)); Add(x => new PanelProxy(x)); + Add(x => new FloorProxy(x)); + Add(x => new CeilingProxy(x)); + Add(x => new FootPrintRoofProxy(x)); + Add(x => new ModelLineProxy(x)); + Add(x => new RoofBaseProxy(x)); } private static void Add(Func f) From d5ef59caa346a73c801873f38f98cdcdabe23717 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Thu, 13 Jun 2024 11:22:49 +0100 Subject: [PATCH 11/25] better handling for wrapped types --- ...ckleConverter.cs => RootToSpeckleConverter.cs} | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) rename DUI3-DX/Sdk/Speckle.Converters.Common/{IRootToSpeckleConverter.cs => RootToSpeckleConverter.cs} (66%) diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common/IRootToSpeckleConverter.cs b/DUI3-DX/Sdk/Speckle.Converters.Common/RootToSpeckleConverter.cs similarity index 66% rename from DUI3-DX/Sdk/Speckle.Converters.Common/IRootToSpeckleConverter.cs rename to DUI3-DX/Sdk/Speckle.Converters.Common/RootToSpeckleConverter.cs index 83e3285f31..65ea7156a2 100644 --- a/DUI3-DX/Sdk/Speckle.Converters.Common/IRootToSpeckleConverter.cs +++ b/DUI3-DX/Sdk/Speckle.Converters.Common/RootToSpeckleConverter.cs @@ -20,21 +20,22 @@ public RootToSpeckleConverter(IFactory toSpeckle, I public Base Convert(object target) { - Type type = target.GetType(); - var wrapper = _proxyMap.WrapIfExists(type, target); - if (wrapper is not null) + Type revitType = target.GetType(); + var wrapper = _proxyMap.WrapIfExists(revitType, target); + if (wrapper == null) { - (type, target) = wrapper.Value; + throw new NotSupportedException($"No wrapper found for Revit type: {revitType.Name}"); } + var (wrappedType, wrappedObject) = wrapper.Value; try { - var objectConverter = _toSpeckle.ResolveInstance(type.Name); //poc: would be nice to have supertypes resolve + var objectConverter = _toSpeckle.ResolveInstance(wrappedType.Name); //poc: would be nice to have supertypes resolve if (objectConverter == null) { - throw new NotSupportedException($"No conversion found for {type.Name}"); + throw new NotSupportedException($"No conversion found for {wrappedType.Name}"); } - var convertedObject = objectConverter.Convert(target); + var convertedObject = objectConverter.Convert(wrappedObject); return convertedObject; } From 373a4da65e330f71c2befcf452c25c7367cc8d99 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Thu, 13 Jun 2024 11:30:10 +0100 Subject: [PATCH 12/25] fix the RevitContext --- .../Speckle.Connectors.Revit2023.csproj | 1 + .../Bindings/BasicConnectorBindingRevit.cs | 2 +- .../Bindings/RevitBaseBinding.cs | 2 +- .../Bindings/RevitSendBinding.cs | 2 +- .../Bindings/SelectionBinding.cs | 2 +- .../DependencyInjection/ProxyMap.cs | 1 + .../RevitConnectorModule.cs | 6 ++++ .../Helpers}/RevitContext.cs | 2 +- .../Helpers}/RevitConversionContextStack.cs | 2 +- .../HostApp/RevitDocumentStore.cs | 2 +- .../Plugin/RevitExternalApplication.cs | 1 - .../Plugin/RevitIdleManager.cs | 2 +- .../Plugin/RevitPlugin.cs | 3 +- .../Speckle.Connectors.RevitShared.projitems | 28 +++---------------- .../RevitConverterModule.cs | 4 --- 15 files changed, 21 insertions(+), 39 deletions(-) rename DUI3-DX/{Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection => Connectors/Revit/Speckle.Connectors.RevitShared/Helpers}/RevitContext.cs (85%) rename DUI3-DX/{Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection => Connectors/Revit/Speckle.Connectors.RevitShared/Helpers}/RevitConversionContextStack.cs (96%) diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.Revit2023/Speckle.Connectors.Revit2023.csproj b/DUI3-DX/Connectors/Revit/Speckle.Connectors.Revit2023/Speckle.Connectors.Revit2023.csproj index be91998c4f..893a9a4c12 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.Revit2023/Speckle.Connectors.Revit2023.csproj +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.Revit2023/Speckle.Connectors.Revit2023.csproj @@ -3,6 +3,7 @@ net48 x64 true + false diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/BasicConnectorBindingRevit.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/BasicConnectorBindingRevit.cs index 697f29a5bd..ff27f05fb4 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/BasicConnectorBindingRevit.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/BasicConnectorBindingRevit.cs @@ -6,8 +6,8 @@ using Speckle.Connectors.DUI.Models; using Speckle.Connectors.DUI.Models.Card; using Speckle.Connectors.Revit.Plugin; +using Speckle.Connectors.RevitShared.Helpers; using Speckle.Connectors.Utils; -using Speckle.Converters.Revit2023.DependencyInjection; using Speckle.Core.Logging; namespace Speckle.Connectors.DUI.Bindings; diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitBaseBinding.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitBaseBinding.cs index b8fdd6424b..7e1e0afdec 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitBaseBinding.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitBaseBinding.cs @@ -1,7 +1,7 @@ using Speckle.Connectors.DUI.Bindings; using Speckle.Connectors.DUI.Bridge; using Speckle.Connectors.DUI.Models; -using Speckle.Converters.Revit2023.DependencyInjection; +using Speckle.Connectors.RevitShared.Helpers; namespace Speckle.Connectors.Revit.Bindings; diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitSendBinding.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitSendBinding.cs index fd7bc3c8e0..0c8ea57338 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitSendBinding.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitSendBinding.cs @@ -9,9 +9,9 @@ using Speckle.Autofac.DependencyInjection; using Speckle.Connectors.DUI.Exceptions; using Speckle.Connectors.DUI.Models; +using Speckle.Connectors.RevitShared.Helpers; using Speckle.Connectors.Utils.Caching; using Speckle.Connectors.Utils.Operations; -using Speckle.Converters.Revit2023.DependencyInjection; namespace Speckle.Connectors.Revit.Bindings; diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/SelectionBinding.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/SelectionBinding.cs index d7a4a1fc8b..11b7e8e864 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/SelectionBinding.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/SelectionBinding.cs @@ -2,8 +2,8 @@ using Speckle.Connectors.DUI.Bridge; using Speckle.Connectors.DUI.Models; using Speckle.Connectors.Revit.Plugin; +using Speckle.Connectors.RevitShared.Helpers; using Speckle.Converters.Common; -using Speckle.Converters.Revit2023.DependencyInjection; namespace Speckle.Connectors.Revit.Bindings; diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs index a8b662b32d..a3b00bf48a 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs @@ -12,6 +12,7 @@ public class ProxyMap : IProxyMap private static readonly ConcurrentDictionary s_reverseMaps = new(); private static readonly ConcurrentDictionary> s_proxyFactory = new(); + [SuppressMessage("Maintainability", "CA1506:Avoid excessive class coupling")] static ProxyMap() { Add(x => new ElementProxy(x)); diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/RevitConnectorModule.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/RevitConnectorModule.cs index bc2e05a284..c5367554e6 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/RevitConnectorModule.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/RevitConnectorModule.cs @@ -11,10 +11,12 @@ using Speckle.Connectors.Revit.Operations.Send; using Speckle.Connectors.Revit.Plugin; using Speckle.Connectors.Revit2023.Converters; +using Speckle.Connectors.RevitShared.Helpers; using Speckle.Connectors.Utils; using Speckle.Connectors.Utils.Builders; using Speckle.Connectors.Utils.Caching; using Speckle.Connectors.Utils.Operations; +using Speckle.Converters.Common; using Speckle.Revit.Interfaces; namespace Speckle.Connectors.Revit.DependencyInjection; @@ -27,6 +29,10 @@ public void Load(SpeckleContainerBuilder builder) builder.AddAutofac(); builder.AddConnectorUtils(); builder.AddDUI(); + builder.AddSingleton(new RevitContext()); + + // POC: the concrete type can come out if we remove all the reference to it + builder.AddScoped, RevitConversionContextStack>(); //builder.AddDUIView(); builder.AddSingletonInstance(); diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitContext.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Helpers/RevitContext.cs similarity index 85% rename from DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitContext.cs rename to DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Helpers/RevitContext.cs index c6f90fadd0..3148acc5dc 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitContext.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Helpers/RevitContext.cs @@ -1,6 +1,6 @@ using Autodesk.Revit.UI; -namespace Speckle.Converters.Revit2023.DependencyInjection; +namespace Speckle.Connectors.RevitShared.Helpers; public class RevitContext { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConversionContextStack.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Helpers/RevitConversionContextStack.cs similarity index 96% rename from DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConversionContextStack.cs rename to DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Helpers/RevitConversionContextStack.cs index 42bfb48aeb..d5461e7f60 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConversionContextStack.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Helpers/RevitConversionContextStack.cs @@ -3,7 +3,7 @@ using Speckle.Revit.Api; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.DependencyInjection; +namespace Speckle.Connectors.RevitShared.Helpers; [System.Diagnostics.CodeAnalysis.SuppressMessage( "Naming", diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/HostApp/RevitDocumentStore.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/HostApp/RevitDocumentStore.cs index 478c46b1b4..1278431790 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/HostApp/RevitDocumentStore.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/HostApp/RevitDocumentStore.cs @@ -6,8 +6,8 @@ using Revit.Async; using Speckle.Connectors.DUI.Models; using Speckle.Connectors.Revit.Plugin; +using Speckle.Connectors.RevitShared.Helpers; using Speckle.Connectors.Utils; -using Speckle.Converters.Revit2023.DependencyInjection; using Speckle.Core.Logging; using Speckle.Newtonsoft.Json; diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitExternalApplication.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitExternalApplication.cs index c84c839054..491a5480e4 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitExternalApplication.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitExternalApplication.cs @@ -1,6 +1,5 @@ using Autodesk.Revit.UI; using Speckle.Autofac.DependencyInjection; -using System.IO; using System.Reflection; using Speckle.Autofac; using Speckle.Connectors.Utils; diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitIdleManager.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitIdleManager.cs index facf64131b..8456ded287 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitIdleManager.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitIdleManager.cs @@ -1,7 +1,7 @@ using System.Collections.Concurrent; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Events; -using Speckle.Converters.Revit2023.DependencyInjection; +using Speckle.Connectors.RevitShared.Helpers; namespace Speckle.Connectors.Revit.Plugin; diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitPlugin.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitPlugin.cs index e38d4cc161..8ed0d5ec51 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitPlugin.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitPlugin.cs @@ -9,8 +9,7 @@ using System.Reflection; using System.Windows.Media.Imaging; using System.Windows.Media; -using System.IO; -using Speckle.Converters.Revit2023.DependencyInjection; +using Speckle.Connectors.RevitShared.Helpers; namespace Speckle.Connectors.Revit.Plugin; diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Speckle.Connectors.RevitShared.projitems b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Speckle.Connectors.RevitShared.projitems index a17b3594c9..906267a41b 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Speckle.Connectors.RevitShared.projitems +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Speckle.Connectors.RevitShared.projitems @@ -16,30 +16,7 @@ - - - - - - - - - - - - - - - - CefSharpPanel.xaml - - - - - - - - + @@ -47,4 +24,7 @@ MSBuild:Compile + + + \ No newline at end of file diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs index e8bec81475..c51626a408 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs @@ -14,14 +14,10 @@ public class RevitConverterModule : ISpeckleModule public void Load(SpeckleContainerBuilder builder) { builder.AddConverterCommon(); - builder.AddSingleton(new RevitContext()); // POC: do we need ToSpeckleScalingService as is, do we need to interface it out? builder.AddScoped(); - // POC: the concrete type can come out if we remove all the reference to it - builder.AddScoped, RevitConversionContextStack>(); - builder.AddScoped(); builder.AddScoped(); From daaac4b41459463e12176f9caf8584eae1679dae Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Thu, 13 Jun 2024 11:38:51 +0100 Subject: [PATCH 13/25] inject interfaces --- .../Helpers/SlopeArrowExtractor.cs | 4 ++-- .../RevitRootToHostConverter.cs | 4 ++-- .../ToSpeckle/CeilingTopLevelConverterToSpeckle.cs | 12 ++++++------ .../TopographyTopLevelConverterToSpeckle.cs | 8 ++++---- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/SlopeArrowExtractor.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/SlopeArrowExtractor.cs index 114ecc8fbd..3394c57b8b 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/SlopeArrowExtractor.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/SlopeArrowExtractor.cs @@ -9,12 +9,12 @@ namespace Speckle.Converters.RevitShared.Helpers; public class SlopeArrowExtractor : ISlopeArrowExtractor { private readonly ITypedConverter _pointConverter; - private readonly ParameterValueExtractor _parameterValueExtractor; + private readonly IParameterValueExtractor _parameterValueExtractor; private readonly IRevitFilterFactory _revitFilterFactory; public SlopeArrowExtractor( ITypedConverter pointConverter, - ParameterValueExtractor parameterValueExtractor, + IParameterValueExtractor parameterValueExtractor, IRevitFilterFactory revitFilterFactory ) { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitRootToHostConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitRootToHostConverter.cs index 46964b9074..add05d6402 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitRootToHostConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitRootToHostConverter.cs @@ -10,11 +10,11 @@ namespace Speckle.Converters.RevitShared; public class RevitRootToHostConverter : IRootToSpeckleConverter { private readonly IConverterResolver _toSpeckle; - private readonly ParameterValueExtractor _parameterValueExtractor; + private readonly IParameterValueExtractor _parameterValueExtractor; public RevitRootToHostConverter( IConverterResolver toSpeckle, - ParameterValueExtractor parameterValueExtractor + IParameterValueExtractor parameterValueExtractor ) { _toSpeckle = toSpeckle; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs index b106fb0181..0083460577 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs @@ -15,18 +15,18 @@ internal sealed class CeilingTopLevelConverterToSpeckle { private readonly ITypedConverter> _curveArrArrayConverter; private readonly ITypedConverter _levelConverter; - private readonly ParameterValueExtractor _parameterValueExtractor; - private readonly ParameterObjectAssigner _parameterObjectAssigner; - private readonly DisplayValueExtractor _displayValueExtractor; + private readonly IParameterValueExtractor _parameterValueExtractor; + private readonly IParameterObjectAssigner _parameterObjectAssigner; + private readonly IDisplayValueExtractor _displayValueExtractor; //private readonly HostedElementConversionToSpeckle _hostedElementConverter; public CeilingTopLevelConverterToSpeckle( ITypedConverter> curveArrArrayConverter, ITypedConverter levelConverter, - ParameterValueExtractor parameterValueExtractor, - ParameterObjectAssigner parameterObjectAssigner, - DisplayValueExtractor displayValueExtractor + IParameterValueExtractor parameterValueExtractor, + IParameterObjectAssigner parameterObjectAssigner, + IDisplayValueExtractor displayValueExtractor ) { _curveArrArrayConverter = curveArrArrayConverter; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/TopographyTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/TopographyTopLevelConverterToSpeckle.cs index eb3d11afb5..5ed057d018 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/TopographyTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/TopographyTopLevelConverterToSpeckle.cs @@ -11,12 +11,12 @@ namespace Speckle.Converters.RevitShared.ToSpeckle; public class TopographyTopLevelConverterToSpeckle : BaseTopLevelConverterToSpeckle { - private readonly DisplayValueExtractor _displayValueExtractor; - private readonly ParameterObjectAssigner _parameterObjectAssigner; + private readonly IDisplayValueExtractor _displayValueExtractor; + private readonly IParameterObjectAssigner _parameterObjectAssigner; public TopographyTopLevelConverterToSpeckle( - DisplayValueExtractor displayValueExtractor, - ParameterObjectAssigner parameterObjectAssigner + IDisplayValueExtractor displayValueExtractor, + IParameterObjectAssigner parameterObjectAssigner ) { _displayValueExtractor = displayValueExtractor; From 9438634b0c385083b1df9947e5225130371a6ca3 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Thu, 13 Jun 2024 11:47:50 +0100 Subject: [PATCH 14/25] convert to new way of casting --- .../ToSpeckle/FloorTopLevelConverterToSpeckle.cs | 7 ++++--- .../ToSpeckle/WallTopLevelConverterToSpeckle.cs | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs index cd461f269d..3fd8578439 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs @@ -43,10 +43,10 @@ public override SOBR.RevitFloor Convert(IRevitFloor target) { SOBR.RevitFloor speckleFloor = new(); - var sketch = (IRevitSketch)target.Document.GetElement(target.SketchId); + var sketch = target.Document.GetElement(target.SketchId).ToSketch().NotNull(); List profiles = _curveArrArrayConverter.Convert(sketch.Profile); - IRevitElementType type = (IRevitElementType)target.Document.GetElement(target.GetTypeId()); + IRevitElementType type = target.Document.GetElement(target.GetTypeId()).ToType().NotNull(); speckleFloor.family = type.FamilyName; speckleFloor.type = type.Name; @@ -86,7 +86,8 @@ public override SOBR.RevitFloor Convert(IRevitFloor target) private void TryAssignSlopeFromSlopeArrow(IRevitFloor target, SOBR.RevitFloor speckleFloor, double? slopeParam) { - if (_slopeArrowExtractor.GetSlopeArrow(target) is not IRevitModelLine slopeArrow) + var slopeArrow = _slopeArrowExtractor.GetSlopeArrow(target); + if (slopeArrow is null) { return; } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs index 84aa5bd7a6..aa80501efe 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs @@ -107,7 +107,8 @@ out double? topOffset private List GetChildElements(IRevitWall target) { List wallChildren = new(); - if (target.CurtainGrid is IRevitCurtainGrid grid) + var grid = target.CurtainGrid; + if (grid is not null) { wallChildren.AddRange(ConvertElements(grid.GetMullionIds())); wallChildren.AddRange(ConvertElements(grid.GetPanelIds())); @@ -161,7 +162,7 @@ private void AssignHostedElements(SOBR.RevitWall speckleWall, List hostedO private void AssignVoids(IRevitWall target, SOBR.RevitWall speckleWall) { - IRevitCurveArrArray? profile = ((IRevitSketch)target.Document.GetElement(target.SketchId))?.Profile; + IRevitCurveArrArray? profile = target.Document.GetElement(target.SketchId).ToSketch()?.Profile; if (profile is null) { return; From c9f4035e2ca57e6cd62c0e23cc610b4bdf377530 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Thu, 13 Jun 2024 12:01:52 +0100 Subject: [PATCH 15/25] update and rejigger dependencies --- .../RevitConnectorModule.cs | 3 +- .../RevitConverterModule.cs | 3 -- .../Helpers/ParameterValueExtractor.cs | 32 +++++++++---------- .../Raw/ParameterConversionToSpeckle.cs | 2 +- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/RevitConnectorModule.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/RevitConnectorModule.cs index c5367554e6..83e0a6af57 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/RevitConnectorModule.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/RevitConnectorModule.cs @@ -17,6 +17,7 @@ using Speckle.Connectors.Utils.Caching; using Speckle.Connectors.Utils.Operations; using Speckle.Converters.Common; +using Speckle.Revit.Api; using Speckle.Revit.Interfaces; namespace Speckle.Connectors.Revit.DependencyInjection; @@ -33,7 +34,7 @@ public void Load(SpeckleContainerBuilder builder) // POC: the concrete type can come out if we remove all the reference to it builder.AddScoped, RevitConversionContextStack>(); - //builder.AddDUIView(); + builder.ScanAssemblyOfType(); builder.AddSingletonInstance(); diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs index c51626a408..17897c69fb 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs @@ -4,7 +4,6 @@ using Speckle.Converters.Revit2023.ToSpeckle; using Speckle.Converters.RevitShared.Helpers; using Speckle.Converters.RevitShared.Services; -using Speckle.Revit.Api; using Speckle.Revit.Interfaces; namespace Speckle.Converters.Revit2023.DependencyInjection; @@ -30,7 +29,5 @@ public void Load(SpeckleContainerBuilder builder) builder.AddScoped(); builder.AddScoped(); //builder.AddScoped(); - - builder.ScanAssemblyOfType(); } } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs index 47e2bb905f..e678b5f0be 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs @@ -31,11 +31,11 @@ public ParameterValueExtractor(IScalingServiceToSpeckle scalingService) return parameter.StorageType switch { - IRevitStorageType.Double => GetValueAsDouble(parameter), - IRevitStorageType.Integer => GetValueAsInt(parameter), - IRevitStorageType.String => GetValueAsString(parameter), - IRevitStorageType.ElementId => GetValueAsElementId(parameter)?.ToString(), - IRevitStorageType.None + RevitStorageType.Double => GetValueAsDouble(parameter), + RevitStorageType.Integer => GetValueAsInt(parameter), + RevitStorageType.String => GetValueAsString(parameter), + RevitStorageType.ElementId => GetValueAsElementId(parameter)?.ToString(), + RevitStorageType.None or _ => throw new SpeckleConversionException($"Unsupported parameter storage type {parameter.StorageType}") }; @@ -60,7 +60,7 @@ public bool TryGetValueAsDouble( var number = GetValueGeneric( element, builtInParameter, - IRevitStorageType.Double, + RevitStorageType.Double, (parameter) => _scalingService.Scale(parameter.AsDouble(), parameter.GetUnitTypeId()) ); if (number.HasValue) @@ -77,7 +77,7 @@ public bool TryGetValueAsDouble( { return GetValueGeneric( parameter, - IRevitStorageType.Double, + RevitStorageType.Double, (parameter) => _scalingService.Scale(parameter.AsDouble(), parameter.GetUnitTypeId()) ); } @@ -87,7 +87,7 @@ public int GetValueAsInt(IRevitElement element, RevitBuiltInParameter builtInPar return GetValueGeneric( element, builtInParameter, - IRevitStorageType.Integer, + RevitStorageType.Integer, (parameter) => parameter.AsInteger() ) ?? throw new SpeckleConversionException( @@ -97,7 +97,7 @@ public int GetValueAsInt(IRevitElement element, RevitBuiltInParameter builtInPar private int? GetValueAsInt(IRevitParameter parameter) { - return GetValueGeneric(parameter, IRevitStorageType.Integer, (parameter) => parameter.AsInteger()); + return GetValueGeneric(parameter, RevitStorageType.Integer, (parameter) => parameter.AsInteger()); } public bool? GetValueAsBool(IRevitElement element, RevitBuiltInParameter builtInParameter) @@ -105,7 +105,7 @@ public int GetValueAsInt(IRevitElement element, RevitBuiltInParameter builtInPar var intVal = GetValueGeneric( element, builtInParameter, - IRevitStorageType.Integer, + RevitStorageType.Integer, (parameter) => parameter.AsInteger() ); @@ -114,12 +114,12 @@ public int GetValueAsInt(IRevitElement element, RevitBuiltInParameter builtInPar public string? GetValueAsString(IRevitElement element, RevitBuiltInParameter builtInParameter) { - return GetValueGeneric(element, builtInParameter, IRevitStorageType.String, (parameter) => parameter.AsString()); + return GetValueGeneric(element, builtInParameter, RevitStorageType.String, (parameter) => parameter.AsString()); } private string? GetValueAsString(IRevitParameter parameter) { - return GetValueGeneric(parameter, IRevitStorageType.String, (parameter) => parameter.AsString()); + return GetValueGeneric(parameter, RevitStorageType.String, (parameter) => parameter.AsString()); } public IRevitElementId GetValueAsElementId(IRevitElement element, RevitBuiltInParameter builtInParameter) @@ -140,7 +140,7 @@ public bool TryGetValueAsElementId( ) { if ( - GetValueGeneric(element, builtInParameter, IRevitStorageType.ElementId, (parameter) => parameter.AsElementId()) + GetValueGeneric(element, builtInParameter, RevitStorageType.ElementId, (parameter) => parameter.AsElementId()) is IRevitElementId elementIdNotNull ) { @@ -154,7 +154,7 @@ is IRevitElementId elementIdNotNull public IRevitElementId? GetValueAsElementId(IRevitParameter parameter) { - return GetValueGeneric(parameter, IRevitStorageType.ElementId, (parameter) => parameter.AsElementId()); + return GetValueGeneric(parameter, RevitStorageType.ElementId, (parameter) => parameter.AsElementId()); } public IRevitLevel? GetValueAsRevitLevel(IRevitElement element, RevitBuiltInParameter builtInParameter) @@ -171,7 +171,7 @@ is IRevitElementId elementIdNotNull private TResult? GetValueGeneric( IRevitElement element, RevitBuiltInParameter builtInParameter, - IRevitStorageType expectedStorageType, + RevitStorageType expectedStorageType, Func getParamValue ) { @@ -189,7 +189,7 @@ Func getParamValue private TResult? GetValueGeneric( IRevitParameter parameter, - IRevitStorageType expectedStorageType, + RevitStorageType expectedStorageType, Func getParamValue ) { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ParameterConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ParameterConversionToSpeckle.cs index 3aa9e156fb..2054eba3e5 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ParameterConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ParameterConversionToSpeckle.cs @@ -23,7 +23,7 @@ public SOBR.Parameter Convert(IRevitParameter target) { string internalName = target.GetInternalName(); IRevitForgeTypeId? unitTypeId = null; - if (target.StorageType is IRevitStorageType.Double) + if (target.StorageType is RevitStorageType.Double) { // according to the api documentation, this method will throw if the storage type is not a VALUE type // however, I've found that it will still throw if StorageType == StorageType.Integer From d426b90a5688cbdbc146ab741734b9085d5f3351 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Thu, 13 Jun 2024 12:15:15 +0100 Subject: [PATCH 16/25] handle null elements --- .../Helpers/DisplayValueExtractor.cs | 4 ++-- .../Helpers/ParameterObjectAssigner.cs | 2 +- .../Helpers/ParameterValueExtractor.cs | 4 ++-- .../Helpers/SlopeArrowExtractor.cs | 4 ++-- .../Raw/BeamConversionToSpeckle.cs | 4 ++-- .../Raw/ColumnConversionToSpeckle.cs | 4 ++-- .../Raw/Geometry/MeshConversionToSpeckle.cs | 2 +- .../ToSpeckle/CeilingTopLevelConverterToSpeckle.cs | 4 ++-- .../ToSpeckle/ElementTopLevelConverterToSpeckle.cs | 2 +- .../ToSpeckle/ExtrusionRoofToSpeckleTopLevelConverter.cs | 2 +- .../ToSpeckle/FloorTopLevelConverterToSpeckle.cs | 4 ++-- .../ToSpeckle/FootPrintRoofToSpeckleTopLevelConverter.cs | 2 +- .../ToSpeckle/HostedElementConversionToSpeckle.cs | 2 +- .../ToSpeckle/RoofBaseToSpeckleTopLevelTopLevelConverter.cs | 2 +- .../ToSpeckle/WallTopLevelConverterToSpeckle.cs | 4 ++-- 15 files changed, 23 insertions(+), 23 deletions(-) diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/DisplayValueExtractor.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/DisplayValueExtractor.cs index 28163ace7d..377e12dd1f 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/DisplayValueExtractor.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/DisplayValueExtractor.cs @@ -43,7 +43,7 @@ IRevitSolidUtils revitSolidUtils { foreach (var id in g.GetMemberIds()) { - var groupMeshes = GetDisplayValue(element.Document.GetElement(id), options); + var groupMeshes = GetDisplayValue(element.Document.GetElement(id).NotNull(), options); displayMeshes.AddRange(groupMeshes); } return displayMeshes; @@ -287,7 +287,7 @@ private bool IsSkippableGraphicStyle(IRevitElementId id, IRevitDocument doc) { if (!_graphicStyleCache.ContainsKey(id.ToString())) { - _graphicStyleCache.Add(id.ToString(), doc.GetElement(id).ToGraphicsStyle().NotNull()); + _graphicStyleCache.Add(id.ToString(), doc.GetElement(id).NotNull().ToGraphicsStyle().NotNull()); } var graphicStyle = _graphicStyleCache[id.ToString()]; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterObjectAssigner.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterObjectAssigner.cs index 746af2eddb..5b543a70f2 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterObjectAssigner.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterObjectAssigner.cs @@ -38,7 +38,7 @@ public void AssignParametersToBase(IRevitElement target, Base @base) // POC: Some elements can have an invalid element type ID, I don't think we want to continue here. if (elementId != _revitElementIdUtils.InvalidElementId && target is not SOBE.Level) //ignore type props of levels..! { - var elementType = target.Document.GetElement(elementId); + var elementType = target.Document.GetElement(elementId).NotNull(); // I don't think we should be adding the type parameters to the object like this var typeParameters = _parameterValueExtractor.GetAllRemainingParams(elementType); AssignSpeckleParamToBaseObject(typeParameters, paramBase, true); diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs index e678b5f0be..2b4cabf2e1 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs @@ -164,8 +164,8 @@ is IRevitElementId elementIdNotNull throw new SpeckleConversionException(); } - IRevitElement paramElement = element.Document.GetElement(elementId); - return paramElement.ToLevel(); + var paramElement = element.Document.GetElement(elementId); + return paramElement?.ToLevel(); } private TResult? GetValueGeneric( diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/SlopeArrowExtractor.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/SlopeArrowExtractor.cs index 3394c57b8b..f1db970430 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/SlopeArrowExtractor.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/SlopeArrowExtractor.cs @@ -28,7 +28,7 @@ IRevitFilterFactory revitFilterFactory IList? elementIds = null; if (element is IRevitFloor floor) { - elementIds = (floor.Document.GetElement(floor.SketchId).ToSketch().NotNull()).GetAllElements(); + elementIds = (floor.Document.GetElement(floor.SketchId).NotNull().ToSketch().NotNull()).GetAllElements(); } if (elementIds == null) @@ -39,7 +39,7 @@ IRevitFilterFactory revitFilterFactory foreach (var elementId in elementIds) { - var line = element.Document.GetElement(elementId).ToModelLine(); + var line = element.Document.GetElement(elementId)?.ToModelLine(); if (line is null) { continue; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BeamConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BeamConversionToSpeckle.cs index 27b7ed1961..e64a824173 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BeamConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BeamConversionToSpeckle.cs @@ -44,13 +44,13 @@ public SOBR.RevitBeam Convert(IRevitFamilyInstance target) ); } - var symbol = target.Document.GetElement(target.GetTypeId()).ToFamilySymbol().NotNull(); + var symbol = target.Document.GetElement(target.GetTypeId()).NotNull().ToFamilySymbol().NotNull(); SOBR.RevitBeam speckleBeam = new() { family = symbol.FamilyName, - type = target.Document.GetElement(target.GetTypeId()).Name, + type = target.Document.GetElement(target.GetTypeId()).NotNull().Name, baseLine = baseCurve }; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs index 149b382834..7f1d2c96d3 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs @@ -37,10 +37,10 @@ IParameterObjectAssigner parameterObjectAssigner public SOBR.RevitColumn Convert(IRevitFamilyInstance target) { - var symbol = target.Document.GetElement(target.GetTypeId()).ToFamilySymbol().NotNull(); + var symbol = target.Document.GetElement(target.GetTypeId()).NotNull().ToFamilySymbol().NotNull(); SOBR.RevitColumn speckleColumn = - new() { family = symbol.FamilyName, type = target.Document.GetElement(target.GetTypeId()).Name }; + new() { family = symbol.FamilyName, type = target.Document.GetElement(target.GetTypeId()).NotNull().Name }; var level = _parameterValueExtractor.GetValueAsRevitLevel(target, RevitBuiltInParameter.FAMILY_BASE_LEVEL_PARAM); speckleColumn.level = _levelConverter.Convert(level.NotNull()); diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/MeshConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/MeshConversionToSpeckle.cs index 8321d14ca2..80529d4ba6 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/MeshConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/MeshConversionToSpeckle.cs @@ -30,7 +30,7 @@ public SOG.Mesh Convert(IRevitMesh target) List faces = GetSpeckleMeshFaceData(target); var element = doc.GetElement(target.MaterialElementId); - var revitMaterial = element.ToMaterial(); + var revitMaterial = element?.ToMaterial(); RenderMaterial? speckleMaterial = null; if (revitMaterial is not null) { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs index 0083460577..41e64c2488 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs @@ -38,12 +38,12 @@ IDisplayValueExtractor displayValueExtractor public override RevitCeiling Convert(IRevitCeiling target) { - var sketch = target.Document.GetElement(target.SketchId).ToSketch().NotNull(); + var sketch = target.Document.GetElement(target.SketchId).NotNull().ToSketch().NotNull(); List profiles = _curveArrArrayConverter.Convert(sketch.Profile); var speckleCeiling = new RevitCeiling(); - var elementType = target.Document.GetElement(target.GetTypeId()).ToType().NotNull(); + var elementType = target.Document.GetElement(target.GetTypeId()).NotNull().ToType().NotNull(); speckleCeiling.type = elementType.Name; speckleCeiling.family = elementType.FamilyName; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ElementTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ElementTopLevelConverterToSpeckle.cs index 4595f9b2d1..a9a5bb2c7a 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ElementTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ElementTopLevelConverterToSpeckle.cs @@ -20,7 +20,7 @@ public override SOBR.RevitElement Convert(IRevitElement target) SOBR.RevitElement speckleElement = new(); var element = target.Document.GetElement(target.GetTypeId()); - var symbol = element.ToFamilySymbol(); + var symbol = element?.ToFamilySymbol(); if (symbol is not null) { speckleElement.family = symbol.FamilyName; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ExtrusionRoofToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ExtrusionRoofToSpeckleTopLevelConverter.cs index b0e2b89422..32090152fc 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ExtrusionRoofToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ExtrusionRoofToSpeckleTopLevelConverter.cs @@ -60,7 +60,7 @@ public override RevitExtrusionRoof Convert(IRevitExtrusionRoof target) speckleExtrusionRoof.level = _levelConverter.Convert(level.NotNull()); speckleExtrusionRoof.outline = _modelCurveArrayConverter.Convert(target.GetProfile()); - var elementType = (IRevitElementType)target.Document.GetElement(target.GetTypeId()); + var elementType = target.Document.GetElement(target.GetTypeId()).NotNull().ToType().NotNull(); speckleExtrusionRoof.type = elementType.Name; speckleExtrusionRoof.family = elementType.FamilyName; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs index 3fd8578439..004433ecbd 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs @@ -43,10 +43,10 @@ public override SOBR.RevitFloor Convert(IRevitFloor target) { SOBR.RevitFloor speckleFloor = new(); - var sketch = target.Document.GetElement(target.SketchId).ToSketch().NotNull(); + var sketch = target.Document.GetElement(target.SketchId).NotNull().ToSketch().NotNull(); List profiles = _curveArrArrayConverter.Convert(sketch.Profile); - IRevitElementType type = target.Document.GetElement(target.GetTypeId()).ToType().NotNull(); + IRevitElementType type = target.Document.GetElement(target.GetTypeId()).NotNull().ToType().NotNull(); speckleFloor.family = type.FamilyName; speckleFloor.type = type.Name; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FootPrintRoofToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FootPrintRoofToSpeckleTopLevelConverter.cs index 15d89f984f..f0ad7efabe 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FootPrintRoofToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FootPrintRoofToSpeckleTopLevelConverter.cs @@ -66,7 +66,7 @@ public override RevitFootprintRoof Convert(IRevitFootPrintRoof target) speckleFootprintRoof.outline = profiles.FirstOrDefault(); speckleFootprintRoof.voids = profiles.Skip(1).ToList(); - var elementType = target.Document.GetElement(target.GetTypeId()).ToType().NotNull(); + var elementType = target.Document.GetElement(target.GetTypeId()).NotNull().ToType().NotNull(); speckleFootprintRoof.type = elementType.Name; speckleFootprintRoof.family = elementType.FamilyName; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/HostedElementConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/HostedElementConversionToSpeckle.cs index 13c804d77b..81dae6b6a5 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/HostedElementConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/HostedElementConversionToSpeckle.cs @@ -28,7 +28,7 @@ public IEnumerable ConvertHostedElements(IEnumerable host { foreach (var elemId in hostedElementIds) { - IRevitElement element = _contextStack.Current.Document.GetElement(elemId); + IRevitElement element = _contextStack.Current.Document.GetElement(elemId).NotNull(); Base @base; try diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/RoofBaseToSpeckleTopLevelTopLevelConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/RoofBaseToSpeckleTopLevelTopLevelConverter.cs index c7853c9939..aee970c621 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/RoofBaseToSpeckleTopLevelTopLevelConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/RoofBaseToSpeckleTopLevelTopLevelConverter.cs @@ -31,7 +31,7 @@ IRevitFilterFactory revitFilterFactory public override RevitRoof Convert(IRevitRoofBase target) { RevitRoof revitRoof = new(); - var elementType = target.Document.GetElement(target.GetTypeId()).ToType().NotNull(); + var elementType = target.Document.GetElement(target.GetTypeId()).NotNull().ToType().NotNull(); revitRoof.type = elementType.Name; revitRoof.family = elementType.FamilyName; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs index aa80501efe..129817f4a1 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs @@ -125,7 +125,7 @@ private IEnumerable ConvertElements(IEnumerable elementId { foreach (IRevitElementId elementId in elementIds) { - yield return _converter.Convert(_contextStack.Current.Document.GetElement(elementId)); + yield return _converter.Convert(_contextStack.Current.Document.GetElement(elementId).NotNull()); } } @@ -162,7 +162,7 @@ private void AssignHostedElements(SOBR.RevitWall speckleWall, List hostedO private void AssignVoids(IRevitWall target, SOBR.RevitWall speckleWall) { - IRevitCurveArrArray? profile = target.Document.GetElement(target.SketchId).ToSketch()?.Profile; + IRevitCurveArrArray? profile = target.Document.GetElement(target.SketchId)?.ToSketch()?.Profile; if (profile is null) { return; From 09d1a43cc308267c8c3c533b181cd5de31bc0aa5 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Thu, 13 Jun 2024 13:37:46 +0100 Subject: [PATCH 17/25] proxy map is also proxy aware --- .../DependencyInjection/ProxyMap.cs | 71 +++++++++++-------- 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs index a3b00bf48a..f6c378630e 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs @@ -8,57 +8,70 @@ namespace Speckle.Connectors.Revit2023.Converters; [SuppressMessage("Performance", "CA1810:Initialize reference type static fields inline")] public class ProxyMap : IProxyMap { - private static readonly ConcurrentDictionary s_typeMaps = new(); - private static readonly ConcurrentDictionary s_reverseMaps = new(); + private static readonly ConcurrentDictionary s_revitToInterfaceMap = new(); + private static readonly ConcurrentDictionary s_proxyToInterfaceMap = new(); + private static readonly ConcurrentDictionary s_interfaceToRevit = new(); private static readonly ConcurrentDictionary> s_proxyFactory = new(); [SuppressMessage("Maintainability", "CA1506:Avoid excessive class coupling")] static ProxyMap() { - Add(x => new ElementProxy(x)); - Add(x => new FamilyInstanceProxy(x)); - Add(x => new CurveProxy(x)); - Add(x => new BoundarySegmentProxy(x)); - Add(x => new LevelProxy(x)); - Add(x => new LocationProxy(x)); - Add(x => new MaterialProxy(x)); - Add(x => new ModelCurveArrayProxy(x)); - Add(x => new ModelCurveArrArrayProxy(x)); - Add(x => new ParameterProxy(x)); - Add(x => new BasePointProxy(x)); - Add(x => new WallProxy(x)); - Add(x => new PanelProxy(x)); - Add(x => new FloorProxy(x)); - Add(x => new CeilingProxy(x)); - Add(x => new FootPrintRoofProxy(x)); - Add(x => new ModelLineProxy(x)); - Add(x => new RoofBaseProxy(x)); + Add(x => new ElementProxy(x)); + Add(x => new FamilyInstanceProxy(x)); + Add(x => new CurveProxy(x)); + Add(x => new BoundarySegmentProxy(x)); + Add(x => new LevelProxy(x)); + Add(x => new LocationProxy(x)); + Add(x => new MaterialProxy(x)); + Add(x => new ModelCurveArrayProxy(x)); + Add(x => new ModelCurveArrArrayProxy(x)); + Add(x => new ParameterProxy(x)); + Add(x => new BasePointProxy(x)); + Add(x => new WallProxy(x)); + Add(x => new PanelProxy(x)); + Add(x => new FloorProxy(x)); + Add(x => new CeilingProxy(x)); + Add(x => new FootPrintRoofProxy(x)); + Add(x => new ModelLineProxy(x)); + Add(x => new RoofBaseProxy(x)); } - private static void Add(Func f) + private static void Add(Func f) where T : class - where TProxy : notnull + where TInterface : notnull + where TProxy : TInterface { - s_typeMaps.TryAdd(typeof(T), typeof(TProxy)); - s_proxyFactory.TryAdd(typeof(TProxy), w => f((T)w)); - s_reverseMaps.TryAdd(typeof(TProxy), typeof(T)); + s_revitToInterfaceMap.TryAdd(typeof(T), typeof(TInterface)); + s_proxyToInterfaceMap.TryAdd(typeof(TProxy), typeof(TInterface)); + s_proxyFactory.TryAdd(typeof(TInterface), w => f((T)w)); + s_interfaceToRevit.TryAdd(typeof(TInterface), typeof(T)); } - public Type? GetMappedType(Type type) + public Type? GetMappedTypeFromHostType(Type type) { - if (s_typeMaps.TryGetValue(type, out var t)) + if (s_revitToInterfaceMap.TryGetValue(type, out var t)) { return t; } + return null; + } + public Type? GetMappedTypeFromProxyType(Type type) + { + if (s_proxyToInterfaceMap.TryGetValue(type, out var t)) + { + return t; + } + return null; } - public Type? UnmapType(Type type) + public Type? GetHostTypeFromMappedType(Type type) { - if (s_reverseMaps.TryGetValue(type, out var t)) + if (s_interfaceToRevit.TryGetValue(type, out var t)) { return t; } + return null; } From 1e3df18f5bd0659885b3f20aa37885fcdc1c4330 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Thu, 13 Jun 2024 13:38:34 +0100 Subject: [PATCH 18/25] fmt --- .../DependencyInjection/ProxyMap.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs index f6c378630e..2d7f7f8314 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs @@ -54,7 +54,8 @@ private static void Add(Func f) return t; } return null; - } + } + public Type? GetMappedTypeFromProxyType(Type type) { if (s_proxyToInterfaceMap.TryGetValue(type, out var t)) From 5ff24812c12a33bc2f0114a41b939861d4053d82 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Thu, 13 Jun 2024 13:58:00 +0100 Subject: [PATCH 19/25] change namespaces --- .../RevitConverterModule.cs | 3 ++- .../LocationConversionToSpeckleTests.cs | 1 + .../Helpers/ParameterValueExtractor.cs | 24 ++++++++++++------- .../Raw/BeamConversionToSpeckle.cs | 2 +- .../Raw/BoundarySegmentConversionToSpeckle.cs | 2 +- .../Raw/BraceToSpeckleConverter.cs | 2 +- .../Raw/ColumnConversionToSpeckle.cs | 2 +- .../Raw/Geometry/ArcToSpeckleConverter.cs | 2 +- .../BoundingBoxXYZToSpeckleConverter.cs | 2 +- .../Raw/Geometry/CircleToSpeckleConverter.cs | 2 +- ...urveArrArrayToSpecklePolycurveConverter.cs | 2 +- .../Geometry/CurveArrayConversionToSpeckle.cs | 3 +-- .../Raw/Geometry/CurveConversionToSpeckle.cs | 2 +- .../Raw/Geometry/EllipseToSpeckleConverter.cs | 2 +- .../HermiteSplineToSpeckleConverter.cs | 2 +- .../Raw/Geometry/LineConversionToSpeckle.cs | 2 +- .../MeshByMaterialDictionaryToSpeckle.cs | 2 +- .../Raw/Geometry/MeshConversionToSpeckle.cs | 2 +- .../Geometry/NurbsSplineToSpeckleConverter.cs | 2 +- .../Raw/Geometry/PlaneToSpeckleConverter.cs | 2 +- .../Geometry/PointCloudToSpeckleConverter.cs | 2 +- .../Raw/Geometry/PointConversionToSpeckle.cs | 2 +- .../Geometry/PolylineToSpeckleConverter.cs | 2 +- .../Raw/Geometry/SolidConversionToSpeckle.cs | 2 +- .../Raw/Geometry/VectorToSpeckleConverter.cs | 2 +- .../Raw/Geometry/XyzConversionToPoint.cs | 2 +- .../Raw/LevelConversionToSpeckle.cs | 3 +-- .../Raw/LocationConversionToSpeckle.cs | 2 +- .../Raw/MaterialConversionToSpeckle.cs | 2 +- .../ModelCurveArrArrayConverterToSpeckle.cs | 2 +- .../Raw/ModelCurveArrayToSpeckleConverter.cs | 3 +-- .../Raw/ParameterConversionToSpeckle.cs | 2 +- .../Raw/RevitVersionConversionHelper.cs | 2 +- .../Services/ReferencePointConverter.cs | 2 +- .../BaseTopLevelConverterToSpeckle.cs | 2 +- .../CeilingTopLevelConverterToSpeckle.cs | 1 - .../DirectShapeTopLevelConverterToSpeckle.cs | 2 +- .../ElementTopLevelConverterToSpeckle.cs | 2 +- ...ExtrusionRoofToSpeckleTopLevelConverter.cs | 2 +- ...amilyInstanceTopLevelConverterToSpeckle.cs | 2 +- .../FloorTopLevelConverterToSpeckle.cs | 2 +- ...FootPrintRoofToSpeckleTopLevelConverter.cs | 2 +- .../HostedElementConversionToSpeckle.cs | 2 +- .../ModelCurveToSpeckleTopLevelConverter.cs | 2 +- ...fBaseToSpeckleTopLevelTopLevelConverter.cs | 2 +- .../RoomTopLevelConverterToSpeckle.cs | 2 +- .../TopographyTopLevelConverterToSpeckle.cs | 1 - .../WallTopLevelConverterToSpeckle.cs | 1 - 48 files changed, 61 insertions(+), 57 deletions(-) diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs index 17897c69fb..cfcdae54c5 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs @@ -1,9 +1,10 @@ using Speckle.Autofac.DependencyInjection; using Speckle.Converters.Common; using Speckle.Converters.Common.DependencyInjection; -using Speckle.Converters.Revit2023.ToSpeckle; +using Speckle.Converters.RevitShared; using Speckle.Converters.RevitShared.Helpers; using Speckle.Converters.RevitShared.Services; +using Speckle.Converters.RevitShared.ToSpeckle; using Speckle.Revit.Interfaces; namespace Speckle.Converters.Revit2023.DependencyInjection; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/LocationConversionToSpeckleTests.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/LocationConversionToSpeckleTests.cs index f791320afa..6fb5ba34d3 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/LocationConversionToSpeckleTests.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/LocationConversionToSpeckleTests.cs @@ -4,6 +4,7 @@ using Objects; using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; +using Speckle.Converters.RevitShared; using Speckle.Converters.RevitShared.Services; using Speckle.Revit.Interfaces; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs index 2b4cabf2e1..b5218980fd 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs @@ -139,12 +139,15 @@ public bool TryGetValueAsElementId( [NotNullWhen(true)] out IRevitElementId? elementId ) { - if ( - GetValueGeneric(element, builtInParameter, RevitStorageType.ElementId, (parameter) => parameter.AsElementId()) - is IRevitElementId elementIdNotNull - ) + var generic = GetValueGeneric( + element, + builtInParameter, + RevitStorageType.ElementId, + (parameter) => parameter.AsElementId() + ); + if (generic is not null) { - elementId = elementIdNotNull; + elementId = generic; return true; } @@ -154,7 +157,7 @@ is IRevitElementId elementIdNotNull public IRevitElementId? GetValueAsElementId(IRevitParameter parameter) { - return GetValueGeneric(parameter, RevitStorageType.ElementId, (parameter) => parameter.AsElementId()); + return GetValueGeneric(parameter, RevitStorageType.ElementId, (p) => p.AsElementId()); } public IRevitLevel? GetValueAsRevitLevel(IRevitElement element, RevitBuiltInParameter builtInParameter) @@ -183,7 +186,11 @@ Func getParamValue _uniqueIdToUsedParameterSetMap[element.UniqueId] = usedParameters; } usedParameters.Add(builtInParameter); - var parameter = element.GetParameter(builtInParameter).NotNull(); + var parameter = element.GetParameter(builtInParameter); + if (parameter is null) + { + return default; + } return GetValueGeneric(parameter, expectedStorageType, getParamValue); } @@ -229,7 +236,8 @@ private void AddElementParamsToDict(IRevitElement element, Dictionary, SOG.Polycurve> { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BraceToSpeckleConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BraceToSpeckleConverter.cs index b16eacfb2a..bcee398c73 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BraceToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BraceToSpeckleConverter.cs @@ -2,7 +2,7 @@ using Speckle.Core.Models; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023; +namespace Speckle.Converters.RevitShared; // POC: There is no validation on this converter to prevent conversion from "not a Revit Beam" to a Speckle Beam. // This will definitely explode if we tried. Goes back to the `CanConvert` functionality conversation. diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs index 7f1d2c96d3..dc12c29082 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs @@ -5,7 +5,7 @@ using Speckle.Core.Models; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023; +namespace Speckle.Converters.RevitShared; // POC: There is no validation on this converter to prevent conversion from "not a Revit Beam" to a Speckle Beam. // This will definitely explode if we tried. Goes back to the `CanConvert` functionality conversation. diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/ArcToSpeckleConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/ArcToSpeckleConverter.cs index a74724e53a..a5830c9c45 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/ArcToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/ArcToSpeckleConverter.cs @@ -4,7 +4,7 @@ using Speckle.Converters.RevitShared.Services; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; public class ArcToSpeckleConverter : ITypedConverter { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/BoundingBoxXYZToSpeckleConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/BoundingBoxXYZToSpeckleConverter.cs index b8d88bbe1f..f91deee0cc 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/BoundingBoxXYZToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/BoundingBoxXYZToSpeckleConverter.cs @@ -3,7 +3,7 @@ using Speckle.Converters.Common.Objects; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; public class BoundingBoxXYZToSpeckleConverter : ITypedConverter { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CircleToSpeckleConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CircleToSpeckleConverter.cs index f36fd115ea..580c223c6b 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CircleToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CircleToSpeckleConverter.cs @@ -3,7 +3,7 @@ using Speckle.Converters.RevitShared.Services; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; public class CircleToSpeckleConverter : ITypedConverter { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveArrArrayToSpecklePolycurveConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveArrArrayToSpecklePolycurveConverter.cs index 5236040a30..d393d310c6 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveArrArrayToSpecklePolycurveConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveArrArrayToSpecklePolycurveConverter.cs @@ -1,7 +1,7 @@ using Speckle.Converters.Common.Objects; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; public sealed class CurveArrArrayToSpecklePolycurveConverter : ITypedConverter> { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveArrayConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveArrayConversionToSpeckle.cs index be3bb98162..afa6ad4830 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveArrayConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveArrayConversionToSpeckle.cs @@ -1,11 +1,10 @@ using Objects; using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Converters.RevitShared; using Speckle.Converters.RevitShared.Services; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; public sealed class CurveArrayConversionToSpeckle : ITypedConverter { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveConversionToSpeckle.cs index 148da296e8..e165964a28 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/CurveConversionToSpeckle.cs @@ -3,7 +3,7 @@ using Speckle.Converters.Common.Objects; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; public class CurveConversionToSpeckle : ITypedConverter { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/EllipseToSpeckleConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/EllipseToSpeckleConverter.cs index 4cd4943bea..7f920e5954 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/EllipseToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/EllipseToSpeckleConverter.cs @@ -4,7 +4,7 @@ using Speckle.Converters.RevitShared.Services; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; public class EllipseToSpeckleConverter : ITypedConverter { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/HermiteSplineToSpeckleConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/HermiteSplineToSpeckleConverter.cs index 9c5285dc98..1c364da849 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/HermiteSplineToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/HermiteSplineToSpeckleConverter.cs @@ -1,7 +1,7 @@ using Speckle.Converters.Common.Objects; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; public class HermiteSplineToSpeckleConverter : ITypedConverter { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/LineConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/LineConversionToSpeckle.cs index d50873233c..ceddef39b0 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/LineConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/LineConversionToSpeckle.cs @@ -4,7 +4,7 @@ using Speckle.Converters.RevitShared.Services; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; public class LineConversionToSpeckle : ITypedConverter { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/MeshByMaterialDictionaryToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/MeshByMaterialDictionaryToSpeckle.cs index 0df626be74..22d806277a 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/MeshByMaterialDictionaryToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/MeshByMaterialDictionaryToSpeckle.cs @@ -3,7 +3,7 @@ using Speckle.Converters.Common.Objects; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; public class MeshByMaterialDictionaryToSpeckle : ITypedConverter>, List> diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/MeshConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/MeshConversionToSpeckle.cs index 80529d4ba6..093d553cf2 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/MeshConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/MeshConversionToSpeckle.cs @@ -3,7 +3,7 @@ using Speckle.Converters.Common.Objects; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; public class MeshConversionToSpeckle : ITypedConverter { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/NurbsSplineToSpeckleConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/NurbsSplineToSpeckleConverter.cs index 539aebc888..c646f9e6b4 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/NurbsSplineToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/NurbsSplineToSpeckleConverter.cs @@ -4,7 +4,7 @@ using Speckle.Converters.RevitShared.Services; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; public class NurbsSplineToSpeckleConverter : ITypedConverter { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PlaneToSpeckleConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PlaneToSpeckleConverter.cs index 0b4f090663..56f098ceda 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PlaneToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PlaneToSpeckleConverter.cs @@ -2,7 +2,7 @@ using Speckle.Converters.Common.Objects; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; public class PlaneToSpeckleConverter : ITypedConverter { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PointCloudToSpeckleConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PointCloudToSpeckleConverter.cs index a66caa3b62..ee5b81e95d 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PointCloudToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PointCloudToSpeckleConverter.cs @@ -2,7 +2,7 @@ using Speckle.Converters.Common.Objects; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; public class PointCloudToSpeckleConverter : ITypedConverter { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PointConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PointConversionToSpeckle.cs index 328283066c..4da12eafca 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PointConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PointConversionToSpeckle.cs @@ -1,7 +1,7 @@ using Speckle.Converters.Common.Objects; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; public class PointConversionToSpeckle : ITypedConverter { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PolylineToSpeckleConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PolylineToSpeckleConverter.cs index b84f63a3ea..e64b28309b 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PolylineToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/PolylineToSpeckleConverter.cs @@ -2,7 +2,7 @@ using Speckle.Converters.Common.Objects; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; public class PolylineToSpeckleConverter : ITypedConverter { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/SolidConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/SolidConversionToSpeckle.cs index 80996f470d..039c706869 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/SolidConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/SolidConversionToSpeckle.cs @@ -1,7 +1,7 @@ using Speckle.Converters.Common.Objects; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; /// /// Solid conversion is a one->many. For each material used in the solid, a mesh will be returned to reduce the amount of instances created. diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/VectorToSpeckleConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/VectorToSpeckleConverter.cs index 1f151a5e84..ad04f5d8db 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/VectorToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/VectorToSpeckleConverter.cs @@ -2,7 +2,7 @@ using Speckle.Converters.RevitShared.Services; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; public class VectorToSpeckleConverter : ITypedConverter { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/XyzConversionToPoint.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/XyzConversionToPoint.cs index 962c13156a..4f5996e1e5 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/XyzConversionToPoint.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/XyzConversionToPoint.cs @@ -4,7 +4,7 @@ using Speckle.Revit.Interfaces; #pragma warning disable IDE0130 -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; public class XyzConversionToPoint : ITypedConverter { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LevelConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LevelConversionToSpeckle.cs index e2af3a7e55..234ddc358d 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LevelConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LevelConversionToSpeckle.cs @@ -2,8 +2,7 @@ using Speckle.Converters.RevitShared.Services; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023; - +namespace Speckle.Converters.RevitShared; public class LevelConversionToSpeckle : ITypedConverter { private readonly IScalingServiceToSpeckle _scalingService; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LocationConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LocationConversionToSpeckle.cs index e3dfae8ef2..e50548699f 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LocationConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LocationConversionToSpeckle.cs @@ -5,7 +5,7 @@ using Speckle.Revit.Interfaces; #pragma warning disable IDE0130 -namespace Speckle.Converters.Revit2023; +namespace Speckle.Converters.RevitShared; #pragma warning restore IDE0130 diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/MaterialConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/MaterialConversionToSpeckle.cs index ddabe2f856..50062f88fd 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/MaterialConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/MaterialConversionToSpeckle.cs @@ -2,7 +2,7 @@ using Speckle.Converters.Common.Objects; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023; +namespace Speckle.Converters.RevitShared; public class MaterialConversionToSpeckle : ITypedConverter { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ModelCurveArrArrayConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ModelCurveArrArrayConverterToSpeckle.cs index 272d81927e..111e12a42b 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ModelCurveArrArrayConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ModelCurveArrArrayConverterToSpeckle.cs @@ -2,7 +2,7 @@ using Speckle.Converters.Common.Objects; using Speckle.Revit.Interfaces; #pragma warning disable IDE0130 -namespace Speckle.Converters.Revit2023; +namespace Speckle.Converters.RevitShared; internal sealed class ModelCurveArrArrayConverterToSpeckle : ITypedConverter { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ModelCurveArrayToSpeckleConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ModelCurveArrayToSpeckleConverter.cs index d96398960d..ce1690ee5d 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ModelCurveArrayToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ModelCurveArrayToSpeckleConverter.cs @@ -1,11 +1,10 @@ using Objects; using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Converters.RevitShared; using Speckle.Converters.RevitShared.Services; using Speckle.Revit.Interfaces; #pragma warning disable IDE0130 -namespace Speckle.Converters.Revit2023; +namespace Speckle.Converters.RevitShared; public sealed class ModelCurveArrayToSpeckleConverter : ITypedConverter { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ParameterConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ParameterConversionToSpeckle.cs index 2054eba3e5..ae2a9ec5c5 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ParameterConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ParameterConversionToSpeckle.cs @@ -3,7 +3,7 @@ using Speckle.Converters.RevitShared.Helpers; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023; +namespace Speckle.Converters.RevitShared; public class ParameterConversionToSpeckle : ITypedConverter { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/RevitVersionConversionHelper.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/RevitVersionConversionHelper.cs index b85e017ba1..7ebcaf9d95 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/RevitVersionConversionHelper.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/RevitVersionConversionHelper.cs @@ -2,7 +2,7 @@ using Speckle.InterfaceGenerator; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023; +namespace Speckle.Converters.RevitShared; [GenerateAutoInterface] public class RevitVersionConversionHelper : IRevitVersionConversionHelper diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/ReferencePointConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/ReferencePointConverter.cs index d3d3e2384f..da8c985834 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/ReferencePointConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/ReferencePointConverter.cs @@ -3,7 +3,7 @@ using Speckle.InterfaceGenerator; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023; +namespace Speckle.Converters.RevitShared; [GenerateAutoInterface] public class RevitConversionSettings : IRevitConversionSettings diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/BaseTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/BaseTopLevelConverterToSpeckle.cs index 394990c507..0a246e3b2f 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/BaseTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/BaseTopLevelConverterToSpeckle.cs @@ -2,7 +2,7 @@ using Speckle.Converters.Common.Objects; using Speckle.Core.Models; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; // POC: maybe but could be generic abstract Converters.Common? // or maybe it's not actually doing very much now and can come out diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs index 41e64c2488..b757b03215 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs @@ -3,7 +3,6 @@ using Objects.Geometry; using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Converters.Revit2023.ToSpeckle; using Speckle.Converters.RevitShared.Helpers; using Speckle.Revit.Interfaces; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/DirectShapeTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/DirectShapeTopLevelConverterToSpeckle.cs index 0aa1d5fab7..1f87f63696 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/DirectShapeTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/DirectShapeTopLevelConverterToSpeckle.cs @@ -4,7 +4,7 @@ using Speckle.Core.Models; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; [NameAndRankValue(nameof(IRevitDirectShape), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] public class DirectShapeTopLevelConverterToSpeckle : BaseTopLevelConverterToSpeckle diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ElementTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ElementTopLevelConverterToSpeckle.cs index a9a5bb2c7a..cbd1cd9e06 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ElementTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ElementTopLevelConverterToSpeckle.cs @@ -2,7 +2,7 @@ using Speckle.Converters.RevitShared.Helpers; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; // POC: not currently used? clearly some missing pieces [NameAndRankValue(nameof(IRevitElement), 0)] diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ExtrusionRoofToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ExtrusionRoofToSpeckleTopLevelConverter.cs index 32090152fc..b02390e933 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ExtrusionRoofToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ExtrusionRoofToSpeckleTopLevelConverter.cs @@ -5,7 +5,7 @@ using Speckle.Converters.RevitShared.Helpers; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; [NameAndRankValue(nameof(IRevitExtrusionRoof), 0)] public class ExtrusionRoofToSpeckleTopLevelConverter diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FamilyInstanceTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FamilyInstanceTopLevelConverterToSpeckle.cs index 0cbdc994d9..b408d104cc 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FamilyInstanceTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FamilyInstanceTopLevelConverterToSpeckle.cs @@ -3,7 +3,7 @@ using Speckle.Core.Models; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; // POC: bin for now? This is also a parent child relationship and may need a pattern for this // so we don't end up with some god FamilyInstanceTopLevelConverterToSpeckle converter diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs index 004433ecbd..b6c8ade775 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs @@ -5,7 +5,7 @@ using Speckle.Core.Models; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; // POC: reminder - writing classes and creating interfaces is a bit like organising your space // if you have a structure for organising things, your interfaces, then finding your stuff, your classes & methods, becomes easy diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FootPrintRoofToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FootPrintRoofToSpeckleTopLevelConverter.cs index f0ad7efabe..5a51d40f28 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FootPrintRoofToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FootPrintRoofToSpeckleTopLevelConverter.cs @@ -6,7 +6,7 @@ using Speckle.Converters.RevitShared.Helpers; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; [NameAndRankValue(nameof(IRevitFootPrintRoof), 0)] public class FootPrintRoofToSpeckleTopLevelConverter diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/HostedElementConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/HostedElementConversionToSpeckle.cs index 81dae6b6a5..b927329b7e 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/HostedElementConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/HostedElementConversionToSpeckle.cs @@ -3,7 +3,7 @@ using Speckle.InterfaceGenerator; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; // POC: do we need to see the blocks investigation outcome? Does the current logic hold? // opportunity to rethink or confirm hosted element handling? Should this be a connector responsibiliy? diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ModelCurveToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ModelCurveToSpeckleTopLevelConverter.cs index a2e7357337..f305468ece 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ModelCurveToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ModelCurveToSpeckleTopLevelConverter.cs @@ -3,7 +3,7 @@ using Speckle.Converters.Common.Objects; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; // POC: ModelCurve looks a bit bogus and we may wish to revise what that is and how it inherits // see https://spockle.atlassian.net/browse/CNX-9381 diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/RoofBaseToSpeckleTopLevelTopLevelConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/RoofBaseToSpeckleTopLevelTopLevelConverter.cs index aee970c621..805671c0a7 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/RoofBaseToSpeckleTopLevelTopLevelConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/RoofBaseToSpeckleTopLevelTopLevelConverter.cs @@ -4,7 +4,7 @@ using Speckle.Converters.RevitShared.Helpers; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; [NameAndRankValue(nameof(IRevitRoofBase), 0)] internal sealed class RoofBaseToSpeckleTopLevelTopLevelConverter diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/RoomTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/RoomTopLevelConverterToSpeckle.cs index 9082b3fec3..6baaa3d6aa 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/RoomTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/RoomTopLevelConverterToSpeckle.cs @@ -5,7 +5,7 @@ using Speckle.Core.Models; using Speckle.Revit.Interfaces; -namespace Speckle.Converters.Revit2023.ToSpeckle; +namespace Speckle.Converters.RevitShared.ToSpeckle; [NameAndRankValue(nameof(IRevitRoom), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] public class RoomTopLevelConverterToSpeckle : BaseTopLevelConverterToSpeckle diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/TopographyTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/TopographyTopLevelConverterToSpeckle.cs index 5ed057d018..ce34b66376 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/TopographyTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/TopographyTopLevelConverterToSpeckle.cs @@ -1,5 +1,4 @@ using Speckle.Converters.Common; -using Speckle.Converters.Revit2023.ToSpeckle; using Speckle.Converters.RevitShared.Helpers; using Speckle.Revit.Interfaces; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs index 129817f4a1..3d48ca2ede 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs @@ -6,7 +6,6 @@ using Speckle.Core.Models.Extensions; using Speckle.Converters.RevitShared.Extensions; using Objects.BuiltElements.Revit; -using Speckle.Converters.Revit2023.ToSpeckle; using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared.ToSpeckle; From 3e780ace86ead3b0baf87c71cec86301dde46665 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Thu, 13 Jun 2024 14:04:39 +0100 Subject: [PATCH 20/25] updates to proxies --- .../Speckle.Connectors.RevitShared.projitems | 3 --- .../RevitConverterModule.cs | 1 - ...kle.Converters.Revit2023.DependencyInjection.csproj | 2 +- .../Speckle.Converters.Revit2023.Tests.csproj | 2 +- .../packages.lock.json | 10 +++++----- .../Speckle.Converters.Revit2023.csproj | 2 +- .../Speckle.Converters.Common.csproj | 2 +- 7 files changed, 9 insertions(+), 13 deletions(-) diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Speckle.Connectors.RevitShared.projitems b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Speckle.Connectors.RevitShared.projitems index 906267a41b..a479f3189b 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Speckle.Connectors.RevitShared.projitems +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Speckle.Connectors.RevitShared.projitems @@ -24,7 +24,4 @@ MSBuild:Compile - - - \ No newline at end of file diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs index cfcdae54c5..f5ecc652f0 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs @@ -29,6 +29,5 @@ public void Load(SpeckleContainerBuilder builder) builder.AddScoped(); builder.AddScoped(); builder.AddScoped(); - //builder.AddScoped(); } } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/Speckle.Converters.Revit2023.DependencyInjection.csproj b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/Speckle.Converters.Revit2023.DependencyInjection.csproj index 5cd7d827cb..1b25c312b3 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/Speckle.Converters.Revit2023.DependencyInjection.csproj +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/Speckle.Converters.Revit2023.DependencyInjection.csproj @@ -6,7 +6,7 @@ - + diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/Speckle.Converters.Revit2023.Tests.csproj b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/Speckle.Converters.Revit2023.Tests.csproj index f82da26310..6169eb80c6 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/Speckle.Converters.Revit2023.Tests.csproj +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/Speckle.Converters.Revit2023.Tests.csproj @@ -14,7 +14,7 @@ - + diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/packages.lock.json b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/packages.lock.json index 393b4d48d6..ada7b1ce13 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/packages.lock.json +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/packages.lock.json @@ -65,9 +65,9 @@ }, "Speckle.Revit2023.Interfaces": { "type": "Direct", - "requested": "[0.1.1-preview.0.18, )", - "resolved": "0.1.1-preview.0.18", - "contentHash": "6YcocyBY9cLHwdKqpy7VY3amlT4/m+7dw74tglta8pGYfVfMzWq8Rtq4CBywXcxIxtimcjYceJ/le5Q0VVao7w==" + "requested": "[0.1.1-preview.0.19, )", + "resolved": "0.1.1-preview.0.19", + "contentHash": "eAiuTXl5eIWTq+1yZUWjV+JQhFvRH4Uv0EWBFB8SXhI9tkHw39FxGn0k3Lwsyrt7c9SxbaQKSt2sut/cbisQFw==" }, "Castle.Core": { "type": "Transitive", @@ -499,7 +499,7 @@ "dependencies": { "Speckle.Autofac": "[2.0.999-local, )", "Speckle.Objects": "[2.0.999-local, )", - "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.18, )" + "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.19, )" } }, "speckle.converters.common.dependencyinjection": { @@ -513,7 +513,7 @@ "type": "Project", "dependencies": { "Speckle.Converters.Common": "[2.0.999-local, )", - "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.18, )" + "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.19, )" } }, "Speckle.Core": { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/Speckle.Converters.Revit2023.csproj b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/Speckle.Converters.Revit2023.csproj index c127965904..2b2e659bb5 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/Speckle.Converters.Revit2023.csproj +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/Speckle.Converters.Revit2023.csproj @@ -9,7 +9,7 @@ - + diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common/Speckle.Converters.Common.csproj b/DUI3-DX/Sdk/Speckle.Converters.Common/Speckle.Converters.Common.csproj index daff575890..ab82e46ba3 100644 --- a/DUI3-DX/Sdk/Speckle.Converters.Common/Speckle.Converters.Common.csproj +++ b/DUI3-DX/Sdk/Speckle.Converters.Common/Speckle.Converters.Common.csproj @@ -4,7 +4,7 @@ netstandard2.0 - + From e2849813aa1d7e62d11365acadaf7c2ded752672 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Thu, 13 Jun 2024 14:31:06 +0100 Subject: [PATCH 21/25] more cast changes --- .../Helpers/DisplayValueExtractor.cs | 91 +++++++++++-------- .../Raw/LevelConversionToSpeckle.cs | 1 + .../Raw/LocationConversionToSpeckle.cs | 17 +++- .../RevitRootToHostConverter.cs | 51 ----------- 4 files changed, 67 insertions(+), 93 deletions(-) delete mode 100644 DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitRootToHostConverter.cs diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/DisplayValueExtractor.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/DisplayValueExtractor.cs index 377e12dd1f..adfbcc8fb2 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/DisplayValueExtractor.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/DisplayValueExtractor.cs @@ -160,28 +160,32 @@ private void SortGeometry( { // POC: switch could possibly become factory and IIndex<,> pattern and move conversions to // separate IComeConversionInterfaces - switch (geomObj) + var solid = geomObj.ToSolid(); + if (solid is not null) { - case IRevitSolid solid: - // skip invalid solid - if ( - solid.Faces.Count == 0 - || Math.Abs(solid.SurfaceArea) == 0 - || IsSkippableGraphicStyle(solid.GraphicsStyleId, element.Document) - ) - { - continue; - } + // skip invalid solid + if ( + solid.Faces.Count == 0 + || Math.Abs(solid.SurfaceArea) == 0 + || IsSkippableGraphicStyle(solid.GraphicsStyleId, element.Document) + ) + { + continue; + } - if (inverseTransform != null) - { - topLevelSolidsCount++; - solid = _revitSolidUtils.CreateTransformed(solid, inverseTransform); - } + if (inverseTransform != null) + { + topLevelSolidsCount++; + solid = _revitSolidUtils.CreateTransformed(solid, inverseTransform); + } - solids.Add(solid); - break; - case IRevitMesh mesh: + solids.Add(solid); + } + else + { + var mesh = geomObj.ToMesh(); + if (mesh is not null) + { if (IsSkippableGraphicStyle(mesh.GraphicsStyleId, element.Document)) { continue; @@ -194,31 +198,44 @@ private void SortGeometry( } meshes.Add(mesh); - break; - case IRevitGeometryInstance instance: - // element transforms should not be carried down into nested geometryInstances. - // Nested geomInstances should have their geom retreived with GetInstanceGeom, not GetSymbolGeom - if (inverseTransform != null) + } + else + { + + var instance = geomObj.ToGeometryInstance(); + if (instance is not null) { - topLevelGeomInstanceCount++; - SortGeometry(element, solids, meshes, instance.GetSymbolGeometry()); - if (meshes.Count > 0 || solids.Count > 0) + // element transforms should not be carried down into nested geometryInstances. + // Nested geomInstances should have their geom retreived with GetInstanceGeom, not GetSymbolGeom + if (inverseTransform != null) { - hasSymbolGeometry = true; + topLevelGeomInstanceCount++; + SortGeometry(element, solids, meshes, instance.GetSymbolGeometry()); + if (meshes.Count > 0 || solids.Count > 0) + { + hasSymbolGeometry = true; + } + } + else + { + SortGeometry(element, solids, meshes, instance.GetInstanceGeometry()); } } else { - SortGeometry(element, solids, meshes, instance.GetInstanceGeometry()); - } - break; - case IRevitGeometryElement geometryElement: - if (inverseTransform != null) - { - topLevelGeomElementCount++; + + var geometryElement = geomObj.ToGeometryElement(); + if (geometryElement is not null) + { + if (inverseTransform != null) + { + topLevelGeomElementCount++; + } + + SortGeometry(element, solids, meshes, geometryElement); + } } - SortGeometry(element, solids, meshes, geometryElement); - break; + } } } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LevelConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LevelConversionToSpeckle.cs index 234ddc358d..bea059ceaa 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LevelConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LevelConversionToSpeckle.cs @@ -3,6 +3,7 @@ using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared; + public class LevelConversionToSpeckle : ITypedConverter { private readonly IScalingServiceToSpeckle _scalingService; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LocationConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LocationConversionToSpeckle.cs index e50548699f..5d4170fd37 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LocationConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LocationConversionToSpeckle.cs @@ -28,11 +28,18 @@ public LocationConversionToSpeckle( public Base Convert(IRevitLocation target) { - return target switch + var curve = target.ToLocationCurve(); + if (curve is not null) { - IRevitLocationCurve curve => (_curveConverter.Convert(curve.Curve) as Base).NotNull(), // POC: ICurve and Base are not related but we know they must be, had to soft cast and then !. - IRevitLocationPoint point => _xyzConverter.Convert(point.Point), - _ => throw new SpeckleConversionException($"Unexpected location type {target.GetType()}") - }; + return + (_curveConverter.Convert(curve.Curve) as Base) + .NotNull(); // POC: ICurve and Base are not related but we know they must be, had to soft cast and then !. + } + var point = target.ToLocationPoint(); + if (point is not null) + { + _xyzConverter.Convert(point.Point); + } + throw new SpeckleConversionException($"Unexpected location type {target.GetType()}"); } } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitRootToHostConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitRootToHostConverter.cs deleted file mode 100644 index add05d6402..0000000000 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitRootToHostConverter.cs +++ /dev/null @@ -1,51 +0,0 @@ -using Speckle.Converters.Common; -using Speckle.Converters.Common.Objects; -using Speckle.Core.Models; -using Speckle.Converters.RevitShared.Helpers; -using Speckle.Revit.Interfaces; - -namespace Speckle.Converters.RevitShared; - -// POC: maybe possible to restrict the access so this cannot be created directly? -public class RevitRootToHostConverter : IRootToSpeckleConverter -{ - private readonly IConverterResolver _toSpeckle; - private readonly IParameterValueExtractor _parameterValueExtractor; - - public RevitRootToHostConverter( - IConverterResolver toSpeckle, - IParameterValueExtractor parameterValueExtractor - ) - { - _toSpeckle = toSpeckle; - _parameterValueExtractor = parameterValueExtractor; - } - - // POC: our assumption here is target is valid for conversion - // if it cannot be converted then we should throw - public Base Convert(object target) - { - var objectConverter = _toSpeckle.GetConversionForType(target.GetType()); - - if (objectConverter == null) - { - throw new SpeckleConversionException($"No conversion found for {target.GetType().Name}"); - } - - Base result = - objectConverter.Convert(target) - ?? throw new SpeckleConversionException($"Conversion of object with type {target.GetType()} returned null"); - - // POC : where should logic common to most objects go? - // shouldn't target ALWAYS be DB.Element? - if (target is IRevitElement element) - { - // POC: is this the right place? - result.applicationId = element.UniqueId; - - _parameterValueExtractor.RemoveUniqueId(element.UniqueId); - } - - return result; - } -} From 10e7114441957b3eadcf582917373749acd62bd7 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Thu, 13 Jun 2024 14:33:55 +0100 Subject: [PATCH 22/25] another cast issue fixed --- .../Helpers/DisplayValueExtractor.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/DisplayValueExtractor.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/DisplayValueExtractor.cs index adfbcc8fb2..cf9a37d276 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/DisplayValueExtractor.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/DisplayValueExtractor.cs @@ -39,7 +39,8 @@ IRevitSolidUtils revitSolidUtils var displayMeshes = new List(); // test if the element is a group first - if (element is IRevitGroup g) + var g = element.ToGroup(); + if (g is not null) { foreach (var id in g.GetMemberIds()) { From 041bb5c47247c347091e6cc5f1567825e242ab0d Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Thu, 13 Jun 2024 14:51:49 +0100 Subject: [PATCH 23/25] update nugets --- ...kle.Converters.Revit2023.DependencyInjection.csproj | 2 +- .../Speckle.Converters.Revit2023.Tests.csproj | 2 +- .../packages.lock.json | 10 +++++----- .../Speckle.Converters.Revit2023.csproj | 2 +- .../Speckle.Converters.Common.csproj | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/Speckle.Converters.Revit2023.DependencyInjection.csproj b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/Speckle.Converters.Revit2023.DependencyInjection.csproj index 1b25c312b3..c390bba29b 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/Speckle.Converters.Revit2023.DependencyInjection.csproj +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/Speckle.Converters.Revit2023.DependencyInjection.csproj @@ -6,7 +6,7 @@ - + diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/Speckle.Converters.Revit2023.Tests.csproj b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/Speckle.Converters.Revit2023.Tests.csproj index 6169eb80c6..70941da6f7 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/Speckle.Converters.Revit2023.Tests.csproj +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/Speckle.Converters.Revit2023.Tests.csproj @@ -14,7 +14,7 @@ - + diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/packages.lock.json b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/packages.lock.json index ada7b1ce13..b6ddfa328f 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/packages.lock.json +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/packages.lock.json @@ -65,9 +65,9 @@ }, "Speckle.Revit2023.Interfaces": { "type": "Direct", - "requested": "[0.1.1-preview.0.19, )", - "resolved": "0.1.1-preview.0.19", - "contentHash": "eAiuTXl5eIWTq+1yZUWjV+JQhFvRH4Uv0EWBFB8SXhI9tkHw39FxGn0k3Lwsyrt7c9SxbaQKSt2sut/cbisQFw==" + "requested": "[0.1.1-preview.0.20, )", + "resolved": "0.1.1-preview.0.20", + "contentHash": "L/8btGlDejt6OCe8Lee05N3ztKV+pz24WAU9fwXRHEeWMgSe+bqq477Jmk641QFcKmcWK25XJlprlHiCh4pAdQ==" }, "Castle.Core": { "type": "Transitive", @@ -499,7 +499,7 @@ "dependencies": { "Speckle.Autofac": "[2.0.999-local, )", "Speckle.Objects": "[2.0.999-local, )", - "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.19, )" + "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.20, )" } }, "speckle.converters.common.dependencyinjection": { @@ -513,7 +513,7 @@ "type": "Project", "dependencies": { "Speckle.Converters.Common": "[2.0.999-local, )", - "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.19, )" + "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.20, )" } }, "Speckle.Core": { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/Speckle.Converters.Revit2023.csproj b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/Speckle.Converters.Revit2023.csproj index 2b2e659bb5..351d1fa2e3 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/Speckle.Converters.Revit2023.csproj +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/Speckle.Converters.Revit2023.csproj @@ -9,7 +9,7 @@ - + diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common/Speckle.Converters.Common.csproj b/DUI3-DX/Sdk/Speckle.Converters.Common/Speckle.Converters.Common.csproj index ab82e46ba3..7fb8e9d333 100644 --- a/DUI3-DX/Sdk/Speckle.Converters.Common/Speckle.Converters.Common.csproj +++ b/DUI3-DX/Sdk/Speckle.Converters.Common/Speckle.Converters.Common.csproj @@ -4,7 +4,7 @@ netstandard2.0 - + From fd019d4b1ec80fb7693b5b2d9e608dfd9aa2eb90 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Thu, 13 Jun 2024 14:59:44 +0100 Subject: [PATCH 24/25] fmt --- .../Helpers/DisplayValueExtractor.cs | 2 -- .../Raw/LocationConversionToSpeckle.cs | 4 +--- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/DisplayValueExtractor.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/DisplayValueExtractor.cs index cf9a37d276..2e5eaa8f4f 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/DisplayValueExtractor.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/DisplayValueExtractor.cs @@ -202,7 +202,6 @@ private void SortGeometry( } else { - var instance = geomObj.ToGeometryInstance(); if (instance is not null) { @@ -224,7 +223,6 @@ private void SortGeometry( } else { - var geometryElement = geomObj.ToGeometryElement(); if (geometryElement is not null) { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LocationConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LocationConversionToSpeckle.cs index 5d4170fd37..ffba569ce6 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LocationConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LocationConversionToSpeckle.cs @@ -31,9 +31,7 @@ public Base Convert(IRevitLocation target) var curve = target.ToLocationCurve(); if (curve is not null) { - return - (_curveConverter.Convert(curve.Curve) as Base) - .NotNull(); // POC: ICurve and Base are not related but we know they must be, had to soft cast and then !. + return (_curveConverter.Convert(curve.Curve) as Base).NotNull(); // POC: ICurve and Base are not related but we know they must be, had to soft cast and then !. } var point = target.ToLocationPoint(); if (point is not null) From 18b4d9833d0a22d5302e761c1d7cba7e1f7e3ba2 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Thu, 13 Jun 2024 15:24:25 +0100 Subject: [PATCH 25/25] add System.IO to make CI happy? --- .../Plugin/RevitExternalApplication.cs | 2 +- .../Revit/Speckle.Connectors.RevitShared/Plugin/RevitPlugin.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitExternalApplication.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitExternalApplication.cs index 491a5480e4..1ce923f7c3 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitExternalApplication.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitExternalApplication.cs @@ -32,7 +32,7 @@ public RevitExternalApplication() "2023", "Speckle New UI", "Revit", - new[] { Path.GetDirectoryName(typeof(RevitExternalApplication).Assembly.Location) }, + new[] { System.IO.Path.GetDirectoryName(typeof(RevitExternalApplication).Assembly.Location) }, "Revit Connector", "2023" //POC: app version? ); diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitPlugin.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitPlugin.cs index 8ed0d5ec51..a46046dd45 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitPlugin.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitPlugin.cs @@ -181,7 +181,7 @@ private void RegisterDockablePane() { try { - var assembly = Assembly.LoadFrom(Path.Combine(path)); + var assembly = Assembly.LoadFrom(System.IO.Path.Combine(path)); var icon = assembly.GetManifestResourceStream(sourceName); PngBitmapDecoder decoder = new(icon, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); ImageSource source = decoder.Frames[0];