Skip to content

Commit

Permalink
Merge pull request #591 from specklesystems/dev
Browse files Browse the repository at this point in the history
test(etabs): bundled installer with ini file magic
  • Loading branch information
bjoernsteinhagen authored Feb 17, 2025
2 parents 929db22 + f882b0f commit 6d4e12d
Show file tree
Hide file tree
Showing 41 changed files with 889 additions and 673 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using ArcGIS.Core.Data;
using ArcGIS.Desktop.Core;
using ArcGIS.Desktop.Editing.Events;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Mapping;
using ArcGIS.Desktop.Mapping.Events;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -101,32 +102,31 @@ private void SubscribeToArcGISEvents()
LayersRemovedEvent.Subscribe(
a =>
_topLevelExceptionHandler.FireAndForget(
async () => await _threadContext.RunOnWorkerAsync(async () => await GetIdsForLayersRemovedEvent(a))
async () => await QueuedTask.Run(async () => await GetIdsForLayersRemovedEvent(a))
),
true
);

StandaloneTablesRemovedEvent.Subscribe(
a =>
_topLevelExceptionHandler.FireAndForget(
async () => await _threadContext.RunOnWorkerAsync(async () => await GetIdsForStandaloneTablesRemovedEvent(a))
async () => await QueuedTask.Run(async () => await GetIdsForStandaloneTablesRemovedEvent(a))
),
true
);

MapPropertyChangedEvent.Subscribe(
a =>
_topLevelExceptionHandler.FireAndForget(
async () => await _threadContext.RunOnWorkerAsync(async () => await GetIdsForMapPropertyChangedEvent(a))
async () => await QueuedTask.Run(async () => await GetIdsForMapPropertyChangedEvent(a))
),
true
); // Map units, CRS etc.

MapMemberPropertiesChangedEvent.Subscribe(
a =>
_topLevelExceptionHandler.FireAndForget(
async () =>
await _threadContext.RunOnWorkerAsync(async () => await GetIdsForMapMemberPropertiesChangedEvent(a))
async () => await QueuedTask.Run(async () => await GetIdsForMapMemberPropertiesChangedEvent(a))
),
true
); // e.g. Layer name
Expand All @@ -135,7 +135,7 @@ await _threadContext.RunOnWorkerAsync(async () => await GetIdsForMapMemberProper
_ =>
_topLevelExceptionHandler.FireAndForget(async () =>
{
await _threadContext.RunOnWorker(SubscribeToMapMembersDataSourceChange);
await QueuedTask.Run(SubscribeToMapMembersDataSourceChange);
}),
true
);
Expand Down Expand Up @@ -376,40 +376,47 @@ public async Task Send(string modelCardId)
using var cancellationItem = _cancellationManager.GetCancellationItem(modelCardId);

using var scope = _serviceProvider.CreateScope();
scope
.ServiceProvider.GetRequiredService<IConverterSettingsStore<ArcGISConversionSettings>>()
.Initialize(
_arcGISConversionSettingsFactory.Create(
Project.Current,
MapView.Active.Map,
new CRSoffsetRotation(MapView.Active.Map)
)
);
List<MapMember> mapMembers = modelCard
.SendFilter.NotNull()
.RefreshObjectIds()
.Select(id => (MapMember)MapView.Active.Map.FindLayer(id) ?? MapView.Active.Map.FindStandaloneTable(id))
.Where(obj => obj != null)
.ToList();
List<MapMember> mapMembers = await QueuedTask.Run(() =>
{
scope
.ServiceProvider.GetRequiredService<IConverterSettingsStore<ArcGISConversionSettings>>()
.Initialize(
_arcGISConversionSettingsFactory.Create(
Project.Current,
MapView.Active.Map,
new CRSoffsetRotation(MapView.Active.Map)
)
);

return modelCard
.SendFilter.NotNull()
.RefreshObjectIds()
.Select(id => (MapMember)MapView.Active.Map.FindLayer(id) ?? MapView.Active.Map.FindStandaloneTable(id))
.Where(obj => obj != null)
.ToList();
});

if (mapMembers.Count == 0)
{
// Handle as CARD ERROR in this function
throw new SpeckleSendFilterException("No objects were found to convert. Please update your publish filter!");
}

// subscribe to the selected layer events
foreach (MapMember mapMember in mapMembers)
await QueuedTask.Run(() =>
{
if (mapMember is FeatureLayer featureLayer)
// subscribe to the selected layer events
foreach (MapMember mapMember in mapMembers)
{
SubscribeToFeatureLayerDataSourceChange(featureLayer);
if (mapMember is FeatureLayer featureLayer)
{
SubscribeToFeatureLayerDataSourceChange(featureLayer);
}
else if (mapMember is StandaloneTable table)
{
SubscribeToTableDataSourceChange(table);
}
}
else if (mapMember is StandaloneTable table)
{
SubscribeToTableDataSourceChange(table);
}
}
});

