1
use Test::More tests => 11;
7
use lib "$FindBin::Bin/../lib";
10
use List::Util qw(first);
12
use Slic3r::Geometry qw(scale convex_hull);
16
my $gcodegen = Slic3r::GCode->new(
20
$gcodegen->set_shift(10, 10);
21
is_deeply $gcodegen->last_pos->arrayref, [scale -10, scale -10], 'last_pos is shifted correctly';
25
my $config = Slic3r::Config->new_from_defaults;
26
$config->set('wipe', [1]);
28
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
30
my @retract_speeds = ();
31
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
32
my ($self, $cmd, $args, $info) = @_;
33
if ($info->{retracting} && $info->{dist_XY} > 0) {
35
my $move_time = $info->{dist_XY} / ($args->{F} // $self->F);
36
push @retract_speeds, abs($info->{dist_E}) / $move_time;
40
ok $have_wipe, "wipe";
41
ok !defined (first { abs($_ - $config->retract_speed->[0]*60) < 5 } @retract_speeds), 'wipe moves don\'t retract faster than configured speed';
45
# This tests the following behavior:
46
# - complete objects does not crash
47
# - no hard-coded "E" are generated
48
# - Z moves are correctly generated for both objects
49
# - no travel moves go outside skirt
50
my $config = Slic3r::Config->new_from_defaults;
51
$config->set('gcode_comments', 1);
52
$config->set('complete_objects', 1);
53
$config->set('extrusion_axis', 'A');
54
$config->set('start_gcode', ''); # prevent any default extra Z move
55
$config->set('layer_height', 0.4);
56
$config->set('first_layer_height', 0.4);
57
my $print = Slic3r::Test::init_print('20mm_cube', config => $config, duplicate => 2);
58
ok my $gcode = Slic3r::Test::gcode($print), "complete_objects";
60
my @travel_moves = (); # array of scaled points
61
my @extrusions = (); # array of scaled points
62
Slic3r::GCode::Reader->new->parse($gcode, sub {
63
my ($self, $cmd, $args, $info) = @_;
64
fail 'unexpected E argument' if defined $args->{E};
65
if (defined $args->{Z}) {
66
push @z_moves, $args->{Z};
69
if ($info->{dist_XY}) {
70
if ($info->{extruding} || $args->{A}) {
71
push @extrusions, Slic3r::Point->new_scale($info->{new_X}, $info->{new_Y});
73
push @travel_moves, Slic3r::Point->new_scale($info->{new_X}, $info->{new_Y})
74
if @extrusions; # skip initial travel move to first skirt point
78
my $layer_count = 20/0.4; # cube is 20mm tall
79
is scalar(@z_moves), 2*$layer_count, 'complete_objects generates the correct number of Z moves';
80
is_deeply [ @z_moves[0..($layer_count-1)] ], [ @z_moves[$layer_count..$#z_moves] ], 'complete_objects generates the correct Z moves';
82
my $convex_hull = convex_hull(\@extrusions);
83
ok !(defined first { !$convex_hull->contains_point($_) } @travel_moves), 'all travel moves happen within skirt';
87
my $config = Slic3r::Config->new_from_defaults;
88
$config->set('retract_length', [1000000]);
89
$config->set('use_relative_e_distances', 1);
90
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
91
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
92
my ($self, $cmd, $args, $info) = @_;
96
ok $print->print->total_used_filament > 0, 'final retraction is not considered in total used filament';
101
my ($print, $comment) = @_;
104
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
105
my ($self, $cmd, $args, $info) = @_;
108
push @percent, $args->{P};
111
# the extruder heater is turned off when M73 P100 is reached
112
ok !(defined first { $_ > 100 } @percent), "M73 is never given more than 100% ($comment)";
116
my $config = Slic3r::Config->new_from_defaults;
117
$config->set('gcode_flavor', 'sailfish');
118
$config->set('raft_layers', 3);
119
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
120
$test->($print, 'single object');
124
my $config = Slic3r::Config->new_from_defaults;
125
$config->set('gcode_flavor', 'sailfish');
126
my $print = Slic3r::Test::init_print('20mm_cube', config => $config, duplicate => 2);
127
$test->($print, 'two copies of single object');
131
my $config = Slic3r::Config->new_from_defaults;
132
$config->set('gcode_flavor', 'sailfish');
133
my $print = Slic3r::Test::init_print(['20mm_cube','20mm_cube'], config => $config);
134
$test->($print, 'two objects');