Skip to content

Commit

Permalink
clear expression when setting constraint non-driving
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Nov 11, 2016
1 parent 025cf18 commit 1df6da7
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/Mod/Sketcher/App/SketchObject.cpp
Expand Up @@ -311,10 +311,10 @@ int SketchObject::setDatum(int ConstrId, double Datum)
int SketchObject::setDriving(int ConstrId, bool isdriving)
{
const std::vector<Constraint *> &vals = this->Constraints.getValues();

if (ConstrId < 0 || ConstrId >= int(vals.size()))
return -1;

ConstraintType type = vals[ConstrId]->Type;

if (type != Distance &&
Expand All @@ -324,7 +324,7 @@ int SketchObject::setDriving(int ConstrId, bool isdriving)
type != Angle &&
type != SnellsLaw)
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.

Expand All @@ -335,10 +335,10 @@ int SketchObject::setDriving(int ConstrId, bool isdriving)
constNew->isDriving = isdriving;
newVals[ConstrId] = constNew;
this->Constraints.setValues(newVals);
if (isdriving)
if (!isdriving)
setExpression(Constraints.createPath(ConstrId), boost::shared_ptr<App::Expression>());
delete constNew;

if(noRecomputes) // if we do not have a recompute, the sketch must be solved to update the DoF of the solver
solve();

Expand All @@ -351,9 +351,9 @@ int SketchObject::getDriving(int ConstrId, bool &isdriving)

if (ConstrId < 0 || ConstrId >= int(vals.size()))
return -1;

ConstraintType type = vals[ConstrId]->Type;

if (type != Distance &&
type != DistanceX &&
type != DistanceY &&
Expand All @@ -372,7 +372,7 @@ int SketchObject::toggleDriving(int ConstrId)

if (ConstrId < 0 || ConstrId >= int(vals.size()))
return -1;

ConstraintType type = vals[ConstrId]->Type;

if (type != Distance &&
Expand All @@ -382,21 +382,21 @@ int SketchObject::toggleDriving(int ConstrId)
type != Angle &&
type != SnellsLaw)
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.

// copy the list
std::vector<Constraint *> newVals(vals);
// clone the changed Constraint
Constraint *constNew = vals[ConstrId]->clone();
constNew->isDriving = !constNew->isDriving;
newVals[ConstrId] = constNew;
this->Constraints.setValues(newVals);
if (constNew->isDriving)
if (!constNew->isDriving)
setExpression(Constraints.createPath(ConstrId), boost::shared_ptr<App::Expression>());
delete constNew;

if(noRecomputes) // if we do not have a recompute, the sketch must be solved to update the DoF of the solver
solve();

Expand Down

0 comments on commit 1df6da7

Please sign in to comment.