]> SALOME platform Git repositories - modules/superv.git/blob - src/GraphBase/DataFlowBase_Graph.cxx
Salome HOME
29b0716b197388e6511889a7193a7f1c4db8c10f
[modules/superv.git] / src / GraphBase / DataFlowBase_Graph.cxx
1 //  SUPERV GraphBase : contains fondamental classes for Services, Input Ports, Output Ports Links and Nodes.
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : DataFlowBase_Graph.cxx
25 //  Author : Jean Rahuel, CEA
26 //  Module : SUPERV
27 //  $Header:
28
29 using namespace std;
30 #include "DataFlowBase_StreamGraph.hxx"
31
32 #include "SALOME_LifeCycleCORBA.hxx"
33
34 GraphBase::Graph::Graph() :
35            DataNode() {
36   cdebug << "GraphBase::Graph::Graph" << endl ;
37   _GraphNodesSize = 0 ;
38 }
39
40 GraphBase::Graph::Graph( CORBA::ORB_ptr ORB ,
41                          SALOME_NamingService* ptrNamingService ,
42                          const char *DataFlowName ,
43                          const SUPERV::KindOfNode DataFlowkind ,
44                          int * Graph_prof_debug ,
45                          ofstream * Graph_fdebug ) :
46 //                         const char * DebugFileName ) :
47            DataNode( ORB ,ptrNamingService , DataFlowName , DataFlowkind , Graph_prof_debug , Graph_fdebug ) {
48   _Orb = CORBA::ORB::_duplicate( ORB ) ;
49   Set_prof_debug( Graph_prof_debug , Graph_fdebug ) ;
50   cdebug << "GraphBase::Graph::Graph( " << DataFlowName << ") GraphNodesSize() " << GraphNodesSize() << endl ;
51   _GraphNodesSize = 0 ;
52 }
53
54 GraphBase::Graph::Graph( CORBA::ORB_ptr ORB ,
55                          SALOME_NamingService* ptrNamingService ,
56                          const SALOME_ModuleCatalog::Service& DataFlowService ,
57                          const char *DataFlowComponentName ,
58                          const char *DataFlowInterfaceName ,
59                          const char *DataFlowName ,
60                          const SUPERV::KindOfNode DataFlowkind ,
61                          const SUPERV::SDate DataFlowFirstCreation ,
62                          const SUPERV::SDate DataFlowLastModification ,
63                          const char * DataFlowEditorRelease ,
64                          const char * DataFlowAuthor ,
65                          const char * DataFlowComputer ,
66                          const char * DataFlowComment ,
67                          int * Graph_prof_debug ,
68                          ofstream * Graph_fdebug ) :
69 //                         const char * DebugFileName ) :
70            DataNode( ORB , ptrNamingService , DataFlowService ,
71                      DataFlowName , DataFlowkind ,
72                      DataFlowFirstCreation , DataFlowLastModification  ,
73                      DataFlowEditorRelease , DataFlowAuthor , DataFlowComment ) {
74   _Orb = CORBA::ORB::_duplicate( ORB ) ;
75   _GraphNodesSize = 0 ;
76   Set_prof_debug( Graph_prof_debug , Graph_fdebug ) ;
77   cdebug_in << "GraphBase::Graph::Graph" << endl ;
78   DataService( ORB , DataFlowService , Graph_prof_debug , Graph_fdebug ) ;
79   cdebug_out << "GraphBase::Graph::Graph" << endl ;
80 }
81
82 GraphBase::Graph::~Graph() {
83   cdebug << "GraphBase::Graph::~Graph" << endl ;
84 }
85
86 void GraphBase::Graph::Set_prof_debug( int * Graph_prof_debug ,
87                                        ofstream * Graph_fdebug ) {
88   SetDebug( _Orb , Graph_prof_debug , Graph_fdebug ) ;
89   _Graph_prof_debug = Graph_prof_debug ;
90   _Graph_fdebug = Graph_fdebug ;
91 }
92
93 GraphBase::SNode * GraphBase::Graph::GetInfo() const {
94   GraphBase::SNode * Info = new GraphBase::SNode ;
95   Info->theComponentName = "" ;
96   Info->theInterfaceName = "" ;
97   Info->theName = Name() ;
98   Info->theKind = Kind() ;
99   if ( IsDataStreamNode() ) {
100     long Timeout ;
101     SUPERV::KindOfDataStreamTrace DataStreamTrace ;
102     double DeltaTime ;
103     ((GraphBase::StreamGraph * ) this)->StreamParams( Timeout , DataStreamTrace , DeltaTime ) ;
104     Info->theTimeout = Timeout ;
105     Info->theDataStreamTrace = DataStreamTrace ;
106     Info->theDeltaTime = DeltaTime ;
107   }
108   Info->theService = *GetService() ;
109   Info->theFirstCreation = FirstCreation() ;
110   Info->theLastModification = LastModification() ;
111   Info->theEditorRelease = EditorRelease() ;
112   Info->theAuthor = Author() ;
113   Info->theContainer = "" ;
114   Info->theComment = Comment() ;
115   Info->theCoords.theX = GraphBase::ComputingNode::XCoordinate() ;
116   Info->theCoords.theY = GraphBase::ComputingNode::YCoordinate() ;
117   return Info ;
118 }
119
120 //----------------------------------------------------------------------
121 // Function : GetNodes
122 // Purpose  : get a nodes list
123 //----------------------------------------------------------------------
124 GraphBase::ListOfSNodes * GraphBase::Graph::GetNodes() const {
125   GraphBase::ListOfSNodes * _list_nodes = new GraphBase::ListOfSNodes;
126
127   cdebug_in << "GraphBase::Graph::GetNodes" << endl ;
128   // All the nodes from _InNodes are taken
129 //  vector< InNode *> Nodes = InNodes() ;
130
131   _list_nodes->resize( GraphNodesSize() );
132
133   int igoto ;
134   int ind ;
135   GraphBase::ComputingNode * aCNode = NULL ;
136   for ( igoto = 0 ; igoto < 2 ; igoto++ ) {
137     for ( ind = 0 ; ind < GraphNodesSize() ; ind++ ) {
138       aCNode = GraphNodes( ind ) ;
139       if ( ( igoto == 0 && !aCNode->IsGOTONode() ) ||
140            ( igoto == 1 && aCNode->IsGOTONode() ) ) {
141         if ( aCNode->IsFactoryNode() ) {
142           GraphBase::FactoryNode * aFNode = (GraphBase::FactoryNode * ) aCNode ;
143 //JR 24.02.2005 Memory Leak          (*_list_nodes)[ind].theComponentName = CORBA::string_dup( aFNode->ComponentName());
144           (*_list_nodes)[ind].theComponentName = string( aFNode->ComponentName());
145 //JR 24.02.2005 Memory Leak          (*_list_nodes)[ind].theInterfaceName = CORBA::string_dup( aFNode->InterfaceName());
146           (*_list_nodes)[ind].theInterfaceName = string( aFNode->InterfaceName());
147         }
148         else {
149           (*_list_nodes)[ind].theComponentName = string( "" );
150           (*_list_nodes)[ind].theInterfaceName = string( "" );
151         }
152 //JR 24.02.2005 Memory Leak        (*_list_nodes)[ind].theName = CORBA::string_dup( aCNode->Name() );
153         (*_list_nodes)[ind].theName = string( aCNode->Name() );
154         (*_list_nodes)[ind].theKind = aCNode->Kind();
155         if ( aCNode->IsInLineNode() || aCNode->IsMacroNode() ) {
156           GraphBase::InLineNode * aINode = (GraphBase::InLineNode * ) aCNode ;
157           (*_list_nodes)[ind].theListOfFuncName.resize( 1 ) ;
158 //JR 24.02.2005 Memory Leak          (*_list_nodes)[ind].theListOfFuncName[0] = CORBA::string_dup( aINode->PyFuncName() ) ;
159           (*_list_nodes)[ind].theListOfFuncName[0] = string( aINode->PyFuncName() ) ;
160           (*_list_nodes)[ind].theListOfPythonFunctions.resize( 1 ) ;
161           (*_list_nodes)[ind].theListOfPythonFunctions[0] = aINode->PythonFunction() ;
162         }
163         if ( aCNode->IsGOTONode() ) {
164           GraphBase::GOTONode * aGNode = (GraphBase::GOTONode * ) aCNode ;
165           (*_list_nodes)[ind].theListOfFuncName.resize( 1 ) ;
166 //JR 24.02.2005 Memory Leak          (*_list_nodes)[ind].theListOfFuncName[0] = CORBA::string_dup( aGNode->PyFuncName() ) ;
167           (*_list_nodes)[ind].theListOfFuncName[0] = string( aGNode->PyFuncName() ) ;
168           (*_list_nodes)[ind].theListOfPythonFunctions.resize( 1 ) ;
169           (*_list_nodes)[ind].theListOfPythonFunctions[0] = aGNode->PythonFunction() ;
170         }
171         if ( aCNode->IsLoopNode() ) {
172           GraphBase::LoopNode * aLNode = (GraphBase::LoopNode * ) aCNode ;
173 //JR 24.02.2005 Memory Leak          (*_list_nodes)[ind].theCoupledNode = CORBA::string_dup( aLNode->CoupledNode()->Name() ) ;
174           (*_list_nodes)[ind].theCoupledNode = string( aLNode->CoupledNode()->Name() ) ;
175           (*_list_nodes)[ind].theListOfFuncName.resize( 3 ) ;
176 //JR 24.02.2005 Memory Leak          (*_list_nodes)[ind].theListOfFuncName[0] = CORBA::string_dup( aLNode->PyFuncName() ) ;
177           (*_list_nodes)[ind].theListOfFuncName[0] = string( aLNode->PyFuncName() ) ;
178 //JR 24.02.2005 Memory Leak          (*_list_nodes)[ind].theListOfFuncName[1] = CORBA::string_dup( aLNode->PyMoreName() ) ;
179           (*_list_nodes)[ind].theListOfFuncName[1] = string( aLNode->PyMoreName() ) ;
180 //JR 24.02.2005 Memory Leak          (*_list_nodes)[ind].theListOfFuncName[2] = CORBA::string_dup( aLNode->PyNextName() ) ;
181           (*_list_nodes)[ind].theListOfFuncName[2] = string( aLNode->PyNextName() ) ;
182           (*_list_nodes)[ind].theListOfPythonFunctions.resize( 3 ) ;
183           (*_list_nodes)[ind].theListOfPythonFunctions[0] = aLNode->PythonFunction() ;
184           (*_list_nodes)[ind].theListOfPythonFunctions[1] = aLNode->MorePythonFunction() ;
185           (*_list_nodes)[ind].theListOfPythonFunctions[2] = aLNode->NextPythonFunction() ;
186         }
187         else if ( aCNode->IsSwitchNode() ) {
188           GraphBase::SwitchNode * aSNode = (GraphBase::SwitchNode * ) aCNode ;
189 //JR 24.02.2005 Memory Leak          (*_list_nodes)[ind].theCoupledNode = CORBA::string_dup( aSNode->CoupledNode()->Name() ) ;
190           (*_list_nodes)[ind].theCoupledNode = string( aSNode->CoupledNode()->Name() ) ;
191           (*_list_nodes)[ind].theListOfFuncName.resize( 1 ) ;
192 //JR 24.02.2005 Memory Leak          (*_list_nodes)[ind].theListOfFuncName[0] = CORBA::string_dup( aSNode->PyFuncName() ) ;
193           (*_list_nodes)[ind].theListOfFuncName[0] = string( aSNode->PyFuncName() ) ;
194           (*_list_nodes)[ind].theListOfPythonFunctions.resize( 1 ) ;
195           (*_list_nodes)[ind].theListOfPythonFunctions[0] = aSNode->PythonFunction() ;
196         }
197         else if ( aCNode->IsEndLoopNode() ) {
198           GraphBase::EndOfLoopNode * aELNode = (GraphBase::EndOfLoopNode * ) aCNode ;
199 //JR 24.02.2005 Memory Leak          (*_list_nodes)[ind].theCoupledNode = CORBA::string_dup( aELNode->CoupledNode()->Name() ) ;
200           (*_list_nodes)[ind].theCoupledNode = string( aELNode->CoupledNode()->Name() ) ;
201           (*_list_nodes)[ind].theListOfFuncName.resize( 1 ) ;
202 //JR 24.02.2005 Memory Leak          (*_list_nodes)[ind].theListOfFuncName[0] = CORBA::string_dup( aELNode->PyFuncName() ) ;
203           (*_list_nodes)[ind].theListOfFuncName[0] = string( aELNode->PyFuncName() ) ;
204           (*_list_nodes)[ind].theListOfPythonFunctions.resize( 1 ) ;
205           (*_list_nodes)[ind].theListOfPythonFunctions[0] = aELNode->PythonFunction() ;
206         }
207         else if ( aCNode->IsEndSwitchNode() ) {
208           GraphBase::EndOfSwitchNode * aESNode = (GraphBase::EndOfSwitchNode * ) aCNode ;
209 //JR 24.02.2005 Memory Leak          (*_list_nodes)[ind].theCoupledNode = CORBA::string_dup( aESNode->CoupledNode()->Name() ) ;
210           (*_list_nodes)[ind].theCoupledNode = string( aESNode->CoupledNode()->Name() ) ;
211           (*_list_nodes)[ind].theListOfFuncName.resize( 1 ) ;
212 //JR 24.02.2005 Memory Leak          (*_list_nodes)[ind].theListOfFuncName[0] = CORBA::string_dup( aESNode->PyFuncName() ) ;
213           (*_list_nodes)[ind].theListOfFuncName[0] = string( aESNode->PyFuncName() ) ;
214           (*_list_nodes)[ind].theListOfPythonFunctions.resize( 1 ) ;
215           (*_list_nodes)[ind].theListOfPythonFunctions[0] = aESNode->PythonFunction() ;
216         }
217         else if ( aCNode->IsMacroNode() ) {
218           GraphBase::Graph * aGraph = (GraphBase::Graph * ) aCNode ;
219 //JR 24.02.2005 Memory Leak          (*_list_nodes)[ind].theCoupledNode = CORBA::string_dup( aGraph->CoupledNode()->Name() ) ;
220           (*_list_nodes)[ind].theCoupledNode = string( aGraph->CoupledNode()->Name() ) ;
221           (*_list_nodes)[ind].theListOfFuncName.resize( 1 ) ;
222 //JR 24.02.2005 Memory Leak          (*_list_nodes)[ind].theListOfFuncName[0] = CORBA::string_dup( aGraph->PyFuncName() ) ;
223           (*_list_nodes)[ind].theListOfFuncName[0] = string( aGraph->PyFuncName() ) ;
224           (*_list_nodes)[ind].theListOfPythonFunctions.resize( 1 ) ;
225           (*_list_nodes)[ind].theListOfPythonFunctions[0] = aGraph->PythonFunction() ;
226         }
227         else {
228           (*_list_nodes)[ind].theCoupledNode = string( "" ) ;
229         }
230 //        (*_list_nodes)[ind].theDataStreamInArgsNumber = aCNode->DataStreamInPortsNumber() ;
231 //        (*_list_nodes)[ind].theDataStreamOutArgsNumber = aCNode->DataStreamOutPortsNumber() ;
232
233         (*_list_nodes)[ind].theListOfInDataStreams.resize( aCNode->DataStreamInPortsNumber() ) ;
234         cdebug << "GraphBase::Graph::GetNodes " << aCNode->Name() << " " << aCNode->DataStreamInPortsNumber() << " DataStreamInPortsNumber" << endl ;
235         int iostream ;
236         int streamind = 0 ;
237         for ( iostream = 0 ; iostream < aCNode->GetNodeInPortsSize() ; iostream++ ) {
238           const GraphBase::InPort * anInPort ;
239           anInPort = aCNode->GetNodeInPort( iostream ) ;
240           if ( anInPort->IsDataStream() ) {
241             cdebug << "GraphBase::Graph::GetNodes In" << iostream << " " << aCNode->Name() << " " << anInPort->NodeName() << " " << anInPort->PortName()
242                    << endl ;
243             (*_list_nodes)[ind].theListOfInDataStreams[streamind].theDataStreamParameter.Parametertype = StringToDataStreamType( anInPort->PortType() ) ;
244             (*_list_nodes)[ind].theListOfInDataStreams[streamind].theDataStreamParameter.Parametername = CORBA::string_dup( anInPort->PortName() ) ;
245             (*_list_nodes)[ind].theListOfInDataStreams[streamind].theDataStreamParameter.Parameterdependency = anInPort->Dependency() ;
246             SUPERV::KindOfSchema        aKindOfSchema ;
247             SUPERV::KindOfInterpolation aKindOfInterpolation ;
248             SUPERV::KindOfExtrapolation aKindOfExtrapolation ;
249             ((GraphBase::InDataStreamPort * ) anInPort)->Params( aKindOfSchema , aKindOfInterpolation , aKindOfExtrapolation ) ;
250             (*_list_nodes)[ind].theListOfInDataStreams[streamind].theKindOfSchema = aKindOfSchema ;
251             (*_list_nodes)[ind].theListOfInDataStreams[streamind].theKindOfInterpolation = aKindOfInterpolation ;
252             (*_list_nodes)[ind].theListOfInDataStreams[streamind].theKindOfExtrapolation = aKindOfExtrapolation ;
253             cdebug << "GraphBase::Graph::GetNodes " << aCNode->Name() << " " << anInPort->NodeName() << " " << anInPort->PortName() << " "
254                    <<  anInPort->Dependency() << " " << aKindOfSchema << " " << aKindOfInterpolation << " " << aKindOfExtrapolation << " list_nodes "
255                    << (*_list_nodes)[ind].theListOfInDataStreams[streamind].theDataStreamParameter.Parametername << " "
256                    << (*_list_nodes)[ind].theListOfInDataStreams[streamind].theDataStreamParameter.Parametertype << " "
257                    << (*_list_nodes)[ind].theListOfInDataStreams[streamind].theDataStreamParameter.Parameterdependency << " "
258                    << (*_list_nodes)[ind].theListOfInDataStreams[streamind].theKindOfSchema << " "
259                    << (*_list_nodes)[ind].theListOfInDataStreams[streamind].theKindOfInterpolation << " "
260                    << (*_list_nodes)[ind].theListOfInDataStreams[streamind].theKindOfExtrapolation << " " << endl ;
261             streamind += 1 ;
262           }
263           else {
264             cdebug << "GraphBase::Graph::GetNodes " << aCNode->Name() << " " << anInPort->NodeName() << " " << anInPort->PortName() << " "
265                    << anInPort->Kind() << " IsDataStream " << anInPort->IsDataStream() << endl ;
266           }
267         }
268
269         (*_list_nodes)[ind].theListOfOutDataStreams.resize( aCNode->DataStreamOutPortsNumber() ) ;
270         cdebug << "GraphBase::Graph::GetNodes " << aCNode->Name() << " " << aCNode->DataStreamOutPortsNumber() << " DataStreamOutPortsNumber" << endl ;
271         streamind = 0 ;
272         for ( iostream = 0 ; iostream < aCNode->GetNodeOutPortsSize() ; iostream++ ) {
273           const GraphBase::OutPort * anOutPort ;
274           anOutPort = aCNode->GetNodeOutPort( iostream ) ;
275           if ( anOutPort->IsDataStream() ) {
276             cdebug << "GraphBase::Graph::GetNodes Out" << iostream << " " << aCNode->Name() << " " << anOutPort->NodeName() << " " << anOutPort->PortName() << " "
277                    << endl ;
278             (*_list_nodes)[ind].theListOfOutDataStreams[streamind].theDataStreamParameter.Parametertype = StringToDataStreamType( anOutPort->PortType() ) ;
279             (*_list_nodes)[ind].theListOfOutDataStreams[streamind].theDataStreamParameter.Parametername = CORBA::string_dup( anOutPort->PortName() ) ;
280             (*_list_nodes)[ind].theListOfOutDataStreams[streamind].theDataStreamParameter.Parameterdependency = anOutPort->Dependency() ;
281             long aNumberOfValues = ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues() ;
282             (*_list_nodes)[ind].theListOfOutDataStreams[streamind].theNumberOfValues = aNumberOfValues ;
283             cdebug << "GraphBase::Graph::GetNodes " << aCNode->Name() << " " << anOutPort->NodeName() << " " << anOutPort->PortName() << " "
284                    <<  anOutPort->Dependency() << " " << aNumberOfValues << " list_nodes "
285                    << (*_list_nodes)[ind].theListOfOutDataStreams[streamind].theDataStreamParameter.Parametername << " "
286                    << (*_list_nodes)[ind].theListOfOutDataStreams[streamind].theDataStreamParameter.Parametertype << " "
287                    << (*_list_nodes)[ind].theListOfOutDataStreams[streamind].theDataStreamParameter.Parameterdependency << " "
288                    << (*_list_nodes)[ind].theListOfOutDataStreams[streamind].theNumberOfValues << endl ;
289             streamind += 1 ;
290           }
291           else {
292             cdebug << "GraphBase::Graph::GetNodes " << aCNode->Name() << " " << anOutPort->NodeName() << " " << anOutPort->PortName() << " "
293                    << anOutPort->Kind() << " IsDataStream " << anOutPort->IsDataStream() << endl ;
294           }
295         }
296
297         (*_list_nodes)[ind].theService = *aCNode->GetService();
298         cdebug << "GraphBase::Graph::GetNodes theService " << &(*_list_nodes)[ind].theService.ServiceName << endl ;
299         unsigned int i ;
300         for ( i = 0 ; i < (*_list_nodes)[ind].theService.ServiceinParameter.length() ; i++ ) {
301           cdebug << "     In" << i << " " << &(*_list_nodes)[ind].theService.ServiceinParameter[i].Parametername
302                  << " " << (*_list_nodes)[ind].theService.ServiceinParameter[i].Parametername
303                  << " " << &(*_list_nodes)[ind].theService.ServiceinParameter[i].Parametertype
304                  << " " << (*_list_nodes)[ind].theService.ServiceinParameter[i].Parametertype << endl ;
305         }
306         for ( i = 0 ; i < (*_list_nodes)[ind].theService.ServiceoutParameter.length() ; i++ ) {
307           cdebug << "     Out" << i << " " << &(*_list_nodes)[ind].theService.ServiceoutParameter[i].Parametername
308                  << " " << (*_list_nodes)[ind].theService.ServiceoutParameter[i].Parametername
309                  << " " << &(*_list_nodes)[ind].theService.ServiceoutParameter[i].Parametertype
310                  << " " << (*_list_nodes)[ind].theService.ServiceoutParameter[i].Parametertype << endl ;
311         }
312         for ( i = 0 ; i < (*_list_nodes)[ind].theService.ServiceinDataStreamParameter.length() ; i++ ) {
313           cdebug << "     InDataStream" << i << " " << &(*_list_nodes)[ind].theService.ServiceinDataStreamParameter[i].Parametername
314                  << " " << (*_list_nodes)[ind].theService.ServiceinDataStreamParameter[i].Parametername
315                  << " " << &(*_list_nodes)[ind].theService.ServiceinDataStreamParameter[i].Parametertype
316                  << " " << (*_list_nodes)[ind].theService.ServiceinDataStreamParameter[i].Parametertype << endl ;
317         }
318         for ( i = 0 ; i < (*_list_nodes)[ind].theService.ServiceoutDataStreamParameter.length() ; i++ ) {
319           cdebug << "     OutDataStream" << i << " " << &(*_list_nodes)[ind].theService.ServiceoutDataStreamParameter[i].Parametername
320                  << " " << (*_list_nodes)[ind].theService.ServiceoutDataStreamParameter[i].Parametername
321                  << " " << &(*_list_nodes)[ind].theService.ServiceoutDataStreamParameter[i].Parametertype
322                  << " " << (*_list_nodes)[ind].theService.ServiceoutDataStreamParameter[i].Parametertype << endl ;
323         }
324         if ( aCNode->IsOneOfInLineNodes() ) {
325           GraphBase::InLineNode * aINode = (GraphBase::InLineNode * ) aCNode ;
326           GraphBase::LoopNode * aLNode = NULL ;
327           if ( aCNode->IsLoopNode() ) {
328             aLNode = (GraphBase::LoopNode * ) aCNode ;
329             (*_list_nodes)[ind].theListOfPythonFunctions.resize( 3 ) ;
330             (*_list_nodes)[ind].theListOfPythonFunctions[ 0 ] = aINode->PythonFunction() ;
331             (*_list_nodes)[ind].theListOfPythonFunctions[ 1 ] = aLNode->MorePythonFunction() ;
332             (*_list_nodes)[ind].theListOfPythonFunctions[ 2 ] = aLNode->NextPythonFunction() ;
333           }
334           else if ( aCNode->IsInLineNode() || aCNode->IsGOTONode() ||
335                     aCNode->IsSwitchNode() || aCNode->IsEndSwitchNode() ) {
336             (*_list_nodes)[ind].theListOfPythonFunctions.resize( 1 ) ;
337             (*_list_nodes)[ind].theListOfPythonFunctions[ 0 ] = aINode->PythonFunction() ;
338           }
339         }
340         (*_list_nodes)[ind].theFirstCreation = aCNode->FirstCreation();
341         (*_list_nodes)[ind].theLastModification = aCNode->LastModification();
342 //JR 24.02.2005 Memory Leak        (*_list_nodes)[ind].theEditorRelease = CORBA::string_dup( aCNode->EditorRelease());
343         (*_list_nodes)[ind].theEditorRelease = string( aCNode->EditorRelease());
344 //JR 24.02.2005 Memory Leak        (*_list_nodes)[ind].theAuthor = CORBA::string_dup( aCNode->Author());
345         if ( aCNode->IsFactoryNode() ) {
346           GraphBase::FactoryNode * aFNode = (GraphBase::FactoryNode * ) aCNode ;
347 //JR 24.02.2005 Memory Leak          (*_list_nodes)[ind].theContainer = CORBA::string_dup( aFNode->Computer());
348           (*_list_nodes)[ind].theContainer = string( aFNode->Computer());
349         }
350         else {
351 //JR 24.02.2005 Memory Leak          (*_list_nodes)[ind].theContainer = CORBA::string_dup( "" );
352           (*_list_nodes)[ind].theContainer = string( "" );
353         }
354 //JR 24.02.2005 Memory Leak        (*_list_nodes)[ind].theComment = CORBA::string_dup( aCNode->Comment());
355         (*_list_nodes)[ind].theComment = string( aCNode->Comment());
356         (*_list_nodes)[ind].theCoords.theX = aCNode->XCoordinate();
357         (*_list_nodes)[ind].theCoords.theY = aCNode->YCoordinate();
358 #if 0
359         int nports = 0 ;
360         int i ;
361         for ( i = 0 ; i < aCNode->GetNodeInPortsSize() ; i++ ) {
362           const GraphBase::InPort * anInPort = aCNode->GetNodeInPort( i ) ;
363           if ( anInPort->IsBus() ) {
364             nports += 1 ;
365             (*_list_nodes)[ind].theListOfParameters.resize( nports ) ;
366 //JR 24.02.2005 Memory Leak            (*_list_nodes)[ind].theListOfParameters[ nports-1 ].theInParameter.Parametertype = CORBA::string_dup( anInPort->PortType() ) ;
367             (*_list_nodes)[ind].theListOfParameters[ nports-1 ].theInParameter.Parametertype = string( anInPort->PortType() ) ;
368 //JR 24.02.2005 Memory Leak            (*_list_nodes)[ind].theListOfParameters[ nports-1 ].theInParameter.Parametername = CORBA::string_dup( anInPort->PortName() ) ;
369             (*_list_nodes)[ind].theListOfParameters[ nports-1 ].theInParameter.Parametername = string( anInPort->PortName() ) ;
370 //JR 24.02.2005 Memory Leak            (*_list_nodes)[ind].theListOfParameters[ nports-1 ].theOutParameter.Parametertype = CORBA::string_dup( aCNode->GetNodeOutPort( anInPort->PortIndex() )->PortType() ) ;
371             (*_list_nodes)[ind].theListOfParameters[ nports-1 ].theOutParameter.Parametertype = string( aCNode->GetNodeOutPort( anInPort->PortIndex() )->PortType() ) ;
372 //JR 24.02.2005 Memory Leak            (*_list_nodes)[ind].theListOfParameters[ nports-1 ].theOutParameter.Parametername = CORBA::string_dup( aCNode->GetNodeOutPort( anInPort->PortIndex() )->PortName() ) ;
373             (*_list_nodes)[ind].theListOfParameters[ nports-1 ].theOutParameter.Parametername = string( aCNode->GetNodeOutPort( anInPort->PortIndex() )->PortName() ) ;
374           }
375         }
376 #endif
377       }
378     }
379   }
380   cdebug_out << "GraphBase::Graph::GetNodes" << endl ;
381   return _list_nodes ;
382 }
383
384
385 //----------------------------------------------------------------------
386 // Function : GetLinks
387 // Purpose  : get a links list
388 //----------------------------------------------------------------------
389 GraphBase::ListOfSLinks * GraphBase::Graph::GetLinks(bool AllLinks ) const {
390   GraphBase::ListOfSLinks * _list_links = new GraphBase::ListOfSLinks;
391
392 // All the links from _LinksList are taken
393 //  vector< InNode *> Nodes = InNodes() ;
394
395   cdebug_in << "Graph::GetLinks( " << AllLinks << " ) " << endl ;
396   int ind = 0 ;
397   int k ;
398   for ( k = 0 ; k < GraphNodesSize() ; k++ ) {
399     GraphBase::ComputingNode * fromNode = GraphNodes( k ) ;
400 //    cdebug << "GraphBase::Graph::GetLinks k" << k << ". :" << fromNode->Name() << endl ;
401     int i ;
402     for ( i = 0 ; i < fromNode->GetNodeOutPortsSize() ; i++ ) {
403       const GraphBase::OutPort* fromPort = fromNode->GetNodeOutPort( i ) ;
404 //      cdebug << "GraphBase::Graph::GetLinks k" << k << ". :" << fromNode->Name()
405 //             << " i" << i << ". : " << fromPort->PortName() << endl ;
406       int j ;
407       for ( j = 0 ; j < fromPort->InPortsSize() ; j++ ) {
408         const GraphBase::InPort* toPort = fromPort->InPorts( j ) ;
409 //        cdebug << "GraphBase::Graph::GetLinks k" << k << ". : fromNode " << fromNode << " = "
410 //               << fromNode->Name() << " i" << i << ". : fromPort " << fromPort << " = "
411 //               << fromPort->PortName() << " j" << j << ". : toPort " << toPort << " = "
412 //               << toPort->NodeName() << "( " << toPort->PortName() << " )" << endl ;
413         if ( toPort->IsPortConnected() ) {
414 // Desole pour ce cast mais avec les maps difficile de faire const ...
415 //          const GraphBase::ComputingNode * toNode = ((GraphBase::Graph * ) this)->GetGraphNode( toPort->NodeName() ) ;
416 //          cdebug << "GraphBase::Graph::GetLinks " << fromNode->Name() << " ("
417 //                 << fromPort->PortName() << " ) IsPortConnected" << fromPort->IsPortConnected()
418 //                 << " --> toNode " << toNode << " " << toPort->NodeName() << "( "
419 //                 << toPort->PortName() << " ) " << " " << fromPort->InPortsSize() << " ports"
420 //                 << endl ;
421           if ( !(fromPort->IsLoop() && toPort->IsLoop() ) || AllLinks ) {
422 //            cdebug << "GraphBase::Graph::GetLinks " << fromNode->Name() << " ("
423 //                   << fromPort->PortName() << " ) IsPortConnected" << fromPort->IsPortConnected()
424 //                   << " --> " << toNode->Name() << "( " << toPort->PortName() << " ) "
425 //                   << " " << fromPort->InPortsSize() << " ports" << endl ;
426             _list_links->resize( ind+1 );
427 //JR 23.02.2005 Memory Leak            (*_list_links)[ind].FromNodeName = CORBA::string_dup( fromNode->Name() );
428             (*_list_links)[ind].FromNodeName = string( fromNode->Name() );
429             (*_list_links)[ind].FromServiceParameterName = fromPort->GetServicesParameter().Parametername;
430 //JR 23.02.2005 Memory Leak            (*_list_links)[ind].ToNodeName = CORBA::string_dup( toPort->NodeName() );
431             (*_list_links)[ind].ToNodeName = string( toPort->NodeName() );
432             (*_list_links)[ind].ToServiceParameterName = toPort->GetServicesParameter().Parametername;
433 //JR 30.03.2005            (*_list_links)[ind].aLinkValue = *fromPort->Value() ;
434             (*_list_links)[ind].aLinkValue = fromPort->Value() ;
435             if ( toPort->IsEndSwitch() ) {
436               (*_list_links)[ind++].aListOfCoords = *(fromPort->Coords()) ;
437             }
438             else {
439               (*_list_links)[ind++].aListOfCoords = *(toPort->Coords()) ;
440             }
441           }
442         }
443         else {
444 //          cdebug << "GraphBase::Graph::GetLinks " << fromNode->Name() << " "
445 //                 << fromPort->PortName() << " ) " << fromPort->PortStatus()
446 //                 << " --> " << toPort->NodeName() << "( " << toPort->PortName() << " ) "
447 //                 << " " << toPort->PortStatus() << " " << fromPort->InPortsSize()
448 //                 << " ports ignored" << endl ;
449         }
450       }
451     }
452   }
453
454   cdebug_out << "Graph::GetLinks( " << AllLinks << " ) " << endl ;
455   return _list_links;
456 }
457
458 GraphBase::ListOfSGraphs * GraphBase::Graph::GetGraphs() const {
459   GraphBase::ListOfSGraphs * _list_graphs = new GraphBase::ListOfSGraphs;
460
461   return _list_graphs;
462 }
463
464 GraphBase::SLink * GraphBase::Graph::GetLink( GraphBase::ComputingNode * aNode ,
465                                               GraphBase::InPort* toPort ) {
466   GraphBase::SLink * _link =  new GraphBase::SLink ;
467   GraphBase::OutPort* fromPort = toPort->GetOutPort() ;
468 //JR 24.02.2005 Memory Leak  _link->FromNodeName = CORBA::string_dup( fromPort->NodeName() );
469   _link->FromNodeName = string( fromPort->NodeName() );
470   _link->FromServiceParameterName = fromPort->GetServicesParameter().Parametername;
471 //JR 24.02.2005 Memory Leak  _link->ToNodeName = CORBA::string_dup( toPort->NodeName() );
472   _link->ToNodeName = string( toPort->NodeName() );
473   _link->ToServiceParameterName = toPort->GetServicesParameter().Parametername;
474 //JR 30.03.2005  CORBA::Any aSPValue = *fromPort->Value() ;
475   CORBA::Any aSPValue = fromPort->Value() ;
476   _link->aLinkValue = aSPValue;
477   _link->aListOfCoords = *(toPort->Coords()) ;
478   return _link;
479 }
480 //----------------------------------------------------------------------
481 // Function : GetDatas
482 // Purpose  : get the datas list
483 //----------------------------------------------------------------------
484 GraphBase::ListOfSLinks * GraphBase::Graph::GetDatas() const {
485   GraphBase::ListOfSLinks * _list_datalinks = new GraphBase::ListOfSLinks;
486
487   int ind = 0 ;
488   const GraphBase::DataNode * aDataNode = this ;
489   int i ;
490   for ( i = 0 ; i < aDataNode->GetNodeInDataNodePortsSize() ; i++ ) {
491     const GraphBase::OutPort* fromDataPort = aDataNode->GetNodeInDataNodePort( i ) ;
492     if ( GraphMacroLevel() == 0 ) {
493       if ( fromDataPort->IsDataConnected() ) {
494         int j ;
495 //We may have SharedData as input of a DataFlow : same input for one or several
496 // input ports. Input(s) of a DataFlow match one or several output-virtual-dataport
497         for ( j = 0 ; j < fromDataPort->InPortsSize() ; j++ ) {
498           _list_datalinks->resize( ind+1 );
499 //JR 24.02.2005 Memory Leak          (*_list_datalinks)[ind].FromNodeName = CORBA::string_dup( aDataNode->Name() );
500           (*_list_datalinks)[ind].FromNodeName = string( aDataNode->Name() );
501           (*_list_datalinks)[ind].FromServiceParameterName = fromDataPort->GetServicesParameter().Parametername;
502           const GraphBase::InPort* toPort = fromDataPort->InPorts( j ) ;
503 //JR 24.02.2005 Memory Leak          (*_list_datalinks)[ind].ToNodeName = CORBA::string_dup( toPort->NodeName() );
504           (*_list_datalinks)[ind].ToNodeName = string( toPort->NodeName() );
505           (*_list_datalinks)[ind].ToServiceParameterName = toPort->GetServicesParameter().Parametername;
506 //JR 30.03.2005          CORBA::Any aSPValue = *fromDataPort->Value() ;
507           CORBA::Any aSPValue = fromDataPort->Value() ;
508           (*_list_datalinks)[ind].aLinkValue = aSPValue;
509           (*_list_datalinks)[ind++].aListOfCoords = *(toPort->Coords()) ;
510         }
511       }
512     }
513   }
514
515   return _list_datalinks ;
516 }
517
518 bool GraphBase::Graph::AddNode( GraphBase::ComputingNode * aNode ) {
519   cdebug_in << "GraphBase::Graph::AddNode "  << (void *) aNode << " " << aNode->Name() << " " << aNode->ServiceName() << endl;
520   bool RetVal = false ;
521   int index = GetGraphNodeIndex( aNode->Name() ) ;
522   if ( index < 0 ) {
523     cdebug << "GraphBase::Graph::AddNode " << _GraphNodesSize << " nodes + 1" << endl ;
524     _GraphNodes.resize( _GraphNodesSize+1 ) ;
525     _GraphNodes[ _GraphNodesSize ] = aNode ;
526     SetGraphNodeIndex( aNode->Name() , _GraphNodesSize ) ;
527     _GraphNodesSize += 1 ;
528     if ( SetServiceOfMap( (GraphBase::Service * ) aNode ) ) {
529       cdebug << "Graph::AddNode SetServiceOfMap " << aNode->ServiceName() << " in MapOfServices" << endl ; 
530     }
531     else {
532       cdebug << "Graph::AddNode SetServiceOfMap " << aNode->ServiceName()
533              << " was already in MapOfServices" << endl ; 
534     }
535
536     RetVal = true ;
537     int i ;
538     cdebug << "GraphBase::Graph::AddNode " << _GraphNodesSize << " Known nodes :" << endl ;
539     for ( i = 0 ; i < _GraphNodesSize ; i++ ) {
540       const GraphBase::ComputingNode * aKnownNode = GetGraphNode( i ) ;
541       if ( aKnownNode ) {
542         cdebug << i << ". " << aKnownNode->Name() << " " << _MapOfGraphNodes[ GetGraphNode( i )->Name() ] - 1 << endl ;
543       }
544       else {
545         cdebug << i << ". ERROR" << endl ;
546       }
547     }
548     aNode->GraphOfNode( this ) ;
549   }
550   cdebug_out << "GraphBase::Graph::AddNode " << _GraphNodesSize << " Nodes. "
551              << aNode->ServiceName() << endl;
552   return RetVal ;
553 }
554
555 bool GraphBase::Graph::ReNameNode( const char* OldNodeName ,
556                                    const char* NewNodeName ) {
557   cdebug_in << "GraphBase::Graph::ReNameNode (" << OldNodeName << " , " << NewNodeName << ") "
558             << endl;
559   int i ;
560   bool RetVal = false ;
561 //#if 0
562   GraphBase::ComputingNode * anOldNode = GetChangeGraphNode( OldNodeName ) ;
563   for ( i = 0 ; i < anOldNode->LinkedNodesSize() ; i++ ) {
564     cdebug << "LinkedNode " << i << " " << anOldNode->LinkedNodes( i )->Name() << endl ;
565   }
566 //#endif
567   if ( !strcmp( OldNodeName , NewNodeName ) ) {
568     RetVal = true ;
569   }
570   else if ( strcmp( Name() , OldNodeName ) ) {
571     int index = GetGraphNodeIndex( OldNodeName ) ;
572     int newindex = GetGraphNodeIndex( NewNodeName ) ;
573     if ( index >= 0 && index < _GraphNodesSize &&
574          ( newindex < 0 || newindex > _GraphNodesSize ) ) {
575       _GraphNodes[ index ]->Name( NewNodeName ) ;
576       _MapOfGraphNodes.erase( OldNodeName ) ;
577       SetGraphNodeIndex( NewNodeName , index ) ;
578
579       GraphBase::ComputingNode * aNode = GetChangeGraphNode( index ) ;
580 // Update 'ToNode's Map from 'aNode'
581       cdebug << "Graph::ReNameNode " << aNode->Name() << " LinkedNodesSize : "
582              << aNode->LinkedNodesSize() << endl ;
583       for ( i = 0 ; i < aNode->LinkedNodesSize() ; i++ ) {
584         GraphBase::StreamNode * ToNode = aNode->LinkedNodes( i ) ;
585         ToNode->ReNameLinkedFromNode( OldNodeName , NewNodeName ) ;
586       }
587 // Rename in _MapOfLinkedNodes of 'FromNode'
588       cdebug << "Graph::ReNameNode " << aNode->Name() << " LinkedFromNodesSize : "
589              << aNode->LinkedFromNodesSize() << endl ;
590       for ( i = 0 ; i < aNode->LinkedFromNodesSize() ; i++ ) {
591         GraphBase::StreamNode * FromNode = aNode->LinkedFromNodes( i ) ;
592         if ( FromNode->GetLinkedNodeIndex( OldNodeName ) >= 0 ) {
593           FromNode->ReNameLinkedNode( OldNodeName , NewNodeName ) ;
594         }
595         else {
596           FromNode->ReNameStreamLinkedNode( OldNodeName , NewNodeName ) ;
597         }
598       }
599 // Inports 'anInPort' of 'aNode'
600       for ( i = aNode->GetNodeInPortsSize()-1 ; i >= 0 ; i-- ) {
601         GraphBase::InPort * anInPort = aNode->GetChangeNodeInPort( i ) ;
602 // OutPort 'anOutPort' linked to 'anInPort'
603         GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
604         cdebug << i << ". " << aNode->Name() << " " << "GraphBase::Graph::ReNameNode of LinkedNode : from " ;
605         if ( anOutPort ) {
606           cdebug << anOutPort->NodeName() ;
607         }
608         else {
609           cdebug << "without link" ;
610         }
611         cdebug << " to " << i << ". " << anInPort->PortName() << " of " << NewNodeName ;
612         if ( !anInPort->IsNotConnected() ) {
613           if ( anOutPort->IsDataConnected() ) {
614             cdebug << " fromDataConnected " << anOutPort->NodeName() << endl ;
615           }
616           else {
617 // Node 'FromNode' of 'anOutPort'
618             GraphBase::ComputingNode * FromNode ;
619             if ( strcmp( anOutPort->NodeName() , Name() ) ) {
620               FromNode = GetChangeGraphNode( anOutPort->NodeName() ) ;
621             }
622             else {
623               FromNode = this ;
624             }
625             cdebug << " fromConnected " << anOutPort->NodeName() << endl ;
626 #if 0
627 //JR 26.01.2005 : a same node may be renamed severeal times. So this is done above
628 // Rename in _MapOfLinkedFromNodes of 'FromNode'
629             if ( anInPort->IsDataStream() ) {
630               FromNode->ReNameStreamLinkedNode( OldNodeName , NewNodeName ) ;
631             }
632             else {
633               FromNode->ReNameLinkedNode( OldNodeName , NewNodeName ) ;
634             }
635 #endif
636           }
637           char* OldNodePortName = new char[ strlen( OldNodeName ) +
638                                             strlen( aNode->GetChangeNodeInPort( i )->PortName() ) + 3 ] ;
639           char* NewNodePortName = new char[ strlen( NewNodeName ) +
640                                             strlen( aNode->GetChangeNodeInPort( i )->PortName() ) + 3 ] ;
641           strcpy( OldNodePortName , OldNodeName ) ;
642 //          strcat( OldNodePortName , "\\" ) ;
643           strcat( OldNodePortName , "__" ) ;
644           strcat( OldNodePortName , aNode->GetChangeNodeInPort( i )->PortName() ) ;
645           strcpy( NewNodePortName , NewNodeName ) ;
646 //          strcat( NewNodePortName , "\\" ) ;
647           strcat( NewNodePortName , "__" ) ;
648           strcat( NewNodePortName , aNode->GetChangeNodeInPort( i )->PortName() ) ;
649           RetVal = anOutPort->ReNameInPort( OldNodePortName , NewNodePortName ) ;
650           delete [] OldNodePortName ;
651           delete [] NewNodePortName ;
652           if ( !RetVal )
653             break ;
654         }
655         else {
656           cdebug << " not connected" << endl ;
657           RetVal = true ;
658         }
659       }
660       RetVal = true ;
661 // PAL8508
662 //JR 02.02.2005 DEBUG : ReName in the CoupledNode was missing
663       if ( aNode->IsLoopNode() || aNode->IsEndLoopNode() ||
664            aNode->IsSwitchNode() || aNode->IsEndSwitchNode() ) {
665         GraphBase::GOTONode * theCoupledNode = NULL ;
666         theCoupledNode = (GraphBase::GOTONode * ) ((GraphBase::GOTONode * ) aNode)->CoupledNode() ;
667         theCoupledNode->CoupledNodeName( aNode->Name() ) ;
668       }
669       else if ( aNode->IsInLineNode() ) {
670         GraphBase::OutPort * anOutPort = aNode->GetNodeInGate()->GetOutPort() ;
671         if ( anOutPort ) {
672           GraphBase::ComputingNode * aLinkedNode ;
673           aLinkedNode = GetChangeGraphNode( anOutPort->NodeName() ) ;
674           if ( aLinkedNode->IsGOTONode() ) {
675             ((GraphBase::GOTONode * ) aLinkedNode)->CoupledNodeName( aNode->Name() ) ;
676           }
677         }
678       }
679     }
680     else {
681       cdebug << "ERROR Node not found" << endl ;
682     }
683   }
684   else {
685     RetVal = Name( NewNodeName ) ;
686   }
687
688   cdebug_out << "GraphBase::Graph::ReNameNode RetVal " << RetVal << endl;
689   return RetVal ;
690 }
691
692 bool GraphBase::Graph::RemoveNode( const char* aNodeName ) {
693   cdebug_in << "Graph::RemoveNode (" << aNodeName << ") " << endl;
694   int i ;
695   bool RetVal = false ;
696   int index = GetGraphNodeIndex( aNodeName ) ;
697   GraphBase::ComputingNode * aNode = NULL ;
698   if ( index >= 0 ) {
699     aNode = GetChangeGraphNode( index ) ;
700   }
701   if ( aNode ) {
702     cdebug << "Graph::RemoveNode " << aNode->Name() << " : " << aNode->GetNodeInPortsSize()
703            << " InPorts " << aNode->GetNodeOutPortsSize() << " OutPorts "
704            << aNode->LinkedNodesSize() << " LinkedNodes " << aNode->LinkedFromNodesSize()
705            << " LinkedFromNodes IsEndSwitchNode " << aNode->IsEndSwitchNode()
706            << " ConnectedInPortsNumber " << aNode->ConnectedInPortsNumber() << endl ;
707     for ( i = 0 ; i < aNode->LinkedNodesSize() ; i++ ) {
708       cdebug << "         LinkedNode" << i << ". " << aNode->LinkedNodes( i ) << " "
709              << aNode->LinkedNodes( i )->Name() << endl ;
710     }
711     if ( !aNode->IsEndLoopNode() ) { // The LoopNode is already deleted
712       for ( i = 0 ; i < aNode->LinkedFromNodesSize() ; i++ ) {
713         cdebug << "         LinkedFromNode" << i << ". " << aNode->LinkedFromNodes( i ) << " "
714                << aNode->LinkedFromNodes( i )->Name() << endl ;
715       }
716     }
717 //PAL8177-PAL8509
718 //JR 24.03.2005 : Debug : CoupledNode field of GOTONodes was not erased
719     if ( aNode->IsInLineNode() ) {
720       GraphBase::OutPort * anOutPort = aNode->GetNodeInGate()->GetOutPort() ;
721       if ( anOutPort ) {
722         GraphBase::ComputingNode * aLinkedNode ;
723         aLinkedNode = GetChangeGraphNode( anOutPort->NodeName() ) ;
724         if ( aLinkedNode->IsGOTONode() ) {
725           cdebug << "Graph::RemoveNode erase CoupledNode " << aLinkedNode->Name() << endl ;
726           ((GraphBase::GOTONode * ) aLinkedNode)->CoupledNode( NULL ) ;
727           ((GraphBase::GOTONode * ) aLinkedNode)->CoupledNodeName( "" ) ;
728         }
729       }
730     }
731     if ( !aNode->IsEndSwitchNode() ) {
732       if ( aNode->GetNodeInPortsSize() ) {
733         for ( i = aNode->GetNodeInPortsSize()-1 ; i >= 0 ; i-- ) {
734           GraphBase::InPort * anInPort = aNode->GetChangeNodeInPort( i ) ;
735           cdebug << "Graph::RemoveNode InPort" << i << ". " << aNodeName << "( "
736                  << anInPort->PortName() << ") " << anInPort->PortStatus() << " <-- " ;
737           GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
738           if ( anOutPort && !( aNode->IsEndLoopNode() && anInPort->IsLoop() ) ) {
739             cdebug << anOutPort->NodeName() << "( " << anOutPort->PortName() << ") "
740                    << anOutPort->PortStatus() ;
741           }
742           cdebug << endl ;
743           if ( !anInPort->IsNotConnected() ) {
744             GraphBase::ComputingNode * FromNode = NULL ;
745             RetVal = true ;
746             if ( anOutPort->IsDataConnected() || anOutPort->IsExternConnected() ) {
747               cdebug << "     Data/Extern ignored" << endl ;
748             }
749             else {
750               FromNode = GetChangeGraphNode( anOutPort->NodeName() ) ;
751             }
752             if ( FromNode ) {
753               cdebug << "FromNode " << FromNode->Name() << " LinkedNodesSize "
754                      << FromNode->LinkedNodesSize() << " and " << aNode->Name()
755                      << " LinkedFromNodesSize " << aNode->LinkedFromNodesSize() << endl ;
756               // asv : 04.11.04 : IsGOTO -> IsOneOfGOTO, I believe that it fixes the bug 7120.
757 // JR 05.01.05 : IsOneOfGOTO is not ok : I shall check the bug 7120 with IsGOTONode
758 //            if ( !FromNode->IsOneOfGOTONodes() ) {
759 //            if ( !FromNode->IsGOTONode() ) {
760               if ( !FromNode->IsGOTONode() &&
761                    !( FromNode->IsEndLoopNode() && anInPort->IsLoop() ) ) {
762                 if ( anInPort->IsDataStream() ) {
763                   RetVal = FromNode->RemoveStreamLinkedNode( aNode ) ;
764                 }
765                 else {
766                   RetVal = FromNode->RemoveLinkedNode( aNode ) ;
767                 }
768                 if ( !RetVal ) {
769                   cdebug << "Graph::RemoveNode anOutPort->RemoveLinkedNode Error RetVal "
770                          << RetVal << endl ;
771                   break ;
772                 }
773               }
774             }
775             RetVal = anOutPort->RemoveInPort( anInPort ) ;
776             if ( !RetVal ) {
777               cdebug << "Graph::RemoveNode anOutPort->RemoveInPort( anInPort ) Error RetVal "
778                      << RetVal << endl ;
779               break ;
780             }
781           }
782           else {
783             RetVal = true ;
784           }
785         }
786       }
787       else {
788         RetVal = true ;
789       }
790     }
791     else {
792 // Special case of EndSwitchNodes : each Input port must be multi-connected.
793 // There is one link for each branch of the switch
794 // But in GraphBase::InPort there is only one field GraphBase::OutPort *
795 // At execution time there is no problem because only one branch of the switch
796 // may be executed and the Executor set the right OutPort in the field
797 // GraphBase::OutPort * of each InPort of the EndSwitchNode
798 // But here we must remove that node EndSwitch from the LinkedNodes field of
799 // terminal nodes of all branches.
800 // And also in the OutPorts of that terminal nodes of branches we must remove
801 // references to InPorts of the EndSwitchNode.
802
803 // Explore LinkedFromnodes of the EndSwitchNode :
804       for ( i = aNode->LinkedFromNodesSize() - 1 ; i >= 0  ; i-- ) {
805         GraphBase::ComputingNode * aLinkedFromNode = (GraphBase::ComputingNode * ) aNode->LinkedFromNodes( i ) ;
806         cdebug << aLinkedFromNode->Name() << " linked to " << aNode->Name() << endl ;
807         int j ;
808         for ( j = aLinkedFromNode->GetNodeOutPortsSize() - 1 ; j >= 0 ; j-- ) {
809           GraphBase::OutPort * anOutPort = aLinkedFromNode->GetChangeNodeOutPort( j ) ;
810           cdebug << "Graph::RemoveNode OutPort" << j << ". Remove " << anOutPort->InPortsSize()
811                  << " InPortsof OutPort : " << anOutPort->NodeName() << "( "
812                  << anOutPort->PortName() << ") "
813                  << anOutPort->PortStatus() << " :" << endl ;
814           int k ;
815           for ( k = anOutPort->InPortsSize() - 1 ; k >= 0  ; k-- ) {
816             GraphBase::InPort * anInPort = anOutPort->ChangeInPorts( k ) ;
817             if ( !strcmp( anInPort->NodeName() , aNode->Name() ) ) {
818 // InPort of the EndSwitchNode
819               cdebug << "       to InPort" << j << ". " << anInPort->NodeName() << "( "
820                      << anInPort->PortName() << ") "
821                      << anInPort->PortStatus() << endl ;
822               anInPort->RemoveOutPort() ;
823               if ( anOutPort->IsDataStream() ) {
824                 aLinkedFromNode->RemoveStreamLinkedNode( aNode ) ;
825               }
826               else {
827 // false ==> No error for aNode->LinkedFromNode()
828                 RetVal = aLinkedFromNode->RemoveLinkedNode( aNode , false ) ;
829                 if ( !RetVal ) {
830                   cdebug << "Graph::RemoveNode aLinkedFromNode->RemoveLinkedNode Error RetVal "
831                          << RetVal << endl ;
832                   break ;
833                 }
834               }
835 // the InPort of the EndSwitchNode from that OutPort was already removed by
836 // anInPort->RemoveOutPort done above :
837 #if 0
838               RetVal = anOutPort->RemoveInPort( anInPort ) ;
839               if ( !RetVal ) {
840                 cdebug << "Graph::RemoveNode anOutPort->RemoveInPort( anInPort ) Error RetVal "
841                        << RetVal << endl ;
842                 break ;
843               }
844 #endif
845             }
846           }
847         }
848       }
849     }
850
851     if ( RetVal ) {
852       for ( i = aNode->GetNodeOutPortsSize() - 1 ; i >= 0 ; i-- ) {
853         GraphBase::OutPort * anOutPort = aNode->GetChangeNodeOutPort( i ) ;
854         cdebug << "Graph::RemoveNode OutPort" << i << ". Remove " << anOutPort->InPortsSize()
855                << " InPortsof OutPort : " << anOutPort->NodeName() << "( "
856                << anOutPort->PortName() << ") "
857                << anOutPort->PortStatus() << " :" << endl ;
858         int j ;
859         for ( j = anOutPort->InPortsSize() - 1 ; j >= 0  ; j-- ) {
860           GraphBase::InPort * anInPort = anOutPort->ChangeInPorts( j ) ;
861           GraphBase::ComputingNode * ToNode = NULL ;
862           cdebug << "       to InPort" << j << ". " << anInPort->NodeName() << "( "
863                  << anInPort->PortName() << ") "
864                  << anInPort->PortStatus() ;
865           if ( anInPort->IsExternConnected() ) {
866             cdebug << " ExternConnected ignored" << endl ;
867           }
868           else {
869             cdebug << endl ;
870             ToNode = GetChangeGraphNode( anInPort->NodeName() ) ;
871           }
872           if ( ToNode ) {
873             RetVal = anInPort->RemoveOutPort() ;
874 // JR 04.02.2005 : Bug if it is a link to an EndSwitchNode. The InPort may be multiple linked !!!
875 // PAL7990
876             if ( !RetVal ) {
877               cdebug << "Graph::RemoveNode anOutPort->RemoveOutPort Error RetVal " << RetVal
878                      << endl ;
879               break ;
880             }
881             if ( ( aNode->IsGOTONode() && ToNode->IsOneOfInLineNodes() ) ||
882                  ( aNode->IsEndLoopNode() && ToNode->IsLoopNode( ) ) ) {
883             }
884             else if ( anOutPort->IsDataStream() ) {
885               RetVal = aNode->RemoveStreamLinkedNode( ToNode ) ;
886             }
887             else {
888               RetVal = aNode->RemoveLinkedNode( ToNode ) ;
889             }
890             if ( !RetVal ) {
891               cdebug << "Graph::RemoveNode anOutPort->RemoveLinkedNode Error RetVal " << RetVal
892                      << endl ;
893               break ;
894             }
895 // the InPort of the EndSwitchNode from that OutPort was already removed by
896 // anInPort->RemoveOutPort done above :
897 #if 0
898             RetVal = anOutPort->RemoveInPort( anInPort ) ;
899             if ( !RetVal ) {
900               cdebug << "Graph::RemoveNode anOutPort->RemoveInPort( anInPort ) Error RetVal "
901                      << RetVal << endl ;
902               break ;
903             }
904 #endif
905             if ( ToNode->IsEndSwitchNode() ) {
906               int i ;
907               int done = false ;
908               for ( i = 0 ; i < ToNode->LinkedFromNodesSize() ; i++ ) {
909                 GraphBase::StreamNode * fromNode = ToNode->LinkedFromNodes( i ) ;
910 // Not the node that we are deleting ... :
911                 if ( strcmp( fromNode->Name() , aNode->Name() ) ) {
912                   int j ;
913                   for ( j = 0 ; j < fromNode->GetNodeOutPortsSize() ; j++ ) {
914                     GraphBase::OutPort * fromOutPort = fromNode->GetChangeNodeOutPort( j ) ;
915                     int k ;
916                     for ( k = 0 ; k < fromOutPort->InPortsSize() ; k++ ) {
917                       if ( strcmp( ToNode->Name() , fromOutPort->InPorts( k )->NodeName() ) == 0 ) {
918                         if ( strcmp( anInPort->PortName() , fromOutPort->InPorts( k )->PortName() ) == 0 ) {
919 // Restore an OutPort in the InPort
920                           anInPort->ChangeOutPort( fromOutPort ) ;
921                           cdebug << "Graph::RemoveNode reestablish " << fromOutPort->NodeName() << "( "
922                                  << fromOutPort->PortName() << " ) in the InPort of EndSwitch : "
923                                  << ToNode->Name() << "( " << anInPort->PortName() << " )"
924                                  << anInPort->Kind() << " " << anInPort->PortStatus()  << endl;
925                           done = true ;
926                           break ;
927                         }
928                       }
929                     }
930                     if ( done ) {
931                       break ;
932                     }
933                   }
934                   if ( done ) {
935                     break ;
936                   }
937                 }
938               }
939             }
940           }
941         }
942         if ( !RetVal ) {
943           cdebug << "Error RetVal " << RetVal << endl ;
944           break ;
945         }
946       }
947     }
948     if ( aNode->LinkedNodesSize() || aNode->LinkedFromNodesSize() ) {
949       cdebug << "Graph::RemoveNode ERROR LinkedNodesSize " << aNode->LinkedNodesSize()
950              << " LinkedFromNodesSize " << aNode->LinkedFromNodesSize() << endl ;
951       RetVal = 0 ;
952     }
953     cdebug << "Graph::RemoveNode " << aNode->Name() << " : " << aNode->GetNodeInPortsSize()
954            << " InPorts " << aNode->GetNodeOutPortsSize() << " OutPorts "
955            << aNode->LinkedNodesSize() << " LinkedNodes " << aNode->LinkedFromNodesSize()
956            << " LinkedFromNodes " << endl ;
957     for ( i = 0 ; i < aNode->LinkedNodesSize() ; i++ ) {
958       cdebug << "         LinkedNode" << i << ". " << aNode->LinkedNodes( i ) << " "
959              << aNode->LinkedNodes( i )->Name() << endl ;
960     }
961     for ( i = 0 ; i < aNode->LinkedFromNodesSize() ; i++ ) {
962       cdebug << "         LinkedFromNode" << i << ". " << aNode->LinkedFromNodes( i ) << " "
963              << aNode->LinkedFromNodes( i )->Name() << endl ;
964     }
965 // Delete of aNode from the Graph :
966 // The LoopNode is needed by the delete of the EndLoopNode. So the LoopNode will be deleted
967 // when the EndLoopNode is deleted. It is the same for SwitchNode & EndSwitchNode
968     if ( RetVal && !aNode->IsLoopNode() && !aNode->IsSwitchNode() ) {
969       GraphBase::InLineNode * theCoupledNode = NULL ;
970       char * theCoupledNodeName = NULL ;
971       int CoupledIndex = -1 ;
972       if ( aNode->IsEndLoopNode() || aNode->IsEndSwitchNode() ) {
973         theCoupledNodeName = ((GraphBase::GOTONode * ) aNode)->CoupledNodeName() ;
974         theCoupledNode = ((GraphBase::GOTONode * ) aNode)->CoupledNode() ;
975       }
976       cdebug << "Graph::RemoveNode Node" << index << " " << _GraphNodes[ index ]->Name()
977              << " will be deleted" << endl ;
978       delete aNode ;
979       _GraphNodesSize -= 1 ;
980       for ( i = index ; i < _GraphNodesSize ; i++ ) {
981         _GraphNodes[ i ] = _GraphNodes[ i+1 ] ;
982         SetGraphNodeIndex( _GraphNodes[ i ]->Name() , i ) ;
983       }
984       _GraphNodes.resize( _GraphNodesSize+1 ) ;
985       _MapOfGraphNodes.erase( aNodeName ) ;
986 // PAL8510
987 // Delete of the LoopNode of that EndLoopNode or of the SwitchNode of that EndSwitchNode :
988       if ( theCoupledNode ) {
989 //JR 02.02.2005 DEBUG : CoupledIndex must be here after the delete of aNode (not before)
990         CoupledIndex = GetGraphNodeIndex( theCoupledNodeName ) ;
991         cdebug << "Graph::RemoveNode CoupledNode" << CoupledIndex << " "
992                << _GraphNodes[ CoupledIndex ]->Name() << " will be deleted" << endl ;
993         delete theCoupledNode ;
994         _GraphNodesSize -= 1 ;
995         for ( i = CoupledIndex ; i < _GraphNodesSize ; i++ ) {
996           _GraphNodes[ i ] = _GraphNodes[ i+1 ] ;
997           SetGraphNodeIndex( _GraphNodes[ i ]->Name() , i ) ;
998         }
999         _GraphNodes.resize( _GraphNodesSize+1 ) ;
1000         _MapOfGraphNodes.erase( theCoupledNodeName ) ;
1001       }
1002       RetVal = true ;
1003     }
1004   }
1005   else {
1006     cdebug << "Graph::RemoveNode Node not found ERROR " << index << endl ;
1007   }
1008
1009 #if 1
1010   cdebug << "Graph::RemoveNode " << _GraphNodesSize << " known nodes" << endl;
1011   for ( i = 0 ; i < _GraphNodesSize ; i++ ) {
1012     cdebug << "Node" << i << _GraphNodes[ i ]->Name() << endl ;
1013   }
1014   map< string , int >::iterator aMapOfGraphNodesIterator ;
1015   i = 0 ;
1016   for ( aMapOfGraphNodesIterator = _MapOfGraphNodes.begin() ;
1017     aMapOfGraphNodesIterator != _MapOfGraphNodes.end() ; aMapOfGraphNodesIterator++ ) {
1018     cdebug << "MapOfGraphNodes " << i++ << " " << aMapOfGraphNodesIterator->first << " --> "
1019            << aMapOfGraphNodesIterator->second << " - 1" << endl ;
1020   }
1021 #endif
1022
1023   cdebug_out << "Graph::RemoveNode " << RetVal << endl;
1024   return RetVal ;
1025 }
1026
1027 bool GraphBase::Graph::AddLink( const char* FromNodeName ,
1028                                 const char* FromServiceParameterName ,
1029                                 const char* ToNodeName ,
1030                                 const char* ToServiceParameterName ) {
1031 //                                , const CORBA::Any aValue ) {
1032   bool RetVal ;
1033 //  int index ;
1034   cdebug_in << "GraphBase::Graph::AddLink(" << FromNodeName << "("
1035             << FromServiceParameterName << ") ---> " << ToNodeName << "("
1036             << ToServiceParameterName << ") , aValue )" << endl;
1037
1038   GraphBase::ComputingNode *fromNode = GetChangeGraphNode( FromNodeName ) ;
1039   GraphBase::ComputingNode *toNode = GetChangeGraphNode( ToNodeName ) ;
1040
1041   GraphBase::OutPort *fromPort = NULL ;
1042   GraphBase::InPort *toPort = NULL ;
1043
1044   if ( fromNode ) {
1045     // asv : 29.12.04 : as I understand, replacement of "InitLoop" by "DoLoop" was
1046     // done by JR in order to keep old graphs and batch test scripts working after change
1047     // of special Loop's port name from "InitLoop" to "DoLoop".  I suppose, it is not
1048     // needed, all old graphs and tests must be changed to use "DoLoop" name for addressing
1049     // this port..  It we don't do it, ANY port with "InitLoop" name will be replaced by "DoLoop"
1050     // and it can cause unexpected bugs in future...  So I comment out the replacement code. 
1051     //if ( strcmp( FromServiceParameterName , "InitLoop" ) ) {
1052 //JR 12.01.05 : Yes the test is not good ; now I test that PortName only in LoopNodes ==>
1053 //   + old graphs will runs normally (it is not possible to ask CEA to edit their graphs)
1054 //   + in old graphs "InitLoop" and "DoLoop" were reserved parameter names (but not controlled)
1055 //   + in new graphs, I have added a control at port creation of that names : they are refused
1056     if ( !(fromNode->IsLoopNode() && strcmp( FromServiceParameterName , "InitLoop" ) == 0 ) ) {
1057       fromPort = fromNode->GetChangeOutPort( FromServiceParameterName ) ;
1058     }
1059     else {
1060       fromPort = fromNode->GetChangeOutPort( "DoLoop" ) ;
1061     }
1062     if ( !fromPort ) {
1063       cdebug << "ERROR AddLink fromPort " << FromServiceParameterName << " FromNode("
1064            << FromNodeName << ") not found." << endl ;
1065     }
1066   }
1067   else {
1068     cdebug << "ERROR AddLink FromNode " << FromNodeName << " not found." << endl ;
1069   }
1070   if ( toNode ) {
1071     // see comment above
1072 //    if ( strcmp( ToServiceParameterName , "InitLoop" ) ) {
1073     if ( !(toNode->IsLoopNode() && strcmp( ToServiceParameterName , "InitLoop" ) == 0 ) ) {
1074       toPort = toNode->GetChangeInPort( ToServiceParameterName ) ;
1075     }
1076     else {
1077       toPort = toNode->GetChangeInPort( "DoLoop" ) ;
1078     }
1079     if ( !toPort ) {
1080       cdebug << "ERROR AddLink toPort " << ToServiceParameterName << " ToNode("
1081              << ToNodeName << ") not found." << endl ;
1082     }
1083   }
1084   else {
1085     cdebug << "ERROR AddLink toNode " << ToNodeName << " not found." << endl ;
1086   }
1087
1088   RetVal = AddLink( fromNode , fromPort , toNode , toPort ) ;
1089
1090   if ( RetVal ) {
1091     if ( fromPort->IsGate() && toPort->IsGate() ) {
1092       CORBA::Any aValue ;
1093       aValue <<= (long ) 1 ;
1094       fromPort->SetValue( aValue ) ;
1095     }
1096 //    else {
1097 //      const CORBA::Any * aDataValue = new CORBA::Any( aValue ) ;
1098 //      fromPort->Value( aDataValue ) ;
1099 //    }
1100 //    fromPort->PortStatus( DataConnected );
1101   }
1102
1103   cdebug_out << "GraphBase::Graph::AddLink " << RetVal << endl;
1104   return RetVal ;
1105 }
1106
1107 bool GraphBase::Graph::AddLink( GraphBase::ComputingNode *fromNode ,
1108                                 GraphBase::OutPort *fromPort ,
1109                                 GraphBase::ComputingNode *toNode ,
1110                                 GraphBase::InPort *toPort ) {
1111 //  bool RetVal ;
1112
1113   if ( !fromNode ) {
1114     cdebug << "ERROR AddLink fromNode not found." << endl ;
1115     return false ;
1116   }
1117   if ( !fromPort ) {
1118     cdebug << "ERROR AddLink fromPort not found." << endl ;
1119     return false ;
1120   }
1121
1122   if ( !toNode ) {
1123     cdebug << "ERROR AddLink toNode not found." << endl ;
1124     return false ;
1125   }
1126   if ( !toPort ) {
1127     cdebug << "ERROR AddLink toPort not found." << endl ;
1128     return false ;
1129   }
1130   if ( ( fromPort->IsDataStream() && !toPort->IsDataStream() ) ||
1131        ( !fromPort->IsDataStream() && toPort->IsDataStream() ) ) {
1132     cdebug << "AddLink fromPort/toPort Stream/Flow. ERROR" << endl ;
1133     return false ;
1134   }
1135   if ( fromPort->IsDataStream() && fromPort->Dependency() == SALOME_ModuleCatalog::DATASTREAM_TEMPORAL &&
1136        toPort->Dependency() == SALOME_ModuleCatalog::DATASTREAM_ITERATIVE ) {
1137     cdebug << "AddLink fromPort/toPort Stream DATASTREAM_TEMPORAL --> DATASTREAM_ITERATIVE. ERROR" << endl ;
1138     return false ;
1139   }
1140
1141   cdebug_in << "Graph::AddLink( " << fromNode->Name() << "("
1142             << fromPort->PortName() << " " << fromPort->PortStatus() << ") " << fromPort->Kind()
1143             << " ---> " << toNode->Name() << "(" << toPort->PortName() << " " << toPort->PortStatus()
1144             << ") " << toPort->Kind() << " )" << endl;
1145   if ( fromPort->IsDataConnected() || fromPort->IsExternConnected() ) {
1146     if ( !fromPort->RemoveInPort() ) { // There is only one ===> RemoveOutPort()
1147       cdebug_out << "GraphBase::Graph::AddLink(" << fromNode->Name() << "("
1148                  << fromPort->PortName() << " " << fromPort->PortStatus() << ") RemoveInPort ERROR " << endl ;
1149       return false ;
1150     }
1151   }
1152   if ( toPort->IsDataConnected() || toPort->IsExternConnected() ) {
1153     if ( !toPort->GetOutPort()->RemoveInPort() ) { // There is only one ===> RemoveOutPort()
1154       cdebug_out << "GraphBase::Graph::AddLink(" << toNode->Name() << "("
1155                  << toPort->PortName() << " " << toPort->PortStatus() << ") RemoveInPort ERROR " << endl ;
1156       return false ;
1157     }
1158   }
1159   else if ( toPort->IsPortConnected() && !toNode->IsEndSwitchNode() ) {
1160     if ( !RemoveLink( toPort->GetOutPort()->NodeName() ,
1161                       toPort->GetOutPort()->PortName() ,
1162                       toNode->Name() , toPort->PortName() ) ) {
1163       cdebug_out << "RemoveLink(AddLink) toPort->GetOutPort()->NodeName() RemoveLink Error." << endl ;
1164       return false ;
1165     }
1166   }
1167
1168   if ( !fromNode->IsDataFlowNode() && !fromNode->IsDataStreamNode() &&
1169        !toNode->IsDataFlowNode() && !toNode->IsDataStreamNode() &&
1170        toPort->GetOutPort() ) {
1171     if ( !strcmp( toPort->GetOutPort()->NodePortName() ,
1172                   fromPort->NodePortName() ) ) {
1173       cdebug << "Link already exists" << endl ;
1174       cdebug_out << "GraphBase::Graph::AddLink 1" << endl;
1175       return true ;
1176     }
1177     else if ( toPort->IsDataConnected() || toPort->IsExternConnected() ) {
1178       toPort->GetOutPort()->RemoveInPort( toPort ) ; //dbg
1179     }
1180     else if ( fromNode->IsGOTONode() ) {
1181       if ( !RemoveLink( toPort->GetOutPort()->NodeName() ,
1182                         toPort->GetOutPort()->PortName() ,
1183                         toNode->Name() , toPort->PortName() ) ) {
1184         cdebug << "RemoveLink(AddLink) Error."
1185                << endl ;
1186         cdebug_out << "GraphBase::Graph::AddLink" << endl;
1187         return false ;
1188       }
1189       if ( fromPort->InPortsSize() ) {
1190         if ( !RemoveLink( fromNode->Name() , fromPort->PortName() ,
1191                           fromPort->ChangeInPorts(0)->NodeName() ,
1192                           fromPort->ChangeInPorts(0)->PortName() ) ) {
1193           cdebug << "RemoveLink(AddLink) fromNode->IsGOTONode Error." << endl ;
1194           cdebug_out << "GraphBase::Graph::AddLink" << endl;
1195           return false ;
1196         }
1197       }
1198     }
1199 //PAL8511
1200 // JR 17.01.2005 : toPort is already linked : RemoveLink
1201     else if ( !toNode->IsEndSwitchNode() ) {
1202 //    else if ( !toNode->IsEndSwitchNode() ||
1203 //              ( toNode->IsEndSwitchNode() && toPort->IsGate() ) ) {
1204 //JR Debug : the fromPort was wrong !
1205 //      if ( !RemoveLink( fromNode->Name() , fromPort->PortName() ,
1206       if ( !RemoveLink( toPort->GetOutPort()->NodeName() , toPort->GetOutPort()->PortName() ,
1207                         toNode->Name() , toPort->PortName() ) ) {
1208         cdebug << "RemoveLink(AddLink) toNode->IsEndSwitchNode Error." << endl ;
1209         cdebug_out << "GraphBase::Graph::AddLink" << endl;
1210         return false ;
1211       }
1212     }
1213 //PAL8511
1214 //JR Debug 15.02.2005 : Not multiple links in that case except if toPort is the DefaultPort
1215     else if ( fromNode->IsSwitchNode() && toNode->IsEndSwitchNode() && !toPort->IsGate() ) {
1216       cdebug << "fromNode->IsSwitchNode() && toNode->IsEndSwitchNode toPort(NotGate)Error."
1217              << endl ;
1218       cdebug_out << "GraphBase::Graph::AddLink" << endl;
1219       return false ;
1220     }
1221   }
1222 //PAL7990
1223 //JR 24.03.2005 : No Link between OutPort of SwitchNode to InPort of EndSwitchNode except if
1224 // they have the same name for a special case :
1225 // Switch with no branch ==> Default is applied always : GraphSyrControl example
1226   else if ( fromNode->IsSwitchNode() && !fromPort->IsGate() &&
1227             toNode->IsEndSwitchNode() && !toPort->IsGate() &&
1228             strcmp( fromPort->PortName() , toPort->PortName() ) ) {
1229     cdebug << "fromNode->IsSwitchNode() && toNode->IsEndSwitchNode with different PortNames Error." << endl ;
1230     cdebug_out << "GraphBase::Graph::AddLink" << endl;
1231     return false ;
1232   }
1233   else if ( fromNode->IsGOTONode() && fromPort->InPortsSize() ) {
1234     if ( !RemoveLink( fromNode->Name() , fromPort->PortName() ,
1235                       fromPort->ChangeInPorts(0)->NodeName() ,
1236                       fromPort->ChangeInPorts(0)->PortName() ) ) {
1237       cdebug << "RemoveLink(AddLink) fromNode->IsGOTONode Error." << endl ;
1238       cdebug_out << "GraphBase::Graph::AddLink" << endl;
1239       return false ;
1240     }
1241   }
1242   else if ( ( fromNode->IsDataFlowNode() || fromNode->IsDataStreamNode() ) &&
1243        ( toPort->IsDataConnected() || toPort->IsExternConnected() ) ) {
1244     fromPort->RemoveInPort( toPort ) ; //dbg
1245   }
1246   else if ( ( toNode->IsDataFlowNode() || toNode->IsDataStreamNode() ) &&
1247        ( fromPort->IsDataConnected() || fromPort->IsExternConnected() ) ) {
1248     fromPort->RemoveInPort() ; // There is only one
1249   }
1250
1251
1252 // JR 12.01.2005 : an OutPort of a SwitchNode connected to a Gate can be connected only to Gate
1253   if ( !toNode->IsDataFlowNode() && !toNode->IsDataStreamNode() &&
1254        fromNode->IsSwitchNode() && fromPort->IsSwitch() && !toPort->IsGate() ) {
1255     cdebug << "toPort->AddLink Error( fromPort->IsSwitch() && !toPort->IsGate())." << endl ;
1256     cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1257     return false ;
1258   }
1259 //JR 11.02.2005 : SwitchNode(Default) may be only linked to EndSwitchNode(Default)
1260 //                SwitchNode(Param) may be linked to EndSwitchNode(Param)
1261 //                SwitchNode(Param-UserDefault) may be linked to EndSwitchNode(Default)
1262   else if ( fromNode->IsSwitchNode() && toNode->IsEndSwitchNode() &&
1263             !( ( fromPort->IsGate() && toPort->IsGate() ) ||
1264                ( !fromPort->IsGate() ) ) ) {
1265 //               ( !fromPort->IsGate() && !toPort->IsGate() ) ) ) {
1266     cdebug << "SwitchNode(Default) may be only linked to EndSwitchNode(Default) AddLink Error."
1267            << endl ;
1268     cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1269     return false ;
1270   }
1271   else if ( toNode->IsEndSwitchNode() && !toPort->IsGate() ) {
1272 //    if ( !toPort->IsEndSwitch() || !fromPort->AddInPort( toPort ) ) {
1273     if ( !fromPort->AddInPort( toPort ) ) {
1274       cdebug << "toNode->IsEndSwitchNode() : !fromPort->AddInPort( toPort ) AddLink Error."
1275              << endl ;
1276       cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1277       return false ;
1278     }
1279     if ( !toPort->IsDataStream() ) {
1280       toPort->Kind( SUPERV::EndSwitchParameter ) ;
1281     }
1282   }
1283   else if ( !fromPort->AddInPort( toPort ) ) { // --> MapOfInports in the OutPort
1284     cdebug << "!fromPort->AddLink Error." << endl ;
1285     cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1286     return false ;
1287   }
1288
1289   if ( fromNode->IsGOTONode() && ( !fromPort->IsGate() || !toPort->IsGate() ||
1290        toNode->IsEndLoopNode() || toNode->IsEndSwitchNode() ) ) {
1291     cdebug << "toPort->AddLink Error( fromNode->IsGOTONode() && toNode->IsEndInLineNode() )." << endl ;
1292     cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1293     return false ;
1294   }
1295   else if ( !fromNode->IsSwitchNode() && fromPort->IsParam() && toPort->IsGate() ) {
1296     cdebug << "toPort->AddLink Error( fromPort->IsParam() && toPort->IsGate())." << endl ;
1297     cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1298     return false ;
1299   }
1300   else if ( !toNode->IsEndSwitchNode() && !toNode->IsEndLoopNode() ) {
1301     if ( !toPort->AddOutPort( fromPort ) ) { // --> Unique OutPort of the InPort
1302       cdebug << "toPort->AddLink Error." << endl ;
1303       cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1304       return false ;
1305     }
1306   }
1307   else {
1308     toPort->AddOutPort( fromPort ) ;
1309   }
1310
1311   if ( ( fromNode->IsGOTONode() && toNode->IsOneOfInLineNodes() ) ||
1312        ( fromNode->IsEndLoopNode() && toNode->IsLoopNode() ) ) {
1313     cdebug << "AddLink fromPort->PortStatus( PortConnected ) "
1314            << "GOTONode/EndLoopNode-->InLineNode/LoopNode/SwitchNode "
1315            << fromNode->Name() << " " << fromPort->PortName()
1316            << " InLineNode/LoopNode_ConnectedInPortsNumber "
1317            << toNode->ConnectedInPortsNumber() << endl;
1318     if ( fromNode->IsGOTONode() ) {
1319       fromPort->Kind( SUPERV::GOTOParameter ) ;
1320     }
1321     fromPort->PortStatus( PortConnected ); // GOTO - Loop
1322   }
1323   else if ( fromNode->IsDataFlowNode() || fromNode->IsDataStreamNode() ) {
1324     cdebug << "AddLink IsDataFlow/StreamNode fromPort->PortStatus( DataConnected ) : "
1325            << fromNode->Name() << " " << fromPort->PortName() << endl ;
1326     fromPort->PortStatus( ExternConnected );
1327   }
1328   else if ( toNode->IsDataFlowNode() || toNode->IsDataStreamNode() ) {
1329     cdebug << "AddLink IsDataFlow/StreamNode fromPort->PortStatus( ExternConnected ) : "
1330            << fromNode->Name() << " " << fromPort->PortName() << endl ;
1331     fromPort->PortStatus( ExternConnected ) ;
1332   }
1333   else {
1334     cdebug << "AddLink fromPort->PortStatus( PortConnected ) & fromNode->toNode "
1335            << fromNode->Name() << " " << fromPort->PortName() << " "
1336            << fromPort->Kind() << " OldPortStatus " << fromPort->PortStatus() << " -> " << toNode->Name()
1337            << " " << " " << toPort->PortName() << " " << toPort->Kind() << endl;
1338     fromPort->PortStatus( PortConnected );
1339     if ( fromPort->IsDataStream() && toPort->IsDataStream() ) {
1340       fromNode->AddStreamLinkedNode( toNode ) ;
1341     }
1342     else {
1343       fromNode->AddLinkedNode( toNode ) ;
1344     }
1345   }
1346   if ( fromNode->IsSwitchNode() ) {
1347     if ( !fromPort->IsDataStream() ) {
1348 //JR 08.02.2005      if ( fromPort->IsInLine() && toPort->IsGate() && !toNode->IsEndSwitchNode() ) {
1349       if ( fromPort->IsInLine() && toPort->IsGate() ) {
1350         fromPort->Kind( SUPERV::SwitchParameter ) ;
1351       }
1352       else if ( !fromPort->IsGate() && !toPort->IsGate() ){
1353         fromPort->Kind( SUPERV::InLineParameter ) ;
1354       }
1355     }
1356     if ( fromPort->IsGate() && !toNode->IsEndSwitchNode() ) {
1357       GraphBase::InLineNode * anEndSwitchNode ;
1358       anEndSwitchNode = ((GraphBase::SwitchNode * ) fromNode)->CoupledNode() ;
1359       GraphBase::InPort * anInPort = anEndSwitchNode->GetChangeNodeInGate() ;
1360       GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1361       if ( anOutPort && !strcmp( fromNode->Name() , anOutPort->NodeName() ) &&
1362            !strcmp( fromPort->PortName() , anOutPort->PortName() ) &&
1363            anOutPort->IsGate() ) {
1364         if ( !RemoveLink( fromNode->Name() , anOutPort->PortName() ,
1365                           anEndSwitchNode->Name() ,
1366                           anInPort->PortName() ) ) {
1367           cdebug << "AddLink Error Removelink ( Switch , Default , EndSwitch , Default )"
1368                  << endl ;
1369           cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1370           return false ;
1371         }
1372       }
1373     }
1374   }
1375 //  cdebug << fromNode->ServiceName() << " " << toNode->ServiceName() << endl ;
1376   cdebug_out << "GraphBase::Graph::AddLink 1" << endl;
1377   return true ;
1378 }
1379
1380 bool GraphBase::Graph::RemoveLink( const char* FromNodeName ,
1381                                    const char* FromServiceParameterName ,
1382                                    const char* ToNodeName ,
1383                                    const char* ToServiceParameterName ) {
1384   cdebug_in << "GraphBase::Graph::RemoveLink from " << FromNodeName << "(" << FromServiceParameterName << ")"
1385             << " to " << ToNodeName << "(" << ToServiceParameterName << ")" << endl;
1386   bool RetVal = false ;
1387   GraphBase::ComputingNode * toNode = GetChangeGraphNode( ToNodeName ) ;
1388   if ( toNode ) {
1389     GraphBase::InPort * anInPort = toNode->GetChangeInPort( ToServiceParameterName ) ;
1390     if ( anInPort && ( anInPort->IsPortConnected() ||
1391                        anInPort->IsDataConnected() ||
1392                        anInPort->IsExternConnected() ) ) {
1393 // JR 13.01.2005 : DeBug : if it is a link to an EndSwitchNode. The OutPort may be an other one !!!
1394       GraphBase::ComputingNode * fromNode = GetChangeGraphNode( FromNodeName ) ;
1395       GraphBase::OutPort * anOutPort = NULL ;
1396       if ( toNode->IsEndSwitchNode() ) {
1397         anOutPort = fromNode->GetChangeOutPort( FromServiceParameterName ) ;
1398         RetVal = anOutPort->RemoveInPort( anInPort ) ;
1399       }
1400       else {
1401         anOutPort = anInPort->GetOutPort() ;
1402         RetVal = anOutPort->RemoveInPort( anInPort ) ;
1403       }
1404 //      anInPort->RemoveOutPort() ; // Already done in RemoveInPort
1405 //      const char * FromNodeName = anOutPort->NodeName() ;
1406       if ( RetVal ) {
1407         if ( fromNode ) {
1408           if ( anInPort->IsDataStream() ) {
1409             fromNode->RemoveStreamLinkedNode( toNode ) ;
1410           }
1411           else {
1412             fromNode->RemoveLinkedNode( toNode ) ;
1413           }
1414         }
1415 //JR PAL7990 : a SwitchPort is an OutPort of a SwitchNode connected to a InGate Port
1416 //Debug : change the kind only if there is no other InGate connected to the OutPort
1417         if ( fromNode->IsSwitchNode() && !anOutPort->IsGate() && anOutPort->InPortsSize() == 0 ) {
1418           if ( !toNode->IsEndSwitchNode() ) {
1419             anOutPort->Kind( SUPERV::InLineParameter ) ;
1420           }
1421           else if ( !anInPort->IsGate() ) {
1422             anOutPort->Kind( SUPERV::InLineParameter ) ;
1423           }
1424         }
1425 // JR 13.01.2005 : DeBug : if it is a link to an EndSwitchNode. The InPort may be multiple linked !!!
1426         if ( toNode->IsEndSwitchNode() ) {
1427           int i ;
1428           int done = false ;
1429           for ( i = 0 ; i < toNode->LinkedFromNodesSize() ; i++ ) {
1430             GraphBase::StreamNode * fromNode = toNode->LinkedFromNodes( i ) ;
1431             int j ;
1432             for ( j = 0 ; j < fromNode->GetNodeOutPortsSize() ; j++ ) {
1433               GraphBase::OutPort * fromOutPort = fromNode->GetChangeNodeOutPort( j ) ;
1434               int k ;
1435               for ( k = 0 ; k < fromOutPort->InPortsSize() ; k++ ) {
1436                 if ( strcmp( toNode->Name() , fromOutPort->InPorts( k )->NodeName() ) == 0 ) {
1437                   if ( strcmp( anInPort->PortName() , fromOutPort->InPorts( k )->PortName() ) == 0 ) {
1438 // Restore an OutPort in the InPort
1439                     anInPort->ChangeOutPort( fromOutPort ) ;
1440                     cdebug << "Graph::RemoveLink reestablish " << fromOutPort->NodeName() << "( "
1441                            << fromOutPort->PortName() << " ) in the InPort of EndSwitch : "
1442                            << toNode->Name() << "( " << anInPort->PortName() << " )"
1443                            << anInPort->Kind() << " " << anInPort->PortStatus() << endl;
1444                     done = true ;
1445                     break ;
1446                   }
1447                 }
1448               }
1449               if ( done ) {
1450                 break ;
1451               }
1452             }
1453             if ( done ) {
1454               break ;
1455             }
1456           }
1457         }
1458       }
1459     }
1460   }
1461   cdebug_out << "GraphBase::Graph::RemoveLink " << RetVal << endl;
1462   return RetVal ;
1463 }
1464
1465 bool GraphBase::Graph::GetLink(const char* ToNodeName ,
1466                                const char* ToServiceParameterName ,
1467                                char** FromNodeName ,
1468                                char** FromServiceParameterName ) {
1469 //  cdebug_in << "GraphBase::Graph::GetLink " << ToNodeName << "("
1470 //            << ToServiceParameterName << ")" << endl;
1471   bool RetVal = false ;
1472   GraphBase::ComputingNode * toNode = GetChangeGraphNode( ToNodeName ) ;
1473   if ( toNode ) {
1474     GraphBase::InPort * anInPort = toNode->GetChangeInPort( ToServiceParameterName ) ;
1475     if ( anInPort && !anInPort->IsNotConnected() ) {
1476       GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1477 //JR 17.02.2005 Memory Leak      *FromNodeName = my_strdup( anOutPort->NodeName() ) ;
1478       *FromNodeName = (char * ) anOutPort->NodeName() ;
1479 //JR 17.02.2005 Memory Leak      *FromServiceParameterName = my_strdup( anOutPort->PortName() ) ;
1480       *FromServiceParameterName = (char * ) anOutPort->PortName() ;
1481       RetVal = true ;
1482     }
1483     else {
1484       cdebug << "GraphBase::Graph::GetLink ERROR no InPort or NotConnected " << ToNodeName
1485              << " " << ToServiceParameterName << " " << RetVal << endl;
1486     }
1487   }
1488   else {
1489     cdebug << "GraphBase::Graph::GetLink ERROR no Node " << ToNodeName << " " << RetVal
1490            << endl;
1491   }
1492 //  cdebug_out << "GraphBase::Graph::GetLink " << RetVal << endl;
1493   return RetVal ;
1494 }
1495
1496 bool GraphBase::Graph::AddInputData( const char* ToNodeName ,
1497                                      const char* ToServiceParameterName ,
1498                                      const CORBA::Any aValue ) {
1499   bool RetVal = false ;
1500   cdebug_in << "GraphBase::Graph::AddInputData(" << ToNodeName << ","
1501             << ToServiceParameterName << " , Any " ;
1502   switch (aValue.type()->kind()) {
1503     case CORBA::tk_string:
1504       char * t;
1505       aValue >>= t;
1506       cdebug << t << " (string) " ;
1507       break;
1508     case CORBA::tk_double:
1509       double d;
1510       aValue >>= d;
1511       cdebug << d << " (double) " ;
1512       break;
1513     case CORBA::tk_long:
1514       long l;
1515       aValue >>= l;
1516       cdebug << l << " (long) " ;
1517       break;
1518     case CORBA::tk_objref:
1519       cdebug << "(object reference) " ;
1520       break;
1521     default:
1522       cdebug << "(other(tk_string(" << CORBA::tk_string << "),tk_double(" << CORBA::tk_double << "),tk_long("
1523              << CORBA::tk_long << "),tk_objref)(" << CORBA::tk_objref << ")) ERROR : " << aValue.type()->kind() ;
1524       break;
1525     }
1526   cdebug << " ) in Graph " << Name() << endl;
1527  
1528   GraphBase::ComputingNode *toNode ;
1529   GraphBase::InPort *toPort ;
1530   char *aNodeName ;
1531   char *aPortName ;
1532   NodePort( ToNodeName , ToServiceParameterName , &aNodeName , &aPortName ) ;
1533   toNode = GetChangeGraphNode( aNodeName ) ;
1534   cdebug << "in Graph " << Name() << " aNodeName '" << aNodeName << "' aPortName '" << aPortName
1535          << "'" << endl;
1536   if ( toNode ) {
1537     toPort = toNode->GetChangeInPort( aPortName ) ;
1538     if ( toPort && !toPort->IsDataConnected() && toPort->GetOutPort() ) {
1539       toPort->RemoveOutPort() ;
1540     }
1541   }
1542   else {
1543     toPort = NULL ;
1544   }
1545
1546   int i ;
1547   for ( i = 0 ; i < GetNodeOutDataNodePortsSize() ; i++ ) {
1548     cdebug << "Graph::AddInputData In" << i << " " << *GetNodeOutDataNodePort(i) << endl ;
1549   }
1550   for ( i = 0 ; i < GetNodeInDataNodePortsSize() ; i++ ) {
1551     cdebug << "Graph::AddInputData Out" << i << " " << *GetNodeInDataNodePort(i) << endl ;
1552   }
1553
1554   if ( toNode && toPort ) {
1555     GraphBase::OutPort *fromDataNodePort = NULL ;
1556     fromDataNodePort = GraphBase::DataNode::GetChangeInDataNodePort( toPort->NodePortName() ) ;
1557     if ( fromDataNodePort && fromDataNodePort->GetInPort( toPort ) ) {
1558       fromDataNodePort->RemoveInPort( toPort ) ;
1559     }
1560     cdebug << "Try AddLink " << toPort->NodePortName() << " : " << Name() << "( "
1561            << fromDataNodePort->PortName() << " ) -->" << toNode->Name() << "( "
1562            << toPort->PortName() << " )" << endl ;
1563     RetVal = AddLink( (GraphBase::ComputingNode * ) this , fromDataNodePort ,
1564                       toNode , toPort ) ;
1565     if ( RetVal ) {
1566       fromDataNodePort->SetValue( aValue ) ;
1567       fromDataNodePort->PortStatus( DataConnected ) ;
1568     }
1569   }
1570   else {
1571     cdebug << "ERROR Node and/or Port not found : " << aNodeName << " " << aPortName << endl ;
1572   }
1573   delete aNodeName ;
1574   delete aPortName ;
1575
1576   cdebug_out << "GraphBase::Graph::AddInputData " << RetVal << endl;
1577   return RetVal ;
1578 }
1579
1580 // Used in the Executor in order to change an Input Value and ReRun
1581 bool GraphBase::Graph::ChangeInputData( const char * ToNodeName ,
1582                                         const char * ToServiceParameterName ,
1583                                         const CORBA::Any aValue ) {
1584   bool RetVal = false ;
1585   cdebug_in << "GraphBase::Graph::ChangeInputData( '" << ToNodeName << "' , '"
1586             << ToServiceParameterName << "' , Any " ;
1587   switch (aValue.type()->kind()) {
1588     case CORBA::tk_string:
1589       char * t;
1590       aValue >>= t;
1591       cdebug << t << " (string) " ;
1592       break;
1593     case CORBA::tk_double:
1594       double d;
1595       aValue >>= d;
1596       cdebug << d << " (double) " ;
1597       break;
1598     case CORBA::tk_long:
1599       long l;
1600       aValue >>= l;
1601       cdebug << l << " (long) " ;
1602       break;
1603     case CORBA::tk_objref:
1604       cdebug << "(object reference) " ;
1605       break;
1606     default:
1607       cdebug << "(other(tk_string,tk_double,tk_long,tk_objref)) ERROR";
1608       break;
1609     }
1610   cdebug << " ) in Graph " << Name() << endl;
1611
1612   GraphBase::ComputingNode * toNode ;
1613   GraphBase::InPort * toPort = NULL ;
1614   char * aNodeName ;
1615   char * aPortName ;
1616   NodePort( ToNodeName , ToServiceParameterName , &aNodeName , &aPortName ) ;
1617   toNode = GetChangeGraphNode( aNodeName ) ;
1618   cdebug << "in Graph " << Name() << " aNodeName " << aNodeName << " aPortName " << aPortName << endl;
1619   if ( toNode ) {
1620     toPort = toNode->GetChangeInPort( aPortName ) ;
1621     if ( toPort && toPort->IsDataConnected() ) {
1622       GraphBase::OutPort * fromPort = toPort->GetOutPort();
1623       if ( fromPort ) {
1624         RetVal = true ;
1625         fromPort->SetValue( aValue ) ;
1626         fromPort->PortStatus( DataConnected ) ;
1627         toPort->PortState( SUPERV::ReadyState ) ;
1628       }
1629       else {
1630         cdebug << "ERROR ChangeInputData fromPort not found" << endl ;
1631       }
1632     }
1633     else {
1634       cdebug << "ERROR ChangeInputData toPort not found" << endl ;
1635     }
1636   }
1637   else {
1638     cdebug << "ERROR ChangeInputData Node not found : " << ToNodeName << endl ;
1639   }
1640
1641   cdebug_out << "GraphBase::Graph::ChangeInputData" << endl;
1642   return RetVal ;
1643 }
1644
1645 #if 0
1646 // To restore InputData in CreateService
1647 bool GraphBase::Graph::AddInputData( const char* ToNodeName ,
1648                                      const char* ToServiceParameterName ,
1649                                      const CORBA::Any ** aValue ) {
1650   bool RetVal = false ;
1651   cdebug_in << "GraphBase::Graph::AddInputData( " << ToNodeName << " , "
1652             << ToServiceParameterName << ", **Any " ;
1653   const CORBA::Any theValue = **aValue ;
1654   switch (theValue.type()->kind()) {
1655     case CORBA::tk_string:
1656       char * t;
1657       theValue >>= t;
1658       cdebug << t << " (string) " ;
1659       break;
1660     case CORBA::tk_double:
1661       double d;
1662       theValue >>= d;
1663       cdebug << d << " (double) " ;
1664       break;
1665     case CORBA::tk_long:
1666       long l;
1667       theValue >>= l;
1668       cdebug << l << " (long) " ;
1669       break;
1670     case CORBA::tk_objref:
1671       cdebug << "(object reference) " ;
1672       break;
1673     default:
1674       cdebug << "(other(tk_string,tk_double,tk_long,tk_objref)) ERROR";
1675       break;
1676     }
1677   cdebug << ") of Graph " << Name() << endl;
1678
1679   GraphBase::ComputingNode *toNode = GetChangeGraphNode( ToNodeName ) ;
1680
1681   if ( toNode ) {
1682     GraphBase::InPort *toPort = NULL ;
1683     GraphBase::OutPort *fromDataNodePort = NULL ;
1684     toPort = toNode->GetChangeInPort( ToServiceParameterName ) ;
1685     fromDataNodePort = GraphBase::DataNode::GetChangeInDataNodePort( toPort->NodePortName() ) ;
1686     cdebug << "Try AddLink " << Name() << "( " << fromDataNodePort << " ) -->"
1687            << toNode->Name() << "( " << toPort->PortName() << " )" << endl ;
1688     RetVal = AddLink( (GraphBase::ComputingNode * ) this , fromDataNodePort ,
1689                       toNode , toPort ) ;
1690     if ( RetVal ) {
1691       fromDataNodePort->Value( aValue ) ;
1692       fromDataNodePort->PortStatus( DataConnected ) ;
1693     }
1694   }
1695   else {
1696     cdebug << "ERROR Node not found " << ToNodeName << " ERROR. Known nodes :" << endl ;
1697     map< string , int >::iterator aMapOfGraphNodesIterator ;
1698     int i = 0 ;
1699     for ( aMapOfGraphNodesIterator = _MapOfGraphNodes.begin() ;
1700           aMapOfGraphNodesIterator != _MapOfGraphNodes.end() ; aMapOfGraphNodesIterator++ ) {
1701       cdebug << "MapOfGraphNodes " << i++ << " " << aMapOfGraphNodesIterator->first << " --> "
1702              << aMapOfGraphNodesIterator->second << endl ;
1703     }
1704   }
1705
1706   cdebug_out << "GraphBase::Graph::AddInputData " << RetVal << endl;
1707   return RetVal ;
1708 }
1709 #endif
1710
1711 bool GraphBase::Graph::AddOutputData( const char* FromNodeName ,
1712                                       const char* FromServiceParameterName ,
1713                                       const CORBA::Any aValue ) {
1714   bool RetVal = true ;
1715   cdebug_in << "GraphBase::Graph::AddOutputData(" << FromNodeName << ","
1716             << FromServiceParameterName << ")" << endl;
1717   GraphBase::ComputingNode *fromNode = GetChangeGraphNode( FromNodeName ) ;
1718
1719   GraphBase::OutPort *anOutPort = NULL ;
1720
1721   if ( fromNode ) {
1722     anOutPort = fromNode->GetChangeOutPort( FromServiceParameterName ) ;
1723 //    toDataNodePort = GraphBase::DataNode::GetChangeOutDataNodePort( fromPort->NodePortName() ) ;
1724 //    RetVal = AddLink( fromNode , fromPort ,
1725 //                      (GraphBase::ComputingNode * ) this , toDataNodePort ) ;
1726     anOutPort->SetValue( aValue ) ;
1727     anOutPort->PortState(  SUPERV::ReadyState ) ;
1728     anOutPort->PortDone( true ) ;
1729     cdebug << *anOutPort ;
1730 #ifdef _DEBUG_
1731     anOutPort->StringValue( *_fdebug ) ;
1732 #endif
1733     cdebug << endl ;
1734   }
1735   else {
1736     cdebug << "ERROR Node not found" << endl ;
1737     RetVal = false ;
1738   }
1739   cdebug_out << "GraphBase::Graph::AddOutputData " << RetVal << endl;
1740   return RetVal ;
1741 }
1742
1743 //JR This is used by StreamGraphs to list "CODES" and after that there is instances
1744 // for each Code (Nodes).
1745 map< string , GraphBase::Service * > GraphBase::Graph::MapOfServiceNames() {
1746                                            return _MapOfServiceNames ; }
1747
1748 GraphBase::Service * GraphBase::Graph::GetServiceOfMap( char * name ) {
1749   return _MapOfServiceNames[ name ] ;
1750 }
1751
1752 bool GraphBase::Graph::SetServiceOfMap( GraphBase::Service * aService ) {
1753   GraphBase::Service * theService = _MapOfServiceNames[ aService->ServiceName() ] ;
1754   if ( theService ) {
1755     cdebug << "SetServiceOfMap of " << aService->ServiceName()
1756            << " already in MapOfServiceNames : erase" << endl ;
1757     _MapOfServiceNames.erase( aService->ServiceName() ) ;
1758   }
1759   _MapOfServiceNames[ (char * ) aService->ServiceName() ] = aService ;
1760   cdebug << "SetServiceOfMap of " << aService->ServiceName() << " done" << endl ;
1761   return true ;
1762 }
1763
1764 //PAL7961
1765 //JR Debug 25.03.2005 : with multiple instances et delete of instances, it was wrong
1766 //Bug created with the developpement of StreamGraphs
1767 int GraphBase::Graph::GetNewServiceInstanceNumber( char * aServiceName ) {
1768   int InstanceNumber = _MapOfServiceInstanceNumber[ aServiceName ] + 1 ;
1769   _MapOfServiceInstanceNumber[ aServiceName ] = InstanceNumber ;
1770   return InstanceNumber ;
1771 }
1772
1773 void GraphBase::Graph::SetGraphPorts() {
1774   cdebug_in << "GraphBase::Graph::SetGraphPorts fill ports of Graph" << endl;
1775   int i ;
1776   for ( i = 0 ; i < GetNodeInDataNodePortsSize() ; i++ ) {
1777     GraphBase::OutPort * anOutPort = GetChangeNodeInDataNodePort( i ) ;
1778     cdebug << "SetGraphPorts Out" << i << " " << anOutPort->PortName() << " " << anOutPort->PortType()
1779            << " " << anOutPort->Kind() << " " << anOutPort->PortStatus() << " " << anOutPort->PortState() << endl ;
1780     if ( !anOutPort->IsGate() ) {
1781       anOutPort->PortStatus( ExternConnected ) ;
1782     }
1783   }
1784   for ( i = 0 ; i < GetNodeOutDataNodePortsSize() ; i++ ) {
1785     GraphBase::InPort * anInPort = GetChangeNodeOutDataNodePort( i ) ;
1786     cdebug << "SetGraphPorts In" << i << " " << anInPort->PortName() << " " << anInPort->PortType()
1787            << " " << anInPort->Kind() << " " << anInPort->PortStatus() << " " << anInPort->PortState() << endl ;
1788     if ( !anInPort->IsGate() ) {
1789       GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1790       anOutPort->PortStatus( ExternConnected ) ;
1791     }
1792   }
1793   cdebug_out << "GraphBase::Graph::SetGraphPorts" << endl;
1794 }
1795
1796 bool GraphBase::Graph::CreateService() {
1797   cdebug_in << "GraphBase::Graph::CreateService " << Name() << " GraphMacroLevel : " << GraphMacroLevel() << endl;
1798   bool RetVal = true ;
1799   SALOME_ModuleCatalog::Service aService ;
1800   int i , j ;
1801   GraphBase::ComputingNode * aToNode ;
1802   int dostore ;
1803   int innbr = 0 ;
1804   int instreamnbr = 0 ;
1805   int outnbr = 0 ;
1806   int outstreamnbr = 0 ;
1807   vector< SUPERV::KindOfPort > InPortsKind ;
1808   vector< SALOME_ModuleCatalog::DataStreamDependency > InDataStreamDependency ;
1809   vector< SUPERV::KindOfSchema > InKindOfSchema ;
1810   vector< SUPERV::KindOfInterpolation > InKindOfInterpolation ;
1811   vector< SUPERV::KindOfExtrapolation > InKindOfExtrapolation ;
1812   vector< SUPERV::KindOfPort > OutPortsKind ;
1813   vector< SALOME_ModuleCatalog::DataStreamDependency > OutDataStreamDependency ;
1814   vector< long > OutNumberOfValues ;
1815 //  if ( GraphMacroLevel() == 0 ) {
1816     for ( dostore = 0 ; dostore <= 2 ; dostore++ ) {
1817       if ( dostore == 1 ) {
1818 //JR 17.02.2005 Memory Leak        aService.ServiceName = Name() ;
1819         aService.ServiceName = my_strdup( Name() ) ;
1820         aService.ServiceinParameter.length( 0 ) ;
1821         aService.ServiceinParameter.length( innbr ) ;
1822         aService.ServiceoutParameter.length( 0 ) ;
1823         aService.ServiceoutParameter.length( outnbr ) ;
1824         InPortsKind.resize( innbr ) ;
1825         InDataStreamDependency.resize( innbr ) ;
1826         InKindOfSchema.resize( innbr ) ;
1827         InKindOfInterpolation.resize( innbr ) ;
1828         InKindOfExtrapolation.resize( innbr ) ;
1829         OutPortsKind.resize( outnbr ) ;
1830         OutDataStreamDependency.resize( outnbr ) ;
1831         OutNumberOfValues.resize( outnbr ) ;
1832       }
1833       else if ( dostore == 2 ) {
1834 //JR Creation of the Service (and of the Ports) with GraphBase::DataNode::DataService :
1835         cdebug << "GraphBase::Graph::CreateService ->DataService innbr " << innbr
1836                << " instreamnbr " << instreamnbr << " outnbr " << outnbr
1837                << " outstreamnbr " << outstreamnbr << endl ;
1838         DataService( _Orb , aService , Graph_prof_debug() , Graph_fdebug() ) ;
1839         aService.ServiceinParameter.length( innbr + instreamnbr ) ;
1840         aService.ServiceoutParameter.length( outnbr + outstreamnbr ) ;
1841         InPortsKind.resize( innbr + instreamnbr ) ;
1842         InDataStreamDependency.resize( innbr + instreamnbr ) ;
1843         InKindOfSchema.resize( innbr + instreamnbr ) ;
1844         InKindOfInterpolation.resize( innbr + instreamnbr ) ;
1845         InKindOfExtrapolation.resize( innbr + instreamnbr ) ;
1846         OutPortsKind.resize( outnbr + outstreamnbr ) ;
1847         OutDataStreamDependency.resize( outnbr + outstreamnbr ) ;
1848         OutNumberOfValues.resize( outnbr + outstreamnbr ) ;
1849       }
1850       if ( dostore == 0 ) {
1851         innbr = 0 ;
1852         instreamnbr = 0 ;
1853         outnbr = 0 ;
1854         outstreamnbr = 0 ;
1855       }
1856       if ( dostore == 1 ) {
1857         innbr = 0 ;
1858         outnbr = 0 ;
1859       }
1860       for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1861         aToNode = GraphNodes( i ) ;
1862         for ( j = 0 ; j < aToNode->GetNodeInPortsSize() ; j++ ) {
1863           GraphBase::InPort *anInPort = aToNode->GetChangeNodeInPort(j) ;
1864           bool isfromcouplednode = false ;
1865           if ( !anInPort->IsNotConnected() ) {
1866             const char * aFromNodeName = anInPort->GetOutPort()->NodeName() ;
1867             GraphBase::ComputingNode * aFromNode = GetChangeGraphNode( aFromNodeName ) ;
1868             cdebug << "GraphBase::Graph::CreateService aFromNodeName " << aFromNodeName << " aToNode "
1869                    << aToNode->Name() << " InPort" << j << " " << anInPort->PortName() << endl ;
1870             if ( aFromNode && aFromNode->IsEndLoopNode() &&
1871                  ((GraphBase::EndOfLoopNode * ) aFromNode)->CoupledNode() == aToNode ) {
1872               isfromcouplednode = true ;
1873             }
1874           }
1875           if ( !anInPort->IsGate() && !anInPort->IsLoop() &&
1876                ( !anInPort->IsPortConnected() ||
1877 //                 ( anInPort->IsPortConnected() && isfromcouplednode ) ) ) {
1878 //JR PAL8914 : InPorts of EndLoopNodes may not be in the Service of the Graph
1879                  ( anInPort->IsPortConnected() && isfromcouplednode ) ) &&
1880                !aToNode->IsEndLoopNode() ) {
1881             if ( dostore == 0 ) {
1882               cdebug << "CreateService " << aToNode->Name() << " Input port "
1883                      << anInPort->PortName() << " " << anInPort->Kind() << " " << anInPort->PortStatus() ;
1884               if ( anInPort->GetOutPort() ) {
1885                 cdebug << "DataConnected from " <<  *(anInPort->GetOutPort() ) ;
1886               }
1887               cdebug << endl ;
1888               if ( anInPort->IsDataStream() ) {
1889                 instreamnbr += 1 ;
1890               }
1891               else {
1892                 innbr += 1 ;
1893               }
1894             }
1895             else if ( ( dostore == 1 && !anInPort->IsDataStream() ) ||
1896                       ( dostore == 2 && anInPort->IsDataStream() ) ) {
1897               aService.ServiceinParameter[innbr].Parametertype = CORBA::string_dup( anInPort->PortType() ) ;
1898               aService.ServiceinParameter[innbr].Parametername = CORBA::string_dup( anInPort->NodePortName() ) ;
1899               InPortsKind[ innbr ] = anInPort->Kind() ;
1900               InDataStreamDependency[ innbr ] = anInPort->Dependency() ;
1901               if ( dostore == 2 && anInPort->IsDataStream() ) {
1902                 ((GraphBase::InDataStreamPort * ) anInPort)->Params( InKindOfSchema[ innbr ] ,
1903                                                                      InKindOfInterpolation[ innbr ] ,
1904                                                                      InKindOfExtrapolation[ innbr ] ) ;
1905               }
1906               cdebug << "In" << innbr << " " << aService.ServiceinParameter[ innbr ].Parametername << " "
1907                      << anInPort->Kind() << " " << anInPort->PortStatus() << endl ;
1908               innbr += 1 ;
1909             }
1910           }
1911           else if ( dostore == 0 ) {
1912             cdebug << "CreateService " << aToNode->Name() << " Input port " << anInPort->PortName()
1913                    << " " << anInPort->PortStatus() ;
1914             if ( anInPort->IsPortConnected() ) {
1915               cdebug << " is connected " ;
1916             }
1917             else {
1918               cdebug << " is NOT connected " ;
1919             }
1920             if ( anInPort->IsGate() ) {
1921               cdebug << " IsGate " ;
1922             }
1923             if ( anInPort->GetOutPort() ) {
1924               cdebug << "DataConnected from " <<  *(anInPort->GetOutPort()) ;
1925             }
1926             else {
1927               cdebug << "NOT DataConnected" ;
1928             }
1929             cdebug << endl ;
1930           }
1931         }
1932         GraphBase::ComputingNode * aFromNode = aToNode ;
1933         for ( j = 0 ; j < aFromNode->GetNodeOutPortsSize() ; j++ ) {
1934           GraphBase::OutPort *anOutPort = aFromNode->GetChangeNodeOutPort(j) ;
1935 //          cdebug << "CreateService Node " << aFromNode->Name() << ". Output port[" << j << "] ";
1936 //          if ( anOutPort ) {
1937 //            cdebug << anOutPort->PortName() << " " << anOutPort->ServicesParameterType() << endl ;
1938 //        }
1939 //          else {
1940 //            cdebug << " NULL" << endl ;
1941 //        }
1942           if ( !aFromNode->IsGOTONode() ) {
1943             if ( !anOutPort->IsGate() && ( anOutPort->IsNotConnected() || anOutPort->IsDataConnected()  ||
1944 //JR PAL8914 : OutPorts of LoopNodes may not be in the Service of the Graph
1945 //                                           anOutPort->IsExternConnected() ) {
1946                                            anOutPort->IsExternConnected() ) &&
1947                  !aFromNode->IsLoopNode() ) {
1948               if ( dostore == 0 ) {
1949 //                cdebug << "CreateService " << aFromNode->Name() << " Output port "
1950 //                       << anOutPort->PortName() << " " << anOutPort->PortStatus() << endl ;
1951                 if ( anOutPort->IsDataStream() ) {
1952                   outstreamnbr += 1 ;
1953                 }
1954                 else {
1955                   outnbr += 1 ;
1956                 }
1957               }
1958               else if ( ( dostore == 1 && !anOutPort->IsDataStream() ) ||
1959                         ( dostore == 2 && anOutPort->IsDataStream() ) ) {
1960                 aService.ServiceoutParameter[outnbr].Parametertype = CORBA::string_dup( anOutPort->PortType() ) ;
1961                 aService.ServiceoutParameter[outnbr].Parametername = CORBA::string_dup( anOutPort->NodePortName() ) ;
1962                 OutPortsKind[ outnbr ] = anOutPort->Kind() ;
1963                 OutDataStreamDependency[ outnbr ] = anOutPort->Dependency() ;
1964                 if ( dostore == 2 && anOutPort->IsDataStream() ) {
1965                   OutNumberOfValues[ outnbr ] = ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues() ;
1966                 }
1967 //                cdebug << "Out" << outnbr << " " << aService.ServiceoutParameter[ outnbr ].Parametername << " "
1968 //                       << anOutPort->Kind() << " " << anOutPort->PortStatus() << endl ;
1969                 outnbr += 1 ;
1970               }
1971             }
1972           }
1973         }
1974       }
1975     }
1976 //  }
1977
1978 #if 1
1979   cdebug << "DataFlowNode ServiceName " << aService.ServiceName << " InPorts " << innbr
1980          << " OutPorts " << outnbr << endl ;
1981   for ( i = 0 ; i < innbr ; i++ ) {
1982     cdebug << "aService.ServiceinParameter[" << i << "].Parametertype "
1983          << aService.ServiceinParameter[i].Parametertype << " Parametername "
1984          << aService.ServiceinParameter[i].Parametername << " " << InPortsKind[ i ] << endl ;
1985     if ( InPortsKind[ i ] != SUPERV::DataStreamParameter ) {
1986       cdebug << "NodeInPort[" << i << "] " << *GetChangeNodeInPort( i ) << endl ;
1987     }
1988   }
1989   for ( i = 0 ; i < outnbr ; i++ ) {
1990     cdebug << "aService.ServiceoutParameter[" << i << "].Parametertype "
1991          << aService.ServiceoutParameter[i].Parametertype << " Parametername "
1992          << aService.ServiceoutParameter[i].Parametername << " " << OutPortsKind[ i ] << endl ;
1993     if ( OutPortsKind[ i ] != SUPERV::DataStreamParameter ) {
1994       cdebug << "NodeOutPort[" << i << "] " << *GetChangeNodeOutPort( i ) << endl ;
1995     }
1996   }
1997 #endif
1998
1999 //  DataService( _Orb , aService , InPortsKind , OutPortsKind , Graph_prof_debug() , Graph_fdebug() ) ;
2000   for ( i = 0 ; i < innbr ; i++ ) {
2001     if ( InPortsKind[ i ] == SUPERV::DataStreamParameter ) {
2002       GraphBase::InDataStreamPort * anInPort = AddInDataStreamPort( aService.ServiceinParameter[ i ].Parametername ,
2003                                                                     StringToDataStreamType( aService.ServiceinParameter[ i ].Parametertype ) ,
2004                                                                     InDataStreamDependency[ i ] ,
2005                                                                     SUPERV::DataStreamParameter ) ;
2006       anInPort->SetParams( InKindOfSchema[ i ] ,
2007                            InKindOfInterpolation[ i ] ,
2008                            InKindOfExtrapolation[ i ] ) ;
2009 // NOT A BUG : AddOutPort for an inport (Reversed service)
2010       anInPort = (GraphBase::InDataStreamPort * ) _DataFlowDataPorts->AddOutPort(
2011                                                            _Orb , NamePtr() ,
2012                                                            Kind() ,
2013                                                            aService.ServiceinParameter[ i ].Parametername ,
2014                                                            aService.ServiceinParameter[ i ].Parametertype ,
2015                                                            SUPERV::DataStreamParameter ,
2016                                                            - 1 ,
2017                                                            _Graph_prof_debug , _Graph_fdebug ) ;
2018       anInPort->Dependency( InDataStreamDependency[ i ] ) ;
2019 // Attention : revoir les reversed DataStreamPorts
2020 //      anInPort->SetParams( InKindOfSchema[ i ] ,
2021 //                           InKindOfInterpolation[ i ] ,
2022 //                           InKindOfExtrapolation[ i ] ) ;
2023       cdebug << "InStreamPort " << GetChangeNodeInPort( i )->PortName() << " " << GetChangeNodeInPort( i )->Kind() << endl ;
2024       cdebug << "ReversedInStreamPort " << _DataFlowDataPorts->GetChangeNodeOutPort( i )->PortName() << " " << _DataFlowDataPorts->GetChangeNodeOutPort( i )->Kind()
2025              << endl ;
2026     }
2027     else {
2028       GetChangeNodeInPort( i )->Kind( InPortsKind[ i ] ) ;
2029       _DataFlowDataPorts->GetChangeNodeOutPort( i )->Kind( InPortsKind[ i ] ) ;
2030       GetChangeNodeInPort( i )->Dependency( InDataStreamDependency[ i ] ) ;
2031       _DataFlowDataPorts->GetChangeNodeOutPort( i )->Dependency( InDataStreamDependency[ i ] ) ;
2032       cdebug << "InPort " << GetChangeNodeInPort( i )->PortName() << " "
2033              << GetChangeNodeInPort( i )->Kind() << " " << GetChangeNodeInPort( i )->PortStatus()
2034              << endl ;
2035       cdebug << "ReversedInPort " << _DataFlowDataPorts->GetChangeNodeOutPort( i )->PortName() << " "
2036              << _DataFlowDataPorts->GetChangeNodeOutPort( i )->Kind() << " "
2037              << _DataFlowDataPorts->GetChangeNodeOutPort( i )->PortStatus()
2038              << endl ;
2039     }
2040   }
2041   for ( i = 0 ; i < outnbr ; i++ ) {
2042     if ( OutPortsKind[ i ] == SUPERV::DataStreamParameter ) {
2043       GraphBase::OutDataStreamPort * anOutPort = AddOutDataStreamPort( aService.ServiceoutParameter[ i ].Parametername ,
2044                                                                        StringToDataStreamType( aService.ServiceoutParameter[ i ].Parametertype ) ,
2045                                                                        OutDataStreamDependency[ i ] ,
2046                                                                        SUPERV::DataStreamParameter ) ;
2047       anOutPort->NumberOfValues( OutNumberOfValues[ i ] ) ;
2048 // NOT A BUG : AddInPort for an outport (Reversed service)
2049       anOutPort = (GraphBase::OutDataStreamPort * ) _DataFlowDataPorts->AddInPort(
2050                                                              _Orb , NamePtr() ,
2051                                                              Kind() ,
2052                                                              aService.ServiceoutParameter[ i ].Parametername ,
2053                                                              aService.ServiceoutParameter[ i ].Parametertype ,
2054                                                              SUPERV::DataStreamParameter ,
2055                                                              - 1 ,
2056                                                              _Graph_prof_debug , _Graph_fdebug ) ;
2057       anOutPort->Dependency( OutDataStreamDependency[ i ] ) ;
2058 // Attention : revoir les reversed DataStreamPorts
2059 //      anOutPort->NumberOfValues( OutNumberOfValues[ i ] ) ;
2060       cdebug << "OutStreamPort " << GetChangeNodeOutPort( i )->PortName() << " " << GetChangeNodeOutPort( i )->Kind() << endl ;
2061       cdebug << "ReversedOutStreamPort " << _DataFlowDataPorts->GetChangeNodeInPort( i )->PortName() << " " << _DataFlowDataPorts->GetChangeNodeInPort( i )->Kind()
2062              << endl ;
2063     }
2064     else {
2065       GetChangeNodeOutPort( i )->Kind( OutPortsKind[ i ] ) ;
2066       _DataFlowDataPorts->GetChangeNodeInPort( i )->Kind( OutPortsKind[ i ] ) ;
2067       GetChangeNodeOutPort( i )->Dependency( OutDataStreamDependency[ i ] ) ;
2068       _DataFlowDataPorts->GetChangeNodeInPort( i )->Dependency( OutDataStreamDependency[ i ] ) ;
2069       GetChangeNodeOutPort( i )->Dependency( OutDataStreamDependency[ i ] ) ;
2070       _DataFlowDataPorts->GetChangeNodeInPort( i )->Dependency( OutDataStreamDependency[ i ] ) ;
2071       cdebug << "OutPort " << GetChangeNodeOutPort( i )->PortName() << " "
2072              << GetChangeNodeOutPort( i )->Kind() << " " << GetChangeNodeOutPort( i )->PortStatus()
2073              << endl ;
2074       cdebug << "ReversedOutPort " << _DataFlowDataPorts->GetChangeNodeInPort( i )->PortName()
2075              << " " << _DataFlowDataPorts->GetChangeNodeInPort( i )->Kind()
2076              << " " << _DataFlowDataPorts->GetChangeNodeInPort( i )->PortStatus()
2077              << endl ;
2078     }
2079   }
2080 // Restore input datas and links :
2081   DataStreamInPortsNumber( 0 ) ;
2082   DataStreamOutPortsNumber( 0 ) ;
2083   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2084     aToNode = GraphNodes( i ) ;
2085     DataStreamInPortsNumber( DataStreamInPortsNumber() + aToNode->DataStreamInPortsNumber() ) ;
2086     DataStreamOutPortsNumber( DataStreamOutPortsNumber() + aToNode->DataStreamOutPortsNumber() ) ;
2087     for ( j = 0 ; j < aToNode->GetNodeInPortsSize() ; j++ ) {
2088       GraphBase::InPort *anInPort = aToNode->GetChangeNodeInPort(j) ;
2089       if ( !anInPort->IsGate() && anInPort->IsDataConnected() ) {
2090         if ( !AddInputData( anInPort->NodeName() ,
2091                             anInPort->PortName() ,
2092 //JR 21.02.2005 Debug Memory leak :                            anInPort->GetOutPort()->ValuePtr() ) ) {
2093 //JR 30.03.2005                            *anInPort->GetOutPort()->Value() ) ) {
2094                             anInPort->GetOutPort()->Value() ) ) {
2095           cdebug << "CreateService In" << j << " " << anInPort->NodeName() << "(" << anInPort->PortName() << ") "
2096                  << anInPort->PortStatus() << " --> AddInputData ERROR" << endl ;
2097           RetVal = false ;
2098         }
2099         else {
2100           cdebug << "CreateService In" << j << " " << anInPort->NodeName() << "(" << anInPort->PortName() << ") "
2101                  << anInPort->PortStatus() << " --> AddInputData" << endl ;
2102         }
2103       }
2104 //JR PAL8914 : InPorts of EndLoopNodes may not be in the Service of the Graph
2105 //      else if ( !anInPort->IsGate() && anInPort->IsNotConnected() ) {
2106       else if ( !anInPort->IsGate() && anInPort->IsNotConnected() && !aToNode->IsEndLoopNode() ) {
2107         if ( !AddLink( this , GetChangeInDataNodePort( anInPort->NodePortName() ) , aToNode , anInPort ) ) {
2108           cdebug << "CreateService In" << j << " " << anInPort->NodeName() << "(" << anInPort->PortName() << ") "
2109                  << anInPort->PortStatus() << " --> AddInLink ERROR" << endl ;
2110           RetVal = false ;
2111         }
2112         else {
2113           cdebug << "CreateService In" << j << " " << anInPort->NodeName() << "(" << anInPort->PortName() << ") "
2114                  << anInPort->PortStatus() << " --> AddInLink" << endl ;
2115         }
2116       }
2117     }
2118     for ( j = 0 ; j < aToNode->GetNodeOutPortsSize() ; j++ ) {
2119       GraphBase::OutPort *anOutPort = aToNode->GetChangeNodeOutPort(j) ;
2120       cdebug << "CreateService Out" << j << " " << anOutPort->NodeName() << "(" << anOutPort->PortName()
2121              << ") " << anOutPort->PortStatus() << " :" << endl ;
2122 //JR PAL8914 : OutPorts of LoopNodes may not be in the Service of the Graph
2123 //      if ( !anOutPort->IsGate() && anOutPort->IsNotConnected() && !aToNode->IsGOTONode() ) {
2124       if ( !anOutPort->IsGate() && anOutPort->IsNotConnected() && !aToNode->IsGOTONode() &&
2125         !aToNode->IsLoopNode() ) {
2126         GraphBase::InPort *anInPort = GetChangeOutDataNodePort( anOutPort->NodePortName() ) ;
2127         if ( !AddLink( aToNode , anOutPort , this , anInPort ) ) {
2128           cdebug << "       --> " << Name() << "(" << anInPort->PortName()
2129                  << ") " << anInPort->PortStatus() << " AddOutLink ERROR" << endl ;
2130           RetVal = false ;
2131         }
2132         else {
2133           cdebug << "       --> " << Name() << "(" << anInPort->PortName()
2134                  << ") " << anInPort->PortStatus() << " AddOutLink" << endl ;
2135         }
2136       }
2137     }
2138   }
2139
2140 #ifdef _DEBUG_
2141   ListPorts( *_Graph_fdebug , 0 ) ;
2142 #endif
2143
2144   cdebug_out << "GraphBase::Graph::CreateService " << RetVal << endl;
2145   return RetVal ;
2146 }
2147
2148 bool GraphBase::Graph::InLineServices() {
2149   cdebug_in << "GraphBase::Graph::InLineServices" << endl;
2150
2151   int i , j ;
2152
2153 #ifdef _DEBUG_
2154   ListPorts( *_Graph_fdebug , 0 ) ;
2155 #endif
2156
2157   GraphBase::InLineNode * aINode ;
2158   SALOME_ModuleCatalog::Service aService ;
2159   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2160     aINode = (GraphBase::InLineNode * ) GraphNodes( i ) ;
2161     if ( aINode->IsOneOfInLineNodes() ) {
2162 //      cdebug << "GraphBase::Graph::InLineServices " << aINode->Name() << endl;
2163       aService.ServiceName = aINode->ServiceName() ;
2164       aService.ServiceinParameter.length( 0 ) ;
2165       aService.ServiceoutParameter.length( 0 ) ;
2166       aINode->DataStreamInPortsNumber( 0 ) ;
2167       aINode->DataStreamOutPortsNumber( 0 ) ;
2168       int InService = 0 ;
2169       int InStreamService = 0 ;
2170       for ( j = 0 ; j < aINode->GetNodeInPortsSize() ; j++ ) {
2171         if ( aINode->GetChangeNodeInPort(j)->IsGate() || aINode->GetChangeNodeInPort(j)->IsLoop() ) {
2172 #if 0
2173           cdebug << "GraphBase::Graph::InLineServices In" << j << " "
2174                  << aINode->GetChangeNodeInPort(j)->Kind() << " " 
2175                  << aINode->GetChangeNodeInPort(j)->PortType() << " " 
2176                  << aINode->GetChangeNodeInPort(j)->PortName() << " ignored "
2177                  << aINode->GetChangeNodeInPort(j)->IsGate() << " "
2178                  << aINode->GetChangeNodeInPort(j)->IsLoop() << endl;
2179 #endif
2180         }
2181         else if ( aINode->GetChangeNodeInPort(j)->IsDataStream() ) {
2182           aService.ServiceinDataStreamParameter.length( InStreamService+1 ) ;
2183           aService.ServiceinDataStreamParameter[InStreamService].Parametertype = StringToDataStreamType( aINode->GetChangeNodeInPort(j)->PortType() ) ;
2184           aService.ServiceinDataStreamParameter[InStreamService].Parametername = CORBA::string_dup( aINode->GetChangeNodeInPort(j)->PortName() ) ;
2185           aService.ServiceinDataStreamParameter[InStreamService++].Parameterdependency = aINode->GetChangeNodeInPort(j)->Dependency() ;
2186           aINode->IncrDataStreamInPorts() ;
2187 #if 0
2188           cdebug << "GraphBase::Graph::InLineServices In" << j << " "
2189                  << aINode->GetChangeNodeInPort(j)->Kind() << " " 
2190                  << aINode->GetChangeNodeInPort(j)->PortType() << " " 
2191                  << aINode->GetChangeNodeInPort(j)->PortName() << " "
2192                  << aINode->GetChangeNodeInPort(j)->IsGate() << " "
2193                  << aINode->GetChangeNodeInPort(j)->IsLoop() << endl;
2194 #endif
2195         }
2196         else {
2197           aService.ServiceinParameter.length( InService+1 ) ;
2198           aService.ServiceinParameter[InService].Parametertype = CORBA::string_dup( aINode->GetChangeNodeInPort(j)->PortType() ) ;
2199           aService.ServiceinParameter[InService++].Parametername = CORBA::string_dup( aINode->GetChangeNodeInPort(j)->PortName() ) ;
2200 #if 0
2201           cdebug << "GraphBase::Graph::InLineServices In" << j << " "
2202                  << aINode->GetChangeNodeInPort(j)->Kind() << " " 
2203                  << aINode->GetChangeNodeInPort(j)->PortType() << " " 
2204                  << aINode->GetChangeNodeInPort(j)->PortName() << " "
2205                  << aINode->GetChangeNodeInPort(j)->IsGate() << " "
2206                  << aINode->GetChangeNodeInPort(j)->IsLoop() << endl;
2207 #endif
2208         }
2209       }
2210       int OutService = 0 ;
2211       int OutStreamService = 0 ;
2212       for ( j = 0 ; j < aINode->GetNodeOutPortsSize() ; j++ ) {
2213 //        if ( aINode->GetChangeNodeOutPort(j)->IsGate() || aINode->GetChangeNodeOutPort(j)->IsLoop() || aINode->GetChangeNodeOutPort(j)->IsDataStream() ) {
2214         if ( aINode->GetChangeNodeOutPort(j)->IsGate() || aINode->GetChangeNodeOutPort(j)->IsLoop() ) {
2215 #if 0
2216           cdebug << "GraphBase::Graph::InLineServices Out" << j << " "
2217                  << aINode->GetChangeNodeOutPort(j)->Kind() << " " 
2218                  << aINode->GetChangeNodeOutPort(j)->PortType() << " " 
2219                  << aINode->GetChangeNodeOutPort(j)->PortName() << " ignored "
2220                  << aINode->GetChangeNodeOutPort(j)->IsGate() << " "
2221                  << aINode->GetChangeNodeOutPort(j)->IsLoop() << endl;
2222 #endif
2223         }
2224         else if ( aINode->GetChangeNodeOutPort(j)->IsDataStream() ) {
2225           aService.ServiceoutDataStreamParameter.length( OutStreamService+1 ) ;
2226           aService.ServiceoutDataStreamParameter[OutStreamService].Parametertype = StringToDataStreamType( aINode->GetChangeNodeOutPort(j)->PortType() ) ;
2227           aService.ServiceoutDataStreamParameter[OutStreamService].Parametername = CORBA::string_dup( aINode->GetChangeNodeOutPort(j)->PortName() ) ;
2228           aService.ServiceoutDataStreamParameter[OutStreamService++].Parameterdependency = aINode->GetChangeNodeOutPort(j)->Dependency() ;
2229           aINode->IncrDataStreamOutPorts() ;
2230 #if 0
2231           cdebug << "GraphBase::Graph::InLineServices Out" << j << " "
2232                  << aINode->GetChangeNodeOutPort(j)->Kind() << " " 
2233                  << aINode->GetChangeNodeOutPort(j)->PortType() << " " 
2234                  << aINode->GetChangeNodeOutPort(j)->PortName() << " "
2235                  << aINode->GetChangeNodeOutPort(j)->IsGate() << " "
2236                  << aINode->GetChangeNodeOutPort(j)->IsLoop() << endl;
2237 #endif
2238         }
2239         else {
2240           aService.ServiceoutParameter.length( OutService+1 ) ;
2241           aService.ServiceoutParameter[OutService].Parametertype = CORBA::string_dup( aINode->GetChangeNodeOutPort(j)->PortType() ) ;
2242           aService.ServiceoutParameter[OutService++].Parametername = CORBA::string_dup( aINode->GetChangeNodeOutPort(j)->PortName() ) ;
2243 #if 0
2244           cdebug << "GraphBase::Graph::InLineServices Out" << j << " "
2245                  << aINode->GetChangeNodeOutPort(j)->Kind() << " " 
2246                  << aINode->GetChangeNodeOutPort(j)->PortType() << " " 
2247                  << aINode->GetChangeNodeOutPort(j)->PortName()  << " "
2248                  << aINode->GetChangeNodeOutPort(j)->IsGate() << " "
2249                  << aINode->GetChangeNodeOutPort(j)->IsLoop() << endl;
2250 #endif
2251         }
2252       }
2253       aINode->SetService( aService ) ;
2254       if ( SetServiceOfMap( (GraphBase::Service * ) aINode ) ) {
2255 #if 0
2256         cdebug << "InLineServices SetServiceOfMap " << aINode->ServiceName() << " in MapOfServices"
2257                << " InStreamPort(" << aINode->DataStreamInPortsNumber() 
2258                << ") OutStreamPort(" << aINode->DataStreamOutPortsNumber() << ")" << endl ; 
2259 #endif
2260       }
2261 //      cdebug << "GraphBase::Graph::InLineServices" << *aINode->GetService() << endl;
2262     }
2263   }
2264
2265   cdebug_out << "GraphBase::Graph::InLineServices" << endl;
2266   return true ;
2267 }
2268
2269 bool GraphBase::Graph::Sort( int & SubStreamGraphsNumber ) {
2270 #ifdef _DEBUG_
2271   ListPorts( *_Graph_fdebug , 0 ) ;
2272 #endif
2273
2274   int i ;
2275   int j ;
2276   int NotSortedNumber = GraphNodesSize() ;
2277   bool NewSorted ;
2278   cdebug_in << "GraphBase::Graph::Sort" << endl;
2279   if ( NotSortedNumber ) {
2280     _LevelsNumber = 0 ;
2281     _ParallelExecutionNodes = false ;
2282     _Sorted.resize( GraphNodesSize() ) ;
2283     _CnxInPortsNumber.resize( GraphNodesSize() ) ;
2284     _DecrInPortsNumber.resize( GraphNodesSize() ) ;
2285     if ( _NodesNumber.size() ) {
2286       _NodesNumber.resize( 0 ) ;
2287       _SortedNodes.resize( 0 ) ;
2288     }
2289           
2290 // This is a simulation of the computation of the graph :
2291 // The initial state of nodes is :
2292 // - Sorted = false : the node is not sorted
2293 // - CnxInPortsNumber = ConnectedInPortsNumber : the number of ports that wait for a value from a link
2294 // - DecrInPortsNumber = 0 : there is no value available.
2295 #if 0
2296     cdebug << "GraphBase::Graph::Sort initial values :" << endl ;
2297     for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2298       GraphBase::ComputingNode * aNode = GraphNodes( i ) ;
2299       cdebug << aNode->Name() << " --> " << aNode->LinkedNodesSize() << " LinkedNodes :" << endl ;
2300       for ( j = 0 ; j < aNode->LinkedNodesSize()  ; j++ ) {
2301         cdebug << "              " << aNode->LinkedNodes( j )->Name() << endl ;
2302       }
2303     }
2304 #endif
2305     for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2306       _Sorted[ i ] = false ;
2307       _CnxInPortsNumber[ i ] = GraphNodes( i )->ConnectedInPortsNumber() ;
2308       _DecrInPortsNumber[ i ] = 0 ;
2309 //      cdebug << "Sort Node [" << i << "] " << GraphNodes( i )->Name() << " initial count "
2310 //             << _CnxInPortsNumber[ i ] << endl ;
2311     }
2312     
2313 // Nodes are linked ONLY if Ports are NOT DataStream for topological sort of node
2314 // ==============================================================================
2315     while ( NotSortedNumber ) {
2316       NewSorted = false ;
2317       
2318       for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2319         cdebug << "Sort level " << _LevelsNumber << ". [" << i << "] "
2320                << GraphNodes( i )->Name() << " count "
2321                << _CnxInPortsNumber[ i ] << endl ;
2322         if ( !_Sorted[ i ] && _CnxInPortsNumber[ i ] == 0 ) {
2323 // All inputs of GraphNodes( i ) are available : "AllDataReady"
2324           if ( (int ) _NodesNumber.size() != _LevelsNumber+1 ) {
2325             _NodesNumber.resize( _LevelsNumber+1 ) ;
2326             _SortedNodes.resize( _LevelsNumber+1 ) ;
2327             _NodesNumber[ _LevelsNumber ] = -1 ;
2328           }
2329 // There is one more node at that level
2330           _NodesNumber[ _LevelsNumber ]++ ;
2331           (_SortedNodes[ _LevelsNumber ]).resize( _NodesNumber[ _LevelsNumber ]+1 ) ;
2332           (_SortedNodes[ _LevelsNumber ])[ _NodesNumber[ _LevelsNumber ] ] = GraphNodes( i ) ;
2333           _Sorted[ i ] = true ;
2334           NewSorted = true ;
2335           NotSortedNumber -= 1 ;
2336           cdebug << GraphNodes( i )->Name() << " belongs to level "
2337                  << _LevelsNumber << ". " << GraphNodes( i )->LinkedNodesSize() << " linkednodes" << endl ;
2338 // GraphNodes( i ) has the state "AllDataReady". We simulate the end of its execution :
2339 // So we loop over all nodes that have a link from that node
2340 // And we increment the number of input ports of GraphNodes( i )->LinkedNodes( j ) that this
2341 // execution will give a value in DecrInPortsNumber : "SomeDataReady"
2342           for ( j = 0 ; j < GraphNodes( i )->LinkedNodesSize() ; j++ ) {
2343 // OutputPorts of GraphNodes( i ) will satisfy 
2344 //   GraphNodes( i )->LinkedInPortsNumber( j ) InPorts of
2345 //      GraphNodes( i )->LinkedNodes( j )
2346             GraphBase::StreamNode * aLinkedNode = GraphNodes( i )->LinkedNodes( j ) ;
2347             int aLinkedInPortsNumber = GraphNodes( i )->LinkedInPortsNumber( j ) ;
2348             cdebug << j << ". LinkedNode " << aLinkedNode->Name() ;
2349             if ( !aLinkedNode->IsDataFlowNode() && !aLinkedNode->IsDataStreamNode() ) {
2350               cdebug << " _DecrInPortsNumber[ "
2351                      << GetGraphNodeIndex( aLinkedNode->Name() )
2352                      << " ] = "
2353                      << _DecrInPortsNumber[ GetGraphNodeIndex( aLinkedNode->Name() ) ]
2354                      << " += " << aLinkedInPortsNumber ;
2355               _DecrInPortsNumber[ GetGraphNodeIndex( aLinkedNode->Name() ) ] += aLinkedInPortsNumber ;
2356             }
2357             cdebug << endl ;
2358           }
2359         }
2360       }
2361 // If no node was found, that FlowGraph is not valid : if we try to execute it, that FlowGraph
2362 // will wait for data(s) from node(s) not executed or not executing for ever
2363       if ( !NewSorted ) {
2364         cdebug << "Loop detected level " << _LevelsNumber << endl ;
2365         return false ; // Loop in the Graph
2366       }
2367 //      cdebug << "Bilan level " << _LevelsNumber << " : " << endl ;
2368       bool ChangeCount = false ;
2369 // We update now the number of InPorts with a link that are waiting for a value
2370       for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2371         if ( _DecrInPortsNumber[ i ] ) {
2372 //          int prevcount = _CnxInPortsNumber[ i ] ;
2373           _CnxInPortsNumber[ i ] -= _DecrInPortsNumber[ i ]  ;
2374           _DecrInPortsNumber[ i ] = 0 ;
2375           ChangeCount = true ;
2376 //          cdebug << "    " << GraphNodes( i )->Name() << " count " << prevcount
2377 //                 << " --> new count " << _CnxInPortsNumber[ i ] << endl ;
2378         }
2379       }
2380 // If there is no loop and if the number of InPorts with a link that are waiting for a value
2381 // does not change, the sort is finished. But there is also NotSortedNumber ...
2382 //      if ( !ChangeCount )
2383 //        break ;
2384       if ( NotSortedNumber ) {
2385         _LevelsNumber += 1 ;
2386       }
2387     }
2388     _ThreadsMax = 0 ;
2389     int AllSortedNodes = 0 ;
2390     _HeadNodes = _SortedNodes[ 0 ] ;
2391     _HeadNodesSize = _SortedNodes[ 0 ].size() ;
2392 // QueueNodes was used in the past in order to know if the execution of a graph is finished
2393 // But because of loop nodes that was changed. So that part of code is a "clutter"
2394 // Now a graph has finished its execution when the number of executing threads is zero
2395     _QueueNodes = _SortedNodes[ _LevelsNumber ] ;
2396     _QueueNodesSize = _SortedNodes[ _LevelsNumber ].size() ;
2397     for ( i = 0 ; i < _QueueNodesSize ; i++ ) {
2398       if ( !_QueueNodes[ i ]->IsGOTONode() ) {
2399         break ;
2400       }
2401     }
2402     if ( i == _QueueNodesSize && _LevelsNumber ) {
2403       _QueueNodes = _SortedNodes[ _LevelsNumber - 1 ] ;
2404       _QueueNodesSize = _SortedNodes[ _LevelsNumber - 1 ].size() ;
2405     }
2406 // Computation of the maximum number of threads == the maximum number of nodes of all levels
2407     for ( i = 0 ; i <= _LevelsNumber ; i++ ) {
2408       AllSortedNodes += _NodesNumber[ i ]+1 ;
2409       if ( _NodesNumber[ i ] + 1 > _ThreadsMax ) {
2410         _ThreadsMax = _NodesNumber[ i ] + 1 ;
2411       }
2412       cdebug << _NodesNumber[ i ]+1 << " Nodes of level " << i << " : "
2413              << (_SortedNodes[ i ])[ 0 ]->Name() << endl ;
2414       for ( j = 1 ; j <= _NodesNumber[ i ] ; j++ ) {
2415         _ParallelExecutionNodes = true ;
2416         cdebug << "                     " << (_SortedNodes[ i ])[ j ]->Name()
2417                << endl ;
2418       }
2419     }
2420     if ( _ParallelExecutionNodes ) {
2421 //      cdebug << "Parallel Execution Nodes detected." << endl ;
2422     }
2423     else {
2424 //      cdebug << "No Parallel Execution Nodes detected." << endl ;
2425     }
2426     if ( AllSortedNodes != GraphNodesSize() ) {
2427       cdebug << "Loop detected level " << _LevelsNumber << endl ;
2428       return false ; // Loop in the Graph
2429     }
2430
2431     cdebug << "Graph::Sort " << _NodesNumber[ 0 ] << " HeadNodes :" << endl ;
2432     for ( i= 0 ; i <= _NodesNumber[ 0 ] ; i++ ) {
2433       (_SortedNodes[ 0 ])[ i ]->HeadNode( true ) ;
2434       cdebug << "            " << i << ". : " << (_SortedNodes[ 0 ])[ i ]->Name() << endl ;
2435     }
2436
2437 // Give a subgraph/substreamgraph number > 0 to HeadNodes (level 0)
2438 // There is no substreamgraph for nodes without StreamPorts
2439     for ( j = 0 ; j <= _NodesNumber[ 0 ] ; j++ ) {
2440       (_SortedNodes[ 0 ])[ j ]->Level( 0 ) ;
2441       (_SortedNodes[ 0 ])[ j ]->SortedIndex( j ) ;
2442       (_SortedNodes[ 0 ])[ j ]->SubGraph( j + 1 ) ;
2443       if ( (_SortedNodes[ 0 ])[ j ]->HasDataStream() ) {
2444         (_SortedNodes[ 0 ])[ j ]->SubStreamGraph( j + 1 ) ;
2445       }
2446       else {
2447         (_SortedNodes[ 0 ])[ j ]->SubStreamGraph( -1 ) ;
2448       }
2449     }
2450
2451 // Give a subgraph/substreamgraph number = 0 to all other nodes :
2452 // the SubGraph of that nodes is unknown
2453 // There is no substreamgraph for nodes without StreamPorts
2454     for ( i = 1 ; i <= _LevelsNumber ; i++ ) {
2455       for ( j = 0 ; j <= _NodesNumber[ i ] ; j++ ) {
2456         (_SortedNodes[ i ])[ j ]->Level( i ) ;
2457         (_SortedNodes[ i ])[ j ]->SortedIndex( j ) ;
2458         (_SortedNodes[ i ])[ j ]->SubGraph( 0 ) ;
2459         if ( (_SortedNodes[ i ])[ j ]->HasDataStream() ) {
2460           (_SortedNodes[ i ])[ j ]->SubStreamGraph( 0 ) ;
2461         }
2462         else {
2463           (_SortedNodes[ i ])[ j ]->SubStreamGraph( -1 ) ;
2464         }
2465       }
2466     }
2467
2468 // Computation of independent SubGraphs which have NO link between them
2469     cdebug << endl << "Computation of SubGraphs" << endl ;
2470     bool Graphs = true ;
2471     while ( Graphs ) {
2472       for ( i = 0 ; i <= _LevelsNumber ; i++ ) {
2473         cdebug << endl << "LevelsNumber " << _LevelsNumber << " " << _NodesNumber[ i ]
2474                << " Nodes :" << endl ;
2475         for ( j = 0 ; j <= _NodesNumber[ i ] ; j++ ) {
2476           GraphBase::ComputingNode * aNode = (_SortedNodes[ i ])[ j ] ;
2477           cdebug << "    " << aNode->Name() << " SubGraph " << aNode->SubGraph() << endl ;
2478           int k ;
2479           for ( k = 0 ; k < aNode->LinkedNodesSize() ; k++ ) {
2480           if ( aNode->LinkedNodes( k )->SubGraph() ) {
2481               if ( aNode->LinkedNodes( k )->SubGraph() != aNode->SubGraph() ) {
2482 //                   && aNode->LinkedNodes( k )->Level() == aNode->Level()+1 ) {
2483 //            aNode->SubGraph( aNode->LinkedNodes( k )->SubGraph() ) ;
2484                 int OldSub = aNode->SubGraph() ;
2485                 int NewSub = aNode->LinkedNodes( k )->SubGraph() ;
2486               cdebug << "        " << aNode->Name() << " changed SubGraph "
2487                        << aNode->LinkedNodes( k )->SubGraph() << endl ;
2488                 int l ;
2489                 for ( l = 0 ; l <= _LevelsNumber ; l++ ) {
2490                   int m ;
2491                   for ( m = 0 ; m <= _NodesNumber[ l ] ; m++ ) {
2492                     if ( (_SortedNodes[ l ])[ m ]->SubGraph() == OldSub ) {
2493                       GraphBase::ComputingNode * aSubNode = (_SortedNodes[ l ])[ m ] ;
2494                       aSubNode->SubGraph( NewSub ) ;
2495                 }
2496                 }
2497               }
2498                 Graphs = false ;
2499                 break ;
2500             }
2501               else {
2502                 cdebug << "        Linked " << aNode->LinkedNodes( k )->Name()
2503                        << " same SubGraph " << aNode->LinkedNodes( k )->SubGraph() << endl ;
2504             }
2505           }
2506             else {
2507               cdebug << "        LinkedNode " << aNode->LinkedNodes( k )->Name()
2508                      << " initial SubGraph " << aNode->SubGraph() << endl ;
2509               aNode->LinkedNodes( k )->SubGraph( aNode->SubGraph() ) ;
2510           }
2511         }
2512           if ( !Graphs ) {
2513             break ;
2514           }
2515         }
2516         if ( !Graphs ) {
2517           break ;
2518         }
2519       }
2520       if ( Graphs ) {
2521         cdebug << endl << "SubGraphs result : " << endl ;
2522         break ;
2523       }
2524       cdebug << endl << "One more time" << endl ;
2525       Graphs = true ;
2526     }
2527 // Make a sequential renumbering of SubGraphs :
2528     _SubGraphsNumber = 0 ;
2529     int CurrGraphsNumber = 0;
2530     int k ;
2531     for ( k = 0 ; k <= _NodesNumber[ 0 ] ; k++ ) {
2532       if ( (_SortedNodes[ 0 ])[ k ]->SubGraph() > CurrGraphsNumber ) {
2533         CurrGraphsNumber = (_SortedNodes[ 0 ])[ k ]->SubGraph() ;
2534         _SubGraphsNumber += 1 ;
2535         for ( i = 0 ; i <= _LevelsNumber ; i++ ) {
2536           for ( j = 0 ; j <= _NodesNumber[ i ] ; j++ ) {
2537             if ( (_SortedNodes[ i ])[ j ]->SubGraph() == CurrGraphsNumber ) {
2538               (_SortedNodes[ i ])[ j ]->SubGraph( _SubGraphsNumber ) ;
2539               cdebug << "SubGraphsNumber " << _SubGraphsNumber << " " << " Level "
2540                      << i << " : " << (_SortedNodes[ i ])[ j ]->Name()
2541                      << endl ;
2542             }
2543           }
2544         }
2545       }
2546     }
2547
2548 //    cdebug << endl << "Computation of SubStreamGraphs" << endl ;
2549     for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2550       GraphBase::ComputingNode * aNode = GraphNodes( i ) ;
2551       if ( aNode->SubStreamGraph() < 0 ) {
2552 //      cdebug << "Graph " << aNode->Name() << " has NO streamport" << endl ;
2553       }
2554       else {
2555 //        cdebug << aNode->Name() << " SubGraph " << aNode->SubGraph() << " --> "
2556 //               << aNode->LinkedStreamNodesSize() << " LinkedStreamNodes :" << endl ;
2557         for ( j = 0 ; j < aNode->LinkedStreamNodesSize()  ; j++ ) {
2558 //          cdebug << "              " << aNode->LinkedStreamNodes( j )->Name() << endl ;
2559         }
2560       }
2561     }
2562
2563 // Computation of independent SubStreamGraphs which have NO StreamLink between them
2564     SubStreamGraphsNumber = 0 ;
2565     int ilevel ;
2566     for ( ilevel = 0 ; ilevel <= _LevelsNumber ; ilevel++ ) {
2567 // Loop for _NodesNumber[ ilevel ] nodes of the level ilevel
2568       int jnode ;
2569       for ( jnode = 0 ; jnode <= _NodesNumber[ ilevel ] ; jnode++ ) {
2570         GraphBase::ComputingNode * aNode = (_SortedNodes[ ilevel ])[ jnode ] ;
2571         if ( aNode->SubStreamGraph() < 0 ) {
2572 //        cdebug << "Graph " << aNode->SubStreamGraph() << " " << aNode->Name()
2573 //                 << " has NO streamport" << endl ;
2574         }
2575         else {
2576           int CurStreamGraphsNumber ;
2577           if ( aNode->SubStreamGraph() > 0 ) {
2578 //          cdebug << "SubStreamGraph " << aNode->SubStreamGraph() << " " << aNode->Name()
2579 //                   << " has streamport LinkedStreamNodesSize already in a SubStreamGraph" << endl ;
2580             CurStreamGraphsNumber = aNode->SubStreamGraph() ;
2581           }
2582           else {
2583             CurStreamGraphsNumber = SubStreamGraphsNumber+1 ;
2584           }
2585           int RetVal = 0 ;
2586           while ( RetVal != CurStreamGraphsNumber ) {
2587             RetVal = CurStreamGraphsNumber ;
2588             aNode->SetSubStreamGraph( CurStreamGraphsNumber , RetVal ) ;
2589             if ( RetVal != CurStreamGraphsNumber ) {
2590               for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2591                 GraphBase::ComputingNode * aNode = GraphNodes( i ) ;
2592                 if ( aNode->SubStreamGraph() == CurStreamGraphsNumber ) {
2593                   aNode->SubStreamGraph( RetVal ) ;
2594                 }
2595               }
2596               CurStreamGraphsNumber = RetVal ;
2597               RetVal = 0 ;
2598             }
2599             if ( CurStreamGraphsNumber > SubStreamGraphsNumber ) {
2600               SubStreamGraphsNumber = CurStreamGraphsNumber ;
2601             }
2602           }
2603         }
2604       }
2605     }
2606 // Make a sequential renumbering of SubGraphs :
2607 //    cdebug << endl << "Last SubStreamGraphsNumber : " << SubStreamGraphsNumber << endl ;
2608     int CurrStreamGraphsNumber = 0 ;
2609     int count = 0 ;
2610     for ( CurrStreamGraphsNumber = 0 ; CurrStreamGraphsNumber <= SubStreamGraphsNumber ; CurrStreamGraphsNumber++ ) {
2611       bool SearchCurrStreamGraphsNumber = true ;
2612       for ( k = 0 ; k <= _LevelsNumber && SearchCurrStreamGraphsNumber ; k++ ) {
2613         int l ;
2614         for ( l = 0 ; l <= _NodesNumber[ k ] && SearchCurrStreamGraphsNumber ; l++ ) {
2615           if ( (_SortedNodes[ k ])[ l ]->SubStreamGraph() == CurrStreamGraphsNumber ) {
2616             SearchCurrStreamGraphsNumber = false ;
2617             count = count + 1 ;
2618             if ( CurrStreamGraphsNumber != count ) {
2619 //              cdebug << "CurrStreamGraphsNumber " << CurrStreamGraphsNumber << " count " << count
2620 //                     << " Level " << k << " n " << l << endl ;
2621               for ( i = k ; i <= _LevelsNumber ; i++ ) {
2622                 for ( j = 0 ; j <= _NodesNumber[ i ] ; j++ ) {
2623                   if ( (_SortedNodes[ i ])[ j ]->SubStreamGraph() == CurrStreamGraphsNumber ) {
2624                     (_SortedNodes[ i ])[ j ]->SubStreamGraph( count ) ;
2625 //                    cdebug << "SubStreamGraphsNumber " << CurrStreamGraphsNumber << " --> " << count << " "
2626 //                           << " Level " << i << " : " << (_SortedNodes[ i ])[ j ]->Name() << endl ;
2627                   }
2628                   else if ( (_SortedNodes[ i ])[ j ]->SubStreamGraph() > 0 ) {
2629 //                    cdebug << "SubStreamGraphsNumber " << (_SortedNodes[ i ])[ j ]->SubStreamGraph()
2630 //                           << " != " << CurrStreamGraphsNumber << " Level " << i << " : "
2631 //                           << (_SortedNodes[ i ])[ j ]->Name() << endl ;
2632                   }
2633                 }
2634               }
2635             }
2636           }
2637         }
2638       }
2639     }
2640     SubStreamGraphsNumber = count ;
2641 //    cdebug << endl << "SubStreamGraphs result : " << SubStreamGraphsNumber << " SubStreamGraphs" << endl ;
2642 //    int CurrStreamGraphsNumber ;
2643 //    for ( CurrStreamGraphsNumber = 1 ; CurrStreamGraphsNumber <= SubStreamGraphsNumber  ; CurrStreamGraphsNumber++ ) {
2644 //      for ( ilevel = 0 ; ilevel <= _LevelsNumber ; ilevel++ ) {
2645 //        for ( k = 0 ; k <= _NodesNumber[ ilevel ] ; k++ ) {
2646 //          if ( (_SortedNodes[ ilevel ])[ k ]->SubStreamGraph() == CurrStreamGraphsNumber ) {
2647 //            cdebug << "SubStreamGraphsNumber " << CurrStreamGraphsNumber << " : "
2648 //                   << (_SortedNodes[ ilevel ])[ k ]->Name() << endl ;
2649 //        }
2650 //      }
2651 //      }
2652 //    }
2653   }
2654
2655 #ifdef _DEBUG_
2656   ListPorts( *_Graph_fdebug , 0 ) ;
2657 #endif
2658
2659   cdebug_out << "GraphBase::Graph::Sort" << endl;
2660   return true ;
2661 }
2662
2663 bool GraphBase::Graph::ValidLoops() const {
2664   cdebug_in << "GraphBase::Graph::ValidLoops" << endl;
2665
2666   int i ;
2667   GraphBase::ComputingNode * aNode ;
2668   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2669     aNode = GraphNodes( i ) ;
2670     if ( aNode->IsLoopNode() ) {
2671       GraphBase::LoopNode * aLoopNode = (GraphBase::LoopNode * ) aNode ;
2672       GraphBase::EndOfLoopNode * anEndLoopNode ;
2673       anEndLoopNode = (GraphBase::EndOfLoopNode * ) aLoopNode->CoupledNode() ;
2674       if ( !aLoopNode->CheckLoop( aLoopNode , anEndLoopNode ) ) {
2675         cdebug_out << "GraphBase::Graph::ValidLoops false aLoopNode " << aLoopNode->Name()
2676                    << endl;
2677         return false ;
2678       }
2679       else if ( !anEndLoopNode->CheckEndLoop( aLoopNode , anEndLoopNode ) ) {
2680         cdebug_out << "GraphBase::Graph::ValidLoops false anEndLoopNode " << anEndLoopNode->Name()
2681                    << endl;
2682         return false ;
2683       }
2684     }
2685   }
2686   cdebug_out << "GraphBase::Graph::ValidLoops true" << endl;
2687   return true ;
2688 }
2689
2690 bool GraphBase::Graph::ValidSwitchs() const {
2691   cdebug_in << "GraphBase::Graph::ValidSwitchs" << endl;
2692
2693   int i ;
2694   GraphBase::ComputingNode * aNode ;
2695   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2696     aNode = GraphNodes( i ) ;
2697     if ( aNode->IsSwitchNode() ) {
2698       GraphBase::SwitchNode * aSwitchNode = (GraphBase::SwitchNode * ) aNode ;
2699       if ( !aSwitchNode->CheckSwitch() ) {
2700         cdebug_out << "GraphBase::Graph::ValidSwitchs false aSwitchNode " << aSwitchNode->Name()
2701                    << endl;
2702         return false ;
2703       }
2704     }
2705   }
2706   cdebug_out << "GraphBase::Graph::ValidSwitchs true" << endl;
2707   return true ;
2708 }
2709
2710 // Controle de la coherence des noeuds de calcul
2711 // Enregistrement dans la liste des noeuds "tete" de graphe
2712
2713 bool GraphBase::Graph::ComputingNodes() const {
2714   bool RetVal = true ;
2715   cdebug << "GraphExecutor::Graph::ComputingNodes ()" << endl;
2716
2717 //  list<GraphEditor::Node *> aComputingNodesList = _G->ComputingNodesList() ;
2718 //  list<GraphEditor::Node *>::iterator aNode = aComputingNodesList.begin();
2719 //  GraphEditor::Port *  iP;
2720
2721 //  for (aNode = _G->ComputingNodesList().begin(); aNode !=_G->ComputingNodesList().end(); aNode++) {
2722 //  while ( aNode != aComputingNodesList.end() ) {
2723   int i ;
2724   GraphBase::ComputingNode * aNode ;
2725   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2726     aNode = GraphNodes( i ) ;
2727     cdebug << "Graph::ComputingNodes " << i << ". " << aNode->Name() << " Head " << aNode->IsHeadNode()
2728            << endl ;
2729     // Tous les ports d'entree de tous les noeuds de calcul sont bien connectes
2730     // Enregistrement eventuel dans la liste des noeuds "tete" de graphe
2731 //    if ((*aNode)->GetNodeInPortsSize() == 0)
2732 //      _headNodes.push_front(*aNode);
2733     int j ;
2734     for ( j = 1 ; j < aNode->GetNodeInPortsSize() ; j++ ) {
2735       const GraphBase::InPort *iP = aNode->GetNodeInPort(j);
2736       if ( iP->IsNotConnected() ){
2737 //      cdebug << "Le port d'entree " << iP->PortName()
2738 //               << " du noeud de calcul " << aNode->Name() << " du graphe  "
2739 //               << Name() << " n'est pas connecte "<< endl;
2740         RetVal = false ;
2741       };
2742
2743     };
2744
2745     // Tous les noeuds de calcul ont au moins un port de sortie connecte
2746     bool oneOutPortConnected = false;
2747     for ( j = 1 ; j < aNode->GetNodeOutPortsSize() ; j++) {
2748       const GraphBase::OutPort *iP = aNode->GetNodeOutPort(j);
2749       if ( iP->IsPortConnected() || iP->IsDataConnected() ){
2750         oneOutPortConnected = true ;
2751 //      break;
2752       }
2753       else {
2754 //      cdebug << "Le port de sortie " << iP->PortName()
2755 //               << " du noeud de calcul " << aNode->Name() << " du graphe  "
2756 //               << Name() << " n'est pas connecte "<< endl;
2757         RetVal = false ;
2758       }
2759     };
2760     if (!oneOutPortConnected) {
2761 //      cdebug << "Le noeud de calcul " << aNode->Name() << " du graphe  "
2762 //               << Name() << " n'a aucun port de sortie connecte "<< endl;
2763 //      _computingError.push_front(2);
2764     }
2765   };
2766 //  return _computingError.size () ;
2767   return RetVal ;
2768 }
2769
2770 bool GraphBase::Graph::LinkLoopNodes(bool & NewLink ) {
2771   bool RetVal = true ;
2772   NewLink = false ;
2773   int i , j ;
2774   cdebug_in << "GraphBase::Graph::LinkLoopNodes()" << endl;
2775   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2776     GraphBase::ComputingNode * aNode = GraphNodes( i ) ;
2777     if ( aNode->IsLoopNode() ) {
2778       GraphBase::LoopNode * aLoopNode = (GraphBase::LoopNode * ) aNode ;
2779       for ( j = 0 ; j < aLoopNode->GetNodeInPortsSize() ; j++ ) {
2780         GraphBase::InPort *anInPort = aLoopNode->GetChangeNodeInPort(j) ;
2781         cdebug << "Graph::LinkLoopNodes " << aLoopNode->Name() << "( " << anInPort->PortName()
2782                << " ) InPort " << anInPort->PortStatus() << endl ;
2783         if ( !anInPort->IsGate() && anInPort->IsNotConnected() ) {
2784           if ( !AddLink( aLoopNode->CoupledNode() , aLoopNode->CoupledNode()->GetChangeNodeOutPort( j ) ,
2785                          aLoopNode , anInPort ) ) {
2786             cdebug << "Graph::LinkLoopNodes AddLink ERROR "
2787                    << aLoopNode->CoupledNode()->Name()
2788                    << "( " << aLoopNode->CoupledNode()->GetChangeNodeOutPort( j )->PortName()
2789                    << " ) --> " << aLoopNode->Name() << "( " << anInPort->PortName() << " )"
2790                    << endl ;
2791             RetVal = false ;
2792           }
2793           else {
2794             NewLink = true ;
2795           }
2796         }
2797       }
2798       for ( j = 0 ; j < aLoopNode->CoupledNode()->GetNodeInPortsSize() ; j++ ) {
2799         GraphBase::EndOfLoopNode * anEndLoopNode ;
2800         anEndLoopNode = (GraphBase::EndOfLoopNode * ) aLoopNode->CoupledNode() ;
2801         GraphBase::InPort *anInPort = anEndLoopNode->GetChangeNodeInPort( j ) ;
2802         cdebug << "Graph::LinkLoopNodes " << anEndLoopNode->Name() << "( " << anInPort->PortName()
2803                << " ) InPort " << anInPort->PortStatus() << endl ;
2804         if ( !anInPort->IsGate() && anInPort->IsNotConnected() ) {
2805           if ( !AddLink( aLoopNode , aLoopNode->GetChangeNodeOutPort( j ) ,
2806                          anEndLoopNode , anInPort ) ) {
2807             cdebug << "Graph::LinkLoopNodes AddLink ERROR " << aLoopNode->Name() << "( "
2808                    << aLoopNode->GetChangeNodeOutPort( j )->PortName() << " ) --> "
2809                    << anEndLoopNode->Name() << "( " << anInPort->PortName() << " )"
2810                    << endl ;
2811             RetVal = false ;
2812           }
2813           else {
2814             NewLink = true ;
2815           }
2816         }
2817       }
2818     }
2819     else if ( aNode->IsGOTONode() ) {
2820       GraphBase::GOTONode * aGOTONode = (GraphBase::GOTONode * ) aNode ;
2821       GraphBase::OutPort *anOutGate = aGOTONode->GetChangeNodeOutGate() ;
2822       if ( anOutGate->IsNotConnected() ) {
2823         if ( aGOTONode->CoupledNode() ) {
2824           cdebug << "Graph::LinkLoopNodes aNode " << aNode << " : " << aNode->Name()
2825                  << aGOTONode->CoupledNode() << " : " << aGOTONode->CoupledNode()->Name()
2826                  << endl ;
2827           RetVal = AddLink( aGOTONode , anOutGate , aGOTONode->CoupledNode() ,
2828                             aGOTONode->CoupledNode()->GetChangeNodeInGate() );
2829           cdebug << "GraphBase::Graph::LinkLoopNodes AddLink ERROR " << aGOTONode->Name() << "( "
2830                  << anOutGate->PortName() << " ) --> " << aGOTONode->CoupledNode()->Name() << "( "
2831                  << aGOTONode->CoupledNode()->GetChangeNodeInGate()->PortName() << " )" << endl ;
2832           if ( !RetVal )
2833             NewLink = true;
2834         }
2835       }
2836     }
2837   }
2838   cdebug_out << "GraphBase::Graph::LinkLoopNodes() NewLink " << NewLink << " returns " << RetVal
2839              << endl;
2840   return RetVal ;
2841 }
2842
2843 // Controle de la coherence des noeuds de calcul
2844 // Enregistrement dans la liste des noeuds "tete" de graphe
2845
2846 bool GraphBase::Graph::DataServerNodes() const {
2847
2848   cdebug_in << "GraphBase::Graph::DataServerNodes ()" << endl;
2849
2850 //  const GraphExecutor::InNode *DataFlowDatas = GetDataFlowDatas() ;
2851   int i , j , ierr = 0 ;
2852
2853 //  if ( DataFlowDatas == NULL ) {
2854 //    MESSAGE( "No input data available in the DataFlow " << _G->Name() );
2855 //    return 0 ;
2856 //  }
2857
2858 //  const GraphExecutor::InNode *DataFlowNode = _G->GetDataFlowNode() ;
2859 //  MESSAGE( "DataServerNodes DataFlowNode : " << *DataFlowNode );
2860
2861 //  MESSAGE( "DataServerNodes DataFlowDatas : " << *DataFlowDatas );
2862
2863 // cout are inversed because DataFlowDatas is a mirror node of the DataFlow
2864
2865   ierr = CheckDataServerNodes() ;
2866
2867 //  list<GraphExecutor::InNode *> aComputingNodesList = _G->ComputingNodesList() ;
2868 //  list<GraphExecutor::InNode *>::iterator aNode = aComputingNodesList.begin();
2869   if ( GraphNodesSize() == 0 ) {
2870     ierr++ ;
2871   }
2872   else {
2873     GraphBase::ComputingNode * aNode ;
2874     for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2875       aNode = GraphNodes( i ) ;
2876 //  while ( aNode != aComputingNodesList.end() ) {
2877       if ( aNode->IsFactoryNode() ) {
2878         GraphBase::FactoryNode * FaNode = (GraphBase::FactoryNode * ) aNode ;
2879         if ( !strlen( FaNode->Computer() ) ) {
2880 //          cdebug << "ComputerName missing for node " << FaNode->Name() ;
2881           if ( !strlen( FaNode->Computer() ) ) {
2882             ierr++ ;
2883             cdebug << endl ;
2884           }
2885           else {
2886 //            cdebug << ". " << FaNode->Computer() << " will be used." << endl ;
2887           }
2888         }
2889     }
2890 // For Outputs of the DataFlow :
2891       for ( j = 0 ; j < aNode->GetNodeOutPortsSize() ; j++ ) {
2892         const GraphBase::OutPort * anOutPort = aNode->GetNodeOutPort(j) ;
2893 //JR Debug 06.06.2005 : if it is not a Gate !
2894 //        if ( anOutPort->IsNotConnected() ) {
2895         if ( anOutPort->IsNotConnected() && !anOutPort->IsGate() ) {
2896           cdebug << "Graph::DataServerNodes Add[Stream]LinkedNode for OutPort "
2897                  << aNode->Name() << "( " << anOutPort->PortName() << " , "
2898                  << anOutPort->PortStatus() << " )" << endl ;
2899           if ( anOutPort->IsDataStream() ) {
2900             aNode->AddStreamLinkedNode( (GraphBase::ComputingNode *) this ) ;
2901           }
2902           else {
2903             aNode->AddLinkedNode( (GraphBase::ComputingNode *) this ) ;
2904           }
2905         }
2906       }
2907     }
2908   }
2909
2910 // Chaque noeud dataserver ne possede qu'un seul port entree ou sortie et il est bien connecte
2911
2912 //  list<GraphExecutor::InNode *> aDataServerNodesList = _G->DataServerNodesList() ;
2913 //  list<GraphExecutor::InNode *>::iterator it = aDataServerNodesList.begin() ;
2914
2915 //  for (it = _G->DataServerNodesList().begin(); it !=_G->DataServerNodesList().end(); it++){
2916 //  while ( it != aDataServerNodesList.end() ) {
2917 //    if ( (*it)->GetNodeOutPortsSize() && (*it)->GetNodeInPortsSize() ) {
2918 //      cerr << "Erreur dans le noeud serveur de donnees " 
2919 //           << (*it)->Name() << " du graphe  " << _G->Name() << endl;
2920 //      cerr << "A la fois importation et exportation de donnees" << endl;
2921 //      _dataServerError.push_front(1);
2922 //    }
2923
2924 //    if ((*it)->GetNodeOutPortsSize()) {
2925 //      if ((*it)->GetNodeOutPortsSize()==1){
2926 //      if ( (*it)->GetNodeOutPort(0)->IsPortConnected() ){
2927 //        _headNodes.push_front(*it);
2928 //      }
2929 //      else {
2930 //        cerr << "Le port de sortie du noeud serveur de donnees "
2931 //               << (*it)->Name() << " du graphe  " << _G->Name()
2932 //               << " n'est pas connecte "<< endl;
2933 //        _dataServerError.push_front(4);
2934 //      }
2935 //      }
2936 //      else {
2937 //      cerr << "Plus d'une donnee importee du noeud serveur de donnees "
2938 //             << (*it)->Name() << " du graphe  " << _G->Name() << endl;
2939 //      _dataServerError.push_front(2);
2940 //      }
2941 //    }
2942
2943 //    if ((*it)->GetNodeInPortsSize()) {
2944 //      if ((*it)->GetNodeInPortsSize() > 1){
2945 //      cerr << "Plus d'une donnee exportee vers le noeud serveur de donnees "
2946 //             << (*it)->Name() << " du graphe  " << _G->Name() << endl;
2947 //      _dataServerError.push_front(3);
2948 //      }
2949 //      else
2950 //      if ( !(*it)->GetNodeInPort(0)->IsPortConnected() ){
2951 //      cerr << "Le port d'entree du noeud serveur de donnees "
2952 //             << (*it)->Name() << " du graphe  " << _G->Name()
2953 //             << " n'est pas connecte "<< endl;
2954 //      _dataServerError.push_front(5);
2955 //      }
2956 //    }
2957 //    it++ ;
2958 //  };
2959
2960 //  return _dataServerError.size ();
2961   cdebug_out << "GraphBase::Graph::DataServerNodes ierr " << ierr << endl;
2962   return ( ierr == 0 ) ;
2963 }
2964
2965 SUPERV::GraphState GraphBase::Graph::PortState(
2966                                    const char* NodeName ,
2967                                    const char* ServiceParameterName ) {
2968   SUPERV::GraphState aRet = SUPERV::UndefinedState ;
2969 //  cdebug << "GraphBase::Graph::PortState( " << NodeName << " , "
2970 //         << ServiceParameterName << " )" << endl ;
2971
2972   char *theNode ;
2973   char *aPort ;
2974   NodePort( NodeName , ServiceParameterName , &theNode , &aPort ) ;
2975
2976   GraphBase::ComputingNode * aNode = GetChangeGraphNode( theNode ) ;
2977   if ( aNode ) {
2978     GraphBase::OutPort *anOutPort ;
2979     anOutPort = aNode->GetChangeOutPort( aPort );
2980     if ( anOutPort == NULL ) {
2981       GraphBase::InPort *anInPort = aNode->GetChangeInPort( aPort );
2982       if ( anInPort )
2983         anOutPort = anInPort->GetOutPort() ;
2984       else {
2985         cdebug << "ERROR GraphBase::Graph::PortState OutPort/InPort not found --> "
2986                << aRet << endl ;
2987       }
2988     }
2989     if ( anOutPort ) {
2990       aRet = anOutPort->PortState() ;
2991 //      cdebug << "GraphBase::Graph::PortState --> " << aRet << endl ;
2992     }
2993   }
2994   else {
2995     cdebug << "ERROR GraphBase::Graph::PortState Node not found --> " << aRet
2996            << endl ;
2997   }
2998   delete theNode ;
2999   delete aPort ;
3000   return aRet ;
3001 }
3002
3003 #define TracePortInOutData 0
3004 //JR 30.03.2005const CORBA::Any * GraphBase::Graph::PortInData( const char* ToNodeName ,
3005 const CORBA::Any GraphBase::Graph::PortInData( const char* ToNodeName ,
3006                                                const char* ToServiceParameterName ) {
3007 //JR 30.03.2005  const CORBA::Any * aRet = new CORBA::Any() ;
3008   CORBA::Any aRet = CORBA::Any() ;
3009   char *theNode ;
3010   char *aPort ;
3011 #if TracePortInOutData
3012   cdebug_in << "GraphBase::Graph::PortInData " << ToNodeName << " "
3013             << ToServiceParameterName << endl ;
3014 #endif
3015   NodePort( ToNodeName , ToServiceParameterName , &theNode , &aPort ) ;
3016
3017   GraphBase::ComputingNode * aNode = GetChangeGraphNode( theNode ) ;
3018
3019   if ( aNode ) {
3020     GraphBase::OutPort *anOutPort = NULL ;
3021     GraphBase::InPort *anInPort = aNode->GetChangeInPort( aPort );
3022     if ( anInPort ) {
3023       anOutPort = anInPort->GetOutPort() ;
3024       if ( anOutPort ) {
3025 #if TracePortInOutData
3026         cdebug << "-->PortInData " << ToNodeName << " " << ToServiceParameterName << " "
3027                << endl ;
3028 #endif
3029         aRet = anOutPort->Value() ;
3030 #if TracePortInOutData
3031         cdebug << "<--PortInData " << ToNodeName << " " << ToServiceParameterName << " " ;
3032         anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
3033         cdebug << endl ;
3034         cdebug << "Graph::PortInData OutPort value " << anOutPort->NodeName() << "("
3035                << anOutPort->PortName() << ") --> InPort " << anInPort->NodeName()
3036                << "(" << anInPort->PortName() << ") " << anInPort->PortStatus() << endl ;
3037 #endif
3038       }
3039       else {
3040         cdebug << "Graph::PortInData GraphBase::Graph::PortInData " << ToNodeName << " "
3041                << ToServiceParameterName << " ERROR no OutPort" << endl ;
3042       }
3043     }
3044     else {
3045       cdebug << "GraphBase::Graph::PortInData " << ToNodeName << " "
3046              << ToServiceParameterName << " ERROR no InPort" << endl ;
3047     }
3048   }
3049   else {
3050     cdebug << "GraphBase::Graph::PortInData " << ToNodeName << " "
3051            << ToServiceParameterName << " ERROR no Node" << endl ;
3052   }
3053   delete theNode ;
3054   delete aPort ;
3055 #if TracePortInOutData
3056   cdebug_out << "GraphBase::Graph::PortInData " << endl ;
3057 #endif
3058   return aRet ;
3059 }
3060
3061 //JR 30.03.2005const CORBA::Any * GraphBase::Graph::PortOutData( const char* FromNodeName ,
3062 const CORBA::Any GraphBase::Graph::PortOutData( const char* FromNodeName ,
3063                                                 const char* FromServiceParameterName ) {
3064 //JR 30.03.2005  const CORBA::Any * aRet = new CORBA::Any() ;
3065   CORBA::Any aRet = CORBA::Any() ;
3066   char *theNode ;
3067   char *aPort ;
3068 #if TracePortInOutData
3069   cdebug_in << "GraphBase::Graph::PortOutData " << FromNodeName << " "
3070             << FromServiceParameterName << endl ;
3071 #endif
3072   NodePort( FromNodeName , FromServiceParameterName , &theNode , &aPort ) ;
3073
3074   GraphBase::ComputingNode * aNode = GetChangeGraphNode( theNode ) ;
3075
3076   if ( aNode ) {
3077     GraphBase::OutPort *anOutPort ;
3078     anOutPort = aNode->GetChangeOutPort( aPort );
3079     if ( anOutPort ) {
3080 #if TracePortInOutData
3081       cdebug << "-->PortOutData " << FromNodeName << " " << FromServiceParameterName << " "
3082              << endl ;
3083 #endif
3084       aRet = anOutPort->Value() ;
3085 #if TracePortInOutData
3086       cdebug << "<--PortOutData " << FromNodeName << " " << FromServiceParameterName << " " ;
3087       anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
3088       cdebug << endl ;
3089 #endif
3090     }
3091     else {
3092       cdebug << "GraphBase::Graph::PortOutData " << FromNodeName << " "
3093              << FromServiceParameterName << " ERROR no OutPort" << endl ;
3094     }
3095   }
3096   else {
3097     cdebug << "GraphBase::Graph::PortOutData " << FromNodeName << " "
3098            << FromServiceParameterName << " ERROR no Node" << endl ;
3099   }
3100   delete theNode ;
3101   delete aPort ;
3102 #if TracePortInOutData
3103   cdebug_out << "GraphBase::Graph::PortOutData " << endl ;
3104 #endif
3105   return aRet ;
3106 }
3107
3108 SUPERV::ListOfStrings * GraphBase::Graph::LevelNodes(long aLevel ) {
3109   SUPERV::ListOfStrings_var RetVal = new SUPERV::ListOfStrings;
3110   if ( aLevel >= 0 && aLevel <= _LevelsNumber ) {
3111     int i ;
3112     RetVal->length( _NodesNumber[ aLevel ] + 1 );
3113     for ( i= 0 ; i <= _NodesNumber[ aLevel ] ; i++ ) {
3114       RetVal[i] = CORBA::string_dup( (_SortedNodes[ aLevel ])[ i ]->Name() ) ;
3115     }
3116   }
3117   return ( RetVal._retn() ) ;
3118 }
3119
3120 bool GraphBase::Graph::StartComponent(const int aThread ,
3121                                       const char * aComputerContainer ,
3122                                       const char * ComponentName ,
3123                                       Engines::Container_var & myContainer ,
3124                                       Engines::Component_var & objComponent ) {
3125   cdebug_in << aThread
3126             << " GraphBase::Graph::StartComponent " << aComputerContainer
3127             << " " << ComponentName << endl;
3128   bool RetVal = true ;
3129
3130   SALOME_LifeCycleCORBA LCC( NamingService() ) ;
3131   objComponent = LCC.FindOrLoad_Component( aComputerContainer ,
3132                                            ComponentName );
3133   if ( CORBA::is_nil( objComponent ) ) {
3134     cdebug_out << aThread 
3135                << " StartComponent cannot FindOrLoad " << aComputerContainer
3136                << " " << ComponentName << " ERROR" << endl;
3137     return 0 ;
3138   }
3139   /* asv : 24.01.05 : FindContainer() method does not exist any more.  FindOrLoad_Component()
3140                       starts the container for us.  If it fails to start the container, then it
3141                       returns nil component.  We don't need to check for if the container was 
3142                       successfully started..
3143   else {
3144     myContainer = LCC.FindContainer( aComputerContainer );
3145     if ( CORBA::is_nil( myContainer ) ) {
3146       cdebug_out << aThread
3147                  << " GraphBase::Graph::StartComponent myContainer = LCC.FindContainer( '"
3148                  << aComputerContainer << "' ) Container does not exist ERROR"
3149                  << endl ;
3150       return 0 ;
3151     }
3152   }
3153   */
3154    cdebug_out << aThread << " GraphBase::Graph::StartComponent " << RetVal << endl;
3155   return RetVal ;
3156 }