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

DUI3-71 receive bindings and receive geometry #3542

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
befeee5
initial nuget references
adamhathcock Jun 25, 2024
b15bae9
Merge remote-tracking branch 'origin/dui3/alpha' into v3-core-nuget
adamhathcock Jun 25, 2024
166b0f5
fmt
adamhathcock Jun 25, 2024
5624c87
remove unused revit dependency
adamhathcock Jun 25, 2024
e8eae5d
Don't use new solution
adamhathcock Jun 25, 2024
958617e
remove unused file
adamhathcock Jun 25, 2024
702ef3d
Merge remote-tracking branch 'origin/dui3/alpha' into v3-core-nuget
adamhathcock Jun 25, 2024
860ea96
update core
adamhathcock Jun 25, 2024
27794ec
Manage V3 versions centrally (exception AutoCAD)
adamhathcock Jun 26, 2024
8ca5e90
fixed up multiple autocad versions
adamhathcock Jun 26, 2024
37d803e
Removal of Revit interfaces
adamhathcock Jun 27, 2024
cfd8aef
Remove Rhino interfaces
adamhathcock Jun 27, 2024
133e60c
fix up project dependencies
adamhathcock Jun 27, 2024
033dd17
some changes from reviewing
adamhathcock Jun 27, 2024
7bf7a8a
Merge remote-tracking branch 'origin/dui3/alpha' into rollback-interf…
adamhathcock Jun 27, 2024
0b88693
merge fixes and fmt
adamhathcock Jun 27, 2024
a1edddf
more review changes
adamhathcock Jun 27, 2024
5d324c6
more fixes
adamhathcock Jun 27, 2024
a04c913
Merge remote-tracking branch 'origin/dui3/alpha' into rollback-interf…
adamhathcock Jun 27, 2024
d6de1b4
recheck lock files
adamhathcock Jun 27, 2024
fd3e2cf
fix caching
adamhathcock Jun 27, 2024
df9da25
logger IOC fixes
adamhathcock Jun 27, 2024
0557fd5
fix IOC and fmt
adamhathcock Jun 27, 2024
433aacf
try stuff for columns?
adamhathcock Jun 27, 2024
214287b
WIP on DUI3-432-Implement-Receive-logic
Jun 27, 2024
1327b9e
Merge remote-tracking branch 'origin/dui3/alpha' into DUI3-423-Update…
Jun 27, 2024
0b6628e
adds geometry conversions to native
Jun 27, 2024
6692d62
Merge remote-tracking branch 'origin/dui3/alpha' into DUI3-423-Update…
Jun 27, 2024
f9af01a
update projitems
Jun 27, 2024
ade9122
update projitems again
Jun 27, 2024
2f954b5
code cleanup
Jun 27, 2024
60d798a
Merge remote-tracking branch 'origin/dui3/alpha' into DUI3-423-Update…
Jun 27, 2024
b5ffbcf
modelcurve to host
Jun 27, 2024
01f0193
remove comment
Jun 27, 2024
ff39c5d
remove commented code
Jun 27, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using Speckle.Connectors.DUI.Bindings;
using Speckle.Connectors.DUI.Bridge;
using Speckle.Connectors.DUI.Models.Card;
using Speckle.Connectors.DUI.Models;
using Speckle.Connectors.Utils.Builders;
using Speckle.Connectors.Utils.Cancellation;
using Speckle.Connectors.Utils.Operations;
using Speckle.Autofac.DependencyInjection;
using Speckle.Connectors.Utils;

namespace Speckle.Connectors.Revit.Bindings;

