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