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