Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kpne authored Dec 12, 2023
2 parents 229357d + 94ee9b9 commit 1296559
Show file tree
Hide file tree
Showing 8 changed files with 258 additions and 51 deletions.
5 changes: 1 addition & 4 deletions GsaGH/Components/5_Results/SelectResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@ protected override void RegisterOutputParams(GH_OutputParamManager pManager) {

protected override void SolveInternal(IGH_DataAccess da) {
var ghTyp = new GH_ObjectWrapper();
if (!da.GetData(0, ref ghTyp)) {
return;
}
da.GetData(0, ref ghTyp);

if (ghTyp.Value is GsaModelGoo modelGoo) {
if (_gsaModel != null) {
Expand All @@ -167,7 +165,6 @@ protected override void SolveInternal(IGH_DataAccess da) {
if (da.GetData(1, ref ghType)) {
if (GH_Convert.ToString(ghType, out string type, GH_Conversion.Both)) {
if (type.ToUpper().StartsWith("A")) {
_resultType = CaseType.AnalysisCase;
_selectedItems[0] = _dropDownItems[0][0];
if (_resultType != CaseType.AnalysisCase) {
_resultType = CaseType.AnalysisCase;
Expand Down
47 changes: 4 additions & 43 deletions GsaGH/Components/6_Display/ResultDiagrams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,13 @@ public class ResultDiagrams : GH_OasysDropDownComponent {

private string _case = string.Empty;
private ForceUnit _forceUnit = DefaultUnits.ForceUnit;
private LengthUnit _lengthResultUnit = DefaultUnits.LengthUnitResult;
private LengthUnit _lengthUnit = DefaultUnits.LengthUnitGeometry;
private MomentUnit _momentUnit = DefaultUnits.MomentUnit;
private PressureUnit _stressUnit = DefaultUnits.StressUnitResult;
private bool _undefinedModelLengthUnit;

public ResultDiagrams() : base("Result Diagrams", "ResultDiagram",
"Displays GSA 1D Element Result Diagram", CategoryName.Name(), SubCategoryName.Cat6()) { }

public override bool Read(GH_IReader reader) {
//warning - sensitive for description string! do not change description if not needed!
_lengthUnit = (LengthUnit)UnitsHelper.Parse(typeof(LengthUnit), reader.GetString("model"));
_lengthResultUnit
= (LengthUnit)UnitsHelper.Parse(typeof(LengthUnit), reader.GetString("length"));
_forceUnit = (ForceUnit)UnitsHelper.Parse(typeof(ForceUnit), reader.GetString("force"));
_momentUnit = (MomentUnit)UnitsHelper.Parse(typeof(MomentUnit), reader.GetString("moment"));
_stressUnit
Expand Down Expand Up @@ -84,8 +77,6 @@ public override void SetSelected(int i, int j) {
}

public override bool Write(GH_IWriter writer) {
writer.SetString("model", Length.GetAbbreviation(_lengthUnit));
writer.SetString("length", Length.GetAbbreviation(_lengthResultUnit));
writer.SetString("force", Force.GetAbbreviation(_forceUnit));
writer.SetString("moment", Moment.GetAbbreviation(_momentUnit));
writer.SetString("stress", Pressure.GetAbbreviation(_stressUnit));
Expand All @@ -99,8 +90,6 @@ protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown men

Menu_AppendSeparator(menu);

ToolStripMenuItem lengthUnitsMenu = GenerateToolStripMenuItem.GetSubMenuItem("Displacement",
EngineeringUnits.Length, Length.GetAbbreviation(_lengthResultUnit), UpdateLength);
ToolStripMenuItem forceUnitsMenu = GenerateToolStripMenuItem.GetSubMenuItem("Force",
EngineeringUnits.Force, Force.GetAbbreviation(_forceUnit), UpdateForce);
ToolStripMenuItem momentUnitsMenu = GenerateToolStripMenuItem.GetSubMenuItem("Moment",
Expand All @@ -111,20 +100,11 @@ protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown men
var unitsMenu = new ToolStripMenuItem("Select Units", Resources.ModelUnits);

unitsMenu.DropDownItems.AddRange(new ToolStripItem[] {
lengthUnitsMenu,
forceUnitsMenu,
momentUnitsMenu,
stressUnitsMenu,
});

if (_undefinedModelLengthUnit) {
ToolStripMenuItem modelUnitsMenu = GenerateToolStripMenuItem.GetSubMenuItem(
"Model geometry", EngineeringUnits.Length, Length.GetAbbreviation(_lengthUnit),
UpdateModel);

unitsMenu.DropDownItems.Insert(0, modelUnitsMenu);
}

unitsMenu.ImageScaling = ToolStripItemImageScaling.SizeToFit;
menu.Items.Add(unitsMenu);
Menu_AppendSeparator(menu);
Expand Down Expand Up @@ -231,13 +211,6 @@ string warningText
}

LengthUnit lengthUnit = result.Model.ModelUnit;
_undefinedModelLengthUnit = false;
if (lengthUnit == LengthUnit.Undefined) {
lengthUnit = _lengthUnit;
_undefinedModelLengthUnit = true;
this.AddRuntimeRemark(
$"Model came straight out of GSA and we couldn't read the units. The geometry has been scaled to be in {lengthUnit}. This can be changed by right-clicking the component -> 'Select Units'");
}

DiagramType type = _selectedItems[0] == "Force"
? Mappings.diagramTypeMappingForce.Where(item => item.Description == _selectedItems[1])
Expand All @@ -247,7 +220,7 @@ string warningText

double unitScale = ComputeUnitScale(autoScale);
double computedScale
= GraphicsScalar.ComputeScale(result.Model, scale, _lengthUnit, autoScale, unitScale);
= GraphicsScalar.ComputeScale(result.Model, scale, lengthUnit, autoScale, unitScale);
var graphic = new DiagramSpecification() {
ListDefinition = list.Definition,
ListType = list.Type,
Expand Down Expand Up @@ -412,31 +385,19 @@ private bool IsStress() {
return isStress;
}

private void UpdateForce(string unit) {
internal void UpdateForce(string unit) {
_forceUnit = (ForceUnit)UnitsHelper.Parse(typeof(ForceUnit), unit);
ExpirePreview(true);
base.UpdateUI();
}

private void UpdateStress(string unit) {
internal void UpdateStress(string unit) {
_stressUnit = (PressureUnit)UnitsHelper.Parse(typeof(PressureUnit), unit);
ExpirePreview(true);
base.UpdateUI();
}

private void UpdateLength(string unit) {
_lengthResultUnit = (LengthUnit)UnitsHelper.Parse(typeof(LengthUnit), unit);
ExpirePreview(true);
base.UpdateUI();
}

private void UpdateModel(string unit) {
_lengthUnit = (LengthUnit)UnitsHelper.Parse(typeof(LengthUnit), unit);
ExpirePreview(true);
base.UpdateUI();
}

private void UpdateMoment(string unit) {
internal void UpdateMoment(string unit) {
_momentUnit = (MomentUnit)UnitsHelper.Parse(typeof(MomentUnit), unit);
ExpirePreview(true);
base.UpdateUI();
Expand Down
118 changes: 118 additions & 0 deletions GsaGHTests/3_Components/5_Results/SelectResultsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,123 @@ public void ChangeFromAnalysisCaseToNonExistentCombinationCase() {
comp.Params.Output[0].CollectData();
Assert.Equal("C4", comp._selectedItems[1]);
}

[Fact]
public void UpdateDropdownsTest() {
var comp = new SelectResult();
var apiModel = new GsaAPI.Model(GsaFile.SteelDesignComplex);
var model = new GsaModel(apiModel);
ComponentTestHelper.SetInput(comp, new GsaModelGoo(model));
comp.Params.Output[0].CollectData();
Assert.Equal(2, comp._dropDownItems.Count);
Assert.Equal(2, comp._dropDownItems[0].Count);
Assert.Equal(13, comp._dropDownItems[1].Count);
comp.SetSelected(0, 1); // combination case
comp.Params.Output[0].CollectData();
Assert.Equal(3, comp._dropDownItems.Count);
Assert.Equal(2, comp._dropDownItems[0].Count);
Assert.Equal(4, comp._dropDownItems[1].Count);
Assert.Equal(3, comp._dropDownItems[2].Count);
}

[Fact]
public void UpdateModelTest() {
var comp = new SelectResult();
var apiModel1 = new GsaAPI.Model(GsaFile.SteelDesignComplex);
var model1 = new GsaModel(apiModel1);
ComponentTestHelper.SetInput(comp, new GsaModelGoo(model1));
comp.Params.Output[0].CollectData();
Assert.Equal(2, comp._dropDownItems.Count);
Assert.Equal(2, comp._dropDownItems[0].Count);
Assert.Equal(13, comp._dropDownItems[1].Count);
var apiModel2 = new GsaAPI.Model(GsaFile.SteelDesignSimple);
var model2 = new GsaModel(apiModel2);
ComponentTestHelper.SetInput(comp, new GsaModelGoo(model2));
comp.Params.Output[0].CollectData();
Assert.Equal(2, comp._dropDownItems.Count);
Assert.Equal(2, comp._dropDownItems[0].Count);
Assert.Equal(2, comp._dropDownItems[1].Count);
}

[Fact]
public void InvalidModelInputsTest() {
var comp = new SelectResult();
ComponentTestHelper.SetInput(comp, "not a model");
comp.Params.Output[0].CollectData();
Assert.True((int)comp.RuntimeMessageLevel >= 10);
}

[Fact]
public void SetCombinationCaseByDropdownThenAnalysisCaseByInput() {
var comp = new SelectResult();
var apiModel = new GsaAPI.Model(GsaFile.SteelDesignComplex);
var model = new GsaModel(apiModel);
ComponentTestHelper.SetInput(comp, new GsaModelGoo(model));
comp.SetSelected(0, 1); // combination case
comp.Params.Output[0].CollectData();
comp.SetSelected(1, 1); // case C2
comp.Params.Output[0].CollectData();
Assert.Equal("Combination", comp._selectedItems[0]);
Assert.Equal(3, comp._dropDownItems.Count);
ComponentTestHelper.SetInput(comp, "Analysis", 1);
comp.Params.Output[0].CollectData();
Assert.Equal("AnalysisCase", comp._selectedItems[0]);
Assert.Equal("A2", comp._selectedItems[1]);
Assert.Equal(2, comp._dropDownItems.Count);
}

[Fact]
public void SetAnalysisCaseByDropdownThenCombinationCaseByInput() {
var comp = new SelectResult();
var apiModel = new GsaAPI.Model(GsaFile.SteelDesignComplex);
var model = new GsaModel(apiModel);
ComponentTestHelper.SetInput(comp, new GsaModelGoo(model));
comp.SetSelected(0, 0); // analysis case
comp.Params.Output[0].CollectData();
comp.SetSelected(1, 1); // case A2
comp.Params.Output[0].CollectData();
Assert.Equal("AnalysisCase", comp._selectedItems[0]);
Assert.Equal(2, comp._dropDownItems.Count);
ComponentTestHelper.SetInput(comp, "Combination", 1);
comp.Params.Output[0].CollectData();
Assert.Equal("Combination", comp._selectedItems[0]);
Assert.Equal("C2", comp._selectedItems[1]);
Assert.Equal(3, comp._dropDownItems.Count);
}

[Fact]
public void SetAnalysisCaseIdByInput() {
var comp = new SelectResult();
var apiModel = new GsaAPI.Model(GsaFile.SteelDesignComplex);
var model = new GsaModel(apiModel);
ComponentTestHelper.SetInput(comp, new GsaModelGoo(model));
ComponentTestHelper.SetInput(comp, 0, 2);
comp.Params.Output[0].CollectData();
Assert.Equal("All", comp._selectedItems[1]);
ComponentTestHelper.SetInput(comp, 2, 2);
comp.Params.Output[0].CollectData();
Assert.Equal("A2", comp._selectedItems[1]);
}

[Fact]
public void SetPermutationIdByInput() {
var comp = new SelectResult();
var apiModel = new GsaAPI.Model(GsaFile.SteelDesignComplex);
var model = new GsaModel(apiModel);
ComponentTestHelper.SetInput(comp, new GsaModelGoo(model));
comp.SetSelected(0, 1); // combination case
comp.Params.Output[0].CollectData();
comp.SetSelected(1, 3); // C4
comp.Params.Output[0].CollectData();
comp.SetSelected(2, 2); // C4p2
comp.Params.Output[0].CollectData();
Assert.Equal("P2", comp._selectedItems[2]);
ComponentTestHelper.SetInput(comp, 0, 3);
comp.Params.Output[0].CollectData();
Assert.Equal("All", comp._selectedItems[2]);
ComponentTestHelper.SetInput(comp, 2, 3);
comp.Params.Output[0].CollectData();
Assert.Equal("from input", comp._selectedItems[2]);
}
}
}
19 changes: 18 additions & 1 deletion GsaGHTests/3_Components/6_Display/Contour1dResultsTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using Grasshopper.Kernel.Special;
using System.Collections.Generic;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Special;
using GsaGH.Components;
using GsaGH.Parameters;
using GsaGH.Parameters.Results;
using GsaGHTests.Helper;
using GsaGHTests.Helpers;
using GsaGHTests.Parameters;
using OasysGH.UI;
Expand All @@ -9,6 +13,19 @@
namespace GsaGHTests.Components.Display {
[Collection("GrasshopperFixture collection")]
public class Contour1dResultsTests {
[Fact]
public void CombinationCaseWithMultiplePermutationsMessageTests() {
var caseResult = (GsaResult)GsaResultTests.CombinationCaseResult(GsaFile.SteelDesignComplex, 2, new List<int>() { 1, 2, 3, });

var comp = new Contour1dResults();
ComponentTestHelper.SetInput(comp, new GsaResultGoo(caseResult));
comp.Params.Output[0].CollectData();
IList<string> messages = comp.RuntimeMessages(GH_RuntimeMessageLevel.Warning);

Assert.Single(messages);
Assert.Equal("Combination Case 2 contains 3 permutations - only one permutation can be displayed at a time.\r\nDisplaying first permutation; please use the 'Select Results' to select other single permutations", messages[0]);
}

[Fact]
public void DefaultDropSelectionsTest() {
var comp = new Contour1dResults();
Expand Down
19 changes: 18 additions & 1 deletion GsaGHTests/3_Components/6_Display/Contour2dResultsTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using Grasshopper.Kernel.Special;
using System.Collections.Generic;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Special;
using GsaGH.Components;
using GsaGH.Parameters;
using GsaGH.Parameters.Results;
using GsaGHTests.Helper;
using GsaGHTests.Helpers;
using GsaGHTests.Parameters;
using OasysGH.UI;
Expand All @@ -9,6 +13,19 @@
namespace GsaGHTests.Components.Display {
[Collection("GrasshopperFixture collection")]
public class Contour2dResultsTests {
[Fact]
public void CombinationCaseWithMultiplePermutationsMessageTests() {
var caseResult = (GsaResult)GsaResultTests.CombinationCaseResult(GsaFile.SteelDesignComplex, 2, new List<int>() { 1, 2, 3, });

var comp = new Contour2dResults();
ComponentTestHelper.SetInput(comp, new GsaResultGoo(caseResult));
comp.Params.Output[0].CollectData();
IList<string> messages = comp.RuntimeMessages(GH_RuntimeMessageLevel.Warning);

Assert.Single(messages);
Assert.Equal("Combination Case 2 contains 3 permutations - only one permutation can be displayed at a time.\r\nDisplaying first permutation; please use the 'Select Results' to select other single permutations", messages[0]);
}

[Fact]
public void DefaultDropSelectionsTest() {
var comp = new Contour2dResults();
Expand Down
19 changes: 18 additions & 1 deletion GsaGHTests/3_Components/6_Display/Contour3dResultsTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using Grasshopper.Kernel.Special;
using System.Collections.Generic;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Special;
using GsaGH.Components;
using GsaGH.Parameters;
using GsaGH.Parameters.Results;
using GsaGHTests.Helper;
using GsaGHTests.Helpers;
using GsaGHTests.Parameters;
using OasysGH.UI;
Expand All @@ -9,6 +13,19 @@
namespace GsaGHTests.Components.Display {
[Collection("GrasshopperFixture collection")]
public class Contour3dResultsTests {
[Fact]
public void CombinationCaseWithMultiplePermutationsMessageTests() {
var caseResult = (GsaResult)GsaResultTests.CombinationCaseResult(GsaFile.SteelDesignComplex, 2, new List<int>() { 1, 2, 3, });

var comp = new Contour3dResults();
ComponentTestHelper.SetInput(comp, new GsaResultGoo(caseResult));
comp.Params.Output[0].CollectData();
IList<string> messages = comp.RuntimeMessages(GH_RuntimeMessageLevel.Warning);

Assert.Single(messages);
Assert.Equal("Combination Case 2 contains 3 permutations - only one permutation can be displayed at a time.\r\nDisplaying first permutation; please use the 'Select Results' to select other single permutations", messages[0]);
}

[Fact]
public void DefaultDropSelectionsTest() {
var comp = new Contour3dResults();
Expand Down
18 changes: 17 additions & 1 deletion GsaGHTests/3_Components/6_Display/ContourNodeResultsTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Grasshopper.Kernel.Special;
using System.Collections.Generic;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Special;
using GsaAPI;
using GsaGH.Components;
using GsaGH.Parameters;
using GsaGH.Parameters.Results;
Expand All @@ -11,6 +14,19 @@
namespace GsaGHTests.Components.Display {
[Collection("GrasshopperFixture collection")]
public class ContourNodeResultsTests {
[Fact]
public void CombinationCaseWithMultiplePermutationsMessageTests() {
var caseResult = (GsaResult)GsaResultTests.CombinationCaseResult(GsaFile.SteelDesignComplex, 2, new List<int>(){1, 2, 3,});

var comp = new ContourNodeResults();
ComponentTestHelper.SetInput(comp, new GsaResultGoo(caseResult));
comp.Params.Output[0].CollectData();
IList<string> messages = comp.RuntimeMessages(GH_RuntimeMessageLevel.Warning);

Assert.Single(messages);
Assert.Equal("Combination Case 2 contains 3 permutations - only one permutation can be displayed at a time.\r\nDisplaying first permutation; please use the 'Select Results' to select other single permutations", messages[0]);
}

[Fact]
public void DefaultDropSelectionsTest() {
var comp = new ContourNodeResults();
Expand Down
Loading

0 comments on commit 1296559

Please sign in to comment.