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

feat(civil3d): adds property sets and parts data to all civil objects #297

Merged
merged 12 commits into from
Oct 11, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ private RootObjectBuilderResult BuildSync(
// 5 - Unpack the color proxies
root[ProxyKeys.COLOR] = _colorUnpacker.UnpackColors(atomicObjects, usedAcadLayers);

// add any additional properties (most likely from verticals)
AddAdditionalProxiesToRoot(root);

return new RootObjectBuilderResult(root, results);
}
}
Expand All @@ -146,6 +149,11 @@ public virtual (Collection, LayerTableRecord?) CreateObjectCollection(Entity ent
return (new(), null);
}

public virtual void AddAdditionalProxiesToRoot(Collection rootCollection)
{
return;
}

private SendConversionResult ConvertAutocadEntity(
Entity entity,
string applicationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
using Speckle.Connectors.Autocad.DependencyInjection;
using Speckle.Converters.Autocad;
#elif CIVIL3D
using Speckle.Converters.Civil3d;
using Speckle.Connectors.Civil3d.DependencyInjection;
using Speckle.Converters.Civil3dShared;
using Speckle.Connectors.Civil3dShared.DependencyInjection;
#endif
namespace Speckle.Connectors.Autocad.Plugin;

Expand All @@ -31,7 +31,7 @@ public void Command()
return;
}

