Perl unit tests for perimeters and multi-material were rewritten to C++.

Perl binding was slimmed down, namely Clipper is no more linked by Perl.
This commit is contained in:
Vojtech Bubnik 2022-05-04 15:05:56 +02:00
parent 7380787b3a
commit a627614b58
48 changed files with 1194 additions and 2310 deletions

View file

@ -1,93 +0,0 @@
use Test::More;
use strict;
use warnings;
plan skip_all => 'variable-width paths are currently disabled';
plan tests => 20;
BEGIN {
use FindBin;
use lib "$FindBin::Bin/../lib";
use local::lib "$FindBin::Bin/../local-lib";
}
use List::Util qw(first);
use Slic3r;
use Slic3r::Geometry qw(X Y scale epsilon);
use Slic3r::Surface ':types';
sub scale_points (@) { map [scale $_->[X], scale $_->[Y]], @_ }
{
my $square = Slic3r::ExPolygon->new([
scale_points [0,0], [10,0], [10,10], [0,10],
]);
my @offsets = @{$square->noncollapsing_offset_ex(- scale 5)};
is scalar @offsets, 1, 'non-collapsing offset';
}
{
local $Slic3r::Config = Slic3r::Config->new(
perimeters => 3,
);
my $w = 0.7;
my $perimeter_flow = Slic3r::Flow->new(
nozzle_diameter => 0.5,
layer_height => 0.4,
width => $w,
);
my $print = Slic3r::Print->new;
my $region = Slic3r::Print::Region->new(
print => $print,
flows => { perimeter => $perimeter_flow },
);
push @{$print->regions}, $region;
my $object = Slic3r::Print::Object->new(
print => $print,
size => [1,1],
);
my $make_layer = sub {
my ($width) = @_;
my $layer = Slic3r::Layer->new(
object => $object,
id => 1,
slices => [
Slic3r::Surface->new(
surface_type => S_TYPE_INTERNAL,
expolygon => Slic3r::ExPolygon->new([ scale_points [0,0], [50,0], [50,$width], [0,$width] ]),
),
],
thin_walls => [],
);
my $layerm = $layer->region(0);
$layer->make_perimeters;
return $layerm;
};
my %widths = (
1 * $w => { perimeters => 1, gaps => 0 },
1.3 * $w => { perimeters => 1, gaps => 1, gap_flow_spacing => $perimeter_flow->clone(width => 0.2 * $w)->spacing },
1.5 * $w => { perimeters => 1, gaps => 1, gap_flow_spacing => $perimeter_flow->clone(width => 0.5 * $w)->spacing },
2 * $w => { perimeters => 1, gaps => 1, gap_flow_spacing => $perimeter_flow->spacing },
2.5 * $w => { perimeters => 1, gaps => 1, gap_flow_spacing => $perimeter_flow->clone(width => 1.5 * $w)->spacing },
3 * $w => { perimeters => 2, gaps => 0 },
4 * $w => { perimeters => 2, gaps => 1, gap_flow_spacing => $perimeter_flow->spacing },
);
foreach my $width (sort keys %widths) {
my $layerm = $make_layer->($width);
is scalar @{$layerm->perimeters}, $widths{$width}{perimeters}, 'right number of perimeters';
is scalar @{$layerm->thin_fills} ? 1 : 0, $widths{$width}{gaps},
($widths{$width}{gaps} ? 'gaps were filled' : 'no gaps detected'); # TODO: we should check the exact number of gaps, but we need a better medial axis algorithm
my @gaps = map $_, @{$layerm->thin_fills};
if (@gaps) {
ok +(!first { abs($_->flow_spacing - $widths{$width}{gap_flow_spacing}) > epsilon } @gaps),
'flow spacing was dynamically adjusted';
}
}
}
__END__

View file

