Improving end of print behavior

This commit is contained in:
LarsBrubaker 2020-10-25 08:48:43 -07:00
parent 1a6e1b41b1
commit 0fbf9e8ccd
6 changed files with 282 additions and 149 deletions

View file

@ -30,7 +30,6 @@ either expressed or implied, of the FreeBSD Project.
using System;
using System.Collections.Generic;
using System.Linq;
using Markdig.Agg;
using MatterHackers.Agg;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.PrinterCommunication;
@ -189,7 +188,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
// Require user confirmation after this point
this.RequireCancelConfirmation = true;
// start heating up the now so it has more time to heat
// start heating up now so it has more time to heat
var bedTemperature = printer.Settings.GetValue<bool>(SettingsKey.has_heated_bed) ?
printer.Settings.GetValue<double>(SettingsKey.bed_temperature)
: 0;

View file

@ -42,9 +42,9 @@ namespace MatterHackers.MatterControl.PrintHistory
{
public class PrintHistoryEditor
{
private ThemeConfig theme;
private PrintTask printTask;
private IEnumerable<PrintTask> printTasks;
private readonly ThemeConfig theme;
private readonly PrintTask printTask;
private readonly IEnumerable<PrintTask> printTasks;
public PrintHistoryEditor(ThemeConfig theme, PrintTask printTask, IEnumerable<PrintTask> printTasks)
{
@ -71,7 +71,7 @@ namespace MatterHackers.MatterControl.PrintHistory
var inputBoxPage = new InputBoxPage(
"Print History Note".Localize(),
"Note".Localize(),
printTask.Note == null ? "" : printTask.Note,
printTask.Note ?? "",
"Enter Note Here".Localize(),
string.IsNullOrEmpty(printTask.Note) ? "Add Note".Localize() : "Update".Localize(),
(newNote) =>
@ -85,7 +85,7 @@ namespace MatterHackers.MatterControl.PrintHistory
AllowEmpty = true,
};
inputBoxPage.ContentRow.AddChild(CreateDefaultOptions(inputBoxPage));
inputBoxPage.ContentRow.AddChild(CreateDefaultOptions(inputBoxPage, theme));
DialogWindow.Show(inputBoxPage);
@ -153,7 +153,7 @@ namespace MatterHackers.MatterControl.PrintHistory
return content;
}
private GuiWidget CreateDefaultOptions(GuiWidget textField)
public static GuiWidget CreateDefaultOptions(GuiWidget textField, ThemeConfig theme)
{
var issues = new string[]
{
@ -205,17 +205,18 @@ namespace MatterHackers.MatterControl.PrintHistory
public void CollectInfoPrintCanceled()
{
string markdownText = @"Looks like you canceled this print. If you need help, here are some links that might be useful.
string markdownText = @"If you need help, here are some links that might be useful.
- [MatterControl Docs](https://www.matterhackers.com/mattercontrol/support)
- [Tutorials](https://www.matterhackers.com/store/l/mattercontrol/sk/MKZGTDW6#tutorials)
- [Trick, Tips & Support Articles](https://www.matterhackers.com/support#mattercontrol)
- [User Forum](https://forums.matterhackers.com/recent)";
new CollectPrintDetailsPage("Print Canceled".Localize(),
"Top Markdown",
"Oops, looks like you canceled the print.",
markdownText,
UserSettingsKey.ShownPrintCanceledMessage,
printTask);
printTask,
false);
}
public void CollectInfoPrintFinished()
@ -226,9 +227,8 @@ namespace MatterHackers.MatterControl.PrintHistory
string markdownText = @"**Find more at MatterHackers**
Supplies and accessories:
- [Filament](https://www.matterhackers.com/store/c/3d-printer-filament)
- [Bed Adhesives](https://www.matterhackers.com/store/c/3d-printer-adhesive)
- [Digital Designs](https://www.matterhackers.com/store/c/digital-designs)
[![Filament](https://lh3.googleusercontent.com/2QmeGU_t2KKvAuXTSCYHq1EQTMHRurwreztY52jGdtRQStAEit7Yjsz_hW9l1akGjun7dVcaCGdHEHdGNIGkKykoMg=w100-h100)](https://www.matterhackers.com/store/c/3d-printer-filament) [![Adhesives](https://lh3.googleusercontent.com/LwlavuKk8UXhOuRVB8Q3hqj-AYDHUl8vg_cDanQ8weKM1M7iyMRLjvVD0QWvj6dmCGpSE1t2lKSeMDAmTpJVHLS1bQ=w100-h100)](https://www.matterhackers.com/store/c/3d-printer-adhesive) [![Accessories](https://lh3.googleusercontent.com/pizcbdPu1qn2_QLwyoB2mSr00ckkKkSNkRJ3YmYP-ydkwTpyKy1P_hb6SV2lrH9CbWyy4HViO3VPXV5Q7q-9iGm0wg=w100-h100)](https://www.matterhackers.com/store/c/printer-accessories)
Support and tutorials:
- [MatterControl Docs](https://www.matterhackers.com/mattercontrol/support)
@ -237,129 +237,146 @@ Support and tutorials:
- [User Forum](https://forums.matterhackers.com/recent)";
new CollectPrintDetailsPage("Congratulations Print Complete".Localize(),
"Top Markdown",
"How did this print come out?",
markdownText,
UserSettingsKey.ShownPrintCompleteMessage,
printTask);
}
}
public class CollectPrintDetailsPage : DialogPage
{
private MHTextEditWidget textEditWidget;
public override string Text { get => textEditWidget.Text; set => textEditWidget.Text = value; }
public CollectPrintDetailsPage(string windowTitle, string topMarkDown, string descriptionMarkdown, string userKey, PrintTask printTask)
{
this.WindowTitle = windowTitle;
this.HeaderText = windowTitle;
this.WindowSize = new Vector2(500 * GuiWidget.DeviceScale, 400 * GuiWidget.DeviceScale);
var scrollable = new ScrollableWidget(autoScroll: true)
{
HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Stretch,
Margin = new BorderDouble(bottom: 10),
};
scrollable.ScrollArea.HAnchor = HAnchor.Stretch;
scrollable.ScrollArea.VAnchor = VAnchor.Fit;
contentRow.AddChild(scrollable);
var topToBottom = scrollable.AddChild(new FlowLayoutWidget(FlowDirection.TopToBottom)
{
HAnchor = HAnchor.Stretch
});
topToBottom.AddChild(new MarkdownWidget(theme, false)
{
Markdown = topMarkDown,
});
topToBottom.AddChild(PrintHistoryEditor.GetQualityWidget(theme,
printTask,
() =>
true);
}
public class CollectPrintDetailsPage : DialogPage
{
private readonly MHTextEditWidget textEditWidget;
public override string Text { get => textEditWidget.Text; set => textEditWidget.Text = value; }
public CollectPrintDetailsPage(string windowTitle,
string topMarkDown,
string descriptionMarkdown,
string userKey,
PrintTask printTask,
bool collectQuality)
{
this.WindowTitle = windowTitle;
this.HeaderText = windowTitle;
this.WindowSize = new Vector2(500 * GuiWidget.DeviceScale, 400 * GuiWidget.DeviceScale);
var scrollable = new ScrollableWidget(autoScroll: true)
{
},
16));
HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Stretch,
Margin = new BorderDouble(bottom: 10),
};
// Adds text box and check box to the above container
var emptyText = "Enter Note Here".Localize();
var initialValue = printTask.Note == null ? "" : printTask.Note;
textEditWidget = new MHTextEditWidget(initialValue, theme, pixelWidth: 300, messageWhenEmptyAndNotSelected: emptyText);
textEditWidget.Name = "InputBoxPage TextEditWidget";
textEditWidget.HAnchor = HAnchor.Stretch;
textEditWidget.Margin = new BorderDouble(5);
scrollable.ScrollArea.HAnchor = HAnchor.Stretch;
scrollable.ScrollArea.VAnchor = VAnchor.Fit;
contentRow.AddChild(scrollable);
//textEditWidget.ActualTextEditWidget.EnterPressed += (s, e) =>
//{
// actionButton.InvokeClick();
//};
//contentRow.AddChild(textEditWidget);
//actionButton = theme.CreateDialogButton(actionButtonTitle);
//actionButton.Name = "InputBoxPage Action Button";
//actionButton.Cursor = Cursors.Hand;
//actionButton.Click += (s, e) =>
//{
// string newName = textEditWidget.ActualTextEditWidget.Text;
// if (!string.IsNullOrEmpty(newName) || AllowEmpty)
// {
// action.Invoke(newName);
// this.DialogWindow.CloseOnIdle();
// }
//};
//this.AddPageAction(actionButton);
topToBottom.AddChild(new MarkdownWidget(theme, false)
{
Markdown = descriptionMarkdown,
});
var hideAfterPrintMessage = new CheckBox("Don't show this again".Localize())
{
TextColor = AppContext.Theme.TextColor,
Margin = new BorderDouble(top: 6, left: 6),
HAnchor = Agg.UI.HAnchor.Left,
Checked = UserSettings.Instance.get(userKey) == "false",
};
contentRow.AddChild(hideAfterPrintMessage);
hideAfterPrintMessage.Click += (s, e1) =>
{
if (hideAfterPrintMessage.Checked)
var topToBottom = scrollable.AddChild(new FlowLayoutWidget(FlowDirection.TopToBottom)
{
UserSettings.Instance.set(userKey, "false");
HAnchor = HAnchor.Stretch
});
topToBottom.AddChild(new MarkdownWidget(theme, false)
{
Markdown = topMarkDown,
});
var reasonSection = new FlowLayoutWidget(FlowDirection.TopToBottom)
{
HAnchor = HAnchor.Stretch,
Visible = !collectQuality
};
if (collectQuality)
{
var qualityInput = GetQualityWidget(theme,
printTask,
() =>
{
reasonSection.Visible = printTask.PrintQuality == 0;
this.Descendants<ScrollableWidget>().First().ScrollPositionFromTop = new Vector2(0, 0);
},
16);
qualityInput.Margin = new BorderDouble(5, 0);
qualityInput.HAnchor = HAnchor.Left;
topToBottom.AddChild(qualityInput);
}
else
{
UserSettings.Instance.set(userKey, "true");
}
};
if (!hideAfterPrintMessage.Checked)
{
UiThread.RunOnIdle(() => DialogWindow.Show(this, 0));
topToBottom.AddChild(reasonSection);
// Adds text box and check box to the above container
var emptyText = "What went wrong?".Localize();
var initialValue = printTask.Note ?? "";
textEditWidget = new MHTextEditWidget(initialValue, theme, pixelWidth: 300, messageWhenEmptyAndNotSelected: emptyText)
{
Name = "InputBoxPage TextEditWidget",
HAnchor = HAnchor.Stretch,
Margin = new BorderDouble(5)
};
reasonSection.AddChild(textEditWidget);
var reasons = PrintHistoryEditor.CreateDefaultOptions(textEditWidget, theme);
reasons.Margin = new BorderDouble(5, 0);
reasons.HAnchor = HAnchor.Left;
reasonSection.AddChild(reasons);
topToBottom.AddChild(new HorizontalLine(theme.BorderColor40)
{
Margin = new BorderDouble(0, 5)
});
topToBottom.AddChild(new MarkdownWidget(theme, false)
{
Markdown = descriptionMarkdown,
});
var hideAfterPrintMessage = new CheckBox("Don't show this again".Localize())
{
TextColor = AppContext.Theme.TextColor,
Margin = new BorderDouble(top: 6, left: 6),
HAnchor = Agg.UI.HAnchor.Left,
Checked = UserSettings.Instance.get(userKey) == "false",
};
contentRow.AddChild(hideAfterPrintMessage);
hideAfterPrintMessage.Click += (s, e1) =>
{
if (hideAfterPrintMessage.Checked)
{
UserSettings.Instance.set(userKey, "false");
}
else
{
UserSettings.Instance.set(userKey, "true");
}
};
if (!hideAfterPrintMessage.Checked)
{
UiThread.RunOnIdle(() =>
{
DialogWindow.Show(this, 0);
// this will cause a layout that fixes a display issue
this.Width += 1;
this.Width -= 1;
this.Descendants<ScrollableWidget>().First().ScrollPositionFromTop = new Vector2(0, 0);
});
}
}
UiThread.RunOnIdle(() =>
{
this.Width = this.Width + 1;
this.Width = this.Width - 1;
});
}
public bool AllowEmpty { get; set; }
public bool AllowEmpty { get; set; }
public override void OnLoad(EventArgs args)
{
UiThread.RunOnIdle(() =>
public override void OnLoad(EventArgs args)
{
textEditWidget.Focus();
textEditWidget.ActualTextEditWidget.InternalTextEditWidget.SelectAll();
});
base.OnLoad(args);
UiThread.RunOnIdle(() =>
{
textEditWidget.Focus();
textEditWidget.ActualTextEditWidget.InternalTextEditWidget.SelectAll();
});
base.OnLoad(args);
}
}
}
}

View file

@ -27,33 +27,10 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using MatterControl.Printing;
using MatterHackers.Agg;
using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.MatterControl.PrinterCommunication.Io;
using MatterHackers.MatterControl.PrintQueue;
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.SerialPortCommunication;
using MatterHackers.SerialPortCommunication.FrostedSerial;
using MatterHackers.VectorMath;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
namespace MatterHackers.MatterControl.PrinterCommunication
{
public class ConnectFailedEventArgs : EventArgs
{
public ConnectionFailure Reason { get; }

View file

@ -0,0 +1,135 @@
/*
Copyright (c) 2018, Lars Brubaker
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.MatterControl.ConfigurationPage.PrintLeveling;
using MatterHackers.MatterControl.SlicerConfiguration;
namespace MatterHackers.MatterControl.PrinterCommunication.Io
{
public class ValidatePrintLevelingStream : GCodeStreamProxy
{
private bool gcodeAlreadyLeveled;
public ValidatePrintLevelingStream(PrinterConfig printer, PrintLevelingStream internalStream)
: base(printer, internalStream)
{
}
public override string DebugInfo => "";
public static string BeginString => "; VALIDATE_LEVELING";
private readonly double[] babySteppingValue = new double[4];
public override string ReadLine()
{
string lineToSend = base.ReadLine();
if (lineToSend != null
&& lineToSend.EndsWith("; NO_PROCESSING"))
{
return lineToSend;
}
if (lineToSend == "; Software Leveling Applied")
{
gcodeAlreadyLeveled = true;
}
if (lineToSend != null
&& !gcodeAlreadyLeveled)
{
if (lineToSend == BeginString)
{
printer.Settings.ForTools<double>(SettingsKey.baby_step_z_offset, (key, value, i) =>
{
// remember the current baby stepping values
babySteppingValue[i] = value;
// clear them while we measure the offsets
printer.Settings.SetValue(key, "0");
});
// turn off print leveling
printer.Connection.AllowLeveling = false;
// clear any data that we are going to be acquiring (sampled positions, after z home offset)
var levelingData = new PrintLevelingData()
{
LevelingSystem = printer.Settings.GetValue<LevelingSystem>(SettingsKey.print_leveling_solution)
};
printer.Connection.QueueLine("T0");
LevelingPlan levelingPlan;
switch (levelingData.LevelingSystem)
{
case LevelingSystem.Probe3Points:
levelingPlan = new LevelWizard3Point(printer);
break;
case LevelingSystem.Probe7PointRadial:
levelingPlan = new LevelWizard7PointRadial(printer);
break;
case LevelingSystem.Probe13PointRadial:
levelingPlan = new LevelWizard13PointRadial(printer);
break;
case LevelingSystem.Probe100PointRadial:
levelingPlan = new LevelWizard100PointRadial(printer);
break;
case LevelingSystem.Probe3x3Mesh:
levelingPlan = new LevelWizardMesh(printer, 3, 3);
break;
case LevelingSystem.Probe5x5Mesh:
levelingPlan = new LevelWizardMesh(printer, 5, 5);
break;
case LevelingSystem.Probe10x10Mesh:
levelingPlan = new LevelWizardMesh(printer, 10, 10);
break;
case LevelingSystem.ProbeCustom:
levelingPlan = new LevelWizardCustom(printer);
break;
default:
throw new NotImplementedException();
}
}
}
return lineToSend;
}
}
}

View file

@ -2405,7 +2405,12 @@ Make sure that your printer is turned on. Some printers will appear to be connec
if (!LevelingValidation.NeedsToBeRun(Printer))
{
accumulatedStream = printLevelingStream = new PrintLevelingStream(Printer, accumulatedStream);
printLevelingStream = new PrintLevelingStream(Printer, accumulatedStream);
if (Printer.Settings.Helpers.UseZProbe()
&& Printer.Settings.GetValue(SettingsKey.start_gcode).Contains(ValidatePrintLevelingStream.BeginString))
{
accumulatedStream = new ValidatePrintLevelingStream(Printer, printLevelingStream);
}
}
accumulatedStream = waitForTempStream = new WaitForTempStream(Printer, accumulatedStream);

@ -1 +1 @@
Subproject commit dd862e4d29fb121cdcee8dffe6305172c2053113
Subproject commit 81c56353d4f6db105087d3ec4c164bce38449b81