2017-05-23 19:03:30 -07:00
/ *
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 .
* /
2017-12-10 21:10:54 -08:00
2017-05-23 19:03:30 -07:00
using System ;
2018-01-21 21:07:14 -08:00
using System.Collections.Generic ;
2018-02-07 18:43:09 -08:00
using System.Collections.ObjectModel ;
using System.IO ;
2017-12-26 09:11:23 -08:00
using System.Linq ;
2017-05-23 19:03:30 -07:00
using MatterHackers.Agg ;
2017-08-20 02:34:39 -07:00
using MatterHackers.Agg.Platform ;
2017-05-23 19:03:30 -07:00
using MatterHackers.Agg.UI ;
using MatterHackers.Localizations ;
using MatterHackers.MatterControl.ActionBar ;
2017-05-24 14:19:02 -07:00
using MatterHackers.MatterControl.CustomWidgets ;
2017-05-23 19:03:30 -07:00
using MatterHackers.MatterControl.EeProm ;
using MatterHackers.MatterControl.PrinterCommunication ;
2017-11-01 13:57:45 -07:00
using MatterHackers.MatterControl.PrintHistory ;
2017-06-29 18:46:59 -07:00
using MatterHackers.MatterControl.SlicerConfiguration ;
2018-01-21 21:07:14 -08:00
using MatterHackers.VectorMath ;
2017-05-23 19:03:30 -07:00
namespace MatterHackers.MatterControl.PartPreviewWindow
{
2017-12-26 09:11:23 -08:00
public class PrinterActionsBar : OverflowBar
2017-05-23 19:03:30 -07:00
{
2017-09-15 12:08:00 -07:00
private PrinterConfig printer ;
2017-08-30 10:37:44 -07:00
private EventHandler unregisterEvents ;
2017-06-09 08:16:46 -07:00
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 ( ) ;
2017-12-11 14:15:50 -08:00
private PrinterTabPage printerTabPage ;
2018-02-07 18:43:09 -08:00
2017-11-29 13:45:01 -08:00
internal GuiWidget sliceButton ;
2017-10-16 16:32:25 -07:00
2018-02-07 18:43:09 -08:00
private RadioIconButton layers2DButton ;
private RadioIconButton layers3DButton ;
internal RadioIconButton modelViewButton ;
2017-09-25 22:11:02 -07:00
public PrinterActionsBar ( PrinterConfig printer , PrinterTabPage printerTabPage , ThemeConfig theme )
2017-12-26 09:11:23 -08:00
: base ( theme )
2017-05-23 19:03:30 -07:00
{
2017-09-15 12:08:00 -07:00
this . printer = printer ;
2017-12-11 14:15:50 -08:00
this . printerTabPage = printerTabPage ;
2017-10-16 17:09:00 -07:00
2017-08-07 15:47:27 -07:00
this . HAnchor = HAnchor . Stretch ;
this . VAnchor = VAnchor . Fit ;
2017-05-23 19:03:30 -07:00
2017-12-10 21:10:54 -08:00
var defaultMargin = theme . ButtonSpacing ;
2017-06-29 19:42:20 -07:00
2017-12-10 21:10:54 -08:00
// add the reset button first (if there is one)
if ( ActiveSliceSettings . Instance . GetValue < bool > ( SettingsKey . show_reset_connection ) )
2017-10-16 16:32:25 -07:00
{
2018-01-16 19:01:09 -08:00
var resetConnectionButton = new TextIconButton (
"Reset" . Localize ( ) ,
AggContext . StaticData . LoadIcon ( "e_stop.png" , 14 , 14 , IconColor . Theme ) ,
theme )
{
ToolTipText = "Reboots the firmware on the controller" . Localize ( ) ,
Margin = defaultMargin
} ;
2017-12-10 21:10:54 -08:00
resetConnectionButton . Click + = ( s , e ) = >
{
UiThread . RunOnIdle ( printer . Connection . RebootBoard ) ;
} ;
this . AddChild ( resetConnectionButton ) ;
}
2017-10-16 16:32:25 -07:00
2017-12-10 21:10:54 -08:00
this . AddChild ( new PrinterConnectButton ( printer , theme ) ) ;
2017-12-12 17:53:32 -08:00
this . AddChild ( new PrintButton ( printerTabPage , printer , theme ) ) ;
2017-10-16 16:32:25 -07:00
2017-12-20 15:43:47 -08:00
var sliceButton = new SliceButton ( printer , printerTabPage , theme )
2017-12-11 14:15:50 -08:00
{
Name = "Generate Gcode Button" ,
Margin = theme . ButtonSpacing ,
} ;
this . AddChild ( sliceButton ) ;
2017-10-16 16:32:25 -07:00
2018-02-07 18:43:09 -08:00
// Add vertical separator
this . AddChild ( new VerticalLine ( 50 )
{
2018-02-09 16:01:50 -08:00
Margin = new BorderDouble ( 3 , 0 ) ,
2018-02-07 18:43:09 -08:00
VAnchor = VAnchor . Absolute ,
Height = theme . ButtonHeight ,
} ) ;
var buttonGroupB = new ObservableCollection < GuiWidget > ( ) ;
var iconPath = Path . Combine ( "ViewTransformControls" , "model.png" ) ;
modelViewButton = new RadioIconButton ( AggContext . StaticData . LoadIcon ( iconPath , IconColor . Theme ) , theme )
{
SiblingRadioButtonList = buttonGroupB ,
Name = "Model View Button" ,
Checked = printer ? . ViewState . ViewMode = = PartViewMode . Model | | printer = = null ,
ToolTipText = "Model View" . Localize ( ) ,
Margin = theme . ButtonSpacing
} ;
modelViewButton . Click + = SwitchModes_Click ;
buttonGroupB . Add ( modelViewButton ) ;
AddChild ( modelViewButton ) ;
iconPath = Path . Combine ( "ViewTransformControls" , "gcode_3d.png" ) ;
layers3DButton = new RadioIconButton ( AggContext . StaticData . LoadIcon ( iconPath , IconColor . Theme ) , theme )
{
SiblingRadioButtonList = buttonGroupB ,
Name = "Layers3D Button" ,
Checked = printer ? . ViewState . ViewMode = = PartViewMode . Layers3D ,
ToolTipText = "3D Layer View" . Localize ( ) ,
Margin = theme . ButtonSpacing
} ;
layers3DButton . Click + = SwitchModes_Click ;
buttonGroupB . Add ( layers3DButton ) ;
if ( ! UserSettings . Instance . IsTouchScreen )
{
this . AddChild ( layers3DButton ) ;
}
iconPath = Path . Combine ( "ViewTransformControls" , "gcode_2d.png" ) ;
layers2DButton = new RadioIconButton ( AggContext . StaticData . LoadIcon ( iconPath , IconColor . Theme ) , theme )
{
SiblingRadioButtonList = buttonGroupB ,
Name = "Layers2D Button" ,
Checked = printer ? . ViewState . ViewMode = = PartViewMode . Layers2D ,
ToolTipText = "2D Layer View" . Localize ( ) ,
Margin = theme . ButtonSpacing ,
} ;
layers2DButton . Click + = SwitchModes_Click ;
buttonGroupB . Add ( layers2DButton ) ;
this . AddChild ( layers2DButton ) ;
2018-02-07 18:44:15 -08:00
//// 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.PrinterConnectionStatus;
//}, ref unregisterEvents);
//this.AddChild(printerConnectionDetail);
2017-08-30 10:37:44 -07:00
2017-08-04 21:32:48 -07:00
this . AddChild ( new HorizontalSpacer ( ) ) ;
2017-09-15 12:08:00 -07:00
bool shareTemp = printer . Settings . GetValue < bool > ( SettingsKey . extruders_share_temperature ) ;
int extruderCount = shareTemp ? 1 : printer . Settings . GetValue < int > ( SettingsKey . extruder_count ) ;
2017-09-06 18:16:45 -07:00
2017-11-16 09:56:16 -08:00
if ( ! printer . Settings . GetValue < bool > ( SettingsKey . sla_printer ) )
2017-06-29 18:46:59 -07:00
{
2017-11-16 09:56:16 -08:00
for ( int extruderIndex = 0 ; extruderIndex < extruderCount ; extruderIndex + + )
2017-09-06 18:16:45 -07:00
{
2017-11-16 09:56:16 -08:00
this . AddChild ( new TemperatureWidgetHotend ( printer , extruderIndex , theme . MenuButtonFactory )
{
Margin = new BorderDouble ( right : 10 )
} ) ;
}
2017-09-06 18:16:45 -07:00
}
2017-06-29 18:46:59 -07:00
2017-09-15 12:08:00 -07:00
if ( printer . Settings . GetValue < bool > ( SettingsKey . has_heated_bed ) )
2017-06-29 18:46:59 -07:00
{
2018-02-08 22:37:58 -08:00
this . AddChild ( new TemperatureWidgetBed ( printer ) ) ;
2017-06-29 18:46:59 -07:00
}
2017-12-26 09:11:23 -08:00
this . OverflowMenu . Name = "Printer Overflow Menu" ;
2018-01-21 21:07:14 -08:00
this . ExtendOverflowMenu = ( popupMenu ) = >
{
this . GeneratePrinterOverflowMenu ( popupMenu , theme ) ;
} ;
2018-02-07 18:43:09 -08:00
printer . ViewState . ViewModeChanged + = ( s , e ) = >
{
if ( e . ViewMode = = PartViewMode . Layers2D )
{
this . layers2DButton . Checked = true ;
}
else if ( e . ViewMode = = PartViewMode . Layers3D )
{
layers3DButton . Checked = true ;
}
else
{
modelViewButton . Checked = true ;
}
} ;
2017-06-02 13:17:30 -07:00
2018-01-17 17:29:37 -08:00
printer . Connection . ConnectionSucceeded . RegisterEvent ( ( s , e ) = >
2017-11-01 13:57:45 -07:00
{
2018-01-17 17:29:37 -08:00
UiThread . RunOnIdle ( ( ) = >
{
PrintRecovery . CheckIfNeedToRecoverPrint ( printer ) ;
} ) ;
2017-11-01 13:57:45 -07:00
} , ref unregisterEvents ) ;
2017-06-09 08:16:46 -07:00
}
2017-05-24 14:19:02 -07:00
2018-02-07 18:43:09 -08:00
private void SwitchModes_Click ( object sender , MouseEventArgs e )
{
if ( sender is GuiWidget widget )
{
if ( widget . Name = = "Layers2D Button" )
{
printer . ViewState . ViewMode = PartViewMode . Layers2D ;
printer . Bed . EnsureGCodeLoaded ( ) ;
}
else if ( widget . Name = = "Layers3D Button" )
{
printer . ViewState . ViewMode = PartViewMode . Layers3D ;
printer . Bed . EnsureGCodeLoaded ( ) ;
}
else
{
printer . ViewState . ViewMode = PartViewMode . Model ;
}
}
}
2017-08-14 11:06:23 -07:00
public override void AddChild ( GuiWidget childToAdd , int indexInChildrenList = - 1 )
{
2017-11-09 15:48:05 -08:00
childToAdd . VAnchor = VAnchor . Center ;
2017-08-14 11:06:23 -07:00
base . AddChild ( childToAdd , indexInChildrenList ) ;
}
2017-07-14 13:55:02 -07:00
public override void OnClosed ( ClosedEventArgs e )
{
2017-08-30 10:37:44 -07:00
unregisterEvents ? . Invoke ( this , null ) ;
2017-07-14 13:55:02 -07:00
base . OnClosed ( e ) ;
}
2018-01-21 21:07:14 -08:00
private void GeneratePrinterOverflowMenu ( PopupMenu popupMenu , ThemeConfig theme )
2017-06-09 08:16:46 -07:00
{
2018-01-21 21:07:14 -08:00
var menuActions = new List < NamedAction > ( )
2017-06-09 08:16:46 -07:00
{
2018-02-28 16:32:58 -08:00
new NamedAction ( )
{
Title = "Import Printer Settings" . Localize ( ) + "..." ,
Action = importMaterialSettingsButton_Click
} ,
2017-07-28 08:57:33 -07:00
new NamedAction ( )
{
2017-08-20 02:34:39 -07:00
Icon = AggContext . StaticData . LoadIcon ( "memory_16x16.png" , 16 , 16 ) ,
2017-07-28 08:57:33 -07:00
Title = "Configure EEProm" . Localize ( ) ,
Action = configureEePromButton_Click
} ,
2018-01-23 12:36:01 -08:00
//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);
// }
// }));
// }
//},
2018-01-03 15:24:55 -08:00
new NamedBoolAction ( )
2017-12-27 13:45:47 -08:00
{
Title = "Configure Printer" . Localize ( ) ,
2018-01-03 15:24:55 -08:00
Action = ( ) = > { } ,
GetIsActive = ( ) = > printer . ViewState . ConfigurePrinterVisible ,
SetIsActive = ( value ) = > printer . ViewState . ConfigurePrinterVisible = value
2017-12-27 13:45:47 -08:00
} ,
2017-07-28 08:19:22 -07:00
new NamedAction ( ) { Title = "----" } ,
new NamedAction ( )
2017-07-27 14:25:21 -07:00
{
2017-07-28 08:19:22 -07:00
Title = "Delete Printer" . Localize ( ) ,
Action = ( ) = >
2017-07-27 14:25:21 -07:00
{
2017-07-28 08:19:22 -07:00
StyledMessageBox . ShowMessageBox (
( doDelete ) = >
{
if ( doDelete )
{
2017-09-15 12:08:00 -07:00
printer . Settings . Helpers . SetMarkedForDelete ( true ) ;
2017-07-28 08:19:22 -07:00
}
} ,
"Are you sure you want to delete your currently selected printer?" . Localize ( ) ,
"Delete Printer?" . Localize ( ) ,
StyledMessageBox . MessageType . YES_NO ,
"Delete Printer" . Localize ( ) ) ;
2017-07-27 14:25:21 -07:00
}
2017-07-28 08:19:22 -07:00
}
2017-07-27 14:25:21 -07:00
} ;
2017-10-15 15:50:48 -07:00
2018-01-21 21:07:14 -08:00
theme . CreateMenuItems ( popupMenu , menuActions ) ;
2017-06-09 08:16:46 -07:00
}
2017-05-23 19:03:30 -07:00
2018-02-28 16:32:58 -08:00
private void importMaterialSettingsButton_Click ( )
{
UiThread . RunOnIdle ( ( ) = >
{
DialogWindow . Show ( new ImportSettingsPage ( ) ) ;
} ) ;
}
2017-07-28 08:57:33 -07:00
private void configureEePromButton_Click ( )
2017-06-09 08:16:46 -07:00
{
UiThread . RunOnIdle ( ( ) = >
2017-05-23 19:03:30 -07:00
{
#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
2017-09-15 12:08:00 -07:00
switch ( printer . Connection . FirmwareType )
2017-06-09 08:16:46 -07:00
{
2017-06-13 17:32:38 -07:00
case FirmwareTypes . Repetier :
2017-06-09 08:16:46 -07:00
if ( openEePromRepetierWidget ! = null )
{
openEePromRepetierWidget . BringToFront ( ) ;
}
else
{
2017-09-15 12:08:00 -07:00
openEePromRepetierWidget = new EePromRepetierWindow ( printer . Connection ) ;
2017-06-09 08:16:46 -07:00
openEePromRepetierWidget . Closed + = ( RepetierWidget , RepetierEvent ) = >
2017-05-23 19:03:30 -07:00
{
2017-06-09 08:16:46 -07:00
openEePromRepetierWidget = null ;
} ;
}
break ;
2017-06-13 17:32:38 -07:00
case FirmwareTypes . Marlin :
2017-06-09 08:16:46 -07:00
if ( openEePromMarlinWidget ! = null )
{
openEePromMarlinWidget . BringToFront ( ) ;
}
else
{
2017-09-15 12:08:00 -07:00
openEePromMarlinWidget = new EePromMarlinWindow ( printer . Connection ) ;
2017-06-09 08:16:46 -07:00
openEePromMarlinWidget . Closed + = ( marlinWidget , marlinEvent ) = >
2017-05-23 19:03:30 -07:00
{
2017-06-09 08:16:46 -07:00
openEePromMarlinWidget = null ;
} ;
}
break ;
default :
2018-01-04 17:30:48 -08:00
printer . Connection . QueueLine ( "M115" ) ;
2017-10-18 19:54:06 -07:00
StyledMessageBox . ShowMessageBox ( noEepromMappingMessage , noEepromMappingTitle , StyledMessageBox . MessageType . OK ) ;
2017-06-09 08:16:46 -07:00
break ;
}
2017-05-23 19:03:30 -07:00
#endif
2017-09-01 21:23:08 -07:00
} ) ;
2017-05-23 19:03:30 -07:00
}
}
}