diff --git a/README.markdown b/README.markdown index bc13c2f0e..f7749c8c0 100644 --- a/README.markdown +++ b/README.markdown @@ -195,14 +195,13 @@ The author is Alessandro Ranellucci (me). --scale Factor for scaling input object (default: 1) --rotate Rotation angle in degrees (0-360, default: 0) --duplicate Number of items with auto-arrange (1+, default: 1) - --duplicate-x Number of items along X axis for manual arrangement (1+, default: 1) - --duplicate-y Number of items along Y axis for manual arrangement (1+, default: 1) + --duplicate-grid Number of items with grid arrangement (default: 1,1) --duplicate-distance Distance in mm between copies (default: 6) - + Miscellaneous options: --notes Notes to be added as comments to the output file - Flow options (advanced): + Flow options (advanced): --extrusion-width-ratio Calculate the extrusion width as the layer height multiplied by this value (> 0, default: calculated automatically) diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm index 13ec74fbf..82f76c515 100644 --- a/lib/Slic3r.pm +++ b/lib/Slic3r.pm @@ -140,8 +140,7 @@ our $skirt_height = 1; # layers our $scale = 1; our $rotate = 0; our $duplicate = 1; -our $duplicate_x = 1; -our $duplicate_y = 1; +our $duplicate_grid = [1,1]; our $duplicate_distance = 6; # mm sub parallelize { diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm index 1db007ee7..786e2bf63 100644 --- a/lib/Slic3r/Config.pm +++ b/lib/Slic3r/Config.pm @@ -5,6 +5,9 @@ use utf8; use constant PI => 4 * atan2(1, 1); +# cemetery of old config settings +our @Ignore = qw(duplicate_x duplicate_y multiply_x multiply_y); + our $Options = { # miscellaneous options @@ -397,17 +400,12 @@ our $Options = { cli => 'duplicate=i', type => 'i', }, - 'duplicate_x' => { - label => 'Copies along X', - cli => 'duplicate-x=i', - type => 'i', - aliases => [qw(multiply_x)], - }, - 'duplicate_y' => { - label => 'Copies along Y', - cli => 'duplicate-y=i', - type => 'i', - aliases => [qw(multiply_y)], + 'duplicate_grid' => { + label => 'Copies (grid)', + cli => 'duplicate-grid=s', + type => 'point', + serialize => sub { join ',', @{$_[0]} }, + deserialize => sub { [ split /,/, $_[0] ] }, }, 'duplicate_distance' => { label => 'Distance between copies', @@ -465,6 +463,8 @@ sub load { my $class = shift; my ($file) = @_; + my %ignore = map { $_ => 1 } @Ignore; + local $/ = "\n"; open my $fh, '<', $file; binmode $fh, ':utf8'; @@ -475,6 +475,7 @@ sub load { next if /^\s*#/; /^(\w+) = (.*)/ or die "Unreadable configuration file (invalid data at line $.)\n"; my $key = $1; + next if $ignore{$key}; if (!exists $Options->{$key}) { $key = +(grep { $Options->{$_}{aliases} && grep $_ eq $key, @{$Options->{$_}{aliases}} } keys %$Options)[0] or warn "Unknown option $1 at line $.\n"; @@ -611,21 +612,11 @@ sub validate { if $Slic3r::scale <= 0; # --duplicate - die "Invalid value for --duplicate\n" - if $Slic3r::duplicate < 1; - - # --duplicate-x - die "Invalid value for --duplicate-x\n" - if $Slic3r::duplicate_x < 1; - - # --duplicate-y - die "Invalid value for --duplicate-y\n" - if $Slic3r::duplicate_y < 1; - - # reflect actual quantity in 'duplicate' setting for use with output-filename-format, ie both --duplicate 15 and --duplicate-x 3 --duplicate-y 5 will make an appropriate filename - if ($Slic3r::duplicate == 1 && (($Slic3r::duplicate_x > 1) || ($Slic3r::duplicate_y > 1))) { - $Slic3r::duplicate = $Slic3r::duplicate_x * $Slic3r::duplicate_y; - } + die "Invalid value for --duplicate or --duplicate-grid\n" + if !$Slic3r::duplicate || $Slic3r::duplicate < 1 || !$Slic3r::duplicate_grid + || (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); # --duplicate-distance die "Invalid value for --duplicate-distance\n" diff --git a/lib/Slic3r/GUI/SkeinPanel.pm b/lib/Slic3r/GUI/SkeinPanel.pm index a51dc78d2..e7b165fc6 100644 --- a/lib/Slic3r/GUI/SkeinPanel.pm +++ b/lib/Slic3r/GUI/SkeinPanel.pm @@ -4,6 +4,7 @@ use warnings; use utf8; use File::Basename qw(basename dirname); +use Slic3r::Geometry qw(X Y); use Wx qw(:sizer :progressdialog wxOK wxICON_INFORMATION wxICON_WARNING wxICON_ERROR wxICON_QUESTION wxOK wxCANCEL wxID_OK wxFD_OPEN wxFD_SAVE wxDEFAULT wxNORMAL); use Wx::Event qw(EVT_BUTTON); @@ -60,7 +61,7 @@ sub new { }, transform => { title => 'Transform', - options => [qw(scale rotate duplicate duplicate_x duplicate_y duplicate_distance)], + options => [qw(scale rotate duplicate duplicate_grid duplicate_distance)], }, gcode => { title => 'Custom G-code', @@ -172,7 +173,8 @@ sub do_slice { Slic3r::Config->validate; # confirm slicing of more than one copies - my $copies = Slic3r::Config->get('duplicate_x') * Slic3r::Config->get('duplicate_y'); + my $copies = $Slic3r::duplicate_grid->[X] * $Slic3r::duplicate_grid->[Y]; + $copies = $Slic3r::duplicate if $Slic3r::duplicate > 1; if ($copies > 1) { my $confirmation = Wx::MessageDialog->new($self, "Are you sure you want to slice $copies copies?", 'Confirm', wxICON_QUESTION | wxOK | wxCANCEL); diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 763ed1edb..442ed7772 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -158,13 +158,13 @@ sub BUILD { my $dist = scale $Slic3r::duplicate_distance; - if ($Slic3r::duplicate_x > 1 || $Slic3r::duplicate_y > 1) { - $self->total_x_length($self->x_length * $Slic3r::duplicate_x + $dist * ($Slic3r::duplicate_x - 1)); - $self->total_y_length($self->y_length * $Slic3r::duplicate_y + $dist * ($Slic3r::duplicate_y - 1)); + if ($Slic3r::duplicate_grid->[X] > 1 || $Slic3r::duplicate_grid->[Y] > 1) { + $self->total_x_length($self->x_length * $Slic3r::duplicate_grid->[X] + $dist * ($Slic3r::duplicate_grid->[X] - 1)); + $self->total_y_length($self->y_length * $Slic3r::duplicate_grid->[Y] + $dist * ($Slic3r::duplicate_grid->[Y] - 1)); # generate offsets for copies - for my $x_copy (1..$Slic3r::duplicate_x) { - for my $y_copy (1..$Slic3r::duplicate_y) { + for my $x_copy (1..$Slic3r::duplicate_grid->[X]) { + for my $y_copy (1..$Slic3r::duplicate_grid->[Y]) { push @{$self->copies}, [ ($self->x_length + $dist) * ($x_copy-1), ($self->y_length + $dist) * ($y_copy-1), diff --git a/slic3r.pl b/slic3r.pl index 62d4b6b14..fa943cfca 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -224,14 +224,13 @@ $j --scale Factor for scaling input object (default: $Slic3r::scale) --rotate Rotation angle in degrees (0-360, default: $Slic3r::rotate) --duplicate Number of items with auto-arrange (1+, default: $Slic3r::duplicate) - --duplicate-x Number of items along X axis for manual arrangement (1+, default: $Slic3r::duplicate_x) - --duplicate-y Number of items along Y axis for manual arrangement (1+, default: $Slic3r::duplicate_y) + --duplicate-grid Number of items with grid arrangement (default: $Slic3r::duplicate_grid->[0],$Slic3r::duplicate_grid->[1]) --duplicate-distance Distance in mm between copies (default: $Slic3r::duplicate_distance) Miscellaneous options: --notes Notes to be added as comments to the output file - Flow options (advanced): + Flow options (advanced): --extrusion-width-ratio Calculate the extrusion width as the layer height multiplied by this value (> 0, default: calculated automatically)