diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index 8a409c045..6edd32609 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -76,46 +76,20 @@ Print::get_object(size_t idx) return objects.at(idx); } -PrintObject* -Print::add_object(ModelObject *model_object, const BoundingBoxf3 &modobj_bbox) -{ - PrintObject *object = new PrintObject(this, model_object, modobj_bbox); - objects.push_back(object); - - // invalidate steps - this->invalidate_step(psSkirt); - this->invalidate_step(psBrim); - - return object; -} - -PrintObject* -Print::set_new_object(size_t idx, ModelObject *model_object, const BoundingBoxf3 &modobj_bbox) -{ - if (idx >= this->objects.size()) throw "bad idx"; - - PrintObjectPtrs::iterator old_it = this->objects.begin() + idx; - // before deleting object, invalidate all of its steps in order to - // invalidate all of the dependent ones in Print - (*old_it)->invalidate_all_steps(); - delete *old_it; - - PrintObject *object = new PrintObject(this, model_object, modobj_bbox); - this->objects[idx] = object; - return object; -} - void Print::delete_object(size_t idx) { PrintObjectPtrs::iterator i = this->objects.begin() + idx; + + // before deleting object, invalidate all of its steps in order to + // invalidate all of the dependent ones in Print + (*i)->invalidate_all_steps(); + + // destroy object and remove it from our container delete *i; this->objects.erase(i); // TODO: purge unused regions - - this->state.invalidate(psSkirt); - this->state.invalidate(psBrim); } void @@ -375,9 +349,23 @@ Print::add_model_object(ModelObject* model_object, int idx) { BoundingBoxf3 bb; model_object->raw_bounding_box(&bb); - o = (idx != -1) - ? this->set_new_object(idx, model_object, bb) - : this->add_object(model_object, bb); + if (idx != -1) { + // replacing existing object + PrintObjectPtrs::iterator old_it = this->objects.begin() + idx; + // before deleting object, invalidate all of its steps in order to + // invalidate all of the dependent ones in Print + (*old_it)->invalidate_all_steps(); + delete *old_it; + + this->objects[idx] = o = new PrintObject(this, model_object, bb); + } else { + o = new PrintObject(this, model_object, bb); + objects.push_back(o); + + // invalidate steps + this->invalidate_step(psSkirt); + this->invalidate_step(psBrim); + } } for (ModelVolumePtrs::const_iterator v_i = model_object->volumes.begin(); v_i != model_object->volumes.end(); ++v_i) { diff --git a/xs/src/libslic3r/Print.hpp b/xs/src/libslic3r/Print.hpp index 45e1eb25c..fd0e6a19d 100644 --- a/xs/src/libslic3r/Print.hpp +++ b/xs/src/libslic3r/Print.hpp @@ -168,8 +168,6 @@ class Print // methods for handling objects void clear_objects(); PrintObject* get_object(size_t idx); - 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); diff --git a/xs/xsp/Print.xsp b/xs/xsp/Print.xsp index 7ed3d6853..aed6f6e4e 100644 --- a/xs/xsp/Print.xsp +++ b/xs/xsp/Print.xsp @@ -139,12 +139,6 @@ _constant() %code%{ RETVAL = &THIS->objects; %}; void clear_objects(); Ref get_object(int idx); - Ref add_object(ModelObject* model_object, - BoundingBoxf3 *modobj_bbox) - %code%{ RETVAL = THIS->add_object(model_object, *modobj_bbox); %}; - Ref set_new_object(size_t idx, ModelObject* model_object, - 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()