Refactoring Sketcher execute() to use solve()
This commit is contained in:
@@ -160,48 +160,28 @@ App::DocumentObjectExecReturn *SketchObject::execute(void)
|
||||
delConstraintsToExternal();
|
||||
}
|
||||
|
||||
// We should have an updated Sketcher geometry or this execute should not have happened
|
||||
// therefore we update our sketch object geometry with the SketchObject one.
|
||||
//
|
||||
// set up a sketch (including dofs counting and diagnosing of conflicts)
|
||||
lastDoF = solvedSketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(),
|
||||
getExternalGeometryCount());
|
||||
lastHasConflict = solvedSketch.hasConflicts();
|
||||
lastHasRedundancies = solvedSketch.hasRedundancies();
|
||||
lastConflicting=solvedSketch.getConflicting();
|
||||
lastRedundant=solvedSketch.getRedundant();
|
||||
// This includes a regular solve including full geometry update, except when an error
|
||||
// ensues
|
||||
int err = this->solve(true);
|
||||
|
||||
lastSolveTime=0.0;
|
||||
lastSolverStatus=GCS::Failed; // Failure is default for notifying the user unless otherwise proven
|
||||
|
||||
solverNeedsUpdate=false;
|
||||
|
||||
if (lastDoF < 0) { // over-constrained sketch
|
||||
if (err == -4) { // over-constrained sketch
|
||||
std::string msg="Over-constrained sketch\n";
|
||||
appendConflictMsg(lastConflicting, msg);
|
||||
return new App::DocumentObjectExecReturn(msg.c_str(),this);
|
||||
}
|
||||
if (lastHasConflict) { // conflicting constraints
|
||||
else if (err == -3) { // conflicting constraints
|
||||
std::string msg="Sketch with conflicting constraints\n";
|
||||
appendConflictMsg(lastConflicting, msg);
|
||||
return new App::DocumentObjectExecReturn(msg.c_str(),this);
|
||||
}
|
||||
if (lastHasRedundancies) { // redundant constraints
|
||||
else if (err == -2) { // redundant constraints
|
||||
std::string msg="Sketch with redundant constraints\n";
|
||||
appendRedundantMsg(lastRedundant, msg);
|
||||
return new App::DocumentObjectExecReturn(msg.c_str(),this);
|
||||
}
|
||||
// solve the sketch
|
||||
lastSolverStatus=solvedSketch.solve();
|
||||
lastSolveTime=solvedSketch.SolveTime;
|
||||
|
||||
if (lastSolverStatus != 0)
|
||||
else if (err == -1) { // Solver failed
|
||||
return new App::DocumentObjectExecReturn("Solving the sketch failed",this);
|
||||
|
||||
std::vector<Part::Geometry *> geomlist = solvedSketch.extractGeometry();
|
||||
Geometry.setValues(geomlist);
|
||||
for (std::vector<Part::Geometry *>::iterator it=geomlist.begin(); it != geomlist.end(); ++it)
|
||||
if (*it) delete *it;
|
||||
}
|
||||
|
||||
// this is not necessary for sketch representation in edit mode, unless we want to trigger an update of
|
||||
// the objects that depend on this sketch (like pads)
|
||||
@@ -254,30 +234,21 @@ int SketchObject::solve(bool updateGeoAfterSolving/*=true*/)
|
||||
// redundancy is a lower priority problem than conflict/over-constraint/solver error
|
||||
// we set it here because we are indeed going to solve, as we can. However, we still want to
|
||||
// provide the right error code.
|
||||
if (lastHasRedundancies) // redundant constraints
|
||||
if (lastHasRedundancies) { // redundant constraints
|
||||
err = -2;
|
||||
}
|
||||
|
||||
if (lastDoF < 0) { // over-constrained sketch
|
||||
err = -4;
|
||||
// if lastDoF<0, then an over-constrained situation has ensued.
|
||||
// The solver has the updated geometry of the SketchObject (see setUpSketch above).
|
||||
// However we are not trying to solve for a geometry that cannot fulfil the constraints.
|
||||
// Therefore there is no need to update the geometry at the end of this function, as it is the same.
|
||||
// However, solver information (e.g. at UI level) must be updated, so trigger an update.
|
||||
this->Constraints.touch();
|
||||
}
|
||||
else if (lastHasConflict) { // conflicting constraints
|
||||
// The situation is exactly the same as in the over-constrained situation.
|
||||
err = -3;
|
||||
this->Constraints.touch();
|
||||
}
|
||||
else {
|
||||
lastSolverStatus=solvedSketch.solve();
|
||||
if (lastSolverStatus != 0){ // solving
|
||||
err = -1;
|
||||
// if solver failed, invalid constraints were likely added before solving
|
||||
// (see solve in addConstraint), so solver information is definitely invalid.
|
||||
this->Constraints.touch();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,6 +261,11 @@ int SketchObject::solve(bool updateGeoAfterSolving/*=true*/)
|
||||
for (std::vector<Part::Geometry *>::iterator it = geomlist.begin(); it != geomlist.end(); ++it)
|
||||
if (*it) delete *it;
|
||||
}
|
||||
else if(err <0) {
|
||||
// if solver failed, invalid constraints were likely added before solving
|
||||
// (see solve in addConstraint), so solver information is definitely invalid.
|
||||
this->Constraints.touch();
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user