var sendResult = await scope
.ServiceProvider.GetRequiredService<SendOperation<MapMember>>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ArcGIS.Core.Data;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Mapping;
using Speckle.Connectors.ArcGIS.Utils;
using Speckle.Connectors.DUI.Bindings;
Expand Down Expand Up @@ -66,19 +67,18 @@ ITopLevelExceptionHandler topLevelExceptionHandler

public void RemoveModel(ModelCard model) => _store.RemoveModel(model);

public Task HighlightObjects(IReadOnlyList<string> objectIds)
public async Task HighlightObjects(IReadOnlyList<string> objectIds)
{
HighlightObjectsOnView(objectIds.Select(x => new ObjectID(x)).ToList());
return Task.CompletedTask;
await HighlightObjectsOnView(objectIds.Select(x => new ObjectID(x)).ToList());
}

public Task HighlightModel(string modelCardId)
public async Task HighlightModel(string modelCardId)
{
var model = _store.GetModelById(modelCardId);

if (model is null)
{
return Task.CompletedTask;
return;
}

var objectIds = new List<ObjectID>();
Expand All @@ -95,22 +95,24 @@ public Task HighlightModel(string modelCardId)

if (objectIds is null)
{
return Task.CompletedTask;
return;
}
HighlightObjectsOnView(objectIds);
return Task.CompletedTask;
await HighlightObjectsOnView(objectIds);
}

private void HighlightObjectsOnView(IReadOnlyList<ObjectID> objectIds)
private async Task HighlightObjectsOnView(IReadOnlyList<ObjectID> objectIds)
{
MapView mapView = MapView.Active;

List<MapMemberFeature> mapMembersFeatures = GetMapMembers(objectIds, mapView);
ClearSelectionInTOC();
ClearSelection();
SelectMapMembersInTOC(mapMembersFeatures);
SelectMapMembersAndFeatures(mapMembersFeatures);
mapView.ZoomToSelected();
await QueuedTask.Run(() =>
{
MapView mapView = MapView.Active;

List<MapMemberFeature> mapMembersFeatures = GetMapMembers(objectIds, mapView);
ClearSelectionInTOC();
ClearSelection();
SelectMapMembersInTOC(mapMembersFeatures);
SelectMapMembersAndFeatures(mapMembersFeatures);
mapView.ZoomToSelected();
});
}

