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