Implement Cancel Compute (begin)

This commit is contained in:
adam 2011-03-17 08:53:25 +00:00
parent 5142df035d
commit 911977bc89
2 changed files with 146 additions and 1 deletions

View File

@ -85,6 +85,8 @@
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QButtonGroup>
#include <QCloseEvent>
#include <QTimerEvent>
// VTK includes
#include <vtkProperty.h>
@ -670,6 +672,87 @@ void SMESHGUI_BaseComputeOp::startOperation()
SMESHGUI_Operation::startOperation();
}
//================================================================================
//================================================================================
SMESHGUI_ComputeDlg_QThread::SMESHGUI_ComputeDlg_QThread(SMESH::SMESH_Gen_var gen,
SMESH::SMESH_Mesh_var mesh,
GEOM::GEOM_Object_var mainShape)
{
myResult = false;
myGen = gen;
myMesh = mesh;
myMainShape = mainShape;
}
void SMESHGUI_ComputeDlg_QThread::run()
{
myResult = myGen->Compute(myMesh, myMainShape);
}
bool SMESHGUI_ComputeDlg_QThread::result()
{
return myResult;
}
void SMESHGUI_ComputeDlg_QThread::cancel()
{
myGen->CancelCompute(myMesh, myMainShape);
}
//================================================================================
//================================================================================
SMESHGUI_ComputeDlg_QThreadQDialog::SMESHGUI_ComputeDlg_QThreadQDialog(QWidget *parent,
SMESH::SMESH_Gen_var gen,
SMESH::SMESH_Mesh_var mesh,
GEOM::GEOM_Object_var mainShape)
: QDialog(parent),
qthread(gen, mesh, mainShape)
{
// --
setWindowTitle(tr("Compute"));
cancelButton = new QPushButton(tr("Cancel"));
cancelButton->setDefault(true);
connect(cancelButton, SIGNAL(clicked()), this, SLOT(onCancel()));
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(cancelButton);
setLayout(layout);
resize(200, 50);
// --
startTimer(30); // 30 millisecs
qthread.start();
}
bool SMESHGUI_ComputeDlg_QThreadQDialog::result()
{
return qthread.result();
}
void SMESHGUI_ComputeDlg_QThreadQDialog::onCancel()
{
qthread.cancel();
}
void SMESHGUI_ComputeDlg_QThreadQDialog::timerEvent(QTimerEvent *event)
{
if(qthread.isFinished())
{
close();
}
event->accept();
}
void SMESHGUI_ComputeDlg_QThreadQDialog::closeEvent(QCloseEvent *event)
{
if(qthread.isRunning())
{
event->ignore();
return;
}
event->accept();
}
//================================================================================
/*!
* \brief computeMesh()
@ -711,7 +794,15 @@ void SMESHGUI_BaseComputeOp::computeMesh()
OCC_CATCH_SIGNALS;
#endif
//SMESH::UpdateNulData(myIObject, true);
if (gen->Compute(myMesh, myMainShape))
bool res;
#ifdef WITH_SMESH_CANCEL_COMPUTE
SMESHGUI_ComputeDlg_QThreadQDialog qthreaddialog(desktop(), gen, myMesh, myMainShape);
qthreaddialog.exec();
res = qthreaddialog.result();
#else
res = gen->Compute(myMesh, myMainShape);
#endif
if (res)
computeFailed = false;
}
catch(const SALOME::SALOME_Exception & S_ex){

View File

@ -37,6 +37,7 @@
#include <QList>
#include <QPointer>
#include <QGroupBox>
#include <QThread>
// IDL includes
#include <SALOMEconfig.h>
@ -260,4 +261,57 @@ private:
QtxComboBox* myPreviewMode;
};
/*!
* \brief Thread to launch computation
*/
class SMESHGUI_EXPORT SMESHGUI_ComputeDlg_QThread : public QThread
{
Q_OBJECT
public:
SMESHGUI_ComputeDlg_QThread(SMESH::SMESH_Gen_var gen,
SMESH::SMESH_Mesh_var mesh,
GEOM::GEOM_Object_var mainShape);
bool result();
void cancel();
protected:
void run();
private:
SMESH::SMESH_Gen_var myGen;
SMESH::SMESH_Mesh_var myMesh;
GEOM::GEOM_Object_var myMainShape;
bool myResult;
};
/*!
* \brief Dialog to display Cancel button
*/
class SMESHGUI_EXPORT SMESHGUI_ComputeDlg_QThreadQDialog : public QDialog
{
Q_OBJECT
public:
SMESHGUI_ComputeDlg_QThreadQDialog(QWidget *parent,
SMESH::SMESH_Gen_var gen,
SMESH::SMESH_Mesh_var mesh,
GEOM::GEOM_Object_var mainShape);
bool result();
protected:
void timerEvent(QTimerEvent *timer);
void closeEvent(QCloseEvent *event);
private slots:
void onCancel();
private:
SMESHGUI_ComputeDlg_QThread qthread;
QPushButton *cancelButton;
};
#endif // SMESHGUI_COMPUTEDLG_H