From d645dabcffcab408f5e1cd9923b87be0cae58e69 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 7 Nov 2014 20:25:05 +0100 Subject: [PATCH] Ported reload_object() to XS --- lib/Slic3r/Print.pm | 14 -------------- xs/src/libslic3r/Print.cpp | 24 ++++++++++++++++++++++++ xs/src/libslic3r/Print.hpp | 1 + xs/xsp/Print.xsp | 1 + 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 443a36715..9121faf17 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -217,20 +217,6 @@ sub add_model_object { $o->config->apply_dynamic($object_config); } -sub reload_object { - my ($self, $obj_idx) = @_; - - # TODO: this method should check whether the per-object config and per-material configs - # have changed in such a way that regions need to be rearranged or we can just apply - # the diff and invalidate something. Same logic as apply_config() - # 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 @models_objects = map $_->model_object, @{$self->objects}; - $self->clear_objects; - $self->add_model_object($_) for @models_objects; -} - sub validate { my $self = shift; diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index d0ec15cb5..b44662dca 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -114,6 +114,30 @@ Print::delete_object(size_t idx) this->state.invalidate(psBrim); } +void +Print::reload_object(size_t idx) +{ + /* TODO: this method should check whether the per-object config and per-material configs + have changed in such a way that regions need to be rearranged or we can just apply + the diff and invalidate something. Same logic as apply_config() + 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. */ + + // collect all current model objects + ModelObjectPtrs model_objects; + for (PrintObjectPtrs::iterator it = this->objects.begin(); it != this->objects.end(); ++it) { + model_objects.push_back(it->model_object()); + } + + // remove our print objects + this->clear_object(); + + // re-add model objects + for (ModelObjectPtrs::iterator it = model_objects.begin(); it != model_objects.end(); ++it) { + this->add_model_object(*it); + } +} + void Print::clear_regions() { diff --git a/xs/src/libslic3r/Print.hpp b/xs/src/libslic3r/Print.hpp index 8b2a45044..5fc01c92d 100644 --- a/xs/src/libslic3r/Print.hpp +++ b/xs/src/libslic3r/Print.hpp @@ -154,6 +154,7 @@ class Print PrintObject* add_object(ModelObject *model_object, const BoundingBoxf3 &modobj_bbox); PrintObject* set_new_object(size_t idx, ModelObject *model_object, const BoundingBoxf3 &modobj_bbox); void delete_object(size_t idx); + void reload_object(size_t idx); // methods for handling regions PrintRegion* get_region(size_t idx); diff --git a/xs/xsp/Print.xsp b/xs/xsp/Print.xsp index 330bc6b9a..17cbdbd44 100644 --- a/xs/xsp/Print.xsp +++ b/xs/xsp/Print.xsp @@ -137,6 +137,7 @@ _constant() BoundingBoxf3 *modobj_bbox) %code%{ RETVAL = THIS->set_new_object(idx, model_object, *modobj_bbox); %}; void delete_object(int idx); + void reload_object(int idx); size_t object_count() %code%{ RETVAL = THIS->objects.size(); %};