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

« back to all changes in this revision

Viewing changes to lib/Slic3r/Print/Simple.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::Print::Simple;
 
2
use Moo;
 
3
 
 
4
use Slic3r::Geometry qw(X Y);
 
5
 
 
6
has '_print' => (
 
7
    is      => 'ro',
 
8
    default => sub { Slic3r::Print->new },
 
9
    handles => [qw(apply_config extruders expanded_output_filepath
 
10
                    total_used_filament total_extruded_volume
 
11
                    placeholder_parser)],
 
12
);
 
13
 
 
14
has 'duplicate' => (
 
15
    is      => 'rw',
 
16
    default => sub { 1 },
 
17
);
 
18
 
 
19
has 'scale' => (
 
20
    is      => 'rw',
 
21
    default => sub { 1 },
 
22
);
 
23
 
 
24
has 'rotate' => (
 
25
    is      => 'rw',
 
26
    default => sub { 0 },
 
27
);
 
28
 
 
29
has 'duplicate_grid' => (
 
30
    is      => 'rw',
 
31
    default => sub { [1,1] },
 
32
);
 
33
 
 
34
has 'status_cb' => (
 
35
    is      => 'rw',
 
36
    default => sub { sub {} },
 
37
);
 
38
 
 
39
has 'output_file' => (
 
40
    is      => 'rw',
 
41
);
 
42
 
 
43
sub set_model {
 
44
    my ($self, $model) = @_;
 
45
    
 
46
    # make method idempotent so that the object is reusable
 
47
    $self->_print->clear_objects;
 
48
    
 
49
    # make sure all objects have at least one defined instance
 
50
    my $need_arrange = $model->add_default_instances;
 
51
    
 
52
    # apply scaling and rotation supplied from command line if any
 
53
    foreach my $instance (map @{$_->instances}, @{$model->objects}) {
 
54
        $instance->set_scaling_factor($instance->scaling_factor * $self->scale);
 
55
        $instance->set_rotation($instance->rotation + $self->rotate);
 
56
    }
 
57
    
 
58
    if ($self->duplicate_grid->[X] > 1 || $self->duplicate_grid->[Y] > 1) {
 
59
        $model->duplicate_objects_grid($self->duplicate_grid, $self->_print->config->duplicate_distance);
 
60
    } elsif ($need_arrange) {
 
61
        $model->duplicate_objects($self->duplicate, $self->_print->config->min_object_distance);
 
62
    } elsif ($self->duplicate > 1) {
 
63
        # if all input objects have defined position(s) apply duplication to the whole model
 
64
        $model->duplicate($self->duplicate, $self->_print->config->min_object_distance);
 
65
    }
 
66
    $model->center_instances_around_point($self->_print->config->print_center);
 
67
    
 
68
    foreach my $model_object (@{$model->objects}) {
 
69
        $self->_print->auto_assign_extruders($model_object);
 
70
        $self->_print->add_model_object($model_object);
 
71
    }
 
72
}
 
73
 
 
74
sub _before_export {
 
75
    my ($self) = @_;
 
76
    
 
77
    $self->_print->status_cb($self->status_cb);
 
78
    $self->_print->validate;
 
79
}
 
80
 
 
81
sub _after_export {
 
82
    my ($self) = @_;
 
83
    
 
84
    $self->_print->status_cb(undef);
 
85
}
 
86
 
 
87
sub export_gcode {
 
88
    my ($self) = @_;
 
89
    
 
90
    $self->_before_export;
 
91
    
 
92
    $self->_print->process;
 
93
    $self->_print->export_gcode(output_file => $self->output_file);
 
94
    
 
95
    $self->_after_export;
 
96
}
 
97
 
 
98
sub export_svg {
 
99
    my ($self) = @_;
 
100
    
 
101
    $self->_before_export;
 
102
    
 
103
    $self->_print->export_svg(output_file => $self->output_file);
 
104
    
 
105
    $self->_after_export;
 
106
}
 
107
 
 
108
1;