Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blocks POC (Rhino, Acad) #3519

Merged
merged 30 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9c65d1a
feat(dui3): adds instance def and instance proxy classes to core
didimitrie Jun 11, 2024
0648654
feat(dui3): rhino blocks send wip
didimitrie Jun 11, 2024
6313b22
feat(dui3): wip (works!) rhino blocks send & receive
didimitrie Jun 11, 2024
43471a2
some cleanup
didimitrie Jun 12, 2024
0c07f75
wip fixes
didimitrie Jun 12, 2024
4137515
wip cleanup
didimitrie Jun 12, 2024
96be32d
wip scaffolds acad
didimitrie Jun 12, 2024
2eb1f93
Merge branch 'dui3/alpha' into dim/dui3/blocks-poc
didimitrie Jun 13, 2024
1e92a17
wip acad send instances and co
didimitrie Jun 14, 2024
6d3b3db
wip acad - getting close to wrapping up send
didimitrie Jun 14, 2024
31da29f
wip - units
didimitrie Jun 15, 2024
c69a781
feat(dui3): blocks poc wip: adds rhino layer manager, moves instance …
didimitrie Jun 16, 2024
5c1c560
feat(dui3): blocks poc WIP - acad receive
didimitrie Jun 16, 2024
4460265
wip acad instance receives
didimitrie Jun 16, 2024
f6ff940
acad blocks - receive ok
didimitrie Jun 16, 2024
e08d946
feat(dui3): acad receive blocks ✅
didimitrie Jun 16, 2024
6cca93d
feat(dui3): blocks poc minor refactors
didimitrie Jun 16, 2024
97d3f65
feat(dui3): acad blocks proper cleanup
didimitrie Jun 16, 2024
ba4556e
feat(dui3): blocks poc ready(ish) rhino & acad
didimitrie Jun 17, 2024
850eef8
Merge branch 'dui3/alpha' into dim/dui3/blocks-poc
didimitrie Jun 17, 2024
6ae0a3f
chore(dui3): reverts accidental change
didimitrie Jun 17, 2024
bfd5d21
feat(dui3): adds comments/docs
didimitrie Jun 17, 2024
536fc6e
chore(dui3): comments
didimitrie Jun 18, 2024
3991441
fix(dui3): throws ex upwards
didimitrie Jun 24, 2024
6ffe054
fix(dui3): blocks correctly handled in acad
didimitrie Jun 25, 2024
844dd02
Merge branch 'dui3/alpha' into dim/dui3/blocks-poc
didimitrie Jun 26, 2024
0ee51df
Merge branch 'dui3/alpha' into dim/dui3/blocks-poc
adamhathcock Jun 27, 2024
33b2614
Merge remote-tracking branch 'origin/dui3/alpha' into dim/dui3/blocks…
adamhathcock Jun 27, 2024
88cb939
update core reference and fix to not use interfaces
adamhathcock Jun 27, 2024
52d1c65
remove extra files
adamhathcock Jun 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
#if AUTOCAD
using Autodesk.AutoCAD.DatabaseServices;
using Speckle.Autofac;
using Speckle.Autofac.DependencyInjection;
using Speckle.Connectors.Autocad.Bindings;
using Speckle.Connectors.Autocad.Filters;
using Speckle.Connectors.Autocad.HostApp;
using Speckle.Connectors.Autocad.Interfaces;
using Speckle.Connectors.Autocad.Operations.Receive;
using Speckle.Connectors.Autocad.Operations.Send;
using Speckle.Connectors.Autocad.Plugin;
using Speckle.Connectors.DUI;
using Speckle.Connectors.DUI.Bindings;
using Speckle.Connectors.DUI.Models;
using Speckle.Connectors.DUI.Models.Card.SendFilter;
using Speckle.Connectors.DUI.WebView;
using Speckle.Connectors.Utils;
using Speckle.Connectors.Utils.Builders;
using Speckle.Connectors.Utils.Caching;
using Speckle.Connectors.Utils.Instances;
Expand All @@ -32,6 +40,9 @@ public void Load(SpeckleContainerBuilder builder)
builder.AddSingleton<AutocadContext>();
builder.AddSingleton<AutocadIdleManager>();

SharedConnectorModule.LoadShared(builder);


builder.AddScoped<AutocadLayerManager>();

// Operations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ ITopLevelExceptionHandler topLevelExceptionHandler

