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/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/Element3dDisplacements.cs b/GsaGH/Components/5_Results/Element3dDisplacements.cs index ae7e11d43..6c2f02006 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) { @@ -105,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)) { @@ -147,57 +133,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 +160,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); } 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; } diff --git a/GsaGH/Components/6_Display/ResultDiagrams.cs b/GsaGH/Components/6_Display/ResultDiagrams.cs index eb76bd61a..3e26c4aba 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))); } 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..fdc3f3518 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(); + } } } 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")]