-
Notifications
You must be signed in to change notification settings - Fork 7
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 corridors (#302)
* 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 * Update PropertySetDefinitionHandler.cs * Update DBBodyToSpeckleRawConverter.cs
- Loading branch information
1 parent
fa1fa35
commit 617bb5f
Showing
16 changed files
with
1,114 additions
and
40 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
75 changes: 75 additions & 0 deletions
75
...ocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/CircularArc2dToSpeckleRawConverter.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,75 @@ | ||
using Speckle.Converters.Common; | ||
using Speckle.Converters.Common.Objects; | ||
|
||
namespace Speckle.Converters.Autocad.ToSpeckle.Raw; | ||
|
||
public class CircularArc2dToSpeckleConverter : ITypedConverter<AG.CircularArc2d, SOG.Arc> | ||
{ | ||
private readonly ITypedConverter<AG.Plane, SOG.Plane> _planeConverter; | ||
private readonly IConverterSettingsStore<AutocadConversionSettings> _settingsStore; | ||
|
||
public CircularArc2dToSpeckleConverter( | ||
ITypedConverter<AG.Plane, SOG.Plane> planeConverter, | ||
IConverterSettingsStore<AutocadConversionSettings> settingsStore | ||
) | ||
{ | ||
_planeConverter = planeConverter; | ||
_settingsStore = settingsStore; | ||
} | ||
|
||
public SOG.Arc Convert(AG.CircularArc2d target) | ||
{ | ||
string units = _settingsStore.Current.SpeckleUnits; | ||
|
||
// find arc plane (normal is in clockwise dir) | ||
var center3 = new AG.Point3d(target.Center.X, target.Center.Y, 0); | ||
AG.Plane plane = target.IsClockWise | ||
? new AG.Plane(center3, AG.Vector3d.ZAxis.MultiplyBy(-1)) | ||
: new AG.Plane(center3, AG.Vector3d.ZAxis); | ||
|
||
// calculate total angle. TODO: This needs to be validated across all possible arc orientations | ||
var totalAngle = target.IsClockWise | ||
? Math.Abs(target.EndAngle - target.StartAngle) | ||
: Math.Abs(target.EndAngle - target.StartAngle); | ||
|
||
double startParam = target.GetParameterOf(target.StartPoint); | ||
double endParam = target.GetParameterOf(target.EndPoint); | ||
AG.Point2d midPoint = target.EvaluatePoint(target.StartAngle + (target.EndAngle - target.StartAngle) / 2); | ||
|
||
// create arc | ||
var arc = new SOG.Arc() | ||
{ | ||
plane = _planeConverter.Convert(plane), | ||
radius = target.Radius, | ||
startPoint = new() | ||
{ | ||
x = target.StartPoint.X, | ||
y = target.StartPoint.Y, | ||
z = 0, | ||
units = units | ||
}, | ||
endPoint = new() | ||
{ | ||
x = target.EndPoint.X, | ||
y = target.EndPoint.Y, | ||
z = 0, | ||
units = units | ||
}, | ||
midPoint = new() | ||
{ | ||
x = midPoint.X, | ||
y = midPoint.Y, | ||
z = 0, | ||
units = units | ||
}, | ||
startAngle = target.StartAngle, | ||
endAngle = target.EndAngle, | ||
angleRadians = totalAngle, | ||
domain = new SOP.Interval { start = startParam, end = endParam }, | ||
length = target.GetLength(0, 1), | ||
units = units | ||
}; | ||
|
||
return arc; | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
...ers/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/DBBodyToSpeckleRawConverter.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,95 @@ | ||
using Speckle.Converters.Common; | ||
using Speckle.Converters.Common.Objects; | ||
using Speckle.Sdk; | ||
using Speckle.Sdk.Common.Exceptions; | ||
using Speckle.Sdk.Models; | ||
|
||
namespace Speckle.Converters.Autocad.ToSpeckle.Raw; | ||
|
||
public class DBBodyToSpeckleRawConverter : ITypedConverter<ADB.Body, SOG.Mesh> | ||
{ | ||
private readonly ITypedConverter<AG.Point3d, SOG.Point> _pointConverter; | ||
private readonly ITypedConverter<ADB.Extents3d, SOG.Box> _boxConverter; | ||
private readonly IConverterSettingsStore<AutocadConversionSettings> _settingsStore; | ||
|
||
public DBBodyToSpeckleRawConverter( | ||
ITypedConverter<AG.Point3d, SOG.Point> pointConverter, | ||
ITypedConverter<ADB.Extents3d, SOG.Box> boxConverter, | ||
IConverterSettingsStore<AutocadConversionSettings> settingsStore | ||
) | ||
{ | ||
_pointConverter = pointConverter; | ||
_boxConverter = boxConverter; | ||
_settingsStore = settingsStore; | ||
} | ||
|
||
public Base Convert(object target) => Convert((ADB.Body)target); | ||
|
||
public SOG.Mesh Convert(ADB.Body target) | ||
{ | ||
using ABR.Brep brep = new(target); | ||
if (brep.IsNull) | ||
{ | ||
throw new ConversionException("Could not retrieve brep from the body."); | ||
} | ||
|
||
var vertices = new List<AG.Point3d>(); | ||
var faces = new List<int>(); | ||
|
||
// create mesh from solid with mesh filter | ||
using ABR.Mesh2dControl control = new(); | ||
control.MaxSubdivisions = 10000; // POC: these settings may need adjusting | ||
using ABR.Mesh2dFilter filter = new(); | ||
filter.Insert(brep, control); | ||
using ABR.Mesh2d m = new(filter); | ||
foreach (ABR.Element2d e in m.Element2ds) | ||
{ | ||
// get vertices | ||
List<int> faceIndices = new(); | ||
foreach (ABR.Node n in e.Nodes) | ||
{ | ||
faceIndices.Add(vertices.Count); | ||
vertices.Add(n.Point); | ||
n.Dispose(); | ||
} | ||
|
||
// get faces | ||
List<int> faceList = new() { e.Nodes.Count() }; | ||
for (int i = 0; i < e.Nodes.Count(); i++) | ||
{ | ||
faceList.Add(faceIndices[i]); | ||
} | ||
|
||
faces.AddRange(faceList); | ||
|
||
e.Dispose(); | ||
} | ||
|
||
// mesh props | ||
var convertedVertices = vertices.SelectMany(o => _pointConverter.Convert(o).ToList()).ToList(); | ||
SOG.Box bbox = _boxConverter.Convert(target.GeometricExtents); | ||
|
||
// create speckle mesh | ||
SOG.Mesh mesh = | ||
new() | ||
{ | ||
vertices = convertedVertices, | ||
faces = faces, | ||
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()) { } | ||
|
||
return mesh; | ||
} | ||
} |
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
Oops, something went wrong.