Reworked the Perl unit / integration tests to use the same Print
interface that the application is using. Old interface used just for the integration tests was removed.
This commit is contained in:
parent
8bf6e69851
commit
ac6969c992
12 changed files with 72 additions and 359 deletions
|
@ -1,104 +0,0 @@
|
|||
# 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.
|
||||
|
||||
package Slic3r::Print::Simple;
|
||||
use Moo;
|
||||
|
||||
use Slic3r::Geometry qw(X Y);
|
||||
|
||||
has '_print' => (
|
||||
is => 'ro',
|
||||
default => sub { Slic3r::Print->new },
|
||||
handles => [qw(apply_config_perl_tests_only extruders output_filepath
|
||||
total_used_filament total_extruded_volume
|
||||
placeholder_parser process)],
|
||||
);
|
||||
|
||||
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 'print_center' => (
|
||||
is => 'rw',
|
||||
default => sub { Slic3r::Pointf->new(100,100) },
|
||||
);
|
||||
|
||||
has 'dont_arrange' => (
|
||||
is => 'rw',
|
||||
default => sub { 0 },
|
||||
);
|
||||
|
||||
has 'output_file' => (
|
||||
is => 'rw',
|
||||
);
|
||||
|
||||
sub set_model {
|
||||
# $model is of type Slic3r::Model
|
||||
my ($self, $model) = @_;
|
||||
|
||||
# make method idempotent so that the object is reusable
|
||||
$self->_print->clear_objects;
|
||||
|
||||
# make sure all objects have at least one defined instance
|
||||
my $need_arrange = $model->add_default_instances && ! $self->dont_arrange;
|
||||
|
||||
# apply scaling and rotation supplied from command line if any
|
||||
foreach my $instance (map @{$_->instances}, @{$model->objects}) {
|
||||
$instance->set_scaling_factor($instance->scaling_factor * $self->scale);
|
||||
$instance->set_rotation($instance->rotation + $self->rotate);
|
||||
}
|
||||
|
||||
if ($self->duplicate_grid->[X] > 1 || $self->duplicate_grid->[Y] > 1) {
|
||||
$model->duplicate_objects_grid($self->duplicate_grid->[X], $self->duplicate_grid->[Y], $self->_print->config->duplicate_distance);
|
||||
} 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);
|
||||
}
|
||||
$_->translate(0,0,-$_->bounding_box->z_min) for @{$model->objects};
|
||||
$model->center_instances_around_point($self->print_center) if (! $self->dont_arrange);
|
||||
|
||||
foreach my $model_object (@{$model->objects}) {
|
||||
$self->_print->auto_assign_extruders($model_object);
|
||||
$self->_print->add_model_object($model_object);
|
||||
}
|
||||
}
|
||||
|
||||
sub export_gcode {
|
||||
my ($self) = @_;
|
||||
$self->_print->validate;
|
||||
$self->_print->export_gcode($self->output_file // '');
|
||||
}
|
||||
|
||||
sub export_png {
|
||||
my ($self) = @_;
|
||||
|
||||
$self->_before_export;
|
||||
|
||||
$self->_print->export_png(output_file => $self->output_file);
|
||||
|
||||
$self->_after_export;
|
||||
}
|
||||
|
||||
1;
|
|
@ -146,60 +146,66 @@ sub mesh {
|
|||
}
|
||||
|
||||
sub model {
|
||||
my ($model_name, %params) = @_;
|
||||
my ($model_names, %params) = @_;
|
||||
$model_names = [ $model_names ] if ! ref($model_names);
|
||||
|
||||
my $input_file = "${model_name}.stl";
|
||||
my $mesh = mesh($model_name, %params);
|
||||
# $mesh->write_ascii("out/$input_file");
|
||||
|
||||
my $model = Slic3r::Model->new;
|
||||
my $object = $model->add_object(input_file => $input_file);
|
||||
$model->set_material($model_name);
|
||||
$object->add_volume(mesh => $mesh, material_id => $model_name);
|
||||
$object->add_instance(
|
||||
offset => Slic3r::Pointf->new(0,0),
|
||||
# 3D full transform
|
||||
rotation => Slic3r::Pointf3->new(0, 0, $params{rotation} // 0),
|
||||
scaling_factor => Slic3r::Pointf3->new($params{scale} // 1, $params{scale} // 1, $params{scale} // 1),
|
||||
# old transform
|
||||
# rotation => $params{rotation} // 0,
|
||||
# scaling_factor => $params{scale} // 1,
|
||||
);
|
||||
|
||||
for my $model_name (@$model_names) {
|
||||
my $input_file = "${model_name}.stl";
|
||||
my $mesh = mesh($model_name, %params);
|
||||
# $mesh->write_ascii("out/$input_file");
|
||||
|
||||
my $object = $model->add_object(input_file => $input_file);
|
||||
$model->set_material($model_name);
|
||||
$object->add_volume(mesh => $mesh, material_id => $model_name);
|
||||
$object->add_instance(
|
||||
offset => Slic3r::Pointf->new(0,0),
|
||||
# 3D full transform
|
||||
rotation => Slic3r::Pointf3->new(0, 0, $params{rotation} // 0),
|
||||
scaling_factor => Slic3r::Pointf3->new($params{scale} // 1, $params{scale} // 1, $params{scale} // 1),
|
||||
# old transform
|
||||
# rotation => $params{rotation} // 0,
|
||||
# scaling_factor => $params{scale} // 1,
|
||||
);
|
||||
}
|
||||
return $model;
|
||||
}
|
||||
|
||||
sub init_print {
|
||||
my ($models, %params) = @_;
|
||||
my $model;
|
||||
if (ref($models) eq 'ARRAY') {
|
||||
$model = model($models, %params);
|
||||
} elsif (ref($models)) {
|
||||
$model = $models;
|
||||
} else {
|
||||
$model = model([$models], %params);
|
||||
}
|
||||
|
||||
my $config = Slic3r::Config->new;
|
||||
$config->apply($params{config}) if $params{config};
|
||||
$config->set('gcode_comments', 1) if $ENV{SLIC3R_TESTS_GCODE};
|
||||
|
||||
my $print = Slic3r::Print->new;
|
||||
$print->apply_config_perl_tests_only($config);
|
||||
|
||||
$models = [$models] if ref($models) ne 'ARRAY';
|
||||
$models = [ map { ref($_) ? $_ : model($_, %params) } @$models ];
|
||||
for my $model (@$models) {
|
||||
die "Unknown model in test" if !defined $model;
|
||||
if (defined $params{duplicate} && $params{duplicate} > 1) {
|
||||
$model->duplicate($params{duplicate} // 1, $print->config->min_object_distance);
|
||||
}
|
||||
$model->arrange_objects($print->config->min_object_distance);
|
||||
$model->center_instances_around_point($params{print_center} ? Slic3r::Pointf->new(@{$params{print_center}}) : Slic3r::Pointf->new(100,100));
|
||||
foreach my $model_object (@{$model->objects}) {
|
||||
$print->auto_assign_extruders($model_object);
|
||||
$print->add_model_object($model_object);
|
||||
}
|
||||
die "Unknown model in test" if !defined $model;
|
||||
if (defined $params{duplicate} && $params{duplicate} > 1) {
|
||||
$model->duplicate($params{duplicate} // 1, $config->min_object_distance);
|
||||
}
|
||||
# Call apply_config_perl_tests_only one more time, so that the layer height profiles are updated over all PrintObjects.
|
||||
$print->apply_config_perl_tests_only($config);
|
||||
$model->arrange_objects($config->min_object_distance);
|
||||
$model->center_instances_around_point($params{print_center} ? Slic3r::Pointf->new(@{$params{print_center}}) : Slic3r::Pointf->new(100,100));
|
||||
foreach my $model_object (@{$model->objects}) {
|
||||
$model_object->ensure_on_bed;
|
||||
$print->auto_assign_extruders($model_object);
|
||||
}
|
||||
|
||||
$print->apply($model, $config);
|
||||
$print->validate;
|
||||
|
||||
# We return a proxy object in order to keep $models alive as required by the Print API.
|
||||
return Slic3r::Test::Print->new(
|
||||
print => $print,
|
||||
models => $models,
|
||||
print => $print,
|
||||
model => $model,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -250,7 +256,7 @@ sub add_facet {
|
|||
package Slic3r::Test::Print;
|
||||
use Moo;
|
||||
|
||||
has 'print' => (is => 'ro', required => 1, handles => [qw(process apply_config_perl_tests_only)]);
|
||||
has 'models' => (is => 'ro', required => 1);
|
||||
has 'print' => (is => 'ro', required => 1, handles => [qw(process apply)]);
|
||||
has 'model' => (is => 'ro', required => 1);
|
||||
|
||||
1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue