Skip to content

Commit

Permalink
adds top level cogopoint converter
Browse files Browse the repository at this point in the history
  • Loading branch information
clairekuang committed Jan 8, 2025
1 parent 23710ee commit 04c02a2
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Helpers\DisplayValueExtractor.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ServiceRegistration.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Properties\PropertiesExtractor.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\TopLevel\CogoPointToSpeckleTopLevelConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\TopLevel\CivilEntityToSpeckleTopLevelConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Properties\ClassPropertiesExtractor.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ToSpeckle\Properties\GeneralPropertiesExtractor.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@ namespace Speckle.Converters.Civil3dShared.ToSpeckle.Raw;

public class Point3dCollectionToSpeckleRawConverter : ITypedConverter<AG.Point3dCollection, SOG.Polyline>
{
private readonly ITypedConverter<AG.Point3d, SOG.Point> _pointConverter;
private readonly IConverterSettingsStore<Civil3dConversionSettings> _settingsStore;

public Point3dCollectionToSpeckleRawConverter(
ITypedConverter<AG.Point3d, SOG.Point> pointConverter,
IConverterSettingsStore<Civil3dConversionSettings> settingsStore
)
public Point3dCollectionToSpeckleRawConverter(IConverterSettingsStore<Civil3dConversionSettings> settingsStore)
{
_pointConverter = pointConverter;
_settingsStore = settingsStore;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// 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.
/// </summary>
[NameAndRankValue(nameof(CDB.CogoPoint), NameAndRankValueAttribute.SPECKLE_DEFAULT_RANK)]
public class CogoPointToSpeckleTopLevelConverter : IToSpeckleTopLevelConverter
{
private readonly IConverterSettingsStore<Civil3dConversionSettings> _settingsStore;
private readonly ITypedConverter<AG.Point3d, SOG.Point> _pointConverter;

public CogoPointToSpeckleTopLevelConverter(
IConverterSettingsStore<Civil3dConversionSettings> settingsStore,
ITypedConverter<AG.Point3d, SOG.Point> 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;
}
}

0 comments on commit 04c02a2

Please sign in to comment.