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