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