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 missing surface properties and extension dictionaries #324

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -16,20 +16,23 @@ public class Civil3dRootToSpeckleConverter : IRootToSpeckleConverter
private readonly PartDataExtractor _partDataExtractor;
private readonly PropertySetExtractor _propertySetExtractor;
private readonly GeneralPropertiesExtractor _generalPropertiesExtractor;
private readonly ExtensionDictionaryExtractor _extensionDictionaryExtractor;

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

public Base Convert(object target)
Expand Down Expand Up @@ -86,29 +89,31 @@ public Base Convert(object target)
{
Dictionary<string, object?> properties = new();

// get general properties
Dictionary<string, object?>? generalProperties = _generalPropertiesExtractor.GetGeneralProperties(entity);
if (generalProperties is not null && generalProperties.Count > 0)
{
properties.Add("Properties", generalProperties);
}
AddDictionaryToPropertyDictionary(
_generalPropertiesExtractor.GetGeneralProperties(entity),
"General Properties",
properties
);
AddDictionaryToPropertyDictionary(_partDataExtractor.GetPartData(entity), "Part Data", properties);
AddDictionaryToPropertyDictionary(_propertySetExtractor.GetPropertySets(entity), "Property Sets", properties);
AddDictionaryToPropertyDictionary(
_extensionDictionaryExtractor.GetExtensionDictionary(entity),
"Extension Dictionary",
properties
);

// get part data
Dictionary<string, object?>? partData = _partDataExtractor.GetPartData(entity);
if (partData is not null && partData.Count > 0)
{
properties.Add("Part Data", partData);
}
return properties;
}

// get property set data
Dictionary<string, object?>? propertySets = _propertySetExtractor.GetPropertySets(entity);
if (propertySets is not null && propertySets.Count > 0)
private void AddDictionaryToPropertyDictionary(
Dictionary<string, object?>? entryDictionary,
string entryName,
Dictionary<string, object?> propertyDictionary
)
{
if (entryDictionary is not null && entryDictionary.Count > 0)
{
properties.Add("Property Sets", propertySets);
propertyDictionary.Add(entryName, entryDictionary);
}

// TODO: add XDATA here

return properties;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public static void AddCivil3dConverters(this IServiceCollection serviceCollectio
serviceCollection.AddScoped<PropertySetDefinitionHandler>();
serviceCollection.AddScoped<GeneralPropertiesExtractor>();
serviceCollection.AddScoped<ClassPropertiesExtractor>();
serviceCollection.AddScoped<ExtensionDictionaryExtractor>();
serviceCollection.AddScoped<CatchmentGroupHandler>();
serviceCollection.AddScoped<PipeNetworkHandler>();
serviceCollection.AddScoped<CorridorHandler>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\BuiltElements\CivilEntityToSpeckleTopLevelConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Properties\ClassPropertiesExtractor.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Properties\GeneralPropertiesExtractor.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Properties\ExtensionDictionaryExtractor.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Properties\PropertySetDefinitionHandler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Properties\PropertySetExtractor.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Properties\PartDataExtractor.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Speckle.Converters.Common;

namespace Speckle.Converters.Civil3dShared.ToSpeckle;

/// <summary>
/// Extracts extension dictionaries out from an element. Expects to be scoped per operation.
/// </summary>
public class ExtensionDictionaryExtractor
{
private readonly IConverterSettingsStore<Civil3dConversionSettings> _settingsStore;

public ExtensionDictionaryExtractor(IConverterSettingsStore<Civil3dConversionSettings> settingsStore)
{
_settingsStore = settingsStore;
}

/// <summary>
/// Extracts extension dictionary out from an entity. Expects to be scoped per operation.
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public Dictionary<string, object?>? GetExtensionDictionary(CDB.Entity entity)
{
if (entity is null || entity.ExtensionDictionary == ADB.ObjectId.Null)
{
return null;
}

Dictionary<string, object?> extensionDictionaryDict = new();

using (ADB.Transaction tr = _settingsStore.Current.Document.TransactionManager.StartTransaction())
{
var extensionDictionary = (ADB.DBDictionary)tr.GetObject(entity.ExtensionDictionary, ADB.OpenMode.ForRead, false);

foreach (ADB.DBDictionaryEntry entry in extensionDictionary)
{
if (tr.GetObject(entry.Value, ADB.OpenMode.ForRead) is ADB.Xrecord xRecord) // sometimes these can be RXClass objects, in property sets
{
Dictionary<string, object?> entryDict = new();
foreach (ADB.TypedValue xEntry in xRecord.Data)
{
entryDict[xEntry.TypeCode.ToString()] = xEntry.Value;
}

if (entryDict.Count > 0)
{
extensionDictionaryDict[$"{entry.Key}"] = entryDict;
}
}
}

tr.Commit();
}

return extensionDictionaryDict.Count > 0 ? extensionDictionaryDict : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,11 @@ CDB.FeatureLineCollection featurelineCollection in offsetFeaturelineCollection.F
switch (surface)
{
case CDB.TinSurface tinSurface:
statisticsDict["Terrain"] = ExtractPropertiesGeneric<CDB.TerrainSurfaceProperties>(
tinSurface.GetTerrainProperties()
);
statisticsDict["TIN"] = ExtractPropertiesGeneric<CDB.TinSurfaceProperties>(tinSurface.GetTinProperties());

break;
case CDB.TinVolumeSurface tinVolumeSurface:
statisticsDict["TIN"] = ExtractPropertiesGeneric<CDB.TinSurfaceProperties>(tinVolumeSurface.GetTinProperties());
Expand All @@ -340,6 +344,9 @@ CDB.FeatureLineCollection featurelineCollection in offsetFeaturelineCollection.F
);
break;
case CDB.GridSurface gridSurface:
statisticsDict["Terrain"] = ExtractPropertiesGeneric<CDB.TerrainSurfaceProperties>(
gridSurface.GetTerrainProperties()
);
statisticsDict["Grid"] = ExtractPropertiesGeneric<CDB.GridSurfaceProperties>(gridSurface.GetGridProperties());
break;
case CDB.GridVolumeSurface gridVolumeSurface:
Expand Down
Loading