+//================================================================================
+//================================================================================
+
+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();
+}
+