From ff13a7c99bde28cf1549f986f13d53080aeb05a8 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Fri, 5 Jan 2024 14:25:05 +0100 Subject: [PATCH 1/2] Store undo/redo snap after stop input-sliding --- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 32 +++++++++++++++++----- src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp | 36 ++++++++++++++++++------- src/slic3r/GUI/SurfaceDrag.cpp | 25 +++-------------- src/slic3r/GUI/SurfaceDrag.hpp | 8 +++--- 4 files changed, 61 insertions(+), 40 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index b92b931ded..6cccfa3c09 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -77,6 +77,14 @@ using namespace Slic3r::GUI; using namespace Slic3r::GUI::Emboss; namespace { +// TRN - Title in Undo/Redo stack after rotate with text around emboss axe +const std::string rotation_snapshot_name = L("Text rotate"); +// NOTE: Translation is made in "m_parent.do_rotate()" + +// TRN - Title in Undo/Redo stack after move with text along emboss axe - From surface +const std::string move_snapshot_name = L("Text move"); +// NOTE: Translation is made in "m_parent.do_translate()" + template struct Limit { // Limitation for view slider range in GUI MinMax gui; @@ -978,7 +986,7 @@ void GLGizmoEmboss::on_stop_dragging() m_rotate_gizmo.set_angle(PI/2); // apply rotation - m_parent.do_rotate(L("Text-Rotate")); + m_parent.do_rotate(rotation_snapshot_name); m_rotate_start_angle.reset(); volume_transformation_changed(); } @@ -2139,7 +2147,7 @@ void fix_transformation(const StyleManager::Style &from, const StyleManager::Sty // fix rotation float f_angle = f_angle_opt.value_or(.0f); float t_angle = t_angle_opt.value_or(.0f); - do_local_z_rotate(canvas, t_angle - f_angle); + do_local_z_rotate(canvas.get_selection(), t_angle - f_angle); } // fix distance (Z move) when exists difference in styles @@ -2148,7 +2156,7 @@ void fix_transformation(const StyleManager::Style &from, const StyleManager::Sty if (!is_approx(f_move_opt, t_move_opt)) { float f_move = f_move_opt.value_or(.0f); float t_move = t_move_opt.value_or(.0f); - do_local_z_move(canvas, t_move - f_move); + do_local_z_move(canvas.get_selection(), t_move - f_move); } } } // namesapce @@ -2412,6 +2420,10 @@ bool GLGizmoEmboss::revertible(const std::string &name, ImGui::SameLine(undo_offset); // change cursor postion if (draw_button(m_icons, IconType::undo)) { value = *default_value; + + // !! Fix to detect change of value after revert of float-slider + m_imgui->get_last_slider_status().deactivated_after_edit = true; + return true; } else if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", undo_tooltip.c_str()); @@ -2841,9 +2853,14 @@ void GLGizmoEmboss::draw_advanced() if (font_prop.per_glyph){ process(); } else { - do_local_z_move(m_parent, distance.value_or(.0f) - prev_distance); - } + do_local_z_move(m_parent.get_selection(), distance.value_or(.0f) - prev_distance); + } } + + // Apply move to model(backend) + if (m_imgui->get_last_slider_status().deactivated_after_edit) + m_parent.do_rotate(move_snapshot_name); + m_imgui->disabled_end(); // allowe_surface_distance // slider for Clock-wise angle in degress @@ -2865,7 +2882,7 @@ void GLGizmoEmboss::draw_advanced() Geometry::to_range_pi_pi(angle_rad); double diff_angle = angle_rad - angle; - do_local_z_rotate(m_parent, diff_angle); + do_local_z_rotate(m_parent.get_selection(), diff_angle); // calc angle after rotation const Selection &selection = m_parent.get_selection(); @@ -2882,6 +2899,9 @@ void GLGizmoEmboss::draw_advanced() if (use_surface || font_prop.per_glyph) process(); } + // Apply rotation on model (backend) + if (m_imgui->get_last_slider_status().deactivated_after_edit) + m_parent.do_rotate(rotation_snapshot_name); // Keep up - lock button icon if (!m_volume->is_the_only_one_part()) { diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp index 2d08f9d7eb..57fc48bd0b 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp @@ -51,6 +51,14 @@ GLGizmoSVG::GLGizmoSVG(GLCanvas3D &parent) // Private functions to create emboss volume namespace{ +// TRN - Title in Undo/Redo stack after rotate with SVG around emboss axe +const std::string rotation_snapshot_name = L("SVG rotate"); +// NOTE: Translation is made in "m_parent.do_rotate()" + +// TRN - Title in Undo/Redo stack after move with SVG along emboss axe - From surface +const std::string move_snapshot_name = L("SVG move"); +// NOTE: Translation is made in "m_parent.do_translate()" + // Variable keep limits for variables const struct Limits { @@ -539,7 +547,7 @@ void GLGizmoSVG::on_stop_dragging() // apply rotation // TRN This is an item label in the undo-redo stack. - m_parent.do_rotate(L("SVG-Rotate")); + m_parent.do_rotate(rotation_snapshot_name); m_rotate_start_angle.reset(); volume_transformation_changed(); @@ -1832,18 +1840,20 @@ void GLGizmoSVG::draw_distance() if (m_imgui->slider_optional_float("##distance", m_distance, min_distance, max_distance, "%.2f mm", 1.f, false, move_tooltip)) is_moved = true; } - - bool can_reset = m_distance.has_value(); - if (can_reset) { + bool is_stop_sliding = m_imgui->get_last_slider_status().deactivated_after_edit; + bool is_reseted = false; + if (m_distance.has_value()) { if (reset_button(m_icons)) { m_distance.reset(); - is_moved = true; + is_reseted = true; } else if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", _u8L("Reset distance").c_str()); } - if (is_moved) - do_local_z_move(m_parent, m_distance.value_or(.0f) - prev_distance); + if (is_moved || is_reseted) + do_local_z_move(m_parent.get_selection(), m_distance.value_or(.0f) - prev_distance); + if (is_stop_sliding || is_reseted) + m_parent.do_move(move_snapshot_name); } void GLGizmoSVG::draw_rotation() @@ -1865,7 +1875,7 @@ void GLGizmoSVG::draw_rotation() double diff_angle = angle_rad - angle; - do_local_z_rotate(m_parent, diff_angle); + do_local_z_rotate(m_parent.get_selection(), diff_angle); // calc angle after rotation m_angle = calc_angle(m_parent.get_selection()); @@ -1874,20 +1884,28 @@ void GLGizmoSVG::draw_rotation() if (m_volume->emboss_shape->projection.use_surface) process(); } + bool is_stop_sliding = m_imgui->get_last_slider_status().deactivated_after_edit; // Reset button + bool is_reseted = false; if (m_angle.has_value()) { if (reset_button(m_icons)) { - do_local_z_rotate(m_parent, -(*m_angle)); + do_local_z_rotate(m_parent.get_selection(), -(*m_angle)); m_angle.reset(); // recalculate for surface cut if (m_volume->emboss_shape->projection.use_surface) process(); + + is_reseted = true; } else if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", _u8L("Reset rotation").c_str()); } + // Apply rotation on model (backend) + if (is_stop_sliding || is_reseted) + m_parent.do_rotate(rotation_snapshot_name); + // Keep up - lock button icon if (!m_volume->is_the_only_one_part()) { ImGui::SameLine(m_gui_cfg->lock_offset); diff --git a/src/slic3r/GUI/SurfaceDrag.cpp b/src/slic3r/GUI/SurfaceDrag.cpp index 39573dbf96..100847bf48 100644 --- a/src/slic3r/GUI/SurfaceDrag.cpp +++ b/src/slic3r/GUI/SurfaceDrag.cpp @@ -322,11 +322,11 @@ bool face_selected_volume_to_camera(const Camera &camera, GLCanvas3D &canvas, co return false; ModelObject &object = *object_ptr; - ModelInstance *instance_ptr = get_model_instance(gl_volume, object); + const ModelInstance *instance_ptr = get_model_instance(gl_volume, object); assert(instance_ptr != nullptr); if (instance_ptr == nullptr) return false; - ModelInstance &instance = *instance_ptr; + const ModelInstance &instance = *instance_ptr; ModelVolume *volume_ptr = get_model_volume(gl_volume, object); assert(volume_ptr != nullptr); @@ -385,10 +385,7 @@ bool face_selected_volume_to_camera(const Camera &camera, GLCanvas3D &canvas, co return true; } -void do_local_z_rotate(GLCanvas3D &canvas, double relative_angle) -{ - Selection &selection = canvas.get_selection(); - +void do_local_z_rotate(Selection &selection, double relative_angle) { assert(!selection.is_empty()); if(selection.is_empty()) return; @@ -418,17 +415,9 @@ void do_local_z_rotate(GLCanvas3D &canvas, double relative_angle) selection.rotate(Vec3d(0., 0., relative_angle), get_drag_transformation_type(selection)); }; selection_transform(selection, selection_rotate_fnc); - - std::string snapshot_name; // empty meand no store undo / redo - // NOTE: it use L instead of _L macro because prefix _ is appended - // inside function do_move - // snapshot_name = L("Set text rotation"); - canvas.do_rotate(snapshot_name); } -void do_local_z_move(GLCanvas3D &canvas, double relative_move) { - - Selection &selection = canvas.get_selection(); +void do_local_z_move(Selection &selection, double relative_move) { assert(!selection.is_empty()); if (selection.is_empty()) return; @@ -438,12 +427,6 @@ void do_local_z_move(GLCanvas3D &canvas, double relative_move) { selection.translate(translate, TransformationType::Local); }; selection_transform(selection, selection_translate_fnc); - - std::string snapshot_name; // empty mean no store undo / redo - // NOTE: it use L instead of _L macro because prefix _ is appended inside - // function do_move - // snapshot_name = L("Set surface distance"); - canvas.do_move(snapshot_name); } TransformationType get_drag_transformation_type(const Selection &selection) diff --git a/src/slic3r/GUI/SurfaceDrag.hpp b/src/slic3r/GUI/SurfaceDrag.hpp index 9f1c0e3c07..44c57c41c7 100644 --- a/src/slic3r/GUI/SurfaceDrag.hpp +++ b/src/slic3r/GUI/SurfaceDrag.hpp @@ -136,16 +136,16 @@ bool face_selected_volume_to_camera(const Camera &camera, GLCanvas3D &canvas, co /// /// Rotation around z Axis(emboss direction) /// -/// Selected volume for rotation +/// Selected volume for rotation /// Relative angle to rotate around emboss direction -void do_local_z_rotate(GLCanvas3D &canvas, double relative_angle); +void do_local_z_rotate(Selection &selection, double relative_angle); /// /// Translation along local z Axis (emboss direction) /// -/// Selected volume for translate +/// Selected volume for translate /// Relative move along emboss direction -void do_local_z_move(GLCanvas3D &canvas, double relative_move); +void do_local_z_move(Selection &selection, double relative_move); /// /// Distiguish between object and volume From b9039c84cba331e587f1ea5475d38cdba13f6bb7 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Thu, 11 Jan 2024 10:32:45 +0100 Subject: [PATCH 2/2] Fix application of rotation and distance from surface after style change --- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 6cccfa3c09..8149496c1e 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -2148,6 +2148,8 @@ void fix_transformation(const StyleManager::Style &from, const StyleManager::Sty float f_angle = f_angle_opt.value_or(.0f); float t_angle = t_angle_opt.value_or(.0f); do_local_z_rotate(canvas.get_selection(), t_angle - f_angle); + std::string no_snapshot; + canvas.do_rotate(no_snapshot); } // fix distance (Z move) when exists difference in styles @@ -2157,6 +2159,8 @@ void fix_transformation(const StyleManager::Style &from, const StyleManager::Sty float f_move = f_move_opt.value_or(.0f); float t_move = t_move_opt.value_or(.0f); do_local_z_move(canvas.get_selection(), t_move - f_move); + std::string no_snapshot; + canvas.do_move(no_snapshot); } } } // namesapce