From 7ffa22191dfaf29e4489b2e602085697f18a9642 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Mon, 5 Nov 2018 17:52:55 +0100 Subject: [PATCH] Fixed some issues with front end / back end synchronization. --- src/libslic3r/Model.cpp | 16 ++++++---------- src/libslic3r/Model.hpp | 9 +++++---- src/libslic3r/PrintObject.cpp | 2 +- xs/xsp/Model.xsp | 2 -- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index c42691395..9cd7846f3 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -254,6 +254,7 @@ void Model::clear_materials() ModelMaterial* Model::add_material(t_model_material_id material_id) { + assert(! material_id.empty()); ModelMaterial* material = this->get_material(material_id); if (material == nullptr) material = this->materials[material_id] = new ModelMaterial(this); @@ -262,6 +263,7 @@ ModelMaterial* Model::add_material(t_model_material_id material_id) ModelMaterial* Model::add_material(t_model_material_id material_id, const ModelMaterial &other) { + assert(! material_id.empty()); // delete existing material if any ModelMaterial* material = this->get_material(material_id); delete material; @@ -1134,7 +1136,8 @@ void ModelVolume::set_material_id(t_model_material_id material_id) { m_material_id = material_id; // ensure m_material_id references an existing material - this->object->get_model()->add_material(material_id); + if (! material_id.empty()) + this->object->get_model()->add_material(material_id); } ModelMaterial* ModelVolume::material() const @@ -1145,15 +1148,8 @@ ModelMaterial* ModelVolume::material() const void ModelVolume::set_material(t_model_material_id material_id, const ModelMaterial &material) { m_material_id = material_id; - this->object->get_model()->add_material(material_id, material); -} - -ModelMaterial* ModelVolume::assign_unique_material() -{ - Model* model = this->get_object()->get_model(); - // as material-id "0" is reserved by the AMF spec we start from 1 - m_material_id = 1 + model->materials.size(); // watchout for implicit cast - return model->add_material(m_material_id); + if (! material_id.empty()) + this->object->get_model()->add_material(material_id, material); } void ModelVolume::calculate_convex_hull() diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index a3aeab739..1850cce1f 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -22,7 +22,6 @@ class ModelInstance; class ModelMaterial; class ModelObject; class ModelVolume; -class PresetBundle; class Print; typedef std::string t_model_material_id; @@ -323,8 +322,6 @@ public: void rotate(double angle, const Vec3d& axis); void mirror(Axis axis); - ModelMaterial* assign_unique_material(); - void calculate_convex_hull(); const TriangleMesh& get_convex_hull() const; @@ -391,14 +388,15 @@ private: mesh(std::move(mesh)), m_convex_hull(std::move(convex_hull)), m_type(MODEL_PART), object(object) {} #if ENABLE_MODELVOLUME_TRANSFORM + // Copying an existing volume, therefore this volume will get a copy of the ID assigned. ModelVolume(ModelObject *object, const ModelVolume &other) : ModelBase(other), // copy the ID name(other.name), mesh(other.mesh), m_convex_hull(other.m_convex_hull), config(other.config), m_type(other.m_type), object(object), m_transformation(other.m_transformation) { this->set_material_id(other.material_id()); } + // Providing a new mesh, therefore this volume will get a new unique ID assigned. ModelVolume(ModelObject *object, const ModelVolume &other, const TriangleMesh &&mesh) : - ModelBase(other), // copy the ID name(other.name), mesh(std::move(mesh)), config(other.config), m_type(other.m_type), object(object), m_transformation(other.m_transformation) { this->set_material_id(other.material_id()); @@ -406,12 +404,15 @@ private: calculate_convex_hull(); } #else + // Copying an existing volume, therefore this volume will get a copy of the ID assigned. ModelVolume(ModelObject *object, const ModelVolume &other) : + ModelBase(other), // copy the ID name(other.name), mesh(other.mesh), m_convex_hull(other.m_convex_hull), config(other.config), m_type(other.m_type), object(object) { if (! other.material_id().empty()) this->set_material_id(other.material_id()); } + // Providing a new mesh, therefore this volume will get a new unique ID assigned. ModelVolume(ModelObject *object, const ModelVolume &other, TriangleMesh &&mesh) : name(other.name), mesh(std::move(mesh)), config(other.config), m_type(other.m_type), object(object) { diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index bc4a3020c..a7e368a11 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -633,7 +633,7 @@ void PrintObject::detect_surfaces_type() // should be visible. bool interface_shells = m_config.interface_shells.value; - for (int idx_region = 0; idx_region < m_print->m_regions.size(); ++ idx_region) { + for (int idx_region = 0; idx_region < this->region_volumes.size(); ++ idx_region) { BOOST_LOG_TRIVIAL(debug) << "Detecting solid surfaces for region " << idx_region << " in parallel - start"; #ifdef SLIC3R_DEBUG_SLICE_PROCESSING for (Layer *layer : m_layers) diff --git a/xs/xsp/Model.xsp b/xs/xsp/Model.xsp index a198b1b9f..11fa7e920 100644 --- a/xs/xsp/Model.xsp +++ b/xs/xsp/Model.xsp @@ -286,8 +286,6 @@ ModelMaterial::attributes() %code%{ THIS->set_type(ModelVolume::SUPPORT_BLOCKER); %}; size_t split(unsigned int max_extruders); - - ModelMaterial* assign_unique_material(); };