From ed3a6349c78a4880a42f2655a906a2c8417680d1 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 11 Jan 2014 14:42:31 +0100 Subject: [PATCH] Adapt the new gcode.t test to master (and subtract final retraction from used filament length) --- lib/Slic3r/Extruder.pm | 4 ++-- lib/Slic3r/Print.pm | 10 +++++++--- t/gcode.t | 3 +-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/Slic3r/Extruder.pm b/lib/Slic3r/Extruder.pm index 514aec7c7..e2334c65e 100644 --- a/lib/Slic3r/Extruder.pm +++ b/lib/Slic3r/Extruder.pm @@ -83,8 +83,8 @@ sub extrude { } sub extruded_volume { - my ($self) = @_; - return $self->absolute_E * ($self->filament_diameter**2) * PI/4; + my ($self, $E) = @_; + return $E * ($self->filament_diameter**2) * PI/4; } sub e_per_mm { diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 4df77cae2..1e85395de 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -977,11 +977,15 @@ sub write_gcode { $self->total_extruded_volume(0); foreach my $extruder_id (@{$self->extruders}) { my $extruder = $gcodegen->extruders->{$extruder_id}; - $self->total_used_filament($self->total_used_filament + $extruder->absolute_E); - $self->total_extruded_volume($self->total_extruded_volume + $extruder->extruded_volume); + # the final retraction doesn't really count as "used filament" + my $used_filament = $extruder->absolute_E + $extruder->retract_length; + my $extruded_volume = $extruder->extruded_volume($used_filament); printf $fh "; filament used = %.1fmm (%.1fcm3)\n", - $extruder->absolute_E, $extruder->extruded_volume/1000; + $used_filament, $extruded_volume/1000; + + $self->total_used_filament($self->total_used_filament + $used_filament); + $self->total_extruded_volume($self->total_extruded_volume + $extruded_volume); } # append full config diff --git a/t/gcode.t b/t/gcode.t index 895277f35..4cfb64327 100644 --- a/t/gcode.t +++ b/t/gcode.t @@ -78,8 +78,7 @@ use Slic3r::Test; }); - # account for one single retraction at the end of the print - ok $print->extruders->[0]->absolute_E + $config->retract_length->[0] > 0, 'total filament length is positive'; + ok $print->total_used_filament > 0, 'final retraction is not considered in total used filament'; } __END__