Propagate transformation from UI to backend on close embossed SVG

(from GLVolume to ModelVolume)
This commit is contained in:
Filip Sykala - NTB T15p 2024-05-15 15:12:07 +02:00 committed by Lukas Matena
parent c5d94d1d95
commit 5898fc5467
4 changed files with 45 additions and 21 deletions

View File

@ -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));

View File

@ -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<typename T, int I, int J>
inline bool is_approx2(
const Eigen::Matrix<T, I, J, Eigen::DontAlign> &m1,
const Eigen::Matrix<T, I, J, Eigen::DontAlign> &m2,
T epsilon = static_cast<T>(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);
}
}

View File

@ -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;
}

View File

@ -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();