From c624d40476bcb5c6d4f36e556b341352afd309be Mon Sep 17 00:00:00 2001 From: Ajinkya Dahale Date: Sun, 4 Sep 2022 14:24:14 +0530 Subject: [PATCH] [Sketcher] Allow driving constraint on construction geometry Fixes issue #7442. Also, the following commits are squashed into this one: [Sketcher] Remove unnecessary variables [Sketcher] Use `setDriving` within `toggleDriving` Suggestion courtesy @0penbrain. [Sketcher] Remove redundant check: `SketchObject::testDrivingChange` `GeoEnum::GeoUndef = -2000` so checking if it's `< 0` is redundant. --- src/Mod/Sketcher/App/SketchObject.cpp | 45 --------------------------- src/Mod/Sketcher/App/SketchObject.h | 2 +- 2 files changed, 1 insertion(+), 46 deletions(-) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 127c29d51c..152cd67e65 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -410,51 +410,6 @@ int SketchObject::getDriving(int ConstrId, bool &isdriving) return 0; } -int SketchObject::toggleDriving(int ConstrId) -{ - Base::StateLocker lock(managedoperation, true); // no need to check input data validity as this is an sketchobject managed operation. - - const std::vector &vals = this->Constraints.getValues(); - - int ret = testDrivingChange(ConstrId,!vals[ConstrId]->isDriving); - - if(ret<0) - return ret; - - const auto geof1 = getGeometryFacade(vals[ConstrId]->First); - const auto geof2 = getGeometryFacade(vals[ConstrId]->Second); - const auto geof3 = getGeometryFacade(vals[ConstrId]->Third); - - bool extorconstructionpoint1 = (vals[ConstrId]->First == GeoEnum::GeoUndef) || - (vals[ConstrId]->First < 0) || - (geof1 && geof1->isGeoType(Part::GeomPoint::getClassTypeId()) && geof1->getConstruction()); - bool extorconstructionpoint2 = (vals[ConstrId]->Second == GeoEnum::GeoUndef)|| - (vals[ConstrId]->Second < 0) || - (geof2 && geof2->isGeoType(Part::GeomPoint::getClassTypeId()) && geof2->getConstruction()); - bool extorconstructionpoint3 = (vals[ConstrId]->Third == GeoEnum::GeoUndef) || - (vals[ConstrId]->Third < 0) || - (geof3 && geof3->isGeoType(Part::GeomPoint::getClassTypeId()) && geof3->getConstruction()); - - if (extorconstructionpoint1 && extorconstructionpoint2 && extorconstructionpoint3 && !vals[ConstrId]->isDriving) - return -4; - - // copy the list - std::vector newVals(vals); - // clone the changed Constraint - Constraint *constNew = vals[ConstrId]->clone(); - constNew->isDriving = !constNew->isDriving; - newVals[ConstrId] = constNew; - this->Constraints.setValues(std::move(newVals)); - if (!constNew->isDriving) - setExpression(Constraints.createPath(ConstrId), std::shared_ptr()); - - - 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::testDrivingChange(int ConstrId, bool isdriving) { const std::vector &vals = this->Constraints.getValues(); diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index 6d79af4269..346a2d03ea 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -229,7 +229,7 @@ public: /// get the driving status of this constraint int getDriving(int ConstrId, bool &isdriving); /// toggle the driving status of this constraint - int toggleDriving(int ConstrId); + int toggleDriving(int ConstrId) {return setDriving(ConstrId, !Constraints.getValues()[ConstrId]->isDriving);} /// set the driving status of this constraint and solve int setActive(int ConstrId, bool isactive);