]> SALOME platform Git repositories - modules/superv.git/blobdiff - src/SUPERVGUI/SUPERVGUI_Main.cxx
Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_Main.cxx
index 284888742e361908d88b5c8c0cc8ffef74784f66..6dc5b6171cbb16563f8b670b665ebd1bb8370577 100644 (file)
@@ -36,6 +36,7 @@ using namespace std;
 #include "QAD_Application.h"
 #include "SUPERVGUI_Def.h"
 #include "QAD_RightFrame.h"
+#include "SALOME_Event.hxx"
 #include "SUPERVGraph_ViewFrame.h"
 #include <qlayout.h>
 #include <qfile.h>
@@ -76,7 +77,7 @@ SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* th
     if (obj->FindAttribute(anAttr, "AttributeIOR")) {
       SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
       Standard_CString ior = anIOR->Value();
-      dataflow = Supervision.getEngine()->getGraph(ior);
+      dataflow = Supervision.getEngine()->getStreamGraph(ior);
       if (SUPERV_isNull(dataflow)) {
        QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_ACCESS_BAD_IOR"));
        close();
@@ -88,7 +89,7 @@ SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* th
       close();
     }
   } else {
-    dataflow = Supervision.getEngine()->Graph(MAIN_NEW);
+    dataflow = Supervision.getEngine()->StreamGraph(MAIN_NEW);
     if (SUPERV_isNull(dataflow)) {
       QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_DF"));
       close();
@@ -112,9 +113,9 @@ SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* th
   Trace("SUPERVGUI_Main::SUPERVGUI_Main (file)")
     theParent->setViewWidget(this);  
   if (isModify) {
-    dataflow = Supervision.getEngine()->Graph(f);
+    dataflow = Supervision.getEngine()->StreamGraph(f);
   } else {
-    dataflow = Supervision.getEngine()->GraphE(f);
+    dataflow = Supervision.getEngine()->StreamGraphE(f);
   }
   if (SUPERV_isNull(dataflow)) {
     QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
@@ -157,6 +158,7 @@ void SUPERVGUI_Main::init(QAD_Desktop* theDesktop) {
 
   myThread = new SUPERVGUI_Thread();
   myThread->setMain(this);
+  connect(this, SIGNAL(KillMyThread(bool)), myThread, SLOT(KillThread(bool)));
 
   myIsKilled = false;
   //myIsRunned = false;
@@ -225,13 +227,27 @@ SUPERVGUI_Main::~SUPERVGUI_Main() {
   delete notification; // kloss : nota bene : quand un datalow est detruit : verifier que les canaux de notification sont aussi detruit
   if (!SUPERV_isNull(dataflow)) {
     if (dataflow->IsExecuting()) {
-      if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), 
+      if (QMessageBox::warning(QAD_Application::getDesktop(),
+                              tr("WARNING"), 
                               tr("MSG_DF_RUNNING"), 
                               tr("MSG_DF_EXECUTION"), 
                               tr("MSG_DF_KILL")) == 1) {
-       dataflow->Kill();
+       if (dataflow->Kill()) {
+         if (myThread->running()) 
+           myThread->wait();
+       }
+      }
+      else {
+       emit KillMyThread(true);
+       if (myThread->running()) 
+         myThread->wait();
       }
     }
+    else {
+      emit KillMyThread(true);
+      if (myThread->running()) 
+       myThread->wait();
+    }
   }
 }
 
@@ -267,6 +283,13 @@ void SUPERVGUI_Main::filterNotification() {
   }
 }
 
+void SUPERVGUI_Main::changeDSGraphParameters() {
+  SUPERVGUI_DSGraphParameters* aDlg = new SUPERVGUI_DSGraphParameters(dataflow, dataflow->IsReadOnly());
+  if (aDlg->exec() )
+    sync();
+  delete aDlg;
+}
+
 void SUPERVGUI_Main::syncAsync() {
     Trace("SUPERVGUI_Main::syncAsync")
     QTimer::singleShot(1, this, SLOT(sync()));
@@ -393,7 +416,7 @@ void SUPERVGUI_Main::copy() {
   SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
     (aStudyFrame->getRightFrame()->getViewFrame());
   if(aViewFrame){
-    SUPERV_Graph aNewGraph = dataflow->Copy();
+    SUPERV_Graph aNewGraph = dataflow->StreamCopy();
     QString aNewName(tr("MSG_COPY_PREFIX").arg(++myCopyNum));
     aNewName += dataflow->Name();
     aNewGraph->SetName(aNewName);
@@ -421,18 +444,21 @@ void SUPERVGUI_Main::run() {
       //if (myIsRunned) {
        if (!dataflow->ReRun()) {
          QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
+         if (dataflow->State() == SUPERV::ErrorState) {
+           kill();
+         }
        } else {
          myThread->startThread(tr("MSG_GRAPH_STARTED"));
-         //syncNotification();
          sync();
        }
       } else {
        if (!dataflow->Run()) {
          QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
+         if (dataflow->State() == SUPERV::ErrorState) {
+           kill();
+         }
        } else {
          myThread->startThread(tr("MSG_GRAPH_STARTED"));
-         //syncNotification();
-         //myIsRunned = true;
          sync();
        }
       }
@@ -463,7 +489,6 @@ void SUPERVGUI_Main::startExecute() {
          QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
        } else {
          myThread->startThread(tr("MSG_GRAPH_STARTED"));
-         //syncNotification();
        }
       }
       else {
@@ -471,7 +496,6 @@ void SUPERVGUI_Main::startExecute() {
          QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
        } else {
          myThread->startThread(tr("MSG_GRAPH_STARTED"));
-         //syncNotification();
        }
       }
     }
@@ -708,6 +732,7 @@ void SUPERVGUI_Main::showPopup(QPopupMenu* p, QMouseEvent* e) {
   Trace("SUPERVGUI_Main::showPopup");
   // To check is Supervision active?
   if (myIsLocked) return;
+  //if (dataflow->IsExecuting()) return;
 
   //if (QAD_Application::getDesktop()->getActiveComponent().compare(STUDY_SUPERVISION) !=0) return;
   if (QAD_Application::getDesktop()->getActiveComponent().compare(QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) ) !=0) return;
@@ -1134,8 +1159,6 @@ void SUPERVGUI_Main::checkExecution() {
   }
 }
 
-
-
 /******************************* SUPERVGUI_Thread class ****************************************/
 SUPERVGUI_Thread::SUPERVGUI_Thread()
      :QThread()
@@ -1160,8 +1183,6 @@ void SUPERVGUI_Thread::startThread(const char* m)
 
 void SUPERVGUI_Thread::stopThread(const char* m)
 {
-  //myIsActive = false;
-  //myMain->sync();
   myMain->getMessage()->setMessage(m);
 }
 
@@ -1170,6 +1191,15 @@ void SUPERVGUI_Thread::setMain(SUPERVGUI_Main* theMain)
   myMain = theMain;
 }
 
+void SUPERVGUI_Thread::KillThread(bool theValue)
+{
+  myMutex.lock();
+  myIsActive = !(theValue);
+  myMutex.unlock();
+}
+
+typedef TVoidMemFun2ArgEvent<SUPERVGUI_Main, char*, SUPERV::GraphState> TNodeSyncEvent;
+
 void SUPERVGUI_Thread::run()
 {
   SUPERV_CNode aNode = NULL;
@@ -1192,7 +1222,9 @@ void SUPERVGUI_Thread::run()
       
     if (aEvent == SUPERV::UndefinedEvent && aState == SUPERV::UndefinedState
        ||
-       aEvent == SUPERV::NoEvent && aState == SUPERV::NoState) {
+       aEvent == SUPERV::NoEvent && aState == SUPERV::NoState
+       ||
+       aEvent == SUPERV::KillEvent && aState == SUPERV::KillState) {
       if (myMain->getEventNodes().count()) {
        myMain->removeEventNodes();
       }
@@ -1257,6 +1289,10 @@ void SUPERVGUI_Thread::run()
       case SUPERV_Error : 
        stopThread(tr("MSG_GRAPH_ABORTED"));
        break;
+       
+      case SUPERV_Kill:
+       stopThread(tr("MSG_GRAPH_KILLED"));
+       break;
       }
 
       break;
@@ -1266,11 +1302,13 @@ void SUPERVGUI_Thread::run()
       //if list not empty call execute() -> sync()
       char * aNodeName = *(myMain->getEventNodes().getFirst());
       SUPERV::GraphState aNodeState = *(myMain->getStates().getFirst());
-      qApp->lock();
-      myMain->execute(aNodeName,aNodeState);  //this is from main
-      qApp->unlock();
+
+      // It is PROHIBITED to deal with widgets in a secondary thread, so event posting is used here
+      ProcessVoidEvent( new TNodeSyncEvent( myMain, &SUPERVGUI_Main::execute, aNodeName, aNodeState ) );
+            
       myMain->removeFirstEN();
       myMain->removeFirstS();
+
     }
 
     aPrevNode = aNode;