Sketcher: Overload setVirtualSpace to allow setting a group of constraints

This commit is contained in:
Abdullah Tahiri
2021-09-28 20:06:52 +02:00
parent 4a47b98b16
commit 7872d0b3bc
2 changed files with 34 additions and 0 deletions

View File

@@ -622,6 +622,38 @@ int SketchObject::setVirtualSpace(int ConstrId, bool isinvirtualspace)
return 0;
}
int SketchObject::setVirtualSpace(std::vector<int> 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<Constraint *> &vals = this->Constraints.getValues();

View File

@@ -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<int> constrIds, bool isinvirtualspace);
/// get the driving status of this constraint
int getVirtualSpace(int ConstrId, bool &isinvirtualspace) const;
/// toggle the driving status of this constraint