2015-04-12 18:16:27 +00:00
|
|
|
use Test::More tests => 23;
|
2013-01-27 12:06:45 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
use FindBin;
|
|
|
|
use lib "$FindBin::Bin/../lib";
|
|
|
|
}
|
|
|
|
|
2013-10-13 15:04:47 +00:00
|
|
|
use List::Util qw(first);
|
2013-01-27 12:06:45 +00:00
|
|
|
use Slic3r;
|
2014-05-26 13:19:13 +00:00
|
|
|
use Slic3r::Geometry qw(scale convex_hull);
|
2013-09-06 17:14:06 +00:00
|
|
|
use Slic3r::Test;
|
2013-01-27 12:06:45 +00:00
|
|
|
|
|
|
|
{
|
2015-07-01 19:47:17 +00:00
|
|
|
my $gcodegen = Slic3r::GCode->new();
|
|
|
|
$gcodegen->set_layer_count(1);
|
2014-10-25 08:56:21 +00:00
|
|
|
$gcodegen->set_origin(Slic3r::Pointf->new(10, 10));
|
2013-07-15 18:31:43 +00:00
|
|
|
is_deeply $gcodegen->last_pos->arrayref, [scale -10, scale -10], 'last_pos is shifted correctly';
|
2013-01-27 12:06:45 +00:00
|
|
|
}
|
|
|
|
|
2013-09-06 17:14:06 +00:00
|
|
|
{
|
|
|
|
my $config = Slic3r::Config->new_from_defaults;
|
|
|
|
$config->set('wipe', [1]);
|
2014-12-24 11:02:42 +00:00
|
|
|
$config->set('retract_layer_change', [0]);
|
2013-09-06 17:14:06 +00:00
|
|
|
|
|
|
|
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
|
|
|
my $have_wipe = 0;
|
2013-10-13 15:04:47 +00:00
|
|
|
my @retract_speeds = ();
|
2014-12-24 11:02:42 +00:00
|
|
|
my $extruded_on_this_layer = 0;
|
|
|
|
my $wiping_on_new_layer = 0;
|
2013-09-06 17:14:06 +00:00
|
|
|
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
|
|
|
my ($self, $cmd, $args, $info) = @_;
|
2014-12-24 11:02:42 +00:00
|
|
|
|
|
|
|
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) {
|
2013-10-13 15:04:47 +00:00
|
|
|
$have_wipe = 1;
|
2014-12-24 11:02:42 +00:00
|
|
|
$wiping_on_new_layer = 1 if !$extruded_on_this_layer;
|
2013-10-13 15:04:47 +00:00
|
|
|
my $move_time = $info->{dist_XY} / ($args->{F} // $self->F);
|
|
|
|
push @retract_speeds, abs($info->{dist_E}) / $move_time;
|
|
|
|
}
|
2013-09-06 17:14:06 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
ok $have_wipe, "wipe";
|
2013-10-13 15:04:47 +00:00
|
|
|
ok !defined (first { abs($_ - $config->retract_speed->[0]*60) < 5 } @retract_speeds), 'wipe moves don\'t retract faster than configured speed';
|
2014-12-24 11:02:42 +00:00
|
|
|
ok !$wiping_on_new_layer, 'no wiping after layer change';
|
2013-09-06 17:14:06 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 18:24:17 +00:00
|
|
|
{
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2013-11-02 13:44:30 +00:00
|
|
|
{
|
2013-12-07 13:52:59 +00:00
|
|
|
# This tests the following behavior:
|
|
|
|
# - complete objects does not crash
|
|
|
|
# - no hard-coded "E" are generated
|
|
|
|
# - Z moves are correctly generated for both objects
|
2014-05-26 13:19:13 +00:00
|
|
|
# - no travel moves go outside skirt
|
2015-03-02 22:56:38 +00:00
|
|
|
# - temperatures are set correctly
|
2013-11-02 13:44:30 +00:00
|
|
|
my $config = Slic3r::Config->new_from_defaults;
|
2013-12-24 00:13:02 +00:00
|
|
|
$config->set('gcode_comments', 1);
|
2013-11-02 13:44:30 +00:00
|
|
|
$config->set('complete_objects', 1);
|
2013-11-24 11:37:36 +00:00
|
|
|
$config->set('extrusion_axis', 'A');
|
2013-12-07 13:52:59 +00:00
|
|
|
$config->set('start_gcode', ''); # prevent any default extra Z move
|
|
|
|
$config->set('layer_height', 0.4);
|
|
|
|
$config->set('first_layer_height', 0.4);
|
2015-03-02 22:56:38 +00:00
|
|
|
$config->set('temperature', [200]);
|
|
|
|
$config->set('first_layer_temperature', [210]);
|
2013-12-24 00:13:02 +00:00
|
|
|
my $print = Slic3r::Test::init_print('20mm_cube', config => $config, duplicate => 2);
|
2013-11-24 11:37:36 +00:00
|
|
|
ok my $gcode = Slic3r::Test::gcode($print), "complete_objects";
|
2013-12-07 13:52:59 +00:00
|
|
|
my @z_moves = ();
|
2014-05-26 13:19:13 +00:00
|
|
|
my @travel_moves = (); # array of scaled points
|
|
|
|
my @extrusions = (); # array of scaled points
|
2015-03-02 22:56:38 +00:00
|
|
|
my @temps = ();
|
2013-11-24 11:37:36 +00:00
|
|
|
Slic3r::GCode::Reader->new->parse($gcode, sub {
|
|
|
|
my ($self, $cmd, $args, $info) = @_;
|
|
|
|
fail 'unexpected E argument' if defined $args->{E};
|
2013-12-07 13:52:59 +00:00
|
|
|
if (defined $args->{Z}) {
|
|
|
|
push @z_moves, $args->{Z};
|
|
|
|
}
|
2014-05-26 13:19:13 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2015-03-02 22:56:38 +00:00
|
|
|
} elsif ($cmd eq 'M104' || $cmd eq 'M109') {
|
|
|
|
push @temps, $args->{S} if !@temps || $args->{S} != $temps[-1];
|
2014-05-26 13:19:13 +00:00
|
|
|
}
|
2013-11-24 11:37:36 +00:00
|
|
|
});
|
2013-12-07 13:52:59 +00:00
|
|
|
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';
|
2014-05-26 13:19:13 +00:00
|
|
|
|
|
|
|
my $convex_hull = convex_hull(\@extrusions);
|
|
|
|
ok !(defined first { !$convex_hull->contains_point($_) } @travel_moves), 'all travel moves happen within skirt';
|
2015-03-02 22:56:38 +00:00
|
|
|
|
|
|
|
is_deeply \@temps, [210, 200, 210, 200, 0], 'expected temperature changes';
|
2013-11-02 13:44:30 +00:00
|
|
|
}
|
|
|
|
|
2014-01-11 13:24:40 +00:00
|
|
|
{
|
|
|
|
my $config = Slic3r::Config->new_from_defaults;
|
|
|
|
$config->set('retract_length', [1000000]);
|
|
|
|
$config->set('use_relative_e_distances', 1);
|
|
|
|
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
2014-11-06 20:13:30 +00:00
|
|
|
Slic3r::Test::gcode($print);
|
2014-05-09 12:24:35 +00:00
|
|
|
ok $print->print->total_used_filament > 0, 'final retraction is not considered in total used filament';
|
2014-01-11 13:24:40 +00:00
|
|
|
}
|
|
|
|
|
2014-01-11 16:40:09 +00:00
|
|
|
{
|
2014-06-05 14:24:47 +00:00
|
|
|
my $test = sub {
|
|
|
|
my ($print, $comment) = @_;
|
2014-01-11 16:40:09 +00:00
|
|
|
|
2014-06-05 14:24:47 +00:00
|
|
|
my @percent = ();
|
2014-11-06 20:06:09 +00:00
|
|
|
my $got_100 = 0;
|
|
|
|
my $extruding_after_100 = 0;
|
2014-06-05 14:24:47 +00:00
|
|
|
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
|
|
|
my ($self, $cmd, $args, $info) = @_;
|
|
|
|
|
|
|
|
if ($cmd eq 'M73') {
|
|
|
|
push @percent, $args->{P};
|
2014-11-06 20:06:09 +00:00
|
|
|
$got_100 = 1 if $args->{P} eq '100';
|
|
|
|
}
|
|
|
|
if ($info->{extruding} && $got_100) {
|
|
|
|
$extruding_after_100 = 1;
|
2014-06-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
# the extruder heater is turned off when M73 P100 is reached
|
|
|
|
ok !(defined first { $_ > 100 } @percent), "M73 is never given more than 100% ($comment)";
|
2014-11-06 20:06:09 +00:00
|
|
|
ok !$extruding_after_100, "no extrusions after M73 P100 ($comment)";
|
2014-06-05 14:24:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
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');
|
|
|
|
}
|
2014-11-06 20:06:09 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
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');
|
|
|
|
}
|
2014-01-11 16:40:09 +00:00
|
|
|
}
|
|
|
|
|
2015-02-15 22:41:36 +00:00
|
|
|
{
|
|
|
|
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';
|
|
|
|
}
|
|
|
|
|
2015-04-12 18:16:27 +00:00
|
|
|
{
|
|
|
|
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';
|
|
|
|
}
|
|
|
|
|
2013-01-27 12:06:45 +00:00
|
|
|
__END__
|