diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm index 256e6971c..1c24b363b 100644 --- a/lib/Slic3r/Config.pm +++ b/lib/Slic3r/Config.pm @@ -8,6 +8,9 @@ use constant PI => 4 * atan2(1, 1); # cemetery of old config settings our @Ignore = qw(duplicate_x duplicate_y multiply_x multiply_y support_material_tool); +my $serialize_comma = sub { join ',', @{$_[0]} }; +my $deserialize_comma = sub { [ split /,/, $_[0] ] }; + our $Options = { # miscellaneous options @@ -52,8 +55,8 @@ our $Options = { sidetext => 'mm', cli => 'print-center=s', type => 'point', - serialize => sub { join ',', @{$_[0]} }, - deserialize => sub { [ split /[,x]/, $_[0] ] }, + serialize => $serialize_comma, + deserialize => $deserialize_comma, default => [100,100], }, 'gcode_flavor' => { @@ -126,8 +129,8 @@ our $Options = { cli => 'nozzle-diameter=f@', type => 'f', sidetext => 'mm', - serialize => sub { join ',', @{$_[0]} }, - deserialize => sub { [ split /,/, $_[0] ] }, + serialize => $serialize_comma, + deserialize => $deserialize_comma, default => [0.5], }, 'filament_diameter' => { @@ -136,8 +139,8 @@ our $Options = { sidetext => 'mm', cli => 'filament-diameter=f@', type => 'f', - serialize => sub { join ',', @{$_[0]} }, - deserialize => sub { [ split /,/, $_[0] ] }, + serialize => $serialize_comma, + deserialize => $deserialize_comma, default => [3], }, 'extrusion_multiplier' => { @@ -145,8 +148,8 @@ our $Options = { tooltip => 'This factor changes the amount of flow proportionally. You may need to tweak this setting to get nice surface finish and correct single wall widths. Usual values are between 0.9 and 1.1. If you think you need to change this more, check filament diameter and your firmware E steps.', cli => 'extrusion-multiplier=f@', type => 'f', - serialize => sub { join ',', @{$_[0]} }, - deserialize => sub { [ split /,/, $_[0] ] }, + serialize => $serialize_comma, + deserialize => $deserialize_comma, default => [1], }, 'temperature' => { @@ -156,7 +159,7 @@ our $Options = { cli => 'temperature=i@', type => 'i', max => 300, - serialize => sub { join ',', @{$_[0]} }, + serialize => $serialize_comma, deserialize => sub { $_[0] ? [ split /,/, $_[0] ] : [0] }, default => [200], }, @@ -166,7 +169,7 @@ our $Options = { sidetext => '°C', cli => 'first-layer-temperature=i@', type => 'i', - serialize => sub { join ',', @{$_[0]} }, + serialize => $serialize_comma, deserialize => sub { $_[0] ? [ split /,/, $_[0] ] : [0] }, max => 300, default => [200], @@ -557,42 +560,52 @@ END label => 'Length', tooltip => 'When retraction is triggered, filament is pulled back by the specified amount (the length is measured on raw filament, before it enters the extruder).', sidetext => 'mm (zero to disable)', - cli => 'retract-length=f', + cli => 'retract-length=f@', type => 'f', - default => 1, + serialize => $serialize_comma, + deserialize => $deserialize_comma, + default => [1], }, 'retract_speed' => { label => 'Speed', tooltip => 'The speed for retractions (it only applies to the extruder motor).', sidetext => 'mm/s', - cli => 'retract-speed=f', + cli => 'retract-speed=f@', type => 'i', max => 1000, - default => 30, + serialize => $serialize_comma, + deserialize => $deserialize_comma, + default => [30], }, 'retract_restart_extra' => { label => 'Extra length on restart', tooltip => 'When the retraction is compensated after the travel move, the extruder will push this additional amount of filament. This setting is rarely needed.', sidetext => 'mm', - cli => 'retract-restart-extra=f', + cli => 'retract-restart-extra=f@', type => 'f', - default => 0, + serialize => $serialize_comma, + deserialize => $deserialize_comma, + default => [0], }, 'retract_before_travel' => { label => 'Minimum travel after retraction', tooltip => 'Retraction is not triggered when travel moves are shorter than this length.', sidetext => 'mm', - cli => 'retract-before-travel=f', + cli => 'retract-before-travel=f@', type => 'f', - default => 2, + serialize => $serialize_comma, + deserialize => $deserialize_comma, + default => [2], }, 'retract_lift' => { label => 'Lift Z', tooltip => 'If you set this to a positive value, Z is quickly raised every time a retraction is triggered.', sidetext => 'mm', - cli => 'retract-lift=f', + cli => 'retract-lift=f@', type => 'f', - default => 0, + serialize => $serialize_comma, + deserialize => $deserialize_comma, + default => [0], }, # cooling options @@ -737,7 +750,7 @@ END sidetext => 'mm', cli => 'bed-size=s', type => 'point', - serialize => sub { join ',', @{$_[0]} }, + serialize => $serialize_comma, deserialize => sub { [ split /[,x]/, $_[0] ] }, default => [200,200], }, @@ -745,7 +758,7 @@ END label => 'Copies (grid)', cli => 'duplicate-grid=s', type => 'point', - serialize => sub { join ',', @{$_[0]} }, + serialize => $serialize_comma, deserialize => sub { [ split /[,x]/, $_[0] ] }, default => [1,1], }, diff --git a/lib/Slic3r/Extruder.pm b/lib/Slic3r/Extruder.pm index 25ddc0fdb..6425ab4e9 100644 --- a/lib/Slic3r/Extruder.pm +++ b/lib/Slic3r/Extruder.pm @@ -6,10 +6,12 @@ use Slic3r::Geometry qw(PI); use constant OPTIONS => [qw( extruder_offset nozzle_diameter filament_diameter extrusion_multiplier temperature first_layer_temperature + retract_length retract_lift retract_speed retract_restart_extra retract_before_travel )]; has $_ => (is => 'ro', required => 1) for @{&OPTIONS}; has 'e_per_mm3' => (is => 'lazy'); +has 'retract_speed_mm_min' => (is => 'lazy'); has '_mm3_per_mm_cache' => (is => 'ro', default => sub {{}}); sub _build_e_per_mm3 { @@ -17,6 +19,11 @@ sub _build_e_per_mm3 { return $self->extrusion_multiplier * (4 / (($self->filament_diameter ** 2) * PI)); } +sub _build_retract_speed_mm_min { + my $self = shift; + return $self->retract_speed * 60; +} + sub make_flow { my $self = shift; return Slic3r::Flow->new(nozzle_diameter => $self->nozzle_diameter, @_); diff --git a/lib/Slic3r/GCode.pm b/lib/Slic3r/GCode.pm index 54ccdef8c..42f50ef4d 100644 --- a/lib/Slic3r/GCode.pm +++ b/lib/Slic3r/GCode.pm @@ -33,7 +33,6 @@ has 'speeds' => ( solid_infill => 60 * $Slic3r::Config->get_value('solid_infill_speed'), top_solid_infill => 60 * $Slic3r::Config->get_value('top_solid_infill_speed'), bridge => 60 * $Slic3r::Config->get_value('bridge_speed'), - retract => 60 * $Slic3r::Config->get_value('retract_speed'), }}, ); @@ -137,7 +136,7 @@ sub extrude_path { # specified by the user *and* to the maximum distance between infill lines { my $distance_from_last_pos = $self->last_pos->distance_to($path->points->[0]) * &Slic3r::SCALING_FACTOR; - my $distance_threshold = $Slic3r::Config->retract_before_travel; + my $distance_threshold = $self->extruder->retract_before_travel; $distance_threshold = 2 * ($self->layer ? $self->layer->flow->width : $Slic3r::flow->width) / $Slic3r::Config->fill_density * sqrt(2) if 0 && $Slic3r::Config->fill_density > 0 && $description =~ /fill/; @@ -198,15 +197,15 @@ sub retract { my $self = shift; my %params = @_; - return "" unless $Slic3r::Config->retract_length > 0 + return "" unless $self->extruder->retract_length > 0 && !$self->retracted; # prepare moves $self->speed('retract'); - my $retract = [undef, undef, -$Slic3r::Config->retract_length, "retract"]; - my $lift = ($Slic3r::Config->retract_lift == 0 || defined $params{move_z}) + my $retract = [undef, undef, -$self->extruder->retract_length, "retract"]; + my $lift = ($self->extruder->retract_lift == 0 || defined $params{move_z}) ? undef - : [undef, $self->z + $Slic3r::Config->retract_lift, 0, 'lift plate during retraction']; + : [undef, $self->z + $self->extruder->retract_lift, 0, 'lift plate during retraction']; my $gcode = ""; if (($Slic3r::Config->g0 || $Slic3r::Config->gcode_flavor eq 'mach3') && $params{travel_to}) { @@ -225,16 +224,16 @@ sub retract { $gcode .= $self->G0(@$travel); } else { $gcode .= $self->G1(@$retract); - if (defined $params{move_z} && $Slic3r::Config->retract_lift > 0) { - my $travel = [undef, $params{move_z} + $Slic3r::Config->retract_lift, 0, 'move to next layer (' . $self->layer->id . ') and lift']; + if (defined $params{move_z} && $self->extruder->retract_lift > 0) { + my $travel = [undef, $params{move_z} + $self->extruder->retract_lift, 0, 'move to next layer (' . $self->layer->id . ') and lift']; $gcode .= $self->G0(@$travel); - $self->lifted(1); + $self->lifted($self->extruder->retract_lift); } elsif ($lift) { $gcode .= $self->G1(@$lift); } } $self->retracted(1); - $self->lifted(1) if $lift; + $self->lifted($self->extruder->retract_lift) if $lift; # reset extrusion distance during retracts # this makes sure we leave sufficient precision in the firmware @@ -249,12 +248,12 @@ sub unretract { my $gcode = ""; if ($self->lifted) { - $gcode .= $self->G0(undef, $self->z - $Slic3r::Config->retract_lift, 0, 'restore layer Z'); + $gcode .= $self->G0(undef, $self->z - $self->lifted, 0, 'restore layer Z'); $self->lifted(0); } $self->speed('retract'); - $gcode .= $self->G0(undef, undef, ($Slic3r::Config->retract_length + $Slic3r::Config->retract_restart_extra), + $gcode .= $self->G0(undef, undef, ($self->extruder->retract_length + $self->extruder->retract_restart_extra), "compensate retraction"); return $gcode; @@ -346,7 +345,9 @@ sub _Gx { } # apply the speed reduction for print moves on bottom layer - my $speed_f = $self->speeds->{$speed}; + my $speed_f = $speed eq 'retract' + ? ($self->extruder->retract_speed_mm_min) + : $self->speeds->{$speed}; if ($e && $self->layer->id == 0 && $comment !~ /retract/) { $speed_f = $Slic3r::Config->first_layer_speed =~ /^(\d+(?:\.\d+)?)%$/ ? ($speed_f * $1/100) diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index c0c7e5226..ca664e8ef 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -558,13 +558,6 @@ sub build { }, ]); - $self->add_options_page('Retraction', 'arrow_up.png', optgroups => [ - { - title => 'Retraction', - options => [qw(retract_length retract_lift retract_speed retract_restart_extra retract_before_travel)], - }, - ]); - $self->add_options_page('Custom G-code', 'cog.png', optgroups => [ { title => 'Start G-code', @@ -616,6 +609,13 @@ sub _build_extruder_pages { title => 'Position (for multi-extruder printers)', options => ['extruder_offset#' . $extruder_idx], }, + { + title => 'Retraction', + options => [ + map "${_}#${extruder_idx}", + qw(retract_length retract_lift retract_speed retract_restart_extra retract_before_travel) + ], + }, ]); $self->{extruder_pages}[$extruder_idx]{disabled} = 0; } diff --git a/slic3r.pl b/slic3r.pl index b317799bc..0cf8baa26 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -227,14 +227,14 @@ $j Retraction options: --retract-length Length of retraction in mm when pausing extrusion - (default: $config->{retract_length}) - --retract-speed Speed for retraction in mm/s (default: $config->{retract_speed}) + (default: $config->{retract_length}[0]) + --retract-speed Speed for retraction in mm/s (default: $config->{retract_speed}[0]) --retract-restart-extra Additional amount of filament in mm to push after - compensating retraction (default: $config->{retract_restart_extra}) + compensating retraction (default: $config->{retract_restart_extra}[0]) --retract-before-travel - Only retract before travel moves of this length in mm (default: $config->{retract_before_travel}) - --retract-lift Lift Z by the given distance in mm when retracting (default: $config->{retract_lift}) + Only retract before travel moves of this length in mm (default: $config->{retract_before_travel}[0]) + --retract-lift Lift Z by the given distance in mm when retracting (default: $config->{retract_lift}[0]) Cooling options: --cooling Enable fan and cooling control