internal class RevitReceiveBinding : IReceiveBinding
{
public string Name => "receiveBinding";
public IBridge Parent { get; }

private readonly CancellationManager _cancellationManager;
private readonly DocumentModelStore _store;
private readonly IUnitOfWorkFactory _unitOfWorkFactory;
public ReceiveBindingUICommands Commands { get; }

public RevitReceiveBinding(
DocumentModelStore store,
CancellationManager cancellationManager,
IBridge parent,
IUnitOfWorkFactory unitOfWorkFactory
)
{
Parent = parent;
_store = store;
_unitOfWorkFactory = unitOfWorkFactory;
_cancellationManager = cancellationManager;
Commands = new ReceiveBindingUICommands(parent);
}

public void CancelReceive(string modelCardId) => _cancellationManager.CancelOperation(modelCardId);

public async Task Receive(string modelCardId)
{
using var unitOfWork = _unitOfWorkFactory.Resolve<ReceiveOperation>();
try
{
// Get receiver card
if (_store.GetModelById(modelCardId) is not ReceiverModelCard modelCard)
{
// Handle as GLOBAL ERROR at BrowserBridge
throw new InvalidOperationException("No download model card was found.");
}

// Init cancellation token source -> Manager also cancel it if exist before
CancellationTokenSource cts = _cancellationManager.InitCancellationTokenSource(modelCardId);

// Receive host objects
HostObjectBuilderResult conversionResults = await unitOfWork.Service
.Execute(
modelCard.AccountId.NotNull(), // POC: I hear -you are saying why we're passing them separately. Not sure pass the DUI3-> Connectors.DUI project dependency to the SDK-> Connector.Utils
modelCard.ProjectId.NotNull(),
modelCard.ProjectName.NotNull(),
modelCard.ModelName.NotNull(),
modelCard.SelectedVersionId.NotNull(),
cts.Token,
(status, progress) => OnSendOperationProgress(modelCardId, status, progress)
)
.ConfigureAwait(false);

modelCard.BakedObjectIds = conversionResults.BakedObjectIds.ToList();
Commands.SetModelReceiveResult(
modelCardId,
conversionResults.BakedObjectIds,
conversionResults.ConversionResults
);
}
// Catch here specific exceptions if they related to model card.
catch (OperationCanceledException)
{
// SWALLOW -> UI handles it immediately, so we do not need to handle anything
return;
}
}

private void OnSendOperationProgress(string modelCardId, string status, double? progress)
{
Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress));
}

