diff --git a/src/SMESHGUI/SMESHGUI_ComputeDlg.cxx b/src/SMESHGUI/SMESHGUI_ComputeDlg.cxx index 8ceb87a5b..5b7fc580f 100644 --- a/src/SMESHGUI/SMESHGUI_ComputeDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_ComputeDlg.cxx @@ -85,6 +85,8 @@ #include #include #include +#include +#include // VTK includes #include @@ -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){ diff --git a/src/SMESHGUI/SMESHGUI_ComputeDlg.h b/src/SMESHGUI/SMESHGUI_ComputeDlg.h index ee268a4d4..34063d61b 100644 --- a/src/SMESHGUI/SMESHGUI_ComputeDlg.h +++ b/src/SMESHGUI/SMESHGUI_ComputeDlg.h @@ -37,6 +37,7 @@ #include #include #include +#include // IDL includes #include @@ -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