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