From 8df2a19974b2031fed5753b50cfdc4e8dceec62d Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Wed, 17 Apr 2019 10:16:39 +0200 Subject: [PATCH] SLA clipping plane can now be controlled by Ctrl + mouse wheel rotation --- src/slic3r/GUI/GLCanvas3D.cpp | 4 ++++ src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp | 12 ++++++++++++ src/slic3r/GUI/Gizmos/GLGizmos.hpp | 4 +++- src/slic3r/GUI/Gizmos/GLGizmosManager.cpp | 17 +++++++++++++++++ src/slic3r/GUI/Gizmos/GLGizmosManager.hpp | 1 + 5 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index e656bec9b..8aa3205a7 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -2374,6 +2374,10 @@ void GLCanvas3D::on_mouse_wheel(wxMouseEvent& evt) } } + // Inform gizmos about the event so they have the opportunity to react. + if (m_gizmos.on_mouse_wheel(evt, *this)) + return; + // Calculate the zoom delta and apply it to the current zoom factor float zoom = (float)evt.GetWheelRotation() / (float)evt.GetWheelDelta(); set_camera_zoom(zoom); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp index 1338bbc4d..1460f9e58 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp @@ -708,6 +708,18 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous } } + if (action == SLAGizmoEventType::MouseWheelUp && control_down) { + m_clipping_plane_distance = std::min(1.f, m_clipping_plane_distance + 0.01f); + m_parent.set_as_dirty(); + return true; + } + + if (action == SLAGizmoEventType::MouseWheelDown && control_down) { + m_clipping_plane_distance = std::max(0.f, m_clipping_plane_distance - 0.01f); + m_parent.set_as_dirty(); + return true; + } + return false; } diff --git a/src/slic3r/GUI/Gizmos/GLGizmos.hpp b/src/slic3r/GUI/Gizmos/GLGizmos.hpp index 95c5754c1..4c2d2d30f 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmos.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmos.hpp @@ -14,7 +14,9 @@ enum class SLAGizmoEventType { ApplyChanges, DiscardChanges, AutomaticGeneration, - ManualEditing + ManualEditing, + MouseWheelUp, + MouseWheelDown }; #include "slic3r/GUI/Gizmos/GLGizmoMove.hpp" diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp index 4cc8c8cf1..2c69b6407 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp @@ -520,6 +520,23 @@ void GLGizmosManager::render_overlay(const GLCanvas3D& canvas, const Selection& glsafe(::glPopMatrix()); } + + +bool GLGizmosManager::on_mouse_wheel(wxMouseEvent& evt, GLCanvas3D& canvas) +{ + bool processed = false; + + if (m_current == SlaSupports) { + float rot = (float)evt.GetWheelRotation() / (float)evt.GetWheelDelta(); + if (gizmo_event((rot > 0.f ? SLAGizmoEventType::MouseWheelUp : SLAGizmoEventType::MouseWheelDown), Vec2d::Zero(), evt.ShiftDown(), evt.AltDown(), evt.ControlDown())) + processed = true; + } + + return processed; +} + + + bool GLGizmosManager::on_mouse(wxMouseEvent& evt, GLCanvas3D& canvas) { Point pos(evt.GetX(), evt.GetY()); diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp index f7a1a980e..a04ced5fa 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp @@ -157,6 +157,7 @@ public: const std::string& get_tooltip() const { return m_tooltip; } bool on_mouse(wxMouseEvent& evt, GLCanvas3D& canvas); + bool on_mouse_wheel(wxMouseEvent& evt, GLCanvas3D& canvas); bool on_char(wxKeyEvent& evt, GLCanvas3D& canvas); bool on_key(wxKeyEvent& evt, GLCanvas3D& canvas);