]> SALOME platform Git repositories - modules/superv.git/blobdiff - src/GraphEditor/DataFlowEditor_OutNode.cxx
Salome HOME
Bug fix: don't set "Loading" state for MacroNodes in InitialState() function (called...
[modules/superv.git] / src / GraphEditor / DataFlowEditor_OutNode.cxx
index 202b1573733137152e20732ac80568b495981f5b..80add3a944878ff7dba6008690426da019bb86d3 100644 (file)
 using namespace std;
 #include <sstream>
 #include <iostream>
+#include "DataFlowEditor_DataFlow.hxx"
 #include "DataFlowEditor_OutNode.hxx"
 #include "DataFlowBase_EndOfLoopNode.hxx"
 #include "DataFlowBase_EndOfSwitchNode.hxx"
 
+//map< string , GraphBase::Graph * > GraphEditor::OutNode::_MapOfGraphs;
+map< string , int > _MapOfGraphNames;
+
+string GraphInstanceName( const char * aGraphName ) {
+  int GraphInstanceNumber = _MapOfGraphNames[ aGraphName ] ;
+  if ( GraphInstanceNumber ) {
+    _MapOfGraphNames[ aGraphName ] = GraphInstanceNumber + 1 ;
+  }
+  else {
+    GraphInstanceNumber = 0 ;
+    _MapOfGraphNames[ aGraphName ] = GraphInstanceNumber + 1 ;
+  }
+  string theGraphInstanceName = string( aGraphName ) ;
+  if ( GraphInstanceNumber ) {
+    theGraphInstanceName += "_" ;
+    ostringstream astr ;
+    astr << GraphInstanceNumber ;
+    theGraphInstanceName += astr.str() ;
+  }
+  return theGraphInstanceName ;
+}
+
+
 // Implementation de la classe GraphEditor::Graph
 
 GraphEditor::OutNode::OutNode() {
 //             Graph() {
   cdebug_in << "GraphEditor::OutNode::OutNode()" << endl;
 
+  _Graph = NULL ;
   _Imported = false ;
   _Valid = false ;
   _Executable = false ;
@@ -50,6 +75,7 @@ GraphEditor::OutNode::OutNode( CORBA::ORB_ptr ORB ,
                                const char * DebugFileName ,
                                const SUPERV::KindOfNode aKindOfNode ) {
 //             Graph( ORB , ptrNamingService , DataFlowName , DebugFileName ) {
+  _Graph = NULL ;
   Set_prof_debug( ORB , DebugFileName ) ;
   cdebug_in << "GraphEditor::OutNode::OutNode(" ;
   if ( DataFlowName ) {
@@ -59,15 +85,15 @@ GraphEditor::OutNode::OutNode( CORBA::ORB_ptr ORB ,
 
   if ( aKindOfNode == SUPERV::DataFlowGraph ) {
     _StreamGraph = NULL ;
-//    _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowName , DebugFileName ) ;
-    _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowName ,
-                                   _prof_debug , _fdebug ) ;
+    _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowName , aKindOfNode ,
+                                   _prof_debug , _fdebug ) ; 
+//    MapGraph( _Graph , _Graph->Name() ) ;
   }
   else if ( aKindOfNode == SUPERV::DataStreamGraph ) {
-//    _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowName , DebugFileName ) ;;
-    _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowName ,
+    _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowName , aKindOfNode ,
                                                _prof_debug , _fdebug ) ;
     _Graph = _StreamGraph ;
+//    MapGraph( _Graph , _Graph->Name() ) ;
   }
   _Orb = CORBA::ORB::_duplicate( ORB ) ;
   _Imported = false ;
@@ -92,11 +118,7 @@ GraphEditor::OutNode::OutNode(
                      const char * DataFlowComputer ,
                      const char * DataFlowComment ,
                      const char * DebugFileName ) {
-//             Graph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
-//                    DataFlowInterfaceName , DataFlowName , DataFlowkind ,
-//                    DataFlowFirstCreation , DataFlowLastModification  ,
-//                    DataFlowEditorRelease , DataFlowAuthor ,
-//                    DataFlowComputer , DataFlowComment , DebugFileName ) {
+  _Graph = NULL ;
   Set_prof_debug( ORB , DebugFileName ) ;
 
   if ( DataFlowkind == SUPERV::DataFlowGraph ) {
@@ -107,7 +129,7 @@ GraphEditor::OutNode::OutNode(
                                    DataFlowEditorRelease , DataFlowAuthor ,
                                    DataFlowComputer , DataFlowComment ,
                                    _prof_debug , _fdebug ) ;
-//                                   DataFlowComputer , DataFlowComment , DebugFileName ) ;
+//    MapGraph( _Graph , _Graph->Name() ) ;
   }
   else if ( DataFlowkind == SUPERV::DataStreamGraph ) {
     _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
@@ -116,8 +138,8 @@ GraphEditor::OutNode::OutNode(
                                                DataFlowEditorRelease , DataFlowAuthor ,
                                                DataFlowComputer , DataFlowComment ,
                                                _prof_debug , _fdebug ) ;
-//                    DataFlowComputer , DataFlowComment , DebugFileName ) ;
     _Graph = _StreamGraph ;
+//    MapGraph( _Graph , _Graph->Name() ) ;
   }
   _Orb = CORBA::ORB::_duplicate( ORB ) ;
   _Imported = false ;
@@ -127,11 +149,25 @@ GraphEditor::OutNode::OutNode(
 } ;
 
 GraphEditor::OutNode::~OutNode() {
+//  EraseGraph( Graph->Name() ) ;
 //  delete _DataFlowNode ;
 //  delete _DataFlowDatas ;
 //  delete _GT ;
 }
 
+bool GraphEditor::OutNode::Name( const char * aName ) {
+  bool RetVal = false ;
+//  if ( !GraphName( aName ) ) {
+//    char * aGraphName = Graph()->Name() ;
+    RetVal = Graph()->Name( aName ) ;
+//    if ( RetVal ) {
+//      EraseGraph( aGraphName ) ;
+//      MapGraph( Graph() , aName ) ;
+//    }
+//  }
+  return RetVal ;
+}
+
 void GraphEditor::OutNode::Set_prof_debug( CORBA::ORB_ptr ORB ,
                                            const char * DebugFileName ) {
   _Graph_prof_debug = 0 ;
@@ -143,15 +179,15 @@ void GraphEditor::OutNode::Set_prof_debug( CORBA::ORB_ptr ORB ,
   }
 }
 
-bool GraphEditor::OutNode::LoadDataFlow( const GraphBase::SGraph *aDataFlow ) {
+bool GraphEditor::OutNode::LoadDataFlow( const GraphBase::SGraph * aDataFlow ) {
   bool RetVal = false ;
-  cdebug_in << "GraphEditor::OutNode::LoadDataFlow() " << aDataFlow->Info.theName.c_str()
+  cdebug_in << "GraphEditor::OutNode::LoadDataFlow() " << (*aDataFlow).Info.theName.c_str()
             << " GraphNodesSize " << Graph()->GraphNodesSize() << endl;
   if ( !_Imported ) {
-    RetVal = LoadInfo( aDataFlow->Info ) ;
+    RetVal = LoadInfo( (*aDataFlow).Info ) ;
     _Imported = true ;
   }
-  else if ( Graph()->IsDataStreamNode() || aDataFlow->Info.theKind == SUPERV::DataFlowGraph ) {
+  else if ( Graph()->IsDataStreamNode() || (*aDataFlow).Info.theKind == SUPERV::DataFlowGraph ) {
     RetVal = true ;
   }
   cdebug << "GraphEditor::OutNode::LoadDataFlow() _Imported " << _Imported << " RetVal " << RetVal << endl;
@@ -159,49 +195,76 @@ bool GraphEditor::OutNode::LoadDataFlow( const GraphBase::SGraph *aDataFlow ) {
   map< string , int > aMapOfNodes ;
   if ( RetVal ) {
     cdebug << "GraphEditor::OutNode::LoadDataFlow() LoadNodes GraphNodesSize " << Graph()->GraphNodesSize() << endl;
-    RetVal = LoadNodes( aMapOfNodes , aDataFlow->Nodes ) ;
+    RetVal = LoadNodes( aMapOfNodes , (*aDataFlow).Nodes ) ;
   }
   if ( RetVal ) {
     cdebug << "GraphEditor::OutNode::LoadDataFlow() LoadLinks GraphNodesSize " << Graph()->GraphNodesSize() << endl;
-    RetVal = LoadLinks( aMapOfNodes , aDataFlow->Links ) ;
+    RetVal = LoadLinks( aMapOfNodes , (*aDataFlow).Links ) ;
   }
   if ( RetVal ) {
     Valid() ;
     cdebug << "GraphEditor::OutNode::LoadDataFlow() LoadDatas GraphNodesSize " << Graph()->GraphNodesSize() << endl;
-    RetVal = LoadDatas( aMapOfNodes , aDataFlow->Datas ) ;
+    RetVal = LoadDatas( aMapOfNodes , (*aDataFlow).Datas ) ;
   }
   cdebug_out << "GraphEditor::OutNode::LoadDataFlow done GraphNodesSize " << Graph()->GraphNodesSize() << endl;
   return RetVal ;
 }
 
+bool GraphEditor::OutNode::LoadXml( const char* myFileName , GraphBase::ListOfSGraphs & aListOfDataFlows ) {
+  bool RetVal = false ;
+//  GraphBase::ListOfSGraphs aListOfDataFlows ;
+  if ( myFileName == NULL ) {
+    cdebug << "GraphEditor::OutNode::LoadXml() No file" << endl;
+    _Imported = true ;
+    char * aDataFlowName = Graph()->Name() ;
+//  Name( Graph()->Name() ) ;
+    Name( GraphInstanceName( Graph()->Name() ).c_str() ) ;
+//    MapGraph( Graph() , Graph()->Name() ) ;
+    cdebug << "GraphEditor::OutNode::LoadXml() " << aDataFlowName << " --> " << Graph()->Name() << endl;
+    RetVal = true ;
+  }
+  else {
+    cdebug_in << "GraphEditor::OutNode::LoadXml() " << myFileName << endl;
+    RetVal = Graph()->LoadXml( _Orb , myFileName , aListOfDataFlows ) ;
+//    RetVal = LoadDataFlows( &aListOfDataFlows ) ;
+    cdebug_out << "GraphEditor::OutNode::LoadXml " << RetVal << " " << aListOfDataFlows.size()
+               << " Graphs" << endl;
+  }
+  return RetVal ;
+} 
+
+#if 0
 bool GraphEditor::OutNode::LoadXml( const char* myFileName ) {
   bool RetVal = false ;
-  GraphBase::SGraph aDataFlow ;
+  GraphBase::ListOfSGraphs aListOfDataFlows ;
   if ( myFileName == NULL ) {
     cdebug << "GraphEditor::OutNode::LoadXml() No file" << endl;
     _Imported = true ;
     RetVal = true ;
   }
-  else if ( Graph()->LoadXml( _Orb , myFileName , aDataFlow ) ) {
+  else if ( Graph()->LoadXml( _Orb , myFileName , aListOfDataFlows ) ) {
     cdebug_in << "GraphEditor::OutNode::LoadXml() " << myFileName << endl;
-    RetVal = LoadDataFlow( &aDataFlow ) ;
+    RetVal = LoadDataFlows( &aListOfDataFlows ) ;
     cdebug_out << "GraphEditor::OutNode::LoadXml " << RetVal << endl;
   }
   return RetVal ;
-} 
+}
+#endif
 
 bool GraphEditor::OutNode::LoadInfo(const GraphBase::SNode &aDataFlowInfo ) {
   bool RetVal = false ;
   cdebug_in << "GraphEditor::OutNode::LoadInfo " << aDataFlowInfo.theName.c_str()
             << endl ;
-//  MESSAGE( "GraphEditor::OutNode::LoadDataFlow" );
+//  MESSAGE( "GraphEditor::OutNode::LoadInfo" );
 //  ComponentName( aDataFlowInfo.theComponentName.c_str() ) ;
 //  InterfaceName( aDataFlowInfo.theInterfaceName.c_str() ) ;
   if ( Graph()->IsDataStreamNode() || aDataFlowInfo.theKind == SUPERV::DataFlowGraph ) {
-    Graph()->Name( aDataFlowInfo.theName.c_str() ) ;
-//    Graph()->Kind( aDataFlowInfo.theKind ) ;
-    cdebug << "GraphEditor::OutNode::LoadInfo aDataFlowInfo.Kind " << aDataFlowInfo.theKind
-           << " Kind() " << Graph()->Kind() << endl ;
+    char * aDataFlowName = Graph()->Name() ;
+//    Graph()->Name( aDataFlowInfo.theName.c_str() ) ;
+    Graph()->Name( GraphInstanceName( aDataFlowInfo.theName.c_str() ).c_str() ) ;
+//    MapGraph( Graph() , Graph()->Name() ) ;
+    cdebug << "GraphEditor::OutNode::LoadInfo " << aDataFlowName << " --> " << Graph()->Name()
+           << " aDataFlowInfo.Kind " << aDataFlowInfo.theKind << " Kind() " << Graph()->Kind() << endl ;
     if ( Graph()->IsDataStreamNode() ) {
       Graph()->Kind( SUPERV::DataStreamGraph ) ;
       StreamGraph()->SetStreamParams( aDataFlowInfo.theTimeout , aDataFlowInfo.theDataStreamTrace , aDataFlowInfo.theDeltaTime ) ;
@@ -230,18 +293,22 @@ bool GraphEditor::OutNode::LoadInfo(const GraphBase::SNode &aDataFlowInfo ) {
 }
 
 bool GraphEditor::OutNode::LoadNodes(map< string , int > & aMapOfNodes ,
-                                     const GraphBase::ListOfNodes &aListOfNodes ) {
+                                     const GraphBase::ListOfSNodes &aListOfNodes ) {
   GraphEditor::InNode * anInNode ;
   cdebug_in << "GraphEditor::OutNode::LoadNodes " << endl ;
   int i ;
   for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
     GraphBase::SNode aNode = aListOfNodes[ i ] ;
     const char * aNodeName = aNode.theName.c_str() ;
-    cout << "GraphEditor::OutNode::LoadNodes " << aNodeName << " "
-         << aNode.theListOfInDataStreams.size() << " InDataStreams "
-         << aNode.theListOfOutDataStreams.size() << " OutDataStreams "
-         << " _prof_debug " << _prof_debug << endl ;
+//    cout << "GraphEditor::OutNode::LoadNodes " << aNodeName << " "
+//         << aNode.theService.ServiceinParameter.length() << " InParameters "
+//         << aNode.theService.ServiceoutParameter.length() << " OutParameters "
+//         << aNode.theListOfInDataStreams.size() << " InDataStreams "
+//         << aNode.theListOfOutDataStreams.size() << " OutDataStreams "
+//         << " _prof_debug " << _prof_debug << endl ;
     cdebug << "GraphEditor::OutNode::LoadNodes " << aNodeName << " "
+           << aNode.theService.ServiceinParameter.length() << " InParameters "
+           << aNode.theService.ServiceoutParameter.length() << " OutParameters "
            << aNode.theListOfInDataStreams.size() << " InDataStreams "
            << aNode.theListOfOutDataStreams.size() << " OutDataStreams "
            << endl ;
@@ -282,7 +349,7 @@ bool GraphEditor::OutNode::LoadNodes(map< string , int > & aMapOfNodes ,
                         aNode.theCoords.theX , aNode.theCoords.theY ) ;
     string * aNodetheName = new string( aNode.theName ) ;
     aMapOfNodes[ *aNodetheName ] = Graph()->GetGraphNodeIndex( anInNode->Name() ) ;
-    if ( anInNode->IsOneOfInLineNodes() ) {
+    if ( anInNode->IsOneOfInLineNodes() || anInNode->IsMacroNode() ) {
       anInNode->GraphEditor::InNode::InLineNode()->DefPortsOfNode(
                 _Orb , aNode.theService , anInNode->NamePtr() ,
                 anInNode->Kind() ,
@@ -298,7 +365,7 @@ bool GraphEditor::OutNode::LoadNodes(map< string , int > & aMapOfNodes ,
         aLNode->SetNextPythonFunction( aNode.theListOfFuncName[ 2 ].c_str() ,
                                        *aNode.theListOfPythonFunctions[ 2 ] ) ;
       }
-      else if ( aINode->IsInLineNode() || aINode->IsGOTONode() ||
+      else if ( aINode->IsMacroNode() || aINode->IsInLineNode() || aINode->IsGOTONode() ||
                 aINode->IsSwitchNode() || aINode->IsEndSwitchNode() ) {
         aINode->SetPythonFunction( aNode.theListOfFuncName[ 0 ].c_str() ,
                                    *aNode.theListOfPythonFunctions[ 0 ] ) ;
@@ -338,15 +405,37 @@ bool GraphEditor::OutNode::LoadNodes(map< string , int > & aMapOfNodes ,
       return false ;
     }
   }
+
+  // setting coupled pairs of nodes: Loop-EndLoop, Switch-EndSwitch, InLine-GOTO, MacroNode-Graph
   for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
     GraphBase::SNode aNode = aListOfNodes[ i ] ;
     cdebug << "GraphEditor::OutNode::LoadNodes " << aNode.theName.c_str() << " Coupled to "
            << aNode.theCoupledNode.c_str() << endl ;
-    anInNode = (GraphEditor::InNode * ) Graph()->GetChangeGraphNode( aNode.theName.c_str() )->GetInNode() ;
+    anInNode = (GraphEditor::InNode * ) Graph()->GetChangeGraphNode( aMapOfNodes[ aNode.theName.c_str() ] )->GetInNode() ;
+
     if ( anInNode->IsOneOfGOTONodes() && strlen( aNode.theCoupledNode.c_str() ) ) {
-      GraphBase::GOTONode * aCoupledNode ;
-      aCoupledNode = (GraphBase::GOTONode * ) Graph()->GetGraphNode( aNode.theName.c_str() ) ;
-      aCoupledNode->CoupledNode( (GraphBase::GOTONode * ) Graph()->GetChangeGraphNode( aNode.theCoupledNode.c_str() ) ) ; 
+      GraphBase::GOTONode * aGOTONode;
+      aGOTONode = (GraphBase::GOTONode * ) anInNode->ComputingNode() ;
+
+      // asv : 25.10.04 : if aNode is a MacroNode, then its coupled node (another Graph) is NOT in aMapOfNodes 
+      //                  and we must couple MacroNode only with name to its subgraph
+      if ( aGOTONode->IsMacroNode() ) {
+        cdebug << "GraphEditor::OutNode::LoadNodes MacroNode " << aNode.theName.c_str()
+              << " is Coupled ONLY WITH NAME to its subgraph " << aNode.theCoupledNode.c_str() << endl;
+        aGOTONode->CoupledNodeName( aNode.theCoupledNode.c_str() ) ;
+      }
+      else { // coupling Loop-EndLoop, Switch-EndSwitch, InLine-GOTO
+       // asv : fix for 6822 : using map because if aNode's name is the same as some existing node's name
+       // aMap will give the correct index any way (aMap has already a different name for aNode, SNode still has old name)
+       int aCoupledNodeIndex = aMapOfNodes[ aNode.theCoupledNode.c_str() ] ;
+       cdebug << "GraphEditor::OutNode::LoadNodes " << aNode.theCoupledNode.c_str()
+              << " index " << aCoupledNodeIndex << endl ;
+        GraphBase::GOTONode * aCoupledNode ;
+        aCoupledNode = (GraphBase::GOTONode * ) Graph()->GetChangeGraphNode( aCoupledNodeIndex ) ;
+        cdebug << "GraphEditor::OutNode::LoadNodes " << aNode.theName.c_str()
+               << " is now Coupled to " << aNode.theCoupledNode.c_str() << endl ;
+        aGOTONode->CoupledNode( aCoupledNode ) ;
+      }
     }
   }
   cdebug_out << "GraphEditor::OutNode::LoadNodes" << endl ;
@@ -354,7 +443,7 @@ bool GraphEditor::OutNode::LoadNodes(map< string , int > & aMapOfNodes ,
 }
 
 bool GraphEditor::OutNode::LoadLinks(map< string , int > & aMapOfNodes ,
-                                     const GraphBase::ListOfLinks &aListOfLinks ) {
+                                     const GraphBase::ListOfSLinks &aListOfLinks ) {
   bool RetVal = true ;
   cdebug_in << "GraphEditor::OutNode::LoadLinks" << endl ;
 //  MESSAGE( "GraphEditor::OutNode::LoadLinks" );
@@ -369,13 +458,13 @@ bool GraphEditor::OutNode::LoadLinks(map< string , int > & aMapOfNodes ,
            << aLink.ToServiceParameterName.c_str() << " )" << endl ;
     if ( Graph()->GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] ) &&
          Graph()->GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] ) ) {
-      GraphBase::ComputingNode * aFromNode = (GraphBase::ComputingNode * ) Graph()->GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] ) ;
-      const GraphBase::OutPort * anOutPort = aFromNode->GetOutPort( aLink.FromServiceParameterName.c_str() ) ;
+//      GraphBase::ComputingNode * aFromNode = (GraphBase::ComputingNode * ) Graph()->GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] ) ;
+//      const GraphBase::OutPort * anOutPort = aFromNode->GetOutPort( aLink.FromServiceParameterName.c_str() ) ;
       RetVal = AddLink( Graph()->GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] )->Name() ,
-                                 aLink.FromServiceParameterName.c_str() ,
-                                 Graph()->GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] )->Name() ,
-                                 aLink.ToServiceParameterName.c_str() ,
-                                 *anOutPort->Value() ) ;
+                        aLink.FromServiceParameterName.c_str() ,
+                        Graph()->GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] )->Name() ,
+                        aLink.ToServiceParameterName.c_str() ) ;
+//                        , *anOutPort->Value() ) ;
     }
     else {
       RetVal = false ;
@@ -404,19 +493,16 @@ bool GraphEditor::OutNode::LoadLinks(map< string , int > & aMapOfNodes ,
 }
 
 bool GraphEditor::OutNode::LoadDatas(map< string , int > & aMapOfNodes ,
-                                     const GraphBase::ListOfLinks &aListOfDatas ) {
+                                     const GraphBase::ListOfSLinks &aListOfDatas ) {
   bool RetVal = true ;
   cdebug_in << "GraphEditor::OutNode::LoadDatas" << endl ;
 //  MESSAGE( "GraphEditor::OutNode::LoadDatas" );
   int i ;
   for ( i = 0 ; i < (int ) aListOfDatas.size() ; i++ ) {
     GraphBase::SLink aLink = aListOfDatas[ i ] ;
-    if ( !strcmp( aLink.FromNodeName.c_str() , Graph()->Name() ) ) {
-      cdebug << "GraphEditor::OutNode::LoadDatas Warning "
-             << aLink.FromNodeName.c_str()
-             << " and " << aLink.ToNodeName.c_str() << " differents from " << Graph()->Name()
-             << endl ;
-    }
+    cdebug << "OutNode::LoadDatas " << i << aLink.FromNodeName.c_str() << "(" << aLink.FromServiceParameterName
+           << ") --> " << aLink.ToNodeName.c_str() << "(" << aLink.ToServiceParameterName << ") CORBA::tk_xxx "
+           << aLink.aLinkValue.type()->kind() << endl ;
     string * aLinkFromNodeName = new string( aLink.FromNodeName.c_str() ) ;
     string * aLinkToNodeName = new string( aLink.ToNodeName.c_str() ) ;
 //      cout << "LoadDatas " << aLink.FromNodeName.c_str() << " "
@@ -440,14 +526,20 @@ bool GraphEditor::OutNode::SaveXml(const char* filename) {
   cdebug_in << "GraphEditor::OutNode::SaveXml(" << filename << ")" << endl;
   ofstream f(filename);
   IsValid() ;
-//  test = SaveXML( f );
-  QDomDocument Graph ;
-  test = SaveXML( Graph );
-  if ( test ) {
-    QString xml = Graph.toString() ;
+  QDomDocument DomGraph ;
+  QDomElement Domsupergraph ;
+  cdebug << "OutNode::SaveXML("<< filename << ") ---> OutNode::SaveXML( ostream & f , QDomDocument & , true "
+         << " , QDomElement & ) " << Graph()->Name() << endl ;
+  test = SaveXML( f , DomGraph , true , Domsupergraph );
+  QString xml = DomGraph.toString() ;
+  f << xml << endl ;
+
+  cdebug << "OutNode::SaveXML("<< filename << ") done" << endl ;
+//  if ( test ) {
+//    QString xml = Graph.toString() ;
 //    cout << "GraphEditor::OutNode::SaveXML " << xml << endl ;
-    f << xml << endl ;
-  }
+//    f << xml << endl ;
+//  }
   cdebug_out << "GraphEditor::OutNode::SaveXml" << endl;
   return test;
 }
@@ -458,26 +550,39 @@ bool GraphEditor::OutNode::SavePy( const char* filename ) {
   cdebug_in << "GraphEditor::OutNode::SavePy(" << filename << ")" << endl;
   ofstream f( filename ) ;
   IsValid() ;
-  test = SavePY( f );
+  test = SavePY( f , true );
+  f << endl << Graph()->Name() << " = Def" << Graph()->Name() << "()" << endl ;
   cdebug_out << "GraphEditor::OutNode::SavePy" << endl;
   return test;
 }
 
-GraphBase::SGraph * GraphEditor::OutNode::GetDataFlow() {
-  GraphBase::SGraph * aDataFlow = new GraphBase::SGraph;
+GraphBase::ListOfSGraphs * GraphEditor::OutNode::GetDataFlows( GraphBase::ListOfSGraphs * aListOfDataFlows ) {
+//  GraphBase::ListOfSGraphs * aListOfDataFlows = new GraphBase::ListOfSGraphs;
+  int index = aListOfDataFlows->size() ;
+  aListOfDataFlows->resize( index + 1 ) ;
   if ( Graph()->IsDataFlowNode() ) {
-    aDataFlow->Info = *Graph()->GetInfo() ;
-    aDataFlow->Nodes = *Graph()->GetNodes() ;
-    aDataFlow->Links = *Graph()->GetLinks( true ) ;
-    aDataFlow->Datas = *Graph()->GetDatas() ;
+    (*aListOfDataFlows)[ index ].Info = *Graph()->GetInfo() ;
+    (*aListOfDataFlows)[ index ].Nodes = *Graph()->GetNodes() ;
+    (*aListOfDataFlows)[ index ].Links = *Graph()->GetLinks( true ) ;
+    (*aListOfDataFlows)[ index ].Datas = *Graph()->GetDatas() ;
   }
   else {
-    aDataFlow->Info = *StreamGraph()->GetInfo() ;
-    aDataFlow->Nodes = *StreamGraph()->GetNodes() ;
-    aDataFlow->Links = *StreamGraph()->GetLinks( true ) ;
-    aDataFlow->Datas = *StreamGraph()->GetDatas() ;
+    (*aListOfDataFlows)[ index ].Info = *StreamGraph()->GetInfo() ;
+    (*aListOfDataFlows)[ index ].Nodes = *StreamGraph()->GetNodes() ;
+    (*aListOfDataFlows)[ index ].Links = *StreamGraph()->GetLinks( true ) ;
+    (*aListOfDataFlows)[ index ].Datas = *StreamGraph()->GetDatas() ;
   }
-  return aDataFlow ;
+  int i ;
+  for ( i = 0 ; i < (int ) (*aListOfDataFlows)[ index ].Nodes.size() ; i++ ) {
+    const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( (*aListOfDataFlows)[ index ].Nodes[i].theName.c_str() ) ;
+    if ( aNode->IsMacroNode() ) {
+//      string aCoupledNodeName = (*aListOfDataFlows)[ index ].Nodes[i].theCoupledNode ;
+      GraphBase::Graph * aGraph = (GraphBase::Graph * ) ((GraphBase::GOTONode * ) aNode )->CoupledNode() ;
+//      GraphBase::Graph * aGraph = MapGraph( aCoupledNodeName.c_str() ) ;
+      aGraph->GraphEditor()->GraphEditor::OutNode::GetDataFlows( aListOfDataFlows ) ;
+    }
+  }
+  return aListOfDataFlows ;
 }
 
 void GraphEditor::OutNode::DateModification() {
@@ -543,7 +648,7 @@ GraphEditor::InNode * GraphEditor::OutNode::AddNode(
   cdebug << " " << NodeKindOfNode << endl ;
   char * RetVal = NULLSTRING ;
   GraphEditor::InNode *Nd = NULL ;
-  char * aNodeName = NULL ;
+  char * aNodeName = NULLSTRING ;
   bool   GeneratedName = false ;
   if ( NodeKindOfNode == SUPERV::InLineNode ||
        NodeKindOfNode == SUPERV::LoopNode ||
@@ -576,7 +681,7 @@ GraphEditor::InNode * GraphEditor::OutNode::AddNode(
     }
     theNodeName = NULLSTRING ;
   }
-  if ( theNodeName == NULLSTRING || strlen( theNodeName ) == 0 ) {
+  if ( theNodeName == NULLSTRING || strlen( theNodeName ) == 0 || Graph()->GetGraphNode( theNodeName ) ) {
     aNodeName = new char[ strlen( NodeService.ServiceName )+1 ] ;
     strcpy( aNodeName , NodeService.ServiceName ) ;
     if ( Graph()->GetGraphNode( NodeService.ServiceName ) ) {
@@ -603,6 +708,9 @@ GraphEditor::InNode * GraphEditor::OutNode::AddNode(
       aNodeName = new char[ strlen( theNodeName )+1 ] ;
       strcpy( aNodeName , theNodeName ) ;
     }
+    else {
+      aNodeName = NULLSTRING ;
+    }
   }
   if ( aNodeName != NULLSTRING ) {
     Nd = new GraphEditor::InNode( _Orb , Graph()->NamingService() ,
@@ -614,8 +722,10 @@ GraphEditor::InNode * GraphEditor::OutNode::AddNode(
                                   NodeComputer , NodeComment , GeneratedName ,
                                   NodeX , NodeY ,
                                   _prof_debug , _fdebug ) ;
-//    MESSAGE( "GraphEditor::OutNode::AddNode " << hex << (void *) Nd << dec );
-//    if ( GraphBase::Graph::AddNode( Nd ) ) {
+    
+    // asv: 28.09.04 fix for 6621
+    //if ( Nd->IsMacroNode() )
+    //  MapGraph( Nd->GraphMacroNode(), aNodeName );
 
     if ( Graph()->IsDataStreamNode() && ( Nd->IsComputingNode() || Nd->IsFactoryNode() ) ) {
       unsigned int i ;
@@ -811,17 +921,13 @@ bool GraphEditor::OutNode::GetLinkCoord( const char* FromNodeName ,
   return false ;
 }
 
-bool GraphEditor::OutNode::AddInputData( const char* ToNodeName1 ,
-                                         const char* ToParameterName1 ,
-                                         const char* ToNodeName2 ,
-                                         const char* ToParameterName2 ) {
-  cdebug_in << "GraphEditor::OutNode::AddInputData" << endl;
-  bool RetVal = Graph()->AddInputData( ToNodeName1 ,
-                                                ToParameterName1 ,
-                                                ToNodeName2 ,
-                                                ToParameterName2 ) ;
-  cdebug_out << "GraphEditor::OutNode::AddInputData" << endl;
+bool GraphEditor::OutNode::UnValid() {
+  bool RetVal = _Valid ;
   _Valid = false ;
+  if ( Graph()->GraphMacroLevel() != 0 ) {
+    cdebug << "GraphEditor::OutNode::UnValid() GraphMacroLevel " << Graph()->GraphMacroLevel() << endl ;
+    RetVal = Valid() ;
+  }
   return RetVal ;
 }
 
@@ -832,11 +938,29 @@ bool GraphEditor::OutNode::Valid() {
   cdebug_in << "GraphEditor::OutNode::Valid" << endl;
   _Executable = false ;
 
-  Graph()->CreateService() ;
+  if ( !Graph()->CreateService() ) {
+    cdebug_out << "GraphEditor::OutNode::Valid " << _Valid << endl;
+    return false ;
+  }
   
+  if ( Graph()->GraphMacroLevel() != 0 ) {
+    cdebug << "CoupledNode " << Graph()->CoupledNode() << endl ;
+    cdebug << "GraphEditor " << Graph()->CoupledNode()->GraphEditor() << endl ;
+    cdebug << "Graph " << Graph()->CoupledNode()->GraphEditor()->Graph() << endl ;
+    cdebug << "Name " << Graph()->CoupledNode()->GraphEditor()->Graph()->Name() << endl ;
+    cdebug << "Valid --> UpdateMacroPorts of " << Graph()->CoupledNodeName() << " of "
+           << Graph()->CoupledNode()->GraphEditor()->Graph()->Name() << endl ;
+    cdebug << Graph()->CoupledNode() << endl ;
+    Graph()->CoupledNode()->UpdateMacroPorts( Graph() ) ;
+    cdebug << Graph()->CoupledNode()->Name() << " Valid --> UnValid of graph "
+           << Graph()->CoupledNode()->GraphEditor()->Graph()->Name()
+           << " GraphMacroLevel " << Graph()->CoupledNode()->GraphEditor()->Graph()->GraphMacroLevel()  << endl ;
+    Graph()->CoupledNode()->GraphEditor()->UnValid() ;
+  }
+
   int SubStreamGraphsNumber = 0 ;
   if ( !Graph()->Sort( SubStreamGraphsNumber ) ) {
-    cdebug << "This DataFlow is not valid." << endl ;
+    cdebug_out << "This DataFlow is not valid." << endl ;
     return false ;
   }
   if ( Graph()->IsDataStreamNode() ) {
@@ -851,7 +975,7 @@ bool GraphEditor::OutNode::Valid() {
 
   _Valid = true ;
 
-  cdebug_out << "GraphEditor::OutNode::Valid" << endl;
+  cdebug_out << "GraphEditor::OutNode::Valid " << _Valid << endl;
   return _Valid ;
 }
 
@@ -884,6 +1008,11 @@ bool GraphEditor::OutNode::Executable() {
     StreamGraph()->CreateStreamTopology( "/tmp/" ) ;
   }
 
+  // asv : 13.12.04 : introducing check for compatibility of linked ports' types.
+  if ( !IsLinksCompatible() ) {
+    _Executable = false;
+  }    
+
   cdebug_out << "GraphEditor::OutNode::Executable" << endl;
   return _Executable ;
 }
@@ -1078,7 +1207,7 @@ bool GraphEditor::OutNode::LinkSavePY( ostream &f , const char * aGraphName ,
 //        << aLink.FromServiceParameterName.c_str()
 //        << "' )" << endl ;
 //    }
-    f << "L" << aLink.FromNodeName.c_str() << aLink.FromServiceParameterName.c_str()
+    f << "    " << "L" << aLink.FromNodeName.c_str() << aLink.FromServiceParameterName.c_str()
       << aLink.ToNodeName.c_str() << aLink.ToServiceParameterName.c_str() ;
     if ( ((GraphBase::Graph *) Graph())->GetChangeGraphNode( aLink.FromNodeName.c_str() )->GetChangeOutPort( aLink.FromServiceParameterName.c_str() )->IsDataStream() ) {
       f << " = " << aGraphName << ".StreamLink( " ;
@@ -1096,7 +1225,7 @@ bool GraphEditor::OutNode::LinkSavePY( ostream &f , const char * aGraphName ,
     f << aLink.ToNodeName.c_str() << aLink.ToServiceParameterName.c_str() << " )" << endl ;
   }
   else {
-    f << "I"<< aLink.ToNodeName.c_str() << aLink.ToServiceParameterName.c_str()
+    f << "    " << "I"<< aLink.ToNodeName.c_str() << aLink.ToServiceParameterName.c_str()
 //      << " = " << aLink.ToNodeName.c_str() << ".Input( '"
 //      << aLink.ToServiceParameterName.c_str() << "' , " ;
       << ".Input( " ;
@@ -1137,7 +1266,7 @@ bool GraphEditor::OutNode::LinkSavePY( ostream &f , const char * aGraphName ,
   }
   int i ;
   for ( i = 0 ; i < (int ) aLink.aListOfCoords.size() ; i++ ) {
-    f << "L" << aLink.FromNodeName.c_str() << aLink.FromServiceParameterName.c_str()
+    f << "    " << "L" << aLink.FromNodeName.c_str() << aLink.FromServiceParameterName.c_str()
       << aLink.ToNodeName.c_str() << aLink.ToServiceParameterName.c_str() << ".AddCoord( " << i+1 << " , "
       << aLink.aListOfCoords[ i ].theX << " , "
       << aLink.aListOfCoords[ i ].theY << " )" << endl ;
@@ -1146,30 +1275,36 @@ bool GraphEditor::OutNode::LinkSavePY( ostream &f , const char * aGraphName ,
 }
 
 //bool GraphEditor::OutNode::SaveXML(ostream & f ) {
-bool GraphEditor::OutNode::SaveXML(QDomDocument & GraphQDom ) {
+bool GraphEditor::OutNode::SaveXML( ostream & f , QDomDocument & GraphQDom ,
+                                    bool aSuperGraph , QDomElement & supergraph ) {
+  cdebug_in << "OutNode::SaveXML( ostream & f , QDomDocument & , " << aSuperGraph << " , QDomElement & ) "
+            << Graph()->Name() << endl ;
   int i ;
-//  f << "<?xml version='1.0' encoding='us-ascii' ?>" << endl << endl ;
-//  f << "<!-- XML Dataflow -->" << endl << endl ;
-//  f << "<!-- Dataflow information -->" << endl ;
-  QString Dataflow("Dataflow") ;
-  GraphQDom = QDomDocument(Dataflow) ;
-//  f << "<dataflow>" << endl ;
-  QDomElement dataflow = GraphQDom.createElement( "dataflow" ) ;
-  GraphQDom.appendChild( dataflow ) ;
-//  f << "     <info-list>" << endl ;
-  QDomElement info = GraphQDom.createElement( "info-list" ) ;
-  dataflow.appendChild( info ) ;
 
-//  f << "             <node>" << endl ;
+  QDomElement dataflow ;
+  if ( aSuperGraph ) {
+    QString SuperGraph("SuperGraph") ;
+    GraphQDom = QDomDocument(SuperGraph) ;
 
-//  GraphBase::DataNode::SaveXML( f , "                        " , 0 , 0 ) ;
-  Graph()->SaveXML( GraphQDom , info , 0 , 0 ) ;
+    supergraph = GraphQDom.createElement( "supergraph" ) ;
+    GraphQDom.appendChild( supergraph ) ;
 
-//  f << "             </node>" << endl ;
+    dataflow = GraphQDom.createElement( "dataflow" ) ;
+    supergraph.appendChild( dataflow ) ;
+  }
+  else {
+//    QString Dataflow("Dataflow") ;
+//    GraphQDom = QDomDocument(Dataflow) ;
 
-//  f << "     </info-list>" << endl << endl ;
+    dataflow = GraphQDom.createElement( "dataflow" ) ;
+    supergraph.appendChild( dataflow ) ;
+  }
+
+  QDomElement info = GraphQDom.createElement( "info-list" ) ;
+  dataflow.appendChild( info ) ;
+
+  Graph()->SaveXML( GraphQDom , info , 0 , 0 ) ;
 
-//  f << "     <node-list>" << endl ;
   QDomElement nodelist = GraphQDom.createElement( "node-list" ) ;
   dataflow.appendChild( nodelist ) ;
   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
@@ -1188,13 +1323,20 @@ bool GraphEditor::OutNode::SaveXML(QDomDocument & GraphQDom ) {
                     Graph()->GraphNodes( i )->XCoordinate() ,
                     Graph()->GraphNodes( i )->YCoordinate() ) ;
       }
-      else if ( Graph()->GraphNodes( i )->IsInLineNode() ) {
+      else if ( Graph()->GraphNodes( i )->IsInLineNode()  ) {
 //        ((GraphBase::InLineNode * ) GraphNodes( i ))->SaveXML( f ,
 //                    "                        " ,
         ((GraphBase::InLineNode * ) Graph()->GraphNodes( i ))->SaveXML( GraphQDom , nodelist ,
                     Graph()->GraphNodes( i )->XCoordinate() ,
                     Graph()->GraphNodes( i )->YCoordinate() ) ;
       }
+      else if ( Graph()->GraphNodes( i )->IsMacroNode() ) {
+//        ((GraphBase::InLineNode * ) GraphNodes( i ))->SaveXML( f ,
+//                    "                        " ,
+        ((GraphBase::GOTONode * ) Graph()->GraphNodes( i ))->SaveXML( GraphQDom , nodelist ,
+                    Graph()->GraphNodes( i )->XCoordinate() ,
+                    Graph()->GraphNodes( i )->YCoordinate() ) ;
+      }
       else if ( Graph()->GraphNodes( i )->IsGOTONode() ) {
 //        ((GraphBase::GOTONode * ) GraphNodes( i ))->SaveXML( f ,
 //                    "                        " ,
@@ -1238,7 +1380,7 @@ bool GraphEditor::OutNode::SaveXML(QDomDocument & GraphQDom ) {
 //  f << "     <link-list>" << endl ;
   QDomElement linklist = GraphQDom.createElement( "link-list" ) ;
   dataflow.appendChild( linklist ) ;
-  const GraphBase::ListOfLinks * Links = Graph()->GetLinks( true ) ;
+  const GraphBase::ListOfSLinks * Links = Graph()->GetLinks( true ) ;
   for ( i = 0 ; i < (int ) Links->size() ; i++ ) {
 //    f << "           <link>" << endl ;
     QDomElement link = GraphQDom.createElement( "link" ) ;
@@ -1252,63 +1394,57 @@ bool GraphEditor::OutNode::SaveXML(QDomDocument & GraphQDom ) {
 //  f << "     <data-list>" << endl ;
   QDomElement datalist = GraphQDom.createElement( "data-list" ) ;
   dataflow.appendChild( datalist ) ;
-  const GraphBase::ListOfLinks * Datas = Graph()->GetDatas() ;
-  for ( i = 0 ; i < (int ) Datas->size() ; i++ ) {
+  if ( Graph()->GraphMacroLevel() == 0 ) {
+    const GraphBase::ListOfSLinks * Datas = Graph()->GetDatas() ;
+    for ( i = 0 ; i < (int ) Datas->size() ; i++ ) {
 //    f << "           <data>" << endl ;
-    QDomElement data = GraphQDom.createElement( "data" ) ;
-    datalist.appendChild( data ) ;
+      QDomElement data = GraphQDom.createElement( "data" ) ;
+      datalist.appendChild( data ) ;
 //    LinkSaveXML( f , "                       " , (*Datas)[ i ] , true ) ;
-    LinkSaveXML( GraphQDom , data , (*Datas)[ i ] , true ) ;
+      LinkSaveXML( GraphQDom , data , (*Datas)[ i ] , true ) ;
 //    f << "           </data>" << endl ;
+    }
   }
-//#if 0
-//  const GraphEditor::OutNode * aDataNode = (GraphEditor::OutNode *) this ;
-//  if ( aDataNode ) {
-//    int i ;
-//    for ( i = 0 ; i < aDataNode->GetNodeOutPortsSize() ; i++ ) {
-//      const GraphBase::InPort *aLink = aDataNode->GetNodeOutPort(i)->GetLink() ;
-//      if ( aLink ) {
-//        f << "               <data>" << endl ;
-//        aLink->SaveXML( f , "                        " ) ;
-//        f << "               </data>" << endl ;
-//      }
-//    }
-//    for ( i = 0 ; i < aDataNode->GetNodeInPortsSize() ; i++ ) {
-//      const GraphBase::InPort *aLink = aDataNode->GetNodeInPort(i)->GetLink() ;
-//      if ( aLink ) {
-//        f << "               <data>" << endl ;
-//        aLink->SaveXML( f , "                        " ) ;
-//        f << "               </data>" << endl ;
-//      }
-//    }
-//  }
-//#endif
 
-#if 0
-  f << "       </data-list>" << endl << endl ;
-  f << "</dataflow>" << endl ;
-#endif
+  for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
+    if ( Graph()->GraphNodes( i )->IsMacroNode() ) {
+      GraphBase::GOTONode * aMacroNode = (GraphBase::GOTONode * ) Graph()->GraphNodes( i ) ;
+      GraphBase::Graph * aMacroGraph = (GraphBase::Graph * ) aMacroNode->CoupledNode() ;
+      cdebug << "OutNode::SaveXML ---> OutNode::SaveXML( ostream & f , QDomDocument & , false "
+             << " , QDomElement & ) MacroGraph " << aMacroGraph->Name() << endl ;
+      if ( !aMacroGraph->GraphEditor()->SaveXML( f , GraphQDom , false , supergraph ) ) {
+        return false ;
+      cdebug << "OutNode::SaveXML MacroGraph "<< aMacroGraph->Name() << " done" << endl ;
+      }
+    }
+  }
+
+  cdebug_out << "OutNode::SaveXML( ostream & f , QDomDocument & , " << aSuperGraph << " , QDomElement & ) "
+             << Graph()->Name() << endl ;
 
   return true ;
 }
 
-bool GraphEditor::OutNode::SavePY( ostream & f ) {
+bool GraphEditor::OutNode::SavePY( ostream & f , bool importSuperV ) {
   int i ;
   int j ;
-  f << endl << "# Generated python file of Graph " << Graph()->Name() << endl << endl ;
+  if ( importSuperV ) {
+    f << endl << "# Generated python file of Graph " << Graph()->Name() << endl << endl ;
 
-  f << "from SuperV import *" << endl ;
+    f << "from SuperV import *" << endl << endl ;
+  }
 
-  f << "# Graph creation " << endl ;
+  f << "# Graph creation of " << Graph()->Name() << endl ;
+  f << "def Def" << Graph()->Name() << "() :" << endl ;
   Graph()->SavePY( f , Graph()->Name() , 0 , 0 ) ;
 
-  f << endl << "# Creation of Factory Nodes" << endl ;
+  f << "    " << endl << "    " << "# Creation of Factory Nodes" << endl ;
   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
     if ( Graph()->GraphNodes( i )->IsFactoryNode() ) {
-      f << endl ;
+      f << "    " << endl ;
       ((GraphBase::FactoryNode * ) Graph()->GraphNodes( i ))->SavePY( f , Graph()->Name() ,
-                Graph()->GraphNodes( i )->XCoordinate() ,
-                Graph()->GraphNodes( i )->YCoordinate() ) ;
+                                                                      Graph()->GraphNodes( i )->XCoordinate() ,
+                                                                      Graph()->GraphNodes( i )->YCoordinate() ) ;
     }
   }
 
@@ -1316,15 +1452,15 @@ bool GraphEditor::OutNode::SavePY( ostream & f ) {
   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
     if ( Graph()->GraphNodes( i )->IsComputingNode() ) {
       if ( first ) {
-        f << endl << "# Creation of Computing Nodes" << endl ;
+        f << "    " << endl << "    " << "# Creation of Computing Nodes" << endl ;
         first = false ;
       }
       else {
-        f << endl ;
+        f << "    " << endl ;
       }
       ((GraphBase::ComputingNode * ) Graph()->GraphNodes( i ))->SavePY( f , Graph()->Name() ,
-                Graph()->GraphNodes( i )->XCoordinate() ,
-                Graph()->GraphNodes( i )->YCoordinate() ) ;
+                                                                        Graph()->GraphNodes( i )->XCoordinate() ,
+                                                                        Graph()->GraphNodes( i )->YCoordinate() ) ;
     }
   }
 
@@ -1332,15 +1468,15 @@ bool GraphEditor::OutNode::SavePY( ostream & f ) {
   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
     if ( Graph()->GraphNodes( i )->IsInLineNode() ) {
       if ( first ) {
-        f << endl << "# Creation of InLine Nodes" << endl ;
+        f << "    " << endl << "    " << "# Creation of InLine Nodes" << endl ;
         first = false ;
       }
       else {
-        f << endl ;
+        f << "    " << endl ;
       }
       ((GraphBase::InLineNode * ) Graph()->GraphNodes( i ))->SavePY( f , Graph()->Name() ,
-                Graph()->GraphNodes( i )->XCoordinate() ,
-                Graph()->GraphNodes( i )->YCoordinate() ) ;
+                                                                     Graph()->GraphNodes( i )->XCoordinate() ,
+                                                                     Graph()->GraphNodes( i )->YCoordinate() ) ;
     }
   }
 
@@ -1348,15 +1484,15 @@ bool GraphEditor::OutNode::SavePY( ostream & f ) {
   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
     if ( Graph()->GraphNodes( i )->IsLoopNode() ) {
       if ( first ) {
-        f << endl << "# Creation of Loop Nodes" << endl ;
+        f << "    " << endl << "    " << "# Creation of Loop Nodes" << endl ;
         first = false ;
       }
       else {
-        f << endl ;
+        f << "    " << endl ;
       }
       ((GraphBase::LoopNode * ) Graph()->GraphNodes( i ))->SavePY( f , Graph()->Name() ,
-                Graph()->GraphNodes( i )->XCoordinate() ,
-                Graph()->GraphNodes( i )->YCoordinate() ) ;
+                                                                   Graph()->GraphNodes( i )->XCoordinate() ,
+                                                                   Graph()->GraphNodes( i )->YCoordinate() ) ;
     }
   }
 
@@ -1364,15 +1500,15 @@ bool GraphEditor::OutNode::SavePY( ostream & f ) {
   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
     if ( Graph()->GraphNodes( i )->IsSwitchNode() ) {
       if ( first ) {
-        f << endl << "# Creation of Switch Nodes" << endl ;
+        f << "    " << endl << "    " << "# Creation of Switch Nodes" << endl ;
         first = false ;
       }
       else {
-        f << endl ;
+        f << "    " << endl ;
       }
       ((GraphBase::SwitchNode * ) Graph()->GraphNodes( i ))->SavePY( f , Graph()->Name() ,
-                Graph()->GraphNodes( i )->XCoordinate() ,
-                Graph()->GraphNodes( i )->YCoordinate() ) ;
+                                                                     Graph()->GraphNodes( i )->XCoordinate() ,
+                                                                     Graph()->GraphNodes( i )->YCoordinate() ) ;
     }
   }
 
@@ -1380,19 +1516,35 @@ bool GraphEditor::OutNode::SavePY( ostream & f ) {
   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
     if ( Graph()->GraphNodes( i )->IsGOTONode() ) {
       if ( first ) {
-        f << endl << "# Creation of GOTO Nodes" << endl ;
+        f << "    " << endl << "    " << "# Creation of GOTO Nodes" << endl ;
         first = false ;
       }
       else {
-        f << endl ;
+        f << "    " << endl ;
       }
       ((GraphBase::GOTONode * ) Graph()->GraphNodes( i ))->SavePY( f , Graph()->Name() ,
-                Graph()->GraphNodes( i )->XCoordinate() ,
-                Graph()->GraphNodes( i )->YCoordinate() ) ;
+                                                                   Graph()->GraphNodes( i )->XCoordinate() ,
+                                                                   Graph()->GraphNodes( i )->YCoordinate() ) ;
     }
   }
 
-  const GraphBase::ListOfLinks * Links = Graph()->GetLinks() ;
+  first = true ;
+  for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
+    if ( Graph()->GraphNodes( i )->IsMacroNode() ) {
+      if ( first ) {
+        f << "    " << endl << "    " << "# Creation of Macro Nodes" << endl ;
+        first = false ;
+      }
+      else {
+        f << "    " << endl ;
+      }
+      ((GraphBase::GOTONode * ) Graph()->GraphNodes( i ))->SavePY( f , Graph()->Name() ,
+                                                                   Graph()->GraphNodes( i )->XCoordinate() ,
+                                                                   Graph()->GraphNodes( i )->YCoordinate() ) ;
+    }
+  }
+
+  const GraphBase::ListOfSLinks * Links = Graph()->GetLinks() ;
 //  bool intervar ;
 //  map< string , int > aMapOfOutPorts ;
   first = true ;
@@ -1400,13 +1552,13 @@ bool GraphEditor::OutNode::SavePY( ostream & f ) {
     for ( j = 0 ; j < (int ) Links->size() ; j++ ) {
       if ( !strcmp( Graph()->GraphNodes( i )->Name() , (*Links)[ j ].FromNodeName.c_str() ) ) {
         if ( first ) {
-          f << endl
-            << "# Creation of Links"
+          f << "    " << endl
+            << "    " << "# Creation of Links"
             << endl ;
           first = false ;
         }
         else {
-          f << endl ;
+          f << "    " << endl ;
         }
 //        char * NodePort = new char [ strlen( (*Links)[ j ].FromNodeName.c_str() ) +
 //                                     strlen( (*Links)[ j ].FromServiceParameterName.c_str() ) + 1 ] ;
@@ -1433,16 +1585,18 @@ bool GraphEditor::OutNode::SavePY( ostream & f ) {
     }
   }
 
-  const GraphBase::ListOfLinks * Datas = Graph()->GetDatas() ;
-  first = true ;
-  for ( i = 0 ; i < (int ) Datas->size() ; i++ ) {
-    if ( first ) {
-      f << endl << "# Input datas" << endl ;
-      first = false ;
+  if ( Graph()->GraphMacroLevel() == 0 ) {
+    const GraphBase::ListOfSLinks * Datas = Graph()->GetDatas() ;
+    first = true ;
+    for ( i = 0 ; i < (int ) Datas->size() ; i++ ) {
+      if ( first ) {
+        f << "    " << endl << "    " << "# Input datas" << endl ;
+        first = false ;
+      }
+      bool fromparam = true ;
+      bool toparam = true ;
+      LinkSavePY( f , Graph()->Name() , (*Datas)[ i ] , fromparam , toparam , true ) ;
     }
-    bool fromparam = true ;
-    bool toparam = true ;
-    LinkSavePY( f , Graph()->Name() , (*Datas)[ i ] , fromparam , toparam , true ) ;
   }
 
   first = true ;
@@ -1454,29 +1608,30 @@ bool GraphEditor::OutNode::SavePY( ostream & f ) {
     char * aPortName ;
     int j ;
     for ( j = 0 ; j < (int ) strlen( aParam ) ; j++ ) {
-      if ( aParam[ j ] == '\\' ) {
+//      if ( aParam[ j ] == '\\' ) {
+      if ( aParam[ j ] == '_' && aParam[ j+1 ] == '_' ) {
         aNodeName = new char[ j+1 ] ;
         strncpy( aNodeName , aParam , j ) ;
         aNodeName[ j ] = '\0' ;
-        aPortName = new char[ strlen( aParam ) - j ] ;
-        strncpy( aPortName , &aParam[ j+1 ] , strlen( aParam ) - j ) ;
+        aPortName = new char[ strlen( aParam ) - j-1 ] ;
+        strncpy( aPortName , &aParam[ j+2 ] , strlen( aParam ) - j-1 ) ;
         break ;
       }
     }
     const GraphBase::InPort * anInPort = Graph()->GetChangeGraphNode( aNodeName )->GetInPort( aPortName ) ;
     if ( !anInPort->IsDataConnected() ) {
       if ( first ) {
-        f << endl << "# Input Ports of the graph" << endl ;
+        f << "    " << endl << "    " << "# Input Ports of the graph" << endl ;
         first = false ;
       }
-      f << "#I" << aNodeName << aPortName << " = " << aNodeName << ".GetInPort( '"
+      f << "    " << "#I" << aNodeName << aPortName << " = " << aNodeName << ".GetInPort( '"
         << aPortName << "' )" << endl ;
     }
     delete [] aNodeName ;
     delete [] aPortName ;
   }
 
-  f << endl << "# Output Ports of the graph" << endl ;
+  f << "    " << endl << "    # Output Ports of the graph" << endl ;
   const SALOME_ModuleCatalog::ListOfServicesParameter ListOfOutParam = Graph()->ServiceOutParameter() ;
   for ( i = 0 ; i < (int ) ListOfOutParam.length() ; i++ ) {
     string _aParam = CORBA::string_dup(ListOfOutParam[ i ].Parametername) ;
@@ -1485,24 +1640,81 @@ bool GraphEditor::OutNode::SavePY( ostream & f ) {
     char * aPortName ;
     int j ;
     for ( j = 0 ; j < (int ) strlen( aParam ) ; j++ ) {
-      if ( aParam[ j ] == '\\' ) {
+//      if ( aParam[ j ] == '\\' ) {
+      if ( aParam[ j ] == '_' && aParam[ j+1 ] == '_' ) {
         aNodeName = new char[ j+1 ] ;
         strncpy( aNodeName , aParam , j ) ;
         aNodeName[ j ] = '\0' ;
-        aPortName = new char[ strlen( aParam ) - j ] ;
-        strncpy( aPortName , &aParam[ j+1 ] , strlen( aParam ) - j ) ;
+        aPortName = new char[ strlen( aParam ) - j-1 ] ;
+        strncpy( aPortName , &aParam[ j+2 ] , strlen( aParam ) - j-1 ) ;
         break ;
       }
     }
-    f << "#O" << aNodeName << aPortName << " = " << aNodeName << ".GetOutPort( '"
+    f << "    " << "#O" << aNodeName << aPortName << " = " << aNodeName << ".GetOutPort( '"
       << aPortName << "' )" << endl ;
     delete [] aNodeName ;
     delete [] aPortName ;
   }
+
+  f << "    " << "return " << Graph()->Name() << endl << endl ;
+
+// RECURSIVE CREATION OF GRAPHS OF MACRONODES
+  for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
+    if ( Graph()->GraphNodes( i )->IsMacroNode() ) {
+      GraphBase::GOTONode * aMacroNode = (GraphBase::GOTONode * ) Graph()->GraphNodes( i ) ;
+      GraphBase::Graph * aMacroGraph = (GraphBase::Graph * ) aMacroNode->CoupledNode() ;
+      cdebug << "OutNode::SavePY ---> OutNode::SavePY( ostream & f ) MacroGraph " << aMacroGraph->Name() << endl ;
+      GraphEditor::DataFlow * aDataFlow = aMacroGraph->GraphEditor() ;
+      cdebug << "SavePY of the Graph " << aDataFlow->Graph() << " of the MacroNode "
+             << aMacroGraph->Name() << endl ;
+      if ( !aDataFlow->SavePY( f , false ) ) {
+        return false ;
+      }
+    }
+  }
+
+//  f << Graph()->Name() << " = " << Graph()->Name() << "()" << endl ;
+
   return true ;
 }
 
+/** Iterate through ALL links (OutPort-InPort pairs) and check if their types are 
+ *  compatible - call GraphEditor::DataFlow::IsCompatible(type1, type2).
+ *  Returns true if all are compatible.
+ */
+bool GraphEditor::OutNode::IsLinksCompatible() {
+  const GraphBase::ListOfSLinks * Links = Graph()->GetLinks( true ) ;
+  bool b = true;
+  for ( int i = 0 ; i < (int ) Links->size() && b ; i++ ) {
+    GraphBase::SLink aLink = (*Links)[i];
+    GraphBase::ComputingNode* anOutNode = Graph()->GetChangeGraphNode( aLink.FromNodeName.c_str() );
+    GraphBase::ComputingNode* anInNode = Graph()->GetChangeGraphNode( aLink.ToNodeName.c_str() );
+    const GraphBase::OutPort* anOutPort = anOutNode->GetOutPort( aLink.FromServiceParameterName.c_str() );
+    const GraphBase::InPort* anInPort = anInNode->GetInPort( aLink.ToServiceParameterName.c_str() );    
+    b = IsCompatible( anOutPort->PortType(), anInPort->PortType() );
+    cdebug << "GraphEditor::OutNode::IsLinksCompatible:  "<<aLink.FromNodeName << "("<<aLink.FromServiceParameterName
+      <<")  -->  "<<aLink.ToNodeName<<"("<<aLink.ToServiceParameterName<<") = " << (b ? "OK" : "Not compatible (ERROR)") << endl;
+    if ( !b )
+      MESSAGE( "Graph structure ERROR: type of port \""<<aLink.FromServiceParameterName<<"\" of node \""
+             <<aLink.FromNodeName<<"\" is not compatible with type of linked port \""
+             <<aLink.ToServiceParameterName<<"\" of node \""<<aLink.ToNodeName<<"\"" );
+  }
+  return b;
+}
 
+/**Returns true if an out-port of type "OutPortType" can be bound with in-port of type "InPortType". 
+ * Types: {"string", "boolean", "char", "short", "int", "long", "float", "double", "objref"};
+ * Currently considered compatible ALL types except for objref - they must match exactly
+ */
+bool GraphEditor::OutNode::IsCompatible( const char* OutPortType, const char* InPortType ) const {
+  bool ret = true;
+  string t1 = OutPortType;
+  string t2 = InPortType;
+  // if ANY is an objref - the other one must be objref as well
+  if ( ( t1 == "objref" || t2 == "objref" ) && t1 != t2 ) 
+    ret = false; 
+  return ret;
+}
 
 ostream & operator<< (ostream & f,const GraphEditor::OutNode & G) {
   f << (GraphBase::ComputingNode ) *(G.Graph()) ;
@@ -1554,10 +1766,27 @@ ostream & operator<< (ostream &fOut,const SUPERV::SDate &D)
   return fOut;
 }
 
+/*
+GraphBase::Graph * GraphEditor::OutNode::MapGraph( const char * aGraphName ) {
+  GraphBase::Graph * aGraph = _MapOfGraphs[ aGraphName ] ;
+  return aGraph ;
+}
 
+bool GraphEditor::OutNode::MapGraph( GraphBase::Graph * aGraph , const char * aGraphName ) {
+  if ( MapGraph( aGraphName ) ) {
+    return false ;
+  }
+  _MapOfGraphs[ aGraphName ] = aGraph ;
+  return true ;
+}
 
+void GraphEditor::OutNode::EraseGraph( const char * aGraphName ) {
+  _MapOfGraphs.erase( aGraphName ) ;
+}
 
-
-
+bool GraphEditor::OutNode::GraphName( const char * aGraphName ) {
+  return  _MapOfGraphNames[ aGraphName ] ;
+}
+*/