]> SALOME platform Git repositories - modules/smesh.git/commitdiff
Salome HOME
Implement Cancel Compute (begin)
authoradam <adam>
Thu, 17 Mar 2011 08:53:25 +0000 (08:53 +0000)
committeradam <adam>
Thu, 17 Mar 2011 08:53:25 +0000 (08:53 +0000)
src/SMESHGUI/SMESHGUI_ComputeDlg.cxx
src/SMESHGUI/SMESHGUI_ComputeDlg.h

index 8ceb87a5b538526e65c4ace37e29b3affef017ac..5b7fc580f9242e07e49c97fa4bac651719830051 100644 (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){
index ee268a4d4756896f33d182fe674f78e0fc5402f5..34063d61b52712536e908fcb3984d3dbc54d22b3 100644 (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