From f71e14a4d9a531881c0be0c88a6c133b9eb72d8c Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Mon, 8 Apr 2019 15:34:42 +0200 Subject: [PATCH] SLA gizmo now uses ctrl to add to selection and alt to remove from selection --- src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp | 50 +++++++++++++------- src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp | 9 +++- src/slic3r/GUI/Gizmos/GLGizmos.hpp | 1 + src/slic3r/GUI/Gizmos/GLGizmosManager.cpp | 14 ++++-- src/slic3r/GUI/Gizmos/GLGizmosManager.hpp | 3 +- 5 files changed, 51 insertions(+), 26 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp index 63bff6305..67abfdd35 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp @@ -96,11 +96,16 @@ void GLGizmoSlaSupports::on_render(const Selection& selection) const void GLGizmoSlaSupports::render_selection_rectangle() const { - if (!m_selection_rectangle_active) + if (m_selection_rectangle_status == srOff) return; glsafe(::glLineWidth(1.5f)); - float render_color[3] = {1.f, 0.f, 0.f}; + float render_color[3] = {0.f, 1.f, 0.f}; + if (m_selection_rectangle_status == srDeselect) { + render_color[0] = 1.f; + render_color[1] = 0.3f; + render_color[2] = 0.3f; + } glsafe(::glColor3fv(render_color)); glsafe(::glPushAttrib(GL_TRANSFORM_BIT)); // remember current MatrixMode @@ -316,31 +321,35 @@ std::pair GLGizmoSlaSupports::unproject_on_mesh(const Vec2d& mouse // The gizmo has an opportunity to react - if it does, it should return true so that the Canvas3D is // aware that the event was reacted to and stops trying to make different sense of it. If the gizmo // concludes that the event was not intended for it, it should return false. -bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down) +bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down) { if (m_editing_mode) { - // left down - show the selection rectangle: - if (action == SLAGizmoEventType::LeftDown && shift_down) { + // left down with shift - show the selection rectangle: + if (action == SLAGizmoEventType::LeftDown && (shift_down || alt_down || control_down)) { if (m_hover_id == -1) { - m_selection_rectangle_active = true; - m_selection_rectangle_start_corner = mouse_position; - m_selection_rectangle_end_corner = mouse_position; - m_canvas_width = m_parent.get_canvas_size().get_width(); - m_canvas_height = m_parent.get_canvas_size().get_height(); + if (shift_down || alt_down) { + m_selection_rectangle_status = shift_down ? srSelect : srDeselect; + m_selection_rectangle_start_corner = mouse_position; + m_selection_rectangle_end_corner = mouse_position; + m_canvas_width = m_parent.get_canvas_size().get_width(); + m_canvas_height = m_parent.get_canvas_size().get_height(); + } } else { if (m_editing_mode_cache[m_hover_id].selected) unselect_point(m_hover_id); - else - select_point(m_hover_id); + else { + if (!alt_down) + select_point(m_hover_id); + } } return true; } // left down without selection rectangle - place point on the mesh: - if (action == SLAGizmoEventType::LeftDown && !m_selection_rectangle_active && !shift_down) { + if (action == SLAGizmoEventType::LeftDown && m_selection_rectangle_status == srOff && !shift_down) { // If any point is in hover state, this should initiate its move - return control back to GLCanvas: if (m_hover_id != -1) return false; @@ -365,7 +374,7 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous } // left up with selection rectangle - select points inside the rectangle: - if ((action == SLAGizmoEventType::LeftUp || action == SLAGizmoEventType::ShiftUp) && m_selection_rectangle_active) { + if ((action == SLAGizmoEventType::LeftUp || action == SLAGizmoEventType::ShiftUp || action == SLAGizmoEventType::AltUp) && m_selection_rectangle_status != srOff) { const Transform3d& instance_matrix = m_model_object->instances[m_active_instance]->get_transformation().get_matrix(); const Camera& camera = m_parent.get_camera(); const std::array& viewport = camera.get_viewport(); @@ -405,11 +414,15 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous if (hits.size() > 1 || hits.front().t > 0.001f) is_obscured = true; - if (!is_obscured) - select_point(i); + if (!is_obscured) { + if (m_selection_rectangle_status == srDeselect) + unselect_point(i); + else + select_point(i); + } } } - m_selection_rectangle_active = false; + m_selection_rectangle_status = srOff; return true; } @@ -427,8 +440,9 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous return true; // point has been placed and the button not released yet // this prevents GLCanvas from starting scene rotation - if (m_selection_rectangle_active) { + if (m_selection_rectangle_status != srOff) { m_selection_rectangle_end_corner = mouse_position; + m_selection_rectangle_status = shift_down ? srSelect : srDeselect; return true; } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp index 126aeab6e..c8abf15f2 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp @@ -50,7 +50,7 @@ public: #endif // ENABLE_SVG_ICONS virtual ~GLGizmoSlaSupports(); void set_sla_support_data(ModelObject* model_object, const Selection& selection); - bool gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down); + bool gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down); void delete_selected_points(bool force = false); std::pair get_sla_clipping_plane() const; @@ -75,7 +75,12 @@ private: mutable std::vector m_editing_mode_cache; // a support point and whether it is currently selected float m_clipping_plane_distance = 0.f; - bool m_selection_rectangle_active = false; + enum SelectionRectangleStatus { + srOff = 0, + srSelect = 1, + srDeselect = 2 + }m_selection_rectangle_status = srOff; + Vec2d m_selection_rectangle_start_corner; Vec2d m_selection_rectangle_end_corner; bool m_wait_for_up_event = false; diff --git a/src/slic3r/GUI/Gizmos/GLGizmos.hpp b/src/slic3r/GUI/Gizmos/GLGizmos.hpp index c45b7648d..95c5754c1 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmos.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmos.hpp @@ -10,6 +10,7 @@ enum class SLAGizmoEventType { Delete, SelectAll, ShiftUp, + AltUp, ApplyChanges, DiscardChanges, AutomaticGeneration, diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp index 3935e240a..ad2d786ff 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp @@ -455,14 +455,14 @@ void GLGizmosManager::set_sla_support_data(ModelObject* model_object, const Sele } // Returns true if the gizmo used the event to do something, false otherwise. -bool GLGizmosManager::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down) +bool GLGizmosManager::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down) { if (!m_enabled) return false; GizmosMap::const_iterator it = m_gizmos.find(SlaSupports); if (it != m_gizmos.end()) - return reinterpret_cast(it->second)->gizmo_event(action, mouse_position, shift_down); + return reinterpret_cast(it->second)->gizmo_event(action, mouse_position, shift_down, alt_down, control_down); return false; } @@ -546,7 +546,7 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt, GLCanvas3D& canvas) if (evt.LeftDown()) { - if ((m_current == SlaSupports) && gizmo_event(SLAGizmoEventType::LeftDown, mouse_pos, evt.ShiftDown())) + if ((m_current == SlaSupports) && gizmo_event(SLAGizmoEventType::LeftDown, mouse_pos, evt.ShiftDown(), evt.AltDown(), evt.ControlDown())) // the gizmo got the event and took some action, there is no need to do anything more processed = true; else if (!selection.is_empty() && grabber_contains_mouse()) @@ -573,7 +573,7 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt, GLCanvas3D& canvas) else if (evt.Dragging() && (canvas.get_move_volume_id() != -1) && (m_current == SlaSupports)) // don't allow dragging objects with the Sla gizmo on processed = true; - else if (evt.Dragging() && (m_current == SlaSupports) && gizmo_event(SLAGizmoEventType::Dragging, mouse_pos, evt.ShiftDown())) + else if (evt.Dragging() && (m_current == SlaSupports) && gizmo_event(SLAGizmoEventType::Dragging, mouse_pos, evt.ShiftDown(), evt.AltDown(), evt.ControlDown())) { // the gizmo got the event and took some action, no need to do anything more here canvas.set_as_dirty(); @@ -660,7 +660,7 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt, GLCanvas3D& canvas) { // in case SLA gizmo is selected, we just pass the LeftUp event and stop processing - neither // object moving or selecting is suppressed in that case - gizmo_event(SLAGizmoEventType::LeftUp, mouse_pos, evt.ShiftDown()); + gizmo_event(SLAGizmoEventType::LeftUp, mouse_pos, evt.ShiftDown(), evt.AltDown(), evt.ControlDown()); processed = true; } else if (evt.LeftUp() && (m_current == Flatten) && ((canvas.get_hover_volume_id() != -1) || grabber_contains_mouse())) @@ -801,6 +801,10 @@ bool GLGizmosManager::on_key(wxKeyEvent& evt, GLCanvas3D& canvas) if ((m_current == SlaSupports) && (keyCode == WXK_SHIFT) && gizmo_event(SLAGizmoEventType::ShiftUp)) // shift has been just released - SLA gizmo might want to close rectangular selection. processed = true; + + if ((m_current == SlaSupports) && (keyCode == WXK_ALT) && gizmo_event(SLAGizmoEventType::AltUp)) + // alt has been just released - SLA gizmo might want to close rectangular selection. + processed = true; } if (processed) diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp index 82dbdc0db..16e902522 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp @@ -145,7 +145,8 @@ public: void set_flattening_data(const ModelObject* model_object); void set_sla_support_data(ModelObject* model_object, const Selection& selection); - bool gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position = Vec2d::Zero(), bool shift_down = false); + bool gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position = Vec2d::Zero(), bool shift_down = false, bool alt_down = false, bool control_down = false); + void render_current_gizmo(const Selection& selection) const; void render_current_gizmo_for_picking_pass(const Selection& selection) const;