Salome HOME
Fix for bug IPAL8054 : "Supervisor is running" wrong message.
[modules/superv.git] / src / GraphBase / DataFlowBase_Graph.cxx
1 //  SUPERV GraphBase : contains fondamental classes for Services, Input Ports, Output Ports Links and Nodes.
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : DataFlowBase_Graph.cxx
25 //  Author : Jean Rahuel, CEA
26 //  Module : SUPERV
27 //  $Header:
28
29 using namespace std;
30 #include "DataFlowBase_StreamGraph.hxx"
31
32 #include "SALOME_LifeCycleCORBA.hxx"
33
34 GraphBase::Graph::Graph() :
35            DataNode() {
36   cdebug << "GraphBase::Graph::Graph" << endl ;
37   _GraphNodesSize = 0 ;
38   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 //JR 29.09.2005 Debug for CEA : we do not do that for MacroNodes :
1105       if ( !fromNode->IsMacroNode() ) {
1106         aValue <<= (long ) 1 ;
1107       }
1108       else {
1109         aValue <<= (long ) 0 ;
1110       }
1111       fromPort->SetValue( aValue ) ;
1112     }
1113 //    else {
1114 //      const CORBA::Any * aDataValue = new CORBA::Any( aValue ) ;
1115 //      fromPort->Value( aDataValue ) ;
1116 //    }
1117 //    fromPort->PortStatus( DataConnected );
1118   }
1119
1120   cdebug_out << "GraphBase::Graph::AddLink " << RetVal << endl;
1121   return RetVal ;
1122 }
1123
1124 bool GraphBase::Graph::AddLink( GraphBase::ComputingNode *fromNode ,
1125                                 GraphBase::OutPort *fromPort ,
1126                                 GraphBase::ComputingNode *toNode ,
1127                                 GraphBase::InPort *toPort ) {
1128 //  bool RetVal ;
1129
1130   if ( !fromNode ) {
1131     cdebug << "ERROR AddLink fromNode not found." << endl ;
1132     return false ;
1133   }
1134   if ( !fromPort ) {
1135     cdebug << "ERROR AddLink fromPort not found." << endl ;
1136     return false ;
1137   }
1138
1139   if ( !toNode ) {
1140     cdebug << "ERROR AddLink toNode not found." << endl ;
1141     return false ;
1142   }
1143   if ( !toPort ) {
1144     cdebug << "ERROR AddLink toPort not found." << endl ;
1145     return false ;
1146   }
1147   if ( ( fromPort->IsDataStream() && !toPort->IsDataStream() ) ||
1148        ( !fromPort->IsDataStream() && toPort->IsDataStream() ) ) {
1149     cdebug << "AddLink fromPort/toPort Stream/Flow. ERROR" << endl ;
1150     return false ;
1151   }
1152   if ( fromPort->IsDataStream() && fromPort->Dependency() == SALOME_ModuleCatalog::DATASTREAM_TEMPORAL &&
1153        toPort->Dependency() == SALOME_ModuleCatalog::DATASTREAM_ITERATIVE ) {
1154     cdebug << "AddLink fromPort/toPort Stream DATASTREAM_TEMPORAL --> DATASTREAM_ITERATIVE. ERROR" << endl ;
1155     return false ;
1156   }
1157
1158   cdebug_in << "Graph::AddLink( " << fromNode->Name() << "("
1159             << fromPort->PortName() << " " << fromPort->PortStatus() << ") " << fromPort->Kind()
1160             << " ---> " << toNode->Name() << "(" << toPort->PortName() << " " << toPort->PortStatus()
1161             << ") " << toPort->Kind() << " )" << endl;
1162   ostringstream LinkStrError ;
1163   LinkStrError << "Creation of link from " << fromNode->Name() << "( "
1164                << fromPort->PortName() << " " << fromPort->PortStatus() << " " << fromPort->Kind()
1165                << " ) ---> " << toNode->Name() << "( " << toPort->PortName() << " "
1166                << toPort->PortStatus() << " " << toPort->Kind() << " ) :\n" ;
1167   if ( fromPort->IsDataConnected() || fromPort->IsExternConnected() ) {
1168     if ( !fromPort->RemoveInPort() ) { // There is only one ===> RemoveOutPort()
1169       cdebug_out << "GraphBase::Graph::AddLink in OutPort ( " << fromNode->Name() << "("
1170                  << fromPort->PortName() << " " << fromPort->PortStatus()
1171                  << ") RemoveInPort ERROR InPortsSize " << fromPort->InPortsSize() << endl ;
1172       return false ;
1173     }
1174   }
1175   if ( toPort->IsDataConnected() || toPort->IsExternConnected() ) {
1176     if ( !toPort->GetOutPort()->RemoveInPort() ) { // There is only one ===> RemoveOutPort()
1177       cdebug_out << "GraphBase::Graph::AddLink in InPort connected to the OutPort ( "
1178                  << toNode->Name() << "(" << toPort->PortName() << " " << toPort->PortStatus()
1179                  << ") RemoveInPort ERROR InPortsSize " << toPort->GetOutPort()->InPortsSize()
1180                  << endl ;
1181       return false ;
1182     }
1183   }
1184   else if ( toPort->IsPortConnected() && !toNode->IsEndSwitchNode() ) {
1185     if ( !RemoveLink( toPort->GetOutPort()->NodeName() ,
1186                       toPort->GetOutPort()->PortName() ,
1187                       toNode->Name() , toPort->PortName() ) ) {
1188       cdebug_out << "RemoveLink(AddLink) toPort->GetOutPort()->NodeName() RemoveLink Error." << endl ;
1189       return false ;
1190     }
1191   }
1192
1193   if ( !fromNode->IsDataFlowNode() && !fromNode->IsDataStreamNode() &&
1194        !toNode->IsDataFlowNode() && !toNode->IsDataStreamNode() &&
1195        toPort->GetOutPort() ) {
1196 //JR Debug 15.06.2005 : the case of multiple links to EndSwitchNode was missing :
1197     if ( toNode->IsEndSwitchNode() && fromPort->GetInPort( toPort ) == toPort ) {
1198       LinkStrError << "Link already exists.\n" ;
1199       SetMessages( LinkStrError.str() ) ;
1200       cdebug << "Link already exists" << endl ;
1201       cdebug_out << "GraphBase::Graph::AddLink 1" << endl;
1202       return true ;
1203     }
1204     else if ( !strcmp( toPort->GetOutPort()->NodePortName() ,
1205                   fromPort->NodePortName() ) ) {
1206       LinkStrError << "Link already exists.\n" ;
1207       SetMessages( LinkStrError.str() ) ;
1208       cdebug << "Link already exists" << endl ;
1209       cdebug_out << "GraphBase::Graph::AddLink 1" << endl;
1210       return true ;
1211     }
1212     else if ( toPort->IsDataConnected() || toPort->IsExternConnected() ) {
1213       toPort->GetOutPort()->RemoveInPort( toPort ) ; //dbg
1214     }
1215     else if ( fromNode->IsGOTONode() ) {
1216       if ( !RemoveLink( toPort->GetOutPort()->NodeName() ,
1217                         toPort->GetOutPort()->PortName() ,
1218                         toNode->Name() , toPort->PortName() ) ) {
1219         cdebug << "RemoveLink(AddLink) Error."
1220                << endl ;
1221         cdebug_out << "GraphBase::Graph::AddLink" << endl;
1222         return false ;
1223       }
1224       if ( fromPort->InPortsSize() ) {
1225         if ( !RemoveLink( fromNode->Name() , fromPort->PortName() ,
1226                           fromPort->ChangeInPorts(0)->NodeName() ,
1227                           fromPort->ChangeInPorts(0)->PortName() ) ) {
1228           cdebug << "RemoveLink(AddLink) fromNode->IsGOTONode Error." << endl ;
1229           cdebug_out << "GraphBase::Graph::AddLink" << endl;
1230           return false ;
1231         }
1232       }
1233     }
1234 //PAL8511
1235 // JR 17.01.2005 : toPort is already linked : RemoveLink
1236     else if ( !toNode->IsEndSwitchNode() ) {
1237 //    else if ( !toNode->IsEndSwitchNode() ||
1238 //              ( toNode->IsEndSwitchNode() && toPort->IsGate() ) ) {
1239 //JR Debug : the fromPort was wrong !
1240 //      if ( !RemoveLink( fromNode->Name() , fromPort->PortName() ,
1241       if ( !RemoveLink( toPort->GetOutPort()->NodeName() , toPort->GetOutPort()->PortName() ,
1242                         toNode->Name() , toPort->PortName() ) ) {
1243         cdebug << "RemoveLink(AddLink) toNode->IsEndSwitchNode Error." << endl ;
1244         cdebug_out << "GraphBase::Graph::AddLink" << endl;
1245         return false ;
1246       }
1247     }
1248 //JR 15.06.2005 : disabled : GraphSwitchBranchGates ...
1249 //    else if ( fromNode->IsSwitchNode() && toNode->IsEndSwitchNode() && !toPort->IsGate() ) {
1250 //      cdebug << "fromNode->IsSwitchNode() && toNode->IsEndSwitchNode toPort(NotGate)Error."
1251 //             << endl ;
1252 //      LinkStrError << "Link from SwitchNode to EndSwitchNode is not allowed.\n" ;
1253 //      SetMessages( LinkStrError.str() ) ;
1254 //      cdebug << "Graph::AddLink ERROR Link from SwitchNode to EndSwitchNode is not allowed."
1255 //             << endl ;
1256 //      cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1257 //      return false ;
1258 //    }
1259 //JR 15.06.2005 : SwitchNode(Default) may be only linked to EndSwitchNode(Default)
1260 //PAL8511
1261 //JR Debug 15.02.2005 : Not multiple links in that case except if toPort is the DefaultPort
1262     else if ( fromNode->IsSwitchNode() && fromPort->IsGate() &&
1263               !toNode->IsEndSwitchNode() ) {
1264       LinkStrError << "Link from SwitchNode(Default) is allowed only to EndSwitchNode(Default).\n" ;
1265       SetMessages( LinkStrError.str() ) ;
1266       cdebug << "SwitchNode(Default) may be only linked to EndSwitchNode(Default) AddLink Error."
1267              << endl ;
1268       cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1269       return false ;
1270     }
1271   }
1272 //PAL7990
1273 //JR 24.03.2005 : No Link between OutPort of SwitchNode to InPort of EndSwitchNode except if
1274 // they have the same name for a special case :
1275 // Switch with no branch ==> Default is applied always : GraphSyrControl example
1276 //JR 22.06.2005 : Enhancement of the behaviour :
1277 //                For the DefaultBranch, if we have same PortsNames, Values are automatically
1278 //                    transmitted
1279 //                But for the DefaultBranch, if we have NOT same PortsNames, we may create links.
1280 //                Look at GraphSyrControlAve* ...
1281 #if 0
1282   else if ( fromNode->IsSwitchNode() && !fromPort->IsGate() &&
1283             toNode->IsEndSwitchNode() && !toPort->IsGate() &&
1284             strcmp( fromPort->PortName() , toPort->PortName() ) ) {
1285     LinkStrError << "Link from SwitchNode to EndSwitchNode with different PortNames is not allowed.\n" ;
1286     SetMessages( LinkStrError.str() ) ;
1287     cdebug << "fromNode->IsSwitchNode() && toNode->IsEndSwitchNode with different PortNames Error."
1288            << endl ;
1289     cdebug_out << "GraphBase::Graph::AddLink" << endl;
1290     return false ;
1291   }
1292 #endif
1293   else if ( fromNode->IsGOTONode() && fromPort->InPortsSize() ) {
1294     if ( !RemoveLink( fromNode->Name() , fromPort->PortName() ,
1295                       fromPort->ChangeInPorts(0)->NodeName() ,
1296                       fromPort->ChangeInPorts(0)->PortName() ) ) {
1297       cdebug << "RemoveLink(AddLink) fromNode->IsGOTONode Error." << endl ;
1298       cdebug_out << "GraphBase::Graph::AddLink" << endl;
1299       return false ;
1300     }
1301   }
1302   else if ( ( fromNode->IsDataFlowNode() || fromNode->IsDataStreamNode() ) &&
1303        ( toPort->IsDataConnected() || toPort->IsExternConnected() ) ) {
1304     fromPort->RemoveInPort( toPort ) ; //dbg
1305   }
1306   else if ( ( toNode->IsDataFlowNode() || toNode->IsDataStreamNode() ) &&
1307        ( fromPort->IsDataConnected() || fromPort->IsExternConnected() ) ) {
1308     fromPort->RemoveInPort() ; // There is only one
1309   }
1310
1311
1312 // JR 12.01.2005 : an OutPort of a SwitchNode connected to a Gate can be connected only to Gate
1313   if ( !toNode->IsDataFlowNode() && !toNode->IsDataStreamNode() &&
1314        fromNode->IsSwitchNode() && fromPort->IsSwitch() && !toPort->IsGate() ) {
1315     LinkStrError << "Link from SwitchNode Port linked to a Gate may be connected only to Gates.\n" ;
1316     SetMessages( LinkStrError.str() ) ;
1317     cdebug << "toPort->AddLink Error( fromPort->IsSwitch() && !toPort->IsGate())." << endl ;
1318     cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1319     return false ;
1320   }
1321 //JR 11.02.2005 : SwitchNode(Default) may be only linked to EndSwitchNode(Default)
1322 //                SwitchNode(Param) may be linked to EndSwitchNode(Param)
1323 //                SwitchNode(Param-UserDefault) may be linked to EndSwitchNode(Default)
1324   else if ( fromNode->IsSwitchNode() && toNode->IsEndSwitchNode() &&
1325             !( ( fromPort->IsGate() && toPort->IsGate() ) ||
1326                ( !fromPort->IsGate() ) ) ) {
1327 //               ( !fromPort->IsGate() && !toPort->IsGate() ) ) ) {
1328     LinkStrError << "Link from SwitchNode to EndSwitchNode : different kinds of ports not allowed.\n" ;
1329     SetMessages( LinkStrError.str() ) ;
1330     cdebug << "Link ERROR from SwitchNode to EndSwitchNode : different kinds of ports not allowed."
1331            << endl ;
1332     cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1333     return false ;
1334   }
1335 //JR 15.06.2005 : SwitchNode(Default) may be only linked to EndSwitchNode(Default)
1336   else if ( fromNode->IsSwitchNode() && fromPort->IsGate() &&
1337             !toNode->IsEndSwitchNode() ) {
1338     LinkStrError << "Link from SwitchNode(Default) is allowed only to EndSwitchNode(Default).\n" ;
1339     SetMessages( LinkStrError.str() ) ;
1340     cdebug << "SwitchNode(Default) may be only linked to EndSwitchNode(Default) AddLink Error."
1341            << endl ;
1342     cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1343     return false ;
1344   }
1345   else if ( toNode->IsEndSwitchNode() && !toPort->IsGate() ) {
1346 //    if ( !toPort->IsEndSwitch() || !fromPort->AddInPort( toPort ) ) {
1347     if ( !fromPort->AddInPort( toPort ) ) {
1348       cdebug << "toNode->IsEndSwitchNode() : !fromPort->AddInPort( toPort ) AddLink Error."
1349              << endl ;
1350       cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1351       return false ;
1352     }
1353     if ( !toPort->IsDataStream() ) {
1354       toPort->Kind( SUPERV::EndSwitchParameter ) ;
1355     }
1356   }
1357   else if ( !fromPort->AddInPort( toPort ) ) { // --> MapOfInports in the OutPort
1358     cdebug << "!fromPort->AddLink Error." << endl ;
1359     cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1360     return false ;
1361   }
1362
1363   if ( fromNode->IsGOTONode() && ( !fromPort->IsGate() || !toPort->IsGate() ||
1364        toNode->IsEndLoopNode() || toNode->IsEndSwitchNode() ) ) {
1365     cdebug << "toPort->AddLink Error( fromNode->IsGOTONode() && toNode->IsEndInLineNode() )." << endl ;
1366     cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1367     return false ;
1368   }
1369   else if ( !fromNode->IsSwitchNode() &&
1370             ( fromPort->IsParam() || fromPort->IsInLine() ) && toPort->IsGate() ) {
1371     LinkStrError << "Link from OutPort to a Gate is not allowed.\n" ;
1372     SetMessages( LinkStrError.str() ) ;
1373     cdebug << "toPort->AddLink Error( fromPort->IsParam() && toPort->IsGate())." << endl ;
1374     cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1375     return false ;
1376   }
1377   else if ( !toNode->IsEndSwitchNode() && !toNode->IsEndLoopNode() ) {
1378     if ( !toPort->AddOutPort( fromPort ) ) { // --> Unique OutPort of the InPort
1379       cdebug << "toPort->AddLink Error." << endl ;
1380       cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1381       return false ;
1382     }
1383   }
1384   else {
1385     toPort->AddOutPort( fromPort ) ;
1386   }
1387
1388   if ( ( fromNode->IsGOTONode() && toNode->IsOneOfInLineNodes() ) ||
1389        ( fromNode->IsEndLoopNode() && toNode->IsLoopNode() ) ) {
1390     cdebug << "AddLink fromPort->PortStatus( PortConnected ) "
1391            << "GOTONode/EndLoopNode-->InLineNode/LoopNode/SwitchNode "
1392            << fromNode->Name() << " " << fromPort->PortName()
1393            << " InLineNode/LoopNode_ConnectedInPortsNumber "
1394            << toNode->ConnectedInPortsNumber() << endl;
1395     if ( fromNode->IsGOTONode() ) {
1396       fromPort->Kind( SUPERV::GOTOParameter ) ;
1397     }
1398     fromPort->PortStatus( PortConnected ); // GOTO - Loop
1399   }
1400   else if ( fromNode->IsDataFlowNode() || fromNode->IsDataStreamNode() ) {
1401     cdebug << "AddLink IsDataFlow/StreamNode fromPort->PortStatus( DataConnected ) : "
1402            << fromNode->Name() << " " << fromPort->PortName() << endl ;
1403     fromPort->PortStatus( ExternConnected );
1404   }
1405   else if ( toNode->IsDataFlowNode() || toNode->IsDataStreamNode() ) {
1406     cdebug << "AddLink IsDataFlow/StreamNode fromPort->PortStatus( ExternConnected ) : "
1407            << fromNode->Name() << " " << fromPort->PortName() << endl ;
1408     fromPort->PortStatus( ExternConnected ) ;
1409   }
1410   else {
1411     cdebug << "AddLink fromPort->PortStatus( PortConnected ) & fromNode->toNode "
1412            << fromNode->Name() << " " << fromPort->PortName() << " "
1413            << fromPort->Kind() << " OldPortStatus " << fromPort->PortStatus() << " -> " << toNode->Name()
1414            << " " << " " << toPort->PortName() << " " << toPort->Kind() << endl;
1415     fromPort->PortStatus( PortConnected );
1416     if ( fromPort->IsDataStream() && toPort->IsDataStream() ) {
1417       fromNode->AddStreamLinkedNode( toNode ) ;
1418     }
1419     else {
1420       fromNode->AddLinkedNode( toNode ) ;
1421     }
1422   }
1423   if ( fromNode->IsSwitchNode() ) {
1424     if ( !fromPort->IsDataStream() ) {
1425 //JR 08.02.2005      if ( fromPort->IsInLine() && toPort->IsGate() && !toNode->IsEndSwitchNode() ) {
1426       if ( fromPort->IsInLine() && toPort->IsGate() ) {
1427         fromPort->Kind( SUPERV::SwitchParameter ) ;
1428       }
1429       else if ( !fromPort->IsGate() && !toPort->IsGate() ){
1430         fromPort->Kind( SUPERV::InLineParameter ) ;
1431       }
1432     }
1433     if ( fromPort->IsGate() && !toNode->IsEndSwitchNode() ) {
1434       GraphBase::InLineNode * anEndSwitchNode ;
1435       anEndSwitchNode = ((GraphBase::SwitchNode * ) fromNode)->CoupledNode() ;
1436       GraphBase::InPort * anInPort = anEndSwitchNode->GetChangeNodeInGate() ;
1437       GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1438       if ( anOutPort && !strcmp( fromNode->Name() , anOutPort->NodeName() ) &&
1439            !strcmp( fromPort->PortName() , anOutPort->PortName() ) &&
1440            anOutPort->IsGate() ) {
1441         if ( !RemoveLink( fromNode->Name() , anOutPort->PortName() ,
1442                           anEndSwitchNode->Name() ,
1443                           anInPort->PortName() ) ) {
1444           cdebug << "AddLink Error Removelink ( Switch , Default , EndSwitch , Default )"
1445                  << endl ;
1446           cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1447           return false ;
1448         }
1449       }
1450     }
1451   }
1452 //  cdebug << fromNode->ServiceName() << " " << toNode->ServiceName() << endl ;
1453   cdebug_out << "GraphBase::Graph::AddLink 1" << endl;
1454   return true ;
1455 }
1456
1457 bool GraphBase::Graph::RemoveLink( const char* FromNodeName ,
1458                                    const char* FromServiceParameterName ,
1459                                    const char* ToNodeName ,
1460                                    const char* ToServiceParameterName ) {
1461   cdebug_in << "GraphBase::Graph::RemoveLink from " << FromNodeName << "(" << FromServiceParameterName << ")"
1462             << " to " << ToNodeName << "(" << ToServiceParameterName << ")" << endl;
1463   bool RetVal = false ;
1464   GraphBase::ComputingNode * toNode = GetChangeGraphNode( ToNodeName ) ;
1465   if ( toNode ) {
1466     GraphBase::InPort * anInPort = toNode->GetChangeInPort( ToServiceParameterName ) ;
1467     if ( anInPort && ( anInPort->IsPortConnected() ||
1468                        anInPort->IsDataConnected() ||
1469                        anInPort->IsExternConnected() ) ) {
1470 // JR 13.01.2005 : DeBug : if it is a link to an EndSwitchNode. The OutPort may be an other one !!!
1471       GraphBase::ComputingNode * fromNode = GetChangeGraphNode( FromNodeName ) ;
1472       GraphBase::OutPort * anOutPort = NULL ;
1473       if ( toNode->IsEndSwitchNode() ) {
1474         anOutPort = fromNode->GetChangeOutPort( FromServiceParameterName ) ;
1475         RetVal = anOutPort->RemoveInPort( anInPort ) ;
1476       }
1477       else {
1478         anOutPort = anInPort->GetOutPort() ;
1479         RetVal = anOutPort->RemoveInPort( anInPort ) ;
1480       }
1481 //      anInPort->RemoveOutPort() ; // Already done in RemoveInPort
1482 //      const char * FromNodeName = anOutPort->NodeName() ;
1483       if ( RetVal ) {
1484         if ( fromNode ) {
1485           if ( anInPort->IsDataStream() ) {
1486             fromNode->RemoveStreamLinkedNode( toNode ) ;
1487           }
1488           else {
1489             fromNode->RemoveLinkedNode( toNode ) ;
1490           }
1491         }
1492 //JR PAL7990 : a SwitchPort is an OutPort of a SwitchNode connected to a InGate Port
1493 //Debug : change the kind only if there is no other InGate connected to the OutPort
1494         if ( fromNode->IsSwitchNode() && !anOutPort->IsGate() && anOutPort->InPortsSize() == 0 ) {
1495           if ( !toNode->IsEndSwitchNode() ) {
1496             anOutPort->Kind( SUPERV::InLineParameter ) ;
1497           }
1498           else if ( !anInPort->IsGate() ) {
1499             anOutPort->Kind( SUPERV::InLineParameter ) ;
1500           }
1501         }
1502 // JR 13.01.2005 : DeBug : if it is a link to an EndSwitchNode. The InPort may be multiple linked !!!
1503         if ( toNode->IsEndSwitchNode() ) {
1504           int i ;
1505           int done = false ;
1506           for ( i = 0 ; i < toNode->LinkedFromNodesSize() ; i++ ) {
1507             GraphBase::StreamNode * fromNode = toNode->LinkedFromNodes( i ) ;
1508             int j ;
1509             for ( j = 0 ; j < fromNode->GetNodeOutPortsSize() ; j++ ) {
1510               GraphBase::OutPort * fromOutPort = fromNode->GetChangeNodeOutPort( j ) ;
1511               int k ;
1512               for ( k = 0 ; k < fromOutPort->InPortsSize() ; k++ ) {
1513                 if ( strcmp( toNode->Name() , fromOutPort->InPorts( k )->NodeName() ) == 0 ) {
1514                   if ( strcmp( anInPort->PortName() , fromOutPort->InPorts( k )->PortName() ) == 0 ) {
1515 // Restore an OutPort in the InPort
1516                     anInPort->ChangeOutPort( fromOutPort ) ;
1517                     cdebug << "Graph::RemoveLink reestablish " << fromOutPort->NodeName() << "( "
1518                            << fromOutPort->PortName() << " ) in the InPort of EndSwitch : "
1519                            << toNode->Name() << "( " << anInPort->PortName() << " )"
1520                            << anInPort->Kind() << " " << anInPort->PortStatus() << endl;
1521                     done = true ;
1522                     break ;
1523                   }
1524                 }
1525               }
1526               if ( done ) {
1527                 break ;
1528               }
1529             }
1530             if ( done ) {
1531               break ;
1532             }
1533           }
1534         }
1535       }
1536     }
1537   }
1538   cdebug_out << "GraphBase::Graph::RemoveLink " << RetVal << endl;
1539   return RetVal ;
1540 }
1541
1542 bool GraphBase::Graph::GetLink(const char* ToNodeName ,
1543                                const char* ToServiceParameterName ,
1544                                char** FromNodeName ,
1545                                char** FromServiceParameterName ) {
1546 //  cdebug_in << "GraphBase::Graph::GetLink " << ToNodeName << "("
1547 //            << ToServiceParameterName << ")" << endl;
1548   bool RetVal = false ;
1549   GraphBase::ComputingNode * toNode = GetChangeGraphNode( ToNodeName ) ;
1550   if ( toNode ) {
1551     GraphBase::InPort * anInPort = toNode->GetChangeInPort( ToServiceParameterName ) ;
1552     if ( anInPort && !anInPort->IsNotConnected() ) {
1553       GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1554 //JR 17.02.2005 Memory Leak      *FromNodeName = my_strdup( anOutPort->NodeName() ) ;
1555       *FromNodeName = (char * ) anOutPort->NodeName() ;
1556 //JR 17.02.2005 Memory Leak      *FromServiceParameterName = my_strdup( anOutPort->PortName() ) ;
1557       *FromServiceParameterName = (char * ) anOutPort->PortName() ;
1558       RetVal = true ;
1559     }
1560     else {
1561       cdebug << "GraphBase::Graph::GetLink ERROR no InPort or NotConnected " << ToNodeName
1562              << " " << ToServiceParameterName << " " << RetVal << endl;
1563     }
1564   }
1565   else {
1566     cdebug << "GraphBase::Graph::GetLink ERROR no Node " << ToNodeName << " " << RetVal
1567            << endl;
1568   }
1569 //  cdebug_out << "GraphBase::Graph::GetLink " << RetVal << endl;
1570   return RetVal ;
1571 }
1572
1573 bool GraphBase::Graph::AddInputData( const char* ToNodeName ,
1574                                      const char* ToServiceParameterName ,
1575                                      const CORBA::Any aValue ) {
1576   bool RetVal = false ;
1577   cdebug_in << "GraphBase::Graph::AddInputData(" << ToNodeName << ","
1578             << ToServiceParameterName << " , Any " ;
1579   bool isUnknown = false;
1580   switch (aValue.type()->kind()) {
1581     case CORBA::tk_string:
1582       char * t;
1583       aValue >>= t;
1584       cdebug << t << " (string) " ;
1585       if ( !strcmp( t, "Unknown CORBA::Any Type" ) ) 
1586         // mkr : IPAL8054 : in this case port has no input value
1587         isUnknown = true;
1588       break;
1589     case CORBA::tk_double:
1590       double d;
1591       aValue >>= d;
1592       cdebug << d << " (double) " ;
1593       break;
1594     case CORBA::tk_long:
1595       long l;
1596       aValue >>= l;
1597       cdebug << l << " (long) " ;
1598       break;
1599     case CORBA::tk_objref:
1600       cdebug << "(object reference) " ;
1601       break;
1602     default:
1603       cdebug << "(other(tk_string(" << CORBA::tk_string << "),tk_double(" << CORBA::tk_double << "),tk_long("
1604              << CORBA::tk_long << "),tk_objref)(" << CORBA::tk_objref << ")) ERROR : " << aValue.type()->kind() ;
1605       break;
1606     }
1607   cdebug << " ) in Graph " << Name() << endl;
1608  
1609   GraphBase::ComputingNode *toNode ;
1610   GraphBase::InPort *toPort ;
1611   char *aNodeName ;
1612   char *aPortName ;
1613   NodePort( ToNodeName , ToServiceParameterName , &aNodeName , &aPortName ) ;
1614   toNode = GetChangeGraphNode( aNodeName ) ;
1615   cdebug << "in Graph " << Name() << " aNodeName '" << aNodeName << "' aPortName '" << aPortName
1616          << "'" << endl;
1617   if ( toNode ) {
1618     toPort = toNode->GetChangeInPort( aPortName ) ;
1619     if ( toPort && !toPort->IsDataConnected() && toPort->GetOutPort() ) {
1620       toPort->RemoveOutPort() ;
1621     }
1622   }
1623   else {
1624     toPort = NULL ;
1625   }
1626
1627   int i ;
1628   cdebug << endl << "Graph::AddInputData ListOfInOutPorts of the Graph : " << endl ;
1629   for ( i = 0 ; i < GetNodeOutDataNodePortsSize() ; i++ ) {
1630     cdebug << "Graph::AddInputData In" << i << " " << *GetNodeOutDataNodePort(i) << endl ;
1631   }
1632   for ( i = 0 ; i < GetNodeInDataNodePortsSize() ; i++ ) {
1633     cdebug << "Graph::AddInputData Out" << i << " " << *GetNodeInDataNodePort(i) << endl ;
1634   }
1635
1636   if ( toNode && toPort ) {
1637     GraphBase::OutPort *fromDataNodePort = NULL ;
1638     fromDataNodePort = GraphBase::DataNode::GetChangeInDataNodePort( toPort->NodePortName() ) ;
1639     if ( fromDataNodePort && fromDataNodePort->GetInPort( toPort ) ) {
1640       fromDataNodePort->RemoveInPort( toPort ) ;
1641     }
1642     cdebug << "Try AddLink " << toPort->NodePortName() << " : " << Name() << "( "
1643            << fromDataNodePort->PortName() << " ) -->" << toNode->Name() << "( "
1644            << toPort->PortName() << " )" << endl ;
1645     RetVal = AddLink( (GraphBase::ComputingNode * ) this , fromDataNodePort ,
1646                       toNode , toPort ) ;
1647     if ( RetVal ) {
1648       fromDataNodePort->SetValue( aValue ) ;
1649       if ( !isUnknown ) // mkr : IPAL8054 : to avoid setting "strange" value to a port
1650         fromDataNodePort->PortStatus( DataConnected ) ;
1651     }
1652   }
1653   else {
1654     cdebug << "ERROR Node and/or Port not found : " << aNodeName << " " << aPortName << endl ;
1655   }
1656   delete aNodeName ;
1657   delete aPortName ;
1658
1659   cdebug_out << "GraphBase::Graph::AddInputData " << RetVal << endl;
1660   return RetVal ;
1661 }
1662
1663 // Used in the Executor in order to change an Input Value and ReRun
1664 bool GraphBase::Graph::ChangeInputData( const char * ToNodeName ,
1665                                         const char * ToServiceParameterName ,
1666                                         const CORBA::Any aValue ) {
1667   bool RetVal = false ;
1668   cdebug_in << "GraphBase::Graph::ChangeInputData( '" << ToNodeName << "' , '"
1669             << ToServiceParameterName << "' , Any " ;
1670   switch (aValue.type()->kind()) {
1671     case CORBA::tk_string:
1672       char * t;
1673       aValue >>= t;
1674       cdebug << t << " (string) " ;
1675       break;
1676     case CORBA::tk_double:
1677       double d;
1678       aValue >>= d;
1679       cdebug << d << " (double) " ;
1680       break;
1681     case CORBA::tk_long:
1682       long l;
1683       aValue >>= l;
1684       cdebug << l << " (long) " ;
1685       break;
1686     case CORBA::tk_objref:
1687       cdebug << "(object reference) " ;
1688       break;
1689     default:
1690       cdebug << "(other(tk_string,tk_double,tk_long,tk_objref)) ERROR";
1691       break;
1692     }
1693   cdebug << " ) in Graph " << Name() << endl;
1694
1695   GraphBase::ComputingNode * toNode ;
1696   GraphBase::InPort * toPort = NULL ;
1697   char * aNodeName ;
1698   char * aPortName ;
1699   NodePort( ToNodeName , ToServiceParameterName , &aNodeName , &aPortName ) ;
1700   toNode = GetChangeGraphNode( aNodeName ) ;
1701   cdebug << "in Graph " << Name() << " aNodeName " << aNodeName << " aPortName " << aPortName << endl;
1702   if ( toNode ) {
1703     toPort = toNode->GetChangeInPort( aPortName ) ;
1704     if ( toPort && toPort->IsDataConnected() ) {
1705       GraphBase::OutPort * fromPort = toPort->GetOutPort();
1706       if ( fromPort ) {
1707         RetVal = true ;
1708         fromPort->SetValue( aValue ) ;
1709         fromPort->PortStatus( DataConnected ) ;
1710         toPort->PortState( SUPERV::ReadyState ) ;
1711       }
1712       else {
1713         cdebug << "ERROR ChangeInputData fromPort not found" << endl ;
1714       }
1715     }
1716     else {
1717       cdebug << "ERROR ChangeInputData toPort not found" << endl ;
1718     }
1719   }
1720   else {
1721     cdebug << "ERROR ChangeInputData Node not found : " << ToNodeName << endl ;
1722   }
1723
1724   cdebug_out << "GraphBase::Graph::ChangeInputData" << endl;
1725   return RetVal ;
1726 }
1727
1728 #if 0
1729 // To restore InputData in CreateService
1730 bool GraphBase::Graph::AddInputData( const char* ToNodeName ,
1731                                      const char* ToServiceParameterName ,
1732                                      const CORBA::Any ** aValue ) {
1733   bool RetVal = false ;
1734   cdebug_in << "GraphBase::Graph::AddInputData( " << ToNodeName << " , "
1735             << ToServiceParameterName << ", **Any " ;
1736   const CORBA::Any theValue = **aValue ;
1737   switch (theValue.type()->kind()) {
1738     case CORBA::tk_string:
1739       char * t;
1740       theValue >>= t;
1741       cdebug << t << " (string) " ;
1742       break;
1743     case CORBA::tk_double:
1744       double d;
1745       theValue >>= d;
1746       cdebug << d << " (double) " ;
1747       break;
1748     case CORBA::tk_long:
1749       long l;
1750       theValue >>= l;
1751       cdebug << l << " (long) " ;
1752       break;
1753     case CORBA::tk_objref:
1754       cdebug << "(object reference) " ;
1755       break;
1756     default:
1757       cdebug << "(other(tk_string,tk_double,tk_long,tk_objref)) ERROR";
1758       break;
1759     }
1760   cdebug << ") of Graph " << Name() << endl;
1761
1762   GraphBase::ComputingNode *toNode = GetChangeGraphNode( ToNodeName ) ;
1763
1764   if ( toNode ) {
1765     GraphBase::InPort *toPort = NULL ;
1766     GraphBase::OutPort *fromDataNodePort = NULL ;
1767     toPort = toNode->GetChangeInPort( ToServiceParameterName ) ;
1768     fromDataNodePort = GraphBase::DataNode::GetChangeInDataNodePort( toPort->NodePortName() ) ;
1769     cdebug << "Try AddLink " << Name() << "( " << fromDataNodePort << " ) -->"
1770            << toNode->Name() << "( " << toPort->PortName() << " )" << endl ;
1771     RetVal = AddLink( (GraphBase::ComputingNode * ) this , fromDataNodePort ,
1772                       toNode , toPort ) ;
1773     if ( RetVal ) {
1774       fromDataNodePort->Value( aValue ) ;
1775       fromDataNodePort->PortStatus( DataConnected ) ;
1776     }
1777   }
1778   else {
1779     cdebug << "ERROR Node not found " << ToNodeName << " ERROR. Known nodes :" << endl ;
1780     map< string , int >::iterator aMapOfGraphNodesIterator ;
1781     int i = 0 ;
1782     for ( aMapOfGraphNodesIterator = _MapOfGraphNodes.begin() ;
1783           aMapOfGraphNodesIterator != _MapOfGraphNodes.end() ; aMapOfGraphNodesIterator++ ) {
1784       cdebug << "MapOfGraphNodes " << i++ << " " << aMapOfGraphNodesIterator->first << " --> "
1785              << aMapOfGraphNodesIterator->second << endl ;
1786     }
1787   }
1788
1789   cdebug_out << "GraphBase::Graph::AddInputData " << RetVal << endl;
1790   return RetVal ;
1791 }
1792 #endif
1793
1794 bool GraphBase::Graph::AddOutputData( const char* FromNodeName ,
1795                                       const char* FromServiceParameterName ,
1796                                       const CORBA::Any aValue ) {
1797   bool RetVal = true ;
1798   cdebug_in << "GraphBase::Graph::AddOutputData(" << FromNodeName << ","
1799             << FromServiceParameterName << ")" << endl;
1800   GraphBase::ComputingNode *fromNode = GetChangeGraphNode( FromNodeName ) ;
1801
1802   GraphBase::OutPort *anOutPort = NULL ;
1803
1804   if ( fromNode ) {
1805     anOutPort = fromNode->GetChangeOutPort( FromServiceParameterName ) ;
1806 //    toDataNodePort = GraphBase::DataNode::GetChangeOutDataNodePort( fromPort->NodePortName() ) ;
1807 //    RetVal = AddLink( fromNode , fromPort ,
1808 //                      (GraphBase::ComputingNode * ) this , toDataNodePort ) ;
1809     anOutPort->SetValue( aValue ) ;
1810     anOutPort->PortState(  SUPERV::ReadyState ) ;
1811     anOutPort->PortDone( true ) ;
1812     cdebug << *anOutPort ;
1813 #ifdef _DEBUG_
1814     anOutPort->StringValue( *_fdebug ) ;
1815 #endif
1816     cdebug << endl ;
1817   }
1818   else {
1819     cdebug << "ERROR Node not found" << endl ;
1820     RetVal = false ;
1821   }
1822   cdebug_out << "GraphBase::Graph::AddOutputData " << RetVal << endl;
1823   return RetVal ;
1824 }
1825
1826 //JR This is used by StreamGraphs to list "CODES" and after that there is instances
1827 // for each Code (Nodes).
1828 map< string , GraphBase::Service * > GraphBase::Graph::MapOfServiceNames() {
1829                                            return _MapOfServiceNames ; }
1830
1831 GraphBase::Service * GraphBase::Graph::GetServiceOfMap( char * name ) {
1832   return _MapOfServiceNames[ name ] ;
1833 }
1834
1835 bool GraphBase::Graph::SetServiceOfMap( GraphBase::Service * aService ) {
1836   GraphBase::Service * theService = _MapOfServiceNames[ aService->ServiceName() ] ;
1837   if ( theService ) {
1838     cdebug << "SetServiceOfMap of " << aService->ServiceName()
1839            << " already in MapOfServiceNames : erase" << endl ;
1840     _MapOfServiceNames.erase( aService->ServiceName() ) ;
1841   }
1842   _MapOfServiceNames[ (char * ) aService->ServiceName() ] = aService ;
1843   cdebug << "SetServiceOfMap of " << aService->ServiceName() << " done" << endl ;
1844   return true ;
1845 }
1846
1847 //PAL7961
1848 //JR Debug 25.03.2005 : with multiple instances et delete of instances, it was wrong
1849 //Bug created with the developpement of StreamGraphs
1850 int GraphBase::Graph::GetNewServiceInstanceNumber( char * aServiceName ) {
1851   int InstanceNumber = _MapOfServiceInstanceNumber[ aServiceName ] + 1 ;
1852   _MapOfServiceInstanceNumber[ aServiceName ] = InstanceNumber ;
1853   return InstanceNumber ;
1854 }
1855
1856 void GraphBase::Graph::SetGraphPorts() {
1857   cdebug_in << "GraphBase::Graph::SetGraphPorts fill ports of Graph" << endl;
1858   int i ;
1859   for ( i = 0 ; i < GetNodeInDataNodePortsSize() ; i++ ) {
1860     GraphBase::OutPort * anOutPort = GetChangeNodeInDataNodePort( i ) ;
1861     cdebug << "SetGraphPorts Out" << i << " " << anOutPort->PortName() << " " << anOutPort->PortType()
1862            << " " << anOutPort->Kind() << " " << anOutPort->PortStatus() << " " << anOutPort->PortState() << endl ;
1863     if ( !anOutPort->IsGate() ) {
1864       anOutPort->PortStatus( ExternConnected ) ;
1865     }
1866   }
1867   for ( i = 0 ; i < GetNodeOutDataNodePortsSize() ; i++ ) {
1868     GraphBase::InPort * anInPort = GetChangeNodeOutDataNodePort( i ) ;
1869     cdebug << "SetGraphPorts In" << i << " " << anInPort->PortName() << " " << anInPort->PortType()
1870            << " " << anInPort->Kind() << " " << anInPort->PortStatus() << " " << anInPort->PortState() << endl ;
1871     if ( !anInPort->IsGate() ) {
1872       GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1873       anOutPort->PortStatus( ExternConnected ) ;
1874     }
1875   }
1876   cdebug_out << "GraphBase::Graph::SetGraphPorts" << endl;
1877 }
1878
1879 string GraphBase::Graph::Messages() {
1880 //  cdebug_in << "Graph::Messages" << endl ;
1881 //  cdebug_out << "Graph::Messages" << endl ;
1882   return ( CORBA::string_dup( _Messages.c_str() ) ) ;
1883 }
1884
1885 void GraphBase::Graph::ReSetMessages() {
1886   cdebug << "Graph::ReSetMessages" << endl ;
1887   _Messages = string( "" ) ;
1888 }
1889
1890 void GraphBase::Graph::SetMessages( string anErrorMessage ) {
1891   cdebug_in << "Graph::SetMessages" << endl ;
1892   _Messages = _Messages + anErrorMessage + string( "\n" ) ;
1893   cdebug_out << "Graph::SetMessages :" << endl << _Messages << endl ;
1894 }
1895
1896 bool GraphBase::Graph::CreateService() {
1897   cdebug_in << "GraphBase::Graph::CreateService " << Name() << " GraphMacroLevel : " << GraphMacroLevel() << endl;
1898   bool RetVal = true ;
1899   SALOME_ModuleCatalog::Service aService ;
1900   int i , j ;
1901   GraphBase::ComputingNode * aToNode ;
1902   int dostore ;
1903   int innbr = 0 ;
1904   int instreamnbr = 0 ;
1905   int outnbr = 0 ;
1906   int outstreamnbr = 0 ;
1907   vector< SUPERV::KindOfPort > InPortsKind ;
1908   vector< SALOME_ModuleCatalog::DataStreamDependency > InDataStreamDependency ;
1909   vector< SUPERV::KindOfSchema > InKindOfSchema ;
1910   vector< SUPERV::KindOfInterpolation > InKindOfInterpolation ;
1911   vector< SUPERV::KindOfExtrapolation > InKindOfExtrapolation ;
1912   vector< SUPERV::KindOfPort > OutPortsKind ;
1913   vector< SALOME_ModuleCatalog::DataStreamDependency > OutDataStreamDependency ;
1914   vector< long > OutNumberOfValues ;
1915 //  if ( GraphMacroLevel() == 0 ) {
1916     for ( dostore = 0 ; dostore <= 2 ; dostore++ ) {
1917       if ( dostore == 1 ) {
1918 //JR 17.02.2005 Memory Leak        aService.ServiceName = Name() ;
1919         aService.ServiceName = my_strdup( Name() ) ;
1920         aService.ServiceinParameter.length( 0 ) ;
1921         aService.ServiceinParameter.length( innbr ) ;
1922         aService.ServiceoutParameter.length( 0 ) ;
1923         aService.ServiceoutParameter.length( outnbr ) ;
1924         InPortsKind.resize( innbr ) ;
1925         InDataStreamDependency.resize( innbr ) ;
1926         InKindOfSchema.resize( innbr ) ;
1927         InKindOfInterpolation.resize( innbr ) ;
1928         InKindOfExtrapolation.resize( innbr ) ;
1929         OutPortsKind.resize( outnbr ) ;
1930         OutDataStreamDependency.resize( outnbr ) ;
1931         OutNumberOfValues.resize( outnbr ) ;
1932       }
1933       else if ( dostore == 2 ) {
1934 //JR Creation of the Service (and of the Ports) with GraphBase::DataNode::DataService :
1935         cdebug << "GraphBase::Graph::CreateService ->DataService innbr " << innbr
1936                << " instreamnbr " << instreamnbr << " outnbr " << outnbr
1937                << " outstreamnbr " << outstreamnbr << endl ;
1938         DataService( _Orb , aService , Graph_prof_debug() , Graph_fdebug() ) ;
1939         aService.ServiceinParameter.length( innbr + instreamnbr ) ;
1940         aService.ServiceoutParameter.length( outnbr + outstreamnbr ) ;
1941         InPortsKind.resize( innbr + instreamnbr ) ;
1942         InDataStreamDependency.resize( innbr + instreamnbr ) ;
1943         InKindOfSchema.resize( innbr + instreamnbr ) ;
1944         InKindOfInterpolation.resize( innbr + instreamnbr ) ;
1945         InKindOfExtrapolation.resize( innbr + instreamnbr ) ;
1946         OutPortsKind.resize( outnbr + outstreamnbr ) ;
1947         OutDataStreamDependency.resize( outnbr + outstreamnbr ) ;
1948         OutNumberOfValues.resize( outnbr + outstreamnbr ) ;
1949       }
1950       if ( dostore == 0 ) {
1951         innbr = 0 ;
1952         instreamnbr = 0 ;
1953         outnbr = 0 ;
1954         outstreamnbr = 0 ;
1955       }
1956       if ( dostore == 1 ) {
1957         innbr = 0 ;
1958         outnbr = 0 ;
1959       }
1960       for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1961         aToNode = GraphNodes( i ) ;
1962         for ( j = 0 ; j < aToNode->GetNodeInPortsSize() ; j++ ) {
1963           GraphBase::InPort *anInPort = aToNode->GetChangeNodeInPort(j) ;
1964           bool isfromcouplednode = false ;
1965           if ( !anInPort->IsNotConnected() ) {
1966             const char * aFromNodeName = anInPort->GetOutPort()->NodeName() ;
1967             GraphBase::ComputingNode * aFromNode = GetChangeGraphNode( aFromNodeName ) ;
1968             cdebug << "GraphBase::Graph::CreateService aFromNodeName " << aFromNodeName << " aToNode "
1969                    << aToNode->Name() << " InPort" << j << " " << anInPort->PortName() << endl ;
1970             if ( aFromNode && aFromNode->IsEndLoopNode() &&
1971                  ((GraphBase::EndOfLoopNode * ) aFromNode)->CoupledNode() == aToNode ) {
1972               isfromcouplednode = true ;
1973             }
1974           }
1975           if ( !anInPort->IsGate() && !anInPort->IsLoop() &&
1976                ( !anInPort->IsPortConnected() ||
1977 //                 ( anInPort->IsPortConnected() && isfromcouplednode ) ) ) {
1978 //JR PAL8914 : InPorts of EndLoopNodes may not be in the Service of the Graph
1979                  ( anInPort->IsPortConnected() && isfromcouplednode ) ) &&
1980                !aToNode->IsEndLoopNode() ) {
1981             if ( dostore == 0 ) {
1982               cdebug << "CreateService " << aToNode->Name() << " Input port "
1983                      << anInPort->PortName() << " " << anInPort->Kind() << " " << anInPort->PortStatus() ;
1984               if ( anInPort->GetOutPort() ) {
1985                 cdebug << "DataConnected from " <<  *(anInPort->GetOutPort() ) ;
1986               }
1987               cdebug << endl ;
1988               if ( anInPort->IsDataStream() ) {
1989                 instreamnbr += 1 ;
1990               }
1991               else {
1992                 innbr += 1 ;
1993               }
1994             }
1995             else if ( ( dostore == 1 && !anInPort->IsDataStream() ) ||
1996                       ( dostore == 2 && anInPort->IsDataStream() ) ) {
1997               aService.ServiceinParameter[innbr].Parametertype = CORBA::string_dup( anInPort->PortType() ) ;
1998               aService.ServiceinParameter[innbr].Parametername = CORBA::string_dup( anInPort->NodePortName() ) ;
1999               InPortsKind[ innbr ] = anInPort->Kind() ;
2000               InDataStreamDependency[ innbr ] = anInPort->Dependency() ;
2001               if ( dostore == 2 && anInPort->IsDataStream() ) {
2002                 ((GraphBase::InDataStreamPort * ) anInPort)->Params( InKindOfSchema[ innbr ] ,
2003                                                                      InKindOfInterpolation[ innbr ] ,
2004                                                                      InKindOfExtrapolation[ innbr ] ) ;
2005               }
2006               cdebug << "In" << innbr << " " << aService.ServiceinParameter[ innbr ].Parametername << " "
2007                      << anInPort->Kind() << " " << anInPort->PortStatus() << endl ;
2008               innbr += 1 ;
2009             }
2010           }
2011           else if ( dostore == 0 ) {
2012             cdebug << "CreateService " << aToNode->Name() << " Input port " << anInPort->PortName()
2013                    << " " << anInPort->PortStatus() ;
2014             if ( anInPort->IsPortConnected() ) {
2015               cdebug << " is connected " ;
2016             }
2017             else {
2018               cdebug << " is NOT connected " ;
2019             }
2020             if ( anInPort->IsGate() ) {
2021               cdebug << " IsGate " ;
2022             }
2023             if ( anInPort->GetOutPort() ) {
2024               cdebug << "DataConnected from " <<  *(anInPort->GetOutPort()) ;
2025             }
2026             else {
2027               cdebug << "NOT DataConnected" ;
2028             }
2029             cdebug << endl ;
2030           }
2031         }
2032         GraphBase::ComputingNode * aFromNode = aToNode ;
2033         for ( j = 0 ; j < aFromNode->GetNodeOutPortsSize() ; j++ ) {
2034           GraphBase::OutPort *anOutPort = aFromNode->GetChangeNodeOutPort(j) ;
2035 //          cdebug << "CreateService Node " << aFromNode->Name() << ". Output port[" << j << "] ";
2036 //          if ( anOutPort ) {
2037 //            cdebug << anOutPort->PortName() << " " << anOutPort->ServicesParameterType() << endl ;
2038 //        }
2039 //          else {
2040 //            cdebug << " NULL" << endl ;
2041 //        }
2042           if ( !aFromNode->IsGOTONode() ) {
2043             if ( !anOutPort->IsGate() && ( anOutPort->IsNotConnected() || anOutPort->IsDataConnected()  ||
2044 //JR PAL8914 : OutPorts of LoopNodes may not be in the Service of the Graph
2045 //                                           anOutPort->IsExternConnected() ) {
2046                                            anOutPort->IsExternConnected() ) &&
2047                  !aFromNode->IsLoopNode() ) {
2048               if ( dostore == 0 ) {
2049 //                cdebug << "CreateService " << aFromNode->Name() << " Output port "
2050 //                       << anOutPort->PortName() << " " << anOutPort->PortStatus() << endl ;
2051                 if ( anOutPort->IsDataStream() ) {
2052                   outstreamnbr += 1 ;
2053                 }
2054                 else {
2055                   outnbr += 1 ;
2056                 }
2057               }
2058               else if ( ( dostore == 1 && !anOutPort->IsDataStream() ) ||
2059                         ( dostore == 2 && anOutPort->IsDataStream() ) ) {
2060                 aService.ServiceoutParameter[outnbr].Parametertype = CORBA::string_dup( anOutPort->PortType() ) ;
2061                 aService.ServiceoutParameter[outnbr].Parametername = CORBA::string_dup( anOutPort->NodePortName() ) ;
2062                 OutPortsKind[ outnbr ] = anOutPort->Kind() ;
2063                 OutDataStreamDependency[ outnbr ] = anOutPort->Dependency() ;
2064                 if ( dostore == 2 && anOutPort->IsDataStream() ) {
2065                   OutNumberOfValues[ outnbr ] = ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues() ;
2066                 }
2067 //                cdebug << "Out" << outnbr << " " << aService.ServiceoutParameter[ outnbr ].Parametername << " "
2068 //                       << anOutPort->Kind() << " " << anOutPort->PortStatus() << endl ;
2069                 outnbr += 1 ;
2070               }
2071             }
2072           }
2073         }
2074       }
2075     }
2076 //  }
2077
2078 #if 1
2079   cdebug << "DataFlowNode ServiceName " << aService.ServiceName << " InPorts " << innbr
2080          << " OutPorts " << outnbr << endl ;
2081   for ( i = 0 ; i < innbr ; i++ ) {
2082     cdebug << "aService.ServiceinParameter[" << i << "].Parametertype "
2083          << aService.ServiceinParameter[i].Parametertype << " Parametername "
2084          << aService.ServiceinParameter[i].Parametername << " " << InPortsKind[ i ] << endl ;
2085     if ( InPortsKind[ i ] != SUPERV::DataStreamParameter ) {
2086       cdebug << "NodeInPort[" << i << "] " << *GetChangeNodeInPort( i ) << endl ;
2087     }
2088   }
2089   for ( i = 0 ; i < outnbr ; i++ ) {
2090     cdebug << "aService.ServiceoutParameter[" << i << "].Parametertype "
2091          << aService.ServiceoutParameter[i].Parametertype << " Parametername "
2092          << aService.ServiceoutParameter[i].Parametername << " " << OutPortsKind[ i ] << endl ;
2093     if ( OutPortsKind[ i ] != SUPERV::DataStreamParameter ) {
2094       cdebug << "NodeOutPort[" << i << "] " << *GetChangeNodeOutPort( i ) << endl ;
2095     }
2096   }
2097 #endif
2098
2099 //  DataService( _Orb , aService , InPortsKind , OutPortsKind , Graph_prof_debug() , Graph_fdebug() ) ;
2100   for ( i = 0 ; i < innbr ; i++ ) {
2101     if ( InPortsKind[ i ] == SUPERV::DataStreamParameter ) {
2102       GraphBase::InDataStreamPort * anInPort = AddInDataStreamPort( aService.ServiceinParameter[ i ].Parametername ,
2103                                                                     StringToDataStreamType( aService.ServiceinParameter[ i ].Parametertype ) ,
2104                                                                     InDataStreamDependency[ i ] ,
2105                                                                     SUPERV::DataStreamParameter ) ;
2106       anInPort->SetParams( InKindOfSchema[ i ] ,
2107                            InKindOfInterpolation[ i ] ,
2108                            InKindOfExtrapolation[ i ] ) ;
2109 // NOT A BUG : AddOutPort for an inport (Reversed service)
2110       anInPort = (GraphBase::InDataStreamPort * ) _DataFlowDataPorts->AddOutPort(
2111                                                            _Orb , NamePtr() ,
2112                                                            Kind() ,
2113                                                            aService.ServiceinParameter[ i ].Parametername ,
2114                                                            aService.ServiceinParameter[ i ].Parametertype ,
2115                                                            SUPERV::DataStreamParameter ,
2116                                                            - 1 ,
2117                                                            _Graph_prof_debug , _Graph_fdebug ) ;
2118       anInPort->Dependency( InDataStreamDependency[ i ] ) ;
2119 // Attention : revoir les reversed DataStreamPorts
2120 //      anInPort->SetParams( InKindOfSchema[ i ] ,
2121 //                           InKindOfInterpolation[ i ] ,
2122 //                           InKindOfExtrapolation[ i ] ) ;
2123       cdebug << "InStreamPort " << GetChangeNodeInPort( i )->PortName() << " " << GetChangeNodeInPort( i )->Kind() << endl ;
2124       cdebug << "ReversedInStreamPort " << _DataFlowDataPorts->GetChangeNodeOutPort( i )->PortName() << " " << _DataFlowDataPorts->GetChangeNodeOutPort( i )->Kind()
2125              << endl ;
2126     }
2127     else {
2128       GetChangeNodeInPort( i )->Kind( InPortsKind[ i ] ) ;
2129       _DataFlowDataPorts->GetChangeNodeOutPort( i )->Kind( InPortsKind[ i ] ) ;
2130       GetChangeNodeInPort( i )->Dependency( InDataStreamDependency[ i ] ) ;
2131       _DataFlowDataPorts->GetChangeNodeOutPort( i )->Dependency( InDataStreamDependency[ i ] ) ;
2132       cdebug << "InPort " << GetChangeNodeInPort( i )->PortName() << " "
2133              << GetChangeNodeInPort( i )->Kind() << " " << GetChangeNodeInPort( i )->PortStatus()
2134              << endl ;
2135       cdebug << "ReversedInPort " << _DataFlowDataPorts->GetChangeNodeOutPort( i )->PortName() << " "
2136              << _DataFlowDataPorts->GetChangeNodeOutPort( i )->Kind() << " "
2137              << _DataFlowDataPorts->GetChangeNodeOutPort( i )->PortStatus()
2138              << endl ;
2139     }
2140   }
2141   for ( i = 0 ; i < outnbr ; i++ ) {
2142     if ( OutPortsKind[ i ] == SUPERV::DataStreamParameter ) {
2143       GraphBase::OutDataStreamPort * anOutPort = AddOutDataStreamPort( aService.ServiceoutParameter[ i ].Parametername ,
2144                                                                        StringToDataStreamType( aService.ServiceoutParameter[ i ].Parametertype ) ,
2145                                                                        OutDataStreamDependency[ i ] ,
2146                                                                        SUPERV::DataStreamParameter ) ;
2147       anOutPort->NumberOfValues( OutNumberOfValues[ i ] ) ;
2148 // NOT A BUG : AddInPort for an outport (Reversed service)
2149       anOutPort = (GraphBase::OutDataStreamPort * ) _DataFlowDataPorts->AddInPort(
2150                                                              _Orb , NamePtr() ,
2151                                                              Kind() ,
2152                                                              aService.ServiceoutParameter[ i ].Parametername ,
2153                                                              aService.ServiceoutParameter[ i ].Parametertype ,
2154                                                              SUPERV::DataStreamParameter ,
2155                                                              - 1 ,
2156                                                              _Graph_prof_debug , _Graph_fdebug ) ;
2157       anOutPort->Dependency( OutDataStreamDependency[ i ] ) ;
2158 // Attention : revoir les reversed DataStreamPorts
2159 //      anOutPort->NumberOfValues( OutNumberOfValues[ i ] ) ;
2160       cdebug << "OutStreamPort " << GetChangeNodeOutPort( i )->PortName() << " " << GetChangeNodeOutPort( i )->Kind() << endl ;
2161       cdebug << "ReversedOutStreamPort " << _DataFlowDataPorts->GetChangeNodeInPort( i )->PortName() << " " << _DataFlowDataPorts->GetChangeNodeInPort( i )->Kind()
2162              << endl ;
2163     }
2164     else {
2165       GetChangeNodeOutPort( i )->Kind( OutPortsKind[ i ] ) ;
2166       _DataFlowDataPorts->GetChangeNodeInPort( i )->Kind( OutPortsKind[ i ] ) ;
2167       GetChangeNodeOutPort( i )->Dependency( OutDataStreamDependency[ i ] ) ;
2168       _DataFlowDataPorts->GetChangeNodeInPort( i )->Dependency( OutDataStreamDependency[ i ] ) ;
2169       GetChangeNodeOutPort( i )->Dependency( OutDataStreamDependency[ i ] ) ;
2170       _DataFlowDataPorts->GetChangeNodeInPort( i )->Dependency( OutDataStreamDependency[ i ] ) ;
2171       cdebug << "OutPort " << GetChangeNodeOutPort( i )->PortName() << " "
2172              << GetChangeNodeOutPort( i )->Kind() << " " << GetChangeNodeOutPort( i )->PortStatus()
2173              << endl ;
2174       cdebug << "ReversedOutPort " << _DataFlowDataPorts->GetChangeNodeInPort( i )->PortName()
2175              << " " << _DataFlowDataPorts->GetChangeNodeInPort( i )->Kind()
2176              << " " << _DataFlowDataPorts->GetChangeNodeInPort( i )->PortStatus()
2177              << endl ;
2178     }
2179   }
2180 // Restore input datas and links :
2181   DataStreamInPortsNumber( 0 ) ;
2182   DataStreamOutPortsNumber( 0 ) ;
2183   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2184     aToNode = GraphNodes( i ) ;
2185     DataStreamInPortsNumber( DataStreamInPortsNumber() + aToNode->DataStreamInPortsNumber() ) ;
2186     DataStreamOutPortsNumber( DataStreamOutPortsNumber() + aToNode->DataStreamOutPortsNumber() ) ;
2187     for ( j = 0 ; j < aToNode->GetNodeInPortsSize() ; j++ ) {
2188       GraphBase::InPort *anInPort = aToNode->GetChangeNodeInPort(j) ;
2189       if ( !anInPort->IsGate() && anInPort->IsDataConnected() ) {
2190         if ( !AddInputData( anInPort->NodeName() ,
2191                             anInPort->PortName() ,
2192 //JR 21.02.2005 Debug Memory leak :                            anInPort->GetOutPort()->ValuePtr() ) ) {
2193 //JR 30.03.2005                            *anInPort->GetOutPort()->Value() ) ) {
2194                             anInPort->GetOutPort()->Value() ) ) {
2195           cdebug << "CreateService In" << j << " " << anInPort->NodeName() << "(" << anInPort->PortName() << ") "
2196                  << anInPort->PortStatus() << " --> AddInputData ERROR" << endl ;
2197           RetVal = false ;
2198         }
2199         else {
2200           cdebug << "CreateService In" << j << " " << anInPort->NodeName() << "(" << anInPort->PortName() << ") "
2201                  << anInPort->PortStatus() << " --> AddInputData" << endl ;
2202         }
2203       }
2204 //JR PAL8914 : InPorts of EndLoopNodes may not be in the Service of the Graph
2205 //      else if ( !anInPort->IsGate() && anInPort->IsNotConnected() ) {
2206       else if ( !anInPort->IsGate() &&
2207                 ( anInPort->IsNotConnected() || anInPort->IsExternConnected() ) &&
2208                 !aToNode->IsEndLoopNode() ) {
2209         if ( !AddLink( this , GetChangeInDataNodePort( anInPort->NodePortName() ) , aToNode , anInPort ) ) {
2210           cdebug << "CreateService In" << j << " " << anInPort->NodeName() << "(" << anInPort->PortName() << ") "
2211                  << anInPort->PortStatus() << " --> AddInLink ERROR" << endl ;
2212           RetVal = false ;
2213         }
2214         else {
2215           cdebug << "CreateService In" << j << " " << anInPort->NodeName() << "(" << anInPort->PortName() << ") "
2216                  << anInPort->PortStatus() << " --> AddInLink" << endl ;
2217         }
2218       }
2219       else {
2220         cdebug << "CreateService In" << j << " " << anInPort->NodeName() << "(" << anInPort->PortName() << ") "
2221                << anInPort->PortStatus() << " --> NO AddInputData/AddInLink" << endl ;
2222       }
2223     }
2224     for ( j = 0 ; j < aToNode->GetNodeOutPortsSize() ; j++ ) {
2225       GraphBase::OutPort *anOutPort = aToNode->GetChangeNodeOutPort(j) ;
2226       cdebug << "CreateService Out" << j << " " << anOutPort->NodeName() << "(" << anOutPort->PortName()
2227              << ") " << anOutPort->PortStatus() << " :" << endl ;
2228 //JR PAL8914 : OutPorts of LoopNodes may not be in the Service of the Graph
2229 //      if ( !anOutPort->IsGate() && anOutPort->IsNotConnected() && !aToNode->IsGOTONode() ) {
2230       if ( !anOutPort->IsGate() && !aToNode->IsGOTONode() && !aToNode->IsLoopNode() &&
2231 //JR Debug : 06.09.2005 : recreate that link if the OutPort is ExternConnected !!!...
2232            ( anOutPort->IsNotConnected() || anOutPort->IsExternConnected() ) ) {
2233         GraphBase::InPort *anInPort = GetChangeOutDataNodePort( anOutPort->NodePortName() ) ;
2234         if ( !AddLink( aToNode , anOutPort , this , anInPort ) ) {
2235           cdebug << "       --> " << Name() << "(" << anInPort->PortName()
2236                  << ") " << anInPort->PortStatus() << " AddOutLink ERROR" << endl ;
2237           RetVal = false ;
2238         }
2239         else {
2240           cdebug << "       --> " << Name() << "(" << anInPort->PortName()
2241                  << ") " << anInPort->PortStatus() << " AddOutLink" << endl ;
2242         }
2243       }
2244     }
2245   }
2246
2247 #ifdef _DEBUG_
2248   ListPorts( *_Graph_fdebug , 0 ) ;
2249 #endif
2250
2251   if ( !RetVal ) {
2252     SetMessages( "Fail to create the Service of the graph.\n" ) ;
2253   }
2254
2255   cdebug_out << "GraphBase::Graph::CreateService " << RetVal << endl;
2256   return RetVal ;
2257 }
2258
2259 bool GraphBase::Graph::InLineServices() {
2260   cdebug_in << "GraphBase::Graph::InLineServices" << endl;
2261
2262   int i , j ;
2263
2264 #ifdef _DEBUG_
2265   ListPorts( *_Graph_fdebug , 0 ) ;
2266 #endif
2267
2268   GraphBase::InLineNode * aINode ;
2269   SALOME_ModuleCatalog::Service aService ;
2270   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2271     aINode = (GraphBase::InLineNode * ) GraphNodes( i ) ;
2272     if ( aINode->IsOneOfInLineNodes() ) {
2273 //      cdebug << "GraphBase::Graph::InLineServices " << aINode->Name() << endl;
2274       aService.ServiceName = aINode->ServiceName() ;
2275       aService.ServiceinParameter.length( 0 ) ;
2276       aService.ServiceoutParameter.length( 0 ) ;
2277       aINode->DataStreamInPortsNumber( 0 ) ;
2278       aINode->DataStreamOutPortsNumber( 0 ) ;
2279       int InService = 0 ;
2280       int InStreamService = 0 ;
2281       for ( j = 0 ; j < aINode->GetNodeInPortsSize() ; j++ ) {
2282         if ( aINode->GetChangeNodeInPort(j)->IsGate() || aINode->GetChangeNodeInPort(j)->IsLoop() ) {
2283 #if 0
2284           cdebug << "GraphBase::Graph::InLineServices In" << j << " "
2285                  << aINode->GetChangeNodeInPort(j)->Kind() << " " 
2286                  << aINode->GetChangeNodeInPort(j)->PortType() << " " 
2287                  << aINode->GetChangeNodeInPort(j)->PortName() << " ignored "
2288                  << aINode->GetChangeNodeInPort(j)->IsGate() << " "
2289                  << aINode->GetChangeNodeInPort(j)->IsLoop() << endl;
2290 #endif
2291         }
2292         else if ( aINode->GetChangeNodeInPort(j)->IsDataStream() ) {
2293           aService.ServiceinDataStreamParameter.length( InStreamService+1 ) ;
2294           aService.ServiceinDataStreamParameter[InStreamService].Parametertype = StringToDataStreamType( aINode->GetChangeNodeInPort(j)->PortType() ) ;
2295           aService.ServiceinDataStreamParameter[InStreamService].Parametername = CORBA::string_dup( aINode->GetChangeNodeInPort(j)->PortName() ) ;
2296           aService.ServiceinDataStreamParameter[InStreamService++].Parameterdependency = aINode->GetChangeNodeInPort(j)->Dependency() ;
2297           aINode->IncrDataStreamInPorts() ;
2298 #if 0
2299           cdebug << "GraphBase::Graph::InLineServices In" << j << " "
2300                  << aINode->GetChangeNodeInPort(j)->Kind() << " " 
2301                  << aINode->GetChangeNodeInPort(j)->PortType() << " " 
2302                  << aINode->GetChangeNodeInPort(j)->PortName() << " "
2303                  << aINode->GetChangeNodeInPort(j)->IsGate() << " "
2304                  << aINode->GetChangeNodeInPort(j)->IsLoop() << endl;
2305 #endif
2306         }
2307         else {
2308           aService.ServiceinParameter.length( InService+1 ) ;
2309           aService.ServiceinParameter[InService].Parametertype = CORBA::string_dup( aINode->GetChangeNodeInPort(j)->PortType() ) ;
2310           aService.ServiceinParameter[InService++].Parametername = CORBA::string_dup( aINode->GetChangeNodeInPort(j)->PortName() ) ;
2311 #if 0
2312           cdebug << "GraphBase::Graph::InLineServices In" << j << " "
2313                  << aINode->GetChangeNodeInPort(j)->Kind() << " " 
2314                  << aINode->GetChangeNodeInPort(j)->PortType() << " " 
2315                  << aINode->GetChangeNodeInPort(j)->PortName() << " "
2316                  << aINode->GetChangeNodeInPort(j)->IsGate() << " "
2317                  << aINode->GetChangeNodeInPort(j)->IsLoop() << endl;
2318 #endif
2319         }
2320       }
2321       int OutService = 0 ;
2322       int OutStreamService = 0 ;
2323       for ( j = 0 ; j < aINode->GetNodeOutPortsSize() ; j++ ) {
2324 //        if ( aINode->GetChangeNodeOutPort(j)->IsGate() || aINode->GetChangeNodeOutPort(j)->IsLoop() || aINode->GetChangeNodeOutPort(j)->IsDataStream() ) {
2325         if ( aINode->GetChangeNodeOutPort(j)->IsGate() || aINode->GetChangeNodeOutPort(j)->IsLoop() ) {
2326 #if 0
2327           cdebug << "GraphBase::Graph::InLineServices Out" << j << " "
2328                  << aINode->GetChangeNodeOutPort(j)->Kind() << " " 
2329                  << aINode->GetChangeNodeOutPort(j)->PortType() << " " 
2330                  << aINode->GetChangeNodeOutPort(j)->PortName() << " ignored "
2331                  << aINode->GetChangeNodeOutPort(j)->IsGate() << " "
2332                  << aINode->GetChangeNodeOutPort(j)->IsLoop() << endl;
2333 #endif
2334         }
2335         else if ( aINode->GetChangeNodeOutPort(j)->IsDataStream() ) {
2336           aService.ServiceoutDataStreamParameter.length( OutStreamService+1 ) ;
2337           aService.ServiceoutDataStreamParameter[OutStreamService].Parametertype = StringToDataStreamType( aINode->GetChangeNodeOutPort(j)->PortType() ) ;
2338           aService.ServiceoutDataStreamParameter[OutStreamService].Parametername = CORBA::string_dup( aINode->GetChangeNodeOutPort(j)->PortName() ) ;
2339           aService.ServiceoutDataStreamParameter[OutStreamService++].Parameterdependency = aINode->GetChangeNodeOutPort(j)->Dependency() ;
2340           aINode->IncrDataStreamOutPorts() ;
2341 #if 0
2342           cdebug << "GraphBase::Graph::InLineServices Out" << j << " "
2343                  << aINode->GetChangeNodeOutPort(j)->Kind() << " " 
2344                  << aINode->GetChangeNodeOutPort(j)->PortType() << " " 
2345                  << aINode->GetChangeNodeOutPort(j)->PortName() << " "
2346                  << aINode->GetChangeNodeOutPort(j)->IsGate() << " "
2347                  << aINode->GetChangeNodeOutPort(j)->IsLoop() << endl;
2348 #endif
2349         }
2350         else {
2351           aService.ServiceoutParameter.length( OutService+1 ) ;
2352           aService.ServiceoutParameter[OutService].Parametertype = CORBA::string_dup( aINode->GetChangeNodeOutPort(j)->PortType() ) ;
2353           aService.ServiceoutParameter[OutService++].Parametername = CORBA::string_dup( aINode->GetChangeNodeOutPort(j)->PortName() ) ;
2354 #if 0
2355           cdebug << "GraphBase::Graph::InLineServices Out" << j << " "
2356                  << aINode->GetChangeNodeOutPort(j)->Kind() << " " 
2357                  << aINode->GetChangeNodeOutPort(j)->PortType() << " " 
2358                  << aINode->GetChangeNodeOutPort(j)->PortName()  << " "
2359                  << aINode->GetChangeNodeOutPort(j)->IsGate() << " "
2360                  << aINode->GetChangeNodeOutPort(j)->IsLoop() << endl;
2361 #endif
2362         }
2363       }
2364       aINode->SetService( aService ) ;
2365       if ( SetServiceOfMap( (GraphBase::Service * ) aINode ) ) {
2366 #if 0
2367         cdebug << "InLineServices SetServiceOfMap " << aINode->ServiceName() << " in MapOfServices"
2368                << " InStreamPort(" << aINode->DataStreamInPortsNumber() 
2369                << ") OutStreamPort(" << aINode->DataStreamOutPortsNumber() << ")" << endl ; 
2370 #endif
2371       }
2372 //      cdebug << "GraphBase::Graph::InLineServices" << *aINode->GetService() << endl;
2373     }
2374   }
2375
2376   cdebug_out << "GraphBase::Graph::InLineServices" << endl;
2377   return true ;
2378 }
2379
2380 bool GraphBase::Graph::Sort( int & SubStreamGraphsNumber ) {
2381 #ifdef _DEBUG_
2382   ListPorts( *_Graph_fdebug , 0 ) ;
2383 #endif
2384
2385   int i ;
2386   int j ;
2387   int NotSortedNumber = GraphNodesSize() ;
2388   bool NewSorted ;
2389   cdebug_in << "GraphBase::Graph::Sort" << endl;
2390   if ( NotSortedNumber ) {
2391     _LevelsNumber = 0 ;
2392     _ParallelExecutionNodes = false ;
2393     _Sorted.resize( GraphNodesSize() ) ;
2394     _CnxInPortsNumber.resize( GraphNodesSize() ) ;
2395     _DecrInPortsNumber.resize( GraphNodesSize() ) ;
2396     if ( _NodesNumber.size() ) {
2397       _NodesNumber.resize( 0 ) ;
2398       _SortedNodes.resize( 0 ) ;
2399     }
2400           
2401 // This is a simulation of the computation of the graph :
2402 // The initial state of nodes is :
2403 // - Sorted = false : the node is not sorted
2404 // - CnxInPortsNumber = ConnectedInPortsNumber : the number of ports that wait for a value from a link
2405 // - DecrInPortsNumber = 0 : there is no value available.
2406 #if 0
2407     cdebug << "GraphBase::Graph::Sort initial values :" << endl ;
2408     for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2409       GraphBase::ComputingNode * aNode = GraphNodes( i ) ;
2410       cdebug << aNode->Name() << " --> " << aNode->LinkedNodesSize() << " LinkedNodes :" << endl ;
2411       for ( j = 0 ; j < aNode->LinkedNodesSize()  ; j++ ) {
2412         cdebug << "              " << aNode->LinkedNodes( j )->Name() << endl ;
2413       }
2414     }
2415 #endif
2416     for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2417       _Sorted[ i ] = false ;
2418       _CnxInPortsNumber[ i ] = GraphNodes( i )->ConnectedInPortsNumber() ;
2419       _DecrInPortsNumber[ i ] = 0 ;
2420 //      cdebug << "Sort Node [" << i << "] " << GraphNodes( i )->Name() << " initial count "
2421 //             << _CnxInPortsNumber[ i ] << endl ;
2422     }
2423     
2424 // Nodes are linked ONLY if Ports are NOT DataStream for topological sort of node
2425 // ==============================================================================
2426     while ( NotSortedNumber ) {
2427       NewSorted = false ;
2428       
2429       for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2430         cdebug << "Sort level " << _LevelsNumber << ". [" << i << "] "
2431                << GraphNodes( i )->Name() << " count "
2432                << _CnxInPortsNumber[ i ] << endl ;
2433         if ( !_Sorted[ i ] && _CnxInPortsNumber[ i ] == 0 ) {
2434 // All inputs of GraphNodes( i ) are available : "AllDataReady"
2435           if ( (int ) _NodesNumber.size() != _LevelsNumber+1 ) {
2436             _NodesNumber.resize( _LevelsNumber+1 ) ;
2437             _SortedNodes.resize( _LevelsNumber+1 ) ;
2438             _NodesNumber[ _LevelsNumber ] = -1 ;
2439           }
2440 // There is one more node at that level
2441           _NodesNumber[ _LevelsNumber ]++ ;
2442           (_SortedNodes[ _LevelsNumber ]).resize( _NodesNumber[ _LevelsNumber ]+1 ) ;
2443           (_SortedNodes[ _LevelsNumber ])[ _NodesNumber[ _LevelsNumber ] ] = GraphNodes( i ) ;
2444           _Sorted[ i ] = true ;
2445           NewSorted = true ;
2446           NotSortedNumber -= 1 ;
2447           cdebug << GraphNodes( i )->Name() << " belongs to level "
2448                  << _LevelsNumber << ". " << GraphNodes( i )->LinkedNodesSize() << " linkednodes" << endl ;
2449 // GraphNodes( i ) has the state "AllDataReady". We simulate the end of its execution :
2450 // So we loop over all nodes that have a link from that node
2451 // And we increment the number of input ports of GraphNodes( i )->LinkedNodes( j ) that this
2452 // execution will give a value in DecrInPortsNumber : "SomeDataReady"
2453           for ( j = 0 ; j < GraphNodes( i )->LinkedNodesSize() ; j++ ) {
2454 // OutputPorts of GraphNodes( i ) will satisfy 
2455 //   GraphNodes( i )->LinkedInPortsNumber( j ) InPorts of
2456 //      GraphNodes( i )->LinkedNodes( j )
2457             GraphBase::StreamNode * aLinkedNode = GraphNodes( i )->LinkedNodes( j ) ;
2458             int aLinkedInPortsNumber = GraphNodes( i )->LinkedInPortsNumber( j ) ;
2459             cdebug << j << ". LinkedNode " << aLinkedNode->Name() ;
2460             if ( !aLinkedNode->IsDataFlowNode() && !aLinkedNode->IsDataStreamNode() ) {
2461               cdebug << " _DecrInPortsNumber[ "
2462                      << GetGraphNodeIndex( aLinkedNode->Name() )
2463                      << " ] = "
2464                      << _DecrInPortsNumber[ GetGraphNodeIndex( aLinkedNode->Name() ) ]
2465                      << " += " << aLinkedInPortsNumber ;
2466               _DecrInPortsNumber[ GetGraphNodeIndex( aLinkedNode->Name() ) ] += aLinkedInPortsNumber ;
2467             }
2468             cdebug << endl ;
2469           }
2470         }
2471       }
2472 // If no node was found, that FlowGraph is not valid : if we try to execute it, that FlowGraph
2473 // will wait for data(s) from node(s) not executed or not executing for ever
2474       if ( !NewSorted ) {
2475         SetMessages( "That graph is cyclic.\n" ) ;
2476         cdebug << "ERROR Loop detected at level " << _LevelsNumber << endl ;
2477         return false ; // Loop in the Graph
2478       }
2479 //      cdebug << "Bilan level " << _LevelsNumber << " : " << endl ;
2480       bool ChangeCount = false ;
2481 // We update now the number of InPorts with a link that are waiting for a value
2482       for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2483         if ( _DecrInPortsNumber[ i ] ) {
2484 //          int prevcount = _CnxInPortsNumber[ i ] ;
2485           _CnxInPortsNumber[ i ] -= _DecrInPortsNumber[ i ]  ;
2486           _DecrInPortsNumber[ i ] = 0 ;
2487           ChangeCount = true ;
2488 //          cdebug << "    " << GraphNodes( i )->Name() << " count " << prevcount
2489 //                 << " --> new count " << _CnxInPortsNumber[ i ] << endl ;
2490         }
2491       }
2492 // If there is no loop and if the number of InPorts with a link that are waiting for a value
2493 // does not change, the sort is finished. But there is also NotSortedNumber ...
2494 //      if ( !ChangeCount )
2495 //        break ;
2496       if ( NotSortedNumber ) {
2497         _LevelsNumber += 1 ;
2498       }
2499     }
2500     _ThreadsMax = 0 ;
2501     int AllSortedNodes = 0 ;
2502     _HeadNodes = _SortedNodes[ 0 ] ;
2503     _HeadNodesSize = _SortedNodes[ 0 ].size() ;
2504 // QueueNodes was used in the past in order to know if the execution of a graph is finished
2505 // But because of loop nodes that was changed. So that part of code is a "clutter"
2506 // Now a graph has finished its execution when the number of executing threads is zero
2507     _QueueNodes = _SortedNodes[ _LevelsNumber ] ;
2508     _QueueNodesSize = _SortedNodes[ _LevelsNumber ].size() ;
2509     for ( i = 0 ; i < _QueueNodesSize ; i++ ) {
2510       if ( !_QueueNodes[ i ]->IsGOTONode() ) {
2511         break ;
2512       }
2513     }
2514     if ( i == _QueueNodesSize && _LevelsNumber ) {
2515       _QueueNodes = _SortedNodes[ _LevelsNumber - 1 ] ;
2516       _QueueNodesSize = _SortedNodes[ _LevelsNumber - 1 ].size() ;
2517     }
2518 // Computation of the maximum number of threads == the maximum number of nodes of all levels
2519     for ( i = 0 ; i <= _LevelsNumber ; i++ ) {
2520       AllSortedNodes += _NodesNumber[ i ]+1 ;
2521       if ( _NodesNumber[ i ] + 1 > _ThreadsMax ) {
2522         _ThreadsMax = _NodesNumber[ i ] + 1 ;
2523       }
2524       cdebug << _NodesNumber[ i ]+1 << " Nodes of level " << i << " : "
2525              << (_SortedNodes[ i ])[ 0 ]->Name() << endl ;
2526       for ( j = 1 ; j <= _NodesNumber[ i ] ; j++ ) {
2527         _ParallelExecutionNodes = true ;
2528         cdebug << "                     " << (_SortedNodes[ i ])[ j ]->Name()
2529                << endl ;
2530       }
2531     }
2532     if ( _ParallelExecutionNodes ) {
2533 //      cdebug << "Parallel Execution Nodes detected." << endl ;
2534     }
2535     else {
2536 //      cdebug << "No Parallel Execution Nodes detected." << endl ;
2537     }
2538     if ( AllSortedNodes != GraphNodesSize() ) {
2539       SetMessages( "That graph is cyclic.\n" ) ;
2540       cdebug << "ERROR Loop detected at level " << _LevelsNumber << endl ;
2541       return false ; // Loop in the Graph
2542     }
2543
2544     cdebug << "Graph::Sort " << _NodesNumber[ 0 ] << " HeadNodes :" << endl ;
2545     for ( i= 0 ; i <= _NodesNumber[ 0 ] ; i++ ) {
2546       (_SortedNodes[ 0 ])[ i ]->HeadNode( true ) ;
2547       cdebug << "            " << i << ". : " << (_SortedNodes[ 0 ])[ i ]->Name() << endl ;
2548     }
2549
2550 // Give a subgraph/substreamgraph number > 0 to HeadNodes (level 0)
2551 // There is no substreamgraph for nodes without StreamPorts
2552     for ( j = 0 ; j <= _NodesNumber[ 0 ] ; j++ ) {
2553       (_SortedNodes[ 0 ])[ j ]->Level( 0 ) ;
2554       (_SortedNodes[ 0 ])[ j ]->SortedIndex( j ) ;
2555       (_SortedNodes[ 0 ])[ j ]->SubGraph( j + 1 ) ;
2556       if ( (_SortedNodes[ 0 ])[ j ]->HasDataStream() ) {
2557         (_SortedNodes[ 0 ])[ j ]->SubStreamGraph( j + 1 ) ;
2558       }
2559       else {
2560         (_SortedNodes[ 0 ])[ j ]->SubStreamGraph( -1 ) ;
2561       }
2562     }
2563
2564 // Give a subgraph/substreamgraph number = 0 to all other nodes :
2565 // the SubGraph of that nodes is unknown
2566 // There is no substreamgraph for nodes without StreamPorts
2567     for ( i = 1 ; i <= _LevelsNumber ; i++ ) {
2568       for ( j = 0 ; j <= _NodesNumber[ i ] ; j++ ) {
2569         (_SortedNodes[ i ])[ j ]->Level( i ) ;
2570         (_SortedNodes[ i ])[ j ]->SortedIndex( j ) ;
2571         (_SortedNodes[ i ])[ j ]->SubGraph( 0 ) ;
2572         if ( (_SortedNodes[ i ])[ j ]->HasDataStream() ) {
2573           (_SortedNodes[ i ])[ j ]->SubStreamGraph( 0 ) ;
2574         }
2575         else {
2576           (_SortedNodes[ i ])[ j ]->SubStreamGraph( -1 ) ;
2577         }
2578       }
2579     }
2580
2581 // Computation of independent SubGraphs which have NO link between them
2582     cdebug << endl << "Computation of SubGraphs" << endl ;
2583     bool Graphs = true ;
2584     while ( Graphs ) {
2585       for ( i = 0 ; i <= _LevelsNumber ; i++ ) {
2586         cdebug << endl << "LevelsNumber " << _LevelsNumber << " " << _NodesNumber[ i ]
2587                << " Nodes :" << endl ;
2588         for ( j = 0 ; j <= _NodesNumber[ i ] ; j++ ) {
2589           GraphBase::ComputingNode * aNode = (_SortedNodes[ i ])[ j ] ;
2590           cdebug << "    " << aNode->Name() << " SubGraph " << aNode->SubGraph() << endl ;
2591           int k ;
2592           for ( k = 0 ; k < aNode->LinkedNodesSize() ; k++ ) {
2593           if ( aNode->LinkedNodes( k )->SubGraph() ) {
2594               if ( aNode->LinkedNodes( k )->SubGraph() != aNode->SubGraph() ) {
2595 //                   && aNode->LinkedNodes( k )->Level() == aNode->Level()+1 ) {
2596 //            aNode->SubGraph( aNode->LinkedNodes( k )->SubGraph() ) ;
2597                 int OldSub = aNode->SubGraph() ;
2598                 int NewSub = aNode->LinkedNodes( k )->SubGraph() ;
2599               cdebug << "        " << aNode->Name() << " changed SubGraph "
2600                        << aNode->LinkedNodes( k )->SubGraph() << endl ;
2601                 int l ;
2602                 for ( l = 0 ; l <= _LevelsNumber ; l++ ) {
2603                   int m ;
2604                   for ( m = 0 ; m <= _NodesNumber[ l ] ; m++ ) {
2605                     if ( (_SortedNodes[ l ])[ m ]->SubGraph() == OldSub ) {
2606                       GraphBase::ComputingNode * aSubNode = (_SortedNodes[ l ])[ m ] ;
2607                       aSubNode->SubGraph( NewSub ) ;
2608                 }
2609                 }
2610               }
2611                 Graphs = false ;
2612                 break ;
2613             }
2614               else {
2615                 cdebug << "        Linked " << aNode->LinkedNodes( k )->Name()
2616                        << " same SubGraph " << aNode->LinkedNodes( k )->SubGraph() << endl ;
2617             }
2618           }
2619             else {
2620               cdebug << "        LinkedNode " << aNode->LinkedNodes( k )->Name()
2621                      << " initial SubGraph " << aNode->SubGraph() << endl ;
2622               aNode->LinkedNodes( k )->SubGraph( aNode->SubGraph() ) ;
2623           }
2624         }
2625           if ( !Graphs ) {
2626             break ;
2627           }
2628         }
2629         if ( !Graphs ) {
2630           break ;
2631         }
2632       }
2633       if ( Graphs ) {
2634         cdebug << endl << "SubGraphs result : " << endl ;
2635         break ;
2636       }
2637       cdebug << endl << "One more time" << endl ;
2638       Graphs = true ;
2639     }
2640 // Make a sequential renumbering of SubGraphs :
2641     _SubGraphsNumber = 0 ;
2642     int CurrGraphsNumber = 0;
2643     int k ;
2644     for ( k = 0 ; k <= _NodesNumber[ 0 ] ; k++ ) {
2645       if ( (_SortedNodes[ 0 ])[ k ]->SubGraph() > CurrGraphsNumber ) {
2646         CurrGraphsNumber = (_SortedNodes[ 0 ])[ k ]->SubGraph() ;
2647         _SubGraphsNumber += 1 ;
2648         for ( i = 0 ; i <= _LevelsNumber ; i++ ) {
2649           for ( j = 0 ; j <= _NodesNumber[ i ] ; j++ ) {
2650             if ( (_SortedNodes[ i ])[ j ]->SubGraph() == CurrGraphsNumber ) {
2651               (_SortedNodes[ i ])[ j ]->SubGraph( _SubGraphsNumber ) ;
2652               cdebug << "SubGraphsNumber " << _SubGraphsNumber << " " << " Level "
2653                      << i << " : " << (_SortedNodes[ i ])[ j ]->Name()
2654                      << endl ;
2655             }
2656           }
2657         }
2658       }
2659     }
2660
2661 //    cdebug << endl << "Computation of SubStreamGraphs" << endl ;
2662     for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2663       GraphBase::ComputingNode * aNode = GraphNodes( i ) ;
2664       if ( aNode->SubStreamGraph() < 0 ) {
2665 //      cdebug << "Graph " << aNode->Name() << " has NO streamport" << endl ;
2666       }
2667       else {
2668 //        cdebug << aNode->Name() << " SubGraph " << aNode->SubGraph() << " --> "
2669 //               << aNode->LinkedStreamNodesSize() << " LinkedStreamNodes :" << endl ;
2670         for ( j = 0 ; j < aNode->LinkedStreamNodesSize()  ; j++ ) {
2671 //          cdebug << "              " << aNode->LinkedStreamNodes( j )->Name() << endl ;
2672         }
2673       }
2674     }
2675
2676 // Computation of independent SubStreamGraphs which have NO StreamLink between them
2677     SubStreamGraphsNumber = 0 ;
2678     int ilevel ;
2679     for ( ilevel = 0 ; ilevel <= _LevelsNumber ; ilevel++ ) {
2680 // Loop for _NodesNumber[ ilevel ] nodes of the level ilevel
2681       int jnode ;
2682       for ( jnode = 0 ; jnode <= _NodesNumber[ ilevel ] ; jnode++ ) {
2683         GraphBase::ComputingNode * aNode = (_SortedNodes[ ilevel ])[ jnode ] ;
2684         if ( aNode->SubStreamGraph() < 0 ) {
2685 //        cdebug << "Graph " << aNode->SubStreamGraph() << " " << aNode->Name()
2686 //                 << " has NO streamport" << endl ;
2687         }
2688         else {
2689           int CurStreamGraphsNumber ;
2690           if ( aNode->SubStreamGraph() > 0 ) {
2691 //          cdebug << "SubStreamGraph " << aNode->SubStreamGraph() << " " << aNode->Name()
2692 //                   << " has streamport LinkedStreamNodesSize already in a SubStreamGraph" << endl ;
2693             CurStreamGraphsNumber = aNode->SubStreamGraph() ;
2694           }
2695           else {
2696             CurStreamGraphsNumber = SubStreamGraphsNumber+1 ;
2697           }
2698           int RetVal = 0 ;
2699           while ( RetVal != CurStreamGraphsNumber ) {
2700             RetVal = CurStreamGraphsNumber ;
2701             aNode->SetSubStreamGraph( CurStreamGraphsNumber , RetVal ) ;
2702             if ( RetVal != CurStreamGraphsNumber ) {
2703               for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2704                 GraphBase::ComputingNode * aNode = GraphNodes( i ) ;
2705                 if ( aNode->SubStreamGraph() == CurStreamGraphsNumber ) {
2706                   aNode->SubStreamGraph( RetVal ) ;
2707                 }
2708               }
2709               CurStreamGraphsNumber = RetVal ;
2710               RetVal = 0 ;
2711             }
2712             if ( CurStreamGraphsNumber > SubStreamGraphsNumber ) {
2713               SubStreamGraphsNumber = CurStreamGraphsNumber ;
2714             }
2715           }
2716         }
2717       }
2718     }
2719 // Make a sequential renumbering of SubGraphs :
2720 //    cdebug << endl << "Last SubStreamGraphsNumber : " << SubStreamGraphsNumber << endl ;
2721     int CurrStreamGraphsNumber = 0 ;
2722     int count = 0 ;
2723     for ( CurrStreamGraphsNumber = 0 ; CurrStreamGraphsNumber <= SubStreamGraphsNumber ; CurrStreamGraphsNumber++ ) {
2724       bool SearchCurrStreamGraphsNumber = true ;
2725       for ( k = 0 ; k <= _LevelsNumber && SearchCurrStreamGraphsNumber ; k++ ) {
2726         int l ;
2727         for ( l = 0 ; l <= _NodesNumber[ k ] && SearchCurrStreamGraphsNumber ; l++ ) {
2728           if ( (_SortedNodes[ k ])[ l ]->SubStreamGraph() == CurrStreamGraphsNumber ) {
2729             SearchCurrStreamGraphsNumber = false ;
2730             count = count + 1 ;
2731             if ( CurrStreamGraphsNumber != count ) {
2732 //              cdebug << "CurrStreamGraphsNumber " << CurrStreamGraphsNumber << " count " << count
2733 //                     << " Level " << k << " n " << l << endl ;
2734               for ( i = k ; i <= _LevelsNumber ; i++ ) {
2735                 for ( j = 0 ; j <= _NodesNumber[ i ] ; j++ ) {
2736                   if ( (_SortedNodes[ i ])[ j ]->SubStreamGraph() == CurrStreamGraphsNumber ) {
2737                     (_SortedNodes[ i ])[ j ]->SubStreamGraph( count ) ;
2738 //                    cdebug << "SubStreamGraphsNumber " << CurrStreamGraphsNumber << " --> " << count << " "
2739 //                           << " Level " << i << " : " << (_SortedNodes[ i ])[ j ]->Name() << endl ;
2740                   }
2741                   else if ( (_SortedNodes[ i ])[ j ]->SubStreamGraph() > 0 ) {
2742 //                    cdebug << "SubStreamGraphsNumber " << (_SortedNodes[ i ])[ j ]->SubStreamGraph()
2743 //                           << " != " << CurrStreamGraphsNumber << " Level " << i << " : "
2744 //                           << (_SortedNodes[ i ])[ j ]->Name() << endl ;
2745                   }
2746                 }
2747               }
2748             }
2749           }
2750         }
2751       }
2752     }
2753     SubStreamGraphsNumber = count ;
2754 //    cdebug << endl << "SubStreamGraphs result : " << SubStreamGraphsNumber << " SubStreamGraphs" << endl ;
2755 //    int CurrStreamGraphsNumber ;
2756 //    for ( CurrStreamGraphsNumber = 1 ; CurrStreamGraphsNumber <= SubStreamGraphsNumber  ; CurrStreamGraphsNumber++ ) {
2757 //      for ( ilevel = 0 ; ilevel <= _LevelsNumber ; ilevel++ ) {
2758 //        for ( k = 0 ; k <= _NodesNumber[ ilevel ] ; k++ ) {
2759 //          if ( (_SortedNodes[ ilevel ])[ k ]->SubStreamGraph() == CurrStreamGraphsNumber ) {
2760 //            cdebug << "SubStreamGraphsNumber " << CurrStreamGraphsNumber << " : "
2761 //                   << (_SortedNodes[ ilevel ])[ k ]->Name() << endl ;
2762 //        }
2763 //      }
2764 //      }
2765 //    }
2766   }
2767
2768 #ifdef _DEBUG_
2769   ListPorts( *_Graph_fdebug , 0 ) ;
2770 #endif
2771
2772   cdebug_out << "GraphBase::Graph::Sort" << endl;
2773   return true ;
2774 }
2775
2776 bool GraphBase::Graph::ValidLoops() const {
2777   cdebug_in << "GraphBase::Graph::ValidLoops" << endl;
2778   bool RetVal = true ;
2779   int i ;
2780   GraphBase::ComputingNode * aNode ;
2781   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2782     aNode = GraphNodes( i ) ;
2783     if ( aNode->IsLoopNode() ) {
2784       GraphBase::LoopNode * aLoopNode = (GraphBase::LoopNode * ) aNode ;
2785       GraphBase::EndOfLoopNode * anEndLoopNode ;
2786       anEndLoopNode = (GraphBase::EndOfLoopNode * ) aLoopNode->CoupledNode() ;
2787       string anErrorMessage = string( "CheckLoop " ) + string( aLoopNode->Name() ) +
2788                               string( " --> " ) + string( anEndLoopNode->Name() ) +
2789                               string( " :\n" ) ;
2790       if ( !aLoopNode->CheckLoop( aLoopNode , anEndLoopNode , anErrorMessage ) ) {
2791         ((GraphBase::Graph * ) this)->SetMessages( anErrorMessage ) ;
2792         cdebug << "GraphBase::Graph::ValidLoops false aLoopNode " << aLoopNode->Name()
2793                << endl;
2794         RetVal = false ;
2795       }
2796       anErrorMessage = string( "CheckEndLoop " ) + string( aLoopNode->Name() ) +
2797                        string( " --> " ) + string( anEndLoopNode->Name() ) + string( " :\n" ) ;
2798       if ( !anEndLoopNode->CheckEndLoop( aLoopNode , anEndLoopNode , anErrorMessage ) ) {
2799         ((GraphBase::Graph * ) this)->SetMessages( anErrorMessage ) ;
2800         cdebug << "GraphBase::Graph::ValidLoops false anEndLoopNode " << anEndLoopNode->Name()
2801                << endl;
2802         RetVal = false ;
2803       }
2804     }
2805   }
2806   cdebug_out << "GraphBase::Graph::ValidLoops RetVal " << RetVal << endl;
2807   return RetVal ;
2808 }
2809
2810 bool GraphBase::Graph::ValidSwitchs() const {
2811   cdebug_in << "GraphBase::Graph::ValidSwitchs" << endl;
2812   bool RetVal = true ;
2813   int i ;
2814   GraphBase::ComputingNode * aNode ;
2815   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2816     aNode = GraphNodes( i ) ;
2817     if ( aNode->IsSwitchNode() ) {
2818       GraphBase::SwitchNode * aSwitchNode = (GraphBase::SwitchNode * ) aNode ;
2819       if ( !aSwitchNode->CheckSwitch() ) {
2820         cdebug << "GraphBase::Graph::ValidSwitchs false aSwitchNode " << aSwitchNode->Name()
2821                << endl;
2822         RetVal = false ;
2823       }
2824     }
2825   }
2826   cdebug_out << "GraphBase::Graph::ValidSwitchs RetVal " << RetVal << endl;
2827   return RetVal ;
2828 }
2829
2830 // Controle de la coherence des noeuds de calcul
2831 // Enregistrement dans la liste des noeuds "tete" de graphe
2832
2833 bool GraphBase::Graph::ComputingNodes() const {
2834   bool RetVal = true ;
2835   cdebug << "GraphExecutor::Graph::ComputingNodes ()" << endl;
2836
2837 //  list<GraphEditor::Node *> aComputingNodesList = _G->ComputingNodesList() ;
2838 //  list<GraphEditor::Node *>::iterator aNode = aComputingNodesList.begin();
2839 //  GraphEditor::Port *  iP;
2840
2841 //  for (aNode = _G->ComputingNodesList().begin(); aNode !=_G->ComputingNodesList().end(); aNode++) {
2842 //  while ( aNode != aComputingNodesList.end() ) {
2843   int i ;
2844   GraphBase::ComputingNode * aNode ;
2845   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2846     aNode = GraphNodes( i ) ;
2847     cdebug << "Graph::ComputingNodes " << i << ". " << aNode->Name() << " Head " << aNode->IsHeadNode()
2848            << endl ;
2849     // Tous les ports d'entree de tous les noeuds de calcul sont bien connectes
2850     // Enregistrement eventuel dans la liste des noeuds "tete" de graphe
2851 //    if ((*aNode)->GetNodeInPortsSize() == 0)
2852 //      _headNodes.push_front(*aNode);
2853     int j ;
2854     for ( j = 1 ; j < aNode->GetNodeInPortsSize() ; j++ ) {
2855       const GraphBase::InPort *iP = aNode->GetNodeInPort(j);
2856       if ( iP->IsNotConnected() ){
2857 //      cdebug << "Le port d'entree " << iP->PortName()
2858 //               << " du noeud de calcul " << aNode->Name() << " du graphe  "
2859 //               << Name() << " n'est pas connecte "<< endl;
2860 //        string anErrorMessage = string( "That graph have InPort not connected " ) +
2861 //                                string( iP->NodeName() ) +
2862 //                                string( "( " ) + string( iP->PortName() ) + string( " )\n" ) ;
2863 //        ((GraphBase::Graph * ) this)->SetMessages( anErrorMessage ) ;
2864         RetVal = false ;
2865       };
2866
2867     };
2868
2869     // Tous les noeuds de calcul ont au moins un port de sortie connecte
2870     bool oneOutPortConnected = false;
2871     for ( j = 1 ; j < aNode->GetNodeOutPortsSize() ; j++) {
2872       const GraphBase::OutPort *iP = aNode->GetNodeOutPort(j);
2873       if ( iP->IsPortConnected() || iP->IsDataConnected() ){
2874         oneOutPortConnected = true ;
2875 //      break;
2876       }
2877       else {
2878 //      cdebug << "Le port de sortie " << iP->PortName()
2879 //               << " du noeud de calcul " << aNode->Name() << " du graphe  "
2880 //               << Name() << " n'est pas connecte "<< endl;
2881 //        string anErrorMessage = string( "That graph have OutPort not connected " ) +
2882 //                                string( iP->NodeName() ) +
2883 //                                string( "( " ) + string( iP->PortName() ) + string( " )\n" ) ;
2884 //        ((GraphBase::Graph * ) this)->SetMessages( anErrorMessage ) ;
2885         RetVal = false ;
2886       }
2887     };
2888     if (!oneOutPortConnected) {
2889 //      cdebug << "Le noeud de calcul " << aNode->Name() << " du graphe  "
2890 //               << Name() << " n'a aucun port de sortie connecte "<< endl;
2891 //      _computingError.push_front(2);
2892     }
2893   };
2894 //  return _computingError.size () ;
2895   return RetVal ;
2896 }
2897
2898 bool GraphBase::Graph::LinkLoopNodes(bool & NewLink ) {
2899   bool RetVal = true ;
2900   NewLink = false ;
2901   int i , j ;
2902   cdebug_in << "GraphBase::Graph::LinkLoopNodes()" << endl;
2903   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2904     GraphBase::ComputingNode * aNode = GraphNodes( i ) ;
2905     if ( aNode->IsLoopNode() ) {
2906       GraphBase::LoopNode * aLoopNode = (GraphBase::LoopNode * ) aNode ;
2907       for ( j = 0 ; j < aLoopNode->GetNodeInPortsSize() ; j++ ) {
2908         GraphBase::InPort *anInPort = aLoopNode->GetChangeNodeInPort(j) ;
2909         cdebug << "Graph::LinkLoopNodes " << aLoopNode->Name() << "( " << anInPort->PortName()
2910                << " ) InPort " << anInPort->PortStatus() << endl ;
2911         if ( !anInPort->IsGate() && anInPort->IsNotConnected() ) {
2912           if ( !AddLink( aLoopNode->CoupledNode() , aLoopNode->CoupledNode()->GetChangeNodeOutPort( j ) ,
2913                          aLoopNode , anInPort ) ) {
2914             cdebug << "Graph::LinkLoopNodes AddLink ERROR "
2915                    << aLoopNode->CoupledNode()->Name()
2916                    << "( " << aLoopNode->CoupledNode()->GetChangeNodeOutPort( j )->PortName()
2917                    << " ) --> " << aLoopNode->Name() << "( " << anInPort->PortName() << " )"
2918                    << endl ;
2919             RetVal = false ;
2920           }
2921           else {
2922             NewLink = true ;
2923           }
2924         }
2925       }
2926       for ( j = 0 ; j < aLoopNode->CoupledNode()->GetNodeInPortsSize() ; j++ ) {
2927         GraphBase::EndOfLoopNode * anEndLoopNode ;
2928         anEndLoopNode = (GraphBase::EndOfLoopNode * ) aLoopNode->CoupledNode() ;
2929         GraphBase::InPort *anInPort = anEndLoopNode->GetChangeNodeInPort( j ) ;
2930         cdebug << "Graph::LinkLoopNodes " << anEndLoopNode->Name() << "( " << anInPort->PortName()
2931                << " ) InPort " << anInPort->PortStatus() << endl ;
2932         if ( !anInPort->IsGate() && anInPort->IsNotConnected() ) {
2933           if ( !AddLink( aLoopNode , aLoopNode->GetChangeNodeOutPort( j ) ,
2934                          anEndLoopNode , anInPort ) ) {
2935             cdebug << "Graph::LinkLoopNodes AddLink ERROR " << aLoopNode->Name() << "( "
2936                    << aLoopNode->GetChangeNodeOutPort( j )->PortName() << " ) --> "
2937                    << anEndLoopNode->Name() << "( " << anInPort->PortName() << " )"
2938                    << endl ;
2939             RetVal = false ;
2940           }
2941           else {
2942             NewLink = true ;
2943           }
2944         }
2945       }
2946     }
2947     else if ( aNode->IsGOTONode() ) {
2948       GraphBase::GOTONode * aGOTONode = (GraphBase::GOTONode * ) aNode ;
2949       GraphBase::OutPort *anOutGate = aGOTONode->GetChangeNodeOutGate() ;
2950       if ( anOutGate->IsNotConnected() ) {
2951         if ( aGOTONode->CoupledNode() ) {
2952           cdebug << "Graph::LinkLoopNodes aNode " << aNode << " : " << aNode->Name()
2953                  << aGOTONode->CoupledNode() << " : " << aGOTONode->CoupledNode()->Name()
2954                  << endl ;
2955           RetVal = AddLink( aGOTONode , anOutGate , aGOTONode->CoupledNode() ,
2956                             aGOTONode->CoupledNode()->GetChangeNodeInGate() );
2957           cdebug << "GraphBase::Graph::LinkLoopNodes AddLink ERROR " << aGOTONode->Name() << "( "
2958                  << anOutGate->PortName() << " ) --> " << aGOTONode->CoupledNode()->Name() << "( "
2959                  << aGOTONode->CoupledNode()->GetChangeNodeInGate()->PortName() << " )" << endl ;
2960           if ( !RetVal )
2961             NewLink = true;
2962         }
2963       }
2964     }
2965   }
2966   cdebug_out << "GraphBase::Graph::LinkLoopNodes() NewLink " << NewLink << " returns " << RetVal
2967              << endl;
2968   return RetVal ;
2969 }
2970
2971 // Controle de la coherence des noeuds de calcul
2972 // Enregistrement dans la liste des noeuds "tete" de graphe
2973
2974 bool GraphBase::Graph::DataServerNodes() const {
2975
2976   cdebug_in << "GraphBase::Graph::DataServerNodes ()" << endl;
2977
2978 //  const GraphExecutor::InNode *DataFlowDatas = GetDataFlowDatas() ;
2979   int i , j , ierr = 0 ;
2980
2981 //  if ( DataFlowDatas == NULL ) {
2982 //    MESSAGE( "No input data available in the DataFlow " << _G->Name() );
2983 //    return 0 ;
2984 //  }
2985
2986 //  const GraphExecutor::InNode *DataFlowNode = _G->GetDataFlowNode() ;
2987 //  MESSAGE( "DataServerNodes DataFlowNode : " << *DataFlowNode );
2988
2989 //  MESSAGE( "DataServerNodes DataFlowDatas : " << *DataFlowDatas );
2990
2991 // cout are inversed because DataFlowDatas is a mirror node of the DataFlow
2992
2993   ierr = CheckDataServerNodes() ;
2994
2995 //  list<GraphExecutor::InNode *> aComputingNodesList = _G->ComputingNodesList() ;
2996 //  list<GraphExecutor::InNode *>::iterator aNode = aComputingNodesList.begin();
2997   if ( GraphNodesSize() == 0 ) {
2998     ierr++ ;
2999   }
3000   else {
3001     GraphBase::ComputingNode * aNode ;
3002     for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
3003       aNode = GraphNodes( i ) ;
3004 //  while ( aNode != aComputingNodesList.end() ) {
3005       if ( aNode->IsFactoryNode() ) {
3006         GraphBase::FactoryNode * FaNode = (GraphBase::FactoryNode * ) aNode ;
3007         if ( !strlen( FaNode->Computer() ) ) {
3008 //          cdebug << "ComputerName missing for node " << FaNode->Name() ;
3009           if ( !strlen( FaNode->Computer() ) ) {
3010             ierr++ ;
3011             cdebug << endl ;
3012           }
3013           else {
3014 //            cdebug << ". " << FaNode->Computer() << " will be used." << endl ;
3015           }
3016         }
3017     }
3018 // For Outputs of the DataFlow :
3019       for ( j = 0 ; j < aNode->GetNodeOutPortsSize() ; j++ ) {
3020         const GraphBase::OutPort * anOutPort = aNode->GetNodeOutPort(j) ;
3021 //JR Debug 06.06.2005 : if it is not a Gate !
3022 //        if ( anOutPort->IsNotConnected() ) {
3023         if ( anOutPort->IsNotConnected() && !anOutPort->IsGate() ) {
3024           cdebug << "Graph::DataServerNodes Add[Stream]LinkedNode for OutPort "
3025                  << aNode->Name() << "( " << anOutPort->PortName() << " , "
3026                  << anOutPort->PortStatus() << " )" << endl ;
3027           if ( anOutPort->IsDataStream() ) {
3028             aNode->AddStreamLinkedNode( (GraphBase::ComputingNode *) this ) ;
3029           }
3030           else {
3031             aNode->AddLinkedNode( (GraphBase::ComputingNode *) this ) ;
3032           }
3033         }
3034       }
3035     }
3036   }
3037
3038 // Chaque noeud dataserver ne possede qu'un seul port entree ou sortie et il est bien connecte
3039
3040 //  list<GraphExecutor::InNode *> aDataServerNodesList = _G->DataServerNodesList() ;
3041 //  list<GraphExecutor::InNode *>::iterator it = aDataServerNodesList.begin() ;
3042
3043 //  for (it = _G->DataServerNodesList().begin(); it !=_G->DataServerNodesList().end(); it++){
3044 //  while ( it != aDataServerNodesList.end() ) {
3045 //    if ( (*it)->GetNodeOutPortsSize() && (*it)->GetNodeInPortsSize() ) {
3046 //      cerr << "Erreur dans le noeud serveur de donnees " 
3047 //           << (*it)->Name() << " du graphe  " << _G->Name() << endl;
3048 //      cerr << "A la fois importation et exportation de donnees" << endl;
3049 //      _dataServerError.push_front(1);
3050 //    }
3051
3052 //    if ((*it)->GetNodeOutPortsSize()) {
3053 //      if ((*it)->GetNodeOutPortsSize()==1){
3054 //      if ( (*it)->GetNodeOutPort(0)->IsPortConnected() ){
3055 //        _headNodes.push_front(*it);
3056 //      }
3057 //      else {
3058 //        cerr << "Le port de sortie du noeud serveur de donnees "
3059 //               << (*it)->Name() << " du graphe  " << _G->Name()
3060 //               << " n'est pas connecte "<< endl;
3061 //        _dataServerError.push_front(4);
3062 //      }
3063 //      }
3064 //      else {
3065 //      cerr << "Plus d'une donnee importee du noeud serveur de donnees "
3066 //             << (*it)->Name() << " du graphe  " << _G->Name() << endl;
3067 //      _dataServerError.push_front(2);
3068 //      }
3069 //    }
3070
3071 //    if ((*it)->GetNodeInPortsSize()) {
3072 //      if ((*it)->GetNodeInPortsSize() > 1){
3073 //      cerr << "Plus d'une donnee exportee vers le noeud serveur de donnees "
3074 //             << (*it)->Name() << " du graphe  " << _G->Name() << endl;
3075 //      _dataServerError.push_front(3);
3076 //      }
3077 //      else
3078 //      if ( !(*it)->GetNodeInPort(0)->IsPortConnected() ){
3079 //      cerr << "Le port d'entree du noeud serveur de donnees "
3080 //             << (*it)->Name() << " du graphe  " << _G->Name()
3081 //             << " n'est pas connecte "<< endl;
3082 //      _dataServerError.push_front(5);
3083 //      }
3084 //    }
3085 //    it++ ;
3086 //  };
3087
3088 //  return _dataServerError.size ();
3089   cdebug_out << "GraphBase::Graph::DataServerNodes ierr " << ierr << endl;
3090   return ( ierr == 0 ) ;
3091 }
3092
3093 SUPERV::GraphState GraphBase::Graph::PortState(
3094                                    const char* NodeName ,
3095                                    const char* ServiceParameterName ) {
3096   SUPERV::GraphState aRet = SUPERV::UndefinedState ;
3097 //  cdebug << "GraphBase::Graph::PortState( " << NodeName << " , "
3098 //         << ServiceParameterName << " )" << endl ;
3099
3100   char *theNode ;
3101   char *aPort ;
3102   NodePort( NodeName , ServiceParameterName , &theNode , &aPort ) ;
3103
3104   GraphBase::ComputingNode * aNode = GetChangeGraphNode( theNode ) ;
3105   if ( aNode ) {
3106     GraphBase::OutPort *anOutPort ;
3107     anOutPort = aNode->GetChangeOutPort( aPort );
3108     if ( anOutPort == NULL ) {
3109       GraphBase::InPort *anInPort = aNode->GetChangeInPort( aPort );
3110       if ( anInPort )
3111         anOutPort = anInPort->GetOutPort() ;
3112       else {
3113         cdebug << "ERROR GraphBase::Graph::PortState OutPort/InPort not found --> "
3114                << aRet << endl ;
3115       }
3116     }
3117     if ( anOutPort ) {
3118       aRet = anOutPort->PortState() ;
3119 //      cdebug << "GraphBase::Graph::PortState --> " << aRet << endl ;
3120     }
3121   }
3122   else {
3123     cdebug << "ERROR GraphBase::Graph::PortState Node not found --> " << aRet
3124            << endl ;
3125   }
3126   delete theNode ;
3127   delete aPort ;
3128   return aRet ;
3129 }
3130
3131 #define TracePortInOutData 0
3132 //JR 30.03.2005const CORBA::Any * GraphBase::Graph::PortInData( const char* ToNodeName ,
3133 const CORBA::Any GraphBase::Graph::PortInData( const char* ToNodeName ,
3134                                                const char* ToServiceParameterName ) {
3135 //JR 30.03.2005  const CORBA::Any * aRet = new CORBA::Any() ;
3136   CORBA::Any aRet = CORBA::Any() ;
3137   char *theNode ;
3138   char *aPort ;
3139 #if TracePortInOutData
3140   cdebug_in << "GraphBase::Graph::PortInData " << ToNodeName << " "
3141             << ToServiceParameterName << endl ;
3142 #endif
3143   NodePort( ToNodeName , ToServiceParameterName , &theNode , &aPort ) ;
3144
3145   GraphBase::ComputingNode * aNode = GetChangeGraphNode( theNode ) ;
3146
3147   if ( aNode ) {
3148     GraphBase::OutPort *anOutPort = NULL ;
3149     GraphBase::InPort *anInPort = aNode->GetChangeInPort( aPort );
3150     if ( anInPort ) {
3151       anOutPort = anInPort->GetOutPort() ;
3152       if ( anOutPort ) {
3153 #if TracePortInOutData
3154         cdebug << "-->PortInData " << ToNodeName << " " << ToServiceParameterName << " "
3155                << endl ;
3156 #endif
3157         aRet = anOutPort->Value() ;
3158 #if TracePortInOutData
3159         cdebug << "<--PortInData " << ToNodeName << " " << ToServiceParameterName << " " ;
3160         anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
3161         cdebug << endl ;
3162         cdebug << "Graph::PortInData OutPort value " << anOutPort->NodeName() << "("
3163                << anOutPort->PortName() << ") --> InPort " << anInPort->NodeName()
3164                << "(" << anInPort->PortName() << ") " << anInPort->PortStatus() << endl ;
3165 #endif
3166       }
3167       else {
3168         cdebug << "Graph::PortInData GraphBase::Graph::PortInData " << ToNodeName << " "
3169                << ToServiceParameterName << " ERROR no OutPort" << endl ;
3170       }
3171     }
3172     else {
3173       cdebug << "GraphBase::Graph::PortInData " << ToNodeName << " "
3174              << ToServiceParameterName << " ERROR no InPort" << endl ;
3175     }
3176   }
3177   else if ( !strcmp( ToNodeName , Name() ) &&
3178             !strcmp( ToServiceParameterName , "Gate" ) ) {
3179     cdebug << "GraphBase::Graph::PortInData " << ToNodeName << " "
3180            << ToServiceParameterName << " InGate ignored" << endl ;
3181   }
3182   else {
3183     cdebug << "GraphBase::Graph::PortInData " << ToNodeName << " "
3184            << ToServiceParameterName << " ERROR no Node" << endl ;
3185   }
3186   delete theNode ;
3187   delete aPort ;
3188 #if TracePortInOutData
3189   cdebug_out << "GraphBase::Graph::PortInData " << endl ;
3190 #endif
3191   return aRet ;
3192 }
3193
3194 //JR 30.03.2005const CORBA::Any * GraphBase::Graph::PortOutData( const char* FromNodeName ,
3195 const CORBA::Any GraphBase::Graph::PortOutData( const char* FromNodeName ,
3196                                                 const char* FromServiceParameterName ) {
3197 //JR 30.03.2005  const CORBA::Any * aRet = new CORBA::Any() ;
3198   CORBA::Any aRet = CORBA::Any() ;
3199   char *theNode ;
3200   char *aPort ;
3201 #if TracePortInOutData
3202   cdebug_in << "GraphBase::Graph::PortOutData " << FromNodeName << " "
3203             << FromServiceParameterName << endl ;
3204 #endif
3205   NodePort( FromNodeName , FromServiceParameterName , &theNode , &aPort ) ;
3206
3207   GraphBase::ComputingNode * aNode = GetChangeGraphNode( theNode ) ;
3208
3209   if ( aNode ) {
3210     GraphBase::OutPort *anOutPort ;
3211     anOutPort = aNode->GetChangeOutPort( aPort );
3212     if ( anOutPort ) {
3213 #if TracePortInOutData
3214       cdebug << "-->PortOutData " << FromNodeName << " " << FromServiceParameterName << " "
3215              << endl ;
3216 #endif
3217       aRet = anOutPort->Value() ;
3218 #if TracePortInOutData
3219       cdebug << "<--PortOutData " << FromNodeName << " " << FromServiceParameterName << " " ;
3220       anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
3221       cdebug << endl ;
3222 #endif
3223     }
3224     else {
3225       cdebug << "GraphBase::Graph::PortOutData " << FromNodeName << " "
3226              << FromServiceParameterName << " ERROR no OutPort" << endl ;
3227     }
3228   }
3229   else if ( !strcmp( FromNodeName , Name() ) &&
3230             !strcmp( FromServiceParameterName , "Gate" ) ) {
3231     cdebug << "GraphBase::Graph::PortOutData " << FromNodeName << " "
3232            << FromServiceParameterName << " OutGate ignored" << endl ;
3233   }
3234   else {
3235     cdebug << "GraphBase::Graph::PortOutData " << FromNodeName << " "
3236            << FromServiceParameterName << " ERROR no Node" << endl ;
3237   }
3238   delete theNode ;
3239   delete aPort ;
3240 #if TracePortInOutData
3241   cdebug_out << "GraphBase::Graph::PortOutData " << endl ;
3242 #endif
3243   return aRet ;
3244 }
3245
3246 SUPERV::ListOfStrings * GraphBase::Graph::LevelNodes(long aLevel ) {
3247   SUPERV::ListOfStrings_var RetVal = new SUPERV::ListOfStrings;
3248   if ( aLevel >= 0 && aLevel <= _LevelsNumber ) {
3249     int i ;
3250     RetVal->length( _NodesNumber[ aLevel ] + 1 );
3251     for ( i= 0 ; i <= _NodesNumber[ aLevel ] ; i++ ) {
3252       RetVal[i] = CORBA::string_dup( (_SortedNodes[ aLevel ])[ i ]->Name() ) ;
3253     }
3254   }
3255   return ( RetVal._retn() ) ;
3256 }
3257
3258 bool GraphBase::Graph::StartComponent(const int aThread ,
3259                                       const char * aComputerContainer ,
3260                                       const char * ComponentName ,
3261                                       Engines::Container_var & myContainer ,
3262                                       Engines::Component_var & objComponent ) {
3263   cdebug_in << aThread
3264             << " GraphBase::Graph::StartComponent " << aComputerContainer
3265             << " " << ComponentName << endl;
3266   bool RetVal = true ;
3267   objComponent = Engines::Component::_nil() ;
3268   SALOME_LifeCycleCORBA LCC( NamingService() ) ;
3269   try {
3270     objComponent = LCC.FindOrLoad_Component( aComputerContainer ,
3271                                              ComponentName );
3272   }
3273   catch (...) {
3274     RetVal = 0 ;
3275   }
3276   if ( CORBA::is_nil( objComponent ) ) {
3277     cdebug_out << aThread 
3278                << " StartComponent cannot FindOrLoad " << aComputerContainer
3279                << " " << ComponentName << " ERROR" << endl;
3280     RetVal = 0 ;
3281   }
3282   /* asv : 24.01.05 : FindContainer() method does not exist any more.  FindOrLoad_Component()
3283                       starts the container for us.  If it fails to start the container, then it
3284                       returns nil component.  We don't need to check for if the container was 
3285                       successfully started..
3286   else {
3287     myContainer = LCC.FindContainer( aComputerContainer );
3288     if ( CORBA::is_nil( myContainer ) ) {
3289       cdebug_out << aThread
3290                  << " GraphBase::Graph::StartComponent myContainer = LCC.FindContainer( '"
3291                  << aComputerContainer << "' ) Container does not exist ERROR"
3292                  << endl ;
3293       return 0 ;
3294     }
3295   }
3296   */
3297   if ( !RetVal ) {
3298     string anErrorMessage = string( "Error while FindOrLoad_Component " ) +
3299                             string( ComponentName ) + string( " in Container " ) +
3300                             string( aComputerContainer )  ;
3301     SetMessages( anErrorMessage ) ;
3302   }
3303   cdebug_out << aThread << " GraphBase::Graph::StartComponent RetVal " << RetVal << endl;
3304   return RetVal ;
3305 }