diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 59bdb450d6..bb9d831ad3 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -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); diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index b33a1b21e0..66277754e1 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -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