Skip to content

Commit

Permalink
feat(civil3d): adds subassembly and parcel props (#305)
Browse files Browse the repository at this point in the history
* adds general and class properties extractors

* Update Speckle.Converters.Civil3dShared.projitems

* adds class properties for catchments

* adds catchment group proxies

* catchment proxy bug fix

* adds site props

* Update ClassPropertiesExtractor.cs

* Update ClassPropertiesExtractor.cs

* adds network, structure, and pipes

* registers pipe network

* adds alignment basecurves and properties

* adds profiles to alignments

* adds corridors

* fixes di and other corridor bugs

* parses corridor solid property sets

* Update CorridorHandler.cs

* Update CorridorHandler.cs

* adds body raw converter to autocad

* adds calculated info

* adds subassembly props

* adds subassemblies, and parcels

* adds volume surface stats

* removes unnecessary

* resolve merge conflict

* handles name exception from some entity types

* Update DBBodyToSpeckleRawConverter.cs
  • Loading branch information
clairekuang authored Oct 16, 2024
1 parent 617bb5f commit 6e56c3c
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ IConverterSettingsStore<Civil3dConversionSettings> converterSettings
case CDB.Alignment alignment:
return GetAlignmentBaseCurves(alignment);

case CDB.Parcel parcel:
return new() { _curveConverter.Convert(parcel.BaseCurve) };
// for any entities that don't use their basecurve prop
default:
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Objects;
using Speckle.Sdk;
using Speckle.Sdk.Models;

namespace Speckle.Converters.Civil3dShared.ToSpeckle.BuiltElements;
Expand Down Expand Up @@ -35,11 +36,18 @@ CorridorHandler corridorHandler

public Base Convert(CDB.Entity target)
{
string name = target.DisplayName;
try
{
name = target.Name; // this will throw for some entities like labels
}
catch (Exception e) when (!e.IsFatal()) { }

Base civilObject =
new()
{
["type"] = target.GetType().ToString().Split('.').Last(),
["name"] = target.Name,
["name"] = name,
["units"] = _settingsStore.Current.SpeckleUnits,
applicationId = target.GetSpeckleApplicationId()
};
Expand Down Expand Up @@ -79,7 +87,12 @@ public Base Convert(CDB.Entity target)
case CDB.Corridor corridor:
children = _corridorHandler.GetCorridorChildren(corridor);
break;

case CDB.Site site:
children = GetSiteChildren(site);
break;
}

if (children is not null)
{
civilObject["@elements"] = children;
Expand All @@ -88,6 +101,23 @@ public Base Convert(CDB.Entity target)
return civilObject;
}

private List<Base>? GetSiteChildren(CDB.Site site)
{
List<Base> parcels = new();

using (var tr = _settingsStore.Current.Document.Database.TransactionManager.StartTransaction())
{
foreach (ADB.ObjectId parcelId in site.GetParcelIds())
{
var parcel = (CDB.Parcel)tr.GetObject(parcelId, ADB.OpenMode.ForRead);
parcels.Add(Convert(parcel));
}

tr.Commit();
}
return parcels.Count > 0 ? parcels : null;
}

private List<Base>? GetAlignmentChildren(CDB.Alignment alignment)
{
List<Base> profiles = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ PipeNetworkHandler pipeNetworkHandler
return ExtractCatchmentProperties(catchment);
case CDB.Site site:
return ExtractSiteProperties(site);
case CDB.Parcel parcel:
return ExtractParcelProperties(parcel);

// pipe networks
case CDB.Pipe pipe:
Expand All @@ -59,28 +61,29 @@ PipeNetworkHandler pipeNetworkHandler
case CDB.Profile profile:
return ExtractProfileProperties(profile);

// assemblies
case CDB.Subassembly subassembly:
return ExtractSubassemblyProperties(subassembly);

default:
return null;
}
}

// For more info on how points are used: https://help.autodesk.com/view/CIV3D/2024/ENU/?guid=GUID-CBABE972-D690-49AE-A7DE-60F2E1B0675D
private Dictionary<string, object?> ExtractPointProperties(CDB.Point point)
private Dictionary<string, object?> ExtractParcelProperties(CDB.Parcel parcel)
{
Dictionary<string, object?> pointProperties =
new()
{
["elevation"] = point.Elevation,
["station"] = point.Station,
["isLoopPoint"] = point.IsLoopPoint
};
return new() { ["number"] = parcel.Number, ["taxId"] = parcel.TaxId };
}

if (point.Codes.Count > 0)
private Dictionary<string, object?> ExtractSubassemblyProperties(CDB.Subassembly subassembly)
{
Dictionary<string, object?> subassemblyProperties = new();
if (subassembly.HasSide)
{
pointProperties["codes"] = point.Codes.ToList();
subassemblyProperties["side"] = subassembly.Side;
}

return pointProperties;
return subassemblyProperties;
}

private Dictionary<string, object?> ExtractProfileProperties(CDB.Profile profile)
Expand Down Expand Up @@ -224,12 +227,10 @@ private void ExtractPartProperties(CDB.Part part, Dictionary<string, object?> di
["area"] = catchment.Area,
["area2d"] = catchment.Area2d,
["boundary"] = boundary,
["exclusionary"] = catchment.Exclusionary,
["hydrologicalSoilGroup"] = catchment.HydrologicalSoilGroup.ToString(),
["imperviousArea"] = catchment.ImperviousArea,
["manningsCoefficient"] = catchment.ManningsCoefficient,
["perimeter2d"] = catchment.Perimeter2d,
["runoffCoefficient"] = catchment.RunoffCoefficient,
["timeOfConcentration"] = catchment.TimeOfConcentration
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
using Autodesk.Civil.Runtime;
using Speckle.Converters.Civil3dShared.Extensions;

namespace Speckle.Converters.Civil3dShared.ToSpeckle;
Expand All @@ -19,6 +20,10 @@ public GeneralPropertiesExtractor() { }
{
switch (entity)
{
// catchment -> properties -> Catchment Properties
case CDB.Catchment catchment:
return ExtractCatchmentProperties(catchment);

// surface -> properties -> statistics -> general, extended, and tin/grid properties
case CDB.Surface surface:
return ExtractSurfaceProperties(surface);
Expand All @@ -32,20 +37,96 @@ public GeneralPropertiesExtractor() { }
case CDB.Corridor corridor:
return ExtractCorridorProperties(corridor);

//case CDB.Assembly assembly:
//return ExtractAssemblyProperties(assembly);

//case CDB.Subassembly subassembly:
//return ExtractSubassemblyProperties(subassembly);
// subassembly -> properties -> parameters, codes
case CDB.Subassembly subassembly:
return ExtractSubassemblyProperties(subassembly);

default:
return null;
}
}

//private Dictionary<string, object?> ExtractSubassemblyProperties(CDB.Subassembly subassembly) { }
private Dictionary<string, object?> ExtractCatchmentProperties(CDB.Catchment catchment)
{
Dictionary<string, object?> generalPropertiesDict = new();

//private Dictionary<string, object?> ExtractAssemblyProperties(CDB.Assembly assembly) { }
// get catchment properties props
Dictionary<string, object?> catchmentPropertiesDict = new();

Dictionary<string, object?> hydrologicalProps = new() { ["runoffCoefficient"] = catchment.RunoffCoefficient };
catchmentPropertiesDict["Hydrological Properties"] = hydrologicalProps;

Dictionary<string, object?> sheetFlow =
new()
{
["sheetFlowSegments"] = catchment.SheetFlowSegments,
["sheetFlowTravelTime"] = catchment.SheetFlowTravelTime
};
catchmentPropertiesDict["Sheet Flow"] = sheetFlow;

Dictionary<string, object?> shallowConcentratedFlow =
new()
{
["shallowFlowSegments"] = catchment.ShallowFlowSegments,
["shallowFlowTravelTime"] = catchment.ShallowFlowTravelTime
};
catchmentPropertiesDict["Shallow Concentrated Flow"] = shallowConcentratedFlow;

Dictionary<string, object?> channelFlow =
new()
{
["channelFlowSegments"] = catchment.ChannelFlowSegments,
["channelFlowTravelTime"] = catchment.ChannelFlowTravelTime
};
catchmentPropertiesDict["Channel Flow"] = channelFlow;

Dictionary<string, object?> timeOfConcentration =
new()
{
["timeOfConcentration"] = catchment.TimeOfConcentration,
["timeOfConcentrationCalculationMethod"] = catchment.TimeOfConcentrationCalculationMethod,
["hydrologicallyMostDistantPoint"] = catchment.HydrologicallyMostDistantPoint.ToArray(),
["hydrologicallyMostDistantLength"] = catchment.HydrologicallyMostDistantLength
};
catchmentPropertiesDict["Time of Concentration"] = timeOfConcentration;

if (catchmentPropertiesDict.Count > 0)
{
generalPropertiesDict["Catchment Properties"] = catchmentPropertiesDict;
}

return generalPropertiesDict;
}

private Dictionary<string, object?> ExtractSubassemblyProperties(CDB.Subassembly subassembly)
{
Dictionary<string, object?> generalPropertiesDict = new();

// get parameters props
Dictionary<string, object?> parametersDict = new();
foreach (ParamBool p in subassembly.ParamsBool)
{
parametersDict[p.DisplayName] = p.Value;
}
foreach (ParamDouble p in subassembly.ParamsDouble)
{
parametersDict[p.DisplayName] = p.Value;
}
foreach (ParamString p in subassembly.ParamsString)
{
parametersDict[p.DisplayName] = p.Value;
}
foreach (ParamLong p in subassembly.ParamsLong)
{
parametersDict[p.DisplayName] = p.Value;
}
if (parametersDict.Count > 0)
{
generalPropertiesDict["Parameters"] = parametersDict;
}

return generalPropertiesDict;
}

private void ProcessCorridorFeaturelinePoints(
CDB.CorridorFeatureLine featureline,
Expand Down Expand Up @@ -252,6 +333,9 @@ CDB.FeatureLineCollection featurelineCollection in offsetFeaturelineCollection.F
break;
case CDB.TinVolumeSurface tinVolumeSurface:
statisticsDict["TIN"] = ExtractPropertiesGeneric<CDB.TinSurfaceProperties>(tinVolumeSurface.GetTinProperties());
statisticsDict["Volume"] = ExtractPropertiesGeneric<CDB.VolumeSurfaceProperties>(
tinVolumeSurface.GetVolumeProperties()
);
break;
case CDB.GridSurface gridSurface:
statisticsDict["Grid"] = ExtractPropertiesGeneric<CDB.GridSurfaceProperties>(gridSurface.GetGridProperties());
Expand All @@ -260,6 +344,9 @@ CDB.FeatureLineCollection featurelineCollection in offsetFeaturelineCollection.F
statisticsDict["Grid"] = ExtractPropertiesGeneric<CDB.GridSurfaceProperties>(
gridVolumeSurface.GetGridProperties()
);
statisticsDict["Volume"] = ExtractPropertiesGeneric<CDB.VolumeSurfaceProperties>(
gridVolumeSurface.GetVolumeProperties()
);
break;
}

Expand All @@ -278,6 +365,11 @@ CDB.FeatureLineCollection featurelineCollection in offsetFeaturelineCollection.F
foreach (PropertyInfo? property in properties)
{
var value = property.GetValue(obj);
if (value is ADB.ObjectId id)
{
value = id.GetSpeckleApplicationId();
}

propertiesDict[property.Name] = value;
}

Expand Down

0 comments on commit 6e56c3c

Please sign in to comment.