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 1 commit
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 @@ -19,6 +19,7 @@ public static IServiceCollection AddTeklaConverters(this IServiceCollection serv

serviceCollection.AddScoped<DisplayValueExtractor>();
serviceCollection.AddScoped<PropertyExtractor>();
serviceCollection.AddScoped<GridHandler>();

serviceCollection.AddRootCommon<TeklaRootToSpeckleConverter>(converterAssembly);
serviceCollection.AddApplicationConverters<TeklaToSpeckleUnitConverter, Units>(converterAssembly);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@ namespace Speckle.Converter.Tekla2024.ToSpeckle.Helpers;
public sealed class DisplayValueExtractor
{
private readonly ITypedConverter<TSM.Solid, SOG.Mesh> _meshConverter;
private readonly GridHandler _gridHandler;
private readonly IConverterSettingsStore<TeklaConversionSettings> _settingsStore;

public DisplayValueExtractor(
ITypedConverter<TSM.Solid, SOG.Mesh> meshConverter,
ITypedConverter<TG.LineSegment, SOG.Line> lineConverter,
IConverterSettingsStore<TeklaConversionSettings> settingsStore
)
{
_meshConverter = meshConverter;
_gridHandler = new GridHandler(lineConverter);
dogukankaratas marked this conversation as resolved.
Show resolved Hide resolved
_settingsStore = settingsStore;
}

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 @@ -38,13 +39,21 @@ public IEnumerable<Base> GetDisplayValue(TSM.ModelObject modelObject)
}
break;

// logic to send reinforcement as solid
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 _gridHandler.GetGridLines(grid))
dogukankaratas marked this conversation as resolved.
Show resolved Hide resolved
{
yield return gridLine;
}
break;

default:
yield break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using Speckle.Converters.Common.Objects;
using Speckle.Sdk.Models;

namespace Speckle.Converter.Tekla2024.ToSpeckle.Helpers;

public class GridHandler
{
private readonly ITypedConverter<TG.LineSegment, SOG.Line> _lineConverter;

public GridHandler(ITypedConverter<TG.LineSegment, SOG.Line> lineConverter)
{
_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> GetGridLines(TSM.Grid grid)
{
var coordinateSystem = grid.GetCoordinateSystem();
if (coordinateSystem == null)
{
yield break;
}

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

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

double extendedMinX = minX - grid.ExtensionLeftX;
double extendedMaxX = maxX + grid.ExtensionRightX;
double extendedMinY = minY - grid.ExtensionLeftY;
double extendedMaxY = maxY + grid.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));
}
}
}
Loading