Reuse LoadFilamentWizard in XYCalibrationWizard

MatterHackers/MCCentral#5266
XYCalibration Wizard should include LoadFilament pages if materials
are unknown
This commit is contained in:
jlewin 2019-04-15 15:10:19 -07:00
parent c327fce29b
commit d0d2317600
5 changed files with 86 additions and 5 deletions

View file

@ -46,5 +46,11 @@ namespace MatterHackers.MatterControl
bool Visible { get; }
bool Enabled { get; }
/// <summary>
/// Allow the wizard to participate in the ClosePage process, optionally aborting the close if needed.
/// </summary>
/// <returns>A value indicating if the owning window should be closed on page close.</returns>
bool ClosePage();
}
}

View file

@ -76,9 +76,15 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
var extruderCount = printer.Settings.GetValue<int>(SettingsKey.extruder_count);
return extruderCount > 1 && !printer.Settings.GetValue<bool>(SettingsKey.filament_1_has_been_loaded);
}
// Not implemented - callers should use FilamentSetupWizard.SetupRequired
public override bool SetupRequired => false;
public IEnumerator<WizardPage> GetWizardPages()
{
return this.GetPages();
}
protected override IEnumerator<WizardPage> GetPages()
{
// Initialize - store startup temp and extruder index

View file

@ -74,6 +74,11 @@ namespace MatterHackers.MatterControl
public Vector2 WindowSize { get; protected set; }
public virtual bool ClosePage()
{
return true;
}
public bool MoveNext()
{
// Shutdown active page

View file

@ -57,11 +57,14 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
public QualityType Quality { get; set; } = QualityType.Normal;
/// <summary>
/// The index of the calibration print that was picked
/// Gets or sets the index of the X calibration item that was selected by the user.
/// </summary>
public int XPick { get; set; } = -1;
public int YPick { get; set; } = -1;
public double Offset { get; set; } = .1;
public bool PrintAgain { get; set; }
public override bool SetupRequired => NeedsToBeRun(printer);
@ -97,9 +100,59 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
base.Dispose();
}
public bool allowChildClose = true;
public bool childRequestedClose = false;
public override bool ClosePage()
{
childRequestedClose = true;
return allowChildClose;
}
protected override IEnumerator<WizardPage> GetPages()
{
yield return new XyCalibrationSelectPage(this);
// run load filament if we need to
if (LoadFilamentWizard.NeedsToBeRun0(printer))
{
using (var tool0FilamentWizard = new LoadFilamentWizard(printer, extruderIndex: 0, showAlreadyLoadedButton: true))
{
allowChildClose = false;
childRequestedClose = false;
var pages = tool0FilamentWizard.GetWizardPages();
while (!childRequestedClose
&& pages.MoveNext())
{
yield return pages.Current;
}
allowChildClose = true;
}
}
if (LoadFilamentWizard.NeedsToBeRun1(printer))
{
using (var tool1FilamentWizard = new LoadFilamentWizard(printer, extruderIndex: 1, showAlreadyLoadedButton: true))
{
allowChildClose = false;
childRequestedClose = false;
var pages = tool1FilamentWizard.GetWizardPages();
while (!childRequestedClose
&& pages.MoveNext())
{
yield return pages.Current;
}
allowChildClose = true;
}
}
yield return new XyCalibrationStartPrintPage(this);
originalEditContext = printer.Bed.EditContext;

View file

@ -77,7 +77,7 @@ namespace MatterHackers.MatterControl
_activeStage.Reset();
_activeStage.MoveNext();
this.ChangeToPage(_activeStage.Current); ;
this.ChangeToPage(_activeStage.Current);
}
}
@ -171,10 +171,21 @@ namespace MatterHackers.MatterControl
public override void ClosePage()
{
// Construct and move to the summary/home page
this.ChangeToPage(setupWizard.HomePageGenerator());
if (this.ActiveStage?.ClosePage() == true)
{
// Construct and move to the summary/home page
this.ChangeToPage(setupWizard.HomePageGenerator());
this.ActiveStage = null;
this.ActiveStage = null;
}
else
{
if (this.ActiveStage != null)
{
this.ActiveStage.MoveNext();
this.ChangeToPage(this.ActiveStage.Current);
}
}
}
public override DialogPage ChangeToPage<PanelType>()