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

« back to all changes in this revision

Viewing changes to lib/Slic3r/Layer.pm

  • 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
package Slic3r::Layer;
 
2
use Moo;
 
3
 
 
4
use List::Util qw(first);
 
5
use Slic3r::Geometry qw(scale chained_path);
 
6
use Slic3r::Geometry::Clipper qw(union_ex);
 
7
 
 
8
has 'id'                => (is => 'rw', required => 1); # sequential number of layer, 0-based
 
9
has 'object'            => (is => 'ro', weak_ref => 1, required => 1, handles => [qw(print config)]);
 
10
has 'upper_layer'       => (is => 'rw', weak_ref => 1);
 
11
has 'lower_layer'       => (is => 'rw', weak_ref => 1);
 
12
has 'regions'           => (is => 'ro', default => sub { [] });
 
13
has 'slicing_errors'    => (is => 'rw');
 
14
 
 
15
has 'slice_z'           => (is => 'ro', required => 1); # Z used for slicing in unscaled coordinates
 
16
has 'print_z'           => (is => 'ro', required => 1); # Z used for printing in unscaled coordinates
 
17
has 'height'            => (is => 'ro', required => 1); # layer height in unscaled coordinates
 
18
 
 
19
# collection of expolygons generated by slicing the original geometry;
 
20
# also known as 'islands' (all regions and surface types are merged here)
 
21
has 'slices'            => (is => 'rw', default => sub { Slic3r::ExPolygon::Collection->new });
 
22
 
 
23
# the purpose of this method is to be overridden for ::Support layers
 
24
sub islands {
 
25
    my $self = shift;
 
26
    return $self->slices;
 
27
}
 
28
 
 
29
sub region {
 
30
    my $self = shift;
 
31
    my ($region_id) = @_;
 
32
    
 
33
    for (my $i = @{$self->regions}; $i <= $region_id; $i++) {
 
34
        $self->regions->[$i] //= Slic3r::Layer::Region->new(
 
35
            layer   => $self,
 
36
            region  => $self->object->print->regions->[$i],
 
37
        );
 
38
    }
 
39
    
 
40
    return $self->regions->[$region_id];
 
41
}
 
42
 
 
43
# merge all regions' slices to get islands
 
44
sub make_slices {
 
45
    my $self = shift;
 
46
    
 
47
    my $slices = union_ex([ map $_->p, map @{$_->slices}, @{$self->regions} ]);
 
48
    
 
49
    # sort slices
 
50
    $slices = [ @$slices[@{chained_path([ map $_->contour->first_point, @$slices ])}] ];
 
51
    
 
52
    $self->slices->clear;
 
53
    $self->slices->append(@$slices);
 
54
}
 
55
 
 
56
sub make_perimeters {
 
57
    my $self = shift;
 
58
    Slic3r::debugf "Making perimeters for layer %d\n", $self->id;
 
59
    $_->make_perimeters for @{$self->regions};
 
60
}
 
61
 
 
62
package Slic3r::Layer::Support;
 
63
use Moo;
 
64
extends 'Slic3r::Layer';
 
65
 
 
66
# ordered collection of extrusion paths to fill surfaces for support material
 
67
has 'support_islands'           => (is => 'rw', default => sub { Slic3r::ExPolygon::Collection->new });
 
68
has 'support_fills'             => (is => 'rw', default => sub { Slic3r::ExtrusionPath::Collection->new });
 
69
has 'support_interface_fills'   => (is => 'rw', default => sub { Slic3r::ExtrusionPath::Collection->new });
 
70
 
 
71
sub islands {
 
72
    my $self = shift;
 
73
    return [ @{$self->slices}, @{$self->support_islands} ];
 
74
}
 
75
 
 
76
1;