Skip to content

Commit

Permalink
Merge branch 'main' into task/GSAGH-345-posthog-diagrams
Browse files Browse the repository at this point in the history
  • Loading branch information
kpne authored Oct 13, 2023
2 parents 6c8721d + a669d59 commit 18c199e
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 78 deletions.
21 changes: 17 additions & 4 deletions GsaGH/Components/0_Model/SaveGsaModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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));
Expand All @@ -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() {
Expand Down Expand Up @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion GsaGH/Components/5_Results/Element2dStresses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected override void InitialiseDropdowns() {
_selectedItems = new List<string>();

_dropDownItems.Add(UnitsHelper.GetFilteredAbbreviations(EngineeringUnits.Stress));
_selectedItems.Add(_stresshUnit.ToString());
_selectedItems.Add(Pressure.GetAbbreviation(_stresshUnit));

_isInitialised = true;
}
Expand Down
85 changes: 18 additions & 67 deletions GsaGH/Components/5_Results/Element3dDisplacements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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) {
Expand All @@ -105,10 +95,6 @@ protected override void SolveInternal(IGH_DataAccess da) {
var outTransY = new DataTree<GH_UnitNumber>();
var outTransZ = new DataTree<GH_UnitNumber>();
var outTransXyz = new DataTree<GH_UnitNumber>();
var outRotX = new DataTree<GH_UnitNumber>();
var outRotY = new DataTree<GH_UnitNumber>();
var outRotZ = new DataTree<GH_UnitNumber>();
var outRotXyz = new DataTree<GH_UnitNumber>();

var ghTypes = new List<GH_ObjectWrapper>();
if (!da.GetDataList(0, ghTypes)) {
Expand Down Expand Up @@ -147,68 +133,33 @@ 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<int, ConcurrentDictionary<int, GsaResultQuantity>> kvp in
foreach (KeyValuePair<int, ConcurrentDictionary<int, GsaResultQuantity>> kvp in
vals[perm - 1].XyzResults) {
int elementId = kvp.Key;
ConcurrentDictionary<int, GsaResultQuantity> 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<int, ConcurrentDictionary<int, GsaResultQuantity>> kvp in
vals[perm - 1].XxyyzzResults) {
int elementId = kvp.Key;
ConcurrentDictionary<int, GsaResultQuantity> 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<int, GsaResultQuantity> 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);
}
}
}

da.SetDataTree(0, outTransX);
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);
}
Expand Down
2 changes: 1 addition & 1 deletion GsaGH/Components/5_Results/Element3dStresses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected override void InitialiseDropdowns() {
_selectedItems = new List<string>();

_dropDownItems.Add(UnitsHelper.GetFilteredAbbreviations(EngineeringUnits.Stress));
_selectedItems.Add(_stresshUnit.ToString());
_selectedItems.Add(Pressure.GetAbbreviation(_stresshUnit));

_isInitialised = true;
}
Expand Down
4 changes: 4 additions & 0 deletions GsaGH/Components/6_Display/ResultDiagrams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ private List<GsaAnnotationGoo> GenerateAnnotations(
= $"{Math.Round(valResult * valueScaleFactor, significantDigits)} {Message}";
}

if (color == Color.Empty) {
color = (Color)annotation.Colour;
}

diagramAnnotations.Add(new GsaAnnotationGoo(
new GsaAnnotationDot(location, color, valueToAnnotate)));
}
Expand Down
1 change: 1 addition & 0 deletions GsaGH/GsaGHInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ var ghLoadingException
Instances.ComponentServer.AddCategoryIcon("GSA", Resources.GSALogo);

Utility.InitialiseMainMenuAndDefaultUnits();
RhinoApp.Closing += Helpers.GsaComHelper.Dispose;

PostHog.PluginLoaded(PluginInfo.Instance, gsaVersion);

Expand Down
16 changes: 13 additions & 3 deletions GsaGH/Helpers/GsaCOM/GsaComHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ namespace GsaGH.Helpers {
public sealed class GsaComObject {
public static ComAuto Instance => lazy.Value;
private static readonly Lazy<ComAuto> lazy = new Lazy<ComAuto>(() => new ComAuto());

private GsaComObject() { }
}

internal static class GsaComHelper {
Expand All @@ -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";

Expand All @@ -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();
}
}
}
4 changes: 2 additions & 2 deletions GsaGHTests/3_Components/ComponentsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down

0 comments on commit 18c199e

Please sign in to comment.