From d92f627a8d206fbf76aaf948e97293346333b012 Mon Sep 17 00:00:00 2001 From: logari81 Date: Sat, 26 May 2012 20:02:57 +0200 Subject: [PATCH] Sketcher: simplify sketch solver messages --- src/Mod/Sketcher/App/SketchObject.cpp | 14 ++++-- src/Mod/Sketcher/Gui/TaskSketcherMessages.cpp | 44 +++-------------- src/Mod/Sketcher/Gui/TaskSketcherMessages.h | 4 +- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 48 ++++++++++--------- src/Mod/Sketcher/Gui/ViewProviderSketch.h | 4 +- 5 files changed, 46 insertions(+), 68 deletions(-) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 8d75c5f24..c09cd6963 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -1393,10 +1393,14 @@ void SketchObject::appendConflictMsg(const std::vector &conflicting, std::s if (msg.length() > 0) ss << msg; if (conflicting.size() > 0) { - ss << "Please remove at least one of the constraints (" << conflicting[0]; + if (conflicting.size() == 1) + ss << "Please remove the following constraint:\n"; + else + ss << "Please remove at least one of the following constraints:\n"; + ss << conflicting[0]; for (unsigned int i=1; i < conflicting.size(); i++) ss << ", " << conflicting[i]; - ss << ")\n"; + ss << "\n"; } msg = ss.str(); } @@ -1407,7 +1411,11 @@ void SketchObject::appendRedundantMsg(const std::vector &redundant, std::st if (msg.length() > 0) ss << msg; if (redundant.size() > 0) { - ss << "The following constraints were identified as redundant and should be removed:\n" << redundant[0]; + if (redundant.size() == 1) + ss << "Please remove the following redundant constraint:\n"; + else + ss << "Please remove the following redundant constraints:\n"; + ss << redundant[0]; for (unsigned int i=1; i < redundant.size(); i++) ss << ", " << redundant[i]; ss << "\n"; diff --git a/src/Mod/Sketcher/Gui/TaskSketcherMessages.cpp b/src/Mod/Sketcher/Gui/TaskSketcherMessages.cpp index 5ef6c65fb..dc006117a 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherMessages.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherMessages.cpp @@ -54,8 +54,8 @@ TaskSketcherMessages::TaskSketcherMessages(ViewProviderSketch *sketchView) this->groupLayout()->addWidget(proxy); - connectionSetUp = sketchView->signalSetUp.connect(boost::bind(&SketcherGui::TaskSketcherMessages::slotSetUp, this,_1,_2,_3)); - connectionSolved = sketchView->signalSolved.connect(boost::bind(&SketcherGui::TaskSketcherMessages::slotSolved, this,_1,_2)); + connectionSetUp = sketchView->signalSetUp.connect(boost::bind(&SketcherGui::TaskSketcherMessages::slotSetUp, this,_1)); + connectionSolved = sketchView->signalSolved.connect(boost::bind(&SketcherGui::TaskSketcherMessages::slotSolved, this,_1)); } TaskSketcherMessages::~TaskSketcherMessages() @@ -65,46 +65,14 @@ TaskSketcherMessages::~TaskSketcherMessages() delete ui; } -void TaskSketcherMessages::slotSetUp(int type, int dofs, const std::string &msg) +void TaskSketcherMessages::slotSetUp(QString msg) { - switch(type){ - case -1: - ui->labelConstrainStatus->setText(QString::fromLatin1("Empty sketch")); - break; - case 0: - ui->labelConstrainStatus->setText(QString::fromLatin1("Fully constrained sketch ")); - break; - case 1: - if (dofs==1) - ui->labelConstrainStatus->setText(QString::fromLatin1("Under-constrained sketch with 1 degree of freedom")); - else - ui->labelConstrainStatus->setText(QString::fromLatin1("Under-constrained sketch with %1 degrees of freedom").arg(dofs)); - break; - case 2: - ui->labelConstrainStatus->setText(QString::fromLatin1("Sketch contains conflicting constraints
%1
").arg(QString::fromStdString(msg))); - break; - case 3: - ui->labelConstrainStatus->setText(QString::fromLatin1("Over-constrained sketch
%1
").arg(QString::fromStdString(msg))); - break; - case 4: - ui->labelConstrainStatus->setText(QString::fromLatin1("Sketch contains redundant constraints
%1").arg(QString::fromStdString(msg))); - break; - } + ui->labelConstrainStatus->setText(msg); } -void TaskSketcherMessages::slotSolved(int type, float time) +void TaskSketcherMessages::slotSolved(QString msg) { - switch(type){ - case -1: - ui->labelSolverStatus->setText(QString()); - break; - case 0: - ui->labelSolverStatus->setText(QString::fromLatin1("Solved in %1 sec").arg(time)); - break; - case 1: - ui->labelSolverStatus->setText(QString::fromLatin1("Unsolved (%1)").arg(time)); - break; - } + ui->labelSolverStatus->setText(msg); } #include "moc_TaskSketcherMessages.cpp" diff --git a/src/Mod/Sketcher/Gui/TaskSketcherMessages.h b/src/Mod/Sketcher/Gui/TaskSketcherMessages.h index 7cdc104a7..cdf5f907b 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherMessages.h +++ b/src/Mod/Sketcher/Gui/TaskSketcherMessages.h @@ -47,8 +47,8 @@ public: TaskSketcherMessages(ViewProviderSketch *sketchView); ~TaskSketcherMessages(); - void slotSetUp(int type, int dofs, const std::string &msg); - void slotSolved(int type, float time); + void slotSetUp(QString msg); + void slotSolved(QString msg); private Q_SLOTS: diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 2239f7445..4b6cc1988 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -822,9 +822,9 @@ bool ViewProviderSketch::mouseMove(const SbVec3f &point, const SbVec3f &normal, if (edit->ActSketch.movePoint(GeoId, PosId, vec, relative) == 0) { setPositionText(Base::Vector2D(x,y)); draw(true); - signalSolved(0, edit->ActSketch.SolveTime); + signalSolved(QString::fromLatin1("Solved in %1 sec").arg(edit->ActSketch.SolveTime)); } else { - signalSolved(1, edit->ActSketch.SolveTime); + signalSolved(QString::fromLatin1("Unsolved (%1 sec)").arg(edit->ActSketch.SolveTime)); //Base::Console().Log("Error solving:%d\n",ret); } } @@ -835,9 +835,9 @@ bool ViewProviderSketch::mouseMove(const SbVec3f &point, const SbVec3f &normal, if (edit->ActSketch.movePoint(edit->DragCurve, Sketcher::none, vec, relative) == 0) { setPositionText(Base::Vector2D(x,y)); draw(true); - signalSolved(0, edit->ActSketch.SolveTime); + signalSolved(QString::fromLatin1("Solved in %1 sec").arg(edit->ActSketch.SolveTime)); } else { - signalSolved(1, edit->ActSketch.SolveTime); + signalSolved(QString::fromLatin1("Unsolved (%1 sec)").arg(edit->ActSketch.SolveTime)); } } return true; @@ -2808,46 +2808,48 @@ void ViewProviderSketch::solveSketch(void) int dofs = edit->ActSketch.setUpSketch(getSketchObject()->getCompleteGeometry(), getSketchObject()->Constraints.getValues(), getSketchObject()->getExternalGeometryCount()); - std::string msg; if (getSketchObject()->Geometry.getSize() == 0) { - signalSetUp(-1, 0, msg); - signalSolved(-1, 0); + signalSetUp(QString::fromLatin1("Empty sketch")); + signalSolved(QString()); } else if (dofs < 0) { // over-constrained sketch + std::string msg; SketchObject::appendConflictMsg(edit->ActSketch.getConflicting(), msg); - //Base::Console().Warning("Over-constrained sketch\n%s",msg.c_str()); - signalSetUp(3, 0, msg); - signalSolved(-1, 0); + signalSetUp(QString::fromLatin1("Over-constrained sketch
%1
") + .arg(QString::fromStdString(msg))); + signalSolved(QString()); } else if (edit->ActSketch.hasConflicts()) { // conflicting constraints + std::string msg; 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); + signalSetUp(QString::fromLatin1("Sketch contains conflicting constraints
%1
") + .arg(QString::fromStdString(msg))); + signalSolved(QString()); } else { if (edit->ActSketch.hasRedundancies()) { // redundant constraints + std::string msg; SketchObject::appendRedundantMsg(edit->ActSketch.getRedundant(), msg); - //Base::Console().Warning("Sketch with redundant constraints\n%s",msg.c_str()); - signalSetUp(4, dofs, msg); + signalSetUp(QString::fromLatin1("Sketch contains redundant constraints
%1
") + .arg(QString::fromStdString(msg))); } if (edit->ActSketch.solve() == 0) { // solving the sketch if (dofs == 0) { // color the sketch as fully constrained edit->FullyConstrained = true; - if (!edit->ActSketch.hasRedundancies()) { - //Base::Console().Message("Fully constrained sketch\n"); - signalSetUp(0, 0, msg); - } + if (!edit->ActSketch.hasRedundancies()) + signalSetUp(QString::fromLatin1("Fully constrained sketch ")); } else if (!edit->ActSketch.hasRedundancies()) { - //Base::Console().Message("Under-constrained sketch with %d degrees of freedom\n", dofs); - signalSetUp(1, dofs, msg); + if (dofs == 1) + signalSetUp(QString::fromLatin1("Under-constrained sketch with 1 degree of freedom")); + else + signalSetUp(QString::fromLatin1("Under-constrained sketch with %1 degrees of freedom").arg(dofs)); } - signalSolved(0, edit->ActSketch.SolveTime); + signalSolved(QString::fromLatin1("Solved in %1 sec").arg(edit->ActSketch.SolveTime)); } else { - signalSolved(1, edit->ActSketch.SolveTime); + signalSolved(QString::fromLatin1("Unsolved (%1 sec)").arg(edit->ActSketch.SolveTime)); } } } diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.h b/src/Mod/Sketcher/Gui/ViewProviderSketch.h index 234ede976..2c98d71eb 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.h +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.h @@ -174,9 +174,9 @@ public: /// signals if the constraints list has changed boost::signal signalConstraintsChanged; /// signals if the sketch has been set up - boost::signal signalSetUp; + boost::signal signalSetUp; /// signals if the sketch has been solved - boost::signal signalSolved; + boost::signal signalSolved; protected: virtual bool setEdit(int ModNum);