private List<MapMemberFeature> GetMapMembers(IReadOnlyList<ObjectID> objectIds, MapView mapView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Speckle.Connectors.Common.Builders;
using Speckle.Connectors.Common.Caching;
using Speckle.Connectors.Common.Operations;
using Speckle.Connectors.Common.Threading;
using Speckle.Connectors.DUI;
using Speckle.Connectors.DUI.Bindings;
using Speckle.Connectors.DUI.Models.Card.SendFilter;
Expand All @@ -27,7 +28,7 @@ public static class ArcGISConnectorModule
public static void AddArcGIS(this IServiceCollection serviceCollection)
{
serviceCollection.AddConnectorUtils();
serviceCollection.AddDUI<ArcGISThreadContext, ArcGISDocumentStore>();
serviceCollection.AddDUI<DefaultThreadContext, ArcGISDocumentStore>();
serviceCollection.AddDUIView();

// Register bindings
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Diagnostics.Contracts;
using ArcGIS.Core.CIM;
using ArcGIS.Core.Geometry;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Mapping;
using Speckle.Connectors.ArcGIS.HostApp;
using Speckle.Connectors.ArcGIS.Utils;
Expand Down Expand Up @@ -60,6 +61,19 @@ public Task<HostObjectBuilderResult> Build(
IProgress<CardProgress> onOperationProgressed,
CancellationToken cancellationToken
)
{
return QueuedTask.Run(
() => BuildInternal(rootObject, projectName, modelName, onOperationProgressed, cancellationToken)
);
}

private HostObjectBuilderResult BuildInternal(
Base rootObject,
string projectName,
string modelName,
IProgress<CardProgress> onOperationProgressed,
CancellationToken cancellationToken
)
{
// TODO get spatialRef and offsets & rotation from ProjectInfo in CommitObject
// ATM, GIS commit CRS is stored per layer (in FeatureClass converter), but should be moved to the Root level too
Expand Down Expand Up @@ -226,7 +240,7 @@ CancellationToken cancellationToken
bakedObjectIds.AddRange(createdLayerGroups.Values.Select(x => x.URI));

// TODO: validated a correct set regarding bakedobject ids
return Task.FromResult(new HostObjectBuilderResult(bakedObjectIds, results));
return new HostObjectBuilderResult(bakedObjectIds, results);
}

private IReadOnlyCollection<LocalToGlobalMap> GetObjectsToConvert(Base rootObject)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ArcGIS.Core.Data.Raster;
using ArcGIS.Core.Geometry;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Speckle.Connectors.ArcGIS.HostApp;
using Speckle.Connectors.ArcGIS.HostApp.Extensions;
Expand Down Expand Up @@ -49,7 +50,14 @@ MapMembersUtils mapMemberUtils
_mapMemberUtils = mapMemberUtils;
}

public async Task<RootObjectBuilderResult> Build(
public Task<RootObjectBuilderResult> Build(
IReadOnlyList<ADM.MapMember> layers,
SendInfo __,
IProgress<CardProgress> onOperationProgressed,
CancellationToken cancellationToken
) => QueuedTask.Run(() => BuildInternal(layers, __, onOperationProgressed, cancellationToken));

private async Task<RootObjectBuilderResult> BuildInternal(
IReadOnlyList<ADM.MapMember> layers,
SendInfo __,
IProgress<CardProgress> onOperationProgressed,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Xml.Linq;
using ArcGIS.Desktop.Core.Events;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Mapping;
using ArcGIS.Desktop.Mapping.Events;
using Speckle.Connectors.Common.Threading;
Expand Down Expand Up @@ -82,8 +83,8 @@ private void OnMapViewChanged(ActiveMapViewChangedEventArgs args)
}

protected override void HostAppSaveState(string modelCardState) =>
_threadContext
.RunOnWorker(() =>
QueuedTask
.Run(() =>
{
Map map = MapView.Active.Map;
// Read existing metadata - To prevent messing existing metadata. 🤞 Hope other add-in developers will do same :D
Expand Down Expand Up @@ -112,8 +113,8 @@ protected override void HostAppSaveState(string modelCardState) =>
.FireAndForget();

protected override void LoadState() =>
_threadContext
.RunOnWorker(() =>
QueuedTask
.Run(() =>
{
Map map = MapView.Active.Map;
var metadata = map.GetMetadata();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Speckle.Connectors.DUI.Bindings;
using Speckle.Connectors.Common.Threading;
using Speckle.Connectors.DUI.Bindings;
using Speckle.Connectors.DUI.Bridge;
using Speckle.Connectors.DUI.Models;
using Speckle.Connectors.DUI.Models.Card;
Expand All @@ -11,6 +12,7 @@ public class CsiSharedBasicConnectorBinding : IBasicConnectorBinding
private readonly ISpeckleApplication _speckleApplication;
private readonly DocumentModelStore _store;
private readonly ITopLevelExceptionHandler _topLevelExceptionHandler;
private readonly IThreadContext _threadContext;
public string Name => "baseBinding";
public IBrowserBridge Parent { get; }
public BasicConnectorBindingCommands Commands { get; }
Expand All @@ -19,9 +21,11 @@ public CsiSharedBasicConnectorBinding(
IBrowserBridge parent,
ISpeckleApplication speckleApplication,
DocumentModelStore store,
ITopLevelExceptionHandler topLevelExceptionHandler
ITopLevelExceptionHandler topLevelExceptionHandler,
IThreadContext threadContext
)
{
_threadContext = threadContext;
Parent = parent;
_speckleApplication = speckleApplication;
_store = store;
Expand All @@ -31,7 +35,11 @@ ITopLevelExceptionHandler topLevelExceptionHandler
_store.DocumentChanged += (_, _) =>
_topLevelExceptionHandler.FireAndForget(async () =>
{
await Commands.NotifyDocumentChanged();
// enforce main thread
await _threadContext.RunOnMainAsync(async () =>
{
await Commands.NotifyDocumentChanged();
});
});
}

Expand All @@ -45,11 +53,17 @@ ITopLevelExceptionHandler topLevelExceptionHandler

public DocumentModelStore GetDocumentState() => _store;

public void AddModel(ModelCard model) => _store.AddModel(model);
/// <remarks>Operations must run on the main thread for ETABS and SAP 2000</remarks>
public void AddModel(ModelCard model) =>
_topLevelExceptionHandler.CatchUnhandled(() => _threadContext.RunOnThread(() => _store.AddModel(model), true));

public void UpdateModel(ModelCard model) => _store.UpdateModel(model);
/// <remarks>Operations must run on the main thread for ETABS and SAP 2000</remarks>
public void UpdateModel(ModelCard model) =>
_topLevelExceptionHandler.CatchUnhandled(() => _threadContext.RunOnThread(() => _store.UpdateModel(model), true));

public void RemoveModel(ModelCard model) => _store.RemoveModel(model);
/// <remarks>Operations must run on the main thread for ETABS and SAP 2000</remarks>
public void RemoveModel(ModelCard model) =>
_topLevelExceptionHandler.CatchUnhandled(() => _threadContext.RunOnThread(() => _store.RemoveModel(model), true));

public Task HighlightModel(string modelCardId) => Task.CompletedTask;

Expand Down
Loading

0 comments on commit 6d4e12d

Please sign in to comment.