diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs
index 5e1735776..4fbf407b3 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;
@@ -1309,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())
+ );
+ }
}
}
@@ -2025,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)
@@ -2041,8 +2057,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;
}
@@ -2090,7 +2106,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);
@@ -2123,7 +2139,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);
}
},
@@ -2139,7 +2155,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,
@@ -2154,7 +2170,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;
}
}
}
@@ -2286,7 +2302,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);
@@ -2306,7 +2322,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;
}
@@ -2314,7 +2330,7 @@ If you experience adhesion problems, please re-run leveling."
}
}
- this.ActivePrinter.Connection.CommunicationState = CommunicationStates.Connected;
+ printer.Connection.CommunicationState = CommunicationStates.Connected;
}
}
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());
}
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
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();
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)