From 23c409dd836516e660bf7d4aebcdc151892669ce Mon Sep 17 00:00:00 2001 From: LarsBrubaker Date: Sun, 30 Aug 2020 08:29:15 -0700 Subject: [PATCH] Don't apply extrusion multiplier while loading and unloading issue: MatterHackers/MCCentral#6024 Load/Unload filament should ignore Extrusion Multiplier --- .../SetupWizards/LoadFilamentWizard.cs | 136 +++++++++--------- .../SetupWizards/UnloadFilamentWizard.cs | 58 ++++---- .../CustomWidgets/TreeView/TreeNode.cs | 46 +++--- .../Library/Widgets/LibraryWidget.cs | 4 +- 4 files changed, 128 insertions(+), 116 deletions(-) diff --git a/MatterControlLib/ConfigurationPage/PrintLeveling/SetupWizards/LoadFilamentWizard.cs b/MatterControlLib/ConfigurationPage/PrintLeveling/SetupWizards/LoadFilamentWizard.cs index 454530f0f..833a61eee 100644 --- a/MatterControlLib/ConfigurationPage/PrintLeveling/SetupWizards/LoadFilamentWizard.cs +++ b/MatterControlLib/ConfigurationPage/PrintLeveling/SetupWizards/LoadFilamentWizard.cs @@ -44,7 +44,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling { private readonly bool showAlreadyLoadedButton; - private int extruderIndex; + private readonly int extruderIndex; public LoadFilamentWizard(PrinterConfig printer, int extruderIndex, bool showAlreadyLoadedButton) : base(printer) @@ -157,8 +157,10 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling printer.Connection.SetTargetHotendTemperature(extruderIndex, printer.Settings.GetValue(SettingsKey.temperature)); var markdownText = printer.Settings.GetValue(SettingsKey.trim_filament_markdown); - var markdownWidget = new MarkdownWidget(theme); - markdownWidget.Markdown = markdownText = markdownText.Replace("\\n", "\n"); + var markdownWidget = new MarkdownWidget(theme) + { + Markdown = markdownText = markdownText.Replace("\\n", "\n") + }; page.ContentRow.AddChild(markdownWidget); } }; @@ -173,6 +175,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling // reset the extrusion amount so this is easier to debug printer.Connection.QueueLine("G92 E0"); + var extrusionMultiplierStream = printer.Connection.ExtrusionMultiplierStream; + var oldExtrusionMultiplier = extrusionMultiplierStream.ExtrusionRatio; // show the insert filament page { @@ -181,6 +185,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling { PageLoad = (page) => { + extrusionMultiplierStream.ExtrusionRatio = 1; + var markdownText = printer.Settings.GetValue(SettingsKey.insert_filament_markdown2); if (extruderIndex == 1) @@ -188,8 +194,10 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling markdownText = printer.Settings.GetValue(SettingsKey.insert_filament_1_markdown); } - var markdownWidget = new MarkdownWidget(theme); - markdownWidget.Markdown = markdownText = markdownText.Replace("\\n", "\n"); + var markdownWidget = new MarkdownWidget(theme) + { + Markdown = markdownText = markdownText.Replace("\\n", "\n") + }; page.ContentRow.AddChild(markdownWidget); // turn off the fan @@ -203,18 +211,9 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling { if (printer.Connection.NumQueuedCommands == 0) { - if (false) - { - // Quite mode - printer.Connection.MoveRelative(PrinterCommunication.PrinterConnection.Axis.E, 1, 80); - printer.Connection.QueueLine("G4 P1"); // empty buffer - allow for cancel - } - else - { - // Pulse mode - printer.Connection.MoveRelative(PrinterCommunication.PrinterConnection.Axis.E, 1, 150); - printer.Connection.QueueLine("G4 P10"); // empty buffer - allow for cancel - } + // Pulse mode + printer.Connection.MoveRelative(PrinterCommunication.PrinterConnection.Axis.E, 1, 150); + printer.Connection.QueueLine("G4 P10"); // empty buffer - allow for cancel if (runningTime.ElapsedMilliseconds > maxSecondsToStartLoading * 1000) { @@ -226,6 +225,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling }, PageClose = () => { + extrusionMultiplierStream.ExtrusionRatio = oldExtrusionMultiplier; + if (runningGCodeCommands != null) { UiThread.ClearInterval(runningGCodeCommands); @@ -250,6 +251,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling { PageLoad = (page) => { + extrusionMultiplierStream.ExtrusionRatio = 1; + page.NextButton.Enabled = false; // add the progress bar @@ -326,6 +329,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling }, PageClose = () => { + extrusionMultiplierStream.ExtrusionRatio = oldExtrusionMultiplier; + UiThread.ClearInterval(runningGCodeCommands); } }; @@ -361,6 +366,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling { PageLoad = (page) => { + extrusionMultiplierStream.ExtrusionRatio = 1; + var markdownText = printer.Settings.GetValue(SettingsKey.running_clean_markdown2); if (extruderIndex == 1) @@ -368,8 +375,10 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling markdownText = printer.Settings.GetValue(SettingsKey.running_clean_1_markdown); } - var markdownWidget = new MarkdownWidget(theme); - markdownWidget.Markdown = markdownText = markdownText.Replace("\\n", "\n"); + var markdownWidget = new MarkdownWidget(theme) + { + Markdown = markdownText = markdownText.Replace("\\n", "\n") + }; page.ContentRow.AddChild(markdownWidget); var runningTime = Stopwatch.StartNew(); @@ -377,18 +386,9 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling { if (printer.Connection.NumQueuedCommands == 0) { - if (false) - { - // Quite mode - printer.Connection.MoveRelative(PrinterCommunication.PrinterConnection.Axis.E, 2, 140); - printer.Connection.QueueLine("G4 P1"); // empty buffer - allow for cancel - } - else - { - // Pulse mode - printer.Connection.MoveRelative(PrinterCommunication.PrinterConnection.Axis.E, 2, 150); - printer.Connection.QueueLine("G4 P10"); // empty buffer - allow for cancel - } + // Pulse mode + printer.Connection.MoveRelative(PrinterCommunication.PrinterConnection.Axis.E, 2, 150); + printer.Connection.QueueLine("G4 P10"); // empty buffer - allow for cancel int secondsToRun = 90; if (runningTime.ElapsedMilliseconds > secondsToRun * 1000) @@ -401,6 +401,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling }, PageClose = () => { + extrusionMultiplierStream.ExtrusionRatio = oldExtrusionMultiplier; + UiThread.ClearInterval(runningGCodeCommands); } }; @@ -411,51 +413,51 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling // put up a success message yield return new DoneLoadingPage(this, extruderIndex); } - } - public class DoneLoadingPage : WizardPage - { - private int extruderIndex; - - public DoneLoadingPage(PrinterSetupWizard setupWizard, int extruderIndex) - : base(setupWizard, "Filament Loaded".Localize(), "Success!\n\nYour filament should now be loaded".Localize()) + public class DoneLoadingPage : WizardPage { - this.extruderIndex = extruderIndex; + private readonly int extruderIndex; - if (printer.Connection.Paused) + public DoneLoadingPage(PrinterSetupWizard setupWizard, int extruderIndex) + : base(setupWizard, "Filament Loaded".Localize(), "Success!\n\nYour filament should now be loaded".Localize()) { - var resumePrintingButton = new TextButton("Resume Printing".Localize(), theme) + this.extruderIndex = extruderIndex; + + if (printer.Connection.Paused) { - Name = "Resume Printing Button", - BackgroundColor = theme.MinimalShade, - }; - resumePrintingButton.Click += (s, e) => - { - printer.Connection.Resume(); - this.DialogWindow.ClosePage(); - }; + var resumePrintingButton = new TextButton("Resume Printing".Localize(), theme) + { + Name = "Resume Printing Button", + BackgroundColor = theme.MinimalShade, + }; + resumePrintingButton.Click += (s, e) => + { + printer.Connection.Resume(); + this.DialogWindow.ClosePage(); + }; - this.AcceptButton = resumePrintingButton; - this.AddPageAction(resumePrintingButton); - } - } - - public override void OnLoad(EventArgs args) - { - switch (extruderIndex) - { - case 0: - printer.Settings.SetValue(SettingsKey.filament_has_been_loaded, "1"); - break; - - case 1: - printer.Settings.SetValue(SettingsKey.filament_1_has_been_loaded, "1"); - break; + this.AcceptButton = resumePrintingButton; + this.AddPageAction(resumePrintingButton); + } } - this.ShowWizardFinished(); + public override void OnLoad(EventArgs args) + { + switch (extruderIndex) + { + case 0: + printer.Settings.SetValue(SettingsKey.filament_has_been_loaded, "1"); + break; - base.OnLoad(args); + case 1: + printer.Settings.SetValue(SettingsKey.filament_1_has_been_loaded, "1"); + break; + } + + this.ShowWizardFinished(); + + base.OnLoad(args); + } } } } diff --git a/MatterControlLib/ConfigurationPage/PrintLeveling/SetupWizards/UnloadFilamentWizard.cs b/MatterControlLib/ConfigurationPage/PrintLeveling/SetupWizards/UnloadFilamentWizard.cs index 16a1e2c3d..82cd7a727 100644 --- a/MatterControlLib/ConfigurationPage/PrintLeveling/SetupWizards/UnloadFilamentWizard.cs +++ b/MatterControlLib/ConfigurationPage/PrintLeveling/SetupWizards/UnloadFilamentWizard.cs @@ -41,7 +41,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling { public class UnloadFilamentWizard : PrinterSetupWizard { - private int extruderIndex; + private readonly int extruderIndex; public UnloadFilamentWizard(PrinterConfig printer, int extruderIndex) : base(printer) @@ -99,6 +99,9 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling temps); } + var extrusionMultiplierStream = printer.Connection.ExtrusionMultiplierStream; + var oldExtrusionMultiplier = extrusionMultiplierStream.ExtrusionRatio; + // show the unloading filament progress bar { int extruderPriorToUnload = printer.Connection.ActiveExtruderIndex; @@ -108,6 +111,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling { PageLoad = (page) => { + extrusionMultiplierStream.ExtrusionRatio = 1; + page.NextButton.Enabled = false; // add the progress bar @@ -203,6 +208,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling }, PageClose = () => { + extrusionMultiplierStream.ExtrusionRatio = oldExtrusionMultiplier; + UiThread.ClearInterval(runningGCodeCommands); } }; @@ -214,6 +221,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling // reset the extruder that was active printer.Connection.QueueLine($"T{extruderPriorToUnload}"); } + printer.Connection.QueueLine("G92 E0"); }; @@ -223,34 +231,34 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling // put up a success message yield return new DoneUnloadingPage(this, extruderIndex); } - } - public class DoneUnloadingPage : WizardPage - { - public DoneUnloadingPage(PrinterSetupWizard setupWizard, int extruderIndex) - : base(setupWizard, "Filament Unloaded".Localize(), "Success!\n\nYour filament should now be unloaded".Localize()) + public class DoneUnloadingPage : WizardPage { - var loadFilamentButton = new TextButton("Load Filament".Localize(), theme) + public DoneUnloadingPage(PrinterSetupWizard setupWizard, int extruderIndex) + : base(setupWizard, "Filament Unloaded".Localize(), "Success!\n\nYour filament should now be unloaded".Localize()) { - Name = "Load Filament", - BackgroundColor = theme.MinimalShade, - }; - loadFilamentButton.Click += (s, e) => + var loadFilamentButton = new TextButton("Load Filament".Localize(), theme) + { + Name = "Load Filament", + BackgroundColor = theme.MinimalShade, + }; + loadFilamentButton.Click += (s, e) => + { + this.DialogWindow.ClosePage(); + + DialogWindow.Show( + new LoadFilamentWizard(printer, extruderIndex, showAlreadyLoadedButton: false)); + }; + + this.AcceptButton = loadFilamentButton; + this.AddPageAction(loadFilamentButton); + } + + public override void OnLoad(EventArgs args) { - this.DialogWindow.ClosePage(); - - DialogWindow.Show( - new LoadFilamentWizard(printer, extruderIndex, showAlreadyLoadedButton: false)); - }; - - this.AcceptButton = loadFilamentButton; - this.AddPageAction(loadFilamentButton); - } - - public override void OnLoad(EventArgs args) - { - this.ShowWizardFinished(); - base.OnLoad(args); + this.ShowWizardFinished(); + base.OnLoad(args); + } } } } diff --git a/MatterControlLib/CustomWidgets/TreeView/TreeNode.cs b/MatterControlLib/CustomWidgets/TreeView/TreeNode.cs index 3ddccecd5..791139c56 100644 --- a/MatterControlLib/CustomWidgets/TreeView/TreeNode.cs +++ b/MatterControlLib/CustomWidgets/TreeView/TreeNode.cs @@ -42,12 +42,12 @@ namespace MatterHackers.MatterControl.CustomWidgets { public class TreeNode : FlowLayoutWidget, ICheckbox { - private GuiWidget content; + private readonly GuiWidget content; private TreeView _treeView; private ImageBuffer _image = null; - private TextWidget textWidget; - private TreeExpandWidget expandWidget; - private ImageWidget imageWidget; + private readonly TextWidget textWidget; + private readonly TreeExpandWidget expandWidget; + private readonly ImageWidget imageWidget; private bool isDirty; public TreeNode(ThemeConfig theme, bool useIcon = true, TreeNode nodeParent = null) @@ -207,11 +207,17 @@ namespace MatterHackers.MatterControl.CustomWidgets // **** Not implemented **** public void BeginEdit() => throw new NotImplementedException(); + public void Collapse(bool collapseChildren) => throw new NotImplementedException(); + public void Collapse() => throw new NotImplementedException(); + public void EndEdit(bool cancel) => throw new NotImplementedException(); + public void EnsureVisible() => throw new NotImplementedException(); + public void ExpandAll() => throw new NotImplementedException(); + public void Remove() => throw new NotImplementedException(); public int GetNodeCount(bool includeSubTrees) @@ -304,8 +310,6 @@ namespace MatterHackers.MatterControl.CustomWidgets return textWidget?.Text ?? ""; } - #region Properties - public bool Checked { get; set; } public bool Editing { get; } @@ -323,6 +327,7 @@ namespace MatterHackers.MatterControl.CustomWidgets } private bool _expanded; + public bool Expanded { get => _expanded; @@ -354,7 +359,7 @@ namespace MatterHackers.MatterControl.CustomWidgets { _image = value; - if(imageWidget != null) + if (imageWidget != null) { imageWidget.Image = _image; } @@ -485,24 +490,18 @@ namespace MatterHackers.MatterControl.CustomWidgets ImageChanged?.Invoke(this, null); } - #endregion Properties - - #region Events - public event EventHandler CheckedStateChanged; public event EventHandler ExpandedChanged; public event EventHandler ImageChanged; - #endregion Events - private class TreeExpandWidget : FlowLayoutWidget { - private ImageBuffer arrowRight; - private ImageBuffer arrowDown; - private ImageBuffer placeholder; - private IconButton imageButton = null; + private readonly ImageBuffer arrowRight; + private readonly ImageBuffer arrowDown; + private readonly ImageBuffer placeholder; + private readonly IconButton imageButton = null; public TreeExpandWidget(ThemeConfig theme) { @@ -514,28 +513,30 @@ namespace MatterHackers.MatterControl.CustomWidgets imageButton = new IconButton(placeholder, theme) { - MinimumSize = new Vector2(16, 16), + MinimumSize = new Vector2(16 * DeviceScale, 16 * DeviceScale), VAnchor = VAnchor.Center, Selectable = false, - Width = 16, - Height = 16 + Width = 16 * DeviceScale, + Height = 16 * DeviceScale }; this.AddChild(imageButton); } private bool _alwaysExpandable; + public bool AlwaysExpandable { get => _alwaysExpandable; set { - imageButton.SetIcon((_expanded) ? arrowDown : arrowRight); + imageButton.SetIcon(_expanded ? arrowDown : arrowRight); _alwaysExpandable = value; } } private bool? _expandable = null; + public bool Expandable { get => _expandable == true || this.AlwaysExpandable; @@ -551,6 +552,7 @@ namespace MatterHackers.MatterControl.CustomWidgets } private bool _expanded; + public bool Expanded { get => _expanded; @@ -579,7 +581,7 @@ namespace MatterHackers.MatterControl.CustomWidgets else { imageButton.Visible = true; - imageButton.SetIcon((_expanded) ? arrowDown : arrowRight); + imageButton.SetIcon(_expanded ? arrowDown : arrowRight); } } diff --git a/MatterControlLib/Library/Widgets/LibraryWidget.cs b/MatterControlLib/Library/Widgets/LibraryWidget.cs index 394aefa47..60983f181 100644 --- a/MatterControlLib/Library/Widgets/LibraryWidget.cs +++ b/MatterControlLib/Library/Widgets/LibraryWidget.cs @@ -482,8 +482,8 @@ namespace MatterHackers.MatterControl.PrintLibrary null, containerItem, null, - 16, - 16, + (int)Math.Round(20 * DeviceScale), + (int)Math.Round(20 * DeviceScale), theme).ConfigureAwait(false); treeNode.ExpandedChanged += (s, e) =>