From 1af82e621ef17cdfae1dab775bdd3ebe48d9b1df Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 28 Sep 2024 18:46:35 +0200 Subject: [PATCH 1/2] Core: Fix resetting placement of transformed image The restored Euler angles of a rotation may significantly differ from the input Euler angles so that determining the plane isn't very reliable. To get the plane reliably multiply (0,0,1) with the rotation and use this as reference normal of the plane. --- src/Gui/TaskView/TaskImage.cpp | 44 ++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/src/Gui/TaskView/TaskImage.cpp b/src/Gui/TaskView/TaskImage.cpp index 27ef04949c..c3fad9ceca 100644 --- a/src/Gui/TaskView/TaskImage.cpp +++ b/src/Gui/TaskView/TaskImage.cpp @@ -288,6 +288,9 @@ void TaskImage::onPreview() // NOLINTNEXTLINE void TaskImage::restoreAngles(const Base::Rotation& rot) { + Base::Vector3d vec(0, 0, 1); + rot.multVec(vec, vec); + double yaw {}; double pitch {}; double roll {}; @@ -300,32 +303,49 @@ void TaskImage::restoreAngles(const Base::Rotation& rot) const double angle2 = 180.0; auto isTopOrBottom = [=](bool& reverse) { - if (fabs(pitch) < tol && (fabs(roll) < tol || fabs(roll - angle2) < tol)) { - if (fabs(roll - angle2) < tol) { - reverse = true; - } + if (std::fabs(vec.z - 1.0) < tol) { + return true; + } + if (std::fabs(vec.z + 1.0) < tol) { + reverse = true; return true; } return false; }; - auto isFrontOrRear = [=](bool& reverse) { - if (fabs(roll - angle1) < tol && (fabs(yaw) < tol || fabs(yaw - angle2) < tol)) { - if (fabs(yaw - angle2) < tol) { - reverse = true; + + auto isFrontOrRear = [&](bool& reverse) { + if (std::fabs(vec.y + 1.0) < tol) { + if (std::fabs(yaw - angle2) < tol) { + pitch = -angle2 - pitch; } return true; } + if (std::fabs(vec.y - 1.0) < tol) { + if (std::fabs(yaw) < tol) { + pitch = -angle2 - pitch; + } + reverse = true; + return true; + } return false; }; - auto isRightOrLeft = [=](bool& reverse) { - if (fabs(roll - angle1) < tol && (fabs(yaw - angle1) < tol || fabs(yaw + angle1) < tol)) { - if (fabs(yaw + angle1) < tol) { - reverse = true; + + auto isRightOrLeft = [&](bool& reverse) { + if (std::fabs(vec.x - 1.0) < tol) { + if (std::fabs(yaw + angle1) < tol) { + pitch = -angle2 - pitch; } return true; } + if (std::fabs(vec.x + 1.0) < tol) { + if (std::fabs(yaw - angle1) < tol) { + pitch = -angle2 - pitch; + } + reverse = true; + return true; + } return false; }; From f6818079d4c42d326f8194db9a1f02d939bf16fc Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 28 Sep 2024 19:05:52 +0200 Subject: [PATCH 2/2] Core: Do not set to XY plane by default if the rotation of the image doesn't match --- src/Gui/TaskView/TaskImage.cpp | 4 ++++ src/Gui/TaskView/TaskImage.ui | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Gui/TaskView/TaskImage.cpp b/src/Gui/TaskView/TaskImage.cpp index c3fad9ceca..69642bb011 100644 --- a/src/Gui/TaskView/TaskImage.cpp +++ b/src/Gui/TaskView/TaskImage.cpp @@ -416,6 +416,10 @@ void TaskImage::updatePlacement() else if (ui->YZ_radioButton->isChecked()) { rot.setYawPitchRoll(90. - dir, -angle, 90.); } + else if (!feature.expired()) { + Base::Placement plm = feature->Placement.getValue(); + rot = plm.getRotation(); + } // NOLINTEND Base::Vector3d offset = Base::Vector3d(ui->spinBoxX->value().getValue(), diff --git a/src/Gui/TaskView/TaskImage.ui b/src/Gui/TaskView/TaskImage.ui index 589d949f81..37aac262c7 100644 --- a/src/Gui/TaskView/TaskImage.ui +++ b/src/Gui/TaskView/TaskImage.ui @@ -27,9 +27,6 @@ XY-Plane - - true -