2016-09-13 09:24:55 +00:00
|
|
|
# A simple wrapper to quickly print a single model without a GUI.
|
|
|
|
# Used by the command line slic3r.pl, by command line utilities pdf-slic3s.pl and view-toolpaths.pl,
|
|
|
|
# and by the quick slice menu of the Slic3r GUI.
|
|
|
|
#
|
|
|
|
# It creates and owns an instance of Slic3r::Print to perform the slicing
|
|
|
|
# and it accepts an instance of Slic3r::Model from the outside.
|
|
|
|
|
2014-01-02 16:54:18 +00:00
|
|
|
package Slic3r::Print::Simple;
|
|
|
|
use Moo;
|
|
|
|
|
|
|
|
use Slic3r::Geometry qw(X Y);
|
|
|
|
|
|
|
|
has '_print' => (
|
|
|
|
is => 'ro',
|
|
|
|
default => sub { Slic3r::Print->new },
|
2016-12-20 18:01:51 +00:00
|
|
|
handles => [qw(apply_config extruders output_filepath
|
2014-04-19 10:10:15 +00:00
|
|
|
total_used_filament total_extruded_volume
|
2014-07-03 07:24:19 +00:00
|
|
|
placeholder_parser process)],
|
2014-01-02 16:54:18 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
has 'duplicate' => (
|
|
|
|
is => 'rw',
|
|
|
|
default => sub { 1 },
|
|
|
|
);
|
|
|
|
|
|
|
|
has 'scale' => (
|
|
|
|
is => 'rw',
|
|
|
|
default => sub { 1 },
|
|
|
|
);
|
|
|
|
|
|
|
|
has 'rotate' => (
|
|
|
|
is => 'rw',
|
|
|
|
default => sub { 0 },
|
|
|
|
);
|
|
|
|
|
|
|
|
has 'duplicate_grid' => (
|
|
|
|
is => 'rw',
|
|
|
|
default => sub { [1,1] },
|
|
|
|
);
|
|
|
|
|
|
|
|
has 'status_cb' => (
|
|
|
|
is => 'rw',
|
|
|
|
default => sub { sub {} },
|
|
|
|
);
|
|
|
|
|
2014-06-16 21:58:45 +00:00
|
|
|
has 'print_center' => (
|
|
|
|
is => 'rw',
|
2014-09-21 08:51:36 +00:00
|
|
|
default => sub { Slic3r::Pointf->new(100,100) },
|
2014-06-16 21:58:45 +00:00
|
|
|
);
|
|
|
|
|
2016-09-05 09:32:58 +00:00
|
|
|
has 'dont_arrange' => (
|
|
|
|
is => 'rw',
|
|
|
|
default => sub { 0 },
|
|
|
|
);
|
|
|
|
|
2014-01-02 16:54:18 +00:00
|
|
|
has 'output_file' => (
|
|
|
|
is => 'rw',
|
|
|
|
);
|
|
|
|
|
|
|
|
sub set_model {
|
2016-09-13 09:24:55 +00:00
|
|
|
# $model is of type Slic3r::Model
|
2014-01-02 16:54:18 +00:00
|
|
|
my ($self, $model) = @_;
|
|
|
|
|
|
|
|
# make method idempotent so that the object is reusable
|
2014-05-06 22:58:29 +00:00
|
|
|
$self->_print->clear_objects;
|
2014-01-02 16:54:18 +00:00
|
|
|
|
2014-04-25 08:20:30 +00:00
|
|
|
# make sure all objects have at least one defined instance
|
2016-09-05 09:32:58 +00:00
|
|
|
my $need_arrange = $model->add_default_instances && ! $self->dont_arrange;
|
2014-01-02 16:54:18 +00:00
|
|
|
|
|
|
|
# apply scaling and rotation supplied from command line if any
|
|
|
|
foreach my $instance (map @{$_->instances}, @{$model->objects}) {
|
2014-04-29 23:04:49 +00:00
|
|
|
$instance->set_scaling_factor($instance->scaling_factor * $self->scale);
|
|
|
|
$instance->set_rotation($instance->rotation + $self->rotate);
|
2014-01-02 16:54:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($self->duplicate_grid->[X] > 1 || $self->duplicate_grid->[Y] > 1) {
|
2016-09-05 09:32:58 +00:00
|
|
|
$model->duplicate_objects_grid($self->duplicate_grid->[X], $self->duplicate_grid->[Y], $self->_print->config->duplicate_distance);
|
2014-01-02 16:54:18 +00:00
|
|
|
} elsif ($need_arrange) {
|
|
|
|
$model->duplicate_objects($self->duplicate, $self->_print->config->min_object_distance);
|
|
|
|
} elsif ($self->duplicate > 1) {
|
|
|
|
# if all input objects have defined position(s) apply duplication to the whole model
|
|
|
|
$model->duplicate($self->duplicate, $self->_print->config->min_object_distance);
|
|
|
|
}
|
2014-12-12 21:43:04 +00:00
|
|
|
$_->translate(0,0,-$_->bounding_box->z_min) for @{$model->objects};
|
2016-09-05 09:32:58 +00:00
|
|
|
$model->center_instances_around_point($self->print_center) if (! $self->dont_arrange);
|
2014-01-02 16:54:18 +00:00
|
|
|
|
|
|
|
foreach my $model_object (@{$model->objects}) {
|
|
|
|
$self->_print->auto_assign_extruders($model_object);
|
2014-05-06 23:11:49 +00:00
|
|
|
$self->_print->add_model_object($model_object);
|
2014-01-02 16:54:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub _before_export {
|
|
|
|
my ($self) = @_;
|
|
|
|
|
2014-05-06 08:07:18 +00:00
|
|
|
$self->_print->set_status_cb($self->status_cb);
|
2014-01-02 16:54:18 +00:00
|
|
|
$self->_print->validate;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub _after_export {
|
|
|
|
my ($self) = @_;
|
|
|
|
|
2014-05-06 08:07:18 +00:00
|
|
|
$self->_print->set_status_cb(undef);
|
2014-01-02 16:54:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub export_gcode {
|
|
|
|
my ($self) = @_;
|
|
|
|
|
|
|
|
$self->_before_export;
|
|
|
|
$self->_print->export_gcode(output_file => $self->output_file);
|
|
|
|
$self->_after_export;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub export_svg {
|
|
|
|
my ($self) = @_;
|
|
|
|
|
|
|
|
$self->_before_export;
|
|
|
|
|
|
|
|
$self->_print->export_svg(output_file => $self->output_file);
|
|
|
|
|
|
|
|
$self->_after_export;
|
|
|
|
}
|
|
|
|
|
2018-05-15 16:01:47 +00:00
|
|
|
sub export_png {
|
|
|
|
my ($self) = @_;
|
|
|
|
|
|
|
|
$self->_before_export;
|
|
|
|
|
|
|
|
$self->_print->export_png(output_file => $self->output_file);
|
|
|
|
|
|
|
|
$self->_after_export;
|
|
|
|
}
|
|
|
|
|
2014-01-02 16:54:18 +00:00
|
|
|
1;
|