PaletteSet = new PaletteSet($"Speckle (Beta) for {AppUtils.App}", s_id)
PaletteSet = new PaletteSet($"Speckle (Beta) for {AppUtils.App.Name}", s_id)
{
Size = new Size(400, 500),
DockEnabled = (DockSides)((int)DockSides.Left + (int)DockSides.Right)
Expand All @@ -52,7 +52,7 @@ public void Command()

var panelWebView = Container.GetRequiredService<DUI3ControlWebView>();

PaletteSet.AddVisual($"Speckle (Beta) for {AppUtils.App} WebView", panelWebView);
PaletteSet.AddVisual($"Speckle (Beta) for {AppUtils.App.Name} WebView", panelWebView);

FocusPalette();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
using Speckle.Connectors.DUI.Models;
using Speckle.Connectors.DUI.Models.Card.SendFilter;
using Speckle.Converters.Autocad;
using Speckle.Converters.Civil3d;
using Speckle.Converters.Civil3dShared;
using Speckle.Converters.Common;
using Speckle.Sdk;

namespace Speckle.Connectors.Civil3d.Bindings;
namespace Speckle.Connectors.Civil3dShared.Bindings;

public sealed class Civil3dSendBinding : AutocadSendBaseBinding
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
using Microsoft.Extensions.DependencyInjection;
using Speckle.Connectors.Autocad.DependencyInjection;
using Speckle.Connectors.Autocad.Operations.Send;
using Speckle.Connectors.Civil3d.Bindings;
using Speckle.Connectors.Civil3d.Operations.Send;
using Speckle.Connectors.Civil3dShared.Bindings;
using Speckle.Connectors.Civil3dShared.Operations.Send;
using Speckle.Connectors.Common.Builders;
using Speckle.Connectors.DUI.Bindings;
using Speckle.Converters.Civil3dShared.ToSpeckle;
using Speckle.Sdk;

namespace Speckle.Connectors.Civil3d.DependencyInjection;
namespace Speckle.Connectors.Civil3dShared.DependencyInjection;

public static class Civil3dConnectorModule
{
Expand All @@ -23,5 +24,8 @@ public static void AddCivil3d(this IServiceCollection serviceCollection)

// automatically detects the Class:IClass interface pattern to register all generated interfaces
serviceCollection.AddMatchingInterfacesAsTransient(Assembly.GetExecutingAssembly());

// additional classes
serviceCollection.AddScoped<PropertySetDefinitionHandler>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
using Speckle.Connectors.Autocad.HostApp;
using Speckle.Connectors.Autocad.Operations.Send;
using Speckle.Connectors.Common.Caching;
using Speckle.Connectors.Common.Operations;
using Speckle.Converters.Civil3dShared.ToSpeckle;
using Speckle.Converters.Common;
using Speckle.Sdk.Logging;
using Speckle.Sdk.Models.Collections;

namespace Speckle.Connectors.Civil3d.Operations.Send;
namespace Speckle.Connectors.Civil3dShared.Operations.Send;

public sealed class Civil3dRootObjectBuilder : AutocadRootObjectBaseBuilder
{
private readonly AutocadLayerUnpacker _layerUnpacker;
private readonly PropertySetDefinitionHandler _propertySetDefinitionHandler;

public Civil3dRootObjectBuilder(
AutocadLayerUnpacker layerUnpacker,
PropertySetDefinitionHandler propertySetDefinitionHandler,
IRootToSpeckleConverter converter,
ISendConversionCache sendConversionCache,
AutocadInstanceUnpacker instanceObjectManager,
Expand All @@ -36,6 +40,7 @@ ISdkActivityFactory activityFactory
)
{
_layerUnpacker = layerUnpacker;
_propertySetDefinitionHandler = propertySetDefinitionHandler;
}

public override (Collection, LayerTableRecord?) CreateObjectCollection(Entity entity, Transaction tr)
Expand All @@ -44,4 +49,10 @@ public override (Collection, LayerTableRecord?) CreateObjectCollection(Entity en

return (layer, autocadLayer);
}

// POC: probably will need to add Network definition proxies as well
public override void AddAdditionalProxiesToRoot(Collection rootObject)
{
rootObject[ProxyKeys.PROPERTYSET_DEFINITIONS] = _propertySetDefinitionHandler.Definitions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public SOG.Mesh RawConvert(ADB.SubDMesh target)
var vertices = new List<double>(target.Vertices.Count * 3);
foreach (AG.Point3d vert in target.Vertices)
{
vertices.AddRange(_pointConverter.Convert(vert).ToList());
vertices.Add(vert.X);
vertices.Add(vert.Y);
vertices.Add(vert.Z);
}

// faces
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public Objects.ICurve Convert(ADB.Curve target) =>
target switch
{
ADB.Line line => _lineConverter.Convert(line),
//ADB.Polyline polyline => _polylineConverter.Convert(polyline),
//ADB.Polyline2d polyline2d => _polyline2dConverter.Convert(polyline2d),
//ADB.Polyline3d polyline3d => _polyline3dConverter.Convert(polyline3d),
ADB.Polyline polyline => _polylineConverter.Convert(polyline),
ADB.Polyline2d polyline2d => _polyline2dConverter.Convert(polyline2d),
ADB.Polyline3d polyline3d => _polyline3dConverter.Convert(polyline3d),
ADB.Arc arc => _arcConverter.Convert(arc),
ADB.Circle circle => _circleConverter.Convert(circle),
ADB.Ellipse ellipse => _ellipseConverter.Convert(ellipse),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace Speckle.Converters.Civil3d;
namespace Speckle.Converters.Civil3dShared;

public record Civil3dConversionSettings(Document Document, string SpeckleUnits);
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Speckle.Converters.Common;
using Speckle.InterfaceGenerator;

namespace Speckle.Converters.Civil3d;
namespace Speckle.Converters.Civil3dShared;

[GenerateAutoInterface]
public class Civil3dConversionSettingsFactory(IHostToSpeckleUnitConverter<AAEC.BuiltInUnit> unitsConverter)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using Autodesk.AutoCAD.DatabaseServices;
using Speckle.Converters.Civil3dShared.ToSpeckle;
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Converters.Common.Registration;
using Speckle.Sdk;
using Speckle.Sdk.Models;

namespace Speckle.Converters.Civil3dShared;

public class Civil3dRootToSpeckleConverter : IRootToSpeckleConverter
{
private readonly IConverterManager<IToSpeckleTopLevelConverter> _toSpeckle;
private readonly IConverterSettingsStore<Civil3dConversionSettings> _settingsStore;
private readonly PartDataExtractor _partDataExtractor;
private readonly PropertySetExtractor _propertySetExtractor;

public Civil3dRootToSpeckleConverter(
IConverterManager<IToSpeckleTopLevelConverter> toSpeckle,
IConverterSettingsStore<Civil3dConversionSettings> settingsStore,
PartDataExtractor partDataExtractor,
PropertySetExtractor propertySetExtractor
)
{
_toSpeckle = toSpeckle;
_settingsStore = settingsStore;
_partDataExtractor = partDataExtractor;
_propertySetExtractor = propertySetExtractor;
}

public Base Convert(object target)
{
if (target is not DBObject dbObject)
{
throw new SpeckleConversionException(
$"Conversion of {target.GetType().Name} to Speckle is not supported. Only objects that inherit from DBObject are."
);
}

Type type = dbObject.GetType();
object objectToConvert = dbObject;
Dictionary<string, object?> properties = new();

// check first for civil type objects
if (target is CDB.Entity civilEntity)
{
type = civilEntity.GetType();
objectToConvert = civilEntity;

// TODO: refactor this into a property extractor class
// get part data
try
{
Dictionary<string, object?>? partData = _partDataExtractor.GetPartData(civilEntity);
if (partData is not null)
{
properties.Add("Part Data", partData);
}
}
catch (Exception e) when (!e.IsFatal())
{
//TODO: logger here
}

// get property set data
try
{
Dictionary<string, object?>? propertySets = _propertySetExtractor.GetPropertySets(civilEntity);
if (propertySets is not null)
{
properties.Add("Property Sets", propertySets);
}
}
catch (Exception e) when (!e.IsFatal())
{
//TODO: logger here
}

// TODO: add XDATA here
}

var objectConverter = _toSpeckle.ResolveConverter(type, true);

if (objectConverter == null)
{
throw new SpeckleConversionException($"No conversion found for {target.GetType().Name}");
}

try
{
using (var l = _settingsStore.Current.Document.LockDocument())
{
using (var tr = _settingsStore.Current.Document.Database.TransactionManager.StartTransaction())
{
var result = objectConverter.Convert(objectToConvert);

if (properties.Count > 0)
{
result["properties"] = properties;
}

tr.Commit();
return result;
}
}
}
catch (SpeckleConversionException e)
{
Console.WriteLine(e);
throw; // Just rethrowing for now, Logs may be needed here.
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Speckle.Sdk;
using Speckle.Sdk.Common;

namespace Speckle.Converters.Civil3d;
namespace Speckle.Converters.Civil3dShared;

public class Civil3dToSpeckleUnitConverter : IHostToSpeckleUnitConverter<AAEC.BuiltInUnit>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
global using AAEC = Autodesk.Aec;
global using AAECPDB = Autodesk.Aec.PropertyData.DatabaseServices;
global using CDB = Autodesk.Civil.DatabaseServices;
Loading
Loading