From 8de283dbfe083064bcc77fb5bcec6ac70af8249f Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Wed, 5 Dec 2018 13:48:25 -0800 Subject: [PATCH] Say who is the owner of executing tasks. This allows us to filter running tasks displays issue: MatterHackers/MCCentral#4660 Not printing printer tab showing print progress from printing printer tab --- .../ApplicationView/ApplicationController.cs | 17 ++++-- MatterControlLib/ApplicationView/BedConfig.cs | 2 +- .../ApplicationView/PrinterConfig.cs | 2 + .../CustomWidgets/ExportPrintItemPage.cs | 2 + .../DesignTools/LithophaneObject3D.cs | 2 +- .../Operations/Image/ImageToPathObject3D.cs | 1 + .../Library/Export/GCodeExport.cs | 3 +- .../PartPreviewWindow/PrinterTabPage.cs | 4 +- .../PartPreviewWindow/RunningTasksWidget.cs | 29 +++++++--- .../View3D/Actions/CombineObject3D.cs | 1 + .../View3D/Actions/IntersectionObject3D.cs | 2 +- .../Actions/SubtractAndReplaceObject3D.cs | 2 +- .../View3D/Actions/SubtractObject3D.cs | 1 + .../View3D/PrinterBar/PrintPopupMenu.cs | 2 +- .../View3D/PrinterBar/SliceButton.cs | 2 +- .../PartPreviewWindow/View3D/SceneActions.cs | 1 + .../PartPreviewWindow/View3D/View3DWidget.cs | 10 ++-- .../PartPreviewWindow/ViewControls3D.cs | 6 +- .../PrinterCommunication/PrinterConnection.cs | 57 +++++++++---------- MatterControlLib/RootSystemWindow.cs | 4 +- 20 files changed, 87 insertions(+), 63 deletions(-) diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index 6ec98be59..381bcf62a 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -1345,7 +1345,7 @@ namespace MatterHackers.MatterControl if (printerConnection.AnyHeatIsOn) { var paused = false; - Tasks.Execute("", (reporter, cancellationToken) => + Tasks.Execute("", printerConnection.Printer, (reporter, cancellationToken) => { var progressStatus = new ProgressStatus(); @@ -2190,6 +2190,7 @@ If you experience adhesion problems, please re-run leveling." this.Tasks.Execute( "Printing".Localize(), + printer, (reporterB, cancellationTokenB) => { var progressStatus = new ProgressStatus(); @@ -2324,7 +2325,7 @@ If you experience adhesion problems, please re-run leveling." // Slice bool slicingSucceeded = false; - await this.Tasks.Execute("Slicing".Localize(), async (reporter, cancellationToken) => + await this.Tasks.Execute("Slicing".Localize(), printer, async (reporter, cancellationToken) => { slicingSucceeded = await Slicer.SliceItem( object3D, @@ -2368,7 +2369,7 @@ If you experience adhesion problems, please re-run leveling." } } - await this.Tasks.Execute("Loading GCode".Localize(), (innerProgress, token) => + await this.Tasks.Execute("Loading GCode".Localize(), printer, (innerProgress, token) => { var status = new ProgressStatus(); @@ -2556,6 +2557,7 @@ If you experience adhesion problems, please re-run leveling." } public string Title { get; set; } + public object Owner { get; set; } public RunningTaskOptions Options { get; internal set; } @@ -2649,14 +2651,15 @@ If you experience adhesion problems, please re-run leveling." }; } - public Task Execute(string taskTitle, Func, CancellationToken, Task> func, RunningTaskOptions taskActions = null) + public Task Execute(string taskTitle, object owner, Func, CancellationToken, Task> func, RunningTaskOptions taskActions = null) { var tokenSource = new CancellationTokenSource(); var taskDetails = new RunningTaskDetails(tokenSource) { Options = taskActions, - Title = taskTitle + Title = taskTitle, + Owner = owner, }; executingTasks.Add(taskDetails); @@ -3151,6 +3154,7 @@ If you experience adhesion problems, please re-run leveling." // Batch startup actions await applicationController.Tasks.Execute( "Finishing Startup".Localize(), + null, (progress, cancellationToken) => { var status = new ProgressStatus(); @@ -3174,6 +3178,7 @@ If you experience adhesion problems, please re-run leveling." await applicationController.Tasks.Execute( "Restoring Printers".Localize(), + null, async (progress, cancellationToken) => { await applicationController.OpenAllPrinters(); @@ -3182,7 +3187,7 @@ If you experience adhesion problems, please re-run leveling." // Batch startup tasks foreach (var task in ApplicationController.StartupTasks.OrderByDescending(t => t.Priority)) { - await applicationController.Tasks.Execute(task.Title, task.Action); + await applicationController.Tasks.Execute(task.Title, null, task.Action); } if (ApplicationSettings.Instance.get(ApplicationSettingsKey.ShownWelcomeMessage) != "false") diff --git a/MatterControlLib/ApplicationView/BedConfig.cs b/MatterControlLib/ApplicationView/BedConfig.cs index 52fc528f4..71433acae 100644 --- a/MatterControlLib/ApplicationView/BedConfig.cs +++ b/MatterControlLib/ApplicationView/BedConfig.cs @@ -153,7 +153,7 @@ namespace MatterHackers.MatterControl public async Task LoadGCodeContent(Stream stream) { - await ApplicationController.Instance.Tasks.Execute("Loading G-Code".Localize(), (reporter, cancellationToken) => + await ApplicationController.Instance.Tasks.Execute("Loading G-Code".Localize(), Printer, (reporter, cancellationToken) => { var progressStatus = new ProgressStatus(); reporter.Report(progressStatus); diff --git a/MatterControlLib/ApplicationView/PrinterConfig.cs b/MatterControlLib/ApplicationView/PrinterConfig.cs index 43ae12fff..6691bb0d3 100644 --- a/MatterControlLib/ApplicationView/PrinterConfig.cs +++ b/MatterControlLib/ApplicationView/PrinterConfig.cs @@ -306,6 +306,7 @@ namespace MatterHackers.MatterControl case DetailedPrintingState.HeatingBed: ApplicationController.Instance.Tasks.Execute( "Heating Bed".Localize(), + this, (reporter, cancellationToken) => { waitingForBedHeat = true; @@ -335,6 +336,7 @@ namespace MatterHackers.MatterControl case DetailedPrintingState.HeatingExtruder: ApplicationController.Instance.Tasks.Execute( "Heating Extruder".Localize(), + this, (reporter, cancellationToken) => { waitingForBedHeat = false; diff --git a/MatterControlLib/CustomWidgets/ExportPrintItemPage.cs b/MatterControlLib/CustomWidgets/ExportPrintItemPage.cs index 2c8befdb2..24e398366 100644 --- a/MatterControlLib/CustomWidgets/ExportPrintItemPage.cs +++ b/MatterControlLib/CustomWidgets/ExportPrintItemPage.cs @@ -183,6 +183,7 @@ namespace MatterHackers.MatterControl { ApplicationController.Instance.Tasks.Execute( "Saving".Localize() + "...", + printer, async (reporter, cancellationToken) => { string path = openParams.FolderPath; @@ -216,6 +217,7 @@ namespace MatterHackers.MatterControl { ApplicationController.Instance.Tasks.Execute( "Exporting".Localize() + "...", + printer, async (reporter, cancellationToken) => { string extension = Path.GetExtension(savePath); diff --git a/MatterControlLib/DesignTools/LithophaneObject3D.cs b/MatterControlLib/DesignTools/LithophaneObject3D.cs index 7bad48b9c..ba975c51f 100644 --- a/MatterControlLib/DesignTools/LithophaneObject3D.cs +++ b/MatterControlLib/DesignTools/LithophaneObject3D.cs @@ -91,7 +91,7 @@ namespace MatterHackers.MatterControl.Plugins.Lithophane this.DebugDepth("Rebuild"); var activeImage = AggContext.ImageIO.LoadImage(this.Image.AssetPath); - ApplicationController.Instance.Tasks.Execute("Generating Lithophane".Localize(), (reporter, cancellationToken) => + ApplicationController.Instance.Tasks.Execute("Generating Lithophane".Localize(), null, (reporter, cancellationToken) => { var generatedMesh = Lithophane.Generate( new Lithophane.ImageBufferImageData(activeImage, this.Width), diff --git a/MatterControlLib/DesignTools/Operations/Image/ImageToPathObject3D.cs b/MatterControlLib/DesignTools/Operations/Image/ImageToPathObject3D.cs index 57fcfbeb8..4682535fe 100644 --- a/MatterControlLib/DesignTools/Operations/Image/ImageToPathObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/Image/ImageToPathObject3D.cs @@ -365,6 +365,7 @@ namespace MatterHackers.MatterControl.DesignTools // now create a long running task to process the image ApplicationController.Instance.Tasks.Execute( "Calculate Path".Localize(), + null, (reporter, cancellationToken) => { var progressStatus = new ProgressStatus(); diff --git a/MatterControlLib/Library/Export/GCodeExport.cs b/MatterControlLib/Library/Export/GCodeExport.cs index 35fd3711e..00267d382 100644 --- a/MatterControlLib/Library/Export/GCodeExport.cs +++ b/MatterControlLib/Library/Export/GCodeExport.cs @@ -152,7 +152,7 @@ namespace MatterHackers.MatterControl.Library.Export else if (firstItem.AssetPath == printer.Bed.EditContext.SourceFilePath) { // If item is bedplate, save any pending changes before starting the print - await ApplicationController.Instance.Tasks.Execute("Saving".Localize(), printer.Bed.SaveChanges); + await ApplicationController.Instance.Tasks.Execute("Saving".Localize(), printer, printer.Bed.SaveChanges); loadedItem = printer.Bed.Scene; CenterOnBed = false; } @@ -212,6 +212,7 @@ namespace MatterHackers.MatterControl.Library.Export await ApplicationController.Instance.Tasks.Execute( "Slicing Item".Localize() + " " + loadedItem.Name, + printer, (reporter, cancellationToken2) => { return Slicer.SliceItem(loadedItem, gcodePath, printer, reporter, cancellationToken2); diff --git a/MatterControlLib/PartPreviewWindow/PrinterTabPage.cs b/MatterControlLib/PartPreviewWindow/PrinterTabPage.cs index 2cc618c4e..d37107a05 100644 --- a/MatterControlLib/PartPreviewWindow/PrinterTabPage.cs +++ b/MatterControlLib/PartPreviewWindow/PrinterTabPage.cs @@ -189,7 +189,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow splitContainer.AddChild(gcodeContainer); - view3DContainer.AddChild(new RunningTasksWidget(theme) + view3DContainer.AddChild(new RunningTasksWidget(theme, printer) { MinimumSize = new Vector2(100, 0), Margin = new BorderDouble(top: printerActionsBar.Height + 1, left: favoritesBar.LocalBounds.Width + favoritesBar.DeviceMarginAndBorder.Width + 1), @@ -550,7 +550,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow bottomRow.Name = printer.Bed.EditContext.GCodeFilePath(printer); } - await ApplicationController.Instance.Tasks.Execute("Saving".Localize(), printer.Bed.SaveChanges); + await ApplicationController.Instance.Tasks.Execute("Saving".Localize(), printer, printer.Bed.SaveChanges); // start up a new slice on a background thread await ApplicationController.Instance.SliceItemLoadOutput( diff --git a/MatterControlLib/PartPreviewWindow/RunningTasksWidget.cs b/MatterControlLib/PartPreviewWindow/RunningTasksWidget.cs index 367966474..8fc92bdf9 100644 --- a/MatterControlLib/PartPreviewWindow/RunningTasksWidget.cs +++ b/MatterControlLib/PartPreviewWindow/RunningTasksWidget.cs @@ -40,9 +40,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow private ThemeConfig theme; private Color borderColor; private FlowLayoutWidget pendingTasksList; + private object owner; - public RunningTasksWidget(ThemeConfig theme) + public RunningTasksWidget(ThemeConfig theme, object owner) { + this.owner = owner; this.theme = theme; if (theme.IsDarkTheme) @@ -95,16 +97,25 @@ namespace MatterHackers.MatterControl.PartPreviewWindow // Add new items foreach (var taskItem in tasks.RunningTasks.Where(t => !displayedTasks.Contains(t))) { - var taskRow = new RunningTaskRow("", taskItem, theme) + // show tasks that are unfiltered (owner == null) or are owned by us + if (taskItem.Owner == null + || taskItem.Owner == owner) { - HAnchor = HAnchor.Stretch, - BackgroundColor = theme.AccentMimimalOverlay, - Border = new BorderDouble(1, 1, 1, 0), - BorderColor = borderColor, - ProgressBackgroundColor = progressBackgroundColor - }; + var taskRow = new RunningTaskRow("", taskItem, theme) + { + HAnchor = HAnchor.Stretch, + BackgroundColor = theme.AccentMimimalOverlay, + Border = new BorderDouble(1, 1, 1, 0), + BorderColor = borderColor, + ProgressBackgroundColor = progressBackgroundColor + }; - pendingTasksList.AddChild(taskRow); + pendingTasksList.AddChild(taskRow); + } + else + { + int a = 0; + } } this.Visible = pendingTasksList.Children.Count > 0; diff --git a/MatterControlLib/PartPreviewWindow/View3D/Actions/CombineObject3D.cs b/MatterControlLib/PartPreviewWindow/View3D/Actions/CombineObject3D.cs index 9e52ed436..c0c659f15 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Actions/CombineObject3D.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Actions/CombineObject3D.cs @@ -77,6 +77,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D // spin up a task to remove holes from the objects in the group ApplicationController.Instance.Tasks.Execute( "Combine".Localize(), + null, (reporter, cancellationToken) => { var progressStatus = new ProgressStatus(); diff --git a/MatterControlLib/PartPreviewWindow/View3D/Actions/IntersectionObject3D.cs b/MatterControlLib/PartPreviewWindow/View3D/Actions/IntersectionObject3D.cs index deb11c073..9a2a32325 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Actions/IntersectionObject3D.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Actions/IntersectionObject3D.cs @@ -74,7 +74,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D var rebuildLock = RebuildLock(); ResetMeshWrapperMeshes(Object3DPropertyFlags.All, CancellationToken.None); - ApplicationController.Instance.Tasks.Execute("Intersection".Localize(), (reporter, cancellationToken) => + ApplicationController.Instance.Tasks.Execute("Intersection".Localize(), null, (reporter, cancellationToken) => { var progressStatus = new ProgressStatus(); diff --git a/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractAndReplaceObject3D.cs b/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractAndReplaceObject3D.cs index c6c12182b..1a5b6267d 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractAndReplaceObject3D.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractAndReplaceObject3D.cs @@ -81,7 +81,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D ResetMeshWrapperMeshes(Object3DPropertyFlags.All, CancellationToken.None); // spin up a task to calculate the paint - ApplicationController.Instance.Tasks.Execute("Subtract".Localize(), (reporter, cancellationToken) => + ApplicationController.Instance.Tasks.Execute("Subtract".Localize(), null, (reporter, cancellationToken) => { var progressStatus = new ProgressStatus(); diff --git a/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractObject3D.cs b/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractObject3D.cs index 6922cd906..2abe63fc0 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractObject3D.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractObject3D.cs @@ -297,6 +297,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D // spin up a task to remove holes from the objects in the group ApplicationController.Instance.Tasks.Execute( "Subtract".Localize(), + null, (reporter, cancellationToken) => { var progressStatus = new ProgressStatus(); diff --git a/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrintPopupMenu.cs b/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrintPopupMenu.cs index cf1822ab0..5603058fa 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrintPopupMenu.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrintPopupMenu.cs @@ -191,7 +191,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow UiThread.RunOnIdle(async () => { // Save any pending changes before starting print operation - await ApplicationController.Instance.Tasks.Execute("Saving Changes".Localize(), printer.Bed.SaveChanges); + await ApplicationController.Instance.Tasks.Execute("Saving Changes".Localize(), printer, printer.Bed.SaveChanges); await ApplicationController.Instance.PrintPart( printer.Bed.EditContext, diff --git a/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/SliceButton.cs b/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/SliceButton.cs index 42b0ae951..df1cc956c 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/SliceButton.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/SliceButton.cs @@ -107,7 +107,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow try { - await ApplicationController.Instance.Tasks.Execute("Saving".Localize(), printer.Bed.SaveChanges); + await ApplicationController.Instance.Tasks.Execute("Saving".Localize(), printer, printer.Bed.SaveChanges); await ApplicationController.Instance.SliceItemLoadOutput( printer, diff --git a/MatterControlLib/PartPreviewWindow/View3D/SceneActions.cs b/MatterControlLib/PartPreviewWindow/View3D/SceneActions.cs index 3be9395f1..fe33b42ab 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/SceneActions.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/SceneActions.cs @@ -87,6 +87,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { await ApplicationController.Instance.Tasks.Execute( "Ungroup".Localize(), + null, (reporter, cancellationToken) => { var progressStatus = new ProgressStatus(); diff --git a/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs b/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs index 54d4b4c91..1ad1be730 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs @@ -539,7 +539,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow Shortcut = "Ctrl+S", Action = () => { - ApplicationController.Instance.Tasks.Execute("Saving".Localize(), sceneContext.SaveChanges).ConfigureAwait(false); + ApplicationController.Instance.Tasks.Execute("Saving".Localize(), printer, sceneContext.SaveChanges).ConfigureAwait(false); }, IsEnabled = () => sceneContext.EditableScene } @@ -660,7 +660,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow if (this.Printer != null) { // Save any pending changes before starting print operation - ApplicationController.Instance.Tasks.Execute("Saving Changes".Localize(), printer.Bed.SaveChanges).ContinueWith(task => + ApplicationController.Instance.Tasks.Execute("Saving Changes".Localize(), printer, printer.Bed.SaveChanges).ContinueWith(task => { ApplicationController.Instance.PrintPart( printer.Bed.EditContext, @@ -735,7 +735,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { Task.Run(async () => { - await ApplicationController.Instance.Tasks.Execute("Saving".Localize(), sceneContext.SaveChanges); + await ApplicationController.Instance.Tasks.Execute("Saving".Localize(), printer, sceneContext.SaveChanges); // Clear bed to get new MCX on disk for this item printer.Bed.ClearPlate(); @@ -778,7 +778,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow ApplicationController.Instance.MainView.TabControl.SelectedTabKey = printer.Settings.GetValue(SettingsKey.printer_name); // Save any pending changes before starting print operation - await ApplicationController.Instance.Tasks.Execute("Saving Changes".Localize(), printer.Bed.SaveChanges); + await ApplicationController.Instance.Tasks.Execute("Saving Changes".Localize(), printer, printer.Bed.SaveChanges); // Slice and print await ApplicationController.Instance.PrintPart( @@ -1920,7 +1920,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow public void Save() { - ApplicationController.Instance.Tasks.Execute("Saving".Localize(), sceneContext.SaveChanges); + ApplicationController.Instance.Tasks.Execute("Saving".Localize(), printer, sceneContext.SaveChanges); } } diff --git a/MatterControlLib/PartPreviewWindow/ViewControls3D.cs b/MatterControlLib/PartPreviewWindow/ViewControls3D.cs index 770797bcc..3a2128436 100644 --- a/MatterControlLib/PartPreviewWindow/ViewControls3D.cs +++ b/MatterControlLib/PartPreviewWindow/ViewControls3D.cs @@ -177,7 +177,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { UiThread.RunOnIdle(async () => { - await ApplicationController.Instance.Tasks.Execute("Saving changes".Localize() + "...", sceneContext.SaveChanges); + await ApplicationController.Instance.Tasks.Execute("Saving changes".Localize() + "...", sceneContext.Printer, sceneContext.SaveChanges); await sceneContext.LoadLibraryContent(item); @@ -671,7 +671,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow iconButton.Click += (s, e) => { - ApplicationController.Instance.Tasks.Execute("Saving".Localize(), async(progress, cancellationToken) => + ApplicationController.Instance.Tasks.Execute("Saving".Localize(), sceneContext.Printer, async(progress, cancellationToken) => { saveButton.Enabled = false; @@ -827,7 +827,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow IObject3D object3D = null; - await ApplicationController.Instance.Tasks.Execute("Loading".Localize() + " " + Path.GetFileName(filePath), async (progressReporter, cancellationToken) => + await ApplicationController.Instance.Tasks.Execute("Loading".Localize() + " " + Path.GetFileName(filePath), sceneContext.Printer, async (progressReporter, cancellationToken) => { var progressStatus = new ProgressStatus(); diff --git a/MatterControlLib/PrinterCommunication/PrinterConnection.cs b/MatterControlLib/PrinterCommunication/PrinterConnection.cs index fe295005c..afd6b2bb2 100644 --- a/MatterControlLib/PrinterCommunication/PrinterConnection.cs +++ b/MatterControlLib/PrinterCommunication/PrinterConnection.cs @@ -238,7 +238,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication public PrinterConnection(PrinterConfig printer) { - this.printer = printer; + this.Printer = printer; TerminalLog = new TerminalLog(this); @@ -481,7 +481,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication // Set this early as we always want our functions to know the state we are in. communicationState = value; timeSinceStartedPrint.Stop(); - PrintFinished?.Invoke(this, new NamedItemEventArgs(printer.Bed.EditContext.SourceItem.Name)); + PrintFinished?.Invoke(this, new NamedItemEventArgs(Printer.Bed.EditContext.SourceItem.Name)); } else { @@ -523,9 +523,9 @@ namespace MatterHackers.MatterControl.PrinterCommunication gCodeFileSwitcher0.SwitchTo(gCodeFilePath); } - public string ComPort => printer.Settings?.Helpers.ComPort(); + public string ComPort => Printer.Settings?.Helpers.ComPort(); - public string DriverType => (this.ComPort == "Emulator") ? "Emulator" : printer.Settings?.GetValue("driver_type"); + public string DriverType => (this.ComPort == "Emulator") ? "Emulator" : Printer.Settings?.GetValue("driver_type"); public bool AtxPowerEnabled { @@ -787,8 +787,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication } } - // HACK: PrinterConnection must be revised to take a constructor that receives and stores a reference to its parent PrinterConfig - this - private PrinterConfig printer { get; set; } + public PrinterConfig Printer { get; } public void ReleaseAndReportFailedConnection(ConnectionFailure reason, string details = null) { @@ -882,7 +881,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication var portFactory = FrostedSerialPortFactory.GetAppropriateFactory(this.DriverType); - bool serialPortIsAvailable = portFactory.SerialPortIsAvailable(serialPortName, printer.Settings); + bool serialPortIsAvailable = portFactory.SerialPortIsAvailable(serialPortName, Printer.Settings); bool serialPortIsAlreadyOpen = this.ComPort != "Emulator" && portFactory.SerialPortAlreadyOpen(serialPortName); @@ -892,7 +891,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication { try { - serialPort = portFactory.CreateAndOpen(serialPortName, printer.Settings, baudRate, true); + serialPort = portFactory.CreateAndOpen(serialPortName, Printer.Settings, baudRate, true); #if __ANDROID__ ToggleHighLowHigh(serialPort); #endif @@ -1368,9 +1367,9 @@ namespace MatterHackers.MatterControl.PrinterCommunication { // TODO: Ideally we would shutdown the printer connection when this method is called and we're connected. The // current approach results in unpredictable behavior if the caller fails to close the connection - if (serialPort == null && this.printer.Settings != null) + if (serialPort == null && this.Printer.Settings != null) { - IFrostedSerialPort resetSerialPort = FrostedSerialPortFactory.GetAppropriateFactory(this.DriverType).Create(this.ComPort, printer.Settings); + IFrostedSerialPort resetSerialPort = FrostedSerialPortFactory.GetAppropriateFactory(this.DriverType).Create(this.ComPort, Printer.Settings); resetSerialPort.Open(); Thread.Sleep(500); @@ -1583,7 +1582,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication { try { - if (printer.Settings.PrinterSelected) + if (Printer.Settings.PrinterSelected) { // first make sure we are not printing if possible (cancel slicing) if (serialPort != null) // we still have a serial port @@ -1611,7 +1610,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication { // We reset the board while attempting to connect, so now we don't have a serial port. // Create one and do the DTR to reset - var resetSerialPort = FrostedSerialPortFactory.GetAppropriateFactory(this.DriverType).Create(this.ComPort, printer.Settings); + var resetSerialPort = FrostedSerialPortFactory.GetAppropriateFactory(this.DriverType).Create(this.ComPort, Printer.Settings); resetSerialPort.Open(); Thread.Sleep(500); @@ -1857,7 +1856,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication case CommunicationStates.PreparingToPrint: { - var activePrintItem = printer.Bed.EditContext.printItem; + var activePrintItem = Printer.Bed.EditContext.printItem; if (activePrintItem.PrintItem.Id == 0) { activePrintItem.PrintItem.Commit(); @@ -1869,7 +1868,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication activePrintTask = new PrintTask { PrintStart = DateTime.Now, - PrinterId = this.printer.Settings.ID.GetHashCode(), + PrinterId = this.Printer.Settings.ID.GetHashCode(), PrintName = activePrintItem.PrintItem.Name, PrintItemId = activePrintItem.PrintItem.Id, PrintingGCodeFileName = gcodeFilename, @@ -2084,45 +2083,45 @@ namespace MatterHackers.MatterControl.PrinterCommunication GCodeStream firstStreamToRead = null; if (gcodeFilename != null) { - gCodeFileSwitcher0 = new GCodeSwitcher(gcodeFilename, printer); + gCodeFileSwitcher0 = new GCodeSwitcher(gcodeFilename, Printer); if (this.RecoveryIsEnabled && activePrintTask != null) // We are resuming a failed print (do lots of interesting stuff). { - sendProgressStream1 = new SendProgressStream(new PrintRecoveryStream(gCodeFileSwitcher0, printer, activePrintTask.PercentDone), printer); + sendProgressStream1 = new SendProgressStream(new PrintRecoveryStream(gCodeFileSwitcher0, Printer, activePrintTask.PercentDone), Printer); // And increment the recovery count activePrintTask.RecoveryCount++; activePrintTask.Commit(); } else { - sendProgressStream1 = new SendProgressStream(gCodeFileSwitcher0, printer); + sendProgressStream1 = new SendProgressStream(gCodeFileSwitcher0, Printer); } - pauseHandlingStream2 = new PauseHandlingStream(printer, sendProgressStream1); + pauseHandlingStream2 = new PauseHandlingStream(Printer, sendProgressStream1); firstStreamToRead = pauseHandlingStream2; } else { gCodeFileSwitcher0 = null; - firstStreamToRead = new NotPrintingStream(printer); + firstStreamToRead = new NotPrintingStream(Printer); } - queuedCommandStream3 = new QueuedCommandsStream(printer, firstStreamToRead); - relativeToAbsoluteStream4 = new RelativeToAbsoluteStream(printer, queuedCommandStream3); - bool enableLineSpliting = gcodeFilename != null && printer.Settings.GetValue(SettingsKey.enable_line_splitting); - babyStepsStream5 = new BabyStepsStream(printer, relativeToAbsoluteStream4, enableLineSpliting ? 1 : 2000); + queuedCommandStream3 = new QueuedCommandsStream(Printer, firstStreamToRead); + relativeToAbsoluteStream4 = new RelativeToAbsoluteStream(Printer, queuedCommandStream3); + bool enableLineSpliting = gcodeFilename != null && Printer.Settings.GetValue(SettingsKey.enable_line_splitting); + babyStepsStream5 = new BabyStepsStream(Printer, relativeToAbsoluteStream4, enableLineSpliting ? 1 : 2000); if (activePrintTask != null) { // make sure we are in the position we were when we stopped printing babyStepsStream5.Offset = new Vector3(activePrintTask.PrintingOffsetX, activePrintTask.PrintingOffsetY, activePrintTask.PrintingOffsetZ); } - printLevelingStream6 = new PrintLevelingStream(printer, babyStepsStream5, true); - waitForTempStream7 = new WaitForTempStream(printer, printLevelingStream6); - extrusionMultiplyerStream8 = new ExtrusionMultiplyerStream(printer, waitForTempStream7); - feedrateMultiplyerStream9 = new FeedRateMultiplyerStream(printer, extrusionMultiplyerStream8); - requestTemperaturesStream10 = new RequestTemperaturesStream(printer, feedrateMultiplyerStream9); - processWriteRegExStream11 = new ProcessWriteRegexStream(printer, requestTemperaturesStream10, queuedCommandStream3); + printLevelingStream6 = new PrintLevelingStream(Printer, babyStepsStream5, true); + waitForTempStream7 = new WaitForTempStream(Printer, printLevelingStream6); + extrusionMultiplyerStream8 = new ExtrusionMultiplyerStream(Printer, waitForTempStream7); + feedrateMultiplyerStream9 = new FeedRateMultiplyerStream(Printer, extrusionMultiplyerStream8); + requestTemperaturesStream10 = new RequestTemperaturesStream(Printer, feedrateMultiplyerStream9); + processWriteRegExStream11 = new ProcessWriteRegexStream(Printer, requestTemperaturesStream10, queuedCommandStream3); totalGCodeStream = processWriteRegExStream11; // Force a reset of the printer checksum state (but allow it to be write regexed) diff --git a/MatterControlLib/RootSystemWindow.cs b/MatterControlLib/RootSystemWindow.cs index 73de34afd..167bf3a17 100644 --- a/MatterControlLib/RootSystemWindow.cs +++ b/MatterControlLib/RootSystemWindow.cs @@ -308,13 +308,13 @@ namespace MatterHackers.MatterControl { if (printer != PrinterConfig.EmptyPrinter) { - await application.Tasks.Execute("Saving Print Bed".Localize() + "...", printer.Bed.SaveChanges); + await application.Tasks.Execute("Saving Print Bed".Localize() + "...", printer, printer.Bed.SaveChanges); } } foreach (var workspace in application.Workspaces) { - await application.Tasks.Execute("Saving Print Bed".Localize() + "...", workspace.SceneContext.SaveChanges); + await application.Tasks.Execute("Saving Print Bed".Localize() + "...", workspace, workspace.SceneContext.SaveChanges); } application.ApplicationExiting = true;