Salome HOME
Point 2.3 of "SUPERVISOR: Current state - bugs/improvements" :
[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 << ") " << LinkedNodesSize() << " LinkedNodes :"
634             << endl;
635   int i ;
636   bool RetVal = false ;
637   int index = GetGraphNodeIndex( aNodeName ) ;
638   GraphBase::ComputingNode * aNode = GetChangeGraphNode( index ) ;
639   for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
640     cdebug << "         " << i << ". " << LinkedNodes( i ) << endl ;
641   }
642   if ( aNode ) {
643     cdebug << "Graph::RemoveNode " << aNode->GetNodeInPortsSize() << " InPorts " << aNode->GetNodeOutPortsSize()
644            << " OutPorts" << endl ;
645     if ( aNode->GetNodeInPortsSize() ) {
646       for ( i = aNode->GetNodeInPortsSize()-1 ; i >= 0 ; i-- ) {
647         GraphBase::InPort * anInPort = aNode->GetChangeNodeInPort( i ) ;
648         cdebug << "InPort" << i << ". " << aNodeName << "( " << anInPort->PortName() << ") "
649                << anInPort->PortStatus() << " <-- " ;
650         GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
651         if ( anOutPort ) {
652           cdebug << anOutPort->NodeName() << "( " << anOutPort->PortName() << ") " << anOutPort->PortStatus() ;
653         }
654         cdebug << endl ;
655         if ( !anInPort->IsNotConnected() ) {
656           RetVal = true ;
657           if ( anOutPort->IsDataConnected() || anOutPort->IsExternConnected() ) {
658             cdebug << "     Data/Extern" << endl ;
659           }
660           else {
661             GraphBase::ComputingNode * FromNode = GetChangeGraphNode( anOutPort->NodeName() ) ;
662             // asv : 04.11.04 : IsGOTO -> IsOneOfGOTO, I believe that it fixes the bug 7120.
663             if ( !FromNode->IsOneOfGOTONodes() ) {
664               if ( anInPort->IsDataStream() ) {
665                 RetVal = FromNode->RemoveStreamLinkedNode( aNode ) ;
666               }
667               else {
668                 RetVal = FromNode->RemoveLinkedNode( aNode ) ;
669               }
670               if ( !RetVal ) {
671                 cdebug << "anOutPort->RemoveLinkedNode Error RetVal " << RetVal << endl ;
672                 break ;
673               }
674             }
675           }
676           RetVal = anOutPort->RemoveInPort( anInPort ) ;
677           if ( !RetVal ) {
678             cdebug << "anOutPort->RemoveInPort( anInPort ) Error RetVal " << RetVal << endl ;
679             break ;
680           }
681         }
682         else {
683           RetVal = true ;
684         }
685       }
686     }
687     else {
688       RetVal = true ;
689     }
690     if ( RetVal ) {
691       for ( i = aNode->GetNodeOutPortsSize() - 1 ; i >= 0 ; i-- ) {
692         GraphBase::OutPort * anOutPort = aNode->GetChangeNodeOutPort( i ) ;
693         cdebug << "OutPort" << i << ". Remove " << anOutPort->InPortsSize()
694                << " InPortsof OutPort : " << anOutPort->NodeName() << "( " << anOutPort->PortName() << ") "
695                << anOutPort->PortStatus() << " :" << endl ;
696         int j ;
697         for ( j = anOutPort->InPortsSize() - 1 ; j >= 0  ; j-- ) {
698           GraphBase::InPort * anInPort = anOutPort->ChangeInPorts( j ) ;
699           cdebug << "       to InPort" << j << ". " << anInPort->NodeName() << "( " << anInPort->PortName() << ") "
700                  << anInPort->PortStatus() << endl ;
701           if ( !anInPort->IsExternConnected() ) {
702             GraphBase::ComputingNode * ToNode = GetChangeGraphNode( anInPort->NodeName() ) ;
703             RetVal = anInPort->RemoveOutPort() ;
704             if ( !RetVal ) {
705               cdebug << "anOutPort->RemoveOutPort Error RetVal " << RetVal << endl ;
706               break ;
707             }
708             if ( ( aNode->IsGOTONode() && ToNode->IsOneOfInLineNodes() ) ||
709                  ( aNode->IsEndLoopNode() && ToNode->IsLoopNode( ) ) ) {
710             }
711             else if ( anOutPort->IsDataStream() ) {
712               RetVal = aNode->RemoveStreamLinkedNode( ToNode ) ;
713             }
714             else {
715               RetVal = aNode->RemoveLinkedNode( ToNode ) ;
716             }
717             if ( !RetVal ) {
718               cdebug << "anOutPort->RemoveLinkedNode Error RetVal " << RetVal << endl ;
719               break ;
720             }
721             RetVal = anOutPort->RemoveInPort( anOutPort->ChangeInPorts( j ) ) ;
722             if ( !RetVal ) {
723               cdebug << "anOutPort->RemoveInPort( anInPort ) Error RetVal " << RetVal << endl ;
724               break ;
725             }
726           }
727         }
728         if ( !RetVal ) {
729           cdebug << "Error RetVal " << RetVal << endl ;
730           break ;
731         }
732       }
733     }
734     if ( RetVal ) {
735       delete aNode ;
736       _GraphNodesSize -= 1 ;
737       for ( i = index ; i < _GraphNodesSize ; i++ ) {
738         SetGraphNodeIndex( _GraphNodes[ i+1 ]->Name() , i ) ;
739         _GraphNodes[ i ] = _GraphNodes[ i+1 ] ;
740       }
741       _GraphNodes.resize( _GraphNodesSize+1 ) ;
742       _MapOfGraphNodes.erase( aNodeName ) ;
743       RetVal = true ;
744     }
745   }
746   else {
747     cdebug << "Node not found ERROR " << index << endl ;
748   }
749
750   cdebug_out << "GraphBase::Graph::RemoveNode " << RetVal << endl;
751   return RetVal ;
752 }
753
754 bool GraphBase::Graph::AddLink( const char* FromNodeName ,
755                                 const char* FromServiceParameterName ,
756                                 const char* ToNodeName ,
757                                 const char* ToServiceParameterName ) {
758 //                                , const CORBA::Any aValue ) {
759   bool RetVal ;
760 //  int index ;
761   cdebug_in << "GraphBase::Graph::AddLink(" << FromNodeName << "("
762             << FromServiceParameterName << ") ---> " << ToNodeName << "("
763             << ToServiceParameterName << ") , aValue )" << endl;
764
765   GraphBase::ComputingNode *fromNode = GetChangeGraphNode( FromNodeName ) ;
766   GraphBase::ComputingNode *toNode = GetChangeGraphNode( ToNodeName ) ;
767
768   GraphBase::OutPort *fromPort = NULL ;
769   GraphBase::InPort *toPort = NULL ;
770
771   if ( fromNode ) {
772     if ( strcmp( FromServiceParameterName , "InitLoop" ) ) {
773       fromPort = fromNode->GetChangeOutPort( FromServiceParameterName ) ;
774     }
775     else {
776       fromPort = fromNode->GetChangeOutPort( "DoLoop" ) ;
777     }
778     if ( !fromPort ) {
779       cdebug << "ERROR AddLink fromPort " << FromServiceParameterName << " FromNode("
780            << FromNodeName << ") not found." << endl ;
781     }
782   }
783   else {
784     cdebug << "ERROR AddLink FromNode " << FromNodeName << " not found." << endl ;
785   }
786   if ( toNode ) {
787     if ( strcmp( ToServiceParameterName , "InitLoop" ) ) {
788       toPort = toNode->GetChangeInPort( ToServiceParameterName ) ;
789     }
790     else {
791       toPort = toNode->GetChangeInPort( "DoLoop" ) ;
792     }
793     if ( !toPort ) {
794       cdebug << "ERROR AddLink toPort " << ToServiceParameterName << " ToNode("
795              << ToNodeName << ") not found." << endl ;
796     }
797   }
798   else {
799     cdebug << "ERROR AddLink toNode " << ToNodeName << " not found." << endl ;
800   }
801
802   RetVal = AddLink( fromNode , fromPort , toNode , toPort ) ;
803
804   if ( RetVal ) {
805     if ( fromPort->IsGate() && toPort->IsGate() ) {
806       CORBA::Any aValue ;
807       aValue <<= (long ) 1 ;
808       fromPort->Value( aValue ) ;
809     }
810 //    else {
811 //      const CORBA::Any * aDataValue = new CORBA::Any( aValue ) ;
812 //      fromPort->Value( aDataValue ) ;
813 //    }
814 //    fromPort->PortStatus( DataConnected );
815   }
816
817   cdebug_out << "GraphBase::Graph::AddLink " << RetVal << endl;
818   return RetVal ;
819 }
820
821 bool GraphBase::Graph::AddLink( GraphBase::ComputingNode *fromNode ,
822                                 GraphBase::OutPort *fromPort ,
823                                 GraphBase::ComputingNode *toNode ,
824                                 GraphBase::InPort *toPort ) {
825 //  bool RetVal ;
826
827   if ( !fromNode ) {
828     cdebug << "ERROR AddLink fromNode not found." << endl ;
829     return false ;
830   }
831   if ( !fromPort ) {
832     cdebug << "ERROR AddLink fromPort not found." << endl ;
833     return false ;
834   }
835
836   if ( !toNode ) {
837     cdebug << "ERROR AddLink toNode not found." << endl ;
838     return false ;
839   }
840   if ( !toPort ) {
841     cdebug << "ERROR AddLink toPort not found." << endl ;
842     return false ;
843   }
844   if ( ( fromPort->IsDataStream() && !toPort->IsDataStream() ) ||
845        ( !fromPort->IsDataStream() && toPort->IsDataStream() ) ) {
846     cdebug << "AddLink fromPort/toPort Stream/Flow. ERROR" << endl ;
847     return false ;
848   }
849   if ( fromPort->IsDataStream() && fromPort->Dependency() == SALOME_ModuleCatalog::DATASTREAM_TEMPORAL &&
850        toPort->Dependency() == SALOME_ModuleCatalog::DATASTREAM_ITERATIVE ) {
851     cdebug << "AddLink fromPort/toPort Stream DATASTREAM_TEMPORAL --> DATASTREAM_ITERATIVE. ERROR" << endl ;
852     return false ;
853   }
854
855   cdebug_in << "GraphBase::Graph::AddLink(" << fromNode->Name() << "("
856             << fromPort->PortName() << " " << fromPort->PortStatus() << ") ---> " << toNode->Name() << "("
857             << toPort->PortName() << " " << toPort->PortStatus() << ") )" << endl;
858   if ( fromPort->IsDataConnected() || fromPort->IsExternConnected() ) {
859     if ( !fromPort->RemoveInPort() ) { // There is only one ===> RemoveOutPort()
860       cdebug_out << "GraphBase::Graph::AddLink(" << fromNode->Name() << "("
861                  << fromPort->PortName() << " " << fromPort->PortStatus() << ") RemoveInPort ERROR " << endl ;
862       return false ;
863     }
864   }
865   if ( toPort->IsDataConnected() || toPort->IsExternConnected() ) {
866     if ( !toPort->GetOutPort()->RemoveInPort() ) { // There is only one ===> RemoveOutPort()
867       cdebug_out << "GraphBase::Graph::AddLink(" << toNode->Name() << "("
868                  << toPort->PortName() << " " << toPort->PortStatus() << ") RemoveInPort ERROR " << endl ;
869       return false ;
870     }
871   }
872   else if ( toPort->IsPortConnected() && !toNode->IsEndSwitchNode() ) {
873     if ( !RemoveLink( toPort->GetOutPort()->NodeName() ,
874                       toPort->GetOutPort()->PortName() ,
875                       toNode->Name() , toPort->PortName() ) ) {
876       cdebug_out << "RemoveLink(AddLink) toPort->GetOutPort()->NodeName() RemoveLink Error." << endl ;
877       return false ;
878     }
879   }
880
881   if ( !fromNode->IsDataFlowNode() && !fromNode->IsDataStreamNode() &&
882        !toNode->IsDataFlowNode() && !toNode->IsDataStreamNode() &&
883        toPort->GetOutPort() ) {
884     if ( !strcmp( toPort->GetOutPort()->NodePortName() ,
885                   fromPort->NodePortName() ) ) {
886       cdebug << "Link already exists" << endl ;
887       cdebug_out << "GraphBase::Graph::AddLink 1" << endl;
888       return true ;
889     }
890     else if ( toPort->IsDataConnected() || toPort->IsExternConnected() ) {
891       toPort->GetOutPort()->RemoveInPort( toPort ) ; //dbg
892     }
893     else if ( fromNode->IsGOTONode() ) {
894       if ( !RemoveLink( toPort->GetOutPort()->NodeName() ,
895                         toPort->GetOutPort()->PortName() ,
896                         toNode->Name() , toPort->PortName() ) ) {
897         cdebug << "RemoveLink(AddLink) Error."
898                << endl ;
899         cdebug_out << "GraphBase::Graph::AddLink" << endl;
900         return false ;
901       }
902       if ( fromPort->InPortsSize() ) {
903         if ( !RemoveLink( fromNode->Name() , fromPort->PortName() ,
904                           fromPort->ChangeInPorts(0)->NodeName() ,
905                           fromPort->ChangeInPorts(0)->PortName() ) ) {
906           cdebug << "RemoveLink(AddLink) fromNode->IsGOTONode Error." << endl ;
907           cdebug_out << "GraphBase::Graph::AddLink" << endl;
908           return false ;
909         }
910       }
911     }
912     else if ( !toNode->IsEndSwitchNode() ||
913               ( toNode->IsEndSwitchNode() && toPort->IsGate() ) ) {
914       if ( !RemoveLink( fromNode->Name() , fromPort->PortName() ,
915                         toNode->Name() , toPort->PortName() ) ) {
916         cdebug << "RemoveLink(AddLink) toNode->IsEndSwitchNode Error." << endl ;
917         cdebug_out << "GraphBase::Graph::AddLink" << endl;
918         return false ;
919       }
920     }
921   }
922   else if ( fromNode->IsGOTONode() && fromPort->InPortsSize() ) {
923     if ( !RemoveLink( fromNode->Name() , fromPort->PortName() ,
924                       fromPort->ChangeInPorts(0)->NodeName() ,
925                       fromPort->ChangeInPorts(0)->PortName() ) ) {
926       cdebug << "RemoveLink(AddLink) fromNode->IsGOTONode Error." << endl ;
927       cdebug_out << "GraphBase::Graph::AddLink" << endl;
928       return false ;
929     }
930   }
931   else if ( ( fromNode->IsDataFlowNode() || fromNode->IsDataStreamNode() ) &&
932        ( toPort->IsDataConnected() || toPort->IsExternConnected() ) ) {
933     fromPort->RemoveInPort( toPort ) ; //dbg
934   }
935   else if ( ( toNode->IsDataFlowNode() || toNode->IsDataStreamNode() ) &&
936        ( fromPort->IsDataConnected() || fromPort->IsExternConnected() ) ) {
937     fromPort->RemoveInPort() ; // There is only one
938   }
939
940
941   if ( toNode->IsEndSwitchNode() && !toPort->IsGate() ) {
942 //    if ( !toPort->IsEndSwitch() || !fromPort->AddInPort( toPort ) ) {
943     if ( !fromPort->AddInPort( toPort ) ) {
944       cdebug << "toNode->IsEndSwitchNode() : !fromPort->AddInPort( toPort ) AddLink Error."
945              << endl ;
946       cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
947       return false ;
948     }
949     if ( !toPort->IsDataStream() ) {
950       toPort->Kind( SUPERV::EndSwitchParameter ) ;
951     }
952   }
953   else if ( !fromPort->AddInPort( toPort ) ) { // --> MapOfInports in the OutPort
954     cdebug << "!fromPort->AddLink Error." << endl ;
955     cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
956     return false ;
957   }
958
959   if ( fromNode->IsGOTONode() && ( !fromPort->IsGate() || !toPort->IsGate() ||
960        toNode->IsEndLoopNode() || toNode->IsEndSwitchNode() ) ) {
961     cdebug << "toPort->AddLink Error( fromNode->IsGOTONode() && toNode->IsEndInLineNode() )." << endl ;
962     cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
963     return false ;
964   }
965   else if ( !fromNode->IsSwitchNode() && fromPort->IsParam() && toPort->IsGate() ) {
966     cdebug << "toPort->AddLink Error( fromPort->IsParam() && toPort->IsGate())." << endl ;
967     cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
968     return false ;
969   }
970   else if ( !toNode->IsEndSwitchNode() && !toNode->IsEndLoopNode() ) {
971     if ( !toPort->AddOutPort( fromPort ) ) { // --> Unique OutPort of the InPort
972       cdebug << "toPort->AddLink Error." << endl ;
973       cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
974       return false ;
975     }
976   }
977   else {
978     toPort->AddOutPort( fromPort ) ;
979   }
980
981   if ( ( fromNode->IsGOTONode() && toNode->IsOneOfInLineNodes() ) ||
982        ( fromNode->IsEndLoopNode() && toNode->IsLoopNode() ) ) {
983     cdebug << "AddLink fromPort->PortStatus( PortConnected ) "
984            << "GOTONode/EndLoopNode-->InLineNode/LoopNode/SwitchNode "
985            << fromNode->Name() << " " << fromPort->PortName()
986            << " InLineNode/LoopNode_ConnectedInPortsNumber "
987            << toNode->ConnectedInPortsNumber() << endl;
988     if ( fromNode->IsGOTONode() ) {
989       fromPort->Kind( SUPERV::GOTOParameter ) ;
990     }
991     fromPort->PortStatus( PortConnected ); // GOTO - Loop
992   }
993   else if ( fromNode->IsDataFlowNode() || fromNode->IsDataStreamNode() ) {
994     cdebug << "AddLink IsDataFlow/StreamNode fromPort->PortStatus( DataConnected ) : "
995            << fromNode->Name() << " " << fromPort->PortName() << endl ;
996     fromPort->PortStatus( ExternConnected );
997   }
998   else if ( toNode->IsDataFlowNode() || toNode->IsDataStreamNode() ) {
999     cdebug << "AddLink IsDataFlow/StreamNode fromPort->PortStatus( ExternConnected ) : "
1000            << fromNode->Name() << " " << fromPort->PortName() << endl ;
1001     fromPort->PortStatus( ExternConnected ) ;
1002   }
1003   else {
1004     cdebug << "AddLink fromPort->PortStatus( PortConnected ) & fromNode->toNode "
1005            << fromNode->Name() << " " << fromPort->PortName() << " "
1006            << fromPort->Kind() << " OldPortStatus " << fromPort->PortStatus() << " -> " << toNode->Name()
1007            << " " << " " << toPort->PortName() << " " << toPort->Kind() << endl;
1008     fromPort->PortStatus( PortConnected );
1009     if ( fromPort->IsDataStream() && toPort->IsDataStream() ) {
1010       fromNode->AddStreamLinkedNode( toNode ) ;
1011     }
1012     else {
1013       fromNode->AddLinkedNode( toNode ) ;
1014     }
1015   }
1016   if ( fromNode->IsSwitchNode() ) {
1017     if ( !fromPort->IsDataStream() ) {
1018       if ( fromPort->IsInLine() && toPort->IsGate() && !toNode->IsEndSwitchNode() ) {
1019         fromPort->Kind( SUPERV::SwitchParameter ) ;
1020       }
1021       else if ( !fromPort->IsGate() && !toPort->IsGate() ){
1022         fromPort->Kind( SUPERV::InLineParameter ) ;
1023       }
1024     }
1025     if ( fromPort->IsGate() && !toNode->IsEndSwitchNode() ) {
1026       GraphBase::InLineNode * anEndSwitchNode ;
1027       anEndSwitchNode = ((GraphBase::SwitchNode * ) fromNode)->CoupledNode() ;
1028       GraphBase::InPort * anInPort = anEndSwitchNode->GetChangeNodeInGate() ;
1029       GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1030       if ( anOutPort && !strcmp( fromNode->Name() , anOutPort->NodeName() ) &&
1031            !strcmp( fromPort->PortName() , anOutPort->PortName() ) &&
1032            anOutPort->IsGate() ) {
1033         if ( !RemoveLink( fromNode->Name() , anOutPort->PortName() ,
1034                           anEndSwitchNode->Name() ,
1035                           anInPort->PortName() ) ) {
1036           cdebug << "AddLink Error Removelink ( Switch , Default , EndSwitch , Default )"
1037                  << endl ;
1038           cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1039           return false ;
1040         }
1041       }
1042     }
1043   }
1044 //  cdebug << fromNode->ServiceName() << " " << toNode->ServiceName() << endl ;
1045   cdebug_out << "GraphBase::Graph::AddLink 1" << endl;
1046   return true ;
1047 }
1048
1049 bool GraphBase::Graph::RemoveLink( const char* FromNodeName ,
1050                                    const char* FromServiceParameterName ,
1051                                    const char* ToNodeName ,
1052                                    const char* ToServiceParameterName ) {
1053   cdebug_in << "GraphBase::Graph::RemoveLink from " << FromNodeName << "(" << FromServiceParameterName << ")"
1054             << " to " << ToNodeName << "(" << ToServiceParameterName << ")" << endl;
1055   bool RetVal = false ;
1056   GraphBase::ComputingNode * toNode = GetChangeGraphNode( ToNodeName ) ;
1057   if ( toNode ) {
1058     GraphBase::InPort * anInPort = toNode->GetChangeInPort( ToServiceParameterName ) ;
1059     if ( anInPort && ( anInPort->IsPortConnected() ||
1060                        anInPort->IsDataConnected() ||
1061                        anInPort->IsExternConnected() ) ) {
1062       GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1063       RetVal = anOutPort->RemoveInPort( anInPort ) ; // ==> :
1064 //      anInPort->RemoveOutPort() ;
1065       const char * FromNodeName = anOutPort->NodeName() ;
1066       GraphBase::ComputingNode * fromNode = GetChangeGraphNode( FromNodeName ) ;
1067       if ( RetVal ) {
1068         if ( fromNode ) {
1069           if ( anInPort->IsDataStream() ) {
1070             fromNode->RemoveStreamLinkedNode( toNode ) ;
1071           }
1072           else {
1073             fromNode->RemoveLinkedNode( toNode ) ;
1074           }
1075         }
1076         if ( fromNode->IsSwitchNode() && !anOutPort->IsGate() && !toNode->IsEndSwitchNode() ) {
1077           anOutPort->Kind( SUPERV::InLineParameter ) ;
1078         }
1079       }
1080     }
1081   }
1082   cdebug_out << "GraphBase::Graph::RemoveLink " << RetVal << endl;
1083   return RetVal ;
1084 }
1085
1086 bool GraphBase::Graph::GetLink(const char* ToNodeName ,
1087                                const char* ToServiceParameterName ,
1088                                char** FromNodeName ,
1089                                char** FromServiceParameterName ) {
1090 //  cdebug_in << "GraphBase::Graph::GetLink " << ToNodeName << "("
1091 //            << ToServiceParameterName << ")" << endl;
1092   bool RetVal = false ;
1093   GraphBase::ComputingNode * toNode = GetChangeGraphNode( ToNodeName ) ;
1094   if ( toNode ) {
1095     GraphBase::InPort * anInPort = toNode->GetChangeInPort( ToServiceParameterName ) ;
1096     if ( anInPort && !anInPort->IsNotConnected() ) {
1097       GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1098       *FromNodeName = my_strdup( anOutPort->NodeName() ) ;
1099       *FromServiceParameterName = my_strdup( anOutPort->PortName() ) ;
1100       RetVal = true ;
1101     }
1102     else {
1103       cdebug << "GraphBase::Graph::GetLink ERROR no InPort or NotConnected " << ToNodeName
1104              << " " << ToServiceParameterName << " " << RetVal << endl;
1105     }
1106   }
1107   else {
1108     cdebug << "GraphBase::Graph::GetLink ERROR no Node " << ToNodeName << " " << RetVal
1109            << endl;
1110   }
1111 //  cdebug_out << "GraphBase::Graph::GetLink " << RetVal << endl;
1112   return RetVal ;
1113 }
1114
1115 bool GraphBase::Graph::AddInputData( const char* ToNodeName ,
1116                                      const char* ToServiceParameterName ,
1117                                      const CORBA::Any aValue ) {
1118   bool RetVal = false ;
1119   cdebug_in << "GraphBase::Graph::AddInputData(" << ToNodeName << ","
1120             << ToServiceParameterName << " , Any " ;
1121   switch (aValue.type()->kind()) {
1122     case CORBA::tk_string:
1123       char * t;
1124       aValue >>= t;
1125       cdebug << t << " (string) " ;
1126       break;
1127     case CORBA::tk_double:
1128       double d;
1129       aValue >>= d;
1130       cdebug << d << " (double) " ;
1131       break;
1132     case CORBA::tk_long:
1133       long l;
1134       aValue >>= l;
1135       cdebug << l << " (long) " ;
1136       break;
1137     case CORBA::tk_objref:
1138       cdebug << "(object reference) " ;
1139       break;
1140     default:
1141       cdebug << "(other(tk_string(" << CORBA::tk_string << "),tk_double(" << CORBA::tk_double << "),tk_long("
1142              << CORBA::tk_long << "),tk_objref)(" << CORBA::tk_objref << ")) ERROR : " << aValue.type()->kind() ;
1143       break;
1144     }
1145   cdebug << " ) in Graph " << Name() << endl;
1146  
1147   GraphBase::ComputingNode *toNode ;
1148   GraphBase::InPort *toPort ;
1149   char *aNodeName ;
1150   char *aPortName ;
1151   NodePort( ToNodeName , ToServiceParameterName , &aNodeName , &aPortName ) ;
1152   toNode = GetChangeGraphNode( aNodeName ) ;
1153   cdebug << "in Graph " << Name() << " aNodeName " << aNodeName << " aPortName " << aPortName << endl;
1154   if ( toNode ) {
1155     toPort = toNode->GetChangeInPort( aPortName ) ;
1156     if ( toPort && !toPort->IsDataConnected() ) {
1157       toPort->RemoveOutPort() ;
1158     }
1159   }
1160   else {
1161     toPort = NULL ;
1162   }
1163
1164   int i ;
1165   for ( i = 0 ; i < GetNodeOutDataNodePortsSize() ; i++ ) {
1166     cdebug << "Graph::AddInputData In" << i << " " << *GetNodeOutDataNodePort(i) << endl ;
1167   }
1168   for ( i = 0 ; i < GetNodeInDataNodePortsSize() ; i++ ) {
1169     cdebug << "Graph::AddInputData Out" << i << " " << *GetNodeInDataNodePort(i) << endl ;
1170   }
1171
1172   if ( toNode && toPort ) {
1173     GraphBase::OutPort *fromDataNodePort = NULL ;
1174     fromDataNodePort = GraphBase::DataNode::GetChangeInDataNodePort( toPort->NodePortName() ) ;
1175     if ( fromDataNodePort && fromDataNodePort->GetInPort( toPort ) ) {
1176       fromDataNodePort->RemoveInPort( toPort ) ;
1177     }
1178     cdebug << "Try AddLink " << toPort->NodePortName() << " : " << Name() << "( "
1179            << fromDataNodePort->PortName() << " ) -->" << toNode->Name() << "( "
1180            << toPort->PortName() << " )" << endl ;
1181     RetVal = AddLink( (GraphBase::ComputingNode * ) this , fromDataNodePort ,
1182                       toNode , toPort ) ;
1183     if ( RetVal ) {
1184       fromDataNodePort->Value( aValue ) ;
1185       fromDataNodePort->PortStatus( DataConnected ) ;
1186     }
1187   }
1188   else {
1189     cdebug << "ERROR Node and/or Port not found : " << aNodeName << " " << aPortName << endl ;
1190   }
1191   delete aNodeName ;
1192   delete aPortName ;
1193
1194   cdebug_out << "GraphBase::Graph::AddInputData " << RetVal << endl;
1195   return RetVal ;
1196 }
1197
1198 // Used in the Executor in order to change an Input Value and ReRun
1199 bool GraphBase::Graph::ChangeInputData( const char * ToNodeName ,
1200                                         const char * ToServiceParameterName ,
1201                                         const CORBA::Any aValue ) {
1202   bool RetVal = false ;
1203   cdebug_in << "GraphBase::Graph::ChangeInputData( '" << ToNodeName << "' , '"
1204             << ToServiceParameterName << "' , Any " ;
1205   switch (aValue.type()->kind()) {
1206     case CORBA::tk_string:
1207       char * t;
1208       aValue >>= t;
1209       cdebug << t << " (string) " ;
1210       break;
1211     case CORBA::tk_double:
1212       double d;
1213       aValue >>= d;
1214       cdebug << d << " (double) " ;
1215       break;
1216     case CORBA::tk_long:
1217       long l;
1218       aValue >>= l;
1219       cdebug << l << " (long) " ;
1220       break;
1221     case CORBA::tk_objref:
1222       cdebug << "(object reference) " ;
1223       break;
1224     default:
1225       cdebug << "(other(tk_string,tk_double,tk_long,tk_objref)) ERROR";
1226       break;
1227     }
1228   cdebug << " ) in Graph " << Name() << endl;
1229
1230   GraphBase::ComputingNode * toNode ;
1231   GraphBase::InPort * toPort = NULL ;
1232   char * aNodeName ;
1233   char * aPortName ;
1234   NodePort( ToNodeName , ToServiceParameterName , &aNodeName , &aPortName ) ;
1235   toNode = GetChangeGraphNode( aNodeName ) ;
1236   cdebug << "in Graph " << Name() << " aNodeName " << aNodeName << " aPortName " << aPortName << endl;
1237   if ( toNode ) {
1238     toPort = toNode->GetChangeInPort( aPortName ) ;
1239     if ( toPort && toPort->IsDataConnected() ) {
1240       GraphBase::OutPort * fromPort = toPort->GetOutPort();
1241       if ( fromPort ) {
1242         RetVal = true ;
1243         fromPort->Value( aValue ) ;
1244         fromPort->PortStatus( DataConnected ) ;
1245         toPort->State( SUPERV::ReadyState ) ;
1246       }
1247       else {
1248         cdebug << "ERROR ChangeInputData fromPort not found" << endl ;
1249       }
1250     }
1251     else {
1252       cdebug << "ERROR ChangeInputData toPort not found" << endl ;
1253     }
1254   }
1255   else {
1256     cdebug << "ERROR ChangeInputData Node not found : " << ToNodeName << endl ;
1257   }
1258
1259   cdebug_out << "GraphBase::Graph::ChangeInputData" << endl;
1260   return RetVal ;
1261 }
1262
1263 // To restore InputData in CreateService
1264 bool GraphBase::Graph::AddInputData( const char* ToNodeName ,
1265                                      const char* ToServiceParameterName ,
1266                                      const CORBA::Any ** aValue ) {
1267   bool RetVal = false ;
1268   cdebug_in << "GraphBase::Graph::AddInputData( " << ToNodeName << " , "
1269             << ToServiceParameterName << ", **Any " ;
1270   const CORBA::Any theValue = **aValue ;
1271   switch (theValue.type()->kind()) {
1272     case CORBA::tk_string:
1273       char * t;
1274       theValue >>= t;
1275       cdebug << t << " (string) " ;
1276       break;
1277     case CORBA::tk_double:
1278       double d;
1279       theValue >>= d;
1280       cdebug << d << " (double) " ;
1281       break;
1282     case CORBA::tk_long:
1283       long l;
1284       theValue >>= l;
1285       cdebug << l << " (long) " ;
1286       break;
1287     case CORBA::tk_objref:
1288       cdebug << "(object reference) " ;
1289       break;
1290     default:
1291       cdebug << "(other(tk_string,tk_double,tk_long,tk_objref)) ERROR";
1292       break;
1293     }
1294   cdebug << ") of Graph " << Name() << endl;
1295
1296   GraphBase::ComputingNode *toNode = GetChangeGraphNode( ToNodeName ) ;
1297
1298   if ( toNode ) {
1299     GraphBase::InPort *toPort = NULL ;
1300     GraphBase::OutPort *fromDataNodePort = NULL ;
1301     toPort = toNode->GetChangeInPort( ToServiceParameterName ) ;
1302     fromDataNodePort = GraphBase::DataNode::GetChangeInDataNodePort( toPort->NodePortName() ) ;
1303     cdebug << "Try AddLink " << Name() << "( " << fromDataNodePort << " ) -->"
1304            << toNode->Name() << "( " << toPort->PortName() << " )" << endl ;
1305     RetVal = AddLink( (GraphBase::ComputingNode * ) this , fromDataNodePort ,
1306                       toNode , toPort ) ;
1307     if ( RetVal ) {
1308       fromDataNodePort->Value( aValue ) ;
1309       fromDataNodePort->PortStatus( DataConnected ) ;
1310     }
1311   }
1312   else {
1313     cdebug << "ERROR Node not found " << ToNodeName << " ERROR. Known nodes :" << endl ;
1314     map< string , int >::iterator aMapOfGraphNodesIterator ;
1315     int i = 0 ;
1316     for ( aMapOfGraphNodesIterator = _MapOfGraphNodes.begin() ;
1317           aMapOfGraphNodesIterator != _MapOfGraphNodes.end() ; aMapOfGraphNodesIterator++ ) {
1318       cdebug << "MapOfGraphNodes " << i++ << " " << aMapOfGraphNodesIterator->first << " --> "
1319              << aMapOfGraphNodesIterator->second << endl ;
1320     }
1321   }
1322
1323   cdebug_out << "GraphBase::Graph::AddInputData " << RetVal << endl;
1324   return RetVal ;
1325 }
1326
1327 bool GraphBase::Graph::AddOutputData( const char* FromNodeName ,
1328                                       const char* FromServiceParameterName ,
1329                                       const CORBA::Any aValue ) {
1330   bool RetVal = true ;
1331   cdebug_in << "GraphBase::Graph::AddOutputData(" << FromNodeName << ","
1332             << FromServiceParameterName << ")" << endl;
1333   GraphBase::ComputingNode *fromNode = GetChangeGraphNode( FromNodeName ) ;
1334
1335   GraphBase::OutPort *anOutPort = NULL ;
1336
1337   if ( fromNode ) {
1338     anOutPort = fromNode->GetChangeOutPort( FromServiceParameterName ) ;
1339 //    toDataNodePort = GraphBase::DataNode::GetChangeOutDataNodePort( fromPort->NodePortName() ) ;
1340 //    RetVal = AddLink( fromNode , fromPort ,
1341 //                      (GraphBase::ComputingNode * ) this , toDataNodePort ) ;
1342     anOutPort->Value( aValue ) ;
1343     anOutPort->State(  SUPERV::ReadyState ) ;
1344     anOutPort->Done( true ) ;
1345     cdebug << *anOutPort ;
1346 #ifdef _DEBUG_
1347     anOutPort->StringValue( *_fdebug ) ;
1348 #endif
1349     cdebug << endl ;
1350   }
1351   else {
1352     cdebug << "ERROR Node not found" << endl ;
1353     RetVal = false ;
1354   }
1355   cdebug_out << "GraphBase::Graph::AddOutputData " << RetVal << endl;
1356   return RetVal ;
1357 }
1358
1359 map< string , GraphBase::Service * > GraphBase::Graph::MapOfServiceNames() {
1360                                            return _MapOfServiceNames ; }
1361
1362 GraphBase::Service * GraphBase::Graph::GetServiceOfMap( char * name ) {
1363   return _MapOfServiceNames[ name ] ;
1364 }
1365
1366 bool GraphBase::Graph::SetServiceOfMap( GraphBase::Service * aService ) {
1367   GraphBase::Service * theService = _MapOfServiceNames[ aService->ServiceName() ] ;
1368   if ( theService ) {
1369     cdebug << "SetServiceOfMap of " << aService->ServiceName()
1370            << " already in MapOfServiceNames : erase" << endl ;
1371     _MapOfServiceNames.erase( aService->ServiceName() ) ;
1372   }
1373   _MapOfServiceNames[ (char * ) aService->ServiceName() ] = aService ;
1374   cdebug << "SetServiceOfMap of " << aService->ServiceName() << " done" << endl ;
1375   return true ;
1376 }
1377
1378 int GraphBase::Graph::GetServiceNameNumber( SALOME_ModuleCatalog::Service aService ) {
1379   GraphBase::Service * theService = _MapOfServiceNames[ (char * ) aService.ServiceName ] ;
1380   if ( theService == NULL ) {
1381     return 1 ;
1382   }
1383   return theService->NewInstance() ;
1384 }
1385
1386 void GraphBase::Graph::SetGraphPorts() {
1387   cdebug_in << "GraphBase::Graph::SetGraphPorts fill ports of Graph" << endl;
1388   int i ;
1389   for ( i = 0 ; i < GetNodeInDataNodePortsSize() ; i++ ) {
1390     GraphBase::OutPort * anOutPort = GetChangeNodeInDataNodePort( i ) ;
1391     cdebug << "SetGraphPorts Out" << i << " " << anOutPort->PortName() << " " << anOutPort->PortType()
1392            << " " << anOutPort->Kind() << " " << anOutPort->PortStatus() << " " << anOutPort->State() << endl ;
1393     if ( !anOutPort->IsGate() ) {
1394       anOutPort->PortStatus( ExternConnected ) ;
1395     }
1396   }
1397   for ( i = 0 ; i < GetNodeOutDataNodePortsSize() ; i++ ) {
1398     GraphBase::InPort * anInPort = GetChangeNodeOutDataNodePort( i ) ;
1399     cdebug << "SetGraphPorts In" << i << " " << anInPort->PortName() << " " << anInPort->PortType()
1400            << " " << anInPort->Kind() << " " << anInPort->PortStatus() << " " << anInPort->State() << endl ;
1401     if ( !anInPort->IsGate() ) {
1402       GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1403       anOutPort->PortStatus( ExternConnected ) ;
1404     }
1405   }
1406   cdebug_out << "GraphBase::Graph::SetGraphPorts" << endl;
1407 }
1408
1409 bool GraphBase::Graph::CreateService() {
1410   cdebug_in << "GraphBase::Graph::CreateService " << Name() << " GraphMacroLevel : " << GraphMacroLevel() << endl;
1411   bool RetVal = true ;
1412   SALOME_ModuleCatalog::Service aService ;
1413   int i , j ;
1414   GraphBase::ComputingNode * aToNode ;
1415   int dostore ;
1416   int innbr = 0 ;
1417   int instreamnbr = 0 ;
1418   int outnbr = 0 ;
1419   int outstreamnbr = 0 ;
1420   vector< SUPERV::KindOfPort > InPortsKind ;
1421   vector< SALOME_ModuleCatalog::DataStreamDependency > InDataStreamDependency ;
1422   vector< SUPERV::KindOfSchema > InKindOfSchema ;
1423   vector< SUPERV::KindOfInterpolation > InKindOfInterpolation ;
1424   vector< SUPERV::KindOfExtrapolation > InKindOfExtrapolation ;
1425   vector< SUPERV::KindOfPort > OutPortsKind ;
1426   vector< SALOME_ModuleCatalog::DataStreamDependency > OutDataStreamDependency ;
1427   vector< long > OutNumberOfValues ;
1428 //  if ( GraphMacroLevel() == 0 ) {
1429     for ( dostore = 0 ; dostore <= 2 ; dostore++ ) {
1430       if ( dostore == 1 ) {
1431         aService.ServiceName = Name() ;
1432         aService.ServiceinParameter.length( 0 ) ;
1433         aService.ServiceinParameter.length( innbr ) ;
1434         aService.ServiceoutParameter.length( 0 ) ;
1435         aService.ServiceoutParameter.length( outnbr ) ;
1436         InPortsKind.resize( innbr ) ;
1437         InDataStreamDependency.resize( innbr ) ;
1438         InKindOfSchema.resize( innbr ) ;
1439         InKindOfInterpolation.resize( innbr ) ;
1440         InKindOfExtrapolation.resize( innbr ) ;
1441         OutPortsKind.resize( outnbr ) ;
1442         OutDataStreamDependency.resize( outnbr ) ;
1443         OutNumberOfValues.resize( outnbr ) ;
1444       }
1445       else if ( dostore == 2 ) {
1446         cdebug << "GraphBase::Graph::CreateService ->DataService innbr " << innbr
1447                << " instreamnbr " << instreamnbr << " outnbr " << outnbr
1448                << " outstreamnbr " << outstreamnbr << endl ;
1449         DataService( _Orb , aService , Graph_prof_debug() , Graph_fdebug() ) ;
1450         aService.ServiceinParameter.length( innbr + instreamnbr ) ;
1451         aService.ServiceoutParameter.length( outnbr + outstreamnbr ) ;
1452         InPortsKind.resize( innbr + instreamnbr ) ;
1453         InDataStreamDependency.resize( innbr + instreamnbr ) ;
1454         InKindOfSchema.resize( innbr + instreamnbr ) ;
1455         InKindOfInterpolation.resize( innbr + instreamnbr ) ;
1456         InKindOfExtrapolation.resize( innbr + instreamnbr ) ;
1457         OutPortsKind.resize( outnbr + outstreamnbr ) ;
1458         OutDataStreamDependency.resize( outnbr + outstreamnbr ) ;
1459         OutNumberOfValues.resize( outnbr + outstreamnbr ) ;
1460       }
1461       if ( dostore == 0 ) {
1462         innbr = 0 ;
1463         instreamnbr = 0 ;
1464         outnbr = 0 ;
1465         outstreamnbr = 0 ;
1466       }
1467       if ( dostore == 1 ) {
1468         innbr = 0 ;
1469         outnbr = 0 ;
1470       }
1471       for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1472         aToNode = GraphNodes( i ) ;
1473         for ( j = 0 ; j < aToNode->GetNodeInPortsSize() ; j++ ) {
1474           GraphBase::InPort *anInPort = aToNode->GetChangeNodeInPort(j) ;
1475           bool isfromcouplednode = false ;
1476           if ( !anInPort->IsNotConnected() ) {
1477             const char * aFromNodeName = anInPort->GetOutPort()->NodeName() ;
1478             GraphBase::ComputingNode * aFromNode = GetChangeGraphNode( aFromNodeName ) ;
1479             cdebug << "GraphBase::Graph::CreateService aFromNodeName " << aFromNodeName << " aToNode "
1480                    << aToNode->Name() << " InPort" << j << " " << anInPort->PortName() << endl ;
1481             if ( aFromNode && aFromNode->IsEndLoopNode() &&
1482                  ((GraphBase::EndOfLoopNode * ) aFromNode)->CoupledNode() == aToNode ) {
1483               isfromcouplednode = true ;
1484             }
1485           }
1486           if ( !anInPort->IsGate() && !anInPort->IsLoop() &&
1487                ( !anInPort->IsPortConnected() ||
1488                  ( anInPort->IsPortConnected() && isfromcouplednode ) ) ) {
1489             if ( dostore == 0 ) {
1490               cdebug << "CreateService " << aToNode->Name() << " Input port "
1491                      << anInPort->PortName() << " " << anInPort->Kind() << " " << anInPort->PortStatus() ;
1492               if ( anInPort->GetOutPort() ) {
1493                 cdebug << "DataConnected from " <<  *(anInPort->GetOutPort() ) ;
1494               }
1495               cdebug << endl ;
1496               if ( anInPort->IsDataStream() ) {
1497                 instreamnbr += 1 ;
1498               }
1499               else {
1500                 innbr += 1 ;
1501               }
1502             }
1503             else if ( ( dostore == 1 && !anInPort->IsDataStream() ) ||
1504                       ( dostore == 2 && anInPort->IsDataStream() ) ) {
1505               aService.ServiceinParameter[innbr].Parametertype = CORBA::string_dup( anInPort->PortType() ) ;
1506               aService.ServiceinParameter[innbr].Parametername = CORBA::string_dup( anInPort->NodePortName() ) ;
1507               InPortsKind[ innbr ] = anInPort->Kind() ;
1508               InDataStreamDependency[ innbr ] = anInPort->Dependency() ;
1509               if ( dostore == 2 && anInPort->IsDataStream() ) {
1510                 ((GraphBase::InDataStreamPort * ) anInPort)->Params( InKindOfSchema[ innbr ] ,
1511                                                                      InKindOfInterpolation[ innbr ] ,
1512                                                                      InKindOfExtrapolation[ innbr ] ) ;
1513               }
1514               cdebug << "In" << innbr << " " << aService.ServiceinParameter[ innbr ].Parametername << " "
1515                      << anInPort->Kind() << " " << anInPort->PortStatus() << endl ;
1516               innbr += 1 ;
1517             }
1518           }
1519           else if ( dostore == 0 ) {
1520             cdebug << "CreateService " << aToNode->Name() << " Input port " << anInPort->PortName()
1521                    << " " << anInPort->PortStatus() ;
1522             if ( anInPort->IsPortConnected() ) {
1523               cdebug << " is connected " ;
1524             }
1525             else {
1526               cdebug << " is NOT connected " ;
1527             }
1528             if ( anInPort->IsGate() ) {
1529               cdebug << " IsGate " ;
1530             }
1531             if ( anInPort->GetOutPort() ) {
1532               cdebug << "DataConnected from " <<  *(anInPort->GetOutPort()) ;
1533             }
1534             else {
1535               cdebug << "NOT DataConnected" ;
1536             }
1537             cdebug << endl ;
1538           }
1539         }
1540         GraphBase::ComputingNode * aFromNode = aToNode ;
1541         for ( j = 0 ; j < aFromNode->GetNodeOutPortsSize() ; j++ ) {
1542           GraphBase::OutPort *anOutPort = aFromNode->GetChangeNodeOutPort(j) ;
1543 //          cdebug << "CreateService Node " << aFromNode->Name() << ". Output port[" << j << "] ";
1544 //          if ( anOutPort ) {
1545 //            cdebug << anOutPort->PortName() << " " << anOutPort->ServicesParameterType() << endl ;
1546 //        }
1547 //          else {
1548 //            cdebug << " NULL" << endl ;
1549 //        }
1550           if ( !aFromNode->IsGOTONode() ) {
1551             if ( !anOutPort->IsGate() && ( anOutPort->IsNotConnected() || anOutPort->IsDataConnected() ) ||
1552                                            anOutPort->IsExternConnected() ) {
1553               if ( dostore == 0 ) {
1554 //                cdebug << "CreateService " << aFromNode->Name() << " Output port "
1555 //                       << anOutPort->PortName() << " " << anOutPort->PortStatus() << endl ;
1556                 if ( anOutPort->IsDataStream() ) {
1557                   outstreamnbr += 1 ;
1558                 }
1559                 else {
1560                   outnbr += 1 ;
1561                 }
1562               }
1563               else if ( ( dostore == 1 && !anOutPort->IsDataStream() ) ||
1564                         ( dostore == 2 && anOutPort->IsDataStream() ) ) {
1565                 aService.ServiceoutParameter[outnbr].Parametertype = CORBA::string_dup( anOutPort->PortType() ) ;
1566                 aService.ServiceoutParameter[outnbr].Parametername = CORBA::string_dup( anOutPort->NodePortName() ) ;
1567                 OutPortsKind[ outnbr ] = anOutPort->Kind() ;
1568                 OutDataStreamDependency[ outnbr ] = anOutPort->Dependency() ;
1569                 if ( dostore == 2 && anOutPort->IsDataStream() ) {
1570                   OutNumberOfValues[ outnbr ] = ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues() ;
1571                 }
1572 //                cdebug << "Out" << outnbr << " " << aService.ServiceoutParameter[ outnbr ].Parametername << " "
1573 //                       << anOutPort->Kind() << " " << anOutPort->PortStatus() << endl ;
1574                 outnbr += 1 ;
1575               }
1576             }
1577           }
1578         }
1579       }
1580     }
1581 //  }
1582
1583 #if 0
1584   cdebug << "DataFlowNode ServiceName " << aService.ServiceName << " InPorts " << innbr
1585          << " OutPorts " << outnbr << endl ;
1586   for ( i = 0 ; i < innbr ; i++ ) {
1587     cdebug << "aService.ServiceinParameter[" << i << "].Parametertype "
1588          << aService.ServiceinParameter[i].Parametertype << " Parametername "
1589          << aService.ServiceinParameter[i].Parametername << " " << InPortsKind[ i ] << endl ;
1590     if ( InPortsKind[ i ] != SUPERV::DataStreamParameter ) {
1591       cdebug << "NodeInPort[" << i << "] " << *GetChangeNodeInPort( i ) << endl ;
1592     }
1593   }
1594   for ( i = 0 ; i < outnbr ; i++ ) {
1595     cdebug << "aService.ServiceoutParameter[" << i << "].Parametertype "
1596          << aService.ServiceoutParameter[i].Parametertype << " Parametername "
1597          << aService.ServiceoutParameter[i].Parametername << " " << OutPortsKind[ i ] << endl ;
1598     if ( OutPortsKind[ i ] != SUPERV::DataStreamParameter ) {
1599       cdebug << "NodeOutPort[" << i << "] " << *GetChangeNodeOutPort( i ) << endl ;
1600     }
1601   }
1602 #endif
1603
1604 //  DataService( _Orb , aService , InPortsKind , OutPortsKind , Graph_prof_debug() , Graph_fdebug() ) ;
1605   for ( i = 0 ; i < innbr ; i++ ) {
1606     if ( InPortsKind[ i ] == SUPERV::DataStreamParameter ) {
1607       GraphBase::InDataStreamPort * anInPort = AddInDataStreamPort( aService.ServiceinParameter[ i ].Parametername ,
1608                                                                     StringToDataStreamType( aService.ServiceinParameter[ i ].Parametertype ) ,
1609                                                                     InDataStreamDependency[ i ] ,
1610                                                                     SUPERV::DataStreamParameter ) ;
1611       anInPort->SetParams( InKindOfSchema[ i ] ,
1612                            InKindOfInterpolation[ i ] ,
1613                            InKindOfExtrapolation[ i ] ) ;
1614 // NOT A BUG : AddOutPort for an inport (Reversed service)
1615       anInPort = (GraphBase::InDataStreamPort * ) _DataFlowDataPorts->AddOutPort(
1616                                                            _Orb , NamePtr() ,
1617                                                            Kind() ,
1618                                                            aService.ServiceinParameter[ i ].Parametername ,
1619                                                            aService.ServiceinParameter[ i ].Parametertype ,
1620                                                            SUPERV::DataStreamParameter ,
1621                                                            - 1 ,
1622                                                            _Graph_prof_debug , _Graph_fdebug ) ;
1623       anInPort->Dependency( InDataStreamDependency[ i ] ) ;
1624 // Attention : revoir les reversed DataStreamPorts
1625 //      anInPort->SetParams( InKindOfSchema[ i ] ,
1626 //                           InKindOfInterpolation[ i ] ,
1627 //                           InKindOfExtrapolation[ i ] ) ;
1628       cdebug << "InStreamPort " << GetChangeNodeInPort( i )->PortName() << " " << GetChangeNodeInPort( i )->Kind() << endl ;
1629       cdebug << "ReversedInStreamPort " << _DataFlowDataPorts->GetChangeNodeOutPort( i )->PortName() << " " << _DataFlowDataPorts->GetChangeNodeOutPort( i )->Kind()
1630              << endl ;
1631     }
1632     else {
1633       GetChangeNodeInPort( i )->Kind( InPortsKind[ i ] ) ;
1634       _DataFlowDataPorts->GetChangeNodeOutPort( i )->Kind( InPortsKind[ i ] ) ;
1635       GetChangeNodeInPort( i )->Dependency( InDataStreamDependency[ i ] ) ;
1636       _DataFlowDataPorts->GetChangeNodeOutPort( i )->Dependency( InDataStreamDependency[ i ] ) ;
1637       cdebug << "InPort " << GetChangeNodeInPort( i )->PortName() << " " << GetChangeNodeInPort( i )->Kind() << endl ;
1638       cdebug << "ReversedInPort " << _DataFlowDataPorts->GetChangeNodeOutPort( i )->PortName() << " " << _DataFlowDataPorts->GetChangeNodeOutPort( i )->Kind()
1639              << endl ;
1640     }
1641   }
1642   for ( i = 0 ; i < outnbr ; i++ ) {
1643     if ( OutPortsKind[ i ] == SUPERV::DataStreamParameter ) {
1644       GraphBase::OutDataStreamPort * anOutPort = AddOutDataStreamPort( aService.ServiceoutParameter[ i ].Parametername ,
1645                                                                        StringToDataStreamType( aService.ServiceoutParameter[ i ].Parametertype ) ,
1646                                                                        OutDataStreamDependency[ i ] ,
1647                                                                        SUPERV::DataStreamParameter ) ;
1648       anOutPort->NumberOfValues( OutNumberOfValues[ i ] ) ;
1649 // NOT A BUG : AddInPort for an outport (Reversed service)
1650       anOutPort = (GraphBase::OutDataStreamPort * ) _DataFlowDataPorts->AddInPort(
1651                                                              _Orb , NamePtr() ,
1652                                                              Kind() ,
1653                                                              aService.ServiceoutParameter[ i ].Parametername ,
1654                                                              aService.ServiceoutParameter[ i ].Parametertype ,
1655                                                              SUPERV::DataStreamParameter ,
1656                                                              - 1 ,
1657                                                              _Graph_prof_debug , _Graph_fdebug ) ;
1658       anOutPort->Dependency( OutDataStreamDependency[ i ] ) ;
1659 // Attention : revoir les reversed DataStreamPorts
1660 //      anOutPort->NumberOfValues( OutNumberOfValues[ i ] ) ;
1661       cdebug << "OutStreamPort " << GetChangeNodeOutPort( i )->PortName() << " " << GetChangeNodeOutPort( i )->Kind() << endl ;
1662       cdebug << "ReversedOutStreamPort " << _DataFlowDataPorts->GetChangeNodeInPort( i )->PortName() << " " << _DataFlowDataPorts->GetChangeNodeInPort( i )->Kind()
1663              << endl ;
1664     }
1665     else {
1666       GetChangeNodeOutPort( i )->Kind( OutPortsKind[ i ] ) ;
1667       _DataFlowDataPorts->GetChangeNodeInPort( i )->Kind( OutPortsKind[ i ] ) ;
1668       GetChangeNodeOutPort( i )->Dependency( OutDataStreamDependency[ i ] ) ;
1669       _DataFlowDataPorts->GetChangeNodeInPort( i )->Dependency( OutDataStreamDependency[ i ] ) ;
1670       GetChangeNodeOutPort( i )->Dependency( OutDataStreamDependency[ i ] ) ;
1671       _DataFlowDataPorts->GetChangeNodeInPort( i )->Dependency( OutDataStreamDependency[ i ] ) ;
1672       cdebug << "OutPort " << GetChangeNodeOutPort( i )->PortName() << " " << GetChangeNodeOutPort( i )->Kind() << endl ;
1673       cdebug << "ReversedOutPort " << _DataFlowDataPorts->GetChangeNodeInPort( i )->PortName() << " " << _DataFlowDataPorts->GetChangeNodeInPort( i )->Kind()
1674              << endl ;
1675     }
1676   }
1677 // Restore input datas and links :
1678   DataStreamInPortsNumber( 0 ) ;
1679   DataStreamOutPortsNumber( 0 ) ;
1680   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1681     aToNode = GraphNodes( i ) ;
1682     DataStreamInPortsNumber( DataStreamInPortsNumber() + aToNode->DataStreamInPortsNumber() ) ;
1683     DataStreamOutPortsNumber( DataStreamOutPortsNumber() + aToNode->DataStreamOutPortsNumber() ) ;
1684     for ( j = 0 ; j < aToNode->GetNodeInPortsSize() ; j++ ) {
1685       GraphBase::InPort *anInPort = aToNode->GetChangeNodeInPort(j) ;
1686       if ( !anInPort->IsGate() && anInPort->IsDataConnected() ) {
1687         if ( !AddInputData( anInPort->NodeName() ,
1688                             anInPort->PortName() ,
1689                             anInPort->GetOutPort()->ValuePtr() ) ) {
1690           cdebug << "CreateService In" << j << " " << anInPort->NodeName() << "(" << anInPort->PortName() << ") "
1691                  << anInPort->PortStatus() << " --> AddInputData ERROR" << endl ;
1692           RetVal = false ;
1693         }
1694         else {
1695           cdebug << "CreateService In" << j << " " << anInPort->NodeName() << "(" << anInPort->PortName() << ") "
1696                  << anInPort->PortStatus() << " --> AddInputData" << endl ;
1697         }
1698       }
1699       else if ( !anInPort->IsGate() && anInPort->IsNotConnected() ) {
1700         if ( !AddLink( this , GetChangeInDataNodePort( anInPort->NodePortName() ) , aToNode , anInPort ) ) {
1701           cdebug << "CreateService In" << j << " " << anInPort->NodeName() << "(" << anInPort->PortName() << ") "
1702                  << anInPort->PortStatus() << " --> AddInLink ERROR" << endl ;
1703           RetVal = false ;
1704         }
1705         else {
1706           cdebug << "CreateService In" << j << " " << anInPort->NodeName() << "(" << anInPort->PortName() << ") "
1707                  << anInPort->PortStatus() << " --> AddInLink" << endl ;
1708         }
1709       }
1710     }
1711     for ( j = 0 ; j < aToNode->GetNodeOutPortsSize() ; j++ ) {
1712       GraphBase::OutPort *anOutPort = aToNode->GetChangeNodeOutPort(j) ;
1713       cdebug << "CreateService Out" << j << " " << anOutPort->NodeName() << "(" << anOutPort->PortName()
1714              << ") " << anOutPort->PortStatus() << " :" << endl ;
1715       if ( !anOutPort->IsGate() && anOutPort->IsNotConnected() && !aToNode->IsGOTONode() ) {
1716         GraphBase::InPort *anInPort = GetChangeOutDataNodePort( anOutPort->NodePortName() ) ;
1717         if ( !AddLink( aToNode , anOutPort , this , anInPort ) ) {
1718           cdebug << "       --> " << Name() << "(" << anInPort->PortName()
1719                  << ") " << anInPort->PortStatus() << " AddOutLink ERROR" << endl ;
1720           RetVal = false ;
1721         }
1722         else {
1723           cdebug << "       --> " << Name() << "(" << anInPort->PortName()
1724                  << ") " << anInPort->PortStatus() << " AddOutLink" << endl ;
1725         }
1726       }
1727     }
1728   }
1729
1730   cdebug_out << "GraphBase::Graph::CreateService " << RetVal << endl;
1731   return RetVal ;
1732 }
1733
1734 bool GraphBase::Graph::InLineServices() {
1735   cdebug_in << "GraphBase::Graph::InLineServices" << endl;
1736
1737   int i , j ;
1738
1739 #ifdef _DEBUG_
1740   ListPorts( *_Graph_fdebug , 0 ) ;
1741 #endif
1742
1743   GraphBase::InLineNode * aINode ;
1744   SALOME_ModuleCatalog::Service aService ;
1745   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1746     aINode = (GraphBase::InLineNode * ) GraphNodes( i ) ;
1747     if ( aINode->IsOneOfInLineNodes() ) {
1748 //      cdebug << "GraphBase::Graph::InLineServices " << aINode->Name() << endl;
1749       aService.ServiceName = aINode->ServiceName() ;
1750       aService.ServiceinParameter.length( 0 ) ;
1751       aService.ServiceoutParameter.length( 0 ) ;
1752       aINode->DataStreamInPortsNumber( 0 ) ;
1753       aINode->DataStreamOutPortsNumber( 0 ) ;
1754       int InService = 0 ;
1755       int InStreamService = 0 ;
1756       for ( j = 0 ; j < aINode->GetNodeInPortsSize() ; j++ ) {
1757         if ( aINode->GetChangeNodeInPort(j)->IsGate() || aINode->GetChangeNodeInPort(j)->IsLoop() ) {
1758 #if 0
1759           cdebug << "GraphBase::Graph::InLineServices In" << j << " "
1760                  << aINode->GetChangeNodeInPort(j)->Kind() << " " 
1761                  << aINode->GetChangeNodeInPort(j)->PortType() << " " 
1762                  << aINode->GetChangeNodeInPort(j)->PortName() << " ignored "
1763                  << aINode->GetChangeNodeInPort(j)->IsGate() << " "
1764                  << aINode->GetChangeNodeInPort(j)->IsLoop() << endl;
1765 #endif
1766         }
1767         else if ( aINode->GetChangeNodeInPort(j)->IsDataStream() ) {
1768           aService.ServiceinDataStreamParameter.length( InStreamService+1 ) ;
1769           aService.ServiceinDataStreamParameter[InStreamService].Parametertype = StringToDataStreamType( aINode->GetChangeNodeInPort(j)->PortType() ) ;
1770           aService.ServiceinDataStreamParameter[InStreamService].Parametername = CORBA::string_dup( aINode->GetChangeNodeInPort(j)->PortName() ) ;
1771           aService.ServiceinDataStreamParameter[InStreamService++].Parameterdependency = aINode->GetChangeNodeInPort(j)->Dependency() ;
1772           aINode->IncrDataStreamInPorts() ;
1773 #if 0
1774           cdebug << "GraphBase::Graph::InLineServices In" << j << " "
1775                  << aINode->GetChangeNodeInPort(j)->Kind() << " " 
1776                  << aINode->GetChangeNodeInPort(j)->PortType() << " " 
1777                  << aINode->GetChangeNodeInPort(j)->PortName() << " "
1778                  << aINode->GetChangeNodeInPort(j)->IsGate() << " "
1779                  << aINode->GetChangeNodeInPort(j)->IsLoop() << endl;
1780 #endif
1781         }
1782         else {
1783           aService.ServiceinParameter.length( InService+1 ) ;
1784           aService.ServiceinParameter[InService].Parametertype = CORBA::string_dup( aINode->GetChangeNodeInPort(j)->PortType() ) ;
1785           aService.ServiceinParameter[InService++].Parametername = CORBA::string_dup( aINode->GetChangeNodeInPort(j)->PortName() ) ;
1786 #if 0
1787           cdebug << "GraphBase::Graph::InLineServices In" << j << " "
1788                  << aINode->GetChangeNodeInPort(j)->Kind() << " " 
1789                  << aINode->GetChangeNodeInPort(j)->PortType() << " " 
1790                  << aINode->GetChangeNodeInPort(j)->PortName() << " "
1791                  << aINode->GetChangeNodeInPort(j)->IsGate() << " "
1792                  << aINode->GetChangeNodeInPort(j)->IsLoop() << endl;
1793 #endif
1794         }
1795       }
1796       int OutService = 0 ;
1797       int OutStreamService = 0 ;
1798       for ( j = 0 ; j < aINode->GetNodeOutPortsSize() ; j++ ) {
1799 //        if ( aINode->GetChangeNodeOutPort(j)->IsGate() || aINode->GetChangeNodeOutPort(j)->IsLoop() || aINode->GetChangeNodeOutPort(j)->IsDataStream() ) {
1800         if ( aINode->GetChangeNodeOutPort(j)->IsGate() || aINode->GetChangeNodeOutPort(j)->IsLoop() ) {
1801 #if 0
1802           cdebug << "GraphBase::Graph::InLineServices Out" << j << " "
1803                  << aINode->GetChangeNodeOutPort(j)->Kind() << " " 
1804                  << aINode->GetChangeNodeOutPort(j)->PortType() << " " 
1805                  << aINode->GetChangeNodeOutPort(j)->PortName() << " ignored "
1806                  << aINode->GetChangeNodeOutPort(j)->IsGate() << " "
1807                  << aINode->GetChangeNodeOutPort(j)->IsLoop() << endl;
1808 #endif
1809         }
1810         else if ( aINode->GetChangeNodeOutPort(j)->IsDataStream() ) {
1811           aService.ServiceoutDataStreamParameter.length( OutStreamService+1 ) ;
1812           aService.ServiceoutDataStreamParameter[OutStreamService].Parametertype = StringToDataStreamType( aINode->GetChangeNodeOutPort(j)->PortType() ) ;
1813           aService.ServiceoutDataStreamParameter[OutStreamService].Parametername = CORBA::string_dup( aINode->GetChangeNodeOutPort(j)->PortName() ) ;
1814           aService.ServiceoutDataStreamParameter[OutStreamService++].Parameterdependency = aINode->GetChangeNodeOutPort(j)->Dependency() ;
1815           aINode->IncrDataStreamOutPorts() ;
1816 #if 0
1817           cdebug << "GraphBase::Graph::InLineServices Out" << j << " "
1818                  << aINode->GetChangeNodeOutPort(j)->Kind() << " " 
1819                  << aINode->GetChangeNodeOutPort(j)->PortType() << " " 
1820                  << aINode->GetChangeNodeOutPort(j)->PortName() << " "
1821                  << aINode->GetChangeNodeOutPort(j)->IsGate() << " "
1822                  << aINode->GetChangeNodeOutPort(j)->IsLoop() << endl;
1823 #endif
1824         }
1825         else {
1826           aService.ServiceoutParameter.length( OutService+1 ) ;
1827           aService.ServiceoutParameter[OutService].Parametertype = CORBA::string_dup( aINode->GetChangeNodeOutPort(j)->PortType() ) ;
1828           aService.ServiceoutParameter[OutService++].Parametername = CORBA::string_dup( aINode->GetChangeNodeOutPort(j)->PortName() ) ;
1829 #if 0
1830           cdebug << "GraphBase::Graph::InLineServices Out" << j << " "
1831                  << aINode->GetChangeNodeOutPort(j)->Kind() << " " 
1832                  << aINode->GetChangeNodeOutPort(j)->PortType() << " " 
1833                  << aINode->GetChangeNodeOutPort(j)->PortName()  << " "
1834                  << aINode->GetChangeNodeOutPort(j)->IsGate() << " "
1835                  << aINode->GetChangeNodeOutPort(j)->IsLoop() << endl;
1836 #endif
1837         }
1838       }
1839       aINode->SetService( aService ) ;
1840       if ( SetServiceOfMap( (GraphBase::Service * ) aINode ) ) {
1841 #if 0
1842         cdebug << "InLineServices SetServiceOfMap " << aINode->ServiceName() << " in MapOfServices"
1843                << " InStreamPort(" << aINode->DataStreamInPortsNumber() 
1844                << ") OutStreamPort(" << aINode->DataStreamOutPortsNumber() << ")" << endl ; 
1845 #endif
1846       }
1847 //      cdebug << "GraphBase::Graph::InLineServices" << *aINode->GetService() << endl;
1848     }
1849   }
1850
1851   cdebug_out << "GraphBase::Graph::InLineServices" << endl;
1852   return true ;
1853 }
1854
1855 bool GraphBase::Graph::Sort( int & SubStreamGraphsNumber ) {
1856   int i ;
1857   int j ;
1858   int NotSortedNumber = GraphNodesSize() ;
1859   bool NewSorted ;
1860   cdebug_in << "GraphBase::Graph::Sort" << endl;
1861   if ( NotSortedNumber ) {
1862     _LevelsNumber = 0 ;
1863     _ParallelExecutionNodes = false ;
1864     _Sorted.resize( GraphNodesSize() ) ;
1865     _CnxInPortsNumber.resize( GraphNodesSize() ) ;
1866     _DecrInPortsNumber.resize( GraphNodesSize() ) ;
1867     if ( _NodesNumber.size() ) {
1868       _NodesNumber.resize( 0 ) ;
1869       _SortedNodes.resize( 0 ) ;
1870     }
1871           
1872 // This is a simulation of the computation of the graph :
1873 // The initial state of nodes is :
1874 // - Sorted = false : the node is not sorted
1875 // - CnxInPortsNumber = ConnectedInPortsNumber : the number of ports that wait for a value from a link
1876 // - DecrInPortsNumber = 0 : there is no value available.
1877 #if 0
1878     cdebug << "GraphBase::Graph::Sort initial values :" << endl ;
1879     for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1880       GraphBase::ComputingNode * aNode = GraphNodes( i ) ;
1881       cdebug << aNode->Name() << " --> " << aNode->LinkedNodesSize() << " LinkedNodes :" << endl ;
1882       for ( j = 0 ; j < aNode->LinkedNodesSize()  ; j++ ) {
1883         cdebug << "              " << aNode->LinkedNodes( j )->Name() << endl ;
1884       }
1885     }
1886 #endif
1887     for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1888       _Sorted[ i ] = false ;
1889       _CnxInPortsNumber[ i ] = GraphNodes( i )->ConnectedInPortsNumber() ;
1890       _DecrInPortsNumber[ i ] = 0 ;
1891 //      cdebug << "Sort Node [" << i << "] " << GraphNodes( i )->Name() << " initial count "
1892 //             << _CnxInPortsNumber[ i ] << endl ;
1893     }
1894     
1895 // Nodes are linked ONLY if Ports are NOT DataStream for topological sort of node
1896 // ==============================================================================
1897     while ( NotSortedNumber ) {
1898       NewSorted = false ;
1899       
1900       for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1901         cdebug << "Sort level " << _LevelsNumber << ". [" << i << "] "
1902                << GraphNodes( i )->Name() << " count "
1903                << _CnxInPortsNumber[ i ] << endl ;
1904         if ( !_Sorted[ i ] && _CnxInPortsNumber[ i ] == 0 ) {
1905 // All inputs of GraphNodes( i ) are available : "AllDataReady"
1906           if ( (int ) _NodesNumber.size() != _LevelsNumber+1 ) {
1907             _NodesNumber.resize( _LevelsNumber+1 ) ;
1908             _SortedNodes.resize( _LevelsNumber+1 ) ;
1909             _NodesNumber[ _LevelsNumber ] = -1 ;
1910           }
1911 // There is one more node at that level
1912           _NodesNumber[ _LevelsNumber ]++ ;
1913           (_SortedNodes[ _LevelsNumber ]).resize( _NodesNumber[ _LevelsNumber ]+1 ) ;
1914           (_SortedNodes[ _LevelsNumber ])[ _NodesNumber[ _LevelsNumber ] ] = GraphNodes( i ) ;
1915           _Sorted[ i ] = true ;
1916           NewSorted = true ;
1917           NotSortedNumber -= 1 ;
1918           cdebug << GraphNodes( i )->Name() << " belongs to level "
1919                  << _LevelsNumber << ". " << GraphNodes( i )->LinkedNodesSize() << " linkednodes" << endl ;
1920 // GraphNodes( i ) has the state "AllDataReady". We simulate the end of its execution :
1921 // So we loop over all nodes that have a link from that node
1922 // And we increment the number of input ports of GraphNodes( i )->LinkedNodes( j ) that this
1923 // execution will give a value in DecrInPortsNumber : "SomeDataReady"
1924           for ( j = 0 ; j < GraphNodes( i )->LinkedNodesSize() ; j++ ) {
1925 // OutputPorts of GraphNodes( i ) will satisfy 
1926 //   GraphNodes( i )->LinkedInPortsNumber( j ) InPorts of
1927 //      GraphNodes( i )->LinkedNodes( j )
1928             GraphBase::StreamNode * aLinkedNode = GraphNodes( i )->LinkedNodes( j ) ;
1929             int aLinkedInPortsNumber = GraphNodes( i )->LinkedInPortsNumber( j ) ;
1930             cdebug << j << ". LinkedNode " << aLinkedNode->Name() ;
1931             if ( !aLinkedNode->IsDataFlowNode() && !aLinkedNode->IsDataStreamNode() ) {
1932               cdebug << " _DecrInPortsNumber[ "
1933                      << GetGraphNodeIndex( aLinkedNode->Name() )
1934                      << " ] = "
1935                      << _DecrInPortsNumber[ GetGraphNodeIndex( aLinkedNode->Name() ) ]
1936                      << " += " << aLinkedInPortsNumber ;
1937               _DecrInPortsNumber[ GetGraphNodeIndex( aLinkedNode->Name() ) ] += aLinkedInPortsNumber ;
1938             }
1939             cdebug << endl ;
1940           }
1941         }
1942       }
1943 // If no node was found, that FlowGraph is not valid : if we try to execute it, that FlowGraph
1944 // will wait for data(s) from node(s) not executed or not executing for ever
1945       if ( !NewSorted ) {
1946         cdebug << "Loop detected level " << _LevelsNumber << endl ;
1947         return false ; // Loop in the Graph
1948       }
1949 //      cdebug << "Bilan level " << _LevelsNumber << " : " << endl ;
1950       bool ChangeCount = false ;
1951 // We update now the number of InPorts with a link that are waiting for a value
1952       for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1953         if ( _DecrInPortsNumber[ i ] ) {
1954 //          int prevcount = _CnxInPortsNumber[ i ] ;
1955           _CnxInPortsNumber[ i ] -= _DecrInPortsNumber[ i ]  ;
1956           _DecrInPortsNumber[ i ] = 0 ;
1957           ChangeCount = true ;
1958 //          cdebug << "    " << GraphNodes( i )->Name() << " count " << prevcount
1959 //                 << " --> new count " << _CnxInPortsNumber[ i ] << endl ;
1960         }
1961       }
1962 // If there is no loop and if the number of InPorts with a link that are waiting for a value
1963 // does not change, the sort is finished. But there is also NotSortedNumber ...
1964 //      if ( !ChangeCount )
1965 //        break ;
1966       if ( NotSortedNumber ) {
1967         _LevelsNumber += 1 ;
1968       }
1969     }
1970     _ThreadsMax = 0 ;
1971     int AllSortedNodes = 0 ;
1972     _HeadNodes = _SortedNodes[ 0 ] ;
1973     _HeadNodesSize = _SortedNodes[ 0 ].size() ;
1974 // QueueNodes was used in the past in order to know if the execution of a graph is finished
1975 // But because of loop nodes that was changed. So that part of code is a "clutter"
1976 // Now a graph has finished its execution when the number of executing threads is zero
1977     _QueueNodes = _SortedNodes[ _LevelsNumber ] ;
1978     _QueueNodesSize = _SortedNodes[ _LevelsNumber ].size() ;
1979     for ( i = 0 ; i < _QueueNodesSize ; i++ ) {
1980       if ( !_QueueNodes[ i ]->IsGOTONode() ) {
1981         break ;
1982       }
1983     }
1984     if ( i == _QueueNodesSize && _LevelsNumber ) {
1985       _QueueNodes = _SortedNodes[ _LevelsNumber - 1 ] ;
1986       _QueueNodesSize = _SortedNodes[ _LevelsNumber - 1 ].size() ;
1987     }
1988 // Computation of the maximum number of threads == the maximum number of nodes of all levels
1989     for ( i = 0 ; i <= _LevelsNumber ; i++ ) {
1990       AllSortedNodes += _NodesNumber[ i ]+1 ;
1991       if ( _NodesNumber[ i ] + 1 > _ThreadsMax ) {
1992         _ThreadsMax = _NodesNumber[ i ] + 1 ;
1993       }
1994       cdebug << _NodesNumber[ i ]+1 << " Nodes of level " << i << " : "
1995              << (_SortedNodes[ i ])[ 0 ]->Name() << endl ;
1996       for ( j = 1 ; j <= _NodesNumber[ i ] ; j++ ) {
1997         _ParallelExecutionNodes = true ;
1998         cdebug << "                     " << (_SortedNodes[ i ])[ j ]->Name()
1999                << endl ;
2000       }
2001     }
2002     if ( _ParallelExecutionNodes ) {
2003 //      cdebug << "Parallel Execution Nodes detected." << endl ;
2004     }
2005     else {
2006 //      cdebug << "No Parallel Execution Nodes detected." << endl ;
2007     }
2008     if ( AllSortedNodes != GraphNodesSize() ) {
2009       cdebug << "Loop detected level " << _LevelsNumber << endl ;
2010       return false ; // Loop in the Graph
2011     }
2012
2013     for ( i= 0 ; i <= _NodesNumber[ 0 ] ; i++ ) {
2014       (_SortedNodes[ 0 ])[ i ]->HeadNode( true ) ;
2015     }
2016
2017 // Give a subgraph/substreamgraph number > 0 to HeadNodes (level 0)
2018 // There is no substreamgraph for nodes without StreamPorts
2019     for ( j = 0 ; j <= _NodesNumber[ 0 ] ; j++ ) {
2020       (_SortedNodes[ 0 ])[ j ]->Level( 0 ) ;
2021       (_SortedNodes[ 0 ])[ j ]->SortedIndex( j ) ;
2022       (_SortedNodes[ 0 ])[ j ]->SubGraph( j + 1 ) ;
2023       if ( (_SortedNodes[ 0 ])[ j ]->HasDataStream() ) {
2024         (_SortedNodes[ 0 ])[ j ]->SubStreamGraph( j + 1 ) ;
2025       }
2026       else {
2027         (_SortedNodes[ 0 ])[ j ]->SubStreamGraph( -1 ) ;
2028       }
2029     }
2030
2031 // Give a subgraph/substreamgraph number = 0 to all other nodes :
2032 // the SubGraph of that nodes is unknown
2033 // There is no substreamgraph for nodes without StreamPorts
2034     for ( i = 1 ; i <= _LevelsNumber ; i++ ) {
2035       for ( j = 0 ; j <= _NodesNumber[ i ] ; j++ ) {
2036         (_SortedNodes[ i ])[ j ]->Level( i ) ;
2037         (_SortedNodes[ i ])[ j ]->SortedIndex( j ) ;
2038         (_SortedNodes[ i ])[ j ]->SubGraph( 0 ) ;
2039         if ( (_SortedNodes[ i ])[ j ]->HasDataStream() ) {
2040           (_SortedNodes[ i ])[ j ]->SubStreamGraph( 0 ) ;
2041         }
2042         else {
2043           (_SortedNodes[ i ])[ j ]->SubStreamGraph( -1 ) ;
2044         }
2045       }
2046     }
2047
2048 // Computation of independent SubGraphs which have NO link between them
2049     cdebug << endl << "Computation of SubGraphs" << endl ;
2050     bool Graphs = true ;
2051     while ( Graphs ) {
2052       for ( i = 0 ; i <= _LevelsNumber ; i++ ) {
2053         cdebug << endl << "LevelsNumber " << _LevelsNumber << " " << _NodesNumber[ i ]
2054                << " Nodes :" << endl ;
2055         for ( j = 0 ; j <= _NodesNumber[ i ] ; j++ ) {
2056           GraphBase::ComputingNode * aNode = (_SortedNodes[ i ])[ j ] ;
2057           cdebug << "    " << aNode->Name() << " SubGraph " << aNode->SubGraph() << endl ;
2058           int k ;
2059           for ( k = 0 ; k < aNode->LinkedNodesSize() ; k++ ) {
2060           if ( aNode->LinkedNodes( k )->SubGraph() ) {
2061               if ( aNode->LinkedNodes( k )->SubGraph() != aNode->SubGraph() ) {
2062 //                   && aNode->LinkedNodes( k )->Level() == aNode->Level()+1 ) {
2063 //            aNode->SubGraph( aNode->LinkedNodes( k )->SubGraph() ) ;
2064                 int OldSub = aNode->SubGraph() ;
2065                 int NewSub = aNode->LinkedNodes( k )->SubGraph() ;
2066               cdebug << "        " << aNode->Name() << " changed SubGraph "
2067                        << aNode->LinkedNodes( k )->SubGraph() << endl ;
2068                 int l ;
2069                 for ( l = 0 ; l <= _LevelsNumber ; l++ ) {
2070                   int m ;
2071                   for ( m = 0 ; m <= _NodesNumber[ l ] ; m++ ) {
2072                     if ( (_SortedNodes[ l ])[ m ]->SubGraph() == OldSub ) {
2073                       GraphBase::ComputingNode * aSubNode = (_SortedNodes[ l ])[ m ] ;
2074                       aSubNode->SubGraph( NewSub ) ;
2075                 }
2076                 }
2077               }
2078                 Graphs = false ;
2079                 break ;
2080             }
2081               else {
2082                 cdebug << "        Linked " << aNode->LinkedNodes( k )->Name()
2083                        << " same SubGraph " << aNode->LinkedNodes( k )->SubGraph() << endl ;
2084             }
2085           }
2086             else {
2087               cdebug << "        LinkedNode " << aNode->LinkedNodes( k )->Name()
2088                      << " initial SubGraph " << aNode->SubGraph() << endl ;
2089               aNode->LinkedNodes( k )->SubGraph( aNode->SubGraph() ) ;
2090           }
2091         }
2092           if ( !Graphs ) {
2093             break ;
2094           }
2095         }
2096         if ( !Graphs ) {
2097           break ;
2098         }
2099       }
2100       if ( Graphs ) {
2101         cdebug << endl << "SubGraphs result : " << endl ;
2102         break ;
2103       }
2104       cdebug << endl << "One more time" << endl ;
2105       Graphs = true ;
2106     }
2107 // Make a sequential renumbering of SubGraphs :
2108     _SubGraphsNumber = 0 ;
2109     int CurrGraphsNumber = 0;
2110     int k ;
2111     for ( k = 0 ; k <= _NodesNumber[ 0 ] ; k++ ) {
2112       if ( (_SortedNodes[ 0 ])[ k ]->SubGraph() > CurrGraphsNumber ) {
2113         CurrGraphsNumber = (_SortedNodes[ 0 ])[ k ]->SubGraph() ;
2114         _SubGraphsNumber += 1 ;
2115         for ( i = 0 ; i <= _LevelsNumber ; i++ ) {
2116           for ( j = 0 ; j <= _NodesNumber[ i ] ; j++ ) {
2117             if ( (_SortedNodes[ i ])[ j ]->SubGraph() == CurrGraphsNumber ) {
2118               (_SortedNodes[ i ])[ j ]->SubGraph( _SubGraphsNumber ) ;
2119               cdebug << "SubGraphsNumber " << _SubGraphsNumber << " " << " Level "
2120                      << i << " : " << (_SortedNodes[ i ])[ j ]->Name()
2121                      << endl ;
2122             }
2123           }
2124         }
2125       }
2126     }
2127
2128 //    cdebug << endl << "Computation of SubStreamGraphs" << endl ;
2129     for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2130       GraphBase::ComputingNode * aNode = GraphNodes( i ) ;
2131       if ( aNode->SubStreamGraph() < 0 ) {
2132 //      cdebug << "Graph " << aNode->Name() << " has NO streamport" << endl ;
2133       }
2134       else {
2135 //        cdebug << aNode->Name() << " SubGraph " << aNode->SubGraph() << " --> "
2136 //               << aNode->LinkedStreamNodesSize() << " LinkedStreamNodes :" << endl ;
2137         for ( j = 0 ; j < aNode->LinkedStreamNodesSize()  ; j++ ) {
2138 //          cdebug << "              " << aNode->LinkedStreamNodes( j )->Name() << endl ;
2139         }
2140       }
2141     }
2142
2143 // Computation of independent SubStreamGraphs which have NO StreamLink between them
2144     SubStreamGraphsNumber = 0 ;
2145     int ilevel ;
2146     for ( ilevel = 0 ; ilevel <= _LevelsNumber ; ilevel++ ) {
2147 // Loop for _NodesNumber[ ilevel ] nodes of the level ilevel
2148       int jnode ;
2149       for ( jnode = 0 ; jnode <= _NodesNumber[ ilevel ] ; jnode++ ) {
2150         GraphBase::ComputingNode * aNode = (_SortedNodes[ ilevel ])[ jnode ] ;
2151         if ( aNode->SubStreamGraph() < 0 ) {
2152 //        cdebug << "Graph " << aNode->SubStreamGraph() << " " << aNode->Name()
2153 //                 << " has NO streamport" << endl ;
2154         }
2155         else {
2156           int CurStreamGraphsNumber ;
2157           if ( aNode->SubStreamGraph() > 0 ) {
2158 //          cdebug << "SubStreamGraph " << aNode->SubStreamGraph() << " " << aNode->Name()
2159 //                   << " has streamport LinkedStreamNodesSize already in a SubStreamGraph" << endl ;
2160             CurStreamGraphsNumber = aNode->SubStreamGraph() ;
2161           }
2162           else {
2163             CurStreamGraphsNumber = SubStreamGraphsNumber+1 ;
2164           }
2165           int RetVal = 0 ;
2166           while ( RetVal != CurStreamGraphsNumber ) {
2167             RetVal = CurStreamGraphsNumber ;
2168             aNode->SetSubStreamGraph( CurStreamGraphsNumber , RetVal ) ;
2169             if ( RetVal != CurStreamGraphsNumber ) {
2170               for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2171                 GraphBase::ComputingNode * aNode = GraphNodes( i ) ;
2172                 if ( aNode->SubStreamGraph() == CurStreamGraphsNumber ) {
2173                   aNode->SubStreamGraph( RetVal ) ;
2174                 }
2175               }
2176               CurStreamGraphsNumber = RetVal ;
2177               RetVal = 0 ;
2178             }
2179             if ( CurStreamGraphsNumber > SubStreamGraphsNumber ) {
2180               SubStreamGraphsNumber = CurStreamGraphsNumber ;
2181             }
2182           }
2183         }
2184       }
2185     }
2186 // Make a sequential renumbering of SubGraphs :
2187 //    cdebug << endl << "Last SubStreamGraphsNumber : " << SubStreamGraphsNumber << endl ;
2188     int CurrStreamGraphsNumber = 0 ;
2189     int count = 0 ;
2190     for ( CurrStreamGraphsNumber = 0 ; CurrStreamGraphsNumber <= SubStreamGraphsNumber ; CurrStreamGraphsNumber++ ) {
2191       bool SearchCurrStreamGraphsNumber = true ;
2192       for ( k = 0 ; k <= _LevelsNumber && SearchCurrStreamGraphsNumber ; k++ ) {
2193         int l ;
2194         for ( l = 0 ; l <= _NodesNumber[ k ] && SearchCurrStreamGraphsNumber ; l++ ) {
2195           if ( (_SortedNodes[ k ])[ l ]->SubStreamGraph() == CurrStreamGraphsNumber ) {
2196             SearchCurrStreamGraphsNumber = false ;
2197             count = count + 1 ;
2198             if ( CurrStreamGraphsNumber != count ) {
2199 //              cdebug << "CurrStreamGraphsNumber " << CurrStreamGraphsNumber << " count " << count
2200 //                     << " Level " << k << " n " << l << endl ;
2201               for ( i = k ; i <= _LevelsNumber ; i++ ) {
2202                 for ( j = 0 ; j <= _NodesNumber[ i ] ; j++ ) {
2203                   if ( (_SortedNodes[ i ])[ j ]->SubStreamGraph() == CurrStreamGraphsNumber ) {
2204                     (_SortedNodes[ i ])[ j ]->SubStreamGraph( count ) ;
2205 //                    cdebug << "SubStreamGraphsNumber " << CurrStreamGraphsNumber << " --> " << count << " "
2206 //                           << " Level " << i << " : " << (_SortedNodes[ i ])[ j ]->Name() << endl ;
2207                   }
2208                   else if ( (_SortedNodes[ i ])[ j ]->SubStreamGraph() > 0 ) {
2209 //                    cdebug << "SubStreamGraphsNumber " << (_SortedNodes[ i ])[ j ]->SubStreamGraph()
2210 //                           << " != " << CurrStreamGraphsNumber << " Level " << i << " : "
2211 //                           << (_SortedNodes[ i ])[ j ]->Name() << endl ;
2212                   }
2213                 }
2214               }
2215             }
2216           }
2217         }
2218       }
2219     }
2220     SubStreamGraphsNumber = count ;
2221 //    cdebug << endl << "SubStreamGraphs result : " << SubStreamGraphsNumber << " SubStreamGraphs" << endl ;
2222 //    int CurrStreamGraphsNumber ;
2223 //    for ( CurrStreamGraphsNumber = 1 ; CurrStreamGraphsNumber <= SubStreamGraphsNumber  ; CurrStreamGraphsNumber++ ) {
2224 //      for ( ilevel = 0 ; ilevel <= _LevelsNumber ; ilevel++ ) {
2225 //        for ( k = 0 ; k <= _NodesNumber[ ilevel ] ; k++ ) {
2226 //          if ( (_SortedNodes[ ilevel ])[ k ]->SubStreamGraph() == CurrStreamGraphsNumber ) {
2227 //            cdebug << "SubStreamGraphsNumber " << CurrStreamGraphsNumber << " : "
2228 //                   << (_SortedNodes[ ilevel ])[ k ]->Name() << endl ;
2229 //        }
2230 //      }
2231 //      }
2232 //    }
2233   }
2234
2235 #ifdef _DEBUG_
2236   ListPorts( *_Graph_fdebug , 0 ) ;
2237 #endif
2238
2239   cdebug_out << "GraphBase::Graph::Sort" << endl;
2240   return true ;
2241 }
2242
2243 bool GraphBase::Graph::ValidLoops() const {
2244   cdebug_in << "GraphBase::Graph::ValidLoops" << endl;
2245
2246   int i ;
2247   GraphBase::ComputingNode * aNode ;
2248   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2249     aNode = GraphNodes( i ) ;
2250     if ( aNode->IsLoopNode() ) {
2251       GraphBase::LoopNode * aLoopNode = (GraphBase::LoopNode * ) aNode ;
2252       GraphBase::EndOfLoopNode * anEndLoopNode ;
2253       anEndLoopNode = (GraphBase::EndOfLoopNode * ) aLoopNode->CoupledNode() ;
2254       if ( !aLoopNode->CheckLoop( aLoopNode , anEndLoopNode ) ) {
2255         cdebug_out << "GraphBase::Graph::ValidLoops false aLoopNode " << aLoopNode->Name()
2256                    << endl;
2257         return false ;
2258       }
2259       else if ( !anEndLoopNode->CheckEndLoop( aLoopNode , anEndLoopNode ) ) {
2260         cdebug_out << "GraphBase::Graph::ValidLoops false anEndLoopNode " << anEndLoopNode->Name()
2261                    << endl;
2262         return false ;
2263       }
2264     }
2265   }
2266   cdebug_out << "GraphBase::Graph::ValidLoops true" << endl;
2267   return true ;
2268 }
2269
2270 // Controle de la coherence des noeuds de calcul
2271 // Enregistrement dans la liste des noeuds "tete" de graphe
2272
2273 bool GraphBase::Graph::ComputingNodes() const {
2274   bool RetVal = true ;
2275   cdebug << "GraphExecutor::GraphControl::ComputingNodes ()" << endl;
2276
2277 //  list<GraphEditor::Node *> aComputingNodesList = _G->ComputingNodesList() ;
2278 //  list<GraphEditor::Node *>::iterator aNode = aComputingNodesList.begin();
2279 //  GraphEditor::Port *  iP;
2280
2281 //  for (aNode = _G->ComputingNodesList().begin(); aNode !=_G->ComputingNodesList().end(); aNode++) {
2282 //  while ( aNode != aComputingNodesList.end() ) {
2283   int i ;
2284   GraphBase::ComputingNode * aNode ;
2285   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2286     aNode = GraphNodes( i ) ;
2287     // Tous les ports d'entree de tous les noeuds de calcul sont bien connectes
2288     // Enregistrement eventuel dans la liste des noeuds "tete" de graphe
2289 //    if ((*aNode)->GetNodeInPortsSize() == 0)
2290 //      _headNodes.push_front(*aNode);
2291     int j ;
2292     for ( j = 1 ; j < aNode->GetNodeInPortsSize() ; j++ ) {
2293       const GraphBase::InPort *iP = aNode->GetNodeInPort(j);
2294       if ( iP->IsNotConnected() ){
2295 //      cdebug << "Le port d'entree " << iP->PortName()
2296 //               << " du noeud de calcul " << aNode->Name() << " du graphe  "
2297 //               << Name() << " n'est pas connecte "<< endl;
2298         RetVal = false ;
2299       };
2300
2301     };
2302
2303     // Tous les noeuds de calcul ont au moins un port de sortie connecte
2304     bool oneOutPortConnected = false;
2305     for ( j = 1 ; j < aNode->GetNodeOutPortsSize() ; j++) {
2306       const GraphBase::OutPort *iP = aNode->GetNodeOutPort(j);
2307       if ( iP->IsPortConnected() || iP->IsDataConnected() ){
2308         oneOutPortConnected = true ;
2309 //      break;
2310       }
2311       else {
2312 //      cdebug << "Le port de sortie " << iP->PortName()
2313 //               << " du noeud de calcul " << aNode->Name() << " du graphe  "
2314 //               << Name() << " n'est pas connecte "<< endl;
2315         RetVal = false ;
2316       }
2317     };
2318     if (!oneOutPortConnected) {
2319 //      cdebug << "Le noeud de calcul " << aNode->Name() << " du graphe  "
2320 //               << Name() << " n'a aucun port de sortie connecte "<< endl;
2321 //      _computingError.push_front(2);
2322     }
2323   };
2324 //  return _computingError.size () ;
2325   return RetVal ;
2326 }
2327
2328 bool GraphBase::Graph::LinkLoopNodes(bool & NewLink ) {
2329   bool RetVal = true ;
2330   NewLink = false ;
2331   int i , j ;
2332   cdebug_in << "GraphBase::Graph::LinkLoopNodes()" << endl;
2333   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2334     GraphBase::ComputingNode * aNode = GraphNodes( i ) ;
2335     if ( aNode->IsLoopNode() ) {
2336       GraphBase::LoopNode * aLoopNode = (GraphBase::LoopNode * ) aNode ;
2337       for ( j = 0 ; j < aLoopNode->GetNodeInPortsSize() ; j++ ) {
2338         GraphBase::InPort *anInPort = aLoopNode->GetChangeNodeInPort(j) ;
2339         if ( !anInPort->IsGate() && anInPort->IsNotConnected() ) {
2340           if ( !AddLink( aLoopNode->CoupledNode() , aLoopNode->CoupledNode()->GetChangeNodeOutPort( j ) ,
2341                          aLoopNode , anInPort ) ) {
2342 //            cdebug << "GraphBase::Graph::CreateService AddLink ERROR " << aLoopNode->CoupledNode()->Name()
2343 //                   << "( " << aLoopNode->CoupledNode()->GetChangeNodeOutPort( j )->PortName() << " ) --> "
2344 //                   << aLoopNode->Name() << "( " << anInPort->PortName() << " )" << endl ;
2345             RetVal = false ;
2346           }
2347           else {
2348             NewLink = true ;
2349           }
2350         }
2351       }
2352       for ( j = 0 ; j < aLoopNode->CoupledNode()->GetNodeInPortsSize() ; j++ ) {
2353         GraphBase::InPort *anInPort = aLoopNode->CoupledNode()->GetChangeNodeInPort( j ) ;
2354         if ( !anInPort->IsGate() && anInPort->IsNotConnected() ) {
2355           if ( !AddLink( aLoopNode , aLoopNode->GetChangeNodeOutPort( j ) ,
2356                          aLoopNode->CoupledNode() , anInPort ) ) {
2357 //            cdebug << "GraphBase::Graph::CreateService AddLink ERROR " << aLoopNode->Name() << "( "
2358 //                   << aLoopNode->GetChangeNodeOutPort( j )->PortName() << " ) --> "
2359 //                   << aLoopNode->CoupledNode()->Name() << "( " << anInPort->PortName() << " )" << endl ;
2360             RetVal = false ;
2361           }
2362           else {
2363             NewLink = true ;
2364           }
2365         }
2366       }
2367     }
2368     else if ( aNode->IsGOTONode() ) {
2369       GraphBase::GOTONode * aGOTONode = (GraphBase::GOTONode * ) aNode ;
2370       GraphBase::OutPort *anOutGate = aGOTONode->GetChangeNodeOutGate() ;
2371       if ( anOutGate->IsNotConnected() ) {
2372         RetVal = aGOTONode->CoupledNode() != NULL;
2373         if ( RetVal ) {
2374           RetVal = AddLink( aGOTONode , anOutGate ,
2375                        aGOTONode->CoupledNode() , aGOTONode->CoupledNode()->GetChangeNodeInGate() );
2376         // cdebug << "GraphBase::Graph::CreateService AddLink ERROR " << aGOTONode->Name() << "( "
2377         //        << anOutGate->PortName() << " ) --> " << aGOTONode->CoupledNode()->Name() << "( "
2378         //        << aGOTONode->CoupledNode()->GetChangeNodeInGate()->PortName() << " )" << endl ;
2379           if ( !RetVal )
2380             NewLink = true;
2381         }
2382       }
2383     }
2384   }
2385   cdebug_out << "GraphBase::Graph::LinkLoopNodes() " << RetVal << endl;
2386   return RetVal ;
2387 }
2388
2389 // Controle de la coherence des noeuds de calcul
2390 // Enregistrement dans la liste des noeuds "tete" de graphe
2391
2392 bool GraphBase::Graph::DataServerNodes() const {
2393
2394   cdebug << "GraphBase::Graph::DataServerNodes ()" << endl;
2395
2396 //  const GraphExecutor::InNode *DataFlowDatas = GetDataFlowDatas() ;
2397   int i , j , ierr = 0 ;
2398
2399 //  if ( DataFlowDatas == NULL ) {
2400 //    MESSAGE( "No input data available in the DataFlow " << _G->Name() );
2401 //    return 0 ;
2402 //  }
2403
2404 //  const GraphExecutor::InNode *DataFlowNode = _G->GetDataFlowNode() ;
2405 //  MESSAGE( "DataServerNodes DataFlowNode : " << *DataFlowNode );
2406
2407 //  MESSAGE( "DataServerNodes DataFlowDatas : " << *DataFlowDatas );
2408
2409 // cout are inversed because DataFlowDatas is a mirror node of the DataFlow
2410
2411   ierr = CheckDataServerNodes() ;
2412
2413 //  list<GraphExecutor::InNode *> aComputingNodesList = _G->ComputingNodesList() ;
2414 //  list<GraphExecutor::InNode *>::iterator aNode = aComputingNodesList.begin();
2415   if ( GraphNodesSize() == 0 ) {
2416     ierr++ ;
2417   }
2418   else {
2419     GraphBase::ComputingNode * aNode ;
2420     for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2421       aNode = GraphNodes( i ) ;
2422 //  while ( aNode != aComputingNodesList.end() ) {
2423       if ( aNode->IsFactoryNode() ) {
2424         GraphBase::FactoryNode * FaNode = (GraphBase::FactoryNode * ) aNode ;
2425         if ( !strlen( FaNode->Computer() ) ) {
2426 //          cdebug << "ComputerName missing for node " << FaNode->Name() ;
2427           if ( !strlen( FaNode->Computer() ) ) {
2428             ierr++ ;
2429             cdebug << endl ;
2430           }
2431           else {
2432 //            cdebug << ". " << FaNode->Computer() << " will be used." << endl ;
2433           }
2434         }
2435     }
2436 // For Outputs of the DataFlow :
2437       for ( j = 0 ; j < aNode->GetNodeOutPortsSize() ; j++ ) {
2438         if ( aNode->GetNodeOutPort(j)->IsNotConnected() ) {
2439           if ( aNode->GetNodeOutPort(j)->IsDataStream() ) {
2440             aNode->AddStreamLinkedNode( (GraphBase::ComputingNode *) this ) ;
2441           }
2442           else {
2443             aNode->AddLinkedNode( (GraphBase::ComputingNode *) this ) ;
2444           }
2445         }
2446       }
2447     }
2448   }
2449
2450 // Chaque noeud dataserver ne possede qu'un seul port entree ou sortie et il est bien connecte
2451
2452 //  list<GraphExecutor::InNode *> aDataServerNodesList = _G->DataServerNodesList() ;
2453 //  list<GraphExecutor::InNode *>::iterator it = aDataServerNodesList.begin() ;
2454
2455 //  for (it = _G->DataServerNodesList().begin(); it !=_G->DataServerNodesList().end(); it++){
2456 //  while ( it != aDataServerNodesList.end() ) {
2457 //    if ( (*it)->GetNodeOutPortsSize() && (*it)->GetNodeInPortsSize() ) {
2458 //      cerr << "Erreur dans le noeud serveur de donnees " 
2459 //           << (*it)->Name() << " du graphe  " << _G->Name() << endl;
2460 //      cerr << "A la fois importation et exportation de donnees" << endl;
2461 //      _dataServerError.push_front(1);
2462 //    }
2463
2464 //    if ((*it)->GetNodeOutPortsSize()) {
2465 //      if ((*it)->GetNodeOutPortsSize()==1){
2466 //      if ( (*it)->GetNodeOutPort(0)->IsPortConnected() ){
2467 //        _headNodes.push_front(*it);
2468 //      }
2469 //      else {
2470 //        cerr << "Le port de sortie du noeud serveur de donnees "
2471 //               << (*it)->Name() << " du graphe  " << _G->Name()
2472 //               << " n'est pas connecte "<< endl;
2473 //        _dataServerError.push_front(4);
2474 //      }
2475 //      }
2476 //      else {
2477 //      cerr << "Plus d'une donnee importee du noeud serveur de donnees "
2478 //             << (*it)->Name() << " du graphe  " << _G->Name() << endl;
2479 //      _dataServerError.push_front(2);
2480 //      }
2481 //    }
2482
2483 //    if ((*it)->GetNodeInPortsSize()) {
2484 //      if ((*it)->GetNodeInPortsSize() > 1){
2485 //      cerr << "Plus d'une donnee exportee vers le noeud serveur de donnees "
2486 //             << (*it)->Name() << " du graphe  " << _G->Name() << endl;
2487 //      _dataServerError.push_front(3);
2488 //      }
2489 //      else
2490 //      if ( !(*it)->GetNodeInPort(0)->IsPortConnected() ){
2491 //      cerr << "Le port d'entree du noeud serveur de donnees "
2492 //             << (*it)->Name() << " du graphe  " << _G->Name()
2493 //             << " n'est pas connecte "<< endl;
2494 //      _dataServerError.push_front(5);
2495 //      }
2496 //    }
2497 //    it++ ;
2498 //  };
2499
2500 //  return _dataServerError.size ();
2501   return ( ierr == 0 ) ;
2502 }
2503
2504 SUPERV::GraphState GraphBase::Graph::PortState(
2505                                    const char* NodeName ,
2506                                    const char* ServiceParameterName ) {
2507   SUPERV::GraphState aRet = SUPERV::UndefinedState ;
2508 //  cdebug << "GraphBase::Graph::PortState( " << NodeName << " , "
2509 //         << ServiceParameterName << " )" << endl ;
2510
2511   char *theNode ;
2512   char *aPort ;
2513   NodePort( NodeName , ServiceParameterName , &theNode , &aPort ) ;
2514
2515   GraphBase::ComputingNode * aNode = GetChangeGraphNode( theNode ) ;
2516   if ( aNode ) {
2517     GraphBase::OutPort *anOutPort ;
2518     anOutPort = aNode->GetChangeOutPort( aPort );
2519     if ( anOutPort == NULL ) {
2520       GraphBase::InPort *anInPort = aNode->GetChangeInPort( aPort );
2521       if ( anInPort )
2522         anOutPort = anInPort->GetOutPort() ;
2523       else {
2524         cdebug << "ERROR GraphBase::Graph::PortState OutPort/InPort not found --> "
2525                << aRet << endl ;
2526       }
2527     }
2528     if ( anOutPort ) {
2529       aRet = anOutPort->State() ;
2530 //      cdebug << "GraphBase::Graph::PortState --> " << aRet << endl ;
2531     }
2532   }
2533   else {
2534     cdebug << "ERROR GraphBase::Graph::PortState Node not found --> " << aRet
2535            << endl ;
2536   }
2537   delete theNode ;
2538   delete aPort ;
2539   return aRet ;
2540 }
2541
2542 const CORBA::Any * GraphBase::Graph::PortInData( const char* ToNodeName ,
2543                                                  const char* ToServiceParameterName ) {
2544   const CORBA::Any * aRet = new CORBA::Any() ;
2545   char *theNode ;
2546   char *aPort ;
2547 //  cdebug_in << "GraphBase::Graph::PortInData " << ToNodeName << " "
2548 //            << ToServiceParameterName << endl ;
2549   NodePort( ToNodeName , ToServiceParameterName , &theNode , &aPort ) ;
2550
2551   GraphBase::ComputingNode * aNode = GetChangeGraphNode( theNode ) ;
2552
2553   if ( aNode ) {
2554     GraphBase::OutPort *anOutPort = NULL ;
2555     GraphBase::InPort *anInPort = aNode->GetChangeInPort( aPort );
2556     if ( anInPort ) {
2557       anOutPort = anInPort->GetOutPort() ;
2558       if ( anOutPort ) {
2559         aRet = anOutPort->Value() ;
2560         cdebug << "OutPort value " << anOutPort->NodeName() << "("
2561                << anOutPort->PortName() << ") --> InPort " << anInPort->NodeName()
2562                << "(" << anInPort->PortName() << ") " << anInPort->PortStatus() << endl ;
2563       }
2564       else {
2565         cdebug << "GraphBase::Graph::PortInData " << ToNodeName << " "
2566                << ToServiceParameterName << " ERROR no OutPort" << endl ;
2567       }
2568     }
2569     else {
2570       cdebug << "GraphBase::Graph::PortInData " << ToNodeName << " "
2571              << ToServiceParameterName << " ERROR no InPort" << endl ;
2572     }
2573   }
2574   else {
2575     cdebug << "GraphBase::Graph::PortInData " << ToNodeName << " "
2576            << ToServiceParameterName << " ERROR no Node" << endl ;
2577   }
2578   delete theNode ;
2579   delete aPort ;
2580 //  cdebug_out << "GraphBase::Graph::PortInData " << endl ;
2581   return aRet ;
2582 }
2583
2584 const CORBA::Any * GraphBase::Graph::PortOutData( const char* FromNodeName ,
2585                                                   const char* FromServiceParameterName ) {
2586   const CORBA::Any * aRet = new CORBA::Any() ;
2587   char *theNode ;
2588   char *aPort ;
2589 //  cdebug_in << "GraphBase::Graph::PortOutData " << FromNodeName << " "
2590 //            << FromServiceParameterName << endl ;
2591   NodePort( FromNodeName , FromServiceParameterName , &theNode , &aPort ) ;
2592
2593   GraphBase::ComputingNode * aNode = GetChangeGraphNode( theNode ) ;
2594
2595   if ( aNode ) {
2596     GraphBase::OutPort *anOutPort ;
2597     anOutPort = aNode->GetChangeOutPort( aPort );
2598     if ( anOutPort ) {
2599       aRet = anOutPort->Value() ;
2600     }
2601     else {
2602       cdebug << "GraphBase::Graph::PortOutData " << FromNodeName << " "
2603              << FromServiceParameterName << " ERROR no OutPort" << endl ;
2604     }
2605   }
2606   else {
2607     cdebug << "GraphBase::Graph::PortOutData " << FromNodeName << " "
2608            << FromServiceParameterName << " ERROR no Node" << endl ;
2609   }
2610   delete theNode ;
2611   delete aPort ;
2612 //  cdebug_out << "GraphBase::Graph::PortOutData " << endl ;
2613   return aRet ;
2614 }
2615
2616 SUPERV::ListOfStrings * GraphBase::Graph::LevelNodes(long aLevel ) {
2617   SUPERV::ListOfStrings_var RetVal = new SUPERV::ListOfStrings;
2618   if ( aLevel >= 0 && aLevel <= _LevelsNumber ) {
2619     int i ;
2620     RetVal->length( _NodesNumber[ aLevel ] + 1 );
2621     for ( i= 0 ; i <= _NodesNumber[ aLevel ] ; i++ ) {
2622       RetVal[i] = CORBA::string_dup( (_SortedNodes[ aLevel ])[ i ]->Name() ) ;
2623     }
2624   }
2625   return ( RetVal._retn() ) ;
2626 }
2627
2628 bool GraphBase::Graph::StartComponent(const int aThread ,
2629                                       const char * aComputerContainer ,
2630                                       const char * ComponentName ,
2631                                       Engines::Container_var & myContainer ,
2632                                       Engines::Component_var & objComponent ) {
2633   cdebug_in << aThread
2634             << " GraphBase::Graph::StartComponent " << aComputerContainer
2635             << " " << ComponentName << endl;
2636   bool RetVal = true ;
2637
2638   SALOME_LifeCycleCORBA LCC( NamingService() ) ;
2639   objComponent = LCC.FindOrLoad_Component( aComputerContainer ,
2640                                            ComponentName );
2641   if ( CORBA::is_nil( objComponent ) ) {
2642     cdebug_out << aThread 
2643                << " StartComponent cannot FindOrLoad " << aComputerContainer
2644                << " " << ComponentName << " ERROR" << endl;
2645     return 0 ;
2646   }
2647   else {
2648     myContainer = LCC.FindContainer( aComputerContainer );
2649     if ( CORBA::is_nil( myContainer ) ) {
2650       cdebug_out << aThread
2651                  << " GraphBase::Graph::StartComponent myContainer = LCC.FindContainer( '"
2652                  << aComputerContainer << "' ) Container does not exist ERROR"
2653                  << endl ;
2654       return 0 ;
2655     }
2656   }
2657   cdebug_out << aThread << " GraphBase::Graph::StartComponent " << RetVal << endl;
2658   return RetVal ;
2659 }