Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/superv.git] / src / Supervision / Graph_Impl.cxx
1 //  SUPERV Supervision : contains the implementation of interfaces of SuperVision described in SUPERV.idl
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 //
24 //  File   : Graph_Impl.cxx
25 //  Author : Jean Rahuel
26 //  Module : SUPERV
27 //  $Header: 
28
29 using namespace std;
30 #include <stdio.h>
31 #include <fstream>
32 //#include <sstream>
33 #include <string>
34
35 //#include "utilities.h"
36
37 #include "SALOME_Container_i.hxx"
38
39 #include "StreamGraph_Impl.hxx"
40
41 #include "DataFlowEditor_DataFlow.hxx"
42
43 extern GraphExecutor::FiniteStateMachine * theAutomaton ;
44
45 static void CreateEditor( CORBA::ORB_ptr orb ,
46                           const char *instanceName ,
47                           const char *aDataFlowName ,
48                           const SUPERV::KindOfNode aKindOfNode ,
49                           string & dbgfile ,
50                           GraphEditor::DataFlow **  aDataFlowEditor ) {
51   bool aXmlFile = false ;
52   int lenname = strlen( aDataFlowName ) ;
53   char * theDataFlowName = new char [ lenname+1 ] ;
54   strcpy( theDataFlowName , aDataFlowName ) ;
55   if ( aDataFlowName ) {
56     if ( lenname > 4 && !strcmp( &aDataFlowName[ lenname - 4 ] , ".xml" ) ) {
57       strncpy( theDataFlowName , &aDataFlowName[ 0 ] , lenname-4 ) ;
58       theDataFlowName[ lenname-4 ] = '\0' ;
59       aXmlFile = true ;
60       int i ;
61       for ( i = lenname - 5 ; i >= 0 ; i-- ) {
62         if ( aDataFlowName[ i ] == '/' ) {
63           strncpy( theDataFlowName , &aDataFlowName[ i + 1 ] , lenname-5-i ) ;
64           theDataFlowName[ lenname-5-i ] = '\0' ;
65           break ;
66         }
67       }
68     }
69     else {
70       strcpy( theDataFlowName , &aDataFlowName[ 0 ] ) ;
71     }
72   }
73   
74   string theDataFlowInstanceName = theDataFlowName ;
75
76   // asv : 16.11.04 : creation of log file in /tmp/logs/$USER dir. 
77   // "/tmp/logs/$USER" was created by  runSalome.py -> orbmodule.py.
78   dbgfile = "/tmp/logs/" ;
79   dbgfile += getenv( "USER" ) ;
80   dbgfile += "/" ;
81   dbgfile += instanceName ;
82   dbgfile += "_" ;
83   dbgfile += theDataFlowInstanceName ;
84   dbgfile = dbgfile + "_" + theAutomaton->DbgFileNumber() + ".log" ;
85   FILE* f = fopen ( dbgfile.c_str(), "a" );
86   if ( f ) { // check if file can be opened for writing
87     fclose( f );
88   } 
89   else { // if file can't be opened - use a guaranteed temp file name
90     char* aTempNam = tempnam( NULL, NULL );
91     dbgfile = aTempNam;
92     free ( aTempNam );
93   }
94
95   SALOME_NamingService * NamingService = new SALOME_NamingService( orb ) ;
96   *aDataFlowEditor = new GraphEditor::DataFlow( orb , NamingService ,
97                                                 theDataFlowInstanceName.c_str() , dbgfile.c_str() ,
98                                                 aKindOfNode ) ;
99   MESSAGE( "CreateEditor " << theDataFlowName << " uniquely named " << theDataFlowInstanceName << " created with "
100            << dbgfile.c_str() ) ;
101
102   delete [] theDataFlowName ;
103 }
104
105 static void CreateExecutor( CORBA::ORB_ptr orb ,
106                           const char *instanceName ,
107                           const char *aDataFlowName ,
108                           const SUPERV::KindOfNode aKindOfNode ,
109                           string & dbgfile ,
110                           GraphExecutor::DataFlow **  aDataFlowExecutor ) {
111   int lenname = strlen( aDataFlowName ) ;
112   char * theDataFlowName = new char [ lenname+1 ] ;
113   strcpy( theDataFlowName , aDataFlowName ) ;
114   if ( aDataFlowName ) {
115     strcpy( theDataFlowName , &aDataFlowName[ 0 ] ) ;
116   }
117
118   string theDataFlowInstanceName = theDataFlowName ;
119
120   // asv : 16.11.04 : creation of log file in /tmp/logs/$USER dir. 
121   // "/tmp/logs/$USER" was created by  runSalome.py -> orbmodule.py.
122   dbgfile = "/tmp/logs/" ;
123   dbgfile += getenv( "USER" ) ;
124   dbgfile += "/" ;
125   dbgfile += instanceName ;
126   dbgfile += "_" ;
127   dbgfile += theDataFlowInstanceName ;
128   dbgfile = dbgfile + "_" + theAutomaton->DbgFileNumber() ;
129   ostringstream astr ;
130   astr << theAutomaton->ExecNumber() ;
131   dbgfile += astr.str() ;
132   dbgfile += string( "_Exec.log" ) ;
133   FILE* f = fopen ( dbgfile.c_str(), "a" );
134   if ( f ) { // check if file can be opened for writing
135     fclose( f );
136   } 
137   else { // if file can't be opened - use a guaranteed temp file name
138     char* aTempNam = tempnam( NULL, NULL );
139     dbgfile = aTempNam;
140     free ( aTempNam );
141   }
142
143   SALOME_NamingService * NamingService = new SALOME_NamingService( orb ) ;
144   *aDataFlowExecutor = new GraphExecutor::DataFlow( orb , NamingService ,
145                                                     theDataFlowInstanceName.c_str() , dbgfile.c_str() ,
146                                                     aKindOfNode ) ;
147
148   MESSAGE( "CreateExecutor " << theDataFlowName << " " << theDataFlowInstanceName << " created with "
149            << dbgfile.c_str() ) ;
150
151   delete [] theDataFlowName ;
152 }
153
154 Graph_Impl::Graph_Impl( CORBA::ORB_ptr orb ,
155                         PortableServer::POA_ptr poa ,
156                         PortableServer::ObjectId * contId , 
157                         const char *instanceName ,
158                         const char *interfaceName ,
159                         const char *aDataFlowName ,
160                         const SUPERV::KindOfNode aKindOfNode ) :
161   GNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowName , aKindOfNode ) {
162 //  MESSAGE("Graph_Impl::Graph_Impl activate object instanceName("
163 //          << instanceName << ") interfaceName(" << interfaceName << ") --> "
164 //          << hex << (void *) this << dec )
165 //  beginService( "Graph_Impl::Graph_Impl" );
166   _Orb = CORBA::ORB::_duplicate(orb);
167   _Poa = poa ;
168   _ContId = contId ;
169   _DebugFileName = NULL ;
170   if ( aKindOfNode == SUPERV::DataFlowGraph || aKindOfNode == SUPERV::MacroNode ) {
171 //    MESSAGE( "Graph_Impl::Graph_Impl _poa->activate_object" );
172     _thisObj = this ;
173     _id = _poa->activate_object(_thisObj);
174   }
175   else {
176 //    MESSAGE( "Graph_Impl::Graph_Impl NO _poa->activate_object " );
177   }
178
179   if ( aKindOfNode == SUPERV::DataFlowGraph || aKindOfNode == SUPERV::DataStreamGraph ) {
180     string dbgfile ;
181     GraphEditor::DataFlow * aDataFlowEditor ;
182     CreateEditor( orb , instanceName , aDataFlowName , aKindOfNode ,
183                   dbgfile , &aDataFlowEditor ) ;
184
185     if ( _DebugFileName ) {
186       delete [] _DebugFileName ;
187     }
188     _DebugFileName = new char[ strlen( dbgfile.c_str() )+1 ] ;
189     strcpy( _DebugFileName , dbgfile.c_str() ) ;
190
191     _NamingService = new SALOME_NamingService( orb ) ;
192     DataFlowEditor( aDataFlowEditor ) ;
193     DataFlowEditor()->Graph()->GraphEditor( aDataFlowEditor ) ;
194     DataFlowEditor()->Graph()->SetObjImpl( this ) ;
195   }
196   pthread_mutex_init( &_MutexExecutorWait , NULL ) ;
197 //  DataFlowExecutor( NULL ) ;
198 //  endService( "Graph_Impl::Graph_Impl" );
199 }
200
201 Graph_Impl::Graph_Impl( CORBA::ORB_ptr orb ,
202                         PortableServer::POA_ptr poa ,
203                         PortableServer::ObjectId * contId , 
204                         const char *instanceName ,
205                         const char *interfaceName ,
206                         GraphEditor::DataFlow * aDataFlowEditor ,
207                         GraphEditor::InNode * aDataFlowNode ) :
208   GNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , aDataFlowNode ) {
209 //  beginService( "Graph_Impl::Graph_Impl" );
210 //  MESSAGE( aDataFlowEditor->Graph()->Name() << " " );
211   if ( aDataFlowEditor->Graph()->IsDataFlowNode() ||
212        ( aDataFlowNode && aDataFlowNode->IsMacroNode() ) ) {
213 //    MESSAGE( "Graph_Impl::Graph_Impl _poa->activate_object" );
214     _thisObj = this ;
215     _id = _poa->activate_object(_thisObj);
216   }
217   else {
218 //    MESSAGE( "Graph_Impl::Graph_Impl NO _poa->activate_object " );
219   }
220   _Orb = CORBA::ORB::_duplicate(orb);
221   _Poa = poa ;
222   _ContId = contId ;
223   _DebugFileName = NULL ;
224   DataFlowEditor( aDataFlowEditor ) ;
225   DataFlowEditor()->Graph()->GraphEditor( aDataFlowEditor ) ;
226   DataFlowEditor()->Graph()->SetObjImpl( this ) ;
227   pthread_mutex_init( &_MutexExecutorWait , NULL ) ;
228 //  DataFlowExecutor( NULL ) ;
229 //  endService( "Graph_Impl::Graph_Impl" );  
230 }
231
232 Graph_Impl::Graph_Impl() {
233 }
234
235 Graph_Impl::~Graph_Impl() {
236   beginService( "Graph_Impl::~Graph_Impl" );
237   endService( "Graph_Impl::~Graph_Impl" );
238 }
239
240 void Graph_Impl::destroy() {
241   beginService( "Graph_Impl::destroy" );
242   if ( DataFlowNode() && DataFlowNode()->ComputingNode()->IsMacroNode() ) {
243     SUPERV::Graph_var aGraph = DataFlowNode()->GOTONode()->MacroObject() ;
244     GNode_Impl::Delete() ;
245     if ( !CORBA::is_nil( aGraph ) ) {
246       aGraph->destroy() ;
247     }
248   }
249   else {
250     SUPERV::Graph_var aGraph = DataFlowEditor()->Graph()->MacroObject() ;
251     GNode_Impl::Delete() ;
252     if ( !CORBA::is_nil( aGraph ) ) {
253       aGraph->destroy() ;
254     }
255   }
256   _poa->deactivate_object(*_id) ;
257 //  CORBA::release(_poa) ;
258   delete(_id) ;
259 //  _thisObj->_remove_ref();
260   endService( "Graph_Impl::destroy" );
261 }
262
263
264 char* Graph_Impl::getIOR() {
265   if ( IsMacro() ) {
266     return CORBA::string_dup( NULLSTRING ) ;
267   }
268   else if ( CORBA::is_nil( myServant ) ) {
269     PortableServer::ObjectId* id = getId();
270     CORBA::Object_var obj;
271     obj = _poa->id_to_reference(*id);
272     myServant = SUPERV::Graph::_narrow(obj);
273   }
274   return(CORBA::string_dup(_Orb->object_to_string(myServant)));
275 }
276
277 SUPERV::Graph_ptr Graph_Impl::Copy() {
278   beginService( "Graph_Impl::Copy" );
279   SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
280   if ( !IsMacro() ) {
281     Graph_Impl * myGraph ;
282     myGraph = new Graph_Impl( _Orb , _Poa, _ContId,
283                               instanceName() , interfaceName() ,
284                               DataFlowEditor()->Graph()->Name() , SUPERV::DataFlowGraph ) ;
285     PortableServer::ObjectId * id = myGraph->getId() ;
286     CORBA::Object_var obj = _poa->id_to_reference(*id);
287     iobject = SUPERV::Graph::_narrow(obj) ;
288     GraphBase::ListOfSGraphs * aListOfSGraphs = GetGraphs() ;
289     myGraph->LoadGraphs( aListOfSGraphs ) ;
290   }
291   endService( "Graph_Impl::Copy" );
292   return SUPERV::Graph::_duplicate(iobject) ;
293 }
294
295 void Graph_Impl::ReadOnly() {
296   DataFlowEditor()->ReadOnly() ;
297 }
298
299 SUPERV::INode_ptr Graph_Impl::Node() {
300 //  beginService( "Graph_Impl::Node" );
301   PortableServer::ObjectId * id = getId() ;
302   CORBA::Object_var obj = _poa->id_to_reference(*id);
303   SUPERV::Graph_var iobject ;
304   iobject = SUPERV::Graph::_narrow(obj) ;
305 //  endService( "Graph_Impl::Node" );
306   return SUPERV::Graph::_duplicate(iobject) ;
307 }
308
309 GraphBase::ListOfSGraphs * Graph_Impl::GetGraphs() {
310   return DataFlowEditor()->GetDataFlows() ;
311 }
312
313 bool Graph_Impl::LoadGraphs( GraphBase::ListOfSGraphs * aListOfDataFlows ) {
314   beginService( "Graph_Impl::LoadGraphs" );
315   bool RetVal = false ;
316   if ( DataFlowEditor()->IsEditing() ) {
317 //    RetVal = DataFlowEditor()->LoadDataFlows( aListOfDataFlows ) ;
318     if ( CORBA::is_nil( LoadDataFlows( DataFlowEditor() , aListOfDataFlows , 0 ) ) ) {
319       RetVal = false ;
320     }
321   }
322   endService( "Graph_Impl::LoadGraphs" );
323   return RetVal ;
324 }
325
326 bool Graph_Impl::Import(const char * aXmlFile ) {
327   beginService( "Graph_Impl::Import" );
328   bool RetVal = false ;
329   if ( DataFlowEditor()->IsEditing() && !IsMacro() ) {
330     GraphBase::ListOfSGraphs aListOfDataFlows ;
331     RetVal = DataFlowEditor()->LoadXml( aXmlFile , aListOfDataFlows ) ;
332     if ( RetVal && aXmlFile != NULL ) {
333 //      RetVal = DataFlowEditor()->LoadDataFlows( &aListOfDataFlows ) ;
334       if ( CORBA::is_nil( LoadDataFlows( DataFlowEditor() , &aListOfDataFlows , 0 ) ) ) {
335         RetVal = false ;
336       }
337     }
338   }
339   endService( "Graph_Impl::Import" );
340   return RetVal ;
341 }
342
343 bool Graph_Impl::Export(const char * anXmlFile ) {
344   beginService( "Graph_Impl::Export" );
345   bool RetVal = false ;
346   if ( !IsMacro() ) {
347     char * aFile = new char [ strlen( anXmlFile ) + 5 ] ;
348     strcpy( aFile , anXmlFile ) ;
349     int len = strlen( aFile ) ;
350     if ( !strcmp( &aFile[ len - 4 ] , ".xml" ) ) {
351     }
352     else if ( !strcmp( &aFile[ len - 3 ] , ".py" ) ) {
353       strcpy( &aFile[ len - 3 ] , ".xml" ) ;
354       len = strlen( aFile ) ;
355     }
356     else {
357       strcat( aFile , ".xml" ) ;
358       len = strlen( aFile ) ;
359     }
360     RetVal = DataFlowEditor()->SaveXml( aFile ) ;
361     if ( RetVal ) {
362       strcpy( &aFile[ len - 4 ] , ".py" ) ;
363       RetVal = DataFlowEditor()->SavePy( aFile ) ;
364     }
365     delete [] aFile ;
366   }
367   endService( "Graph_Impl::Export" );
368   return RetVal ;
369 }
370
371 char *  Graph_Impl::SavePY( bool importSuperV ) {
372   beginService( "Graph_Impl::SavePY" );
373   ostringstream fstring ;
374   bool RetVal ;
375   RetVal = DataFlowEditor()->SavePY( fstring , importSuperV ) ;
376   fstring  << ends ;
377   endService( "Graph_Impl::SavePY" );
378   return CORBA::string_dup( fstring.str().c_str() );
379 }
380 SUPERV::CNode_ptr Graph_Impl::CNode( const SALOME_ModuleCatalog::Service &NodeService ) {
381   beginService( "Graph_Impl::CNode" );
382   SUPERV::CNode_var iobject = SUPERV::CNode::_nil() ;
383   if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() && !IsMacro() ) {
384     CNode_Impl * myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
385                                           instanceName() , interfaceName() ,
386                                           DataFlowEditor() ,
387                                           NodeService , NULLSTRING ,
388                                           SUPERV::ComputingNode , NULLSTRING ) ;
389     if ( myNode->DataFlowNode() ) {
390       PortableServer::ObjectId * id = myNode->getId() ;
391       CORBA::Object_var obj = _poa->id_to_reference(*id);
392       iobject = SUPERV::CNode::_narrow(obj) ;
393       myNode->SetObjRef( SUPERV::CNode::_duplicate( iobject ) ) ;
394     }
395   }
396   DataFlowEditor()->UnValid() ;
397   endService( "Graph_Impl::CNode" );
398   return SUPERV::CNode::_duplicate( iobject ) ;
399 }
400
401 SUPERV::FNode_ptr Graph_Impl::FNode( const char * NodeComponentName ,
402                                      const char * NodeInterfaceName ,
403                                      const SALOME_ModuleCatalog::Service &NodeService ,
404                                      const SALOME_ModuleCatalog::ImplType ImplType ) {
405   beginService( "Graph_Impl::FNode" );
406   SUPERV::FNode_var iobject = SUPERV::FNode::_nil() ;
407   bool isCimpl = true;
408   switch (ImplType)
409   {
410   case SALOME_ModuleCatalog::PY:
411     isCimpl = false;
412     break;
413   case SALOME_ModuleCatalog::SO:
414   case SALOME_ModuleCatalog::EXE:
415   default:
416     ;
417   }
418   if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() && !IsMacro() ) {
419     FNode_Impl * myNode = new FNode_Impl( _Orb , _Poa , _ContId ,
420                                           instanceName() , interfaceName() ,
421                                           DataFlowEditor() ,
422                                           NodeService ,
423                                           NodeComponentName ,
424                                           NodeInterfaceName ,
425                                           NULLSTRING ,
426                                           SUPERV::FactoryNode ,
427                                           isCimpl ) ;
428     if ( myNode->DataFlowNode() ) {
429       PortableServer::ObjectId * id = myNode->getId() ;
430       CORBA::Object_var obj = _poa->id_to_reference(*id);
431       iobject = SUPERV::FNode::_narrow(obj) ;
432       myNode->SetObjRef( SUPERV::FNode::_duplicate( iobject ) ) ;
433     }
434   }
435   DataFlowEditor()->UnValid() ;
436   endService( "Graph_Impl::FNode" );
437   return SUPERV::FNode::_duplicate( iobject ) ;
438 }
439
440 SUPERV::INode_ptr Graph_Impl::INode( const char * FuncName ,
441                                      const SUPERV::ListOfStrings & PythonFuntion ) {
442   beginService( "Graph_Impl::INode" );
443   SUPERV::INode_var iobject = SUPERV::INode::_nil() ;
444   if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() && !IsMacro() ) {
445     INode_Impl * myNode = new INode_Impl( _Orb , _Poa , _ContId ,
446                                           instanceName() , interfaceName() ,
447                                           DataFlowEditor() ,
448                                           FuncName , PythonFuntion ,
449                                           SUPERV::InLineNode ) ;
450     if ( myNode->DataFlowNode() ) {
451       PortableServer::ObjectId * id = myNode->getId() ;
452       CORBA::Object_var obj = _poa->id_to_reference(*id);
453       iobject = SUPERV::INode::_narrow(obj) ;
454       myNode->SetObjRef( SUPERV::INode::_duplicate( iobject ) ) ;
455     }
456   }
457   endService( "Graph_Impl::INode" );
458   return SUPERV::INode::_duplicate( iobject ) ;
459 }
460
461
462 SUPERV::GNode_ptr Graph_Impl::GNode( const char * FuncName ,
463                                      const SUPERV::ListOfStrings & PythonFuntion ,
464                                      const char * anInLineNode ) {
465   beginService( "Graph_Impl::GNode" );
466   SUPERV::GNode_var iobject = SUPERV::GNode::_nil() ;
467   if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() && !IsMacro() ) {
468     GNode_Impl * myNode = new GNode_Impl( _Orb , _Poa , _ContId ,
469                                           instanceName() , interfaceName() ,
470                                           DataFlowEditor() ,
471                                           FuncName , PythonFuntion ,
472                                           SUPERV::GOTONode ) ;
473     if ( myNode->DataFlowNode() ) {
474       PortableServer::ObjectId * id = myNode->getId() ;
475       CORBA::Object_var obj = _poa->id_to_reference(*id);
476       iobject = SUPERV::GNode::_narrow(obj) ;
477       myNode->SetObjRef( SUPERV::GNode::_duplicate( iobject ) ) ;
478       if ( strlen( anInLineNode ) ) {
479         GraphBase::InLineNode * CoupledINode = (GraphBase::InLineNode * ) DataFlowEditor()->Graph()->GetGraphNode( anInLineNode ) ;
480         if ( anInLineNode ) {
481           myNode->SetCoupled( anInLineNode ) ;
482           Link( myNode->Port( "OutGate" ) , CoupledINode->ObjRef()->Port( "InGate" ) ) ;
483         }
484       }
485     }
486   }
487   DataFlowEditor()->UnValid() ;
488   endService( "Graph_Impl::GNode" );
489   return SUPERV::GNode::_duplicate( iobject ) ;
490 }
491
492 SUPERV::LNode_ptr Graph_Impl::LNode( const char * InitName ,
493                                      const SUPERV::ListOfStrings & InitFunction ,
494                                      const char * MoreName ,
495                                      const SUPERV::ListOfStrings & MoreFunction ,
496                                      const char * NextName ,
497                                      const SUPERV::ListOfStrings & NextFunction ,
498                                      SUPERV::INode_out anEndOfLoop ) {
499   beginService( "Graph_Impl::LNode" );
500   SUPERV::LNode_var iobject = SUPERV::LNode::_nil() ;
501   SUPERV::ELNode_var iendobject = SUPERV::ELNode::_nil() ;
502   if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() && !IsMacro() ) {
503     GraphBase::ListOfFuncName FuncNameList ;
504     FuncNameList.resize(3) ;
505     FuncNameList[0] = InitName ;
506     FuncNameList[1] = MoreName ;
507     FuncNameList[2] = NextName ;
508     GraphBase::ListOfPythonFunctions PythonFunctionList ;
509     PythonFunctionList.resize(3) ;
510     PythonFunctionList[0] = &InitFunction ;
511     PythonFunctionList[1] = &MoreFunction ;
512     PythonFunctionList[2] = &NextFunction ;
513     LNode_Impl * myNode = new LNode_Impl( _Orb , _Poa , _ContId ,
514                                           instanceName() , interfaceName() ,
515                                           DataFlowEditor() ,
516                                           FuncNameList , PythonFunctionList ,
517 //                                          InitName , InitFunction ,
518 //                                          MoreName , MoreFunction ,
519 //                                          NextName , NextFunction ,
520                                           SUPERV::LoopNode ) ;
521     if ( myNode->DataFlowNode() ) {
522       PortableServer::ObjectId * id = myNode->getId() ;
523       CORBA::Object_var obj = _poa->id_to_reference(*id);
524       iobject = SUPERV::LNode::_narrow(obj) ;
525       myNode->SetObjRef( SUPERV::LNode::_duplicate( iobject ) ) ;
526
527       SALOME_ModuleCatalog::Service aVoidService = SALOME_ModuleCatalog::Service() ;
528       char * anEndName ;
529       if ( strlen( InitName ) ) {
530         anEndName = new char[ 3 + strlen( InitName ) + 1 ];
531         strcpy( anEndName , "End" ) ;
532         strcat( anEndName , InitName ) ;
533       }
534       else {
535         anEndName = new char[ 3 + strlen( "Loop" ) + 1 ];
536         strcpy( anEndName , "EndLoop" ) ;
537       }
538       ELNode_Impl * myEndNode = new ELNode_Impl( _Orb , _Poa , _ContId ,
539                                                  instanceName() , interfaceName() ,
540                                                  DataFlowEditor() ,
541                                                  anEndName ,
542                                                  SUPERV::EndLoopNode ) ;
543       PortableServer::ObjectId * endid = myEndNode->getId() ;
544       CORBA::Object_var endobj = _poa->id_to_reference(*endid);
545       iendobject = SUPERV::ELNode::_narrow(endobj) ;
546       myEndNode->SetObjRef( SUPERV::ELNode::_duplicate( iendobject ) ) ;
547       myNode->SetCoupled( myEndNode->BaseNode()->Name() ) ;
548       myEndNode->SetCoupled( myNode->BaseNode()->Name() ) ;
549 //JR 25.01.2005  That links are already done in SetCoupled above ...
550 //      Link( myNode->Port( "DoLoop" ) , myEndNode->Port( "DoLoop" ) ) ;
551 //      Link( myEndNode->Port( "DoLoop" ) , myNode->Port( "InitLoop" ) ) ;
552 //      Link( myEndNode->Port( "DoLoop" ) , myNode->Port( "DoLoop" ) ) ;
553     }
554   }
555   anEndOfLoop = SUPERV::ELNode::_duplicate( iendobject ) ;
556   DataFlowEditor()->UnValid() ;
557   endService( "Graph_Impl::LNode" );
558   return SUPERV::LNode::_duplicate( iobject ) ;
559 }
560
561 SUPERV::SNode_ptr Graph_Impl::SNode( const char * FuncName ,
562                                      const SUPERV::ListOfStrings & PythonFunction ,
563                                      SUPERV::INode_out anEndOfSwitch ) {
564   beginService( "Graph_Impl::SNode" );
565   SUPERV::SNode_var iobject = SUPERV::SNode::_nil() ;
566   SUPERV::ESNode_var iendobject = SUPERV::ESNode::_nil() ;
567   if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() && !IsMacro() ) {
568     SNode_Impl * myNode = new SNode_Impl( _Orb , _Poa , _ContId ,
569                                           instanceName() , interfaceName() ,
570                                           DataFlowEditor() ,
571                                           FuncName , PythonFunction ,
572                                           SUPERV::SwitchNode ) ;
573     if ( myNode->DataFlowNode() ) {
574       PortableServer::ObjectId * id = myNode->getId() ;
575       CORBA::Object_var obj = _poa->id_to_reference(*id);
576       iobject = SUPERV::SNode::_narrow(obj) ;
577       myNode->SetObjRef( SUPERV::SNode::_duplicate( iobject ) ) ;
578
579       string anEndName = "End" ;
580       if ( strlen( FuncName ) ) {
581         anEndName += FuncName ;
582       }
583       else {
584         anEndName += "Switch" ;
585       }
586 //      cout << "Graph_Impl::SNode anEndName " << (void *) FuncName << " " << FuncName
587 //           << " " << strlen(FuncName) << " " << (void *) anEndName.c_str() << " "
588 //           << anEndName.c_str() << endl ;
589       ESNode_Impl * myEndNode = new ESNode_Impl( _Orb , _Poa , _ContId ,
590                                                instanceName() , interfaceName() ,
591                                                DataFlowEditor() ,
592                                                anEndName.c_str() ,
593                                                SUPERV::EndSwitchNode ) ;
594 //      cout << "Graph_Impl::SNode returned anEndName " << (void *) FuncName << " "
595 //           << FuncName << " " << strlen(FuncName) << " " << (void *) anEndName.c_str()
596 //           << " " << anEndName.c_str() << endl ;
597       PortableServer::ObjectId * endid = myEndNode->getId() ;
598       CORBA::Object_var endobj = _poa->id_to_reference(*endid);
599       iendobject = SUPERV::ESNode::_narrow(endobj) ;
600       myEndNode->SetObjRef( SUPERV::ESNode::_duplicate( iendobject ) ) ;
601       myNode->SetCoupled( myEndNode->BaseNode()->Name() ) ;
602       myEndNode->SetCoupled( myNode->BaseNode()->Name() ) ;
603 //JR NPAL14793 05.02.2007 : do not add that link
604 //      if ( !Link( myNode->Port( "Default" ) , myEndNode->Port( "Default" ) ) ) {
605 //        iobject = SUPERV::SNode::_nil() ;
606 //        iendobject = SUPERV::ESNode::_nil() ;
607 //      }
608     }
609   }
610   anEndOfSwitch = SUPERV::ESNode::_duplicate( iendobject ) ;
611   DataFlowEditor()->UnValid() ;
612   endService( "Graph_Impl::SNode" );
613   return SUPERV::SNode::_duplicate( iobject ) ;
614 }
615
616 // WARNING : THIS IS COMPLICATED :
617 SUPERV::Graph_var Graph_Impl::LoadDataFlows( GraphEditor::DataFlow * aDataFlowEditor ,
618                                              GraphBase::ListOfSGraphs * aListOfDataFlows ,
619                                              int index ) {
620   beginService( "Graph_Impl::EditorLoadDataFlows" ) ;
621   MESSAGE("Graph_Impl::LoadDataFlows index " << index << " " << (*aListOfDataFlows)[index].Info.theName.c_str() ) ;
622
623   SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
624 // That method is recursive :
625 // At first we load the supergraph with index = 0 :
626 // (After we load the graph corresponding to each MacroNode :)
627   if ( !aDataFlowEditor->LoadDataFlow( &(*aListOfDataFlows)[ index ] ) ) {
628     MESSAGE("Graph_Impl::LoadDataFlows failed " << (*aListOfDataFlows)[index].Info.theName.c_str() ) ;
629     return SUPERV::Graph::_duplicate( iobject ) ;
630   }
631 // That graph is not a StreamGraph :
632   else if ( !aDataFlowEditor->Graph()->HasDataStream() ) {
633     aDataFlowEditor->Graph()->Kind( SUPERV::DataFlowGraph ) ;
634 //    aDataFlowEditor->Graph()->SetGraphEditor( aDataFlowEditor ) ;
635     Graph_Impl * myGraph ;
636 // We create a Graph ObjRef for that graph
637     myGraph = new Graph_Impl( _Orb , _Poa, _ContId,
638                               instanceName() , interfaceName() ,
639                               aDataFlowEditor , NULL ) ;
640     PortableServer::ObjectId * id = myGraph->getId() ;
641     CORBA::Object_var obj = _poa->id_to_reference(*id) ;
642     iobject = SUPERV::Graph::_narrow( obj ) ;
643     myGraph->SetObjRef( SUPERV::Graph::_duplicate( iobject ) ) ;
644     myGraph->SetObjImpl( (CNode_Impl * ) myGraph ) ;
645     GraphBase::Graph * aGraph = myGraph->DataFlowEditor()->Graph() ;
646     int i ;
647
648 // asv: set Editor for the graph itself and for all its macro nodes
649     aGraph->GraphEditor( aDataFlowEditor );
650
651 // For the supergraph or each graph of MacroNodes we search MacroNodes recursively :
652     for ( i = 0 ; i < aGraph->GraphNodesSize() ; i++ ) {
653       if ( aGraph->GraphNodes( i )->IsMacroNode() ) {
654         GraphBase::GOTONode * aMacroNode = (GraphBase::GOTONode * ) aGraph->GraphNodes( i ) ;
655
656         // asv : 05.11.04 : fix of bug - "insert file" into existing graph with MacroNodes worked incorrectly!
657         // aMacroNode is an "old" node, and here we must analize only "new" nodes, that
658         // came from aListOfDataFlows and were loaded by aDataFlowEditor->LoadDataFlow( &(*aListOfDataFlows)[ index ] )
659         // so here we check if the node is "new" or "old"
660         if ( aMacroNode->GraphEditor() && aMacroNode->CoupledNode() )
661           continue;
662
663         // asv: set Editor for the graph itself and for all its macro nodes
664         aMacroNode->GraphEditor( aDataFlowEditor );
665
666         // Creation of a GraphMacroNode ObjRef in the current editor
667         SUPERV::Graph_var macroiobject = SUPERV::Graph::_nil() ;
668         Graph_Impl * myMacroNode ;
669         myMacroNode = new Graph_Impl( _Orb , _Poa, _ContId,
670                                       instanceName() , interfaceName() ,
671                                       aMacroNode->Name() , SUPERV::MacroNode ) ;
672         id = myMacroNode->getId() ;
673         obj = _poa->id_to_reference(*id);
674         macroiobject = SUPERV::Graph::_narrow( obj ) ;
675         myMacroNode->DataFlowEditor( aDataFlowEditor ) ;
676         GraphEditor::InNode * aDataFlowNode = (GraphEditor::InNode * ) aMacroNode->GetInNode() ;
677         myMacroNode->DataFlowNode( aDataFlowNode ) ;
678         aDataFlowNode->SetObjRef( SUPERV::CNode::_duplicate( SUPERV::CNode::_narrow( obj ) ) ) ;
679         aDataFlowNode->SetObjImpl( myMacroNode ) ;
680
681         char * aCoupledNodeName = aMacroNode->CoupledNodeName() ;
682         MESSAGE( "LoadDataFlows MacroNode " << aMacroNode->Name() << " --> " << aCoupledNodeName
683                  << " to be searched among " << (*aListOfDataFlows).size() << " Graphs" ) ;
684         int index ;
685         bool found = false ;
686         for ( index = 0 ; index < (int ) (*aListOfDataFlows).size() ; index++ ) {
687           MESSAGE( "LoadDataFlows Graph" << index << " " << (*aListOfDataFlows)[index].Info.theName.c_str() ) ;
688           if ( !strcmp( aCoupledNodeName , (*aListOfDataFlows)[index].Info.theName.c_str() ) ) {
689             found = true ;
690             string dbgfile ;
691 // At first create the editor and a StreamGraph
692             GraphEditor::DataFlow * aMacroGraphDataFlowEditor ;
693             CreateEditor( _Orb , instanceName() , aCoupledNodeName , SUPERV::DataStreamGraph ,
694                           dbgfile , &aMacroGraphDataFlowEditor ) ;
695
696             if ( _DebugFileName ) {
697               delete [] _DebugFileName ;
698             }
699             _DebugFileName = new char[ strlen( dbgfile.c_str() )+1 ] ;
700             strcpy( _DebugFileName , dbgfile.c_str() ) ;
701
702             MESSAGE( "RECURSIVE IMPORT OF GRAPHS OF MACRONODES :" << aCoupledNodeName ) ;
703             if ( CORBA::is_nil( LoadDataFlows( aMacroGraphDataFlowEditor , aListOfDataFlows , index ) ) ) {
704               MESSAGE("Graph_Impl::LoadDataFlows failed" ) ;
705               return SUPERV::Graph::_duplicate( iobject ) ;
706             }
707
708 // That graph is not a StreamGraph :
709             else if ( !aMacroGraphDataFlowEditor->Graph()->HasDataStream() ) {
710               Graph_Impl * myMacroGraph ;
711 // The Graph ObjRef for that graph was already created
712               myMacroGraph = (Graph_Impl * ) aMacroGraphDataFlowEditor->Graph()->ObjImpl() ;
713
714               GraphBase::Graph * aMacroGraph = myMacroGraph->DataFlowEditor()->Graph() ;
715               
716               aMacroGraph->GraphMacroLevel( aGraph->GraphMacroLevel() + 1 ) ;
717               aMacroGraph->CoupledNode( aMacroNode ) ;
718               aMacroGraph->MacroObject( SUPERV::Graph::_duplicate( macroiobject ) ) ;
719
720 // Set the GraphMacroNode ObjRef in the MacroNode
721               aMacroNode->GraphMacroLevel( aGraph->GraphMacroLevel() + 1 ) ;
722               aMacroNode->CoupledNode( aMacroGraph ) ;
723               aMacroNode->MacroObject( SUPERV::Graph::_narrow( aMacroGraphDataFlowEditor->Graph()->ObjRef() ) ) ;
724               MESSAGE( "LoadDataFlows aMacroGraph " << aMacroGraph << " " << aMacroGraph->Name()
725                        << " coupled to " << aMacroGraph->CoupledNode() << " "
726                        << aMacroGraph->CoupledNode()->Name() << " Editor " << aMacroGraph->GraphEditor() ) ;
727               MESSAGE( "LoadDataFlows aMacroNode " << aMacroNode << " " << aMacroNode->Name()
728                        << " coupled to " << aMacroNode->CoupledNode() << " "
729                        << aMacroNode->CoupledNode()->Name() << " Editor " << aMacroNode->GraphEditor() ) ;
730               MESSAGE( "LoadDataFlows current Graph " << aGraph << " " << aGraph->Name()
731                        << " coupled to " << aGraph->CoupledNode()
732                        << " Editor " << aGraph->GraphEditor() << " " << aGraph->Name() ) ;
733             }
734             break ;
735           }
736         }
737         if ( !found ) {
738           return SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
739         }
740       }
741     }
742   }
743   else if ( (*aListOfDataFlows).size() == 1 ) {
744     StreamGraph_Impl * myStreamGraph ;
745 // We create a Graph ObjRef for that graph
746     myStreamGraph = new StreamGraph_Impl( _Orb , _Poa, _ContId,
747                                           instanceName() , interfaceName() ,
748                                           aDataFlowEditor , NULL ) ;
749     PortableServer::ObjectId * id = myStreamGraph->getId() ;
750     CORBA::Object_var obj = _poa->id_to_reference(*id) ;
751     SUPERV::StreamGraph_var Streamiobject = SUPERV::StreamGraph::_nil() ;
752     Streamiobject = SUPERV::StreamGraph::_narrow( obj ) ;
753     myStreamGraph->SetObjRef( SUPERV::StreamGraph::_duplicate( Streamiobject ) ) ;
754     myStreamGraph->SetObjImpl( (CNode_Impl * ) myStreamGraph ) ;
755 //    iobject = SUPERV::Graph::_narrow( obj ) ;
756     iobject = SUPERV::Graph::_narrow( Streamiobject ) ;
757   }
758   else {
759     MESSAGE( "Graph_Impl::LoadDataFlows StreamGraph with MacroNodes not yet implemented" ) ;
760   }
761
762   endService( "Graph_Impl::EditorLoadDataFlows" );
763   return SUPERV::Graph::_duplicate( iobject ) ;
764 }
765
766 SUPERV::Graph_var Graph_Impl::LoadDataFlows( GraphExecutor::DataFlow * aDataFlowExecutor ,
767                                              GraphBase::ListOfSGraphs * aListOfDataFlows ,
768                                              int index ) {
769   beginService( "Graph_Impl::ExecutorLoadDataFlows" ) ;
770   MESSAGE("Graph_Impl::LoadDataFlows(Executor) index " << index << " " << (*aListOfDataFlows)[index].Info.theName.c_str() << " aDataFlowExecutor " << aDataFlowExecutor ) ;
771
772   // That method is recursive :
773   // At first we load the supergraph with index = 0 :
774   // (After we load the graph corresponding to each MacroNode :)
775   if ( !aDataFlowExecutor->LoadDataFlow( &(*aListOfDataFlows)[ index ] ) ) {
776     MESSAGE("Graph_Impl::LoadDataFlows(Executor) failed, could not LoadDataFlow(supergraph)" ) ;
777     return SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
778   }
779
780   // That graph is not a StreamGraph :
781   else {
782     aDataFlowExecutor->Graph()->Kind( SUPERV::DataFlowGraph ) ;
783     GraphEditor::DataFlow * aDataFlowEditor ;
784     aDataFlowEditor = DataFlowEditor() ;
785     GraphBase::Graph * anEditorGraph = aDataFlowEditor->Graph() ;
786     GraphBase::Graph * anExecutorGraph = aDataFlowExecutor->Graph() ;
787     if ( aDataFlowEditor->Executor() ) {
788       delete aDataFlowEditor->Executor() ;
789       aDataFlowEditor->Executor( NULL ) ;
790       aDataFlowEditor->Editing() ;
791     }
792     aDataFlowEditor->Executor( aDataFlowExecutor ) ;
793     anExecutorGraph->GraphEditor( aDataFlowEditor ) ;
794
795     if ( !aDataFlowExecutor->Graph()->HasDataStream() ) {
796     // For the supergraph or each graph of MacroNodes we search MacroNodes recursively :
797       int i;
798       for ( i = 0 ; i < anExecutorGraph->GraphNodesSize() ; i++ ) {
799         if ( anExecutorGraph->GraphNodes( i )->IsMacroNode() ) {
800           GraphBase::GOTONode * aMacroNode = (GraphBase::GOTONode * ) anExecutorGraph->GraphNodes( i ) ;
801           aMacroNode->GraphEditor( aDataFlowEditor ) ;
802
803         // get the macro node's editor object
804           char * aMacroGraphName = aMacroNode->CoupledNodeName() ;
805           GraphBase::Graph* aMacroGraph =  (GraphBase::Graph*)((GraphBase::GOTONode *)anEditorGraph->GetGraphNode( aMacroNode->Name() ))->CoupledNode() ;
806         GraphEditor::DataFlow* aMacroGraphEditor = aMacroGraph->GraphEditor();
807
808           MESSAGE( "LoadDataFlows(Executor) MacroNode " << aMacroNode->Name() << " Coupled to " << aMacroGraphName
809                    << " to be searched among " << (*aListOfDataFlows).size() << " Graphs" << endl ) ;
810           int index;
811           bool found = false ;
812           for ( index = 0 ; index < (int ) (*aListOfDataFlows).size() && !found; index++ ) {
813             if ( !strcmp( aMacroGraphName , (*aListOfDataFlows)[index].Info.theName.c_str() ) )
814               found = true;
815           }
816           if ( !found ) {
817             MESSAGE("Graph_Impl::LoadDataFlows(Executor) failed, Macro node's coupled graph \"" << aMacroGraphName << "\" was not found" ) ;
818             return SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
819           }
820           index--; // it was incremented in "for ..." before last check ( !found ).
821         
822         // At first create the editor and a StreamGraph
823           string dbgfile ;
824           GraphExecutor::DataFlow * aMacroGraphExecutor ;
825           CreateExecutor( _Orb , instanceName() , aMacroGraphName , SUPERV::DataStreamGraph ,
826                         dbgfile , &aMacroGraphExecutor );
827           theAutomaton->Executed() ; // Decrement _GraphExecutingNumber for MacroSubGraph
828
829         // set GraphMacroLevel for Executor's graph
830           GraphBase::Graph* aMacroGraphExe = aMacroGraphExecutor->Graph();
831             aMacroGraphExe->GraphMacroLevel( anExecutorGraph->GraphMacroLevel() + 1 );
832
833         // load data flows in MacroGraph's executor
834           Graph_Impl* aMacroGraphImpl = (Graph_Impl*) aMacroGraphEditor->Graph()->ObjImpl();
835           MESSAGE( "RECURSIVE IMPORT OF GRAPHS OF MACRONODES : " << aMacroGraphName ) ;
836           if ( CORBA::is_nil( aMacroGraphImpl->LoadDataFlows( aMacroGraphExecutor, aListOfDataFlows , index ) ) ) {
837             MESSAGE("Graph_Impl::LoadDataFlows(Executor) failed,  could not LoadDataFlow( MacroNodeGraph \"" <<aMacroGraphName << "\" )" ) ;
838             return SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
839           }
840           
841           // set coupled pair MacroNode <--> MacroGraph
842           aMacroGraphExe->CoupledNode( aMacroNode ) ;
843           aMacroNode->CoupledNode( aMacroGraphExe ) ;
844
845 //JR 04.05.2005 Debug : InPorts values of MacroNodes are like for other nodes
846 //                      InPorts values of MacroGraphs of MacroNodes are done in the Executor
847 // It was probably to try to debug anything but it was a wrong debug and I do not know what bug
848 // ===> folowing code is commented
849 #if 0
850           // initialize MacroNode's InPorts with corresponding "external" values
851           int q ;
852           for ( q = 0 ; q < aMacroNode->GetNodeInPortsSize() ; q++ ) {
853             const GraphBase::InPort * anInPort = aMacroNode->GetNodeInPort( q ) ;
854             if ( anInPort->IsDataConnected() ) {
855               const char* aMacroGraphInPortName = aMacroGraph->GetNodeInPort( q )->PortName();
856 //JR 30.03.2005       if ( !aMacroGraphExecutor->InputOfAny(  aMacroGraphInPortName, *anInPort->GetOutPort()->Value(),false ) ) {
857               if ( !aMacroGraphExecutor->InputOfAny(  aMacroGraphInPortName, anInPort->GetOutPort()->Value(),false ) ) {
858                 return SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
859               }
860               else {
861                 MESSAGE( "LoadDataFlows(Executor) " << aMacroGraph->Name() << "->InputOfAny( " 
862                          << aMacroGraphInPortName << " , Value )" ) ;
863               }
864             }
865           } // end of init MacroNode's InPorts
866 #endif
867           aMacroGraphImpl->Run() ;
868
869         }
870       } // end of for( get nodes of the graph...)
871     }
872   } // end of setting initial graph's structure..
873
874   endService( "Graph_Impl::ExecutorLoadDataFlows" );
875
876   PortableServer::ObjectId * id = getId();
877   CORBA::Object_var obj = _poa->id_to_reference( *id );
878   SUPERV::Graph_var iobject = SUPERV::Graph::_narrow( obj ) ;
879   return SUPERV::Graph::_duplicate( iobject ) ;
880 }
881
882 SUPERV::Graph_ptr Graph_Impl::MNode( const char * aXmlFileName ) {
883   beginService( "Graph_Impl::MNode" );
884   SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
885   MESSAGE( "Graph_Impl::MNode( " << aXmlFileName << " )" ) ;
886   if ( !IsMacro() ) {
887     GraphBase::ListOfSGraphs aListOfDataFlows ;
888     string dbgfile ;
889 // At first create the editor and a StreamGraph with the xml file
890     GraphEditor::DataFlow * aDataFlowEditor ;
891     CreateEditor( _Orb , instanceName() , aXmlFileName , SUPERV::DataStreamGraph ,
892                   dbgfile , &aDataFlowEditor ) ;
893
894     if ( _DebugFileName ) {
895       delete [] _DebugFileName ;
896     }
897     _DebugFileName = new char[ strlen( dbgfile.c_str() )+1 ] ;
898     strcpy( _DebugFileName , dbgfile.c_str() ) ;
899
900     int lenname = strlen( aXmlFileName ) ;
901     bool loaded = false ;
902 // Import of the xml file
903     if ( lenname > 4 && !strcmp( &aXmlFileName[ lenname - 4 ] , ".xml" ) ) {
904       loaded = aDataFlowEditor->LoadXml( aXmlFileName , aListOfDataFlows ) ;
905       if ( loaded ) {
906         iobject = MNode( aDataFlowEditor , &aListOfDataFlows ) ;
907       }
908     }
909   }
910   return iobject ;
911 }
912
913 // WARNING : THIS IS COMPLICATED :
914 // I should have to remove duplicated code ...
915 SUPERV::Graph_ptr Graph_Impl::MNode( GraphEditor::DataFlow * aMacroGraphDataFlowEditor ,
916                                      GraphBase::ListOfSGraphs * aListOfDataFlows ) {
917   beginService( "Graph_Impl::MNode" ) ;
918   SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
919   SUPERV::Graph_var macroiobject = SUPERV::Graph::_nil() ;
920
921   if ( !IsMacro() ) {
922     MESSAGE( "Graph_Impl::MNode DataFlowEditor->LoadDataFlow" ) ;
923 //    if ( !aMacroGraphDataFlowEditor->LoadDataFlow( &aListOfDataFlows[ 0 ] ) ) {
924     iobject = LoadDataFlows( aMacroGraphDataFlowEditor , aListOfDataFlows , 0 ) ;
925     if ( CORBA::is_nil( iobject ) ) {
926       MESSAGE("Graph_Impl::MNode LoadDataFlow failed" ) ;
927       return false ;
928     }
929
930 // That graph is not a StreamGraph :
931     else if ( !aMacroGraphDataFlowEditor->Graph()->HasDataStream() ) {
932       aMacroGraphDataFlowEditor->Graph()->Kind( SUPERV::DataFlowGraph ) ;
933       aMacroGraphDataFlowEditor->Graph()->GraphEditor( aMacroGraphDataFlowEditor ) ;
934
935       Graph_Impl * myMacroGraph = (Graph_Impl * ) aMacroGraphDataFlowEditor->Graph()->ObjImpl() ;
936 // Creation of a GraphMacroNode in the current editor
937       string aMacroNodeName = string( "Macro_" ) + string( myMacroGraph->Name() ) ;
938       Graph_Impl * myMacroNode ;
939       myMacroNode = new Graph_Impl( _Orb , _Poa, _ContId,
940                                     instanceName() , interfaceName() ,
941                                     aMacroNodeName.c_str() , SUPERV::MacroNode ) ;
942       PortableServer::ObjectId * id = myMacroNode->getId() ;
943       CORBA::Object_var obj = _poa->id_to_reference(*id);
944       macroiobject = SUPERV::Graph::_narrow( obj ) ;
945       myMacroNode->DataFlowEditor( DataFlowEditor() ) ;
946
947 // Creation of the MacroNode itself in the current Graph
948       GraphBase::ListOfFuncName aFuncName ;
949       aFuncName.resize( 1 ) ;
950       aFuncName[0] = "" ;
951       SUPERV::ListOfStrings aListOfStrings ;
952       aListOfStrings.length( 1 ) ;
953       aListOfStrings[0] = "" ;
954       GraphBase::ListOfPythonFunctions aPythonFunction ;
955       aPythonFunction.resize( 1 ) ;
956       aPythonFunction[0] = &aListOfStrings ;
957       SALOME_ModuleCatalog::Service * aMacroNodeService = myMacroGraph->Service() ;
958       GraphEditor::InNode * aDataFlowNode = DataFlowEditor()->AddNode( *aMacroNodeService , "" , "" ,
959                                                                        aMacroNodeName.c_str() , SUPERV::MacroNode ,
960                                                                        aFuncName , aPythonFunction ) ;
961       aDataFlowNode->SetPythonFunction( "" , aListOfStrings ) ;
962       myMacroNode->DataFlowNode( aDataFlowNode ) ;
963       aDataFlowNode->ComputingNode()->SetService( *aMacroNodeService ) ;
964       aDataFlowNode->SetObjRef( SUPERV::CNode::_duplicate( SUPERV::CNode::_narrow( obj ) ) ) ;
965       aDataFlowNode->SetObjImpl( this ) ;
966
967       GraphBase::Graph * aGraph = myMacroGraph->DataFlowEditor()->Graph() ;
968       GraphBase::Graph * aGraphOfMacroGraph = myMacroNode->DataFlowEditor()->Graph() ;
969       GraphBase::Graph * aMacroGraph = myMacroNode->DataFlowNode()->GraphMacroNode() ;
970       aMacroGraph->Kind( SUPERV::MacroNode ) ;
971       aMacroGraph->GraphEditor( DataFlowEditor() ) ;
972 // Creation of the Ports of the MacroNode from the ports of the GraphMacroNode
973       aMacroGraph->SetMacroPorts( aGraph ) ;
974 // Valid ==> creation of Service and the ports of the current Graph
975       DataFlowEditor()->IsValid() ;
976 // Set the Input Datas from the GraphMacroNode to the current Graph
977       aMacroGraph->SetMacroDatas( aGraph , aGraphOfMacroGraph ) ;
978       aMacroGraphDataFlowEditor->UnValid() ;
979 // Set the MacroNode ObjRef in the GraphMacroNode
980       aGraph->CoupledNode( aMacroGraph ) ;
981       aGraph->MacroObject( SUPERV::Graph::_duplicate( macroiobject ) ) ;
982 // Set the GraphMacroNode ObjRef in the MacroNode
983       aDataFlowNode->GraphMacroNode()->GraphMacroLevel( aGraphOfMacroGraph->GraphMacroLevel() + 1 ) ;
984       aMacroGraph->CoupledNode( aGraph ) ;
985 //      aGraphOfMacroGraph->CoupledNode( aGraph ) ;
986       aMacroGraph->MacroObject( SUPERV::Graph::_duplicate( iobject ) ) ;
987 //      aGraphOfMacroGraph->MacroObject( SUPERV::Graph::_duplicate( iobject ) ) ;
988 //    aDataFlowNode->CoupledNode( aGraph ) ;
989 //    aDataFlowNode->ComputingNode()->MacroObject( SUPERV::Graph::_duplicate( iobject ) ) ;
990 // Set the MacroLevel of that graph
991       aGraph->GraphMacroLevel( aGraphOfMacroGraph->GraphMacroLevel() + 1 ) ;
992       aMacroGraph->Coordinates( 0 , 0 ) ;
993       MESSAGE( "DataFlowNode Graph " << this << " DataFlowEditor " << DataFlowEditor() << " aDataFlowNode "
994                << aDataFlowNode << " " << aDataFlowNode->Name() << " created" ) ;
995       MESSAGE( "MNode aGraph " << aGraph << " " << aGraph->Name()
996                << " coupled to " << aGraph->CoupledNode() << " "
997                << aGraph->CoupledNode()->Name() ) ;
998       MESSAGE( "MNode aMacroGraph " << aMacroGraph << " " << aMacroGraph->Name()
999                << " coupled to " << aMacroGraph->CoupledNode() << " "
1000                << aMacroGraph->CoupledNode()->Name() ) ;
1001       MESSAGE( "MNode aMacroGraph " << myMacroNode->DataFlowEditor()->Graph() << " "
1002                << myMacroNode->DataFlowEditor()->Graph()->Name()
1003                << " coupled to " << myMacroNode->DataFlowEditor()->Graph()->CoupledNode() ) ;
1004     }
1005     else {
1006       delete aMacroGraphDataFlowEditor ;
1007     }
1008   }
1009   endService( "Graph_Impl::MNode" );
1010   return SUPERV::Graph::_duplicate( macroiobject ) ;
1011 }
1012
1013 // For python supergraph
1014 SUPERV::Graph_ptr Graph_Impl::GraphMNode( SUPERV::Graph_ptr myMacroGraph ) {
1015   SUPERV::Graph_var iobject = myMacroGraph ;
1016   beginService( "Graph_Impl::GraphMNode" ) ;
1017
1018 //  GraphBase::Graph * myMacroGraph = aGraph;
1019   SUPERV::Graph_var macroiobject = SUPERV::StreamGraph::_nil() ;
1020 // Creation of a GraphMacroNode in the current editor
1021   if ( !IsMacro() ) {
1022     string aMacroNodeName = string( "Macro_" ) + string( myMacroGraph->Name() ) ;
1023     //string aMacroNodeName = string( myMacroGraph->CoupledName() ) ;
1024     MESSAGE( "GraphMNode( " << myMacroGraph->Name() << " )" ) ;
1025     Graph_Impl * myMacroNode ;
1026     myMacroNode = new Graph_Impl( _Orb , _Poa, _ContId,
1027                                   instanceName() , interfaceName() ,
1028                                   aMacroNodeName.c_str() , SUPERV::MacroNode ) ;
1029     PortableServer::ObjectId * id = myMacroNode->getId() ;
1030     CORBA::Object_var obj = _poa->id_to_reference(*id);
1031     macroiobject = SUPERV::Graph::_narrow( obj ) ;
1032     myMacroNode->DataFlowEditor( DataFlowEditor() ) ;
1033
1034 // Creation of the MacroNode itself in the current Graph
1035     GraphBase::ListOfFuncName aFuncName ;
1036     aFuncName.resize( 1 ) ;
1037     aFuncName[0] = "" ;
1038     SUPERV::ListOfStrings aListOfStrings ;
1039     aListOfStrings.length( 1 ) ;
1040     aListOfStrings[0] = "" ;
1041     GraphBase::ListOfPythonFunctions aPythonFunction ;
1042     aPythonFunction.resize( 1 ) ;
1043     aPythonFunction[0] = &aListOfStrings ;
1044     SALOME_ModuleCatalog::Service * aMacroNodeService = myMacroGraph->Service() ;
1045     GraphEditor::InNode * aDataFlowNode ;
1046     aDataFlowNode = DataFlowEditor()->AddNode( *aMacroNodeService , "" , "" ,
1047                                                aMacroNodeName.c_str() , SUPERV::MacroNode ,
1048                                                aFuncName , aPythonFunction ) ;
1049     aDataFlowNode->SetPythonFunction( "" , aListOfStrings ) ;
1050     myMacroNode->DataFlowNode( aDataFlowNode ) ;
1051     aDataFlowNode->ComputingNode()->SetService( *aMacroNodeService ) ;
1052     aDataFlowNode->SetObjRef( SUPERV::CNode::_duplicate( SUPERV::CNode::_narrow( obj ) ) ) ;
1053     aDataFlowNode->SetObjImpl( this ) ;
1054
1055     GraphBase::Graph * aSubGraph = NULL ;
1056 //    GraphBase::Graph * aGraph = DataFlowEditor()->Automaton()->MapGraph( myMacroGraph->Name() ) ;
1057     //DataFlowEditor()->Automaton()->GraphBase( &aGraph ) ;
1058 //JR 20.09.2005 Debug SAB_data_1609_bugPAL.py from CEA (Anthony)
1059 //    Graph_Impl * aSubGraphImpl = dynamic_cast<Graph_Impl * >( _Poa->id_to_servant( *myMacroGraph->_Id ) ) ;
1060     myMacroGraph->ping() ;
1061     Graph_Impl * aSubGraphImpl = theAutomaton->GraphImpl() ;
1062     aSubGraph = aSubGraphImpl->DataFlowEditor()->Graph() ;
1063     myMacroGraph->Coupled() ;
1064     GraphBase::Graph * aGraphOfMacroGraph = myMacroNode->DataFlowEditor()->Graph() ;
1065     GraphBase::Graph * aMacroGraph = myMacroNode->DataFlowNode()->GraphMacroNode() ;
1066     aMacroGraph->Kind( SUPERV::MacroNode ) ;
1067     aMacroGraph->GraphEditor( DataFlowEditor() ) ;
1068 // Creation of the Ports of the MacroNode from the ports of the GraphMacroNode
1069     aMacroGraph->SetMacroPorts( aSubGraph ) ;
1070 // Valid ==> creation of Service and the ports of the current Graph
1071     DataFlowEditor()->IsValid() ;
1072 // Set the Input Datas from the GraphMacroNode to the current Graph
1073     aMacroGraph->SetMacroDatas( aSubGraph , aGraphOfMacroGraph ) ;
1074 //    aMacroGraphDataFlowEditor->UnValid() ;
1075     aSubGraph->GraphEditor()->UnValid() ;
1076 // Set the MacroNode ObjRef in the GraphMacroNode
1077     aSubGraph->CoupledNode( aMacroGraph ) ;
1078     aSubGraph->MacroObject( SUPERV::Graph::_duplicate( macroiobject ) ) ;
1079 // Set the GraphMacroNode ObjRef in the MacroNode
1080     aDataFlowNode->GraphMacroNode()->GraphMacroLevel( aGraphOfMacroGraph->GraphMacroLevel() + 1 ) ;
1081     aMacroGraph->CoupledNode( aSubGraph ) ;
1082     aMacroGraph->MacroObject( SUPERV::Graph::_duplicate( iobject ) ) ;
1083 //    aDataFlowNode->CoupledNode( aSubGraph ) ;
1084 //    aDataFlowNode->ComputingNode()->MacroObject( SUPERV::Graph::_duplicate( iobject ) ) ;
1085 // Set the MacroLevel of that graph
1086     aSubGraph->GraphMacroLevel( aGraphOfMacroGraph->GraphMacroLevel() + 1 ) ;
1087     aMacroGraph->Coordinates( 0 , 0 ) ;
1088     MESSAGE( aSubGraph->Name() << "->CoupledNode()->GraphEditor() : " << aSubGraph->CoupledNode()->GraphEditor() ) ;
1089     MESSAGE( aMacroGraph->Name() << "->CoupledNode()->GraphEditor() : "
1090              << aMacroGraph->CoupledNode()->GraphEditor() ) ;
1091     MESSAGE( "DataFlowNode Graph " << this << " DataFlowEditor " << DataFlowEditor() << " aDataFlowNode "
1092              << aDataFlowNode << " " << aDataFlowNode->Name() << " created" ) ;
1093   }
1094   endService( "Graph_Impl::GraphMNode" ) ;
1095   return SUPERV::Graph::_duplicate( macroiobject ) ;
1096 }
1097
1098 SUPERV::Graph_ptr Graph_Impl::FlowObjRef() {
1099   beginService( "Graph_Impl::FlowObjRef" );
1100   SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
1101   if ( IsMacro() ) {
1102     iobject = SUPERV::Graph::_narrow( DataFlowNode()->GraphMacroNode()->MacroObject() ) ;
1103   }
1104   else if ( IsGraph() ) {
1105     iobject = SUPERV::Graph::_narrow( DataFlowEditor()->Graph()->MacroObject() ) ;
1106   }
1107   if ( CORBA::is_nil( iobject ) ) {
1108     MESSAGE( "Graph_Impl::FlowObjRef() returns a NIL Object" ) ;
1109   }
1110   endService( "Graph_Impl::FlowObjRef" );
1111   return SUPERV::Graph::_duplicate( iobject ) ;
1112 }
1113
1114 SUPERV::StreamGraph_ptr Graph_Impl::StreamObjRef() {
1115   beginService( "Graph_Impl::StreamObjRef" );
1116   SUPERV::StreamGraph_var iobject = SUPERV::StreamGraph::_nil() ;
1117   if ( IsMacro() ) {
1118     iobject = SUPERV::StreamGraph::_narrow( DataFlowNode()->GraphMacroNode()->MacroObject() ) ;
1119   }
1120   else if ( IsGraph() || IsStreamGraph() ) {
1121     iobject = SUPERV::StreamGraph::_narrow( DataFlowEditor()->Graph()->MacroObject() ) ;
1122   }
1123   if ( CORBA::is_nil( iobject ) ) {
1124     MESSAGE( "Graph_Impl::StreamObjRef() returns a NIL Object" ) ;
1125   }
1126   endService( "Graph_Impl::StreamObjRef" );
1127   return SUPERV::StreamGraph::_duplicate( iobject ) ;
1128 }
1129
1130 SUPERV::CNode_ptr Graph_Impl::Node(char const * aNodeName ) {
1131 //  beginService( "Graph_Impl::Node" );
1132   SUPERV::CNode_var iobject = SUPERV::CNode::_nil() ;
1133   /* JR : 13/06/03
1134      if ( CORBA::is_nil( DataFlowEditor()->GetNode( aNodeName )->ObjRef() ) ) {
1135      CNode_Impl * myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
1136      instanceName() , interfaceName() ,
1137      DataFlowEditor() ,
1138      DataFlowEditor()->GetNode( aNodeName ) ) ;
1139      PortableServer::ObjectId * id = myNode->getId() ;
1140      CORBA::Object_var obj = _poa->id_to_reference(*id);
1141      iobject = SUPERV::CNode::_narrow(obj) ;
1142      myNode->SetObjRef( SUPERV::CNode::_duplicate( iobject ) ) ;
1143      }
1144      else {
1145      iobject = DataFlowEditor()->GetNode( aNodeName )->ObjRef() ;
1146   */
1147   if ( !IsMacro() ) {
1148     GraphEditor::InNode * anInNode = DataFlowEditor()->GetNode( aNodeName ) ;
1149     if ( anInNode ) {
1150       if ( CORBA::is_nil( anInNode->ObjRef() ) ) {
1151         SetNodeObjRef( anInNode ) ;
1152       }
1153       iobject = anInNode->ObjRef() ;
1154     }
1155   }
1156 //  endService( "Graph_Impl::Node" );
1157   return SUPERV::CNode::_duplicate( iobject ) ;
1158 }
1159
1160 SUPERV::Link_ptr Graph_Impl::Link( SUPERV::Port_ptr OutPort ,
1161                                    SUPERV::Port_ptr InPort ) {
1162 //  beginService( "Graph_Impl::Link" );
1163   SUPERV::Link_var iobject = SUPERV::Link::_nil() ;
1164   if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() &&
1165        !OutPort->IsDataStream() && !InPort->IsDataStream() && !IsMacro() ) {
1166     MESSAGE( "Graph_Impl::Link( " << OutPort->Node()->Name() << "( " << OutPort->Name() << " ) --> "
1167              << InPort->Node()->Name() << "( " << InPort->Name() << " )" ) ;
1168     GraphEditor::InNode * anInNode = DataFlowEditor()->GetNode( InPort->Node()->Name() ) ;
1169     GraphEditor::InNode * anOutNode = DataFlowEditor()->GetNode( OutPort->Node()->Name() ) ;
1170     if ( anInNode == NULL || anOutNode== NULL ) {
1171       MESSAGE( "Graph_Impl::Link( " << OutPort->Node()->Name() << " " << anOutNode << " , "
1172                << InPort->Node()->Name() << " " << anInNode << " ) Node(s) not found in " << Name() ) ;
1173     }
1174     else {
1175       GraphBase::InPort * anInPort = anInNode->ComputingNode()->GetChangeInPort( InPort->Name() ) ;
1176       GraphBase::OutPort * anOutPort = anOutNode->ComputingNode()->GetChangeOutPort( OutPort->Name() ) ;
1177       if ( anInPort == NULL || anOutPort== NULL ) {
1178         MESSAGE( "Graph_Impl::Link( " << OutPort->Name() << " " << anOutPort << " , "
1179                  << InPort->Name() << " " << anInPort << " ) Port(s) not found" ) ;
1180       }
1181       else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
1182         const char * DataFlowOutNodeName = OutPort->Node()->Name() ;
1183         GraphEditor::InNode * DataFlowOutNode = DataFlowEditor()->GetNode( DataFlowOutNodeName ) ;
1184         const char * DataFlowInNodeName = InPort->Node()->Name() ;
1185         GraphEditor::InNode * DataFlowInNode = DataFlowEditor()->GetNode( DataFlowInNodeName ) ;
1186         if ( DataFlowOutNode && DataFlowInNode ) {
1187           bool Success ;
1188           Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
1189                                               instanceName() , interfaceName() ,
1190                                               DataFlowEditor() ,
1191                                               DataFlowInNode ,
1192                                               InPort->Name() ,
1193                                               DataFlowOutNode ,
1194                                               OutPort->Name() ,
1195                                               true , false , Success ) ;
1196           if ( Success ) {
1197             PortableServer::ObjectId * id = myLink->getId() ;
1198             CORBA::Object_var obj = _poa->id_to_reference(*id);
1199             iobject = SUPERV::Link::_narrow(obj) ;
1200             anOutPort->AddInPortObjRef( anInPort , SUPERV::Link::_duplicate( iobject ) ) ;
1201           }
1202         }
1203       }
1204       else {
1205         MESSAGE( "Graph_Impl::Link( " << OutPort->Name() << " " << anOutPort << " , "
1206                  << InPort->Name() << " " << anInPort << " ) ObjRef already exists" ) ;
1207         iobject = anOutPort->InPortObjRef( anInPort ) ;
1208       }
1209     }
1210   }
1211   DataFlowEditor()->UnValid() ;
1212 //  endService( "Graph_Impl::Link" );
1213   return SUPERV::Link::_duplicate( iobject ) ;
1214 }
1215
1216 // Only to see MacroNodes with actual GUI ... :
1217 #define GOTOMacroNode 0
1218
1219 void Graph_Impl::SetNodeObjRef( GraphEditor::InNode * anInNode ) {
1220   MESSAGE("Graph_Impl::SetNodeObjRef " << anInNode->Name() << " " << anInNode->Kind() ) ;
1221   CORBA::Object_var obj ;
1222   if ( anInNode->IsComputingNode() ) {
1223     CNode_Impl * myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
1224                                           instanceName() , interfaceName() ,
1225                                           DataFlowEditor() ,
1226                                           anInNode ) ;
1227     PortableServer::ObjectId * id = myNode->getId() ;
1228     obj = _poa->id_to_reference(*id);
1229     SUPERV::CNode_var iobject = SUPERV::CNode::_narrow(obj) ;
1230     myNode->SetObjRef( SUPERV::CNode::_duplicate( iobject ) ) ;
1231   }
1232   else if ( anInNode->IsFactoryNode() ) {
1233     FNode_Impl * myNode = new FNode_Impl( _Orb , _Poa , _ContId ,
1234                                           instanceName() , interfaceName() ,
1235                                           DataFlowEditor() ,
1236                                           anInNode ) ;
1237     PortableServer::ObjectId * id = myNode->getId() ;
1238     obj = _poa->id_to_reference(*id);
1239     SUPERV::FNode_var iobject = SUPERV::FNode::_narrow(obj) ;
1240     myNode->SetObjRef( SUPERV::FNode::_duplicate( iobject ) ) ;
1241   }
1242   else if ( anInNode->IsInLineNode() ) {
1243     INode_Impl * myNode = new INode_Impl( _Orb , _Poa , _ContId ,
1244                                           instanceName() , interfaceName() ,
1245                                           DataFlowEditor() ,
1246                                           anInNode ) ;
1247     PortableServer::ObjectId * id = myNode->getId() ;
1248     obj = _poa->id_to_reference(*id);
1249     SUPERV::INode_var iobject = SUPERV::INode::_narrow(obj) ;
1250     myNode->SetObjRef( SUPERV::INode::_duplicate( iobject ) ) ;
1251   }
1252 #if GOTOMacroNode
1253   else if ( anInNode->IsGOTONode() || anInNode->IsMacroNode() ) {
1254     if ( anInNode->IsMacroNode() ) {
1255       anInNode->ComputingNode()->Kind( SUPERV::GOTONode ) ;
1256     }
1257 #else
1258   else if ( anInNode->IsGOTONode() ) {
1259 #endif
1260     GNode_Impl * myNode = new GNode_Impl( _Orb , _Poa , _ContId ,
1261                                           instanceName() , interfaceName() ,
1262                                           DataFlowEditor() ,
1263                                           anInNode ) ;
1264     PortableServer::ObjectId * id = myNode->getId() ;
1265     obj = _poa->id_to_reference(*id);
1266     SUPERV::GNode_var iobject = SUPERV::GNode::_narrow(obj) ;
1267     myNode->SetObjRef( SUPERV::GNode::_duplicate( iobject ) ) ;
1268   }
1269   else if ( anInNode->IsMacroNode() ) {
1270     Graph_Impl * myNode = new Graph_Impl( _Orb , _Poa , _ContId ,
1271                                           instanceName() , interfaceName() ,
1272                                           DataFlowEditor() ,
1273                                           anInNode ) ;
1274     PortableServer::ObjectId * id = myNode->getId() ;
1275     obj = _poa->id_to_reference(*id);
1276     SUPERV::Graph_var iobject = SUPERV::Graph::_narrow(obj) ;
1277     myNode->SetObjRef( SUPERV::Graph::_duplicate( iobject ) ) ;
1278   }
1279   else if ( anInNode->IsLoopNode() ) {
1280     LNode_Impl * myNode = new LNode_Impl( _Orb , _Poa , _ContId ,
1281                                           instanceName() , interfaceName() ,
1282                                           DataFlowEditor() ,
1283                                           anInNode ) ;
1284     PortableServer::ObjectId * id = myNode->getId() ;
1285     obj = _poa->id_to_reference(*id);
1286     SUPERV::LNode_var iobject = SUPERV::LNode::_narrow(obj) ;
1287     myNode->SetObjRef( SUPERV::LNode::_duplicate( iobject ) ) ;
1288   }
1289   else if ( anInNode->IsEndLoopNode() ) {
1290     ELNode_Impl * myNode = new ELNode_Impl( _Orb , _Poa , _ContId ,
1291                                             instanceName() , interfaceName() ,
1292                                             DataFlowEditor() ,
1293                                             anInNode ) ;
1294     PortableServer::ObjectId * id = myNode->getId() ;
1295     obj = _poa->id_to_reference(*id);
1296     SUPERV::ELNode_var iobject = SUPERV::ELNode::_narrow(obj) ;
1297     myNode->SetObjRef( SUPERV::ELNode::_duplicate( iobject ) ) ;
1298   }
1299   else if ( anInNode->IsSwitchNode() ) {
1300     SNode_Impl * myNode = new SNode_Impl( _Orb , _Poa , _ContId ,
1301                                           instanceName() , interfaceName() ,
1302                                           DataFlowEditor() ,
1303                                           anInNode ) ;
1304     PortableServer::ObjectId * id = myNode->getId() ;
1305     obj = _poa->id_to_reference(*id);
1306     SUPERV::SNode_var iobject = SUPERV::SNode::_narrow(obj) ;
1307     myNode->SetObjRef( SUPERV::SNode::_duplicate( iobject ) ) ;
1308   }
1309   else if ( anInNode->IsEndSwitchNode() ) {
1310     ESNode_Impl * myNode = new ESNode_Impl( _Orb , _Poa , _ContId ,
1311                                             instanceName() , interfaceName() ,
1312                                             DataFlowEditor() ,
1313                                             anInNode ) ;
1314     PortableServer::ObjectId * id = myNode->getId() ;
1315     obj = _poa->id_to_reference(*id);
1316     SUPERV::ESNode_var iobject = SUPERV::ESNode::_narrow(obj) ;
1317     myNode->SetObjRef( SUPERV::ESNode::_duplicate( iobject ) ) ;
1318   }
1319 }
1320
1321 SUPERV::ListOfNodes_var  Graph_Impl::SetNode( SUPERV::ListOfNodes_var RetVal ,
1322                                               GraphBase::ComputingNode * aNode ) {
1323   int index = 0 ;
1324 //  if ( _DataFlowExecutor ) {
1325   if ( DataFlowExecutor() ) {
1326     MESSAGE("Graph_Impl::SetNode " << aNode->Name() << " " << aNode->Kind() << " "
1327             << DataFlowExecutor()->StateName( DataFlowExecutor()->AutomatonState( aNode->Name() ) ) ) ;
1328   }
1329   else {
1330     MESSAGE("Graph_Impl::SetNode " << aNode->Name() << " " << aNode->Kind() ) ;
1331   }
1332   if ( aNode->IsComputingNode() ) {
1333     index = RetVal->CNodes.length() ;
1334     RetVal->CNodes.length( index+1 );
1335   }
1336   else if ( aNode->IsFactoryNode() ) {
1337     index = RetVal->FNodes.length() ;
1338     RetVal->FNodes.length( index+1 );
1339   }
1340   else if ( aNode->IsInLineNode() ) {
1341     index = RetVal->INodes.length() ;
1342     RetVal->INodes.length( index+1 );
1343   }
1344 #if GOTOMacroNode
1345   else if ( aNode->IsGOTONode() || aNode->IsMacroNode() ) {
1346 #else
1347   else if ( aNode->IsGOTONode() ) {
1348 #endif
1349     index = RetVal->GNodes.length() ;
1350     RetVal->GNodes.length( index+1 );
1351   }
1352   else if ( aNode->IsMacroNode() ) {
1353     index = RetVal->Graphs.length() ;
1354     RetVal->Graphs.length( index+1 );
1355   }
1356   else if ( aNode->IsLoopNode() ) {
1357     index = RetVal->LNodes.length() ;
1358     RetVal->LNodes.length( index+1 );
1359   }
1360   else if ( aNode->IsEndLoopNode() ) {
1361     index = RetVal->ELNodes.length() ;
1362     RetVal->ELNodes.length( index+1 );
1363   }
1364   else if ( aNode->IsSwitchNode() ) {
1365     index = RetVal->SNodes.length() ;
1366     RetVal->SNodes.length( index+1 );
1367   }
1368   else if ( aNode->IsEndSwitchNode() ) {
1369     index = RetVal->ESNodes.length() ;
1370     RetVal->ESNodes.length( index+1 );
1371   }
1372   if ( CORBA::is_nil( aNode->ObjRef() ) ) {
1373     SetNodeObjRef( (GraphEditor::InNode * ) aNode->GetInNode() ) ;
1374   }
1375   SUPERV::CNode_var aNodeObjRef = aNode->ObjRef() ;
1376   if ( aNode->IsComputingNode() ) {
1377     RetVal->CNodes[index] = SUPERV::CNode::_duplicate( aNodeObjRef ) ;
1378   }
1379   else if ( aNode->IsFactoryNode() ) {
1380     RetVal->FNodes[index] = SUPERV::FNode::_duplicate( SUPERV::FNode::_narrow( aNodeObjRef ) ) ;
1381   }
1382   else if ( aNode->IsInLineNode() ) {
1383     RetVal->INodes[index] = SUPERV::INode::_duplicate( SUPERV::INode::_narrow( aNodeObjRef ) ) ;
1384   }
1385 #if GOTOMacroNode
1386   else if ( aNode->IsGOTONode() || aNode->IsMacroNode() ) {
1387 #else
1388   else if ( aNode->IsGOTONode() ) {
1389 #endif
1390     RetVal->GNodes[index] = SUPERV::GNode::_duplicate( SUPERV::GNode::_narrow( aNodeObjRef ) ) ;
1391   }
1392   else if ( aNode->IsMacroNode() ) {
1393     RetVal->Graphs[index] = SUPERV::Graph::_duplicate( SUPERV::Graph::_narrow( aNodeObjRef ) ) ;
1394   }
1395   else if ( aNode->IsLoopNode() ) {
1396     RetVal->LNodes[index] = SUPERV::LNode::_duplicate( SUPERV::LNode::_narrow( aNodeObjRef ) ) ;
1397   }
1398   else if ( aNode->IsEndLoopNode() ) {
1399     RetVal->ELNodes[index] = SUPERV::ELNode::_duplicate( SUPERV::ELNode::_narrow( aNodeObjRef ) ) ;
1400   }
1401   else if ( aNode->IsSwitchNode() ) {
1402     RetVal->SNodes[index] = SUPERV::SNode::_duplicate( SUPERV::SNode::_narrow( aNodeObjRef ) ) ;
1403   }
1404    else if ( aNode->IsEndSwitchNode() ) {
1405     RetVal->ESNodes[index] = SUPERV::ESNode::_duplicate( SUPERV::ESNode::_narrow( aNodeObjRef ) ) ;
1406   }
1407  return ( RetVal._retn() ) ;
1408 }
1409
1410 SUPERV::ListOfNodes * Graph_Impl::Nodes() {
1411   SUPERV::ListOfNodes_var RetVal = new SUPERV::ListOfNodes;
1412   beginService( "Graph_Impl::Nodes" );
1413   RetVal->CNodes.length(0) ;
1414   RetVal->FNodes.length(0) ;
1415   RetVal->INodes.length(0) ;
1416   RetVal->LNodes.length(0) ;
1417   RetVal->SNodes.length(0) ;
1418   RetVal->GNodes.length(0) ;
1419   RetVal->Graphs.length(0) ;
1420   if ( !IsMacro() ) {
1421     int i ;
1422     MESSAGE( DataFlowEditor()->Graph()->GetGraphNodeSize() << " Nodes in the Map and "
1423              << DataFlowEditor()->Graph()->GraphNodesSize() << " Nodes int the Vector" ) ;
1424     for ( i = 0 ; i < DataFlowEditor()->Graph()->GraphNodesSize() ; i++ ) {
1425       GraphBase::ComputingNode * aNode = DataFlowEditor()->Graph()->GraphNodes( i ) ;
1426 #if 1
1427       MESSAGE( i << ". Vector : " << aNode->Name() << " Map : "
1428                << DataFlowEditor()->Graph()->GetGraphNode( aNode->Name() )->Name() ) ;
1429 #endif
1430       RetVal = SetNode( RetVal , aNode ) ;
1431     }
1432 #if 0
1433     char * aStateG = "" ;
1434     if ( DataFlowExecutor() ) {
1435       aStateG = (char *) DataFlowExecutor()->StateName( DataFlowExecutor()->AutomatonState() ) ;
1436     }
1437     MESSAGE("Graph_Impl::Nodes GraphState " << aStateG << " CNodes " << RetVal->CNodes.length() ) ;
1438     for ( i = 0 ; i < RetVal->CNodes.length() ; i++ ) {
1439       MESSAGE("           " << RetVal->CNodes[ i ] ->Name() ) ;
1440     }
1441     MESSAGE("FNodes " << RetVal->FNodes.length() ) ;
1442     for ( i = 0 ; i < RetVal->FNodes.length() ; i++ ) {
1443       MESSAGE("           " << RetVal->FNodes[ i ] ->Name() ) ;
1444     }
1445     MESSAGE("INodes " << RetVal->INodes.length() ) ;
1446     for ( i = 0 ; i < RetVal->INodes.length() ; i++ ) {
1447       MESSAGE("           " << RetVal->INodes[ i ] ->Name() ) ;
1448     }
1449     MESSAGE("GNodes " << RetVal->GNodes.length() ) ;
1450     for ( i = 0 ; i < RetVal->GNodes.length() ; i++ ) {
1451       MESSAGE("           " << RetVal->GNodes[ i ] ->Name() ) ;
1452     }
1453     MESSAGE("LNodes " << RetVal->LNodes.length() ) ;
1454     for ( i = 0 ; i < RetVal->LNodes.length() ; i++ ) {
1455       MESSAGE("           " << RetVal->LNodes[ i ] ->Name() ) ;
1456     }
1457     MESSAGE("ELNodes " << RetVal->ELNodes.length() ) ;
1458     for ( i = 0 ; i < RetVal->ELNodes.length() ; i++ ) {
1459       MESSAGE("           " << RetVal->ELNodes[ i ] ->Name() ) ;
1460     }
1461     MESSAGE("SNodes " << RetVal->SNodes.length() ) ;
1462     for ( i = 0 ; i < RetVal->SNodes.length() ; i++ ) {
1463       MESSAGE("           " << RetVal->SNodes[ i ] ->Name() ) ;
1464     }
1465     MESSAGE("ESNodes " << RetVal->ESNodes.length() ) ;
1466     for ( i = 0 ; i < RetVal->ESNodes.length() ; i++ ) {
1467       MESSAGE("           " << RetVal->ESNodes[ i ] ->Name() ) ;
1468     }
1469     MESSAGE("Graphs " << RetVal->Graphs.length() ) ;
1470     for ( i = 0 ; i < RetVal->Graphs.length() ; i++ ) {
1471       MESSAGE("           " << RetVal->Graphs[ i ] ->Name() ) ;
1472     }
1473     if ( DataFlowExecutor() ) {
1474       DataFlowExecutor()->EventList() ;
1475     }
1476 #endif
1477   }
1478   endService( "Graph_Impl::Nodes" );
1479   return ( RetVal._retn() ) ;
1480 }
1481
1482 SUPERV::ListOfLinks * Graph_Impl::GLinks() {
1483   return Links( NULL , NULL ) ;
1484 }
1485
1486 SUPERV::ListOfLinks * Graph_Impl::Links( GraphBase::ComputingNode * theNode ,
1487                                          const char * anInputParam ) {
1488   bool begin = true ;
1489   SUPERV::ListOfLinks_var RetVal = new SUPERV::ListOfLinks ;
1490   RetVal->length( 0 ) ;
1491   if ( !IsMacro() ) {
1492     int i , j , countlink ;
1493     countlink = 0 ;
1494     for ( i = 0 ; i < DataFlowEditor()->Graph()->GraphNodesSize() ; i++ ) {
1495       GraphEditor::InNode * aNode = NULL ;
1496       aNode = (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GraphNodes( i )->GetInNode() ;
1497       bool ToProcess = false ;
1498       if ( theNode == NULL ) {
1499         ToProcess = true ;
1500       }
1501       else {
1502         if ( !strcmp( theNode->Name() , aNode->Name() ) ) {
1503           if ( !theNode->IsEndSwitchNode() ) {
1504             ToProcess = true ;
1505           }
1506         }
1507         else if ( theNode->IsEndSwitchNode() ) {
1508           ToProcess = true ;
1509         }
1510       }
1511       if ( ToProcess ) {
1512         for ( j = 0 ; j < aNode->GetNodeInPortsSize() ; j++ ) {
1513           GraphBase::InPort * anInPort = NULL ;
1514           anInPort = aNode->GetChangeNodeInPort( j ) ;
1515           if ( anInputParam == NULL ||
1516                !strcmp( anInPort->PortName() , anInputParam ) ) {
1517             GraphBase::OutPort * anOutPort = NULL ;
1518             anOutPort = anInPort->GetOutPort() ;
1519             if ( anOutPort && !anOutPort->IsDataStream() ) {
1520               if ( strcmp( anOutPort->NodeName() , Name() ) ) {
1521 //                MESSAGE("Graph_Impl::Links " << anOutPort->NodeName() << "("
1522 //                        << anOutPort->PortName() << ") --> " << aNode->Name() << "("
1523 //                        << anInPort->PortName() << ")" ) ;
1524                 if ( theNode == NULL ||
1525 //PAL8521
1526 //JR 14.02.2005 : Debug : we must see also that links !
1527 //                     ( theNode != NULL && !theNode->IsEndSwitchNode() &&
1528                        !strcmp( theNode->Name() , aNode->Name() ) ) {
1529                   if ( anInPort->IsLoop() || anOutPort->IsLoop() ||
1530                        ( aNode->IsEndLoopNode() && !strcmp( aNode->CoupledNode()->Name() ,
1531                                                             anOutPort->NodeName() ) ) ) {
1532 //                    MESSAGE( "Link " << anOutPort->NodeName() << "("
1533 //                            << anOutPort->PortName() << ") --> " << aNode->Name() << "("
1534 //                            << anInPort->PortName() << ")" << " ignored" ) ;
1535                   }
1536                   else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
1537                     if ( begin ) {
1538                       beginService( "Graph_Impl::Links" );
1539                       begin = false ;
1540                     }
1541                     GraphEditor::InNode * anOutNode = NULL ;
1542                     anOutNode = (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GetChangeGraphNode( anOutPort->NodeName() )->GetInNode() ;
1543                     if ( anOutNode ) {
1544                       bool Success ;
1545                       Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
1546                                                           instanceName() , interfaceName() ,
1547                                                           DataFlowEditor() ,
1548                                                           aNode ,
1549                                                           anInPort->PortName() ,
1550                                                           anOutNode ,
1551                                                           anOutPort->PortName() ,
1552                                                           false , true , Success ) ;
1553                       if ( Success ) {
1554                         PortableServer::ObjectId * id = myLink->getId() ;
1555                         CORBA::Object_var obj = _poa->id_to_reference(*id);
1556                         SUPERV::Link_var iobject ;
1557                         iobject = SUPERV::Link::_narrow(obj) ;
1558                         RetVal->length( countlink + 1 ) ;
1559                         RetVal[ countlink++ ] = SUPERV::Link::_duplicate( iobject ) ;
1560                         anOutPort->AddInPortObjRef( anInPort , SUPERV::Link::_duplicate( iobject ) ) ;
1561                       }
1562                     }
1563                   }
1564                   else {
1565                     RetVal->length( countlink + 1 ) ;
1566                     RetVal[ countlink++ ] = SUPERV::Link::_duplicate( anOutPort->InPortObjRef( anInPort ) ) ;
1567                   }
1568 //                  MESSAGE( "Link " << anOutPort->NodeName() << "("
1569 //                           << anOutPort->PortName() << ") --> " << aNode->Name() << "("
1570 //                           << anInPort->PortName() << ")" << " selected" ) ;
1571                 }
1572                 else {
1573 //                  MESSAGE( "Link " << anOutPort->NodeName() << "("
1574 //                           << anOutPort->PortName() << ") --> " << aNode->Name() << "("
1575 //                           << anInPort->PortName() << ")" << " skipped" ) ;
1576                 }
1577               }
1578             }
1579           }
1580         }
1581       }
1582       for ( j = 0 ; j < aNode->GetNodeOutPortsSize() ; j++ ) {
1583         GraphBase::OutPort * anOutPort = aNode->GetChangeNodeOutPort( j ) ;
1584 //        MESSAGE( "Graph_Impl::Links " << aNode->Name() << " Out" << j << " " << anOutPort->PortName() << " "
1585 //                 << anOutPort->PortStatus() << " PortConnected to " << anOutPort->InPortsSize() << " InPorts" ) ;
1586         int k ;
1587         for ( k = 0 ; k < anOutPort->InPortsSize() ; k++ ) {
1588           GraphBase::InPort * anInPort = anOutPort->ChangeInPorts( k ) ;
1589 //          MESSAGE( "              -->  In" << k << " " << anInPort->NodeName() << " " << anInPort->PortName()
1590 //                   << " " << anInPort->PortStatus() ) ;
1591           if ( anInPort->IsPortConnected() ) {
1592             GraphBase::ComputingNode * aComputingNode = DataFlowEditor()->Graph()->GetChangeGraphNode( anInPort->NodeName() ) ;
1593             GraphEditor::InNode * toNode = (GraphEditor::InNode * ) aComputingNode->GetInNode() ;
1594             if ( theNode == NULL ||
1595                  !strcmp( theNode->Name() , aNode->Name() ) ) {
1596               if ( !anInPort->IsDataStream() ) {
1597 //PAL8521
1598 //JR 14.02.2005 : Debug : we must see also that links !
1599 //                if ( theNode || ( toNode->IsEndSwitchNode() && !aNode->IsSwitchNode() ) ) {
1600                   if ( anInputParam == NULL ||
1601                        !strcmp( anInPort->PortName() , anInputParam ) ) {
1602                     if ( anInPort->IsLoop() || anOutPort->IsLoop() ||
1603                          ( toNode->IsEndLoopNode() && !strcmp( toNode->CoupledNode()->Name() ,
1604                                                                anOutPort->NodeName() ) ) ) {
1605 //                      MESSAGE( "Link " << anOutPort->NodeName() << "("
1606 //                              << anOutPort->PortName() << ") --> " << toNode->Name() << "("
1607 //                              << anInPort->PortName() << ")" << " ignored" ) ;
1608                     }
1609                     else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
1610                       if ( begin ) {
1611                         beginService( "Graph_Impl::Links" );
1612                         begin = false ;
1613                       }
1614                       bool Success ;
1615                       Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
1616                                                           instanceName() , interfaceName() ,
1617                                                           DataFlowEditor() ,
1618                                                           toNode ,
1619                                                           anInPort->PortName() ,
1620                                                           aNode ,
1621                                                           anOutPort->PortName() ,
1622                                                           false , true , Success ) ;
1623                       if ( Success ) {
1624                         PortableServer::ObjectId * id = myLink->getId() ;
1625                         CORBA::Object_var obj = _poa->id_to_reference(*id);
1626                         SUPERV::Link_var iobject ;
1627                         iobject = SUPERV::Link::_narrow(obj) ;
1628                         RetVal->length( countlink + 1 ) ;
1629                         RetVal[ countlink++ ] = SUPERV::Link::_duplicate( iobject ) ;
1630                         anOutPort->AddInPortObjRef( anInPort , SUPERV::Link::_duplicate( iobject ) ) ;
1631                       }
1632                     }
1633                     else {
1634                       RetVal->length( countlink + 1 ) ;
1635                       RetVal[ countlink++ ] = SUPERV::Link::_duplicate( SUPERV::Link::_narrow( anOutPort->InPortObjRef( anInPort ) ) ) ;
1636                     }
1637 //                    MESSAGE( "Link " << anOutPort->NodeName() << "("
1638 //                             << anOutPort->PortName() << ") --> " << toNode->Name() << "("
1639 //                             << anInPort->PortName() << ")" << " selected" ) ;
1640                   }
1641                   else {
1642 //                    MESSAGE( "Link " << anOutPort->NodeName() << "("
1643 //                             << anOutPort->PortName() << ") --> " << toNode->Name() << "("
1644 //                             << anInPort->PortName() << ")" << " skipped" ) ;
1645                   }
1646 //              }
1647               }
1648             }
1649           }
1650         }
1651       }
1652     }
1653
1654 #if 0
1655     const char * NodeName = "" ;
1656     const char * InputParamName = "" ;
1657     if ( theNode ) {
1658       NodeName = theNode->Name() ;
1659     }
1660     if ( anInputParam ) {
1661       InputParamName = anInputParam ;
1662     }
1663     MESSAGE( RetVal->length() << " Links of Node " << NodeName << " and of InPort " << InputParamName ) ;
1664     for ( i = 0 ; i < (int ) RetVal->length() ; i++ ) {
1665       MESSAGE( "Link " << RetVal[i]->OutPort()->Node()->Name() << "("
1666                << RetVal[i]->OutPort()->Name() << ") --> "
1667                << RetVal[i]->InPort()->Node()->Name() << "("
1668                << RetVal[i]->InPort()->Name() << ")" ) ;
1669     }
1670 #endif
1671     if ( !begin ) {
1672       endService( "Graph_Impl::Links" );
1673     }
1674   }
1675   return ( RetVal._retn() ) ;
1676 }
1677
1678 Engines::Component_ptr Graph_Impl::ComponentRef( const char * aComputerContainer ,
1679                                                  const char * aComponentName ) {
1680   Engines::Component_var objComponent = Engines::Component::_nil() ;
1681   if ( !IsMacro() ) {
1682     Engines::Container_var myContainer ;
1683     DataFlowEditor()->Graph()->StartComponent( 0 , aComputerContainer , aComponentName ,
1684                                                myContainer , objComponent ) ;
1685   }
1686   return Engines::Component::_duplicate( objComponent ) ;
1687 }
1688
1689 char * Graph_Impl::Messages() {
1690   beginService( "Graph_Impl::Messages" );
1691   string Messages  ;
1692   MESSAGE( "Graph_Impl::Messages IsEditing " << DataFlowEditor()->IsEditing() ) ;
1693   Messages = DataFlowEditor()->Graph()->Messages() ;
1694   DataFlowEditor()->Graph()->ReSetMessages() ;
1695   if ( DataFlowExecutor() ) {
1696     Messages += DataFlowExecutor()->Graph()->Messages() ;
1697     DataFlowExecutor()->Graph()->ReSetMessages() ;
1698   }
1699   endService( "Graph_Impl::Messages" );
1700   return ( CORBA::string_dup( Messages.c_str() ) ) ;
1701 }
1702
1703 bool Graph_Impl::IsValid() {
1704 //  beginService( "Graph_Impl::IsValid" );
1705   bool RetVal = false ;
1706   if ( !IsMacro() ) {
1707     RetVal = DataFlowEditor()->IsValid() ;
1708   }
1709 //  endService( "Graph_Impl::IsValid" );
1710   return RetVal ;
1711 }
1712 bool Graph_Impl::IsExecutable() {
1713 //  beginService( "Graph_Impl::IsExecutable" );
1714   bool RetVal = false ;
1715
1716   // asv : 15.11.04 : added "&& GraphMacroLevel() == 0" -> 
1717   // subgraphs are not executable by themselves, RetVal = false..
1718   if ( !IsMacro() && DataFlowEditor()->Graph()->GraphMacroLevel() == 0 ) {
1719     RetVal = DataFlowEditor()->IsExecutable() ;
1720   }
1721 //  endService( "Graph_Impl::IsExecutable" );
1722   return RetVal ;
1723 }
1724
1725 bool Graph_Impl::IsEditing() {
1726 /*
1727   bool RetVal = false ;
1728   if ( !IsMacro() ) {
1729     RetVal = DataFlowEditor()->IsEditing() ;
1730   }
1731   return RetVal ;
1732 */
1733   if ( IsMacro() )
1734     return false;
1735   return !IsExecuting();
1736 }
1737
1738 bool Graph_Impl::IsExecuting() {
1739 /*
1740   bool RetVal = false ;
1741   if ( !IsMacro() ) {
1742     RetVal = !DataFlowEditor()->IsEditing() ;
1743   }
1744   return RetVal ;
1745 */
1746   return CNode_Impl::IsExecuting();
1747 }
1748
1749 bool Graph_Impl::IsReadOnly() {
1750 //  beginService( "Graph_Impl::IsExecuting" );
1751   bool RetVal = false ;
1752   if ( !IsMacro() ) {
1753     RetVal = DataFlowEditor()->IsReadOnly() ;
1754   }
1755 //  endService( "Graph_Impl::IsExecuting" );
1756   return RetVal ;
1757 }
1758
1759 CORBA::Long Graph_Impl::LevelMax() {
1760 //  beginService( "Graph_Impl::LevelMax" );
1761   CORBA::Long RetVal = 0 ;
1762   if ( !IsMacro() ) {
1763     RetVal = DataFlowEditor()->LevelMax() ;
1764   }
1765 //  endService( "Graph_Impl::LevelMax" );
1766   return RetVal ;
1767 }
1768 SUPERV::ListOfNodes * Graph_Impl::LevelNodes(CORBA::Long aLevel ) {
1769 //  beginService( "Graph_Impl::LevelNodes" );
1770   SUPERV::ListOfNodes_var RetVal = new SUPERV::ListOfNodes;
1771   if ( !IsMacro() ) {
1772     int i ;
1773     SUPERV::ListOfStrings_var Nodes = DataFlowEditor()->LevelNodes( aLevel ) ;
1774 //  RetVal->length( Nodes->length() );
1775     for ( i = 0 ; i < (int ) Nodes->length() ; i++ ) {
1776 //    char * aNode = Nodes[ i ] ;
1777       GraphBase::ComputingNode * aNode = DataFlowEditor()->Graph()->GetChangeGraphNode( Nodes[ i ] ) ;
1778       RetVal = SetNode( RetVal , aNode ) ;
1779 //    cout << "Graph_Impl::LevelNodes( " << aLevel << " ) " << aNode->Name() << endl ;
1780 //    CNode_Impl * myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
1781 //                               instanceName() , interfaceName() ,
1782 //                               DataFlowEditor() ,
1783 //                               (GraphEditor::InNode * ) DataFlowEditor()->GetChangeGraphNode( aNode )->GetInNode() ) ;
1784 //    PortableServer::ObjectId * id = myNode->getId() ;
1785 //    CORBA::Object_var obj = _poa->id_to_reference(*id);
1786 //    SUPERV::CNode_var iobject ;
1787 //    iobject = SUPERV::CNode::_narrow(obj) ;
1788 //    RetVal[i] = SUPERV::CNode::_duplicate( iobject ) ;
1789     }
1790   }
1791 //  endService( "Graph_Impl::LevelNodes" );
1792   return ( RetVal._retn() ) ;
1793 }
1794 CORBA::Long Graph_Impl::ThreadsMax() {
1795 //  beginService( "Graph_Impl::ThreadsMax" );
1796   CORBA::Long RetVal = 0 ;
1797   if ( !IsMacro() ) {
1798     RetVal =  DataFlowEditor()->ThreadsMax() ;
1799   }
1800 //  endService( "Graph_Impl::ThreadsMax" );
1801   return RetVal ;
1802 }
1803 CORBA::Long Graph_Impl::Threads() {
1804 //  beginService( "Node_Impl::Threads" );
1805   CORBA::Long RetVal = false ;
1806   if ( !IsMacro() ) {
1807     RetVal = DataFlowExecutor()->Threads() ;
1808   }
1809 //  endService( "Node_Impl::Threads" );
1810   return RetVal ;
1811 }
1812 CORBA::Long Graph_Impl::SuspendedThreads() {
1813 //  beginService( "Node_Impl::SuspendedThreads" );
1814   CORBA::Long RetVal = false ;
1815   if ( !IsMacro() ) {
1816     RetVal = DataFlowExecutor()->SuspendedThreads() ;
1817   }
1818 //  endService( "Node_Impl::SuspendedThreads" );
1819   return RetVal ;
1820 }
1821
1822 bool Graph_Impl::Begin() {
1823   bool RetVal = false ;
1824   // mkr : IPAL11408 : "Run()" method returns "0" after trying to start graph execution.
1825   // If we call Run() method from Python script two times for one graph, we have to be sure,
1826   // that first execution of this graph ended (i.e. GraphEditor::DataFlow::Editing() method was called).
1827   // Otherwise, the second call of Run() method will return 0. Therefore, we have to waiting for
1828   // the first execution finish. 
1829   // NB! From GUI we cann't run dataflow if its previous execution not finished.
1830   while ( !DataFlowEditor()->IsEditing() ) {} // waiting for the previous execution of this graph ended
1831   if ( DataFlowEditor()->IsEditing() ) {
1832     if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1833       perror("pthread_mutex_lock _MutexExecutorWait") ;
1834       exit( 0 ) ;
1835     }
1836     DataFlowEditor()->Graph()->ReSetMessages() ; // ==> Only one set of errors messages ...
1837     if ( DataFlowExecutor() ) {
1838       MESSAGE( "Graph_Impl::Begin " << DataFlowExecutor()->Threads() << " threads" )
1839       Editing(); // just in case it was not called before by GUI..
1840     }
1841     if ( DataFlowEditor()->IsExecutable() ) {
1842       DataFlowEditor()->EditedAfterExecution( false ) ;
1843       GraphBase::ListOfSGraphs * myListOfGraphs = DataFlowEditor()->GetDataFlows() ;
1844
1845       GraphExecutor::DataFlow * aDataFlowExecutor ;
1846       string dbgfile ;
1847       CreateExecutor( _Orb , instanceName() , (*myListOfGraphs)[ 0 ].Info.theName.c_str() , Kind() ,
1848                       dbgfile , &aDataFlowExecutor ) ;
1849
1850       MESSAGE( "Graph_Impl::Begin : DataFlowExecutor created" );
1851       if ( !CORBA::is_nil( LoadDataFlows( aDataFlowExecutor, myListOfGraphs , 0 ) ) ) 
1852         RetVal = true ;
1853   
1854       if ( RetVal )
1855         DataFlowExecutor()->Graph()->SetObjImpl( DataFlowEditor()->Graph()->ObjImpl() ) ;
1856     
1857     }
1858     if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1859       perror("pthread_mutex_unlock _MutexExecutorWait") ;
1860       exit( 0 ) ;
1861     }
1862   }
1863   return RetVal ;
1864 }
1865
1866 /**
1867  * run() : was created in order to reduce code dublication, Run() and Start() do the same thing
1868  *         except for final call to Executor->Run( bool ) - Run() calls with AndSuspend=false
1869  *         and Start() calls with AndSuspend=true flag.  The rest of the actions are the same:
1870  *         1. if a MacroNode's coupled graph (MacroLevel>0) -> simply Run() it.
1871  *         2. if a Supergraph -> create executor, load dataflow in it (done in Begin()), then - Run() it.
1872  */
1873 bool Graph_Impl::run( const bool andSuspend ) {
1874   bool RetVal = false ;
1875
1876   // if Editing or Finished state, and, naturally, 'this' is not a MacroNode. 
1877   if ( ( DataFlowEditor()->IsEditing() || IsDone() ) && !IsMacro() ) {
1878
1879     if ( DataFlowEditor()->Graph()->GraphMacroLevel() ) {
1880       // MacroGraph's Executor was created in recursive function LoadDataflows(Executor), called from
1881       // Begin() of Supergraph.  See Begin() and LoadDataflows(Executor) for details.
1882       RetVal = true ; 
1883     }
1884     else {
1885       // Create Executor instance and its datamodel
1886       RetVal = Begin() ;
1887     }
1888     if ( RetVal ) {
1889       // Set Executing flag to avoid edition operations during execution, EditedAfterExecution=false
1890       DataFlowEditor()->Executing() ;
1891       DataFlowEditor()->EditedAfterExecution( false ); 
1892
1893       // THE MAIN RUN METHOD
1894       RetVal = DataFlowExecutor()->Run( andSuspend );
1895     }
1896   }
1897   return RetVal ;
1898
1899 }
1900
1901 /**
1902  * Run() - called on "Execute" command
1903  */
1904 bool Graph_Impl::Run() {
1905   beginService( "Graph_Impl::Run" );
1906   bool RetVal = run( /*andSuspend=*/false ) ;
1907   MESSAGE( "Graph_Impl::Run " << DataFlowEditor()->Graph()->Name() << " RetVal " << RetVal ) ;
1908   endService( "Graph_Impl::Run" );
1909   return RetVal ;
1910 }
1911
1912 /**
1913  * Run() - called on "Execute step-by-step" command
1914  */
1915 bool Graph_Impl::Start() {
1916   beginService( "Graph_Impl::Start" );
1917   bool RetVal = run( /*andSuspend=*/true ) ;
1918   MESSAGE( "Graph_Impl::Start " << DataFlowEditor()->Graph()->Name() << " RetVal " << RetVal ) ;
1919   endService( "Graph_Impl::Start" );
1920   return RetVal ;
1921 }
1922
1923 bool Graph_Impl::EventNoW( SUPERV::CNode_out aNode ,
1924                            SUPERV::GraphEvent & anEvent ,
1925                            SUPERV::GraphState & aState ) {
1926   bool RetVal = false ;
1927   char * aNodeName = NULL ;
1928   SUPERV::GraphEvent theEvent = SUPERV::UndefinedEvent ;
1929   SUPERV::GraphState theState = SUPERV::UndefinedState ;
1930   if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1931     perror("pthread_mutex_lock _MutexExecutorWait") ;
1932     exit( 0 ) ;
1933   }
1934   if ( DataFlowExecutor() && !IsMacro() &&
1935        ( DataFlowExecutor()->GetListSize() || !DataFlowEditor()->IsEditing() ) ) {
1936     RetVal = DataFlowExecutor()->Event( & aNodeName , theEvent , theState , false ) ;
1937 //  endService( "Graph_Impl::Event" );
1938     if ( strlen( aNodeName ) ) {
1939       if ( strcmp( aNodeName , Name() ) ) {
1940         aNode = Node( aNodeName ) ;
1941       }
1942       else {
1943         aNode = Node() ;
1944       }
1945     }
1946     else {
1947       aNode = SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
1948     }
1949 //    cout << "Graph_Impl::EventNoW " << aNode->Name() << " QSize " << DataFlowExecutor()->GetListSize() << endl ;
1950   }
1951   else {
1952 //    cout << "Graph_Impl::EventNoW NO DataFlowExecutor() or QSize=0 " << endl ;
1953   }
1954   if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1955     perror("pthread_mutex_unlock _MutexExecutorWait") ;
1956     exit( 0 ) ;
1957   }
1958   anEvent = theEvent ;
1959   aState = theState ;
1960   return RetVal ;
1961 }
1962
1963 bool Graph_Impl::Event( SUPERV::CNode_out aNode ,
1964                         SUPERV::GraphEvent & anEvent ,
1965                         SUPERV::GraphState & aState ) {
1966 //  beginService( "Graph_Impl::Event" );
1967   bool RetVal = false ;
1968   char * aNodeName = NULL ;
1969   SUPERV::GraphEvent theEvent = SUPERV::UndefinedEvent ;
1970   SUPERV::GraphState theState = SUPERV::UndefinedState ;
1971   if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1972     perror("pthread_mutex_lock _MutexExecutorWait") ;
1973     exit( 0 ) ;
1974   }
1975   if ( DataFlowExecutor() && !IsMacro() &&
1976        ( DataFlowExecutor()->GetListSize() || !DataFlowEditor()->IsEditing() ) ){
1977     RetVal = DataFlowExecutor()->Event( & aNodeName , theEvent , theState ) ;
1978 //  endService( "Graph_Impl::Event" );
1979     if ( strlen( aNodeName ) ) {
1980       if ( strcmp( aNodeName , Name() ) ) {
1981         aNode = Node( aNodeName ) ;
1982       }
1983       else {
1984         aNode = Node() ;
1985       }
1986     }
1987     else {
1988       aNode = SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
1989     }
1990 //    cout << "Graph_Impl::Event " << aNode->Name() << " QSize " << DataFlowExecutor()->GetListSize() << endl ;
1991   }
1992   else {
1993 //    cout << "Graph_Impl::Event NO DataFlowExecutor() or QSize=0 " << endl ;
1994   }
1995   if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1996     perror("pthread_mutex_unlock _MutexExecutorWait") ;
1997     exit( 0 ) ;
1998   }
1999   anEvent = theEvent ;
2000   aState = theState ;
2001
2002   return RetVal ;
2003 }
2004
2005 bool Graph_Impl::EventW( SUPERV::CNode_out aNode ,
2006                          SUPERV::GraphEvent & anEvent ,
2007                          SUPERV::GraphState & aState ) {
2008 //  beginService( "Graph_Impl::EventW" );
2009   bool RetVal = false ;
2010   char * aNodeName = NULL ;
2011   SUPERV::GraphEvent theEvent = SUPERV::UndefinedEvent ;
2012   SUPERV::GraphState theState = SUPERV::UndefinedState ;
2013   if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
2014     perror("pthread_mutex_lock _MutexExecutorWait") ;
2015     exit( 0 ) ;
2016   }
2017   if ( DataFlowExecutor() && !IsMacro() &&
2018        ( DataFlowExecutor()->GetListSize() || !DataFlowEditor()->IsEditing() ) ) {
2019     RetVal = DataFlowExecutor()->EventW( & aNodeName , theEvent , theState ) ;
2020     if ( RetVal && strcmp( aNodeName , Name() ) ) {
2021       aNode = Node( aNodeName ) ;
2022     }
2023     else {
2024       aNode = Node() ;
2025     }
2026   }
2027   if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
2028     perror("pthread_mutex_unlock _MutexExecutorWait") ;
2029     exit( 0 ) ;
2030   }
2031   anEvent = theEvent ;
2032   aState = theState ;
2033 //  endService( "Graph_Impl::EventW" );
2034   return RetVal ;
2035 }
2036
2037 CORBA::Long Graph_Impl::EventQSize() {
2038 //  beginService( "Graph_Impl::EventQSize" );
2039   CORBA::Long QSize = -1 ;
2040   if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
2041     perror("pthread_mutex_lock _MutexExecutorWait") ;
2042     exit( 0 ) ;
2043   }
2044   if ( DataFlowExecutor() && !IsMacro() ) {
2045     QSize = DataFlowExecutor()->EventQSize() ;
2046   }
2047   if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
2048     perror("pthread_mutex_unlock _MutexExecutorWait") ;
2049     exit( 0 ) ;
2050   }
2051 //  endService( "Graph_Impl::EventQSize" );
2052   return QSize ;
2053 }
2054
2055 CORBA::Long Graph_Impl::LastLevelDone() {
2056 //  beginService( "Graph_Impl::LastLevelDone" );
2057   if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
2058     perror("pthread_mutex_lock _MutexExecutorWait") ;
2059     exit( 0 ) ;
2060   }
2061   CORBA::Long RetVal = 0 ;
2062   if ( DataFlowExecutor() && !IsMacro() ) {
2063     RetVal = DataFlowExecutor()->LastLevelDone() ;
2064   }
2065   if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
2066     perror("pthread_mutex_unlock _MutexExecutorWait") ;
2067     exit( 0 ) ;
2068   }
2069 //  endService( "Graph_Impl::LastLevelDone" );
2070   return RetVal ;
2071 }
2072
2073 CORBA::Long Graph_Impl::SubGraphsNumber() {
2074 //  beginService( "Graph_Impl::SubGraphsNumber" );
2075   CORBA::Long RetVal = 0 ;
2076   if ( DataFlowEditor()->IsExecutable() && !IsMacro() ) {
2077     RetVal = DataFlowEditor()->SubGraphsNumber() ;
2078   }
2079 //  endService( "Graph_Impl::SubGraphsNumber" );
2080   return RetVal ;
2081 }
2082
2083 SUPERV::ListOfNodes * Graph_Impl::SubGraphsNodes( CORBA::Long aSubGraphNumber ) {
2084   beginService( "Graph_Impl::SubGraphsNodes" );
2085   SUPERV::ListOfNodes_var RetVal = new SUPERV::ListOfNodes ;
2086   if ( DataFlowEditor()->IsEditing() && !IsMacro() ) {
2087     SUPERV::ListOfNodes * aGraphNodes = Nodes() ;
2088     int i ;
2089 // ComputingNodes
2090     for ( i = 0 ; i < (int ) aGraphNodes->CNodes.length() ; i++ ) {
2091       SUPERV::CNode_var aNode = (aGraphNodes->CNodes)[ i ] ;
2092       if ( aNode->SubGraph() == aSubGraphNumber ) {
2093         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
2094       }
2095     }
2096 // FactoryNodes
2097     for ( i = 0 ; i < (int ) aGraphNodes->FNodes.length() ; i++ ) {
2098       SUPERV::FNode_var aNode = (aGraphNodes->FNodes)[ i ] ;
2099       if ( aNode->SubGraph() == aSubGraphNumber ) {
2100         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
2101       }
2102     }
2103 // InLineNodes
2104     for ( i = 0 ; i < (int ) aGraphNodes->INodes.length() ; i++ ) {
2105       SUPERV::INode_var aNode = (aGraphNodes->INodes)[ i ] ;
2106       if ( aNode->SubGraph() == aSubGraphNumber ) {
2107         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
2108       }
2109     }
2110 // GOTONodes
2111     for ( i = 0 ; i < (int ) aGraphNodes->GNodes.length() ; i++ ) {
2112       SUPERV::GNode_var aNode = (aGraphNodes->GNodes)[ i ] ;
2113       if ( aNode->SubGraph() == aSubGraphNumber ) {
2114         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
2115       }
2116     }
2117 // LoopNodes
2118     for ( i = 0 ; i < (int ) aGraphNodes->LNodes.length() ; i++ ) {
2119       SUPERV::LNode_var aNode = (aGraphNodes->LNodes)[ i ] ;
2120       if ( aNode->SubGraph() == aSubGraphNumber ) {
2121         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
2122       }
2123     }
2124 // EndLoopNodes
2125     for ( i = 0 ; i < (int ) aGraphNodes->ELNodes.length() ; i++ ) {
2126       SUPERV::ELNode_var aNode = (aGraphNodes->ELNodes)[ i ] ;
2127       if ( aNode->SubGraph() == aSubGraphNumber ) {
2128         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
2129       }
2130     }
2131 // SwitchNodes
2132     for ( i = 0 ; i < (int ) aGraphNodes->SNodes.length() ; i++ ) {
2133       SUPERV::SNode_var aNode = (aGraphNodes->SNodes)[ i ] ;
2134       if ( aNode->SubGraph() == aSubGraphNumber ) {
2135         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
2136       }
2137     }
2138 // EndSwitchNodes
2139     for ( i = 0 ; i < (int ) aGraphNodes->ESNodes.length() ; i++ ) {
2140       SUPERV::ESNode_var aNode = (aGraphNodes->ESNodes)[ i ] ;
2141       if ( aNode->SubGraph() == aSubGraphNumber ) {
2142         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
2143       }
2144     }
2145   }
2146   endService( "Graph_Impl::SubGraphsNodes" );
2147   return ( RetVal._retn() ) ;
2148 }
2149
2150 bool Graph_Impl::Merge(const SUPERV::Graph_ptr aGraph ) {
2151 //  beginService( "Graph_Impl::Merge" );
2152   bool RetVal = true ;
2153   if ( !IsMacro() ) {
2154     map< string , int > aMapOfNodes ;
2155     RetVal = Merge( aGraph , aMapOfNodes ) ;
2156   }
2157 //  endService( "Graph_Impl::Merge" );
2158   return RetVal ;
2159 }
2160
2161 bool Graph_Impl::Merge(const SUPERV::Graph_ptr aGraph , map< string , int > & aMapOfNodes ) {
2162   beginService( "Graph_Impl::Merge" );
2163   bool RetVal = true ;
2164   if ( DataFlowEditor()->IsEditing() && !IsMacro() ) {
2165     SUPERV::ListOfNodes * aGraphNodes = aGraph->Nodes() ;
2166     int i ;
2167     SUPERV::Port_ptr aPort ;
2168 //    SUPERV::StreamPort_ptr aStreamPort ;
2169 // ComputingNodes
2170     for ( i = 0 ; i < (int ) aGraphNodes->CNodes.length() ; i++ ) {
2171       SUPERV::CNode_var aNode = (aGraphNodes->CNodes)[ i ] ;
2172       SUPERV::CNode_ptr myNode = CNode( *(aNode->Service()) ) ;
2173       if ( !CORBA::is_nil( myNode ) ) {
2174         myNode->SetName( aNode->Name() ) ;
2175         myNode->SetAuthor( aNode->Author() ) ;
2176         myNode->SetComment( aNode->Comment() ) ;
2177         myNode->Coords( aNode->X() , aNode->Y() ) ;
2178         string * aNodetheName = new string( aNode->Name() ) ;
2179         aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
2180         delete aNodetheName ;
2181         RetVal = true ;
2182       }
2183       else {
2184         RetVal = false ;
2185         break ;
2186       }
2187 // The following informations are now in the service from SALOME_ModuleCatalog
2188 //      SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
2189 //      int j ;
2190 //      for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
2191 //        if ( myStreamPorts[ j ]->IsInput() && myStreamPorts[ j ]->IsDataStream() ) {
2192 //          aStreamPort = myNode->InStreamPort( myStreamPorts[ j ]->Name() , myStreamPorts[ j ]->Type() ) ;
2193 //        }
2194 //        else if ( myStreamPorts[ j ]->IsDataStream() ) {
2195 //          aStreamPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name() , myStreamPorts[ j ]->Type() ) ;
2196 //        }
2197 //      }
2198     }
2199 // FactoryNodes
2200     if ( RetVal ) {
2201       for ( i = 0 ; i < (int ) aGraphNodes->FNodes.length() ; i++ ) {
2202         SUPERV::FNode_var aNode = (aGraphNodes->FNodes)[ i ] ;
2203         SALOME_ModuleCatalog::ImplType implType = SALOME_ModuleCatalog::SO;
2204         if (!aNode->IsCimpl()) implType = SALOME_ModuleCatalog::PY;
2205         SUPERV::FNode_ptr myNode = FNode( aNode->GetComponentName() ,
2206                                           aNode->GetInterfaceName() ,
2207                                           *(aNode->Service()) ,
2208                                           implType ) ; // mkr : PAL11273
2209         if ( !CORBA::is_nil( myNode ) ) {
2210           myNode->SetName( aNode->Name() ) ;
2211           myNode->SetAuthor( aNode->Author() ) ;
2212           myNode->SetComment( aNode->Comment() ) ;
2213           myNode->Coords( aNode->X() , aNode->Y() ) ;
2214           string * aNodetheName = new string( aNode->Name() ) ;
2215           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
2216           delete aNodetheName ;
2217           RetVal = true ;
2218         }
2219         else {
2220           RetVal = false ;
2221           break ;
2222         }
2223 // The following informations are now in the service from SALOME_ModuleCatalog
2224 //        SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
2225 //        int j ;
2226 //        for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
2227 //          if ( myStreamPorts[ j ]->IsInput() && myStreamPorts[ j ]->IsDataStream() ) {
2228 //            aStreamPort = myNode->InStreamPort( myStreamPorts[ j ]->Name() , myStreamPorts[ j ]->Type() ) ;
2229 //          }
2230 //          else if ( myStreamPorts[ j ]->IsDataStream() ) {
2231 //            aStreamPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name() , myStreamPorts[ j ]->Type() ) ;
2232 //          }
2233 //        }
2234       }
2235     }
2236 // InLineNodes
2237     if ( RetVal ) {
2238       for ( i = 0 ; i < (int ) aGraphNodes->INodes.length() ; i++ ) {
2239         SUPERV::INode_var aNode = (aGraphNodes->INodes)[ i ] ;
2240         SUPERV::INode_ptr myNode = INode( aNode->PyFuncName() , *(aNode->PyFunction()) ) ;
2241         if ( !CORBA::is_nil( myNode ) ) {
2242           myNode->SetName( aNode->Name() ) ;
2243           myNode->SetAuthor( aNode->Author() ) ;
2244           myNode->SetComment( aNode->Comment() ) ;
2245           myNode->Coords( aNode->X() , aNode->Y() ) ;
2246           string * aNodetheName = new string( aNode->Name() ) ;
2247           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
2248           delete aNodetheName ;
2249           SUPERV::ListOfPorts myPorts = *(aNode->Ports()) ;
2250           int j ;
2251           for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
2252             if ( myPorts[ j ]->IsInput() ) {
2253               aPort = myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2254             }
2255             else {
2256               aPort = myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2257             }
2258           }
2259           if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
2260             SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
2261             for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
2262               if ( myStreamPorts[ j ]->IsInput() ) {
2263                 aPort = myNode->InStreamPort( myStreamPorts[ j ]->Name(), myStreamPorts[ j ]->Type(), myStreamPorts[ j ]->Dependency() ) ;
2264               }
2265               else {
2266                 aPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name(), myStreamPorts[ j ]->Type(), myStreamPorts[ j ]->Dependency() ) ;
2267               }
2268             }
2269           }
2270           RetVal = true ;
2271         }
2272         else {
2273           RetVal = false ;
2274           break ;
2275         }
2276       }
2277     }
2278 // GOTONodes
2279     if ( RetVal ) {
2280       for ( i = 0 ; i < (int ) aGraphNodes->GNodes.length() ; i++ ) {
2281         SUPERV::GNode_var aNode = (aGraphNodes->GNodes)[ i ] ;
2282         SUPERV::GNode_ptr myNode = GNode( aNode->PyFuncName() , *(aNode->PyFunction()) , aNode->Coupled()->Name() ) ;
2283         if ( !CORBA::is_nil( myNode ) ) {
2284           myNode->SetName( aNode->Name() ) ;
2285           myNode->SetAuthor( aNode->Author() ) ;
2286           myNode->SetComment( aNode->Comment() ) ;
2287           myNode->Coords( aNode->X() , aNode->Y() ) ;
2288           string * aNodetheName = new string( aNode->Name() ) ;
2289           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
2290           delete aNodetheName ;
2291           SUPERV::ListOfPorts myPorts = *(aNode->Ports()) ;
2292           int j ;
2293           for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
2294             if ( myPorts[ j ]->IsInput() ) {
2295               aPort = myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2296             }
2297             else {
2298               aPort = myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2299             }
2300           }
2301           if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
2302             SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
2303             for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
2304               if ( myStreamPorts[ j ]->IsInput() ) {
2305                 aPort = myNode->InStreamPort( myStreamPorts[ j ]->Name(), myStreamPorts[ j ]->Type(), myStreamPorts[ j ]->Dependency() ) ;
2306               }
2307               else {
2308                 aPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name(), myStreamPorts[ j ]->Type(), myStreamPorts[ j ]->Dependency() ) ;
2309               }
2310             }
2311           }
2312           RetVal = true ;
2313         }
2314         else {
2315           RetVal = false ;
2316           break ;
2317         }
2318       }
2319     }
2320 // LoopNodes
2321     if ( RetVal ) {
2322       for ( i = 0 ; i < (int ) aGraphNodes->LNodes.length() ; i++ ) {
2323         SUPERV::LNode_var aNode = (aGraphNodes->LNodes)[ i ] ;
2324         SUPERV::INode_ptr anEndOfLoop ;
2325         SUPERV::LNode_ptr myNode = LNode( aNode->PyInitName() ,
2326                                           *(aNode->PyInit()) ,
2327                                           aNode->PyMoreName() ,
2328                                           *(aNode->PyMore()) ,
2329                                           aNode->PyNextName() ,
2330                                           *(aNode->PyNext()) ,
2331                                           anEndOfLoop ) ;
2332         if ( !CORBA::is_nil( myNode ) ) {
2333           myNode->SetName( aNode->Name() ) ;
2334           myNode->SetAuthor( aNode->Author() ) ;
2335           myNode->SetComment( aNode->Comment() ) ;
2336           myNode->Coords( aNode->X() , aNode->Y() ) ;
2337           string * aNodetheName = new string( aNode->Name() ) ;
2338           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
2339           delete aNodetheName ;
2340           SUPERV::ListOfPorts myPorts = *(aNode->Ports()) ;
2341           int j ;
2342           for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
2343             if ( myPorts[ j ]->IsInput() ) {
2344               aPort = myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2345             }
2346             else {
2347               aPort = myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2348             }
2349           }
2350           if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
2351             SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
2352             for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
2353               if ( myStreamPorts[ j ]->IsInput() ) {
2354                 aPort = myNode->InStreamPort( myStreamPorts[ j ]->Name(), myStreamPorts[ j ]->Type(), myStreamPorts[ j ]->Dependency() ) ;
2355               }
2356               else {
2357                 aPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name(), myStreamPorts[ j ]->Type(), myStreamPorts[ j ]->Dependency() ) ;
2358               }
2359             }
2360           }
2361           SUPERV::INode_ptr myEndOfLoop = aNode->Coupled() ;
2362           anEndOfLoop->SetName( myEndOfLoop->Name() ) ;
2363           anEndOfLoop->SetAuthor( myEndOfLoop->Author() ) ;
2364           anEndOfLoop->SetComment( myEndOfLoop->Comment() ) ;
2365           anEndOfLoop->Coords( myEndOfLoop->X() , myEndOfLoop->Y() ) ;
2366           anEndOfLoop->SetPyFunction( myEndOfLoop->PyFuncName() , *(myEndOfLoop->PyFunction()) ) ;
2367           aNodetheName = new string( myEndOfLoop->Name() ) ;
2368           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( anEndOfLoop->Name() ) ;
2369           if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
2370             SUPERV::ListOfStreamPorts myStreamLoopPorts = *(myEndOfLoop->StreamPorts()) ;
2371             for ( j = 0 ; j < (int ) myStreamLoopPorts.length() ; j++ ) {
2372               if ( myStreamLoopPorts[ j ]->IsInput() ) {
2373                 aPort = myNode->InStreamPort( myStreamLoopPorts[ j ]->Name(), myStreamLoopPorts[ j ]->Type(), myStreamLoopPorts[ j ]->Dependency() ) ;
2374               }
2375               else {
2376                 aPort = myNode->OutStreamPort( myStreamLoopPorts[ j ]->Name(), myStreamLoopPorts[ j ]->Type(), myStreamLoopPorts[ j ]->Dependency() ) ;
2377               }
2378             }
2379           }
2380           delete aNodetheName ;
2381           RetVal = true ;
2382         }
2383         else {
2384           RetVal = false ;
2385           break ;
2386         }
2387       }
2388     }
2389 // SwitchNodes
2390     if ( RetVal ) {
2391       for ( i = 0 ; i < (int ) aGraphNodes->SNodes.length() ; i++ ) {
2392         SUPERV::SNode_var aNode = (aGraphNodes->SNodes)[ i ] ;
2393         SUPERV::INode_ptr anEndOfSwitch ;
2394         SUPERV::SNode_ptr myNode = SNode( aNode->PyFuncName() , *(aNode->PyFunction()) , anEndOfSwitch ) ;
2395         if ( !CORBA::is_nil( myNode ) ) {
2396           myNode->SetName( aNode->Name() ) ;
2397           myNode->SetAuthor( aNode->Author() ) ;
2398           myNode->SetComment( aNode->Comment() ) ;
2399           myNode->Coords( aNode->X() , aNode->Y() ) ;
2400           string * aNodetheName = new string( aNode->Name() ) ;
2401           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
2402           delete aNodetheName ;
2403           SUPERV::ListOfPorts myPorts = *(aNode->Ports()) ;
2404           int j ;
2405           for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
2406             if ( myPorts[ j ]->IsInput() ) {
2407               aPort = myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2408             }
2409             else {
2410               aPort = myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2411             }
2412           }
2413           if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
2414             SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
2415             for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
2416               if ( myStreamPorts[ j ]->IsInput() ) {
2417                 aPort = myNode->InStreamPort( myStreamPorts[ j ]->Name(), myStreamPorts[ j ]->Type(), myStreamPorts[ j ]->Dependency() ) ;
2418               }
2419               else {
2420                 aPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name(), myStreamPorts[ j ]->Type(), myStreamPorts[ j ]->Dependency() ) ;
2421               }
2422             }
2423           }
2424           SUPERV::INode_ptr myEndOfSwitch = aNode->Coupled() ;
2425           anEndOfSwitch->SetName( myEndOfSwitch->Name() ) ;
2426           anEndOfSwitch->SetAuthor( myEndOfSwitch->Author() ) ;
2427           anEndOfSwitch->SetComment( myEndOfSwitch->Comment() ) ;
2428           anEndOfSwitch->Coords( myEndOfSwitch->X() , myEndOfSwitch->Y() ) ;
2429           anEndOfSwitch->SetPyFunction( myEndOfSwitch->PyFuncName() , *(myEndOfSwitch->PyFunction()) ) ;
2430           aNodetheName = new string( myEndOfSwitch->Name() ) ;
2431           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( anEndOfSwitch->Name() ) ;
2432           delete aNodetheName ;
2433           myPorts = *(myEndOfSwitch->Ports()) ;
2434           for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
2435             if ( myPorts[ j ]->IsInput() ) {
2436               aPort = anEndOfSwitch->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ; // mkr : IPAL11394 (add port to !EndSwitch! node)
2437             }
2438             else {
2439               aPort = anEndOfSwitch->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ; // mkr : IPAL11394 (add port to !EndSwitch! node)
2440             }
2441           }
2442           if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
2443             SUPERV::ListOfStreamPorts myStreamSwitchPorts = *(myEndOfSwitch->StreamPorts()) ;
2444             for ( j = 0 ; j < (int ) myStreamSwitchPorts.length() ; j++ ) {
2445               if ( myStreamSwitchPorts[ j ]->IsInput() ) {
2446                 aPort = anEndOfSwitch->InStreamPort( myStreamSwitchPorts[ j ]->Name(), myStreamSwitchPorts[ j ]->Type(), myStreamSwitchPorts[ j ]->Dependency() ) ; // mkr : IPAL11394 (add port to !EndSwitch! node)
2447               }
2448               else {
2449                 aPort = anEndOfSwitch->OutStreamPort( myStreamSwitchPorts[ j ]->Name(), myStreamSwitchPorts[ j ]->Type(), myStreamSwitchPorts[ j ]->Dependency() ) ; // mkr : IPAL11394 (add port to !EndSwitch! node)
2450               }
2451             }
2452           }
2453           RetVal = true ;
2454         }
2455         else {
2456           RetVal = false ;
2457           break ;
2458         }
2459       }
2460     }
2461     if ( RetVal ) {
2462       SUPERV::ListOfLinks * aGraphLinks = aGraph->GLinks() ;
2463       SUPERV::ListOfPorts * aGraphPorts = aGraph->Ports() ;
2464 //      cout << "Graph_Impl::Merge " << aGraphLinks->length() << " links " << aGraphPorts->length() << " GraphPorts"
2465 //           << endl ;
2466       for ( i = 0 ; i < (int ) aGraphLinks->length() ; i++ ) {
2467         SUPERV::Link_var aLink = (*aGraphLinks)[ i ] ;
2468         SUPERV::Port_var OutPort = aLink->OutPort() ;
2469         SUPERV::Port_var InPort = aLink->InPort() ;
2470         string * aLinkFromNodeName = new string( OutPort->Node()->Name() ) ;
2471         string * aLinkToNodeName = new string( InPort->Node()->Name() ) ;
2472         RetVal = DataFlowEditor()->AddLink( DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] )->Name() ,
2473                                            OutPort->Name() ,
2474                                            DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] )->Name() ,
2475                                            InPort->Name() ) ;
2476         if ( RetVal ) {
2477           CORBA::Long j ;
2478           for ( j = 1 ; j <= aLink->CoordsSize() ; j++ ) {
2479             CORBA::Long X , Y ;
2480             RetVal = aLink->Coords( j , X , Y ) ;
2481             if ( !RetVal )
2482               break ;
2483             RetVal = DataFlowEditor()->AddLinkCoord( DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] )->Name() ,
2484                                                      OutPort->Name() ,
2485                                                      DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] )->Name() ,
2486                                                      InPort->Name() ,
2487                                                      j , X , Y ) ;
2488             if ( !RetVal ) {
2489               break ;
2490             }
2491           }
2492         }
2493         delete aLinkFromNodeName ;
2494         delete aLinkToNodeName ;
2495         if ( !RetVal ) {
2496           break ;
2497         }
2498       }
2499       if ( RetVal ) {
2500         for ( i = 0 ; i < (int ) aGraphPorts->length() ; i++ ) {
2501           SUPERV::Port_var aPort = (*aGraphPorts)[ i ] ;
2502           if ( !aPort->IsGate() ) {
2503             MESSAGE( "Graph_Impl::Merge " << i << ". " << aPort->Node()->Name() << " " << aPort->Name() ) ;
2504             char * aPortName = aPort->Name() ;
2505             char * aNodeName = new char[ strlen( aPortName ) + 1 ] ;
2506             strcpy( aNodeName , aPortName ) ;
2507 //            char * thePortName = strchr( aNodeName , '\\' ) ;
2508             char * thePortName = aNodeName ;
2509             while ( ( thePortName = strchr( thePortName , '_' ) ) ) {
2510               if ( thePortName[1] == '_' ) {
2511                 thePortName[ 0 ] = '\0' ;
2512                 break ;
2513               }
2514               else {
2515                 thePortName = &thePortName[2] ;
2516               }
2517             }
2518             bool hasinput = aGraph->Node( aNodeName )->Port( thePortName + 2 )->HasInput() ;
2519 //            cout << "Graph_Impl::Merge " << " aNodeName " << aNodeName << " aPort " << thePortName + 1
2520 //                 << " HasInput " << hasinput << endl ;
2521             if ( hasinput ) {
2522               RetVal = DataFlowEditor()->AddInputData( DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aNodeName ] )->Name() ,
2523                                                        thePortName + 2 ,
2524                                                        *(aPort->ToAny()) ) ;
2525             }
2526             delete [] aNodeName ;
2527             if ( !RetVal ) {
2528               break ;
2529             }
2530           }
2531         }
2532       }
2533     }
2534   }
2535   MESSAGE( "Graph_Impl::Merge returns " << RetVal ) ;
2536   endService( "Graph_Impl::Merge" );
2537   return RetVal ;
2538 }
2539
2540 SUPERV::StreamGraph_ptr Graph_Impl::ToStreamGraph() {
2541   SUPERV::StreamGraph_var iobject = SUPERV::StreamGraph::_nil() ;
2542   beginService( "Graph_Impl::ToStreamGraph" );
2543   if ( IsStreamGraph() && !IsMacro() ) {
2544 //  StreamGraph_Impl * myStreamGraph = new StreamGraph_Impl( _Orb , _Poa , _ContId ,
2545 //                                          instanceName() , interfaceName() ) ;
2546 //  PortableServer::ObjectId * id = myStreamGraph->getId() ;
2547 //  CORBA::Object_var obj = _poa->id_to_reference(*id);
2548     iobject = SUPERV::StreamGraph::_narrow( ObjRef() ) ;
2549     if ( CORBA::is_nil( iobject ) ) {
2550       MESSAGE( "ToStreamGraph of " << Name() << " (IsStreamGraph) --> nil reference" ) ;
2551     }
2552   }
2553   else {
2554     MESSAGE( "ToStreamGraph of " << Name() << " (IsNOTStreamGraph) --> nil reference" ) ;
2555   }
2556   endService( "Graph_Impl::ToStreamGraph" );
2557   return SUPERV::StreamGraph::_duplicate( iobject ) ;
2558 }
2559
2560 /**
2561  * Destroy Executor and use only Editor and its data model
2562  */
2563 void Graph_Impl::Editing() {
2564   if ( DataFlowEditor() && DataFlowExecutor() ) {
2565     delete DataFlowExecutor() ;
2566     DataFlowEditor()->Executor( NULL );
2567   }
2568 }
2569
2570 /**
2571  * Returns the default name of container for C component
2572  */
2573 char* Graph_Impl::DefaultCContainerName() {
2574   return ( CORBA::string_dup( FACTORYSERVER ) );
2575 }
2576
2577 /**
2578  * Returns the default name of container for Python component
2579  */
2580 char* Graph_Impl::DefaultPythonContainerName() {
2581   return ( CORBA::string_dup( FACTORYSERVERPY ) );
2582 }
2583
2584 /*! 
2585  * Returns the last container name associated with theComponentName component
2586  */ 
2587 char* Graph_Impl::ContainerNameForComponent( const char * theComponentName ) {
2588   const char* aContainer = DataFlowEditor()->Graph()->RetrieveFromMapOfComponentNameContainer(theComponentName);
2589   if ( aContainer )
2590     return my_strdup(aContainer);
2591   else
2592     return "";
2593 }