Skip to content

Commit

Permalink
add progress indicator to BOP check task panel
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Aug 14, 2018
1 parent 2b02b07 commit d5c63cf
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 5 deletions.
87 changes: 83 additions & 4 deletions src/Mod/Part/Gui/TaskCheckGeometry.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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"
22 changes: 21 additions & 1 deletion src/Mod/Part/Gui/TaskCheckGeometry.h
Expand Up @@ -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;
Expand Down Expand Up @@ -112,7 +115,8 @@ private Q_SLOTS:
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;
Expand Down Expand Up @@ -143,6 +147,22 @@ class TaskCheckGeometryDialog : public Gui::TaskView::TaskDialog
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

1 comment on commit d5c63cf

@berndhahnebach
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.