From aedb6cc35ff03170a0bbc56f61d975fa7ec7171c Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Wed, 6 Jun 2012 15:23:34 +0200 Subject: [PATCH] Accept both relative and absolute extrusion width values. #151 --- README.markdown | 5 ++--- lib/Slic3r.pm | 2 +- lib/Slic3r/Config.pm | 25 +++++++++++++++++-------- lib/Slic3r/GUI/SkeinPanel.pm | 2 +- lib/Slic3r/Print.pm | 2 +- slic3r.pl | 5 ++--- 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/README.markdown b/README.markdown index 96d2c2e1b..5385e1122 100644 --- a/README.markdown +++ b/README.markdown @@ -211,9 +211,8 @@ The author is Alessandro Ranellucci. --notes Notes to be added as comments to the output file Flow options (advanced): - --extrusion-width-ratio - Calculate the extrusion width as the layer height multiplied by - this value (> 0, default: calculated automatically) + --extrusion-width Set extrusion width manually; it accepts either an absolute value in mm + (like 0.65) or a percentage over layer height (like 200%) --bridge-flow-ratio Multiplier for extrusion when bridging (> 0, default: 1) diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm index b0c92c321..8839fb280 100644 --- a/lib/Slic3r.pm +++ b/lib/Slic3r.pm @@ -99,7 +99,7 @@ our $first_layer_height_ratio = 1; our $infill_every_layers = 1; # flow options -our $extrusion_width_ratio = 0; +our $extrusion_width = 0; our $bridge_flow_ratio = 1; our $overlap_factor = 0.5; our $flow_width; diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm index 095d11dd7..25aa3b8f3 100644 --- a/lib/Slic3r/Config.pm +++ b/lib/Slic3r/Config.pm @@ -198,9 +198,9 @@ our $Options = { }, # flow options - 'extrusion_width_ratio' => { - label => 'Extrusion width (ratio over layer height; leave zero to calculate automatically)', - cli => 'extrusion-width-ratio=f', + 'extrusion_width' => { + label => 'Extrusion width (mm or %; leave zero to calculate automatically)', + cli => 'extrusion-width=f', type => 'f', }, 'bridge_flow_ratio' => { @@ -516,15 +516,22 @@ sub load { next if /^$/; next if /^\s*#/; /^(\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}; + if ($key eq 'extrusion_width_ratio') { + $key = 'extrusion_width'; + $val = $val =~ /^\d+(\.\d+)?$/ ? ($val*100) . "%" : 0; + } + if (!exists $Options->{$key}) { $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; my $opt = $Options->{$key}; - set($key, $opt->{deserialize} ? $opt->{deserialize}->($2) : $2); + set($key, $opt->{deserialize} ? $opt->{deserialize}->($val) : $val); } close $fh; } @@ -581,8 +588,10 @@ sub validate { die "First layer height can't be zero or negative\n" if ($Slic3r::layer_height * $Slic3r::first_layer_height_ratio) <= 0; - if ($Slic3r::extrusion_width_ratio) { - $Slic3r::flow_width = $Slic3r::layer_height * $Slic3r::extrusion_width_ratio; + if ($Slic3r::extrusion_width) { + $Slic3r::flow_width = $Slic3r::extrusion_width =~ /^(\d+(?:\.\d+)?)%$/ + ? ($Slic3r::layer_height * $1 / 100) + : $Slic3r::extrusion_width; } else { # here we calculate a sane default by matching the flow speed (at the nozzle) # and the feed rate diff --git a/lib/Slic3r/GUI/SkeinPanel.pm b/lib/Slic3r/GUI/SkeinPanel.pm index f19c93314..8e0c9887a 100644 --- a/lib/Slic3r/GUI/SkeinPanel.pm +++ b/lib/Slic3r/GUI/SkeinPanel.pm @@ -70,7 +70,7 @@ sub new { }, extrusion => { title => 'Extrusion', - options => [qw(extrusion_width_ratio bridge_flow_ratio)], + options => [qw(extrusion_width bridge_flow_ratio)], }, output => { title => 'Output', diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index ae3c4b272..848c8f42e 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -437,7 +437,7 @@ sub write_gcode { print $fh "\n" if $Slic3r::notes; 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 "; single wall width = %.2fmm\n", $Slic3r::flow_width; diff --git a/slic3r.pl b/slic3r.pl index 6ea7f7822..ce45e66c3 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -255,9 +255,8 @@ $j --notes Notes to be added as comments to the output file Flow options (advanced): - --extrusion-width-ratio - Calculate the extrusion width as the layer height multiplied by - this value (> 0, default: calculated automatically) + --extrusion-width Set extrusion width manually; it accepts either an absolute value in mm + (like 0.65) or a percentage over layer height (like 200%) --bridge-flow-ratio Multiplier for extrusion when bridging (> 0, default: $Slic3r::bridge_flow_ratio) EOF