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