Sketcher: Mass operations on dimensionals

=========================================

This commit introduces two functions to operate on all datum constraints exclusively:

- Make all datum constraints driving or not driving, depending on the argument.
- Move all datum constraints at the end of the constraint list.

The practical use an ongoing effort towards improving the block constraint behaviour, that will be defered to 0.19
This commit is contained in:
Abdullah Tahiri
2018-10-29 11:07:12 +01:00
committed by Yorik van Havre
parent 21f2e79021
commit 7129b3ca0e
2 changed files with 110 additions and 16 deletions

View File

@@ -326,14 +326,10 @@ int SketchObject::setDriving(int ConstrId, bool isdriving)
{
const std::vector<Constraint *> &vals = this->Constraints.getValues();
if (ConstrId < 0 || ConstrId >= int(vals.size()))
return -1;
int ret = testDrivingChange(ConstrId, isdriving);
if (!vals[ConstrId]->isDimensional())
return -2;
if (!(vals[ConstrId]->First>=0 || vals[ConstrId]->Second>=0 || vals[ConstrId]->Third>=0) && isdriving==true)
return -3; // a constraint that does not have at least one element as not-external-geometry can never be driving.
if(ret < 0)
return ret;
// copy the list
std::vector<Constraint *> newVals(vals);
@@ -370,14 +366,10 @@ int SketchObject::toggleDriving(int ConstrId)
{
const std::vector<Constraint *> &vals = this->Constraints.getValues();
if (ConstrId < 0 || ConstrId >= int(vals.size()))
return -1;
int ret = testDrivingChange(ConstrId,!vals[ConstrId]->isDriving);
if (!vals[ConstrId]->isDimensional())
return -2;
if (!(vals[ConstrId]->First>=0 || vals[ConstrId]->Second>=0 || vals[ConstrId]->Third>=0) && vals[ConstrId]->isDriving==false)
return -3; // a constraint that does not have at least one element as not-external-geometry can never be driving.
if(ret<0)
return ret;
const Part::Geometry * geo1 = getGeometry(vals[ConstrId]->First);
const Part::Geometry * geo2 = getGeometry(vals[ConstrId]->Second);
@@ -389,7 +381,7 @@ int SketchObject::toggleDriving(int ConstrId)
if (extorconstructionpoint1 && extorconstructionpoint2 && extorconstructionpoint3 && vals[ConstrId]->isDriving==false)
return -4;
// copy the list
std::vector<Constraint *> newVals(vals);
// clone the changed Constraint
@@ -407,6 +399,97 @@ int SketchObject::toggleDriving(int ConstrId)
return 0;
}
int SketchObject::testDrivingChange(int ConstrId, bool isdriving)
{
const std::vector<Constraint *> &vals = this->Constraints.getValues();
if (ConstrId < 0 || ConstrId >= int(vals.size()))
return -1;
if (!vals[ConstrId]->isDimensional())
return -2;
if (!(vals[ConstrId]->First>=0 || vals[ConstrId]->Second>=0 || vals[ConstrId]->Third>=0) && isdriving==true)
return -3; // a constraint that does not have at least one element as not-external-geometry can never be driving.
return 0;
}
/// Make all dimensionals Driving/non-Driving
int SketchObject::setDatumsDriving(bool isdriving)
{
const std::vector<Constraint *> &vals = this->Constraints.getValues();
std::vector<Constraint *> newVals(vals);
std::vector< Constraint * > tbd; // list of dynamically allocated memory that need to be deleted;
for(size_t i=0; i<newVals.size(); i++) {
if(!testDrivingChange(i, isdriving)) {
Constraint *constNew = newVals[i]->clone();
constNew->isDriving = isdriving;
newVals[i] = constNew;
tbd.push_back(constNew);
}
}
this->Constraints.setValues(newVals);
for(size_t i = 0; i < newVals.size(); i++) {
if (!isdriving && newVals[i]->isDimensional())
setExpression(Constraints.createPath(i), boost::shared_ptr<App::Expression>());
}
for(auto &t : tbd)
delete t;
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::moveDatumsToEnd(void)
{
const std::vector<Constraint *> &vals = this->Constraints.getValues();
std::vector<Constraint *> copy(vals);
std::vector<Constraint *> newVals(vals.size());
int addindex= copy.size()-1;
// add the dimensionals at the end
for(int i= copy.size()-1 ; i >= 0; i--) {
if(copy[i]->isDimensional()) {
newVals[addindex] = copy[i];
addindex--;
}
}
// add the non-dimensionals
for(int i = copy.size()-1; i >= 0; i--) {
if(!copy[i]->isDimensional()) {
newVals[addindex] = copy[i];
addindex--;
}
}
this->Constraints.setValues(newVals);
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::setVirtualSpace(int ConstrId, bool isinvirtualspace)
{
const std::vector<Constraint *> &vals = this->Constraints.getValues();

View File

@@ -113,7 +113,7 @@ public:
/// Copy the constraints instead of cloning them and copying the expressions if any
int addCopyOfConstraints(const SketchObject &orig);
/// add constraint
int addConstraint(const Constraint *constraint);
int addConstraint(const Constraint *constraint);
/// delete constraint
int delConstraint(int ConstrId);
int delConstraints(std::vector<int> ConstrIds, bool updategeometry=true);
@@ -179,6 +179,12 @@ public:
int getDriving(int ConstrId, bool &isdriving);
/// toggle the driving status of this constraint
int toggleDriving(int ConstrId);
/// Make all dimensionals Driving/non-Driving
int setDatumsDriving(bool isdriving);
/// Move Dimensional constraints at the end of the properties array
int moveDatumsToEnd(void);
/// set the driving status of this constraint and solve
int setVirtualSpace(int ConstrId, bool isinvirtualspace);
/// get the driving status of this constraint
@@ -408,6 +414,11 @@ protected:
\retval list - the supported geometry list
*/
std::vector<Part::Geometry *> supportedGeometry(const std::vector<Part::Geometry *> &geoList) const;
// refactoring functions
// check whether constraint may be changed driving status
int testDrivingChange(int ConstrId, bool isdriving);
private:
/// Flag to allow external geometry from other bodies than the one this sketch belongs to