Salome HOME
Patch from Christian CAREMOLI for bug PAL10339 : random GUI freeze.
authormkr <mkr@opencascade.com>
Mon, 24 Oct 2005 10:26:51 +0000 (10:26 +0000)
committermkr <mkr@opencascade.com>
Mon, 24 Oct 2005 10:26:51 +0000 (10:26 +0000)
src/SUPERVGUI/SUPERVGUI_Main.cxx
src/SUPERVGUI/SUPERVGUI_Main.h

index 0b858393313d41daee986941dc092f606351501a..4bbdb9e5e2ba19273902f20ef74d800f66793daf 100644 (file)
@@ -1351,69 +1351,105 @@ void SUPERVGUI_Thread::KillThread( bool theValue )
   myMutex.unlock();
 }
 
-typedef TVoidMemFun2ArgEvent<SUPERVGUI_Main, char*, SUPERV::GraphState> TNodeSyncEvent;
-
-void SUPERVGUI_Thread::run()
-{
-  myMain->startTimer();
-
-  // GUI cycle to handle events coming for Engine
-  while ( myIsActive ) {
+template<class TObject, typename TArg, typename TArg1, typename TArg2,
+        typename TStoreArg = TArg, typename TStoreArg1 = TArg1, typename TStoreArg2 = TArg2>
+class TVoidMemFun3ArgEvent: public SALOME_Event{
+public:
+  typedef void (TObject::* TAction)(TArg,TArg1,TArg2);
+  TVoidMemFun3ArgEvent(TObject* theObject, TAction theAction, TArg theArg, TArg1 theArg1, TArg2 theArg2):
+    myObject(theObject),
+    myAction(theAction),
+    myArg(theArg),
+    myArg1(theArg1),
+    myArg2(theArg2)
+  {}
+  virtual void Execute(){
+    (myObject->*myAction)(myArg,myArg1,myArg2);
+  }
+private:
+  TObject* myObject;
+  TAction myAction;
+  TStoreArg myArg;
+  TStoreArg1 myArg1;
+  TStoreArg2 myArg2;
+};
 
-    SUPERV_CNode aNode = NULL;
-    SUPERV::GraphEvent aEvent = SUPERV::UndefinedEvent ;
-    SUPERV::GraphState aState = SUPERV::UndefinedState ;
+typedef TVoidMemFun3ArgEvent<SUPERVGUI_Thread, SUPERV_CNode&, SUPERV::GraphEvent&, SUPERV::GraphState&> TMainRunEvent;
 
-    // blocking function of Engine.  Return from there only after anEvent happens on node aNode
-    myMain->getDataflow()->Event(aNode, aEvent, aState);
-    
+/**
+ * main_thread_run must be executed in the qt main thread
+ * It is activated by calling ProcessVoidEvent
+ */
+void SUPERVGUI_Thread::main_thread_run(SUPERV_CNode& aNode, SUPERV::GraphEvent& aEvent, SUPERV::GraphState& aState)
+{
     // in case node "said" something during changing state through notification mechanism - output it
     myMain->syncNotification();
     
     // "kill" or undefined event came
     if (( aEvent == SUPERV::UndefinedEvent && aState == SUPERV::UndefinedState ) ||
-       ( aEvent == SUPERV::NoEvent && aState == SUPERV::NoState ) ||
-       ( aEvent == SUPERV::KillEvent && aState == SUPERV::KillState )) {
+       ( aEvent == SUPERV::NoEvent && aState == SUPERV::NoState ) ||
+       ( aEvent == SUPERV::KillEvent && aState == SUPERV::KillState )) {
 
       myIsActive = false;
     }
     else { // a "normal" execution event came
       char* aName = NULL;
       if ( aNode != NULL && !CORBA::is_nil( aNode ) ) 
-       aName = aNode->Name();      
+       aName = aNode->Name();      
 
+      // What follow is not quite sure. The entire function is posted to the main qt thread.
+      // So all executions are serialized. Is it really possible to call execute when another
+      // execute is running. I don't think so (C Caremoli)
       // 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 ) );
+      myMain->execute(aName, aState );
     }    
-  
+
     // execution is finished.  just set a "finished" message(s)
     if ( !myIsActive ) {
       switch ( myMain->getDataflow()->State() ) {
       case SUPERV_Editing :     
-       myMain->getMessage()->putMessage( myMain->getDataflow()->IsReadOnly()? 
-                                        tr("MSG_GRAPH_READONLY"): tr("MSG_GRAPH_EDITING") );
-       break;  
+       myMain->getMessage()->putMessage( myMain->getDataflow()->IsReadOnly()? 
+                                        tr("MSG_GRAPH_READONLY"): tr("MSG_GRAPH_EDITING") );
+       break;  
       case SUPERV_Suspend : 
-       myMain->getMessage()->putMessage( tr("MSG_GRAPH_SUSPENDED") );
-       break; 
+       myMain->getMessage()->putMessage( tr("MSG_GRAPH_SUSPENDED") );
+       break; 
       case SUPERV_Done : 
-       myMain->getMessage()->putMessage( tr("MSG_GRAPH_FINISHED") );
-       break;  
+       myMain->getMessage()->putMessage( tr("MSG_GRAPH_FINISHED") );
+       break;  
       case SUPERV_Error :
-       myMain->getMessage()->putMessage( tr("MSG_GRAPH_ABORTED") );
-       break;  
+       myMain->getMessage()->putMessage( tr("MSG_GRAPH_ABORTED") );
+       break;  
       case SUPERV_Kill:
-       myMain->getMessage()->putMessage( tr("MSG_GRAPH_KILLED") );
-       break;
+       myMain->getMessage()->putMessage( tr("MSG_GRAPH_KILLED") );
+       break;
       } // end of switch
 
       // asv 03.02.05 : fix for PAL6859, not very good, but works..
       myMain->sync();
     } // end of if !myIsActive
-  } // end of while( myIsActive )
+}
 
+void SUPERVGUI_Thread::run()
+{
+  myMain->startTimer();
+  
+  // GUI cycle to handle events coming for Engine
+  while ( myIsActive ) {
+    
+    SUPERV_CNode aNode = NULL;
+    SUPERV::GraphEvent aEvent = SUPERV::UndefinedEvent ;
+    SUPERV::GraphState aState = SUPERV::UndefinedState ;
+    
+    // blocking function of Engine.  Return from there only after anEvent happens on node aNode
+    myMain->getDataflow()->Event(aNode, aEvent, aState);
+    
+    ProcessVoidEvent( new TMainRunEvent( this, &SUPERVGUI_Thread::main_thread_run,aNode, aEvent, aState ) );
+    
+  } // end of while( myIsActive )
+  
   QThread::exit();
 }
 
index e0f834e0993d9986548e61a4c459bd9774d68f27..5d52fce86882115042e2215bcee9c0cc609e7a8c 100644 (file)
@@ -224,6 +224,7 @@ class SUPERVGUI_Thread : public QObject, public QThread {
   
  protected:
   virtual void run();
+  void main_thread_run(SUPERV_CNode& aNode, SUPERV::GraphEvent& aEvent, SUPERV::GraphState& aState);
 
  private:
   bool                myIsActive;