Enable/disable duplication controls

This commit is contained in:
Alessandro Ranellucci 2012-04-11 17:38:56 +02:00
parent e58ed195fd
commit e5abb0b9df
4 changed files with 30 additions and 3 deletions

View file

@ -139,6 +139,7 @@ our $skirt_height = 1; # layers
# transform options
our $scale = 1;
our $rotate = 0;
our $duplicate_mode = 'no';
our $duplicate = 1;
our $bed_size = [200,200];
our $duplicate_grid = [1,1];

View file

@ -395,6 +395,13 @@ our $Options = {
cli => 'rotate=i',
type => 'i',
},
'duplicate_mode' => {
label => 'Duplicate',
gui_only => 1,
type => 'select',
values => [qw(no autoarrange grid)],
labels => ['No', 'Autoarrange', 'Grid'],
},
'duplicate' => {
label => 'Copies (autoarrange)',
cli => 'duplicate=i',
@ -459,6 +466,7 @@ sub save {
open my $fh, '>', $file;
binmode $fh, ':utf8';
foreach my $opt (sort keys %$Options) {
next if $Options->{$opt}{gui_only};
my $value = get($opt);
$value = $Options->{$opt}{serialize}->($value) if $Options->{$opt}{serialize};
printf $fh "%s = %s\n", $opt, $value;
@ -624,6 +632,8 @@ sub validate {
|| (grep !$_, @$Slic3r::duplicate_grid);
die "Use either --duplicate or --duplicate-grid (using both doesn't make sense)\n"
if $Slic3r::duplicate > 1 && $Slic3r::duplicate_grid && (grep $_ && $_ > 1, @$Slic3r::duplicate_grid);
$Slic3r::duplicate_mode = 'autoarrange' if $Slic3r::duplicate > 1;
$Slic3r::duplicate_mode = 'grid' if grep $_ && $_ > 1, @$Slic3r::duplicate_grid;
# --duplicate-distance
die "Invalid value for --duplicate-distance\n"

View file

@ -8,7 +8,8 @@ use base 'Wx::StaticBoxSizer';
# not very elegant, but this solution is temporary waiting for a better GUI
our @reload_callbacks = ();
our @reload_callbacks = (\&update_duplicate_controls);
our %fields = (); # $key => [$control]
sub new {
my $class = shift;
@ -77,9 +78,13 @@ sub new {
$x_field->SetValue($value->[0]);
$y_field->SetValue($value->[1]);
};
$fields{$opt_key} = [$x_field, $y_field];
} elsif ($opt->{type} eq 'select') {
$field = Wx::Choice->new($parent, -1, Wx::wxDefaultPosition, Wx::wxDefaultSize, $opt->{labels} || $opt->{values});
EVT_CHOICE($parent, $field, sub { Slic3r::Config->set($opt_key, $opt->{values}[$field->GetSelection]) });
EVT_CHOICE($parent, $field, sub {
Slic3r::Config->set($opt_key, $opt->{values}[$field->GetSelection]);
update_duplicate_controls() if $opt_key eq 'duplicate_mode';
});
push @reload_callbacks, sub {
my $value = Slic3r::Config->get($opt_key);
$field->SetSelection(grep $opt->{values}[$_] eq $value, 0..$#{$opt->{values}});
@ -89,6 +94,7 @@ sub new {
die "Unsupported option type: " . $opt->{type};
}
$grid_sizer->Add($_) for $label, $field;
$fields{$opt_key} ||= [$field];
}
$self->Add($grid_sizer, 0, wxEXPAND);
@ -96,4 +102,12 @@ sub new {
return $self;
}
sub update_duplicate_controls {
my $value = Slic3r::Config->get('duplicate_mode');
$_->Enable($value eq 'autoarrange') for @{$fields{duplicate}};
$_->Enable($value eq 'autoarrange') for @{$fields{bed_size}};
$_->Enable($value eq 'grid') for @{$fields{duplicate_grid}};
$_->Enable($value ne 'no') for @{$fields{duplicate_distance}};
}
1;

View file

@ -61,7 +61,7 @@ sub new {
},
transform => {
title => 'Transform',
options => [qw(scale rotate duplicate bed_size duplicate_grid duplicate_distance)],
options => [qw(scale rotate duplicate_mode duplicate bed_size duplicate_grid duplicate_distance)],
},
gcode => {
title => 'Custom G-code',
@ -156,6 +156,8 @@ sub new {
$self->SetSizer($sizer);
$self->Layout;
$_->() for @Slic3r::GUI::OptionsGroup::reload_callbacks;
return $self;
}