Salome HOME
DCQ:prepare 2.0.0
[modules/superv.git] / src / GraphBase / DataFlowBase_ComputingNode.cxx
index 4f04a806658b5bfd87aee99c32f59525d01b045d..1cce3b212b0687aa3df7b0db997bc2ed656fb14b 100644 (file)
@@ -92,10 +92,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,7 +115,8 @@ 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() ;
@@ -130,6 +133,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,7 +155,7 @@ 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 ;
@@ -304,15 +308,22 @@ 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 ) ;
     }
@@ -323,12 +334,12 @@ bool GraphBase::ComputingNode::IsLinked(const char * ToServiceParameterName ) {
   bool RetVal = false ;
   const GraphBase::InPort * thePort = GetInPort( ToServiceParameterName ) ;
   if ( thePort ) {
-    RetVal = thePort->IsConnected() ;
+    RetVal = thePort->IsPortConnected() ;
   }
   else {
     const GraphBase::OutPort * thePort = GetOutPort( ToServiceParameterName ) ;
     if ( thePort ) {
-      RetVal = thePort->IsConnected() ;
+      RetVal = thePort->IsPortConnected() ;
     }
   }
   return RetVal ;
@@ -336,20 +347,23 @@ 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 ) {
+  const GraphBase::InPort * theInPort = GetInPort( ToServiceParameterName ) ;
+#if 0
+  if ( IsDataFlowNode() && theInPort ) {
     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() ;
+  else 
+#endif
+  if ( theInPort ) {
+//    cout << "GraphBase::ComputingNode::HasInput theInPort " << theInPort << " " << theInPort->PortName() << " of "
+//         << theInPort->NodeName() << " IsDataConnected " << theInPort->IsDataConnected() << " OutPort "
+//         << theInPort->GetOutPort() << endl ;
+    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 ;
@@ -385,6 +399,161 @@ 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() ) ;
+    }
+  }
+  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 ) ;
+      }
+    }
+  }
+  cdebug_out << "GraphBase::ComputingNode::UpdateMacroPorts" << 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() ) {
+      aGraphOfMacroGraph->AddInputData( Name() , anInPort->PortName() , *(anOutPort->Value()) ) ;
+      anOutPort->PortStatus( ExternConnected ) ;
+    }
+  }
+  cdebug_out << "GraphBase::ComputingNode::SetMacroDatas" << endl;
+}
+
 void GraphBase::ComputingNode::DelInPort( const char * InputParameterName ) {
   GraphBase::PortsOfNode::DelInPort( InputParameterName ) ;
 }
@@ -394,26 +563,28 @@ void GraphBase::ComputingNode::DelOutPort( const char * OutputParameterName ) {
 
 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 ;
   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 +598,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 +607,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 +619,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,8 +628,9 @@ 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 ;
 }
@@ -593,7 +768,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 +795,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;
@@ -922,56 +1099,56 @@ bool GraphBase::ComputingNode::SavePY( ostream &f , const char * aGraphName ,
   // 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 ;
   }
   else if ( IsDataStreamNode() && HasDataStream() != 0 ) {
-    f << Name() << " = StreamGraph( '" << Name() << "' )" << endl ;
+    f << "    " << Name() << " = StreamGraph( '" << Name() << "' )" << endl ;
     long Timeout ;
     SUPERV::KindOfDataStreamTrace DataStreamTrace ;
     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,29 +1156,40 @@ 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 ;
+      }
+    }
     else {
 //      char * EndName = NULL ;
 //      EndName = new char[ 3 + strlen( Name() ) + 1 ] ;
@@ -1012,46 +1200,46 @@ bool GraphBase::ComputingNode::SavePY( ostream &f , const char * aGraphName ,
         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 +1247,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,17 +1260,17 @@ 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 ;
          }
         }
@@ -1091,11 +1279,11 @@ bool GraphBase::ComputingNode::SavePY( ostream &f , const char * aGraphName ,
           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 +1291,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 +1300,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 +1353,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,22 +1363,22 @@ 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 ;
          }
         }
@@ -1203,13 +1391,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 +1406,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 +1415,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 +1424,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 +1471,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,18 +1494,18 @@ 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 ;
         }
       }
     }