2014-01-29 19:09:30 -08:00
|
|
|
|
/*
|
2017-06-23 15:13:39 -07:00
|
|
|
|
Copyright (c) 2017, Lars Brubaker, John Lewin
|
2014-01-29 19:09:30 -08:00
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
2015-04-08 15:20:10 -07:00
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
2015-04-08 15:20:10 -07:00
|
|
|
|
list of conditions and the following disclaimer.
|
2014-01-29 19:09:30 -08:00
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
2015-04-08 15:20:10 -07:00
|
|
|
|
and/or other materials provided with the distribution.
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
|
|
|
|
|
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
|
2015-04-08 15:20:10 -07:00
|
|
|
|
of the authors and should not be interpreted as representing official policies,
|
2014-01-29 19:09:30 -08:00
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2017-06-23 15:13:39 -07:00
|
|
|
|
using System;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
using MatterHackers.Agg;
|
2014-06-19 15:55:20 -07:00
|
|
|
|
using MatterHackers.Agg.UI;
|
2018-01-10 18:22:13 -08:00
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
2014-06-11 14:52:58 -07:00
|
|
|
|
using MatterHackers.MatterControl.PrinterCommunication;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
using MatterHackers.MatterControl.PrinterControls;
|
2014-06-19 15:55:20 -07:00
|
|
|
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl
|
|
|
|
|
|
{
|
2018-01-10 16:34:24 -08:00
|
|
|
|
public static class EnabledWidgetExtensions
|
|
|
|
|
|
{
|
|
|
|
|
|
public static void SetEnabled(this GuiWidget guiWidget, bool enabled)
|
|
|
|
|
|
{
|
|
|
|
|
|
guiWidget.Enabled = enabled;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-07 14:49:26 -07:00
|
|
|
|
public class ManualPrinterControls : ScrollableWidget, ICloseableTab
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2018-01-10 22:44:45 -08:00
|
|
|
|
public static RootedObjectEventHandler AddPluginControls = new RootedObjectEventHandler();
|
2015-04-09 17:45:14 -07:00
|
|
|
|
private static bool pluginsQueuedToAdd = false;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2018-01-10 16:34:24 -08:00
|
|
|
|
private GuiWidget fanControlsContainer;
|
|
|
|
|
|
private GuiWidget macroControlsContainer;
|
|
|
|
|
|
private GuiWidget tuningAdjustmentControlsContainer;
|
2017-08-06 18:17:46 -07:00
|
|
|
|
private MovementControls movementControlsContainer;
|
2018-01-10 16:34:24 -08:00
|
|
|
|
private GuiWidget calibrationControlsContainer;
|
2016-01-13 16:11:13 -08:00
|
|
|
|
|
2017-06-23 15:13:39 -07:00
|
|
|
|
private EventHandler unregisterEvents;
|
2018-01-10 22:37:15 -08:00
|
|
|
|
private ThemeConfig theme;
|
2017-09-15 12:08:00 -07:00
|
|
|
|
private PrinterConfig printer;
|
2018-01-10 22:37:15 -08:00
|
|
|
|
private FlowLayoutWidget column;
|
2017-06-23 15:13:39 -07:00
|
|
|
|
|
2018-07-12 09:22:28 -07:00
|
|
|
|
public ManualPrinterControls(PrinterConfig printer, ThemeConfig theme)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2018-07-12 09:22:28 -07:00
|
|
|
|
this.theme = theme;
|
2017-10-31 17:27:37 -07:00
|
|
|
|
this.printer = printer;
|
|
|
|
|
|
this.ScrollArea.HAnchor |= HAnchor.Stretch;
|
|
|
|
|
|
this.AnchorAll();
|
|
|
|
|
|
this.AutoScroll = true;
|
|
|
|
|
|
this.HAnchor = HAnchor.Stretch;
|
|
|
|
|
|
this.VAnchor = VAnchor.Stretch;
|
2018-01-10 22:37:15 -08:00
|
|
|
|
|
|
|
|
|
|
this.Name = "ManualPrinterControls";
|
2017-10-31 17:27:37 -07:00
|
|
|
|
|
2017-08-06 20:55:00 -07:00
|
|
|
|
int headingPointSize = theme.H1PointSize;
|
2017-08-06 18:17:46 -07:00
|
|
|
|
|
2018-01-10 22:37:15 -08:00
|
|
|
|
column = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
2017-06-23 15:13:39 -07:00
|
|
|
|
{
|
2017-08-07 15:47:27 -07:00
|
|
|
|
HAnchor = HAnchor.MaxFitOrStretch,
|
|
|
|
|
|
VAnchor = VAnchor.Fit,
|
2017-06-23 15:13:39 -07:00
|
|
|
|
Name = "ManualPrinterControls.ControlsContainer",
|
|
|
|
|
|
Margin = new BorderDouble(0)
|
|
|
|
|
|
};
|
2018-01-10 18:23:34 -08:00
|
|
|
|
this.AddChild(column);
|
2016-11-30 13:31:19 -08:00
|
|
|
|
|
2018-01-10 22:37:15 -08:00
|
|
|
|
movementControlsContainer = this.RegisterSection(MovementControls.CreateSection(printer, theme)) as MovementControls;
|
2015-04-23 20:19:00 -07:00
|
|
|
|
|
2017-09-17 01:11:18 -07:00
|
|
|
|
if (!printer.Settings.GetValue<bool>(SettingsKey.has_hardware_leveling))
|
2017-06-23 15:13:39 -07:00
|
|
|
|
{
|
2018-01-10 22:37:15 -08:00
|
|
|
|
calibrationControlsContainer = this.RegisterSection(CalibrationControls.CreateSection(printer, theme));
|
2017-06-23 15:13:39 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-10 22:37:15 -08:00
|
|
|
|
macroControlsContainer = this.RegisterSection(MacroControls.CreateSection(printer, theme));
|
2015-04-23 20:19:00 -07:00
|
|
|
|
|
2017-09-17 01:11:18 -07:00
|
|
|
|
if (printer.Settings.GetValue<bool>(SettingsKey.has_fan))
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2018-01-10 22:37:15 -08:00
|
|
|
|
fanControlsContainer = this.RegisterSection(FanControls.CreateSection(printer, theme));
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-02-23 15:24:27 -08:00
|
|
|
|
#if !__ANDROID__
|
2018-01-10 22:37:15 -08:00
|
|
|
|
this.RegisterSection(PowerControls.CreateSection(printer, theme));
|
2017-02-23 15:24:27 -08:00
|
|
|
|
#endif
|
2018-01-10 18:22:13 -08:00
|
|
|
|
|
2018-01-10 22:37:15 -08:00
|
|
|
|
tuningAdjustmentControlsContainer = this.RegisterSection(AdjustmentControls.CreateSection(printer, theme));
|
2015-04-23 20:19:00 -07:00
|
|
|
|
|
2017-08-06 17:44:57 -07:00
|
|
|
|
// HACK: this is a hack to make the layout engine fire again for this control
|
|
|
|
|
|
UiThread.RunOnIdle(() => tuningAdjustmentControlsContainer.Width = tuningAdjustmentControlsContainer.Width + 1);
|
2016-12-08 15:39:23 -08:00
|
|
|
|
|
2018-11-09 13:19:14 -08:00
|
|
|
|
printer.Connection.CommunicationStateChanged += onPrinterStatusChanged;
|
|
|
|
|
|
this.Closed += (s, e) => printer.Connection.CommunicationStateChanged -= onPrinterStatusChanged;
|
|
|
|
|
|
|
2018-11-09 14:02:11 -08:00
|
|
|
|
printer.Connection.EnableChanged += onPrinterStatusChanged;
|
|
|
|
|
|
this.Closed += (s, e) => printer.Connection.EnableChanged -= onPrinterStatusChanged;
|
2017-08-06 17:44:57 -07:00
|
|
|
|
|
|
|
|
|
|
SetVisibleControls();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-10 22:37:15 -08:00
|
|
|
|
public GuiWidget RegisterSection(SectionWidget sectionWidget)
|
|
|
|
|
|
{
|
2018-01-11 16:12:08 -08:00
|
|
|
|
// Section not active due to constraints
|
|
|
|
|
|
if (sectionWidget == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-14 20:52:35 -07:00
|
|
|
|
theme.ApplyBoxStyle(sectionWidget);
|
|
|
|
|
|
|
|
|
|
|
|
sectionWidget.ContentPanel.Padding = new BorderDouble(10, 10, 10, 0);
|
2018-01-10 22:37:15 -08:00
|
|
|
|
|
|
|
|
|
|
column.AddChild(sectionWidget);
|
|
|
|
|
|
|
2018-04-15 13:45:10 -07:00
|
|
|
|
// Disable borders on all SettingsRow children in control panels
|
|
|
|
|
|
foreach(var settingsRow in sectionWidget.ContentPanel.Descendants<SettingsRow>())
|
|
|
|
|
|
{
|
|
|
|
|
|
settingsRow.BorderColor = Color.Transparent;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-10 22:37:15 -08:00
|
|
|
|
// Return the panel widget rather than the source sectionWidget
|
|
|
|
|
|
return sectionWidget.ContentPanel;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-10 22:44:45 -08:00
|
|
|
|
public override void OnLoad(EventArgs args)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!pluginsQueuedToAdd && printer.Settings.GetValue(SettingsKey.include_firmware_updater) == "Simple Arduino")
|
|
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
AddPluginControls.CallEvents(this, null);
|
|
|
|
|
|
pluginsQueuedToAdd = false;
|
|
|
|
|
|
});
|
|
|
|
|
|
pluginsQueuedToAdd = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
base.OnLoad(args);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-23 16:44:11 -07:00
|
|
|
|
public override void OnClosed(EventArgs e)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2017-08-06 17:44:57 -07:00
|
|
|
|
unregisterEvents?.Invoke(this, null);
|
|
|
|
|
|
base.OnClosed(e);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2015-04-09 17:45:14 -07:00
|
|
|
|
private void onPrinterStatusChanged(object sender, EventArgs e)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-04-09 17:45:14 -07:00
|
|
|
|
SetVisibleControls();
|
2017-06-23 15:13:39 -07:00
|
|
|
|
UiThread.RunOnIdle(this.Invalidate);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SetVisibleControls()
|
|
|
|
|
|
{
|
2017-09-17 01:11:18 -07:00
|
|
|
|
if (!printer.Settings.PrinterSelected)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2018-01-10 16:34:24 -08:00
|
|
|
|
movementControlsContainer?.SetEnabled(false);
|
|
|
|
|
|
fanControlsContainer?.SetEnabled(false);
|
|
|
|
|
|
macroControlsContainer?.SetEnabled(false);
|
|
|
|
|
|
calibrationControlsContainer?.SetEnabled(false);
|
|
|
|
|
|
tuningAdjustmentControlsContainer?.SetEnabled(false);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
else // we at least have a printer selected
|
|
|
|
|
|
{
|
2017-09-15 12:08:00 -07:00
|
|
|
|
switch (printer.Connection.CommunicationState)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2017-06-13 17:32:38 -07:00
|
|
|
|
case CommunicationStates.Disconnecting:
|
|
|
|
|
|
case CommunicationStates.ConnectionLost:
|
|
|
|
|
|
case CommunicationStates.Disconnected:
|
|
|
|
|
|
case CommunicationStates.AttemptingToConnect:
|
|
|
|
|
|
case CommunicationStates.FailedToConnect:
|
2018-01-10 16:34:24 -08:00
|
|
|
|
movementControlsContainer?.SetEnabled(false);
|
|
|
|
|
|
fanControlsContainer?.SetEnabled(false);
|
|
|
|
|
|
macroControlsContainer?.SetEnabled(false);
|
|
|
|
|
|
tuningAdjustmentControlsContainer?.SetEnabled(false);
|
|
|
|
|
|
calibrationControlsContainer?.SetEnabled(false);
|
2016-01-13 07:39:22 -08:00
|
|
|
|
|
|
|
|
|
|
foreach (var widget in movementControlsContainer.DisableableWidgets)
|
|
|
|
|
|
{
|
2018-01-10 16:34:24 -08:00
|
|
|
|
widget?.SetEnabled(true);
|
2016-01-13 07:39:22 -08:00
|
|
|
|
}
|
2017-02-27 13:26:33 -08:00
|
|
|
|
movementControlsContainer?.jogControls.SetEnabledLevels(false, false);
|
2016-01-13 07:39:22 -08:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
2017-06-13 17:32:38 -07:00
|
|
|
|
case CommunicationStates.FinishedPrint:
|
|
|
|
|
|
case CommunicationStates.Connected:
|
2018-01-10 16:34:24 -08:00
|
|
|
|
movementControlsContainer?.SetEnabled(true);
|
|
|
|
|
|
fanControlsContainer?.SetEnabled(true);
|
|
|
|
|
|
macroControlsContainer?.SetEnabled(true);
|
|
|
|
|
|
tuningAdjustmentControlsContainer?.SetEnabled(true);
|
|
|
|
|
|
calibrationControlsContainer?.SetEnabled(true);
|
2016-01-13 07:39:22 -08:00
|
|
|
|
|
|
|
|
|
|
foreach (var widget in movementControlsContainer.DisableableWidgets)
|
|
|
|
|
|
{
|
2018-01-10 16:34:24 -08:00
|
|
|
|
widget?.SetEnabled(true);
|
2016-01-13 07:39:22 -08:00
|
|
|
|
}
|
2018-06-29 12:29:58 -07:00
|
|
|
|
movementControlsContainer?.jogControls.SetEnabledLevels(enableBabysteppingMode: false, enableEControls: true);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
2017-06-13 17:32:38 -07:00
|
|
|
|
case CommunicationStates.PrintingFromSd:
|
2018-01-10 16:34:24 -08:00
|
|
|
|
movementControlsContainer?.SetEnabled(false);
|
|
|
|
|
|
fanControlsContainer?.SetEnabled(true);
|
|
|
|
|
|
macroControlsContainer?.SetEnabled(false);
|
|
|
|
|
|
tuningAdjustmentControlsContainer?.SetEnabled(false);
|
|
|
|
|
|
calibrationControlsContainer?.SetEnabled(false);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
2017-06-13 17:32:38 -07:00
|
|
|
|
case CommunicationStates.PreparingToPrint:
|
|
|
|
|
|
case CommunicationStates.Printing:
|
2017-09-15 12:08:00 -07:00
|
|
|
|
switch (printer.Connection.DetailedPrintingState)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2017-06-13 17:32:38 -07:00
|
|
|
|
case DetailedPrintingState.HomingAxis:
|
|
|
|
|
|
case DetailedPrintingState.HeatingBed:
|
|
|
|
|
|
case DetailedPrintingState.HeatingExtruder:
|
|
|
|
|
|
case DetailedPrintingState.Printing:
|
2018-01-10 16:34:24 -08:00
|
|
|
|
fanControlsContainer?.SetEnabled(true);
|
|
|
|
|
|
macroControlsContainer?.SetEnabled(false);
|
|
|
|
|
|
tuningAdjustmentControlsContainer?.SetEnabled(true);
|
|
|
|
|
|
calibrationControlsContainer?.SetEnabled(false);
|
2016-01-13 07:39:22 -08:00
|
|
|
|
|
2017-08-06 19:22:47 -07:00
|
|
|
|
foreach (var widget in movementControlsContainer.DisableableWidgets)
|
2016-01-13 07:39:22 -08:00
|
|
|
|
{
|
2018-01-10 16:34:24 -08:00
|
|
|
|
widget?.SetEnabled(false);
|
2016-01-13 07:39:22 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-29 12:29:58 -07:00
|
|
|
|
movementControlsContainer?.jogControls.SetEnabledLevels(enableBabysteppingMode: true, enableEControls: false);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2017-06-13 17:32:38 -07:00
|
|
|
|
case CommunicationStates.Paused:
|
2018-01-10 16:34:24 -08:00
|
|
|
|
movementControlsContainer?.SetEnabled(true);
|
|
|
|
|
|
fanControlsContainer?.SetEnabled(true);
|
|
|
|
|
|
macroControlsContainer?.SetEnabled(true);
|
|
|
|
|
|
tuningAdjustmentControlsContainer?.SetEnabled(true);
|
|
|
|
|
|
calibrationControlsContainer?.SetEnabled(true);
|
2016-01-13 07:39:22 -08:00
|
|
|
|
|
|
|
|
|
|
foreach (var widget in movementControlsContainer.DisableableWidgets)
|
|
|
|
|
|
{
|
2018-01-10 16:34:24 -08:00
|
|
|
|
widget?.SetEnabled(true);
|
2016-01-13 07:39:22 -08:00
|
|
|
|
}
|
2018-06-29 12:29:58 -07:00
|
|
|
|
movementControlsContainer?.jogControls.SetEnabledLevels(enableBabysteppingMode: false, enableEControls: true);
|
2016-01-13 07:39:22 -08:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-02-23 12:43:37 -08:00
|
|
|
|
}
|