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