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