Made the reset - connect - print -cancel buttons butter
Made them all have icons, switch states better and enable disable butter The all also hold position and are closer to the play stop modle of a music player
This commit is contained in:
parent
a3a611d1e9
commit
e18c98f830
5 changed files with 288 additions and 299 deletions
92
PartPreviewWindow/View3D/PrinterBar/CancelButton.cs
Normal file
92
PartPreviewWindow/View3D/PrinterBar/CancelButton.cs
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
Copyright (c) 2017, Lars Brubaker, John Lewin
|
||||
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.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using MatterHackers.Agg.Platform;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.PrinterCommunication;
|
||||
|
||||
namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||
{
|
||||
public class CancelButton : FlowLayoutWidget
|
||||
{
|
||||
private Button cancelPrintButton;
|
||||
private PrinterConfig printer;
|
||||
private EventHandler unregisterEvents;
|
||||
|
||||
public CancelButton(PrinterConfig printer, ThemeConfig theme)
|
||||
{
|
||||
var defaultMargin = theme.ButtonSpacing;
|
||||
|
||||
this.printer = printer;
|
||||
|
||||
cancelPrintButton = theme.ButtonFactory.Generate("Cancel".Localize().ToUpper(), AggContext.StaticData.LoadIcon("icon_stop_32x32.png", 14, 14, IconColor.Theme));
|
||||
cancelPrintButton.ToolTipText = "Stop the current print".Localize();
|
||||
cancelPrintButton.Name = "Cancel Print Button";
|
||||
cancelPrintButton.Margin = defaultMargin;
|
||||
cancelPrintButton.Click += (s, e) => UiThread.RunOnIdle(() =>
|
||||
{
|
||||
ApplicationController.Instance.ConditionalCancelPrint();
|
||||
SetButtonStates();
|
||||
});
|
||||
this.AddChild(cancelPrintButton);
|
||||
|
||||
printer.Connection.CommunicationStateChanged.RegisterEvent((s, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(SetButtonStates);
|
||||
}, ref unregisterEvents);
|
||||
|
||||
SetButtonStates();
|
||||
}
|
||||
|
||||
public override void OnClosed(ClosedEventArgs e)
|
||||
{
|
||||
unregisterEvents?.Invoke(this, null);
|
||||
base.OnClosed(e);
|
||||
}
|
||||
|
||||
protected void SetButtonStates()
|
||||
{
|
||||
switch (printer.Connection.CommunicationState)
|
||||
{
|
||||
case CommunicationStates.PreparingToPrint:
|
||||
case CommunicationStates.PrintingFromSd:
|
||||
case CommunicationStates.Printing:
|
||||
case CommunicationStates.Paused:
|
||||
cancelPrintButton.Enabled = !printer.Connection.PrintWasCanceled;
|
||||
break;
|
||||
|
||||
default:
|
||||
cancelPrintButton.Enabled = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
189
PartPreviewWindow/View3D/PrinterBar/PauseResumeButton.cs
Normal file
189
PartPreviewWindow/View3D/PrinterBar/PauseResumeButton.cs
Normal file
|
|
@ -0,0 +1,189 @@
|
|||
/*
|
||||
Copyright (c) 2017, Lars Brubaker, John Lewin
|
||||
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.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using MatterHackers.Agg.Platform;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling;
|
||||
using MatterHackers.MatterControl.PrinterCommunication;
|
||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||
|
||||
namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||
{
|
||||
public class PrintPauseResumeButton : FlowLayoutWidget
|
||||
{
|
||||
private GuiWidget finishSetupButton;
|
||||
private GuiWidget pausePrintButton;
|
||||
private PrinterConfig printer;
|
||||
private GuiWidget resumePrintButton;
|
||||
private GuiWidget startPrintButton;
|
||||
private EventHandler unregisterEvents;
|
||||
|
||||
public PrintPauseResumeButton(PrinterActionsBar printerActionsBar, PrinterTabPage printerTabPage, PrinterConfig printer, ThemeConfig theme)
|
||||
{
|
||||
var defaultMargin = theme.ButtonSpacing;
|
||||
|
||||
this.printer = printer;
|
||||
|
||||
// add the finish setup button
|
||||
finishSetupButton = theme.ButtonFactory.Generate("Finish 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.Click += (s, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(async () =>
|
||||
{
|
||||
var context = printer.Bed.EditContext;
|
||||
await ApplicationController.Instance.PrintPart(
|
||||
context.PartFilePath,
|
||||
context.GCodeFilePath,
|
||||
context.SourceItem.Name,
|
||||
printer,
|
||||
null);
|
||||
});
|
||||
};
|
||||
this.AddChild(finishSetupButton);
|
||||
|
||||
// add the start print button
|
||||
startPrintButton = theme.ButtonFactory.Generate("Print".Localize().ToUpper(), 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 printerTabPage.view3DWidget.PersistPlateIfNeeded();
|
||||
|
||||
var context = printer.Bed.EditContext;
|
||||
await ApplicationController.Instance.PrintPart(
|
||||
context.PartFilePath,
|
||||
context.GCodeFilePath,
|
||||
context.SourceItem.Name,
|
||||
printer,
|
||||
null);
|
||||
});
|
||||
};
|
||||
this.AddChild(startPrintButton);
|
||||
|
||||
// add the pause / resume button
|
||||
pausePrintButton = theme.ButtonFactory.Generate("Pause".Localize().ToUpper(), 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().ToUpper(), 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);
|
||||
}, ref unregisterEvents);
|
||||
|
||||
SetButtonStates();
|
||||
}
|
||||
|
||||
public override void OnClosed(ClosedEventArgs e)
|
||||
{
|
||||
unregisterEvents?.Invoke(this, null);
|
||||
base.OnClosed(e);
|
||||
}
|
||||
|
||||
protected void SetButtonStates()
|
||||
{
|
||||
switch (printer.Connection.CommunicationState)
|
||||
{
|
||||
case CommunicationStates.Connected:
|
||||
PrintLevelingData levelingData = printer.Settings.Helpers.GetPrintLevelingData();
|
||||
if (levelingData != null && printer.Settings.GetValue<bool>(SettingsKey.print_leveling_required_to_print)
|
||||
&& !levelingData.HasBeenRunAndEnabled())
|
||||
{
|
||||
SetChildVisible(finishSetupButton, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetChildVisible(startPrintButton, true);
|
||||
}
|
||||
break;
|
||||
|
||||
case CommunicationStates.PrintingFromSd:
|
||||
case CommunicationStates.Printing:
|
||||
SetChildVisible(pausePrintButton, true);
|
||||
break;
|
||||
|
||||
case CommunicationStates.Paused:
|
||||
SetChildVisible(resumePrintButton, true);
|
||||
break;
|
||||
|
||||
case CommunicationStates.FinishedPrint:
|
||||
SetChildVisible(startPrintButton, true);
|
||||
break;
|
||||
|
||||
default:
|
||||
SetChildVisible(startPrintButton, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetChildVisible(GuiWidget visibleChild, bool enabled)
|
||||
{
|
||||
foreach (var child in Children)
|
||||
{
|
||||
if (child == visibleChild)
|
||||
{
|
||||
child.Visible = true;
|
||||
child.Enabled = enabled;
|
||||
}
|
||||
else
|
||||
{
|
||||
child.Visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
252
PartPreviewWindow/View3D/PrinterBar/PrinterActionsBar.cs
Normal file
252
PartPreviewWindow/View3D/PrinterBar/PrinterActionsBar.cs
Normal file
|
|
@ -0,0 +1,252 @@
|
|||
/*
|
||||
Copyright (c) 2017, Lars Brubaker, John Lewin
|
||||
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.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.Platform;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.ActionBar;
|
||||
using MatterHackers.MatterControl.CustomWidgets;
|
||||
using MatterHackers.MatterControl.EeProm;
|
||||
using MatterHackers.MatterControl.PrinterCommunication;
|
||||
using MatterHackers.MatterControl.PrintHistory;
|
||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||
|
||||
namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||
{
|
||||
public class PrinterActionsBar : FlowLayoutWidget
|
||||
{
|
||||
private PrinterConfig printer;
|
||||
private EventHandler unregisterEvents;
|
||||
private static EePromMarlinWindow openEePromMarlinWidget = null;
|
||||
private static EePromRepetierWindow openEePromRepetierWidget = null;
|
||||
private string noEepromMappingMessage = "Oops! There is no eeprom mapping for your printer's firmware.".Localize() + "\n\n" + "You may need to wait a minute for your printer to finish initializing.".Localize();
|
||||
private string noEepromMappingTitle = "Warning - No EEProm Mapping".Localize();
|
||||
|
||||
private OverflowMenu overflowMenu;
|
||||
|
||||
internal GuiWidget sliceButton;
|
||||
|
||||
public PrinterActionsBar(PrinterConfig printer, PrinterTabPage printerTabPage, ThemeConfig theme)
|
||||
{
|
||||
this.printer = printer;
|
||||
|
||||
this.HAnchor = HAnchor.Stretch;
|
||||
this.VAnchor = VAnchor.Fit;
|
||||
|
||||
var defaultMargin = theme.ButtonSpacing;
|
||||
|
||||
// add the reset button first (if there is one)
|
||||
if (ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.show_reset_connection))
|
||||
{
|
||||
var resetConnectionButton = theme.ButtonFactory.Generate("Reset".Localize().ToUpper(), AggContext.StaticData.LoadIcon("e_stop.png", 14, 14, IconColor.Theme));
|
||||
resetConnectionButton.ToolTipText = "Reboots the firmware on the controller".Localize();
|
||||
resetConnectionButton.Margin = defaultMargin;
|
||||
resetConnectionButton.Click += (s, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(printer.Connection.RebootBoard);
|
||||
};
|
||||
this.AddChild(resetConnectionButton);
|
||||
}
|
||||
|
||||
this.AddChild(new PrinterConnectButton(printer, theme));
|
||||
this.AddChild(new PrintPauseResumeButton(this, printerTabPage, printer, theme));
|
||||
this.AddChild(new CancelButton(printer, theme));
|
||||
|
||||
this.AddChild(sliceButton = new SlicePopupMenu(printer, theme, printerTabPage));
|
||||
|
||||
// put in the detail message
|
||||
var printerConnectionDetail = new TextWidget("")
|
||||
{
|
||||
Margin = new BorderDouble(5, 0),
|
||||
TextColor = ActiveTheme.Instance.PrimaryTextColor,
|
||||
AutoExpandBoundsToText = true,
|
||||
PointSize = 8
|
||||
};
|
||||
printer.Connection.PrintingStateChanged.RegisterEvent((s, e) =>
|
||||
{
|
||||
printerConnectionDetail.Text = printer.Connection.PrinterConnectionStatus;
|
||||
}, ref unregisterEvents);
|
||||
this.AddChild(printerConnectionDetail);
|
||||
|
||||
this.AddChild(new HorizontalSpacer());
|
||||
|
||||
bool shareTemp = printer.Settings.GetValue<bool>(SettingsKey.extruders_share_temperature);
|
||||
int extruderCount = shareTemp ? 1 : printer.Settings.GetValue<int>(SettingsKey.extruder_count);
|
||||
|
||||
if (!printer.Settings.GetValue<bool>(SettingsKey.sla_printer))
|
||||
{
|
||||
for (int extruderIndex = 0; extruderIndex < extruderCount; extruderIndex++)
|
||||
{
|
||||
this.AddChild(new TemperatureWidgetHotend(printer, extruderIndex, theme.MenuButtonFactory)
|
||||
{
|
||||
Margin = new BorderDouble(right: 10)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (printer.Settings.GetValue<bool>(SettingsKey.has_heated_bed))
|
||||
{
|
||||
this.AddChild(new TemperatureWidgetBed(printer));
|
||||
}
|
||||
|
||||
overflowMenu = new OverflowMenu(IconColor.Theme)
|
||||
{
|
||||
AlignToRightEdge = true,
|
||||
Name = "Printer Overflow Menu",
|
||||
Margin = theme.ButtonSpacing
|
||||
};
|
||||
overflowMenu.DynamicPopupContent = GeneratePrinterOverflowMenu;
|
||||
|
||||
ApplicationController.Instance.ActivePrinter.Connection.ConnectionSucceeded.RegisterEvent((s, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(PrintRecovery.CheckIfNeedToRecoverPrint);
|
||||
}, ref unregisterEvents);
|
||||
|
||||
this.AddChild(overflowMenu);
|
||||
}
|
||||
|
||||
public override void AddChild(GuiWidget childToAdd, int indexInChildrenList = -1)
|
||||
{
|
||||
childToAdd.VAnchor = VAnchor.Center;
|
||||
base.AddChild(childToAdd, indexInChildrenList);
|
||||
}
|
||||
|
||||
public override void OnClosed(ClosedEventArgs e)
|
||||
{
|
||||
unregisterEvents?.Invoke(this, null);
|
||||
base.OnClosed(e);
|
||||
}
|
||||
|
||||
private GuiWidget GeneratePrinterOverflowMenu()
|
||||
{
|
||||
var menuActions = new NamedAction[]
|
||||
{
|
||||
new NamedAction()
|
||||
{
|
||||
Icon = AggContext.StaticData.LoadIcon("memory_16x16.png", 16, 16),
|
||||
Title = "Configure EEProm".Localize(),
|
||||
Action = configureEePromButton_Click
|
||||
},
|
||||
new NamedAction()
|
||||
{
|
||||
Title = "Rename Printer".Localize(),
|
||||
Action = () =>
|
||||
{
|
||||
DialogWindow.Show(
|
||||
new InputBoxPage(
|
||||
"Rename Printer".Localize(),
|
||||
"Name".Localize(),
|
||||
printer.Settings.GetValue(SettingsKey.printer_name),
|
||||
"Enter New Name Here".Localize(),
|
||||
"Rename".Localize(),
|
||||
(newName) =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(newName))
|
||||
{
|
||||
printer.Settings.SetValue(SettingsKey.printer_name, newName);
|
||||
}
|
||||
}));
|
||||
}
|
||||
},
|
||||
new NamedAction() { Title = "----" },
|
||||
new NamedAction()
|
||||
{
|
||||
Title = "Delete Printer".Localize(),
|
||||
Action = () =>
|
||||
{
|
||||
StyledMessageBox.ShowMessageBox(
|
||||
(doDelete) =>
|
||||
{
|
||||
if (doDelete)
|
||||
{
|
||||
printer.Settings.Helpers.SetMarkedForDelete(true);
|
||||
}
|
||||
},
|
||||
"Are you sure you want to delete your currently selected printer?".Localize(),
|
||||
"Delete Printer?".Localize(),
|
||||
StyledMessageBox.MessageType.YES_NO,
|
||||
"Delete Printer".Localize());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return ApplicationController.Instance.Theme.CreatePopupMenu(menuActions);
|
||||
}
|
||||
|
||||
private void configureEePromButton_Click()
|
||||
{
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
#if false // This is to force the creation of the repetier window for testing when we don't have repetier firmware.
|
||||
new MatterHackers.MatterControl.EeProm.EePromRepetierWidget();
|
||||
#else
|
||||
switch (printer.Connection.FirmwareType)
|
||||
{
|
||||
case FirmwareTypes.Repetier:
|
||||
if (openEePromRepetierWidget != null)
|
||||
{
|
||||
openEePromRepetierWidget.BringToFront();
|
||||
}
|
||||
else
|
||||
{
|
||||
openEePromRepetierWidget = new EePromRepetierWindow(printer.Connection);
|
||||
openEePromRepetierWidget.Closed += (RepetierWidget, RepetierEvent) =>
|
||||
{
|
||||
openEePromRepetierWidget = null;
|
||||
};
|
||||
}
|
||||
break;
|
||||
|
||||
case FirmwareTypes.Marlin:
|
||||
if (openEePromMarlinWidget != null)
|
||||
{
|
||||
openEePromMarlinWidget.BringToFront();
|
||||
}
|
||||
else
|
||||
{
|
||||
openEePromMarlinWidget = new EePromMarlinWindow(printer.Connection);
|
||||
openEePromMarlinWidget.Closed += (marlinWidget, marlinEvent) =>
|
||||
{
|
||||
openEePromMarlinWidget = null;
|
||||
};
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
printer.Connection.SendLineToPrinterNow("M115");
|
||||
StyledMessageBox.ShowMessageBox(noEepromMappingMessage, noEepromMappingTitle, StyledMessageBox.MessageType.OK);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
197
PartPreviewWindow/View3D/PrinterBar/PrinterConnectButton.cs
Normal file
197
PartPreviewWindow/View3D/PrinterBar/PrinterConnectButton.cs
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
/*
|
||||
Copyright (c) 2017, Lars Brubaker, John Lewin
|
||||
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.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using MatterHackers.Agg.Platform;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.PrinterCommunication;
|
||||
|
||||
namespace MatterHackers.MatterControl.ActionBar
|
||||
{
|
||||
public class PrinterConnectButton : FlowLayoutWidget
|
||||
{
|
||||
private readonly string disconnectAndCancelTitle = "Disconnect and stop the current print?".Localize();
|
||||
private readonly string disconnectAndCancelMessage = "WARNING: Disconnecting will stop the current print.\n\nAre you sure you want to disconnect?".Localize();
|
||||
|
||||
private Button cancelConnectButton;
|
||||
private GuiWidget connectButton;
|
||||
private Button disconnectButton;
|
||||
|
||||
private EventHandler unregisterEvents;
|
||||
private PrinterConfig printer;
|
||||
|
||||
public PrinterConnectButton(PrinterConfig printer, ThemeConfig theme)
|
||||
{
|
||||
this.printer = printer;
|
||||
this.HAnchor = HAnchor.Left | HAnchor.Fit;
|
||||
this.VAnchor = VAnchor.Fit;
|
||||
this.Margin = 0;
|
||||
this.Padding = 0;
|
||||
|
||||
connectButton = theme.ButtonFactory.Generate("Connect".Localize().ToUpper(), AggContext.StaticData.LoadIcon("connect.png", 14, 14, IconColor.Theme));
|
||||
connectButton.Name = "Connect to printer button";
|
||||
connectButton.ToolTipText = "Connect to the currently selected printer".Localize();
|
||||
connectButton.Click += (s, e) =>
|
||||
{
|
||||
if (connectButton.Enabled)
|
||||
{
|
||||
if (printer.Settings.PrinterSelected)
|
||||
{
|
||||
UserRequestedConnectToActivePrinter();
|
||||
}
|
||||
}
|
||||
};
|
||||
this.AddChild(connectButton);
|
||||
|
||||
// add the cancel stop button
|
||||
cancelConnectButton = theme.ButtonFactory.Generate("Cancel".Localize().ToUpper(), AggContext.StaticData.LoadIcon("connect.png", 14, 14, IconColor.Theme));
|
||||
cancelConnectButton.ToolTipText = "Stop trying to connect to the printer.".Localize();
|
||||
cancelConnectButton.Click += (s, e) => UiThread.RunOnIdle(() =>
|
||||
{
|
||||
ApplicationController.Instance.ConditionalCancelPrint();
|
||||
cancelConnectButton.Enabled = false;
|
||||
});
|
||||
this.AddChild(cancelConnectButton);
|
||||
|
||||
disconnectButton = theme.ButtonFactory.Generate("Disconnect".Localize().ToUpper(), AggContext.StaticData.LoadIcon("connect.png", 14, 14, IconColor.Theme));
|
||||
disconnectButton.Name = "Disconnect from printer button";
|
||||
disconnectButton.Visible = false;
|
||||
disconnectButton.ToolTipText = "Disconnect from current printer".Localize();
|
||||
disconnectButton.Click += (s, e) => UiThread.RunOnIdle(() =>
|
||||
{
|
||||
if (printer.Connection.PrinterIsPrinting)
|
||||
{
|
||||
StyledMessageBox.ShowMessageBox(
|
||||
(bool disconnectCancel) =>
|
||||
{
|
||||
if (disconnectCancel)
|
||||
{
|
||||
printer.Connection.Stop(false);
|
||||
printer.Connection.Disable();
|
||||
}
|
||||
},
|
||||
disconnectAndCancelMessage,
|
||||
disconnectAndCancelTitle,
|
||||
StyledMessageBox.MessageType.YES_NO,
|
||||
"Disconnect".Localize(),
|
||||
"Stay Connected".Localize());
|
||||
}
|
||||
else
|
||||
{
|
||||
printer.Connection.Disable();
|
||||
}
|
||||
});
|
||||
this.AddChild(disconnectButton);
|
||||
|
||||
foreach (var child in Children)
|
||||
{
|
||||
child.VAnchor = VAnchor.Center;
|
||||
child.Cursor = Cursors.Hand;
|
||||
child.Margin = theme.ButtonSpacing;
|
||||
}
|
||||
|
||||
printer.Connection.EnableChanged.RegisterEvent((s, e) => SetVisibleStates(), ref unregisterEvents);
|
||||
printer.Connection.CommunicationStateChanged.RegisterEvent((s, e) => SetVisibleStates(), ref unregisterEvents);
|
||||
|
||||
this.SetVisibleStates();
|
||||
}
|
||||
|
||||
public override void OnClosed(ClosedEventArgs e)
|
||||
{
|
||||
unregisterEvents?.Invoke(this, null);
|
||||
base.OnClosed(e);
|
||||
}
|
||||
|
||||
public void UserRequestedConnectToActivePrinter()
|
||||
{
|
||||
if (printer.Settings.PrinterSelected)
|
||||
{
|
||||
#if __ANDROID__
|
||||
if (!printer.Settings.GetValue<bool>(SettingsKey.enable_network_printing)
|
||||
&& !FrostedSerialPort.HasPermissionToDevice())
|
||||
{
|
||||
// Opens the USB device permissions dialog which will call back into our UsbDevice broadcast receiver to connect
|
||||
FrostedSerialPort.RequestPermissionToDevice(RunTroubleShooting);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
printer.Connection.HaltConnectionThread();
|
||||
printer.Connection.Connect(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void RunTroubleShooting()
|
||||
{
|
||||
DialogWindow.Show<SetupWizardTroubleshooting>();
|
||||
}
|
||||
|
||||
private void SetChildVisible(GuiWidget visibleChild, bool enabled)
|
||||
{
|
||||
foreach (var child in Children)
|
||||
{
|
||||
if (child == visibleChild)
|
||||
{
|
||||
child.Visible = true;
|
||||
child.Enabled = enabled;
|
||||
}
|
||||
else
|
||||
{
|
||||
child.Visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetVisibleStates()
|
||||
{
|
||||
switch (printer.Connection.CommunicationState)
|
||||
{
|
||||
case CommunicationStates.FailedToConnect:
|
||||
case CommunicationStates.Disconnected:
|
||||
case CommunicationStates.ConnectionLost:
|
||||
SetChildVisible(connectButton, true);
|
||||
break;
|
||||
|
||||
case CommunicationStates.Disconnecting:
|
||||
SetChildVisible(disconnectButton, false);
|
||||
break;
|
||||
|
||||
case CommunicationStates.AttemptingToConnect:
|
||||
SetChildVisible(cancelConnectButton, true);
|
||||
break;
|
||||
|
||||
default:
|
||||
SetChildVisible(disconnectButton, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue