diff --git a/ExampleFiles/Components/CreateSpringProperties.gh b/ExampleFiles/Components/CreateSpringProperties.gh index 710172305..602954a3f 100644 Binary files a/ExampleFiles/Components/CreateSpringProperties.gh and b/ExampleFiles/Components/CreateSpringProperties.gh differ diff --git a/ExampleFiles/Parameters/2_Geometry/GetGeometry_TrGen_10.gh b/ExampleFiles/Parameters/2_Geometry/GetGeometry_TrGen_10.gh index 07a57a34f..9f219b214 100644 Binary files a/ExampleFiles/Parameters/2_Geometry/GetGeometry_TrGen_10.gh and b/ExampleFiles/Parameters/2_Geometry/GetGeometry_TrGen_10.gh differ diff --git a/GsaGH/Components/0_Model/GetModelGeometry.cs b/GsaGH/Components/0_Model/GetModelGeometry.cs index 6cac06ac5..166c6a86d 100644 --- a/GsaGH/Components/0_Model/GetModelGeometry.cs +++ b/GsaGH/Components/0_Model/GetModelGeometry.cs @@ -697,7 +697,8 @@ private SolveResults Compute(GsaModel model, string nodeList, string elemList, s _results.Nodes = Nodes.GetNodes( nodeList.ToLower() == "all" ? model.ApiNodes : model.Model.Nodes(nodeList), model.ModelUnit, - model.ApiAxis); + model.ApiAxis, + model.SpringProps); _results.DisplaySupports = new ConcurrentBag(_results.Nodes.Where(n => n.Value.IsSupport)); break; diff --git a/GsaGH/Components/1_Properties/CreateSpringProperty.cs b/GsaGH/Components/1_Properties/CreateSpringProperty.cs index 4e8e110a5..479005d82 100644 --- a/GsaGH/Components/1_Properties/CreateSpringProperty.cs +++ b/GsaGH/Components/1_Properties/CreateSpringProperty.cs @@ -114,23 +114,23 @@ public override void VariableParameterMaintenance() { return; case SpringPropertyType.Torsional: - SetInputProperties(1, "Stiffness xx [" + rotationalStiffnessAbr + "]", "Sxx", "Stiffness xx", false); + SetInputProperties(1, "Stiffness xx [" + rotationalStiffnessAbr + "]", "Sxx", "Stiffness in xx direction", false); SetDampingRatioInputAt(2); return; case SpringPropertyType.General: - SetInputProperties(1, "Spring Curve x", "SCx", "[Optional] Spring Curve x"); - SetInputProperties(2, "Stiffness x [" + stiffnessAbr + "]", "Sx", "[Optional] Stiffness x"); - SetInputProperties(3, "Spring Curve y", "SCy", "[Optional] Spring Curve y"); - SetInputProperties(4, "Stiffness y [" + stiffnessAbr + "]", "Sy", "[Optional] Stiffness y"); - SetInputProperties(5, "Spring Curve z", "SCz", "[Optional] Spring Curve z"); - SetInputProperties(6, "Stiffness z [" + stiffnessAbr + "]", "Sz", "[Optional] Stiffness z"); - SetInputProperties(7, "Spring Curve xx", "SCxx", "[Optional] Spring Curve xx"); - SetInputProperties(8, "Stiffness xx [" + rotationalStiffnessAbr + "]", "Sxx", "[Optional] Stiffness xx"); - SetInputProperties(9, "Spring Curve yy", "SCyy", "[Optional] Spring Curve yy"); - SetInputProperties(10, "Stiffness yy [" + rotationalStiffnessAbr + "]", "Syy", "[Optional] Stiffness yy"); - SetInputProperties(11, "Spring Curve zz", "SCzz", "[Optional] Spring Curve zz"); - SetInputProperties(12, "Stiffness zz [" + rotationalStiffnessAbr + "]", "Szz", "[Optional] Stiffness zz"); + SetInputProperties(1, "Spring Curve x", "SCx", "[Optional] Spring Curve in x direction"); + SetInputProperties(2, "Stiffness x [" + stiffnessAbr + "]", "Sx", "[Optional] Stiffness in x direction"); + SetInputProperties(3, "Spring Curve y", "SCy", "[Optional] Spring Curve in y direction"); + SetInputProperties(4, "Stiffness y [" + stiffnessAbr + "]", "Sy", "[Optional] Stiffness in y direction"); + SetInputProperties(5, "Spring Curve z", "SCz", "[Optional] Spring Curve in z direction"); + SetInputProperties(6, "Stiffness z [" + stiffnessAbr + "]", "Sz", "[Optional] Stiffness in z direction"); + SetInputProperties(7, "Spring Curve xx", "SCxx", "[Optional] Spring Curve in xx direction"); + SetInputProperties(8, "Stiffness xx [" + rotationalStiffnessAbr + "]", "Sxx", "[Optional] Stiffness in xx direction"); + SetInputProperties(9, "Spring Curve yy", "SCyy", "[Optional] Spring Curve in yy direction"); + SetInputProperties(10, "Stiffness yy [" + rotationalStiffnessAbr + "]", "Syy", "[Optional] Stiffness in yy direction"); + SetInputProperties(11, "Spring Curve zz", "SCzz", "[Optional] Spring Curve in zz direction"); + SetInputProperties(12, "Stiffness zz [" + rotationalStiffnessAbr + "]", "Szz", "[Optional] Stiffness in zz direction"); SetDampingRatioInputAt(13); return; @@ -151,9 +151,9 @@ public override void VariableParameterMaintenance() { return; case SpringPropertyType.Friction: - SetInputProperties(1, "Stiffness x [" + stiffnessAbr + "]", "Sx", "Stiffness x", false); - SetInputProperties(2, "Stiffness y [" + stiffnessAbr + "]", "Sy", "Stiffness y", false); - SetInputProperties(3, "Stiffness z [" + stiffnessAbr + "]", "Sz", "Stiffness z", false); + SetInputProperties(1, "Stiffness x [" + stiffnessAbr + "]", "Sx", "Stiffness in x direction", false); + SetInputProperties(2, "Stiffness y [" + stiffnessAbr + "]", "Sy", "Stiffness in y direction", false); + SetInputProperties(3, "Stiffness z [" + stiffnessAbr + "]", "Sz", "Stiffness in z direction", false); SetInputProperties(4, "Coeff. of Friction [" + stiffnessAbr + "]", "CF", "Coefficient of Friction", false); SetDampingRatioInputAt(5); return; diff --git a/GsaGH/Components/1_Properties/GetSpringProperty.cs b/GsaGH/Components/1_Properties/GetSpringProperty.cs index 42a704ab8..042c0be1e 100644 --- a/GsaGH/Components/1_Properties/GetSpringProperty.cs +++ b/GsaGH/Components/1_Properties/GetSpringProperty.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using GH_IO.Serialization; @@ -25,7 +24,6 @@ public class GetSpringProperty : GH_OasysComponent, IGH_VariableParameterCompone protected override Bitmap Icon => Resources.GetSpringProperty; private RotationalStiffnessUnit _rotationalStiffnessUnit = RotationalStiffnessUnit.NewtonMeterPerRadian; private LengthUnit _lengthUnit = DefaultUnits.LengthUnitSection; - private List _rotationalStiffnessUnitAbbreviations = new List(); private ForcePerLengthUnit _stiffnessUnit = DefaultUnits.ForcePerLengthUnit; public GetSpringProperty() : base("Get Spring Property", "GetPS", @@ -148,29 +146,29 @@ protected override void RegisterOutputParams(GH_OutputParamManager pManager) { pManager.AddTextParameter("Name", "Na", "Spring Property Name", GH_ParamAccess.item); - pManager.AddTextParameter("Spring Curve x", "SCx", "Spring Curve x", GH_ParamAccess.item); + pManager.AddIntegerParameter("Spring Curve x", "SCx", "Spring Curve in x direction", GH_ParamAccess.item); - pManager.AddGenericParameter("Stiffness x [" + stiffnessAbr + "]", "Sx", "Stiffness x", GH_ParamAccess.item); + pManager.AddGenericParameter("Stiffness x [" + stiffnessAbr + "]", "Sx", "Stiffness in x direction", GH_ParamAccess.item); - pManager.AddTextParameter("Spring Curve y", "SCy", "Spring Curve y", GH_ParamAccess.item); + pManager.AddIntegerParameter("Spring Curve y", "SCy", "Spring Curve y", GH_ParamAccess.item); - pManager.AddGenericParameter("Stiffness y [" + stiffnessAbr + "]", "Sy", "Stiffness y", GH_ParamAccess.item); + pManager.AddGenericParameter("Stiffness y [" + stiffnessAbr + "]", "Sy", "Stiffness in y direction", GH_ParamAccess.item); - pManager.AddTextParameter("Spring Curve z", "SCz", "Spring Curve z", GH_ParamAccess.item); + pManager.AddIntegerParameter("Spring Curve z", "SCz", "Spring Curve z", GH_ParamAccess.item); - pManager.AddGenericParameter("Stiffness z [" + stiffnessAbr + "]", "Sz", "Stiffness z", GH_ParamAccess.item); + pManager.AddGenericParameter("Stiffness z [" + stiffnessAbr + "]", "Sz", "Stiffness in z direction", GH_ParamAccess.item); - pManager.AddTextParameter("Spring Curve xx", "SCxx", "Spring Curve xx", GH_ParamAccess.item); + pManager.AddIntegerParameter("Spring Curve xx", "SCxx", "Spring Curve xx", GH_ParamAccess.item); - pManager.AddGenericParameter("Stiffness xx [" + rotationalStiffnessAbr + "]", "Sxx", "Stiffness xx", GH_ParamAccess.item); + pManager.AddGenericParameter("Stiffness xx [" + rotationalStiffnessAbr + "]", "Sxx", "Stiffness in xx direction", GH_ParamAccess.item); - pManager.AddTextParameter("Spring Curve yy", "SCyy", "Spring Curve yy", GH_ParamAccess.item); + pManager.AddIntegerParameter("Spring Curve yy", "SCyy", "Spring Curve yy", GH_ParamAccess.item); - pManager.AddGenericParameter("Stiffness yy [" + rotationalStiffnessAbr + "]", "Syy", "Stiffness yy", GH_ParamAccess.item); + pManager.AddGenericParameter("Stiffness yy [" + rotationalStiffnessAbr + "]", "Syy", "Stiffness in yy direction", GH_ParamAccess.item); - pManager.AddTextParameter("Spring Curve zz", "SCzz", "Spring Curve zz", GH_ParamAccess.item); + pManager.AddIntegerParameter("Spring Curve zz", "SCzz", "Spring Curve zz", GH_ParamAccess.item); - pManager.AddGenericParameter("Stiffness zz [" + rotationalStiffnessAbr + "]", "Szz", "Stiffness zz", GH_ParamAccess.item); + pManager.AddGenericParameter("Stiffness zz [" + rotationalStiffnessAbr + "]", "Szz", "Stiffness in zz direction", GH_ParamAccess.item); pManager.AddGenericParameter("Spring Matrix", "SM", "Spring Matrix", GH_ParamAccess.item); @@ -186,7 +184,7 @@ protected override void RegisterOutputParams(GH_OutputParamManager pManager) { protected override void SolveInstance(IGH_DataAccess da) { GsaSpringPropertyGoo springPropertyGoo = null; if (!da.GetData(0, ref springPropertyGoo)) { - this.AddRuntimeWarning("Input PB failed to collect data"); + this.AddRuntimeWarning("Input PS failed to collect data"); return; } GsaSpringProperty springProperty = springPropertyGoo.Value; @@ -249,12 +247,12 @@ protected override void SolveInstance(IGH_DataAccess da) { case LockupSpringProperty lockup: da.SetData(14, new GH_UnitNumber(new Length((double)lockup.NegativeLockup, LengthUnit.Meter).ToUnit(_lengthUnit))); da.SetData(15, new GH_UnitNumber(new Length((double)lockup.PositiveLockup, LengthUnit.Meter).ToUnit(_lengthUnit))); - return; + break; case FrictionSpringProperty friction: - da.SetData(2, new GH_UnitNumber(new ForcePerLength((double)friction.StiffnessX, ForcePerLengthUnit.NewtonPerMeter).ToUnit(_stiffnessUnit))); - da.SetData(4, new GH_UnitNumber(new ForcePerLength((double)friction.StiffnessY, ForcePerLengthUnit.NewtonPerMeter).ToUnit(_stiffnessUnit))); - da.SetData(6, new GH_UnitNumber(new ForcePerLength((double)friction.StiffnessZ, ForcePerLengthUnit.NewtonPerMeter).ToUnit(_stiffnessUnit))); + da.SetData(2, new GH_UnitNumber(new ForcePerLength((double)friction.StiffnessX, ForcePerLengthUnit.NewtonPerMeter).ToUnit(_stiffnessUnit))); + da.SetData(4, new GH_UnitNumber(new ForcePerLength((double)friction.StiffnessY, ForcePerLengthUnit.NewtonPerMeter).ToUnit(_stiffnessUnit))); + da.SetData(6, new GH_UnitNumber(new ForcePerLength((double)friction.StiffnessZ, ForcePerLengthUnit.NewtonPerMeter).ToUnit(_stiffnessUnit))); da.SetData(16, friction.FrictionCoefficient); break; @@ -262,6 +260,7 @@ protected override void SolveInstance(IGH_DataAccess da) { default: break; } + da.SetData(17, new GH_UnitNumber(new Ratio(springProperty.ApiProperty.DampingRatio, RatioUnit.DecimalFraction).ToUnit(RatioUnit.Percent))); } diff --git a/GsaGH/Components/2_Geometry/Create1dElement.cs b/GsaGH/Components/2_Geometry/Create1dElement.cs index aadf5ac57..13e59b2a1 100644 --- a/GsaGH/Components/2_Geometry/Create1dElement.cs +++ b/GsaGH/Components/2_Geometry/Create1dElement.cs @@ -1,7 +1,10 @@ using System; using System.Drawing; +using GH_IO.Serialization; +using System.Linq; using Grasshopper.Kernel; using Grasshopper.Kernel.Types; +using GsaAPI; using GsaGH.Helpers.GH; using GsaGH.Parameters; using GsaGH.Properties; @@ -22,9 +25,18 @@ public class Create1dElement : Section3dPreviewComponent { public Create1dElement() : base("Create 1D Element", "Elem1D", "Create GSA 1D Element", CategoryName.Name(), SubCategoryName.Cat2()) { } + public override bool Read(GH_IReader reader) { + bool flag = base.Read(reader); + if (Params.Input[1].Name == new GsaSectionParameter().Name) { + Params.ReplaceInputParameter(new GsaPropertyParameter(), 1, true); + } + + return flag; + } + protected override void RegisterInputParams(GH_InputParamManager pManager) { pManager.AddLineParameter("Line", "L", "Line to create GSA Element", GH_ParamAccess.item); - pManager.AddParameter(new GsaSectionParameter()); + pManager.AddParameter(new GsaPropertyParameter()); pManager[1].Optional = true; pManager.HideParameter(0); } @@ -38,11 +50,22 @@ protected override void SolveInstance(IGH_DataAccess da) { da.GetData(0, ref ghln); var elem = new GsaElement1d(new LineCurve(ghln.Value)); - GsaSectionGoo sectionGoo = null; + GsaPropertyGoo sectionGoo = null; if (da.GetData(1, ref sectionGoo)) { - elem.Section = sectionGoo.Value; - if (Preview3dSection) { - elem.CreateSection3dPreview(); + switch (sectionGoo.Value) { + case GsaSection section: + elem.Section = section; + elem.SpringProperty = null; + if (Preview3dSection) { + elem.CreateSection3dPreview(); + } + break; + + case GsaSpringProperty springProperty: + elem.ApiElement.Type = ElementType.SPRING; + elem.Section = null; + elem.SpringProperty = springProperty; + break; } } diff --git a/GsaGH/Components/2_Geometry/Create1dMember.cs b/GsaGH/Components/2_Geometry/Create1dMember.cs index d19296acc..c7b55c899 100644 --- a/GsaGH/Components/2_Geometry/Create1dMember.cs +++ b/GsaGH/Components/2_Geometry/Create1dMember.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; using System.Drawing; +using System.Linq; using GH_IO.Serialization; using Grasshopper.Kernel; using Grasshopper.Kernel.Types; +using GsaAPI; using GsaGH.Helpers.GH; using GsaGH.Parameters; using GsaGH.Properties; @@ -92,7 +94,12 @@ public override bool Read(GH_IReader reader) { _xx2 = reader.GetBoolean("xx2"); _yy2 = reader.GetBoolean("yy2"); _zz2 = reader.GetBoolean("zz2"); - return base.Read(reader); + bool flag = base.Read(reader); + if (Params.Input[1].Name == new GsaSectionParameter().Name) { + Params.ReplaceInputParameter(new GsaPropertyParameter(), 1, true); + } + + return flag; } public void SetReleases(List> restraints) { @@ -136,7 +143,7 @@ protected override void RegisterInputParams(GH_InputParamManager pManager) { pManager.AddCurveParameter("Curve", "C", "Curve (a NURBS curve will automatically be converted in to a Polyline of Arc and Line segments)", GH_ParamAccess.item); - pManager.AddParameter(new GsaSectionParameter()); + pManager.AddParameter(new GsaPropertyParameter()); pManager.AddNumberParameter("Mesh Size in model units", "Ms", "Target mesh size", GH_ParamAccess.item); pManager[1].Optional = true; @@ -188,11 +195,22 @@ protected override void SolveInternal(IGH_DataAccess da) { }; mem.ReleaseEnd = rel2; - GsaSectionGoo sectionGoo = null; + GsaPropertyGoo sectionGoo = null; if (da.GetData(1, ref sectionGoo)) { - mem.Section = sectionGoo.Value; - if (Preview3dSection) { - mem.CreateSection3dPreview(); + switch (sectionGoo.Value) { + case GsaSection section: + mem.Section = section; + mem.SpringProperty = null; + if (Preview3dSection) { + mem.CreateSection3dPreview(); + } + break; + + case GsaSpringProperty springProperty: + mem.ApiMember.Type1D = ElementType.SPRING; + mem.Section = null; + mem.SpringProperty = springProperty; + break; } } diff --git a/GsaGH/Components/2_Geometry/Edit1dElement.cs b/GsaGH/Components/2_Geometry/Edit1dElement.cs index 569043d50..2636114e0 100644 --- a/GsaGH/Components/2_Geometry/Edit1dElement.cs +++ b/GsaGH/Components/2_Geometry/Edit1dElement.cs @@ -1,6 +1,7 @@ using System; using System.Drawing; using System.Linq; +using GH_IO.Serialization; using Grasshopper; using Grasshopper.Kernel; using Grasshopper.Kernel.Data; @@ -37,6 +38,16 @@ protected override void BeforeSolveInstance() { } } + public override bool Read(GH_IReader reader) { + bool flag = base.Read(reader); + if (Params.Input[3].Name == new GsaSectionParameter().Name) { + Params.ReplaceInputParameter(new GsaPropertyParameter(), 3, true); + Params.ReplaceOutputParameter(new GsaPropertyParameter(), 3); + } + + return flag; + } + protected override void RegisterInputParams(GH_InputParamManager pManager) { pManager.AddParameter(new GsaElement1dParameter(), GsaElement1dGoo.Name, GsaElement1dGoo.NickName, @@ -92,8 +103,7 @@ protected override void RegisterOutputParams(GH_OutputParamManager pManager) { GH_ParamAccess.item); pManager.AddLineParameter("Line", "L", "Element Line", GH_ParamAccess.item); pManager.HideParameter(2); - pManager.AddGenericParameter("Section", "PB", "Get Section or Spring Property", - GH_ParamAccess.item); + pManager.AddParameter(new GsaPropertyParameter()); pManager.AddIntegerParameter("Group", "Gr", "Get Element Group", GH_ParamAccess.item); pManager.AddTextParameter("Type", "eT", "Get Element Type", GH_ParamAccess.item); @@ -142,26 +152,27 @@ protected override void SolveInstance(IGH_DataAccess da) { if (da.GetData(3, ref sectionGoo)) { switch (sectionGoo.Value) { case GsaSection section: - if (elem.ApiElement.Type == ElementType.SPRING) { - this.AddRuntimeError("Input PB has to be a Spring Property"); - return; + if (section.IsReferencedById && elem.ApiElement.Type == ElementType.SPRING) { + elem.Section = null; + elem.SpringProperty = new GsaSpringProperty(section.Id); + } else { + if (elem.ApiElement.Type == ElementType.SPRING) { + this.AddRuntimeError("PB input must be a SpringProperty"); + return; + } + elem.Section = section; + elem.SpringProperty = null; } - elem.Section = section; - elem.SpringProperty = null; + break; case GsaSpringProperty springProperty: - if (elem.ApiElement.Type != ElementType.SPRING) { - this.AddRuntimeError("Element Type is not Spring"); - return; - } + elem.ApiElement.Type = ElementType.SPRING; + this.AddRuntimeRemark("ElementType changed to Spring"); elem.Section = null; elem.SpringProperty = springProperty; break; } - } else if (elem.ApiElement.Type == ElementType.SPRING) { - this.AddRuntimeError("Input PB has to be a Spring Property"); - return; } int id = 0; diff --git a/GsaGH/Components/2_Geometry/Edit1dMember.cs b/GsaGH/Components/2_Geometry/Edit1dMember.cs index e72183456..9eb720454 100644 --- a/GsaGH/Components/2_Geometry/Edit1dMember.cs +++ b/GsaGH/Components/2_Geometry/Edit1dMember.cs @@ -1,6 +1,7 @@ using System; using System.Drawing; using System.Linq; +using GH_IO.Serialization; using Grasshopper.Kernel; using Grasshopper.Kernel.Parameters; using Grasshopper.Kernel.Types; @@ -53,6 +54,16 @@ bool IGH_VariableParameterComponent.DestroyParameter(GH_ParameterSide side, int public void VariableParameterMaintenance() { } + public override bool Read(GH_IReader reader) { + bool flag = base.Read(reader); + if (Params.Input[3].Name == new GsaSectionParameter().Name) { + Params.ReplaceInputParameter(new GsaPropertyParameter(), 3, true); + Params.ReplaceOutputParameter(new GsaPropertyParameter(), 3); + } + + return flag; + } + protected override void RegisterInputParams(GH_InputParamManager pManager) { pManager.AddParameter(new GsaMember1dParameter(), GsaMember1dGoo.Name, GsaMember1dGoo.NickName, @@ -188,26 +199,27 @@ protected override void SolveInstance(IGH_DataAccess da) { if (da.GetData(3, ref sectionGoo)) { switch (sectionGoo.Value) { case GsaSection section: - if (mem.ApiMember.Type1D == ElementType.SPRING) { - this.AddRuntimeError("Input PB has to be a Spring Property"); - return; + if (section.IsReferencedById && mem.ApiMember.Type1D == ElementType.SPRING) { + mem.Section = null; + mem.SpringProperty = new GsaSpringProperty(section.Id); + } else { + if (mem.ApiMember.Type1D == ElementType.SPRING) { + this.AddRuntimeError("PB input must be a SpringProperty"); + return; + } + mem.Section = section; + mem.SpringProperty = null; } - mem.Section = section; - mem.SpringProperty = null; + break; case GsaSpringProperty springProperty: - if (mem.ApiMember.Type1D != ElementType.SPRING) { - this.AddRuntimeError("1D Element Type is not Spring"); - return; - } + mem.ApiMember.Type1D = ElementType.SPRING; + this.AddRuntimeRemark("ElementType changed to Spring"); mem.Section = null; mem.SpringProperty = springProperty; break; } - } else if (mem.ApiMember.Type1D == ElementType.SPRING) { - this.AddRuntimeError("Input PB has to be a Spring Property"); - return; } int id = 0; diff --git a/GsaGH/Components/2_Geometry/EditNode.cs b/GsaGH/Components/2_Geometry/EditNode.cs index 19227754d..64eec788f 100644 --- a/GsaGH/Components/2_Geometry/EditNode.cs +++ b/GsaGH/Components/2_Geometry/EditNode.cs @@ -1,5 +1,6 @@ using System; using System.Drawing; +using System.Linq; using System.Windows.Forms; using GH_IO.Serialization; using Grasshopper.Kernel; @@ -49,7 +50,13 @@ public bool DestroyParameter(GH_ParameterSide side, int index) { public override bool Read(GH_IReader reader) { _mode = (FoldMode)reader.GetInt32("Mode"); - return base.Read(reader); + bool flag = base.Read(reader); + if (Params.Input[7].Description == "Set Spring Property by reference") { + Params.ReplaceInputParameter(new GsaSpringPropertyParameter(), 7, true); + Params.ReplaceOutputParameter(new GsaSpringPropertyParameter(), 7); + } + + return flag; } public void VariableParameterMaintenance() { @@ -95,8 +102,7 @@ protected override void RegisterInputParams(GH_InputParamManager pManager) { GH_ParamAccess.item); pManager.AddIntegerParameter("Mass Property", "MP", "Set Mass Property by reference", GH_ParamAccess.item); - pManager.AddIntegerParameter("Spring Property", "SP", "Set Spring Property by reference", - GH_ParamAccess.item); + pManager.AddParameter(new GsaSpringPropertyParameter()); pManager.AddTextParameter("Node Name", "Na", "Set Name of Node", GH_ParamAccess.item); pManager.AddColourParameter("Node Colour", "Co", "Set colour of node", GH_ParamAccess.item); @@ -127,8 +133,7 @@ protected override void RegisterOutputParams(GH_OutputParamManager pManager) { GH_ParamAccess.item); pManager.AddIntegerParameter("Mass Property", "MP", "Get Mass Property reference", GH_ParamAccess.item); - pManager.AddIntegerParameter("Spring Property", "SP", "Get Spring Property reference", - GH_ParamAccess.item); + pManager.AddParameter(new GsaSpringPropertyParameter()); pManager.AddTextParameter("Node Name", "Na", "Name of Node", GH_ParamAccess.item); pManager.AddColourParameter("Node Colour", "Co", "Get colour of node", GH_ParamAccess.item); if (_mode != FoldMode.GetConnected) { @@ -185,9 +190,9 @@ protected override void SolveInstance(IGH_DataAccess da) { node.ApiNode.MassProperty = massId; } - int springId = 0; - if (da.GetData(7, ref springId)) { - node.ApiNode.SpringProperty = springId; + GsaSpringPropertyGoo springGoo = null; + if (da.GetData(7, ref springGoo)) { + node.SpringProperty = springGoo.Value; } string name = string.Empty; @@ -207,7 +212,7 @@ protected override void SolveInstance(IGH_DataAccess da) { da.SetData(4, new GsaBool6Goo(node.Restraint)); da.SetData(5, node.ApiNode.DamperProperty); da.SetData(6, node.ApiNode.MassProperty); - da.SetData(7, node.ApiNode.SpringProperty); + da.SetData(7, new GsaSpringPropertyGoo(node.SpringProperty)); da.SetData(8, node.ApiNode?.Name); da.SetData(9, node.ApiNode.Colour); diff --git a/GsaGH/Components/2_Geometry/ExpandBeamToShell.cs b/GsaGH/Components/2_Geometry/ExpandBeamToShell.cs index 91864916e..e14c601fb 100644 --- a/GsaGH/Components/2_Geometry/ExpandBeamToShell.cs +++ b/GsaGH/Components/2_Geometry/ExpandBeamToShell.cs @@ -23,12 +23,9 @@ using LengthUnit = OasysUnits.Units.LengthUnit; namespace GsaGH.Components { - /// - /// Component to edit a Node - /// public class ExpandBeamToShell : GH_OasysComponent, IGH_VariableParameterComponent { public override Guid ComponentGuid => new Guid("42221f6b-b0f1-41ae-abcf-df5521565464"); - public override GH_Exposure Exposure => GH_Exposure.senary | GH_Exposure.obscure; + public override GH_Exposure Exposure => GH_Exposure.quarternary; public override OasysPluginInfo PluginInfo => GsaGH.PluginInfo.Instance; protected override Bitmap Icon => Resources.ExpandBeamToShell; private LengthUnit _lengthUnit = DefaultUnits.LengthUnitGeometry; diff --git a/GsaGH/Helpers/Assembly/Geometry/Nodes.cs b/GsaGH/Helpers/Assembly/Geometry/Nodes.cs index a6844000b..7e24c2e4f 100644 --- a/GsaGH/Helpers/Assembly/Geometry/Nodes.cs +++ b/GsaGH/Helpers/Assembly/Geometry/Nodes.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using GsaAPI; +using GsaGH.Helpers.Import; using GsaGH.Parameters; using OasysUnits; using Rhino.Geometry; @@ -61,9 +62,10 @@ private void ConvertNode(GsaNode node) { apiNode.AxisProperty = TryGetExistingAxisId(ax); } - if ( - // if the ID is larger than 0 than means the ID has been set and we sent it to the known list - node.Id > 0) { + apiNode.SpringProperty = ConvertSpringProp(node.SpringProperty); + + // if the ID is larger than 0 than means the ID has been set and we sent it to the known list + if (node.Id > 0) { _nodes.SetValue(node.Id, apiNode); } else { AddNode(apiNode); diff --git a/GsaGH/Helpers/Assembly/ModelAssembly.cs b/GsaGH/Helpers/Assembly/ModelAssembly.cs index 7bb9bd04e..041ccc545 100644 --- a/GsaGH/Helpers/Assembly/ModelAssembly.cs +++ b/GsaGH/Helpers/Assembly/ModelAssembly.cs @@ -76,8 +76,8 @@ internal ModelAssembly( SetupModel(model, modelUnit); - ConvertNodes(nodes); ConvertProperties(mats, sections, prop2Ds, prop3Ds, springProps); + ConvertNodes(nodes); ConvertElements(elem1ds, elem2ds, elem3ds); ConvertMembers(mem1ds, mem2ds, mem3ds); ConvertNodeList(lists); @@ -512,10 +512,8 @@ private void SetupModel(GsaModel model, LengthUnit unit) { _model.UiUnits().LengthLarge = UnitMapping.GetApiUnit(_unit); UiUnits units = _model.UiUnits(); - _springProperties = new GsaGuidDictionary(_model.SpringProperties()); - _nodes = new GsaIntDictionary(model.ApiNodes); _axes = new GsaIntDictionary(model.ApiAxis); _elements = new GsaGuidIntListDictionary(_model.Elements()); diff --git a/GsaGH/Helpers/GH/ReplaceParam.cs b/GsaGH/Helpers/GH/ReplaceParam.cs new file mode 100644 index 000000000..b09fe1e70 --- /dev/null +++ b/GsaGH/Helpers/GH/ReplaceParam.cs @@ -0,0 +1,26 @@ +using System; +using System.Linq; +using Grasshopper.Kernel; + +namespace GsaGH.Helpers.GH { + public static class ReplaceParam { + public static void ReplaceInputParameter( + this GH_ComponentParamServer parameters, IGH_Param newParam, int id, bool optional = false) { + var sources = parameters.Input[id].Sources.ToList(); + parameters.UnregisterInputParameter(parameters.Input[id], false); + parameters.RegisterInputParam(newParam, id); + parameters.Input[id].Optional = optional; + foreach (IGH_Param source in sources) { + parameters.Input[id].AddSource(source); + } + } + + public static void ReplaceOutputParameter( + this GH_ComponentParamServer parameters, IGH_Param newParam, int id) { + Guid guid = parameters.Output[id].InstanceGuid; + parameters.UnregisterOutputParameter(parameters.Output[id], false); + parameters.RegisterOutputParam(newParam, id); + parameters.Output[id].NewInstanceGuid(guid); + } + } +} diff --git a/GsaGH/Helpers/Import/Nodes.cs b/GsaGH/Helpers/Import/Nodes.cs index 7a1aadba1..529138a76 100644 --- a/GsaGH/Helpers/Import/Nodes.cs +++ b/GsaGH/Helpers/Import/Nodes.cs @@ -113,15 +113,23 @@ internal static ConcurrentDictionary GetNodeDictionary( /// /// Dictionary of GSA Nodes pre-filtered for nodes to import /// + /// /// /// internal static ConcurrentBag GetNodes( ReadOnlyDictionary nDict, LengthUnit unit, - ReadOnlyDictionary axDict = null) { + ReadOnlyDictionary axDict = null, + ReadOnlyDictionary springProps = null) { var outNodes = new ConcurrentBag(); - Parallel.ForEach(nDict, node => - outNodes.Add(new GsaNodeGoo(GetNode(node.Value, unit, node.Key, axDict))) - ); + Parallel.ForEach(nDict, node => { + GsaNode n = GetNode(node.Value, unit, node.Key, axDict); + if (springProps != null && node.Value.SpringProperty != 0 + && springProps.ContainsKey(node.Value.SpringProperty)) { + n.SpringProperty = springProps[node.Value.SpringProperty].Value; + } + + outNodes.Add(new GsaNodeGoo(n)); + }); return outNodes; } diff --git a/GsaGH/Helpers/MergeModels.cs b/GsaGH/Helpers/MergeModels.cs index 5dae8dc22..637c5b90d 100644 --- a/GsaGH/Helpers/MergeModels.cs +++ b/GsaGH/Helpers/MergeModels.cs @@ -36,7 +36,8 @@ public static GsaModel MergeModel( GsaModel mainModel, GsaModel appendModel, GH_Component owner, Length tolerance) { appendModel.ModelUnit = mainModel.ModelUnit; ConcurrentBag goonodes = - Import.Nodes.GetNodes(appendModel.ApiNodes, mainModel.ModelUnit); + Import.Nodes.GetNodes( + appendModel.ApiNodes, mainModel.ModelUnit, appendModel.ApiAxis, appendModel.SpringProps); var nodes = goonodes.Select(n => n.Value).OrderByDescending(x => x.Id).ToList(); nodes.Select(c => { c.Id = 0; // set node Id of incoming to 0 to append to end and use CollapseCoincidingNodes diff --git a/GsaGH/Parameters/0_Model/GsaList.cs b/GsaGH/Parameters/0_Model/GsaList.cs index 50d5d42a8..901b70be8 100644 --- a/GsaGH/Parameters/0_Model/GsaList.cs +++ b/GsaGH/Parameters/0_Model/GsaList.cs @@ -424,7 +424,8 @@ private void PopulateListObjectsFromModel(LengthUnit unit) { switch (EntityType) { case EntityType.Node: - _nodes = Nodes.GetNodes(_model.Model.Nodes(Definition), unit, _model.Model.Axes()); + _nodes = Nodes.GetNodes( + _model.Model.Nodes(Definition), unit, _model.Model.Axes(), _model.SpringProps); break; case EntityType.Element: diff --git a/GsaGH/Parameters/1_Properties/GsaPropertyGoo.cs b/GsaGH/Parameters/1_Properties/GsaPropertyGoo.cs index e15d6494f..8df8c267c 100644 --- a/GsaGH/Parameters/1_Properties/GsaPropertyGoo.cs +++ b/GsaGH/Parameters/1_Properties/GsaPropertyGoo.cs @@ -17,5 +17,14 @@ public GsaPropertyGoo(IGsaProperty item) : base(item) { } public override IGH_Goo Duplicate() { return new GsaPropertyGoo(Value); } + + public override string ToString() { + if (Value == null) { + return "Null"; + } + + string typeName = Value.GetType().Name.TrimStart('I').Replace("Gsa", string.Empty); + return PluginInfo.ProductName + " " + typeName + " (" + Value.ToString() + ")"; + } } } diff --git a/GsaGH/Parameters/1_Properties/GsaPropertyParameter.cs b/GsaGH/Parameters/1_Properties/GsaPropertyParameter.cs index e64d7c265..c0dae54a2 100644 --- a/GsaGH/Parameters/1_Properties/GsaPropertyParameter.cs +++ b/GsaGH/Parameters/1_Properties/GsaPropertyParameter.cs @@ -26,28 +26,10 @@ protected override GsaPropertyGoo PreferredCast(object data) { string mes = string.Empty; string defaultText = $"{data.GetTypeName()} does not contain a Section"; switch (data) { - case GsaElement1dGoo elem1d: - if (elem1d.Value.Section == null) { - mes = defaultText; - break; - } - - return new GsaPropertyGoo(elem1d.Value.Section); - - case GsaMember1dGoo mem1d: - if (mem1d.Value.Section == null) { - mes = defaultText; - break; - } - - return new GsaPropertyGoo(mem1d.Value.Section); + case GsaSectionGoo section: + return new GsaPropertyGoo(section.Value); case GsaSpringPropertyGoo springProperty: - if (springProperty.Value.ApiProperty == null) { - mes = defaultText; - break; - } - return new GsaPropertyGoo(springProperty.Value); } diff --git a/GsaGH/Parameters/1_Properties/GsaSectionGoo.cs b/GsaGH/Parameters/1_Properties/GsaSectionGoo.cs index aa82b07fe..1afc5ac04 100644 --- a/GsaGH/Parameters/1_Properties/GsaSectionGoo.cs +++ b/GsaGH/Parameters/1_Properties/GsaSectionGoo.cs @@ -21,7 +21,7 @@ public override bool CastTo(ref TQ target) { return true; } } - + target = default; return false; } diff --git a/GsaGH/Parameters/1_Properties/GsaSectionParameter.cs b/GsaGH/Parameters/1_Properties/GsaSectionParameter.cs index b9ebbeac5..f1683b2f8 100644 --- a/GsaGH/Parameters/1_Properties/GsaSectionParameter.cs +++ b/GsaGH/Parameters/1_Properties/GsaSectionParameter.cs @@ -41,6 +41,14 @@ protected override GsaSectionGoo PreferredCast(object data) { } return new GsaSectionGoo(mem1d.Value.Section); + + case GsaPropertyGoo prop: + if (prop.Value is GsaSection section) { + return new GsaSectionGoo(section); + } else { + this.AddRuntimeError($"Data conversion failed from Spring to Section" + mes); + return new GsaSectionGoo(null); + } } if (!string.IsNullOrEmpty(mes)) { diff --git a/GsaGH/Parameters/1_Properties/GsaSpringProperty.cs b/GsaGH/Parameters/1_Properties/GsaSpringProperty.cs index a06236e63..df707bbf0 100644 --- a/GsaGH/Parameters/1_Properties/GsaSpringProperty.cs +++ b/GsaGH/Parameters/1_Properties/GsaSpringProperty.cs @@ -1,9 +1,20 @@ using System; using System.Collections.Generic; +using System.Configuration; +using System.Drawing; using System.Linq; +using System.Windows.Forms.VisualStyles; using GsaAPI; using GsaGH.Helpers; using GsaGH.Helpers.GsaApi; +using OasysGH.Parameters; +using OasysUnits.Units; +using OasysUnits; +using OasysGH.Units; +using LengthUnit = OasysUnits.Units.LengthUnit; +using Newtonsoft.Json.Linq; +using static Rhino.Render.TextureGraphInfo; +using Grasshopper.Kernel.Types.Transforms; namespace GsaGH.Parameters { /// @@ -125,7 +136,11 @@ public SpringProperty DuplicateApiObject() { return null; } - property.Colour = ApiProperty.Colour; + // workaround to handle that Color is non-nullable type + if ((Color)ApiProperty.Colour != Color.FromArgb(0, 0, 0)) { + property.Colour = ApiProperty.Colour; + } + property.DampingRatio = ApiProperty.DampingRatio; property.Name = ApiProperty.Name; @@ -140,7 +155,104 @@ public override string ToString() { string name = ApiProperty.Name; string type = Mappings.SpringPropertyTypeMapping.FirstOrDefault(x => x.Value == ApiProperty.GetType()).Key; - return string.Join(" ", ps, type, name).TrimSpaces(); + string values = SpringValuesToString(); + return string.Join(" ", ps, type, name, values).TrimSpaces(); + } + + private string SpringValuesToString() { + string value = string.Empty; + RotationalStiffnessUnit _rotationalStiffnessUnit = RotationalStiffnessUnit.NewtonMeterPerRadian; + LengthUnit _lengthUnit = DefaultUnits.LengthUnitSection; + ForcePerLengthUnit _stiffnessUnit = DefaultUnits.ForcePerLengthUnit; + switch (ApiProperty) { + case AxialSpringProperty axial: + value = new ForcePerLength(axial.Stiffness, ForcePerLengthUnit.NewtonPerMeter) + .ToUnit(_stiffnessUnit).ToString().Replace(" ", string.Empty); + break; + + case TensionSpringProperty tension: + value = new ForcePerLength(tension.Stiffness, ForcePerLengthUnit.NewtonPerMeter) + .ToUnit(_stiffnessUnit).ToString().Replace(" ", string.Empty); + break; + + case CompressionSpringProperty compression: + value = new ForcePerLength(compression.Stiffness, ForcePerLengthUnit.NewtonPerMeter) + .ToUnit(_stiffnessUnit).ToString().Replace(" ", string.Empty); + break; + + case GapSpringProperty gap: + value = new ForcePerLength(gap.Stiffness, ForcePerLengthUnit.NewtonPerMeter) + .ToUnit(_stiffnessUnit).ToString().Replace(" ", string.Empty); + break; + + case TorsionalSpringProperty torsional: + value = new RotationalStiffness(torsional.Stiffness, RotationalStiffnessUnit.NewtonMeterPerRadian) + .ToUnit(_rotationalStiffnessUnit).ToString().Replace(" ", string.Empty); + break; + + case GeneralSpringProperty general: + string x = GeneralSpringToString("X", general.SpringCurveX, general.StiffnessX); + string y = GeneralSpringToString("Y", general.SpringCurveY, general.StiffnessY); + string z = GeneralSpringToString("Z", general.SpringCurveZ, general.StiffnessZ); + string xx = GeneralRotationalSpringToString( + "XX", general.SpringCurveXX, general.StiffnessXX); + string yy = GeneralRotationalSpringToString( + "YY", general.SpringCurveYY, general.StiffnessYY); + string zz = GeneralRotationalSpringToString( + "ZZ", general.SpringCurveZZ, general.StiffnessZZ); + value = string.Join(" ", x, y, z, xx, yy, zz); + break; + + case MatrixSpringProperty matrix: + value = $"MatrixID:{matrix.SpringMatrix}"; + break; + + case LockupSpringProperty lockup: + value = "+ve:" + new Length((double)lockup.PositiveLockup, LengthUnit.Meter) + .ToUnit(_lengthUnit).ToString().Replace(" ", string.Empty) + + " -ve:" + new Length((double)lockup.NegativeLockup, LengthUnit.Meter) + .ToUnit(_lengthUnit).ToString().Replace(" ", string.Empty); + break; + + case FrictionSpringProperty friction: + string fx = GeneralSpringToString("X", null, friction.StiffnessX); + string fy = GeneralSpringToString("Y", null, friction.StiffnessY); + string fz = GeneralSpringToString("Z", null, friction.StiffnessZ); + string coeff = friction.FrictionCoefficient == 0 ? string.Empty + : $"Coeff.:{friction.FrictionCoefficient}"; + value = string.Join(" ", fx, fy, fz, coeff); + break; + case ConnectorSpringProperty connector: + default: + break; + } + + string damping = ApiProperty.DampingRatio == 0 ? string.Empty + : new Ratio(ApiProperty.DampingRatio, RatioUnit.DecimalFraction).ToUnit(RatioUnit.Percent).ToString().Replace(" ", string.Empty); + + return string.Join(" ", value, damping).Replace(",", string.Empty).TrimSpaces(); + } + + private string GeneralSpringToString(string prefix, int? curve, double? stiffness) { + if (curve == null && stiffness == null) { + return string.Empty; + } + + string val = curve != null ? $"CurveID:{curve}" + : new ForcePerLength((double)stiffness, ForcePerLengthUnit.NewtonPerMeter) + .ToUnit(DefaultUnits.ForcePerLengthUnit).ToString().Replace(" ", string.Empty); + return $"{prefix}:{val}"; + } + + private string GeneralRotationalSpringToString(string prefix, int? curve, double? stiffness) { + if (curve == null && stiffness == null) { + return string.Empty; + } + + string val = curve != null ? $"CurveID:{curve}" + : new RotationalStiffness((double)stiffness, RotationalStiffnessUnit.NewtonMeterPerRadian) + .ToString().Replace(" ", string.Empty); + return $"{prefix}:{val}"; } } } diff --git a/GsaGH/Parameters/1_Properties/GsaSpringPropertyParameter.cs b/GsaGH/Parameters/1_Properties/GsaSpringPropertyParameter.cs index ea3981a98..27da8c3e4 100644 --- a/GsaGH/Parameters/1_Properties/GsaSpringPropertyParameter.cs +++ b/GsaGH/Parameters/1_Properties/GsaSpringPropertyParameter.cs @@ -26,6 +26,15 @@ protected override GsaSpringPropertyGoo PreferredCast(object data) { string mes = string.Empty; string defaultText = $"{data.GetTypeName()} does not contain a Spring Property"; + if (data is GsaPropertyGoo prop) { + if (prop.Value is GsaSpringProperty spring) { + return new GsaSpringPropertyGoo(spring); + } else { + this.AddRuntimeError($"Data conversion failed from Section to Spring" + mes); + return new GsaSpringPropertyGoo(null); + } + } + if (GH_Convert.ToInt32(data, out int id, GH_Conversion.Both)) { GH_Convert.ToString(data, out string val, GH_Conversion.Both); if (!val.Contains(".")) { diff --git a/GsaGH/Parameters/2_Geometry/GsaNode.cs b/GsaGH/Parameters/2_Geometry/GsaNode.cs index 1d9d058c5..234f8eb3e 100644 --- a/GsaGH/Parameters/2_Geometry/GsaNode.cs +++ b/GsaGH/Parameters/2_Geometry/GsaNode.cs @@ -17,6 +17,7 @@ public class GsaNode { public Node ApiNode { get; internal set; } public int Id { get; set; } = 0; public Plane LocalAxis { get; set; } = Plane.WorldXY; + public GsaSpringProperty SpringProperty { get; set; } public SupportPreview SupportPreview { get; private set; } public bool IsSupport => IsRestrained(); public bool IsGlobalAxis => CheckGlobalAxis(); @@ -54,6 +55,7 @@ public GsaNode(GsaNode other) { ApiNode = other.DuplicateApiObject(); LocalAxis = other.LocalAxis; SupportPreview = other.SupportPreview; + SpringProperty = other.SpringProperty; } /// diff --git a/GsaGHTests/1_BaseParameters/1_Properties/GsaSpringPropertyTest.cs b/GsaGHTests/1_BaseParameters/1_Properties/GsaSpringPropertyTest.cs index 178c695c9..af8a0cc0d 100644 --- a/GsaGHTests/1_BaseParameters/1_Properties/GsaSpringPropertyTest.cs +++ b/GsaGHTests/1_BaseParameters/1_Properties/GsaSpringPropertyTest.cs @@ -397,5 +397,176 @@ public void DuplicateReferenceTest2() { var duplicate = new GsaSpringProperty(original); Duplicates.AreEqual(original, duplicate, new List() { "Guid" }); } + + [Fact] + public void ToStringAxialTest() { + var spring = new GsaSpringProperty { + ApiProperty = new AxialSpringProperty() { + Colour = Color.Yellow, + DampingRatio = 0.1, + Name = "Name", + Stiffness = 1.2 + } + }; + + Assert.Equal("Axial Name 0.0012kN/m 10%", spring.ToString()); + } + + [Fact] + public void ToStringTorsionalTest() { + var spring = new GsaSpringProperty { + ApiProperty = new TorsionalSpringProperty() { + Colour = Color.Yellow, + DampingRatio = 0.1, + Name = "Name", + Stiffness = 1.2 + } + }; + + Assert.Equal("Torsional Name 1.2N·m/rad 10%", spring.ToString()); + } + + [Fact] + public void ToStringGeneralTest1() { + var spring = new GsaSpringProperty { + ApiProperty = new GeneralSpringProperty() { + Colour = Color.Yellow, + DampingRatio = 0.1, + Name = "Name", + StiffnessX = 1.2, + StiffnessY = 2.2, + StiffnessZ = 3.2, + StiffnessXX = 4.2, + StiffnessYY = 4.2, + StiffnessZZ = 4.2, + } + }; + + Assert.Equal("General Name X:0.0012kN/m Y:0.0022kN/m Z:0.0032kN/m XX:4.2N·m/rad " + + "YY:4.2N·m/rad ZZ:4.2N·m/rad 10%", spring.ToString()); + } + + [Fact] + public void ToStringGeneralTest2() { + var spring = new GsaSpringProperty { + ApiProperty = new GeneralSpringProperty() { + Colour = Color.Yellow, + DampingRatio = 0.1, + Name = "Name", + SpringCurveX = 1, + SpringCurveY = 2, + SpringCurveZ = 3, + SpringCurveXX = 4, + SpringCurveYY = 5, + SpringCurveZZ = 6 + } + }; + + Assert.Equal("General Name X:CurveID:1 Y:CurveID:2 Z:CurveID:3 XX:CurveID:4 YY:CurveID:5" + + " ZZ:CurveID:6 10%", spring.ToString()); + } + + [Fact] + public void ToStringMatrixTest() { + var spring = new GsaSpringProperty { + ApiProperty = new MatrixSpringProperty() { + Colour = Color.Yellow, + DampingRatio = 0.1, + Name = "Name", + SpringMatrix = 2 + } + }; + + Assert.Equal("Matrix Name MatrixID:2 10%", spring.ToString()); + } + + [Fact] + public void ToStringTensionOnlyTest() { + var spring = new GsaSpringProperty { + ApiProperty = new TensionSpringProperty() { + Colour = Color.Yellow, + DampingRatio = 0.1, + Name = "Name", + Stiffness = 1.2 + } + }; + + Assert.Equal("Tension-only Name 0.0012kN/m 10%", spring.ToString()); + } + + [Fact] + public void ToStringCompressionOnlyTest() { + var spring = new GsaSpringProperty { + ApiProperty = new CompressionSpringProperty() { + Colour = Color.Yellow, + DampingRatio = 0.1, + Name = "Name", + Stiffness = 1.2 + } + }; + + Assert.Equal("Compression-only Name 0.0012kN/m 10%", spring.ToString()); + } + + [Fact] + public void ToStringConnectorTest() { + var spring = new GsaSpringProperty { + ApiProperty = new ConnectorSpringProperty() { + Colour = Color.Yellow, + DampingRatio = 0.1, + Name = "Name" + } + }; + + Assert.Equal("Connector Name 10%", spring.ToString()); + } + + [Fact] + public void ToStringLockupTest() { + var spring = new GsaSpringProperty { + ApiProperty = new LockupSpringProperty() { + Colour = Color.Yellow, + DampingRatio = 0.1, + Name = "Name", + Stiffness = 1.2, + NegativeLockup = 2.1, + PositiveLockup = 3.1, + } + }; + + Assert.Equal("Lockup Name +ve:310cm -ve:210cm 10%", spring.ToString()); + } + + [Fact] + public void ToStringGapTest() { + var spring = new GsaSpringProperty { + ApiProperty = new GapSpringProperty() { + Colour = Color.Yellow, + DampingRatio = 0.1, + Name = "Name", + Stiffness = 1.2 + } + }; + + Assert.Equal("Gap Name 0.0012kN/m 10%", spring.ToString()); + } + + [Fact] + public void ToStringFrictionTest() { + var spring = new GsaSpringProperty { + ApiProperty = new FrictionSpringProperty() { + Colour = Color.Yellow, + DampingRatio = 0.1, + Name = "Name", + StiffnessX = 1.2, + StiffnessY = 2.2, + StiffnessZ = 3.2, + FrictionCoefficient = 0.1 + } + }; + + Assert.Equal("Friction Name X:0.0012kN/m Y:0.0022kN/m Z:0.0032kN/m Coeff.:0.1 10%", + spring.ToString()); + } } } diff --git a/GsaGHTests/2_GooWrappers/PersistentParameters/GH_OasysPersistentParamTest.cs b/GsaGHTests/2_GooWrappers/PersistentParameters/GH_OasysPersistentParamTest.cs index 9d122653d..93f37eee8 100644 --- a/GsaGHTests/2_GooWrappers/PersistentParameters/GH_OasysPersistentParamTest.cs +++ b/GsaGHTests/2_GooWrappers/PersistentParameters/GH_OasysPersistentParamTest.cs @@ -19,6 +19,7 @@ public class GH_OasysPersistentParamTest { [InlineData(typeof(GsaBool6Parameter))] [InlineData(typeof(GsaMaterialParameter))] [InlineData(typeof(GsaOffsetParameter))] + [InlineData(typeof(GsaPropertyParameter), true)] [InlineData(typeof(GsaProperty2dParameter))] [InlineData(typeof(GsaProperty3dParameter))] [InlineData(typeof(GsaSectionModifierParameter))] diff --git a/GsaGHTests/3_Components/2_Geometry/EditElement1dTests.cs b/GsaGHTests/3_Components/2_Geometry/EditElement1dTests.cs index 7c598c43b..ebe7fbec3 100644 --- a/GsaGHTests/3_Components/2_Geometry/EditElement1dTests.cs +++ b/GsaGHTests/3_Components/2_Geometry/EditElement1dTests.cs @@ -31,7 +31,7 @@ public void GetOutputsFromInputElements() { var elem = (GsaElement1dGoo)ComponentTestHelper.GetOutput(comp, 0); var id = (GH_Integer)ComponentTestHelper.GetOutput(comp, 1); var line = (GH_Line)ComponentTestHelper.GetOutput(comp, 2); - var section = (GsaSectionGoo)ComponentTestHelper.GetOutput(comp, 3); + var section = (GsaPropertyGoo)ComponentTestHelper.GetOutput(comp, 3); var group = (GH_Integer)ComponentTestHelper.GetOutput(comp, 4); var type = (GH_String)ComponentTestHelper.GetOutput(comp, 5); var offset = (GsaOffsetGoo)ComponentTestHelper.GetOutput(comp, 6); @@ -58,7 +58,7 @@ public void GetOutputsFromInputElements() { Assert.Equal(7, line.Value.To.X, 6); Assert.Equal(3, line.Value.To.Y, 6); Assert.Equal(1, line.Value.To.Z, 6); - Assert.Equal("STD CH(ft) 1 2 3 4", section.Value.ApiSection.Profile); + Assert.Equal("STD CH(ft) 1 2 3 4", ((GsaSection)section.Value).ApiSection.Profile); Assert.Equal(0, group.Value); Assert.Equal("Beam", type.Value); Assert.Equal(0, offset.Value.X1.Value, 6); @@ -113,7 +113,7 @@ public void EditElementByInputs() { var elem = (GsaElement1dGoo)ComponentTestHelper.GetOutput(comp, 0); var id = (GH_Integer)ComponentTestHelper.GetOutput(comp, 1); var line = (GH_Line)ComponentTestHelper.GetOutput(comp, 2); - var section = (GsaSectionGoo)ComponentTestHelper.GetOutput(comp, 3); + var section = (GsaPropertyGoo)ComponentTestHelper.GetOutput(comp, 3); var group = (GH_Integer)ComponentTestHelper.GetOutput(comp, 4); var type = (GH_String)ComponentTestHelper.GetOutput(comp, 5); var offset = (GsaOffsetGoo)ComponentTestHelper.GetOutput(comp, 6); @@ -140,7 +140,7 @@ public void EditElementByInputs() { Assert.Equal(1, line.Value.To.X); Assert.Equal(2, line.Value.To.Y); Assert.Equal(3, line.Value.To.Z); - Assert.Equal("STD CH 10 20 30 40", section.Value.ApiSection.Profile); + Assert.Equal("STD CH 10 20 30 40", ((GsaSection)section.Value).ApiSection.Profile); Assert.Equal(7, group.Value); Assert.Equal("Beam", type.Value); Assert.Equal(1, offset.Value.X1.Value); @@ -192,7 +192,7 @@ public void ChangeToSpringElement() { var elem = (GsaElement1dGoo)ComponentTestHelper.GetOutput(comp, 0); var id = (GH_Integer)ComponentTestHelper.GetOutput(comp, 1); var line = (GH_Line)ComponentTestHelper.GetOutput(comp, 2); - var springProperty = (GsaSpringPropertyGoo)ComponentTestHelper.GetOutput(comp, 3); + var springProperty = (GsaPropertyGoo)ComponentTestHelper.GetOutput(comp, 3); var group = (GH_Integer)ComponentTestHelper.GetOutput(comp, 4); var type = (GH_String)ComponentTestHelper.GetOutput(comp, 5); var offset = (GsaOffsetGoo)ComponentTestHelper.GetOutput(comp, 6); @@ -219,7 +219,7 @@ public void ChangeToSpringElement() { Assert.Equal(7, line.Value.To.X, 6); Assert.Equal(3, line.Value.To.Y, 6); Assert.Equal(1, line.Value.To.Z, 6); - Assert.NotNull(springProperty.Value.ApiProperty); + Assert.NotNull(((GsaSpringProperty)springProperty.Value).ApiProperty); Assert.Equal(0, group.Value); Assert.Equal("Spring", type.Value); Assert.Equal(0, offset.Value.X1.Value, 6); @@ -254,12 +254,12 @@ public void InvalidPropertyElementTypeCombination1() { var property = new AxialSpringProperty { Stiffness = 3.0 }; - ComponentTestHelper.SetInput(comp, new GsaPropertyGoo(new GsaSpringProperty(property)), 3); + ComponentTestHelper.SetInput(comp, new GsaSpringPropertyGoo(new GsaSpringProperty(property)), 3); ComponentTestHelper.SetInput(comp, "Beam", 5); comp.Params.Output[0].ExpireSolution(true); comp.Params.Output[0].CollectData(); - Assert.Single(comp.RuntimeMessages(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error)); + Assert.Empty(comp.RuntimeMessages(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error)); } [Fact] @@ -281,7 +281,7 @@ public void InvalidPropertyElementTypeCombination3() { comp.Params.Output[0].ExpireSolution(true); comp.Params.Output[0].CollectData(); - Assert.Single(comp.RuntimeMessages(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error)); + Assert.Empty(comp.RuntimeMessages(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error)); } } } diff --git a/GsaGHTests/3_Components/2_Geometry/EditMember1dTests.cs b/GsaGHTests/3_Components/2_Geometry/EditMember1dTests.cs index 6a0d59210..ce7ea65fc 100644 --- a/GsaGHTests/3_Components/2_Geometry/EditMember1dTests.cs +++ b/GsaGHTests/3_Components/2_Geometry/EditMember1dTests.cs @@ -318,7 +318,7 @@ public void InvalidPropertyElement1DTypeCombination1() { comp.Params.Output[0].ExpireSolution(true); comp.Params.Output[0].CollectData(); - Assert.Single(comp.RuntimeMessages(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error)); + Assert.Single(comp.RuntimeMessages(Grasshopper.Kernel.GH_RuntimeMessageLevel.Remark)); } [Fact] @@ -340,7 +340,7 @@ public void InvalidPropertyElement1DTypeCombination3() { comp.Params.Output[0].ExpireSolution(true); comp.Params.Output[0].CollectData(); - Assert.Single(comp.RuntimeMessages(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error)); + Assert.Empty(comp.RuntimeMessages(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error)); } } } diff --git a/GsaGHTests/3_Components/2_Geometry/EditNodeTests.cs b/GsaGHTests/3_Components/2_Geometry/EditNodeTests.cs index eb96589d8..15f862a7b 100644 --- a/GsaGHTests/3_Components/2_Geometry/EditNodeTests.cs +++ b/GsaGHTests/3_Components/2_Geometry/EditNodeTests.cs @@ -33,7 +33,7 @@ public void GetValuesTest() { var output4 = (GsaBool6Goo)ComponentTestHelper.GetOutput(comp, 4); var output5 = (GH_Integer)ComponentTestHelper.GetOutput(comp, 5); var output6 = (GH_Integer)ComponentTestHelper.GetOutput(comp, 6); - var output7 = (GH_Integer)ComponentTestHelper.GetOutput(comp, 7); + var output7 = (GsaSpringPropertyGoo)ComponentTestHelper.GetOutput(comp, 7); var output8 = (GH_String)ComponentTestHelper.GetOutput(comp, 8); var output9 = (GH_Colour)ComponentTestHelper.GetOutput(comp, 9); @@ -61,7 +61,7 @@ public void GetValuesTest() { Assert.Equal(0, output0.Value.ApiNode.MassProperty); Assert.Equal(0, output6.Value); Assert.Equal(0, output0.Value.ApiNode.SpringProperty); - Assert.Equal(0, output7.Value); + Assert.Null(output7.Value); Assert.Equal("", output8.Value); Assert.Equal(0, output9.Value.R); @@ -91,7 +91,7 @@ public void SetValuesTest() { var output4 = (GsaBool6Goo)ComponentTestHelper.GetOutput(comp, 4); var output5 = (GH_Integer)ComponentTestHelper.GetOutput(comp, 5); var output6 = (GH_Integer)ComponentTestHelper.GetOutput(comp, 6); - var output7 = (GH_Integer)ComponentTestHelper.GetOutput(comp, 7); + var output7 = (GsaSpringPropertyGoo)ComponentTestHelper.GetOutput(comp, 7); var output8 = (GH_String)ComponentTestHelper.GetOutput(comp, 8); var output9 = (GH_Colour)ComponentTestHelper.GetOutput(comp, 9); @@ -119,8 +119,7 @@ public void SetValuesTest() { Assert.Equal(3, output5.Value); Assert.Equal(6, output0.Value.ApiNode.MassProperty); Assert.Equal(6, output6.Value); - Assert.Equal(9, output0.Value.ApiNode.SpringProperty); - Assert.Equal(9, output7.Value); + Assert.Equal(9, output7.Value.Id); Assert.Equal("name", output8.Value); Assert.Equal(255, output9.Value.R); diff --git a/GsaGHTests/Helpers/Assemble/AssembleModelTestsHelper.cs b/GsaGHTests/Helpers/Assemble/AssembleModelTestsHelper.cs index 246eb29c5..2bb3ade87 100644 --- a/GsaGHTests/Helpers/Assemble/AssembleModelTestsHelper.cs +++ b/GsaGHTests/Helpers/Assemble/AssembleModelTestsHelper.cs @@ -276,7 +276,9 @@ internal void TestNode( Assert.Equal(apiNode.Colour, expected.ApiNode.Colour); Assert.Equal(apiNode.DamperProperty, expected.ApiNode.DamperProperty); Assert.Equal(apiNode.MassProperty, expected.ApiNode.MassProperty); - Assert.Equal(apiNode.SpringProperty, expected.ApiNode.SpringProperty); + if (expected.SpringProperty != null) { + Assert.Equal(apiNode.SpringProperty, expected.SpringProperty.Id); + } } internal void TestProp2d(GsaProperty2d expected, int expectedId, GsaModel actualModel) { diff --git a/GsaGHTests/Helpers/Assemble/AssembleModelTestsNodes.cs b/GsaGHTests/Helpers/Assemble/AssembleModelTestsNodes.cs index baa6db3fb..dfc0967f7 100644 --- a/GsaGHTests/Helpers/Assemble/AssembleModelTestsNodes.cs +++ b/GsaGHTests/Helpers/Assemble/AssembleModelTestsNodes.cs @@ -42,7 +42,7 @@ public void AssembleModelWithNodeTest() { node.Value.LocalAxis = new Plane(new Point3d(1, 2, 3), new Vector3d(4, 3, 1)); node.Value.ApiNode.DamperProperty = 4; node.Value.ApiNode.MassProperty = 3; - node.Value.ApiNode.SpringProperty = 2; + node.Value.SpringProperty = new GsaSpringProperty(2); node.Value.Id = 42; var modelGoo = (GsaModelGoo)ComponentTestHelper.GetOutput(