From fbb8b428b1056ce83ec208a34fe2cd1aa56dbcc4 Mon Sep 17 00:00:00 2001 From: Tilman Reinhardt Date: Tue, 30 Apr 2024 11:53:48 +0200 Subject: [PATCH 1/5] GSAGH-482 grid loading with reference polylines --- GsaGH/Components/0_Model/GetModelLoads.cs | 38 ++-- .../Components/3_Loads/CreateGridAreaLoad.cs | 2 +- .../Components/3_Loads/CreateGridLineLoad.cs | 2 +- .../Components/6_Display/AnnotateDetailed.cs | 2 +- GsaGH/Helpers/Assembly/Loads/Loads.cs | 8 + GsaGH/Helpers/GH/RhinoConversions.cs | 2 +- GsaGH/Helpers/MergeModels.cs | 31 ++-- GsaGH/Parameters/2_Geometry/GsaMember3d.cs | 1 + GsaGH/Parameters/3_Loads/GridLoadHelper.cs | 18 +- GsaGH/Parameters/3_Loads/GsaGridAreaLoad.cs | 12 ++ GsaGH/Parameters/3_Loads/GsaGridLineLoad.cs | 12 ++ GsaGH/Parameters/3_Loads/GsaLoadFactory.cs | 163 ++++++++++-------- .../2_Geometry/GsaElement2dTest.cs | 1 + .../2_Geometry/GsaMember2dTest.cs | 6 +- 14 files changed, 172 insertions(+), 126 deletions(-) diff --git a/GsaGH/Components/0_Model/GetModelLoads.cs b/GsaGH/Components/0_Model/GetModelLoads.cs index 63059d319..390c307fc 100644 --- a/GsaGH/Components/0_Model/GetModelLoads.cs +++ b/GsaGH/Components/0_Model/GetModelLoads.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.Drawing; using System.Linq; using Grasshopper.Kernel; +using GsaAPI; using GsaGH.Helpers.GH; using GsaGH.Parameters; using GsaGH.Properties; @@ -92,29 +92,21 @@ public class GetModelLoads : GH_OasysDropDownComponent { GsaModelGoo modelGoo = null; da.GetData(0, ref modelGoo); - GsaAPI.Model model = modelGoo.Value.Model; - ReadOnlyDictionary loadCases = model.LoadCases(); - List cases = GsaLoadFactory.CreateLoadCasesFromApi(loadCases); - List gravity = GsaLoadFactory.CreateGravityLoadsFromApi(model.GravityLoads(), loadCases); - List node = GsaLoadFactory.CreateNodeLoadsFromApi(model, loadCases); - List beam = GsaLoadFactory.CreateBeamLoadsFromApi(model.BeamLoads(), loadCases); - List beamThermal = GsaLoadFactory.CreateBeamThermalLoadsFromApi(model.BeamThermalLoads(), loadCases); - List face = GsaLoadFactory.CreateFaceLoadsFromApi(model.FaceLoads(), loadCases); - List faceThermal = GsaLoadFactory.CreateFaceThermalLoadsFromApi(model.FaceThermalLoads(), loadCases); - - IReadOnlyDictionary srfDict = model.GridSurfaces(); - IReadOnlyDictionary plnDict = model.GridPlanes(); - IReadOnlyDictionary axDict = model.Axes(); - List point = GsaLoadFactory.CreateGridPointLoadsFromApi( - model.GridPointLoads(), srfDict, plnDict, axDict, loadCases, _lengthUnit); - List line = GsaLoadFactory.CreateGridLineLoadsFromApi( - model.GridLineLoads(), srfDict, plnDict, axDict, loadCases, _lengthUnit); - List area = GsaLoadFactory.CreateGridAreaLoadsFromApi( - model.GridAreaLoads(), srfDict, plnDict, axDict, loadCases, _lengthUnit); - + Model model = modelGoo.Value.Model; + List cases = GsaLoadFactory.CreateLoadCasesFromApi(model); + List gravity = GsaLoadFactory.CreateGravityLoadsFromApi(model); + List node = GsaLoadFactory.CreateNodeLoadsFromApi(model); + List beam = GsaLoadFactory.CreateBeamLoadsFromApi(model); + List beamThermal = GsaLoadFactory.CreateBeamThermalLoadsFromApi(model); + List face = GsaLoadFactory.CreateFaceLoadsFromApi(model); + List faceThermal = GsaLoadFactory.CreateFaceThermalLoadsFromApi(model); + List point = GsaLoadFactory.CreateGridPointLoadsFromApi(model, _lengthUnit); + List line = GsaLoadFactory.CreateGridLineLoadsFromApi(model, _lengthUnit); + List area = GsaLoadFactory.CreateGridAreaLoadsFromApi(model, _lengthUnit); + + IReadOnlyDictionary srfDict = model.GridSurfaces(); var gps = srfDict.Keys.Select(key - => new GsaGridPlaneSurfaceGoo(GsaLoadFactory.CreateGridPlaneSurfaceFromApi(srfDict, plnDict, axDict, key, - _lengthUnit))).ToList(); + => new GsaGridPlaneSurfaceGoo(GsaLoadFactory.CreateGridPlaneSurfaceFromApi(model, key, _lengthUnit))).ToList(); da.SetDataList(0, cases); da.SetDataList(1, gravity); diff --git a/GsaGH/Components/3_Loads/CreateGridAreaLoad.cs b/GsaGH/Components/3_Loads/CreateGridAreaLoad.cs index d3b539227..09a5cf549 100644 --- a/GsaGH/Components/3_Loads/CreateGridAreaLoad.cs +++ b/GsaGH/Components/3_Loads/CreateGridAreaLoad.cs @@ -204,7 +204,7 @@ public class CreateGridAreaLoad : GH_OasysDropDownComponent { Curve[] edges = Curve.JoinCurves(edgeSegments); Curve curve = edges[0]; - if (curve.TryGetPolyline(out Polyline polyline)) { + if (curve.TryGetPolyline(out Rhino.Geometry.Polyline polyline)) { var ctrlPts = new Point3dList(polyline); gridareaload.Points = ctrlPts; diff --git a/GsaGH/Components/3_Loads/CreateGridLineLoad.cs b/GsaGH/Components/3_Loads/CreateGridLineLoad.cs index dec580d6c..f0e44ab49 100644 --- a/GsaGH/Components/3_Loads/CreateGridLineLoad.cs +++ b/GsaGH/Components/3_Loads/CreateGridLineLoad.cs @@ -199,7 +199,7 @@ public class CreateGridLineLoad : GH_OasysDropDownComponent { Curve curve = null; GH_Convert.ToCurve(ghCurve, ref curve, GH_Conversion.Both); - if (curve.TryGetPolyline(out Polyline ln)) { + if (curve.TryGetPolyline(out Rhino.Geometry.Polyline ln)) { var controlPoints = new Point3dList(ln); gridlineload.Points = controlPoints; diff --git a/GsaGH/Components/6_Display/AnnotateDetailed.cs b/GsaGH/Components/6_Display/AnnotateDetailed.cs index 5314f1083..678ea9c42 100644 --- a/GsaGH/Components/6_Display/AnnotateDetailed.cs +++ b/GsaGH/Components/6_Display/AnnotateDetailed.cs @@ -229,7 +229,7 @@ public class AnnotateDetailed : GH_OasysDropDownComponent { break; case GsaMember2dGoo m2d: - m2d.Value.PolyCurve.TryGetPolyline(out Polyline pl); + m2d.Value.PolyCurve.TryGetPolyline(out Rhino.Geometry.Polyline pl); if (_text3d) { Plane.FitPlaneToPoints(pl, out Plane pln); pln.Origin = pl.CenterPoint(); diff --git a/GsaGH/Helpers/Assembly/Loads/Loads.cs b/GsaGH/Helpers/Assembly/Loads/Loads.cs index 4bdbe1459..2025db819 100644 --- a/GsaGH/Helpers/Assembly/Loads/Loads.cs +++ b/GsaGH/Helpers/Assembly/Loads/Loads.cs @@ -237,6 +237,10 @@ internal partial class ModelAssembly { $"({Length.GetAbbreviation(_unit)})"; } + if(load.ApiPolyline != null) { + _model.AddPolyline(load.ApiPolyline); + } + if (load.GridPlaneSurface == null) { _gridAreaLoads.Add(load.ApiLoad); return; @@ -265,6 +269,10 @@ internal partial class ModelAssembly { $"({Length.GetAbbreviation(_unit)})"; } + if (load.ApiPolyline != null) { + _model.AddPolyline(load.ApiPolyline); + } + GsaGridPlaneSurface gridplnsrf = load.GridPlaneSurface; if (gridplnsrf.GridPlane != null) { diff --git a/GsaGH/Helpers/GH/RhinoConversions.cs b/GsaGH/Helpers/GH/RhinoConversions.cs index ec45e4275..09a91de36 100644 --- a/GsaGH/Helpers/GH/RhinoConversions.cs +++ b/GsaGH/Helpers/GH/RhinoConversions.cs @@ -706,7 +706,7 @@ public static edges.AddRange(inner); Point3dList ctrlPts; - if (edges[0].TryGetPolyline(out Polyline tempCrv)) { + if (edges[0].TryGetPolyline(out Rhino.Geometry.Polyline tempCrv)) { ctrlPts = new Point3dList(tempCrv); } else { Tuple> convertBadSrf diff --git a/GsaGH/Helpers/MergeModels.cs b/GsaGH/Helpers/MergeModels.cs index 90e8d8b51..c37eb5e72 100644 --- a/GsaGH/Helpers/MergeModels.cs +++ b/GsaGH/Helpers/MergeModels.cs @@ -133,37 +133,28 @@ public class MergeModels { }).ToList(); var gooloads = new List(); - ReadOnlyDictionary loadCases = appendModel.Model.LoadCases(); - gooloads.AddRange(GsaLoadFactory.CreateGravityLoadsFromApi(appendModel.Model.GravityLoads(), loadCases)); - gooloads.AddRange(GsaLoadFactory.CreateNodeLoadsFromApi(appendModel.Model, loadCases)); - gooloads.AddRange(GsaLoadFactory.CreateBeamLoadsFromApi(appendModel.Model.BeamLoads(), loadCases)); - gooloads.AddRange(GsaLoadFactory.CreateBeamThermalLoadsFromApi(appendModel.Model.BeamThermalLoads(), loadCases)); - gooloads.AddRange(GsaLoadFactory.CreateFaceLoadsFromApi(appendModel.Model.FaceLoads(), loadCases)); - gooloads.AddRange(GsaLoadFactory.CreateFaceThermalLoadsFromApi(appendModel.Model.FaceThermalLoads(), loadCases)); + gooloads.AddRange(GsaLoadFactory.CreateGravityLoadsFromApi(appendModel.Model)); + gooloads.AddRange(GsaLoadFactory.CreateNodeLoadsFromApi(appendModel.Model)); + gooloads.AddRange(GsaLoadFactory.CreateBeamLoadsFromApi(appendModel.Model)); + gooloads.AddRange(GsaLoadFactory.CreateBeamThermalLoadsFromApi(appendModel.Model)); + gooloads.AddRange(GsaLoadFactory.CreateFaceLoadsFromApi(appendModel.Model)); + gooloads.AddRange(GsaLoadFactory.CreateFaceThermalLoadsFromApi(appendModel.Model)); IReadOnlyDictionary srfDict = appendModel.Model.GridSurfaces(); IReadOnlyDictionary plnDict = appendModel.Model.GridPlanes(); - gooloads.AddRange(GsaLoadFactory.CreateGridPointLoadsFromApi( - appendModel.Model.GridPointLoads(), srfDict, plnDict, appendModel.ApiAxis, loadCases, - LengthUnit.Meter)); - gooloads.AddRange(GsaLoadFactory.CreateGridLineLoadsFromApi( - appendModel.Model.GridLineLoads(), srfDict, plnDict, appendModel.ApiAxis, loadCases, - LengthUnit.Meter)); - gooloads.AddRange(GsaLoadFactory.CreateGridAreaLoadsFromApi( - appendModel.Model.GridAreaLoads(), srfDict, plnDict, appendModel.ApiAxis, loadCases, - LengthUnit.Meter)); + gooloads.AddRange(GsaLoadFactory.CreateGridPointLoadsFromApi(appendModel.Model, LengthUnit.Meter)); + gooloads.AddRange(GsaLoadFactory.CreateGridLineLoadsFromApi(appendModel.Model, LengthUnit.Meter)); + gooloads.AddRange(GsaLoadFactory.CreateGridAreaLoadsFromApi(appendModel.Model, LengthUnit.Meter)); var loads = gooloads.Select(n => n.Value).ToList(); var gpsgoo = srfDict.Keys.Select(key => new GsaGridPlaneSurfaceGoo( - GsaLoadFactory.CreateGridPlaneSurfaceFromApi( - srfDict, plnDict, appendModel.ApiAxis, key, LengthUnit.Meter))).ToList(); + GsaLoadFactory.CreateGridPlaneSurfaceFromApi(appendModel.Model, key, LengthUnit.Meter))).ToList(); var gps = gpsgoo.Select(n => n.Value).ToList(); List lists = appendModel.GetLists(); List gridLines = appendModel.GetGridLines(); - var gsaLoadCases = - GsaLoadFactory.CreateLoadCasesFromApi(loadCases).Select(n => n.Value).ToList(); + var gsaLoadCases = GsaLoadFactory.CreateLoadCasesFromApi(appendModel.Model).Select(n => n.Value).ToList(); var designTasks = new List(); foreach (SteelDesignTask designTask in appendModel.Model.SteelDesignTasks().Values) { var kvp = new KeyValuePair(0, designTask); diff --git a/GsaGH/Parameters/2_Geometry/GsaMember3d.cs b/GsaGH/Parameters/2_Geometry/GsaMember3d.cs index 4907f2bf1..a39184685 100644 --- a/GsaGH/Parameters/2_Geometry/GsaMember3d.cs +++ b/GsaGH/Parameters/2_Geometry/GsaMember3d.cs @@ -12,6 +12,7 @@ using Rhino.Geometry.Collections; using LengthUnit = OasysUnits.Units.LengthUnit; using Line = Rhino.Geometry.Line; +using Polyline = Rhino.Geometry.Polyline; namespace GsaGH.Parameters { /// diff --git a/GsaGH/Parameters/3_Loads/GridLoadHelper.cs b/GsaGH/Parameters/3_Loads/GridLoadHelper.cs index 7fb455c00..9a00c57d2 100644 --- a/GsaGH/Parameters/3_Loads/GridLoadHelper.cs +++ b/GsaGH/Parameters/3_Loads/GridLoadHelper.cs @@ -1,4 +1,5 @@ -using GsaAPI; +using System.Collections.Generic; +using GsaAPI; using OasysUnits; using Rhino.Collections; using Rhino.Geometry; @@ -27,7 +28,7 @@ internal static class GridLoadHelper { return ClearDefGetUnit(definition).def; } - internal static Point3dList ConvertPoints(string definition, LengthUnit desiredUnit, Plane localPlane) { + internal static Point3dList ConvertPoints(string definition, LengthUnit desiredUnit, Plane localPlane) { (LengthUnit lengthUnit, string def) = ClearDefGetUnit(definition); var points = new Point3dList(); string[] pts = def.Split(')'); @@ -45,6 +46,19 @@ internal static class GridLoadHelper { return points; } + internal static Point3dList ConvertPoints(List definition, LengthUnit desiredUnit, Plane localPlane) { + var map = Transform.ChangeBasis(localPlane, Plane.WorldXY); + var points = new Point3dList(); + foreach (Vector2 vector in definition) { + var x = new Length(vector.X, LengthUnit.Meter); + var y = new Length(vector.Y, LengthUnit.Meter); + var point = new Point3d(x.As(desiredUnit), y.As(desiredUnit), 0); + point.Transform(map); + points.Add(point); + } + return points; + } + private static (LengthUnit lengthUnit, string def) ClearDefGetUnit(string definition) { LengthUnit lengthUnit = LengthUnit.Meter; if (definition.EndsWith("(mm)")) { diff --git a/GsaGH/Parameters/3_Loads/GsaGridAreaLoad.cs b/GsaGH/Parameters/3_Loads/GsaGridAreaLoad.cs index 95e51001d..ecce11d4c 100644 --- a/GsaGH/Parameters/3_Loads/GsaGridAreaLoad.cs +++ b/GsaGH/Parameters/3_Loads/GsaGridAreaLoad.cs @@ -6,6 +6,7 @@ namespace GsaGH.Parameters { public class GsaGridAreaLoad : IGsaGridLoad { public GridAreaLoad ApiLoad { get; set; } = new GridAreaLoad(); + public Polyline ApiPolyline { get; internal set; } public GsaGridPlaneSurface GridPlaneSurface { get; set; } = new GsaGridPlaneSurface(); public GsaLoadCase LoadCase { get; set; } public ReferenceType ReferenceType => GridPlaneSurface._referenceType; @@ -44,11 +45,22 @@ public class GsaGridAreaLoad : IGsaGridLoad { Points = Points, }; + if(ApiPolyline != null) { + dup.ApiPolyline = DuplicateApiPolyline(); + } + if (LoadCase != null) { dup.LoadCase = LoadCase; } return dup; } + + private Polyline DuplicateApiPolyline() { + var polyline = new Polyline(ApiPolyline.Points) { + Name = ApiPolyline.Name + }; + return polyline; + } } } diff --git a/GsaGH/Parameters/3_Loads/GsaGridLineLoad.cs b/GsaGH/Parameters/3_Loads/GsaGridLineLoad.cs index 79954bed6..3e51ad7ac 100644 --- a/GsaGH/Parameters/3_Loads/GsaGridLineLoad.cs +++ b/GsaGH/Parameters/3_Loads/GsaGridLineLoad.cs @@ -6,6 +6,7 @@ namespace GsaGH.Parameters { public class GsaGridLineLoad : IGsaGridLoad { public GridLineLoad ApiLoad { get; set; } = new GridLineLoad(); + public Polyline ApiPolyline { get; internal set; } public GsaGridPlaneSurface GridPlaneSurface { get; set; } = new GsaGridPlaneSurface(); public GsaLoadCase LoadCase { get; set; } public ReferenceType ReferenceType => GridPlaneSurface._referenceType; @@ -45,11 +46,22 @@ public class GsaGridLineLoad : IGsaGridLoad { Points = Points, }; + if (ApiPolyline != null) { + dup.ApiPolyline = DuplicateApiPolyline(); + } + if (LoadCase != null) { dup.LoadCase = LoadCase; } return dup; } + + private Polyline DuplicateApiPolyline() { + var polyline = new Polyline(ApiPolyline.Points) { + Name = ApiPolyline.Name + }; + return polyline; + } } } diff --git a/GsaGH/Parameters/3_Loads/GsaLoadFactory.cs b/GsaGH/Parameters/3_Loads/GsaLoadFactory.cs index 46be1e587..90b68d24b 100644 --- a/GsaGH/Parameters/3_Loads/GsaLoadFactory.cs +++ b/GsaGH/Parameters/3_Loads/GsaLoadFactory.cs @@ -14,9 +14,11 @@ public static class GsaLoadFactory { /// Method to import Load Cases from a GSA model. /// Will output a list of GsaLoadCase. /// - /// + /// /// - internal static List CreateLoadCasesFromApi(ReadOnlyDictionary loadCases) { + internal static List CreateLoadCasesFromApi(Model model) { + ReadOnlyDictionary loadCases = model.LoadCases(); + var cases = new List(); foreach (KeyValuePair kvp in loadCases) { cases.Add(new GsaLoadCaseGoo(new GsaLoadCase(kvp.Key, loadCases))); @@ -29,11 +31,12 @@ public static class GsaLoadFactory { /// Method to import Beam Loads from a GSA model. /// Will output a list of GsaLoads. /// - /// Collection of beams loads to be imported - /// + /// /// - internal static List CreateBeamLoadsFromApi( - ReadOnlyCollection beamLoads, ReadOnlyDictionary loadCases) { + internal static List CreateBeamLoadsFromApi(Model model) { + ReadOnlyCollection beamLoads = model.BeamLoads(); + ReadOnlyDictionary loadCases = model.LoadCases(); + var loads = new List(); foreach (BeamLoad apiLoad in beamLoads) { var load = new GsaBeamLoad { @@ -51,11 +54,12 @@ public static class GsaLoadFactory { /// Method to import Beam Thermal Loads from a GSA model. /// Will output a list of GsaLoads. /// - /// Collection of beam thermal loads to be imported - /// + /// /// - internal static List CreateBeamThermalLoadsFromApi( - ReadOnlyCollection beamThermalLoads, ReadOnlyDictionary loadCases) { + internal static List CreateBeamThermalLoadsFromApi(Model model) { + ReadOnlyCollection beamThermalLoads = model.BeamThermalLoads(); + ReadOnlyDictionary loadCases = model.LoadCases(); + var loads = new List(); foreach (BeamThermalLoad apiLoad in beamThermalLoads) { var load = new GsaBeamThermalLoad { @@ -73,11 +77,12 @@ public static class GsaLoadFactory { /// Method to import Face Loads from a GSA model. /// Will output a list of GsaLoads. /// - /// Collection of Face loads to be imported - /// + /// /// - internal static List CreateFaceLoadsFromApi(ReadOnlyCollection faceLoads, - ReadOnlyDictionary loadCases) { + internal static List CreateFaceLoadsFromApi(Model model) { + ReadOnlyCollection faceLoads = model.FaceLoads(); + ReadOnlyDictionary loadCases = model.LoadCases(); + var loads = new List(); foreach (FaceLoad apiLoad in faceLoads) { var load = new GsaFaceLoad { @@ -95,11 +100,12 @@ public static class GsaLoadFactory { /// Method to import Face Thermal Loads from a GSA model. /// Will output a list of GsaLoads. /// - /// Collection of Face Thermal loads to be imported - /// + /// /// - internal static List CreateFaceThermalLoadsFromApi( - ReadOnlyCollection faceThermalLoads, ReadOnlyDictionary loadCases) { + internal static List CreateFaceThermalLoadsFromApi(Model model) { + ReadOnlyCollection faceThermalLoads = model.FaceThermalLoads(); + ReadOnlyDictionary loadCases = model.LoadCases(); + var loads = new List(); foreach (FaceThermalLoad apiLoad in faceThermalLoads) { var load = new GsaFaceThermalLoad { @@ -117,11 +123,12 @@ public static class GsaLoadFactory { /// Method to import Gravity Loads from a GSA model. /// Will output a list of GsaLoadsGoo. /// - /// Collection of gravity loads to import - /// + /// /// - internal static List CreateGravityLoadsFromApi( - ReadOnlyCollection gravityLoads, ReadOnlyDictionary loadCases) { + internal static List CreateGravityLoadsFromApi(Model model) { + ReadOnlyCollection gravityLoads = model.GravityLoads(); + ReadOnlyDictionary loadCases = model.LoadCases(); + var loads = new List(); foreach (GravityLoad apiLoad in gravityLoads) { var load = new GsaGravityLoad { @@ -139,30 +146,32 @@ public static class GsaLoadFactory { /// Method to import Grid Area Loads from a GSA model. /// Will output a list of GsaLoads. /// - /// Collection of Grid Area loads to be imported - /// Grid Surface Dictionary - /// Grid Plane Dictionary - /// Axes Dictionary - /// + /// /// /// - internal static List CreateGridAreaLoadsFromApi( - ReadOnlyCollection areaLoads, IReadOnlyDictionary srfDict, - IReadOnlyDictionary plnDict, IReadOnlyDictionary axDict, - ReadOnlyDictionary loadCases, LengthUnit unit) { + internal static List CreateGridAreaLoadsFromApi(Model model, LengthUnit unit) { + ReadOnlyCollection areaLoads = model.GridAreaLoads(); + IReadOnlyDictionary srfDict = model.GridSurfaces(); + IReadOnlyDictionary plnDict = model.GridPlanes(); + IReadOnlyDictionary axDict = model.Axes(); + ReadOnlyDictionary loadCases = model.LoadCases(); + ReadOnlyDictionary polylines = model.Polylines(); + var loads = new List(); foreach (GridAreaLoad gridAreaLoad in areaLoads) { var load = new GsaGridAreaLoad { ApiLoad = gridAreaLoad, - GridPlaneSurface - = CreateGridPlaneSurfaceFromApi(srfDict, plnDict, axDict, gridAreaLoad.GridSurface, unit) + GridPlaneSurface = CreateGridPlaneSurfaceFromApi(model, gridAreaLoad.GridSurface, unit) }; - if (gridAreaLoad.PolyLineDefinition != string.Empty - && gridAreaLoad.PolyLineDefinition.Contains('(') - && load.GridPlaneSurface != null) { - load.Points = GridLoadHelper.ConvertPoints( - gridAreaLoad.PolyLineDefinition.ToString(), unit, load.GridPlaneSurface.Plane); + if (load.GridPlaneSurface != null) { + if (gridAreaLoad.PolyLineDefinition != string.Empty && gridAreaLoad.PolyLineDefinition.Contains('(')) { + load.Points = GridLoadHelper.ConvertPoints(gridAreaLoad.PolyLineDefinition.ToString(), unit, load.GridPlaneSurface.Plane); + } else if (polylines.ContainsKey(gridAreaLoad.PolyLineReference)) { + GsaAPI.Polyline polyline = polylines[gridAreaLoad.PolyLineReference]; + load.Points = GridLoadHelper.ConvertPoints(polyline.Points, unit, load.GridPlaneSurface.Plane); + load.ApiPolyline = polyline; + } } load.LoadCase = new GsaLoadCase(load.ApiLoad.Case, loadCases); @@ -176,30 +185,33 @@ public static class GsaLoadFactory { /// Method to import Grid Line Loads from a GSA model. /// Will output a list of GsaLoads. /// - /// Collection of Grid Line loads to be imported - /// Grid Surface Dictionary - /// Grid Plane Dictionary - /// Axes Dictionary - /// + /// /// /// - internal static List CreateGridLineLoadsFromApi( - ReadOnlyCollection lineLoads, IReadOnlyDictionary srfDict, - IReadOnlyDictionary plnDict, IReadOnlyDictionary axDict, - ReadOnlyDictionary loadCases, LengthUnit unit) { + internal static List CreateGridLineLoadsFromApi(Model model, LengthUnit unit) { + ReadOnlyCollection lineLoads = model.GridLineLoads(); + ReadOnlyCollection areaLoads = model.GridAreaLoads(); + IReadOnlyDictionary srfDict = model.GridSurfaces(); + IReadOnlyDictionary plnDict = model.GridPlanes(); + IReadOnlyDictionary axDict = model.Axes(); + ReadOnlyDictionary loadCases = model.LoadCases(); + ReadOnlyDictionary polylines = model.Polylines(); + var loads = new List(); foreach (GridLineLoad gridLineLoad in lineLoads) { var load = new GsaGridLineLoad { ApiLoad = gridLineLoad, - GridPlaneSurface - = CreateGridPlaneSurfaceFromApi(srfDict, plnDict, axDict, gridLineLoad.GridSurface, unit) + GridPlaneSurface = CreateGridPlaneSurfaceFromApi(model, gridLineLoad.GridSurface, unit) }; - if (gridLineLoad.PolyLineDefinition != string.Empty - && gridLineLoad.PolyLineDefinition.Contains('(') - && load.GridPlaneSurface != null) { - load.Points = GridLoadHelper.ConvertPoints( - gridLineLoad.PolyLineDefinition.ToString(), unit, load.GridPlaneSurface.Plane); + if (load.GridPlaneSurface != null) { + if (gridLineLoad.PolyLineDefinition != string.Empty && gridLineLoad.PolyLineDefinition.Contains('(')) { + load.Points = GridLoadHelper.ConvertPoints(gridLineLoad.PolyLineDefinition.ToString(), unit, load.GridPlaneSurface.Plane); + } else if (polylines.ContainsKey(gridLineLoad.PolyLineReference)) { + GsaAPI.Polyline polyline = polylines[gridLineLoad.PolyLineReference]; + load.Points = GridLoadHelper.ConvertPoints(polyline.Points, unit, load.GridPlaneSurface.Plane); + load.ApiPolyline = polyline; + } } load.LoadCase = new GsaLoadCase(load.ApiLoad.Case, loadCases); @@ -217,15 +229,17 @@ public static class GsaLoadFactory { /// Only Grid Surface ID is required, the others will be found by ref /// Will output a new GsaGridPlaneSurface. /// - /// Grid Surface Dictionary - /// Grid Plane Dictionary - /// Axes Dictionary + /// /// ID/Key/number of Grid Surface in GSA model to convert /// /// - internal static GsaGridPlaneSurface CreateGridPlaneSurfaceFromApi( - IReadOnlyDictionary srfDict, IReadOnlyDictionary plnDict, - IReadOnlyDictionary axDict, int gridSrfId, LengthUnit unit) { + internal static GsaGridPlaneSurface CreateGridPlaneSurfaceFromApi(Model model, int gridSrfId, LengthUnit unit) { + ReadOnlyCollection areaLoads = model.GridAreaLoads(); + IReadOnlyDictionary srfDict = model.GridSurfaces(); + IReadOnlyDictionary plnDict = model.GridPlanes(); + IReadOnlyDictionary axDict = model.Axes(); + ReadOnlyDictionary loadCases = model.LoadCases(); + if (srfDict.Count == 0 || !srfDict.TryGetValue(gridSrfId, out GridSurface gs)) { return null; } @@ -268,23 +282,23 @@ public static class GsaLoadFactory { /// Method to import Grid Point Loads from a GSA model. /// Will output a list of GsaLoads. /// - /// Collection of Grid Point loads to be imported - /// Grid Surface Dictionary - /// Grid Plane Dictionary - /// Axes Dictionary - /// + /// /// /// - internal static List CreateGridPointLoadsFromApi( - ReadOnlyCollection pointLoads, IReadOnlyDictionary srfDict, - IReadOnlyDictionary plnDict, IReadOnlyDictionary axDict, - ReadOnlyDictionary loadCases, LengthUnit unit) { + internal static List CreateGridPointLoadsFromApi(Model model, LengthUnit unit) { + ReadOnlyCollection pointLoads = model.GridPointLoads(); + ReadOnlyCollection areaLoads = model.GridAreaLoads(); + IReadOnlyDictionary srfDict = model.GridSurfaces(); + IReadOnlyDictionary plnDict = model.GridPlanes(); + IReadOnlyDictionary axDict = model.Axes(); + ReadOnlyDictionary loadCases = model.LoadCases(); + var loads = new List(); foreach (GridPointLoad gridPointLoad in pointLoads) { var load = new GsaGridPointLoad { ApiLoad = gridPointLoad, - GridPlaneSurface - = CreateGridPlaneSurfaceFromApi(srfDict, plnDict, axDict, gridPointLoad.GridSurface, unit), }; + GridPlaneSurface = CreateGridPlaneSurfaceFromApi(model, gridPointLoad.GridSurface, unit) + }; if (unit != LengthUnit.Meter) { load.ApiLoad.X = new Length(load.ApiLoad.X, LengthUnit.Meter).As(unit); @@ -305,10 +319,11 @@ public static class GsaLoadFactory { /// requeres the entire model to be inputted to this method. /// Will output a list of GsaLoads. /// - /// GSA model containing node loads - /// + /// /// - internal static List CreateNodeLoadsFromApi(Model model, ReadOnlyDictionary loadCases) { + internal static List CreateNodeLoadsFromApi(Model model) { + ReadOnlyDictionary loadCases = model.LoadCases(); + var loads = new List(); // NodeLoads come in varioys types, depending on GsaAPI.NodeLoadType: diff --git a/GsaGHTests/1_BaseParameters/2_Geometry/GsaElement2dTest.cs b/GsaGHTests/1_BaseParameters/2_Geometry/GsaElement2dTest.cs index de665c276..d595c2511 100644 --- a/GsaGHTests/1_BaseParameters/2_Geometry/GsaElement2dTest.cs +++ b/GsaGHTests/1_BaseParameters/2_Geometry/GsaElement2dTest.cs @@ -10,6 +10,7 @@ using Rhino.Geometry; using Xunit; using LengthUnit = OasysUnits.Units.LengthUnit; +using Polyline = Rhino.Geometry.Polyline; namespace GsaGHTests.Parameters { [Collection("GrasshopperFixture collection")] diff --git a/GsaGHTests/1_BaseParameters/2_Geometry/GsaMember2dTest.cs b/GsaGHTests/1_BaseParameters/2_Geometry/GsaMember2dTest.cs index b4ec46dd0..bd1da7e2f 100644 --- a/GsaGHTests/1_BaseParameters/2_Geometry/GsaMember2dTest.cs +++ b/GsaGHTests/1_BaseParameters/2_Geometry/GsaMember2dTest.cs @@ -20,7 +20,7 @@ public class GsaMember2dTest { new Point3d(-1, 2, 0), }; pts.Add(pts[0]); - var pol = new Polyline(pts); + var pol = new Rhino.Geometry.Polyline(pts); Brep brep = Brep.CreatePlanarBreps(pol.ToNurbsCurve(), 0.001)[0]; var inclpts = new Point3dList(); @@ -69,7 +69,7 @@ public class GsaMember2dTest { new Point3d(4, 2, 0), }; pts.Add(pts[0]); - var pol = new Polyline(pts); + var pol = new Rhino.Geometry.Polyline(pts); Brep brep = Brep.CreatePlanarBreps(pol.ToNurbsCurve(), 0.001)[0]; var inclpts = new Point3dList { @@ -127,7 +127,7 @@ public class GsaMember2dTest { new Point3d(2, 4, 0), }; pts2.Add(pts2[0]); - var pol2 = new Polyline(pts2); + var pol2 = new Rhino.Geometry.Polyline(pts2); Brep brep2 = Brep.CreatePlanarBreps(pol2.ToNurbsCurve(), 0.001)[0]; original.UpdateGeometry(brep2); From d1a3143f037baa0a2c0924f43aff1943f68f36de Mon Sep 17 00:00:00 2001 From: Tilman Reinhardt Date: Thu, 2 May 2024 10:15:34 +0200 Subject: [PATCH 2/5] TestAdapterPath --- build-test-deploy.yml | 4 ++-- build-test-nightly.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build-test-deploy.yml b/build-test-deploy.yml index 4d30237ba..2dcb8e8da 100644 --- a/build-test-deploy.yml +++ b/build-test-deploy.yml @@ -74,8 +74,8 @@ steps: MSBUILDDISABLENODEREUSE: 1 - powershell: | - dotnet test --collect:"XPlat Code Coverage" /TestAdapterPath:$env:UserProfile\.nuget\packages\coverlet.collector\6.0.0\build --results-directory .\results\gsagh .\GsaGHTests\bin\x64\Release\net48\GsaGHTests.dll - dotnet test --collect:"XPlat Code Coverage" /TestAdapterPath:$env:UserProfile\.nuget\packages\coverlet.collector\6.0.0\build --results-directory .\results\integration .\IntegrationTests\bin\x64\Release\net48\IntegrationTests.dll + dotnet test --collect:"XPlat Code Coverage" /TestAdapterPath:$env:UserProfile\.nuget\packages\coverlet.collector\6.0.2\build --results-directory .\results\gsagh .\GsaGHTests\bin\x64\Release\net48\GsaGHTests.dll + dotnet test --collect:"XPlat Code Coverage" /TestAdapterPath:$env:UserProfile\.nuget\packages\coverlet.collector\6.0.2\build --results-directory .\results\integration .\IntegrationTests\bin\x64\Release\net48\IntegrationTests.dll displayName: dotnet tests failOnStderr: true diff --git a/build-test-nightly.yml b/build-test-nightly.yml index f26e2ee45..7ec6687a3 100644 --- a/build-test-nightly.yml +++ b/build-test-nightly.yml @@ -76,8 +76,8 @@ steps: MSBUILDDISABLENODEREUSE: 1 - powershell: | - dotnet test --collect:"XPlat Code Coverage" /TestAdapterPath:$env:UserProfile\.nuget\packages\coverlet.collector\6.0.0\build --results-directory .\results\gsagh .\GsaGHTests\bin\x64\Release\net48\GsaGHTests.dll - dotnet test --collect:"XPlat Code Coverage" /TestAdapterPath:$env:UserProfile\.nuget\packages\coverlet.collector\6.0.0\build --results-directory .\results\integration .\IntegrationTests\bin\x64\Release\net48\IntegrationTests.dll + dotnet test --collect:"XPlat Code Coverage" /TestAdapterPath:$env:UserProfile\.nuget\packages\coverlet.collector\6.0.2\build --results-directory .\results\gsagh .\GsaGHTests\bin\x64\Release\net48\GsaGHTests.dll + dotnet test --collect:"XPlat Code Coverage" /TestAdapterPath:$env:UserProfile\.nuget\packages\coverlet.collector\6.0.2\build --results-directory .\results\integration .\IntegrationTests\bin\x64\Release\net48\IntegrationTests.dll displayName: dotnet tests failOnStderr: true From ece739d0dd8a7b7b57bbec1d17c633468fda55ec Mon Sep 17 00:00:00 2001 From: Tilman Reinhardt Date: Fri, 3 May 2024 16:16:42 +0200 Subject: [PATCH 3/5] nuget packages --- GsaGH/Helpers/Assembly/Loads/Loads.cs | 4 ++-- GsaGH/Parameters/3_Loads/GridLoadHelper.cs | 2 +- GsaGHTests/GsaGHTests.csproj | 4 ++-- IntegrationTests/IntegrationTests.csproj | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/GsaGH/Helpers/Assembly/Loads/Loads.cs b/GsaGH/Helpers/Assembly/Loads/Loads.cs index 2025db819..06e32fd74 100644 --- a/GsaGH/Helpers/Assembly/Loads/Loads.cs +++ b/GsaGH/Helpers/Assembly/Loads/Loads.cs @@ -237,7 +237,7 @@ internal partial class ModelAssembly { $"({Length.GetAbbreviation(_unit)})"; } - if(load.ApiPolyline != null) { + if(load.ApiLoad.PolyLineReference > 0) { _model.AddPolyline(load.ApiPolyline); } @@ -269,7 +269,7 @@ internal partial class ModelAssembly { $"({Length.GetAbbreviation(_unit)})"; } - if (load.ApiPolyline != null) { + if (load.ApiLoad.PolyLineReference > 0) { _model.AddPolyline(load.ApiPolyline); } diff --git a/GsaGH/Parameters/3_Loads/GridLoadHelper.cs b/GsaGH/Parameters/3_Loads/GridLoadHelper.cs index 9a00c57d2..06164f9b0 100644 --- a/GsaGH/Parameters/3_Loads/GridLoadHelper.cs +++ b/GsaGH/Parameters/3_Loads/GridLoadHelper.cs @@ -28,7 +28,7 @@ internal static class GridLoadHelper { return ClearDefGetUnit(definition).def; } - internal static Point3dList ConvertPoints(string definition, LengthUnit desiredUnit, Plane localPlane) { + internal static Point3dList ConvertPoints(string definition, LengthUnit desiredUnit, Plane localPlane) { (LengthUnit lengthUnit, string def) = ClearDefGetUnit(definition); var points = new Point3dList(); string[] pts = def.Split(')'); diff --git a/GsaGHTests/GsaGHTests.csproj b/GsaGHTests/GsaGHTests.csproj index 440971f17..91a4ec1e2 100644 --- a/GsaGHTests/GsaGHTests.csproj +++ b/GsaGHTests/GsaGHTests.csproj @@ -14,8 +14,8 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/IntegrationTests/IntegrationTests.csproj b/IntegrationTests/IntegrationTests.csproj index ee09ff47e..b9063c61e 100644 --- a/IntegrationTests/IntegrationTests.csproj +++ b/IntegrationTests/IntegrationTests.csproj @@ -6,8 +6,8 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all From 7e9bfde2eaf0c779b95c5836fcfeccd0388c6e5b Mon Sep 17 00:00:00 2001 From: Tilman Reinhardt Date: Mon, 6 May 2024 09:14:03 +0200 Subject: [PATCH 4/5] GSAGH-482 unit tests --- GsaGHTests/1_BaseParameters/3_Loads/GsaGridAreaLoadTest.cs | 3 +++ GsaGHTests/1_BaseParameters/3_Loads/GsaGridLineLoadTest.cs | 2 ++ 2 files changed, 5 insertions(+) diff --git a/GsaGHTests/1_BaseParameters/3_Loads/GsaGridAreaLoadTest.cs b/GsaGHTests/1_BaseParameters/3_Loads/GsaGridAreaLoadTest.cs index 5c7517a80..0825b92e7 100644 --- a/GsaGHTests/1_BaseParameters/3_Loads/GsaGridAreaLoadTest.cs +++ b/GsaGHTests/1_BaseParameters/3_Loads/GsaGridAreaLoadTest.cs @@ -1,9 +1,11 @@ using System; +using System.Collections.Generic; using GsaAPI; using GsaGH.Parameters; using GsaGHTests.Helpers; using Rhino.Geometry; using Xunit; +using Polyline = GsaAPI.Polyline; namespace GsaGHTests.Parameters { [Collection("GrasshopperFixture collection")] @@ -44,6 +46,7 @@ public class GsaGridAreaLoadTest { Type = type, Value = 10, }, + ApiPolyline = new Polyline(new List()) }; var originalGridPlaneSurface = new GsaGridPlaneSurface(); original.GridPlaneSurface = originalGridPlaneSurface; diff --git a/GsaGHTests/1_BaseParameters/3_Loads/GsaGridLineLoadTest.cs b/GsaGHTests/1_BaseParameters/3_Loads/GsaGridLineLoadTest.cs index 1ffd9d7b1..0eff5bc23 100644 --- a/GsaGHTests/1_BaseParameters/3_Loads/GsaGridLineLoadTest.cs +++ b/GsaGHTests/1_BaseParameters/3_Loads/GsaGridLineLoadTest.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using GsaAPI; using GsaGH.Parameters; using GsaGHTests.Helpers; @@ -44,6 +45,7 @@ public class GsaGridLineLoadTest { ValueAtStart = 10, ValueAtEnd = 20, }, + ApiPolyline = new Polyline(new List()) }; var duplicate = (GsaGridLineLoad)original.Duplicate(); From 1ac4e57e05071a6d5df6ebb68a28fd373638c483 Mon Sep 17 00:00:00 2001 From: Tilman Reinhardt Date: Mon, 6 May 2024 13:10:19 +0200 Subject: [PATCH 5/5] GSAGH-182 polyline definition --- GsaGHTests/1_BaseParameters/3_Loads/GsaGridAreaLoadTest.cs | 7 ++++++- GsaGHTests/1_BaseParameters/3_Loads/GsaGridLineLoadTest.cs | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/GsaGHTests/1_BaseParameters/3_Loads/GsaGridAreaLoadTest.cs b/GsaGHTests/1_BaseParameters/3_Loads/GsaGridAreaLoadTest.cs index 0825b92e7..e174a09cf 100644 --- a/GsaGHTests/1_BaseParameters/3_Loads/GsaGridAreaLoadTest.cs +++ b/GsaGHTests/1_BaseParameters/3_Loads/GsaGridAreaLoadTest.cs @@ -46,7 +46,12 @@ public class GsaGridAreaLoadTest { Type = type, Value = 10, }, - ApiPolyline = new Polyline(new List()) + ApiPolyline = new Polyline(new List() { + new Vector2(-3.1, 8.8), + new Vector2(13.6, 9.8), + new Vector2(12.2 , 14.3), + new Vector2(-0.7, 15.6), + }) }; var originalGridPlaneSurface = new GsaGridPlaneSurface(); original.GridPlaneSurface = originalGridPlaneSurface; diff --git a/GsaGHTests/1_BaseParameters/3_Loads/GsaGridLineLoadTest.cs b/GsaGHTests/1_BaseParameters/3_Loads/GsaGridLineLoadTest.cs index 0eff5bc23..5bc0e2d59 100644 --- a/GsaGHTests/1_BaseParameters/3_Loads/GsaGridLineLoadTest.cs +++ b/GsaGHTests/1_BaseParameters/3_Loads/GsaGridLineLoadTest.cs @@ -45,7 +45,12 @@ public class GsaGridLineLoadTest { ValueAtStart = 10, ValueAtEnd = 20, }, - ApiPolyline = new Polyline(new List()) + ApiPolyline = new Polyline(new List() { + new Vector2(-3.1, 8.8), + new Vector2(13.6, 9.8), + new Vector2(12.2 , 14.3), + new Vector2(-0.7, 15.6), + }) }; var duplicate = (GsaGridLineLoad)original.Duplicate();