Salome HOME
Update version to 3.1.0a
[modules/superv.git] / src / Supervision / Graph_Impl.cxx
index 31358d78322d656f7ded040d322f1ff71f74d874..b6aee77e1bd8cb40d387be9bf2718c5316d2d8e0 100644 (file)
@@ -34,6 +34,8 @@ using namespace std;
 
 //#include "utilities.h"
 
+#include "SALOME_Container_i.hxx"
+
 #include "StreamGraph_Impl.hxx"
 
 #include "DataFlowEditor_DataFlow.hxx"
@@ -46,11 +48,7 @@ static void CreateEditor( CORBA::ORB_ptr orb ,
                           const SUPERV::KindOfNode aKindOfNode ,
                           string & dbgfile ,
                           GraphEditor::DataFlow **  aDataFlowEditor ) {
-//    string dbgfile = "/tmp/" ;
   bool aXmlFile = false ;
-  dbgfile = "/tmp/" ;
-  dbgfile += instanceName ;
-  dbgfile += "_" ;
   int lenname = strlen( aDataFlowName ) ;
   char * theDataFlowName = new char [ lenname+1 ] ;
   strcpy( theDataFlowName , aDataFlowName ) ;
@@ -72,52 +70,84 @@ static void CreateEditor( CORBA::ORB_ptr orb ,
       strcpy( theDataFlowName , &aDataFlowName[ 0 ] ) ;
     }
   }
+  
   string theDataFlowInstanceName = theDataFlowName ;
-  if ( !aXmlFile ) {
-    theDataFlowInstanceName = theAutomaton->GraphInstanceName( theDataFlowName ) ;
-  }
+
+  // asv : 16.11.04 : creation of log file in /tmp/logs/$USER dir. 
+  // "/tmp/logs/$USER" was created by  runSalome.py -> orbmodule.py.
+  dbgfile = "/tmp/logs/" ;
+  dbgfile += getenv( "USER" ) ;
+  dbgfile += "/" ;
+  dbgfile += instanceName ;
+  dbgfile += "_" ;
   dbgfile += theDataFlowInstanceName ;
   dbgfile = dbgfile + "_" + theAutomaton->DbgFileNumber() + ".log" ;
+  FILE* f = fopen ( dbgfile.c_str(), "a" );
+  if ( f ) { // check if file can be opened for writing
+    fclose( f );
+  } 
+  else { // if file can't be opened - use a guaranteed temp file name
+    char* aTempNam = tempnam( NULL, NULL );
+    dbgfile = aTempNam;
+    free ( aTempNam );
+  }
+
   SALOME_NamingService * NamingService = new SALOME_NamingService( orb ) ;
   *aDataFlowEditor = new GraphEditor::DataFlow( orb , NamingService ,
                                                 theDataFlowInstanceName.c_str() , dbgfile.c_str() ,
                                                 aKindOfNode ) ;
   MESSAGE( "CreateEditor " << theDataFlowName << " uniquely named " << theDataFlowInstanceName << " created with "
            << dbgfile.c_str() ) ;
+
   delete [] theDataFlowName ;
 }
 
-static void CreateEditor( CORBA::ORB_ptr orb ,
+static void CreateExecutor( CORBA::ORB_ptr orb ,
                          const char *instanceName ,
                           const char *aDataFlowName ,
                           const SUPERV::KindOfNode aKindOfNode ,
                           string & dbgfile ,
                           GraphExecutor::DataFlow **  aDataFlowExecutor ) {
-//    string dbgfile = "/tmp/" ;
-  dbgfile = "/tmp/" ;
-  dbgfile += instanceName ;
-  dbgfile += "_" ;
   int lenname = strlen( aDataFlowName ) ;
   char * theDataFlowName = new char [ lenname+1 ] ;
   strcpy( theDataFlowName , aDataFlowName ) ;
   if ( aDataFlowName ) {
     strcpy( theDataFlowName , &aDataFlowName[ 0 ] ) ;
   }
+
   string theDataFlowInstanceName = theDataFlowName ;
+
+  // asv : 16.11.04 : creation of log file in /tmp/logs/$USER dir. 
+  // "/tmp/logs/$USER" was created by  runSalome.py -> orbmodule.py.
+  dbgfile = "/tmp/logs/" ;
+  dbgfile += getenv( "USER" ) ;
+  dbgfile += "/" ;
+  dbgfile += instanceName ;
+  dbgfile += "_" ;
   dbgfile += theDataFlowInstanceName ;
   dbgfile = dbgfile + "_" + theAutomaton->DbgFileNumber() ;
-
   ostringstream astr ;
   astr << theAutomaton->ExecNumber() ;
   dbgfile += astr.str() ;
   dbgfile += string( "_Exec.log" ) ;
+  FILE* f = fopen ( dbgfile.c_str(), "a" );
+  if ( f ) { // check if file can be opened for writing
+    fclose( f );
+  } 
+  else { // if file can't be opened - use a guaranteed temp file name
+    char* aTempNam = tempnam( NULL, NULL );
+    dbgfile = aTempNam;
+    free ( aTempNam );
+  }
 
   SALOME_NamingService * NamingService = new SALOME_NamingService( orb ) ;
   *aDataFlowExecutor = new GraphExecutor::DataFlow( orb , NamingService ,
                                                     theDataFlowInstanceName.c_str() , dbgfile.c_str() ,
                                                     aKindOfNode ) ;
-  MESSAGE( "CreateEditor " << theDataFlowName << " " << theDataFlowInstanceName << " created with "
+
+  MESSAGE( "CreateExecutor " << theDataFlowName << " " << theDataFlowInstanceName << " created with "
            << dbgfile.c_str() ) ;
+
   delete [] theDataFlowName ;
 }
 
@@ -136,6 +166,7 @@ Graph_Impl::Graph_Impl( CORBA::ORB_ptr orb ,
   _Orb = CORBA::ORB::_duplicate(orb);
   _Poa = poa ;
   _ContId = contId ;
+  _DebugFileName = NULL ;
   if ( aKindOfNode == SUPERV::DataFlowGraph || aKindOfNode == SUPERV::MacroNode ) {
 //    MESSAGE( "Graph_Impl::Graph_Impl _poa->activate_object" );
     _thisObj = this ;
@@ -150,12 +181,16 @@ Graph_Impl::Graph_Impl( CORBA::ORB_ptr orb ,
     GraphEditor::DataFlow * aDataFlowEditor ;
     CreateEditor( orb , instanceName , aDataFlowName , aKindOfNode ,
                   dbgfile , &aDataFlowEditor ) ;
+
+    if ( _DebugFileName ) {
+      delete [] _DebugFileName ;
+    }
     _DebugFileName = new char[ strlen( dbgfile.c_str() )+1 ] ;
     strcpy( _DebugFileName , dbgfile.c_str() ) ;
 
     _NamingService = new SALOME_NamingService( orb ) ;
     DataFlowEditor( aDataFlowEditor ) ;
-    DataFlowEditor()->Graph()->SetGraphEditor( aDataFlowEditor ) ;
+    DataFlowEditor()->Graph()->GraphEditor( aDataFlowEditor ) ;
     DataFlowEditor()->Graph()->SetObjImpl( this ) ;
   }
   pthread_mutex_init( &_MutexExecutorWait , NULL ) ;
@@ -173,7 +208,8 @@ Graph_Impl::Graph_Impl( CORBA::ORB_ptr orb ,
   GNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , aDataFlowNode ) {
 //  beginService( "Graph_Impl::Graph_Impl" );
 //  MESSAGE( aDataFlowEditor->Graph()->Name() << " " );
-  if ( aDataFlowEditor->Graph()->IsDataFlowNode() || aDataFlowNode->IsMacroNode() ) {
+  if ( aDataFlowEditor->Graph()->IsDataFlowNode() ||
+       ( aDataFlowNode && aDataFlowNode->IsMacroNode() ) ) {
 //    MESSAGE( "Graph_Impl::Graph_Impl _poa->activate_object" );
     _thisObj = this ;
     _id = _poa->activate_object(_thisObj);
@@ -184,43 +220,15 @@ Graph_Impl::Graph_Impl( CORBA::ORB_ptr orb ,
   _Orb = CORBA::ORB::_duplicate(orb);
   _Poa = poa ;
   _ContId = contId ;
+  _DebugFileName = NULL ;
   DataFlowEditor( aDataFlowEditor ) ;
-    DataFlowEditor()->Graph()->SetGraphEditor( aDataFlowEditor ) ;
+  DataFlowEditor()->Graph()->GraphEditor( aDataFlowEditor ) ;
   DataFlowEditor()->Graph()->SetObjImpl( this ) ;
   pthread_mutex_init( &_MutexExecutorWait , NULL ) ;
 //  DataFlowExecutor( NULL ) ;
 //  endService( "Graph_Impl::Graph_Impl" );  
 }
 
-Graph_Impl::Graph_Impl( CORBA::ORB_ptr orb ,
-                       PortableServer::POA_ptr poa ,
-                       PortableServer::ObjectId * contId , 
-                       const char *instanceName ,
-                        const char *interfaceName ,
-                        GraphExecutor::DataFlow * aDataFlowExecutor ,
-                        GraphExecutor::InNode * aDataFlowExecutorNode ) :
-  GNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowExecutor , aDataFlowExecutorNode ) {
-//  beginService( "Graph_Impl::Graph_Impl" );
-//  MESSAGE( aDataFlowExecutor->Graph()->Name() << " " );
-  if ( aDataFlowExecutor->Graph()->IsDataFlowNode() || aDataFlowExecutorNode->IsMacroNode() ) {
-//    MESSAGE( "Graph_Impl::Graph_Impl _poa->activate_object" );
-    _thisObj = this ;
-    _id = _poa->activate_object(_thisObj);
-  }
-  else {
-//    MESSAGE( "Graph_Impl::Graph_Impl NO _poa->activate_object " );
-  }
-  _Orb = CORBA::ORB::_duplicate(orb);
-  _Poa = poa ;
-  _ContId = contId ;
-  DataFlowExecutor( aDataFlowExecutor ) ;
-  DataFlowExecutor()->Graph()->SetGraphExecutor( aDataFlowExecutor ) ;
-  DataFlowExecutor()->Graph()->SetObjImpl( this ) ;
-  pthread_mutex_init( &_MutexExecutorWait , NULL ) ;
-//  DataFlowExecutor( NULL ) ;
-//  endService( "Graph_Impl::Graph_Impl" );  
-}
-
 Graph_Impl::Graph_Impl() {
 }
 
@@ -231,11 +239,25 @@ Graph_Impl::~Graph_Impl() {
 
 void Graph_Impl::destroy() {
   beginService( "Graph_Impl::destroy" );
+  if ( DataFlowNode() && DataFlowNode()->ComputingNode()->IsMacroNode() ) {
+    SUPERV::Graph_var aGraph = DataFlowNode()->GOTONode()->MacroObject() ;
+    GNode_Impl::Delete() ;
+    if ( !CORBA::is_nil( aGraph ) ) {
+      aGraph->destroy() ;
+    }
+  }
+  else {
+    SUPERV::Graph_var aGraph = DataFlowEditor()->Graph()->MacroObject() ;
+    GNode_Impl::Delete() ;
+    if ( !CORBA::is_nil( aGraph ) ) {
+      aGraph->destroy() ;
+    }
+  }
   _poa->deactivate_object(*_id) ;
-  CORBA::release(_poa) ;
+//  CORBA::release(_poa) ;
   delete(_id) ;
-  _thisObj->_remove_ref();
-//  endService( "Graph_Impl::destroy" );
+//  _thisObj->_remove_ref();
+  endService( "Graph_Impl::destroy" );
 }
 
 
@@ -293,7 +315,9 @@ bool Graph_Impl::LoadGraphs( GraphBase::ListOfSGraphs * aListOfDataFlows ) {
   bool RetVal = false ;
   if ( DataFlowEditor()->IsEditing() ) {
 //    RetVal = DataFlowEditor()->LoadDataFlows( aListOfDataFlows ) ;
-    RetVal = LoadDataFlows( DataFlowEditor() , aListOfDataFlows , 0 ) ;
+    if ( CORBA::is_nil( LoadDataFlows( DataFlowEditor() , aListOfDataFlows , 0 ) ) ) {
+      RetVal = false ;
+    }
   }
   endService( "Graph_Impl::LoadGraphs" );
   return RetVal ;
@@ -307,7 +331,9 @@ bool Graph_Impl::Import(const char * aXmlFile ) {
     RetVal = DataFlowEditor()->LoadXml( aXmlFile , aListOfDataFlows ) ;
     if ( RetVal && aXmlFile != NULL ) {
 //      RetVal = DataFlowEditor()->LoadDataFlows( &aListOfDataFlows ) ;
-      RetVal = LoadDataFlows( DataFlowEditor() , &aListOfDataFlows , 0 ) ;
+      if ( CORBA::is_nil( LoadDataFlows( DataFlowEditor() , &aListOfDataFlows , 0 ) ) ) {
+        RetVal = false ;
+      }
     }
   }
   endService( "Graph_Impl::Import" );
@@ -342,6 +368,15 @@ bool Graph_Impl::Export(const char * anXmlFile ) {
   return RetVal ;
 }
 
+char *  Graph_Impl::SavePY( bool importSuperV ) {
+  beginService( "Graph_Impl::SavePY" );
+  ostringstream fstring ;
+  bool RetVal ;
+  RetVal = DataFlowEditor()->SavePY( fstring , importSuperV ) ;
+  fstring  << ends ;
+  endService( "Graph_Impl::SavePY" );
+  return CORBA::string_dup( fstring.str().c_str() );
+}
 SUPERV::CNode_ptr Graph_Impl::CNode( const SALOME_ModuleCatalog::Service &NodeService ) {
   beginService( "Graph_Impl::CNode" );
   SUPERV::CNode_var iobject = SUPERV::CNode::_nil() ;
@@ -358,6 +393,7 @@ SUPERV::CNode_ptr Graph_Impl::CNode( const SALOME_ModuleCatalog::Service &NodeSe
       myNode->SetObjRef( SUPERV::CNode::_duplicate( iobject ) ) ;
     }
   }
+  DataFlowEditor()->UnValid() ;
   endService( "Graph_Impl::CNode" );
   return SUPERV::CNode::_duplicate( iobject ) ;
 }
@@ -381,6 +417,7 @@ SUPERV::FNode_ptr Graph_Impl::FNode( const char * NodeComponentName ,
       myNode->SetObjRef( SUPERV::FNode::_duplicate( iobject ) ) ;
     }
   }
+  DataFlowEditor()->UnValid() ;
   endService( "Graph_Impl::FNode" );
   return SUPERV::FNode::_duplicate( iobject ) ;
 }
@@ -432,6 +469,7 @@ SUPERV::GNode_ptr Graph_Impl::GNode( const char * FuncName ,
       }
     }
   }
+  DataFlowEditor()->UnValid() ;
   endService( "Graph_Impl::GNode" );
   return SUPERV::GNode::_duplicate( iobject ) ;
 }
@@ -493,11 +531,14 @@ SUPERV::LNode_ptr Graph_Impl::LNode( const char * InitName ,
       myEndNode->SetObjRef( SUPERV::ELNode::_duplicate( iendobject ) ) ;
       myNode->SetCoupled( myEndNode->BaseNode()->Name() ) ;
       myEndNode->SetCoupled( myNode->BaseNode()->Name() ) ;
-      Link( myNode->Port( "DoLoop" ) , myEndNode->Port( "DoLoop" ) ) ;
-      Link( myEndNode->Port( "DoLoop" ) , myNode->Port( "InitLoop" ) ) ;
+//JR 25.01.2005  That links are already done in SetCoupled above ...
+//      Link( myNode->Port( "DoLoop" ) , myEndNode->Port( "DoLoop" ) ) ;
+//      Link( myEndNode->Port( "DoLoop" ) , myNode->Port( "InitLoop" ) ) ;
+//      Link( myEndNode->Port( "DoLoop" ) , myNode->Port( "DoLoop" ) ) ;
     }
   }
   anEndOfLoop = SUPERV::ELNode::_duplicate( iendobject ) ;
+  DataFlowEditor()->UnValid() ;
   endService( "Graph_Impl::LNode" );
   return SUPERV::LNode::_duplicate( iobject ) ;
 }
