/
retraction.t
103 lines (84 loc) · 3.27 KB
/
retraction.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use Test::More tests => 9;
use strict;
use warnings;
BEGIN {
use FindBin;
use lib "$FindBin::Bin/../lib";
}
use Slic3r;
use Slic3r::Test qw(_eq);
my $config = Slic3r::Config->new_from_defaults;
my $test = sub {
my ($conf) = @_;
$conf ||= $config;
my $print = Slic3r::Test::init_print('20mm_cube', config => $conf);
my $tool = 0;
my @retracted = (1); # ignore the first travel move from home to first point
my $lifted = 0;
my $changed_tool = 0;
Slic3r::Test::GCodeReader->new(gcode => Slic3r::Test::gcode($print))->parse(sub {
my ($self, $cmd, $args, $info) = @_;
if ($cmd =~ /^T(\d+)/) {
$tool = $1;
$changed_tool = 1;
}
if ($info->{dist_Z}) {
# lift move or lift + change layer
if (_eq($info->{dist_Z}, $conf->retract_lift->[$tool])
|| (_eq($info->{dist_Z}, $conf->layer_height + $conf->retract_lift->[$tool]) && $conf->retract_lift->[$tool] > 0)) {
fail 'only lifting while retracted' if !$retracted[$tool] && !($conf->g0 && $info->{retracting});
$lifted = 1;
}
if ($info->{dist_Z} < 0) {
fail 'going down only after lifting' if !$lifted;
fail 'going down by the same amount of the lift'
if !_eq($info->{dist_Z}, -$conf->retract_lift->[$tool]);
$lifted = 0;
}
}
if ($info->{retracting}) {
fail 'retracted by the correct amount'
if !_eq(-$info->{dist_E}, $conf->retract_length->[$tool]);
fail 'combining retraction and travel with G0'
if $cmd ne 'G0' && $conf->g0 && ($info->{dist_Z} || $info->{dist_XY});
$retracted[$tool] = 1;
}
if ($info->{extruding}) {
fail 'only extruding while not lifted' if $lifted;
if ($retracted[$tool]) {
my $expected_amount = $conf->retract_length->[$tool] + $conf->retract_restart_extra->[$tool];
if ($changed_tool) {
$expected_amount = $conf->retract_length_toolchange->[$tool] + $conf->retract_restart_extra_toolchange->[$tool];
}
fail 'unretracted by the correct amount'
if !_eq($info->{dist_E}, $expected_amount);
$retracted[$tool] = 0;
}
}
if ($info->{travel} && $info->{dist_XY} >= $conf->retract_before_travel->[$tool]) {
fail 'retracted before long travel move' if !$retracted[$tool];
}
});
1;
};
$config->set('retract_length', [1.5]);
$config->set('retract_before_travel', [3]);
my $retract_tests = sub {
my ($descr) = @_;
ok $test->(), "retraction$descr";
my $conf = $config->clone;
$conf->set('retract_restart_extra', [1]);
ok $test->($conf), "restart extra length$descr";
$conf->set('retract_lift', [1]);
ok $test->($conf), "lift$descr";
};
$retract_tests->('');
$config->set('duplicate', 2);
$retract_tests->(' (duplicate)');
$config->set('g0', 1);
$retract_tests->(' (G0 and duplicate)');
$config->set('duplicate', 1);
$config->set('g0', 0);
$config->set('infill_extruder', 2);
$retract_tests->(' (dual extruder)');
__END__