Options on command line now override config. Also, "feed rate" was renamed to "speed" everywhere. #77

This commit is contained in:
Alessandro Ranellucci 2011-12-01 22:03:13 +01:00
parent 2a02d26ca5
commit e99c9f9e5f
6 changed files with 120 additions and 112 deletions

View File

@ -106,11 +106,11 @@ The author is Alessandro Ranellucci (me).
--temperature Extrusion temperature, set 0 to disable (default: 200) --temperature Extrusion temperature, set 0 to disable (default: 200)
Speed options: Speed options:
--print-feed-rate Speed of print moves in mm/sec (default: 60) --travel-speed Speed of non-print moves in mm/sec (default: 130)
--travel-feed-rate Speed of non-print moves in mm/sec (default: 130) --perimeter-speed Speed of print moves for perimeters in mm/sec (default: 30)
--perimeter-feed-rate --infill-speed Speed of print moves in mm/sec (default: 60)
Speed of print moves for perimeters in mm/sec (default: 60) --solid-infill-speed Speed of print moves for solid surfaces in mm/sec (default: 60)
--bridge-feed-rate Speed of bridge print moves in mm/sec (default: 60) --bridge-speed Speed of bridge print moves in mm/sec (default: 60)
--bottom-layer-speed-ratio --bottom-layer-speed-ratio
Factor to increase/decrease speeds on bottom Factor to increase/decrease speeds on bottom
layer by (default: 0.3) layer by (default: 0.3)

View File

@ -48,11 +48,11 @@ our $extrusion_multiplier = 1;
our $temperature = 200; our $temperature = 200;
# speed options # speed options
our $travel_feed_rate = 130; # mm/sec our $travel_speed = 130; # mm/sec
our $perimeter_feed_rate = 30; # mm/sec our $perimeter_speed = 30; # mm/sec
our $infill_feed_rate = 60; # mm/sec our $infill_speed = 60; # mm/sec
our $solid_infill_feed_rate = 60; # mm/sec our $solid_infill_speed = 60; # mm/sec
our $bridge_feed_rate = 60; # mm/sec our $bridge_speed = 60; # mm/sec
our $bottom_layer_speed_ratio = 0.3; our $bottom_layer_speed_ratio = 0.3;
# accuracy options # accuracy options

View File

