~ubuntu-branches/ubuntu/utopic/slic3r/utopic

« back to all changes in this revision

Viewing changes to t/custom_gcode.t

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2014-06-17 01:27:26 UTC
  • Revision ID: package-import@ubuntu.com-20140617012726-2wrs4zdo251nr4vg
Tags: upstream-1.1.4+dfsg
ImportĀ upstreamĀ versionĀ 1.1.4+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
use Test::More tests => 13;
 
2
use strict;
 
3
use warnings;
 
4
 
 
5
BEGIN {
 
6
    use FindBin;
 
7
    use lib "$FindBin::Bin/../lib";
 
8
}
 
9
 
 
10
use Slic3r;
 
11
use Slic3r::Test;
 
12
 
 
13
{
 
14
    my $config = Slic3r::Config->new_from_defaults;
 
15
    
 
16
    my $test = sub {
 
17
        my ($conf) = @_;
 
18
        $conf ||= $config;
 
19
        
 
20
        my $print = Slic3r::Test::init_print('2x20x10', config => $conf);
 
21
        
 
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) = @_;
 
25
            
 
26
            if ($last_move_was_z_change && $cmd ne $config->layer_gcode) {
 
27
                fail 'custom layer G-code was not applied after Z change';
 
28
            }
 
29
            if (!$last_move_was_z_change && $cmd eq $config->layer_gcode) {
 
30
                fail 'custom layer G-code was not applied after Z change';
 
31
            }
 
32
            
 
33
            $last_move_was_z_change = (defined $info->{dist_Z} && $info->{dist_Z} > 0);
 
34
        });
 
35
        
 
36
        1;
 
37
    };
 
38
    
 
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";
 
42
}
 
43
 
 
44
#==========================================================
 
45
 
 
46
{
 
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";
 
52
}
 
53
 
 
54
{
 
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);
 
59
    
 
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';
 
63
    
 
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';
 
68
}
 
69
 
 
70
{
 
71
    my $config = Slic3r::Config->new;
 
72
    $config->set('extruder', 2);
 
73
    $config->set('first_layer_temperature', [200,205]);
 
74
    
 
75
    {
 
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';
 
80
    }
 
81
    
 
82
    $config->set('infill_extruder', 1);
 
83
    {
 
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';
 
88
    }
 
89
    
 
90
    $config->set('start_gcode', qq!
 
91
;__temp0:[first_layer_temperature_0]__
 
92
;__temp1:[first_layer_temperature_1]__
 
93
;__temp2:[first_layer_temperature_2]__
 
94
    !);
 
95
    {
 
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';
 
104
    }
 
105
}
 
106
 
 
107
__END__