mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-08-05 04:54:08 -06:00
Refactoring to Model API for making it stricter and safer
This commit is contained in:
parent
bc023c2d51
commit
7ba08c90cf
17 changed files with 316 additions and 317 deletions
|
@ -124,9 +124,9 @@ sub model {
|
|||
$model->set_material($model_name);
|
||||
$object->add_volume(mesh => mesh($model_name, %params), material_id => $model_name);
|
||||
$object->add_instance(
|
||||
offset => [0,0],
|
||||
rotation => $params{rotation} // 0,
|
||||
scaling_factor => $params{scale} // 1,
|
||||
offset => Slic3r::Pointf->new(0,0),
|
||||
rotation => $params{rotation} // 0,
|
||||
scaling_factor => $params{scale} // 1,
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
|
@ -142,7 +142,8 @@ sub init_print {
|
|||
$print->apply_config($config);
|
||||
|
||||
$models = [$models] if ref($models) ne 'ARRAY';
|
||||
for my $model (map { ref($_) ? $_ : model($_, %params) } @$models) {
|
||||
$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);
|
||||
|
@ -156,12 +157,18 @@ sub init_print {
|
|||
}
|
||||
$print->validate;
|
||||
|
||||
return $print;
|
||||
# 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,
|
||||
);
|
||||
}
|
||||
|
||||
sub gcode {
|
||||
my ($print) = @_;
|
||||
|
||||
$print = $print->print if $print->isa('Slic3r::Test::Print');
|
||||
|
||||
my $fh = IO::Scalar->new(\my $gcode);
|
||||
$print->process;
|
||||
$print->export_gcode(output_fh => $fh, quiet => 1);
|
||||
|
@ -189,4 +196,10 @@ sub add_facet {
|
|||
}
|
||||
}
|
||||
|
||||
package Slic3r::Test::Print;
|
||||
use Moo;
|
||||
|
||||
has 'print' => (is => 'ro', required => 1);
|
||||
has 'models' => (is => 'ro', required => 1);
|
||||
|
||||
1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue