diff --git a/lib/Slic3r/GCode.pm b/lib/Slic3r/GCode.pm index 27c1ccd35..cea5dcd54 100644 --- a/lib/Slic3r/GCode.pm +++ b/lib/Slic3r/GCode.pm @@ -90,7 +90,7 @@ sub change_layer { my $gcode = ""; if (defined $self->layer_count) { # TODO: cap this to 99% and add an explicit M73 P100 in the end G-code - $gcode .= $self->writer->update_progress(int(99 * ($self->_layer_index / ($self->layer_count - 1)))); + $gcode .= $self->writer->update_progress($self->_layer_index, $self->layer_count); } my $z = $layer->print_z + $self->config->z_offset; # in unscaled coordinates diff --git a/lib/Slic3r/GCode/Writer.pm b/lib/Slic3r/GCode/Writer.pm index ed72cc2c2..1563ca7ac 100644 --- a/lib/Slic3r/GCode/Writer.pm +++ b/lib/Slic3r/GCode/Writer.pm @@ -129,11 +129,14 @@ sub set_acceleration { } sub update_progress { - my ($self, $percent) = @_; + my ($self, $num, $tot, $allow_100) = @_; return "" if $self->config->gcode_flavor !~ /^(?:makerware|sailfish)$/; + + my $percent = int($num/$tot*100); + $percent = min($percent, 99) if !$allow_100; return sprintf "M73 P%s%s\n", - int($percent), + $percent, $self->_comment('update progress'); } diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 68e6378f2..b814880b9 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -938,6 +938,7 @@ sub write_gcode { print $fh $gcodegen->retract; print $fh $gcodegen->writer->set_fan(0); printf $fh "%s\n", $gcodegen->placeholder_parser->process($self->config->end_gcode); + print $fh $gcodegen->writer->update_progress($gcodegen->layer_count, $gcodegen->layer_count, 1); # 100% $self->total_used_filament(0); $self->total_extruded_volume(0); diff --git a/t/gcode.t b/t/gcode.t index f82bc72ac..ee92d199c 100644 --- a/t/gcode.t +++ b/t/gcode.t @@ -1,4 +1,4 @@ -use Test::More tests => 11; +use Test::More tests => 16; use strict; use warnings; @@ -101,15 +101,22 @@ use Slic3r::Test; my ($print, $comment) = @_; my @percent = (); + my $got_100 = 0; + my $extruding_after_100 = 0; Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub { my ($self, $cmd, $args, $info) = @_; if ($cmd eq 'M73') { push @percent, $args->{P}; + $got_100 = 1 if $args->{P} eq '100'; + } + if ($info->{extruding} && $got_100) { + $extruding_after_100 = 1; } }); # the extruder heater is turned off when M73 P100 is reached ok !(defined first { $_ > 100 } @percent), "M73 is never given more than 100% ($comment)"; + ok !$extruding_after_100, "no extrusions after M73 P100 ($comment)"; }; { @@ -133,6 +140,13 @@ use Slic3r::Test; my $print = Slic3r::Test::init_print(['20mm_cube','20mm_cube'], config => $config); $test->($print, 'two objects'); } + + { + my $config = Slic3r::Config->new_from_defaults; + $config->set('gcode_flavor', 'sailfish'); + my $print = Slic3r::Test::init_print('20mm_cube', config => $config, scale_xyz => [1,1, 1/(20/$config->layer_height) ]); + $test->($print, 'one layer object'); + } } __END__