2017-12-11 22:22:56 -08:00
|
|
|
|
/*
|
2019-01-23 06:54:18 -08:00
|
|
|
|
Copyright (c) 2019, Lars Brubaker, John Lewin
|
2017-12-11 22:22:56 -08:00
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
|
|
list of conditions and the following disclaimer.
|
|
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
|
and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
|
|
The views and conclusions contained in the software and documentation are those
|
|
|
|
|
|
of the authors and should not be interpreted as representing official policies,
|
|
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2017-12-12 17:53:32 -08:00
|
|
|
|
using System;
|
2018-02-09 21:44:09 -08:00
|
|
|
|
using System.Collections.Generic;
|
2018-01-20 10:16:36 -08:00
|
|
|
|
using System.Linq;
|
2017-12-12 17:53:32 -08:00
|
|
|
|
using System.Threading;
|
2017-12-11 22:22:56 -08:00
|
|
|
|
using MatterHackers.Agg;
|
2021-03-03 14:32:40 -08:00
|
|
|
|
using MatterHackers.Agg.Platform;
|
2017-12-11 22:22:56 -08:00
|
|
|
|
using MatterHackers.Agg.UI;
|
2021-05-21 15:23:25 -07:00
|
|
|
|
using MatterHackers.ImageProcessing;
|
2017-12-11 22:22:56 -08:00
|
|
|
|
using MatterHackers.Localizations;
|
|
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
2018-07-18 14:59:23 -07:00
|
|
|
|
using MatterHackers.MatterControl.Library;
|
2019-05-24 10:19:45 -07:00
|
|
|
|
using MatterHackers.MatterControl.Library.Export;
|
|
|
|
|
|
using MatterHackers.MatterControl.Plugins.X3GDriver;
|
2021-06-24 10:36:32 -07:00
|
|
|
|
using MatterHackers.MatterControl.PrinterCommunication;
|
2017-12-11 22:22:56 -08:00
|
|
|
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
2018-03-08 17:23:03 -08:00
|
|
|
|
using MatterHackers.VectorMath;
|
2017-12-11 22:22:56 -08:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.PartPreviewWindow
|
|
|
|
|
|
{
|
2017-12-27 13:12:34 -08:00
|
|
|
|
public class PrintPopupMenu : PopupMenuButton
|
2017-12-11 22:22:56 -08:00
|
|
|
|
{
|
|
|
|
|
|
private PrinterConfig printer;
|
2018-02-09 21:44:09 -08:00
|
|
|
|
private Dictionary<string, UIField> allUiFields = new Dictionary<string, UIField>();
|
|
|
|
|
|
private SettingsContext settingsContext;
|
2017-12-11 22:22:56 -08:00
|
|
|
|
|
2018-02-10 21:28:55 -08:00
|
|
|
|
public PrintPopupMenu(PrinterConfig printer, ThemeConfig theme)
|
2018-07-12 09:22:28 -07:00
|
|
|
|
: base(theme)
|
2017-12-11 22:22:56 -08:00
|
|
|
|
{
|
|
|
|
|
|
this.printer = printer;
|
2017-12-27 13:12:34 -08:00
|
|
|
|
this.DrawArrow = true;
|
2018-01-16 19:01:09 -08:00
|
|
|
|
this.BackgroundColor = theme.ToolbarButtonBackground;
|
|
|
|
|
|
this.HoverColor = theme.ToolbarButtonHover;
|
|
|
|
|
|
this.MouseDownColor = theme.ToolbarButtonDown;
|
2017-12-11 22:22:56 -08:00
|
|
|
|
this.Name = "PrintPopupMenu";
|
|
|
|
|
|
this.HAnchor = HAnchor.Fit;
|
|
|
|
|
|
this.VAnchor = VAnchor.Fit;
|
2018-02-09 21:44:09 -08:00
|
|
|
|
|
|
|
|
|
|
settingsContext = new SettingsContext(printer, null, NamedSettingsLayers.All);
|
|
|
|
|
|
|
2018-12-03 13:23:24 -08:00
|
|
|
|
this.PopupHAnchor = HAnchor.Fit;
|
|
|
|
|
|
this.PopupVAnchor = VAnchor.Fit;
|
|
|
|
|
|
this.MakeScrollable = false;
|
|
|
|
|
|
|
2017-12-11 22:22:56 -08:00
|
|
|
|
this.DynamicPopupContent = () =>
|
|
|
|
|
|
{
|
2018-04-12 08:42:10 -07:00
|
|
|
|
var menuTheme = ApplicationController.Instance.MenuTheme;
|
|
|
|
|
|
|
2017-12-11 22:22:56 -08:00
|
|
|
|
int tabIndex = 0;
|
|
|
|
|
|
|
2018-02-09 21:44:09 -08:00
|
|
|
|
allUiFields.Clear();
|
|
|
|
|
|
|
2019-01-22 09:15:30 -08:00
|
|
|
|
var printPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
2017-12-11 22:22:56 -08:00
|
|
|
|
{
|
2018-10-13 17:58:54 -07:00
|
|
|
|
Padding = theme.DefaultContainerPadding,
|
2018-11-03 09:50:09 -07:00
|
|
|
|
BackgroundColor = menuTheme.BackgroundColor
|
2017-12-11 22:22:56 -08:00
|
|
|
|
};
|
2018-01-24 16:31:10 -08:00
|
|
|
|
|
2019-03-09 14:12:45 -08:00
|
|
|
|
printPanel.AddChild(new TextWidget("Options".Localize(), textColor: menuTheme.TextColor, pointSize: theme.DefaultFontSize)
|
2017-12-11 22:22:56 -08:00
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Left
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var optionsPanel = new IgnoredFlowLayout()
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "PrintPopupMenu Panel",
|
|
|
|
|
|
HAnchor = HAnchor.Fit | HAnchor.Left,
|
|
|
|
|
|
VAnchor = VAnchor.Fit,
|
|
|
|
|
|
Padding = 5,
|
2020-07-19 18:04:02 -07:00
|
|
|
|
MinimumSize = new Vector2(400 * GuiWidget.DeviceScale, 65 * GuiWidget.DeviceScale),
|
2017-12-11 22:22:56 -08:00
|
|
|
|
};
|
2019-01-22 09:15:30 -08:00
|
|
|
|
printPanel.AddChild(optionsPanel);
|
2017-12-11 22:22:56 -08:00
|
|
|
|
|
2020-11-28 10:21:55 -08:00
|
|
|
|
var settingsToAdd = new[]
|
|
|
|
|
|
{
|
|
|
|
|
|
SettingsKey.layer_height,
|
|
|
|
|
|
SettingsKey.fill_density,
|
|
|
|
|
|
SettingsKey.create_raft,
|
|
|
|
|
|
SettingsKey.create_per_layer_support
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var key in settingsToAdd)
|
2017-12-11 22:22:56 -08:00
|
|
|
|
{
|
2019-01-06 13:19:01 -08:00
|
|
|
|
var settingsData = PrinterSettings.SettingsData[key];
|
2018-04-12 08:42:10 -07:00
|
|
|
|
var row = SliceSettingsTabView.CreateItemRow(settingsData, settingsContext, printer, menuTheme, ref tabIndex, allUiFields);
|
2018-01-20 10:16:36 -08:00
|
|
|
|
|
2018-12-20 17:10:35 -08:00
|
|
|
|
if (row is SliceSettingsRow settingsRow)
|
|
|
|
|
|
{
|
2018-12-31 11:41:50 -08:00
|
|
|
|
settingsRow.ArrowDirection = ArrowDirection.Left;
|
2018-12-20 17:10:35 -08:00
|
|
|
|
}
|
2018-01-20 10:16:36 -08:00
|
|
|
|
|
2017-12-11 22:22:56 -08:00
|
|
|
|
optionsPanel.AddChild(row);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-11-01 18:19:09 -07:00
|
|
|
|
var subPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
|
|
|
|
|
{
|
|
|
|
|
|
Margin = new BorderDouble(2, 0)
|
|
|
|
|
|
};
|
2018-01-22 10:32:32 -08:00
|
|
|
|
|
2018-12-03 13:23:24 -08:00
|
|
|
|
bool anySettingOverridden = false;
|
|
|
|
|
|
anySettingOverridden |= printer.Settings.GetValue<bool>(SettingsKey.spiral_vase);
|
|
|
|
|
|
anySettingOverridden |= !string.IsNullOrWhiteSpace(printer.Settings.GetValue(SettingsKey.layer_to_pause));
|
|
|
|
|
|
|
2019-01-31 12:35:12 -08:00
|
|
|
|
var sectionWidget = new SectionWidget("Advanced".Localize(), subPanel, menuTheme, expanded: anySettingOverridden)
|
2018-01-22 10:32:32 -08:00
|
|
|
|
{
|
2018-01-24 16:31:10 -08:00
|
|
|
|
Name = "Advanced Section",
|
2018-01-22 10:32:32 -08:00
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Fit,
|
|
|
|
|
|
Margin = 0
|
|
|
|
|
|
};
|
2019-01-22 09:15:30 -08:00
|
|
|
|
printPanel.AddChild(sectionWidget);
|
2018-01-22 10:32:32 -08:00
|
|
|
|
|
2018-05-26 12:21:09 -07:00
|
|
|
|
foreach (var key in new[] { SettingsKey.spiral_vase, SettingsKey.layer_to_pause })
|
2018-01-22 10:32:32 -08:00
|
|
|
|
{
|
2018-12-20 17:10:35 -08:00
|
|
|
|
var advancedRow = SliceSettingsTabView.CreateItemRow(
|
2019-01-06 13:19:01 -08:00
|
|
|
|
PrinterSettings.SettingsData[key],
|
2018-12-20 17:10:35 -08:00
|
|
|
|
settingsContext,
|
|
|
|
|
|
printer,
|
|
|
|
|
|
menuTheme,
|
|
|
|
|
|
ref tabIndex,
|
|
|
|
|
|
allUiFields);
|
|
|
|
|
|
|
|
|
|
|
|
if (advancedRow is SliceSettingsRow settingsRow)
|
|
|
|
|
|
{
|
2018-12-31 11:41:50 -08:00
|
|
|
|
settingsRow.ArrowDirection = ArrowDirection.Left;
|
2018-12-20 17:10:35 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
subPanel.AddChild(advancedRow);
|
2018-01-22 10:32:32 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-11-01 18:19:09 -07:00
|
|
|
|
menuTheme.ApplyBoxStyle(sectionWidget);
|
2018-04-14 20:52:35 -07:00
|
|
|
|
|
2018-04-12 22:27:30 -07:00
|
|
|
|
sectionWidget.Margin = new BorderDouble(0, 10);
|
2018-04-12 22:29:08 -07:00
|
|
|
|
sectionWidget.ContentPanel.Children<SettingsRow>().First().Border = new BorderDouble(0, 1);
|
|
|
|
|
|
sectionWidget.ContentPanel.Children<SettingsRow>().Last().Border = 0;
|
2018-01-22 10:32:32 -08:00
|
|
|
|
|
2018-12-03 13:23:24 -08:00
|
|
|
|
var printerReadyToTakeCommands = printer.Connection.CommunicationState == PrinterCommunication.CommunicationStates.FinishedPrint
|
|
|
|
|
|
|| printer.Connection.CommunicationState == PrinterCommunication.CommunicationStates.Connected;
|
|
|
|
|
|
|
|
|
|
|
|
// add the start print button
|
|
|
|
|
|
var setupRow = new FlowLayoutWidget()
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-01-22 09:15:30 -08:00
|
|
|
|
// Perform validation before popup
|
2019-05-16 15:31:19 -07:00
|
|
|
|
var errors = printer.Validate();
|
2018-12-03 13:23:24 -08:00
|
|
|
|
|
2020-10-25 15:45:51 -07:00
|
|
|
|
var startPrintButton = CreateStartPrintButton("Start Print".Localize(), printer, menuTheme, out bool printEnabled);
|
|
|
|
|
|
startPrintButton.Click += (s, e) => this.CloseMenu();
|
2019-01-22 18:04:05 -08:00
|
|
|
|
|
2019-06-04 17:34:22 -07:00
|
|
|
|
var hasErrors = errors.Any(e => e.ErrorLevel == ValidationErrorLevel.Error);
|
|
|
|
|
|
var hasWarnings = errors.Any(e => e.ErrorLevel == ValidationErrorLevel.Warning
|
|
|
|
|
|
&& UserSettings.Instance.get($"Ignore_{e.ID}") != "true");
|
|
|
|
|
|
|
|
|
|
|
|
var hasErrorsOrWarnings = hasErrors || hasWarnings;
|
|
|
|
|
|
if (hasErrorsOrWarnings)
|
|
|
|
|
|
{
|
|
|
|
|
|
string label = hasErrors ? "Action Required".Localize() : "Action Recommended".Localize();
|
|
|
|
|
|
|
|
|
|
|
|
setupRow.AddChild(new TextWidget(label, textColor: hasErrors ? Color.Red : theme.PrimaryAccentColor, pointSize: theme.DefaultFontSize)
|
|
|
|
|
|
{
|
|
|
|
|
|
VAnchor = VAnchor.Bottom,
|
|
|
|
|
|
AutoExpandBoundsToText = true,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setupRow.AddChild(new HorizontalSpacer());
|
|
|
|
|
|
|
2019-06-04 17:53:27 -07:00
|
|
|
|
// Export button {{
|
2019-06-04 17:25:05 -07:00
|
|
|
|
bool isSailfish = printer.Settings.GetValue<bool>("enable_sailfish_communication");
|
2019-06-04 17:53:27 -07:00
|
|
|
|
var exportPlugins = PluginFinder.CreateInstancesOf<IExportPlugin>();
|
|
|
|
|
|
var targetPluginType = isSailfish ? typeof(X3GExport) : typeof(GCodeExport);
|
2019-05-24 10:19:45 -07:00
|
|
|
|
|
2019-06-04 17:53:27 -07:00
|
|
|
|
// Find the first export plugin with the target type
|
|
|
|
|
|
if (exportPlugins.FirstOrDefault(p => p.GetType() == targetPluginType) is IExportPlugin exportPlugin)
|
2019-05-24 10:19:45 -07:00
|
|
|
|
{
|
2019-06-04 17:53:27 -07:00
|
|
|
|
string exportType = isSailfish ? "Export X3G".Localize() : "Export G-Code".Localize();
|
2019-05-24 10:19:45 -07:00
|
|
|
|
|
2019-06-04 17:53:27 -07:00
|
|
|
|
exportPlugin.Initialize(printer);
|
2019-06-04 17:25:05 -07:00
|
|
|
|
|
2021-02-25 23:06:42 -08:00
|
|
|
|
var exportGCodeButton = menuTheme.CreateSplitButton(new SplitButtonParams()
|
2019-06-04 17:53:27 -07:00
|
|
|
|
{
|
2021-02-25 23:06:42 -08:00
|
|
|
|
ButtonText = "Export".Localize(),
|
|
|
|
|
|
ButtonTooltip = exportPlugin.Enabled ? exportType : exportPlugin.DisabledReason,
|
|
|
|
|
|
ExtendPopupMenu = (popupMenu) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var operationMenu = popupMenu.CreateMenuItem("Options...");
|
|
|
|
|
|
operationMenu.Click += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
ApplicationController.Instance.ExportLibraryItems(
|
|
|
|
|
|
new[] { new InMemoryLibraryItem(printer.Bed.Scene) },
|
|
|
|
|
|
centerOnBed: false,
|
|
|
|
|
|
printer: printer);
|
|
|
|
|
|
this.CloseMenu();
|
|
|
|
|
|
};
|
|
|
|
|
|
},
|
2021-05-21 15:23:25 -07:00
|
|
|
|
Icon = StaticData.Instance.LoadIcon("cube_export.png", 16, 16).SetToColor(theme.TextColor),
|
2021-02-25 23:06:42 -08:00
|
|
|
|
ButtonEnabled = exportPlugin.Enabled,
|
2021-03-16 11:02:21 -07:00
|
|
|
|
ButtonName = "Export GCode Button",
|
2021-02-25 23:06:42 -08:00
|
|
|
|
ButtonAction = (widget) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
this.CloseMenu();
|
|
|
|
|
|
ExportPrintItemPage.DoExport(
|
|
|
|
|
|
new[] { new InMemoryLibraryItem(printer.Bed.Scene) },
|
|
|
|
|
|
printer,
|
|
|
|
|
|
exportPlugin);
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
});
|
2021-03-03 14:32:40 -08:00
|
|
|
|
|
2021-03-15 12:27:36 -07:00
|
|
|
|
exportGCodeButton.Enabled = exportPlugin.Enabled;
|
2021-02-25 23:06:42 -08:00
|
|
|
|
exportGCodeButton.ToolTipText = "More Export Options".Localize();
|
2019-05-24 10:19:45 -07:00
|
|
|
|
|
2019-06-04 17:53:27 -07:00
|
|
|
|
setupRow.AddChild(exportGCodeButton);
|
|
|
|
|
|
}
|
2019-05-24 10:19:45 -07:00
|
|
|
|
|
2019-06-04 17:53:27 -07:00
|
|
|
|
// Export button }}
|
2019-06-04 17:34:22 -07:00
|
|
|
|
|
2019-06-04 17:16:43 -07:00
|
|
|
|
setupRow.AddChild(startPrintButton);
|
2018-12-03 13:23:24 -08:00
|
|
|
|
|
2019-01-22 09:15:30 -08:00
|
|
|
|
printPanel.AddChild(setupRow);
|
2018-12-03 13:23:24 -08:00
|
|
|
|
|
2019-01-22 09:15:30 -08:00
|
|
|
|
if (printEnabled)
|
2018-12-03 13:23:24 -08:00
|
|
|
|
{
|
|
|
|
|
|
theme.ApplyPrimaryActionStyle(startPrintButton);
|
|
|
|
|
|
}
|
2019-01-22 13:30:40 -08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
startPrintButton.BackgroundColor = theme.MinimalShade;
|
|
|
|
|
|
}
|
2017-12-11 22:22:56 -08:00
|
|
|
|
|
2019-01-22 18:04:05 -08:00
|
|
|
|
if (hasErrorsOrWarnings)
|
2019-01-22 09:15:30 -08:00
|
|
|
|
{
|
2019-01-23 06:54:18 -08:00
|
|
|
|
var errorsPanel = new ValidationErrorsPanel(errors, menuTheme);
|
2019-01-22 09:15:30 -08:00
|
|
|
|
|
|
|
|
|
|
// Conditional layout for right or bottom errors panel alignment
|
2019-01-22 13:25:16 -08:00
|
|
|
|
var layoutStyle = FlowDirection.TopToBottom;
|
|
|
|
|
|
|
|
|
|
|
|
if (layoutStyle == FlowDirection.LeftToRight)
|
|
|
|
|
|
{
|
|
|
|
|
|
errorsPanel.HAnchor = HAnchor.Absolute;
|
|
|
|
|
|
errorsPanel.VAnchor = VAnchor.Fit | VAnchor.Top;
|
|
|
|
|
|
errorsPanel.BackgroundColor = theme.ResolveColor(menuTheme.BackgroundColor, theme.PrimaryAccentColor.WithAlpha(30));
|
|
|
|
|
|
errorsPanel.Width = 350;
|
|
|
|
|
|
|
|
|
|
|
|
errorsPanel.Load += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
errorsPanel.Parent.BackgroundColor = Color.Transparent;
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
errorsPanel.HAnchor = HAnchor.Stretch;
|
|
|
|
|
|
errorsPanel.VAnchor = VAnchor.Fit;
|
|
|
|
|
|
errorsPanel.Margin = 3;
|
|
|
|
|
|
}
|
2019-01-22 09:15:30 -08:00
|
|
|
|
|
|
|
|
|
|
// Instead of the typical case where the print panel is returned, wrap and append validation errors panel
|
|
|
|
|
|
var errorsContainer = new FlowLayoutWidget(layoutStyle)
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Fit,
|
2019-01-22 13:25:16 -08:00
|
|
|
|
VAnchor = VAnchor.Fit,
|
|
|
|
|
|
BackgroundColor = layoutStyle == FlowDirection.TopToBottom ? printPanel.BackgroundColor : Color.Transparent
|
2019-01-22 09:15:30 -08:00
|
|
|
|
};
|
2019-01-22 18:04:05 -08:00
|
|
|
|
|
|
|
|
|
|
// Clear bottom padding
|
|
|
|
|
|
printPanel.Padding = printPanel.Padding.Clone(bottom: 2);
|
|
|
|
|
|
|
2019-01-22 09:15:30 -08:00
|
|
|
|
errorsContainer.AddChild(printPanel);
|
|
|
|
|
|
errorsContainer.AddChild(errorsPanel);
|
|
|
|
|
|
|
|
|
|
|
|
return errorsContainer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return printPanel;
|
2017-12-11 22:22:56 -08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
this.AddChild(new TextButton("Print".Localize(), theme)
|
|
|
|
|
|
{
|
2017-12-27 13:12:34 -08:00
|
|
|
|
Selectable = false,
|
2018-06-25 08:16:17 -07:00
|
|
|
|
Padding = theme.TextButtonPadding.Clone(right: 5)
|
2017-12-11 22:22:56 -08:00
|
|
|
|
});
|
2018-02-09 21:44:09 -08:00
|
|
|
|
|
2018-11-16 08:44:56 -08:00
|
|
|
|
// Register listeners
|
2018-11-12 17:20:59 -08:00
|
|
|
|
printer.Settings.SettingChanged += Printer_SettingChanged;
|
2018-02-09 21:44:09 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-25 15:45:51 -07:00
|
|
|
|
public static GuiWidget CreateStartPrintButton(string buttonText,
|
|
|
|
|
|
PrinterConfig printer,
|
|
|
|
|
|
ThemeConfig theme,
|
|
|
|
|
|
out bool printEnabled)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Enable print option when no validation Errors exists
|
|
|
|
|
|
var printingOrPause = printer.Connection.Printing || printer.Connection.Paused;
|
|
|
|
|
|
var errors = printer.Validate();
|
|
|
|
|
|
printEnabled = !printingOrPause && !errors.Any(err => err.ErrorLevel == ValidationErrorLevel.Error);
|
|
|
|
|
|
|
|
|
|
|
|
var startPrintButton = new TextButton(buttonText, theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "Start Print Button",
|
|
|
|
|
|
Enabled = printEnabled
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
startPrintButton.Click += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
// Exit if the bed is not GCode and the bed has no printable items
|
|
|
|
|
|
if (!printer.Bed.EditContext.IsGGCodeSource
|
|
|
|
|
|
&& !printer.PrintableItems(printer.Bed.Scene).Any())
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UiThread.RunOnIdle(async () =>
|
|
|
|
|
|
{
|
|
|
|
|
|
// Save any pending changes before starting print operation
|
|
|
|
|
|
await ApplicationController.Instance.Tasks.Execute("Saving Changes".Localize(), printer, printer.Bed.SaveChanges);
|
|
|
|
|
|
|
|
|
|
|
|
await ApplicationController.Instance.PrintPart(
|
|
|
|
|
|
printer.Bed.EditContext,
|
|
|
|
|
|
printer,
|
|
|
|
|
|
null,
|
2021-01-14 15:49:34 -08:00
|
|
|
|
CancellationToken.None,
|
2021-06-24 10:36:32 -07:00
|
|
|
|
PrinterConnection.PrintingModes.Normal);
|
2020-10-25 15:45:51 -07:00
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return startPrintButton;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-23 16:44:11 -07:00
|
|
|
|
public override void OnClosed(EventArgs e)
|
2018-02-09 21:44:09 -08:00
|
|
|
|
{
|
2018-11-16 08:44:56 -08:00
|
|
|
|
// Unregister listeners
|
|
|
|
|
|
printer.Settings.SettingChanged -= Printer_SettingChanged;
|
|
|
|
|
|
|
2018-02-09 21:44:09 -08:00
|
|
|
|
base.OnClosed(e);
|
2017-12-11 22:22:56 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-20 12:38:05 -08:00
|
|
|
|
private void Printer_SettingChanged(object s, StringEventArgs stringEvent)
|
2018-11-16 08:44:56 -08:00
|
|
|
|
{
|
2018-12-20 12:38:05 -08:00
|
|
|
|
if (stringEvent != null)
|
2018-11-16 08:44:56 -08:00
|
|
|
|
{
|
|
|
|
|
|
string settingsKey = stringEvent.Data;
|
|
|
|
|
|
if (allUiFields.TryGetValue(settingsKey, out UIField uifield))
|
|
|
|
|
|
{
|
|
|
|
|
|
string currentValue = settingsContext.GetValue(settingsKey);
|
|
|
|
|
|
if (uifield.Value != currentValue
|
|
|
|
|
|
|| settingsKey == "com_port")
|
|
|
|
|
|
{
|
|
|
|
|
|
uifield.SetValue(
|
|
|
|
|
|
currentValue,
|
|
|
|
|
|
userInitiated: false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-11 22:22:56 -08:00
|
|
|
|
private class IgnoredFlowLayout : FlowLayoutWidget, IIgnoredPopupChild
|
|
|
|
|
|
{
|
|
|
|
|
|
public IgnoredFlowLayout()
|
2017-12-12 17:53:32 -08:00
|
|
|
|
: base(FlowDirection.TopToBottom)
|
2017-12-11 22:22:56 -08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
2018-09-11 10:57:53 -07:00
|
|
|
|
|
2018-10-11 15:04:03 -07:00
|
|
|
|
public bool KeepMenuOpen => false;
|
2017-12-11 22:22:56 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|