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,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)

View File

@ -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 {

View File

@ -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"

View File

@ -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);

View File

@ -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),

View File

@ -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)