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

chore(civil3d): constants fixes and additional conversion polishing #317

Merged
merged 3 commits into from
Oct 22, 2024
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 @@ -70,7 +70,7 @@ List<LayerTableRecord> layers
}
}

// Stage 2: make sure we collect layer colors as well
// Stage 2: make sure we collect layer materials as well
foreach (LayerTableRecord layer in layers)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PlatformTarget>x64</PlatformTarget>
<UseWpf>true</UseWpf>
<Civil3DVersion>2023</Civil3DVersion>
<DefineConstants>$(DefineConstants);CIVIL3D;CIVIL3D2023;CIVIL3D2023_OR_GREATER</DefineConstants>
<DefineConstants>$(DefineConstants);CIVIL3D;CIVIL3D2023;CIVIL3D2022_OR_GREATER;CIVIL3D2023_OR_GREATER</DefineConstants>
<Configurations>Debug;Release;Local</Configurations>
<StartAction>Program</StartAction>
<StartProgram>$(ProgramW6432)\Autodesk\AutoCAD $(Civil3DVersion)\acad.exe</StartProgram>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PlatformTarget>x64</PlatformTarget>
<UseWpf>true</UseWpf>
<Civil3DVersion>2024</Civil3DVersion>
<DefineConstants>$(DefineConstants);CIVIL3D;CIVIL3D2024;CIVIL3D2024_OR_GREATER</DefineConstants>
<DefineConstants>$(DefineConstants);CIVIL3D;CIVIL3D2024;CIVIL3D2022_OR_GREATER;CIVIL3D2023_OR_GREATER;CIVIL3D2024_OR_GREATER</DefineConstants>
<Configurations>Debug;Release;Local</Configurations>
<StartAction>Program</StartAction>
<StartProgram>$(ProgramW6432)\Autodesk\AutoCAD $(Civil3DVersion)\acad.exe</StartProgram>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PlatformTarget>x64</PlatformTarget>
<UseWpf>true</UseWpf>
<Civil3DVersion>2025</Civil3DVersion>
<DefineConstants>$(DefineConstants);CIVIL3D2025;CIVIL3D</DefineConstants>
<DefineConstants>$(DefineConstants);CIVIL3D2025;CIVIL3D;CIVIL3D2022_OR_GREATER;CIVIL3D2023_OR_GREATER;CIVIL3D2024_OR_GREATER;CIVIL3D2025_OR_GREATER</DefineConstants>
<Configurations>Debug;Release;Local</Configurations>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<RuntimeIdentifier>win-x64</RuntimeIdentifier> <!-- .NET Core uses this to move native dependencies into a root for runtime selection and usage for non-windows development https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#enablewindowstargeting -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,16 @@ public SOG.Mesh Convert(ADB.Body target)
{
vertices = convertedVertices,
faces = faces,
area = brep.GetSurfaceArea(),
units = _settingsStore.Current.SpeckleUnits,
bbox = bbox
};

try
{
mesh.area = brep.GetSurfaceArea();
}
catch (Exception e) when (!e.IsFatal()) { }
try
{
mesh.volume = brep.GetVolume();
}
catch (Exception e) when (!e.IsFatal()) { }
catch (Autodesk.AutoCAD.BoundaryRepresentation.Exception e) when (!e.IsFatal()) { }

return mesh;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
<DefineConstants>$(DefineConstants);CIVIL3D;CIVIL3D2023;CIVIL3D2023_OR_GREATER</DefineConstants>
<DefineConstants>$(DefineConstants);CIVIL3D;CIVIL3D2023;CIVIL3D2022_OR_GREATER;CIVIL3D2023_OR_GREATER</DefineConstants>
<Configurations>Debug;Release;Local</Configurations>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
<DefineConstants>$(DefineConstants);CIVIL3D;CIVIL3D2024;CIVIL3D2024_OR_GREATER</DefineConstants>
<DefineConstants>$(DefineConstants);CIVIL3D;CIVIL3D2024;CIVIL3D2022_OR_GREATER;CIVIL3D2023_OR_GREATER;CIVIL3D2024_OR_GREATER</DefineConstants>
<Configurations>Debug;Release;Local</Configurations>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
<DefineConstants>$(DefineConstants);CIVIL3d2025;CIVIL3D</DefineConstants>
<DefineConstants>$(DefineConstants);CIVIL3d2025;CIVIL3D;CIVIL3D2022_OR_GREATER;CIVIL3D2023_OR_GREATER;CIVIL3D2024_OR_GREATER;CIVIL3D2025_OR_GREATER</DefineConstants>
<Configurations>Debug;Release;Local</Configurations>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,19 @@ public sealed class CorridorHandler

private readonly ITypedConverter<ADB.Solid3d, SOG.Mesh> _solidConverter;
private readonly ITypedConverter<ADB.Body, SOG.Mesh> _bodyConverter;
private readonly ITypedConverter<AG.Point3dCollection, SOG.Polyline> _pointCollectionConverter;
private readonly IConverterSettingsStore<Civil3dConversionSettings> _settingsStore;

public CorridorHandler(
ITypedConverter<ADB.Solid3d, SOG.Mesh> solidConverter,
ITypedConverter<ADB.Body, SOG.Mesh> bodyConverter,
ITypedConverter<AG.Point3dCollection, SOG.Polyline> pointCollectionConverter,
IConverterSettingsStore<Civil3dConversionSettings> settingsStore
)
{
_solidConverter = solidConverter;
_bodyConverter = bodyConverter;
_pointCollectionConverter = pointCollectionConverter;
_settingsStore = settingsStore;
}

Expand All @@ -52,7 +55,7 @@ public List<Base> GetCorridorChildren(CDB.Corridor corridor)
// track children hierarchy ids:
string corridorHandle = corridor.Handle.ToString();

// process baselines
// process baselines and any featurelines found
List<Base> baselines = new(corridor.Baselines.Count);
foreach (CDB.Baseline baseline in corridor.Baselines)
{
Expand Down Expand Up @@ -82,6 +85,42 @@ public List<Base> GetCorridorChildren(CDB.Corridor corridor)
convertedBaseline["profileId"] = baseline.ProfileId.GetSpeckleApplicationId();
}

// get baseline featurelines
List<Base> mainFeatureLines = new();
foreach (
CDB.FeatureLineCollection mainFeaturelineCollection in baseline
.MainBaselineFeatureLines
.FeatureLineCollectionMap
)
{
foreach (CDB.CorridorFeatureLine featureline in mainFeaturelineCollection)
{
mainFeatureLines.Add(FeatureLineToSpeckle(featureline));
}
}
if (mainFeatureLines.Count > 0)
{
convertedBaseline["mainBaselineFeatureLines"] = mainFeatureLines;
}

List<Base> offsetFeatureLines = new();
foreach (CDB.BaselineFeatureLines offsetFeaturelineCollection in baseline.OffsetBaselineFeatureLinesCol) // offset featurelines
{
foreach (
CDB.FeatureLineCollection featurelineCollection in offsetFeaturelineCollection.FeatureLineCollectionMap
)
{
foreach (CDB.CorridorFeatureLine featureline in featurelineCollection)
{
offsetFeatureLines.Add(FeatureLineToSpeckle(featureline));
}
}
}
if (offsetFeatureLines.Count > 0)
{
convertedBaseline["offsetBaselineFeatureLines"] = mainFeatureLines;
}

// get the baseline regions
List<Base> regions = new();
foreach (CDB.BaselineRegion region in baseline.BaselineRegions)
Expand Down Expand Up @@ -228,6 +267,30 @@ CDB.AppliedSubassembly appliedSubassembly
speckleAppliedSubassembly["calculatedShapes"] = calculatedShapes;
}

private Base FeatureLineToSpeckle(CDB.CorridorFeatureLine featureline)
{
// get the display polylines
var polylines = new List<SOG.Polyline>();

var polylinePoints = new AG.Point3dCollection();
for (int i = 0; i < featureline.FeatureLinePoints.Count; i++)
{
var point = featureline.FeatureLinePoints[i];
if (!point.IsBreak)
{
polylinePoints.Add(point.XYZ);
}
if (polylinePoints.Count > 1 && (i == featureline.FeatureLinePoints.Count - 1 || point.IsBreak))
{
polylines.Add(_pointCollectionConverter.Convert(polylinePoints));
polylinePoints.Clear();
}
}

// create featureline
return new() { ["codeName"] = featureline.CodeName, ["displayValue"] = polylines };
}

/// <summary>
/// Extracts the solids from a corridor and stores in <see cref="CorridorSolidsCache"/> according to property sets on the solid.
/// NOTE: The Export Solids method is only available for version 2024 or greater
Expand Down Expand Up @@ -266,7 +329,7 @@ private void HandleCorridorSolids(CDB.Corridor corridor)

if (solidKey is (string, string, string, string, string) validSolidKey)
{
if (CorridorSolidsCache.TryGetValue(validSolidKey, out List<SOG.Mesh> display))
if (CorridorSolidsCache.TryGetValue(validSolidKey, out List<SOG.Mesh>? display))
{
display.Add(mesh);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,49 @@ PipeNetworkHandler pipeNetworkHandler
private Dictionary<string, object?> ExtractSubassemblyProperties(CDB.Subassembly subassembly)
{
Dictionary<string, object?> subassemblyProperties = new();

subassemblyProperties["origin"] = _pointConverter.Convert(subassembly.Origin);

// get shapes > links > points info
Dictionary<string, object?> shapes = new();
int shapeCount = 0;
foreach (CDB.Shape shape in subassembly.Shapes)
{
Dictionary<string, object?> links = new();
int linkCount = 0;
foreach (CDB.Link link in shape.Links)
{
Dictionary<string, object?> points = new();
int pointCount = 0;
foreach (CDB.Point point in link.Points)
{
points[pointCount.ToString()] = new Dictionary<string, object?>()
{
["elevation"] = point.Elevation,
["codes"] = point.Codes.ToList(),
["offset"] = point.Offset,
};
pointCount++;
}

links[linkCount.ToString()] = new Dictionary<string, object?>()
{
["codes"] = link.Codes.ToList(),
["points"] = points
};

linkCount++;
}

shapes[shapeCount.ToString()] = new Dictionary<string, object?>()
{
["codes"] = shape.Codes.ToList(),
["links"] = links
};
}

subassemblyProperties["shapes"] = shapes;

if (subassembly.HasSide)
{
subassemblyProperties["side"] = subassembly.Side;
Expand Down Expand Up @@ -221,6 +264,7 @@ private void ExtractPartProperties(CDB.Part part, Dictionary<string, object?> di
{
// get the bounding curve of the catchment
SOG.Polyline boundary = _point3dCollectionConverter.Convert(catchment.BoundaryPolyline3d);
boundary.closed = true;

// use the catchment group handler to process the catchment's group
_catchmentGroupHandler.HandleCatchmentGroup(catchment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public SOG.Polyline Convert(AG.Point3dCollection target)
{
value = value,
units = _settingsStore.Current.SpeckleUnits,
closed = true,
closed = false,
length = length
};
}
Expand Down
Loading