diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 7724f5d6ab..e7b95f71db 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -420,6 +420,64 @@ int SketchObject::testDrivingChange(int ConstrId, bool isdriving) return 0; } +int SketchObject::setActive(int ConstrId, bool isactive) +{ + const std::vector &vals = this->Constraints.getValues(); + + if (ConstrId < 0 || ConstrId >= int(vals.size())) + return -1; + + // copy the list + std::vector newVals(vals); + // clone the changed Constraint + Constraint *constNew = vals[ConstrId]->clone(); + constNew->isActive = isactive; + newVals[ConstrId] = constNew; + this->Constraints.setValues(newVals); + + delete constNew; + + if(noRecomputes) // if we do not have a recompute, the sketch must be solved to update the DoF of the solver + solve(); + + return 0; +} + +int SketchObject::getActive(int ConstrId, bool &isactive) +{ + const std::vector &vals = this->Constraints.getValues(); + + if (ConstrId < 0 || ConstrId >= int(vals.size())) + return -1; + + isactive = vals[ConstrId]->isActive; + + return 0; +} + +int SketchObject::toggleActive(int ConstrId) +{ + const std::vector &vals = this->Constraints.getValues(); + + if (ConstrId < 0 || ConstrId >= int(vals.size())) + return -1; + + // copy the list + std::vector newVals(vals); + // clone the changed Constraint + Constraint *constNew = vals[ConstrId]->clone(); + constNew->isActive = !constNew->isActive; + newVals[ConstrId] = constNew; + this->Constraints.setValues(newVals); + + delete constNew; + + if(noRecomputes) // if we do not have a recompute, the sketch must be solved to update the DoF of the solver + solve(); + + return 0; +} + /// Make all dimensionals Driving/non-Driving int SketchObject::setDatumsDriving(bool isdriving) diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index dbf4449905..8ce03b6a32 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -179,6 +179,13 @@ public: /// toggle the driving status of this constraint int toggleDriving(int ConstrId); + /// set the driving status of this constraint and solve + int setActive(int ConstrId, bool isactive); + /// get the driving status of this constraint + int getActive(int ConstrId, bool &isactive); + /// toggle the driving status of this constraint + int toggleActive(int ConstrId); + /// Make all dimensionals Driving/non-Driving int setDatumsDriving(bool isdriving); /// Move Dimensional constraints at the end of the properties array