diff --git a/lib/Slic3r/GUI.pm b/lib/Slic3r/GUI.pm index c4fe92a04..aea900028 100644 --- a/lib/Slic3r/GUI.pm +++ b/lib/Slic3r/GUI.pm @@ -60,6 +60,7 @@ our $no_controller; our $no_plater; our $mode; our $autosave; +our $threads; our @cb; our $Settings = { @@ -70,8 +71,8 @@ our $Settings = { invert_zoom => 0, background_processing => 0, # If set, the "Controller" tab for the control of the printer over serial line and the serial port settings are hidden. - # By default, Prusa has the controller hidden. - no_controller => 1, + no_controller => 0, + threads => $Slic3r::Config::Options->{threads}{default}, }, }; @@ -121,16 +122,15 @@ sub OnInit { my $last_version; if (-f "$enc_datadir/slic3r.ini") { my $ini = eval { Slic3r::Config->read_ini("$datadir/slic3r.ini") }; - $Settings = $ini if $ini; - $last_version = $Settings->{_}{version}; - $Settings->{_}{mode} ||= 'expert'; - $Settings->{_}{autocenter} //= 1; - $Settings->{_}{invert_zoom} //= 0; - $Settings->{_}{background_processing} //= 1; - # If set, the "Controller" tab for the control of the printer over serial line and the serial port settings are hidden. - $Settings->{_}{no_controller} //= 1; + if ($ini) { + $last_version = $ini->{_}{version}; + $ini->{_}{$_} = $Settings->{_}{$_} + for grep !exists $ini->{_}{$_}, keys %{$Settings->{_}}; + $Settings = $ini; + } } $Settings->{_}{version} = $Slic3r::VERSION; + $Settings->{_}{threads} = $threads if $threads; $self->save_settings; # application frame diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index d8d11f3e2..c62067371 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -1157,6 +1157,10 @@ sub start_background_process { return; } + if ($Slic3r::GUI::Settings->{_}{threads}) { + $self->{print}->config->set('threads', $Slic3r::GUI::Settings->{_}{threads}); + } + # start thread @_ = (); $self->{process_thread} = Slic3r::spawn_thread(sub { diff --git a/lib/Slic3r/GUI/Preferences.pm b/lib/Slic3r/GUI/Preferences.pm index 91465fa64..231eb5cc9 100644 --- a/lib/Slic3r/GUI/Preferences.pm +++ b/lib/Slic3r/GUI/Preferences.pm @@ -67,6 +67,13 @@ sub new { default => $Slic3r::GUI::Settings->{_}{background_processing}, readonly => !$Slic3r::have_threads, )); + $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( + opt_id => 'threads', + type => 'i', + label => 'Threads', + tooltip => $Slic3r::Config::Options->{threads}{tooltip}, + default => $Slic3r::GUI::Settings->{_}{threads}, + )); $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( opt_id => 'no_controller', type => 'bool', diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index 6f772d2b7..a19bb1e76 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -497,7 +497,7 @@ sub build { external_perimeter_extrusion_width infill_extrusion_width solid_infill_extrusion_width top_infill_extrusion_width support_material_extrusion_width infill_overlap bridge_flow_ratio - xy_size_compensation threads resolution + xy_size_compensation resolution )); $self->{config}->set('print_settings_id', ''); @@ -686,7 +686,6 @@ sub build { { my $optgroup = $page->new_optgroup('Other'); $optgroup->append_single_option_line('xy_size_compensation'); - $optgroup->append_single_option_line('threads') if $Slic3r::have_threads; $optgroup->append_single_option_line('resolution'); } } diff --git a/lib/Slic3r/Print/Simple.pm b/lib/Slic3r/Print/Simple.pm index 9087ae0bc..26f1d4383 100644 --- a/lib/Slic3r/Print/Simple.pm +++ b/lib/Slic3r/Print/Simple.pm @@ -14,7 +14,7 @@ use Slic3r::Geometry::Clipper qw(diff); has '_print' => ( is => 'ro', default => sub { Slic3r::Print->new }, - handles => [qw(apply_config extruders output_filepath + handles => [qw(apply_config config extruders output_filepath total_used_filament total_extruded_volume placeholder_parser process)], ); diff --git a/slic3r.pl b/slic3r.pl index d4ebd5c48..69bb58593 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -29,6 +29,7 @@ my %cli_options = (); 'debug' => \$Slic3r::debug, 'gui' => \$opt{gui}, 'o|output=s' => \$opt{output}, + 'j|threads=i' => \$opt{threads}, 'save=s' => \$opt{save}, 'load=s@' => \$opt{load}, @@ -109,6 +110,7 @@ if ((!@ARGV || $opt{gui}) && !$opt{save} && eval "require Slic3r::GUI; 1") { $Slic3r::GUI::no_plater = $opt{no_plater}; $Slic3r::GUI::mode = $opt{gui_mode}; $Slic3r::GUI::autosave = $opt{autosave}; + $Slic3r::GUI::threads = $opt{threads}; } $gui = Slic3r::GUI->new; setlocale(LC_NUMERIC, 'C'); @@ -263,6 +265,7 @@ if (@ARGV) { # slicing from command line ); $sprint->apply_config($config); + $sprint->config->set('threads', $opt{threads}) if $opt{threads}; $sprint->set_model($model); if ($opt{export_svg}) { @@ -293,7 +296,7 @@ sub usage { my $j = ''; if ($Slic3r::have_threads) { $j = <<"EOF"; - -j, --threads Number of threads to use (1+, default: $config->{threads}) + -j, --threads Number of threads to use EOF } diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 586661510..1766f63cd 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -1383,7 +1383,6 @@ PrintConfigDef::PrintConfigDef() def = this->add("threads", coInt); def->label = "Threads"; def->tooltip = "Threads are used to parallelize long-running tasks. Optimal threads number is slightly above the number of available cores/processors."; - def->cli = "threads|j=i"; def->readonly = true; def->min = 1; { diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index bd63bb919..2ea423d8c 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -624,6 +624,7 @@ class CLIConfig ConfigOptionString save; ConfigOptionFloat scale; ConfigOptionPoint3 scale_to_fit; + ConfigOptionBool threads; CLIConfig() : ConfigBase(), StaticConfig() { this->def = &cli_config_def; @@ -647,6 +648,7 @@ class CLIConfig OPT_PTR(save); OPT_PTR(scale); OPT_PTR(scale_to_fit); + OPT_PTR(threads); return NULL; };