From 9993f2215d56d7dfdf727794b590756893a2ba39 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Tue, 10 Apr 2018 12:17:55 +0200 Subject: [PATCH] Auto assignement of extruder, after object's splitting to parts --- xs/src/libslic3r/Model.cpp | 40 +++++++++++++++++++++++++++++--------- xs/src/libslic3r/Model.hpp | 6 ++++++ 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index d49594c72..561106713 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -16,6 +16,8 @@ namespace Slic3r { + unsigned int Model::s_auto_extruder_id = 1; + Model::Model(const Model &other) { // copy materials @@ -405,9 +407,8 @@ void Model::convert_multipart_object() ModelObject* object = new ModelObject(this); object->input_file = this->objects.front()->input_file; - - unsigned int auto_extruder_id = 1; - char str_extruder[64]; + + reset_auto_extruder_id(); for (const ModelObject* o : this->objects) for (const ModelVolume* v : o->volumes) @@ -416,12 +417,7 @@ void Model::convert_multipart_object() if (new_v != nullptr) { new_v->name = o->name; - - sprintf(str_extruder, "%ud", auto_extruder_id); - new_v->config.set_deserialize("extruder", str_extruder); - - if (++auto_extruder_id > 4) - auto_extruder_id = 1; + new_v->config.set_deserialize("extruder", get_auto_extruder_id_as_string()); } } @@ -481,6 +477,28 @@ bool Model::fits_print_volume(const FullPrintConfig &config) const return print_volume.contains(transformed_bounding_box()); } +unsigned int Model::get_auto_extruder_id() +{ + unsigned int id = s_auto_extruder_id; + + if (++s_auto_extruder_id > 4) + reset_auto_extruder_id(); + + return id; +} + +std::string Model::get_auto_extruder_id_as_string() +{ + char str_extruder[64]; + sprintf(str_extruder, "%ud", get_auto_extruder_id()); + return str_extruder; +} + +void Model::reset_auto_extruder_id() +{ + s_auto_extruder_id = 1; +} + ModelObject::ModelObject(Model *model, const ModelObject &other, bool copy_volumes) : name(other.name), input_file(other.input_file), @@ -1010,6 +1028,9 @@ size_t ModelVolume::split() size_t idx = 0; size_t ivolume = std::find(this->object->volumes.begin(), this->object->volumes.end(), this) - this->object->volumes.begin(); std::string name = this->name; + + Model::reset_auto_extruder_id(); + for (TriangleMesh *mesh : meshptrs) { mesh->repair(); if (idx == 0) @@ -1019,6 +1040,7 @@ size_t ModelVolume::split() char str_idx[64]; sprintf(str_idx, "_%d", idx + 1); this->object->volumes[ivolume]->name = name + str_idx; + this->object->volumes[ivolume]->config.set_deserialize("extruder", Model::get_auto_extruder_id_as_string()); delete mesh; ++ idx; } diff --git a/xs/src/libslic3r/Model.hpp b/xs/src/libslic3r/Model.hpp index bf7f60e36..0c0ffe776 100644 --- a/xs/src/libslic3r/Model.hpp +++ b/xs/src/libslic3r/Model.hpp @@ -230,6 +230,8 @@ private: // all objects may share mutliple materials. class Model { + static unsigned int s_auto_extruder_id; + public: // Materials are owned by a model and referenced by objects through t_model_material_id. // Single material may be shared by multiple models. @@ -288,6 +290,10 @@ public: bool fits_print_volume(const FullPrintConfig &config) const; void print_info() const { for (const ModelObject *o : this->objects) o->print_info(); } + + static unsigned int get_auto_extruder_id(); + static std::string get_auto_extruder_id_as_string(); + static void reset_auto_extruder_id(); }; }