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