Merge pull request #2765 from jlewin/design_tools
Enable pause/resume on task, remove pause/resume/cancel from bar
This commit is contained in:
commit
bfccd707fb
8 changed files with 77 additions and 84 deletions
|
|
@ -43,6 +43,8 @@ using MatterHackers.MatterControl.SlicerConfiguration;
|
|||
using Newtonsoft.Json;
|
||||
using MatterHackers.MatterControl.Library;
|
||||
using System.Collections.ObjectModel;
|
||||
using MatterHackers.MatterControl;
|
||||
using System.Threading;
|
||||
|
||||
namespace MatterHackers.MatterControl
|
||||
{
|
||||
|
|
@ -1218,7 +1220,7 @@ namespace MatterHackers.MatterControl
|
|||
Thread.Sleep(200);
|
||||
}
|
||||
|
||||
while (printer.Connection.PrinterIsPrinting
|
||||
while ((printer.Connection.PrinterIsPrinting || printer.Connection.PrinterIsPaused)
|
||||
&& !cancellationTokenB.IsCancellationRequested)
|
||||
{
|
||||
//progressStatus.Status = $"{printing} Layer ({printer.Connection.CurrentlyPrintingLayer } of {totalLayers})";
|
||||
|
|
@ -1229,7 +1231,22 @@ namespace MatterHackers.MatterControl
|
|||
}
|
||||
});
|
||||
},
|
||||
extraInfo: () => PrinterTabPage.PrintProgressWidget(printer));
|
||||
taskActions: new RunningTaskActions()
|
||||
{
|
||||
RichProgressWidget = () => PrinterTabPage.PrintProgressWidget(printer),
|
||||
Pause = () => UiThread.RunOnIdle(() =>
|
||||
{
|
||||
printer.Connection.RequestPause();
|
||||
}),
|
||||
Resume = () => UiThread.RunOnIdle(() =>
|
||||
{
|
||||
printer.Connection.Resume();
|
||||
}),
|
||||
Stop = () => UiThread.RunOnIdle(() =>
|
||||
{
|
||||
ApplicationController.Instance.ConditionalCancelPrint();
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1373,7 +1390,7 @@ namespace MatterHackers.MatterControl
|
|||
{
|
||||
public event EventHandler<ProgressStatus> ProgressChanged;
|
||||
|
||||
public Func<GuiWidget> ExtraInfo { get; set; }
|
||||
public Func<GuiWidget> DetailsItemAction { get; set; }
|
||||
|
||||
public RunningTaskDetails(CancellationTokenSource tokenSource)
|
||||
{
|
||||
|
|
@ -1381,6 +1398,10 @@ namespace MatterHackers.MatterControl
|
|||
}
|
||||
|
||||
public string Title { get; set; }
|
||||
public Action<Printer> PauseAction { get; internal set; }
|
||||
public Action<Printer> ResumeAction { get; internal set; }
|
||||
public Action<Printer> StopAction { get; internal set; }
|
||||
public RunningTaskActions TaskActions { get; internal set; }
|
||||
|
||||
private CancellationTokenSource tokenSource;
|
||||
|
||||
|
|
@ -1395,6 +1416,14 @@ namespace MatterHackers.MatterControl
|
|||
}
|
||||
}
|
||||
|
||||
public class RunningTaskActions
|
||||
{
|
||||
public Func<GuiWidget> RichProgressWidget { get; set; }
|
||||
public Action Pause { get; set; }
|
||||
public Action Resume { get; set; }
|
||||
public Action Stop { get; set; }
|
||||
}
|
||||
|
||||
public class RunningTasksConfig
|
||||
{
|
||||
public event EventHandler TasksChanged;
|
||||
|
|
@ -1411,13 +1440,13 @@ namespace MatterHackers.MatterControl
|
|||
};
|
||||
}
|
||||
|
||||
internal Task Execute(Func<IProgress<ProgressStatus>, CancellationToken, Task> func, Func<GuiWidget> extraInfo = null)
|
||||
internal Task Execute(Func<IProgress<ProgressStatus>, CancellationToken, Task> func, RunningTaskActions taskActions = null)
|
||||
{
|
||||
var tokenSource = new CancellationTokenSource();
|
||||
|
||||
var taskDetails = new RunningTaskDetails(tokenSource)
|
||||
{
|
||||
ExtraInfo = extraInfo
|
||||
TaskActions = taskActions,
|
||||
};
|
||||
|
||||
executingTasks.Add(taskDetails);
|
||||
|
|
|
|||
|
|
@ -110,28 +110,51 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
|
||||
topRow.AddChild(new HorizontalSpacer());
|
||||
|
||||
var pauseButton = theme.ButtonFactory.GenerateIconButton(AggContext.StaticData.LoadIcon("fa-pause_12.png", IconColor.Theme));
|
||||
IconButton resumeButton = null;
|
||||
|
||||
var pauseButton = new IconButton(AggContext.StaticData.LoadIcon("fa-pause_12.png", IconColor.Theme), theme);
|
||||
pauseButton.Margin = theme.ButtonSpacing;
|
||||
pauseButton.Enabled = false;
|
||||
pauseButton.Enabled = taskDetails.TaskActions?.Pause != null;
|
||||
pauseButton.Click += (s, e) =>
|
||||
{
|
||||
taskDetails.CancelTask();
|
||||
taskDetails.TaskActions?.Pause();
|
||||
pauseButton.Visible = false;
|
||||
resumeButton.Visible = true;
|
||||
};
|
||||
topRow.AddChild(pauseButton);
|
||||
|
||||
resumeButton = new IconButton(AggContext.StaticData.LoadIcon("fa-play_12.png", IconColor.Theme), theme);
|
||||
resumeButton.Visible = false;
|
||||
resumeButton.Margin = theme.ButtonSpacing;
|
||||
resumeButton.Click += (s, e) =>
|
||||
{
|
||||
taskDetails.TaskActions?.Resume();
|
||||
pauseButton.Visible = true;
|
||||
resumeButton.Visible = false;
|
||||
};
|
||||
topRow.AddChild(resumeButton);
|
||||
|
||||
var stopButton = theme.ButtonFactory.GenerateIconButton(AggContext.StaticData.LoadIcon("fa-stop_12.png", IconColor.Theme));
|
||||
stopButton.Margin = theme.ButtonSpacing;
|
||||
stopButton.Click += (s, e) =>
|
||||
{
|
||||
taskDetails.CancelTask();
|
||||
var stopAction = taskDetails.TaskActions?.Stop;
|
||||
if (stopAction == null)
|
||||
{
|
||||
taskDetails.CancelTask();
|
||||
}
|
||||
else
|
||||
{
|
||||
stopAction.Invoke();
|
||||
}
|
||||
};
|
||||
topRow.AddChild(stopButton);
|
||||
|
||||
this.AddChild(detailsPanel);
|
||||
|
||||
// Add rich progress controls
|
||||
if (taskDetails.ExtraInfo != null
|
||||
&& taskDetails.ExtraInfo?.Invoke() is GuiWidget guiWidget)
|
||||
if (taskDetails.TaskActions?.RichProgressWidget != null
|
||||
&& taskDetails.TaskActions?.RichProgressWidget?.Invoke() is GuiWidget guiWidget)
|
||||
{
|
||||
guiWidget.VAnchor = VAnchor.Absolute;
|
||||
guiWidget.Visible = false;
|
||||
|
|
|
|||
|
|
@ -38,26 +38,23 @@ using MatterHackers.MatterControl.SlicerConfiguration;
|
|||
|
||||
namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||
{
|
||||
public class PrintPauseResumeButton : FlowLayoutWidget
|
||||
public class PrintButton : FlowLayoutWidget
|
||||
{
|
||||
private GuiWidget finishSetupButton;
|
||||
private GuiWidget pausePrintButton;
|
||||
private PrinterConfig printer;
|
||||
private GuiWidget resumePrintButton;
|
||||
private GuiWidget startPrintButton;
|
||||
|
||||
private EventHandler unregisterEvents;
|
||||
private PrinterConfig printer;
|
||||
|
||||
public PrintPauseResumeButton(PrinterActionsBar printerActionsBar, PrinterTabPage printerTabPage, PrinterConfig printer, ThemeConfig theme)
|
||||
public PrintButton(PrinterTabPage printerTabPage, PrinterConfig printer, ThemeConfig theme)
|
||||
{
|
||||
var defaultMargin = theme.ButtonSpacing;
|
||||
|
||||
this.printer = printer;
|
||||
|
||||
// add the finish setup button
|
||||
finishSetupButton = theme.ButtonFactory.Generate("Setup...".Localize(), AggContext.StaticData.LoadIcon("icon_play_32x32.png", 14, 14, IconColor.Theme));
|
||||
finishSetupButton.Name = "Finish Setup Button";
|
||||
finishSetupButton.ToolTipText = "Run setup configuration for printer.".Localize();
|
||||
finishSetupButton.Margin = defaultMargin;
|
||||
finishSetupButton.Margin = theme.ButtonSpacing;
|
||||
finishSetupButton.Click += (s, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(async () =>
|
||||
|
|
@ -75,54 +72,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
this.AddChild(finishSetupButton);
|
||||
|
||||
// add the start print button
|
||||
startPrintButton = theme.ButtonFactory.Generate("Print".Localize(), AggContext.StaticData.LoadIcon("icon_play_32x32.png", 14, 14, IconColor.Theme));
|
||||
startPrintButton.Name = "Start Print Button";
|
||||
startPrintButton.ToolTipText = "Begin printing the selected item.".Localize();
|
||||
startPrintButton.Margin = defaultMargin;
|
||||
startPrintButton.Click += (s, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(async () =>
|
||||
{
|
||||
// Save any pending changes before starting print operation
|
||||
await ApplicationController.Instance.Tasks.Execute(printerTabPage.view3DWidget.SaveChanges);
|
||||
|
||||
var context = printer.Bed.EditContext;
|
||||
await ApplicationController.Instance.PrintPart(
|
||||
context.PartFilePath,
|
||||
context.GCodeFilePath,
|
||||
context.SourceItem.Name,
|
||||
printer,
|
||||
null,
|
||||
CancellationToken.None);
|
||||
});
|
||||
};
|
||||
startPrintButton = new PrintPopupMenu(printer, theme, printerTabPage);
|
||||
startPrintButton.Margin = theme.ButtonSpacing;
|
||||
this.AddChild(startPrintButton);
|
||||
|
||||
// add the pause / resume button
|
||||
pausePrintButton = theme.ButtonFactory.Generate("Pause".Localize(), AggContext.StaticData.LoadIcon("icon_pause_32x32.png", 14, 14, IconColor.Theme));
|
||||
pausePrintButton.ToolTipText = "Pause the current print".Localize();
|
||||
pausePrintButton.Margin = defaultMargin;
|
||||
pausePrintButton.Click += (s, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(printer.Connection.RequestPause);
|
||||
pausePrintButton.Enabled = false;
|
||||
};
|
||||
this.AddChild(pausePrintButton);
|
||||
|
||||
resumePrintButton = theme.ButtonFactory.Generate("Resume".Localize(), AggContext.StaticData.LoadIcon("icon_play_32x32.png", 14, 14, IconColor.Theme));
|
||||
resumePrintButton.ToolTipText = "Resume the current print".Localize();
|
||||
resumePrintButton.Margin = defaultMargin;
|
||||
resumePrintButton.Name = "Resume Button";
|
||||
resumePrintButton.Click += (s, e) =>
|
||||
{
|
||||
if (printer.Connection.PrinterIsPaused)
|
||||
{
|
||||
printer.Connection.Resume();
|
||||
}
|
||||
pausePrintButton.Enabled = true;
|
||||
};
|
||||
this.AddChild(resumePrintButton);
|
||||
|
||||
printer.Connection.CommunicationStateChanged.RegisterEvent((s, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(SetButtonStates);
|
||||
|
|
@ -157,11 +110,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
|
||||
case CommunicationStates.PrintingFromSd:
|
||||
case CommunicationStates.Printing:
|
||||
SetChildVisible(pausePrintButton, true);
|
||||
break;
|
||||
|
||||
case CommunicationStates.Paused:
|
||||
SetChildVisible(resumePrintButton, true);
|
||||
break;
|
||||
|
||||
case CommunicationStates.FinishedPrint:
|
||||
|
|
|
|||
|
|
@ -27,14 +27,13 @@ of the authors and should not be interpreted as representing official policies,
|
|||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.CustomWidgets;
|
||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||
{
|
||||
|
|
@ -43,7 +42,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
private TextImageButtonFactory buttonFactory = ApplicationController.Instance.Theme.ButtonFactory;
|
||||
private PrinterConfig printer;
|
||||
private PrinterTabPage printerTabPage;
|
||||
private bool activelySlicing = false;
|
||||
|
||||
public PrintPopupMenu(PrinterConfig printer, ThemeConfig theme, PrinterTabPage printerTabPage)
|
||||
{
|
||||
|
|
@ -112,6 +110,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
CancellationToken.None);
|
||||
});
|
||||
};
|
||||
button.EnabledChanged += (s, e) => Console.WriteLine();
|
||||
column.AddChild(button);
|
||||
|
||||
return column;
|
||||
|
|
@ -123,17 +122,15 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
Name = "Start Print Button",
|
||||
BackgroundColor = theme.ButtonFactory.Options.NormalFillColor,
|
||||
HoverColor = theme.ButtonFactory.Options.HoverFillColor,
|
||||
Margin = theme.ButtonSpacing,
|
||||
});
|
||||
}
|
||||
|
||||
private class IgnoredFlowLayout : FlowLayoutWidget, IIgnoredPopupChild
|
||||
{
|
||||
public IgnoredFlowLayout()
|
||||
: base (FlowDirection.TopToBottom)
|
||||
: base(FlowDirection.TopToBottom)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -82,12 +82,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
}
|
||||
|
||||
this.AddChild(new PrinterConnectButton(printer, theme));
|
||||
this.AddChild(new PrintPauseResumeButton(this, printerTabPage, printer, theme));
|
||||
|
||||
var printButton = new PrintPopupMenu(printer, theme, printerTabPage);
|
||||
this.AddChild(printButton);
|
||||
|
||||
this.AddChild(new CancelButton(printer, theme));
|
||||
this.AddChild(new PrintButton(printerTabPage, printer, theme));
|
||||
|
||||
var sliceButton = new SliceButton(printer, theme)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2558,7 +2558,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
|
|||
activePrintTask.PrintingOffsetZ = (float)babyStepsStream7.Offset.Z;
|
||||
try
|
||||
{
|
||||
Task.Run(() => activePrintTask.Commit());
|
||||
Task.Run(() => activePrintTask?.Commit());
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
|
|||
BIN
StaticData/Icons/fa-play_12.png
Normal file
BIN
StaticData/Icons/fa-play_12.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 265 B |
|
|
@ -1 +1 @@
|
|||
Subproject commit 70f95e807d377b248af90092524f3896f967ce08
|
||||
Subproject commit 6187f68c913fa095915801fcd8a029c6fa0c4106
|
||||
Loading…
Add table
Add a link
Reference in a new issue