@ -2,7 +2,7 @@ use Test::More;
use strict;
use warnings;
plan tests => 27;
plan tests => 26;
BEGIN {
use FindBin;
@ -125,13 +125,6 @@ my $polygons = [
#==========================================================
{
my $line = Slic3r::Line->new([10,10], [20,10]);
is $line->grow(5)->[0]->area, Slic3r::Polygon->new([10,5], [20,5], [20,15], [10,15])->area, 'grow line';
}
#==========================================================
{
# if chained_path() works correctly, these points should be joined with no diagonal paths
# (thus 26 units long)

221
t/multi.t
View file

@ -1,221 +0,0 @@
use Test::More tests => 13;
use strict;
use warnings;
BEGIN {
use FindBin;
use lib "$FindBin::Bin/../lib";
use local::lib "$FindBin::Bin/../local-lib";
}
use List::Util qw(first);
use Slic3r;
use Slic3r::Geometry qw(scale convex_hull);
use Slic3r::Geometry::Clipper qw(offset);
use Slic3r::Test;
{
my $config = Slic3r::Config::new_from_defaults;
$config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]);
$config->set('raft_layers', 2);
$config->set('infill_extruder', 2);
$config->set('solid_infill_extruder', 3);
$config->set('support_material_extruder', 4);
$config->set('ooze_prevention', 1);
$config->set('extruder_offset', [ [0,0], [20,0], [0,20], [20,20] ]);
$config->set('temperature', [200, 180, 170, 160]);
$config->set('first_layer_temperature', [206, 186, 166, 156]);
$config->set('toolchange_gcode', 'T[next_extruder] ;toolchange'); # test that it doesn't crash when this is supplied
# Since July 2019, PrusaSlicer only emits automatic Tn command in case that the toolchange_gcode is empty
# The "T[next_extruder]" is therefore needed in this test.
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
my $tool = undef;
my @tool_temp = (0,0,0,0);
my @toolchange_points = ();
my @extrusion_points = ();
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
my ($self, $cmd, $args, $info) = @_;
if ($cmd =~ /^T(\d+)/) {
# ignore initial toolchange
if (defined $tool) {
my $expected_temp = $self->Z == ($config->get_value('first_layer_height') + $config->z_offset)
? $config->first_layer_temperature->[$tool]
: $config->temperature->[$tool];
die 'standby temperature was not set before toolchange'
if $tool_temp[$tool] != $expected_temp + $config->standby_temperature_delta;
push @toolchange_points, my $point = Slic3r::Point->new_scale($self->X, $self->Y);
}
$tool = $1;
} elsif ($cmd eq 'M104' || $cmd eq 'M109') {
my $t = $args->{T} // $tool;
if ($tool_temp[$t] == 0) {
fail 'initial temperature is not equal to first layer temperature + standby delta'
unless $args->{S} == $config->first_layer_temperature->[$t] + $config->standby_temperature_delta;
}
$tool_temp[$t] = $args->{S};
} elsif ($cmd eq 'G1' && $info->{extruding} && $info->{dist_XY} > 0) {
push @extrusion_points, my $point = Slic3r::Point->new_scale($args->{X}, $args->{Y});
$point->translate(map +scale($_), @{ $config->extruder_offset->[$tool] });
}
});
my $convex_hull = convex_hull(\@extrusion_points);
my @t = ();
foreach my $point (@toolchange_points) {
foreach my $offset (@{$config->extruder_offset}) {
push @t, my $p = $point->clone;
$p->translate(map +scale($_), @$offset);
}
}
ok !(defined first { $convex_hull->contains_point($_) } @t), 'all nozzles are outside skirt at toolchange';
if (0) {
require "Slic3r/SVG.pm";
Slic3r::SVG::output(
"ooze_prevention_test.svg",
no_arrows => 1,
polygons => [$convex_hull],
red_points => \@t,
points => \@toolchange_points,
);
}
# offset the skirt by the maximum displacement between extruders plus a safety extra margin
my $delta = scale(20 * sqrt(2) + 1);
my $outer_convex_hull = offset([$convex_hull], +$delta)->[0];
ok !(defined first { !$outer_convex_hull->contains_point($_) } @toolchange_points), 'all toolchanges happen within expected area';
}
{
my $config = Slic3r::Config::new_from_defaults;
$config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]);
$config->set('support_material_extruder', 3);
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
ok Slic3r::Test::gcode($print), 'no errors when using non-consecutive extruders';
}
{
my $config = Slic3r::Config->new;
$config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]);
$config->set('extruder', 2);
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
like Slic3r::Test::gcode($print), qr/ T1/, 'extruder shortcut';
}
{
my $config = Slic3r::Config->new;
$config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]);
$config->set('perimeter_extruder', 2);
$config->set('infill_extruder', 2);
$config->set('support_material_extruder', 2);
$config->set('support_material_interface_extruder', 2);
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
ok Slic3r::Test::gcode($print), 'no errors when using multiple skirts with a single, non-zero, extruder';
}
{
my $model = stacked_cubes();
my $lower_config = $model->get_material('lower')->config;
my $upper_config = $model->get_material('upper')->config;
$lower_config->set('extruder', 1);
$lower_config->set('bottom_solid_layers', 0);
$lower_config->set('top_solid_layers', 1);
$upper_config->set('extruder', 2);
$upper_config->set('bottom_solid_layers', 1);
$upper_config->set('top_solid_layers', 0);
my $config = Slic3r::Config::new_from_defaults;
$config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]);
$config->set('fill_density', 0);
$config->set('solid_infill_speed', 99);
$config->set('top_solid_infill_speed', 99);
$config->set('cooling', [ 0 ]); # for preventing speeds from being altered
$config->set('first_layer_speed', '100%'); # for preventing speeds from being altered
my $test = sub {
my $print = Slic3r::Test::init_print($model, config => $config);
my $tool = undef;
my %T0_shells = my %T1_shells = (); # Z => 1
Slic3r::GCode::Reader->new->parse(my $gcode = Slic3r::Test::gcode($print), sub {
my ($self, $cmd, $args, $info) = @_;
if ($cmd =~ /^T(\d+)/) {
$tool = $1;
} elsif ($cmd eq 'G1' && $info->{extruding} && $info->{dist_XY} > 0) {
if (($args->{F} // $self->F) == $config->solid_infill_speed*60) {
if ($tool == 0) {
$T0_shells{$self->Z} = 1;
} elsif ($tool == 1) {
$T1_shells{$self->Z} = 1;
}
}
}
});
return [ sort keys %T0_shells ], [ sort keys %T1_shells ];
};
{
my ($t0, $t1) = $test->();
is scalar(@$t0), 0, 'no interface shells';
is scalar(@$t1), 0, 'no interface shells';
}
{
$config->set('interface_shells', 1);
my ($t0, $t1) = $test->();
is scalar(@$t0), $lower_config->top_solid_layers, 'top interface shells';
is scalar(@$t1), $upper_config->bottom_solid_layers, 'bottom interface shells';
}
}
{
my $model = stacked_cubes();
my $object = $model->objects->[0];
my $config = Slic3r::Config::new_from_defaults;
$config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]);
$config->set('layer_height', 0.4);
$config->set('first_layer_height', $config->layer_height);
$config->set('skirts', 0);
my $print = Slic3r::Test::init_print($model, config => $config);
is $object->volumes->[0]->config->extruder, 1, 'auto_assign_extruders() assigned correct extruder to first volume';
is $object->volumes->[1]->config->extruder, 2, 'auto_assign_extruders() assigned correct extruder to second volume';
my $tool = undef;
my %T0 = my %T1 = (); # Z => 1
Slic3r::GCode::Reader->new->parse(my $gcode = Slic3r::Test::gcode($print), sub {
my ($self, $cmd, $args, $info) = @_;
if ($cmd =~ /^T(\d+)/) {
$tool = $1;
} elsif ($cmd eq 'G1' && $info->{extruding} && $info->{dist_XY} > 0) {
if ($tool == 0) {
$T0{$self->Z} = 1;
} elsif ($tool == 1) {
$T1{$self->Z} = 1;
}
}
});
ok !(defined first { $_ > 20 } keys %T0), 'T0 is never used for upper object';
ok !(defined first { $_ < 20 } keys %T1), 'T1 is never used for lower object';
}
sub stacked_cubes {
my $model = Slic3r::Model->new;
my $object = $model->add_object;
$object->add_volume(mesh => Slic3r::Test::mesh('20mm_cube'), material_id => 'lower');
$object->add_volume(mesh => Slic3r::Test::mesh('20mm_cube', translate => [0,0,20]), material_id => 'upper');
$object->add_instance(offset => Slic3r::Pointf->new(0,0));
return $model;
}
__END__

