From 5898fc54674680dafacf0fff4a87e997aed7c3ce Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Wed, 15 May 2024 15:12:07 +0200 Subject: [PATCH] Propagate transformation from UI to backend on close embossed SVG (from GLVolume to ModelVolume) --- src/libslic3r/Point.hpp | 10 ++++++++ src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 22 ++--------------- src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp | 33 ++++++++++++++++++++++++- src/slic3r/GUI/Gizmos/GLGizmoSVG.hpp | 1 + 4 files changed, 45 insertions(+), 21 deletions(-) diff --git a/src/libslic3r/Point.hpp b/src/libslic3r/Point.hpp index 085075a611..690c30cda1 100644 --- a/src/libslic3r/Point.hpp +++ b/src/libslic3r/Point.hpp @@ -266,6 +266,16 @@ inline bool is_approx(const Vec3d &p1, const Vec3d &p2, double epsilon = EPSILON return d.x() < epsilon && d.y() < epsilon && d.z() < epsilon; } +inline bool is_approx(const Matrix3d &m1, const Matrix3d &m2, double epsilon = EPSILON) +{ + for (size_t i = 0; i < 3; i++) + for (size_t j = 0; j < 3; j++) + if (!is_approx(m1(i, j), m2(i, j), epsilon)) + return false; + + return true; +} + inline Point lerp(const Point &a, const Point &b, double t) { assert((t >= -EPSILON) && (t <= 1. + EPSILON)); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index ddc45056fd..66bc232b9c 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -1343,24 +1343,6 @@ bool GLGizmoEmboss::process(bool make_snapshot) return true; } -namespace { -// IMPROVE: Move to Point.hpp and rename to is_approx() -// NOTE: Point has its own epsilon :-( -template -inline bool is_approx2( - const Eigen::Matrix &m1, - const Eigen::Matrix &m2, - T epsilon = static_cast(EPSILON) -) { - for (size_t i = 0; i < I; i++) - for (size_t j = 0; j < J; j++) - if (!is_approx(m1(i, j), m2(i, j), epsilon)) - return false; - - return true; -} -} - void GLGizmoEmboss::close() { if (m_volume != nullptr && @@ -1390,9 +1372,9 @@ void GLGizmoEmboss::close() const Matrix3d &gl_v_rot = gl_v_tr.linear(); const Vec3d &v_move = v_tr.translation(); const Vec3d &gl_v_move = gl_v_tr.translation(); - if (!is_approx2(v_rot, gl_v_rot)) { + if (!is_approx(v_rot, gl_v_rot)) { m_parent.do_rotate(rotation_snapshot_name); - } else if (!is_approx2(v_move, gl_v_move)){ + } else if (!is_approx(v_move, gl_v_move)){ m_parent.do_move(move_snapshot_name); } } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp index 50118376ca..7b55a99041 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp @@ -331,6 +331,37 @@ void GLGizmoSVG::volume_transformation_changed() calculate_scale(); } +void GLGizmoSVG::on_mouse_confirm_edit(const wxMouseEvent &mouse_event) { + // Fix phanthom transformation + // appear when mouse click into scene during edit Rotation in input (click "Edit" button) + // this must happen just before unselect selection (to find current volume) + static bool was_dragging = true; + if ((mouse_event.LeftUp() || mouse_event.RightUp()) && + m_parent.get_first_hover_volume_idx() < 0 && + !was_dragging && + m_volume != nullptr && + m_volume->is_svg() ) { + // current volume + const GLVolume *gl_volume_ptr = m_parent.get_selection().get_first_volume(); + assert(gl_volume_ptr->geometry_id.first == m_volume->id().id); + if (gl_volume_ptr != nullptr) { + const Transform3d &v_tr = m_volume->get_matrix(); + const Transform3d &gl_v_tr = gl_volume_ptr->get_volume_transformation().get_matrix(); + + const Matrix3d &v_rot = v_tr.linear(); + const Matrix3d &gl_v_rot = gl_v_tr.linear(); + const Vec3d &v_move = v_tr.translation(); + const Vec3d &gl_v_move = gl_v_tr.translation(); + if (!is_approx(v_rot, gl_v_rot)) { + m_parent.do_rotate(rotation_snapshot_name); + } else if (!is_approx(v_move, gl_v_move)) { + m_parent.do_move(move_snapshot_name); + } + } + } + was_dragging = mouse_event.Dragging(); +} + bool GLGizmoSVG::on_mouse(const wxMouseEvent &mouse_event) { // not selected volume @@ -340,7 +371,7 @@ bool GLGizmoSVG::on_mouse(const wxMouseEvent &mouse_event) if (on_mouse_for_rotation(mouse_event)) return true; if (on_mouse_for_translate(mouse_event)) return true; - + on_mouse_confirm_edit(mouse_event); return false; } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSVG.hpp b/src/slic3r/GUI/Gizmos/GLGizmoSVG.hpp index 103051c0fa..42cd3fc007 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSVG.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSVG.hpp @@ -129,6 +129,7 @@ private: // process mouse event bool on_mouse_for_rotation(const wxMouseEvent &mouse_event); bool on_mouse_for_translate(const wxMouseEvent &mouse_event); + void on_mouse_confirm_edit(const wxMouseEvent &mouse_event); void volume_transformation_changed();