diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 27df5de63..2d208284c 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -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 geomlist = sketch.extractGeometry(); + Geometry.setValues(geomlist); + for (std::vector::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 geomlist = sketch.extractGeometry(); - Geometry.setValues(geomlist); - for (std::vector::iterator it = geomlist.begin(); it != geomlist.end(); ++it) - if (*it) delete *it; - } - else + int err = solve(); + if (err) this->Constraints.setValues(vals); return err; diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index 916bde006..0cd4af863 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -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 diff --git a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp index 5f093872f..c02684585 100644 --- a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp +++ b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp @@ -107,7 +107,9 @@ PyObject* SketchObjectPy::addConstraint(PyObject *args) if (PyObject_TypeCheck(pcObj, &(Sketcher::ConstraintPy::Type))) { Sketcher::Constraint *constr = static_cast(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; }