-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(civil3d): adds property sets and parts data to all civil objects (…
…#297) * adds parts data and better display mesh and base curve conversions * fixes di issues * removes arc pipes for now * Update BaseCurveExtractor.cs * Update PartDataExtractor.cs * adds property sets and defs * additional bug fixes * renames parameters folder to properties * Update Speckle.Converters.Civil3dShared.projitems --------- Co-authored-by: Adam Hathcock <[email protected]>
- Loading branch information
1 parent
ed2d3ed
commit 8c34416
Showing
25 changed files
with
784 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
Converters/Civil3d/Speckle.Converters.Civil3dShared/Civil3dConversionSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
2 changes: 1 addition & 1 deletion
2
Converters/Civil3d/Speckle.Converters.Civil3dShared/Civil3dConversionSettingsFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 0 additions & 67 deletions
67
Converters/Civil3d/Speckle.Converters.Civil3dShared/Civil3dRootToHostConverter.cs
This file was deleted.
Oops, something went wrong.
113 changes: 113 additions & 0 deletions
113
Converters/Civil3d/Speckle.Converters.Civil3dShared/Civil3dRootToSpeckleConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
Converters/Civil3d/Speckle.Converters.Civil3dShared/GlobalUsings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.