From 7724802efdfbf95d1b01910866d597b2c8dda52e Mon Sep 17 00:00:00 2001 From: Kristjan Nielsen Date: Tue, 10 Oct 2023 15:19:30 +0200 Subject: [PATCH 1/7] stress unit abbreviation --- GsaGH/Components/5_Results/Element2dStresses.cs | 2 +- GsaGH/Components/5_Results/Element3dStresses.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/GsaGH/Components/5_Results/Element2dStresses.cs b/GsaGH/Components/5_Results/Element2dStresses.cs index 767e7a959..34f536721 100644 --- a/GsaGH/Components/5_Results/Element2dStresses.cs +++ b/GsaGH/Components/5_Results/Element2dStresses.cs @@ -63,7 +63,7 @@ protected override void InitialiseDropdowns() { _selectedItems = new List(); _dropDownItems.Add(UnitsHelper.GetFilteredAbbreviations(EngineeringUnits.Stress)); - _selectedItems.Add(_stresshUnit.ToString()); + _selectedItems.Add(Pressure.GetAbbreviation(_stresshUnit)); _isInitialised = true; } diff --git a/GsaGH/Components/5_Results/Element3dStresses.cs b/GsaGH/Components/5_Results/Element3dStresses.cs index e547b355f..1a60c5225 100644 --- a/GsaGH/Components/5_Results/Element3dStresses.cs +++ b/GsaGH/Components/5_Results/Element3dStresses.cs @@ -63,7 +63,7 @@ protected override void InitialiseDropdowns() { _selectedItems = new List(); _dropDownItems.Add(UnitsHelper.GetFilteredAbbreviations(EngineeringUnits.Stress)); - _selectedItems.Add(_stresshUnit.ToString()); + _selectedItems.Add(Pressure.GetAbbreviation(_stresshUnit)); _isInitialised = true; } From 2f1f48d0e808260bd3a57b7e2d8d6263825131ff Mon Sep 17 00:00:00 2001 From: Kristjan Nielsen Date: Tue, 10 Oct 2023 15:20:09 +0200 Subject: [PATCH 2/7] remove 3d rotation results as they dont exists --- .../5_Results/Element3dDisplacements.cs | 81 +++++-------------- 1 file changed, 18 insertions(+), 63 deletions(-) diff --git a/GsaGH/Components/5_Results/Element3dDisplacements.cs b/GsaGH/Components/5_Results/Element3dDisplacements.cs index ae7e11d43..cc6a3297c 100644 --- a/GsaGH/Components/5_Results/Element3dDisplacements.cs +++ b/GsaGH/Components/5_Results/Element3dDisplacements.cs @@ -75,9 +75,7 @@ protected override void RegisterInputParams(GH_InputParamManager pManager) { protected override void RegisterOutputParams(GH_OutputParamManager pManager) { string unitAbbreviation = Length.GetAbbreviation(_lengthUnit); - string note = ResultNotes.Note2dResults; - pManager.AddGenericParameter("Translations X [" + unitAbbreviation + "]", "Ux", "Translations in X-direction in Global Axis." + note, GH_ParamAccess.tree); pManager.AddGenericParameter("Translations Y [" + unitAbbreviation + "]", "Uy", @@ -86,14 +84,6 @@ protected override void RegisterOutputParams(GH_OutputParamManager pManager) { "Translations in Z-direction in Global Axis." + note, GH_ParamAccess.tree); pManager.AddGenericParameter("Translations |XYZ| [" + unitAbbreviation + "]", "|U|", "Combined |XYZ| Translations." + note, GH_ParamAccess.tree); - pManager.AddGenericParameter("Rotations XX [rad]", "Rxx", - "Rotations around X-axis in Global Axis." + note, GH_ParamAccess.tree); - pManager.AddGenericParameter("Rotations YY [rad]", "Ryy", - "Rotations around Y-axis in Global Axiss." + note, GH_ParamAccess.tree); - pManager.AddGenericParameter("Rotations ZZ [rad]", "Rzz", - "Rotations around Z-axis in Global Axis." + note, GH_ParamAccess.tree); - pManager.AddGenericParameter("Rotations |XYZ| [rad]", "|R|", - "Combined |XXYYZZ| Rotations." + note, GH_ParamAccess.tree); } protected override void SolveInternal(IGH_DataAccess da) { @@ -147,57 +137,26 @@ protected override void SolveInternal(IGH_DataAccess da) { continue; } - Parallel.For(0, 2, thread => // split computation in two for xyz and xxyyzz - { - switch (thread) { - case 0: { - foreach (KeyValuePair> kvp in + foreach (KeyValuePair> kvp in vals[perm - 1].XyzResults) { - int elementId = kvp.Key; - ConcurrentDictionary res = kvp.Value; - if (res.Count == 0) { - continue; - } - - var path = new GH_Path(result.CaseId, - result.SelectedPermutationIds == null ? 0 : perm, elementId); - - outTransX.AddRange( - res.Select(x => new GH_UnitNumber(x.Value.X.ToUnit(_lengthUnit))), - path); // use ToUnit to capture changes in dropdown - outTransY.AddRange( - res.Select(x => new GH_UnitNumber(x.Value.Y.ToUnit(_lengthUnit))), path); - outTransZ.AddRange( - res.Select(x => new GH_UnitNumber(x.Value.Z.ToUnit(_lengthUnit))), path); - outTransXyz.AddRange( - res.Select(x => new GH_UnitNumber(x.Value.Xyz.ToUnit(_lengthUnit))), path); - } - - break; - } - case 1: { - foreach (KeyValuePair> kvp in - vals[perm - 1].XxyyzzResults) { - int elementId = kvp.Key; - ConcurrentDictionary res = kvp.Value; - if (res.Count == 0) { - continue; - } - - var path = new GH_Path(result.CaseId, - result.SelectedPermutationIds == null ? 0 : perm, elementId); - - outRotX.AddRange(res.Select(x => new GH_UnitNumber(x.Value.X)), - path); // always use [rad] units - outRotY.AddRange(res.Select(x => new GH_UnitNumber(x.Value.Y)), path); - outRotZ.AddRange(res.Select(x => new GH_UnitNumber(x.Value.Z)), path); - outRotXyz.AddRange(res.Select(x => new GH_UnitNumber(x.Value.Xyz)), path); - } - - break; - } + int elementId = kvp.Key; + ConcurrentDictionary res = kvp.Value; + if (res.Count == 0) { + continue; } - }); + + var path = new GH_Path(result.CaseId, + result.SelectedPermutationIds == null ? 0 : perm, elementId); + // use ToUnit to capture changes in dropdown + outTransX.AddRange( + res.Select(x => new GH_UnitNumber(x.Value.X.ToUnit(_lengthUnit))), path); + outTransY.AddRange( + res.Select(x => new GH_UnitNumber(x.Value.Y.ToUnit(_lengthUnit))), path); + outTransZ.AddRange( + res.Select(x => new GH_UnitNumber(x.Value.Z.ToUnit(_lengthUnit))), path); + outTransXyz.AddRange( + res.Select(x => new GH_UnitNumber(x.Value.Xyz.ToUnit(_lengthUnit))), path); + } } } @@ -205,10 +164,6 @@ protected override void SolveInternal(IGH_DataAccess da) { da.SetDataTree(1, outTransY); da.SetDataTree(2, outTransZ); da.SetDataTree(3, outTransXyz); - da.SetDataTree(4, outRotX); - da.SetDataTree(5, outRotY); - da.SetDataTree(6, outRotZ); - da.SetDataTree(7, outRotXyz); PostHog.Result(result.Type, 3, GsaResultsValues.ResultType.Displacement); } From a8f035168b1400fa7b1b134db7825f33b1b77a50 Mon Sep 17 00:00:00 2001 From: Kristjan Nielsen Date: Tue, 10 Oct 2023 15:20:43 +0200 Subject: [PATCH 3/7] cleanup --- GsaGH/Components/5_Results/Element3dDisplacements.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/GsaGH/Components/5_Results/Element3dDisplacements.cs b/GsaGH/Components/5_Results/Element3dDisplacements.cs index cc6a3297c..6c2f02006 100644 --- a/GsaGH/Components/5_Results/Element3dDisplacements.cs +++ b/GsaGH/Components/5_Results/Element3dDisplacements.cs @@ -95,10 +95,6 @@ protected override void SolveInternal(IGH_DataAccess da) { var outTransY = new DataTree(); var outTransZ = new DataTree(); var outTransXyz = new DataTree(); - var outRotX = new DataTree(); - var outRotY = new DataTree(); - var outRotZ = new DataTree(); - var outRotXyz = new DataTree(); var ghTypes = new List(); if (!da.GetDataList(0, ghTypes)) { From b9f765be65fbaf7c6236dbbcd259aebbf3f7786b Mon Sep 17 00:00:00 2001 From: Kristjan Nielsen Date: Tue, 10 Oct 2023 17:54:31 +0200 Subject: [PATCH 4/7] update test --- GsaGHTests/3_Components/ComponentsTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GsaGHTests/3_Components/ComponentsTests.cs b/GsaGHTests/3_Components/ComponentsTests.cs index 624352502..e32a7924b 100644 --- a/GsaGHTests/3_Components/ComponentsTests.cs +++ b/GsaGHTests/3_Components/ComponentsTests.cs @@ -125,10 +125,10 @@ public void WhenInitialiseDropdowns_ThenDropDownItems_ShouldBeNull(Type t) { [InlineData(typeof(Contour2dResults), "Displacement", "Footfall")] [InlineData(typeof(Element2dDisplacements), "mm", "ft")] [InlineData(typeof(Element2dForcesAndMoments), "kN/m", "kipf/ft")] - [InlineData(typeof(Element2dStresses), "Megapascal", "kipf/ft²")] + [InlineData(typeof(Element2dStresses), "MPa", "kipf/ft²")] [InlineData(typeof(Contour3dResults), "Displacement", "Stress")] [InlineData(typeof(Element3dDisplacements), "mm", "ft")] - [InlineData(typeof(Element3dStresses), "Megapascal", "kipf/ft²")] + [InlineData(typeof(Element3dStresses), "MPa", "kipf/ft²")] [InlineData(typeof(GlobalPerformanceResults), "t", "slug")] [InlineData(typeof(ContourNodeResults), "Displacement", "Footfall")] [InlineData(typeof(NodeDisplacements), "mm", "ft")] From c0c2008d2e8bf283a0521abd5fd2315a59528222 Mon Sep 17 00:00:00 2001 From: Kristjan Nielsen Date: Tue, 10 Oct 2023 18:44:51 +0200 Subject: [PATCH 5/7] use default colour for annotation if user has not set an input --- GsaGH/Components/6_Display/ResultDiagrams.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/GsaGH/Components/6_Display/ResultDiagrams.cs b/GsaGH/Components/6_Display/ResultDiagrams.cs index 9269b8011..0f8270dca 100644 --- a/GsaGH/Components/6_Display/ResultDiagrams.cs +++ b/GsaGH/Components/6_Display/ResultDiagrams.cs @@ -306,6 +306,10 @@ private List GenerateAnnotations( = $"{Math.Round(valResult * valueScaleFactor, significantDigits)} {Message}"; } + if (color == Color.Empty) { + color = (Color)annotation.Colour; + } + diagramAnnotations.Add(new GsaAnnotationGoo( new GsaAnnotationDot(location, color, valueToAnnotate))); } From 27a8f6745a757b5b008c8d64958666f60b8e2356 Mon Sep 17 00:00:00 2001 From: Kristjan Nielsen Date: Thu, 12 Oct 2023 11:43:24 +0200 Subject: [PATCH 6/7] save gsa file fixes --- GsaGH/Components/0_Model/SaveGsaModel.cs | 21 +++++++++++++++++---- GsaGH/GsaGHInfo.cs | 1 + GsaGH/Helpers/GsaCOM/GsaComHelper.cs | 16 +++++++++++++--- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/GsaGH/Components/0_Model/SaveGsaModel.cs b/GsaGH/Components/0_Model/SaveGsaModel.cs index fa1e625b7..e1099324d 100644 --- a/GsaGH/Components/0_Model/SaveGsaModel.cs +++ b/GsaGH/Components/0_Model/SaveGsaModel.cs @@ -31,6 +31,7 @@ public class SaveGsaModel : GH_OasysDropDownComponent { public override OasysPluginInfo PluginInfo => GsaGH.PluginInfo.Instance; protected override Bitmap Icon => Resources.SaveGsaModel; private string _fileNameLastSaved; + private bool _saveInputOverride = false; public SaveGsaModel() : base("Save GSA Model", "Save", "Saves your GSA model from this parametric nightmare", CategoryName.Name(), @@ -95,8 +96,9 @@ protected override void SolveInternal(IGH_DataAccess da) { da.GetData(2, ref fileName); bool save = false; - if (da.GetData(1, ref save) && save) { + if (da.GetData(1, ref save) && (save || _saveInputOverride)) { Save(ref gsaModel, fileName); + _saveInputOverride = false; } da.SetData(0, new GsaModelGoo(gsaModel)); @@ -121,7 +123,12 @@ internal void Save(ref GsaModel model, string fileNameAndPath) { } internal void SaveButtonClick() { - UpdateUI(); + if (string.IsNullOrEmpty(_fileNameLastSaved)) { + SaveAsButtonClick(); + return; + } + + _saveInputOverride = true; } internal void SaveAsButtonClick() { @@ -153,9 +160,15 @@ internal void SaveAsButtonClick() { } internal void OpenGsaExe() { - if (!string.IsNullOrEmpty(_fileNameLastSaved)) { - Process.Start(_fileNameLastSaved); + if (string.IsNullOrEmpty(_fileNameLastSaved)) { + Params.Input[0].CollectData(); + var tempModel = (GsaModelGoo)Params.Input[0].VolatileData.AllData(true).First(); + string tempPath = Path.GetTempPath() + tempModel.Value.Guid.ToString() + ".gwb"; + GsaModel gsaModel = tempModel.Value; + Save(ref gsaModel, tempPath); } + + Process.Start(_fileNameLastSaved); } } } diff --git a/GsaGH/GsaGHInfo.cs b/GsaGH/GsaGHInfo.cs index b59a903a0..2f3725332 100644 --- a/GsaGH/GsaGHInfo.cs +++ b/GsaGH/GsaGHInfo.cs @@ -121,6 +121,7 @@ var ghLoadingException Instances.ComponentServer.AddCategoryIcon("GSA", Resources.GSALogo); Utility.InitialiseMainMenuAndDefaultUnits(); + RhinoApp.Closing += Helpers.GsaComHelper.Dispose; PostHog.PluginLoaded(PluginInfo.Instance, gsaVersion); diff --git a/GsaGH/Helpers/GsaCOM/GsaComHelper.cs b/GsaGH/Helpers/GsaCOM/GsaComHelper.cs index 4629e53b0..cef8aea79 100644 --- a/GsaGH/Helpers/GsaCOM/GsaComHelper.cs +++ b/GsaGH/Helpers/GsaCOM/GsaComHelper.cs @@ -7,8 +7,6 @@ namespace GsaGH.Helpers { public sealed class GsaComObject { public static ComAuto Instance => lazy.Value; private static readonly Lazy lazy = new Lazy(() => new ComAuto()); - - private GsaComObject() { } } internal static class GsaComHelper { @@ -27,6 +25,10 @@ internal static ComAuto GetGsaComModel(GsaModel model) { return gsa; } + if (File.Exists(tempPath)) { + File.Delete(tempPath); + } + guid = model.Guid; tempPath = Path.GetTempPath() + guid.ToString() + ".gwb"; @@ -39,11 +41,19 @@ internal static ComAuto GetGsaComModel(GsaModel model) { internal static GsaModel GetGsaGhModel() { ComAuto gsa = GsaComObject.Instance; - gsa.SaveAs(tempPath); var gsaGh = new GsaModel(); gsaGh.Model.Open(tempPath); + return gsaGh; } + + internal static void Dispose(object? sender, EventArgs e) { + if (File.Exists(tempPath)) { + File.Delete(tempPath); + } + + GsaComObject.Instance.Close(); + } } } From 5b9e09b31bc44fbc6d66ae463ad4ad2791c3da00 Mon Sep 17 00:00:00 2001 From: Kristjan Nielsen Date: Thu, 12 Oct 2023 22:46:42 +0200 Subject: [PATCH 7/7] remove nullable reference --- GsaGH/Helpers/GsaCOM/GsaComHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GsaGH/Helpers/GsaCOM/GsaComHelper.cs b/GsaGH/Helpers/GsaCOM/GsaComHelper.cs index cef8aea79..fdc3f3518 100644 --- a/GsaGH/Helpers/GsaCOM/GsaComHelper.cs +++ b/GsaGH/Helpers/GsaCOM/GsaComHelper.cs @@ -48,7 +48,7 @@ internal static GsaModel GetGsaGhModel() { return gsaGh; } - internal static void Dispose(object? sender, EventArgs e) { + internal static void Dispose(object sender, EventArgs e) { if (File.Exists(tempPath)) { File.Delete(tempPath); }