From 3db3a6152049bb32f2b37db3af25a55331747aca Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Fri, 3 Apr 2020 18:04:37 +0200 Subject: [PATCH] InstancesHider implementation Any gizmo can now ask for hiding all but the active instance by returning proper value from on_get_requirements --- src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp | 42 ++++++++++++++++++++--- src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp | 8 +++-- src/slic3r/GUI/Gizmos/GLGizmosManager.cpp | 7 ++-- 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp index 8022b93f2..3dd604b6b 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp @@ -14,7 +14,7 @@ CommonGizmosDataPool::CommonGizmosDataPool(GLCanvas3D* canvas) { using c = CommonGizmosDataID; m_data[c::SelectionInfo].reset( new SelectionInfo(this)); - //m_data[c::InstancesHider].reset( new InstancesHider(this)); + m_data[c::InstancesHider].reset( new InstancesHider(this)); //m_data[c::HollowedMesh].reset( new HollowedMesh(this)); //m_data[c::ClippingPlaneWrapper].reset(new ClippingPlaneWrapper(this)); //m_data[c::SupportsClipper].reset( new SupportsClipper(this)); @@ -27,8 +27,10 @@ void CommonGizmosDataPool::update(CommonGizmosDataID required) for (auto& [id, data] : m_data) { if (int(required) & int(CommonGizmosDataID(id))) data->update(); - else if (data->is_valid()) - data->release(); + else + if (data->is_valid()) + data->release(); + } } @@ -36,6 +38,7 @@ void CommonGizmosDataPool::update(CommonGizmosDataID required) SelectionInfo* CommonGizmosDataPool::selection_info() { SelectionInfo* sel_info = dynamic_cast(m_data[CommonGizmosDataID::SelectionInfo].get()); + assert(sel_info->is_valid()); return sel_info; } @@ -54,7 +57,7 @@ bool CommonGizmosDataPool::check_dependencies(CommonGizmosDataID required) const void SelectionInfo::on_update() { - Selection selection = m_common->get_canvas()->get_selection(); + const Selection& selection = m_common->get_canvas()->get_selection(); if (selection.is_single_full_instance()) m_model_object = selection.get_model()->objects[selection.get_object_idx()]; else @@ -66,5 +69,36 @@ void SelectionInfo::on_release() m_model_object = nullptr; } +int SelectionInfo::get_active_instance() +{ + const Selection& selection = m_common->get_canvas()->get_selection(); + return selection.get_instance_idx(); +} + + + + + +void InstancesHider::on_update() +{ + const ModelObject* mo = m_common->selection_info()->model_object(); + int active_inst = m_common->selection_info()->get_active_instance(); + GLCanvas3D* canvas = m_common->get_canvas(); + + if (mo && active_inst != -1) { + canvas->toggle_model_objects_visibility(false); + canvas->toggle_model_objects_visibility(true, mo, active_inst); + } + else + canvas->toggle_model_objects_visibility(true); +} + +void InstancesHider::on_release() +{ + m_common->get_canvas()->toggle_model_objects_visibility(true); +} + + + } // namespace GUI } // namespace Slic3r diff --git a/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp b/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp index 3f3854ffa..f1840837f 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp @@ -119,19 +119,21 @@ private: int m_active_inst = -1; }; -/* + class InstancesHider : public CommonGizmosDataBase { public: explicit InstancesHider(CommonGizmosDataPool* cgdp) : CommonGizmosDataBase(cgdp) {} - void update(bool required) override; +protected: + void on_update() override; + void on_release() override; }; - +/* class HollowedMesh : public CommonGizmosDataBase diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp index d5be7cd10..26f42ed34 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp @@ -1196,10 +1196,13 @@ void GLGizmosManager::activate_gizmo(EType type) return; // gizmo refused to be turned off, do nothing. } + m_current = type; + m_common_gizmos_data->update(get_current() + ? get_current()->get_requirements() + : CommonGizmosDataID(0)); + if (type != Undefined) m_gizmos[type]->set_state(GLGizmoBase::On); - - m_current = type; }