Skip to content

Commit

Permalink
Merge branch 'dui3/alpha' into revit-fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhathcock authored Jun 19, 2024
2 parents 055c077 + 8405135 commit 1b7baea
Show file tree
Hide file tree
Showing 17 changed files with 130 additions and 46 deletions.
1 change: 0 additions & 1 deletion Core/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
<PackageReference Include="Sentry.Serilog" Version="3.33.0"/>
<PackageReference Include="Serilog" Version="2.12.0"/>
<PackageReference Include="Serilog.Enrichers.ClientInfo" Version="1.3.0"/>
<PackageReference Include="Serilog.Enrichers.GlobalLogContext" Version="3.0.0"/>
<PackageReference Include="Serilog.Exceptions" Version="8.4.0"/>
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0"/>
<PackageReference Include="Serilog.Sinks.Seq" Version="5.2.2"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace Speckle.Connectors.ArcGIS.Bindings;

public class ArcGISSelectionBinding : ISelectionBinding
{
public string Name { get; } = "selectionBinding";
public IBridge Parent { get; set; }
public string Name => "selectionBinding";
public IBridge Parent { get; }

public ArcGISSelectionBinding(IBridge parent)
{
Expand All @@ -22,7 +22,7 @@ public ArcGISSelectionBinding(IBridge parent)
private void OnSelectionChanged(MapViewEventArgs args)
{
SelectionInfo selInfo = GetSelection();
Parent?.Send(SelectionBindingEvents.SET_SELECTION, selInfo);
Parent.Send(SelectionBindingEvents.SET_SELECTION, selInfo);
}

public SelectionInfo GetSelection()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ private void SelectMapMembersInTOC(List<MapMember> mapMembers)
{
if (member is Layer layer)
{
layers.Add(layer);
if (member is not GroupLayer) // group layer selection clears other layers selection
{
layers.Add(layer);
}
}
else if (member is StandaloneTable table)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ CancellationToken cancellationToken
{
if (IsGISType(obj))
{
string nestedLayerPath = $"{string.Join("\\", path)}\\{((Collection)obj).name}";
string nestedLayerPath = $"{string.Join("\\", path)}";
string datasetId = (string)_converter.Convert(obj);
conversionTracker[ctx] = new ObjectConversionTracker(obj, nestedLayerPath, datasetId);
}
Expand All @@ -92,10 +92,17 @@ CancellationToken cancellationToken
onOperationProgressed?.Invoke("Writing to Database", null);
_nonGisFeaturesUtils.WriteGeometriesToDatasets(conversionTracker);

// Create main group layer
Dictionary<string, GroupLayer> createdLayerGroups = new();
Map map = _contextStack.Current.Document.Map;
GroupLayer groupLayer = LayerFactory.Instance.CreateGroupLayer(map, 0, $"{projectName}: {modelName}");
createdLayerGroups["Basic Speckle Group"] = groupLayer; // key doesn't really matter here

// 3. add layer and tables to the Table Of Content
int bakeCount = 0;
Dictionary<string, MapMember> bakedMapMembers = new();
onOperationProgressed?.Invoke("Adding to Map", bakeCount);

foreach (var item in conversionTracker)
{
cancellationToken.ThrowIfCancellationRequested();
Expand All @@ -120,7 +127,7 @@ CancellationToken cancellationToken
else
{
// add layer and layer URI to tracker
MapMember mapMember = AddDatasetsToMap(trackerItem);
MapMember mapMember = AddDatasetsToMap(trackerItem, createdLayerGroups);
trackerItem.AddConvertedMapMember(mapMember);
trackerItem.AddLayerURI(mapMember.URI);
conversionTracker[item.Key] = trackerItem;
Expand All @@ -133,6 +140,7 @@ CancellationToken cancellationToken
}
onOperationProgressed?.Invoke("Adding to Map", (double)++bakeCount / conversionTracker.Count);
}
bakedObjectIds.AddRange(createdLayerGroups.Values.Select(x => x.URI));

// TODO: validated a correct set regarding bakedobject ids
return new(bakedObjectIds, results);
Expand Down Expand Up @@ -160,37 +168,77 @@ private void AddResultsFromTracker(ObjectConversionTracker trackerItem, List<Rec
}
}

private MapMember AddDatasetsToMap(ObjectConversionTracker trackerItem)
private MapMember AddDatasetsToMap(
ObjectConversionTracker trackerItem,
Dictionary<string, GroupLayer> createdLayerGroups
)
{
// get layer details
string? datasetId = trackerItem.DatasetId; // should not ne null here
Uri uri = new($"{_contextStack.Current.Document.SpeckleDatabasePath.AbsolutePath.Replace('/', '\\')}\\{datasetId}");
string nestedLayerName = trackerItem.NestedLayerName;

Uri uri = new($"{_contextStack.Current.Document.SpeckleDatabasePath.AbsolutePath.Replace('/', '\\')}\\{datasetId}");
Map map = _contextStack.Current.Document.Map;
// add group for the current layer
string shortName = nestedLayerName.Split("\\")[^1];
string nestedLayerPath = string.Join("\\", nestedLayerName.Split("\\").SkipLast(1));

GroupLayer groupLayer = CreateNestedGroupLayer(nestedLayerPath, createdLayerGroups);

// Most of the Speckle-written datasets will be containing geometry and added as Layers
// although, some datasets might be just tables (e.g. native GIS Tables, in the future maybe Revit schedules etc.
// We can create a connection to the dataset in advance and determine its type, but this will be more
// expensive, than assuming by default that it's a layer with geometry (which in most cases it's expected to be)
try
{
var layer = LayerFactory.Instance.CreateLayer(uri, map, layerName: nestedLayerName);
var layer = LayerFactory.Instance.CreateLayer(uri, groupLayer, layerName: shortName);
layer.SetExpanded(true);
return layer;
}
catch (ArgumentException)
{
var table = StandaloneTableFactory.Instance.CreateStandaloneTable(uri, map, tableName: nestedLayerName);
var table = StandaloneTableFactory.Instance.CreateStandaloneTable(uri, groupLayer, tableName: shortName);
return table;
}
}

private GroupLayer CreateNestedGroupLayer(string nestedLayerPath, Dictionary<string, GroupLayer> createdLayerGroups)
{
GroupLayer lastGroup = createdLayerGroups.FirstOrDefault().Value;
if (lastGroup == null) // if layer not found
{
throw new InvalidOperationException("Speckle Layer Group not found");
}

// iterate through each nested level
string createdGroupPath = "";
var allPathElements = nestedLayerPath.Split("\\").Where(x => !string.IsNullOrEmpty(x));
foreach (string pathElement in allPathElements)
{
createdGroupPath += "\\" + pathElement;
if (createdLayerGroups.TryGetValue(createdGroupPath, out var existingGroupLayer))
{
lastGroup = existingGroupLayer;
}
else
{
// create new GroupLayer under last found Group, named with last pathElement
lastGroup = LayerFactory.Instance.CreateGroupLayer(lastGroup, 0, pathElement);
lastGroup.SetExpanded(true);
}
createdLayerGroups[createdGroupPath] = lastGroup;
}
return lastGroup;
}

[Pure]
private static string[] GetLayerPath(TraversalContext context)
{
string[] collectionBasedPath = context.GetAscendantOfType<Collection>().Select(c => c.name).ToArray();
string[] reverseOrderPath =
collectionBasedPath.Length != 0 ? collectionBasedPath : context.GetPropertyPath().ToArray();
return reverseOrderPath.Reverse().ToArray();

var originalPath = reverseOrderPath.Reverse().ToArray();
return originalPath.Where(x => !string.IsNullOrEmpty(x)).ToArray();
}

[Pure]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ public class AutocadSelectionBinding : ISelectionBinding
{
private const string SELECTION_EVENT = "setSelection";

private readonly List<Document> _visitedDocuments = new();

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

private readonly HashSet<Document> _visitedDocuments = new();
public string Name => "selectionBinding";
public IBridge Parent { get; }

public AutocadSelectionBinding(IBridge parent)
Expand All @@ -26,9 +24,9 @@ public AutocadSelectionBinding(IBridge parent)
Application.DocumentManager.DocumentActivated += (sender, e) => OnDocumentChanged(e.Document);
}

private void OnDocumentChanged(Document document) => TryRegisterDocumentForSelection(document);
private void OnDocumentChanged(Document? document) => TryRegisterDocumentForSelection(document);

private void TryRegisterDocumentForSelection(Document document)
private void TryRegisterDocumentForSelection(Document? document)
{
if (document == null)
{
Expand All @@ -49,13 +47,13 @@ private void TryRegisterDocumentForSelection(Document document)
private void OnSelectionChanged()
{
SelectionInfo selInfo = GetSelection();
Parent?.Send(SELECTION_EVENT, selInfo);
Parent.Send(SELECTION_EVENT, selInfo);
}

public SelectionInfo GetSelection()
{
// POC: Will be addressed to move it into AutocadContext! https://spockle.atlassian.net/browse/CNX-9319
Document doc = Application.DocumentManager.MdiActiveDocument;
Document? doc = Application.DocumentManager.MdiActiveDocument;
List<string> objs = new();
List<string> objectTypes = new();
if (doc != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Speckle.Connectors.Autocad.Bindings;

public sealed class AutocadSendBinding : ISendBinding
{
public string Name { get; } = "sendBinding";
public string Name => "sendBinding";
public SendBindingUICommands Commands { get; }
public IBridge Parent { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ namespace Speckle.Connectors.Revit.Bindings;
internal abstract class RevitBaseBinding : IBinding
{
// POC: name and bridge might be better for them to be protected props?
public string Name { get; protected set; }
public IBridge Parent { get; protected set; }
public string Name { get; }
public IBridge Parent { get; }

protected readonly DocumentModelStore Store;
protected readonly RevitContext RevitContext;

public RevitBaseBinding(string name, DocumentModelStore store, IBridge bridge, RevitContext revitContext)
protected RevitBaseBinding(string name, DocumentModelStore store, IBridge bridge, RevitContext revitContext)
{
Name = name;
Parent = bridge;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace Speckle.Connectors.Rhino7.Bindings;

public class RhinoBasicConnectorBinding : IBasicConnectorBinding
{
public string Name { get; set; } = "baseBinding";
public IBridge Parent { get; set; }
public string Name => "baseBinding";
public IBridge Parent { get; }
public BasicConnectorBindingCommands Commands { get; }

private readonly DocumentModelStore _store;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ namespace Speckle.Connectors.Rhino7.Bindings;

public class RhinoReceiveBinding : IReceiveBinding
{
public string Name { get; set; } = "receiveBinding";
public IBridge Parent { get; set; }
public string Name => "receiveBinding";
public IBridge Parent { get; }

private readonly CancellationManager _cancellationManager;
private readonly DocumentModelStore _store;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ namespace Speckle.Connectors.Rhino7.Bindings;

public sealed class RhinoSendBinding : ISendBinding
{
public string Name { get; } = "sendBinding";
public string Name => "sendBinding";
public SendBindingUICommands Commands { get; }
public IBridge Parent { get; set; }
public IBridge Parent { get; }

private readonly DocumentModelStore _store;
private readonly RhinoIdleManager _idleManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ArcGISConverterModule : ISpeckleModule
public void Load(SpeckleContainerBuilder builder)
{
//don't need a host specific RootToSpeckleConverter
builder.AddConverterCommon<RootToSpeckleConverter, ArcGISToSpeckleUnitConverter, Unit>();
builder.AddConverterCommon<LegacyRootToSpeckleConverter, ArcGISToSpeckleUnitConverter, Unit>();
// most things should be InstancePerLifetimeScope so we get one per operation
builder.AddScoped<IFeatureClassUtils, FeatureClassUtils>();
builder.AddScoped<IArcGISFieldUtils, ArcGISFieldUtils>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,6 @@
"Serilog": "2.4.0"
}
},
"Serilog.Enrichers.GlobalLogContext": {
"type": "Transitive",
"resolved": "3.0.0",
"contentHash": "IIZcj5mAUVhIl/NTA+YI2KC+sPDzcwvs0ZMHH42jsPfl1a4LVX7ohVpw5UK+e3GxuV3Nv239Il5oM2peUIl44g==",
"dependencies": {
"Serilog": "2.12.0"
}
},
"Serilog.Exceptions": {
"type": "Transitive",
"resolved": "8.4.0",
Expand Down Expand Up @@ -529,7 +521,6 @@
"Sentry.Serilog": "[3.33.0, )",
"Serilog": "[2.12.0, )",
"Serilog.Enrichers.ClientInfo": "[1.3.0, )",
"Serilog.Enrichers.GlobalLogContext": "[3.0.0, )",
"Serilog.Exceptions": "[8.4.0, )",
"Serilog.Sinks.Console": "[4.1.0, )",
"Serilog.Sinks.Seq": "[5.2.2, )",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class RhinoConverterModule : ISpeckleModule
{
public void Load(SpeckleContainerBuilder builder)
{
builder.AddConverterCommon<RootToSpeckleConverter, RhinoToSpeckleUnitConverter, UnitSystem>();
builder.AddConverterCommon<LegacyRootToSpeckleConverter, RhinoToSpeckleUnitConverter, UnitSystem>();
// single stack per conversion
builder.AddScoped<IConversionContextStack<RhinoDoc, UnitSystem>, RhinoConversionContextStack>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace Speckle.Connectors.DUI.Bindings;

public class AccountBinding : IBinding
{
public string Name { get; set; } = "accountsBinding";
public IBridge Parent { get; private set; }
public string Name => "accountsBinding";
public IBridge Parent { get; }

public AccountBinding(IBridge bridge)
{
Expand Down
4 changes: 2 additions & 2 deletions DUI3-DX/DUI3/Speckle.Connectors.DUI/Bindings/TestBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace Speckle.Connectors.DUI.Bindings;
/// </summary>
public class TestBinding : IBinding
{
public string Name { get; set; } = "testBinding";
public IBridge Parent { get; private set; }
public string Name => "testBinding";
public IBridge Parent { get; }

public TestBinding(IBridge bridge)
{
Expand Down
8 changes: 8 additions & 0 deletions DUI3-DX/Sdk/Speckle.Connectors.Utils/NotNullExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Speckle.Connectors.Utils;

public static class NotNullExtensions
{
/// <inheritdoc cref="NotNull{T}(T?,string?)"/>
public static async Task<T> NotNull<T>(
this Task<T?> task,
[CallerArgumentExpression(nameof(task))] string? message = null
Expand All @@ -19,6 +20,7 @@ public static async Task<T> NotNull<T>(
return x;
}

/// <inheritdoc cref="NotNull{T}(T?,string?)"/>
public static async Task<T> NotNull<T>(
this Task<T?> task,
[CallerArgumentExpression(nameof(task))] string? message = null
Expand All @@ -33,6 +35,11 @@ public static async Task<T> NotNull<T>(
return x.Value;
}

/// <param name="obj">the object to check for null</param>
/// <param name="paramName">see <see cref="CallerArgumentExpressionAttribute"/></param>
/// <typeparam name="T"><paramref name="obj"/> type</typeparam>
/// <returns>A non null <typeparamref name="T"/> value</returns>
/// <exception cref="ArgumentNullException"><paramref name="obj"/> was null</exception>
public static T NotNull<T>([NotNull] this T? obj, [CallerArgumentExpression(nameof(obj))] string? paramName = null)
where T : class
{
Expand All @@ -43,6 +50,7 @@ public static T NotNull<T>([NotNull] this T? obj, [CallerArgumentExpression(name
return obj;
}

/// <inheritdoc cref="NotNull{T}(T?,string?)"/>
public static T NotNull<T>([NotNull] this T? obj, [CallerArgumentExpression(nameof(obj))] string? paramName = null)
where T : struct
{
Expand Down
Loading

0 comments on commit 1b7baea

Please sign in to comment.