diff --git a/Build/Consts.cs b/Build/Consts.cs index 48a14139b0..2fa9d8deaa 100644 --- a/Build/Consts.cs +++ b/Build/Consts.cs @@ -5,7 +5,11 @@ namespace Build; public static class Consts { public static readonly string[] Solutions = { "DUI3-DX.slnf" }; - public static readonly string[] TestProjects = { "Speckle.Converters.Revit2023.Tests" }; + public static readonly string[] TestProjects = + { + "Speckle.Converters.Revit2023.Tests", + "Speckle.Converters.Common.Tests" + }; public static readonly InstallerProject[] InstallerManifests = { diff --git a/Build/Program.cs b/Build/Program.cs index a6d5ff9bc1..610115c621 100644 --- a/Build/Program.cs +++ b/Build/Program.cs @@ -127,7 +127,7 @@ IEnumerable GetFiles(string d) foreach (var file in GetFiles($"**/{t}.csproj")) { - Run("dotnet", $"test {file} -c Release --no-restore --verbosity=normal"); + Run("dotnet", $"test {file} -c Release --no-build --no-restore --verbosity=normal"); } } ); diff --git a/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/packages.lock.json b/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/packages.lock.json index 3b14166e57..5306011fc3 100644 --- a/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/packages.lock.json +++ b/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/packages.lock.json @@ -302,11 +302,6 @@ "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", @@ -431,8 +426,7 @@ "type": "Project", "dependencies": { "Speckle.Autofac": "[2.0.999-local, )", - "Speckle.Objects": "[2.0.999-local, )", - "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.24, )" + "Speckle.Objects": "[2.0.999-local, )" } }, "speckle.converters.common.dependencyinjection": { 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 b584dc45f9..ecbfc4fb09 100644 --- a/DUI3-DX/Connectors/Autocad/Speckle.Connectors.Autocad2023/packages.lock.json +++ b/DUI3-DX/Connectors/Autocad/Speckle.Connectors.Autocad2023/packages.lock.json @@ -279,11 +279,6 @@ "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", @@ -487,8 +482,7 @@ "type": "Project", "dependencies": { "Speckle.Autofac": "[2.0.999-local, )", - "Speckle.Objects": "[2.0.999-local, )", - "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.24, )" + "Speckle.Objects": "[2.0.999-local, )" } }, "speckle.converters.common.dependencyinjection": { 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 9039fbd17b..27da03b1ba 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.Revit2023/packages.lock.json +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.Revit2023/packages.lock.json @@ -315,18 +315,18 @@ }, "Speckle.Revit2023.Api": { "type": "Transitive", - "resolved": "0.1.1-preview.0.24", - "contentHash": "hPRXbyvgmealdPPWTxjHbpBRTsyt67DddoIs09M0n319eHh/eONnPC+SgBzJmmB834TtzzayMVk06S1cMT0Iow==", + "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.24" + "Speckle.Revit2023.Interfaces": "0.1.1-preview.0.28" } }, "Speckle.Revit2023.Interfaces": { "type": "Transitive", - "resolved": "0.1.1-preview.0.24", - "contentHash": "BSVpOUJc9g6ISrw8GxvtkglTlITpHEDYNOhxv1ZPbckBsI0yO36JiphhQV4q57ERqD9PpCozUJkVhlCaxWeS6A==" + "resolved": "0.1.1-preview.0.28", + "contentHash": "7szXg/vRvP3Wdrn2ZGriVOfsw+bddlpVorBkCIhSHHs5qVTTG8IAIrI1l9dO0/aullaTMF+Xgxm9x3w1aXPiuA==" }, "SQLitePCLRaw.bundle_e_sqlite3": { "type": "Transitive", @@ -514,8 +514,7 @@ "type": "Project", "dependencies": { "Speckle.Autofac": "[2.0.999-local, )", - "Speckle.Objects": "[2.0.999-local, )", - "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.24, )" + "Speckle.Objects": "[2.0.999-local, )" } }, "speckle.converters.common.dependencyinjection": { @@ -529,7 +528,7 @@ "type": "Project", "dependencies": { "Speckle.Converters.Common": "[2.0.999-local, )", - "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.24, )" + "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.28, )" } }, "speckle.converters.revit2023.dependencyinjection": { @@ -538,7 +537,7 @@ "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.24, )" + "Speckle.Revit2023.Api": "[0.1.1-preview.0.28, )" } }, "Speckle.Core": { diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMapper.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMapper.cs new file mode 100644 index 0000000000..e4e997c4e2 --- /dev/null +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMapper.cs @@ -0,0 +1,17 @@ +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/Rhino/Speckle.Connectors.Rhino7/Bindings/RhinoSelectionBinding.cs b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Bindings/RhinoSelectionBinding.cs index ded20ed05f..dcb7c57fcf 100644 --- a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Bindings/RhinoSelectionBinding.cs +++ b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Bindings/RhinoSelectionBinding.cs @@ -8,7 +8,7 @@ namespace Speckle.Connectors.Rhino7.Bindings; public class RhinoSelectionBinding : ISelectionBinding { - private readonly RhinoIdleManager _idleManager; + private readonly IRhinoIdleManager _idleManager; private readonly ITopLevelExceptionHandler _topLevelExceptionHandler; private const string SELECTION_EVENT = "setSelection"; @@ -16,7 +16,7 @@ public class RhinoSelectionBinding : ISelectionBinding public IBridge Parent { get; } public RhinoSelectionBinding( - RhinoIdleManager idleManager, + IRhinoIdleManager idleManager, IBridge parent, ITopLevelExceptionHandler topLevelExceptionHandler ) diff --git a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Bindings/RhinoSendBinding.cs b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Bindings/RhinoSendBinding.cs index 96ed6aa8a0..f0fd3a63d3 100644 --- a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Bindings/RhinoSendBinding.cs +++ b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Bindings/RhinoSendBinding.cs @@ -23,10 +23,9 @@ public sealed class RhinoSendBinding : ISendBinding public IBridge Parent { get; } private readonly DocumentModelStore _store; - private readonly RhinoIdleManager _idleManager; + private readonly IRhinoIdleManager _idleManager; private readonly IUnitOfWorkFactory _unitOfWorkFactory; private readonly List _sendFilters; - private readonly SendOperation _sendOperation; private readonly CancellationManager _cancellationManager; private readonly RhinoSettings _rhinoSettings; @@ -40,10 +39,9 @@ public sealed class RhinoSendBinding : ISendBinding public RhinoSendBinding( DocumentModelStore store, - RhinoIdleManager idleManager, + IRhinoIdleManager idleManager, IBridge parent, IEnumerable sendFilters, - SendOperation sendOperation, IUnitOfWorkFactory unitOfWorkFactory, RhinoSettings rhinoSettings, CancellationManager cancellationManager, @@ -54,7 +52,6 @@ ITopLevelExceptionHandler topLevelExceptionHandler _store = store; _idleManager = idleManager; _unitOfWorkFactory = unitOfWorkFactory; - _sendOperation = sendOperation; _sendFilters = sendFilters.ToList(); _rhinoSettings = rhinoSettings; _cancellationManager = cancellationManager; diff --git a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/DependencyInjection/ProxyMapper.cs b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/DependencyInjection/ProxyMapper.cs new file mode 100644 index 0000000000..dabeb71d95 --- /dev/null +++ b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/DependencyInjection/ProxyMapper.cs @@ -0,0 +1,17 @@ +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 a227755c66..16cdc3a7de 100644 --- a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/DependencyInjection/RhinoConnectorModule.cs +++ b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/DependencyInjection/RhinoConnectorModule.cs @@ -10,7 +10,6 @@ using Speckle.Connectors.Rhino7.Bindings; using Speckle.Connectors.Rhino7.Filters; using Speckle.Connectors.Rhino7.HostApp; -using Speckle.Connectors.Rhino7.Interfaces; using Speckle.Connectors.Rhino7.Operations.Send; using Speckle.Connectors.Rhino7.Plugin; using Speckle.Connectors.Utils.Cancellation; @@ -21,7 +20,9 @@ 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; @@ -37,6 +38,7 @@ public void Load(SpeckleContainerBuilder builder) builder.AddConnectorUtils(); builder.AddDUI(); builder.AddDUIView(); + builder.ScanAssemblyOfType(); // POC: Overwriting the SyncToMainThread to SyncToCurrentThread for Rhino! builder.AddSingletonInstance(); @@ -44,7 +46,8 @@ public void Load(SpeckleContainerBuilder builder) // Register other connector specific types builder.AddSingleton(); builder.AddSingleton(); - builder.AddSingleton(); + builder.AddSingleton(); + builder.AddSingleton(); // Register bindings builder.AddSingleton(); diff --git a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/DependencyInjection/RhinoPlugin.cs b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/DependencyInjection/RhinoPlugin.cs index a295f9f8b6..2262f93f9f 100644 --- a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/DependencyInjection/RhinoPlugin.cs +++ b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/DependencyInjection/RhinoPlugin.cs @@ -1,21 +1,17 @@ using Rhino; -using Speckle.Connectors.DUI.WebView; using Speckle.Connectors.Rhino7.HostApp; -using Speckle.Connectors.Rhino7.Interfaces; using Speckle.Connectors.Rhino7.Plugin; +using Speckle.InterfaceGenerator; namespace Speckle.Connectors.Rhino7.DependencyInjection; +[GenerateAutoInterface] public class RhinoPlugin : IRhinoPlugin { - private readonly RhinoIdleManager _idleManager; - private readonly DUI3ControlWebView _panel; - private readonly RhinoSettings _settings; + private readonly IRhinoIdleManager _idleManager; - public RhinoPlugin(DUI3ControlWebView panel, RhinoSettings settings, RhinoIdleManager idleManager) + public RhinoPlugin(IRhinoIdleManager idleManager) { - _panel = panel; - _settings = settings; _idleManager = idleManager; } diff --git a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/HostApp/RhinoContext.cs b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/HostApp/RhinoContext.cs deleted file mode 100644 index 17b532035a..0000000000 --- a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/HostApp/RhinoContext.cs +++ /dev/null @@ -1,8 +0,0 @@ -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/HostApp/RhinoIdleManager.cs b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/HostApp/RhinoIdleManager.cs index 374d979750..5a88ed6c20 100644 --- a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/HostApp/RhinoIdleManager.cs +++ b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/HostApp/RhinoIdleManager.cs @@ -1,12 +1,14 @@ using System.Collections.Concurrent; using Rhino; +using Speckle.InterfaceGenerator; namespace Speckle.Connectors.Rhino7.HostApp; /// /// Rhino Idle Manager is a helper util to manage deferred actions. /// -public class RhinoIdleManager +[GenerateAutoInterface] +public class RhinoIdleManager : IRhinoIdleManager { // NOTE: ConcurrentDictionary possibly removing the collection has been modified errors in here private readonly ConcurrentDictionary _sCalls = new(); diff --git a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Interfaces/IRhinoPlugin.cs b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Interfaces/IRhinoPlugin.cs deleted file mode 100644 index 487c2968f5..0000000000 --- a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Interfaces/IRhinoPlugin.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Speckle.Connectors.Rhino7.Interfaces; - -public interface IRhinoPlugin -{ - void Initialise(); - void Shutdown(); -} 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 1182e5de7a..621bfa45ed 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 Rhino.DocObjects.Tables; +using Speckle.Rhino7.Interfaces; 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 ViewTable _viewTable; + private readonly IRhinoViewTable _viewTable; private readonly bool _returnToStatus; - public DisableRedrawScope(ViewTable viewTable, bool returnToStatus = true) + public DisableRedrawScope(IRhinoViewTable 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 02f653f08a..6c73b9bd10 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,31 +1,32 @@ 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 + IConversionContextStack contextStack, + GraphTraversal traverseFunction, + IRhinoDocFactory rhinoDocFactory ) { _converter = converter; _contextStack = contextStack; _traverseFunction = traverseFunction; + _rhinoDocFactory = rhinoDocFactory; } public HostObjectBuilderResult Build( @@ -53,15 +54,19 @@ CancellationToken cancellationToken // POC: Potentially refactor out into an IObjectBaker. private HostObjectBuilderResult BakeObjects(IEnumerable objectsGraph, string baseLayerName) { - RhinoDoc doc = _contextStack.Current.Document; - var rootLayerIndex = _contextStack.Current.Document.Layers.Find(Guid.Empty, baseLayerName, RhinoMath.UnsetIntIndex); + var doc = _contextStack.Current.Document; + var rootLayerIndex = _contextStack.Current.Document.Layers.Find( + Guid.Empty, + baseLayerName, + _rhinoDocFactory.UnsetIntIndex + ); // POC: We could move this out into a separate service for testing and re-use. // Cleans up any previously received objects - if (rootLayerIndex != RhinoMath.UnsetIntIndex) + if (rootLayerIndex != _rhinoDocFactory.UnsetIntIndex) { - Layer documentLayer = doc.Layers[rootLayerIndex]; - Layer[]? childLayers = documentLayer.GetChildren(); + var documentLayer = doc.Layers[rootLayerIndex]; + var childLayers = documentLayer.GetChildren(); if (childLayers != null) { using var layerNoDraw = new DisableRedrawScope(doc.Views); @@ -77,7 +82,7 @@ private HostObjectBuilderResult BakeObjects(IEnumerable object } var cache = new Dictionary(); - rootLayerIndex = doc.Layers.Add(new Layer { Name = baseLayerName }); + rootLayerIndex = doc.Layers.Add(_rhinoDocFactory.CreateLayer(baseLayerName)); cache.Add(baseLayerName, rootLayerIndex); using var noDraw = new DisableRedrawScope(doc.Views); @@ -91,7 +96,7 @@ private HostObjectBuilderResult BakeObjects(IEnumerable object { var path = GetLayerPath(tc); - var fullLayerName = string.Join(Layer.PathSeparator, path); + var fullLayerName = string.Join(_rhinoDocFactory.LayerPathSeparator, path); var layerIndex = cache.TryGetValue(fullLayerName, out int value) ? value : GetAndCreateLayerFromPath(path, baseLayerName, cache); @@ -120,31 +125,31 @@ private IReadOnlyList HandleConversionResult(object conversionResult, Ba List newObjectIds = new(); switch (conversionResult) { - case IEnumerable list: + case IEnumerable list: { - Group group = BakeObjectsAsGroup(originalObject.id, list, layerIndex); + var group = BakeObjectsAsGroup(originalObject.id, list, layerIndex); newObjectIds.Add(group.Id.ToString()); break; } - case GeometryBase newObject: + case IRhinoGeometryBase newObject: { - var newObjectGuid = doc.Objects.Add(newObject, new ObjectAttributes { LayerIndex = layerIndex }); + var newObjectGuid = doc.Objects.Add(newObject, _rhinoDocFactory.CreateAttributes(layerIndex)); newObjectIds.Add(newObjectGuid.ToString()); break; } default: throw new SpeckleConversionException( - $"Unexpected result from conversion: Expected {nameof(GeometryBase)} but instead got {conversionResult.GetType().Name}" + $"Unexpected result from conversion: Expected {nameof(IRhinoGeometryBase)} but instead got {conversionResult.GetType().Name}" ); } return newObjectIds; } - private Group BakeObjectsAsGroup(string groupName, IEnumerable list, int layerIndex) + private IRhinoGroup BakeObjectsAsGroup(string groupName, IEnumerable list, int layerIndex) { var doc = _contextStack.Current.Document; - var objectIds = list.Select(obj => doc.Objects.Add(obj, new ObjectAttributes { LayerIndex = layerIndex })); + var objectIds = list.Select(obj => doc.Objects.Add(obj, _rhinoDocFactory.CreateAttributes(layerIndex))); var groupIndex = _contextStack.Current.Document.Groups.Add(groupName, objectIds); var group = _contextStack.Current.Document.Groups.FindIndex(groupIndex); return group; @@ -154,12 +159,12 @@ private Group BakeObjectsAsGroup(string groupName, IEnumerable lis private int GetAndCreateLayerFromPath(string[] path, string baseLayerName, Dictionary cache) { var currentLayerName = baseLayerName; - RhinoDoc currentDocument = _contextStack.Current.Document; + var currentDocument = _contextStack.Current.Document; var previousLayer = currentDocument.Layers.FindName(currentLayerName); foreach (var layerName in path) { - currentLayerName = baseLayerName + Layer.PathSeparator + layerName; + currentLayerName = baseLayerName + _rhinoDocFactory.LayerPathSeparator + layerName; currentLayerName = currentLayerName.Replace("{", "").Replace("}", ""); // Rhino specific cleanup for gh (see RemoveInvalidRhinoChars) if (cache.TryGetValue(currentLayerName, out int value)) { @@ -168,7 +173,7 @@ private int GetAndCreateLayerFromPath(string[] path, string baseLayerName, Dicti } var cleanNewLayerName = layerName.Replace("{", "").Replace("}", ""); - var newLayer = new Layer { Name = cleanNewLayerName, ParentLayerId = previousLayer.Id }; + var newLayer = _rhinoDocFactory.CreateLayer(cleanNewLayerName, 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/Plugin/Speckle.Connectors.Rhino7Plugin.cs b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Plugin/Speckle.Connectors.Rhino7Plugin.cs index 8dff82b2d5..16e7297e5a 100644 --- a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Plugin/Speckle.Connectors.Rhino7Plugin.cs +++ b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Plugin/Speckle.Connectors.Rhino7Plugin.cs @@ -2,8 +2,8 @@ using Rhino.PlugIns; using Speckle.Autofac; using Speckle.Autofac.DependencyInjection; +using Speckle.Connectors.Rhino7.DependencyInjection; using Speckle.Connectors.Rhino7.HostApp; -using Speckle.Connectors.Rhino7.Interfaces; using Speckle.Core.Kits; using Speckle.Core.Logging; using Speckle.Core.Models.Extensions; 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 cf48f27e61..b64bd8b20b 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,6 +15,8 @@ + + @@ -41,5 +43,4 @@ 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 df37836fb8..2b6b868bae 100644 --- a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/packages.lock.json +++ b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/packages.lock.json @@ -29,6 +29,24 @@ "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, )", @@ -70,6 +88,21 @@ "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", @@ -288,11 +321,6 @@ "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", @@ -385,6 +413,11 @@ "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", @@ -481,8 +514,7 @@ "type": "Project", "dependencies": { "Speckle.Autofac": "[2.0.999-local, )", - "Speckle.Objects": "[2.0.999-local, )", - "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.24, )" + "Speckle.Objects": "[2.0.999-local, )" } }, "speckle.converters.common.dependencyinjection": { @@ -495,7 +527,7 @@ "speckle.converters.rhino7.dependencyinjection": { "type": "Project", "dependencies": { - "RhinoCommon": "[7.13.21348.13001, )" + "Speckle.Rhino7.Interfaces": "[0.1.1-preview.0.28, )" } }, "Speckle.Core": { diff --git a/DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3.DependencyInjection/packages.lock.json b/DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3.DependencyInjection/packages.lock.json index 308e61b7c6..acad1bb553 100644 --- a/DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3.DependencyInjection/packages.lock.json +++ b/DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3.DependencyInjection/packages.lock.json @@ -270,11 +270,6 @@ "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", @@ -366,8 +361,7 @@ "type": "Project", "dependencies": { "Speckle.Autofac": "[2.0.999-local, )", - "Speckle.Objects": "[2.0.999-local, )", - "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.24, )" + "Speckle.Objects": "[2.0.999-local, )" } }, "speckle.converters.common.dependencyinjection": { diff --git a/DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3/packages.lock.json b/DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3/packages.lock.json index 25847a4ec6..9c5d3fa603 100644 --- a/DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3/packages.lock.json +++ b/DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3/packages.lock.json @@ -265,11 +265,6 @@ "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", @@ -354,8 +349,7 @@ "type": "Project", "dependencies": { "Speckle.Autofac": "[2.0.999-local, )", - "Speckle.Objects": "[2.0.999-local, )", - "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.24, )" + "Speckle.Objects": "[2.0.999-local, )" } }, "Speckle.Core": { diff --git a/DUI3-DX/Converters/Autocad/Speckle.Converters.Autocad2023.DependencyInjection/packages.lock.json b/DUI3-DX/Converters/Autocad/Speckle.Converters.Autocad2023.DependencyInjection/packages.lock.json index a7f09e4723..57f50cdecb 100644 --- a/DUI3-DX/Converters/Autocad/Speckle.Converters.Autocad2023.DependencyInjection/packages.lock.json +++ b/DUI3-DX/Converters/Autocad/Speckle.Converters.Autocad2023.DependencyInjection/packages.lock.json @@ -213,11 +213,6 @@ "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", @@ -374,8 +369,7 @@ "type": "Project", "dependencies": { "Speckle.Autofac": "[2.0.999-local, )", - "Speckle.Objects": "[2.0.999-local, )", - "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.24, )" + "Speckle.Objects": "[2.0.999-local, )" } }, "speckle.converters.common.dependencyinjection": { diff --git a/DUI3-DX/Converters/Autocad/Speckle.Converters.Autocad2023/packages.lock.json b/DUI3-DX/Converters/Autocad/Speckle.Converters.Autocad2023/packages.lock.json index 66bbf8290c..2ea05d5e3f 100644 --- a/DUI3-DX/Converters/Autocad/Speckle.Converters.Autocad2023/packages.lock.json +++ b/DUI3-DX/Converters/Autocad/Speckle.Converters.Autocad2023/packages.lock.json @@ -205,11 +205,6 @@ "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", @@ -359,8 +354,7 @@ "type": "Project", "dependencies": { "Speckle.Autofac": "[2.0.999-local, )", - "Speckle.Objects": "[2.0.999-local, )", - "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.24, )" + "Speckle.Objects": "[2.0.999-local, )" } }, "Speckle.Core": { 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 1c7eae1e2f..7900f25180 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs @@ -14,7 +14,6 @@ public class RevitConverterModule : ISpeckleModule public void Load(SpeckleContainerBuilder builder) { builder.AddConverterCommon(); - builder.ScanAssemblyOfType(); // POC: do we need ToSpeckleScalingService as is, do we need to interface it out? 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 ae4703a46f..b9b0735ffe 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/Speckle.Converters.Revit2023.DependencyInjection.csproj +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/Speckle.Converters.Revit2023.DependencyInjection.csproj @@ -6,7 +6,7 @@ - + diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/packages.lock.json b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/packages.lock.json index 48eed8707b..a1b26cfcdc 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 @@ -16,13 +16,13 @@ }, "Speckle.Revit2023.Api": { "type": "Direct", - "requested": "[0.1.1-preview.0.24, )", - "resolved": "0.1.1-preview.0.24", - "contentHash": "hPRXbyvgmealdPPWTxjHbpBRTsyt67DddoIs09M0n319eHh/eONnPC+SgBzJmmB834TtzzayMVk06S1cMT0Iow==", + "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.24" + "Speckle.Revit2023.Interfaces": "0.1.1-preview.0.28" } }, "GraphQL.Client": { @@ -232,8 +232,8 @@ }, "Speckle.Revit2023.Interfaces": { "type": "Transitive", - "resolved": "0.1.1-preview.0.24", - "contentHash": "BSVpOUJc9g6ISrw8GxvtkglTlITpHEDYNOhxv1ZPbckBsI0yO36JiphhQV4q57ERqD9PpCozUJkVhlCaxWeS6A==" + "resolved": "0.1.1-preview.0.28", + "contentHash": "7szXg/vRvP3Wdrn2ZGriVOfsw+bddlpVorBkCIhSHHs5qVTTG8IAIrI1l9dO0/aullaTMF+Xgxm9x3w1aXPiuA==" }, "SQLitePCLRaw.bundle_e_sqlite3": { "type": "Transitive", @@ -389,8 +389,7 @@ "type": "Project", "dependencies": { "Speckle.Autofac": "[2.0.999-local, )", - "Speckle.Objects": "[2.0.999-local, )", - "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.24, )" + "Speckle.Objects": "[2.0.999-local, )" } }, "speckle.converters.common.dependencyinjection": { @@ -404,7 +403,7 @@ "type": "Project", "dependencies": { "Speckle.Converters.Common": "[2.0.999-local, )", - "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.24, )" + "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.28, )" } }, "Speckle.Core": { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/Speckle.Converters.Revit2023.Tests.csproj b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/Speckle.Converters.Revit2023.Tests.csproj index 296350ca71..4657d9e8ba 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/Speckle.Converters.Revit2023.Tests.csproj +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/Speckle.Converters.Revit2023.Tests.csproj @@ -14,7 +14,7 @@ - + diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/packages.lock.json b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/packages.lock.json index 256510d436..2d40fe5534 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/packages.lock.json +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.Tests/packages.lock.json @@ -65,9 +65,9 @@ }, "Speckle.Revit2023.Interfaces": { "type": "Direct", - "requested": "[0.1.1-preview.0.24, )", - "resolved": "0.1.1-preview.0.24", - "contentHash": "BSVpOUJc9g6ISrw8GxvtkglTlITpHEDYNOhxv1ZPbckBsI0yO36JiphhQV4q57ERqD9PpCozUJkVhlCaxWeS6A==" + "requested": "[0.1.1-preview.0.28, )", + "resolved": "0.1.1-preview.0.28", + "contentHash": "7szXg/vRvP3Wdrn2ZGriVOfsw+bddlpVorBkCIhSHHs5qVTTG8IAIrI1l9dO0/aullaTMF+Xgxm9x3w1aXPiuA==" }, "Castle.Core": { "type": "Transitive", @@ -490,8 +490,7 @@ "type": "Project", "dependencies": { "Speckle.Autofac": "[2.0.999-local, )", - "Speckle.Objects": "[2.0.999-local, )", - "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.24, )" + "Speckle.Objects": "[2.0.999-local, )" } }, "speckle.converters.common.dependencyinjection": { @@ -505,7 +504,7 @@ "type": "Project", "dependencies": { "Speckle.Converters.Common": "[2.0.999-local, )", - "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.24, )" + "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.28, )" } }, "Speckle.Core": { diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/Speckle.Converters.Revit2023.csproj b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/Speckle.Converters.Revit2023.csproj index 01dc874c3f..26aa7a8647 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/Speckle.Converters.Revit2023.csproj +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/Speckle.Converters.Revit2023.csproj @@ -9,7 +9,7 @@ - + diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/packages.lock.json b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/packages.lock.json index b021d0f201..7c350fca98 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/packages.lock.json +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023/packages.lock.json @@ -16,9 +16,9 @@ }, "Speckle.Revit2023.Interfaces": { "type": "Direct", - "requested": "[0.1.1-preview.0.24, )", - "resolved": "0.1.1-preview.0.24", - "contentHash": "BSVpOUJc9g6ISrw8GxvtkglTlITpHEDYNOhxv1ZPbckBsI0yO36JiphhQV4q57ERqD9PpCozUJkVhlCaxWeS6A==" + "requested": "[0.1.1-preview.0.28, )", + "resolved": "0.1.1-preview.0.28", + "contentHash": "7szXg/vRvP3Wdrn2ZGriVOfsw+bddlpVorBkCIhSHHs5qVTTG8IAIrI1l9dO0/aullaTMF+Xgxm9x3w1aXPiuA==" }, "GraphQL.Client": { "type": "Transitive", @@ -354,8 +354,7 @@ "type": "Project", "dependencies": { "Speckle.Autofac": "[2.0.999-local, )", - "Speckle.Objects": "[2.0.999-local, )", - "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.24, )" + "Speckle.Objects": "[2.0.999-local, )" } }, "Speckle.Core": { 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 088b93cc10..6c315439fe 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,8 +9,9 @@ public class RhinoConverterModule : ISpeckleModule { public void Load(SpeckleContainerBuilder builder) { - builder.AddConverterCommon(); + builder.AddConverterCommon(); // single stack per conversion - builder.AddScoped, RhinoConversionContextStack>(); + builder.AddScoped, RhinoConversionContextStack>(); + builder.AddScoped(); } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7.DependencyInjection/RhinoRootElementProvider.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7.DependencyInjection/RhinoRootElementProvider.cs new file mode 100644 index 0000000000..58a13d8107 --- /dev/null +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7.DependencyInjection/RhinoRootElementProvider.cs @@ -0,0 +1,9 @@ +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 d944ee5ed1..052b08bafc 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 590b6f9e6c..0b5cd3165f 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 @@ -8,18 +8,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", @@ -205,11 +205,6 @@ "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", @@ -359,8 +354,7 @@ "type": "Project", "dependencies": { "Speckle.Autofac": "[2.0.999-local, )", - "Speckle.Objects": "[2.0.999-local, )", - "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.24, )" + "Speckle.Objects": "[2.0.999-local, )" } }, "speckle.converters.common.dependencyinjection": { @@ -373,8 +367,8 @@ "speckle.converters.rhino7": { "type": "Project", "dependencies": { - "RhinoCommon": "[7.13.21348.13001, )", - "Speckle.Converters.Common": "[2.0.999-local, )" + "Speckle.Converters.Common": "[2.0.999-local, )", + "Speckle.Rhino7.Interfaces": "[0.1.1-preview.0.28, )" } }, "Speckle.Core": { diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/GlobalUsings.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/GlobalUsings.cs index baa44c188e..c88d8e3105 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/GlobalUsings.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/GlobalUsings.cs @@ -1,3 +1,2 @@ -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 79ac2f77a4..799f32b350 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,8 +10,11 @@ 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(IHostToSpeckleUnitConverter unitConverter) - : base(RhinoDoc.ActiveDoc, RhinoDoc.ActiveDoc.ModelUnitSystem, unitConverter) { } + public RhinoConversionContextStack( + IRhinoDocFactory rhinoDocFactory, + IHostToSpeckleUnitConverter unitConverter + ) + : base(rhinoDocFactory.ActiveDoc(), rhinoDocFactory.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 4f4f9c77e4..f7953bc383 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 Rhino; -using Speckle.Converters.Common; +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[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; + _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; } - public string ConvertOrThrow(UnitSystem hostUnit) + public string ConvertOrThrow(RhinoUnitSystem 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 249814e554..72c57460cd 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,12 +3,11 @@ net48 - - + + - diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/SpeckleToHostGeometryBaseTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/SpeckleToHostGeometryBaseTopLevelConverter.cs index 75ff2162c2..3d5e09c1a0 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/SpeckleToHostGeometryBaseTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/SpeckleToHostGeometryBaseTopLevelConverter.cs @@ -1,25 +1,28 @@ -using Rhino; -using Speckle.Converters.Common; +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 : RG.GeometryBase + where TOut : IRhinoGeometryBase { - 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 + IConversionContextStack contextStack, + ITypedConverter geometryBaseConverter, + IRhinoTransformFactory transformFactory ) { ContextStack = contextStack; _geometryBaseConverter = geometryBaseConverter; + _transformFactory = transformFactory; } public object Convert(Base target) @@ -35,7 +38,7 @@ public object Convert(Base target) if (castedBase["units"] is string units) { var scaleFactor = Units.GetConversionFactor(units, ContextStack.Current.SpeckleUnits); - var scale = RG.Transform.Scale(RG.Point3d.Origin, scaleFactor); + var scale = _transformFactory.Scale(_transformFactory.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 0068c38ef2..63d745dec6 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/ArcToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/ArcToHostConverter.cs @@ -1,34 +1,38 @@ using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; /// /// Converts a SpeckleArcRaw object to a Rhino.Geometry.Arc object or Rhino.Geometry.ArcCurve object. /// -public class ArcToHostConverter : ITypedConverter, ITypedConverter +public class ArcToHostConverter : ITypedConverter, ITypedConverter { - private readonly ITypedConverter _pointConverter; - private readonly ITypedConverter _intervalConverter; + private readonly ITypedConverter _pointConverter; + private readonly ITypedConverter _intervalConverter; + private readonly IRhinoArcFactory _rhinoArcFactory; public ArcToHostConverter( - ITypedConverter pointConverter, - ITypedConverter intervalConverter + ITypedConverter pointConverter, + ITypedConverter intervalConverter, + IRhinoArcFactory rhinoArcFactory ) { _pointConverter = pointConverter; this._intervalConverter = intervalConverter; + _rhinoArcFactory = rhinoArcFactory; } /// - /// Converts a object to a object. + /// Converts a object to a object. /// /// The Speckle Arc object to convert. - /// The converted object. + /// The converted object. /// ⚠️ This conversion does NOT perform scaling. ///
⚠️ This method does not preserve the original curve domain
- public RG.Arc Convert(SOG.Arc target) + public IRhinoArc Convert(SOG.Arc target) { - var rhinoArc = new RG.Arc( + var rhinoArc = _rhinoArcFactory.Create( _pointConverter.Convert(target.startPoint), _pointConverter.Convert(target.midPoint), _pointConverter.Convert(target.endPoint) @@ -39,16 +43,16 @@ public RG.Arc Convert(SOG.Arc target) // POC: CNX-9271 Potential code-smell by directly implementing the interface. We should discuss this further but // since we're using the interfaces instead of the direct type, this may not be an issue. /// - /// Converts a object to a object. + /// Converts a object to a object. /// /// The object to convert. - /// The converted object. + /// The converted object. /// ⚠️ This conversion does NOT perform scaling. - ///
⚠️ Converting to instead of preserves the domain of the curve.
- RG.ArcCurve ITypedConverter.Convert(SOG.Arc target) + ///
⚠️ Converting to instead of preserves the domain of the curve.
+ IRhinoArcCurve ITypedConverter.Convert(SOG.Arc target) { var rhinoArc = Convert(target); - var arcCurve = new RG.ArcCurve(rhinoArc) { Domain = _intervalConverter.Convert(target.domain) }; + var arcCurve = _rhinoArcFactory.Create(rhinoArc, _intervalConverter.Convert(target.domain)); return arcCurve; } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/BrepToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/BrepToHostConverter.cs index db94e2f7f0..c579d736a1 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,24 +1,26 @@ 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 IConversionContextStack _contextStack; + private readonly ITypedConverter _curveConverter; + private readonly ITypedConverter _surfaceConverter; + private readonly ITypedConverter _pointConverter; + private readonly ITypedConverter _intervalConverter; + private readonly IRhinoBrepFactory _rhinoBrepFactory; public BrepToHostConverter( - IConversionContextStack contextStack, - ITypedConverter curveConverter, - ITypedConverter surfaceConverter, - ITypedConverter pointConverter, - ITypedConverter intervalConverter + IConversionContextStack contextStack, + ITypedConverter curveConverter, + ITypedConverter surfaceConverter, + ITypedConverter pointConverter, + ITypedConverter intervalConverter, + IRhinoBrepFactory rhinoBrepFactory ) { _contextStack = contextStack; @@ -26,10 +28,11 @@ public BrepToHostConverter( _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. @@ -40,11 +43,11 @@ public BrepToHostConverter( /// The Speckle Brep object to be converted. /// The equivalent Rhino Brep object. /// ⚠️ This conversion does NOT perform scaling. - public RG.Brep Convert(SOG.Brep target) + public IRhinoBrep Convert(SOG.Brep target) { var tolerance = _contextStack.Current.Document.ModelAbsoluteTolerance; - var rhinoBrep = new RG.Brep(); + var rhinoBrep = _rhinoBrepFactory.Create(); // Geometry goes in first, always. Order doesn't matter. target.Curve3D.ForEach(curve => rhinoBrep.AddEdgeCurve(_curveConverter.Convert(curve))); @@ -70,21 +73,21 @@ public RG.Brep 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(RG.Brep rhinoBrep, SOG.BrepLoop speckleLoop, double tol) + private void ConvertSpeckleBrepLoop(IRhinoBrep rhinoBrep, SOG.BrepLoop speckleLoop, double tol) { var f = rhinoBrep.Faces[speckleLoop.FaceIndex]; - rhinoBrep.Loops.Add((RG.BrepLoopType)speckleLoop.Type, f); + rhinoBrep.Loops.Add((RhinoBrepLoopType)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. @@ -92,7 +95,7 @@ private void ConvertSpeckleBrepLoop(RG.Brep rhinoBrep, SOG.BrepLoop speckleLoop, .ToList() .ForEach(trim => { - RG.BrepTrim rhTrim; + IRhinoBrepTrim rhTrim; if (trim.EdgeIndex != -1) { rhTrim = rhinoBrep.Trims.Add( @@ -107,7 +110,7 @@ private void ConvertSpeckleBrepLoop(RG.Brep rhinoBrep, SOG.BrepLoop speckleLoop, rhTrim = rhinoBrep.Trims.AddSingularTrim( rhinoBrep.Vertices[trim.EndIndex], rhinoBrep.Loops[trim.LoopIndex], - (RG.IsoStatus)trim.IsoStatus, + (RhinoIsoStatus)trim.IsoStatus, trim.CurveIndex ); } @@ -116,8 +119,8 @@ private void ConvertSpeckleBrepLoop(RG.Brep rhinoBrep, SOG.BrepLoop speckleLoop, rhTrim = rhinoBrep.Trims.Add(trim.IsReversed, rhinoBrep.Loops[trim.LoopIndex], trim.CurveIndex); } - rhTrim.IsoStatus = (RG.IsoStatus)trim.IsoStatus; - rhTrim.TrimType = (RG.BrepTrimType)trim.TrimType; + rhTrim.IsoStatus = (RhinoIsoStatus)trim.IsoStatus; + rhTrim.TrimType = (RhinoBrepTrimType)trim.TrimType; rhTrim.SetTolerances(tol, tol); }); } @@ -133,7 +136,7 @@ private void ConvertSpeckleBrepLoop(RG.Brep rhinoBrep, SOG.BrepLoop speckleLoop, /// 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(RG.Brep rhinoBrep, SOG.BrepEdge speckleEdge, double tolerance) + private void ConvertSpeckleBrepEdge(IRhinoBrep rhinoBrep, SOG.BrepEdge speckleEdge, double tolerance) { if ( speckleEdge.Domain == null @@ -158,11 +161,11 @@ private void ConvertSpeckleBrepEdge(RG.Brep rhinoBrep, SOG.BrepEdge speckleEdge, } /// - /// 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(RG.Brep rhinoBrep, SOG.BrepFace speckleFace) + private void ConvertSpeckleBrepFace(IRhinoBrep 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 1431d3fc1a..1fbdfd4a2e 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/CircleToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/CircleToHostConverter.cs @@ -1,46 +1,52 @@ using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; /// -/// This class is responsible for converting a into and objects. +/// This class is responsible for converting a into and objects. /// Implements the interface, -/// providing implementation for to and conversion. +/// providing implementation for to and conversion. /// -public class CircleToHostConverter : ITypedConverter, ITypedConverter +public class CircleToHostConverter + : ITypedConverter, + ITypedConverter { - private readonly ITypedConverter _planeConverter; - private readonly ITypedConverter _intervalConverter; + private readonly ITypedConverter _planeConverter; + private readonly ITypedConverter _intervalConverter; + private readonly IRhinoCircleFactory _rhinoCircleFactory; /// /// Constructs a new instance of the class. /// /// - /// An implementation of used to convert into . + /// An implementation of used to convert into . /// /// - /// An implementation of used to convert into . + /// An implementation of used to convert into . /// public CircleToHostConverter( - ITypedConverter intervalConverter, - ITypedConverter planeConverter + ITypedConverter intervalConverter, + ITypedConverter planeConverter, + IRhinoCircleFactory rhinoCircleFactory ) { _intervalConverter = intervalConverter; _planeConverter = planeConverter; + _rhinoCircleFactory = rhinoCircleFactory; } /// - /// Converts the given object into a object. + /// Converts the given object into a object. /// /// The object to convert. - /// The resulting object. + /// The resulting object. /// /// Thrown when the radius of the given object is null. /// /// ⚠️ This conversion does NOT perform scaling. - ///
⚠️ This conversion does not preserve the curve domain. If you need it preserved you must request a conversion to conversion instead
- public RG.Circle Convert(SOG.Circle target) + ///
⚠️ This conversion does not preserve the curve domain. If you need it preserved you must request a conversion to conversion instead
+ public IRhinoCircle Convert(SOG.Circle target) { if (target.radius == null) { @@ -50,9 +56,9 @@ public RG.Circle Convert(SOG.Circle target) var plane = _planeConverter.Convert(target.plane); var radius = target.radius.Value; - return new RG.Circle(plane, radius); + return _rhinoCircleFactory.Create(plane, radius); } - RG.ArcCurve ITypedConverter.Convert(SOG.Circle target) => - new(Convert(target)) { Domain = _intervalConverter.Convert(target.domain) }; + IRhinoArcCurve ITypedConverter.Convert(SOG.Circle target) => + _rhinoCircleFactory.Create(Convert(target), _intervalConverter.Convert(target.domain)); } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/CurveToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/CurveToHostConverter.cs index a61425dc2a..d96d413258 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,28 +1,29 @@ 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; @@ -36,13 +37,13 @@ public CurveToHostConverter( } /// - /// Converts a given ICurve object to an RG.Curve object. + /// Converts a given ICurve object to an IRhinoCurve object. /// /// The ICurve object to convert. - /// The converted RG.Curve object. + /// The converted IRhinoCurve object. /// Thrown when the conversion is not supported for the given type of curve. /// ⚠️ This conversion does NOT perform scaling. - public RG.Curve Convert(ICurve target) => + public IRhinoCurve 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 74f309a61f..c45fa5c3ab 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/EllipseToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/EllipseToHostConverter.cs @@ -1,49 +1,57 @@ using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; public class EllipseToHostConverter - : ITypedConverter, - ITypedConverter + : ITypedConverter, + ITypedConverter { - private readonly ITypedConverter _planeConverter; - private readonly ITypedConverter _intervalConverter; + private readonly ITypedConverter _planeConverter; + private readonly ITypedConverter _intervalConverter; + private readonly IRhinoEllipseFactory _rhinoEllipseFactory; public EllipseToHostConverter( - ITypedConverter planeConverter, - ITypedConverter intervalConverter + ITypedConverter planeConverter, + ITypedConverter intervalConverter, + IRhinoEllipseFactory rhinoEllipseFactory ) { _planeConverter = planeConverter; _intervalConverter = intervalConverter; + _rhinoEllipseFactory = rhinoEllipseFactory; } /// - /// Converts an instance of to an while preserving geometric properties. + /// Converts an instance of to an while preserving geometric properties. /// /// The instance to be converted. - /// The resulting after conversion. + /// The resulting after conversion. /// Thrown when or properties are null. /// ⚠️ This conversion does NOT perform scaling. - ///
⚠️ This conversion does not preserve the curve domain. If you need it preserved you must request a conversion to conversion instead
- public RG.Ellipse Convert(SOG.Ellipse target) + ///
⚠️ This conversion does not preserve the curve domain. If you need it preserved you must request a conversion to conversion instead
+ public IRhinoEllipse Convert(SOG.Ellipse target) { if (!target.firstRadius.HasValue || !target.secondRadius.HasValue) { throw new InvalidOperationException($"Ellipses cannot have null radii"); } - return new RG.Ellipse(_planeConverter.Convert(target.plane), target.firstRadius.Value, target.secondRadius.Value); + return _rhinoEllipseFactory.Create( + _planeConverter.Convert(target.plane), + target.firstRadius.Value, + target.secondRadius.Value + ); } /// - /// Converts the provided into a representation. + /// Converts the provided into a representation. /// /// The to convert. /// - /// A that represents the provided . + /// A that represents the provided . /// - RG.NurbsCurve ITypedConverter.Convert(SOG.Ellipse target) + IRhinoNurbsCurve ITypedConverter.Convert(SOG.Ellipse target) { var rhinoEllipse = Convert(target); var rhinoNurbsEllipse = rhinoEllipse.ToNurbsCurve(); diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/FlatPointListToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/FlatPointListToHostConverter.cs index f0363a387d..97c2786b44 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/FlatPointListToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/FlatPointListToHostConverter.cs @@ -1,14 +1,21 @@ -using Rhino.Collections; -using Speckle.Converters.Common.Objects; +using Speckle.Converters.Common.Objects; using Speckle.Core.Logging; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; /// /// Converts a flat list of raw double values to a Point3dList. /// -public class FlatPointListToHostConverter : ITypedConverter, Point3dList> +public class FlatPointListToHostConverter : ITypedConverter, IRhinoPoint3dList> { + private readonly IRhinoPointFactory _rhinoPointFactory; + + public FlatPointListToHostConverter(IRhinoPointFactory rhinoPointFactory) + { + _rhinoPointFactory = rhinoPointFactory; + } + /// /// Converts a flat list of raw double values to a Point3dList. /// @@ -19,20 +26,20 @@ public class FlatPointListToHostConverter : ITypedConverter /// Throws when the input list count is not a multiple of 3. - public Point3dList Convert(IReadOnlyList target) + public IRhinoPoint3dList Convert(IReadOnlyList target) { if (target.Count % 3 != 0) { throw new SpeckleException("Array malformed: length%3 != 0."); } - var points = new List(target.Count / 3); + var points = new List(target.Count / 3); for (int i = 2; i < target.Count; i += 3) { - points.Add(new RG.Point3d(target[i - 2], target[i - 1], target[i])); + points.Add(_rhinoPointFactory.Create(target[i - 2], target[i - 1], target[i])); } - return new Point3dList(points); + return _rhinoPointFactory.Create(points); } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/IntervalToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/IntervalToHostConverter.cs index f201283ebd..ddaa476970 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/IntervalToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/IntervalToHostConverter.cs @@ -1,9 +1,17 @@ using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class IntervalToHostConverter : ITypedConverter +public class IntervalToHostConverter : ITypedConverter { + private readonly IRhinoIntervalFactory _rhinoIntervalFactory; + + public IntervalToHostConverter(IRhinoIntervalFactory rhinoIntervalFactory) + { + _rhinoIntervalFactory = rhinoIntervalFactory; + } + /// /// Converts a Speckle Interval object to a Rhino.Geometry.Interval object. /// @@ -11,13 +19,13 @@ public class IntervalToHostConverter : ITypedConverterThe converted Rhino.Geometry.Interval object. /// Thrown when the start or end value of the Interval is null. /// ⚠️ This conversion does NOT perform scaling. - public RG.Interval Convert(SOP.Interval target) + public IRhinoInterval Convert(SOP.Interval target) { if (!target.start.HasValue || !target.end.HasValue) // POC: CNX-9272 Interval start and end being nullable makes no sense. { throw new ArgumentException("Interval start/end cannot be null"); } - return new RG.Interval(target.start.Value, target.end.Value); + return _rhinoIntervalFactory.Create(target.start.Value, target.end.Value); } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/LineToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/LineToHostConverter.cs index c549e96741..a66222299f 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/LineToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/LineToHostConverter.cs @@ -1,14 +1,20 @@ using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class LineToHostConverter : ITypedConverter, ITypedConverter +public class LineToHostConverter : ITypedConverter, ITypedConverter { - private readonly ITypedConverter _pointConverter; + private readonly ITypedConverter _pointConverter; + private readonly IRhinoLineFactory _rhinoLineFactory; - public LineToHostConverter(ITypedConverter pointConverter) + public LineToHostConverter( + ITypedConverter pointConverter, + IRhinoLineFactory rhinoLineFactory + ) { _pointConverter = pointConverter; + _rhinoLineFactory = rhinoLineFactory; } /// @@ -20,15 +26,16 @@ public LineToHostConverter(ITypedConverter pointConverter /// ///
⚠️ This conversion does not preserve the curve domain. /// If you need it preserved you must request a conversion to - /// conversion instead + /// conversion instead ///
- public RG.Line Convert(SOG.Line target) => - new(_pointConverter.Convert(target.start), _pointConverter.Convert(target.end)); + public IRhinoLine Convert(SOG.Line target) => + _rhinoLineFactory.Create(_pointConverter.Convert(target.start), _pointConverter.Convert(target.end)); /// /// Converts a Speckle Line object to a Rhino LineCurve object. /// /// The Speckle Line object to convert. /// Returns the resulting Rhino LineCurve object. - RG.LineCurve ITypedConverter.Convert(SOG.Line target) => new(Convert(target)); + IRhinoLineCurve ITypedConverter.Convert(SOG.Line target) => + _rhinoLineFactory.Create(Convert(target)); } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/MeshToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/MeshToHostConverter.cs index d3917dafd3..e24adb8ad1 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,17 +1,28 @@ 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, Point3dList> _pointListConverter; - - public MeshToHostConverter(ITypedConverter, Point3dList> pointListConverter) + 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 + ) { _pointListConverter = pointListConverter; + _rhinoMeshFactory = rhinoMeshFactory; + _rhinoNgonFactory = rhinoNgonFactory; + _rhinoPointFactory = rhinoPointFactory; } /// @@ -20,11 +31,11 @@ public MeshToHostConverter(ITypedConverter, Point3dList> p /// The Speckle mesh object to convert. /// A Rhino mesh object converted from the Speckle mesh. /// ⚠️ This conversion does NOT perform scaling. - public RG.Mesh Convert(SOG.Mesh target) + public IRhinoMesh Convert(SOG.Mesh target) { target.AlignVerticesWithTexCoordsByIndex(); - RG.Mesh m = new(); + IRhinoMesh m = _rhinoMeshFactory.Create(); var vertices = _pointListConverter.Convert(target.vertices); var colors = target.colors.Select(Color.FromArgb).ToArray(); @@ -43,7 +54,7 @@ public RG.Mesh 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, RG.Mesh m) + private void AssignMeshFaces(SOG.Mesh target, IRhinoMesh m) { int i = 0; while (i < target.faces.Count) @@ -59,14 +70,12 @@ private void AssignMeshFaces(SOG.Mesh target, RG.Mesh m) if (n == 3) { // triangle - m.Faces.AddFace(new RG.MeshFace(target.faces[i + 1], target.faces[i + 2], target.faces[i + 3])); + m.Faces.AddFace(target.faces[i + 1], target.faces[i + 2], target.faces[i + 3]); } else if (n == 4) { // quad - m.Faces.AddFace( - new RG.MeshFace(target.faces[i + 1], target.faces[i + 2], target.faces[i + 3], target.faces[i + 4]) - ); + m.Faces.AddFace(target.faces[i + 1], target.faces[i + 2], target.faces[i + 3], target.faces[i + 4]); } else { @@ -76,11 +85,10 @@ private void AssignMeshFaces(SOG.Mesh target, RG.Mesh m) var faceIndices = new List(triangles.Count); for (int t = 0; t < triangles.Count; t += 3) { - var face = new RG.MeshFace(triangles[t], triangles[t + 1], triangles[t + 2]); - faceIndices.Add(m.Faces.AddFace(face)); + faceIndices.Add(m.Faces.AddFace(triangles[t], triangles[t + 1], triangles[t + 2])); } - RG.MeshNgon ngon = RG.MeshNgon.Create(target.faces.GetRange(i + 1, n), faceIndices); + IRhinoMeshNgon ngon = _rhinoNgonFactory.Create(target.faces.GetRange(i + 1, n), faceIndices); m.Ngons.AddNgon(ngon); } @@ -89,13 +97,13 @@ private void AssignMeshFaces(SOG.Mesh target, RG.Mesh m) m.Faces.CullDegenerateFaces(); } - private void AssignTextureCoordinates(SOG.Mesh target, RG.Mesh m) + private void AssignTextureCoordinates(SOG.Mesh target, IRhinoMesh m) { - var textureCoordinates = new RG.Point2f[target.TextureCoordinatesCount]; + var textureCoordinates = new IRhinoPoint2f[target.TextureCoordinatesCount]; for (int ti = 0; ti < target.TextureCoordinatesCount; ti++) { var (u, v) = target.GetTextureCoordinate(ti); - textureCoordinates[ti] = new RG.Point2f(u, v); + textureCoordinates[ti] = _rhinoPointFactory.Create(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 9f9bf52811..9e2ee516f4 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/NurbsCurveToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/NurbsCurveToHostConverter.cs @@ -1,15 +1,24 @@ using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class NurbsCurveToHostConverter : ITypedConverter +public class NurbsCurveToHostConverter : ITypedConverter { - private readonly ITypedConverter _intervalConverter; + private readonly IRhinoPointFactory _rhinoPointFactory; + private readonly IRhinoCurveFactory _rhinoCurveFactory; + private readonly ITypedConverter _intervalConverter; - public NurbsCurveToHostConverter(ITypedConverter intervalConverter) + public NurbsCurveToHostConverter( + ITypedConverter intervalConverter, + IRhinoCurveFactory rhinoCurveFactory, + IRhinoPointFactory rhinoPointFactory + ) { _intervalConverter = intervalConverter; + _rhinoCurveFactory = rhinoCurveFactory; + _rhinoPointFactory = rhinoPointFactory; } /// @@ -19,14 +28,14 @@ public NurbsCurveToHostConverter(ITypedConverter inte /// The converted Rhino NurbsCurve object. /// Thrown when the conversion fails. /// ⚠️ This conversion does NOT perform scaling. - public RG.NurbsCurve Convert(SOG.Curve target) + public IRhinoNurbsCurve Convert(SOG.Curve target) { - RG.NurbsCurve nurbsCurve = new(target.degree, target.points.Count / 3); + IRhinoNurbsCurve nurbsCurve = _rhinoCurveFactory.Create(target.degree, target.points.Count / 3); // Hyper optimised curve control point conversion for (int i = 2, j = 0; i < target.points.Count; i += 3, j++) { - var pt = new RG.Point3d(target.points[i - 2], target.points[i - 1], target.points[i]); // Skip the point converter for performance + var pt = _rhinoPointFactory.Create(target.points[i - 2], target.points[i - 1], target.points[i]); // Skip the point converter for performance nurbsCurve.Points.SetPoint(j, pt, target.weights[j]); } @@ -37,11 +46,11 @@ public RG.NurbsCurve Convert(SOG.Curve target) { if (extraKnots == 2) { - nurbsCurve.Knots[j] = target.knots[j + 1]; + nurbsCurve.Knots.SetKnot(j, target.knots[j + 1]); } else { - nurbsCurve.Knots[j] = target.knots[j]; + nurbsCurve.Knots.SetKnot(j, target.knots[j]); } } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PlaneToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PlaneToHostConverter.cs index 49e10ab69e..4b18fac738 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PlaneToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PlaneToHostConverter.cs @@ -1,19 +1,23 @@ using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class PlaneToHostConverter : ITypedConverter +public class PlaneToHostConverter : ITypedConverter { - private readonly ITypedConverter _pointConverter; - private readonly ITypedConverter _vectorConverter; + private readonly ITypedConverter _pointConverter; + private readonly ITypedConverter _vectorConverter; + private readonly IRhinoPlaneFactory _rhinoPlaneFactory; public PlaneToHostConverter( - ITypedConverter pointConverter, - ITypedConverter vectorConverter + ITypedConverter pointConverter, + ITypedConverter vectorConverter, + IRhinoPlaneFactory rhinoPlaneFactory ) { _pointConverter = pointConverter; _vectorConverter = vectorConverter; + _rhinoPlaneFactory = rhinoPlaneFactory; } /// @@ -22,8 +26,8 @@ public PlaneToHostConverter( /// The Speckle Plane object to be converted. /// The converted Rhino Plane object. /// ⚠️ This conversion does NOT perform scaling. - public RG.Plane Convert(SOG.Plane target) => - new( + public IRhinoPlane Convert(SOG.Plane target) => + _rhinoPlaneFactory.Create( _pointConverter.Convert(target.origin), _vectorConverter.Convert(target.xdir), _vectorConverter.Convert(target.ydir) diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PointCloudToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PointCloudToHostConverter.cs index a6d749b15c..f4a67b8d8d 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PointCloudToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PointCloudToHostConverter.cs @@ -1,16 +1,21 @@ using System.Drawing; -using Rhino.Collections; using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class PointCloudToHostConverter : ITypedConverter +public class PointCloudToHostConverter : ITypedConverter { - private readonly ITypedConverter, Point3dList> _pointListConverter; + private readonly ITypedConverter, IRhinoPoint3dList> _pointListConverter; + private readonly IRhinoPointCloudFactory _rhinoPointCloudFactory; - public PointCloudToHostConverter(ITypedConverter, Point3dList> pointListConverter) + public PointCloudToHostConverter( + ITypedConverter, IRhinoPoint3dList> pointListConverter, + IRhinoPointCloudFactory rhinoPointCloudFactory + ) { _pointListConverter = pointListConverter; + _rhinoPointCloudFactory = rhinoPointCloudFactory; } /// @@ -19,10 +24,10 @@ public PointCloudToHostConverter(ITypedConverter, Point3dL /// The raw Speckle Pointcloud object to convert. /// The converted Rhino PointCloud object. /// ⚠️ This conversion does NOT perform scaling. - public RG.PointCloud Convert(SOG.Pointcloud target) + public IRhinoPointCloud Convert(SOG.Pointcloud target) { var rhinoPoints = _pointListConverter.Convert(target.points); - var rhinoPointCloud = new RG.PointCloud(rhinoPoints); + var rhinoPointCloud = _rhinoPointCloudFactory.Create(rhinoPoints); if (target.colors.Count == rhinoPoints.Count) { diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PointToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PointToHostConverter.cs index 8ce40bcb59..35938f8ad4 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PointToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PointToHostConverter.cs @@ -1,16 +1,24 @@ using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class PointToHostConverter : ITypedConverter, ITypedConverter +public class PointToHostConverter : ITypedConverter, ITypedConverter { + private readonly IRhinoPointFactory _rhinoPointFactory; + + public PointToHostConverter(IRhinoPointFactory rhinoPointFactory) + { + _rhinoPointFactory = rhinoPointFactory; + } + /// /// Converts a Speckle Point object to a Rhino Point3d object. /// /// The Speckle Point object to convert. /// The converted Rhino Point3d object. /// ⚠️ This conversion does NOT perform scaling. - public RG.Point3d Convert(SOG.Point target) => new(target.x, target.y, target.z); + public IRhinoPoint3d Convert(SOG.Point target) => _rhinoPointFactory.Create(target.x, target.y, target.z); /// /// Converts a Speckle Point object to a Rhino Point object. @@ -18,5 +26,6 @@ public class PointToHostConverter : ITypedConverter, ITyp /// The Speckle Point object to convert. /// The converted Rhino Point object. /// ⚠️ This conversion does NOT perform scaling. - RG.Point ITypedConverter.Convert(SOG.Point target) => new(Convert(target)); + IRhinoPoint ITypedConverter.Convert(SOG.Point target) => + _rhinoPointFactory.Create(Convert(target)); } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PolyCurveToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PolyCurveToHostConverter.cs index 3f35905090..6a2655ed48 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,18 +2,24 @@ 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 ITypedConverter _intervalConverter; + private readonly IRhinoCurveFactory _rhinoCurveFactory; - public PolyCurveToHostConverter(ITypedConverter intervalConverter) + public PolyCurveToHostConverter( + ITypedConverter intervalConverter, + IRhinoCurveFactory rhinoCurveFactory + ) { _intervalConverter = intervalConverter; + _rhinoCurveFactory = rhinoCurveFactory; } /// @@ -22,13 +28,14 @@ public PolyCurveToHostConverter(ITypedConverter inter /// The SpecklePolyCurve object to convert. /// The converted Rhino PolyCurve object. /// ⚠️ This conversion does NOT perform scaling. - public RG.PolyCurve Convert(SOG.Polycurve target) + public IRhinoPolyCurve Convert(SOG.Polycurve target) { - RG.PolyCurve result = new(); + IRhinoPolyCurve result = _rhinoCurveFactory.Create(); + var converter = CurveConverter.NotNull(); foreach (var segment in target.segments) { - var childCurve = CurveConverter.NotNull().Convert(segment); + var childCurve = converter.Convert(segment); bool success = result.AppendSegment(childCurve); if (!success) { diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PolylineToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PolylineToHostConverter.cs index 5abe48fed5..b803a07943 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PolylineToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/PolylineToHostConverter.cs @@ -1,22 +1,25 @@ -using Rhino.Collections; -using Speckle.Converters.Common.Objects; +using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; public class PolylineToHostConverter - : ITypedConverter, - ITypedConverter + : ITypedConverter, + ITypedConverter { - private readonly ITypedConverter, Point3dList> _pointListConverter; - private readonly ITypedConverter _intervalConverter; + private readonly ITypedConverter, IRhinoPoint3dList> _pointListConverter; + private readonly ITypedConverter _intervalConverter; + private readonly IRhinoLineFactory _rhinoLineFactory; public PolylineToHostConverter( - ITypedConverter, Point3dList> pointListConverter, - ITypedConverter intervalConverter + ITypedConverter, IRhinoPoint3dList> pointListConverter, + ITypedConverter intervalConverter, + IRhinoLineFactory rhinoLineFactory ) { _pointListConverter = pointListConverter; _intervalConverter = intervalConverter; + _rhinoLineFactory = rhinoLineFactory; } /// @@ -28,9 +31,9 @@ public PolylineToHostConverter( /// ///
⚠️ This conversion does not preserve the curve domain. /// If you need it preserved you must request a conversion to - /// conversion instead + /// conversion instead ///
- public RG.Polyline Convert(SOG.Polyline target) + public IRhinoPolyline Convert(SOG.Polyline target) { var points = _pointListConverter.Convert(target.value); @@ -39,7 +42,7 @@ public RG.Polyline Convert(SOG.Polyline target) points.Add(points[0]); } - var poly = new RG.Polyline(points); + var poly = _rhinoLineFactory.Create(points); return poly; } @@ -52,7 +55,7 @@ public RG.Polyline Convert(SOG.Polyline target) /// The Speckle polyline object to be converted. /// The converted Rhino Polyline object. /// ⚠️ This conversion does NOT perform scaling. - RG.PolylineCurve ITypedConverter.Convert(SOG.Polyline target) + IRhinoPolylineCurve ITypedConverter.Convert(SOG.Polyline target) { var poly = Convert(target).ToPolylineCurve(); poly.Domain = _intervalConverter.Convert(target.domain); diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/SpiralToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/SpiralToHostConverter.cs index cb7f5a8745..c3cc3532ce 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/SpiralToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/SpiralToHostConverter.cs @@ -1,15 +1,16 @@ using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class SpiralToHostConverter : ITypedConverter +public class SpiralToHostConverter : ITypedConverter { - private readonly ITypedConverter _polylineConverter; - private readonly ITypedConverter _intervalConverter; + private readonly ITypedConverter _polylineConverter; + private readonly ITypedConverter _intervalConverter; public SpiralToHostConverter( - ITypedConverter polylineConverter, - ITypedConverter intervalConverter + ITypedConverter polylineConverter, + ITypedConverter intervalConverter ) { _polylineConverter = polylineConverter; @@ -22,7 +23,7 @@ public SpiralToHostConverter( /// The Speckle Spiral object to be converted. /// A Rhino PolylineCurve object. /// ⚠️ This conversion does NOT perform scaling. - public RG.PolylineCurve Convert(SOG.Spiral target) + public IRhinoPolylineCurve Convert(SOG.Spiral target) { var result = _polylineConverter.Convert(target.displayValue); result.Domain = _intervalConverter.Convert(target.domain); diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/SurfaceToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/SurfaceToHostConverter.cs index 91da44ec59..46689761a8 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/SurfaceToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/SurfaceToHostConverter.cs @@ -1,21 +1,29 @@ using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class SurfaceToHostConverter : ITypedConverter +public class SurfaceToHostConverter : ITypedConverter { + private readonly IRhinoSurfaceFactory _rhinoSurfaceFactory; + + public SurfaceToHostConverter(IRhinoSurfaceFactory rhinoSurfaceFactory) + { + _rhinoSurfaceFactory = rhinoSurfaceFactory; + } + /// /// Converts a raw Speckle surface to a Rhino NURBS surface. /// /// The raw Speckle surface to convert. /// The converted Rhino NURBS surface. /// ⚠️ This conversion does NOT perform scaling. - public RG.NurbsSurface Convert(SOG.Surface target) + public IRhinoNurbsSurface Convert(SOG.Surface target) { // Create rhino surface var points = target.GetControlPoints().ToList(); - var result = RG.NurbsSurface.Create( + var result = _rhinoSurfaceFactory.Create( 3, target.rational, target.degreeU + 1, @@ -28,13 +36,13 @@ public RG.NurbsSurface Convert(SOG.Surface target) var correctUKnots = GetCorrectKnots(target.knotsU, target.countU, target.degreeU); for (int i = 0; i < correctUKnots.Count; i++) { - result.KnotsU[i] = correctUKnots[i]; + result.KnotsU.SetKnot(i, correctUKnots[i]); } var correctVKnots = GetCorrectKnots(target.knotsV, target.countV, target.degreeV); for (int i = 0; i < correctVKnots.Count; i++) { - result.KnotsV[i] = correctVKnots[i]; + result.KnotsV.SetKnot(i, correctVKnots[i]); } // Set control points diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/VectorToHostConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/VectorToHostConverter.cs index 77e017f0fd..85ff17692c 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/VectorToHostConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/Raw/VectorToHostConverter.cs @@ -1,14 +1,22 @@ using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToHost.Raw; -public class VectorToHostConverter : ITypedConverter +public class VectorToHostConverter : ITypedConverter { + private readonly IRhinoVectorFactory _rhinoVectorFactory; + + public VectorToHostConverter(IRhinoVectorFactory rhinoVectorFactory) + { + _rhinoVectorFactory = rhinoVectorFactory; + } + /// /// Converts a Speckle.Vector object to a Rhino Vector3d object. /// /// The Speckle.Vector to be converted. /// The converted Rhino Vector3d object. /// ⚠️ This conversion does NOT perform scaling. - public RG.Vector3d Convert(SOG.Vector target) => new(target.x, target.y, target.z); + public IRhinoVector3d Convert(SOG.Vector target) => _rhinoVectorFactory.Create(target.x, target.y, target.z); } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/ArcToHostTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToHost/TopLevel/ArcToHostTopLevelConverter.cs index 12c4420914..ca8b4938bd 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,15 +1,16 @@ -using Rhino; -using Speckle.Converters.Common; +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 + IConversionContextStack contextStack, + ITypedConverter geometryBaseConverter, + IRhinoTransformFactory rhinoTransformFactory ) - : base(contextStack, geometryBaseConverter) { } + : base(contextStack, geometryBaseConverter, rhinoTransformFactory) { } } 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 6ca70d3ad1..1c8706bd99 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,15 +1,16 @@ -using Rhino; -using Speckle.Converters.Common; +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 + IConversionContextStack contextStack, + ITypedConverter geometryBaseConverter, + IRhinoTransformFactory rhinoTransformFactory ) - : base(contextStack, geometryBaseConverter) { } + : base(contextStack, geometryBaseConverter, rhinoTransformFactory) { } } 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 1493120e57..942854b10b 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,15 +1,16 @@ -using Rhino; -using Speckle.Converters.Common; +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 + IConversionContextStack contextStack, + ITypedConverter geometryBaseConverter, + IRhinoTransformFactory rhinoTransformFactory ) - : base(contextStack, geometryBaseConverter) { } + : base(contextStack, geometryBaseConverter, rhinoTransformFactory) { } } 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 e6a4b03a41..dbc35c205b 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,15 +1,16 @@ -using Rhino; -using Speckle.Converters.Common; +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 + IConversionContextStack contextStack, + ITypedConverter geometryBaseConverter, + IRhinoTransformFactory rhinoTransformFactory ) - : base(contextStack, geometryBaseConverter) { } + : base(contextStack, geometryBaseConverter, rhinoTransformFactory) { } } 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 811433890c..34c5a989ae 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,42 +1,45 @@ -using Rhino; -using Speckle.Converters.Common; +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 ITypedConverter _lineConverter; + private readonly ITypedConverter _polylineConverter; + private readonly ITypedConverter _meshConverter; + private readonly IConversionContextStack _contextStack; + private readonly IRhinoTransformFactory _rhinoTransformFactory; public FallbackToHostTopLevelConverter( - ITypedConverter lineConverter, - ITypedConverter polylineConverter, - ITypedConverter meshConverter, - IConversionContextStack contextStack + ITypedConverter lineConverter, + ITypedConverter polylineConverter, + ITypedConverter meshConverter, + IConversionContextStack contextStack, + IRhinoTransformFactory rhinoTransformFactory ) { _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) { - RG.GeometryBase x = item switch + IRhinoGeometryBase x = item switch { SOG.Line line => _lineConverter.Convert(line), SOG.Polyline polyline => _polylineConverter.Convert(polyline), @@ -50,7 +53,7 @@ IConversionContextStack contextStack return result; } - private RG.Transform GetUnitsTransform(Base speckleObject) + private IRhinoTransform GetUnitsTransform(Base speckleObject) { /* * POC: CNX-9270 Looking at a simpler, more performant way of doing unit scaling on `ToNative` @@ -60,10 +63,10 @@ private RG.Transform GetUnitsTransform(Base speckleObject) if (speckleObject["units"] is string units) { var scaleFactor = Units.GetConversionFactor(units, _contextStack.Current.SpeckleUnits); - var scale = RG.Transform.Scale(RG.Point3d.Origin, scaleFactor); + var scale = _rhinoTransformFactory.Scale(_rhinoTransformFactory.Origin, scaleFactor); return scale; } - return RG.Transform.Identity; + return _rhinoTransformFactory.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 5a64a3ebab..8767a91e06 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,15 +1,16 @@ -using Rhino; -using Speckle.Converters.Common; +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 + IConversionContextStack contextStack, + ITypedConverter geometryBaseConverter, + IRhinoTransformFactory rhinoTransformFactory ) - : base(contextStack, geometryBaseConverter) { } + : base(contextStack, geometryBaseConverter, rhinoTransformFactory) { } } 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 c7d047df3b..6cdacc4288 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,15 +1,16 @@ -using Rhino; -using Speckle.Converters.Common; +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 + IConversionContextStack contextStack, + ITypedConverter geometryBaseConverter, + IRhinoTransformFactory rhinoTransformFactory ) - : base(contextStack, geometryBaseConverter) { } + : base(contextStack, geometryBaseConverter, rhinoTransformFactory) { } } 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 987b46161f..19201d066a 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,15 +1,16 @@ -using Rhino; -using Speckle.Converters.Common; +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 + IConversionContextStack contextStack, + ITypedConverter geometryBaseConverter, + IRhinoTransformFactory rhinoTransformFactory ) - : base(contextStack, geometryBaseConverter) { } + : base(contextStack, geometryBaseConverter, rhinoTransformFactory) { } } 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 51a2613e90..c4e199b3d4 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,16 +1,17 @@ -using Rhino; -using Speckle.Converters.Common; +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 + IConversionContextStack contextStack, + ITypedConverter geometryBaseConverter, + IRhinoTransformFactory rhinoTransformFactory ) - : base(contextStack, geometryBaseConverter) { } + : base(contextStack, geometryBaseConverter, rhinoTransformFactory) { } } 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 de10053ce9..6922cf12ad 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,15 +1,16 @@ -using Rhino; -using Speckle.Converters.Common; +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 + IConversionContextStack contextStack, + ITypedConverter geometryBaseConverter, + IRhinoTransformFactory rhinoTransformFactory ) - : base(contextStack, geometryBaseConverter) { } + : base(contextStack, geometryBaseConverter, rhinoTransformFactory) { } } 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 d6f8d2f14b..96511e2856 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,15 +1,17 @@ -using Rhino; -using Speckle.Converters.Common; +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 + IConversionContextStack contextStack, + ITypedConverter geometryBaseConverter, + IRhinoTransformFactory rhinoTransformFactory ) - : base(contextStack, geometryBaseConverter) { } + : base(contextStack, geometryBaseConverter, rhinoTransformFactory) { } } 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 081f217f04..c098b09930 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,16 +1,17 @@ -using Rhino; -using Speckle.Converters.Common; +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 + IConversionContextStack contextStack, + ITypedConverter geometryBaseConverter, + IRhinoTransformFactory rhinoTransformFactory ) - : base(contextStack, geometryBaseConverter) { } + : base(contextStack, geometryBaseConverter, rhinoTransformFactory) { } } 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 8a3eee9cb7..f262520e97 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 RG.ArcCurve to an ICurve. + /// Converts an IRhinoArcCurve to an ICurve. /// - /// The RG.ArcCurve to convert. + /// The IRhinoArcCurve 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(RG.ArcCurve target) + public ICurve Convert(IRhinoArcCurve target) { var tolerance = _contextStack.Current.Document.ModelAbsoluteTolerance; @@ -57,5 +57,5 @@ public ICurve Convert(RG.ArcCurve 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(RG.ArcCurve target) => (Base)Convert(target); + Base ITypedConverter.Convert(IRhinoArcCurve 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 82c89c2551..0458715c91 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,27 +1,30 @@ -using Rhino; -using Speckle.Converters.Common; +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 ITypedConverter _pointConverter; + private readonly ITypedConverter _planeConverter; + private readonly ITypedConverter _boxConverter; + private readonly IConversionContextStack _contextStack; + private readonly IRhinoBoxFactory _boxFactory; public ArcToSpeckleConverter( - ITypedConverter pointConverter, - ITypedConverter planeConverter, - ITypedConverter boxConverter, - IConversionContextStack contextStack + ITypedConverter pointConverter, + ITypedConverter planeConverter, + ITypedConverter boxConverter, + IConversionContextStack contextStack, + IRhinoBoxFactory boxFactory ) { _pointConverter = pointConverter; _planeConverter = planeConverter; _boxConverter = boxConverter; _contextStack = contextStack; + _boxFactory = boxFactory; } /// @@ -32,7 +35,7 @@ IConversionContextStack contextStack /// /// 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(RG.Arc target) => + public SOG.Arc Convert(IRhinoArc target) => new( _planeConverter.Convert(target.Plane), target.Radius, @@ -47,6 +50,6 @@ public SOG.Arc Convert(RG.Arc target) => endPoint = _pointConverter.Convert(target.EndPoint), domain = new SOP.Interval(0, 1), length = target.Length, - bbox = _boxConverter.Convert(new RG.Box(target.BoundingBox())) + bbox = _boxConverter.Convert(_boxFactory.CreateBox(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 cebd6e5d70..cae6a5d610 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 Rhino; -using Speckle.Converters.Common; +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(RG.Box target) => + public SOG.Box Convert(IRhinoBox 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 236653d4d7..1ae05128f7 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,30 +1,34 @@ 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 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; public BrepToSpeckleConverter( - ITypedConverter pointConverter, - ITypedConverter curveConverter, - ITypedConverter surfaceConverter, - ITypedConverter meshConverter, - ITypedConverter boxConverter, - ITypedConverter intervalConverter, - IConversionContextStack contextStack + ITypedConverter pointConverter, + ITypedConverter curveConverter, + ITypedConverter surfaceConverter, + ITypedConverter meshConverter, + ITypedConverter boxConverter, + ITypedConverter intervalConverter, + IConversionContextStack contextStack, + IRhinoBoxFactory rhinoBoxFactory, + IRhinoMeshFactory rhinoMeshFactory ) { _pointConverter = pointConverter; @@ -34,6 +38,8 @@ IConversionContextStack contextStack _boxConverter = boxConverter; _intervalConverter = intervalConverter; _contextStack = contextStack; + _rhinoBoxFactory = rhinoBoxFactory; + _rhinoMeshFactory = rhinoMeshFactory; } /// @@ -41,7 +47,7 @@ IConversionContextStack contextStack /// /// The Brep object to convert. /// The converted Speckle Brep object. - public SOG.Brep Convert(RG.Brep target) + public SOG.Brep Convert(IRhinoBrep target) { var tol = _contextStack.Current.Document.ModelAbsoluteTolerance; target.Repair(tol); @@ -89,7 +95,7 @@ public SOG.Brep Convert(RG.Brep target) Orientation = (SOG.BrepOrientation)target.SolidOrientation, volume = target.IsSolid ? target.GetVolume() : 0, area = target.GetArea(), - bbox = _boxConverter.Convert(new RG.Box(target.GetBoundingBox(false))), + bbox = _boxConverter.Convert(_rhinoBoxFactory.CreateBox(target.GetBoundingBox(false))), units = _contextStack.Current.SpeckleUnits }; @@ -106,7 +112,7 @@ public SOG.Brep Convert(RG.Brep target) return speckleBrep; } - private static List ConvertBrepFaces(RG.Brep brep, SOG.Brep speckleParent) => + private static List ConvertBrepFaces(IRhinoBrep brep, SOG.Brep speckleParent) => brep.Faces .Select( f => @@ -120,7 +126,7 @@ public SOG.Brep Convert(RG.Brep target) ) .ToList(); - private List ConvertBrepEdges(RG.Brep brep, SOG.Brep speckleParent) => + private List ConvertBrepEdges(IRhinoBrep brep, SOG.Brep speckleParent) => brep.Edges .Select( edge => @@ -128,15 +134,15 @@ public SOG.Brep Convert(RG.Brep target) speckleParent, edge.EdgeCurveIndex, edge.TrimIndices(), - edge.StartVertex?.VertexIndex ?? -1, - edge.EndVertex?.VertexIndex ?? -1, + edge.StartVertex.VertexIndex, + edge.EndVertex.VertexIndex, edge.ProxyCurveIsReversed, _intervalConverter.Convert(edge.Domain) ) ) .ToList(); - private List ConvertBrepTrims(RG.Brep brep, SOG.Brep speckleParent) => + private List ConvertBrepTrims(IRhinoBrep brep, SOG.Brep speckleParent) => brep.Trims .Select(trim => { @@ -160,7 +166,7 @@ public SOG.Brep Convert(RG.Brep target) }) .ToList(); - private List ConvertBrepLoops(RG.Brep brep, SOG.Brep speckleParent) => + private List ConvertBrepLoops(IRhinoBrep brep, SOG.Brep speckleParent) => brep.Loops .Select( loop => @@ -173,14 +179,13 @@ public SOG.Brep Convert(RG.Brep target) ) .ToList(); - private RG.Mesh? GetBrepDisplayMesh(RG.Brep brep) + private IRhinoMesh? GetBrepDisplayMesh(IRhinoBrep brep) { - var joinedMesh = new RG.Mesh(); + var joinedMesh = _rhinoMeshFactory.Create(); // get from settings //Settings.TryGetValue("sendMeshSetting", out string meshSetting); - RG.MeshingParameters mySettings = new(0.05, 0.05); // switch (SelectedMeshSettings) // { // case MeshSettings.CurrentDoc: @@ -194,7 +199,7 @@ public SOG.Brep Convert(RG.Brep target) try { - joinedMesh.Append(RG.Mesh.CreateFromBrep(brep, mySettings)); + joinedMesh.Append(_rhinoMeshFactory.CreateFromBrep(brep, 0.05, 0.05)); 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 0e3f91e3bf..64ef397045 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 Rhino; -using Speckle.Converters.Common; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Core.Models; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.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((RG.Circle)target); + public Base Convert(object target) => Convert((IRhinoCircle)target); /// - /// Converts a RG.Circle object to a SOG.Circle object. + /// Converts a IRhinoCircle object to a SOG.Circle object. /// - /// The RG.Circle object to convert. + /// The IRhinoCircle 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(RG.Circle target) => + public SOG.Circle Convert(IRhinoCircle 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 d3747e2faf..0fa733ca87 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,15 +1,14 @@ -using Rhino; -using Speckle.Converters.Common; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; -using Speckle.Core.Models; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.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; } @@ -19,8 +18,6 @@ public ControlPointToSpeckleConverter(IConversionContextStack /// The ControlPoint object to convert. /// The converted Speckle ControlPoint object. - public SOG.ControlPoint Convert(RG.ControlPoint target) => + public SOG.ControlPoint Convert(IRhinoControlPoint 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 5c792ebaf8..855a2d43d5 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,24 +1,25 @@ 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; @@ -37,15 +38,31 @@ 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(RG.Curve target) => - target switch + 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) { - 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()) - }; + 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); + } - Base ITypedConverter.Convert(RG.Curve target) => (Base)Convert(target); + Base ITypedConverter.Convert(IRhinoCurve 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 fc6b52cc8f..0420067ae7 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,24 +1,27 @@ -using Rhino; -using Speckle.Converters.Common; +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 ITypedConverter _planeConverter; + private readonly ITypedConverter _boxConverter; + private readonly IConversionContextStack _contextStack; + private readonly IRhinoBoxFactory _rhinoBoxFactory; public EllipseToSpeckleConverter( - ITypedConverter planeConverter, - ITypedConverter boxConverter, - IConversionContextStack contextStack + ITypedConverter planeConverter, + ITypedConverter boxConverter, + IConversionContextStack contextStack, + IRhinoBoxFactory rhinoBoxFactory ) { _planeConverter = planeConverter; _boxConverter = boxConverter; _contextStack = contextStack; + _rhinoBoxFactory = rhinoBoxFactory; } /// @@ -29,7 +32,7 @@ IConversionContextStack contextStack /// /// ⚠️ 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(RG.Ellipse target) + public SOG.Ellipse Convert(IRhinoEllipse target) { var nurbsCurve = target.ToNurbsCurve(); return new( @@ -42,7 +45,7 @@ public SOG.Ellipse Convert(RG.Ellipse target) domain = new SOP.Interval(0, 1), length = nurbsCurve.GetLength(), area = Math.PI * target.Radius1 * target.Radius2, - bbox = _boxConverter.Convert(new RG.Box(nurbsCurve.GetBoundingBox(true))) + bbox = _boxConverter.Convert(_rhinoBoxFactory.CreateBox(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 272fecafdb..8044a90e7d 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,13 +1,14 @@ 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(RG.Interval target) => new(target.T0, target.T1); + public SOP.Interval Convert(IRhinoInterval 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 f40620f78d..dc480c79fd 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,24 +1,27 @@ -using Rhino; -using Speckle.Converters.Common; +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 ITypedConverter _pointConverter; + private readonly ITypedConverter _boxConverter; + private readonly IConversionContextStack _contextStack; + private readonly IRhinoBoxFactory _rhinoBoxFactory; public LineToSpeckleConverter( - ITypedConverter pointConverter, - ITypedConverter boxConverter, - IConversionContextStack contextStack + ITypedConverter pointConverter, + ITypedConverter boxConverter, + IConversionContextStack contextStack, + IRhinoBoxFactory rhinoBoxFactory ) { _pointConverter = pointConverter; _boxConverter = boxConverter; _contextStack = contextStack; + _rhinoBoxFactory = rhinoBoxFactory; } /// @@ -29,13 +32,13 @@ IConversionContextStack contextStack /// /// ⚠️ 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(RG.Line target) => + public SOG.Line Convert(IRhinoLine 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(new RG.Box(target.BoundingBox)) + bbox = _boxConverter.Convert(_rhinoBoxFactory.CreateBox(target.BoundingBox)) }; - public SOG.Line Convert(RG.LineCurve target) => Convert(target.Line); + public SOG.Line Convert(IRhinoLineCurve 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 73aa3f4a8a..cf7dfbc288 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 Rhino; -using Speckle.Converters.Common; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.Raw; -[NameAndRankValue(nameof(RG.Mesh), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public class MeshToSpeckleConverter : ITypedConverter +[NameAndRankValue(nameof(IRhinoMesh), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +public class MeshToSpeckleConverter : ITypedConverter { - private readonly ITypedConverter _pointConverter; - private readonly ITypedConverter _boxConverter; - private readonly IConversionContextStack _contextStack; + private readonly ITypedConverter _boxConverter; + private readonly IConversionContextStack _contextStack; + private readonly IRhinoBoxFactory _rhinoBoxFactory; public MeshToSpeckleConverter( - ITypedConverter pointConverter, - ITypedConverter boxConverter, - IConversionContextStack contextStack + ITypedConverter boxConverter, + IConversionContextStack contextStack, + IRhinoBoxFactory rhinoBoxFactory ) { - _pointConverter = pointConverter; _boxConverter = boxConverter; _contextStack = contextStack; + _rhinoBoxFactory = rhinoBoxFactory; } /// @@ -28,7 +28,7 @@ IConversionContextStack contextStack /// The Rhino Mesh to be converted. /// The converted Speckle Mesh. /// Thrown when the Rhino Mesh has 0 vertices or faces. - public SOG.Mesh Convert(RG.Mesh target) + public SOG.Mesh Convert(IRhinoMesh target) { if (target.Vertices.Count == 0 || target.Faces.Count == 0) { @@ -38,7 +38,7 @@ public SOG.Mesh Convert(RG.Mesh target) var vertexCoordinates = target.Vertices.ToPoint3dArray().SelectMany(pt => new[] { pt.X, pt.Y, pt.Z }).ToList(); var faces = new List(); - foreach (RG.MeshNgon polygon in target.GetNgonAndFacesEnumerable()) + foreach (IRhinoMeshNgon polygon in target.GetNgonAndFacesEnumerable()) { var vertIndices = polygon.BoundaryVertexIndexList(); int n = vertIndices.Length; @@ -55,7 +55,7 @@ public SOG.Mesh Convert(RG.Mesh target) var colors = target.VertexColors.Select(cl => cl.ToArgb()).ToList(); var volume = target.IsClosed ? target.Volume() : 0; - var bbox = _boxConverter.Convert(new RG.Box(target.GetBoundingBox(false))); + var bbox = _boxConverter.Convert(_rhinoBoxFactory.CreateBox(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 6cf8dca53d..7c28b72c3d 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,27 +1,30 @@ -using Rhino; -using Speckle.Converters.Common; +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 ITypedConverter _polylineConverter; + private readonly ITypedConverter _intervalConverter; + private readonly ITypedConverter _boxConverter; + private readonly IConversionContextStack _contextStack; + private readonly IRhinoBoxFactory _rhinoBoxFactory; public NurbsCurveConverter( - ITypedConverter polylineConverter, - ITypedConverter intervalConverter, - ITypedConverter boxConverter, - IConversionContextStack contextStack + ITypedConverter polylineConverter, + ITypedConverter intervalConverter, + ITypedConverter boxConverter, + IConversionContextStack contextStack, + IRhinoBoxFactory rhinoBoxFactory ) { _polylineConverter = polylineConverter; _intervalConverter = intervalConverter; _boxConverter = boxConverter; _contextStack = contextStack; + _rhinoBoxFactory = rhinoBoxFactory; } /// @@ -34,13 +37,9 @@ IConversionContextStack contextStack /// 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(RG.NurbsCurve target) + public SOG.Curve Convert(IRhinoNurbsCurve 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); @@ -63,7 +62,7 @@ public SOG.Curve Convert(RG.NurbsCurve target) domain = _intervalConverter.Convert(nurbsCurve.Domain), closed = nurbsCurve.IsClosed, length = nurbsCurve.GetLength(), - bbox = _boxConverter.Convert(new RG.Box(nurbsCurve.GetBoundingBox(true))) + bbox = _boxConverter.Convert(_rhinoBoxFactory.CreateBox(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 0d663ff520..4f4952622a 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,28 +1,30 @@ -using Rhino; -using Rhino.Geometry.Collections; -using Speckle.Converters.Common; +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 ITypedConverter _boxConverter; + private readonly ITypedConverter _intervalConverter; + private readonly ITypedConverter _controlPointConverter; + private readonly IConversionContextStack _contextStack; + private readonly IRhinoBoxFactory _rhinoBoxFactory; public NurbsSurfaceToSpeckleConverter( - ITypedConverter boxConverter, - ITypedConverter intervalConverter, - ITypedConverter controlPointConverter, - IConversionContextStack contextStack + ITypedConverter boxConverter, + ITypedConverter intervalConverter, + ITypedConverter controlPointConverter, + IConversionContextStack contextStack, + IRhinoBoxFactory rhinoBoxFactory ) { _boxConverter = boxConverter; _intervalConverter = intervalConverter; _controlPointConverter = controlPointConverter; _contextStack = contextStack; + _rhinoBoxFactory = rhinoBoxFactory; } /// @@ -30,7 +32,7 @@ IConversionContextStack contextStack /// /// The NurbsSurface object to convert. /// A Surface object representing the converted NurbsSurface. - public SOG.Surface Convert(RG.NurbsSurface target) + public SOG.Surface Convert(IRhinoNurbsSurface target) { var result = new SOG.Surface { @@ -44,7 +46,7 @@ public SOG.Surface Convert(RG.NurbsSurface target) knotsU = target.KnotsU.ToList(), knotsV = target.KnotsV.ToList(), units = _contextStack.Current.SpeckleUnits, - bbox = _boxConverter.Convert(new RG.Box(target.GetBoundingBox(true))) + bbox = _boxConverter.Convert(_rhinoBoxFactory.CreateBox(target.GetBoundingBox(true))) }; result.SetControlPoints(ControlPointsToSpeckle(target.Points)); @@ -52,7 +54,7 @@ public SOG.Surface Convert(RG.NurbsSurface target) return result; } - private List> ControlPointsToSpeckle(NurbsSurfacePointList controlPoints) + private List> ControlPointsToSpeckle(IRhinoNurbsSurfacePointList 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 40d15be50c..b2a3264467 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(RG.Plane target) => + public SOG.Plane Convert(IRhinoPlane 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 2bfdfdae1c..c110af447a 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,14 +1,16 @@ -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; } @@ -18,7 +20,8 @@ public PointToSpeckleConverter(IConversionContextStack con /// /// The Rhino 3D point to convert. /// The converted Speckle point. - public SOG.Point Convert(RG.Point3d target) => new(target.X, target.Y, target.Z, _contextStack.Current.SpeckleUnits); + public SOG.Point Convert(IRhinoPoint3d target) => + new(target.X, target.Y, target.Z, _contextStack.Current.SpeckleUnits); - public SOG.Point Convert(RG.Point target) => Convert(target.Location); + public SOG.Point Convert(IRhinoPoint 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 6937d6b007..10cdf491d5 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,26 +1,30 @@ 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; + 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 PolyCurveToSpeckleConverter( - ITypedConverter intervalConverter, - ITypedConverter boxConverter, - IConversionContextStack contextStack + ITypedConverter intervalConverter, + ITypedConverter boxConverter, + IConversionContextStack contextStack, + IRhinoBoxFactory rhinoBoxFactory ) { _intervalConverter = intervalConverter; _boxConverter = boxConverter; _contextStack = contextStack; + _rhinoBoxFactory = rhinoBoxFactory; } /// @@ -32,14 +36,14 @@ IConversionContextStack contextStack /// 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(RG.PolyCurve target) + public SOG.Polycurve Convert(IRhinoPolyCurve target) { var myPoly = new SOG.Polycurve { closed = target.IsClosed, domain = _intervalConverter.Convert(target.Domain), length = target.GetLength(), - bbox = _boxConverter.Convert(new RG.Box(target.GetBoundingBox(true))), + bbox = _boxConverter.Convert(_rhinoBoxFactory.CreateBox(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 1ee241e7d1..7682ceeb42 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,29 +1,32 @@ -using Rhino; -using Speckle.Converters.Common; +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 ITypedConverter _pointConverter; + private readonly ITypedConverter _boxConverter; + private readonly ITypedConverter _intervalConverter; + private readonly IConversionContextStack _contextStack; + private readonly IRhinoBoxFactory _rhinoBoxFactory; public PolylineToSpeckleConverter( - ITypedConverter pointConverter, - ITypedConverter boxConverter, - IConversionContextStack contextStack, - ITypedConverter intervalConverter + ITypedConverter pointConverter, + ITypedConverter boxConverter, + IConversionContextStack contextStack, + ITypedConverter intervalConverter, + IRhinoBoxFactory rhinoBoxFactory ) { _pointConverter = pointConverter; _boxConverter = boxConverter; _contextStack = contextStack; _intervalConverter = intervalConverter; + _rhinoBoxFactory = rhinoBoxFactory; } /// @@ -32,12 +35,12 @@ public PolylineToSpeckleConverter( /// 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(RG.Polyline target) + public SOG.Polyline Convert(IRhinoPolyline target) { - var box = _boxConverter.Convert(new RG.Box(target.BoundingBox)); + var box = _boxConverter.Convert(_rhinoBoxFactory.CreateBox(target.BoundingBox)); var points = target.Select(pt => _pointConverter.Convert(pt)).ToList(); - if (target.IsClosed) + if (points[0] == points[^1] && target.IsClosed) { points.RemoveAt(points.Count - 1); } @@ -48,8 +51,8 @@ public SOG.Polyline Convert(RG.Polyline target) ) { bbox = box, - length = target.Length, - domain = new(0, target.Length), + length = target.Count, + domain = new(0, target.Count), closed = target.IsClosed }; } @@ -60,7 +63,7 @@ public SOG.Polyline Convert(RG.Polyline target) /// The Rhino PolylineCurve to be converted. /// The converted Speckle polyline. /// ✅ This conversion respects the domain of the original PolylineCurve - public SOG.Polyline Convert(RG.PolylineCurve target) + public SOG.Polyline Convert(IRhinoPolylineCurve 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 5e4a17e6cb..f7d0fdee98 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,21 +1,24 @@ -using Rhino; -using Speckle.Converters.Common; +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 IConversionContextStack _contextStack; + private readonly ITypedConverter _boxConverter; + private readonly IRhinoBoxFactory _rhinoBoxFactory; public RawPointCloudToSpeckle( - IConversionContextStack contextStack, - ITypedConverter boxConverter + IConversionContextStack contextStack, + ITypedConverter boxConverter, + IRhinoBoxFactory rhinoBoxFactory ) { _contextStack = contextStack; _boxConverter = boxConverter; + _rhinoBoxFactory = rhinoBoxFactory; } /// @@ -23,12 +26,12 @@ public RawPointCloudToSpeckle( /// /// The Rhino PointCloud object to convert. /// The converted Speckle Pointcloud object. - public SOG.Pointcloud Convert(RG.PointCloud target) => + public SOG.Pointcloud Convert(IRhinoPointCloud 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(new RG.Box(target.GetBoundingBox(true))), + bbox = _boxConverter.Convert(_rhinoBoxFactory.CreateBox(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 489eddedc4..fe5de7db27 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 Rhino; -using Speckle.Converters.Common; +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 co /// /// The Rhino Vector3d object to convert. /// The converted Speckle Vector object. - public SOG.Vector Convert(RG.Vector3d target) => + public SOG.Vector Convert(IRhinoVector3d 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 7520c1bd83..d55b39090c 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/BrepObjectToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/BrepObjectToSpeckleTopLevelConverter.cs @@ -1,23 +1,23 @@ -using Rhino.DocObjects; -using Speckle.Converters.Common; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Core.Models; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.TopLevel; -[NameAndRankValue(nameof(BrepObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +[NameAndRankValue(nameof(IRhinoBrepObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] public class BrepObjectToSpeckleTopLevelConverter : IToSpeckleTopLevelConverter { - private readonly ITypedConverter _curveConverter; + private readonly ITypedConverter _curveConverter; - public BrepObjectToSpeckleTopLevelConverter(ITypedConverter curveConverter) + public BrepObjectToSpeckleTopLevelConverter(ITypedConverter curveConverter) { _curveConverter = curveConverter; } public Base Convert(object target) { - var curveObject = (BrepObject)target; + var curveObject = (IRhinoBrepObject)target; //can only be this type var speckleCurve = _curveConverter.Convert(curveObject.BrepGeometry); return speckleCurve; } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/CurveObjectToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/CurveObjectToSpeckleTopLevelConverter.cs index a8214a0c97..34fcf6c18e 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/CurveObjectToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/CurveObjectToSpeckleTopLevelConverter.cs @@ -1,15 +1,16 @@ -using Rhino.DocObjects; -using Speckle.Converters.Common; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Core.Models; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.TopLevel; -[NameAndRankValue(nameof(CurveObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public class CurveObjectToSpeckleTopLevelConverter : RhinoObjectToSpeckleTopLevelConverter +[NameAndRankValue(nameof(IRhinoCurveObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +public class CurveObjectToSpeckleTopLevelConverter + : RhinoObjectToSpeckleTopLevelConverter { - public CurveObjectToSpeckleTopLevelConverter(ITypedConverter conversion) + public CurveObjectToSpeckleTopLevelConverter(ITypedConverter conversion) : base(conversion) { } - protected override RG.Curve GetTypedGeometry(CurveObject input) => input.CurveGeometry; + protected override IRhinoCurve GetTypedGeometry(IRhinoCurveObject input) => input.CurveGeometry; } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/ExtrusionObjectToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/ExtrusionObjectToSpeckleTopLevelConverter.cs index 46d2c27586..3c5d93335d 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/ExtrusionObjectToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/ExtrusionObjectToSpeckleTopLevelConverter.cs @@ -1,23 +1,23 @@ -using Rhino.DocObjects; -using Speckle.Converters.Common; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Core.Models; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.TopLevel; -[NameAndRankValue(nameof(ExtrusionObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +[NameAndRankValue(nameof(IRhinoExtrusionObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] public class ExtrusionObjectToSpeckleTopLevelConverter : IToSpeckleTopLevelConverter { - private readonly ITypedConverter _curveConverter; + private readonly ITypedConverter _curveConverter; - public ExtrusionObjectToSpeckleTopLevelConverter(ITypedConverter curveConverter) + public ExtrusionObjectToSpeckleTopLevelConverter(ITypedConverter curveConverter) { _curveConverter = curveConverter; } public Base Convert(object target) { - var curveObject = (ExtrusionObject)target; + var curveObject = (IRhinoExtrusionObject)target; //can only be this type var speckleCurve = _curveConverter.Convert(curveObject.ExtrusionGeometry.ToBrep()); return speckleCurve; } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/MeshObjectToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/MeshObjectToSpeckleTopLevelConverter.cs index f1c9675a04..025e36fd99 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/MeshObjectToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/MeshObjectToSpeckleTopLevelConverter.cs @@ -1,14 +1,15 @@ -using Rhino.DocObjects; -using Speckle.Converters.Common; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.TopLevel; -[NameAndRankValue(nameof(MeshObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] -public class MeshObjectToSpeckleTopLevelConverter : RhinoObjectToSpeckleTopLevelConverter +[NameAndRankValue(nameof(IRhinoMeshObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +public class MeshObjectToSpeckleTopLevelConverter + : RhinoObjectToSpeckleTopLevelConverter { - public MeshObjectToSpeckleTopLevelConverter(ITypedConverter conversion) + public MeshObjectToSpeckleTopLevelConverter(ITypedConverter conversion) : base(conversion) { } - protected override RG.Mesh GetTypedGeometry(MeshObject input) => input.MeshGeometry; + protected override IRhinoMesh GetTypedGeometry(IRhinoMeshObject input) => input.MeshGeometry; } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/PointCloudObjectToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/PointCloudObjectToSpeckleTopLevelConverter.cs index e741e38e49..b25c80d190 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/PointCloudObjectToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/PointCloudObjectToSpeckleTopLevelConverter.cs @@ -1,15 +1,15 @@ -using Rhino.DocObjects; -using Speckle.Converters.Common; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.TopLevel; -[NameAndRankValue(nameof(PointCloudObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +[NameAndRankValue(nameof(IRhinoPointCloudObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] public class PointCloudObjectToSpeckleTopLevelConverter - : RhinoObjectToSpeckleTopLevelConverter + : RhinoObjectToSpeckleTopLevelConverter { - public PointCloudObjectToSpeckleTopLevelConverter(ITypedConverter conversion) + public PointCloudObjectToSpeckleTopLevelConverter(ITypedConverter conversion) : base(conversion) { } - protected override RG.PointCloud GetTypedGeometry(PointCloudObject input) => input.PointCloudGeometry; + protected override IRhinoPointCloud GetTypedGeometry(IRhinoPointCloudObject input) => input.PointCloudGeometry; } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/PointObjectToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/PointObjectToSpeckleTopLevelConverter.cs index 7d9c750b64..d127aa0266 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/PointObjectToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/PointObjectToSpeckleTopLevelConverter.cs @@ -1,15 +1,15 @@ -using Rhino.DocObjects; -using Speckle.Converters.Common; +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; +using Speckle.Rhino7.Interfaces; namespace Speckle.Converters.Rhino7.ToSpeckle.TopLevel; -[NameAndRankValue(nameof(PointObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +[NameAndRankValue(nameof(IRhinoPointObject), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] public class PointObjectToSpeckleTopLevelConverter - : RhinoObjectToSpeckleTopLevelConverter + : RhinoObjectToSpeckleTopLevelConverter { - public PointObjectToSpeckleTopLevelConverter(ITypedConverter conversion) + public PointObjectToSpeckleTopLevelConverter(ITypedConverter conversion) : base(conversion) { } - protected override RG.Point GetTypedGeometry(PointObject input) => input.PointGeometry; + protected override IRhinoPoint GetTypedGeometry(IRhinoPointObject input) => input.PointGeometry; } diff --git a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/RhinoObjectToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/ToSpeckle/TopLevel/RhinoObjectToSpeckleTopLevelConverter.cs index edff24473a..f86d7a09f5 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 : Rhino.DocObjects.RhinoObject - where TInRaw : RG.GeometryBase + where TTopLevelIn : notnull + where TInRaw : notnull where TOutRaw : Base { - public ITypedConverter Conversion { get; } + private readonly ITypedConverter _conversion; 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; + var typedTarget = (TTopLevelIn)target; //can only be this typee 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 2512d2a6e6..9a85ec5d77 100644 --- a/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/packages.lock.json +++ b/DUI3-DX/Converters/Rhino/Speckle.Converters.Rhino7/packages.lock.json @@ -8,18 +8,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", @@ -205,11 +205,6 @@ "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", @@ -359,8 +354,7 @@ "type": "Project", "dependencies": { "Speckle.Autofac": "[2.0.999-local, )", - "Speckle.Objects": "[2.0.999-local, )", - "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.24, )" + "Speckle.Objects": "[2.0.999-local, )" } }, "Speckle.Core": { diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/ContainerRegistration.cs b/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/ContainerRegistration.cs index 189bbcc6e7..07f974d26a 100644 --- a/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/ContainerRegistration.cs +++ b/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/ContainerRegistration.cs @@ -12,6 +12,7 @@ this SpeckleContainerBuilder builder where TRootToSpeckleConverter : class, IRootToSpeckleConverter where THostToSpeckleUnitConverter : class, IHostToSpeckleUnitConverter { + builder.ScanAssemblyOfType(); builder.AddScoped(); builder.AddScoped, THostToSpeckleUnitConverter>(); /* diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/packages.lock.json b/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/packages.lock.json index 326fdefd15..890db720a4 100644 --- a/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/packages.lock.json +++ b/DUI3-DX/Sdk/Speckle.Converters.Common.DependencyInjection/packages.lock.json @@ -302,11 +302,6 @@ "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", @@ -459,8 +454,7 @@ "type": "Project", "dependencies": { "Speckle.Autofac": "[2.0.999-local, )", - "Speckle.Objects": "[2.0.999-local, )", - "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.24, )" + "Speckle.Objects": "[2.0.999-local, )" } }, "Speckle.Core": { diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common.Tests/RootToSpeckleConverterTests.cs b/DUI3-DX/Sdk/Speckle.Converters.Common.Tests/RootToSpeckleConverterTests.cs index a94bf874e4..ae505bb94b 100644 --- a/DUI3-DX/Sdk/Speckle.Converters.Common.Tests/RootToSpeckleConverterTests.cs +++ b/DUI3-DX/Sdk/Speckle.Converters.Common.Tests/RootToSpeckleConverterTests.cs @@ -1,8 +1,7 @@ -using FluentAssertions; +using FluentAssertions; using Moq; using NUnit.Framework; using Speckle.Core.Models; -using Speckle.Revit.Interfaces; namespace Speckle.Converters.Common.Tests; 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 index e687d74095..f1e4c53353 100644 --- 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 @@ -14,7 +14,7 @@ - + diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common.Tests/packages.lock.json b/DUI3-DX/Sdk/Speckle.Converters.Common.Tests/packages.lock.json index c0e6585eb9..202e7670ff 100644 --- a/DUI3-DX/Sdk/Speckle.Converters.Common.Tests/packages.lock.json +++ b/DUI3-DX/Sdk/Speckle.Converters.Common.Tests/packages.lock.json @@ -65,9 +65,9 @@ }, "Speckle.Revit2023.Interfaces": { "type": "Direct", - "requested": "[0.1.1-preview.0.24, )", - "resolved": "0.1.1-preview.0.24", - "contentHash": "BSVpOUJc9g6ISrw8GxvtkglTlITpHEDYNOhxv1ZPbckBsI0yO36JiphhQV4q57ERqD9PpCozUJkVhlCaxWeS6A==" + "requested": "[0.1.1-preview.0.28, )", + "resolved": "0.1.1-preview.0.28", + "contentHash": "7szXg/vRvP3Wdrn2ZGriVOfsw+bddlpVorBkCIhSHHs5qVTTG8IAIrI1l9dO0/aullaTMF+Xgxm9x3w1aXPiuA==" }, "Castle.Core": { "type": "Transitive", @@ -413,8 +413,7 @@ "type": "Project", "dependencies": { "Speckle.Autofac": "[2.0.999-local, )", - "Speckle.Objects": "[2.0.999-local, )", - "Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.24, )" + "Speckle.Objects": "[2.0.999-local, )" } }, "Speckle.Core": { diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common/IProxyMapper.cs b/DUI3-DX/Sdk/Speckle.Converters.Common/IProxyMapper.cs new file mode 100644 index 0000000000..8b467d9395 --- /dev/null +++ b/DUI3-DX/Sdk/Speckle.Converters.Common/IProxyMapper.cs @@ -0,0 +1,33 @@ +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/RootConvertManager.cs b/DUI3-DX/Sdk/Speckle.Converters.Common/RootConvertManager.cs index 4ae930fa1c..6f29a573ad 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}"); + throw new NotSupportedException($"No conversion found for {type.Name} with actual type of {obj.GetType()}"); } 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 fac0af321d..18ccad7495 100644 --- a/DUI3-DX/Sdk/Speckle.Converters.Common/RootToSpeckleConverter.cs +++ b/DUI3-DX/Sdk/Speckle.Converters.Common/RootToSpeckleConverter.cs @@ -1,6 +1,5 @@ using Speckle.Core.Models; using Speckle.InterfaceGenerator; -using Speckle.Revit.Interfaces; namespace Speckle.Converters.Common; diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common/Speckle.Converters.Common.csproj b/DUI3-DX/Sdk/Speckle.Converters.Common/Speckle.Converters.Common.csproj index 07793ee159..9c80cf3aba 100644 --- a/DUI3-DX/Sdk/Speckle.Converters.Common/Speckle.Converters.Common.csproj +++ b/DUI3-DX/Sdk/Speckle.Converters.Common/Speckle.Converters.Common.csproj @@ -8,8 +8,5 @@ - - - diff --git a/DUI3-DX/Sdk/Speckle.Converters.Common/packages.lock.json b/DUI3-DX/Sdk/Speckle.Converters.Common/packages.lock.json index c3d43a1f8a..a9095c6e5b 100644 --- a/DUI3-DX/Sdk/Speckle.Converters.Common/packages.lock.json +++ b/DUI3-DX/Sdk/Speckle.Converters.Common/packages.lock.json @@ -23,12 +23,6 @@ "resolved": "0.9.5", "contentHash": "oU/L7pN1R7q8KkbrpQ3WJnHirPHqn+9DEA7asOcUiggV5dzVg1A/VYs7GOSusD24njxXh03tE3a2oTLOjt3cVg==" }, - "Speckle.Revit2023.Interfaces": { - "type": "Direct", - "requested": "[0.1.1-preview.0.24, )", - "resolved": "0.1.1-preview.0.24", - "contentHash": "BSVpOUJc9g6ISrw8GxvtkglTlITpHEDYNOhxv1ZPbckBsI0yO36JiphhQV4q57ERqD9PpCozUJkVhlCaxWeS6A==" - }, "GraphQL.Client": { "type": "Transitive", "resolved": "6.0.0",