1
use Test::More tests => 17;
7
use lib "$FindBin::Bin/../lib";
11
use Slic3r::Test qw(_eq);
14
my $config = Slic3r::Config->new_from_defaults;
21
my $print = Slic3r::Test::init_print('20mm_cube', config => $conf, duplicate => $duplicate);
24
my @toolchange_count = (); # track first usages so that we don't expect retract_length_toolchange when extruders are used for the first time
25
my @retracted = (1); # ignore the first travel move from home to first point
26
my @retracted_length = (0);
29
my $wait_for_toolchange = 0;
30
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
31
my ($self, $cmd, $args, $info) = @_;
33
if ($cmd =~ /^T(\d+)/) {
36
$wait_for_toolchange = 0;
37
$toolchange_count[$tool] //= 0;
38
$toolchange_count[$tool]++;
39
} elsif ($cmd =~ /^G[01]$/ && !$args->{Z}) { # ignore lift taking place after retraction
40
fail 'toolchange happens right after retraction' if $wait_for_toolchange;
43
if ($info->{dist_Z}) {
44
# lift move or lift + change layer
45
if (_eq($info->{dist_Z}, $print->print->config->get_at('retract_lift', $tool))
46
|| (_eq($info->{dist_Z}, $conf->layer_height + $print->print->config->get_at('retract_lift', $tool)) && $print->print->config->get_at('retract_lift', $tool) > 0)) {
47
fail 'only lifting while retracted' if !$retracted[$tool] && !($conf->g0 && $info->{retracting});
48
fail 'double lift' if $lifted;
51
if ($info->{dist_Z} < 0) {
52
fail 'going down only after lifting' if !$lifted;
53
fail 'going down by the same amount of the lift or by the amount needed to get to next layer'
54
if !_eq($info->{dist_Z}, -$print->print->config->get_at('retract_lift', $tool))
55
&& !_eq($info->{dist_Z}, -$print->print->config->get_at('retract_lift', $tool) + $conf->layer_height);
58
fail 'move Z at travel speed' if ($args->{F} // $self->F) != $conf->travel_speed * 60;
60
if ($info->{retracting}) {
61
$retracted[$tool] = 1;
62
$retracted_length[$tool] += -$info->{dist_E};
63
if (_eq($retracted_length[$tool], $print->print->config->get_at('retract_length', $tool))) {
65
} elsif (_eq($retracted_length[$tool], $print->print->config->get_at('retract_length_toolchange', $tool))) {
66
$wait_for_toolchange = 1;
68
fail 'retracted by the correct amount';
70
fail 'combining retraction and travel with G0'
71
if $cmd ne 'G0' && $conf->g0 && ($info->{dist_Z} || $info->{dist_XY});
73
if ($info->{extruding}) {
74
fail 'only extruding while not lifted' if $lifted;
75
if ($retracted[$tool]) {
76
my $expected_amount = $retracted_length[$tool] + $print->print->config->get_at('retract_restart_extra', $tool);
77
if ($changed_tool && $toolchange_count[$tool] > 1) {
78
$expected_amount = $print->print->config->get_at('retract_length_toolchange', $tool) + $print->print->config->get_at('retract_restart_extra_toolchange', $tool);
81
fail 'unretracted by the correct amount'
82
if !_eq($info->{dist_E}, $expected_amount);
83
$retracted[$tool] = 0;
84
$retracted_length[$tool] = 0;
87
if ($info->{travel} && $info->{dist_XY} >= $print->print->config->get_at('retract_before_travel', $tool)) {
88
fail 'retracted before long travel move' if !$retracted[$tool];
95
$config->set('first_layer_height', $config->layer_height);
96
$config->set('first_layer_speed', '100%');
97
$config->set('start_gcode', ''); # to avoid dealing with the nozzle lift in start G-code
98
$config->set('retract_length', [1.5]);
99
$config->set('retract_before_travel', [3]);
100
$config->set('only_retract_when_crossing_perimeters', 0);
102
my $retract_tests = sub {
105
ok $test->(), "retraction$descr";
107
my $conf = $config->clone;
108
$conf->set('retract_restart_extra', [1]);
109
ok $test->($conf), "restart extra length$descr";
111
$conf->set('retract_restart_extra', [-1]);
112
ok $test->($conf), "negative restart extra length$descr";
114
$conf->set('retract_lift', [1]);
115
ok $test->($conf), "lift$descr";
118
$retract_tests->('');
121
$retract_tests->(' (duplicate)');
123
$config->set('g0', 1);
124
$retract_tests->(' (G0 and duplicate)');
127
$config->set('g0', 0);
128
$config->set('infill_extruder', 2);
129
$config->set('skirts', 4);
130
$config->set('skirt_height', 3);
131
$retract_tests->(' (dual extruder with multiple skirt layers)');
135
my $config = Slic3r::Config->new_from_defaults;
136
$config->set('retract_layer_change', [0]);
138
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
140
my $layer_changes_with_retraction = 0;
141
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
142
my ($self, $cmd, $args, $info) = @_;
144
if ($info->{retracting}) {
146
} elsif ($info->{extruding} && $retracted) {
150
if ($info->{dist_Z} && $retracted) {
151
$layer_changes_with_retraction++;
155
is $layer_changes_with_retraction, 0, 'no retraction on layer change';