Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhathcock committed Dec 17, 2024
1 parent 676a7e8 commit 6ebcc3f
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class ArcGISLayerUnpacker
Collection containerCollection = CreateAndCacheMapMemberCollection(mapMember, true);
parentCollection.elements.Add(containerCollection);

UnpackSelection(container.Layers, containerCollection, objects);
UnpackSelection(container.Layers, containerCollection, objects);
break;

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ CancellationToken cancellationToken
IEnumerable<ADM.MapMember> layersOrdered = _mapMemberUtils.GetMapMembersInOrder(map, layers);
using (var _ = _activityFactory.Start("Unpacking selection"))
{
unpackedLayers = _layerUnpacker.UnpackSelection(layersOrdered, rootCollection);
unpackedLayers = _layerUnpacker.UnpackSelection(layersOrdered, rootCollection);
}

List<SendConversionResult> results = new(unpackedLayers.Count);
Expand All @@ -112,7 +112,7 @@ CancellationToken cancellationToken
int count = 0;
foreach (ADM.MapMember layer in unpackedLayers)
{
cancellationToken.ThrowIfCancellationRequested();
cancellationToken.ThrowIfCancellationRequested();
string layerApplicationId = layer.GetSpeckleApplicationId();

try
Expand All @@ -138,15 +138,15 @@ out ObjectReference? value
switch (layer)
{
case ADM.FeatureLayer featureLayer:
List<Base> convertedFeatureLayerObjects = ConvertFeatureLayerObjects(featureLayer);
List<Base> convertedFeatureLayerObjects = ConvertFeatureLayerObjects(featureLayer);
layerCollection.elements.AddRange(convertedFeatureLayerObjects);
break;
case ADM.RasterLayer rasterLayer:
List<Base> convertedRasterLayerObjects = ConvertRasterLayerObjects(rasterLayer);
List<Base> convertedRasterLayerObjects = ConvertRasterLayerObjects(rasterLayer);
layerCollection.elements.AddRange(convertedRasterLayerObjects);
break;
case ADM.LasDatasetLayer lasDatasetLayer:
List<Base> convertedLasDatasetObjects = ConvertLasDatasetLayerObjects(lasDatasetLayer);
List<Base> convertedLasDatasetObjects = ConvertLasDatasetLayerObjects(lasDatasetLayer);
layerCollection.elements.AddRange(convertedLasDatasetObjects);
break;
default:
Expand Down Expand Up @@ -189,32 +189,31 @@ private List<Base> ConvertFeatureLayerObjects(ADM.FeatureLayer featureLayer)
{
string layerApplicationId = featureLayer.GetSpeckleApplicationId();
List<Base> convertedObjects = new();
// store the layer renderer for color unpacking
_colorUnpacker.StoreRendererAndFields(featureLayer);
// store the layer renderer for color unpacking
_colorUnpacker.StoreRendererAndFields(featureLayer);

// search the rows of the layer, where each row is treated like an object
// RowCursor is IDisposable but is not being correctly picked up by IDE warnings.
// This means we need to be carefully adding using statements based on the API documentation coming from each method/class
using (ACD.RowCursor rowCursor = featureLayer.Search())
// search the rows of the layer, where each row is treated like an object
// RowCursor is IDisposable but is not being correctly picked up by IDE warnings.
// This means we need to be carefully adding using statements based on the API documentation coming from each method/class
using (ACD.RowCursor rowCursor = featureLayer.Search())
{
while (rowCursor.MoveNext())
{
// Same IDisposable issue appears to happen on Row class too. Docs say it should always be disposed of manually by the caller.
using (ACD.Row row = rowCursor.Current)
{
while (rowCursor.MoveNext())
{
// Same IDisposable issue appears to happen on Row class too. Docs say it should always be disposed of manually by the caller.
using (ACD.Row row = rowCursor.Current)
{
// get application id. test for subtypes before defaulting to base type.
Base converted = _rootToSpeckleConverter.Convert(row);
string applicationId = row.GetSpeckleApplicationId(layerApplicationId);
converted.applicationId = applicationId;
// get application id. test for subtypes before defaulting to base type.
Base converted = _rootToSpeckleConverter.Convert(row);
string applicationId = row.GetSpeckleApplicationId(layerApplicationId);
converted.applicationId = applicationId;

convertedObjects.Add(converted);
convertedObjects.Add(converted);

// process the object color
_colorUnpacker.ProcessFeatureLayerColor(row, applicationId);
}
}
// process the object color
_colorUnpacker.ProcessFeatureLayerColor(row, applicationId);
}

}
}

return convertedObjects;
}
Expand All @@ -224,11 +223,11 @@ private List<Base> ConvertRasterLayerObjects(ADM.RasterLayer rasterLayer)
{
string layerApplicationId = rasterLayer.GetSpeckleApplicationId();
List<Base> convertedObjects = new();
Raster raster = rasterLayer.GetRaster();
Base converted = _rootToSpeckleConverter.Convert(raster);
string applicationId = raster.GetSpeckleApplicationId(layerApplicationId);
converted.applicationId = applicationId;
convertedObjects.Add(converted);
Raster raster = rasterLayer.GetRaster();
Base converted = _rootToSpeckleConverter.Convert(raster);
string applicationId = raster.GetSpeckleApplicationId(layerApplicationId);
converted.applicationId = applicationId;
convertedObjects.Add(converted);
return convertedObjects;
}

Expand All @@ -239,27 +238,25 @@ private List<Base> ConvertLasDatasetLayerObjects(ADM.LasDatasetLayer lasDatasetL

try
{
// store the layer renderer for color unpacking
_colorUnpacker.StoreRenderer(lasDatasetLayer);
// store the layer renderer for color unpacking
_colorUnpacker.StoreRenderer(lasDatasetLayer);

using (
ACD.Analyst3D.LasPointCursor ptCursor = lasDatasetLayer.SearchPoints(new ACD.Analyst3D.LasPointFilter())
)
using (ACD.Analyst3D.LasPointCursor ptCursor = lasDatasetLayer.SearchPoints(new ACD.Analyst3D.LasPointFilter()))
{
while (ptCursor.MoveNext())
{
using (ACD.Analyst3D.LasPoint pt = ptCursor.Current)
{
while (ptCursor.MoveNext())
{
using (ACD.Analyst3D.LasPoint pt = ptCursor.Current)
{
Base converted = _rootToSpeckleConverter.Convert(pt);
string applicationId = pt.GetSpeckleApplicationId(layerApplicationId);
converted.applicationId = applicationId;
convertedObjects.Add(converted);
Base converted = _rootToSpeckleConverter.Convert(pt);
string applicationId = pt.GetSpeckleApplicationId(layerApplicationId);
converted.applicationId = applicationId;
convertedObjects.Add(converted);

// process the object color
_colorUnpacker.ProcessLasLayerColor(pt, applicationId);
}
}
// process the object color
_colorUnpacker.ProcessLasLayerColor(pt, applicationId);
}
}
}
}
catch (ACD.Exceptions.TinException ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,14 @@ NavisworksDocumentEvents documentEvents

public string GetConnectorVersion() => _speckleApplication.SpeckleVersion;

public DocumentInfo? GetDocumentInfo()
=>
NavisworksApp.ActiveDocument is null || NavisworksApp.ActiveDocument.Models.Count == 0
? null
: new DocumentInfo(
NavisworksApp.ActiveDocument.CurrentFileName,
NavisworksApp.ActiveDocument.Title,
NavisworksApp.ActiveDocument.GetHashCode().ToString()
)

;
public DocumentInfo? GetDocumentInfo() =>
NavisworksApp.ActiveDocument is null || NavisworksApp.ActiveDocument.Models.Count == 0
? null
: new DocumentInfo(
NavisworksApp.ActiveDocument.CurrentFileName,
NavisworksApp.ActiveDocument.Title,
NavisworksApp.ActiveDocument.GetHashCode().ToString()
);

public DocumentModelStore GetDocumentState() => _store;

Expand All @@ -64,6 +61,6 @@ NavisworksDocumentEvents documentEvents
public Task HighlightModel(string modelCardId) => Task.CompletedTask;

public async Task HighlightObjects(IReadOnlyList<string> objectIds) =>
// TODO: Implement highlighting logic on main thread
await Task.CompletedTask.ConfigureAwait(false);
// TODO: Implement highlighting logic on main thread
await Task.CompletedTask.ConfigureAwait(false);
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,21 @@ public async Task Send(string modelCardId)
using var activity = _activityFactory.Start();
try
{
var modelCard = GetModelCard(modelCardId);
var modelCard = GetModelCard(modelCardId);

using var scope = _serviceProvider.CreateScope();
using var scope = _serviceProvider.CreateScope();

InitializeConverterSettings(scope, modelCard);
InitializeConverterSettings(scope, modelCard);

CancellationToken token = _cancellationManager.InitCancellationTokenSource(modelCardId);
CancellationToken token = _cancellationManager.InitCancellationTokenSource(modelCardId);

var navisworksModelItems = GetNavisworksModelItems(modelCard);
var navisworksModelItems = GetNavisworksModelItems(modelCard);

var sendResult = await ExecuteSendOperation(scope, modelCard, navisworksModelItems, token)
.ConfigureAwait(false);
var sendResult = await ExecuteSendOperation(scope, modelCard, navisworksModelItems, token).ConfigureAwait(false);

await Commands
.SetModelSendResult(modelCardId, sendResult.RootObjId, sendResult.ConversionResults)
.ConfigureAwait(false);
await Commands
.SetModelSendResult(modelCardId, sendResult.RootObjId, sendResult.ConversionResults)
.ConfigureAwait(false);
}
catch (OperationCanceledException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,24 +102,24 @@ private async Task ProcessModelStateChangeAsync()

try
{
var store = _serviceProvider.GetRequiredService<NavisworksDocumentModelStore>();
var basicBinding = _serviceProvider.GetRequiredService<IBasicConnectorBinding>();
var commands = (basicBinding as NavisworksBasicConnectorBinding)?.Commands;

switch (_finalModelCount)
{
case 0 when _priorModelCount > 0:
store.ClearAndSave();
break;
case > 0 when _priorModelCount == 0:
store.ReloadState();
break;
}

if (commands != null)
{
await commands.NotifyDocumentChanged().ConfigureAwait(false);
}
var store = _serviceProvider.GetRequiredService<NavisworksDocumentModelStore>();
var basicBinding = _serviceProvider.GetRequiredService<IBasicConnectorBinding>();
var commands = (basicBinding as NavisworksBasicConnectorBinding)?.Commands;

switch (_finalModelCount)
{
case 0 when _priorModelCount > 0:
store.ClearAndSave();
break;
case > 0 when _priorModelCount == 0:
store.ReloadState();
break;
}

if (commands != null)
{
await commands.NotifyDocumentChanged().ConfigureAwait(false);
}
}
finally
{
Expand Down

0 comments on commit 6ebcc3f

Please sign in to comment.