Salome HOME
0439956c359220f51302d9196d71f39d5d9ace10
[modules/superv.git] / src / GraphBase / DataFlowBase_ComputingNode.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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //  File   : DataFlowBase_ComputingNode.cxx
24 //  Author : Jean Rahuel, CEA
25 //  Module : SUPERV
26
27 using namespace std;
28 //#include <sstream>
29 //#include <iostream>
30
31 #include "DataFlowBase_StreamGraph.hxx"
32 //#include "DataFlowBase_LoopNode.hxx"
33
34 static void InitFields( //SUPERV::KindOfNode &_Kind ,
35                         SUPERV::SDate      &_FirstCreation ,
36                         SUPERV::SDate      &_LastModification ,
37                         char *             &_EditorRelease ,
38                         char *             &_Author ,
39                         char *             &_Comment ,
40                         //bool               &_HeadNode ,
41                         bool               &_GeneratedName ,
42                         //int                &_DataStreamInPortsNumber ,
43                         //int                &_DataStreamOutPortsNumber ,
44                         int                &_ConnectedInPortsNumber ,
45                         int                &_DecrConnectedInPortsNumber ) {
46                         //int                &_LinkedNodesSize ,
47                         //int                &_SubGraphNumber ) {
48   time_t T = time(NULL);
49   struct tm * Tm = localtime(&T);
50
51 //  _Kind = SUPERV::DataFlowGraph ;
52
53   _FirstCreation.Second = _LastModification.Second = Tm->tm_sec;
54   _FirstCreation.Minute = _LastModification.Minute = Tm->tm_min;
55   _FirstCreation.Hour   = _LastModification.Hour   = Tm->tm_hour;
56   _FirstCreation.Day    = _LastModification.Day    = Tm->tm_mday;
57   _FirstCreation.Month  = _LastModification.Month  = Tm->tm_mon + 1;
58   _FirstCreation.Year   = _LastModification.Year   = Tm->tm_year + 1900; 
59
60   _EditorRelease = new char[ strlen( SuperVision_Version ) + 1 ] ;
61   strcpy( _EditorRelease , SuperVision_Version ) ;
62   _Author = NULLSTRING ;
63 //  _Computer = new char[ strlen( FACTORYSERVER ) + 1 ] ;
64 //  strcpy( _Computer  , FACTORYSERVER ) ;
65   _Comment = NULLSTRING ;
66
67 //  _SubGraphNumber = 0 ;
68 //  _HeadNode = false ;
69   _GeneratedName = false ;
70
71 //  _DataStreamInPortsNumber = 0 ;
72 //  _DataStreamOutPortsNumber = 0 ;
73
74   _ConnectedInPortsNumber = 0 ;
75   _DecrConnectedInPortsNumber = 0 ;
76 //  _LinkedNodesSize = 0 ;
77 //  _SubGraphNumber = 0 ;
78 }
79
80 GraphBase::ComputingNode::ComputingNode() :
81 //  GraphBase::PortsOfNode::PortsOfNode() {
82   GraphBase::StreamNode::StreamNode() {
83
84   InitFields( //_Kind ,
85               _FirstCreation ,
86               _LastModification ,
87               _EditorRelease ,
88               _Author ,
89               _Comment ,
90               //_HeadNode ,
91               _GeneratedName ,
92               //_DataStreamInPortsNumber ,
93               //_DataStreamOutPortsNumber ,
94               _ConnectedInPortsNumber ,
95               _DecrConnectedInPortsNumber ) ;
96               //_LinkedNodesSize ,
97               //_SubGraphNumber ) ;
98   Kind( SUPERV::DataFlowGraph ) ;
99   _NamingService = NULL ;
100   _Node_var = SUPERV::CNode::_nil() ;
101   _Node_Impl = NULL ;
102   _InNode = NULL ;
103   _ThreadNo = pthread_self() ;
104   cdebug << "GraphBase::Node::Node "  << this << " "  << endl ;
105
106 }
107
108 GraphBase::ComputingNode::ComputingNode( CORBA::ORB_ptr ORB ,
109                                          SALOME_NamingService* ptrNamingService ,
110                                          const char * aDataFlowName ,
111                                          const SUPERV::KindOfNode DataFlowkind ,
112                                          int * Graph_prof_debug ,
113                                          ofstream * Graph_fdebug ) :
114 //  GraphBase::PortsOfNode::PortsOfNode( aDataFlowName ) {
115   GraphBase::StreamNode::StreamNode( aDataFlowName , DataFlowkind ,
116                                      Graph_prof_debug , Graph_fdebug ) {
117
118 //  MESSAGE( "GraphBase::ComputingNode::ComputingNode " << aDataFlowName << " Graph_prof_debug " << Graph_prof_debug ) ;
119   InitFields( //_Kind ,
120               _FirstCreation ,
121               _LastModification ,
122               _EditorRelease ,
123               _Author ,
124               _Comment ,
125               //_HeadNode ,
126               _GeneratedName ,
127               //_DataStreamInPortsNumber ,
128               //_DataStreamOutPortsNumber ,
129               _ConnectedInPortsNumber ,
130               _DecrConnectedInPortsNumber ) ;
131               //_LinkedNodesSize ,
132               //_SubGraphNumber ) ;
133
134 //  Kind( SUPERV::DataFlowGraph ) ;
135   Kind( DataFlowkind ) ;
136   _ORB = CORBA::ORB::_duplicate( ORB ) ;
137   _NamingService = ptrNamingService ;
138   _Node_var = SUPERV::CNode::_nil() ;
139   _Node_Impl = NULL ;
140   _InNode = NULL ;
141   _ThreadNo = pthread_self() ;
142
143   if ( Graph_prof_debug ) {
144 //    MESSAGE( "GraphBase::ComputingNode::ComputingNode --> SetDebug" ) ;
145 //    cout << "GraphBase::ComputingNode::ComputingNode --> SetDebug" << endl ;
146     _Graph_prof_debug = Graph_prof_debug ;
147     _Graph_fdebug = Graph_fdebug ;
148     SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
149   }
150 //  else {
151 //    cout << "GraphBase::ComputingNode::ComputingNode NO SetDebug" << endl ;
152 //  }
153   DefPortsOfNode( ORB , SALOME_ModuleCatalog::Service() , NamePtr() , Kind() , Graph_prof_debug , Graph_fdebug ) ;
154   cdebug << "GraphBase::ComputingNode::ComputingNode "  << this 
155          << " Name '" << Name() << "' "  << _FirstCreation
156          << " "  << _LastModification << endl ;
157 }
158
159 GraphBase::ComputingNode::ComputingNode( CORBA::ORB_ptr ORB ,
160                                          SALOME_NamingService* ptrNamingService ,
161                                          const SALOME_ModuleCatalog::Service& aService ,
162                                          const char *NodeName ,
163                                          const SUPERV::KindOfNode akind ,
164                                          const SUPERV::SDate NodeFirstCreation ,
165                                          const SUPERV::SDate NodeLastModification  ,
166                                          const char * NodeEditorRelease ,
167                                          const char * NodeAuthor ,
168                                          const char * NodeComment ,
169                                          const bool   GeneratedName ,
170                                          const long   X ,
171                                          const long   Y ,
172                                          int * Graph_prof_debug ,
173                                          ofstream * Graph_fdebug ) :
174 //  GraphBase::PortsOfNode::PortsOfNode() {
175   GraphBase::StreamNode::StreamNode( NodeName , akind , Graph_prof_debug , Graph_fdebug ) {
176
177   _ORB = CORBA::ORB::_duplicate( ORB ) ;
178   _NamingService = ptrNamingService ;
179   _Node_var = SUPERV::CNode::_nil() ;
180   _Node_Impl = NULL ;
181   _InNode = NULL ;
182   _ThreadNo = pthread_self() ;
183
184   Kind( akind ) ;
185 //  _Kind = akind ;
186
187   time_t T = time(NULL);
188   struct tm * Tm = localtime(&T);
189
190   _FirstCreation.Second = _LastModification.Second = Tm->tm_sec;
191   _FirstCreation.Minute = _LastModification.Minute = Tm->tm_min;
192   _FirstCreation.Hour   = _LastModification.Hour   = Tm->tm_hour;
193   _FirstCreation.Day    = _LastModification.Day    = Tm->tm_mday;
194   _FirstCreation.Month  = _LastModification.Month  = Tm->tm_mon + 1;
195   _FirstCreation.Year   = _LastModification.Year   = Tm->tm_year + 1900; 
196
197   if ( NodeEditorRelease != NULLSTRING ) {
198     _EditorRelease = new char[ strlen( NodeEditorRelease ) + 1 ] ;
199     strcpy( _EditorRelease , NodeEditorRelease ) ;
200   }
201   else {
202     _EditorRelease = new char[ strlen( SuperVision_Version ) + 1 ] ;
203     strcpy( _EditorRelease , SuperVision_Version ) ;
204   }
205
206   if ( NodeAuthor != NULLSTRING ) {
207     _Author = new char[ strlen( NodeAuthor ) + 1 ] ;
208     strcpy( _Author  , NodeAuthor ) ;
209   }
210   else {
211     _Author = NULLSTRING ;
212   }
213
214   if ( NodeComment != NULLSTRING ) {
215     _Comment = new char[ strlen( NodeComment ) + 1 ] ;
216     strcpy( _Comment  , NodeComment ) ;
217   }
218   else {
219     _Comment = NULLSTRING ;
220   }
221
222 //  _SubGraphNumber = 0 ;
223 //  _HeadNode = false ;
224   _GeneratedName = GeneratedName ;
225
226 //  const char *aNodeName = NodeName ;
227 //  _Name = new char[strlen(aNodeName)+1];
228 //  strcpy(_Name , aNodeName);
229
230 //  _DataStreamInPortsNumber = 0 ;
231 //  _DataStreamOutPortsNumber = 0 ;
232
233   _ConnectedInPortsNumber = 0 ;
234   _DecrConnectedInPortsNumber = 0 ;
235 //  _LinkedNodesSize = 0 ;
236
237   _X = X ;
238   _Y = Y ;
239
240   _Graph_prof_debug = Graph_prof_debug ;
241   _Graph_fdebug = Graph_fdebug ;
242 //  MESSAGE( "GraphBase::ComputingNode::ComputingNode " << NodeName
243 //           << " _Graph_prof_debug " << _Graph_prof_debug ) ;
244   SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
245   cdebug_in << "GraphBase::ComputingNode::ComputingNode(" << aService.ServiceName << "," << NodeName << ","
246             << akind << ")" << endl;
247   
248
249   DefPortsOfNode( ORB , aService , NamePtr() , Kind() , Graph_prof_debug , Graph_fdebug ) ;
250   cdebug << "GraphBase::ComputingNode::ComputingNode "  << this 
251          << " Name '" << Name()
252          << "' KindOfNode " << Kind()
253          << " ServiceName '" << ServiceName() << "' In(" << ServiceInParameter().length()
254          << ") Out(" << ServiceOutParameter().length() << ")" << endl ;
255
256   cdebug_out << "GraphBase::ComputingNode::ComputingNode" << endl;
257 }
258
259 GraphBase::ComputingNode::~ComputingNode() {
260   cdebug << "GraphBase::ComputingNode::~ComputingNode "  << this 
261          << " Name() "<< Name() << " _Comment "
262          << (void *) _Comment << " "  << _Comment << " "  << endl ;
263 }
264
265 //->StreamNode bool GraphBase::ComputingNode::Name( const char * aName) {
266 //->StreamNode   cdebug_in << "GraphBase::ComputingNode::Name " << _Name << endl;
267 //->StreamNode   if ( _Name ) {
268 //->StreamNode     cdebug << "GraphBase::ComputingNode::ReName "  << _Name << " --> " << aName << endl ;
269 //->StreamNode     delete [] _Name ;
270 //->StreamNode   }
271 //->StreamNode   _Name = new char[strlen(aName)+1] ;
272 //->StreamNode   strcpy( _Name , aName ) ;
273 //->StreamNode   cdebug_out << "GraphBase::ComputingNode::Name " << _Name << endl;
274 //->StreamNode   return true ;
275 //->StreamNode }
276
277 SUPERV::SDate GraphBase::ComputingNode::FirstCreation () const {
278 //  cdebug << "GraphBase::ComputingNode::FirstCreation "
279 //         << " Name '" << Name() << "' "  << _FirstCreation << " "  
280 //         << _LastModification << endl ;
281   return _FirstCreation;
282 }
283
284 SUPERV::SDate GraphBase::ComputingNode::LastModification () const {
285   return _LastModification ;
286 }
287
288 void GraphBase::ComputingNode::FirstCreation(const SUPERV::SDate aDate ) {
289   _FirstCreation = aDate ;
290 }
291
292 void GraphBase::ComputingNode::LastModification(const SUPERV::SDate aDate ) {
293   _LastModification = aDate ;
294 }
295
296 bool GraphBase::ComputingNode::EditorRelease(const char * c){
297   if ( _EditorRelease && _EditorRelease != NULLSTRING )
298     delete _EditorRelease;
299   _EditorRelease = my_strdup(c);
300   return true ;
301 }
302
303 bool GraphBase::ComputingNode::Author(const char * a) {
304   cdebug_in << "GraphBase::ComputingNode::Author " << _Author << endl;
305   if ( _Author && _Author != NULLSTRING )
306     delete _Author;
307   _Author = my_strdup(a);
308   cdebug_out << "GraphBase::ComputingNode::Author " << _Author << endl;
309   return true ;
310 }
311
312 bool GraphBase::ComputingNode::Comment(const char *c) {
313   cdebug_in << "GraphBase::ComputingNode::Comment " << _Comment << endl;
314   if ( _Comment != NULLSTRING )
315     delete [] _Comment;
316   _Comment = my_strdup(c);
317   cdebug_out << "GraphBase::ComputingNode::Comment " << _Comment << endl;
318   return true ;
319 }
320
321 void GraphBase::ComputingNode::NodePort( const char * NodeName ,
322                                 const char * ServiceParameterName ,
323                                 char ** aNode , char ** aPort ) {
324   if ( strcmp( NodeName , Name() ) ) {
325     *aNode = my_strdup( NodeName ) ;
326     *aPort = my_strdup( ServiceParameterName ) ;
327   }
328   else {
329 //    char * BPort = strchr( ServiceParameterName , '\\' ) ;
330     char * BPort = (char * ) ServiceParameterName ;
331     while ( ( BPort = strchr( BPort , '_' ) ) ) {
332       if ( BPort[1] == '_' ) {
333         int len = BPort - ServiceParameterName ;
334         *aNode = new char [ len + 1 ] ;
335         strncpy( *aNode , ServiceParameterName , len ) ;
336         (*aNode)[ len ] = '\0' ;
337         *aPort = my_strdup( &BPort[ 2 ] ) ;
338         break ;
339       }
340       else {
341         BPort = &BPort[2] ;
342       }
343     }
344     if ( BPort == NULL ) {
345       *aNode = my_strdup( NULLSTRING ) ;
346       *aPort = my_strdup( NULLSTRING ) ;
347     }
348   }
349 }
350
351 bool GraphBase::ComputingNode::IsLinked(const char * ToServiceParameterName, bool isInput ) {
352   bool RetVal = false ;
353   if ( isInput ) { // mkr : PAL8060
354     // we have to know the type of the port, because of input and output ports 
355     // belong to one node may have the same names
356     const GraphBase::InPort * thePort = GetInPort( ToServiceParameterName ) ;
357     if ( thePort ) {
358       RetVal = thePort->IsPortConnected() ;
359     }
360   }
361   else {
362     const GraphBase::OutPort * thePort = GetOutPort( ToServiceParameterName ) ;
363     if ( thePort ) {
364       RetVal = thePort->IsPortConnected() ;
365     }
366   }
367   return RetVal ;
368 }
369
370 bool GraphBase::ComputingNode::HasInput(const char * ToServiceParameterName ) {
371   bool RetVal = false ;
372   const GraphBase::InPort * theInPort = GetInPort( ToServiceParameterName ) ;
373   if ( theInPort ) {
374     RetVal = theInPort->IsDataConnected() ;
375   }
376   else {
377     const GraphBase::OutPort * theOutPort = GetOutPort( ToServiceParameterName ) ;
378     if ( theOutPort ) {
379       RetVal = theOutPort->IsDataConnected() ;
380     }
381   }
382   return RetVal ;
383 }
384
385 GraphBase::SNode * GraphBase::ComputingNode::GetInfo() {
386   cdebug_in << "GraphBase::ComputingNode::GetInfo" << endl;
387   GraphBase::SNode * Info = new GraphBase::SNode ;
388 //  Info->theComponentName = ComponentName() ;
389 //  Info->theInterfaceName = InterfaceName() ;
390   Info->theName = Name() ;
391   Info->theKind = Kind() ;
392   if ( IsDataStreamNode() ) {
393     CORBA::Long Timeout ;
394     SUPERV::KindOfDataStreamTrace DataStreamTrace ;
395     CORBA::Double DeltaTime ;
396     ((GraphBase::StreamGraph * ) this)->StreamParams( Timeout , DataStreamTrace , DeltaTime ) ;
397     Info->theTimeout = Timeout ;
398     Info->theDataStreamTrace = DataStreamTrace ;
399     Info->theDeltaTime = DeltaTime ;
400   }
401   Info->theService = *GetService() ;
402 //  Info->theListOfParameters = *GetListOfParameters() ;
403   Info->theFirstCreation = FirstCreation() ;
404   Info->theLastModification = LastModification() ;
405   Info->theEditorRelease = EditorRelease() ;
406   Info->theAuthor = Author() ;
407 //  Info->theContainer = Computer() ;
408   Info->theComment = Comment() ;
409   Info->theCoords.theX = GraphBase::ComputingNode::XCoordinate() ;
410   Info->theCoords.theY = GraphBase::ComputingNode::YCoordinate() ;
411   cdebug_out << "GraphBase::ComputingNode::GetInfo" << endl;
412   return Info ;
413 }
414
415 void GraphBase::ComputingNode::SetMacroPorts( GraphBase::Graph * aGraph ) {
416   cdebug_in << "GraphBase::ComputingNode::SetMacroPorts fill ports of MacroNode" << endl;
417   int i ;
418   for ( i = 0 ; i < aGraph->GetNodeInPortsSize() ; i++ ) {
419     const GraphBase::InPort * anInPort = aGraph->GetNodeInPort( i ) ;
420     cdebug << "SetMacroPorts In" << i << " " << anInPort->PortName() << " " << anInPort->PortType()
421            << " " << anInPort->Kind() << endl ;
422     GraphBase::InPort * aNewInPort ;
423     if ( anInPort->IsDataStream() ) {
424       aNewInPort = AddInDataStreamPort( anInPort->PortName() , StringToDataStreamType( anInPort->PortType() ) ,
425                                         anInPort->Dependency() , anInPort->Kind() ) ;
426     }
427     else if ( anInPort->IsParam() || anInPort->IsInLine() ) {
428       aNewInPort = AddInPort( anInPort->PortName() , anInPort->PortType() , anInPort->Kind() ) ;
429     }
430   }
431   for ( i = 0 ; i < aGraph->GetNodeOutPortsSize() ; i++ ) {
432     const GraphBase::OutPort * anOutPort = aGraph->GetNodeOutPort( i ) ;
433     cdebug << "SetMacroPorts Out" << i << " " << anOutPort->PortName() << " " << anOutPort->PortType()
434            << " " << anOutPort->Kind() << endl ;
435     if ( anOutPort->IsDataStream() ) {
436       AddOutDataStreamPort( anOutPort->PortName() , StringToDataStreamType( anOutPort->PortType() ) ,
437                             anOutPort->Dependency() , anOutPort->Kind() ) ;
438     }
439     else if ( anOutPort->IsParam() || anOutPort->IsInLine() ) {
440       AddOutPort( anOutPort->PortName() , anOutPort->PortType() , anOutPort->Kind() ) ;
441     }
442   }
443   cdebug_out << "GraphBase::ComputingNode::SetMacroPorts" << endl;
444 }
445
446 void GraphBase::ComputingNode::UpdateMacroPorts( GraphBase::Graph * aGraph ) {
447   cdebug_in << "GraphBase::ComputingNode::UpdateMacroPorts fill ports of MacroNode from "
448             << aGraph->Name() << " InPorts(" << aGraph->GetNodeInPortsSize() << ") OutPorts("
449             << aGraph->GetNodeInPortsSize() << ") to MacroNode " << Name() << " InPorts(" << GetNodeInPortsSize()
450             << ") OutPorts(" << GetNodeInPortsSize() << ")" << endl;
451   cdebug << Name() << " : " << *GetService() << endl ;
452   cdebug << aGraph->Name() << " : " << *aGraph->GetService() << endl ;
453   int i ;
454 // Loop over InPorts of MacroNode ; if it does not exist in the MacroGraph ===> DelInPort in the MacroNode
455   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
456     GraphBase::InPort * anInPort = aGraph->GetChangeInPort( GetNodeInPort( i )->PortName() ) ;
457     if ( anInPort && !anInPort->IsGate() && !GetNodeInPort( i )->IsGate() ) {
458       if ( strcmp( GetNodeInPort( i )->PortType() , anInPort->PortType() ) ) {
459         cdebug << Name() << " " << GetNodeInPort( i )->PortName() << " " << GetNodeInPort( i )->PortType()
460                << " " << GetNodeInPort( i )->Kind() << " " << GetNodeInPort( i )->Dependency() << endl ;
461         cdebug << "  <--> " << aGraph->Name() << " " << anInPort->PortName() << " " << anInPort->PortType()
462                << " " << anInPort->Kind() << " " << anInPort->Dependency() << endl ;
463         GetChangeNodeInPort( i )->PortType( (char * ) anInPort->PortType() ) ;
464       }
465       if ( GetNodeInPort( i )->Kind() != anInPort->Kind() ) {
466         cdebug << Name() << " " << GetNodeInPort( i )->PortName() << " " << GetNodeInPort( i )->PortType()
467                << " " << GetNodeInPort( i )->Kind() << " " << GetNodeInPort( i )->Dependency() << endl ;
468         cdebug << "  <--> " << aGraph->Name() << " " << anInPort->PortName() << " " << anInPort->PortType()
469                << " " << anInPort->Kind() << " " << anInPort->Dependency() << endl ;
470         GetChangeNodeInPort( i )->Kind( anInPort->Kind() ) ;
471       }
472       if ( GetNodeInPort( i )->Dependency() != anInPort->Dependency() ) {
473         cdebug << Name() << " " << GetNodeInPort( i )->PortName() << " " << GetNodeInPort( i )->PortType()
474                << " " << GetNodeInPort( i )->Kind() << " " << GetNodeInPort( i )->Dependency() << endl ;
475         cdebug << "  <--> " << aGraph->Name() << " " << anInPort->PortName() << " " << anInPort->PortType()
476                << " " << anInPort->Kind() << " " << anInPort->Dependency() << endl ;
477         GetChangeNodeInPort( i )->Dependency( anInPort->Dependency() ) ;
478       }
479     }
480     else if ( !GetNodeInPort( i )->IsGate() ) {
481       cdebug << "UpdateMacroPorts DelInPort In" << i << " " << GetNodeInPort( i )->PortName() << " "
482              << GetNodeInPort( i )->PortType() << " " << GetNodeInPort( i )->Kind() << endl ;
483       DelInPort( GetNodeInPort( i )->PortName() ) ;
484       i--; // mkr : fix for bug PAL8004
485     }
486   }
487   int index ;
488 // Loop over InPorts of the MacroGraph : if it does not exist in the MacroNode ==> AddInPort in the MacroNode
489   for ( index = 0 ; index < aGraph->GetNodeInPortsSize() ; index++ ) {
490     GraphBase::InPort * anInPort = aGraph->GetChangeNodeInPort( index ) ;
491     GraphBase::InPort * aMacroInPort = GetChangeInPort( anInPort->PortName() ) ;
492     if ( !anInPort->IsGate() &&
493          strcmp( GetChangeNodeInPort( index )->PortName() , anInPort->PortName() ) ) {
494       cdebug << "UpdateMacroPorts Add/MoveInPort In" << index << " " << anInPort->PortName() << " "
495              << anInPort->PortType() << " " << anInPort->Kind() << endl ;
496       if ( aMacroInPort ) {
497         MoveInPort( anInPort->PortName() , index ) ;
498       }
499       else {
500         AddInPort( anInPort->PortName() , anInPort->PortType() , anInPort->Kind() , index ) ;
501       }
502     }
503   }
504 // Loop over OutPorts of MacroNode ; if it does not exist in the MacroGraph ===> DelOutPort in the MacroNode
505   for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
506     GraphBase::OutPort * anOutPort = aGraph->GetChangeOutPort( GetNodeOutPort( i )->PortName() ) ;
507     if ( anOutPort && !anOutPort->IsGate() && !GetNodeOutPort( i )->IsGate() ) {
508       if ( strcmp( GetNodeOutPort( i )->PortType() , anOutPort->PortType() ) ) {
509         cdebug << Name() << " " << GetNodeOutPort( i )->PortName() << " " << GetNodeOutPort( i )->PortType()
510                << " " << GetNodeOutPort( i )->Kind() << " " << GetNodeOutPort( i )->Dependency() << endl ;
511         cdebug << "  <--> " << aGraph->Name() << " " << anOutPort->PortName() << " " << anOutPort->PortType()
512                << " " << anOutPort->Kind() << " " << anOutPort->Dependency() << endl ;
513         GetChangeNodeOutPort( i )->PortType( (char * ) anOutPort->PortType() ) ;
514       }
515       if ( GetNodeOutPort( i )->Kind() != anOutPort->Kind() ) {
516         cdebug << Name() << " " << GetNodeOutPort( i )->PortName() << " " << GetNodeOutPort( i )->PortType()
517                << " " << GetNodeOutPort( i )->Kind() << " " << GetNodeOutPort( i )->Dependency() << endl ;
518         cdebug << "  <--> " << aGraph->Name() << " " << anOutPort->PortName() << " " << anOutPort->PortType()
519                << " " << anOutPort->Kind() << " " << anOutPort->Dependency() << endl ;
520         GetChangeNodeOutPort( i )->Kind( anOutPort->Kind() ) ;
521       }
522       if ( GetNodeOutPort( i )->Dependency() != anOutPort->Dependency() ) {
523         cdebug << Name() << " " << GetNodeOutPort( i )->PortName() << " " << GetNodeOutPort( i )->PortType()
524                << " " << GetNodeOutPort( i )->Kind() << " " << GetNodeOutPort( i )->Dependency() << endl ;
525         cdebug << "  <--> " << aGraph->Name() << " " << anOutPort->PortName() << " " << anOutPort->PortType()
526                << " " << anOutPort->Kind() << " " << anOutPort->Dependency() << endl ;
527         GetChangeNodeOutPort( i )->Dependency( anOutPort->Dependency() ) ;
528       }
529     }
530     else if ( !GetNodeOutPort( i )->IsGate() ) {
531       cdebug << "UpdateMacroPorts DelOutPort Out" << i << " " << GetNodeOutPort( i )->PortName() << " "
532              << GetNodeOutPort( i )->PortType() << " " << GetNodeOutPort( i )->Kind() << endl ;
533       DelOutPort( GetNodeOutPort( i )->PortName() ) ;
534     }
535   }
536 // Loop over OutPorts of the MacroGraph : if it does not exist in the MacroNode ==> AddOutPort in the MacroNode
537   for ( index = 0 ; index < aGraph->GetNodeOutPortsSize() ; index++ ) {
538     GraphBase::OutPort * anOutPort = aGraph->GetChangeNodeOutPort( index ) ;
539     GraphBase::OutPort * aMacroOutPort = GetChangeOutPort( anOutPort->PortName() ) ;
540     if ( !anOutPort->IsGate() && strcmp( GetNodeOutPort( index )->PortName() , anOutPort->PortName() ) ) {
541       cdebug << "UpdateMacroPorts Add/MoveOutPort Out" << index << " " << anOutPort->PortName() << " "
542              << anOutPort->PortType() << " " << anOutPort->Kind() << endl ;
543       if ( aMacroOutPort ) {
544         MoveOutPort( anOutPort->PortName() , index ) ;
545       }
546       else {
547         AddOutPort( anOutPort->PortName() , anOutPort->PortType() , anOutPort->Kind() , index ) ;
548       }
549     }
550   }
551   bool ErrPort = false ;
552   if ( aGraph->GetNodeInPortsSize() != GetNodeInPortsSize() ||
553        aGraph->GetNodeOutPortsSize() != GetNodeOutPortsSize() ) {
554     ErrPort = true ;
555   }
556   for ( i = 0 ; i < aGraph->GetNodeInPortsSize() && i < GetNodeInPortsSize() ; i++ ) {
557     if ( !strcmp( aGraph->GetNodeInPort( i )->PortName() , GetNodeInPort( i )->PortName() ) ) {
558       ErrPort = true ;
559     }
560   }
561   for ( i = 0 ; i < aGraph->GetNodeOutPortsSize() && i < GetNodeOutPortsSize() ; i++ ) {
562     if ( !strcmp( aGraph->GetNodeOutPort( i )->PortName() , GetNodeOutPort( i )->PortName() ) ) {
563       ErrPort = true ;
564     }
565   }
566   if ( ErrPort ) {
567     for ( i = 0 ; i < aGraph->GetNodeInPortsSize() || i < GetNodeInPortsSize() ; i++ ) {
568       if ( i < aGraph->GetNodeInPortsSize() && i < GetNodeInPortsSize() ) {
569         cdebug << "ComputingNode::UpdateMacroPorts In" << i << " " << aGraph->GetNodeInPort( i )->PortName()
570                << "  " << GetNodeInPort( i )->PortName() << endl ;
571       }
572       else if ( i >= GetNodeInPortsSize() ) {
573         cdebug << "ComputingNode::UpdateMacroPorts In" << i << " " << aGraph->GetNodeInPort( i )->PortName()
574                << endl ;
575       }
576       else {
577         cdebug << "ComputingNode::UpdateMacroPorts In" << i << " " << GetNodeInPort( i )->PortName()
578                << endl ;
579       }
580     }
581     for ( i = 0 ; i < aGraph->GetNodeOutPortsSize() || i < GetNodeOutPortsSize() ; i++ ) {
582       if ( i < aGraph->GetNodeOutPortsSize() && i < GetNodeOutPortsSize() ) {
583         cdebug << "ComputingNode::UpdateMacroPorts Out" << i << " " << aGraph->GetNodeOutPort( i )->PortName()
584                << " != " << GetNodeOutPort( i )->PortName() << endl ;
585       }
586       else if ( i >= GetNodeOutPortsSize() ) {
587         cdebug << "ComputingNode::UpdateMacroPorts Out" << i << " " << aGraph->GetNodeOutPort( i )->PortName()
588                << endl ;
589       }
590       else {
591         cdebug << "ComputingNode::UpdateMacroPorts Out" << i << " " << GetNodeOutPort( i )->PortName()
592                << endl ;
593       }
594     }
595   }
596   cdebug_out << "GraphBase::ComputingNode::UpdateMacroPorts"
597              << aGraph->Name() << " InPorts(" << aGraph->GetNodeInPortsSize() << ") OutPorts("
598              << aGraph->GetNodeOutPortsSize() << ") to MacroNode " << Name() << " InPorts("
599              << GetNodeInPortsSize() << ") OutPorts(" << GetNodeOutPortsSize() << ")" << endl;
600 }
601
602 void GraphBase::ComputingNode::SetMacroDatas( GraphBase::Graph * aGraph ,
603                                               GraphBase::Graph * aGraphOfMacroGraph ) {
604   cdebug_in << "GraphBase::ComputingNode::SetMacroDatas fill inputs of MacroNode" << endl;
605   int i ;
606   for ( i = 0 ; i < aGraph->GetNodeInPortsSize() ; i++ ) {
607     const GraphBase::InPort * anInPort = aGraph->GetNodeInPort( i ) ;
608     GraphBase::OutPort * anOutPort = aGraph->GetChangeNodeInDataNodePort(i) ;
609     cdebug << "                 " << Name() << " " << anOutPort->PortName() << " " << anOutPort->PortType()
610            << " " << anOutPort->Kind() << " " << anOutPort->PortStatus() << endl ;
611     if ( anOutPort->IsDataConnected() ) {
612 //JR 30.03.2005      aGraphOfMacroGraph->AddInputData( Name() , anInPort->PortName() , *(anOutPort->Value()) ) ;
613       aGraphOfMacroGraph->AddInputData( Name() , anInPort->PortName() , anOutPort->Value() ) ;
614       anOutPort->PortStatus( ExternConnected ) ;
615     }
616   }
617   cdebug_out << "GraphBase::ComputingNode::SetMacroDatas" << endl;
618 }
619
620 void GraphBase::ComputingNode::DelInPort( const char * InputParameterName ) {
621 //PAL9122
622 //JR 07.06.2005 Debug : LinkedNodes and LinkedFromNode must be updated
623 //                      LinkedInPortsNumber and LinkedFromInPortsNumber must be updated
624   cdebug_in << "ComputingNode::DelInPort " << Name() << "( " << InputParameterName << " )"
625              << endl;
626   bool RetVal = true ;
627   if ( !IsEndSwitchNode() ) {
628     GraphBase::InPort * anInPort = GetChangeInPort( InputParameterName ) ;
629     cdebug << "ComputingNode::DelInPort InPort " << Name() << "( "
630            << anInPort->PortName() << " ) " << anInPort->PortStatus() << " <-- " ;
631     GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
632     if ( anOutPort && !( IsEndLoopNode() && anInPort->IsLoop() ) ) {
633       cdebug << anOutPort->NodeName() << "( " << anOutPort->PortName() << ") "
634              << anOutPort->PortStatus() ;
635     }
636     cdebug << endl ;
637     if ( !anInPort->IsNotConnected() ) {
638       GraphBase::ComputingNode * FromNode = NULL ;
639       RetVal = true ;
640       if ( anOutPort->IsDataConnected() || anOutPort->IsExternConnected() ) {
641         cdebug << "     Data/Extern ignored" << endl ;
642       }
643       else {
644         FromNode = GraphOfNode()->GetChangeGraphNode( anOutPort->NodeName() ) ;
645       }
646       if ( FromNode ) {
647         cdebug << "FromNode " << FromNode->Name() << " LinkedNodesSize "
648                << FromNode->LinkedNodesSize() << " and " << Name()
649                << " LinkedFromNodesSize " << LinkedFromNodesSize() << endl ;
650         if ( !FromNode->IsGOTONode() &&
651              !( FromNode->IsEndLoopNode() && anInPort->IsLoop() ) ) {
652           if ( anInPort->IsDataStream() ) {
653             RetVal = FromNode->RemoveStreamLinkedNode( this ) ;
654           }
655           else {
656             RetVal = FromNode->RemoveLinkedNode( this ) ;
657           }
658           if ( !RetVal ) {
659             cdebug << "ComputingNode::DelInPort anOutPort->RemoveLinkedNode Error RetVal "
660                    << RetVal << endl ;
661           }
662         }
663       }
664     }
665   }
666 //We have an EndSwitchNode :
667   else {
668     int i ;
669     for ( i = LinkedFromNodesSize() - 1 ; i >= 0  ; i-- ) {
670       GraphBase::ComputingNode * aLinkedFromNode = (GraphBase::ComputingNode * ) LinkedFromNodes( i ) ;
671       cdebug << aLinkedFromNode->Name() << " linked to " << Name() << endl ;
672       int j ;
673       for ( j = aLinkedFromNode->GetNodeOutPortsSize() - 1 ; j >= 0 ; j-- ) {
674         GraphBase::OutPort * anOutPort = aLinkedFromNode->GetChangeNodeOutPort( j ) ;
675         cdebug << "ComputingNode::DelInPort OutPort" << j << ". Remove " << anOutPort->InPortsSize()
676                << " InPortsof OutPort : " << anOutPort->NodeName() << "( "
677                << anOutPort->PortName() << ") "
678                << anOutPort->PortStatus() << " :" << endl ;
679         int k ;
680 //Process concerned OutPorts of LinkedFromNodes of that EndSwitchNode
681         for ( k = anOutPort->InPortsSize() - 1 ; k >= 0  ; k-- ) {
682           GraphBase::InPort * anInPort = anOutPort->ChangeInPorts( k ) ;
683           if ( !strcmp( anInPort->NodeName() , Name() ) &&
684                !strcmp( anInPort->PortName() , InputParameterName ) ) {
685 // InPort of the EndSwitchNode
686             cdebug << "       to InPort" << j << ". " << anInPort->NodeName() << "( "
687                    << anInPort->PortName() << ") "
688                    << anInPort->PortStatus() << endl ;
689             anInPort->RemoveOutPort() ;
690             if ( anOutPort->IsDataStream() ) {
691               aLinkedFromNode->RemoveStreamLinkedNode( this ) ;
692             }
693             else {
694 // false ==> No error for aNode->LinkedFromNode()
695               RetVal = aLinkedFromNode->RemoveLinkedNode( this , false ) ;
696               if ( !RetVal ) {
697                 cdebug << "ComputingNode::DelInPort aLinkedFromNode->RemoveLinkedNode Error RetVal "
698                        << RetVal << endl ;
699                 break ;
700               }
701             }
702 // Remove the InPort of the EndSwitchNode from that OutPort
703             RetVal = anOutPort->RemoveInPort( anInPort ) ;
704             if ( !RetVal ) {
705               cdebug << "ComputingNode::DelInPort anOutPort->RemoveInPort( anInPort ) Error RetVal "
706                      << RetVal << endl ;
707               break ;
708             }
709           }
710         }
711       }
712     }
713   }
714
715   GraphBase::PortsOfNode::DelInPort( InputParameterName ) ;
716   cdebug_out << "ComputingNode::DelInPort " << Name() << "( " << InputParameterName << " )"
717              << endl;
718 }
719 void GraphBase::ComputingNode::DelOutPort( const char * OutputParameterName ) {
720 //PAL9122
721 //JR 07.06.2005 Debug : LinkedNodes and LinkedFromNode must be updated
722 //                      LinkedInPortsNumber and LinkedFromInPortsNumber must be updated
723   cdebug_in << "ComputingNode::DelOutPort " << Name() << "( " << OutputParameterName << " )"
724             << endl;
725   bool RetVal = true ;
726   GraphBase::OutPort * anOutPort = GetChangeOutPort( OutputParameterName ) ;
727   cdebug << "ComputingNode::DelOutPort OutPort " << " InPortof OutPort : "
728          << anOutPort->NodeName() << "( " << anOutPort->PortName() << ") "
729          << anOutPort->PortStatus() << " :" << endl ;
730   int j ;
731   for ( j = anOutPort->InPortsSize() - 1 ; j >= 0  ; j-- ) {
732     GraphBase::InPort * anInPort = anOutPort->ChangeInPorts( j ) ;
733     GraphBase::ComputingNode * ToNode = NULL ;
734     cdebug << "       to InPort" << j << ". " << anInPort->NodeName() << "( "
735            << anInPort->PortName() << ") " << anInPort->PortStatus() ;
736     if ( anInPort->IsExternConnected() ) {
737       cdebug << " ExternConnected ignored" << endl ;
738     }
739     else {
740       cdebug << endl ;
741       ToNode = GraphOfNode()->GetChangeGraphNode( anInPort->NodeName() ) ;
742     }
743     if ( ToNode ) {
744       RetVal = anInPort->RemoveOutPort() ;
745 // JR 04.02.2005 : Bug if it is a link to an EndSwitchNode. The InPort may be multiple linked !!!
746 // PAL7990
747       if ( !RetVal ) {
748         cdebug << "ComputingNode::DelOutPort anOutPort->RemoveOutPort Error RetVal " << RetVal
749                << endl ;
750         break ;
751       }
752       if ( ( IsGOTONode() && ToNode->IsOneOfInLineNodes() ) ||
753            ( IsEndLoopNode() && ToNode->IsLoopNode( ) ) ) {
754       }
755       else if ( anOutPort->IsDataStream() ) {
756         RetVal = RemoveStreamLinkedNode( ToNode ) ;
757       }
758       else {
759         RetVal = RemoveLinkedNode( ToNode ) ;
760       }
761       if ( !RetVal ) {
762         cdebug << "ComputingNode::DelOutPort anOutPort->RemoveLinkedNode Error RetVal " << RetVal
763                << endl ;
764         break ;
765       }
766       if ( ToNode->IsEndSwitchNode() ) {
767         int i ;
768         int done = false ;
769         for ( i = 0 ; i < ToNode->LinkedFromNodesSize() ; i++ ) {
770           GraphBase::StreamNode * fromNode = ToNode->LinkedFromNodes( i ) ;
771 // Not the node that we are deleting ... :
772           if ( strcmp( fromNode->Name() , Name() ) ) {
773             int j ;
774             for ( j = 0 ; j < fromNode->GetNodeOutPortsSize() ; j++ ) {
775               GraphBase::OutPort * fromOutPort = fromNode->GetChangeNodeOutPort( j ) ;
776               int k ;
777               for ( k = 0 ; k < fromOutPort->InPortsSize() ; k++ ) {
778                 if ( strcmp( ToNode->Name() , fromOutPort->InPorts( k )->NodeName() ) == 0 ) {
779                   if ( strcmp( anInPort->PortName() , fromOutPort->InPorts( k )->PortName() ) == 0 ) {
780 // Restore an OutPort in the InPort
781                     anInPort->ChangeOutPort( fromOutPort ) ;
782                     cdebug << "ComputingNode::DelOutPort reestablish " << fromOutPort->NodeName() << "( "
783                            << fromOutPort->PortName() << " ) in the InPort of EndSwitch : "
784                            << ToNode->Name() << "( " << anInPort->PortName() << " )"
785                            << anInPort->Kind() << " " << anInPort->PortStatus()  << endl;
786                     done = true ;
787                     break ;
788                   }
789                 }
790               }
791               if ( done ) {
792                 break ;
793               }
794             }
795             if ( done ) {
796               break ;
797             }
798           }
799         }
800       }
801     }
802   }
803   if ( !RetVal ) {
804     cdebug << "Error RetVal " << RetVal << endl ;
805   }
806
807   GraphBase::PortsOfNode::DelOutPort( OutputParameterName ) ;
808   cdebug_out << "ComputingNode::DelOutPort " << Name() << "( " << OutputParameterName << " )"
809              << endl;
810 }
811
812 GraphBase::InPort * GraphBase::ComputingNode::AddInPort( const char * InputParameterName ,
813                                                          const char * InputParameterType ,
814                                                          const SUPERV::KindOfPort aKindOfPort ,
815                                                          int index ) {
816   cdebug << "AddInPort " << Name() << " ConnectedInPortsNumber " << ConnectedInPortsNumber() << endl ;
817 // JR 12.01.2005 : InitLoop and DoLoop are reserved parameter names in LoopNodes :
818   if ( IsLoopNode() && ( strcmp( InputParameterName , "InitLoop" ) == 0 ||
819                          strcmp( InputParameterName , "DoLoop" ) == 0 ) ) {
820     return NULL ;
821   }
822   return GraphBase::PortsOfNode::AddInPort( _ORB , NamePtr() ,
823                                             Kind() ,
824                                             InputParameterName ,
825                                             InputParameterType ,
826                                             aKindOfPort ,
827                                             index ,
828                                             _Graph_prof_debug , _Graph_fdebug ) ;
829 }
830 GraphBase::OutPort * GraphBase::ComputingNode::AddOutPort( const char * OutputParameterName ,
831                                                            const char * OutputParameterType ,
832                                                            const SUPERV::KindOfPort aKindOfPort ,
833                                                            int index ) {
834   cdebug << "AddOutPort " << Name() << " ConnectedInPortsNumber " << ConnectedInPortsNumber() << endl ;
835   return GraphBase::PortsOfNode::AddOutPort( _ORB , NamePtr() ,
836                                              Kind() ,
837                                              OutputParameterName ,
838                                              OutputParameterType ,
839                                              aKindOfPort ,
840                                              index ,
841                                              _Graph_prof_debug , _Graph_fdebug ) ;
842 }
843
844 void GraphBase::ComputingNode::DelInDataStreamPort( const char * InputParameterName ) {
845   GraphBase::PortsOfNode::DelInPort( InputParameterName ) ;
846 }
847 void GraphBase::ComputingNode::DelOutDataStreamPort( const char * OutputParameterName ) {
848   GraphBase::PortsOfNode::DelOutPort( OutputParameterName ) ;
849 }
850
851 GraphBase::InDataStreamPort * GraphBase::ComputingNode::AddInDataStreamPort( const char * InputParameterName ,
852                                                                              const SALOME_ModuleCatalog::DataStreamType InputParameterType ,
853                                                                              const SALOME_ModuleCatalog::DataStreamDependency aDependency ,
854                                                                              const SUPERV::KindOfPort aKindOfPort ,
855                                                                              int index ) {
856 //  IncrDataStreamInPorts() ;
857   GraphBase::InDataStreamPort * aDataStreamPort ;
858   aDataStreamPort = (GraphBase::InDataStreamPort * ) GraphBase::PortsOfNode::AddInPort( _ORB , NamePtr() ,
859                                                                                         Kind() ,
860                                                                                         InputParameterName ,
861                                                                                         DataStreamTypeToString( InputParameterType ).c_str() ,
862                                                                                         aKindOfPort ,
863                                                                                         index ,
864                                                                                         _Graph_prof_debug ,
865                                                                                         _Graph_fdebug ) ;
866   aDataStreamPort->Dependency( aDependency ) ;
867   if ( aDependency == SALOME_ModuleCatalog::DATASTREAM_TEMPORAL ) {
868     aDataStreamPort->SetParams( SUPERV::TI , SUPERV::L1 , SUPERV::EXTRANULL ) ;
869   }
870   return aDataStreamPort ;
871 }
872 GraphBase::OutDataStreamPort * GraphBase::ComputingNode::AddOutDataStreamPort( const char * OutputParameterName ,
873                                                                                const SALOME_ModuleCatalog::DataStreamType OutputParameterType ,
874                                                                                const SALOME_ModuleCatalog::DataStreamDependency aDependency ,
875                                                                                const SUPERV::KindOfPort aKindOfPort ,
876                                                                                int index ) {
877 //  IncrDataStreamOutPorts() ;
878   GraphBase::OutDataStreamPort * aDataStreamPort ;
879   aDataStreamPort = (GraphBase::OutDataStreamPort * ) GraphBase::PortsOfNode::AddOutPort( _ORB , NamePtr() ,
880                                                                                           Kind() ,
881                                                                                           OutputParameterName ,
882                                                                                           DataStreamTypeToString( OutputParameterType ).c_str() ,
883                                                                                           aKindOfPort ,
884                                                                                           index ,
885                                                                                           _Graph_prof_debug ,
886                                                                                           _Graph_fdebug ) ;
887   aDataStreamPort->Dependency( aDependency ) ;
888   return aDataStreamPort ;
889 }
890
891
892 bool GraphBase::ComputingNode::CheckLoop( GraphBase::LoopNode * aLoopNode ,
893                                           GraphBase::EndOfLoopNode * anEndLoopNode ,
894                                           string & anErrorMessage ) const {
895   cdebug_in << Name() << "->ComputingNode::CheckLoop( " << aLoopNode->Name() << " , "
896             << anEndLoopNode->Name() << ") LinkedNodesSize "
897             << LinkedNodesSize() << endl;
898
899   int i ;
900   if ( LinkedNodesSize() == 0 && !IsDataFlowNode() && !IsDataStreamNode() ) {
901     anErrorMessage = anErrorMessage + string( "The node " ) + string( Name() ) +
902                      string( " has no linked Nodes. Loop not valid\n" ) ;
903     cdebug_out << Name() << "->ComputingNode::CheckLoop( " << aLoopNode->Name()
904                << " , " << anEndLoopNode->Name() << ") LinkedNodesSize "
905                << LinkedNodesSize() << " ERROR false" << endl;
906     return false ;
907   }
908 // We check that all nodes linked to that node go to the end of LoopNode :
909   for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
910     GraphBase::ComputingNode * aNode = (GraphBase::ComputingNode * ) LinkedNodes( i ) ;
911     cdebug << i << ". " << Name() << " Linked to " << aNode->Name() << endl ;
912     if ( !aNode->IsEndLoopNode() || aNode != anEndLoopNode ) {
913       if ( !aNode->CheckLoop( aLoopNode , anEndLoopNode , anErrorMessage) ) {
914         cdebug_out << Name() << "->ComputingNode::CheckLoop( " << aLoopNode->Name()
915                    << " , " << anEndLoopNode->Name() << ") LinkedNodesSize "
916                    << LinkedNodesSize() << " ERROR false" << endl;
917         return false ;
918       }
919     }
920   }
921   cdebug_out << Name() << "->ComputingNode::CheckLoop( " << aLoopNode->Name() << " , "
922              << anEndLoopNode->Name() << ") LinkedNodesSize "
923              << LinkedNodesSize() << " true" << endl;
924   return true ;
925 }
926
927 bool GraphBase::ComputingNode::CheckEndLoop(GraphBase::LoopNode * aLoopNode ,
928                                             GraphBase::EndOfLoopNode * anEndLoopNode ,
929                                             string & anErrorMessage ) const {
930   cdebug_in << Name() << "->ComputingNode::CheckEndLoop( " << aLoopNode->Name() << " , "
931             << anEndLoopNode->Name() << ") LinkedFromNodesSize "
932             << LinkedFromNodesSize() << endl;
933
934   int i ;
935   if ( LinkedFromNodesSize() == 0 ) {
936     anErrorMessage = anErrorMessage + string( "The node " ) + string( Name() ) +
937                      string( " has no reversed linked Nodes. Loop not valid\n" ) ;
938     cdebug_out << Name() << "->ComputingNode::CheckEndLoop( " << aLoopNode->Name()
939                << " , " << anEndLoopNode->Name() << ") LinkedFromNodesSize "
940                << LinkedFromNodesSize() << " ERROR false" << endl;
941     return false ;
942   }
943 // We have to check that all nodes linked from that node go to the beginning of LoopNode : 
944   for ( i = 0 ; i < LinkedFromNodesSize() ; i++ ) {
945     GraphBase::ComputingNode * aNode = (GraphBase::ComputingNode * ) LinkedFromNodes( i ) ;
946     cdebug << i << ". " << Name() << " Linked from " << aNode->Name() << endl ;
947     if ( !aNode->IsLoopNode() || aNode != aLoopNode ) {
948       if ( !aNode->CheckEndLoop( aLoopNode , anEndLoopNode , anErrorMessage ) ) {
949         cdebug_out << Name() << "->ComputingNode::CheckEndLoop( " << aLoopNode->Name()
950                    << " , " << anEndLoopNode->Name() << ") LinkedFromNodesSize "
951                    << LinkedFromNodesSize() << " ERROR false" << endl;
952         return false ;
953       }
954     }
955   }
956   cdebug_out << Name() << "->ComputingNode::CheckEndLoop( " << aLoopNode->Name() << " , "
957              << anEndLoopNode->Name() << ") LinkedFromNodesSize "
958              << LinkedFromNodesSize() << " true" << endl;
959   return true ;
960 }
961
962 bool GraphBase::ComputingNode::InitBranchOfSwitchDone( bool AllInit ,
963                                                        GraphBase::EndOfSwitchNode * anEndSwitchNode ,
964                                                        string & anErrorMessage ) {
965   bool RetVal = true ;
966   bool sts = BranchOfSwitchDone( false ) ;
967   if ( !sts && !AllInit && anEndSwitchNode != this ) {
968 // Common Node in branchs :
969     anErrorMessage = anErrorMessage + string( "Common Node between some SwitchBranches : " ) +
970                      string( Name() ) + string("\n" ) ;
971     cdebug << Name() << "->ComputingNode::InitBranchOfSwitchDone ERROR false"
972            << endl ;
973     RetVal = false ;
974   }
975   int i ;
976   if ( !IsGOTONode() && anEndSwitchNode != this ) {
977     for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
978       GraphBase::ComputingNode * aNode ;
979       aNode = (GraphBase::ComputingNode * ) LinkedNodes( i ) ;
980       if ( !aNode->InitBranchOfSwitchDone( AllInit , anEndSwitchNode , anErrorMessage ) ) {
981         RetVal = false ;
982       }
983     }
984   }
985   return RetVal ;
986 }
987
988 bool GraphBase::ComputingNode::CheckSwitch( GraphBase::EndOfSwitchNode * anEndSwitchNode ,
989                                             string & anErrorMessage ) {
990   bool RetVal = true ;
991   cdebug_in << Name() << "->ComputingNode::CheckSwitch( "
992             << anEndSwitchNode->Name() << " ) " << Kind() << endl;
993   if ( anEndSwitchNode == this ) {
994   }
995 // if it is a SwitchNode, continue the check at the corresponding EndSwitchNode
996   else if ( IsSwitchNode() ) {
997     GraphBase::EndOfSwitchNode * anOtherEndSwitchNode ;
998     anOtherEndSwitchNode = (GraphBase::EndOfSwitchNode * ) ((GraphBase::SwitchNode * ) this)->CoupledNode() ;
999     cdebug << Name() << "->ComputingNode::CheckSwitch will Check "
1000            << anOtherEndSwitchNode->Name() << endl ;
1001     if ( !anOtherEndSwitchNode->CheckSwitch( anEndSwitchNode , anErrorMessage ) ) {
1002       cdebug_out << Name() << "->ComputingNode::CheckSwitch "
1003                  << anOtherEndSwitchNode->Name() << " ERROR false" << endl;
1004       RetVal = false ;
1005     }
1006   }
1007   else {
1008     int i ;
1009     for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1010       GraphBase::OutPort * anOutPort = GetChangeNodeOutPort( i ) ;
1011       if ( !anOutPort->IsDataStream() ) {
1012         int j ;
1013         for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
1014           GraphBase::InPort * anInPort = anOutPort->ChangeInPorts( j ) ;
1015           if ( !anInPort->IsDataStream() ) {
1016             GraphBase::ComputingNode * aNode ;
1017             aNode = GraphOfNode()->GetChangeGraphNode( anInPort->NodeName() ) ;
1018             GraphBase::LoopNode * aLoopNode = NULL ;
1019             GraphBase::EndOfLoopNode * aEndLoopNode = NULL ;
1020             if ( IsLoopNode() ) {
1021               aEndLoopNode = (GraphBase::EndOfLoopNode * ) ((GraphBase::LoopNode * ) this)->CoupledNode() ;
1022               cdebug << Name() << "->ComputingNode::CheckSwitch LoopNode " << Name() << " coupled to "
1023                      << aEndLoopNode << " " << aEndLoopNode->Name() << " aNode " << aNode << endl ;
1024             }
1025             else if ( IsEndLoopNode() ) {
1026               aLoopNode = (GraphBase::LoopNode * ) ((GraphBase::EndOfLoopNode * ) this)->CoupledNode() ;
1027               cdebug << Name() << "->ComputingNode::CheckSwitch EndLoopNode " << Name()
1028                      << " coupled to "
1029                      << aLoopNode << " " << aLoopNode->Name() << " aNode " << aNode << endl ;
1030             }
1031             if ( aNode == NULL ) {
1032               cdebug << Name() << "->ComputingNode::CheckSwitch ignore "
1033                      << anInPort->NodeName() << "( " << anInPort->PortName() << " )" << endl ;
1034             }
1035             else if ( aNode == anEndSwitchNode ) {
1036               if ( !((GraphBase::EndOfSwitchNode * ) aNode)->DecrEndSwitchInPortLinked( anInPort ,
1037                                                                                         anErrorMessage ) ) {
1038                 RetVal = false ;
1039               }
1040             }
1041             else if ( aNode->BranchOfSwitchDone() ) {
1042               cdebug << Name() << "->ComputingNode::CheckSwitch will NOT Check "
1043                      << anInPort->NodeName() << "( " << anInPort->PortName() << " ) : already checked"
1044                      << endl ;
1045             }
1046             else if ( IsLoopNode() && aNode == aEndLoopNode ) {
1047               cdebug << Name() << "->ComputingNode::CheckSwitch will NOT Check "
1048                      << anInPort->NodeName() << "( " << anInPort->PortName() << " )" << endl ;
1049             }
1050             else if ( IsEndLoopNode() && aNode == aLoopNode ) {
1051               cdebug << Name() << "->ComputingNode::CheckSwitch will NOT Check "
1052                      << anInPort->NodeName() << "( " << anInPort->PortName() << " )" << endl ;
1053             }
1054             else if ( aNode->IsGOTONode() ) {
1055               cdebug << Name() << "->ComputingNode::CheckSwitch will NOT Check "
1056                      << anInPort->NodeName() << "( " << anInPort->PortName() << " )" << endl ;
1057               anEndSwitchNode->SetSwitchWithGOTO() ;
1058             }
1059             else {
1060               cdebug << Name() << "->ComputingNode::CheckSwitch will Check "
1061                      << anInPort->NodeName() << "( " << anInPort->PortName() << " )" << endl ;
1062               if ( !aNode->CheckSwitch( anEndSwitchNode , anErrorMessage ) ) {
1063                 cdebug_out << Name() << "->ComputingNode::CheckSwitch "
1064                          << anEndSwitchNode->Name() << " ERROR false" << endl;
1065                 RetVal =  false ;
1066               }
1067 //            aNode->BranchOfSwitchDone( true ) ;
1068             }
1069           }
1070         }
1071       }
1072     }
1073   }
1074   if ( RetVal ) {
1075     BranchOfSwitchDone( true ) ;
1076   }
1077   cdebug_out << Name() << "->ComputingNode::CheckSwitch "
1078              << anEndSwitchNode->Name() << " RetVal " << RetVal << endl;
1079   return RetVal ;
1080 }
1081
1082 #include <sys/time.h>
1083 #include <sys/resource.h>
1084 #include <unistd.h>
1085
1086 const long GraphBase::ComputingNode::CpuUsed() {
1087   struct rusage usage ;
1088   if ( getrusage( RUSAGE_SELF , &usage ) == -1 ) {
1089     perror("GraphBase::CpuUsed") ;
1090     return 0 ;
1091   }
1092 //  return usage.ru_utime.__time_t tv_sec ;
1093   cdebug << "CpuUsed " << usage.ru_utime.tv_sec << " " << usage.ru_utime.tv_usec << " "
1094          << usage.ru_stime.tv_sec << " " << usage.ru_stime.tv_usec << endl ;
1095   return usage.ru_utime.tv_sec ;
1096 }
1097
1098 #if 0
1099 const GraphBase::ListOfParameters * GraphBase::ComputingNode::GetListOfParameters() const {
1100   GraphBase::ListOfParameters * aListOfParameters = new GraphBase::ListOfParameters ;
1101   if ( IsInLineNode() || IsGOTONode() ) {
1102     unsigned int i;
1103     for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1104       const InPort * anInPort = GetNodeInPort( i ) ;
1105       if ( anInPort->IsBus() ) {
1106         int size = aListOfParameters->size() ;
1107         aListOfParameters->resize( size + 1 ) ;
1108         (*aListOfParameters)[size].theInParameter.Parametername = anInPort->PortName() ;
1109         (*aListOfParameters)[size].theInParameter.Parametertype = anInPort->PortType() ;
1110         const OutPort * anOutPort = GetNodeOutPort( anInPort->PortIndex() ) ;
1111         (*aListOfParameters)[size].theOutParameter.Parametername = anOutPort->PortName() ;
1112         (*aListOfParameters)[size].theOutParameter.Parametertype = anOutPort->PortType() ;
1113       }
1114     }
1115   }
1116   return aListOfParameters ;
1117 }
1118 #endif
1119
1120 bool GraphBase::ComputingNode::SaveXML( QDomDocument & Graph , QDomElement & info ,
1121                                         const char * ComponentName ,
1122                                         const char * InterfaceName ,
1123                                         const char * Computer ,
1124                                         const char * CoupledNode ,
1125                                         const ListOfFuncName FuncNames ,
1126                                         const ListOfPythonFunctions PythonFunctions ,
1127                                         int XCoordinate , int YCoordinate ) const {
1128   cdebug_in << "SaveXML Node " << Name() << endl ;
1129   QDomElement node = Graph.createElement( "node" ) ;
1130   info.appendChild( node ) ;
1131   QDomElement componentname = Graph.createElement( "component-name" ) ;
1132   QDomText aField ;
1133   if ( strlen( ComponentName ) ) {
1134 //    f << Tabs << "<component-name>" << ComponentName << "</component-name>"
1135 //      << endl ;
1136 //    componentname.setNodeValue( ComponentName ) ;
1137     aField = Graph.createTextNode( ComponentName ) ;
1138   }
1139   else {
1140 //    f << Tabs << "<component-name>?</component-name>" << endl ;
1141 //    componentname.setNodeValue( "?" ) ;
1142     aField = Graph.createTextNode( "?" ) ;
1143   }
1144   node.appendChild( componentname ) ;
1145   componentname.appendChild( aField ) ;
1146
1147   QDomElement interfacename = Graph.createElement("interface-name") ;
1148   if ( strlen( InterfaceName ) ) {
1149 //    f << Tabs << "<interface-name>" << InterfaceName << "</interface-name>"
1150 //      << endl ;
1151 //    interfacename.setAttribute("name" , InterfaceName ) ;
1152     aField = Graph.createTextNode( InterfaceName ) ;
1153   }
1154   else {
1155 //    f << Tabs << "<interface-name>?</interface-name>" << endl ;
1156 //    interfacename.setAttribute("name" , "?" ) ;
1157     aField = Graph.createTextNode( "?" ) ;
1158   }
1159   node.appendChild(interfacename) ;
1160   interfacename.appendChild( aField ) ;
1161
1162 //  f << Tabs << "<node-name>" << Name() << "</node-name>" << endl ;
1163   QDomElement nodename = Graph.createElement("node-name") ;
1164   aField = Graph.createTextNode( Name() ) ;
1165   node.appendChild( nodename ) ;
1166   nodename.appendChild( aField ) ;
1167
1168 //  f << Tabs << "<kind>" << (int ) Kind() << "</kind>" << endl ;
1169   QDomElement kind = Graph.createElement( "kind" ) ;
1170   QString aKind ;
1171
1172   // san - Presumably, data stream graphs should be always saved with kind = DataStreamGraph
1173 // JR : the bug was at line 566 : && HasDataStream() != 0 was missing
1174   if ( IsDataFlowNode() || ( IsDataStreamNode() && HasDataStream() == 0 ) ) {
1175     aKind = aKind.setNum( SUPERV::DataFlowGraph ) ;
1176   }
1177   else {
1178     aKind = aKind.setNum( Kind() ) ;
1179   }
1180   aField = Graph.createTextNode( aKind ) ;
1181   node.appendChild( kind ) ;
1182   kind.appendChild( aField ) ;
1183
1184   if ( IsDataStreamNode() && HasDataStream() != 0 ) {
1185     CORBA::Long Timeout ;
1186     SUPERV::KindOfDataStreamTrace DataStreamTrace ;
1187     CORBA::Double DeltaTime ;
1188     ((GraphBase::StreamGraph * ) this)->StreamParams( Timeout , DataStreamTrace , DeltaTime ) ;
1189
1190     QDomElement timeout = Graph.createElement("streamgraph-timeout") ;
1191     QString aTimeout ;
1192     aTimeout = aTimeout.setNum( Timeout ) ;
1193     aField = Graph.createTextNode( aTimeout ) ;
1194     node.appendChild( timeout ) ;
1195     timeout.appendChild( aField ) ;
1196
1197     QDomElement datastreamtrace = Graph.createElement("streamgraph-datastreamtrace") ;
1198     QString aDataStreamTrace ;
1199     aDataStreamTrace = aDataStreamTrace.setNum( DataStreamTrace ) ;
1200     aField = Graph.createTextNode( aDataStreamTrace ) ;
1201     node.appendChild( datastreamtrace ) ;
1202     datastreamtrace.appendChild( aField ) ;
1203
1204     QDomElement deltatime = Graph.createElement("streamgraph-deltatime") ;
1205     QString aDeltaTime ;
1206     aDeltaTime = aDeltaTime.setNum( DeltaTime ) ;
1207     aField = Graph.createTextNode( aDeltaTime ) ;
1208     node.appendChild( deltatime ) ;
1209     deltatime.appendChild( aField ) ;
1210   }
1211
1212   QDomElement couplednode = Graph.createElement("coupled-node") ;
1213   if ( IsGOTONode() || IsLoopNode() || IsEndLoopNode() ||
1214        IsSwitchNode() || IsEndSwitchNode() || IsMacroNode() ) {
1215 //    f << Tabs << "<coupled-node>" << CoupledNode << "</coupled-node>"
1216 //      << endl ;
1217     aField = Graph.createTextNode( CoupledNode ) ;
1218   }
1219   else {
1220 //    f << Tabs << "<coupled-node>?</coupled-node>" << endl ;
1221     aField = Graph.createTextNode( "?" ) ;
1222   }
1223   node.appendChild(couplednode) ;
1224   couplednode.appendChild( aField ) ;
1225
1226 //  f << Tabs << "<service>" << endl ;
1227   QDomElement service = Graph.createElement("service") ;
1228   node.appendChild(service) ;
1229   QDomElement servicename = Graph.createElement("service-name") ;
1230   if ( strlen( ServiceName() ) ) {
1231 //    f << Tabs << "    <service-name>" << ServiceName() << "</service-name>" << endl ;
1232     aField = Graph.createTextNode( ServiceName() ) ;
1233   }
1234   else {
1235 //    f << Tabs << "    <service-name>?</service-name>" << endl ;
1236     aField = Graph.createTextNode( "?" ) ;
1237   }
1238   service.appendChild(servicename) ;
1239   servicename.appendChild( aField ) ;
1240
1241   cdebug << "SaveXML " << Name() << " In(" << ServiceInParameter().length()
1242          << ") Out(" << ServiceOutParameter().length() << ")" << endl ;
1243   QDomElement inParameterlist = Graph.createElement("inParameter-list") ;
1244   service.appendChild(inParameterlist) ;
1245   unsigned int i;
1246   GraphBase::ComputingNode * aNode = (GraphBase::ComputingNode * ) this ;
1247   for ( i = 0 ; i < ServiceInParameter().length() ; i++ ) {
1248     const GraphBase::InPort * anInPort ;
1249     anInPort = aNode->GetInPort( ServiceInParameter()[i].Parametername ) ;
1250     if ( !anInPort->IsDataStream() ) {
1251       cdebug << "SaveXML " << i << ". " << ServiceInParameter()[i].Parametername
1252              << " InParameterPort " << anInPort->Kind() << endl ;
1253       QDomElement inParameter = Graph.createElement("inParameter") ;
1254       inParameterlist.appendChild(inParameter) ;
1255       QDomElement inParametertype = Graph.createElement("inParameter-type") ;
1256       if ( strlen( ServiceInParameter()[i].Parametertype ) ) {
1257         aField = Graph.createTextNode( strdup( ServiceInParameter()[i].Parametertype ) ) ;
1258       }
1259       else {
1260         aField = Graph.createTextNode( "?" ) ;
1261       }
1262       inParameter.appendChild(inParametertype) ;
1263       inParametertype.appendChild( aField ) ;
1264       QDomElement inParametername = Graph.createElement("inParameter-name") ;
1265       if ( strlen( ServiceInParameter()[i].Parametername ) ) {
1266         aField = Graph.createTextNode( strdup(ServiceInParameter()[i].Parametername) ) ;
1267       }
1268       else {
1269         aField = Graph.createTextNode( "?" ) ;
1270       }
1271       inParameter.appendChild(inParametername) ;
1272       inParametername.appendChild( aField ) ;
1273     }
1274   }
1275   QDomElement outParameterlist = Graph.createElement("outParameter-list") ;
1276   service.appendChild(outParameterlist) ;
1277   for ( i = 0 ; i < ServiceOutParameter().length() ; i++ ) {
1278     const GraphBase::OutPort * anOutPort ;
1279     anOutPort = aNode->GetOutPort( ServiceOutParameter()[i].Parametername ) ;
1280     if ( !anOutPort->IsDataStream() ) {
1281       cdebug << "SaveXML " << i << ". " << ServiceOutParameter()[i].Parametername
1282              << " OutParameterPort " << anOutPort->Kind() << endl ;
1283       QDomElement outParameter = Graph.createElement("outParameter") ;
1284       outParameterlist.appendChild(outParameter) ;
1285       QDomElement outParametertype = Graph.createElement("outParameter-type") ;
1286       if ( strlen( ServiceOutParameter()[i].Parametertype ) ) {
1287         aField = Graph.createTextNode( strdup(ServiceOutParameter()[i].Parametertype) ) ;
1288       }
1289       else {
1290         aField = Graph.createTextNode( "?" ) ;
1291       }
1292       outParameter.appendChild(outParametertype) ;
1293       outParametertype.appendChild( aField ) ;
1294       QDomElement outParametername = Graph.createElement("outParameter-name") ;
1295       if ( strlen( ServiceOutParameter()[i].Parametername ) ) {
1296         aField = Graph.createTextNode( strdup(ServiceOutParameter()[i].Parametername) ) ;
1297       }
1298       else {
1299         aField = Graph.createTextNode( "?" ) ;
1300       }
1301       outParameter.appendChild(outParametername) ;
1302       outParametername.appendChild( aField ) ;
1303     }
1304   }
1305
1306   QDomElement DataStreamlist = Graph.createElement("DataStream-list") ;
1307   node.appendChild( DataStreamlist ) ;
1308   for ( i = 0 ; i < (unsigned int ) GetNodeInPortsSize() ; i++ ) {
1309     const GraphBase::InPort * anInPort ;
1310     anInPort = aNode->GetNodeInPort( i ) ;
1311     if ( anInPort->IsDataStream() ) {
1312       cdebug << "SaveXML " << i << " " << Name() << " " << anInPort->PortName() << " " << anInPort->PortType()
1313              << " InDataStreamPort " << anInPort->Kind() << endl ;
1314       QDomElement inParameter = Graph.createElement("inParameter") ;
1315       DataStreamlist.appendChild(inParameter) ;
1316       QDomElement inParametertype = Graph.createElement("inParameter-type") ;
1317       QString aType ;
1318       aType = aType.setNum( StringToDataStreamType( anInPort->PortType() ) ) ;
1319       cdebug << "SaveXML " << anInPort->PortType() << " --> " << StringToDataStreamType( anInPort->PortType() )
1320              << " " << aType << endl ;
1321       aField = Graph.createTextNode( aType ) ;
1322       inParameter.appendChild(inParametertype) ;
1323       inParametertype.appendChild( aField ) ;
1324       QDomElement inParametername = Graph.createElement("inParameter-name") ;
1325       if ( strlen( anInPort->PortName() ) ) {
1326         aField = Graph.createTextNode( strdup(anInPort->PortName()) ) ;
1327       }
1328       else {
1329         aField = Graph.createTextNode( "?" ) ;
1330       }
1331       inParameter.appendChild(inParametername) ;
1332       inParametername.appendChild( aField ) ;
1333       cdebug << "SaveXML " << anInPort->PortName() << endl ;
1334       QDomElement inParameterdependency = Graph.createElement("inParameter-dependency") ;
1335       QString aDependency ;
1336       aDependency = aDependency.setNum( anInPort->Dependency() ) ;
1337       aField = Graph.createTextNode( aDependency ) ;
1338       inParameter.appendChild(inParameterdependency) ;
1339       inParameterdependency.appendChild( aField ) ;
1340       cdebug << "SaveXML Dependency " << anInPort->Dependency() << endl ;
1341       SUPERV::KindOfSchema        aKindOfSchema ;
1342       SUPERV::KindOfInterpolation aKindOfInterpolation ;
1343       SUPERV::KindOfExtrapolation aKindOfExtrapolation ;
1344       ((GraphBase::InDataStreamPort * ) anInPort)->Params( aKindOfSchema , aKindOfInterpolation , aKindOfExtrapolation ) ;
1345       QDomElement inParameterKindOfSchema = Graph.createElement("inParameter-schema") ;
1346       QString aSchema ;
1347       aSchema = aSchema.setNum( aKindOfSchema ) ;
1348       aField = Graph.createTextNode( aSchema ) ;
1349       inParameter.appendChild(inParameterKindOfSchema) ;
1350       inParameterKindOfSchema.appendChild( aField ) ;
1351       cdebug << "SaveXML aKindOfSchema " << aKindOfSchema << endl ;
1352       QDomElement inParameterKindOfInterpolation = Graph.createElement("inParameter-interpolation") ;
1353       QString anInterpolation ;
1354       anInterpolation = anInterpolation.setNum( aKindOfInterpolation ) ;
1355       aField = Graph.createTextNode( anInterpolation ) ;
1356       inParameter.appendChild(inParameterKindOfInterpolation) ;
1357       inParameterKindOfInterpolation.appendChild( aField ) ;
1358       cdebug << "SaveXML aKindOfInterpolation " << aKindOfInterpolation << endl ;
1359       QDomElement inParameterKindOfExtrapolation = Graph.createElement("inParameter-extrapolation") ;
1360       QString anExtrapolation ;
1361       anExtrapolation = anExtrapolation.setNum( aKindOfExtrapolation ) ;
1362       aField = Graph.createTextNode( anExtrapolation ) ;
1363       inParameter.appendChild(inParameterKindOfExtrapolation) ;
1364       inParameterKindOfExtrapolation.appendChild( aField ) ;
1365       cdebug << "SaveXML aKindOfExtrapolation " << aKindOfExtrapolation << endl ;
1366     }
1367   }
1368   for ( i = 0 ; i < (unsigned int ) GetNodeOutPortsSize() ; i++ ) {
1369     const GraphBase::OutPort * anOutPort ;
1370     anOutPort = aNode->GetNodeOutPort( i ) ;
1371     if ( anOutPort->IsDataStream() ) {
1372       cdebug << "SaveXML " << i << " " << Name() << " " << anOutPort->PortName() << " " << anOutPort->PortType()
1373              << " OutDataStreamPort " << anOutPort->Kind() << endl ;
1374       QDomElement outParameter = Graph.createElement("outParameter") ;
1375       DataStreamlist.appendChild(outParameter) ;
1376       QDomElement outParametertype = Graph.createElement("outParameter-type") ;
1377       QString aType ;
1378       aType = aType.setNum( StringToDataStreamType( anOutPort->PortType() ) ) ;
1379       cdebug << "SaveXML " << anOutPort->PortType() << " --> " << StringToDataStreamType( anOutPort->PortType() )
1380              << " " << aType << endl ;
1381       aField = Graph.createTextNode( aType ) ;
1382       outParameter.appendChild(outParametertype) ;
1383       outParametertype.appendChild( aField ) ;
1384       QDomElement outParametername = Graph.createElement("outParameter-name") ;
1385       if ( strlen( anOutPort->PortName() ) ) {
1386         aField = Graph.createTextNode( strdup(anOutPort->PortName() ) ) ;
1387       }
1388       else {
1389         aField = Graph.createTextNode( "?" ) ;
1390       }
1391       outParameter.appendChild(outParametername) ;
1392       outParametername.appendChild( aField ) ;
1393       cdebug << "SaveXML " << anOutPort->PortName() << endl ;
1394       QDomElement outParameterdependency = Graph.createElement("outParameter-dependency") ;
1395       QString aDependency ;
1396       aDependency = aDependency.setNum( anOutPort->Dependency() )  ;
1397       aField = Graph.createTextNode( aDependency ) ;
1398       outParameter.appendChild(outParameterdependency) ;
1399       outParameterdependency.appendChild( aField ) ;
1400       cdebug << "SaveXML Dependency " << anOutPort->Dependency() << endl ;
1401       long aNumberOfValues ;
1402       aNumberOfValues = ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues() ;
1403       QDomElement outParameterNumberOfValues = Graph.createElement("outParameter-values") ;
1404       QString aValues ;
1405       aValues = aValues.setNum( aNumberOfValues ) ;
1406       aField = Graph.createTextNode( aValues ) ;
1407       outParameter.appendChild(outParameterNumberOfValues) ;
1408       outParameterNumberOfValues.appendChild( aField ) ;
1409       cdebug << "SaveXML NumberOfValues " << ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues() << endl ;
1410     }
1411   }
1412 //  f << Tabs << "</Parameter-list>" << endl ;    
1413
1414 //  f << Tabs << "<PyFunction-list>" << endl ;
1415   QDomElement PyFunctionlist = Graph.createElement("PyFunction-list") ;
1416   node.appendChild( PyFunctionlist ) ;
1417   for ( i = 0 ; i < PythonFunctions.size() ; i++ ) {
1418 //    f << Tabs << "    <PyFunction>" << endl ;
1419     QDomElement PyFunction = Graph.createElement("PyFunction") ;
1420     PyFunctionlist.appendChild( PyFunction ) ;
1421     int j ;
1422     QDomElement FuncName = Graph.createElement("FuncName") ;
1423     if ( strlen( FuncNames[i].c_str() ) ) {
1424       aField = Graph.createTextNode( FuncNames[i].c_str() ) ;
1425     }
1426     else {
1427       aField = Graph.createTextNode( "?" ) ;
1428     }
1429     PyFunction.appendChild( FuncName ) ;
1430     FuncName.appendChild( aField ) ;
1431     if ( (*PythonFunctions[i]).length() ) {
1432       for ( j = 0 ; j < (int ) (*PythonFunctions[i]).length() ; j++ ) {
1433         QDomElement PyFunc = Graph.createElement("PyFunc") ;
1434         QDomCDATASection aCDATA ;
1435       // mpv: Linux 8.0 compiler compatibility
1436         char * aCDATAChar = strdup ((*PythonFunctions[i])[j]) ;
1437         int i ;
1438         for ( i = 0 ; i < (int ) strlen( aCDATAChar ) ; i++ ) {
1439           if ( aCDATAChar[ i ] != ' ' ) {
1440             break ;
1441           }
1442         }
1443         if ( i == (int ) strlen( aCDATAChar ) ) {
1444           aCDATA = Graph.createCDATASection( "?" ) ;
1445         }
1446         else {
1447           aCDATA = Graph.createCDATASection( aCDATAChar ) ;
1448         }
1449         PyFunction.appendChild( PyFunc ) ;
1450         PyFunc.appendChild( aCDATA ) ;
1451       }
1452     }
1453     else {
1454       QDomElement PyFunc = Graph.createElement("PyFunc") ;
1455       QDomCDATASection aCDATA = Graph.createCDATASection( "?" ) ;
1456       PyFunction.appendChild( PyFunc ) ;
1457       PyFunc.appendChild( aCDATA ) ;
1458     }
1459   }
1460
1461 //  f << Tabs << "<creation-date>" << FirstCreation() << "</creation-date>"
1462 //    << endl ;
1463   QDomElement creationdate = Graph.createElement("creation-date") ;
1464   char fdate[30] ;
1465   sprintf( fdate , "%d/%d/%d - %d:%d:%d" ,  FirstCreation().Day , FirstCreation().Month , FirstCreation().Year , FirstCreation().Hour , FirstCreation().Minute , FirstCreation().Second ) ;
1466   aField = Graph.createTextNode( fdate ) ;
1467   node.appendChild( creationdate ) ;
1468   creationdate.appendChild( aField ) ;
1469 //  f << Tabs << "<lastmodification-date>" << LastModification()
1470 //    << "</lastmodification-date>" << endl ;
1471   QDomElement lastmodificationdate = Graph.createElement("lastmodification-date") ;
1472   char ldate[30] ;
1473   sprintf( ldate , "%d/%d/%d - %d:%d:%d" , LastModification().Day , LastModification().Month , LastModification().Year , LastModification().Hour , LastModification().Minute , LastModification().Second ) ;
1474   aField = Graph.createTextNode( ldate ) ;
1475   node.appendChild( lastmodificationdate ) ;
1476   lastmodificationdate.appendChild( aField ) ;
1477 //  f << Tabs << "<editor-release>" << EditorRelease() << "</editor-release>"
1478 //    << endl ;
1479   QDomElement editorrelease = Graph.createElement("editor-release") ;
1480   aField = Graph.createTextNode( EditorRelease() ) ;
1481   node.appendChild( editorrelease ) ;
1482   editorrelease.appendChild( aField ) ;
1483   QDomElement author = Graph.createElement("author") ;
1484   if ( strlen( Author() ) ) {
1485 //    f << Tabs << "<author>" << Author() << "</author>" << endl ;
1486     aField = Graph.createTextNode( Author() ) ;
1487   }
1488   else {
1489 //    f << Tabs << "<author>?</author>" << endl ;
1490     aField = Graph.createTextNode( "?" ) ;
1491   }
1492   node.appendChild( author ) ;
1493   author.appendChild( aField ) ;
1494   QDomElement container = Graph.createElement("container") ;
1495   if ( IsFactoryNode() && strlen( Computer) ) {
1496 //    f << Tabs << "<container>" << Computer << "</container>" << endl ;
1497     aField = Graph.createTextNode( Computer ) ;
1498   }
1499   else {
1500 //    f << Tabs << "<container>?</container>" << endl ;
1501     aField = Graph.createTextNode( "?" ) ;
1502   }
1503   node.appendChild( container ) ;
1504   container.appendChild( aField ) ;
1505   QDomElement comment = Graph.createElement("comment") ;
1506   if ( strlen( Comment() ) ) {
1507 //    f << Tabs << "<comment>" << Comment() << "</comment>" << endl ;
1508     aField = Graph.createTextNode( Comment() ) ;
1509   }
1510   else {
1511 //    f << Tabs << "<comment>?</comment>" << endl ;
1512     aField = Graph.createTextNode( "?" ) ;
1513   }
1514   node.appendChild( comment ) ;
1515   comment.appendChild( aField ) ;
1516 //  f << Tabs << "<x-position>" << XCoordinate << "</x-position>" << endl ;
1517   QDomElement xposition = Graph.createElement("x-position") ;
1518   QString aXCoordinate ;
1519   aXCoordinate = aKind.setNum( XCoordinate ) ;
1520   aField = Graph.createTextNode( aXCoordinate ) ;
1521   node.appendChild( xposition ) ;
1522   xposition.appendChild( aField ) ;
1523 //  f << Tabs << "<y-position>" << YCoordinate << "</y-position>" << endl ;
1524   QDomElement yposition = Graph.createElement("y-position") ;
1525   QString aYCoordinate ;
1526   aYCoordinate = aKind.setNum( YCoordinate ) ;
1527   aField = Graph.createTextNode( aYCoordinate ) ;
1528   node.appendChild( yposition ) ;
1529   yposition.appendChild( aField ) ;
1530   cdebug_out << "SaveXML Node " << Name() << endl ;
1531   return true ;
1532 }
1533
1534 bool GraphBase::ComputingNode::SavePY( ostream &f , const char * aGraphName ,
1535                                        const char * ComponentName ,
1536                                        const char * InterfaceName ,
1537                                        const char * Computer ,
1538                                        const GraphBase::InLineNode * aCoupledNode ,
1539                                        const ListOfFuncName FuncNames ,
1540                                        const ListOfPythonFunctions PythonFunctions ,
1541                                        int XCoordinate , int YCoordinate ) const {
1542   cdebug_in << "ComputingNode::SavePY " << Name() << endl ;
1543   // san - Presumably, data stream graphs should be always saved with kind = DataStreamGraph
1544 // JR : the bug was at line 927 : && HasDataStream() != 0 was missing
1545   if ( IsDataFlowNode() || ( IsDataStreamNode() && HasDataStream() == 0 ) ) {
1546     f << "    " << Name() << " = Graph( '" << Name() << "' )" << endl ;
1547      if ( GraphMacroLevel() ) {
1548       f << "    " << Name() << ".SetCoupled( '"
1549         << ((GraphBase::GOTONode * ) this)->CoupledNodeName() << "' )" << endl ;
1550     }
1551   }
1552   else if ( IsDataStreamNode() && HasDataStream() != 0 ) {
1553     f << "    " << Name() << " = StreamGraph( '" << Name() << "' )" << endl ;
1554     CORBA::Long Timeout ;
1555     SUPERV::KindOfDataStreamTrace DataStreamTrace ;
1556     CORBA::Double DeltaTime ;
1557     ((GraphBase::StreamGraph * ) this)->StreamParams( Timeout , DataStreamTrace , DeltaTime ) ;
1558     f << "    " << aGraphName << ".SetStreamParams( " << Timeout << " , SUPERV." << DataStreamTrace
1559       << " , " << DeltaTime << " )" << endl ;
1560   }
1561   else if ( IsComputingNode() ) {
1562     int i ;
1563     f << "    " << Name() << "_ServiceinParameter = []" << endl ;
1564     for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1565       f << "    " << Name() << "_ServiceinParameter.append( SALOME_ModuleCatalog.ServicesParameter( '"
1566         << ServiceInParameter()[i].Parametertype << "' , '"
1567         << ServiceInParameter()[i].Parametername << "' ) )" << endl ;
1568     }
1569     f << "    " << Name() << "_ServiceoutParameter = []" << endl ;
1570     for ( i = 0 ; i < (int ) ServiceOutParameter().length() ; i++ ) {
1571       f << "    " << Name() << "_ServiceoutParameter.append( SALOME_ModuleCatalog.ServicesParameter( '"
1572         << ServiceOutParameter()[i].Parametertype << "' , '"
1573         << ServiceOutParameter()[i].Parametername << "' ) )" << endl ;
1574     }
1575     f << "    " << Name() << "_ServiceinStreamParameter = []" << endl ;
1576     for ( i = 0 ; i < (int ) ServiceInStreamParameter().length() ; i++ ) {
1577       f << "    " << Name() << "_ServiceinStreamParameter.append( SALOME_ModuleCatalog.ServicesDataStreamParameter( SALOME_ModuleCatalog."
1578         << ServiceInStreamParameter()[i].Parametertype << " , '"
1579         << ServiceInStreamParameter()[i].Parametername << "' , SALOME_ModuleCatalog."
1580         << ServiceInStreamParameter()[i].Parameterdependency << " ) )" << endl ;
1581     }
1582     f << "    " << Name() << "_ServiceoutStreamParameter = []" << endl ;
1583     for ( i = 0 ; i < (int ) ServiceOutStreamParameter().length() ; i++ ) {
1584       f << "    " << Name() << "_ServiceoutStreamParameter.append( SALOME_ModuleCatalog.ServicesDataStreamParameter( SALOME_ModuleCatalog."
1585         << ServiceOutStreamParameter()[i].Parametertype << " , '"
1586         << ServiceOutStreamParameter()[i].Parametername << "' , SALOME_ModuleCatalog."
1587         << ServiceOutStreamParameter()[i].Parameterdependency << " ) )" << endl ;
1588     }
1589     f << "    " << Name() << "_Service = SALOME_ModuleCatalog.Service( '" << ServiceName()
1590       << "' , " << Name() << "_ServiceinParameter"
1591       << " , " << Name() << "_ServiceoutParameter"
1592       << " , " << Name() << "_ServiceinStreamParameter"
1593       << " , " << Name() << "_ServiceoutStreamParameter"
1594       << " , 0 , 0 )" << endl ;
1595     f << "    " << Name() << " = " << aGraphName << ".CNode( " << Name() << "_Service" << " )"
1596       << endl ;
1597   }
1598   else if ( IsFactoryNode() ) {
1599     f << "    " << Name() << " = " << aGraphName << ".FNode( '" << ComponentName
1600       << "' , '" << InterfaceName << "' , '" << ServiceName() << "' )"
1601       << endl ;
1602   }
1603   else if ( IsEndLoopNode() || IsEndSwitchNode() ) {
1604 // It is done with LoopNode or SwitchNode with CoupledNode()
1605   }
1606   else {
1607     if ( !IsMacroNode() ) {
1608       f << "    " << "Py" << Name() << " = []" << endl ;
1609     }
1610     int i ;
1611     SUPERV::ListOfStrings aPyFunc ;
1612     if ( PythonFunctions.size() ) {
1613       aPyFunc = *PythonFunctions[0] ;
1614       for ( i = 0 ; i < (int ) aPyFunc.length() ; i++ ) {
1615         f << "    " << "Py" << Name() << ".append( '" << aPyFunc[i] << "' )" << endl ;
1616       }
1617     }
1618     if ( IsInLineNode() ) {
1619       f << "    " << Name() << " = " << aGraphName << ".INode( '" << FuncNames[0].c_str() << "' , Py"
1620         << Name() << " )" << endl ;
1621     }
1622     else if ( IsGOTONode() ) {
1623       if ( aCoupledNode ) {
1624         f << "    " << Name() << " = " << aGraphName << ".GNode( '" << FuncNames[0].c_str() << "' , Py"
1625           << Name() << " , '" << aCoupledNode->Name() << "' )" << endl ;
1626       }
1627       else {
1628         f << "    " << Name() << " = " << aGraphName << ".GNode( '" << FuncNames[0].c_str() << "' , Py"
1629           << Name() << " , '' )" << endl ;
1630       }
1631     }
1632     else if ( IsMacroNode() ) {
1633       if ( aCoupledNode ) {
1634         f << "    " << aCoupledNode->Name() << " = Def" << aCoupledNode->Name() << "()" << endl ;
1635         f << "    " << Name() << " = " << aGraphName << ".GraphMNode( " << aCoupledNode->Name() << " )" << endl ;
1636       }
1637       else {
1638         f << "    " << Name() << " = " << aGraphName << ".GraphMNode( ? )" << endl ;
1639       }
1640       f << "    " << Name() << ".SetCoupled( '" << aCoupledNode->Name() << "' )" << endl ;
1641     }
1642     else {
1643 //      char * EndName = NULL ;
1644 //      EndName = new char[ 3 + strlen( Name() ) + 1 ] ;
1645 //      strcpy( EndName , "End" ) ;
1646 //      strcat( EndName , Name() ) ;
1647       char * EndName = aCoupledNode->Name() ;
1648       cdebug << "ComputingNode::SavePY Node " << Name() << " EndName " << EndName
1649              << endl ;
1650       if ( IsLoopNode() ) {
1651         int i ;
1652         SUPERV::ListOfStrings aPyMore = *PythonFunctions[1] ;
1653         SUPERV::ListOfStrings aPyNext = *PythonFunctions[2] ;
1654         f << "    " << "PyMore" << Name() << " = []" << endl ;
1655         for ( i = 0 ; i < (int ) aPyMore.length() ; i++ ) {
1656           f << "    " << "PyMore" << Name() << ".append( '" << aPyMore[i] << "' )" << endl ;
1657         }
1658         f << "    " << "PyNext" << Name() << " = []" << endl ;
1659         for ( i = 0 ; i < (int ) aPyNext.length() ; i++ ) {
1660           f << "    " << "PyNext" << Name() << ".append( '" << aPyNext[i] << "' )" << endl ;
1661         }
1662         f << "    " << Name() << "," << EndName << " = " << aGraphName << ".LNode( '"
1663           << FuncNames[0].c_str() << "' , Py" << Name() << " , '"
1664           << FuncNames[1].c_str() << "' , PyMore" << Name()
1665           << " , '" << FuncNames[2].c_str() << "' , PyNext"
1666           << Name() << " )" << endl ;
1667         f << "    " << EndName << ".SetName( '" << aCoupledNode->Name() << "' )" << endl ;
1668         f << "    " << EndName << ".SetAuthor( '" << aCoupledNode->Author() << "' )" << endl ;
1669         f << "    " << EndName << ".SetComment( '" << aCoupledNode->Comment() << "' )" << endl ;
1670         f << "    " << EndName << ".Coords( " << aCoupledNode->XCoordinate() << " , "
1671           << aCoupledNode->YCoordinate() << " )" << endl ;
1672         SUPERV::ListOfStrings aPyFunc = *aCoupledNode->PythonFunction() ;
1673         f << "    " << "Py" << aCoupledNode->Name() << " = []" << endl ;
1674         for ( i = 0 ; i < (int ) aPyFunc.length() ; i++ ) {
1675           f << "    " << "Py" << aCoupledNode->Name() << ".append( '" << aPyFunc[i] << "' )"
1676             << endl ;
1677         }
1678         f << "    " << EndName << ".SetPyFunction( '" << aCoupledNode->PyFuncName() << "' , Py" << aCoupledNode->Name() << " )" << endl ;
1679         for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1680           const GraphBase::InPort * anInPort = GetNodeInPort(i) ;
1681           cdebug << "Node " << Name() << " InPort " << anInPort->PortName()
1682                  << " " << anInPort->Kind() << endl ;
1683           if ( anInPort->IsLoop() ) {
1684             f << "    " << "I" << Name() << anInPort->PortName() << " = "
1685               << Name() << ".GetInPort( '" << anInPort->PortName() << "' )" << endl ;
1686           }
1687           else if ( anInPort->IsInLine() ) {
1688             f << "    " << "I" << Name() << anInPort->PortName() << " = "
1689               << Name() << ".InPort( '" << anInPort->PortName() << "' , '"
1690               << anInPort->PortType() << "' )" << endl ;
1691           }
1692           else if ( anInPort->IsDataStream() ) {
1693             f << "    " << "I" << Name() << anInPort->PortName() << " = " << Name()
1694               << ".InStreamPort( '" << anInPort->PortName()
1695               << "' , SALOME_ModuleCatalog." << StringToDataStreamType( anInPort->PortType() )
1696               << " , SALOME_ModuleCatalog." << anInPort->Dependency() << " )" << endl ;
1697             SUPERV::KindOfSchema        aKindOfSchema ;
1698             SUPERV::KindOfInterpolation aKindOfInterpolation ;
1699             SUPERV::KindOfExtrapolation aKindOfExtrapolation ;
1700             ((GraphBase::InDataStreamPort * ) anInPort)->Params( aKindOfSchema , aKindOfInterpolation , aKindOfExtrapolation ) ;
1701             f << "    " << "I" << Name() << anInPort->PortName() << ".SetParams( SUPERV." << aKindOfSchema << " , SUPERV."
1702               << aKindOfInterpolation << " , SUPERV." << aKindOfExtrapolation << " )" << endl ;
1703           }
1704           else if ( anInPort->IsGate() ) {
1705             f << "    " << "I" << Name() << anInPort->PortName() << " = "
1706               << Name() << ".GetInPort( '" << anInPort->PortName() << "' )" << endl ;
1707           }
1708         }
1709         for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1710           const GraphBase::OutPort * anOutPort = GetNodeOutPort(i) ;
1711           cdebug << "Node " << Name() << " OutPort " << anOutPort->PortName()
1712                  << " " << anOutPort->Kind() << endl ;
1713           if ( anOutPort->IsInLine() || anOutPort->IsLoop() ) {
1714             f << "    " << "O" << Name() << anOutPort->PortName() << " = "
1715               << Name() << ".GetOutPort( '" << anOutPort->PortName() << "' )" << endl ;
1716           }
1717           else if ( anOutPort->IsDataStream() ) {
1718             f << "    " << "O" << Name() << anOutPort->PortName() << " = " << Name()
1719               << ".OutStreamPort( '" << anOutPort->PortName()
1720               << "' , SALOME_ModuleCatalog." << StringToDataStreamType( anOutPort->PortType() )
1721               << " , SALOME_ModuleCatalog." << anOutPort->Dependency() << " )" << endl ;
1722             long aNumberOfValues ;
1723             aNumberOfValues = ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues() ;
1724             f << "    " << "O" << Name() << anOutPort->PortName() << ".SetNumberOfValues( " << aNumberOfValues << " )"
1725               << endl ;
1726           }
1727 //JR 02.09.2005 : GetOutPort for Gates was missing
1728           else if ( anOutPort->IsGate() ) {
1729             f << "    " << "O" << Name() << anOutPort->PortName() << " = "
1730               << Name() << ".GetOutPort( '" << anOutPort->PortName() << "' )" << endl ;
1731           }
1732         }
1733         for ( i = 0 ; i < aCoupledNode->GetNodeInPortsSize() ; i++ ) {
1734           const GraphBase::InPort * anInPort = aCoupledNode->GetNodeInPort(i) ;
1735           cdebug << "Node " << aCoupledNode->Name() << " InPort " << anInPort->PortName()
1736                  << " " << anInPort->Kind() << endl ;
1737           if ( anInPort->IsInLine() || anInPort->IsLoop() || anInPort->IsGate() ) {
1738             f << "    " << "I" << EndName << anInPort->PortName() << " = " << EndName
1739               << ".GetInPort( '" << anInPort->PortName() << "' )" << endl ;
1740           }
1741           else if ( anInPort->IsDataStream() ) {
1742             f << "    " << "I" << EndName << anInPort->PortName() << " = " << EndName
1743               << ".InStreamPort( '" << anInPort->PortName()
1744               << "' , SALOME_ModuleCatalog." << StringToDataStreamType( anInPort->PortType() )
1745               << " , SALOME_ModuleCatalog." << anInPort->Dependency() << " )" << endl ;
1746             SUPERV::KindOfSchema        aKindOfSchema ;
1747             SUPERV::KindOfInterpolation aKindOfInterpolation ;
1748             SUPERV::KindOfExtrapolation aKindOfExtrapolation ;
1749             ((GraphBase::InDataStreamPort * ) anInPort)->Params( aKindOfSchema , aKindOfInterpolation , aKindOfExtrapolation ) ;
1750             f << "    " << "I" << EndName << anInPort->PortName() << ".SetParams( SUPERV." << aKindOfSchema << " , SUPERV."
1751               << aKindOfInterpolation << " , SUPERV." << aKindOfExtrapolation << " )" << endl ;
1752           }
1753         }
1754         for ( i = 0 ; i < aCoupledNode->GetNodeOutPortsSize() ; i++ ) {
1755           const GraphBase::OutPort * anOutPort = aCoupledNode->GetNodeOutPort(i) ;
1756           cdebug << "Node " << aCoupledNode->Name() << " OutPort " << anOutPort->PortName()
1757                  << " " << anOutPort->Kind() << endl ;
1758           if ( anOutPort->IsInLine() || anOutPort->IsLoop() || anOutPort->IsGate() ) {
1759             f << "    " << "O" << EndName << anOutPort->PortName() << " = " << EndName
1760               << ".GetOutPort( '" << anOutPort->PortName() << "' )" << endl ;
1761           }
1762           else if ( anOutPort->IsDataStream() ) {
1763             f << "    " << "O" << EndName << anOutPort->PortName() << " = " << EndName
1764               << ".OutStreamPort( '" << anOutPort->PortName()
1765               << "' , SALOME_ModuleCatalog." << StringToDataStreamType( anOutPort->PortType() )
1766               << " , SALOME_ModuleCatalog." << anOutPort->Dependency() << " )" << endl ;
1767             long aNumberOfValues ;
1768             aNumberOfValues = ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues() ;
1769             f << "    " << "O" << EndName << anOutPort->PortName() << ".SetNumberOfValues( " << aNumberOfValues << " )"
1770               << endl ;
1771           }
1772         }
1773       }
1774       else if ( IsSwitchNode() ) {
1775         f << "    " << Name() << "," << EndName << " = " << aGraphName << ".SNode( '"
1776           << FuncNames[0].c_str() << "' , Py" << Name() << " )" << endl ;
1777         f << "    " << EndName << ".SetName( '" << aCoupledNode->Name() << "' )" << endl ;
1778         f << "    " << EndName << ".SetAuthor( '" << aCoupledNode->Author() << "' )" << endl ;
1779         f << "    " << EndName << ".SetComment( '" << aCoupledNode->Comment() << "' )" << endl ;
1780         f << "    " << EndName << ".Coords( " << aCoupledNode->XCoordinate() << " , "
1781           << aCoupledNode->YCoordinate() << " )" << endl ;
1782         SUPERV::ListOfStrings aPyFunc = *aCoupledNode->PythonFunction() ;
1783         f << "    " << "Py" << aCoupledNode->Name() << " = []" << endl ;
1784         for ( i = 0 ; i < (int ) aPyFunc.length() ; i++ ) {
1785           f << "    " << "Py" << aCoupledNode->Name() << ".append( '" << aPyFunc[i] << "' )"
1786             << endl ;
1787         }
1788         f << "    " << EndName << ".SetPyFunction( '" << aCoupledNode->PyFuncName() << "' , Py" << aCoupledNode->Name() << " )" << endl ;
1789         for ( i = 0 ; i < aCoupledNode->GetNodeInPortsSize() ; i++ ) {
1790           const GraphBase::InPort * anInPort = aCoupledNode->GetNodeInPort(i) ;
1791           cdebug << "Node " << aCoupledNode->Name() << " InPort " << anInPort->PortName()
1792                  << " " << anInPort->Kind() << endl ;
1793 //          if ( anInPort->IsGate() || anInPort->IsEndSwitch() ) {
1794           if ( anInPort->IsGate() ) {
1795             f << "    " << "I" << EndName << anInPort->PortName() << " = " << EndName
1796               << ".GetInPort( '" << anInPort->PortName() << "' )" << endl ;
1797           }
1798           else if ( anInPort->IsInLine() || anInPort->IsEndSwitch() ) {
1799             f << "    " << "I" << EndName << anInPort->PortName() << " = " << EndName
1800               << ".InPort( '" << anInPort->PortName()
1801               << "' , '" << anInPort->PortType() << "' )" << endl ;
1802           }
1803           else if ( anInPort->IsDataStream() ) {
1804             f << "    " << "I" << EndName << anInPort->PortName() << " = " << EndName
1805               << ".InStreamPort( '" << anInPort->PortName()
1806               << "' , SALOME_ModuleCatalog." << StringToDataStreamType( anInPort->PortType() )
1807               << " , SALOME_ModuleCatalog." << anInPort->Dependency() << " )" << endl ;
1808             SUPERV::KindOfSchema        aKindOfSchema ;
1809             SUPERV::KindOfInterpolation aKindOfInterpolation ;
1810             SUPERV::KindOfExtrapolation aKindOfExtrapolation ;
1811             ((GraphBase::InDataStreamPort * ) anInPort)->Params( aKindOfSchema , aKindOfInterpolation , aKindOfExtrapolation ) ;
1812             f << "    " << "I" << EndName << anInPort->PortName() << ".SetParams( SUPERV." << aKindOfSchema << " , SUPERV."
1813               << aKindOfInterpolation << " , SUPERV." << aKindOfExtrapolation << " )" << endl ;
1814           }
1815         }
1816         for ( i = 0 ; i < aCoupledNode->GetNodeOutPortsSize() ; i++ ) {
1817           const GraphBase::OutPort * anOutPort = aCoupledNode->GetNodeOutPort(i) ;
1818           cdebug << "Node " << aCoupledNode->Name() << " OutPort " << anOutPort->PortName()
1819                  << " " << anOutPort->Kind() << endl ;
1820 //          if ( anOutPort->IsGate() || anOutPort->IsEndSwitch() ) {
1821           if ( anOutPort->IsGate() ) {
1822             f << "    " << "O" << EndName << anOutPort->PortName() << " = " << EndName
1823               << ".GetOutPort( '" << anOutPort->PortName() << "' )" << endl ;
1824           }
1825           else if ( anOutPort->IsInLine() || anOutPort->IsSwitch() ) {
1826             f << "    " << "O" << EndName << anOutPort->PortName() << " = " << EndName
1827               << ".OutPort( '" << anOutPort->PortName()
1828               << "' , '" << anOutPort->PortType() << "' )" << endl ;
1829           }
1830           else if ( anOutPort->IsDataStream() ) {
1831             f << "    " << "O" << EndName << anOutPort->PortName() << " = " << EndName
1832               << ".OutStreamPort( '" << anOutPort->PortName()
1833               << "' , SALOME_ModuleCatalog." << StringToDataStreamType( anOutPort->PortType() )
1834               << " , SALOME_ModuleCatalog." << anOutPort->Dependency() << " )" << endl ;
1835             long aNumberOfValues ;
1836             aNumberOfValues = ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues() ;
1837             f << "    " << "O" << EndName << anOutPort->PortName() << ".SetNumberOfValues( " << aNumberOfValues << " )"
1838               << endl ;
1839           }
1840         }
1841       }
1842       cdebug << "ComputingNode::SavePY Node " << Name() << " EndName " << EndName
1843              << endl ;
1844 // PAL8507
1845 //JR 24.02.2005 Debug !!!... : I should not delete myself : what a stupid thing !
1846 //      delete [] EndName ;
1847     }
1848   }
1849
1850   if ( IsEndLoopNode() || IsEndSwitchNode() ) {
1851 // It is done with LoopNode or SwitchNode with CoupledNode()
1852   }
1853   else {
1854     f << "    " << Name() << ".SetName( '" << Name() << "' )" << endl ;
1855     f << "    " << Name() << ".SetAuthor( '" << Author() << "' )" << endl ;
1856     if ( IsFactoryNode() ) {
1857       f << "    " << Name() << ".SetContainer( '" << Computer << "' )" << endl ;
1858     }
1859     f << "    " << Name() << ".SetComment( '" << Comment() << "' )" << endl ;
1860     f << "    " << Name() << ".Coords( " << XCoordinate << " , " << YCoordinate << " )" << endl ;
1861
1862     if ( IsComputingNode() || IsFactoryNode() ) {
1863       int i ;
1864       for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1865         const GraphBase::InPort * anInPort = GetNodeInPort(i) ;
1866         if ( !anInPort->IsDataStream() ) {
1867           cdebug << "Node " << Name() << " InPort " << anInPort->PortName()
1868                  << " " << anInPort->Kind() << endl ;
1869           f << "    " << "I" << Name() << anInPort->PortName() << " = "
1870             << Name() << ".GetInPort( '" << anInPort->PortName() << "' )" << endl ;
1871         }
1872       }
1873       for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1874         const GraphBase::OutPort * anOutPort = GetNodeOutPort(i) ;
1875         if ( !anOutPort->IsDataStream() ) {
1876           cdebug << "Node " << Name() << " OutPort " << anOutPort->PortName()
1877                  << " " << anOutPort->Kind() << endl ;
1878           f << "    " << "O" << Name() << anOutPort->PortName() << " = "
1879             << Name() << ".GetOutPort( '" << anOutPort->PortName() << "' )" << endl ;
1880         }
1881       }
1882     }
1883     else if ( IsOneOfInLineNodes() && !IsLoopNode() ) {
1884       int i ;
1885       for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1886         const GraphBase::InPort * anInPort = GetNodeInPort(i) ;
1887         cdebug << "ComputingNode::SavePY Node " << Name() << " InPort " << anInPort->PortName()
1888                << " " << anInPort->Kind() << endl ;
1889 //        if ( anInPort->IsGate() || ( anInPort->IsInLine() && IsMacroNode() ) ) {
1890         if ( anInPort->IsGate() || IsMacroNode() ) {
1891           f << "    " << "I" << Name() << anInPort->PortName() << " = "
1892             << Name() << ".GetInPort( '" << anInPort->PortName()  << "' )" << endl ;
1893         }
1894         else if ( anInPort->IsInLine() || anInPort->IsEndSwitch() ) {
1895           f << "    " << "I" << Name() << anInPort->PortName() << " = "
1896             << Name() << ".InPort( '" << anInPort->PortName() << "' , '"
1897             << anInPort->PortType() << "' )" << endl ;
1898         }
1899         else {
1900           cdebug << "Ignored " << Name() << " " << anInPort->PortName() << " " << anInPort->PortStatus() << endl ;
1901 //          f << "    " << "I" << Name() << anInPort->PortName() << " = "
1902 //            << Name() << ".GetInPort( '" << anInPort->PortName()  << "' )" << endl ;
1903         }
1904       }
1905       for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1906         const GraphBase::OutPort * anOutPort = GetNodeOutPort(i) ;
1907         cdebug << "ComputingNode::SavePY Node " << Name() << " OutPort " << anOutPort->PortName()
1908                << " " << anOutPort->Kind() << endl ;
1909 //        if ( anOutPort->IsGate() || ( anOutPort->IsInLine() && IsMacroNode() ) ) {
1910         if ( anOutPort->IsGate() || IsMacroNode() ) {
1911           f << "    " << "O" << Name() << anOutPort->PortName() << " = "
1912             << Name() << ".GetOutPort( '" << anOutPort->PortName() << "' )" << endl ;
1913         }
1914         else if ( anOutPort->IsInLine() || anOutPort->IsSwitch() ) {
1915           f << "    " << "O" << Name() << anOutPort->PortName() << " = "
1916             << Name() << ".OutPort( '" << anOutPort->PortName()
1917             << "' , '" << anOutPort->PortType() << "' )" << endl ;
1918         }
1919         else {
1920           cdebug << "Ignored " << Name() << " " << anOutPort->PortName() << " " << anOutPort->PortStatus() << endl ;
1921 //          f << "    " << "O" << Name() << anOutPort->PortName() << " = "
1922 //            << Name() << ".GetOutPort( '" << anOutPort->PortName() << "' )" << endl ;
1923         }
1924       }
1925     }
1926     if ( !IsDataFlowNode() && !IsDataStreamNode() ) {
1927       int i ;
1928       for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1929         const GraphBase::InPort * anInPort = GetNodeInPort(i) ;
1930         cdebug << "Node " << Name() << " InPort " << anInPort->PortName()
1931                << " " << anInPort->Kind() << endl ;
1932         if ( anInPort->IsDataStream() ) {
1933           if ( IsOneOfInLineNodes() ) {
1934             f << "    " << "I" << Name() << anInPort->PortName() << " = "
1935               << Name() << ".InStreamPort( '" << anInPort->PortName() << "' , SALOME_ModuleCatalog."
1936               << StringToDataStreamType( anInPort->PortType() ) << " , SALOME_ModuleCatalog."
1937               << anInPort->Dependency() << " )" << endl ;
1938           }
1939           else {
1940             f << "    " << "I" << Name() << anInPort->PortName() << " = "
1941               << Name() << ".GetInStreamPort( '" << anInPort->PortName() << "' )" << endl ;
1942           }
1943           SUPERV::KindOfSchema        aKindOfSchema ;
1944           SUPERV::KindOfInterpolation aKindOfInterpolation ;
1945           SUPERV::KindOfExtrapolation aKindOfExtrapolation ;
1946           ((GraphBase::InDataStreamPort * ) anInPort)->Params( aKindOfSchema , aKindOfInterpolation , aKindOfExtrapolation ) ;
1947           f << "    " << "I" << Name() << anInPort->PortName() << ".SetParams( SUPERV." << aKindOfSchema << " , SUPERV."
1948             << aKindOfInterpolation << " , SUPERV." << aKindOfExtrapolation << " )" << endl ;
1949         }
1950       }
1951       for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1952         const GraphBase::OutPort * anOutPort = GetNodeOutPort(i) ;
1953         cdebug << "Node " << Name() << " OutPort " << anOutPort->PortName()
1954                << " " << anOutPort->Kind() << endl ;
1955         if ( anOutPort->IsDataStream() ) {
1956           if ( IsOneOfInLineNodes() ) {
1957             f << "    " << "O" << Name() << anOutPort->PortName() << " = "
1958               << Name() << ".OutStreamPort( '" << anOutPort->PortName() << "' , SALOME_ModuleCatalog."
1959               << StringToDataStreamType( anOutPort->PortType() ) << " , SALOME_ModuleCatalog."
1960               << anOutPort->Dependency() << " )" << endl ;
1961           }
1962           else {
1963             f << "    " << "O" << Name() << anOutPort->PortName() << " = "
1964               << Name() << ".GetOutStreamPort( '" << anOutPort->PortName() << "' )" << endl ;
1965           }
1966           long aNumberOfValues ;
1967           aNumberOfValues = ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues() ;
1968           f << "    " << "O" << Name() << anOutPort->PortName() << ".SetNumberOfValues( " << aNumberOfValues << " )" << endl ;
1969         }
1970       }
1971     }
1972   }
1973
1974   cdebug_out << "ComputingNode::SavePY " ;
1975   NodeInfo( *_fdebug ) ;
1976   cdebug << endl ;
1977   return true ;
1978 }
1979
1980 void GraphBase::ComputingNode::NodeInfo(ostream & s) const {
1981   s << *this ;
1982   ListPorts( s , true ) ;
1983   s << ends ;
1984 }
1985
1986 ostream & operator<< (ostream & f,const GraphBase::ComputingNode & G) {
1987 //  f << "ComponentName    " << G.ComponentName() << endl ;
1988   if ( G.IsComputingNode() ) {
1989     f << "NodeName         " << G.Name() << endl ;
1990   }
1991   else {
1992     f << "DataFlowName     " << G.Name() << endl ;
1993   }
1994   f << "Kind             " << G.Kind() << endl ;
1995   f << "Service          " << *G.GetService() ;
1996   f << "FirstCreation    " << G.FirstCreation () << endl ;
1997   f << "LastModification " << G.LastModification() << endl ;
1998   f << "EditorRelease    " << G.EditorRelease() << endl ;
1999   f << "Author           " << G.Author() << endl ;
2000 //  f << "Computer         " << G.Computer() << endl ;
2001   f << "Comment          " << G.Comment() << endl ;
2002   f << endl ;
2003   
2004   return f;
2005 }
2006
2007 void GraphBase::ComputingNode::ListLinks(ostream &f ) const {
2008   int i ;
2009   for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
2010     const GraphBase::OutPort* fromPort = GetNodeOutPort( i ) ;
2011     if ( fromPort->IsPortConnected() ) {
2012       int j ;
2013       for ( j = 0 ; j < fromPort->InPortsSize() ; j++ ) {
2014         if ( j == 0 ) {
2015           f << "FromNode " << Name() << endl ;
2016         }
2017         f << "         FromServiceParameterName "
2018           << fromPort->GetServicesParameter().Parametername ;
2019         const GraphBase::InPort* toPort = fromPort->InPorts( j ) ;
2020         f << " ToNode " << toPort->NodeName() ;
2021         f << " ToServiceParameterName "
2022           << toPort->GetServicesParameter().Parametername;
2023         f << " Value " ;
2024         fromPort->StringValue( f ) ;
2025         f << endl ;
2026       }
2027     }
2028   }
2029 }
2030
2031 ostream & operator<< (ostream &fOut,const SUPERV::SDate &D) {
2032 //  cdebug_in << "operator<< GraphEditor::Date" << endl;
2033
2034   fOut  << D.Day << "/" 
2035         << D.Month << "/" 
2036         << D.Year << " - " 
2037         << D.Hour << ":" 
2038         << D.Minute <<  ":"  
2039         << D.Second;
2040
2041 //  cdebug_out << "operator<< GraphEditor::Date" << endl;
2042   return fOut;
2043 }
2044