Handling of gizmos related char events moved into new method GLGizmosManager::on_char()

This commit is contained in:
Enrico Turri 2019-03-26 14:08:02 +01:00
parent c1d74d2943
commit d18208458b
3 changed files with 98 additions and 45 deletions

View file

@ -2240,6 +2240,9 @@ void GLCanvas3D::on_char(wxKeyEvent& evt)
return;
}
if (m_gizmos.on_char(evt, *this))
return;
//#ifdef __APPLE__
// ctrlMask |= wxMOD_RAW_CONTROL;
//#endif /* __APPLE__ */
@ -2248,9 +2251,6 @@ void GLCanvas3D::on_char(wxKeyEvent& evt)
case 'a':
case 'A':
case WXK_CONTROL_A:
if (m_gizmos.get_current_type() == GLGizmosManager::SlaSupports && m_gizmos.gizmo_event(SLAGizmoEventType::SelectAll)) // Sla gizmo selects all support points
m_dirty = true;
else
post_event(SimpleEvent(EVT_GLCANVAS_SELECT_ALL));
break;
#ifdef __APPLE__
@ -2266,29 +2266,12 @@ void GLCanvas3D::on_char(wxKeyEvent& evt)
} else {
switch (keyCode)
{
// key ESC
case WXK_ESCAPE: {
if (m_gizmos.get_current_type() != GLGizmosManager::SlaSupports || !m_gizmos.gizmo_event(SLAGizmoEventType::DiscardChanges))
m_gizmos.reset_all_states();
m_dirty = true;
break;
}
case WXK_RETURN: {
if (m_gizmos.get_current_type() == GLGizmosManager::SlaSupports && m_gizmos.gizmo_event(SLAGizmoEventType::ApplyChanges))
m_dirty = true;
break;
}
#ifdef __APPLE__
case WXK_BACK: // the low cost Apple solutions are not equipped with a Delete key, use Backspace instead.
#else /* __APPLE__ */
case WXK_DELETE:
#endif /* __APPLE__ */
if (m_gizmos.get_current_type() == GLGizmosManager::SlaSupports && m_gizmos.gizmo_event(SLAGizmoEventType::Delete))
m_dirty = true;
else
post_event(SimpleEvent(EVT_GLTOOLBAR_DELETE));
post_event(SimpleEvent(EVT_GLTOOLBAR_DELETE));
break;
case '0': { select_view("iso"); break; }
@ -2302,15 +2285,7 @@ void GLCanvas3D::on_char(wxKeyEvent& evt)
case '-': { post_event(Event<int>(EVT_GLCANVAS_INCREASE_INSTANCES, -1)); break; }
case '?': { post_event(SimpleEvent(EVT_GLCANVAS_QUESTION_MARK)); break; }
case 'A':
case 'a': {
if (m_gizmos.get_current_type() == GLGizmosManager::SlaSupports) {
if (m_gizmos.gizmo_event(SLAGizmoEventType::AutomaticGeneration))
m_dirty = true;
}
else
post_event(SimpleEvent(EVT_GLCANVAS_ARRANGE));
break;
}
case 'a': { post_event(SimpleEvent(EVT_GLCANVAS_ARRANGE)); break; }
case 'B':
case 'b': { zoom_to_bed(); break; }
case 'I':
@ -2319,23 +2294,9 @@ void GLCanvas3D::on_char(wxKeyEvent& evt)
case 'o': { set_camera_zoom(-1.0f); break; }
case 'Z':
case 'z': { m_selection.is_empty() ? zoom_to_volumes() : zoom_to_selection(); break; }
case 'M':
case 'm': {
if (m_gizmos.get_current_type() == GLGizmosManager::SlaSupports && m_gizmos.gizmo_event(SLAGizmoEventType::ManualEditing)) {
m_dirty = true;
break;
}
} // intentional fallthrough
default:
{
if (m_gizmos.handle_shortcut(keyCode, m_selection))
{
update_gizmos_data();
m_dirty = true;
}
else
evt.Skip();
evt.Skip();
break;
}
}

View file

@ -654,6 +654,97 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt, GLCanvas3D& canvas)
return processed;
}
bool GLGizmosManager::on_char(wxKeyEvent& evt, GLCanvas3D& canvas)
{
// see include/wx/defs.h enum wxKeyCode
int keyCode = evt.GetKeyCode();
int ctrlMask = wxMOD_CONTROL;
const Selection& selection = canvas.get_selection();
bool processed = false;
if ((evt.GetModifiers() & ctrlMask) != 0)
{
switch (keyCode)
{
case WXK_CONTROL_A:
{
// Sla gizmo selects all support points
if ((m_current == SlaSupports) && gizmo_event(SLAGizmoEventType::SelectAll))
processed = true;
break;
}
}
}
else if (!evt.HasModifiers())
{
switch (keyCode)
{
// key ESC
case WXK_ESCAPE:
{
if ((m_current != SlaSupports) || !gizmo_event(SLAGizmoEventType::DiscardChanges))
reset_all_states();
processed = true;
break;
}
case WXK_RETURN:
{
if ((m_current == SlaSupports) && gizmo_event(SLAGizmoEventType::ApplyChanges))
processed = true;
break;
}
#ifdef __APPLE__
case WXK_BACK: // the low cost Apple solutions are not equipped with a Delete key, use Backspace instead.
#else /* __APPLE__ */
case WXK_DELETE:
#endif /* __APPLE__ */
{
if ((m_current == SlaSupports) && gizmo_event(SLAGizmoEventType::Delete))
processed = true;
break;
}
case 'A':
case 'a':
{
if (m_current == SlaSupports)
{
gizmo_event(SLAGizmoEventType::AutomaticGeneration);
// set as processed no matter what's returned by gizmo_event() to avoid the calling canvas to process 'A' as arrange
processed = true;
}
break;
}
case 'M':
case 'm':
{
if ((m_current == SlaSupports) && gizmo_event(SLAGizmoEventType::ManualEditing))
processed = true;
break;
}
}
}
if (!processed)
{
if (handle_shortcut(keyCode, selection))
{
canvas.update_gizmos_data();
processed = true;
}
}
if (processed)
canvas.set_as_dirty();
return processed;
}
void GLGizmosManager::reset()
{
for (GizmosMap::value_type& gizmo : m_gizmos)

View file

@ -153,6 +153,7 @@ public:
const std::string& get_tooltip() const { return m_tooltip; }
bool on_mouse(wxMouseEvent& evt, GLCanvas3D& canvas);
bool on_char(wxKeyEvent& evt, GLCanvas3D& canvas);
private:
void reset();