Skip to content

Commit

Permalink
Merge branch 'dui3/alpha' into dui3/ci/github-actions-test
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanRynne committed May 8, 2024
2 parents f1d9fc8 + 17819af commit dc73ade
Show file tree
Hide file tree
Showing 64 changed files with 543 additions and 539 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
using Speckle.Autofac.DependencyInjection;
using Speckle.Connectors.DUI.Bindings;
using Speckle.Connectors.DUI.Bridge;
using Speckle.Connectors.DUI.Utils;
using Speckle.Connectors.ArcGis.Operations.Send;
using Speckle.Connectors.Utils.Cancellation;
using Speckle.Core.Logging;
using ICancelable = System.Reactive.Disposables.ICancelable;
using Speckle.Connectors.ArcGIS.Utils;
using Speckle.Connectors.DUI.Models.Card;
using Speckle.Connectors.DUI.Models.Card.SendFilter;
using Speckle.Connectors.DUI.Settings;

namespace Speckle.Connectors.ArcGIS.Bindings;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,14 @@ private async Task SendInternal(string modelCardId)
throw new InvalidOperationException("No objects were found. Please update your send filter!");
}

var sendInfo = new SendInfo()
{
AccountId = modelCard.AccountId,
ProjectId = modelCard.ProjectId,
ModelId = modelCard.ModelId,
ConvertedObjects = _convertedObjectReferences,
ChangedObjectIds = modelCard.ChangedObjectIds,
SourceApplication = _autocadSettings.HostAppInfo.Name
};
var sendInfo = new SendInfo(
modelCard.AccountId,
modelCard.ProjectId,
modelCard.ModelId,
_autocadSettings.HostAppInfo.Name,
_convertedObjectReferences,
modelCard.ChangedObjectIds
);

var sendResult = await uow.Service
.Execute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class AutocadCommand

public AutofacContainer? Container { get; private set; }

