Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[modules/superv.git] / src / GraphBase / DataFlowBase_ComputingNode.cxx
index 1cce3b212b0687aa3df7b0db997bc2ed656fb14b..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 ;
@@ -119,7 +120,8 @@ GraphBase::ComputingNode::ComputingNode( CORBA::ORB_ptr ORB ,
   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() ;
 
@@ -159,7 +161,8 @@ GraphBase::ComputingNode::ComputingNode( CORBA::ORB_ptr ORB ,
 
   _ORB = CORBA::ORB::_duplicate( ORB ) ;
   _NamingService = ptrNamingService ;
-  _Node = SUPERV::CNode::_nil() ;
+  _Node_var = SUPERV::CNode::_nil() ;
+  _Node_Impl = NULL ;
   _InNode = NULL ;
   _ThreadNo = pthread_self() ;
 
@@ -330,11 +333,15 @@ void GraphBase::ComputingNode::NodePort( const char * NodeName ,
   }
 }
 
-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->IsPortConnected() ;
+  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 ) ;
@@ -348,16 +355,7 @@ bool GraphBase::ComputingNode::IsLinked(const char * ToServiceParameterName ) {
 bool GraphBase::ComputingNode::HasInput(const char * ToServiceParameterName ) {
   bool RetVal = false ;
   const GraphBase::InPort * theInPort = GetInPort( ToServiceParameterName ) ;
-#if 0
-  if ( IsDataFlowNode() && theInPort ) {
-    RetVal = true ;
-  }
-  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 {
@@ -377,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 ;
@@ -468,6 +466,7 @@ void GraphBase::ComputingNode::UpdateMacroPorts( GraphBase::Graph * aGraph ) {
       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 ;
@@ -534,7 +533,55 @@ void GraphBase::ComputingNode::UpdateMacroPorts( GraphBase::Graph * aGraph ) {
       }
     }
   }
-  cdebug_out << "GraphBase::ComputingNode::UpdateMacroPorts" << endl;
+  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 ,
@@ -547,7 +594,8 @@ void GraphBase::ComputingNode::SetMacroDatas( GraphBase::Graph * aGraph ,
     cdebug << "                 " << Name() << " " << anOutPort->PortName() << " " << anOutPort->PortType()
            << " " << anOutPort->Kind() << " " << anOutPort->PortStatus() << endl ;
     if ( anOutPort->IsDataConnected() ) {
-      aGraphOfMacroGraph->AddInputData( Name() , anInPort->PortName() , *(anOutPort->Value()) ) ;
+//JR 30.03.2005      aGraphOfMacroGraph->AddInputData( Name() , anInPort->PortName() , *(anOutPort->Value()) ) ;
+      aGraphOfMacroGraph->AddInputData( Name() , anInPort->PortName() , anOutPort->Value() ) ;
       anOutPort->PortStatus( ExternConnected ) ;
     }
   }
@@ -555,10 +603,195 @@ void GraphBase::ComputingNode::SetMacroDatas( GraphBase::Graph * aGraph ,
 }
 
 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 ,
@@ -566,6 +799,11 @@ GraphBase::InPort * GraphBase::ComputingNode::AddInPort( const char * InputParam
                                                          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 ,
@@ -636,6 +874,196 @@ GraphBase::OutDataStreamPort * GraphBase::ComputingNode::AddOutDataStreamPort( c
 }
 
 
+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>
@@ -739,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") ;
@@ -1096,16 +1524,21 @@ 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 ;
+     if ( GraphMacroLevel() ) {
+      f << "    " << Name() << ".SetCoupled( '"
+        << ((GraphBase::GOTONode * ) this)->CoupledNodeName() << "' )" << endl ;
+    }
   }
   else if ( IsDataStreamNode() && HasDataStream() != 0 ) {
     f << "    " << Name() << " = StreamGraph( '" << Name() << "' )" << endl ;
-    long Timeout ;
+    CORBA::Long Timeout ;
     SUPERV::KindOfDataStreamTrace DataStreamTrace ;
-    double DeltaTime ;
+    CORBA::Double DeltaTime ;
     ((GraphBase::StreamGraph * ) this)->StreamParams( Timeout , DataStreamTrace , DeltaTime ) ;
     f << "    " << aGraphName << ".SetStreamParams( " << Timeout << " , SUPERV." << DataStreamTrace
       << " , " << DeltaTime << " )" << endl ;
@@ -1189,6 +1622,7 @@ bool GraphBase::ComputingNode::SavePY( ostream &f , const char * aGraphName ,
       else {
         f << "    " << Name() << " = " << aGraphName << ".GraphMNode( ? )" << endl ;
       }
+      f << "    " << Name() << ".SetCoupled( '" << aCoupledNode->Name() << "' )" << endl ;
     }
     else {
 //      char * EndName = NULL ;
@@ -1196,6 +1630,8 @@ bool GraphBase::ComputingNode::SavePY( ostream &f , const char * aGraphName ,
 //      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] ;
@@ -1273,6 +1709,11 @@ bool GraphBase::ComputingNode::SavePY( ostream &f , const char * aGraphName ,
             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) ;
@@ -1383,7 +1824,11 @@ bool GraphBase::ComputingNode::SavePY( ostream &f , const char * aGraphName ,
          }
         }
       }
-      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 ;
     }
   }
 
@@ -1511,6 +1956,9 @@ bool GraphBase::ComputingNode::SavePY( ostream &f , const char * aGraphName ,
     }
   }
 
+  cdebug_out << "ComputingNode::SavePY " ;
+  NodeInfo( *_fdebug ) ;
+  cdebug << endl ;
   return true ;
 }