File diff suppressed because one or more lines are too long

152
t/slice.t
View file

@ -1,152 +0,0 @@
use Test::More;
use strict;
use warnings;
plan skip_all => 'temporarily disabled';
plan tests => 16;
BEGIN {
use FindBin;
use lib "$FindBin::Bin/../lib";
use local::lib "$FindBin::Bin/../local-lib";
}
# temporarily disable compilation errors due to constant not being exported anymore
sub Slic3r::TriangleMesh::I_B {}
sub Slic3r::TriangleMesh::I_FACET_EDGE {}
sub Slic3r::TriangleMesh::FE_BOTTOM {
sub Slic3r::TriangleMesh::FE_TOP {}}
use Slic3r;
use Slic3r::Geometry qw(X Y Z);
my @lines;
my $z = 20;
my @points = ([3, 4], [8, 5], [1, 9]); # XY coordinates of the facet vertices
# NOTE:
# the first point of the intersection lines is replaced by -1 because TriangleMesh.pm
# is saving memory and doesn't store point A anymore since it's not actually needed.
# We disable this test because intersect_facet() now assumes we never feed a horizontal
# facet to it.
# is_deeply lines(20, 20, 20), [
# [ -1, $points[1] ], # $points[0]
# [ -1, $points[2] ], # $points[1]
# [ -1, $points[0] ], # $points[2]
# ], 'horizontal';
is_deeply lines(22, 20, 20), [ [ -1, $points[2] ] ], 'lower edge on layer'; # $points[1]
is_deeply lines(20, 20, 22), [ [ -1, $points[1] ] ], 'lower edge on layer'; # $points[0]
is_deeply lines(20, 22, 20), [ [ -1, $points[0] ] ], 'lower edge on layer'; # $points[2]
is_deeply lines(20, 20, 10), [ [ -1, $points[0] ] ], 'upper edge on layer'; # $points[1]
is_deeply lines(10, 20, 20), [ [ -1, $points[1] ] ], 'upper edge on layer'; # $points[2]
is_deeply lines(20, 10, 20), [ [ -1, $points[2] ] ], 'upper edge on layer'; # $points[0]
is_deeply lines(20, 15, 10), [ ], 'upper vertex on layer';
is_deeply lines(28, 20, 30), [ ], 'lower vertex on layer';
{
my @z = (24, 10, 16);
is_deeply lines(@z), [
[
-1, # line_plane_intersection([ vertices(@z)->[0], vertices(@z)->[1] ]),
line_plane_intersection([ vertices(@z)->[2], vertices(@z)->[0] ]),
]
], 'two edges intersect';
}
{
my @z = (16, 24, 10);
is_deeply lines(@z), [
[
-1, # line_plane_intersection([ vertices(@z)->[1], vertices(@z)->[2] ]),
line_plane_intersection([ vertices(@z)->[0], vertices(@z)->[1] ]),
]
], 'two edges intersect';
}
{
my @z = (10, 16, 24);
is_deeply lines(@z), [
[
-1, # line_plane_intersection([ vertices(@z)->[2], vertices(@z)->[0] ]),
line_plane_intersection([ vertices(@z)->[1], vertices(@z)->[2] ]),
]
], 'two edges intersect';
}
{
my @z = (24, 10, 20);
is_deeply lines(@z), [
[
-1, # line_plane_intersection([ vertices(@z)->[0], vertices(@z)->[1] ]),
$points[2],
]
], 'one vertex on plane and one edge intersects';
}
{
my @z = (10, 20, 24);
is_deeply lines(@z), [
[
-1, # line_plane_intersection([ vertices(@z)->[2], vertices(@z)->[0] ]),
$points[1],
]
], 'one vertex on plane and one edge intersects';
}
{
my @z = (20, 24, 10);
is_deeply lines(@z), [
[
-1, # line_plane_intersection([ vertices(@z)->[1], vertices(@z)->[2] ]),
$points[0],
]
], 'one vertex on plane and one edge intersects';
}
my @lower = intersect(22, 20, 20);
my @upper = intersect(20, 20, 10);
is $lower[0][Slic3r::TriangleMesh::I_FACET_EDGE], Slic3r::TriangleMesh::FE_BOTTOM, 'bottom edge on layer';
is $upper[0][Slic3r::TriangleMesh::I_FACET_EDGE], Slic3r::TriangleMesh::FE_TOP, 'upper edge on layer';
my $mesh;
sub intersect {
$mesh = Slic3r::TriangleMesh->new(
facets => [],
vertices => [],
);
push @{$mesh->facets}, [ [0,0,0], @{vertices(@_)} ];
$mesh->analyze;
return map Slic3r::TriangleMesh::unpack_line($_), $mesh->intersect_facet($#{$mesh->facets}, $z);
}
sub vertices {
push @{$mesh->vertices}, map [ @{$points[$_]}, $_[$_] ], 0..2;
[ ($#{$mesh->vertices}-2) .. $#{$mesh->vertices} ]
}
sub lines {
my @lines = intersect(@_);
#$_->a->[X] = sprintf('%.0f', $_->a->[X]) for @lines;
#$_->a->[Y] = sprintf('%.0f', $_->a->[Y]) for @lines;
$_->[Slic3r::TriangleMesh::I_B][X] = sprintf('%.0f', $_->[Slic3r::TriangleMesh::I_B][X]) for @lines;
$_->[Slic3r::TriangleMesh::I_B][Y] = sprintf('%.0f', $_->[Slic3r::TriangleMesh::I_B][Y]) for @lines;
return [ map [ -1, $_->[Slic3r::TriangleMesh::I_B] ], @lines ];
}
sub line_plane_intersection {
my ($line) = @_;
@$line = map $mesh->vertices->[$_], @$line;
return [
map sprintf('%.0f', $_),
map +($line->[1][$_] + ($line->[0][$_] - $line->[1][$_]) * ($z - $line->[1][Z]) / ($line->[0][Z] - $line->[1][Z])),
(X,Y)
];
}
__END__

View file

@ -1,272 +0,0 @@
use Test::More;
use strict;
use warnings;
plan skip_all => 'temporarily disabled';
plan tests => 27;
BEGIN {
use FindBin;
use lib "$FindBin::Bin/../lib";
use local::lib "$FindBin::Bin/../local-lib";
}
use List::Util qw(first);
use Slic3r;
use Slic3r::Flow ':roles';
use Slic3r::Geometry qw(epsilon scale);
use Slic3r::Geometry::Clipper qw(diff);
use Slic3r::Test;
{
my $config = Slic3r::Config::new_from_defaults;
$config->set('support_material', 1);
my @contact_z = my @top_z = ();
my $test = sub {
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
my $object_config = $print->print->objects->[0]->config;
my $flow = Slic3r::Flow->new_from_width(
width => $object_config->support_material_extrusion_width || $object_config->extrusion_width,
role => FLOW_ROLE_SUPPORT_MATERIAL,
nozzle_diameter => $print->config->nozzle_diameter->[$object_config->support_material_extruder-1] // $print->config->nozzle_diameter->[0],
layer_height => $object_config->layer_height,
);
my $support = Slic3r::Print::SupportMaterial->new(
object_config => $print->print->objects->[0]->config,
print_config => $print->print->config,
flow => $flow,
interface_flow => $flow,
first_layer_flow => $flow,
);
my $support_z = $support->support_layers_z($print->print->objects->[0], \@contact_z, \@top_z, $config->layer_height);
my $expected_top_spacing = $support->contact_distance($config->layer_height, $config->nozzle_diameter->[0]);
is $support_z->[0], $config->first_layer_height,
'first layer height is honored';
is scalar(grep { $support_z->[$_]-$support_z->[$_-1] <= 0 } 1..$#$support_z), 0,
'no null or negative support layers';
is scalar(grep { $support_z->[$_]-$support_z->[$_-1] > $config->nozzle_diameter->[0] + epsilon } 1..$#$support_z), 0,
'no layers thicker than nozzle diameter';
my $wrong_top_spacing = 0;
foreach my $top_z (@top_z) {
# find layer index of this top surface
my $layer_id = first { abs($support_z->[$_] - $top_z) < epsilon } 0..$#$support_z;
# check that first support layer above this top surface (or the next one) is spaced with nozzle diameter
$wrong_top_spacing = 1
if ($support_z->[$layer_id+1] - $support_z->[$layer_id]) != $expected_top_spacing
&& ($support_z->[$layer_id+2] - $support_z->[$layer_id]) != $expected_top_spacing;
}
ok !$wrong_top_spacing, 'layers above top surfaces are spaced correctly';
};
$config->set('layer_height', 0.2);
$config->set('first_layer_height', 0.3);
@contact_z = (1.9);
@top_z = (1.1);
$test->();
$config->set('first_layer_height', 0.4);
$test->();
$config->set('layer_height', $config->nozzle_diameter->[0]);
$test->();
}
{
my $config = Slic3r::Config::new_from_defaults;
$config->set('raft_layers', 3);
$config->set('brim_width', 0);
$config->set('skirts', 0);
$config->set('support_material_extruder', 2);
$config->set('support_material_interface_extruder', 2);
$config->set('layer_height', 0.4);
$config->set('first_layer_height', 0.4);
my $print = Slic3r::Test::init_print('overhang', config => $config);
ok my $gcode = Slic3r::Test::gcode($print), 'no conflict between raft/support and brim';
my $tool = 0;
Slic3r::GCode::Reader->new->parse($gcode, sub {
my ($self, $cmd, $args, $info) = @_;
if ($cmd =~ /^T(\d+)/) {
$tool = $1;
} elsif ($info->{extruding}) {
if ($self->Z <= ($config->raft_layers * $config->layer_height)) {
fail 'not extruding raft with support material extruder'
if $tool != ($config->support_material_extruder-1);
} else {
fail 'support material exceeds raft layers'
if $tool == $config->support_material_extruder-1;
# TODO: we should test that full support is generated when we use raft too
}
}
});
}
{
my $config = Slic3r::Config::new_from_defaults;
$config->set('skirts', 0);
$config->set('raft_layers', 3);
$config->set('support_material_pattern', 'honeycomb');
$config->set('support_material_extrusion_width', 0.6);
$config->set('first_layer_extrusion_width', '100%');
$config->set('bridge_speed', 99);
$config->set('cooling', [ 0 ]); # prevent speed alteration
$config->set('first_layer_speed', '100%'); # prevent speed alteration
$config->set('start_gcode', ''); # prevent any unexpected Z move
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
my $layer_id = -1; # so that first Z move sets this to 0
my @raft = my @first_object_layer = ();
my %first_object_layer_speeds = (); # F => 1
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
my ($self, $cmd, $args, $info) = @_;
if ($info->{extruding} && $info->{dist_XY} > 0) {
if ($layer_id <= $config->raft_layers) {
# this is a raft layer or the first object layer
my $line = Slic3r::Line->new_scale([ $self->X, $self->Y ], [ $info->{new_X}, $info->{new_Y} ]);
my @path = @{$line->grow(scale($config->support_material_extrusion_width/2))};
if ($layer_id < $config->raft_layers) {
# this is a raft layer
push @raft, @path;
} else {
push @first_object_layer, @path;
$first_object_layer_speeds{ $args->{F} // $self->F } = 1;
}
}
} elsif ($cmd eq 'G1' && $info->{dist_Z} > 0) {
$layer_id++;
}
});
ok !@{diff(\@first_object_layer, \@raft)},
'first object layer is completely supported by raft';
is scalar(keys %first_object_layer_speeds), 1,
'only one speed used in first object layer';
ok +(keys %first_object_layer_speeds)[0] == $config->bridge_speed*60,
'bridge speed used in first object layer';
}
{
my $config = Slic3r::Config::new_from_defaults;
$config->set('skirts', 0);
$config->set('layer_height', 0.35);
$config->set('first_layer_height', 0.3);
$config->set('nozzle_diameter', [0.5]);
$config->set('support_material_extruder', 2);
$config->set('support_material_interface_extruder', 2);
my $test = sub {
my ($raft_layers) = @_;
$config->set('raft_layers', $raft_layers);
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
my %raft_z = (); # z => 1
my $tool = undef;
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
my ($self, $cmd, $args, $info) = @_;
if ($cmd =~ /^T(\d+)/) {
$tool = $1;
} elsif ($info->{extruding} && $info->{dist_XY} > 0) {
if ($tool == $config->support_material_extruder-1) {
$raft_z{$self->Z} = 1;
}
}
});
is scalar(keys %raft_z), $config->raft_layers, 'correct number of raft layers is generated';
};
$test->(2);
$test->(70);
$config->set('layer_height', 0.4);
$config->set('first_layer_height', 0.35);
$test->(3);
$test->(70);
}
{
my $config = Slic3r::Config::new_from_defaults;
$config->set('brim_width', 0);
$config->set('skirts', 0);
$config->set('support_material', 1);
$config->set('top_solid_layers', 0); # so that we don't have the internal bridge over infill
$config->set('bridge_speed', 99);
$config->set('cooling', [ 0 ]);
$config->set('first_layer_speed', '100%');
my $test = sub {
my $print = Slic3r::Test::init_print('overhang', config => $config);
my $has_bridge_speed = 0;
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
my ($self, $cmd, $args, $info) = @_;
if ($info->{extruding}) {
if (($args->{F} // $self->F) == $config->bridge_speed*60) {
$has_bridge_speed = 1;
}
}
});
return $has_bridge_speed;
};
$config->set('support_material_contact_distance', 0.2);
ok $test->(), 'bridge speed is used when support_material_contact_distance > 0';
$config->set('support_material_contact_distance', 0);
ok !$test->(), 'bridge speed is not used when support_material_contact_distance == 0';
$config->set('raft_layers', 5);
$config->set('support_material_contact_distance', 0.2);
ok $test->(), 'bridge speed is used when raft_layers > 0 and support_material_contact_distance > 0';
$config->set('support_material_contact_distance', 0);
ok !$test->(), 'bridge speed is not used when raft_layers > 0 and support_material_contact_distance == 0';
}
{
my $config = Slic3r::Config::new_from_defaults;
$config->set('skirts', 0);
$config->set('start_gcode', '');
$config->set('raft_layers', 8);
$config->set('nozzle_diameter', [0.4, 1]);
$config->set('layer_height', 0.1);
$config->set('first_layer_height', 0.8);
$config->set('support_material_extruder', 2);
$config->set('support_material_interface_extruder', 2);
$config->set('support_material_contact_distance', 0);
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
ok my $gcode = Slic3r::Test::gcode($print), 'first_layer_height is validated with support material extruder nozzle diameter when using raft layers';
my $tool = undef;
my @z = (0);
my %layer_heights_by_tool = (); # tool => [ lh, lh... ]
Slic3r::GCode::Reader->new->parse($gcode, sub {
my ($self, $cmd, $args, $info) = @_;
if ($cmd =~ /^T(\d+)/) {
$tool = $1;
} elsif ($cmd eq 'G1' && exists $args->{Z} && $args->{Z} != $self->Z) {
push @z, $args->{Z};
} elsif ($info->{extruding} && $info->{dist_XY} > 0) {
$layer_heights_by_tool{$tool} ||= [];
push @{ $layer_heights_by_tool{$tool} }, $z[-1] - $z[-2];
}
});
ok !defined(first { $_ > $config->nozzle_diameter->[0] + epsilon }
@{ $layer_heights_by_tool{$config->perimeter_extruder-1} }),
'no object layer is thicker than nozzle diameter';
ok !defined(first { abs($_ - $config->layer_height) < epsilon }
@{ $layer_heights_by_tool{$config->support_material_extruder-1} }),
'no support material layer is as thin as object layers';
}
__END__