From 2349a5464dca95d4055d9e033a727636a4728713 Mon Sep 17 00:00:00 2001 From: Connor Ivy Date: Fri, 28 Jun 2024 09:03:03 -0500 Subject: [PATCH 1/6] Auto stash before checking out "origin/dui3/alpha" --- .../Speckle.Connectors.Rhino7/packages.lock.json | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 53de68cb60..969febf948 100644 --- a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/packages.lock.json +++ b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/packages.lock.json @@ -2,6 +2,15 @@ "version": 2, "dependencies": { ".NETFramework,Version=v4.8": { + "Microsoft.NETFramework.ReferenceAssemblies": { + "type": "Direct", + "requested": "[1.0.3, )", + "resolved": "1.0.3", + "contentHash": "vUc9Npcs14QsyOD01tnv/m8sQUnGTGOw1BCmKcv77LBJY7OxhJ+zJF7UD/sCL3lYNFuqmQEVlkfS4Quif6FyYg==", + "dependencies": { + "Microsoft.NETFramework.ReferenceAssemblies.net48": "1.0.3" + } + }, "Microsoft.SourceLink.GitHub": { "type": "Direct", "requested": "[8.0.0, )", @@ -166,6 +175,11 @@ "System.Runtime.CompilerServices.Unsafe": "6.0.0" } }, + "Microsoft.NETFramework.ReferenceAssemblies.net48": { + "type": "Transitive", + "resolved": "1.0.3", + "contentHash": "zMk4D+9zyiEWByyQ7oPImPN/Jhpj166Ky0Nlla4eXlNL8hI/BtSJsgR8Inldd4NNpIAH3oh8yym0W2DrhXdSLQ==" + }, "Microsoft.SourceLink.Common": { "type": "Transitive", "resolved": "8.0.0", From 7a6182e01b67f49ebbd8d3629c7f68b0d6c9538a Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Fri, 28 Jun 2024 17:31:52 +0100 Subject: [PATCH 2/6] Fix Rhino lock --- .../Speckle.Connectors.Rhino7/packages.lock.json | 14 -------------- 1 file changed, 14 deletions(-) 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 969febf948..53de68cb60 100644 --- a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/packages.lock.json +++ b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/packages.lock.json @@ -2,15 +2,6 @@ "version": 2, "dependencies": { ".NETFramework,Version=v4.8": { - "Microsoft.NETFramework.ReferenceAssemblies": { - "type": "Direct", - "requested": "[1.0.3, )", - "resolved": "1.0.3", - "contentHash": "vUc9Npcs14QsyOD01tnv/m8sQUnGTGOw1BCmKcv77LBJY7OxhJ+zJF7UD/sCL3lYNFuqmQEVlkfS4Quif6FyYg==", - "dependencies": { - "Microsoft.NETFramework.ReferenceAssemblies.net48": "1.0.3" - } - }, "Microsoft.SourceLink.GitHub": { "type": "Direct", "requested": "[8.0.0, )", @@ -175,11 +166,6 @@ "System.Runtime.CompilerServices.Unsafe": "6.0.0" } }, - "Microsoft.NETFramework.ReferenceAssemblies.net48": { - "type": "Transitive", - "resolved": "1.0.3", - "contentHash": "zMk4D+9zyiEWByyQ7oPImPN/Jhpj166Ky0Nlla4eXlNL8hI/BtSJsgR8Inldd4NNpIAH3oh8yym0W2DrhXdSLQ==" - }, "Microsoft.SourceLink.Common": { "type": "Transitive", "resolved": "8.0.0", From 3b2611ac5fad24763161252df1e718f7b1412a89 Mon Sep 17 00:00:00 2001 From: Connor Ivy Date: Mon, 1 Jul 2024 15:44:48 -0500 Subject: [PATCH 3/6] address pr comments --- .../Operations/Receive/RevitHostObjectBuilder.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Operations/Receive/RevitHostObjectBuilder.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Operations/Receive/RevitHostObjectBuilder.cs index 245284543d..222de1a776 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Operations/Receive/RevitHostObjectBuilder.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Operations/Receive/RevitHostObjectBuilder.cs @@ -41,15 +41,17 @@ public HostObjectBuilderResult Build( CancellationToken cancellationToken ) { - var objectsToConvert = _traverseFunction - .TraverseWithProgress(rootObject, onOperationProgressed, cancellationToken) - .Where(obj => obj.Current is not Collection); + try + { + var objectsToConvert = _traverseFunction + .TraverseWithProgress(rootObject, onOperationProgressed, cancellationToken) + .Where(obj => obj.Current is not Collection); using TransactionGroup transactionGroup = new(_contextStack.Current.Document, $"Received data from {projectName}"); transactionGroup.Start(); _transactionManager.StartTransaction(); - var conversionResults = BakeObjects(objectsToConvert); + var conversionResults = BakeObjects(objectsToConvert); _transactionManager.CommitTransaction(); transactionGroup.Assimilate(); From 7aea31d431284b88376b36bba7709bf67601b039 Mon Sep 17 00:00:00 2001 From: Connor Ivy Date: Mon, 1 Jul 2024 16:53:17 -0500 Subject: [PATCH 4/6] add level receive (and top level send) --- .../RevitConverterModule.cs | 2 + .../RevitRootToHostConverter.cs | 28 +++++++ .../Speckle.Converters.RevitShared.projitems | 4 +- .../TopLevel/LevelToHostTopLevelConverter.cs | 77 +++++++++++++++++++ .../LevelTopLevelConverterToSpeckle.cs} | 7 +- 5 files changed, 114 insertions(+), 4 deletions(-) create mode 100644 DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitRootToHostConverter.cs create mode 100644 DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToHost/TopLevel/LevelToHostTopLevelConverter.cs rename DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/{Raw/LevelConversionToSpeckle.cs => TopLevel/LevelTopLevelConverterToSpeckle.cs} (68%) 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 f5211019ae..4f35c4ceeb 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.Revit2023.DependencyInjection/RevitConverterModule.cs @@ -1,5 +1,6 @@ using Autodesk.Revit.DB; using Speckle.Autofac.DependencyInjection; +using Speckle.Converters.Common; using Speckle.Converters.Common.DependencyInjection; using Speckle.Converters.RevitShared; using Speckle.Converters.RevitShared.Helpers; @@ -13,6 +14,7 @@ public class RevitConverterModule : ISpeckleModule public void Load(SpeckleContainerBuilder builder) { builder.AddConverterCommon(); + builder.AddScoped(); builder.AddSingleton(new RevitContext()); // POC: do we need ToSpeckleScalingService as is, do we need to interface it out? diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitRootToHostConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitRootToHostConverter.cs new file mode 100644 index 0000000000..f6284b930f --- /dev/null +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/RevitRootToHostConverter.cs @@ -0,0 +1,28 @@ +using Speckle.Converters.Common; +using Speckle.Converters.Common.Objects; +using Speckle.Core.Models; + +namespace Speckle.Converters.RevitShared; + +public class RevitRootToHostConverter : IRootToHostConverter +{ + private readonly IConverterResolver _converterResolver; + + public RevitRootToHostConverter(IConverterResolver converterResolver) + { + _converterResolver = converterResolver; + } + + public object Convert(Base target) + { + var objectConverter = _converterResolver.GetConversionForType(target.GetType()); + + if (objectConverter == null) + { + throw new SpeckleConversionException($"No conversion found for {target.GetType().Name}"); + } + + return objectConverter.Convert(target) + ?? throw new SpeckleConversionException($"Conversion of object with type {target.GetType()} returned null"); + } +} diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Speckle.Converters.RevitShared.projitems b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Speckle.Converters.RevitShared.projitems index dce4c4898e..338c467deb 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Speckle.Converters.RevitShared.projitems +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Speckle.Converters.RevitShared.projitems @@ -23,6 +23,7 @@ + @@ -36,6 +37,7 @@ + @@ -59,7 +61,7 @@ - + diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToHost/TopLevel/LevelToHostTopLevelConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToHost/TopLevel/LevelToHostTopLevelConverter.cs new file mode 100644 index 0000000000..69f72e4f18 --- /dev/null +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToHost/TopLevel/LevelToHostTopLevelConverter.cs @@ -0,0 +1,77 @@ +using Speckle.Converters.Common; +using Speckle.Converters.RevitShared.Helpers; +using Speckle.Converters.RevitShared.ToSpeckle; +using Speckle.Converters.RevitShared.Services; + +namespace Speckle.Converters.RevitShared.ToHost.ToLevel; + +[NameAndRankValue(nameof(SOBE.Level), 0)] +public class LevelToHostTopLevelConverter : BaseTopLevelConverterToHost +{ + private readonly IRevitConversionContextStack _contextStack; + private readonly ScalingServiceToHost _scalingService; + + public LevelToHostTopLevelConverter(IRevitConversionContextStack contextStack, ScalingServiceToHost scalingService) + { + _contextStack = contextStack; + _scalingService = scalingService; + } + + public override DB.Level Convert(SOBE.Level target) + { + using var documentLevelCollector = new DB.FilteredElementCollector(_contextStack.Current.Document); + var docLevels = documentLevelCollector.OfClass(typeof(DB.Level)).ToElements().Cast(); + + // POC : I'm not really understanding the linked use case for this. Do we want to bring this over? + + //bool elevationMatch = true; + ////level by name component + //if (target is RevitLevel speckleRevitLevel && speckleRevitLevel.referenceOnly) + //{ + // //see: https://speckle.community/t/revit-connector-levels-and-spaces/2824/5 + // elevationMatch = false; + // if (GetExistingLevelByName(docLevels, target.name) is DB.Level existingLevelWithSameName) + // { + // return existingLevelWithSameName; + // } + //} + + DB.Level revitLevel; + var targetElevation = _scalingService.ScaleToNative(target.elevation, target.units); + + if (GetExistingLevelByElevation(docLevels, targetElevation) is DB.Level existingLevel) + { + revitLevel = existingLevel; + } + else + { + revitLevel = DB.Level.Create(_contextStack.Current.Document, targetElevation); + revitLevel.Name = target.name; + + if (target is SOBR.RevitLevel rl && rl.createView) + { + using var viewPlan = CreateViewPlan(target.name, revitLevel.Id); + } + } + + return revitLevel; + } + + private static DB.Level GetExistingLevelByElevation(IEnumerable docLevels, double elevation) + { + return docLevels.FirstOrDefault(l => Math.Abs(l.Elevation - elevation) < RevitConversionContextStack.TOLERANCE); + } + + private DB.ViewPlan CreateViewPlan(string name, DB.ElementId levelId) + { + using var collector = new DB.FilteredElementCollector(_contextStack.Current.Document); + var vt = collector + .OfClass(typeof(DB.ViewFamilyType)) + .First(el => ((DB.ViewFamilyType)el).ViewFamily == DB.ViewFamily.FloorPlan); + + var view = DB.ViewPlan.Create(_contextStack.Current.Document, vt.Id, levelId); + view.Name = name; + + return view; + } +} diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/Raw/LevelConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/TopLevel/LevelTopLevelConverterToSpeckle.cs similarity index 68% rename from DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/Raw/LevelConversionToSpeckle.cs rename to DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/TopLevel/LevelTopLevelConverterToSpeckle.cs index 33e1d7fea2..2916415bb3 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/Raw/LevelConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/TopLevel/LevelTopLevelConverterToSpeckle.cs @@ -1,9 +1,10 @@ -using Speckle.Converters.Common.Objects; +using Speckle.Converters.Common; using Speckle.Converters.RevitShared.Services; namespace Speckle.Converters.RevitShared.ToSpeckle; -public class LevelConversionToSpeckle : ITypedConverter +[NameAndRankValue(nameof(DB.Level), 0)] +public class LevelConversionToSpeckle : BaseTopLevelConverterToSpeckle { private readonly ScalingServiceToSpeckle _scalingService; @@ -12,7 +13,7 @@ public LevelConversionToSpeckle(ScalingServiceToSpeckle scalingService) _scalingService = scalingService; } - public SOBR.RevitLevel Convert(DB.Level target) + public override SOBR.RevitLevel Convert(DB.Level target) { SOBR.RevitLevel level = new() From af7051cc6e492c16a12503ef9ea27e661cdc4776 Mon Sep 17 00:00:00 2001 From: Connor Ivy Date: Tue, 2 Jul 2024 15:53:31 -0500 Subject: [PATCH 5/6] fix merge --- .../Speckle.Converters.RevitShared.projitems | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Speckle.Converters.RevitShared.projitems b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Speckle.Converters.RevitShared.projitems index 338c467deb..245396695d 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Speckle.Converters.RevitShared.projitems +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Speckle.Converters.RevitShared.projitems @@ -37,7 +37,7 @@ - + From 34f75b3d99dcd94e36ccdb72430823bdbf75136a Mon Sep 17 00:00:00 2001 From: Connor Ivy Date: Tue, 2 Jul 2024 16:02:20 -0500 Subject: [PATCH 6/6] fix rebase operation --- .../Operations/Receive/RevitHostObjectBuilder.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Operations/Receive/RevitHostObjectBuilder.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Operations/Receive/RevitHostObjectBuilder.cs index 222de1a776..245284543d 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Operations/Receive/RevitHostObjectBuilder.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Operations/Receive/RevitHostObjectBuilder.cs @@ -41,17 +41,15 @@ public HostObjectBuilderResult Build( CancellationToken cancellationToken ) { - try - { - var objectsToConvert = _traverseFunction - .TraverseWithProgress(rootObject, onOperationProgressed, cancellationToken) - .Where(obj => obj.Current is not Collection); + var objectsToConvert = _traverseFunction + .TraverseWithProgress(rootObject, onOperationProgressed, cancellationToken) + .Where(obj => obj.Current is not Collection); using TransactionGroup transactionGroup = new(_contextStack.Current.Document, $"Received data from {projectName}"); transactionGroup.Start(); _transactionManager.StartTransaction(); - var conversionResults = BakeObjects(objectsToConvert); + var conversionResults = BakeObjects(objectsToConvert); _transactionManager.CommitTransaction(); transactionGroup.Assimilate();