]> SALOME platform Git repositories - modules/superv.git/blob - src/GraphBase/DataFlowBase_Graph.cxx
Salome HOME
method getViewType() added that returns CANVAS, CONTROL or CANVASTABLE constant corre...
[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() ) == 0 ) {
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 // JR 12.01.2005 : an OutPort of a SwitchNode connected to a Gate can be connected only to Gate
1073   else if ( fromNode->IsSwitchNode() && fromPort->IsSwitch() && !toPort->IsGate() ) {
1074     cdebug << "toPort->AddLink Error( fromPort->IsSwitch() && !toPort->IsGate())." << endl ;
1075     cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1076     return false ;
1077   }
1078   else if ( !fromPort->AddInPort( toPort ) ) { // --> MapOfInports in the OutPort
1079     cdebug << "!fromPort->AddLink Error." << endl ;
1080     cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1081     return false ;
1082   }
1083
1084   if ( fromNode->IsGOTONode() && ( !fromPort->IsGate() || !toPort->IsGate() ||
1085        toNode->IsEndLoopNode() || toNode->IsEndSwitchNode() ) ) {
1086     cdebug << "toPort->AddLink Error( fromNode->IsGOTONode() && toNode->IsEndInLineNode() )." << endl ;
1087     cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1088     return false ;
1089   }
1090   else if ( !fromNode->IsSwitchNode() && fromPort->IsParam() && toPort->IsGate() ) {
1091     cdebug << "toPort->AddLink Error( fromPort->IsParam() && toPort->IsGate())." << endl ;
1092     cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1093     return false ;
1094   }
1095   else if ( !toNode->IsEndSwitchNode() && !toNode->IsEndLoopNode() ) {
1096     if ( !toPort->AddOutPort( fromPort ) ) { // --> Unique OutPort of the InPort
1097       cdebug << "toPort->AddLink Error." << endl ;
1098       cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1099       return false ;
1100     }
1101   }
1102   else {
1103     toPort->AddOutPort( fromPort ) ;
1104   }
1105
1106   if ( ( fromNode->IsGOTONode() && toNode->IsOneOfInLineNodes() ) ||
1107        ( fromNode->IsEndLoopNode() && toNode->IsLoopNode() ) ) {
1108     cdebug << "AddLink fromPort->PortStatus( PortConnected ) "
1109            << "GOTONode/EndLoopNode-->InLineNode/LoopNode/SwitchNode "
1110            << fromNode->Name() << " " << fromPort->PortName()
1111            << " InLineNode/LoopNode_ConnectedInPortsNumber "
1112            << toNode->ConnectedInPortsNumber() << endl;
1113     if ( fromNode->IsGOTONode() ) {
1114       fromPort->Kind( SUPERV::GOTOParameter ) ;
1115     }
1116     fromPort->PortStatus( PortConnected ); // GOTO - Loop
1117   }
1118   else if ( fromNode->IsDataFlowNode() || fromNode->IsDataStreamNode() ) {
1119     cdebug << "AddLink IsDataFlow/StreamNode fromPort->PortStatus( DataConnected ) : "
1120            << fromNode->Name() << " " << fromPort->PortName() << endl ;
1121     fromPort->PortStatus( ExternConnected );
1122   }
1123   else if ( toNode->IsDataFlowNode() || toNode->IsDataStreamNode() ) {
1124     cdebug << "AddLink IsDataFlow/StreamNode fromPort->PortStatus( ExternConnected ) : "
1125            << fromNode->Name() << " " << fromPort->PortName() << endl ;
1126     fromPort->PortStatus( ExternConnected ) ;
1127   }
1128   else {
1129     cdebug << "AddLink fromPort->PortStatus( PortConnected ) & fromNode->toNode "
1130            << fromNode->Name() << " " << fromPort->PortName() << " "
1131            << fromPort->Kind() << " OldPortStatus " << fromPort->PortStatus() << " -> " << toNode->Name()
1132            << " " << " " << toPort->PortName() << " " << toPort->Kind() << endl;
1133     fromPort->PortStatus( PortConnected );
1134     if ( fromPort->IsDataStream() && toPort->IsDataStream() ) {
1135       fromNode->AddStreamLinkedNode( toNode ) ;
1136     }
1137     else {
1138       fromNode->AddLinkedNode( toNode ) ;
1139     }
1140   }
1141   if ( fromNode->IsSwitchNode() ) {
1142     if ( !fromPort->IsDataStream() ) {
1143       if ( fromPort->IsInLine() && toPort->IsGate() && !toNode->IsEndSwitchNode() ) {
1144         fromPort->Kind( SUPERV::SwitchParameter ) ;
1145       }
1146       else if ( !fromPort->IsGate() && !toPort->IsGate() ){
1147         fromPort->Kind( SUPERV::InLineParameter ) ;
1148       }
1149     }
1150     if ( fromPort->IsGate() && !toNode->IsEndSwitchNode() ) {
1151       GraphBase::InLineNode * anEndSwitchNode ;
1152       anEndSwitchNode = ((GraphBase::SwitchNode * ) fromNode)->CoupledNode() ;
1153       GraphBase::InPort * anInPort = anEndSwitchNode->GetChangeNodeInGate() ;
1154       GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1155       if ( anOutPort && !strcmp( fromNode->Name() , anOutPort->NodeName() ) &&
1156            !strcmp( fromPort->PortName() , anOutPort->PortName() ) &&
1157            anOutPort->IsGate() ) {
1158         if ( !RemoveLink( fromNode->Name() , anOutPort->PortName() ,
1159                           anEndSwitchNode->Name() ,
1160                           anInPort->PortName() ) ) {
1161           cdebug << "AddLink Error Removelink ( Switch , Default , EndSwitch , Default )"
1162                  << endl ;
1163           cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1164           return false ;
1165         }
1166       }
1167     }
1168   }
1169 //  cdebug << fromNode->ServiceName() << " " << toNode->ServiceName() << endl ;
1170   cdebug_out << "GraphBase::Graph::AddLink 1" << endl;
1171   return true ;
1172 }
1173
1174 bool GraphBase::Graph::RemoveLink( const char* FromNodeName ,
1175                                    const char* FromServiceParameterName ,
1176                                    const char* ToNodeName ,
1177                                    const char* ToServiceParameterName ) {
1178   cdebug_in << "GraphBase::Graph::RemoveLink from " << FromNodeName << "(" << FromServiceParameterName << ")"
1179             << " to " << ToNodeName << "(" << ToServiceParameterName << ")" << endl;
1180   bool RetVal = false ;
1181   GraphBase::ComputingNode * toNode = GetChangeGraphNode( ToNodeName ) ;
1182   if ( toNode ) {
1183     GraphBase::InPort * anInPort = toNode->GetChangeInPort( ToServiceParameterName ) ;
1184     if ( anInPort && ( anInPort->IsPortConnected() ||
1185                        anInPort->IsDataConnected() ||
1186                        anInPort->IsExternConnected() ) ) {
1187 // JR 13.01.2005 : Bug if it is a link to an EndSwitchNode. The OutPort may be an other one !!!
1188       GraphBase::ComputingNode * fromNode = GetChangeGraphNode( FromNodeName ) ;
1189       GraphBase::OutPort * anOutPort = NULL ;
1190       if ( toNode->IsEndSwitchNode() ) {
1191         anOutPort = fromNode->GetChangeOutPort( FromServiceParameterName ) ;
1192         RetVal = anOutPort->RemoveInPort( anInPort ) ;
1193       }
1194       else {
1195         anOutPort = anInPort->GetOutPort() ;
1196         RetVal = anOutPort->RemoveInPort( anInPort ) ;
1197       }
1198 //      anInPort->RemoveOutPort() ; // Already done in RemoveInPort
1199 //      const char * FromNodeName = anOutPort->NodeName() ;
1200       if ( RetVal ) {
1201         if ( fromNode ) {
1202           if ( anInPort->IsDataStream() ) {
1203             fromNode->RemoveStreamLinkedNode( toNode ) ;
1204           }
1205           else {
1206             fromNode->RemoveLinkedNode( toNode ) ;
1207           }
1208         }
1209         if ( fromNode->IsSwitchNode() && !anOutPort->IsGate() && !toNode->IsEndSwitchNode() ) {
1210           anOutPort->Kind( SUPERV::InLineParameter ) ;
1211         }
1212 // JR 13.01.2005 : Bug if it is a link to an EndSwitchNode. The InPort may be linked !!!
1213         if ( toNode->IsEndSwitchNode() ) {
1214           int i ;
1215           int done = false ;
1216           for ( i = 0 ; i < toNode->LinkedFromNodesSize() ; i++ ) {
1217             GraphBase::StreamNode * fromNode = toNode->LinkedFromNodes( i ) ;
1218             int j ;
1219             for ( j = 0 ; j < fromNode->GetNodeOutPortsSize() ; j++ ) {
1220               GraphBase::OutPort * fromOutPort = fromNode->GetChangeNodeOutPort( j ) ;
1221               int k ;
1222               for ( k = 0 ; k < fromOutPort->InPortsSize() ; k++ ) {
1223                 if ( strcmp( toNode->Name() , fromOutPort->InPorts( k )->NodeName() ) == 0 ) {
1224 // Restore an OutPort in the InPort
1225                   anInPort->ChangeOutPort( fromOutPort ) ;
1226                   cdebug << "Graph::RemoveLink reestablish " << fromOutPort->NodeName() << "( "
1227                          << fromOutPort->PortName() << " ) in the InPort of EndSwitch : "
1228                          << toNode->Name() << "( " << anInPort->PortName() << " )" << endl;
1229                   done = true ;
1230                   break ;
1231                 }
1232               }
1233               if ( done ) {
1234                 break ;
1235               }
1236             }
1237             if ( done ) {
1238               break ;
1239             }
1240           }
1241         }
1242       }
1243     }
1244   }
1245   cdebug_out << "GraphBase::Graph::RemoveLink " << RetVal << endl;
1246   return RetVal ;
1247 }
1248
1249 bool GraphBase::Graph::GetLink(const char* ToNodeName ,
1250                                const char* ToServiceParameterName ,
1251                                char** FromNodeName ,
1252                                char** FromServiceParameterName ) {
1253 //  cdebug_in << "GraphBase::Graph::GetLink " << ToNodeName << "("
1254 //            << ToServiceParameterName << ")" << endl;
1255   bool RetVal = false ;
1256   GraphBase::ComputingNode * toNode = GetChangeGraphNode( ToNodeName ) ;
1257   if ( toNode ) {
1258     GraphBase::InPort * anInPort = toNode->GetChangeInPort( ToServiceParameterName ) ;
1259     if ( anInPort && !anInPort->IsNotConnected() ) {
1260       GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1261       *FromNodeName = my_strdup( anOutPort->NodeName() ) ;
1262       *FromServiceParameterName = my_strdup( anOutPort->PortName() ) ;
1263       RetVal = true ;
1264     }
1265     else {
1266       cdebug << "GraphBase::Graph::GetLink ERROR no InPort or NotConnected " << ToNodeName
1267              << " " << ToServiceParameterName << " " << RetVal << endl;
1268     }
1269   }
1270   else {
1271     cdebug << "GraphBase::Graph::GetLink ERROR no Node " << ToNodeName << " " << RetVal
1272            << endl;
1273   }
1274 //  cdebug_out << "GraphBase::Graph::GetLink " << RetVal << endl;
1275   return RetVal ;
1276 }
1277
1278 bool GraphBase::Graph::AddInputData( const char* ToNodeName ,
1279                                      const char* ToServiceParameterName ,
1280                                      const CORBA::Any aValue ) {
1281   bool RetVal = false ;
1282   cdebug_in << "GraphBase::Graph::AddInputData(" << ToNodeName << ","
1283             << ToServiceParameterName << " , Any " ;
1284   switch (aValue.type()->kind()) {
1285     case CORBA::tk_string:
1286       char * t;
1287       aValue >>= t;
1288       cdebug << t << " (string) " ;
1289       break;
1290     case CORBA::tk_double:
1291       double d;
1292       aValue >>= d;
1293       cdebug << d << " (double) " ;
1294       break;
1295     case CORBA::tk_long:
1296       long l;
1297       aValue >>= l;
1298       cdebug << l << " (long) " ;
1299       break;
1300     case CORBA::tk_objref:
1301       cdebug << "(object reference) " ;
1302       break;
1303     default:
1304       cdebug << "(other(tk_string(" << CORBA::tk_string << "),tk_double(" << CORBA::tk_double << "),tk_long("
1305              << CORBA::tk_long << "),tk_objref)(" << CORBA::tk_objref << ")) ERROR : " << aValue.type()->kind() ;
1306       break;
1307     }
1308   cdebug << " ) in Graph " << Name() << endl;
1309  
1310   GraphBase::ComputingNode *toNode ;
1311   GraphBase::InPort *toPort ;
1312   char *aNodeName ;
1313   char *aPortName ;
1314   NodePort( ToNodeName , ToServiceParameterName , &aNodeName , &aPortName ) ;
1315   toNode = GetChangeGraphNode( aNodeName ) ;
1316   cdebug << "in Graph " << Name() << " aNodeName " << aNodeName << " aPortName " << aPortName << endl;
1317   if ( toNode ) {
1318     toPort = toNode->GetChangeInPort( aPortName ) ;
1319     if ( toPort && !toPort->IsDataConnected() ) {
1320       toPort->RemoveOutPort() ;
1321     }
1322   }
1323   else {
1324     toPort = NULL ;
1325   }
1326
1327   int i ;
1328   for ( i = 0 ; i < GetNodeOutDataNodePortsSize() ; i++ ) {
1329     cdebug << "Graph::AddInputData In" << i << " " << *GetNodeOutDataNodePort(i) << endl ;
1330   }
1331   for ( i = 0 ; i < GetNodeInDataNodePortsSize() ; i++ ) {
1332     cdebug << "Graph::AddInputData Out" << i << " " << *GetNodeInDataNodePort(i) << endl ;
1333   }
1334
1335   if ( toNode && toPort ) {
1336     GraphBase::OutPort *fromDataNodePort = NULL ;
1337     fromDataNodePort = GraphBase::DataNode::GetChangeInDataNodePort( toPort->NodePortName() ) ;
1338     if ( fromDataNodePort && fromDataNodePort->GetInPort( toPort ) ) {
1339       fromDataNodePort->RemoveInPort( toPort ) ;
1340     }
1341     cdebug << "Try AddLink " << toPort->NodePortName() << " : " << Name() << "( "
1342            << fromDataNodePort->PortName() << " ) -->" << toNode->Name() << "( "
1343            << toPort->PortName() << " )" << endl ;
1344     RetVal = AddLink( (GraphBase::ComputingNode * ) this , fromDataNodePort ,
1345                       toNode , toPort ) ;
1346     if ( RetVal ) {
1347       fromDataNodePort->Value( aValue ) ;
1348       fromDataNodePort->PortStatus( DataConnected ) ;
1349     }
1350   }
1351   else {
1352     cdebug << "ERROR Node and/or Port not found : " << aNodeName << " " << aPortName << endl ;
1353   }
1354   delete aNodeName ;
1355   delete aPortName ;
1356
1357   cdebug_out << "GraphBase::Graph::AddInputData " << RetVal << endl;
1358   return RetVal ;
1359 }
1360
1361 // Used in the Executor in order to change an Input Value and ReRun
1362 bool GraphBase::Graph::ChangeInputData( const char * ToNodeName ,
1363                                         const char * ToServiceParameterName ,
1364                                         const CORBA::Any aValue ) {
1365   bool RetVal = false ;
1366   cdebug_in << "GraphBase::Graph::ChangeInputData( '" << ToNodeName << "' , '"
1367             << ToServiceParameterName << "' , Any " ;
1368   switch (aValue.type()->kind()) {
1369     case CORBA::tk_string:
1370       char * t;
1371       aValue >>= t;
1372       cdebug << t << " (string) " ;
1373       break;
1374     case CORBA::tk_double:
1375       double d;
1376       aValue >>= d;
1377       cdebug << d << " (double) " ;
1378       break;
1379     case CORBA::tk_long:
1380       long l;
1381       aValue >>= l;
1382       cdebug << l << " (long) " ;
1383       break;
1384     case CORBA::tk_objref:
1385       cdebug << "(object reference) " ;
1386       break;
1387     default:
1388       cdebug << "(other(tk_string,tk_double,tk_long,tk_objref)) ERROR";
1389       break;
1390     }
1391   cdebug << " ) in Graph " << Name() << endl;
1392
1393   GraphBase::ComputingNode * toNode ;
1394   GraphBase::InPort * toPort = NULL ;
1395   char * aNodeName ;
1396   char * aPortName ;
1397   NodePort( ToNodeName , ToServiceParameterName , &aNodeName , &aPortName ) ;
1398   toNode = GetChangeGraphNode( aNodeName ) ;
1399   cdebug << "in Graph " << Name() << " aNodeName " << aNodeName << " aPortName " << aPortName << endl;
1400   if ( toNode ) {
1401     toPort = toNode->GetChangeInPort( aPortName ) ;
1402     if ( toPort && toPort->IsDataConnected() ) {
1403       GraphBase::OutPort * fromPort = toPort->GetOutPort();
1404       if ( fromPort ) {
1405         RetVal = true ;
1406         fromPort->Value( aValue ) ;
1407         fromPort->PortStatus( DataConnected ) ;
1408         toPort->State( SUPERV::ReadyState ) ;
1409       }
1410       else {
1411         cdebug << "ERROR ChangeInputData fromPort not found" << endl ;
1412       }
1413     }
1414     else {
1415       cdebug << "ERROR ChangeInputData toPort not found" << endl ;
1416     }
1417   }
1418   else {
1419     cdebug << "ERROR ChangeInputData Node not found : " << ToNodeName << endl ;
1420   }
1421
1422   cdebug_out << "GraphBase::Graph::ChangeInputData" << endl;
1423   return RetVal ;
1424 }
1425
1426 // To restore InputData in CreateService
1427 bool GraphBase::Graph::AddInputData( const char* ToNodeName ,
1428                                      const char* ToServiceParameterName ,
1429                                      const CORBA::Any ** aValue ) {
1430   bool RetVal = false ;
1431   cdebug_in << "GraphBase::Graph::AddInputData( " << ToNodeName << " , "
1432             << ToServiceParameterName << ", **Any " ;
1433   const CORBA::Any theValue = **aValue ;
1434   switch (theValue.type()->kind()) {
1435     case CORBA::tk_string:
1436       char * t;
1437       theValue >>= t;
1438       cdebug << t << " (string) " ;
1439       break;
1440     case CORBA::tk_double:
1441       double d;
1442       theValue >>= d;
1443       cdebug << d << " (double) " ;
1444       break;
1445     case CORBA::tk_long:
1446       long l;
1447       theValue >>= l;
1448       cdebug << l << " (long) " ;
1449       break;
1450     case CORBA::tk_objref:
1451       cdebug << "(object reference) " ;
1452       break;
1453     default:
1454       cdebug << "(other(tk_string,tk_double,tk_long,tk_objref)) ERROR";
1455       break;
1456     }
1457   cdebug << ") of Graph " << Name() << endl;
1458
1459   GraphBase::ComputingNode *toNode = GetChangeGraphNode( ToNodeName ) ;
1460
1461   if ( toNode ) {
1462     GraphBase::InPort *toPort = NULL ;
1463     GraphBase::OutPort *fromDataNodePort = NULL ;
1464     toPort = toNode->GetChangeInPort( ToServiceParameterName ) ;
1465     fromDataNodePort = GraphBase::DataNode::GetChangeInDataNodePort( toPort->NodePortName() ) ;
1466     cdebug << "Try AddLink " << Name() << "( " << fromDataNodePort << " ) -->"
1467            << toNode->Name() << "( " << toPort->PortName() << " )" << endl ;
1468     RetVal = AddLink( (GraphBase::ComputingNode * ) this , fromDataNodePort ,
1469                       toNode , toPort ) ;
1470     if ( RetVal ) {
1471       fromDataNodePort->Value( aValue ) ;
1472       fromDataNodePort->PortStatus( DataConnected ) ;
1473     }
1474   }
1475   else {
1476     cdebug << "ERROR Node not found " << ToNodeName << " ERROR. Known nodes :" << endl ;
1477     map< string , int >::iterator aMapOfGraphNodesIterator ;
1478     int i = 0 ;
1479     for ( aMapOfGraphNodesIterator = _MapOfGraphNodes.begin() ;
1480           aMapOfGraphNodesIterator != _MapOfGraphNodes.end() ; aMapOfGraphNodesIterator++ ) {
1481       cdebug << "MapOfGraphNodes " << i++ << " " << aMapOfGraphNodesIterator->first << " --> "
1482              << aMapOfGraphNodesIterator->second << endl ;
1483     }
1484   }
1485
1486   cdebug_out << "GraphBase::Graph::AddInputData " << RetVal << endl;
1487   return RetVal ;
1488 }
1489
1490 bool GraphBase::Graph::AddOutputData( const char* FromNodeName ,
1491                                       const char* FromServiceParameterName ,
1492                                       const CORBA::Any aValue ) {
1493   bool RetVal = true ;
1494   cdebug_in << "GraphBase::Graph::AddOutputData(" << FromNodeName << ","
1495             << FromServiceParameterName << ")" << endl;
1496   GraphBase::ComputingNode *fromNode = GetChangeGraphNode( FromNodeName ) ;
1497
1498   GraphBase::OutPort *anOutPort = NULL ;
1499
1500   if ( fromNode ) {
1501     anOutPort = fromNode->GetChangeOutPort( FromServiceParameterName ) ;
1502 //    toDataNodePort = GraphBase::DataNode::GetChangeOutDataNodePort( fromPort->NodePortName() ) ;
1503 //    RetVal = AddLink( fromNode , fromPort ,
1504 //                      (GraphBase::ComputingNode * ) this , toDataNodePort ) ;
1505     anOutPort->Value( aValue ) ;
1506     anOutPort->State(  SUPERV::ReadyState ) ;
1507     anOutPort->Done( true ) ;
1508     cdebug << *anOutPort ;
1509 #ifdef _DEBUG_
1510     anOutPort->StringValue( *_fdebug ) ;
1511 #endif
1512     cdebug << endl ;
1513   }
1514   else {
1515     cdebug << "ERROR Node not found" << endl ;
1516     RetVal = false ;
1517   }
1518   cdebug_out << "GraphBase::Graph::AddOutputData " << RetVal << endl;
1519   return RetVal ;
1520 }
1521
1522 map< string , GraphBase::Service * > GraphBase::Graph::MapOfServiceNames() {
1523                                            return _MapOfServiceNames ; }
1524
1525 GraphBase::Service * GraphBase::Graph::GetServiceOfMap( char * name ) {
1526   return _MapOfServiceNames[ name ] ;
1527 }
1528
1529 bool GraphBase::Graph::SetServiceOfMap( GraphBase::Service * aService ) {
1530   GraphBase::Service * theService = _MapOfServiceNames[ aService->ServiceName() ] ;
1531   if ( theService ) {
1532     cdebug << "SetServiceOfMap of " << aService->ServiceName()
1533            << " already in MapOfServiceNames : erase" << endl ;
1534     _MapOfServiceNames.erase( aService->ServiceName() ) ;
1535   }
1536   _MapOfServiceNames[ (char * ) aService->ServiceName() ] = aService ;
1537   cdebug << "SetServiceOfMap of " << aService->ServiceName() << " done" << endl ;
1538   return true ;
1539 }
1540
1541 int GraphBase::Graph::GetServiceNameNumber( SALOME_ModuleCatalog::Service aService ) {
1542   GraphBase::Service * theService = _MapOfServiceNames[ (char * ) aService.ServiceName ] ;
1543   if ( theService == NULL ) {
1544     return 1 ;
1545   }
1546   return theService->NewInstance() ;
1547 }
1548
1549 void GraphBase::Graph::SetGraphPorts() {
1550   cdebug_in << "GraphBase::Graph::SetGraphPorts fill ports of Graph" << endl;
1551   int i ;
1552   for ( i = 0 ; i < GetNodeInDataNodePortsSize() ; i++ ) {
1553     GraphBase::OutPort * anOutPort = GetChangeNodeInDataNodePort( i ) ;
1554     cdebug << "SetGraphPorts Out" << i << " " << anOutPort->PortName() << " " << anOutPort->PortType()
1555            << " " << anOutPort->Kind() << " " << anOutPort->PortStatus() << " " << anOutPort->State() << endl ;
1556     if ( !anOutPort->IsGate() ) {
1557       anOutPort->PortStatus( ExternConnected ) ;
1558     }
1559   }
1560   for ( i = 0 ; i < GetNodeOutDataNodePortsSize() ; i++ ) {
1561     GraphBase::InPort * anInPort = GetChangeNodeOutDataNodePort( i ) ;
1562     cdebug << "SetGraphPorts In" << i << " " << anInPort->PortName() << " " << anInPort->PortType()
1563            << " " << anInPort->Kind() << " " << anInPort->PortStatus() << " " << anInPort->State() << endl ;
1564     if ( !anInPort->IsGate() ) {
1565       GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1566       anOutPort->PortStatus( ExternConnected ) ;
1567     }
1568   }
1569   cdebug_out << "GraphBase::Graph::SetGraphPorts" << endl;
1570 }
1571
1572 bool GraphBase::Graph::CreateService() {
1573   cdebug_in << "GraphBase::Graph::CreateService " << Name() << " GraphMacroLevel : " << GraphMacroLevel() << endl;
1574   bool RetVal = true ;
1575   SALOME_ModuleCatalog::Service aService ;
1576   int i , j ;
1577   GraphBase::ComputingNode * aToNode ;
1578   int dostore ;
1579   int innbr = 0 ;
1580   int instreamnbr = 0 ;
1581   int outnbr = 0 ;
1582   int outstreamnbr = 0 ;
1583   vector< SUPERV::KindOfPort > InPortsKind ;
1584   vector< SALOME_ModuleCatalog::DataStreamDependency > InDataStreamDependency ;
1585   vector< SUPERV::KindOfSchema > InKindOfSchema ;
1586   vector< SUPERV::KindOfInterpolation > InKindOfInterpolation ;
1587   vector< SUPERV::KindOfExtrapolation > InKindOfExtrapolation ;
1588   vector< SUPERV::KindOfPort > OutPortsKind ;
1589   vector< SALOME_ModuleCatalog::DataStreamDependency > OutDataStreamDependency ;
1590   vector< long > OutNumberOfValues ;
1591 //  if ( GraphMacroLevel() == 0 ) {
1592     for ( dostore = 0 ; dostore <= 2 ; dostore++ ) {
1593       if ( dostore == 1 ) {
1594         aService.ServiceName = Name() ;
1595         aService.ServiceinParameter.length( 0 ) ;
1596         aService.ServiceinParameter.length( innbr ) ;
1597         aService.ServiceoutParameter.length( 0 ) ;
1598         aService.ServiceoutParameter.length( outnbr ) ;
1599         InPortsKind.resize( innbr ) ;
1600         InDataStreamDependency.resize( innbr ) ;
1601         InKindOfSchema.resize( innbr ) ;
1602         InKindOfInterpolation.resize( innbr ) ;
1603         InKindOfExtrapolation.resize( innbr ) ;
1604         OutPortsKind.resize( outnbr ) ;
1605         OutDataStreamDependency.resize( outnbr ) ;
1606         OutNumberOfValues.resize( outnbr ) ;
1607       }
1608       else if ( dostore == 2 ) {
1609         cdebug << "GraphBase::Graph::CreateService ->DataService innbr " << innbr
1610                << " instreamnbr " << instreamnbr << " outnbr " << outnbr
1611                << " outstreamnbr " << outstreamnbr << endl ;
1612         DataService( _Orb , aService , Graph_prof_debug() , Graph_fdebug() ) ;
1613         aService.ServiceinParameter.length( innbr + instreamnbr ) ;
1614         aService.ServiceoutParameter.length( outnbr + outstreamnbr ) ;
1615         InPortsKind.resize( innbr + instreamnbr ) ;
1616         InDataStreamDependency.resize( innbr + instreamnbr ) ;
1617         InKindOfSchema.resize( innbr + instreamnbr ) ;
1618         InKindOfInterpolation.resize( innbr + instreamnbr ) ;
1619         InKindOfExtrapolation.resize( innbr + instreamnbr ) ;
1620         OutPortsKind.resize( outnbr + outstreamnbr ) ;
1621         OutDataStreamDependency.resize( outnbr + outstreamnbr ) ;
1622         OutNumberOfValues.resize( outnbr + outstreamnbr ) ;
1623       }
1624       if ( dostore == 0 ) {
1625         innbr = 0 ;
1626         instreamnbr = 0 ;
1627         outnbr = 0 ;
1628         outstreamnbr = 0 ;
1629       }
1630       if ( dostore == 1 ) {
1631         innbr = 0 ;
1632         outnbr = 0 ;
1633       }
1634       for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1635         aToNode = GraphNodes( i ) ;
1636         for ( j = 0 ; j < aToNode->GetNodeInPortsSize() ; j++ ) {
1637           GraphBase::InPort *anInPort = aToNode->GetChangeNodeInPort(j) ;
1638           bool isfromcouplednode = false ;
1639           if ( !anInPort->IsNotConnected() ) {
1640             const char * aFromNodeName = anInPort->GetOutPort()->NodeName() ;
1641             GraphBase::ComputingNode * aFromNode = GetChangeGraphNode( aFromNodeName ) ;
1642             cdebug << "GraphBase::Graph::CreateService aFromNodeName " << aFromNodeName << " aToNode "
1643                    << aToNode->Name() << " InPort" << j << " " << anInPort->PortName() << endl ;
1644             if ( aFromNode && aFromNode->IsEndLoopNode() &&
1645                  ((GraphBase::EndOfLoopNode * ) aFromNode)->CoupledNode() == aToNode ) {
1646               isfromcouplednode = true ;
1647             }
1648           }
1649           if ( !anInPort->IsGate() && !anInPort->IsLoop() &&
1650                ( !anInPort->IsPortConnected() ||
1651                  ( anInPort->IsPortConnected() && isfromcouplednode ) ) ) {
1652             if ( dostore == 0 ) {
1653               cdebug << "CreateService " << aToNode->Name() << " Input port "
1654                      << anInPort->PortName() << " " << anInPort->Kind() << " " << anInPort->PortStatus() ;
1655               if ( anInPort->GetOutPort() ) {
1656                 cdebug << "DataConnected from " <<  *(anInPort->GetOutPort() ) ;
1657               }
1658               cdebug << endl ;
1659               if ( anInPort->IsDataStream() ) {
1660                 instreamnbr += 1 ;
1661               }
1662               else {
1663                 innbr += 1 ;
1664               }
1665             }
1666             else if ( ( dostore == 1 && !anInPort->IsDataStream() ) ||
1667                       ( dostore == 2 && anInPort->IsDataStream() ) ) {
1668               aService.ServiceinParameter[innbr].Parametertype = CORBA::string_dup( anInPort->PortType() ) ;
1669               aService.ServiceinParameter[innbr].Parametername = CORBA::string_dup( anInPort->NodePortName() ) ;
1670               InPortsKind[ innbr ] = anInPort->Kind() ;
1671               InDataStreamDependency[ innbr ] = anInPort->Dependency() ;
1672               if ( dostore == 2 && anInPort->IsDataStream() ) {
1673                 ((GraphBase::InDataStreamPort * ) anInPort)->Params( InKindOfSchema[ innbr ] ,
1674                                                                      InKindOfInterpolation[ innbr ] ,
1675                                                                      InKindOfExtrapolation[ innbr ] ) ;
1676               }
1677               cdebug << "In" << innbr << " " << aService.ServiceinParameter[ innbr ].Parametername << " "
1678                      << anInPort->Kind() << " " << anInPort->PortStatus() << endl ;
1679               innbr += 1 ;
1680             }
1681           }
1682           else if ( dostore == 0 ) {
1683             cdebug << "CreateService " << aToNode->Name() << " Input port " << anInPort->PortName()
1684                    << " " << anInPort->PortStatus() ;
1685             if ( anInPort->IsPortConnected() ) {
1686               cdebug << " is connected " ;
1687             }
1688             else {
1689               cdebug << " is NOT connected " ;
1690             }
1691             if ( anInPort->IsGate() ) {
1692               cdebug << " IsGate " ;
1693             }
1694             if ( anInPort->GetOutPort() ) {
1695               cdebug << "DataConnected from " <<  *(anInPort->GetOutPort()) ;
1696             }
1697             else {
1698               cdebug << "NOT DataConnected" ;
1699             }
1700             cdebug << endl ;
1701           }
1702         }
1703         GraphBase::ComputingNode * aFromNode = aToNode ;
1704         for ( j = 0 ; j < aFromNode->GetNodeOutPortsSize() ; j++ ) {
1705           GraphBase::OutPort *anOutPort = aFromNode->GetChangeNodeOutPort(j) ;
1706 //          cdebug << "CreateService Node " << aFromNode->Name() << ". Output port[" << j << "] ";
1707 //          if ( anOutPort ) {
1708 //            cdebug << anOutPort->PortName() << " " << anOutPort->ServicesParameterType() << endl ;
1709 //        }
1710 //          else {
1711 //            cdebug << " NULL" << endl ;
1712 //        }
1713           if ( !aFromNode->IsGOTONode() ) {
1714             if ( !anOutPort->IsGate() && ( anOutPort->IsNotConnected() || anOutPort->IsDataConnected() ) ||
1715                                            anOutPort->IsExternConnected() ) {
1716               if ( dostore == 0 ) {
1717 //                cdebug << "CreateService " << aFromNode->Name() << " Output port "
1718 //                       << anOutPort->PortName() << " " << anOutPort->PortStatus() << endl ;
1719                 if ( anOutPort->IsDataStream() ) {
1720                   outstreamnbr += 1 ;
1721                 }
1722                 else {
1723                   outnbr += 1 ;
1724                 }
1725               }
1726               else if ( ( dostore == 1 && !anOutPort->IsDataStream() ) ||
1727                         ( dostore == 2 && anOutPort->IsDataStream() ) ) {
1728                 aService.ServiceoutParameter[outnbr].Parametertype = CORBA::string_dup( anOutPort->PortType() ) ;
1729                 aService.ServiceoutParameter[outnbr].Parametername = CORBA::string_dup( anOutPort->NodePortName() ) ;
1730                 OutPortsKind[ outnbr ] = anOutPort->Kind() ;
1731                 OutDataStreamDependency[ outnbr ] = anOutPort->Dependency() ;
1732                 if ( dostore == 2 && anOutPort->IsDataStream() ) {
1733                   OutNumberOfValues[ outnbr ] = ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues() ;
1734                 }
1735 //                cdebug << "Out" << outnbr << " " << aService.ServiceoutParameter[ outnbr ].Parametername << " "
1736 //                       << anOutPort->Kind() << " " << anOutPort->PortStatus() << endl ;
1737                 outnbr += 1 ;
1738               }
1739             }
1740           }
1741         }
1742       }
1743     }
1744 //  }
1745
1746 #if 0
1747   cdebug << "DataFlowNode ServiceName " << aService.ServiceName << " InPorts " << innbr
1748          << " OutPorts " << outnbr << endl ;
1749   for ( i = 0 ; i < innbr ; i++ ) {
1750     cdebug << "aService.ServiceinParameter[" << i << "].Parametertype "
1751          << aService.ServiceinParameter[i].Parametertype << " Parametername "
1752          << aService.ServiceinParameter[i].Parametername << " " << InPortsKind[ i ] << endl ;
1753     if ( InPortsKind[ i ] != SUPERV::DataStreamParameter ) {
1754       cdebug << "NodeInPort[" << i << "] " << *GetChangeNodeInPort( i ) << endl ;
1755     }
1756   }
1757   for ( i = 0 ; i < outnbr ; i++ ) {
1758     cdebug << "aService.ServiceoutParameter[" << i << "].Parametertype "
1759          << aService.ServiceoutParameter[i].Parametertype << " Parametername "
1760          << aService.ServiceoutParameter[i].Parametername << " " << OutPortsKind[ i ] << endl ;
1761     if ( OutPortsKind[ i ] != SUPERV::DataStreamParameter ) {
1762       cdebug << "NodeOutPort[" << i << "] " << *GetChangeNodeOutPort( i ) << endl ;
1763     }
1764   }
1765 #endif
1766
1767 //  DataService( _Orb , aService , InPortsKind , OutPortsKind , Graph_prof_debug() , Graph_fdebug() ) ;
1768   for ( i = 0 ; i < innbr ; i++ ) {
1769     if ( InPortsKind[ i ] == SUPERV::DataStreamParameter ) {
1770       GraphBase::InDataStreamPort * anInPort = AddInDataStreamPort( aService.ServiceinParameter[ i ].Parametername ,
1771                                                                     StringToDataStreamType( aService.ServiceinParameter[ i ].Parametertype ) ,
1772                                                                     InDataStreamDependency[ i ] ,
1773                                                                     SUPERV::DataStreamParameter ) ;
1774       anInPort->SetParams( InKindOfSchema[ i ] ,
1775                            InKindOfInterpolation[ i ] ,
1776                            InKindOfExtrapolation[ i ] ) ;
1777 // NOT A BUG : AddOutPort for an inport (Reversed service)
1778       anInPort = (GraphBase::InDataStreamPort * ) _DataFlowDataPorts->AddOutPort(
1779                                                            _Orb , NamePtr() ,
1780                                                            Kind() ,
1781                                                            aService.ServiceinParameter[ i ].Parametername ,
1782                                                            aService.ServiceinParameter[ i ].Parametertype ,
1783                                                            SUPERV::DataStreamParameter ,
1784                                                            - 1 ,
1785                                                            _Graph_prof_debug , _Graph_fdebug ) ;
1786       anInPort->Dependency( InDataStreamDependency[ i ] ) ;
1787 // Attention : revoir les reversed DataStreamPorts
1788 //      anInPort->SetParams( InKindOfSchema[ i ] ,
1789 //                           InKindOfInterpolation[ i ] ,
1790 //                           InKindOfExtrapolation[ i ] ) ;
1791       cdebug << "InStreamPort " << GetChangeNodeInPort( i )->PortName() << " " << GetChangeNodeInPort( i )->Kind() << endl ;
1792       cdebug << "ReversedInStreamPort " << _DataFlowDataPorts->GetChangeNodeOutPort( i )->PortName() << " " << _DataFlowDataPorts->GetChangeNodeOutPort( i )->Kind()
1793              << endl ;
1794     }
1795     else {
1796       GetChangeNodeInPort( i )->Kind( InPortsKind[ i ] ) ;
1797       _DataFlowDataPorts->GetChangeNodeOutPort( i )->Kind( InPortsKind[ i ] ) ;
1798       GetChangeNodeInPort( i )->Dependency( InDataStreamDependency[ i ] ) ;
1799       _DataFlowDataPorts->GetChangeNodeOutPort( i )->Dependency( InDataStreamDependency[ i ] ) ;
1800       cdebug << "InPort " << GetChangeNodeInPort( i )->PortName() << " " << GetChangeNodeInPort( i )->Kind() << endl ;
1801       cdebug << "ReversedInPort " << _DataFlowDataPorts->GetChangeNodeOutPort( i )->PortName() << " " << _DataFlowDataPorts->GetChangeNodeOutPort( i )->Kind()
1802              << endl ;
1803     }
1804   }
1805   for ( i = 0 ; i < outnbr ; i++ ) {
1806     if ( OutPortsKind[ i ] == SUPERV::DataStreamParameter ) {
1807       GraphBase::OutDataStreamPort * anOutPort = AddOutDataStreamPort( aService.ServiceoutParameter[ i ].Parametername ,
1808                                                                        StringToDataStreamType( aService.ServiceoutParameter[ i ].Parametertype ) ,
1809                                                                        OutDataStreamDependency[ i ] ,
1810                                                                        SUPERV::DataStreamParameter ) ;
1811       anOutPort->NumberOfValues( OutNumberOfValues[ i ] ) ;
1812 // NOT A BUG : AddInPort for an outport (Reversed service)
1813       anOutPort = (GraphBase::OutDataStreamPort * ) _DataFlowDataPorts->AddInPort(
1814                                                              _Orb , NamePtr() ,
1815                                                              Kind() ,
1816                                                              aService.ServiceoutParameter[ i ].Parametername ,
1817                                                              aService.ServiceoutParameter[ i ].Parametertype ,
1818                                                              SUPERV::DataStreamParameter ,
1819                                                              - 1 ,
1820                                                              _Graph_prof_debug , _Graph_fdebug ) ;
1821       anOutPort->Dependency( OutDataStreamDependency[ i ] ) ;
1822 // Attention : revoir les reversed DataStreamPorts
1823 //      anOutPort->NumberOfValues( OutNumberOfValues[ i ] ) ;
1824       cdebug << "OutStreamPort " << GetChangeNodeOutPort( i )->PortName() << " " << GetChangeNodeOutPort( i )->Kind() << endl ;
1825       cdebug << "ReversedOutStreamPort " << _DataFlowDataPorts->GetChangeNodeInPort( i )->PortName() << " " << _DataFlowDataPorts->GetChangeNodeInPort( i )->Kind()
1826              << endl ;
1827     }
1828     else {
1829       GetChangeNodeOutPort( i )->Kind( OutPortsKind[ i ] ) ;
1830       _DataFlowDataPorts->GetChangeNodeInPort( i )->Kind( OutPortsKind[ i ] ) ;
1831       GetChangeNodeOutPort( i )->Dependency( OutDataStreamDependency[ i ] ) ;
1832       _DataFlowDataPorts->GetChangeNodeInPort( i )->Dependency( OutDataStreamDependency[ i ] ) ;
1833       GetChangeNodeOutPort( i )->Dependency( OutDataStreamDependency[ i ] ) ;
1834       _DataFlowDataPorts->GetChangeNodeInPort( i )->Dependency( OutDataStreamDependency[ i ] ) ;
1835       cdebug << "OutPort " << GetChangeNodeOutPort( i )->PortName() << " " << GetChangeNodeOutPort( i )->Kind() << endl ;
1836       cdebug << "ReversedOutPort " << _DataFlowDataPorts->GetChangeNodeInPort( i )->PortName() << " " << _DataFlowDataPorts->GetChangeNodeInPort( i )->Kind()
1837              << endl ;
1838     }
1839   }
1840 // Restore input datas and links :
1841   DataStreamInPortsNumber( 0 ) ;
1842   DataStreamOutPortsNumber( 0 ) ;
1843   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1844     aToNode = GraphNodes( i ) ;
1845     DataStreamInPortsNumber( DataStreamInPortsNumber() + aToNode->DataStreamInPortsNumber() ) ;
1846     DataStreamOutPortsNumber( DataStreamOutPortsNumber() + aToNode->DataStreamOutPortsNumber() ) ;
1847     for ( j = 0 ; j < aToNode->GetNodeInPortsSize() ; j++ ) {
1848       GraphBase::InPort *anInPort = aToNode->GetChangeNodeInPort(j) ;
1849       if ( !anInPort->IsGate() && anInPort->IsDataConnected() ) {
1850         if ( !AddInputData( anInPort->NodeName() ,
1851                             anInPort->PortName() ,
1852                             anInPort->GetOutPort()->ValuePtr() ) ) {
1853           cdebug << "CreateService In" << j << " " << anInPort->NodeName() << "(" << anInPort->PortName() << ") "
1854                  << anInPort->PortStatus() << " --> AddInputData ERROR" << endl ;
1855           RetVal = false ;
1856         }
1857         else {
1858           cdebug << "CreateService In" << j << " " << anInPort->NodeName() << "(" << anInPort->PortName() << ") "
1859                  << anInPort->PortStatus() << " --> AddInputData" << endl ;
1860         }
1861       }
1862       else if ( !anInPort->IsGate() && anInPort->IsNotConnected() ) {
1863         if ( !AddLink( this , GetChangeInDataNodePort( anInPort->NodePortName() ) , aToNode , anInPort ) ) {
1864           cdebug << "CreateService In" << j << " " << anInPort->NodeName() << "(" << anInPort->PortName() << ") "
1865                  << anInPort->PortStatus() << " --> AddInLink ERROR" << endl ;
1866           RetVal = false ;
1867         }
1868         else {
1869           cdebug << "CreateService In" << j << " " << anInPort->NodeName() << "(" << anInPort->PortName() << ") "
1870                  << anInPort->PortStatus() << " --> AddInLink" << endl ;
1871         }
1872       }
1873     }
1874     for ( j = 0 ; j < aToNode->GetNodeOutPortsSize() ; j++ ) {
1875       GraphBase::OutPort *anOutPort = aToNode->GetChangeNodeOutPort(j) ;
1876       cdebug << "CreateService Out" << j << " " << anOutPort->NodeName() << "(" << anOutPort->PortName()
1877              << ") " << anOutPort->PortStatus() << " :" << endl ;
1878       if ( !anOutPort->IsGate() && anOutPort->IsNotConnected() && !aToNode->IsGOTONode() ) {
1879         GraphBase::InPort *anInPort = GetChangeOutDataNodePort( anOutPort->NodePortName() ) ;
1880         if ( !AddLink( aToNode , anOutPort , this , anInPort ) ) {
1881           cdebug << "       --> " << Name() << "(" << anInPort->PortName()
1882                  << ") " << anInPort->PortStatus() << " AddOutLink ERROR" << endl ;
1883           RetVal = false ;
1884         }
1885         else {
1886           cdebug << "       --> " << Name() << "(" << anInPort->PortName()
1887                  << ") " << anInPort->PortStatus() << " AddOutLink" << endl ;
1888         }
1889       }
1890     }
1891   }
1892
1893   cdebug_out << "GraphBase::Graph::CreateService " << RetVal << endl;
1894   return RetVal ;
1895 }
1896
1897 bool GraphBase::Graph::InLineServices() {
1898   cdebug_in << "GraphBase::Graph::InLineServices" << endl;
1899
1900   int i , j ;
1901
1902 #ifdef _DEBUG_
1903   ListPorts( *_Graph_fdebug , 0 ) ;
1904 #endif
1905
1906   GraphBase::InLineNode * aINode ;
1907   SALOME_ModuleCatalog::Service aService ;
1908   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1909     aINode = (GraphBase::InLineNode * ) GraphNodes( i ) ;
1910     if ( aINode->IsOneOfInLineNodes() ) {
1911 //      cdebug << "GraphBase::Graph::InLineServices " << aINode->Name() << endl;
1912       aService.ServiceName = aINode->ServiceName() ;
1913       aService.ServiceinParameter.length( 0 ) ;
1914       aService.ServiceoutParameter.length( 0 ) ;
1915       aINode->DataStreamInPortsNumber( 0 ) ;
1916       aINode->DataStreamOutPortsNumber( 0 ) ;
1917       int InService = 0 ;
1918       int InStreamService = 0 ;
1919       for ( j = 0 ; j < aINode->GetNodeInPortsSize() ; j++ ) {
1920         if ( aINode->GetChangeNodeInPort(j)->IsGate() || aINode->GetChangeNodeInPort(j)->IsLoop() ) {
1921 #if 0
1922           cdebug << "GraphBase::Graph::InLineServices In" << j << " "
1923                  << aINode->GetChangeNodeInPort(j)->Kind() << " " 
1924                  << aINode->GetChangeNodeInPort(j)->PortType() << " " 
1925                  << aINode->GetChangeNodeInPort(j)->PortName() << " ignored "
1926                  << aINode->GetChangeNodeInPort(j)->IsGate() << " "
1927                  << aINode->GetChangeNodeInPort(j)->IsLoop() << endl;
1928 #endif
1929         }
1930         else if ( aINode->GetChangeNodeInPort(j)->IsDataStream() ) {
1931           aService.ServiceinDataStreamParameter.length( InStreamService+1 ) ;
1932           aService.ServiceinDataStreamParameter[InStreamService].Parametertype = StringToDataStreamType( aINode->GetChangeNodeInPort(j)->PortType() ) ;
1933           aService.ServiceinDataStreamParameter[InStreamService].Parametername = CORBA::string_dup( aINode->GetChangeNodeInPort(j)->PortName() ) ;
1934           aService.ServiceinDataStreamParameter[InStreamService++].Parameterdependency = aINode->GetChangeNodeInPort(j)->Dependency() ;
1935           aINode->IncrDataStreamInPorts() ;
1936 #if 0
1937           cdebug << "GraphBase::Graph::InLineServices In" << j << " "
1938                  << aINode->GetChangeNodeInPort(j)->Kind() << " " 
1939                  << aINode->GetChangeNodeInPort(j)->PortType() << " " 
1940                  << aINode->GetChangeNodeInPort(j)->PortName() << " "
1941                  << aINode->GetChangeNodeInPort(j)->IsGate() << " "
1942                  << aINode->GetChangeNodeInPort(j)->IsLoop() << endl;
1943 #endif
1944         }
1945         else {
1946           aService.ServiceinParameter.length( InService+1 ) ;
1947           aService.ServiceinParameter[InService].Parametertype = CORBA::string_dup( aINode->GetChangeNodeInPort(j)->PortType() ) ;
1948           aService.ServiceinParameter[InService++].Parametername = CORBA::string_dup( aINode->GetChangeNodeInPort(j)->PortName() ) ;
1949 #if 0
1950           cdebug << "GraphBase::Graph::InLineServices In" << j << " "
1951                  << aINode->GetChangeNodeInPort(j)->Kind() << " " 
1952                  << aINode->GetChangeNodeInPort(j)->PortType() << " " 
1953                  << aINode->GetChangeNodeInPort(j)->PortName() << " "
1954                  << aINode->GetChangeNodeInPort(j)->IsGate() << " "
1955                  << aINode->GetChangeNodeInPort(j)->IsLoop() << endl;
1956 #endif
1957         }
1958       }
1959       int OutService = 0 ;
1960       int OutStreamService = 0 ;
1961       for ( j = 0 ; j < aINode->GetNodeOutPortsSize() ; j++ ) {
1962 //        if ( aINode->GetChangeNodeOutPort(j)->IsGate() || aINode->GetChangeNodeOutPort(j)->IsLoop() || aINode->GetChangeNodeOutPort(j)->IsDataStream() ) {
1963         if ( aINode->GetChangeNodeOutPort(j)->IsGate() || aINode->GetChangeNodeOutPort(j)->IsLoop() ) {
1964 #if 0
1965           cdebug << "GraphBase::Graph::InLineServices Out" << j << " "
1966                  << aINode->GetChangeNodeOutPort(j)->Kind() << " " 
1967                  << aINode->GetChangeNodeOutPort(j)->PortType() << " " 
1968                  << aINode->GetChangeNodeOutPort(j)->PortName() << " ignored "
1969                  << aINode->GetChangeNodeOutPort(j)->IsGate() << " "
1970                  << aINode->GetChangeNodeOutPort(j)->IsLoop() << endl;
1971 #endif
1972         }
1973         else if ( aINode->GetChangeNodeOutPort(j)->IsDataStream() ) {
1974           aService.ServiceoutDataStreamParameter.length( OutStreamService+1 ) ;
1975           aService.ServiceoutDataStreamParameter[OutStreamService].Parametertype = StringToDataStreamType( aINode->GetChangeNodeOutPort(j)->PortType() ) ;
1976           aService.ServiceoutDataStreamParameter[OutStreamService].Parametername = CORBA::string_dup( aINode->GetChangeNodeOutPort(j)->PortName() ) ;
1977           aService.ServiceoutDataStreamParameter[OutStreamService++].Parameterdependency = aINode->GetChangeNodeOutPort(j)->Dependency() ;
1978           aINode->IncrDataStreamOutPorts() ;
1979 #if 0
1980           cdebug << "GraphBase::Graph::InLineServices Out" << j << " "
1981                  << aINode->GetChangeNodeOutPort(j)->Kind() << " " 
1982                  << aINode->GetChangeNodeOutPort(j)->PortType() << " " 
1983                  << aINode->GetChangeNodeOutPort(j)->PortName() << " "
1984                  << aINode->GetChangeNodeOutPort(j)->IsGate() << " "
1985                  << aINode->GetChangeNodeOutPort(j)->IsLoop() << endl;
1986 #endif
1987         }
1988         else {
1989           aService.ServiceoutParameter.length( OutService+1 ) ;
1990           aService.ServiceoutParameter[OutService].Parametertype = CORBA::string_dup( aINode->GetChangeNodeOutPort(j)->PortType() ) ;
1991           aService.ServiceoutParameter[OutService++].Parametername = CORBA::string_dup( aINode->GetChangeNodeOutPort(j)->PortName() ) ;
1992 #if 0
1993           cdebug << "GraphBase::Graph::InLineServices Out" << j << " "
1994                  << aINode->GetChangeNodeOutPort(j)->Kind() << " " 
1995                  << aINode->GetChangeNodeOutPort(j)->PortType() << " " 
1996                  << aINode->GetChangeNodeOutPort(j)->PortName()  << " "
1997                  << aINode->GetChangeNodeOutPort(j)->IsGate() << " "
1998                  << aINode->GetChangeNodeOutPort(j)->IsLoop() << endl;
1999 #endif
2000         }
2001       }
2002       aINode->SetService( aService ) ;
2003       if ( SetServiceOfMap( (GraphBase::Service * ) aINode ) ) {
2004 #if 0
2005         cdebug << "InLineServices SetServiceOfMap " << aINode->ServiceName() << " in MapOfServices"
2006                << " InStreamPort(" << aINode->DataStreamInPortsNumber() 
2007                << ") OutStreamPort(" << aINode->DataStreamOutPortsNumber() << ")" << endl ; 
2008 #endif
2009       }
2010 //      cdebug << "GraphBase::Graph::InLineServices" << *aINode->GetService() << endl;
2011     }
2012   }
2013
2014   cdebug_out << "GraphBase::Graph::InLineServices" << endl;
2015   return true ;
2016 }
2017
2018 bool GraphBase::Graph::Sort( int & SubStreamGraphsNumber ) {
2019   int i ;
2020   int j ;
2021   int NotSortedNumber = GraphNodesSize() ;
2022   bool NewSorted ;
2023   cdebug_in << "GraphBase::Graph::Sort" << endl;
2024   if ( NotSortedNumber ) {
2025     _LevelsNumber = 0 ;
2026     _ParallelExecutionNodes = false ;
2027     _Sorted.resize( GraphNodesSize() ) ;
2028     _CnxInPortsNumber.resize( GraphNodesSize() ) ;
2029     _DecrInPortsNumber.resize( GraphNodesSize() ) ;
2030     if ( _NodesNumber.size() ) {
2031       _NodesNumber.resize( 0 ) ;
2032       _SortedNodes.resize( 0 ) ;
2033     }
2034           
2035 // This is a simulation of the computation of the graph :
2036 // The initial state of nodes is :
2037 // - Sorted = false : the node is not sorted
2038 // - CnxInPortsNumber = ConnectedInPortsNumber : the number of ports that wait for a value from a link
2039 // - DecrInPortsNumber = 0 : there is no value available.
2040 #if 0
2041     cdebug << "GraphBase::Graph::Sort initial values :" << endl ;
2042     for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2043       GraphBase::ComputingNode * aNode = GraphNodes( i ) ;
2044       cdebug << aNode->Name() << " --> " << aNode->LinkedNodesSize() << " LinkedNodes :" << endl ;
2045       for ( j = 0 ; j < aNode->LinkedNodesSize()  ; j++ ) {
2046         cdebug << "              " << aNode->LinkedNodes( j )->Name() << endl ;
2047       }
2048     }
2049 #endif
2050     for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2051       _Sorted[ i ] = false ;
2052       _CnxInPortsNumber[ i ] = GraphNodes( i )->ConnectedInPortsNumber() ;
2053       _DecrInPortsNumber[ i ] = 0 ;
2054 //      cdebug << "Sort Node [" << i << "] " << GraphNodes( i )->Name() << " initial count "
2055 //             << _CnxInPortsNumber[ i ] << endl ;
2056     }
2057     
2058 // Nodes are linked ONLY if Ports are NOT DataStream for topological sort of node
2059 // ==============================================================================
2060     while ( NotSortedNumber ) {
2061       NewSorted = false ;
2062       
2063       for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2064         cdebug << "Sort level " << _LevelsNumber << ". [" << i << "] "
2065                << GraphNodes( i )->Name() << " count "
2066                << _CnxInPortsNumber[ i ] << endl ;
2067         if ( !_Sorted[ i ] && _CnxInPortsNumber[ i ] == 0 ) {
2068 // All inputs of GraphNodes( i ) are available : "AllDataReady"
2069           if ( (int ) _NodesNumber.size() != _LevelsNumber+1 ) {
2070             _NodesNumber.resize( _LevelsNumber+1 ) ;
2071             _SortedNodes.resize( _LevelsNumber+1 ) ;
2072             _NodesNumber[ _LevelsNumber ] = -1 ;
2073           }
2074 // There is one more node at that level
2075           _NodesNumber[ _LevelsNumber ]++ ;
2076           (_SortedNodes[ _LevelsNumber ]).resize( _NodesNumber[ _LevelsNumber ]+1 ) ;
2077           (_SortedNodes[ _LevelsNumber ])[ _NodesNumber[ _LevelsNumber ] ] = GraphNodes( i ) ;
2078           _Sorted[ i ] = true ;
2079           NewSorted = true ;
2080           NotSortedNumber -= 1 ;
2081           cdebug << GraphNodes( i )->Name() << " belongs to level "
2082                  << _LevelsNumber << ". " << GraphNodes( i )->LinkedNodesSize() << " linkednodes" << endl ;
2083 // GraphNodes( i ) has the state "AllDataReady". We simulate the end of its execution :
2084 // So we loop over all nodes that have a link from that node
2085 // And we increment the number of input ports of GraphNodes( i )->LinkedNodes( j ) that this
2086 // execution will give a value in DecrInPortsNumber : "SomeDataReady"
2087           for ( j = 0 ; j < GraphNodes( i )->LinkedNodesSize() ; j++ ) {
2088 // OutputPorts of GraphNodes( i ) will satisfy 
2089 //   GraphNodes( i )->LinkedInPortsNumber( j ) InPorts of
2090 //      GraphNodes( i )->LinkedNodes( j )
2091             GraphBase::StreamNode * aLinkedNode = GraphNodes( i )->LinkedNodes( j ) ;
2092             int aLinkedInPortsNumber = GraphNodes( i )->LinkedInPortsNumber( j ) ;
2093             cdebug << j << ". LinkedNode " << aLinkedNode->Name() ;
2094             if ( !aLinkedNode->IsDataFlowNode() && !aLinkedNode->IsDataStreamNode() ) {
2095               cdebug << " _DecrInPortsNumber[ "
2096                      << GetGraphNodeIndex( aLinkedNode->Name() )
2097                      << " ] = "
2098                      << _DecrInPortsNumber[ GetGraphNodeIndex( aLinkedNode->Name() ) ]
2099                      << " += " << aLinkedInPortsNumber ;
2100               _DecrInPortsNumber[ GetGraphNodeIndex( aLinkedNode->Name() ) ] += aLinkedInPortsNumber ;
2101             }
2102             cdebug << endl ;
2103           }
2104         }
2105       }
2106 // If no node was found, that FlowGraph is not valid : if we try to execute it, that FlowGraph
2107 // will wait for data(s) from node(s) not executed or not executing for ever
2108       if ( !NewSorted ) {
2109         cdebug << "Loop detected level " << _LevelsNumber << endl ;
2110         return false ; // Loop in the Graph
2111       }
2112 //      cdebug << "Bilan level " << _LevelsNumber << " : " << endl ;
2113       bool ChangeCount = false ;
2114 // We update now the number of InPorts with a link that are waiting for a value
2115       for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2116         if ( _DecrInPortsNumber[ i ] ) {
2117 //          int prevcount = _CnxInPortsNumber[ i ] ;
2118           _CnxInPortsNumber[ i ] -= _DecrInPortsNumber[ i ]  ;
2119           _DecrInPortsNumber[ i ] = 0 ;
2120           ChangeCount = true ;
2121 //          cdebug << "    " << GraphNodes( i )->Name() << " count " << prevcount
2122 //                 << " --> new count " << _CnxInPortsNumber[ i ] << endl ;
2123         }
2124       }
2125 // If there is no loop and if the number of InPorts with a link that are waiting for a value
2126 // does not change, the sort is finished. But there is also NotSortedNumber ...
2127 //      if ( !ChangeCount )
2128 //        break ;
2129       if ( NotSortedNumber ) {
2130         _LevelsNumber += 1 ;
2131       }
2132     }
2133     _ThreadsMax = 0 ;
2134     int AllSortedNodes = 0 ;
2135     _HeadNodes = _SortedNodes[ 0 ] ;
2136     _HeadNodesSize = _SortedNodes[ 0 ].size() ;
2137 // QueueNodes was used in the past in order to know if the execution of a graph is finished
2138 // But because of loop nodes that was changed. So that part of code is a "clutter"
2139 // Now a graph has finished its execution when the number of executing threads is zero
2140     _QueueNodes = _SortedNodes[ _LevelsNumber ] ;
2141     _QueueNodesSize = _SortedNodes[ _LevelsNumber ].size() ;
2142     for ( i = 0 ; i < _QueueNodesSize ; i++ ) {
2143       if ( !_QueueNodes[ i ]->IsGOTONode() ) {
2144         break ;
2145       }
2146     }
2147     if ( i == _QueueNodesSize && _LevelsNumber ) {
2148       _QueueNodes = _SortedNodes[ _LevelsNumber - 1 ] ;
2149       _QueueNodesSize = _SortedNodes[ _LevelsNumber - 1 ].size() ;
2150     }
2151 // Computation of the maximum number of threads == the maximum number of nodes of all levels
2152     for ( i = 0 ; i <= _LevelsNumber ; i++ ) {
2153       AllSortedNodes += _NodesNumber[ i ]+1 ;
2154       if ( _NodesNumber[ i ] + 1 > _ThreadsMax ) {
2155         _ThreadsMax = _NodesNumber[ i ] + 1 ;
2156       }
2157       cdebug << _NodesNumber[ i ]+1 << " Nodes of level " << i << " : "
2158              << (_SortedNodes[ i ])[ 0 ]->Name() << endl ;
2159       for ( j = 1 ; j <= _NodesNumber[ i ] ; j++ ) {
2160         _ParallelExecutionNodes = true ;
2161         cdebug << "                     " << (_SortedNodes[ i ])[ j ]->Name()
2162                << endl ;
2163       }
2164     }
2165     if ( _ParallelExecutionNodes ) {
2166 //      cdebug << "Parallel Execution Nodes detected." << endl ;
2167     }
2168     else {
2169 //      cdebug << "No Parallel Execution Nodes detected." << endl ;
2170     }
2171     if ( AllSortedNodes != GraphNodesSize() ) {
2172       cdebug << "Loop detected level " << _LevelsNumber << endl ;
2173       return false ; // Loop in the Graph
2174     }
2175
2176     for ( i= 0 ; i <= _NodesNumber[ 0 ] ; i++ ) {
2177       (_SortedNodes[ 0 ])[ i ]->HeadNode( true ) ;
2178     }
2179
2180 // Give a subgraph/substreamgraph number > 0 to HeadNodes (level 0)
2181 // There is no substreamgraph for nodes without StreamPorts
2182     for ( j = 0 ; j <= _NodesNumber[ 0 ] ; j++ ) {
2183       (_SortedNodes[ 0 ])[ j ]->Level( 0 ) ;
2184       (_SortedNodes[ 0 ])[ j ]->SortedIndex( j ) ;
2185       (_SortedNodes[ 0 ])[ j ]->SubGraph( j + 1 ) ;
2186       if ( (_SortedNodes[ 0 ])[ j ]->HasDataStream() ) {
2187         (_SortedNodes[ 0 ])[ j ]->SubStreamGraph( j + 1 ) ;
2188       }
2189       else {
2190         (_SortedNodes[ 0 ])[ j ]->SubStreamGraph( -1 ) ;
2191       }
2192     }
2193
2194 // Give a subgraph/substreamgraph number = 0 to all other nodes :
2195 // the SubGraph of that nodes is unknown
2196 // There is no substreamgraph for nodes without StreamPorts
2197     for ( i = 1 ; i <= _LevelsNumber ; i++ ) {
2198       for ( j = 0 ; j <= _NodesNumber[ i ] ; j++ ) {
2199         (_SortedNodes[ i ])[ j ]->Level( i ) ;
2200         (_SortedNodes[ i ])[ j ]->SortedIndex( j ) ;
2201         (_SortedNodes[ i ])[ j ]->SubGraph( 0 ) ;
2202         if ( (_SortedNodes[ i ])[ j ]->HasDataStream() ) {
2203           (_SortedNodes[ i ])[ j ]->SubStreamGraph( 0 ) ;
2204         }
2205         else {
2206           (_SortedNodes[ i ])[ j ]->SubStreamGraph( -1 ) ;
2207         }
2208       }
2209     }
2210
2211 // Computation of independent SubGraphs which have NO link between them
2212     cdebug << endl << "Computation of SubGraphs" << endl ;
2213     bool Graphs = true ;
2214     while ( Graphs ) {
2215       for ( i = 0 ; i <= _LevelsNumber ; i++ ) {
2216         cdebug << endl << "LevelsNumber " << _LevelsNumber << " " << _NodesNumber[ i ]
2217                << " Nodes :" << endl ;
2218         for ( j = 0 ; j <= _NodesNumber[ i ] ; j++ ) {
2219           GraphBase::ComputingNode * aNode = (_SortedNodes[ i ])[ j ] ;
2220           cdebug << "    " << aNode->Name() << " SubGraph " << aNode->SubGraph() << endl ;
2221           int k ;
2222           for ( k = 0 ; k < aNode->LinkedNodesSize() ; k++ ) {
2223           if ( aNode->LinkedNodes( k )->SubGraph() ) {
2224               if ( aNode->LinkedNodes( k )->SubGraph() != aNode->SubGraph() ) {
2225 //                   && aNode->LinkedNodes( k )->Level() == aNode->Level()+1 ) {
2226 //            aNode->SubGraph( aNode->LinkedNodes( k )->SubGraph() ) ;
2227                 int OldSub = aNode->SubGraph() ;
2228                 int NewSub = aNode->LinkedNodes( k )->SubGraph() ;
2229               cdebug << "        " << aNode->Name() << " changed SubGraph "
2230                        << aNode->LinkedNodes( k )->SubGraph() << endl ;
2231                 int l ;
2232                 for ( l = 0 ; l <= _LevelsNumber ; l++ ) {
2233                   int m ;
2234                   for ( m = 0 ; m <= _NodesNumber[ l ] ; m++ ) {
2235                     if ( (_SortedNodes[ l ])[ m ]->SubGraph() == OldSub ) {
2236                       GraphBase::ComputingNode * aSubNode = (_SortedNodes[ l ])[ m ] ;
2237                       aSubNode->SubGraph( NewSub ) ;
2238                 }
2239                 }
2240               }
2241                 Graphs = false ;
2242                 break ;
2243             }
2244               else {
2245                 cdebug << "        Linked " << aNode->LinkedNodes( k )->Name()
2246                        << " same SubGraph " << aNode->LinkedNodes( k )->SubGraph() << endl ;
2247             }
2248           }
2249             else {
2250               cdebug << "        LinkedNode " << aNode->LinkedNodes( k )->Name()
2251                      << " initial SubGraph " << aNode->SubGraph() << endl ;
2252               aNode->LinkedNodes( k )->SubGraph( aNode->SubGraph() ) ;
2253           }
2254         }
2255           if ( !Graphs ) {
2256             break ;
2257           }
2258         }
2259         if ( !Graphs ) {
2260           break ;
2261         }
2262       }
2263       if ( Graphs ) {
2264         cdebug << endl << "SubGraphs result : " << endl ;
2265         break ;
2266       }
2267       cdebug << endl << "One more time" << endl ;
2268       Graphs = true ;
2269     }
2270 // Make a sequential renumbering of SubGraphs :
2271     _SubGraphsNumber = 0 ;
2272     int CurrGraphsNumber = 0;
2273     int k ;
2274     for ( k = 0 ; k <= _NodesNumber[ 0 ] ; k++ ) {
2275       if ( (_SortedNodes[ 0 ])[ k ]->SubGraph() > CurrGraphsNumber ) {
2276         CurrGraphsNumber = (_SortedNodes[ 0 ])[ k ]->SubGraph() ;
2277         _SubGraphsNumber += 1 ;
2278         for ( i = 0 ; i <= _LevelsNumber ; i++ ) {
2279           for ( j = 0 ; j <= _NodesNumber[ i ] ; j++ ) {
2280             if ( (_SortedNodes[ i ])[ j ]->SubGraph() == CurrGraphsNumber ) {
2281               (_SortedNodes[ i ])[ j ]->SubGraph( _SubGraphsNumber ) ;
2282               cdebug << "SubGraphsNumber " << _SubGraphsNumber << " " << " Level "
2283                      << i << " : " << (_SortedNodes[ i ])[ j ]->Name()
2284                      << endl ;
2285             }
2286           }
2287         }
2288       }
2289     }
2290
2291 //    cdebug << endl << "Computation of SubStreamGraphs" << endl ;
2292     for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2293       GraphBase::ComputingNode * aNode = GraphNodes( i ) ;
2294       if ( aNode->SubStreamGraph() < 0 ) {
2295 //      cdebug << "Graph " << aNode->Name() << " has NO streamport" << endl ;
2296       }
2297       else {
2298 //        cdebug << aNode->Name() << " SubGraph " << aNode->SubGraph() << " --> "
2299 //               << aNode->LinkedStreamNodesSize() << " LinkedStreamNodes :" << endl ;
2300         for ( j = 0 ; j < aNode->LinkedStreamNodesSize()  ; j++ ) {
2301 //          cdebug << "              " << aNode->LinkedStreamNodes( j )->Name() << endl ;
2302         }
2303       }
2304     }
2305
2306 // Computation of independent SubStreamGraphs which have NO StreamLink between them
2307     SubStreamGraphsNumber = 0 ;
2308     int ilevel ;
2309     for ( ilevel = 0 ; ilevel <= _LevelsNumber ; ilevel++ ) {
2310 // Loop for _NodesNumber[ ilevel ] nodes of the level ilevel
2311       int jnode ;
2312       for ( jnode = 0 ; jnode <= _NodesNumber[ ilevel ] ; jnode++ ) {
2313         GraphBase::ComputingNode * aNode = (_SortedNodes[ ilevel ])[ jnode ] ;
2314         if ( aNode->SubStreamGraph() < 0 ) {
2315 //        cdebug << "Graph " << aNode->SubStreamGraph() << " " << aNode->Name()
2316 //                 << " has NO streamport" << endl ;
2317         }
2318         else {
2319           int CurStreamGraphsNumber ;
2320           if ( aNode->SubStreamGraph() > 0 ) {
2321 //          cdebug << "SubStreamGraph " << aNode->SubStreamGraph() << " " << aNode->Name()
2322 //                   << " has streamport LinkedStreamNodesSize already in a SubStreamGraph" << endl ;
2323             CurStreamGraphsNumber = aNode->SubStreamGraph() ;
2324           }
2325           else {
2326             CurStreamGraphsNumber = SubStreamGraphsNumber+1 ;
2327           }
2328           int RetVal = 0 ;
2329           while ( RetVal != CurStreamGraphsNumber ) {
2330             RetVal = CurStreamGraphsNumber ;
2331             aNode->SetSubStreamGraph( CurStreamGraphsNumber , RetVal ) ;
2332             if ( RetVal != CurStreamGraphsNumber ) {
2333               for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2334                 GraphBase::ComputingNode * aNode = GraphNodes( i ) ;
2335                 if ( aNode->SubStreamGraph() == CurStreamGraphsNumber ) {
2336                   aNode->SubStreamGraph( RetVal ) ;
2337                 }
2338               }
2339               CurStreamGraphsNumber = RetVal ;
2340               RetVal = 0 ;
2341             }
2342             if ( CurStreamGraphsNumber > SubStreamGraphsNumber ) {
2343               SubStreamGraphsNumber = CurStreamGraphsNumber ;
2344             }
2345           }
2346         }
2347       }
2348     }
2349 // Make a sequential renumbering of SubGraphs :
2350 //    cdebug << endl << "Last SubStreamGraphsNumber : " << SubStreamGraphsNumber << endl ;
2351     int CurrStreamGraphsNumber = 0 ;
2352     int count = 0 ;
2353     for ( CurrStreamGraphsNumber = 0 ; CurrStreamGraphsNumber <= SubStreamGraphsNumber ; CurrStreamGraphsNumber++ ) {
2354       bool SearchCurrStreamGraphsNumber = true ;
2355       for ( k = 0 ; k <= _LevelsNumber && SearchCurrStreamGraphsNumber ; k++ ) {
2356         int l ;
2357         for ( l = 0 ; l <= _NodesNumber[ k ] && SearchCurrStreamGraphsNumber ; l++ ) {
2358           if ( (_SortedNodes[ k ])[ l ]->SubStreamGraph() == CurrStreamGraphsNumber ) {
2359             SearchCurrStreamGraphsNumber = false ;
2360             count = count + 1 ;
2361             if ( CurrStreamGraphsNumber != count ) {
2362 //              cdebug << "CurrStreamGraphsNumber " << CurrStreamGraphsNumber << " count " << count
2363 //                     << " Level " << k << " n " << l << endl ;
2364               for ( i = k ; i <= _LevelsNumber ; i++ ) {
2365                 for ( j = 0 ; j <= _NodesNumber[ i ] ; j++ ) {
2366                   if ( (_SortedNodes[ i ])[ j ]->SubStreamGraph() == CurrStreamGraphsNumber ) {
2367                     (_SortedNodes[ i ])[ j ]->SubStreamGraph( count ) ;
2368 //                    cdebug << "SubStreamGraphsNumber " << CurrStreamGraphsNumber << " --> " << count << " "
2369 //                           << " Level " << i << " : " << (_SortedNodes[ i ])[ j ]->Name() << endl ;
2370                   }
2371                   else if ( (_SortedNodes[ i ])[ j ]->SubStreamGraph() > 0 ) {
2372 //                    cdebug << "SubStreamGraphsNumber " << (_SortedNodes[ i ])[ j ]->SubStreamGraph()
2373 //                           << " != " << CurrStreamGraphsNumber << " Level " << i << " : "
2374 //                           << (_SortedNodes[ i ])[ j ]->Name() << endl ;
2375                   }
2376                 }
2377               }
2378             }
2379           }
2380         }
2381       }
2382     }
2383     SubStreamGraphsNumber = count ;
2384 //    cdebug << endl << "SubStreamGraphs result : " << SubStreamGraphsNumber << " SubStreamGraphs" << endl ;
2385 //    int CurrStreamGraphsNumber ;
2386 //    for ( CurrStreamGraphsNumber = 1 ; CurrStreamGraphsNumber <= SubStreamGraphsNumber  ; CurrStreamGraphsNumber++ ) {
2387 //      for ( ilevel = 0 ; ilevel <= _LevelsNumber ; ilevel++ ) {
2388 //        for ( k = 0 ; k <= _NodesNumber[ ilevel ] ; k++ ) {
2389 //          if ( (_SortedNodes[ ilevel ])[ k ]->SubStreamGraph() == CurrStreamGraphsNumber ) {
2390 //            cdebug << "SubStreamGraphsNumber " << CurrStreamGraphsNumber << " : "
2391 //                   << (_SortedNodes[ ilevel ])[ k ]->Name() << endl ;
2392 //        }
2393 //      }
2394 //      }
2395 //    }
2396   }
2397
2398 #ifdef _DEBUG_
2399   ListPorts( *_Graph_fdebug , 0 ) ;
2400 #endif
2401
2402   cdebug_out << "GraphBase::Graph::Sort" << endl;
2403   return true ;
2404 }
2405
2406 bool GraphBase::Graph::ValidLoops() const {
2407   cdebug_in << "GraphBase::Graph::ValidLoops" << endl;
2408
2409   int i ;
2410   GraphBase::ComputingNode * aNode ;
2411   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2412     aNode = GraphNodes( i ) ;
2413     if ( aNode->IsLoopNode() ) {
2414       GraphBase::LoopNode * aLoopNode = (GraphBase::LoopNode * ) aNode ;
2415       GraphBase::EndOfLoopNode * anEndLoopNode ;
2416       anEndLoopNode = (GraphBase::EndOfLoopNode * ) aLoopNode->CoupledNode() ;
2417       if ( !aLoopNode->CheckLoop( aLoopNode , anEndLoopNode ) ) {
2418         cdebug_out << "GraphBase::Graph::ValidLoops false aLoopNode " << aLoopNode->Name()
2419                    << endl;
2420         return false ;
2421       }
2422       else if ( !anEndLoopNode->CheckEndLoop( aLoopNode , anEndLoopNode ) ) {
2423         cdebug_out << "GraphBase::Graph::ValidLoops false anEndLoopNode " << anEndLoopNode->Name()
2424                    << endl;
2425         return false ;
2426       }
2427     }
2428   }
2429   cdebug_out << "GraphBase::Graph::ValidLoops true" << endl;
2430   return true ;
2431 }
2432
2433 // Controle de la coherence des noeuds de calcul
2434 // Enregistrement dans la liste des noeuds "tete" de graphe
2435
2436 bool GraphBase::Graph::ComputingNodes() const {
2437   bool RetVal = true ;
2438   cdebug << "GraphExecutor::GraphControl::ComputingNodes ()" << endl;
2439
2440 //  list<GraphEditor::Node *> aComputingNodesList = _G->ComputingNodesList() ;
2441 //  list<GraphEditor::Node *>::iterator aNode = aComputingNodesList.begin();
2442 //  GraphEditor::Port *  iP;
2443
2444 //  for (aNode = _G->ComputingNodesList().begin(); aNode !=_G->ComputingNodesList().end(); aNode++) {
2445 //  while ( aNode != aComputingNodesList.end() ) {
2446   int i ;
2447   GraphBase::ComputingNode * aNode ;
2448   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2449     aNode = GraphNodes( i ) ;
2450     // Tous les ports d'entree de tous les noeuds de calcul sont bien connectes
2451     // Enregistrement eventuel dans la liste des noeuds "tete" de graphe
2452 //    if ((*aNode)->GetNodeInPortsSize() == 0)
2453 //      _headNodes.push_front(*aNode);
2454     int j ;
2455     for ( j = 1 ; j < aNode->GetNodeInPortsSize() ; j++ ) {
2456       const GraphBase::InPort *iP = aNode->GetNodeInPort(j);
2457       if ( iP->IsNotConnected() ){
2458 //      cdebug << "Le port d'entree " << iP->PortName()
2459 //               << " du noeud de calcul " << aNode->Name() << " du graphe  "
2460 //               << Name() << " n'est pas connecte "<< endl;
2461         RetVal = false ;
2462       };
2463
2464     };
2465
2466     // Tous les noeuds de calcul ont au moins un port de sortie connecte
2467     bool oneOutPortConnected = false;
2468     for ( j = 1 ; j < aNode->GetNodeOutPortsSize() ; j++) {
2469       const GraphBase::OutPort *iP = aNode->GetNodeOutPort(j);
2470       if ( iP->IsPortConnected() || iP->IsDataConnected() ){
2471         oneOutPortConnected = true ;
2472 //      break;
2473       }
2474       else {
2475 //      cdebug << "Le port de sortie " << iP->PortName()
2476 //               << " du noeud de calcul " << aNode->Name() << " du graphe  "
2477 //               << Name() << " n'est pas connecte "<< endl;
2478         RetVal = false ;
2479       }
2480     };
2481     if (!oneOutPortConnected) {
2482 //      cdebug << "Le noeud de calcul " << aNode->Name() << " du graphe  "
2483 //               << Name() << " n'a aucun port de sortie connecte "<< endl;
2484 //      _computingError.push_front(2);
2485     }
2486   };
2487 //  return _computingError.size () ;
2488   return RetVal ;
2489 }
2490
2491 bool GraphBase::Graph::LinkLoopNodes(bool & NewLink ) {
2492   bool RetVal = true ;
2493   NewLink = false ;
2494   int i , j ;
2495   cdebug_in << "GraphBase::Graph::LinkLoopNodes()" << endl;
2496   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2497     GraphBase::ComputingNode * aNode = GraphNodes( i ) ;
2498     if ( aNode->IsLoopNode() ) {
2499       GraphBase::LoopNode * aLoopNode = (GraphBase::LoopNode * ) aNode ;
2500       for ( j = 0 ; j < aLoopNode->GetNodeInPortsSize() ; j++ ) {
2501         GraphBase::InPort *anInPort = aLoopNode->GetChangeNodeInPort(j) ;
2502         if ( !anInPort->IsGate() && anInPort->IsNotConnected() ) {
2503           if ( !AddLink( aLoopNode->CoupledNode() , aLoopNode->CoupledNode()->GetChangeNodeOutPort( j ) ,
2504                          aLoopNode , anInPort ) ) {
2505 //            cdebug << "GraphBase::Graph::CreateService AddLink ERROR " << aLoopNode->CoupledNode()->Name()
2506 //                   << "( " << aLoopNode->CoupledNode()->GetChangeNodeOutPort( j )->PortName() << " ) --> "
2507 //                   << aLoopNode->Name() << "( " << anInPort->PortName() << " )" << endl ;
2508             RetVal = false ;
2509           }
2510           else {
2511             NewLink = true ;
2512           }
2513         }
2514       }
2515       for ( j = 0 ; j < aLoopNode->CoupledNode()->GetNodeInPortsSize() ; j++ ) {
2516         GraphBase::InPort *anInPort = aLoopNode->CoupledNode()->GetChangeNodeInPort( j ) ;
2517         if ( !anInPort->IsGate() && anInPort->IsNotConnected() ) {
2518           if ( !AddLink( aLoopNode , aLoopNode->GetChangeNodeOutPort( j ) ,
2519                          aLoopNode->CoupledNode() , anInPort ) ) {
2520 //            cdebug << "GraphBase::Graph::CreateService AddLink ERROR " << aLoopNode->Name() << "( "
2521 //                   << aLoopNode->GetChangeNodeOutPort( j )->PortName() << " ) --> "
2522 //                   << aLoopNode->CoupledNode()->Name() << "( " << anInPort->PortName() << " )" << endl ;
2523             RetVal = false ;
2524           }
2525           else {
2526             NewLink = true ;
2527           }
2528         }
2529       }
2530     }
2531     else if ( aNode->IsGOTONode() ) {
2532       GraphBase::GOTONode * aGOTONode = (GraphBase::GOTONode * ) aNode ;
2533       GraphBase::OutPort *anOutGate = aGOTONode->GetChangeNodeOutGate() ;
2534       if ( anOutGate->IsNotConnected() ) {
2535         RetVal = aGOTONode->CoupledNode() != NULL;
2536         if ( RetVal ) {
2537           RetVal = AddLink( aGOTONode , anOutGate ,
2538                        aGOTONode->CoupledNode() , aGOTONode->CoupledNode()->GetChangeNodeInGate() );
2539         // cdebug << "GraphBase::Graph::CreateService AddLink ERROR " << aGOTONode->Name() << "( "
2540         //        << anOutGate->PortName() << " ) --> " << aGOTONode->CoupledNode()->Name() << "( "
2541         //        << aGOTONode->CoupledNode()->GetChangeNodeInGate()->PortName() << " )" << endl ;
2542           if ( !RetVal )
2543             NewLink = true;
2544         }
2545       }
2546     }
2547   }
2548   cdebug_out << "GraphBase::Graph::LinkLoopNodes() " << RetVal << endl;
2549   return RetVal ;
2550 }
2551
2552 // Controle de la coherence des noeuds de calcul
2553 // Enregistrement dans la liste des noeuds "tete" de graphe
2554
2555 bool GraphBase::Graph::DataServerNodes() const {
2556
2557   cdebug << "GraphBase::Graph::DataServerNodes ()" << endl;
2558
2559 //  const GraphExecutor::InNode *DataFlowDatas = GetDataFlowDatas() ;
2560   int i , j , ierr = 0 ;
2561
2562 //  if ( DataFlowDatas == NULL ) {
2563 //    MESSAGE( "No input data available in the DataFlow " << _G->Name() );
2564 //    return 0 ;
2565 //  }
2566
2567 //  const GraphExecutor::InNode *DataFlowNode = _G->GetDataFlowNode() ;
2568 //  MESSAGE( "DataServerNodes DataFlowNode : " << *DataFlowNode );
2569
2570 //  MESSAGE( "DataServerNodes DataFlowDatas : " << *DataFlowDatas );
2571
2572 // cout are inversed because DataFlowDatas is a mirror node of the DataFlow
2573
2574   ierr = CheckDataServerNodes() ;
2575
2576 //  list<GraphExecutor::InNode *> aComputingNodesList = _G->ComputingNodesList() ;
2577 //  list<GraphExecutor::InNode *>::iterator aNode = aComputingNodesList.begin();
2578   if ( GraphNodesSize() == 0 ) {
2579     ierr++ ;
2580   }
2581   else {
2582     GraphBase::ComputingNode * aNode ;
2583     for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2584       aNode = GraphNodes( i ) ;
2585 //  while ( aNode != aComputingNodesList.end() ) {
2586       if ( aNode->IsFactoryNode() ) {
2587         GraphBase::FactoryNode * FaNode = (GraphBase::FactoryNode * ) aNode ;
2588         if ( !strlen( FaNode->Computer() ) ) {
2589 //          cdebug << "ComputerName missing for node " << FaNode->Name() ;
2590           if ( !strlen( FaNode->Computer() ) ) {
2591             ierr++ ;
2592             cdebug << endl ;
2593           }
2594           else {
2595 //            cdebug << ". " << FaNode->Computer() << " will be used." << endl ;
2596           }
2597         }
2598     }
2599 // For Outputs of the DataFlow :
2600       for ( j = 0 ; j < aNode->GetNodeOutPortsSize() ; j++ ) {
2601         if ( aNode->GetNodeOutPort(j)->IsNotConnected() ) {
2602           if ( aNode->GetNodeOutPort(j)->IsDataStream() ) {
2603             aNode->AddStreamLinkedNode( (GraphBase::ComputingNode *) this ) ;
2604           }
2605           else {
2606             aNode->AddLinkedNode( (GraphBase::ComputingNode *) this ) ;
2607           }
2608         }
2609       }
2610     }
2611   }
2612
2613 // Chaque noeud dataserver ne possede qu'un seul port entree ou sortie et il est bien connecte
2614
2615 //  list<GraphExecutor::InNode *> aDataServerNodesList = _G->DataServerNodesList() ;
2616 //  list<GraphExecutor::InNode *>::iterator it = aDataServerNodesList.begin() ;
2617
2618 //  for (it = _G->DataServerNodesList().begin(); it !=_G->DataServerNodesList().end(); it++){
2619 //  while ( it != aDataServerNodesList.end() ) {
2620 //    if ( (*it)->GetNodeOutPortsSize() && (*it)->GetNodeInPortsSize() ) {
2621 //      cerr << "Erreur dans le noeud serveur de donnees " 
2622 //           << (*it)->Name() << " du graphe  " << _G->Name() << endl;
2623 //      cerr << "A la fois importation et exportation de donnees" << endl;
2624 //      _dataServerError.push_front(1);
2625 //    }
2626
2627 //    if ((*it)->GetNodeOutPortsSize()) {
2628 //      if ((*it)->GetNodeOutPortsSize()==1){
2629 //      if ( (*it)->GetNodeOutPort(0)->IsPortConnected() ){
2630 //        _headNodes.push_front(*it);
2631 //      }
2632 //      else {
2633 //        cerr << "Le port de sortie du noeud serveur de donnees "
2634 //               << (*it)->Name() << " du graphe  " << _G->Name()
2635 //               << " n'est pas connecte "<< endl;
2636 //        _dataServerError.push_front(4);
2637 //      }
2638 //      }
2639 //      else {
2640 //      cerr << "Plus d'une donnee importee du noeud serveur de donnees "
2641 //             << (*it)->Name() << " du graphe  " << _G->Name() << endl;
2642 //      _dataServerError.push_front(2);
2643 //      }
2644 //    }
2645
2646 //    if ((*it)->GetNodeInPortsSize()) {
2647 //      if ((*it)->GetNodeInPortsSize() > 1){
2648 //      cerr << "Plus d'une donnee exportee vers le noeud serveur de donnees "
2649 //             << (*it)->Name() << " du graphe  " << _G->Name() << endl;
2650 //      _dataServerError.push_front(3);
2651 //      }
2652 //      else
2653 //      if ( !(*it)->GetNodeInPort(0)->IsPortConnected() ){
2654 //      cerr << "Le port d'entree du noeud serveur de donnees "
2655 //             << (*it)->Name() << " du graphe  " << _G->Name()
2656 //             << " n'est pas connecte "<< endl;
2657 //      _dataServerError.push_front(5);
2658 //      }
2659 //    }
2660 //    it++ ;
2661 //  };
2662
2663 //  return _dataServerError.size ();
2664   return ( ierr == 0 ) ;
2665 }
2666
2667 SUPERV::GraphState GraphBase::Graph::PortState(
2668                                    const char* NodeName ,
2669                                    const char* ServiceParameterName ) {
2670   SUPERV::GraphState aRet = SUPERV::UndefinedState ;
2671 //  cdebug << "GraphBase::Graph::PortState( " << NodeName << " , "
2672 //         << ServiceParameterName << " )" << endl ;
2673
2674   char *theNode ;
2675   char *aPort ;
2676   NodePort( NodeName , ServiceParameterName , &theNode , &aPort ) ;
2677
2678   GraphBase::ComputingNode * aNode = GetChangeGraphNode( theNode ) ;
2679   if ( aNode ) {
2680     GraphBase::OutPort *anOutPort ;
2681     anOutPort = aNode->GetChangeOutPort( aPort );
2682     if ( anOutPort == NULL ) {
2683       GraphBase::InPort *anInPort = aNode->GetChangeInPort( aPort );
2684       if ( anInPort )
2685         anOutPort = anInPort->GetOutPort() ;
2686       else {
2687         cdebug << "ERROR GraphBase::Graph::PortState OutPort/InPort not found --> "
2688                << aRet << endl ;
2689       }
2690     }
2691     if ( anOutPort ) {
2692       aRet = anOutPort->State() ;
2693 //      cdebug << "GraphBase::Graph::PortState --> " << aRet << endl ;
2694     }
2695   }
2696   else {
2697     cdebug << "ERROR GraphBase::Graph::PortState Node not found --> " << aRet
2698            << endl ;
2699   }
2700   delete theNode ;
2701   delete aPort ;
2702   return aRet ;
2703 }
2704
2705 const CORBA::Any * GraphBase::Graph::PortInData( const char* ToNodeName ,
2706                                                  const char* ToServiceParameterName ) {
2707   const CORBA::Any * aRet = new CORBA::Any() ;
2708   char *theNode ;
2709   char *aPort ;
2710 //  cdebug_in << "GraphBase::Graph::PortInData " << ToNodeName << " "
2711 //            << ToServiceParameterName << endl ;
2712   NodePort( ToNodeName , ToServiceParameterName , &theNode , &aPort ) ;
2713
2714   GraphBase::ComputingNode * aNode = GetChangeGraphNode( theNode ) ;
2715
2716   if ( aNode ) {
2717     GraphBase::OutPort *anOutPort = NULL ;
2718     GraphBase::InPort *anInPort = aNode->GetChangeInPort( aPort );
2719     if ( anInPort ) {
2720       anOutPort = anInPort->GetOutPort() ;
2721       if ( anOutPort ) {
2722         aRet = anOutPort->Value() ;
2723         cdebug << "Graph::PortInData OutPort value " << anOutPort->NodeName() << "("
2724                << anOutPort->PortName() << ") --> InPort " << anInPort->NodeName()
2725                << "(" << anInPort->PortName() << ") " << anInPort->PortStatus() << endl ;
2726       }
2727       else {
2728         cdebug << "Graph::PortInData GraphBase::Graph::PortInData " << ToNodeName << " "
2729                << ToServiceParameterName << " ERROR no OutPort" << endl ;
2730       }
2731     }
2732     else {
2733       cdebug << "GraphBase::Graph::PortInData " << ToNodeName << " "
2734              << ToServiceParameterName << " ERROR no InPort" << endl ;
2735     }
2736   }
2737   else {
2738     cdebug << "GraphBase::Graph::PortInData " << ToNodeName << " "
2739            << ToServiceParameterName << " ERROR no Node" << endl ;
2740   }
2741   delete theNode ;
2742   delete aPort ;
2743 //  cdebug_out << "GraphBase::Graph::PortInData " << endl ;
2744   return aRet ;
2745 }
2746
2747 const CORBA::Any * GraphBase::Graph::PortOutData( const char* FromNodeName ,
2748                                                   const char* FromServiceParameterName ) {
2749   const CORBA::Any * aRet = new CORBA::Any() ;
2750   char *theNode ;
2751   char *aPort ;
2752 //  cdebug_in << "GraphBase::Graph::PortOutData " << FromNodeName << " "
2753 //            << FromServiceParameterName << endl ;
2754   NodePort( FromNodeName , FromServiceParameterName , &theNode , &aPort ) ;
2755
2756   GraphBase::ComputingNode * aNode = GetChangeGraphNode( theNode ) ;
2757
2758   if ( aNode ) {
2759     GraphBase::OutPort *anOutPort ;
2760     anOutPort = aNode->GetChangeOutPort( aPort );
2761     if ( anOutPort ) {
2762       aRet = anOutPort->Value() ;
2763     }
2764     else {
2765       cdebug << "GraphBase::Graph::PortOutData " << FromNodeName << " "
2766              << FromServiceParameterName << " ERROR no OutPort" << endl ;
2767     }
2768   }
2769   else {
2770     cdebug << "GraphBase::Graph::PortOutData " << FromNodeName << " "
2771            << FromServiceParameterName << " ERROR no Node" << endl ;
2772   }
2773   delete theNode ;
2774   delete aPort ;
2775 //  cdebug_out << "GraphBase::Graph::PortOutData " << endl ;
2776   return aRet ;
2777 }
2778
2779 SUPERV::ListOfStrings * GraphBase::Graph::LevelNodes(long aLevel ) {
2780   SUPERV::ListOfStrings_var RetVal = new SUPERV::ListOfStrings;
2781   if ( aLevel >= 0 && aLevel <= _LevelsNumber ) {
2782     int i ;
2783     RetVal->length( _NodesNumber[ aLevel ] + 1 );
2784     for ( i= 0 ; i <= _NodesNumber[ aLevel ] ; i++ ) {
2785       RetVal[i] = CORBA::string_dup( (_SortedNodes[ aLevel ])[ i ]->Name() ) ;
2786     }
2787   }
2788   return ( RetVal._retn() ) ;
2789 }
2790
2791 bool GraphBase::Graph::StartComponent(const int aThread ,
2792                                       const char * aComputerContainer ,
2793                                       const char * ComponentName ,
2794                                       Engines::Container_var & myContainer ,
2795                                       Engines::Component_var & objComponent ) {
2796   cdebug_in << aThread
2797             << " GraphBase::Graph::StartComponent " << aComputerContainer
2798             << " " << ComponentName << endl;
2799   bool RetVal = true ;
2800
2801   SALOME_LifeCycleCORBA LCC( NamingService() ) ;
2802   objComponent = LCC.FindOrLoad_Component( aComputerContainer ,
2803                                            ComponentName );
2804   if ( CORBA::is_nil( objComponent ) ) {
2805     cdebug_out << aThread 
2806                << " StartComponent cannot FindOrLoad " << aComputerContainer
2807                << " " << ComponentName << " ERROR" << endl;
2808     return 0 ;
2809   }
2810   /* asv : 24.01.05 : FindContainer() method does not exist any more.  FindOrLoad_Component()
2811                       starts the container for us.  If it fails to start the container, then it
2812                       returns nil component.  We don't need to check for if the container was 
2813                       successfully started..
2814   else {
2815     myContainer = LCC.FindContainer( aComputerContainer );
2816     if ( CORBA::is_nil( myContainer ) ) {
2817       cdebug_out << aThread
2818                  << " GraphBase::Graph::StartComponent myContainer = LCC.FindContainer( '"
2819                  << aComputerContainer << "' ) Container does not exist ERROR"
2820                  << endl ;
2821       return 0 ;
2822     }
2823   }
2824   */
2825   cdebug_out << aThread << " GraphBase::Graph::StartComponent " << RetVal << endl;
2826   return RetVal ;
2827 }