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