-
Notifications
You must be signed in to change notification settings - Fork 175
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
connorivy
wants to merge
35
commits into
dui3/alpha
from
DUI3-423-Update-create-bindings-and-other-receive-boiler-plate-for-Revit
Closed
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
befeee5
initial nuget references
adamhathcock b15bae9
Merge remote-tracking branch 'origin/dui3/alpha' into v3-core-nuget
adamhathcock 166b0f5
fmt
adamhathcock 5624c87
remove unused revit dependency
adamhathcock e8eae5d
Don't use new solution
adamhathcock 958617e
remove unused file
adamhathcock 702ef3d
Merge remote-tracking branch 'origin/dui3/alpha' into v3-core-nuget
adamhathcock 860ea96
update core
adamhathcock 27794ec
Manage V3 versions centrally (exception AutoCAD)
adamhathcock 8ca5e90
fixed up multiple autocad versions
adamhathcock 37d803e
Removal of Revit interfaces
adamhathcock cfd8aef
Remove Rhino interfaces
adamhathcock 133e60c
fix up project dependencies
adamhathcock 033dd17
some changes from reviewing
adamhathcock 7bf7a8a
Merge remote-tracking branch 'origin/dui3/alpha' into rollback-interf…
adamhathcock 0b88693
merge fixes and fmt
adamhathcock a1edddf
more review changes
adamhathcock 5d324c6
more fixes
adamhathcock a04c913
Merge remote-tracking branch 'origin/dui3/alpha' into rollback-interf…
adamhathcock d6de1b4
recheck lock files
adamhathcock fd3e2cf
fix caching
adamhathcock df9da25
logger IOC fixes
adamhathcock 0557fd5
fix IOC and fmt
adamhathcock 433aacf
try stuff for columns?
adamhathcock 214287b
WIP on DUI3-432-Implement-Receive-logic
1327b9e
Merge remote-tracking branch 'origin/dui3/alpha' into DUI3-423-Update…
0b6628e
adds geometry conversions to native
6692d62
Merge remote-tracking branch 'origin/dui3/alpha' into DUI3-423-Update…
f9af01a
update projitems
ade9122
update projitems again
2f954b5
code cleanup
60d798a
Merge remote-tracking branch 'origin/dui3/alpha' into DUI3-423-Update…
b5ffbcf
modelcurve to host
01f0193
remove comment
ff39c5d
remove commented code
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitReceiveBinding.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...onnectors/Revit/Speckle.Connectors.RevitShared/Operations/Receive/RevitContextAccessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
93 changes: 93 additions & 0 deletions
93
...nectors/Revit/Speckle.Connectors.RevitShared/Operations/Receive/RevitHostObjectBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
.