From d88b82ddb2938161d81a56e7d342bad58bfec122 Mon Sep 17 00:00:00 2001 From: jlewin Date: Thu, 4 Apr 2019 16:52:17 -0700 Subject: [PATCH 1/5] Reduce accessibility --- .../ConfigurationPage/PrintLeveling/WizardPages/WizardPage.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/WizardPage.cs b/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/WizardPage.cs index c02ff842c..b997a9360 100644 --- a/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/WizardPage.cs +++ b/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/WizardPage.cs @@ -108,7 +108,7 @@ namespace MatterHackers.MatterControl base.OnClosed(e); } - public void ShowWizardFinished() + protected void ShowWizardFinished() { var doneButton = new TextButton("Done".Localize(), theme) { From 4f3fbba14de22ee41026537b700ea26b32d8dc3b Mon Sep 17 00:00:00 2001 From: jlewin Date: Thu, 4 Apr 2019 16:54:33 -0700 Subject: [PATCH 2/5] Replace RunAnyRequiredPrinterSetup with Wizard.NextIncompleteStage() --- .../ApplicationView/ApplicationController.cs | 47 ------------------- .../CalibrateProbeLastPageInstructions.cs | 6 --- .../WizardPages/LastPageInstructions.cs | 8 ---- .../WizardPages/SelectMaterialPage.cs | 1 + .../PrintLeveling/WizardPages/WizardPage.cs | 9 +++- .../SetupWizard/StagedSetupWindow.cs | 14 ++++++ 6 files changed, 23 insertions(+), 62 deletions(-) diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index 7b5ef8156..a686cab26 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -1621,53 +1621,6 @@ namespace MatterHackers.MatterControl || ProbeCalibrationWizard.NeedsToBeRun(printer); } - public bool RunAnyRequiredPrinterSetup(PrinterConfig printer, ThemeConfig theme) - { - // run probe calibration first if we need to - if (ProbeCalibrationWizard.NeedsToBeRun(printer)) - { - UiThread.RunOnIdle(() => - { - DialogWindow.Show(new ProbeCalibrationWizard(printer)); - }); - return true; - } - - // run the leveling wizard if we need to - if (LevelingValidation.NeedsToBeRun(printer)) - { - UiThread.RunOnIdle(() => - { - DialogWindow.Show(new PrintLevelingWizard(printer)); - }); - return true; - } - - // run load filament if we need to - if (LoadFilamentWizard.NeedsToBeRun0(printer)) - { - UiThread.RunOnIdle(() => - { - DialogWindow.Show( - new LoadFilamentWizard(printer, extruderIndex: 0, showAlreadyLoadedButton: true)); - }); - return true; - } - - // run load filament for extruder 1 if we need to - if (LoadFilamentWizard.NeedsToBeRun1(printer)) - { - UiThread.RunOnIdle(() => - { - DialogWindow.Show( - new LoadFilamentWizard(printer, extruderIndex: 1, showAlreadyLoadedButton: true)); - }); - return true; - } - - return false; - } - public void Shutdown() { // Ensure all threads shutdown gracefully on close diff --git a/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/CalibrateProbeLastPageInstructions.cs b/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/CalibrateProbeLastPageInstructions.cs index 6a952e3eb..a4a12c46e 100644 --- a/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/CalibrateProbeLastPageInstructions.cs +++ b/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/CalibrateProbeLastPageInstructions.cs @@ -77,11 +77,5 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling base.OnLoad(args); } - - public override void OnClosed(EventArgs e) - { - // move from this wizard to the print leveling wizard if needed - ApplicationController.Instance.RunAnyRequiredPrinterSetup(printer, theme); - } } } \ No newline at end of file diff --git a/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/LastPageInstructions.cs b/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/LastPageInstructions.cs index a36452ed5..54a86877e 100644 --- a/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/LastPageInstructions.cs +++ b/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/LastPageInstructions.cs @@ -106,13 +106,5 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling base.OnLoad(args); } - - public override void OnClosed(EventArgs e) - { - // give instruction about how to load filament if the user has not gotten them - ApplicationController.Instance.RunAnyRequiredPrinterSetup(printer, theme); - - base.OnClosed(e); - } } } \ No newline at end of file diff --git a/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/SelectMaterialPage.cs b/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/SelectMaterialPage.cs index ff08f69d4..d0ef101f0 100644 --- a/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/SelectMaterialPage.cs +++ b/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/SelectMaterialPage.cs @@ -82,6 +82,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling alreadyLoadedButton.Click += (s, e) => { this.DialogWindow.ClosePage(); + switch (extruderIndex) { case 0: diff --git a/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/WizardPage.cs b/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/WizardPage.cs index b997a9360..d46de43b4 100644 --- a/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/WizardPage.cs +++ b/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/WizardPage.cs @@ -118,7 +118,14 @@ namespace MatterHackers.MatterControl doneButton.Click += (s, e) => { - this.DialogWindow.ClosePage(); + if (this.DialogWindow is StagedSetupWindow setupWindow) + { + setupWindow.NextIncompleteStage(); + } + else + { + this.DialogWindow.ClosePage(); + } }; this.AddPageAction(doneButton); diff --git a/MatterControlLib/SetupWizard/StagedSetupWindow.cs b/MatterControlLib/SetupWizard/StagedSetupWindow.cs index 041fa71c5..f1ac0a8ed 100644 --- a/MatterControlLib/SetupWizard/StagedSetupWindow.cs +++ b/MatterControlLib/SetupWizard/StagedSetupWindow.cs @@ -157,6 +157,20 @@ namespace MatterHackers.MatterControl this.Invalidate(); } + public void NextIncompleteStage() + { + ISetupWizard nextStage = stages.FirstOrDefault(s => s.SetupRequired); + + if (nextStage != null) + { + this.ActiveStage = nextStage; + } + else + { + this.ClosePage(); + } + } + public override void ClosePage() { // Move to the summary/home page From 50e2419d725d2c09cde0119ce2595073526307bb Mon Sep 17 00:00:00 2001 From: jlewin Date: Thu, 4 Apr 2019 17:18:12 -0700 Subject: [PATCH 3/5] Improve support for StagedSetupWizards --- .../ControlWidgets/CalibrationControls.cs | 25 +----- .../ControlWidgets/IStagedSetupWizard.cs | 43 ++++++++++ .../PrinterCalibrationWizard.cs | 84 +++++++++++++++++++ MatterControlLib/SetupWizard/DialogWindow.cs | 12 ++- .../SetupWizard/StagedSetupWindow.cs | 18 ++-- 5 files changed, 141 insertions(+), 41 deletions(-) create mode 100644 MatterControlLib/PrinterControls/ControlWidgets/IStagedSetupWizard.cs create mode 100644 MatterControlLib/PrinterControls/ControlWidgets/PrinterCalibrationWizard.cs diff --git a/MatterControlLib/PrinterControls/ControlWidgets/CalibrationControls.cs b/MatterControlLib/PrinterControls/ControlWidgets/CalibrationControls.cs index 18fc9200e..247a76525 100644 --- a/MatterControlLib/PrinterControls/ControlWidgets/CalibrationControls.cs +++ b/MatterControlLib/PrinterControls/ControlWidgets/CalibrationControls.cs @@ -72,30 +72,7 @@ namespace MatterHackers.MatterControl.PrinterControls { UiThread.RunOnIdle(() => { - DialogWindow.Show( - "Printer Calibration".Localize(), - new Vector2(1200, 700), - new ISetupWizard[] - { - new PrintLevelingWizard(printer), - new ProbeCalibrationWizard(printer), - new XyCalibrationWizard(printer, 1) - }, - () => - { - var homePage = new WizardSummaryPage() - { - HeaderText = "Printer Setup & Calibration".Localize() - }; - - homePage.ContentRow.AddChild( - new WrappedTextWidget( - @"Select the calibration task on the left to continue".Replace("\r\n", "\n"), - pointSize: theme.DefaultFontSize, - textColor: theme.TextColor)); - - return homePage; - }); + DialogWindow.Show(new PrinterCalibrationWizard(printer, theme)); }); }; settingsRow.AddChild(runWizardButton); diff --git a/MatterControlLib/PrinterControls/ControlWidgets/IStagedSetupWizard.cs b/MatterControlLib/PrinterControls/ControlWidgets/IStagedSetupWizard.cs new file mode 100644 index 000000000..0c31855a7 --- /dev/null +++ b/MatterControlLib/PrinterControls/ControlWidgets/IStagedSetupWizard.cs @@ -0,0 +1,43 @@ +/* +Copyright (c) 2019, Lars Brubaker, John Lewin +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +The views and conclusions contained in the software and documentation are those +of the authors and should not be interpreted as representing official policies, +either expressed or implied, of the FreeBSD Project. +*/ + +using System; +using System.Collections.Generic; +using MatterHackers.VectorMath; + +namespace MatterHackers.MatterControl +{ + public interface IStagedSetupWizard + { + IEnumerable Stages { get; } + string Title { get; } + Vector2 WindowSize { get; } + Func HomePageGenerator { get; } + } +} \ No newline at end of file diff --git a/MatterControlLib/PrinterControls/ControlWidgets/PrinterCalibrationWizard.cs b/MatterControlLib/PrinterControls/ControlWidgets/PrinterCalibrationWizard.cs new file mode 100644 index 000000000..9bf96ba9c --- /dev/null +++ b/MatterControlLib/PrinterControls/ControlWidgets/PrinterCalibrationWizard.cs @@ -0,0 +1,84 @@ +/* +Copyright (c) 2019, Lars Brubaker, John Lewin +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +The views and conclusions contained in the software and documentation are those +of the authors and should not be interpreted as representing official policies, +either expressed or implied, of the FreeBSD Project. +*/ + +using System; +using System.Collections.Generic; +using MatterHackers.Agg.UI; +using MatterHackers.Localizations; +using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling; +using MatterHackers.MatterControl.PrinterControls; +using MatterHackers.VectorMath; + +namespace MatterHackers.MatterControl +{ + public class PrinterCalibrationWizard : IStagedSetupWizard + { + public PrinterCalibrationWizard(PrinterConfig printer, ThemeConfig theme) + { + this.Stages = new ISetupWizard[] + { + new PrintLevelingWizard(printer), + new ProbeCalibrationWizard(printer), + new XyCalibrationWizard(printer, 1) + }; + + this.HomePageGenerator = () => + { + var homePage = new WizardSummaryPage() + { + HeaderText = "Printer Setup & Calibration".Localize() + }; + + homePage.ContentRow.AddChild( + new WrappedTextWidget( + @"Select the calibration task on the left to continue".Replace("\r\n", "\n"), + pointSize: theme.DefaultFontSize, + textColor: theme.TextColor)); + + return homePage; + }; + } + + public string Title { get; } = "Printer Calibration".Localize(); + + public Vector2 WindowSize { get; } = new Vector2(1200, 700); + + public IEnumerable Stages { get; } + + public Func HomePageGenerator { get; } + + public static bool SetupRequired(PrinterConfig printer) + { + return LevelingValidation.NeedsToBeRun(printer) // PrintLevelingWizard + || ProbeCalibrationWizard.NeedsToBeRun(printer) + || LoadFilamentWizard.NeedsToBeRun0(printer) + || LoadFilamentWizard.NeedsToBeRun1(printer); + } + } +} \ No newline at end of file diff --git a/MatterControlLib/SetupWizard/DialogWindow.cs b/MatterControlLib/SetupWizard/DialogWindow.cs index 496ded97c..0c261e319 100644 --- a/MatterControlLib/SetupWizard/DialogWindow.cs +++ b/MatterControlLib/SetupWizard/DialogWindow.cs @@ -87,19 +87,17 @@ namespace MatterHackers.MatterControl return wizardWindow; } - public static DialogWindow Show(string title, Vector2 windowSize, IEnumerable stages, Func homePageGenerator) + public static DialogWindow Show(IStagedSetupWizard setupWizard) { - var wizardStages = stages.ToList(); - var type = homePageGenerator.GetType(); + var type = setupWizard.GetType(); - var homePage = homePageGenerator(); - - var wizardWindow = new StagedSetupWindow(title, stages, homePageGenerator); + var wizardWindow = new StagedSetupWindow(setupWizard); wizardWindow.Closed += (s, e) => allWindows.Remove(type); allWindows[type] = wizardWindow; - wizardWindow.Size = windowSize; + wizardWindow.Size = setupWizard.WindowSize; + var homePage = setupWizard.HomePageGenerator(); SetSizeAndShow(wizardWindow, homePage); wizardWindow.ChangeToPage(homePage); diff --git a/MatterControlLib/SetupWizard/StagedSetupWindow.cs b/MatterControlLib/SetupWizard/StagedSetupWindow.cs index f1ac0a8ed..e4c9e0610 100644 --- a/MatterControlLib/SetupWizard/StagedSetupWindow.cs +++ b/MatterControlLib/SetupWizard/StagedSetupWindow.cs @@ -37,8 +37,6 @@ namespace MatterHackers.MatterControl { public class StagedSetupWindow : DialogWindow { - private IEnumerable stages; - private Func homePageGenerator; private FlowLayoutWidget leftPanel; private DialogPage activePage; private GuiWidget rightPanel; @@ -46,6 +44,7 @@ namespace MatterHackers.MatterControl private ISetupWizard _activeStage; private Dictionary stageButtons = new Dictionary(); + private IStagedSetupWizard setupWizard; public ISetupWizard ActiveStage { @@ -82,10 +81,9 @@ namespace MatterHackers.MatterControl } } - public StagedSetupWindow(string title, IEnumerable stages, Func homePageGenerator) + public StagedSetupWindow(IStagedSetupWizard setupWizard) { - this.stages = stages; - this.homePageGenerator = homePageGenerator; + this.setupWizard = setupWizard; var theme = AppContext.Theme; @@ -105,7 +103,7 @@ namespace MatterHackers.MatterControl }); int i = 1; - foreach (var stage in stages.Where(s => s.Visible)) + foreach (var stage in setupWizard.Stages.Where(s => s.Visible)) { var stageWidget = new WizardStageRow( $"{i++}. {stage.Title}", @@ -129,7 +127,7 @@ namespace MatterHackers.MatterControl VAnchor = VAnchor.Stretch }); - this.Title = title; + this.Title = setupWizard.Title; // Multi-part wizard should not try to resize per page this.UseChildWindowSize = false; @@ -159,7 +157,7 @@ namespace MatterHackers.MatterControl public void NextIncompleteStage() { - ISetupWizard nextStage = stages.FirstOrDefault(s => s.SetupRequired); + ISetupWizard nextStage = setupWizard.Stages.FirstOrDefault(s => s.SetupRequired); if (nextStage != null) { @@ -173,8 +171,8 @@ namespace MatterHackers.MatterControl public override void ClosePage() { - // Move to the summary/home page - this.ChangeToPage(homePageGenerator()); + // Construct and move to the summary/home page + this.ChangeToPage(setupWizard.HomePageGenerator()); this.ActiveStage = null; } From a2fc4b916aab0fb2944de38b250e992eae7334aa Mon Sep 17 00:00:00 2001 From: jlewin Date: Thu, 4 Apr 2019 17:18:52 -0700 Subject: [PATCH 4/5] Add support for launching into next incomplete stage --- MatterControlLib/SetupWizard/DialogWindow.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/MatterControlLib/SetupWizard/DialogWindow.cs b/MatterControlLib/SetupWizard/DialogWindow.cs index 0c261e319..b61710f79 100644 --- a/MatterControlLib/SetupWizard/DialogWindow.cs +++ b/MatterControlLib/SetupWizard/DialogWindow.cs @@ -87,7 +87,7 @@ namespace MatterHackers.MatterControl return wizardWindow; } - public static DialogWindow Show(IStagedSetupWizard setupWizard) + public static DialogWindow Show(IStagedSetupWizard setupWizard, bool advanceToIncompleteStage = false) { var type = setupWizard.GetType(); @@ -100,7 +100,14 @@ namespace MatterHackers.MatterControl var homePage = setupWizard.HomePageGenerator(); SetSizeAndShow(wizardWindow, homePage); - wizardWindow.ChangeToPage(homePage); + if (advanceToIncompleteStage) + { + wizardWindow.NextIncompleteStage(); + } + else + { + wizardWindow.ChangeToPage(homePage); + } return wizardWindow; } From 1c08ccadebe324da7c1b202be9d882a1f45a0861 Mon Sep 17 00:00:00 2001 From: jlewin Date: Thu, 4 Apr 2019 17:26:16 -0700 Subject: [PATCH 5/5] Reuse new wizard launcher, switch to incomplete stage mode --- .../ApplicationView/ApplicationController.cs | 11 ++++++++--- MatterControlLib/ApplicationView/PrinterConfig.cs | 12 +++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index a686cab26..84b91510d 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -2367,10 +2367,15 @@ namespace MatterHackers.MatterControl try { - // If leveling is required or is currently on - if(this.RunAnyRequiredPrinterSetup(printer, this.Theme)) + if (PrinterCalibrationWizard.SetupRequired(printer)) { - // We need to calibrate. So, don't print this part. + UiThread.RunOnIdle(() => + { + DialogWindow.Show( + new PrinterCalibrationWizard(printer, AppContext.Theme), + advanceToIncompleteStage: true); + }); + return; } diff --git a/MatterControlLib/ApplicationView/PrinterConfig.cs b/MatterControlLib/ApplicationView/PrinterConfig.cs index 0660480b5..d7897289c 100644 --- a/MatterControlLib/ApplicationView/PrinterConfig.cs +++ b/MatterControlLib/ApplicationView/PrinterConfig.cs @@ -385,7 +385,17 @@ namespace MatterHackers.MatterControl { if (sender is PrinterConfig printer) { - ApplicationController.Instance.RunAnyRequiredPrinterSetup(printer, ApplicationController.Instance.Theme); + if (PrinterCalibrationWizard.SetupRequired(printer)) + { + UiThread.RunOnIdle(() => + { + DialogWindow.Show( + new PrinterCalibrationWizard(printer, AppContext.Theme), + advanceToIncompleteStage: true); + }); + + return; + } } }