diff --git a/src/Mod/Sketcher/App/Sketch.cpp b/src/Mod/Sketcher/App/Sketch.cpp index 608d9da0e..969c08312 100644 --- a/src/Mod/Sketcher/App/Sketch.cpp +++ b/src/Mod/Sketcher/App/Sketch.cpp @@ -96,8 +96,9 @@ void Sketch::clear(void) Conflicting.clear(); } -int Sketch::setUpSketch(const std::vector &GeoList, const std::vector &ConstraintList, - bool withDiagnose, int extGeoCount) +int Sketch::setUpSketch(const std::vector &GeoList, + const std::vector &ConstraintList, + int extGeoCount) { clear(); @@ -121,11 +122,7 @@ int Sketch::setUpSketch(const std::vector &GeoList, const std: GCSsys.clearByTag(-1); GCSsys.clearByTag(-2); GCSsys.initSolution(Parameters); - - if (withDiagnose) - return diagnose(); - else - return 0; + return diagnose(); } const char* nameByType(Sketch::GeoType type) @@ -1606,7 +1603,7 @@ int Sketch::solve(void) break; } - // if successfully solved try write the parameters back + // if successfully solved try to write the parameters back if (ret == GCS::Success) { GCSsys.applySolution(); valid_solution = updateGeometry(); diff --git a/src/Mod/Sketcher/App/Sketch.h b/src/Mod/Sketcher/App/Sketch.h index ec108421b..3f22f7fdd 100644 --- a/src/Mod/Sketcher/App/Sketch.h +++ b/src/Mod/Sketcher/App/Sketch.h @@ -53,9 +53,21 @@ public: int solve(void); /// delete all geometry and constraints, leave an empty sketch void clear(void); - /// set the sketch up with geoms and constraints + /** set the sketch up with geoms and constraints + * + * returns the degree of freedom of a sketch and calculates a list of + * conflicting constraints + * + * 0 degrees of freedom correspond to a fully constrained sketch + * -1 degrees of freedom correspond to an over-constrained sketch + * positive degrees of freedom correspond to an under-constrained sketch + * + * an over-constrained sketch will always contain conflicting constraints + * a fully constrained or under-constrained sketch may contain conflicting + * constraints or may not + */ int setUpSketch(const std::vector &GeoList, const std::vector &ConstraintList, - bool withDiagnose=true, int extGeoCount=0); + int extGeoCount=0); /// return the actual geometry of the sketch a TopoShape Part::TopoShape toShape(void) const; /// add unspecified geometry diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 95aa455a7..c9e5b3845 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -97,7 +97,7 @@ App::DocumentObjectExecReturn *SketchObject::execute(void) rebuildExternalGeometry(); Sketch sketch; int dofs = sketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(), - true, getExternalGeometryCount()); + getExternalGeometryCount()); if (dofs < 0) { // over-constrained sketch std::string msg="Over-constrained sketch\n"; appendConflictMsg(sketch.getConflicting(), msg); @@ -128,7 +128,7 @@ int SketchObject::hasConflicts(void) const // set up a sketch (including dofs counting and diagnosing of conflicts) Sketch sketch; int dofs = sketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(), - true, getExternalGeometryCount()); + getExternalGeometryCount()); if (dofs < 0) // over-constrained sketch return -2; if (sketch.hasConflicts()) // conflicting constraints @@ -166,7 +166,7 @@ int SketchObject::setDatum(int ConstrId, double Datum) // set up a sketch (including dofs counting and diagnosing of conflicts) Sketch sketch; int dofs = sketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(), - true, getExternalGeometryCount()); + getExternalGeometryCount()); int err=0; if (dofs < 0) // over-constrained sketch err = -3; @@ -192,7 +192,7 @@ int SketchObject::movePoint(int GeoId, PointPos PosId, const Base::Vector3d& toP { Sketch sketch; int dofs = sketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(), - true, getExternalGeometryCount()); + getExternalGeometryCount()); if (dofs < 0) // over-constrained sketch return -1; if (sketch.hasConflicts()) // conflicting constraints diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index ee289f1d7..1618af878 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -2694,42 +2694,7 @@ void ViewProviderSketch::updateData(const App::Property *prop) if (edit && (prop == &(getSketchObject()->Geometry) || &(getSketchObject()->Constraints))) { edit->FullyConstrained = false; - int dofs = edit->ActSketch.setUpSketch(getSketchObject()->getCompleteGeometry(), - getSketchObject()->Constraints.getValues(), - true, getSketchObject()->getExternalGeometryCount()); - std::string msg; - if (getSketchObject()->Geometry.getSize() == 0) { - signalSetUp(-1, 0, msg); - signalSolved(-1, 0); - } - else if (dofs < 0) { // over-constrained sketch - SketchObject::appendConflictMsg(edit->ActSketch.getConflicting(), msg); - //Base::Console().Warning("Over-constrained sketch\n%s",msg.c_str()); - signalSetUp(3, 0, msg); - signalSolved(-1,0); - } - else if (edit->ActSketch.hasConflicts()) { // conflicting constraints - SketchObject::appendConflictMsg(edit->ActSketch.getConflicting(), msg); - //Base::Console().Warning("Sketch with conflicting constraints\n%s",msg.c_str()); - signalSetUp(2, dofs, msg); - signalSolved(-1,0); - } - else if (edit->ActSketch.solve() == 0) { // solving the sketch - if (dofs == 0) { - // color the sketch as fully constrained - edit->FullyConstrained = true; - //Base::Console().Message("Fully constrained sketch\n"); - signalSetUp(0, 0, msg); - } - else { - //Base::Console().Message("Under-constrained sketch with %d degrees of freedom\n", dofs); - signalSetUp(1, dofs, msg); - } - signalSolved(0,edit->ActSketch.SolveTime); - } - else { - signalSolved(1,edit->ActSketch.SolveTime); - } + solveSketch(); draw(true); } if (edit && &(getSketchObject()->Constraints)) { @@ -2831,10 +2796,18 @@ bool ViewProviderSketch::setEdit(int ModNum) else Gui::Control().showDialog(new TaskDlgEditSketch(this)); + solveSketch(); + draw(); + + return true; +} + +void ViewProviderSketch::solveSketch(void) +{ // set up the sketch and diagnose possible conflicts int dofs = edit->ActSketch.setUpSketch(getSketchObject()->getCompleteGeometry(), getSketchObject()->Constraints.getValues(), - true, getSketchObject()->getExternalGeometryCount()); + getSketchObject()->getExternalGeometryCount()); std::string msg; if (getSketchObject()->Geometry.getSize() == 0) { signalSetUp(-1, 0, msg); @@ -2868,10 +2841,6 @@ bool ViewProviderSketch::setEdit(int ModNum) else { signalSolved(1, edit->ActSketch.SolveTime); } - - draw(); - - return true; } void ViewProviderSketch::createEditInventorNodes(void) diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.h b/src/Mod/Sketcher/Gui/ViewProviderSketch.h index 572547186..234ede976 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.h +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.h @@ -183,6 +183,8 @@ protected: virtual void unsetEdit(int ModNum); virtual void setEditViewer(Gui::View3DInventorViewer*, int ModNum); virtual void unsetEditViewer(Gui::View3DInventorViewer*); + /// set up and solve the sketch + void solveSketch(void); /// helper to detect whether the picked point lies on the sketch bool isPointOnSketch(const SoPickedPoint *pp) const; /// get called by the container whenever a property has been changed