From 97f63f167e80e859fec49666c8986f5a01f61838 Mon Sep 17 00:00:00 2001 From: "zhou.xu" Date: Thu, 11 Jul 2024 10:56:21 +0800 Subject: [PATCH] FIX:limit scaling ratio by grabber in scale tool jira: none Change-Id: I20a4404d4e4025ae230ab46ba8d8d3e5ffed10e3 --- src/slic3r/GUI/Gizmos/GLGizmoScale.cpp | 10 ++++++++++ src/slic3r/GUI/Gizmos/GLGizmoScale.hpp | 2 +- .../GUI/Gizmos/GizmoObjectManipulation.cpp | 17 +++++++++++------ .../GUI/Gizmos/GizmoObjectManipulation.hpp | 2 ++ 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp b/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp index d51d971dc..255d3a232 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp @@ -29,7 +29,17 @@ GLGizmoScale3D::GLGizmoScale3D(GLCanvas3D& parent, const std::string& icon_filen , m_snap_step(0.05) //BBS: GUI refactor: add obj manipulation , m_object_manipulation(obj_manipulation) +{} + +const Vec3d &GLGizmoScale3D::get_scale() { + if (m_object_manipulation) { + Vec3d cache_scale = m_object_manipulation->get_cache().scale.cwiseQuotient(Vec3d(100,100,100)); + Vec3d temp_scale = cache_scale.cwiseProduct(m_scale); + m_object_manipulation->limit_scaling_ratio(temp_scale); + m_scale = temp_scale.cwiseQuotient(cache_scale); + } + return m_scale; } std::string GLGizmoScale3D::get_tooltip() const diff --git a/src/slic3r/GUI/Gizmos/GLGizmoScale.hpp b/src/slic3r/GUI/Gizmos/GLGizmoScale.hpp index bfcd102e1..e03f84345 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoScale.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoScale.hpp @@ -52,7 +52,7 @@ public: double get_snap_step(double step) const { return m_snap_step; } void set_snap_step(double step) { m_snap_step = step; } - const Vec3d& get_scale() const { return m_scale; } + const Vec3d &get_scale(); void set_scale(const Vec3d& scale) { m_starting.scale = scale; m_scale = scale; } const Vec3d& get_offset() const { return m_offset; } diff --git a/src/slic3r/GUI/Gizmos/GizmoObjectManipulation.cpp b/src/slic3r/GUI/Gizmos/GizmoObjectManipulation.cpp index e60b7aee7..8ce03036a 100644 --- a/src/slic3r/GUI/Gizmos/GizmoObjectManipulation.cpp +++ b/src/slic3r/GUI/Gizmos/GizmoObjectManipulation.cpp @@ -395,18 +395,23 @@ void GizmoObjectManipulation::do_scale(int axis, const Vec3d &scale) const transformation_type.set_relative(); Vec3d scaling_factor = m_uniform_scale ? scale(axis) * Vec3d::Ones() : scale; - for (size_t i = 0; i < scaling_factor.size(); i++) {//range protect //scaling_factor too big has problem - if (scaling_factor[i] * m_unscale_size[i] > MAX_NUM) { - scaling_factor[i] = MAX_NUM/ m_unscale_size[i]; - } - } + limit_scaling_ratio(scaling_factor); + selection.start_dragging(); selection.scale(scaling_factor, transformation_type); m_glcanvas.do_scale(L("Set Scale")); } -void GizmoObjectManipulation::on_change(const std::string& opt_key, int axis, double new_value) +void GizmoObjectManipulation::limit_scaling_ratio(Vec3d &scaling_factor) const{ + for (size_t i = 0; i < scaling_factor.size(); i++) { // range protect //scaling_factor too big has problem + if (scaling_factor[i] * m_unscale_size[i] > MAX_NUM) { + scaling_factor[i] = MAX_NUM / m_unscale_size[i]; + } + } +} + +void GizmoObjectManipulation::on_change(const std::string &opt_key, int axis, double new_value) { if (!m_cache.is_valid()) return; diff --git a/src/slic3r/GUI/Gizmos/GizmoObjectManipulation.hpp b/src/slic3r/GUI/Gizmos/GizmoObjectManipulation.hpp index 1186568cc..af3c5d3f8 100644 --- a/src/slic3r/GUI/Gizmos/GizmoObjectManipulation.hpp +++ b/src/slic3r/GUI/Gizmos/GizmoObjectManipulation.hpp @@ -117,8 +117,10 @@ public: bool is_instance_coordinates() const { return m_coordinates_type == ECoordinatesType::Instance; } bool is_local_coordinates() const { return m_coordinates_type == ECoordinatesType::Local; } + const Cache& get_cache() {return m_cache; } void reset_cache() { m_cache.reset(); } + void limit_scaling_ratio(Vec3d &scaling_factor) const; void on_change(const std::string& opt_key, int axis, double new_value); bool render_combo(ImGuiWrapper *imgui_wrapper, const std::string &label, const std::vector &lines, size_t &selection_idx, float label_width, float item_width); void do_render_move_window(ImGuiWrapper *imgui_wrapper, std::string window_name, float x, float y, float bottom_limit);