From 075213c73115b53c3fffbed1f3fc0921e0c39da9 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Wed, 22 Aug 2012 18:57:03 +0200 Subject: [PATCH] Refactoring: make 'retracted' an attribute of the Extruder object --- lib/Slic3r/Extruder.pm | 1 + lib/Slic3r/GCode.pm | 15 +++++++-------- lib/Slic3r/Print.pm | 4 ++++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/Slic3r/Extruder.pm b/lib/Slic3r/Extruder.pm index 6425ab4e9..5ebaa9fc5 100644 --- a/lib/Slic3r/Extruder.pm +++ b/lib/Slic3r/Extruder.pm @@ -10,6 +10,7 @@ use constant OPTIONS => [qw( )]; has $_ => (is => 'ro', required => 1) for @{&OPTIONS}; +has 'retracted' => (is => 'rw', default => sub {0} ); has 'e_per_mm3' => (is => 'lazy'); has 'retract_speed_mm_min' => (is => 'lazy'); has '_mm3_per_mm_cache' => (is => 'ro', default => sub {{}}); diff --git a/lib/Slic3r/GCode.pm b/lib/Slic3r/GCode.pm index fe08723ef..a9f62fd5c 100644 --- a/lib/Slic3r/GCode.pm +++ b/lib/Slic3r/GCode.pm @@ -14,7 +14,6 @@ has 'extruder_idx' => (is => 'rw', default => sub {0}); has 'extrusion_distance' => (is => 'rw', default => sub {0} ); has 'elapsed_time' => (is => 'rw', default => sub {0} ); # seconds has 'total_extrusion_length' => (is => 'rw', default => sub {0} ); -has 'retracted' => (is => 'rw', default => sub {1} ); # this spits out some plastic at start has 'lifted' => (is => 'rw', default => sub {0} ); has 'last_pos' => (is => 'rw', default => sub { Slic3r::Point->new(0,0) } ); has 'last_speed' => (is => 'rw', default => sub {""}); @@ -150,7 +149,7 @@ sub extrude_path { if !points_coincide($self->last_pos, $path->points->[0]); # compensate retraction - $gcode .= $self->unretract if $self->retracted; + $gcode .= $self->unretract if $self->extruder->retracted; my $area; # mm^3 of extrudate per mm of tool movement if ($path->role == EXTR_ROLE_BRIDGE) { @@ -198,7 +197,7 @@ sub retract { my %params = @_; return "" unless $self->extruder->retract_length > 0 - && !$self->retracted; + && !$self->extruder->retracted; # prepare moves $self->speed('retract'); @@ -232,7 +231,7 @@ sub retract { $gcode .= $self->G1(@$lift); } } - $self->retracted(1); + $self->extruder->retracted($self->extruder->retract_length + $self->extruder->retract_restart_extra); $self->lifted($self->extruder->retract_lift) if $lift; # reset extrusion distance during retracts @@ -244,7 +243,7 @@ sub retract { sub unretract { my $self = shift; - $self->retracted(0); + my $gcode = ""; if ($self->lifted) { @@ -253,8 +252,8 @@ sub unretract { } $self->speed('retract'); - $gcode .= $self->G0(undef, undef, ($self->extruder->retract_length + $self->extruder->retract_restart_extra), - "compensate retraction"); + $gcode .= $self->G0(undef, undef, $self->extruder->retracted, "compensate retraction"); + $self->extruder->retracted(0); return $gcode; } @@ -348,7 +347,7 @@ sub _Gx { my $speed_f = $speed eq 'retract' ? ($self->extruder->retract_speed_mm_min) : $self->speeds->{$speed}; - if ($e && $self->layer->id == 0 && $comment !~ /retract/) { + if ($e && $self->layer && $self->layer->id == 0 && $comment !~ /retract/) { $speed_f = $Slic3r::Config->first_layer_speed =~ /^(\d+(?:\.\d+)?)%$/ ? ($speed_f * $1/100) : $Slic3r::Config->first_layer_speed * 60; diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 314e08c12..16e0f03b0 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -569,6 +569,10 @@ sub write_gcode { print $fh $gcodegen->set_tool(0) if @$Slic3r::extruders > 1; print $fh $gcodegen->set_fan(0, 1) if $Slic3r::Config->cooling && $Slic3r::Config->disable_fan_first_layers; + # this spits out some platic at start from the first extruder + # (TODO: make this consistent in multi-head setups) + $gcodegen->retract; + # write start commands to file printf $fh $gcodegen->set_bed_temperature($Slic3r::Config->first_layer_bed_temperature, 1), if $Slic3r::Config->first_layer_bed_temperature && $Slic3r::Config->start_gcode !~ /M190/i;