From d5f1f76e24d5406a9db39b54bb1dfc9e31260624 Mon Sep 17 00:00:00 2001 From: Dogukan Karatas <61163577+dogukankaratas@users.noreply.github.com> Date: Wed, 6 Nov 2024 20:15:37 +0100 Subject: [PATCH] dogukan/cnx-748-send-grids-from-tekla (#353) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * create displayValue for grids * injects gridToSpeckleConverter --------- Co-authored-by: Oğuzhan Koral <45078678+oguzhankoral@users.noreply.github.com> --- .../Helpers/DisplayValueExtractor.cs | 26 ++--- ...wConverter.cs => ArcToSpeckleConverter.cs} | 4 +- .../ToSpeckle/Raw/GridToSpeckleConverter.cs | 97 +++++++++++++++++++ ...rter.cs => PolycurveToSpeckleConverter.cs} | 4 +- ...nverter.cs => VectorToSpeckleConverter.cs} | 4 +- 5 files changed, 117 insertions(+), 18 deletions(-) rename Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Raw/{ArcToSpeckleRawConverter.cs => ArcToSpeckleConverter.cs} (92%) create mode 100644 Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Raw/GridToSpeckleConverter.cs rename Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Raw/{PolycurveToSpeckleRawConverter.cs => PolycurveToSpeckleConverter.cs} (90%) rename Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Raw/{VectorToSpeckleRawConverter.cs => VectorToSpeckleConverter.cs} (67%) diff --git a/Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Helpers/DisplayValueExtractor.cs b/Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Helpers/DisplayValueExtractor.cs index 03cb8b2bc..9243a149d 100644 --- a/Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Helpers/DisplayValueExtractor.cs +++ b/Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Helpers/DisplayValueExtractor.cs @@ -1,3 +1,4 @@ +using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Sdk.Models; @@ -6,26 +7,30 @@ namespace Speckle.Converter.Tekla2024.ToSpeckle.Helpers; public sealed class DisplayValueExtractor { private readonly ITypedConverter _meshConverter; + private readonly IConverterSettingsStore _settingsStore; private readonly ITypedConverter _lineConverter; private readonly ITypedConverter _arcConverter; + private readonly ITypedConverter> _gridConverter; public DisplayValueExtractor( ITypedConverter meshConverter, ITypedConverter lineConverter, - ITypedConverter arcConverter + ITypedConverter arcConverter, + ITypedConverter> gridConverter, + IConverterSettingsStore settingsStore ) { _meshConverter = meshConverter; + _settingsStore = settingsStore; _lineConverter = lineConverter; _arcConverter = arcConverter; + _gridConverter = gridConverter; } public IEnumerable 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) { @@ -40,7 +45,6 @@ public IEnumerable 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, @@ -63,16 +67,14 @@ public IEnumerable 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; diff --git a/Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Raw/ArcToSpeckleRawConverter.cs b/Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Raw/ArcToSpeckleConverter.cs similarity index 92% rename from Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Raw/ArcToSpeckleRawConverter.cs rename to Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Raw/ArcToSpeckleConverter.cs index 17ef1c976..89f4e2375 100644 --- a/Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Raw/ArcToSpeckleRawConverter.cs +++ b/Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Raw/ArcToSpeckleConverter.cs @@ -3,13 +3,13 @@ namespace Speckle.Converter.Tekla2024.ToSpeckle.Raw; -public class ArcToSpeckleRawConverter : ITypedConverter +public class ArcToSpeckleConverter : ITypedConverter { private readonly IConverterSettingsStore _settingsStore; private readonly ITypedConverter _pointConverter; private readonly ITypedConverter _vectorConverter; - public ArcToSpeckleRawConverter( + public ArcToSpeckleConverter( IConverterSettingsStore settingsStore, ITypedConverter pointConverter, ITypedConverter vectorConverter diff --git a/Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Raw/GridToSpeckleConverter.cs b/Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Raw/GridToSpeckleConverter.cs new file mode 100644 index 000000000..07cec2e2d --- /dev/null +++ b/Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Raw/GridToSpeckleConverter.cs @@ -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> +{ + private readonly IConverterSettingsStore _settingsStore; + private readonly ITypedConverter _lineConverter; + + public GridToSpeckleConverter( + IConverterSettingsStore settingsStore, + ITypedConverter lineConverter + ) + { + _settingsStore = settingsStore; + _lineConverter = lineConverter; + } + + private IEnumerable 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 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)); + } + } +} diff --git a/Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Raw/PolycurveToSpeckleRawConverter.cs b/Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Raw/PolycurveToSpeckleConverter.cs similarity index 90% rename from Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Raw/PolycurveToSpeckleRawConverter.cs rename to Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Raw/PolycurveToSpeckleConverter.cs index 3efb20477..33427499d 100644 --- a/Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Raw/PolycurveToSpeckleRawConverter.cs +++ b/Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Raw/PolycurveToSpeckleConverter.cs @@ -3,13 +3,13 @@ namespace Speckle.Converter.Tekla2024.ToSpeckle.Raw; -public class PolycurveToSpeckleRawConverter : ITypedConverter +public class PolycurveToSpeckleConverter : ITypedConverter { private readonly ITypedConverter _lineConverter; private readonly ITypedConverter _arcConverter; private readonly IConverterSettingsStore _settingsStore; - public PolycurveToSpeckleRawConverter( + public PolycurveToSpeckleConverter( ITypedConverter lineConverter, ITypedConverter arcConverter, IConverterSettingsStore settingsStore diff --git a/Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Raw/VectorToSpeckleRawConverter.cs b/Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Raw/VectorToSpeckleConverter.cs similarity index 67% rename from Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Raw/VectorToSpeckleRawConverter.cs rename to Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Raw/VectorToSpeckleConverter.cs index efb6102f5..a0e1d0e5e 100644 --- a/Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Raw/VectorToSpeckleRawConverter.cs +++ b/Converters/Tekla/Speckle.Converter.Tekla2024/ToSpeckle/Raw/VectorToSpeckleConverter.cs @@ -3,11 +3,11 @@ namespace Speckle.Converter.Tekla2024.ToSpeckle.Raw; -public class VectorToSpeckleRawConverter : ITypedConverter +public class VectorToSpeckleConverter : ITypedConverter { private readonly IConverterSettingsStore _settingsStore; - public VectorToSpeckleRawConverter(IConverterSettingsStore settingsStore) + public VectorToSpeckleConverter(IConverterSettingsStore settingsStore) { _settingsStore = settingsStore; }