From 63997e2f62f74a4031fab279605434d981990bf2 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Sun, 11 Nov 2018 12:46:38 -0800 Subject: [PATCH 1/7] Mark ActivePrinter as obsolete --- MatterControlLib/ApplicationView/ApplicationController.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index 5e1735776..df9d4af40 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -331,6 +331,7 @@ namespace MatterHackers.MatterControl // us down to a single point where code is making assumptions about the presence of a printer, printer counts, etc. If we previously checked for // PrinterConnection.IsPrinterConnected, that could should be updated to iterate ActiverPrinters, checking each one and acting on each as it would // have for the single case + [Obsolete("ActivePrinter references should be migrated to logic than supports multi-printer mode")] public PrinterConfig ActivePrinter { get; private set; } = PrinterConfig.EmptyPrinter; public Action RedeemDesignCode; From 6e7c81bfdbd7484999c8d0c31d60011ae9a86ee8 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Sun, 11 Nov 2018 12:36:15 -0800 Subject: [PATCH 2/7] Use passed in printer references rather than static ActivePrinter --- .../ApplicationView/ApplicationController.cs | 46 +++++++++++-------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index df9d4af40..bc74c5f38 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -1310,15 +1310,25 @@ namespace MatterHackers.MatterControl + "\n" + "Error Reported".Localize() + ":" + $" \"{line}\"."; - UiThread.RunOnIdle(() => - StyledMessageBox.ShowMessageBox((clickedOk) => - { - if (clickedOk && this.ActivePrinter.Connection.PrinterIsPaused) - { - this.ActivePrinter.Connection.Resume(); - } - }, message, "Printer Hardware Error".Localize(), StyledMessageBox.MessageType.YES_NO, "Resume".Localize(), "OK".Localize()) - ); + + if (sender is PrinterConnection printerConnection) + { + UiThread.RunOnIdle(() => + StyledMessageBox.ShowMessageBox( + (clickedOk) => + { + if (clickedOk && printerConnection.PrinterIsPaused) + { + printerConnection.Resume(); + } + }, + message, + "Printer Hardware Error".Localize(), + StyledMessageBox.MessageType.YES_NO, + "Resume".Localize(), + "OK".Localize()) + ); + } } } @@ -2042,8 +2052,8 @@ namespace MatterHackers.MatterControl var printItemName = editContext.SourceItem.Name; // Exit if called in a non-applicable state - if (this.ActivePrinter.Connection.CommunicationState != CommunicationStates.Connected - && this.ActivePrinter.Connection.CommunicationState != CommunicationStates.FinishedPrint) + if (printer.Connection.CommunicationState != CommunicationStates.Connected + && printer.Connection.CommunicationState != CommunicationStates.FinishedPrint) { return; } @@ -2091,7 +2101,7 @@ If you experience adhesion problems, please re-run leveling." } // clear the output cache prior to starting a print - this.ActivePrinter.Connection.TerminalLog.Clear(); + printer.Connection.TerminalLog.Clear(); string hideGCodeWarning = ApplicationSettings.Instance.get(ApplicationSettingsKey.HideGCodeWarning); @@ -2124,7 +2134,7 @@ If you experience adhesion problems, please re-run leveling." { if (messageBoxResponse) { - this.ActivePrinter.Connection.CommunicationState = CommunicationStates.PreparingToPrint; + printer.Connection.CommunicationState = CommunicationStates.PreparingToPrint; this.ArchiveAndStartPrint(partFilePath, gcodeFilePath, printer); } }, @@ -2140,7 +2150,7 @@ If you experience adhesion problems, please re-run leveling." } else { - this.ActivePrinter.Connection.CommunicationState = CommunicationStates.PreparingToPrint; + printer.Connection.CommunicationState = CommunicationStates.PreparingToPrint; (bool slicingSucceeded, string finalPath) = await this.SliceItemLoadOutput( printer, @@ -2155,7 +2165,7 @@ If you experience adhesion problems, please re-run leveling." else { // TODO: Need to reset printing state? This seems like I shouldn't own this indicator - this.ActivePrinter.Connection.CommunicationState = CommunicationStates.Connected; + printer.Connection.CommunicationState = CommunicationStates.Connected; } } } @@ -2287,7 +2297,7 @@ If you experience adhesion problems, please re-run leveling." if (originalIsGCode) { - await this.ActivePrinter.Connection.StartPrint(gcodeFilePath); + await printer.Connection.StartPrint(gcodeFilePath); MonitorPrintTask(printer); @@ -2307,7 +2317,7 @@ If you experience adhesion problems, please re-run leveling." string fileEnd = System.Text.Encoding.UTF8.GetString(buffer); if (fileEnd.Contains("filament used")) { - await this.ActivePrinter.Connection.StartPrint(gcodeFilePath); + await printer.Connection.StartPrint(gcodeFilePath); MonitorPrintTask(printer); return; } @@ -2315,7 +2325,7 @@ If you experience adhesion problems, please re-run leveling." } } - this.ActivePrinter.Connection.CommunicationState = CommunicationStates.Connected; + printer.Connection.CommunicationState = CommunicationStates.Connected; } } From c5cd0b2ebc69f35f5a17842d9ceb65c3297dc03b Mon Sep 17 00:00:00 2001 From: John Lewin Date: Sun, 11 Nov 2018 13:16:32 -0800 Subject: [PATCH 3/7] Add AnyPrintTaskRunning helper property --- MatterControlLib/ApplicationView/ApplicationController.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index bc74c5f38..4fbf407b3 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -2036,6 +2036,11 @@ namespace MatterHackers.MatterControl public bool PrinterTabSelected { get; set; } = false; + /// + /// Indicates if any ActivePrinter is running a print task, either in paused or printing states + /// + public bool AnyPrintTaskRunning => this.ActivePrinters.Any(p => p.Connection.PrinterIsPrinting || p.Connection.PrinterIsPaused); + public event EventHandler AddPrintersTabRightElement; public void NotifyPrintersTabRightElement(GuiWidget sourceExentionArea) From e2a6c761a4e1cc12de1942737e3ca377c631975a Mon Sep 17 00:00:00 2001 From: John Lewin Date: Sun, 11 Nov 2018 13:22:32 -0800 Subject: [PATCH 4/7] Require and use printer reference rather than static ActivePrinter --- .../SlicerConfiguration/SliceSettingsWidget.cs | 2 +- .../SlicerConfiguration/UIFields/DropMenuWrappedField.cs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/MatterControlLib/SlicerConfiguration/SliceSettingsWidget.cs b/MatterControlLib/SlicerConfiguration/SliceSettingsWidget.cs index a53a34814..5575a1f4e 100644 --- a/MatterControlLib/SlicerConfiguration/SliceSettingsWidget.cs +++ b/MatterControlLib/SlicerConfiguration/SliceSettingsWidget.cs @@ -808,7 +808,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration if (settingData.QuickMenuSettings.Count > 0 && settingData.SlicerConfigName == "baud_rate") { - var dropMenu = new DropMenuWrappedField(uiField, settingData, theme.TextColor, theme); + var dropMenu = new DropMenuWrappedField(uiField, settingData, theme.TextColor, theme, printer); dropMenu.Initialize(tabIndexForItem); settingsRow.AddContent(dropMenu.Content); diff --git a/MatterControlLib/SlicerConfiguration/UIFields/DropMenuWrappedField.cs b/MatterControlLib/SlicerConfiguration/UIFields/DropMenuWrappedField.cs index 829be4ee5..f702f9acf 100644 --- a/MatterControlLib/SlicerConfiguration/UIFields/DropMenuWrappedField.cs +++ b/MatterControlLib/SlicerConfiguration/UIFields/DropMenuWrappedField.cs @@ -38,10 +38,12 @@ namespace MatterHackers.MatterControl.SlicerConfiguration private UIField uiField; private Color textColor; private ThemeConfig theme; + private PrinterConfig printer; private SliceSettingData settingData; - public DropMenuWrappedField(UIField uiField, SliceSettingData settingData, Color textColor, ThemeConfig theme) + public DropMenuWrappedField(UIField uiField, SliceSettingData settingData, Color textColor, ThemeConfig theme, PrinterConfig printer) { + this.printer = printer; this.settingData = settingData; this.uiField = uiField; this.textColor = textColor; @@ -98,8 +100,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration if (e is StringEventArgs stringArgs && stringArgs.Data == settingData.SlicerConfigName) { - var activePrinter = ApplicationController.Instance.ActivePrinter; - string newSliceSettingValue = activePrinter.Settings.GetValue(settingData.SlicerConfigName); + string newSliceSettingValue = printer.Settings.GetValue(settingData.SlicerConfigName); bool foundSetting = false; foreach (QuickMenuNameValue nameValue in settingData.QuickMenuSettings) From 4f683d490a3467d5e058a50509bd657d51b6e475 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Sun, 11 Nov 2018 13:45:33 -0800 Subject: [PATCH 5/7] Remove dead code --- MatterControlLib/Queue/QueueData.cs | 71 ----------------------------- 1 file changed, 71 deletions(-) diff --git a/MatterControlLib/Queue/QueueData.cs b/MatterControlLib/Queue/QueueData.cs index 29a89fb4a..39f70afa6 100644 --- a/MatterControlLib/Queue/QueueData.cs +++ b/MatterControlLib/Queue/QueueData.cs @@ -128,77 +128,6 @@ namespace MatterHackers.MatterControl.PrintQueue return PrintItems[itemIndex].Name; } - private bool gotBeginFileList = false; - - private EventHandler unregisterEvents; - - public void LoadFilesFromSD() - { - if (ApplicationController.Instance.ActivePrinter.Connection.IsConnected - && !(ApplicationController.Instance.ActivePrinter.Connection.PrinterIsPrinting - || ApplicationController.Instance.ActivePrinter.Connection.PrinterIsPaused)) - { - gotBeginFileList = false; - ApplicationController.Instance.ActivePrinter.Connection.LineReceived += GetSdCardList; - StringBuilder commands = new StringBuilder(); - commands.AppendLine("M21"); // Init SD card - commands.AppendLine("M20"); // List SD card - ApplicationController.Instance.ActivePrinter.Connection.QueueLine(commands.ToString()); - } - } - - private void GetSdCardList(object sender, string line) - { - if (line != null) - { - if (!line.StartsWith("echo:")) - { - switch (line) - { - case "Begin file list": - gotBeginFileList = true; - break; - - default: - if (gotBeginFileList) - { - bool sdCardItemInQueue = false; - bool validSdCardItem = false; - - foreach (PrintItem item in CreateReadOnlyPartList(false)) - { - if (item.FileLocation == QueueData.SdCardFileName - && item.Name == line) - { - sdCardItemInQueue = true; - break; - } - } - - string sdCardFileExtension = line.ToUpper(); - - if (sdCardFileExtension.Contains(".GCO") - || sdCardFileExtension.Contains(".GCODE")) - { - validSdCardItem = true; - } - - if (!sdCardItemInQueue && validSdCardItem) - { - // If there is not already an sd card item in the queue with this name then add it. - AddItem(new PrintItemWrapper(new PrintItem(line, QueueData.SdCardFileName))); - } - } - break; - - case "End file list": - ApplicationController.Instance.ActivePrinter.Connection.LineReceived -= GetSdCardList; - break; - } - } - } - } - public List CreateReadOnlyPartList(bool includeProtectedItems) { List listToReturn = new List(); From 90a219e89b859e729460c581bf6615f9963d44bf Mon Sep 17 00:00:00 2001 From: John Lewin Date: Sun, 11 Nov 2018 13:45:48 -0800 Subject: [PATCH 6/7] Use AnyPrintTaskRunning helper --- .../Library/ContentProviders/MeshContentProvider.cs | 2 +- .../Library/Widgets/HardwarePage/PrinterDetails.cs | 3 +-- MatterControlLib/Library/Widgets/InventoryTreeView.cs | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/MatterControlLib/Library/ContentProviders/MeshContentProvider.cs b/MatterControlLib/Library/ContentProviders/MeshContentProvider.cs index 802323059..28d8f8bf2 100644 --- a/MatterControlLib/Library/ContentProviders/MeshContentProvider.cs +++ b/MatterControlLib/Library/ContentProviders/MeshContentProvider.cs @@ -171,7 +171,7 @@ namespace MatterHackers.MatterControl RenderOrthographic ? RenderType.ORTHOGROPHIC : RenderType.RAY_TRACE, width, height, - allowMultiThreading: !ApplicationController.Instance.ActivePrinter.Connection.PrinterIsPrinting); + allowMultiThreading: !ApplicationController.Instance.AnyPrintTaskRunning); } public ImageBuffer DefaultImage { get; } = AggContext.StaticData.LoadIcon("mesh.png"); diff --git a/MatterControlLib/Library/Widgets/HardwarePage/PrinterDetails.cs b/MatterControlLib/Library/Widgets/HardwarePage/PrinterDetails.cs index d5838ae0b..92bff15f2 100644 --- a/MatterControlLib/Library/Widgets/HardwarePage/PrinterDetails.cs +++ b/MatterControlLib/Library/Widgets/HardwarePage/PrinterDetails.cs @@ -260,8 +260,7 @@ namespace MatterHackers.MatterControl.Library.Widgets.HardwarePage else { // TODO: when this opens a new tab we will not need to check any printer - if (activePrinter.Connection.PrinterIsPrinting - || activePrinter.Connection.PrinterIsPaused) + if (ApplicationController.Instance.AnyPrintTaskRunning) { // TODO: Rather than block here, the UI elements driving the change should be disabled while printing/paused UiThread.RunOnIdle(() => diff --git a/MatterControlLib/Library/Widgets/InventoryTreeView.cs b/MatterControlLib/Library/Widgets/InventoryTreeView.cs index 540006a1e..6704b0061 100644 --- a/MatterControlLib/Library/Widgets/InventoryTreeView.cs +++ b/MatterControlLib/Library/Widgets/InventoryTreeView.cs @@ -86,8 +86,7 @@ namespace MatterHackers.MatterControl.PrintLibrary createPrinter.Click += (s, e) => UiThread.RunOnIdle(() => { - if (ApplicationController.Instance.ActivePrinter.Connection.PrinterIsPrinting - || ApplicationController.Instance.ActivePrinter.Connection.PrinterIsPaused) + if (ApplicationController.Instance.AnyPrintTaskRunning) { StyledMessageBox.ShowMessageBox("Please wait until the print has finished and try again.".Localize(), "Can't add printers while printing".Localize()); } From f3a8824ecf365a32150b0237545fa4c948c383c5 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Sun, 11 Nov 2018 13:52:31 -0800 Subject: [PATCH 7/7] Demand printer dependency in constructor --- MatterControlLib/PartPreviewWindow/GCode3DWidget.cs | 2 +- MatterControlLib/PartPreviewWindow/SpeedsLegend.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/MatterControlLib/PartPreviewWindow/GCode3DWidget.cs b/MatterControlLib/PartPreviewWindow/GCode3DWidget.cs index 7fb8b3595..2f4e1715a 100644 --- a/MatterControlLib/PartPreviewWindow/GCode3DWidget.cs +++ b/MatterControlLib/PartPreviewWindow/GCode3DWidget.cs @@ -121,7 +121,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow loadedGCodeSection.AddChild( speedsWidget = new SectionWidget( "Speeds".Localize(), - new SpeedsLegend(sceneContext.LoadedGCode, theme) + new SpeedsLegend(sceneContext.LoadedGCode, theme, printer) { HAnchor = HAnchor.Stretch, Visible = renderSpeeds, diff --git a/MatterControlLib/PartPreviewWindow/SpeedsLegend.cs b/MatterControlLib/PartPreviewWindow/SpeedsLegend.cs index c3bafbfec..838d5f7e6 100644 --- a/MatterControlLib/PartPreviewWindow/SpeedsLegend.cs +++ b/MatterControlLib/PartPreviewWindow/SpeedsLegend.cs @@ -39,7 +39,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { public class SpeedsLegend : FlowLayoutWidget { - public SpeedsLegend(GCodeFile gcodeFileTest, ThemeConfig theme) + public SpeedsLegend(GCodeFile gcodeFileTest, ThemeConfig theme, PrinterConfig printer) : base(FlowDirection.TopToBottom) { GCodeMemoryFile memoryFile = gcodeFileTest as GCodeMemoryFile; @@ -49,7 +49,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow return; } - GCodeRenderer renderer = ApplicationController.Instance.ActivePrinter.Bed.GCodeRenderer; + GCodeRenderer renderer = printer.Bed.GCodeRenderer; if (renderer == null) { // Renderer did not load for content and speeds should not be rendered