2012-06-17 20:27:05 +00:00
package Slic3r::GUI::Tab ;
use strict ;
use warnings ;
use utf8 ;
2012-06-19 12:47:02 +00:00
use File::Basename qw( basename ) ;
2012-06-18 20:27:57 +00:00
use List::Util qw( first ) ;
2014-06-14 17:59:59 +00:00
use Wx qw( :bookctrl :dialog :keycode :icon :id :misc :panel :sizer :treectrl :window
wxTheApp ) ;
2012-07-24 12:17:10 +00:00
use Wx::Event qw( EVT_BUTTON EVT_CHOICE EVT_KEY_DOWN EVT_TREE_SEL_CHANGED ) ;
2012-06-18 14:46:43 +00:00
use base 'Wx::Panel' ;
2012-06-17 20:27:05 +00:00
sub new {
my $ class = shift ;
2012-07-18 18:36:34 +00:00
my ( $ parent , % params ) = @ _ ;
2012-07-24 10:42:58 +00:00
my $ self = $ class - > SUPER:: new ( $ parent , - 1 , wxDefaultPosition , wxDefaultSize , wxBK_LEFT | wxTAB_TRAVERSAL ) ;
2012-07-27 19:13:03 +00:00
$ self - > { options } = [] ; # array of option names handled by this tab
2013-03-09 15:43:09 +00:00
$ self - > { $ _ } = $ params { $ _ } for qw( on_value_change on_presets_changed ) ;
2012-06-19 15:23:10 +00:00
2012-06-18 20:27:57 +00:00
# horizontal sizer
2012-07-01 17:24:06 +00:00
$ self - > { sizer } = Wx::BoxSizer - > new ( wxHORIZONTAL ) ;
2012-06-18 14:46:43 +00:00
$ self - > { sizer } - > SetSizeHints ( $ self ) ;
$ self - > SetSizer ( $ self - > { sizer } ) ;
2013-03-09 15:27:18 +00:00
# left vertical sizer
my $ left_sizer = Wx::BoxSizer - > new ( wxVERTICAL ) ;
$ self - > { sizer } - > Add ( $ left_sizer , 0 , wxEXPAND | wxLEFT | wxTOP | wxBOTTOM , 3 ) ;
my $ left_col_width = 150 ;
# preset chooser
{
2012-06-18 20:27:57 +00:00
2013-03-09 15:27:18 +00:00
# choice menu
$ self - > { presets_choice } = Wx::Choice - > new ( $ self , - 1 , wxDefaultPosition , [ $ left_col_width , - 1 ] , [] ) ;
$ self - > { presets_choice } - > SetFont ( $ Slic3r:: GUI:: small_font ) ;
2012-10-22 14:03:08 +00:00
2013-03-09 15:27:18 +00:00
# buttons
$ self - > { btn_save_preset } = Wx::BitmapButton - > new ( $ self , - 1 , Wx::Bitmap - > new ( "$Slic3r::var/disk.png" , wxBITMAP_TYPE_PNG ) ) ;
$ self - > { btn_delete_preset } = Wx::BitmapButton - > new ( $ self , - 1 , Wx::Bitmap - > new ( "$Slic3r::var/delete.png" , wxBITMAP_TYPE_PNG ) ) ;
$ self - > { btn_save_preset } - > SetToolTipString ( "Save current " . lc ( $ self - > title ) ) ;
$ self - > { btn_delete_preset } - > SetToolTipString ( "Delete this preset" ) ;
$ self - > { btn_delete_preset } - > Disable ;
2012-10-22 14:03:08 +00:00
2013-03-09 15:27:18 +00:00
### These cause GTK warnings:
###my $box = Wx::StaticBox->new($self, -1, "Presets:", wxDefaultPosition, [$left_col_width, 50]);
###my $hsizer = Wx::StaticBoxSizer->new($box, wxHORIZONTAL);
2012-06-18 20:27:57 +00:00
2013-03-09 15:27:18 +00:00
my $ hsizer = Wx::BoxSizer - > new ( wxHORIZONTAL ) ;
2012-06-18 20:27:57 +00:00
2013-03-09 15:27:18 +00:00
$ left_sizer - > Add ( $ hsizer , 0 , wxEXPAND | wxBOTTOM , 5 ) ;
$ hsizer - > Add ( $ self - > { presets_choice } , 1 , wxRIGHT | wxALIGN_CENTER_VERTICAL , 3 ) ;
$ hsizer - > Add ( $ self - > { btn_save_preset } , 0 , wxALIGN_CENTER_VERTICAL ) ;
$ hsizer - > Add ( $ self - > { btn_delete_preset } , 0 , wxALIGN_CENTER_VERTICAL ) ;
2013-01-03 14:49:20 +00:00
}
2012-06-18 20:27:57 +00:00
2013-03-09 15:27:18 +00:00
# tree
$ self - > { treectrl } = Wx::TreeCtrl - > new ( $ self , - 1 , wxDefaultPosition , [ $ left_col_width , - 1 ] , wxTR_NO_BUTTONS | wxTR_HIDE_ROOT | wxTR_SINGLE | wxTR_NO_LINES | wxBORDER_SUNKEN | wxWANTS_CHARS ) ;
$ left_sizer - > Add ( $ self - > { treectrl } , 1 , wxEXPAND ) ;
$ self - > { icons } = Wx::ImageList - > new ( 16 , 16 , 1 ) ;
$ self - > { treectrl } - > AssignImageList ( $ self - > { icons } ) ;
$ self - > { iconcount } = - 1 ;
$ self - > { treectrl } - > AddRoot ( "root" ) ;
$ self - > { pages } = [] ;
$ self - > { treectrl } - > SetIndent ( 0 ) ;
EVT_TREE_SEL_CHANGED ( $ parent , $ self - > { treectrl } , sub {
my $ page = first { $ _ - > { title } eq $ self - > { treectrl } - > GetItemText ( $ self - > { treectrl } - > GetSelection ) } @ { $ self - > { pages } }
or return ;
$ _ - > Hide for @ { $ self - > { pages } } ;
$ page - > Show ;
$ self - > { sizer } - > Layout ;
$ self - > Refresh ;
} ) ;
EVT_KEY_DOWN ( $ self - > { treectrl } , sub {
my ( $ treectrl , $ event ) = @ _ ;
if ( $ event - > GetKeyCode == WXK_TAB ) {
$ treectrl - > Navigate ( $ event - > ShiftDown ? & Wx:: wxNavigateBackward : & Wx:: wxNavigateForward ) ;
} else {
$ event - > Skip ;
2012-06-19 15:47:48 +00:00
}
2013-03-09 15:27:18 +00:00
} ) ;
EVT_CHOICE ( $ parent , $ self - > { presets_choice } , sub {
$ self - > on_select_preset ;
2013-03-09 15:43:09 +00:00
$ self - > on_presets_changed ;
2013-03-09 15:27:18 +00:00
} ) ;
2013-11-11 20:45:58 +00:00
EVT_BUTTON ( $ self , $ self - > { btn_save_preset } , sub { $ self - > save_preset } ) ;
2013-03-09 15:27:18 +00:00
EVT_BUTTON ( $ self , $ self - > { btn_delete_preset } , sub {
my $ i = $ self - > { presets_choice } - > GetSelection ;
return if $ i == 0 ; # this shouldn't happen but let's trap it anyway
my $ res = Wx::MessageDialog - > new ( $ self , "Are you sure you want to delete the selected preset?" , 'Delete Preset' , wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION ) - > ShowModal ;
return unless $ res == wxID_YES ;
if ( - e $ self - > { presets } [ $ i ] { file } ) {
unlink $ self - > { presets } [ $ i ] { file } ;
}
splice @ { $ self - > { presets } } , $ i , 1 ;
$ self - > set_dirty ( 0 ) ;
$ self - > { presets_choice } - > Delete ( $ i ) ;
$ self - > { presets_choice } - > SetSelection ( 0 ) ;
$ self - > on_select_preset ;
2013-03-09 15:43:09 +00:00
$ self - > on_presets_changed ;
2013-03-09 15:27:18 +00:00
} ) ;
$ self - > { config } = Slic3r::Config - > new ;
$ self - > build ;
if ( $ self - > hidden_options ) {
$ self - > { config } - > apply ( Slic3r::Config - > new_from_defaults ( $ self - > hidden_options ) ) ;
push @ { $ self - > { options } } , $ self - > hidden_options ;
2012-07-27 19:13:03 +00:00
}
2013-03-09 15:27:18 +00:00
$ self - > load_presets ;
2012-07-18 18:36:34 +00:00
2012-06-17 20:27:05 +00:00
return $ self ;
}
2012-07-15 15:54:57 +00:00
sub current_preset {
my $ self = shift ;
return $ self - > { presets } [ $ self - > { presets_choice } - > GetSelection ] ;
}
2012-08-07 16:44:47 +00:00
sub get_preset {
my $ self = shift ;
return $ self - > { presets } [ $ _ [ 0 ] ] ;
}
2013-11-11 20:45:58 +00:00
sub save_preset {
my ( $ self , $ name ) = @ _ ;
# since buttons (and choices too) don't get focus on Mac, we set focus manually
# to the treectrl so that the EVT_* events are fired for the input field having
# focus currently. is there anything better than this?
$ self - > { treectrl } - > SetFocus ;
if ( ! defined $ name ) {
my $ preset = $ self - > current_preset ;
my $ default_name = $ preset - > { default } ? 'Untitled' : basename ( $ preset - > { name } ) ;
$ default_name =~ s/\.ini$//i ;
my $ dlg = Slic3r::GUI::SavePresetWindow - > new ( $ self ,
title = > lc ( $ self - > title ) ,
default = > $ default_name ,
values = > [ map { my $ name = $ _ - > { name } ; $ name =~ s/\.ini$//i ; $ name } @ { $ self - > { presets } } ] ,
) ;
return unless $ dlg - > ShowModal == wxID_OK ;
$ name = $ dlg - > get_name ;
}
$ self - > config - > save ( sprintf "$Slic3r::GUI::datadir/%s/%s.ini" , $ self - > name , $ name ) ;
$ self - > set_dirty ( 0 ) ;
$ self - > load_presets ;
$ self - > { presets_choice } - > SetSelection ( first { basename ( $ self - > { presets } [ $ _ ] { file } ) eq $ name . ".ini" } 1 .. $# { $ self - > { presets } } ) ;
$ self - > on_select_preset ;
$ self - > on_presets_changed ;
}
2012-07-27 19:13:03 +00:00
# propagate event to the parent
sub on_value_change {
my $ self = shift ;
$ self - > { on_value_change } - > ( @ _ ) if $ self - > { on_value_change } ;
}
2013-03-09 15:43:09 +00:00
sub on_presets_changed {
my $ self = shift ;
$ self - > { on_presets_changed } - > ( [ $ self - > { presets_choice } - > GetStrings ] , $ self - > { presets_choice } - > GetSelection )
if $ self - > { on_presets_changed } ;
}
2012-07-18 18:36:34 +00:00
sub on_preset_loaded { }
2012-07-27 19:13:03 +00:00
sub hidden_options { }
sub config { $ _ [ 0 ] - > { config } - > clone }
2012-07-18 18:36:34 +00:00
2012-07-28 09:34:12 +00:00
sub select_default_preset {
my $ self = shift ;
$ self - > { presets_choice } - > SetSelection ( 0 ) ;
}
2012-08-07 16:44:47 +00:00
sub select_preset {
my $ self = shift ;
$ self - > { presets_choice } - > SetSelection ( $ _ [ 0 ] ) ;
$ self - > on_select_preset ;
}
2012-06-19 15:23:10 +00:00
sub on_select_preset {
my $ self = shift ;
if ( defined $ self - > { dirty } ) {
2012-07-27 12:11:04 +00:00
my $ name = $ self - > { dirty } == 0 ? 'Default preset' : "Preset \"$self->{presets}[$self->{dirty}]{name}\"" ;
my $ confirm = Wx::MessageDialog - > new ( $ self , "$name has unsaved changes. Discard changes and continue anyway?" ,
2012-07-27 11:57:58 +00:00
'Unsaved Changes' , wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION ) ;
if ( $ confirm - > ShowModal == wxID_NO ) {
$ self - > { presets_choice } - > SetSelection ( $ self - > { dirty } ) ;
return ;
}
2012-06-19 15:23:10 +00:00
$ self - > set_dirty ( 0 ) ;
}
2012-07-15 15:54:57 +00:00
my $ preset = $ self - > current_preset ;
2012-08-07 16:44:47 +00:00
my $ preset_config = $ self - > get_preset_config ( $ preset ) ;
eval {
local $ SIG { __WARN__ } = Slic3r::GUI:: warning_catcher ( $ self ) ;
foreach my $ opt_key ( @ { $ self - > { options } } ) {
2012-08-08 22:41:03 +00:00
$ self - > { config } - > set ( $ opt_key , $ preset_config - > get ( $ opt_key ) )
if $ preset_config - > has ( $ opt_key ) ;
2012-06-19 15:23:10 +00:00
}
2013-03-29 23:30:21 +00:00
( $ preset - > { default } || $ preset - > { external } )
? $ self - > { btn_delete_preset } - > Disable
: $ self - > { btn_delete_preset } - > Enable ;
$ self - > on_preset_loaded ;
$ self - > reload_values ;
$ self - > set_dirty ( 0 ) ;
$ Slic3r:: GUI:: Settings - > { presets } { $ self - > name } = $ preset - > { file } ? basename ( $ preset - > { file } ) : '' ;
2012-08-07 16:44:47 +00:00
} ;
2013-03-29 23:30:21 +00:00
if ( $@ ) {
$@ = "I was unable to load the selected config file: $@" ;
Slic3r::GUI:: catch_error ( $ self ) ;
$ self - > select_default_preset ;
}
2012-08-07 16:44:47 +00:00
2014-06-14 17:59:59 +00:00
wxTheApp - > save_settings ;
2012-06-19 15:23:10 +00:00
}
2012-08-07 16:44:47 +00:00
sub get_preset_config {
my $ self = shift ;
my ( $ preset ) = @ _ ;
2012-08-08 22:59:41 +00:00
if ( $ preset - > { default } ) {
return Slic3r::Config - > new_from_defaults ( @ { $ self - > { options } } ) ;
} else {
2012-08-07 16:44:47 +00:00
if ( ! - e $ preset - > { file } ) {
Slic3r::GUI:: show_error ( $ self , "The selected preset does not exist anymore ($preset->{file})." ) ;
return ;
}
2013-03-09 15:27:18 +00:00
# apply preset values on top of defaults
2012-08-08 17:36:34 +00:00
my $ external_config = Slic3r::Config - > load ( $ preset - > { file } ) ;
2012-08-08 22:59:41 +00:00
my $ config = Slic3r::Config - > new ;
2012-08-08 22:41:03 +00:00
$ config - > set ( $ _ , $ external_config - > get ( $ _ ) )
for grep $ external_config - > has ( $ _ ) , @ { $ self - > { options } } ;
2012-08-08 22:59:41 +00:00
return $ config ;
2012-08-07 16:44:47 +00:00
}
}
2012-06-18 20:27:57 +00:00
sub add_options_page {
2012-06-17 20:27:05 +00:00
my $ self = shift ;
2012-07-18 18:36:34 +00:00
my ( $ title , $ icon , % params ) = @ _ ;
2012-06-17 20:54:08 +00:00
2013-03-09 15:27:18 +00:00
if ( $ icon ) {
2012-07-18 18:36:34 +00:00
my $ bitmap = Wx::Bitmap - > new ( "$Slic3r::var/$icon" , wxBITMAP_TYPE_PNG ) ;
2012-06-18 14:46:43 +00:00
$ self - > { icons } - > Add ( $ bitmap ) ;
$ self - > { iconcount } + + ;
2012-06-17 20:54:08 +00:00
}
2012-07-18 18:36:34 +00:00
2012-07-27 19:13:03 +00:00
{
# get all config options being added to the current page; remove indexes; associate defaults
my @ options = map { $ _ =~ s/#.+// ; $ _ } grep ! ref ( $ _ ) , map @ { $ _ - > { options } } , @ { $ params { optgroups } } ;
my % defaults_to_set = map { $ _ = > 1 } @ options ;
# apply default values for the options we don't have already
2013-03-09 15:27:18 +00:00
delete $ defaults_to_set { $ _ } for @ { $ self - > { options } } ;
2012-07-27 19:13:03 +00:00
$ self - > { config } - > apply ( Slic3r::Config - > new_from_defaults ( keys % defaults_to_set ) ) if % defaults_to_set ;
# append such options to our list
push @ { $ self - > { options } } , @ options ;
}
2012-07-18 18:36:34 +00:00
my $ page = Slic3r::GUI::Tab::Page - > new ( $ self , $ title , $ self - > { iconcount } , % params , on_change = > sub {
$ self - > on_value_change ( @ _ ) ;
$ self - > set_dirty ( 1 ) ;
} ) ;
2013-03-09 15:27:18 +00:00
$ page - > Hide ;
2012-07-24 10:41:51 +00:00
$ self - > { sizer } - > Add ( $ page , 1 , wxEXPAND | wxLEFT , 5 ) ;
2012-07-18 18:36:34 +00:00
push @ { $ self - > { pages } } , $ page ;
$ self - > update_tree ;
return $ page ;
}
2012-07-24 13:30:50 +00:00
sub set_value {
my $ self = shift ;
my ( $ opt_key , $ value ) = @ _ ;
my $ changed = 0 ;
foreach my $ page ( @ { $ self - > { pages } } ) {
$ changed = 1 if $ page - > set_value ( $ opt_key , $ value ) ;
}
return $ changed ;
}
sub reload_values {
my $ self = shift ;
2013-12-22 00:27:09 +00:00
$ self - > set_value ( $ _ , $ self - > { config } - > get ( $ _ ) )
for @ { $ self - > { config } - > get_keys } ;
2012-07-24 13:30:50 +00:00
}
2012-07-18 18:36:34 +00:00
sub update_tree {
my $ self = shift ;
my ( $ select ) = @ _ ;
$ select // = 0 ; #/
my $ rootItem = $ self - > { treectrl } - > GetRootItem ;
$ self - > { treectrl } - > DeleteChildren ( $ rootItem ) ;
foreach my $ page ( @ { $ self - > { pages } } ) {
my $ itemId = $ self - > { treectrl } - > AppendItem ( $ rootItem , $ page - > { title } , $ page - > { iconID } ) ;
$ self - > { treectrl } - > SelectItem ( $ itemId ) if $ self - > { treectrl } - > GetChildrenCount ( $ rootItem ) == $ select + 1 ;
2012-06-18 20:27:57 +00:00
}
2012-06-17 20:27:05 +00:00
}
2012-06-18 20:27:57 +00:00
sub set_dirty {
my $ self = shift ;
my ( $ dirty ) = @ _ ;
2014-03-29 21:23:35 +00:00
return if $ dirty and $ self - > is_dirty ;
return if ( not $ dirty ) and ( not $ self - > is_dirty ) ;
2012-06-18 20:27:57 +00:00
2012-07-27 11:54:45 +00:00
my $ selection = $ self - > { presets_choice } - > GetSelection ;
my $ i = $ self - > { dirty } // $ selection ; #/
2012-06-18 20:27:57 +00:00
my $ text = $ self - > { presets_choice } - > GetString ( $ i ) ;
2012-07-15 15:54:57 +00:00
2012-06-18 20:27:57 +00:00
if ( $ dirty ) {
$ self - > { dirty } = $ i ;
if ( $ text !~ / \(modified\)$/ ) {
$ self - > { presets_choice } - > SetString ( $ i , "$text (modified)" ) ;
2012-07-27 11:54:45 +00:00
$ self - > { presets_choice } - > SetSelection ( $ selection ) ; # http://trac.wxwidgets.org/ticket/13769
2012-06-18 20:27:57 +00:00
}
} else {
$ self - > { dirty } = undef ;
$ text =~ s/ \(modified\)$// ;
$ self - > { presets_choice } - > SetString ( $ i , $ text ) ;
2012-07-27 11:54:45 +00:00
$ self - > { presets_choice } - > SetSelection ( $ selection ) ; # http://trac.wxwidgets.org/ticket/13769
2012-06-18 20:27:57 +00:00
}
2013-03-09 15:43:09 +00:00
$ self - > on_presets_changed ;
2012-06-18 20:27:57 +00:00
}
2012-06-23 15:38:19 +00:00
sub is_dirty {
my $ self = shift ;
2012-06-30 20:34:13 +00:00
return ( defined $ self - > { dirty } ) ;
2012-06-23 15:38:19 +00:00
}
2012-06-18 20:27:57 +00:00
sub load_presets {
my $ self = shift ;
2012-07-15 15:54:57 +00:00
$ self - > { presets } = [ {
default = > 1 ,
name = > '- default -' ,
} ] ;
2012-06-18 20:27:57 +00:00
2014-06-14 17:59:59 +00:00
my % presets = wxTheApp - > presets ( $ self - > name ) ;
2014-04-06 20:45:40 +00:00
foreach my $ preset_name ( sort keys % presets ) {
2012-07-15 15:54:57 +00:00
push @ { $ self - > { presets } } , {
2014-03-25 13:04:01 +00:00
name = > $ preset_name ,
file = > $ presets { $ preset_name } ,
2012-07-15 15:54:57 +00:00
} ;
}
2012-06-18 20:27:57 +00:00
$ self - > { presets_choice } - > Clear ;
2012-07-15 15:54:57 +00:00
$ self - > { presets_choice } - > Append ( $ _ - > { name } ) for @ { $ self - > { presets } } ;
2012-06-19 16:11:51 +00:00
{
2012-07-15 15:54:57 +00:00
# load last used preset
2012-07-27 19:13:03 +00:00
my $ i = first { basename ( $ self - > { presets } [ $ _ ] { file } ) eq ( $ Slic3r:: GUI:: Settings - > { presets } { $ self - > name } || '' ) } 1 .. $# { $ self - > { presets } } ;
2012-07-15 15:54:57 +00:00
$ self - > { presets_choice } - > SetSelection ( $ i || 0 ) ;
2012-06-20 15:17:07 +00:00
$ self - > on_select_preset ;
2012-06-19 16:11:51 +00:00
}
2013-03-09 15:43:09 +00:00
$ self - > on_presets_changed ;
2012-06-18 20:27:57 +00:00
}
2012-06-17 20:27:05 +00:00
2013-03-09 15:27:18 +00:00
sub load_config_file {
2012-06-19 12:47:02 +00:00
my $ self = shift ;
my ( $ file ) = @ _ ;
2013-03-09 15:27:18 +00:00
# look for the loaded config among the existing menu items
my $ i = first { $ self - > { presets } [ $ _ ] { file } eq $ file && $ self - > { presets } [ $ _ ] { external } } 1 .. $# { $ self - > { presets } } ;
if ( ! $ i ) {
my $ preset_name = basename ( $ file ) ; # keep the .ini suffix
push @ { $ self - > { presets } } , {
file = > $ file ,
name = > $ preset_name ,
external = > 1 ,
} ;
$ self - > { presets_choice } - > Append ( $ preset_name ) ;
$ i = $# { $ self - > { presets } } ;
2012-06-19 12:47:02 +00:00
}
2013-03-09 15:27:18 +00:00
$ self - > { presets_choice } - > SetSelection ( $ i ) ;
$ self - > on_select_preset ;
2013-03-09 15:43:09 +00:00
$ self - > on_presets_changed ;
2012-06-19 12:47:02 +00:00
}
2012-06-18 20:27:57 +00:00
package Slic3r::GUI::Tab::Print ;
2012-06-17 20:27:05 +00:00
use base 'Slic3r::GUI::Tab' ;
2012-07-27 19:13:03 +00:00
sub name { 'print' }
2012-07-18 18:36:34 +00:00
sub title { 'Print Settings' }
sub build {
my $ self = shift ;
2012-06-17 20:27:05 +00:00
2012-06-18 20:27:57 +00:00
$ self - > add_options_page ( 'Layers and perimeters' , 'layers.png' , optgroups = > [
2012-06-17 20:27:05 +00:00
{
title = > 'Layer height' ,
options = > [ qw( layer_height first_layer_height ) ] ,
} ,
{
title = > 'Vertical shells' ,
2013-07-05 20:23:45 +00:00
options = > [ qw( perimeters spiral_vase ) ] ,
2012-06-17 20:27:05 +00:00
} ,
{
title = > 'Horizontal shells' ,
2012-10-25 10:21:04 +00:00
options = > [ qw( top_solid_layers bottom_solid_layers ) ] ,
2012-10-25 09:24:56 +00:00
lines = > [
{
label = > 'Solid layers' ,
2012-10-25 10:21:04 +00:00
options = > [ qw( top_solid_layers bottom_solid_layers ) ] ,
2012-10-25 09:24:56 +00:00
} ,
] ,
2012-06-17 20:27:05 +00:00
} ,
2013-07-05 19:57:56 +00:00
{
title = > 'Quality (slower slicing)' ,
2014-05-22 17:34:49 +00:00
options = > [ qw( extra_perimeters avoid_crossing_perimeters thin_walls overhangs ) ] ,
2013-07-05 20:06:58 +00:00
lines = > [
Slic3r::GUI::OptionsGroup - > single_option_line ( 'extra_perimeters' ) ,
Slic3r::GUI::OptionsGroup - > single_option_line ( 'avoid_crossing_perimeters' ) ,
2013-07-05 20:10:43 +00:00
Slic3r::GUI::OptionsGroup - > single_option_line ( 'thin_walls' ) ,
2013-07-06 09:35:40 +00:00
Slic3r::GUI::OptionsGroup - > single_option_line ( 'overhangs' ) ,
2013-07-05 20:06:58 +00:00
] ,
2013-07-05 19:57:56 +00:00
} ,
2012-08-23 13:42:58 +00:00
{
title = > 'Advanced' ,
2014-05-24 20:10:28 +00:00
options = > [ qw( seam_position external_perimeters_first ) ] ,
2012-08-23 13:42:58 +00:00
} ,
2012-06-17 20:27:05 +00:00
] ) ;
2012-06-18 20:27:57 +00:00
$ self - > add_options_page ( 'Infill' , 'shading.png' , optgroups = > [
2012-06-17 20:27:05 +00:00
{
title = > 'Infill' ,
2012-08-07 18:22:26 +00:00
options = > [ qw( fill_density fill_pattern solid_fill_pattern ) ] ,
} ,
2013-07-05 19:55:01 +00:00
{
2013-07-06 00:46:09 +00:00
title = > 'Reducing printing time' ,
2013-07-05 19:55:01 +00:00
options = > [ qw( infill_every_layers infill_only_where_needed ) ] ,
} ,
2012-08-07 18:22:26 +00:00
{
title = > 'Advanced' ,
2013-07-05 19:55:01 +00:00
options = > [ qw( solid_infill_every_layers fill_angle
2013-03-10 17:15:44 +00:00
solid_infill_below_area only_retract_when_crossing_perimeters infill_first ) ] ,
2012-06-17 20:27:05 +00:00
} ,
] ) ;
2012-06-18 20:27:57 +00:00
$ self - > add_options_page ( 'Speed' , 'time.png' , optgroups = > [
2012-06-17 20:27:05 +00:00
{
title = > 'Speed for print moves' ,
2014-05-21 13:21:20 +00:00
options = > [ qw( perimeter_speed small_perimeter_speed external_perimeter_speed infill_speed solid_infill_speed top_solid_infill_speed support_material_speed support_material_interface_speed bridge_speed gap_fill_speed ) ] ,
2012-06-17 20:27:05 +00:00
} ,
{
title = > 'Speed for non-print moves' ,
options = > [ qw( travel_speed ) ] ,
} ,
{
2012-06-18 08:19:24 +00:00
title = > 'Modifiers' ,
2012-06-17 20:27:05 +00:00
options = > [ qw( first_layer_speed ) ] ,
} ,
2013-01-10 14:29:40 +00:00
{
title = > 'Acceleration control (advanced)' ,
2013-08-09 12:30:43 +00:00
options = > [ qw( perimeter_acceleration infill_acceleration bridge_acceleration first_layer_acceleration default_acceleration ) ] ,
2013-01-10 14:29:40 +00:00
} ,
2012-06-17 20:27:05 +00:00
] ) ;
2012-07-18 13:48:04 +00:00
$ self - > add_options_page ( 'Skirt and brim' , 'box.png' , optgroups = > [
2012-06-17 20:27:05 +00:00
{
title = > 'Skirt' ,
2012-10-29 10:17:57 +00:00
options = > [ qw( skirts skirt_distance skirt_height min_skirt_length ) ] ,
2012-06-17 20:27:05 +00:00
} ,
2012-07-18 13:48:04 +00:00
{
title = > 'Brim' ,
options = > [ qw( brim_width ) ] ,
} ,
2012-06-17 20:27:05 +00:00
] ) ;
2012-06-18 20:27:57 +00:00
$ self - > add_options_page ( 'Support material' , 'building.png' , optgroups = > [
2012-06-17 20:27:05 +00:00
{
title = > 'Support material' ,
2013-02-04 14:48:57 +00:00
options = > [ qw( support_material support_material_threshold support_material_enforce_layers ) ] ,
2012-06-17 20:27:05 +00:00
} ,
2013-01-28 13:12:01 +00:00
{
title = > 'Raft' ,
options = > [ qw( raft_layers ) ] ,
} ,
2013-02-03 16:23:50 +00:00
{
title = > 'Options for support material and raft' ,
options = > [ qw( support_material_pattern support_material_spacing support_material_angle
2014-04-26 15:19:50 +00:00
support_material_interface_layers support_material_interface_spacing
dont_support_bridges ) ] ,
2012-06-17 20:27:05 +00:00
} ,
] ) ;
2012-06-18 20:27:57 +00:00
$ self - > add_options_page ( 'Notes' , 'note.png' , optgroups = > [
2012-06-17 20:27:05 +00:00
{
title = > 'Notes' ,
2012-06-17 21:24:10 +00:00
no_labels = > 1 ,
2012-06-17 20:27:05 +00:00
options = > [ qw( notes ) ] ,
} ,
] ) ;
2012-06-18 20:27:57 +00:00
$ self - > add_options_page ( 'Output options' , 'page_white_go.png' , optgroups = > [
2012-06-17 20:27:05 +00:00
{
title = > 'Sequential printing' ,
options = > [ qw( complete_objects extruder_clearance_radius extruder_clearance_height ) ] ,
2012-10-25 10:37:02 +00:00
lines = > [
Slic3r::GUI::OptionsGroup - > single_option_line ( 'complete_objects' ) ,
{
label = > 'Extruder clearance (mm)' ,
options = > [ qw( extruder_clearance_radius extruder_clearance_height ) ] ,
} ,
] ,
2012-06-17 20:27:05 +00:00
} ,
{
title = > 'Output file' ,
options = > [ qw( gcode_comments output_filename_format ) ] ,
} ,
{
2012-06-17 21:24:10 +00:00
title = > 'Post-processing scripts' ,
no_labels = > 1 ,
2012-06-18 09:26:21 +00:00
options = > [ qw( post_process ) ] ,
2012-06-17 20:27:05 +00:00
} ,
] ) ;
2012-08-07 18:14:28 +00:00
$ self - > add_options_page ( 'Multiple Extruders' , 'funnel.png' , optgroups = > [
{
2014-03-26 23:01:33 +00:00
title = > 'Extruders' ,
2013-07-29 18:49:54 +00:00
options = > [ qw( perimeter_extruder infill_extruder support_material_extruder support_material_interface_extruder ) ] ,
2012-08-07 18:14:28 +00:00
} ,
2013-09-18 15:45:02 +00:00
{
2013-11-15 15:01:15 +00:00
title = > 'Ooze prevention' ,
options = > [ qw( ooze_prevention standby_temperature_delta ) ] ,
2013-09-18 15:45:02 +00:00
} ,
2014-03-25 00:11:28 +00:00
{
title = > 'Advanced' ,
options = > [ qw( interface_shells ) ] ,
} ,
2012-08-07 18:14:28 +00:00
] ) ;
2012-06-18 20:27:57 +00:00
$ self - > add_options_page ( 'Advanced' , 'wrench.png' , optgroups = > [
2012-06-17 20:27:05 +00:00
{
title = > 'Extrusion width' ,
2012-06-18 12:29:47 +00:00
label_width = > 180 ,
2014-06-09 19:14:48 +00:00
options = > [ qw( extrusion_width first_layer_extrusion_width perimeter_extrusion_width external_perimeter_extrusion_width infill_extrusion_width solid_infill_extrusion_width top_infill_extrusion_width support_material_extrusion_width ) ] ,
2012-06-17 20:27:05 +00:00
} ,
{
title = > 'Flow' ,
options = > [ qw( bridge_flow_ratio ) ] ,
} ,
2013-03-16 18:58:34 +00:00
{
2012-06-18 09:26:21 +00:00
title = > 'Other' ,
2014-06-10 11:28:57 +00:00
options = > [ ( $ Slic3r:: have_threads ? qw( threads ) : ( ) ) , qw( resolution xy_size_compensation ) ] ,
2013-03-16 18:58:34 +00:00
} ,
2012-06-17 20:27:05 +00:00
] ) ;
}
2012-07-27 19:13:03 +00:00
sub hidden_options { ! $ Slic3r:: have_threads ? qw( threads ) : ( ) }
2012-06-18 12:29:47 +00:00
package Slic3r::GUI::Tab::Filament ;
use base 'Slic3r::GUI::Tab' ;
2012-07-27 19:13:03 +00:00
sub name { 'filament' }
2012-07-18 18:36:34 +00:00
sub title { 'Filament Settings' }
sub build {
my $ self = shift ;
2012-06-18 12:29:47 +00:00
2012-06-18 20:27:57 +00:00
$ self - > add_options_page ( 'Filament' , 'spool.png' , optgroups = > [
2012-06-18 12:29:47 +00:00
{
title = > 'Filament' ,
2012-07-18 13:48:04 +00:00
options = > [ 'filament_diameter#0' , 'extrusion_multiplier#0' ] ,
2012-06-18 12:29:47 +00:00
} ,
{
2012-10-25 10:37:02 +00:00
title = > 'Temperature (°C)' ,
2012-07-18 13:48:04 +00:00
options = > [ 'temperature#0' , 'first_layer_temperature#0' , qw( bed_temperature first_layer_bed_temperature ) ] ,
2012-10-25 10:37:02 +00:00
lines = > [
{
label = > 'Extruder' ,
options = > [ 'first_layer_temperature#0' , 'temperature#0' ] ,
} ,
{
label = > 'Bed' ,
options = > [ qw( first_layer_bed_temperature bed_temperature ) ] ,
} ,
] ,
2012-06-18 12:29:47 +00:00
} ,
] ) ;
2012-06-18 20:27:57 +00:00
$ self - > add_options_page ( 'Cooling' , 'hourglass.png' , optgroups = > [
2012-06-18 12:29:47 +00:00
{
title = > 'Enable' ,
2013-05-13 16:33:44 +00:00
options = > [ qw( fan_always_on cooling ) ] ,
2012-10-28 11:43:41 +00:00
lines = > [
2013-05-13 16:33:44 +00:00
Slic3r::GUI::OptionsGroup - > single_option_line ( 'fan_always_on' ) ,
2012-10-28 11:43:41 +00:00
Slic3r::GUI::OptionsGroup - > single_option_line ( 'cooling' ) ,
{
label = > '' ,
widget = > ( $ self - > { description_line } = Slic3r::GUI::OptionsGroup::StaticTextLine - > new ) ,
} ,
] ,
2012-06-18 12:29:47 +00:00
} ,
{
title = > 'Fan settings' ,
2013-05-13 16:33:44 +00:00
options = > [ qw( min_fan_speed max_fan_speed bridge_fan_speed disable_fan_first_layers ) ] ,
2012-10-25 10:37:02 +00:00
lines = > [
{
label = > 'Fan speed' ,
2012-10-28 11:43:41 +00:00
options = > [ qw( min_fan_speed max_fan_speed ) ] ,
2012-10-25 10:37:02 +00:00
} ,
2012-10-28 11:43:41 +00:00
Slic3r::GUI::OptionsGroup - > single_option_line ( 'bridge_fan_speed' ) ,
2012-10-25 10:37:02 +00:00
Slic3r::GUI::OptionsGroup - > single_option_line ( 'disable_fan_first_layers' ) ,
] ,
2012-06-18 12:29:47 +00:00
} ,
{
title = > 'Cooling thresholds' ,
label_width = > 250 ,
options = > [ qw( fan_below_layer_time slowdown_below_layer_time min_print_speed ) ] ,
} ,
] ) ;
}
2012-10-28 11:43:41 +00:00
sub _update_description {
my $ self = shift ;
my $ config = $ self - > config ;
my $ msg = "" ;
2013-05-10 13:09:27 +00:00
my $ fan_other_layers = $ config - > fan_always_on
? sprintf "will always run at %d%%%s." , $ config - > min_fan_speed ,
( $ config - > disable_fan_first_layers > 1
? " except for the first " . $ config - > disable_fan_first_layers . " layers"
: $ config - > disable_fan_first_layers == 1
? " except for the first layer"
: "" )
: "will be turned off." ;
2012-10-28 11:43:41 +00:00
if ( $ config - > cooling ) {
2013-09-16 08:09:39 +00:00
$ msg = sprintf "If estimated layer time is below ~%ds, fan will run at %d%% and print speed will be reduced so that no less than %ds are spent on that layer (however, speed will never be reduced below %dmm/s)." ,
$ config - > slowdown_below_layer_time , $ config - > max_fan_speed , $ config - > slowdown_below_layer_time , $ config - > min_print_speed ;
2012-10-28 11:43:41 +00:00
if ( $ config - > fan_below_layer_time > $ config - > slowdown_below_layer_time ) {
$ msg . = sprintf "\nIf estimated layer time is greater, but still below ~%ds, fan will run at a proportionally decreasing speed between %d%% and %d%%." ,
$ config - > fan_below_layer_time , $ config - > max_fan_speed , $ config - > min_fan_speed ;
}
2013-05-10 13:09:27 +00:00
$ msg . = "\nDuring the other layers, fan $fan_other_layers"
} else {
$ msg = "Fan $fan_other_layers" ;
2012-10-28 11:43:41 +00:00
}
2013-03-09 15:27:18 +00:00
$ self - > { description_line } - > SetText ( $ msg ) ;
2012-10-28 11:43:41 +00:00
}
sub on_value_change {
my $ self = shift ;
my ( $ opt_key ) = @ _ ;
$ self - > SUPER:: on_value_change ( @ _ ) ;
$ self - > _update_description ;
}
2012-06-17 20:27:05 +00:00
package Slic3r::GUI::Tab::Printer ;
use base 'Slic3r::GUI::Tab' ;
2012-07-27 19:13:03 +00:00
sub name { 'printer' }
2012-07-18 18:36:34 +00:00
sub title { 'Printer Settings' }
sub build {
my $ self = shift ;
2012-06-17 20:27:05 +00:00
2012-07-24 13:30:50 +00:00
$ self - > { extruders_count } = 1 ;
2012-06-18 20:27:57 +00:00
$ self - > add_options_page ( 'General' , 'printer_empty.png' , optgroups = > [
2012-06-17 20:27:05 +00:00
{
title = > 'Size and coordinates' ,
options = > [ qw( bed_size print_center z_offset ) ] ,
} ,
{
title = > 'Firmware' ,
options = > [ qw( gcode_flavor use_relative_e_distances ) ] ,
} ,
{
2014-04-05 07:54:43 +00:00
class = > 'Slic3r::GUI::OptionsGroup' ,
2012-07-18 18:36:34 +00:00
title = > 'Capabilities' ,
2012-07-24 13:30:50 +00:00
options = > [
{
opt_key = > 'extruders_count' ,
label = > 'Extruders' ,
tooltip = > 'Number of extruders of the printer.' ,
type = > 'i' ,
min = > 1 ,
default = > 1 ,
on_change = > sub { $ self - > { extruders_count } = $ _ [ 0 ] } ,
} ,
] ,
2012-06-17 20:27:05 +00:00
} ,
2012-12-05 14:08:17 +00:00
{
title = > 'Advanced' ,
2013-10-27 15:59:18 +00:00
options = > [ qw( use_firmware_retraction vibration_limit ) ] ,
2012-12-05 14:08:17 +00:00
} ,
2012-06-17 20:27:05 +00:00
] ) ;
2012-06-18 20:27:57 +00:00
$ self - > add_options_page ( 'Custom G-code' , 'cog.png' , optgroups = > [
2012-06-17 20:27:05 +00:00
{
2012-06-17 21:24:10 +00:00
title = > 'Start G-code' ,
no_labels = > 1 ,
options = > [ qw( start_gcode ) ] ,
} ,
{
title = > 'End G-code' ,
no_labels = > 1 ,
options = > [ qw( end_gcode ) ] ,
} ,
{
title = > 'Layer change G-code' ,
no_labels = > 1 ,
options = > [ qw( layer_gcode ) ] ,
2012-06-17 20:27:05 +00:00
} ,
2012-12-23 15:29:08 +00:00
{
title = > 'Tool change G-code' ,
no_labels = > 1 ,
options = > [ qw( toolchange_gcode ) ] ,
} ,
2012-06-17 20:27:05 +00:00
] ) ;
2012-07-18 18:36:34 +00:00
$ self - > { extruder_pages } = [] ;
2012-07-27 19:13:03 +00:00
$ self - > _build_extruder_pages ;
2012-07-18 18:36:34 +00:00
}
2013-03-18 20:20:32 +00:00
sub _extruder_options { qw( nozzle_diameter extruder_offset retract_length retract_lift retract_speed retract_restart_extra retract_before_travel wipe
2013-03-09 19:05:43 +00:00
retract_layer_change retract_length_toolchange retract_restart_extra_toolchange ) }
2012-07-18 18:36:34 +00:00
2012-07-27 19:13:03 +00:00
sub _build_extruder_pages {
2012-07-18 18:36:34 +00:00
my $ self = shift ;
2012-06-18 20:27:57 +00:00
2014-04-19 14:38:28 +00:00
my $ default_config = Slic3r::Config::Full - > new ;
foreach my $ extruder_idx ( @ { $ self - > { extruder_pages } } .. $ self - > { extruders_count } - 1 ) {
# extend options
foreach my $ opt_key ( $ self - > _extruder_options ) {
my $ values = $ self - > { config } - > get ( $ opt_key ) ;
2014-05-20 21:37:17 +00:00
if ( ! defined $ values ) {
$ values = [ $ default_config - > get_at ( $ opt_key , 0 ) ] ;
} else {
# use last extruder's settings for the new one
my $ last_value = $ values - > [ - 1 ] ;
$ values - > [ $ extruder_idx ] // = $ last_value ;
}
2014-04-19 14:38:28 +00:00
$ self - > { config } - > set ( $ opt_key , $ values )
or die "Unable to extend $opt_key" ;
}
# build page
$ self - > { extruder_pages } [ $ extruder_idx ] = $ self - > add_options_page ( "Extruder " . ( $ extruder_idx + 1 ) , 'funnel.png' , optgroups = > [
2012-07-18 18:36:34 +00:00
{
title = > 'Size' ,
options = > [ 'nozzle_diameter#' . $ extruder_idx ] ,
} ,
2012-08-08 22:51:53 +00:00
{
title = > 'Position (for multi-extruder printers)' ,
2012-08-07 19:39:45 +00:00
options = > [ 'extruder_offset#' . $ extruder_idx ] ,
2012-08-08 22:51:53 +00:00
} ,
2012-07-18 18:36:34 +00:00
{
title = > 'Retraction' ,
2012-08-07 19:08:56 +00:00
options = > [
map "${_}#${extruder_idx}" ,
2013-03-18 20:20:32 +00:00
qw( retract_length retract_lift retract_speed retract_restart_extra retract_before_travel retract_layer_change wipe )
2012-08-08 20:06:47 +00:00
] ,
2012-07-18 18:36:34 +00:00
} ,
2012-08-22 17:11:45 +00:00
{
title = > 'Retraction when tool is disabled (advanced settings for multi-extruder setups)' ,
options = > [
map "${_}#${extruder_idx}" ,
qw( retract_length_toolchange retract_restart_extra_toolchange )
] ,
} ,
2012-07-18 18:36:34 +00:00
] ) ;
$ self - > { extruder_pages } [ $ extruder_idx ] { disabled } = 0 ;
}
2014-04-19 14:38:28 +00:00
# remove extra pages
if ( $ self - > { extruders_count } <= $# { $ self - > { extruder_pages } } ) {
splice @ { $ self - > { extruder_pages } } , $ self - > { extruders_count } ;
}
# remove extra config values
foreach my $ opt_key ( $ self - > _extruder_options ) {
my $ values = $ self - > { config } - > get ( $ opt_key ) ;
splice @$ values , $ self - > { extruders_count } if $ self - > { extruders_count } <= $#$ values ;
$ self - > { config } - > set ( $ opt_key , $ values )
or die "Unable to truncate $opt_key" ;
}
2012-07-18 18:36:34 +00:00
# rebuild page list
@ { $ self - > { pages } } = (
( grep $ _ - > { title } !~ /^Extruder \d+/ , @ { $ self - > { pages } } ) ,
2012-07-24 13:30:50 +00:00
@ { $ self - > { extruder_pages } } [ 0 .. $ self - > { extruders_count } - 1 ] ,
2012-07-18 18:36:34 +00:00
) ;
}
sub on_value_change {
my $ self = shift ;
my ( $ opt_key ) = @ _ ;
$ self - > SUPER:: on_value_change ( @ _ ) ;
if ( $ opt_key eq 'extruders_count' ) {
2014-04-19 14:38:28 +00:00
# add extra pages or remove unused
2012-07-27 19:13:03 +00:00
$ self - > _build_extruder_pages ;
2012-07-18 18:36:34 +00:00
# update page list and select first page (General)
$ self - > update_tree ( 0 ) ;
}
}
2012-07-27 19:13:03 +00:00
# this gets executed after preset is loaded and before GUI fields are updated
2012-07-18 18:36:34 +00:00
sub on_preset_loaded {
my $ self = shift ;
# update the extruders count field
2012-07-20 12:41:27 +00:00
{
2012-07-24 13:30:50 +00:00
# update the GUI field according to the number of nozzle diameters supplied
2012-07-27 19:13:03 +00:00
$ self - > set_value ( 'extruders_count' , scalar @ { $ self - > { config } - > nozzle_diameter } ) ;
2012-07-18 18:36:34 +00:00
# update extruder page list
$ self - > on_value_change ( 'extruders_count' ) ;
}
2012-06-17 20:27:05 +00:00
}
2013-03-09 15:27:18 +00:00
sub load_config_file {
2012-08-07 18:14:28 +00:00
my $ self = shift ;
2013-03-09 15:27:18 +00:00
$ self - > SUPER:: load_config_file ( @ _ ) ;
2012-08-07 18:14:28 +00:00
Slic3r::GUI:: warning_catcher ( $ self ) - > (
"Your configuration was imported. However, Slic3r is currently only able to import settings "
. "for the first defined filament. We recommend you don't use exported configuration files "
. "for multi-extruder setups and rely on the built-in preset management system instead." )
if @ { $ self - > { config } - > nozzle_diameter } > 1 ;
}
2012-06-17 20:27:05 +00:00
package Slic3r::GUI::Tab::Page ;
2013-03-09 15:27:18 +00:00
use Wx qw( :misc :panel :sizer ) ;
2012-06-18 09:26:21 +00:00
use base 'Wx::ScrolledWindow' ;
2012-06-17 20:27:05 +00:00
sub new {
my $ class = shift ;
2012-07-18 18:36:34 +00:00
my ( $ parent , $ title , $ iconID , % params ) = @ _ ;
2012-07-24 10:42:58 +00:00
my $ self = $ class - > SUPER:: new ( $ parent , - 1 , wxDefaultPosition , wxDefaultSize , wxTAB_TRAVERSAL ) ;
2012-07-24 13:30:50 +00:00
$ self - > { optgroups } = [] ;
2012-07-18 18:36:34 +00:00
$ self - > { title } = $ title ;
$ self - > { iconID } = $ iconID ;
2012-06-17 20:27:05 +00:00
2012-06-18 09:26:21 +00:00
$ self - > SetScrollbars ( 1 , 1 , 1 , 1 ) ;
2013-03-09 13:55:07 +00:00
$ self - > { vsizer } = Wx::BoxSizer - > new ( wxVERTICAL ) ;
$ self - > SetSizer ( $ self - > { vsizer } ) ;
2012-06-17 20:27:05 +00:00
if ( $ params { optgroups } ) {
2013-03-09 15:27:18 +00:00
$ self - > append_optgroup (
%$ _ ,
config = > $ parent - > { config } ,
on_change = > $ params { on_change } ,
) for @ { $ params { optgroups } } ;
2013-03-09 13:55:07 +00:00
}
2012-06-17 20:27:05 +00:00
return $ self ;
}
sub append_optgroup {
my $ self = shift ;
2012-07-18 18:36:34 +00:00
my % params = @ _ ;
2012-06-17 20:27:05 +00:00
2012-10-25 09:24:56 +00:00
my $ class = $ params { class } || 'Slic3r::GUI::ConfigOptionsGroup' ;
my $ optgroup = $ class - > new (
2012-07-27 19:13:03 +00:00
parent = > $ self ,
config = > $ self - > GetParent - > { config } ,
label_width = > 200 ,
% params ,
) ;
2013-03-09 15:27:18 +00:00
$ self - > { vsizer } - > Add ( $ optgroup - > sizer , 0 , wxEXPAND | wxALL , 5 ) ;
2012-07-24 13:30:50 +00:00
push @ { $ self - > { optgroups } } , $ optgroup ;
}
sub set_value {
my $ self = shift ;
my ( $ opt_key , $ value ) = @ _ ;
my $ changed = 0 ;
foreach my $ optgroup ( @ { $ self - > { optgroups } } ) {
$ changed = 1 if $ optgroup - > set_value ( $ opt_key , $ value ) ;
}
return $ changed ;
2012-06-17 20:27:05 +00:00
}
2012-06-18 20:27:57 +00:00
package Slic3r::GUI::SavePresetWindow ;
2012-07-02 23:20:30 +00:00
use Wx qw( :combobox :dialog :id :misc :sizer ) ;
2012-06-21 11:01:59 +00:00
use Wx::Event qw( EVT_BUTTON EVT_TEXT_ENTER ) ;
2012-06-18 20:27:57 +00:00
use base 'Wx::Dialog' ;
sub new {
my $ class = shift ;
my ( $ parent , % params ) = @ _ ;
2012-07-02 23:20:30 +00:00
my $ self = $ class - > SUPER:: new ( $ parent , - 1 , "Save preset" , wxDefaultPosition , wxDefaultSize ) ;
2012-06-18 20:27:57 +00:00
2014-03-23 20:40:45 +00:00
my @ values = grep $ _ ne '- default -' , @ { $ params { values } } ;
2012-07-02 23:20:30 +00:00
my $ text = Wx::StaticText - > new ( $ self , - 1 , "Save " . lc ( $ params { title } ) . " as:" , wxDefaultPosition , wxDefaultSize ) ;
2014-03-23 20:40:45 +00:00
$ self - > { combo } = Wx::ComboBox - > new ( $ self , - 1 , $ params { default } , wxDefaultPosition , wxDefaultSize , \ @ values ,
2012-07-01 17:24:06 +00:00
wxTE_PROCESS_ENTER ) ;
my $ buttons = $ self - > CreateStdDialogButtonSizer ( wxOK | wxCANCEL ) ;
2012-06-18 20:27:57 +00:00
my $ sizer = Wx::BoxSizer - > new ( wxVERTICAL ) ;
$ sizer - > Add ( $ text , 0 , wxEXPAND | wxTOP | wxLEFT | wxRIGHT , 10 ) ;
2012-06-21 11:01:59 +00:00
$ sizer - > Add ( $ self - > { combo } , 0 , wxEXPAND | wxLEFT | wxRIGHT , 10 ) ;
2012-06-18 20:27:57 +00:00
$ sizer - > Add ( $ buttons , 0 , wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT , 10 ) ;
2012-07-01 17:24:06 +00:00
EVT_BUTTON ( $ self , wxID_OK , \ & accept ) ;
2012-06-21 11:01:59 +00:00
EVT_TEXT_ENTER ( $ self , $ self - > { combo } , \ & accept ) ;
2012-06-18 20:27:57 +00:00
$ self - > SetSizer ( $ sizer ) ;
$ sizer - > SetSizeHints ( $ self ) ;
return $ self ;
}
2012-06-21 11:01:59 +00:00
sub accept {
my ( $ self , $ event ) = @ _ ;
2012-07-15 16:55:01 +00:00
if ( ( $ self - > { chosen_name } = $ self - > { combo } - > GetValue ) ) {
2014-03-23 20:40:45 +00:00
if ( $ self - > { chosen_name } !~ /^[^<>:\/\\|?*\"]+$/i ) {
2012-08-06 12:23:00 +00:00
Slic3r::GUI:: show_error ( $ self , "The supplied name is not valid; the following characters are not allowed: <>:/\|?*\"" ) ;
2014-03-23 20:40:45 +00:00
} elsif ( $ self - > { chosen_name } eq '- default -' ) {
Slic3r::GUI:: show_error ( $ self , "The supplied name is not available." ) ;
} else {
$ self - > EndModal ( wxID_OK ) ;
2012-07-15 16:55:01 +00:00
}
2012-06-21 11:01:59 +00:00
}
}
2012-06-18 20:27:57 +00:00
sub get_name {
my $ self = shift ;
return $ self - > { chosen_name } ;
}
2012-06-17 20:27:05 +00:00
1 ;