2018-02-23 14:55:27 +01:00
#include "Preferences.hpp"
#include "AppConfig.hpp"
#include "OptionsGroup.hpp"
2018-11-26 14:41:58 +01:00
#include "I18N.hpp"
2018-02-23 14:55:27 +01:00
namespace Slic3r {
namespace GUI {
2018-10-02 13:23:38 +02:00
PreferencesDialog :: PreferencesDialog ( wxWindow * parent ) :
2019-04-18 02:03:40 +02:00
DPIDialog ( parent , wxID_ANY , _ ( L ( "Preferences" )), wxDefaultPosition ,
2019-04-25 15:06:44 +02:00
wxDefaultSize , wxDEFAULT_DIALOG_STYLE )
2019-04-18 02:03:40 +02:00
{
2019-05-22 17:08:02 +02:00
#ifdef __WXOSX__
isOSX = true ;
#endif
2018-10-02 13:23:38 +02:00
build ();
}
2018-05-02 13:20:36 +02:00
2018-02-23 14:55:27 +01:00
void PreferencesDialog :: build ()
{
auto app_config = get_app_config ();
m_optgroup = std :: make_shared < ConfigOptionsGroup > ( this , _ ( L ( "General" )));
2019-04-18 02:03:40 +02:00
m_optgroup -> label_width = 40 ;
2019-05-22 13:51:02 +02:00
m_optgroup -> m_on_change = [ this ]( t_config_option_key opt_key , boost :: any value ) {
2018-02-23 14:55:27 +01:00
m_values [ opt_key ] = boost :: any_cast < bool > ( value ) ? "1" : "0" ;
2019-05-22 13:51:02 +02:00
if ( opt_key == "use_custom_toolbar_size" ) {
m_icon_size_sizer -> ShowItems ( boost :: any_cast < bool > ( value ));
this -> layout ();
}
2019-06-24 15:55:14 +02:00
};
2018-02-23 14:55:27 +01:00
2018-03-13 12:39:57 +01:00
// TODO
2018-02-23 14:55:27 +01:00
// $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
// opt_id = > 'version_check',
// type = > 'bool',
// label = > 'Check for updates',
// tooltip = > 'If this is enabled, Slic3r will check for updates daily and display a reminder if a newer version is available.',
// default = > $app_config->get("version_check") // 1,
// readonly = > !wxTheApp->have_version_check,
// ));
ConfigOptionDef def ;
def . label = L ( "Remember output directory" );
def . type = coBool ;
def . tooltip = L ( "If this is enabled, Slic3r will prompt the last output directory "
"instead of the one containing the input files." );
2019-05-03 18:01:39 +02:00
def . set_default_value ( new ConfigOptionBool { app_config -> has ( "remember_output_path" ) ? app_config -> get ( "remember_output_path" ) == "1" : true });
2018-05-21 11:50:48 +02:00
Option option ( def , "remember_output_path" );
2018-02-23 14:55:27 +01:00
m_optgroup -> append_single_option_line ( option );
def . label = L ( "Auto-center parts" );
def . type = coBool ;
def . tooltip = L ( "If this is enabled, Slic3r will auto-center objects "
"around the print bed center." );
2019-05-03 18:01:39 +02:00
def . set_default_value ( new ConfigOptionBool { app_config -> get ( "autocenter" ) == "1" });
2018-02-23 14:55:27 +01:00
option = Option ( def , "autocenter" );
m_optgroup -> append_single_option_line ( option );
def . label = L ( "Background processing" );
def . type = coBool ;
def . tooltip = L ( "If this is enabled, Slic3r will pre-process objects as soon "
"as they \' re loaded in order to save time when exporting G-code." );
2019-05-03 18:01:39 +02:00
def . set_default_value ( new ConfigOptionBool { app_config -> get ( "background_processing" ) == "1" });
2018-02-23 14:55:27 +01:00
option = Option ( def , "background_processing" );
m_optgroup -> append_single_option_line ( option );
2018-04-18 12:33:07 +02:00
// Please keep in sync with ConfigWizard
def . label = L ( "Check for application updates" );
def . type = coBool ;
2019-05-13 10:05:59 +02:00
def . tooltip = L ( "If enabled, PrusaSlicer will check for the new versions of itself online. When a new version becomes available a notification is displayed at the next application startup (never during program usage). This is only a notification mechanisms, no automatic installation is done." );
2019-05-03 18:01:39 +02:00
def . set_default_value ( new ConfigOptionBool ( app_config -> get ( "version_check" ) == "1" ));
2018-04-18 12:33:07 +02:00
option = Option ( def , "version_check" );
m_optgroup -> append_single_option_line ( option );
// Please keep in sync with ConfigWizard
def . label = L ( "Update built-in Presets automatically" );
def . type = coBool ;
def . tooltip = L ( "If enabled, Slic3r downloads updates of built-in system presets in the background. These updates are downloaded into a separate temporary location. When a new preset version becomes available it is offered at application startup." );
2019-05-03 18:01:39 +02:00
def . set_default_value ( new ConfigOptionBool ( app_config -> get ( "preset_update" ) == "1" ));
2018-04-18 12:33:07 +02:00
option = Option ( def , "preset_update" );
m_optgroup -> append_single_option_line ( option );
2018-02-23 14:55:27 +01:00
def . label = L ( "Suppress \" - default - \" presets" );
def . type = coBool ;
def . tooltip = L ( "Suppress \" - default - \" presets in the Print / Filament / Printer "
"selections once there are any other valid presets available." );
2019-05-03 18:01:39 +02:00
def . set_default_value ( new ConfigOptionBool { app_config -> get ( "no_defaults" ) == "1" });
2018-02-23 14:55:27 +01:00
option = Option ( def , "no_defaults" );
m_optgroup -> append_single_option_line ( option );
def . label = L ( "Show incompatible print and filament presets" );
def . type = coBool ;
def . tooltip = L ( "When checked, the print and filament presets are shown in the preset editor "
"even if they are marked as incompatible with the active printer" );
2019-05-03 18:01:39 +02:00
def . set_default_value ( new ConfigOptionBool { app_config -> get ( "show_incompatible_presets" ) == "1" });
2018-02-23 14:55:27 +01:00
option = Option ( def , "show_incompatible_presets" );
m_optgroup -> append_single_option_line ( option );
2019-01-24 11:30:29 +01:00
#if __APPLE__
def . label = L ( "Use Retina resolution for the 3D scene" );
def . type = coBool ;
def . tooltip = L ( "If enabled, the 3D scene will be rendered in Retina resolution. "
"If you are experiencing 3D performance problems, disabling this option may help." );
2019-05-03 18:01:39 +02:00
def . set_default_value ( new ConfigOptionBool { app_config -> get ( "use_retina_opengl" ) == "1" });
2019-01-24 11:30:29 +01:00
option = Option ( def , "use_retina_opengl" );
m_optgroup -> append_single_option_line ( option );
#endif
2019-06-24 15:55:14 +02:00
def . label = L ( "Use perspective camera" );
def . type = coBool ;
def . tooltip = L ( "If enabled, use perspective camera. If not enabled, use orthographic camera." );
def . set_default_value ( new ConfigOptionBool { app_config -> get ( "use_perspective_camera" ) == "1" });
option = Option ( def , "use_perspective_camera" );
m_optgroup -> append_single_option_line ( option );
2019-05-22 13:51:02 +02:00
def . label = L ( "Use custom size for toolbar icons" );
def . type = coBool ;
def . tooltip = L ( "If enabled, you can change size of toolbar icons manually." );
def . set_default_value ( new ConfigOptionBool { app_config -> get ( "use_custom_toolbar_size" ) == "1" });
option = Option ( def , "use_custom_toolbar_size" );
m_optgroup -> append_single_option_line ( option );
create_icon_size_slider ();
m_icon_size_sizer -> ShowItems ( app_config -> get ( "use_custom_toolbar_size" ) == "1" );
2018-02-23 14:55:27 +01:00
auto sizer = new wxBoxSizer ( wxVERTICAL );
sizer -> Add ( m_optgroup -> sizer , 0 , wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT , 10 );
2019-04-13 23:46:52 +02:00
SetFont ( wxGetApp (). normal_font ());
2018-02-23 14:55:27 +01:00
auto buttons = CreateStdDialogButtonSizer ( wxOK | wxCANCEL );
wxButton * btn = static_cast < wxButton *> ( FindWindowById ( wxID_OK , this ));
btn -> Bind ( wxEVT_BUTTON , [ this ]( wxCommandEvent & ) { accept (); });
sizer -> Add ( buttons , 0 , wxALIGN_CENTER_HORIZONTAL | wxBOTTOM , 10 );
SetSizer ( sizer );
sizer -> SetSizeHints ( this );
}
void PreferencesDialog :: accept ()
{
2019-06-25 09:20:58 +02:00
if ( m_values . find ( "no_defaults" ) != m_values . end ()) {
2019-04-26 10:52:38 +02:00
warning_catcher ( this , wxString :: Format ( _ ( L ( "You need to restart %s to make the changes effective." )), SLIC3R_APP_NAME ));
2018-02-23 14:55:27 +01:00
}
auto app_config = get_app_config ();
for ( std :: map < std :: string , std :: string >:: iterator it = m_values . begin (); it != m_values . end (); ++ it ) {
app_config -> set ( it -> first , it -> second );
}
EndModal ( wxID_OK );
// Nothify the UI to update itself from the ini file.
2018-10-02 13:23:38 +02:00
wxGetApp (). update_ui_from_settings ();
2018-02-23 14:55:27 +01:00
}
2019-04-18 02:03:40 +02:00
void PreferencesDialog :: on_dpi_changed ( const wxRect & suggested_rect )
{
2019-04-25 01:45:00 +02:00
m_optgroup -> msw_rescale ();
2019-04-18 02:03:40 +02:00
2019-05-22 13:51:02 +02:00
msw_buttons_rescale ( this , em_unit (), { wxID_OK , wxID_CANCEL });
layout ();
}
void PreferencesDialog :: layout ()
{
2019-04-25 15:06:44 +02:00
const int em = em_unit ();
2019-05-22 13:51:02 +02:00
SetMinSize ( wxSize ( 47 * em , 28 * em ));
2019-04-25 15:06:44 +02:00
Fit ();
2019-04-18 02:03:40 +02:00
Refresh ();
}
2019-05-22 13:51:02 +02:00
void PreferencesDialog :: create_icon_size_slider ()
{
const auto app_config = get_app_config ();
const int em = em_unit ();
m_icon_size_sizer = new wxBoxSizer ( wxHORIZONTAL );
2019-05-22 17:08:02 +02:00
wxWindow * parent = m_optgroup -> ctrl_parent ();
2019-05-22 13:51:02 +02:00
2019-05-22 17:08:02 +02:00
if ( isOSX )
2019-05-23 08:58:42 +02:00
// For correct rendering of the slider and value label under OSX
// we should use system default background
2019-05-22 17:08:02 +02:00
parent -> SetBackgroundStyle ( wxBG_STYLE_ERASE );
auto label = new wxStaticText ( parent , wxID_ANY , _ ( L ( "Icon size in a respect to the default size" )) + " (%) :" );
m_icon_size_sizer -> Add ( label , 0 , wxALIGN_CENTER_VERTICAL | wxRIGHT | ( isOSX ? 0 : wxLEFT ), em );
2019-05-22 13:51:02 +02:00
const int def_val = atoi ( app_config -> get ( "custom_toolbar_size" ). c_str ());
2019-05-22 17:08:02 +02:00
long style = wxSL_HORIZONTAL ;
if ( ! isOSX )
style |= wxSL_LABELS | wxSL_AUTOTICKS ;
2019-05-22 13:51:02 +02:00
2019-05-23 08:58:42 +02:00
auto slider = new wxSlider ( parent , wxID_ANY , def_val , 30 , 100 ,
2019-05-22 17:08:02 +02:00
wxDefaultPosition , wxDefaultSize , style );
2019-05-22 13:51:02 +02:00
2019-05-23 08:58:42 +02:00
slider -> SetTickFreq ( 10 );
slider -> SetPageSize ( 10 );
2019-05-22 13:51:02 +02:00
slider -> SetToolTip ( _ ( L ( "Select toolbar icon size in respect to the default one." )));
2019-05-22 17:08:02 +02:00
m_icon_size_sizer -> Add ( slider , 1 , wxEXPAND );
wxStaticText * val_label { nullptr };
if ( isOSX ) {
val_label = new wxStaticText ( parent , wxID_ANY , wxString :: Format ( "%d" , def_val ));
m_icon_size_sizer -> Add ( val_label , 0 , wxALIGN_CENTER_VERTICAL | wxLEFT , em );
}
slider -> Bind ( wxEVT_SLIDER , ([ this , slider , val_label ]( wxCommandEvent e ) {
2019-05-22 13:51:02 +02:00
auto val = slider -> GetValue ();
m_values [ "custom_toolbar_size" ] = ( boost :: format ( "%d" ) % val ). str ();
2019-05-22 17:08:02 +02:00
if ( val_label )
val_label -> SetLabelText ( wxString :: Format ( "%d" , val ));
2019-05-22 13:51:02 +02:00
}), slider -> GetId ());
2019-05-22 17:08:02 +02:00
for ( wxWindow * win : std :: vector < wxWindow *> { slider , label , val_label }) {
if ( ! win ) continue ;
win -> SetFont ( wxGetApp (). normal_font ());
2019-05-23 08:58:42 +02:00
if ( isOSX ) continue ; // under OSX we use wxBG_STYLE_ERASE
2019-05-22 17:08:02 +02:00
win -> SetBackgroundStyle ( wxBG_STYLE_PAINT );
}
2019-05-22 13:51:02 +02:00
m_optgroup -> sizer -> Add ( m_icon_size_sizer , 0 , wxEXPAND | wxALL , em );
}
2018-02-23 14:55:27 +01:00
} // GUI
} // Slic3r