SLA gizmo open/close should be saved on undo/redo stack

This commit is contained in:
Lukas Matena 2019-08-19 12:11:26 +02:00
parent b6d35c9840
commit 409a7c7734
3 changed files with 44 additions and 25 deletions

View File

@ -12,6 +12,7 @@
#include "slic3r/GUI/GUI.hpp" #include "slic3r/GUI/GUI.hpp"
#include "slic3r/GUI/GUI_ObjectSettings.hpp" #include "slic3r/GUI/GUI_ObjectSettings.hpp"
#include "slic3r/GUI/GUI_ObjectList.hpp" #include "slic3r/GUI/GUI_ObjectList.hpp"
#include "slic3r/GUI/Plater.hpp"
#include "slic3r/GUI/PresetBundle.hpp" #include "slic3r/GUI/PresetBundle.hpp"
#include "libslic3r/Tesselate.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 if (m_state == On && m_old_state != On) { // the gizmo was just turned on
Plater::TakeSnapshot snapshot(wxGetApp().plater(), _(L("SLA gizmo turned on"))); Plater::TakeSnapshot snapshot(wxGetApp().plater(), _(L("SLA gizmo turned on")));
if (is_mesh_update_necessary()) if (is_mesh_update_necessary())

View File

@ -151,8 +151,7 @@ void GLGizmosManager::refresh_on_off_state()
{ {
if (!gizmo->is_activable()) if (!gizmo->is_activable())
{ {
gizmo->set_state(GLGizmoBase::Off); activate_gizmo(Undefined);
m_current = Undefined;
} }
} }
} }
@ -165,7 +164,7 @@ void GLGizmosManager::reset_all_states()
if (m_serializing) if (m_serializing)
return; return;
m_current = Undefined; activate_gizmo(Undefined);
m_hover = Undefined; m_hover = Undefined;
} }
@ -256,8 +255,9 @@ bool GLGizmosManager::is_running() const
if (!m_enabled) if (!m_enabled)
return false; return false;
GLGizmoBase* curr = get_current(); //GLGizmoBase* curr = get_current();
return (curr != nullptr) ? (curr->get_state() == GLGizmoBase::On) : false; //return (curr != nullptr) ? (curr->get_state() == GLGizmoBase::On) : false;
return m_current != Undefined;
} }
bool GLGizmosManager::handle_shortcut(int key) 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 (gizmo->is_activable() && ((it_key == key - 64) || (it_key == key - 96)))
{ {
if (m_current == idx) { if (m_current == idx) {
gizmo->set_state(GLGizmoBase::Off); activate_gizmo(Undefined);
m_current = Undefined;
handled = true; handled = true;
} }
else if (m_current != idx) { else if (m_current != idx) {
gizmo->set_state(GLGizmoBase::On); activate_gizmo((EType)idx);
m_current = (EType)idx;
handled = true; handled = true;
} }
} }
@ -953,7 +951,7 @@ void GLGizmosManager::do_render_overlay() const
float u_right = u_left + u_icon_size; 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 } }); 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(); 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); 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 (gizmo->is_activable() && inside)
{ {
if (m_hover == idx) { if (m_hover == idx) {
gizmo->set_state(m_current == idx ? GLGizmoBase::Off : GLGizmoBase::On); if (m_current == idx)
m_current = (EType)(m_current == idx ? Undefined : 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; top_y += scaled_stride_y;
@ -1086,6 +1088,21 @@ std::string GLGizmosManager::update_hover_state(const Vec2d& mouse_pos)
return name; 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 bool GLGizmosManager::overlay_contains_mouse(const Vec2d& mouse_pos) const
{ {
if (!m_enabled) if (!m_enabled)

View File

@ -76,6 +76,8 @@ private:
EType m_current; EType m_current;
EType m_hover; EType m_hover;
void activate_gizmo(EType type);
float m_overlay_icons_size; float m_overlay_icons_size;
float m_overlay_scale; float m_overlay_scale;
float m_overlay_border; float m_overlay_border;
@ -112,18 +114,13 @@ public:
m_serializing = true; m_serializing = true;
EType current = m_current;
ar(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(); if (m_current != Undefined)
/* for (GizmosMap::const_iterator it = m_gizmos.begin(); it != m_gizmos.end(); ++it) { m_gizmos[m_current]->load(ar);
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);
}
}*/
} }
template<class Archive> template<class Archive>
@ -134,9 +131,8 @@ public:
ar(m_current); ar(m_current);
/*GLGizmoBase* curr = get_current(); if (m_current != Undefined && !m_gizmos.empty())
if (curr != nullptr) m_gizmos[m_current]->save(ar);
curr->save(ar);*/
} }
bool is_enabled() const { return m_enabled; } bool is_enabled() const { return m_enabled; }