Merge branch 'sapir-modelcpp'
This commit is contained in:
commit
6e207d3830
@ -148,6 +148,8 @@ sub thread_cleanup {
|
||||
*Slic3r::Geometry::BoundingBox::DESTROY = sub {};
|
||||
*Slic3r::Geometry::BoundingBoxf3::DESTROY = sub {};
|
||||
*Slic3r::Line::DESTROY = sub {};
|
||||
*Slic3r::Model::DESTROY = sub {};
|
||||
*Slic3r::Model::Object::DESTROY = sub {};
|
||||
*Slic3r::Point::DESTROY = sub {};
|
||||
*Slic3r::Pointf::DESTROY = sub {};
|
||||
*Slic3r::Pointf3::DESTROY = sub {};
|
||||
|
@ -35,8 +35,8 @@ sub write_file {
|
||||
printf $fh qq{<?xml version="1.0" encoding="UTF-8"?>\n};
|
||||
printf $fh qq{<amf unit="millimeter">\n};
|
||||
printf $fh qq{ <metadata type="cad">Slic3r %s</metadata>\n}, $Slic3r::VERSION;
|
||||
for my $material_id (sort keys %{ $model->materials }) {
|
||||
my $material = $model->materials->{$material_id};
|
||||
for my $material_id (sort @{ $model->material_names }) {
|
||||
my $material = $model->get_material($material_id);
|
||||
printf $fh qq{ <material id="%s">\n}, $material_id;
|
||||
for (keys %{$material->attributes}) {
|
||||
printf $fh qq{ <metadata type=\"%s\">%s</metadata>\n}, $_, $material->attributes->{$_};
|
||||
|
@ -471,8 +471,8 @@ sub reset {
|
||||
my $self = shift;
|
||||
|
||||
@{$self->{objects}} = ();
|
||||
$self->{model}->delete_all_objects;
|
||||
$self->{print}->delete_all_objects;
|
||||
$self->{model}->clear_objects;
|
||||
$self->{print}->clear_objects;
|
||||
$self->{list}->DeleteAllItems;
|
||||
$self->object_list_changed;
|
||||
|
||||
@ -542,7 +542,7 @@ sub rotate {
|
||||
|
||||
{
|
||||
my $new_angle = $model_instance->rotation + $angle;
|
||||
$_->rotation($new_angle) for @{ $model_object->instances };
|
||||
$_->set_rotation($new_angle) for @{ $model_object->instances };
|
||||
$model_object->update_bounding_box;
|
||||
|
||||
# update print
|
||||
@ -578,7 +578,7 @@ sub changescale {
|
||||
$range->[0] *= $variation;
|
||||
$range->[1] *= $variation;
|
||||
}
|
||||
$_->scaling_factor($scale) for @{ $model_object->instances };
|
||||
$_->set_scaling_factor($scale) for @{ $model_object->instances };
|
||||
$model_object->update_bounding_box;
|
||||
|
||||
# update print
|
||||
@ -1108,10 +1108,11 @@ sub mouse_event {
|
||||
return if !$self->{drag_start_pos}; # concurrency problems
|
||||
my ($obj_idx, $instance_idx) = @{ $self->{drag_object} };
|
||||
my $model_object = $parent->{model}->objects->[$obj_idx];
|
||||
$model_object->instances->[$instance_idx]->offset([
|
||||
unscale($pos->[X] - $self->{drag_start_pos}[X]),
|
||||
unscale($pos->[Y] - $self->{drag_start_pos}[Y]),
|
||||
]);
|
||||
$model_object->instances->[$instance_idx]->set_offset(
|
||||
Slic3r::Pointf->new(
|
||||
unscale($pos->[X] - $self->{drag_start_pos}[X]),
|
||||
unscale($pos->[Y] - $self->{drag_start_pos}[Y]),
|
||||
));
|
||||
$model_object->update_bounding_box;
|
||||
$parent->Refresh;
|
||||
} elsif ($event->Moving) {
|
||||
|
@ -158,7 +158,7 @@ sub selection_changed {
|
||||
|
||||
# attach volume material config to settings panel
|
||||
my $volume = $self->{model_object}->volumes->[ $itemData->{volume_id} ];
|
||||
my $material = $self->{model_object}->model->materials->{ $volume->material_id // '_' };
|
||||
my $material = $self->{model_object}->model->get_material($volume->material_id // '_');
|
||||
$material //= $volume->assign_unique_material;
|
||||
$self->{staticbox}->SetLabel('Part Settings');
|
||||
$self->{settings_panel}->enable;
|
||||
@ -211,7 +211,7 @@ sub on_btn_load {
|
||||
$new_volume->mesh->translate(@{$self->{model_object}->origin_translation}, 0);
|
||||
|
||||
# set a default extruder value, since user can't add it manually
|
||||
my $material = $self->{model_object}->model->materials->{$new_volume->material_id};
|
||||
my $material = $self->{model_object}->model->get_material($new_volume->material_id);
|
||||
$material->config->set_ifndef('extruder', 1);
|
||||
|
||||
$self->{parts_changed} = 1;
|
||||
|
@ -1,12 +1,8 @@
|
||||
package Slic3r::Model;
|
||||
use Moo;
|
||||
|
||||
use List::Util qw(first max);
|
||||
use Slic3r::Geometry qw(X Y Z move_points);
|
||||
|
||||
has 'materials' => (is => 'ro', default => sub { {} });
|
||||
has 'objects' => (is => 'ro', default => sub { [] });
|
||||
|
||||
sub read_from_file {
|
||||
my $class = shift;
|
||||
my ($input_file) = @_;
|
||||
@ -16,7 +12,7 @@ sub read_from_file {
|
||||
: $input_file =~ /\.amf(\.xml)?$/i ? Slic3r::Format::AMF->read_file($input_file)
|
||||
: die "Input file must have .stl, .obj or .amf(.xml) extension\n";
|
||||
|
||||
$_->input_file($input_file) for @{$model->objects};
|
||||
$_->set_input_file($input_file) for @{$model->objects};
|
||||
return $model;
|
||||
}
|
||||
|
||||
@ -44,6 +40,7 @@ sub add_object {
|
||||
input_file => $object->input_file,
|
||||
config => $object->config,
|
||||
layer_height_ranges => $object->layer_height_ranges, # TODO: clone!
|
||||
origin_translation => $object->origin_translation,
|
||||
);
|
||||
|
||||
foreach my $volume (@{$object->volumes}) {
|
||||
@ -51,40 +48,32 @@ sub add_object {
|
||||
}
|
||||
|
||||
$new_object->add_instance(
|
||||
offset => $_->offset,
|
||||
offset => [ @{$_->offset} ],
|
||||
rotation => $_->rotation,
|
||||
scaling_factor => $_->scaling_factor,
|
||||
) for @{ $object->instances // [] };
|
||||
} else {
|
||||
push @{$self->objects}, $new_object = Slic3r::Model::Object->new(model => $self, @_);
|
||||
my (%args) = @_;
|
||||
$new_object = $self->_add_object(
|
||||
$args{input_file},
|
||||
$args{config} // Slic3r::Config->new,
|
||||
$args{layer_height_ranges} // [],
|
||||
$args{origin_translation} // Slic3r::Pointf->new,
|
||||
);
|
||||
}
|
||||
|
||||
return $new_object;
|
||||
}
|
||||
|
||||
sub delete_object {
|
||||
my ($self, $obj_idx) = @_;
|
||||
splice @{$self->objects}, $obj_idx, 1;
|
||||
}
|
||||
|
||||
sub delete_all_objects {
|
||||
my ($self) = @_;
|
||||
@{$self->objects} = ();
|
||||
}
|
||||
|
||||
sub set_material {
|
||||
my $self = shift;
|
||||
my ($material_id, $attributes) = @_;
|
||||
|
||||
return $self->materials->{$material_id} = Slic3r::Model::Material->new(
|
||||
model => $self,
|
||||
attributes => $attributes || {},
|
||||
);
|
||||
}
|
||||
$attributes //= {};
|
||||
|
||||
sub get_material {
|
||||
my ($self, $material_id) = @_;
|
||||
return $self->materials->{$material_id};
|
||||
my $material = $self->_set_material($material_id);
|
||||
$material->set_attribute($_, $attributes->{$_}) for keys %$attributes;
|
||||
return $material;
|
||||
}
|
||||
|
||||
sub duplicate_objects_grid {
|
||||
@ -94,7 +83,7 @@ sub duplicate_objects_grid {
|
||||
if @{$self->objects} > 1;
|
||||
|
||||
my $object = $self->objects->[0];
|
||||
@{$object->instances} = ();
|
||||
$object->clear_instances;
|
||||
|
||||
my $size = $object->bounding_box->size;
|
||||
for my $x_copy (1..$grid->[X]) {
|
||||
@ -144,7 +133,7 @@ sub arrange_objects {
|
||||
my @positions = $self->_arrange(\@instance_sizes, $distance, $bb);
|
||||
|
||||
foreach my $object (@{$self->objects}) {
|
||||
$_->offset([ @{shift @positions} ]) for @{$object->instances};
|
||||
$_->set_offset(Slic3r::Pointf->new(@{shift @positions})) for @{$object->instances};
|
||||
$object->update_bounding_box;
|
||||
}
|
||||
}
|
||||
@ -231,8 +220,10 @@ sub center_instances_around_point {
|
||||
|
||||
foreach my $object (@{$self->objects}) {
|
||||
foreach my $instance (@{$object->instances}) {
|
||||
$instance->offset->[X] += $shift[X];
|
||||
$instance->offset->[Y] += $shift[Y];
|
||||
$instance->set_offset(Slic3r::Pointf->new(
|
||||
$instance->offset->x + $shift[X],
|
||||
$instance->offset->y + $shift[Y], #++
|
||||
));
|
||||
}
|
||||
$object->update_bounding_box;
|
||||
}
|
||||
@ -276,7 +267,7 @@ sub split_meshes {
|
||||
if (@{$object->volumes} > 1) {
|
||||
# We can't split meshes if there's more than one material, because
|
||||
# we can't group the resulting meshes by object afterwards
|
||||
push @{$self->objects}, $object;
|
||||
$self->_add_object($object);
|
||||
next;
|
||||
}
|
||||
|
||||
@ -286,6 +277,7 @@ sub split_meshes {
|
||||
input_file => $object->input_file,
|
||||
config => $object->config->clone,
|
||||
layer_height_ranges => $object->layer_height_ranges, # TODO: this needs to be cloned
|
||||
origin_translation => $object->origin_translation,
|
||||
);
|
||||
$new_object->add_volume(
|
||||
mesh => $mesh,
|
||||
@ -312,36 +304,22 @@ sub get_material_name {
|
||||
my ($material_id) = @_;
|
||||
|
||||
my $name;
|
||||
if (exists $self->materials->{$material_id}) {
|
||||
$name //= $self->materials->{$material_id}->attributes->{$_} for qw(Name name);
|
||||
if ($self->has_material($material_id)) {
|
||||
$name //= $self->get_material($material_id)
|
||||
->attributes->{$_} for qw(Name name);
|
||||
}
|
||||
$name //= $material_id;
|
||||
return $name;
|
||||
}
|
||||
|
||||
package Slic3r::Model::Material;
|
||||
use Moo;
|
||||
|
||||
has 'model' => (is => 'ro', weak_ref => 1, required => 1);
|
||||
has 'attributes' => (is => 'rw', default => sub { {} });
|
||||
has 'config' => (is => 'rw', default => sub { Slic3r::Config->new });
|
||||
|
||||
package Slic3r::Model::Object;
|
||||
use Moo;
|
||||
|
||||
use File::Basename qw(basename);
|
||||
use List::Util qw(first sum);
|
||||
use Slic3r::Geometry qw(X Y Z rad2deg);
|
||||
|
||||
has 'input_file' => (is => 'rw');
|
||||
has 'model' => (is => 'ro', weak_ref => 1, required => 1);
|
||||
has 'volumes' => (is => 'ro', default => sub { [] });
|
||||
has 'instances' => (is => 'rw');
|
||||
has 'config' => (is => 'rw', default => sub { Slic3r::Config->new });
|
||||
has 'layer_height_ranges' => (is => 'rw', default => sub { [] }); # [ z_min, z_max, layer_height ]
|
||||
has '_bounding_box' => (is => 'rw');
|
||||
has 'origin_translation' => (is => 'ro', default => sub { Slic3r::Point->new }); # translation vector applied by center_around_origin()
|
||||
|
||||
sub add_volume {
|
||||
my $self = shift;
|
||||
|
||||
@ -350,19 +328,16 @@ sub add_volume {
|
||||
# we have a Model::Volume
|
||||
my ($volume) = @_;
|
||||
|
||||
$new_volume = Slic3r::Model::Volume->new(
|
||||
object => $self,
|
||||
material_id => $volume->material_id,
|
||||
mesh => $volume->mesh->clone,
|
||||
modifier => $volume->modifier,
|
||||
);
|
||||
$new_volume = $self->_add_volume(
|
||||
$volume->material_id, $volume->mesh->clone, $volume->modifier);
|
||||
|
||||
# TODO: material_id can't be undef.
|
||||
if (defined $volume->material_id) {
|
||||
# merge material attributes and config (should we rename materials in case of duplicates?)
|
||||
if (my $material = $volume->object->model->materials->{$volume->material_id}) {
|
||||
if (my $material = $volume->object->model->get_material($volume->material_id)) {
|
||||
my %attributes = %{ $material->attributes };
|
||||
if (exists $self->model->materials->{$volume->material_id}) {
|
||||
%attributes = (%attributes, %{ $self->model->materials->{$volume->material_id}->attributes })
|
||||
if ($self->model->has_material($volume->material_id)) {
|
||||
%attributes = (%attributes, %{ $self->model->get_material($volume->material_id)->attributes })
|
||||
}
|
||||
my $new_material = $self->model->set_material($volume->material_id, {%attributes});
|
||||
$new_material->config->apply($material->config);
|
||||
@ -370,10 +345,10 @@ sub add_volume {
|
||||
}
|
||||
} else {
|
||||
my %args = @_;
|
||||
$new_volume = Slic3r::Model::Volume->new(
|
||||
object => $self,
|
||||
%args,
|
||||
);
|
||||
$new_volume = $self->_add_volume(
|
||||
$args{material_id},
|
||||
$args{mesh},
|
||||
$args{modifier} // 0);
|
||||
}
|
||||
|
||||
if (defined $new_volume->material_id && !defined $self->model->get_material($new_volume->material_id)) {
|
||||
@ -381,33 +356,19 @@ sub add_volume {
|
||||
$self->model->set_material($new_volume->material_id);
|
||||
}
|
||||
|
||||
push @{$self->volumes}, $new_volume;
|
||||
|
||||
# invalidate cached bounding box
|
||||
$self->_bounding_box(undef);
|
||||
$self->invalidate_bounding_box();
|
||||
|
||||
return $new_volume;
|
||||
}
|
||||
|
||||
sub delete_volume {
|
||||
my ($self, $i) = @_;
|
||||
splice @{$self->volumes}, $i, 1;
|
||||
}
|
||||
|
||||
sub add_instance {
|
||||
my $self = shift;
|
||||
my %params = @_;
|
||||
|
||||
$self->instances([]) if !defined $self->instances;
|
||||
push @{$self->instances}, my $i = Slic3r::Model::Instance->new(object => $self, %params);
|
||||
$self->_bounding_box(undef);
|
||||
return $i;
|
||||
}
|
||||
|
||||
sub delete_last_instance {
|
||||
my ($self) = @_;
|
||||
pop @{$self->instances};
|
||||
$self->_bounding_box(undef);
|
||||
return $self->_add_instance(
|
||||
$params{rotation} // 0,
|
||||
$params{scaling_factor} // 1,
|
||||
$params{offset} // []);
|
||||
}
|
||||
|
||||
sub instances_count {
|
||||
@ -487,8 +448,9 @@ sub center_around_origin {
|
||||
|
||||
if (defined $self->instances) {
|
||||
foreach my $instance (@{ $self->instances }) {
|
||||
$instance->offset->[X] -= $shift[X];
|
||||
$instance->offset->[Y] -= $shift[Y];
|
||||
$instance->set_offset(Slic3r::Pointf->new(
|
||||
$instance->offset->x - $shift[X],
|
||||
$instance->offset->y - $shift[Y]));
|
||||
}
|
||||
$self->update_bounding_box;
|
||||
}
|
||||
@ -511,7 +473,7 @@ sub rotate_x {
|
||||
$angle = rad2deg($angle);
|
||||
|
||||
$_->mesh->rotate_x($angle) for @{$self->volumes};
|
||||
$self->_bounding_box(undef);
|
||||
$self->invalidate_bounding_box;
|
||||
}
|
||||
|
||||
sub materials_count {
|
||||
@ -577,22 +539,22 @@ sub cut {
|
||||
|
||||
# clone this one
|
||||
my $upper = Slic3r::Model::Object->new(
|
||||
input_file => $self->input_file,
|
||||
model => $self->model,
|
||||
config => $self->config->clone,
|
||||
layer_height_ranges => $self->layer_height_ranges,
|
||||
origin_translation => $self->origin_translation->clone,
|
||||
$self->model,
|
||||
$self->input_file,
|
||||
$self->config, # config is cloned by new()
|
||||
$self->layer_height_ranges,
|
||||
$self->origin_translation,
|
||||
);
|
||||
my $lower = Slic3r::Model::Object->new(
|
||||
input_file => $self->input_file,
|
||||
model => $self->model,
|
||||
config => $self->config->clone,
|
||||
layer_height_ranges => $self->layer_height_ranges,
|
||||
origin_translation => $self->origin_translation->clone,
|
||||
$self->model,
|
||||
$self->input_file,
|
||||
$self->config, # config is cloned by new()
|
||||
$self->layer_height_ranges,
|
||||
$self->origin_translation,
|
||||
);
|
||||
foreach my $instance (@{$self->instances}) {
|
||||
$upper->add_instance(offset => $instance->offset);
|
||||
$lower->add_instance(offset => $instance->offset);
|
||||
$upper->add_instance(offset => [ @{$instance->offset} ]);
|
||||
$lower->add_instance(offset => [ @{$instance->offset} ]);
|
||||
}
|
||||
|
||||
foreach my $volume (@{$self->volumes}) {
|
||||
@ -632,29 +594,17 @@ sub cut {
|
||||
}
|
||||
|
||||
package Slic3r::Model::Volume;
|
||||
use Moo;
|
||||
|
||||
has 'object' => (is => 'ro', weak_ref => 1, required => 1);
|
||||
has 'material_id' => (is => 'rw');
|
||||
has 'mesh' => (is => 'rw', required => 1);
|
||||
has 'modifier' => (is => 'rw', defualt => sub { 0 });
|
||||
|
||||
sub assign_unique_material {
|
||||
my ($self) = @_;
|
||||
|
||||
my $model = $self->object->model;
|
||||
my $material_id = 1 + scalar keys %{$model->materials};
|
||||
my $material_id = 1 + $model->material_count;
|
||||
$self->material_id($material_id);
|
||||
return $model->set_material($material_id);
|
||||
}
|
||||
|
||||
package Slic3r::Model::Instance;
|
||||
use Moo;
|
||||
|
||||
has 'object' => (is => 'ro', weak_ref => 1, required => 1);
|
||||
has 'rotation' => (is => 'rw', default => sub { 0 }); # around mesh center point
|
||||
has 'scaling_factor' => (is => 'rw', default => sub { 1 });
|
||||
has 'offset' => (is => 'rw'); # must be arrayref in *unscaled* coordinates
|
||||
|
||||
sub transform_mesh {
|
||||
my ($self, $mesh, $dont_translate) = @_;
|
||||
|
@ -86,7 +86,7 @@ sub apply_config {
|
||||
$new->apply_dynamic($model_object_config);
|
||||
}
|
||||
if (defined $volume->material_id) {
|
||||
my $material_config = $object->model_object->model->materials->{$volume->material_id}->config->clone;
|
||||
my $material_config = $object->model_object->model->get_material($volume->material_id)->config->clone;
|
||||
$material_config->normalize;
|
||||
$new->apply_dynamic($material_config);
|
||||
}
|
||||
@ -104,9 +104,8 @@ sub apply_config {
|
||||
if ($rearrange_regions) {
|
||||
# the current subdivision of regions does not make sense anymore.
|
||||
# we need to remove all objects and re-add them
|
||||
my @model_objects = map $_->model_object, @{$self->objects};
|
||||
$self->delete_all_objects;
|
||||
$self->add_model_object($_) for @model_objects;
|
||||
$self->clear_objects;
|
||||
$self->add_model_object($_->model_object) for @{$self->objects};
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,7 +137,7 @@ sub add_model_object {
|
||||
$config->apply_dynamic($object_config);
|
||||
|
||||
if (defined $volume->material_id) {
|
||||
my $material_config = $object->model->materials->{ $volume->material_id }->config->clone;
|
||||
my $material_config = $object->model->get_material($volume->material_id)->config->clone;
|
||||
$material_config->normalize;
|
||||
$config->apply_dynamic($material_config);
|
||||
}
|
||||
@ -201,7 +200,7 @@ sub delete_object {
|
||||
$self->_state->invalidate(STEP_BRIM);
|
||||
}
|
||||
|
||||
sub delete_all_objects {
|
||||
sub clear_objects {
|
||||
my ($self) = @_;
|
||||
|
||||
@{$self->objects} = ();
|
||||
@ -220,9 +219,9 @@ sub reload_object {
|
||||
# For now we just re-add all objects since we haven't implemented this incremental logic yet.
|
||||
# This should also check whether object volumes (parts) have changed.
|
||||
|
||||
my @model_objects = map $_->model_object, @{$self->objects};
|
||||
$self->delete_all_objects;
|
||||
$self->add_model_object($_) for @model_objects;
|
||||
my @models_objects = map $_->model_object, @{$self->objects};
|
||||
$self->clear_objects;
|
||||
$self->add_model_object($_) for @models_objects;
|
||||
}
|
||||
|
||||
sub validate {
|
||||
@ -1116,7 +1115,7 @@ sub auto_assign_extruders {
|
||||
foreach my $i (0..$#{$model_object->volumes}) {
|
||||
my $volume = $model_object->volumes->[$i];
|
||||
if (defined $volume->material_id) {
|
||||
my $material = $model_object->model->materials->{ $volume->material_id };
|
||||
my $material = $model_object->model->get_material($volume->material_id);
|
||||
my $config = $material->config;
|
||||
my $extruder_id = $i + 1;
|
||||
$config->set_ifndef('extruder', $extruder_id);
|
||||
|
@ -10,7 +10,7 @@ use Slic3r::Print::State ':steps';
|
||||
use Slic3r::Surface ':types';
|
||||
|
||||
has 'print' => (is => 'ro', weak_ref => 1, required => 1);
|
||||
has 'model_object' => (is => 'ro', required => 1);
|
||||
has 'model_object' => (is => 'ro', required => 1); # caller is responsible for holding the Model object
|
||||
has 'region_volumes' => (is => 'rw', default => sub { [] }); # by region_id
|
||||
has 'copies' => (is => 'ro'); # Slic3r::Point objects in scaled G-code coordinates
|
||||
has 'config' => (is => 'ro', default => sub { Slic3r::Config::PrintObject->new });
|
||||
|
@ -44,15 +44,15 @@ sub set_model {
|
||||
my ($self, $model) = @_;
|
||||
|
||||
# make method idempotent so that the object is reusable
|
||||
$self->_print->delete_all_objects;
|
||||
$self->_print->clear_objects;
|
||||
|
||||
# make sure all objects have at least one defined instance
|
||||
my $need_arrange = $model->add_default_instances;
|
||||
|
||||
# apply scaling and rotation supplied from command line if any
|
||||
foreach my $instance (map @{$_->instances}, @{$model->objects}) {
|
||||
$instance->scaling_factor($instance->scaling_factor * $self->scale);
|
||||
$instance->rotation($instance->rotation + $self->rotate);
|
||||
$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) {
|
||||
|
@ -172,7 +172,6 @@ if (@ARGV) { # slicing from command line
|
||||
|
||||
$sprint->apply_config($config);
|
||||
$sprint->set_model($model);
|
||||
undef $model; # free memory
|
||||
|
||||
if ($opt{export_svg}) {
|
||||
$sprint->export_svg;
|
||||
|
@ -1673,6 +1673,7 @@ src/Geometry.hpp
|
||||
src/Layer.hpp
|
||||
src/Line.cpp
|
||||
src/Line.hpp
|
||||
src/Model.cpp
|
||||
src/Model.hpp
|
||||
src/MultiPoint.cpp
|
||||
src/MultiPoint.hpp
|
||||
@ -1742,6 +1743,7 @@ xsp/ExtrusionPath.xsp
|
||||
xsp/Flow.xsp
|
||||
xsp/Geometry.xsp
|
||||
xsp/Line.xsp
|
||||
xsp/Model.xsp
|
||||
xsp/my.map
|
||||
xsp/mytype.map
|
||||
xsp/Point.xsp
|
||||
|
@ -13,31 +13,16 @@ use overload
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
'fallback' => 1;
|
||||
|
||||
package Slic3r::Line::Ref;
|
||||
our @ISA = 'Slic3r::Line';
|
||||
|
||||
sub DESTROY {}
|
||||
|
||||
package Slic3r::Point;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
'fallback' => 1;
|
||||
|
||||
package Slic3r::Point::Ref;
|
||||
our @ISA = 'Slic3r::Point';
|
||||
|
||||
sub DESTROY {}
|
||||
|
||||
package Slic3r::Pointf;
|
||||
use overload
|
||||
'@{}' => sub { [ $_[0]->x, $_[0]->y ] }, #,
|
||||
'fallback' => 1;
|
||||
|
||||
package Slic3r::Pointf::Ref;
|
||||
our @ISA = 'Slic3r::Pointf';
|
||||
|
||||
sub DESTROY {}
|
||||
|
||||
package Slic3r::Pointf3;
|
||||
use overload
|
||||
'@{}' => sub { [ $_[0]->x, $_[0]->y, $_[0]->z ] }, #,
|
||||
@ -48,21 +33,11 @@ use overload
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
'fallback' => 1;
|
||||
|
||||
package Slic3r::ExPolygon::Ref;
|
||||
our @ISA = 'Slic3r::ExPolygon';
|
||||
|
||||
sub DESTROY {}
|
||||
|
||||
package Slic3r::Polyline;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
'fallback' => 1;
|
||||
|
||||
package Slic3r::Polyline::Ref;
|
||||
our @ISA = 'Slic3r::Polyline';
|
||||
|
||||
sub DESTROY {}
|
||||
|
||||
package Slic3r::Polyline::Collection;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
@ -73,11 +48,6 @@ use overload
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
'fallback' => 1;
|
||||
|
||||
package Slic3r::Polygon::Ref;
|
||||
our @ISA = 'Slic3r::Polygon';
|
||||
|
||||
sub DESTROY {}
|
||||
|
||||
package Slic3r::ExPolygon::Collection;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
@ -96,11 +66,6 @@ sub new {
|
||||
return $self;
|
||||
}
|
||||
|
||||
package Slic3r::ExtrusionPath::Collection::Ref;
|
||||
our @ISA = 'Slic3r::ExtrusionPath::Collection';
|
||||
|
||||
sub DESTROY {}
|
||||
|
||||
package Slic3r::ExtrusionLoop;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
@ -114,11 +79,6 @@ sub new_from_paths {
|
||||
return $loop;
|
||||
}
|
||||
|
||||
package Slic3r::ExtrusionLoop::Ref;
|
||||
our @ISA = 'Slic3r::ExtrusionLoop';
|
||||
|
||||
sub DESTROY {}
|
||||
|
||||
package Slic3r::ExtrusionPath;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
@ -148,11 +108,6 @@ sub clone {
|
||||
);
|
||||
}
|
||||
|
||||
package Slic3r::ExtrusionPath::Ref;
|
||||
our @ISA = 'Slic3r::ExtrusionPath';
|
||||
|
||||
sub DESTROY {}
|
||||
|
||||
package Slic3r::Flow;
|
||||
|
||||
sub new {
|
||||
@ -213,14 +168,38 @@ sub clone {
|
||||
);
|
||||
}
|
||||
|
||||
package Slic3r::Surface::Ref;
|
||||
our @ISA = 'Slic3r::Surface';
|
||||
|
||||
sub DESTROY {}
|
||||
|
||||
package Slic3r::Surface::Collection;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
'fallback' => 1;
|
||||
|
||||
package main;
|
||||
for my $class (qw(
|
||||
Slic3r::Config
|
||||
Slic3r::Config::Print
|
||||
Slic3r::ExPolygon
|
||||
Slic3r::ExtrusionLoop
|
||||
Slic3r::ExtrusionPath
|
||||
Slic3r::ExtrusionPath::Collection
|
||||
Slic3r::Geometry::BoundingBoxf3
|
||||
Slic3r::Line
|
||||
Slic3r::Model
|
||||
Slic3r::Model::Instance
|
||||
Slic3r::Model::Material
|
||||
Slic3r::Model::Object
|
||||
Slic3r::Model::Volume
|
||||
Slic3r::Point
|
||||
Slic3r::Pointf
|
||||
Slic3r::Pointf3
|
||||
Slic3r::Polygon
|
||||
Slic3r::Polyline
|
||||
Slic3r::Surface
|
||||
Slic3r::TriangleMesh
|
||||
))
|
||||
{
|
||||
no strict 'refs';
|
||||
my $ref_class = $class . "::Ref";
|
||||
eval "package $ref_class; our \@ISA = '$class'; sub DESTROY {};";
|
||||
}
|
||||
|
||||
1;
|
||||
|
325
xs/src/Model.cpp
Normal file
325
xs/src/Model.cpp
Normal file
@ -0,0 +1,325 @@
|
||||
#include "Model.hpp"
|
||||
#ifdef SLIC3RXS
|
||||
#include "perlglue.hpp"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
Model::Model() {}
|
||||
|
||||
Model::Model(const Model &other)
|
||||
{
|
||||
objects.reserve(other.objects.size());
|
||||
|
||||
for (ModelMaterialMap::const_iterator i = other.materials.begin();
|
||||
i != other.materials.end(); ++i)
|
||||
{
|
||||
ModelMaterial *copy = new ModelMaterial(*i->second);
|
||||
copy->model = this;
|
||||
materials[i->first] = copy;
|
||||
|
||||
}
|
||||
|
||||
for (ModelObjectPtrs::const_iterator i = other.objects.begin();
|
||||
i != other.objects.end(); ++i)
|
||||
{
|
||||
ModelObject *copy = new ModelObject(**i);
|
||||
copy->model = this;
|
||||
objects.push_back(copy);
|
||||
}
|
||||
}
|
||||
|
||||
Model::~Model()
|
||||
{
|
||||
this->clear_objects();
|
||||
this->clear_materials();
|
||||
}
|
||||
|
||||
ModelObject*
|
||||
Model::add_object(const std::string &input_file, const DynamicPrintConfig &config,
|
||||
const t_layer_height_ranges &layer_height_ranges, const Pointf &origin_translation)
|
||||
{
|
||||
ModelObject* object = new ModelObject(this, input_file, config,
|
||||
layer_height_ranges, origin_translation);
|
||||
this->objects.push_back(object);
|
||||
return object;
|
||||
}
|
||||
|
||||
void
|
||||
Model::delete_object(size_t idx)
|
||||
{
|
||||
ModelObjectPtrs::iterator i = this->objects.begin() + idx;
|
||||
delete *i;
|
||||
this->objects.erase(i);
|
||||
}
|
||||
|
||||
void
|
||||
Model::clear_objects()
|
||||
{
|
||||
for (size_t i = this->objects.size()-1; i >= 0; --i)
|
||||
this->delete_object(i);
|
||||
}
|
||||
|
||||
void
|
||||
Model::delete_material(t_model_material_id material_id)
|
||||
{
|
||||
ModelMaterialMap::iterator i = this->materials.find(material_id);
|
||||
if (i != this->materials.end()) {
|
||||
delete i->second;
|
||||
this->materials.erase(i);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Model::clear_materials()
|
||||
{
|
||||
while (!this->materials.empty())
|
||||
this->delete_material( this->materials.begin()->first );
|
||||
}
|
||||
|
||||
ModelMaterial *
|
||||
Model::set_material(t_model_material_id material_id)
|
||||
{
|
||||
ModelMaterialMap::iterator i = this->materials.find(material_id);
|
||||
|
||||
ModelMaterial *mat;
|
||||
if (i == this->materials.end()) {
|
||||
mat = this->materials[material_id] = new ModelMaterial(this);
|
||||
} else {
|
||||
mat = i->second;
|
||||
}
|
||||
|
||||
return mat;
|
||||
}
|
||||
|
||||
/*
|
||||
void
|
||||
Model::duplicate_objects_grid(unsigned int x, unsigned int y, coordf_t distance)
|
||||
{
|
||||
if (this->objects.size() > 1) throw "Grid duplication is not supported with multiple objects";
|
||||
if (this->objects.empty()) throw "No objects!";
|
||||
|
||||
ModelObject* object = this->objects.front();
|
||||
object->clear_instances();
|
||||
|
||||
BoundingBoxf3 bb;
|
||||
object->bounding_box(&bb);
|
||||
Sizef3 size = bb.size();
|
||||
|
||||
for (unsigned int x_copy = 1; x_copy <= x; ++x_copy) {
|
||||
for (unsigned int y_copy = 1; y_copy <= y; ++y_copy) {
|
||||
ModelInstance* instance = object->add_instance();
|
||||
instance->offset.x = (size.x + distance) * (x_copy-1);
|
||||
instance->offset.y = (size.y + distance) * (y_copy-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
bool
|
||||
Model::has_objects_with_no_instances() const
|
||||
{
|
||||
for (ModelObjectPtrs::const_iterator i = this->objects.begin();
|
||||
i != this->objects.end(); ++i)
|
||||
{
|
||||
if ((*i)->instances.empty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
REGISTER_CLASS(Model, "Model");
|
||||
#endif
|
||||
|
||||
|
||||
ModelMaterial::ModelMaterial(Model *model) : model(model) {}
|
||||
|
||||
void
|
||||
ModelMaterial::apply(const t_model_material_attributes &attributes)
|
||||
{
|
||||
this->attributes.insert(attributes.begin(), attributes.end());
|
||||
}
|
||||
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
REGISTER_CLASS(ModelMaterial, "Model::Material");
|
||||
#endif
|
||||
|
||||
|
||||
ModelObject::ModelObject(Model *model, const std::string &input_file,
|
||||
const DynamicPrintConfig &config, const t_layer_height_ranges &layer_height_ranges,
|
||||
const Pointf &origin_translation)
|
||||
: model(model),
|
||||
input_file(input_file),
|
||||
config(config),
|
||||
layer_height_ranges(layer_height_ranges),
|
||||
origin_translation(origin_translation),
|
||||
_bounding_box_valid(false)
|
||||
{
|
||||
}
|
||||
|
||||
ModelObject::ModelObject(const ModelObject &other)
|
||||
: model(other.model),
|
||||
input_file(other.input_file),
|
||||
instances(),
|
||||
volumes(),
|
||||
config(other.config),
|
||||
layer_height_ranges(other.layer_height_ranges),
|
||||
origin_translation(other.origin_translation),
|
||||
_bounding_box(other._bounding_box),
|
||||
_bounding_box_valid(other._bounding_box_valid)
|
||||
{
|
||||
volumes.reserve(other.volumes.size());
|
||||
instances.reserve(other.instances.size());
|
||||
|
||||
for (ModelVolumePtrs::const_iterator i = other.volumes.begin();
|
||||
i != other.volumes.end(); ++i)
|
||||
{
|
||||
ModelVolume *v = new ModelVolume(**i);
|
||||
v->object = this;
|
||||
volumes.push_back(v);
|
||||
|
||||
}
|
||||
|
||||
for (ModelInstancePtrs::const_iterator i = other.instances.begin();
|
||||
i != other.instances.end(); ++i)
|
||||
{
|
||||
ModelInstance *in = new ModelInstance(**i);
|
||||
in->object = this;
|
||||
instances.push_back(in);
|
||||
}
|
||||
}
|
||||
|
||||
ModelObject::~ModelObject()
|
||||
{
|
||||
this->clear_volumes();
|
||||
this->clear_instances();
|
||||
}
|
||||
|
||||
ModelVolume *
|
||||
ModelObject::add_volume(const t_model_material_id &material_id,
|
||||
const TriangleMesh &mesh, bool modifier)
|
||||
{
|
||||
ModelVolume *v = new ModelVolume(this, material_id, mesh, modifier);
|
||||
this->volumes.push_back(v);
|
||||
this->invalidate_bounding_box();
|
||||
return v;
|
||||
}
|
||||
|
||||
void
|
||||
ModelObject::delete_volume(size_t idx)
|
||||
{
|
||||
ModelVolumePtrs::iterator i = this->volumes.begin() + idx;
|
||||
delete *i;
|
||||
this->volumes.erase(i);
|
||||
this->invalidate_bounding_box();
|
||||
}
|
||||
|
||||
void
|
||||
ModelObject::clear_volumes()
|
||||
{
|
||||
for (size_t i = this->volumes.size()-1; i >= 0; --i)
|
||||
this->delete_volume(i);
|
||||
}
|
||||
|
||||
ModelInstance *
|
||||
ModelObject::add_instance(double rotation, double scaling_factor,
|
||||
Pointf offset)
|
||||
{
|
||||
ModelInstance *i = new ModelInstance(
|
||||
this, rotation, scaling_factor, offset);
|
||||
this->instances.push_back(i);
|
||||
this->invalidate_bounding_box();
|
||||
return i;
|
||||
}
|
||||
|
||||
void
|
||||
ModelObject::delete_instance(size_t idx)
|
||||
{
|
||||
ModelInstancePtrs::iterator i = this->instances.begin() + idx;
|
||||
delete *i;
|
||||
this->instances.erase(i);
|
||||
this->invalidate_bounding_box();
|
||||
}
|
||||
|
||||
void
|
||||
ModelObject::delete_last_instance()
|
||||
{
|
||||
this->delete_instance(this->instances.size() - 1);
|
||||
}
|
||||
|
||||
void
|
||||
ModelObject::clear_instances()
|
||||
{
|
||||
for (size_t i = 0; i < this->instances.size(); ++i)
|
||||
this->delete_instance(i);
|
||||
}
|
||||
|
||||
void
|
||||
ModelObject::invalidate_bounding_box()
|
||||
{
|
||||
this->_bounding_box_valid = false;
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
REGISTER_CLASS(ModelObject, "Model::Object");
|
||||
|
||||
SV*
|
||||
ModelObject::to_SV_ref() {
|
||||
SV* sv = newSV(0);
|
||||
sv_setref_pv( sv, perl_class_name_ref(this), this );
|
||||
return sv;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
ModelVolume::ModelVolume(ModelObject* object, const t_model_material_id &material_id,
|
||||
const TriangleMesh &mesh, bool modifier)
|
||||
: object(object),
|
||||
material_id(material_id),
|
||||
mesh(mesh),
|
||||
modifier(modifier)
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
REGISTER_CLASS(ModelVolume, "Model::Volume");
|
||||
|
||||
SV*
|
||||
ModelVolume::to_SV_ref() {
|
||||
SV* sv = newSV(0);
|
||||
sv_setref_pv( sv, perl_class_name_ref(this), this );
|
||||
return sv;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
ModelInstance::ModelInstance(ModelObject *object, double rotation,
|
||||
double scaling_factor, const Pointf &offset)
|
||||
: object(object),
|
||||
rotation(rotation),
|
||||
scaling_factor(scaling_factor),
|
||||
offset(offset)
|
||||
{
|
||||
}
|
||||
|
||||
ModelInstance::~ModelInstance()
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
REGISTER_CLASS(ModelInstance, "Model::Instance");
|
||||
|
||||
SV*
|
||||
ModelInstance::to_SV_ref() {
|
||||
SV* sv = newSV(0);
|
||||
sv_setref_pv( sv, perl_class_name_ref(this), this );
|
||||
return sv;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
104
xs/src/Model.hpp
104
xs/src/Model.hpp
@ -2,7 +2,7 @@
|
||||
#define slic3r_Model_hpp_
|
||||
|
||||
#include <myinit.h>
|
||||
#include "Config.hpp"
|
||||
#include "PrintConfig.hpp"
|
||||
#include "Layer.hpp"
|
||||
#include "Point.hpp"
|
||||
#include "TriangleMesh.hpp"
|
||||
@ -22,30 +22,40 @@ typedef std::string t_model_material_id;
|
||||
typedef std::string t_model_material_attribute;
|
||||
typedef std::map<t_model_material_attribute,std::string> t_model_material_attributes;
|
||||
|
||||
typedef std::map<t_model_material_id,ModelMaterial*> ModelMaterialMap;
|
||||
typedef std::vector<ModelObject*> ModelObjectPtrs;
|
||||
typedef std::vector<ModelVolume*> ModelVolumePtrs;
|
||||
typedef std::vector<ModelInstance*> ModelInstancePtrs;
|
||||
|
||||
class Model
|
||||
{
|
||||
public:
|
||||
std::map<t_model_material_id,ModelMaterial*> materials;
|
||||
std::vector<ModelObject*> objects;
|
||||
ModelMaterialMap materials;
|
||||
ModelObjectPtrs objects;
|
||||
|
||||
Model();
|
||||
Model(const Model &other);
|
||||
~Model();
|
||||
ModelObject* add_object(const ModelObject &object);
|
||||
void delete_object(size_t obj_idx);
|
||||
void delete_all_objects();
|
||||
void set_material(t_model_material_id material_id, const t_model_material_attributes &attributes);
|
||||
void duplicate_objects_grid(coordf_t x, coordf_t y, coordf_t distance);
|
||||
void duplicate_objects(size_t copies_num, coordf_t distance, const BoundingBox &bb);
|
||||
void arrange_objects(coordf_t distance, const BoundingBox &bb);
|
||||
void duplicate(size_t copies_num, coordf_t distance, const BoundingBox &bb);
|
||||
ModelObject* add_object(const std::string &input_file, const DynamicPrintConfig &config,
|
||||
const t_layer_height_ranges &layer_height_ranges, const Pointf &origin_translation);
|
||||
void delete_object(size_t idx);
|
||||
void clear_objects();
|
||||
void delete_material(t_model_material_id material_id);
|
||||
void clear_materials();
|
||||
ModelMaterial *set_material(t_model_material_id material_id);
|
||||
// void duplicate_objects_grid(unsigned int x, unsigned int y, coordf_t distance);
|
||||
// void duplicate_objects(size_t copies_num, coordf_t distance, const BoundingBox &bb);
|
||||
// void arrange_objects(coordf_t distance, const BoundingBox &bb);
|
||||
// void duplicate(size_t copies_num, coordf_t distance, const BoundingBox &bb);
|
||||
bool has_objects_with_no_instances() const;
|
||||
void bounding_box(BoundingBox* bb) const;
|
||||
void align_to_origin();
|
||||
void center_instances_around_point(const Pointf &point);
|
||||
void translate(coordf_t x, coordf_t y, coordf_t z);
|
||||
void mesh(TriangleMesh* mesh) const;
|
||||
void split_meshes();
|
||||
std::string get_material_name(t_model_material_id material_id);
|
||||
// void bounding_box(BoundingBox* bb) const;
|
||||
// void align_to_origin();
|
||||
// void center_instances_around_point(const Pointf &point);
|
||||
// void translate(coordf_t x, coordf_t y, coordf_t z);
|
||||
// void mesh(TriangleMesh* mesh) const;
|
||||
// void split_meshes();
|
||||
// std::string get_material_name(t_model_material_id material_id);
|
||||
|
||||
|
||||
private:
|
||||
void _arrange(const std::vector<Size> &sizes, coordf_t distance, const BoundingBox &bb) const;
|
||||
@ -56,7 +66,10 @@ class ModelMaterial
|
||||
public:
|
||||
Model* model;
|
||||
t_model_material_attributes attributes;
|
||||
DynamicConfig config;
|
||||
DynamicPrintConfig config;
|
||||
|
||||
ModelMaterial(Model *model);
|
||||
void apply(const t_model_material_attributes &attributes);
|
||||
};
|
||||
|
||||
class ModelObject
|
||||
@ -64,16 +77,32 @@ class ModelObject
|
||||
public:
|
||||
Model* model;
|
||||
std::string input_file;
|
||||
std::vector<ModelInstance*> instances;
|
||||
std::vector<ModelVolume*> volumes;
|
||||
DynamicConfig config;
|
||||
ModelInstancePtrs instances;
|
||||
ModelVolumePtrs volumes;
|
||||
DynamicPrintConfig config;
|
||||
t_layer_height_ranges layer_height_ranges;
|
||||
Pointf origin_translation;
|
||||
BoundingBoxf3 _bounding_box;
|
||||
bool _bounding_box_valid;
|
||||
|
||||
ModelObject();
|
||||
ModelObject(Model *model, const std::string &input_file, const DynamicPrintConfig &config,
|
||||
const t_layer_height_ranges &layer_height_ranges, const Pointf &origin_translation);
|
||||
ModelObject(const ModelObject &other);
|
||||
~ModelObject();
|
||||
ModelInstance* add_instance(const ModelInstance &instance);
|
||||
ModelVolume* add_volume(const ModelVolume &volume);
|
||||
|
||||
ModelVolume* add_volume(const t_model_material_id &material_id,
|
||||
const TriangleMesh &mesh, bool modifier);
|
||||
void delete_volume(size_t idx);
|
||||
void clear_volumes();
|
||||
|
||||
ModelInstance *add_instance(double rotation=0, double scaling_factor = 1,
|
||||
Pointf offset = Pointf(0, 0));
|
||||
void delete_instance(size_t idx);
|
||||
void delete_last_instance();
|
||||
void clear_instances();
|
||||
|
||||
void invalidate_bounding_box();
|
||||
|
||||
void raw_mesh(TriangleMesh* mesh) const;
|
||||
void mesh(TriangleMesh* mesh) const;
|
||||
void instance_bounding_box(size_t instance_idx, BoundingBox* bb) const;
|
||||
@ -84,8 +113,11 @@ class ModelObject
|
||||
size_t facets_count() const;
|
||||
bool needed_repair() const;
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
SV* to_SV_ref();
|
||||
#endif
|
||||
|
||||
private:
|
||||
BoundingBox bb;
|
||||
void update_bounding_box();
|
||||
};
|
||||
|
||||
@ -95,18 +127,34 @@ class ModelVolume
|
||||
ModelObject* object;
|
||||
t_model_material_id material_id;
|
||||
TriangleMesh mesh;
|
||||
bool modifier;
|
||||
|
||||
ModelVolume(ModelObject *object, const t_model_material_id &material_id,
|
||||
const TriangleMesh &mesh, bool modifier);
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
SV* to_SV_ref();
|
||||
#endif
|
||||
};
|
||||
|
||||
class ModelInstance
|
||||
{
|
||||
public:
|
||||
ModelObject* object;
|
||||
double rotation;
|
||||
double rotation; // around mesh center point
|
||||
double scaling_factor;
|
||||
Pointf offset;
|
||||
Pointf offset; // in unscaled coordinates
|
||||
|
||||
ModelInstance(ModelObject *object, double rotation, double scaling_factor,
|
||||
const Pointf &offset);
|
||||
~ModelInstance();
|
||||
|
||||
void transform_mesh(TriangleMesh* mesh, bool dont_translate) const;
|
||||
void transform_polygon(Polygon* polygon) const;
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
SV* to_SV_ref();
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -9,11 +9,16 @@ struct ClassTraits {
|
||||
static const char* name_ref;
|
||||
};
|
||||
|
||||
#define REGISTER_CLASS(cname,perlname) \
|
||||
class cname; \
|
||||
// use this for typedefs for which the forward prototype
|
||||
// in REGISTER_CLASS won't work
|
||||
#define __REGISTER_CLASS(cname, perlname) \
|
||||
template <>const char* ClassTraits<cname>::name = "Slic3r::" perlname; \
|
||||
template <>const char* ClassTraits<cname>::name_ref = "Slic3r::" perlname "::Ref";
|
||||
|
||||
#define REGISTER_CLASS(cname,perlname) \
|
||||
class cname; \
|
||||
__REGISTER_CLASS(cname, perlname);
|
||||
|
||||
template<class T>
|
||||
const char* perl_class_name(const T*) { return ClassTraits<T>::name; }
|
||||
template<class T>
|
||||
|
233
xs/xsp/Model.xsp
Normal file
233
xs/xsp/Model.xsp
Normal file
@ -0,0 +1,233 @@
|
||||
%module{Slic3r::XS};
|
||||
|
||||
%{
|
||||
#include <myinit.h>
|
||||
#include "Model.hpp"
|
||||
#include "PrintConfig.hpp"
|
||||
#include "perlglue.hpp"
|
||||
%}
|
||||
|
||||
%name{Slic3r::Model} class Model {
|
||||
Model();
|
||||
~Model();
|
||||
|
||||
Clone<Model> clone()
|
||||
%code%{ RETVAL = THIS; %};
|
||||
|
||||
Ref<ModelObject> _add_object(std::string input_file,
|
||||
DynamicPrintConfig* config,
|
||||
t_layer_height_ranges layer_height_ranges,
|
||||
Pointf* origin_translation)
|
||||
%code%{
|
||||
RETVAL = THIS->add_object(input_file, *config, layer_height_ranges,
|
||||
*origin_translation);
|
||||
%};
|
||||
|
||||
void delete_object(size_t idx);
|
||||
void clear_objects();
|
||||
void delete_material(t_model_material_id material_id);
|
||||
void clear_materials();
|
||||
|
||||
%name{_set_material} Ref<ModelMaterial> set_material(t_model_material_id material_id)
|
||||
%code%{ RETVAL = THIS->set_material(material_id); %};
|
||||
|
||||
Ref<ModelMaterial> get_material(t_model_material_id material_id)
|
||||
%code%{
|
||||
ModelMaterialMap::iterator i = THIS->materials.find(material_id);
|
||||
if (i == THIS->materials.end()) {
|
||||
XSRETURN_UNDEF;
|
||||
}
|
||||
|
||||
RETVAL = i->second;
|
||||
%};
|
||||
|
||||
bool has_material(t_model_material_id material_id) const
|
||||
%code%{
|
||||
RETVAL = (THIS->materials.find(material_id) != THIS->materials.end());
|
||||
%};
|
||||
|
||||
std::vector<std::string> material_names() const
|
||||
%code%{
|
||||
for (ModelMaterialMap::iterator i = THIS->materials.begin();
|
||||
i != THIS->materials.end(); ++i)
|
||||
{
|
||||
RETVAL.push_back(i->first);
|
||||
}
|
||||
%};
|
||||
|
||||
size_t material_count() const
|
||||
%code%{ RETVAL = THIS->materials.size(); %};
|
||||
|
||||
// void duplicate_objects_grid(coordf_t x, coordf_t y, coordf_t distance);
|
||||
// void duplicate_objects(size_t copies_num, coordf_t distance, const BoundingBox &bb);
|
||||
// void arrange_objects(coordf_t distance, const BoundingBox &bb);
|
||||
// void duplicate(size_t copies_num, coordf_t distance, const BoundingBox &bb);
|
||||
bool has_objects_with_no_instances() const;
|
||||
// void bounding_box(BoundingBox* bb) const;
|
||||
// void center_instances_around_point(const Pointf &point);
|
||||
// void align_instances_to_origin();
|
||||
// void translate(coordf_t x, coordf_t y, coordf_t z);
|
||||
// void mesh(TriangleMesh* mesh) const;
|
||||
// void split_meshes();
|
||||
// std::string get_material_name(t_model_material_id material_id);
|
||||
|
||||
ModelObjectPtrs *objects()
|
||||
%code%{
|
||||
if (THIS->objects.empty()) {
|
||||
XSRETURN_UNDEF;
|
||||
}
|
||||
|
||||
RETVAL = &THIS->objects;
|
||||
%};
|
||||
};
|
||||
|
||||
|
||||
%name{Slic3r::Model::Material} class ModelMaterial {
|
||||
~ModelMaterial();
|
||||
|
||||
Ref<Model> model()
|
||||
%code%{ RETVAL = THIS->model; %};
|
||||
|
||||
Ref<DynamicPrintConfig> config()
|
||||
%code%{ RETVAL = &THIS->config; %};
|
||||
|
||||
std::string get_attribute(std::string name)
|
||||
%code%{ if (THIS->attributes.find(name) != THIS->attributes.end()) RETVAL = THIS->attributes[name]; %};
|
||||
|
||||
void set_attribute(std::string name, std::string value)
|
||||
%code%{ THIS->attributes[name] = value; %};
|
||||
|
||||
%{
|
||||
|
||||
SV*
|
||||
ModelMaterial::attributes()
|
||||
CODE:
|
||||
HV* hv = newHV();
|
||||
for (t_model_material_attributes::const_iterator attr = THIS->attributes.begin(); attr != THIS->attributes.end(); ++attr) {
|
||||
(void)hv_store( hv, attr->first.c_str(), attr->first.length(), newSVpv(attr->second.c_str(), attr->second.length()), 0 );
|
||||
}
|
||||
RETVAL = (SV*)newRV_noinc((SV*)hv);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
%}
|
||||
|
||||
};
|
||||
|
||||
|
||||
%name{Slic3r::Model::Object} class ModelObject {
|
||||
ModelObject(Model* model, std::string input_file,
|
||||
DynamicPrintConfig* config, t_layer_height_ranges layer_height_ranges,
|
||||
Pointf* origin_translation)
|
||||
%code%{
|
||||
RETVAL = new ModelObject(model, input_file, *config,
|
||||
layer_height_ranges, *origin_translation);
|
||||
%};
|
||||
|
||||
~ModelObject();
|
||||
|
||||
ModelVolumePtrs *volumes()
|
||||
%code%{
|
||||
if (THIS->volumes.empty()) {
|
||||
XSRETURN_UNDEF;
|
||||
}
|
||||
|
||||
RETVAL = &THIS->volumes;
|
||||
%};
|
||||
|
||||
ModelInstancePtrs *instances()
|
||||
%code%{
|
||||
if (THIS->instances.empty()) {
|
||||
XSRETURN_UNDEF;
|
||||
}
|
||||
|
||||
RETVAL = &THIS->instances;
|
||||
%};
|
||||
|
||||
|
||||
void invalidate_bounding_box();
|
||||
|
||||
Ref<BoundingBoxf3> _bounding_box(BoundingBoxf3 *new_bbox = NULL)
|
||||
%code{%
|
||||
if (NULL != new_bbox) {
|
||||
THIS->_bounding_box = *new_bbox;
|
||||
THIS->_bounding_box_valid = true;
|
||||
}
|
||||
|
||||
if (!THIS->_bounding_box_valid) {
|
||||
XSRETURN_UNDEF;
|
||||
}
|
||||
|
||||
RETVAL = &THIS->_bounding_box;
|
||||
%};
|
||||
|
||||
%name{_add_volume} Ref<ModelVolume> add_volume(
|
||||
t_model_material_id material_id, TriangleMesh* mesh, bool modifier)
|
||||
%code%{ RETVAL = THIS->add_volume(material_id, *mesh, modifier); %};
|
||||
|
||||
void delete_volume(size_t idx);
|
||||
void clear_volumes();
|
||||
|
||||
%name{_add_instance} Ref<ModelInstance> add_instance(
|
||||
double rotation, double scaling_factor, std::vector<double> offset)
|
||||
%code%{
|
||||
RETVAL = THIS->add_instance(rotation, scaling_factor,
|
||||
Pointf(offset[0], offset[1]));
|
||||
%};
|
||||
void delete_last_instance();
|
||||
void clear_instances();
|
||||
|
||||
std::string input_file()
|
||||
%code%{ RETVAL = THIS->input_file; %};
|
||||
void set_input_file(std::string value)
|
||||
%code%{ THIS->input_file = value; %};
|
||||
Ref<DynamicPrintConfig> config()
|
||||
%code%{ RETVAL = &THIS->config; %};
|
||||
|
||||
Ref<Model> model()
|
||||
%code%{ RETVAL = THIS->model; %};
|
||||
|
||||
t_layer_height_ranges layer_height_ranges()
|
||||
%code%{ RETVAL = THIS->layer_height_ranges; %};
|
||||
|
||||
Clone<Pointf> origin_translation()
|
||||
%code%{ RETVAL = THIS->origin_translation; %};
|
||||
};
|
||||
|
||||
|
||||
%name{Slic3r::Model::Volume} class ModelVolume {
|
||||
~ModelVolume();
|
||||
|
||||
Ref<ModelObject> object()
|
||||
%code%{ RETVAL = THIS->object; %};
|
||||
|
||||
t_model_material_id material_id()
|
||||
%code%{ RETVAL = THIS->material_id; %};
|
||||
|
||||
Ref<TriangleMesh> mesh()
|
||||
%code%{ RETVAL = &THIS->mesh; %};
|
||||
|
||||
bool modifier()
|
||||
%code%{ RETVAL = THIS->modifier; %};
|
||||
};
|
||||
|
||||
|
||||
%name{Slic3r::Model::Instance} class ModelInstance {
|
||||
~ModelInstance();
|
||||
|
||||
Ref<ModelObject> object()
|
||||
%code%{ RETVAL = THIS->object; %};
|
||||
|
||||
double rotation()
|
||||
%code%{ RETVAL = THIS->rotation; %};
|
||||
double scaling_factor()
|
||||
%code%{ RETVAL = THIS->scaling_factor; %};
|
||||
Clone<Pointf> offset()
|
||||
%code%{ RETVAL = THIS->offset; %};
|
||||
|
||||
void set_rotation(double val)
|
||||
%code%{ THIS->rotation = val; %};
|
||||
void set_scaling_factor(double val)
|
||||
%code%{ THIS->scaling_factor = val; %};
|
||||
void set_offset(Pointf *offset)
|
||||
%code%{ THIS->offset = *offset; %};
|
||||
};
|
116
xs/xsp/my.map
116
xs/xsp/my.map
@ -1,6 +1,12 @@
|
||||
coordf_t T_NV
|
||||
|
||||
std::vector<Points::size_type> T_STD_VECTOR_INT
|
||||
std::vector<size_t> T_STD_VECTOR_INT
|
||||
|
||||
t_config_option_key T_STD_STRING
|
||||
t_model_material_id T_STD_STRING
|
||||
t_layer_height_ranges T_LAYER_HEIGHT_RANGES
|
||||
|
||||
|
||||
BoundingBox* O_OBJECT_SLIC3R
|
||||
Ref<BoundingBox> O_OBJECT_SLIC3R_T
|
||||
@ -11,6 +17,7 @@ Ref<BoundingBoxf3> O_OBJECT_SLIC3R_T
|
||||
Clone<BoundingBoxf3> O_OBJECT_SLIC3R_T
|
||||
|
||||
DynamicPrintConfig* O_OBJECT_SLIC3R
|
||||
Ref<DynamicPrintConfig> O_OBJECT_SLIC3R_T
|
||||
PrintObjectConfig* O_OBJECT_SLIC3R
|
||||
PrintRegionConfig* O_OBJECT_SLIC3R
|
||||
PrintConfig* O_OBJECT_SLIC3R
|
||||
@ -83,6 +90,27 @@ SurfaceCollection* O_OBJECT_SLIC3R
|
||||
|
||||
Extruder* O_OBJECT_SLIC3R
|
||||
|
||||
Model* O_OBJECT_SLIC3R
|
||||
Ref<Model> O_OBJECT_SLIC3R_T
|
||||
Clone<Model> O_OBJECT_SLIC3R_T
|
||||
|
||||
ModelMaterial* O_OBJECT_SLIC3R
|
||||
Ref<ModelMaterial> O_OBJECT_SLIC3R_T
|
||||
Clone<ModelMaterial> O_OBJECT_SLIC3R_T
|
||||
|
||||
ModelObject* O_OBJECT_SLIC3R
|
||||
Ref<ModelObject> O_OBJECT_SLIC3R_T
|
||||
Clone<ModelObject> O_OBJECT_SLIC3R_T
|
||||
|
||||
ModelVolume* O_OBJECT_SLIC3R
|
||||
Ref<ModelVolume> O_OBJECT_SLIC3R_T
|
||||
Clone<ModelVolume> O_OBJECT_SLIC3R_T
|
||||
|
||||
ModelInstance* O_OBJECT_SLIC3R
|
||||
Ref<ModelInstance> O_OBJECT_SLIC3R_T
|
||||
Clone<ModelInstance> O_OBJECT_SLIC3R_T
|
||||
|
||||
|
||||
ExtrusionRole T_UV
|
||||
FlowRole T_UV
|
||||
PrintStep T_UV
|
||||
@ -104,12 +132,16 @@ Surfaces T_ARRAYREF
|
||||
# by reference and marked ::Ref because they're contained in another
|
||||
# Perl object
|
||||
Polygons* T_ARRAYREF_PTR
|
||||
ModelObjectPtrs* T_PTR_ARRAYREF_PTR
|
||||
ModelVolumePtrs* T_PTR_ARRAYREF_PTR
|
||||
ModelInstancePtrs* T_PTR_ARRAYREF_PTR
|
||||
|
||||
# we return these types whenever we want the items to be returned
|
||||
# by reference and not marked ::Ref because they're newly allocated
|
||||
# and not referenced by any Perl object
|
||||
TriangleMeshPtrs T_PTR_ARRAYREF
|
||||
|
||||
|
||||
INPUT
|
||||
|
||||
O_OBJECT_SLIC3R
|
||||
@ -141,6 +173,53 @@ T_ARRAYREF
|
||||
${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
|
||||
\"$var\");
|
||||
|
||||
T_LAYER_HEIGHT_RANGES
|
||||
{
|
||||
if (!SvROK($arg) || SvTYPE(SvRV($arg)) != SVt_PVAV) {
|
||||
Perl_croak(aTHX_ \"%s: %s is not an array reference\",
|
||||
${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
|
||||
\"$var\");
|
||||
}
|
||||
|
||||
AV* av = (AV*)SvRV($arg);
|
||||
const unsigned int len = av_len(av)+1;
|
||||
t_layer_height_ranges tmp_ranges;
|
||||
for (unsigned int i = 0; i < len; i++) {
|
||||
SV* elem = *av_fetch(av, i, 0);
|
||||
if (!SvROK(elem) || SvTYPE(SvRV(elem)) != SVt_PVAV) {
|
||||
Perl_croak(
|
||||
aTHX_ \"%s: %s contains something that is not an array reference\",
|
||||
${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
|
||||
\"$var\");
|
||||
}
|
||||
|
||||
AV* elemAV = (AV*)SvRV(elem);
|
||||
if (av_len(elemAV) + 1 != 3) {
|
||||
Perl_croak(
|
||||
aTHX_ \"%s: %s contains an array that isn't 3 elements long\",
|
||||
${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
|
||||
\"$var\");
|
||||
}
|
||||
|
||||
coordf_t vals[3];
|
||||
for (unsigned int j = 0; j < 3; ++j) {
|
||||
SV *elem_elem = *av_fetch(elemAV, j, 0);
|
||||
if (!SvNOK(elem_elem)) {
|
||||
Perl_croak(
|
||||
aTHX_ \"%s: layer ranges and heights must be numbers\",
|
||||
${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]});
|
||||
}
|
||||
|
||||
vals[j] = SvNV(elem_elem);
|
||||
}
|
||||
|
||||
tmp_ranges[t_layer_height_range(vals[0], vals[1])] = vals[2];
|
||||
}
|
||||
|
||||
$var = tmp_ranges;
|
||||
}
|
||||
|
||||
|
||||
OUTPUT
|
||||
# return object from pointer
|
||||
O_OBJECT_SLIC3R
|
||||
@ -172,6 +251,16 @@ T_ARRAYREF_PTR
|
||||
av_store(av, i++, it->to_SV_ref());
|
||||
}
|
||||
|
||||
T_PTR_ARRAYREF_PTR
|
||||
AV* av = newAV();
|
||||
$arg = newRV_noinc((SV*)av);
|
||||
sv_2mortal($arg);
|
||||
av_extend(av, $var->size()-1);
|
||||
int i = 0;
|
||||
for (${ my $t = $type; $t =~ s/\*$//; \$t }::iterator it = $var->begin(); it != $var->end(); ++it) {
|
||||
av_store(av, i++, (*it)->to_SV_ref());
|
||||
}
|
||||
|
||||
T_PTR_ARRAYREF
|
||||
AV* av = newAV();
|
||||
$arg = newRV_noinc((SV*)av);
|
||||
@ -181,3 +270,30 @@ T_PTR_ARRAYREF
|
||||
for (${type}::iterator it = $var.begin(); it != $var.end(); ++it) {
|
||||
av_store(av, i++, (*it)->to_SV());
|
||||
}
|
||||
|
||||
T_LAYER_HEIGHT_RANGES
|
||||
AV* av = newAV();
|
||||
$arg = newRV_noinc((SV*)av);
|
||||
sv_2mortal($arg);
|
||||
av_extend(av, $var.size() - 1);
|
||||
// map is sorted, so we can just copy it in order
|
||||
int i = 0;
|
||||
for (${type}::iterator it = $var.begin(); it != $var.end(); ++it) {
|
||||
const coordf_t range_values[] = {
|
||||
it->first.first, // key's first = minz
|
||||
it->first.second, // key's second = maxz
|
||||
it->second, // value = height
|
||||
};
|
||||
|
||||
AV *rangeAV = newAV();
|
||||
SV *rangeAV_ref = newRV_noinc((SV*)rangeAV);
|
||||
sv_2mortal(rangeAV_ref);
|
||||
av_extend(rangeAV, 2);
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
SV *val = sv_newmortal();
|
||||
sv_setnv(val, range_values[j]);
|
||||
av_store(rangeAV, j, val);
|
||||
}
|
||||
|
||||
av_store(av, i++, (SV*)rangeAV_ref);
|
||||
}
|
||||
|
@ -1,12 +1,16 @@
|
||||
%typemap{bool}{simple};
|
||||
%typemap{size_t}{simple};
|
||||
%typemap{coordf_t}{simple};
|
||||
%typemap{std::string};
|
||||
%typemap{t_config_option_key};
|
||||
%typemap{t_model_material_id};
|
||||
%typemap{std::vector<int>};
|
||||
%typemap{std::vector<size_t>};
|
||||
%typemap{std::vector<unsigned int>*};
|
||||
%typemap{std::vector<double>};
|
||||
%typemap{std::vector<double>*};
|
||||
%typemap{std::vector<std::string>};
|
||||
%typemap{t_layer_height_ranges};
|
||||
%typemap{SV*};
|
||||
%typemap{AV*};
|
||||
%typemap{Point*};
|
||||
@ -25,6 +29,7 @@
|
||||
%typemap{Ref<BoundingBoxf3>}{simple};
|
||||
%typemap{Clone<BoundingBoxf3>}{simple};
|
||||
%typemap{DynamicPrintConfig*};
|
||||
%typemap{Ref<DynamicPrintConfig>}{simple};
|
||||
%typemap{PrintObjectConfig*};
|
||||
%typemap{PrintRegionConfig*};
|
||||
%typemap{PrintConfig*};
|
||||
@ -73,8 +78,33 @@
|
||||
%typemap{ExtrusionPaths};
|
||||
%typemap{Surfaces};
|
||||
%typemap{Polygons*};
|
||||
%typemap{TriangleMesh*};
|
||||
%typemap{TriangleMeshPtrs};
|
||||
%typemap{Extruder*};
|
||||
%typemap{Model*};
|
||||
%typemap{Ref<Model>}{simple};
|
||||
%typemap{Clone<Model>}{simple};
|
||||
%typemap{ModelMaterial*};
|
||||
%typemap{Ref<ModelMaterial>}{simple};
|
||||
%typemap{Clone<ModelMaterial>}{simple};
|
||||
%typemap{ModelObject*};
|
||||
%typemap{Ref<ModelObject>}{simple};
|
||||
%typemap{Clone<ModelObject>}{simple};
|
||||
%typemap{ModelObjectPtrs*};
|
||||
%typemap{Ref<ModelObjectPtrs>}{simple};
|
||||
%typemap{Clone<ModelObjectPtrs>}{simple};
|
||||
%typemap{ModelVolume*};
|
||||
%typemap{Ref<ModelVolume>}{simple};
|
||||
%typemap{Clone<ModelVolume>}{simple};
|
||||
%typemap{ModelVolumePtrs*};
|
||||
%typemap{Ref<ModelVolumePtrs>}{simple};
|
||||
%typemap{Clone<ModelVolumePtrs>}{simple};
|
||||
%typemap{ModelInstance*};
|
||||
%typemap{Ref<ModelInstance>}{simple};
|
||||
%typemap{Clone<ModelInstance>}{simple};
|
||||
%typemap{ModelInstancePtrs*};
|
||||
%typemap{Ref<ModelInstancePtrs>}{simple};
|
||||
%typemap{Clone<ModelInstancePtrs>}{simple};
|
||||
|
||||
%typemap{SurfaceType}{parsed}{
|
||||
%cpp_type{SurfaceType};
|
||||
|
Loading…
Reference in New Issue
Block a user