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 78c255849f
commit 9ca1206cfe
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;