Salome HOME
Improvement for handling node events coming from Engine. SUPERVGUI_Thread::run...
authorasv <asv@opencascade.com>
Thu, 3 Feb 2005 12:52:33 +0000 (12:52 +0000)
committerasv <asv@opencascade.com>
Thu, 3 Feb 2005 12:52:33 +0000 (12:52 +0000)
src/SUPERVGUI/SUPERVGUI.cxx
src/SUPERVGUI/SUPERVGUI_CanvasNode.cxx
src/SUPERVGUI/SUPERVGUI_Main.cxx
src/SUPERVGUI/SUPERVGUI_Main.h

index a294f89c3c7f8f2dfade31e4de71fb4e5d9e739b..8b29eec9b754a098aa89c95a37af9d0e749921ff 100644 (file)
@@ -454,7 +454,7 @@ bool SUPERVGUI::createDataflow( const NEW_DF_MODE mode ) {
     aGraph = engine->StreamGraph( MAIN_NEW );
 
   if ( CORBA::is_nil( aGraph ) ) {
-    QString msg( mode == New ? QString("MSG_CANT_CREATE_DF") : QString("MSG_BAD_FILE").arg(f) );
+    QString msg( mode == New ? tr("MSG_CANT_CREATE_DF") : tr("MSG_BAD_FILE").arg(f) );
     QAD_MessageBox::warn1( QAD_Application::getDesktop(), tr("ERROR"), tr(msg), tr("BUT_OK") );
     return false;
   }
index 1cbe56f3c59b927f8535eaa294b268a802dc0d68..a7469ff8a7bd4c14e49835a80e96abaa0e4446b0 100644 (file)
@@ -20,6 +20,8 @@ using namespace std;
 
 #include "SALOMEGUI_NameDlg.h"
 #include "QAD_MessageBox.h"
+#include "QAD_Message.h"
+
 
 SUPERVGUI_CanvasNode::SUPERVGUI_CanvasNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode, bool theIsCell):
     QObject(theParent),
@@ -406,7 +408,7 @@ void SUPERVGUI_CanvasNode::suspendResume() {
       QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_SUSPENDNODE"));
     } else {
       syncOnEvent(SUPERV::SuspendReadyState);
-      myMain->getMyThread()->stopThread(tr("MSG_NODE_SUSPENDED1")+myNode->Name()+tr("MSG_NODE_SUSPENDED2"));
+      myMain->getMessage()->setMessage(tr("MSG_NODE_SUSPENDED1")+myNode->Name()+tr("MSG_NODE_SUSPENDED2"));
     }
   }
 }
