From d5c63cf2119f3523396872e5e83b6b288ea0e587 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 14 Aug 2018 23:51:02 +0200 Subject: [PATCH] add progress indicator to BOP check task panel --- src/Mod/Part/Gui/TaskCheckGeometry.cpp | 87 ++++++++++++++++++++++++-- src/Mod/Part/Gui/TaskCheckGeometry.h | 22 ++++++- 2 files changed, 104 insertions(+), 5 deletions(-) diff --git a/src/Mod/Part/Gui/TaskCheckGeometry.cpp b/src/Mod/Part/Gui/TaskCheckGeometry.cpp index a35bca036e..43ab47d495 100644 --- a/src/Mod/Part/Gui/TaskCheckGeometry.cpp +++ b/src/Mod/Part/Gui/TaskCheckGeometry.cpp @@ -23,9 +23,11 @@ #include "PreCompiled.h" #ifndef _PreComp_ # include +# include # include # include # include +# include # include # include #endif @@ -65,6 +67,7 @@ #include #include #include +#include #include "TaskCheckGeometry.h" using namespace PartGui; @@ -414,9 +417,14 @@ void TaskCheckGeometryResults::goCheck() std::vector selection = Gui::Selection().getSelection(); std::vector::iterator it; ResultEntry *theRoot = new ResultEntry(); + + Handle(Message_ProgressIndicator) theProgress = new BOPProgressIndicator(tr("Check geometry"), Gui::getMainWindow()); + theProgress->NewScope("BOP check..."); + theProgress->Show(); + + selectedCount = static_cast(selection.size()); for (it = selection.begin(); it != selection.end(); ++it) { - selectedCount++; Part::Feature *feature = dynamic_cast((*it).pObject); if (!feature) continue; @@ -470,8 +478,16 @@ void TaskCheckGeometryResults::goCheck() //for now, user has edit the config file to turn it on. //following line ensures that the config file has the setting. group->SetBool("RunBOPCheck", runSignal); - if (runSignal) - invalidShapes += goBOPSingleCheck(shape, theRoot, baseName); + if (runSignal) { + std::string label = "Checking "; + label += feature->Label.getStrValue(); + label += "..."; + theProgress->NewScope(label.c_str()); + invalidShapes += goBOPSingleCheck(shape, theRoot, baseName, theProgress); + theProgress->EndScope(); + if (theProgress->UserBreak()) + break; + } } } model->setResults(theRoot); @@ -578,7 +594,8 @@ QString TaskCheckGeometryResults::getShapeContentString() return QString::fromStdString(shapeContentString); } -int TaskCheckGeometryResults::goBOPSingleCheck(const TopoDS_Shape& shapeIn, ResultEntry *theRoot, const QString &baseName) +int TaskCheckGeometryResults::goBOPSingleCheck(const TopoDS_Shape& shapeIn, ResultEntry *theRoot, const QString &baseName, + const Handle(Message_ProgressIndicator)& theProgress) { //ArgumentAnalyser was moved at version 6.6. no back port for now. #if OCC_VERSION_HEX >= 0x060600 @@ -594,6 +611,7 @@ int TaskCheckGeometryResults::goBOPSingleCheck(const TopoDS_Shape& shapeIn, Resu //this is left for another time. TopoDS_Shape BOPCopy = BRepBuilderAPI_Copy(shapeIn).Shape(); BOPAlgo_ArgumentAnalyzer BOPCheck; + BOPCheck.SetProgressIndicator(theProgress); // BOPCheck.StopOnFirstFaulty() = true; //this doesn't run any faster but gives us less results. BOPCheck.SetShape1(BOPCopy); //all settings are false by default. so only turn on what we want. @@ -935,4 +953,65 @@ TaskCheckGeometryDialog::~TaskCheckGeometryDialog() } } +//////////////////////////////////////////////////////////////////////////////////////////////// + +BOPProgressIndicator::BOPProgressIndicator (const QString& title, QWidget* parent) +{ + steps = 0; + canceled = false; + myProgress = new QProgressDialog(parent); + myProgress->setWindowTitle(title); + myProgress->setAttribute(Qt::WA_DeleteOnClose); +} + +BOPProgressIndicator::~BOPProgressIndicator () +{ + myProgress->close(); +} + +Standard_Boolean BOPProgressIndicator::Show (const Standard_Boolean theForce) +{ + if (theForce) { + steps = 0; + canceled = false; + + time.start(); + myProgress->show(); + + myProgress->setRange(0, 0); + myProgress->setValue(0); + } + else { + Handle(TCollection_HAsciiString) aName = GetScope(1).GetName(); //current step + if (!aName.IsNull()) + myProgress->setLabelText (QString::fromLatin1(aName->ToCString())); + } + + return Standard_True; +} + +Standard_Boolean BOPProgressIndicator::UserBreak() +{ + // this is needed to check the status outside BOPAlgo_ArgumentAnalyzer + if (canceled) + return Standard_True; + + QThread *currentThread = QThread::currentThread(); + if (currentThread == myProgress->thread()) { + // it suffices to update only every second + // to avoid to unnecessarily process events + steps++; + myProgress->setValue(steps); + if (time.elapsed() > 1000) { + time.restart(); + QCoreApplication::processEvents(); + + canceled = myProgress->wasCanceled(); + return canceled; + } + } + + return Standard_False; +} + #include "moc_TaskCheckGeometry.cpp" diff --git a/src/Mod/Part/Gui/TaskCheckGeometry.h b/src/Mod/Part/Gui/TaskCheckGeometry.h index 30822e6085..e7d7d31271 100644 --- a/src/Mod/Part/Gui/TaskCheckGeometry.h +++ b/src/Mod/Part/Gui/TaskCheckGeometry.h @@ -26,10 +26,13 @@ #include #include #include +#include #include #include #include #include +#include +#include class SoSeparator; class SoSwitch; @@ -112,7 +115,8 @@ private: void dispatchError(ResultEntry *entry, const BRepCheck_Status &stat); bool split(QString &input, QString &doc, QString &object, QString &sub); void setupFunctionMap(); - int goBOPSingleCheck(const TopoDS_Shape &shapeIn, ResultEntry *theRoot, const QString &baseName); + int goBOPSingleCheck(const TopoDS_Shape &shapeIn, ResultEntry *theRoot, const QString &baseName, + const Handle(Message_ProgressIndicator)& theProgress); void buildShapeContent(const QString &baseName, const TopoDS_Shape &shape); ResultModel *model; QTreeView *treeView; @@ -143,6 +147,22 @@ private: QTextEdit *contentLabel; }; +class BOPProgressIndicator : public Message_ProgressIndicator +{ +public: + BOPProgressIndicator (const QString &title, QWidget* parent); + virtual ~BOPProgressIndicator (); + + virtual Standard_Boolean Show (const Standard_Boolean theForce = Standard_True); + virtual Standard_Boolean UserBreak(); + +private: + int steps; + bool canceled; + QTime time; + QProgressDialog* myProgress; +}; + } #endif // TASKCHECKGEOMETRY_H