add progress indicator to BOP check task panel

This commit is contained in:
wmayer
2018-08-14 23:51:02 +02:00
parent 2b02b07538
commit d5c63cf211
2 changed files with 104 additions and 5 deletions

View File

@@ -23,9 +23,11 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QBoxLayout>
# include <QCoreApplication>
# include <QHeaderView>
# include <QTextEdit>
# include <QTextStream>
# include <QThread>
# include <QTreeWidget>
# include <Python.h>
#endif
@@ -65,6 +67,7 @@
#include <Gui/Application.h>
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
#include <Gui/MainWindow.h>
#include "TaskCheckGeometry.h"
using namespace PartGui;
@@ -414,9 +417,14 @@ void TaskCheckGeometryResults::goCheck()
std::vector<Gui::SelectionSingleton::SelObj> selection = Gui::Selection().getSelection();
std::vector<Gui::SelectionSingleton::SelObj>::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<int>(selection.size());
for (it = selection.begin(); it != selection.end(); ++it)
{
selectedCount++;
Part::Feature *feature = dynamic_cast<Part::Feature *>((*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"

View File

@@ -26,10 +26,13 @@
#include <boost/tuple/tuple.hpp>
#include <BRepCheck_Analyzer.hxx>
#include <BRepCheck_Status.hxx>
#include <Message_ProgressIndicator.hxx>
#include <TopTools_MapOfShape.hxx>
#include <Gui/TaskView/TaskDialog.h>
#include <Gui/TaskView/TaskView.h>
#include <QAbstractItemModel>
#include <QProgressDialog>
#include <QTime>
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