123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- use Test::More tests => 24;
- use strict;
- use warnings;
- BEGIN {
- use FindBin;
- use lib "$FindBin::Bin/../lib";
- use local::lib "$FindBin::Bin/../local-lib";
- }
- use List::Util qw(first sum);
- use Slic3r;
- use Slic3r::Geometry qw(epsilon);
- use Slic3r::Surface qw(S_TYPE_TOP);
- use Slic3r::Test;
- {
- my $config = Slic3r::Config->new_from_defaults;
- $config->set('skirts', 0);
- $config->set('perimeters', 0);
- $config->set('solid_infill_speed', 99);
- $config->set('top_solid_infill_speed', 99);
- $config->set('bridge_speed', 72);
- $config->set('first_layer_speed', '100%');
- $config->set('cooling', 0);
-
- my $test = sub {
- my ($conf) = @_;
- $conf ||= $config;
-
- my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
-
- my %z = ();
- my %layers_with_solid_infill = ();
- my %layers_with_bridge_infill = ();
- Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
- my ($self, $cmd, $args, $info) = @_;
-
- if ($self->Z > 0) {
- $z{ $self->Z } = 1;
- if ($info->{extruding} && $info->{dist_XY} > 0) {
- my $F = $args->{F} // $self->F;
- $layers_with_solid_infill{$self->Z} = 1
- if $F == $config->solid_infill_speed*60;
- $layers_with_bridge_infill{$self->Z} = 1
- if $F == $config->bridge_speed*60;
- }
- }
- });
- my @z = sort { $a <=> $b } keys %z;
- my @shells = map $layers_with_solid_infill{$_} || $layers_with_bridge_infill{$_}, @z;
- fail "insufficient number of bottom solid layers"
- unless !defined(first { !$_ } @shells[0..$config->bottom_solid_layers-1]);
- fail "excessive number of bottom solid layers"
- unless scalar(grep $_, @shells[0 .. $#shells/2]) == $config->bottom_solid_layers;
- fail "insufficient number of top solid layers"
- unless !defined(first { !$_ } @shells[-$config->top_solid_layers..-1]);
- fail "excessive number of top solid layers"
- unless scalar(grep $_, @shells[($#shells/2)..$#shells]) == $config->top_solid_layers;
- if ($config->top_solid_layers > 0) {
- fail "unexpected solid infill speed in first solid layer over sparse infill"
- if $layers_with_solid_infill{ $z[-$config->top_solid_layers] };
- die "bridge speed not used in first solid layer over sparse infill"
- if !$layers_with_bridge_infill{ $z[-$config->top_solid_layers] };
- }
- 1;
- };
-
- $config->set('top_solid_layers', 3);
- $config->set('bottom_solid_layers', 3);
- ok $test->(), "proper number of shells is applied";
-
- $config->set('top_solid_layers', 0);
- $config->set('bottom_solid_layers', 0);
- ok $test->(), "no shells are applied when both top and bottom are set to zero";
-
- $config->set('perimeters', 1);
- $config->set('top_solid_layers', 3);
- $config->set('bottom_solid_layers', 3);
- $config->set('fill_density', 0);
- ok $test->(), "proper number of shells is applied even when fill density is none";
- }
- {
- my $config = Slic3r::Config->new_from_defaults;
- $config->set('layer_height', 0.3);
- $config->set('first_layer_height', '100%');
- $config->set('bottom_solid_layers', 0);
- $config->set('top_solid_layers', 3);
- $config->set('cooling', 0);
- $config->set('bridge_speed', 99);
- $config->set('solid_infill_speed', 99);
- $config->set('top_solid_infill_speed', 99);
- $config->set('first_layer_speed', '100%');
-
- my $print = Slic3r::Test::init_print('V', config => $config);
- my %layers_with_solid_infill = ();
- Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
- my ($self, $cmd, $args, $info) = @_;
-
- $layers_with_solid_infill{$self->Z} = 1
- if $info->{extruding} && ($args->{F} // $self->F) == $config->solid_infill_speed*60;
- });
- is scalar(map $layers_with_solid_infill{$_}, grep $_ <= 7.2, keys %layers_with_solid_infill), 3,
- "correct number of top solid shells is generated in V-shaped object";
- }
- {
- my $config = Slic3r::Config->new_from_defaults;
-
-
-
-
-
-
-
- $config->set('perimeters', 1);
- $config->set('fill_density', 0);
- $config->set('cooling', 0);
- $config->set('first_layer_speed', '100%');
- $config->set('layer_height', 0.4);
- $config->set('first_layer_height', '100%');
- $config->set('extrusion_width', 0.55);
- $config->set('bottom_solid_layers', 3);
- $config->set('top_solid_layers', 0);
- $config->set('solid_infill_speed', 99);
-
- my $print = Slic3r::Test::init_print('V', config => $config);
- my %layers = ();
- Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
- my ($self, $cmd, $args, $info) = @_;
- $layers{$self->Z} = 1
- if $info->{extruding} && ($args->{F} // $self->F) == $config->solid_infill_speed*60;
- });
- is scalar(keys %layers), $config->bottom_solid_layers,
- "shells are not propagated across perimeters of the neighbor layer";
- }
- {
- my $config = Slic3r::Config->new_from_defaults;
- $config->set('perimeters', 3);
- $config->set('cooling', 0);
- $config->set('first_layer_speed', '100%');
- $config->set('layer_height', 0.4);
- $config->set('first_layer_height', '100%');
- $config->set('bottom_solid_layers', 3);
- $config->set('top_solid_layers', 3);
- $config->set('solid_infill_speed', 99);
- $config->set('top_solid_infill_speed', 99);
- $config->set('bridge_speed', 99);
-
- my $print = Slic3r::Test::init_print('sloping_hole', config => $config);
- my %solid_layers = ();
- Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
- my ($self, $cmd, $args, $info) = @_;
- $solid_layers{$self->Z} = 1
- if $info->{extruding} && ($args->{F} // $self->F) == $config->solid_infill_speed*60;
- });
- is scalar(keys %solid_layers), $config->bottom_solid_layers + $config->top_solid_layers,
- "no superfluous shells are generated";
- }
- {
- my $config = Slic3r::Config->new_from_defaults;
- $config->set('perimeters', 1);
- $config->set('fill_density', 0);
- $config->set('top_solid_layers', 0);
- $config->set('spiral_vase', 1);
- $config->set('bottom_solid_layers', 0);
- $config->set('skirts', 0);
- $config->set('first_layer_height', '100%');
- $config->set('start_gcode', '');
- $config->set('temperature', [200]);
- $config->set('first_layer_temperature', [205]);
-
-
-
-
-
- my $test = sub {
- my ($model_name, $description) = @_;
- my $print = Slic3r::Test::init_print($model_name, config => $config);
- my $travel_moves_after_first_extrusion = 0;
- my $started_extruding = 0;
- my $first_layer_temperature_set = 0;
- my $temperature_set = 0;
- my @z_steps = ();
- Slic3r::GCode::Reader->new(Z => $config->z_offset)->parse(Slic3r::Test::gcode($print), sub {
- my ($self, $cmd, $args, $info) = @_;
-
- if ($cmd eq 'G1') {
- $started_extruding = 1 if $info->{extruding};
- push @z_steps, $info->{dist_Z}
- if $started_extruding && $info->{dist_Z} > 0;
- $travel_moves_after_first_extrusion++
- if $info->{travel} && $info->{dist_XY} > 0 && $started_extruding && !exists $args->{Z};
- } elsif ($cmd eq 'M104') {
- $first_layer_temperature_set = 1 if $args->{S} == 205;
- $temperature_set = 1 if $args->{S} == 200;
- }
- });
-
- ok $first_layer_temperature_set, 'first layer temperature is preserved';
- ok $temperature_set, 'temperature is preserved';
-
-
-
-
- ok $travel_moves_after_first_extrusion <= 1, "no gaps in spiral vase ($description)";
- ok !(grep { $_ > $config->layer_height + epsilon } @z_steps), "no gaps in Z ($description)";
- };
-
- $test->('20mm_cube', 'solid model');
-
- $config->set('z_offset', -10);
- $test->('20mm_cube', 'solid model with negative z-offset');
-
-
-
-
- }
- {
- my $config = Slic3r::Config->new_from_defaults;
- $config->set('spiral_vase', 1);
- $config->set('perimeters', 1);
- $config->set('fill_density', 0);
- $config->set('top_solid_layers', 0);
- $config->set('bottom_solid_layers', 0);
- $config->set('retract_layer_change', [0]);
- $config->set('skirts', 0);
- $config->set('first_layer_height', '100%');
- $config->set('layer_height', 0.4);
- $config->set('start_gcode', '');
- $config->validate;
-
- my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
- my $z_moves = 0;
- my @this_layer = ();
-
- my $bottom_layer_not_flat = 0;
- my $null_z_moves_not_layer_changes = 0;
- my $null_z_moves_not_multiples_of_layer_height = 0;
- my $sum_of_partial_z_equals_to_layer_height = 0;
- my $all_layer_segments_have_same_slope = 0;
- my $horizontal_extrusions = 0;
-
- Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
- my ($self, $cmd, $args, $info) = @_;
-
- if ($cmd eq 'G1') {
- if ($z_moves < 2) {
-
-
- if (exists $args->{Z}) {
- $z_moves++;
- $bottom_layer_not_flat = 1
- if $info->{dist_Z} > 0 && $info->{dist_Z} != $config->layer_height;
- }
- } elsif ($info->{dist_Z} == 0 && $args->{Z}) {
- $null_z_moves_not_layer_changes = 1
- if $info->{dist_XY} != 0;
-
-
- $null_z_moves_not_multiples_of_layer_height = 1
- if abs(($args->{Z} / $config->layer_height) * $config->layer_height - $args->{Z}) > epsilon;
-
- my $total_dist_XY = sum(map $_->[1], @this_layer);
- $sum_of_partial_z_equals_to_layer_height = 1
- if abs(sum(map $_->[0], @this_layer) - $config->layer_height) > epsilon;
-
- foreach my $segment (@this_layer) {
-
- $all_layer_segments_have_same_slope = 1
- if abs($segment->[0]*$total_dist_XY/$config->layer_height - $segment->[1]) > 0.2;
- }
-
- @this_layer = ();
- } elsif ($info->{extruding} && $info->{dist_XY} > 0) {
- $horizontal_extrusions = 1
- if $info->{dist_Z} == 0;
- push @this_layer, [ $info->{dist_Z}, $info->{dist_XY} ];
- }
- }
- });
- ok !$bottom_layer_not_flat, 'bottom layer is flat when using spiral vase';
- ok !$null_z_moves_not_layer_changes, 'null Z moves are layer changes';
- ok !$null_z_moves_not_multiples_of_layer_height, 'null Z moves are multiples of layer height';
- ok !$sum_of_partial_z_equals_to_layer_height, 'sum of partial Z increments equals to a full layer height';
- ok !$all_layer_segments_have_same_slope, 'all layer segments have the same slope';
- ok !$horizontal_extrusions, 'no horizontal extrusions';
- }
- {
- my $config = Slic3r::Config->new_from_defaults;
- $config->set('perimeters', 1);
- $config->set('fill_density', 0);
- $config->set('top_solid_layers', 0);
- $config->set('spiral_vase', 1);
- $config->set('bottom_solid_layers', 0);
- $config->set('skirts', 0);
- $config->set('first_layer_height', '100%');
- $config->set('start_gcode', '');
-
- my $print = Slic3r::Test::init_print('two_hollow_squares', config => $config);
- my $diagonal_moves = 0;
- Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
- my ($self, $cmd, $args, $info) = @_;
-
- if ($cmd eq 'G1') {
- if ($info->{extruding} && $info->{dist_XY} > 0) {
- if ($info->{dist_Z} > 0) {
- $diagonal_moves++;
- }
- }
- }
- });
- is $diagonal_moves, 0, 'no spiral moves on two-island object';
- }
- {
-
- my $config = Slic3r::Config->new_from_defaults;
- $config->set('perimeters', 2);
- $config->set('extrusion_width', 0.55);
- $config->set('first_layer_height', 0.25);
- $config->set('infill_overlap', '50%');
- $config->set('layer_height', 0.25);
- $config->set('perimeters', 2);
- $config->set('extra_perimeters', 1);
-
- my $tprint = Slic3r::Test::init_print('step', config => $config);
- $tprint->print->process;
- my $layerm19 = $tprint->print->get_object(0)->get_layer(19)->get_region(0);
- is scalar(@{$layerm19->slices->filter_by_type(S_TYPE_TOP)}), 1, 'top slice detected';
- is scalar(@{$layerm19->fill_surfaces->filter_by_type(S_TYPE_TOP)}), 0, 'no top fill_surface detected';
- is $layerm19->perimeters->items_count, 3, 'extra perimeter detected';
- }
- __END__
|