]> SALOME platform Git repositories - modules/superv.git/blob - src/Supervision/Graph_Impl.cxx
Salome HOME
End of developpement/test of Switch Python Nodes
[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 char * Graph_Impl::Messages() {
1659   beginService( "Graph_Impl::Messages" );
1660   string Messages  ;
1661   MESSAGE( "Graph_Impl::Messages IsEditing " << DataFlowEditor()->IsEditing() ) ;
1662   Messages = DataFlowEditor()->Graph()->Messages() ;
1663   DataFlowEditor()->Graph()->ReSetMessages() ;
1664   if ( DataFlowExecutor() ) {
1665     Messages += DataFlowExecutor()->Graph()->Messages() ;
1666     DataFlowExecutor()->Graph()->ReSetMessages() ;
1667   }
1668   endService( "Graph_Impl::Messages" );
1669   return ( CORBA::string_dup( Messages.c_str() ) ) ;
1670 }
1671
1672 bool Graph_Impl::IsValid() {
1673 //  beginService( "Graph_Impl::IsValid" );
1674   bool RetVal = false ;
1675   if ( !IsMacro() ) {
1676     RetVal = DataFlowEditor()->IsValid() ;
1677   }
1678 //  endService( "Graph_Impl::IsValid" );
1679   return RetVal ;
1680 }
1681 bool Graph_Impl::IsExecutable() {
1682 //  beginService( "Graph_Impl::IsExecutable" );
1683   bool RetVal = false ;
1684
1685   // asv : 15.11.04 : added "&& GraphMacroLevel() == 0" -> 
1686   // subgraphs are not executable by themselves, RetVal = false..
1687   if ( !IsMacro() && DataFlowEditor()->Graph()->GraphMacroLevel() == 0 ) {
1688     RetVal = DataFlowEditor()->IsExecutable() ;
1689   }
1690 //  endService( "Graph_Impl::IsExecutable" );
1691   return RetVal ;
1692 }
1693
1694 bool Graph_Impl::IsEditing() {
1695 /*
1696   bool RetVal = false ;
1697   if ( !IsMacro() ) {
1698     RetVal = DataFlowEditor()->IsEditing() ;
1699   }
1700   return RetVal ;
1701 */
1702   if ( IsMacro() )
1703     return false;
1704   return !IsExecuting();
1705 }
1706
1707 bool Graph_Impl::IsExecuting() {
1708 /*
1709   bool RetVal = false ;
1710   if ( !IsMacro() ) {
1711     RetVal = !DataFlowEditor()->IsEditing() ;
1712   }
1713   return RetVal ;
1714 */
1715   return CNode_Impl::IsExecuting();
1716 }
1717
1718 bool Graph_Impl::IsReadOnly() {
1719 //  beginService( "Graph_Impl::IsExecuting" );
1720   bool RetVal = false ;
1721   if ( !IsMacro() ) {
1722     RetVal = DataFlowEditor()->IsReadOnly() ;
1723   }
1724 //  endService( "Graph_Impl::IsExecuting" );
1725   return RetVal ;
1726 }
1727
1728 long Graph_Impl::LevelMax() {
1729 //  beginService( "Graph_Impl::LevelMax" );
1730   long RetVal = 0 ;
1731   if ( !IsMacro() ) {
1732     RetVal = DataFlowEditor()->LevelMax() ;
1733   }
1734 //  endService( "Graph_Impl::LevelMax" );
1735   return RetVal ;
1736 }
1737 SUPERV::ListOfNodes * Graph_Impl::LevelNodes(long aLevel ) {
1738 //  beginService( "Graph_Impl::LevelNodes" );
1739   SUPERV::ListOfNodes_var RetVal = new SUPERV::ListOfNodes;
1740   if ( !IsMacro() ) {
1741     int i ;
1742     SUPERV::ListOfStrings_var Nodes = DataFlowEditor()->LevelNodes( aLevel ) ;
1743 //  RetVal->length( Nodes->length() );
1744     for ( i = 0 ; i < (int ) Nodes->length() ; i++ ) {
1745 //    char * aNode = Nodes[ i ] ;
1746       GraphBase::ComputingNode * aNode = DataFlowEditor()->Graph()->GetChangeGraphNode( Nodes[ i ] ) ;
1747       RetVal = SetNode( RetVal , aNode ) ;
1748 //    cout << "Graph_Impl::LevelNodes( " << aLevel << " ) " << aNode->Name() << endl ;
1749 //    CNode_Impl * myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
1750 //                               instanceName() , interfaceName() ,
1751 //                               DataFlowEditor() ,
1752 //                               (GraphEditor::InNode * ) DataFlowEditor()->GetChangeGraphNode( aNode )->GetInNode() ) ;
1753 //    PortableServer::ObjectId * id = myNode->getId() ;
1754 //    CORBA::Object_var obj = _poa->id_to_reference(*id);
1755 //    SUPERV::CNode_var iobject ;
1756 //    iobject = SUPERV::CNode::_narrow(obj) ;
1757 //    RetVal[i] = SUPERV::CNode::_duplicate( iobject ) ;
1758     }
1759   }
1760 //  endService( "Graph_Impl::LevelNodes" );
1761   return ( RetVal._retn() ) ;
1762 }
1763 long Graph_Impl::ThreadsMax() {
1764 //  beginService( "Graph_Impl::ThreadsMax" );
1765   long RetVal = 0 ;
1766   if ( !IsMacro() ) {
1767     RetVal =  DataFlowEditor()->ThreadsMax() ;
1768   }
1769 //  endService( "Graph_Impl::ThreadsMax" );
1770   return RetVal ;
1771 }
1772 long Graph_Impl::Threads() {
1773 //  beginService( "Node_Impl::Threads" );
1774   long RetVal = false ;
1775   if ( !IsMacro() ) {
1776     RetVal = DataFlowExecutor()->Threads() ;
1777   }
1778 //  endService( "Node_Impl::Threads" );
1779   return RetVal ;
1780 }
1781 long Graph_Impl::SuspendedThreads() {
1782 //  beginService( "Node_Impl::SuspendedThreads" );
1783   long RetVal = false ;
1784   if ( !IsMacro() ) {
1785     RetVal = DataFlowExecutor()->SuspendedThreads() ;
1786   }
1787 //  endService( "Node_Impl::SuspendedThreads" );
1788   return RetVal ;
1789 }
1790
1791 bool Graph_Impl::Begin() {
1792   bool RetVal = false ;
1793   if ( DataFlowEditor()->IsEditing() ) {
1794     if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1795       perror("pthread_mutex_lock _MutexExecutorWait") ;
1796       exit( 0 ) ;
1797     }
1798     DataFlowEditor()->Graph()->ReSetMessages() ; // ==> Only one set of errors messages ...
1799     if ( DataFlowExecutor() ) {
1800       MESSAGE( "Graph_Impl::Begin " << DataFlowExecutor()->Threads() << " threads" )
1801       Editing(); // just in case it was not called before by GUI..
1802     }
1803     if ( DataFlowEditor()->IsExecutable() ) {
1804       DataFlowEditor()->EditedAfterExecution( false ) ;
1805       GraphBase::ListOfSGraphs * myListOfGraphs = DataFlowEditor()->GetDataFlows() ;
1806
1807       GraphExecutor::DataFlow * aDataFlowExecutor ;
1808       string dbgfile ;
1809       CreateExecutor( _Orb , instanceName() , (*myListOfGraphs)[ 0 ].Info.theName.c_str() , Kind() ,
1810                       dbgfile , &aDataFlowExecutor ) ;
1811
1812       MESSAGE( "Graph_Impl::Begin : DataFlowExecutor created" );
1813       if ( !CORBA::is_nil( LoadDataFlows( aDataFlowExecutor, myListOfGraphs , 0 ) ) ) 
1814         RetVal = true ;
1815   
1816       if ( RetVal )
1817         DataFlowExecutor()->Graph()->SetObjImpl( DataFlowEditor()->Graph()->ObjImpl() ) ;
1818     
1819     }
1820     if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1821       perror("pthread_mutex_unlock _MutexExecutorWait") ;
1822       exit( 0 ) ;
1823     }
1824   }
1825   return RetVal ;
1826 }
1827
1828 /**
1829  * run() : was created in order to reduce code dublication, Run() and Start() do the same thing
1830  *         except for final call to Executor->Run( bool ) - Run() calls with AndSuspend=false
1831  *         and Start() calls with AndSuspend=true flag.  The rest of the actions are the same:
1832  *         1. if a MacroNode's coupled graph (MacroLevel>0) -> simply Run() it.
1833  *         2. if a Supergraph -> create executor, load dataflow in it (done in Begin()), then - Run() it.
1834  */
1835 bool Graph_Impl::run( const bool andSuspend ) {
1836   bool RetVal = false ;
1837
1838   // if Editing or Finished state, and, naturally, 'this' is not a MacroNode. 
1839   if ( ( DataFlowEditor()->IsEditing() || IsDone() ) && !IsMacro() ) {
1840
1841     if ( DataFlowEditor()->Graph()->GraphMacroLevel() ) {
1842       // MacroGraph's Executor was created in recursive function LoadDataflows(Executor), called from
1843       // Begin() of Supergraph.  See Begin() and LoadDataflows(Executor) for details.
1844       RetVal = true ; 
1845     }
1846     else {
1847       // Create Executor instance and its datamodel
1848       RetVal = Begin() ;
1849     }
1850     if ( RetVal ) {
1851       // Set Executing flag to avoid edition operations during execution, EditedAfterExecution=false
1852       DataFlowEditor()->Executing() ;
1853       DataFlowEditor()->EditedAfterExecution( false ); 
1854
1855       // THE MAIN RUN METHOD
1856       RetVal = DataFlowExecutor()->Run( andSuspend );
1857     }
1858   }
1859   return RetVal ;
1860
1861 }
1862
1863 /**
1864  * Run() - called on "Execute" command
1865  */
1866 bool Graph_Impl::Run() {
1867   beginService( "Graph_Impl::Run" );
1868   bool RetVal = run( /*andSuspend=*/false ) ;
1869   MESSAGE( "Graph_Impl::Run " << DataFlowEditor()->Graph()->Name() << " RetVal " << RetVal ) ;
1870   endService( "Graph_Impl::Run" );
1871   return RetVal ;
1872 }
1873
1874 /**
1875  * Run() - called on "Execute step-by-step" command
1876  */
1877 bool Graph_Impl::Start() {
1878   beginService( "Graph_Impl::Start" );
1879   bool RetVal = run( /*andSuspend=*/true ) ;
1880   MESSAGE( "Graph_Impl::Start " << DataFlowEditor()->Graph()->Name() << " RetVal " << RetVal ) ;
1881   endService( "Graph_Impl::Start" );
1882   return RetVal ;
1883 }
1884
1885 bool Graph_Impl::EventNoW( SUPERV::CNode_out aNode ,
1886                            SUPERV::GraphEvent & anEvent ,
1887                            SUPERV::GraphState & aState ) {
1888   bool RetVal = false ;
1889   char * aNodeName = NULL ;
1890   SUPERV::GraphEvent theEvent = SUPERV::UndefinedEvent ;
1891   SUPERV::GraphState theState = SUPERV::UndefinedState ;
1892   if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1893     perror("pthread_mutex_lock _MutexExecutorWait") ;
1894     exit( 0 ) ;
1895   }
1896   if ( DataFlowExecutor() && !IsMacro() &&
1897        ( DataFlowExecutor()->GetListSize() || !DataFlowEditor()->IsEditing() ) ) {
1898     RetVal = DataFlowExecutor()->Event( & aNodeName , theEvent , theState , false ) ;
1899 //  endService( "Graph_Impl::Event" );
1900     if ( strlen( aNodeName ) ) {
1901       if ( strcmp( aNodeName , Name() ) ) {
1902         aNode = Node( aNodeName ) ;
1903       }
1904       else {
1905         aNode = Node() ;
1906       }
1907     }
1908     else {
1909       aNode = SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
1910     }
1911 //    cout << "Graph_Impl::EventNoW " << aNode->Name() << " QSize " << DataFlowExecutor()->GetListSize() << endl ;
1912   }
1913   else {
1914 //    cout << "Graph_Impl::EventNoW NO DataFlowExecutor() or QSize=0 " << endl ;
1915   }
1916   if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1917     perror("pthread_mutex_unlock _MutexExecutorWait") ;
1918     exit( 0 ) ;
1919   }
1920   anEvent = theEvent ;
1921   aState = theState ;
1922   return RetVal ;
1923 }
1924
1925 bool Graph_Impl::Event( SUPERV::CNode_out aNode ,
1926                         SUPERV::GraphEvent & anEvent ,
1927                         SUPERV::GraphState & aState ) {
1928 //  beginService( "Graph_Impl::Event" );
1929   bool RetVal = false ;
1930   char * aNodeName = NULL ;
1931   SUPERV::GraphEvent theEvent = SUPERV::UndefinedEvent ;
1932   SUPERV::GraphState theState = SUPERV::UndefinedState ;
1933   if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1934     perror("pthread_mutex_lock _MutexExecutorWait") ;
1935     exit( 0 ) ;
1936   }
1937   if ( DataFlowExecutor() && !IsMacro() &&
1938        ( DataFlowExecutor()->GetListSize() || !DataFlowEditor()->IsEditing() ) ){
1939     RetVal = DataFlowExecutor()->Event( & aNodeName , theEvent , theState ) ;
1940 //  endService( "Graph_Impl::Event" );
1941     if ( strlen( aNodeName ) ) {
1942       if ( strcmp( aNodeName , Name() ) ) {
1943         aNode = Node( aNodeName ) ;
1944       }
1945       else {
1946         aNode = Node() ;
1947       }
1948     }
1949     else {
1950       aNode = SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
1951     }
1952 //    cout << "Graph_Impl::Event " << aNode->Name() << " QSize " << DataFlowExecutor()->GetListSize() << endl ;
1953   }
1954   else {
1955 //    cout << "Graph_Impl::Event NO DataFlowExecutor() or QSize=0 " << endl ;
1956   }
1957   if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1958     perror("pthread_mutex_unlock _MutexExecutorWait") ;
1959     exit( 0 ) ;
1960   }
1961   anEvent = theEvent ;
1962   aState = theState ;
1963
1964   return RetVal ;
1965 }
1966
1967 bool Graph_Impl::EventW( SUPERV::CNode_out aNode ,
1968                          SUPERV::GraphEvent & anEvent ,
1969                          SUPERV::GraphState & aState ) {
1970 //  beginService( "Graph_Impl::EventW" );
1971   bool RetVal = false ;
1972   char * aNodeName = NULL ;
1973   SUPERV::GraphEvent theEvent = SUPERV::UndefinedEvent ;
1974   SUPERV::GraphState theState = SUPERV::UndefinedState ;
1975   if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1976     perror("pthread_mutex_lock _MutexExecutorWait") ;
1977     exit( 0 ) ;
1978   }
1979   if ( DataFlowExecutor() && !IsMacro() &&
1980        ( DataFlowExecutor()->GetListSize() || !DataFlowEditor()->IsEditing() ) ) {
1981     RetVal = DataFlowExecutor()->EventW( & aNodeName , theEvent , theState ) ;
1982     if ( RetVal && strcmp( aNodeName , Name() ) ) {
1983       aNode = Node( aNodeName ) ;
1984     }
1985     else {
1986       aNode = Node() ;
1987     }
1988   }
1989   if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1990     perror("pthread_mutex_unlock _MutexExecutorWait") ;
1991     exit( 0 ) ;
1992   }
1993   anEvent = theEvent ;
1994   aState = theState ;
1995 //  endService( "Graph_Impl::EventW" );
1996   return RetVal ;
1997 }
1998
1999 long Graph_Impl::EventQSize() {
2000 //  beginService( "Graph_Impl::EventQSize" );
2001   long QSize = -1 ;
2002   if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
2003     perror("pthread_mutex_lock _MutexExecutorWait") ;
2004     exit( 0 ) ;
2005   }
2006   if ( DataFlowExecutor() && !IsMacro() ) {
2007     QSize = DataFlowExecutor()->EventQSize() ;
2008   }
2009   if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
2010     perror("pthread_mutex_unlock _MutexExecutorWait") ;
2011     exit( 0 ) ;
2012   }
2013 //  endService( "Graph_Impl::EventQSize" );
2014   return QSize ;
2015 }
2016
2017 long Graph_Impl::LastLevelDone() {
2018 //  beginService( "Graph_Impl::LastLevelDone" );
2019   if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
2020     perror("pthread_mutex_lock _MutexExecutorWait") ;
2021     exit( 0 ) ;
2022   }
2023   long RetVal = 0 ;
2024   if ( DataFlowExecutor() && !IsMacro() ) {
2025     RetVal = DataFlowExecutor()->LastLevelDone() ;
2026   }
2027   if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
2028     perror("pthread_mutex_unlock _MutexExecutorWait") ;
2029     exit( 0 ) ;
2030   }
2031 //  endService( "Graph_Impl::LastLevelDone" );
2032   return RetVal ;
2033 }
2034
2035 long Graph_Impl::SubGraphsNumber() {
2036 //  beginService( "Graph_Impl::SubGraphsNumber" );
2037   long RetVal = 0 ;
2038   if ( DataFlowEditor()->IsExecutable() && !IsMacro() ) {
2039     RetVal = DataFlowEditor()->SubGraphsNumber() ;
2040   }
2041 //  endService( "Graph_Impl::SubGraphsNumber" );
2042   return RetVal ;
2043 }
2044
2045 SUPERV::ListOfNodes * Graph_Impl::SubGraphsNodes( const long aSubGraphNumber ) {
2046   beginService( "Graph_Impl::SubGraphsNodes" );
2047   SUPERV::ListOfNodes_var RetVal = new SUPERV::ListOfNodes ;
2048   if ( DataFlowEditor()->IsEditing() && !IsMacro() ) {
2049     SUPERV::ListOfNodes * aGraphNodes = Nodes() ;
2050     int i ;
2051 // ComputingNodes
2052     for ( i = 0 ; i < (int ) aGraphNodes->CNodes.length() ; i++ ) {
2053       SUPERV::CNode_var aNode = (aGraphNodes->CNodes)[ i ] ;
2054       if ( aNode->SubGraph() == aSubGraphNumber ) {
2055         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
2056       }
2057     }
2058 // FactoryNodes
2059     for ( i = 0 ; i < (int ) aGraphNodes->FNodes.length() ; i++ ) {
2060       SUPERV::FNode_var aNode = (aGraphNodes->FNodes)[ i ] ;
2061       if ( aNode->SubGraph() == aSubGraphNumber ) {
2062         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
2063       }
2064     }
2065 // InLineNodes
2066     for ( i = 0 ; i < (int ) aGraphNodes->INodes.length() ; i++ ) {
2067       SUPERV::INode_var aNode = (aGraphNodes->INodes)[ i ] ;
2068       if ( aNode->SubGraph() == aSubGraphNumber ) {
2069         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
2070       }
2071     }
2072 // GOTONodes
2073     for ( i = 0 ; i < (int ) aGraphNodes->GNodes.length() ; i++ ) {
2074       SUPERV::GNode_var aNode = (aGraphNodes->GNodes)[ i ] ;
2075       if ( aNode->SubGraph() == aSubGraphNumber ) {
2076         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
2077       }
2078     }
2079 // LoopNodes
2080     for ( i = 0 ; i < (int ) aGraphNodes->LNodes.length() ; i++ ) {
2081       SUPERV::LNode_var aNode = (aGraphNodes->LNodes)[ i ] ;
2082       if ( aNode->SubGraph() == aSubGraphNumber ) {
2083         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
2084       }
2085     }
2086 // EndLoopNodes
2087     for ( i = 0 ; i < (int ) aGraphNodes->ELNodes.length() ; i++ ) {
2088       SUPERV::ELNode_var aNode = (aGraphNodes->ELNodes)[ i ] ;
2089       if ( aNode->SubGraph() == aSubGraphNumber ) {
2090         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
2091       }
2092     }
2093 // SwitchNodes
2094     for ( i = 0 ; i < (int ) aGraphNodes->SNodes.length() ; i++ ) {
2095       SUPERV::SNode_var aNode = (aGraphNodes->SNodes)[ i ] ;
2096       if ( aNode->SubGraph() == aSubGraphNumber ) {
2097         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
2098       }
2099     }
2100 // EndSwitchNodes
2101     for ( i = 0 ; i < (int ) aGraphNodes->ESNodes.length() ; i++ ) {
2102       SUPERV::ESNode_var aNode = (aGraphNodes->ESNodes)[ i ] ;
2103       if ( aNode->SubGraph() == aSubGraphNumber ) {
2104         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
2105       }
2106     }
2107   }
2108   endService( "Graph_Impl::SubGraphsNodes" );
2109   return ( RetVal._retn() ) ;
2110 }
2111
2112 bool Graph_Impl::Merge(const SUPERV::Graph_ptr aGraph ) {
2113 //  beginService( "Graph_Impl::Merge" );
2114   bool RetVal = true ;
2115   if ( !IsMacro() ) {
2116     map< string , int > aMapOfNodes ;
2117     RetVal = Merge( aGraph , aMapOfNodes ) ;
2118   }
2119 //  endService( "Graph_Impl::Merge" );
2120   return RetVal ;
2121 }
2122
2123 bool Graph_Impl::Merge(const SUPERV::Graph_ptr aGraph , map< string , int > & aMapOfNodes ) {
2124   beginService( "Graph_Impl::Merge" );
2125   bool RetVal = true ;
2126   if ( DataFlowEditor()->IsEditing() && !IsMacro() ) {
2127     SUPERV::ListOfNodes * aGraphNodes = aGraph->Nodes() ;
2128     int i ;
2129     SUPERV::Port_ptr aPort ;
2130 //    SUPERV::StreamPort_ptr aStreamPort ;
2131 // ComputingNodes
2132     for ( i = 0 ; i < (int ) aGraphNodes->CNodes.length() ; i++ ) {
2133       SUPERV::CNode_var aNode = (aGraphNodes->CNodes)[ i ] ;
2134       SUPERV::CNode_ptr myNode = CNode( *(aNode->Service()) ) ;
2135       if ( !CORBA::is_nil( myNode ) ) {
2136         myNode->SetName( aNode->Name() ) ;
2137         myNode->SetAuthor( aNode->Author() ) ;
2138         myNode->SetComment( aNode->Comment() ) ;
2139         myNode->Coords( aNode->X() , aNode->Y() ) ;
2140         string * aNodetheName = new string( aNode->Name() ) ;
2141         aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
2142         delete aNodetheName ;
2143         RetVal = true ;
2144       }
2145       else {
2146         RetVal = false ;
2147         break ;
2148       }
2149 // The following informations are now in the service from SALOME_ModuleCatalog
2150 //      SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
2151 //      int j ;
2152 //      for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
2153 //        if ( myStreamPorts[ j ]->IsInput() && myStreamPorts[ j ]->IsDataStream() ) {
2154 //          aStreamPort = myNode->InStreamPort( myStreamPorts[ j ]->Name() , myStreamPorts[ j ]->Type() ) ;
2155 //        }
2156 //        else if ( myStreamPorts[ j ]->IsDataStream() ) {
2157 //          aStreamPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name() , myStreamPorts[ j ]->Type() ) ;
2158 //        }
2159 //      }
2160     }
2161 // FactoryNodes
2162     if ( RetVal ) {
2163       for ( i = 0 ; i < (int ) aGraphNodes->FNodes.length() ; i++ ) {
2164         SUPERV::FNode_var aNode = (aGraphNodes->FNodes)[ i ] ;
2165         SUPERV::FNode_ptr myNode = FNode( aNode->GetComponentName() ,
2166                                           aNode->GetInterfaceName() ,
2167                                           *(aNode->Service()) ) ;
2168         if ( !CORBA::is_nil( myNode ) ) {
2169           myNode->SetName( aNode->Name() ) ;
2170           myNode->SetAuthor( aNode->Author() ) ;
2171           myNode->SetComment( aNode->Comment() ) ;
2172           myNode->Coords( aNode->X() , aNode->Y() ) ;
2173           string * aNodetheName = new string( aNode->Name() ) ;
2174           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
2175           delete aNodetheName ;
2176           RetVal = true ;
2177         }
2178         else {
2179           RetVal = false ;
2180           break ;
2181         }
2182 // The following informations are now in the service from SALOME_ModuleCatalog
2183 //        SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
2184 //        int j ;
2185 //        for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
2186 //          if ( myStreamPorts[ j ]->IsInput() && myStreamPorts[ j ]->IsDataStream() ) {
2187 //            aStreamPort = myNode->InStreamPort( myStreamPorts[ j ]->Name() , myStreamPorts[ j ]->Type() ) ;
2188 //          }
2189 //          else if ( myStreamPorts[ j ]->IsDataStream() ) {
2190 //            aStreamPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name() , myStreamPorts[ j ]->Type() ) ;
2191 //          }
2192 //        }
2193       }
2194     }
2195 // InLineNodes
2196     if ( RetVal ) {
2197       for ( i = 0 ; i < (int ) aGraphNodes->INodes.length() ; i++ ) {
2198         SUPERV::INode_var aNode = (aGraphNodes->INodes)[ i ] ;
2199         SUPERV::INode_ptr myNode = INode( aNode->PyFuncName() , *(aNode->PyFunction()) ) ;
2200         if ( !CORBA::is_nil( myNode ) ) {
2201           myNode->SetName( aNode->Name() ) ;
2202           myNode->SetAuthor( aNode->Author() ) ;
2203           myNode->SetComment( aNode->Comment() ) ;
2204           myNode->Coords( aNode->X() , aNode->Y() ) ;
2205           string * aNodetheName = new string( aNode->Name() ) ;
2206           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
2207           delete aNodetheName ;
2208           SUPERV::ListOfPorts myPorts = *(aNode->Ports()) ;
2209           int j ;
2210           for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
2211             if ( myPorts[ j ]->IsInput() ) {
2212               aPort = myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2213             }
2214             else {
2215               aPort = myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2216             }
2217           }
2218           if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
2219             SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
2220             for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
2221               if ( myStreamPorts[ j ]->IsInput() ) {
2222                 aPort = myNode->InStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
2223               }
2224               else {
2225                 aPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
2226               }
2227             }
2228           }
2229           RetVal = true ;
2230         }
2231         else {
2232           RetVal = false ;
2233           break ;
2234         }
2235       }
2236     }
2237 // GOTONodes
2238     if ( RetVal ) {
2239       for ( i = 0 ; i < (int ) aGraphNodes->GNodes.length() ; i++ ) {
2240         SUPERV::GNode_var aNode = (aGraphNodes->GNodes)[ i ] ;
2241         SUPERV::GNode_ptr myNode = GNode( aNode->PyFuncName() , *(aNode->PyFunction()) , aNode->Coupled()->Name() ) ;
2242         if ( !CORBA::is_nil( myNode ) ) {
2243           myNode->SetName( aNode->Name() ) ;
2244           myNode->SetAuthor( aNode->Author() ) ;
2245           myNode->SetComment( aNode->Comment() ) ;
2246           myNode->Coords( aNode->X() , aNode->Y() ) ;
2247           string * aNodetheName = new string( aNode->Name() ) ;
2248           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
2249           delete aNodetheName ;
2250           SUPERV::ListOfPorts myPorts = *(aNode->Ports()) ;
2251           int j ;
2252           for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
2253             if ( myPorts[ j ]->IsInput() ) {
2254               aPort = myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2255             }
2256             else {
2257               aPort = myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2258             }
2259           }
2260           if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
2261             SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
2262             for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
2263               if ( myStreamPorts[ j ]->IsInput() ) {
2264                 aPort = myNode->InStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
2265               }
2266               else {
2267                 aPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
2268               }
2269             }
2270           }
2271           RetVal = true ;
2272         }
2273         else {
2274           RetVal = false ;
2275           break ;
2276         }
2277       }
2278     }
2279 // LoopNodes
2280     if ( RetVal ) {
2281       for ( i = 0 ; i < (int ) aGraphNodes->LNodes.length() ; i++ ) {
2282         SUPERV::LNode_var aNode = (aGraphNodes->LNodes)[ i ] ;
2283         SUPERV::INode_ptr anEndOfLoop ;
2284         SUPERV::LNode_ptr myNode = LNode( aNode->PyInitName() ,
2285                                           *(aNode->PyInit()) ,
2286                                           aNode->PyMoreName() ,
2287                                           *(aNode->PyMore()) ,
2288                                           aNode->PyNextName() ,
2289                                           *(aNode->PyNext()) ,
2290                                           anEndOfLoop ) ;
2291         if ( !CORBA::is_nil( myNode ) ) {
2292           myNode->SetName( aNode->Name() ) ;
2293           myNode->SetAuthor( aNode->Author() ) ;
2294           myNode->SetComment( aNode->Comment() ) ;
2295           myNode->Coords( aNode->X() , aNode->Y() ) ;
2296           string * aNodetheName = new string( aNode->Name() ) ;
2297           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
2298           delete aNodetheName ;
2299           SUPERV::ListOfPorts myPorts = *(aNode->Ports()) ;
2300           int j ;
2301           for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
2302             if ( myPorts[ j ]->IsInput() ) {
2303               aPort = myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2304             }
2305             else {
2306               aPort = myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2307             }
2308           }
2309           if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
2310             SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
2311             for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
2312               if ( myStreamPorts[ j ]->IsInput() ) {
2313                 aPort = myNode->InStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
2314               }
2315               else {
2316                 aPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
2317               }
2318             }
2319           }
2320           SUPERV::INode_ptr myEndOfLoop = aNode->Coupled() ;
2321           anEndOfLoop->SetName( myEndOfLoop->Name() ) ;
2322           anEndOfLoop->SetAuthor( myEndOfLoop->Author() ) ;
2323           anEndOfLoop->SetComment( myEndOfLoop->Comment() ) ;
2324           anEndOfLoop->Coords( myEndOfLoop->X() , myEndOfLoop->Y() ) ;
2325           anEndOfLoop->SetPyFunction( myEndOfLoop->PyFuncName() , *(myEndOfLoop->PyFunction()) ) ;
2326           aNodetheName = new string( myEndOfLoop->Name() ) ;
2327           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( anEndOfLoop->Name() ) ;
2328           if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
2329             SUPERV::ListOfStreamPorts myStreamLoopPorts = *(myEndOfLoop->StreamPorts()) ;
2330             for ( j = 0 ; j < (int ) myStreamLoopPorts.length() ; j++ ) {
2331               if ( myStreamLoopPorts[ j ]->IsInput() ) {
2332                 aPort = myNode->InStreamPort( myStreamLoopPorts[ j ]->Name() , StringToDataStreamType( myStreamLoopPorts[ j ]->Type() ) , myStreamLoopPorts[ j ]->Dependency() ) ;
2333               }
2334               else {
2335                 aPort = myNode->OutStreamPort( myStreamLoopPorts[ j ]->Name() , StringToDataStreamType( myStreamLoopPorts[ j ]->Type() ) , myStreamLoopPorts[ j ]->Dependency() ) ;
2336               }
2337             }
2338           }
2339           delete aNodetheName ;
2340           RetVal = true ;
2341         }
2342         else {
2343           RetVal = false ;
2344           break ;
2345         }
2346       }
2347     }
2348 // SwitchNodes
2349     if ( RetVal ) {
2350       for ( i = 0 ; i < (int ) aGraphNodes->SNodes.length() ; i++ ) {
2351         SUPERV::SNode_var aNode = (aGraphNodes->SNodes)[ i ] ;
2352         SUPERV::INode_ptr anEndOfSwitch ;
2353         SUPERV::SNode_ptr myNode = SNode( aNode->PyFuncName() , *(aNode->PyFunction()) , anEndOfSwitch ) ;
2354         if ( !CORBA::is_nil( myNode ) ) {
2355           myNode->SetName( aNode->Name() ) ;
2356           myNode->SetAuthor( aNode->Author() ) ;
2357           myNode->SetComment( aNode->Comment() ) ;
2358           myNode->Coords( aNode->X() , aNode->Y() ) ;
2359           string * aNodetheName = new string( aNode->Name() ) ;
2360           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
2361           delete aNodetheName ;
2362           SUPERV::ListOfPorts myPorts = *(aNode->Ports()) ;
2363           int j ;
2364           for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
2365             if ( myPorts[ j ]->IsInput() ) {
2366               aPort = myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2367             }
2368             else {
2369               aPort = myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2370             }
2371           }
2372           if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
2373             SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
2374             for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
2375               if ( myStreamPorts[ j ]->IsInput() ) {
2376                 aPort = myNode->InStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
2377               }
2378               else {
2379                 aPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
2380               }
2381             }
2382           }
2383           SUPERV::INode_ptr myEndOfSwitch = aNode->Coupled() ;
2384           anEndOfSwitch->SetName( myEndOfSwitch->Name() ) ;
2385           anEndOfSwitch->SetAuthor( myEndOfSwitch->Author() ) ;
2386           anEndOfSwitch->SetComment( myEndOfSwitch->Comment() ) ;
2387           anEndOfSwitch->Coords( myEndOfSwitch->X() , myEndOfSwitch->Y() ) ;
2388           anEndOfSwitch->SetPyFunction( myEndOfSwitch->PyFuncName() , *(myEndOfSwitch->PyFunction()) ) ;
2389           aNodetheName = new string( myEndOfSwitch->Name() ) ;
2390           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( anEndOfSwitch->Name() ) ;
2391           delete aNodetheName ;
2392           myPorts = *(myEndOfSwitch->Ports()) ;
2393           for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
2394             if ( myPorts[ j ]->IsInput() ) {
2395               aPort = myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2396             }
2397             else {
2398               aPort = myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2399             }
2400           }
2401           if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
2402             SUPERV::ListOfStreamPorts myStreamSwitchPorts = *(myEndOfSwitch->StreamPorts()) ;
2403             for ( j = 0 ; j < (int ) myStreamSwitchPorts.length() ; j++ ) {
2404               if ( myStreamSwitchPorts[ j ]->IsInput() ) {
2405                 aPort = myNode->InStreamPort( myStreamSwitchPorts[ j ]->Name() , StringToDataStreamType( myStreamSwitchPorts[ j ]->Type() ) , myStreamSwitchPorts[ j ]->Dependency() ) ;
2406               }
2407               else {
2408                 aPort = myNode->OutStreamPort( myStreamSwitchPorts[ j ]->Name() , StringToDataStreamType( myStreamSwitchPorts[ j ]->Type() ) , myStreamSwitchPorts[ j ]->Dependency() ) ;
2409               }
2410             }
2411           }
2412           RetVal = true ;
2413         }
2414         else {
2415           RetVal = false ;
2416           break ;
2417         }
2418       }
2419     }
2420     if ( RetVal ) {
2421       SUPERV::ListOfLinks * aGraphLinks = aGraph->GLinks() ;
2422       SUPERV::ListOfPorts * aGraphPorts = aGraph->Ports() ;
2423 //      cout << "Graph_Impl::Merge " << aGraphLinks->length() << " links " << aGraphPorts->length() << " GraphPorts"
2424 //           << endl ;
2425       for ( i = 0 ; i < (int ) aGraphLinks->length() ; i++ ) {
2426         SUPERV::Link_var aLink = (*aGraphLinks)[ i ] ;
2427         SUPERV::Port_var OutPort = aLink->OutPort() ;
2428         SUPERV::Port_var InPort = aLink->InPort() ;
2429         string * aLinkFromNodeName = new string( OutPort->Node()->Name() ) ;
2430         string * aLinkToNodeName = new string( InPort->Node()->Name() ) ;
2431         RetVal = DataFlowEditor()->AddLink( DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] )->Name() ,
2432                                            OutPort->Name() ,
2433                                            DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] )->Name() ,
2434                                            InPort->Name() ) ;
2435         if ( RetVal ) {
2436           int j ;
2437           for ( j = 1 ; j <= aLink->CoordsSize() ; j++ ) {
2438             long X , Y ;
2439             RetVal = aLink->Coords( j , X , Y ) ;
2440             if ( !RetVal )
2441               break ;
2442             RetVal = DataFlowEditor()->AddLinkCoord( DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] )->Name() ,
2443                                                      OutPort->Name() ,
2444                                                      DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] )->Name() ,
2445                                                      InPort->Name() ,
2446                                                      j , X , Y ) ;
2447             if ( !RetVal ) {
2448               break ;
2449             }
2450           }
2451         }
2452         delete aLinkFromNodeName ;
2453         delete aLinkToNodeName ;
2454         if ( !RetVal ) {
2455           break ;
2456         }
2457       }
2458       if ( RetVal ) {
2459         for ( i = 0 ; i < (int ) aGraphPorts->length() ; i++ ) {
2460           SUPERV::Port_var aPort = (*aGraphPorts)[ i ] ;
2461           if ( !aPort->IsGate() ) {
2462             MESSAGE( "Graph_Impl::Merge " << i << ". " << aPort->Node()->Name() << " " << aPort->Name() ) ;
2463             char * aPortName = aPort->Name() ;
2464             char * aNodeName = new char[ strlen( aPortName ) + 1 ] ;
2465             strcpy( aNodeName , aPortName ) ;
2466 //            char * thePortName = strchr( aNodeName , '\\' ) ;
2467             char * thePortName = aNodeName ;
2468             while ( ( thePortName = strchr( thePortName , '_' ) ) ) {
2469               if ( thePortName[1] == '_' ) {
2470                 thePortName[ 0 ] = '\0' ;
2471                 break ;
2472               }
2473               else {
2474                 thePortName = &thePortName[2] ;
2475               }
2476             }
2477             bool hasinput = aGraph->Node( aNodeName )->Port( thePortName + 2 )->HasInput() ;
2478 //            cout << "Graph_Impl::Merge " << " aNodeName " << aNodeName << " aPort " << thePortName + 1
2479 //                 << " HasInput " << hasinput << endl ;
2480             if ( hasinput ) {
2481               RetVal = DataFlowEditor()->AddInputData( DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aNodeName ] )->Name() ,
2482                                                        thePortName + 2 ,
2483                                                        *(aPort->ToAny()) ) ;
2484             }
2485             delete [] aNodeName ;
2486             if ( !RetVal ) {
2487               break ;
2488             }
2489           }
2490         }
2491       }
2492     }
2493   }
2494   MESSAGE( "Graph_Impl::Merge returns " << RetVal ) ;
2495   endService( "Graph_Impl::Merge" );
2496   return RetVal ;
2497 }
2498
2499 SUPERV::StreamGraph_ptr Graph_Impl::ToStreamGraph() {
2500   SUPERV::StreamGraph_var iobject = SUPERV::StreamGraph::_nil() ;
2501   beginService( "Graph_Impl::ToStreamGraph" );
2502   if ( IsStreamGraph() && !IsMacro() ) {
2503 //  StreamGraph_Impl * myStreamGraph = new StreamGraph_Impl( _Orb , _Poa , _ContId ,
2504 //                                          instanceName() , interfaceName() ) ;
2505 //  PortableServer::ObjectId * id = myStreamGraph->getId() ;
2506 //  CORBA::Object_var obj = _poa->id_to_reference(*id);
2507     iobject = SUPERV::StreamGraph::_narrow( ObjRef() ) ;
2508     if ( CORBA::is_nil( iobject ) ) {
2509       MESSAGE( "ToStreamGraph of " << Name() << " (IsStreamGraph) --> nil reference" ) ;
2510     }
2511   }
2512   else {
2513     MESSAGE( "ToStreamGraph of " << Name() << " (IsNOTStreamGraph) --> nil reference" ) ;
2514   }
2515   endService( "Graph_Impl::ToStreamGraph" );
2516   return SUPERV::StreamGraph::_duplicate( iobject ) ;
2517 }
2518
2519 /**
2520  * Destroy Executor and use only Editor and its data model
2521  */
2522 void Graph_Impl::Editing() {
2523   if ( DataFlowEditor() && DataFlowExecutor() ) {
2524     delete DataFlowExecutor() ;
2525     DataFlowEditor()->Executor( NULL );
2526   }
2527 }
2528