Sketcher: Fix reverting of geometry on undoing a new constraint

This commit is contained in:
logari81 2012-12-08 23:45:21 +01:00
parent d838f44e3c
commit db901921db
3 changed files with 30 additions and 21 deletions

View File

@ -144,6 +144,29 @@ int SketchObject::hasConflicts(void) const
return 0;
}
int SketchObject::solve()
{
// set up a sketch (including dofs counting and diagnosing of conflicts)
Sketch sketch;
int dofs = sketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(),
getExternalGeometryCount());
int err=0;
if (dofs < 0) // over-constrained sketch
err = -3;
else if (sketch.hasConflicts()) // conflicting constraints
err = -3;
else if (sketch.solve() != 0) // solving
err = -2;
if (err == 0) {
// set the newly solved geometry
std::vector<Part::Geometry *> geomlist = sketch.extractGeometry();
Geometry.setValues(geomlist);
for (std::vector<Part::Geometry *>::iterator it = geomlist.begin(); it != geomlist.end(); ++it)
if (*it) delete *it;
}
}
int SketchObject::setDatum(int ConstrId, double Datum)
{
// set the changed value for the constraint
@ -170,26 +193,8 @@ int SketchObject::setDatum(int ConstrId, double Datum)
this->Constraints.setValues(newVals);
delete constNew;
// set up a sketch (including dofs counting and diagnosing of conflicts)
Sketch sketch;
int dofs = sketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(),
getExternalGeometryCount());
int err=0;
if (dofs < 0) // over-constrained sketch
err = -3;
else if (sketch.hasConflicts()) // conflicting constraints
err = -3;
else if (sketch.solve() != 0) // solving
err = -2;
if (err == 0) {
// set the newly solved geometry
std::vector<Part::Geometry *> geomlist = sketch.extractGeometry();
Geometry.setValues(geomlist);
for (std::vector<Part::Geometry *>::iterator it = geomlist.begin(); it != geomlist.end(); ++it)
if (*it) delete *it;
}
else
int err = solve();
if (err)
this->Constraints.setValues(vals);
return err;

View File

@ -104,6 +104,8 @@ public:
/// returns non zero if the sketch contains conflicting constraints
int hasConflicts(void) const;
/// solves the sketch and updates the Geometry
int solve();
/// set the datum of a Distance or Angle constraint and solve
int setDatum(int ConstrId, double Datum);
/// move this point to a new location and solve

View File

@ -107,7 +107,9 @@ PyObject* SketchObjectPy::addConstraint(PyObject *args)
if (PyObject_TypeCheck(pcObj, &(Sketcher::ConstraintPy::Type))) {
Sketcher::Constraint *constr = static_cast<Sketcher::ConstraintPy*>(pcObj)->getConstraintPtr();
return Py::new_reference_to(Py::Int(this->getSketchObjectPtr()->addConstraint(constr)));
int ret = this->getSketchObjectPtr()->addConstraint(constr);
this->getSketchObjectPtr()->solve();
return Py::new_reference_to(Py::Int(ret));
}
Py_Return;
}