@@ -551,24 +592,30 @@ SUPERV::SNode_ptr Graph_Impl::SNode( const char * FuncName ,
     }
   }
   anEndOfSwitch = SUPERV::ESNode::_duplicate( iendobject ) ;
+  DataFlowEditor()->UnValid() ;
   endService( "Graph_Impl::SNode" );
   return SUPERV::SNode::_duplicate( iobject ) ;
 }
 
 // WARNING : THIS IS COMPLICATED :
-bool Graph_Impl::LoadDataFlows( GraphEditor::DataFlow * aDataFlowEditor ,
-                                GraphBase::ListOfSGraphs * aListOfDataFlows ,
-                                int index ) {
+SUPERV::Graph_var Graph_Impl::LoadDataFlows( GraphEditor::DataFlow * aDataFlowEditor ,
+                                             GraphBase::ListOfSGraphs * aListOfDataFlows ,
+                                             int index ) {
   beginService( "Graph_Impl::EditorLoadDataFlows" ) ;
+  MESSAGE("Graph_Impl::LoadDataFlows index " << index << " " << (*aListOfDataFlows)[index].Info.theName.c_str() ) ;
+
   SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
+// That method is recursive :
+// At first we load the supergraph with index = 0 :
+// (After we load the graph corresponding to each MacroNode :)
   if ( !aDataFlowEditor->LoadDataFlow( &(*aListOfDataFlows)[ index ] ) ) {
-    MESSAGE("Graph_Impl::LoadDataFlows failed" ) ;
-    return false ;
+    MESSAGE("Graph_Impl::LoadDataFlows failed " << (*aListOfDataFlows)[index].Info.theName.c_str() ) ;
+    return SUPERV::Graph::_duplicate( iobject ) ;
   }
 // That graph is not a StreamGraph :
   else if ( !aDataFlowEditor->Graph()->HasDataStream() ) {
     aDataFlowEditor->Graph()->Kind( SUPERV::DataFlowGraph ) ;
-    aDataFlowEditor->Graph()->SetGraphEditor( aDataFlowEditor ) ;
+//    aDataFlowEditor->Graph()->SetGraphEditor( aDataFlowEditor ) ;
     Graph_Impl * myGraph ;
 // We create a Graph ObjRef for that graph
     myGraph = new Graph_Impl( _Orb , _Poa, _ContId,
@@ -578,237 +625,268 @@ bool Graph_Impl::LoadDataFlows( GraphEditor::DataFlow * aDataFlowEditor ,
     CORBA::Object_var obj = _poa->id_to_reference(*id) ;
     iobject = SUPERV::Graph::_narrow( obj ) ;
     myGraph->SetObjRef( SUPERV::Graph::_duplicate( iobject ) ) ;
+    myGraph->SetObjImpl( (CNode_Impl * ) myGraph ) ;
     GraphBase::Graph * aGraph = myGraph->DataFlowEditor()->Graph() ;
     int i ;
+
+// asv: set Editor for the graph itself and for all its macro nodes
+    aGraph->GraphEditor( aDataFlowEditor );
+
+// For the supergraph or each graph of MacroNodes we search MacroNodes recursively :
     for ( i = 0 ; i < aGraph->GraphNodesSize() ; i++ ) {
       if ( aGraph->GraphNodes( i )->IsMacroNode() ) {
         GraphBase::GOTONode * aMacroNode = (GraphBase::GOTONode * ) aGraph->GraphNodes( i ) ;
 
+       // asv : 05.11.04 : fix of bug - "insert file" into existing graph with MacroNodes worked incorrectly!
+       // aMacroNode is an "old" node, and here we must analize only "new" nodes, that
+       // came from aListOfDataFlows and were loaded by aDataFlowEditor->LoadDataFlow( &(*aListOfDataFlows)[ index ] )
+       // so here we check if the node is "new" or "old"
+       if ( aMacroNode->GraphEditor() && aMacroNode->CoupledNode() )
+         continue;
 
+       // asv: set Editor for the graph itself and for all its macro nodes
+       aMacroNode->GraphEditor( aDataFlowEditor );
 
-// Creation of a GraphMacroNode in the current editor
+       // Creation of a GraphMacroNode ObjRef in the current editor
         SUPERV::Graph_var macroiobject = SUPERV::Graph::_nil() ;
-        string aMacroNodeName = string( "Macro_" ) + string( myGraph->Name() ) ;
         Graph_Impl * myMacroNode ;
         myMacroNode = new Graph_Impl( _Orb , _Poa, _ContId,
                                       instanceName() , interfaceName() ,
-                                      aMacroNodeName.c_str() , SUPERV::MacroNode ) ;
+                                      aMacroNode->Name() , SUPERV::MacroNode ) ;
         id = myMacroNode->getId() ;
         obj = _poa->id_to_reference(*id);
         macroiobject = SUPERV::Graph::_narrow( obj ) ;
-        myMacroNode->DataFlowEditor( DataFlowEditor() ) ;
-        aMacroNode->SetGraphEditor( DataFlowEditor() ) ;
+        myMacroNode->DataFlowEditor( aDataFlowEditor ) ;
         GraphEditor::InNode * aDataFlowNode = (GraphEditor::InNode * ) aMacroNode->GetInNode() ;
         myMacroNode->DataFlowNode( aDataFlowNode ) ;
         aDataFlowNode->SetObjRef( SUPERV::CNode::_duplicate( SUPERV::CNode::_narrow( obj ) ) ) ;
-        aDataFlowNode->SetObjImpl( this ) ;
-
-
-
-
+        aDataFlowNode->SetObjImpl( myMacroNode ) ;
 
         char * aCoupledNodeName = aMacroNode->CoupledNodeName() ;
         MESSAGE( "LoadDataFlows MacroNode " << aMacroNode->Name() << " --> " << aCoupledNodeName
                  << " to be searched among " << (*aListOfDataFlows).size() << " Graphs" ) ;
         int index ;
+        bool found = false ;
         for ( index = 0 ; index < (int ) (*aListOfDataFlows).size() ; index++ ) {
+          MESSAGE( "LoadDataFlows Graph" << index << " " << (*aListOfDataFlows)[index].Info.theName.c_str() ) ;
           if ( !strcmp( aCoupledNodeName , (*aListOfDataFlows)[index].Info.theName.c_str() ) ) {
+            found = true ;
             string dbgfile ;
 // At first create the editor and a StreamGraph
             GraphEditor::DataFlow * aMacroGraphDataFlowEditor ;
             CreateEditor( _Orb , instanceName() , aCoupledNodeName , SUPERV::DataStreamGraph ,
                           dbgfile , &aMacroGraphDataFlowEditor ) ;
-//            if ( !aDataFlowEditor->LoadDataFlow( aDataFlowEditor , aListOfDataFlows , index ) ) {
+
+            if ( _DebugFileName ) {
+              delete [] _DebugFileName ;
+            }
+            _DebugFileName = new char[ strlen( dbgfile.c_str() )+1 ] ;
+            strcpy( _DebugFileName , dbgfile.c_str() ) ;
+
             MESSAGE( "RECURSIVE IMPORT OF GRAPHS OF MACRONODES :" << aCoupledNodeName ) ;
-            if ( !LoadDataFlows( aMacroGraphDataFlowEditor , aListOfDataFlows , index ) ) {
+            if ( CORBA::is_nil( LoadDataFlows( aMacroGraphDataFlowEditor , aListOfDataFlows , index ) ) ) {
               MESSAGE("Graph_Impl::LoadDataFlows failed" ) ;
-              return false ;
+              return SUPERV::Graph::_duplicate( iobject ) ;
             }
 
 // That graph is not a StreamGraph :
             else if ( !aMacroGraphDataFlowEditor->Graph()->HasDataStream() ) {
-              aMacroGraphDataFlowEditor->Graph()->Kind( SUPERV::DataFlowGraph ) ;
-              aMacroGraphDataFlowEditor->Graph()->SetGraphEditor( aMacroGraphDataFlowEditor ) ;
               Graph_Impl * myMacroGraph ;
-// We create a Graph ObjRef for that graph
-              myMacroGraph = new Graph_Impl( _Orb , _Poa, _ContId,
-                                             instanceName() , interfaceName() ,
-                                             aMacroGraphDataFlowEditor , NULL ) ;
-              PortableServer::ObjectId * id = myMacroGraph->getId() ;
-              CORBA::Object_var obj = _poa->id_to_reference(*id);
-              SUPERV::Graph_var iobject = SUPERV::Graph::_narrow( obj ) ;
-              myMacroGraph->SetObjRef( SUPERV::Graph::_duplicate( iobject ) ) ;
+// The Graph ObjRef for that graph was already created
+              myMacroGraph = (Graph_Impl * ) aMacroGraphDataFlowEditor->Graph()->ObjImpl() ;
 
               GraphBase::Graph * aMacroGraph = myMacroGraph->DataFlowEditor()->Graph() ;
+             
               aMacroGraph->GraphMacroLevel( aGraph->GraphMacroLevel() + 1 ) ;
               aMacroGraph->CoupledNode( aMacroNode ) ;
-
-              aMacroGraph->MacroObject( SUPERV::Graph::_duplicate( iobject ) ) ;
               aMacroGraph->MacroObject( SUPERV::Graph::_duplicate( macroiobject ) ) ;
 
 // Set the GraphMacroNode ObjRef in the MacroNode
+              aMacroNode->GraphMacroLevel( aGraph->GraphMacroLevel() + 1 ) ;
               aMacroNode->CoupledNode( aMacroGraph ) ;
-              aMacroNode->MacroObject( SUPERV::Graph::_duplicate( iobject ) ) ;
+              aMacroNode->MacroObject( SUPERV::Graph::_narrow( aMacroGraphDataFlowEditor->Graph()->ObjRef() ) ) ;
+              MESSAGE( "LoadDataFlows aMacroGraph " << aMacroGraph << " " << aMacroGraph->Name()
+                       << " coupled to " << aMacroGraph->CoupledNode() << " "
+                       << aMacroGraph->CoupledNode()->Name() << " Editor " << aMacroGraph->GraphEditor() ) ;
+              MESSAGE( "LoadDataFlows aMacroNode " << aMacroNode << " " << aMacroNode->Name()
+                       << " coupled to " << aMacroNode->CoupledNode() << " "
+                       << aMacroNode->CoupledNode()->Name() << " Editor " << aMacroNode->GraphEditor() ) ;
+              MESSAGE( "LoadDataFlows current Graph " << aGraph << " " << aGraph->Name()
+                       << " coupled to " << aGraph->CoupledNode()
+                       << " Editor " << aGraph->GraphEditor() << " " << aGraph->Name() ) ;
            }
+            break ;
          }
        }
+        if ( !found ) {
+          return SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
+       }
       }
     }
   }
+  else if ( (*aListOfDataFlows).size() == 1 ) {
+    StreamGraph_Impl * myStreamGraph ;
+// We create a Graph ObjRef for that graph
+    myStreamGraph = new StreamGraph_Impl( _Orb , _Poa, _ContId,
+                                          instanceName() , interfaceName() ,
+                                          aDataFlowEditor , NULL ) ;
+    PortableServer::ObjectId * id = myStreamGraph->getId() ;
+    CORBA::Object_var obj = _poa->id_to_reference(*id) ;
+    SUPERV::StreamGraph_var Streamiobject = SUPERV::StreamGraph::_nil() ;
+    Streamiobject = SUPERV::StreamGraph::_narrow( obj ) ;
+    myStreamGraph->SetObjRef( SUPERV::StreamGraph::_duplicate( Streamiobject ) ) ;
+    myStreamGraph->SetObjImpl( (CNode_Impl * ) myStreamGraph ) ;
+//    iobject = SUPERV::Graph::_narrow( obj ) ;
+    iobject = SUPERV::Graph::_narrow( Streamiobject ) ;
+  }
+  else {
+    MESSAGE( "Graph_Impl::LoadDataFlows StreamGraph with MacroNodes not yet implemented" ) ;
+  }
 
   endService( "Graph_Impl::EditorLoadDataFlows" );
-  return true ;
+  return SUPERV::Graph::_duplicate( iobject ) ;
 }
 
-bool Graph_Impl::LoadDataFlows( GraphExecutor::DataFlow * aDataFlowExecutor ,
-                                GraphBase::ListOfSGraphs * aListOfDataFlows ,
-                                int index ) {
+SUPERV::Graph_var Graph_Impl::LoadDataFlows( GraphExecutor::DataFlow * aDataFlowExecutor ,
+                                             GraphBase::ListOfSGraphs * aListOfDataFlows ,
+                                             int index ) {
   beginService( "Graph_Impl::ExecutorLoadDataFlows" ) ;
-  MESSAGE("Graph_Impl::LoadDataFlows index " << index << " " << (*aListOfDataFlows)[index].Info.theName.c_str() ) ;
-  SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
-// That method is recursive :
-// At first we load the supergraph with index = 0 :
-// (After we load the graph corresponding to each MacroNode :)
+  MESSAGE("Graph_Impl::LoadDataFlows(Executor) index " << index << " " << (*aListOfDataFlows)[index].Info.theName.c_str() << " aDataFlowExecutor " << aDataFlowExecutor ) ;
+
+  // That method is recursive :
+  // At first we load the supergraph with index = 0 :
+  // (After we load the graph corresponding to each MacroNode :)
   if ( !aDataFlowExecutor->LoadDataFlow( &(*aListOfDataFlows)[ index ] ) ) {
-    MESSAGE("Graph_Impl::LoadDataFlows failed" ) ;
-    return false ;
+    MESSAGE("Graph_Impl::LoadDataFlows(Executor) failed, could not LoadDataFlow(supergraph)" ) ;
+    return SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
   }
-// That graph is not a StreamGraph :
-  else if ( !aDataFlowExecutor->Graph()->HasDataStream() ) {
+
+  // That graph is not a StreamGraph :
+  else {
     aDataFlowExecutor->Graph()->Kind( SUPERV::DataFlowGraph ) ;
     GraphEditor::DataFlow * aDataFlowEditor ;
-    aDataFlowEditor = theAutomaton->MapGraph( (*aListOfDataFlows)[index].Info.theName.c_str() )->GraphEditor() ;
+    aDataFlowEditor = DataFlowEditor() ;
+    GraphBase::Graph * anEditorGraph = aDataFlowEditor->Graph() ;
+    GraphBase::Graph * anExecutorGraph = aDataFlowExecutor->Graph() ;
+    if ( aDataFlowEditor->Executor() ) {
+      delete aDataFlowEditor->Executor() ;
+      aDataFlowEditor->Executor( NULL ) ;
+      aDataFlowEditor->Editing() ;
+    }
     aDataFlowEditor->Executor( aDataFlowExecutor ) ;
-    aDataFlowEditor->Graph()->SetGraphEditor( aDataFlowEditor ) ;
-    aDataFlowEditor->Graph()->SetGraphExecutor( aDataFlowExecutor ) ;
-    aDataFlowExecutor->Graph()->SetGraphEditor( aDataFlowEditor ) ;
-    aDataFlowExecutor->Graph()->SetGraphExecutor( aDataFlowExecutor ) ;
-    Graph_Impl * myGraph ;
-// We create a Graph ObjRef for that graph
-    myGraph = new Graph_Impl( _Orb , _Poa, _ContId,
-                              instanceName() , interfaceName() ,
-                              aDataFlowExecutor , NULL ) ;
-    PortableServer::ObjectId * id = myGraph->getId() ;
-    CORBA::Object_var obj = _poa->id_to_reference(*id) ;
-    iobject = SUPERV::Graph::_narrow( obj ) ;
-    myGraph->SetObjRef( SUPERV::Graph::_duplicate( iobject ) ) ;
-    myGraph->DataFlowEditor( aDataFlowEditor ) ;
-    myGraph->DataFlowExecutor( aDataFlowExecutor ) ;
-    MESSAGE("ExecutorLoadDataFlows IsEditing " << myGraph->Name() << " "
-            << myGraph->DataFlowEditor() << " " << myGraph->DataFlowEditor()->IsEditing() << " "
-            << myGraph->DataFlowEditor()->Graph()->Name() << " "
-            << myGraph->DataFlowEditor()->Graph()->GraphEditor() << " "
-            << myGraph->DataFlowEditor()->Graph()->GraphEditor()->IsEditing() ) ;
-    GraphBase::Graph * aGraph = myGraph->DataFlowExecutor()->Graph() ;
-    int i ;
-// For the supergraph or each graph of MacroNodes we search MacroNodes recursively :
-    for ( i = 0 ; i < aGraph->GraphNodesSize() ; i++ ) {
-      if ( aGraph->GraphNodes( i )->IsMacroNode() ) {
-        GraphBase::GOTONode * aMacroNode = (GraphBase::GOTONode * ) aGraph->GraphNodes( i ) ;
-
-
-
-// Creation of a GraphMacroNode ObjRef in the current executor
-        SUPERV::Graph_var macroiobject = SUPERV::Graph::_nil() ;
-        string aMacroNodeName = string( "Macro_" ) + string( aGraph->Name() ) ;
-        Graph_Impl * myMacroNode ;
-        myMacroNode = new Graph_Impl( _Orb , _Poa, _ContId,
-                                      instanceName() , interfaceName() ,
-                                      aMacroNodeName.c_str() , SUPERV::MacroNode ) ;
-        id = myMacroNode->getId() ;
-        obj = _poa->id_to_reference(*id);
-        macroiobject = SUPERV::Graph::_narrow( obj ) ;
-        myMacroNode->DataFlowEditor( DataFlowEditor() ) ;
-        myMacroNode->DataFlowExecutor( DataFlowExecutor() ) ;
-        aMacroNode->SetGraphEditor( DataFlowEditor() ) ;
-        GraphExecutor::InNode * aDataFlowExecutorNode = (GraphExecutor::InNode * ) aMacroNode->GetInNode() ;
-        myMacroNode->DataFlowNode( aDataFlowExecutorNode ) ;
-        aDataFlowExecutorNode->SetObjRef( SUPERV::CNode::_duplicate( SUPERV::CNode::_narrow( obj ) ) ) ;
-        aDataFlowExecutorNode->SetObjImpl( this ) ;
-
-        char * aCoupledNodeName = aMacroNode->CoupledNodeName() ;
-        MESSAGE( "LoadDataFlows MacroNode " << aMacroNode->Name() << " --> " << aCoupledNodeName
-                 << " to be searched among " << (*aListOfDataFlows).size() << " Graphs" ) ;
-        int index ;
-        for ( index = 0 ; index < (int ) (*aListOfDataFlows).size() ; index++ ) {
-          if ( !strcmp( aCoupledNodeName , (*aListOfDataFlows)[index].Info.theName.c_str() ) ) {
-            string dbgfile ;
-// At first create the editor and a StreamGraph
-            GraphExecutor::DataFlow * aMacroGraphDataFlowExecutor ;
-            CreateEditor( _Orb , instanceName() , aCoupledNodeName , SUPERV::DataStreamGraph ,
-                          dbgfile , &aMacroGraphDataFlowExecutor ) ;
-//            if ( !aDataFlowEditor->LoadDataFlow( aDataFlowEditor , aListOfDataFlows , index ) ) {
-            MESSAGE( "RECURSIVE IMPORT OF GRAPHS OF MACRONODES :" << aCoupledNodeName ) ;
-            if ( !LoadDataFlows( aMacroGraphDataFlowExecutor , aListOfDataFlows , index ) ) {
-              MESSAGE("Graph_Impl::LoadDataFlows failed" ) ;
-              return false ;
-            }
-
-// That graph is not a StreamGraph :
-            else if ( !aMacroGraphDataFlowExecutor->Graph()->HasDataStream() ) {
-              aMacroGraphDataFlowExecutor->Graph()->Kind( SUPERV::DataFlowGraph ) ;
-              aMacroGraphDataFlowExecutor->Graph()->SetGraphExecutor( aMacroGraphDataFlowExecutor ) ;
-              GraphEditor::DataFlow * aDataFlow = theAutomaton->MapGraph( aCoupledNodeName )->GraphEditor() ;
-              if ( aDataFlow == NULL ) {
-                MESSAGE( "ExecutorLoadDataFlows NULL GraphEditor ERROR" ) ;
+    anExecutorGraph->GraphEditor( aDataFlowEditor ) ;
+
+    if ( !aDataFlowExecutor->Graph()->HasDataStream() ) {
+    // For the supergraph or each graph of MacroNodes we search MacroNodes recursively :
+      int i;
+      for ( i = 0 ; i < anExecutorGraph->GraphNodesSize() ; i++ ) {
+        if ( anExecutorGraph->GraphNodes( i )->IsMacroNode() ) {
+          GraphBase::GOTONode * aMacroNode = (GraphBase::GOTONode * ) anExecutorGraph->GraphNodes( i ) ;
+          aMacroNode->GraphEditor( aDataFlowEditor ) ;
+
+       // get the macro node's editor object
+          char * aMacroGraphName = aMacroNode->CoupledNodeName() ;
+          GraphBase::Graph* aMacroGraph =  (GraphBase::Graph*)((GraphBase::GOTONode *)anEditorGraph->GetGraphNode( aMacroNode->Name() ))->CoupledNode() ;
+       GraphEditor::DataFlow* aMacroGraphEditor = aMacroGraph->GraphEditor();
+
+          MESSAGE( "LoadDataFlows(Executor) MacroNode " << aMacroNode->Name() << " Coupled to " << aMacroGraphName
+                   << " to be searched among " << (*aListOfDataFlows).size() << " Graphs" << endl ) ;
+          int index;
+          bool found = false ;
+          for ( index = 0 ; index < (int ) (*aListOfDataFlows).size() && !found; index++ ) {
+            if ( !strcmp( aMacroGraphName , (*aListOfDataFlows)[index].Info.theName.c_str() ) )
+              found = true;
+         }
+         if ( !found ) {
+           MESSAGE("Graph_Impl::LoadDataFlows(Executor) failed, Macro node's coupled graph \"" << aMacroGraphName << "\" was not found" ) ;
+           return SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
+         }
+         index--; // it was incremented in "for ..." before last check ( !found ).
+       
+       // At first create the editor and a StreamGraph
+         string dbgfile ;
+         GraphExecutor::DataFlow * aMacroGraphExecutor ;
+         CreateExecutor( _Orb , instanceName() , aMacroGraphName , SUPERV::DataStreamGraph ,
+                       dbgfile , &aMacroGraphExecutor );
+
+       // set GraphMacroLevel for Executor's graph
+         GraphBase::Graph* aMacroGraphExe = aMacroGraphExecutor->Graph();
+            aMacroGraphExe->GraphMacroLevel( anExecutorGraph->GraphMacroLevel() + 1 );
+
+       // load data flows in MacroGraph's executor
+         Graph_Impl* aMacroGraphImpl = (Graph_Impl*) aMacroGraphEditor->Graph()->ObjImpl();
+         MESSAGE( "RECURSIVE IMPORT OF GRAPHS OF MACRONODES : " << aMacroGraphName ) ;
+         if ( CORBA::is_nil( aMacroGraphImpl->LoadDataFlows( aMacroGraphExecutor, aListOfDataFlows , index ) ) ) {
+           MESSAGE("Graph_Impl::LoadDataFlows(Executor) failed,  could not LoadDataFlow( MacroNodeGraph \"" <<aMacroGraphName << "\" )" ) ;
+           return SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
+         }
+         
+         // set coupled pair MacroNode <--> MacroGraph
+          aMacroGraphExe->CoupledNode( aMacroNode ) ;
+          aMacroNode->CoupledNode( aMacroGraphExe ) ;
+
+//JR 04.05.2005 Debug : InPorts values of MacroNodes are like for other nodes
+//                      InPorts values of MacroGraphs of MacroNodes are done in the Executor
+// It was probably to try to debug anything but it was a wrong debug and I do not know what bug
+// ===> folowing code is commented
+#if 0
+         // initialize MacroNode's InPorts with corresponding "external" values
+         int q ;
+         for ( q = 0 ; q < aMacroNode->GetNodeInPortsSize() ; q++ ) {
+           const GraphBase::InPort * anInPort = aMacroNode->GetNodeInPort( q ) ;
+           if ( anInPort->IsDataConnected() ) {
+             const char* aMacroGraphInPortName = aMacroGraph->GetNodeInPort( q )->PortName();
+//JR 30.03.2005              if ( !aMacroGraphExecutor->InputOfAny(  aMacroGraphInPortName, *anInPort->GetOutPort()->Value(),false ) ) {
+             if ( !aMacroGraphExecutor->InputOfAny(  aMacroGraphInPortName, anInPort->GetOutPort()->Value(),false ) ) {
+               return SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
+             }
+             else {
+               MESSAGE( "LoadDataFlows(Executor) " << aMacroGraph->Name() << "->InputOfAny( " 
+                         << aMacroGraphInPortName << " , Value )" ) ;
              }
-              aMacroGraphDataFlowExecutor->Graph()->SetGraphEditor( aDataFlow ) ;
-              aMacroGraphDataFlowExecutor->Graph()->SetGraphExecutor( aMacroGraphDataFlowExecutor ) ;
-              aMacroGraphDataFlowExecutor->Graph()->SetGraphPorts() ;
-              Graph_Impl * myMacroGraph ;
-// We create a Graph ObjRef for that graph
-              myMacroGraph = new Graph_Impl( _Orb , _Poa, _ContId,
-                                             instanceName() , interfaceName() ,
-                                             aMacroGraphDataFlowExecutor , NULL ) ;
-              PortableServer::ObjectId * id = myMacroGraph->getId() ;
-              CORBA::Object_var obj = _poa->id_to_reference(*id);
-              SUPERV::Graph_var iobject = SUPERV::Graph::_narrow( obj ) ;
-              myMacroGraph->SetObjRef( SUPERV::Graph::_duplicate( iobject ) ) ;
-              myMacroGraph->DataFlowEditor( aDataFlow ) ;
-              aDataFlow->Executor( aMacroGraphDataFlowExecutor ) ;
-              myMacroGraph->DebugFileName( (char * ) dbgfile.c_str() ) ;
-
-              GraphBase::Graph * aMacroGraph = myMacroGraph->DataFlowExecutor()->Graph() ;
-              aMacroGraph->GraphMacroLevel( aGraph->GraphMacroLevel() + 1 ) ;
-
-// Set the MacroNode ObjRef in the GraphMacroNode
-              aMacroGraph->CoupledNode( aMacroNode ) ;
-              aMacroGraph->MacroObject( SUPERV::Graph::_duplicate( macroiobject ) ) ;
-
-// Set the GraphMacroNode ObjRef in the MacroNode
-              aMacroNode->CoupledNode( aMacroGraph ) ;
-              aMacroNode->MacroObject( SUPERV::Graph::_duplicate( iobject ) ) ;
-
-              iobject->Run() ;
            }
-            break ;
-         }
-       }
-      }
+         } // end of init MacroNode's InPorts
+#endif
+         aMacroGraphImpl->Run() ;
+
+        }
+      } // end of for( get nodes of the graph...)
     }
-  }
+  } // end of setting initial graph's structure..
 
   endService( "Graph_Impl::ExecutorLoadDataFlows" );
-  return true ;
+
+  PortableServer::ObjectId * id = getId();
+  CORBA::Object_var obj = _poa->id_to_reference( *id );
+  SUPERV::Graph_var iobject = SUPERV::Graph::_narrow( obj ) ;
+  return SUPERV::Graph::_duplicate( iobject ) ;
 }
 
 SUPERV::Graph_ptr Graph_Impl::MNode( const char * aXmlFileName ) {
   beginService( "Graph_Impl::MNode" );
   SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
-  if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() && !IsMacro() ) {
+  MESSAGE( "Graph_Impl::MNode( " << aXmlFileName << " )" ) ;
+  if ( !IsMacro() ) {
     GraphBase::ListOfSGraphs aListOfDataFlows ;
     string dbgfile ;
 // At first create the editor and a StreamGraph with the xml file
     GraphEditor::DataFlow * aDataFlowEditor ;
     CreateEditor( _Orb , instanceName() , aXmlFileName , SUPERV::DataStreamGraph ,
                   dbgfile , &aDataFlowEditor ) ;
+
+    if ( _DebugFileName ) {
+      delete [] _DebugFileName ;
+    }
+    _DebugFileName = new char[ strlen( dbgfile.c_str() )+1 ] ;
+    strcpy( _DebugFileName , dbgfile.c_str() ) ;
+
     int lenname = strlen( aXmlFileName ) ;
     bool loaded = false ;
 // Import of the xml file
     if ( lenname > 4 && !strcmp( &aXmlFileName[ lenname - 4 ] , ".xml" ) ) {
       loaded = aDataFlowEditor->LoadXml( aXmlFileName , aListOfDataFlows ) ;
       if ( loaded ) {
-        iobject = MNode( aDataFlowEditor , aListOfDataFlows ) ;
+        iobject = MNode( aDataFlowEditor , &aListOfDataFlows ) ;
       }
     }
   }
@@ -818,13 +896,16 @@ SUPERV::Graph_ptr Graph_Impl::MNode( const char * aXmlFileName ) {
 // WARNING : THIS IS COMPLICATED :
 // I should have to remove duplicated code ...
 SUPERV::Graph_ptr Graph_Impl::MNode( GraphEditor::DataFlow * aMacroGraphDataFlowEditor ,
-                                     GraphBase::ListOfSGraphs aListOfDataFlows ) {
+                                     GraphBase::ListOfSGraphs aListOfDataFlows ) {
   beginService( "Graph_Impl::MNode" ) ;
   SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
   SUPERV::Graph_var macroiobject = SUPERV::Graph::_nil() ;
 
   if ( !IsMacro() ) {
-    if ( !aMacroGraphDataFlowEditor->LoadDataFlow( &aListOfDataFlows[ 0 ] ) ) {
+    MESSAGE( "Graph_Impl::MNode DataFlowEditor->LoadDataFlow" ) ;
+//    if ( !aMacroGraphDataFlowEditor->LoadDataFlow( &aListOfDataFlows[ 0 ] ) ) {
+    iobject = LoadDataFlows( aMacroGraphDataFlowEditor , aListOfDataFlows , 0 ) ;
+    if ( CORBA::is_nil( iobject ) ) {
       MESSAGE("Graph_Impl::MNode LoadDataFlow failed" ) ;
       return false ;
     }
@@ -832,27 +913,17 @@ SUPERV::Graph_ptr Graph_Impl::MNode( GraphEditor::DataFlow * aMacroGraphDataFlow
 // That graph is not a StreamGraph :
     else if ( !aMacroGraphDataFlowEditor->Graph()->HasDataStream() ) {
       aMacroGraphDataFlowEditor->Graph()->Kind( SUPERV::DataFlowGraph ) ;
-      aMacroGraphDataFlowEditor->Graph()->SetGraphEditor( aMacroGraphDataFlowEditor ) ;
-      Graph_Impl * myMacroGraph ;
-// We create a Graph ObjRef for that graph
-      myMacroGraph = new Graph_Impl( _Orb , _Poa, _ContId,
-                                     instanceName() , interfaceName() ,
-                                     aMacroGraphDataFlowEditor , NULL ) ;
-      PortableServer::ObjectId * id = myMacroGraph->getId() ;
-      CORBA::Object_var obj = _poa->id_to_reference(*id);
-      iobject = SUPERV::Graph::_narrow( obj ) ;
-      myMacroGraph->SetObjRef( SUPERV::Graph::_duplicate( iobject ) ) ;
-
-
+      aMacroGraphDataFlowEditor->Graph()->GraphEditor( aMacroGraphDataFlowEditor ) ;
 
+      Graph_Impl * myMacroGraph = (Graph_Impl * ) aMacroGraphDataFlowEditor->Graph()->ObjImpl() ;
 // Creation of a GraphMacroNode in the current editor
       string aMacroNodeName = string( "Macro_" ) + string( myMacroGraph->Name() ) ;
       Graph_Impl * myMacroNode ;
       myMacroNode = new Graph_Impl( _Orb , _Poa, _ContId,
                                     instanceName() , interfaceName() ,
                                     aMacroNodeName.c_str() , SUPERV::MacroNode ) ;
-      id = myMacroNode->getId() ;
-      obj = _poa->id_to_reference(*id);
+      PortableServer::ObjectId * id = myMacroNode->getId() ;
+      CORBA::Object_var obj = _poa->id_to_reference(*id);
       macroiobject = SUPERV::Graph::_narrow( obj ) ;
       myMacroNode->DataFlowEditor( DataFlowEditor() ) ;
 
@@ -876,13 +947,11 @@ SUPERV::Graph_ptr Graph_Impl::MNode( GraphEditor::DataFlow * aMacroGraphDataFlow
       aDataFlowNode->SetObjRef( SUPERV::CNode::_duplicate( SUPERV::CNode::_narrow( obj ) ) ) ;
       aDataFlowNode->SetObjImpl( this ) ;
 
-
-
       GraphBase::Graph * aGraph = myMacroGraph->DataFlowEditor()->Graph() ;
       GraphBase::Graph * aGraphOfMacroGraph = myMacroNode->DataFlowEditor()->Graph() ;
       GraphBase::Graph * aMacroGraph = myMacroNode->DataFlowNode()->GraphMacroNode() ;
       aMacroGraph->Kind( SUPERV::MacroNode ) ;
-      aMacroGraph->SetGraphEditor( DataFlowEditor() ) ;
+      aMacroGraph->GraphEditor( DataFlowEditor() ) ;
 // Creation of the Ports of the MacroNode from the ports of the GraphMacroNode
       aMacroGraph->SetMacroPorts( aGraph ) ;
 // Valid ==> creation of Service and the ports of the current Graph
@@ -894,8 +963,11 @@ SUPERV::Graph_ptr Graph_Impl::MNode( GraphEditor::DataFlow * aMacroGraphDataFlow
       aGraph->CoupledNode( aMacroGraph ) ;
       aGraph->MacroObject( SUPERV::Graph::_duplicate( macroiobject ) ) ;
 // Set the GraphMacroNode ObjRef in the MacroNode
+      aDataFlowNode->GraphMacroNode()->GraphMacroLevel( aGraphOfMacroGraph->GraphMacroLevel() + 1 ) ;
       aMacroGraph->CoupledNode( aGraph ) ;
+//      aGraphOfMacroGraph->CoupledNode( aGraph ) ;
       aMacroGraph->MacroObject( SUPERV::Graph::_duplicate( iobject ) ) ;
+//      aGraphOfMacroGraph->MacroObject( SUPERV::Graph::_duplicate( iobject ) ) ;
 //    aDataFlowNode->CoupledNode( aGraph ) ;
 //    aDataFlowNode->ComputingNode()->MacroObject( SUPERV::Graph::_duplicate( iobject ) ) ;
 // Set the MacroLevel of that graph
@@ -903,6 +975,15 @@ SUPERV::Graph_ptr Graph_Impl::MNode( GraphEditor::DataFlow * aMacroGraphDataFlow
       aMacroGraph->Coordinates( 0 , 0 ) ;
       MESSAGE( "DataFlowNode Graph " << this << " DataFlowEditor " << DataFlowEditor() << " aDataFlowNode "
                << aDataFlowNode << " " << aDataFlowNode->Name() << " created" ) ;
+      MESSAGE( "MNode aGraph " << aGraph << " " << aGraph->Name()
+               << " coupled to " << aGraph->CoupledNode() << " "
+               << aGraph->CoupledNode()->Name() ) ;
+      MESSAGE( "MNode aMacroGraph " << aMacroGraph << " " << aMacroGraph->Name()
+               << " coupled to " << aMacroGraph->CoupledNode() << " "
+               << aMacroGraph->CoupledNode()->Name() ) ;
+      MESSAGE( "MNode aMacroGraph " << myMacroNode->DataFlowEditor()->Graph() << " "
+               << myMacroNode->DataFlowEditor()->Graph()->Name()
+               << " coupled to " << myMacroNode->DataFlowEditor()->Graph()->CoupledNode() ) ;
     }
     else {
       delete aMacroGraphDataFlowEditor ;
@@ -912,6 +993,7 @@ SUPERV::Graph_ptr Graph_Impl::MNode( GraphEditor::DataFlow * aMacroGraphDataFlow
   return SUPERV::Graph::_duplicate( macroiobject ) ;
 }
 
+// For python supergraph
 SUPERV::Graph_ptr Graph_Impl::GraphMNode( SUPERV::Graph_ptr myMacroGraph ) {
   SUPERV::Graph_var iobject = myMacroGraph ;
   beginService( "Graph_Impl::GraphMNode" ) ;
@@ -921,6 +1003,7 @@ SUPERV::Graph_ptr Graph_Impl::GraphMNode( SUPERV::Graph_ptr myMacroGraph ) {
 // Creation of a GraphMacroNode in the current editor
   if ( !IsMacro() ) {
     string aMacroNodeName = string( "Macro_" ) + string( myMacroGraph->Name() ) ;
+    //string aMacroNodeName = string( myMacroGraph->CoupledName() ) ;
     MESSAGE( "GraphMNode( " << myMacroGraph->Name() << " )" ) ;
     Graph_Impl * myMacroNode ;
     myMacroNode = new Graph_Impl( _Orb , _Poa, _ContId,
@@ -942,23 +1025,24 @@ SUPERV::Graph_ptr Graph_Impl::GraphMNode( SUPERV::Graph_ptr myMacroGraph ) {
     aPythonFunction.resize( 1 ) ;
     aPythonFunction[0] = &aListOfStrings ;
     SALOME_ModuleCatalog::Service * aMacroNodeService = myMacroGraph->Service() ;
-    GraphEditor::InNode * aDataFlowNode = DataFlowEditor()->AddNode( *aMacroNodeService , "" , "" ,
-                                                                     aMacroNodeName.c_str() , SUPERV::MacroNode ,
-                                                                     aFuncName , aPythonFunction ) ;
+    GraphEditor::InNode * aDataFlowNode ;
+    aDataFlowNode = DataFlowEditor()->AddNode( *aMacroNodeService , "" , "" ,
+                                               aMacroNodeName.c_str() , SUPERV::MacroNode ,
+                                               aFuncName , aPythonFunction ) ;
     aDataFlowNode->SetPythonFunction( "" , aListOfStrings ) ;
     myMacroNode->DataFlowNode( aDataFlowNode ) ;
     aDataFlowNode->ComputingNode()->SetService( *aMacroNodeService ) ;
     aDataFlowNode->SetObjRef( SUPERV::CNode::_duplicate( SUPERV::CNode::_narrow( obj ) ) ) ;
     aDataFlowNode->SetObjImpl( this ) ;
 
-
-
-//    GraphBase::Graph * aGraph = myMacroGraph->DataFlowEditor()->Graph() ;
-    GraphBase::Graph * aGraph = DataFlowEditor()->Automaton()->MapGraph( myMacroGraph->Name() ) ;
+//    GraphBase::Graph * aGraph = DataFlowEditor()->Automaton()->MapGraph( myMacroGraph->Name() ) ;
+    GraphBase::Graph * aGraph ;
+    //DataFlowEditor()->Automaton()->GraphBase( &aGraph ) ;
+    myMacroGraph->Coupled() ;
     GraphBase::Graph * aGraphOfMacroGraph = myMacroNode->DataFlowEditor()->Graph() ;
     GraphBase::Graph * aMacroGraph = myMacroNode->DataFlowNode()->GraphMacroNode() ;
     aMacroGraph->Kind( SUPERV::MacroNode ) ;
-    aMacroGraph->SetGraphEditor( DataFlowEditor() ) ;
+    aMacroGraph->GraphEditor( DataFlowEditor() ) ;
 // Creation of the Ports of the MacroNode from the ports of the GraphMacroNode
     aMacroGraph->SetMacroPorts( aGraph ) ;
 // Valid ==> creation of Service and the ports of the current Graph
@@ -971,6 +1055,7 @@ SUPERV::Graph_ptr Graph_Impl::GraphMNode( SUPERV::Graph_ptr myMacroGraph ) {
     aGraph->CoupledNode( aMacroGraph ) ;
     aGraph->MacroObject( SUPERV::Graph::_duplicate( macroiobject ) ) ;
 // Set the GraphMacroNode ObjRef in the MacroNode
+    aDataFlowNode->GraphMacroNode()->GraphMacroLevel( aGraphOfMacroGraph->GraphMacroLevel() + 1 ) ;
     aMacroGraph->CoupledNode( aGraph ) ;
     aMacroGraph->MacroObject( SUPERV::Graph::_duplicate( iobject ) ) ;
 //    aDataFlowNode->CoupledNode( aGraph ) ;
@@ -979,7 +1064,8 @@ SUPERV::Graph_ptr Graph_Impl::GraphMNode( SUPERV::Graph_ptr myMacroGraph ) {
     aGraph->GraphMacroLevel( aGraphOfMacroGraph->GraphMacroLevel() + 1 ) ;
     aMacroGraph->Coordinates( 0 , 0 ) ;
     MESSAGE( aGraph->Name() << "->CoupledNode()->GraphEditor() : " << aGraph->CoupledNode()->GraphEditor() ) ;
-    MESSAGE( aMacroGraph->Name() << "->CoupledNode()->GraphEditor() : " << aMacroGraph->CoupledNode()->GraphEditor() ) ;
+    MESSAGE( aMacroGraph->Name() << "->CoupledNode()->GraphEditor() : "
+             << aMacroGraph->CoupledNode()->GraphEditor() ) ;
     MESSAGE( "DataFlowNode Graph " << this << " DataFlowEditor " << DataFlowEditor() << " aDataFlowNode "
              << aDataFlowNode << " " << aDataFlowNode->Name() << " created" ) ;
   }
@@ -1051,40 +1137,57 @@ SUPERV::CNode_ptr Graph_Impl::Node(char const * aNodeName ) {
 
 SUPERV::Link_ptr Graph_Impl::Link( SUPERV::Port_ptr OutPort ,
                                    SUPERV::Port_ptr InPort ) {
-  beginService( "Graph_Impl::Link" );
+//  beginService( "Graph_Impl::Link" );
   SUPERV::Link_var iobject = SUPERV::Link::_nil() ;
   if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() &&
        !OutPort->IsDataStream() && !InPort->IsDataStream() && !IsMacro() ) {
-    GraphBase::InPort * anInPort = DataFlowEditor()->GetNode( InPort->Node()->Name() )->ComputingNode()->GetChangeInPort( InPort->Name() ) ;
-    GraphBase::OutPort * anOutPort = DataFlowEditor()->GetNode( OutPort->Node()->Name() )->ComputingNode()->GetChangeOutPort( OutPort->Name() ) ;
-    if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
-      const char * DataFlowOutNodeName = OutPort->Node()->Name() ;
-      GraphEditor::InNode * DataFlowOutNode = DataFlowEditor()->GetNode( DataFlowOutNodeName ) ;
-      const char * DataFlowInNodeName = InPort->Node()->Name() ;
-      GraphEditor::InNode * DataFlowInNode = DataFlowEditor()->GetNode( DataFlowInNodeName ) ;
-      if ( DataFlowOutNode && DataFlowInNode ) {
-        bool Success ;
-        Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
-                                            instanceName() , interfaceName() ,
-                                            DataFlowEditor() ,
-                                            DataFlowInNode ,
-                                            InPort->Name() ,
-                                            DataFlowOutNode ,
-                                            OutPort->Name() ,
-                                            true , false , Success ) ;
-        if ( Success ) {
-          PortableServer::ObjectId * id = myLink->getId() ;
-          CORBA::Object_var obj = _poa->id_to_reference(*id);
-          iobject = SUPERV::Link::_narrow(obj) ;
-          anOutPort->AddInPortObjRef( anInPort , SUPERV::Link::_duplicate( iobject ) ) ;
-       }
-      }
+    MESSAGE( "Graph_Impl::Link( " << OutPort->Node()->Name() << "( " << OutPort->Name() << " ) --> "
+             << InPort->Node()->Name() << "( " << InPort->Name() << " )" ) ;
+    GraphEditor::InNode * anInNode = DataFlowEditor()->GetNode( InPort->Node()->Name() ) ;
+    GraphEditor::InNode * anOutNode = DataFlowEditor()->GetNode( OutPort->Node()->Name() ) ;
+    if ( anInNode == NULL || anOutNode== NULL ) {
+      MESSAGE( "Graph_Impl::Link( " << OutPort->Node()->Name() << " " << anOutNode << " , "
+               << InPort->Node()->Name() << " " << anInNode << " ) Node(s) not found in " << Name() ) ;
     }
     else {
-      iobject = anOutPort->InPortObjRef( anInPort ) ;
+      GraphBase::InPort * anInPort = anInNode->ComputingNode()->GetChangeInPort( InPort->Name() ) ;
+      GraphBase::OutPort * anOutPort = anOutNode->ComputingNode()->GetChangeOutPort( OutPort->Name() ) ;
+      if ( anInPort == NULL || anOutPort== NULL ) {
+        MESSAGE( "Graph_Impl::Link( " << OutPort->Name() << " " << anOutPort << " , "
+                 << InPort->Name() << " " << anInPort << " ) Port(s) not found" ) ;
+      }
+      else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
+        const char * DataFlowOutNodeName = OutPort->Node()->Name() ;
+        GraphEditor::InNode * DataFlowOutNode = DataFlowEditor()->GetNode( DataFlowOutNodeName ) ;
+        const char * DataFlowInNodeName = InPort->Node()->Name() ;
+        GraphEditor::InNode * DataFlowInNode = DataFlowEditor()->GetNode( DataFlowInNodeName ) ;
+        if ( DataFlowOutNode && DataFlowInNode ) {
+          bool Success ;
+          Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
+                                              instanceName() , interfaceName() ,
+                                              DataFlowEditor() ,
+                                              DataFlowInNode ,
+                                              InPort->Name() ,
+                                              DataFlowOutNode ,
+                                              OutPort->Name() ,
+                                              true , false , Success ) ;
+          if ( Success ) {
+            PortableServer::ObjectId * id = myLink->getId() ;
+            CORBA::Object_var obj = _poa->id_to_reference(*id);
+            iobject = SUPERV::Link::_narrow(obj) ;
+            anOutPort->AddInPortObjRef( anInPort , SUPERV::Link::_duplicate( iobject ) ) ;
+         }
+        }
+      }
+      else {
+        MESSAGE( "Graph_Impl::Link( " << OutPort->Name() << " " << anOutPort << " , "
+                 << InPort->Name() << " " << anInPort << " ) ObjRef already exists" ) ;
+        iobject = anOutPort->InPortObjRef( anInPort ) ;
+      }
     }
   }
-  endService( "Graph_Impl::Link" );
+  DataFlowEditor()->UnValid() ;
+//  endService( "Graph_Impl::Link" );
   return SUPERV::Link::_duplicate( iobject ) ;
 }
 
@@ -1294,8 +1397,14 @@ SUPERV::ListOfNodes * Graph_Impl::Nodes() {
   RetVal->Graphs.length(0) ;
   if ( !IsMacro() ) {
     int i ;
+    MESSAGE( DataFlowEditor()->Graph()->GetGraphNodeSize() << " Nodes in the Map and "
+             << DataFlowEditor()->Graph()->GraphNodesSize() << " Nodes int the Vector" ) ;
     for ( i = 0 ; i < DataFlowEditor()->Graph()->GraphNodesSize() ; i++ ) {
       GraphBase::ComputingNode * aNode = DataFlowEditor()->Graph()->GraphNodes( i ) ;
+#if 1
+      MESSAGE( i << ". Vector : " << aNode->Name() << " Map : "
+               << DataFlowEditor()->Graph()->GetGraphNode( aNode->Name() )->Name() ) ;
+#endif
       RetVal = SetNode( RetVal , aNode ) ;
     }
 #if 0
@@ -1391,8 +1500,10 @@ SUPERV::ListOfLinks * Graph_Impl::Links( GraphBase::ComputingNode * theNode ,
 //                        << anOutPort->PortName() << ") --> " << aNode->Name() << "("
 //                        << anInPort->PortName() << ")" ) ;
                 if ( theNode == NULL ||
-                     ( theNode != NULL && !theNode->IsEndSwitchNode() &&
-                       !strcmp( theNode->Name() , aNode->Name() ) ) ) {
+//PAL8521
+//JR 14.02.2005 : Debug : we must see also that links !
+//                     ( theNode != NULL && !theNode->IsEndSwitchNode() &&
+                       !strcmp( theNode->Name() , aNode->Name() ) ) {
                   if ( anInPort->IsLoop() || anOutPort->IsLoop() ||
                        ( aNode->IsEndLoopNode() && !strcmp( aNode->CoupledNode()->Name() ,
                                                             anOutPort->NodeName() ) ) ) {
@@ -1455,12 +1566,15 @@ SUPERV::ListOfLinks * Graph_Impl::Links( GraphBase::ComputingNode * theNode ,
           GraphBase::InPort * anInPort = anOutPort->ChangeInPorts( k ) ;
 //          MESSAGE( "              -->  In" << k << " " << anInPort->NodeName() << " " << anInPort->PortName()
 //                   << " " << anInPort->PortStatus() ) ;
-          if ( !anInPort->IsExternConnected() ) {
-            GraphEditor::InNode * toNode = (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GetChangeGraphNode( anInPort->NodeName() )->GetInNode() ;
+          if ( anInPort->IsPortConnected() ) {
+           GraphBase::ComputingNode * aComputingNode = DataFlowEditor()->Graph()->GetChangeGraphNode( anInPort->NodeName() ) ;
+            GraphEditor::InNode * toNode = (GraphEditor::InNode * ) aComputingNode->GetInNode() ;
             if ( theNode == NULL ||
                  !strcmp( theNode->Name() , aNode->Name() ) ) {
               if ( !anInPort->IsDataStream() ) {
-                if ( theNode || ( toNode->IsEndSwitchNode() && !aNode->IsSwitchNode() ) ) {
+//PAL8521
+//JR 14.02.2005 : Debug : we must see also that links !
+//                if ( theNode || ( toNode->IsEndSwitchNode() && !aNode->IsSwitchNode() ) ) {
                   if ( anInputParam == NULL ||
                        !strcmp( anInPort->PortName() , anInputParam ) ) {
                     if ( anInPort->IsLoop() || anOutPort->IsLoop() ||
@@ -1507,7 +1621,7 @@ SUPERV::ListOfLinks * Graph_Impl::Links( GraphBase::ComputingNode * theNode ,
 //                             << anOutPort->PortName() << ") --> " << toNode->Name() << "("
 //                             << anInPort->PortName() << ")" << " skipped" ) ;
                  }
-               }
+//             }
              }
            }
          }
@@ -1550,6 +1664,20 @@ Engines::Component_ptr Graph_Impl::ComponentRef( const char * aComputerContainer
   return Engines::Component::_duplicate( objComponent ) ;
 }
 
+char * Graph_Impl::Messages() {
+  beginService( "Graph_Impl::Messages" );
+  string Messages  ;
+  MESSAGE( "Graph_Impl::Messages IsEditing " << DataFlowEditor()->IsEditing() ) ;
+  Messages = DataFlowEditor()->Graph()->Messages() ;
+  DataFlowEditor()->Graph()->ReSetMessages() ;
+  if ( DataFlowExecutor() ) {
+    Messages += DataFlowExecutor()->Graph()->Messages() ;
+    DataFlowExecutor()->Graph()->ReSetMessages() ;
+  }
+  endService( "Graph_Impl::Messages" );
+  return ( CORBA::string_dup( Messages.c_str() ) ) ;
+}
+
 bool Graph_Impl::IsValid() {
 //  beginService( "Graph_Impl::IsValid" );
   bool RetVal = false ;
@@ -1562,7 +1690,10 @@ bool Graph_Impl::IsValid() {
 bool Graph_Impl::IsExecutable() {
 //  beginService( "Graph_Impl::IsExecutable" );
   bool RetVal = false ;
-  if ( !IsMacro() ) {
+
+  // asv : 15.11.04 : added "&& GraphMacroLevel() == 0" -> 
+  // subgraphs are not executable by themselves, RetVal = false..
+  if ( !IsMacro() && DataFlowEditor()->Graph()->GraphMacroLevel() == 0 ) {
     RetVal = DataFlowEditor()->IsExecutable() ;
   }
 //  endService( "Graph_Impl::IsExecutable" );
@@ -1570,22 +1701,27 @@ bool Graph_Impl::IsExecutable() {
 }
 
 bool Graph_Impl::IsEditing() {
-//  beginService( "Graph_Impl::IsEditing" );
+/*
   bool RetVal = false ;
   if ( !IsMacro() ) {
     RetVal = DataFlowEditor()->IsEditing() ;
   }
-//  endService( "Graph_Impl::IsEditing" );
   return RetVal ;
+*/
+  if ( IsMacro() )
+    return false;
+  return !IsExecuting();
 }
+
 bool Graph_Impl::IsExecuting() {
-//  beginService( "Graph_Impl::IsExecuting" );
+/*
   bool RetVal = false ;
   if ( !IsMacro() ) {
     RetVal = !DataFlowEditor()->IsEditing() ;
   }
-//  endService( "Graph_Impl::IsExecuting" );
   return RetVal ;
+*/
+  return CNode_Impl::IsExecuting();
 }
 
 bool Graph_Impl::IsReadOnly() {
@@ -1668,46 +1804,27 @@ bool Graph_Impl::Begin() {
       perror("pthread_mutex_lock _MutexExecutorWait") ;
       exit( 0 ) ;
     }
+    DataFlowEditor()->Graph()->ReSetMessages() ; // ==> Only one set of errors messages ...
     if ( DataFlowExecutor() ) {
       MESSAGE( "Graph_Impl::Begin " << DataFlowExecutor()->Threads() << " threads" )
-      if ( DataFlowExecutor()->Threads() ) {
-        DataFlowExecutor()->JoinedWait() ;
-      }
-      delete DataFlowExecutor() ;
-      DataFlowExecutor( NULL ) ;
-      DataFlowEditor()->Executor( NULL ) ;
+      Editing(); // just in case it was not called before by GUI..
     }
     if ( DataFlowEditor()->IsExecutable() ) {
       DataFlowEditor()->EditedAfterExecution( false ) ;
-      int _ExecNumber = theAutomaton->ExecNumber() ;
-      char ExecNumber[30] ;
-      sprintf( ExecNumber , "_%d" , _ExecNumber ) ;
-      int len = strlen( _DebugFileName ) ;
-      char * DebugFileName = new char [ len + strlen( ExecNumber ) + 6 ] ;
-      strncpy( DebugFileName , _DebugFileName , len - 4 ) ;
-      DebugFileName[ len - 4 ] = '\0' ;
-      strcat( DebugFileName , ExecNumber ) ;
-      strcat( DebugFileName , "_Exec.log" ) ;
-      GraphExecutor::DataFlow * aDataFlowExecutor ;
       GraphBase::ListOfSGraphs * myListOfGraphs = DataFlowEditor()->GetDataFlows() ;
-      int i ;
-      for ( i = 0 ; i < (int ) myListOfGraphs->size() ; i++ ) {
-        GraphEditor::DataFlow * aDataFlowEditor ;
-        aDataFlowEditor = theAutomaton->MapGraph( (*myListOfGraphs)[ i ].Info.theName.c_str() )->GraphEditor() ;
-        MESSAGE("myListOfGraphs" << i << " " << (*myListOfGraphs)[ i ].Info.theName.c_str() << " "
-                << aDataFlowEditor << " IsEditing " << aDataFlowEditor->IsEditing() ) ;
-              
-      }
-      aDataFlowExecutor = new GraphExecutor::DataFlow( _Orb , _NamingService ,
-                                                       (*myListOfGraphs)[ 0 ].Info.theName.c_str() ,
-                                                       DebugFileName , Kind() ) ;
-      DataFlowExecutor( aDataFlowExecutor ) ;
+
+      GraphExecutor::DataFlow * aDataFlowExecutor ;
+      string dbgfile ;
+      CreateExecutor( _Orb , instanceName() , (*myListOfGraphs)[ 0 ].Info.theName.c_str() , Kind() ,
+                      dbgfile , &aDataFlowExecutor ) ;
+
       MESSAGE( "Graph_Impl::Begin : DataFlowExecutor created" );
-      RetVal = LoadDataFlows( DataFlowExecutor() , myListOfGraphs , 0 ) ;
-      if ( RetVal ) {
+      if ( !CORBA::is_nil( LoadDataFlows( aDataFlowExecutor, myListOfGraphs , 0 ) ) ) 
+        RetVal = true ;
+  
+      if ( RetVal )
         DataFlowExecutor()->Graph()->SetObjImpl( DataFlowEditor()->Graph()->ObjImpl() ) ;
-        DataFlowEditor()->Executor( DataFlowExecutor() ) ;
-      }
+    
     }
     if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
       perror("pthread_mutex_unlock _MutexExecutorWait") ;
@@ -1716,55 +1833,60 @@ bool Graph_Impl::Begin() {
   }
   return RetVal ;
 }
-bool Graph_Impl::Run() {
-  beginService( "Graph_Impl::Run" );
+
+/**
+ * run() : was created in order to reduce code dublication, Run() and Start() do the same thing
+ *         except for final call to Executor->Run( bool ) - Run() calls with AndSuspend=false
+ *         and Start() calls with AndSuspend=true flag.  The rest of the actions are the same:
+ *         1. if a MacroNode's coupled graph (MacroLevel>0) -> simply Run() it.
+ *         2. if a Supergraph -> create executor, load dataflow in it (done in Begin()), then - Run() it.
+ */
+bool Graph_Impl::run( const bool andSuspend ) {
   bool RetVal = false ;
-  if ( DataFlowEditor()->IsEditing() && !IsMacro() ) {
-    MESSAGE( "Graph_Impl::Run " << DataFlowEditor()->Graph()->Name() << " " << DataFlowEditor() << " IsEditing" );
+
+  // if Editing or Finished state, and, naturally, 'this' is not a MacroNode. 
+  if ( ( DataFlowEditor()->IsEditing() || IsDone() ) && !IsMacro() ) {
+
     if ( DataFlowEditor()->Graph()->GraphMacroLevel() ) {
-      MESSAGE( "Graph_Impl::Run " << DataFlowEditor()->Graph()->Name() << " GraphMacroLevel "
-               << DataFlowEditor()->Graph()->GraphMacroLevel() ) ;
-      RetVal = true ;
+      // MacroGraph's Executor was created in recursive function LoadDataflows(Executor), called from
+      // Begin() of Supergraph.  See Begin() and LoadDataflows(Executor) for details.
+      RetVal = true ; 
     }
     else {
-      MESSAGE( "Graph_Impl::Run " << DataFlowEditor()->Graph()->Name() << " GraphMacroLevel "
-               << DataFlowEditor()->Graph()->GraphMacroLevel() << " --> Begin()" ) ;
+      // Create Executor instance and its datamodel
       RetVal = Begin() ;
     }
     if ( RetVal ) {
-      MESSAGE( "Graph_Impl::Run " );
+      // Set Executing flag to avoid edition operations during execution, EditedAfterExecution=false
       DataFlowEditor()->Executing() ;
-      RetVal = CNode_Impl::Run() ;
+      DataFlowEditor()->EditedAfterExecution( false ); 
+
+      // THE MAIN RUN METHOD
+      RetVal = DataFlowExecutor()->Run( andSuspend );
     }
   }
-  else if ( !IsMacro() ) {
-    MESSAGE( "Graph_Impl::Run " << DataFlowEditor()->Graph()->Name() << " " << DataFlowEditor()
-             << " IsNOTEditing --> CNode_Impl::ReRun" );
-    DataFlowEditor()->Executing() ;
-    RetVal = CNode_Impl::ReRun() ;
-  }
+  return RetVal ;
+
+}
+
+/**
+ * Run() - called on "Execute" command
+ */
+bool Graph_Impl::Run() {
+  beginService( "Graph_Impl::Run" );
+  bool RetVal = run( /*andSuspend=*/false ) ;
+  MESSAGE( "Graph_Impl::Run " << DataFlowEditor()->Graph()->Name() << " RetVal " << RetVal ) ;
   endService( "Graph_Impl::Run" );
   return RetVal ;
 }
+
+/**
+ * Run() - called on "Execute step-by-step" command
+ */
 bool Graph_Impl::Start() {
   beginService( "Graph_Impl::Start" );
-  bool RetVal = false ;
-  if ( !IsMacro() ) {
-    if ( DataFlowEditor()->IsEditing() ) {
-      MESSAGE( "Graph_Impl::Start IsEditing" );
-      RetVal = Begin() ;
-    }
-    else {
-      RetVal = true ;
-    }
-    if ( RetVal ) {
-      MESSAGE( "Graph_Impl::(Re)Start " );
-      // Added by NKV to fix PAL6222 --> to be confirm by JR 
-      DataFlowEditor()->Executing() ;
-      // End of NKV's correction
-      RetVal = ReStart() ;
-    }
-  }
+  bool RetVal = run( /*andSuspend=*/true ) ;
+  MESSAGE( "Graph_Impl::Start " << DataFlowEditor()->Graph()->Name() << " RetVal " << RetVal ) ;
   endService( "Graph_Impl::Start" );
   return RetVal ;
 }
@@ -1847,6 +1969,7 @@ bool Graph_Impl::Event( SUPERV::CNode_out aNode ,
   }
   anEvent = theEvent ;
   aState = theState ;
+
   return RetVal ;
 }
 
@@ -2402,5 +2525,13 @@ SUPERV::StreamGraph_ptr Graph_Impl::ToStreamGraph() {
   return SUPERV::StreamGraph::_duplicate( iobject ) ;
 }
 
-
+/**
+ * Destroy Executor and use only Editor and its data model
+ */
+void Graph_Impl::Editing() {
+  if ( DataFlowEditor() && DataFlowExecutor() ) {
+    delete DataFlowExecutor() ;
+    DataFlowEditor()->Executor( NULL );
+  }
+}