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 ;
2016-06-09 14:58:39 -07:00
using MatterHackers.MatterControl.CustomWidgets ;
2016-07-13 13:39:11 -07:00
using MatterHackers.MatterControl.SetupWizard ;
2016-04-21 18:02:02 -07:00
using System ;
2016-06-09 19:28:21 -07:00
using System.Collections.Generic ;
2016-06-10 16:04:45 -07:00
using System.IO ;
2016-06-09 19:28:21 -07:00
using System.Linq ;
2016-04-04 17:58:33 -07:00
namespace MatterHackers.MatterControl.SlicerConfiguration
{
public class SliceSettingsDetailControl : FlowLayoutWidget
{
private const string SliceSettingsLevelEntry = "SliceSettingsLevel" ;
2016-04-26 15:10:51 -07:00
private const string SliceSettingsShowHelpEntry = "SliceSettingsShowHelp" ;
2016-06-03 18:11:51 -07:00
private DropDownList settingsDetailSelector ;
2016-04-26 15:10:51 -07:00
private CheckBox showHelpBox ;
2017-05-26 11:23:41 -07:00
private List < NamedAction > slicerOptionsMenuItems ;
2016-04-04 17:58:33 -07:00
2017-03-01 13:48:49 -08:00
string resetToDefaultsMessage = "Resetting to default values will remove your current overrides and restore your original printer settings.\nAre you sure you want to continue?" . Localize ( ) ;
string resetToDefaultsWindowTitle = "Revert Settings" . Localize ( ) ;
2017-02-15 15:45:52 -08:00
bool primarySettingsView ;
2016-06-09 19:28:21 -07:00
2016-07-20 15:16:00 -07:00
public SliceSettingsDetailControl ( List < PrinterSettingsLayer > layerCascade )
2016-04-04 17:58:33 -07:00
{
2017-02-15 15:45:52 -08:00
primarySettingsView = layerCascade = = null ;
2016-06-03 18:11:51 -07:00
settingsDetailSelector = new DropDownList ( "Basic" , maxHeight : 200 ) ;
2016-04-04 17:58:33 -07:00
settingsDetailSelector . Name = "User Level Dropdown" ;
2016-04-22 17:30:34 -07:00
settingsDetailSelector . AddItem ( "Basic" . Localize ( ) , "Simple" ) ;
settingsDetailSelector . AddItem ( "Standard" . Localize ( ) , "Intermediate" ) ;
settingsDetailSelector . AddItem ( "Advanced" . Localize ( ) , "Advanced" ) ;
2016-07-20 15:16:00 -07:00
2017-02-15 15:45:52 -08:00
if ( primarySettingsView )
2016-04-04 17:58:33 -07:00
{
2016-07-20 15:16:00 -07:00
// set to the user requested value when in default view
if ( UserSettings . Instance . get ( SliceSettingsLevelEntry ) ! = null
& & SliceSettingsOrganizer . Instance . UserLevels . ContainsKey ( UserSettings . Instance . get ( SliceSettingsLevelEntry ) ) )
{
settingsDetailSelector . SelectedValue = UserSettings . Instance . get ( SliceSettingsLevelEntry ) ;
}
}
else // in settings editor view
{
// set to advanced
settingsDetailSelector . SelectedValue = "Advanced" ;
2016-04-04 17:58:33 -07:00
}
2016-12-01 15:14:53 -08:00
settingsDetailSelector . SelectionChanged + = ( s , e ) = > RebuildSlicerSettings ( null , null ) ;
2016-04-04 17:58:33 -07:00
settingsDetailSelector . VAnchor = VAnchor . ParentCenter ;
settingsDetailSelector . Margin = new BorderDouble ( 5 , 3 ) ;
settingsDetailSelector . BorderColor = new RGBA_Bytes ( ActiveTheme . Instance . SecondaryTextColor , 100 ) ;
2017-02-15 15:45:52 -08:00
if ( primarySettingsView )
2016-07-20 15:16:00 -07:00
{
// only add these in the default view
this . AddChild ( settingsDetailSelector ) ;
this . AddChild ( GetSliceOptionsMenuDropList ( ) ) ;
}
VAnchor = VAnchor . ParentCenter ;
2016-04-04 17:58:33 -07:00
}
2016-04-26 15:10:51 -07:00
public event EventHandler ShowHelpChanged ;
2016-06-09 14:58:39 -07:00
public string SelectedValue = > settingsDetailSelector . SelectedValue ;
2016-04-26 15:10:51 -07:00
2017-02-15 15:45:52 -08:00
public bool ShowingHelp = > primarySettingsView ? showHelpBox . Checked : false ;
2016-04-26 15:10:51 -07:00
2016-04-04 17:58:33 -07:00
private DropDownMenu GetSliceOptionsMenuDropList ( )
{
2016-08-31 13:09:06 -07:00
DropDownMenu sliceOptionsMenuDropList ;
2017-02-15 14:11:37 -08:00
sliceOptionsMenuDropList = new DropDownMenu ( "Options" . Localize ( ) + "... " )
2016-04-04 17:58:33 -07:00
{
2016-08-31 13:09:06 -07:00
HoverColor = new RGBA_Bytes ( 0 , 0 , 0 , 50 ) ,
NormalColor = new RGBA_Bytes ( 0 , 0 , 0 , 0 ) ,
BorderColor = new RGBA_Bytes ( ActiveTheme . Instance . SecondaryTextColor , 100 ) ,
BackgroundColor = new RGBA_Bytes ( 0 , 0 , 0 , 0 ) ,
BorderWidth = 1 ,
MenuAsWideAsItems = false ,
AlignToRightEdge = true ,
} ;
2016-09-27 12:47:15 -07:00
sliceOptionsMenuDropList . Name = "Slice Settings Options Menu" ;
2016-08-31 13:09:06 -07:00
sliceOptionsMenuDropList . VAnchor | = VAnchor . ParentCenter ;
2017-02-15 14:11:37 -08:00
showHelpBox = new CheckBox ( "Show Help" . Localize ( ) ) ;
2017-02-15 15:45:52 -08:00
if ( primarySettingsView )
2017-02-15 14:11:37 -08:00
{
// only turn on the help if in the main view and it is set to on
showHelpBox . Checked = UserSettings . Instance . get ( SliceSettingsShowHelpEntry ) = = "true" ;
}
showHelpBox . CheckedStateChanged + = ( s , e ) = >
{
2017-02-15 15:45:52 -08:00
if ( primarySettingsView )
2017-02-15 14:11:37 -08:00
{
// only save the help settings if in the main view
UserSettings . Instance . set ( SliceSettingsShowHelpEntry , showHelpBox . Checked . ToString ( ) . ToLower ( ) ) ;
}
ShowHelpChanged ? . Invoke ( this , null ) ;
} ;
MenuItem showHelp = new MenuItem ( showHelpBox , "Show Help Checkbox" )
{
Padding = sliceOptionsMenuDropList . MenuItemsPadding ,
} ;
sliceOptionsMenuDropList . MenuItems . Add ( showHelp ) ;
sliceOptionsMenuDropList . AddHorizontalLine ( ) ;
2016-08-31 13:09:06 -07:00
sliceOptionsMenuDropList . AddItem ( "Import" . Localize ( ) ) . Selected + = ( s , e ) = > { ImportSettingsMenu_Click ( ) ; } ;
sliceOptionsMenuDropList . AddItem ( "Export" . Localize ( ) ) . Selected + = ( s , e ) = > { WizardWindow . Show < ExportSettingsPage > ( "ExportSettingsPage" , "Export Settings" ) ; } ;
2016-10-28 16:31:50 -07:00
MenuItem settingsHistory = sliceOptionsMenuDropList . AddItem ( "Restore Settings" . Localize ( ) ) ;
settingsHistory . Selected + = ( s , e ) = > { WizardWindow . Show < PrinterProfileHistoryPage > ( "PrinterProfileHistory" , "Restore Settings" ) ; } ;
2016-08-31 13:09:06 -07:00
2016-09-28 11:20:54 -07:00
settingsHistory . Enabled = ! string . IsNullOrEmpty ( AuthenticationData . Instance . ActiveSessionUsername ) ;
2016-08-31 13:09:06 -07:00
2016-12-12 14:35:34 -08:00
sliceOptionsMenuDropList . AddItem ( "Reset to Defaults" . Localize ( ) ) . Selected + = ( s , e ) = > { UiThread . RunOnIdle ( ResetToDefaults ) ; } ;
2016-04-04 17:58:33 -07:00
return sliceOptionsMenuDropList ;
}
2016-04-26 15:10:51 -07:00
private bool ImportSettingsMenu_Click ( )
{
2016-06-11 16:24:30 -07:00
UiThread . RunOnIdle ( ( ) = > WizardWindow . Show < ImportSettingsPage > ( "ImportSettingsPage" , "Import Settings Page" ) ) ;
2016-04-26 15:10:51 -07:00
return true ;
}
private void RebuildSlicerSettings ( object sender , EventArgs e )
{
UserSettings . Instance . set ( SliceSettingsLevelEntry , settingsDetailSelector . SelectedValue ) ;
ApplicationController . Instance . ReloadAdvancedControlsPanel ( ) ;
}
2016-06-09 14:58:39 -07:00
private void ResetToDefaults ( )
2016-04-26 15:10:51 -07:00
{
2016-06-09 07:59:25 -07:00
StyledMessageBox . ShowMessageBox (
revertSettings = >
{
if ( revertSettings )
{
2016-09-27 12:47:15 -07:00
bool onlyReloadSliceSettings = true ;
if ( ActiveSliceSettings . Instance . GetValue < bool > ( SettingsKey . print_leveling_required_to_print )
& & ActiveSliceSettings . Instance . GetValue < bool > ( SettingsKey . print_leveling_enabled ) )
{
onlyReloadSliceSettings = false ;
}
2016-06-11 16:24:30 -07:00
ActiveSliceSettings . Instance . ClearUserOverrides ( ) ;
2016-07-18 15:20:19 -07:00
ActiveSliceSettings . Instance . Save ( ) ;
2016-09-27 12:47:15 -07:00
if ( onlyReloadSliceSettings )
{
ApplicationController . Instance . ReloadAdvancedControlsPanel ( ) ;
}
else
{
2016-12-29 11:05:16 -08:00
ApplicationController . Instance . ReloadAll ( ) ;
2016-09-27 12:47:15 -07:00
}
2016-06-10 16:04:45 -07:00
}
} ,
resetToDefaultsMessage ,
resetToDefaultsWindowTitle ,
StyledMessageBox . MessageType . YES_NO ) ;
}
2016-04-04 17:58:33 -07:00
}
2016-04-21 18:02:02 -07:00
}