From 931757e1e6e3393be1e78dee1c8d8ce0226eba06 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Mon, 4 Jan 2021 09:00:33 +0100 Subject: [PATCH] Sketcher: ViewProvider - Show malformed constraints in solver messages --- src/Mod/Sketcher/Gui/TaskSketcherMessages.cpp | 8 ++- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 55 ++++++++++++------- src/Mod/Sketcher/Gui/ViewProviderSketch.h | 9 ++- 3 files changed, 47 insertions(+), 25 deletions(-) diff --git a/src/Mod/Sketcher/Gui/TaskSketcherMessages.cpp b/src/Mod/Sketcher/Gui/TaskSketcherMessages.cpp index f090cbd8bd..c3441c7360 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherMessages.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherMessages.cpp @@ -107,13 +107,15 @@ void TaskSketcherMessages::on_labelConstrainStatus_linkActivated(const QString & { if( str == QString::fromLatin1("#conflicting")) Gui::Application::Instance->commandManager().runCommandByName("Sketcher_SelectConflictingConstraints"); - + else if( str == QString::fromLatin1("#redundant")) Gui::Application::Instance->commandManager().runCommandByName("Sketcher_SelectRedundantConstraints"); - + else if( str == QString::fromLatin1("#dofs")) Gui::Application::Instance->commandManager().runCommandByName("Sketcher_SelectElementsWithDoFs"); - + else + if( str == QString::fromLatin1("#malformed")) + Gui::Application::Instance->commandManager().runCommandByName("Sketcher_SelectMalformedConstraints"); } void TaskSketcherMessages::on_autoUpdate_stateChanged(int state) diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 150f723645..66e4c5c621 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -6270,35 +6270,40 @@ bool ViewProviderSketch::setEdit(int ModNum) QString ViewProviderSketch::appendConflictMsg(const std::vector &conflicting) { - QString msg; - QTextStream ss(&msg); - if (conflicting.size() > 0) { - if (conflicting.size() == 1) - ss << tr("Please remove the following constraint:"); - else - ss << tr("Please remove at least one of the following constraints:"); - ss << "\n"; - ss << conflicting[0]; - for (unsigned int i=1; i < conflicting.size(); i++) - ss << ", " << conflicting[i]; - ss << "\n"; - } - return msg; + return appendConstraintMsg(tr("Please remove the following constraint:"), + tr("Please remove at least one of the following constraints:"), + conflicting); } QString ViewProviderSketch::appendRedundantMsg(const std::vector &redundant) +{ + return appendConstraintMsg(tr("Please remove the following redundant constraint:"), + tr("Please remove the following redundant constraints:"), + redundant); +} + +QString ViewProviderSketch::appendMalformedMsg(const std::vector &malformed) +{ + return appendConstraintMsg(tr("Please remove the following malformed constraint:"), + tr("Please remove the following malformed constraints:"), + malformed); +} + +QString ViewProviderSketch::appendConstraintMsg(const QString & singularmsg, + const QString & pluralmsg, + const std::vector &vector) { QString msg; QTextStream ss(&msg); - if (redundant.size() > 0) { - if (redundant.size() == 1) - ss << tr("Please remove the following redundant constraint:"); + if (vector.size() > 0) { + if (vector.size() == 1) + ss << singularmsg; else - ss << tr("Please remove the following redundant constraints:"); + ss << pluralmsg; ss << "\n"; - ss << redundant[0]; - for (unsigned int i=1; i < redundant.size(); i++) - ss << ", " << redundant[i]; + ss << vector[0]; + for (unsigned int i=1; i < vector.size(); i++) + ss << ", " << vector[i]; ss << "\n"; } @@ -6311,6 +6316,7 @@ void ViewProviderSketch::UpdateSolverInformation() int dofs = getSketchObject()->getLastDoF(); bool hasConflicts = getSketchObject()->getLastHasConflicts(); bool hasRedundancies = getSketchObject()->getLastHasRedundancies(); + bool hasMalformed = getSketchObject()->getLastHasMalformedConstraints(); if (getSketchObject()->Geometry.getSize() == 0) { signalSetUp(tr("Empty sketch")); @@ -6325,6 +6331,13 @@ void ViewProviderSketch::UpdateSolverInformation() .arg(QString::fromStdString(msg))); signalSolved(QString()); } + else if (hasMalformed) { // malformed constraints + signalSetUp(QString::fromLatin1("%1%2
%3

") + .arg(tr("Sketch contains malformed constraints ")) + .arg(tr("(click to select)")) + .arg(appendMalformedMsg(getSketchObject()->getLastMalformedConstraints()))); + signalSolved(QString()); + } else if (hasConflicts) { // conflicting constraints signalSetUp(QString::fromLatin1("%1%2
%3

") .arg(tr("Sketch contains conflicting constraints ")) diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.h b/src/Mod/Sketcher/Gui/ViewProviderSketch.h index 7a47ab8e3a..998f030f8f 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.h +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.h @@ -93,8 +93,10 @@ class SketcherGuiExport ViewProviderSketch : public PartGui::ViewProvider2DObjec static QString appendConflictMsg(const std::vector &conflicting); /// generates a warning message about redundant constraints and appends it to the given message static QString appendRedundantMsg(const std::vector &redundant); + /// generates a warning message about redundant constraints and appends it to the given message + static QString appendMalformedMsg(const std::vector &redundant); - PROPERTY_HEADER(SketcherGui::ViewProviderSketch); + PROPERTY_HEADER_WITH_OVERRIDE(SketcherGui::ViewProviderSketch); public: /// constructor @@ -303,6 +305,11 @@ protected: void forceUpdateData(); + /// Auxiliary function to generate messages about conflicting, redundant and malformed constraints + static QString appendConstraintMsg( const QString & singularmsg, + const QString & pluralmsg, + const std::vector &vector); + /// Return display string for constraint including hiding units if //requested. QString getPresentationString(const Sketcher::Constraint *constraint);