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