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

« back to all changes in this revision

Viewing changes to t/support.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 => 16;
 
2
use strict;
 
3
use warnings;
 
4
 
 
5
BEGIN {
 
6
    use FindBin;
 
7
    use lib "$FindBin::Bin/../lib";
 
8
}
 
9
 
 
10
use List::Util qw(first);
 
11
use Slic3r;
 
12
use Slic3r::Geometry qw(epsilon scale);
 
13
use Slic3r::Geometry::Clipper qw(diff);
 
14
use Slic3r::Test;
 
15
 
 
16
{
 
17
    my $config = Slic3r::Config->new_from_defaults;
 
18
    $config->set('support_material', 1);
 
19
    my @contact_z = my @top_z = ();
 
20
    
 
21
    my $test = sub {
 
22
        my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
 
23
        $print->print->init_extruders;
 
24
        my $flow = $print->print->objects->[0]->support_material_flow;
 
25
        my $support_z = Slic3r::Print::SupportMaterial
 
26
            ->new(
 
27
                object_config       => $print->print->objects->[0]->config,
 
28
                print_config        => $print->print->config,
 
29
                flow                => $flow,
 
30
                interface_flow      => $flow,
 
31
                first_layer_flow    => $flow,
 
32
            )
 
33
            ->support_layers_z(\@contact_z, \@top_z, $config->layer_height);
 
34
        
 
35
        is $support_z->[0], $config->first_layer_height,
 
36
            'first layer height is honored';
 
37
        is scalar(grep { $support_z->[$_]-$support_z->[$_-1] <= 0 } 1..$#$support_z), 0,
 
38
            'no null or negative support layers';
 
39
        is scalar(grep { $support_z->[$_]-$support_z->[$_-1] > $config->nozzle_diameter->[0] + epsilon } 1..$#$support_z), 0,
 
40
            'no layers thicker than nozzle diameter';
 
41
        
 
42
        my $wrong_top_spacing = 0;
 
43
        foreach my $top_z (@top_z) {
 
44
            # find layer index of this top surface
 
45
            my $layer_id = first { abs($support_z->[$_] - $top_z) < epsilon } 0..$#$support_z;
 
46
            
 
47
            # check that first support layer above this top surface is spaced with nozzle diameter
 
48
            $wrong_top_spacing = 1
 
49
                if ($support_z->[$layer_id+1] - $support_z->[$layer_id]) != $config->nozzle_diameter->[0];
 
50
        }
 
51
        ok !$wrong_top_spacing, 'layers above top surfaces are spaced correctly';
 
52
    };
 
53
    
 
54
    $config->set('layer_height', 0.2);
 
55
    $config->set('first_layer_height', 0.3);
 
56
    @contact_z = (1.9);
 
57
    @top_z = (1.1);
 
58
    $test->();
 
59
    
 
60
    $config->set('first_layer_height', 0.4);
 
61
    $test->();
 
62
    
 
63
    $config->set('layer_height', $config->nozzle_diameter->[0]);
 
64
    $test->();
 
65
}
 
66
 
 
67
{
 
68
    my $config = Slic3r::Config->new_from_defaults;
 
69
    $config->set('raft_layers', 3);
 
70
    $config->set('brim_width',  6);
 
71
    $config->set('skirts', 0);
 
72
    $config->set('support_material_extruder', 2);
 
73
    $config->set('support_material_interface_extruder', 2);
 
74
    $config->set('layer_height', 0.4);
 
75
    $config->set('first_layer_height', '100%');
 
76
    my $print = Slic3r::Test::init_print('overhang', config => $config);
 
77
    ok my $gcode = Slic3r::Test::gcode($print), 'no conflict between raft/support and brim';
 
78
    
 
79
    my $tool = 0;
 
80
    Slic3r::GCode::Reader->new->parse($gcode, sub {
 
81
        my ($self, $cmd, $args, $info) = @_;
 
82
        
 
83
        if ($cmd =~ /^T(\d+)/) {
 
84
            $tool = $1;
 
85
        } elsif ($info->{extruding}) {
 
86
            if ($self->Z <= ($config->raft_layers * $config->layer_height)) {
 
87
                fail 'not extruding raft/brim with support material extruder'
 
88
                    if $tool != ($config->support_material_extruder-1);
 
89
            } else {
 
90
                fail 'support material exceeds raft layers'
 
91
                    if $tool == $config->support_material_extruder-1;
 
92
                # TODO: we should test that full support is generated when we use raft too
 
93
            }
 
94
        }
 
95
    });
 
96
}
 
97
 
 
98
{
 
99
    my $config = Slic3r::Config->new_from_defaults;
 
100
    $config->set('skirts', 0);
 
101
    $config->set('raft_layers', 3);
 
102
    $config->set('support_material_pattern', 'honeycomb');
 
103
    $config->set('support_material_extrusion_width', 0.6);
 
104
    $config->set('first_layer_extrusion_width', '100%');
 
105
    my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
 
106
    
 
107
    my $layer_id = 0;
 
108
    my @raft = my @first_object_layer = ();
 
109
    Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
 
110
        my ($self, $cmd, $args, $info) = @_;
 
111
        
 
112
        if ($info->{extruding} && $info->{dist_XY} > 0) {
 
113
            if ($layer_id <= $config->raft_layers) {
 
114
                # this is a raft layer or the first object layer
 
115
                my $line = Slic3r::Line->new_scale([ $self->X, $self->Y ], [ $info->{new_X}, $info->{new_Y} ]);
 
116
                my @path = @{$line->grow(scale($config->support_material_extrusion_width/2))};
 
117
                if ($layer_id < $config->raft_layers) {
 
118
                    # this is a raft layer
 
119
                    push @raft, @path;
 
120
                } else {
 
121
                    push @first_object_layer, @path;
 
122
                }
 
123
            }
 
124
        } elsif ($cmd eq 'G1' && $info->{dist_Z} > 0) {
 
125
            $layer_id++;
 
126
        }
 
127
    });
 
128
    
 
129
    ok !@{diff(\@first_object_layer, \@raft)},
 
130
        'first object layer is completely supported by raft';
 
131
}
 
132
 
 
133
foreach my $raft_layers (2, 70) {
 
134
    my $config = Slic3r::Config->new_from_defaults;
 
135
    $config->set('skirts', 0);
 
136
    $config->set('raft_layers', $raft_layers);
 
137
    $config->set('layer_height', 0.35);
 
138
    $config->set('first_layer_height', 0.3);
 
139
    $config->set('nozzle_diameter', [0.5]);
 
140
    $config->set('support_material_extruder', 2);
 
141
    $config->set('support_material_interface_extruder', 2);
 
142
    my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
 
143
    my %raft_z = ();  # z => 1
 
144
    my $tool = undef;
 
145
    Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
 
146
        my ($self, $cmd, $args, $info) = @_;
 
147
        
 
148
        if ($cmd =~ /^T(\d+)/) {
 
149
            $tool = $1;
 
150
        } elsif ($info->{extruding} && $info->{dist_XY} > 0) {
 
151
            if ($tool == $config->support_material_extruder-1) {
 
152
                $raft_z{$self->Z} = 1;
 
153
            }
 
154
        }
 
155
    });
 
156
    
 
157
    is scalar(keys %raft_z), $config->raft_layers, 'correct number of raft layers is generated';
 
158
}
 
159
 
 
160
__END__