From 70254199e2f548886a463ffcc509cea49ec76472 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Mon, 31 Jan 2022 17:01:37 -0800 Subject: [PATCH] Working on file change detection and save prompt Origin center for radial array --- .../ApplicationView/ApplicationController.cs | 30 +++--- .../ApplicationView/Config/BedConfig.cs | 8 ++ .../ApplicationView/ISceneContext.cs | 2 + .../Operations/ArrayRadialObject3D.cs | 12 ++- MatterControlLib/RootSystemWindow.cs | 101 +++++++++++------- StaticData/Translations/Master.txt | 6 ++ 6 files changed, 103 insertions(+), 56 deletions(-) diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index fb00998c7..aa54b777f 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -289,14 +289,17 @@ namespace MatterHackers.MatterControl } } - public async Task PersistUserWorkspaceTabs(bool saveSceneChanges) + public async Task PersistUserWorkspaceTabs(bool savePrinterScenes) { - if (saveSceneChanges) + if (savePrinterScenes) { // Persist all pending changes in all workspaces to disk foreach (var workspace in this.Workspaces.ToArray()) { - await this.Tasks.Execute("Saving".Localize() + $" \"{workspace.Name}\" ...", workspace, workspace.SceneContext.SaveChanges); + if (workspace.Printer != null) + { + await this.Tasks.Execute("Saving".Localize() + $" \"{workspace.Name}\" ...", workspace, workspace.SceneContext.SaveChanges); + } } } @@ -443,15 +446,17 @@ namespace MatterHackers.MatterControl public static Func>> GetProfileHistory; - public void OnWorkspacesChanged(WorkspacesChangedEventArgs e) + public void OnWorkspacesChanged(PartWorkspace workspace, WorkspacesChangedEventArgs.OperationType operationType) { - this.WorkspacesChanged?.Invoke(this, e); + this.WorkspacesChanged?.Invoke(this, new WorkspacesChangedEventArgs( + workspace, + operationType)); - if (e.Operation != WorkspacesChangedEventArgs.OperationType.Restore) + if (operationType != WorkspacesChangedEventArgs.OperationType.Restore) { UiThread.RunOnIdle(async () => { - await ApplicationController.Instance.PersistUserWorkspaceTabs(true); + await Instance.PersistUserWorkspaceTabs(true); }); } } @@ -481,10 +486,7 @@ namespace MatterHackers.MatterControl { this.Workspaces.Remove(workspace); - this.OnWorkspacesChanged( - new WorkspacesChangedEventArgs( - workspace, - WorkspacesChangedEventArgs.OperationType.Remove)); + this.OnWorkspacesChanged(workspace, WorkspacesChangedEventArgs.OperationType.Remove); } } @@ -1597,11 +1599,7 @@ namespace MatterHackers.MatterControl public void OpenWorkspace(PartWorkspace workspace, WorkspacesChangedEventArgs.OperationType operationType) { - this.OnWorkspacesChanged( - new WorkspacesChangedEventArgs( - workspace, - operationType)); - + this.OnWorkspacesChanged(workspace, operationType); this.Workspaces.Add(workspace); } diff --git a/MatterControlLib/ApplicationView/Config/BedConfig.cs b/MatterControlLib/ApplicationView/Config/BedConfig.cs index e02e8802f..67855d42a 100644 --- a/MatterControlLib/ApplicationView/Config/BedConfig.cs +++ b/MatterControlLib/ApplicationView/Config/BedConfig.cs @@ -701,6 +701,14 @@ namespace MatterHackers.MatterControl } } + public bool HadSaveError + { + get + { + return false; + } + } + public List GetBaseViewOptions() { return new List(); diff --git a/MatterControlLib/ApplicationView/ISceneContext.cs b/MatterControlLib/ApplicationView/ISceneContext.cs index 321e302eb..7125de53e 100644 --- a/MatterControlLib/ApplicationView/ISceneContext.cs +++ b/MatterControlLib/ApplicationView/ISceneContext.cs @@ -84,6 +84,8 @@ namespace MatterHackers.MatterControl Task SaveChanges(IProgress progress, CancellationTokenSource cancellationToken); + bool HadSaveError { get; } + // TODO: Isolate printer specifics from ISceneContext // ******************************************************* diff --git a/MatterControlLib/DesignTools/Operations/ArrayRadialObject3D.cs b/MatterControlLib/DesignTools/Operations/ArrayRadialObject3D.cs index dd90d5c62..8b5df5231 100644 --- a/MatterControlLib/DesignTools/Operations/ArrayRadialObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/ArrayRadialObject3D.cs @@ -28,7 +28,6 @@ either expressed or implied, of the FreeBSD Project. */ using System; -using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Threading.Tasks; @@ -79,6 +78,8 @@ namespace MatterHackers.MatterControl.DesignTools.Operations this.DebugDepth("Rebuild"); var aabb = this.GetAxisAlignedBoundingBox(); + var firstBuild = this.Children.Count == 1; + var sourceContainer = SourceContainer; this.Children.Modify(list => { @@ -104,10 +105,17 @@ namespace MatterHackers.MatterControl.DesignTools.Operations next.Rotate(nextAabb.Center, normal, -angleRadians); } + next.Matrix *= Matrix4X4.CreateTranslation(-Axis.Origin); + list.Add(next); } }); + if (firstBuild) + { + this.Matrix *= Matrix4X4.CreateTranslation(Axis.Origin); + } + ProcessIndexExpressions(); SourceContainer.Visible = false; @@ -123,7 +131,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations public void DrawEditor(Object3DControlsLayer layer, DrawEventArgs e) { - layer.World.RenderDirectionAxis(Axis, this.WorldMatrix(), 30); + layer.World.RenderDirectionAxis(new DirectionAxis() { Normal = Axis.Normal, Origin = Vector3.Zero }, this.WorldMatrix(), 30); } } } \ No newline at end of file diff --git a/MatterControlLib/RootSystemWindow.cs b/MatterControlLib/RootSystemWindow.cs index 1b2862709..5007dcb5f 100644 --- a/MatterControlLib/RootSystemWindow.cs +++ b/MatterControlLib/RootSystemWindow.cs @@ -28,8 +28,10 @@ either expressed or implied, of the FreeBSD Project. */ using System; +using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Linq; using MatterHackers.Agg; using MatterHackers.Agg.Platform; using MatterHackers.Agg.UI; @@ -294,17 +296,16 @@ namespace MatterHackers.MatterControl else if (!ApplicationController.Instance.ApplicationExiting) { // Check if there are unsaved design spaces - bool unsavedChanges = false; + var unsavedWorkspaces = new List(); foreach (var workspace in ApplicationController.Instance.Workspaces) { if (workspace.SceneContext?.Scene?.HasUnsavedChanges == true) { - unsavedChanges = true; - break; - } + unsavedWorkspaces.Add(workspace); + } } - void SavePrinterWorkspaces() + void SavePrinterWorkspacesAndClose() { // cancel the close so that we can save all our active work spaces eventArgs.Cancel = true; @@ -324,49 +325,73 @@ namespace MatterHackers.MatterControl }); } - if (unsavedChanges) + if (unsavedWorkspaces.Count > 0) { + exitDialogOpen = true; + + // We need to show an interactive dialog to determine if the original Close request should be honored, thus cancel the current Close request + eventArgs.Cancel = true; + // Ask if the user wants to save all workspaces, close without save, or cancel. UiThread.RunOnIdle(() => { - if (this.TabContent is PartTabPage partTab - && partTab?.Workspace?.SceneContext?.Scene is InteractiveScene sceneContext - && sceneContext.HasUnsavedChanges) - { - StyledMessageBox.ShowYNCMessageBox( - (response) => - { - switch (response) - { - case StyledMessageBox.ResponseType.YES: - UiThread.RunOnIdle(async () => - { - await ApplicationController.Instance.Tasks.Execute("Saving Changes".Localize(), this, partTab.Workspace.SceneContext.SaveChanges); - this.parentTabControl.CloseTab(this); - this.CloseClicked?.Invoke(this, null); - }); - break; + StyledMessageBox.ShowYNCMessageBox( + (response) => + { + exitDialogOpen = false; - case StyledMessageBox.ResponseType.NO: - UiThread.RunOnIdle(async () => + switch (response) + { + case StyledMessageBox.ResponseType.YES: + UiThread.RunOnIdle(async () => + { + var hadSaveError = false; + // Persist each design workspaces to disk (this may require getting a filename + foreach (var workspace in ApplicationController.Instance.Workspaces.ToArray()) { - this.parentTabControl.CloseTab(this); - this.CloseClicked?.Invoke(this, null); - }); - break; - } - }, - "Wolud you like to save changes before closing?".Localize(), - "Save Changes?".Localize(), - "Save Changes".Localize(), - "Discard Changes".Localize(), - "Cancel".Localize()); - } + if (workspace.Printer == null) + { + // if we have a filename + // save + // else + // switch to the tab we are about to save + // ask the user to give us a filname + // if no filename + // abort the exit procedure + await ApplicationController.Instance.Tasks.Execute("Saving".Localize() + $" \"{workspace.Name}\" ...", workspace, workspace.SceneContext.SaveChanges); + // check for error or abort + hadSaveError |= workspace.SceneContext.HadSaveError; + } + } + + if (!hadSaveError) + { + // make sure we also save the printer workspaces as we close + SavePrinterWorkspacesAndClose(); + } + }); + break; + + case StyledMessageBox.ResponseType.NO: + UiThread.RunOnIdle(() => + { + // make sure we still save the printer workspaces + SavePrinterWorkspacesAndClose(); + }); + break; + } + }, + unsavedWorkspaces.Count == 1 ? "You have one unsave design ({0}). Wolud you like to save changes before closing?".Localize().FormatWith(unsavedWorkspaces[0].Name) + : "You have {0} unsave designs. Wolud you like to save changes before closing?".Localize().FormatWith(unsavedWorkspaces.Count), + "Save Changes?".Localize(), + "Save Changes".Localize(), + "Discard Changes".Localize(), + "Cancel".Localize()); }); } else { - SavePrinterWorkspaces(); + SavePrinterWorkspacesAndClose(); } } } diff --git a/StaticData/Translations/Master.txt b/StaticData/Translations/Master.txt index 30df41a74..f97483a9d 100644 --- a/StaticData/Translations/Master.txt +++ b/StaticData/Translations/Master.txt @@ -4354,6 +4354,12 @@ Translated:You are connected to the Emulator not an actual printer. English:You can also Translated:You can also +English:You have {0} unsave design(s). Wolud you like to save changes before closing? +Translated:You have {0} unsave design(s). Wolud you like to save changes before closing? + +English:You have one unsave design ({0}). Wolud you like to save changes before closing? +Translated:You have one unsave design ({0}). Wolud you like to save changes before closing? + English:You have successfully imported a new printer profile. You can find '{0}' in your list of available printers. Translated:You have successfully imported a new printer profile. You can find '{0}' in your list of available printers.