Merge pull request #467 from henrikbrixandersen/ratio-options

Two small ratio option improvements/bug fixes
This commit is contained in:
Henrik Brix Andersen 2012-06-19 06:44:16 -07:00
commit 8fcf24a766
2 changed files with 21 additions and 13 deletions

View file

@ -136,7 +136,7 @@ our $Options = {
},
'small_perimeter_speed' => {
label => 'Small perimeters (mm/s or %)',
cli => 'small-perimeter-speed=f',
cli => 'small-perimeter-speed=s',
type => 'f',
ratio_over => 'perimeter_speed',
},
@ -148,14 +148,14 @@ our $Options = {
},
'solid_infill_speed' => {
label => 'Solid infill (mm/s or %)',
cli => 'solid-infill-speed=f',
cli => 'solid-infill-speed=s',
type => 'f',
ratio_over => 'infill_speed',
aliases => [qw(solid_infill_feed_rate)],
},
'top_solid_infill_speed' => {
label => 'Top solid infill (mm/s or %)',
cli => 'top-solid-infill-speed=f',
cli => 'top-solid-infill-speed=s',
type => 'f',
ratio_over => 'solid_infill_speed',
},
@ -490,6 +490,14 @@ sub get {
return $value;
}
sub get_raw {
my $class = @_ == 2 ? shift : undef;
my ($opt_key) = @_;
no strict 'refs';
my $value = ${"Slic3r::$opt_key"};
return $value;
}
sub set {
my $class = @_ == 3 ? shift : undef;
my ($opt_key, $value) = @_;
@ -501,8 +509,8 @@ sub serialize {
my $class = @_ == 2 ? shift : undef;
my ($opt_key) = @_;
return $Options->{$opt_key}{serialize}
? $Options->{$opt_key}{serialize}->(get($opt_key))
: get($opt_key);
? $Options->{$opt_key}{serialize}->(get_raw($opt_key))
: get_raw($opt_key);
}
sub deserialize {
@ -521,7 +529,7 @@ sub save {
binmode $fh, ':utf8';
foreach my $opt (sort keys %$Options) {
next if $Options->{$opt}{gui_only};
my $value = get($opt);
my $value = get_raw($opt);
$value = $Options->{$opt}{serialize}->($value) if $Options->{$opt}{serialize};
printf $fh "%s = %s\n", $opt, $value;
}

View file

@ -44,7 +44,7 @@ sub new {
$size = Wx::Size->new($opt->{width} || -1, $opt->{height} || -1);
}
my ($get, $set) = $opt->{type} eq 's@' ? qw(serialize deserialize) : qw(get set);
my ($get, $set) = $opt->{type} eq 's@' ? qw(serialize deserialize) : qw(get_raw set);
$field = Wx::TextCtrl->new($parent, -1, Slic3r::Config->$get($opt_key),
Wx::wxDefaultPosition, $size, $style);
@ -52,13 +52,13 @@ sub new {
push @reload_callbacks, sub { $field->SetValue(Slic3r::Config->$get($opt_key)) };
} elsif ($opt->{type} eq 'bool') {
$field = Wx::CheckBox->new($parent, -1, "");
$field->SetValue(Slic3r::Config->get($opt_key));
$field->SetValue(Slic3r::Config->get_raw($opt_key));
EVT_CHECKBOX($parent, $field, sub { Slic3r::Config->set($opt_key, $field->GetValue) });
push @reload_callbacks, sub { $field->SetValue(Slic3r::Config->get($opt_key)) };
push @reload_callbacks, sub { $field->SetValue(Slic3r::Config->get_raw($opt_key)) };
} elsif ($opt->{type} eq 'point') {
$field = Wx::BoxSizer->new(wxHORIZONTAL);
my $field_size = Wx::Size->new(40, -1);
my $value = Slic3r::Config->get($opt_key);
my $value = Slic3r::Config->get_raw($opt_key);
$field->Add($_) for (
Wx::StaticText->new($parent, -1, "x:"),
my $x_field = Wx::TextCtrl->new($parent, -1, $value->[0], Wx::wxDefaultPosition, $field_size),
@ -67,14 +67,14 @@ sub new {
);
my $set_value = sub {
my ($i, $value) = @_;
my $val = Slic3r::Config->get($opt_key);
my $val = Slic3r::Config->get_raw($opt_key);
$val->[$i] = $value;
Slic3r::Config->set($opt_key, $val);
};
EVT_TEXT($parent, $x_field, sub { $set_value->(0, $x_field->GetValue) });
EVT_TEXT($parent, $y_field, sub { $set_value->(1, $y_field->GetValue) });
push @reload_callbacks, sub {
my $value = Slic3r::Config->get($opt_key);
my $value = Slic3r::Config->get_raw($opt_key);
$x_field->SetValue($value->[0]);
$y_field->SetValue($value->[1]);
};
@ -85,7 +85,7 @@ sub new {
Slic3r::Config->set($opt_key, $opt->{values}[$field->GetSelection]);
});
push @reload_callbacks, sub {
my $value = Slic3r::Config->get($opt_key);
my $value = Slic3r::Config->get_raw($opt_key);
$field->SetSelection(grep $opt->{values}[$_] eq $value, 0..$#{$opt->{values}});
};
$reload_callbacks[-1]->();