diff --git a/All.sln b/All.sln index 59406b4cb8..da15c240b4 100644 --- a/All.sln +++ b/All.sln @@ -558,8 +558,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{B1324D25 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Speckle.Converters.Revit2023.Tests", "DUI3-DX\Converters\Revit\Speckle.Converters.Revit2023.Tests\Speckle.Converters.Revit2023.Tests.csproj", "{AEC26A0B-25F3-4544-A9D6-A427BFF79250}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Speckle.Converters.Common.Tests", "DUI3-DX\Sdk\Speckle.Converters.Common.Tests\Speckle.Converters.Common.Tests.csproj", "{95E23A97-E5EA-4506-A52C-D3DA9012DA02}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Speckle.Connectors.Civil3d2024", "DUI3-DX\Connectors\Autocad\Speckle.Connectors.Civil3d2024\Speckle.Connectors.Civil3d2024.csproj", "{DDBBA313-69A6-40DE-AB3A-79EE5BF32A7E}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Speckle.Converters.Autocad2024", "DUI3-DX\Converters\Autocad\2024\Speckle.Converters.Autocad2024\Speckle.Converters.Autocad2024.csproj", "{C9C28F31-1367-438C-83B0-049C3B3A3E3B}" @@ -2816,22 +2814,6 @@ Global {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 - {95E23A97-E5EA-4506-A52C-D3DA9012DA02}.Debug Mac|Any CPU.ActiveCfg = Debug|Any CPU - {95E23A97-E5EA-4506-A52C-D3DA9012DA02}.Debug Mac|Any CPU.Build.0 = Debug|Any CPU - {95E23A97-E5EA-4506-A52C-D3DA9012DA02}.Debug Mac|x64.ActiveCfg = Debug|Any CPU - {95E23A97-E5EA-4506-A52C-D3DA9012DA02}.Debug Mac|x64.Build.0 = Debug|Any CPU - {95E23A97-E5EA-4506-A52C-D3DA9012DA02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {95E23A97-E5EA-4506-A52C-D3DA9012DA02}.Debug|Any CPU.Build.0 = Debug|Any CPU - {95E23A97-E5EA-4506-A52C-D3DA9012DA02}.Debug|x64.ActiveCfg = Debug|Any CPU - {95E23A97-E5EA-4506-A52C-D3DA9012DA02}.Debug|x64.Build.0 = Debug|Any CPU - {95E23A97-E5EA-4506-A52C-D3DA9012DA02}.Release Mac|Any CPU.ActiveCfg = Debug|Any CPU - {95E23A97-E5EA-4506-A52C-D3DA9012DA02}.Release Mac|Any CPU.Build.0 = Debug|Any CPU - {95E23A97-E5EA-4506-A52C-D3DA9012DA02}.Release Mac|x64.ActiveCfg = Debug|Any CPU - {95E23A97-E5EA-4506-A52C-D3DA9012DA02}.Release Mac|x64.Build.0 = Debug|Any CPU - {95E23A97-E5EA-4506-A52C-D3DA9012DA02}.Release|Any CPU.ActiveCfg = Release|Any CPU - {95E23A97-E5EA-4506-A52C-D3DA9012DA02}.Release|Any CPU.Build.0 = Release|Any CPU - {95E23A97-E5EA-4506-A52C-D3DA9012DA02}.Release|x64.ActiveCfg = Release|Any CPU - {95E23A97-E5EA-4506-A52C-D3DA9012DA02}.Release|x64.Build.0 = Release|Any CPU {DDBBA313-69A6-40DE-AB3A-79EE5BF32A7E}.Debug Mac|Any CPU.ActiveCfg = Debug|Any CPU {DDBBA313-69A6-40DE-AB3A-79EE5BF32A7E}.Debug Mac|Any CPU.Build.0 = Debug|Any CPU {DDBBA313-69A6-40DE-AB3A-79EE5BF32A7E}.Debug Mac|x64.ActiveCfg = Debug|Any CPU @@ -3092,7 +3074,6 @@ Global {70DEAA13-6DC8-44A0-B287-9E806A8054F1} = {890F3257-FCC2-4ED8-9180-22B3641B494C} {F06E4C37-4076-4272-9CA6-FB505E02CD31} = {BE521908-7944-46F3-98BF-B47D34509934} {AEC26A0B-25F3-4544-A9D6-A427BFF79250} = {D92751C8-1039-4005-90B2-913E55E0B8BD} - {95E23A97-E5EA-4506-A52C-D3DA9012DA02} = {2E00592E-558D-492D-88F9-3ECEE4C0C7DA} {DDBBA313-69A6-40DE-AB3A-79EE5BF32A7E} = {743489BF-1941-43D5-8AF9-35C56D0DCC34} {C9C28F31-1367-438C-83B0-049C3B3A3E3B} = {804E065F-914C-414A-AF84-009312C3CFF6} {06082BAA-98E8-49B1-9D33-252B126A0561} = {804E065F-914C-414A-AF84-009312C3CFF6} diff --git a/Build/Consts.cs b/Build/Consts.cs index 2fa9d8deaa..5d3f91de54 100644 --- a/Build/Consts.cs +++ b/Build/Consts.cs @@ -5,11 +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", - "Speckle.Converters.Common.Tests" - }; + public static readonly string[] TestProjects = System.Array.Empty(); public static readonly InstallerProject[] InstallerManifests = { diff --git a/DUI3-DX.slnf b/DUI3-DX.slnf index 157eec292b..4f4a6e3edb 100644 --- a/DUI3-DX.slnf +++ b/DUI3-DX.slnf @@ -18,7 +18,6 @@ "DUI3-DX\\Converters\\Autocad\\2024\\Speckle.Converters.Autocad2024\\Speckle.Converters.Autocad2024.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", @@ -28,7 +27,6 @@ "DUI3-DX\\Sdk\\Speckle.Autofac\\Speckle.Autofac.csproj", "DUI3-DX\\Sdk\\Speckle.Connectors.Utils\\Speckle.Connectors.Utils.csproj", "DUI3-DX\\Sdk\\Speckle.Converters.Common.DependencyInjection\\Speckle.Converters.Common.DependencyInjection.csproj", - "DUI3-DX\\Sdk\\Speckle.Converters.Common.Tests\\Speckle.Converters.Common.Tests.csproj", "DUI3-DX\\Sdk\\Speckle.Converters.Common\\Speckle.Converters.Common.csproj" ] } diff --git a/DUI3-DX/Connectors/Autocad/Speckle.Connectors.Autocad2023/packages.lock.json b/DUI3-DX/Connectors/Autocad/Speckle.Connectors.Autocad2023/packages.lock.json index df67e2ad73..68bcf35809 100644 --- a/DUI3-DX/Connectors/Autocad/Speckle.Connectors.Autocad2023/packages.lock.json +++ b/DUI3-DX/Connectors/Autocad/Speckle.Connectors.Autocad2023/packages.lock.json @@ -272,42 +272,11 @@ "Serilog": "2.10.0" } }, - "Speckle.Core": { - "type": "Transitive", - "resolved": "3.0.1-alpha.11", - "contentHash": "Zt2dBJLlfziEACYCHThbhKypSjhoA01rTw9BzNI72c/BDyftXIz70Tetq/8ZMEqQnKqfmRyYADsAdWKxpdV0Hg==", - "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.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.Newtonsoft.Json": { "type": "Transitive", "resolved": "13.0.2", "contentHash": "g1BejUZwax5PRfL6xHgLEK23sqHWOgOj9hE7RvfRRlN00AGt8GnPYt8HedSK7UB3HiRW8zCA9Pn0iiYxCK24BA==" }, - "Speckle.Objects": { - "type": "Transitive", - "resolved": "3.0.1-alpha.11", - "contentHash": "YR7sei3OQBAi8R/kIu8bEmg5ELDIJK6l5fhOgdnqA9ZvD/fvmRb+09z8lIUTDsgdAdvYU/A/x9VxH9OGPbp9Kw==", - "dependencies": { - "Speckle.Core": "3.0.1-alpha.11" - } - }, "SQLitePCLRaw.bundle_e_sqlite3": { "type": "Transitive", "resolved": "2.1.4", diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.Revit2023/packages.lock.json b/DUI3-DX/Connectors/Revit/Speckle.Connectors.Revit2023/packages.lock.json index 99af7ef77d..0a002c7391 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.Revit2023/packages.lock.json +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.Revit2023/packages.lock.json @@ -90,21 +90,6 @@ "resolved": "6.0.0", "contentHash": "yg72rrYDapfsIUrul7aF6wwNnTJBOFvuA9VdDTQpPa8AlAriHbufeXYLBcodKjfUdkCnaiggX1U/nEP08Zb5GA==" }, - "Mapster": { - "type": "Transitive", - "resolved": "7.3.0", - "contentHash": "NrCUX/rJa5PTyo6iW4AL5dZLU9PDNlYnrJOVjgdpo5OQM9EtWH2CMHnC5sSuJWC0d0b0SnmeRrIviEem6WxtuQ==", - "dependencies": { - "Mapster.Core": "1.2.0", - "Microsoft.CSharp": "4.3.0", - "System.Reflection.Emit": "4.3.0" - } - }, - "Mapster.Core": { - "type": "Transitive", - "resolved": "1.2.0", - "contentHash": "TNdqZk2zAuBYfJF88D/3clQTOyOdqr1crU81yZQtlGa+e7FYWhJdK/buBWT+TpM3qQko9UzmzfOT4iq3JCs/ZA==" - }, "Microsoft.Bcl.AsyncInterfaces": { "type": "Transitive", "resolved": "7.0.0", @@ -310,11 +295,6 @@ "resolved": "13.0.2", "contentHash": "g1BejUZwax5PRfL6xHgLEK23sqHWOgOj9hE7RvfRRlN00AGt8GnPYt8HedSK7UB3HiRW8zCA9Pn0iiYxCK24BA==" }, - "Speckle.Revit.API": { - "type": "Transitive", - "resolved": "2023.0.0", - "contentHash": "tq40eD7psgTbV+epNouYyqfo6+hEi7FmXZqcxEOsAV7zfYyWhL6Rt3vmojkWGNuerGbH6oRI6KIIxrnlCNb8Hw==" - }, "SQLitePCLRaw.bundle_e_sqlite3": { "type": "Transitive", "resolved": "2.1.4", @@ -407,11 +387,6 @@ "System.Threading.Tasks.Extensions": "4.5.4" } }, - "System.Reflection.Emit": { - "type": "Transitive", - "resolved": "4.3.0", - "contentHash": "228FG0jLcIwTVJyz8CLFKueVqQK36ANazUManGaJHkO0icjiIypKW7YLWLIWahyIkdh5M7mV2dJepllLyA1SKg==" - }, "System.Reflection.Metadata": { "type": "Transitive", "resolved": "5.0.0", @@ -509,7 +484,7 @@ "type": "Project", "dependencies": { "Speckle.Converters.Common": "[2.0.999-local, )", - "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.28, )" + "Speckle.Revit.API": "[2023.0.0, )" } }, "speckle.converters.revit2023.dependencyinjection": { @@ -517,8 +492,7 @@ "dependencies": { "Speckle.Converters.Common": "[2.0.999-local, )", "Speckle.Converters.Common.DependencyInjection": "[2.0.999-local, )", - "Speckle.Converters.Revit2023": "[2.0.999-local, )", - "Speckle.Revit2023.Api": "[0.1.1-preview.0.28, )" + "Speckle.Converters.Revit2023": "[2.0.999-local, )" } }, "Microsoft.Extensions.Logging.Abstractions": { @@ -574,22 +548,11 @@ "Speckle.Core": "3.0.1-alpha.11" } }, - "Speckle.Revit2023.Api": { - "type": "CentralTransitive", - "requested": "[0.1.1-preview.0.28, )", - "resolved": "0.1.1-preview.0.28", - "contentHash": "ejwYS/HI8yy0rJE4vgTr5aj8Fkg/E9JnMGjwyVS2fLtI4f7+FmwAY6inTUT2p/RAoRc2nQw+TerDpUtOhddzag==", - "dependencies": { - "Mapster": "7.3.0", - "Speckle.Revit.API": "2023.0.0", - "Speckle.Revit2023.Interfaces": "0.1.1-preview.0.28" - } - }, - "Speckle.Revit2023.Interfaces": { + "Speckle.Revit.API": { "type": "CentralTransitive", - "requested": "[0.1.1-preview.0.28, )", - "resolved": "0.1.1-preview.0.28", - "contentHash": "7szXg/vRvP3Wdrn2ZGriVOfsw+bddlpVorBkCIhSHHs5qVTTG8IAIrI1l9dO0/aullaTMF+Xgxm9x3w1aXPiuA==" + "requested": "[2023.0.0, )", + "resolved": "2023.0.0", + "contentHash": "tq40eD7psgTbV+epNouYyqfo6+hEi7FmXZqcxEOsAV7zfYyWhL6Rt3vmojkWGNuerGbH6oRI6KIIxrnlCNb8Hw==" }, "System.Threading.Tasks.Dataflow": { "type": "CentralTransitive", 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 ff27f05fb4..3aa6be233f 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.RevitShared.Helpers; 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 566cc9c41a..9774517d94 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.Connectors.RevitShared.Helpers; +using Speckle.Converters.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 8bd3033442..99e6492b79 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitSendBinding.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitSendBinding.cs @@ -3,12 +3,12 @@ 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; using Speckle.Connectors.DUI.Exceptions; using Speckle.Connectors.DUI.Models; -using Speckle.Connectors.RevitShared.Helpers; using Speckle.Connectors.Utils.Caching; using Speckle.Connectors.Utils.Cancellation; using Speckle.Connectors.Utils.Operations; 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 d60fe3ef27..c74a0606bd 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.RevitShared.Helpers; namespace Speckle.Connectors.Revit.Bindings; diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMapper.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMapper.cs deleted file mode 100644 index e4e997c4e2..0000000000 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMapper.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Speckle.Converters.Common; -using Speckle.ProxyGenerator; - -namespace Speckle.Connectors.Revit.DependencyInjection; - -public class ProxyMapper : IProxyMapper -{ - public Type? GetMappedTypeFromHostType(Type type) => ProxyMap.GetMappedTypeFromHostType(type); - - public Type? GetMappedTypeFromProxyType(Type type) => ProxyMap.GetMappedTypeFromProxyType(type); - - public Type? GetHostTypeFromMappedType(Type type) => ProxyMap.GetHostTypeFromMappedType(type); - - public object CreateProxy(Type type, object toWrap) => ProxyMap.CreateProxy(type, toWrap); - - public T CreateProxy(object toWrap) => ProxyMap.CreateProxy(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 879bf05041..ec1bcb5566 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/RevitConnectorModule.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/RevitConnectorModule.cs @@ -10,14 +10,10 @@ using Speckle.Connectors.Revit.HostApp; using Speckle.Connectors.Revit.Operations.Send; using Speckle.Connectors.Revit.Plugin; -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.Api; -using Speckle.Revit.Interfaces; namespace Speckle.Connectors.Revit.DependencyInjection; @@ -29,11 +25,7 @@ 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.ScanAssemblyOfType(); + //builder.AddDUIView(); builder.AddSingletonInstance(); diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Helpers/RevitConversionContextStack.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Helpers/RevitConversionContextStack.cs deleted file mode 100644 index d5461e7f60..0000000000 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Helpers/RevitConversionContextStack.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Autodesk.Revit.DB; -using Speckle.Converters.Common; -using Speckle.Revit.Api; -using Speckle.Revit.Interfaces; - -namespace Speckle.Connectors.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, - 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 - ) { } - - ContextWrapper IConversionContextStack.Push( - string speckleUnit - ) => throw new NotImplementedException(); -} 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 ba9b7d8db3..42acdc95ca 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/HostApp/RevitDocumentStore.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/HostApp/RevitDocumentStore.cs @@ -7,8 +7,8 @@ using Speckle.Connectors.DUI.Bridge; using Speckle.Connectors.DUI.Models; using Speckle.Connectors.Revit.Plugin; -using Speckle.Connectors.RevitShared.Helpers; using Speckle.Connectors.Utils; +using Speckle.Converters.RevitShared.Helpers; 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 417478e952..df84c9218e 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,13 +3,12 @@ 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; @@ -17,14 +16,14 @@ public class RevitRootObjectBuilder : IRootObjectBuilder { // POC: SendSelection and RevitConversionContextStack should be interfaces, former needs interfaces private readonly IRootToSpeckleConverter _converter; - private readonly IConversionContextStack _contextStack; + private readonly IRevitConversionContextStack _contextStack; private readonly Dictionary _collectionCache; private readonly Collection _rootObject; private readonly ISendConversionCache _sendConversionCache; public RevitRootObjectBuilder( IRootToSpeckleConverter converter, - IConversionContextStack contextStack, + IRevitConversionContextStack contextStack, ISendConversionCache sendConversionCache ) { @@ -46,7 +45,7 @@ public RootObjectBuilderResult Build( CancellationToken ct = default ) { - var doc = ((DocumentProxy)_contextStack.Current.Document)._Instance; + var doc = _contextStack.Current.Document; if (doc.IsFamilyDocument) { @@ -57,7 +56,7 @@ public RootObjectBuilderResult Build( foreach (var id in objects) { - var el = doc.GetElement(id); + var el = _contextStack.Current.Document.GetElement(id); if (el != null) { revitElements.Add(el); 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 afe71b6f6d..6de43da0c7 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitExternalApplication.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitExternalApplication.cs @@ -1,5 +1,6 @@ using Autodesk.Revit.UI; using Speckle.Autofac.DependencyInjection; +using System.IO; using System.Reflection; using Speckle.Autofac; using Speckle.Connectors.Utils; @@ -31,7 +32,7 @@ public RevitExternalApplication() "2023", "Speckle New UI", "Revit", - new[] { System.IO.Path.GetDirectoryName(typeof(RevitExternalApplication).Assembly.Location) }, + new[] { Path.GetDirectoryName(typeof(RevitExternalApplication).Assembly.Location) }, "Revit Connector", "2023" //POC: app version? ); 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 6e3d0c4e5e..1b46efa267 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitIdleManager.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitIdleManager.cs @@ -2,7 +2,7 @@ using Autodesk.Revit.UI; using Autodesk.Revit.UI.Events; using Speckle.Connectors.DUI.Bridge; -using Speckle.Connectors.RevitShared.Helpers; +using Speckle.Converters.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 a46046dd45..13d3500b2f 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitPlugin.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitPlugin.cs @@ -5,11 +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 Speckle.Connectors.RevitShared.Helpers; +using System.IO; namespace Speckle.Connectors.Revit.Plugin; @@ -181,7 +182,7 @@ private void RegisterDockablePane() { try { - var assembly = Assembly.LoadFrom(System.IO.Path.Combine(path)); + var assembly = Assembly.LoadFrom(Path.Combine(path)); var icon = assembly.GetManifestResourceStream(sourceName); PngBitmapDecoder decoder = new(icon, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); ImageSource source = decoder.Frames[0]; 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 a479f3189b..8a671aefc9 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,7 +16,28 @@ - + + + + + + + + + + + + + + CefSharpPanel.xaml + + + + + + + + diff --git a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/DependencyInjection/ProxyMapper.cs b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/DependencyInjection/ProxyMapper.cs deleted file mode 100644 index dabeb71d95..0000000000 --- a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/DependencyInjection/ProxyMapper.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Speckle.Converters.Common; -using Speckle.ProxyGenerator; - -namespace Speckle.Connectors.Rhino7.DependencyInjection; - -public class ProxyMapper : IProxyMapper -{ - public Type? GetMappedTypeFromHostType(Type type) => ProxyMap.GetMappedTypeFromHostType(type); - - public Type? GetMappedTypeFromProxyType(Type type) => ProxyMap.GetMappedTypeFromProxyType(type); - - public Type? GetHostTypeFromMappedType(Type type) => ProxyMap.GetHostTypeFromMappedType(type); - - public object CreateProxy(Type type, object toWrap) => ProxyMap.CreateProxy(type, toWrap); - - public T CreateProxy(object toWrap) => ProxyMap.CreateProxy(toWrap); -} diff --git a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/DependencyInjection/RhinoConnectorModule.cs b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/DependencyInjection/RhinoConnectorModule.cs index 16cdc3a7de..7be48aa2b6 100644 --- a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/DependencyInjection/RhinoConnectorModule.cs +++ b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/DependencyInjection/RhinoConnectorModule.cs @@ -20,9 +20,7 @@ using Speckle.Connectors.Utils.Builders; using Speckle.Connectors.Utils.Caching; using Speckle.Connectors.Utils.Operations; -using Speckle.Converters.Common; using Speckle.Core.Models.GraphTraversal; -using Speckle.Rhino7.Api; namespace Speckle.Connectors.Rhino7.DependencyInjection; @@ -38,7 +36,6 @@ public void Load(SpeckleContainerBuilder builder) builder.AddConnectorUtils(); builder.AddDUI(); builder.AddDUIView(); - builder.ScanAssemblyOfType(); // POC: Overwriting the SyncToMainThread to SyncToCurrentThread for Rhino! builder.AddSingletonInstance(); @@ -47,7 +44,6 @@ public void Load(SpeckleContainerBuilder builder) builder.AddSingleton(); builder.AddSingleton(); builder.AddSingleton(); - builder.AddSingleton(); // Register bindings builder.AddSingleton(); diff --git a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/HostApp/RhinoContext.cs b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/HostApp/RhinoContext.cs new file mode 100644 index 0000000000..17b532035a --- /dev/null +++ b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/HostApp/RhinoContext.cs @@ -0,0 +1,8 @@ +using Rhino; + +namespace Speckle.Connectors.Rhino7.HostApp; + +public class RhinoContext +{ + public RhinoDoc Document { get; } = RhinoDoc.ActiveDoc; +} diff --git a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Operations/Receive/DisableRedrawScope.cs b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Operations/Receive/DisableRedrawScope.cs index 621bfa45ed..1182e5de7a 100644 --- a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Operations/Receive/DisableRedrawScope.cs +++ b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Operations/Receive/DisableRedrawScope.cs @@ -1,16 +1,16 @@ -using Speckle.Rhino7.Interfaces; +using Rhino.DocObjects.Tables; namespace Speckle.Connectors.Rhino7.Operations.Receive; /// -/// Helper class to disable within a scope +/// Helper class to disable within a scope /// public sealed class DisableRedrawScope : IDisposable { - private readonly IRhinoViewTable _viewTable; + private readonly ViewTable _viewTable; private readonly bool _returnToStatus; - public DisableRedrawScope(IRhinoViewTable viewTable, bool returnToStatus = true) + public DisableRedrawScope(ViewTable viewTable, bool returnToStatus = true) { _viewTable = viewTable; _returnToStatus = returnToStatus; diff --git a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Operations/Receive/RhinoHostObjectBuilder.cs b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Operations/Receive/RhinoHostObjectBuilder.cs index 6c73b9bd10..02f653f08a 100644 --- a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Operations/Receive/RhinoHostObjectBuilder.cs +++ b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Operations/Receive/RhinoHostObjectBuilder.cs @@ -1,32 +1,31 @@ using System.Diagnostics.Contracts; +using Rhino; +using Rhino.DocObjects; +using Rhino.Geometry; using Speckle.Connectors.Utils.Builders; using Speckle.Connectors.Utils.Conversion; using Speckle.Converters.Common; using Speckle.Core.Logging; using Speckle.Core.Models; using Speckle.Core.Models.GraphTraversal; -using Speckle.Rhino7.Interfaces; namespace Speckle.Connectors.Rhino7.Operations.Receive; public class RhinoHostObjectBuilder : IHostObjectBuilder { private readonly IRootToHostConverter _converter; - private readonly IConversionContextStack _contextStack; + private readonly IConversionContextStack _contextStack; private readonly GraphTraversal _traverseFunction; - private readonly IRhinoDocFactory _rhinoDocFactory; public RhinoHostObjectBuilder( IRootToHostConverter converter, - IConversionContextStack contextStack, - GraphTraversal traverseFunction, - IRhinoDocFactory rhinoDocFactory + IConversionContextStack contextStack, + GraphTraversal traverseFunction ) { _converter = converter; _contextStack = contextStack; _traverseFunction = traverseFunction; - _rhinoDocFactory = rhinoDocFactory; } public HostObjectBuilderResult Build( @@ -54,19 +53,15 @@ CancellationToken cancellationToken // POC: Potentially refactor out into an IObjectBaker. private HostObjectBuilderResult BakeObjects(IEnumerable objectsGraph, string baseLayerName) { - var doc = _contextStack.Current.Document; - var rootLayerIndex = _contextStack.Current.Document.Layers.Find( - Guid.Empty, - baseLayerName, - _rhinoDocFactory.UnsetIntIndex - ); + RhinoDoc doc = _contextStack.Current.Document; + var rootLayerIndex = _contextStack.Current.Document.Layers.Find(Guid.Empty, baseLayerName, RhinoMath.UnsetIntIndex); // POC: We could move this out into a separate service for testing and re-use. // Cleans up any previously received objects - if (rootLayerIndex != _rhinoDocFactory.UnsetIntIndex) + if (rootLayerIndex != RhinoMath.UnsetIntIndex) { - var documentLayer = doc.Layers[rootLayerIndex]; - var childLayers = documentLayer.GetChildren(); + Layer documentLayer = doc.Layers[rootLayerIndex]; + Layer[]? childLayers = documentLayer.GetChildren(); if (childLayers != null) { using var layerNoDraw = new DisableRedrawScope(doc.Views); @@ -82,7 +77,7 @@ private HostObjectBuilderResult BakeObjects(IEnumerable object } var cache = new Dictionary(); - rootLayerIndex = doc.Layers.Add(_rhinoDocFactory.CreateLayer(baseLayerName)); + rootLayerIndex = doc.Layers.Add(new Layer { Name = baseLayerName }); cache.Add(baseLayerName, rootLayerIndex); using var noDraw = new DisableRedrawScope(doc.Views); @@ -96,7 +91,7 @@ private HostObjectBuilderResult BakeObjects(IEnumerable object { var path = GetLayerPath(tc); - var fullLayerName = string.Join(_rhinoDocFactory.LayerPathSeparator, path); + var fullLayerName = string.Join(Layer.PathSeparator, path); var layerIndex = cache.TryGetValue(fullLayerName, out int value) ? value : GetAndCreateLayerFromPath(path, baseLayerName, cache); @@ -125,31 +120,31 @@ private IReadOnlyList HandleConversionResult(object conversionResult, Ba List newObjectIds = new(); switch (conversionResult) { - case IEnumerable list: + case IEnumerable list: { - var group = BakeObjectsAsGroup(originalObject.id, list, layerIndex); + Group group = BakeObjectsAsGroup(originalObject.id, list, layerIndex); newObjectIds.Add(group.Id.ToString()); break; } - case IRhinoGeometryBase newObject: + case GeometryBase newObject: { - var newObjectGuid = doc.Objects.Add(newObject, _rhinoDocFactory.CreateAttributes(layerIndex)); + var newObjectGuid = doc.Objects.Add(newObject, new ObjectAttributes { LayerIndex = layerIndex }); newObjectIds.Add(newObjectGuid.ToString()); break; } default: throw new SpeckleConversionException( - $"Unexpected result from conversion: Expected {nameof(IRhinoGeometryBase)} but instead got {conversionResult.GetType().Name}" + $"Unexpected result from conversion: Expected {nameof(GeometryBase)} but instead got {conversionResult.GetType().Name}" ); } return newObjectIds; } - private IRhinoGroup BakeObjectsAsGroup(string groupName, IEnumerable list, int layerIndex) + private Group BakeObjectsAsGroup(string groupName, IEnumerable list, int layerIndex) { var doc = _contextStack.Current.Document; - var objectIds = list.Select(obj => doc.Objects.Add(obj, _rhinoDocFactory.CreateAttributes(layerIndex))); + var objectIds = list.Select(obj => doc.Objects.Add(obj, new ObjectAttributes { LayerIndex = layerIndex })); var groupIndex = _contextStack.Current.Document.Groups.Add(groupName, objectIds); var group = _contextStack.Current.Document.Groups.FindIndex(groupIndex); return group; @@ -159,12 +154,12 @@ private IRhinoGroup BakeObjectsAsGroup(string groupName, IEnumerable cache) { var currentLayerName = baseLayerName; - var currentDocument = _contextStack.Current.Document; + RhinoDoc currentDocument = _contextStack.Current.Document; var previousLayer = currentDocument.Layers.FindName(currentLayerName); foreach (var layerName in path) { - currentLayerName = baseLayerName + _rhinoDocFactory.LayerPathSeparator + layerName; + currentLayerName = baseLayerName + Layer.PathSeparator + layerName; currentLayerName = currentLayerName.Replace("{", "").Replace("}", ""); // Rhino specific cleanup for gh (see RemoveInvalidRhinoChars) if (cache.TryGetValue(currentLayerName, out int value)) { @@ -173,7 +168,7 @@ private int GetAndCreateLayerFromPath(string[] path, string baseLayerName, Dicti } var cleanNewLayerName = layerName.Replace("{", "").Replace("}", ""); - var newLayer = _rhinoDocFactory.CreateLayer(cleanNewLayerName, previousLayer.Id); + var newLayer = new Layer { Name = cleanNewLayerName, ParentLayerId = previousLayer.Id }; var index = currentDocument.Layers.Add(newLayer); cache.Add(currentLayerName, index); previousLayer = currentDocument.Layers.FindIndex(index); // note we need to get the correct id out, hence why we're double calling this diff --git a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Speckle.Connectors.Rhino7.csproj b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Speckle.Connectors.Rhino7.csproj index e114f0d218..dbea907d5c 100644 --- a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Speckle.Connectors.Rhino7.csproj +++ b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Speckle.Connectors.Rhino7.csproj @@ -15,8 +15,6 @@ - - @@ -43,4 +41,5 @@ Resources.Designer.cs + diff --git a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/packages.lock.json b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/packages.lock.json index c8f0acc3ee..42b0399f3e 100644 --- a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/packages.lock.json +++ b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/packages.lock.json @@ -39,24 +39,6 @@ "resolved": "0.9.5", "contentHash": "oU/L7pN1R7q8KkbrpQ3WJnHirPHqn+9DEA7asOcUiggV5dzVg1A/VYs7GOSusD24njxXh03tE3a2oTLOjt3cVg==" }, - "Speckle.Rhino7.Api": { - "type": "Direct", - "requested": "[0.1.1-preview.0.28, )", - "resolved": "0.1.1-preview.0.28", - "contentHash": "AE+1lMl+lzwEdNn6kvEWuCy6wRSFAIYP0KXeGI8fECNsCBj023c4IE/wSVn7wIHD+nM2ZHcST/62dmZXNqUt5A==", - "dependencies": { - "Mapster": "7.3.0", - "RhinoCommon": "7.13.21348.13001", - "RhinoWindows": "7.13.21348.13001", - "Speckle.Rhino7.Interfaces": "0.1.1-preview.0.28" - } - }, - "Speckle.Rhino7.Interfaces": { - "type": "Direct", - "requested": "[0.1.1-preview.0.28, )", - "resolved": "0.1.1-preview.0.28", - "contentHash": "TcbfXlRMnQRat1JodgW+YW5FflTYem1GGo9DtKA+6iAuVaYagN5dxsrM5LE6M3pCnEV9rkEQOjFo7sgnnbo4mw==" - }, "System.Resources.Extensions": { "type": "Direct", "requested": "[7.0.0, )", @@ -98,21 +80,6 @@ "resolved": "6.0.0", "contentHash": "yg72rrYDapfsIUrul7aF6wwNnTJBOFvuA9VdDTQpPa8AlAriHbufeXYLBcodKjfUdkCnaiggX1U/nEP08Zb5GA==" }, - "Mapster": { - "type": "Transitive", - "resolved": "7.3.0", - "contentHash": "NrCUX/rJa5PTyo6iW4AL5dZLU9PDNlYnrJOVjgdpo5OQM9EtWH2CMHnC5sSuJWC0d0b0SnmeRrIviEem6WxtuQ==", - "dependencies": { - "Mapster.Core": "1.2.0", - "Microsoft.CSharp": "4.3.0", - "System.Reflection.Emit": "4.3.0" - } - }, - "Mapster.Core": { - "type": "Transitive", - "resolved": "1.2.0", - "contentHash": "TNdqZk2zAuBYfJF88D/3clQTOyOdqr1crU81yZQtlGa+e7FYWhJdK/buBWT+TpM3qQko9UzmzfOT4iq3JCs/ZA==" - }, "Microsoft.Bcl.AsyncInterfaces": { "type": "Transitive", "resolved": "7.0.0", @@ -318,6 +285,11 @@ "resolved": "13.0.2", "contentHash": "g1BejUZwax5PRfL6xHgLEK23sqHWOgOj9hE7RvfRRlN00AGt8GnPYt8HedSK7UB3HiRW8zCA9Pn0iiYxCK24BA==" }, + "Speckle.Revit2023.Interfaces": { + "type": "Transitive", + "resolved": "0.1.1-preview.0.24", + "contentHash": "BSVpOUJc9g6ISrw8GxvtkglTlITpHEDYNOhxv1ZPbckBsI0yO36JiphhQV4q57ERqD9PpCozUJkVhlCaxWeS6A==" + }, "SQLitePCLRaw.bundle_e_sqlite3": { "type": "Transitive", "resolved": "2.1.4", @@ -410,11 +382,6 @@ "System.Threading.Tasks.Extensions": "4.5.4" } }, - "System.Reflection.Emit": { - "type": "Transitive", - "resolved": "4.3.0", - "contentHash": "228FG0jLcIwTVJyz8CLFKueVqQK36ANazUManGaJHkO0icjiIypKW7YLWLIWahyIkdh5M7mV2dJepllLyA1SKg==" - }, "System.Reflection.Metadata": { "type": "Transitive", "resolved": "5.0.0", @@ -518,7 +485,7 @@ "speckle.converters.rhino7.dependencyinjection": { "type": "Project", "dependencies": { - "Speckle.Rhino7.Interfaces": "[0.1.1-preview.0.28, )" + "RhinoCommon": "[7.13.21348.13001, )" } }, "Microsoft.Extensions.Logging.Abstractions": { diff --git a/DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3.DependencyInjection/ArcGISConverterModule.cs b/DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3.DependencyInjection/ArcGISConverterModule.cs index 88d26d8166..30a739310b 100644 --- a/DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3.DependencyInjection/ArcGISConverterModule.cs +++ b/DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3.DependencyInjection/ArcGISConverterModule.cs @@ -11,7 +11,7 @@ public class ArcGISConverterModule : ISpeckleModule public void Load(SpeckleContainerBuilder builder) { //don't need a host specific RootToSpeckleConverter - builder.AddConverterCommon(); + builder.AddConverterCommon(); // most things should be InstancePerLifetimeScope so we get one per operation builder.AddScoped(); builder.AddScoped(); diff --git a/DUI3-DX/Converters/Autocad/2024/Speckle.Converters.Autocad2024/packages.lock.json b/DUI3-DX/Converters/Autocad/2024/Speckle.Converters.Autocad2024/packages.lock.json index 66a0d5e333..5ef4059ca1 100644 --- a/DUI3-DX/Converters/Autocad/2024/Speckle.Converters.Autocad2024/packages.lock.json +++ b/DUI3-DX/Converters/Autocad/2024/Speckle.Converters.Autocad2024/packages.lock.json @@ -211,42 +211,11 @@ "Serilog": "2.10.0" } }, - "Speckle.Core": { - "type": "Transitive", - "resolved": "3.0.1-alpha.11", - "contentHash": "Zt2dBJLlfziEACYCHThbhKypSjhoA01rTw9BzNI72c/BDyftXIz70Tetq/8ZMEqQnKqfmRyYADsAdWKxpdV0Hg==", - "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.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.Newtonsoft.Json": { "type": "Transitive", "resolved": "13.0.2", "contentHash": "g1BejUZwax5PRfL6xHgLEK23sqHWOgOj9hE7RvfRRlN00AGt8GnPYt8HedSK7UB3HiRW8zCA9Pn0iiYxCK24BA==" }, - "Speckle.Objects": { - "type": "Transitive", - "resolved": "3.0.1-alpha.11", - "contentHash": "YR7sei3OQBAi8R/kIu8bEmg5ELDIJK6l5fhOgdnqA9ZvD/fvmRb+09z8lIUTDsgdAdvYU/A/x9VxH9OGPbp9Kw==", - "dependencies": { - "Speckle.Core": "3.0.1-alpha.11" - } - }, "SQLitePCLRaw.bundle_e_sqlite3": { "type": "Transitive", "resolved": "2.1.4", 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 7900f25180..60c5050217 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,10 @@ +using Autodesk.Revit.DB; using Speckle.Autofac.DependencyInjection; -using Speckle.Converters.Common; using Speckle.Converters.Common.DependencyInjection; 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; @@ -13,21 +12,24 @@ 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(); - 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(); } } 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 a4ecb27491..704fef95ed 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,9 +5,6 @@ x64 - - - diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/packages.lock.json b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/packages.lock.json index 928fe09a85..a1186a3a61 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/packages.lock.json +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/packages.lock.json @@ -24,17 +24,6 @@ "resolved": "0.9.5", "contentHash": "oU/L7pN1R7q8KkbrpQ3WJnHirPHqn+9DEA7asOcUiggV5dzVg1A/VYs7GOSusD24njxXh03tE3a2oTLOjt3cVg==" }, - "Speckle.Revit2023.Api": { - "type": "Direct", - "requested": "[0.1.1-preview.0.28, )", - "resolved": "0.1.1-preview.0.28", - "contentHash": "ejwYS/HI8yy0rJE4vgTr5aj8Fkg/E9JnMGjwyVS2fLtI4f7+FmwAY6inTUT2p/RAoRc2nQw+TerDpUtOhddzag==", - "dependencies": { - "Mapster": "7.3.0", - "Speckle.Revit.API": "2023.0.0", - "Speckle.Revit2023.Interfaces": "0.1.1-preview.0.28" - } - }, "GraphQL.Client": { "type": "Transitive", "resolved": "6.0.0", @@ -67,21 +56,6 @@ "resolved": "6.0.0", "contentHash": "yg72rrYDapfsIUrul7aF6wwNnTJBOFvuA9VdDTQpPa8AlAriHbufeXYLBcodKjfUdkCnaiggX1U/nEP08Zb5GA==" }, - "Mapster": { - "type": "Transitive", - "resolved": "7.3.0", - "contentHash": "NrCUX/rJa5PTyo6iW4AL5dZLU9PDNlYnrJOVjgdpo5OQM9EtWH2CMHnC5sSuJWC0d0b0SnmeRrIviEem6WxtuQ==", - "dependencies": { - "Mapster.Core": "1.2.0", - "Microsoft.CSharp": "4.3.0", - "System.Reflection.Emit": "4.3.0" - } - }, - "Mapster.Core": { - "type": "Transitive", - "resolved": "1.2.0", - "contentHash": "TNdqZk2zAuBYfJF88D/3clQTOyOdqr1crU81yZQtlGa+e7FYWhJdK/buBWT+TpM3qQko9UzmzfOT4iq3JCs/ZA==" - }, "Microsoft.Bcl.AsyncInterfaces": { "type": "Transitive", "resolved": "5.0.0", @@ -236,11 +210,6 @@ "resolved": "13.0.2", "contentHash": "g1BejUZwax5PRfL6xHgLEK23sqHWOgOj9hE7RvfRRlN00AGt8GnPYt8HedSK7UB3HiRW8zCA9Pn0iiYxCK24BA==" }, - "Speckle.Revit.API": { - "type": "Transitive", - "resolved": "2023.0.0", - "contentHash": "tq40eD7psgTbV+epNouYyqfo6+hEi7FmXZqcxEOsAV7zfYyWhL6Rt3vmojkWGNuerGbH6oRI6KIIxrnlCNb8Hw==" - }, "SQLitePCLRaw.bundle_e_sqlite3": { "type": "Transitive", "resolved": "2.1.4", @@ -324,11 +293,6 @@ "System.Threading.Tasks.Extensions": "4.5.4" } }, - "System.Reflection.Emit": { - "type": "Transitive", - "resolved": "4.3.0", - "contentHash": "228FG0jLcIwTVJyz8CLFKueVqQK36ANazUManGaJHkO0icjiIypKW7YLWLIWahyIkdh5M7mV2dJepllLyA1SKg==" - }, "System.Reflection.Metadata": { "type": "Transitive", "resolved": "5.0.0", @@ -408,7 +372,7 @@ "type": "Project", "dependencies": { "Speckle.Converters.Common": "[2.0.999-local, )", - "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.28, )" + "Speckle.Revit.API": "[2023.0.0, )" } }, "Microsoft.Extensions.Logging.Abstractions": { @@ -454,11 +418,11 @@ "Speckle.Core": "3.0.1-alpha.11" } }, - "Speckle.Revit2023.Interfaces": { + "Speckle.Revit.API": { "type": "CentralTransitive", - "requested": "[0.1.1-preview.0.28, )", - "resolved": "0.1.1-preview.0.28", - "contentHash": "7szXg/vRvP3Wdrn2ZGriVOfsw+bddlpVorBkCIhSHHs5qVTTG8IAIrI1l9dO0/aullaTMF+Xgxm9x3w1aXPiuA==" + "requested": "[2023.0.0, )", + "resolved": "2023.0.0", + "contentHash": "tq40eD7psgTbV+epNouYyqfo6+hEi7FmXZqcxEOsAV7zfYyWhL6Rt3vmojkWGNuerGbH6oRI6KIIxrnlCNb8Hw==" } } } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/LocationConversionToSpeckleTests.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/LocationConversionToSpeckleTests.cs deleted file mode 100644 index 6fb5ba34d3..0000000000 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/LocationConversionToSpeckleTests.cs +++ /dev/null @@ -1,85 +0,0 @@ -using FluentAssertions; -using Moq; -using NUnit.Framework; -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.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.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 deleted file mode 100644 index 2839be1e72..0000000000 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/Speckle.Converters.Revit2023.Tests.csproj +++ /dev/null @@ -1,27 +0,0 @@ - - - - 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 deleted file mode 100644 index 2c05f6ade3..0000000000 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/packages.lock.json +++ /dev/null @@ -1,560 +0,0 @@ -{ - "version": 2, - "dependencies": { - ".NETFramework,Version=v4.8": { - "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, )", - "resolved": "17.10.0", - "contentHash": "0/2HeACkaHEYU3wc83YlcD2Fi4LMtECJjqrtvw0lPi9DCEa35zSPt1j4fuvM8NagjDqJuh1Ja35WcRtn1Um6/A==", - "dependencies": { - "Microsoft.CodeCoverage": "17.10.0" - } - }, - "Microsoft.SourceLink.GitHub": { - "type": "Direct", - "requested": "[8.0.0, )", - "resolved": "8.0.0", - "contentHash": "G5q7OqtwIyGTkeIOAc3u2ZuV/kicQaec5EaRnc0pIeSnh9LUjj+PYQrJYBURvDt7twGl2PKA7nSN0kz1Zw5bnQ==", - "dependencies": { - "Microsoft.Build.Tasks.Git": "8.0.0", - "Microsoft.SourceLink.Common": "8.0.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==" - }, - "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.28, )", - "resolved": "0.1.1-preview.0.28", - "contentHash": "7szXg/vRvP3Wdrn2ZGriVOfsw+bddlpVorBkCIhSHHs5qVTTG8IAIrI1l9dO0/aullaTMF+Xgxm9x3w1aXPiuA==" - }, - "Castle.Core": { - "type": "Transitive", - "resolved": "5.1.1", - "contentHash": "rpYtIczkzGpf+EkZgDr9CClTdemhsrwA/W5hMoPjLkRFnXzH44zDLoovXeKtmxb1ykXK9aJVODSpiJml8CTw2g==" - }, - "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.Build.Tasks.Git": { - "type": "Transitive", - "resolved": "8.0.0", - "contentHash": "bZKfSIKJRXLTuSzLudMFte/8CempWjVamNUR5eHJizsy+iuOuO/k2gnh7W0dHJmYY0tBf+gUErfluCv5mySAOQ==" - }, - "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.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" - } - }, - "Microsoft.SourceLink.Common": { - "type": "Transitive", - "resolved": "8.0.0", - "contentHash": "dk9JPxTCIevS75HyEQ0E4OVAFhB2N+V9ShCXf8Q6FkUQZDkgLI12y679Nym1YqsiSysuQskT7Z+6nUf3yab6Vw==" - }, - "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.Exceptions": { - "type": "Transitive", - "resolved": "8.4.0", - "contentHash": "nc/+hUw3lsdo0zCj0KMIybAu7perMx79vu72w0za9Nsi6mWyNkGXxYxakAjWB7nEmYL6zdmhEQRB4oJ2ALUeug==", - "dependencies": { - "Serilog": "2.8.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.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.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.connectors.utils": { - "type": "Project", - "dependencies": { - "Serilog.Extensions.Logging": "[7.0.0, )", - "Speckle.Autofac": "[2.0.999-local, )", - "Speckle.Core": "[3.0.1-alpha.11, )" - } - }, - "speckle.converters.common": { - "type": "Project", - "dependencies": { - "Speckle.Autofac": "[2.0.999-local, )", - "Speckle.Objects": "[3.0.1-alpha.11, )" - } - }, - "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.28, )" - } - }, - "Microsoft.Extensions.Logging.Abstractions": { - "type": "CentralTransitive", - "requested": "[7.0.0, )", - "resolved": "7.0.0", - "contentHash": "kmn78+LPVMOWeITUjIlfxUPDsI0R6G0RkeAMBmQxAJ7vBJn4q2dTva7pWi65ceN5vPGjJ9q/Uae2WKgvfktJAw==", - "dependencies": { - "System.Buffers": "4.5.1", - "System.Memory": "4.5.5" - } - }, - "Serilog.Extensions.Logging": { - "type": "CentralTransitive", - "requested": "[7.0.0, )", - "resolved": "7.0.0", - "contentHash": "9faU0zNQqU7I6soVhLUMYaGNpgWv6cKlKb2S5AnS8gXxzW/em5Ladm/6FMrWTnX41cdbdGPOWNAo6adi4WaJ6A==", - "dependencies": { - "Microsoft.Extensions.Logging": "7.0.0", - "Serilog": "2.12.0" - } - }, - "Speckle.Core": { - "type": "CentralTransitive", - "requested": "[3.0.1-alpha.11, )", - "resolved": "3.0.1-alpha.11", - "contentHash": "Zt2dBJLlfziEACYCHThbhKypSjhoA01rTw9BzNI72c/BDyftXIz70Tetq/8ZMEqQnKqfmRyYADsAdWKxpdV0Hg==", - "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.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": "CentralTransitive", - "requested": "[3.0.1-alpha.11, )", - "resolved": "3.0.1-alpha.11", - "contentHash": "YR7sei3OQBAi8R/kIu8bEmg5ELDIJK6l5fhOgdnqA9ZvD/fvmRb+09z8lIUTDsgdAdvYU/A/x9VxH9OGPbp9Kw==", - "dependencies": { - "Speckle.Core": "3.0.1-alpha.11" - } - } - } - } -} \ 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 new file mode 100644 index 0000000000..515c2e057f --- /dev/null +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/RevitVersionConversionHelper.cs @@ -0,0 +1,19 @@ +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 e3c04fcf68..985086abd5 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,13 +3,12 @@ net48 x64 - false - + diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/packages.lock.json b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/packages.lock.json index 220a146664..0fbae10307 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/packages.lock.json +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/packages.lock.json @@ -24,11 +24,11 @@ "resolved": "0.9.5", "contentHash": "oU/L7pN1R7q8KkbrpQ3WJnHirPHqn+9DEA7asOcUiggV5dzVg1A/VYs7GOSusD24njxXh03tE3a2oTLOjt3cVg==" }, - "Speckle.Revit2023.Interfaces": { + "Speckle.Revit.API": { "type": "Direct", - "requested": "[0.1.1-preview.0.28, )", - "resolved": "0.1.1-preview.0.28", - "contentHash": "7szXg/vRvP3Wdrn2ZGriVOfsw+bddlpVorBkCIhSHHs5qVTTG8IAIrI1l9dO0/aullaTMF+Xgxm9x3w1aXPiuA==" + "requested": "[2023.0.0, )", + "resolved": "2023.0.0", + "contentHash": "tq40eD7psgTbV+epNouYyqfo6+hEi7FmXZqcxEOsAV7zfYyWhL6Rt3vmojkWGNuerGbH6oRI6KIIxrnlCNb8Hw==" }, "GraphQL.Client": { "type": "Transitive", 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 c0acca23c8..9083375a2e 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 Speckle.Revit.Interfaces; +using Autodesk.Revit.DB; namespace Speckle.Converters.RevitShared.Extensions; public static class CategoryExtensions { - public static SOBR.RevitCategory GetSchemaBuilderCategoryFromBuiltIn(this RevitBuiltInCategory builtInCategory) + public static SOBR.RevitCategory GetSchemaBuilderCategoryFromBuiltIn(this DB.BuiltInCategory 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 RevitB return cat; } - public static RevitBuiltInCategory GetBuiltInCategory(this IRevitCategory category) + public static BuiltInCategory GetBuiltInCategory(this Category category) { - return (RevitBuiltInCategory)category.Id.IntegerValue; + return (BuiltInCategory)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 1b3a22beda..77aff9d11b 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Extensions/DefinitionExtensions.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Extensions/DefinitionExtensions.cs @@ -1,12 +1,16 @@ -using Speckle.Revit.Interfaces; +using Autodesk.Revit.DB; 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 IRevitDefinition definition) + public static string GetUnitTypeString(this Definition 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 e8553e34cb..468a98fd0f 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Extensions/ElementExtensions.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Extensions/ElementExtensions.cs @@ -1,31 +1,30 @@ -using Speckle.Revit.Interfaces; +using Autodesk.Revit.DB; namespace Speckle.Converters.RevitShared.Extensions; public static class ElementExtensions { // POC: should this be an injected service? - public static IList GetHostedElementIds(this IRevitElement host, IRevitFilterFactory filterFactory) + public static IList GetHostedElementIds(this Element host) { - IList ids; - var hostObject = host.ToHostObject(); - if (hostObject is not null) + IList ids; + if (host is HostObject hostObject) { ids = hostObject.FindInserts(true, false, false, false); } else { - var typeFilter = filterFactory.CreateElementIsElementTypeFilter(true); - var categoryFilter = filterFactory.CreateElementMulticategoryFilter( - new List() + var typeFilter = new ElementIsElementTypeFilter(true); + var categoryFilter = new ElementMulticategoryFilter( + new List() { - RevitBuiltInCategory.OST_CLines, - RevitBuiltInCategory.OST_SketchLines, - RevitBuiltInCategory.OST_WeakDims + BuiltInCategory.OST_CLines, + BuiltInCategory.OST_SketchLines, + BuiltInCategory.OST_WeakDims }, true ); - ids = host.GetDependentElements(filterFactory.CreateLogicalAndFilter(typeFilter, categoryFilter)); + ids = host.GetDependentElements(new LogicalAndFilter(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 1c9d03b5a1..790e92a07a 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 Speckle.Revit.Interfaces; +using Autodesk.Revit.DB; namespace Speckle.Converters.RevitShared.Extensions; public static class ForgeTypeIdExtensions { - public static string? GetSymbol(this IRevitForgeTypeId forgeTypeId, IRevitFormatOptionsUtils formatOptionsUtils) + public static string? GetSymbol(this ForgeTypeId forgeTypeId) { - if (!formatOptionsUtils.CanHaveSymbol(forgeTypeId)) + if (!FormatOptions.CanHaveSymbol(forgeTypeId)) { return null; } - var validSymbols = formatOptionsUtils.GetValidSymbols(forgeTypeId); + var validSymbols = FormatOptions.GetValidSymbols(forgeTypeId); var typeId = validSymbols.Where(x => !x.Empty()); - foreach (var symbolId in typeId) + foreach (DB.ForgeTypeId symbolId in typeId) { - return formatOptionsUtils.GetLabelForSymbol(symbolId); + return LabelUtils.GetLabelForSymbol(symbolId); } return null; } - public static string ToUniqueString(this IRevitForgeTypeId forgeTypeId) + public static string ToUniqueString(this ForgeTypeId 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 704eb40484..c8ac6f92e8 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Extensions/ParameterExtensions.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Extensions/ParameterExtensions.cs @@ -1,5 +1,4 @@ -using Speckle.Converters.Common; -using Speckle.Revit.Interfaces; +using Autodesk.Revit.DB; namespace Speckle.Converters.RevitShared.Extensions; @@ -11,7 +10,7 @@ public static class ParameterExtensions /// /// /// - public static string GetInternalName(this IRevitParameter rp) + public static string GetInternalName(this DB.Parameter rp) { if (rp.IsShared) { @@ -19,8 +18,8 @@ public static string GetInternalName(this IRevitParameter rp) } else { - var def = rp.Definition.ToInternal().NotNull(); - if (def.BuiltInParameter == RevitBuiltInParameter.INVALID) + var def = (InternalDefinition)rp.Definition; + if (def.BuiltInParameter == BuiltInParameter.INVALID) { return def.Name; } @@ -29,9 +28,9 @@ public static string GetInternalName(this IRevitParameter rp) } } - public static RevitBuiltInParameter? GetBuiltInParameter(this IRevitParameter rp) + public static BuiltInParameter? GetBuiltInParameter(this Parameter rp) { - var def = rp.Definition.ToInternal(); + var def = rp.Definition as InternalDefinition; 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 a4a6c2cf0d..5a7a8f20bd 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/GlobalUsings.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/GlobalUsings.cs @@ -1,3 +1,5 @@ -global using SOG = Objects.Geometry; +global using DB = Autodesk.Revit.DB; +global using DBA = Autodesk.Revit.DB.Architecture; +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 d292b5ed2f..7980fa5b02 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/DisplayValueExtractor.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/DisplayValueExtractor.cs @@ -1,53 +1,38 @@ -using System.Diagnostics.CodeAnalysis; using Microsoft.Extensions.Logging; -using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.InterfaceGenerator; -using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared.Helpers; // POC: needs breaking down https://spockle.atlassian.net/browse/CNX-9354 -[GenerateAutoInterface] -public sealed class DisplayValueExtractor : IDisplayValueExtractor +public sealed class DisplayValueExtractor { - private readonly ITypedConverter< - Dictionary>, - List - > _meshByMaterialConverter; - private readonly IRevitOptionsFactory _revitOptionsFactory; - private readonly IRevitSolidUtils _revitSolidUtils; + private readonly ITypedConverter>, List> _meshByMaterialConverter; private readonly ILogger _logger; public DisplayValueExtractor( - ITypedConverter>, List> meshByMaterialConverter, - IRevitOptionsFactory revitOptionsFactory, - IRevitSolidUtils revitSolidUtils, + ITypedConverter>, List> meshByMaterialConverter, ILogger logger ) { _meshByMaterialConverter = meshByMaterialConverter; - _revitOptionsFactory = revitOptionsFactory; - _revitSolidUtils = revitSolidUtils; _logger = logger; } public List GetDisplayValue( - IRevitElement element, - IRevitOptions? options = null, + DB.Element element, + DB.Options? options = null, // POC: should this be part of the context? - IRevitTransform? transform = null + DB.Transform? transform = null ) { var displayMeshes = new List(); // test if the element is a group first - var g = element.ToGroup(); - if (g is not null) + if (element is DB.Group g) { foreach (var id in g.GetMemberIds()) { - var groupMeshes = GetDisplayValue(element.Document.GetElement(id).NotNull(), options); + var groupMeshes = GetDisplayValue(element.Document.GetElement(id), options); displayMeshes.AddRange(groupMeshes); } return displayMeshes; @@ -60,18 +45,18 @@ ILogger logger 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; } @@ -80,12 +65,12 @@ List solids foreach (var solid in solids) { - foreach (IRevitFace face in solid.Faces) + foreach (DB.Face 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; } @@ -96,30 +81,29 @@ List solids return meshesByMaterial; } - [SuppressMessage("Design", "CA1031:Do not catch general exception types")] - private (List, List) GetSolidsAndMeshesFromElement( - IRevitElement element, - IRevitOptions? options, - IRevitTransform? transform = null + private (List, List) GetSolidsAndMeshesFromElement( + DB.Element element, + DB.Options? options, + DB.Transform? transform = null ) { //options = ViewSpecificOptions ?? options ?? new Options() { DetailLevel = DetailLevelSetting }; - options ??= _revitOptionsFactory.Create(RevitViewDetailLevel.Fine); + options ??= new DB.Options { DetailLevel = DB.ViewDetailLevel.Fine }; - IRevitGeometryElement? geom; + DB.GeometryElement geom; try { - geom = element.GetGeometry(options); + geom = element.get_Geometry(options); } // POC: should we be trying to continue? - catch (Exception) + catch (Autodesk.Revit.Exceptions.ArgumentException) { options.ComputeReferences = false; - geom = element.GetGeometry(options); + geom = element.get_Geometry(options); } - var solids = new List(); - var meshes = new List(); + var solids = new List(); + var meshes = new List(); if (geom != null) { @@ -147,11 +131,11 @@ List solids /// /// private void SortGeometry( - IRevitElement element, - List solids, - List meshes, - IRevitGeometryElement geom, - IRevitTransform? inverseTransform = null + DB.Element element, + List solids, + List meshes, + DB.GeometryElement geom, + DB.Transform? inverseTransform = null ) { var topLevelSolidsCount = 0; @@ -160,36 +144,32 @@ private void SortGeometry( var topLevelGeomInstanceCount = 0; bool hasSymbolGeometry = false; - foreach (IRevitGeometryObject geomObj in geom) + foreach (DB.GeometryObject geomObj in geom) { // POC: switch could possibly become factory and IIndex<,> pattern and move conversions to // separate IComeConversionInterfaces - var solid = geomObj.ToSolid(); - if (solid is not null) + switch (geomObj) { - // skip invalid solid - if ( - solid.Faces.Count == 0 - || Math.Abs(solid.SurfaceArea) == 0 - || IsSkippableGraphicStyle(solid.GraphicsStyleId, element.Document) - ) - { - continue; - } + case DB.Solid solid: + // skip invalid solid + if ( + solid.Faces.Size == 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 = DB.SolidUtils.CreateTransformed(solid, inverseTransform); + } - solids.Add(solid); - } - else - { - var mesh = geomObj.ToMesh(); - if (mesh is not null) - { + solids.Add(solid); + break; + case DB.Mesh mesh: if (IsSkippableGraphicStyle(mesh.GraphicsStyleId, element.Document)) { continue; @@ -198,46 +178,35 @@ private void SortGeometry( if (inverseTransform != null) { topLevelMeshesCount++; - mesh = mesh.GetTransformed(inverseTransform); + mesh = mesh.get_Transformed(inverseTransform); } meshes.Add(mesh); - } - else - { - var instance = geomObj.ToGeometryInstance(); - if (instance is not null) + break; + case DB.GeometryInstance 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) { - // element transforms should not be carried down into nested geometryInstances. - // Nested geomInstances should have their geom retreived with GetInstanceGeom, not GetSymbolGeom - if (inverseTransform != null) - { - topLevelGeomInstanceCount++; - SortGeometry(element, solids, meshes, instance.GetSymbolGeometry()); - if (meshes.Count > 0 || solids.Count > 0) - { - hasSymbolGeometry = true; - } - } - else + topLevelGeomInstanceCount++; + SortGeometry(element, solids, meshes, instance.GetSymbolGeometry()); + if (meshes.Count > 0 || solids.Count > 0) { - SortGeometry(element, solids, meshes, instance.GetInstanceGeometry()); + hasSymbolGeometry = true; } } else { - var geometryElement = geomObj.ToGeometryElement(); - if (geometryElement is not null) - { - if (inverseTransform != null) - { - topLevelGeomElementCount++; - } - - SortGeometry(element, solids, meshes, geometryElement); - } + SortGeometry(element, solids, meshes, instance.GetInstanceGeometry()); } - } + break; + case DB.GeometryElement geometryElement: + if (inverseTransform != null) + { + topLevelGeomElementCount++; + } + SortGeometry(element, solids, meshes, geometryElement); + break; } } @@ -255,7 +224,7 @@ private void SortGeometry( // POC: should be hoovered up with the new reporting, logging, exception philosophy private void LogInstanceMeshRetrievalWarnings( - IRevitElement element, + DB.Element element, int topLevelSolidsCount, int topLevelMeshesCount, int topLevelGeomElementCount, @@ -288,24 +257,27 @@ 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(IRevitElementId id, IRevitDocument doc) + /// + /// + /// + private bool IsSkippableGraphicStyle(DB.ElementId id, DB.Document doc) { - var graphicStyle = doc.GetElement(id)?.ToGraphicsStyle(); - if (graphicStyle is null) - { - return false; - } - if (!_graphicStyleCache.ContainsKey(id.IntegerValue)) + var key = id.ToString(); + if (_graphicStyleCache.TryGetValue(key, out var graphicStyle)) { - _graphicStyleCache.Add(id.IntegerValue, graphicStyle); + graphicStyle = (DB.GraphicsStyle)doc.GetElement(id); + _graphicStyleCache.Add(key, graphicStyle); } - if (graphicStyle.GraphicsStyleCategory.Id.IntegerValue == (int)RevitBuiltInCategory.OST_LightingFixtureSource) + if ( + graphicStyle != null + && graphicStyle.GraphicsStyleCategory.Id.IntegerValue == (int)DB.BuiltInCategory.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 new file mode 100644 index 0000000000..1cf5d4b80c --- /dev/null +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/IRevitConversionContextStack.cs @@ -0,0 +1,13 @@ +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 new file mode 100644 index 0000000000..750f4d1073 --- /dev/null +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ISlopeArrowExtractor.cs @@ -0,0 +1,10 @@ +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 b6489d3646..86735165b1 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterObjectAssigner.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterObjectAssigner.cs @@ -1,49 +1,44 @@ -using Microsoft.Extensions.Logging; +using Autodesk.Revit.DB; +using Microsoft.Extensions.Logging; using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; 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? -[GenerateAutoInterface] -public sealed class ParameterObjectAssigner : IParameterObjectAssigner +public sealed class ParameterObjectAssigner { - private readonly ITypedConverter _paramConverter; - private readonly IParameterValueExtractor _parameterValueExtractor; - private readonly IRevitElementIdUtils _revitElementIdUtils; + private readonly ITypedConverter _paramConverter; + private readonly ParameterValueExtractor _parameterValueExtractor; private readonly ILogger _logger; public ParameterObjectAssigner( - ITypedConverter paramConverter, - IParameterValueExtractor parameterValueExtractor, - IRevitElementIdUtils revitElementIdUtils, + ITypedConverter paramConverter, + ParameterValueExtractor parameterValueExtractor, ILogger logger ) { _paramConverter = paramConverter; _parameterValueExtractor = parameterValueExtractor; - _revitElementIdUtils = revitElementIdUtils; _logger = logger; } - public void AssignParametersToBase(IRevitElement target, Base @base) + public void AssignParametersToBase(Element target, Base @base) { - var instanceParameters = _parameterValueExtractor.GetAllRemainingParams(target); - IRevitElementId elementId = target.GetTypeId(); + Dictionary instanceParameters = _parameterValueExtractor.GetAllRemainingParams(target); + ElementId 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.IntegerValue != _revitElementIdUtils.InvalidElementId.IntegerValue && target is not SOBE.Level) //ignore type props of levels..! + if (elementId != ElementId.InvalidElementId && target is not Level) //ignore type props of levels..! { - var elementType = target.Document.GetElement(elementId).NotNull(); + var elementType = target.Document.GetElement(elementId); // I don't think we should be adding the type parameters to the object like this - var typeParameters = _parameterValueExtractor.GetAllRemainingParams(elementType); + Dictionary typeParameters = _parameterValueExtractor.GetAllRemainingParams(elementType); AssignSpeckleParamToBaseObject(typeParameters, paramBase, true); } @@ -54,7 +49,7 @@ public void AssignParametersToBase(IRevitElement target, Base @base) } private void AssignSpeckleParamToBaseObject( - IEnumerable> parameters, + IEnumerable> parameters, Base paramBase, bool isTypeParameter = false ) @@ -64,7 +59,7 @@ private void AssignSpeckleParamToBaseObject( { try { - var speckleParam = _paramConverter.Convert(kv.Value); + SOBR.Parameter 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 new file mode 100644 index 0000000000..71cf930224 --- /dev/null +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterObjectBuilder.cs @@ -0,0 +1,50 @@ +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 2f5a71a853..cdc8e69243 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs @@ -1,8 +1,7 @@ -using System.Diagnostics.CodeAnalysis; +using Autodesk.Revit.DB; using Speckle.Converters.Common; using Speckle.Converters.RevitShared.Extensions; using Speckle.Converters.RevitShared.Services; -using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared.Helpers; @@ -10,18 +9,17 @@ 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 : IParameterValueExtractor +public class ParameterValueExtractor { - private readonly IScalingServiceToSpeckle _scalingService; - private readonly Dictionary> _uniqueIdToUsedParameterSetMap = new(); + private readonly ScalingServiceToSpeckle _scalingService; + private readonly Dictionary> _uniqueIdToUsedParameterSetMap = new(); - public ParameterValueExtractor(IScalingServiceToSpeckle scalingService) + public ParameterValueExtractor(ScalingServiceToSpeckle scalingService) { _scalingService = scalingService; } - public object? GetValue(IRevitParameter parameter) + public object? GetValue(Parameter parameter) { if (!parameter.HasValue) { @@ -30,36 +28,32 @@ public ParameterValueExtractor(IScalingServiceToSpeckle scalingService) return parameter.StorageType switch { - RevitStorageType.Double => GetValueAsDouble(parameter), - RevitStorageType.Integer => GetValueAsInt(parameter), - RevitStorageType.String => GetValueAsString(parameter), - RevitStorageType.ElementId => GetValueAsElementId(parameter)?.ToString(), - RevitStorageType.None + StorageType.Double => GetValueAsDouble(parameter), + StorageType.Integer => GetValueAsInt(parameter), + StorageType.String => GetValueAsString(parameter), + StorageType.ElementId => GetValueAsElementId(parameter)?.ToString(), + StorageType.None or _ => throw new SpeckleConversionException($"Unsupported parameter storage type {parameter.StorageType}") }; } - public double GetValueAsDouble(IRevitElement element, RevitBuiltInParameter builtInParameter) + public double GetValueAsDouble(Element element, BuiltInParameter 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( - IRevitElement element, - RevitBuiltInParameter builtInParameter, - [NotNullWhen(true)] out double? value - ) + public bool TryGetValueAsDouble(Element element, BuiltInParameter builtInParameter, out double? value) { var number = GetValueGeneric( element, builtInParameter, - RevitStorageType.Double, + StorageType.Double, (parameter) => _scalingService.Scale(parameter.AsDouble(), parameter.GetUnitTypeId()) ); if (number.HasValue) @@ -72,81 +66,69 @@ public bool TryGetValueAsDouble( return false; } - private double? GetValueAsDouble(IRevitParameter parameter) + private double? GetValueAsDouble(Parameter parameter) { return GetValueGeneric( parameter, - RevitStorageType.Double, + StorageType.Double, (parameter) => _scalingService.Scale(parameter.AsDouble(), parameter.GetUnitTypeId()) ); } - public int GetValueAsInt(IRevitElement element, RevitBuiltInParameter builtInParameter) + public int GetValueAsInt(Element element, BuiltInParameter builtInParameter) { - return GetValueGeneric( - element, - builtInParameter, - RevitStorageType.Integer, - (parameter) => parameter.AsInteger() - ) + return GetValueGeneric(element, builtInParameter, StorageType.Integer, (parameter) => parameter.AsInteger()) ?? throw new SpeckleConversionException( $"Expected int but got null for property {builtInParameter} on element of type {element.GetType()}" ); } - private int? GetValueAsInt(IRevitParameter parameter) + private int? GetValueAsInt(Parameter parameter) { - return GetValueGeneric(parameter, RevitStorageType.Integer, (parameter) => parameter.AsInteger()); + return GetValueGeneric(parameter, StorageType.Integer, (parameter) => parameter.AsInteger()); } - public bool? GetValueAsBool(IRevitElement element, RevitBuiltInParameter builtInParameter) + public bool? GetValueAsBool(Element element, BuiltInParameter builtInParameter) { var intVal = GetValueGeneric( element, builtInParameter, - RevitStorageType.Integer, + StorageType.Integer, (parameter) => parameter.AsInteger() ); return intVal.HasValue ? Convert.ToBoolean(intVal.Value) : null; } - public string? GetValueAsString(IRevitElement element, RevitBuiltInParameter builtInParameter) + public string? GetValueAsString(Element element, BuiltInParameter builtInParameter) { - return GetValueGeneric(element, builtInParameter, RevitStorageType.String, (parameter) => parameter.AsString()); + return GetValueGeneric(element, builtInParameter, StorageType.String, (parameter) => parameter.AsString()); } - private string? GetValueAsString(IRevitParameter parameter) + private string? GetValueAsString(Parameter parameter) { - return GetValueGeneric(parameter, RevitStorageType.String, (parameter) => parameter.AsString()); + return GetValueGeneric(parameter, StorageType.String, (parameter) => parameter.AsString()); } - public IRevitElementId GetValueAsElementId(IRevitElement element, RevitBuiltInParameter builtInParameter) + public ElementId GetValueAsElementId(Element element, BuiltInParameter 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( - IRevitElement element, - RevitBuiltInParameter builtInParameter, - [NotNullWhen(true)] out IRevitElementId? elementId - ) + public bool TryGetValueAsElementId(Element element, BuiltInParameter builtInParameter, out ElementId? elementId) { - var generic = GetValueGeneric( - element, - builtInParameter, - RevitStorageType.ElementId, - (parameter) => parameter.AsElementId() - ); - if (generic is not null) + if ( + GetValueGeneric(element, builtInParameter, StorageType.ElementId, (parameter) => parameter.AsElementId()) + is ElementId elementIdNotNull + ) { - elementId = generic; + elementId = elementIdNotNull; return true; } @@ -154,66 +136,62 @@ public bool TryGetValueAsElementId( return false; } - public IRevitElementId? GetValueAsElementId(IRevitParameter parameter) + public ElementId? GetValueAsElementId(Parameter parameter) { - return GetValueGeneric(parameter, RevitStorageType.ElementId, (p) => p.AsElementId()); + return GetValueGeneric(parameter, StorageType.ElementId, (parameter) => parameter.AsElementId()); } - public IRevitLevel GetValueAsRevitLevel(IRevitElement element, RevitBuiltInParameter builtInParameter) + public bool TryGetValueAsDocumentObject(Element element, BuiltInParameter builtInParameter, out T? value) { if (!TryGetValueAsElementId(element, builtInParameter, out var elementId)) { - throw new SpeckleConversionException(); + value = default; + return false; } - var paramElement = element.Document.GetElement(elementId); - return (paramElement?.ToLevel()).NotNull(); + Element paramElement = element.Document.GetElement(elementId); + if (paramElement is not T typedElement) + { + value = default; + return false; + } + + value = typedElement; + return true; } - public bool TryGetValueAsRevitLevel( - IRevitElement element, - RevitBuiltInParameter builtInParameter, - [NotNullWhen(true)] out IRevitLevel? revitLevel - ) + public T GetValueAsDocumentObject(Element element, BuiltInParameter builtInParameter) + where T : class { - if (!TryGetValueAsElementId(element, builtInParameter, out var elementId)) + if (!TryGetValueAsDocumentObject(element, builtInParameter, out var value)) { - revitLevel = null; - return false; + throw new SpeckleConversionException($"Failed to get {builtInParameter} as an element of type {typeof(T)}"); } - var paramElement = element.Document.GetElement(elementId); - revitLevel = paramElement?.ToLevel(); - return revitLevel is not null; + return value!; // If TryGet returns true, we succeeded in obtaining the value, and it will not be null. } private TResult? GetValueGeneric( - IRevitElement element, - RevitBuiltInParameter builtInParameter, - RevitStorageType expectedStorageType, - Func getParamValue + Element element, + BuiltInParameter builtInParameter, + StorageType 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.GetParameter(builtInParameter); - if (parameter is null) - { - return default; - } + var parameter = element.get_Parameter(builtInParameter); return GetValueGeneric(parameter, expectedStorageType, getParamValue); } private TResult? GetValueGeneric( - IRevitParameter parameter, - RevitStorageType expectedStorageType, - Func getParamValue + Parameter parameter, + StorageType expectedStorageType, + Func getParamValue ) { if (parameter == null || !parameter.HasValue) @@ -231,20 +209,20 @@ Func getParamValue return getParamValue(parameter); } - public Dictionary GetAllRemainingParams(IRevitElement revitElement) + public Dictionary GetAllRemainingParams(DB.Element revitElement) { - var allParams = new Dictionary(); + var allParams = new Dictionary(); AddElementParamsToDict(revitElement, allParams); return allParams; } - private void AddElementParamsToDict(IRevitElement element, Dictionary paramDict) + private void AddElementParamsToDict(DB.Element element, Dictionary paramDict) { - _uniqueIdToUsedParameterSetMap.TryGetValue(element.UniqueId, out HashSet? usedParameters); + _uniqueIdToUsedParameterSetMap.TryGetValue(element.UniqueId, out HashSet? usedParameters); using var parameters = element.Parameters; - foreach (IRevitParameter param in parameters) + foreach (DB.Parameter param in parameters) { var internalName = param.GetInternalName(); if (paramDict.ContainsKey(internalName)) @@ -252,8 +230,7 @@ private void AddElementParamsToDict(IRevitElement 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 new file mode 100644 index 0000000000..f883f7c9e8 --- /dev/null +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/RevitCategoryInfo.cs @@ -0,0 +1,65 @@ +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/Connectors/Revit/Speckle.Connectors.RevitShared/Helpers/RevitContext.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/RevitContext.cs similarity index 80% rename from DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Helpers/RevitContext.cs rename to DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/RevitContext.cs index 3148acc5dc..59c3892a75 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Helpers/RevitContext.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/RevitContext.cs @@ -1,6 +1,6 @@ -using Autodesk.Revit.UI; +using Autodesk.Revit.UI; -namespace Speckle.Connectors.RevitShared.Helpers; +namespace Speckle.Converters.RevitShared.Helpers; public class RevitContext { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/RevitConversionContextStack.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/RevitConversionContextStack.cs new file mode 100644 index 0000000000..ce43a88901 --- /dev/null +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/RevitConversionContextStack.cs @@ -0,0 +1,28 @@ +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 new file mode 100644 index 0000000000..c6b4590a6d --- /dev/null +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/SendSelection.cs @@ -0,0 +1,17 @@ +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 1ae02630be..9db6d14583 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/SlopeArrowExtractor.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/SlopeArrowExtractor.cs @@ -1,51 +1,43 @@ -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 IParameterValueExtractor _parameterValueExtractor; - private readonly IRevitFilterFactory _revitFilterFactory; + private readonly ITypedConverter _pointConverter; + private readonly ParameterValueExtractor _parameterValueExtractor; public SlopeArrowExtractor( - ITypedConverter pointConverter, - IParameterValueExtractor parameterValueExtractor, - IRevitFilterFactory revitFilterFactory + ITypedConverter pointConverter, + ParameterValueExtractor parameterValueExtractor ) { _pointConverter = pointConverter; _parameterValueExtractor = parameterValueExtractor; - _revitFilterFactory = revitFilterFactory; } - public IRevitModelLine? GetSlopeArrow(IRevitElement element) + public DB.ModelLine? GetSlopeArrow(DB.Element element) { - IList? elementIds = null; - if (element is IRevitFloor floor) + IList? elementIds = null; + if (element is DB.Floor floor) { - elementIds = (floor.Document.GetElement(floor.SketchId).NotNull().ToSketch().NotNull()).GetAllElements(); + elementIds = ((DB.Sketch)floor.Document.GetElement(floor.SketchId)).GetAllElements(); } if (elementIds == null) { - using var modelLineFilter = _revitFilterFactory.CreateElementCategoryFilter(RevitBuiltInCategory.OST_SketchLines); + using var modelLineFilter = new DB.ElementCategoryFilter(DB.BuiltInCategory.OST_SketchLines); elementIds = element.GetDependentElements(modelLineFilter); } foreach (var elementId in elementIds) { - var line = element.Document.GetElement(elementId)?.ToModelLine(); - if (line is null) + if (element.Document.GetElement(elementId) is not DB.ModelLine line) { continue; } - var offsetAtTailParameter = line.GetParameter(RevitBuiltInParameter.SLOPE_START_HEIGHT); + var offsetAtTailParameter = line.get_Parameter(DB.BuiltInParameter.SLOPE_START_HEIGHT); if (offsetAtTailParameter != null) { return line; @@ -54,29 +46,26 @@ IRevitFilterFactory revitFilterFactory return null; } - public SOG.Point GetSlopeArrowHead(IRevitModelLine slopeArrow) + public SOG.Point GetSlopeArrowHead(DB.ModelLine slopeArrow) { - return _pointConverter.Convert((slopeArrow.GetLocationAsLocationCurve().NotNull()).Curve.GetEndPoint(1)); + return _pointConverter.Convert(((DB.LocationCurve)slopeArrow.Location).Curve.GetEndPoint(1)); } - public SOG.Point GetSlopeArrowTail(IRevitModelLine slopeArrow) + public SOG.Point GetSlopeArrowTail(DB.ModelLine slopeArrow) { - return _pointConverter.Convert((slopeArrow.GetLocationAsLocationCurve().NotNull()).Curve.GetEndPoint(0)); + return _pointConverter.Convert(((DB.LocationCurve)slopeArrow.Location).Curve.GetEndPoint(0)); } - public double GetSlopeArrowTailOffset(IRevitModelLine slopeArrow) + public double GetSlopeArrowTailOffset(DB.ModelLine slopeArrow) { - return _parameterValueExtractor.GetValueAsDouble(slopeArrow, RevitBuiltInParameter.SLOPE_START_HEIGHT); + return _parameterValueExtractor.GetValueAsDouble(slopeArrow, DB.BuiltInParameter.SLOPE_START_HEIGHT); } - public double GetSlopeArrowHeadOffset(IRevitModelLine slopeArrow, double tailOffset, out double slope) + public double GetSlopeArrowHeadOffset(DB.ModelLine slopeArrow, double tailOffset, out double slope) { - var specifyOffset = _parameterValueExtractor.GetValueAsInt( - slopeArrow, - RevitBuiltInParameter.SPECIFY_SLOPE_OR_OFFSET - ); + var specifyOffset = _parameterValueExtractor.GetValueAsInt(slopeArrow, DB.BuiltInParameter.SPECIFY_SLOPE_OR_OFFSET); - var lineLength = _parameterValueExtractor.GetValueAsDouble(slopeArrow, RevitBuiltInParameter.CURVE_ELEM_LENGTH); + var lineLength = _parameterValueExtractor.GetValueAsDouble(slopeArrow, DB.BuiltInParameter.CURVE_ELEM_LENGTH); slope = 0; double headOffset = 0; @@ -84,12 +73,12 @@ public double GetSlopeArrowHeadOffset(IRevitModelLine slopeArrow, double tailOff if (specifyOffset == 1) { // in this scenario, slope is returned as a percentage. Divide by 100 to get the unitless form - slope = _parameterValueExtractor.GetValueAsDouble(slopeArrow, RevitBuiltInParameter.ROOF_SLOPE) / 100d; + slope = _parameterValueExtractor.GetValueAsDouble(slopeArrow, DB.BuiltInParameter.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, RevitBuiltInParameter.SLOPE_END_HEIGHT); + headOffset = _parameterValueExtractor.GetValueAsDouble(slopeArrow, DB.BuiltInParameter.SLOPE_END_HEIGHT); slope = (headOffset - tailOffset) / lineLength; } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ToSpeckleConvertedObjectsCache.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ToSpeckleConvertedObjectsCache.cs new file mode 100644 index 0000000000..c4c91d9fb8 --- /dev/null +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ToSpeckleConvertedObjectsCache.cs @@ -0,0 +1,25 @@ +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 new file mode 100644 index 0000000000..f526412336 --- /dev/null +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/IReferencePointConverter.cs @@ -0,0 +1,6 @@ +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 new file mode 100644 index 0000000000..18a593cbbd --- /dev/null +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/IRevitVersionConversionHelper.cs @@ -0,0 +1,6 @@ +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 59f790664f..d6ee746e43 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BeamConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BeamConversionToSpeckle.cs @@ -3,28 +3,27 @@ using Speckle.Converters.Common.Objects; using Speckle.Converters.RevitShared.Helpers; using Speckle.Core.Models; -using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared; +namespace Speckle.Converters.RevitShared.ToSpeckle; // 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 IParameterValueExtractor _parameterValueExtractor; - private readonly IDisplayValueExtractor _displayValueExtractor; - private readonly IParameterObjectAssigner _parameterObjectAssigner; + private readonly ITypedConverter _locationConverter; + private readonly ITypedConverter _levelConverter; + private readonly ParameterValueExtractor _parameterValueExtractor; + private readonly DisplayValueExtractor _displayValueExtractor; + private readonly ParameterObjectAssigner _parameterObjectAssigner; public BeamConversionToSpeckle( - ITypedConverter locationConverter, - ITypedConverter levelConverter, - IParameterValueExtractor parameterValueExtractor, - IDisplayValueExtractor displayValueExtractor, - IParameterObjectAssigner parameterObjectAssigner + ITypedConverter locationConverter, + ITypedConverter levelConverter, + ParameterValueExtractor parameterValueExtractor, + DisplayValueExtractor displayValueExtractor, + ParameterObjectAssigner parameterObjectAssigner ) { _locationConverter = locationConverter; @@ -34,7 +33,7 @@ IParameterObjectAssigner parameterObjectAssigner _parameterObjectAssigner = parameterObjectAssigner; } - public SOBR.RevitBeam Convert(IRevitFamilyInstance target) + public SOBR.RevitBeam Convert(DB.FamilyInstance target) { var baseGeometry = _locationConverter.Convert(target.Location); if (baseGeometry is not ICurve baseCurve) @@ -43,20 +42,19 @@ public SOBR.RevitBeam Convert(IRevitFamilyInstance target) $"Beam location conversion did not yield an ICurve, instead it yielded an object of type {baseGeometry.GetType()}" ); } - - var symbol = target.Document.GetElement(target.GetTypeId()).NotNull().ToFamilySymbol().NotNull(); + var symbol = (DB.FamilySymbol)target.Document.GetElement(target.GetTypeId()); SOBR.RevitBeam speckleBeam = new() { family = symbol.FamilyName, - type = target.Document.GetElement(target.GetTypeId()).NotNull().Name, + type = target.Document.GetElement(target.GetTypeId()).Name, baseLine = baseCurve }; - var level = _parameterValueExtractor.GetValueAsRevitLevel( + var level = _parameterValueExtractor.GetValueAsDocumentObject( target, - RevitBuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM + DB.BuiltInParameter.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 793e03735e..8f02d4c345 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BoundarySegmentConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BoundarySegmentConversionToSpeckle.cs @@ -1,19 +1,18 @@ using Objects; using Speckle.Converters.Common.Objects; -using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared; +namespace Speckle.Converters.RevitShared.ToSpeckle; -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) { @@ -23,7 +22,7 @@ public SOG.Polycurve Convert(IList target) var poly = new SOG.Polycurve(); foreach (var segment in target) { - IRevitCurve revitCurve = segment.GetCurve(); + DB.Curve 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 bcee398c73..ccae249fe5 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BraceToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BraceToSpeckleConverter.cs @@ -1,25 +1,24 @@ -using Speckle.Converters.Common.Objects; +using Speckle.Converters.Common.Objects; using Speckle.Core.Models; -using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared; +namespace Speckle.Converters.RevitShared.ToSpeckle; // 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(IRevitFamilyInstance target) + public SOBR.RevitBrace Convert(DB.FamilyInstance target) { - // POC: we might want some easy one-liner here to FamilyMatchesOrThrow(target, IRevitStructure.StructuralType.Brace) or similar + // POC: we might want some easy one-liner here to FamilyMatchesOrThrow(target, DB.Structure.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 afcf6f27eb..1786febd39 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs @@ -1,30 +1,31 @@ -using Objects; +using Autodesk.Revit.DB; +using Objects; +using Objects.BuiltElements.Revit; 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; +namespace Speckle.Converters.RevitShared.ToSpeckle; // 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 IParameterValueExtractor _parameterValueExtractor; - private readonly IDisplayValueExtractor _displayValueExtractor; - private readonly IConversionContextStack _contextStack; - private readonly IParameterObjectAssigner _parameterObjectAssigner; + private readonly ITypedConverter _locationConverter; + private readonly ITypedConverter _levelConverter; + private readonly ParameterValueExtractor _parameterValueExtractor; + private readonly DisplayValueExtractor _displayValueExtractor; + private readonly IRevitConversionContextStack _contextStack; + private readonly ParameterObjectAssigner _parameterObjectAssigner; public ColumnConversionToSpeckle( - ITypedConverter locationConverter, - ITypedConverter levelConverter, - IParameterValueExtractor parameterValueExtractor, - IDisplayValueExtractor displayValueExtractor, - IConversionContextStack contextStack, - IParameterObjectAssigner parameterObjectAssigner + ITypedConverter locationConverter, + ITypedConverter levelConverter, + ParameterValueExtractor parameterValueExtractor, + DisplayValueExtractor displayValueExtractor, + IRevitConversionContextStack contextStack, + ParameterObjectAssigner parameterObjectAssigner ) { _locationConverter = locationConverter; @@ -35,71 +36,67 @@ IParameterObjectAssigner parameterObjectAssigner _parameterObjectAssigner = parameterObjectAssigner; } - public SOBR.RevitColumn Convert(IRevitFamilyInstance target) + public RevitColumn Convert(DB.FamilyInstance target) { - var symbol = target.Document.GetElement(target.GetTypeId()).NotNull().ToFamilySymbol().NotNull(); + FamilySymbol symbol = (FamilySymbol)target.Document.GetElement(target.GetTypeId()); - SOBR.RevitColumn speckleColumn = - new() { family = symbol.FamilyName, type = target.Document.GetElement(target.GetTypeId()).NotNull().Name }; + RevitColumn speckleColumn = + new() { family = symbol.FamilyName, type = target.Document.GetElement(target.GetTypeId()).Name }; - //should these all be try? if ( - _parameterValueExtractor.TryGetValueAsRevitLevel( + _parameterValueExtractor.TryGetValueAsDocumentObject( target, - RevitBuiltInParameter.FAMILY_BASE_LEVEL_PARAM, + BuiltInParameter.FAMILY_BASE_LEVEL_PARAM, out var level ) ) { - speckleColumn.level = _levelConverter.Convert(level); + speckleColumn.level = _levelConverter.Convert(level.NotNull()); } - //should these all be try? if ( - _parameterValueExtractor.TryGetValueAsRevitLevel( + _parameterValueExtractor.TryGetValueAsDocumentObject( target, - RevitBuiltInParameter.FAMILY_TOP_LEVEL_PARAM, + BuiltInParameter.FAMILY_TOP_LEVEL_PARAM, out var topLevel ) ) { - speckleColumn.topLevel = _levelConverter.Convert(topLevel); + speckleColumn.topLevel = _levelConverter.Convert(topLevel.NotNull()); } - //should these all be try? if ( _parameterValueExtractor.TryGetValueAsDouble( target, - RevitBuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM, + BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM, out var baseOffset ) ) { - speckleColumn.baseOffset = baseOffset.Value; + speckleColumn.baseOffset = baseOffset.NotNull(); } - //should these all be try? if ( _parameterValueExtractor.TryGetValueAsDouble( target, - RevitBuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM, + BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM, out var topOffset ) ) { - speckleColumn.topOffset = topOffset.Value; + speckleColumn.topOffset = topOffset.NotNull(); } + speckleColumn.facingFlipped = target.FacingFlipped; speckleColumn.handFlipped = target.HandFlipped; speckleColumn.isSlanted = target.IsSlantedColumn; - var locationPoint = target.GetLocationAsLocationPoint(); - if (locationPoint is not null) + if (target.Location is LocationPoint locationPoint) { speckleColumn.rotation = locationPoint.Rotation; } speckleColumn.baseLine = - GetBaseCurve(target, speckleColumn.topLevel?.elevation, speckleColumn.topOffset) + GetBaseCurve(target, speckleColumn.topLevel?.elevation ?? -1, speckleColumn.topOffset) ?? throw new SpeckleConversionException("Unable to find a valid baseCurve for column"); speckleColumn.displayValue = _displayValueExtractor.GetDisplayValue(target); @@ -109,7 +106,7 @@ out var topOffset return speckleColumn; } - private ICurve? GetBaseCurve(IRevitFamilyInstance target, double? topLevelElevation, double topLevelOffset) + private ICurve? GetBaseCurve(DB.FamilyInstance target, double topLevelElevation, double topLevelOffset) { Base baseGeometry = _locationConverter.Convert(target.Location); ICurve? baseCurve = baseGeometry as ICurve; @@ -132,12 +129,7 @@ out var topOffset return new SOG.Line( basePoint, - new SOG.Point( - basePoint.x, - basePoint.y, - topLevelElevation ?? 0 + topLevelOffset, - _contextStack.Current.SpeckleUnits - ), + new SOG.Point(basePoint.x, basePoint.y, topLevelElevation + topLevelOffset, _contextStack.Current.SpeckleUnits), _contextStack.Current.SpeckleUnits ); } 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 a5830c9c45..d6774a710b 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,46 +1,42 @@ -using Objects.Primitive; -using Speckle.Converters.Common; +using Objects.Primitive; using Speckle.Converters.Common.Objects; +using Speckle.Converters.RevitShared.Helpers; using Speckle.Converters.RevitShared.Services; -using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared.ToSpeckle; -public class ArcToSpeckleConverter : ITypedConverter +public class ArcToSpeckleConverter : ITypedConverter { - private readonly IConversionContextStack _contextStack; - private readonly ITypedConverter _xyzToPointConverter; - private readonly ITypedConverter _planeConverter; - private readonly IScalingServiceToSpeckle _scalingService; - private readonly IRevitPlaneUtils _revitPlaneUtils; + private readonly IRevitConversionContextStack _contextStack; + private readonly ITypedConverter _xyzToPointConverter; + private readonly ITypedConverter _planeConverter; + private readonly ScalingServiceToSpeckle _scalingService; public ArcToSpeckleConverter( - IConversionContextStack contextStack, - ITypedConverter xyzToPointConverter, - ITypedConverter planeConverter, - IScalingServiceToSpeckle scalingService, - IRevitPlaneUtils revitPlaneUtils + IRevitConversionContextStack contextStack, + ITypedConverter xyzToPointConverter, + ITypedConverter planeConverter, + ScalingServiceToSpeckle scalingService ) { _contextStack = contextStack; _xyzToPointConverter = xyzToPointConverter; _planeConverter = planeConverter; _scalingService = scalingService; - _revitPlaneUtils = revitPlaneUtils; } - public SOG.Arc Convert(IRevitArc target) + public SOG.Arc Convert(DB.Arc target) { // see https://forums.autodesk.com/t5/revit-api-forum/how-to-retrieve-startangle-and-endangle-of-arc-object/td-p/7637128 - var arcPlane = _revitPlaneUtils.CreateByOriginAndBasis(target.Center, target.XDirection, target.YDirection); - IRevitXYZ center = target.Center; + var arcPlane = DB.Plane.CreateByOriginAndBasis(target.Center, target.XDirection, target.YDirection); + DB.XYZ center = target.Center; - IRevitXYZ dir0 = (target.GetEndPoint(0).Subtract(center)).Normalize(); - IRevitXYZ dir1 = (target.GetEndPoint(1).Subtract(center)).Normalize(); + DB.XYZ dir0 = (target.GetEndPoint(0) - center).Normalize(); + DB.XYZ dir1 = (target.GetEndPoint(1) - center).Normalize(); - IRevitXYZ start = target.Evaluate(0, true); - IRevitXYZ end = target.Evaluate(1, true); - IRevitXYZ mid = target.Evaluate(0.5, true); + DB.XYZ start = target.Evaluate(0, true); + DB.XYZ end = target.Evaluate(1, true); + DB.XYZ 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 f91deee0cc..a891579ad5 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,31 +1,27 @@ -using Objects.Primitive; -using Speckle.Converters.Common; +using Objects.Primitive; using Speckle.Converters.Common.Objects; -using Speckle.Revit.Interfaces; +using Speckle.Converters.RevitShared.Helpers; namespace Speckle.Converters.RevitShared.ToSpeckle; -public class BoundingBoxXYZToSpeckleConverter : ITypedConverter +public class BoundingBoxXYZToSpeckleConverter : ITypedConverter { - private readonly IConversionContextStack _contextStack; - private readonly ITypedConverter _xyzToPointConverter; - private readonly ITypedConverter _planeConverter; - private readonly IRevitPlaneUtils _revitPlaneUtils; + private readonly IRevitConversionContextStack _contextStack; + private readonly ITypedConverter _xyzToPointConverter; + private readonly ITypedConverter _planeConverter; public BoundingBoxXYZToSpeckleConverter( - IConversionContextStack contextStack, - ITypedConverter xyzToPointConverter, - ITypedConverter planeConverter, - IRevitPlaneUtils revitPlaneUtils + IRevitConversionContextStack contextStack, + ITypedConverter xyzToPointConverter, + ITypedConverter planeConverter ) { _contextStack = contextStack; _xyzToPointConverter = xyzToPointConverter; _planeConverter = planeConverter; - _revitPlaneUtils = revitPlaneUtils; } - public SOG.Box Convert(IRevitBoundingBoxXYZ target) + public SOG.Box Convert(DB.BoundingBoxXYZ target) { // convert min and max pts to speckle first var min = _xyzToPointConverter.Convert(target.Min); @@ -33,7 +29,7 @@ public SOG.Box Convert(IRevitBoundingBoxXYZ target) // get the base plane of the bounding box from the transform var transform = target.Transform; - var plane = _revitPlaneUtils.CreateByOriginAndBasis( + var plane = DB.Plane.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 580c223c6b..7abdc08cfc 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,36 +1,32 @@ -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; -public class CircleToSpeckleConverter : ITypedConverter +public class CircleToSpeckleConverter : ITypedConverter { - private readonly IConversionContextStack _contextStack; - private readonly ITypedConverter _planeConverter; - private readonly IScalingServiceToSpeckle _scalingService; - private readonly IRevitPlaneUtils _revitPlaneUtils; + private readonly IRevitConversionContextStack _contextStack; + private readonly ITypedConverter _planeConverter; + private readonly ScalingServiceToSpeckle _scalingService; public CircleToSpeckleConverter( - IConversionContextStack contextStack, - ITypedConverter planeConverter, - IScalingServiceToSpeckle scalingService, - IRevitPlaneUtils revitPlaneUtils + IRevitConversionContextStack contextStack, + ITypedConverter planeConverter, + ScalingServiceToSpeckle scalingService ) { _contextStack = contextStack; _planeConverter = planeConverter; _scalingService = scalingService; - _revitPlaneUtils = revitPlaneUtils; } - public SOG.Circle Convert(IRevitArc target) + public SOG.Circle Convert(DB.Arc 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 = _revitPlaneUtils.CreateByNormalAndOrigin(target.Normal, target.Center); + var arcPlane = DB.Plane.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 d393d310c6..4644bc1435 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,25 +1,34 @@ -using Speckle.Converters.Common.Objects; -using Speckle.Revit.Interfaces; +using Autodesk.Revit.DB; +using Objects.Geometry; +using Speckle.Converters.Common.Objects; -namespace Speckle.Converters.RevitShared.ToSpeckle; +namespace Speckle.Converters.RevitShared.Raw; -public sealed class CurveArrArrayToSpecklePolycurveConverter : ITypedConverter> +internal 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(IRevitCurveArrArray target) + public List Convert(CurveArrArray target) { - List polycurves = new(target.Count); - foreach (var curveArray in target) + List polycurves = new(); + foreach (var curveArray in GetCurveArrays(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 afa6ad4830..8ec80fe9f7 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,21 +1,22 @@ -using Objects; -using Speckle.Converters.Common; +using Autodesk.Revit.DB; +using Objects; +using Objects.Geometry; using Speckle.Converters.Common.Objects; +using Speckle.Converters.RevitShared.Helpers; using Speckle.Converters.RevitShared.Services; -using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared.ToSpeckle; -public sealed class CurveArrayConversionToSpeckle : ITypedConverter +public sealed class CurveArrayConversionToSpeckle : ITypedConverter { - private readonly IConversionContextStack _contextStack; - private readonly IScalingServiceToSpeckle _scalingService; - private readonly ITypedConverter _curveConverter; + private readonly IRevitConversionContextStack _contextStack; + private readonly ScalingServiceToSpeckle _scalingService; + private readonly ITypedConverter _curveConverter; public CurveArrayConversionToSpeckle( - IConversionContextStack contextStack, - IScalingServiceToSpeckle scalingService, - ITypedConverter curveConverter + IRevitConversionContextStack contextStack, + ScalingServiceToSpeckle scalingService, + ITypedConverter curveConverter ) { _contextStack = contextStack; @@ -23,14 +24,15 @@ ITypedConverter curveConverter _curveConverter = curveConverter; } - public SOG.Polycurve Convert(IRevitCurveArray target) + public Polycurve Convert(CurveArray target) { - List curves = target.Cast().ToList(); + List curves = target.Cast().ToList(); - return new SOG.Polycurve() + return new Polycurve() { units = _contextStack.Current.SpeckleUnits, - closed = curves.First().GetEndPoint(0).DistanceTo(curves.Last().GetEndPoint(1)) < RevitConstants.TOLERANCE, + closed = + curves.First().GetEndPoint(0).DistanceTo(curves.Last().GetEndPoint(1)) < RevitConversionContextStack.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 e165964a28..0b034a779c 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,26 +1,25 @@ -using Objects; -using Speckle.Converters.Common; +using Objects; using Speckle.Converters.Common.Objects; -using Speckle.Revit.Interfaces; +using Speckle.Converters.Common; namespace Speckle.Converters.RevitShared.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; @@ -31,34 +30,18 @@ public CurveConversionToSpeckle( _hermiteConverter = hermiteConverter; } - public ICurve Convert(IRevitCurve target) + public ICurve Convert(DB.Curve target) { - var line = target.ToLine(); - if (line is not null) - { - 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 target switch { - return _hermiteConverter.Convert(hermite); - } + DB.Line 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), - 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/Raw/Geometry/EllipseToSpeckleConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/Geometry/EllipseToSpeckleConverter.cs index 7f920e5954..96ca62f8f1 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,40 +1,30 @@ -using Objects.Primitive; -using Speckle.Converters.Common; +using Objects.Primitive; using Speckle.Converters.Common.Objects; +using Speckle.Converters.RevitShared.Helpers; using Speckle.Converters.RevitShared.Services; -using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared.ToSpeckle; -public class EllipseToSpeckleConverter : ITypedConverter +public class EllipseToSpeckleConverter : ITypedConverter { - private readonly IConversionContextStack _contextStack; - private readonly ITypedConverter _planeConverter; - private readonly IScalingServiceToSpeckle _scalingService; - private readonly IRevitPlaneUtils _revitPlaneUtils; + private readonly IRevitConversionContextStack _contextStack; + private readonly ITypedConverter _planeConverter; + private readonly ScalingServiceToSpeckle _scalingService; public EllipseToSpeckleConverter( - IConversionContextStack contextStack, - ITypedConverter planeConverter, - IScalingServiceToSpeckle scalingService, - IRevitPlaneUtils revitPlaneUtils + IRevitConversionContextStack contextStack, + ITypedConverter planeConverter, + ScalingServiceToSpeckle scalingService ) { _contextStack = contextStack; _planeConverter = planeConverter; _scalingService = scalingService; - _revitPlaneUtils = revitPlaneUtils; } - public SOG.Ellipse Convert(IRevitEllipse target) + public SOG.Ellipse Convert(DB.Ellipse target) { - using ( - IRevitPlane basePlane = _revitPlaneUtils.CreateByOriginAndBasis( - target.Center, - target.XDirection, - target.YDirection - ) - ) + using (DB.Plane basePlane = DB.Plane.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 1c364da849..5aa2a07ed2 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,25 +1,19 @@ -using Speckle.Converters.Common.Objects; -using Speckle.Revit.Interfaces; +using Speckle.Converters.Common.Objects; namespace Speckle.Converters.RevitShared.ToSpeckle; -public class HermiteSplineToSpeckleConverter : ITypedConverter +public class HerminteSplitToSpeckleConverter : ITypedConverter { - private readonly ITypedConverter _splineConverter; - private readonly IRevitNurbSplineUtils _revitNurbSplineUtils; + private readonly ITypedConverter _splineConverter; - public HermiteSplineToSpeckleConverter( - ITypedConverter splineConverter, - IRevitNurbSplineUtils revitNurbSplineUtils - ) + public HerminteSplitToSpeckleConverter(ITypedConverter splineConverter) { _splineConverter = splineConverter; - _revitNurbSplineUtils = revitNurbSplineUtils; } - public SOG.Curve Convert(IRevitHermiteSpline target) + public SOG.Curve Convert(DB.HermiteSpline target) { - var nurbs = _revitNurbSplineUtils.Create(target); + var nurbs = DB.NurbSpline.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 ceddef39b0..2405cf0b22 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,21 +1,20 @@ -using Objects.Primitive; -using Speckle.Converters.Common; +using Objects.Primitive; using Speckle.Converters.Common.Objects; +using Speckle.Converters.RevitShared.Helpers; using Speckle.Converters.RevitShared.Services; -using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared.ToSpeckle; -public class LineConversionToSpeckle : ITypedConverter +public class LineConversionToSpeckle : ITypedConverter { - private readonly IConversionContextStack _contextStack; - private readonly ITypedConverter _xyzToPointConverter; - private readonly IScalingServiceToSpeckle _scalingService; + private readonly IRevitConversionContextStack _contextStack; + private readonly ITypedConverter _xyzToPointConverter; + private readonly ScalingServiceToSpeckle _scalingService; public LineConversionToSpeckle( - IConversionContextStack contextStack, - ITypedConverter xyzToPointConverter, - IScalingServiceToSpeckle scalingService + IRevitConversionContextStack contextStack, + ITypedConverter xyzToPointConverter, + ScalingServiceToSpeckle scalingService ) { _contextStack = contextStack; @@ -23,7 +22,7 @@ IScalingServiceToSpeckle scalingService _scalingService = scalingService; } - public SOG.Line Convert(IRevitLine target) => + public SOG.Line Convert(DB.Line 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 22d806277a..29b0bd9f98 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,21 +1,20 @@ using Objects.Other; -using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Revit.Interfaces; +using Speckle.Converters.RevitShared.Helpers; namespace Speckle.Converters.RevitShared.ToSpeckle; public class MeshByMaterialDictionaryToSpeckle - : ITypedConverter>, List> + : ITypedConverter>, List> { - private readonly IConversionContextStack _contextStack; - private readonly ITypedConverter _xyzToPointConverter; - private readonly ITypedConverter _materialConverter; + private readonly IRevitConversionContextStack _contextStack; + private readonly ITypedConverter _xyzToPointConverter; + private readonly ITypedConverter _materialConverter; public MeshByMaterialDictionaryToSpeckle( - ITypedConverter materialConverter, - IConversionContextStack contextStack, - ITypedConverter xyzToPointConverter + ITypedConverter materialConverter, + IRevitConversionContextStack contextStack, + ITypedConverter xyzToPointConverter ) { _materialConverter = materialConverter; @@ -26,24 +25,24 @@ public MeshByMaterialDictionaryToSpeckle( /// /// Converts a dictionary of Revit meshes, where key is MaterialId, into a list of Speckle meshes. /// - /// A dictionary with IRevitElementId keys and List of IRevitMesh values. + /// A dictionary with DB.ElementId keys and List of DB.Mesh 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 IRevitMaterial 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 DB.Material 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) { - IRevitElementId materialId = meshData.Key; - List meshes = meshData.Value; + DB.ElementId 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); @@ -56,7 +55,7 @@ public MeshByMaterialDictionaryToSpeckle( ); var doc = _contextStack.Current.Document; - if (doc.GetElement(materialId) is IRevitMaterial material) + if (doc.GetElement(materialId) is DB.Material material) { speckleMesh["renderMaterial"] = _materialConverter.Convert(material); } @@ -73,7 +72,7 @@ public MeshByMaterialDictionaryToSpeckle( return result; } - private void AppendToSpeckleMesh(IRevitMesh mesh, SOG.Mesh speckleMesh) + private void AppendToSpeckleMesh(DB.Mesh mesh, SOG.Mesh speckleMesh) { int faceIndexOffset = speckleMesh.vertices.Count / 3; @@ -87,16 +86,16 @@ private void AppendToSpeckleMesh(IRevitMesh mesh, SOG.Mesh speckleMesh) for (int i = 0; i < mesh.NumTriangles; i++) { - var triangle = mesh.GetTriangle(i); + var triangle = mesh.get_Triangle(i); speckleMesh.faces.Add(3); // TRIANGLE flag - speckleMesh.faces.Add((int)triangle.GetIndex(0) + faceIndexOffset); - speckleMesh.faces.Add((int)triangle.GetIndex(1) + faceIndexOffset); - speckleMesh.faces.Add((int)triangle.GetIndex(2) + faceIndexOffset); + 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); } } - 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 093d553cf2..2f6c494ba0 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,20 +1,19 @@ using Objects.Other; -using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Revit.Interfaces; +using Speckle.Converters.RevitShared.Helpers; namespace Speckle.Converters.RevitShared.ToSpeckle; -public class MeshConversionToSpeckle : ITypedConverter +public class MeshConversionToSpeckle : ITypedConverter { - private readonly ITypedConverter _xyzToPointConverter; - private readonly ITypedConverter _materialConverter; - private readonly IConversionContextStack _contextStack; + private readonly ITypedConverter _xyzToPointConverter; + private readonly ITypedConverter _materialConverter; + private readonly IRevitConversionContextStack _contextStack; public MeshConversionToSpeckle( - IConversionContextStack contextStack, - ITypedConverter xyzToPointConverter, - ITypedConverter materialConverter + IRevitConversionContextStack contextStack, + ITypedConverter xyzToPointConverter, + ITypedConverter materialConverter ) { _contextStack = contextStack; @@ -22,17 +21,15 @@ ITypedConverter materialConverter _materialConverter = materialConverter; } - public SOG.Mesh Convert(IRevitMesh target) + public SOG.Mesh Convert(DB.Mesh 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 (revitMaterial is not null) + if (doc.GetElement(target.MaterialElementId) is DB.Material revitMaterial) { speckleMaterial = _materialConverter.Convert(revitMaterial); } @@ -43,7 +40,7 @@ public SOG.Mesh Convert(IRevitMesh target) }; } - private List GetSpeckleMeshVertexData(IRevitMesh target) + private List GetSpeckleMeshVertexData(DB.Mesh target) { var vertices = new List(target.Vertices.Count * 3); @@ -55,12 +52,12 @@ private List GetSpeckleMeshVertexData(IRevitMesh target) return vertices; } - private List GetSpeckleMeshFaceData(IRevitMesh target) + private List GetSpeckleMeshFaceData(DB.Mesh target) { var faces = new List(target.NumTriangles * 4); for (int i = 0; i < target.NumTriangles; i++) { - var triangle = target.GetTriangle(i); + var triangle = target.get_Triangle(i); faces.AddRange(GetMeshTriangleData(triangle)); } @@ -76,12 +73,12 @@ private List GetSpeckleMeshFaceData(IRevitMesh 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(IRevitMeshTriangle triangle) => + private IReadOnlyList GetMeshTriangleData(DB.MeshTriangle triangle) => new[] { 3, // The TRIANGLE flag in speckle - (int)triangle.GetIndex(0), - (int)triangle.GetIndex(1), - (int)triangle.GetIndex(2) + (int)triangle.get_Index(0), + (int)triangle.get_Index(1), + (int)triangle.get_Index(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 c646f9e6b4..7229f639e3 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,23 +1,22 @@ -using Objects.Primitive; -using Speckle.Converters.Common; +using Objects.Primitive; using Speckle.Converters.Common.Objects; +using Speckle.Converters.RevitShared.Helpers; using Speckle.Converters.RevitShared.Services; -using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared.ToSpeckle; -public class NurbsSplineToSpeckleConverter : ITypedConverter +public class NurbsSplineToSpeckleConverter : ITypedConverter { private readonly IRevitVersionConversionHelper _conversionHelper; - private readonly IConversionContextStack _contextStack; - private readonly ITypedConverter _xyzToPointConverter; - private readonly IScalingServiceToSpeckle _scalingService; + private readonly IRevitConversionContextStack _contextStack; + private readonly ITypedConverter _xyzToPointConverter; + private readonly ScalingServiceToSpeckle _scalingService; public NurbsSplineToSpeckleConverter( IRevitVersionConversionHelper conversionHelper, - IConversionContextStack contextStack, - ITypedConverter xyzToPointConverter, - IScalingServiceToSpeckle scalingService + IRevitConversionContextStack contextStack, + ITypedConverter xyzToPointConverter, + ScalingServiceToSpeckle scalingService ) { _conversionHelper = conversionHelper; @@ -26,7 +25,7 @@ IScalingServiceToSpeckle scalingService _scalingService = scalingService; } - public SOG.Curve Convert(IRevitNurbSpline target) + public SOG.Curve Convert(DB.NurbSpline target) { var units = _contextStack.Current.SpeckleUnits; @@ -41,12 +40,12 @@ public SOG.Curve Convert(IRevitNurbSpline target) return new SOG.Curve() { - weights = target.Weights.ToList(), + weights = target.Weights.Cast().ToList(), points = points, - knots = target.Knots.ToList(), + knots = target.Knots.Cast().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 56f098ceda..27cef7bab6 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,19 +1,18 @@ -using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Revit.Interfaces; +using Speckle.Converters.RevitShared.Helpers; namespace Speckle.Converters.RevitShared.ToSpeckle; -public class PlaneToSpeckleConverter : ITypedConverter +public class PlaneToSpeckleConverter : ITypedConverter { - private readonly IConversionContextStack _contextStack; - private readonly ITypedConverter _xyzToPointConverter; - private readonly ITypedConverter _xyzToVectorConverter; + private readonly IRevitConversionContextStack _contextStack; + private readonly ITypedConverter _xyzToPointConverter; + private readonly ITypedConverter _xyzToVectorConverter; public PlaneToSpeckleConverter( - IConversionContextStack contextStack, - ITypedConverter xyzToPointConverter, - ITypedConverter xyzToVectorConverter + IRevitConversionContextStack contextStack, + ITypedConverter xyzToPointConverter, + ITypedConverter xyzToVectorConverter ) { _contextStack = contextStack; @@ -21,7 +20,7 @@ public PlaneToSpeckleConverter( _xyzToVectorConverter = xyzToVectorConverter; } - public SOG.Plane Convert(IRevitPlane target) + public SOG.Plane Convert(DB.Plane 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 c552e7dbdf..ab86301cd2 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,52 +1,39 @@ -using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Revit.Interfaces; +using Speckle.Converters.RevitShared.Helpers; namespace Speckle.Converters.RevitShared.ToSpeckle; -public class PointCloudToSpeckleConverter : ITypedConverter +public class PointCloudToSpeckleConverter : ITypedConverter { - private readonly IConversionContextStack _contextStack; - private readonly ITypedConverter _xyzToPointConverter; - private readonly ITypedConverter _boundingBoxConverter; - private readonly IRevitPlaneUtils _revitPlaneUtils; - private readonly IRevitXYZUtils _revitxyzUtils; - private readonly IRevitFilterFactory _revitFilterFactory; + private readonly IRevitConversionContextStack _contextStack; + private readonly ITypedConverter _xyzToPointConverter; + private readonly ITypedConverter _boundingBoxConverter; public PointCloudToSpeckleConverter( - IConversionContextStack contextStack, - ITypedConverter xyzToPointConverter, - ITypedConverter boundingBoxConverter, - IRevitPlaneUtils revitPlaneUtils, - IRevitXYZUtils revitxyzUtils, - IRevitFilterFactory revitFilterFactory + IRevitConversionContextStack contextStack, + ITypedConverter xyzToPointConverter, + ITypedConverter boundingBoxConverter ) { _contextStack = contextStack; _xyzToPointConverter = xyzToPointConverter; _boundingBoxConverter = boundingBoxConverter; - _revitPlaneUtils = revitPlaneUtils; - _revitxyzUtils = revitxyzUtils; - _revitFilterFactory = revitFilterFactory; } - public SOG.Pointcloud Convert(IRevitPointCloudInstance target) + public SOG.Pointcloud Convert(DB.PointCloudInstance target) { - var boundingBox = target.GetBoundingBox(); - using IRevitTransform transform = target.GetTransform(); + var boundingBox = target.get_BoundingBox(null); + using DB.Transform transform = target.GetTransform(); { - var minPlane = _revitPlaneUtils.CreateByNormalAndOrigin( - _revitxyzUtils.BasisZ, - transform.OfPoint(boundingBox.NotNull().Min) - ); - var filter = _revitFilterFactory.CreateMultiPlaneFilter(minPlane); + var minPlane = DB.Plane.CreateByNormalAndOrigin(DB.XYZ.BasisZ, transform.OfPoint(boundingBox.Min)); + var filter = DB.PointClouds.PointCloudFilterFactory.CreateMultiPlaneFilter(new List() { 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.ToXYZ()))) + .Select(o => _xyzToPointConverter.Convert(transform.OfPoint(o))) .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 4da12eafca..8f6ca703db 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,16 +1,15 @@ -using Speckle.Converters.Common.Objects; -using Speckle.Revit.Interfaces; +using Speckle.Converters.Common.Objects; namespace Speckle.Converters.RevitShared.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(IRevitPoint target) => _xyzToPointConverter.Convert(target.Coord); + public SOG.Point Convert(DB.Point 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 e64b28309b..5efb22e278 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,24 +1,23 @@ -using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Revit.Interfaces; +using Speckle.Converters.RevitShared.Helpers; namespace Speckle.Converters.RevitShared.ToSpeckle; -public class PolylineToSpeckleConverter : ITypedConverter +public class PolylineToSpeckleConverter : ITypedConverter { - private readonly IConversionContextStack _contextStack; - private readonly ITypedConverter _xyzToPointConverter; + private readonly IRevitConversionContextStack _contextStack; + private readonly ITypedConverter _xyzToPointConverter; public PolylineToSpeckleConverter( - IConversionContextStack contextStack, - ITypedConverter xyzToPointConverter + IRevitConversionContextStack contextStack, + ITypedConverter xyzToPointConverter ) { _contextStack = contextStack; _xyzToPointConverter = xyzToPointConverter; } - public SOG.Polyline Convert(IRevitPolyLine target) + public SOG.Polyline Convert(DB.PolyLine 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 039c706869..e848d3a843 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.Revit.Interfaces; +using Speckle.Converters.Common.Objects; +using Speckle.Converters.RevitShared.Helpers; 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. /// -public class SolidConversionToSpeckle : ITypedConverter> +public class SolidConversionToSpeckle : IRawConversion> { - private readonly ITypedConverter< - Dictionary>, - List - > _meshByMaterialConverter; + private readonly RevitConversionContextStack _contextStack; + private readonly IRawConversion>, List> _meshByMaterialConverter; public SolidConversionToSpeckle( - ITypedConverter>, List> meshByMaterialConverter + RevitConversionContextStack contextStack, + IRawConversion>, 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 Convert(IRevitSolid target) + public List RawConvert(DB.Solid target) { var meshesByMaterial = GetTriangulatedMeshesFromSolidByMaterial(target); - return _meshByMaterialConverter.Convert(meshesByMaterial); + return _meshByMaterialConverter.RawConvert(meshesByMaterial); } - private Dictionary> GetTriangulatedMeshesFromSolidByMaterial(IRevitSolid solid) + private Dictionary> GetTriangulatedMeshesFromSolidByMaterial(DB.Solid solid) { - var result = new Dictionary>(); - foreach (IRevitFace face in solid.Faces) + var result = new Dictionary>(); + foreach (DB.Face face in solid.Faces) { - if (!result.TryGetValue(face.MaterialElementId, out var mat)) + if (!result.ContainsKey(face.MaterialElementId)) { - mat = new List(); - result[face.MaterialElementId] = mat; + result[face.MaterialElementId] = new List(); } - mat.Add(face.Triangulate()); + + result[face.MaterialElementId].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 ad04f5d8db..e97cf962f4 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,28 +1,27 @@ -using Speckle.Converters.Common.Objects; +using Speckle.Converters.Common.Objects; using Speckle.Converters.RevitShared.Services; -using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared.ToSpeckle; -public class VectorToSpeckleConverter : ITypedConverter +public class VectorToSpeckleConverter : ITypedConverter { private readonly IReferencePointConverter _referencePointConverter; - private readonly IScalingServiceToSpeckle _scalingService; + private readonly ScalingServiceToSpeckle _scalingService; public VectorToSpeckleConverter( IReferencePointConverter referencePointConverter, - IScalingServiceToSpeckle scalingService + ScalingServiceToSpeckle scalingService ) { _referencePointConverter = referencePointConverter; _scalingService = scalingService; } - public SOG.Vector Convert(IRevitXYZ target) + public SOG.Vector Convert(DB.XYZ target) { // POC: originally had a concept of not transforming, but this was // optional arg defaulting to false - removing the argument appeared to break nothing - var extPt = _referencePointConverter.ConvertToExternalCoordindates(target, false); + DB.XYZ 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 4f5996e1e5..bf250d06c3 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,26 +1,24 @@ -using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; +using Speckle.Converters.RevitShared.Helpers; using Speckle.Converters.RevitShared.Services; -using Speckle.Revit.Interfaces; -#pragma warning disable IDE0130 namespace Speckle.Converters.RevitShared.ToSpeckle; -public class XyzConversionToPoint : ITypedConverter +public class XyzConversionToPoint : ITypedConverter { - private readonly IScalingServiceToSpeckle _toSpeckleScalingService; - private readonly IConversionContextStack _contextStack; + private readonly ScalingServiceToSpeckle _toSpeckleScalingService; + private readonly IRevitConversionContextStack _contextStack; public XyzConversionToPoint( - IScalingServiceToSpeckle toSpeckleScalingService, - IConversionContextStack contextStack + ScalingServiceToSpeckle toSpeckleScalingService, + IRevitConversionContextStack contextStack ) { _toSpeckleScalingService = toSpeckleScalingService; _contextStack = contextStack; } - public SOG.Point Convert(IRevitXYZ target) + public SOG.Point Convert(DB.XYZ 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 bea059ceaa..33e1d7fea2 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LevelConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LevelConversionToSpeckle.cs @@ -1,19 +1,18 @@ -using Speckle.Converters.Common.Objects; +using Speckle.Converters.Common.Objects; using Speckle.Converters.RevitShared.Services; -using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared; +namespace Speckle.Converters.RevitShared.ToSpeckle; -public class LevelConversionToSpeckle : ITypedConverter +public class LevelConversionToSpeckle : ITypedConverter { - private readonly IScalingServiceToSpeckle _scalingService; + private readonly ScalingServiceToSpeckle _scalingService; - public LevelConversionToSpeckle(IScalingServiceToSpeckle scalingService) + public LevelConversionToSpeckle(ScalingServiceToSpeckle scalingService) { _scalingService = scalingService; } - public SOBR.RevitLevel Convert(IRevitLevel target) + public SOBR.RevitLevel Convert(DB.Level 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 ac47cb38cf..29d3378103 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LocationConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/LocationConversionToSpeckle.cs @@ -1,43 +1,34 @@ -using Objects; -using Speckle.Converters.Common; +using Objects; using Speckle.Converters.Common.Objects; +using Speckle.Converters.Common; using Speckle.Core.Models; -using Speckle.Revit.Interfaces; -#pragma warning disable IDE0130 -namespace Speckle.Converters.RevitShared; +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(IRevitLocation target) + public Base Convert(DB.Location 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 !. - } - var point = target.ToLocationPoint(); - if (point is not null) + return target switch { - return _xyzConverter.Convert(point.Point); - } - throw new SpeckleConversionException($"Unexpected location type {target.GetType()}"); + 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), + _ => 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 50062f88fd..f7f48974f7 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/MaterialConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/MaterialConversionToSpeckle.cs @@ -1,12 +1,11 @@ using Objects.Other; using Speckle.Converters.Common.Objects; -using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared; +namespace Speckle.Converters.RevitShared.ToSpeckle; -public class MaterialConversionToSpeckle : ITypedConverter +public class MaterialConversionToSpeckle : ITypedConverter { - public RenderMaterial Convert(IRevitMaterial target) => + public RenderMaterial Convert(DB.Material 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 deleted file mode 100644 index 111e12a42b..0000000000 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ModelCurveArrArrayConverterToSpeckle.cs +++ /dev/null @@ -1,30 +0,0 @@ -using Objects.Geometry; -using Speckle.Converters.Common.Objects; -using Speckle.Revit.Interfaces; -#pragma warning disable IDE0130 -namespace Speckle.Converters.RevitShared; - -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 new file mode 100644 index 0000000000..d294360b2d --- /dev/null +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ModelCurveArrArrayToSpeckleConverter.cs @@ -0,0 +1,28 @@ +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 ce1690ee5d..5bfd4d11bb 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,21 @@ -using Objects; +using Objects; using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; +using Speckle.Converters.RevitShared.Helpers; using Speckle.Converters.RevitShared.Services; -using Speckle.Revit.Interfaces; -#pragma warning disable IDE0130 -namespace Speckle.Converters.RevitShared; -public sealed class ModelCurveArrayToSpeckleConverter : ITypedConverter +namespace Speckle.Converters.RevitShared.Raw; + +internal sealed class ModelCurveArrayToSpeckleConverter : ITypedConverter { - private readonly IConversionContextStack _contextStack; - private readonly IScalingServiceToSpeckle _scalingService; - private readonly ITypedConverter _curveConverter; + private readonly IRevitConversionContextStack _contextStack; + private readonly ScalingServiceToSpeckle _scalingService; + private readonly ITypedConverter _curveConverter; public ModelCurveArrayToSpeckleConverter( - IConversionContextStack contextStack, - IScalingServiceToSpeckle scalingService, - ITypedConverter curveConverter + IRevitConversionContextStack contextStack, + ScalingServiceToSpeckle scalingService, + ITypedConverter curveConverter ) { _contextStack = contextStack; @@ -23,12 +23,10 @@ ITypedConverter curveConverter _curveConverter = curveConverter; } - public SOG.Polycurve Convert(IRevitModelCurveArray target) => Convert((IReadOnlyList)target); - - public SOG.Polycurve Convert(IReadOnlyList target) + public SOG.Polycurve Convert(DB.ModelCurveArray target) { SOG.Polycurve polycurve = new(); - var curves = target.Select(mc => mc.GeometryCurve).ToArray(); + var curves = target.Cast().Select(mc => mc.GeometryCurve).ToArray(); if (curves.Length == 0) { @@ -38,7 +36,7 @@ public SOG.Polycurve Convert(IReadOnlyList target) var start = curves[0].GetEndPoint(0); var end = curves[^1].GetEndPoint(1); polycurve.units = _contextStack.Current.SpeckleUnits; - polycurve.closed = start.DistanceTo(end) < RevitConstants.TOLERANCE; + polycurve.closed = start.DistanceTo(end) < RevitConversionContextStack.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 ae2a9ec5c5..a0b1f01da5 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ParameterConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ParameterConversionToSpeckle.cs @@ -1,35 +1,30 @@ -using Speckle.Converters.Common.Objects; +using Autodesk.Revit.DB; +using Speckle.Converters.Common.Objects; using Speckle.Converters.RevitShared.Extensions; using Speckle.Converters.RevitShared.Helpers; -using Speckle.Revit.Interfaces; -namespace Speckle.Converters.RevitShared; +namespace Speckle.Converters.RevitShared.ToSpeckle; -public class ParameterConversionToSpeckle : ITypedConverter +public class ParameterConversionToSpeckle : ITypedConverter { - private readonly IParameterValueExtractor _valueExtractor; - private readonly IRevitFormatOptionsUtils _revitFormatOptionsUtils; + private readonly ParameterValueExtractor _valueExtractor; - public ParameterConversionToSpeckle( - IParameterValueExtractor valueExtractor, - IRevitFormatOptionsUtils revitFormatOptionsUtils - ) + public ParameterConversionToSpeckle(ParameterValueExtractor valueExtractor) { _valueExtractor = valueExtractor; - _revitFormatOptionsUtils = revitFormatOptionsUtils; } - public SOBR.Parameter Convert(IRevitParameter target) + public SOBR.Parameter Convert(Parameter target) { string internalName = target.GetInternalName(); - IRevitForgeTypeId? unitTypeId = null; - if (target.StorageType is RevitStorageType.Double) + ForgeTypeId? unitTypeId = null; + if (target.StorageType is StorageType.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(); } - IRevitDefinition definition = target.Definition; + Definition definition = target.Definition; return new SOBR.Parameter() { @@ -38,7 +33,7 @@ public SOBR.Parameter Convert(IRevitParameter target) isShared = target.IsShared, isReadOnly = target.IsReadOnly, name = definition.Name, - units = unitTypeId?.GetSymbol(_revitFormatOptionsUtils) ?? "None", + units = unitTypeId?.GetSymbol() ?? "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 deleted file mode 100644 index 7ebcaf9d95..0000000000 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/RevitVersionConversionHelper.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using Speckle.InterfaceGenerator; -using Speckle.Revit.Interfaces; - -namespace Speckle.Converters.RevitShared; - -[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/Services/ReferencePointConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ReferencePointConverter.cs similarity index 51% rename from DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/ReferencePointConverter.cs rename to DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ReferencePointConverter.cs index 4eef722c25..4704184be6 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/ReferencePointConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ReferencePointConverter.cs @@ -1,25 +1,12 @@ using System.Diagnostics.CodeAnalysis; -using Speckle.Converters.Common; -using Speckle.InterfaceGenerator; -using Speckle.Revit.Interfaces; +using Speckle.Converters.RevitShared.Helpers; namespace Speckle.Converters.RevitShared; -[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] +// 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 public class ReferencePointConverter : IReferencePointConverter { // POC: probably not the best place for this @@ -27,33 +14,21 @@ public class ReferencePointConverter : IReferencePointConverter private const string REFPOINT_PROJECT_BASE = "Project Base"; private const string REFPOINT_SURVEY = "Survey"; - 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 - ) + private readonly RevitConversionSettings _revitSettings; + private readonly IRevitConversionContextStack _contextStack; + + private readonly Dictionary _docTransforms = new(); + + public ReferencePointConverter(IRevitConversionContextStack contextStack, RevitConversionSettings revitSettings) { _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 IRevitXYZ ConvertToExternalCoordindates(IRevitXYZ inbound, bool isPoint) + public DB.XYZ ConvertToExternalCoordindates(DB.XYZ inbound, bool isPoint) { var rpt = GetDocReferencePointTransform(_contextStack.Current.Document); return isPoint ? rpt.OfPoint(inbound) : rpt.OfVector(inbound); @@ -61,13 +36,13 @@ public IRevitXYZ ConvertToExternalCoordindates(IRevitXYZ 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 IRevitTransform GetDocReferencePointTransform(IRevitDocument doc) + public DB.Transform GetDocReferencePointTransform(DB.Document 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 IRevitTransform? transform)) + if (!_docTransforms.TryGetValue(id, out DB.Transform? transform)) { // get from settings var referencePointSetting = _revitSettings.TryGetSettingString("reference-point", out string value) @@ -81,25 +56,25 @@ public IRevitTransform GetDocReferencePointTransform(IRevitDocument doc) } [SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope")] - public IRevitTransform GetReferencePointTransform(string referencePointSetting) + public DB.Transform GetReferencePointTransform(string referencePointSetting) { // first get the main doc base points and reference setting transform - var referencePointTransform = _transformUtils.Identity; + var referencePointTransform = DB.Transform.Identity; // POC: bogus disposal below - var points = _revitFilterFactory - .CreateFilteredElementCollector(_contextStack.Current.Document) - .OfClass() + var points = new DB.FilteredElementCollector(_contextStack.Current.Document) + .OfClass(typeof(DB.BasePoint)) + .Cast() .ToList(); - var projectPoint = NotNullExtensions.NotNull(points.FirstOrDefault(o => o.IsShared == false), "No projectPoint"); - var surveyPoint = NotNullExtensions.NotNull(points.FirstOrDefault(o => o.IsShared), "No surveyPoint"); + var projectPoint = points.FirstOrDefault(o => o.IsShared == false); + var surveyPoint = points.FirstOrDefault(o => o.IsShared); // 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 = _transformUtils.CreateTranslation(projectPoint.Position); + referencePointTransform = DB.Transform.CreateTranslation(projectPoint.Position); break; case REFPOINT_SURVEY: @@ -107,12 +82,12 @@ public IRevitTransform GetReferencePointTransform(string referencePointSetting) // retrieve the survey point rotation from the project point // POC: should a null angle resolve to 0? - var angle = projectPoint.GetParameter(RevitBuiltInParameter.BASEPOINT_ANGLETON_PARAM)?.AsDouble() ?? 0; + var angle = projectPoint.get_Parameter(DB.BuiltInParameter.BASEPOINT_ANGLETON_PARAM)?.AsDouble() ?? 0; // POC: following disposed incorrectly or early or maybe a false negative? - referencePointTransform = _transformUtils + referencePointTransform = DB.Transform .CreateTranslation(surveyPoint.Position) - .Multiply(_transformUtils.CreateRotation(_revitXyzUtils.BasisZ, angle)); + .Multiply(DB.Transform.CreateRotation(DB.XYZ.BasisZ, angle)); break; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitConstants.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitConstants.cs deleted file mode 100644 index 79a6ef167a..0000000000 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitConstants.cs +++ /dev/null @@ -1,6 +0,0 @@ -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 new file mode 100644 index 0000000000..3fb4466120 --- /dev/null +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitConversionSettings.cs @@ -0,0 +1,19 @@ +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 new file mode 100644 index 0000000000..78790ee19e --- /dev/null +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitRootToHostConverter.cs @@ -0,0 +1,50 @@ +using Speckle.Converters.Common; +using Speckle.Converters.Common.Objects; +using Speckle.Core.Models; +using Speckle.Converters.RevitShared.Helpers; + +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 ParameterValueExtractor _parameterValueExtractor; + + public RevitRootToHostConverter( + IConverterResolver toSpeckle, + ParameterValueExtractor 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 DB.Element element) + { + // POC: is this the right place? + result.applicationId = element.UniqueId; + + _parameterValueExtractor.RemoveUniqueId(element.UniqueId); + } + + return result; + } +} 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 e6de0840fa..e1d7a7a62b 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/RevitToSpeckleUnitConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/RevitToSpeckleUnitConverter.cs @@ -1,30 +1,29 @@ 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(IRevitUnitUtils revitUnitUtils) + public RevitToSpeckleUnitConverter() { - _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; + _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; } // POC: maybe just convert, it's not a Try method - public string ConvertOrThrow(IRevitForgeTypeId hostUnit) + public string ConvertOrThrow(DB.ForgeTypeId hostUnit) { - if (_unitMapping.TryGetValue(hostUnit.TypeId, out string value)) + if (_unitMapping.TryGetValue(hostUnit, 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 57ba7be5f2..a0c2779048 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/ScalingServiceToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Services/ScalingServiceToSpeckle.cs @@ -1,27 +1,20 @@ -using Speckle.Converters.Common; -using Speckle.InterfaceGenerator; -using Speckle.Revit.Interfaces; +using Autodesk.Revit.DB; +using Speckle.Converters.RevitShared.Helpers; 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 -[GenerateAutoInterface] -public sealed class ScalingServiceToSpeckle : IScalingServiceToSpeckle +public sealed class ScalingServiceToSpeckle { private readonly double _defaultLengthConversionFactor; - private readonly IRevitUnitUtils _revitUnitUtils; // POC: this seems like the reverse relationship - public ScalingServiceToSpeckle( - IConversionContextStack contextStack, - IRevitUnitUtils revitUnitUtils - ) + public ScalingServiceToSpeckle(IRevitConversionContextStack contextStack) { - _revitUnitUtils = revitUnitUtils; // POC: this is accurate for the current context stack - var documentUnits = contextStack.Current.Document.GetUnits(); - var formatOptions = documentUnits.GetFormatOptions(_revitUnitUtils.Length); + Units documentUnits = contextStack.Current.Document.GetUnits(); + FormatOptions formatOptions = documentUnits.GetFormatOptions(SpecTypeId.Length); var lengthUnitsTypeId = formatOptions.GetUnitTypeId(); _defaultLengthConversionFactor = ScaleStatic(1, lengthUnitsTypeId); } @@ -33,14 +26,14 @@ IRevitUnitUtils revitUnitUtils public double ScaleLength(double length) => length * _defaultLengthConversionFactor; // POC: not sure about this??? - public double Scale(double value, IRevitForgeTypeId forgeTypeId) + public double Scale(double value, ForgeTypeId forgeTypeId) { return ScaleStatic(value, forgeTypeId); } // POC: not sure why this is needed??? - private double ScaleStatic(double value, IRevitForgeTypeId forgeTypeId) + private static double ScaleStatic(double value, ForgeTypeId forgeTypeId) { - return _revitUnitUtils.ConvertFromInternalUnits(value, forgeTypeId); + return UnitUtils.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 575c0093e6..5e5d29480e 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,6 +9,72 @@ 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 0a246e3b2f..f7a94c8d1f 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/BaseTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/BaseTopLevelConverterToSpeckle.cs @@ -1,4 +1,4 @@ -using Speckle.Converters.Common; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Core.Models; 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 3dd7ed8cb6..c3de2636aa 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs @@ -1,31 +1,30 @@ +using Autodesk.Revit.DB; using Objects; using Objects.BuiltElements.Revit; using Objects.Geometry; using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Converters.RevitShared.Helpers; -using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared.ToSpeckle; -[NameAndRankValue(nameof(IRevitCeiling), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -internal sealed class CeilingTopLevelConverterToSpeckle - : BaseTopLevelConverterToSpeckle +[NameAndRankValue(nameof(DB.Ceiling), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +internal sealed class CeilingTopLevelConverterToSpeckle : BaseTopLevelConverterToSpeckle { - private readonly ITypedConverter> _curveArrArrayConverter; - private readonly ITypedConverter _levelConverter; - private readonly IParameterValueExtractor _parameterValueExtractor; - private readonly IParameterObjectAssigner _parameterObjectAssigner; - private readonly IDisplayValueExtractor _displayValueExtractor; + private readonly ITypedConverter> _curveArrArrayConverter; + private readonly ITypedConverter _levelConverter; + private readonly ParameterValueExtractor _parameterValueExtractor; + private readonly ParameterObjectAssigner _parameterObjectAssigner; + private readonly DisplayValueExtractor _displayValueExtractor; //private readonly HostedElementConversionToSpeckle _hostedElementConverter; public CeilingTopLevelConverterToSpeckle( - ITypedConverter> curveArrArrayConverter, - ITypedConverter levelConverter, - IParameterValueExtractor parameterValueExtractor, - IParameterObjectAssigner parameterObjectAssigner, - IDisplayValueExtractor displayValueExtractor + ITypedConverter> curveArrArrayConverter, + ITypedConverter levelConverter, + ParameterValueExtractor parameterValueExtractor, + ParameterObjectAssigner parameterObjectAssigner, + DisplayValueExtractor displayValueExtractor ) { _curveArrArrayConverter = curveArrArrayConverter; @@ -35,14 +34,14 @@ IDisplayValueExtractor displayValueExtractor _displayValueExtractor = displayValueExtractor; } - public override RevitCeiling Convert(IRevitCeiling target) + public override RevitCeiling Convert(DB.Ceiling target) { - var sketch = target.Document.GetElement(target.SketchId).NotNull().ToSketch().NotNull(); + var sketch = (Sketch)target.Document.GetElement(target.SketchId); List profiles = _curveArrArrayConverter.Convert(sketch.Profile); var speckleCeiling = new RevitCeiling(); - var elementType = target.Document.GetElement(target.GetTypeId()).NotNull().ToType().NotNull(); + var elementType = (ElementType)target.Document.GetElement(target.GetTypeId()); speckleCeiling.type = elementType.Name; speckleCeiling.family = elementType.FamilyName; @@ -59,7 +58,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.GetValueAsDocumentObject(target, DB.BuiltInParameter.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 1f87f63696..c9c9ca5e14 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.RevitShared.ToSpeckle; +namespace Speckle.Converters.Revit2023.ToSpeckle; -[NameAndRankValue(nameof(IRevitDirectShape), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public class DirectShapeTopLevelConverterToSpeckle : BaseTopLevelConverterToSpeckle +[NameAndRankValue(nameof(DB.DirectShape), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +public class DirectShapeTopLevelConverterToSpeckle : BaseTopLevelConverterToSpeckle { - private readonly IConversionContextStack _contextStack; - private readonly IParameterObjectAssigner _parameterObjectAssigner; - private readonly IDisplayValueExtractor _displayValueExtractor; + private readonly IRevitConversionContextStack _contextStack; + private readonly ParameterObjectAssigner _parameterObjectAssigner; + private readonly DisplayValueExtractor _displayValueExtractor; public DirectShapeTopLevelConverterToSpeckle( - IParameterObjectAssigner parameterObjectAssigner, - IConversionContextStack contextStack, - IDisplayValueExtractor displayValueExtractor + ParameterObjectAssigner parameterObjectAssigner, + IRevitConversionContextStack contextStack, + DisplayValueExtractor displayValueExtractor ) { _parameterObjectAssigner = parameterObjectAssigner; @@ -24,7 +24,7 @@ IDisplayValueExtractor displayValueExtractor _displayValueExtractor = displayValueExtractor; } - public override SOBR.DirectShape Convert(IRevitDirectShape target) + public override SOBR.DirectShape Convert(DB.DirectShape 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 cbd1cd9e06..c3b96c9001 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ElementTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ElementTopLevelConverterToSpeckle.cs @@ -1,27 +1,25 @@ -using Speckle.Converters.Common; +using Speckle.Converters.Common; +using Objects.BuiltElements.Revit; using Speckle.Converters.RevitShared.Helpers; -using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared.ToSpeckle; // POC: not currently used? clearly some missing pieces -[NameAndRankValue(nameof(IRevitElement), 0)] -public class ElementTopLevelConverterToSpeckle : BaseTopLevelConverterToSpeckle +[NameAndRankValue(nameof(DB.Element), 0)] +public class ElementTopLevelConverterToSpeckle : BaseTopLevelConverterToSpeckle { - private readonly IDisplayValueExtractor _displayValueExtractor; + private readonly DisplayValueExtractor _displayValueExtractor; - public ElementTopLevelConverterToSpeckle(IDisplayValueExtractor displayValueExtractor) + public ElementTopLevelConverterToSpeckle(DisplayValueExtractor displayValueExtractor) { _displayValueExtractor = displayValueExtractor; } - public override SOBR.RevitElement Convert(IRevitElement target) + public override RevitElement Convert(DB.Element target) { - SOBR.RevitElement speckleElement = new(); + RevitElement speckleElement = new(); - var element = target.Document.GetElement(target.GetTypeId()); - var symbol = element?.ToFamilySymbol(); - if (symbol is not null) + if (target.Document.GetElement(target.GetTypeId()) is DB.FamilySymbol symbol) { 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 8dfeb7907a..d46c93794f 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ExtrusionRoofToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ExtrusionRoofToSpeckleTopLevelConverter.cs @@ -1,34 +1,32 @@ using Objects.BuiltElements.Revit.RevitRoof; -using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Converters.RevitShared.Extensions; +using Speckle.Converters.Common; using Speckle.Converters.RevitShared.Helpers; -using Speckle.Revit.Interfaces; + +using Speckle.Converters.RevitShared.Extensions; namespace Speckle.Converters.RevitShared.ToSpeckle; -[NameAndRankValue(nameof(IRevitExtrusionRoof), 0)] +[NameAndRankValue(nameof(DB.ExtrusionRoof), 0)] public class ExtrusionRoofToSpeckleTopLevelConverter - : BaseTopLevelConverterToSpeckle + : BaseTopLevelConverterToSpeckle { - 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; + 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; public ExtrusionRoofToSpeckleTopLevelConverter( - ITypedConverter levelConverter, - ITypedConverter modelCurveArrayConverter, - ITypedConverter pointConverter, - IParameterValueExtractor parameterValueExtractor, - IDisplayValueExtractor displayValueExtractor, - IHostedElementConversionToSpeckle hostedElementConverter, - IParameterObjectAssigner parameterObjectAssigner, - IRevitFilterFactory revitFilterFactory + ITypedConverter levelConverter, + ITypedConverter modelCurveArrayConverter, + ITypedConverter pointConverter, + ParameterValueExtractor parameterValueExtractor, + DisplayValueExtractor displayValueExtractor, + HostedElementConversionToSpeckle hostedElementConverter, + ParameterObjectAssigner parameterObjectAssigner ) { _levelConverter = levelConverter; @@ -38,36 +36,35 @@ IRevitFilterFactory revitFilterFactory _displayValueExtractor = displayValueExtractor; _hostedElementConverter = hostedElementConverter; _parameterObjectAssigner = parameterObjectAssigner; - _revitFilterFactory = revitFilterFactory; } - public override RevitExtrusionRoof Convert(IRevitExtrusionRoof target) + public override RevitExtrusionRoof Convert(DB.ExtrusionRoof target) { var speckleExtrusionRoof = new RevitExtrusionRoof { - start = _parameterValueExtractor.GetValueAsDouble(target, RevitBuiltInParameter.EXTRUSION_START_PARAM), - end = _parameterValueExtractor.GetValueAsDouble(target, RevitBuiltInParameter.EXTRUSION_END_PARAM) + start = _parameterValueExtractor.GetValueAsDouble(target, DB.BuiltInParameter.EXTRUSION_START_PARAM), + end = _parameterValueExtractor.GetValueAsDouble(target, DB.BuiltInParameter.EXTRUSION_END_PARAM) }; - var plane = target.GetProfile()[0].SketchPlane.GetPlane(); + var plane = target.GetProfile().get_Item(0).SketchPlane.GetPlane(); speckleExtrusionRoof.referenceLine = new SOG.Line( _pointConverter.Convert(plane.Origin.Add(plane.XVec.Normalize().Negate())), _pointConverter.Convert(plane.Origin) ); - var level = _parameterValueExtractor.GetValueAsRevitLevel( + var level = _parameterValueExtractor.GetValueAsDocumentObject( target, - RevitBuiltInParameter.ROOF_CONSTRAINT_LEVEL_PARAM + DB.BuiltInParameter.ROOF_CONSTRAINT_LEVEL_PARAM ); speckleExtrusionRoof.level = _levelConverter.Convert(level); speckleExtrusionRoof.outline = _modelCurveArrayConverter.Convert(target.GetProfile()); - var elementType = target.Document.GetElement(target.GetTypeId()).NotNull().ToType().NotNull(); + var elementType = (DB.ElementType)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(_revitFilterFactory)) + .ConvertHostedElements(target.GetHostedElementIds()) .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 b408d104cc..446dcd4383 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FamilyInstanceTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FamilyInstanceTopLevelConverterToSpeckle.cs @@ -1,26 +1,24 @@ -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; // 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(IRevitFamilyInstance), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public sealed class FamilyInstanceTopLevelConverterToSpeckle - : BaseTopLevelConverterToSpeckle +[NameAndRankValue(nameof(DB.FamilyInstance), 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; @@ -29,13 +27,13 @@ public FamilyInstanceTopLevelConverterToSpeckle( _braceConversion = braceConversion; } - public override Base Convert(IRevitFamilyInstance target) + public override Base Convert(DB.FamilyInstance target) { return target.StructuralType switch { - RevitStructuralType.Beam => _beamConversion.Convert(target), - RevitStructuralType.Column => _columnConversion.Convert(target), - RevitStructuralType.Brace => _braceConversion.Convert(target), + DB.Structure.StructuralType.Beam => _beamConversion.Convert(target), + DB.Structure.StructuralType.Column => _columnConversion.Convert(target), + DB.Structure.StructuralType.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 eb292cae5b..13d0d3086f 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs @@ -1,33 +1,32 @@ 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.RevitShared.ToSpeckle; +namespace Speckle.Converters.Common; // 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(IRevitFloor), 0)] -public class FloorTopLevelConverterToSpeckle : BaseTopLevelConverterToSpeckle +[NameAndRankValue(nameof(DB.Floor), 0)] +public class FloorTopLevelConverterToSpeckle : BaseTopLevelConverterToSpeckle { - private readonly ITypedConverter> _curveArrArrayConverter; - private readonly ITypedConverter _levelConverter; - private readonly IParameterValueExtractor _parameterValueExtractor; - private readonly IParameterObjectAssigner _parameterObjectAssigner; - private readonly IDisplayValueExtractor _displayValueExtractor; + private readonly ITypedConverter> _curveArrArrayConverter; + private readonly ITypedConverter _levelConverter; + private readonly ParameterValueExtractor _parameterValueExtractor; + private readonly ParameterObjectAssigner _parameterObjectAssigner; + private readonly DisplayValueExtractor _displayValueExtractor; private readonly ISlopeArrowExtractor _slopeArrowExtractor; public FloorTopLevelConverterToSpeckle( - ITypedConverter> curveArrArrayConverter, - ITypedConverter levelConverter, - IParameterValueExtractor parameterValueExtractor, - IParameterObjectAssigner parameterObjectAssigner, - IDisplayValueExtractor displayValueExtractor, + ITypedConverter> curveArrArrayConverter, + ITypedConverter levelConverter, + ParameterValueExtractor parameterValueExtractor, + ParameterObjectAssigner parameterObjectAssigner, + DisplayValueExtractor displayValueExtractor, ISlopeArrowExtractor slopeArrowExtractor ) { @@ -39,14 +38,14 @@ ISlopeArrowExtractor slopeArrowExtractor _slopeArrowExtractor = slopeArrowExtractor; } - public override SOBR.RevitFloor Convert(IRevitFloor target) + public override SOBR.RevitFloor Convert(DB.Floor target) { SOBR.RevitFloor speckleFloor = new(); - var sketch = target.Document.GetElement(target.SketchId).NotNull().ToSketch().NotNull(); + var sketch = (DB.Sketch)target.Document.GetElement(target.SketchId); List profiles = _curveArrArrayConverter.Convert(sketch.Profile); - IRevitElementType type = target.Document.GetElement(target.GetTypeId()).NotNull().ToType().NotNull(); + DB.ElementType type = (DB.ElementType)target.Document.GetElement(target.GetTypeId()); speckleFloor.family = type.FamilyName; speckleFloor.type = type.Name; @@ -62,13 +61,13 @@ public override SOBR.RevitFloor Convert(IRevitFloor target) speckleFloor.voids = profiles.Skip(1).ToList(); } - var level = _parameterValueExtractor.GetValueAsRevitLevel(target, RevitBuiltInParameter.LEVEL_PARAM); - speckleFloor.level = _levelConverter.Convert(level.NotNull()); + var level = _parameterValueExtractor.GetValueAsDocumentObject(target, DB.BuiltInParameter.LEVEL_PARAM); + speckleFloor.level = _levelConverter.Convert(level); speckleFloor.structural = - _parameterValueExtractor.GetValueAsBool(target, RevitBuiltInParameter.FLOOR_PARAM_IS_STRUCTURAL) ?? false; + _parameterValueExtractor.GetValueAsBool(target, DB.BuiltInParameter.FLOOR_PARAM_IS_STRUCTURAL) ?? false; double? slopeParam = null; - if (_parameterValueExtractor.TryGetValueAsDouble(target, RevitBuiltInParameter.ROOF_SLOPE, out var slope)) + if (_parameterValueExtractor.TryGetValueAsDouble(target, DB.BuiltInParameter.ROOF_SLOPE, out var slope)) { // Divide by 100 to convert from percentage to unitless ratio (rise over run) slopeParam = slope / 100d; @@ -84,10 +83,9 @@ public override SOBR.RevitFloor Convert(IRevitFloor target) return speckleFloor; } - private void TryAssignSlopeFromSlopeArrow(IRevitFloor target, SOBR.RevitFloor speckleFloor, double? slopeParam) + private void TryAssignSlopeFromSlopeArrow(DB.Floor target, SOBR.RevitFloor speckleFloor, double? slopeParam) { - var slopeArrow = _slopeArrowExtractor.GetSlopeArrow(target); - if (slopeArrow is null) + if (_slopeArrowExtractor.GetSlopeArrow(target) is not DB.ModelLine 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 78600db3ff..1c8e74bb04 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 Objects; +using Autodesk.Revit.DB; +using Objects; +using Objects.BuiltElements.Revit; 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; -[NameAndRankValue(nameof(IRevitFootPrintRoof), 0)] +[NameAndRankValue(nameof(DB.FootPrintRoof), 0)] public class FootPrintRoofToSpeckleTopLevelConverter - : BaseTopLevelConverterToSpeckle + : BaseTopLevelConverterToSpeckle { - 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; + private readonly ITypedConverter _levelConverter; + private readonly ITypedConverter _modelCurveArrArrayConverter; + private readonly ParameterValueExtractor _parameterValueExtractor; + private readonly DisplayValueExtractor _displayValueExtractor; + private readonly HostedElementConversionToSpeckle _hostedElementConverter; + private readonly ParameterObjectAssigner _parameterObjectAssigner; public FootPrintRoofToSpeckleTopLevelConverter( - ITypedConverter levelConverter, - ITypedConverter modelCurveArrArrayConverter, - IParameterValueExtractor parameterValueExtractor, - IDisplayValueExtractor displayValueExtractor, - IHostedElementConversionToSpeckle hostedElementConverter, - IParameterObjectAssigner parameterObjectAssigner, - IRevitFilterFactory revitFilterFactory + ITypedConverter levelConverter, + ITypedConverter modelCurveArrArrayConverter, + ParameterValueExtractor parameterValueExtractor, + DisplayValueExtractor displayValueExtractor, + HostedElementConversionToSpeckle hostedElementConverter, + ParameterObjectAssigner parameterObjectAssigner ) { _levelConverter = levelConverter; @@ -36,20 +36,25 @@ IRevitFilterFactory revitFilterFactory _displayValueExtractor = displayValueExtractor; _hostedElementConverter = hostedElementConverter; _parameterObjectAssigner = parameterObjectAssigner; - _revitFilterFactory = revitFilterFactory; } - public override RevitFootprintRoof Convert(IRevitFootPrintRoof target) + public override RevitFootprintRoof Convert(FootPrintRoof target) { - var baseLevel = _parameterValueExtractor.GetValueAsRevitLevel(target, RevitBuiltInParameter.ROOF_BASE_LEVEL_PARAM); + var baseLevel = _parameterValueExtractor.GetValueAsDocumentObject( + target, + DB.BuiltInParameter.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. - IRevitLevel? topLevel; - _parameterValueExtractor.TryGetValueAsRevitLevel(target, RevitBuiltInParameter.ROOF_UPTO_LEVEL_PARAM, out topLevel); + _parameterValueExtractor.TryGetValueAsDocumentObject( + target, + DB.BuiltInParameter.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, RevitBuiltInParameter.ROOF_SLOPE, out var slope); + _parameterValueExtractor.TryGetValueAsDouble(target, DB.BuiltInParameter.ROOF_SLOPE, out var slope); RevitFootprintRoof speckleFootprintRoof = new() @@ -67,7 +72,7 @@ public override RevitFootprintRoof Convert(IRevitFootPrintRoof target) speckleFootprintRoof.outline = profiles.FirstOrDefault(); speckleFootprintRoof.voids = profiles.Skip(1).ToList(); - var elementType = target.Document.GetElement(target.GetTypeId()).NotNull().ToType().NotNull(); + var elementType = (ElementType)target.Document.GetElement(target.GetTypeId()); speckleFootprintRoof.type = elementType.Name; speckleFootprintRoof.family = elementType.FamilyName; @@ -76,7 +81,7 @@ public override RevitFootprintRoof Convert(IRevitFootPrintRoof target) _parameterObjectAssigner.AssignParametersToBase(target, speckleFootprintRoof); speckleFootprintRoof.displayValue = _displayValueExtractor.GetDisplayValue(target); speckleFootprintRoof.elements = _hostedElementConverter - .ConvertHostedElements(target.GetHostedElementIds(_revitFilterFactory)) + .ConvertHostedElements(target.GetHostedElementIds()) .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 b927329b7e..f9643119e0 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/HostedElementConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/HostedElementConversionToSpeckle.cs @@ -1,7 +1,7 @@ -using Speckle.Converters.Common; +using Autodesk.Revit.DB; +using Speckle.Converters.Common; +using Speckle.Converters.RevitShared.Helpers; using Speckle.Core.Models; -using Speckle.InterfaceGenerator; -using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared.ToSpeckle; @@ -9,26 +9,22 @@ namespace Speckle.Converters.RevitShared.ToSpeckle; // 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 -[GenerateAutoInterface] -public class HostedElementConversionToSpeckle : IHostedElementConversionToSpeckle +public class HostedElementConversionToSpeckle { private readonly IRootToSpeckleConverter _converter; - private readonly IConversionContextStack _contextStack; + private readonly IRevitConversionContextStack _contextStack; - public HostedElementConversionToSpeckle( - IRootToSpeckleConverter converter, - IConversionContextStack contextStack - ) + public HostedElementConversionToSpeckle(IRootToSpeckleConverter converter, IRevitConversionContextStack contextStack) { _converter = converter; _contextStack = contextStack; } - public IEnumerable ConvertHostedElements(IEnumerable hostedElementIds) + public IEnumerable ConvertHostedElements(IEnumerable hostedElementIds) { foreach (var elemId in hostedElementIds) { - IRevitElement element = _contextStack.Current.Document.GetElement(elemId).NotNull(); + Element 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 f305468ece..240cbe4713 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ModelCurveToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ModelCurveToSpeckleTopLevelConverter.cs @@ -1,29 +1,28 @@ -using Objects; +using Objects; using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Revit.Interfaces; +using Speckle.Converters.RevitShared.Helpers; 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 -[NameAndRankValue(nameof(IRevitModelCurve), 0)] -public class ModelCurveToSpeckleTopLevelConverter - : BaseTopLevelConverterToSpeckle +[NameAndRankValue(nameof(DB.ModelCurve), 0)] +public class ModelCurveToSpeckleTopLevelConverter : BaseTopLevelConverterToSpeckle { - private readonly ITypedConverter _curveConverter; - private readonly IConversionContextStack _conversionContext; + private readonly ITypedConverter _curveConverter; + private readonly IRevitConversionContextStack _conversionContext; public ModelCurveToSpeckleTopLevelConverter( - ITypedConverter curveConverter, - IConversionContextStack conversionContext + ITypedConverter curveConverter, + IRevitConversionContextStack conversionContext ) { _curveConverter = curveConverter; _conversionContext = conversionContext; } - public override SOBR.Curve.ModelCurve Convert(IRevitModelCurve target) + public override SOBR.Curve.ModelCurve Convert(DB.ModelCurve 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 805671c0a7..77f9ce831c 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/RoofBaseToSpeckleTopLevelTopLevelConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/RoofBaseToSpeckleTopLevelTopLevelConverter.cs @@ -1,45 +1,40 @@ -using Objects.BuiltElements.Revit.RevitRoof; +using Autodesk.Revit.DB; +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; -[NameAndRankValue(nameof(IRevitRoofBase), 0)] +[NameAndRankValue(nameof(DB.RoofBase), 0)] internal sealed class RoofBaseToSpeckleTopLevelTopLevelConverter - : BaseTopLevelConverterToSpeckle + : BaseTopLevelConverterToSpeckle { - private readonly IDisplayValueExtractor _displayValueExtractor; - private readonly IHostedElementConversionToSpeckle _hostedElementConverter; - private readonly IParameterObjectAssigner _parameterObjectAssigner; - private readonly IRevitFilterFactory _revitFilterFactory; + private readonly DisplayValueExtractor _displayValueExtractor; + private readonly HostedElementConversionToSpeckle _hostedElementConverter; + private readonly ParameterObjectAssigner _parameterObjectAssigner; public RoofBaseToSpeckleTopLevelTopLevelConverter( - IDisplayValueExtractor displayValueExtractor, - IHostedElementConversionToSpeckle hostedElementConverter, - IParameterObjectAssigner parameterObjectAssigner, - IRevitFilterFactory revitFilterFactory + DisplayValueExtractor displayValueExtractor, + HostedElementConversionToSpeckle hostedElementConverter, + ParameterObjectAssigner parameterObjectAssigner ) { _displayValueExtractor = displayValueExtractor; _hostedElementConverter = hostedElementConverter; _parameterObjectAssigner = parameterObjectAssigner; - _revitFilterFactory = revitFilterFactory; } - public override RevitRoof Convert(IRevitRoofBase target) + public override RevitRoof Convert(RoofBase target) { RevitRoof revitRoof = new(); - var elementType = target.Document.GetElement(target.GetTypeId()).NotNull().ToType().NotNull(); + var elementType = (ElementType)target.Document.GetElement(target.GetTypeId()); revitRoof.type = elementType.Name; revitRoof.family = elementType.FamilyName; _parameterObjectAssigner.AssignParametersToBase(target, revitRoof); revitRoof.displayValue = _displayValueExtractor.GetDisplayValue(target); - revitRoof.elements = _hostedElementConverter - .ConvertHostedElements(target.GetHostedElementIds(_revitFilterFactory)) - .ToList(); + revitRoof.elements = _hostedElementConverter.ConvertHostedElements(target.GetHostedElementIds()).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 6baaa3d6aa..6e4e1f91cb 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/RoomTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/RoomTopLevelConverterToSpeckle.cs @@ -3,27 +3,26 @@ using Speckle.Converters.Common.Objects; using Speckle.Converters.RevitShared.Helpers; using Speckle.Core.Models; -using Speckle.Revit.Interfaces; namespace Speckle.Converters.RevitShared.ToSpeckle; -[NameAndRankValue(nameof(IRevitRoom), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public class RoomTopLevelConverterToSpeckle : BaseTopLevelConverterToSpeckle +[NameAndRankValue(nameof(DBA.Room), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +public class RoomTopLevelConverterToSpeckle : BaseTopLevelConverterToSpeckle { - 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; + 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; public RoomTopLevelConverterToSpeckle( - IDisplayValueExtractor displayValueExtractor, - IParameterObjectAssigner parameterObjectAssigner, - ITypedConverter levelConverter, - IParameterValueExtractor parameterValueExtractor, - ITypedConverter locationConverter, - ITypedConverter, SOG.Polycurve> boundarySegmentConverter + DisplayValueExtractor displayValueExtractor, + ParameterObjectAssigner parameterObjectAssigner, + ITypedConverter levelConverter, + ParameterValueExtractor parameterValueExtractor, + ITypedConverter locationConverter, + ITypedConverter, SOG.Polycurve> boundarySegmentConverter ) { _displayValueExtractor = displayValueExtractor; @@ -34,19 +33,19 @@ public RoomTopLevelConverterToSpeckle( _boundarySegmentConverter = boundarySegmentConverter; } - public override SOBE.Room Convert(IRevitRoom target) + public override SOBE.Room Convert(DBA.Room target) { var number = target.Number; - var name = _parameterValueExtractor.GetValueAsString(target, RevitBuiltInParameter.ROOM_NAME); - var area = _parameterValueExtractor.GetValueAsDouble(target, RevitBuiltInParameter.ROOM_AREA); + var name = _parameterValueExtractor.GetValueAsString(target, DB.BuiltInParameter.ROOM_NAME); + var area = _parameterValueExtractor.GetValueAsDouble(target, DB.BuiltInParameter.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() - .Select(c => (ICurve)_boundarySegmentConverter.Convert(c.ToList())) + .GetBoundarySegments(new DB.SpatialElementBoundaryOptions()) + .Select(c => (ICurve)_boundarySegmentConverter.Convert(c)) .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 ce34b66376..eea4ea51c9 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/TopographyTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/TopographyTopLevelConverterToSpeckle.cs @@ -1,28 +1,27 @@ -using Speckle.Converters.Common; +using Speckle.Converters.Common; 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(IRevitTopographySurface), 0)] +[NameAndRankValue(nameof(DBA.TopographySurface), 0)] public class TopographyTopLevelConverterToSpeckle - : BaseTopLevelConverterToSpeckle + : BaseTopLevelConverterToSpeckle { - private readonly IDisplayValueExtractor _displayValueExtractor; - private readonly IParameterObjectAssigner _parameterObjectAssigner; + private readonly DisplayValueExtractor _displayValueExtractor; + private readonly ParameterObjectAssigner _parameterObjectAssigner; public TopographyTopLevelConverterToSpeckle( - IDisplayValueExtractor displayValueExtractor, - IParameterObjectAssigner parameterObjectAssigner + DisplayValueExtractor displayValueExtractor, + ParameterObjectAssigner parameterObjectAssigner ) { _displayValueExtractor = displayValueExtractor; _parameterObjectAssigner = parameterObjectAssigner; } - public override SOBR.RevitTopography Convert(IRevitTopographySurface target) + public override SOBR.RevitTopography Convert(DBA.TopographySurface 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 e9a0dbafc1..8e0cce3ba9 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs @@ -6,35 +6,32 @@ using Speckle.Core.Models.Extensions; using Speckle.Converters.RevitShared.Extensions; using Objects.BuiltElements.Revit; -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(IRevitWall), 0)] -public class WallTopLevelConverterToSpeckle : BaseTopLevelConverterToSpeckle +[NameAndRankValue(nameof(DB.Wall), 0)] +public class WallTopLevelConverterToSpeckle : BaseTopLevelConverterToSpeckle { - 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 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 IRootToSpeckleConverter _converter; - private readonly IRevitFilterFactory _revitFilterFactory; public WallTopLevelConverterToSpeckle( - ITypedConverter curveConverter, - ITypedConverter levelConverter, - ITypedConverter> curveArrArrayConverter, - IConversionContextStack contextStack, - IParameterValueExtractor parameterValueExtractor, - IDisplayValueExtractor displayValueExtractor, - IParameterObjectAssigner parameterObjectAssigner, - IRootToSpeckleConverter converter, - IRevitFilterFactory revitFilterFactory + ITypedConverter curveConverter, + ITypedConverter levelConverter, + ITypedConverter> curveArrArrayConverter, + IRevitConversionContextStack contextStack, + ParameterValueExtractor parameterValueExtractor, + DisplayValueExtractor displayValueExtractor, + ParameterObjectAssigner parameterObjectAssigner, + IRootToSpeckleConverter converter ) { _curveConverter = curveConverter; @@ -45,10 +42,9 @@ IRevitFilterFactory revitFilterFactory _displayValueExtractor = displayValueExtractor; _parameterObjectAssigner = parameterObjectAssigner; _converter = converter; - _revitFilterFactory = revitFilterFactory; } - public override SOBR.RevitWall Convert(IRevitWall target) + public override SOBR.RevitWall Convert(DB.Wall target) { SOBR.RevitWall speckleWall = new() { family = target.WallType.FamilyName.ToString(), type = target.WallType.Name }; @@ -61,10 +57,9 @@ public override SOBR.RevitWall Convert(IRevitWall target) return speckleWall; } - private void AssignSpecificParameters(IRevitWall target, RevitWall speckleWall) + private void AssignSpecificParameters(DB.Wall target, RevitWall speckleWall) { - var locationCurve = target.GetLocationAsLocationCurve(); - if (locationCurve is null) + if (target.Location is not DB.LocationCurve locationCurve) { throw new SpeckleConversionException( "Incorrect assumption was made that all Revit Wall location properties would be of type \"LocationCurve\"" @@ -73,41 +68,46 @@ 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.GetValueAsDocumentObject( + target, + DB.BuiltInParameter.WALL_BASE_CONSTRAINT + ); speckleWall.level = _levelConverter.Convert(level); - var topLevel = _parameterValueExtractor.GetValueAsRevitLevel(target, RevitBuiltInParameter.WALL_BASE_CONSTRAINT); + var topLevel = _parameterValueExtractor.GetValueAsDocumentObject( + target, + DB.BuiltInParameter.WALL_BASE_CONSTRAINT + ); speckleWall.topLevel = _levelConverter.Convert(topLevel); // POC : what to do if these parameters are unset (instead of assigning default) _ = _parameterValueExtractor.TryGetValueAsDouble( target, - RevitBuiltInParameter.WALL_USER_HEIGHT_PARAM, + DB.BuiltInParameter.WALL_USER_HEIGHT_PARAM, out double? height ); speckleWall.height = height ?? 0; _ = _parameterValueExtractor.TryGetValueAsDouble( target, - RevitBuiltInParameter.WALL_BASE_OFFSET, + DB.BuiltInParameter.WALL_BASE_OFFSET, out double? baseOffset ); speckleWall.baseOffset = baseOffset ?? 0; _ = _parameterValueExtractor.TryGetValueAsDouble( target, - RevitBuiltInParameter.WALL_TOP_OFFSET, + DB.BuiltInParameter.WALL_TOP_OFFSET, out double? topOffset ); speckleWall.topOffset = topOffset ?? 0; speckleWall.structural = - _parameterValueExtractor.GetValueAsBool(target, RevitBuiltInParameter.WALL_STRUCTURAL_SIGNIFICANT) ?? false; + _parameterValueExtractor.GetValueAsBool(target, DB.BuiltInParameter.WALL_STRUCTURAL_SIGNIFICANT) ?? false; speckleWall.flipped = target.Flipped; } - private List GetChildElements(IRevitWall target) + private List GetChildElements(DB.Wall target) { List wallChildren = new(); - var grid = target.CurtainGrid; - if (grid is not null) + if (target.CurtainGrid is DB.CurtainGrid grid) { wallChildren.AddRange(ConvertElements(grid.GetMullionIds())); wallChildren.AddRange(ConvertElements(grid.GetPanelIds())); @@ -116,19 +116,19 @@ private List GetChildElements(IRevitWall target) { wallChildren.AddRange(ConvertElements(target.GetStackedWallMemberIds())); } - wallChildren.AddRange(ConvertElements(target.GetHostedElementIds(_revitFilterFactory))); + wallChildren.AddRange(ConvertElements(target.GetHostedElementIds())); return wallChildren; } - private IEnumerable ConvertElements(IEnumerable elementIds) + private IEnumerable ConvertElements(IEnumerable elementIds) { - foreach (IRevitElementId elementId in elementIds) + foreach (DB.ElementId elementId in elementIds) { - yield return _converter.Convert(_contextStack.Current.Document.GetElement(elementId).NotNull()); + yield return _converter.Convert(_contextStack.Current.Document.GetElement(elementId)); } } - private void AssignDisplayValue(IRevitWall target, RevitWall speckleWall) + private void AssignDisplayValue(DB.Wall target, RevitWall speckleWall) { if (target.CurtainGrid is null) { @@ -159,9 +159,9 @@ private void AssignHostedElements(SOBR.RevitWall speckleWall, List hostedO } } - private void AssignVoids(IRevitWall target, SOBR.RevitWall speckleWall) + private void AssignVoids(DB.Wall target, SOBR.RevitWall speckleWall) { - IRevitCurveArrArray? profile = target.Document.GetElement(target.SketchId)?.ToSketch()?.Profile; + DB.CurveArrArray? profile = ((DB.Sketch)target.Document.GetElement(target.SketchId))?.Profile; if (profile is null) { return; diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7.DependencyInjection/RhinoConverterModule.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7.DependencyInjection/RhinoConverterModule.cs index 6c315439fe..9117848c90 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7.DependencyInjection/RhinoConverterModule.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7.DependencyInjection/RhinoConverterModule.cs @@ -1,7 +1,7 @@ using Speckle.Autofac.DependencyInjection; using Speckle.Converters.Common; +using Rhino; using Speckle.Converters.Common.DependencyInjection; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.DependencyInjection; @@ -9,9 +9,8 @@ public class RhinoConverterModule : ISpeckleModule { public void Load(SpeckleContainerBuilder builder) { - builder.AddConverterCommon(); + builder.AddConverterCommon(); // single stack per conversion - builder.AddScoped, RhinoConversionContextStack>(); - builder.AddScoped(); + builder.AddScoped, RhinoConversionContextStack>(); } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7.DependencyInjection/RhinoRootElementProvider.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7.DependencyInjection/RhinoRootElementProvider.cs deleted file mode 100644 index 58a13d8107..0000000000 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7.DependencyInjection/RhinoRootElementProvider.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Speckle.Converters.Common; -using Speckle.Rhino7.Interfaces; - -namespace Speckle.Converters.Rhino7.DependencyInjection; - -public class RhinoRootElementProvider : IRootElementProvider -{ - public Type GetRootType() => typeof(IRhinoObject); -} diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7.DependencyInjection/Speckle.Converters.Rhino7.DependencyInjection.csproj b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7.DependencyInjection/Speckle.Converters.Rhino7.DependencyInjection.csproj index a9a52748e3..78870eeb41 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7.DependencyInjection/Speckle.Converters.Rhino7.DependencyInjection.csproj +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7.DependencyInjection/Speckle.Converters.Rhino7.DependencyInjection.csproj @@ -11,6 +11,6 @@ - + diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7.DependencyInjection/packages.lock.json b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7.DependencyInjection/packages.lock.json index 7e98fae831..a897641f42 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7.DependencyInjection/packages.lock.json +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7.DependencyInjection/packages.lock.json @@ -18,18 +18,18 @@ "resolved": "1.14.1", "contentHash": "mOOmFYwad3MIOL14VCjj02LljyF1GNw1wP0YVlxtcPvqdxjGGMNdNJJxHptlry3MOd8b40Flm8RPOM8JOlN2sQ==" }, + "RhinoCommon": { + "type": "Direct", + "requested": "[7.13.21348.13001, )", + "resolved": "7.13.21348.13001", + "contentHash": "JQdaNw61ddBqIe08E9O4N/grwrN1hjDHcYW7tWylwCZyFR7SepoCD4NS+6LN6+oSQhNbhLi9Bf+hQOFYFdRAEA==" + }, "Speckle.InterfaceGenerator": { "type": "Direct", "requested": "[0.9.5, )", "resolved": "0.9.5", "contentHash": "oU/L7pN1R7q8KkbrpQ3WJnHirPHqn+9DEA7asOcUiggV5dzVg1A/VYs7GOSusD24njxXh03tE3a2oTLOjt3cVg==" }, - "Speckle.Rhino7.Interfaces": { - "type": "Direct", - "requested": "[0.1.1-preview.0.28, )", - "resolved": "0.1.1-preview.0.28", - "contentHash": "TcbfXlRMnQRat1JodgW+YW5FflTYem1GGo9DtKA+6iAuVaYagN5dxsrM5LE6M3pCnEV9rkEQOjFo7sgnnbo4mw==" - }, "GraphQL.Client": { "type": "Transitive", "resolved": "6.0.0", @@ -216,6 +216,11 @@ "resolved": "13.0.2", "contentHash": "g1BejUZwax5PRfL6xHgLEK23sqHWOgOj9hE7RvfRRlN00AGt8GnPYt8HedSK7UB3HiRW8zCA9Pn0iiYxCK24BA==" }, + "Speckle.Revit2023.Interfaces": { + "type": "Transitive", + "resolved": "0.1.1-preview.0.24", + "contentHash": "BSVpOUJc9g6ISrw8GxvtkglTlITpHEDYNOhxv1ZPbckBsI0yO36JiphhQV4q57ERqD9PpCozUJkVhlCaxWeS6A==" + }, "SQLitePCLRaw.bundle_e_sqlite3": { "type": "Transitive", "resolved": "2.1.4", @@ -377,8 +382,8 @@ "speckle.converters.rhino7": { "type": "Project", "dependencies": { - "Speckle.Converters.Common": "[2.0.999-local, )", - "Speckle.Rhino7.Interfaces": "[0.1.1-preview.0.28, )" + "RhinoCommon": "[7.13.21348.13001, )", + "Speckle.Converters.Common": "[2.0.999-local, )" } }, "Microsoft.Extensions.Logging.Abstractions": { diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/GlobalUsings.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/GlobalUsings.cs index c88d8e3105..baa44c188e 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/GlobalUsings.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/GlobalUsings.cs @@ -1,2 +1,3 @@ +global using RG = Rhino.Geometry; global using SOG = Objects.Geometry; global using SOP = Objects.Primitive; diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/RhinoConversionContextStack.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/RhinoConversionContextStack.cs index 799f32b350..79ac2f77a4 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/RhinoConversionContextStack.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/RhinoConversionContextStack.cs @@ -1,6 +1,6 @@ using System.Diagnostics.CodeAnalysis; +using Rhino; using Speckle.Converters.Common; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7; @@ -10,11 +10,8 @@ namespace Speckle.Converters.Rhino7; "CA1711:Identifiers should not have incorrect suffix", Justification = "Name ends in Stack but it is in fact a Stack, just not inheriting from `System.Collections.Stack`" )] -public class RhinoConversionContextStack : ConversionContextStack +public class RhinoConversionContextStack : ConversionContextStack { - public RhinoConversionContextStack( - IRhinoDocFactory rhinoDocFactory, - IHostToSpeckleUnitConverter unitConverter - ) - : base(rhinoDocFactory.ActiveDoc(), rhinoDocFactory.ActiveDoc().ModelUnitSystem, unitConverter) { } + public RhinoConversionContextStack(IHostToSpeckleUnitConverter unitConverter) + : base(RhinoDoc.ActiveDoc, RhinoDoc.ActiveDoc.ModelUnitSystem, unitConverter) { } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/RhinoToSpeckleUnitConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/RhinoToSpeckleUnitConverter.cs index f7953bc383..4f4f9c77e4 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/RhinoToSpeckleUnitConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/RhinoToSpeckleUnitConverter.cs @@ -1,29 +1,29 @@ -using Speckle.Converters.Common; +using Rhino; +using Speckle.Converters.Common; using Speckle.Core.Kits; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7; -public class RhinoToSpeckleUnitConverter : IHostToSpeckleUnitConverter +public class RhinoToSpeckleUnitConverter : IHostToSpeckleUnitConverter { - private readonly Dictionary _unitMapping = new(); + private readonly Dictionary _unitMapping = new(); public RhinoToSpeckleUnitConverter() { // POC: CNX-9269 Add unit test to ensure these don't change. - _unitMapping[RhinoUnitSystem.None] = Units.Meters; - _unitMapping[RhinoUnitSystem.Millimeters] = Units.Millimeters; - _unitMapping[RhinoUnitSystem.Centimeters] = Units.Centimeters; - _unitMapping[RhinoUnitSystem.Meters] = Units.Meters; - _unitMapping[RhinoUnitSystem.Kilometers] = Units.Kilometers; - _unitMapping[RhinoUnitSystem.Inches] = Units.Inches; - _unitMapping[RhinoUnitSystem.Feet] = Units.Feet; - _unitMapping[RhinoUnitSystem.Yards] = Units.Yards; - _unitMapping[RhinoUnitSystem.Miles] = Units.Miles; - _unitMapping[RhinoUnitSystem.Unset] = Units.Meters; + _unitMapping[UnitSystem.None] = Units.Meters; + _unitMapping[UnitSystem.Millimeters] = Units.Millimeters; + _unitMapping[UnitSystem.Centimeters] = Units.Centimeters; + _unitMapping[UnitSystem.Meters] = Units.Meters; + _unitMapping[UnitSystem.Kilometers] = Units.Kilometers; + _unitMapping[UnitSystem.Inches] = Units.Inches; + _unitMapping[UnitSystem.Feet] = Units.Feet; + _unitMapping[UnitSystem.Yards] = Units.Yards; + _unitMapping[UnitSystem.Miles] = Units.Miles; + _unitMapping[UnitSystem.Unset] = Units.Meters; } - public string ConvertOrThrow(RhinoUnitSystem hostUnit) + public string ConvertOrThrow(UnitSystem hostUnit) { if (_unitMapping.TryGetValue(hostUnit, out string value)) { diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/Speckle.Converters.Rhino7.csproj b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/Speckle.Converters.Rhino7.csproj index 206a1eecf0..bf1bdbd6de 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/Speckle.Converters.Rhino7.csproj +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/Speckle.Converters.Rhino7.csproj @@ -3,11 +3,12 @@ net48 + - + - + diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/SpeckleToHostGeometryBaseTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/SpeckleToHostGeometryBaseTopLevelConverter.cs index 3d5e09c1a0..75ff2162c2 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/SpeckleToHostGeometryBaseTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/SpeckleToHostGeometryBaseTopLevelConverter.cs @@ -1,28 +1,25 @@ -using Speckle.Converters.Common; +using Rhino; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Core.Kits; using Speckle.Core.Models; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7; public abstract class SpeckleToHostGeometryBaseTopLevelConverter : IToHostTopLevelConverter where TIn : Base - where TOut : IRhinoGeometryBase + where TOut : RG.GeometryBase { - protected IConversionContextStack ContextStack { get; private set; } + protected IConversionContextStack ContextStack { get; private set; } private readonly ITypedConverter _geometryBaseConverter; - private readonly IRhinoTransformFactory _transformFactory; protected SpeckleToHostGeometryBaseTopLevelConverter( - IConversionContextStack contextStack, - ITypedConverter geometryBaseConverter, - IRhinoTransformFactory transformFactory + IConversionContextStack contextStack, + ITypedConverter geometryBaseConverter ) { ContextStack = contextStack; _geometryBaseConverter = geometryBaseConverter; - _transformFactory = transformFactory; } public object Convert(Base target) @@ -38,7 +35,7 @@ public object Convert(Base target) if (castedBase["units"] is string units) { var scaleFactor = Units.GetConversionFactor(units, ContextStack.Current.SpeckleUnits); - var scale = _transformFactory.Scale(_transformFactory.Origin, scaleFactor); + var scale = RG.Transform.Scale(RG.Point3d.Origin, scaleFactor); result.Transform(scale); } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/ArcToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/ArcToHostConverter.cs index 63d745dec6..0068c38ef2 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/ArcToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/ArcToHostConverter.cs @@ -1,38 +1,34 @@ using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; /// /// Converts a SpeckleArcRaw object to a Rhino.Geometry.Arc object or Rhino.Geometry.ArcCurve object. /// -public class ArcToHostConverter : ITypedConverter, ITypedConverter +public class ArcToHostConverter : ITypedConverter, ITypedConverter { - private readonly ITypedConverter _pointConverter; - private readonly ITypedConverter _intervalConverter; - private readonly IRhinoArcFactory _rhinoArcFactory; + private readonly ITypedConverter _pointConverter; + private readonly ITypedConverter _intervalConverter; public ArcToHostConverter( - ITypedConverter pointConverter, - ITypedConverter intervalConverter, - IRhinoArcFactory rhinoArcFactory + ITypedConverter pointConverter, + ITypedConverter intervalConverter ) { _pointConverter = pointConverter; this._intervalConverter = intervalConverter; - _rhinoArcFactory = rhinoArcFactory; } /// - /// Converts a object to a object. + /// Converts a object to a object. /// /// The Speckle Arc object to convert. - /// The converted object. + /// The converted object. /// ⚠️ This conversion does NOT perform scaling. ///
⚠️ This method does not preserve the original curve domain
- public IRhinoArc Convert(SOG.Arc target) + public RG.Arc Convert(SOG.Arc target) { - var rhinoArc = _rhinoArcFactory.Create( + var rhinoArc = new RG.Arc( _pointConverter.Convert(target.startPoint), _pointConverter.Convert(target.midPoint), _pointConverter.Convert(target.endPoint) @@ -43,16 +39,16 @@ public IRhinoArc Convert(SOG.Arc target) // POC: CNX-9271 Potential code-smell by directly implementing the interface. We should discuss this further but // since we're using the interfaces instead of the direct type, this may not be an issue. /// - /// Converts a object to a object. + /// Converts a object to a object. /// /// The object to convert. - /// The converted object. + /// The converted object. /// ⚠️ This conversion does NOT perform scaling. - ///
⚠️ Converting to instead of preserves the domain of the curve.
- IRhinoArcCurve ITypedConverter.Convert(SOG.Arc target) + ///
⚠️ Converting to instead of preserves the domain of the curve.
+ RG.ArcCurve ITypedConverter.Convert(SOG.Arc target) { var rhinoArc = Convert(target); - var arcCurve = _rhinoArcFactory.Create(rhinoArc, _intervalConverter.Convert(target.domain)); + var arcCurve = new RG.ArcCurve(rhinoArc) { Domain = _intervalConverter.Convert(target.domain) }; return arcCurve; } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/BrepToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/BrepToHostConverter.cs index c579d736a1..db94e2f7f0 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/BrepToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/BrepToHostConverter.cs @@ -1,26 +1,24 @@ using Objects; +using Rhino; using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class BrepToHostConverter : ITypedConverter +public class BrepToHostConverter : ITypedConverter { - private readonly IConversionContextStack _contextStack; - private readonly ITypedConverter _curveConverter; - private readonly ITypedConverter _surfaceConverter; - private readonly ITypedConverter _pointConverter; - private readonly ITypedConverter _intervalConverter; - private readonly IRhinoBrepFactory _rhinoBrepFactory; + private readonly IConversionContextStack _contextStack; + private readonly ITypedConverter _curveConverter; + private readonly ITypedConverter _surfaceConverter; + private readonly ITypedConverter _pointConverter; + private readonly ITypedConverter _intervalConverter; public BrepToHostConverter( - IConversionContextStack contextStack, - ITypedConverter curveConverter, - ITypedConverter surfaceConverter, - ITypedConverter pointConverter, - ITypedConverter intervalConverter, - IRhinoBrepFactory rhinoBrepFactory + IConversionContextStack contextStack, + ITypedConverter curveConverter, + ITypedConverter surfaceConverter, + ITypedConverter pointConverter, + ITypedConverter intervalConverter ) { _contextStack = contextStack; @@ -28,11 +26,10 @@ IRhinoBrepFactory rhinoBrepFactory _surfaceConverter = surfaceConverter; _pointConverter = pointConverter; _intervalConverter = intervalConverter; - _rhinoBrepFactory = rhinoBrepFactory; } /// - /// Converts a Speckle to a Rhino . + /// Converts a Speckle to a Rhino . /// /// /// This method converts a Speckle Brep object to its equivalent Rhino Brep representation. @@ -43,11 +40,11 @@ IRhinoBrepFactory rhinoBrepFactory /// The Speckle Brep object to be converted. /// The equivalent Rhino Brep object. /// ⚠️ This conversion does NOT perform scaling. - public IRhinoBrep Convert(SOG.Brep target) + public RG.Brep Convert(SOG.Brep target) { var tolerance = _contextStack.Current.Document.ModelAbsoluteTolerance; - var rhinoBrep = _rhinoBrepFactory.Create(); + var rhinoBrep = new RG.Brep(); // Geometry goes in first, always. Order doesn't matter. target.Curve3D.ForEach(curve => rhinoBrep.AddEdgeCurve(_curveConverter.Convert(curve))); @@ -73,21 +70,21 @@ public IRhinoBrep Convert(SOG.Brep target) } /// - /// Converts a Speckle to a Rhino and adds it to the provided . + /// Converts a Speckle to a Rhino and adds it to the provided . /// /// /// A consists of individual trims. There are special cases for singular trims and trims with defined edge indices. /// Note that edge cases in Brep structures are not fully covered by this method and should be reviewed for robustness improvement. - /// This operation alters the state of the provided by adding a new loop. + /// This operation alters the state of the provided by adding a new loop. /// - /// The where the new loop will be added. + /// The where the new loop will be added. /// The to be converted and added to . /// The tolerance factor used when adding trims and setting their tolerances. - private void ConvertSpeckleBrepLoop(IRhinoBrep rhinoBrep, SOG.BrepLoop speckleLoop, double tol) + private void ConvertSpeckleBrepLoop(RG.Brep rhinoBrep, SOG.BrepLoop speckleLoop, double tol) { var f = rhinoBrep.Faces[speckleLoop.FaceIndex]; - rhinoBrep.Loops.Add((RhinoBrepLoopType)speckleLoop.Type, f); + rhinoBrep.Loops.Add((RG.BrepLoopType)speckleLoop.Type, f); // POC: This works but it doesn't fully cover all Brep edge cases and could be the cause of some of our failed Rhino->Rhino breps. // We should check Rhino.Inside as they have similar code structure. @@ -95,7 +92,7 @@ private void ConvertSpeckleBrepLoop(IRhinoBrep rhinoBrep, SOG.BrepLoop speckleLo .ToList() .ForEach(trim => { - IRhinoBrepTrim rhTrim; + RG.BrepTrim rhTrim; if (trim.EdgeIndex != -1) { rhTrim = rhinoBrep.Trims.Add( @@ -110,7 +107,7 @@ private void ConvertSpeckleBrepLoop(IRhinoBrep rhinoBrep, SOG.BrepLoop speckleLo rhTrim = rhinoBrep.Trims.AddSingularTrim( rhinoBrep.Vertices[trim.EndIndex], rhinoBrep.Loops[trim.LoopIndex], - (RhinoIsoStatus)trim.IsoStatus, + (RG.IsoStatus)trim.IsoStatus, trim.CurveIndex ); } @@ -119,8 +116,8 @@ private void ConvertSpeckleBrepLoop(IRhinoBrep rhinoBrep, SOG.BrepLoop speckleLo rhTrim = rhinoBrep.Trims.Add(trim.IsReversed, rhinoBrep.Loops[trim.LoopIndex], trim.CurveIndex); } - rhTrim.IsoStatus = (RhinoIsoStatus)trim.IsoStatus; - rhTrim.TrimType = (RhinoBrepTrimType)trim.TrimType; + rhTrim.IsoStatus = (RG.IsoStatus)trim.IsoStatus; + rhTrim.TrimType = (RG.BrepTrimType)trim.TrimType; rhTrim.SetTolerances(tol, tol); }); } @@ -136,7 +133,7 @@ private void ConvertSpeckleBrepLoop(IRhinoBrep rhinoBrep, SOG.BrepLoop speckleLo /// is untrimmed, and hence added directly as a reference to the curve it points to. /// If the edge is trimmed, it is added based on vertices and subdomain using the supplied tolerance /// - private void ConvertSpeckleBrepEdge(IRhinoBrep rhinoBrep, SOG.BrepEdge speckleEdge, double tolerance) + private void ConvertSpeckleBrepEdge(RG.Brep rhinoBrep, SOG.BrepEdge speckleEdge, double tolerance) { if ( speckleEdge.Domain == null @@ -161,11 +158,11 @@ private void ConvertSpeckleBrepEdge(IRhinoBrep rhinoBrep, SOG.BrepEdge speckleEd } /// - /// Converts a into a and adds it to the provided . + /// Converts a into a and adds it to the provided . /// /// The Rhinoceros brep geometry to which the converted face is added. /// The Speckle brep face to be converted and added. - private void ConvertSpeckleBrepFace(IRhinoBrep rhinoBrep, SOG.BrepFace speckleFace) + private void ConvertSpeckleBrepFace(RG.Brep rhinoBrep, SOG.BrepFace speckleFace) { var f = rhinoBrep.Faces.Add(speckleFace.SurfaceIndex); f.OrientationIsReversed = speckleFace.OrientationReversed; diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/CircleToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/CircleToHostConverter.cs index 1fbdfd4a2e..1431d3fc1a 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/CircleToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/CircleToHostConverter.cs @@ -1,52 +1,46 @@ using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; /// -/// This class is responsible for converting a into and objects. +/// This class is responsible for converting a into and objects. /// Implements the interface, -/// providing implementation for to and conversion. +/// providing implementation for to and conversion. /// -public class CircleToHostConverter - : ITypedConverter, - ITypedConverter +public class CircleToHostConverter : ITypedConverter, ITypedConverter { - private readonly ITypedConverter _planeConverter; - private readonly ITypedConverter _intervalConverter; - private readonly IRhinoCircleFactory _rhinoCircleFactory; + private readonly ITypedConverter _planeConverter; + private readonly ITypedConverter _intervalConverter; /// /// Constructs a new instance of the class. /// /// - /// An implementation of used to convert into . + /// An implementation of used to convert into . /// /// - /// An implementation of used to convert into . + /// An implementation of used to convert into . /// public CircleToHostConverter( - ITypedConverter intervalConverter, - ITypedConverter planeConverter, - IRhinoCircleFactory rhinoCircleFactory + ITypedConverter intervalConverter, + ITypedConverter planeConverter ) { _intervalConverter = intervalConverter; _planeConverter = planeConverter; - _rhinoCircleFactory = rhinoCircleFactory; } /// - /// Converts the given object into a object. + /// Converts the given object into a object. /// /// The object to convert. - /// The resulting object. + /// The resulting object. /// /// Thrown when the radius of the given object is null. /// /// ⚠️ This conversion does NOT perform scaling. - ///
⚠️ This conversion does not preserve the curve domain. If you need it preserved you must request a conversion to conversion instead
- public IRhinoCircle Convert(SOG.Circle target) + ///
⚠️ This conversion does not preserve the curve domain. If you need it preserved you must request a conversion to conversion instead
+ public RG.Circle Convert(SOG.Circle target) { if (target.radius == null) { @@ -56,9 +50,9 @@ public IRhinoCircle Convert(SOG.Circle target) var plane = _planeConverter.Convert(target.plane); var radius = target.radius.Value; - return _rhinoCircleFactory.Create(plane, radius); + return new RG.Circle(plane, radius); } - IRhinoArcCurve ITypedConverter.Convert(SOG.Circle target) => - _rhinoCircleFactory.Create(Convert(target), _intervalConverter.Convert(target.domain)); + RG.ArcCurve ITypedConverter.Convert(SOG.Circle target) => + new(Convert(target)) { Domain = _intervalConverter.Convert(target.domain) }; } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/CurveToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/CurveToHostConverter.cs index d96d413258..a61425dc2a 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/CurveToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/CurveToHostConverter.cs @@ -1,29 +1,28 @@ using Objects; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class CurveToHostConverter : ITypedConverter +public class CurveToHostConverter : ITypedConverter { - private readonly ITypedConverter _lineConverter; - private readonly ITypedConverter _arcConverter; - private readonly ITypedConverter _ellipseConverter; - private readonly ITypedConverter _spiralConverter; - private readonly ITypedConverter _circleConverter; - private readonly ITypedConverter _polylineConverter; - private readonly ITypedConverter _polyCurveConverter; - private readonly ITypedConverter _nurbsCurveConverter; + private readonly ITypedConverter _lineConverter; + private readonly ITypedConverter _arcConverter; + private readonly ITypedConverter _ellipseConverter; + private readonly ITypedConverter _spiralConverter; + private readonly ITypedConverter _circleConverter; + private readonly ITypedConverter _polylineConverter; + private readonly ITypedConverter _polyCurveConverter; + private readonly ITypedConverter _nurbsCurveConverter; public CurveToHostConverter( - ITypedConverter lineConverter, - ITypedConverter arcConverter, - ITypedConverter ellipseConverter, - ITypedConverter spiralConverter, - ITypedConverter circleConverter, - ITypedConverter polylineConverter, - ITypedConverter polyCurveConverter, - ITypedConverter nurbsCurveConverter + ITypedConverter lineConverter, + ITypedConverter arcConverter, + ITypedConverter ellipseConverter, + ITypedConverter spiralConverter, + ITypedConverter circleConverter, + ITypedConverter polylineConverter, + ITypedConverter polyCurveConverter, + ITypedConverter nurbsCurveConverter ) { _lineConverter = lineConverter; @@ -37,13 +36,13 @@ public CurveToHostConverter( } /// - /// Converts a given ICurve object to an IRhinoCurve object. + /// Converts a given ICurve object to an RG.Curve object. /// /// The ICurve object to convert. - /// The converted IRhinoCurve object. + /// The converted RG.Curve object. /// Thrown when the conversion is not supported for the given type of curve. /// ⚠️ This conversion does NOT perform scaling. - public IRhinoCurve Convert(ICurve target) => + public RG.Curve Convert(ICurve target) => target switch { SOG.Line line => _lineConverter.Convert(line), diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/EllipseToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/EllipseToHostConverter.cs index c45fa5c3ab..74f309a61f 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/EllipseToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/EllipseToHostConverter.cs @@ -1,57 +1,49 @@ using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; public class EllipseToHostConverter - : ITypedConverter, - ITypedConverter + : ITypedConverter, + ITypedConverter { - private readonly ITypedConverter _planeConverter; - private readonly ITypedConverter _intervalConverter; - private readonly IRhinoEllipseFactory _rhinoEllipseFactory; + private readonly ITypedConverter _planeConverter; + private readonly ITypedConverter _intervalConverter; public EllipseToHostConverter( - ITypedConverter planeConverter, - ITypedConverter intervalConverter, - IRhinoEllipseFactory rhinoEllipseFactory + ITypedConverter planeConverter, + ITypedConverter intervalConverter ) { _planeConverter = planeConverter; _intervalConverter = intervalConverter; - _rhinoEllipseFactory = rhinoEllipseFactory; } /// - /// Converts an instance of to an while preserving geometric properties. + /// Converts an instance of to an while preserving geometric properties. /// /// The instance to be converted. - /// The resulting after conversion. + /// The resulting after conversion. /// Thrown when or properties are null. /// ⚠️ This conversion does NOT perform scaling. - ///
⚠️ This conversion does not preserve the curve domain. If you need it preserved you must request a conversion to conversion instead
- public IRhinoEllipse Convert(SOG.Ellipse target) + ///
⚠️ This conversion does not preserve the curve domain. If you need it preserved you must request a conversion to conversion instead
+ public RG.Ellipse Convert(SOG.Ellipse target) { if (!target.firstRadius.HasValue || !target.secondRadius.HasValue) { throw new InvalidOperationException($"Ellipses cannot have null radii"); } - return _rhinoEllipseFactory.Create( - _planeConverter.Convert(target.plane), - target.firstRadius.Value, - target.secondRadius.Value - ); + return new RG.Ellipse(_planeConverter.Convert(target.plane), target.firstRadius.Value, target.secondRadius.Value); } /// - /// Converts the provided into a representation. + /// Converts the provided into a representation. /// /// The to convert. /// - /// A that represents the provided . + /// A that represents the provided . /// - IRhinoNurbsCurve ITypedConverter.Convert(SOG.Ellipse target) + RG.NurbsCurve ITypedConverter.Convert(SOG.Ellipse target) { var rhinoEllipse = Convert(target); var rhinoNurbsEllipse = rhinoEllipse.ToNurbsCurve(); diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/FlatPointListToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/FlatPointListToHostConverter.cs index 97c2786b44..f0363a387d 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/FlatPointListToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/FlatPointListToHostConverter.cs @@ -1,21 +1,14 @@ -using Speckle.Converters.Common.Objects; +using Rhino.Collections; +using Speckle.Converters.Common.Objects; using Speckle.Core.Logging; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; /// /// Converts a flat list of raw double values to a Point3dList. /// -public class FlatPointListToHostConverter : ITypedConverter, IRhinoPoint3dList> +public class FlatPointListToHostConverter : ITypedConverter, Point3dList> { - private readonly IRhinoPointFactory _rhinoPointFactory; - - public FlatPointListToHostConverter(IRhinoPointFactory rhinoPointFactory) - { - _rhinoPointFactory = rhinoPointFactory; - } - /// /// Converts a flat list of raw double values to a Point3dList. /// @@ -26,20 +19,20 @@ public FlatPointListToHostConverter(IRhinoPointFactory rhinoPointFactory) /// with the numbers being coordinates of each point in the format {x1, y1, z1, x2, y2, z2, ..., xN, yN, zN} /// /// Throws when the input list count is not a multiple of 3. - public IRhinoPoint3dList Convert(IReadOnlyList target) + public Point3dList Convert(IReadOnlyList target) { if (target.Count % 3 != 0) { throw new SpeckleException("Array malformed: length%3 != 0."); } - var points = new List(target.Count / 3); + var points = new List(target.Count / 3); for (int i = 2; i < target.Count; i += 3) { - points.Add(_rhinoPointFactory.Create(target[i - 2], target[i - 1], target[i])); + points.Add(new RG.Point3d(target[i - 2], target[i - 1], target[i])); } - return _rhinoPointFactory.Create(points); + return new Point3dList(points); } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/IntervalToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/IntervalToHostConverter.cs index ddaa476970..f201283ebd 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/IntervalToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/IntervalToHostConverter.cs @@ -1,17 +1,9 @@ using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class IntervalToHostConverter : ITypedConverter +public class IntervalToHostConverter : ITypedConverter { - private readonly IRhinoIntervalFactory _rhinoIntervalFactory; - - public IntervalToHostConverter(IRhinoIntervalFactory rhinoIntervalFactory) - { - _rhinoIntervalFactory = rhinoIntervalFactory; - } - /// /// Converts a Speckle Interval object to a Rhino.Geometry.Interval object. /// @@ -19,13 +11,13 @@ public IntervalToHostConverter(IRhinoIntervalFactory rhinoIntervalFactory) /// The converted Rhino.Geometry.Interval object. /// Thrown when the start or end value of the Interval is null. /// ⚠️ This conversion does NOT perform scaling. - public IRhinoInterval Convert(SOP.Interval target) + public RG.Interval Convert(SOP.Interval target) { if (!target.start.HasValue || !target.end.HasValue) // POC: CNX-9272 Interval start and end being nullable makes no sense. { throw new ArgumentException("Interval start/end cannot be null"); } - return _rhinoIntervalFactory.Create(target.start.Value, target.end.Value); + return new RG.Interval(target.start.Value, target.end.Value); } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/LineToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/LineToHostConverter.cs index a66222299f..c549e96741 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/LineToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/LineToHostConverter.cs @@ -1,20 +1,14 @@ using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class LineToHostConverter : ITypedConverter, ITypedConverter +public class LineToHostConverter : ITypedConverter, ITypedConverter { - private readonly ITypedConverter _pointConverter; - private readonly IRhinoLineFactory _rhinoLineFactory; + private readonly ITypedConverter _pointConverter; - public LineToHostConverter( - ITypedConverter pointConverter, - IRhinoLineFactory rhinoLineFactory - ) + public LineToHostConverter(ITypedConverter pointConverter) { _pointConverter = pointConverter; - _rhinoLineFactory = rhinoLineFactory; } /// @@ -26,16 +20,15 @@ IRhinoLineFactory rhinoLineFactory /// ///
⚠️ This conversion does not preserve the curve domain. /// If you need it preserved you must request a conversion to - /// conversion instead + /// conversion instead ///
- public IRhinoLine Convert(SOG.Line target) => - _rhinoLineFactory.Create(_pointConverter.Convert(target.start), _pointConverter.Convert(target.end)); + public RG.Line Convert(SOG.Line target) => + new(_pointConverter.Convert(target.start), _pointConverter.Convert(target.end)); /// /// Converts a Speckle Line object to a Rhino LineCurve object. /// /// The Speckle Line object to convert. /// Returns the resulting Rhino LineCurve object. - IRhinoLineCurve ITypedConverter.Convert(SOG.Line target) => - _rhinoLineFactory.Create(Convert(target)); + RG.LineCurve ITypedConverter.Convert(SOG.Line target) => new(Convert(target)); } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/MeshToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/MeshToHostConverter.cs index e24adb8ad1..d3917dafd3 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/MeshToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/MeshToHostConverter.cs @@ -1,28 +1,17 @@ using System.Drawing; using Objects.Utils; +using Rhino.Collections; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class MeshToHostConverter : ITypedConverter +public class MeshToHostConverter : ITypedConverter { - private readonly ITypedConverter, IRhinoPoint3dList> _pointListConverter; - private readonly IRhinoMeshFactory _rhinoMeshFactory; - private readonly IRhinoNgonFactory _rhinoNgonFactory; - private readonly IRhinoPointFactory _rhinoPointFactory; - - public MeshToHostConverter( - ITypedConverter, IRhinoPoint3dList> pointListConverter, - IRhinoMeshFactory rhinoMeshFactory, - IRhinoNgonFactory rhinoNgonFactory, - IRhinoPointFactory rhinoPointFactory - ) + private readonly ITypedConverter, Point3dList> _pointListConverter; + + public MeshToHostConverter(ITypedConverter, Point3dList> pointListConverter) { _pointListConverter = pointListConverter; - _rhinoMeshFactory = rhinoMeshFactory; - _rhinoNgonFactory = rhinoNgonFactory; - _rhinoPointFactory = rhinoPointFactory; } /// @@ -31,11 +20,11 @@ IRhinoPointFactory rhinoPointFactory /// The Speckle mesh object to convert. /// A Rhino mesh object converted from the Speckle mesh. /// ⚠️ This conversion does NOT perform scaling. - public IRhinoMesh Convert(SOG.Mesh target) + public RG.Mesh Convert(SOG.Mesh target) { target.AlignVerticesWithTexCoordsByIndex(); - IRhinoMesh m = _rhinoMeshFactory.Create(); + RG.Mesh m = new(); var vertices = _pointListConverter.Convert(target.vertices); var colors = target.colors.Select(Color.FromArgb).ToArray(); @@ -54,7 +43,7 @@ public IRhinoMesh Convert(SOG.Mesh target) // POC: CNX-9274 We should abstract this into the `Mesh` class, or some utility class adjacent to it // All converters need to do this so it's going to be a source of repetition // and it is directly tied to how we serialise the data in the mesh. - private void AssignMeshFaces(SOG.Mesh target, IRhinoMesh m) + private void AssignMeshFaces(SOG.Mesh target, RG.Mesh m) { int i = 0; while (i < target.faces.Count) @@ -70,12 +59,14 @@ private void AssignMeshFaces(SOG.Mesh target, IRhinoMesh m) if (n == 3) { // triangle - m.Faces.AddFace(target.faces[i + 1], target.faces[i + 2], target.faces[i + 3]); + m.Faces.AddFace(new RG.MeshFace(target.faces[i + 1], target.faces[i + 2], target.faces[i + 3])); } else if (n == 4) { // quad - m.Faces.AddFace(target.faces[i + 1], target.faces[i + 2], target.faces[i + 3], target.faces[i + 4]); + m.Faces.AddFace( + new RG.MeshFace(target.faces[i + 1], target.faces[i + 2], target.faces[i + 3], target.faces[i + 4]) + ); } else { @@ -85,10 +76,11 @@ private void AssignMeshFaces(SOG.Mesh target, IRhinoMesh m) var faceIndices = new List(triangles.Count); for (int t = 0; t < triangles.Count; t += 3) { - faceIndices.Add(m.Faces.AddFace(triangles[t], triangles[t + 1], triangles[t + 2])); + var face = new RG.MeshFace(triangles[t], triangles[t + 1], triangles[t + 2]); + faceIndices.Add(m.Faces.AddFace(face)); } - IRhinoMeshNgon ngon = _rhinoNgonFactory.Create(target.faces.GetRange(i + 1, n), faceIndices); + RG.MeshNgon ngon = RG.MeshNgon.Create(target.faces.GetRange(i + 1, n), faceIndices); m.Ngons.AddNgon(ngon); } @@ -97,13 +89,13 @@ private void AssignMeshFaces(SOG.Mesh target, IRhinoMesh m) m.Faces.CullDegenerateFaces(); } - private void AssignTextureCoordinates(SOG.Mesh target, IRhinoMesh m) + private void AssignTextureCoordinates(SOG.Mesh target, RG.Mesh m) { - var textureCoordinates = new IRhinoPoint2f[target.TextureCoordinatesCount]; + var textureCoordinates = new RG.Point2f[target.TextureCoordinatesCount]; for (int ti = 0; ti < target.TextureCoordinatesCount; ti++) { var (u, v) = target.GetTextureCoordinate(ti); - textureCoordinates[ti] = _rhinoPointFactory.Create(u, v); + textureCoordinates[ti] = new RG.Point2f(u, v); } m.TextureCoordinates.SetTextureCoordinates(textureCoordinates); } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/NurbsCurveToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/NurbsCurveToHostConverter.cs index 9e2ee516f4..9f9bf52811 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/NurbsCurveToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/NurbsCurveToHostConverter.cs @@ -1,24 +1,15 @@ using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class NurbsCurveToHostConverter : ITypedConverter +public class NurbsCurveToHostConverter : ITypedConverter { - private readonly IRhinoPointFactory _rhinoPointFactory; - private readonly IRhinoCurveFactory _rhinoCurveFactory; - private readonly ITypedConverter _intervalConverter; + private readonly ITypedConverter _intervalConverter; - public NurbsCurveToHostConverter( - ITypedConverter intervalConverter, - IRhinoCurveFactory rhinoCurveFactory, - IRhinoPointFactory rhinoPointFactory - ) + public NurbsCurveToHostConverter(ITypedConverter intervalConverter) { _intervalConverter = intervalConverter; - _rhinoCurveFactory = rhinoCurveFactory; - _rhinoPointFactory = rhinoPointFactory; } /// @@ -28,14 +19,14 @@ IRhinoPointFactory rhinoPointFactory /// The converted Rhino NurbsCurve object. /// Thrown when the conversion fails. /// ⚠️ This conversion does NOT perform scaling. - public IRhinoNurbsCurve Convert(SOG.Curve target) + public RG.NurbsCurve Convert(SOG.Curve target) { - IRhinoNurbsCurve nurbsCurve = _rhinoCurveFactory.Create(target.degree, target.points.Count / 3); + RG.NurbsCurve nurbsCurve = new(target.degree, target.points.Count / 3); // Hyper optimised curve control point conversion for (int i = 2, j = 0; i < target.points.Count; i += 3, j++) { - var pt = _rhinoPointFactory.Create(target.points[i - 2], target.points[i - 1], target.points[i]); // Skip the point converter for performance + var pt = new RG.Point3d(target.points[i - 2], target.points[i - 1], target.points[i]); // Skip the point converter for performance nurbsCurve.Points.SetPoint(j, pt, target.weights[j]); } @@ -46,11 +37,11 @@ public IRhinoNurbsCurve Convert(SOG.Curve target) { if (extraKnots == 2) { - nurbsCurve.Knots.SetKnot(j, target.knots[j + 1]); + nurbsCurve.Knots[j] = target.knots[j + 1]; } else { - nurbsCurve.Knots.SetKnot(j, target.knots[j]); + nurbsCurve.Knots[j] = target.knots[j]; } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PlaneToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PlaneToHostConverter.cs index 4b18fac738..49e10ab69e 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PlaneToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PlaneToHostConverter.cs @@ -1,23 +1,19 @@ using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class PlaneToHostConverter : ITypedConverter +public class PlaneToHostConverter : ITypedConverter { - private readonly ITypedConverter _pointConverter; - private readonly ITypedConverter _vectorConverter; - private readonly IRhinoPlaneFactory _rhinoPlaneFactory; + private readonly ITypedConverter _pointConverter; + private readonly ITypedConverter _vectorConverter; public PlaneToHostConverter( - ITypedConverter pointConverter, - ITypedConverter vectorConverter, - IRhinoPlaneFactory rhinoPlaneFactory + ITypedConverter pointConverter, + ITypedConverter vectorConverter ) { _pointConverter = pointConverter; _vectorConverter = vectorConverter; - _rhinoPlaneFactory = rhinoPlaneFactory; } /// @@ -26,8 +22,8 @@ IRhinoPlaneFactory rhinoPlaneFactory /// The Speckle Plane object to be converted. /// The converted Rhino Plane object. /// ⚠️ This conversion does NOT perform scaling. - public IRhinoPlane Convert(SOG.Plane target) => - _rhinoPlaneFactory.Create( + public RG.Plane Convert(SOG.Plane target) => + new( _pointConverter.Convert(target.origin), _vectorConverter.Convert(target.xdir), _vectorConverter.Convert(target.ydir) diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PointCloudToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PointCloudToHostConverter.cs index f4a67b8d8d..a6d749b15c 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PointCloudToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PointCloudToHostConverter.cs @@ -1,21 +1,16 @@ using System.Drawing; +using Rhino.Collections; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class PointCloudToHostConverter : ITypedConverter +public class PointCloudToHostConverter : ITypedConverter { - private readonly ITypedConverter, IRhinoPoint3dList> _pointListConverter; - private readonly IRhinoPointCloudFactory _rhinoPointCloudFactory; + private readonly ITypedConverter, Point3dList> _pointListConverter; - public PointCloudToHostConverter( - ITypedConverter, IRhinoPoint3dList> pointListConverter, - IRhinoPointCloudFactory rhinoPointCloudFactory - ) + public PointCloudToHostConverter(ITypedConverter, Point3dList> pointListConverter) { _pointListConverter = pointListConverter; - _rhinoPointCloudFactory = rhinoPointCloudFactory; } /// @@ -24,10 +19,10 @@ IRhinoPointCloudFactory rhinoPointCloudFactory /// The raw Speckle Pointcloud object to convert. /// The converted Rhino PointCloud object. /// ⚠️ This conversion does NOT perform scaling. - public IRhinoPointCloud Convert(SOG.Pointcloud target) + public RG.PointCloud Convert(SOG.Pointcloud target) { var rhinoPoints = _pointListConverter.Convert(target.points); - var rhinoPointCloud = _rhinoPointCloudFactory.Create(rhinoPoints); + var rhinoPointCloud = new RG.PointCloud(rhinoPoints); if (target.colors.Count == rhinoPoints.Count) { diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PointToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PointToHostConverter.cs index 35938f8ad4..8ce40bcb59 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PointToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PointToHostConverter.cs @@ -1,24 +1,16 @@ using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class PointToHostConverter : ITypedConverter, ITypedConverter +public class PointToHostConverter : ITypedConverter, ITypedConverter { - private readonly IRhinoPointFactory _rhinoPointFactory; - - public PointToHostConverter(IRhinoPointFactory rhinoPointFactory) - { - _rhinoPointFactory = rhinoPointFactory; - } - /// /// Converts a Speckle Point object to a Rhino Point3d object. /// /// The Speckle Point object to convert. /// The converted Rhino Point3d object. /// ⚠️ This conversion does NOT perform scaling. - public IRhinoPoint3d Convert(SOG.Point target) => _rhinoPointFactory.Create(target.x, target.y, target.z); + public RG.Point3d Convert(SOG.Point target) => new(target.x, target.y, target.z); /// /// Converts a Speckle Point object to a Rhino Point object. @@ -26,6 +18,5 @@ public PointToHostConverter(IRhinoPointFactory rhinoPointFactory) /// The Speckle Point object to convert. /// The converted Rhino Point object. /// ⚠️ This conversion does NOT perform scaling. - IRhinoPoint ITypedConverter.Convert(SOG.Point target) => - _rhinoPointFactory.Create(Convert(target)); + RG.Point ITypedConverter.Convert(SOG.Point target) => new(Convert(target)); } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PolyCurveToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PolyCurveToHostConverter.cs index 6a2655ed48..3f35905090 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PolyCurveToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PolyCurveToHostConverter.cs @@ -2,24 +2,18 @@ using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Core.Kits; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class PolyCurveToHostConverter : ITypedConverter +public class PolyCurveToHostConverter : ITypedConverter { - public ITypedConverter? CurveConverter { get; set; } // POC: CNX-9311 Circular dependency injected by the container using property. + public ITypedConverter? CurveConverter { get; set; } // POC: CNX-9311 Circular dependency injected by the container using property. - private readonly ITypedConverter _intervalConverter; - private readonly IRhinoCurveFactory _rhinoCurveFactory; + private readonly ITypedConverter _intervalConverter; - public PolyCurveToHostConverter( - ITypedConverter intervalConverter, - IRhinoCurveFactory rhinoCurveFactory - ) + public PolyCurveToHostConverter(ITypedConverter intervalConverter) { _intervalConverter = intervalConverter; - _rhinoCurveFactory = rhinoCurveFactory; } /// @@ -28,14 +22,13 @@ IRhinoCurveFactory rhinoCurveFactory /// The SpecklePolyCurve object to convert. /// The converted Rhino PolyCurve object. /// ⚠️ This conversion does NOT perform scaling. - public IRhinoPolyCurve Convert(SOG.Polycurve target) + public RG.PolyCurve Convert(SOG.Polycurve target) { - IRhinoPolyCurve result = _rhinoCurveFactory.Create(); - var converter = CurveConverter.NotNull(); + RG.PolyCurve result = new(); foreach (var segment in target.segments) { - var childCurve = converter.Convert(segment); + var childCurve = CurveConverter.NotNull().Convert(segment); bool success = result.AppendSegment(childCurve); if (!success) { diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PolylineToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PolylineToHostConverter.cs index b803a07943..5abe48fed5 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PolylineToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PolylineToHostConverter.cs @@ -1,25 +1,22 @@ -using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; +using Rhino.Collections; +using Speckle.Converters.Common.Objects; namespace Speckle.Converters.Rhino7.ToHost.Raw; public class PolylineToHostConverter - : ITypedConverter, - ITypedConverter + : ITypedConverter, + ITypedConverter { - private readonly ITypedConverter, IRhinoPoint3dList> _pointListConverter; - private readonly ITypedConverter _intervalConverter; - private readonly IRhinoLineFactory _rhinoLineFactory; + private readonly ITypedConverter, Point3dList> _pointListConverter; + private readonly ITypedConverter _intervalConverter; public PolylineToHostConverter( - ITypedConverter, IRhinoPoint3dList> pointListConverter, - ITypedConverter intervalConverter, - IRhinoLineFactory rhinoLineFactory + ITypedConverter, Point3dList> pointListConverter, + ITypedConverter intervalConverter ) { _pointListConverter = pointListConverter; _intervalConverter = intervalConverter; - _rhinoLineFactory = rhinoLineFactory; } /// @@ -31,9 +28,9 @@ IRhinoLineFactory rhinoLineFactory /// ///
⚠️ This conversion does not preserve the curve domain. /// If you need it preserved you must request a conversion to - /// conversion instead + /// conversion instead ///
- public IRhinoPolyline Convert(SOG.Polyline target) + public RG.Polyline Convert(SOG.Polyline target) { var points = _pointListConverter.Convert(target.value); @@ -42,7 +39,7 @@ public IRhinoPolyline Convert(SOG.Polyline target) points.Add(points[0]); } - var poly = _rhinoLineFactory.Create(points); + var poly = new RG.Polyline(points); return poly; } @@ -55,7 +52,7 @@ public IRhinoPolyline Convert(SOG.Polyline target) /// The Speckle polyline object to be converted. /// The converted Rhino Polyline object. /// ⚠️ This conversion does NOT perform scaling. - IRhinoPolylineCurve ITypedConverter.Convert(SOG.Polyline target) + RG.PolylineCurve ITypedConverter.Convert(SOG.Polyline target) { var poly = Convert(target).ToPolylineCurve(); poly.Domain = _intervalConverter.Convert(target.domain); diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/SpiralToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/SpiralToHostConverter.cs index c3cc3532ce..cb7f5a8745 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/SpiralToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/SpiralToHostConverter.cs @@ -1,16 +1,15 @@ using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class SpiralToHostConverter : ITypedConverter +public class SpiralToHostConverter : ITypedConverter { - private readonly ITypedConverter _polylineConverter; - private readonly ITypedConverter _intervalConverter; + private readonly ITypedConverter _polylineConverter; + private readonly ITypedConverter _intervalConverter; public SpiralToHostConverter( - ITypedConverter polylineConverter, - ITypedConverter intervalConverter + ITypedConverter polylineConverter, + ITypedConverter intervalConverter ) { _polylineConverter = polylineConverter; @@ -23,7 +22,7 @@ public SpiralToHostConverter( /// The Speckle Spiral object to be converted. /// A Rhino PolylineCurve object. /// ⚠️ This conversion does NOT perform scaling. - public IRhinoPolylineCurve Convert(SOG.Spiral target) + public RG.PolylineCurve Convert(SOG.Spiral target) { var result = _polylineConverter.Convert(target.displayValue); result.Domain = _intervalConverter.Convert(target.domain); diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/SurfaceToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/SurfaceToHostConverter.cs index 46689761a8..91da44ec59 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/SurfaceToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/SurfaceToHostConverter.cs @@ -1,29 +1,21 @@ using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class SurfaceToHostConverter : ITypedConverter +public class SurfaceToHostConverter : ITypedConverter { - private readonly IRhinoSurfaceFactory _rhinoSurfaceFactory; - - public SurfaceToHostConverter(IRhinoSurfaceFactory rhinoSurfaceFactory) - { - _rhinoSurfaceFactory = rhinoSurfaceFactory; - } - /// /// Converts a raw Speckle surface to a Rhino NURBS surface. /// /// The raw Speckle surface to convert. /// The converted Rhino NURBS surface. /// ⚠️ This conversion does NOT perform scaling. - public IRhinoNurbsSurface Convert(SOG.Surface target) + public RG.NurbsSurface Convert(SOG.Surface target) { // Create rhino surface var points = target.GetControlPoints().ToList(); - var result = _rhinoSurfaceFactory.Create( + var result = RG.NurbsSurface.Create( 3, target.rational, target.degreeU + 1, @@ -36,13 +28,13 @@ public IRhinoNurbsSurface Convert(SOG.Surface target) var correctUKnots = GetCorrectKnots(target.knotsU, target.countU, target.degreeU); for (int i = 0; i < correctUKnots.Count; i++) { - result.KnotsU.SetKnot(i, correctUKnots[i]); + result.KnotsU[i] = correctUKnots[i]; } var correctVKnots = GetCorrectKnots(target.knotsV, target.countV, target.degreeV); for (int i = 0; i < correctVKnots.Count; i++) { - result.KnotsV.SetKnot(i, correctVKnots[i]); + result.KnotsV[i] = correctVKnots[i]; } // Set control points diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/VectorToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/VectorToHostConverter.cs index 85ff17692c..77e017f0fd 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/VectorToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/VectorToHostConverter.cs @@ -1,22 +1,14 @@ using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class VectorToHostConverter : ITypedConverter +public class VectorToHostConverter : ITypedConverter { - private readonly IRhinoVectorFactory _rhinoVectorFactory; - - public VectorToHostConverter(IRhinoVectorFactory rhinoVectorFactory) - { - _rhinoVectorFactory = rhinoVectorFactory; - } - /// /// Converts a Speckle.Vector object to a Rhino Vector3d object. /// /// The Speckle.Vector to be converted. /// The converted Rhino Vector3d object. /// ⚠️ This conversion does NOT perform scaling. - public IRhinoVector3d Convert(SOG.Vector target) => _rhinoVectorFactory.Create(target.x, target.y, target.z); + public RG.Vector3d Convert(SOG.Vector target) => new(target.x, target.y, target.z); } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/ArcToHostTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/ArcToHostTopLevelConverter.cs index ca8b4938bd..12c4420914 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/ArcToHostTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/ArcToHostTopLevelConverter.cs @@ -1,16 +1,15 @@ -using Speckle.Converters.Common; +using Rhino; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.TopLevel; [NameAndRankValue(nameof(SOG.Arc), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public class ArcToHostTopLevelConverter : SpeckleToHostGeometryBaseTopLevelConverter +public class ArcToHostTopLevelConverter : SpeckleToHostGeometryBaseTopLevelConverter { public ArcToHostTopLevelConverter( - IConversionContextStack contextStack, - ITypedConverter geometryBaseConverter, - IRhinoTransformFactory rhinoTransformFactory + IConversionContextStack contextStack, + ITypedConverter geometryBaseConverter ) - : base(contextStack, geometryBaseConverter, rhinoTransformFactory) { } + : base(contextStack, geometryBaseConverter) { } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/BrepToHostTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/BrepToHostTopLevelConverter.cs index 1c8706bd99..6ca70d3ad1 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/BrepToHostTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/BrepToHostTopLevelConverter.cs @@ -1,16 +1,15 @@ -using Speckle.Converters.Common; +using Rhino; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.TopLevel; [NameAndRankValue(nameof(SOG.Brep), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public class BrepToHostTopLevelConverter : SpeckleToHostGeometryBaseTopLevelConverter +public class BrepToHostTopLevelConverter : SpeckleToHostGeometryBaseTopLevelConverter { public BrepToHostTopLevelConverter( - IConversionContextStack contextStack, - ITypedConverter geometryBaseConverter, - IRhinoTransformFactory rhinoTransformFactory + IConversionContextStack contextStack, + ITypedConverter geometryBaseConverter ) - : base(contextStack, geometryBaseConverter, rhinoTransformFactory) { } + : base(contextStack, geometryBaseConverter) { } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/CircleToHostTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/CircleToHostTopLevelConverter.cs index 942854b10b..1493120e57 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/CircleToHostTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/CircleToHostTopLevelConverter.cs @@ -1,16 +1,15 @@ -using Speckle.Converters.Common; +using Rhino; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.TopLevel; [NameAndRankValue(nameof(SOG.Circle), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public class CircleToHostTopLevelConverter : SpeckleToHostGeometryBaseTopLevelConverter +public class CircleToHostTopLevelConverter : SpeckleToHostGeometryBaseTopLevelConverter { public CircleToHostTopLevelConverter( - IConversionContextStack contextStack, - ITypedConverter geometryBaseConverter, - IRhinoTransformFactory rhinoTransformFactory + IConversionContextStack contextStack, + ITypedConverter geometryBaseConverter ) - : base(contextStack, geometryBaseConverter, rhinoTransformFactory) { } + : base(contextStack, geometryBaseConverter) { } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/EllipseToHostTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/EllipseToHostTopLevelConverter.cs index dbc35c205b..e6a4b03a41 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/EllipseToHostTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/EllipseToHostTopLevelConverter.cs @@ -1,16 +1,15 @@ -using Speckle.Converters.Common; +using Rhino; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.TopLevel; [NameAndRankValue(nameof(SOG.Ellipse), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public class EllipseToHostTopLevelConverter : SpeckleToHostGeometryBaseTopLevelConverter +public class EllipseToHostTopLevelConverter : SpeckleToHostGeometryBaseTopLevelConverter { public EllipseToHostTopLevelConverter( - IConversionContextStack contextStack, - ITypedConverter geometryBaseConverter, - IRhinoTransformFactory rhinoTransformFactory + IConversionContextStack contextStack, + ITypedConverter geometryBaseConverter ) - : base(contextStack, geometryBaseConverter, rhinoTransformFactory) { } + : base(contextStack, geometryBaseConverter) { } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/FallbackToHostTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/FallbackToHostTopLevelConverter.cs index 34c5a989ae..811433890c 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/FallbackToHostTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/FallbackToHostTopLevelConverter.cs @@ -1,45 +1,42 @@ -using Speckle.Converters.Common; +using Rhino; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Core.Kits; using Speckle.Core.Models; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.TopLevel; [NameAndRankValue(nameof(DisplayableObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] public class FallbackToHostTopLevelConverter : IToHostTopLevelConverter, - ITypedConverter> + ITypedConverter> { - private readonly ITypedConverter _lineConverter; - private readonly ITypedConverter _polylineConverter; - private readonly ITypedConverter _meshConverter; - private readonly IConversionContextStack _contextStack; - private readonly IRhinoTransformFactory _rhinoTransformFactory; + private readonly ITypedConverter _lineConverter; + private readonly ITypedConverter _polylineConverter; + private readonly ITypedConverter _meshConverter; + private readonly IConversionContextStack _contextStack; public FallbackToHostTopLevelConverter( - ITypedConverter lineConverter, - ITypedConverter polylineConverter, - ITypedConverter meshConverter, - IConversionContextStack contextStack, - IRhinoTransformFactory rhinoTransformFactory + ITypedConverter lineConverter, + ITypedConverter polylineConverter, + ITypedConverter meshConverter, + IConversionContextStack contextStack ) { _lineConverter = lineConverter; _polylineConverter = polylineConverter; _meshConverter = meshConverter; _contextStack = contextStack; - _rhinoTransformFactory = rhinoTransformFactory; } public object Convert(Base target) => Convert((DisplayableObject)target); - public List Convert(DisplayableObject target) + public List Convert(DisplayableObject target) { - var result = new List(); + var result = new List(); foreach (var item in target.displayValue) { - IRhinoGeometryBase x = item switch + RG.GeometryBase x = item switch { SOG.Line line => _lineConverter.Convert(line), SOG.Polyline polyline => _polylineConverter.Convert(polyline), @@ -53,7 +50,7 @@ public List Convert(DisplayableObject target) return result; } - private IRhinoTransform GetUnitsTransform(Base speckleObject) + private RG.Transform GetUnitsTransform(Base speckleObject) { /* * POC: CNX-9270 Looking at a simpler, more performant way of doing unit scaling on `ToNative` @@ -63,10 +60,10 @@ private IRhinoTransform GetUnitsTransform(Base speckleObject) if (speckleObject["units"] is string units) { var scaleFactor = Units.GetConversionFactor(units, _contextStack.Current.SpeckleUnits); - var scale = _rhinoTransformFactory.Scale(_rhinoTransformFactory.Origin, scaleFactor); + var scale = RG.Transform.Scale(RG.Point3d.Origin, scaleFactor); return scale; } - return _rhinoTransformFactory.Identity; + return RG.Transform.Identity; } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/LineToHostTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/LineToHostTopLevelConverter.cs index 8767a91e06..5a64a3ebab 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/LineToHostTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/LineToHostTopLevelConverter.cs @@ -1,16 +1,15 @@ -using Speckle.Converters.Common; +using Rhino; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.TopLevel; [NameAndRankValue(nameof(SOG.Line), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public class LineToHostTopLevelConverter : SpeckleToHostGeometryBaseTopLevelConverter +public class LineToHostTopLevelConverter : SpeckleToHostGeometryBaseTopLevelConverter { public LineToHostTopLevelConverter( - IConversionContextStack contextStack, - ITypedConverter geometryBaseConverter, - IRhinoTransformFactory rhinoTransformFactory + IConversionContextStack contextStack, + ITypedConverter geometryBaseConverter ) - : base(contextStack, geometryBaseConverter, rhinoTransformFactory) { } + : base(contextStack, geometryBaseConverter) { } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/MeshToHostTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/MeshToHostTopLevelConverter.cs index 6cdacc4288..c7d047df3b 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/MeshToHostTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/MeshToHostTopLevelConverter.cs @@ -1,16 +1,15 @@ -using Speckle.Converters.Common; +using Rhino; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.TopLevel; [NameAndRankValue(nameof(SOG.Mesh), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public class MeshToHostTopLevelConverter : SpeckleToHostGeometryBaseTopLevelConverter +public class MeshToHostTopLevelConverter : SpeckleToHostGeometryBaseTopLevelConverter { public MeshToHostTopLevelConverter( - IConversionContextStack contextStack, - ITypedConverter geometryBaseConverter, - IRhinoTransformFactory rhinoTransformFactory + IConversionContextStack contextStack, + ITypedConverter geometryBaseConverter ) - : base(contextStack, geometryBaseConverter, rhinoTransformFactory) { } + : base(contextStack, geometryBaseConverter) { } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/NurbsCurveToHostTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/NurbsCurveToHostTopLevelConverter.cs index 19201d066a..987b46161f 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/NurbsCurveToHostTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/NurbsCurveToHostTopLevelConverter.cs @@ -1,16 +1,15 @@ -using Speckle.Converters.Common; +using Rhino; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.TopLevel; [NameAndRankValue(nameof(SOG.Curve), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public class NurbsCurveToHostTopLevelConverter : SpeckleToHostGeometryBaseTopLevelConverter +public class NurbsCurveToHostTopLevelConverter : SpeckleToHostGeometryBaseTopLevelConverter { public NurbsCurveToHostTopLevelConverter( - IConversionContextStack contextStack, - ITypedConverter geometryBaseConverter, - IRhinoTransformFactory rhinoTransformFactory + IConversionContextStack contextStack, + ITypedConverter geometryBaseConverter ) - : base(contextStack, geometryBaseConverter, rhinoTransformFactory) { } + : base(contextStack, geometryBaseConverter) { } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/PointCloudToHostTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/PointCloudToHostTopLevelConverter.cs index c4e199b3d4..51a2613e90 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/PointCloudToHostTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/PointCloudToHostTopLevelConverter.cs @@ -1,17 +1,16 @@ -using Speckle.Converters.Common; +using Rhino; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.TopLevel; [NameAndRankValue(nameof(SOG.Pointcloud), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] public class PointCloudToHostTopLevelConverter - : SpeckleToHostGeometryBaseTopLevelConverter + : SpeckleToHostGeometryBaseTopLevelConverter { public PointCloudToHostTopLevelConverter( - IConversionContextStack contextStack, - ITypedConverter geometryBaseConverter, - IRhinoTransformFactory rhinoTransformFactory + IConversionContextStack contextStack, + ITypedConverter geometryBaseConverter ) - : base(contextStack, geometryBaseConverter, rhinoTransformFactory) { } + : base(contextStack, geometryBaseConverter) { } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/PointToHostTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/PointToHostTopLevelConverter.cs index 6922cf12ad..de10053ce9 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/PointToHostTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/PointToHostTopLevelConverter.cs @@ -1,16 +1,15 @@ -using Speckle.Converters.Common; +using Rhino; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.TopLevel; [NameAndRankValue(nameof(SOG.Point), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public class PointToHostTopLevelConverter : SpeckleToHostGeometryBaseTopLevelConverter +public class PointToHostTopLevelConverter : SpeckleToHostGeometryBaseTopLevelConverter { public PointToHostTopLevelConverter( - IConversionContextStack contextStack, - ITypedConverter geometryBaseConverter, - IRhinoTransformFactory rhinoTransformFactory + IConversionContextStack contextStack, + ITypedConverter geometryBaseConverter ) - : base(contextStack, geometryBaseConverter, rhinoTransformFactory) { } + : base(contextStack, geometryBaseConverter) { } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/PolycurveToHostTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/PolycurveToHostTopLevelConverter.cs index 96511e2856..d6f8d2f14b 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/PolycurveToHostTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/PolycurveToHostTopLevelConverter.cs @@ -1,17 +1,15 @@ -using Speckle.Converters.Common; +using Rhino; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.TopLevel; [NameAndRankValue(nameof(SOG.Polycurve), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public class PolycurveToHostTopLevelConverter - : SpeckleToHostGeometryBaseTopLevelConverter +public class PolycurveToHostTopLevelConverter : SpeckleToHostGeometryBaseTopLevelConverter { public PolycurveToHostTopLevelConverter( - IConversionContextStack contextStack, - ITypedConverter geometryBaseConverter, - IRhinoTransformFactory rhinoTransformFactory + IConversionContextStack contextStack, + ITypedConverter geometryBaseConverter ) - : base(contextStack, geometryBaseConverter, rhinoTransformFactory) { } + : base(contextStack, geometryBaseConverter) { } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/PolylineToHostTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/PolylineToHostTopLevelConverter.cs index c098b09930..081f217f04 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/PolylineToHostTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/PolylineToHostTopLevelConverter.cs @@ -1,17 +1,16 @@ -using Speckle.Converters.Common; +using Rhino; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.TopLevel; [NameAndRankValue(nameof(SOG.Polyline), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] public class PolylineToHostTopLevelConverter - : SpeckleToHostGeometryBaseTopLevelConverter + : SpeckleToHostGeometryBaseTopLevelConverter { public PolylineToHostTopLevelConverter( - IConversionContextStack contextStack, - ITypedConverter geometryBaseConverter, - IRhinoTransformFactory rhinoTransformFactory + IConversionContextStack contextStack, + ITypedConverter geometryBaseConverter ) - : base(contextStack, geometryBaseConverter, rhinoTransformFactory) { } + : base(contextStack, geometryBaseConverter) { } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/ArcCurveToSpeckleConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/ArcCurveToSpeckleConverter.cs index f262520e97..8a3eee9cb7 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/ArcCurveToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/ArcCurveToSpeckleConverter.cs @@ -1,23 +1,23 @@ using Objects; +using Rhino; using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Core.Models; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.Raw; -public class ArcCurveToSpeckleConverter : ITypedConverter, ITypedConverter +public class ArcCurveToSpeckleConverter : ITypedConverter, ITypedConverter { - private readonly ITypedConverter _circleConverter; - private readonly ITypedConverter _arcConverter; - private readonly ITypedConverter _intervalConverter; - private readonly IConversionContextStack _contextStack; + private readonly ITypedConverter _circleConverter; + private readonly ITypedConverter _arcConverter; + private readonly ITypedConverter _intervalConverter; + private readonly IConversionContextStack _contextStack; public ArcCurveToSpeckleConverter( - ITypedConverter circleConverter, - ITypedConverter arcConverter, - ITypedConverter intervalConverter, - IConversionContextStack contextStack + ITypedConverter circleConverter, + ITypedConverter arcConverter, + ITypedConverter intervalConverter, + IConversionContextStack contextStack ) { _circleConverter = circleConverter; @@ -27,16 +27,16 @@ IConversionContextStack contextStack } /// - /// Converts an IRhinoArcCurve to an ICurve. + /// Converts an RG.ArcCurve to an ICurve. /// - /// The IRhinoArcCurve to convert. + /// The RG.ArcCurve to convert. /// The converted ICurve. /// /// ⚠️ If the provided ArcCurve is a complete circle, a Speckle Circle will be returned. /// Otherwise, the output will be a Speckle Arc.
/// ✅ This method preserves the domain of the original ArcCurve.
///
- public ICurve Convert(IRhinoArcCurve target) + public ICurve Convert(RG.ArcCurve target) { var tolerance = _contextStack.Current.Document.ModelAbsoluteTolerance; @@ -57,5 +57,5 @@ public ICurve Convert(IRhinoArcCurve target) // This also causes us to have to force cast ICurve to Base as a result, which is expected to always succeed but not nice. /// /// The converted ICurve with a cast to object - Base ITypedConverter.Convert(IRhinoArcCurve target) => (Base)Convert(target); + Base ITypedConverter.Convert(RG.ArcCurve target) => (Base)Convert(target); } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/ArcToSpeckleConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/ArcToSpeckleConverter.cs index 0458715c91..82c89c2551 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/ArcToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/ArcToSpeckleConverter.cs @@ -1,30 +1,27 @@ -using Speckle.Converters.Common; +using Rhino; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.Raw; -public class ArcToSpeckleConverter : ITypedConverter +public class ArcToSpeckleConverter : ITypedConverter { - private readonly ITypedConverter _pointConverter; - private readonly ITypedConverter _planeConverter; - private readonly ITypedConverter _boxConverter; - private readonly IConversionContextStack _contextStack; - private readonly IRhinoBoxFactory _boxFactory; + private readonly ITypedConverter _pointConverter; + private readonly ITypedConverter _planeConverter; + private readonly ITypedConverter _boxConverter; + private readonly IConversionContextStack _contextStack; public ArcToSpeckleConverter( - ITypedConverter pointConverter, - ITypedConverter planeConverter, - ITypedConverter boxConverter, - IConversionContextStack contextStack, - IRhinoBoxFactory boxFactory + ITypedConverter pointConverter, + ITypedConverter planeConverter, + ITypedConverter boxConverter, + IConversionContextStack contextStack ) { _pointConverter = pointConverter; _planeConverter = planeConverter; _boxConverter = boxConverter; _contextStack = contextStack; - _boxFactory = boxFactory; } /// @@ -35,7 +32,7 @@ IRhinoBoxFactory boxFactory /// /// This method assumes the domain of the arc is (0,1) as Arc types in Rhino do not have domain. You may want to request a conversion from ArcCurve instead. /// - public SOG.Arc Convert(IRhinoArc target) => + public SOG.Arc Convert(RG.Arc target) => new( _planeConverter.Convert(target.Plane), target.Radius, @@ -50,6 +47,6 @@ public SOG.Arc Convert(IRhinoArc target) => endPoint = _pointConverter.Convert(target.EndPoint), domain = new SOP.Interval(0, 1), length = target.Length, - bbox = _boxConverter.Convert(_boxFactory.CreateBox(target.BoundingBox())) + bbox = _boxConverter.Convert(new RG.Box(target.BoundingBox())) }; } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/BoxToSpeckleConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/BoxToSpeckleConverter.cs index cae6a5d610..cebd6e5d70 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/BoxToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/BoxToSpeckleConverter.cs @@ -1,19 +1,19 @@ -using Speckle.Converters.Common; +using Rhino; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.Raw; -public class BoxToSpeckleConverter : ITypedConverter +public class BoxToSpeckleConverter : ITypedConverter { - private readonly ITypedConverter _planeConverter; - private readonly ITypedConverter _intervalConverter; - private readonly IConversionContextStack _contextStack; + private readonly ITypedConverter _planeConverter; + private readonly ITypedConverter _intervalConverter; + private readonly IConversionContextStack _contextStack; public BoxToSpeckleConverter( - ITypedConverter planeConverter, - ITypedConverter intervalConverter, - IConversionContextStack contextStack + ITypedConverter planeConverter, + ITypedConverter intervalConverter, + IConversionContextStack contextStack ) { _planeConverter = planeConverter; @@ -26,7 +26,7 @@ IConversionContextStack contextStack /// /// The Rhino Box object to convert. /// The converted Speckle Box object. - public SOG.Box Convert(IRhinoBox target) => + public SOG.Box Convert(RG.Box target) => new( _planeConverter.Convert(target.Plane), _intervalConverter.Convert(target.X), diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/BrepToSpeckleConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/BrepToSpeckleConverter.cs index 1ae05128f7..e74bb2f374 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/BrepToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/BrepToSpeckleConverter.cs @@ -1,34 +1,30 @@ using Objects; +using Rhino; using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Core.Kits; using Speckle.Core.Logging; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.Raw; -public class BrepToSpeckleConverter : ITypedConverter +public class BrepToSpeckleConverter : ITypedConverter { - private readonly ITypedConverter _pointConverter; - private readonly ITypedConverter _curveConverter; - private readonly ITypedConverter _surfaceConverter; - private readonly ITypedConverter _meshConverter; - private readonly ITypedConverter _boxConverter; - private readonly ITypedConverter _intervalConverter; - private readonly IConversionContextStack _contextStack; - private readonly IRhinoBoxFactory _rhinoBoxFactory; - private readonly IRhinoMeshFactory _rhinoMeshFactory; + private readonly ITypedConverter _pointConverter; + private readonly ITypedConverter _curveConverter; + private readonly ITypedConverter _surfaceConverter; + private readonly ITypedConverter _meshConverter; + private readonly ITypedConverter _boxConverter; + private readonly ITypedConverter _intervalConverter; + private readonly IConversionContextStack _contextStack; public BrepToSpeckleConverter( - ITypedConverter pointConverter, - ITypedConverter curveConverter, - ITypedConverter surfaceConverter, - ITypedConverter meshConverter, - ITypedConverter boxConverter, - ITypedConverter intervalConverter, - IConversionContextStack contextStack, - IRhinoBoxFactory rhinoBoxFactory, - IRhinoMeshFactory rhinoMeshFactory + ITypedConverter pointConverter, + ITypedConverter curveConverter, + ITypedConverter surfaceConverter, + ITypedConverter meshConverter, + ITypedConverter boxConverter, + ITypedConverter intervalConverter, + IConversionContextStack contextStack ) { _pointConverter = pointConverter; @@ -38,8 +34,6 @@ IRhinoMeshFactory rhinoMeshFactory _boxConverter = boxConverter; _intervalConverter = intervalConverter; _contextStack = contextStack; - _rhinoBoxFactory = rhinoBoxFactory; - _rhinoMeshFactory = rhinoMeshFactory; } /// @@ -47,7 +41,7 @@ IRhinoMeshFactory rhinoMeshFactory /// /// The Brep object to convert. /// The converted Speckle Brep object. - public SOG.Brep Convert(IRhinoBrep target) + public SOG.Brep Convert(RG.Brep target) { var tol = _contextStack.Current.Document.ModelAbsoluteTolerance; target.Repair(tol); @@ -95,7 +89,7 @@ public SOG.Brep Convert(IRhinoBrep target) Orientation = (SOG.BrepOrientation)target.SolidOrientation, volume = target.IsSolid ? target.GetVolume() : 0, area = target.GetArea(), - bbox = _boxConverter.Convert(_rhinoBoxFactory.CreateBox(target.GetBoundingBox(false))), + bbox = _boxConverter.Convert(new RG.Box(target.GetBoundingBox(false))), units = _contextStack.Current.SpeckleUnits }; @@ -112,7 +106,7 @@ public SOG.Brep Convert(IRhinoBrep target) return speckleBrep; } - private static List ConvertBrepFaces(IRhinoBrep brep, SOG.Brep speckleParent) => + private static List ConvertBrepFaces(RG.Brep brep, SOG.Brep speckleParent) => brep.Faces .Select( f => @@ -126,7 +120,7 @@ public SOG.Brep Convert(IRhinoBrep target) ) .ToList(); - private List ConvertBrepEdges(IRhinoBrep brep, SOG.Brep speckleParent) => + private List ConvertBrepEdges(RG.Brep brep, SOG.Brep speckleParent) => brep.Edges .Select( edge => @@ -142,13 +136,13 @@ public SOG.Brep Convert(IRhinoBrep target) ) .ToList(); - private List ConvertBrepTrims(IRhinoBrep brep, SOG.Brep speckleParent) => + private List ConvertBrepTrims(RG.Brep brep, SOG.Brep speckleParent) => brep.Trims .Select(trim => { var t = new SOG.BrepTrim( speckleParent, - trim.Edge?.EdgeIndex ?? -1, + trim.Edge.EdgeIndex, trim.Face.FaceIndex, trim.Loop.LoopIndex, trim.TrimCurveIndex, @@ -166,7 +160,7 @@ public SOG.Brep Convert(IRhinoBrep target) }) .ToList(); - private List ConvertBrepLoops(IRhinoBrep brep, SOG.Brep speckleParent) => + private List ConvertBrepLoops(RG.Brep brep, SOG.Brep speckleParent) => brep.Loops .Select( loop => @@ -179,13 +173,14 @@ public SOG.Brep Convert(IRhinoBrep target) ) .ToList(); - private IRhinoMesh? GetBrepDisplayMesh(IRhinoBrep brep) + private RG.Mesh? GetBrepDisplayMesh(RG.Brep brep) { - var joinedMesh = _rhinoMeshFactory.Create(); + var joinedMesh = new RG.Mesh(); // get from settings //Settings.TryGetValue("sendMeshSetting", out string meshSetting); + RG.MeshingParameters mySettings = new(0.05, 0.05); // switch (SelectedMeshSettings) // { // case MeshSettings.CurrentDoc: @@ -199,7 +194,7 @@ public SOG.Brep Convert(IRhinoBrep target) try { - joinedMesh.Append(_rhinoMeshFactory.CreateFromBrep(brep, 0.05, 0.05)); + joinedMesh.Append(RG.Mesh.CreateFromBrep(brep, mySettings)); return joinedMesh; } catch (Exception ex) when (!ex.IsFatal()) diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/CircleToSpeckleConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/CircleToSpeckleConverter.cs index 64ef397045..0e3f91e3bf 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/CircleToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/CircleToSpeckleConverter.cs @@ -1,35 +1,35 @@ -using Speckle.Converters.Common; +using Rhino; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Core.Models; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.Raw; -public class CircleToSpeckleConverter : ITypedConverter +public class CircleToSpeckleConverter : ITypedConverter { - private readonly ITypedConverter _planeConverter; - private readonly IConversionContextStack _contextStack; + private readonly ITypedConverter _planeConverter; + private readonly IConversionContextStack _contextStack; public CircleToSpeckleConverter( - ITypedConverter planeConverter, - IConversionContextStack contextStack + ITypedConverter planeConverter, + IConversionContextStack contextStack ) { _planeConverter = planeConverter; _contextStack = contextStack; } - public Base Convert(object target) => Convert((IRhinoCircle)target); + public Base Convert(object target) => Convert((RG.Circle)target); /// - /// Converts a IRhinoCircle object to a SOG.Circle object. + /// Converts a RG.Circle object to a SOG.Circle object. /// - /// The IRhinoCircle object to convert. + /// The RG.Circle object to convert. /// The converted SOG.Circle object. /// /// ⚠️ This conversion assumes the domain of a circle is (0,1) as Rhino Circle types do not have a domain. If you want to preserve the domain use ArcCurve conversion instead. /// - public SOG.Circle Convert(IRhinoCircle target) => + public SOG.Circle Convert(RG.Circle target) => new(_planeConverter.Convert(target.Plane), target.Radius, _contextStack.Current.SpeckleUnits) { domain = new SOP.Interval(0, 1), diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/ControlPointToSpeckleConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/ControlPointToSpeckleConverter.cs index 0fa733ca87..d3747e2faf 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/ControlPointToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/ControlPointToSpeckleConverter.cs @@ -1,14 +1,15 @@ -using Speckle.Converters.Common; +using Rhino; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; +using Speckle.Core.Models; namespace Speckle.Converters.Rhino7.ToSpeckle.Raw; -public class ControlPointToSpeckleConverter : ITypedConverter +public class ControlPointToSpeckleConverter : ITypedConverter { - private readonly IConversionContextStack _contextStack; + private readonly IConversionContextStack _contextStack; - public ControlPointToSpeckleConverter(IConversionContextStack contextStack) + public ControlPointToSpeckleConverter(IConversionContextStack contextStack) { _contextStack = contextStack; } @@ -18,6 +19,8 @@ public ControlPointToSpeckleConverter(IConversionContextStack /// The ControlPoint object to convert. /// The converted Speckle ControlPoint object. - public SOG.ControlPoint Convert(IRhinoControlPoint target) => + public SOG.ControlPoint Convert(RG.ControlPoint target) => new(target.Location.X, target.Location.Y, target.Location.Z, target.Weight, _contextStack.Current.SpeckleUnits); + + public Base Convert(object target) => Convert((RG.ControlPoint)target); } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/CurveToSpeckleConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/CurveToSpeckleConverter.cs index 855a2d43d5..5c792ebaf8 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/CurveToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/CurveToSpeckleConverter.cs @@ -1,25 +1,24 @@ using Objects; using Speckle.Converters.Common.Objects; using Speckle.Core.Models; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.Raw; // POC: CNX-9278 This converter decides which specific curve conversion to use. IIndex may be a better choice. -public class CurveToSpeckleConverter : ITypedConverter, ITypedConverter +public class CurveToSpeckleConverter : ITypedConverter, ITypedConverter { - private readonly ITypedConverter _polyCurveConverter; - private readonly ITypedConverter _arcCurveConverter; - private readonly ITypedConverter _polylineConverter; - private readonly ITypedConverter _nurbsCurveConverter; - private readonly ITypedConverter _lineCurveConverter; + private readonly ITypedConverter _polyCurveConverter; + private readonly ITypedConverter _arcCurveConverter; + private readonly ITypedConverter _polylineConverter; + private readonly ITypedConverter _nurbsCurveConverter; + private readonly ITypedConverter _lineCurveConverter; public CurveToSpeckleConverter( - ITypedConverter polyCurveConverter, - ITypedConverter arcCurveConverter, - ITypedConverter polylineConverter, - ITypedConverter nurbsCurveConverter, - ITypedConverter lineCurveConverter + ITypedConverter polyCurveConverter, + ITypedConverter arcCurveConverter, + ITypedConverter polylineConverter, + ITypedConverter nurbsCurveConverter, + ITypedConverter lineCurveConverter ) { _polyCurveConverter = polyCurveConverter; @@ -38,31 +37,15 @@ public CurveToSpeckleConverter( /// This is the main converter when the type of curve you input or output does not matter to the caller.
/// ⚠️ If an unsupported type of Curve is input, it will be converted to NURBS. /// - public ICurve Convert(IRhinoCurve target) - { - var polyline = target.ToPolylineCurve(); - if (polyline is not null) - { - return _polylineConverter.Convert(polyline); - } - var arcCurve = target.ToArcCurve(); - if (arcCurve is not null) - { - return _arcCurveConverter.Convert(arcCurve); - } - var polyCurve = target.ToPolyCurve(); - if (polyCurve is not null) + public ICurve Convert(RG.Curve target) => + target switch { - return _polyCurveConverter.Convert(polyCurve); - } - var lineCurve = target.ToLineCurve(); - if (lineCurve is not null) - { - return _lineCurveConverter.Convert(lineCurve); - } - var nurbsCurve = target.ToNurbsCurve(); - return _nurbsCurveConverter.Convert(nurbsCurve); - } + RG.PolyCurve polyCurve => _polyCurveConverter.Convert(polyCurve), + RG.ArcCurve arcCurve => _arcCurveConverter.Convert(arcCurve), + RG.PolylineCurve polylineCurve => _polylineConverter.Convert(polylineCurve), + RG.LineCurve lineCurve => _lineCurveConverter.Convert(lineCurve), + _ => _nurbsCurveConverter.Convert(target.ToNurbsCurve()) + }; - Base ITypedConverter.Convert(IRhinoCurve target) => (Base)Convert(target); + Base ITypedConverter.Convert(RG.Curve target) => (Base)Convert(target); } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/EllipseToSpeckleConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/EllipseToSpeckleConverter.cs index 0420067ae7..fc6b52cc8f 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/EllipseToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/EllipseToSpeckleConverter.cs @@ -1,27 +1,24 @@ -using Speckle.Converters.Common; +using Rhino; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.Raw; -public class EllipseToSpeckleConverter : ITypedConverter +public class EllipseToSpeckleConverter : ITypedConverter { - private readonly ITypedConverter _planeConverter; - private readonly ITypedConverter _boxConverter; - private readonly IConversionContextStack _contextStack; - private readonly IRhinoBoxFactory _rhinoBoxFactory; + private readonly ITypedConverter _planeConverter; + private readonly ITypedConverter _boxConverter; + private readonly IConversionContextStack _contextStack; public EllipseToSpeckleConverter( - ITypedConverter planeConverter, - ITypedConverter boxConverter, - IConversionContextStack contextStack, - IRhinoBoxFactory rhinoBoxFactory + ITypedConverter planeConverter, + ITypedConverter boxConverter, + IConversionContextStack contextStack ) { _planeConverter = planeConverter; _boxConverter = boxConverter; _contextStack = contextStack; - _rhinoBoxFactory = rhinoBoxFactory; } /// @@ -32,7 +29,7 @@ IRhinoBoxFactory rhinoBoxFactory /// /// ⚠️ Rhino ellipses are not curves. The result is a mathematical representation of an ellipse that can be converted into NURBS for display. /// - public SOG.Ellipse Convert(IRhinoEllipse target) + public SOG.Ellipse Convert(RG.Ellipse target) { var nurbsCurve = target.ToNurbsCurve(); return new( @@ -45,7 +42,7 @@ public SOG.Ellipse Convert(IRhinoEllipse target) domain = new SOP.Interval(0, 1), length = nurbsCurve.GetLength(), area = Math.PI * target.Radius1 * target.Radius2, - bbox = _boxConverter.Convert(_rhinoBoxFactory.CreateBox(nurbsCurve.GetBoundingBox(true))) + bbox = _boxConverter.Convert(new RG.Box(nurbsCurve.GetBoundingBox(true))) }; } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/IntervalToSpeckleConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/IntervalToSpeckleConverter.cs index 8044a90e7d..272fecafdb 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/IntervalToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/IntervalToSpeckleConverter.cs @@ -1,14 +1,13 @@ using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.Raw; -public class IntervalToSpeckleConverter : ITypedConverter +public class IntervalToSpeckleConverter : ITypedConverter { /// /// Converts a Rhino Interval object to a Speckle Interval object. /// /// The Rhino Interval object to be converted. /// The converted Speckle Interval object. - public SOP.Interval Convert(IRhinoInterval target) => new(target.T0, target.T1); + public SOP.Interval Convert(RG.Interval target) => new(target.T0, target.T1); } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/LineToSpeckleConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/LineToSpeckleConverter.cs index dc480c79fd..f40620f78d 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/LineToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/LineToSpeckleConverter.cs @@ -1,27 +1,24 @@ -using Speckle.Converters.Common; +using Rhino; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.Raw; -public class LineToSpeckleConverter : ITypedConverter, ITypedConverter +public class LineToSpeckleConverter : ITypedConverter, ITypedConverter { - private readonly ITypedConverter _pointConverter; - private readonly ITypedConverter _boxConverter; - private readonly IConversionContextStack _contextStack; - private readonly IRhinoBoxFactory _rhinoBoxFactory; + private readonly ITypedConverter _pointConverter; + private readonly ITypedConverter _boxConverter; + private readonly IConversionContextStack _contextStack; public LineToSpeckleConverter( - ITypedConverter pointConverter, - ITypedConverter boxConverter, - IConversionContextStack contextStack, - IRhinoBoxFactory rhinoBoxFactory + ITypedConverter pointConverter, + ITypedConverter boxConverter, + IConversionContextStack contextStack ) { _pointConverter = pointConverter; _boxConverter = boxConverter; _contextStack = contextStack; - _rhinoBoxFactory = rhinoBoxFactory; } /// @@ -32,13 +29,13 @@ IRhinoBoxFactory rhinoBoxFactory /// /// ⚠️ This conversion assumes the domain of a line is (0, LENGTH), as Rhino Lines do not have domain. If you want the domain preserved use LineCurve conversions instead. /// - public SOG.Line Convert(IRhinoLine target) => + public SOG.Line Convert(RG.Line target) => new(_pointConverter.Convert(target.From), _pointConverter.Convert(target.To), _contextStack.Current.SpeckleUnits) { length = target.Length, domain = new SOP.Interval(0, target.Length), - bbox = _boxConverter.Convert(_rhinoBoxFactory.CreateBox(target.BoundingBox)) + bbox = _boxConverter.Convert(new RG.Box(target.BoundingBox)) }; - public SOG.Line Convert(IRhinoLineCurve target) => Convert(target.Line); + public SOG.Line Convert(RG.LineCurve target) => Convert(target.Line); } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/MeshToSpeckleConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/MeshToSpeckleConverter.cs index cf7dfbc288..73aa3f4a8a 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/MeshToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/MeshToSpeckleConverter.cs @@ -1,25 +1,25 @@ -using Speckle.Converters.Common; +using Rhino; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.Raw; -[NameAndRankValue(nameof(IRhinoMesh), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public class MeshToSpeckleConverter : ITypedConverter +[NameAndRankValue(nameof(RG.Mesh), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +public class MeshToSpeckleConverter : ITypedConverter { - private readonly ITypedConverter _boxConverter; - private readonly IConversionContextStack _contextStack; - private readonly IRhinoBoxFactory _rhinoBoxFactory; + private readonly ITypedConverter _pointConverter; + private readonly ITypedConverter _boxConverter; + private readonly IConversionContextStack _contextStack; public MeshToSpeckleConverter( - ITypedConverter boxConverter, - IConversionContextStack contextStack, - IRhinoBoxFactory rhinoBoxFactory + ITypedConverter pointConverter, + ITypedConverter boxConverter, + IConversionContextStack contextStack ) { + _pointConverter = pointConverter; _boxConverter = boxConverter; _contextStack = contextStack; - _rhinoBoxFactory = rhinoBoxFactory; } /// @@ -28,7 +28,7 @@ IRhinoBoxFactory rhinoBoxFactory /// The Rhino Mesh to be converted. /// The converted Speckle Mesh. /// Thrown when the Rhino Mesh has 0 vertices or faces. - public SOG.Mesh Convert(IRhinoMesh target) + public SOG.Mesh Convert(RG.Mesh target) { if (target.Vertices.Count == 0 || target.Faces.Count == 0) { @@ -38,7 +38,7 @@ public SOG.Mesh Convert(IRhinoMesh target) var vertexCoordinates = target.Vertices.ToPoint3dArray().SelectMany(pt => new[] { pt.X, pt.Y, pt.Z }).ToList(); var faces = new List(); - foreach (IRhinoMeshNgon polygon in target.GetNgonAndFacesEnumerable()) + foreach (RG.MeshNgon polygon in target.GetNgonAndFacesEnumerable()) { var vertIndices = polygon.BoundaryVertexIndexList(); int n = vertIndices.Length; @@ -55,7 +55,7 @@ public SOG.Mesh Convert(IRhinoMesh target) var colors = target.VertexColors.Select(cl => cl.ToArgb()).ToList(); var volume = target.IsClosed ? target.Volume() : 0; - var bbox = _boxConverter.Convert(_rhinoBoxFactory.CreateBox(target.GetBoundingBox(false))); + var bbox = _boxConverter.Convert(new RG.Box(target.GetBoundingBox(false))); return new SOG.Mesh(vertexCoordinates, faces, colors, textureCoordinates, _contextStack.Current.SpeckleUnits) { diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/NurbsCurveConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/NurbsCurveConverter.cs index 7c28b72c3d..6cf8dca53d 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/NurbsCurveConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/NurbsCurveConverter.cs @@ -1,30 +1,27 @@ -using Speckle.Converters.Common; +using Rhino; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.Raw; -public class NurbsCurveConverter : ITypedConverter +public class NurbsCurveConverter : ITypedConverter { - private readonly ITypedConverter _polylineConverter; - private readonly ITypedConverter _intervalConverter; - private readonly ITypedConverter _boxConverter; - private readonly IConversionContextStack _contextStack; - private readonly IRhinoBoxFactory _rhinoBoxFactory; + private readonly ITypedConverter _polylineConverter; + private readonly ITypedConverter _intervalConverter; + private readonly ITypedConverter _boxConverter; + private readonly IConversionContextStack _contextStack; public NurbsCurveConverter( - ITypedConverter polylineConverter, - ITypedConverter intervalConverter, - ITypedConverter boxConverter, - IConversionContextStack contextStack, - IRhinoBoxFactory rhinoBoxFactory + ITypedConverter polylineConverter, + ITypedConverter intervalConverter, + ITypedConverter boxConverter, + IConversionContextStack contextStack ) { _polylineConverter = polylineConverter; _intervalConverter = intervalConverter; _boxConverter = boxConverter; _contextStack = contextStack; - _rhinoBoxFactory = rhinoBoxFactory; } /// @@ -37,9 +34,13 @@ IRhinoBoxFactory rhinoBoxFactory /// It adds 1 extra knot at the start and end of the vector by repeating the first and last value. /// This is because Rhino's standard of (controlPoints + degree + 1) wasn't followed on other software. /// - public SOG.Curve Convert(IRhinoNurbsCurve target) + public SOG.Curve Convert(RG.NurbsCurve target) { target.ToPolyline(0, 1, 0, 0, 0, 0.1, 0, 0, true).TryGetPolyline(out var poly); + if (target.IsClosed) + { + poly.Add(poly[0]); + } SOG.Polyline displayValue = _polylineConverter.Convert(poly); @@ -62,7 +63,7 @@ public SOG.Curve Convert(IRhinoNurbsCurve target) domain = _intervalConverter.Convert(nurbsCurve.Domain), closed = nurbsCurve.IsClosed, length = nurbsCurve.GetLength(), - bbox = _boxConverter.Convert(_rhinoBoxFactory.CreateBox(nurbsCurve.GetBoundingBox(true))) + bbox = _boxConverter.Convert(new RG.Box(nurbsCurve.GetBoundingBox(true))) }; return myCurve; diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/NurbsSurfaceToSpeckleConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/NurbsSurfaceToSpeckleConverter.cs index 4f4952622a..0d663ff520 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/NurbsSurfaceToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/NurbsSurfaceToSpeckleConverter.cs @@ -1,30 +1,28 @@ -using Speckle.Converters.Common; +using Rhino; +using Rhino.Geometry.Collections; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.Raw; -public class NurbsSurfaceToSpeckleConverter : ITypedConverter +public class NurbsSurfaceToSpeckleConverter : ITypedConverter { - private readonly ITypedConverter _boxConverter; - private readonly ITypedConverter _intervalConverter; - private readonly ITypedConverter _controlPointConverter; - private readonly IConversionContextStack _contextStack; - private readonly IRhinoBoxFactory _rhinoBoxFactory; + private readonly ITypedConverter _boxConverter; + private readonly ITypedConverter _intervalConverter; + private readonly ITypedConverter _controlPointConverter; + private readonly IConversionContextStack _contextStack; public NurbsSurfaceToSpeckleConverter( - ITypedConverter boxConverter, - ITypedConverter intervalConverter, - ITypedConverter controlPointConverter, - IConversionContextStack contextStack, - IRhinoBoxFactory rhinoBoxFactory + ITypedConverter boxConverter, + ITypedConverter intervalConverter, + ITypedConverter controlPointConverter, + IConversionContextStack contextStack ) { _boxConverter = boxConverter; _intervalConverter = intervalConverter; _controlPointConverter = controlPointConverter; _contextStack = contextStack; - _rhinoBoxFactory = rhinoBoxFactory; } /// @@ -32,7 +30,7 @@ IRhinoBoxFactory rhinoBoxFactory /// /// The NurbsSurface object to convert. /// A Surface object representing the converted NurbsSurface. - public SOG.Surface Convert(IRhinoNurbsSurface target) + public SOG.Surface Convert(RG.NurbsSurface target) { var result = new SOG.Surface { @@ -46,7 +44,7 @@ public SOG.Surface Convert(IRhinoNurbsSurface target) knotsU = target.KnotsU.ToList(), knotsV = target.KnotsV.ToList(), units = _contextStack.Current.SpeckleUnits, - bbox = _boxConverter.Convert(_rhinoBoxFactory.CreateBox(target.GetBoundingBox(true))) + bbox = _boxConverter.Convert(new RG.Box(target.GetBoundingBox(true))) }; result.SetControlPoints(ControlPointsToSpeckle(target.Points)); @@ -54,7 +52,7 @@ public SOG.Surface Convert(IRhinoNurbsSurface target) return result; } - private List> ControlPointsToSpeckle(IRhinoNurbsSurfacePointList controlPoints) + private List> ControlPointsToSpeckle(NurbsSurfacePointList controlPoints) { var points = new List>(); for (var i = 0; i < controlPoints.CountU; i++) diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/PlaneToSpeckleConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/PlaneToSpeckleConverter.cs index b2a3264467..40d15be50c 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/PlaneToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/PlaneToSpeckleConverter.cs @@ -1,19 +1,19 @@ +using Rhino; using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.Raw; -public class PlaneToSpeckleConverter : ITypedConverter +public class PlaneToSpeckleConverter : ITypedConverter { - private readonly ITypedConverter _vectorConverter; - private readonly ITypedConverter _pointConverter; - private readonly IConversionContextStack _contextStack; + private readonly ITypedConverter _vectorConverter; + private readonly ITypedConverter _pointConverter; + private readonly IConversionContextStack _contextStack; public PlaneToSpeckleConverter( - ITypedConverter vectorConverter, - ITypedConverter pointConverter, - IConversionContextStack contextStack + ITypedConverter vectorConverter, + ITypedConverter pointConverter, + IConversionContextStack contextStack ) { _vectorConverter = vectorConverter; @@ -26,7 +26,7 @@ IConversionContextStack contextStack /// /// The instance of Rhino Plane to convert. /// The converted instance of Speckle Plane. - public SOG.Plane Convert(IRhinoPlane target) => + public SOG.Plane Convert(RG.Plane target) => new( _pointConverter.Convert(target.Origin), _vectorConverter.Convert(target.ZAxis), diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/PointToSpeckleConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/PointToSpeckleConverter.cs index c110af447a..2bfdfdae1c 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/PointToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/PointToSpeckleConverter.cs @@ -1,16 +1,14 @@ +using Rhino; using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.Raw; -public class PointToSpeckleConverter - : ITypedConverter, - ITypedConverter +public class PointToSpeckleConverter : ITypedConverter, ITypedConverter { - private readonly IConversionContextStack _contextStack; + private readonly IConversionContextStack _contextStack; - public PointToSpeckleConverter(IConversionContextStack contextStack) + public PointToSpeckleConverter(IConversionContextStack contextStack) { _contextStack = contextStack; } @@ -20,8 +18,7 @@ public PointToSpeckleConverter(IConversionContextStack /// The Rhino 3D point to convert. /// The converted Speckle point. - public SOG.Point Convert(IRhinoPoint3d target) => - new(target.X, target.Y, target.Z, _contextStack.Current.SpeckleUnits); + public SOG.Point Convert(RG.Point3d target) => new(target.X, target.Y, target.Z, _contextStack.Current.SpeckleUnits); - public SOG.Point Convert(IRhinoPoint target) => Convert(target.Location); + public SOG.Point Convert(RG.Point target) => Convert(target.Location); } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/PolyCurveToSpeckleConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/PolyCurveToSpeckleConverter.cs index 10cdf491d5..6937d6b007 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/PolyCurveToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/PolyCurveToSpeckleConverter.cs @@ -1,30 +1,26 @@ using Objects; +using Rhino; using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.Raw; -public class PolyCurveToSpeckleConverter : ITypedConverter +public class PolyCurveToSpeckleConverter : ITypedConverter { - public ITypedConverter? CurveConverter { get; set; } // POC: CNX-9279 This created a circular dependency on the constructor, making it a property allows for the container to resolve it correctly - - private readonly ITypedConverter _intervalConverter; - private readonly ITypedConverter _boxConverter; - private readonly IConversionContextStack _contextStack; - private readonly IRhinoBoxFactory _rhinoBoxFactory; + public ITypedConverter? CurveConverter { get; set; } // POC: CNX-9279 This created a circular dependency on the constructor, making it a property allows for the container to resolve it correctly + private readonly ITypedConverter _intervalConverter; + private readonly ITypedConverter _boxConverter; + private readonly IConversionContextStack _contextStack; public PolyCurveToSpeckleConverter( - ITypedConverter intervalConverter, - ITypedConverter boxConverter, - IConversionContextStack contextStack, - IRhinoBoxFactory rhinoBoxFactory + ITypedConverter intervalConverter, + ITypedConverter boxConverter, + IConversionContextStack contextStack ) { _intervalConverter = intervalConverter; _boxConverter = boxConverter; _contextStack = contextStack; - _rhinoBoxFactory = rhinoBoxFactory; } /// @@ -36,14 +32,14 @@ IRhinoBoxFactory rhinoBoxFactory /// This method removes the nesting of the PolyCurve by duplicating the segments at a granular level. /// All PolyLIne, PolyCurve and NURBS curves with G1 discontinuities will be broken down. /// - public SOG.Polycurve Convert(IRhinoPolyCurve target) + public SOG.Polycurve Convert(RG.PolyCurve target) { var myPoly = new SOG.Polycurve { closed = target.IsClosed, domain = _intervalConverter.Convert(target.Domain), length = target.GetLength(), - bbox = _boxConverter.Convert(_rhinoBoxFactory.CreateBox(target.GetBoundingBox(true))), + bbox = _boxConverter.Convert(new RG.Box(target.GetBoundingBox(true))), segments = target.DuplicateSegments().Select(x => CurveConverter.NotNull().Convert(x)).ToList(), units = _contextStack.Current.SpeckleUnits }; diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/PolylineToSpeckleConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/PolylineToSpeckleConverter.cs index 7682ceeb42..1ee241e7d1 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/PolylineToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/PolylineToSpeckleConverter.cs @@ -1,32 +1,29 @@ -using Speckle.Converters.Common; +using Rhino; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.Raw; public class PolylineToSpeckleConverter - : ITypedConverter, - ITypedConverter + : ITypedConverter, + ITypedConverter { - private readonly ITypedConverter _pointConverter; - private readonly ITypedConverter _boxConverter; - private readonly ITypedConverter _intervalConverter; - private readonly IConversionContextStack _contextStack; - private readonly IRhinoBoxFactory _rhinoBoxFactory; + private readonly ITypedConverter _pointConverter; + private readonly ITypedConverter _boxConverter; + private readonly ITypedConverter _intervalConverter; + private readonly IConversionContextStack _contextStack; public PolylineToSpeckleConverter( - ITypedConverter pointConverter, - ITypedConverter boxConverter, - IConversionContextStack contextStack, - ITypedConverter intervalConverter, - IRhinoBoxFactory rhinoBoxFactory + ITypedConverter pointConverter, + ITypedConverter boxConverter, + IConversionContextStack contextStack, + ITypedConverter intervalConverter ) { _pointConverter = pointConverter; _boxConverter = boxConverter; _contextStack = contextStack; _intervalConverter = intervalConverter; - _rhinoBoxFactory = rhinoBoxFactory; } /// @@ -35,12 +32,12 @@ IRhinoBoxFactory rhinoBoxFactory /// The Rhino polyline to be converted. /// The converted Speckle polyline. /// ⚠️ This conversion assumes domain interval is (0,LENGTH) as Rhino Polylines have no domain. If needed, you may want to use PolylineCurve conversion instead. - public SOG.Polyline Convert(IRhinoPolyline target) + public SOG.Polyline Convert(RG.Polyline target) { - var box = _boxConverter.Convert(_rhinoBoxFactory.CreateBox(target.BoundingBox)); + var box = _boxConverter.Convert(new RG.Box(target.BoundingBox)); var points = target.Select(pt => _pointConverter.Convert(pt)).ToList(); - if (points[0] == points[^1] && target.IsClosed) + if (target.IsClosed) { points.RemoveAt(points.Count - 1); } @@ -51,8 +48,8 @@ public SOG.Polyline Convert(IRhinoPolyline target) ) { bbox = box, - length = target.Count, - domain = new(0, target.Count), + length = target.Length, + domain = new(0, target.Length), closed = target.IsClosed }; } @@ -63,7 +60,7 @@ public SOG.Polyline Convert(IRhinoPolyline target) /// The Rhino PolylineCurve to be converted. /// The converted Speckle polyline. /// ✅ This conversion respects the domain of the original PolylineCurve - public SOG.Polyline Convert(IRhinoPolylineCurve target) + public SOG.Polyline Convert(RG.PolylineCurve target) { var result = Convert(target.ToPolyline()); result.domain = _intervalConverter.Convert(target.Domain); diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/RawPointCloudToSpeckle.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/RawPointCloudToSpeckle.cs index f7d0fdee98..5e4a17e6cb 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/RawPointCloudToSpeckle.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/RawPointCloudToSpeckle.cs @@ -1,24 +1,21 @@ -using Speckle.Converters.Common; +using Rhino; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.Raw; -public class RawPointCloudToSpeckle : ITypedConverter +public class RawPointCloudToSpeckle : ITypedConverter { - private readonly IConversionContextStack _contextStack; - private readonly ITypedConverter _boxConverter; - private readonly IRhinoBoxFactory _rhinoBoxFactory; + private readonly IConversionContextStack _contextStack; + private readonly ITypedConverter _boxConverter; public RawPointCloudToSpeckle( - IConversionContextStack contextStack, - ITypedConverter boxConverter, - IRhinoBoxFactory rhinoBoxFactory + IConversionContextStack contextStack, + ITypedConverter boxConverter ) { _contextStack = contextStack; _boxConverter = boxConverter; - _rhinoBoxFactory = rhinoBoxFactory; } /// @@ -26,12 +23,12 @@ IRhinoBoxFactory rhinoBoxFactory /// /// The Rhino PointCloud object to convert. /// The converted Speckle Pointcloud object. - public SOG.Pointcloud Convert(IRhinoPointCloud target) => + public SOG.Pointcloud Convert(RG.PointCloud target) => new() { points = target.GetPoints().SelectMany(pt => new[] { pt.X, pt.Y, pt.Z }).ToList(), colors = target.GetColors().Select(o => o.ToArgb()).ToList(), - bbox = _boxConverter.Convert(_rhinoBoxFactory.CreateBox(target.GetBoundingBox(true))), + bbox = _boxConverter.Convert(new RG.Box(target.GetBoundingBox(true))), units = _contextStack.Current.SpeckleUnits }; } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/VectorToSpeckleConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/VectorToSpeckleConverter.cs index fe5de7db27..489eddedc4 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/VectorToSpeckleConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/Raw/VectorToSpeckleConverter.cs @@ -1,14 +1,14 @@ -using Speckle.Converters.Common; +using Rhino; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.Raw; -public class VectorToSpeckleConverter : ITypedConverter +public class VectorToSpeckleConverter : ITypedConverter { - private readonly IConversionContextStack _contextStack; + private readonly IConversionContextStack _contextStack; - public VectorToSpeckleConverter(IConversionContextStack contextStack) + public VectorToSpeckleConverter(IConversionContextStack contextStack) { _contextStack = contextStack; } @@ -18,6 +18,6 @@ public VectorToSpeckleConverter(IConversionContextStack /// The Rhino Vector3d object to convert. /// The converted Speckle Vector object. - public SOG.Vector Convert(IRhinoVector3d target) => + public SOG.Vector Convert(RG.Vector3d target) => new(target.X, target.Y, target.Z, _contextStack.Current.SpeckleUnits); } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/BrepObjectToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/BrepObjectToSpeckleTopLevelConverter.cs index d55b39090c..7520c1bd83 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/BrepObjectToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/BrepObjectToSpeckleTopLevelConverter.cs @@ -1,23 +1,23 @@ -using Speckle.Converters.Common; +using Rhino.DocObjects; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Core.Models; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.TopLevel; -[NameAndRankValue(nameof(IRhinoBrepObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +[NameAndRankValue(nameof(BrepObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] public class BrepObjectToSpeckleTopLevelConverter : IToSpeckleTopLevelConverter { - private readonly ITypedConverter _curveConverter; + private readonly ITypedConverter _curveConverter; - public BrepObjectToSpeckleTopLevelConverter(ITypedConverter curveConverter) + public BrepObjectToSpeckleTopLevelConverter(ITypedConverter curveConverter) { _curveConverter = curveConverter; } public Base Convert(object target) { - var curveObject = (IRhinoBrepObject)target; //can only be this type + var curveObject = (BrepObject)target; var speckleCurve = _curveConverter.Convert(curveObject.BrepGeometry); return speckleCurve; } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/CurveObjectToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/CurveObjectToSpeckleTopLevelConverter.cs index 34fcf6c18e..a8214a0c97 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/CurveObjectToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/CurveObjectToSpeckleTopLevelConverter.cs @@ -1,16 +1,15 @@ -using Speckle.Converters.Common; +using Rhino.DocObjects; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Core.Models; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.TopLevel; -[NameAndRankValue(nameof(IRhinoCurveObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public class CurveObjectToSpeckleTopLevelConverter - : RhinoObjectToSpeckleTopLevelConverter +[NameAndRankValue(nameof(CurveObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +public class CurveObjectToSpeckleTopLevelConverter : RhinoObjectToSpeckleTopLevelConverter { - public CurveObjectToSpeckleTopLevelConverter(ITypedConverter conversion) + public CurveObjectToSpeckleTopLevelConverter(ITypedConverter conversion) : base(conversion) { } - protected override IRhinoCurve GetTypedGeometry(IRhinoCurveObject input) => input.CurveGeometry; + protected override RG.Curve GetTypedGeometry(CurveObject input) => input.CurveGeometry; } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/ExtrusionObjectToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/ExtrusionObjectToSpeckleTopLevelConverter.cs index 3c5d93335d..46d2c27586 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/ExtrusionObjectToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/ExtrusionObjectToSpeckleTopLevelConverter.cs @@ -1,23 +1,23 @@ -using Speckle.Converters.Common; +using Rhino.DocObjects; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Core.Models; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.TopLevel; -[NameAndRankValue(nameof(IRhinoExtrusionObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +[NameAndRankValue(nameof(ExtrusionObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] public class ExtrusionObjectToSpeckleTopLevelConverter : IToSpeckleTopLevelConverter { - private readonly ITypedConverter _curveConverter; + private readonly ITypedConverter _curveConverter; - public ExtrusionObjectToSpeckleTopLevelConverter(ITypedConverter curveConverter) + public ExtrusionObjectToSpeckleTopLevelConverter(ITypedConverter curveConverter) { _curveConverter = curveConverter; } public Base Convert(object target) { - var curveObject = (IRhinoExtrusionObject)target; //can only be this type + var curveObject = (ExtrusionObject)target; var speckleCurve = _curveConverter.Convert(curveObject.ExtrusionGeometry.ToBrep()); return speckleCurve; } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/MeshObjectToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/MeshObjectToSpeckleTopLevelConverter.cs index 025e36fd99..f1c9675a04 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/MeshObjectToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/MeshObjectToSpeckleTopLevelConverter.cs @@ -1,15 +1,14 @@ -using Speckle.Converters.Common; +using Rhino.DocObjects; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.TopLevel; -[NameAndRankValue(nameof(IRhinoMeshObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public class MeshObjectToSpeckleTopLevelConverter - : RhinoObjectToSpeckleTopLevelConverter +[NameAndRankValue(nameof(MeshObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +public class MeshObjectToSpeckleTopLevelConverter : RhinoObjectToSpeckleTopLevelConverter { - public MeshObjectToSpeckleTopLevelConverter(ITypedConverter conversion) + public MeshObjectToSpeckleTopLevelConverter(ITypedConverter conversion) : base(conversion) { } - protected override IRhinoMesh GetTypedGeometry(IRhinoMeshObject input) => input.MeshGeometry; + protected override RG.Mesh GetTypedGeometry(MeshObject input) => input.MeshGeometry; } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/PointCloudObjectToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/PointCloudObjectToSpeckleTopLevelConverter.cs index b25c80d190..e741e38e49 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/PointCloudObjectToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/PointCloudObjectToSpeckleTopLevelConverter.cs @@ -1,15 +1,15 @@ -using Speckle.Converters.Common; +using Rhino.DocObjects; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.TopLevel; -[NameAndRankValue(nameof(IRhinoPointCloudObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +[NameAndRankValue(nameof(PointCloudObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] public class PointCloudObjectToSpeckleTopLevelConverter - : RhinoObjectToSpeckleTopLevelConverter + : RhinoObjectToSpeckleTopLevelConverter { - public PointCloudObjectToSpeckleTopLevelConverter(ITypedConverter conversion) + public PointCloudObjectToSpeckleTopLevelConverter(ITypedConverter conversion) : base(conversion) { } - protected override IRhinoPointCloud GetTypedGeometry(IRhinoPointCloudObject input) => input.PointCloudGeometry; + protected override RG.PointCloud GetTypedGeometry(PointCloudObject input) => input.PointCloudGeometry; } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/PointObjectToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/PointObjectToSpeckleTopLevelConverter.cs index d127aa0266..7d9c750b64 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/PointObjectToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/PointObjectToSpeckleTopLevelConverter.cs @@ -1,15 +1,15 @@ -using Speckle.Converters.Common; +using Rhino.DocObjects; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.TopLevel; -[NameAndRankValue(nameof(IRhinoPointObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +[NameAndRankValue(nameof(PointObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] public class PointObjectToSpeckleTopLevelConverter - : RhinoObjectToSpeckleTopLevelConverter + : RhinoObjectToSpeckleTopLevelConverter { - public PointObjectToSpeckleTopLevelConverter(ITypedConverter conversion) + public PointObjectToSpeckleTopLevelConverter(ITypedConverter conversion) : base(conversion) { } - protected override IRhinoPoint GetTypedGeometry(IRhinoPointObject input) => input.PointGeometry; + protected override RG.Point GetTypedGeometry(PointObject input) => input.PointGeometry; } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/RhinoObjectToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/RhinoObjectToSpeckleTopLevelConverter.cs index f86d7a09f5..edff24473a 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/RhinoObjectToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/RhinoObjectToSpeckleTopLevelConverter.cs @@ -4,15 +4,15 @@ namespace Speckle.Converters.Rhino7.ToSpeckle.TopLevel; public abstract class RhinoObjectToSpeckleTopLevelConverter : IToSpeckleTopLevelConverter - where TTopLevelIn : notnull - where TInRaw : notnull + where TTopLevelIn : Rhino.DocObjects.RhinoObject + where TInRaw : RG.GeometryBase where TOutRaw : Base { - private readonly ITypedConverter _conversion; + public ITypedConverter Conversion { get; } protected RhinoObjectToSpeckleTopLevelConverter(ITypedConverter conversion) { - _conversion = conversion; + Conversion = conversion; } // POC: IIndex would fix this as I would just request the type from `RhinoObject.Geometry` directly. @@ -20,10 +20,10 @@ protected RhinoObjectToSpeckleTopLevelConverter(ITypedConverter public virtual Base Convert(object target) { - var typedTarget = (TTopLevelIn)target; //can only be this typee + var typedTarget = (TTopLevelIn)target; var typedGeometry = GetTypedGeometry(typedTarget); - var result = _conversion.Convert(typedGeometry); + var result = Conversion.Convert(typedGeometry); // POC: Any common operations for all RhinoObjects should be done here, not on the specific implementer // Things like user-dictionaries and other user-defined metadata. diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/packages.lock.json b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/packages.lock.json index e88d9d0998..57b03cf40e 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/packages.lock.json +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/packages.lock.json @@ -18,18 +18,18 @@ "resolved": "1.14.1", "contentHash": "mOOmFYwad3MIOL14VCjj02LljyF1GNw1wP0YVlxtcPvqdxjGGMNdNJJxHptlry3MOd8b40Flm8RPOM8JOlN2sQ==" }, + "RhinoCommon": { + "type": "Direct", + "requested": "[7.13.21348.13001, )", + "resolved": "7.13.21348.13001", + "contentHash": "JQdaNw61ddBqIe08E9O4N/grwrN1hjDHcYW7tWylwCZyFR7SepoCD4NS+6LN6+oSQhNbhLi9Bf+hQOFYFdRAEA==" + }, "Speckle.InterfaceGenerator": { "type": "Direct", "requested": "[0.9.5, )", "resolved": "0.9.5", "contentHash": "oU/L7pN1R7q8KkbrpQ3WJnHirPHqn+9DEA7asOcUiggV5dzVg1A/VYs7GOSusD24njxXh03tE3a2oTLOjt3cVg==" }, - "Speckle.Rhino7.Interfaces": { - "type": "Direct", - "requested": "[0.1.1-preview.0.28, )", - "resolved": "0.1.1-preview.0.28", - "contentHash": "TcbfXlRMnQRat1JodgW+YW5FflTYem1GGo9DtKA+6iAuVaYagN5dxsrM5LE6M3pCnEV9rkEQOjFo7sgnnbo4mw==" - }, "GraphQL.Client": { "type": "Transitive", "resolved": "6.0.0", diff --git a/DUI3-DX/DUI3/Speckle.Connectors.DUI.WebView/packages.lock.json b/DUI3-DX/DUI3/Speckle.Connectors.DUI.WebView/packages.lock.json index 2586c0cd45..9529e2c9c7 100644 --- a/DUI3-DX/DUI3/Speckle.Connectors.DUI.WebView/packages.lock.json +++ b/DUI3-DX/DUI3/Speckle.Connectors.DUI.WebView/packages.lock.json @@ -262,29 +262,6 @@ "Serilog": "2.10.0" } }, - "Speckle.Core": { - "type": "Transitive", - "resolved": "3.0.1-alpha.11", - "contentHash": "Zt2dBJLlfziEACYCHThbhKypSjhoA01rTw9BzNI72c/BDyftXIz70Tetq/8ZMEqQnKqfmRyYADsAdWKxpdV0Hg==", - "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.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.Newtonsoft.Json": { "type": "Transitive", "resolved": "13.0.2", @@ -803,29 +780,6 @@ "Serilog": "2.10.0" } }, - "Speckle.Core": { - "type": "Transitive", - "resolved": "3.0.1-alpha.11", - "contentHash": "Zt2dBJLlfziEACYCHThbhKypSjhoA01rTw9BzNI72c/BDyftXIz70Tetq/8ZMEqQnKqfmRyYADsAdWKxpdV0Hg==", - "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.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.Newtonsoft.Json": { "type": "Transitive", "resolved": "13.0.2", diff --git a/DUI3-DX/Directory.Packages.props b/DUI3-DX/Directory.Packages.props index 5e7ea97006..ece50df9a0 100644 --- a/DUI3-DX/Directory.Packages.props +++ b/DUI3-DX/Directory.Packages.props @@ -3,25 +3,22 @@ - - - - - - - + + + + diff --git a/DUI3-DX/Sdk/Speckle.Connectors.Utils/ContainerRegistration.cs b/DUI3-DX/Sdk/Speckle.Connectors.Utils/ContainerRegistration.cs index 3168ac7709..93a7c326dd 100644 --- a/DUI3-DX/Sdk/Speckle.Connectors.Utils/ContainerRegistration.cs +++ b/DUI3-DX/Sdk/Speckle.Connectors.Utils/ContainerRegistration.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Logging; +using Autofac; +using Microsoft.Extensions.Logging; using Serilog; using Speckle.Autofac.DependencyInjection; using Speckle.Connectors.Utils.Cancellation; @@ -19,6 +20,9 @@ public static void AddConnectorUtils(this SpeckleContainerBuilder builder) var serilogLogger = SpeckleLog.Logger; ILoggerFactory loggerFactory = new LoggerFactory().AddSerilog(serilogLogger); + builder.ContainerBuilder.Register(_ => loggerFactory).As().SingleInstance().AutoActivate(); + + builder.ContainerBuilder.RegisterGeneric(typeof(Logger<>)).As(typeof(ILogger<>)).SingleInstance(); builder.AddSingleton(loggerFactory); } } diff --git a/DUI3-DX/Sdk/Speckle.Connectors.Utils/Speckle.Connectors.Utils.csproj b/DUI3-DX/Sdk/Speckle.Connectors.Utils/Speckle.Connectors.Utils.csproj index d379d2aace..125a1a6f7a 100644 --- a/DUI3-DX/Sdk/Speckle.Connectors.Utils/Speckle.Connectors.Utils.csproj +++ b/DUI3-DX/Sdk/Speckle.Connectors.Utils/Speckle.Connectors.Utils.csproj @@ -6,6 +6,7 @@ + diff --git a/DUI3-DX/Sdk/Speckle.Connectors.Utils/packages.lock.json b/DUI3-DX/Sdk/Speckle.Connectors.Utils/packages.lock.json index 077e72b92b..2b72b82db0 100644 --- a/DUI3-DX/Sdk/Speckle.Connectors.Utils/packages.lock.json +++ b/DUI3-DX/Sdk/Speckle.Connectors.Utils/packages.lock.json @@ -2,6 +2,15 @@ "version": 2, "dependencies": { ".NETStandard,Version=v2.0": { + "Autofac": { + "type": "Direct", + "requested": "[5.2.0, )", + "resolved": "5.2.0", + "contentHash": "V8dBH0dsv75uDzl7Sw+HkhKDPUw2eXnlMjcSVMH+tLo2s67MpTKGyDj1pDcpR+IF2u4YRs0s3/x7R88YJzIWvg==", + "dependencies": { + "Microsoft.Bcl.AsyncInterfaces": "1.1.0" + } + }, "Microsoft.SourceLink.GitHub": { "type": "Direct", "requested": "[8.0.0, )", diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/ContainerRegistration.cs b/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/ContainerRegistration.cs index 07f974d26a..6a5fb37913 100644 --- a/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/ContainerRegistration.cs +++ b/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/ContainerRegistration.cs @@ -12,7 +12,6 @@ this SpeckleContainerBuilder builder where TRootToSpeckleConverter : class, IRootToSpeckleConverter where THostToSpeckleUnitConverter : class, IHostToSpeckleUnitConverter { - builder.ScanAssemblyOfType(); builder.AddScoped(); builder.AddScoped, THostToSpeckleUnitConverter>(); /* @@ -30,7 +29,7 @@ This will require consolidating across other connectors. builder.AddScoped(); - builder.RegisterConverters(); + builder.RegisterRawConversions(); 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 1c701cc642..c4a0800ce7 100644 --- a/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/NamedTypeInjector.cs +++ b/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/NamedTypeInjector.cs @@ -7,8 +7,6 @@ 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 { @@ -21,33 +19,33 @@ public static void InjectNamedTypes(this SpeckleContainerBuilder containerBui { var nameAndRank = x.GetCustomAttribute(); - return new NamedType(Name: nameAndRank.Name, Rank: nameAndRank.Rank, Type: x); + return (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(); @@ -59,8 +57,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... @@ -69,11 +67,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 7b8743151e..73745af1f7 100644 --- a/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/RawConversionRegisterer.cs +++ b/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/RawConversionRegisterer.cs @@ -6,29 +6,22 @@ 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 ConverterRegistration +public static class RawConversionRegisterer { - public static void RegisterConverters(this SpeckleContainerBuilder containerBuilder) + public static void RegisterRawConversions(this SpeckleContainerBuilder containerBuilder) { // POC: hard-coding speckle... :/ foreach (Type speckleType in containerBuilder.SpeckleTypes) { - foreach (var conversionInterface in RegisterConversionsForType(speckleType)) - { - containerBuilder.ContainerBuilder - .RegisterType(speckleType) - .As(conversionInterface) - .PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies) - .InstancePerLifetimeScope(); - } + RegisterRawConversionsForType(containerBuilder.ContainerBuilder, speckleType); } } - private static IEnumerable RegisterConversionsForType(Type type) + private static void RegisterRawConversionsForType(ContainerBuilder containerBuilder, Type type) { if (!type.IsClass || type.IsAbstract) { - yield break; + return; } var rawConversionInterfaces = type.GetInterfaces() @@ -36,7 +29,11 @@ private static IEnumerable RegisterConversionsForType(Type type) foreach (var conversionInterface in rawConversionInterfaces) { - yield return conversionInterface.NotNull(); + containerBuilder + .RegisterType(type) + .As(conversionInterface) + .PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies) + .InstancePerLifetimeScope(); } } } diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common.Tests/FakeType.cs b/DUI3-DX/Sdk/Speckle.Converters.Common.Tests/FakeType.cs deleted file mode 100644 index 517313bd4b..0000000000 --- a/DUI3-DX/Sdk/Speckle.Converters.Common.Tests/FakeType.cs +++ /dev/null @@ -1,109 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using System.Globalization; -using System.Reflection; - -namespace Speckle.Converters.Common.Tests; - -public class FakeType : Type -{ - public FakeType(string name) - { - Name = name; - } - - public override object[] GetCustomAttributes(bool inherit) => throw new NotImplementedException(); - - public override bool IsDefined(Type attributeType, bool inherit) => throw new NotImplementedException(); - - public override ConstructorInfo[] GetConstructors(BindingFlags bindingAttr) => throw new NotImplementedException(); - - public override Type GetInterface(string name, bool ignoreCase) => throw new NotImplementedException(); - - public override Type[] GetInterfaces() => throw new NotImplementedException(); - - public override EventInfo GetEvent(string name, BindingFlags bindingAttr) => throw new NotImplementedException(); - - public override EventInfo[] GetEvents(BindingFlags bindingAttr) => throw new NotImplementedException(); - - public override Type[] GetNestedTypes(BindingFlags bindingAttr) => throw new NotImplementedException(); - - public override Type GetNestedType(string name, BindingFlags bindingAttr) => throw new NotImplementedException(); - - public override Type GetElementType() => throw new NotImplementedException(); - - protected override bool HasElementTypeImpl() => throw new NotImplementedException(); - - protected override PropertyInfo GetPropertyImpl( - string name, - BindingFlags bindingAttr, - Binder binder, - Type returnType, - Type[] types, - ParameterModifier[] modifiers - ) => throw new NotImplementedException(); - - public override PropertyInfo[] GetProperties(BindingFlags bindingAttr) => throw new NotImplementedException(); - - protected override MethodInfo GetMethodImpl( - string name, - BindingFlags bindingAttr, - Binder binder, - CallingConventions callConvention, - Type[] types, - ParameterModifier[] modifiers - ) => throw new NotImplementedException(); - - public override MethodInfo[] GetMethods(BindingFlags bindingAttr) => throw new NotImplementedException(); - - public override FieldInfo GetField(string name, BindingFlags bindingAttr) => throw new NotImplementedException(); - - public override FieldInfo[] GetFields(BindingFlags bindingAttr) => throw new NotImplementedException(); - - public override MemberInfo[] GetMembers(BindingFlags bindingAttr) => throw new NotImplementedException(); - - protected override TypeAttributes GetAttributeFlagsImpl() => throw new NotImplementedException(); - - protected override bool IsArrayImpl() => throw new NotImplementedException(); - - protected override bool IsByRefImpl() => throw new NotImplementedException(); - - protected override bool IsPointerImpl() => throw new NotImplementedException(); - - protected override bool IsPrimitiveImpl() => throw new NotImplementedException(); - - protected override bool IsCOMObjectImpl() => throw new NotImplementedException(); - - public override object InvokeMember( - string name, - BindingFlags invokeAttr, - Binder binder, - object target, - object[] args, - ParameterModifier[] modifiers, - CultureInfo culture, - string[] namedParameters - ) => throw new NotImplementedException(); - - public override Type UnderlyingSystemType { get; } - - protected override ConstructorInfo GetConstructorImpl( - BindingFlags bindingAttr, - Binder binder, - CallingConventions callConvention, - Type[] types, - ParameterModifier[] modifiers - ) => throw new NotImplementedException(); - - public override string Name { get; } - - [SuppressMessage("Naming", "CA1720:Identifier contains type name")] - public override Guid GUID { get; } = Guid.Empty; - public override Module Module { get; } - public override Assembly Assembly { get; } - public override string FullName { get; } - public override string Namespace { get; } - public override string AssemblyQualifiedName { get; } - public override Type BaseType { get; } - - public override object[] GetCustomAttributes(Type attributeType, bool inherit) => throw new NotImplementedException(); -} diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common.Tests/RootToSpeckleConverterTests.cs b/DUI3-DX/Sdk/Speckle.Converters.Common.Tests/RootToSpeckleConverterTests.cs deleted file mode 100644 index ae505bb94b..0000000000 --- a/DUI3-DX/Sdk/Speckle.Converters.Common.Tests/RootToSpeckleConverterTests.cs +++ /dev/null @@ -1,66 +0,0 @@ -using FluentAssertions; -using Moq; -using NUnit.Framework; -using Speckle.Core.Models; - -namespace Speckle.Converters.Common.Tests; - -public class RootToSpeckleConverterTests -{ - private readonly MockRepository _repository = new(MockBehavior.Strict); - - private readonly Mock _rootConvertManager; - private readonly Mock _proxyMapper; - private readonly Mock _rootElementProvider; - - public RootToSpeckleConverterTests() - { - _rootConvertManager = _repository.Create(); - _proxyMapper = _repository.Create(); - _rootElementProvider = _repository.Create(); - } - - [TearDown] - public void Verify() => _repository.VerifyAll(); - - [Test] - public void Convert_BaseType() - { - try - { - Type baseType = new FakeType("baseType"); - Type hostType = new FakeType("hostType"); - - object target = new(); - Type targetType = new FakeType("targetType"); - - object wrappedTarget = new(); - Base converted = new(); - - _rootConvertManager.Setup(x => x.GetTargetType(target)).Returns(targetType); - _rootElementProvider.Setup(x => x.GetRootType()).Returns(baseType); - _proxyMapper.Setup(x => x.GetHostTypeFromMappedType(baseType)).Returns(hostType); - - _proxyMapper.Setup(x => x.GetMappedTypeFromHostType(targetType)).Returns((Type?)null); - _proxyMapper.Setup(x => x.GetMappedTypeFromProxyType(targetType)).Returns((Type?)null); - - _rootConvertManager.Setup(x => x.IsSubClass(baseType, targetType)).Returns(true); - _proxyMapper.Setup(x => x.CreateProxy(baseType, target)).Returns(wrappedTarget); - _rootConvertManager.Setup(x => x.Convert(baseType, wrappedTarget)).Returns(converted); - - var rootToSpeckleConverter = new RootToSpeckleConverter( - _proxyMapper.Object, - _rootConvertManager.Object, - _rootElementProvider.Object - ); - var testConverted = rootToSpeckleConverter.Convert(target); - - testConverted.Should().BeSameAs(converted); - } - catch (Exception e) - { - Console.WriteLine(e); - throw; - } - } -} diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common.Tests/Speckle.Converters.Common.Tests.csproj b/DUI3-DX/Sdk/Speckle.Converters.Common.Tests/Speckle.Converters.Common.Tests.csproj deleted file mode 100644 index e5baa8e603..0000000000 --- a/DUI3-DX/Sdk/Speckle.Converters.Common.Tests/Speckle.Converters.Common.Tests.csproj +++ /dev/null @@ -1,24 +0,0 @@ - - - - net48 - x64 - false - true - - - - - - - - - - - - - - - - - diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common.Tests/packages.lock.json b/DUI3-DX/Sdk/Speckle.Converters.Common.Tests/packages.lock.json deleted file mode 100644 index 25241e1d85..0000000000 --- a/DUI3-DX/Sdk/Speckle.Converters.Common.Tests/packages.lock.json +++ /dev/null @@ -1,468 +0,0 @@ -{ - "version": 2, - "dependencies": { - ".NETFramework,Version=v4.8": { - "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, )", - "resolved": "17.10.0", - "contentHash": "0/2HeACkaHEYU3wc83YlcD2Fi4LMtECJjqrtvw0lPi9DCEa35zSPt1j4fuvM8NagjDqJuh1Ja35WcRtn1Um6/A==", - "dependencies": { - "Microsoft.CodeCoverage": "17.10.0" - } - }, - "Microsoft.SourceLink.GitHub": { - "type": "Direct", - "requested": "[8.0.0, )", - "resolved": "8.0.0", - "contentHash": "G5q7OqtwIyGTkeIOAc3u2ZuV/kicQaec5EaRnc0pIeSnh9LUjj+PYQrJYBURvDt7twGl2PKA7nSN0kz1Zw5bnQ==", - "dependencies": { - "Microsoft.Build.Tasks.Git": "8.0.0", - "Microsoft.SourceLink.Common": "8.0.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==" - }, - "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.28, )", - "resolved": "0.1.1-preview.0.28", - "contentHash": "7szXg/vRvP3Wdrn2ZGriVOfsw+bddlpVorBkCIhSHHs5qVTTG8IAIrI1l9dO0/aullaTMF+Xgxm9x3w1aXPiuA==" - }, - "Castle.Core": { - "type": "Transitive", - "resolved": "5.1.1", - "contentHash": "rpYtIczkzGpf+EkZgDr9CClTdemhsrwA/W5hMoPjLkRFnXzH44zDLoovXeKtmxb1ykXK9aJVODSpiJml8CTw2g==" - }, - "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": "5.0.0", - "contentHash": "W8DPQjkMScOMTtJbPwmPyj9c3zYSFGawDW3jwlBOOsnY+EzZFLgNQ/UMkK35JmkNOVPdCyPr2Tw7Vv9N+KA3ZQ==", - "dependencies": { - "System.Threading.Tasks.Extensions": "4.5.4" - } - }, - "Microsoft.Build.Tasks.Git": { - "type": "Transitive", - "resolved": "8.0.0", - "contentHash": "bZKfSIKJRXLTuSzLudMFte/8CempWjVamNUR5eHJizsy+iuOuO/k2gnh7W0dHJmYY0tBf+gUErfluCv5mySAOQ==" - }, - "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.SourceLink.Common": { - "type": "Transitive", - "resolved": "8.0.0", - "contentHash": "dk9JPxTCIevS75HyEQ0E4OVAFhB2N+V9ShCXf8Q6FkUQZDkgLI12y679Nym1YqsiSysuQskT7Z+6nUf3yab6Vw==" - }, - "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.Exceptions": { - "type": "Transitive", - "resolved": "8.4.0", - "contentHash": "nc/+hUw3lsdo0zCj0KMIybAu7perMx79vu72w0za9Nsi6mWyNkGXxYxakAjWB7nEmYL6zdmhEQRB4oJ2ALUeug==", - "dependencies": { - "Serilog": "2.8.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.Collections.Immutable": { - "type": "Transitive", - "resolved": "5.0.0", - "contentHash": "FXkLXiK0sVVewcso0imKQoOxjoPAj42R8HtjjbSjVPAzwDfzoyoznWxgA3c38LDbN9SJux1xXoXYAhz98j7r2g==", - "dependencies": { - "System.Memory": "4.5.4" - } - }, - "System.DoubleNumerics": { - "type": "Transitive", - "resolved": "3.1.3", - "contentHash": "KRKEM/L3KBodjA9VOg3EifFVWUY6EOqaMB05UvPEDm7Zeby/kZW+4kdWUEPzW6xtkwf46p661L9NrbeeQhtLzw==", - "dependencies": { - "NETStandard.Library": "1.6.1" - } - }, - "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": "5.0.0", - "contentHash": "ZD9TMpsmYJLrxbbmdvhwt9YEgG5WntEnZ/d1eH8JBX9LBp+Ju8BSBhUGbZMNVHHomWo2KVImJhTDl2hIgw/6MA==" - }, - "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.converters.common": { - "type": "Project", - "dependencies": { - "Speckle.Autofac": "[2.0.999-local, )", - "Speckle.Objects": "[3.0.1-alpha.11, )" - } - }, - "Microsoft.Extensions.Logging.Abstractions": { - "type": "CentralTransitive", - "requested": "[7.0.0, )", - "resolved": "7.0.0", - "contentHash": "kmn78+LPVMOWeITUjIlfxUPDsI0R6G0RkeAMBmQxAJ7vBJn4q2dTva7pWi65ceN5vPGjJ9q/Uae2WKgvfktJAw==", - "dependencies": { - "System.Buffers": "4.5.1", - "System.Memory": "4.5.5" - } - }, - "Speckle.Core": { - "type": "CentralTransitive", - "requested": "[3.0.1-alpha.11, )", - "resolved": "3.0.1-alpha.11", - "contentHash": "Zt2dBJLlfziEACYCHThbhKypSjhoA01rTw9BzNI72c/BDyftXIz70Tetq/8ZMEqQnKqfmRyYADsAdWKxpdV0Hg==", - "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.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": "CentralTransitive", - "requested": "[3.0.1-alpha.11, )", - "resolved": "3.0.1-alpha.11", - "contentHash": "YR7sei3OQBAi8R/kIu8bEmg5ELDIJK6l5fhOgdnqA9ZvD/fvmRb+09z8lIUTDsgdAdvYU/A/x9VxH9OGPbp9Kw==", - "dependencies": { - "Speckle.Core": "3.0.1-alpha.11" - } - } - } - } -} \ No newline at end of file diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common/ContextWrapper.cs b/DUI3-DX/Sdk/Speckle.Converters.Common/ContextWrapper.cs index 97d77a3389..02088f06bb 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 IConversionContext? Context { get; private set; } + public ConversionContext? 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 c4423c1cc2..723877d0b9 100644 --- a/DUI3-DX/Sdk/Speckle.Converters.Common/ConversionContext.cs +++ b/DUI3-DX/Sdk/Speckle.Converters.Common/ConversionContext.cs @@ -1,9 +1,7 @@ -using Speckle.InterfaceGenerator; +namespace Speckle.Converters.Common; -namespace Speckle.Converters.Common; - -[GenerateAutoInterface] -public class ConversionContext : IConversionContext +// POC: record? +public class ConversionContext 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 4575c4da49..918a29d3c1 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 IConversionContext Current => _stack.Peek(); + public ConversionContext Current => _stack.Peek(); public ContextWrapper Push(string speckleUnit) { @@ -39,7 +39,10 @@ public ContextWrapper Push(string speckleUnit) return new ContextWrapper(this); } - public ContextWrapper Push(THostUnit hostUnit) => Push(_unitConverter.ConvertOrThrow(hostUnit)); + public ContextWrapper Push(THostUnit hostUnit) + { + return Push(_unitConverter.ConvertOrThrow(hostUnit)); + } public void Pop() => _stack.Pop(); } diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common/IProxyMapper.cs b/DUI3-DX/Sdk/Speckle.Converters.Common/IProxyMapper.cs deleted file mode 100644 index 8b467d9395..0000000000 --- a/DUI3-DX/Sdk/Speckle.Converters.Common/IProxyMapper.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace Speckle.Converters.Common; - -public interface IProxyMapper -{ - Type? GetMappedTypeFromHostType(Type type); - Type? GetMappedTypeFromProxyType(Type type); - Type? GetHostTypeFromMappedType(Type type); - - object CreateProxy(Type type, object toWrap); - - T CreateProxy(object toWrap); -} - -public record WrappedType(Type Type, object Target); - -// ghetto default interface implementation :( -public static class ProxyMapExtensions -{ - public static WrappedType? WrapIfExists(this IProxyMapper proxyMap, Type target, object toWrap) - { - var mappedType = proxyMap.GetMappedTypeFromHostType(target); - if (mappedType is not null) - { - return new(mappedType, proxyMap.CreateProxy(mappedType, toWrap)); - } - mappedType = proxyMap.GetMappedTypeFromProxyType(target); - if (mappedType is not null) - { - return new(mappedType, toWrap); - } - return null; - } -} diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common/LegacyRootToSpeckleConverter.cs b/DUI3-DX/Sdk/Speckle.Converters.Common/LegacyRootToSpeckleConverter.cs deleted file mode 100644 index 34cd5576a2..0000000000 --- a/DUI3-DX/Sdk/Speckle.Converters.Common/LegacyRootToSpeckleConverter.cs +++ /dev/null @@ -1,37 +0,0 @@ -using Speckle.Autofac.DependencyInjection; -using Speckle.Converters.Common.Objects; -using Speckle.Core.Models; - -namespace Speckle.Converters.Common; - -public class LegacyRootToSpeckleConverter : IRootToSpeckleConverter -{ - private readonly IFactory _toSpeckle; - - public LegacyRootToSpeckleConverter(IFactory toSpeckle) - { - _toSpeckle = toSpeckle; - } - - public Base Convert(object target) - { - Type type = target.GetType(); - try - { - var objectConverter = _toSpeckle.ResolveInstance(type.Name); //poc: would be nice to have supertypes resolve - - if (objectConverter == null) - { - throw new NotSupportedException($"No conversion found for {type.Name}"); - } - var convertedObject = objectConverter.Convert(target); - - return convertedObject; - } - catch (SpeckleConversionException e) - { - Console.WriteLine(e); - throw; // Just rethrowing for now, Logs may be needed here. - } - } -} diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common/RootConvertManager.cs b/DUI3-DX/Sdk/Speckle.Converters.Common/RootConvertManager.cs index 6f29a573ad..4ae930fa1c 100644 --- a/DUI3-DX/Sdk/Speckle.Converters.Common/RootConvertManager.cs +++ b/DUI3-DX/Sdk/Speckle.Converters.Common/RootConvertManager.cs @@ -27,7 +27,7 @@ public Base Convert(Type type, object obj) if (objectConverter == null) { - throw new NotSupportedException($"No conversion found for {type.Name} with actual type of {obj.GetType()}"); + throw new NotSupportedException($"No conversion found for {type.Name}"); } var convertedObject = objectConverter.Convert(obj); diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common/RootToSpeckleConverter.cs b/DUI3-DX/Sdk/Speckle.Converters.Common/RootToSpeckleConverter.cs index 18ccad7495..d1807e231f 100644 --- a/DUI3-DX/Sdk/Speckle.Converters.Common/RootToSpeckleConverter.cs +++ b/DUI3-DX/Sdk/Speckle.Converters.Common/RootToSpeckleConverter.cs @@ -1,3 +1,5 @@ +using Speckle.Autofac.DependencyInjection; +using Speckle.Converters.Common.Objects; using Speckle.Core.Models; using Speckle.InterfaceGenerator; @@ -6,41 +8,32 @@ namespace Speckle.Converters.Common; [GenerateAutoInterface] public class RootToSpeckleConverter : IRootToSpeckleConverter { - private readonly IRootConvertManager _rootConvertManager; - private readonly IProxyMapper _proxyMapper; - private readonly IRootElementProvider _rootElementProvider; + private readonly IFactory _toSpeckle; - private readonly Type _revitElementType; - - public RootToSpeckleConverter( - IProxyMapper proxyMapper, - IRootConvertManager rootConvertManager, - IRootElementProvider rootElementProvider - ) + public RootToSpeckleConverter(IFactory toSpeckle) { - _proxyMapper = proxyMapper; - _rootConvertManager = rootConvertManager; - _rootElementProvider = rootElementProvider; - _revitElementType = _proxyMapper.GetHostTypeFromMappedType(_rootElementProvider.GetRootType()).NotNull(); + _toSpeckle = toSpeckle; } public Base Convert(object target) { - Type revitType = _rootConvertManager.GetTargetType(target); - var wrapper = _proxyMapper.WrapIfExists(revitType, target); - if (wrapper == null) + Type type = target.GetType(); + try { - //try to fallback to element type - if (_rootConvertManager.IsSubClass(_revitElementType, revitType)) + var objectConverter = _toSpeckle.ResolveInstance(type.Name); //poc: would be nice to have supertypes resolve + + if (objectConverter == null) { - return _rootConvertManager.Convert( - _rootElementProvider.GetRootType(), - _proxyMapper.CreateProxy(_rootElementProvider.GetRootType(), target) - ); + throw new NotSupportedException($"No conversion found for {type.Name}"); } - throw new NotSupportedException($"No wrapper found for Revit type: {revitType.Name}"); + var convertedObject = objectConverter.Convert(target); + + return convertedObject; + } + catch (SpeckleConversionException e) + { + Console.WriteLine(e); + throw; // Just rethrowing for now, Logs may be needed here. } - var (wrappedType, wrappedObject) = wrapper; - return _rootConvertManager.Convert(wrappedType, wrappedObject); } }