Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[modules/superv.git] / src / GraphBase / DataFlowBase_ComputingNode.cxx
index 4f04a806658b5bfd87aee99c32f59525d01b045d..cafe8512556b4e6437229d4ce2699ddf9cd5b304 100644 (file)
@@ -82,7 +82,8 @@ GraphBase::ComputingNode::ComputingNode() :
               //_SubGraphNumber ) ;
   Kind( SUPERV::DataFlowGraph ) ;
   _NamingService = NULL ;
-  _Node = SUPERV::CNode::_nil() ;
+  _Node_var = SUPERV::CNode::_nil() ;
+  _Node_Impl = NULL ;
   _InNode = NULL ;
   _ThreadNo = pthread_self() ;
   cdebug << "GraphBase::Node::Node "  << this << " "  << endl ;
@@ -92,10 +93,12 @@ GraphBase::ComputingNode::ComputingNode() :
 GraphBase::ComputingNode::ComputingNode( CORBA::ORB_ptr ORB ,
                                          SALOME_NamingService* ptrNamingService ,
                                          const char * aDataFlowName ,
+                                         const SUPERV::KindOfNode DataFlowkind ,
                                          int * Graph_prof_debug ,
                                          ofstream * Graph_fdebug ) :
 //  GraphBase::PortsOfNode::PortsOfNode( aDataFlowName ) {