public void CancelSend(string modelCardId) => _cancellationManager.CancelOperation(modelCardId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
using Speckle.Autofac.DependencyInjection;
using Speckle.Connectors.DUI;
using Speckle.Connectors.DUI.Bindings;
using Speckle.Connectors.DUI.Bridge;
using Speckle.Connectors.DUI.Models;
using Speckle.Connectors.Revit.Bindings;
using Speckle.Connectors.Revit.HostApp;
using Speckle.Connectors.Revit.Operations.Receive;
using Speckle.Connectors.Revit.Operations.Send;
using Speckle.Connectors.Revit.Plugin;
using Speckle.Connectors.Utils;
using Speckle.Connectors.Utils.Builders;
using Speckle.Connectors.Utils.Caching;
using Speckle.Connectors.Utils.Operations;
using Speckle.Core.Models.GraphTraversal;

namespace Speckle.Connectors.Revit.DependencyInjection;

Expand All @@ -27,7 +28,7 @@ public void Load(SpeckleContainerBuilder builder)
builder.AddDUI();
//builder.AddDUIView();

builder.AddSingletonInstance<ISyncToThread, SyncToCurrentThread>();
builder.AddSingletonInstance<ISyncToThread, RevitContextAccessor>();

// POC: different versons for different versions of CEF
builder.AddSingleton(BindingOptions.DefaultBinder);
Expand All @@ -49,20 +50,24 @@ public void Load(SpeckleContainerBuilder builder)
// and where the UoW should be
// register UI bindings
builder.AddSingleton<IBinding, TestBinding>();
builder.AddSingleton<IBinding, ConfigBinding>("connectorName", "ArcGIS"); // POC: Easier like this for now, should be cleaned up later
builder.AddSingleton<IBinding, ConfigBinding>("connectorName", "Revit"); // POC: Easier like this for now, should be cleaned up later
builder.AddSingleton<IBinding, AccountBinding>();
builder.AddSingleton<IBinding, BasicConnectorBindingRevit>();
builder.AddSingleton<IBasicConnectorBinding, BasicConnectorBindingRevit>();
builder.AddSingleton<IBinding, SelectionBinding>();
builder.AddSingleton<IBinding, RevitSendBinding>();
//no receive?
builder.AddSingleton<IBinding, RevitReceiveBinding>();
builder.AddSingleton<IRevitIdleManager, RevitIdleManager>();

// send operation and dependencies
builder.AddScoped<SendOperation<ElementId>>();
builder.AddScoped<IRootObjectBuilder<ElementId>, RevitRootObjectBuilder>();

// register send conversion cache
builder.AddSingleton<ISendConversionCache, SendConversionCache>();

// receive operation and dependencies
builder.AddScoped<ReceiveOperation>();
builder.AddScoped<IHostObjectBuilder, RevitHostObjectBuilder>();
builder.AddScoped<TransactionManager>();
builder.AddSingleton(DefaultTraversal.CreateTraversalFunc());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep perfect. This new and improved DefaultTraversal is exactly what we should be using (injecting as you have here) from now on.
Tldr, this one should behave functionally equivalent to the old one, while no longer being dependent on the old CanConvertFunction.

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Revit.Async;
using Speckle.Connectors.Utils.Operations;

namespace Speckle.Connectors.Revit.Operations.Receive;

internal class RevitContextAccessor : ISyncToThread
{
public Task<T> RunOnThread<T>(Func<T> func) => RevitTask.RunAsync(func);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using Speckle.Connectors.Utils.Builders;
using Speckle.Connectors.Utils.Conversion;
using Speckle.Converters.Common;
using Speckle.Core.Logging;
using Speckle.Core.Models.GraphTraversal;
using Speckle.Core.Models;
using Speckle.Converters.RevitShared.Helpers;

namespace Speckle.Connectors.Revit.Operations.Receive;

internal class RevitHostObjectBuilder : IHostObjectBuilder
{
private readonly IRootToHostConverter _converter;
private readonly IRevitConversionContextStack _contextStack;
private readonly GraphTraversal _traverseFunction;
private readonly TransactionManager _transactionManager;

public RevitHostObjectBuilder(
IRootToHostConverter converter,
IRevitConversionContextStack contextStack,
GraphTraversal traverseFunction,
TransactionManager transactionManager
)
{
_converter = converter;
_contextStack = contextStack;
_traverseFunction = traverseFunction;
_transactionManager = transactionManager;
}

public HostObjectBuilderResult Build(
Base rootObject,
string projectName,
string modelName,
Action<string, double?>? onOperationProgressed,
CancellationToken cancellationToken
)
{
var objectsToConvert = _traverseFunction
.TraverseWithProgress(rootObject, onOperationProgressed, cancellationToken)
.Where(obj => obj.Current is not Collection);

_transactionManager.StartTransactionGroup($"Received data from {projectName}");

var conversionResults = BakeObjects(objectsToConvert);

_transactionManager.CommitTransactionGroup();
_transactionManager.Dispose();

return conversionResults;
}

// POC: Potentially refactor out into an IObjectBaker.
private HostObjectBuilderResult BakeObjects(IEnumerable<TraversalContext> objectsGraph)
{
var conversionResults = new List<ReceiveConversionResult>();
var bakedObjectIds = new List<string>();

foreach (TraversalContext tc in objectsGraph)
{
try
{
YieldToUiThread();
var result = _converter.Convert(tc.Current);
}
catch (Exception ex) when (!ex.IsFatal())
{
conversionResults.Add(new(Status.ERROR, tc.Current, null, null, ex));
}
}

return new(bakedObjectIds, conversionResults);
}

private DateTime _timerStarted = DateTime.MinValue;

private void YieldToUiThread()
{
var currentTime = DateTime.UtcNow;

if (currentTime.Subtract(_timerStarted) < TimeSpan.FromSeconds(.15))
{
return;
}

System.Windows.Threading.Dispatcher.CurrentDispatcher.Invoke(
() => { },
System.Windows.Threading.DispatcherPriority.Background
);

_timerStarted = currentTime;
}
}
Loading
Loading