Merge pull request #3981 from jlewin/master
Reduce ActivePrinter references
This commit is contained in:
commit
e0b7ed128d
9 changed files with 45 additions and 101 deletions
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if any ActivePrinter is running a print task, either in paused or printing states
|
||||
/// </summary>
|
||||
public bool AnyPrintTaskRunning => this.ActivePrinters.Any(p => p.Connection.PrinterIsPrinting || p.Connection.PrinterIsPaused);
|
||||
|
||||
public event EventHandler<WidgetSourceEventArgs> 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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(() =>
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<PrintItem> CreateReadOnlyPartList(bool includeProtectedItems)
|
||||
{
|
||||
List<PrintItem> listToReturn = new List<PrintItem>();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue