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