Bugfix: custom layer G-code was applied before Z change, and not after like it was documented. #869
This commit is contained in:
parent
b70404bb23
commit
ea304a4803
4 changed files with 51 additions and 2 deletions
1
MANIFEST
1
MANIFEST
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
Normal file
41
t/custom_gcode.t
Normal file
|
@ -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__
|
Loading…
Reference in a new issue