2017-05-26 11:23:41 -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 .
* /
using MatterHackers.Agg ;
2017-11-10 23:14:43 -08:00
using MatterHackers.Agg.Platform ;
2016-04-04 17:58:33 -07:00
using MatterHackers.Agg.UI ;
using MatterHackers.Localizations ;
2017-06-07 09:14:02 -07:00
using MatterHackers.MatterControl.PartPreviewWindow ;
2016-07-13 13:39:11 -07:00
using MatterHackers.MatterControl.SetupWizard ;
2016-04-04 17:58:33 -07:00
namespace MatterHackers.MatterControl.SlicerConfiguration
{
2017-10-15 16:24:39 -07:00
public class SliceSettingsOverflowMenu : OverflowMenu
2016-04-04 17:58:33 -07:00
{
2017-10-15 16:24:39 -07:00
public SliceSettingsOverflowMenu ( PrinterConfig printer , SliceSettingsWidget sliceSettingsWidget )
2016-04-04 17:58:33 -07:00
{
2017-08-07 15:47:27 -07:00
this . VAnchor = VAnchor . Fit | VAnchor . Center ;
2017-10-15 16:24:39 -07:00
this . AlignToRightEdge = true ;
this . Name = "Slice Settings Overflow Menu" ;
2017-09-17 01:11:18 -07:00
2017-10-15 16:24:39 -07:00
this . PopupContent = GenerateMenuContents ( printer , sliceSettingsWidget ) ;
}
2017-08-07 12:31:06 -07:00
2017-10-15 16:24:39 -07:00
private FlowLayoutWidget GenerateMenuContents ( PrinterConfig printer , SliceSettingsWidget sliceSettingsWidget )
{
2017-11-10 13:12:02 -08:00
var popupMenu = new PopupMenu ( ApplicationController . Instance . Theme ) ;
2017-10-15 16:24:39 -07:00
2017-11-10 23:14:43 -08:00
var checkedIcon = AggContext . StaticData . LoadIcon ( "fa-check_16.png" ) ;
2017-02-15 14:11:37 -08:00
2017-11-10 23:14:43 -08:00
var icon = sliceSettingsWidget . ShowHelpControls ? checkedIcon : null ;
2016-08-31 13:09:06 -07:00
2017-11-10 23:14:43 -08:00
popupMenu . CreateMenuItem ( "Show Help" . Localize ( ) , icon ) . Click + = ( s , e ) = >
2017-06-07 09:14:02 -07:00
{
2017-11-10 23:14:43 -08:00
sliceSettingsWidget . ShowHelpControls = ! sliceSettingsWidget . ShowHelpControls ;
sliceSettingsWidget . RebuildSliceSettingsTabs ( ) ;
} ;
2016-08-31 13:09:06 -07:00
2017-11-09 18:26:32 -08:00
popupMenu . CreateHorizontalLine ( ) ;
2016-08-31 13:09:06 -07:00
2017-11-10 13:12:02 -08:00
PopupMenu . MenuItem menuItem ;
2016-04-04 17:58:33 -07:00
2017-11-09 18:26:32 -08:00
menuItem = popupMenu . CreateMenuItem ( "Export" . Localize ( ) ) ;
2017-10-15 16:24:39 -07:00
menuItem . Click + = ( s , e ) = >
2017-06-07 09:14:02 -07:00
{
2017-11-08 15:56:37 -08:00
DialogWindow . Show < ExportSettingsPage > ( ) ;
2017-06-07 09:14:02 -07:00
} ;
2016-04-26 15:10:51 -07:00
2017-11-09 18:26:32 -08:00
menuItem = popupMenu . CreateMenuItem ( "Restore Settings" . Localize ( ) ) ;
2017-10-15 16:24:39 -07:00
menuItem . Click + = ( s , e ) = >
2017-06-07 09:14:02 -07:00
{
2017-11-08 15:56:37 -08:00
DialogWindow . Show < PrinterProfileHistoryPage > ( ) ;
2017-06-07 09:14:02 -07:00
} ;
menuItem . Enabled = ! string . IsNullOrEmpty ( AuthenticationData . Instance . ActiveSessionUsername ) ;
2016-04-26 15:10:51 -07:00
2017-11-09 18:26:32 -08:00
menuItem = popupMenu . CreateMenuItem ( "Reset to Defaults" . Localize ( ) ) ;
2017-10-15 16:24:39 -07:00
menuItem . Click + = ( s , e ) = >
2017-06-07 09:14:02 -07:00
{
UiThread . RunOnIdle ( ( ) = >
2016-06-09 07:59:25 -07:00
{
2017-06-07 09:14:02 -07:00
StyledMessageBox . ShowMessageBox (
revertSettings = >
2016-09-27 12:47:15 -07:00
{
2017-06-07 09:14:02 -07:00
if ( revertSettings )
{
bool onlyReloadSliceSettings = true ;
2017-09-17 01:11:18 -07:00
if ( printer . Settings . GetValue < bool > ( SettingsKey . print_leveling_required_to_print )
& & printer . Settings . GetValue < bool > ( SettingsKey . print_leveling_enabled ) )
2017-06-07 09:14:02 -07:00
{
onlyReloadSliceSettings = false ;
}
2017-09-17 01:11:18 -07:00
printer . Settings . ClearUserOverrides ( ) ;
printer . Settings . Save ( ) ;
2017-06-07 09:14:02 -07:00
if ( onlyReloadSliceSettings )
{
2017-10-30 16:49:22 -07:00
printer ? . Bed . GCodeRenderer ? . Clear3DGCode ( ) ;
2017-06-07 09:14:02 -07:00
}
else
{
ApplicationController . Instance . ReloadAll ( ) ;
}
}
} ,
2017-10-15 16:24:39 -07:00
"Resetting to default values will remove your current overrides and restore your original printer settings.\nAre you sure you want to continue?" . Localize ( ) ,
"Revert Settings" . Localize ( ) ,
2017-06-07 09:14:02 -07:00
StyledMessageBox . MessageType . YES_NO ) ;
} ) ;
} ;
2016-09-27 12:47:15 -07:00
2017-11-09 18:26:32 -08:00
return popupMenu ;
2016-06-10 16:04:45 -07:00
}
2016-04-04 17:58:33 -07:00
}
2016-04-21 18:02:02 -07:00
}