@@ -418,7 +420,7 @@ void SUPERVGUI_CanvasNode::kill() {
     QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_KILLNODE"));
   } else {
     syncOnEvent(SUPERV_Kill);
-    myMain->getMyThread()->stopThread(tr("MSG_NODE_KILLED1")+myNode->Name()+tr("MSG_NODE_KILLED2"));
+    myMain->getMessage()->setMessage(tr("MSG_NODE_KILLED1")+myNode->Name()+tr("MSG_NODE_KILLED2"));
   }
 }
 /* asv : 15.12.04 : commented out stopRestart() in Main and CanvasNode because it's not called from anywhere,
index 3cd797d4520242ee32261c2ed5c3c80ffa39aff8..4ef006a520be62647630808534ce7dcd911def1d 100644 (file)
@@ -233,13 +233,13 @@ void SUPERVGUI_Main::syncAsync() {
 void SUPERVGUI_Main::execute( char *  theNodeName, SUPERV::GraphState theNodeState ) {
   if (myCurrentView == CANVAS || myCurrentView == CONTROLFLOW) {
     SUPERVGUI_CanvasNode* aNode = (SUPERVGUI_CanvasNode*) myCanvas->child(theNodeName, "SUPERVGUI_CanvasNode");
-    if ( aNode ) {
+    if ( aNode )
       aNode->sync();
-    }
   }
   else if (myCurrentView == CANVASTABLE) {
     SUPERVGUI_CanvasCellNode* aNode = (SUPERVGUI_CanvasCellNode*) myArray->child(theNodeName, "SUPERVGUI_CanvasCellNode");
-    if (aNode) aNode->sync();
+    if (aNode) 
+      aNode->sync();
   }
 
   // asv : 26.01.05 : Bug PAL7164 : puting out-value to study if the "put_to_Study" flag is set on a 
@@ -538,7 +538,7 @@ void SUPERVGUI_Main::kill() {
     QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
   } 
   else if (dataflow->Kill()) {
-    myThread->stopThread(tr("MSG_GRAPH_KILLED"));
+    getMessage()->setMessage( tr("MSG_GRAPH_KILLED") );
     sync();
   } 
   else {
@@ -561,7 +561,7 @@ void SUPERVGUI_Main::suspendResume() {
     } else {
       if (dataflow->Suspend()) {
        sync();
-       myThread->stopThread(tr("MSG_GRAPH_SUSPENDED"));
+       getMessage()->setMessage( tr("MSG_GRAPH_SUSPENDED") );
       } else {
        QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_SUSPEND"));
       }
@@ -1243,24 +1243,18 @@ void SUPERVGUI_Thread::startThread(const char* m)
 {
   if (!myIsActive) {
     myIsActive = true;
-    //QThread::start();
-    this->start();
+    start();
     myMain->getMessage()->setMessage(m); 
     myMain->sync();
   }
 }
 
-void SUPERVGUI_Thread::stopThread(const char* m)
-{
-  myMain->getMessage()->setMessage(m);
-}
-
-void SUPERVGUI_Thread::setMain(SUPERVGUI_Main* theMain)
+void SUPERVGUI_Thread::setMain( SUPERVGUI_Main* theMain )
 {
   myMain = theMain;
 }
 
-void SUPERVGUI_Thread::KillThread(bool theValue)
+void SUPERVGUI_Thread::KillThread( bool theValue )
 {
   myMutex.lock();
   myIsActive = !(theValue);
@@ -1271,132 +1265,61 @@ typedef TVoidMemFun2ArgEvent<SUPERVGUI_Main, char*, SUPERV::GraphState> TNodeSyn
 
 void SUPERVGUI_Thread::run()
 {
-  SUPERV_CNode aNode = NULL;
-  SUPERV::GraphEvent aEvent = SUPERV::UndefinedEvent ;
-  SUPERV::GraphState aState = SUPERV::UndefinedState ;
-
-  SUPERV_CNode aPrevNode = NULL;
-  SUPERV::GraphEvent aPrevEvent = SUPERV::UndefinedEvent ;
-  SUPERV::GraphState aPrevState = SUPERV::UndefinedState ;
-
-  char * aName;
-  char * aPrevName;
+  myMain->startTimer();
 
-  QPtrList< char * > anEventNodes;
-  QPtrList< SUPERV::GraphState > aStates;
+  // GUI cycle to handle events coming for Engine
+  while ( myIsActive ) {
 
-  myMain->startTimer();
+    SUPERV_CNode aNode = NULL;
+    SUPERV::GraphEvent aEvent = SUPERV::UndefinedEvent ;
+    SUPERV::GraphState aState = SUPERV::UndefinedState ;
 
-  while(myIsActive) {
+    // blocking function of Engine.  Return from there only after anEvent happens on node aNode
     myMain->getDataflow()->Event(aNode, aEvent, aState);
     
-    if (aEvent == SUPERV::UndefinedEvent && aState == SUPERV::UndefinedState
-       ||
-       aEvent == SUPERV::NoEvent && aState == SUPERV::NoState
-       ||
-       aEvent == SUPERV::KillEvent && aState == SUPERV::KillState) {
-
-      if (myMain->getEventNodes().count()) {
-       myMain->removeEventNodes();
-      }    
-      if (myMain->getStates().count()) {
-       myMain->removeStates();
-      }    
+    // "kill" or undefined event came
+    if (( aEvent == SUPERV::UndefinedEvent && aState == SUPERV::UndefinedState ) ||
+       ( aEvent == SUPERV::NoEvent && aState == SUPERV::NoState ) ||
+       ( aEvent == SUPERV::KillEvent && aState == SUPERV::KillState )) {
+
       myIsActive = false;
     }
-    else {    
-      if ( aNode != NULL && !CORBA::is_nil( aNode ) ) {
-       aName = aNode->Name();
-      }
-
-      if ( aPrevNode == NULL || CORBA::is_nil( aPrevNode ) ) {  //first initialize aPrev... variables
-       anEventNodes = myMain->getEventNodes();
-       anEventNodes.append( &aName ) ;
-       myMain->setEventNodes(anEventNodes);
-       
-       aStates = myMain->getStates();
-       aStates.append( &aState ) ;
-       myMain->setStates(aStates);
-      }
-      else {
-       if ( aEvent == aPrevEvent && aState == aPrevState) {
-         QString aNameStr = aName;
-         QString aPrevNameStr = aPrevName;
-         if ( aNameStr != aPrevNameStr ) {
-           anEventNodes = myMain->getEventNodes();
-           anEventNodes.append( &aName ) ;
-           myMain->setEventNodes(anEventNodes);
-           
-           aStates = myMain->getStates();
-           aStates.append( &aState ) ;
-           myMain->setStates(aStates);
-         }
-       }
-       else {
-         anEventNodes = myMain->getEventNodes();
-         anEventNodes.append( &aName ) ;
-         myMain->setEventNodes(anEventNodes);
-         
-         aStates = myMain->getStates();
-         aStates.append( &aState ) ;
-         myMain->setStates(aStates);
-       }
-      }
-    }      
-    if (!myIsActive) {
-      switch (myMain->getDataflow()->State()) {
+    else { // a "normal" execution event came
+      char* aName = NULL;
+      if ( aNode != NULL && !CORBA::is_nil( aNode ) ) 
+       aName = aNode->Name();      
+
+      // this function is asynchronious.  The call does NOT wait when SUPERVGUI_Main::execute finishes
+      // handling the event.  So: SUPERVGUI_Main::execute must be fast, in order we don't get here again
+      // on the next loop iteration, BEFORE  previous SUPERVGUI_Main::execute finished.
+      ProcessVoidEvent( new TNodeSyncEvent( myMain, &SUPERVGUI_Main::execute, aName, aState ) );
+    }    
+  
+    // execution is finished.  just set a "finished" message(s)
+    if ( !myIsActive ) {
+      switch ( myMain->getDataflow()->State() ) {
       case SUPERV_Editing :     
-       stopThread(myMain->getDataflow()->IsReadOnly()? tr("MSG_GRAPH_READONLY"): tr("MSG_GRAPH_EDITING"));
-       break;
-       
+       myMain->getMessage()->setMessage( myMain->getDataflow()->IsReadOnly()? 
+                                        tr("MSG_GRAPH_READONLY"): tr("MSG_GRAPH_EDITING") );
+       break;  
       case SUPERV_Suspend : 
-       stopThread(tr("MSG_GRAPH_SUSPENDED"));
-       break;
+       myMain->getMessage()->setMessage( tr("MSG_GRAPH_SUSPENDED") );
+       break; 
       case SUPERV_Done : 
-       stopThread(tr("MSG_GRAPH_FINISHED"));
-       break;
-       
+       myMain->getMessage()->setMessage( tr("MSG_GRAPH_FINISHED") );
+       break;  
       case SUPERV_Error :
-       stopThread(tr("MSG_GRAPH_ABORTED"));
-       break;
-       
+       myMain->getMessage()->setMessage( tr("MSG_GRAPH_ABORTED") );
+       break;  
       case SUPERV_Kill:
-       stopThread(tr("MSG_GRAPH_KILLED"));
+       myMain->getMessage()->setMessage( tr("MSG_GRAPH_KILLED") );
        break;
-      }
-
-      break;
-    }
-    if ( myMain->getEventNodes().count() ) {    
-      //if list not empty call execute() -> sync()
-      char * aNodeName = *(myMain->getEventNodes().getFirst());
-      SUPERV::GraphState aNodeState = *(myMain->getStates().getFirst());
+      } // end of switch
 
-      // 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;
-    aPrevEvent = aEvent;
-    aPrevState = aState;
-
-    if ( aPrevNode == NULL || CORBA::is_nil( aPrevNode ) ) 
-      aPrevName = "";
-    else 
-      aPrevName = aPrevNode->Name();
-    
-    //usleep(10);
-    //msleep(5);
-  }
-  // VSR: 04/12/03 ---> update object browser ufter finishing
-//   qApp->lock();
-//   myMain->getStudy()->updateObjBrowser();
-//   qApp->unlock();
-  // VSR: 04/12/03 <---    
+      // asv 03.02.05 : fix for PAL6859, not very good, but works..
+      myMain->sync();
+    } // end of if !myIsActive
+  } // end of while( myIsActive )
 
   QThread::exit();
 }
index 131c918ae5348bab145aebab435fc79a9db36741..ef8bd80d20fa2d0e202267ad5fbd7ac02028af24 100644 (file)
@@ -219,7 +219,6 @@ class SUPERVGUI_Thread : public QObject, public QThread {
   ~SUPERVGUI_Thread();
 
   void startThread(const char* m);
-  void stopThread(const char* m);
   void setMain(SUPERVGUI_Main* theMain);
 
  public slots: