Salome HOME
MPV: Merge V1_2d
[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_Graph.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 char * DebugFileName ) :
44            DataNode( ORB ,ptrNamingService , DataFlowName ) {
45   Set_prof_debug( ORB , DebugFileName ) ;
46   cdebug << "GraphBase::Graph::Graph( " << DataFlowName << ")" << endl ;
47   _Orb = CORBA::ORB::_duplicate( ORB ) ;
48   _GraphNodesSize = 0 ;
49 }
50
51 GraphBase::Graph::Graph( CORBA::ORB_ptr ORB ,
52                          SALOME_NamingService* ptrNamingService ,
53                          const SALOME_ModuleCatalog::Service& DataFlowService ,
54                          const char *DataFlowComponentName ,
55                          const char *DataFlowInterfaceName ,
56                          const char *DataFlowName ,
57                          const SUPERV::KindOfNode DataFlowkind ,
58                          const SUPERV::SDate DataFlowFirstCreation ,
59                          const SUPERV::SDate DataFlowLastModification ,
60                          const char * DataFlowEditorRelease ,
61                          const char * DataFlowAuthor ,
62                          const char * DataFlowComputer ,
63                          const char * DataFlowComment ,
64                          const char * DebugFileName ) :
65            DataNode( ORB , ptrNamingService , DataFlowService ,
66                      DataFlowName , DataFlowkind ,
67                      DataFlowFirstCreation , DataFlowLastModification  ,
68                      DataFlowEditorRelease , DataFlowAuthor , DataFlowComment ) {
69   _Orb = CORBA::ORB::_duplicate( ORB ) ;
70   _GraphNodesSize = 0 ;
71   Set_prof_debug( ORB , DebugFileName ) ;
72   cdebug_in << "GraphBase::Graph::Graph" << endl ;
73   DataService( ORB , DataFlowService , Graph_prof_debug() , Graph_fdebug() ) ;
74   cdebug_out << "GraphBase::Graph::Graph" << endl ;
75 }
76
77 GraphBase::Graph::~Graph() {
78   cdebug << "GraphBase::Graph::~Graph" << endl ;
79 }
80
81 void GraphBase::Graph::Set_prof_debug( CORBA::ORB_ptr ORB ,
82                                        const char * DebugFileName ) {
83   _Graph_prof_debug = 0 ;
84   if ( DebugFileName ) {
85     _Graph_fdebug = new ofstream( DebugFileName );
86     MESSAGE( endl << "Trace redirected to file " << DebugFileName << endl)
87     SetDebug( ORB , &_Graph_prof_debug , _Graph_fdebug ) ;
88   }
89   cdebug << "GraphBase::Graph::Set_prof_debug redirect Trace to file " << DebugFileName << endl ;
90 }
91
92 GraphBase::SNode * GraphBase::Graph::GetInfo() const {
93   GraphBase::SNode * Info = new GraphBase::SNode ;
94   Info->theComponentName = "" ;
95   Info->theInterfaceName = "" ;
96   Info->theName = Name() ;
97   Info->theKind = Kind() ;
98   Info->theService = *GetService() ;
99   Info->theFirstCreation = FirstCreation() ;
100   Info->theLastModification = LastModification() ;
101   Info->theEditorRelease = EditorRelease() ;
102   Info->theAuthor = Author() ;
103   Info->theContainer = "" ;
104   Info->theComment = Comment() ;
105   Info->theCoords.theX = GraphBase::ComputingNode::XCoordinate() ;
106   Info->theCoords.theY = GraphBase::ComputingNode::YCoordinate() ;
107   return Info ;
108 }
109
110 //----------------------------------------------------------------------
111 // Function : GetNodes
112 // Purpose  : get a nodes list
113 //----------------------------------------------------------------------
114 GraphBase::ListOfNodes * GraphBase::Graph::GetNodes() const {
115   GraphBase::ListOfNodes * _list_nodes = 
116                                   new GraphBase::ListOfNodes;
117
118   // All the nodes from _InNodes are taken
119 //  vector< InNode *> Nodes = InNodes() ;
120
121   _list_nodes->resize( GraphNodesSize() );
122
123   int igoto ;
124   int ind ;
125   GraphBase::ComputingNode * aCNode = NULL ;
126   for ( igoto = 0 ; igoto < 2 ; igoto++ ) {
127     for ( ind = 0 ; ind < GraphNodesSize() ; ind++ ) {
128       aCNode = GraphNodes( ind ) ;
129       if ( ( igoto == 0 && !aCNode->IsGOTONode() ) ||
130            ( igoto == 1 && aCNode->IsGOTONode() ) ) {
131         if ( aCNode->IsFactoryNode() ) {
132           GraphBase::FactoryNode * aFNode = (GraphBase::FactoryNode * ) aCNode ;
133           (*_list_nodes)[ind].theComponentName = CORBA::string_dup( aFNode->ComponentName());
134           (*_list_nodes)[ind].theInterfaceName = CORBA::string_dup( aFNode->InterfaceName());
135         }
136         else {
137           (*_list_nodes)[ind].theComponentName = CORBA::string_dup( "" );
138           (*_list_nodes)[ind].theInterfaceName = CORBA::string_dup( "" );
139         }
140         (*_list_nodes)[ind].theName = CORBA::string_dup( aCNode->Name() );
141         (*_list_nodes)[ind].theKind = aCNode->Kind();
142         if ( aCNode->IsInLineNode() ) {
143           GraphBase::InLineNode * aINode = (GraphBase::InLineNode * ) aCNode ;
144           (*_list_nodes)[ind].theListOfFuncName.resize( 1 ) ;
145           (*_list_nodes)[ind].theListOfFuncName[0] = CORBA::string_dup( aINode->PyFuncName() ) ;
146           (*_list_nodes)[ind].theListOfPythonFunctions.resize( 1 ) ;
147           (*_list_nodes)[ind].theListOfPythonFunctions[0] = aINode->PythonFunction() ;
148         }
149         if ( aCNode->IsGOTONode() ) {
150           GraphBase::GOTONode * aGNode = (GraphBase::GOTONode * ) aCNode ;
151           (*_list_nodes)[ind].theListOfFuncName.resize( 1 ) ;
152           (*_list_nodes)[ind].theListOfFuncName[0] = CORBA::string_dup( aGNode->PyFuncName() ) ;
153           (*_list_nodes)[ind].theListOfPythonFunctions.resize( 1 ) ;
154           (*_list_nodes)[ind].theListOfPythonFunctions[0] = aGNode->PythonFunction() ;
155         }
156         if ( aCNode->IsLoopNode() ) {
157           GraphBase::LoopNode * aLNode = (GraphBase::LoopNode * ) aCNode ;
158           (*_list_nodes)[ind].theCoupledNode = CORBA::string_dup( aLNode->CoupledNode()->Name() ) ;
159           (*_list_nodes)[ind].theListOfFuncName.resize( 3 ) ;
160           (*_list_nodes)[ind].theListOfFuncName[0] = CORBA::string_dup( aLNode->PyFuncName() ) ;
161           (*_list_nodes)[ind].theListOfFuncName[1] = CORBA::string_dup( aLNode->PyMoreName() ) ;
162           (*_list_nodes)[ind].theListOfFuncName[2] = CORBA::string_dup( aLNode->PyNextName() ) ;
163           (*_list_nodes)[ind].theListOfPythonFunctions.resize( 3 ) ;
164           (*_list_nodes)[ind].theListOfPythonFunctions[0] = aLNode->PythonFunction() ;
165           (*_list_nodes)[ind].theListOfPythonFunctions[1] = aLNode->MorePythonFunction() ;
166           (*_list_nodes)[ind].theListOfPythonFunctions[2] = aLNode->NextPythonFunction() ;
167         }
168         else if ( aCNode->IsSwitchNode() ) {
169           GraphBase::SwitchNode * aSNode = (GraphBase::SwitchNode * ) aCNode ;
170           (*_list_nodes)[ind].theCoupledNode = CORBA::string_dup( aSNode->CoupledNode()->Name() ) ;
171           (*_list_nodes)[ind].theListOfFuncName.resize( 1 ) ;
172           (*_list_nodes)[ind].theListOfFuncName[0] = CORBA::string_dup( aSNode->PyFuncName() ) ;
173           (*_list_nodes)[ind].theListOfPythonFunctions.resize( 1 ) ;
174           (*_list_nodes)[ind].theListOfPythonFunctions[0] = aSNode->PythonFunction() ;
175         }
176         else if ( aCNode->IsEndLoopNode() ) {
177           GraphBase::EndOfLoopNode * aELNode = (GraphBase::EndOfLoopNode * ) aCNode ;
178           (*_list_nodes)[ind].theCoupledNode = CORBA::string_dup( aELNode->CoupledNode()->Name() ) ;
179           (*_list_nodes)[ind].theListOfFuncName.resize( 1 ) ;
180           (*_list_nodes)[ind].theListOfFuncName[0] = CORBA::string_dup( aELNode->PyFuncName() ) ;
181           (*_list_nodes)[ind].theListOfPythonFunctions.resize( 1 ) ;
182           (*_list_nodes)[ind].theListOfPythonFunctions[0] = aELNode->PythonFunction() ;
183         }
184         else if ( aCNode->IsEndSwitchNode() ) {
185           GraphBase::EndOfSwitchNode * aESNode = (GraphBase::EndOfSwitchNode * ) aCNode ;
186           (*_list_nodes)[ind].theCoupledNode = CORBA::string_dup( aESNode->CoupledNode()->Name() ) ;
187           (*_list_nodes)[ind].theListOfFuncName.resize( 1 ) ;
188           (*_list_nodes)[ind].theListOfFuncName[0] = CORBA::string_dup( aESNode->PyFuncName() ) ;
189           (*_list_nodes)[ind].theListOfPythonFunctions.resize( 1 ) ;
190           (*_list_nodes)[ind].theListOfPythonFunctions[0] = aESNode->PythonFunction() ;
191         }
192         else {
193           (*_list_nodes)[ind].theCoupledNode = CORBA::string_dup( "" ) ;
194         }
195         (*_list_nodes)[ind].theService = *aCNode->GetService();
196 //        (*_list_nodes)[ind].theListOfParameters = *aCNode->GetListOfParameters() ;
197         if ( aCNode->IsOneOfInLineNodes() ) {
198           GraphBase::InLineNode * aINode = (GraphBase::InLineNode * ) aCNode ;
199           GraphBase::LoopNode * aLNode = NULL ;
200           if ( aCNode->IsLoopNode() ) {
201             aLNode = (GraphBase::LoopNode * ) aCNode ;
202             (*_list_nodes)[ind].theListOfPythonFunctions.resize( 3 ) ;
203             (*_list_nodes)[ind].theListOfPythonFunctions[ 0 ] = aINode->PythonFunction() ;
204             (*_list_nodes)[ind].theListOfPythonFunctions[ 1 ] = aLNode->MorePythonFunction() ;
205             (*_list_nodes)[ind].theListOfPythonFunctions[ 2 ] = aLNode->NextPythonFunction() ;
206           }
207           else if ( aCNode->IsInLineNode() || aCNode->IsGOTONode() ||
208                     aCNode->IsSwitchNode() || aCNode->IsEndSwitchNode() ) {
209             (*_list_nodes)[ind].theListOfPythonFunctions.resize( 1 ) ;
210             (*_list_nodes)[ind].theListOfPythonFunctions[ 0 ] = aINode->PythonFunction() ;
211           }
212         }
213         (*_list_nodes)[ind].theFirstCreation = aCNode->FirstCreation();
214         (*_list_nodes)[ind].theLastModification = aCNode->LastModification();
215         (*_list_nodes)[ind].theEditorRelease = CORBA::string_dup( aCNode->EditorRelease());
216         (*_list_nodes)[ind].theAuthor = CORBA::string_dup( aCNode->Author());
217         if ( aCNode->IsFactoryNode() ) {
218           GraphBase::FactoryNode * aFNode = (GraphBase::FactoryNode * ) aCNode ;
219           (*_list_nodes)[ind].theContainer = CORBA::string_dup( aFNode->Computer());
220         }
221         else {
222           (*_list_nodes)[ind].theContainer = CORBA::string_dup( "" );
223         }
224         (*_list_nodes)[ind].theComment = CORBA::string_dup( aCNode->Comment());
225         (*_list_nodes)[ind].theCoords.theX = aCNode->XCoordinate();
226         (*_list_nodes)[ind].theCoords.theY = aCNode->YCoordinate();
227 #if 0
228         int nports = 0 ;
229         int i ;
230         for ( i = 0 ; i < aCNode->GetNodeInPortsSize() ; i++ ) {
231           const GraphBase::InPort * anInPort = aCNode->GetNodeInPort( i ) ;
232           if ( anInPort->IsBus() ) {
233             nports += 1 ;
234             (*_list_nodes)[ind].theListOfParameters.resize( nports ) ;
235             (*_list_nodes)[ind].theListOfParameters[ nports-1 ].theInParameter.Parametertype = CORBA::string_dup( anInPort->PortType() ) ;
236             (*_list_nodes)[ind].theListOfParameters[ nports-1 ].theInParameter.Parametername = CORBA::string_dup( anInPort->PortName() ) ;
237             (*_list_nodes)[ind].theListOfParameters[ nports-1 ].theOutParameter.Parametertype = CORBA::string_dup( aCNode->GetNodeOutPort( anInPort->PortIndex() )->PortType() ) ;
238             (*_list_nodes)[ind].theListOfParameters[ nports-1 ].theOutParameter.Parametername = CORBA::string_dup( aCNode->GetNodeOutPort( anInPort->PortIndex() )->PortName() ) ;
239           }
240         }
241 #endif
242       }
243     }
244   }
245   return _list_nodes ;
246 }
247
248
249 //----------------------------------------------------------------------
250 // Function : GetLinks
251 // Purpose  : get a links list
252 //----------------------------------------------------------------------
253 GraphBase::ListOfLinks * GraphBase::Graph::GetLinks(bool AllLinks ) const {
254   GraphBase::ListOfLinks * _list_links = 
255                                new GraphBase::ListOfLinks;
256
257 // All the links from _LinksList are taken
258 //  vector< InNode *> Nodes = InNodes() ;
259
260   int ind = 0 ;
261   int k ;
262   for ( k = 0 ; k < GraphNodesSize() ; k++ ) {
263     GraphBase::ComputingNode * fromNode = GraphNodes( k ) ;
264     int i ;
265     for ( i = 0 ; i < fromNode->GetNodeOutPortsSize() ; i++ ) {
266       const GraphBase::OutPort* fromPort = fromNode->GetNodeOutPort( i ) ;
267 //      if ( fromPort->IsPortConnected() && ( !fromPort->IsLoop() || AllLinks ) ) {
268         int j ;
269         for ( j = 0 ; j < fromPort->InPortsSize() ; j++ ) {
270           const GraphBase::InPort* toPort = fromPort->InPorts( j ) ;
271 // Desole pour ce cast mais avec les maps difficile de faire const ...
272           const GraphBase::ComputingNode * toNode = ((GraphBase::Graph * ) this)->GetGraphNode( toPort->NodeName() ) ;
273           if ( !(fromPort->IsLoop() && toPort->IsLoop() ) || AllLinks ) {
274             cdebug << "GraphBase::Graph::GetLinks " << fromNode->Name() << " ("
275                    << fromPort->PortName() << " ) IsPortConnected" << fromPort->IsPortConnected()
276                    << " --> " << toNode->Name() << "( " << toPort->PortName() << " ) "
277                    << " " << fromPort->InPortsSize() << " ports" << endl ;
278             _list_links->resize( ind+1 );
279             (*_list_links)[ind].FromNodeName = CORBA::string_dup( fromNode->Name() );
280             (*_list_links)[ind].FromServiceParameterName = fromPort->GetServicesParameter().Parametername;
281             (*_list_links)[ind].ToNodeName = CORBA::string_dup( toPort->NodeName() );
282             (*_list_links)[ind].ToServiceParameterName = toPort->GetServicesParameter().Parametername;
283             (*_list_links)[ind].aLinkValue = *fromPort->Value() ;
284             if ( toPort->IsEndSwitch() ) {
285               (*_list_links)[ind++].aListOfCoords = *(fromPort->Coords()) ;
286             }
287             else {
288               (*_list_links)[ind++].aListOfCoords = *(toPort->Coords()) ;
289             }
290           }
291           else {
292             cdebug << "GraphBase::Graph::GetLinks " << fromNode->Name() << " "
293                    << fromPort->PortName() << " ) IsPortConnected" << fromPort->IsPortConnected()
294                    << " --> " << toNode->Name() << "( " << toPort->PortName() << " ) "
295                    << " " << fromPort->InPortsSize() << " ports ignored" << endl ;
296           }
297         }
298 //      }
299     }
300   }
301
302   return _list_links;
303 }
304
305 GraphBase::ListOfGraphs * GraphBase::Graph::GetGraphs() const {
306   GraphBase::ListOfGraphs * _list_graphs = 
307                                new GraphBase::ListOfGraphs;
308
309   return _list_graphs;
310 }
311
312 GraphBase::SLink * GraphBase::Graph::GetLink( GraphBase::ComputingNode * aNode ,
313                                               GraphBase::InPort* toPort ) {
314   GraphBase::SLink * _link =  new GraphBase::SLink ;
315   GraphBase::OutPort* fromPort = toPort->GetOutPort() ;
316   _link->FromNodeName = CORBA::string_dup( fromPort->NodeName() );
317   _link->FromServiceParameterName = fromPort->GetServicesParameter().Parametername;
318   _link->ToNodeName = CORBA::string_dup( toPort->NodeName() );
319   _link->ToServiceParameterName = toPort->GetServicesParameter().Parametername;
320   CORBA::Any aSPValue = *fromPort->Value() ;
321   _link->aLinkValue = aSPValue;
322   _link->aListOfCoords = *(toPort->Coords()) ;
323   return _link;
324 }
325 //----------------------------------------------------------------------
326 // Function : GetDatas
327 // Purpose  : get the datas list
328 //----------------------------------------------------------------------
329 GraphBase::ListOfLinks * GraphBase::Graph::GetDatas() const {
330   GraphBase::ListOfLinks * _list_datalinks = 
331                                new GraphBase::ListOfLinks;
332
333   int ind = 0 ;
334   const GraphBase::DataNode * aDataNode = this ;
335   int i ;
336   for ( i = 0 ; i < aDataNode->GetNodeInDataNodePortsSize() ; i++ ) {
337     const GraphBase::OutPort* fromDataPort = aDataNode->GetNodeInDataNodePort( i ) ;
338     if ( fromDataPort->IsDataConnected() ) {
339       int j ;
340 //We may have SharedData as input of a DataFlow : same input for one or several
341 // input ports. Input(s) of a DataFlow match one or several output-virtual-dataport
342       for ( j = 0 ; j < fromDataPort->InPortsSize() ; j++ ) {
343         _list_datalinks->resize( ind+1 );
344         (*_list_datalinks)[ind].FromNodeName = CORBA::string_dup( aDataNode->Name() );
345         (*_list_datalinks)[ind].FromServiceParameterName = fromDataPort->GetServicesParameter().Parametername;
346         const GraphBase::InPort* toPort = fromDataPort->InPorts( j ) ;
347         (*_list_datalinks)[ind].ToNodeName = CORBA::string_dup( toPort->NodeName() );
348         (*_list_datalinks)[ind].ToServiceParameterName = toPort->GetServicesParameter().Parametername;
349           CORBA::Any aSPValue = *fromDataPort->Value() ;
350         (*_list_datalinks)[ind].aLinkValue = aSPValue;
351         (*_list_datalinks)[ind++].aListOfCoords = *(toPort->Coords()) ;
352       }
353     }
354   }
355
356 #if 0
357 // Output(s) of a DataFlow match only one input-virtual-dataport
358   for ( i = 0 ; i < aDataNode->GetNodeOutDataNodePortsSize() ; i++ ) {
359     GraphBase::InPort* toDataPort = aDataNode->GetChangeNodeOutDataNodePort( i ) ;
360     const GraphBase::OutPort* fromPort = toDataPort->GetLink() ;
361     if ( fromPort->IsDataConnected() ) {
362       _list_datalinks->length( ind+1 );
363       _list_datalinks[ind].FromNodeName = CORBA::string_dup( fromPort->NodeName() );
364       _list_datalinks[ind].FromServiceParameterName = fromPort->GetServicesParameter().Parametername;
365       _list_datalinks[ind].ToNodeName = CORBA::string_dup( aDataNode->Name() );
366       _list_datalinks[ind].ToServiceParameterName = toDataPort->GetServicesParameter().Parametername;
367 //      SALOME_SuperVisionBase::ServicesParameterValue aSPValue;
368           CORBA::Any aSPValue = *fromPort->Value() ;
369 //      aSPValue.Value = CORBA::string_dup( fromPort->Value() );
370 //      aSPValue.Kind = fromPort->Kind();
371       _list_datalinks[ind].aLinkValue = aSPValue;
372       _list_datalinks[ind++].aListOfCoords = toDataPort->Coords() ;
373     }
374   }
375 #endif
376
377   return _list_datalinks ;
378 }
379
380 bool GraphBase::Graph::AddNode( GraphBase::ComputingNode * aNode ) {
381   cdebug_in << "GraphBase::Graph::AddNode "  << (void *) aNode << " "
382             << aNode->Name() << " " << aNode->ServiceName() << endl;
383   bool RetVal = false ;
384   int index = GetGraphNodeIndex( aNode->Name() ) ;
385   if ( index < 0 ) {
386     _GraphNodes.resize( _GraphNodesSize+1 ) ;
387     _GraphNodes[ _GraphNodesSize ] = aNode ;
388     SetGraphNodeIndex( aNode->Name() , _GraphNodesSize ) ;
389     _GraphNodesSize += 1 ;
390     RetVal = true ;
391   }
392 //  cout << "GraphBase::Graph::AddNode(" << aNode->ComponentName() << " , "
393 //       << aNode->Name() << ")" << endl;
394   int i ;
395   cdebug << "GraphBase::Graph::AddNode Known nodes :" << endl ;
396   for ( i = 0 ; i < _GraphNodesSize ; i++ ) {
397     cdebug << i << ". " << GetGraphNode( i )->Name() << " "
398            << _MapOfGraphNodes[ GetGraphNode( i )->Name() ] - 1 << endl ;
399   }
400   cdebug_out << "GraphBase::Graph::AddNode " << _GraphNodesSize << " Nodes. "
401              << aNode->ServiceName() << endl;
402   return RetVal ;
403 }
404
405 bool GraphBase::Graph::ReNameNode( const char* OldNodeName ,
406                                    const char* NewNodeName ) {
407   cdebug_in << "GraphBase::Graph::ReNameNode (" << OldNodeName << " , "
408             << NewNodeName << ")" << endl;
409   int i ;
410   bool RetVal = false ;
411   if ( !strcmp( OldNodeName , NewNodeName ) ) {
412     RetVal = true ;
413   }
414   else if ( strcmp( Name() , OldNodeName ) ) {
415     int index = GetGraphNodeIndex( OldNodeName ) ;
416     int newindex = GetGraphNodeIndex( NewNodeName ) ;
417     if ( index >= 0 && index < _GraphNodesSize &&
418          ( newindex < 0 || newindex > _GraphNodesSize ) ) {
419       _GraphNodes[ index ]->Name( NewNodeName ) ;
420       _MapOfGraphNodes.erase( OldNodeName ) ;
421       SetGraphNodeIndex( NewNodeName , index ) ;
422
423       GraphBase::ComputingNode * aNode = GetChangeGraphNode( index ) ;
424       for ( i = aNode->GetNodeInPortsSize()-1 ; i >= 0 ; i-- ) {
425         cdebug << i << ". GraphBase::Graph::ReNameNode of LinkedNode : from " ;
426         GraphBase::InPort * anInPort = aNode->GetChangeNodeInPort( i ) ;
427         GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
428         if ( anOutPort ) {
429           cdebug << anOutPort->NodeName() ;
430         }
431         else {
432           cdebug << "without link" ;
433         }
434         cdebug << " to " << i << ". " << anInPort->PortName()
435                << " of " << NewNodeName ;
436         if ( anInPort->IsConnected() ) {
437           if ( anOutPort->IsDataConnected() ) {
438             cdebug << " fromDataConnected "
439                    << anOutPort->NodeName()
440                    << endl ;
441           }
442           else {
443             GraphBase::ComputingNode * FromNode = GetChangeGraphNode( anOutPort->NodeName() ) ;
444             cdebug << " fromConnected " << FromNode->Name() << endl ;
445             FromNode->ReNameLink( OldNodeName , NewNodeName ) ;
446           }
447           char* OldNodePortName = new char[ strlen( OldNodeName ) +
448                                             strlen( aNode->GetChangeNodeInPort( i )->PortName() ) + 2 ] ;
449           char* NewNodePortName = new char[ strlen( NewNodeName ) +
450                                             strlen( aNode->GetChangeNodeInPort( i )->PortName() ) + 2 ] ;
451           strcpy( OldNodePortName , OldNodeName ) ;
452           strcat( OldNodePortName , "\\" ) ;
453           strcat( OldNodePortName , aNode->GetChangeNodeInPort( i )->PortName() ) ;
454           strcpy( NewNodePortName , NewNodeName ) ;
455           strcat( NewNodePortName , "\\" ) ;
456           strcat( NewNodePortName , aNode->GetChangeNodeInPort( i )->PortName() ) ;
457           RetVal = anOutPort->ReNameInPort( OldNodePortName , NewNodePortName ) ;
458           delete [] OldNodePortName ;
459           delete [] NewNodePortName ;
460           if ( !RetVal )
461             break ;
462         }
463         else {
464           cdebug << " not connected" << endl ;
465           RetVal = true ;
466         }
467       }
468       RetVal = true ;
469     }
470     else {
471       cdebug << "Node not found" << endl ;
472     }
473   }
474   else {
475     RetVal = Name( NewNodeName ) ;
476   }
477
478   cdebug_out << "GraphBase::Graph::ReNameNode" << endl;
479   return RetVal ;
480 }
481
482 bool GraphBase::Graph::RemoveNode( const char* aNodeName ) {
483   cdebug_in << "GraphBase::Graph::RemoveNode (" << aNodeName << ")" << endl;
484   int i ;
485   bool RetVal = false ;
486   int index = GetGraphNodeIndex( aNodeName ) ;
487   GraphBase::ComputingNode * aNode = GetChangeGraphNode( index ) ;
488   if ( aNode ) {
489     if ( aNode->GetNodeInPortsSize() ) {
490       for ( i = aNode->GetNodeInPortsSize()-1 ; i >= 0 ; i-- ) {
491         cdebug << i << ". GraphBase::Graph::RemoveNode of LinkedNode : from " ;
492         GraphBase::InPort * anInPort = aNode->GetChangeNodeInPort( i ) ;
493         GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
494         if ( anOutPort ) {
495           cdebug << anOutPort->NodeName() ;
496         }
497         else {
498           cdebug << "without link" ;
499         }
500         cdebug << " to " << i << ". " << anInPort->PortName()
501                << " of " << aNodeName ;
502         if ( anInPort->IsConnected() ) {
503           if ( anOutPort->IsDataConnected() ) {
504             cdebug << " fromDataConnected " << anOutPort->NodeName() << endl ;
505           }
506           else {
507             GraphBase::ComputingNode * FromNode = GetChangeGraphNode( anOutPort->NodeName() ) ;
508             cdebug << " fromConnected " << FromNode->Name() << endl ;
509             FromNode->RemoveLink( aNode ) ;
510           }
511           RetVal = anOutPort->RemoveInPort( anInPort ) ;
512           if ( !RetVal )
513             break ;
514         }
515         else {
516           cdebug << " not connected" << endl ;
517           RetVal = true ;
518         }
519       }
520     }
521     else {
522       RetVal = true ;
523     }
524     if ( RetVal ) {
525       for ( i = aNode->GetNodeOutPortsSize() - 1 ; i >= 0 ; i-- ) {
526         GraphBase::OutPort * anOutPort = aNode->GetChangeNodeOutPort( i ) ;
527         cdebug << "GraphBase::Graph::Remove " <<anOutPort->InPortsSize()
528                << " Links of OutPort : " << i << ". "
529                << *aNode->GetChangeNodeOutPort( i ) ;
530         int j ;
531         for ( j = anOutPort->InPortsSize() - 1 ; j >= 0  ; j-- ) {
532           cdebug << "       to " << j << ". " << *anOutPort->InPorts( j )
533                  << endl ;
534           RetVal = anOutPort->ChangeInPorts( j )->RemoveOutPort() ;
535           if ( !RetVal )
536             break ;
537           GraphBase::ComputingNode * ToNode = GetChangeGraphNode( anOutPort->InPorts( j )->NodeName() ) ;
538           aNode->RemoveLink( ToNode ) ;
539           RetVal = anOutPort->RemoveInPort( anOutPort->ChangeInPorts( j ) ) ;
540           if ( !RetVal )
541             break ;
542         }
543 //        RetVal = aNode->GetChangeNodeOutPort( j )->RemoveLinks() ;
544         if ( !RetVal )
545           break ;
546       }
547     }
548 //    RetVal = aNode->RemoveLinks() ; // In PortsOfNode
549 //    if ( RetVal ) {
550 //      if ( aNode->IsLoopNode() || aNode->IsEndLoopNode() || aNode->IsSwitchNode() || aNode->IsEndSwitchNode() ) {
551 //        GraphBase::InLineNode * anInLineNode =  ((GraphBase::GOTONode * ) aNode)->CoupledNode() ;
552 //        if ( anInLineNode ) {
553 //          RetVal = RemoveNode( anInLineNode->Name() ) ;
554 //        }
555 //      }
556 //    }
557     if ( RetVal ) {
558       delete aNode ;
559       _GraphNodesSize -= 1 ;
560       for ( i = index ; i < _GraphNodesSize ; i++ ) {
561         SetGraphNodeIndex( _GraphNodes[ i+1 ]->Name() , i ) ;
562         _GraphNodes[ i ] = _GraphNodes[ i+1 ] ;
563       }
564       _GraphNodes.resize( _GraphNodesSize+1 ) ;
565       _MapOfGraphNodes.erase( aNodeName ) ;
566       RetVal = true ;
567     }
568   }
569   else {
570     cdebug << "Node not found" << endl ;
571   }
572
573   cdebug_out << "GraphBase::Graph::RemoveNode" << endl;
574   return RetVal ;
575 }
576
577 bool GraphBase::Graph::AddLink( const char* FromNodeName ,
578                                 const char* FromServiceParameterName ,
579                                 const char* ToNodeName ,
580                                 const char* ToServiceParameterName ,
581                                 const CORBA::Any aValue ) {
582   bool RetVal ;
583 //  int index ;
584   cdebug_in << "GraphBase::Graph::AddLink(" << FromNodeName << "("
585             << FromServiceParameterName << ") ---> " << ToNodeName << "("
586             << ToServiceParameterName << ") )" << endl;
587
588   GraphBase::ComputingNode *fromNode = GetChangeGraphNode( FromNodeName ) ;
589   GraphBase::ComputingNode *toNode = GetChangeGraphNode( ToNodeName ) ;
590
591   GraphBase::OutPort *fromPort = NULL ;
592   GraphBase::InPort *toPort = NULL ;
593
594   if ( fromNode ) {
595     fromPort = fromNode->GetChangeOutPort( FromServiceParameterName ) ;
596     if ( !fromPort ) {
597       cdebug << "AddLink fromPort " << FromServiceParameterName << " FromNode("
598            << FromNodeName << ") not found." << endl ;
599     }
600   }
601   else {
602     cdebug << "AddLink FromNode " << FromNodeName << " not found." << endl ;
603   }
604   if ( toNode ) {
605     toPort = toNode->GetChangeInPort( ToServiceParameterName ) ;
606     if ( !toPort ) {
607       cdebug << "AddLink toPort " << ToServiceParameterName << " ToNode("
608              << ToNodeName << ") not found." << endl ;
609     }
610   }
611   else {
612     cdebug << "AddLink toNode " << ToNodeName << " not found." << endl ;
613   }
614
615   RetVal = AddLink( fromNode , fromPort , toNode , toPort ) ;
616
617   if ( RetVal ) {
618     if ( fromPort->IsGate() && toPort->IsGate() ) {
619       CORBA::Any aValue ;
620       aValue <<= (long ) 1 ;
621       fromPort->Value( aValue ) ;
622     }
623     else {
624       const CORBA::Any * aDataValue = new CORBA::Any( aValue ) ;
625       fromPort->Value( aDataValue ) ;
626     }
627   }
628
629   cdebug_out << "GraphBase::Graph::AddLink" << endl;
630   return RetVal ;
631 }
632
633 bool GraphBase::Graph::AddLink( GraphBase::ComputingNode *fromNode ,
634                                 GraphBase::OutPort *fromPort ,
635                                 GraphBase::ComputingNode *toNode ,
636                                 GraphBase::InPort *toPort ) {
637 //  bool RetVal ;
638
639   if ( !fromNode ) {
640     cdebug << "AddLink fromNode not found." << endl ;
641     return false ;
642   }
643   if ( !fromPort ) {
644     cdebug << "AddLink fromPort not found." << endl ;
645     return false ;
646   }
647
648   if ( !toNode ) {
649     cdebug << "AddLink toNode not found." << endl ;
650     return false ;
651   }
652   if ( !toPort ) {
653     cdebug << "AddLink toPort not found." << endl ;
654     return false ;
655   }
656
657   cdebug_in << "GraphBase::Graph::AddLink(" << fromNode->Name() << "("
658             << fromPort->PortName() << ") ---> " << toNode->Name() << "("
659             << toPort->PortName() << ") )" << endl;
660   if ( !fromNode->IsDataFlowNode() && !toNode->IsDataFlowNode() &&
661        toPort->GetOutPort() ) {
662     if ( !strcmp( toPort->GetOutPort()->NodePortName() ,
663                   fromPort->NodePortName() ) ) {
664       cdebug << "Link already exists" << endl ;
665       cdebug_out << "GraphBase::Graph::AddLink" << endl;
666       return true ;
667     }
668     else if ( toPort->IsDataConnected() ) {
669       toPort->RemoveOutPort() ;
670     }
671     else if ( fromNode->IsGOTONode() ) {
672       if ( !RemoveLink( toPort->GetOutPort()->NodeName() ,
673                         toPort->GetOutPort()->PortName() ,
674                         toNode->Name() , toPort->PortName() ) ) {
675         cdebug << "RemoveLink(AddLink) toPort->GetOutPort()->NodeName() Error."
676                << endl ;
677         cdebug_out << "GraphBase::Graph::AddLink" << endl;
678         return false ;
679       }
680       if ( fromPort->InPortsSize() ) {
681         if ( !RemoveLink( fromNode->Name() , fromPort->PortName() ,
682                           fromPort->ChangeInPorts(0)->NodeName() ,
683                           fromPort->ChangeInPorts(0)->PortName() ) ) {
684           cdebug << "RemoveLink(AddLink) fromNode->IsGOTONode Error." << endl ;
685           cdebug_out << "GraphBase::Graph::AddLink" << endl;
686           return false ;
687         }
688       }
689     }
690     else if ( !toNode->IsEndSwitchNode() ||
691               ( toNode->IsEndSwitchNode() && toPort->IsGate() ) ) {
692       if ( !RemoveLink( fromNode->Name() , fromPort->PortName() ,
693                         toNode->Name() , toPort->PortName() ) ) {
694         cdebug << "RemoveLink(AddLink) toNode->IsEndSwitchNode Error." << endl ;
695         cdebug_out << "GraphBase::Graph::AddLink" << endl;
696         return false ;
697       }
698     }
699   }
700   else if ( fromNode->IsGOTONode() && fromPort->InPortsSize() ) {
701     if ( !RemoveLink( fromNode->Name() , fromPort->PortName() ,
702                       fromPort->ChangeInPorts(0)->NodeName() ,
703                       fromPort->ChangeInPorts(0)->PortName() ) ) {
704       cdebug << "RemoveLink(AddLink) fromNode->IsGOTONode Error." << endl ;
705       cdebug_out << "GraphBase::Graph::AddLink" << endl;
706       return false ;
707     }
708   }
709
710   if ( toNode->IsEndSwitchNode() && !toPort->IsGate() ) {
711 //    if ( !toPort->IsEndSwitch() || !fromPort->AddInPort( toPort ) ) {
712     if ( !fromPort->AddInPort( toPort ) ) {
713       cdebug << "toNode->IsEndSwitchNode() : !fromPort->AddInPort( toPort ) AddLink Error."
714              << endl ;
715       cdebug_out << "GraphBase::Graph::AddLink" << endl;
716       return false ;
717     }
718     toPort->Kind( SUPERV::EndSwitchParameter ) ;
719   }
720   else if ( !fromPort->AddInPort( toPort ) ) { // --> MapOfInports in the OutPort
721     cdebug << "!fromPort->AddLink Error." << endl ;
722     cdebug_out << "GraphBase::Graph::AddLink" << endl;
723     return false ;
724   }
725
726   if ( fromNode->IsDataFlowNode() && toPort->IsDataConnected() ) {
727     toPort->RemoveOutPort() ;
728   }
729
730   if ( fromNode->IsGOTONode() && ( !fromPort->IsGate() || !toPort->IsGate() ||
731        toNode->IsEndLoopNode() || toNode->IsEndSwitchNode() ) ) {
732     cdebug << "toPort->AddLink Error( fromNode->IsGOTONode() && toNode->IsEndInLineNode() )." << endl ;
733     cdebug_out << "GraphBase::Graph::AddLink" << endl;
734     return false ;
735   }
736   else if ( !fromNode->IsSwitchNode() && fromPort->IsParam() && toPort->IsGate() ) {
737     cdebug << "toPort->AddLink Error( fromPort->IsParam() && toPort->IsGate())." << endl ;
738     cdebug_out << "GraphBase::Graph::AddLink" << endl;
739     return false ;
740   }
741   else if ( !toNode->IsEndSwitchNode() && !toNode->IsEndLoopNode() ) {
742     if ( !toPort->AddOutPort( fromPort ) ) { // --> Unique OutPort of the InPort
743       cdebug << "toPort->AddLink Error." << endl ;
744       cdebug_out << "GraphBase::Graph::AddLink" << endl;
745       return false ;
746     }
747   }
748   else {
749     toPort->AddOutPort( fromPort ) ;
750   }
751
752   if ( ( fromNode->IsGOTONode() && toNode->IsOneOfInLineNodes() ) ||
753        ( fromNode->IsEndLoopNode() && toNode->IsLoopNode() ) ) {
754     cdebug << "AddLink fromPort->PortStatus( PortConnected ) "
755            << "GOTONode/EndLoopNode-->InLineNode/LoopNode/SwitchNode "
756            << fromNode->Name() << " " << fromPort->PortName()
757            << " InLineNode/LoopNode_ConnectedInPortsNumber "
758            << toNode->ConnectedInPortsNumber() << endl;
759     if ( fromNode->IsGOTONode() ) {
760       fromPort->Kind( SUPERV::GOTOParameter ) ;
761     }
762     fromPort->PortStatus( PortConnected ); // GOTO - Loop
763   }
764   else if ( fromNode->IsDataFlowNode() || toNode->IsDataFlowNode() ) {
765     cdebug << "AddLink IsDataFlowNode fromPort->PortStatus( DataConnected ) "
766            << fromNode->Name() << " " << fromPort->PortName() << endl ;
767     fromPort->PortStatus( DataConnected );
768   }
769   else {
770     cdebug << "AddLink fromPort->PortStatus( PortConnected ) & fromNode->toNode "
771            << fromNode->Name() << " " << fromPort->PortName() << endl;
772     fromPort->PortStatus( PortConnected );
773     fromNode->AddLink( toNode ) ;
774   }
775   if ( fromNode->IsSwitchNode() ) {
776     if ( fromPort->IsInLine() && toPort->IsGate() && !toNode->IsEndSwitchNode() ) {
777       fromPort->Kind( SUPERV::SwitchParameter ) ;
778     }
779     else if ( !fromPort->IsGate() && !toPort->IsGate() ){
780       fromPort->Kind( SUPERV::InLineParameter ) ;
781     }
782     if ( fromPort->IsGate() && !toNode->IsEndSwitchNode() ) {
783       GraphBase::InLineNode * anEndSwitchNode ;
784       anEndSwitchNode = ((GraphBase::SwitchNode * ) fromNode)->CoupledNode() ;
785       GraphBase::InPort * anInPort = anEndSwitchNode->GetChangeNodeInGate() ;
786       GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
787       if ( anOutPort && !strcmp( fromNode->Name() , anOutPort->NodeName() ) &&
788            !strcmp( fromPort->PortName() , anOutPort->PortName() ) &&
789            anOutPort->IsGate() ) {
790         if ( !RemoveLink( fromNode->Name() , anOutPort->PortName() ,
791                           anEndSwitchNode->Name() ,
792                           anInPort->PortName() ) ) {
793           cdebug << "AddLink Error Removelink ( Switch , Default , EndSwitch , Default )"
794                  << endl ;
795           cdebug_out << "GraphBase::Graph::AddLink" << endl;
796           return false ;
797         }
798       }
799     }
800   }
801 //  cdebug << fromNode->ServiceName() << " " << toNode->ServiceName() << endl ;
802   cdebug_out << "GraphBase::Graph::AddLink" << endl;
803   return true ;
804 }
805
806 bool GraphBase::Graph::RemoveLink( const char* FromNodeName ,
807                                    const char* FromServiceParameterName ,
808                                    const char* ToNodeName ,
809                                    const char* ToServiceParameterName ) {
810   cdebug_in << "GraphBase::Graph::RemoveLink from " << FromNodeName << "(" << FromServiceParameterName << ")"
811             << " to " << ToNodeName << "(" << ToServiceParameterName << ")" << endl;
812   bool RetVal = false ;
813   GraphBase::ComputingNode * toNode = GetChangeGraphNode( ToNodeName ) ;
814   if ( toNode ) {
815     GraphBase::InPort * anInPort = toNode->GetChangeInPort( ToServiceParameterName ) ;
816     if ( anInPort && ( anInPort->IsConnected() ||
817                        anInPort->IsDataConnected() ) ) {
818       GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
819       RetVal = anOutPort->RemoveInPort( anInPort ) ;
820       anInPort->RemoveOutPort() ;
821       const char * FromNodeName = anOutPort->NodeName() ;
822       GraphBase::ComputingNode * fromNode = GetChangeGraphNode( FromNodeName ) ;
823       if ( RetVal ) {
824         if ( fromNode ) {
825           fromNode->RemoveLink( toNode ) ;
826         }
827         if ( fromNode->IsSwitchNode() && !anOutPort->IsGate() && !toNode->IsEndSwitchNode() ) {
828           anOutPort->Kind( SUPERV::InLineParameter ) ;
829         }
830 #if 0
831         if ( fromNode->IsEndLoopNode() ) {
832           toNode = ((GraphBase::EndOfLoopNode * ) fromNode)->CoupledNode() ;
833           if ( toNode ) {
834             anInPort = toNode->GetChangeInPort( ToServiceParameterName ) ;
835             RetVal = AddLink( fromNode , anOutPort , toNode , anInPort ) ;
836           }
837           else {
838             RetVal = false ;
839           }
840         }
841         if ( toNode->IsLoopNode() ) {
842           fromNode = ((GraphBase::LoopNode * ) toNode)->CoupledNode() ;
843           if ( fromNode ) {
844             anOutPort = fromNode->GetChangeOutPort( FromServiceParameterName ) ;
845             RetVal = AddLink( fromNode , anOutPort , toNode , toNode->GetChangeInPort( ToServiceParameterName ) ) ;
846           }
847           else {
848             RetVal = false ;
849           }
850         }
851 #endif
852       }
853     }
854   }
855   cdebug_out << "GraphBase::Graph::RemoveLink " << RetVal << endl;
856   return RetVal ;
857 }
858
859 bool GraphBase::Graph::GetLink(const char* ToNodeName ,
860                                const char* ToServiceParameterName ,
861                                char** FromNodeName ,
862                                char** FromServiceParameterName ) {
863 //  cdebug_in << "GraphBase::Graph::GetLink " << ToNodeName << "("
864 //            << ToServiceParameterName << ")" << endl;
865   bool RetVal = false ;
866   GraphBase::ComputingNode * toNode = GetChangeGraphNode( ToNodeName ) ;
867   if ( toNode ) {
868     GraphBase::InPort * anInPort = toNode->GetChangeInPort( ToServiceParameterName ) ;
869     if ( anInPort && anInPort->IsConnected() ) {
870       GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
871       *FromNodeName = my_strdup( anOutPort->NodeName() ) ;
872       *FromServiceParameterName = my_strdup( anOutPort->PortName() ) ;
873       RetVal = true ;
874     }
875     else {
876       cdebug << "GraphEditor::OutNode::GetLink ERROR no InPort or NotConnected " << ToNodeName
877              << " " << ToServiceParameterName << " " << RetVal << endl;
878     }
879   }
880   else {
881     cdebug << "GraphEditor::OutNode::GetLink ERROR no Node " << ToNodeName << " " << RetVal
882            << endl;
883   }
884 //  cdebug_out << "GraphEditor::OutNode::GetLink " << RetVal << endl;
885   return RetVal ;
886 }
887
888 bool GraphBase::Graph::AddInputData( const char* ToNodeName ,
889                                      const char* ToServiceParameterName ,
890                                      const CORBA::Any aValue ) {
891   bool RetVal = false ;
892   cdebug_in << "GraphBase::Graph::AddInputData(" << ToNodeName << ","
893             << ToServiceParameterName << " , Any " ;
894   switch (aValue.type()->kind()) {
895     case CORBA::tk_string:
896       char * t;
897       aValue >>= t;
898       cdebug << t << " (string) " ;
899       break;
900     case CORBA::tk_double:
901       double d;
902       aValue >>= d;
903       cdebug << d << " (double) " ;
904       break;
905     case CORBA::tk_long:
906       long l;
907       aValue >>= l;
908       cdebug << l << " (long) " ;
909       break;
910     case CORBA::tk_objref:
911       cdebug << "(object reference) " ;
912       break;
913     default:
914       cdebug << "(other(tk_string,tk_double,tk_long,tk_objref)) ERROR";
915       break;
916     }
917   cdebug << ")" << endl;
918
919   GraphBase::OutPort *fromDataNodePort = NULL ;
920
921   GraphBase::ComputingNode *toNode ;
922   GraphBase::InPort *toPort ;
923   char *aNode ;
924   char *aPort ;
925   NodePort( ToNodeName , ToServiceParameterName , &aNode , &aPort ) ;
926   toNode = GetChangeGraphNode( aNode ) ;
927   if ( toNode ) {
928     toPort = toNode->GetChangeInPort( aPort ) ;
929     if ( toPort && !toPort->IsDataConnected() ) {
930       toPort->RemoveOutPort() ;
931     }
932   }
933   else {
934     toPort = NULL ;
935   }
936   delete aNode ;
937   delete aPort ;
938
939 #if 0
940   int i ;
941   for ( i = 0 ; i < GetNodeOutDataNodePortsSize() ; i++ ) {
942     cdebug "GraphBase::Graph::AddInputData " << GetNodeOutDataNodePort(i) << endl ;
943   }
944   for ( i = 0 ; i < GetNodeInDataNodePortsSize() ; i++ ) {
945     cdebug "GraphBase::Graph::AddInputData " << GetNodeInDataNodePort(i) << endl ;
946   }
947 #endif
948
949   if ( toNode && toPort ) {
950     fromDataNodePort = GraphBase::DataNode::GetChangeInDataNodePort( toPort->NodePortName() ) ;
951     if ( fromDataNodePort && fromDataNodePort->GetInPort( toPort ) ) {
952       fromDataNodePort->RemoveInPort( toPort ) ;
953     }
954     cdebug << "Try AddLink " << toPort->NodePortName() << " : " << Name() << "( "
955            << fromDataNodePort->PortName() << " ) -->" << toNode->Name() << "( "
956            << toPort->PortName() << " )" << endl ;
957     RetVal = AddLink( (GraphBase::ComputingNode * ) this , fromDataNodePort ,
958                       toNode , toPort ) ;
959     if ( RetVal ) {
960       fromDataNodePort->Value( aValue ) ;
961     }
962   }
963   else {
964     cdebug << "Node not found" << endl ;
965   }
966
967   cdebug_out << "GraphBase::Graph::AddInputData " << RetVal << endl;
968   return RetVal ;
969 }
970
971 bool GraphBase::Graph::ChangeInputData( const char * ToNodeName ,
972                                         const char * ToServiceParameterName ,
973                                         const CORBA::Any aValue ) {
974   bool RetVal = false ;
975   cdebug_in << "GraphBase::Graph::ChangeInputData( '" << ToNodeName << "' , '"
976             << ToServiceParameterName << "' , Any " ;
977   switch (aValue.type()->kind()) {
978     case CORBA::tk_string:
979       char * t;
980       aValue >>= t;
981       cdebug << t << " (string) " ;
982       break;
983     case CORBA::tk_double:
984       double d;
985       aValue >>= d;
986       cdebug << d << " (double) " ;
987       break;
988     case CORBA::tk_long:
989       long l;
990       aValue >>= l;
991       cdebug << l << " (long) " ;
992       break;
993     case CORBA::tk_objref:
994       cdebug << "(object reference) " ;
995       break;
996     default:
997       cdebug << "(other(tk_string,tk_double,tk_long,tk_objref)) ERROR";
998       break;
999     }
1000   cdebug << ")" << endl;
1001
1002   GraphBase::ComputingNode *toNode = GetChangeGraphNode( ToNodeName ) ;
1003
1004   GraphBase::OutPort *fromPort = NULL ;
1005   GraphBase::InPort *toPort = NULL ;
1006
1007   if ( toNode ) {
1008     toPort = toNode->GetChangeInPort( ToServiceParameterName ) ;
1009     if ( toPort ) {
1010       fromPort = toPort->GetOutPort();
1011       if ( fromPort ) {
1012         RetVal = true ;
1013         fromPort->Value( aValue ) ;
1014         toPort->State( SUPERV::ReadyState ) ;
1015       }
1016       else {
1017         cdebug << "ChangeInputData fromPort not found" << endl ;
1018       }
1019     }
1020     else {
1021       cdebug << "ChangeInputData toPort not found" << endl ;
1022     }
1023   }
1024   else {
1025     cdebug << "ChangeInputData Node not found : " << ToNodeName << endl ;
1026   }
1027
1028   cdebug_out << "GraphBase::Graph::ChangeInputData" << endl;
1029   return RetVal ;
1030 }
1031
1032 bool GraphBase::Graph::AddInputData(
1033             const char* ToNodeName1 ,
1034             const char* ToServiceParameterName1 ,
1035             const char* ToNodeName2 ,
1036             const char* ToServiceParameterName2 ) {
1037   bool RetVal = false ;
1038   cdebug_in << "GraphBase::Graph::AddInputSharedData(" << ToNodeName1 << ","
1039             << ToServiceParameterName1 << ", " << ToNodeName2 << ","
1040             << ToServiceParameterName2 << " )" << endl;
1041
1042   GraphBase::ComputingNode *toNode1 = GetChangeGraphNode( ToNodeName1 ) ;
1043   GraphBase::ComputingNode *toNode2 = GetChangeGraphNode( ToNodeName2 ) ;
1044
1045   GraphBase::OutPort *fromDataNodePort1 = NULL ;
1046   GraphBase::OutPort *fromDataNodePort2 = NULL ;
1047   GraphBase::InPort *toPort1 = NULL ;
1048   GraphBase::InPort *toPort2 = NULL ;
1049
1050   if ( toNode1 && toNode2 ) {
1051     toPort1 = toNode1->GetChangeInPort( ToServiceParameterName1 ) ;
1052     toPort2 = toNode2->GetChangeInPort( ToServiceParameterName2 ) ;
1053     fromDataNodePort1 = GraphBase::DataNode::GetChangeInDataNodePort( toPort1->NodePortName() ) ;
1054 //    const char* aDataValue = fromDataNodePort->Value() ;
1055     const CORBA::Any ** aDataValue1 = fromDataNodePort1->ValuePtr() ;
1056     fromDataNodePort2 = GraphBase::DataNode::GetChangeInDataNodePort( toPort2->NodePortName() ) ;
1057     RetVal = AddLink( (GraphBase::ComputingNode * ) this , fromDataNodePort1 ,
1058                       toNode2 , toPort2 ) ;
1059 //                      aDataValue ) ;
1060     fromDataNodePort2->Value( aDataValue1 ) ;
1061   }
1062   else {
1063     cdebug << "Node not found" << endl ;
1064   }
1065
1066   cdebug_out << "GraphBase::Graph::AddInputSharedData" << endl;
1067   return RetVal ;
1068 }
1069
1070 bool GraphBase::Graph::AddInputData( const char* ToNodeName ,
1071                                      const char* ToServiceParameterName ,
1072                                      const CORBA::Any ** aValue ) {
1073   bool RetVal = false ;
1074   cdebug_in << "GraphBase::Graph::AddInputData(" << ToNodeName << ","
1075             << ToServiceParameterName << " **Any " ;
1076   const CORBA::Any theValue = **aValue ;
1077   switch (theValue.type()->kind()) {
1078     case CORBA::tk_string:
1079       char * t;
1080       theValue >>= t;
1081       cdebug << t << " (string) " ;
1082       break;
1083     case CORBA::tk_double:
1084       double d;
1085       theValue >>= d;
1086       cdebug << d << " (double) " ;
1087       break;
1088     case CORBA::tk_long:
1089       long l;
1090       theValue >>= l;
1091       cdebug << l << " (long) " ;
1092       break;
1093     case CORBA::tk_objref:
1094       cdebug << "(object reference) " ;
1095       break;
1096     default:
1097       cdebug << "(other(tk_string,tk_double,tk_long,tk_objref)) ERROR";
1098       break;
1099     }
1100   cdebug << ")" << endl;
1101
1102   GraphBase::ComputingNode *toNode = GetChangeGraphNode( ToNodeName ) ;
1103
1104   GraphBase::OutPort *fromDataNodePort = NULL ;
1105   GraphBase::InPort *toPort = NULL ;
1106
1107   if ( toNode ) {
1108     toPort = toNode->GetChangeInPort( ToServiceParameterName ) ;
1109     fromDataNodePort = GraphBase::DataNode::GetChangeInDataNodePort( toPort->NodePortName() ) ;
1110     cdebug << "Try AddLink " << Name() << "( " << fromDataNodePort << " ) -->"
1111            << toNode->Name() << "( " << toPort->PortName() << " )" << endl ;
1112     RetVal = AddLink( (GraphBase::ComputingNode * ) this , fromDataNodePort ,
1113                       toNode , toPort ) ;
1114     if ( RetVal ) {
1115       fromDataNodePort->Value( aValue ) ;
1116     }
1117   }
1118   else {
1119     cdebug << "Node not found" << endl ;
1120   }
1121
1122   cdebug_out << "GraphBase::Graph::AddInputData" << endl;
1123   return RetVal ;
1124 }
1125
1126 bool GraphBase::Graph::AddOutputData(
1127                        const char* FromNodeName ,
1128                        const char* FromServiceParameterName ,
1129                        const CORBA::Any aValue ) {
1130 //            const char* DataValue ,
1131 //            const SUPERV::KindOfPortValue aKindOfPortValue ) {
1132   bool RetVal = false ;
1133   cdebug_in << "GraphBase::Graph::AddOutputData(" << FromNodeName << ","
1134             << FromServiceParameterName
1135 //            << FromServiceParameterName << ", " << DataValue << ","
1136 //            << aKindOfPortValue
1137             << ")" << endl;
1138 #if 0
1139   GraphBase::ComputingNode *fromNode = GetChangeGraphNode( FromNodeName ) ;
1140
1141   GraphBase::OutPort *fromPort = NULL ;
1142   GraphBase::InPort *toDataNodePort = NULL ;
1143
1144   if ( fromNode ) {
1145     fromPort = fromNode->GetChangeOutPort( FromServiceParameterName ) ;
1146     toDataNodePort = GraphBase::DataNode::GetChangeOutDataNodePort( fromPort->NodePortName() ) ;
1147     RetVal = AddLink( fromNode , fromPort ,
1148                       (GraphBase::ComputingNode * ) this , toDataNodePort ,
1149                       aValue ) ;
1150 //                      DataValue , aKindOfPortValue ) ;
1151   }
1152   else {
1153     cdebug << "Node not found" << endl ;
1154   }
1155 #endif
1156   cdebug_out << "GraphBase::Graph::AddOutputData" << endl;
1157   return RetVal ;
1158 }
1159
1160 bool GraphBase::Graph::CreateService() {
1161   cdebug_in << "GraphBase::Graph::CreateService" << endl;
1162   bool RetVal = true ;
1163   SALOME_ModuleCatalog::Service aService ;
1164   int i , j ;
1165   GraphBase::ComputingNode * aToNode ;
1166   int dostore ;
1167   int innbr ;
1168   int outnbr ;
1169   for ( dostore = 0 ; dostore <= 1 ; dostore++ ) {
1170     if ( dostore == 1 ) {
1171       aService.ServiceName = Name() ;
1172       aService.ServiceinParameter.length( 0 ) ;
1173       aService.ServiceinParameter.length( innbr ) ;
1174       aService.ServiceoutParameter.length( 0 ) ;
1175       aService.ServiceoutParameter.length( outnbr ) ;
1176     }
1177     innbr = 0 ;
1178     outnbr = 0 ;
1179     for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1180       aToNode = GraphNodes( i ) ;
1181       for ( j = 0 ; j < aToNode->GetNodeInPortsSize() ; j++ ) {
1182         GraphBase::InPort *anInPort = aToNode->GetChangeNodeInPort(j) ;
1183 #if 0
1184         if ( dostore == 0 &&
1185              strcmp( anInPort->ServicesParameterType() , "string" ) &&
1186              strcmp( anInPort->ServicesParameterType() , "long" ) &&
1187              strcmp( anInPort->ServicesParameterType() , "double" ) &&
1188              strcmp( anInPort->ServicesParameterType() , "objref" ) ) {
1189           cdebug << "CreateService Node " << aToNode->Name() << ". Input port " << anInPort->PortName()
1190                  << " has illegal type " << anInPort->ServicesParameterType() << endl ;
1191           RetVal = false ;
1192         }
1193 #endif
1194         bool isfromcouplednode = false ;
1195         if ( anInPort->IsConnected() && anInPort->GetOutPort() ) {
1196           GraphBase::ComputingNode * aFromNode = GetChangeGraphNode( anInPort->GetOutPort()->NodeName() ) ;
1197           if ( aFromNode->IsEndLoopNode() && ((GraphBase::EndOfLoopNode * ) aFromNode)->CoupledNode() == aToNode ) {
1198             isfromcouplednode = true ;
1199           }
1200         }
1201         if ( !anInPort->IsGate() && !anInPort->IsLoop() &&
1202              ( !anInPort->IsConnected() || ( anInPort->IsConnected() && isfromcouplednode ) ) ) {
1203           if ( dostore == 0 ) {
1204             cdebug << "CreateService " << aToNode->Name() << " Input port "
1205                    << anInPort->PortName() << " " << anInPort->Kind() << " is NOT connected " ;
1206             if ( anInPort->GetOutPort() ) {
1207               cdebug << "DataConnected from " <<  *(anInPort->GetOutPort() ) ;
1208             }
1209             cdebug << endl ;
1210             innbr += 1 ;
1211           }
1212           else {
1213             aService.ServiceinParameter[innbr].Parametertype = CORBA::string_dup( anInPort->PortType() ) ;
1214             aService.ServiceinParameter[innbr++].Parametername = CORBA::string_dup( anInPort->NodePortName() ) ;
1215           }
1216         }
1217         else {
1218           cdebug << "CreateService " << aToNode->Name() << " Input port " << anInPort->PortName() ;
1219           if ( anInPort->IsConnected() ) {
1220             cdebug << " is connected " ;
1221           }
1222           else {
1223             cdebug << " is NOT connected " ;
1224           }
1225           if ( anInPort->IsGate() ) {
1226             cdebug << " IsGate " ;
1227           }
1228           if ( anInPort->GetOutPort() ) {
1229             cdebug << "DataConnected from " <<  *(anInPort->GetOutPort()) ;
1230           }
1231           else {
1232             cdebug << "NOT DataConnected" ;
1233           }
1234           cdebug << endl ;
1235         }
1236       }
1237       GraphBase::ComputingNode * aFromNode = aToNode ;
1238       for ( j = 0 ; j < aFromNode->GetNodeOutPortsSize() ; j++ ) {
1239         GraphBase::OutPort *anOutPort = aFromNode->GetChangeNodeOutPort(j) ;
1240         cdebug << "CreateService Node " << aFromNode->Name() << ". Output port[" << j << "] ";
1241         if ( anOutPort ) {
1242           cdebug << anOutPort->PortName() << " " << anOutPort->ServicesParameterType() << endl ;
1243         }
1244         else {
1245           cdebug << " NULL" << endl ;
1246         }
1247 #if 0
1248         if ( dostore == 0 &&
1249              strcmp( anOutPort->ServicesParameterType() , "string" ) &&
1250              strcmp( anOutPort->ServicesParameterType() , "long" ) &&
1251              strcmp( anOutPort->ServicesParameterType() , "double" ) &&
1252              strcmp( anOutPort->ServicesParameterType() , "objref" ) ) {
1253           cdebug << "CreateService Node " << aFromNode->Name() << ". Output port " << anOutPort->PortName()
1254                  << " has illegal type " << anOutPort->ServicesParameterType() << endl ;
1255           RetVal = false ;
1256         }
1257 #endif
1258         if ( !aFromNode->IsGOTONode() ) {
1259           if ( !anOutPort->IsGate() && 
1260                ( anOutPort->IsNotConnected() || anOutPort->IsDataConnected() ) ) {
1261             if ( dostore == 0 ) {
1262               cdebug << "CreateService " << aFromNode->Name() << " Output port "
1263                      << anOutPort->PortName() << endl ;
1264               outnbr += 1 ;
1265             }
1266             else {
1267               aService.ServiceoutParameter[outnbr].Parametertype = CORBA::string_dup( anOutPort->PortType() ) ;
1268               aService.ServiceoutParameter[outnbr++].Parametername = CORBA::string_dup( anOutPort->NodePortName() ) ;
1269             }
1270           }
1271         }
1272       }
1273     }
1274   }
1275
1276 //  MESSAGE( "DataFlowNode ServiceName " << aService.ServiceName );
1277 //  for ( i = 0 ; i < innbr ; i++ ) {
1278 //    cout << "aService.ServiceinParameter[" << i << "].Parametertype "
1279 //         << aService.ServiceinParameter[i].Parametertype << endl ;
1280 //    cout << "aService.ServiceinParameter[" << i << "].Parametername "
1281 //         << aService.ServiceinParameter[i].Parametername << endl ;
1282 //  }
1283 //  for ( i = 0 ; i < outnbr ; i++ ) {
1284 //    cout << "aService.ServiceoutParameter[" << i << "].Parametertype "
1285 //         << aService.ServiceoutParameter[i].Parametertype << endl ;
1286 //    cout << "aService.ServiceoutParameter[" << i << "].Parametername "
1287 //         << aService.ServiceoutParameter[i].Parametername << endl ;
1288 //  }
1289
1290   DataService( _Orb , aService , Graph_prof_debug() , Graph_fdebug() ) ;
1291
1292 // Restore input datas :
1293   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1294     aToNode = GraphNodes( i ) ;
1295     for ( j = 0 ; j < aToNode->GetNodeInPortsSize() ; j++ ) {
1296       GraphBase::InPort *anInPort = aToNode->GetChangeNodeInPort(j) ;
1297       if ( anInPort->IsDataConnected() ) {
1298         AddInputData( anInPort->NodeName() ,
1299                       anInPort->PortName() ,
1300                       anInPort->GetOutPort()->ValuePtr() ) ;
1301       }
1302     }
1303   }
1304
1305   cdebug_out << "GraphBase::Graph::CreateService" << endl;
1306   return RetVal ;
1307 }
1308
1309 bool GraphBase::Graph::InLineServices() {
1310   cdebug_in << "GraphBase::Graph::InLineServices" << endl;
1311
1312   int i , j ;
1313   GraphBase::InLineNode * aINode ;
1314   SALOME_ModuleCatalog::Service aService ;
1315   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1316     aINode = (GraphBase::InLineNode * ) GraphNodes( i ) ;
1317     if ( aINode->IsOneOfInLineNodes() ) {
1318       cdebug << "GraphBase::Graph::InLineServices " << aINode->Name() << endl;
1319       aService.ServiceName = aINode->ServiceName() ;
1320       aService.ServiceinParameter.length( 0 ) ;
1321       aService.ServiceoutParameter.length( 0 ) ;
1322       int InService = 0 ;
1323       for ( j = 0 ; j < aINode->GetNodeInPortsSize() ; j++ ) {
1324         if ( aINode->GetChangeNodeInPort(j)->IsGate() ||
1325              aINode->GetChangeNodeInPort(j)->IsLoop() ) {
1326 //          cdebug << "GraphBase::Graph::InLineServices In" << j << " "
1327 //                 << aINode->GetChangeNodeInPort(j)->Kind() << " " 
1328 //                 << aINode->GetChangeNodeInPort(j)->PortType() << " " 
1329 //                 << aINode->GetChangeNodeInPort(j)->PortName() << " ignored "
1330 //                 << aINode->GetChangeNodeInPort(j)->IsGate() << " "
1331 //                 << aINode->GetChangeNodeInPort(j)->IsLoop() << endl;
1332         }
1333         else {
1334           aService.ServiceinParameter.length( InService+1 ) ;
1335           aService.ServiceinParameter[InService].Parametertype = CORBA::string_dup( aINode->GetChangeNodeInPort(j)->PortType() ) ;
1336           aService.ServiceinParameter[InService++].Parametername = CORBA::string_dup( aINode->GetChangeNodeInPort(j)->PortName() ) ;
1337 //          cdebug << "GraphBase::Graph::InLineServices In" << j << " "
1338 //                 << aINode->GetChangeNodeInPort(j)->Kind() << " " 
1339 //                 << aINode->GetChangeNodeInPort(j)->PortType() << " " 
1340 //                 << aINode->GetChangeNodeInPort(j)->PortName() << " "
1341 //                 << aINode->GetChangeNodeInPort(j)->IsGate() << " "
1342 //                 << aINode->GetChangeNodeInPort(j)->IsLoop() << endl;
1343         }
1344       }
1345       int OutService = 0 ;
1346       for ( j = 0 ; j < aINode->GetNodeOutPortsSize() ; j++ ) {
1347         if ( aINode->GetChangeNodeOutPort(j)->IsGate() ||
1348              aINode->GetChangeNodeOutPort(j)->IsLoop() ) {
1349 //          cdebug << "GraphBase::Graph::InLineServices Out" << j << " "
1350 //                 << aINode->GetChangeNodeOutPort(j)->Kind() << " " 
1351 //                 << aINode->GetChangeNodeOutPort(j)->PortType() << " " 
1352 //                 << aINode->GetChangeNodeOutPort(j)->PortName() << " ignored "
1353 //                 << aINode->GetChangeNodeOutPort(j)->IsGate() << " "
1354 //                 << aINode->GetChangeNodeOutPort(j)->IsLoop() << endl;
1355         }
1356         else {
1357           aService.ServiceoutParameter.length( OutService+1 ) ;
1358           aService.ServiceoutParameter[OutService].Parametertype = CORBA::string_dup( aINode->GetChangeNodeOutPort(j)->PortType() ) ;
1359           aService.ServiceoutParameter[OutService++].Parametername = CORBA::string_dup( aINode->GetChangeNodeOutPort(j)->PortName() ) ;
1360 //          cdebug << "GraphBase::Graph::InLineServices Out" << j << " "
1361 //                 << aINode->GetChangeNodeOutPort(j)->Kind() << " " 
1362 //                 << aINode->GetChangeNodeOutPort(j)->PortType() << " " 
1363 //                 << aINode->GetChangeNodeOutPort(j)->PortName()  << " "
1364 //                 << aINode->GetChangeNodeOutPort(j)->IsGate() << " "
1365 //                 << aINode->GetChangeNodeOutPort(j)->IsLoop() << endl;
1366         }
1367       }
1368       aINode->SetService( aService ) ;
1369 //      cdebug << "GraphBase::Graph::InLineServices" << *aINode->GetService() << endl;
1370     }
1371   }
1372
1373   cdebug_out << "GraphBase::Graph::InLineServices" << endl;
1374   return true ;
1375 }
1376
1377 bool GraphBase::Graph::Sort() {
1378   int i ;
1379   int j ;
1380   int NotSortedNumber = GraphNodesSize() ;
1381   bool NewSorted ;
1382   if ( NotSortedNumber ) {
1383     _LevelsNumber = 0 ;
1384     _ParallelExecutionNodes = false ;
1385     _Sorted.resize( GraphNodesSize() ) ;
1386     _CnxInPortsNumber.resize( GraphNodesSize() ) ;
1387     _DecrInPortsNumber.resize( GraphNodesSize() ) ;
1388     if ( _NodesNumber.size() )
1389       _NodesNumber.resize( 0 ) ;
1390       _SortedNodes.resize( 0 ) ;
1391           
1392     for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1393       _Sorted[ i ] = false ;
1394       _CnxInPortsNumber[ i ] = GraphNodes( i )->ConnectedInPortsNumber() ;
1395       _DecrInPortsNumber[ i ] = 0 ;
1396     }
1397     
1398     while ( NotSortedNumber ) {
1399       NewSorted = false ;
1400       
1401       for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1402         cdebug << "Sort level " << _LevelsNumber << ". [" << i << "] "
1403                << GraphNodes( i )->Name() << " count "
1404                << _CnxInPortsNumber[ i ] << endl ;
1405         if ( !_Sorted[ i ] && _CnxInPortsNumber[ i ] == 0 ) {
1406 // All inputs of GraphNodes( i ) are available
1407           if ( (int ) _NodesNumber.size() != _LevelsNumber+1 ) {
1408             _NodesNumber.resize( _LevelsNumber+1 ) ;
1409             _SortedNodes.resize( _LevelsNumber+1 ) ;
1410             _NodesNumber[ _LevelsNumber ] = -1 ;
1411           }
1412           _NodesNumber[ _LevelsNumber ]++ ;
1413           (_SortedNodes[ _LevelsNumber ]).resize( _NodesNumber[ _LevelsNumber ]+1 ) ;
1414           (_SortedNodes[ _LevelsNumber ])[ _NodesNumber[ _LevelsNumber ] ] = GraphNodes( i ) ;
1415           _Sorted[ i ] = true ;
1416           NewSorted = true ;
1417           cdebug << GraphNodes( i )->Name() << " belongs to level "
1418                  << _LevelsNumber << "." << endl ;
1419           for ( j = 0 ; j < GraphNodes( i )->LinkedNodesSize() ; j++ ) {
1420 // Outputs of GraphNodes( i ) will satisfy 
1421 //   GraphNodes( i )->LinkedInPortsNumber( j ) InPorts of
1422 //      GraphNodes( i )->LinkedNodes( j )
1423             GraphBase::ComputingNode * aLinkedNode = GraphNodes( i )->LinkedNodes( j ) ;
1424             int aLinkedInPortsNumber = GraphNodes( i )->LinkedInPortsNumber( j ) ;
1425             cdebug << j << ". LinkedNode " << aLinkedNode->Name() ;
1426             if ( !aLinkedNode->IsDataFlowNode() ) {
1427               cdebug << " _DecrInPortsNumber[ "
1428                      << GetGraphNodeIndex( aLinkedNode->Name() )
1429                      << " ] = "
1430                      << _DecrInPortsNumber[ GetGraphNodeIndex( aLinkedNode->Name() ) ]
1431                      << " += " << aLinkedInPortsNumber ;
1432               _DecrInPortsNumber[ GetGraphNodeIndex( aLinkedNode->Name() ) ] += aLinkedInPortsNumber ;
1433             }
1434             cdebug << endl ;
1435 //            GraphNodes( i )->LinkedNodes( j )->IncrDecrConnectedInPortsNumber( GraphNodes( i )->LinkedInPortsNumber( j ) ) ;
1436           }
1437         }
1438       }
1439       if ( !NewSorted ) {
1440         cdebug << "Loop detected level " << _LevelsNumber << endl ;
1441         return false ; // Loop in the Graph
1442       }
1443       cdebug << "Bilan level " << _LevelsNumber << " : " << endl ;
1444       bool ChangeCount = false ;
1445       for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1446 //        if ( GraphNodes( i )->DecrIncrDecrConnectedInPortsNumber() ) {
1447         if ( _DecrInPortsNumber[ i ] ) {
1448           int prevcount = _CnxInPortsNumber[ i ] ;
1449           _CnxInPortsNumber[ i ] -= _DecrInPortsNumber[ i ]  ;
1450           _DecrInPortsNumber[ i ] = 0 ;
1451           ChangeCount = true ;
1452           cdebug << "    " << GraphNodes( i )->Name() << " count " << prevcount
1453                  << " --> new count " << _CnxInPortsNumber[ i ] << endl ;
1454         }
1455       }
1456       
1457       if ( !ChangeCount )
1458         break ;
1459       _LevelsNumber += 1 ;
1460     }
1461     _ThreadsMax = 0 ;
1462     int AllSortedNodes = 0 ;
1463     _HeadNodes = _SortedNodes[ 0 ] ;
1464     _HeadNodesSize = _SortedNodes[ 0 ].size() ;
1465     _QueueNodes = _SortedNodes[ _LevelsNumber ] ;
1466     _QueueNodesSize = _SortedNodes[ _LevelsNumber ].size() ;
1467     for ( i = 0 ; i < _QueueNodesSize ; i++ ) {
1468       if ( !_QueueNodes[ i ]->IsGOTONode() ) {
1469         break ;
1470       }
1471     }
1472     if ( i == _QueueNodesSize && _LevelsNumber ) {
1473       _QueueNodes = _SortedNodes[ _LevelsNumber - 1 ] ;
1474       _QueueNodesSize = _SortedNodes[ _LevelsNumber - 1 ].size() ;
1475     }
1476     for ( i = 0 ; i <= _LevelsNumber ; i++ ) {
1477       AllSortedNodes += _NodesNumber[ i ]+1 ;
1478       if ( _NodesNumber[ i ] + 1 > _ThreadsMax )
1479         _ThreadsMax = _NodesNumber[ i ] + 1 ;
1480       cdebug << _NodesNumber[ i ]+1 << " Nodes of level " << i << " : "
1481              << (_SortedNodes[ i ])[ 0 ]->Name() << endl ;
1482       for ( j = 1 ; j <= _NodesNumber[ i ] ; j++ ) {
1483         _ParallelExecutionNodes = true ;
1484         cdebug << "                     " << (_SortedNodes[ i ])[ j ]->Name()
1485                << endl ;
1486       }
1487     }
1488     if ( _ParallelExecutionNodes ) {
1489       cdebug << "Parallel Execution Nodes detected." << endl ;
1490     }
1491     else {
1492       cdebug << "No Parallel Execution Nodes detected." << endl ;
1493     }
1494     if ( AllSortedNodes != GraphNodesSize() ) {
1495       cdebug << "Loop detected level " << _LevelsNumber << endl ;
1496       return false ; // Loop in the Graph
1497     }
1498
1499     for ( i= 0 ; i <= _NodesNumber[ 0 ] ; i++ ) {
1500       (_SortedNodes[ 0 ])[ i ]->HeadNode( true ) ;
1501     }
1502
1503     for ( i = 0 ; i <= _NodesNumber[ 0 ] ; i++ ) {
1504       (_SortedNodes[ 0 ])[ i ]->Level( 0 ) ;
1505       (_SortedNodes[ 0 ])[ i ]->SubGraph( i + 1 ) ;
1506     }
1507
1508     for ( i = 1 ; i <= _LevelsNumber ; i++ ) {
1509       for ( j = 0 ; j <= _NodesNumber[ i ] ; j++ ) {
1510         (_SortedNodes[ i ])[ j ]->Level( i ) ;
1511         (_SortedNodes[ i ])[ j ]->SubGraph( 0 ) ;
1512       }
1513     }
1514
1515     bool Graphs = true ;
1516     while ( Graphs ) {
1517       for ( i = 0 ; i <= _LevelsNumber ; i++ ) {
1518         for ( j = 0 ; j <= _NodesNumber[ i ] ; j++ ) {
1519           GraphBase::ComputingNode * aNode = (_SortedNodes[ i ])[ j ] ;
1520           cdebug << "Graph " << aNode->SubGraph() << " " << aNode->Name()
1521                  << endl ;
1522           int k ;
1523           for ( k = 0 ; k < aNode->LinkedNodesSize() ; k++ ) {
1524             if ( aNode->LinkedNodes( k )->SubGraph() ) {
1525               if ( aNode->LinkedNodes( k )->SubGraph() != aNode->SubGraph() &&
1526                    aNode->LinkedNodes( k )->Level() == aNode->Level()+1 ) {
1527                 aNode->SubGraph( aNode->LinkedNodes( k )->SubGraph() ) ;
1528                 cdebug << "   Linked " << aNode->LinkedNodes( k )->Name()
1529                        << " Graph(" << aNode->LinkedNodes( k )->SubGraph()
1530                        << ") ==>" << endl ;
1531                 cdebug << "   Graph " << aNode->SubGraph() << " for "
1532                        << aNode->Name() << " ==> again" << endl ;
1533                 int l ;
1534                 for ( l = 0 ; l < aNode->LinkedNodesSize() ; l++ ) {
1535                   aNode->LinkedNodes( l )->SubGraph( aNode->SubGraph() ) ;
1536                 }
1537                 Graphs = false ;
1538                 break ;
1539               }
1540               else {
1541                 cdebug << "   Linked " << aNode->LinkedNodes( k )->Name()
1542                        << " Graph(" << aNode->LinkedNodes( k )->SubGraph()
1543                        << ") distance > 1 ignored" << endl ;
1544               }
1545             }
1546             else {
1547               cdebug << "   Linked " << aNode->LinkedNodes( k )->Name()
1548                      << " GraphInit to " << aNode->SubGraph() << " from "
1549                      << aNode->Name() << endl ;
1550               aNode->LinkedNodes( k )->SubGraph( aNode->SubGraph() ) ;
1551             }
1552           }
1553         }
1554         if ( !Graphs )
1555           break ;
1556       }
1557       if ( Graphs ) {
1558         cdebug << endl << "Graphs result : " << endl ;
1559         break ;
1560       }
1561       cdebug << endl << "One more time" << endl ;
1562       Graphs = true ;
1563     }
1564     _GraphsNumber = 0 ;
1565     int CurrGraphsNumber = 0;
1566     int k ;
1567     for ( k = 0 ; k <= _NodesNumber[ 0 ] ; k++ ) {
1568       if ( (_SortedNodes[ 0 ])[ k ]->SubGraph() > CurrGraphsNumber ) {
1569         CurrGraphsNumber = (_SortedNodes[ 0 ])[ k ]->SubGraph() ;
1570         _GraphsNumber += 1 ;
1571         for ( i = 0 ; i <= _LevelsNumber ; i++ ) {
1572           for ( j = 0 ; j <= _NodesNumber[ i ] ; j++ ) {
1573             if ( (_SortedNodes[ i ])[ j ]->SubGraph() == CurrGraphsNumber ) {
1574               (_SortedNodes[ i ])[ j ]->SubGraph( _GraphsNumber ) ;
1575               cdebug << "GraphsNumber " << _GraphsNumber << " " << " Level "
1576                      << i << " : " << (_SortedNodes[ i ])[ j ]->Name()
1577                      << endl ;
1578             }
1579           }
1580         }
1581       }
1582     }
1583   }
1584
1585   return true ;
1586 }
1587
1588 // Controle de la coherence des noeuds de calcul
1589 // Enregistrement dans la liste des noeuds "tete" de graphe
1590
1591 bool GraphBase::Graph::ComputingNodes() const {
1592   bool RetVal = true ;
1593   cdebug << "GraphExecutor::GraphControl::ComputingNodes ()" << endl;
1594
1595 //  list<GraphEditor::Node *> aComputingNodesList = _G->ComputingNodesList() ;
1596 //  list<GraphEditor::Node *>::iterator aNode = aComputingNodesList.begin();
1597 //  GraphEditor::Port *  iP;
1598
1599 //  for (aNode = _G->ComputingNodesList().begin(); aNode !=_G->ComputingNodesList().end(); aNode++) {
1600 //  while ( aNode != aComputingNodesList.end() ) {
1601   int i ;
1602   GraphBase::ComputingNode * aNode ;
1603   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1604     aNode = GraphNodes( i ) ;
1605     // Tous les ports d'entree de tous les noeuds de calcul sont bien connectes
1606     // Enregistrement eventuel dans la liste des noeuds "tete" de graphe
1607 //    if ((*aNode)->GetNodeInPortsSize() == 0)
1608 //      _headNodes.push_front(*aNode);
1609     int j ;
1610     for ( j = 1 ; j < aNode->GetNodeInPortsSize() ; j++ ) {
1611       const GraphBase::InPort *iP = aNode->GetNodeInPort(j);
1612       if ( !iP->IsConnected() ){
1613         cdebug << "Le port d'entree " << iP->PortName()
1614                << " du noeud de calcul " << aNode->Name() << " du graphe  "
1615                << Name() << " n'est pas connecte "<< endl;
1616         RetVal = false ;
1617       };
1618
1619     };
1620
1621     // Tous les noeuds de calcul ont au moins un port de sortie connecte
1622     bool oneOutPortConnected = false;
1623     for ( j = 1 ; j < aNode->GetNodeOutPortsSize() ; j++) {
1624       const GraphBase::OutPort *iP = aNode->GetNodeOutPort(j);
1625       if ( iP->IsPortConnected() || iP->IsDataConnected() ){
1626         oneOutPortConnected = true ;
1627 //      break;
1628       }
1629       else {
1630         cdebug << "Le port de sortie " << iP->PortName()
1631                << " du noeud de calcul " << aNode->Name() << " du graphe  "
1632                << Name() << " n'est pas connecte "<< endl;
1633         RetVal = false ;
1634       }
1635     };
1636     if (!oneOutPortConnected) {
1637         cdebug << "Le noeud de calcul " << aNode->Name() << " du graphe  "
1638                << Name() << " n'a aucun port de sortie connecte "<< endl;
1639 //      _computingError.push_front(2);
1640     }
1641   };
1642 //  return _computingError.size () ;
1643   return RetVal ;
1644 }
1645
1646 bool GraphBase::Graph::LinkLoopNodes(bool & NewLink ) {
1647   bool RetVal = true ;
1648   NewLink = false ;
1649   int i , j ;
1650   cdebug_in << "GraphBase::Graph::LinkLoopNodes()" << endl;
1651   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1652     GraphBase::ComputingNode * aNode = GraphNodes( i ) ;
1653     if ( aNode->IsLoopNode() ) {
1654       GraphBase::LoopNode * aLoopNode = (GraphBase::LoopNode * ) aNode ;
1655       for ( j = 0 ; j < aLoopNode->GetNodeInPortsSize() ; j++ ) {
1656         GraphBase::InPort *anInPort = aLoopNode->GetChangeNodeInPort(j) ;
1657         if ( !anInPort->IsGate() && !anInPort->IsConnected() && !anInPort->IsDataConnected() ) {
1658           if ( !AddLink( aLoopNode->CoupledNode() , aLoopNode->CoupledNode()->GetChangeNodeOutPort( j ) ,
1659                          aLoopNode , anInPort ) ) {
1660             cdebug << "GraphBase::Graph::CreateService AddLink ERROR " << aLoopNode->CoupledNode()->Name()
1661                    << "( " << aLoopNode->CoupledNode()->GetChangeNodeOutPort( j )->PortName() << " ) --> "
1662                    << aLoopNode->Name() << "( " << anInPort->PortName() << " )" << endl ;
1663             RetVal = false ;
1664           }
1665           else {
1666             NewLink = true ;
1667           }
1668         }
1669       }
1670       for ( j = 0 ; j < aLoopNode->CoupledNode()->GetNodeInPortsSize() ; j++ ) {
1671         GraphBase::InPort *anInPort = aLoopNode->CoupledNode()->GetChangeNodeInPort( j ) ;
1672         if ( !anInPort->IsConnected() ) {
1673           if ( !AddLink( aLoopNode , aLoopNode->GetChangeNodeOutPort( j ) ,
1674                          aLoopNode->CoupledNode() , anInPort ) ) {
1675             cdebug << "GraphBase::Graph::CreateService AddLink ERROR " << aLoopNode->Name() << "( "
1676                    << aLoopNode->GetChangeNodeOutPort( j )->PortName() << " ) --> "
1677                    << aLoopNode->CoupledNode()->Name() << "( " << anInPort->PortName() << " )" << endl ;
1678             RetVal = false ;
1679           }
1680           else {
1681             NewLink = true ;
1682           }
1683         }
1684       }
1685     }
1686     else if ( aNode->IsGOTONode() ) {
1687       GraphBase::GOTONode * aGOTONode = (GraphBase::GOTONode * ) aNode ;
1688       GraphBase::OutPort *anOutGate = aGOTONode->GetChangeNodeOutGate() ;
1689       if ( !anOutGate->IsConnected() ) {
1690         if ( !AddLink( aGOTONode , anOutGate ,
1691                        aGOTONode->CoupledNode() , aGOTONode->CoupledNode()->GetChangeNodeInGate() ) ) {
1692           cdebug << "GraphBase::Graph::CreateService AddLink ERROR " << aGOTONode->Name() << "( "
1693                  << anOutGate->PortName() << " ) --> " << aGOTONode->CoupledNode()->Name() << "( "
1694                  << aGOTONode->CoupledNode()->GetChangeNodeInGate()->PortName() << " )" << endl ;
1695           RetVal = false ;
1696         }
1697         else {
1698           NewLink = true ;
1699         }
1700       }
1701     }
1702   }
1703   cdebug_out << "GraphBase::Graph::LinkLoopNodes() " << RetVal << endl;
1704   return RetVal ;
1705 }
1706
1707 // Controle de la coherence des noeuds de calcul
1708 // Enregistrement dans la liste des noeuds "tete" de graphe
1709
1710 bool GraphBase::Graph::DataServerNodes() const {
1711
1712   cdebug << "GraphBase::Graph::DataServerNodes ()" << endl;
1713
1714 //  const GraphExecutor::InNode *DataFlowDatas = GetDataFlowDatas() ;
1715   int i , j , ierr = 0 ;
1716
1717 //  if ( DataFlowDatas == NULL ) {
1718 //    MESSAGE( "No input data available in the DataFlow " << _G->Name() );
1719 //    return 0 ;
1720 //  }
1721
1722 //  const GraphExecutor::InNode *DataFlowNode = _G->GetDataFlowNode() ;
1723 //  MESSAGE( "DataServerNodes DataFlowNode : " << *DataFlowNode );
1724
1725 //  MESSAGE( "DataServerNodes DataFlowDatas : " << *DataFlowDatas );
1726
1727 // cout are inversed because DataFlowDatas is a mirror node of the DataFlow
1728
1729   ierr = CheckDataServerNodes() ;
1730
1731 //  list<GraphExecutor::InNode *> aComputingNodesList = _G->ComputingNodesList() ;
1732 //  list<GraphExecutor::InNode *>::iterator aNode = aComputingNodesList.begin();
1733   if ( GraphNodesSize() == 0 ) {
1734     ierr++ ;
1735   }
1736   else {
1737     GraphBase::ComputingNode * aNode ;
1738     for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1739       aNode = GraphNodes( i ) ;
1740 //  while ( aNode != aComputingNodesList.end() ) {
1741       if ( aNode->IsFactoryNode() ) {
1742       GraphBase::FactoryNode * FaNode = (GraphBase::FactoryNode * ) aNode ;
1743         if ( !strlen( FaNode->Computer() ) ) {
1744           cdebug << "ComputerName missing for node " << FaNode->Name() ;
1745           if ( !strlen( FaNode->Computer() ) ) {
1746             ierr++ ;
1747             cdebug << endl ;
1748           }
1749           else {
1750             cdebug << ". " << FaNode->Computer() << " will be used." << endl ;
1751           }
1752         }
1753     }
1754 // For Outputs of the DataFlow :
1755       for ( j = 0 ; j < aNode->GetNodeOutPortsSize() ; j++ ) {
1756         if ( !aNode->GetNodeOutPort(j)->IsConnected() ) {
1757           aNode->AddLink( (GraphBase::ComputingNode *) this ) ;
1758         }
1759       }
1760     }
1761   }
1762
1763 // Chaque noeud dataserver ne possede qu'un seul port entree ou sortie et il est bien connecte
1764
1765 //  list<GraphExecutor::InNode *> aDataServerNodesList = _G->DataServerNodesList() ;
1766 //  list<GraphExecutor::InNode *>::iterator it = aDataServerNodesList.begin() ;
1767
1768 //  for (it = _G->DataServerNodesList().begin(); it !=_G->DataServerNodesList().end(); it++){
1769 //  while ( it != aDataServerNodesList.end() ) {
1770 //    if ( (*it)->GetNodeOutPortsSize() && (*it)->GetNodeInPortsSize() ) {
1771 //      cerr << "Erreur dans le noeud serveur de donnees " 
1772 //           << (*it)->Name() << " du graphe  " << _G->Name() << endl;
1773 //      cerr << "A la fois importation et exportation de donnees" << endl;
1774 //      _dataServerError.push_front(1);
1775 //    }
1776
1777 //    if ((*it)->GetNodeOutPortsSize()) {
1778 //      if ((*it)->GetNodeOutPortsSize()==1){
1779 //      if ( (*it)->GetNodeOutPort(0)->IsPortConnected() ){
1780 //        _headNodes.push_front(*it);
1781 //      }
1782 //      else {
1783 //        cerr << "Le port de sortie du noeud serveur de donnees "
1784 //               << (*it)->Name() << " du graphe  " << _G->Name()
1785 //               << " n'est pas connecte "<< endl;
1786 //        _dataServerError.push_front(4);
1787 //      }
1788 //      }
1789 //      else {
1790 //      cerr << "Plus d'une donnee importee du noeud serveur de donnees "
1791 //             << (*it)->Name() << " du graphe  " << _G->Name() << endl;
1792 //      _dataServerError.push_front(2);
1793 //      }
1794 //    }
1795
1796 //    if ((*it)->GetNodeInPortsSize()) {
1797 //      if ((*it)->GetNodeInPortsSize() > 1){
1798 //      cerr << "Plus d'une donnee exportee vers le noeud serveur de donnees "
1799 //             << (*it)->Name() << " du graphe  " << _G->Name() << endl;
1800 //      _dataServerError.push_front(3);
1801 //      }
1802 //      else
1803 //      if ( !(*it)->GetNodeInPort(0)->IsPortConnected() ){
1804 //      cerr << "Le port d'entree du noeud serveur de donnees "
1805 //             << (*it)->Name() << " du graphe  " << _G->Name()
1806 //             << " n'est pas connecte "<< endl;
1807 //      _dataServerError.push_front(5);
1808 //      }
1809 //    }
1810 //    it++ ;
1811 //  };
1812
1813 //  return _dataServerError.size ();
1814   return ( ierr == 0 ) ;
1815 }
1816
1817 SUPERV::GraphState GraphBase::Graph::PortState(
1818                                    const char* NodeName ,
1819                                    const char* ServiceParameterName ) {
1820   SUPERV::GraphState aRet = SUPERV::UndefinedState ;
1821 //  cdebug << "GraphBase::Graph::PortState( " << NodeName << " , "
1822 //         << ServiceParameterName << " )" << endl ;
1823
1824   char *theNode ;
1825   char *aPort ;
1826   NodePort( NodeName , ServiceParameterName , &theNode , &aPort ) ;
1827
1828   GraphBase::ComputingNode * aNode = GetChangeGraphNode( theNode ) ;
1829   if ( aNode ) {
1830     GraphBase::OutPort *anOutPort ;
1831     anOutPort = aNode->GetChangeOutPort( aPort );
1832     if ( anOutPort == NULL ) {
1833       GraphBase::InPort *anInPort = aNode->GetChangeInPort( aPort );
1834       if ( anInPort )
1835         anOutPort = anInPort->GetOutPort() ;
1836       else {
1837         cdebug << "GraphBase::Graph::PortState OutPort/InPort not found --> "
1838                << aRet << endl ;
1839       }
1840     }
1841     if ( anOutPort ) {
1842       aRet = anOutPort->State() ;
1843 //      cdebug << "GraphBase::Graph::PortState --> " << aRet << endl ;
1844     }
1845   }
1846   else {
1847     cdebug << "GraphBase::Graph::PortState Node not found --> " << aRet
1848            << endl ;
1849   }
1850   delete theNode ;
1851   delete aPort ;
1852   return aRet ;
1853 }
1854
1855 const CORBA::Any * GraphBase::Graph::PortInData( const char* ToNodeName ,
1856                                                  const char* ToServiceParameterName ) {
1857   const CORBA::Any * aRet = new CORBA::Any() ;
1858   char *theNode ;
1859   char *aPort ;
1860 //  cdebug_in << "GraphBase::Graph::PortInData " << ToNodeName << " "
1861 //            << ToServiceParameterName << endl ;
1862   NodePort( ToNodeName , ToServiceParameterName , &theNode , &aPort ) ;
1863
1864   GraphBase::ComputingNode * aNode = GetChangeGraphNode( theNode ) ;
1865
1866   if ( aNode ) {
1867     GraphBase::OutPort *anOutPort = NULL ;
1868     GraphBase::InPort *anInPort = aNode->GetChangeInPort( aPort );
1869     if ( anInPort ) {
1870       anOutPort = anInPort->GetOutPort() ;
1871       if ( anOutPort ) {
1872         aRet = anOutPort->Value() ;
1873 //        cdebug << "OutPort value " << anOutPort->NodeName() << "("
1874 //               << anOutPort->PortName() << ") --> InPort " << anInPort->NodeName()
1875 //               << "(" << anInPort->PortName() << ")" << endl ;
1876       }
1877       else {
1878         cdebug << "GraphBase::Graph::PortInData " << ToNodeName << " "
1879                << ToServiceParameterName << " ERROR no OutPort" << endl ;
1880       }
1881     }
1882     else {
1883       cdebug << "GraphBase::Graph::PortInData " << ToNodeName << " "
1884              << ToServiceParameterName << " ERROR no InPort" << endl ;
1885     }
1886   }
1887   else {
1888     cdebug << "GraphBase::Graph::PortInData " << ToNodeName << " "
1889            << ToServiceParameterName << " ERROR no Node" << endl ;
1890   }
1891   delete theNode ;
1892   delete aPort ;
1893 //  cdebug_out << "GraphBase::Graph::PortInData " << endl ;
1894   return aRet ;
1895 }
1896
1897 const CORBA::Any * GraphBase::Graph::PortOutData( const char* FromNodeName ,
1898                                                   const char* FromServiceParameterName ) {
1899   const CORBA::Any * aRet = new CORBA::Any() ;
1900   char *theNode ;
1901   char *aPort ;
1902 //  cdebug_in << "GraphBase::Graph::PortOutData " << FromNodeName << " "
1903 //            << FromServiceParameterName << endl ;
1904   NodePort( FromNodeName , FromServiceParameterName , &theNode , &aPort ) ;
1905
1906   GraphBase::ComputingNode * aNode = GetChangeGraphNode( theNode ) ;
1907
1908   if ( aNode ) {
1909     GraphBase::OutPort *anOutPort ;
1910     anOutPort = aNode->GetChangeOutPort( aPort );
1911     if ( anOutPort ) {
1912       aRet = anOutPort->Value() ;
1913     }
1914     else {
1915       cdebug << "GraphBase::Graph::PortOutData " << FromNodeName << " "
1916              << FromServiceParameterName << " ERROR no OutPort" << endl ;
1917     }
1918   }
1919   else {
1920     cdebug << "GraphBase::Graph::PortOutData " << FromNodeName << " "
1921            << FromServiceParameterName << " ERROR no Node" << endl ;
1922   }
1923   delete theNode ;
1924   delete aPort ;
1925 //  cdebug_out << "GraphBase::Graph::PortOutData " << endl ;
1926   return aRet ;
1927 }
1928
1929 SUPERV::ListOfStrings * GraphBase::Graph::LevelNodes(long aLevel ) {
1930   SUPERV::ListOfStrings_var RetVal = new SUPERV::ListOfStrings;
1931   if ( aLevel >= 0 && aLevel <= _LevelsNumber ) {
1932     int i ;
1933     RetVal->length( _NodesNumber[ aLevel ] + 1 );
1934     for ( i= 0 ; i <= _NodesNumber[ aLevel ] ; i++ ) {
1935       RetVal[i] = CORBA::string_dup( (_SortedNodes[ aLevel ])[ i ]->Name() ) ;
1936     }
1937   }
1938   return ( RetVal._retn() ) ;
1939 }
1940
1941 bool GraphBase::Graph::StartComponent(const int aThread ,
1942                                       const char * aComputerContainer ,
1943                                       const char * ComponentName ,
1944                                       Engines::Container_var & myContainer ,
1945                                       Engines::Component_var & objComponent ) {
1946   cdebug_in << aThread
1947             << " GraphBase::Graph::StartComponent " << aComputerContainer
1948             << " " << ComponentName << endl;
1949   bool RetVal = true ;
1950
1951   SALOME_LifeCycleCORBA LCC( NamingService() ) ;
1952   objComponent = LCC.FindOrLoad_Component( aComputerContainer ,
1953                                            ComponentName );
1954   if ( CORBA::is_nil( objComponent ) ) {
1955     cdebug_out << aThread 
1956                << " StartComponent cannot FindOrLoad " << aComputerContainer
1957                << " " << ComponentName << endl;
1958     return 0 ;
1959   }
1960   else {
1961     myContainer = LCC.FindContainer( aComputerContainer );
1962     if ( CORBA::is_nil( myContainer ) ) {
1963       cdebug_out << aThread
1964                  << " GraphBase::Graph::StartComponent myContainer = LCC.FindContainer( '"
1965                  << aComputerContainer << "' ) Container does not exist"
1966                  << endl ;
1967       return 0 ;
1968     }
1969   }
1970   cdebug_out << aThread << " GraphBase::Graph::StartComponent" << endl;
1971   return RetVal ;
1972 }
1973