Bug fix: General reduction solution / new sketch solving model

=================================================================

The new solving architecture focus all the solving on the SketchObject.

Actions that change the DoF can call execute() (i.e. recompute) or Solve() depending on whether a full recompute of dependent features is required or not.
In both calls the geometry of the solver is updated with the geometry of the SketchObject.

The only additional call that calls the solver is MovePoint. This function may or may not update the geometry of the SketchObject
(as now it is intended for UI related solving, like dragging, rubberbands, ...).

In operations that do not involve a change of DoF and therefore do not require a sketch solving, it may happen that as a side effect of moving a point, the
geometry changes to old behaviour. In order to avoid that, those SketchObject operations, as for example setConstruction or ToggleConstruction,
must set a flag "bool solverNeedsUpdate" to true. In case a movePoint is executed before any other solver execution, the geometry is first updated and then
the moving is performed.

So to keep in mind when programming sketcher operations:
-> Need recompute (UpdateActive)
-> Need solving because DoF changed (solve())
-> The operation does not change DoF (set solverNeedsUpdate to true)
This commit is contained in:
Abdullah Tahiri 2015-06-08 16:09:34 +02:00 committed by wmayer
parent 4b0bd78814
commit eb7a3c763c
2 changed files with 23 additions and 5 deletions

View File

@ -89,6 +89,8 @@ SketchObject::SketchObject()
lastSolverStatus=0;
lastSolveTime=0;
solverNeedsUpdate=false;
noRecomputes=false;
}
@ -127,7 +129,9 @@ App::DocumentObjectExecReturn *SketchObject::execute(void)
lastHasConflict = solvedSketch.hasConflicts();
lastHasRedundancies = solvedSketch.hasRedundancies();
lastConflicting=solvedSketch.getConflicting();
lastRedundant=solvedSketch.getRedundant();
lastRedundant=solvedSketch.getRedundant();
solverNeedsUpdate=false;
if (lastDoF < 0) { // over-constrained sketch
std::string msg="Over-constrained sketch\n";
@ -195,6 +199,8 @@ int SketchObject::solve()
lastDoF = solvedSketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(),
getExternalGeometryCount());
solverNeedsUpdate=false;
lastHasConflict = solvedSketch.hasConflicts();
int err=0;
@ -362,14 +368,16 @@ int SketchObject::movePoint(int GeoId, PointPos PosId, const Base::Vector3d& toP
// of SketchObject upon moving. => use updateGeometry parameter = true then
if(updateGeometry) {
if(updateGeometry || solverNeedsUpdate) {
lastDoF = solvedSketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(),
getExternalGeometryCount());
lastHasConflict = solvedSketch.hasConflicts();
lastHasRedundancies = solvedSketch.hasRedundancies();
lastConflicting=solvedSketch.getConflicting();
lastRedundant=solvedSketch.getRedundant();
lastRedundant=solvedSketch.getRedundant();
solverNeedsUpdate=false;
}
if (lastDoF < 0) // over-constrained sketch
@ -583,6 +591,7 @@ int SketchObject::toggleConstruction(int GeoId)
this->Geometry.setValues(newVals);
//this->Constraints.acceptGeometry(getCompleteGeometry()); <= This is not necessary for a toggle. Reducing redundant solving. Abdullah
solverNeedsUpdate=true;
return 0;
}
@ -600,6 +609,7 @@ int SketchObject::setConstruction(int GeoId, bool on)
this->Geometry.setValues(newVals);
//this->Constraints.acceptGeometry(getCompleteGeometry()); <= This is not necessary for a toggle. Reducing redundant solving. Abdullah
solverNeedsUpdate=true;
return 0;
}

View File

@ -51,7 +51,7 @@ public:
App ::PropertyLinkSubList ExternalGeometry;
/** @name methods overide Feature */
//@{
/// recalculate the Feature
/// recalculate the Feature (if no recompute is needed see also solve() and updateSolverGeometry() )
App::DocumentObjectExecReturn *execute(void);
/// returns the type name of the ViewProvider
@ -118,7 +118,10 @@ public:
/// returns non zero if the sketch contains conflicting constraints
int hasConflicts(void);
/// solves the sketch and updates the Geometry
/** solves the sketch and updates the geometry, but not all the dependent features (does not recompute)
When a recompute is necessary, recompute triggers execute() which solves the sketch and updates all dependent features
When a solve only is necessary (e.g. DoF changed), solve() solves the sketch and updates the geometry, but does not trigger any updates
*/
int solve();
/// set the datum of a Distance or Angle constraint and solve
int setDatum(int ConstrId, double Datum);
@ -233,6 +236,11 @@ private:
Sketch solvedSketch;
/** this internal flag indicate that an operation modifying the geometry, but not the DoF of the sketch took place (e.g. toggle construction),
so if next action is a movement of a point (movePoint), the geometry must be updated first.
*/
bool solverNeedsUpdate;
int lastDoF;
bool lastHasConflict;
bool lastHasRedundancies;