From 77964de9f24dab24c811ae293d9775e0c080d59a Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Wed, 13 Mar 2019 14:04:59 +0100 Subject: [PATCH] Update of ModelVolume::m_is_splittable moved inside ModelVolume itself --- src/libslic3r/Model.cpp | 9 +++++++++ src/libslic3r/Model.hpp | 5 ++--- src/slic3r/GUI/GUI_ObjectList.cpp | 7 +------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index 9c5f8c826..606bcd6f0 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -1456,6 +1456,15 @@ int ModelVolume::extruder_id() const return extruder_id; } +bool ModelVolume::is_splittable() const +{ + // the call mesh.has_multiple_patches() is expensive, so cache the value to calculate it only once + if (m_is_splittable == -1) + m_is_splittable = (int)mesh.has_multiple_patches(); + + return m_is_splittable == 1; +} + void ModelVolume::center_geometry() { #if ENABLE_VOLUMES_CENTERING_FIXES diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index a4b32d93f..432e49220 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -336,8 +336,7 @@ public: // Extruder ID is only valid for FFF. Returns -1 for SLA or if the extruder ID is not applicable (support volumes). int extruder_id() const; - void set_splittable(const int val) { m_is_splittable = val; } - int is_splittable() const { return m_is_splittable; } + bool is_splittable() const; // Split this volume, append the result to the object owning this volume. // Return the number of volumes created from this one. @@ -417,7 +416,7 @@ private: // -1 -> is unknown value (before first cheking) // 0 -> is not splittable // 1 -> is splittable - int m_is_splittable {-1}; + mutable int m_is_splittable{ -1 }; ModelVolume(ModelObject *object, const TriangleMesh &mesh) : mesh(mesh), m_type(ModelVolumeType::MODEL_PART), object(object) { diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 6a605a667..494467f79 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -1519,12 +1519,7 @@ bool ObjectList::is_splittable() if (!get_volume_by_item(item, volume) || !volume) return false; - int splittable = volume->is_splittable(); - if (splittable == -1) { - splittable = (int)volume->mesh.has_multiple_patches(); - volume->set_splittable(splittable); - } - return splittable != 0; + return volume->is_splittable(); } bool ObjectList::selected_instances_of_same_object()