-  GraphBase::StreamNode::StreamNode( aDataFlowName ) {
+  GraphBase::StreamNode::StreamNode( aDataFlowName , DataFlowkind ,
+                                     Graph_prof_debug , Graph_fdebug ) {
 
 //  MESSAGE( "GraphBase::ComputingNode::ComputingNode " << aDataFlowName << " Graph_prof_debug " << Graph_prof_debug ) ;
   InitFields( //_Kind ,
@@ -113,10 +116,12 @@ GraphBase::ComputingNode::ComputingNode( CORBA::ORB_ptr ORB ,
               //_LinkedNodesSize ,
               //_SubGraphNumber ) ;
 
-  Kind( SUPERV::DataFlowGraph ) ;
+//  Kind( SUPERV::DataFlowGraph ) ;
+  Kind( DataFlowkind ) ;
   _ORB = CORBA::ORB::_duplicate( ORB ) ;
   _NamingService = ptrNamingService ;
-  _Node = SUPERV::CNode::_nil() ;
+  _Node_var = SUPERV::CNode::_nil() ;
+  _Node_Impl = NULL ;
   _InNode = NULL ;
   _ThreadNo = pthread_self() ;
 
@@ -130,6 +135,7 @@ GraphBase::ComputingNode::ComputingNode( CORBA::ORB_ptr ORB ,
 //  else {
 //    cout << "GraphBase::ComputingNode::ComputingNode NO SetDebug" << endl ;
 //  }
+  DefPortsOfNode( ORB , SALOME_ModuleCatalog::Service() , NamePtr() , Kind() , Graph_prof_debug , Graph_fdebug ) ;
   cdebug << "GraphBase::ComputingNode::ComputingNode "  << this 
          << " Name '" << Name() << "' "  << _FirstCreation
          << " "  << _LastModification << endl ;
@@ -151,11 +157,12 @@ GraphBase::ComputingNode::ComputingNode( CORBA::ORB_ptr ORB ,
                                          int * Graph_prof_debug ,
                                          ofstream * Graph_fdebug ) :
 //  GraphBase::PortsOfNode::PortsOfNode() {
-  GraphBase::StreamNode::StreamNode( NodeName ) {
+  GraphBase::StreamNode::StreamNode( NodeName , akind , Graph_prof_debug , Graph_fdebug ) {
 
   _ORB = CORBA::ORB::_duplicate( ORB ) ;
   _NamingService = ptrNamingService ;
-  _Node = SUPERV::CNode::_nil() ;
+  _Node_var = SUPERV::CNode::_nil() ;
+  _Node_Impl = NULL ;
   _InNode = NULL ;
   _ThreadNo = pthread_self() ;
 
@@ -304,31 +311,42 @@ void GraphBase::ComputingNode::NodePort( const char * NodeName ,
     *aPort = my_strdup( ServiceParameterName ) ;
   }
   else {
-    char * BPort = strchr( ServiceParameterName , '\\' ) ;
-    if ( BPort ) {
-      int len = BPort - ServiceParameterName ;
-      *aNode = new char [ len + 1 ] ;
-      strncpy( *aNode , ServiceParameterName , len ) ;
-      (*aNode)[ len ] = '\0' ;
-      *aPort = my_strdup( &BPort[ 1 ] ) ;
+//    char * BPort = strchr( ServiceParameterName , '\\' ) ;
+    char * BPort = (char * ) ServiceParameterName ;
+    while ( ( BPort = strchr( BPort , '_' ) ) ) {
+      if ( BPort[1] == '_' ) {
+        int len = BPort - ServiceParameterName ;
+        *aNode = new char [ len + 1 ] ;
+        strncpy( *aNode , ServiceParameterName , len ) ;
+        (*aNode)[ len ] = '\0' ;
+        *aPort = my_strdup( &BPort[ 2 ] ) ;
+        break ;
+      }
+      else {
+        BPort = &BPort[2] ;
+      }
     }
-    else {
+    if ( BPort == NULL ) {
       *aNode = my_strdup( NULLSTRING ) ;
       *aPort = my_strdup( NULLSTRING ) ;
     }
   }
 }
 
-bool GraphBase::ComputingNode::IsLinked(const char * ToServiceParameterName ) {
+bool GraphBase::ComputingNode::IsLinked(const char * ToServiceParameterName, bool isInput ) {
   bool RetVal = false ;
-  const GraphBase::InPort * thePort = GetInPort( ToServiceParameterName ) ;
-  if ( thePort ) {
-    RetVal = thePort->IsConnected() ;
+  if ( isInput ) { // mkr : PAL8060
+    // we have to know the type of the port, because of input and output ports 
+    // belong to one node may have the same names
+    const GraphBase::InPort * thePort = GetInPort( ToServiceParameterName ) ;
+    if ( thePort ) {
+      RetVal = thePort->IsPortConnected() ;
+    }
   }
   else {
     const GraphBase::OutPort * thePort = GetOutPort( ToServiceParameterName ) ;
     if ( thePort ) {
-      RetVal = thePort->IsConnected() ;
+      RetVal = thePort->IsPortConnected() ;
     }
   }
   return RetVal ;
@@ -336,20 +354,14 @@ bool GraphBase::ComputingNode::IsLinked(const char * ToServiceParameterName ) {
 
 bool GraphBase::ComputingNode::HasInput(const char * ToServiceParameterName ) {
   bool RetVal = false ;
-  const GraphBase::InPort * thePort = GetInPort( ToServiceParameterName ) ;
-  if ( IsDataFlowNode() && thePort ) {
-    RetVal = true ;
-  }
-  else if ( thePort ) {
-//    cout << "GraphBase::ComputingNode::HasInput theInPort " << thePort << " " << thePort->PortName() << " of "
-//         << thePort->NodeName() << " IsDataConnected " << thePort->IsDataConnected() << " OutPort "
-//         << thePort->GetOutPort() << endl ;
-    RetVal = thePort->IsDataConnected() ;
+  const GraphBase::InPort * theInPort = GetInPort( ToServiceParameterName ) ;
+  if ( theInPort ) {
+    RetVal = theInPort->IsDataConnected() ;
   }
   else {
-    const GraphBase::OutPort * thePort = GetOutPort( ToServiceParameterName ) ;
-    if ( thePort ) {
-      RetVal = thePort->IsDataConnected() ;
+    const GraphBase::OutPort * theOutPort = GetOutPort( ToServiceParameterName ) ;
+    if ( theOutPort ) {
+      RetVal = theOutPort->IsDataConnected() ;
     }
   }
   return RetVal ;
@@ -363,9 +375,9 @@ GraphBase::SNode * GraphBase::ComputingNode::GetInfo() {
   Info->theName = Name() ;
   Info->theKind = Kind() ;
   if ( IsDataStreamNode() ) {
-    long Timeout ;
+    CORBA::Long Timeout ;
     SUPERV::KindOfDataStreamTrace DataStreamTrace ;
-    double DeltaTime ;
+    CORBA::Double DeltaTime ;
     ((GraphBase::StreamGraph * ) this)->StreamParams( Timeout , DataStreamTrace , DeltaTime ) ;
     Info->theTimeout = Timeout ;
     Info->theDataStreamTrace = DataStreamTrace ;
@@ -385,35 +397,432 @@ GraphBase::SNode * GraphBase::ComputingNode::GetInfo() {
   return Info ;
 }
 
+void GraphBase::ComputingNode::SetMacroPorts( GraphBase::Graph * aGraph ) {
+  cdebug_in << "GraphBase::ComputingNode::SetMacroPorts fill ports of MacroNode" << endl;
+  int i ;
+  for ( i = 0 ; i < aGraph->GetNodeInPortsSize() ; i++ ) {
+    const GraphBase::InPort * anInPort = aGraph->GetNodeInPort( i ) ;
+    cdebug << "SetMacroPorts In" << i << " " << anInPort->PortName() << " " << anInPort->PortType()
+           << " " << anInPort->Kind() << endl ;
+    GraphBase::InPort * aNewInPort ;
+    if ( anInPort->IsDataStream() ) {
+      aNewInPort = AddInDataStreamPort( anInPort->PortName() , StringToDataStreamType( anInPort->PortType() ) ,
+                                        anInPort->Dependency() , anInPort->Kind() ) ;
+    }
+    else if ( anInPort->IsParam() || anInPort->IsInLine() ) {
+      aNewInPort = AddInPort( anInPort->PortName() , anInPort->PortType() , anInPort->Kind() ) ;
+    }
+  }
+  for ( i = 0 ; i < aGraph->GetNodeOutPortsSize() ; i++ ) {
+    const GraphBase::OutPort * anOutPort = aGraph->GetNodeOutPort( i ) ;
+    cdebug << "SetMacroPorts Out" << i << " " << anOutPort->PortName() << " " << anOutPort->PortType()
+           << " " << anOutPort->Kind() << endl ;
+    if ( anOutPort->IsDataStream() ) {
+      AddOutDataStreamPort( anOutPort->PortName() , StringToDataStreamType( anOutPort->PortType() ) ,
+                            anOutPort->Dependency() , anOutPort->Kind() ) ;
+    }
+    else if ( anOutPort->IsParam() || anOutPort->IsInLine() ) {
+      AddOutPort( anOutPort->PortName() , anOutPort->PortType() , anOutPort->Kind() ) ;
+    }
+  }
+  cdebug_out << "GraphBase::ComputingNode::SetMacroPorts" << endl;
+}
+
+void GraphBase::ComputingNode::UpdateMacroPorts( GraphBase::Graph * aGraph ) {
+  cdebug_in << "GraphBase::ComputingNode::UpdateMacroPorts fill ports of MacroNode from "
+            << aGraph->Name() << " InPorts(" << aGraph->GetNodeInPortsSize() << ") OutPorts("
+            << aGraph->GetNodeInPortsSize() << ") to MacroNode " << Name() << " InPorts(" << GetNodeInPortsSize()
+            << ") OutPorts(" << GetNodeInPortsSize() << ")" << endl;
+  cdebug << Name() << " : " << *GetService() << endl ;
+  cdebug << aGraph->Name() << " : " << *aGraph->GetService() << endl ;
+  int i ;
+// Loop over InPorts of MacroNode ; if it does not exist in the MacroGraph ===> DelInPort in the MacroNode
+  for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
+    GraphBase::InPort * anInPort = aGraph->GetChangeInPort( GetNodeInPort( i )->PortName() ) ;
+    if ( anInPort && !anInPort->IsGate() && !GetNodeInPort( i )->IsGate() ) {
+      if ( strcmp( GetNodeInPort( i )->PortType() , anInPort->PortType() ) ) {
+        cdebug << Name() << " " << GetNodeInPort( i )->PortName() << " " << GetNodeInPort( i )->PortType()
+               << " " << GetNodeInPort( i )->Kind() << " " << GetNodeInPort( i )->Dependency() << endl ;
+        cdebug << "  <--> " << aGraph->Name() << " " << anInPort->PortName() << " " << anInPort->PortType()
+               << " " << anInPort->Kind() << " " << anInPort->Dependency() << endl ;
+        GetChangeNodeInPort( i )->PortType( (char * ) anInPort->PortType() ) ;
+      }
+      if ( GetNodeInPort( i )->Kind() != anInPort->Kind() ) {
+        cdebug << Name() << " " << GetNodeInPort( i )->PortName() << " " << GetNodeInPort( i )->PortType()
+               << " " << GetNodeInPort( i )->Kind() << " " << GetNodeInPort( i )->Dependency() << endl ;
+        cdebug << "  <--> " << aGraph->Name() << " " << anInPort->PortName() << " " << anInPort->PortType()
+               << " " << anInPort->Kind() << " " << anInPort->Dependency() << endl ;
+        GetChangeNodeInPort( i )->Kind( anInPort->Kind() ) ;
+      }
+      if ( GetNodeInPort( i )->Dependency() != anInPort->Dependency() ) {
+        cdebug << Name() << " " << GetNodeInPort( i )->PortName() << " " << GetNodeInPort( i )->PortType()
+               << " " << GetNodeInPort( i )->Kind() << " " << GetNodeInPort( i )->Dependency() << endl ;
+        cdebug << "  <--> " << aGraph->Name() << " " << anInPort->PortName() << " " << anInPort->PortType()
+               << " " << anInPort->Kind() << " " << anInPort->Dependency() << endl ;
+        GetChangeNodeInPort( i )->Dependency( anInPort->Dependency() ) ;
+      }
+    }
+    else if ( !GetNodeInPort( i )->IsGate() ) {
+      cdebug << "UpdateMacroPorts DelInPort In" << i << " " << GetNodeInPort( i )->PortName() << " "
+             << GetNodeInPort( i )->PortType() << " " << GetNodeInPort( i )->Kind() << endl ;
+      DelInPort( GetNodeInPort( i )->PortName() ) ;
+      i--; // mkr : fix for bug PAL8004
+    }
+  }
+  int index ;
+// Loop over InPorts of the MacroGraph : if it does not exist in the MacroNode ==> AddInPort in the MacroNode
+  for ( index = 0 ; index < aGraph->GetNodeInPortsSize() ; index++ ) {
+    GraphBase::InPort * anInPort = aGraph->GetChangeNodeInPort( index ) ;
+    GraphBase::InPort * aMacroInPort = GetChangeInPort( anInPort->PortName() ) ;
+    if ( !anInPort->IsGate() &&
+         strcmp( GetChangeNodeInPort( index )->PortName() , anInPort->PortName() ) ) {
+      cdebug << "UpdateMacroPorts Add/MoveInPort In" << index << " " << anInPort->PortName() << " "
+             << anInPort->PortType() << " " << anInPort->Kind() << endl ;
+      if ( aMacroInPort ) {
+        MoveInPort( anInPort->PortName() , index ) ;
+      }
+      else {
+        AddInPort( anInPort->PortName() , anInPort->PortType() , anInPort->Kind() , index ) ;
+      }
+    }
+  }
+// Loop over OutPorts of MacroNode ; if it does not exist in the MacroGraph ===> DelOutPort in the MacroNode
+  for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
+    GraphBase::OutPort * anOutPort = aGraph->GetChangeOutPort( GetNodeOutPort( i )->PortName() ) ;
+    if ( anOutPort && !anOutPort->IsGate() && !GetNodeOutPort( i )->IsGate() ) {
+      if ( strcmp( GetNodeOutPort( i )->PortType() , anOutPort->PortType() ) ) {
+        cdebug << Name() << " " << GetNodeOutPort( i )->PortName() << " " << GetNodeOutPort( i )->PortType()
+               << " " << GetNodeOutPort( i )->Kind() << " " << GetNodeOutPort( i )->Dependency() << endl ;
+        cdebug << "  <--> " << aGraph->Name() << " " << anOutPort->PortName() << " " << anOutPort->PortType()
+               << " " << anOutPort->Kind() << " " << anOutPort->Dependency() << endl ;
+        GetChangeNodeOutPort( i )->PortType( (char * ) anOutPort->PortType() ) ;
+      }
+      if ( GetNodeOutPort( i )->Kind() != anOutPort->Kind() ) {
+        cdebug << Name() << " " << GetNodeOutPort( i )->PortName() << " " << GetNodeOutPort( i )->PortType()
+               << " " << GetNodeOutPort( i )->Kind() << " " << GetNodeOutPort( i )->Dependency() << endl ;
+        cdebug << "  <--> " << aGraph->Name() << " " << anOutPort->PortName() << " " << anOutPort->PortType()
+               << " " << anOutPort->Kind() << " " << anOutPort->Dependency() << endl ;
+        GetChangeNodeOutPort( i )->Kind( anOutPort->Kind() ) ;
+      }
+      if ( GetNodeOutPort( i )->Dependency() != anOutPort->Dependency() ) {
+        cdebug << Name() << " " << GetNodeOutPort( i )->PortName() << " " << GetNodeOutPort( i )->PortType()
+               << " " << GetNodeOutPort( i )->Kind() << " " << GetNodeOutPort( i )->Dependency() << endl ;
+        cdebug << "  <--> " << aGraph->Name() << " " << anOutPort->PortName() << " " << anOutPort->PortType()
+               << " " << anOutPort->Kind() << " " << anOutPort->Dependency() << endl ;
+        GetChangeNodeOutPort( i )->Dependency( anOutPort->Dependency() ) ;
+      }
+    }
+    else if ( !GetNodeOutPort( i )->IsGate() ) {
+      cdebug << "UpdateMacroPorts DelOutPort Out" << i << " " << GetNodeOutPort( i )->PortName() << " "
+             << GetNodeOutPort( i )->PortType() << " " << GetNodeOutPort( i )->Kind() << endl ;
+      DelOutPort( GetNodeOutPort( i )->PortName() ) ;
+    }
+  }
+// Loop over OutPorts of the MacroGraph : if it does not exist in the MacroNode ==> AddOutPort in the MacroNode
+  for ( index = 0 ; index < aGraph->GetNodeOutPortsSize() ; index++ ) {
+    GraphBase::OutPort * anOutPort = aGraph->GetChangeNodeOutPort( index ) ;
+    GraphBase::OutPort * aMacroOutPort = GetChangeOutPort( anOutPort->PortName() ) ;
+    if ( !anOutPort->IsGate() && strcmp( GetNodeOutPort( index )->PortName() , anOutPort->PortName() ) ) {
+      cdebug << "UpdateMacroPorts Add/MoveOutPort Out" << index << " " << anOutPort->PortName() << " "
+             << anOutPort->PortType() << " " << anOutPort->Kind() << endl ;
+      if ( aMacroOutPort ) {
+        MoveOutPort( anOutPort->PortName() , index ) ;
+      }
+      else {
+        AddOutPort( anOutPort->PortName() , anOutPort->PortType() , anOutPort->Kind() , index ) ;
+      }
+    }
+  }
+  bool ErrPort = false ;
+  if ( aGraph->GetNodeInPortsSize() != GetNodeInPortsSize() ||
+       aGraph->GetNodeOutPortsSize() != GetNodeOutPortsSize() ) {
+    ErrPort = true ;
+  }
+  for ( i = 0 ; i < aGraph->GetNodeInPortsSize() && i < GetNodeInPortsSize() ; i++ ) {
+    if ( !strcmp( aGraph->GetNodeInPort( i )->PortName() , GetNodeInPort( i )->PortName() ) ) {
+      ErrPort = true ;
+    }
+  }
+  for ( i = 0 ; i < aGraph->GetNodeOutPortsSize() && i < GetNodeOutPortsSize() ; i++ ) {
+    if ( !strcmp( aGraph->GetNodeOutPort( i )->PortName() , GetNodeOutPort( i )->PortName() ) ) {
+      ErrPort = true ;
+    }
+  }
+  if ( ErrPort ) {
+    for ( i = 0 ; i < aGraph->GetNodeInPortsSize() || i < GetNodeInPortsSize() ; i++ ) {
+      if ( i < aGraph->GetNodeInPortsSize() && i < GetNodeInPortsSize() ) {
+        cdebug << "ComputingNode::UpdateMacroPorts In" << i << " " << aGraph->GetNodeInPort( i )->PortName()
+               << "  " << GetNodeInPort( i )->PortName() << endl ;
+      }
+      else if ( i >= GetNodeInPortsSize() ) {
+        cdebug << "ComputingNode::UpdateMacroPorts In" << i << " " << aGraph->GetNodeInPort( i )->PortName()
+               << endl ;
+      }
+      else {
+        cdebug << "ComputingNode::UpdateMacroPorts In" << i << " " << GetNodeInPort( i )->PortName()
+               << endl ;
+      }
+    }
+    for ( i = 0 ; i < aGraph->GetNodeOutPortsSize() || i < GetNodeOutPortsSize() ; i++ ) {
+      if ( i < aGraph->GetNodeOutPortsSize() && i < GetNodeOutPortsSize() ) {
+        cdebug << "ComputingNode::UpdateMacroPorts Out" << i << " " << aGraph->GetNodeOutPort( i )->PortName()
+               << " != " << GetNodeOutPort( i )->PortName() << endl ;
+      }
+      else if ( i >= GetNodeOutPortsSize() ) {
+        cdebug << "ComputingNode::UpdateMacroPorts Out" << i << " " << aGraph->GetNodeOutPort( i )->PortName()
+               << endl ;
+      }
+      else {
+        cdebug << "ComputingNode::UpdateMacroPorts Out" << i << " " << GetNodeOutPort( i )->PortName()
+               << endl ;
+      }
+    }
+  }
+  cdebug_out << "GraphBase::ComputingNode::UpdateMacroPorts"
+             << aGraph->Name() << " InPorts(" << aGraph->GetNodeInPortsSize() << ") OutPorts("
+             << aGraph->GetNodeOutPortsSize() << ") to MacroNode " << Name() << " InPorts("
+             << GetNodeInPortsSize() << ") OutPorts(" << GetNodeOutPortsSize() << ")" << endl;
+}
+
+void GraphBase::ComputingNode::SetMacroDatas( GraphBase::Graph * aGraph ,
+                                              GraphBase::Graph * aGraphOfMacroGraph ) {
+  cdebug_in << "GraphBase::ComputingNode::SetMacroDatas fill inputs of MacroNode" << endl;
+  int i ;
+  for ( i = 0 ; i < aGraph->GetNodeInPortsSize() ; i++ ) {
+    const GraphBase::InPort * anInPort = aGraph->GetNodeInPort( i ) ;
+    GraphBase::OutPort * anOutPort = aGraph->GetChangeNodeInDataNodePort(i) ;
+    cdebug << "                 " << Name() << " " << anOutPort->PortName() << " " << anOutPort->PortType()
+           << " " << anOutPort->Kind() << " " << anOutPort->PortStatus() << endl ;
+    if ( anOutPort->IsDataConnected() ) {
+//JR 30.03.2005      aGraphOfMacroGraph->AddInputData( Name() , anInPort->PortName() , *(anOutPort->Value()) ) ;
+      aGraphOfMacroGraph->AddInputData( Name() , anInPort->PortName() , anOutPort->Value() ) ;
+      anOutPort->PortStatus( ExternConnected ) ;
+    }
+  }
+  cdebug_out << "GraphBase::ComputingNode::SetMacroDatas" << endl;
+}
+
 void GraphBase::ComputingNode::DelInPort( const char * InputParameterName ) {
+//PAL9122
+//JR 07.06.2005 Debug : LinkedNodes and LinkedFromNode must be updated
+//                      LinkedInPortsNumber and LinkedFromInPortsNumber must be updated
+  cdebug_in << "ComputingNode::DelInPort " << Name() << "( " << InputParameterName << " )"
+             << endl;
+  bool RetVal = true ;
+  if ( !IsEndSwitchNode() ) {
+    GraphBase::InPort * anInPort = GetChangeInPort( InputParameterName ) ;
+    cdebug << "ComputingNode::DelInPort InPort " << Name() << "( "
+           << anInPort->PortName() << " ) " << anInPort->PortStatus() << " <-- " ;
+    GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
+    if ( anOutPort && !( IsEndLoopNode() && anInPort->IsLoop() ) ) {
+      cdebug << anOutPort->NodeName() << "( " << anOutPort->PortName() << ") "
+             << anOutPort->PortStatus() ;
+    }
+    cdebug << endl ;
+    if ( !anInPort->IsNotConnected() ) {
+      GraphBase::ComputingNode * FromNode = NULL ;
+      RetVal = true ;
+      if ( anOutPort->IsDataConnected() || anOutPort->IsExternConnected() ) {
+        cdebug << "     Data/Extern ignored" << endl ;
+      }
+      else {
+        FromNode = GraphOfNode()->GetChangeGraphNode( anOutPort->NodeName() ) ;
+      }
+      if ( FromNode ) {
+        cdebug << "FromNode " << FromNode->Name() << " LinkedNodesSize "
+               << FromNode->LinkedNodesSize() << " and " << Name()
+               << " LinkedFromNodesSize " << LinkedFromNodesSize() << endl ;
+        if ( !FromNode->IsGOTONode() &&
+             !( FromNode->IsEndLoopNode() && anInPort->IsLoop() ) ) {
+          if ( anInPort->IsDataStream() ) {
+            RetVal = FromNode->RemoveStreamLinkedNode( this ) ;
+          }
+          else {
+            RetVal = FromNode->RemoveLinkedNode( this ) ;
+         }
+          if ( !RetVal ) {
+            cdebug << "ComputingNode::DelInPort anOutPort->RemoveLinkedNode Error RetVal "
+                   << RetVal << endl ;
+         }
+       }
+      }
+    }
+  }
+//We have an EndSwitchNode :
+  else {
+    int i ;
+    for ( i = LinkedFromNodesSize() - 1 ; i >= 0  ; i-- ) {
+      GraphBase::ComputingNode * aLinkedFromNode = (GraphBase::ComputingNode * ) LinkedFromNodes( i ) ;
+      cdebug << aLinkedFromNode->Name() << " linked to " << Name() << endl ;
+      int j ;
+      for ( j = aLinkedFromNode->GetNodeOutPortsSize() - 1 ; j >= 0 ; j-- ) {
+        GraphBase::OutPort * anOutPort = aLinkedFromNode->GetChangeNodeOutPort( j ) ;
+        cdebug << "ComputingNode::DelInPort OutPort" << j << ". Remove " << anOutPort->InPortsSize()
+               << " InPortsof OutPort : " << anOutPort->NodeName() << "( "
+               << anOutPort->PortName() << ") "
+               << anOutPort->PortStatus() << " :" << endl ;
+        int k ;
+//Process concerned OutPorts of LinkedFromNodes of that EndSwitchNode
+        for ( k = anOutPort->InPortsSize() - 1 ; k >= 0  ; k-- ) {
+          GraphBase::InPort * anInPort = anOutPort->ChangeInPorts( k ) ;
+          if ( !strcmp( anInPort->NodeName() , Name() ) &&
+               !strcmp( anInPort->PortName() , InputParameterName ) ) {
+// InPort of the EndSwitchNode
+            cdebug << "       to InPort" << j << ". " << anInPort->NodeName() << "( "
+                   << anInPort->PortName() << ") "
+                   << anInPort->PortStatus() << endl ;
+            anInPort->RemoveOutPort() ;
+            if ( anOutPort->IsDataStream() ) {
+              aLinkedFromNode->RemoveStreamLinkedNode( this ) ;
+           }
+            else {
+// false ==> No error for aNode->LinkedFromNode()
+              RetVal = aLinkedFromNode->RemoveLinkedNode( this , false ) ;
+              if ( !RetVal ) {
+                cdebug << "ComputingNode::DelInPort aLinkedFromNode->RemoveLinkedNode Error RetVal "
+                       << RetVal << endl ;
+                break ;
+             }
+           }
+// Remove the InPort of the EndSwitchNode from that OutPort
+            RetVal = anOutPort->RemoveInPort( anInPort ) ;
+            if ( !RetVal ) {
+              cdebug << "ComputingNode::DelInPort anOutPort->RemoveInPort( anInPort ) Error RetVal "
+                     << RetVal << endl ;
+              break ;
+           }
+         }
+       }
+      }
+    }
+  }
+
   GraphBase::PortsOfNode::DelInPort( InputParameterName ) ;
+  cdebug_out << "ComputingNode::DelInPort " << Name() << "( " << InputParameterName << " )"
+             << endl;
 }
 void GraphBase::ComputingNode::DelOutPort( const char * OutputParameterName ) {
+//PAL9122
+//JR 07.06.2005 Debug : LinkedNodes and LinkedFromNode must be updated
+//                      LinkedInPortsNumber and LinkedFromInPortsNumber must be updated
+  cdebug_in << "ComputingNode::DelOutPort " << Name() << "( " << OutputParameterName << " )"
+            << endl;
+  bool RetVal = true ;
+  GraphBase::OutPort * anOutPort = GetChangeOutPort( OutputParameterName ) ;
+  cdebug << "ComputingNode::DelOutPort OutPort " << " InPortof OutPort : "
+         << anOutPort->NodeName() << "( " << anOutPort->PortName() << ") "
+         << anOutPort->PortStatus() << " :" << endl ;
+  int j ;
+  for ( j = anOutPort->InPortsSize() - 1 ; j >= 0  ; j-- ) {
+    GraphBase::InPort * anInPort = anOutPort->ChangeInPorts( j ) ;
+    GraphBase::ComputingNode * ToNode = NULL ;
+    cdebug << "       to InPort" << j << ". " << anInPort->NodeName() << "( "
+           << anInPort->PortName() << ") " << anInPort->PortStatus() ;
+    if ( anInPort->IsExternConnected() ) {
+      cdebug << " ExternConnected ignored" << endl ;
+    }
+    else {
+      cdebug << endl ;
+      ToNode = GraphOfNode()->GetChangeGraphNode( anInPort->NodeName() ) ;
+    }
+    if ( ToNode ) {
+      RetVal = anInPort->RemoveOutPort() ;
+// JR 04.02.2005 : Bug if it is a link to an EndSwitchNode. The InPort may be multiple linked !!!
+// PAL7990
+      if ( !RetVal ) {
+        cdebug << "ComputingNode::DelOutPort anOutPort->RemoveOutPort Error RetVal " << RetVal
+               << endl ;
+        break ;
+      }
+      if ( ( IsGOTONode() && ToNode->IsOneOfInLineNodes() ) ||
+           ( IsEndLoopNode() && ToNode->IsLoopNode( ) ) ) {
+      }
+      else if ( anOutPort->IsDataStream() ) {
+        RetVal = RemoveStreamLinkedNode( ToNode ) ;
+      }
+      else {
+        RetVal = RemoveLinkedNode( ToNode ) ;
+      }
+      if ( !RetVal ) {
+        cdebug << "ComputingNode::DelOutPort anOutPort->RemoveLinkedNode Error RetVal " << RetVal
+               << endl ;
+        break ;
+      }
+      if ( ToNode->IsEndSwitchNode() ) {
+        int i ;
+        int done = false ;
+        for ( i = 0 ; i < ToNode->LinkedFromNodesSize() ; i++ ) {
+          GraphBase::StreamNode * fromNode = ToNode->LinkedFromNodes( i ) ;
+// Not the node that we are deleting ... :
+          if ( strcmp( fromNode->Name() , Name() ) ) {
+            int j ;
+            for ( j = 0 ; j < fromNode->GetNodeOutPortsSize() ; j++ ) {
+              GraphBase::OutPort * fromOutPort = fromNode->GetChangeNodeOutPort( j ) ;
+              int k ;
+              for ( k = 0 ; k < fromOutPort->InPortsSize() ; k++ ) {
+                if ( strcmp( ToNode->Name() , fromOutPort->InPorts( k )->NodeName() ) == 0 ) {
+                  if ( strcmp( anInPort->PortName() , fromOutPort->InPorts( k )->PortName() ) == 0 ) {
+// Restore an OutPort in the InPort
+                    anInPort->ChangeOutPort( fromOutPort ) ;
+                    cdebug << "ComputingNode::DelOutPort reestablish " << fromOutPort->NodeName() << "( "
+                           << fromOutPort->PortName() << " ) in the InPort of EndSwitch : "
+                           << ToNode->Name() << "( " << anInPort->PortName() << " )"
+                           << anInPort->Kind() << " " << anInPort->PortStatus()  << endl;
+                    done = true ;
+                    break ;
+                 }
+               }
+             }
+              if ( done ) {
+                break ;
+             }
+           }
+            if ( done ) {
+              break ;
+           }
+         }
+       }
+      }
+    }
+  }
+  if ( !RetVal ) {
+    cdebug << "Error RetVal " << RetVal << endl ;
+  }
+
   GraphBase::PortsOfNode::DelOutPort( OutputParameterName ) ;
+  cdebug_out << "ComputingNode::DelOutPort " << Name() << "( " << OutputParameterName << " )"
+             << endl;
 }
 
 GraphBase::InPort * GraphBase::ComputingNode::AddInPort( const char * InputParameterName ,
                                                          const char * InputParameterType ,
-                                                         const SUPERV::KindOfPort aKindOfPort ) {
+                                                         const SUPERV::KindOfPort aKindOfPort ,
+                                                         int index ) {
   cdebug << "AddInPort " << Name() << " ConnectedInPortsNumber " << ConnectedInPortsNumber() << endl ;
+// JR 12.01.2005 : InitLoop and DoLoop are reserved parameter names in LoopNodes :
+  if ( IsLoopNode() && ( strcmp( InputParameterName , "InitLoop" ) == 0 ||
+                         strcmp( InputParameterName , "DoLoop" ) == 0 ) ) {
+    return NULL ;
+  }
   return GraphBase::PortsOfNode::AddInPort( _ORB , NamePtr() ,
                                             Kind() ,
                                             InputParameterName ,
                                             InputParameterType ,
                                             aKindOfPort ,
-//                                            DataStreamInPortsNumber() ,
+                                            index ,
                                             _Graph_prof_debug , _Graph_fdebug ) ;
 }
 GraphBase::OutPort * GraphBase::ComputingNode::AddOutPort( const char * OutputParameterName ,
                                                            const char * OutputParameterType ,
-                                                           const SUPERV::KindOfPort aKindOfPort ) {
+                                                           const SUPERV::KindOfPort aKindOfPort ,
+                                                           int index ) {
   cdebug << "AddOutPort " << Name() << " ConnectedInPortsNumber " << ConnectedInPortsNumber() << endl ;
   return GraphBase::PortsOfNode::AddOutPort( _ORB , NamePtr() ,
                                              Kind() ,
                                              OutputParameterName ,
                                              OutputParameterType ,
                                              aKindOfPort ,
-//                                             DataStreamOutPortsNumber() ,
+                                             index ,
                                              _Graph_prof_debug , _Graph_fdebug ) ;
 }
 
@@ -427,7 +836,8 @@ void GraphBase::ComputingNode::DelOutDataStreamPort( const char * OutputParamete
 GraphBase::InDataStreamPort * GraphBase::ComputingNode::AddInDataStreamPort( const char * InputParameterName ,
                                                                              const SALOME_ModuleCatalog::DataStreamType InputParameterType ,
                                                                              const SALOME_ModuleCatalog::DataStreamDependency aDependency ,
-                                                                             const SUPERV::KindOfPort aKindOfPort ) {
+                                                                             const SUPERV::KindOfPort aKindOfPort ,
+                                                                             int index ) {
 //  IncrDataStreamInPorts() ;
   GraphBase::InDataStreamPort * aDataStreamPort ;
   aDataStreamPort = (GraphBase::InDataStreamPort * ) GraphBase::PortsOfNode::AddInPort( _ORB , NamePtr() ,
@@ -435,8 +845,9 @@ GraphBase::InDataStreamPort * GraphBase::ComputingNode::AddInDataStreamPort( con
                                                                                         InputParameterName ,
                                                                                         DataStreamTypeToString( InputParameterType ).c_str() ,
                                                                                         aKindOfPort ,
-//                                                                                        DataStreamInPortsNumber() ,
-                                                                                        _Graph_prof_debug , _Graph_fdebug ) ;
+                                                                                        index ,
+                                                                                        _Graph_prof_debug ,
+                                                                                        _Graph_fdebug ) ;
   aDataStreamPort->Dependency( aDependency ) ;
   if ( aDependency == SALOME_ModuleCatalog::DATASTREAM_TEMPORAL ) {
     aDataStreamPort->SetParams( SUPERV::TI , SUPERV::L1 , SUPERV::EXTRANULL ) ;
@@ -446,7 +857,8 @@ GraphBase::InDataStreamPort * GraphBase::ComputingNode::AddInDataStreamPort( con
 GraphBase::OutDataStreamPort * GraphBase::ComputingNode::AddOutDataStreamPort( const char * OutputParameterName ,
                                                                                const SALOME_ModuleCatalog::DataStreamType OutputParameterType ,
                                                                                const SALOME_ModuleCatalog::DataStreamDependency aDependency ,
-                                                                               const SUPERV::KindOfPort aKindOfPort ) {
+                                                                               const SUPERV::KindOfPort aKindOfPort ,
+                                                                               int index ) {
 //  IncrDataStreamOutPorts() ;
   GraphBase::OutDataStreamPort * aDataStreamPort ;
   aDataStreamPort = (GraphBase::OutDataStreamPort * ) GraphBase::PortsOfNode::AddOutPort( _ORB , NamePtr() ,
@@ -454,13 +866,204 @@ GraphBase::OutDataStreamPort * GraphBase::ComputingNode::AddOutDataStreamPort( c
                                                                                           OutputParameterName ,
                                                                                           DataStreamTypeToString( OutputParameterType ).c_str() ,
                                                                                           aKindOfPort ,
-//                                                                                          DataStreamOutPortsNumber() ,
-                                                                                          _Graph_prof_debug , _Graph_fdebug ) ;
+                                                                                          index ,
+                                                                                          _Graph_prof_debug ,
+                                                                                          _Graph_fdebug ) ;
   aDataStreamPort->Dependency( aDependency ) ;
   return aDataStreamPort ;
 }
 
 
+bool GraphBase::ComputingNode::CheckLoop( GraphBase::LoopNode * aLoopNode ,
+                                          GraphBase::EndOfLoopNode * anEndLoopNode ,
+                                          string & anErrorMessage ) const {
+  cdebug_in << Name() << "->ComputingNode::CheckLoop( " << aLoopNode->Name() << " , "
+            << anEndLoopNode->Name() << ") LinkedNodesSize "
+            << LinkedNodesSize() << endl;
+
+  int i ;
+  if ( LinkedNodesSize() == 0 && !IsDataFlowNode() && !IsDataStreamNode() ) {
+    anErrorMessage = anErrorMessage + string( "The node " ) + string( Name() ) +
+                     string( " has no linked Nodes. Loop not valid\n" ) ;
+    cdebug_out << Name() << "->ComputingNode::CheckLoop( " << aLoopNode->Name()
+               << " , " << anEndLoopNode->Name() << ") LinkedNodesSize "
+               << LinkedNodesSize() << " ERROR false" << endl;
+    return false ;
+  }
+// We check that all nodes linked to that node go to the end of LoopNode :
+  for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
+    GraphBase::ComputingNode * aNode = (GraphBase::ComputingNode * ) LinkedNodes( i ) ;
+    cdebug << i << ". " << Name() << " Linked to " << aNode->Name() << endl ;
+    if ( !aNode->IsEndLoopNode() || aNode != anEndLoopNode ) {
+      if ( !aNode->CheckLoop( aLoopNode , anEndLoopNode , anErrorMessage) ) {
+        cdebug_out << Name() << "->ComputingNode::CheckLoop( " << aLoopNode->Name()
+                   << " , " << anEndLoopNode->Name() << ") LinkedNodesSize "
+                   << LinkedNodesSize() << " ERROR false" << endl;
+        return false ;
+      }
+    }
+  }
+  cdebug_out << Name() << "->ComputingNode::CheckLoop( " << aLoopNode->Name() << " , "
+             << anEndLoopNode->Name() << ") LinkedNodesSize "
+             << LinkedNodesSize() << " true" << endl;
+  return true ;
+}
+
+bool GraphBase::ComputingNode::CheckEndLoop(GraphBase::LoopNode * aLoopNode ,
+                                            GraphBase::EndOfLoopNode * anEndLoopNode ,
+                                            string & anErrorMessage ) const {
+  cdebug_in << Name() << "->ComputingNode::CheckEndLoop( " << aLoopNode->Name() << " , "
+            << anEndLoopNode->Name() << ") LinkedFromNodesSize "
+            << LinkedFromNodesSize() << endl;
+
+  int i ;
+  if ( LinkedFromNodesSize() == 0 ) {
+    anErrorMessage = anErrorMessage + string( "The node " ) + string( Name() ) +
+                     string( " has no reversed linked Nodes. Loop not valid\n" ) ;
+    cdebug_out << Name() << "->ComputingNode::CheckEndLoop( " << aLoopNode->Name()
+               << " , " << anEndLoopNode->Name() << ") LinkedFromNodesSize "
+               << LinkedFromNodesSize() << " ERROR false" << endl;
+    return false ;
+  }
+// We have to check that all nodes linked from that node go to the beginning of LoopNode : 
+  for ( i = 0 ; i < LinkedFromNodesSize() ; i++ ) {
+    GraphBase::ComputingNode * aNode = (GraphBase::ComputingNode * ) LinkedFromNodes( i ) ;
+    cdebug << i << ". " << Name() << " Linked from " << aNode->Name() << endl ;
+    if ( !aNode->IsLoopNode() || aNode != aLoopNode ) {
+      if ( !aNode->CheckEndLoop( aLoopNode , anEndLoopNode , anErrorMessage ) ) {
+        cdebug_out << Name() << "->ComputingNode::CheckEndLoop( " << aLoopNode->Name()
+                   << " , " << anEndLoopNode->Name() << ") LinkedFromNodesSize "
+                   << LinkedFromNodesSize() << " ERROR false" << endl;
+        return false ;
+      }
+    }
+  }
+  cdebug_out << Name() << "->ComputingNode::CheckEndLoop( " << aLoopNode->Name() << " , "
+             << anEndLoopNode->Name() << ") LinkedFromNodesSize "
+             << LinkedFromNodesSize() << " true" << endl;
+  return true ;
+}
+
+bool GraphBase::ComputingNode::InitBranchOfSwitchDone( bool AllInit ,
+                                                       GraphBase::EndOfSwitchNode * anEndSwitchNode ,
+                                                       string & anErrorMessage ) {
+  bool RetVal = true ;
+  bool sts = BranchOfSwitchDone( false ) ;
+  if ( !sts && !AllInit && anEndSwitchNode != this ) {
+// Common Node in branchs :
+    anErrorMessage = anErrorMessage + string( "Common Node between some SwitchBranches : " ) +
+                     string( Name() ) + string("\n" ) ;
+    cdebug << Name() << "->ComputingNode::InitBranchOfSwitchDone ERROR false"
+           << endl ;
+    RetVal = false ;
+  }
+  int i ;
+  if ( !IsGOTONode() && anEndSwitchNode != this ) {
+    for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
+      GraphBase::ComputingNode * aNode ;
+      aNode = (GraphBase::ComputingNode * ) LinkedNodes( i ) ;
+      if ( !aNode->InitBranchOfSwitchDone( AllInit , anEndSwitchNode , anErrorMessage ) ) {
+        RetVal = false ;
+      }
+    }
+  }
+  return RetVal ;
+}
+
+bool GraphBase::ComputingNode::CheckSwitch( GraphBase::EndOfSwitchNode * anEndSwitchNode ,
+                                            string & anErrorMessage ) {
+  bool RetVal = true ;
+  cdebug_in << Name() << "->ComputingNode::CheckSwitch( "
+            << anEndSwitchNode->Name() << " ) " << Kind() << endl;
+  if ( anEndSwitchNode == this ) {
+  }
+// if it is a SwitchNode, continue the check at the corresponding EndSwitchNode
+  else if ( IsSwitchNode() ) {
+    GraphBase::EndOfSwitchNode * anOtherEndSwitchNode ;
+    anOtherEndSwitchNode = (GraphBase::EndOfSwitchNode * ) ((GraphBase::SwitchNode * ) this)->CoupledNode() ;
+    cdebug << Name() << "->ComputingNode::CheckSwitch will Check "
+           << anOtherEndSwitchNode->Name() << endl ;
+    if ( !anOtherEndSwitchNode->CheckSwitch( anEndSwitchNode , anErrorMessage ) ) {
+      cdebug_out << Name() << "->ComputingNode::CheckSwitch "
+                 << anOtherEndSwitchNode->Name() << " ERROR false" << endl;
+      RetVal = false ;
+    }
+  }
+  else {
+    int i ;
+    for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
+      GraphBase::OutPort * anOutPort = GetChangeNodeOutPort( i ) ;
+      if ( !anOutPort->IsDataStream() ) {
+        int j ;
+        for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
+          GraphBase::InPort * anInPort = anOutPort->ChangeInPorts( j ) ;
+          if ( !anInPort->IsDataStream() ) {
+            GraphBase::ComputingNode * aNode ;
+            aNode = GraphOfNode()->GetChangeGraphNode( anInPort->NodeName() ) ;
+            GraphBase::LoopNode * aLoopNode = NULL ;
+            GraphBase::EndOfLoopNode * aEndLoopNode = NULL ;
+            if ( IsLoopNode() ) {
+              aEndLoopNode = (GraphBase::EndOfLoopNode * ) ((GraphBase::LoopNode * ) this)->CoupledNode() ;
+              cdebug << Name() << "->ComputingNode::CheckSwitch LoopNode " << Name() << " coupled to "
+                     << aEndLoopNode << " " << aEndLoopNode->Name() << " aNode " << aNode << endl ;
+            }
+            else if ( IsEndLoopNode() ) {
+              aLoopNode = (GraphBase::LoopNode * ) ((GraphBase::EndOfLoopNode * ) this)->CoupledNode() ;
+              cdebug << Name() << "->ComputingNode::CheckSwitch EndLoopNode " << Name()
+                     << " coupled to "
+                     << aLoopNode << " " << aLoopNode->Name() << " aNode " << aNode << endl ;
+            }
+            if ( aNode == NULL ) {
+              cdebug << Name() << "->ComputingNode::CheckSwitch ignore "
+                     << anInPort->NodeName() << "( " << anInPort->PortName() << " )" << endl ;
+            }
+            else if ( aNode == anEndSwitchNode ) {
+              if ( !((GraphBase::EndOfSwitchNode * ) aNode)->DecrEndSwitchInPortLinked( anInPort ,
+                                                                                        anErrorMessage ) ) {
+                RetVal = false ;
+             }
+            }
+            else if ( aNode->BranchOfSwitchDone() ) {
+              cdebug << Name() << "->ComputingNode::CheckSwitch will NOT Check "
+                     << anInPort->NodeName() << "( " << anInPort->PortName() << " ) : already checked"
+                     << endl ;
+            }
+            else if ( IsLoopNode() && aNode == aEndLoopNode ) {
+              cdebug << Name() << "->ComputingNode::CheckSwitch will NOT Check "
+                     << anInPort->NodeName() << "( " << anInPort->PortName() << " )" << endl ;
+            }
+            else if ( IsEndLoopNode() && aNode == aLoopNode ) {
+              cdebug << Name() << "->ComputingNode::CheckSwitch will NOT Check "
+                     << anInPort->NodeName() << "( " << anInPort->PortName() << " )" << endl ;
+            }
+            else if ( aNode->IsGOTONode() ) {
+              cdebug << Name() << "->ComputingNode::CheckSwitch will NOT Check "
+                     << anInPort->NodeName() << "( " << anInPort->PortName() << " )" << endl ;
+              anEndSwitchNode->SetSwitchWithGOTO() ;
+            }
+            else {
+              cdebug << Name() << "->ComputingNode::CheckSwitch will Check "
+                     << anInPort->NodeName() << "( " << anInPort->PortName() << " )" << endl ;
+              if ( !aNode->CheckSwitch( anEndSwitchNode , anErrorMessage ) ) {
+                cdebug_out << Name() << "->ComputingNode::CheckSwitch "
+                         << anEndSwitchNode->Name() << " ERROR false" << endl;
+                RetVal =  false ;
+             }
+//            aNode->BranchOfSwitchDone( true ) ;
+            }
+          }
+        }
+      }
+    }
+  }
+  if ( RetVal ) {
+    BranchOfSwitchDone( true ) ;
+  }
+  cdebug_out << Name() << "->ComputingNode::CheckSwitch "
+             << anEndSwitchNode->Name() << " RetVal " << RetVal << endl;
+  return RetVal ;
+}
+
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <unistd.h>
@@ -564,9 +1167,9 @@ bool GraphBase::ComputingNode::SaveXML( QDomDocument & Graph , QDomElement & inf
   kind.appendChild( aField ) ;
 
   if ( IsDataStreamNode() && HasDataStream() != 0 ) {
-    long Timeout ;
+    CORBA::Long Timeout ;
     SUPERV::KindOfDataStreamTrace DataStreamTrace ;
-    double DeltaTime ;
+    CORBA::Double DeltaTime ;
     ((GraphBase::StreamGraph * ) this)->StreamParams( Timeout , DataStreamTrace , DeltaTime ) ;
 
     QDomElement timeout = Graph.createElement("streamgraph-timeout") ;
@@ -593,7 +1196,7 @@ bool GraphBase::ComputingNode::SaveXML( QDomDocument & Graph , QDomElement & inf
 
   QDomElement couplednode = Graph.createElement("coupled-node") ;
   if ( IsGOTONode() || IsLoopNode() || IsEndLoopNode() ||
-       IsSwitchNode() || IsEndSwitchNode() ) {
+       IsSwitchNode() || IsEndSwitchNode() || IsMacroNode() ) {
 //    f << Tabs << "<coupled-node>" << CoupledNode << "</coupled-node>"
 //      << endl ;
     aField = Graph.createTextNode( CoupledNode ) ;
@@ -620,6 +1223,8 @@ bool GraphBase::ComputingNode::SaveXML( QDomDocument & Graph , QDomElement & inf
   service.appendChild(servicename) ;
   servicename.appendChild( aField ) ;
 
+  cdebug << "SaveXML " << Name() << " In(" << ServiceInParameter().length()
+         << ") Out(" << ServiceOutParameter().length() << ")" << endl ;
   QDomElement inParameterlist = Graph.createElement("inParameter-list") ;
   service.appendChild(inParameterlist) ;
   unsigned int i;
@@ -919,59 +1524,64 @@ bool GraphBase::ComputingNode::SavePY( ostream &f , const char * aGraphName ,
                                        const ListOfFuncName FuncNames ,
                                        const ListOfPythonFunctions PythonFunctions ,
                                        int XCoordinate , int YCoordinate ) const {
+  cdebug_in << "ComputingNode::SavePY " << Name() << endl ;
   // san - Presumably, data stream graphs should be always saved with kind = DataStreamGraph
 // JR : the bug was at line 927 : && HasDataStream() != 0 was missing
   if ( IsDataFlowNode() || ( IsDataStreamNode() && HasDataStream() == 0 ) ) {
-    f << Name() << " = Graph( '" << Name() << "' )" << endl ;
+    f << "    " << Name() << " = Graph( '" << Name() << "' )" << endl ;
+     if ( GraphMacroLevel() ) {
+      f << "    " << Name() << ".SetCoupled( '"
+        << ((GraphBase::GOTONode * ) this)->CoupledNodeName() << "' )" << endl ;
+    }
   }
   else if ( IsDataStreamNode() && HasDataStream() != 0 ) {
-    f << Name() << " = StreamGraph( '" << Name() << "' )" << endl ;
-    long Timeout ;
+    f << "    " << Name() << " = StreamGraph( '" << Name() << "' )" << endl ;
+    CORBA::Long Timeout ;
     SUPERV::KindOfDataStreamTrace DataStreamTrace ;
-    double DeltaTime ;
+    CORBA::Double DeltaTime ;
     ((GraphBase::StreamGraph * ) this)->StreamParams( Timeout , DataStreamTrace , DeltaTime ) ;
-    f << aGraphName << ".SetStreamParams( " << Timeout << " , SUPERV." << DataStreamTrace
+    f << "    " << aGraphName << ".SetStreamParams( " << Timeout << " , SUPERV." << DataStreamTrace
       << " , " << DeltaTime << " )" << endl ;
   }
   else if ( IsComputingNode() ) {
     int i ;
-    f << Name() << "_ServiceinParameter = []" << endl ;
+    f << "    " << Name() << "_ServiceinParameter = []" << endl ;
     for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
-      f << Name() << "_ServiceinParameter.append( SALOME_ModuleCatalog.ServicesParameter( '"
+      f << "    " << Name() << "_ServiceinParameter.append( SALOME_ModuleCatalog.ServicesParameter( '"
         << ServiceInParameter()[i].Parametertype << "' , '"
         << ServiceInParameter()[i].Parametername << "' ) )" << endl ;
     }
-    f << Name() << "_ServiceoutParameter = []" << endl ;
+    f << "    " << Name() << "_ServiceoutParameter = []" << endl ;
     for ( i = 0 ; i < (int ) ServiceOutParameter().length() ; i++ ) {
-      f << Name() << "_ServiceoutParameter.append( SALOME_ModuleCatalog.ServicesParameter( '"
+      f << "    " << Name() << "_ServiceoutParameter.append( SALOME_ModuleCatalog.ServicesParameter( '"
         << ServiceOutParameter()[i].Parametertype << "' , '"
         << ServiceOutParameter()[i].Parametername << "' ) )" << endl ;
     }
-    f << Name() << "_ServiceinStreamParameter = []" << endl ;
+    f << "    " << Name() << "_ServiceinStreamParameter = []" << endl ;
     for ( i = 0 ; i < (int ) ServiceInStreamParameter().length() ; i++ ) {
-      f << Name() << "_ServiceinStreamParameter.append( SALOME_ModuleCatalog.ServicesDataStreamParameter( SALOME_ModuleCatalog."
+      f << "    " << Name() << "_ServiceinStreamParameter.append( SALOME_ModuleCatalog.ServicesDataStreamParameter( SALOME_ModuleCatalog."
         << ServiceInStreamParameter()[i].Parametertype << " , '"
         << ServiceInStreamParameter()[i].Parametername << "' , SALOME_ModuleCatalog."
         << ServiceInStreamParameter()[i].Parameterdependency << " ) )" << endl ;
     }
-    f << Name() << "_ServiceoutStreamParameter = []" << endl ;
+    f << "    " << Name() << "_ServiceoutStreamParameter = []" << endl ;
     for ( i = 0 ; i < (int ) ServiceOutStreamParameter().length() ; i++ ) {
-      f << Name() << "_ServiceoutStreamParameter.append( SALOME_ModuleCatalog.ServicesDataStreamParameter( SALOME_ModuleCatalog."
+      f << "    " << Name() << "_ServiceoutStreamParameter.append( SALOME_ModuleCatalog.ServicesDataStreamParameter( SALOME_ModuleCatalog."
         << ServiceOutStreamParameter()[i].Parametertype << " , '"
         << ServiceOutStreamParameter()[i].Parametername << "' , SALOME_ModuleCatalog."
         << ServiceOutStreamParameter()[i].Parameterdependency << " ) )" << endl ;
     }
-    f << Name() << "_Service = SALOME_ModuleCatalog.Service( '" << ServiceName()
+    f << "    " << Name() << "_Service = SALOME_ModuleCatalog.Service( '" << ServiceName()
       << "' , " << Name() << "_ServiceinParameter"
       << " , " << Name() << "_ServiceoutParameter"
       << " , " << Name() << "_ServiceinStreamParameter"
       << " , " << Name() << "_ServiceoutStreamParameter"
       << " , 0 , 0 )" << endl ;
-    f << Name() << " = " << aGraphName << ".CNode( " << Name() << "_Service" << " )"
+    f << "    " << Name() << " = " << aGraphName << ".CNode( " << Name() << "_Service" << " )"
       << endl ;
   }
   else if ( IsFactoryNode() ) {
-    f << Name() << " = " << aGraphName << ".FNode( '" << ComponentName
+    f << "    " << Name() << " = " << aGraphName << ".FNode( '" << ComponentName
       << "' , '" << InterfaceName << "' , '" << ServiceName() << "' )"
       << endl ;
   }
@@ -979,79 +1589,93 @@ bool GraphBase::ComputingNode::SavePY( ostream &f , const char * aGraphName ,
 // It is done with LoopNode or SwitchNode with CoupledNode()
   }
   else {
-    f << "Py" << Name() << " = []" << endl ;
+    if ( !IsMacroNode() ) {
+      f << "    " << "Py" << Name() << " = []" << endl ;
+    }
     int i ;
     SUPERV::ListOfStrings aPyFunc ;
     if ( PythonFunctions.size() ) {
       aPyFunc = *PythonFunctions[0] ;
       for ( i = 0 ; i < (int ) aPyFunc.length() ; i++ ) {
-        f << "Py" << Name() << ".append( '" << aPyFunc[i] << "' )" << endl ;
+        f << "    " << "Py" << Name() << ".append( '" << aPyFunc[i] << "' )" << endl ;
       }
     }
     if ( IsInLineNode() ) {
-      f << Name() << " = " << aGraphName << ".INode( '" << FuncNames[0].c_str() << "' , Py"
+      f << "    " << Name() << " = " << aGraphName << ".INode( '" << FuncNames[0].c_str() << "' , Py"
         << Name() << " )" << endl ;
     }
     else if ( IsGOTONode() ) {
       if ( aCoupledNode ) {
-        f << Name() << " = " << aGraphName << ".GNode( '" << FuncNames[0].c_str() << "' , Py"
+        f << "    " << Name() << " = " << aGraphName << ".GNode( '" << FuncNames[0].c_str() << "' , Py"
           << Name() << " , '" << aCoupledNode->Name() << "' )" << endl ;
       }
       else {
-        f << Name() << " = " << aGraphName << ".GNode( '" << FuncNames[0].c_str() << "' , Py"
+        f << "    " << Name() << " = " << aGraphName << ".GNode( '" << FuncNames[0].c_str() << "' , Py"
           << Name() << " , '' )" << endl ;
       }
     }
+    else if ( IsMacroNode() ) {
+      if ( aCoupledNode ) {
+        f << "    " << aCoupledNode->Name() << " = Def" << aCoupledNode->Name() << "()" << endl ;
+        f << "    " << Name() << " = " << aGraphName << ".GraphMNode( " << aCoupledNode->Name() << " )" << endl ;
+      }
+      else {
+        f << "    " << Name() << " = " << aGraphName << ".GraphMNode( ? )" << endl ;
+      }
+      f << "    " << Name() << ".SetCoupled( '" << aCoupledNode->Name() << "' )" << endl ;
+    }
     else {
 //      char * EndName = NULL ;
 //      EndName = new char[ 3 + strlen( Name() ) + 1 ] ;
 //      strcpy( EndName , "End" ) ;
 //      strcat( EndName , Name() ) ;
       char * EndName = aCoupledNode->Name() ;
+      cdebug << "ComputingNode::SavePY Node " << Name() << " EndName " << EndName
+             << endl ;
       if ( IsLoopNode() ) {
         int i ;
         SUPERV::ListOfStrings aPyMore = *PythonFunctions[1] ;
         SUPERV::ListOfStrings aPyNext = *PythonFunctions[2] ;
-        f << "PyMore" << Name() << " = []" << endl ;
+        f << "    " << "PyMore" << Name() << " = []" << endl ;
         for ( i = 0 ; i < (int ) aPyMore.length() ; i++ ) {
-          f << "PyMore" << Name() << ".append( '" << aPyMore[i] << "' )" << endl ;
+          f << "    " << "PyMore" << Name() << ".append( '" << aPyMore[i] << "' )" << endl ;
         }
-        f << "PyNext" << Name() << " = []" << endl ;
+        f << "    " << "PyNext" << Name() << " = []" << endl ;
         for ( i = 0 ; i < (int ) aPyNext.length() ; i++ ) {
-          f << "PyNext" << Name() << ".append( '" << aPyNext[i] << "' )" << endl ;
+          f << "    " << "PyNext" << Name() << ".append( '" << aPyNext[i] << "' )" << endl ;
         }
-        f << Name() << "," << EndName << " = " << aGraphName << ".LNode( '"
+        f << "    " << Name() << "," << EndName << " = " << aGraphName << ".LNode( '"
           << FuncNames[0].c_str() << "' , Py" << Name() << " , '"
           << FuncNames[1].c_str() << "' , PyMore" << Name()
           << " , '" << FuncNames[2].c_str() << "' , PyNext"
           << Name() << " )" << endl ;
-        f << EndName << ".SetName( '" << aCoupledNode->Name() << "' )" << endl ;
-        f << EndName << ".SetAuthor( '" << aCoupledNode->Author() << "' )" << endl ;
-        f << EndName << ".SetComment( '" << aCoupledNode->Comment() << "' )" << endl ;
-        f << EndName << ".Coords( " << aCoupledNode->XCoordinate() << " , "
+        f << "    " << EndName << ".SetName( '" << aCoupledNode->Name() << "' )" << endl ;
+        f << "    " << EndName << ".SetAuthor( '" << aCoupledNode->Author() << "' )" << endl ;
+        f << "    " << EndName << ".SetComment( '" << aCoupledNode->Comment() << "' )" << endl ;
+        f << "    " << EndName << ".Coords( " << aCoupledNode->XCoordinate() << " , "
           << aCoupledNode->YCoordinate() << " )" << endl ;
         SUPERV::ListOfStrings aPyFunc = *aCoupledNode->PythonFunction() ;
-        f << "Py" << aCoupledNode->Name() << " = []" << endl ;
+        f << "    " << "Py" << aCoupledNode->Name() << " = []" << endl ;
         for ( i = 0 ; i < (int ) aPyFunc.length() ; i++ ) {
-          f << "Py" << aCoupledNode->Name() << ".append( '" << aPyFunc[i] << "' )"
+          f << "    " << "Py" << aCoupledNode->Name() << ".append( '" << aPyFunc[i] << "' )"
             << endl ;
         }
-        f << EndName << ".SetPyFunction( '" << aCoupledNode->PyFuncName() << "' , Py" << aCoupledNode->Name() << " )" << endl ;
+        f << "    " << EndName << ".SetPyFunction( '" << aCoupledNode->PyFuncName() << "' , Py" << aCoupledNode->Name() << " )" << endl ;
         for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
           const GraphBase::InPort * anInPort = GetNodeInPort(i) ;
           cdebug << "Node " << Name() << " InPort " << anInPort->PortName()
                  << " " << anInPort->Kind() << endl ;
           if ( anInPort->IsLoop() ) {
-            f << "I" << Name() << anInPort->PortName() << " = "
+            f << "    " << "I" << Name() << anInPort->PortName() << " = "
               << Name() << ".GetInPort( '" << anInPort->PortName() << "' )" << endl ;
          }
           else if ( anInPort->IsInLine() ) {
-            f << "I" << Name() << anInPort->PortName() << " = "
+            f << "    " << "I" << Name() << anInPort->PortName() << " = "
               << Name() << ".InPort( '" << anInPort->PortName() << "' , '"
               << anInPort->PortType() << "' )" << endl ;
           }
           else if ( anInPort->IsDataStream() ) {
-            f << "I" << Name() << anInPort->PortName() << " = " << Name()
+            f << "    " << "I" << Name() << anInPort->PortName() << " = " << Name()
               << ".InStreamPort( '" << anInPort->PortName()
               << "' , SALOME_ModuleCatalog." << StringToDataStreamType( anInPort->PortType() )
               << " , SALOME_ModuleCatalog." << anInPort->Dependency() << " )" << endl ;
@@ -1059,11 +1683,11 @@ bool GraphBase::ComputingNode::SavePY( ostream &f , const char * aGraphName ,
             SUPERV::KindOfInterpolation aKindOfInterpolation ;
             SUPERV::KindOfExtrapolation aKindOfExtrapolation ;
             ((GraphBase::InDataStreamPort * ) anInPort)->Params( aKindOfSchema , aKindOfInterpolation , aKindOfExtrapolation ) ;
-            f << "I" << Name() << anInPort->PortName() << ".SetParams( SUPERV." << aKindOfSchema << " , SUPERV."
+            f << "    " << "I" << Name() << anInPort->PortName() << ".SetParams( SUPERV." << aKindOfSchema << " , SUPERV."
               << aKindOfInterpolation << " , SUPERV." << aKindOfExtrapolation << " )" << endl ;
          }
           else if ( anInPort->IsGate() ) {
-            f << "I" << Name() << anInPort->PortName() << " = "
+            f << "    " << "I" << Name() << anInPort->PortName() << " = "
               << Name() << ".GetInPort( '" << anInPort->PortName() << "' )" << endl ;
          }
         }
@@ -1072,30 +1696,35 @@ bool GraphBase::ComputingNode::SavePY( ostream &f , const char * aGraphName ,
           cdebug << "Node " << Name() << " OutPort " << anOutPort->PortName()
                  << " " << anOutPort->Kind() << endl ;
           if ( anOutPort->IsInLine() || anOutPort->IsLoop() ) {
-            f << "O" << Name() << anOutPort->PortName() << " = "
+            f << "    " << "O" << Name() << anOutPort->PortName() << " = "
               << Name() << ".GetOutPort( '" << anOutPort->PortName() << "' )" << endl ;
           }
           else if ( anOutPort->IsDataStream() ) {
-            f << "O" << Name() << anOutPort->PortName() << " = " << Name()
+            f << "    " << "O" << Name() << anOutPort->PortName() << " = " << Name()
               << ".OutStreamPort( '" << anOutPort->PortName()
               << "' , SALOME_ModuleCatalog." << StringToDataStreamType( anOutPort->PortType() )
               << " , SALOME_ModuleCatalog." << anOutPort->Dependency() << " )" << endl ;
             long aNumberOfValues ;
             aNumberOfValues = ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues() ;
-            f << "O" << Name() << anOutPort->PortName() << ".SetNumberOfValues( " << aNumberOfValues << " )"
+            f << "    " << "O" << Name() << anOutPort->PortName() << ".SetNumberOfValues( " << aNumberOfValues << " )"
               << endl ;
          }
+//JR 02.09.2005 : GetOutPort for Gates was missing
+          else if ( anOutPort->IsGate() ) {
+            f << "    " << "O" << Name() << anOutPort->PortName() << " = "
+              << Name() << ".GetOutPort( '" << anOutPort->PortName() << "' )" << endl ;
+          }
         }
         for ( i = 0 ; i < aCoupledNode->GetNodeInPortsSize() ; i++ ) {
           const GraphBase::InPort * anInPort = aCoupledNode->GetNodeInPort(i) ;
           cdebug << "Node " << aCoupledNode->Name() << " InPort " << anInPort->PortName()
                  << " " << anInPort->Kind() << endl ;
           if ( anInPort->IsInLine() || anInPort->IsLoop() || anInPort->IsGate() ) {
-            f << "I" << EndName << anInPort->PortName() << " = " << EndName
+            f << "    " << "I" << EndName << anInPort->PortName() << " = " << EndName
               << ".GetInPort( '" << anInPort->PortName() << "' )" << endl ;
           }
           else if ( anInPort->IsDataStream() ) {
-            f << "I" << EndName << anInPort->PortName() << " = " << EndName
+            f << "    " << "I" << EndName << anInPort->PortName() << " = " << EndName
               << ".InStreamPort( '" << anInPort->PortName()
               << "' , SALOME_ModuleCatalog." << StringToDataStreamType( anInPort->PortType() )
               << " , SALOME_ModuleCatalog." << anInPort->Dependency() << " )" << endl ;
@@ -1103,7 +1732,7 @@ bool GraphBase::ComputingNode::SavePY( ostream &f , const char * aGraphName ,
             SUPERV::KindOfInterpolation aKindOfInterpolation ;
             SUPERV::KindOfExtrapolation aKindOfExtrapolation ;
             ((GraphBase::InDataStreamPort * ) anInPort)->Params( aKindOfSchema , aKindOfInterpolation , aKindOfExtrapolation ) ;
-            f << "I" << EndName << anInPort->PortName() << ".SetParams( SUPERV." << aKindOfSchema << " , SUPERV."
+            f << "    " << "I" << EndName << anInPort->PortName() << ".SetParams( SUPERV." << aKindOfSchema << " , SUPERV."
               << aKindOfInterpolation << " , SUPERV." << aKindOfExtrapolation << " )" << endl ;
          }
         }
@@ -1112,52 +1741,52 @@ bool GraphBase::ComputingNode::SavePY( ostream &f , const char * aGraphName ,
           cdebug << "Node " << aCoupledNode->Name() << " OutPort " << anOutPort->PortName()
                  << " " << anOutPort->Kind() << endl ;
           if ( anOutPort->IsInLine() || anOutPort->IsLoop() || anOutPort->IsGate() ) {
-            f << "O" << EndName << anOutPort->PortName() << " = " << EndName
+            f << "    " << "O" << EndName << anOutPort->PortName() << " = " << EndName
               << ".GetOutPort( '" << anOutPort->PortName() << "' )" << endl ;
           }
           else if ( anOutPort->IsDataStream() ) {
-            f << "O" << EndName << anOutPort->PortName() << " = " << EndName
+            f << "    " << "O" << EndName << anOutPort->PortName() << " = " << EndName
               << ".OutStreamPort( '" << anOutPort->PortName()
               << "' , SALOME_ModuleCatalog." << StringToDataStreamType( anOutPort->PortType() )
               << " , SALOME_ModuleCatalog." << anOutPort->Dependency() << " )" << endl ;
             long aNumberOfValues ;
             aNumberOfValues = ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues() ;
-            f << "O" << EndName << anOutPort->PortName() << ".SetNumberOfValues( " << aNumberOfValues << " )"
+            f << "    " << "O" << EndName << anOutPort->PortName() << ".SetNumberOfValues( " << aNumberOfValues << " )"
               << endl ;
          }
         }
       }
       else if ( IsSwitchNode() ) {
-        f << Name() << "," << EndName << " = " << aGraphName << ".SNode( '"
+        f << "    " << Name() << "," << EndName << " = " << aGraphName << ".SNode( '"
           << FuncNames[0].c_str() << "' , Py" << Name() << " )" << endl ;
-        f << EndName << ".SetName( '" << aCoupledNode->Name() << "' )" << endl ;
-        f << EndName << ".SetAuthor( '" << aCoupledNode->Author() << "' )" << endl ;
-        f << EndName << ".SetComment( '" << aCoupledNode->Comment() << "' )" << endl ;
-        f << EndName << ".Coords( " << aCoupledNode->XCoordinate() << " , "
+        f << "    " << EndName << ".SetName( '" << aCoupledNode->Name() << "' )" << endl ;
+        f << "    " << EndName << ".SetAuthor( '" << aCoupledNode->Author() << "' )" << endl ;
+        f << "    " << EndName << ".SetComment( '" << aCoupledNode->Comment() << "' )" << endl ;
+        f << "    " << EndName << ".Coords( " << aCoupledNode->XCoordinate() << " , "
           << aCoupledNode->YCoordinate() << " )" << endl ;
         SUPERV::ListOfStrings aPyFunc = *aCoupledNode->PythonFunction() ;
-        f << "Py" << aCoupledNode->Name() << " = []" << endl ;
+        f << "    " << "Py" << aCoupledNode->Name() << " = []" << endl ;
         for ( i = 0 ; i < (int ) aPyFunc.length() ; i++ ) {
-          f << "Py" << aCoupledNode->Name() << ".append( '" << aPyFunc[i] << "' )"
+          f << "    " << "Py" << aCoupledNode->Name() << ".append( '" << aPyFunc[i] << "' )"
             << endl ;
         }
-        f << EndName << ".SetPyFunction( '" << aCoupledNode->PyFuncName() << "' , Py" << aCoupledNode->Name() << " )" << endl ;
+        f << "    " << EndName << ".SetPyFunction( '" << aCoupledNode->PyFuncName() << "' , Py" << aCoupledNode->Name() << " )" << endl ;
         for ( i = 0 ; i < aCoupledNode->GetNodeInPortsSize() ; i++ ) {
           const GraphBase::InPort * anInPort = aCoupledNode->GetNodeInPort(i) ;
           cdebug << "Node " << aCoupledNode->Name() << " InPort " << anInPort->PortName()
                  << " " << anInPort->Kind() << endl ;
 //          if ( anInPort->IsGate() || anInPort->IsEndSwitch() ) {
           if ( anInPort->IsGate() ) {
-            f << "I" << EndName << anInPort->PortName() << " = " << EndName
+            f << "    " << "I" << EndName << anInPort->PortName() << " = " << EndName
               << ".GetInPort( '" << anInPort->PortName() << "' )" << endl ;
           }
           else if ( anInPort->IsInLine() || anInPort->IsEndSwitch() ) {
-            f << "I" << EndName << anInPort->PortName() << " = " << EndName
+            f << "    " << "I" << EndName << anInPort->PortName() << " = " << EndName
               << ".InPort( '" << anInPort->PortName()
               << "' , '" << anInPort->PortType() << "' )" << endl ;
           }
           else if ( anInPort->IsDataStream() ) {
-            f << "I" << EndName << anInPort->PortName() << " = " << EndName
+            f << "    " << "I" << EndName << anInPort->PortName() << " = " << EndName
               << ".InStreamPort( '" << anInPort->PortName()
               << "' , SALOME_ModuleCatalog." << StringToDataStreamType( anInPort->PortType() )
               << " , SALOME_ModuleCatalog." << anInPort->Dependency() << " )" << endl ;
@@ -1165,7 +1794,7 @@ bool GraphBase::ComputingNode::SavePY( ostream &f , const char * aGraphName ,
             SUPERV::KindOfInterpolation aKindOfInterpolation ;
             SUPERV::KindOfExtrapolation aKindOfExtrapolation ;
             ((GraphBase::InDataStreamPort * ) anInPort)->Params( aKindOfSchema , aKindOfInterpolation , aKindOfExtrapolation ) ;
-            f << "I" << EndName << anInPort->PortName() << ".SetParams( SUPERV." << aKindOfSchema << " , SUPERV."
+            f << "    " << "I" << EndName << anInPort->PortName() << ".SetParams( SUPERV." << aKindOfSchema << " , SUPERV."
               << aKindOfInterpolation << " , SUPERV." << aKindOfExtrapolation << " )" << endl ;
          }
         }
@@ -1175,27 +1804,31 @@ bool GraphBase::ComputingNode::SavePY( ostream &f , const char * aGraphName ,
                  << " " << anOutPort->Kind() << endl ;
 //          if ( anOutPort->IsGate() || anOutPort->IsEndSwitch() ) {
           if ( anOutPort->IsGate() ) {
-            f << "O" << EndName << anOutPort->PortName() << " = " << EndName
+            f << "    " << "O" << EndName << anOutPort->PortName() << " = " << EndName
               << ".GetOutPort( '" << anOutPort->PortName() << "' )" << endl ;
           }
           else if ( anOutPort->IsInLine() || anOutPort->IsSwitch() ) {
-            f << "O" << EndName << anOutPort->PortName() << " = " << EndName
+            f << "    " << "O" << EndName << anOutPort->PortName() << " = " << EndName
               << ".OutPort( '" << anOutPort->PortName()
               << "' , '" << anOutPort->PortType() << "' )" << endl ;
           }
           else if ( anOutPort->IsDataStream() ) {
-            f << "O" << EndName << anOutPort->PortName() << " = " << EndName
+            f << "    " << "O" << EndName << anOutPort->PortName() << " = " << EndName
               << ".OutStreamPort( '" << anOutPort->PortName()
               << "' , SALOME_ModuleCatalog." << StringToDataStreamType( anOutPort->PortType() )
               << " , SALOME_ModuleCatalog." << anOutPort->Dependency() << " )" << endl ;
             long aNumberOfValues ;
             aNumberOfValues = ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues() ;
-            f << "O" << EndName << anOutPort->PortName() << ".SetNumberOfValues( " << aNumberOfValues << " )"
+            f << "    " << "O" << EndName << anOutPort->PortName() << ".SetNumberOfValues( " << aNumberOfValues << " )"
               << endl ;
          }
         }
       }
-      delete [] EndName ;
+      cdebug << "ComputingNode::SavePY Node " << Name() << " EndName " << EndName
+             << endl ;
+// PAL8507
+//JR 24.02.2005 Debug !!!... : I should not delete myself : what a stupid thing !
+//      delete [] EndName ;
     }
   }
 
@@ -1203,13 +1836,13 @@ bool GraphBase::ComputingNode::SavePY( ostream &f , const char * aGraphName ,
 // It is done with LoopNode or SwitchNode with CoupledNode()
   }
   else {
-    f << Name() << ".SetName( '" << Name() << "' )" << endl ;
-    f << Name() << ".SetAuthor( '" << Author() << "' )" << endl ;
+    f << "    " << Name() << ".SetName( '" << Name() << "' )" << endl ;
+    f << "    " << Name() << ".SetAuthor( '" << Author() << "' )" << endl ;
     if ( IsFactoryNode() ) {
-      f << Name() << ".SetContainer( '" << Computer << "' )" << endl ;
+      f << "    " << Name() << ".SetContainer( '" << Computer << "' )" << endl ;
     }
-    f << Name() << ".SetComment( '" << Comment() << "' )" << endl ;
-    f << Name() << ".Coords( " << XCoordinate << " , " << YCoordinate << " )" << endl ;
+    f << "    " << Name() << ".SetComment( '" << Comment() << "' )" << endl ;
+    f << "    " << Name() << ".Coords( " << XCoordinate << " , " << YCoordinate << " )" << endl ;
 
     if ( IsComputingNode() || IsFactoryNode() ) {
       int i ;
@@ -1218,7 +1851,7 @@ bool GraphBase::ComputingNode::SavePY( ostream &f , const char * aGraphName ,
         if ( !anInPort->IsDataStream() ) {
           cdebug << "Node " << Name() << " InPort " << anInPort->PortName()
                  << " " << anInPort->Kind() << endl ;
-          f << "I" << Name() << anInPort->PortName() << " = "
+          f << "    " << "I" << Name() << anInPort->PortName() << " = "
             << Name() << ".GetInPort( '" << anInPort->PortName() << "' )" << endl ;
        }
       }
@@ -1227,7 +1860,7 @@ bool GraphBase::ComputingNode::SavePY( ostream &f , const char * aGraphName ,
         if ( !anOutPort->IsDataStream() ) {
           cdebug << "Node " << Name() << " OutPort " << anOutPort->PortName()
                  << " " << anOutPort->Kind() << endl ;
-          f << "O" << Name() << anOutPort->PortName() << " = "
+          f << "    " << "O" << Name() << anOutPort->PortName() << " = "
             << Name() << ".GetOutPort( '" << anOutPort->PortName() << "' )" << endl ;
        }
       }
@@ -1236,30 +1869,42 @@ bool GraphBase::ComputingNode::SavePY( ostream &f , const char * aGraphName ,
       int i ;
       for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
         const GraphBase::InPort * anInPort = GetNodeInPort(i) ;
-        cdebug << "Node " << Name() << " InPort " << anInPort->PortName()
+        cdebug << "ComputingNode::SavePY Node " << Name() << " InPort " << anInPort->PortName()
                << " " << anInPort->Kind() << endl ;
-        if ( anInPort->IsInLine() || anInPort->IsEndSwitch() ) {
-          f << "I" << Name() << anInPort->PortName() << " = "
+//        if ( anInPort->IsGate() || ( anInPort->IsInLine() && IsMacroNode() ) ) {
+        if ( anInPort->IsGate() || IsMacroNode() ) {
+          f << "    " << "I" << Name() << anInPort->PortName() << " = "
+            << Name() << ".GetInPort( '" << anInPort->PortName()  << "' )" << endl ;
+        }
+        else if ( anInPort->IsInLine() || anInPort->IsEndSwitch() ) {
+          f << "    " << "I" << Name() << anInPort->PortName() << " = "
             << Name() << ".InPort( '" << anInPort->PortName() << "' , '"
             << anInPort->PortType() << "' )" << endl ;
         }
-        else if ( anInPort->IsGate() ) {
-          f << "I" << Name() << anInPort->PortName() << " = "
-            << Name() << ".GetInPort( '" << anInPort->PortName()  << "' )" << endl ;
+        else {
+          cdebug << "Ignored " << Name() << " " << anInPort->PortName() << " " << anInPort->PortStatus() << endl ;
+//          f << "    " << "I" << Name() << anInPort->PortName() << " = "
+//            << Name() << ".GetInPort( '" << anInPort->PortName()  << "' )" << endl ;
         }
       }
       for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
         const GraphBase::OutPort * anOutPort = GetNodeOutPort(i) ;
-        cdebug << "Node " << Name() << " OutPort " << anOutPort->PortName()
+        cdebug << "ComputingNode::SavePY Node " << Name() << " OutPort " << anOutPort->PortName()
                << " " << anOutPort->Kind() << endl ;
-        if ( anOutPort->IsInLine() || anOutPort->IsSwitch() ) {
-          f << "O" << Name() << anOutPort->PortName() << " = "
+//        if ( anOutPort->IsGate() || ( anOutPort->IsInLine() && IsMacroNode() ) ) {
+        if ( anOutPort->IsGate() || IsMacroNode() ) {
+          f << "    " << "O" << Name() << anOutPort->PortName() << " = "
+            << Name() << ".GetOutPort( '" << anOutPort->PortName() << "' )" << endl ;
+        }
+        else if ( anOutPort->IsInLine() || anOutPort->IsSwitch() ) {
+          f << "    " << "O" << Name() << anOutPort->PortName() << " = "
             << Name() << ".OutPort( '" << anOutPort->PortName()
             << "' , '" << anOutPort->PortType() << "' )" << endl ;
         }
-        else if ( anOutPort->IsGate() ) {
-          f << "O" << Name() << anOutPort->PortName() << " = "
-            << Name() << ".GetOutPort( '" << anOutPort->PortName() << "' )" << endl ;
+        else {
+          cdebug << "Ignored " << Name() << " " << anOutPort->PortName() << " " << anOutPort->PortStatus() << endl ;
+//          f << "    " << "O" << Name() << anOutPort->PortName() << " = "
+//            << Name() << ".GetOutPort( '" << anOutPort->PortName() << "' )" << endl ;
         }
       }
     }
@@ -1271,20 +1916,20 @@ bool GraphBase::ComputingNode::SavePY( ostream &f , const char * aGraphName ,
                << " " << anInPort->Kind() << endl ;
         if ( anInPort->IsDataStream() ) {
           if ( IsOneOfInLineNodes() ) {
-            f << "I" << Name() << anInPort->PortName() << " = "
+            f << "    " << "I" << Name() << anInPort->PortName() << " = "
               << Name() << ".InStreamPort( '" << anInPort->PortName() << "' , SALOME_ModuleCatalog."
               << StringToDataStreamType( anInPort->PortType() ) << " , SALOME_ModuleCatalog."
               << anInPort->Dependency() << " )" << endl ;
          }
           else {
-            f << "I" << Name() << anInPort->PortName() << " = "
+            f << "    " << "I" << Name() << anInPort->PortName() << " = "
               << Name() << ".GetInStreamPort( '" << anInPort->PortName() << "' )" << endl ;
          }
           SUPERV::KindOfSchema        aKindOfSchema ;
           SUPERV::KindOfInterpolation aKindOfInterpolation ;
           SUPERV::KindOfExtrapolation aKindOfExtrapolation ;
           ((GraphBase::InDataStreamPort * ) anInPort)->Params( aKindOfSchema , aKindOfInterpolation , aKindOfExtrapolation ) ;
-          f << "I" << Name() << anInPort->PortName() << ".SetParams( SUPERV." << aKindOfSchema << " , SUPERV."
+          f << "    " << "I" << Name() << anInPort->PortName() << ".SetParams( SUPERV." << aKindOfSchema << " , SUPERV."
             << aKindOfInterpolation << " , SUPERV." << aKindOfExtrapolation << " )" << endl ;
         }
       }
@@ -1294,23 +1939,26 @@ bool GraphBase::ComputingNode::SavePY( ostream &f , const char * aGraphName ,
                << " " << anOutPort->Kind() << endl ;
         if ( anOutPort->IsDataStream() ) {
           if ( IsOneOfInLineNodes() ) {
-            f << "O" << Name() << anOutPort->PortName() << " = "
+            f << "    " << "O" << Name() << anOutPort->PortName() << " = "
               << Name() << ".OutStreamPort( '" << anOutPort->PortName() << "' , SALOME_ModuleCatalog."
               << StringToDataStreamType( anOutPort->PortType() ) << " , SALOME_ModuleCatalog."
               << anOutPort->Dependency() << " )" << endl ;
          }
           else {
-            f << "O" << Name() << anOutPort->PortName() << " = "
+            f << "    " << "O" << Name() << anOutPort->PortName() << " = "
               << Name() << ".GetOutStreamPort( '" << anOutPort->PortName() << "' )" << endl ;
          }
           long aNumberOfValues ;
           aNumberOfValues = ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues() ;
-          f << "O" << Name() << anOutPort->PortName() << ".SetNumberOfValues( " << aNumberOfValues << " )" << endl ;
+          f << "    " << "O" << Name() << anOutPort->PortName() << ".SetNumberOfValues( " << aNumberOfValues << " )" << endl ;
         }
       }
     }
   }
 
+  cdebug_out << "ComputingNode::SavePY " ;
+  NodeInfo( *_fdebug ) ;
+  cdebug << endl ;
   return true ;
 }