diff --git a/src/Mod/Sketcher/App/Sketch.cpp b/src/Mod/Sketcher/App/Sketch.cpp index 72811c6e98..040cfcc594 100644 --- a/src/Mod/Sketcher/App/Sketch.cpp +++ b/src/Mod/Sketcher/App/Sketch.cpp @@ -2581,6 +2581,30 @@ int Sketch::addConstraints( return rtn; } +bool Sketch::updateConstraints(const std::vector& constrIds, + const std::vector& ConstraintList) +{ + if (Constrs.size() != ConstraintList.size()) { + return false; + } + + int size = static_cast(ConstraintList.size()); + auto it = std::find_if(constrIds.begin(), constrIds.end(), [size](int id) { + return id < 0 || id >= size; + }); + if (it != constrIds.end()) { + return false; + } + + for (int id : constrIds) { + Constraint* constr = ConstraintList[id]; + Constrs[id].constr = constr; + Constrs[id].driving = constr->isDriving; + } + + return true; +} + void Sketch::getBlockedGeometry( std::vector& blockedGeometry, std::vector& unenforceableConstraints, diff --git a/src/Mod/Sketcher/App/Sketch.h b/src/Mod/Sketcher/App/Sketch.h index 99a4a44a2e..0aad671354 100644 --- a/src/Mod/Sketcher/App/Sketch.h +++ b/src/Mod/Sketcher/App/Sketch.h @@ -250,6 +250,10 @@ public: /// add one constraint to the sketch int addConstraint(const Constraint* constraint); + /// Updates the internal constraints of the given indexes + bool updateConstraints(const std::vector& constrIds, + const std::vector& ConstraintList); + /** * add a fixed X coordinate constraint to a point * diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index afc31b5c3f..8f33f98556 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -1180,6 +1180,7 @@ int SketchObject::setLabelPosition(int ConstrId, float value) constNew->LabelPosition = value; newVals[ConstrId] = constNew; this->Constraints.setValues(std::move(newVals)); + solvedSketch.updateConstraints({ConstrId}, this->Constraints.getValues()); return 0; } @@ -1214,6 +1215,7 @@ int SketchObject::setLabelDistance(int ConstrId, float value) constNew->LabelDistance = value; newVals[ConstrId] = constNew; this->Constraints.setValues(std::move(newVals)); + solvedSketch.updateConstraints({ConstrId}, this->Constraints.getValues()); return 0; } @@ -1405,6 +1407,7 @@ int SketchObject::setVirtualSpace(int ConstrId, bool isinvirtualspace) newVals[ConstrId] = constNew; this->Constraints.setValues(std::move(newVals)); + solvedSketch.updateConstraints({ConstrId}, this->Constraints.getValues()); // Solver didn't actually update, but we need this to inform view provider // to redraw @@ -1440,6 +1443,7 @@ int SketchObject::setVirtualSpace(std::vector constrIds, bool isinvirtualsp } this->Constraints.setValues(std::move(newVals)); + solvedSketch.updateConstraints(constrIds, this->Constraints.getValues()); // Solver didn't actually update, but we need this to inform view provider // to redraw @@ -1479,6 +1483,7 @@ int SketchObject::toggleVirtualSpace(int ConstrId) newVals[ConstrId] = constNew; this->Constraints.setValues(std::move(newVals)); + solvedSketch.updateConstraints({ConstrId}, this->Constraints.getValues()); // Solver didn't actually update, but we need this to inform view provider // to redraw