diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp index 28d569761b..e877ab7035 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp @@ -12,6 +12,7 @@ #include "slic3r/GUI/GUI.hpp" #include "slic3r/GUI/GUI_ObjectSettings.hpp" #include "slic3r/GUI/GUI_ObjectList.hpp" +#include "slic3r/GUI/Plater.hpp" #include "slic3r/GUI/PresetBundle.hpp" #include "libslic3r/Tesselate.hpp" @@ -1111,6 +1112,11 @@ void GLGizmoSlaSupports::on_set_state() } } + if (m_state == m_old_state) + return; + + Plater::TakeSnapshot snapshot(wxGetApp().plater(), _(L("SLA gizmo on/off"))); + if (m_state == On && m_old_state != On) { // the gizmo was just turned on Plater::TakeSnapshot snapshot(wxGetApp().plater(), _(L("SLA gizmo turned on"))); if (is_mesh_update_necessary()) diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp index 088552e985..3093a9de27 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp @@ -151,8 +151,7 @@ void GLGizmosManager::refresh_on_off_state() { if (!gizmo->is_activable()) { - gizmo->set_state(GLGizmoBase::Off); - m_current = Undefined; + activate_gizmo(Undefined); } } } @@ -165,7 +164,7 @@ void GLGizmosManager::reset_all_states() if (m_serializing) return; - m_current = Undefined; + activate_gizmo(Undefined); m_hover = Undefined; } @@ -256,8 +255,9 @@ bool GLGizmosManager::is_running() const if (!m_enabled) return false; - GLGizmoBase* curr = get_current(); - return (curr != nullptr) ? (curr->get_state() == GLGizmoBase::On) : false; + //GLGizmoBase* curr = get_current(); + //return (curr != nullptr) ? (curr->get_state() == GLGizmoBase::On) : false; + return m_current != Undefined; } bool GLGizmosManager::handle_shortcut(int key) @@ -280,13 +280,11 @@ bool GLGizmosManager::handle_shortcut(int key) if (gizmo->is_activable() && ((it_key == key - 64) || (it_key == key - 96))) { if (m_current == idx) { - gizmo->set_state(GLGizmoBase::Off); - m_current = Undefined; + activate_gizmo(Undefined); handled = true; } else if (m_current != idx) { - gizmo->set_state(GLGizmoBase::On); - m_current = (EType)idx; + activate_gizmo((EType)idx); handled = true; } } @@ -953,7 +951,7 @@ void GLGizmosManager::do_render_overlay() const float u_right = u_left + u_icon_size; GLTexture::render_sub_texture(icons_texture_id, top_x, top_x + scaled_icons_size, top_y - scaled_icons_size, top_y, { { u_left, v_bottom }, { u_right, v_bottom }, { u_right, v_top }, { u_left, v_top } }); - if (gizmo->get_state() == GLGizmoBase::On) { + if (idx == m_current) { float toolbar_top = (float)cnv_h - m_parent.get_view_toolbar_height(); gizmo->render_input_window(width, 0.5f * cnv_h - top_y * zoom, toolbar_top); } @@ -1042,8 +1040,12 @@ void GLGizmosManager::update_on_off_state(const Vec2d& mouse_pos) if (gizmo->is_activable() && inside) { if (m_hover == idx) { - gizmo->set_state(m_current == idx ? GLGizmoBase::Off : GLGizmoBase::On); - m_current = (EType)(m_current == idx ? Undefined : idx); + if (m_current == idx) + activate_gizmo(Undefined); + else + activate_gizmo((EType)idx); + //gizmo->set_state(m_current == idx ? GLGizmoBase::Off : GLGizmoBase::On); + //m_current = (EType)(m_current == idx ? Undefined : idx); } } top_y += scaled_stride_y; @@ -1086,6 +1088,21 @@ std::string GLGizmosManager::update_hover_state(const Vec2d& mouse_pos) return name; } +void GLGizmosManager::activate_gizmo(EType type) +{ + if (m_gizmos.empty() || m_current == type) + return; + + if (m_current != Undefined) + m_gizmos[m_current]->set_state(GLGizmoBase::Off); + + if (type != Undefined) + m_gizmos[type]->set_state(GLGizmoBase::On); + + m_current = type; + +} + bool GLGizmosManager::overlay_contains_mouse(const Vec2d& mouse_pos) const { if (!m_enabled) diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp index 3a724d6f56..3f9d060cce 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp @@ -76,6 +76,8 @@ private: EType m_current; EType m_hover; + void activate_gizmo(EType type); + float m_overlay_icons_size; float m_overlay_scale; float m_overlay_border; @@ -112,18 +114,13 @@ public: m_serializing = true; + EType current = m_current; ar(m_current); + //std::swap(current, m_current); // undo the deserialization, let activate_gizmo do the change + //activate_gizmo(current); - GLGizmoBase* curr = get_current(); -/* for (GizmosMap::const_iterator it = m_gizmos.begin(); it != m_gizmos.end(); ++it) { - GLGizmoBase* gizmo = it->second; - if (gizmo != nullptr) { - gizmo->set_hover_id(-1); - gizmo->set_state((it->second == curr) ? GLGizmoBase::On : GLGizmoBase::Off); - if (gizmo == curr) - gizmo->load(ar); - } - }*/ + if (m_current != Undefined) + m_gizmos[m_current]->load(ar); } template @@ -134,9 +131,8 @@ public: ar(m_current); - /*GLGizmoBase* curr = get_current(); - if (curr != nullptr) - curr->save(ar);*/ + if (m_current != Undefined && !m_gizmos.empty()) + m_gizmos[m_current]->save(ar); } bool is_enabled() const { return m_enabled; }