Skip to content

Commit

Permalink
Reworked the Perl unit / integration tests to use the same Print
Browse files Browse the repository at this point in the history
interface that the application is using. Old interface used just
for the integration tests was removed.
  • Loading branch information
bubnikv committed Jun 20, 2019
1 parent 8bf6e69 commit ac6969c
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 359 deletions.
1 change: 0 additions & 1 deletion lib/Slic3r.pm
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ use Slic3r::Point;
use Slic3r::Polygon;
use Slic3r::Polyline;
use Slic3r::Print::Object;
use Slic3r::Print::Simple;
use Slic3r::Surface;
our $build = eval "use Slic3r::Build; 1";

Expand Down
104 changes: 0 additions & 104 deletions lib/Slic3r/Print/Simple.pm

This file was deleted.

82 changes: 44 additions & 38 deletions lib/Slic3r/Test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}

Expand Down Expand Up @@ -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;
4 changes: 2 additions & 2 deletions src/libslic3r/Model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,8 @@ class Model : public ModelBase
Model() {}
~Model() { this->clear_objects(); this->clear_materials(); }

/* To be able to return an object from own copy / clone methods. Hopefully the compiler will do the "Copy elision" */
/* (Omits copy and move(since C++11) constructors, resulting in zero - copy pass - by - value semantics). */
// To be able to return an object from own copy / clone methods. Hopefully the compiler will do the "Copy elision"
// (Omits copy and move(since C++11) constructors, resulting in zero - copy pass - by - value semantics).
Model(const Model &rhs) : ModelBase(-1) { this->assign_copy(rhs); }
explicit Model(Model &&rhs) : ModelBase(-1) { this->assign_copy(std::move(rhs)); }
Model& operator=(const Model &rhs) { this->assign_copy(rhs); return *this; }
Expand Down
Loading

0 comments on commit ac6969c

Please sign in to comment.