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