Implement a function in sketchObject that swap an angle constraint to its supplementary.

This commit is contained in:
Paddle
2023-09-18 18:55:12 +02:00
parent 2c2a977e04
commit 3c275de11d
2 changed files with 25 additions and 0 deletions

View File

@@ -660,6 +660,28 @@ 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
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);
}
}
bool SketchObject::constraintHasExpression(int constNum)
{
App::ObjectIdentifier path = Constraints.createPath(constNum);

View File

@@ -269,6 +269,9 @@ public:
/// Move Dimensional constraints at the end of the properties array
int moveDatumsToEnd();
/// Change an angle constraint to its supplementary angle.
void reverseAngleConstraintToSupplementary(Constraint* constr, int constNum);
// Check if a constraint has an expression associated.
bool constraintHasExpression(int constNum);
// Get a constraint associated expression