Skip to content

Commit

Permalink
[Sketcher] Allow driving constraint on construction geometry
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AjinkyaDahale authored and abdullahtahiriyo committed Oct 16, 2022
1 parent f50d1c3 commit 3d7871f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 46 deletions.
45 changes: 0 additions & 45 deletions src/Mod/Sketcher/App/SketchObject.cpp
Expand Up @@ -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<Constraint *> &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<Constraint *> 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<App::Expression>());


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<Constraint *> &vals = this->Constraints.getValues();
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Sketcher/App/SketchObject.h
Expand Up @@ -229,7 +229,7 @@ class SketcherExport SketchObject : public Part::Part2DObject
/// 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);
Expand Down

0 comments on commit 3d7871f

Please sign in to comment.