Merge branch 'fs_SPE-2126'

This commit is contained in:
Lukas Matena 2024-06-12 19:15:08 +02:00
commit fa1bb08d25
4 changed files with 74 additions and 12 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

@ -1345,18 +1345,38 @@ bool GLGizmoEmboss::process(bool make_snapshot)
void GLGizmoEmboss::close()
{
// remove volume when text is empty
if (m_volume != nullptr &&
m_volume->text_configuration.has_value() &&
is_text_empty(m_text)) {
Plater &p = *wxGetApp().plater();
// is the text object?
if (m_volume->is_the_only_one_part()) {
// delete whole object
p.remove(m_parent.get_selection().get_object_idx());
} else {
// delete text volume
p.remove_selected();
m_volume->text_configuration.has_value() ){
// remove volume when text is empty
if (is_text_empty(m_text)) {
Plater &p = *wxGetApp().plater();
// is the text object?
if (m_volume->is_the_only_one_part()) {
// delete whole object
p.remove(m_parent.get_selection().get_object_idx());
} else {
// delete text volume
p.remove_selected();
}
}
// Fix phanthom transformation
// appear when right click into scene during edit Rotation in input (click "Edit" button)
const GLVolume *gl_volume_ptr = m_parent.get_selection().get_first_volume();
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);
}
}
}

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