Ditch --duplicate-x and --duplicate-y, add --duplicate-grid

This commit is contained in:
Alessandro Ranellucci 2012-04-11 15:58:09 +02:00
parent 761cb9d73e
commit 4ae551a424
6 changed files with 32 additions and 42 deletions

View File

@ -195,8 +195,7 @@ The author is Alessandro Ranellucci (me).
--scale Factor for scaling input object (default: 1) --scale Factor for scaling input object (default: 1)
--rotate Rotation angle in degrees (0-360, default: 0) --rotate Rotation angle in degrees (0-360, default: 0)
--duplicate Number of items with auto-arrange (1+, default: 1) --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-grid Number of items with grid arrangement (default: 1,1)
--duplicate-y Number of items along Y axis for manual arrangement (1+, default: 1)
--duplicate-distance Distance in mm between copies (default: 6) --duplicate-distance Distance in mm between copies (default: 6)
Miscellaneous options: Miscellaneous options:

View File

@ -140,8 +140,7 @@ our $skirt_height = 1; # layers
our $scale = 1; our $scale = 1;
our $rotate = 0; our $rotate = 0;
our $duplicate = 1; our $duplicate = 1;
our $duplicate_x = 1; our $duplicate_grid = [1,1];
our $duplicate_y = 1;
our $duplicate_distance = 6; # mm our $duplicate_distance = 6; # mm
sub parallelize { sub parallelize {

View File

@ -5,6 +5,9 @@ use utf8;
use constant PI => 4 * atan2(1, 1); 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 = { our $Options = {
# miscellaneous options # miscellaneous options
@ -397,17 +400,12 @@ our $Options = {
cli => 'duplicate=i', cli => 'duplicate=i',
type => 'i', type => 'i',
}, },
'duplicate_x' => { 'duplicate_grid' => {
label => 'Copies along X', label => 'Copies (grid)',
cli => 'duplicate-x=i', cli => 'duplicate-grid=s',
type => 'i', type => 'point',
aliases => [qw(multiply_x)], serialize => sub { join ',', @{$_[0]} },
}, deserialize => sub { [ split /,/, $_[0] ] },
'duplicate_y' => {
label => 'Copies along Y',
cli => 'duplicate-y=i',
type => 'i',
aliases => [qw(multiply_y)],
}, },
'duplicate_distance' => { 'duplicate_distance' => {
label => 'Distance between copies', label => 'Distance between copies',
@ -465,6 +463,8 @@ sub load {
my $class = shift; my $class = shift;
my ($file) = @_; my ($file) = @_;
my %ignore = map { $_ => 1 } @Ignore;
local $/ = "\n"; local $/ = "\n";
open my $fh, '<', $file; open my $fh, '<', $file;
binmode $fh, ':utf8'; binmode $fh, ':utf8';
@ -475,6 +475,7 @@ sub load {
next if /^\s*#/; next if /^\s*#/;
/^(\w+) = (.*)/ or die "Unreadable configuration file (invalid data at line $.)\n"; /^(\w+) = (.*)/ or die "Unreadable configuration file (invalid data at line $.)\n";
my $key = $1; my $key = $1;
next if $ignore{$key};
if (!exists $Options->{$key}) { if (!exists $Options->{$key}) {
$key = +(grep { $Options->{$_}{aliases} && grep $_ eq $key, @{$Options->{$_}{aliases}} } $key = +(grep { $Options->{$_}{aliases} && grep $_ eq $key, @{$Options->{$_}{aliases}} }
keys %$Options)[0] or warn "Unknown option $1 at line $.\n"; keys %$Options)[0] or warn "Unknown option $1 at line $.\n";
@ -611,21 +612,11 @@ sub validate {
if $Slic3r::scale <= 0; if $Slic3r::scale <= 0;
# --duplicate # --duplicate
die "Invalid value for --duplicate\n" die "Invalid value for --duplicate or --duplicate-grid\n"
if $Slic3r::duplicate < 1; if !$Slic3r::duplicate || $Slic3r::duplicate < 1 || !$Slic3r::duplicate_grid
|| (grep !$_, @$Slic3r::duplicate_grid);
# --duplicate-x die "Use either --duplicate or --duplicate-grid (using both doesn't make sense)\n"
die "Invalid value for --duplicate-x\n" if $Slic3r::duplicate > 1 && $Slic3r::duplicate_grid && (grep $_ && $_ > 1, @$Slic3r::duplicate_grid);
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;
}
# --duplicate-distance # --duplicate-distance
die "Invalid value for --duplicate-distance\n" die "Invalid value for --duplicate-distance\n"

View File

@ -4,6 +4,7 @@ use warnings;
use utf8; use utf8;
use File::Basename qw(basename dirname); 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 use Wx qw(:sizer :progressdialog wxOK wxICON_INFORMATION wxICON_WARNING wxICON_ERROR wxICON_QUESTION
wxOK wxCANCEL wxID_OK wxFD_OPEN wxFD_SAVE wxDEFAULT wxNORMAL); wxOK wxCANCEL wxID_OK wxFD_OPEN wxFD_SAVE wxDEFAULT wxNORMAL);
use Wx::Event qw(EVT_BUTTON); use Wx::Event qw(EVT_BUTTON);
@ -60,7 +61,7 @@ sub new {
}, },
transform => { transform => {
title => 'Transform', title => 'Transform',
options => [qw(scale rotate duplicate duplicate_x duplicate_y duplicate_distance)], options => [qw(scale rotate duplicate duplicate_grid duplicate_distance)],
}, },
gcode => { gcode => {
title => 'Custom G-code', title => 'Custom G-code',
@ -172,7 +173,8 @@ sub do_slice {
Slic3r::Config->validate; Slic3r::Config->validate;
# confirm slicing of more than one copies # 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) { if ($copies > 1) {
my $confirmation = Wx::MessageDialog->new($self, "Are you sure you want to slice $copies copies?", my $confirmation = Wx::MessageDialog->new($self, "Are you sure you want to slice $copies copies?",
'Confirm', wxICON_QUESTION | wxOK | wxCANCEL); 'Confirm', wxICON_QUESTION | wxOK | wxCANCEL);

View File

@ -158,13 +158,13 @@ sub BUILD {
my $dist = scale $Slic3r::duplicate_distance; my $dist = scale $Slic3r::duplicate_distance;
if ($Slic3r::duplicate_x > 1 || $Slic3r::duplicate_y > 1) { if ($Slic3r::duplicate_grid->[X] > 1 || $Slic3r::duplicate_grid->[Y] > 1) {
$self->total_x_length($self->x_length * $Slic3r::duplicate_x + $dist * ($Slic3r::duplicate_x - 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_y + $dist * ($Slic3r::duplicate_y - 1)); $self->total_y_length($self->y_length * $Slic3r::duplicate_grid->[Y] + $dist * ($Slic3r::duplicate_grid->[Y] - 1));
# generate offsets for copies # generate offsets for copies
for my $x_copy (1..$Slic3r::duplicate_x) { for my $x_copy (1..$Slic3r::duplicate_grid->[X]) {
for my $y_copy (1..$Slic3r::duplicate_y) { for my $y_copy (1..$Slic3r::duplicate_grid->[Y]) {
push @{$self->copies}, [ push @{$self->copies}, [
($self->x_length + $dist) * ($x_copy-1), ($self->x_length + $dist) * ($x_copy-1),
($self->y_length + $dist) * ($y_copy-1), ($self->y_length + $dist) * ($y_copy-1),

View File

@ -224,8 +224,7 @@ $j
--scale Factor for scaling input object (default: $Slic3r::scale) --scale Factor for scaling input object (default: $Slic3r::scale)
--rotate Rotation angle in degrees (0-360, default: $Slic3r::rotate) --rotate Rotation angle in degrees (0-360, default: $Slic3r::rotate)
--duplicate Number of items with auto-arrange (1+, default: $Slic3r::duplicate) --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-grid Number of items with grid arrangement (default: $Slic3r::duplicate_grid->[0],$Slic3r::duplicate_grid->[1])
--duplicate-y Number of items along Y axis for manual arrangement (1+, default: $Slic3r::duplicate_y)
--duplicate-distance Distance in mm between copies (default: $Slic3r::duplicate_distance) --duplicate-distance Distance in mm between copies (default: $Slic3r::duplicate_distance)
Miscellaneous options: Miscellaneous options: