diff --git a/Library/Widgets/PrintLibraryWidget.cs b/Library/Widgets/PrintLibraryWidget.cs index 5c2b6827d..6c4cfe4e0 100644 --- a/Library/Widgets/PrintLibraryWidget.cs +++ b/Library/Widgets/PrintLibraryWidget.cs @@ -377,6 +377,8 @@ namespace MatterHackers.MatterControl.PrintLibrary } } + ApplicationController.Instance.ActiveView3DWidget.partHasBeenEdited = true; + var scene = ApplicationController.Instance.ActiveView3DWidget.Scene; scene.ModifyChildren(children => { diff --git a/PartPreviewWindow/SaveAsWindow.cs b/PartPreviewWindow/SaveAsWindow.cs index 041cd7d3b..b0c13be0a 100644 --- a/PartPreviewWindow/SaveAsWindow.cs +++ b/PartPreviewWindow/SaveAsWindow.cs @@ -29,6 +29,7 @@ either expressed or implied, of the FreeBSD Project. using System; using System.IO; +using System.Threading.Tasks; using MatterHackers.Agg; using MatterHackers.Agg.UI; using MatterHackers.Localizations; @@ -44,7 +45,7 @@ namespace MatterHackers.MatterControl public class SaveAsWindow : SystemWindow { - private Action functionToCallOnSaveAs; + private Func functionToCallOnSaveAs; private TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory(); private MHTextEditWidget textToAddWidget; private ListView librarySelectorWidget; @@ -52,7 +53,7 @@ namespace MatterHackers.MatterControl private ILibraryContext libraryNavContext; - public SaveAsWindow(Action functionToCallOnSaveAs, ILibraryContainer providerLocator, bool showQueue, bool getNewName) + public SaveAsWindow(Func functionToCallOnSaveAs, ILibraryContainer providerLocator, bool showQueue, bool getNewName) : base(480, 500) { textImageButtonFactory.normalTextColor = ActiveTheme.Instance.PrimaryTextColor; @@ -224,7 +225,7 @@ namespace MatterHackers.MatterControl string fileName = Path.ChangeExtension(Path.GetRandomFileName(), ".amf"); string fileNameAndPath = Path.Combine(ApplicationDataStorage.Instance.ApplicationLibraryDataPath, fileName); - functionToCallOnSaveAs(new SaveAsReturnInfo(newName, fileNameAndPath, librarySelectorWidget.ActiveContainer), null); + functionToCallOnSaveAs(new SaveAsReturnInfo(newName, fileNameAndPath, librarySelectorWidget.ActiveContainer)); CloseOnIdle(); } diff --git a/PartPreviewWindow/View3D/View3DWidget.cs b/PartPreviewWindow/View3D/View3DWidget.cs index 4cec2c51b..fbfaa4690 100644 --- a/PartPreviewWindow/View3D/View3DWidget.cs +++ b/PartPreviewWindow/View3D/View3DWidget.cs @@ -182,14 +182,13 @@ namespace MatterHackers.MatterControl.PartPreviewWindow private static string PartsNotPrintableMessage = "Parts are not on the bed or outside the print area.\n\nWould you like to center them on the bed?".Localize(); private static string PartsNotPrintableTitle = "Parts not in print area".Localize(); - private Action afterSaveCallback = null; private bool editorThatRequestedSave = false; private ExportPrintItemWindow exportingWindow = null; private ObservableCollection extruderButtons = new ObservableCollection(); private bool hasDrawn = false; private OpenMode openMode; - private bool partHasBeenEdited = false; + internal bool partHasBeenEdited = false; private PrintItemWrapper printItemWrapper { get; set; } private ProgressControl processingProgressControl; private SaveAsWindow saveAsWindow = null; @@ -553,11 +552,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow // make sure the colors are set correct ThemeChanged(this, null); - saveButtons.VisibleChanged += (sender, e) => - { - partHasBeenEdited = true; - }; - if (DoBooleanTest) { BeforeDraw += CreateBooleanTestGeometry; @@ -976,6 +970,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow this.deferEditorTillMouseUp = false; Scene_SelectionChanged(null, null); + + this.PartHasBeenChanged(); } public override void OnLoad(EventArgs args) @@ -1060,6 +1056,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow dragDropItem.Matrix = loadedItem.Matrix * dragDropItem.Matrix; dragDropItem.Matrix *= Matrix4X4.CreateTranslation(-meshGroupCenter.x, -meshGroupCenter.y, -dragDropItem.GetAxisAlignedBoundingBox(Matrix4X4.Identity).minXYZ.z); } + + this.PartHasBeenChanged(); } public override void OnDraw(Graphics2D graphics2D) @@ -1556,6 +1554,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow public void PartHasBeenChanged() { + partHasBeenEdited = true; saveButtons.Visible = true; SelectedTransformChanged?.Invoke(this, null); Invalidate(); @@ -1985,6 +1984,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow currentRatioDone += ratioPerFile; } } + + this.PartHasBeenChanged(); } public void LockEditControls() @@ -2091,10 +2092,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow private GuiWidget selectedObjectPanel; private FlowLayoutWidget editorPanel; - private async void SaveChanges(SaveAsWindow.SaveAsReturnInfo returnInfo = null, Action eventToCallAfterSave = null) + private async Task SaveChanges(SaveAsWindow.SaveAsReturnInfo returnInfo = null) { editorThatRequestedSave = true; - afterSaveCallback = eventToCallAfterSave; if (Scene.HasChildren) { @@ -2176,7 +2176,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow UnlockEditControls(); saveButtons.Visible = true; - afterSaveCallback?.Invoke(); + partHasBeenEdited = false; } } @@ -2372,11 +2372,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow } // Before printing persist any changes to disk - internal void PersistPlateIfNeeded() + internal async Task PersistPlateIfNeeded() { if (partHasBeenEdited) { - SaveChanges(null); + await SaveChanges(null); } } diff --git a/PartPreviewWindow/ViewGcodeBasic.cs b/PartPreviewWindow/ViewGcodeBasic.cs index d8bddab0b..39d3d57c6 100644 --- a/PartPreviewWindow/ViewGcodeBasic.cs +++ b/PartPreviewWindow/ViewGcodeBasic.cs @@ -204,12 +204,16 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { if (ActiveSliceSettings.Instance.PrinterSelected) { - if (ActiveSliceSettings.Instance.IsValid() && printItem != null) + // Save any pending changes before starting the print + ApplicationController.Instance.ActiveView3DWidget.PersistPlateIfNeeded().ContinueWith((t) => { - generateGCodeButton.Visible = false; - SlicingQueue.Instance.QueuePartForSlicing(printItem); - startedSliceFromGenerateButton = true; - } + if (ActiveSliceSettings.Instance.IsValid() && printItem != null) + { + generateGCodeButton.Visible = false; + SlicingQueue.Instance.QueuePartForSlicing(printItem); + startedSliceFromGenerateButton = true; + } + }); } else { diff --git a/PrinterCommunication/PrinterConnectionAndCommunication.cs b/PrinterCommunication/PrinterConnectionAndCommunication.cs index 06285e1a6..d4adbfbf7 100644 --- a/PrinterCommunication/PrinterConnectionAndCommunication.cs +++ b/PrinterCommunication/PrinterConnectionAndCommunication.cs @@ -1335,7 +1335,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication } } - public void PrintActivePart(bool overrideAllowGCode = false) + public async void PrintActivePart(bool overrideAllowGCode = false) { try { @@ -1352,7 +1352,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication } // Save any pending changes before starting the print - ApplicationController.Instance.ActiveView3DWidget.PersistPlateIfNeeded(); + await ApplicationController.Instance.ActiveView3DWidget.PersistPlateIfNeeded(); if (ActivePrintItem != null) { diff --git a/Tests/MatterControl.AutomationTests/PrintingTests.cs b/Tests/MatterControl.AutomationTests/PrintingTests.cs index 354064d6e..1f60119d9 100644 --- a/Tests/MatterControl.AutomationTests/PrintingTests.cs +++ b/Tests/MatterControl.AutomationTests/PrintingTests.cs @@ -29,8 +29,8 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.SwitchToAdvancedSliceSettings(); - testRunner.ClickByName("Printer Tab", 1); - testRunner.ClickByName("Custom G-Code Tab", 1); + testRunner.ClickByName("Printer Tab"); + testRunner.ClickByName("Custom G-Code Tab"); testRunner.ClickByName("end_gcode Edit Field"); testRunner.Type("^a"); testRunner.Type("{BACKSPACE}"); @@ -38,7 +38,7 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.AddDefaultFileToBedplate(); - testRunner.ClickByName("Start Print Button", 1); + testRunner.ClickByName("Start Print Button"); // Wait for print to finish testRunner.WaitForPrintFinished(); diff --git a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs index 127f9486a..f8e2406c0 100644 --- a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs +++ b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs @@ -401,21 +401,18 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.ClickByName(partName); testRunner.AddSelectedItemToBedplate(); + testRunner.Delay(1); } public static void AddSelectedItemToBedplate(this AutomationRunner testRunner) { testRunner.ClickByName("Print Library Overflow Menu"); testRunner.ClickByName("Add to Plate Menu Item"); - - testRunner.ClickByName("Save Button"); - - testRunner.Delay(1); } public static void WaitForPrintFinished(this AutomationRunner testRunner) { - testRunner.Delay(() => PrinterConnectionAndCommunication.Instance.CommunicationState == PrinterConnectionAndCommunication.CommunicationStates.FinishedPrint, 120); + testRunner.Delay(() => PrinterConnectionAndCommunication.Instance.CommunicationState == PrinterConnectionAndCommunication.CommunicationStates.FinishedPrint, 500); } public static async Task RunTest(