private void SubscribeToRhinoEvents()
{
// POC: It is unclear to me why is the binding keeping track of ChangedObjectIds. Change tracking should be moved to a separate type.
RhinoDoc.LayerTableEvent += (_, _) =>
{
Commands.RefreshSendFilters();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Speckle.Core.Logging;
using Speckle.Core.Models;
using Speckle.Core.Models.Instances;
using Speckle.Rhino7.Interfaces;

namespace Speckle.Connectors.Rhino7.HostApp;

Expand All @@ -19,15 +20,15 @@ namespace Speckle.Connectors.Rhino7.HostApp;
/// </summary>
public class RhinoInstanceObjectsManager : IInstanceObjectsManager<RhinoObject, List<string>>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are into Rhino now and my brain is melting and it's probably worth considering my ACAD comments first.

Also I wonder if these can be made to be more DRY though I suspect not, maybe that's one for later IF

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They could be with an abstract class in between, but i'd settle with them as they are as "good enough" for now. We'd need to test this against other host apps to fully understand the patterns at play first (eg., tekla, revit)

{
private readonly IConversionContextStack<RhinoDoc, UnitSystem> _contextStack;
private readonly IConversionContextStack<IRhinoDoc, RhinoUnitSystem> _contextStack;
private readonly Dictionary<string, InstanceProxy> _instanceProxies = new();
private readonly Dictionary<string, List<InstanceProxy>> _instanceProxiesByDefinitionId = new();
private readonly Dictionary<string, InstanceDefinitionProxy> _definitionProxies = new();
private readonly Dictionary<string, RhinoObject> _flatAtomicObjects = new();
private readonly RhinoLayerManager _layerManager;

public RhinoInstanceObjectsManager(
IConversionContextStack<RhinoDoc, UnitSystem> contextStack,
IConversionContextStack<IRhinoDoc, RhinoUnitSystem> contextStack,
RhinoLayerManager layerManager
)
{
Expand All @@ -52,14 +53,15 @@ private void UnpackInstance(InstanceObject instance, int depth = 0)
{
var instanceId = instance.Id.ToString();
var instanceDefinitionId = instance.InstanceDefinition.Id.ToString();
var currentDoc = RhinoDoc.ActiveDoc; // POC: too much right now to interface around
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have the ticket for this and drop that into the POC comment? This is easily unit testable and this would block that, we could make the ticket to complete this an add some unit tests


_instanceProxies[instanceId] = new InstanceProxy()
{
applicationId = instanceId,
DefinitionId = instance.InstanceDefinition.Id.ToString(),
Transform = XFormToMatrix(instance.InstanceXform),
MaxDepth = depth,
Units = _contextStack.Current.Document.ModelUnitSystem.ToSpeckleString()
Units = currentDoc.ModelUnitSystem.ToSpeckleString()
};

// For each block instance that has the same definition, we need to keep track of the "maximum depth" at which is found.
Expand Down Expand Up @@ -125,7 +127,9 @@ public BakeResult BakeInstances(
Action<string, double?>? onOperationProgressed
)
{
var doc = _contextStack.Current.Document;
// var doc = _contextStack.Current.Document;
var doc = RhinoDoc.ActiveDoc; // POC: too much right now to interface around

var sortedInstanceComponents = instanceComponents
.OrderByDescending(x => x.obj.MaxDepth) // Sort by max depth, so we start baking from the deepest element first
.ThenBy(x => x.obj is InstanceDefinitionProxy ? 0 : 1) // Ensure we bake the deepest definition first, then any instances that depend on it
Expand Down Expand Up @@ -214,11 +218,12 @@ instanceOrDefinition is InstanceProxy instanceProxy

public void PurgeInstances(string namePrefix)
{
foreach (var definition in _contextStack.Current.Document.InstanceDefinitions)
var currentDoc = RhinoDoc.ActiveDoc; // POC: too much right now to interface around
foreach (var definition in currentDoc.InstanceDefinitions)
{
if (!definition.IsDeleted && definition.Name.Contains(namePrefix))
{
_contextStack.Current.Document.InstanceDefinitions.Delete(definition.Index, true, false);
currentDoc.InstanceDefinitions.Delete(definition.Index, true, false);
}
}
}
Expand All @@ -228,10 +233,8 @@ private Matrix4x4 XFormToMatrix(Transform t) =>

private Transform MatrixToTransform(Matrix4x4 matrix, string units)
{
var conversionFactor = Units.GetConversionFactor(
units,
_contextStack.Current.Document.ModelUnitSystem.ToSpeckleString()
);
var currentDoc = RhinoDoc.ActiveDoc; // POC: too much right now to interface around
var conversionFactor = Units.GetConversionFactor(units, currentDoc.ModelUnitSystem.ToSpeckleString());

var t = Transform.Identity;
t.M00 = matrix.M11;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Speckle.Converters.Common;
using Speckle.Core.Models;
using Speckle.Core.Models.GraphTraversal;
using Speckle.Rhino7.Interfaces;

namespace Speckle.Connectors.Rhino7.HostApp;

Expand All @@ -12,11 +13,11 @@ namespace Speckle.Connectors.Rhino7.HostApp;
/// </summary>
public class RhinoLayerManager
{
private readonly IConversionContextStack<RhinoDoc, UnitSystem> _contextStack;
private readonly IConversionContextStack<IRhinoDoc, RhinoUnitSystem> _contextStack;
private readonly Dictionary<string, int> _hostLayerCache;
private readonly Dictionary<int, Collection> _layerCollectionCache;

public RhinoLayerManager(IConversionContextStack<RhinoDoc, UnitSystem> contextStack)
public RhinoLayerManager(IConversionContextStack<IRhinoDoc, RhinoUnitSystem> contextStack)
{
_contextStack = contextStack;
_hostLayerCache = new();
Expand All @@ -29,7 +30,8 @@ public RhinoLayerManager(IConversionContextStack<RhinoDoc, UnitSystem> contextSt
/// <param name="baseLayerName"></param>
public void CreateBaseLayer(string baseLayerName)
{
var index = _contextStack.Current.Document.Layers.Add(new Layer { Name = baseLayerName });
var index = RhinoDoc.ActiveDoc.Layers.Add(new Layer { Name = baseLayerName }); // POC: too much effort right now to wrap around the interfaced layers and doc
// var index = _contextStack.Current.Document.Layers.Add(new Layer { Name = baseLayerName });
_hostLayerCache.Add(baseLayerName, index);
}

Expand All @@ -48,7 +50,7 @@ public int GetAndCreateLayerFromPath(string[] path, string baseLayerName)
}

var currentLayerName = baseLayerName;
RhinoDoc currentDocument = _contextStack.Current.Document;
var currentDocument = RhinoDoc.ActiveDoc; // POC: too much effort right now to wrap around the interfaced layers

var previousLayer = currentDocument.Layers.FindName(currentLayerName);
foreach (var layerName in path)
Expand Down Expand Up @@ -77,7 +79,7 @@ public int GetAndCreateLayerFromPath(string[] path, string baseLayerName)
/// <param name="layer">The layer you want the equivalent collection for.</param>
/// <param name="rootObjectCollection">The root object that will be sent to Speckle, and will host all collections.</param>
/// <returns></returns>
public Collection GetHostObjectCollection(Layer layer, Collection rootObjectCollection)
public Collection GetHostObjectCollection(IRhinoLayer layer, Collection rootObjectCollection)
{
if (_layerCollectionCache.TryGetValue(layer.Index, out Collection value))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Rhino;
using Rhino.DocObjects;
using Rhino.Geometry;
using Speckle.Connectors.Rhino7.HostApp;
using Speckle.Connectors.Utils.Builders;
using Speckle.Connectors.Utils.Conversion;
Expand All @@ -10,6 +8,7 @@
using Speckle.Core.Models;
using Speckle.Core.Models.GraphTraversal;
using Speckle.Core.Models.Instances;
using Speckle.Rhino7.Interfaces;

namespace Speckle.Connectors.Rhino7.Operations.Receive;

Expand All @@ -21,22 +20,26 @@ public class RhinoHostObjectBuilder : IHostObjectBuilder
private readonly IRootToHostConverter _converter;
private readonly IConversionContextStack<IRhinoDoc, RhinoUnitSystem> _contextStack;
private readonly GraphTraversal _traverseFunction;

private readonly IInstanceObjectsManager<RhinoObject, List<string>> _instanceObjectsManager;
private readonly RhinoLayerManager _layerManager;
private readonly IRhinoDocFactory _rhinoDocFactory;

public RhinoHostObjectBuilder(
IRootToHostConverter converter,
IConversionContextStack<RhinoDoc, UnitSystem> contextStack,
IConversionContextStack<IRhinoDoc, RhinoUnitSystem> contextStack,
GraphTraversal traverseFunction,
RhinoLayerManager layerManager,
IInstanceObjectsManager<RhinoObject, List<string>> instanceObjectsManager
IInstanceObjectsManager<RhinoObject, List<string>> instanceObjectsManager,
IRhinoDocFactory rhinoDocFactory
)
{
_converter = converter;
_contextStack = contextStack;
_traverseFunction = traverseFunction;
_layerManager = layerManager;
_instanceObjectsManager = instanceObjectsManager;
_rhinoDocFactory = rhinoDocFactory;
}

public HostObjectBuilderResult Build(
Expand Down Expand Up @@ -77,9 +80,13 @@ private HostObjectBuilderResult BakeObjects(
Action<string, double?>? onOperationProgressed
)
{
RhinoDoc doc = _contextStack.Current.Document;
var doc = _contextStack.Current.Document;
var rootLayerIndex = _contextStack.Current.Document.Layers.Find(
Guid.Empty,
baseLayerName,
_rhinoDocFactory.UnsetIntIndex
);

var rootLayerIndex = _contextStack.Current.Document.Layers.Find(Guid.Empty, baseLayerName, RhinoMath.UnsetIntIndex);
PreReceiveDeepClean(baseLayerName, rootLayerIndex);
_layerManager.CreateBaseLayer(baseLayerName);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Diagnostics;
using Rhino.DocObjects;
using Rhino;
using Speckle.Core.Models;
using Speckle.Autofac.DependencyInjection;
using Speckle.Converters.Common;
Expand All @@ -12,6 +11,7 @@
using Speckle.Connectors.Utils.Instances;
using Speckle.Connectors.Utils.Operations;
using Speckle.Core.Logging;
using Speckle.Rhino7.Interfaces;

namespace Speckle.Connectors.Rhino7.Operations.Send;

Expand All @@ -23,13 +23,13 @@ public class RhinoRootObjectBuilder : IRootObjectBuilder<RhinoObject>
private readonly IUnitOfWorkFactory _unitOfWorkFactory;
private readonly ISendConversionCache _sendConversionCache;
private readonly IInstanceObjectsManager<RhinoObject, List<string>> _instanceObjectsManager;
private readonly IConversionContextStack<RhinoDoc, UnitSystem> _contextStack;
private readonly IConversionContextStack<IRhinoDoc, RhinoUnitSystem> _contextStack;
private readonly RhinoLayerManager _layerManager;

public RhinoRootObjectBuilder(
IUnitOfWorkFactory unitOfWorkFactory,
ISendConversionCache sendConversionCache,
IConversionContextStack<RhinoDoc, UnitSystem> contextStack,
IConversionContextStack<IRhinoDoc, RhinoUnitSystem> contextStack,
RhinoLayerManager layerManager,
IInstanceObjectsManager<RhinoObject, List<string>> instanceObjectsManager
)
Expand Down Expand Up @@ -78,7 +78,7 @@ private RootObjectBuilderResult ConvertObjects(
foreach (RhinoObject rhinoObject in atomicObjects)
{
cancellationToken.ThrowIfCancellationRequested();

// RhinoDoc.ActiveDoc.Layers
var layer = _contextStack.Current.Document.Layers[rhinoObject.Attributes.LayerIndex];

var collectionHost = _layerManager.GetHostObjectCollection(layer, rootObjectCollection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<ItemGroup>
<PackageReference Include="RhinoCommon" Version="7.13.21348.13001" IncludeAssets="compile;build" />
<PackageReference Include="RhinoWindows" Version="7.13.21348.13001" IncludeAssets="compile;build" />
<PackageReference Include="Speckle.Rhino7.Api" Version="0.1.1-preview.0.28" />
<PackageReference Include="Speckle.Rhino7.Interfaces" Version="0.1.1-preview.0.28" />
<PackageReference Include="Speckle.Rhino7.Api" Version="0.1.1-preview.0.29" />
<PackageReference Include="Speckle.Rhino7.Interfaces" Version="0.1.1-preview.0.29" />
<PackageReference Include="System.Resources.Extensions" Version="7.0.0"/>
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@
},
"Speckle.Rhino7.Api": {
"type": "Direct",
"requested": "[0.1.1-preview.0.28, )",
"resolved": "0.1.1-preview.0.28",
"contentHash": "AE+1lMl+lzwEdNn6kvEWuCy6wRSFAIYP0KXeGI8fECNsCBj023c4IE/wSVn7wIHD+nM2ZHcST/62dmZXNqUt5A==",
"requested": "[0.1.1-preview.0.29, )",
"resolved": "0.1.1-preview.0.29",
"contentHash": "tmDprI1IAq9/CAes/vFTYiQGHpGWnAe7FZnoteiSA4CWF5aqWCKVQjJG0c746qynRbJq/0mAJ7FQ7ADGDRNP3w==",
"dependencies": {
"Mapster": "7.3.0",
"RhinoCommon": "7.13.21348.13001",
"RhinoWindows": "7.13.21348.13001",
"Speckle.Rhino7.Interfaces": "0.1.1-preview.0.28"
"Speckle.Rhino7.Interfaces": "0.1.1-preview.0.29"
}
},
"Speckle.Rhino7.Interfaces": {
"type": "Direct",
"requested": "[0.1.1-preview.0.28, )",
"resolved": "0.1.1-preview.0.28",
"contentHash": "TcbfXlRMnQRat1JodgW+YW5FflTYem1GGo9DtKA+6iAuVaYagN5dxsrM5LE6M3pCnEV9rkEQOjFo7sgnnbo4mw=="
"requested": "[0.1.1-preview.0.29, )",
"resolved": "0.1.1-preview.0.29",
"contentHash": "hDpFhNp3+Jidh+vJQM+nyJXo2pE6Mt9EgLv533xHnQ2u6z5ab2iCVuDlDgwS9G76tSYzl/GEvKmiMJQOiqb2vA=="
},
"System.Resources.Extensions": {
"type": "Direct",
Expand Down Expand Up @@ -527,7 +527,7 @@
"speckle.converters.rhino7.dependencyinjection": {
"type": "Project",
"dependencies": {
"Speckle.Rhino7.Interfaces": "[0.1.1-preview.0.28, )"
"Speckle.Rhino7.Interfaces": "[0.1.1-preview.0.29, )"
}
},
"Speckle.Core": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Speckle.Rhino7.Interfaces" Version="0.1.1-preview.0.28" />
<PackageReference Include="Speckle.Rhino7.Interfaces" Version="0.1.1-preview.0.29" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
},
"Speckle.Rhino7.Interfaces": {
"type": "Direct",
"requested": "[0.1.1-preview.0.28, )",
"resolved": "0.1.1-preview.0.28",
"contentHash": "TcbfXlRMnQRat1JodgW+YW5FflTYem1GGo9DtKA+6iAuVaYagN5dxsrM5LE6M3pCnEV9rkEQOjFo7sgnnbo4mw=="
"requested": "[0.1.1-preview.0.29, )",
"resolved": "0.1.1-preview.0.29",
"contentHash": "hDpFhNp3+Jidh+vJQM+nyJXo2pE6Mt9EgLv533xHnQ2u6z5ab2iCVuDlDgwS9G76tSYzl/GEvKmiMJQOiqb2vA=="
},
"GraphQL.Client": {
"type": "Transitive",
Expand Down Expand Up @@ -368,7 +368,7 @@
"type": "Project",
"dependencies": {
"Speckle.Converters.Common": "[2.0.999-local, )",
"Speckle.Rhino7.Interfaces": "[0.1.1-preview.0.28, )"
"Speckle.Rhino7.Interfaces": "[0.1.1-preview.0.29, )"
}
},
"Speckle.Core": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net48</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Speckle.Rhino7.Interfaces" Version="0.1.1-preview.0.28" />
<PackageReference Include="Speckle.Rhino7.Interfaces" Version="0.1.1-preview.0.29" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
},
"Speckle.Rhino7.Interfaces": {
"type": "Direct",
"requested": "[0.1.1-preview.0.28, )",
"resolved": "0.1.1-preview.0.28",
"contentHash": "TcbfXlRMnQRat1JodgW+YW5FflTYem1GGo9DtKA+6iAuVaYagN5dxsrM5LE6M3pCnEV9rkEQOjFo7sgnnbo4mw=="
"requested": "[0.1.1-preview.0.29, )",
"resolved": "0.1.1-preview.0.29",
"contentHash": "hDpFhNp3+Jidh+vJQM+nyJXo2pE6Mt9EgLv533xHnQ2u6z5ab2iCVuDlDgwS9G76tSYzl/GEvKmiMJQOiqb2vA=="
},
"GraphQL.Client": {
"type": "Transitive",
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.