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