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