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