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