Skip to content

Commit

Permalink
Blocks POC (Rhino, Acad) (#3519)
Browse files Browse the repository at this point in the history
* feat(dui3): adds instance def and instance proxy classes to core

* feat(dui3): rhino blocks send wip

* feat(dui3): wip (works!) rhino blocks send & receive

* some cleanup

* wip fixes

* wip cleanup

* wip scaffolds acad

* wip acad send instances and co

* wip acad - getting close to wrapping up send

* wip - units

* feat(dui3): blocks poc wip: adds rhino layer manager, moves instance baking to instance manager, etc.

* feat(dui3): blocks poc WIP - acad receive

* wip acad instance receives

* acad blocks - receive ok

* feat(dui3): acad receive blocks ✅

more testing still needed!

* feat(dui3): blocks poc minor refactors

* feat(dui3): acad blocks proper cleanup

* feat(dui3): blocks poc ready(ish) rhino & acad

* chore(dui3): reverts accidental change

* feat(dui3): adds comments/docs

* chore(dui3): comments

* fix(dui3): throws ex upwards

* fix(dui3): blocks correctly handled in acad

* update core reference and fix to not use interfaces

* remove extra files

---------

Co-authored-by: Adam Hathcock <[email protected]>
  • Loading branch information
didimitrie and adamhathcock authored Jun 27, 2024
1 parent e11bace commit 0568a29
Show file tree
Hide file tree
Showing 41 changed files with 1,488 additions and 440 deletions.
12 changes: 12 additions & 0 deletions Core/Core/Models/Instances/IInstanceComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Speckle.Core.Models.Instances;

/// <summary>
/// Abstracts over <see cref="InstanceProxy"/> and <see cref="InstanceDefinitionProxy"/> for sorting and grouping in receive operations.
/// </summary>
public interface IInstanceComponent
{
/// <summary>
/// The maximum "depth" at which this <see cref="InstanceProxy"/> or <see cref="InstanceDefinitionProxy"/> was found. On receive, as instances can be composed of other instances, we need to start from the deepest instance elements first when reconstructing them, starting with definitions first.
/// </summary>
public int MaxDepth { get; set; }
}
16 changes: 16 additions & 0 deletions Core/Core/Models/Instances/InstanceDefinitionProxy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections.Generic;

namespace Speckle.Core.Models.Instances;

/// <summary>
/// A proxy class for an instance definition.
/// </summary>
public class InstanceDefinitionProxy : Base, IInstanceComponent
{
/// <summary>
/// The original ids of the objects that are part of this definition, as present in the source host app. On receive, they will be mapped to corresponding newly created definition ids.
/// </summary>
public List<string> Objects { get; set; } // source app application ids for the objects

public int MaxDepth { get; set; }
}
26 changes: 26 additions & 0 deletions Core/Core/Models/Instances/InstanceProxy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.DoubleNumerics;

namespace Speckle.Core.Models.Instances;

/// <summary>
/// A proxy class for an instance (e.g, a rhino block, or an autocad block reference).
/// </summary>
public class InstanceProxy : Base, IInstanceComponent
{
/// <summary>
/// The definition id as present in the original host app. On receive, it will be mapped to the newly created definition id.
/// </summary>
public string DefinitionId { get; set; }

/// <summary>
/// The transform of the instance reference.
/// </summary>
public Matrix4x4 Transform { get; set; }

/// <summary>
/// The units of the host application file.
/// </summary>
public string Units { get; set; } = Kits.Units.Meters;

public int MaxDepth { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@
"Microsoft.Extensions.Logging.Abstractions": "[7.0.0, )",
"Speckle.Autofac": "[2.0.999-local, )",
"Speckle.Connectors.Utils": "[2.0.999-local, )",
"Speckle.Core": "[3.0.1-alpha.11, )",
"Speckle.Core": "[3.0.1-alpha.14, )",
"System.Threading.Tasks.Dataflow": "[6.0.0, )"
}
},
Expand All @@ -399,7 +399,7 @@
"dependencies": {
"Serilog.Extensions.Logging": "[7.0.0, )",
"Speckle.Autofac": "[2.0.999-local, )",
"Speckle.Core": "[3.0.1-alpha.11, )"
"Speckle.Core": "[3.0.1-alpha.14, )"
}
},
"speckle.converters.arcgis3": {
Expand All @@ -421,7 +421,7 @@
"type": "Project",
"dependencies": {
"Speckle.Autofac": "[2.0.999-local, )",
"Speckle.Objects": "[3.0.1-alpha.11, )"
"Speckle.Objects": "[3.0.1-alpha.14, )"
}
},
"speckle.converters.common.dependencyinjection": {
Expand Down Expand Up @@ -455,9 +455,9 @@
},
"Speckle.Core": {
"type": "CentralTransitive",
"requested": "[3.0.1-alpha.11, )",
"resolved": "3.0.1-alpha.11",
"contentHash": "Zt2dBJLlfziEACYCHThbhKypSjhoA01rTw9BzNI72c/BDyftXIz70Tetq/8ZMEqQnKqfmRyYADsAdWKxpdV0Hg==",
"requested": "[3.0.1-alpha.14, )",
"resolved": "3.0.1-alpha.14",
"contentHash": "RzQPVIGFFkKvG56YLr8ACtiwdWJE6IJ9vCQ4qHa0PIsUEpfzAIAi59jnzqtByOFC0FiFrFPow9bkfzylaZorAA==",
"dependencies": {
"GraphQL.Client": "6.0.0",
"Microsoft.CSharp": "4.7.0",
Expand All @@ -479,11 +479,11 @@
},
"Speckle.Objects": {
"type": "CentralTransitive",
"requested": "[3.0.1-alpha.11, )",
"resolved": "3.0.1-alpha.11",
"contentHash": "YR7sei3OQBAi8R/kIu8bEmg5ELDIJK6l5fhOgdnqA9ZvD/fvmRb+09z8lIUTDsgdAdvYU/A/x9VxH9OGPbp9Kw==",
"requested": "[3.0.1-alpha.14, )",
"resolved": "3.0.1-alpha.14",
"contentHash": "z38LGryMvh7iU1uBW+4uo5DwsB3CwRgLt2uFexWFx3mPSid+A0l5XcJzOgLwgFhNl6B42Ryz4ezBsddTp1Uc/g==",
"dependencies": {
"Speckle.Core": "3.0.1-alpha.11"
"Speckle.Core": "3.0.1-alpha.14"
}
},
"System.Threading.Tasks.Dataflow": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@
"Microsoft.Extensions.Logging.Abstractions": "[7.0.0, )",
"Speckle.Autofac": "[2.0.999-local, )",
"Speckle.Connectors.Utils": "[2.0.999-local, )",
"Speckle.Core": "[3.0.1-alpha.11, )",
"Speckle.Core": "[3.0.1-alpha.14, )",
"System.Threading.Tasks.Dataflow": "[6.0.0, )"
}
},
Expand All @@ -452,7 +452,7 @@
"dependencies": {
"Serilog.Extensions.Logging": "[7.0.0, )",
"Speckle.Autofac": "[2.0.999-local, )",
"Speckle.Core": "[3.0.1-alpha.11, )"
"Speckle.Core": "[3.0.1-alpha.14, )"
}
},
"speckle.converters.autocad2023": {
Expand All @@ -474,7 +474,7 @@
"type": "Project",
"dependencies": {
"Speckle.Autofac": "[2.0.999-local, )",
"Speckle.Objects": "[3.0.1-alpha.11, )"
"Speckle.Objects": "[3.0.1-alpha.14, )"
}
},
"speckle.converters.common.dependencyinjection": {
Expand Down Expand Up @@ -511,9 +511,9 @@
},
"Speckle.Core": {
"type": "CentralTransitive",
"requested": "[3.0.1-alpha.11, )",
"resolved": "3.0.1-alpha.11",
"contentHash": "Zt2dBJLlfziEACYCHThbhKypSjhoA01rTw9BzNI72c/BDyftXIz70Tetq/8ZMEqQnKqfmRyYADsAdWKxpdV0Hg==",
"requested": "[3.0.1-alpha.14, )",
"resolved": "3.0.1-alpha.14",
"contentHash": "RzQPVIGFFkKvG56YLr8ACtiwdWJE6IJ9vCQ4qHa0PIsUEpfzAIAi59jnzqtByOFC0FiFrFPow9bkfzylaZorAA==",
"dependencies": {
"GraphQL.Client": "6.0.0",
"Microsoft.CSharp": "4.7.0",
Expand All @@ -535,11 +535,11 @@
},
"Speckle.Objects": {
"type": "CentralTransitive",
"requested": "[3.0.1-alpha.11, )",
"resolved": "3.0.1-alpha.11",
"contentHash": "YR7sei3OQBAi8R/kIu8bEmg5ELDIJK6l5fhOgdnqA9ZvD/fvmRb+09z8lIUTDsgdAdvYU/A/x9VxH9OGPbp9Kw==",
"requested": "[3.0.1-alpha.14, )",
"resolved": "3.0.1-alpha.14",
"contentHash": "z38LGryMvh7iU1uBW+4uo5DwsB3CwRgLt2uFexWFx3mPSid+A0l5XcJzOgLwgFhNl6B42Ryz4ezBsddTp1Uc/g==",
"dependencies": {
"Speckle.Core": "3.0.1-alpha.11"
"Speckle.Core": "3.0.1-alpha.14"
}
},
"System.Threading.Tasks.Dataflow": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Speckle.Core.Credentials;
using Speckle.Connectors.Autocad.HostApp.Extensions;
using Speckle.Connectors.Utils;
using Speckle.Core.Logging;

namespace Speckle.Connectors.Autocad.Bindings;

Expand Down Expand Up @@ -108,34 +109,50 @@ public void HighlightModel(string modelCardId)
return;
}

