Adapt GUI to new XS Config

xs-config
Alessandro Ranellucci 2013-12-22 01:27:09 +01:00
parent 4515d90052
commit 9fb62e671f
5 changed files with 44 additions and 13 deletions

View File

@ -21,9 +21,15 @@ our $Options = print_config_def();
sub new_from_defaults { sub new_from_defaults {
my $class = shift; my $class = shift;
my (@opt_keys) = @_;
my $self = $class->new; my $self = $class->new;
$self->apply_static(Slic3r::Config::Print->new); my $defaults = Slic3r::Config::Print->new;
if (@opt_keys) {
$self->set($_, $defaults->get($_)) for @opt_keys;
} else {
$self->apply_static($defaults);
}
return $self; return $self;
} }
@ -71,7 +77,12 @@ sub load {
my $ini = __PACKAGE__->read_ini($file); my $ini = __PACKAGE__->read_ini($file);
my $config = __PACKAGE__->new; my $config = __PACKAGE__->new;
$config->set_deserialize(handle_legacy($_, $ini->{_}{$_})) for keys %{$ini->{_}}; foreach my $opt_key (keys %{$ini->{_}}) {
print "key: $opt_key\n";
($opt_key, my $value) = handle_legacy($opt_key, $ini->{_}{$opt_key});
next if !defined $opt_key;
$config->set_deserialize($opt_key, $value);
}
return $config; return $config;
} }
@ -97,7 +108,7 @@ sub handle_legacy {
my ($opt_key, $value) = @_; my ($opt_key, $value) = @_;
# handle legacy options # handle legacy options
return if first { $_ eq $opt_key } @Ignore; return ($opt_key, $value) if first { $_ eq $opt_key } @Ignore;
if ($opt_key =~ /^(extrusion_width|bottom_layer_speed|first_layer_height)_ratio$/) { if ($opt_key =~ /^(extrusion_width|bottom_layer_speed|first_layer_height)_ratio$/) {
$opt_key = $1; $opt_key = $1;
$opt_key =~ s/^bottom_layer_speed$/first_layer_speed/; $opt_key =~ s/^bottom_layer_speed$/first_layer_speed/;
@ -125,7 +136,7 @@ sub handle_legacy {
my @keys = grep { $Options->{$_}{aliases} && grep $_ eq $opt_key, @{$Options->{$_}{aliases}} } keys %$Options; my @keys = grep { $Options->{$_}{aliases} && grep $_ eq $opt_key, @{$Options->{$_}{aliases}} } keys %$Options;
if (!@keys) { if (!@keys) {
warn "Unknown option $opt_key\n"; warn "Unknown option $opt_key\n";
return; return ();
} }
$opt_key = $keys[0]; $opt_key = $keys[0];
} }
@ -173,8 +184,6 @@ sub validate {
# -j, --threads # -j, --threads
die "Invalid value for --threads\n" die "Invalid value for --threads\n"
if $self->threads < 1; if $self->threads < 1;
die "Your perl wasn't built with multithread support\n"
if $self->threads > 1 && !$Slic3r::have_threads;
# --layer-height # --layer-height
die "Invalid value for --layer-height\n" die "Invalid value for --layer-height\n"

View File

@ -381,9 +381,17 @@ sub _set_config {
my ($opt_key, $index, $value) = @_; my ($opt_key, $index, $value) = @_;
my ($get_m, $serialized) = $self->_config_methods($opt_key, $index); my ($get_m, $serialized) = $self->_config_methods($opt_key, $index);
defined $index if (defined $index) {
? $self->config->$get_m($opt_key)->[$index] = $value my $values = $self->config->$get_m($opt_key);
: $self->config->set($opt_key, $value, $serialized); $values->[$index] = $value;
$self->config->set($opt_key, $values);
} else {
if ($serialized) {
$self->config->set_deserialize($opt_key, $value);
} else {
$self->config->set($opt_key, $value);
}
}
} }
sub _config_methods { sub _config_methods {

View File

@ -686,6 +686,9 @@ sub export_gcode {
catch_error => sub { Slic3r::GUI::catch_error($self, @_) && $self->on_export_failed }, catch_error => sub { Slic3r::GUI::catch_error($self, @_) && $self->on_export_failed },
); );
} }
# this method gets executed in a separate thread by wxWidgets since it's a button handler
Slic3r::thread_cleanup() if $Slic3r::have_threads;
} }
sub export_gcode2 { sub export_gcode2 {
@ -766,6 +769,9 @@ sub export_stl {
my $output_file = $self->_get_export_file('STL') or return; my $output_file = $self->_get_export_file('STL') or return;
Slic3r::Format::STL->write_file($output_file, $self->make_model, binary => 1); Slic3r::Format::STL->write_file($output_file, $self->make_model, binary => 1);
$self->statusbar->SetStatusText("STL file exported to $output_file"); $self->statusbar->SetStatusText("STL file exported to $output_file");
# this method gets executed in a separate thread by wxWidgets since it's a button handler
Slic3r::thread_cleanup() if $Slic3r::have_threads;
} }
sub export_amf { sub export_amf {
@ -774,6 +780,9 @@ sub export_amf {
my $output_file = $self->_get_export_file('AMF') or return; my $output_file = $self->_get_export_file('AMF') or return;
Slic3r::Format::AMF->write_file($output_file, $self->make_model); Slic3r::Format::AMF->write_file($output_file, $self->make_model);
$self->statusbar->SetStatusText("AMF file exported to $output_file"); $self->statusbar->SetStatusText("AMF file exported to $output_file");
# this method gets executed in a separate thread by wxWidgets since it's a menu handler
Slic3r::thread_cleanup() if $Slic3r::have_threads;
} }
sub _get_export_file { sub _get_export_file {
@ -850,7 +859,9 @@ sub make_thumbnail {
}; };
@_ = (); @_ = ();
$Slic3r::have_threads ? threads->create($cb)->detach : $cb->(); $Slic3r::have_threads
? threads->create(sub { $cb->(); Slic3r::thread_cleanup(); })->detach
: $cb->();
} }
sub on_thumbnail_made { sub on_thumbnail_made {

View File

@ -305,7 +305,7 @@ sub load_config {
my ($config) = @_; my ($config) = @_;
foreach my $tab (values %{$self->{options_tabs}}) { foreach my $tab (values %{$self->{options_tabs}}) {
$tab->set_value($_, $config->$_) for keys %$config; $tab->set_value($_, $config->$_) for @{$config->get_keys};
} }
} }

View File

@ -291,7 +291,8 @@ sub set_value {
sub reload_values { sub reload_values {
my $self = shift; my $self = shift;
$self->set_value($_, $self->{config}->get($_)) for keys %{$self->{config}}; $self->set_value($_, $self->{config}->get($_))
for @{$self->{config}->get_keys};
} }
sub update_tree { sub update_tree {
@ -735,7 +736,9 @@ sub config {
# remove all unused values # remove all unused values
foreach my $opt_key ($self->_extruder_options) { foreach my $opt_key ($self->_extruder_options) {
splice @{ $config->{$opt_key} }, $self->{extruders_count}; my $values = $config->get($opt_key);
splice @$values, $self->{extruders_count};
$config->set($opt_key, $values);
} }
return $config; return $config;