[CommandMethod("SpeckleDUI3DX")]
[CommandMethod("SpeckleNewUI")]
public void Command()
{
if (PaletteSet != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CefSharp.Wpf" Version="92.0.260" />
<PackageReference Include="CefSharp.Wpf" Version="92.0.260" IncludeAssets="compile" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Revit.Async" Version="2.0.1" />
<PackageReference Include="Serilog.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Speckle.Revit.API" Version="2023.0.0" />
<PackageReference Include="Speckle.Revit.API" Version="2023.0.0" IncludeAssets="compile;build" />
</ItemGroup>

<Target AfterTargets="Clean" Name="CleanAddinFolder">
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public DocumentInfo GetDocumentInfo()
}

// POC: Notify user here if document is null.

return new DocumentInfo
{
Name = doc.Title,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ internal abstract class RevitBaseBinding : IBinding
public string Name { get; protected set; }
public IBridge Parent { get; protected set; }

protected readonly DocumentModelStore _store;
protected readonly RevitContext _revitContext;
protected readonly DocumentModelStore Store;
protected readonly RevitContext RevitContext;

public RevitBaseBinding(string name, DocumentModelStore store, IBridge bridge, RevitContext revitContext)
{
Name = name;
Parent = bridge;
_store = store;
_revitContext = revitContext;
Store = store;
RevitContext = revitContext;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ IBridge bridge

// POC: we can inject the solution here
// TODO: Need to figure it out equivalent of SelectionChanged for Revit2020
_revitContext.UIApplication.SelectionChanged += (_, _) => _revitIdleManager.SubscribeToIdle(OnSelectionChanged);

_revitContext.UIApplication.ViewActivated += (_, _) =>
{
Parent.Send(SelectionBindingEvents.SET_SELECTION, new SelectionInfo());
};
RevitContext.UIApplication.SelectionChanged += (_, _) => _revitIdleManager.SubscribeToIdle(OnSelectionChanged);
}

private void OnSelectionChanged()
Expand All @@ -42,7 +37,7 @@ public SelectionInfo GetSelection()
// POC: this was also being called on shutdown
// probably the bridge needs to be able to know if the plugin has been terminated
// also on termination the OnSelectionChanged event needs unwinding
var selectionIds = _revitContext.UIApplication.ActiveUIDocument.Selection
var selectionIds = RevitContext.UIApplication.ActiveUIDocument.Selection
.GetElementIds()
.Select(id => id.ToString())
.ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
using System.Threading.Tasks;
using System.Threading;
using Speckle.Converters.RevitShared.Helpers;
using Speckle.Connectors.Revit.Operations.Send;
using Speckle.Connectors.DUI.Models.Card;
using Speckle.Connectors.DUI.Bindings;
using Speckle.Autofac.DependencyInjection;
using Speckle.Connectors.DUI.Models;
using Speckle.Connectors.Utils.Operations;
using Speckle.Core.Models;

namespace Speckle.Connectors.Revit.Bindings;

Expand All @@ -27,6 +28,12 @@ internal class SendBinding : RevitBaseBinding, ICancelable, ISendBinding
// POC: does it need injecting?
private HashSet<string> ChangedObjectIds { get; set; } = new();

/// <summary>
/// Keeps track of previously converted objects as a dictionary of (applicationId, object reference).
/// </summary>
private readonly Dictionary<string, ObjectReference> _convertedObjectReferences = new();

private readonly RevitSettings _revitSettings;
private readonly IRevitIdleManager _idleManager;
private readonly IUnitOfWorkFactory _unitOfWorkFactory;

Expand All @@ -35,12 +42,14 @@ public SendBinding(
RevitContext revitContext,
DocumentModelStore store,
IBridge bridge,
IUnitOfWorkFactory unitOfWorkFactory
IUnitOfWorkFactory unitOfWorkFactory,
RevitSettings revitSettings
)
: base("sendBinding", store, bridge, revitContext)
{
_idleManager = idleManager;
_unitOfWorkFactory = unitOfWorkFactory;
_revitSettings = revitSettings;
Commands = new SendBindingUICommands(bridge);

// TODO expiry events
Expand Down Expand Up @@ -78,25 +87,45 @@ private async Task HandleSend(string modelCardId)
// bubbling up to the bridge.
try
{
if (_store.GetModelById(modelCardId) is not SenderModelCard modelCard)
if (Store.GetModelById(modelCardId) is not SenderModelCard modelCard)
{
throw new InvalidOperationException("No publish model card was found.");
}

using IUnitOfWork<SendOperation> sendOperation = _unitOfWorkFactory.Resolve<SendOperation>();
using IUnitOfWork<SendOperation<ElementId>> sendOperation = _unitOfWorkFactory.Resolve<
SendOperation<ElementId>
>();

List<ElementId> revitObjects = modelCard.SendFilter.GetObjectIds().Select(id => ElementId.Parse(id)).ToList();

var sendInfo = new SendInfo(
modelCard.AccountId,
modelCard.ProjectId,
modelCard.ModelId,
_revitSettings.HostSlug,
_convertedObjectReferences,
modelCard.ChangedObjectIds
);

string versionId = await sendOperation.Service
var sendResult = await sendOperation.Service
.Execute(
modelCard.SendFilter,
modelCard.AccountId,
modelCard.ProjectId,
modelCard.ModelId,
revitObjects,
sendInfo,
(status, progress) => OnSendOperationProgress(modelCardId, status, progress),
cts.Token
)
.ConfigureAwait(false);

Commands.SetModelCreatedVersionId(modelCardId, versionId);
// Store the converted references in memory for future send operations, overwriting the existing values for the given application id.
foreach (var kvp in sendResult.convertedReferences)
{
_convertedObjectReferences[kvp.Key + modelCard.ProjectId] = kvp.Value;
}

// It's important to reset the model card's list of changed obj ids so as to ensure we accurately keep track of changes between send operations.
modelCard.ChangedObjectIds = new();

Commands.SetModelCreatedVersionId(modelCardId, sendResult.rootObjId);
}
catch (OperationCanceledException)
{
Expand Down Expand Up @@ -166,15 +195,18 @@ private void DocChangeHandler(Autodesk.Revit.DB.Events.DocumentChangedEventArgs

private void RunExpirationChecks()
{
List<SenderModelCard> senders = _store.GetSenders();
List<SenderModelCard> senders = Store.GetSenders();
string[] objectIdsList = ChangedObjectIds.ToArray();
List<string> expiredSenderIds = new();

foreach (var sender in senders)
foreach (SenderModelCard modelCard in senders)
{
bool isExpired = sender.SendFilter.CheckExpiry(ChangedObjectIds.ToArray());
var intersection = modelCard.SendFilter.GetObjectIds().Intersect(objectIdsList).ToList();
bool isExpired = modelCard.SendFilter.CheckExpiry(ChangedObjectIds.ToArray());
if (isExpired)
{
expiredSenderIds.Add(sender.ModelCardId);
expiredSenderIds.Add(modelCard.ModelCardId);
modelCard.ChangedObjectIds.UnionWith(intersection);
}
}

Expand Down
Loading

0 comments on commit dc73ade

Please sign in to comment.