Starting work on an automatic z offset validator
This commit is contained in:
parent
c628d06e90
commit
fe31aaca05
14 changed files with 514 additions and 172 deletions
|
|
@ -307,7 +307,29 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
|
|||
babySteppingValue[i] = 0;
|
||||
}
|
||||
|
||||
yield return new CalibrateProbeLastPageInstructions(this, this.Title + " " + "Wizard".Localize());
|
||||
var pageTitle = this.Title + " " + "Wizard".Localize();
|
||||
|
||||
if (hotendCount == 1 // this could be improved for dual extrusion calibration in the future. But for now it is single extrusion.
|
||||
&& probeBeingUsed
|
||||
&& printer.Settings.GetValue<bool>(SettingsKey.validate_probe_offset))
|
||||
{
|
||||
// let the user know we are done with the manual part
|
||||
yield return new CalibrateProbeRemovePaperInstructions(this, pageTitle, false);
|
||||
// tell them about the automatic part and any settings that should be changed
|
||||
yield return new ZProbePrintCalibrationPartPage(
|
||||
this,
|
||||
printer,
|
||||
"Validating Z Offset".Localize(),
|
||||
"We will now improve accuracy by measure the probe offset from the top of a printed calibration object.".Localize());
|
||||
// measure the top of the part we just printed
|
||||
yield return new ZProbeCalibrateRetrieveTopProbeData(this, pageTitle);
|
||||
// tell the user we are done and everything should be working
|
||||
yield return new ZCalibrationValidateComplete(this, pageTitle);
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return new CalibrateProbeRemovePaperInstructions(this, pageTitle);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetExtruderOffset(List<PrintLevelingWizard.ProbePosition> autoProbePositions, List<List<PrintLevelingWizard.ProbePosition>> manualProbePositions, bool probeBeingUsed, int extruderIndex)
|
||||
|
|
|
|||
|
|
@ -34,20 +34,23 @@ using MatterHackers.MatterControl.SlicerConfiguration;
|
|||
|
||||
namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
|
||||
{
|
||||
public class CalibrateProbeLastPageInstructions : WizardPage
|
||||
public class CalibrateProbeRemovePaperInstructions : WizardPage
|
||||
{
|
||||
public CalibrateProbeLastPageInstructions(ISetupWizard setupWizard, string headerText)
|
||||
public CalibrateProbeRemovePaperInstructions(ISetupWizard setupWizard, string headerText, bool lastPage = true)
|
||||
: base(setupWizard, headerText, "")
|
||||
{
|
||||
contentRow.AddChild(
|
||||
this.CreateTextField(
|
||||
"Z Calibration complete.".Localize() +
|
||||
"Manual Z Calibration complete.".Localize() +
|
||||
"\n • " +
|
||||
"Remove the paper".Localize()));
|
||||
|
||||
contentRow.BackgroundColor = theme.MinimalShade;
|
||||
|
||||
this.ShowWizardFinished();
|
||||
if (lastPage)
|
||||
{
|
||||
this.ShowWizardFinished();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnLoad(EventArgs args)
|
||||
|
|
@ -32,6 +32,8 @@ using MatterHackers.Agg;
|
|||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.CustomWidgets;
|
||||
using MatterHackers.MatterControl.PartPreviewWindow;
|
||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||
|
||||
namespace MatterHackers.MatterControl
|
||||
{
|
||||
|
|
@ -77,6 +79,39 @@ namespace MatterHackers.MatterControl
|
|||
this.NextButton = nextButton;
|
||||
}
|
||||
|
||||
public static void AddSettingsRow(GuiWidget contentRow, PrinterConfig printer, string warning, string key, ThemeConfig theme, ref int tabIndex)
|
||||
{
|
||||
var settingsContext = new SettingsContext(printer, null, NamedSettingsLayers.All);
|
||||
|
||||
contentRow.AddChild(
|
||||
new TextWidget(
|
||||
"Recommended Settings Changes".Localize() + ":",
|
||||
textColor: theme.TextColor,
|
||||
pointSize: theme.DefaultFontSize)
|
||||
{
|
||||
Margin = new BorderDouble(10, 0, 0, 20)
|
||||
});
|
||||
|
||||
contentRow.AddChild(
|
||||
new WrappedTextWidget(
|
||||
warning,
|
||||
textColor: theme.TextColor,
|
||||
pointSize: theme.DefaultFontSize)
|
||||
{
|
||||
Margin = new BorderDouble(0, 10, 0, 20)
|
||||
});
|
||||
|
||||
var settingsData = PrinterSettings.SettingsData[key];
|
||||
var row = SliceSettingsTabView.CreateItemRow(settingsData, settingsContext, printer, theme, ref tabIndex);
|
||||
|
||||
if (row is SliceSettingsRow settingsRow)
|
||||
{
|
||||
settingsRow.ArrowDirection = ArrowDirection.Left;
|
||||
}
|
||||
|
||||
contentRow.AddChild(row);
|
||||
}
|
||||
|
||||
protected void MoveToNextPage()
|
||||
{
|
||||
OnAdvance();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
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 MatterHackers.Localizations;
|
||||
|
||||
namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
|
||||
{
|
||||
public class ZCalibrationValidateComplete : WizardPage
|
||||
{
|
||||
public ZCalibrationValidateComplete(ISetupWizard setupWizard, string headerText, bool lastPage = true)
|
||||
: base(setupWizard, headerText, "")
|
||||
{
|
||||
contentRow.AddChild(
|
||||
this.CreateTextField(
|
||||
"Precise probe calibration complete.".Localize() +
|
||||
"\n • " +
|
||||
"Your probe is now finely calibrated and should produce excellent first layer results".Localize()));
|
||||
|
||||
contentRow.BackgroundColor = theme.MinimalShade;
|
||||
|
||||
if (lastPage)
|
||||
{
|
||||
this.ShowWizardFinished();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
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 MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.PrinterCommunication;
|
||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||
|
||||
namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
|
||||
{
|
||||
public class ZProbeCalibrateRetrieveTopProbeData : WizardPage
|
||||
{
|
||||
public ZProbeCalibrateRetrieveTopProbeData(ISetupWizard setupWizard, string headerText)
|
||||
: base(setupWizard, headerText, "")
|
||||
{
|
||||
contentRow.AddChild(this.CreateTextField("We will now sample the top of the part.".Localize()));
|
||||
|
||||
contentRow.BackgroundColor = theme.MinimalShade;
|
||||
}
|
||||
|
||||
public override void OnLoad(EventArgs args)
|
||||
{
|
||||
this.NextButton.Enabled = false;
|
||||
|
||||
printer.Connection.QueueLine("T0");
|
||||
printer.Connection.MoveRelative(PrinterConnection.Axis.X, .1, printer.Settings.Helpers.ManualMovementSpeeds().X);
|
||||
|
||||
if (printer.Settings.GetValue<bool>(SettingsKey.z_homes_to_max))
|
||||
{
|
||||
printer.Connection.HomeAxis(PrinterConnection.Axis.XYZ);
|
||||
}
|
||||
else if (!printer.Settings.GetValue<bool>(SettingsKey.has_z_probe))
|
||||
{
|
||||
// Lift the hotend off the bed - at the conclusion of the wizard, make sure we lift the heated nozzle off the bed
|
||||
printer.Connection.MoveRelative(PrinterConnection.Axis.Z, 2, printer.Settings.Helpers.ManualMovementSpeeds().Z);
|
||||
}
|
||||
|
||||
base.OnLoad(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
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 MatterHackers.Agg;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.DataConverters3D;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||
using MatterHackers.PolygonMesh;
|
||||
|
||||
namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
|
||||
{
|
||||
public class ZProbePrintCalibrationPartPage : WizardPage
|
||||
{
|
||||
public ZProbePrintCalibrationPartPage(ISetupWizard setupWizard, PrinterConfig printer, string headerText, string details)
|
||||
: base(setupWizard, headerText, details)
|
||||
{
|
||||
var spacer = new GuiWidget(15, 15);
|
||||
contentRow.AddChild(spacer);
|
||||
|
||||
int tabIndex = 0;
|
||||
|
||||
contentRow.AddChild(
|
||||
new TextWidget(
|
||||
"This wizard will close to print a calibration part and resume after the print completes.".Localize(),
|
||||
textColor: theme.TextColor,
|
||||
pointSize: theme.DefaultFontSize)
|
||||
{
|
||||
Margin = new BorderDouble(bottom: theme.DefaultContainerPadding)
|
||||
});
|
||||
|
||||
if (printer.Settings.GetValue<double>(SettingsKey.layer_height) < printer.Settings.GetValue<double>(SettingsKey.nozzle_diameter) / 2)
|
||||
{
|
||||
// The layer height is very small and it will be hard to see features. Show a warning.
|
||||
AddSettingsRow(contentRow, printer, "The calibration object will printer better if the layer hight is set to a larger value. It is recommended that your increase it.".Localize(), SettingsKey.layer_height, theme, ref tabIndex);
|
||||
}
|
||||
|
||||
if (printer.Settings.GetValue<bool>(SettingsKey.create_raft))
|
||||
{
|
||||
// The layer height is very small and it will be hard to see features. Show a warning.
|
||||
AddSettingsRow(contentRow, printer, "A raft is not needed for the calibration object. It is recommended that you turn it off.".Localize(), SettingsKey.create_raft, theme, ref tabIndex);
|
||||
}
|
||||
|
||||
if (printer.Settings.GetValue<int>(SettingsKey.top_solid_layers) < 4)
|
||||
{
|
||||
// The layer height is very small and it will be hard to see features. Show a warning.
|
||||
AddSettingsRow(contentRow, printer, "You should have at least 3 top layers for this calibration to measure off of.".Localize(), SettingsKey.top_solid_layers, theme, ref tabIndex);
|
||||
}
|
||||
|
||||
this.NextButton.Visible = false;
|
||||
|
||||
var startCalibrationPrint = theme.CreateDialogButton("Start Print".Localize());
|
||||
startCalibrationPrint.Name = "Start Calibration Print";
|
||||
startCalibrationPrint.Click += async (s, e) =>
|
||||
{
|
||||
var preCalibrationPrintViewMode = printer.ViewState.ViewMode;
|
||||
|
||||
// create the calibration objects
|
||||
var item = CreateCalibrationObject(printer);
|
||||
|
||||
var calibrationObjectPrinter = new CalibrationObjectPrinter(printer, item);
|
||||
// hide this window
|
||||
this.DialogWindow.Visible = false;
|
||||
|
||||
await calibrationObjectPrinter.PrintCalibrationPart();
|
||||
|
||||
// Restore the original DialogWindow
|
||||
this.DialogWindow.Visible = true;
|
||||
|
||||
// Restore to original view mode
|
||||
printer.ViewState.ViewMode = preCalibrationPrintViewMode;
|
||||
|
||||
this.MoveToNextPage();
|
||||
};
|
||||
|
||||
this.AcceptButton = startCalibrationPrint;
|
||||
|
||||
this.AddPageAction(startCalibrationPrint);
|
||||
}
|
||||
|
||||
public static double CalibrationObjectHeight(PrinterConfig printer)
|
||||
{
|
||||
var layerHeight = printer.Settings.GetValue<double>(SettingsKey.layer_height);
|
||||
var firstLayerHeight = printer.Settings.GetValue<double>(SettingsKey.first_layer_height);
|
||||
|
||||
return firstLayerHeight + layerHeight * 4;
|
||||
}
|
||||
|
||||
private static IObject3D CreateCalibrationObject(PrinterConfig printer)
|
||||
{
|
||||
var nozzleDiameter = printer.Settings.GetValue<double>(SettingsKey.nozzle_diameter);
|
||||
var size = Math.Min(30, nozzleDiameter * 20);
|
||||
|
||||
return new Object3D()
|
||||
{
|
||||
Mesh = PlatonicSolids.CreateCube(size, size, CalibrationObjectHeight(printer))
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
150
MatterControlLib/CustomWidgets/CalibrationObjectPrinter.cs
Normal file
150
MatterControlLib/CustomWidgets/CalibrationObjectPrinter.cs
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
/*
|
||||
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.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MatterHackers.DataConverters3D;
|
||||
using MatterHackers.MatterControl.Library;
|
||||
using MatterHackers.MatterControl.PrinterCommunication;
|
||||
using MatterHackers.VectorMath;
|
||||
|
||||
namespace MatterHackers.MatterControl
|
||||
{
|
||||
public class CalibrationObjectPrinter
|
||||
{
|
||||
private PrinterConfig printer;
|
||||
private IObject3D item;
|
||||
private bool calibrationComplete;
|
||||
|
||||
public CalibrationObjectPrinter(PrinterConfig printer, IObject3D objectToPrint)
|
||||
{
|
||||
this.printer = printer;
|
||||
this.item = objectToPrint;
|
||||
}
|
||||
|
||||
public async Task PrintCalibrationPart()
|
||||
{
|
||||
var scene = new Object3D();
|
||||
|
||||
// add the calibration object to the bed
|
||||
scene.Children.Add(item);
|
||||
|
||||
// move the part to the center of the bed
|
||||
var bedBounds = printer.Settings.BedBounds;
|
||||
var aabb = item.GetAxisAlignedBoundingBox();
|
||||
item.Matrix *= Matrix4X4.CreateTranslation(bedBounds.Center.X - aabb.MinXYZ.X - aabb.XSize / 2, bedBounds.Center.Y - aabb.MinXYZ.Y - aabb.YSize / 2, -aabb.MinXYZ.Z);
|
||||
|
||||
// register callbacks for print completion
|
||||
printer.Connection.Disposed += this.Connection_Disposed;
|
||||
printer.Connection.CancelCompleted += this.Connection_PrintCanceled;
|
||||
printer.Connection.CommunicationStateChanged += this.Connection_CommunicationStateChanged;
|
||||
|
||||
string gcodePath = EditContext.GCodeFilePath(printer, scene);
|
||||
|
||||
printer.Connection.CommunicationState = CommunicationStates.PreparingToPrint;
|
||||
|
||||
(bool slicingSucceeded, string finalGCodePath) = await ApplicationController.Instance.SliceItemLoadOutput(
|
||||
printer,
|
||||
scene,
|
||||
gcodePath);
|
||||
|
||||
// Only start print if slicing completed
|
||||
if (slicingSucceeded)
|
||||
{
|
||||
await printer.Bed.LoadContent(new EditContext()
|
||||
{
|
||||
SourceItem = new FileSystemFileItem(gcodePath),
|
||||
ContentStore = null // No content store for GCode
|
||||
});
|
||||
|
||||
await printer.Connection.StartPrint(finalGCodePath, printingMode: PrinterConnection.PrintingModes.Calibration);
|
||||
ApplicationController.Instance.MonitorPrintTask(printer);
|
||||
}
|
||||
else
|
||||
{
|
||||
printer.Connection.CommunicationState = CommunicationStates.Connected;
|
||||
}
|
||||
|
||||
bool PrintCompleted()
|
||||
{
|
||||
return calibrationComplete;
|
||||
}
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
while (!calibrationComplete)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void Connection_PrintCanceled(object sender, EventArgs e)
|
||||
{
|
||||
this.ReturnToCalibrationWizard();
|
||||
}
|
||||
|
||||
private void UnregisterPrinterEvents()
|
||||
{
|
||||
printer.Connection.Disposed -= this.Connection_Disposed;
|
||||
printer.Connection.CommunicationStateChanged -= this.Connection_CommunicationStateChanged;
|
||||
printer.Connection.CancelCompleted -= this.Connection_PrintCanceled;
|
||||
|
||||
calibrationComplete = true;
|
||||
}
|
||||
|
||||
private void Connection_CommunicationStateChanged(object sender, EventArgs e)
|
||||
{
|
||||
switch (printer.Connection.CommunicationState)
|
||||
{
|
||||
case CommunicationStates.Disconnected:
|
||||
case CommunicationStates.AttemptingToConnect:
|
||||
case CommunicationStates.FailedToConnect:
|
||||
case CommunicationStates.ConnectionLost:
|
||||
case CommunicationStates.PrintingFromSd:
|
||||
case CommunicationStates.FinishedPrint:
|
||||
// We are no longer printing, exit and return to where we started
|
||||
this.ReturnToCalibrationWizard();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ReturnToCalibrationWizard()
|
||||
{
|
||||
this.UnregisterPrinterEvents();
|
||||
}
|
||||
|
||||
private void Connection_Disposed(object sender, EventArgs e)
|
||||
{
|
||||
this.UnregisterPrinterEvents();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -28,7 +28,6 @@ either expressed or implied, of the FreeBSD Project.
|
|||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.UI;
|
||||
|
|
@ -36,11 +35,8 @@ using MatterHackers.DataConverters3D;
|
|||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling;
|
||||
using MatterHackers.MatterControl.DesignTools;
|
||||
using MatterHackers.MatterControl.Library;
|
||||
using MatterHackers.MatterControl.PartPreviewWindow;
|
||||
using MatterHackers.MatterControl.PrinterCommunication;
|
||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||
using MatterHackers.VectorMath;
|
||||
using static MatterHackers.MatterControl.ConfigurationPage.PrintLeveling.XyCalibrationWizard;
|
||||
|
||||
namespace MatterHackers.MatterControl
|
||||
|
|
@ -50,7 +46,6 @@ namespace MatterHackers.MatterControl
|
|||
private readonly RadioButton coarseCalibration;
|
||||
private readonly RadioButton normalCalibration;
|
||||
private readonly RadioButton fineCalibration;
|
||||
private PartViewMode preCalibrationPrintViewMode;
|
||||
|
||||
public XyCalibrationSelectPage(XyCalibrationWizard calibrationWizard)
|
||||
: base(calibrationWizard)
|
||||
|
|
@ -58,8 +53,6 @@ namespace MatterHackers.MatterControl
|
|||
this.WindowTitle = "Nozzle Offset Calibration Wizard".Localize();
|
||||
this.HeaderText = "Calibration Print".Localize();
|
||||
|
||||
preCalibrationPrintViewMode = printer.ViewState.ViewMode;
|
||||
|
||||
contentRow.Padding = theme.DefaultContainerPadding;
|
||||
|
||||
// default to normal offset
|
||||
|
|
@ -123,58 +116,18 @@ namespace MatterHackers.MatterControl
|
|||
calibrationWizard.Offset = printer.Settings.GetValue<double>(SettingsKey.nozzle_diameter) / 9.0;
|
||||
};
|
||||
|
||||
var settingsContext = new SettingsContext(printer, null, NamedSettingsLayers.All);
|
||||
int tabIndex = 0;
|
||||
var allUiFields = new Dictionary<string, UIField>();
|
||||
var settingAdded = false;
|
||||
|
||||
void AddSettingsRow(string warning, string key)
|
||||
{
|
||||
if (!settingAdded)
|
||||
{
|
||||
contentRow.AddChild(
|
||||
new TextWidget(
|
||||
"Recommended Settings Changes".Localize() + ":",
|
||||
textColor: theme.TextColor,
|
||||
pointSize: theme.DefaultFontSize)
|
||||
{
|
||||
Margin = new BorderDouble(10, 0, 0, 20)
|
||||
});
|
||||
|
||||
settingAdded = true;
|
||||
}
|
||||
|
||||
contentRow.AddChild(
|
||||
new WrappedTextWidget(
|
||||
warning,
|
||||
textColor: theme.TextColor,
|
||||
pointSize: theme.DefaultFontSize)
|
||||
{
|
||||
Margin = new BorderDouble(0, 10, 0, 20)
|
||||
});
|
||||
|
||||
var settingsData = PrinterSettings.SettingsData[key];
|
||||
var row = SliceSettingsTabView.CreateItemRow(settingsData, settingsContext, printer, theme, ref tabIndex, allUiFields);
|
||||
|
||||
if (row is SliceSettingsRow settingsRow)
|
||||
{
|
||||
settingsRow.ArrowDirection = ArrowDirection.Left;
|
||||
}
|
||||
|
||||
contentRow.AddChild(row);
|
||||
}
|
||||
|
||||
|
||||
if (printer.Settings.GetValue<double>(SettingsKey.layer_height) < printer.Settings.GetValue<double>(SettingsKey.nozzle_diameter) / 2)
|
||||
{
|
||||
// The layer height is very small and it will be hard to see features. Show a warning.
|
||||
AddSettingsRow("The calibration object will printer better if the layer hight is set to a larger value. It is recommended that your increase it.".Localize(), SettingsKey.layer_height);
|
||||
AddSettingsRow(contentRow, printer, "The calibration object will printer better if the layer hight is set to a larger value. It is recommended that your increase it.".Localize(), SettingsKey.layer_height, theme, ref tabIndex);
|
||||
}
|
||||
|
||||
if (printer.Settings.GetValue<bool>(SettingsKey.create_raft))
|
||||
{
|
||||
// The layer height is very small and it will be hard to see features. Show a warning.
|
||||
AddSettingsRow("A raft is not needed for the calibration object. It is recommended that you turn it off.".Localize(), SettingsKey.create_raft);
|
||||
AddSettingsRow(contentRow, printer, "A raft is not needed for the calibration object. It is recommended that you turn it off.".Localize(), SettingsKey.create_raft, theme, ref tabIndex);
|
||||
}
|
||||
|
||||
this.NextButton.Visible = false;
|
||||
|
|
@ -185,7 +138,7 @@ namespace MatterHackers.MatterControl
|
|||
alreadyCalibratedButton.Click += (s, e) =>
|
||||
{
|
||||
printer.Settings.SetValue(SettingsKey.xy_offsets_have_been_calibrated, "1");
|
||||
this.FinishWizard();
|
||||
FinishWizard();
|
||||
};
|
||||
|
||||
this.AddPageAction(alreadyCalibratedButton);
|
||||
|
|
@ -194,97 +147,17 @@ namespace MatterHackers.MatterControl
|
|||
startCalibrationPrint.Name = "Start Calibration Print";
|
||||
startCalibrationPrint.Click += async (s, e) =>
|
||||
{
|
||||
await PrintCalibrationPart(calibrationWizard);
|
||||
};
|
||||
var preCalibrationPrintViewMode = printer.ViewState.ViewMode;
|
||||
|
||||
this.AcceptButton = startCalibrationPrint;
|
||||
// create the calibration objects
|
||||
IObject3D item = await CreateCalibrationObject(printer, calibrationWizard);
|
||||
|
||||
this.AddPageAction(startCalibrationPrint);
|
||||
}
|
||||
var calibrationObjectPrinter = new CalibrationObjectPrinter(printer, item);
|
||||
// hide this window
|
||||
this.DialogWindow.Visible = false;
|
||||
|
||||
private async Task PrintCalibrationPart(XyCalibrationWizard calibrationWizard)
|
||||
{
|
||||
var scene = new Object3D();
|
||||
await calibrationObjectPrinter.PrintCalibrationPart();
|
||||
|
||||
// create the calibration objects
|
||||
IObject3D item = await CreateCalibrationObject(printer, calibrationWizard);
|
||||
|
||||
// add the calibration object to the bed
|
||||
scene.Children.Add(item);
|
||||
|
||||
// move the part to the center of the bed
|
||||
var bedBounds = printer.Settings.BedBounds;
|
||||
var aabb = item.GetAxisAlignedBoundingBox();
|
||||
item.Matrix *= Matrix4X4.CreateTranslation(bedBounds.Center.X - aabb.MinXYZ.X - aabb.XSize / 2, bedBounds.Center.Y - aabb.MinXYZ.Y - aabb.YSize / 2, -aabb.MinXYZ.Z);
|
||||
|
||||
// register callbacks for print completion
|
||||
printer.Connection.Disposed += this.Connection_Disposed;
|
||||
printer.Connection.CancelCompleted += this.Connection_PrintCanceled;
|
||||
printer.Connection.CommunicationStateChanged += this.Connection_CommunicationStateChanged;
|
||||
|
||||
// hide this window
|
||||
this.DialogWindow.Visible = false;
|
||||
|
||||
string gcodePath = EditContext.GCodeFilePath(printer, scene);
|
||||
|
||||
printer.Connection.CommunicationState = CommunicationStates.PreparingToPrint;
|
||||
|
||||
(bool slicingSucceeded, string finalGCodePath) = await ApplicationController.Instance.SliceItemLoadOutput(
|
||||
printer,
|
||||
scene,
|
||||
gcodePath);
|
||||
|
||||
// Only start print if slicing completed
|
||||
if (slicingSucceeded)
|
||||
{
|
||||
await printer.Bed.LoadContent(new EditContext()
|
||||
{
|
||||
SourceItem = new FileSystemFileItem(gcodePath),
|
||||
ContentStore = null // No content store for GCode
|
||||
});
|
||||
|
||||
await printer.Connection.StartPrint(finalGCodePath, printingMode: PrinterConnection.PrintingModes.Calibration);
|
||||
ApplicationController.Instance.MonitorPrintTask(printer);
|
||||
}
|
||||
else
|
||||
{
|
||||
printer.Connection.CommunicationState = CommunicationStates.Connected;
|
||||
}
|
||||
}
|
||||
|
||||
private void Connection_PrintCanceled(object sender, EventArgs e)
|
||||
{
|
||||
this.ReturnToCalibrationWizard();
|
||||
}
|
||||
|
||||
private void UnregisterPrinterEvents()
|
||||
{
|
||||
printer.Connection.Disposed -= this.Connection_Disposed;
|
||||
printer.Connection.CommunicationStateChanged -= this.Connection_CommunicationStateChanged;
|
||||
printer.Connection.CancelCompleted -= this.Connection_PrintCanceled;
|
||||
}
|
||||
|
||||
private void Connection_CommunicationStateChanged(object sender, EventArgs e)
|
||||
{
|
||||
switch (printer.Connection.CommunicationState)
|
||||
{
|
||||
case CommunicationStates.Disconnected:
|
||||
case CommunicationStates.AttemptingToConnect:
|
||||
case CommunicationStates.FailedToConnect:
|
||||
case CommunicationStates.ConnectionLost:
|
||||
case CommunicationStates.PrintingFromSd:
|
||||
case CommunicationStates.FinishedPrint:
|
||||
// We are no longer printing, exit and return to where we started
|
||||
this.ReturnToCalibrationWizard();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ReturnToCalibrationWizard()
|
||||
{
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
// Restore the original DialogWindow
|
||||
this.DialogWindow.Visible = true;
|
||||
|
||||
|
|
@ -292,14 +165,11 @@ namespace MatterHackers.MatterControl
|
|||
printer.ViewState.ViewMode = preCalibrationPrintViewMode;
|
||||
|
||||
this.MoveToNextPage();
|
||||
});
|
||||
};
|
||||
|
||||
this.UnregisterPrinterEvents();
|
||||
}
|
||||
this.AcceptButton = startCalibrationPrint;
|
||||
|
||||
private void Connection_Disposed(object sender, EventArgs e)
|
||||
{
|
||||
this.UnregisterPrinterEvents();
|
||||
this.AddPageAction(startCalibrationPrint);
|
||||
}
|
||||
|
||||
private static async Task<IObject3D> CreateCalibrationObject(PrinterConfig printer, XyCalibrationWizard calibrationWizard)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue