mirror of
https://github.com/QIDITECH/QIDISlicer.git
synced 2026-02-02 00:48:43 +03:00
QIDISlicer1.0.0
This commit is contained in:
242
t/gcode.t
Normal file
242
t/gcode.t
Normal file
@@ -0,0 +1,242 @@
|
||||
use Test::More tests => 23;
|
||||
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::Test;
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('wipe', [1]);
|
||||
$config->set('retract_layer_change', [0]);
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
my $have_wipe = 0;
|
||||
my @retract_speeds = ();
|
||||
my $extruded_on_this_layer = 0;
|
||||
my $wiping_on_new_layer = 0;
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($info->{travel} && $info->{dist_Z}) {
|
||||
# changing layer
|
||||
$extruded_on_this_layer = 0;
|
||||
} elsif ($info->{extruding} && $info->{dist_XY}) {
|
||||
$extruded_on_this_layer = 1;
|
||||
} elsif ($info->{retracting} && $info->{dist_XY} > 0) {
|
||||
$have_wipe = 1;
|
||||
$wiping_on_new_layer = 1 if !$extruded_on_this_layer;
|
||||
my $move_time = $info->{dist_XY} / ($args->{F} // $self->F);
|
||||
push @retract_speeds, abs($info->{dist_E}) / $move_time;
|
||||
}
|
||||
});
|
||||
|
||||
ok $have_wipe, "wipe";
|
||||
ok !defined (first { abs($_ - $config->retract_speed->[0]*60) < 5 } @retract_speeds), 'wipe moves don\'t retract faster than configured speed';
|
||||
ok !$wiping_on_new_layer, 'no wiping after layer change';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('z_offset', 5);
|
||||
$config->set('start_gcode', '');
|
||||
|
||||
my $test = sub {
|
||||
my ($comment) = @_;
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
my $moves_below_z_offset = 0;
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($info->{travel} && exists $args->{Z}) {
|
||||
$moves_below_z_offset++ if $args->{Z} < $config->z_offset;
|
||||
}
|
||||
});
|
||||
is $moves_below_z_offset, 0, "no Z moves below Z offset ($comment)";
|
||||
};
|
||||
|
||||
$test->("no lift");
|
||||
|
||||
$config->set('retract_lift', [3]);
|
||||
$test->("lift < z_offset");
|
||||
|
||||
$config->set('retract_lift', [6]);
|
||||
$test->("lift > z_offset");
|
||||
}
|
||||
|
||||
{
|
||||
# This tests the following behavior:
|
||||
# - complete objects does not crash
|
||||
# - no hard-coded "E" are generated
|
||||
# - Z moves are correctly generated for both objects
|
||||
# - no travel moves go outside skirt
|
||||
# - temperatures are set correctly
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('gcode_comments', 1);
|
||||
$config->set('complete_objects', 1);
|
||||
$config->set('extrusion_axis', 'A');
|
||||
$config->set('start_gcode', ''); # prevent any default extra Z move
|
||||
$config->set('layer_height', 0.4);
|
||||
$config->set('first_layer_height', 0.4);
|
||||
$config->set('temperature', [200]);
|
||||
$config->set('first_layer_temperature', [210]);
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config, duplicate => 2);
|
||||
ok my $gcode = Slic3r::Test::gcode($print), "complete_objects";
|
||||
my @z_moves = ();
|
||||
my @travel_moves = (); # array of scaled points
|
||||
my @extrusions = (); # array of scaled points
|
||||
my @temps = ();
|
||||
Slic3r::GCode::Reader->new->parse($gcode, sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
fail 'unexpected E argument' if defined $args->{E};
|
||||
if (defined $args->{Z}) {
|
||||
push @z_moves, $args->{Z};
|
||||
}
|
||||
|
||||
if ($info->{dist_XY}) {
|
||||
if ($info->{extruding} || $args->{A}) {
|
||||
push @extrusions, Slic3r::Point->new_scale($info->{new_X}, $info->{new_Y});
|
||||
} else {
|
||||
push @travel_moves, Slic3r::Point->new_scale($info->{new_X}, $info->{new_Y})
|
||||
if @extrusions; # skip initial travel move to first skirt point
|
||||
}
|
||||
} elsif ($cmd eq 'M104' || $cmd eq 'M109') {
|
||||
push @temps, $args->{S} if !@temps || $args->{S} != $temps[-1];
|
||||
}
|
||||
});
|
||||
my $layer_count = 20/0.4; # cube is 20mm tall
|
||||
is scalar(@z_moves), 2*$layer_count, 'complete_objects generates the correct number of Z moves';
|
||||
is_deeply [ @z_moves[0..($layer_count-1)] ], [ @z_moves[$layer_count..$#z_moves] ], 'complete_objects generates the correct Z moves';
|
||||
|
||||
my $convex_hull = convex_hull(\@extrusions);
|
||||
ok !(defined first { !$convex_hull->contains_point($_) } @travel_moves), 'all travel moves happen within skirt';
|
||||
|
||||
is_deeply \@temps, [210, 200, 210, 200, 0], 'expected temperature changes';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('retract_length', [1000000]);
|
||||
$config->set('use_relative_e_distances', 1);
|
||||
$config->set('layer_gcode', "G92 E0\n");
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
Slic3r::Test::gcode($print);
|
||||
ok $print->print->total_used_filament > 0, 'final retraction is not considered in total used filament';
|
||||
}
|
||||
|
||||
{
|
||||
my $test = sub {
|
||||
my ($print, $comment) = @_;
|
||||
|
||||
my @percent = ();
|
||||
my $got_100 = 0;
|
||||
my $extruding_after_100 = 0;
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($cmd eq 'M73') {
|
||||
push @percent, $args->{P};
|
||||
$got_100 = 1 if $args->{P} eq '100';
|
||||
}
|
||||
if ($info->{extruding} && $got_100) {
|
||||
$extruding_after_100 = 1;
|
||||
}
|
||||
});
|
||||
# the extruder heater is turned off when M73 P100 is reached
|
||||
ok !(defined first { $_ > 100 } @percent), "M73 is never given more than 100% ($comment)";
|
||||
ok !$extruding_after_100, "no extrusions after M73 P100 ($comment)";
|
||||
};
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('gcode_flavor', 'sailfish');
|
||||
$config->set('raft_layers', 3);
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
$test->($print, 'single object');
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('gcode_flavor', 'sailfish');
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config, duplicate => 2);
|
||||
$test->($print, 'two copies of single object');
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('gcode_flavor', 'sailfish');
|
||||
my $print = Slic3r::Test::init_print(['20mm_cube','20mm_cube'], config => $config);
|
||||
$test->($print, 'two objects');
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('gcode_flavor', 'sailfish');
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config, scale_xyz => [1,1, 1/(20/$config->layer_height) ]);
|
||||
$test->($print, 'one layer object');
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('start_gcode', 'START:[input_filename]');
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
my $gcode = Slic3r::Test::gcode($print);
|
||||
like $gcode, qr/START:20mm_cube/, '[input_filename] is also available in custom G-code';
|
||||
}
|
||||
|
||||
# The current Spiral Vase slicing code removes the holes and all but the largest contours from each slice,
|
||||
# therefore the following test is no more valid.
|
||||
#{
|
||||
# my $config = Slic3r::Config::new_from_defaults;
|
||||
# $config->set('spiral_vase', 1);
|
||||
# my $print = Slic3r::Test::init_print('cube_with_hole', config => $config);
|
||||
#
|
||||
# my $spiral = 0;
|
||||
# Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
# my ($self, $cmd, $args, $info) = @_;
|
||||
#
|
||||
# if ($cmd eq 'G1' && exists $args->{E} && exists $args->{Z}) {
|
||||
# $spiral = 1;
|
||||
# }
|
||||
# });
|
||||
#
|
||||
# ok !$spiral, 'spiral vase is correctly disabled on layers with multiple loops';
|
||||
#}
|
||||
|
||||
|
||||
{
|
||||
# Tests that the Repetier flavor produces M201 Xnnn Ynnn for resetting
|
||||
# acceleration, also that M204 Snnn syntax is not generated.
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('gcode_flavor', 'repetier');
|
||||
$config->set('default_acceleration', 1337);
|
||||
my $print = Slic3r::Test::init_print('cube_with_hole', config => $config);
|
||||
|
||||
my $has_accel = 0;
|
||||
my $has_m204 = 0;
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($cmd eq 'M201' && exists $args->{X} && exists $args->{Y}) {
|
||||
if ($args->{X} == 1337 && $args->{Y} == 1337) {
|
||||
$has_accel = 1;
|
||||
}
|
||||
}
|
||||
if ($cmd eq 'M204' && exists $args->{S}) {
|
||||
$has_m204 = 1;
|
||||
}
|
||||
});
|
||||
ok $has_accel, 'M201 is generated for repetier firmware.';
|
||||
ok !$has_m204, 'M204 is not generated for repetier firmware';
|
||||
}
|
||||
|
||||
__END__
|
||||
95
t/geometry.t
Normal file
95
t/geometry.t
Normal file
@@ -0,0 +1,95 @@
|
||||
use Test::More;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
plan tests => 10;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
use Slic3r;
|
||||
use Slic3r::Geometry qw(PI
|
||||
chained_path_from epsilon scale);
|
||||
|
||||
{
|
||||
# this test was failing on Windows (GH #1950)
|
||||
my $polygon = Slic3r::Polygon->new(
|
||||
[207802834,-57084522],[196528149,-37556190],[173626821,-25420928],[171285751,-21366123],
|
||||
[118673592,-21366123],[116332562,-25420928],[93431208,-37556191],[82156517,-57084523],
|
||||
[129714478,-84542120],[160244873,-84542120],
|
||||
);
|
||||
my $point = Slic3r::Point->new(95706562, -57294774);
|
||||
ok $polygon->contains_point($point), 'contains_point';
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
|
||||
my $polygons = [
|
||||
Slic3r::Polygon->new( # contour, ccw
|
||||
[45919000, 515273900], [14726100, 461246400], [14726100, 348753500], [33988700, 315389800],
|
||||
[43749700, 343843000], [45422300, 352251500], [52362100, 362637800], [62748400, 369577600],
|
||||
[75000000, 372014700], [87251500, 369577600], [97637800, 362637800], [104577600, 352251500],
|
||||
[107014700, 340000000], [104577600, 327748400], [97637800, 317362100], [87251500, 310422300],
|
||||
[82789200, 309534700], [69846100, 294726100], [254081000, 294726100], [285273900, 348753500],
|
||||
[285273900, 461246400], [254081000, 515273900],
|
||||
|
||||
),
|
||||
Slic3r::Polygon->new( # hole, cw
|
||||
[75000000, 502014700], [87251500, 499577600], [97637800, 492637800], [104577600, 482251500],
|
||||
[107014700, 470000000], [104577600, 457748400], [97637800, 447362100], [87251500, 440422300],
|
||||
[75000000, 437985300], [62748400, 440422300], [52362100, 447362100], [45422300, 457748400],
|
||||
[42985300, 470000000], [45422300, 482251500], [52362100, 492637800], [62748400, 499577600],
|
||||
),
|
||||
];
|
||||
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
my $polygon = Slic3r::Polygon->new([0, 0], [10, 0], [5, 5]);
|
||||
my $result = $polygon->split_at_index(1);
|
||||
is ref($result), 'Slic3r::Polyline', 'split_at_index returns polyline';
|
||||
is_deeply $result->pp, [ [10, 0], [5, 5], [0, 0], [10, 0] ], 'split_at_index';
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
|
||||
#{
|
||||
# my $bb = Slic3r::Geometry::BoundingBox->new_from_points([ map Slic3r::Point->new(@$_), [0, 1], [10, 2], [20, 2] ]);
|
||||
# $bb->scale(2);
|
||||
# is_deeply [ $bb->min_point->pp, $bb->max_point->pp ], [ [0,2], [40,4] ], 'bounding box is scaled correctly';
|
||||
#}
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
# if chained_path() works correctly, these points should be joined with no diagonal paths
|
||||
# (thus 26 units long)
|
||||
my @points = map Slic3r::Point->new_scale(@$_), [26,26],[52,26],[0,26],[26,52],[26,0],[0,52],[52,52],[52,0];
|
||||
my @ordered = @points[@{chained_path_from(\@points, $points[0])}];
|
||||
ok !(grep { abs($ordered[$_]->distance_to($ordered[$_+1]) - scale 26) > epsilon } 0..$#ordered-1), 'chained_path';
|
||||
}
|
||||
|
||||
#==========================================================
|
||||
|
||||
{
|
||||
my $line = Slic3r::Line->new([0, 0], [20, 0]);
|
||||
is +Slic3r::Point->new(10, 10)->distance_to_line($line), 10, 'distance_to';
|
||||
is +Slic3r::Point->new(50, 0)->distance_to_line($line), 30, 'distance_to';
|
||||
is +Slic3r::Point->new(0, 0)->distance_to_line($line), 0, 'distance_to';
|
||||
is +Slic3r::Point->new(20, 0)->distance_to_line($line), 0, 'distance_to';
|
||||
is +Slic3r::Point->new(10, 0)->distance_to_line($line), 0, 'distance_to';
|
||||
}
|
||||
|
||||
{
|
||||
my $triangle = Slic3r::Polygon->new(
|
||||
[16000170,26257364], [714223,461012], [31286371,461008],
|
||||
);
|
||||
my $simplified = $triangle->simplify(250000)->[0];
|
||||
is scalar(@$simplified), 3, 'triangle is never simplified to less than 3 points';
|
||||
}
|
||||
|
||||
__END__
|
||||
78
t/layers.t
Normal file
78
t/layers.t
Normal file
@@ -0,0 +1,78 @@
|
||||
use Test::More tests => 5;
|
||||
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::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 @z = ();
|
||||
my @increments = ();
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($info->{dist_Z}) {
|
||||
push @z, 1*$args->{Z};
|
||||
push @increments, $info->{dist_Z};
|
||||
}
|
||||
});
|
||||
|
||||
fail 'wrong first layer height'
|
||||
if $z[0] ne $config->get_value('first_layer_height') + $config->z_offset;
|
||||
|
||||
fail 'wrong second layer height'
|
||||
if $z[1] ne $config->get_value('first_layer_height') + $config->get_value('layer_height') + $config->z_offset;
|
||||
|
||||
fail 'wrong layer height'
|
||||
if first { !_eq($_, $config->layer_height) } @increments[1..$#increments];
|
||||
|
||||
1;
|
||||
};
|
||||
|
||||
$config->set('start_gcode', ''); # to avoid dealing with the nozzle lift in start G-code
|
||||
$config->set('layer_height', 0.3);
|
||||
$config->set('first_layer_height', 0.2);
|
||||
ok $test->(), "absolute first layer height";
|
||||
|
||||
$config->set('first_layer_height', 0.6 * $config->layer_height);
|
||||
ok $test->(), "relative first layer height";
|
||||
|
||||
$config->set('z_offset', 0.9);
|
||||
ok $test->(), "positive Z offset";
|
||||
|
||||
$config->set('z_offset', -0.8);
|
||||
ok $test->(), "negative Z offset";
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config->new;
|
||||
$config->set('fill_density', 0); # just for making the test faster
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config, scale => 2);
|
||||
|
||||
my @z = ();
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($info->{dist_Z}) {
|
||||
push @z, 1*$args->{Z};
|
||||
}
|
||||
});
|
||||
ok $z[-1] > 20*1.8 && $z[-1] < 20*2.2, 'resulting G-code has reasonable height';
|
||||
}
|
||||
|
||||
__END__
|
||||
260
t/retraction.t
Normal file
260
t/retraction.t
Normal file
@@ -0,0 +1,260 @@
|
||||
use Test::More tests => 26;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use local::lib "$FindBin::Bin/../local-lib";
|
||||
}
|
||||
|
||||
use List::Util qw(any);
|
||||
use Slic3r;
|
||||
use Slic3r::Test qw(_eq);
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
my $duplicate = 1;
|
||||
|
||||
my $test = sub {
|
||||
my ($conf) = @_;
|
||||
$conf ||= $config;
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $conf, duplicate => $duplicate);
|
||||
|
||||
my $tool = 0;
|
||||
my @toolchange_count = (); # track first usages so that we don't expect retract_length_toolchange when extruders are used for the first time
|
||||
my @retracted = (1); # ignore the first travel move from home to first point
|
||||
my @retracted_length = (0);
|
||||
my $lifted = 0;
|
||||
my $lift_dist = 0; # track lifted distance for toolchanges and extruders with different retract_lift values
|
||||
my $changed_tool = 0;
|
||||
my $wait_for_toolchange = 0;
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($cmd =~ /^T(\d+)/) {
|
||||
$tool = $1;
|
||||
$changed_tool = 1;
|
||||
$wait_for_toolchange = 0;
|
||||
$toolchange_count[$tool] //= 0;
|
||||
$toolchange_count[$tool]++;
|
||||
} elsif ($cmd =~ /^G[01]$/ && !$args->{Z}) { # ignore lift taking place after retraction
|
||||
fail 'toolchange happens right after retraction' if $wait_for_toolchange;
|
||||
}
|
||||
|
||||
if ($info->{dist_Z}) {
|
||||
# lift move or lift + change layer
|
||||
if (_eq($info->{dist_Z}, $print->print->config->get_at('retract_lift', $tool))
|
||||
|| (_eq($info->{dist_Z}, $conf->layer_height + $print->print->config->get_at('retract_lift', $tool)) && $print->print->config->get_at('retract_lift', $tool) > 0)) {
|
||||
fail 'only lifting while retracted' if !$retracted[$tool];
|
||||
fail 'double lift' if $lifted;
|
||||
$lifted = 1;
|
||||
$lift_dist = $info->{dist_Z};
|
||||
}
|
||||
if ($info->{dist_Z} < 0) {
|
||||
fail 'going down only after lifting' if !$lifted;
|
||||
fail 'going down by the same amount of the lift or by the amount needed to get to next layer'
|
||||
if !_eq($info->{dist_Z}, -$lift_dist)
|
||||
&& !_eq($info->{dist_Z}, -lift_dist + $conf->layer_height);
|
||||
$lift_dist = 0;
|
||||
$lifted = 0;
|
||||
}
|
||||
fail 'move Z at travel speed' if ($args->{F} // $self->F) != $conf->travel_speed * 60;
|
||||
}
|
||||
if ($info->{retracting}) {
|
||||
$retracted[$tool] = 1;
|
||||
$retracted_length[$tool] += -$info->{dist_E};
|
||||
if (_eq($retracted_length[$tool], $print->print->config->get_at('retract_length', $tool))) {
|
||||
# okay
|
||||
} elsif (_eq($retracted_length[$tool], $print->print->config->get_at('retract_length_toolchange', $tool))) {
|
||||
$wait_for_toolchange = 1;
|
||||
} else {
|
||||
fail 'retracted by the correct amount';
|
||||
}
|
||||
}
|
||||
if ($info->{extruding}) {
|
||||
fail 'only extruding while not lifted' if $lifted;
|
||||
if ($retracted[$tool]) {
|
||||
my $expected_amount = $retracted_length[$tool] + $print->print->config->get_at('retract_restart_extra', $tool);
|
||||
if ($changed_tool && $toolchange_count[$tool] > 1) {
|
||||
$expected_amount = $print->print->config->get_at('retract_length_toolchange', $tool) + $print->print->config->get_at('retract_restart_extra_toolchange', $tool);
|
||||
$changed_tool = 0;
|
||||
}
|
||||
fail 'unretracted by the correct amount' && exit
|
||||
if !_eq($info->{dist_E}, $expected_amount);
|
||||
$retracted[$tool] = 0;
|
||||
$retracted_length[$tool] = 0;
|
||||
}
|
||||
}
|
||||
if ($info->{travel} && $info->{dist_XY} >= $print->print->config->get_at('retract_before_travel', $tool)) {
|
||||
fail 'retracted before long travel move' if !$retracted[$tool];
|
||||
}
|
||||
});
|
||||
|
||||
1;
|
||||
};
|
||||
|
||||
$config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]);
|
||||
$config->set('first_layer_height', $config->layer_height);
|
||||
$config->set('first_layer_speed', '100%');
|
||||
$config->set('start_gcode', ''); # to avoid dealing with the nozzle lift in start G-code
|
||||
$config->set('retract_length', [1.5]);
|
||||
$config->set('retract_before_travel', [3]);
|
||||
$config->set('only_retract_when_crossing_perimeters', 0);
|
||||
|
||||
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_restart_extra', [-1]);
|
||||
ok $test->($conf), "negative restart extra length$descr";
|
||||
|
||||
$conf->set('retract_lift', [1, 2]);
|
||||
ok $test->($conf), "lift$descr";
|
||||
};
|
||||
|
||||
$retract_tests->('');
|
||||
|
||||
$duplicate = 2;
|
||||
$retract_tests->(' (duplicate)');
|
||||
|
||||
$duplicate = 1;
|
||||
$config->set('infill_extruder', 2);
|
||||
$config->set('skirts', 4);
|
||||
$config->set('skirt_height', 3);
|
||||
$retract_tests->(' (dual extruder with multiple skirt layers)');
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('start_gcode', ''); # prevent any default priming Z move from affecting our lift detection
|
||||
$config->set('retract_length', [0]);
|
||||
$config->set('retract_layer_change', [0]);
|
||||
$config->set('retract_lift', [0.2]);
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
my $retracted = 0;
|
||||
my $layer_changes_with_retraction = 0;
|
||||
my $retractions = my $z_restores = 0;
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($info->{retracting}) {
|
||||
$retracted = 1;
|
||||
$retractions++;
|
||||
} elsif ($info->{extruding} && $retracted) {
|
||||
$retracted = 0;
|
||||
}
|
||||
|
||||
if ($info->{dist_Z} && $retracted) {
|
||||
$layer_changes_with_retraction++;
|
||||
}
|
||||
if ($info->{dist_Z} && $args->{Z} < $self->Z) {
|
||||
$z_restores++;
|
||||
}
|
||||
});
|
||||
|
||||
is $layer_changes_with_retraction, 0, 'no retraction on layer change';
|
||||
is $retractions, 0, 'no retractions';
|
||||
is $z_restores, 0, 'no lift';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('use_firmware_retraction', 1);
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
my $retracted = 0;
|
||||
my $double_retractions = my $double_unretractions = 0;
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($cmd eq 'G10') {
|
||||
$double_retractions++ if $retracted;
|
||||
$retracted = 1;
|
||||
} elsif ($cmd eq 'G11') {
|
||||
$double_unretractions++ if !$retracted;
|
||||
$retracted = 0;
|
||||
}
|
||||
});
|
||||
|
||||
is $double_retractions, 0, 'no double retractions';
|
||||
is $double_unretractions, 0, 'no double unretractions';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('use_firmware_retraction', 1);
|
||||
$config->set('retract_length', [0]);
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
my $retracted = 0;
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($cmd eq 'G10') {
|
||||
$retracted = 1;
|
||||
}
|
||||
});
|
||||
|
||||
ok $retracted, 'retracting also when --retract-length is 0 but --use-firmware-retraction is enabled';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]);
|
||||
$config->set('start_gcode', '');
|
||||
$config->set('retract_lift', [3, 4]);
|
||||
|
||||
my @lifted_at = ();
|
||||
my $test = sub {
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config, duplicate => 2);
|
||||
@lifted_at = ();
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($cmd eq 'G1' && $info->{dist_Z} < 0) {
|
||||
push @lifted_at, $info->{new_Z};
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$config->set('retract_lift_above', [0, 0]);
|
||||
$config->set('retract_lift_below', [0, 0]);
|
||||
$test->();
|
||||
ok !!@lifted_at, 'lift takes place when above/below == 0';
|
||||
|
||||
$config->set('retract_lift_above', [5, 6]);
|
||||
$config->set('retract_lift_below', [15, 13]);
|
||||
$test->();
|
||||
ok !!@lifted_at, 'lift takes place when above/below != 0';
|
||||
ok !(any { $_ < $config->get_at('retract_lift_above', 0) } @lifted_at),
|
||||
'Z is not lifted below the configured value';
|
||||
ok !(any { $_ > $config->get_at('retract_lift_below', 0) } @lifted_at),
|
||||
'Z is not lifted above the configured value';
|
||||
|
||||
# check lifting with different values for 2. extruder
|
||||
$config->set('perimeter_extruder', 2);
|
||||
$config->set('infill_extruder', 2);
|
||||
$config->set('retract_lift_above', [0, 0]);
|
||||
$config->set('retract_lift_below', [0, 0]);
|
||||
$test->();
|
||||
ok !!@lifted_at, 'lift takes place when above/below == 0 for 2. extruder';
|
||||
|
||||
$config->set('retract_lift_above', [5, 6]);
|
||||
$config->set('retract_lift_below', [15, 13]);
|
||||
$test->();
|
||||
ok !!@lifted_at, 'lift takes place when above/below != 0 for 2. extruder';
|
||||
ok !(any { $_ < $config->get_at('retract_lift_above', 1) } @lifted_at),
|
||||
'Z is not lifted below the configured value for 2. extruder';
|
||||
ok !(any { $_ > $config->get_at('retract_lift_below', 1) } @lifted_at),
|
||||
'Z is not lifted above the configured value for 2. extruder';
|
||||
}
|
||||
|
||||
__END__
|
||||
146
t/skirt_brim.t
Normal file
146
t/skirt_brim.t
Normal file
@@ -0,0 +1,146 @@
|
||||
use Test::More tests => 6;
|
||||
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(unscale convex_hull);
|
||||
use Slic3r::Test;
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('skirts', 1);
|
||||
$config->set('skirt_height', 2);
|
||||
$config->set('perimeters', 0);
|
||||
$config->set('support_material_speed', 99);
|
||||
$config->set('cooling', [ 0 ]); # to prevent speeds to be altered
|
||||
$config->set('first_layer_speed', '100%'); # to prevent speeds to be altered
|
||||
|
||||
my $test = sub {
|
||||
my ($conf) = @_;
|
||||
$conf ||= $config;
|
||||
|
||||
my $print = Slic3r::Test::init_print(['20mm_cube','20mm_cube'], config => $config);
|
||||
|
||||
my %layers_with_skirt = (); # Z => $count
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if (defined $self->Z) {
|
||||
$layers_with_skirt{$self->Z} //= 0;
|
||||
$layers_with_skirt{$self->Z} = 1
|
||||
if $info->{extruding} && ($args->{F} // $self->F) == $config->support_material_speed*60;
|
||||
}
|
||||
});
|
||||
fail "wrong number of layers with skirt"
|
||||
unless (grep $_, values %layers_with_skirt) == $config->skirt_height;
|
||||
};
|
||||
|
||||
ok $test->(), "skirt_height is honored when printing multiple objects too";
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('skirts', 0);
|
||||
$config->set('perimeters', 0);
|
||||
$config->set('top_solid_layers', 0); # to prevent solid shells and their speeds
|
||||
$config->set('bottom_solid_layers', 0); # to prevent solid shells and their speeds
|
||||
$config->set('brim_width', 5);
|
||||
$config->set('support_material_speed', 99);
|
||||
$config->set('cooling', [ 0 ]); # to prevent speeds to be altered
|
||||
$config->set('first_layer_speed', '100%'); # to prevent speeds to be altered
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
|
||||
my %layers_with_brim = (); # Z => $count
|
||||
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
||||
my ($self, $cmd, $args, $info) = @_;
|
||||
|
||||
if (defined $self->Z) {
|
||||
$layers_with_brim{$self->Z} //= 0;
|
||||
$layers_with_brim{$self->Z} = 1
|
||||
if $info->{extruding} && $info->{dist_XY} > 0 && ($args->{F} // $self->F) != $config->infill_speed*60;
|
||||
}
|
||||
});
|
||||
is scalar(grep $_, values %layers_with_brim), 1, "brim is generated";
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('skirts', 1);
|
||||
$config->set('brim_width', 10);
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
ok Slic3r::Test::gcode($print), 'successful G-code generation when skirt is smaller than brim width';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('skirts', 1);
|
||||
$config->set('skirt_height', 0);
|
||||
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
ok Slic3r::Test::gcode($print), 'successful G-code generation when skirt_height = 0 and skirts > 0';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
# Define 4 extruders.
|
||||
$config->set('nozzle_diameter', [0.4, 0.4, 0.4, 0.4]);
|
||||
$config->set('layer_height', 0.4);
|
||||
$config->set('first_layer_height', 0.4);
|
||||
$config->set('skirts', 1);
|
||||
$config->set('skirt_distance', 0);
|
||||
$config->set('support_material_speed', 99);
|
||||
$config->set('perimeter_extruder', 1);
|
||||
$config->set('support_material_extruder', 2);
|
||||
$config->set('cooling', [ 0 ]); # to prevent speeds to be altered
|
||||
$config->set('first_layer_speed', '100%'); # to prevent speeds to be altered
|
||||
|
||||
my $print = Slic3r::Test::init_print('overhang', config => $config);
|
||||
$print->process;
|
||||
|
||||
# we enable support material after skirt has been generated
|
||||
$config->set('support_material', 1);
|
||||
$print->apply($print->print->model->clone, $config);
|
||||
|
||||
my $skirt_length = 0;
|
||||
my @extrusion_points = ();
|
||||
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 (defined $self->Z && $self->Z == $config->first_layer_height) {
|
||||
# we're on first layer
|
||||
if ($info->{extruding} && $info->{dist_XY} > 0) {
|
||||
my $speed = ($args->{F} // $self->F) / 60;
|
||||
if ($speed == $config->support_material_speed && $tool == $config->perimeter_extruder-1) {
|
||||
# skirt uses support material speed but first object's extruder
|
||||
$skirt_length += $info->{dist_XY};
|
||||
} else {
|
||||
push @extrusion_points, my $point = Slic3r::Point->new_scale($args->{X}, $args->{Y});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
my $convex_hull = convex_hull(\@extrusion_points);
|
||||
my $hull_perimeter = unscale($convex_hull->split_at_first_point->length);
|
||||
ok $skirt_length > $hull_perimeter, 'skirt lenght is large enough to contain object with support';
|
||||
}
|
||||
|
||||
{
|
||||
my $config = Slic3r::Config::new_from_defaults;
|
||||
$config->set('min_skirt_length', 20);
|
||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||
ok Slic3r::Test::gcode($print), 'no crash when using min_skirt_length';
|
||||
}
|
||||
|
||||
__END__
|
||||
Reference in New Issue
Block a user