1
use Test::More tests => 16;
7
use lib "$FindBin::Bin/../lib";
10
use List::Util qw(first);
12
use Slic3r::Geometry qw(epsilon scale);
13
use Slic3r::Geometry::Clipper qw(diff);
17
my $config = Slic3r::Config->new_from_defaults;
18
$config->set('support_material', 1);
19
my @contact_z = my @top_z = ();
22
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
23
$print->print->init_extruders;
24
my $flow = $print->print->objects->[0]->support_material_flow;
25
my $support_z = Slic3r::Print::SupportMaterial
27
object_config => $print->print->objects->[0]->config,
28
print_config => $print->print->config,
30
interface_flow => $flow,
31
first_layer_flow => $flow,
33
->support_layers_z(\@contact_z, \@top_z, $config->layer_height);
35
is $support_z->[0], $config->first_layer_height,
36
'first layer height is honored';
37
is scalar(grep { $support_z->[$_]-$support_z->[$_-1] <= 0 } 1..$#$support_z), 0,
38
'no null or negative support layers';
39
is scalar(grep { $support_z->[$_]-$support_z->[$_-1] > $config->nozzle_diameter->[0] + epsilon } 1..$#$support_z), 0,
40
'no layers thicker than nozzle diameter';
42
my $wrong_top_spacing = 0;
43
foreach my $top_z (@top_z) {
44
# find layer index of this top surface
45
my $layer_id = first { abs($support_z->[$_] - $top_z) < epsilon } 0..$#$support_z;
47
# check that first support layer above this top surface is spaced with nozzle diameter
48
$wrong_top_spacing = 1
49
if ($support_z->[$layer_id+1] - $support_z->[$layer_id]) != $config->nozzle_diameter->[0];
51
ok !$wrong_top_spacing, 'layers above top surfaces are spaced correctly';
54
$config->set('layer_height', 0.2);
55
$config->set('first_layer_height', 0.3);
60
$config->set('first_layer_height', 0.4);
63
$config->set('layer_height', $config->nozzle_diameter->[0]);
68
my $config = Slic3r::Config->new_from_defaults;
69
$config->set('raft_layers', 3);
70
$config->set('brim_width', 6);
71
$config->set('skirts', 0);
72
$config->set('support_material_extruder', 2);
73
$config->set('support_material_interface_extruder', 2);
74
$config->set('layer_height', 0.4);
75
$config->set('first_layer_height', '100%');
76
my $print = Slic3r::Test::init_print('overhang', config => $config);
77
ok my $gcode = Slic3r::Test::gcode($print), 'no conflict between raft/support and brim';
80
Slic3r::GCode::Reader->new->parse($gcode, sub {
81
my ($self, $cmd, $args, $info) = @_;
83
if ($cmd =~ /^T(\d+)/) {
85
} elsif ($info->{extruding}) {
86
if ($self->Z <= ($config->raft_layers * $config->layer_height)) {
87
fail 'not extruding raft/brim with support material extruder'
88
if $tool != ($config->support_material_extruder-1);
90
fail 'support material exceeds raft layers'
91
if $tool == $config->support_material_extruder-1;
92
# TODO: we should test that full support is generated when we use raft too
99
my $config = Slic3r::Config->new_from_defaults;
100
$config->set('skirts', 0);
101
$config->set('raft_layers', 3);
102
$config->set('support_material_pattern', 'honeycomb');
103
$config->set('support_material_extrusion_width', 0.6);
104
$config->set('first_layer_extrusion_width', '100%');
105
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
108
my @raft = my @first_object_layer = ();
109
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
110
my ($self, $cmd, $args, $info) = @_;
112
if ($info->{extruding} && $info->{dist_XY} > 0) {
113
if ($layer_id <= $config->raft_layers) {
114
# this is a raft layer or the first object layer
115
my $line = Slic3r::Line->new_scale([ $self->X, $self->Y ], [ $info->{new_X}, $info->{new_Y} ]);
116
my @path = @{$line->grow(scale($config->support_material_extrusion_width/2))};
117
if ($layer_id < $config->raft_layers) {
118
# this is a raft layer
121
push @first_object_layer, @path;
124
} elsif ($cmd eq 'G1' && $info->{dist_Z} > 0) {
129
ok !@{diff(\@first_object_layer, \@raft)},
130
'first object layer is completely supported by raft';
133
foreach my $raft_layers (2, 70) {
134
my $config = Slic3r::Config->new_from_defaults;
135
$config->set('skirts', 0);
136
$config->set('raft_layers', $raft_layers);
137
$config->set('layer_height', 0.35);
138
$config->set('first_layer_height', 0.3);
139
$config->set('nozzle_diameter', [0.5]);
140
$config->set('support_material_extruder', 2);
141
$config->set('support_material_interface_extruder', 2);
142
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
143
my %raft_z = (); # z => 1
145
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
146
my ($self, $cmd, $args, $info) = @_;
148
if ($cmd =~ /^T(\d+)/) {
150
} elsif ($info->{extruding} && $info->{dist_XY} > 0) {
151
if ($tool == $config->support_material_extruder-1) {
152
$raft_z{$self->Z} = 1;
157
is scalar(keys %raft_z), $config->raft_layers, 'correct number of raft layers is generated';