1
use Test::More tests => 13;
7
use lib "$FindBin::Bin/../lib";
14
my $config = Slic3r::Config->new_from_defaults;
20
my $print = Slic3r::Test::init_print('2x20x10', config => $conf);
22
my $last_move_was_z_change = 0;
23
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
24
my ($self, $cmd, $args, $info) = @_;
26
if ($last_move_was_z_change && $cmd ne $config->layer_gcode) {
27
fail 'custom layer G-code was not applied after Z change';
29
if (!$last_move_was_z_change && $cmd eq $config->layer_gcode) {
30
fail 'custom layer G-code was not applied after Z change';
33
$last_move_was_z_change = (defined $info->{dist_Z} && $info->{dist_Z} > 0);
39
$config->set('start_gcode', '_MY_CUSTOM_START_GCODE_'); # to avoid dealing with the nozzle lift in start G-code
40
$config->set('layer_gcode', '_MY_CUSTOM_LAYER_GCODE_');
41
ok $test->(), "custom layer G-code is applied after Z move and before other moves";
44
#==========================================================
47
my $parser = Slic3r::GCode::PlaceholderParser->new;
48
$parser->apply_config(my $config = Slic3r::Config->new_from_defaults);
49
is $parser->process('[temperature_[foo]]', { foo => '1' }),
50
$config->temperature->[0],
51
"nested config options";
55
my $config = Slic3r::Config->new_from_defaults;
56
$config->set('output_filename_format', '[travel_speed]_[layer_height].gcode');
57
$config->set('start_gcode', "TRAVEL:[travel_speed] HEIGHT:[layer_height]\n");
58
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
60
my $output_file = $print->print->expanded_output_filepath;
61
ok $output_file !~ /\[travel_speed\]/, 'print config options are replaced in output filename';
62
ok $output_file !~ /\[layer_height\]/, 'region config options are replaced in output filename';
64
my $gcode = Slic3r::Test::gcode($print);
65
my ($t, $h) = map $config->$_, qw(travel_speed layer_height);
66
ok $gcode =~ /TRAVEL:$t/, 'print config options are replaced in custom G-code';
67
ok $gcode =~ /HEIGHT:$h/, 'region config options are replaced in custom G-code';
71
my $config = Slic3r::Config->new;
72
$config->set('extruder', 2);
73
$config->set('first_layer_temperature', [200,205]);
76
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
77
my $gcode = Slic3r::Test::gcode($print);
78
ok $gcode =~ /M104 S205 T1/, 'temperature set correctly for non-zero yet single extruder';
79
ok $gcode !~ /M104 S\d+ T0/, 'unused extruder correctly ignored';
82
$config->set('infill_extruder', 1);
84
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
85
my $gcode = Slic3r::Test::gcode($print);
86
ok $gcode =~ /M104 S200 T0/, 'temperature set correctly for first extruder';
87
ok $gcode =~ /M104 S205 T1/, 'temperature set correctly for second extruder';
90
$config->set('start_gcode', qq!
91
;__temp0:[first_layer_temperature_0]__
92
;__temp1:[first_layer_temperature_1]__
93
;__temp2:[first_layer_temperature_2]__
96
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
97
my $gcode = Slic3r::Test::gcode($print);
98
# we use the [infill_extruder] placeholder to make sure this test doesn't
99
# catch a false positive caused by the unparsed start G-code option itself
100
# being embedded in the G-code
101
ok $gcode =~ /temp0:200/, 'temperature placeholder for first extruder correctly populated';
102
ok $gcode =~ /temp1:205/, 'temperature placeholder for second extruder correctly populated';
103
ok $gcode =~ /temp2:200/, 'tempearture placeholder for unused extruder populated with first value';