X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FSMESHGUI%2FSMESHGUI_ComputeDlg.cxx;h=5b7fc580f9242e07e49c97fa4bac651719830051;hb=911977bc89d1e9527b0a4ac4c22823116b2e883c;hp=8ceb87a5b538526e65c4ace37e29b3affef017ac;hpb=5142df035d3a1f35c6af00cde28969088a547205;p=modules%2Fsmesh.git 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){