Salome HOME
Patch from Christian CAREMOLI for bug PAL10339 : random GUI freeze.
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_Main.cxx
index 494dd7e5cf2e080693f1a7078f659e7cefec166f..4bbdb9e5e2ba19273902f20ef74d800f66793daf 100644 (file)
@@ -1069,10 +1069,18 @@ bool SUPERVGUI_Main::putDataStudy( SUPERV_Port p, const char* inout ) {
        }
       }
       else { // FNode is NULL -> bad
-       MESSAGE( "FNode is NULL.  Not good at all.  Aborting command." );
-       aBuilder->AbortCommand();
-       isIn = false;
-       return false;
+       MESSAGE( "FNode is NULL." );
+       if ( SUPERV::INode::_narrow( p->Node() ) ) { // mkr : IPAL10175
+         _PTR(SObject) anIORSO ( aStudy->FindObjectIOR( p->ToString() ) );
+         if ( anIORSO )
+           aBuilder->Addreference(aSO, anIORSO);
+       }
+       else {
+         MESSAGE( "FNode and INode are NULL.  Not good at all.  Aborting command." );
+         aBuilder->AbortCommand();
+         isIn = false;
+         return false;
+       }
       }
     } 
     else {
@@ -1293,6 +1301,20 @@ bool SUPERVGUI_Main::ReadyToModify() {
   return true;
 }
 
+void SUPERVGUI_Main::resizeView( QResizeEvent* theEvent )
+{
+  if ( (myCurrentView == CANVAS || myCurrentView == CONTROLFLOW) && getCanvas() )
+    if ( getCanvas()->width() < theEvent->size().width()
+        ||
+        getCanvas()->height() < theEvent->size().height() )
+      getCanvas()->resize( theEvent->size().width(), theEvent->size().height() );
+  if ( myCurrentView == CANVASTABLE && getCanvasArray() )
+    if ( getCanvasArray()->width() < theEvent->size().width()
+        ||
+        getCanvasArray()->height() < theEvent->size().height() )
+      getCanvasArray()->resize( theEvent->size().width(), theEvent->size().height() );
+}
+
 /******************************* SUPERVGUI_Thread class ****************************************/
 SUPERVGUI_Thread::SUPERVGUI_Thread()
      :QThread()
@@ -1329,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();
 }