diff --git a/.gitignore b/.gitignore index d9fd6c074..62e52ce4e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ xs/buildtmp MANIFEST.bak xs/MANIFEST.bak xs/assertlib* +.init_bundle.ini \ No newline at end of file diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm index 9ba2c4c10..db7ff9691 100644 --- a/lib/Slic3r/Config.pm +++ b/lib/Slic3r/Config.pm @@ -31,7 +31,8 @@ sub new_from_defaults { my $self = $class->new; my $defaults = Slic3r::Config::Full->new; if (@opt_keys) { - $self->set($_, $defaults->get($_)) for @opt_keys; + $self->set($_, $defaults->get($_)) + for grep $defaults->has($_), @opt_keys; } else { $self->apply_static($defaults); } diff --git a/lib/Slic3r/GUI.pm b/lib/Slic3r/GUI.pm index 7b82de30b..077b5625b 100644 --- a/lib/Slic3r/GUI.pm +++ b/lib/Slic3r/GUI.pm @@ -5,6 +5,7 @@ use utf8; use File::Basename qw(basename); use FindBin; +use List::Util qw(first); use Slic3r::GUI::2DBed; use Slic3r::GUI::AboutDialog; use Slic3r::GUI::BedShapeDialog; @@ -126,6 +127,22 @@ sub OnInit { ); $self->SetTopWindow($frame); + # load init bundle + { + my @dirs = ($FindBin::Bin); + if (&Wx::wxMAC) { + push @dirs, qw(); + } elsif (&Wx::wxMSW) { + push @dirs, qw(); + } + my $init_bundle = first { -e $_ } map "$_/.init_bundle.ini", @dirs; + if ($init_bundle) { + Slic3r::debugf "Loading config bundle from %s\n", $init_bundle; + $self->{mainframe}->load_configbundle($init_bundle, 1); + $run_wizard = 0; + } + } + if (!$run_wizard && (!defined $last_version || $last_version ne $Slic3r::VERSION)) { # user was running another Slic3r version on this computer if (!defined $last_version || $last_version =~ /^0\./) { diff --git a/lib/Slic3r/GUI/MainFrame.pm b/lib/Slic3r/GUI/MainFrame.pm index 3ad443572..f4940b0d7 100644 --- a/lib/Slic3r/GUI/MainFrame.pm +++ b/lib/Slic3r/GUI/MainFrame.pm @@ -560,14 +560,16 @@ sub export_configbundle { } sub load_configbundle { - my $self = shift; + my ($self, $file, $skip_no_id) = @_; - my $dir = $last_config ? dirname($last_config) : $Slic3r::GUI::Settings->{recent}{config_directory} || $Slic3r::GUI::Settings->{recent}{skein_directory} || ''; - my $dlg = Wx::FileDialog->new($self, 'Select configuration to load:', $dir, "config.ini", - &Slic3r::GUI::FILE_WILDCARDS->{ini}, wxFD_OPEN | wxFD_FILE_MUST_EXIST); - return unless $dlg->ShowModal == wxID_OK; - my $file = Slic3r::decode_path($dlg->GetPaths); - $dlg->Destroy; + if (!$file) { + my $dir = $last_config ? dirname($last_config) : $Slic3r::GUI::Settings->{recent}{config_directory} || $Slic3r::GUI::Settings->{recent}{skein_directory} || ''; + my $dlg = Wx::FileDialog->new($self, 'Select configuration to load:', $dir, "config.ini", + &Slic3r::GUI::FILE_WILDCARDS->{ini}, wxFD_OPEN | wxFD_FILE_MUST_EXIST); + return unless $dlg->ShowModal == wxID_OK; + $file = Slic3r::decode_path($dlg->GetPaths); + $dlg->Destroy; + } $Slic3r::GUI::Settings->{recent}{config_directory} = dirname($file); wxTheApp->save_settings; @@ -593,11 +595,23 @@ sub load_configbundle { } } my $imported = 0; - foreach my $ini_category (sort keys %$ini) { + INI_BLOCK: foreach my $ini_category (sort keys %$ini) { next unless $ini_category =~ /^(print|filament|printer):(.+)$/; my ($section, $preset_name) = ($1, $2); my $config = Slic3r::Config->load_ini_hash($ini->{$ini_category}); + next if $skip_no_id && !$config->get($section . "_settings_id"); + + { + my %current_presets = Slic3r::GUI->presets($section); + my %current_ids = map { $_ => 1 } + grep $_, + map Slic3r::Config->load($_)->get($section . "_settings_id"), + values %current_presets; + next INI_BLOCK if exists $current_ids{$config->get($section . "_settings_id")}; + } + $config->save(sprintf "$Slic3r::GUI::datadir/%s/%s.ini", $section, $preset_name); + Slic3r::debugf "Imported %s preset %s\n", $section, $preset_name; $imported++; } if ($self->{mode} eq 'expert') { diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index e87f9828c..d7ec57d58 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -493,6 +493,7 @@ sub build { infill_overlap bridge_flow_ratio xy_size_compensation threads resolution )); + $self->{config}->set('print_settings_id', ''); { my $page = $self->add_options_page('Layers and perimeters', 'layers.png'); @@ -856,6 +857,7 @@ sub build { min_fan_speed max_fan_speed bridge_fan_speed disable_fan_first_layers fan_below_layer_time slowdown_below_layer_time min_print_speed )); + $self->{config}->set('filament_settings_id', ''); { my $page = $self->add_options_page('Filament', 'spool.png'); @@ -996,6 +998,7 @@ sub build { retract_length retract_lift retract_speed retract_restart_extra retract_before_travel retract_layer_change wipe retract_length_toolchange retract_restart_extra_toolchange )); + $self->{config}->set('printer_settings_id', ''); my $bed_shape_widget = sub { my ($parent) = @_; diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 7b24f44c3..93725d25b 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -245,6 +245,8 @@ PrintConfigDef::build_def() { Options["filament_diameter"].sidetext = "mm"; Options["filament_diameter"].cli = "filament-diameter=f@"; Options["filament_diameter"].min = 0; + + Options["filament_settings_id"].type = coString; Options["fill_angle"].type = coInt; Options["fill_angle"].label = "Fill angle"; @@ -621,6 +623,9 @@ PrintConfigDef::build_def() { Options["post_process"].full_width = true; Options["post_process"].height = 60; + Options["print_settings_id"].type = coString; + Options["printer_settings_id"].type = coString; + Options["pressure_advance"].type = coFloat; Options["pressure_advance"].label = "Pressure advance"; Options["pressure_advance"].tooltip = "When set to a non-zero value, this experimental option enables pressure regulation. It's the K constant for the advance algorithm that pushes more or less filament upon speed changes. It's useful for Bowden-tube extruders. Reasonable values are in range 0-10.";