Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Bugfix: custom layer G-code was applied before Z change, and not afte…

…r like it was documented. #869
  • Loading branch information...
commit ea304a4803e316fb376f555826f24ada72517be3 1 parent b70404b
Alessandro Ranellucci authored
1  MANIFEST
View
@@ -55,6 +55,7 @@ t/arcs.t
t/clean_polylines.t
t/clipper.t
t/collinear.t
+t/custom_gcode.t
t/dynamic.t
t/fill.t
t/geometry.t
2  lib/Slic3r/GCode.pm
View
@@ -7,6 +7,7 @@ use Slic3r::Geometry qw(scale unscale scaled_epsilon points_coincide PI X Y B);
has 'multiple_extruders' => (is => 'ro', default => sub {0} );
has 'layer' => (is => 'rw');
+has 'move_z_callback' => (is => 'rw');
has 'shift_x' => (is => 'rw', default => sub {0} );
has 'shift_y' => (is => 'rw', default => sub {0} );
has 'z' => (is => 'rw');
@@ -79,6 +80,7 @@ sub move_z {
$self->speed('travel');
$gcode .= $self->G0(undef, $z, 0, $comment || ('move to next layer (' . $self->layer->id . ')'))
unless ($current_z // -1) != ($self->z // -1);
+ $gcode .= $self->move_z_callback->() if defined $self->move_z_callback;
}
return $gcode;
9 lib/Slic3r/Print.pm
View
@@ -738,8 +738,13 @@ sub write_gcode {
# set new layer, but don't move Z as support material interfaces may need an intermediate one
$gcodegen->layer($self->objects->[$object_copies->[0][0]]->layers->[$layer_id]);
$gcodegen->elapsed_time(0);
- $gcode .= $Slic3r::Config->replace_options($Slic3r::Config->layer_gcode) . "\n"
- if $Slic3r::Config->layer_gcode;
+
+ # prepare callback to call as soon as a Z command is generated
+ $gcodegen->move_z_callback(sub {
+ $gcodegen->move_z_callback(undef); # circular ref or not?
+ return $Slic3r::Config->replace_options($Slic3r::Config->layer_gcode) . "\n"
+ if $Slic3r::Config->layer_gcode;
+ });
# extrude skirt
if ($skirt_done < $Slic3r::Config->skirt_height) {
41 t/custom_gcode.t
View
@@ -0,0 +1,41 @@
+use Test::More tests => 1;
+use strict;
+use warnings;
+
+BEGIN {
+ use FindBin;
+ use lib "$FindBin::Bin/../lib";
+}
+
+use Slic3r;
+use Slic3r::Test;
+
+my $config = Slic3r::Config->new_from_defaults;
+
+my $test = sub {
+ my ($conf) = @_;
+ $conf ||= $config;
+
+ my $print = Slic3r::Test::init_print('2x20x10', config => $conf);
+
+ my $last_move_was_z_change = 0;
+ Slic3r::Test::GCodeReader->new(gcode => Slic3r::Test::gcode($print))->parse(sub {
+ my ($self, $cmd, $args, $info) = @_;
+
+ if ($last_move_was_z_change && $cmd ne $config->layer_gcode) {
+ fail 'custom layer G-code was not applied after Z change';
+ }
+ if (!$last_move_was_z_change && $cmd eq $config->layer_gcode) {
+ fail 'custom layer G-code was not applied after Z change';
+ }
+
+ $last_move_was_z_change = (defined $info->{dist_Z} && $info->{dist_Z} > 0);
+ });
+
+ 1;
+};
+
+$config->set('layer_gcode', '_MY_CUSTOM_GCODE_');
+ok $test->(), "custom layer G-code is applied after Z move and before other moves";
+
+__END__
Please sign in to comment.
Something went wrong with that request. Please try again.