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