Skip to content

Commit

Permalink
bjorn/cnx-396-etabs-structure-layout (#3628)
Browse files Browse the repository at this point in the history
gridLinesToSpeckle() Transformation

Applying the same logic of GridLinesToNative() in the gridLinesToSpeckle()
  • Loading branch information
bjoernsteinhagen authored Sep 16, 2024
1 parent 03d12af commit 429dcfd
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,6 @@ private GridSystemRepresentation CreateGridSystem(double gridRotation)
var systemName = GetUniqueGridSystemName();
_ = cSapModel.GridSys.SetGridSys(systemName, 0, 0, gridRotation * 180 / Math.PI);

// when a grid system is created, it doesn't show up unless it has at least one grid in each direction
AddCartesian(systemName, XGridLineType, "Default0", 0, "No");
AddCartesian(systemName, YGridLineType, "Default1", 0, "No");
return new GridSystemRepresentation(systemName, 0, 0, gridRotation);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using System;
using System.Collections.Generic;
using Objects.Geometry;
using Objects.Structural.CSI.Geometry;
using Objects.BuiltElements;
using ConverterCSIShared.Models;
using Objects.Other;

namespace Objects.Converter.CSI;

Expand Down Expand Up @@ -53,29 +56,63 @@ ref BubbleLocY

if (GridSysType == "Cartesian")
{
// Create transformation matrix
var gridSystem = new GridSystemRepresentation(name, Xo, Yo, RZ * Math.PI / 180);
var transform = GetTransformFromGridSystem(gridSystem);

for (int i = 0; i < NumXLines; i++)
{
var pt1 = new Point(OrdinateX[i], OrdinateY[0], units: ModelUnits());
var pt2 = new Point(OrdinateX[i], OrdinateY[NumYLines - 1], units: ModelUnits());
var gridline = new GridLine(new Line(pt1, pt2, ModelUnits()));
gridline.label = GridLineIDX[i];
speckleGridLines.gridLines.Add(gridline);
var line = new Line(
new Point(OrdinateX[i], OrdinateY[0], units: ModelUnits()),
new Point(OrdinateX[i], OrdinateY[NumYLines - 1], units: ModelUnits()),
ModelUnits()
);
if (line.TransformTo(transform, out Line transformedLine)) // Maybe it's an orthogonal system and doesn't need to be transformed
{
var gridLine = new GridLine(transformedLine) { label = GridLineIDX[i] };
speckleGridLines.gridLines.Add(gridLine);
}
}
for (int j = 0; j < NumYLines; j++)
{
var pt1 = new Point(OrdinateX[0], OrdinateY[j], units: ModelUnits());
var pt2 = new Point(OrdinateX[NumXLines - 1], OrdinateY[j], units: ModelUnits());
var gridline = new GridLine(new Line(pt1, pt2, ModelUnits()));
gridline.label = GridLineIDY[j];
speckleGridLines.gridLines.Add(gridline);
var line = new Line(
new Point(OrdinateX[0], OrdinateY[j], units: ModelUnits()),
new Point(OrdinateX[NumXLines - 1], OrdinateY[j], units: ModelUnits()),
ModelUnits()
);
if (line.TransformTo(transform, out Line transformedLine)) // Maybe it's an orthogonal system and doesn't need to be transformed
{
var gridLine = new GridLine(transformedLine) { label = GridLineIDY[j] };
speckleGridLines.gridLines.Add(gridLine);
}
}
speckleGridLines.GridSystemType = GridSysType;
speckleGridLines.Xo = Xo;
speckleGridLines.Yo = Yo;
speckleGridLines.Rz = RZ;
}

SpeckleModel.elements.Add(speckleGridLines);
return speckleGridLines;
}

private static Transform GetTransformFromGridSystem(GridSystemRepresentation sys)
{
return new Transform(
new double[]
{
Math.Cos(sys.Rotation),
-Math.Sin(sys.Rotation),
0,
sys.XOrigin,
Math.Sin(sys.Rotation),
Math.Cos(sys.Rotation),
0,
sys.YOrigin,
0,
0,
1,
0,
0,
0,
0,
1
}
);
}
}

0 comments on commit 429dcfd

Please sign in to comment.