]> SALOME platform Git repositories - modules/superv.git/blob - src/Supervision/Graph_Impl.cxx
Salome HOME
A special "Loading" state was implemented. It is returned to GUI if the correspondin...
[modules/superv.git] / src / Supervision / Graph_Impl.cxx
1 //  SUPERV Supervision : contains the implementation of interfaces of SuperVision described in SUPERV.idl
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : Graph_Impl.cxx
25 //  Author : Jean Rahuel
26 //  Module : SUPERV
27 //  $Header: 
28
29 using namespace std;
30 #include <stdio.h>
31 #include <fstream>
32 //#include <sstream>
33 #include <string>
34
35 //#include "utilities.h"
36
37 #include "SALOME_Container_i.hxx"
38
39 #include "StreamGraph_Impl.hxx"
40
41 #include "DataFlowEditor_DataFlow.hxx"
42
43 extern GraphExecutor::FiniteStateMachine * theAutomaton ;
44
45 static void CreateEditor( CORBA::ORB_ptr orb ,
46                           const char *instanceName ,
47                           const char *aDataFlowName ,
48                           const SUPERV::KindOfNode aKindOfNode ,
49                           string & dbgfile ,
50                           GraphEditor::DataFlow **  aDataFlowEditor ) {
51   bool aXmlFile = false ;
52   int lenname = strlen( aDataFlowName ) ;
53   char * theDataFlowName = new char [ lenname+1 ] ;
54   strcpy( theDataFlowName , aDataFlowName ) ;
55   if ( aDataFlowName ) {
56     if ( lenname > 4 && !strcmp( &aDataFlowName[ lenname - 4 ] , ".xml" ) ) {
57       strncpy( theDataFlowName , &aDataFlowName[ 0 ] , lenname-4 ) ;
58       theDataFlowName[ lenname-4 ] = '\0' ;
59       aXmlFile = true ;
60       int i ;
61       for ( i = lenname - 5 ; i >= 0 ; i-- ) {
62         if ( aDataFlowName[ i ] == '/' ) {
63           strncpy( theDataFlowName , &aDataFlowName[ i + 1 ] , lenname-5-i ) ;
64           theDataFlowName[ lenname-5-i ] = '\0' ;
65           break ;
66         }
67       }
68     }
69     else {
70       strcpy( theDataFlowName , &aDataFlowName[ 0 ] ) ;
71     }
72   }
73   
74   string theDataFlowInstanceName = theDataFlowName ;
75
76   // asv : 16.11.04 : creation of log file in /tmp/logs/$USER dir. 
77   // "/tmp/logs/$USER" was created by  runSalome.py -> orbmodule.py.
78   dbgfile = "/tmp/logs/" ;
79   dbgfile += getenv( "USER" ) ;
80   dbgfile += "/" ;
81   dbgfile += instanceName ;
82   dbgfile += "_" ;
83   dbgfile += theDataFlowInstanceName ;
84   dbgfile = dbgfile + "_" + theAutomaton->DbgFileNumber() + ".log" ;
85   FILE* f = fopen ( dbgfile.c_str(), "a" );
86   if ( f ) { // check if file can be opened for writing
87     fclose( f );
88   } 
89   else { // if file can't be opened - use a guaranteed temp file name
90     char* aTempNam = tempnam( NULL, NULL );
91     dbgfile = aTempNam;
92     free ( aTempNam );
93   }
94
95   SALOME_NamingService * NamingService = new SALOME_NamingService( orb ) ;
96   *aDataFlowEditor = new GraphEditor::DataFlow( orb , NamingService ,
97                                                 theDataFlowInstanceName.c_str() , dbgfile.c_str() ,
98                                                 aKindOfNode ) ;
99   MESSAGE( "CreateEditor " << theDataFlowName << " uniquely named " << theDataFlowInstanceName << " created with "
100            << dbgfile.c_str() ) ;
101
102   delete [] theDataFlowName ;
103 }
104
105 static void CreateExecutor( CORBA::ORB_ptr orb ,
106                           const char *instanceName ,
107                           const char *aDataFlowName ,
108                           const SUPERV::KindOfNode aKindOfNode ,
109                           string & dbgfile ,
110                           GraphExecutor::DataFlow **  aDataFlowExecutor ) {
111   int lenname = strlen( aDataFlowName ) ;
112   char * theDataFlowName = new char [ lenname+1 ] ;
113   strcpy( theDataFlowName , aDataFlowName ) ;
114   if ( aDataFlowName ) {
115     strcpy( theDataFlowName , &aDataFlowName[ 0 ] ) ;
116   }
117
118   string theDataFlowInstanceName = theDataFlowName ;
119
120   // asv : 16.11.04 : creation of log file in /tmp/logs/$USER dir. 
121   // "/tmp/logs/$USER" was created by  runSalome.py -> orbmodule.py.
122   dbgfile = "/tmp/logs/" ;
123   dbgfile += getenv( "USER" ) ;
124   dbgfile += "/" ;
125   dbgfile += instanceName ;
126   dbgfile += "_" ;
127   dbgfile += theDataFlowInstanceName ;
128   dbgfile = dbgfile + "_" + theAutomaton->DbgFileNumber() ;
129   ostringstream astr ;
130   astr << theAutomaton->ExecNumber() ;
131   dbgfile += astr.str() ;
132   dbgfile += string( "_Exec.log" ) ;
133   FILE* f = fopen ( dbgfile.c_str(), "a" );
134   if ( f ) { // check if file can be opened for writing
135     fclose( f );
136   } 
137   else { // if file can't be opened - use a guaranteed temp file name
138     char* aTempNam = tempnam( NULL, NULL );
139     dbgfile = aTempNam;
140     free ( aTempNam );
141   }
142
143   SALOME_NamingService * NamingService = new SALOME_NamingService( orb ) ;
144   *aDataFlowExecutor = new GraphExecutor::DataFlow( orb , NamingService ,
145                                                     theDataFlowInstanceName.c_str() , dbgfile.c_str() ,
146                                                     aKindOfNode ) ;
147
148   MESSAGE( "CreateExecutor " << theDataFlowName << " " << theDataFlowInstanceName << " created with "
149            << dbgfile.c_str() ) ;
150
151   delete [] theDataFlowName ;
152 }
153
154 Graph_Impl::Graph_Impl( CORBA::ORB_ptr orb ,
155                         PortableServer::POA_ptr poa ,
156                         PortableServer::ObjectId * contId , 
157                         const char *instanceName ,
158                         const char *interfaceName ,
159                         const char *aDataFlowName ,
160                         const SUPERV::KindOfNode aKindOfNode ) :
161   GNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowName , aKindOfNode ) {
162 //  MESSAGE("Graph_Impl::Graph_Impl activate object instanceName("
163 //          << instanceName << ") interfaceName(" << interfaceName << ") --> "
164 //          << hex << (void *) this << dec )
165 //  beginService( "Graph_Impl::Graph_Impl" );
166   _Orb = CORBA::ORB::_duplicate(orb);
167   _Poa = poa ;
168   _ContId = contId ;
169   _DebugFileName = NULL ;
170   if ( aKindOfNode == SUPERV::DataFlowGraph || aKindOfNode == SUPERV::MacroNode ) {
171 //    MESSAGE( "Graph_Impl::Graph_Impl _poa->activate_object" );
172     _thisObj = this ;
173     _id = _poa->activate_object(_thisObj);
174   }
175   else {
176 //    MESSAGE( "Graph_Impl::Graph_Impl NO _poa->activate_object " );
177   }
178
179   if ( aKindOfNode == SUPERV::DataFlowGraph || aKindOfNode == SUPERV::DataStreamGraph ) {
180     string dbgfile ;
181     GraphEditor::DataFlow * aDataFlowEditor ;
182     CreateEditor( orb , instanceName , aDataFlowName , aKindOfNode ,
183                   dbgfile , &aDataFlowEditor ) ;
184
185     if ( _DebugFileName ) {
186       delete [] _DebugFileName ;
187     }
188     _DebugFileName = new char[ strlen( dbgfile.c_str() )+1 ] ;
189     strcpy( _DebugFileName , dbgfile.c_str() ) ;
190
191     _NamingService = new SALOME_NamingService( orb ) ;
192     DataFlowEditor( aDataFlowEditor ) ;
193     DataFlowEditor()->Graph()->GraphEditor( aDataFlowEditor ) ;
194     DataFlowEditor()->Graph()->SetObjImpl( this ) ;
195   }
196   pthread_mutex_init( &_MutexExecutorWait , NULL ) ;
197 //  DataFlowExecutor( NULL ) ;
198 //  endService( "Graph_Impl::Graph_Impl" );
199 }
200
201 Graph_Impl::Graph_Impl( CORBA::ORB_ptr orb ,
202                         PortableServer::POA_ptr poa ,
203                         PortableServer::ObjectId * contId , 
204                         const char *instanceName ,
205                         const char *interfaceName ,
206                         GraphEditor::DataFlow * aDataFlowEditor ,
207                         GraphEditor::InNode * aDataFlowNode ) :
208   GNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , aDataFlowNode ) {
209 //  beginService( "Graph_Impl::Graph_Impl" );
210 //  MESSAGE( aDataFlowEditor->Graph()->Name() << " " );
211   if ( aDataFlowEditor->Graph()->IsDataFlowNode() ||
212        ( aDataFlowNode && aDataFlowNode->IsMacroNode() ) ) {
213 //    MESSAGE( "Graph_Impl::Graph_Impl _poa->activate_object" );
214     _thisObj = this ;
215     _id = _poa->activate_object(_thisObj);
216   }
217   else {
218 //    MESSAGE( "Graph_Impl::Graph_Impl NO _poa->activate_object " );
219   }
220   _Orb = CORBA::ORB::_duplicate(orb);
221   _Poa = poa ;
222   _ContId = contId ;
223   _DebugFileName = NULL ;
224   DataFlowEditor( aDataFlowEditor ) ;
225   DataFlowEditor()->Graph()->GraphEditor( aDataFlowEditor ) ;
226   DataFlowEditor()->Graph()->SetObjImpl( this ) ;
227   pthread_mutex_init( &_MutexExecutorWait , NULL ) ;
228 //  DataFlowExecutor( NULL ) ;
229 //  endService( "Graph_Impl::Graph_Impl" );  
230 }
231
232 Graph_Impl::Graph_Impl() {
233 }
234
235 Graph_Impl::~Graph_Impl() {
236   beginService( "Graph_Impl::~Graph_Impl" );
237   endService( "Graph_Impl::~Graph_Impl" );
238 }
239
240 void Graph_Impl::destroy() {
241   beginService( "Graph_Impl::destroy" );
242   if ( DataFlowNode() && DataFlowNode()->ComputingNode()->IsMacroNode() ) {
243     SUPERV::Graph_var aGraph = DataFlowNode()->GOTONode()->MacroObject() ;
244     GNode_Impl::Delete() ;
245     if ( !CORBA::is_nil( aGraph ) ) {
246       aGraph->destroy() ;
247     }
248   }
249   else {
250     SUPERV::Graph_var aGraph = DataFlowEditor()->Graph()->MacroObject() ;
251     GNode_Impl::Delete() ;
252     if ( !CORBA::is_nil( aGraph ) ) {
253       aGraph->destroy() ;
254     }
255   }
256   _poa->deactivate_object(*_id) ;
257   CORBA::release(_poa) ;
258   delete(_id) ;
259   _thisObj->_remove_ref();
260   endService( "Graph_Impl::destroy" );
261 }
262
263
264 char* Graph_Impl::getIOR() {
265   if ( IsMacro() ) {
266     return CORBA::string_dup( NULLSTRING ) ;
267   }
268   else if ( CORBA::is_nil( myServant ) ) {
269     PortableServer::ObjectId* id = getId();
270     CORBA::Object_var obj;
271     obj = _poa->id_to_reference(*id);
272     myServant = SUPERV::Graph::_narrow(obj);
273   }
274   return(CORBA::string_dup(_Orb->object_to_string(myServant)));
275 }
276
277 SUPERV::Graph_ptr Graph_Impl::Copy() {
278   beginService( "Graph_Impl::Copy" );
279   SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
280   if ( !IsMacro() ) {
281     Graph_Impl * myGraph ;
282     myGraph = new Graph_Impl( _Orb , _Poa, _ContId,
283                               instanceName() , interfaceName() ,
284                               DataFlowEditor()->Graph()->Name() , SUPERV::DataFlowGraph ) ;
285     PortableServer::ObjectId * id = myGraph->getId() ;
286     CORBA::Object_var obj = _poa->id_to_reference(*id);
287     iobject = SUPERV::Graph::_narrow(obj) ;
288     GraphBase::ListOfSGraphs * aListOfSGraphs = GetGraphs() ;
289     myGraph->LoadGraphs( aListOfSGraphs ) ;
290   }
291   endService( "Graph_Impl::Copy" );
292   return SUPERV::Graph::_duplicate(iobject) ;
293 }
294
295 void Graph_Impl::ReadOnly() {
296   DataFlowEditor()->ReadOnly() ;
297 }
298
299 SUPERV::INode_ptr Graph_Impl::Node() {
300 //  beginService( "Graph_Impl::Node" );
301   PortableServer::ObjectId * id = getId() ;
302   CORBA::Object_var obj = _poa->id_to_reference(*id);
303   SUPERV::Graph_var iobject ;
304   iobject = SUPERV::Graph::_narrow(obj) ;
305 //  endService( "Graph_Impl::Node" );
306   return SUPERV::Graph::_duplicate(iobject) ;
307 }
308
309 GraphBase::ListOfSGraphs * Graph_Impl::GetGraphs() {
310   return DataFlowEditor()->GetDataFlows() ;
311 }
312
313 bool Graph_Impl::LoadGraphs( GraphBase::ListOfSGraphs * aListOfDataFlows ) {
314   beginService( "Graph_Impl::LoadGraphs" );
315   bool RetVal = false ;
316   if ( DataFlowEditor()->IsEditing() ) {
317 //    RetVal = DataFlowEditor()->LoadDataFlows( aListOfDataFlows ) ;
318     if ( CORBA::is_nil( LoadDataFlows( DataFlowEditor() , aListOfDataFlows , 0 ) ) ) {
319       RetVal = false ;
320     }
321   }
322   endService( "Graph_Impl::LoadGraphs" );
323   return RetVal ;
324 }
325
326 bool Graph_Impl::Import(const char * aXmlFile ) {
327   beginService( "Graph_Impl::Import" );
328   bool RetVal = false ;
329   if ( DataFlowEditor()->IsEditing() && !IsMacro() ) {
330     GraphBase::ListOfSGraphs aListOfDataFlows ;
331     RetVal = DataFlowEditor()->LoadXml( aXmlFile , aListOfDataFlows ) ;
332     if ( RetVal && aXmlFile != NULL ) {
333 //      RetVal = DataFlowEditor()->LoadDataFlows( &aListOfDataFlows ) ;
334       if ( CORBA::is_nil( LoadDataFlows( DataFlowEditor() , &aListOfDataFlows , 0 ) ) ) {
335         RetVal = false ;
336       }
337     }
338   }
339   endService( "Graph_Impl::Import" );
340   return RetVal ;
341 }
342
343 bool Graph_Impl::Export(const char * anXmlFile ) {
344   beginService( "Graph_Impl::Export" );
345   bool RetVal = false ;
346   if ( !IsMacro() ) {
347     char * aFile = new char [ strlen( anXmlFile ) + 5 ] ;
348     strcpy( aFile , anXmlFile ) ;
349     int len = strlen( aFile ) ;
350     if ( !strcmp( &aFile[ len - 4 ] , ".xml" ) ) {
351     }
352     else if ( !strcmp( &aFile[ len - 3 ] , ".py" ) ) {
353       strcpy( &aFile[ len - 3 ] , ".xml" ) ;
354       len = strlen( aFile ) ;
355     }
356     else {
357       strcat( aFile , ".xml" ) ;
358       len = strlen( aFile ) ;
359     }
360     RetVal = DataFlowEditor()->SaveXml( aFile ) ;
361     if ( RetVal ) {
362       strcpy( &aFile[ len - 4 ] , ".py" ) ;
363       RetVal = DataFlowEditor()->SavePy( aFile ) ;
364     }
365     delete [] aFile ;
366   }
367   endService( "Graph_Impl::Export" );
368   return RetVal ;
369 }
370
371 SUPERV::CNode_ptr Graph_Impl::CNode( const SALOME_ModuleCatalog::Service &NodeService ) {
372   beginService( "Graph_Impl::CNode" );
373   SUPERV::CNode_var iobject = SUPERV::CNode::_nil() ;
374   if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() && !IsMacro() ) {
375     CNode_Impl * myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
376                                           instanceName() , interfaceName() ,
377                                           DataFlowEditor() ,
378                                           NodeService , NULLSTRING ,
379                                           SUPERV::ComputingNode , NULLSTRING ) ;
380     if ( myNode->DataFlowNode() ) {
381       PortableServer::ObjectId * id = myNode->getId() ;
382       CORBA::Object_var obj = _poa->id_to_reference(*id);
383       iobject = SUPERV::CNode::_narrow(obj) ;
384       myNode->SetObjRef( SUPERV::CNode::_duplicate( iobject ) ) ;
385     }
386   }
387   DataFlowEditor()->UnValid() ;
388   endService( "Graph_Impl::CNode" );
389   return SUPERV::CNode::_duplicate( iobject ) ;
390 }
391
392 SUPERV::FNode_ptr Graph_Impl::FNode( const char * NodeComponentName ,
393                                      const char * NodeInterfaceName ,
394                                      const SALOME_ModuleCatalog::Service &NodeService ) {
395   beginService( "Graph_Impl::FNode" );
396   SUPERV::FNode_var iobject = SUPERV::FNode::_nil() ;
397   if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() && !IsMacro() ) {
398     FNode_Impl * myNode = new FNode_Impl( _Orb , _Poa , _ContId ,
399                                           instanceName() , interfaceName() ,
400                                           DataFlowEditor() ,
401                                           NodeService ,
402                                           NodeComponentName ,
403                                           NodeInterfaceName ) ;
404     if ( myNode->DataFlowNode() ) {
405       PortableServer::ObjectId * id = myNode->getId() ;
406       CORBA::Object_var obj = _poa->id_to_reference(*id);
407       iobject = SUPERV::FNode::_narrow(obj) ;
408       myNode->SetObjRef( SUPERV::FNode::_duplicate( iobject ) ) ;
409     }
410   }
411   DataFlowEditor()->UnValid() ;
412   endService( "Graph_Impl::FNode" );
413   return SUPERV::FNode::_duplicate( iobject ) ;
414 }
415
416 SUPERV::INode_ptr Graph_Impl::INode( const char * FuncName ,
417                                      const SUPERV::ListOfStrings & PythonFuntion ) {
418   beginService( "Graph_Impl::INode" );
419   SUPERV::INode_var iobject = SUPERV::INode::_nil() ;
420   if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() && !IsMacro() ) {
421     INode_Impl * myNode = new INode_Impl( _Orb , _Poa , _ContId ,
422                                           instanceName() , interfaceName() ,
423                                           DataFlowEditor() ,
424                                           FuncName , PythonFuntion ,
425                                           SUPERV::InLineNode ) ;
426     if ( myNode->DataFlowNode() ) {
427       PortableServer::ObjectId * id = myNode->getId() ;
428       CORBA::Object_var obj = _poa->id_to_reference(*id);
429       iobject = SUPERV::INode::_narrow(obj) ;
430       myNode->SetObjRef( SUPERV::INode::_duplicate( iobject ) ) ;
431     }
432   }
433   endService( "Graph_Impl::INode" );
434   return SUPERV::INode::_duplicate( iobject ) ;
435 }
436
437
438 SUPERV::GNode_ptr Graph_Impl::GNode( const char * FuncName ,
439                                      const SUPERV::ListOfStrings & PythonFuntion ,
440                                      const char * anInLineNode ) {
441   beginService( "Graph_Impl::GNode" );
442   SUPERV::GNode_var iobject = SUPERV::GNode::_nil() ;
443   if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() && !IsMacro() ) {
444     GNode_Impl * myNode = new GNode_Impl( _Orb , _Poa , _ContId ,
445                                           instanceName() , interfaceName() ,
446                                           DataFlowEditor() ,
447                                           FuncName , PythonFuntion ,
448                                           SUPERV::GOTONode ) ;
449     if ( myNode->DataFlowNode() ) {
450       PortableServer::ObjectId * id = myNode->getId() ;
451       CORBA::Object_var obj = _poa->id_to_reference(*id);
452       iobject = SUPERV::GNode::_narrow(obj) ;
453       myNode->SetObjRef( SUPERV::GNode::_duplicate( iobject ) ) ;
454       if ( strlen( anInLineNode ) ) {
455         GraphBase::InLineNode * CoupledINode = (GraphBase::InLineNode * ) DataFlowEditor()->Graph()->GetGraphNode( anInLineNode ) ;
456         if ( anInLineNode ) {
457           myNode->SetCoupled( anInLineNode ) ;
458           Link( myNode->Port( "OutGate" ) , CoupledINode->ObjRef()->Port( "InGate" ) ) ;
459         }
460       }
461     }
462   }
463   DataFlowEditor()->UnValid() ;
464   endService( "Graph_Impl::GNode" );
465   return SUPERV::GNode::_duplicate( iobject ) ;
466 }
467
468 SUPERV::LNode_ptr Graph_Impl::LNode( const char * InitName ,
469                                      const SUPERV::ListOfStrings & InitFunction ,
470                                      const char * MoreName ,
471                                      const SUPERV::ListOfStrings & MoreFunction ,
472                                      const char * NextName ,
473                                      const SUPERV::ListOfStrings & NextFunction ,
474                                      SUPERV::INode_out anEndOfLoop ) {
475   beginService( "Graph_Impl::LNode" );
476   SUPERV::LNode_var iobject = SUPERV::LNode::_nil() ;
477   SUPERV::ELNode_var iendobject = SUPERV::ELNode::_nil() ;
478   if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() && !IsMacro() ) {
479     GraphBase::ListOfFuncName FuncNameList ;
480     FuncNameList.resize(3) ;
481     FuncNameList[0] = InitName ;
482     FuncNameList[1] = MoreName ;
483     FuncNameList[2] = NextName ;
484     GraphBase::ListOfPythonFunctions PythonFunctionList ;
485     PythonFunctionList.resize(3) ;
486     PythonFunctionList[0] = &InitFunction ;
487     PythonFunctionList[1] = &MoreFunction ;
488     PythonFunctionList[2] = &NextFunction ;
489     LNode_Impl * myNode = new LNode_Impl( _Orb , _Poa , _ContId ,
490                                           instanceName() , interfaceName() ,
491                                           DataFlowEditor() ,
492                                           FuncNameList , PythonFunctionList ,
493 //                                          InitName , InitFunction ,
494 //                                          MoreName , MoreFunction ,
495 //                                          NextName , NextFunction ,
496                                           SUPERV::LoopNode ) ;
497     if ( myNode->DataFlowNode() ) {
498       PortableServer::ObjectId * id = myNode->getId() ;
499       CORBA::Object_var obj = _poa->id_to_reference(*id);
500       iobject = SUPERV::LNode::_narrow(obj) ;
501       myNode->SetObjRef( SUPERV::LNode::_duplicate( iobject ) ) ;
502
503       SALOME_ModuleCatalog::Service aVoidService = SALOME_ModuleCatalog::Service() ;
504       char * anEndName ;
505       if ( strlen( InitName ) ) {
506         anEndName = new char( 3 + strlen( InitName ) + 1 ) ;
507         strcpy( anEndName , "End" ) ;
508         strcat( anEndName , InitName ) ;
509       }
510       else {
511         anEndName = new char( 3 + strlen( "Loop" ) + 1 ) ;
512         strcpy( anEndName , "EndLoop" ) ;
513       }
514       ELNode_Impl * myEndNode = new ELNode_Impl( _Orb , _Poa , _ContId ,
515                                                  instanceName() , interfaceName() ,
516                                                  DataFlowEditor() ,
517                                                  anEndName ,
518                                                  SUPERV::EndLoopNode ) ;
519       PortableServer::ObjectId * endid = myEndNode->getId() ;
520       CORBA::Object_var endobj = _poa->id_to_reference(*endid);
521       iendobject = SUPERV::ELNode::_narrow(endobj) ;
522       myEndNode->SetObjRef( SUPERV::ELNode::_duplicate( iendobject ) ) ;
523       myNode->SetCoupled( myEndNode->BaseNode()->Name() ) ;
524       myEndNode->SetCoupled( myNode->BaseNode()->Name() ) ;
525       Link( myNode->Port( "DoLoop" ) , myEndNode->Port( "DoLoop" ) ) ;
526       Link( myEndNode->Port( "DoLoop" ) , myNode->Port( "InitLoop" ) ) ;
527     }
528   }
529   anEndOfLoop = SUPERV::ELNode::_duplicate( iendobject ) ;
530   DataFlowEditor()->UnValid() ;
531   endService( "Graph_Impl::LNode" );
532   return SUPERV::LNode::_duplicate( iobject ) ;
533 }
534
535 SUPERV::SNode_ptr Graph_Impl::SNode( const char * FuncName ,
536                                      const SUPERV::ListOfStrings & PythonFunction ,
537                                      SUPERV::INode_out anEndOfSwitch ) {
538   beginService( "Graph_Impl::SNode" );
539   SUPERV::SNode_var iobject = SUPERV::SNode::_nil() ;
540   SUPERV::ESNode_var iendobject = SUPERV::ESNode::_nil() ;
541   if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() && !IsMacro() ) {
542     SNode_Impl * myNode = new SNode_Impl( _Orb , _Poa , _ContId ,
543                                           instanceName() , interfaceName() ,
544                                           DataFlowEditor() ,
545                                           FuncName , PythonFunction ,
546                                           SUPERV::SwitchNode ) ;
547     if ( myNode->DataFlowNode() ) {
548       PortableServer::ObjectId * id = myNode->getId() ;
549       CORBA::Object_var obj = _poa->id_to_reference(*id);
550       iobject = SUPERV::SNode::_narrow(obj) ;
551       myNode->SetObjRef( SUPERV::SNode::_duplicate( iobject ) ) ;
552
553       string anEndName = "End" ;
554       if ( strlen( FuncName ) ) {
555         anEndName += FuncName ;
556       }
557       else {
558         anEndName += "Switch" ;
559       }
560 //      cout << "Graph_Impl::SNode anEndName " << (void *) FuncName << " " << FuncName
561 //           << " " << strlen(FuncName) << " " << (void *) anEndName.c_str() << " "
562 //           << anEndName.c_str() << endl ;
563       ESNode_Impl * myEndNode = new ESNode_Impl( _Orb , _Poa , _ContId ,
564                                                instanceName() , interfaceName() ,
565                                                DataFlowEditor() ,
566                                                anEndName.c_str() ,
567                                                SUPERV::EndSwitchNode ) ;
568 //      cout << "Graph_Impl::SNode returned anEndName " << (void *) FuncName << " "
569 //           << FuncName << " " << strlen(FuncName) << " " << (void *) anEndName.c_str()
570 //           << " " << anEndName.c_str() << endl ;
571       PortableServer::ObjectId * endid = myEndNode->getId() ;
572       CORBA::Object_var endobj = _poa->id_to_reference(*endid);
573       iendobject = SUPERV::ESNode::_narrow(endobj) ;
574       myEndNode->SetObjRef( SUPERV::ESNode::_duplicate( iendobject ) ) ;
575       myNode->SetCoupled( myEndNode->BaseNode()->Name() ) ;
576       myEndNode->SetCoupled( myNode->BaseNode()->Name() ) ;
577       if ( !Link( myNode->Port( "Default" ) , myEndNode->Port( "Default" ) ) ) {
578         iobject = SUPERV::SNode::_nil() ;
579         iendobject = SUPERV::ESNode::_nil() ;
580       }
581     }
582   }
583   anEndOfSwitch = SUPERV::ESNode::_duplicate( iendobject ) ;
584   DataFlowEditor()->UnValid() ;
585   endService( "Graph_Impl::SNode" );
586   return SUPERV::SNode::_duplicate( iobject ) ;
587 }
588
589 // WARNING : THIS IS COMPLICATED :
590 SUPERV::Graph_var Graph_Impl::LoadDataFlows( GraphEditor::DataFlow * aDataFlowEditor ,
591                                              GraphBase::ListOfSGraphs * aListOfDataFlows ,
592                                              int index ) {
593   beginService( "Graph_Impl::EditorLoadDataFlows" ) ;
594   MESSAGE("Graph_Impl::LoadDataFlows index " << index << " " << (*aListOfDataFlows)[index].Info.theName.c_str() ) ;
595
596   SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
597 // That method is recursive :
598 // At first we load the supergraph with index = 0 :
599 // (After we load the graph corresponding to each MacroNode :)
600   if ( !aDataFlowEditor->LoadDataFlow( &(*aListOfDataFlows)[ index ] ) ) {
601     MESSAGE("Graph_Impl::LoadDataFlows failed " << (*aListOfDataFlows)[index].Info.theName.c_str() ) ;
602     return SUPERV::Graph::_duplicate( iobject ) ;
603   }
604 // That graph is not a StreamGraph :
605   else if ( !aDataFlowEditor->Graph()->HasDataStream() ) {
606     aDataFlowEditor->Graph()->Kind( SUPERV::DataFlowGraph ) ;
607 //    aDataFlowEditor->Graph()->SetGraphEditor( aDataFlowEditor ) ;
608     Graph_Impl * myGraph ;
609 // We create a Graph ObjRef for that graph
610     myGraph = new Graph_Impl( _Orb , _Poa, _ContId,
611                               instanceName() , interfaceName() ,
612                               aDataFlowEditor , NULL ) ;
613     PortableServer::ObjectId * id = myGraph->getId() ;
614     CORBA::Object_var obj = _poa->id_to_reference(*id) ;
615     iobject = SUPERV::Graph::_narrow( obj ) ;
616     myGraph->SetObjRef( SUPERV::Graph::_duplicate( iobject ) ) ;
617     myGraph->SetObjImpl( (CNode_Impl * ) myGraph ) ;
618     GraphBase::Graph * aGraph = myGraph->DataFlowEditor()->Graph() ;
619     int i ;
620
621 // asv: set Editor for the graph itself and for all its macro nodes
622     aGraph->GraphEditor( aDataFlowEditor );
623
624 // For the supergraph or each graph of MacroNodes we search MacroNodes recursively :
625     for ( i = 0 ; i < aGraph->GraphNodesSize() ; i++ ) {
626       if ( aGraph->GraphNodes( i )->IsMacroNode() ) {
627         GraphBase::GOTONode * aMacroNode = (GraphBase::GOTONode * ) aGraph->GraphNodes( i ) ;
628
629         // asv : 05.11.04 : fix of bug - "insert file" into existing graph with MacroNodes worked incorrectly!
630         // aMacroNode is an "old" node, and here we must analize only "new" nodes, that
631         // came from aListOfDataFlows and were loaded by aDataFlowEditor->LoadDataFlow( &(*aListOfDataFlows)[ index ] )
632         // so here we check if the node is "new" or "old"
633         if ( aMacroNode->GraphEditor() && aMacroNode->CoupledNode() )
634           continue;
635
636         // asv: set Editor for the graph itself and for all its macro nodes
637         aMacroNode->GraphEditor( aDataFlowEditor );
638
639         // Creation of a GraphMacroNode ObjRef in the current editor
640         SUPERV::Graph_var macroiobject = SUPERV::Graph::_nil() ;
641         Graph_Impl * myMacroNode ;
642         myMacroNode = new Graph_Impl( _Orb , _Poa, _ContId,
643                                       instanceName() , interfaceName() ,
644                                       aMacroNode->Name() , SUPERV::MacroNode ) ;
645         id = myMacroNode->getId() ;
646         obj = _poa->id_to_reference(*id);
647         macroiobject = SUPERV::Graph::_narrow( obj ) ;
648         myMacroNode->DataFlowEditor( aDataFlowEditor ) ;
649         GraphEditor::InNode * aDataFlowNode = (GraphEditor::InNode * ) aMacroNode->GetInNode() ;
650         myMacroNode->DataFlowNode( aDataFlowNode ) ;
651         aDataFlowNode->SetObjRef( SUPERV::CNode::_duplicate( SUPERV::CNode::_narrow( obj ) ) ) ;
652         aDataFlowNode->SetObjImpl( myMacroNode ) ;
653
654         char * aCoupledNodeName = aMacroNode->CoupledNodeName() ;
655         MESSAGE( "LoadDataFlows MacroNode " << aMacroNode->Name() << " --> " << aCoupledNodeName
656                  << " to be searched among " << (*aListOfDataFlows).size() << " Graphs" ) ;
657         int index ;
658         bool found = false ;
659         for ( index = 0 ; index < (int ) (*aListOfDataFlows).size() ; index++ ) {
660           MESSAGE( "LoadDataFlows Graph" << index << " " << (*aListOfDataFlows)[index].Info.theName.c_str() ) ;
661           if ( !strcmp( aCoupledNodeName , (*aListOfDataFlows)[index].Info.theName.c_str() ) ) {
662             found = true ;
663             string dbgfile ;
664 // At first create the editor and a StreamGraph
665             GraphEditor::DataFlow * aMacroGraphDataFlowEditor ;
666             CreateEditor( _Orb , instanceName() , aCoupledNodeName , SUPERV::DataStreamGraph ,
667                           dbgfile , &aMacroGraphDataFlowEditor ) ;
668
669             if ( _DebugFileName ) {
670               delete [] _DebugFileName ;
671             }
672             _DebugFileName = new char[ strlen( dbgfile.c_str() )+1 ] ;
673             strcpy( _DebugFileName , dbgfile.c_str() ) ;
674
675             MESSAGE( "RECURSIVE IMPORT OF GRAPHS OF MACRONODES :" << aCoupledNodeName ) ;
676             if ( CORBA::is_nil( LoadDataFlows( aMacroGraphDataFlowEditor , aListOfDataFlows , index ) ) ) {
677               MESSAGE("Graph_Impl::LoadDataFlows failed" ) ;
678               return SUPERV::Graph::_duplicate( iobject ) ;
679             }
680
681 // That graph is not a StreamGraph :
682             else if ( !aMacroGraphDataFlowEditor->Graph()->HasDataStream() ) {
683               Graph_Impl * myMacroGraph ;
684 // The Graph ObjRef for that graph was already created
685               myMacroGraph = (Graph_Impl * ) aMacroGraphDataFlowEditor->Graph()->ObjImpl() ;
686
687               GraphBase::Graph * aMacroGraph = myMacroGraph->DataFlowEditor()->Graph() ;
688               
689               aMacroGraph->GraphMacroLevel( aGraph->GraphMacroLevel() + 1 ) ;
690               aMacroGraph->CoupledNode( aMacroNode ) ;
691               aMacroGraph->MacroObject( SUPERV::Graph::_duplicate( macroiobject ) ) ;
692
693 // Set the GraphMacroNode ObjRef in the MacroNode
694               aMacroNode->GraphMacroLevel( aGraph->GraphMacroLevel() + 1 ) ;
695               aMacroNode->CoupledNode( aMacroGraph ) ;
696               aMacroNode->MacroObject( SUPERV::Graph::_narrow( aMacroGraphDataFlowEditor->Graph()->ObjRef() ) ) ;
697               MESSAGE( "LoadDataFlows aMacroGraph " << aMacroGraph << " " << aMacroGraph->Name()
698                        << " coupled to " << aMacroGraph->CoupledNode() << " "
699                        << aMacroGraph->CoupledNode()->Name() << " Editor " << aMacroGraph->GraphEditor() ) ;
700               MESSAGE( "LoadDataFlows aMacroNode " << aMacroNode << " " << aMacroNode->Name()
701                        << " coupled to " << aMacroNode->CoupledNode() << " "
702                        << aMacroNode->CoupledNode()->Name() << " Editor " << aMacroNode->GraphEditor() ) ;
703               MESSAGE( "LoadDataFlows current Graph " << aGraph << " " << aGraph->Name()
704                        << " coupled to " << aGraph->CoupledNode()
705                        << " Editor " << aGraph->GraphEditor() << " " << aGraph->Name() ) ;
706             }
707             break ;
708           }
709         }
710         if ( !found ) {
711           return SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
712         }
713       }
714     }
715   }
716   else if ( (*aListOfDataFlows).size() == 1 ) {
717     StreamGraph_Impl * myStreamGraph ;
718 // We create a Graph ObjRef for that graph
719     myStreamGraph = new StreamGraph_Impl( _Orb , _Poa, _ContId,
720                                           instanceName() , interfaceName() ,
721                                           aDataFlowEditor , NULL ) ;
722     PortableServer::ObjectId * id = myStreamGraph->getId() ;
723     CORBA::Object_var obj = _poa->id_to_reference(*id) ;
724     SUPERV::StreamGraph_var Streamiobject = SUPERV::StreamGraph::_nil() ;
725     Streamiobject = SUPERV::StreamGraph::_narrow( obj ) ;
726     myStreamGraph->SetObjRef( SUPERV::StreamGraph::_duplicate( Streamiobject ) ) ;
727     myStreamGraph->SetObjImpl( (CNode_Impl * ) myStreamGraph ) ;
728 //    iobject = SUPERV::Graph::_narrow( obj ) ;
729     iobject = SUPERV::Graph::_narrow( Streamiobject ) ;
730   }
731   else {
732     MESSAGE( "Graph_Impl::LoadDataFlows StreamGraph with MacroNodes not yet implemented" ) ;
733   }
734
735   endService( "Graph_Impl::EditorLoadDataFlows" );
736   return SUPERV::Graph::_duplicate( iobject ) ;
737 }
738
739 SUPERV::Graph_var Graph_Impl::LoadDataFlows( GraphExecutor::DataFlow * aDataFlowExecutor ,
740                                              GraphBase::ListOfSGraphs * aListOfDataFlows ,
741                                              int index ) {
742   beginService( "Graph_Impl::ExecutorLoadDataFlows" ) ;
743   MESSAGE("Graph_Impl::LoadDataFlows(Executor) index " << index << " " << (*aListOfDataFlows)[index].Info.theName.c_str() << " aDataFlowExecutor " << aDataFlowExecutor ) ;
744
745   // That method is recursive :
746   // At first we load the supergraph with index = 0 :
747   // (After we load the graph corresponding to each MacroNode :)
748   if ( !aDataFlowExecutor->LoadDataFlow( &(*aListOfDataFlows)[ index ] ) ) {
749     MESSAGE("Graph_Impl::LoadDataFlows(Executor) failed, could not LoadDataFlow(supergraph)" ) ;
750     return SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
751   }
752
753   // That graph is not a StreamGraph :
754   else {
755     aDataFlowExecutor->Graph()->Kind( SUPERV::DataFlowGraph ) ;
756     GraphEditor::DataFlow * aDataFlowEditor ;
757     aDataFlowEditor = DataFlowEditor() ;
758     GraphBase::Graph * anEditorGraph = aDataFlowEditor->Graph() ;
759     GraphBase::Graph * anExecutorGraph = aDataFlowExecutor->Graph() ;
760     if ( aDataFlowEditor->Executor() ) {
761       delete aDataFlowEditor->Executor() ;
762       aDataFlowEditor->Executor( NULL ) ;
763       aDataFlowEditor->Editing() ;
764     }
765     aDataFlowEditor->Executor( aDataFlowExecutor ) ;
766     anExecutorGraph->GraphEditor( aDataFlowEditor ) ;
767
768     if ( !aDataFlowExecutor->Graph()->HasDataStream() ) {
769     // For the supergraph or each graph of MacroNodes we search MacroNodes recursively :
770       int i;
771       for ( i = 0 ; i < anExecutorGraph->GraphNodesSize() ; i++ ) {
772         if ( anExecutorGraph->GraphNodes( i )->IsMacroNode() ) {
773           GraphBase::GOTONode * aMacroNode = (GraphBase::GOTONode * ) anExecutorGraph->GraphNodes( i ) ;
774           aMacroNode->GraphEditor( aDataFlowEditor ) ;
775
776         // get the macro node's editor object
777           char * aMacroGraphName = aMacroNode->CoupledNodeName() ;
778           GraphBase::Graph* aMacroGraph =  (GraphBase::Graph*)((GraphBase::GOTONode *)anEditorGraph->GetGraphNode( aMacroNode->Name() ))->CoupledNode() ;
779         GraphEditor::DataFlow* aMacroGraphEditor = aMacroGraph->GraphEditor();
780
781           MESSAGE( "LoadDataFlows(Executor) MacroNode " << aMacroNode->Name() << " Coupled to " << aMacroGraphName
782                    << " to be searched among " << (*aListOfDataFlows).size() << " Graphs" << endl ) ;
783           int index;
784           bool found = false ;
785           for ( index = 0 ; index < (int ) (*aListOfDataFlows).size() && !found; index++ ) {
786             if ( !strcmp( aMacroGraphName , (*aListOfDataFlows)[index].Info.theName.c_str() ) )
787               found = true;
788           }
789           if ( !found ) {
790             MESSAGE("Graph_Impl::LoadDataFlows(Executor) failed, Macro node's coupled graph \"" << aMacroGraphName << "\" was not found" ) ;
791             return SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
792           }
793           index--; // it was incremented in "for ..." before last check ( !found ).
794         
795         // At first create the editor and a StreamGraph
796           string dbgfile ;
797           GraphExecutor::DataFlow * aMacroGraphExecutor ;
798           CreateExecutor( _Orb , instanceName() , aMacroGraphName , SUPERV::DataStreamGraph ,
799                         dbgfile , &aMacroGraphExecutor );
800
801         // set GraphMacroLevel for Executor's graph
802           GraphBase::Graph* aMacroGraphExe = aMacroGraphExecutor->Graph();
803             aMacroGraphExe->GraphMacroLevel( anExecutorGraph->GraphMacroLevel() + 1 );
804
805         // load data flows in MacroGraph's executor
806           Graph_Impl* aMacroGraphImpl = (Graph_Impl*) aMacroGraphEditor->Graph()->ObjImpl();
807           MESSAGE( "RECURSIVE IMPORT OF GRAPHS OF MACRONODES : " << aMacroGraphName ) ;
808           if ( CORBA::is_nil( aMacroGraphImpl->LoadDataFlows( aMacroGraphExecutor, aListOfDataFlows , index ) ) ) {
809             MESSAGE("Graph_Impl::LoadDataFlows(Executor) failed,  could not LoadDataFlow( MacroNodeGraph \"" <<aMacroGraphName << "\" )" ) ;
810             return SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
811           }
812           
813           // set coupled pair MacroNode <--> MacroGraph
814           aMacroGraphExe->CoupledNode( aMacroNode ) ;
815           aMacroNode->CoupledNode( aMacroGraphExe ) ;
816
817           // initialize MacroNode's InPorts with corresponding "external" values
818           int q ;
819           for ( q = 0 ; q < aMacroNode->GetNodeInPortsSize() ; q++ ) {
820             const GraphBase::InPort * anInPort = aMacroNode->GetNodeInPort( q ) ;
821             if ( anInPort->IsDataConnected() ) {
822               const char* aMacroGraphInPortName = aMacroGraph->GetNodeInPort( q )->PortName();
823               if ( !aMacroGraphExecutor->InputOfAny(  aMacroGraphInPortName, *anInPort->GetOutPort()->Value(),false ) ) {
824                 return SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
825               }
826               else {
827                 MESSAGE( "LoadDataFlows(Executor) " << aMacroGraph->Name() << "->InputOfAny( " 
828                          << aMacroGraphInPortName << " , Value )" ) ;
829               }
830             }
831           } // end of init MacroNode's InPorts
832
833           aMacroGraphImpl->Run() ;
834
835         }
836       } // end of for( get nodes of the graph...)
837     }
838   } // end of setting initial graph's structure..
839
840   endService( "Graph_Impl::ExecutorLoadDataFlows" );
841
842   PortableServer::ObjectId * id = getId();
843   CORBA::Object_var obj = _poa->id_to_reference( *id );
844   SUPERV::Graph_var iobject = SUPERV::Graph::_narrow( obj ) ;
845   return SUPERV::Graph::_duplicate( iobject ) ;
846 }
847
848 SUPERV::Graph_ptr Graph_Impl::MNode( const char * aXmlFileName ) {
849   beginService( "Graph_Impl::MNode" );
850   SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
851   MESSAGE( "Graph_Impl::MNode( " << aXmlFileName << " )" ) ;
852   if ( !IsMacro() ) {
853     GraphBase::ListOfSGraphs aListOfDataFlows ;
854     string dbgfile ;
855 // At first create the editor and a StreamGraph with the xml file
856     GraphEditor::DataFlow * aDataFlowEditor ;
857     CreateEditor( _Orb , instanceName() , aXmlFileName , SUPERV::DataStreamGraph ,
858                   dbgfile , &aDataFlowEditor ) ;
859
860     if ( _DebugFileName ) {
861       delete [] _DebugFileName ;
862     }
863     _DebugFileName = new char[ strlen( dbgfile.c_str() )+1 ] ;
864     strcpy( _DebugFileName , dbgfile.c_str() ) ;
865
866     int lenname = strlen( aXmlFileName ) ;
867     bool loaded = false ;
868 // Import of the xml file
869     if ( lenname > 4 && !strcmp( &aXmlFileName[ lenname - 4 ] , ".xml" ) ) {
870       loaded = aDataFlowEditor->LoadXml( aXmlFileName , aListOfDataFlows ) ;
871       if ( loaded ) {
872         iobject = MNode( aDataFlowEditor , &aListOfDataFlows ) ;
873       }
874     }
875   }
876   return iobject ;
877 }
878
879 // WARNING : THIS IS COMPLICATED :
880 // I should have to remove duplicated code ...
881 SUPERV::Graph_ptr Graph_Impl::MNode( GraphEditor::DataFlow * aMacroGraphDataFlowEditor ,
882                                      GraphBase::ListOfSGraphs * aListOfDataFlows ) {
883   beginService( "Graph_Impl::MNode" ) ;
884   SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
885   SUPERV::Graph_var macroiobject = SUPERV::Graph::_nil() ;
886
887   if ( !IsMacro() ) {
888     MESSAGE( "Graph_Impl::MNode DataFlowEditor->LoadDataFlow" ) ;
889 //    if ( !aMacroGraphDataFlowEditor->LoadDataFlow( &aListOfDataFlows[ 0 ] ) ) {
890     iobject = LoadDataFlows( aMacroGraphDataFlowEditor , aListOfDataFlows , 0 ) ;
891     if ( CORBA::is_nil( iobject ) ) {
892       MESSAGE("Graph_Impl::MNode LoadDataFlow failed" ) ;
893       return false ;
894     }
895
896 // That graph is not a StreamGraph :
897     else if ( !aMacroGraphDataFlowEditor->Graph()->HasDataStream() ) {
898       aMacroGraphDataFlowEditor->Graph()->Kind( SUPERV::DataFlowGraph ) ;
899       aMacroGraphDataFlowEditor->Graph()->GraphEditor( aMacroGraphDataFlowEditor ) ;
900
901       Graph_Impl * myMacroGraph = (Graph_Impl * ) aMacroGraphDataFlowEditor->Graph()->ObjImpl() ;
902 // Creation of a GraphMacroNode in the current editor
903       string aMacroNodeName = string( "Macro_" ) + string( myMacroGraph->Name() ) ;
904       Graph_Impl * myMacroNode ;
905       myMacroNode = new Graph_Impl( _Orb , _Poa, _ContId,
906                                     instanceName() , interfaceName() ,
907                                     aMacroNodeName.c_str() , SUPERV::MacroNode ) ;
908       PortableServer::ObjectId * id = myMacroNode->getId() ;
909       CORBA::Object_var obj = _poa->id_to_reference(*id);
910       macroiobject = SUPERV::Graph::_narrow( obj ) ;
911       myMacroNode->DataFlowEditor( DataFlowEditor() ) ;
912
913 // Creation of the MacroNode itself in the current Graph
914       GraphBase::ListOfFuncName aFuncName ;
915       aFuncName.resize( 1 ) ;
916       aFuncName[0] = "" ;
917       SUPERV::ListOfStrings aListOfStrings ;
918       aListOfStrings.length( 1 ) ;
919       aListOfStrings[0] = "" ;
920       GraphBase::ListOfPythonFunctions aPythonFunction ;
921       aPythonFunction.resize( 1 ) ;
922       aPythonFunction[0] = &aListOfStrings ;
923       SALOME_ModuleCatalog::Service * aMacroNodeService = myMacroGraph->Service() ;
924       GraphEditor::InNode * aDataFlowNode = DataFlowEditor()->AddNode( *aMacroNodeService , "" , "" ,
925                                                                        aMacroNodeName.c_str() , SUPERV::MacroNode ,
926                                                                        aFuncName , aPythonFunction ) ;
927       aDataFlowNode->SetPythonFunction( "" , aListOfStrings ) ;
928       myMacroNode->DataFlowNode( aDataFlowNode ) ;
929       aDataFlowNode->ComputingNode()->SetService( *aMacroNodeService ) ;
930       aDataFlowNode->SetObjRef( SUPERV::CNode::_duplicate( SUPERV::CNode::_narrow( obj ) ) ) ;
931       aDataFlowNode->SetObjImpl( this ) ;
932
933       GraphBase::Graph * aGraph = myMacroGraph->DataFlowEditor()->Graph() ;
934       GraphBase::Graph * aGraphOfMacroGraph = myMacroNode->DataFlowEditor()->Graph() ;
935       GraphBase::Graph * aMacroGraph = myMacroNode->DataFlowNode()->GraphMacroNode() ;
936       aMacroGraph->Kind( SUPERV::MacroNode ) ;
937       aMacroGraph->GraphEditor( DataFlowEditor() ) ;
938 // Creation of the Ports of the MacroNode from the ports of the GraphMacroNode
939       aMacroGraph->SetMacroPorts( aGraph ) ;
940 // Valid ==> creation of Service and the ports of the current Graph
941       DataFlowEditor()->IsValid() ;
942 // Set the Input Datas from the GraphMacroNode to the current Graph
943       aMacroGraph->SetMacroDatas( aGraph , aGraphOfMacroGraph ) ;
944       aMacroGraphDataFlowEditor->UnValid() ;
945 // Set the MacroNode ObjRef in the GraphMacroNode
946       aGraph->CoupledNode( aMacroGraph ) ;
947       aGraph->MacroObject( SUPERV::Graph::_duplicate( macroiobject ) ) ;
948 // Set the GraphMacroNode ObjRef in the MacroNode
949       aDataFlowNode->GraphMacroNode()->GraphMacroLevel( aGraphOfMacroGraph->GraphMacroLevel() + 1 ) ;
950       aMacroGraph->CoupledNode( aGraph ) ;
951 //      aGraphOfMacroGraph->CoupledNode( aGraph ) ;
952       aMacroGraph->MacroObject( SUPERV::Graph::_duplicate( iobject ) ) ;
953 //      aGraphOfMacroGraph->MacroObject( SUPERV::Graph::_duplicate( iobject ) ) ;
954 //    aDataFlowNode->CoupledNode( aGraph ) ;
955 //    aDataFlowNode->ComputingNode()->MacroObject( SUPERV::Graph::_duplicate( iobject ) ) ;
956 // Set the MacroLevel of that graph
957       aGraph->GraphMacroLevel( aGraphOfMacroGraph->GraphMacroLevel() + 1 ) ;
958       aMacroGraph->Coordinates( 0 , 0 ) ;
959       MESSAGE( "DataFlowNode Graph " << this << " DataFlowEditor " << DataFlowEditor() << " aDataFlowNode "
960                << aDataFlowNode << " " << aDataFlowNode->Name() << " created" ) ;
961       MESSAGE( "MNode aGraph " << aGraph << " " << aGraph->Name()
962                << " coupled to " << aGraph->CoupledNode() << " "
963                << aGraph->CoupledNode()->Name() ) ;
964       MESSAGE( "MNode aMacroGraph " << aMacroGraph << " " << aMacroGraph->Name()
965                << " coupled to " << aMacroGraph->CoupledNode() << " "
966                << aMacroGraph->CoupledNode()->Name() ) ;
967       MESSAGE( "MNode aMacroGraph " << myMacroNode->DataFlowEditor()->Graph() << " "
968                << myMacroNode->DataFlowEditor()->Graph()->Name()
969                << " coupled to " << myMacroNode->DataFlowEditor()->Graph()->CoupledNode() ) ;
970     }
971     else {
972       delete aMacroGraphDataFlowEditor ;
973     }
974   }
975   endService( "Graph_Impl::MNode" );
976   return SUPERV::Graph::_duplicate( macroiobject ) ;
977 }
978
979 // For python supergraph
980 SUPERV::Graph_ptr Graph_Impl::GraphMNode( SUPERV::Graph_ptr myMacroGraph ) {
981   SUPERV::Graph_var iobject = myMacroGraph ;
982   beginService( "Graph_Impl::GraphMNode" ) ;
983
984 //  GraphBase::Graph * myMacroGraph = aGraph;
985   SUPERV::Graph_var macroiobject = SUPERV::StreamGraph::_nil() ;
986 // Creation of a GraphMacroNode in the current editor
987   if ( !IsMacro() ) {
988     string aMacroNodeName = string( "Macro_" ) + string( myMacroGraph->Name() ) ;
989     //string aMacroNodeName = string( myMacroGraph->CoupledName() ) ;
990     MESSAGE( "GraphMNode( " << myMacroGraph->Name() << " )" ) ;
991     Graph_Impl * myMacroNode ;
992     myMacroNode = new Graph_Impl( _Orb , _Poa, _ContId,
993                                   instanceName() , interfaceName() ,
994                                   aMacroNodeName.c_str() , SUPERV::MacroNode ) ;
995     PortableServer::ObjectId * id = myMacroNode->getId() ;
996     CORBA::Object_var obj = _poa->id_to_reference(*id);
997     macroiobject = SUPERV::Graph::_narrow( obj ) ;
998     myMacroNode->DataFlowEditor( DataFlowEditor() ) ;
999
1000 // Creation of the MacroNode itself in the current Graph
1001     GraphBase::ListOfFuncName aFuncName ;
1002     aFuncName.resize( 1 ) ;
1003     aFuncName[0] = "" ;
1004     SUPERV::ListOfStrings aListOfStrings ;
1005     aListOfStrings.length( 1 ) ;
1006     aListOfStrings[0] = "" ;
1007     GraphBase::ListOfPythonFunctions aPythonFunction ;
1008     aPythonFunction.resize( 1 ) ;
1009     aPythonFunction[0] = &aListOfStrings ;
1010     SALOME_ModuleCatalog::Service * aMacroNodeService = myMacroGraph->Service() ;
1011     GraphEditor::InNode * aDataFlowNode ;
1012     aDataFlowNode = DataFlowEditor()->AddNode( *aMacroNodeService , "" , "" ,
1013                                                aMacroNodeName.c_str() , SUPERV::MacroNode ,
1014                                                aFuncName , aPythonFunction ) ;
1015     aDataFlowNode->SetPythonFunction( "" , aListOfStrings ) ;
1016     myMacroNode->DataFlowNode( aDataFlowNode ) ;
1017     aDataFlowNode->ComputingNode()->SetService( *aMacroNodeService ) ;
1018     aDataFlowNode->SetObjRef( SUPERV::CNode::_duplicate( SUPERV::CNode::_narrow( obj ) ) ) ;
1019     aDataFlowNode->SetObjImpl( this ) ;
1020
1021 //    GraphBase::Graph * aGraph = DataFlowEditor()->Automaton()->MapGraph( myMacroGraph->Name() ) ;
1022     GraphBase::Graph * aGraph ;
1023     //DataFlowEditor()->Automaton()->GraphBase( &aGraph ) ;
1024     myMacroGraph->Coupled() ;
1025     GraphBase::Graph * aGraphOfMacroGraph = myMacroNode->DataFlowEditor()->Graph() ;
1026     GraphBase::Graph * aMacroGraph = myMacroNode->DataFlowNode()->GraphMacroNode() ;
1027     aMacroGraph->Kind( SUPERV::MacroNode ) ;
1028     aMacroGraph->GraphEditor( DataFlowEditor() ) ;
1029 // Creation of the Ports of the MacroNode from the ports of the GraphMacroNode
1030     aMacroGraph->SetMacroPorts( aGraph ) ;
1031 // Valid ==> creation of Service and the ports of the current Graph
1032     DataFlowEditor()->IsValid() ;
1033 // Set the Input Datas from the GraphMacroNode to the current Graph
1034     aMacroGraph->SetMacroDatas( aGraph , aGraphOfMacroGraph ) ;
1035 //    aMacroGraphDataFlowEditor->UnValid() ;
1036     aGraph->GraphEditor()->UnValid() ;
1037 // Set the MacroNode ObjRef in the GraphMacroNode
1038     aGraph->CoupledNode( aMacroGraph ) ;
1039     aGraph->MacroObject( SUPERV::Graph::_duplicate( macroiobject ) ) ;
1040 // Set the GraphMacroNode ObjRef in the MacroNode
1041     aDataFlowNode->GraphMacroNode()->GraphMacroLevel( aGraphOfMacroGraph->GraphMacroLevel() + 1 ) ;
1042     aMacroGraph->CoupledNode( aGraph ) ;
1043     aMacroGraph->MacroObject( SUPERV::Graph::_duplicate( iobject ) ) ;
1044 //    aDataFlowNode->CoupledNode( aGraph ) ;
1045 //    aDataFlowNode->ComputingNode()->MacroObject( SUPERV::Graph::_duplicate( iobject ) ) ;
1046 // Set the MacroLevel of that graph
1047     aGraph->GraphMacroLevel( aGraphOfMacroGraph->GraphMacroLevel() + 1 ) ;
1048     aMacroGraph->Coordinates( 0 , 0 ) ;
1049     MESSAGE( aGraph->Name() << "->CoupledNode()->GraphEditor() : " << aGraph->CoupledNode()->GraphEditor() ) ;
1050     MESSAGE( aMacroGraph->Name() << "->CoupledNode()->GraphEditor() : "
1051              << aMacroGraph->CoupledNode()->GraphEditor() ) ;
1052     MESSAGE( "DataFlowNode Graph " << this << " DataFlowEditor " << DataFlowEditor() << " aDataFlowNode "
1053              << aDataFlowNode << " " << aDataFlowNode->Name() << " created" ) ;
1054   }
1055   endService( "Graph_Impl::GraphMNode" ) ;
1056   return SUPERV::Graph::_duplicate( macroiobject ) ;
1057 }
1058
1059 SUPERV::Graph_ptr Graph_Impl::FlowObjRef() {
1060   beginService( "Graph_Impl::FlowObjRef" );
1061   SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
1062   if ( IsMacro() ) {
1063     iobject = SUPERV::Graph::_narrow( DataFlowNode()->GraphMacroNode()->MacroObject() ) ;
1064   }
1065   else if ( IsGraph() ) {
1066     iobject = SUPERV::Graph::_narrow( DataFlowEditor()->Graph()->MacroObject() ) ;
1067   }
1068   if ( CORBA::is_nil( iobject ) ) {
1069     MESSAGE( "Graph_Impl::FlowObjRef() returns a NIL Object" ) ;
1070   }
1071   endService( "Graph_Impl::FlowObjRef" );
1072   return SUPERV::Graph::_duplicate( iobject ) ;
1073 }
1074
1075 SUPERV::StreamGraph_ptr Graph_Impl::StreamObjRef() {
1076   beginService( "Graph_Impl::StreamObjRef" );
1077   SUPERV::StreamGraph_var iobject = SUPERV::StreamGraph::_nil() ;
1078   if ( IsMacro() ) {
1079     iobject = SUPERV::StreamGraph::_narrow( DataFlowNode()->GraphMacroNode()->MacroObject() ) ;
1080   }
1081   else if ( IsGraph() || IsStreamGraph() ) {
1082     iobject = SUPERV::StreamGraph::_narrow( DataFlowEditor()->Graph()->MacroObject() ) ;
1083   }
1084   if ( CORBA::is_nil( iobject ) ) {
1085     MESSAGE( "Graph_Impl::StreamObjRef() returns a NIL Object" ) ;
1086   }
1087   endService( "Graph_Impl::StreamObjRef" );
1088   return SUPERV::StreamGraph::_duplicate( iobject ) ;
1089 }
1090
1091 SUPERV::CNode_ptr Graph_Impl::Node(char const * aNodeName ) {
1092 //  beginService( "Graph_Impl::Node" );
1093   SUPERV::CNode_var iobject = SUPERV::CNode::_nil() ;
1094   /* JR : 13/06/03
1095      if ( CORBA::is_nil( DataFlowEditor()->GetNode( aNodeName )->ObjRef() ) ) {
1096      CNode_Impl * myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
1097      instanceName() , interfaceName() ,
1098      DataFlowEditor() ,
1099      DataFlowEditor()->GetNode( aNodeName ) ) ;
1100      PortableServer::ObjectId * id = myNode->getId() ;
1101      CORBA::Object_var obj = _poa->id_to_reference(*id);
1102      iobject = SUPERV::CNode::_narrow(obj) ;
1103      myNode->SetObjRef( SUPERV::CNode::_duplicate( iobject ) ) ;
1104      }
1105      else {
1106      iobject = DataFlowEditor()->GetNode( aNodeName )->ObjRef() ;
1107   */
1108   if ( !IsMacro() ) {
1109     GraphEditor::InNode * anInNode = DataFlowEditor()->GetNode( aNodeName ) ;
1110     if ( anInNode ) {
1111       if ( CORBA::is_nil( anInNode->ObjRef() ) ) {
1112         SetNodeObjRef( anInNode ) ;
1113       }
1114       iobject = anInNode->ObjRef() ;
1115     }
1116   }
1117 //  endService( "Graph_Impl::Node" );
1118   return SUPERV::CNode::_duplicate( iobject ) ;
1119 }
1120
1121 SUPERV::Link_ptr Graph_Impl::Link( SUPERV::Port_ptr OutPort ,
1122                                    SUPERV::Port_ptr InPort ) {
1123 //  beginService( "Graph_Impl::Link" );
1124   SUPERV::Link_var iobject = SUPERV::Link::_nil() ;
1125   if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() &&
1126        !OutPort->IsDataStream() && !InPort->IsDataStream() && !IsMacro() ) {
1127     MESSAGE( "Graph_Impl::Link( " << OutPort->Node()->Name() << "( " << OutPort->Name() << " ) --> "
1128              << InPort->Node()->Name() << "( " << InPort->Name() << " )" ) ;
1129     GraphEditor::InNode * anInNode = DataFlowEditor()->GetNode( InPort->Node()->Name() ) ;
1130     GraphEditor::InNode * anOutNode = DataFlowEditor()->GetNode( OutPort->Node()->Name() ) ;
1131     if ( anInNode == NULL || anOutNode== NULL ) {
1132       MESSAGE( "Graph_Impl::Link( " << OutPort->Node()->Name() << " " << anOutNode << " , "
1133                << InPort->Node()->Name() << " " << anInNode << " ) Node(s) not found in " << Name() ) ;
1134     }
1135     else {
1136       GraphBase::InPort * anInPort = anInNode->ComputingNode()->GetChangeInPort( InPort->Name() ) ;
1137       GraphBase::OutPort * anOutPort = anOutNode->ComputingNode()->GetChangeOutPort( OutPort->Name() ) ;
1138       if ( anInPort == NULL || anOutPort== NULL ) {
1139         MESSAGE( "Graph_Impl::Link( " << OutPort->Name() << " " << anOutPort << " , "
1140                  << InPort->Name() << " " << anInPort << " ) Port(s) not found" ) ;
1141       }
1142       else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
1143         const char * DataFlowOutNodeName = OutPort->Node()->Name() ;
1144         GraphEditor::InNode * DataFlowOutNode = DataFlowEditor()->GetNode( DataFlowOutNodeName ) ;
1145         const char * DataFlowInNodeName = InPort->Node()->Name() ;
1146         GraphEditor::InNode * DataFlowInNode = DataFlowEditor()->GetNode( DataFlowInNodeName ) ;
1147         if ( DataFlowOutNode && DataFlowInNode ) {
1148           bool Success ;
1149           Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
1150                                               instanceName() , interfaceName() ,
1151                                               DataFlowEditor() ,
1152                                               DataFlowInNode ,
1153                                               InPort->Name() ,
1154                                               DataFlowOutNode ,
1155                                               OutPort->Name() ,
1156                                               true , false , Success ) ;
1157           if ( Success ) {
1158             PortableServer::ObjectId * id = myLink->getId() ;
1159             CORBA::Object_var obj = _poa->id_to_reference(*id);
1160             iobject = SUPERV::Link::_narrow(obj) ;
1161             anOutPort->AddInPortObjRef( anInPort , SUPERV::Link::_duplicate( iobject ) ) ;
1162           }
1163         }
1164       }
1165       else {
1166         iobject = anOutPort->InPortObjRef( anInPort ) ;
1167       }
1168     }
1169   }
1170   DataFlowEditor()->UnValid() ;
1171 //  endService( "Graph_Impl::Link" );
1172   return SUPERV::Link::_duplicate( iobject ) ;
1173 }
1174
1175 // Only to see MacroNodes with actual GUI ... :
1176 #define GOTOMacroNode 0
1177
1178 void Graph_Impl::SetNodeObjRef( GraphEditor::InNode * anInNode ) {
1179   MESSAGE("Graph_Impl::SetNodeObjRef " << anInNode->Name() << " " << anInNode->Kind() ) ;
1180   CORBA::Object_var obj ;
1181   if ( anInNode->IsComputingNode() ) {
1182     CNode_Impl * myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
1183                                           instanceName() , interfaceName() ,
1184                                           DataFlowEditor() ,
1185                                           anInNode ) ;
1186     PortableServer::ObjectId * id = myNode->getId() ;
1187     obj = _poa->id_to_reference(*id);
1188     SUPERV::CNode_var iobject = SUPERV::CNode::_narrow(obj) ;
1189     myNode->SetObjRef( SUPERV::CNode::_duplicate( iobject ) ) ;
1190   }
1191   else if ( anInNode->IsFactoryNode() ) {
1192     FNode_Impl * myNode = new FNode_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::FNode_var iobject = SUPERV::FNode::_narrow(obj) ;
1199     myNode->SetObjRef( SUPERV::FNode::_duplicate( iobject ) ) ;
1200   }
1201   else if ( anInNode->IsInLineNode() ) {
1202     INode_Impl * myNode = new INode_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::INode_var iobject = SUPERV::INode::_narrow(obj) ;
1209     myNode->SetObjRef( SUPERV::INode::_duplicate( iobject ) ) ;
1210   }
1211 #if GOTOMacroNode
1212   else if ( anInNode->IsGOTONode() || anInNode->IsMacroNode() ) {
1213     if ( anInNode->IsMacroNode() ) {
1214       anInNode->ComputingNode()->Kind( SUPERV::GOTONode ) ;
1215     }
1216 #else
1217   else if ( anInNode->IsGOTONode() ) {
1218 #endif
1219     GNode_Impl * myNode = new GNode_Impl( _Orb , _Poa , _ContId ,
1220                                           instanceName() , interfaceName() ,
1221                                           DataFlowEditor() ,
1222                                           anInNode ) ;
1223     PortableServer::ObjectId * id = myNode->getId() ;
1224     obj = _poa->id_to_reference(*id);
1225     SUPERV::GNode_var iobject = SUPERV::GNode::_narrow(obj) ;
1226     myNode->SetObjRef( SUPERV::GNode::_duplicate( iobject ) ) ;
1227   }
1228   else if ( anInNode->IsMacroNode() ) {
1229     Graph_Impl * myNode = new Graph_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::Graph_var iobject = SUPERV::Graph::_narrow(obj) ;
1236     myNode->SetObjRef( SUPERV::Graph::_duplicate( iobject ) ) ;
1237   }
1238   else if ( anInNode->IsLoopNode() ) {
1239     LNode_Impl * myNode = new LNode_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::LNode_var iobject = SUPERV::LNode::_narrow(obj) ;
1246     myNode->SetObjRef( SUPERV::LNode::_duplicate( iobject ) ) ;
1247   }
1248   else if ( anInNode->IsEndLoopNode() ) {
1249     ELNode_Impl * myNode = new ELNode_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::ELNode_var iobject = SUPERV::ELNode::_narrow(obj) ;
1256     myNode->SetObjRef( SUPERV::ELNode::_duplicate( iobject ) ) ;
1257   }
1258   else if ( anInNode->IsSwitchNode() ) {
1259     SNode_Impl * myNode = new SNode_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::SNode_var iobject = SUPERV::SNode::_narrow(obj) ;
1266     myNode->SetObjRef( SUPERV::SNode::_duplicate( iobject ) ) ;
1267   }
1268   else if ( anInNode->IsEndSwitchNode() ) {
1269     ESNode_Impl * myNode = new ESNode_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::ESNode_var iobject = SUPERV::ESNode::_narrow(obj) ;
1276     myNode->SetObjRef( SUPERV::ESNode::_duplicate( iobject ) ) ;
1277   }
1278 }
1279
1280 SUPERV::ListOfNodes_var  Graph_Impl::SetNode( SUPERV::ListOfNodes_var RetVal ,
1281                                               GraphBase::ComputingNode * aNode ) {
1282   int index = 0 ;
1283 //  if ( _DataFlowExecutor ) {
1284   if ( DataFlowExecutor() ) {
1285     MESSAGE("Graph_Impl::SetNode " << aNode->Name() << " " << aNode->Kind() << " "
1286             << DataFlowExecutor()->StateName( DataFlowExecutor()->AutomatonState( aNode->Name() ) ) ) ;
1287   }
1288   else {
1289     MESSAGE("Graph_Impl::SetNode " << aNode->Name() << " " << aNode->Kind() ) ;
1290   }
1291   if ( aNode->IsComputingNode() ) {
1292     index = RetVal->CNodes.length() ;
1293     RetVal->CNodes.length( index+1 );
1294   }
1295   else if ( aNode->IsFactoryNode() ) {
1296     index = RetVal->FNodes.length() ;
1297     RetVal->FNodes.length( index+1 );
1298   }
1299   else if ( aNode->IsInLineNode() ) {
1300     index = RetVal->INodes.length() ;
1301     RetVal->INodes.length( index+1 );
1302   }
1303 #if GOTOMacroNode
1304   else if ( aNode->IsGOTONode() || aNode->IsMacroNode() ) {
1305 #else
1306   else if ( aNode->IsGOTONode() ) {
1307 #endif
1308     index = RetVal->GNodes.length() ;
1309     RetVal->GNodes.length( index+1 );
1310   }
1311   else if ( aNode->IsMacroNode() ) {
1312     index = RetVal->Graphs.length() ;
1313     RetVal->Graphs.length( index+1 );
1314   }
1315   else if ( aNode->IsLoopNode() ) {
1316     index = RetVal->LNodes.length() ;
1317     RetVal->LNodes.length( index+1 );
1318   }
1319   else if ( aNode->IsEndLoopNode() ) {
1320     index = RetVal->ELNodes.length() ;
1321     RetVal->ELNodes.length( index+1 );
1322   }
1323   else if ( aNode->IsSwitchNode() ) {
1324     index = RetVal->SNodes.length() ;
1325     RetVal->SNodes.length( index+1 );
1326   }
1327   else if ( aNode->IsEndSwitchNode() ) {
1328     index = RetVal->ESNodes.length() ;
1329     RetVal->ESNodes.length( index+1 );
1330   }
1331   if ( CORBA::is_nil( aNode->ObjRef() ) ) {
1332     SetNodeObjRef( (GraphEditor::InNode * ) aNode->GetInNode() ) ;
1333   }
1334   SUPERV::CNode_var aNodeObjRef = aNode->ObjRef() ;
1335   if ( aNode->IsComputingNode() ) {
1336     RetVal->CNodes[index] = SUPERV::CNode::_duplicate( aNodeObjRef ) ;
1337   }
1338   else if ( aNode->IsFactoryNode() ) {
1339     RetVal->FNodes[index] = SUPERV::FNode::_duplicate( SUPERV::FNode::_narrow( aNodeObjRef ) ) ;
1340   }
1341   else if ( aNode->IsInLineNode() ) {
1342     RetVal->INodes[index] = SUPERV::INode::_duplicate( SUPERV::INode::_narrow( aNodeObjRef ) ) ;
1343   }
1344 #if GOTOMacroNode
1345   else if ( aNode->IsGOTONode() || aNode->IsMacroNode() ) {
1346 #else
1347   else if ( aNode->IsGOTONode() ) {
1348 #endif
1349     RetVal->GNodes[index] = SUPERV::GNode::_duplicate( SUPERV::GNode::_narrow( aNodeObjRef ) ) ;
1350   }
1351   else if ( aNode->IsMacroNode() ) {
1352     RetVal->Graphs[index] = SUPERV::Graph::_duplicate( SUPERV::Graph::_narrow( aNodeObjRef ) ) ;
1353   }
1354   else if ( aNode->IsLoopNode() ) {
1355     RetVal->LNodes[index] = SUPERV::LNode::_duplicate( SUPERV::LNode::_narrow( aNodeObjRef ) ) ;
1356   }
1357   else if ( aNode->IsEndLoopNode() ) {
1358     RetVal->ELNodes[index] = SUPERV::ELNode::_duplicate( SUPERV::ELNode::_narrow( aNodeObjRef ) ) ;
1359   }
1360   else if ( aNode->IsSwitchNode() ) {
1361     RetVal->SNodes[index] = SUPERV::SNode::_duplicate( SUPERV::SNode::_narrow( aNodeObjRef ) ) ;
1362   }
1363    else if ( aNode->IsEndSwitchNode() ) {
1364     RetVal->ESNodes[index] = SUPERV::ESNode::_duplicate( SUPERV::ESNode::_narrow( aNodeObjRef ) ) ;
1365   }
1366  return ( RetVal._retn() ) ;
1367 }
1368
1369 SUPERV::ListOfNodes * Graph_Impl::Nodes() {
1370   SUPERV::ListOfNodes_var RetVal = new SUPERV::ListOfNodes;
1371   beginService( "Graph_Impl::Nodes" );
1372   RetVal->CNodes.length(0) ;
1373   RetVal->FNodes.length(0) ;
1374   RetVal->INodes.length(0) ;
1375   RetVal->LNodes.length(0) ;
1376   RetVal->SNodes.length(0) ;
1377   RetVal->GNodes.length(0) ;
1378   RetVal->Graphs.length(0) ;
1379   if ( !IsMacro() ) {
1380     int i ;
1381     for ( i = 0 ; i < DataFlowEditor()->Graph()->GraphNodesSize() ; i++ ) {
1382       GraphBase::ComputingNode * aNode = DataFlowEditor()->Graph()->GraphNodes( i ) ;
1383       RetVal = SetNode( RetVal , aNode ) ;
1384     }
1385 #if 0
1386     char * aStateG = "" ;
1387     if ( DataFlowExecutor() ) {
1388       aStateG = (char *) DataFlowExecutor()->StateName( DataFlowExecutor()->AutomatonState() ) ;
1389     }
1390     MESSAGE("Graph_Impl::Nodes GraphState " << aStateG << " CNodes " << RetVal->CNodes.length() ) ;
1391     for ( i = 0 ; i < RetVal->CNodes.length() ; i++ ) {
1392       MESSAGE("           " << RetVal->CNodes[ i ] ->Name() ) ;
1393     }
1394     MESSAGE("FNodes " << RetVal->FNodes.length() ) ;
1395     for ( i = 0 ; i < RetVal->FNodes.length() ; i++ ) {
1396       MESSAGE("           " << RetVal->FNodes[ i ] ->Name() ) ;
1397     }
1398     MESSAGE("INodes " << RetVal->INodes.length() ) ;
1399     for ( i = 0 ; i < RetVal->INodes.length() ; i++ ) {
1400       MESSAGE("           " << RetVal->INodes[ i ] ->Name() ) ;
1401     }
1402     MESSAGE("GNodes " << RetVal->GNodes.length() ) ;
1403     for ( i = 0 ; i < RetVal->GNodes.length() ; i++ ) {
1404       MESSAGE("           " << RetVal->GNodes[ i ] ->Name() ) ;
1405     }
1406     MESSAGE("LNodes " << RetVal->LNodes.length() ) ;
1407     for ( i = 0 ; i < RetVal->LNodes.length() ; i++ ) {
1408       MESSAGE("           " << RetVal->LNodes[ i ] ->Name() ) ;
1409     }
1410     MESSAGE("ELNodes " << RetVal->ELNodes.length() ) ;
1411     for ( i = 0 ; i < RetVal->ELNodes.length() ; i++ ) {
1412       MESSAGE("           " << RetVal->ELNodes[ i ] ->Name() ) ;
1413     }
1414     MESSAGE("SNodes " << RetVal->SNodes.length() ) ;
1415     for ( i = 0 ; i < RetVal->SNodes.length() ; i++ ) {
1416       MESSAGE("           " << RetVal->SNodes[ i ] ->Name() ) ;
1417     }
1418     MESSAGE("ESNodes " << RetVal->ESNodes.length() ) ;
1419     for ( i = 0 ; i < RetVal->ESNodes.length() ; i++ ) {
1420       MESSAGE("           " << RetVal->ESNodes[ i ] ->Name() ) ;
1421     }
1422     MESSAGE("Graphs " << RetVal->Graphs.length() ) ;
1423     for ( i = 0 ; i < RetVal->Graphs.length() ; i++ ) {
1424       MESSAGE("           " << RetVal->Graphs[ i ] ->Name() ) ;
1425     }
1426     if ( DataFlowExecutor() ) {
1427       DataFlowExecutor()->EventList() ;
1428     }
1429 #endif
1430   }
1431   endService( "Graph_Impl::Nodes" );
1432   return ( RetVal._retn() ) ;
1433 }
1434
1435 SUPERV::ListOfLinks * Graph_Impl::GLinks() {
1436   return Links( NULL , NULL ) ;
1437 }
1438
1439 SUPERV::ListOfLinks * Graph_Impl::Links( GraphBase::ComputingNode * theNode ,
1440                                          const char * anInputParam ) {
1441   bool begin = true ;
1442   SUPERV::ListOfLinks_var RetVal = new SUPERV::ListOfLinks ;
1443   RetVal->length( 0 ) ;
1444   if ( !IsMacro() ) {
1445     int i , j , countlink ;
1446     countlink = 0 ;
1447     for ( i = 0 ; i < DataFlowEditor()->Graph()->GraphNodesSize() ; i++ ) {
1448       GraphEditor::InNode * aNode = NULL ;
1449       aNode = (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GraphNodes( i )->GetInNode() ;
1450       bool ToProcess = false ;
1451       if ( theNode == NULL ) {
1452         ToProcess = true ;
1453       }
1454       else {
1455         if ( !strcmp( theNode->Name() , aNode->Name() ) ) {
1456           if ( !theNode->IsEndSwitchNode() ) {
1457             ToProcess = true ;
1458           }
1459         }
1460         else if ( theNode->IsEndSwitchNode() ) {
1461           ToProcess = true ;
1462         }
1463       }
1464       if ( ToProcess ) {
1465         for ( j = 0 ; j < aNode->GetNodeInPortsSize() ; j++ ) {
1466           GraphBase::InPort * anInPort = NULL ;
1467           anInPort = aNode->GetChangeNodeInPort( j ) ;
1468           if ( anInputParam == NULL ||
1469                !strcmp( anInPort->PortName() , anInputParam ) ) {
1470             GraphBase::OutPort * anOutPort = NULL ;
1471             anOutPort = anInPort->GetOutPort() ;
1472             if ( anOutPort && !anOutPort->IsDataStream() ) {
1473               if ( strcmp( anOutPort->NodeName() , Name() ) ) {
1474 //                MESSAGE("Graph_Impl::Links " << anOutPort->NodeName() << "("
1475 //                        << anOutPort->PortName() << ") --> " << aNode->Name() << "("
1476 //                        << anInPort->PortName() << ")" ) ;
1477                 if ( theNode == NULL ||
1478                      ( theNode != NULL && !theNode->IsEndSwitchNode() &&
1479                        !strcmp( theNode->Name() , aNode->Name() ) ) ) {
1480                   if ( anInPort->IsLoop() || anOutPort->IsLoop() ||
1481                        ( aNode->IsEndLoopNode() && !strcmp( aNode->CoupledNode()->Name() ,
1482                                                             anOutPort->NodeName() ) ) ) {
1483 //                    MESSAGE( "Link " << anOutPort->NodeName() << "("
1484 //                            << anOutPort->PortName() << ") --> " << aNode->Name() << "("
1485 //                            << anInPort->PortName() << ")" << " ignored" ) ;
1486                   }
1487                   else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
1488                     if ( begin ) {
1489                       beginService( "Graph_Impl::Links" );
1490                       begin = false ;
1491                     }
1492                     GraphEditor::InNode * anOutNode = NULL ;
1493                     anOutNode = (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GetChangeGraphNode( anOutPort->NodeName() )->GetInNode() ;
1494                     if ( anOutNode ) {
1495                       bool Success ;
1496                       Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
1497                                                           instanceName() , interfaceName() ,
1498                                                           DataFlowEditor() ,
1499                                                           aNode ,
1500                                                           anInPort->PortName() ,
1501                                                           anOutNode ,
1502                                                           anOutPort->PortName() ,
1503                                                           false , true , Success ) ;
1504                       if ( Success ) {
1505                         PortableServer::ObjectId * id = myLink->getId() ;
1506                         CORBA::Object_var obj = _poa->id_to_reference(*id);
1507                         SUPERV::Link_var iobject ;
1508                         iobject = SUPERV::Link::_narrow(obj) ;
1509                         RetVal->length( countlink + 1 ) ;
1510                         RetVal[ countlink++ ] = SUPERV::Link::_duplicate( iobject ) ;
1511                         anOutPort->AddInPortObjRef( anInPort , SUPERV::Link::_duplicate( iobject ) ) ;
1512                       }
1513                     }
1514                   }
1515                   else {
1516                     RetVal->length( countlink + 1 ) ;
1517                     RetVal[ countlink++ ] = SUPERV::Link::_duplicate( anOutPort->InPortObjRef( anInPort ) ) ;
1518                   }
1519 //                  MESSAGE( "Link " << anOutPort->NodeName() << "("
1520 //                           << anOutPort->PortName() << ") --> " << aNode->Name() << "("
1521 //                           << anInPort->PortName() << ")" << " selected" ) ;
1522                 }
1523                 else {
1524 //                  MESSAGE( "Link " << anOutPort->NodeName() << "("
1525 //                           << anOutPort->PortName() << ") --> " << aNode->Name() << "("
1526 //                           << anInPort->PortName() << ")" << " skipped" ) ;
1527                 }
1528               }
1529             }
1530           }
1531         }
1532       }
1533       for ( j = 0 ; j < aNode->GetNodeOutPortsSize() ; j++ ) {
1534         GraphBase::OutPort * anOutPort = aNode->GetChangeNodeOutPort( j ) ;
1535 //        MESSAGE( "Graph_Impl::Links " << aNode->Name() << " Out" << j << " " << anOutPort->PortName() << " "
1536 //                 << anOutPort->PortStatus() << " PortConnected to " << anOutPort->InPortsSize() << " InPorts" ) ;
1537         int k ;
1538         for ( k = 0 ; k < anOutPort->InPortsSize() ; k++ ) {
1539           GraphBase::InPort * anInPort = anOutPort->ChangeInPorts( k ) ;
1540 //          MESSAGE( "              -->  In" << k << " " << anInPort->NodeName() << " " << anInPort->PortName()
1541 //                   << " " << anInPort->PortStatus() ) ;
1542           if ( anInPort->IsPortConnected() ) {
1543             GraphBase::ComputingNode * aComputingNode = DataFlowEditor()->Graph()->GetChangeGraphNode( anInPort->NodeName() ) ;
1544             GraphEditor::InNode * toNode = (GraphEditor::InNode * ) aComputingNode->GetInNode() ;
1545             if ( theNode == NULL ||
1546                  !strcmp( theNode->Name() , aNode->Name() ) ) {
1547               if ( !anInPort->IsDataStream() ) {
1548                 if ( theNode || ( toNode->IsEndSwitchNode() && !aNode->IsSwitchNode() ) ) {
1549                   if ( anInputParam == NULL ||
1550                        !strcmp( anInPort->PortName() , anInputParam ) ) {
1551                     if ( anInPort->IsLoop() || anOutPort->IsLoop() ||
1552                          ( toNode->IsEndLoopNode() && !strcmp( toNode->CoupledNode()->Name() ,
1553                                                                anOutPort->NodeName() ) ) ) {
1554 //                      MESSAGE( "Link " << anOutPort->NodeName() << "("
1555 //                              << anOutPort->PortName() << ") --> " << toNode->Name() << "("
1556 //                              << anInPort->PortName() << ")" << " ignored" ) ;
1557                     }
1558                     else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
1559                       if ( begin ) {
1560                         beginService( "Graph_Impl::Links" );
1561                         begin = false ;
1562                       }
1563                       bool Success ;
1564                       Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
1565                                                           instanceName() , interfaceName() ,
1566                                                           DataFlowEditor() ,
1567                                                           toNode ,
1568                                                           anInPort->PortName() ,
1569                                                           aNode ,
1570                                                           anOutPort->PortName() ,
1571                                                           false , true , Success ) ;
1572                       if ( Success ) {
1573                         PortableServer::ObjectId * id = myLink->getId() ;
1574                         CORBA::Object_var obj = _poa->id_to_reference(*id);
1575                         SUPERV::Link_var iobject ;
1576                         iobject = SUPERV::Link::_narrow(obj) ;
1577                         RetVal->length( countlink + 1 ) ;
1578                         RetVal[ countlink++ ] = SUPERV::Link::_duplicate( iobject ) ;
1579                         anOutPort->AddInPortObjRef( anInPort , SUPERV::Link::_duplicate( iobject ) ) ;
1580                       }
1581                     }
1582                     else {
1583                       RetVal->length( countlink + 1 ) ;
1584                       RetVal[ countlink++ ] = SUPERV::Link::_duplicate( SUPERV::Link::_narrow( anOutPort->InPortObjRef( anInPort ) ) ) ;
1585                     }
1586 //                    MESSAGE( "Link " << anOutPort->NodeName() << "("
1587 //                             << anOutPort->PortName() << ") --> " << toNode->Name() << "("
1588 //                             << anInPort->PortName() << ")" << " selected" ) ;
1589                   }
1590                   else {
1591 //                    MESSAGE( "Link " << anOutPort->NodeName() << "("
1592 //                             << anOutPort->PortName() << ") --> " << toNode->Name() << "("
1593 //                             << anInPort->PortName() << ")" << " skipped" ) ;
1594                   }
1595                 }
1596               }
1597             }
1598           }
1599         }
1600       }
1601     }
1602
1603 #if 0
1604     const char * NodeName = "" ;
1605     const char * InputParamName = "" ;
1606     if ( theNode ) {
1607       NodeName = theNode->Name() ;
1608     }
1609     if ( anInputParam ) {
1610       InputParamName = anInputParam ;
1611     }
1612     MESSAGE( RetVal->length() << " Links of Node " << NodeName << " and of InPort " << InputParamName ) ;
1613     for ( i = 0 ; i < (int ) RetVal->length() ; i++ ) {
1614       MESSAGE( "Link " << RetVal[i]->OutPort()->Node()->Name() << "("
1615                << RetVal[i]->OutPort()->Name() << ") --> "
1616                << RetVal[i]->InPort()->Node()->Name() << "("
1617                << RetVal[i]->InPort()->Name() << ")" ) ;
1618     }
1619 #endif
1620     if ( !begin ) {
1621       endService( "Graph_Impl::Links" );
1622     }
1623   }
1624   return ( RetVal._retn() ) ;
1625 }
1626
1627 Engines::Component_ptr Graph_Impl::ComponentRef( const char * aComputerContainer ,
1628                                                  const char * aComponentName ) {
1629   Engines::Component_var objComponent = Engines::Component::_nil() ;
1630   if ( !IsMacro() ) {
1631     Engines::Container_var myContainer ;
1632     DataFlowEditor()->Graph()->StartComponent( 0 , aComputerContainer , aComponentName ,
1633                                                myContainer , objComponent ) ;
1634   }
1635   return Engines::Component::_duplicate( objComponent ) ;
1636 }
1637
1638 bool Graph_Impl::IsValid() {
1639 //  beginService( "Graph_Impl::IsValid" );
1640   bool RetVal = false ;
1641   if ( !IsMacro() ) {
1642     RetVal = DataFlowEditor()->IsValid() ;
1643   }
1644 //  endService( "Graph_Impl::IsValid" );
1645   return RetVal ;
1646 }
1647 bool Graph_Impl::IsExecutable() {
1648 //  beginService( "Graph_Impl::IsExecutable" );
1649   bool RetVal = false ;
1650
1651   // asv : 15.11.04 : added "&& GraphMacroLevel() == 0" -> 
1652   // subgraphs are not executable by themselves, RetVal = false..
1653   if ( !IsMacro() && DataFlowEditor()->Graph()->GraphMacroLevel() == 0 ) {
1654     RetVal = DataFlowEditor()->IsExecutable() ;
1655   }
1656 //  endService( "Graph_Impl::IsExecutable" );
1657   return RetVal ;
1658 }
1659
1660 bool Graph_Impl::IsEditing() {
1661 /*
1662   bool RetVal = false ;
1663   if ( !IsMacro() ) {
1664     RetVal = DataFlowEditor()->IsEditing() ;
1665   }
1666   return RetVal ;
1667 */
1668   if ( IsMacro() )
1669     return false;
1670   return !IsExecuting();
1671 }
1672
1673 bool Graph_Impl::IsExecuting() {
1674 /*
1675   bool RetVal = false ;
1676   if ( !IsMacro() ) {
1677     RetVal = !DataFlowEditor()->IsEditing() ;
1678   }
1679   return RetVal ;
1680 */
1681   return CNode_Impl::IsExecuting();
1682 }
1683
1684 bool Graph_Impl::IsReadOnly() {
1685 //  beginService( "Graph_Impl::IsExecuting" );
1686   bool RetVal = false ;
1687   if ( !IsMacro() ) {
1688     RetVal = DataFlowEditor()->IsReadOnly() ;
1689   }
1690 //  endService( "Graph_Impl::IsExecuting" );
1691   return RetVal ;
1692 }
1693
1694 long Graph_Impl::LevelMax() {
1695 //  beginService( "Graph_Impl::LevelMax" );
1696   long RetVal = 0 ;
1697   if ( !IsMacro() ) {
1698     RetVal = DataFlowEditor()->LevelMax() ;
1699   }
1700 //  endService( "Graph_Impl::LevelMax" );
1701   return RetVal ;
1702 }
1703 SUPERV::ListOfNodes * Graph_Impl::LevelNodes(long aLevel ) {
1704 //  beginService( "Graph_Impl::LevelNodes" );
1705   SUPERV::ListOfNodes_var RetVal = new SUPERV::ListOfNodes;
1706   if ( !IsMacro() ) {
1707     int i ;
1708     SUPERV::ListOfStrings_var Nodes = DataFlowEditor()->LevelNodes( aLevel ) ;
1709 //  RetVal->length( Nodes->length() );
1710     for ( i = 0 ; i < (int ) Nodes->length() ; i++ ) {
1711 //    char * aNode = Nodes[ i ] ;
1712       GraphBase::ComputingNode * aNode = DataFlowEditor()->Graph()->GetChangeGraphNode( Nodes[ i ] ) ;
1713       RetVal = SetNode( RetVal , aNode ) ;
1714 //    cout << "Graph_Impl::LevelNodes( " << aLevel << " ) " << aNode->Name() << endl ;
1715 //    CNode_Impl * myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
1716 //                               instanceName() , interfaceName() ,
1717 //                               DataFlowEditor() ,
1718 //                               (GraphEditor::InNode * ) DataFlowEditor()->GetChangeGraphNode( aNode )->GetInNode() ) ;
1719 //    PortableServer::ObjectId * id = myNode->getId() ;
1720 //    CORBA::Object_var obj = _poa->id_to_reference(*id);
1721 //    SUPERV::CNode_var iobject ;
1722 //    iobject = SUPERV::CNode::_narrow(obj) ;
1723 //    RetVal[i] = SUPERV::CNode::_duplicate( iobject ) ;
1724     }
1725   }
1726 //  endService( "Graph_Impl::LevelNodes" );
1727   return ( RetVal._retn() ) ;
1728 }
1729 long Graph_Impl::ThreadsMax() {
1730 //  beginService( "Graph_Impl::ThreadsMax" );
1731   long RetVal = 0 ;
1732   if ( !IsMacro() ) {
1733     RetVal =  DataFlowEditor()->ThreadsMax() ;
1734   }
1735 //  endService( "Graph_Impl::ThreadsMax" );
1736   return RetVal ;
1737 }
1738 long Graph_Impl::Threads() {
1739 //  beginService( "Node_Impl::Threads" );
1740   long RetVal = false ;
1741   if ( !IsMacro() ) {
1742     RetVal = DataFlowExecutor()->Threads() ;
1743   }
1744 //  endService( "Node_Impl::Threads" );
1745   return RetVal ;
1746 }
1747 long Graph_Impl::SuspendedThreads() {
1748 //  beginService( "Node_Impl::SuspendedThreads" );
1749   long RetVal = false ;
1750   if ( !IsMacro() ) {
1751     RetVal = DataFlowExecutor()->SuspendedThreads() ;
1752   }
1753 //  endService( "Node_Impl::SuspendedThreads" );
1754   return RetVal ;
1755 }
1756
1757 bool Graph_Impl::Begin() {
1758   bool RetVal = false ;
1759   if ( DataFlowEditor()->IsEditing() ) {
1760     if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1761       perror("pthread_mutex_lock _MutexExecutorWait") ;
1762       exit( 0 ) ;
1763     }
1764     if ( DataFlowExecutor() ) {
1765       MESSAGE( "Graph_Impl::Begin " << DataFlowExecutor()->Threads() << " threads" )
1766 //      if ( DataFlowExecutor()->Threads() ) {
1767 //        DataFlowExecutor()->JoinedWait() ;
1768 //      }
1769       delete DataFlowExecutor() ;
1770       DataFlowEditor()->Executor( NULL ) ;
1771     }
1772     if ( DataFlowEditor()->IsExecutable() ) {
1773       DataFlowEditor()->EditedAfterExecution( false ) ;
1774       GraphBase::ListOfSGraphs * myListOfGraphs = DataFlowEditor()->GetDataFlows() ;
1775
1776       GraphExecutor::DataFlow * aDataFlowExecutor ;
1777       string dbgfile ;
1778       CreateExecutor( _Orb , instanceName() , (*myListOfGraphs)[ 0 ].Info.theName.c_str() , Kind() ,
1779                       dbgfile , &aDataFlowExecutor ) ;
1780
1781       MESSAGE( "Graph_Impl::Begin : DataFlowExecutor created" );
1782       if ( !CORBA::is_nil( LoadDataFlows( aDataFlowExecutor, myListOfGraphs , 0 ) ) ) 
1783         RetVal = true ;
1784   
1785       if ( RetVal )
1786         DataFlowExecutor()->Graph()->SetObjImpl( DataFlowEditor()->Graph()->ObjImpl() ) ;
1787     
1788     }
1789     if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1790       perror("pthread_mutex_unlock _MutexExecutorWait") ;
1791       exit( 0 ) ;
1792     }
1793   }
1794   return RetVal ;
1795 }
1796 bool Graph_Impl::Run() {
1797   beginService( "Graph_Impl::Run" );
1798   bool RetVal = false ;
1799   if ( ( DataFlowEditor()->IsEditing() || IsDone() ) && !IsMacro() ) {
1800     MESSAGE( "Graph_Impl::Run " << DataFlowEditor()->Graph()->Name() << " " << DataFlowEditor() << " IsEditing" );
1801     if ( DataFlowEditor()->Graph()->GraphMacroLevel() ) {
1802       MESSAGE( "Graph_Impl::Run " << DataFlowEditor()->Graph()->Name() << " GraphMacroLevel "
1803                << DataFlowEditor()->Graph()->GraphMacroLevel() ) ;
1804       RetVal = true ;
1805     }
1806     else {
1807       MESSAGE( "Graph_Impl::Run " << DataFlowEditor()->Graph()->Name() << " GraphMacroLevel "
1808                << DataFlowEditor()->Graph()->GraphMacroLevel() << " --> Begin()" ) ;
1809       RetVal = Begin() ;
1810     }
1811     if ( RetVal ) {
1812       MESSAGE( "Graph_Impl::Run " );
1813       DataFlowEditor()->Executing() ;
1814       RetVal = CNode_Impl::Run() ;
1815     }
1816   }
1817 // It is necessary to reload the dataflow because of ports with input initial values changed
1818 // during execution to values of outport of EndLoopNode or GOTONode
1819 //  else if ( !IsMacro() && IsDone() ) {
1820 //    MESSAGE( "Graph_Impl::Run " << DataFlowEditor()->Graph()->Name() << " " << DataFlowEditor()
1821 //             << " IsNOTEditing --> CNode_Impl::ReRun" );
1822 //    DataFlowEditor()->Executing() ;
1823 //    RetVal = CNode_Impl::ReRun() ;
1824 //  }
1825   MESSAGE( "Graph_Impl::Run " << DataFlowEditor()->Graph()->Name() << " RetVal " << RetVal ) ;
1826   endService( "Graph_Impl::Run" );
1827   return RetVal ;
1828 }
1829 bool Graph_Impl::Start() {
1830   beginService( "Graph_Impl::Start" );
1831   bool RetVal = false ;
1832   if ( ( DataFlowEditor()->IsEditing() || IsDone() ) && !IsMacro() ) {
1833     MESSAGE( "Graph_Impl::Start " << DataFlowEditor()->Graph()->Name() << " " << DataFlowEditor() << " IsEditing" );
1834     if ( DataFlowEditor()->Graph()->GraphMacroLevel() ) {
1835       MESSAGE( "Graph_Impl::Start " << DataFlowEditor()->Graph()->Name() << " GraphMacroLevel "
1836                << DataFlowEditor()->Graph()->GraphMacroLevel() ) ;
1837       RetVal = true ;
1838     }
1839     else {
1840       MESSAGE( "Graph_Impl::Start " << DataFlowEditor()->Graph()->Name() << " GraphMacroLevel "
1841                << DataFlowEditor()->Graph()->GraphMacroLevel() << " --> Begin()" ) ;
1842       RetVal = Begin() ;
1843     }
1844     if ( RetVal ) {
1845       // Added by NKV to fix PAL6222 --> to be confirm by JR ; JR confirmed
1846       DataFlowEditor()->Executing() ;
1847       // End of NKV's correction
1848       MESSAGE( "Graph_Impl::(Re)Start " );
1849       RetVal = ReStart() ;
1850     }
1851   }
1852 // It is necessary to reload the dataflow because of ports with input initial values changed
1853 // during execution to values of outport of EndLoopNode or GOTONode
1854 //  else if ( !IsMacro() && IsDone() ) {
1855 //    MESSAGE( "Graph_Impl::Start " << DataFlowEditor()->Graph()->Name() << " " << DataFlowEditor()
1856 //             << " IsNOTEditing --> CNode_Impl::ReStart" );
1857 //    DataFlowEditor()->Executing() ;
1858 //    RetVal = CNode_Impl::ReStart() ;
1859 //  }
1860   MESSAGE( "Graph_Impl::Start " << DataFlowEditor()->Graph()->Name() << " RetVal " << RetVal ) ;
1861   endService( "Graph_Impl::Start" );
1862   return RetVal ;
1863 }
1864
1865 bool Graph_Impl::EventNoW( SUPERV::CNode_out aNode ,
1866                            SUPERV::GraphEvent & anEvent ,
1867                            SUPERV::GraphState & aState ) {
1868   bool RetVal = false ;
1869   char * aNodeName = NULL ;
1870   SUPERV::GraphEvent theEvent = SUPERV::UndefinedEvent ;
1871   SUPERV::GraphState theState = SUPERV::UndefinedState ;
1872   if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1873     perror("pthread_mutex_lock _MutexExecutorWait") ;
1874     exit( 0 ) ;
1875   }
1876   if ( DataFlowExecutor() && !IsMacro() &&
1877        ( DataFlowExecutor()->GetListSize() || !DataFlowEditor()->IsEditing() ) ) {
1878     RetVal = DataFlowExecutor()->Event( & aNodeName , theEvent , theState , false ) ;
1879 //  endService( "Graph_Impl::Event" );
1880     if ( strlen( aNodeName ) ) {
1881       if ( strcmp( aNodeName , Name() ) ) {
1882         aNode = Node( aNodeName ) ;
1883       }
1884       else {
1885         aNode = Node() ;
1886       }
1887     }
1888     else {
1889       aNode = SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
1890     }
1891 //    cout << "Graph_Impl::EventNoW " << aNode->Name() << " QSize " << DataFlowExecutor()->GetListSize() << endl ;
1892   }
1893   else {
1894 //    cout << "Graph_Impl::EventNoW NO DataFlowExecutor() or QSize=0 " << endl ;
1895   }
1896   if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1897     perror("pthread_mutex_unlock _MutexExecutorWait") ;
1898     exit( 0 ) ;
1899   }
1900   anEvent = theEvent ;
1901   aState = theState ;
1902   return RetVal ;
1903 }
1904
1905 bool Graph_Impl::Event( SUPERV::CNode_out aNode ,
1906                         SUPERV::GraphEvent & anEvent ,
1907                         SUPERV::GraphState & aState ) {
1908 //  beginService( "Graph_Impl::Event" );
1909   bool RetVal = false ;
1910   char * aNodeName = NULL ;
1911   SUPERV::GraphEvent theEvent = SUPERV::UndefinedEvent ;
1912   SUPERV::GraphState theState = SUPERV::UndefinedState ;
1913   if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1914     perror("pthread_mutex_lock _MutexExecutorWait") ;
1915     exit( 0 ) ;
1916   }
1917   if ( DataFlowExecutor() && !IsMacro() &&
1918        ( DataFlowExecutor()->GetListSize() || !DataFlowEditor()->IsEditing() ) ){
1919     RetVal = DataFlowExecutor()->Event( & aNodeName , theEvent , theState ) ;
1920 //  endService( "Graph_Impl::Event" );
1921     if ( strlen( aNodeName ) ) {
1922       if ( strcmp( aNodeName , Name() ) ) {
1923         aNode = Node( aNodeName ) ;
1924       }
1925       else {
1926         aNode = Node() ;
1927       }
1928     }
1929     else {
1930       aNode = SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
1931     }
1932 //    cout << "Graph_Impl::Event " << aNode->Name() << " QSize " << DataFlowExecutor()->GetListSize() << endl ;
1933   }
1934   else {
1935 //    cout << "Graph_Impl::Event NO DataFlowExecutor() or QSize=0 " << endl ;
1936   }
1937   if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1938     perror("pthread_mutex_unlock _MutexExecutorWait") ;
1939     exit( 0 ) ;
1940   }
1941   anEvent = theEvent ;
1942   aState = theState ;
1943   return RetVal ;
1944 }
1945
1946 bool Graph_Impl::EventW( SUPERV::CNode_out aNode ,
1947                          SUPERV::GraphEvent & anEvent ,
1948                          SUPERV::GraphState & aState ) {
1949 //  beginService( "Graph_Impl::EventW" );
1950   bool RetVal = false ;
1951   char * aNodeName = NULL ;
1952   SUPERV::GraphEvent theEvent = SUPERV::UndefinedEvent ;
1953   SUPERV::GraphState theState = SUPERV::UndefinedState ;
1954   if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1955     perror("pthread_mutex_lock _MutexExecutorWait") ;
1956     exit( 0 ) ;
1957   }
1958   if ( DataFlowExecutor() && !IsMacro() &&
1959        ( DataFlowExecutor()->GetListSize() || !DataFlowEditor()->IsEditing() ) ) {
1960     RetVal = DataFlowExecutor()->EventW( & aNodeName , theEvent , theState ) ;
1961     if ( RetVal && strcmp( aNodeName , Name() ) ) {
1962       aNode = Node( aNodeName ) ;
1963     }
1964     else {
1965       aNode = Node() ;
1966     }
1967   }
1968   if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1969     perror("pthread_mutex_unlock _MutexExecutorWait") ;
1970     exit( 0 ) ;
1971   }
1972   anEvent = theEvent ;
1973   aState = theState ;
1974 //  endService( "Graph_Impl::EventW" );
1975   return RetVal ;
1976 }
1977
1978 long Graph_Impl::EventQSize() {
1979 //  beginService( "Graph_Impl::EventQSize" );
1980   long QSize = -1 ;
1981   if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1982     perror("pthread_mutex_lock _MutexExecutorWait") ;
1983     exit( 0 ) ;
1984   }
1985   if ( DataFlowExecutor() && !IsMacro() ) {
1986     QSize = DataFlowExecutor()->EventQSize() ;
1987   }
1988   if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1989     perror("pthread_mutex_unlock _MutexExecutorWait") ;
1990     exit( 0 ) ;
1991   }
1992 //  endService( "Graph_Impl::EventQSize" );
1993   return QSize ;
1994 }
1995
1996 long Graph_Impl::LastLevelDone() {
1997 //  beginService( "Graph_Impl::LastLevelDone" );
1998   if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1999     perror("pthread_mutex_lock _MutexExecutorWait") ;
2000     exit( 0 ) ;
2001   }
2002   long RetVal = 0 ;
2003   if ( DataFlowExecutor() && !IsMacro() ) {
2004     RetVal = DataFlowExecutor()->LastLevelDone() ;
2005   }
2006   if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
2007     perror("pthread_mutex_unlock _MutexExecutorWait") ;
2008     exit( 0 ) ;
2009   }
2010 //  endService( "Graph_Impl::LastLevelDone" );
2011   return RetVal ;
2012 }
2013
2014 long Graph_Impl::SubGraphsNumber() {
2015 //  beginService( "Graph_Impl::SubGraphsNumber" );
2016   long RetVal = 0 ;
2017   if ( DataFlowEditor()->IsExecutable() && !IsMacro() ) {
2018     RetVal = DataFlowEditor()->SubGraphsNumber() ;
2019   }
2020 //  endService( "Graph_Impl::SubGraphsNumber" );
2021   return RetVal ;
2022 }
2023
2024 SUPERV::ListOfNodes * Graph_Impl::SubGraphsNodes( const long aSubGraphNumber ) {
2025   beginService( "Graph_Impl::SubGraphsNodes" );
2026   SUPERV::ListOfNodes_var RetVal = new SUPERV::ListOfNodes ;
2027   if ( DataFlowEditor()->IsEditing() && !IsMacro() ) {
2028     SUPERV::ListOfNodes * aGraphNodes = Nodes() ;
2029     int i ;
2030 // ComputingNodes
2031     for ( i = 0 ; i < (int ) aGraphNodes->CNodes.length() ; i++ ) {
2032       SUPERV::CNode_var aNode = (aGraphNodes->CNodes)[ i ] ;
2033       if ( aNode->SubGraph() == aSubGraphNumber ) {
2034         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
2035       }
2036     }
2037 // FactoryNodes
2038     for ( i = 0 ; i < (int ) aGraphNodes->FNodes.length() ; i++ ) {
2039       SUPERV::FNode_var aNode = (aGraphNodes->FNodes)[ i ] ;
2040       if ( aNode->SubGraph() == aSubGraphNumber ) {
2041         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
2042       }
2043     }
2044 // InLineNodes
2045     for ( i = 0 ; i < (int ) aGraphNodes->INodes.length() ; i++ ) {
2046       SUPERV::INode_var aNode = (aGraphNodes->INodes)[ i ] ;
2047       if ( aNode->SubGraph() == aSubGraphNumber ) {
2048         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
2049       }
2050     }
2051 // GOTONodes
2052     for ( i = 0 ; i < (int ) aGraphNodes->GNodes.length() ; i++ ) {
2053       SUPERV::GNode_var aNode = (aGraphNodes->GNodes)[ i ] ;
2054       if ( aNode->SubGraph() == aSubGraphNumber ) {
2055         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
2056       }
2057     }
2058 // LoopNodes
2059     for ( i = 0 ; i < (int ) aGraphNodes->LNodes.length() ; i++ ) {
2060       SUPERV::LNode_var aNode = (aGraphNodes->LNodes)[ i ] ;
2061       if ( aNode->SubGraph() == aSubGraphNumber ) {
2062         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
2063       }
2064     }
2065 // EndLoopNodes
2066     for ( i = 0 ; i < (int ) aGraphNodes->ELNodes.length() ; i++ ) {
2067       SUPERV::ELNode_var aNode = (aGraphNodes->ELNodes)[ i ] ;
2068       if ( aNode->SubGraph() == aSubGraphNumber ) {
2069         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
2070       }
2071     }
2072 // SwitchNodes
2073     for ( i = 0 ; i < (int ) aGraphNodes->SNodes.length() ; i++ ) {
2074       SUPERV::SNode_var aNode = (aGraphNodes->SNodes)[ i ] ;
2075       if ( aNode->SubGraph() == aSubGraphNumber ) {
2076         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
2077       }
2078     }
2079 // EndSwitchNodes
2080     for ( i = 0 ; i < (int ) aGraphNodes->ESNodes.length() ; i++ ) {
2081       SUPERV::ESNode_var aNode = (aGraphNodes->ESNodes)[ i ] ;
2082       if ( aNode->SubGraph() == aSubGraphNumber ) {
2083         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
2084       }
2085     }
2086   }
2087   endService( "Graph_Impl::SubGraphsNodes" );
2088   return ( RetVal._retn() ) ;
2089 }
2090
2091 bool Graph_Impl::Merge(const SUPERV::Graph_ptr aGraph ) {
2092 //  beginService( "Graph_Impl::Merge" );
2093   bool RetVal = true ;
2094   if ( !IsMacro() ) {
2095     map< string , int > aMapOfNodes ;
2096     RetVal = Merge( aGraph , aMapOfNodes ) ;
2097   }
2098 //  endService( "Graph_Impl::Merge" );
2099   return RetVal ;
2100 }
2101
2102 bool Graph_Impl::Merge(const SUPERV::Graph_ptr aGraph , map< string , int > & aMapOfNodes ) {
2103   beginService( "Graph_Impl::Merge" );
2104   bool RetVal = true ;
2105   if ( DataFlowEditor()->IsEditing() && !IsMacro() ) {
2106     SUPERV::ListOfNodes * aGraphNodes = aGraph->Nodes() ;
2107     int i ;
2108     SUPERV::Port_ptr aPort ;
2109 //    SUPERV::StreamPort_ptr aStreamPort ;
2110 // ComputingNodes
2111     for ( i = 0 ; i < (int ) aGraphNodes->CNodes.length() ; i++ ) {
2112       SUPERV::CNode_var aNode = (aGraphNodes->CNodes)[ i ] ;
2113       SUPERV::CNode_ptr myNode = CNode( *(aNode->Service()) ) ;
2114       if ( !CORBA::is_nil( myNode ) ) {
2115         myNode->SetName( aNode->Name() ) ;
2116         myNode->SetAuthor( aNode->Author() ) ;
2117         myNode->SetComment( aNode->Comment() ) ;
2118         myNode->Coords( aNode->X() , aNode->Y() ) ;
2119         string * aNodetheName = new string( aNode->Name() ) ;
2120         aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
2121         delete aNodetheName ;
2122         RetVal = true ;
2123       }
2124       else {
2125         RetVal = false ;
2126         break ;
2127       }
2128 // The following informations are now in the service from SALOME_ModuleCatalog
2129 //      SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
2130 //      int j ;
2131 //      for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
2132 //        if ( myStreamPorts[ j ]->IsInput() && myStreamPorts[ j ]->IsDataStream() ) {
2133 //          aStreamPort = myNode->InStreamPort( myStreamPorts[ j ]->Name() , myStreamPorts[ j ]->Type() ) ;
2134 //        }
2135 //        else if ( myStreamPorts[ j ]->IsDataStream() ) {
2136 //          aStreamPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name() , myStreamPorts[ j ]->Type() ) ;
2137 //        }
2138 //      }
2139     }
2140 // FactoryNodes
2141     if ( RetVal ) {
2142       for ( i = 0 ; i < (int ) aGraphNodes->FNodes.length() ; i++ ) {
2143         SUPERV::FNode_var aNode = (aGraphNodes->FNodes)[ i ] ;
2144         SUPERV::FNode_ptr myNode = FNode( aNode->GetComponentName() ,
2145                                           aNode->GetInterfaceName() ,
2146                                           *(aNode->Service()) ) ;
2147         if ( !CORBA::is_nil( myNode ) ) {
2148           myNode->SetName( aNode->Name() ) ;
2149           myNode->SetAuthor( aNode->Author() ) ;
2150           myNode->SetComment( aNode->Comment() ) ;
2151           myNode->Coords( aNode->X() , aNode->Y() ) ;
2152           string * aNodetheName = new string( aNode->Name() ) ;
2153           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
2154           delete aNodetheName ;
2155           RetVal = true ;
2156         }
2157         else {
2158           RetVal = false ;
2159           break ;
2160         }
2161 // The following informations are now in the service from SALOME_ModuleCatalog
2162 //        SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
2163 //        int j ;
2164 //        for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
2165 //          if ( myStreamPorts[ j ]->IsInput() && myStreamPorts[ j ]->IsDataStream() ) {
2166 //            aStreamPort = myNode->InStreamPort( myStreamPorts[ j ]->Name() , myStreamPorts[ j ]->Type() ) ;
2167 //          }
2168 //          else if ( myStreamPorts[ j ]->IsDataStream() ) {
2169 //            aStreamPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name() , myStreamPorts[ j ]->Type() ) ;
2170 //          }
2171 //        }
2172       }
2173     }
2174 // InLineNodes
2175     if ( RetVal ) {
2176       for ( i = 0 ; i < (int ) aGraphNodes->INodes.length() ; i++ ) {
2177         SUPERV::INode_var aNode = (aGraphNodes->INodes)[ i ] ;
2178         SUPERV::INode_ptr myNode = INode( aNode->PyFuncName() , *(aNode->PyFunction()) ) ;
2179         if ( !CORBA::is_nil( myNode ) ) {
2180           myNode->SetName( aNode->Name() ) ;
2181           myNode->SetAuthor( aNode->Author() ) ;
2182           myNode->SetComment( aNode->Comment() ) ;
2183           myNode->Coords( aNode->X() , aNode->Y() ) ;
2184           string * aNodetheName = new string( aNode->Name() ) ;
2185           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
2186           delete aNodetheName ;
2187           SUPERV::ListOfPorts myPorts = *(aNode->Ports()) ;
2188           int j ;
2189           for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
2190             if ( myPorts[ j ]->IsInput() ) {
2191               aPort = myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2192             }
2193             else {
2194               aPort = myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2195             }
2196           }
2197           if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
2198             SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
2199             for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
2200               if ( myStreamPorts[ j ]->IsInput() ) {
2201                 aPort = myNode->InStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
2202               }
2203               else {
2204                 aPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
2205               }
2206             }
2207           }
2208           RetVal = true ;
2209         }
2210         else {
2211           RetVal = false ;
2212           break ;
2213         }
2214       }
2215     }
2216 // GOTONodes
2217     if ( RetVal ) {
2218       for ( i = 0 ; i < (int ) aGraphNodes->GNodes.length() ; i++ ) {
2219         SUPERV::GNode_var aNode = (aGraphNodes->GNodes)[ i ] ;
2220         SUPERV::GNode_ptr myNode = GNode( aNode->PyFuncName() , *(aNode->PyFunction()) , aNode->Coupled()->Name() ) ;
2221         if ( !CORBA::is_nil( myNode ) ) {
2222           myNode->SetName( aNode->Name() ) ;
2223           myNode->SetAuthor( aNode->Author() ) ;
2224           myNode->SetComment( aNode->Comment() ) ;
2225           myNode->Coords( aNode->X() , aNode->Y() ) ;
2226           string * aNodetheName = new string( aNode->Name() ) ;
2227           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
2228           delete aNodetheName ;
2229           SUPERV::ListOfPorts myPorts = *(aNode->Ports()) ;
2230           int j ;
2231           for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
2232             if ( myPorts[ j ]->IsInput() ) {
2233               aPort = myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2234             }
2235             else {
2236               aPort = myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2237             }
2238           }
2239           if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
2240             SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
2241             for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
2242               if ( myStreamPorts[ j ]->IsInput() ) {
2243                 aPort = myNode->InStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
2244               }
2245               else {
2246                 aPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
2247               }
2248             }
2249           }
2250           RetVal = true ;
2251         }
2252         else {
2253           RetVal = false ;
2254           break ;
2255         }
2256       }
2257     }
2258 // LoopNodes
2259     if ( RetVal ) {
2260       for ( i = 0 ; i < (int ) aGraphNodes->LNodes.length() ; i++ ) {
2261         SUPERV::LNode_var aNode = (aGraphNodes->LNodes)[ i ] ;
2262         SUPERV::INode_ptr anEndOfLoop ;
2263         SUPERV::LNode_ptr myNode = LNode( aNode->PyInitName() ,
2264                                           *(aNode->PyInit()) ,
2265                                           aNode->PyMoreName() ,
2266                                           *(aNode->PyMore()) ,
2267                                           aNode->PyNextName() ,
2268                                           *(aNode->PyNext()) ,
2269                                           anEndOfLoop ) ;
2270         if ( !CORBA::is_nil( myNode ) ) {
2271           myNode->SetName( aNode->Name() ) ;
2272           myNode->SetAuthor( aNode->Author() ) ;
2273           myNode->SetComment( aNode->Comment() ) ;
2274           myNode->Coords( aNode->X() , aNode->Y() ) ;
2275           string * aNodetheName = new string( aNode->Name() ) ;
2276           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
2277           delete aNodetheName ;
2278           SUPERV::ListOfPorts myPorts = *(aNode->Ports()) ;
2279           int j ;
2280           for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
2281             if ( myPorts[ j ]->IsInput() ) {
2282               aPort = myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2283             }
2284             else {
2285               aPort = myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2286             }
2287           }
2288           if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
2289             SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
2290             for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
2291               if ( myStreamPorts[ j ]->IsInput() ) {
2292                 aPort = myNode->InStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
2293               }
2294               else {
2295                 aPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
2296               }
2297             }
2298           }
2299           SUPERV::INode_ptr myEndOfLoop = aNode->Coupled() ;
2300           anEndOfLoop->SetName( myEndOfLoop->Name() ) ;
2301           anEndOfLoop->SetAuthor( myEndOfLoop->Author() ) ;
2302           anEndOfLoop->SetComment( myEndOfLoop->Comment() ) ;
2303           anEndOfLoop->Coords( myEndOfLoop->X() , myEndOfLoop->Y() ) ;
2304           anEndOfLoop->SetPyFunction( myEndOfLoop->PyFuncName() , *(myEndOfLoop->PyFunction()) ) ;
2305           aNodetheName = new string( myEndOfLoop->Name() ) ;
2306           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( anEndOfLoop->Name() ) ;
2307           if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
2308             SUPERV::ListOfStreamPorts myStreamLoopPorts = *(myEndOfLoop->StreamPorts()) ;
2309             for ( j = 0 ; j < (int ) myStreamLoopPorts.length() ; j++ ) {
2310               if ( myStreamLoopPorts[ j ]->IsInput() ) {
2311                 aPort = myNode->InStreamPort( myStreamLoopPorts[ j ]->Name() , StringToDataStreamType( myStreamLoopPorts[ j ]->Type() ) , myStreamLoopPorts[ j ]->Dependency() ) ;
2312               }
2313               else {
2314                 aPort = myNode->OutStreamPort( myStreamLoopPorts[ j ]->Name() , StringToDataStreamType( myStreamLoopPorts[ j ]->Type() ) , myStreamLoopPorts[ j ]->Dependency() ) ;
2315               }
2316             }
2317           }
2318           delete aNodetheName ;
2319           RetVal = true ;
2320         }
2321         else {
2322           RetVal = false ;
2323           break ;
2324         }
2325       }
2326     }
2327 // SwitchNodes
2328     if ( RetVal ) {
2329       for ( i = 0 ; i < (int ) aGraphNodes->SNodes.length() ; i++ ) {
2330         SUPERV::SNode_var aNode = (aGraphNodes->SNodes)[ i ] ;
2331         SUPERV::INode_ptr anEndOfSwitch ;
2332         SUPERV::SNode_ptr myNode = SNode( aNode->PyFuncName() , *(aNode->PyFunction()) , anEndOfSwitch ) ;
2333         if ( !CORBA::is_nil( myNode ) ) {
2334           myNode->SetName( aNode->Name() ) ;
2335           myNode->SetAuthor( aNode->Author() ) ;
2336           myNode->SetComment( aNode->Comment() ) ;
2337           myNode->Coords( aNode->X() , aNode->Y() ) ;
2338           string * aNodetheName = new string( aNode->Name() ) ;
2339           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
2340           delete aNodetheName ;
2341           SUPERV::ListOfPorts myPorts = *(aNode->Ports()) ;
2342           int j ;
2343           for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
2344             if ( myPorts[ j ]->IsInput() ) {
2345               aPort = myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2346             }
2347             else {
2348               aPort = myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2349             }
2350           }
2351           if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
2352             SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
2353             for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
2354               if ( myStreamPorts[ j ]->IsInput() ) {
2355                 aPort = myNode->InStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
2356               }
2357               else {
2358                 aPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
2359               }
2360             }
2361           }
2362           SUPERV::INode_ptr myEndOfSwitch = aNode->Coupled() ;
2363           anEndOfSwitch->SetName( myEndOfSwitch->Name() ) ;
2364           anEndOfSwitch->SetAuthor( myEndOfSwitch->Author() ) ;
2365           anEndOfSwitch->SetComment( myEndOfSwitch->Comment() ) ;
2366           anEndOfSwitch->Coords( myEndOfSwitch->X() , myEndOfSwitch->Y() ) ;
2367           anEndOfSwitch->SetPyFunction( myEndOfSwitch->PyFuncName() , *(myEndOfSwitch->PyFunction()) ) ;
2368           aNodetheName = new string( myEndOfSwitch->Name() ) ;
2369           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( anEndOfSwitch->Name() ) ;
2370           delete aNodetheName ;
2371           myPorts = *(myEndOfSwitch->Ports()) ;
2372           for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
2373             if ( myPorts[ j ]->IsInput() ) {
2374               aPort = myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2375             }
2376             else {
2377               aPort = myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2378             }
2379           }
2380           if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
2381             SUPERV::ListOfStreamPorts myStreamSwitchPorts = *(myEndOfSwitch->StreamPorts()) ;
2382             for ( j = 0 ; j < (int ) myStreamSwitchPorts.length() ; j++ ) {
2383               if ( myStreamSwitchPorts[ j ]->IsInput() ) {
2384                 aPort = myNode->InStreamPort( myStreamSwitchPorts[ j ]->Name() , StringToDataStreamType( myStreamSwitchPorts[ j ]->Type() ) , myStreamSwitchPorts[ j ]->Dependency() ) ;
2385               }
2386               else {
2387                 aPort = myNode->OutStreamPort( myStreamSwitchPorts[ j ]->Name() , StringToDataStreamType( myStreamSwitchPorts[ j ]->Type() ) , myStreamSwitchPorts[ j ]->Dependency() ) ;
2388               }
2389             }
2390           }
2391           RetVal = true ;
2392         }
2393         else {
2394           RetVal = false ;
2395           break ;
2396         }
2397       }
2398     }
2399     if ( RetVal ) {
2400       SUPERV::ListOfLinks * aGraphLinks = aGraph->GLinks() ;
2401       SUPERV::ListOfPorts * aGraphPorts = aGraph->Ports() ;
2402 //      cout << "Graph_Impl::Merge " << aGraphLinks->length() << " links " << aGraphPorts->length() << " GraphPorts"
2403 //           << endl ;
2404       for ( i = 0 ; i < (int ) aGraphLinks->length() ; i++ ) {
2405         SUPERV::Link_var aLink = (*aGraphLinks)[ i ] ;
2406         SUPERV::Port_var OutPort = aLink->OutPort() ;
2407         SUPERV::Port_var InPort = aLink->InPort() ;
2408         string * aLinkFromNodeName = new string( OutPort->Node()->Name() ) ;
2409         string * aLinkToNodeName = new string( InPort->Node()->Name() ) ;
2410         RetVal = DataFlowEditor()->AddLink( DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] )->Name() ,
2411                                            OutPort->Name() ,
2412                                            DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] )->Name() ,
2413                                            InPort->Name() ) ;
2414         if ( RetVal ) {
2415           int j ;
2416           for ( j = 1 ; j <= aLink->CoordsSize() ; j++ ) {
2417             long X , Y ;
2418             RetVal = aLink->Coords( j , X , Y ) ;
2419             if ( !RetVal )
2420               break ;
2421             RetVal = DataFlowEditor()->AddLinkCoord( DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] )->Name() ,
2422                                                      OutPort->Name() ,
2423                                                      DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] )->Name() ,
2424                                                      InPort->Name() ,
2425                                                      j , X , Y ) ;
2426             if ( !RetVal ) {
2427               break ;
2428             }
2429           }
2430         }
2431         delete aLinkFromNodeName ;
2432         delete aLinkToNodeName ;
2433         if ( !RetVal ) {
2434           break ;
2435         }
2436       }
2437       if ( RetVal ) {
2438         for ( i = 0 ; i < (int ) aGraphPorts->length() ; i++ ) {
2439           SUPERV::Port_var aPort = (*aGraphPorts)[ i ] ;
2440           if ( !aPort->IsGate() ) {
2441             MESSAGE( "Graph_Impl::Merge " << i << ". " << aPort->Node()->Name() << " " << aPort->Name() ) ;
2442             char * aPortName = aPort->Name() ;
2443             char * aNodeName = new char[ strlen( aPortName ) + 1 ] ;
2444             strcpy( aNodeName , aPortName ) ;
2445 //            char * thePortName = strchr( aNodeName , '\\' ) ;
2446             char * thePortName = aNodeName ;
2447             while ( ( thePortName = strchr( thePortName , '_' ) ) ) {
2448               if ( thePortName[1] == '_' ) {
2449                 thePortName[ 0 ] = '\0' ;
2450                 break ;
2451               }
2452               else {
2453                 thePortName = &thePortName[2] ;
2454               }
2455             }
2456             bool hasinput = aGraph->Node( aNodeName )->Port( thePortName + 2 )->HasInput() ;
2457 //            cout << "Graph_Impl::Merge " << " aNodeName " << aNodeName << " aPort " << thePortName + 1
2458 //                 << " HasInput " << hasinput << endl ;
2459             if ( hasinput ) {
2460               RetVal = DataFlowEditor()->AddInputData( DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aNodeName ] )->Name() ,
2461                                                        thePortName + 2 ,
2462                                                        *(aPort->ToAny()) ) ;
2463             }
2464             delete [] aNodeName ;
2465             if ( !RetVal ) {
2466               break ;
2467             }
2468           }
2469         }
2470       }
2471     }
2472   }
2473   MESSAGE( "Graph_Impl::Merge returns " << RetVal ) ;
2474   endService( "Graph_Impl::Merge" );
2475   return RetVal ;
2476 }
2477
2478 SUPERV::StreamGraph_ptr Graph_Impl::ToStreamGraph() {
2479   SUPERV::StreamGraph_var iobject = SUPERV::StreamGraph::_nil() ;
2480   beginService( "Graph_Impl::ToStreamGraph" );
2481   if ( IsStreamGraph() && !IsMacro() ) {
2482 //  StreamGraph_Impl * myStreamGraph = new StreamGraph_Impl( _Orb , _Poa , _ContId ,
2483 //                                          instanceName() , interfaceName() ) ;
2484 //  PortableServer::ObjectId * id = myStreamGraph->getId() ;
2485 //  CORBA::Object_var obj = _poa->id_to_reference(*id);
2486     iobject = SUPERV::StreamGraph::_narrow( ObjRef() ) ;
2487     if ( CORBA::is_nil( iobject ) ) {
2488       MESSAGE( "ToStreamGraph of " << Name() << " (IsStreamGraph) --> nil reference" ) ;
2489     }
2490   }
2491   else {
2492     MESSAGE( "ToStreamGraph of " << Name() << " (IsNOTStreamGraph) --> nil reference" ) ;
2493   }
2494   endService( "Graph_Impl::ToStreamGraph" );
2495   return SUPERV::StreamGraph::_duplicate( iobject ) ;
2496 }
2497
2498
2499