diff --git a/Converters/Civil3d/Speckle.Converters.Civil3dShared/Civil3dRootToSpeckleConverter.cs b/Converters/Civil3d/Speckle.Converters.Civil3dShared/Civil3dRootToSpeckleConverter.cs index aefb201ac..fd056b5f2 100644 --- a/Converters/Civil3d/Speckle.Converters.Civil3dShared/Civil3dRootToSpeckleConverter.cs +++ b/Converters/Civil3d/Speckle.Converters.Civil3dShared/Civil3dRootToSpeckleConverter.cs @@ -34,6 +34,8 @@ public Base Convert(object target) object objectToConvert = dbObject; // check first for civil type objects + // POC: some classes (eg Civil.DatabaseServices.CogoPoint) actually inherit from Autocad.DatabaseServices.Entity instead of Civil!! + // These need top level converters in Civil for now, but in the future we should implement a EntityToSpeckleTopLevelConverter for Autocad as well. if (target is CDB.Entity civilEntity) { type = civilEntity.GetType(); diff --git a/Converters/Civil3d/Speckle.Converters.Civil3dShared/Speckle.Converters.Civil3dShared.projitems b/Converters/Civil3d/Speckle.Converters.Civil3dShared/Speckle.Converters.Civil3dShared.projitems index 0e98b9c50..0ab60d801 100644 --- a/Converters/Civil3d/Speckle.Converters.Civil3dShared/Speckle.Converters.Civil3dShared.projitems +++ b/Converters/Civil3d/Speckle.Converters.Civil3dShared/Speckle.Converters.Civil3dShared.projitems @@ -23,6 +23,7 @@ + diff --git a/Converters/Civil3d/Speckle.Converters.Civil3dShared/ToSpeckle/Raw/Point3dCollectionToSpeckleRawConverter.cs b/Converters/Civil3d/Speckle.Converters.Civil3dShared/ToSpeckle/Raw/Point3dCollectionToSpeckleRawConverter.cs index b2c29160b..53ab432db 100644 --- a/Converters/Civil3d/Speckle.Converters.Civil3dShared/ToSpeckle/Raw/Point3dCollectionToSpeckleRawConverter.cs +++ b/Converters/Civil3d/Speckle.Converters.Civil3dShared/ToSpeckle/Raw/Point3dCollectionToSpeckleRawConverter.cs @@ -5,15 +5,10 @@ namespace Speckle.Converters.Civil3dShared.ToSpeckle.Raw; public class Point3dCollectionToSpeckleRawConverter : ITypedConverter { - private readonly ITypedConverter _pointConverter; private readonly IConverterSettingsStore _settingsStore; - public Point3dCollectionToSpeckleRawConverter( - ITypedConverter pointConverter, - IConverterSettingsStore settingsStore - ) + public Point3dCollectionToSpeckleRawConverter(IConverterSettingsStore settingsStore) { - _pointConverter = pointConverter; _settingsStore = settingsStore; } diff --git a/Converters/Civil3d/Speckle.Converters.Civil3dShared/ToSpeckle/TopLevel/CivilEntityToSpeckleTopLevelConverter.cs b/Converters/Civil3d/Speckle.Converters.Civil3dShared/ToSpeckle/TopLevel/CivilEntityToSpeckleTopLevelConverter.cs index 6b16b85c3..a332160e1 100644 --- a/Converters/Civil3d/Speckle.Converters.Civil3dShared/ToSpeckle/TopLevel/CivilEntityToSpeckleTopLevelConverter.cs +++ b/Converters/Civil3d/Speckle.Converters.Civil3dShared/ToSpeckle/TopLevel/CivilEntityToSpeckleTopLevelConverter.cs @@ -7,7 +7,7 @@ using Speckle.Sdk; using Speckle.Sdk.Models; -namespace Speckle.Converters.Civil3dShared.ToSpeckle.BuiltElements; +namespace Speckle.Converters.Civil3dShared.ToSpeckle.TopLevel; [NameAndRankValue(nameof(CDB.Entity), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] public class CivilEntityToSpeckleTopLevelConverter : IToSpeckleTopLevelConverter diff --git a/Converters/Civil3d/Speckle.Converters.Civil3dShared/ToSpeckle/TopLevel/CogoPointToSpeckleTopLevelConverter.cs b/Converters/Civil3d/Speckle.Converters.Civil3dShared/ToSpeckle/TopLevel/CogoPointToSpeckleTopLevelConverter.cs new file mode 100644 index 000000000..a99326c67 --- /dev/null +++ b/Converters/Civil3d/Speckle.Converters.Civil3dShared/ToSpeckle/TopLevel/CogoPointToSpeckleTopLevelConverter.cs @@ -0,0 +1,65 @@ +using Speckle.Converters.Civil3dShared.Extensions; +using Speckle.Converters.Common; +using Speckle.Converters.Common.Objects; +using Speckle.Objects.Data; +using Speckle.Sdk; +using Speckle.Sdk.Models; + +namespace Speckle.Converters.Civil3dShared.ToSpeckle.TopLevel; + +/// +/// This top level converter is needed because the namespace of CogoPoint is Autodesk.Civil.DatabaseServices, but the inheritance of CogoPoint is Autodesk.Autocad.Entity +/// This means cogo points will *not* be picked up by the top level civil entity converter. +/// POC: implementing a top level autocad entity converter can probably replace this converter. +/// +[NameAndRankValue(nameof(CDB.CogoPoint), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)] +public class CogoPointToSpeckleTopLevelConverter : IToSpeckleTopLevelConverter +{ + private readonly IConverterSettingsStore _settingsStore; + private readonly ITypedConverter _pointConverter; + + public CogoPointToSpeckleTopLevelConverter( + IConverterSettingsStore settingsStore, + ITypedConverter pointConverter + ) + { + _settingsStore = settingsStore; + _pointConverter = pointConverter; + } + + public Base Convert(object target) => Convert((CDB.CogoPoint)target); + + public Civil3dObject Convert(CDB.CogoPoint target) + { + string name = ""; + try + { + name = target.PointName; + } + catch (Autodesk.Civil.CivilException e) when (!e.IsFatal()) { } // throws if name doesn't exist + + // extract display value as point + SOG.Point displayPoint = _pointConverter.Convert(target.Location); + + Civil3dObject civilObject = + new() + { + name = name, + type = target.GetType().ToString().Split('.').Last(), + baseCurves = null, + elements = new(), + displayValue = new() { displayPoint }, + properties = new(), + units = _settingsStore.Current.SpeckleUnits, + applicationId = target.Id.GetSpeckleApplicationId() + }; + + // add additional class properties + civilObject["pointNumber"] = target.PointNumber; + civilObject["northing"] = target.Northing; + //civilObject["latitude"] = target.Latitude; // might not be necessary, and also sometimes throws if transforms are not enabled + //civilObject["longitude"] = target.Longitude; // might not be necessary, and also sometimes throws if transforms are not enabled + + return civilObject; + } +}