From d3818471c52c2ea31cbf1fe62892d7dfb968b1c4 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Fri, 6 Apr 2018 14:58:25 -0700 Subject: [PATCH] Made probe calibration happen automatically if required --- ApplicationView/ApplicationController.cs | 40 +++++++++++++----- .../CalibrationControls.cs | 5 +-- .../PrintLeveling/LevelWizard13PointRadial.cs | 4 +- .../PrintLeveling/LevelWizard3Point.cs | 4 +- .../PrintLeveling/LevelWizard3x3Mesh.cs | 4 +- .../PrintLeveling/LevelWizard5x5Mesh.cs | 4 +- .../PrintLeveling/LevelWizard7PointRadial.cs | 4 +- .../PrintLeveling/LevelWizardBase.cs | 41 +++++++------------ .../PrintLeveling/PrintLevelPages.cs | 7 ++++ .../PrintLeveling/ProbeCalibrationWizard.cs | 21 ++++++++++ .../Settings/SettingsHelpers.cs | 1 + .../SlicerMapping/SliceEngineMapping.cs | 1 + StaticData/SliceSettings/Properties.json | 9 ++++ .../MatterControl/SettingsParseTests.cs | 2 +- 14 files changed, 96 insertions(+), 51 deletions(-) diff --git a/ApplicationView/ApplicationController.cs b/ApplicationView/ApplicationController.cs index b99c9f9b2..762b091fd 100644 --- a/ApplicationView/ApplicationController.cs +++ b/ApplicationView/ApplicationController.cs @@ -782,10 +782,7 @@ namespace MatterHackers.MatterControl var printer = ApplicationController.Instance.ActivePrinters.Where(p => p.Connection == s).FirstOrDefault(); if (printer != null) { - if (PrintLevelingData.NeedsToBeRun(printer)) - { - UiThread.RunOnIdle(() => LevelWizardBase.ShowPrintLevelWizard(printer)); - } + ApplicationController.Instance.RunAnyRequiredCalibration(printer); } }, ref unregisterEvents); @@ -807,6 +804,31 @@ namespace MatterHackers.MatterControl } } + public bool RunAnyRequiredCalibration(PrinterConfig printer) + { + if (PrintLevelingData.NeedsToBeRun(printer)) + { + // run probe calibration first if we need to + if (ProbeCalibrationWizard.NeedsToBeRun(printer)) + { + UiThread.RunOnIdle(() => + { + ProbeCalibrationWizard.ShowProbeCalibrationWizard(printer); + }); + } + else // run the leveling wizard + { + UiThread.RunOnIdle(() => + { + LevelWizardBase.ShowPrintLevelWizard(printer); + }); + } + return true; + } + + return false; + } + public HashSet GetEditorsForType(Type selectedItemType) { HashSet mappedEditors; @@ -1408,14 +1430,10 @@ namespace MatterHackers.MatterControl try { // If leveling is required or is currently on - if (ActiveSliceSettings.Instance.GetValue(SettingsKey.print_leveling_required_to_print) - || ActiveSliceSettings.Instance.GetValue(SettingsKey.print_leveling_enabled)) + if(ApplicationController.Instance.RunAnyRequiredCalibration(printer)) { - if (PrintLevelingData.NeedsToBeRun(printer)) - { - LevelWizardBase.ShowPrintLevelWizard(printer); - return; - } + // We need to calibrate. So, don't print this part. + return; } //if (!string.IsNullOrEmpty(partFilePath) && File.Exists(partFilePath)) diff --git a/ConfigurationPage/CalibrationSettings/CalibrationControls.cs b/ConfigurationPage/CalibrationSettings/CalibrationControls.cs index a1e279331..fbbd56b17 100644 --- a/ConfigurationPage/CalibrationSettings/CalibrationControls.cs +++ b/ConfigurationPage/CalibrationSettings/CalibrationControls.cs @@ -60,7 +60,7 @@ namespace MatterHackers.MatterControl.PrinterControls { UiThread.RunOnIdle(() => { - LevelWizardBase.ShowPrintLevelWizard(printer, LevelWizardBase.RunningState.UserRequestedCalibration); + LevelWizardBase.ShowPrintLevelWizard(printer); }); }; @@ -93,8 +93,7 @@ namespace MatterHackers.MatterControl.PrinterControls // add in the controls for configuring probe offset if (printer.Settings.GetValue(SettingsKey.has_z_probe) - && printer.Settings.GetValue(SettingsKey.use_z_probe) - && printer.Settings.GetValue(SettingsKey.has_z_servo)) + && printer.Settings.GetValue(SettingsKey.use_z_probe)) { var probeCalibrationRow = new FlowLayoutWidget() { diff --git a/ConfigurationPage/PrintLeveling/LevelWizard13PointRadial.cs b/ConfigurationPage/PrintLeveling/LevelWizard13PointRadial.cs index bf707d448..6c20c8fb4 100644 --- a/ConfigurationPage/PrintLeveling/LevelWizard13PointRadial.cs +++ b/ConfigurationPage/PrintLeveling/LevelWizard13PointRadial.cs @@ -36,8 +36,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling { public class LevelWizard13PointRadial : LevelWizardBase { - public LevelWizard13PointRadial(PrinterConfig printer, LevelWizardBase.RunningState runningState) - : base(printer, runningState) + public LevelWizard13PointRadial(PrinterConfig printer) + : base(printer) { } diff --git a/ConfigurationPage/PrintLeveling/LevelWizard3Point.cs b/ConfigurationPage/PrintLeveling/LevelWizard3Point.cs index 7b19ec5d2..6271e6abb 100644 --- a/ConfigurationPage/PrintLeveling/LevelWizard3Point.cs +++ b/ConfigurationPage/PrintLeveling/LevelWizard3Point.cs @@ -40,8 +40,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling { public class LevelWizard3Point : LevelWizardBase { - public LevelWizard3Point(PrinterConfig printer, LevelWizardBase.RunningState runningState) - : base(printer, runningState) + public LevelWizard3Point(PrinterConfig printer) + : base(printer) { } diff --git a/ConfigurationPage/PrintLeveling/LevelWizard3x3Mesh.cs b/ConfigurationPage/PrintLeveling/LevelWizard3x3Mesh.cs index 1f29ab934..0e51ffa07 100644 --- a/ConfigurationPage/PrintLeveling/LevelWizard3x3Mesh.cs +++ b/ConfigurationPage/PrintLeveling/LevelWizard3x3Mesh.cs @@ -37,8 +37,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling { public class LevelWizard3x3Mesh : LevelWizardBase { - public LevelWizard3x3Mesh(PrinterConfig printer, LevelWizardBase.RunningState runningState) - : base(printer, runningState) + public LevelWizard3x3Mesh(PrinterConfig printer) + : base(printer) { } diff --git a/ConfigurationPage/PrintLeveling/LevelWizard5x5Mesh.cs b/ConfigurationPage/PrintLeveling/LevelWizard5x5Mesh.cs index 7cc81a9b1..b675208f9 100644 --- a/ConfigurationPage/PrintLeveling/LevelWizard5x5Mesh.cs +++ b/ConfigurationPage/PrintLeveling/LevelWizard5x5Mesh.cs @@ -37,8 +37,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling { public class LevelWizard5x5Mesh : LevelWizardBase { - public LevelWizard5x5Mesh(PrinterConfig printer, LevelWizardBase.RunningState runningState) - : base(printer, runningState) + public LevelWizard5x5Mesh(PrinterConfig printer) + : base(printer) { } diff --git a/ConfigurationPage/PrintLeveling/LevelWizard7PointRadial.cs b/ConfigurationPage/PrintLeveling/LevelWizard7PointRadial.cs index a8187453e..6491f6c03 100644 --- a/ConfigurationPage/PrintLeveling/LevelWizard7PointRadial.cs +++ b/ConfigurationPage/PrintLeveling/LevelWizard7PointRadial.cs @@ -36,8 +36,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling { public class LevelWizard7PointRadial : LevelWizardBase { - public LevelWizard7PointRadial(PrinterConfig printer, LevelWizardBase.RunningState runningState) - : base(printer, runningState) + public LevelWizard7PointRadial(PrinterConfig printer) + : base(printer) { } diff --git a/ConfigurationPage/PrintLeveling/LevelWizardBase.cs b/ConfigurationPage/PrintLeveling/LevelWizardBase.cs index d0943cdb8..94528e69d 100644 --- a/ConfigurationPage/PrintLeveling/LevelWizardBase.cs +++ b/ConfigurationPage/PrintLeveling/LevelWizardBase.cs @@ -45,7 +45,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling private static SystemWindow printLevelWizardWindow; private LevelingStrings levelingStrings; - public LevelWizardBase(PrinterConfig printer, RunningState runningState) + public LevelWizardBase(PrinterConfig printer) : base(500, 370) { levelingStrings = new LevelingStrings(printer.Settings); @@ -65,10 +65,14 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling printLevelWizard = new WizardControl(); AddChild(printLevelWizard); - if (runningState == LevelWizardBase.RunningState.InitialStartupCalibration) + // If no leveling data has been calculated + bool showWelcomeScreen = printer.Settings.Helpers.GetPrintLevelingData().SampledPositions.Count == 0 + && !ProbeCalibrationWizard.UsingZProbe(printer); + + if (showWelcomeScreen) { - string part1 = "Congratulations on connecting to your new printer. Before starting your first print we need to run a simple calibration procedure.".Localize(); - string part2 = "The next few screens will walk your through the print leveling wizard.".Localize(); + string part1 = "Congratulations on connecting to your printer. Before starting your first print we need to run a simple calibration procedure.".Localize(); + string part2 = "The next few screens will walk your through calibrating your printer.".Localize(); string requiredPageInstructions = $"{part1}\n\n{part2}"; printLevelWizard.AddPage(new FirstPageInstructions(printer, levelingStrings.initialPrinterSetupStepText, requiredPageInstructions)); } @@ -138,32 +142,17 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling printLevelWizard.AddPage(new LastPagelInstructions(printer, printLevelWizard, "Done".Localize(), levelingStrings.DoneInstructions, probePositions)); } - public enum RunningState { InitialStartupCalibration, UserRequestedCalibration } - public abstract int ProbeCount { get; } public int TotalSteps => ProbeCount * 3; public static void ShowPrintLevelWizard(PrinterConfig printer) - { - LevelWizardBase.RunningState runningState = LevelWizardBase.RunningState.UserRequestedCalibration; - - if (printer.Settings.GetValue(SettingsKey.print_leveling_required_to_print)) - { - // run in the first run state - runningState = LevelWizardBase.RunningState.InitialStartupCalibration; - } - - ShowPrintLevelWizard(printer, runningState); - } - - public static void ShowPrintLevelWizard(PrinterConfig printer, LevelWizardBase.RunningState runningState) { if (printLevelWizardWindow == null) { // turn off print leveling PrintLevelingStream.AllowLeveling = false; - printLevelWizardWindow = LevelWizardBase.CreateAndShowWizard(printer, runningState); + printLevelWizardWindow = LevelWizardBase.CreateAndShowWizard(printer); printLevelWizardWindow.Closed += (sender, e) => { @@ -191,7 +180,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling public abstract IEnumerable GetPrintLevelPositionToSample(); - private static LevelWizardBase CreateAndShowWizard(PrinterConfig printer, LevelWizardBase.RunningState runningState) + private static LevelWizardBase CreateAndShowWizard(PrinterConfig printer) { // clear any data that we are going to be acquiring (sampled positions, after z home offset) PrintLevelingData levelingData = new PrintLevelingData() @@ -205,23 +194,23 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling switch (levelingData.LevelingSystem) { case LevelingSystem.Probe3Points: - printLevelWizardWindow = new LevelWizard3Point(printer, runningState); + printLevelWizardWindow = new LevelWizard3Point(printer); break; case LevelingSystem.Probe7PointRadial: - printLevelWizardWindow = new LevelWizard7PointRadial(printer, runningState); + printLevelWizardWindow = new LevelWizard7PointRadial(printer); break; case LevelingSystem.Probe13PointRadial: - printLevelWizardWindow = new LevelWizard13PointRadial(printer, runningState); + printLevelWizardWindow = new LevelWizard13PointRadial(printer); break; case LevelingSystem.Probe3x3Mesh: - printLevelWizardWindow = new LevelWizard3x3Mesh(printer, runningState); + printLevelWizardWindow = new LevelWizard3x3Mesh(printer); break; case LevelingSystem.Probe5x5Mesh: - printLevelWizardWindow = new LevelWizard5x5Mesh(printer, runningState); + printLevelWizardWindow = new LevelWizard5x5Mesh(printer); break; default: diff --git a/ConfigurationPage/PrintLeveling/PrintLevelPages.cs b/ConfigurationPage/PrintLeveling/PrintLevelPages.cs index 8ec8210ba..9de8e8db7 100644 --- a/ConfigurationPage/PrintLeveling/PrintLevelPages.cs +++ b/ConfigurationPage/PrintLeveling/PrintLevelPages.cs @@ -264,6 +264,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling // make sure we don't have leveling data double newProbeOffset = autoProbePositions[0].position.Z - manualProbePositions[0].position.Z; printer.Settings.SetValue(SettingsKey.z_probe_z_offset, newProbeOffset.ToString("0.###")); + printer.Settings.SetValue(SettingsKey.probe_has_been_calibrated, "1"); if (printer.Settings.GetValue(SettingsKey.z_homes_to_max)) { @@ -272,6 +273,12 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling container.backButton.Enabled = false; + Closed += (s, e) => + { + // move from this wizard to the print leveling wizard if needed + ApplicationController.Instance.RunAnyRequiredCalibration(printer); + }; + base.PageIsBecomingActive(); } } diff --git a/ConfigurationPage/PrintLeveling/ProbeCalibrationWizard.cs b/ConfigurationPage/PrintLeveling/ProbeCalibrationWizard.cs index f64e14cd1..d90a790d3 100644 --- a/ConfigurationPage/PrintLeveling/ProbeCalibrationWizard.cs +++ b/ConfigurationPage/PrintLeveling/ProbeCalibrationWizard.cs @@ -67,6 +67,14 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling printLevelWizard = new WizardControl(); AddChild(printLevelWizard); + if (printer.Settings.GetValue(SettingsKey.probe_has_been_calibrated)) + { + string part1 = "Congratulations on connecting to your printer. Before starting your first print we need to run a simple calibration procedure.".Localize(); + string part2 = "The next few screens will walk your through calibrating your printer.".Localize(); + string requiredPageInstructions = $"{part1}\n\n{part2}"; + printLevelWizard.AddPage(new FirstPageInstructions(printer, levelingStrings.initialPrinterSetupStepText, requiredPageInstructions)); + } + var CalibrateProbeWelcomText = "{0}\n\n\t• {1}\n\t• {2}\n\t• {3}\n\n{4}\n\n{5}".FormatWith( "Welcome to the probe calibration wizard. Here is a quick overview on what we are going to do.".Localize(), "Home the printer".Localize(), @@ -116,6 +124,19 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling private static SystemWindow probeCalibrationWizardWindow; + public static bool UsingZProbe(PrinterConfig printer) + { + // we have a probe that we are using and we have not done leveling yet + return printer.Settings.GetValue(SettingsKey.has_z_probe) + && printer.Settings.GetValue(SettingsKey.use_z_probe); + } + + public static bool NeedsToBeRun(PrinterConfig printer) + { + // we have a probe that we are using and we have not done leveling yet + return UsingZProbe(printer) && !printer.Settings.GetValue(SettingsKey.probe_has_been_calibrated); + } + public static void ShowProbeCalibrationWizard(PrinterConfig printer) { if (probeCalibrationWizardWindow == null) diff --git a/SlicerConfiguration/Settings/SettingsHelpers.cs b/SlicerConfiguration/Settings/SettingsHelpers.cs index 3d0f36386..ae24163ea 100644 --- a/SlicerConfiguration/Settings/SettingsHelpers.cs +++ b/SlicerConfiguration/Settings/SettingsHelpers.cs @@ -120,6 +120,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration public const string print_leveling_data = nameof(print_leveling_data); public const string print_leveling_enabled = nameof(print_leveling_enabled); public const string print_leveling_probe_start = nameof(print_leveling_probe_start); + public const string probe_has_been_calibrated = nameof(probe_has_been_calibrated); public const string print_leveling_required_to_print = nameof(print_leveling_required_to_print); public const string print_leveling_solution = nameof(print_leveling_solution); public const string printer_name = nameof(printer_name); diff --git a/SlicerConfiguration/SlicerMapping/SliceEngineMapping.cs b/SlicerConfiguration/SlicerMapping/SliceEngineMapping.cs index 1ac894361..95e37af8b 100644 --- a/SlicerConfiguration/SlicerMapping/SliceEngineMapping.cs +++ b/SlicerConfiguration/SlicerMapping/SliceEngineMapping.cs @@ -73,6 +73,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration SettingsKey.z_servo_retracted_angle, SettingsKey.pause_gcode, SettingsKey.print_leveling_probe_start, + SettingsKey.probe_has_been_calibrated, SettingsKey.print_leveling_required_to_print, SettingsKey.print_leveling_solution, SettingsKey.recover_first_layer_speed, diff --git a/StaticData/SliceSettings/Properties.json b/StaticData/SliceSettings/Properties.json index bdbc4efdc..da61fc6a6 100644 --- a/StaticData/SliceSettings/Properties.json +++ b/StaticData/SliceSettings/Properties.json @@ -799,6 +799,15 @@ "DefaultValue": "0", "RebuildGCodeOnChange": false }, + { + "SlicerConfigName": "probe_has_been_calibrated", + "PresentationName": "Probe Has Been Calibrated", + "HelpText": "Flag keeping track if probe calibration wizard has been run.", + "DataEditType": "CHECK_BOX", + "ShowIfSet": "!has_hardware_leveling", + "DefaultValue": "0", + "RebuildGCodeOnChange": false + }, { "SlicerConfigName": "print_leveling_probe_start", "PresentationName": "Start Height", diff --git a/Tests/MatterControl.Tests/MatterControl/SettingsParseTests.cs b/Tests/MatterControl.Tests/MatterControl/SettingsParseTests.cs index 679406b85..327074b76 100644 --- a/Tests/MatterControl.Tests/MatterControl/SettingsParseTests.cs +++ b/Tests/MatterControl.Tests/MatterControl/SettingsParseTests.cs @@ -20,7 +20,7 @@ namespace MatterControl.Tests.MatterControl { AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData")); MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4)); - LevelWizard3Point levelingSolution = new LevelWizard3Point(ActiveSliceSettings.Instance.printer, LevelWizardBase.RunningState.InitialStartupCalibration); + LevelWizard3Point levelingSolution = new LevelWizard3Point(ActiveSliceSettings.Instance.printer); var printerSettings = ActiveSliceSettings.Instance; {