From 7872d0b3bc2019eba31cd0f539ef8e434b6359a4 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Tue, 28 Sep 2021 20:06:52 +0200 Subject: [PATCH] Sketcher: Overload setVirtualSpace to allow setting a group of constraints --- src/Mod/Sketcher/App/SketchObject.cpp | 32 +++++++++++++++++++++++++++ src/Mod/Sketcher/App/SketchObject.h | 2 ++ 2 files changed, 34 insertions(+) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index ac03e294ec..dc165de246 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -622,6 +622,38 @@ int SketchObject::setVirtualSpace(int ConstrId, bool isinvirtualspace) return 0; } +int SketchObject::setVirtualSpace(std::vector constrIds, bool isinvirtualspace) +{ + Base::StateLocker lock(managedoperation, true); // no need to check input data validity as this is an sketchobject managed operation. + + if (constrIds.empty()) + return 0; + + std::sort(constrIds.begin(),constrIds.end()); + + const std::vector< Constraint * > &vals = this->Constraints.getValues(); + + if (constrIds.front() < 0 || constrIds.back() >= int(vals.size())) + return -1; + + std::vector< Constraint * > newVals(vals); + + for(auto cid : constrIds) { + // clone the changed Constraint + if(vals[cid]->isInVirtualSpace != isinvirtualspace) { + Constraint *constNew = vals[cid]->clone(); + constNew->isInVirtualSpace = isinvirtualspace; + newVals[cid] = constNew; + } + } + + this->Constraints.setValues(std::move(newVals)); + + return 0; +} + + + int SketchObject::getVirtualSpace(int ConstrId, bool &isinvirtualspace) const { const std::vector &vals = this->Constraints.getValues(); diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index dfa127b057..fe2f9453be 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -244,6 +244,8 @@ public: /// set the driving status of this constraint and solve int setVirtualSpace(int ConstrId, bool isinvirtualspace); + /// set the driving status of a group of constraints at once + int setVirtualSpace(std::vector constrIds, bool isinvirtualspace); /// get the driving status of this constraint int getVirtualSpace(int ConstrId, bool &isinvirtualspace) const; /// toggle the driving status of this constraint