Fix rotation expression errors in handleLegacyTangentPlaneOrientation() (#26058)
* Fix rotation expression handling - Make added rotation angle unit the same as the original expression unit - Keep rotated angle expressions within the accepted [-180, +180] range
This commit is contained in:
@@ -607,6 +607,31 @@ void AttachExtension::handleLegacyTangentPlaneOrientation()
|
||||
}
|
||||
|
||||
// convert placement and expressions according to the dominant axis
|
||||
auto makeRotatedExpression =
|
||||
[owner](const App::Expression* expr, double angle) -> App::Expression* {
|
||||
if (!expr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string unitSafeExprStr = "(" + expr->toString() + ")";
|
||||
if (angle >= 0) {
|
||||
unitSafeExprStr += " + " + std::to_string(angle);
|
||||
}
|
||||
else {
|
||||
unitSafeExprStr += " - " + std::to_string(-angle);
|
||||
}
|
||||
|
||||
if (const App::Expression* simple = expr->eval()) {
|
||||
if (auto ue = dynamic_cast<const App::UnitExpression*>(simple)) {
|
||||
const auto& q = ue->getQuantity();
|
||||
if (q.getUnit() == Base::Unit::Angle) {
|
||||
unitSafeExprStr += " deg";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return App::ExpressionParser::parse(owner, unitSafeExprStr.c_str());
|
||||
};
|
||||
App::Expression* newExprX = nullptr;
|
||||
App::Expression* newExprY = nullptr;
|
||||
App::Expression* newExprYaw = nullptr;
|
||||
@@ -625,8 +650,12 @@ void AttachExtension::handleLegacyTangentPlaneOrientation()
|
||||
newExprX = App::ExpressionParser::parse(owner, expr.c_str());
|
||||
}
|
||||
if (exprYaw) {
|
||||
std::string expr = "(" + exprYaw->toString() + ") + 90 deg";
|
||||
newExprYaw = App::ExpressionParser::parse(owner, expr.c_str());
|
||||
if (yaw > 90) {
|
||||
newExprYaw = makeRotatedExpression(exprYaw, -270);
|
||||
}
|
||||
else {
|
||||
newExprYaw = makeRotatedExpression(exprYaw, 90);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (axis == 1) { // normal mostly Y
|
||||
@@ -644,8 +673,12 @@ void AttachExtension::handleLegacyTangentPlaneOrientation()
|
||||
newExprX = App::ExpressionParser::parse(owner, exprY->toString().c_str());
|
||||
}
|
||||
if (exprYaw) {
|
||||
std::string expr = "(" + exprYaw->toString() + ") - 90 deg";
|
||||
newExprYaw = App::ExpressionParser::parse(owner, expr.c_str());
|
||||
if (yaw < -90) {
|
||||
newExprYaw = makeRotatedExpression(exprYaw, 270);
|
||||
}
|
||||
else {
|
||||
newExprYaw = makeRotatedExpression(exprYaw, -90);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user