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 ;
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 )
{
var popupContainer = new FlowLayoutWidget ( FlowDirection . TopToBottom ) ;
var showHelpBox = new CheckBox ( "Show Help" . Localize ( ) ) ;
2017-06-08 16:43:30 -07:00
showHelpBox . Checked = sliceSettingsWidget . ShowHelpControls ;
2017-02-15 14:11:37 -08:00
showHelpBox . CheckedStateChanged + = ( s , e ) = >
{
2017-06-08 16:43:30 -07:00
sliceSettingsWidget . ShowHelpControls = showHelpBox . Checked ;
sliceSettingsWidget . RebuildSliceSettingsTabs ( ) ;
2017-02-15 14:11:37 -08:00
} ;
2016-08-31 13:09:06 -07:00
2017-06-07 09:14:02 -07:00
popupContainer . AddChild ( new MenuItem ( showHelpBox , "Show Help Checkbox" )
{
2017-10-15 15:40:31 -07:00
Padding = OverflowMenu . MenuPadding ,
2017-06-07 09:14:02 -07:00
} ) ;
2016-08-31 13:09:06 -07:00
2017-10-15 15:40:31 -07:00
popupContainer . AddChild ( OverflowMenu . CreateHorizontalLine ( ) ) ;
2016-08-31 13:09:06 -07:00
2017-06-07 09:14:02 -07:00
MenuItem menuItem ;
2016-04-04 17:58:33 -07:00
2017-10-15 15:40:31 -07:00
menuItem = OverflowMenu . CreateMenuItem ( "Export" . Localize ( ) ) ;
2017-10-15 16:24:39 -07:00
menuItem . Click + = ( s , e ) = >
2017-06-07 09:14:02 -07:00
{
2017-08-23 15:51:29 -07:00
WizardWindow . Show < ExportSettingsPage > ( ) ;
2017-06-07 09:14:02 -07:00
} ;
popupContainer . AddChild ( menuItem ) ;
2016-04-26 15:10:51 -07:00
2017-10-15 15:40:31 -07:00
menuItem = OverflowMenu . 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-08-23 15:51:29 -07:00
WizardWindow . Show < PrinterProfileHistoryPage > ( ) ;
2017-06-07 09:14:02 -07:00
} ;
menuItem . Enabled = ! string . IsNullOrEmpty ( AuthenticationData . Instance . ActiveSessionUsername ) ;
popupContainer . AddChild ( menuItem ) ;
2016-04-26 15:10:51 -07:00
2017-10-15 15:40:31 -07:00
menuItem = OverflowMenu . 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 )
{
ApplicationController . Instance . ReloadAdvancedControlsPanel ( ) ;
}
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 ) ;
} ) ;
} ;
popupContainer . AddChild ( menuItem ) ;
2016-09-27 12:47:15 -07:00
2017-10-15 15:40:31 -07:00
popupContainer . AddChild ( OverflowMenu . CreateHorizontalLine ( ) ) ;
2017-06-08 18:41:45 -07:00
popupContainer . AddChild ( new TextWidget ( "Mode" )
{
Margin = new BorderDouble ( 35 , 2 , 8 , 8 ) ,
TextColor = RGBA_Bytes . Gray
} ) ;
var modeSelector = new SettingsModeSelector ( )
{
SelectedValue = sliceSettingsWidget . UserLevel ,
Name = "User Level Dropdown" ,
Margin = new BorderDouble ( 35 , 15 , 35 , 5 ) ,
BorderColor = new RGBA_Bytes ( ActiveTheme . Instance . SecondaryTextColor , 100 )
} ;
modeSelector . SelectionChanged + = ( s , e ) = >
{
UserSettings . Instance . set ( UserSettingsKey . SliceSettingsLevel , modeSelector . SelectedValue ) ;
sliceSettingsWidget . RebuildSliceSettingsTabs ( ) ;
} ;
popupContainer . AddChild ( modeSelector ) ;
2017-10-15 16:24:39 -07:00
return popupContainer ;
2016-06-10 16:04:45 -07:00
}
2016-04-04 17:58:33 -07:00
}
2017-06-08 18:41:45 -07:00
public class SettingsModeSelector : DropDownList , IIgnoredPopupChild
{
public SettingsModeSelector ( )
: base ( "Basic" )
{
this . TextColor = RGBA_Bytes . Black ;
this . AddItem ( "Basic" . Localize ( ) , "Simple" ) ;
this . AddItem ( "Standard" . Localize ( ) , "Intermediate" ) ;
this . AddItem ( "Advanced" . Localize ( ) , "Advanced" ) ;
}
}
2016-04-21 18:02:02 -07:00
}