From 14c4469cbfb1d86d429e4a1ed17a89699baa8b8e Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Tue, 14 May 2019 11:57:39 +0200 Subject: [PATCH] Added Esc shortcut and menu item for command deselect all --- src/libslic3r/Technologies.hpp | 8 +++++++ src/slic3r/GUI/GLCanvas3D.cpp | 28 +++++++++++------------ src/slic3r/GUI/GLCanvas3D.hpp | 1 + src/slic3r/GUI/GUI_Preview.cpp | 6 +++++ src/slic3r/GUI/GUI_Preview.hpp | 1 + src/slic3r/GUI/Gizmos/GLGizmosManager.cpp | 9 +++++--- src/slic3r/GUI/MainFrame.cpp | 11 ++++++++- src/slic3r/GUI/MainFrame.hpp | 1 + src/slic3r/GUI/Plater.cpp | 7 ++++++ src/slic3r/GUI/Plater.hpp | 1 + 10 files changed, 55 insertions(+), 18 deletions(-) diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index 45f04b1df..3375a282b 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -59,4 +59,12 @@ #define ENABLE_SVG_ICONS (1 && ENABLE_1_42_0_ALPHA8 && ENABLE_TEXTURES_FROM_SVG) +//==================== +// 1.42.0.rc techs +//==================== +#define ENABLE_1_42_0_RC 1 + +// Disables Edit->Deselect all item menu item +#define DISABLE_DESELECT_ALL_MENU_ITEM (1 && ENABLE_1_42_0_RC) + #endif // _technologies_h_ diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index df5558461..7633c2319 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1715,6 +1715,16 @@ void GLCanvas3D::select_all() m_dirty = true; } +void GLCanvas3D::deselect_all() +{ + m_selection.clear(); + m_selection.set_mode(Selection::Instance); + wxGetApp().obj_manipul()->set_dirty(); + m_gizmos.reset_all_states(); + m_gizmos.update_data(*this); + post_event(SimpleEvent(EVT_GLCANVAS_OBJECT_SELECT)); +} + void GLCanvas3D::delete_selected() { m_selection.erase(); @@ -2359,7 +2369,8 @@ void GLCanvas3D::on_char(wxKeyEvent& evt) post_event(SimpleEvent(EVT_GLTOOLBAR_DELETE)); break; - case '0': { select_view("iso"); break; } + case WXK_ESCAPE: { deselect_all(); break; } + case '0': { select_view("iso"); break; } case '1': { select_view("top"); break; } case '2': { select_view("bottom"); break; } case '3': { select_view("front"); break; } @@ -2379,11 +2390,7 @@ 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; } - default: - { - evt.Skip(); - break; - } + default: { evt.Skip(); break; } } } } @@ -2900,14 +2907,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) { // deselect and propagate event through callback if (!evt.ShiftDown() && m_picking_enabled) - { - m_selection.clear(); - m_selection.set_mode(Selection::Instance); - wxGetApp().obj_manipul()->set_dirty(); - m_gizmos.reset_all_states(); - m_gizmos.update_data(*this); - post_event(SimpleEvent(EVT_GLCANVAS_OBJECT_SELECT)); - } + deselect_all(); } else if (evt.LeftUp() && m_mouse.dragging) // Flips X mouse deltas if bed is upside down diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 96b958cbf..51a36cf69 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -555,6 +555,7 @@ public: void render(); void select_all(); + void deselect_all(); void delete_selected(); void ensure_on_bed(unsigned int object_idx); diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index 88fea933e..c9228d085 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -99,6 +99,12 @@ void View3D::select_all() m_canvas->select_all(); } +void View3D::deselect_all() +{ + if (m_canvas != nullptr) + m_canvas->deselect_all(); +} + void View3D::delete_selected() { if (m_canvas != nullptr) diff --git a/src/slic3r/GUI/GUI_Preview.hpp b/src/slic3r/GUI/GUI_Preview.hpp index 2540980f4..b70d01fa4 100644 --- a/src/slic3r/GUI/GUI_Preview.hpp +++ b/src/slic3r/GUI/GUI_Preview.hpp @@ -47,6 +47,7 @@ public: void select_view(const std::string& direction); void select_all(); + void deselect_all(); void delete_selected(); void mirror_selection(Axis axis); diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp index 7e978e2a3..478bd1fa7 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp @@ -790,10 +790,13 @@ bool GLGizmosManager::on_char(wxKeyEvent& evt, GLCanvas3D& canvas) // key ESC case WXK_ESCAPE: { - if ((m_current != SlaSupports) || !gizmo_event(SLAGizmoEventType::DiscardChanges)) - reset_all_states(); + if (m_current != Undefined) + { + if ((m_current != SlaSupports) || !gizmo_event(SLAGizmoEventType::DiscardChanges)) + reset_all_states(); - processed = true; + processed = true; + } break; } case WXK_RETURN: diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 39a7c85f2..a8a7e5c86 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -267,6 +267,11 @@ bool MainFrame::can_select() const return (m_plater != nullptr) && !m_plater->model().objects.empty(); } +bool MainFrame::can_deselect() const +{ + return (m_plater != nullptr) && !m_plater->is_selection_empty(); +} + bool MainFrame::can_delete() const { return (m_plater != nullptr) && !m_plater->is_selection_empty(); @@ -449,6 +454,11 @@ void MainFrame::init_menubar() append_menu_item(editMenu, wxID_ANY, _(L("&Select all")) + sep + GUI::shortkey_ctrl_prefix() + sep_space + "A", _(L("Selects all objects")), [this](wxCommandEvent&) { if (m_plater != nullptr) m_plater->select_all(); }, "", nullptr, [this](){return can_select(); }, this); +#if !DISABLE_DESELECT_ALL_MENU_ITEM + append_menu_item(editMenu, wxID_ANY, _(L("D&eselect all")) + sep + GUI::shortkey_ctrl_prefix() + sep + "Esc", + _(L("Deselects all objects")), [this](wxCommandEvent&) { if (m_plater != nullptr) m_plater->deselect_all(); }, + "", nullptr, [this](){return can_deselect(); }, this); +#endif // !DISABLE_DESELECT_ALL_MENU_ITEM editMenu->AppendSeparator(); append_menu_item(editMenu, wxID_ANY, _(L("&Delete selected")) + sep + hotkey_delete, _(L("Deletes the current selection")),[this](wxCommandEvent&) { m_plater->remove_selected(); }, @@ -458,7 +468,6 @@ void MainFrame::init_menubar() menu_icon("delete_all_menu"), nullptr, [this](){return can_delete_all(); }, this); editMenu->AppendSeparator(); - append_menu_item(editMenu, wxID_ANY, _(L("&Copy")) + sep + GUI::shortkey_ctrl_prefix() + sep_space + "C", _(L("Copy selection to clipboard")), [this](wxCommandEvent&) { m_plater->copy_selection_to_clipboard(); }, menu_icon("copy_menu"), nullptr, [this](){return m_plater->can_copy(); }, this); diff --git a/src/slic3r/GUI/MainFrame.hpp b/src/slic3r/GUI/MainFrame.hpp index f3d582681..b5d875cbf 100644 --- a/src/slic3r/GUI/MainFrame.hpp +++ b/src/slic3r/GUI/MainFrame.hpp @@ -68,6 +68,7 @@ class MainFrame : public DPIFrame bool can_slice() const; bool can_change_view() const; bool can_select() const; + bool can_deselect() const; bool can_delete() const; bool can_delete_all() const; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 8c4a8d4b0..572b25c16 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1261,6 +1261,7 @@ struct Plater::priv void object_list_changed(); void select_all(); + void deselect_all(); void remove(size_t obj_idx); void delete_object_from_model(size_t obj_idx); void reset(); @@ -2032,6 +2033,11 @@ void Plater::priv::select_all() this->sidebar->obj_list()->update_selections(); } +void Plater::priv::deselect_all() +{ + view3D->deselect_all(); +} + void Plater::priv::remove(size_t obj_idx) { // Prevent toolpaths preview from rendering while we modify the Print object @@ -3303,6 +3309,7 @@ void Plater::select_view(const std::string& direction) { p->select_view(directio void Plater::select_view_3D(const std::string& name) { p->select_view_3D(name); } void Plater::select_all() { p->select_all(); } +void Plater::deselect_all() { p->deselect_all(); } void Plater::remove(size_t obj_idx) { p->remove(obj_idx); } void Plater::reset() { p->reset(); } diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index f77ec53a7..d4d4b3d18 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -152,6 +152,7 @@ public: void update_ui_from_settings(); void select_all(); + void deselect_all(); void remove(size_t obj_idx); void reset(); void reset_with_confirm();