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