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
adamhathcock committed May 21, 2024
2 parents a936ba0 + e54e5a2 commit 804fa61
Show file tree
Hide file tree
Showing 24 changed files with 174 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ namespace Speckle.Connectors.ArcGIS.Bindings;

public class ArcGISSelectionBinding : ISelectionBinding
{
private const string SELECTION_EVENT = "setSelection";

public string Name { get; } = "selectionBinding";
public IBridge Parent { get; set; }

Expand All @@ -17,14 +15,14 @@ public ArcGISSelectionBinding(IBridge parent)
Parent = parent;

// example: https://github.com/Esri/arcgis-pro-sdk-community-samples/blob/master/Map-Authoring/QueryBuilderControl/DefinitionQueryDockPaneViewModel.cs
MapViewEventArgs args = new(MapView.Active);
// MapViewEventArgs args = new(MapView.Active);
TOCSelectionChangedEvent.Subscribe(OnSelectionChanged, true);
}

private void OnSelectionChanged(MapViewEventArgs args)
{
SelectionInfo selInfo = GetSelection();
Parent?.Send(SELECTION_EVENT, selInfo);
Parent?.Send(SelectionBindingEvents.SET_SELECTION, selInfo);
}

public SelectionInfo GetSelection()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
using Speckle.Connectors.DUI.Models.Card.SendFilter;
using Speckle.Connectors.DUI.Settings;
using Speckle.Connectors.Utils;
using ArcGIS.Desktop.Mapping.Events;
using ArcGIS.Desktop.Mapping;
using Speckle.Connectors.ArcGIS.Filters;

namespace Speckle.Connectors.ArcGIS.Bindings;

Expand Down Expand Up @@ -45,6 +48,54 @@ CancellationManager cancellationManager

Parent = parent;
Commands = new SendBindingUICommands(parent);
SubscribeToArcGISEvents();
}

private void SubscribeToArcGISEvents()
{
LayersRemovedEvent.Subscribe(GetIdsForLayersRemovedEvent, true);
StandaloneTablesRemovedEvent.Subscribe(GetIdsForStandaloneTablesRemovedEvent, true);
MapPropertyChangedEvent.Subscribe(GetIdsForMapPropertyChangedEvent, true); // Map units, CRS etc.
MapMemberPropertiesChangedEvent.Subscribe(GetIdsForMapMemberPropertiesChangedEvent, true); // e.g. Layer name
}

private void GetIdsForLayersRemovedEvent(LayerEventsArgs args)
{
foreach (Layer layer in args.Layers)
{
ChangedObjectIds.Add(layer.URI);
}
RunExpirationChecks(true);
}

private void GetIdsForStandaloneTablesRemovedEvent(StandaloneTableEventArgs args)
{
foreach (StandaloneTable table in args.Tables)
{
ChangedObjectIds.Add(table.URI);
}
RunExpirationChecks(true);
}

private void GetIdsForMapPropertyChangedEvent(MapPropertyChangedEventArgs args)
{
foreach (Map map in args.Maps)
{
foreach (MapMember member in map.Layers)
{
ChangedObjectIds.Add(member.URI);
}
}
RunExpirationChecks(false);
}

private void GetIdsForMapMemberPropertiesChangedEvent(MapMemberPropertiesChangedEventArgs args)
{
foreach (MapMember member in args.MapMembers)
{
ChangedObjectIds.Add(member.URI);
}
RunExpirationChecks(false);
}

