Skip to content

Commit

Permalink
save gsa file fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristjan Nielsen committed Oct 12, 2023
1 parent 6fbc436 commit 27a8f67
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 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);
}
}
}
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();
}
}
}

0 comments on commit 27a8f67

Please sign in to comment.