@ -10,119 +10,158 @@ our $Options = {
# printer options # printer options
'nozzle_diameter' => { 'nozzle_diameter' => {
label => 'Nozzle diameter', label => 'Nozzle diameter',
cli => 'nozzle-diameter=f',
type => 'f', type => 'f',
}, },
'print_center' => { 'print_center' => {
label => 'Print center', label => 'Print center',
cli => 'print-center=s',
type => 'point', type => 'point',
serialize => sub { join ',', @{$_[0]} }, serialize => sub { join ',', @{$_[0]} },
deserialize => sub { [ split /,/, $_[0] ] }, deserialize => sub { [ split /,/, $_[0] ] },
}, },
'use_relative_e_distances' => { 'use_relative_e_distances' => {
label => 'Use relative E distances', label => 'Use relative E distances',
cli => 'use-relative-e-distances',
type => 'bool', type => 'bool',
}, },
'no_extrusion' => { 'no_extrusion' => {
label => 'No extrusion', label => 'No extrusion',
cli => 'no-extrusion',
type => 'bool', type => 'bool',
}, },
'z_offset' => { 'z_offset' => {
label => 'Z offset', label => 'Z offset',
cli => 'z-offset=f',
type => 'f', type => 'f',
}, },
'gcode_arcs' => {
label => 'Use native GCODE arcs',
cli => 'gcode-arcs',
type => 'bool',
},
'g0' => {
label => 'Use g0 for travel moves',
cli => 'g0',
type => 'bool',
},
# filament options # filament options
'filament_diameter' => { 'filament_diameter' => {
label => 'Diameter (mm)', label => 'Diameter (mm)',
cli => 'filament-diameter=f',
type => 'f', type => 'f',
}, },
'extrusion_multiplier' => { 'extrusion_multiplier' => {
label => 'Extrusion multiplier', label => 'Extrusion multiplier',
cli => 'extrusion-multiplier=f',
type => 'f', type => 'f',
aliases => [qw(filament_packing_density)], aliases => [qw(filament_packing_density)],
}, },
'temperature' => { 'temperature' => {
label => 'Temperature (°C)', label => 'Temperature (°C)',
cli => 'temperature=i',
type => 'i', type => 'i',
}, },
# speed options # speed options
'travel_feed_rate' => { 'travel_speed' => {
label => 'Travel (mm/s)', label => 'Travel (mm/s)',
cli => 'travel-speed=i',
type => 'f', type => 'f',
aliases => [qw(travel_feed_rate)],
}, },
'perimeter_feed_rate' => { 'perimeter_speed' => {
label => 'Perimeters (mm/s)', label => 'Perimeters (mm/s)',
cli => 'perimeter-speed=i',
type => 'f', type => 'f',
aliases => [qw(perimeter_feed_rate)],
}, },
'infill_feed_rate' => { 'infill_speed' => {
label => 'Infill (mm/s)', label => 'Infill (mm/s)',
cli => 'infill-speed=i',
type => 'f', type => 'f',
aliases => [qw(print_feed_rate)], aliases => [qw(print_feed_rate infill_feed_rate)],
}, },
'solid_infill_feed_rate' => { 'solid_infill_speed' => {
label => 'Solid infill (mm/s)', label => 'Solid infill (mm/s)',
cli => 'solid-infill-speed=i',
type => 'f', type => 'f',
aliases => [qw(solid_infill_feed_rate)],
}, },
'bridge_feed_rate' => { 'bridge_speed' => {
label => 'Bridges (mm/s)', label => 'Bridges (mm/s)',
cli => 'bridge-speed=i',
type => 'f', type => 'f',
aliases => [qw(bridge_feed_rate)],
}, },
'bottom_layer_speed_ratio' => { 'bottom_layer_speed_ratio' => {
label => 'Bottom layer speed ratio', label => 'Bottom layer speed ratio',
cli => 'bottom-layer-speed-ratio=f',
type => 'f', type => 'f',
}, },
# accuracy options # accuracy options
'layer_height' => { 'layer_height' => {
label => 'Layer height (mm)', label => 'Layer height (mm)',
cli => 'layer-height=f',
type => 'f', type => 'f',
}, },
'extrusion_width_ratio' => { 'extrusion_width_ratio' => {
label => 'Extrusion width (ratio over layer height; leave zero to calculate automatically)', label => 'Extrusion width (ratio over layer height; leave zero to calculate automatically)',
cli => 'extrusion-width-ratio=f',
type => 'f', type => 'f',
}, },
'first_layer_height_ratio' => { 'first_layer_height_ratio' => {
label => 'First layer height ratio', label => 'First layer height ratio',
cli => 'first-layer-height-ratio=f',
type => 'f', type => 'f',
}, },
'infill_every_layers' => { 'infill_every_layers' => {
label => 'Infill every N layers', label => 'Infill every N layers',
cli => 'infill-every-layers=i',
type => 'i', type => 'i',
}, },
# print options # print options
'perimeters' => { 'perimeters' => {
label => 'Perimeters', label => 'Perimeters',
cli => 'perimeters=i',
type => 'i', type => 'i',
aliases => [qw(perimeter_offsets)], aliases => [qw(perimeter_offsets)],
}, },
'solid_layers' => { 'solid_layers' => {
label => 'Solid layers', label => 'Solid layers',
cli => 'solid-layers=i',
type => 'i', type => 'i',
}, },
'fill_pattern' => { 'fill_pattern' => {
label => 'Fill pattern', label => 'Fill pattern',
cli => 'fill-pattern=s',
type => 'select', type => 'select',
values => [qw(rectilinear line concentric hilbertcurve archimedeanchords octagramspiral)], values => [qw(rectilinear line concentric hilbertcurve archimedeanchords octagramspiral)],
labels => [qw(rectilinear line concentric), 'hilbertcurve (slow)', 'archimedeanchords (slow)', 'octagramspiral (slow)'], labels => [qw(rectilinear line concentric), 'hilbertcurve (slow)', 'archimedeanchords (slow)', 'octagramspiral (slow)'],
}, },
'solid_fill_pattern' => { 'solid_fill_pattern' => {
label => 'Solid fill pattern', label => 'Solid fill pattern',
cli => 'solid-fill-pattern=s',
type => 'select', type => 'select',
values => [qw(rectilinear concentric hilbertcurve archimedeanchords octagramspiral)], values => [qw(rectilinear concentric hilbertcurve archimedeanchords octagramspiral)],
labels => [qw(rectilinear concentric), 'hilbertcurve (slow)', 'archimedeanchords (slow)', 'octagramspiral (slow)'], labels => [qw(rectilinear concentric), 'hilbertcurve (slow)', 'archimedeanchords (slow)', 'octagramspiral (slow)'],
}, },
'fill_density' => { 'fill_density' => {
label => 'Fill density', label => 'Fill density',
cli => 'fill-density=f',
type => 'f', type => 'f',
}, },
'fill_angle' => { 'fill_angle' => {
label => 'Fill angle (°)', label => 'Fill angle (°)',
cli => 'fill-angle=i',
type => 'i', type => 'i',
}, },
'start_gcode' => { 'start_gcode' => {
label => 'Start GCODE', label => 'Start GCODE',
cli => 'start-gcode=s',
type => 's', type => 's',
multiline => 1, multiline => 1,
width => 350, width => 350,
@ -132,6 +171,7 @@ our $Options = {
}, },
'end_gcode' => { 'end_gcode' => {
label => 'End GCODE', label => 'End GCODE',
cli => 'end-gcode=s',
type => 's', type => 's',
multiline => 1, multiline => 1,
width => 350, width => 350,
@ -143,60 +183,73 @@ our $Options = {
# retraction options # retraction options
'retract_length' => { 'retract_length' => {
label => 'Length (mm)', label => 'Length (mm)',
cli => 'retract-length=f',
type => 'f', type => 'f',
}, },
'retract_speed' => { 'retract_speed' => {
label => 'Speed (mm/s)', label => 'Speed (mm/s)',
cli => 'retract-speed=i',
type => 'i', type => 'i',
}, },
'retract_restart_extra' => { 'retract_restart_extra' => {
label => 'Extra length on restart (mm)', label => 'Extra length on restart (mm)',
cli => 'retract-restart-extra=f',
type => 'f', type => 'f',
}, },
'retract_before_travel' => { 'retract_before_travel' => {
label => 'Minimum travel after retraction (mm)', label => 'Minimum travel after retraction (mm)',
cli => 'retract-before-travel=f',
type => 'f', type => 'f',
}, },
'retract_lift' => { 'retract_lift' => {
label => 'Lift Z (mm)', label => 'Lift Z (mm)',
cli => 'retract-lift=f',
type => 'f', type => 'f',
}, },
# skirt options # skirt options
'skirts' => { 'skirts' => {
label => 'Loops', label => 'Loops',
cli => 'skirts=i',
type => 'i', type => 'i',
}, },
'skirt_distance' => { 'skirt_distance' => {
label => 'Distance from object (mm)', label => 'Distance from object (mm)',
cli => 'skirt-distance=i',
type => 'i', type => 'i',
}, },
'skirt_height' => { 'skirt_height' => {
label => 'Skirt height (layers)', label => 'Skirt height (layers)',
cli => 'skirt-height=i',
type => 'i', type => 'i',
}, },
# transform options # transform options
'scale' => { 'scale' => {
label => 'Scale', label => 'Scale',
cli => 'scale=f',
type => 'f', type => 'f',
}, },
'rotate' => { 'rotate' => {
label => 'Rotate (°)', label => 'Rotate (°)',
cli => 'rotate=i',
type => 'i', type => 'i',
}, },
'duplicate_x' => { 'duplicate_x' => {
label => 'Copies along X', label => 'Copies along X',
cli => 'duplicate-x=i',
type => 'i', type => 'i',
aliases => [qw(multiply_x)], aliases => [qw(multiply_x)],
}, },
'duplicate_y' => { 'duplicate_y' => {
label => 'Copies along Y', label => 'Copies along Y',
cli => 'duplicate-y=i',
type => 'i', type => 'i',
aliases => [qw(multiply_y)], aliases => [qw(multiply_y)],
}, },
'duplicate_distance' => { 'duplicate_distance' => {
label => 'Distance between copies', label => 'Distance between copies',
cli => 'duplicate-distance=i',
type => 'i', type => 'i',
aliases => [qw(multiply_distance)], aliases => [qw(multiply_distance)],
}, },
@ -260,7 +313,7 @@ sub validate_cli {
die "Invalid value for --${_}-gcode: file does not exist" die "Invalid value for --${_}-gcode: file does not exist"
if !-e $opt->{$_."_gcode"}; if !-e $opt->{$_."_gcode"};
open my $fh, "<", $opt->{$_."_gcode"}; open my $fh, "<", $opt->{$_."_gcode"};
set($_."_gcode", do { local $/; <$fh> }); $opt->{$_."_gcode"} = do { local $/; <$fh> };
close $fh; close $fh;
} }
} }
@ -361,8 +414,8 @@ sub validate {
if $Slic3r::skirt_height < 1; if $Slic3r::skirt_height < 1;
# legacy with existing config files # legacy with existing config files
$Slic3r::bridge_feed_rate ||= $Slic3r::infill_feed_rate; $Slic3r::bridge_speed ||= $Slic3r::infill_speed;
$Slic3r::solid_infill_feed_rate ||= $Slic3r::infill_feed_rate; $Slic3r::solid_infill_speed ||= $Slic3r::infill_speed;
} }
1; 1;

View File

@ -16,25 +16,25 @@ has 'last_f' => (is => 'rw', default => sub {0});
has 'dec' => (is => 'ro', default => sub { 3 } ); has 'dec' => (is => 'ro', default => sub { 3 } );
# calculate speeds # calculate speeds
has 'travel_feed_rate' => ( has 'travel_speed' => (
is => 'ro', is => 'ro',
default => sub { $Slic3r::travel_feed_rate * 60 }, # mm/min default => sub { $Slic3r::travel_speed * 60 }, # mm/min
); );
has 'perimeter_feed_rate' => ( has 'perimeter_speed' => (
is => 'ro', is => 'ro',
default => sub { $Slic3r::perimeter_feed_rate * 60 }, # mm/min default => sub { $Slic3r::perimeter_speed * 60 }, # mm/min
); );
has 'infill_feed_rate' => ( has 'infill_speed' => (
is => 'ro', is => 'ro',
default => sub { $Slic3r::infill_feed_rate * 60 }, # mm/min default => sub { $Slic3r::infill_speed * 60 }, # mm/min
); );
has 'solid_infill_feed_rate' => ( has 'solid_infill_speed' => (
is => 'ro', is => 'ro',
default => sub { $Slic3r::solid_infill_feed_rate * 60 }, # mm/min default => sub { $Slic3r::solid_infill_speed * 60 }, # mm/min
); );
has 'bridge_feed_rate' => ( has 'bridge_speed' => (
is => 'ro', is => 'ro',
default => sub { $Slic3r::bridge_feed_rate * 60 }, # mm/min default => sub { $Slic3r::bridge_speed * 60 }, # mm/min
); );
has 'retract_speed' => ( has 'retract_speed' => (
is => 'ro', is => 'ro',
@ -122,10 +122,10 @@ sub extrude {
# extrude arc or line # extrude arc or line
$self->print_feed_rate( $self->print_feed_rate(
$path->role =~ /^(perimeter|skirt)$/o ? $self->perimeter_feed_rate $path->role =~ /^(perimeter|skirt)$/o ? $self->perimeter_speed
: $path->role eq 'fill' ? $self->infill_feed_rate : $path->role eq 'fill' ? $self->infill_speed
: $path->role eq 'solid-fill' ? $self->solid_infill_feed_rate : $path->role eq 'solid-fill' ? $self->solid_infill_speed
: $path->role eq 'bridge' ? $self->bridge_feed_rate : $path->role eq 'bridge' ? $self->bridge_speed
: die "Unknown role: " . $path->role : die "Unknown role: " . $path->role
); );
if ($path->isa('Slic3r::ExtrusionPath::Arc')) { if ($path->isa('Slic3r::ExtrusionPath::Arc')) {
@ -268,7 +268,7 @@ sub _Gx {
: 1; : 1;
# determine speed # determine speed
my $speed = ($e ? $self->print_feed_rate : $self->travel_feed_rate) * $speed_multiplier; my $speed = ($e ? $self->print_feed_rate : $self->travel_speed) * $speed_multiplier;
# output speed if it's different from last one used # output speed if it's different from last one used
# (goal: reduce gcode size) # (goal: reduce gcode size)

View File

@ -25,11 +25,11 @@ sub new {
}, },
print_speed => { print_speed => {
title => 'Print speed', title => 'Print speed',
options => [qw(perimeter_feed_rate infill_feed_rate solid_infill_feed_rate bridge_feed_rate)], options => [qw(perimeter_speed infill_speed solid_infill_speed bridge_speed)],
}, },
speed => { speed => {
title => 'Other speed settings', title => 'Other speed settings',
options => [qw(travel_feed_rate bottom_layer_speed_ratio)], options => [qw(travel_speed bottom_layer_speed_ratio)],
}, },
accuracy => { accuracy => {
title => 'Accuracy', title => 'Accuracy',

View File

@ -11,10 +11,12 @@ BEGIN {
use Getopt::Long; use Getopt::Long;
use Slic3r; use Slic3r;
use XXX; use XXX;
$|++; $|++;
our %opt;
GetOptions( my %opt = ();
my %cli_options = ();
{
my %options = (
'help' => sub { usage() }, 'help' => sub { usage() },
'debug' => \$Slic3r::debug, 'debug' => \$Slic3r::debug,
@ -23,64 +25,15 @@ GetOptions(
'save=s' => \$opt{save}, 'save=s' => \$opt{save},
'load=s' => \$opt{load}, 'load=s' => \$opt{load},
);
foreach my $opt_key (keys %$Slic3r::Config::Options) {
my $opt = $Slic3r::Config::Options->{$opt_key};
$options{ $opt->{cli} } = \$cli_options{$opt_key}
if $opt->{cli};
}
# printer options GetOptions(%options) or usage(1);
'nozzle-diameter=f' => \$Slic3r::nozzle_diameter, }
'print-center=s' => \$Slic3r::print_center,
'use-relative-e-distances' => \$Slic3r::use_relative_e_distances,
'no-extrusion' => \$Slic3r::no_extrusion,
'z-offset=f' => \$Slic3r::z_offset,
'gcode-arcs' => \$Slic3r::gcode_arcs,
'g0' => \$Slic3r::g0,
# filament options
'filament-diameter=f' => \$Slic3r::filament_diameter,
'extrusion-multiplier=f' => \$Slic3r::extrusion_multiplier,
'temperature=i' => \$Slic3r::temperature,
# speed options
'travel-feed-rate=i' => \$Slic3r::travel_feed_rate,
'perimeter-feed-rate=i' => \$Slic3r::perimeter_feed_rate,
'infill-feed-rate=i' => \$Slic3r::infill_feed_rate,
'solid-infill-feed-rate=i' => \$Slic3r::solid_infill_feed_rate,
'bridge-feed-rate=i' => \$Slic3r::bridge_feed_rate,
'bottom-layer-speed-ratio=f' => \$Slic3r::bottom_layer_speed_ratio,
# accuracy options
'layer-height=f' => \$Slic3r::layer_height,
'extrusion-width-ratio=f' => \$Slic3r::extrusion_width_ratio,
'first-layer-height-ratio=f' => \$Slic3r::first_layer_height_ratio,
'infill-every-layers=i' => \$Slic3r::infill_every_layers,
# print options
'perimeters=i' => \$Slic3r::perimeters,
'solid-layers=i' => \$Slic3r::solid_layers,
'fill-pattern=s' => \$Slic3r::fill_pattern,
'solid-fill-pattern=s' => \$Slic3r::solid_fill_pattern,
'fill-density=f' => \$Slic3r::fill_density,
'fill-angle=i' => \$Slic3r::fill_angle,
'start-gcode=s' => \$opt{start_gcode},
'end-gcode=s' => \$opt{end_gcode},
# retraction options
'retract-length=f' => \$Slic3r::retract_length,
'retract-speed=i' => \$Slic3r::retract_speed,
'retract-restart-extra=f' => \$Slic3r::retract_restart_extra,
'retract-before-travel=f' => \$Slic3r::retract_before_travel,
'retract-lift=f' => \$Slic3r::retract_lift,
# skirt options
'skirts=i' => \$Slic3r::skirts,
'skirt-distance=i' => \$Slic3r::skirt_distance,
'skirt-height=i' => \$Slic3r::skirt_height,
# transform options
'scale=f' => \$Slic3r::scale,
'rotate=i' => \$Slic3r::rotate,
'duplicate-x=i' => \$Slic3r::duplicate_x,
'duplicate-y=i' => \$Slic3r::duplicate_y,
'duplicate-distance=i' => \$Slic3r::duplicate_distance,
) or usage(1);
# load configuration # load configuration
if ($opt{load}) { if ($opt{load}) {
@ -89,7 +42,11 @@ if ($opt{load}) {
} }
# validate command line options # validate command line options
Slic3r::Config->validate_cli(\%opt); Slic3r::Config->validate_cli(\%cli_options);
# apply command line options
Slic3r::Config->set($_ => $cli_options{$_})
for grep defined $cli_options{$_}, keys %cli_options;
# validate configuration # validate configuration
Slic3r::Config->validate; Slic3r::Config->validate;
@ -155,13 +112,11 @@ Usage: slic3r.pl [ OPTIONS ] file.stl
--temperature Extrusion temperature, set 0 to disable (default: $Slic3r::temperature) --temperature Extrusion temperature, set 0 to disable (default: $Slic3r::temperature)
Speed options: Speed options:
--travel-feed-rate Speed of non-print moves in mm/sec (default: $Slic3r::travel_feed_rate) --travel-speed Speed of non-print moves in mm/sec (default: $Slic3r::travel_speed)
--perimeter-feed-rate --perimeter-speed Speed of print moves for perimeters in mm/sec (default: $Slic3r::perimeter_speed)
Speed of print moves for perimeters in mm/sec (default: $Slic3r::perimeter_feed_rate) --infill-speed Speed of print moves in mm/sec (default: $Slic3r::infill_speed)
--infill-feed-rate Speed of print moves in mm/sec (default: $Slic3r::infill_feed_rate) --solid-infill-speed Speed of print moves for solid surfaces in mm/sec (default: $Slic3r::solid_infill_speed)
--solid-infill-feed-rate --bridge-speed Speed of bridge print moves in mm/sec (default: $Slic3r::bridge_speed)
Speed of print moves for solid surfaces in mm/sec (default: $Slic3r::solid_infill_feed_rate)
--bridge-feed-rate Speed of bridge print moves in mm/sec (default: $Slic3r::bridge_feed_rate)
--bottom-layer-speed-ratio --bottom-layer-speed-ratio
Factor to increase/decrease speeds on bottom Factor to increase/decrease speeds on bottom
layer by (default: $Slic3r::bottom_layer_speed_ratio) layer by (default: $Slic3r::bottom_layer_speed_ratio)