From 368cfedbc72ac2da35ef0cc60ae176f676784e47 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 20 Jul 2021 15:32:24 +0200 Subject: [PATCH] Keep non-sinking volumes on top of the printbed while scaling --- src/slic3r/GUI/Selection.cpp | 33 ++++++++++++++++++++++++++------- src/slic3r/GUI/Selection.hpp | 4 ++++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/slic3r/GUI/Selection.cpp b/src/slic3r/GUI/Selection.cpp index c38b88c3e..f2e879605 100644 --- a/src/slic3r/GUI/Selection.cpp +++ b/src/slic3r/GUI/Selection.cpp @@ -838,8 +838,21 @@ void Selection::scale(const Vec3d& scale, TransformationType transformation_type if (!m_valid) return; +#if ENABLE_ALLOW_NEGATIVE_Z + bool is_any_volume_sinking = false; +#if DISABLE_ALLOW_NEGATIVE_Z_FOR_SLA + bool is_sla = wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() == ptSLA; +#endif // DISABLE_ALLOW_NEGATIVE_Z_FOR_SLA +#endif // ENABLE_ALLOW_NEGATIVE_Z + for (unsigned int i : m_list) { GLVolume &volume = *(*m_volumes)[i]; +#if ENABLE_ALLOW_NEGATIVE_Z +#if DISABLE_ALLOW_NEGATIVE_Z_FOR_SLA + if (!is_sla) +#endif // DISABLE_ALLOW_NEGATIVE_Z_FOR_SLA + is_any_volume_sinking |= !volume.is_modifier && std::find(m_cache.sinking_volumes.begin(), m_cache.sinking_volumes.end(), i) != m_cache.sinking_volumes.end(); +#endif // ENABLE_ALLOW_NEGATIVE_Z if (is_single_full_instance()) { if (transformation_type.relative()) { Transform3d m = Geometry::assemble_transform(Vec3d::Zero(), Vec3d::Zero(), scale); @@ -895,10 +908,10 @@ void Selection::scale(const Vec3d& scale, TransformationType transformation_type synchronize_unselected_volumes(); #endif // !DISABLE_INSTANCES_SYNCH -#if DISABLE_ALLOW_NEGATIVE_Z_FOR_SLA - if (wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() == ptSLA) +#if ENABLE_ALLOW_NEGATIVE_Z + if (!is_any_volume_sinking) ensure_on_bed(); -#endif // DISABLE_ALLOW_NEGATIVE_Z_FOR_SLA +#endif // ENABLE_ALLOW_NEGATIVE_Z this->set_bounding_boxes_dirty(); } @@ -1644,10 +1657,16 @@ void Selection::update_type() void Selection::set_caches() { m_cache.volumes_data.clear(); - for (unsigned int i = 0; i < (unsigned int)m_volumes->size(); ++i) - { - const GLVolume* v = (*m_volumes)[i]; - m_cache.volumes_data.emplace(i, VolumeCache(v->get_volume_transformation(), v->get_instance_transformation())); +#if ENABLE_ALLOW_NEGATIVE_Z + m_cache.sinking_volumes.clear(); +#endif // ENABLE_ALLOW_NEGATIVE_Z + for (unsigned int i = 0; i < (unsigned int)m_volumes->size(); ++i) { + const GLVolume& v = *(*m_volumes)[i]; + m_cache.volumes_data.emplace(i, VolumeCache(v.get_volume_transformation(), v.get_instance_transformation())); +#if ENABLE_ALLOW_NEGATIVE_Z + if (v.is_sinking()) + m_cache.sinking_volumes.push_back(i); +#endif // ENABLE_ALLOW_NEGATIVE_Z } m_cache.dragging_center = get_bounding_box().center(); } diff --git a/src/slic3r/GUI/Selection.hpp b/src/slic3r/GUI/Selection.hpp index ae82f9ca7..c6409f9f2 100644 --- a/src/slic3r/GUI/Selection.hpp +++ b/src/slic3r/GUI/Selection.hpp @@ -186,6 +186,10 @@ private: // to a set of indices of ModelVolume instances in ModelObject::instances // Here the index means a position inside the respective std::vector, not ObjectID. ObjectIdxsToInstanceIdxsMap content; +#if ENABLE_ALLOW_NEGATIVE_Z + // List of ids of the volumes which are sinking when starting dragging + std::vector sinking_volumes; +#endif // ENABLE_ALLOW_NEGATIVE_Z }; // Volumes owned by GLCanvas3D.