From 72245ed07992cb42efdfe4ff875619fba5407a7f Mon Sep 17 00:00:00 2001 From: "zhou.xu" Date: Thu, 10 Oct 2024 17:35:51 +0800 Subject: [PATCH] FIX:ban move glvolume when at cut and so on gizmo jira:STUDIO-8408 part code is from OrcaSlicer,thanks for OrcaSlicer and Filip Sykala commit 9dbb2dfe0d5395577a1f86fad7954771d7c77910 Author: Filip Sykala Date: Sun Oct 29 23:11:10 2023 +0800 Various gizmos refactoring Change-Id: I7173e997bab1611c96643628fde9b147c54df5e6 --- src/slic3r/GUI/GLCanvas3D.cpp | 12 ++++++++---- src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp | 2 ++ src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp | 2 +- src/slic3r/GUI/Gizmos/GLGizmosManager.cpp | 12 ++++++++++++ src/slic3r/GUI/Gizmos/GLGizmosManager.hpp | 1 + 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index a9e8a2f6c..0426ab80c 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -3475,7 +3475,10 @@ void GLCanvas3D::on_key(wxKeyEvent& evt) m_dirty = true; }, [this](const Vec3d& direction, bool slow, bool camera_space) { - m_selection.start_dragging(); + if (m_gizmos.is_ban_move_glvolume()) { + return; + } + m_selection.setup_cache(); double multiplier = slow ? 1.0 : 10.0; Vec3d displacement; @@ -3490,7 +3493,6 @@ void GLCanvas3D::on_key(wxKeyEvent& evt) TransformationType trafo_type; trafo_type.set_relative(); m_selection.translate(displacement, trafo_type); - m_selection.stop_dragging(); m_dirty = true; } );} @@ -3647,12 +3649,14 @@ void GLCanvas3D::on_key(wxKeyEvent& evt) post_event(SimpleEvent(EVT_GLCANVAS_COLLAPSE_SIDEBAR)); } else if (m_gizmos.is_enabled() && !m_selection.is_empty() && m_canvas_type != CanvasAssembleView) { auto _do_rotate = [this](double angle_z_rad) { + if (m_gizmos.is_ban_move_glvolume()) { + return; + } if (!m_gizmos.get_gizmo_active_condition(GLGizmosManager::EType::Rotate)) { return; } - m_selection.start_dragging(); + m_selection.setup_cache(); m_selection.rotate(Vec3d(0.0, 0.0, angle_z_rad), TransformationType(TransformationType::World_Relative_Joint)); - m_selection.stop_dragging(); m_dirty = true; // wxGetApp().obj_manipul()->set_dirty(); }; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp index 264903f94..3ccef182f 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp @@ -510,6 +510,8 @@ void GLGizmoRotate3D::data_changed(bool is_serializing) { } m_object_manipulation->set_init_rotation(tran); } + for (GLGizmoRotate &g : m_gizmos) + g.init_data_from_selection(m_parent.get_selection()); } bool GLGizmoRotate3D::on_is_activable() const diff --git a/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp b/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp index 138a345e3..be645f098 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp @@ -59,6 +59,7 @@ public: void set_center(const Vec3d &point) { m_custom_center = point; } void set_force_local_coordinate(bool use) { m_force_local_coordinate = use; } + void init_data_from_selection(const Selection &selection); protected: bool on_init() override; @@ -80,7 +81,6 @@ private: void transform_to_local(const Selection& selection) const; // returns the intersection of the mouse ray with the plane perpendicular to the gizmo axis, in local coordinate Vec3d mouse_position_in_local_plane(const Linef3& mouse_ray, const Selection& selection) const; - void init_data_from_selection(const Selection &selection); }; class GLGizmoRotate3D : public GLGizmoBase diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp index 6f5184c8f..0f7c417ef 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp @@ -724,6 +724,18 @@ bool GLGizmosManager::is_show_only_active_plate() return false; } +bool GLGizmosManager::is_ban_move_glvolume() +{ + auto current_type = get_current_type(); + if (current_type == GLGizmosManager::EType::Undefined || + current_type == GLGizmosManager::EType::Move || + current_type == GLGizmosManager::EType::Rotate || + current_type == GLGizmosManager::EType::Scale) { + return false; + } + return true; +} + bool GLGizmosManager::get_gizmo_active_condition(GLGizmosManager::EType type) { if (auto cur_gizmo = get_gizmo(type)) { return cur_gizmo->is_activable(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp index 6df7ad3d5..57646797c 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp @@ -294,6 +294,7 @@ public: bool is_gizmo_activable_when_single_full_instance(); bool is_gizmo_click_empty_not_exit(); bool is_show_only_active_plate(); + bool is_ban_move_glvolume(); bool get_gizmo_active_condition(GLGizmosManager::EType type); void check_object_located_outside_plate(bool change_plate =true); bool get_object_located_outside_plate() { return m_object_located_outside_plate; }