Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revit receive first pass: reference geometry workflow (CNX-403) #254

Merged
merged 37 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
54a3a45
feat(dui3): re-enables receive binding
didimitrie Sep 9, 2024
0af84a8
chore(revit): drastic cleanup
didimitrie Sep 9, 2024
bdbb20e
feat(revit): starts scaffolding revit root to host converter
didimitrie Sep 9, 2024
24f86ce
RenderMaterialToHostConverter added back
kekesidavid Sep 10, 2024
a4abd26
casting to GeometryObject instead of GeometryElement
kekesidavid Sep 10, 2024
8f84a9e
feat(dui3): fallback display values and refactors out material converter
didimitrie Sep 10, 2024
807d9ff
feat(dui3): creates DS and adds point support
didimitrie Sep 10, 2024
05f30e3
feat(dui3): closed nurbs fallback to display values
didimitrie Sep 10, 2024
cfb20de
David/cnx 443 selection (#231)
kekesidavid Sep 10, 2024
7f1e00e
wip
kekesidavid Sep 12, 2024
71f857f
Merge branch 'dev' into grouping-sandbox
didimitrie Sep 12, 2024
9823cec
feat(revit): wraps receive in correct context
didimitrie Sep 12, 2024
92bbddb
wip
didimitrie Sep 12, 2024
5d8d572
feat(dui3): adds prototype grouping by collection
didimitrie Sep 12, 2024
18c8d44
remove invalid characters from group name
kekesidavid Sep 12, 2024
7ce34d6
hide warnings preprocessor
kekesidavid Sep 12, 2024
38ed784
exception handling and error log
kekesidavid Sep 12, 2024
e1b0832
added cancellation and progress reporting
kekesidavid Sep 12, 2024
81f35f6
chore: comments and minor cleanup
didimitrie Sep 12, 2024
0cc0897
Merge pull request #237 from specklesystems/grouping-sandbox
didimitrie Sep 12, 2024
0e87060
David/cnx 409 2 add rendermaterial and color manager to connector (#242)
kekesidavid Sep 16, 2024
e77b2e4
Minor cleanup
oguzhankoral Sep 16, 2024
10d0988
Add object application id into objects of its layer render material p…
oguzhankoral Sep 16, 2024
90834bd
feat(dui3): adds compatibility for objects with display values
didimitrie Sep 16, 2024
1de58a3
Merge pull request #243 from specklesystems/oguzhan/cnx-470-add-suppo…
didimitrie Sep 16, 2024
57407d4
Use LocalToGlobal logic for revit receive
oguzhankoral Sep 16, 2024
e1053df
Use common local to global util for arcgis too
oguzhankoral Sep 16, 2024
206524a
Remove unnecessary registration
oguzhankoral Sep 16, 2024
70e43dd
Remove using
oguzhankoral Sep 16, 2024
4e523ac
Remove unnecessart ToList
oguzhankoral Sep 16, 2024
b8b9355
Register LocalToGlobalConverterUtils for connectors not as common
oguzhankoral Sep 17, 2024
f74f9bc
Merge pull request #244 from specklesystems/oguzhan/cnx-442-handle-in…
didimitrie Sep 17, 2024
5caf403
purge materials and groups in Revit before update (#245)
kekesidavid Sep 18, 2024
5e52cdd
assign categories to DirectShapes after receive, updated revit invali…
kekesidavid Sep 18, 2024
2fa3477
Merge remote-tracking branch 'origin/dev' into revit-receive
oguzhankoral Sep 19, 2024
dc394fa
Post conflict resolving problems
oguzhankoral Sep 19, 2024
7a42a10
minor changes, logging, comments (#257)
kekesidavid Sep 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Post conflict resolving problems
  • Loading branch information
oguzhankoral committed Sep 19, 2024
commit dc394fa0479be6acec1597d930ed6cfa428012c9
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Autofac;
using Microsoft.Extensions.Logging;
using Speckle.Autofac.DependencyInjection;
using Speckle.Connectors.DUI.Bindings;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Autodesk.Revit.DB;
using Speckle.Connectors.Revit.Operations.Receive;
using Speckle.Connectors.Utils.Operations.Receive;
using Speckle.Converters.RevitShared.Helpers;
using Speckle.Converters.Common;
using Speckle.Converters.RevitShared.Settings;
using Speckle.Sdk.Models.GraphTraversal;

namespace Speckle.Connectors.Revit.HostApp;
Expand All @@ -12,18 +12,12 @@ namespace Speckle.Connectors.Revit.HostApp;
/// </summary>
public class RevitGroupBaker : TraversalContextUnpacker
{
private readonly IRevitConversionContextStack _contextStack;
private readonly ITransactionManager _transactionManager;
private readonly IConverterSettingsStore<RevitConversionSettings> _converterSettings;
private readonly RevitUtils _revitUtils;

public RevitGroupBaker(
IRevitConversionContextStack contextStack,
ITransactionManager transactionManager,
RevitUtils revitUtils
)
public RevitGroupBaker(IConverterSettingsStore<RevitConversionSettings> converterSettings, RevitUtils revitUtils)
{
_contextStack = contextStack;
_transactionManager = transactionManager;
_converterSettings = converterSettings;
_revitUtils = revitUtils;
}

Expand Down Expand Up @@ -76,7 +70,7 @@ public void BakeGroups(string baseGroupName)

foreach (var group in orderedGroups)
{
var docGroup = _contextStack.Current.Document.Create.NewGroup(group.Ids);
var docGroup = _converterSettings.Current.Document.Create.NewGroup(group.Ids);
group.Parent?.Ids.Add(docGroup.Id);
docGroup.GroupType.Name = group.Name;
lastGroup = docGroup;
Expand All @@ -88,7 +82,7 @@ public void BakeGroups(string baseGroupName)
public void PurgeGroups(string baseGroupName)
{
var validBaseGroupName = _revitUtils.RemoveInvalidChars(baseGroupName);
var document = _contextStack.Current.Document;
var document = _converterSettings.Current.Document;

using (var collector = new FilteredElementCollector(document))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Autodesk.Revit.DB;
using Microsoft.Extensions.Logging;
using Speckle.Connectors.Utils.Operations.Receive;
using Speckle.Converters.RevitShared.Helpers;
using Speckle.Converters.Common;
using Speckle.Converters.RevitShared.Settings;
using Speckle.Objects.Other;
using Speckle.Sdk;
using Speckle.Sdk.Models.Collections;
Expand All @@ -15,19 +16,19 @@ namespace Speckle.Connectors.Revit.HostApp;
/// </summary>
public class RevitMaterialBaker
{
private readonly IRevitConversionContextStack _contextStack;
private readonly IConverterSettingsStore<RevitConversionSettings> _converterSettings;
private readonly ILogger<RevitMaterialBaker> _logger;
private readonly RevitUtils _revitUtils;

public RevitMaterialBaker(
IRevitConversionContextStack contextStack,
ILogger<RevitMaterialBaker> logger,
RevitUtils revitUtils
RevitUtils revitUtils,
IConverterSettingsStore<RevitConversionSettings> converterSettings
)
{
_contextStack = contextStack;
_logger = logger;
_revitUtils = revitUtils;
_converterSettings = converterSettings;
}

/// <summary>
Expand Down Expand Up @@ -124,8 +125,8 @@ string baseLayerName
string materialId = speckleRenderMaterial.applicationId ?? speckleRenderMaterial.id;
string matName = _revitUtils.RemoveInvalidChars($"{speckleRenderMaterial.name}-({materialId})-{baseLayerName}");

var newMaterialId = Autodesk.Revit.DB.Material.Create(_contextStack.Current.Document, matName);
var revitMaterial = (Autodesk.Revit.DB.Material)_contextStack.Current.Document.GetElement(newMaterialId);
var newMaterialId = Autodesk.Revit.DB.Material.Create(_converterSettings.Current.Document, matName);
var revitMaterial = (Autodesk.Revit.DB.Material)_converterSettings.Current.Document.GetElement(newMaterialId);
revitMaterial.Color = new Color(diffuse.R, diffuse.G, diffuse.B);

revitMaterial.Transparency = (int)(transparency * 100);
Expand All @@ -149,7 +150,7 @@ string baseLayerName
public void PurgeMaterials(string baseGroupName)
{
var validBaseGroupName = _revitUtils.RemoveInvalidChars(baseGroupName);
var document = _contextStack.Current.Document;
var document = _converterSettings.Current.Document;

using (var collector = new FilteredElementCollector(document))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Speckle.Connectors.Utils.Instances;
using Speckle.Connectors.Utils.Operations.Receive;
using Speckle.Converters.Common;
using Speckle.Converters.RevitShared.Helpers;
using Speckle.Converters.RevitShared.Settings;
using Speckle.Sdk;
using Speckle.Sdk.Logging;
Expand All @@ -20,6 +21,7 @@ internal sealed class RevitHostObjectBuilder : IHostObjectBuilder, IDisposable
private readonly IRootToHostConverter _converter;
private readonly IConverterSettingsStore<RevitConversionSettings> _converterSettings;
private readonly GraphTraversal _traverseFunction;
private readonly RevitMaterialCacheSingleton _revitMaterialCacheSingleton;
private readonly ITransactionManager _transactionManager;
private readonly ILocalToGlobalUnpacker _localToGlobalUnpacker;
private readonly LocalToGlobalConverterUtils _localToGlobalConverterUtils;
Expand All @@ -35,27 +37,27 @@ public RevitHostObjectBuilder(
IConverterSettingsStore<RevitConversionSettings> converterSettings,
GraphTraversal traverseFunction,
ITransactionManager transactionManager,
ISyncToThread syncToThread,
ISdkActivityFactory activityFactory,
ILocalToGlobalUnpacker localToGlobalUnpacker,
LocalToGlobalConverterUtils localToGlobalConverterUtils,
RevitGroupBaker groupManager,
RevitMaterialBaker materialBaker,
RootObjectUnpacker rootObjectUnpacker,
ILogger<RevitHostObjectBuilder> logger
ILogger<RevitHostObjectBuilder> logger,
RevitMaterialCacheSingleton revitMaterialCacheSingleton
)
{
_converter = converter;
_converterSettings = converterSettings;
_traverseFunction = traverseFunction;
_transactionManager = transactionManager;
_syncToThread = syncToThread;
_localToGlobalUnpacker = localToGlobalUnpacker;
_localToGlobalConverterUtils = localToGlobalConverterUtils;
_groupBaker = groupManager;
_materialBaker = materialBaker;
_rootObjectUnpacker = rootObjectUnpacker;
_logger = logger;
_revitMaterialCacheSingleton = revitMaterialCacheSingleton;
_activityFactory = activityFactory;
}

Expand All @@ -79,10 +81,10 @@ CancellationToken cancellationToken
var baseGroupName = $"Project {projectName}: Model {modelName}"; // TODO: unify this across connectors!

onOperationProgressed?.Invoke("Converting", null);
using var activity = SpeckleActivityFactory.Start("Build");
using var activity = _activityFactory.Start("Build");

// 0 - Clean then Rock n Roll! 🎸
using TransactionGroup preReceiveCleanTransaction = new(_contextStack.Current.Document, "Pre-receive clean");
using TransactionGroup preReceiveCleanTransaction = new(_converterSettings.Current.Document, "Pre-receive clean");
preReceiveCleanTransaction.Start();
_transactionManager.StartTransaction(true);

Expand All @@ -95,7 +97,7 @@ CancellationToken cancellationToken
_logger.LogError(ex, "Failed to clean up before receive in Revit");
}

using (var _ = SpeckleActivityFactory.Start("Commit"))
using (var _ = _activityFactory.Start("Commit"))
{
_transactionManager.CommitTransaction();
preReceiveCleanTransaction.Assimilate();
Expand All @@ -108,7 +110,8 @@ CancellationToken cancellationToken
unpackedRoot.ObjectsToConvert.ToList()
);

using TransactionGroup transactionGroup = new(_converterSettings.Current.Document, $"Received data from {projectName}");
using TransactionGroup transactionGroup =
new(_converterSettings.Current.Document, $"Received data from {projectName}");
transactionGroup.Start();
_transactionManager.StartTransaction();

Expand All @@ -119,19 +122,19 @@ CancellationToken cancellationToken
var map = _materialBaker.BakeMaterials(unpackedRoot.RenderMaterialProxies, baseGroupName);
foreach (var kvp in map)
{
_contextStack.RenderMaterialProxyCache.ObjectIdAndMaterialIndexMap.Add(kvp.Key, kvp.Value);
_revitMaterialCacheSingleton.ObjectIdAndMaterialIndexMap.Add(kvp.Key, kvp.Value);
}
}

var conversionResults = BakeObjects(localToGlobalMaps, onOperationProgressed, cancellationToken);

using (var _ = SpeckleActivityFactory.Start("Commit"))
using (var _ = _activityFactory.Start("Commit"))
{
_transactionManager.CommitTransaction();
transactionGroup.Assimilate();
}

using TransactionGroup createGroupTransaction = new(_contextStack.Current.Document, "Creating group");
using TransactionGroup createGroupTransaction = new(_converterSettings.Current.Document, "Creating group");
createGroupTransaction.Start();
_transactionManager.StartTransaction(true);

Expand All @@ -144,13 +147,13 @@ CancellationToken cancellationToken
_logger.LogError(ex, "Failed to create group after receiving elements in Revit");
}

using (var _ = SpeckleActivityFactory.Start("Commit"))
using (var _ = _activityFactory.Start("Commit"))
{
_transactionManager.CommitTransaction();
createGroupTransaction.Assimilate();
}

_contextStack.RenderMaterialProxyCache.ObjectIdAndMaterialIndexMap.Clear(); // Massive hack!
_revitMaterialCacheSingleton.ObjectIdAndMaterialIndexMap.Clear(); // Massive hack!

return conversionResults;
}
Expand All @@ -161,7 +164,7 @@ private HostObjectBuilderResult BakeObjects(
CancellationToken cancellationToken
)
{
using var _ = SpeckleActivityFactory.Start("BakeObjects");
using var _ = _activityFactory.Start("BakeObjects");
var conversionResults = new List<ReceiveConversionResult>();
var bakedObjectIds = new List<string>();
int count = 0;
Expand All @@ -171,7 +174,7 @@ CancellationToken cancellationToken
cancellationToken.ThrowIfCancellationRequested();
try
{
using var activity = SpeckleActivityFactory.Start("BakeObject");
using var activity = _activityFactory.Start("BakeObject");
var atomicObject = _localToGlobalConverterUtils.TransformObjects(
localToGlobalMap.AtomicObject,
localToGlobalMap.Matrix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Autodesk.Revit.DB;
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Converters.RevitShared.Helpers;
using Speckle.Converters.RevitShared.Settings;
using Speckle.Objects;
using Speckle.Sdk.Models;
using Speckle.Sdk.Models.Extensions;
Expand All @@ -11,25 +11,25 @@ namespace Speckle.Converters.RevitShared;

public class RevitRootToHostConverter : IRootToHostConverter
{
private readonly IRevitConversionContextStack _revitContextStack;
private readonly IConverterSettingsStore<RevitConversionSettings> _converterSettings;
private readonly IConverterResolver<IToHostTopLevelConverter> _converterResolver;
private readonly ITypedConverter<SOG.Point, DB.XYZ> _pointConverter;
private readonly ITypedConverter<ICurve, DB.CurveArray> _curveConverter;
private readonly ITypedConverter<SOG.Mesh, List<DB.GeometryObject>> _meshConverter;

public RevitRootToHostConverter(
IRevitConversionContextStack revitContextStack,
IConverterResolver<IToHostTopLevelConverter> converterResolver,
ITypedConverter<SOG.Point, DB.XYZ> pointConverter,
ITypedConverter<ICurve, DB.CurveArray> curveConverter,
ITypedConverter<SOG.Mesh, List<DB.GeometryObject>> meshConverter
ITypedConverter<SOG.Mesh, List<DB.GeometryObject>> meshConverter,
IConverterSettingsStore<RevitConversionSettings> converterSettings
)
{
_revitContextStack = revitContextStack;
_converterResolver = converterResolver;
_pointConverter = pointConverter;
_curveConverter = curveConverter;
_meshConverter = meshConverter;
_converterSettings = converterSettings;
}

public object Convert(Base target)
Expand Down Expand Up @@ -66,15 +66,15 @@ public object Convert(Base target)
var res = Enum.TryParse($"OST_{categoryString}", out DB.BuiltInCategory cat);
if (res)
{
var c = Category.GetCategory(_revitContextStack.Current.Document, cat);
if (c is not null && DirectShape.IsValidCategoryId(c.Id, _revitContextStack.Current.Document))
var c = Category.GetCategory(_converterSettings.Current.Document, cat);
if (c is not null && DirectShape.IsValidCategoryId(c.Id, _converterSettings.Current.Document))
{
category = cat;
}
}
}

var ds = DB.DirectShape.CreateElement(_revitContextStack.Current.Document, new DB.ElementId(category));
var ds = DB.DirectShape.CreateElement(_converterSettings.Current.Document, new DB.ElementId(category));
ds.SetShape(geometryObjects);

return ds;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ namespace Speckle.Converters.RevitShared.ToHost.TopLevel;
public class MeshConverterToHost : ITypedConverter<SOG.Mesh, List<DB.GeometryObject>>
{
private readonly ITypedConverter<SOG.Point, DB.XYZ> _pointConverter;
private readonly IRevitConversionContextStack _revitContextStack;
private readonly RevitMaterialCacheSingleton _revitMaterialCacheSingleton;

public MeshConverterToHost(
ITypedConverter<SOG.Point, XYZ> pointConverter,
IRevitConversionContextStack revitContextStack
RevitMaterialCacheSingleton revitMaterialCacheSingleton
)
{
_pointConverter = pointConverter;
_revitContextStack = revitContextStack;
_revitMaterialCacheSingleton = revitMaterialCacheSingleton;
}

public List<DB.GeometryObject> Convert(SOG.Mesh mesh)
Expand All @@ -39,7 +39,7 @@ IRevitConversionContextStack revitContextStack
ElementId materialId = ElementId.InvalidElementId;

if (
_revitContextStack.RenderMaterialProxyCache.ObjectIdAndMaterialIndexMap.TryGetValue(
_revitMaterialCacheSingleton.ObjectIdAndMaterialIndexMap.TryGetValue(
mesh.applicationId ?? mesh.id,
out var mappedElementId
)
Expand Down
Loading