[Sketcher] Fix angle constraint expression regression (#10743)
* fix 10742 * moved expression string modifier to helper function * Tests: Add example tests for SketchObject * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * made expr modifier func static, pass by value and added unit tests --------- Co-authored-by: Chris Hennes <chennes@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -660,25 +660,20 @@ int SketchObject::moveDatumsToEnd()
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void SketchObject::reverseAngleConstraintToSupplementary(Constraint* constr, int constNum)
|
||||
{
|
||||
std::swap(constr->First, constr->Second);
|
||||
std::swap(constr->FirstPos, constr->SecondPos);
|
||||
constr->FirstPos = (constr->FirstPos == Sketcher::PointPos::start) ? Sketcher::PointPos::end : Sketcher::PointPos::start;
|
||||
double actAngle = constr->getValue();
|
||||
constr->setValue(M_PI - actAngle);
|
||||
|
||||
// Edit the expression if any
|
||||
// Edit the expression if any, else modify constraint value directly
|
||||
if (constraintHasExpression(constNum)) {
|
||||
std::string expression = getConstraintExpression(constNum);
|
||||
if (expression.substr(0, 7) == "180 - (") {
|
||||
expression = expression.substr(7, expression.size() - 8);
|
||||
}
|
||||
else {
|
||||
expression = "180 - (" + expression + ")";
|
||||
}
|
||||
setConstraintExpression(constNum, expression);
|
||||
setConstraintExpression(constNum, reverseAngleConstraintExpression(expression));
|
||||
}
|
||||
else {
|
||||
double actAngle = constr->getValue();
|
||||
constr->setValue(M_PI - actAngle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -719,6 +714,30 @@ void SketchObject::setConstraintExpression(int constNum, const std::string& newE
|
||||
}
|
||||
}
|
||||
|
||||
std::string SketchObject::reverseAngleConstraintExpression(std::string expression)
|
||||
{
|
||||
// Check if expression contains units (°, deg, rad)
|
||||
if (expression.find("°") != std::string::npos
|
||||
|| expression.find("deg") != std::string::npos
|
||||
|| expression.find("rad") != std::string::npos) {
|
||||
if (expression.substr(0, 9) == "180 ° - ") {
|
||||
expression = expression.substr(9, expression.size() - 9);
|
||||
}
|
||||
else {
|
||||
expression = "180 ° - (" + expression + ")";
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (expression.substr(0, 6) == "180 - ") {
|
||||
expression = expression.substr(6, expression.size() - 6);
|
||||
}
|
||||
else {
|
||||
expression = "180 - (" + expression + ")";
|
||||
}
|
||||
}
|
||||
return expression;
|
||||
}
|
||||
|
||||
int SketchObject::setVirtualSpace(int ConstrId, bool isinvirtualspace)
|
||||
{
|
||||
// no need to check input data validity as this is an sketchobject managed operation.
|
||||
|
||||
Reference in New Issue
Block a user