HighlightObjectsOnView(objectIds);
HighlightObjectsOnView(objectIds, modelCardId);
}

private void HighlightObjectsOnView(ObjectId[] objectIds)
private void HighlightObjectsOnView(ObjectId[] objectIds, string? modelCardId = null)
{
var doc = Application.DocumentManager.MdiActiveDocument;

Parent.RunOnMainThread(() =>
{
doc.Editor.SetImpliedSelection(Array.Empty<ObjectId>()); // Deselects
doc.Editor.SetImpliedSelection(objectIds); // Selects
doc.Editor.UpdateScreen();
try
{
doc.Editor.SetImpliedSelection(Array.Empty<ObjectId>()); // Deselects
doc.Editor.SetImpliedSelection(objectIds); // Selects
doc.Editor.UpdateScreen();

Extents3d selectedExtents = new();

Extents3d selectedExtents = new();
var tr = doc.TransactionManager.StartTransaction();
foreach (ObjectId objectId in objectIds)
{
var entity = (Entity)tr.GetObject(objectId, OpenMode.ForRead);
if (entity != null)
{
selectedExtents.AddExtents(entity.GeometricExtents);
}
}

var tr = doc.TransactionManager.StartTransaction();
foreach (ObjectId objectId in objectIds)
doc.Editor.Zoom(selectedExtents);
tr.Commit();
Autodesk.AutoCAD.Internal.Utils.FlushGraphics();
}
catch (Exception ex) when (!ex.IsFatal())
{
var entity = (Entity)tr.GetObject(objectId, OpenMode.ForRead);
if (entity != null)
if (modelCardId != null)
{
Commands.SetModelError(modelCardId, new OperationCanceledException("Failed to highlight objects."));
}
else
{
selectedExtents.AddExtents(entity.GeometricExtents);
// This will happen, in some cases, where we highlight individual objects. Should be caught by the top level handler and not
// crash the host app.
throw;
}
}

doc.Editor.Zoom(selectedExtents);
tr.Commit();
Autodesk.AutoCAD.Internal.Utils.FlushGraphics();
});
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
#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;
using Speckle.Connectors.Utils.Operations;
using Speckle.Core.Models.GraphTraversal;

Expand All @@ -17,8 +27,24 @@ public class AutocadConnectorModule : ISpeckleModule
{
public void Load(SpeckleContainerBuilder builder)
{
builder.AddAutofac();
builder.AddConnectorUtils();
builder.AddDUI();
builder.AddDUIView();

// Register other connector specific types
builder.AddSingleton<IAutocadPlugin, AutocadPlugin>();
builder.AddTransient<TransactionContext>();
builder.AddSingleton(new AutocadDocumentManager()); // TODO: Dependent to TransactionContext, can be moved to AutocadContext
builder.AddSingleton<DocumentModelStore, AutocadDocumentStore>();
builder.AddSingleton<AutocadContext>();
builder.AddSingleton<AutocadIdleManager>();

SharedConnectorModule.LoadShared(builder);


builder.AddScoped<AutocadLayerManager>();

// Operations
builder.AddScoped<SendOperation<AutocadRootObject>>();
builder.AddSingleton(DefaultTraversal.CreateTraversalFunc());
Expand All @@ -37,6 +63,7 @@ public void Load(SpeckleContainerBuilder builder)

// register send conversion cache
builder.AddSingleton<ISendConversionCache, SendConversionCache>();
builder.AddScoped<IInstanceObjectsManager<AutocadRootObject, List<Entity>>, AutocadInstanceObjectManager>();
}
}
#endif
Loading

0 comments on commit 0568a29

Please sign in to comment.