Add check for unselection to close emboss gizmo before snapshot

This commit is contained in:
Filip Sykala - NTB T15p 2023-03-28 21:48:34 +02:00
parent cc9a3a473e
commit 856b8d1a24
3 changed files with 35 additions and 1 deletions

View File

@ -1711,6 +1711,11 @@ void GLCanvas3D::deselect_all()
if (m_selection.is_empty()) if (m_selection.is_empty())
return; return;
// close actual opened gizmo before deselection(m_selection.remove_all()) write to undo/redo snapshot
if (GLGizmosManager::EType current_type = m_gizmos.get_current_type();
current_type != GLGizmosManager::Undefined)
m_gizmos.open_gizmo(current_type);
m_selection.remove_all(); m_selection.remove_all();
wxGetApp().obj_manipul()->set_dirty(); wxGetApp().obj_manipul()->set_dirty();
m_gizmos.reset_all_states(); m_gizmos.reset_all_states();

View File

@ -405,6 +405,33 @@ bool GLGizmoEmboss::on_mouse_for_translate(const wxMouseEvent &mouse_event)
return res; return res;
} }
void GLGizmoEmboss::on_mouse_change_selection(const wxMouseEvent &mouse_event)
{
if (mouse_event.LeftDown()) {
// is hovered volume closest hovered?
int hovered_idx = m_parent.get_first_hover_volume_idx();
if (hovered_idx < 0)
// unselect object
return close();
const GLVolumePtrs &gl_volumes = m_parent.get_volumes().volumes;
auto hovered_idx_ = static_cast<size_t>(hovered_idx);
if (hovered_idx_ >= gl_volumes.size())
return close();
const GLVolume *gl_volume = gl_volumes[hovered_idx_];
if (gl_volume == nullptr)
return close();
const ModelVolume *volume = get_model_volume(*gl_volume, m_parent.get_model()->objects);
if (volume == nullptr || !volume->text_configuration.has_value())
// select volume without text configuration
return close();
// Reselection of text to another text
}
}
bool GLGizmoEmboss::on_mouse(const wxMouseEvent &mouse_event) bool GLGizmoEmboss::on_mouse(const wxMouseEvent &mouse_event)
{ {
// not selected volume // not selected volume
@ -414,7 +441,7 @@ bool GLGizmoEmboss::on_mouse(const wxMouseEvent &mouse_event)
if (on_mouse_for_rotation(mouse_event)) return true; if (on_mouse_for_rotation(mouse_event)) return true;
if (on_mouse_for_translate(mouse_event)) return true; if (on_mouse_for_translate(mouse_event)) return true;
on_mouse_change_selection(mouse_event);
return false; return false;
} }
@ -527,6 +554,7 @@ void GLGizmoEmboss::on_render_input_window(float x, float y, float bottom_limit)
if (m_volume == nullptr || if (m_volume == nullptr ||
get_model_volume(m_volume_id, m_parent.get_selection().get_model()->objects) == nullptr || get_model_volume(m_volume_id, m_parent.get_selection().get_model()->objects) == nullptr ||
!m_volume->text_configuration.has_value()) { !m_volume->text_configuration.has_value()) {
// This closing could lead to bad behavior of undo/redo stack when unselection create snapshot before close
close(); close();
return; return;
} }

View File

@ -149,6 +149,7 @@ private:
// process mouse event // process mouse event
bool on_mouse_for_rotation(const wxMouseEvent &mouse_event); bool on_mouse_for_rotation(const wxMouseEvent &mouse_event);
bool on_mouse_for_translate(const wxMouseEvent &mouse_event); bool on_mouse_for_translate(const wxMouseEvent &mouse_event);
void on_mouse_change_selection(const wxMouseEvent &mouse_event);
// When open text loaded from .3mf it could be written with unknown font // When open text loaded from .3mf it could be written with unknown font
bool m_is_unknown_font; bool m_is_unknown_font;