From 33fe53fd7c4d735826fa52670c686f7cc0001357 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 13 Nov 2014 00:34:56 +0100 Subject: [PATCH] Ported three PrintObject methods to XS --- lib/Slic3r/GUI/Plater.pm | 2 +- lib/Slic3r/Print/Object.pm | 20 -------------------- xs/src/libslic3r/Print.hpp | 3 +++ xs/src/libslic3r/PrintObject.cpp | 23 +++++++++++++++++++++++ xs/xsp/Print.xsp | 4 ++++ 5 files changed, 31 insertions(+), 21 deletions(-) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 0900b782b..32645e338 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -571,7 +571,7 @@ sub increase { scaling_factor => $last_instance->scaling_factor, rotation => $last_instance->rotation, ); - $self->{print}->objects->[$obj_idx]->add_copy(@{$i->offset}); + $self->{print}->objects->[$obj_idx]->add_copy($i->offset); $self->{list}->SetItem($obj_idx, 1, $model_object->instances_count); # only autoarrange if user has autocentering enabled diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm index 24c07472e..ba03cc6a8 100644 --- a/lib/Slic3r/Print/Object.pm +++ b/lib/Slic3r/Print/Object.pm @@ -32,26 +32,6 @@ sub support_layers { return [ map $self->get_support_layer($_), 0..($self->support_layer_count - 1) ]; } -# in unscaled coordinates -sub add_copy { - my ($self, $x, $y) = @_; - my @copies = @{$self->copies}; - push @copies, Slic3r::Point->new_scale($x, $y); - return $self->set_copies(\@copies); -} - -sub delete_last_copy { - my ($self) = @_; - my @copies = $self->copies; - pop @copies; - return $self->set_copies(\@copies); -} - -sub delete_all_copies { - my ($self) = @_; - return $self->set_copies([]); -} - # this is the *total* layer count (including support layers) # this value is not supposed to be compared with $layer->id # since they have different semantics diff --git a/xs/src/libslic3r/Print.hpp b/xs/src/libslic3r/Print.hpp index 3e9702117..0c4d7c24f 100644 --- a/xs/src/libslic3r/Print.hpp +++ b/xs/src/libslic3r/Print.hpp @@ -103,6 +103,9 @@ class PrintObject ModelObject* model_object(); Points copies() const; + bool add_copy(const Pointf &point); + bool delete_last_copy(); + bool delete_all_copies(); bool set_copies(const Points &points); bool reload_model_instances(); diff --git a/xs/src/libslic3r/PrintObject.cpp b/xs/src/libslic3r/PrintObject.cpp index 868da0fd7..54ddea33d 100644 --- a/xs/src/libslic3r/PrintObject.cpp +++ b/xs/src/libslic3r/PrintObject.cpp @@ -53,6 +53,29 @@ PrintObject::copies() const return this->_copies; } +bool +PrintObject::add_copy(const Pointf &point) +{ + Points points = this->_copies; + points.push_back(Point::new_scale(point.x, point.y)); + return this->set_copies(points); +} + +bool +PrintObject::delete_last_copy() +{ + Points points = this->_copies; + points.pop_back(); + return this->set_copies(points); +} + +bool +PrintObject::delete_all_copies() +{ + Points points; + return this->set_copies(points); +} + bool PrintObject::set_copies(const Points &points) { diff --git a/xs/xsp/Print.xsp b/xs/xsp/Print.xsp index d18d689de..556e87396 100644 --- a/xs/xsp/Print.xsp +++ b/xs/xsp/Print.xsp @@ -74,6 +74,10 @@ _constant() void set_shifted_copies(Points value) %code%{ THIS->_shifted_copies = value; %}; + bool add_copy(Pointf* point) + %code%{ RETVAL = THIS->add_copy(*point); %}; + bool delete_last_copy(); + bool delete_all_copies(); bool set_copies(Points copies); bool reload_model_instances(); void set_layer_height_ranges(t_layer_height_ranges layer_height_ranges)