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

dogukan/cnx-748-send-grids-from-tekla #353

Merged
merged 4 commits into from
Nov 6, 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
@@ -1,3 +1,4 @@
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Sdk.Models;

Expand All @@ -6,26 +7,30 @@ namespace Speckle.Converter.Tekla2024.ToSpeckle.Helpers;
public sealed class DisplayValueExtractor
{
private readonly ITypedConverter<TSM.Solid, SOG.Mesh> _meshConverter;
private readonly IConverterSettingsStore<TeklaConversionSettings> _settingsStore;
private readonly ITypedConverter<TG.LineSegment, SOG.Line> _lineConverter;
private readonly ITypedConverter<TG.Arc, SOG.Arc> _arcConverter;
private readonly ITypedConverter<TSM.Grid, IEnumerable<Base>> _gridConverter;

public DisplayValueExtractor(
ITypedConverter<TSM.Solid, SOG.Mesh> meshConverter,
ITypedConverter<TG.LineSegment, SOG.Line> lineConverter,
ITypedConverter<TG.Arc, SOG.Arc> arcConverter
ITypedConverter<TG.Arc, SOG.Arc> arcConverter,
ITypedConverter<TSM.Grid, IEnumerable<Base>> gridConverter,
IConverterSettingsStore<TeklaConversionSettings> settingsStore
)
{
_meshConverter = meshConverter;
_settingsStore = settingsStore;
_lineConverter = lineConverter;
_arcConverter = arcConverter;
_gridConverter = gridConverter;
}

public IEnumerable<Base> GetDisplayValue(TSM.ModelObject modelObject)
{
switch (modelObject)
{
// both beam and contour plate are child classes of part
// its simpler to use part for common methods
case TSM.Part part:
if (part.GetSolid() is TSM.Solid partSolid)
{
Expand All @@ -40,7 +45,6 @@ public IEnumerable<Base> GetDisplayValue(TSM.ModelObject modelObject)
}
break;

// this is the logic to send rebars as lines and arcs
case TSM.Reinforcement reinforcement:
var rebarGeometries = reinforcement.GetRebarComplexGeometries(
withHooks: true,
Expand All @@ -63,16 +67,14 @@ public IEnumerable<Base> GetDisplayValue(TSM.ModelObject modelObject)
}
}
}

break;

// we can switch to volumetric using the logic below
// case TSM.Reinforcement reinforcement:
// if (reinforcement.GetSolid() is TSM.Solid reinforcementSolid)
// {
// yield return _meshConverter.Convert(reinforcementSolid);
// }
// break;
case TSM.Grid grid:
foreach (var gridLine in _gridConverter.Convert(grid))
{
yield return gridLine;
}
break;

default:
yield break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

namespace Speckle.Converter.Tekla2024.ToSpeckle.Raw;

public class ArcToSpeckleRawConverter : ITypedConverter<TG.Arc, SOG.Arc>
public class ArcToSpeckleConverter : ITypedConverter<TG.Arc, SOG.Arc>
{
private readonly IConverterSettingsStore<TeklaConversionSettings> _settingsStore;
private readonly ITypedConverter<TG.Point, SOG.Point> _pointConverter;
private readonly ITypedConverter<TG.Vector, SOG.Vector> _vectorConverter;

public ArcToSpeckleRawConverter(
public ArcToSpeckleConverter(
IConverterSettingsStore<TeklaConversionSettings> settingsStore,
ITypedConverter<TG.Point, SOG.Point> pointConverter,
ITypedConverter<TG.Vector, SOG.Vector> vectorConverter
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Sdk.Models;

namespace Speckle.Converter.Tekla2024.ToSpeckle.Raw;

public class GridToSpeckleConverter : ITypedConverter<TSM.Grid, IEnumerable<Base>>
{
private readonly IConverterSettingsStore<TeklaConversionSettings> _settingsStore;
private readonly ITypedConverter<TG.LineSegment, SOG.Line> _lineConverter;

public GridToSpeckleConverter(
IConverterSettingsStore<TeklaConversionSettings> settingsStore,
ITypedConverter<TG.LineSegment, SOG.Line> lineConverter
)
{
_settingsStore = settingsStore;
_lineConverter = lineConverter;
}

private IEnumerable<double> ParseCoordinateString(string coordinateString)
{
if (string.IsNullOrEmpty(coordinateString))
{
yield break;
}

var parts = coordinateString.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
double lastValue = 0;

foreach (var part in parts)
{
if (part.Contains("*"))
{
var repetitionParts = part.Split(new[] { '*' }, StringSplitOptions.RemoveEmptyEntries);
if (
repetitionParts.Length == 2
&& int.TryParse(repetitionParts[0], out int count)
&& double.TryParse(repetitionParts[1], out double increment)
)
{
double baseValue = lastValue;
for (int i = 1; i <= count; i++)
{
double value = baseValue + (increment * i);
yield return value;
lastValue = value;
}
}
}
else
{
if (double.TryParse(part, out double value))
{
yield return value;
lastValue = value;
}
}
}
}

public IEnumerable<Base> Convert(TSM.Grid target)
{
var coordinateSystem = target.GetCoordinateSystem();
if (coordinateSystem == null)
{
yield break;
}

var xCoordinates = ParseCoordinateString(target.CoordinateX).ToList();
var yCoordinates = ParseCoordinateString(target.CoordinateY).ToList();

double minX = xCoordinates.Min();
double maxX = xCoordinates.Max();
double minY = yCoordinates.Min();
double maxY = yCoordinates.Max();

double extendedMinX = minX - target.ExtensionLeftX;
double extendedMaxX = maxX + target.ExtensionRightX;
double extendedMinY = minY - target.ExtensionLeftY;
double extendedMaxY = maxY + target.ExtensionRightY;

foreach (var x in xCoordinates)
{
var startPoint = new TG.Point(x, extendedMinY, coordinateSystem.Origin.Z);
var endPoint = new TG.Point(x, extendedMaxY, coordinateSystem.Origin.Z);
yield return _lineConverter.Convert(new TG.LineSegment(startPoint, endPoint));
}

foreach (var y in yCoordinates)
{
var startPoint = new TG.Point(extendedMinX, y, coordinateSystem.Origin.Z);
var endPoint = new TG.Point(extendedMaxX, y, coordinateSystem.Origin.Z);
yield return _lineConverter.Convert(new TG.LineSegment(startPoint, endPoint));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

namespace Speckle.Converter.Tekla2024.ToSpeckle.Raw;

public class PolycurveToSpeckleRawConverter : ITypedConverter<TG.Polycurve, SOG.Polycurve>
public class PolycurveToSpeckleConverter : ITypedConverter<TG.Polycurve, SOG.Polycurve>
{
private readonly ITypedConverter<TG.LineSegment, SOG.Line> _lineConverter;
private readonly ITypedConverter<TG.Arc, SOG.Arc> _arcConverter;
private readonly IConverterSettingsStore<TeklaConversionSettings> _settingsStore;

public PolycurveToSpeckleRawConverter(
public PolycurveToSpeckleConverter(
ITypedConverter<TG.LineSegment, SOG.Line> lineConverter,
ITypedConverter<TG.Arc, SOG.Arc> arcConverter,
IConverterSettingsStore<TeklaConversionSettings> settingsStore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

namespace Speckle.Converter.Tekla2024.ToSpeckle.Raw;

public class VectorToSpeckleRawConverter : ITypedConverter<TG.Vector, SOG.Vector>
public class VectorToSpeckleConverter : ITypedConverter<TG.Vector, SOG.Vector>
{
private readonly IConverterSettingsStore<TeklaConversionSettings> _settingsStore;

public VectorToSpeckleRawConverter(IConverterSettingsStore<TeklaConversionSettings> settingsStore)
public VectorToSpeckleConverter(IConverterSettingsStore<TeklaConversionSettings> settingsStore)
{
_settingsStore = settingsStore;
}
Expand Down
Loading