From 429dcfd6a9bedf1a86f9a44a2c5058ded993f52d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Steinhagen?= Date: Mon, 16 Sep 2024 17:31:27 +0200 Subject: [PATCH] bjorn/cnx-396-etabs-structure-layout (#3628) gridLinesToSpeckle() Transformation Applying the same logic of GridLinesToNative() in the gridLinesToSpeckle() --- .../Models/ETABSGridLineDefinitionTable.cs | 3 - .../Geometry/ConvertGridLines.cs | 67 ++++++++++++++----- 2 files changed, 52 insertions(+), 18 deletions(-) diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/Models/ETABSGridLineDefinitionTable.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/Models/ETABSGridLineDefinitionTable.cs index 7b27782d21..55d3c3b215 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/Models/ETABSGridLineDefinitionTable.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/Models/ETABSGridLineDefinitionTable.cs @@ -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); } diff --git a/Objects/Converters/ConverterCSI/ConverterCSIShared/PartialClasses/Geometry/ConvertGridLines.cs b/Objects/Converters/ConverterCSI/ConverterCSIShared/PartialClasses/Geometry/ConvertGridLines.cs index 42b35e50a4..d29a5810fd 100644 --- a/Objects/Converters/ConverterCSI/ConverterCSIShared/PartialClasses/Geometry/ConvertGridLines.cs +++ b/Objects/Converters/ConverterCSI/ConverterCSIShared/PartialClasses/Geometry/ConvertGridLines.cs @@ -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; @@ -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 + } + ); + } }