From a71c19e0c9e96910831bf9dc03c005bea993d141 Mon Sep 17 00:00:00 2001 From: jlewin Date: Tue, 26 Mar 2019 11:48:29 -0700 Subject: [PATCH] Consolidate XYCalibrationData into XYCalibrationWizard - Type acts as state for wizard, simplify by unifying into one --- .../SetupWizards/XyCalibrationData.cs | 53 ------------------- .../SetupWizards/XyCalibrationWizard.cs | 37 ++++++++----- .../XyCalibrationCollectDataPage.cs | 30 +++++------ .../XyCalibrationDataRecieved.cs | 35 ++++++------ .../CustomWidgets/XyCalibrationSelectPage.cs | 26 ++++----- .../XyCalibrationStartPrintPage.cs | 38 ++++++------- 6 files changed, 85 insertions(+), 134 deletions(-) delete mode 100644 MatterControlLib/ConfigurationPage/PrintLeveling/SetupWizards/XyCalibrationData.cs diff --git a/MatterControlLib/ConfigurationPage/PrintLeveling/SetupWizards/XyCalibrationData.cs b/MatterControlLib/ConfigurationPage/PrintLeveling/SetupWizards/XyCalibrationData.cs deleted file mode 100644 index 591b45ab8..000000000 --- a/MatterControlLib/ConfigurationPage/PrintLeveling/SetupWizards/XyCalibrationData.cs +++ /dev/null @@ -1,53 +0,0 @@ -/* -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. -*/ - -namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling -{ - public class XyCalibrationData - { - public enum QualityType { Coarse, Normal, Fine } - - public XyCalibrationData(int extruderToCalibrateIndex) - { - this.ExtruderToCalibrateIndex = extruderToCalibrateIndex; - } - - public int ExtruderToCalibrateIndex { get; } - - public QualityType Quality { get; set; } = QualityType.Normal; - - /// - /// The index of the calibration print that was picked - /// - public int XPick { get; set; } = -1; - public int YPick { get; set; } = -1; - public double Offset { get; set; } = .1; - public bool PrintAgain { get; set; } - } -} \ No newline at end of file diff --git a/MatterControlLib/ConfigurationPage/PrintLeveling/SetupWizards/XyCalibrationWizard.cs b/MatterControlLib/ConfigurationPage/PrintLeveling/SetupWizards/XyCalibrationWizard.cs index 138447f3b..a99d9e891 100644 --- a/MatterControlLib/ConfigurationPage/PrintLeveling/SetupWizards/XyCalibrationWizard.cs +++ b/MatterControlLib/ConfigurationPage/PrintLeveling/SetupWizards/XyCalibrationWizard.cs @@ -37,16 +37,29 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling { public class XyCalibrationWizard : PrinterSetupWizard { - private int extruderToCalibrateIndex; - public XyCalibrationWizard(PrinterConfig printer, int extruderToCalibrateIndex) : base(printer) { - this.extruderToCalibrateIndex = extruderToCalibrateIndex; + this.ExtruderToCalibrateIndex = extruderToCalibrateIndex; + this.Title = "Nozzle Calibration".Localize(); this.WindowSize = new Vector2(600 * GuiWidget.DeviceScale, 700 * GuiWidget.DeviceScale); } + public enum QualityType { Coarse, Normal, Fine } + + public int ExtruderToCalibrateIndex { get; } + + public QualityType Quality { get; set; } = QualityType.Normal; + + /// + /// The index of the calibration print that was picked + /// + 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); public override bool Visible => printer.Settings.GetValue(SettingsKey.extruder_count) > 1; @@ -71,19 +84,17 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling protected override IEnumerator GetPages() { - var wizardState = new XyCalibrationData(extruderToCalibrateIndex); - - yield return new XyCalibrationSelectPage(this, printer, wizardState); - yield return new XyCalibrationStartPrintPage(this, printer, wizardState); - yield return new XyCalibrationCollectDataPage(this, printer, wizardState); - yield return new XyCalibrationDataRecieved(this, printer, wizardState); + yield return new XyCalibrationSelectPage(this, printer); + yield return new XyCalibrationStartPrintPage(this, printer); + yield return new XyCalibrationCollectDataPage(this, printer); + yield return new XyCalibrationDataRecieved(this, printer); // loop until we are done calibrating - while (wizardState.PrintAgain) + while (this.PrintAgain) { - yield return new XyCalibrationStartPrintPage(this, printer, wizardState); - yield return new XyCalibrationCollectDataPage(this, printer, wizardState); - yield return new XyCalibrationDataRecieved(this, printer, wizardState); + yield return new XyCalibrationStartPrintPage(this, printer); + yield return new XyCalibrationCollectDataPage(this, printer); + yield return new XyCalibrationDataRecieved(this, printer); } } } diff --git a/MatterControlLib/CustomWidgets/XyCalibrationCollectDataPage.cs b/MatterControlLib/CustomWidgets/XyCalibrationCollectDataPage.cs index 3ab460d65..2d4aa05c5 100644 --- a/MatterControlLib/CustomWidgets/XyCalibrationCollectDataPage.cs +++ b/MatterControlLib/CustomWidgets/XyCalibrationCollectDataPage.cs @@ -38,15 +38,15 @@ namespace MatterHackers.MatterControl public class XyCalibrationCollectDataPage : WizardPage { private List xButtons; - private XyCalibrationData xyCalibrationData; private List yButtons; private bool HaveWrittenData = false; private bool pageCanceled; + private XyCalibrationWizard calibrationWizard; - public XyCalibrationCollectDataPage(ISetupWizard setupWizard, PrinterConfig printer, XyCalibrationData xyCalibrationData) - : base(setupWizard) + public XyCalibrationCollectDataPage(XyCalibrationWizard calibrationWizard, PrinterConfig printer) + : base(calibrationWizard) { - this.xyCalibrationData = xyCalibrationData; + this.calibrationWizard = calibrationWizard; this.WindowTitle = "Nozzle Offset Calibration Wizard".Localize(); this.HeaderText = "Nozzle Offset Calibration".Localize() + ":"; this.Name = "Nozzle Offset Calibration Wizard"; @@ -58,7 +58,7 @@ namespace MatterHackers.MatterControl Margin = new Agg.BorderDouble(0, 15, 0, 0) }); - // disable the next button until we recieve data about both the x and y axis alignment + // disable the next button until we receive data about both the x and y axis alignment NextButton.Enabled = false; var xButtonsGroup = new FlowLayoutWidget(FlowDirection.TopToBottom) @@ -122,14 +122,14 @@ namespace MatterHackers.MatterControl // save the offsets to the extruder if (!pageCanceled && !HaveWrittenData - && xyCalibrationData.XPick != -1 - && xyCalibrationData.YPick != -1) + && calibrationWizard.XPick != -1 + && calibrationWizard.YPick != -1) { - var hotendOffset = printer.Settings.Helpers.ExtruderOffset(xyCalibrationData.ExtruderToCalibrateIndex); - hotendOffset.X -= xyCalibrationData.Offset * -3 + xyCalibrationData.Offset * xyCalibrationData.XPick; - hotendOffset.Y -= xyCalibrationData.Offset * -3 + xyCalibrationData.Offset * xyCalibrationData.YPick; + var hotendOffset = printer.Settings.Helpers.ExtruderOffset(calibrationWizard.ExtruderToCalibrateIndex); + hotendOffset.X -= calibrationWizard.Offset * -3 + calibrationWizard.Offset * calibrationWizard.XPick; + hotendOffset.Y -= calibrationWizard.Offset * -3 + calibrationWizard.Offset * calibrationWizard.YPick; - printer.Settings.Helpers.SetExtruderOffset(xyCalibrationData.ExtruderToCalibrateIndex, hotendOffset); + printer.Settings.Helpers.SetExtruderOffset(calibrationWizard.ExtruderToCalibrateIndex, hotendOffset); HaveWrittenData = true; } @@ -138,8 +138,8 @@ namespace MatterHackers.MatterControl private void CheckIfCanAdvance() { - if (xyCalibrationData.YPick != -1 - && xyCalibrationData.XPick != -1) + if (calibrationWizard.YPick != -1 + && calibrationWizard.XPick != -1) { NextButton.Enabled = true; } @@ -152,7 +152,7 @@ namespace MatterHackers.MatterControl { if (button == sender) { - xyCalibrationData.XPick = i; + calibrationWizard.XPick = i; break; } i++; @@ -167,7 +167,7 @@ namespace MatterHackers.MatterControl { if (button == sender) { - xyCalibrationData.YPick = i; + calibrationWizard.YPick = i; break; } i++; diff --git a/MatterControlLib/CustomWidgets/XyCalibrationDataRecieved.cs b/MatterControlLib/CustomWidgets/XyCalibrationDataRecieved.cs index 6b95606b5..35d3a196b 100644 --- a/MatterControlLib/CustomWidgets/XyCalibrationDataRecieved.cs +++ b/MatterControlLib/CustomWidgets/XyCalibrationDataRecieved.cs @@ -31,13 +31,14 @@ using MatterHackers.Agg.UI; using MatterHackers.Localizations; using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling; using MatterHackers.MatterControl.SlicerConfiguration; +using static MatterHackers.MatterControl.ConfigurationPage.PrintLeveling.XyCalibrationWizard; namespace MatterHackers.MatterControl { public class XyCalibrationDataRecieved : WizardPage { - public XyCalibrationDataRecieved(ISetupWizard setupWizard, PrinterConfig printer, XyCalibrationData xyCalibrationData) - : base(setupWizard) + public XyCalibrationDataRecieved(XyCalibrationWizard calibrationWizard, PrinterConfig printer) + : base(calibrationWizard) { this.WindowTitle = "Nozzle Offset Calibration Wizard".Localize(); this.HeaderText = "Nozzle Offset Calibration".Localize() + ":"; @@ -45,13 +46,13 @@ namespace MatterHackers.MatterControl contentRow.Padding = theme.DefaultContainerPadding; - xyCalibrationData.PrintAgain = false; + calibrationWizard.PrintAgain = false; // check if we picked an outside of the calibration - if (xyCalibrationData.XPick == 0 - || xyCalibrationData.XPick == 6 - || xyCalibrationData.YPick == 0 - || xyCalibrationData.YPick == 6) + if (calibrationWizard.XPick == 0 + || calibrationWizard.XPick == 6 + || calibrationWizard.YPick == 0 + || calibrationWizard.YPick == 6) { // offer to re-run the calibration with the same settings as last time contentRow.AddChild(new TextWidget("Your printer has been adjusted but we need to run calibrating again to improve accuracy.".Localize(), textColor: theme.TextColor, pointSize: theme.DefaultFontSize) @@ -59,13 +60,13 @@ namespace MatterHackers.MatterControl Margin = new Agg.BorderDouble(0, 15, 0, 0) }); - xyCalibrationData.PrintAgain = true; + calibrationWizard.PrintAgain = true; } else { - switch (xyCalibrationData.Quality) + switch (calibrationWizard.Quality) { - case XyCalibrationData.QualityType.Coarse: + case QualityType.Coarse: // if we are on coarse calibration offer to move down to normal contentRow.AddChild(new TextWidget("Coarse calibration complete, we will now do a normal calibration to improve accuracy.".Localize(), textColor: theme.TextColor, pointSize: theme.DefaultFontSize) { @@ -73,11 +74,11 @@ namespace MatterHackers.MatterControl }); // switch to normal calibration - xyCalibrationData.Quality = XyCalibrationData.QualityType.Normal; - xyCalibrationData.PrintAgain = true; + calibrationWizard.Quality = QualityType.Normal; + calibrationWizard.PrintAgain = true; break; - case XyCalibrationData.QualityType.Normal: + case QualityType.Normal: // let the user know they are done with calibration, but if they would like they can print a fine calibration for even better results // add a button to request fine calibration var normalMessage = "Your nozzles should now be calibrated.".Localize(); @@ -93,15 +94,15 @@ namespace MatterHackers.MatterControl startFineCalibratingButton.Click += (s, e) => { // switch to fine - xyCalibrationData.Quality = XyCalibrationData.QualityType.Fine; + calibrationWizard.Quality = QualityType.Fine; // start up at the print window - xyCalibrationData.PrintAgain = true; + calibrationWizard.PrintAgain = true; this.NextButton.InvokeClick(); }; contentRow.AddChild(startFineCalibratingButton); break; - case XyCalibrationData.QualityType.Fine: + case QualityType.Fine: // done! contentRow.AddChild(new TextWidget("Offset Calibration complete.".Localize(), textColor: theme.TextColor, pointSize: theme.DefaultFontSize) { @@ -111,7 +112,7 @@ namespace MatterHackers.MatterControl } } - if (!xyCalibrationData.PrintAgain) + if (!calibrationWizard.PrintAgain) { // this is the last page of the wizard hide the next button this.NextButton.Visible = false; diff --git a/MatterControlLib/CustomWidgets/XyCalibrationSelectPage.cs b/MatterControlLib/CustomWidgets/XyCalibrationSelectPage.cs index 8425c21d0..11be4ed24 100644 --- a/MatterControlLib/CustomWidgets/XyCalibrationSelectPage.cs +++ b/MatterControlLib/CustomWidgets/XyCalibrationSelectPage.cs @@ -27,11 +27,11 @@ of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. */ -using System.Collections.Generic; using MatterHackers.Agg.UI; using MatterHackers.Localizations; using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling; using MatterHackers.MatterControl.SlicerConfiguration; +using static MatterHackers.MatterControl.ConfigurationPage.PrintLeveling.XyCalibrationWizard; namespace MatterHackers.MatterControl { @@ -41,8 +41,8 @@ namespace MatterHackers.MatterControl private RadioButton normalCalibration; private RadioButton fineCalibration; - public XyCalibrationSelectPage(ISetupWizard setupWizard, PrinterConfig printer, XyCalibrationData xyCalibrationData) - : base(setupWizard) + public XyCalibrationSelectPage(XyCalibrationWizard calibrationWizard, PrinterConfig printer) + : base(calibrationWizard) { this.WindowTitle = "Nozzle Offset Calibration Wizard".Localize(); this.HeaderText = "Nozzle Offset Calibration".Localize() + ":"; @@ -50,7 +50,7 @@ namespace MatterHackers.MatterControl contentRow.Padding = theme.DefaultContainerPadding; // default to normal offset - xyCalibrationData.Offset = printer.Settings.GetValue(SettingsKey.nozzle_diameter) / 3.0; + calibrationWizard.Offset = printer.Settings.GetValue(SettingsKey.nozzle_diameter) / 3.0; contentRow.AddChild(new TextWidget("Choose the calibration you would like to perform.".Localize(), textColor: theme.TextColor, pointSize: theme.DefaultFontSize) { @@ -59,30 +59,30 @@ namespace MatterHackers.MatterControl contentRow.AddChild(coarseCalibration = new RadioButton("Coarse Calibration: If your printer is way off".Localize(), textColor: theme.TextColor, fontSize: theme.DefaultFontSize) { - Checked = xyCalibrationData.Quality == XyCalibrationData.QualityType.Coarse + Checked = calibrationWizard.Quality == QualityType.Coarse }); coarseCalibration.CheckedStateChanged += (s, e) => { - xyCalibrationData.Quality = XyCalibrationData.QualityType.Coarse; - xyCalibrationData.Offset = printer.Settings.GetValue(SettingsKey.nozzle_diameter); + calibrationWizard.Quality = QualityType.Coarse; + calibrationWizard.Offset = printer.Settings.GetValue(SettingsKey.nozzle_diameter); }; contentRow.AddChild(normalCalibration = new RadioButton("Normal Calibration: Start here".Localize(), textColor: theme.TextColor, fontSize: theme.DefaultFontSize) { - Checked = xyCalibrationData.Quality == XyCalibrationData.QualityType.Normal + Checked = calibrationWizard.Quality == QualityType.Normal }); normalCalibration.CheckedStateChanged += (s, e) => { - xyCalibrationData.Quality = XyCalibrationData.QualityType.Normal; - xyCalibrationData.Offset = printer.Settings.GetValue(SettingsKey.nozzle_diameter) / 3.0; + calibrationWizard.Quality = QualityType.Normal; + calibrationWizard.Offset = printer.Settings.GetValue(SettingsKey.nozzle_diameter) / 3.0; }; contentRow.AddChild(fineCalibration = new RadioButton("Fine Calibration: When you want that extra precision".Localize(), textColor: theme.TextColor, fontSize: theme.DefaultFontSize) { - Checked = xyCalibrationData.Quality == XyCalibrationData.QualityType.Fine + Checked = calibrationWizard.Quality == QualityType.Fine }); fineCalibration.CheckedStateChanged += (s, e) => { - xyCalibrationData.Quality = XyCalibrationData.QualityType.Fine; - xyCalibrationData.Offset = printer.Settings.GetValue(SettingsKey.nozzle_diameter) / 9.0; + calibrationWizard.Quality = QualityType.Fine; + calibrationWizard.Offset = printer.Settings.GetValue(SettingsKey.nozzle_diameter) / 9.0; }; } } diff --git a/MatterControlLib/CustomWidgets/XyCalibrationStartPrintPage.cs b/MatterControlLib/CustomWidgets/XyCalibrationStartPrintPage.cs index 40a1d5cc3..d49c01861 100644 --- a/MatterControlLib/CustomWidgets/XyCalibrationStartPrintPage.cs +++ b/MatterControlLib/CustomWidgets/XyCalibrationStartPrintPage.cs @@ -37,17 +37,15 @@ using MatterHackers.MatterControl.Library; using MatterHackers.MatterControl.PrinterCommunication; using MatterHackers.MatterControl.SlicerConfiguration; using MatterHackers.VectorMath; +using static MatterHackers.MatterControl.ConfigurationPage.PrintLeveling.XyCalibrationWizard; namespace MatterHackers.MatterControl { public class XyCalibrationStartPrintPage : WizardPage { - private XyCalibrationData xyCalibrationData; - - public XyCalibrationStartPrintPage(ISetupWizard setupWizard, PrinterConfig printer, XyCalibrationData xyCalibrationData) - : base(setupWizard) + public XyCalibrationStartPrintPage(XyCalibrationWizard calibrationWizard, PrinterConfig printer) + : base(calibrationWizard) { - this.xyCalibrationData = xyCalibrationData; this.WindowTitle = "Nozzle Offset Calibration Wizard".Localize(); this.HeaderText = "Nozzle Offset Calibration".Localize(); this.Name = "Nozzle Offset Calibration Wizard"; @@ -71,7 +69,7 @@ namespace MatterHackers.MatterControl var scene = new Object3D(); // create the calibration objects - IObject3D item = CreateCalibrationObject(printer, xyCalibrationData); + IObject3D item = CreateCalibrationObject(printer, calibrationWizard); // add the calibration object to the bed scene.Children.Add(item); @@ -162,33 +160,27 @@ namespace MatterHackers.MatterControl RestoreBedAndClearPrinterCallbacks(); } - private static IObject3D CreateCalibrationObject(PrinterConfig printer, XyCalibrationData xyCalibrationData) + private static IObject3D CreateCalibrationObject(PrinterConfig printer, XyCalibrationWizard calibrationWizard) { - IObject3D item; var layerHeight = printer.Settings.GetValue(SettingsKey.layer_height); - switch (xyCalibrationData.Quality) - { - case XyCalibrationData.QualityType.Coarse: - item = XyCalibrationTabObject3D.Create(1, - Math.Max(printer.Settings.GetValue(SettingsKey.first_layer_height) * 2, layerHeight * 2), - xyCalibrationData.Offset, - printer.Settings.GetValue(SettingsKey.nozzle_diameter)).GetAwaiter().GetResult(); - break; - case XyCalibrationData.QualityType.Normal: - case XyCalibrationData.QualityType.Fine: + switch (calibrationWizard.Quality) + { + case QualityType.Coarse: + return XyCalibrationTabObject3D.Create(1, + Math.Max(printer.Settings.GetValue(SettingsKey.first_layer_height) * 2, layerHeight * 2), + calibrationWizard.Offset, + printer.Settings.GetValue(SettingsKey.nozzle_diameter)).GetAwaiter().GetResult(); + default: - item = XyCalibrationFaceObject3D.Create(1, + return XyCalibrationFaceObject3D.Create(1, printer.Settings.GetValue(SettingsKey.first_layer_height) + layerHeight, layerHeight, - xyCalibrationData.Offset, + calibrationWizard.Offset, printer.Settings.GetValue(SettingsKey.nozzle_diameter), printer.Settings.GetValue(SettingsKey.wipe_tower_size), 6).GetAwaiter().GetResult(); - break; } - - return item; } } }