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