Import config bundle automatically if found in application directory

This commit is contained in:
Alessandro Ranellucci 2015-12-07 12:17:06 +01:00
parent 7e1fac8f76
commit 32a333f16a
6 changed files with 50 additions and 9 deletions

1
.gitignore vendored
View File

@ -9,3 +9,4 @@ xs/buildtmp
MANIFEST.bak MANIFEST.bak
xs/MANIFEST.bak xs/MANIFEST.bak
xs/assertlib* xs/assertlib*
.init_bundle.ini

View File

@ -31,7 +31,8 @@ sub new_from_defaults {
my $self = $class->new; my $self = $class->new;
my $defaults = Slic3r::Config::Full->new; my $defaults = Slic3r::Config::Full->new;
if (@opt_keys) { if (@opt_keys) {
$self->set($_, $defaults->get($_)) for @opt_keys; $self->set($_, $defaults->get($_))
for grep $defaults->has($_), @opt_keys;
} else { } else {
$self->apply_static($defaults); $self->apply_static($defaults);
} }

View File

@ -5,6 +5,7 @@ use utf8;
use File::Basename qw(basename); use File::Basename qw(basename);
use FindBin; use FindBin;
use List::Util qw(first);
use Slic3r::GUI::2DBed; use Slic3r::GUI::2DBed;
use Slic3r::GUI::AboutDialog; use Slic3r::GUI::AboutDialog;
use Slic3r::GUI::BedShapeDialog; use Slic3r::GUI::BedShapeDialog;
@ -126,6 +127,22 @@ sub OnInit {
); );
$self->SetTopWindow($frame); $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)) { if (!$run_wizard && (!defined $last_version || $last_version ne $Slic3r::VERSION)) {
# user was running another Slic3r version on this computer # user was running another Slic3r version on this computer
if (!defined $last_version || $last_version =~ /^0\./) { if (!defined $last_version || $last_version =~ /^0\./) {

View File

@ -560,14 +560,16 @@ sub export_configbundle {
} }
sub load_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} || ''; if (!$file) {
my $dlg = Wx::FileDialog->new($self, 'Select configuration to load:', $dir, "config.ini", my $dir = $last_config ? dirname($last_config) : $Slic3r::GUI::Settings->{recent}{config_directory} || $Slic3r::GUI::Settings->{recent}{skein_directory} || '';
&Slic3r::GUI::FILE_WILDCARDS->{ini}, wxFD_OPEN | wxFD_FILE_MUST_EXIST); my $dlg = Wx::FileDialog->new($self, 'Select configuration to load:', $dir, "config.ini",
return unless $dlg->ShowModal == wxID_OK; &Slic3r::GUI::FILE_WILDCARDS->{ini}, wxFD_OPEN | wxFD_FILE_MUST_EXIST);
my $file = Slic3r::decode_path($dlg->GetPaths); return unless $dlg->ShowModal == wxID_OK;
$dlg->Destroy; $file = Slic3r::decode_path($dlg->GetPaths);
$dlg->Destroy;
}
$Slic3r::GUI::Settings->{recent}{config_directory} = dirname($file); $Slic3r::GUI::Settings->{recent}{config_directory} = dirname($file);
wxTheApp->save_settings; wxTheApp->save_settings;
@ -593,11 +595,23 @@ sub load_configbundle {
} }
} }
my $imported = 0; 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):(.+)$/; next unless $ini_category =~ /^(print|filament|printer):(.+)$/;
my ($section, $preset_name) = ($1, $2); my ($section, $preset_name) = ($1, $2);
my $config = Slic3r::Config->load_ini_hash($ini->{$ini_category}); 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); $config->save(sprintf "$Slic3r::GUI::datadir/%s/%s.ini", $section, $preset_name);
Slic3r::debugf "Imported %s preset %s\n", $section, $preset_name;
$imported++; $imported++;
} }
if ($self->{mode} eq 'expert') { if ($self->{mode} eq 'expert') {

View File

@ -493,6 +493,7 @@ sub build {
infill_overlap bridge_flow_ratio infill_overlap bridge_flow_ratio
xy_size_compensation threads resolution xy_size_compensation threads resolution
)); ));
$self->{config}->set('print_settings_id', '');
{ {
my $page = $self->add_options_page('Layers and perimeters', 'layers.png'); 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 min_fan_speed max_fan_speed bridge_fan_speed disable_fan_first_layers
fan_below_layer_time slowdown_below_layer_time min_print_speed 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'); 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 retract_lift retract_speed retract_restart_extra retract_before_travel retract_layer_change wipe
retract_length_toolchange retract_restart_extra_toolchange retract_length_toolchange retract_restart_extra_toolchange
)); ));
$self->{config}->set('printer_settings_id', '');
my $bed_shape_widget = sub { my $bed_shape_widget = sub {
my ($parent) = @_; my ($parent) = @_;

View File

@ -246,6 +246,8 @@ PrintConfigDef::build_def() {
Options["filament_diameter"].cli = "filament-diameter=f@"; Options["filament_diameter"].cli = "filament-diameter=f@";
Options["filament_diameter"].min = 0; Options["filament_diameter"].min = 0;
Options["filament_settings_id"].type = coString;
Options["fill_angle"].type = coInt; Options["fill_angle"].type = coInt;
Options["fill_angle"].label = "Fill angle"; Options["fill_angle"].label = "Fill angle";
Options["fill_angle"].category = "Infill"; Options["fill_angle"].category = "Infill";
@ -621,6 +623,9 @@ PrintConfigDef::build_def() {
Options["post_process"].full_width = true; Options["post_process"].full_width = true;
Options["post_process"].height = 60; 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"].type = coFloat;
Options["pressure_advance"].label = "Pressure advance"; 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."; 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.";