Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dui3/alpha' into dui3/ci/github-…
Browse files Browse the repository at this point in the history
…actions-test
  • Loading branch information
adamhathcock committed May 21, 2024
2 parents 9c7377f + 055c3b6 commit 68670f0
Show file tree
Hide file tree
Showing 233 changed files with 1,445 additions and 1,535 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void Load(SpeckleContainerBuilder builder)
builder.AddSingleton<IBinding, ArcGISReceiveBinding>();

builder.AddTransient<ISendFilter, ArcGISSelectionFilter>();
builder.AddScoped<IHostObjectBuilder, HostObjectBuilder>();
builder.AddScoped<IHostObjectBuilder, ArcGISHostObjectBuilder>();
builder.AddSingleton(DefaultTraversal.CreateTraversalFunc());

// register send operation and dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@

namespace Speckle.Connectors.ArcGIS.Operations.Receive;

public class HostObjectBuilder : IHostObjectBuilder
public class ArcGISHostObjectBuilder : IHostObjectBuilder
{
private readonly ISpeckleConverterToHost _toHostConverter;
private readonly IRootToHostConverter _converter;
private readonly IArcGISProjectUtils _arcGISProjectUtils;
private readonly INonNativeFeaturesUtils _nonGisFeaturesUtils;

// POC: figure out the correct scope to only initialize on Receive
private readonly IConversionContextStack<Map, Unit> _contextStack;
private readonly GraphTraversal _traverseFunction;

public HostObjectBuilder(
ISpeckleConverterToHost toHostConverter,
public ArcGISHostObjectBuilder(
IRootToHostConverter converter,
IArcGISProjectUtils arcGISProjectUtils,
IConversionContextStack<Map, Unit> contextStack,
INonNativeFeaturesUtils nonGisFeaturesUtils,
GraphTraversal traverseFunction
)
{
_toHostConverter = toHostConverter;
_converter = converter;
_arcGISProjectUtils = arcGISProjectUtils;
_contextStack = contextStack;
_nonGisFeaturesUtils = nonGisFeaturesUtils;
Expand All @@ -44,7 +44,7 @@ GraphTraversal traverseFunction
List<string> objectIds
)
{
Geometry converted = (Geometry)_toHostConverter.Convert(obj);
Geometry converted = (Geometry)_converter.Convert(obj);
objectIds.Add(obj.id);
List<string> objPath = path.ToList();
objPath.Add(obj.speckle_type.Split(".")[^1]);
Expand All @@ -53,7 +53,7 @@ List<string> objectIds

public (string, string) ConvertNativeLayers(Base obj, string[] path, List<string> objectIds)
{
string converted = (string)_toHostConverter.Convert(obj);
string converted = (string)_converter.Convert(obj);
objectIds.Add(obj.id);
string objPath = $"{string.Join("\\", path)}\\{((Collection)obj).name}";
return (objPath, converted);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private Collection ConvertObjects(
{
// POC: does this feel like the right place? I am wondering if this should be called from within send/rcv?
// begin the unit of work
using var uow = _unitOfWorkFactory.Resolve<ISpeckleConverterToSpeckle>();
using var uow = _unitOfWorkFactory.Resolve<IRootToSpeckleConverter>();
var converter = uow.Service;

// var rootObjectCollection = new Collection { name = RhinoDoc.ActiveDoc.Name ?? "Unnamed document" };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,14 @@ public void HighlightModel(string modelCardId)

if (model is SenderModelCard senderModelCard)
{
List<(DBObject obj, string applicationId)> dbObjects = doc.GetObjects(
senderModelCard.SendFilter.NotNull().GetObjectIds()
);
objectIds = dbObjects.Select(tuple => tuple.obj.Id).ToArray();
var dbObjects = doc.GetObjects(senderModelCard.SendFilter.NotNull().GetObjectIds());
objectIds = dbObjects.Select(tuple => tuple.Root.Id).ToArray();
}

if (model is ReceiverModelCard receiverModelCard)
{
List<(DBObject obj, string applicationId)> dbObjects = doc.GetObjects(
(receiverModelCard.ReceiveResult?.BakedObjectIds).NotNull()
);
objectIds = dbObjects.Select(tuple => tuple.obj.Id).ToArray();
var dbObjects = doc.GetObjects((receiverModelCard.ReceiveResult?.BakedObjectIds).NotNull());
objectIds = dbObjects.Select(tuple => tuple.Root.Id).ToArray();
}

if (objectIds.Length == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Speckle.Connectors.Utils.Cancellation;
using Speckle.Core.Logging;
using Speckle.Autofac.DependencyInjection;
using Speckle.Connectors.Autocad.Operations.Send;
using Speckle.Connectors.Utils.Operations;
using Speckle.Core.Models;
using ICancelable = System.Reactive.Disposables.ICancelable;
Expand Down Expand Up @@ -121,7 +122,7 @@ private async Task SendInternal(string modelCardId)
{
try
{
using var uow = _unitOfWorkFactory.Resolve<SendOperation<(DBObject obj, string applicationId)>>();
using var uow = _unitOfWorkFactory.Resolve<SendOperation<AutocadRootObject>>();
// 0 - Init cancellation token source -> Manager also cancel it if exist before
CancellationTokenSource cts = _cancellationManager.InitCancellationTokenSource(modelCardId);

Expand All @@ -132,8 +133,9 @@ private async Task SendInternal(string modelCardId)
}

// Get elements to convert
List<(DBObject obj, string applicationId)> autocadObjects =
Application.DocumentManager.CurrentDocument.GetObjects(modelCard.SendFilter.NotNull().GetObjectIds());
List<AutocadRootObject> autocadObjects = Application.DocumentManager.CurrentDocument.GetObjects(
modelCard.SendFilter.NotNull().GetObjectIds()
);
if (autocadObjects.Count == 0)
{
throw new InvalidOperationException("No objects were found. Please update your send filter!");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Autodesk.AutoCAD.DatabaseServices;
using Speckle.Autofac;
using Speckle.Autofac.DependencyInjection;
using Speckle.Connectors.Autocad.Bindings;
Expand All @@ -16,8 +15,6 @@
using Speckle.Connectors.Utils;
using Speckle.Connectors.Utils.Builders;
using Speckle.Connectors.Utils.Operations;
using Speckle.Converters.Autocad;
using Speckle.Converters.Common;
using Speckle.Core.Models.GraphTraversal;

namespace Speckle.Connectors.Autocad.DependencyInjection;
Expand All @@ -41,12 +38,12 @@ public void Load(SpeckleContainerBuilder builder)
builder.AddSingleton<AutocadIdleManager>();

// Operations
builder.AddScoped<SendOperation<(DBObject obj, string applicationId)>>();
builder.AddScoped<SendOperation<AutocadRootObject>>();
builder.AddSingleton(DefaultTraversal.CreateTraversalFunc());

// Object Builders
builder.AddScoped<IHostObjectBuilder, HostObjectBuilder>();
builder.AddSingleton<IRootObjectBuilder<(DBObject obj, string applicationId)>, RootObjectBuilder>();
builder.AddScoped<IHostObjectBuilder, AutocadHostObjectBuilder>();
builder.AddSingleton<IRootObjectBuilder<AutocadRootObject>, AutocadRootObjectBuilder>();

// Register bindings

Expand All @@ -59,8 +56,6 @@ public void Load(SpeckleContainerBuilder builder)
builder.AddSingleton<IBinding, AutocadSendBinding>();
builder.AddSingleton<IBinding, AutocadReceiveBinding>();

builder.AddSingleton<IHostToSpeckleUnitConverter<UnitsValue>, AutocadToSpeckleUnitConverter>();

// register send filters
builder.AddTransient<ISendFilter, AutocadSelectionFilter>();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using Autodesk.AutoCAD.DatabaseServices;
using Speckle.Connectors.Autocad.Operations.Send;

namespace Speckle.Connectors.Autocad.HostApp.Extensions;

public static class DocumentExtensions
{
public static List<(DBObject, string)> GetObjects(this Document doc, IEnumerable<string> objectIds)
public static List<AutocadRootObject> GetObjects(this Document doc, IEnumerable<string> objectIds)
{
List<(DBObject, string)> objects = new();
List<AutocadRootObject> objects = new();
using (TransactionContext.StartTransaction(doc))
{
Transaction tr = doc.Database.TransactionManager.TopTransaction;
Expand All @@ -20,7 +21,7 @@ public static class DocumentExtensions
{
if (tr.GetObject(myObjectId, OpenMode.ForRead) is DBObject dbObject)
{
objects.Add((dbObject, objectIdHandle));
objects.Add(new(dbObject, objectIdHandle));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

namespace Speckle.Connectors.Autocad.Operations.Receive;

public class HostObjectBuilder : IHostObjectBuilder
public class AutocadHostObjectBuilder : IHostObjectBuilder
{
private readonly ISpeckleConverterToHost _converter;
private readonly IRootToHostConverter _converter;
private readonly AutocadLayerManager _autocadLayerManager;
private readonly GraphTraversal _traversalFunction;

public HostObjectBuilder(
ISpeckleConverterToHost converter,
public AutocadHostObjectBuilder(
IRootToHostConverter converter,
AutocadLayerManager autocadLayerManager,
GraphTraversal traversalFunction
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using Autodesk.AutoCAD.DatabaseServices;

namespace Speckle.Connectors.Autocad.Operations.Send;

public record AutocadRootObject(DBObject Root, string ApplicationId);
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@

namespace Speckle.Connectors.Autocad.Operations.Send;

public class RootObjectBuilder : IRootObjectBuilder<(DBObject obj, string applicationId)>
public class AutocadRootObjectBuilder : IRootObjectBuilder<AutocadRootObject>
{
private readonly ISpeckleConverterToSpeckle _converter;
private readonly IRootToSpeckleConverter _converter;
private readonly string[] _documentPathSeparator = { "\\" };

public RootObjectBuilder(ISpeckleConverterToSpeckle converter)
public AutocadRootObjectBuilder(IRootToSpeckleConverter converter)
{
_converter = converter;
}

public Base Build(
IReadOnlyList<(DBObject obj, string applicationId)> objects,
IReadOnlyList<AutocadRootObject> objects,
SendInfo sendInfo,
Action<string, double?>? onOperationProgressed = null,
CancellationToken ct = default
Expand All @@ -39,13 +39,10 @@ public Base Build(
Dictionary<string, Collection> collectionCache = new();
int count = 0;

foreach ((DBObject obj, string applicationId) tuple in objects)
foreach (var (root, applicationId) in objects)
{
ct.ThrowIfCancellationRequested();

var dbObject = tuple.obj;
var applicationId = tuple.applicationId;

try
{
Base converted;
Expand All @@ -58,7 +55,7 @@ public Base Build(
}
else
{
converted = _converter.Convert(dbObject);
converted = _converter.Convert(root);

if (converted == null)
{
Expand All @@ -69,7 +66,7 @@ public Base Build(
}

// Create and add a collection for each layer if not done so already.
if ((tuple.obj as Entity)?.Layer is string layer)
if ((root as Entity)?.Layer is string layer)
{
if (!collectionCache.TryGetValue(layer, out Collection? collection))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
<Compile Include="$(MSBuildThisFileDirectory)HostApp\Extensions\EditorExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HostApp\Extensions\EntityExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HostApp\TransactionContext.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Operations\Receive\HostObjectBuilder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Operations\Send\RootObjectBuilder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Operations\Receive\AutocadHostObjectBuilder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Operations\Send\AutocadRootObject.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Operations\Send\AutocadRootObjectBuilder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Plugin\AutocadExtensionApplication.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Plugin\AutocadPlugin.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interfaces\IAutocadPlugin.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ public void Load(SpeckleContainerBuilder builder)

// send operation and dependencies
builder.AddScoped<SendOperation<ElementId>>();
builder.AddScoped<IRootObjectBuilder<ElementId>, RootObjectBuilder>();
builder.AddScoped<IRootObjectBuilder<ElementId>, RevitRootObjectBuilder>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,17 @@

namespace Speckle.Connectors.Revit.Operations.Send;

public class RootObjectBuilder : IRootObjectBuilder<ElementId>
public class RevitRootObjectBuilder : IRootObjectBuilder<ElementId>
{
// POC: SendSelection and RevitConversionContextStack should be interfaces, former needs interfaces
private readonly ISpeckleConverterToSpeckle _converter;
private readonly ToSpeckleConvertedObjectsCache _convertedObjectsCache;
private readonly IRootToSpeckleConverter _converter;
private readonly IRevitConversionContextStack _contextStack;
private readonly Dictionary<string, Collection> _collectionCache;
private readonly Collection _rootObject;

public RootObjectBuilder(
ISpeckleConverterToSpeckle converter,
ToSpeckleConvertedObjectsCache convertedObjectsCache,
IRevitConversionContextStack contextStack
)
public RevitRootObjectBuilder(IRootToSpeckleConverter converter, IRevitConversionContextStack contextStack)
{
_converter = converter;
// POC: needs considering if this is something to add now or needs refactoring
_convertedObjectsCache = convertedObjectsCache;
_contextStack = contextStack;

// Note, this class is instantiated per unit of work (aka per send operation), so we can safely initialize what we need in here.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
<Compile Include="$(MSBuildThisFileDirectory)HostApp\IdStorageSchema.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HostApp\IStorageSchema.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HostApp\RevitDocumentStore.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DependencyInjection\RevitConnectorShared.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Operations\Send\RootObjectBuilder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DependencyInjection\RevitConnectorModule.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Operations\Send\RevitRootObjectBuilder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Plugin\CefSharpPanel.xaml.cs">
<DependentUpon>CefSharpPanel.xaml</DependentUpon>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ public void Load(SpeckleContainerBuilder builder)
builder.AddScoped<SendOperation<RhinoObject>>();
builder.AddSingleton(DefaultTraversal.CreateTraversalFunc());

builder.AddSingleton<IRootObjectBuilder<RhinoObject>, RootObjectBuilder>();
builder.AddSingleton<IRootObjectBuilder<RhinoObject>, RhinoRootObjectBuilder>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ namespace Speckle.Connectors.Rhino7.Operations.Receive;

public class RhinoHostObjectBuilder : IHostObjectBuilder
{
private readonly ISpeckleConverterToHost _toHostConverter;
private readonly IRootToHostConverter _converter;
private readonly IConversionContextStack<RhinoDoc, UnitSystem> _contextStack;
private readonly GraphTraversal _traverseFunction;

public RhinoHostObjectBuilder(
ISpeckleConverterToHost toHostConverter,
IRootToHostConverter converter,
IConversionContextStack<RhinoDoc, UnitSystem> contextStack,
GraphTraversal traverseFunction
)
{
_toHostConverter = toHostConverter;
_converter = converter;
_contextStack = contextStack;
_traverseFunction = traverseFunction;
}
Expand Down Expand Up @@ -106,7 +106,7 @@ CancellationToken cancellationToken

onOperationProgressed?.Invoke("Converting & creating objects", (double)++count / objects.Count);

var result = _toHostConverter.Convert(baseObj);
var result = _converter.Convert(baseObj);

var conversionIds = HandleConversionResult(result, baseObj, layerIndex);
newObjectIds.AddRange(conversionIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ namespace Speckle.Connectors.Rhino7.Operations.Send;
/// <summary>
/// Stateless builder object to turn an <see cref="ISendFilter"/> into a <see cref="Base"/> object
/// </summary>
public class RootObjectBuilder : IRootObjectBuilder<RhinoObject>
public class RhinoRootObjectBuilder : IRootObjectBuilder<RhinoObject>
{
private readonly IUnitOfWorkFactory _unitOfWorkFactory;

public RootObjectBuilder(IUnitOfWorkFactory unitOfWorkFactory)
public RhinoRootObjectBuilder(IUnitOfWorkFactory unitOfWorkFactory)
{
_unitOfWorkFactory = unitOfWorkFactory;
}
Expand Down Expand Up @@ -48,7 +48,7 @@ private Collection ConvertObjects(
{
// POC: does this feel like the right place? I am wondering if this should be called from within send/rcv?
// begin the unit of work
using var uow = _unitOfWorkFactory.Resolve<ISpeckleConverterToSpeckle>();
using var uow = _unitOfWorkFactory.Resolve<IRootToSpeckleConverter>();
var converter = uow.Service;

var rootObjectCollection = new Collection { name = RhinoDoc.ActiveDoc.Name ?? "Unnamed document" };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public class ArcGISConverterModule : ISpeckleModule
{
public void Load(SpeckleContainerBuilder builder)
{
builder.AddConverterCommon();
//don't need a host specific RootToSpeckleConverter
builder.AddConverterCommon<RootToSpeckleConverter, ArcGISToSpeckleUnitConverter, Unit>();
// most things should be InstancePerLifetimeScope so we get one per operation
builder.AddScoped<ISpeckleConverterToSpeckle, ArcGISConverterToSpeckle>();
builder.AddScoped<IFeatureClassUtils, FeatureClassUtils>();
builder.AddScoped<IArcGISFieldUtils, ArcGISFieldUtils>();
builder.AddScoped<ICharacterCleaner, CharacterCleaner>();
Expand Down
Loading

0 comments on commit 68670f0

Please sign in to comment.