Reduce wizard definitions to new ISetupWizard interface

- Remove overlapping roles with DialogPage
- Use ISetupWizard to define forward through page definitions
- Remove PrinterSetupWizardRootPage, use first page in Pages
This commit is contained in:
John Lewin 2019-02-16 00:44:35 -08:00 committed by jlewin
parent 4e0078ebf0
commit 029f4fc0a7
16 changed files with 100 additions and 101 deletions

View file

@ -1,5 +1,5 @@
/*
Copyright (c) 2018, Lars Brubaker, John Lewin
Copyright (c) 2019, Lars Brubaker, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -27,23 +27,14 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System;
namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
namespace MatterHackers.MatterControl
{
public class PrinterSetupWizardRootPage : DialogPage
public interface ISetupWizard
{
private PrinterSetupWizard printerSetupWizard;
PrinterConfig Printer { get; }
public PrinterSetupWizardRootPage(PrinterSetupWizard printerSetupWizard)
{
this.printerSetupWizard = printerSetupWizard;
}
WizardPage GetNextPage();
public override void OnLoad(EventArgs args)
{
printerSetupWizard.ShowNextPage(this.DialogWindow);
base.OnLoad(args);
}
WizardPage CurrentPage { get; }
}
}

View file

@ -51,13 +51,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
var loadFilamentWizard = new LoadFilamentWizard(printer, extruderIndex, showAlreadyLoadedButton);
loadFilamentWizard.WindowTitle = $"{ApplicationController.Instance.ProductName} - " + "Load Filament Wizard".Localize();
var loadFilamentWizardWindow = DialogWindow.Show(new PrinterSetupWizardRootPage(loadFilamentWizard)
{
WindowTitle = loadFilamentWizard.WindowTitle
});
loadFilamentWizardWindow.Closed += (s, e) =>
var dialogWindow = DialogWindow.Show(loadFilamentWizard.CurrentPage);
dialogWindow.Closed += (s, e) =>
{
printer.Connection.SetTargetHotendTemperature(extruderIndex, loadFilamentWizard.TemperatureAtStart);
};
@ -67,6 +62,10 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
: base(printer)
{
this.showAlreadyLoadedButton = showAlreadyLoadedButton;
pages = this.GetPages();
pages.MoveNext();
TemperatureAtStart = printer.Connection.GetTargetHotendTemperature(extruderIndex);
this.extruderIndex = extruderIndex;
}
@ -82,7 +81,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
return extruderCount > 1 && !printer.Settings.GetValue<bool>(SettingsKey.filament_1_has_been_loaded);
}
protected override IEnumerator<WizardPage> GetWizardSteps()
private IEnumerator<WizardPage> GetPages()
{
var extruderCount = printer.Settings.GetValue<int>(SettingsKey.extruder_count);
@ -96,7 +95,10 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
}
// select the material
yield return new SelectMaterialPage(this, title, instructions, "Select".Localize(), extruderIndex, true, showAlreadyLoadedButton);
yield return new SelectMaterialPage(this, title, instructions, "Select".Localize(), extruderIndex, true, showAlreadyLoadedButton)
{
WindowTitle = $"{ApplicationController.Instance.ProductName} - " + "Load Filament Wizard".Localize()
};
var theme = ApplicationController.Instance.Theme;

View file

@ -45,6 +45,9 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
: base(printer)
{
this.levelingPlan = levelingPlan;
pages = this.GetPages();
pages.MoveNext();
}
public bool WindowHasBeenClosed { get; private set; }
@ -105,23 +108,16 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
throw new NotImplementedException();
}
var levelingContext = new PrintLevelingWizard(levelingPlan, printer)
{
WindowTitle = $"{ApplicationController.Instance.ProductName} - " + "Print Leveling Wizard".Localize()
};
var printLevelWizardWindow = DialogWindow.Show(new PrinterSetupWizardRootPage(levelingContext)
{
WindowTitle = levelingContext.WindowTitle
});
printLevelWizardWindow.Closed += (s, e) =>
var levelingWizard = new PrintLevelingWizard(levelingPlan, printer);
var dialogWindow = DialogWindow.Show(levelingWizard.CurrentPage);
dialogWindow.Closed += (s, e) =>
{
// If leveling was on when we started, make sure it is on when we are done.
printer.Connection.AllowLeveling = true;
printLevelWizardWindow = null;
levelingContext.WindowHasBeenClosed = true;
dialogWindow = null;
levelingWizard.WindowHasBeenClosed = true;
// make sure we raise the probe on close
if (printer.Settings.GetValue<bool>(SettingsKey.has_z_probe)
@ -135,7 +131,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
};
}
protected override IEnumerator<WizardPage> GetWizardSteps()
private IEnumerator<WizardPage> GetPages()
{
var probePositions = new List<ProbePosition>(levelingPlan.ProbeCount);
for (int j = 0; j < levelingPlan.ProbeCount; j++)
@ -149,6 +145,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
bool showWelcomeScreen = printer.Settings.Helpers.GetPrintLevelingData().SampledPositions.Count == 0
&& !ProbeCalibrationWizard.UsingZProbe(printer);
string windowTitle = string.Format("{0} - {1}", ApplicationController.Instance.ProductName, "Print Leveling Wizard".Localize());
if (showWelcomeScreen)
{
yield return new WizardPage(
@ -157,7 +155,10 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
string.Format(
"{0}\n\n{1}",
"Congratulations on connecting to your printer. Before starting your first print we need to run a simple calibration procedure.".Localize(),
"The next few screens will walk your through calibrating your printer.".Localize()));
"The next few screens will walk your through calibrating your printer.".Localize()))
{
WindowTitle = windowTitle
};
}
bool hasHeatedBed = printer.Settings.GetValue<bool>(SettingsKey.has_heated_bed);
@ -202,7 +203,10 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
yield return new WizardPage(
this,
"Print Leveling Overview".Localize(),
buildWelcomeText());
buildWelcomeText())
{
WindowTitle = windowTitle
};
yield return new HomePrinterPage(
this,

View file

@ -28,17 +28,12 @@ either expressed or implied, of the FreeBSD Project.
*/
using System.Collections.Generic;
using MatterHackers.Agg.UI;
namespace MatterHackers.MatterControl
{
public abstract class PrinterSetupWizard
public abstract class PrinterSetupWizard : ISetupWizard
{
private IEnumerator<WizardPage> pages;
protected abstract IEnumerator<WizardPage> GetWizardSteps();
public string WindowTitle { get; internal set; }
protected IEnumerator<WizardPage> pages;
protected PrinterConfig printer;
@ -47,22 +42,20 @@ namespace MatterHackers.MatterControl
public PrinterSetupWizard(PrinterConfig printer)
{
this.printer = printer;
this.pages = this.GetWizardSteps();
}
public void ShowNextPage(DialogWindow dialogWindow)
{
UiThread.RunOnIdle(() =>
{
// Shutdown active page
pages.Current?.Close();
public WizardPage CurrentPage => pages.Current;
// Advance
if (pages.MoveNext())
{
dialogWindow.ChangeToPage(pages.Current);
}
});
public WizardPage GetNextPage()
{
// Shutdown active page
pages.Current?.Close();
// Advance
pages.MoveNext();
return pages.Current;
}
}
}

View file

@ -41,6 +41,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
public ProbeCalibrationWizard(PrinterConfig printer)
: base(printer)
{
pages = this.GetPages();
pages.MoveNext();
}
public static bool NeedsToBeRun(PrinterConfig printer)
@ -54,21 +56,15 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
// turn off print leveling
printer.Connection.AllowLeveling = false;
var levelingContext = new ProbeCalibrationWizard(printer)
{
WindowTitle = $"{ApplicationController.Instance.ProductName} - " + "Probe Calibration Wizard".Localize()
};
var probeWizard = new ProbeCalibrationWizard(printer);
var probeCalibrationWizardWindow = DialogWindow.Show(new PrinterSetupWizardRootPage(levelingContext)
{
WindowTitle = levelingContext.WindowTitle
});
probeCalibrationWizardWindow.Closed += (s, e) =>
var dialogWindow = DialogWindow.Show(probeWizard.CurrentPage);
dialogWindow.Closed += (s, e) =>
{
// If leveling was on when we started, make sure it is on when we are done.
printer.Connection.AllowLeveling = true;
probeCalibrationWizardWindow = null;
dialogWindow = null;
// make sure we raise the probe on close
if (printer.Settings.GetValue<bool>(SettingsKey.has_z_probe)
@ -92,7 +88,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
&& printer.Settings.GetValue<bool>(SettingsKey.use_z_probe);
}
protected override IEnumerator<WizardPage> GetWizardSteps()
private IEnumerator<WizardPage> GetPages()
{
var levelingStrings = new LevelingStrings();
var autoProbePositions = new List<ProbePosition>(3);
@ -103,6 +99,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
int totalSteps = 3;
string windowTitle = $"{ApplicationController.Instance.ProductName} - " + "Probe Calibration Wizard".Localize();
// make a welcome page if this is the first time calibrating the probe
if (!printer.Settings.GetValue<bool>(SettingsKey.probe_has_been_calibrated))
{
@ -112,7 +110,10 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
string.Format(
"{0}\n\n{1}",
"Congratulations on connecting to your printer. Before starting your first print we need to run a simple calibration procedure.".Localize(),
"The next few screens will walk your through calibrating your printer.".Localize()));
"The next few screens will walk your through calibrating your printer.".Localize()))
{
WindowTitle = windowTitle
};
}
// show what steps will be taken
@ -126,7 +127,10 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
"Probe the bed at the center".Localize(),
"Manually measure the extruder at the center".Localize(),
"We should be done in less than five minutes.".Localize(),
"Click 'Next' to continue.".Localize()));
"Click 'Next' to continue.".Localize()))
{
WindowTitle = windowTitle
};
// add in the homing printer page
yield return new HomePrinterPage(

View file

@ -48,16 +48,10 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
public static void Start(PrinterConfig printer, ThemeConfig theme, int extruderIndex)
{
// turn off print leveling
var levelingContext = new UnloadFilamentWizard(printer, extruderIndex)
{
WindowTitle = $"{ApplicationController.Instance.ProductName} - " + "Unload Filament Wizard".Localize()
};
var unloadWizard = new UnloadFilamentWizard(printer, extruderIndex);
var loadFilamentWizardWindow = DialogWindow.Show(new PrinterSetupWizardRootPage(levelingContext)
{
WindowTitle = levelingContext.WindowTitle
});
loadFilamentWizardWindow.Closed += (s, e) =>
var dialogWindow = DialogWindow.Show(unloadWizard.CurrentPage);
dialogWindow.Closed += (s, e) =>
{
printer.Connection.TurnOffBedAndExtruders(TurnOff.AfterDelay);
};
@ -66,10 +60,13 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
public UnloadFilamentWizard(PrinterConfig printer, int extruderIndex)
: base(printer)
{
pages = this.GetPages();
pages.MoveNext();
this.extruderIndex = extruderIndex;
}
protected override IEnumerator<WizardPage> GetWizardSteps()
private IEnumerator<WizardPage> GetPages()
{
var extruderCount = printer.Settings.GetValue<int>(SettingsKey.extruder_count);
@ -83,7 +80,10 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
}
// select the material
yield return new SelectMaterialPage(this, title, instructions, "Unload".Localize(), extruderIndex, false, false);
yield return new SelectMaterialPage(this, title, instructions, "Unload".Localize(), extruderIndex, false, false)
{
WindowTitle = $"{ApplicationController.Instance.ProductName} - " + "Unload Filament Wizard".Localize()
};
var theme = ApplicationController.Instance.Theme;

View file

@ -44,13 +44,12 @@ namespace MatterHackers.MatterControl
public Action PageClose { get; set; }
protected PrinterSetupWizard setupWizard;
protected ISetupWizard setupWizard;
public WizardPage(PrinterSetupWizard setupWizard, string headerText, string instructionsText)
public WizardPage(ISetupWizard setupWizard, string headerText, string instructionsText)
{
this.setupWizard = setupWizard;
this.printer = setupWizard.Printer;
this.WindowTitle = setupWizard.WindowTitle;
this.HeaderText = headerText;
if (!string.IsNullOrEmpty(instructionsText))
@ -59,17 +58,20 @@ namespace MatterHackers.MatterControl
this.CreateTextField(instructionsText.Replace("\t", " ")));
}
NextButton = new TextButton("Next".Localize(), theme)
this.NextButton = new TextButton("Next".Localize(), theme)
{
Name = "Next Button",
BackgroundColor = theme.MinimalShade
};
NextButton.Click += (s, e) =>
this.NextButton.Click += (s, e) =>
{
setupWizard.ShowNextPage(this.DialogWindow);
if (setupWizard.GetNextPage() is WizardPage wizardPage)
{
this.DialogWindow.ChangeToPage(wizardPage);
}
};
this.AddPageAction(NextButton);
this.AddPageAction(this.NextButton);
}
protected GuiWidget CreateTextField(string text)

