Accept both relative and absolute extrusion width values. #151

This commit is contained in:
Alessandro Ranellucci 2012-06-06 15:23:34 +02:00
parent 2e3c8241e4
commit aedb6cc35f
6 changed files with 24 additions and 17 deletions

View file

@ -211,9 +211,8 @@ The author is Alessandro Ranellucci.
--notes Notes to be added as comments to the output file --notes Notes to be added as comments to the output file
Flow options (advanced): Flow options (advanced):
--extrusion-width-ratio --extrusion-width Set extrusion width manually; it accepts either an absolute value in mm
Calculate the extrusion width as the layer height multiplied by (like 0.65) or a percentage over layer height (like 200%)
this value (> 0, default: calculated automatically)
--bridge-flow-ratio Multiplier for extrusion when bridging (> 0, default: 1) --bridge-flow-ratio Multiplier for extrusion when bridging (> 0, default: 1)

View file

@ -99,7 +99,7 @@ our $first_layer_height_ratio = 1;
our $infill_every_layers = 1; our $infill_every_layers = 1;
# flow options # flow options
our $extrusion_width_ratio = 0; our $extrusion_width = 0;
our $bridge_flow_ratio = 1; our $bridge_flow_ratio = 1;
our $overlap_factor = 0.5; our $overlap_factor = 0.5;
our $flow_width; our $flow_width;

View file

@ -198,9 +198,9 @@ our $Options = {
}, },
# flow options # flow options
'extrusion_width_ratio' => { 'extrusion_width' => {
label => 'Extrusion width (ratio over layer height; leave zero to calculate automatically)', label => 'Extrusion width (mm or %; leave zero to calculate automatically)',
cli => 'extrusion-width-ratio=f', cli => 'extrusion-width=f',
type => 'f', type => 'f',
}, },
'bridge_flow_ratio' => { 'bridge_flow_ratio' => {
@ -516,15 +516,22 @@ sub load {
next if /^$/; next if /^$/;
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, $val) = ($1, $2);
# handle legacy options
next if $ignore{$key}; next if $ignore{$key};
if ($key eq 'extrusion_width_ratio') {
$key = 'extrusion_width';
$val = $val =~ /^\d+(\.\d+)?$/ ? ($val*100) . "%" : 0;
}
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 $key at line $.\n";
} }
next unless $key; next unless $key;
my $opt = $Options->{$key}; my $opt = $Options->{$key};
set($key, $opt->{deserialize} ? $opt->{deserialize}->($2) : $2); set($key, $opt->{deserialize} ? $opt->{deserialize}->($val) : $val);
} }
close $fh; close $fh;
} }
@ -581,8 +588,10 @@ sub validate {
die "First layer height can't be zero or negative\n" die "First layer height can't be zero or negative\n"
if ($Slic3r::layer_height * $Slic3r::first_layer_height_ratio) <= 0; if ($Slic3r::layer_height * $Slic3r::first_layer_height_ratio) <= 0;
if ($Slic3r::extrusion_width_ratio) { if ($Slic3r::extrusion_width) {
$Slic3r::flow_width = $Slic3r::layer_height * $Slic3r::extrusion_width_ratio; $Slic3r::flow_width = $Slic3r::extrusion_width =~ /^(\d+(?:\.\d+)?)%$/
? ($Slic3r::layer_height * $1 / 100)
: $Slic3r::extrusion_width;
} else { } else {
# here we calculate a sane default by matching the flow speed (at the nozzle) # here we calculate a sane default by matching the flow speed (at the nozzle)
# and the feed rate # and the feed rate

View file

@ -70,7 +70,7 @@ sub new {
}, },
extrusion => { extrusion => {
title => 'Extrusion', title => 'Extrusion',
options => [qw(extrusion_width_ratio bridge_flow_ratio)], options => [qw(extrusion_width bridge_flow_ratio)],
}, },
output => { output => {
title => 'Output', title => 'Output',

View file

@ -437,7 +437,7 @@ sub write_gcode {
print $fh "\n" if $Slic3r::notes; print $fh "\n" if $Slic3r::notes;
for (qw(layer_height perimeters solid_layers fill_density nozzle_diameter filament_diameter for (qw(layer_height perimeters solid_layers fill_density nozzle_diameter filament_diameter
extrusion_multiplier perimeter_speed infill_speed travel_speed extrusion_width_ratio scale)) { extrusion_multiplier perimeter_speed infill_speed travel_speed scale)) {
printf $fh "; %s = %s\n", $_, Slic3r::Config->get($_); printf $fh "; %s = %s\n", $_, Slic3r::Config->get($_);
} }
printf $fh "; single wall width = %.2fmm\n", $Slic3r::flow_width; printf $fh "; single wall width = %.2fmm\n", $Slic3r::flow_width;

View file

@ -255,9 +255,8 @@ $j
--notes Notes to be added as comments to the output file --notes Notes to be added as comments to the output file
Flow options (advanced): Flow options (advanced):
--extrusion-width-ratio --extrusion-width Set extrusion width manually; it accepts either an absolute value in mm
Calculate the extrusion width as the layer height multiplied by (like 0.65) or a percentage over layer height (like 200%)
this value (> 0, default: calculated automatically)
--bridge-flow-ratio Multiplier for extrusion when bridging (> 0, default: $Slic3r::bridge_flow_ratio) --bridge-flow-ratio Multiplier for extrusion when bridging (> 0, default: $Slic3r::bridge_flow_ratio)
EOF EOF