public List<ISendFilter> GetSendFilters() => _sendFilters;
Expand Down Expand Up @@ -112,17 +163,28 @@ public async Task Send(string modelCardId)
/// <summary>
/// Checks if any sender model cards contain any of the changed objects. If so, also updates the changed objects hashset for each model card - this last part is important for on send change detection.
/// </summary>
private void RunExpirationChecks()
private void RunExpirationChecks(bool idsDeleted)
{
var senders = _store.GetSenders();
List<string> expiredSenderIds = new();
string[] objectIdsList = ChangedObjectIds.ToArray();

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

// Update the model card object Ids
if (idsDeleted && sender.SendFilter is ArcGISSelectionFilter filter)
{
List<string> remainingObjIds = objIds.SkipWhile(x => intersection.Contains(x)).ToList();
filter.SelectedObjectIds = remainingObjIds;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public BasicConnectorBinding(DocumentModelStore store, ArcGISSettings settings,

public string GetConnectorVersion() => Assembly.GetAssembly(GetType()).NotNull().GetVersion();

// TODO
public DocumentInfo GetDocumentInfo() => new(Project.Current.URI, Project.Current.Name, Project.Current.Name);

public DocumentModelStore GetDocumentState() => _store;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.IO;
using System.Reflection;
using ArcGIS.Desktop.Framework;
using Autofac;
using Speckle.Autofac;
using Speckle.Autofac.DependencyInjection;
using Speckle.Autofac.Files;
using Speckle.Connectors.ArcGIS.HostApp;
Expand Down Expand Up @@ -29,7 +28,7 @@ internal sealed class SpeckleModule : Module

public SpeckleModule()
{
AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve;
AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolver.OnAssemblyResolve<SpeckleModule>;

Container = new AutofacContainer(new StorageInfo());
Container.PreBuildEvent += Container_PreBuildEvent;
Expand Down Expand Up @@ -57,25 +56,4 @@ private static void Container_PreBuildEvent(object? sender, ContainerBuilder con
containerBuilder.InjectNamedTypes<IHostObjectToSpeckleConversion>();
containerBuilder.InjectNamedTypes<ISpeckleObjectToHostConversion>();
}

private static Assembly? OnAssemblyResolve(object? sender, ResolveEventArgs args)
{
// POC: dupe code
// POC: tight binding to files
Assembly? assembly = null;
string name = args.Name.Split(',')[0];
string? path = Path.GetDirectoryName(typeof(SpeckleModule).Assembly.Location);

if (path != null)
{
string assemblyFile = Path.Combine(path, name + ".dll");

if (File.Exists(assemblyFile))
{
assembly = Assembly.LoadFrom(assemblyFile);
}
}

return assembly;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public string GetConnectorVersion() =>
{
return null;
}
string name = doc.Name.Split(System.IO.Path.PathSeparator).Reverse().First();
return new DocumentInfo(doc.Name, name, doc.Name);
string name = doc.Name.Split(System.IO.Path.PathSeparator).Last();
return new DocumentInfo(doc.Name, name, doc.GetHashCode().ToString());
}

public DocumentModelStore GetDocumentState() => _store;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
using System.IO;
using System.Reflection;
using Autodesk.AutoCAD.Runtime;
using Speckle.Autofac;

namespace Speckle.Connectors.Autocad.Plugin;

public class AutocadExtensionApplication : IExtensionApplication
{
public void Initialize() => AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(OnAssemblyResolve);
public void Initialize() =>
AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolver.OnAssemblyResolve<AutocadExtensionApplication>;

public void Terminate() { }

private Assembly? OnAssemblyResolve(object sender, ResolveEventArgs args)
{
Assembly? a = null;
string name = args.Name.Split(',')[0];
string path = Path.GetDirectoryName(typeof(AutocadExtensionApplication).Assembly.Location);

string assemblyFile = Path.Combine(path, name + ".dll");

if (File.Exists(assemblyFile))
{
a = Assembly.LoadFrom(assemblyFile);
}

return a;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,26 @@ public string GetConnectorVersion()

public string GetSourceApplicationName() => _revitSettings.HostSlug.ToLower(); // POC: maybe not right place but... // ANOTHER POC: We should align this naming from somewhere in common DUI projects instead old structs. I know there are other POC comments around this

public string GetSourceApplicationVersion()
{
// POC: maybe not right place but...
return _revitSettings.HostAppVersion;
}
public string GetSourceApplicationVersion() => _revitSettings.HostAppVersion; // POC: maybe not right place but...

public DocumentInfo? GetDocumentInfo()
{
// POC: not sure why this would ever be null, is this needed?
_revitContext.UIApplication.NotNull();

var doc = _revitContext.UIApplication.ActiveUIDocument.Document;
var doc = _revitContext.UIApplication.ActiveUIDocument?.Document;
if (doc is null)
{
return null;
}

var info = new DocumentInfo(doc.Title, doc.GetHashCode().ToString(), doc.PathName);
if (doc.IsFamilyDocument)
{
info.Message = "Family Environment files not supported by Speckle.";
return new DocumentInfo("", "", "") { Message = "Family environment files not supported by Speckle." };
}

// POC: Notify user here if document is null.
var info = new DocumentInfo(doc.PathName, doc.Title, doc.GetHashCode().ToString());

return info;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,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.GetElementIds())
var selectionIds = (RevitContext.UIApplication?.ActiveUIDocument?.Selection.GetElementIds())
.NotNull()
.Select(id => id.ToString())
.ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public override void ReadFromFile()
{
try
{
var stateEntity = GetSpeckleEntity(_revitContext.UIApplication?.ActiveUIDocument.Document);
var stateEntity = GetSpeckleEntity(_revitContext.UIApplication?.ActiveUIDocument?.Document);
if (stateEntity == null || !stateEntity.IsValid())
{
Models = new();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Autodesk.Revit.UI;
using Speckle.Autofac.DependencyInjection;
using Speckle.Autofac.Files;
using System.Reflection;
using System.IO;
using Autofac;
using Speckle.Autofac;
using Speckle.Connectors.Utils;
using Speckle.Converters.Common.DependencyInjection;
using Speckle.Converters.Common.Objects;
Expand Down Expand Up @@ -47,15 +47,16 @@ public Result OnStartup(UIControlledApplication application)
try
{
// POC: not sure what this is doing... could be messing up our Aliasing????
AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve;
AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolver.OnAssemblyResolve<RevitExternalApplication>;

_container = new AutofacContainer(new StorageInfo());
_container.PreBuildEvent += ContainerPreBuildEvent;

// init DI
_container
.LoadAutofacModules(_revitSettings.ModuleFolders.NotNull())
.AddSingletonInstance<RevitSettings>(_revitSettings) // apply revit settings into DI
.AddSingletonInstance<UIControlledApplication>(application) // inject UIControlledApplication application
.AddSingletonInstance(_revitSettings) // apply revit settings into DI
.AddSingletonInstance(application) // inject UIControlledApplication application
.Build();

// resolve root object
Expand Down Expand Up @@ -96,24 +97,4 @@ public Result OnShutdown(UIControlledApplication application)

return Result.Succeeded;
}

private Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
{
// POC: tight binding to files
Assembly? assembly = null;
string name = args.Name.Split(',')[0];
string path = Path.GetDirectoryName(typeof(RevitPlugin).Assembly.Location);

if (path != null)
{
string assemblyFile = Path.Combine(path, name + ".dll");

if (File.Exists(assemblyFile))
{
assembly = Assembly.LoadFrom(assemblyFile);
}
}

return assembly.NotNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ private void PostApplicationInit()

_cefSharpPanel.Browser.IsBrowserInitializedChanged += (sender, e) =>
{
// Not needed now, as we should be able to correctly open dev tools via user interaction
// _cefSharpPanel.ShowDevTools();
if (e.NewValue is false)
{
return;
}

foreach (IBinding binding in _bindings.Select(x => x.Value))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ protected override void Load(ContainerBuilder builder)

// binding dependencies
builder.RegisterType<CancellationManager>().InstancePerDependency();
builder.RegisterType<ServerTransport>().As<ITransport>().InstancePerDependency();

// register send filters
builder.RegisterType<RhinoSelectionFilter>().As<ISendFilter>().InstancePerDependency();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using Rhino.UI;
using Speckle.Connectors.DUI.WebView;
using Speckle.Connectors.Rhino7.Plugin;

Expand All @@ -8,10 +11,43 @@ namespace Speckle.Connectors.Rhino7.HostApp;
public class SpeckleRhinoPanelHost : RhinoWindows.Controls.WpfElementHost
{
private readonly uint _docSn;
private readonly DUI3ControlWebView? _webView;

public SpeckleRhinoPanelHost(uint docSn)
: base(SpeckleConnectorsRhino7Plugin.Instance.Container?.Resolve<DUI3ControlWebView>(), null)
{
_docSn = docSn;
_webView = SpeckleConnectorsRhino7Plugin.Instance.Container?.Resolve<DUI3ControlWebView>();
Panels.Closed += PanelsOnClosed;
}

private void PanelsOnClosed(object sender, PanelEventArgs e)
{
if (e.PanelId == typeof(SpeckleRhinoPanelHost).GUID)
{
// This check comes from behavioral difference on closing Rhino Panels.
// IsPanelVisible returns;
// - True, when docked Panel closed from the list on right click on panel tab,
// whenever it is closed with this way, Rhino.Panels tries to reinit this object and expect the different UIElement, that's why we disconnect Child.
// - False, when detached Panel is closed by 'X' close button.
// whenever it is closed with this way, Rhino.Panels don't create this object, that's why we do not disconnect Child UIElement.
if (!Panels.IsPanelVisible(typeof(SpeckleRhinoPanelHost).GUID))
{
return;
}

// Unsubscribe from the event to prevent growing registrations.
Panels.Closed -= PanelsOnClosed;

// Disconnect UIElement from WpfElementHost. Otherwise, we can't reinit panel with same DUI3ControlWebView
if (_webView != null)
{
// Since WpfHost inherited from Border, find the parent as border and set null it's Child.
if (LogicalTreeHelper.GetParent(_webView) is Border border)
{
border.Child = null;
}
}
}
}
}
Loading

0 comments on commit 804fa61

Please sign in to comment.