View file

@ -46,7 +46,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
protected Vector3 probeStartPosition;
public AutoProbeFeedback(PrinterSetupWizard context, Vector3 probeStartPosition, string headerText, List<ProbePosition> probePositions, int probePositionsBeingEditedIndex)
public AutoProbeFeedback(ISetupWizard context, Vector3 probeStartPosition, string headerText, List<ProbePosition> probePositions, int probePositionsBeingEditedIndex)
: base(context, headerText, headerText)
{
this.probeStartPosition = probeStartPosition;

View file

@ -41,7 +41,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
private bool pageWasActive = false;
public CalibrateProbeLastPageInstructions(PrinterSetupWizard context, string headerText)
public CalibrateProbeLastPageInstructions(ISetupWizard context, string headerText)
: base(context, headerText, "")
{
var calibrated = "Your Probe is now calibrated.".Localize() + "\n"

View file

@ -49,7 +49,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
protected JogControls.MoveButton zMinusControl;
private RunningInterval runningInterval;
public FindBedHeight(PrinterSetupWizard context, string pageDescription, string setZHeightCoarseInstruction1, string setZHeightCoarseInstruction2, double moveDistance,
public FindBedHeight(ISetupWizard context, string pageDescription, string setZHeightCoarseInstruction1, string setZHeightCoarseInstruction2, double moveDistance,
List<ProbePosition> probePositions, int probePositionsBeingEditedIndex)
: base(context, pageDescription, setZHeightCoarseInstruction1)
{

View file

@ -34,7 +34,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
public class GetUltraFineBedHeight : FindBedHeight
{
public GetUltraFineBedHeight(PrinterSetupWizard context, string pageDescription, List<ProbePosition> probePositions,
public GetUltraFineBedHeight(ISetupWizard context, string pageDescription, List<ProbePosition> probePositions,
int probePositionsBeingEditedIndex, LevelingStrings levelingStrings)
: base(
context,

View file

@ -41,7 +41,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
private ProbePosition probePosition;
private EventHandler unregisterEvents;
public GettingThirdPointFor2PointCalibration(PrinterSetupWizard context, string pageDescription, Vector3 probeStartPosition, string instructionsText,
public GettingThirdPointFor2PointCalibration(ISetupWizard context, string pageDescription, Vector3 probeStartPosition, string instructionsText,
ProbePosition probePosition)
: base(context, pageDescription, instructionsText)
{

View file

@ -38,7 +38,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
private bool autoAdvance;
public HomePrinterPage(PrinterSetupWizard context, string headerText, string instructionsText, bool autoAdvance)
public HomePrinterPage(ISetupWizard context, string headerText, string instructionsText, bool autoAdvance)
: base(context, headerText, instructionsText)
{
this.autoAdvance = autoAdvance;

View file

@ -42,7 +42,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
private List<ProbePosition> probePositions;
public LastPageInstructions(PrinterSetupWizard context, string pageDescription, bool useZProbe, List<ProbePosition> probePositions)
public LastPageInstructions(ISetupWizard context, string pageDescription, bool useZProbe, List<ProbePosition> probePositions)
: base(context, pageDescription, "")
{
this.probePositions = probePositions;

View file

@ -36,7 +36,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
public class SelectMaterialPage : WizardPage
{
public SelectMaterialPage(PrinterSetupWizard context, string headerText, string instructionsText, string nextButtonText, int extruderIndex, bool showLoadFilamentButton, bool showAlreadyLoadedButton)
public SelectMaterialPage(ISetupWizard context, string headerText, string instructionsText, string nextButtonText, int extruderIndex, bool showLoadFilamentButton, bool showAlreadyLoadedButton)
: base(context, headerText, instructionsText)
{
contentRow.AddChild(
@ -59,7 +59,10 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
};
loadFilamentButton.Click += (s, e) =>
{
setupWizard.ShowNextPage(this.DialogWindow);
if(setupWizard.GetNextPage() is WizardPage wizardPage)
{
this.DialogWindow.ChangeToPage(wizardPage);
}
};
this.AddPageAction(loadFilamentButton);

View file

@ -52,7 +52,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
private List<TextWidget> hotEndDoneTexts = new List<TextWidget>();
private double[] targetHotendTemps;
public WaitForTempPage(PrinterSetupWizard context,
public WaitForTempPage(ISetupWizard context,
string step, string instructions,
double targetBedTemp, double[] targetHotendTemps)
: base(context, step, instructions)