Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[modules/superv.git] / src / Supervision / Graph_Impl.cxx
1 //  SUPERV Supervision : contains the implementation of interfaces of SuperVision described in SUPERV.idl
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : Graph_Impl.cxx
25 //  Author : Jean Rahuel
26 //  Module : SUPERV
27 //  $Header: 
28
29 using namespace std;
30 #include <stdio.h>
31 #include <fstream>
32 //#include <sstream>
33 #include <string>
34
35 //#include "utilities.h"
36
37 #include "Graph_Impl.hxx"
38
39 #include "DataFlowEditor_DataFlow.hxx"
40
41 extern GraphExecutor::FiniteStateMachine * theAutomaton ;
42
43 Graph_Impl::Graph_Impl( CORBA::ORB_ptr orb ,
44                         PortableServer::POA_ptr poa ,
45                         PortableServer::ObjectId * contId , 
46                         const char *instanceName ,
47                         const char *interfaceName ,
48                         const char *aDataFlowName ,
49                         const SUPERV::KindOfNode aKindOfNode ) :
50   INode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowName ) {
51 //  MESSAGE("Graph_Impl::Graph_Impl activate object instanceName("
52 //          << instanceName << ") interfaceName(" << interfaceName << ") --> "
53 //          << hex << (void *) this << dec )
54   beginService( "Graph_Impl::Graph_Impl" );
55   _Orb = CORBA::ORB::_duplicate(orb);
56   _Poa = poa ;
57   _ContId = contId ;
58   if ( aKindOfNode == SUPERV::DataFlowGraph ) {
59     _thisObj = this ;
60     _id = _poa->activate_object(_thisObj);
61   }
62
63   string dbgfile = "/tmp/" ;
64   dbgfile += instanceName ;
65   dbgfile += "_" ;
66   int lenname = strlen( aDataFlowName ) ;
67   char * theDataFlowName = new char [ lenname+1 ] ;
68   strcpy( theDataFlowName , aDataFlowName ) ;
69   if ( aDataFlowName ) {
70     if ( lenname > 4 && !strcmp( &aDataFlowName[ lenname - 4 ] , ".xml" ) ) {
71       strncpy( theDataFlowName , &aDataFlowName[ 0 ] , lenname-4 ) ;
72       theDataFlowName[ lenname-4 ] = '\0' ;
73       int i ;
74       for ( i = lenname - 5 ; i >= 0 ; i-- ) {
75         if ( aDataFlowName[ i ] == '/' ) {
76           strncpy( theDataFlowName , &aDataFlowName[ i + 1 ] , lenname-5-i ) ;
77           theDataFlowName[ lenname-5-i ] = '\0' ;
78           break ;
79         }
80       }
81     }
82     else {
83       strcpy( theDataFlowName , &aDataFlowName[ 0 ] ) ;
84     }
85     dbgfile += theDataFlowName ;
86   }
87   dbgfile += ".log" ;
88   _DebugFileName = new char[ strlen( dbgfile.c_str() )+1 ] ;
89   strcpy( _DebugFileName , dbgfile.c_str() ) ;
90
91   _NamingService = new SALOME_NamingService( orb ) ;
92   GraphEditor::DataFlow *  aDataFlowEditor ;
93   aDataFlowEditor = new GraphEditor::DataFlow( _Orb , _NamingService ,
94                                                theDataFlowName , _DebugFileName ,
95                                                aKindOfNode ) ;
96   DataFlowEditor( aDataFlowEditor ) ;
97   DataFlowEditor()->Graph()->SetObjImpl( this ) ;
98   pthread_mutex_init( &_MutexExecutorWait , NULL ) ;
99   _DataFlowExecutor = NULL ;
100   delete [] theDataFlowName ;
101   endService( "Graph_Impl::Graph_Impl" );
102 }
103
104 Graph_Impl::Graph_Impl() {
105 }
106
107 Graph_Impl::~Graph_Impl() {
108   beginService( "Graph_Impl::~Graph_Impl" );
109   endService( "Graph_Impl::~Graph_Impl" );
110 }
111
112 void Graph_Impl::destroy() {
113   beginService( "Graph_Impl::destroy" );
114   _poa->deactivate_object(*_id) ;
115   CORBA::release(_poa) ;
116   delete(_id) ;
117   _thisObj->_remove_ref();
118 //  endService( "Graph_Impl::destroy" );
119 }
120
121 char* Graph_Impl::getIOR() {
122   if (CORBA::is_nil(myServant)) {
123     PortableServer::ObjectId* id = getId();
124     CORBA::Object_var obj;
125     obj = _poa->id_to_reference(*id);
126     myServant = SUPERV::Graph::_narrow(obj);
127   }
128   return(CORBA::string_dup(_Orb->object_to_string(myServant)));
129 }
130
131 SUPERV::Graph_ptr Graph_Impl::Copy() {
132   beginService( "Graph_Impl::Copy" );
133   Graph_Impl * myGraph ;
134   myGraph = new Graph_Impl( _Orb , _Poa, _ContId,
135                             instanceName() , interfaceName() ,
136                             DataFlowEditor()->Graph()->Name() , SUPERV::DataFlowGraph ) ;
137   PortableServer::ObjectId * id = myGraph->getId() ;
138   CORBA::Object_var obj = _poa->id_to_reference(*id);
139   SUPERV::Graph_var iobject ;
140   iobject = SUPERV::Graph::_narrow(obj) ;
141   GraphBase::SGraph * aSGraph = GetGraph() ;
142   myGraph->LoadGraph( aSGraph ) ;
143   endService( "Graph_Impl::Copy" );
144   return SUPERV::Graph::_duplicate(iobject) ;
145 }
146
147 void Graph_Impl::ReadOnly() {
148   DataFlowEditor()->ReadOnly() ;
149 }
150
151 SUPERV::INode_ptr Graph_Impl::Node() {
152 //  beginService( "Graph_Impl::Node" );
153   PortableServer::ObjectId * id = getId() ;
154   CORBA::Object_var obj = _poa->id_to_reference(*id);
155   SUPERV::Graph_var iobject ;
156   iobject = SUPERV::Graph::_narrow(obj) ;
157 //  endService( "Graph_Impl::Node" );
158   return SUPERV::Graph::_duplicate(iobject) ;
159 }
160
161 GraphBase::SGraph * Graph_Impl::GetGraph() {
162   return DataFlowEditor()->GetDataFlow() ;
163 }
164
165 #if 0
166 char * Graph_Impl::DataFlowInfo() {
167   beginService( "Graph_Impl::DataFlowInfo" );
168   char * RetVal = DataFlowEditor()->DataFlowInfo() ;
169   endService( "Graph_Impl::DataFlowInfo" );
170   return CORBA::string_dup( RetVal ) ;
171 }
172
173 char * Graph_Impl::DataNodeInfo() {
174   beginService( "Graph_Impl::DataNodeInfo" );
175   char * RetVal = DataFlowEditor()->DataNodeInfo() ;
176   endService( "Graph_Impl::DataNodeInfo" );
177   return CORBA::string_dup( RetVal ) ;
178 }
179
180 char * Graph_Impl::NodeInfo( const char * aNodeName ) {
181   beginService( "Graph_Impl::NodeInfo" );
182   char * RetVal = DataFlowEditor()->NodeInfo( aNodeName ) ;
183   endService( "Graph_Impl::NodeInfo" );
184   return CORBA::string_dup( RetVal ) ;
185 }
186 #endif
187
188 bool Graph_Impl::LoadGraph(const GraphBase::SGraph * aDataFlow ) {
189 //  beginService( "Graph_Impl::LoadGraph" );
190   bool RetVal = false ;
191   if ( DataFlowEditor()->IsEditing() ) {
192     RetVal = DataFlowEditor()->LoadDataFlow( aDataFlow ) ;
193   }
194 //  endService( "Graph_Impl::LoadGraph" );
195   return RetVal ;
196 }
197
198 bool Graph_Impl::Import(const char * aXmlFile ) {
199 //  beginService( "Graph_Impl::Import" );
200   bool RetVal = false ;
201   if ( DataFlowEditor()->IsEditing() ) {
202     RetVal = DataFlowEditor()->LoadXml( aXmlFile ) ;
203   }
204 //  endService( "Graph_Impl::Import" );
205   return RetVal ;
206 }
207
208 bool Graph_Impl::Export(const char * anXmlFile ) {
209   beginService( "Graph_Impl::Export" );
210   char * aFile = new char [ strlen( anXmlFile ) + 5 ] ;
211   strcpy( aFile , anXmlFile ) ;
212   int len = strlen( aFile ) ;
213   if ( !strcmp( &aFile[ len - 4 ] , ".xml" ) ) {
214   }
215   else if ( !strcmp( &aFile[ len - 3 ] , ".py" ) ) {
216     strcpy( &aFile[ len - 3 ] , ".xml" ) ;
217     len = strlen( aFile ) ;
218   }
219   else {
220     strcat( aFile , ".xml" ) ;
221     len = strlen( aFile ) ;
222   }
223   bool RetVal = DataFlowEditor()->SaveXml( aFile ) ;
224   if ( RetVal ) {
225     strcpy( &aFile[ len - 4 ] , ".py" ) ;
226     RetVal = DataFlowEditor()->SavePy( aFile ) ;
227   }
228   delete [] aFile ;
229   endService( "Graph_Impl::Export" );
230   return RetVal ;
231 }
232
233 #if 0
234 GraphBase::ListOfNodes * Graph_Impl::GetNodes() {
235 //  beginService( "Graph_Impl::GetNodes" );
236   GraphBase::ListOfNodes * RetVal = DataFlowEditor()->GetNodes() ;
237 //  endService( "Graph_Impl::GetNodes" );
238   return RetVal ;
239 }
240 GraphBase::ListOfLinks * Graph_Impl::GetLinks() {
241 //  beginService( "Graph_Impl::GetLinks" );
242   GraphBase::ListOfLinks * RetVal = DataFlowEditor()->GetLinks() ;
243 //  endService( "Graph_Impl::GetLinks" );
244   return RetVal ;
245 }
246 GraphBase::ListOfLinks * Graph_Impl::GetDatas() {
247 //  beginService( "Graph_Impl::GetDatas" );
248   GraphBase::ListOfLinks * RetVal = DataFlowEditor()->GetDatas() ;
249 //  endService( "Graph_Impl::GetDatas" );
250   return RetVal ;
251 }
252 #endif
253
254 SUPERV::CNode_ptr Graph_Impl::CNode( const SALOME_ModuleCatalog::Service &NodeService ) {
255   beginService( "Graph_Impl::CNode" );
256   SUPERV::CNode_var iobject = SUPERV::CNode::_nil() ;
257   if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() ) {
258     CNode_Impl * myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
259                                           instanceName() , interfaceName() ,
260                                           DataFlowEditor() ,
261                                           NodeService , NULLSTRING ,
262                                           SUPERV::ComputingNode , NULLSTRING ) ;
263     if ( myNode->DataFlowNode() ) {
264       PortableServer::ObjectId * id = myNode->getId() ;
265       CORBA::Object_var obj = _poa->id_to_reference(*id);
266       iobject = SUPERV::CNode::_narrow(obj) ;
267       myNode->SetObjRef( SUPERV::CNode::_duplicate( iobject ) ) ;
268     }
269   }
270   endService( "Graph_Impl::CNode" );
271   return SUPERV::CNode::_duplicate( iobject ) ;
272 }
273
274 SUPERV::FNode_ptr Graph_Impl::FNode( const char * NodeComponentName ,
275                                      const char * NodeInterfaceName ,
276                                      const SALOME_ModuleCatalog::Service &NodeService ) {
277   beginService( "Graph_Impl::FNode" );
278   SUPERV::FNode_var iobject = SUPERV::FNode::_nil() ;
279   if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() ) {
280     FNode_Impl * myNode = new FNode_Impl( _Orb , _Poa , _ContId ,
281                                           instanceName() , interfaceName() ,
282                                           DataFlowEditor() ,
283                                           NodeService ,
284                                           NodeComponentName ,
285                                           NodeInterfaceName ) ;
286     if ( myNode->DataFlowNode() ) {
287       PortableServer::ObjectId * id = myNode->getId() ;
288       CORBA::Object_var obj = _poa->id_to_reference(*id);
289       iobject = SUPERV::FNode::_narrow(obj) ;
290       myNode->SetObjRef( SUPERV::FNode::_duplicate( iobject ) ) ;
291     }
292   }
293   endService( "Graph_Impl::FNode" );
294   return SUPERV::FNode::_duplicate( iobject ) ;
295 }
296
297 SUPERV::INode_ptr Graph_Impl::INode( const char * FuncName ,
298                                      const SUPERV::ListOfStrings & PythonFuntion ) {
299   beginService( "Graph_Impl::INode" );
300   SUPERV::INode_var iobject = SUPERV::INode::_nil() ;
301   if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() ) {
302     INode_Impl * myNode = new INode_Impl( _Orb , _Poa , _ContId ,
303                                           instanceName() , interfaceName() ,
304                                           DataFlowEditor() ,
305                                           FuncName , PythonFuntion ,
306                                           SUPERV::InLineNode ) ;
307     if ( myNode->DataFlowNode() ) {
308       PortableServer::ObjectId * id = myNode->getId() ;
309       CORBA::Object_var obj = _poa->id_to_reference(*id);
310       iobject = SUPERV::INode::_narrow(obj) ;
311       myNode->SetObjRef( SUPERV::INode::_duplicate( iobject ) ) ;
312     }
313   }
314   endService( "Graph_Impl::INode" );
315   return SUPERV::INode::_duplicate( iobject ) ;
316 }
317
318
319 SUPERV::GNode_ptr Graph_Impl::GNode( const char * FuncName ,
320                                      const SUPERV::ListOfStrings & PythonFuntion ,
321                                      const char * anInLineNode ) {
322   beginService( "Graph_Impl::GNode" );
323   SUPERV::GNode_var iobject = SUPERV::GNode::_nil() ;
324   if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() ) {
325     GNode_Impl * myNode = new GNode_Impl( _Orb , _Poa , _ContId ,
326                                           instanceName() , interfaceName() ,
327                                           DataFlowEditor() ,
328                                           FuncName , PythonFuntion ,
329                                           SUPERV::GOTONode ) ;
330     if ( myNode->DataFlowNode() ) {
331       PortableServer::ObjectId * id = myNode->getId() ;
332       CORBA::Object_var obj = _poa->id_to_reference(*id);
333       iobject = SUPERV::GNode::_narrow(obj) ;
334       myNode->SetObjRef( SUPERV::GNode::_duplicate( iobject ) ) ;
335       if ( strlen( anInLineNode ) ) {
336         GraphBase::InLineNode * CoupledINode = (GraphBase::InLineNode * ) DataFlowEditor()->Graph()->GetGraphNode( anInLineNode ) ;
337         if ( anInLineNode ) {
338           myNode->SetCoupled( anInLineNode ) ;
339           Link( myNode->Port( "OutGate" ) , CoupledINode->ObjRef()->Port( "InGate" ) ) ;
340         }
341       }
342     }
343   }
344   endService( "Graph_Impl::GNode" );
345   return SUPERV::GNode::_duplicate( iobject ) ;
346 }
347
348 SUPERV::LNode_ptr Graph_Impl::LNode( const char * InitName ,
349                                      const SUPERV::ListOfStrings & InitFunction ,
350                                      const char * MoreName ,
351                                      const SUPERV::ListOfStrings & MoreFunction ,
352                                      const char * NextName ,
353                                      const SUPERV::ListOfStrings & NextFunction ,
354                                      SUPERV::INode_out anEndOfLoop ) {
355   beginService( "Graph_Impl::LNode" );
356   SUPERV::LNode_var iobject = SUPERV::LNode::_nil() ;
357   SUPERV::ELNode_var iendobject = SUPERV::ELNode::_nil() ;
358   if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() ) {
359     GraphBase::ListOfFuncName FuncNameList ;
360     FuncNameList.resize(3) ;
361     FuncNameList[0] = InitName ;
362     FuncNameList[1] = MoreName ;
363     FuncNameList[2] = NextName ;
364     GraphBase::ListOfPythonFunctions PythonFunctionList ;
365     PythonFunctionList.resize(3) ;
366     PythonFunctionList[0] = &InitFunction ;
367     PythonFunctionList[1] = &MoreFunction ;
368     PythonFunctionList[2] = &NextFunction ;
369     LNode_Impl * myNode = new LNode_Impl( _Orb , _Poa , _ContId ,
370                                           instanceName() , interfaceName() ,
371                                           DataFlowEditor() ,
372                                           FuncNameList , PythonFunctionList ,
373 //                                          InitName , InitFunction ,
374 //                                          MoreName , MoreFunction ,
375 //                                          NextName , NextFunction ,
376                                           SUPERV::LoopNode ) ;
377     if ( myNode->DataFlowNode() ) {
378       PortableServer::ObjectId * id = myNode->getId() ;
379       CORBA::Object_var obj = _poa->id_to_reference(*id);
380       iobject = SUPERV::LNode::_narrow(obj) ;
381       myNode->SetObjRef( SUPERV::LNode::_duplicate( iobject ) ) ;
382
383       SALOME_ModuleCatalog::Service aVoidService = SALOME_ModuleCatalog::Service() ;
384       char * anEndName ;
385       if ( strlen( InitName ) ) {
386         anEndName = new char( 3 + strlen( InitName ) + 1 ) ;
387         strcpy( anEndName , "End" ) ;
388         strcat( anEndName , InitName ) ;
389       }
390       else {
391         anEndName = new char( 3 + strlen( "Loop" ) + 1 ) ;
392         strcpy( anEndName , "EndLoop" ) ;
393       }
394       ELNode_Impl * myEndNode = new ELNode_Impl( _Orb , _Poa , _ContId ,
395                                                  instanceName() , interfaceName() ,
396                                                  DataFlowEditor() ,
397                                                  anEndName ,
398                                                  SUPERV::EndLoopNode ) ;
399       PortableServer::ObjectId * endid = myEndNode->getId() ;
400       CORBA::Object_var endobj = _poa->id_to_reference(*endid);
401       iendobject = SUPERV::ELNode::_narrow(endobj) ;
402       myEndNode->SetObjRef( SUPERV::ELNode::_duplicate( iendobject ) ) ;
403       myNode->SetCoupled( myEndNode->BaseNode()->Name() ) ;
404       myEndNode->SetCoupled( myNode->BaseNode()->Name() ) ;
405       Link( myNode->Port( "DoLoop" ) , myEndNode->Port( "DoLoop" ) ) ;
406       Link( myEndNode->Port( "DoLoop" ) , myNode->Port( "InitLoop" ) ) ;
407     }
408   }
409   anEndOfLoop = SUPERV::ELNode::_duplicate( iendobject ) ;
410   endService( "Graph_Impl::LNode" );
411   return SUPERV::LNode::_duplicate( iobject ) ;
412 }
413
414 SUPERV::SNode_ptr Graph_Impl::SNode( const char * FuncName ,
415                                      const SUPERV::ListOfStrings & PythonFunction ,
416                                      SUPERV::INode_out anEndOfSwitch ) {
417   beginService( "Graph_Impl::SNode" );
418   SUPERV::SNode_var iobject = SUPERV::SNode::_nil() ;
419   SUPERV::ESNode_var iendobject = SUPERV::ESNode::_nil() ;
420   if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() ) {
421     SNode_Impl * myNode = new SNode_Impl( _Orb , _Poa , _ContId ,
422                                           instanceName() , interfaceName() ,
423                                           DataFlowEditor() ,
424                                           FuncName , PythonFunction ,
425                                           SUPERV::SwitchNode ) ;
426     if ( myNode->DataFlowNode() ) {
427       PortableServer::ObjectId * id = myNode->getId() ;
428       CORBA::Object_var obj = _poa->id_to_reference(*id);
429       iobject = SUPERV::SNode::_narrow(obj) ;
430       myNode->SetObjRef( SUPERV::SNode::_duplicate( iobject ) ) ;
431
432       string anEndName = "End" ;
433       if ( strlen( FuncName ) ) {
434         anEndName += FuncName ;
435       }
436       else {
437         anEndName += "Switch" ;
438       }
439 //      cout << "Graph_Impl::SNode anEndName " << (void *) FuncName << " " << FuncName
440 //           << " " << strlen(FuncName) << " " << (void *) anEndName.c_str() << " "
441 //           << anEndName.c_str() << endl ;
442       ESNode_Impl * myEndNode = new ESNode_Impl( _Orb , _Poa , _ContId ,
443                                                instanceName() , interfaceName() ,
444                                                DataFlowEditor() ,
445                                                anEndName.c_str() ,
446                                                SUPERV::EndSwitchNode ) ;
447 //      cout << "Graph_Impl::SNode returned anEndName " << (void *) FuncName << " "
448 //           << FuncName << " " << strlen(FuncName) << " " << (void *) anEndName.c_str()
449 //           << " " << anEndName.c_str() << endl ;
450       PortableServer::ObjectId * endid = myEndNode->getId() ;
451       CORBA::Object_var endobj = _poa->id_to_reference(*endid);
452       iendobject = SUPERV::ESNode::_narrow(endobj) ;
453       myEndNode->SetObjRef( SUPERV::ESNode::_duplicate( iendobject ) ) ;
454       myNode->SetCoupled( myEndNode->BaseNode()->Name() ) ;
455       myEndNode->SetCoupled( myNode->BaseNode()->Name() ) ;
456       if ( !Link( myNode->Port( "Default" ) , myEndNode->Port( "Default" ) ) ) {
457         iobject = SUPERV::SNode::_nil() ;
458         iendobject = SUPERV::ESNode::_nil() ;
459       }
460     }
461   }
462   anEndOfSwitch = SUPERV::ESNode::_duplicate( iendobject ) ;
463   endService( "Graph_Impl::SNode" );
464   return SUPERV::SNode::_duplicate( iobject ) ;
465 }
466
467
468 SUPERV::CNode_ptr Graph_Impl::Node(char const * aNodeName ) {
469 //  beginService( "Graph_Impl::Node" );
470   SUPERV::CNode_var iobject = SUPERV::CNode::_nil() ;
471   /* JR : 13/06/03
472      if ( CORBA::is_nil( DataFlowEditor()->GetNode( aNodeName )->ObjRef() ) ) {
473      CNode_Impl * myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
474      instanceName() , interfaceName() ,
475      DataFlowEditor() ,
476      DataFlowEditor()->GetNode( aNodeName ) ) ;
477      PortableServer::ObjectId * id = myNode->getId() ;
478      CORBA::Object_var obj = _poa->id_to_reference(*id);
479      iobject = SUPERV::CNode::_narrow(obj) ;
480      myNode->SetObjRef( SUPERV::CNode::_duplicate( iobject ) ) ;
481      }
482      else {
483      iobject = DataFlowEditor()->GetNode( aNodeName )->ObjRef() ;
484   */
485   GraphEditor::InNode * anInNode = DataFlowEditor()->GetNode( aNodeName ) ;
486   if ( anInNode ) {
487     if ( CORBA::is_nil( anInNode->ObjRef() ) ) {
488       SetNodeObjRef( anInNode ) ;
489     }
490     iobject = anInNode->ObjRef() ;
491   }
492 //  endService( "Graph_Impl::Node" );
493   return SUPERV::CNode::_duplicate( iobject ) ;
494 }
495
496 SUPERV::Link_ptr Graph_Impl::Link( SUPERV::Port_ptr OutPort ,
497                                    SUPERV::Port_ptr InPort ) {
498   beginService( "Graph_Impl::Link" );
499   SUPERV::Link_var iobject = SUPERV::Link::_nil() ;
500   if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() &&
501        !OutPort->IsDataStream() && !InPort->IsDataStream() ) {
502     GraphBase::InPort * anInPort = DataFlowEditor()->GetNode( InPort->Node()->Name() )->ComputingNode()->GetChangeInPort( InPort->Name() ) ;
503     GraphBase::OutPort * anOutPort = DataFlowEditor()->GetNode( OutPort->Node()->Name() )->ComputingNode()->GetChangeOutPort( OutPort->Name() ) ;
504     if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
505       const char * DataFlowOutNodeName = OutPort->Node()->Name() ;
506       GraphEditor::InNode * DataFlowOutNode = DataFlowEditor()->GetNode( DataFlowOutNodeName ) ;
507       const char * DataFlowInNodeName = InPort->Node()->Name() ;
508       GraphEditor::InNode * DataFlowInNode = DataFlowEditor()->GetNode( DataFlowInNodeName ) ;
509       if ( DataFlowOutNode && DataFlowInNode ) {
510         bool Success ;
511         Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
512                                             instanceName() , interfaceName() ,
513                                             DataFlowEditor() ,
514                                             DataFlowInNode ,
515                                             InPort->Name() ,
516                                             DataFlowOutNode ,
517                                             OutPort->Name() ,
518                                             true , false , Success ) ;
519         if ( Success ) {
520           PortableServer::ObjectId * id = myLink->getId() ;
521           CORBA::Object_var obj = _poa->id_to_reference(*id);
522           iobject = SUPERV::Link::_narrow(obj) ;
523           anOutPort->AddInPortObjRef( anInPort , SUPERV::Link::_duplicate( iobject ) ) ;
524         }
525       }
526     }
527     else {
528       iobject = anOutPort->InPortObjRef( anInPort ) ;
529     }
530   }
531   endService( "Graph_Impl::Link" );
532   return SUPERV::Link::_duplicate( iobject ) ;
533 }
534
535 void Graph_Impl::SetNodeObjRef( GraphEditor::InNode * anInNode ) {
536   CORBA::Object_var obj ;
537   if ( anInNode->IsComputingNode() ) {
538     CNode_Impl * myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
539                                           instanceName() , interfaceName() ,
540                                           DataFlowEditor() ,
541                                           anInNode ) ;
542     PortableServer::ObjectId * id = myNode->getId() ;
543     obj = _poa->id_to_reference(*id);
544     SUPERV::CNode_var iobject = SUPERV::CNode::_narrow(obj) ;
545     myNode->SetObjRef( SUPERV::CNode::_duplicate( iobject ) ) ;
546   }
547   else if ( anInNode->IsFactoryNode() ) {
548     FNode_Impl * myNode = new FNode_Impl( _Orb , _Poa , _ContId ,
549                                           instanceName() , interfaceName() ,
550                                           DataFlowEditor() ,
551                                           anInNode ) ;
552     PortableServer::ObjectId * id = myNode->getId() ;
553     obj = _poa->id_to_reference(*id);
554     SUPERV::FNode_var iobject = SUPERV::FNode::_narrow(obj) ;
555     myNode->SetObjRef( SUPERV::FNode::_duplicate( iobject ) ) ;
556   }
557   else if ( anInNode->IsInLineNode() ) {
558     INode_Impl * myNode = new INode_Impl( _Orb , _Poa , _ContId ,
559                                           instanceName() , interfaceName() ,
560                                           DataFlowEditor() ,
561                                           anInNode ) ;
562     PortableServer::ObjectId * id = myNode->getId() ;
563     obj = _poa->id_to_reference(*id);
564     SUPERV::INode_var iobject = SUPERV::INode::_narrow(obj) ;
565     myNode->SetObjRef( SUPERV::INode::_duplicate( iobject ) ) ;
566   }
567   else if ( anInNode->IsGOTONode() ) {
568     GNode_Impl * myNode = new GNode_Impl( _Orb , _Poa , _ContId ,
569                                           instanceName() , interfaceName() ,
570                                           DataFlowEditor() ,
571                                           anInNode ) ;
572     PortableServer::ObjectId * id = myNode->getId() ;
573     obj = _poa->id_to_reference(*id);
574     SUPERV::GNode_var iobject = SUPERV::GNode::_narrow(obj) ;
575     myNode->SetObjRef( SUPERV::GNode::_duplicate( iobject ) ) ;
576   }
577   else if ( anInNode->IsLoopNode() ) {
578     LNode_Impl * myNode = new LNode_Impl( _Orb , _Poa , _ContId ,
579                                           instanceName() , interfaceName() ,
580                                           DataFlowEditor() ,
581                                           anInNode ) ;
582     PortableServer::ObjectId * id = myNode->getId() ;
583     obj = _poa->id_to_reference(*id);
584     SUPERV::LNode_var iobject = SUPERV::LNode::_narrow(obj) ;
585     myNode->SetObjRef( SUPERV::LNode::_duplicate( iobject ) ) ;
586   }
587   else if ( anInNode->IsEndLoopNode() ) {
588     ELNode_Impl * myNode = new ELNode_Impl( _Orb , _Poa , _ContId ,
589                                             instanceName() , interfaceName() ,
590                                             DataFlowEditor() ,
591                                             anInNode ) ;
592     PortableServer::ObjectId * id = myNode->getId() ;
593     obj = _poa->id_to_reference(*id);
594     SUPERV::ELNode_var iobject = SUPERV::ELNode::_narrow(obj) ;
595     myNode->SetObjRef( SUPERV::ELNode::_duplicate( iobject ) ) ;
596   }
597   else if ( anInNode->IsSwitchNode() ) {
598     SNode_Impl * myNode = new SNode_Impl( _Orb , _Poa , _ContId ,
599                                           instanceName() , interfaceName() ,
600                                           DataFlowEditor() ,
601                                           anInNode ) ;
602     PortableServer::ObjectId * id = myNode->getId() ;
603     obj = _poa->id_to_reference(*id);
604     SUPERV::SNode_var iobject = SUPERV::SNode::_narrow(obj) ;
605     myNode->SetObjRef( SUPERV::SNode::_duplicate( iobject ) ) ;
606   }
607   else if ( anInNode->IsEndSwitchNode() ) {
608     ESNode_Impl * myNode = new ESNode_Impl( _Orb , _Poa , _ContId ,
609                                             instanceName() , interfaceName() ,
610                                             DataFlowEditor() ,
611                                             anInNode ) ;
612     PortableServer::ObjectId * id = myNode->getId() ;
613     obj = _poa->id_to_reference(*id);
614     SUPERV::ESNode_var iobject = SUPERV::ESNode::_narrow(obj) ;
615     myNode->SetObjRef( SUPERV::ESNode::_duplicate( iobject ) ) ;
616   }
617 }
618
619 SUPERV::ListOfNodes_var  Graph_Impl::SetNode( SUPERV::ListOfNodes_var RetVal ,
620                                               GraphBase::ComputingNode * aNode ) {
621   int index = 0 ;
622   if ( _DataFlowExecutor ) {
623     MESSAGE("Graph_Impl::SetNode " << aNode->Name() << " " << aNode->Kind() << " "
624             << _DataFlowExecutor->StateName( _DataFlowExecutor->AutomatonState( aNode->Name() ) ) ) ;
625   }
626   else {
627     MESSAGE("Graph_Impl::SetNode " << aNode->Name() << " " << aNode->Kind() ) ;
628   }
629   if ( aNode->IsComputingNode() ) {
630     index = RetVal->CNodes.length() ;
631     RetVal->CNodes.length( index+1 );
632   }
633   else if ( aNode->IsFactoryNode() ) {
634     index = RetVal->FNodes.length() ;
635     RetVal->FNodes.length( index+1 );
636   }
637   else if ( aNode->IsInLineNode() ) {
638     index = RetVal->INodes.length() ;
639     RetVal->INodes.length( index+1 );
640   }
641   else if ( aNode->IsGOTONode() ) {
642     index = RetVal->GNodes.length() ;
643     RetVal->GNodes.length( index+1 );
644   }
645   else if ( aNode->IsLoopNode() ) {
646     index = RetVal->LNodes.length() ;
647     RetVal->LNodes.length( index+1 );
648   }
649   else if ( aNode->IsEndLoopNode() ) {
650     index = RetVal->ELNodes.length() ;
651     RetVal->ELNodes.length( index+1 );
652   }
653   else if ( aNode->IsSwitchNode() ) {
654     index = RetVal->SNodes.length() ;
655     RetVal->SNodes.length( index+1 );
656   }
657   else if ( aNode->IsEndSwitchNode() ) {
658     index = RetVal->ESNodes.length() ;
659     RetVal->ESNodes.length( index+1 );
660   }
661   if ( CORBA::is_nil( aNode->ObjRef() ) ) {
662     SetNodeObjRef( (GraphEditor::InNode * ) aNode->GetInNode() ) ;
663   }
664   SUPERV::CNode_var aNodeObjRef = aNode->ObjRef() ;
665   if ( aNode->IsComputingNode() ) {
666     RetVal->CNodes[index] = SUPERV::CNode::_duplicate( aNodeObjRef ) ;
667   }
668   else if ( aNode->IsFactoryNode() ) {
669     RetVal->FNodes[index] = SUPERV::FNode::_duplicate( SUPERV::FNode::_narrow( aNodeObjRef ) ) ;
670   }
671   else if ( aNode->IsInLineNode() ) {
672     RetVal->INodes[index] = SUPERV::INode::_duplicate( SUPERV::INode::_narrow( aNodeObjRef ) ) ;
673   }
674   else if ( aNode->IsGOTONode() ) {
675     RetVal->GNodes[index] = SUPERV::GNode::_duplicate( SUPERV::GNode::_narrow( aNodeObjRef ) ) ;
676   }
677   else if ( aNode->IsLoopNode() ) {
678     RetVal->LNodes[index] = SUPERV::LNode::_duplicate( SUPERV::LNode::_narrow( aNodeObjRef ) ) ;
679   }
680   else if ( aNode->IsEndLoopNode() ) {
681     RetVal->ELNodes[index] = SUPERV::ELNode::_duplicate( SUPERV::ELNode::_narrow( aNodeObjRef ) ) ;
682   }
683   else if ( aNode->IsSwitchNode() ) {
684     RetVal->SNodes[index] = SUPERV::SNode::_duplicate( SUPERV::SNode::_narrow( aNodeObjRef ) ) ;
685   }
686    else if ( aNode->IsEndSwitchNode() ) {
687     RetVal->ESNodes[index] = SUPERV::ESNode::_duplicate( SUPERV::ESNode::_narrow( aNodeObjRef ) ) ;
688   }
689  return ( RetVal._retn() ) ;
690 }
691
692 SUPERV::ListOfNodes * Graph_Impl::Nodes() {
693   SUPERV::ListOfNodes_var RetVal = new SUPERV::ListOfNodes;
694   beginService( "Graph_Impl::Nodes" );
695   RetVal->CNodes.length(0) ;
696   RetVal->FNodes.length(0) ;
697   RetVal->INodes.length(0) ;
698   RetVal->LNodes.length(0) ;
699   RetVal->SNodes.length(0) ;
700   RetVal->GNodes.length(0) ;
701   int i ;
702   for ( i = 0 ; i < DataFlowEditor()->Graph()->GraphNodesSize() ; i++ ) {
703     GraphBase::ComputingNode * aNode = DataFlowEditor()->Graph()->GraphNodes( i ) ;
704     RetVal = SetNode( RetVal , aNode ) ;
705   }
706 #if 0
707   char * aStateG = "" ;
708   if ( _DataFlowExecutor ) {
709     aStateG = (char *) _DataFlowExecutor->StateName( _DataFlowExecutor->AutomatonState() ) ;
710   }
711   MESSAGE("Graph_Impl::Nodes GraphState " << aStateG
712           << " CNodes " << RetVal->CNodes.length()
713           << " FNodes " << RetVal->FNodes.length()
714           << " INodes " << RetVal->INodes.length()
715           << " GNodes " << RetVal->GNodes.length()
716           << " LNodes " << RetVal->LNodes.length()
717           << " ELNodes " << RetVal->ELNodes.length()
718           << " SNodes " << RetVal->SNodes.length()
719           << " ESNodes " << RetVal->ESNodes.length() ) ;
720   if ( _DataFlowExecutor ) {
721     _DataFlowExecutor->EventList() ;
722   }
723 #endif
724   endService( "Graph_Impl::Nodes" );
725   return ( RetVal._retn() ) ;
726 }
727
728 SUPERV::ListOfLinks * Graph_Impl::GLinks() {
729   return Links( NULL , NULL ) ;
730 }
731
732 SUPERV::ListOfLinks * Graph_Impl::Links( GraphBase::ComputingNode * theNode ,
733                                          const char * anInputParam ) {
734   bool begin = true ;
735   SUPERV::ListOfLinks_var RetVal = new SUPERV::ListOfLinks ;
736   RetVal->length( 0 ) ;
737   int i , j , countlink ;
738   countlink = 0 ;
739   for ( i = 0 ; i < DataFlowEditor()->Graph()->GraphNodesSize() ; i++ ) {
740     GraphEditor::InNode * aNode = NULL ;
741     aNode = (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GraphNodes( i )->GetInNode() ;
742     bool ToProcess = false ;
743     if ( theNode == NULL ) {
744       ToProcess = true ;
745     }
746     else {
747       if ( !strcmp( theNode->Name() , aNode->Name() ) ) {
748         if ( !theNode->IsEndSwitchNode() ) {
749           ToProcess = true ;
750         }
751       }
752       else if ( theNode->IsEndSwitchNode() ) {
753         ToProcess = true ;
754       }
755     }
756     if ( ToProcess ) {
757       for ( j = 0 ; j < aNode->GetNodeInPortsSize() ; j++ ) {
758         GraphBase::InPort * anInPort = NULL ;
759         anInPort = aNode->GetChangeNodeInPort( j ) ;
760         if ( anInputParam == NULL ||
761              !strcmp( anInPort->PortName() , anInputParam ) ) {
762           GraphBase::OutPort * anOutPort = NULL ;
763           anOutPort = anInPort->GetOutPort() ;
764           if ( anOutPort && !anOutPort->IsDataStream() ) {
765             if ( strcmp( anOutPort->NodeName() , Name() ) ) {
766 //              MESSAGE("Graph_Impl::Links " << anOutPort->NodeName() << "("
767 //                      << anOutPort->PortName() << ") --> " << aNode->Name() << "("
768 //                      << anInPort->PortName() << ")" ) ;
769               if ( theNode == NULL ||
770                    ( theNode != NULL && !theNode->IsEndSwitchNode() &&
771                      !strcmp( theNode->Name() , aNode->Name() ) ) ) {
772                 if ( anInPort->IsLoop() || anOutPort->IsLoop() ||
773                      ( aNode->IsEndLoopNode() && !strcmp( aNode->CoupledNode()->Name() ,
774                                                           anOutPort->NodeName() ) ) ) {
775 //                  MESSAGE( "Link " << anOutPort->NodeName() << "("
776 //                          << anOutPort->PortName() << ") --> " << aNode->Name() << "("
777 //                          << anInPort->PortName() << ")" << " ignored" ) ;
778                 }
779                 else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
780                   if ( begin ) {
781                     beginService( "Graph_Impl::Links" );
782                     begin = false ;
783                   }
784                   GraphEditor::InNode * anOutNode = NULL ;
785                   anOutNode = (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GetChangeGraphNode( anOutPort->NodeName() )->GetInNode() ;
786                   if ( anOutNode ) {
787                     bool Success ;
788                     Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
789                                           instanceName() , interfaceName() ,
790                                           DataFlowEditor() ,
791                                           aNode ,
792                                           anInPort->PortName() ,
793                                           anOutNode ,
794                                           anOutPort->PortName() ,
795                                           false , true , Success ) ;
796                     if ( Success ) {
797                       PortableServer::ObjectId * id = myLink->getId() ;
798                       CORBA::Object_var obj = _poa->id_to_reference(*id);
799                       SUPERV::Link_var iobject ;
800                       iobject = SUPERV::Link::_narrow(obj) ;
801                       RetVal->length( countlink + 1 ) ;
802                       RetVal[ countlink++ ] = SUPERV::Link::_duplicate( iobject ) ;
803                       anOutPort->AddInPortObjRef( anInPort , SUPERV::Link::_duplicate( iobject ) ) ;
804                     }
805                   }
806                 }
807                 else {
808                   RetVal->length( countlink + 1 ) ;
809                   RetVal[ countlink++ ] = SUPERV::Link::_duplicate( anOutPort->InPortObjRef( anInPort ) ) ;
810                 }
811 //                MESSAGE( "Link " << anOutPort->NodeName() << "("
812 //                         << anOutPort->PortName() << ") --> " << aNode->Name() << "("
813 //                         << anInPort->PortName() << ")" << " selected" ) ;
814               }
815               else {
816 //                MESSAGE( "Link " << anOutPort->NodeName() << "("
817 //                         << anOutPort->PortName() << ") --> " << aNode->Name() << "("
818 //                         << anInPort->PortName() << ")" << " skipped" ) ;
819               }
820             }
821           }
822         }
823       }
824     }
825     for ( j = 0 ; j < aNode->GetNodeOutPortsSize() ; j++ ) {
826       GraphBase::OutPort * anOutPort = aNode->GetChangeNodeOutPort( j ) ;
827       int k ;
828       for ( k = 0 ; k < anOutPort->InPortsSize() ; k++ ) {
829         GraphBase::InPort * anInPort = anOutPort->ChangeInPorts( k ) ;
830         GraphEditor::InNode * toNode = (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GetChangeGraphNode( anInPort->NodeName() )->GetInNode() ;
831         if ( theNode == NULL ||
832              !strcmp( theNode->Name() , aNode->Name() ) ) {
833           if ( !anInPort->IsDataStream() ) {
834             if ( theNode || ( toNode->IsEndSwitchNode() && !aNode->IsSwitchNode() ) ) {
835               if ( anInputParam == NULL ||
836                    !strcmp( anInPort->PortName() , anInputParam ) ) {
837                 if ( anInPort->IsLoop() || anOutPort->IsLoop() ||
838                      ( toNode->IsEndLoopNode() && !strcmp( toNode->CoupledNode()->Name() ,
839                                                            anOutPort->NodeName() ) ) ) {
840 //                  MESSAGE( "Link " << anOutPort->NodeName() << "("
841 //                          << anOutPort->PortName() << ") --> " << toNode->Name() << "("
842 //                          << anInPort->PortName() << ")" << " ignored" ) ;
843                 }
844                 else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
845                   if ( begin ) {
846                     beginService( "Graph_Impl::Links" );
847                     begin = false ;
848                   }
849                   bool Success ;
850                   Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
851                                         instanceName() , interfaceName() ,
852                                         DataFlowEditor() ,
853                                         toNode ,
854                                         anInPort->PortName() ,
855                                         aNode ,
856                                         anOutPort->PortName() ,
857                                         false , true , Success ) ;
858                   if ( Success ) {
859                     PortableServer::ObjectId * id = myLink->getId() ;
860                     CORBA::Object_var obj = _poa->id_to_reference(*id);
861                     SUPERV::Link_var iobject ;
862                     iobject = SUPERV::Link::_narrow(obj) ;
863                     RetVal->length( countlink + 1 ) ;
864                     RetVal[ countlink++ ] = SUPERV::Link::_duplicate( iobject ) ;
865                     anOutPort->AddInPortObjRef( anInPort , SUPERV::Link::_duplicate( iobject ) ) ;
866                   }
867                 }
868                 else {
869                   RetVal->length( countlink + 1 ) ;
870                   RetVal[ countlink++ ] = SUPERV::Link::_duplicate( SUPERV::Link::_narrow( anOutPort->InPortObjRef( anInPort ) ) ) ;
871                 }
872 //                MESSAGE( "Link " << anOutPort->NodeName() << "("
873 //                         << anOutPort->PortName() << ") --> " << toNode->Name() << "("
874 //                         << anInPort->PortName() << ")" << " selected" ) ;
875               }
876               else {
877 //                MESSAGE( "Link " << anOutPort->NodeName() << "("
878 //                         << anOutPort->PortName() << ") --> " << toNode->Name() << "("
879 //                         << anInPort->PortName() << ")" << " skipped" ) ;
880               }
881             }
882           }
883         }
884       }
885     }
886   }
887 #if 0
888   const char * NodeName = "" ;
889   const char * InputParamName = "" ;
890   if ( theNode ) {
891     NodeName = theNode->Name() ;
892   }
893   if ( anInputParam ) {
894     InputParamName = anInputParam ;
895   }
896   MESSAGE( RetVal->length() << " Links of Node " << NodeName << " and of InPort " << InputParamName ) ;
897   for ( i = 0 ; i < (int ) RetVal->length() ; i++ ) {
898     MESSAGE( "Link " << RetVal[i]->OutPort()->Node()->Name() << "("
899              << RetVal[i]->OutPort()->Name() << ") --> "
900              << RetVal[i]->InPort()->Node()->Name() << "("
901              << RetVal[i]->InPort()->Name() << ")" ) ;
902   }
903 #endif
904   if ( !begin ) {
905     endService( "Graph_Impl::Links" );
906   }
907   return ( RetVal._retn() ) ;
908 }
909
910 Engines::Component_ptr Graph_Impl::ComponentRef( const char * aComputerContainer ,
911                                                  const char * aComponentName ) {
912   Engines::Container_var myContainer ;
913   Engines::Component_var objComponent ;
914   DataFlowEditor()->Graph()->StartComponent( 0 , aComputerContainer , aComponentName ,
915                                     myContainer , objComponent ) ;
916   return Engines::Component::_duplicate( objComponent ) ;
917 }
918
919 bool Graph_Impl::IsValid() {
920 //  beginService( "Graph_Impl::IsValid" );
921   bool RetVal = DataFlowEditor()->IsValid() ;
922 //  endService( "Graph_Impl::IsValid" );
923   return RetVal ;
924 }
925 bool Graph_Impl::IsExecutable() {
926 //  beginService( "Graph_Impl::IsExecutable" );
927   bool RetVal = DataFlowEditor()->IsExecutable() ;
928 //  endService( "Graph_Impl::IsExecutable" );
929   return RetVal ;
930 }
931
932 bool Graph_Impl::IsEditing() {
933 //  beginService( "Graph_Impl::IsEditing" );
934   bool RetVal = DataFlowEditor()->IsEditing() ;
935 //  endService( "Graph_Impl::IsEditing" );
936   return RetVal ;
937 }
938 bool Graph_Impl::IsExecuting() {
939 //  beginService( "Graph_Impl::IsExecuting" );
940   bool RetVal = !DataFlowEditor()->IsEditing() ;
941 //  endService( "Graph_Impl::IsExecuting" );
942   return RetVal ;
943 }
944
945 bool Graph_Impl::IsReadOnly() {
946 //  beginService( "Graph_Impl::IsExecuting" );
947   bool RetVal = DataFlowEditor()->IsReadOnly() ;
948 //  endService( "Graph_Impl::IsExecuting" );
949   return RetVal ;
950 }
951
952 long Graph_Impl::LevelMax() {
953 //  beginService( "Graph_Impl::LevelMax" );
954   long RetVal = DataFlowEditor()->LevelMax() ;
955 //  endService( "Graph_Impl::LevelMax" );
956   return RetVal ;
957 }
958 SUPERV::ListOfNodes * Graph_Impl::LevelNodes(long aLevel ) {
959 //  beginService( "Graph_Impl::LevelNodes" );
960   SUPERV::ListOfNodes_var RetVal = new SUPERV::ListOfNodes;
961   int i ;
962   SUPERV::ListOfStrings_var Nodes = DataFlowEditor()->LevelNodes( aLevel ) ;
963 //  RetVal->length( Nodes->length() );
964   for ( i = 0 ; i < (int ) Nodes->length() ; i++ ) {
965 //    char * aNode = Nodes[ i ] ;
966     GraphBase::ComputingNode * aNode = DataFlowEditor()->Graph()->GetChangeGraphNode( Nodes[ i ] ) ;
967     RetVal = SetNode( RetVal , aNode ) ;
968 //    cout << "Graph_Impl::LevelNodes( " << aLevel << " ) " << aNode->Name() << endl ;
969 //    CNode_Impl * myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
970 //                               instanceName() , interfaceName() ,
971 //                               DataFlowEditor() ,
972 //                               (GraphEditor::InNode * ) DataFlowEditor()->GetChangeGraphNode( aNode )->GetInNode() ) ;
973 //    PortableServer::ObjectId * id = myNode->getId() ;
974 //    CORBA::Object_var obj = _poa->id_to_reference(*id);
975 //    SUPERV::CNode_var iobject ;
976 //    iobject = SUPERV::CNode::_narrow(obj) ;
977 //    RetVal[i] = SUPERV::CNode::_duplicate( iobject ) ;
978   }
979 //  endService( "Graph_Impl::LevelNodes" );
980   return ( RetVal._retn() ) ;
981 }
982 long Graph_Impl::ThreadsMax() {
983 //  beginService( "Graph_Impl::ThreadsMax" );
984   long RetVal =  DataFlowEditor()->ThreadsMax() ;
985 //  endService( "Graph_Impl::ThreadsMax" );
986   return RetVal ;
987 }
988 long Graph_Impl::Threads() {
989 //  beginService( "Node_Impl::Threads" );
990   long RetVal = _DataFlowExecutor->Threads() ;
991 //  endService( "Node_Impl::Threads" );
992   return RetVal ;
993 }
994 long Graph_Impl::SuspendedThreads() {
995 //  beginService( "Node_Impl::SuspendedThreads" );
996   long RetVal = _DataFlowExecutor->SuspendedThreads() ;
997 //  endService( "Node_Impl::SuspendedThreads" );
998   return RetVal ;
999 }
1000
1001 bool Graph_Impl::Begin() {
1002   bool RetVal = false ;
1003   if ( DataFlowEditor()->IsEditing() ) {
1004     if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1005       perror("pthread_mutex_lock _MutexExecutorWait") ;
1006       exit( 0 ) ;
1007     }
1008     if ( _DataFlowExecutor ) {
1009       MESSAGE( "Graph_Impl::Begin " << _DataFlowExecutor->Threads() << " threads" )
1010       if ( _DataFlowExecutor->Threads() ) {
1011         _DataFlowExecutor->JoinedWait() ;
1012       }
1013       delete _DataFlowExecutor ;
1014       _DataFlowExecutor = NULL ;
1015       DataFlowEditor()->Executor( NULL ) ;
1016     }
1017     DataFlowEditor()->EditedAfterExecution( false ) ;
1018     int _ExecNumber = theAutomaton->ExecNumber() ;
1019     char ExecNumber[30] ;
1020     sprintf( ExecNumber , "_%d" , _ExecNumber ) ;
1021     int len = strlen( _DebugFileName ) ;
1022     char * DebugFileName = new char [ len + strlen( ExecNumber ) + 6 ] ;
1023     strncpy( DebugFileName , _DebugFileName , len - 4 ) ;
1024     DebugFileName[ len - 4 ] = '\0' ;
1025     strcat( DebugFileName , ExecNumber ) ;
1026     strcat( DebugFileName , "_Exec.log" ) ;
1027     GraphBase::SGraph * myGraph = DataFlowEditor()->GetDataFlow() ;
1028     _DataFlowExecutor = new GraphExecutor::DataFlow( _Orb , _NamingService ,
1029                                                      myGraph->Info.theName.c_str() ,
1030                                                      DebugFileName , Kind() ) ;
1031     MESSAGE( "Graph_Impl::Begin : DataFlowExecutor created" );
1032     RetVal = _DataFlowExecutor->LoadDataFlow( *myGraph ) ;
1033     if ( RetVal ) {
1034       _DataFlowExecutor->Graph()->SetObjImpl( DataFlowEditor()->Graph()->ObjImpl() ) ;
1035       DataFlowEditor()->Executor( _DataFlowExecutor ) ;
1036     }
1037     if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1038       perror("pthread_mutex_unlock _MutexExecutorWait") ;
1039       exit( 0 ) ;
1040     }
1041   }
1042   return RetVal ;
1043 }
1044 bool Graph_Impl::Run() {
1045   beginService( "Graph_Impl::Run" );
1046   bool RetVal = false ;
1047   if ( DataFlowEditor()->IsEditing() ) {
1048     MESSAGE( "Graph_Impl::Run IsEditing" );
1049     RetVal = Begin() ;
1050     if ( RetVal ) {
1051       MESSAGE( "Graph_Impl::(Re)Run " );
1052       RetVal = CNode_Impl::Run() ;
1053     }
1054   }
1055   else {
1056     MESSAGE( "Graph_Impl::(Re)Run " );
1057     RetVal = CNode_Impl::ReRun() ;
1058   }
1059   endService( "Graph_Impl::Run" );
1060   return RetVal ;
1061 }
1062 bool Graph_Impl::Start() {
1063   beginService( "Graph_Impl::Start" );
1064   bool RetVal = false ;
1065   if ( DataFlowEditor()->IsEditing() ) {
1066     MESSAGE( "Graph_Impl::Start IsEditing" );
1067     RetVal = Begin() ;
1068   }
1069   else {
1070     RetVal = true ;
1071   }
1072   if ( RetVal ) {
1073     MESSAGE( "Graph_Impl::(Re)Start " );
1074     RetVal = ReStart() ;
1075   }
1076   endService( "Graph_Impl::Start" );
1077   return RetVal ;
1078 }
1079
1080 bool Graph_Impl::EventNoW( SUPERV::CNode_out aNode ,
1081                            SUPERV::GraphEvent & anEvent ,
1082                            SUPERV::GraphState & aState ) {
1083   bool RetVal = false ;
1084   char * aNodeName = NULL ;
1085   SUPERV::GraphEvent theEvent = SUPERV::UndefinedEvent ;
1086   SUPERV::GraphState theState = SUPERV::UndefinedState ;
1087   if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1088     perror("pthread_mutex_lock _MutexExecutorWait") ;
1089     exit( 0 ) ;
1090   }
1091   if ( _DataFlowExecutor &&
1092        ( _DataFlowExecutor->GetListSize() || !DataFlowEditor()->IsEditing() ) ) {
1093     RetVal = _DataFlowExecutor->Event( & aNodeName , theEvent , theState , false ) ;
1094 //  endService( "Graph_Impl::Event" );
1095     if ( strlen( aNodeName ) ) {
1096       if ( strcmp( aNodeName , Name() ) ) {
1097         aNode = Node( aNodeName ) ;
1098       }
1099       else {
1100         aNode = Node() ;
1101       }
1102     }
1103     else {
1104       aNode = SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
1105     }
1106 //    cout << "Graph_Impl::EventNoW " << aNode->Name() << " QSize " << _DataFlowExecutor->GetListSize() << endl ;
1107   }
1108   else {
1109 //    cout << "Graph_Impl::EventNoW NO DataFlowExecutor or QSize=0 " << endl ;
1110   }
1111   if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1112     perror("pthread_mutex_unlock _MutexExecutorWait") ;
1113     exit( 0 ) ;
1114   }
1115   anEvent = theEvent ;
1116   aState = theState ;
1117   return RetVal ;
1118 }
1119
1120 bool Graph_Impl::Event( SUPERV::CNode_out aNode ,
1121                         SUPERV::GraphEvent & anEvent ,
1122                         SUPERV::GraphState & aState ) {
1123 //  beginService( "Graph_Impl::Event" );
1124   bool RetVal = false ;
1125   char * aNodeName = NULL ;
1126   SUPERV::GraphEvent theEvent = SUPERV::UndefinedEvent ;
1127   SUPERV::GraphState theState = SUPERV::UndefinedState ;
1128   if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1129     perror("pthread_mutex_lock _MutexExecutorWait") ;
1130     exit( 0 ) ;
1131   }
1132   if ( _DataFlowExecutor &&
1133        ( _DataFlowExecutor->GetListSize() || !DataFlowEditor()->IsEditing() ) ){
1134     RetVal = _DataFlowExecutor->Event( & aNodeName , theEvent , theState ) ;
1135 //  endService( "Graph_Impl::Event" );
1136     if ( strlen( aNodeName ) ) {
1137       if ( strcmp( aNodeName , Name() ) ) {
1138         aNode = Node( aNodeName ) ;
1139       }
1140       else {
1141         aNode = Node() ;
1142       }
1143     }
1144     else {
1145       aNode = SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
1146     }
1147 //    cout << "Graph_Impl::Event " << aNode->Name() << " QSize " << _DataFlowExecutor->GetListSize() << endl ;
1148   }
1149   else {
1150 //    cout << "Graph_Impl::Event NO DataFlowExecutor or QSize=0 " << endl ;
1151   }
1152   if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1153     perror("pthread_mutex_unlock _MutexExecutorWait") ;
1154     exit( 0 ) ;
1155   }
1156   anEvent = theEvent ;
1157   aState = theState ;
1158   return RetVal ;
1159 }
1160
1161 bool Graph_Impl::EventW( SUPERV::CNode_out aNode ,
1162                          SUPERV::GraphEvent & anEvent ,
1163                          SUPERV::GraphState & aState ) {
1164 //  beginService( "Graph_Impl::EventW" );
1165   bool RetVal = false ;
1166   char * aNodeName = NULL ;
1167   SUPERV::GraphEvent theEvent = SUPERV::UndefinedEvent ;
1168   SUPERV::GraphState theState = SUPERV::UndefinedState ;
1169   if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1170     perror("pthread_mutex_lock _MutexExecutorWait") ;
1171     exit( 0 ) ;
1172   }
1173   if ( _DataFlowExecutor &&
1174        ( _DataFlowExecutor->GetListSize() || !DataFlowEditor()->IsEditing() ) ) {
1175     RetVal = _DataFlowExecutor->EventW( & aNodeName , theEvent , theState ) ;
1176     if ( RetVal && strcmp( aNodeName , Name() ) ) {
1177       aNode = Node( aNodeName ) ;
1178     }
1179     else {
1180       aNode = Node() ;
1181     }
1182   }
1183   if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1184     perror("pthread_mutex_unlock _MutexExecutorWait") ;
1185     exit( 0 ) ;
1186   }
1187   anEvent = theEvent ;
1188   aState = theState ;
1189 //  endService( "Graph_Impl::EventW" );
1190   return RetVal ;
1191 }
1192
1193 long Graph_Impl::EventQSize() {
1194 //  beginService( "Graph_Impl::EventQSize" );
1195   long QSize = -1 ;
1196   if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1197     perror("pthread_mutex_lock _MutexExecutorWait") ;
1198     exit( 0 ) ;
1199   }
1200   if ( _DataFlowExecutor ) {
1201     QSize = _DataFlowExecutor->EventQSize() ;
1202   }
1203   if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1204     perror("pthread_mutex_unlock _MutexExecutorWait") ;
1205     exit( 0 ) ;
1206   }
1207 //  endService( "Graph_Impl::EventQSize" );
1208   return QSize ;
1209 }
1210
1211 long Graph_Impl::LastLevelDone() {
1212 //  beginService( "Graph_Impl::LastLevelDone" );
1213   if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1214     perror("pthread_mutex_lock _MutexExecutorWait") ;
1215     exit( 0 ) ;
1216   }
1217   long RetVal = 0 ;
1218   if ( _DataFlowExecutor ) {
1219     RetVal = _DataFlowExecutor->LastLevelDone() ;
1220   }
1221   if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1222     perror("pthread_mutex_unlock _MutexExecutorWait") ;
1223     exit( 0 ) ;
1224   }
1225 //  endService( "Graph_Impl::LastLevelDone" );
1226   return RetVal ;
1227 }
1228
1229 long Graph_Impl::SubGraphsNumber() {
1230 //  beginService( "Graph_Impl::SubGraphsNumber" );
1231   long RetVal = 0 ;
1232   if ( DataFlowEditor()->IsExecutable() ) {
1233     RetVal = DataFlowEditor()->SubGraphsNumber() ;
1234   }
1235 //  endService( "Graph_Impl::SubGraphsNumber" );
1236   return RetVal ;
1237 }
1238
1239 SUPERV::ListOfNodes * Graph_Impl::SubGraphsNodes( const long aSubGraphNumber ) {
1240   beginService( "Graph_Impl::SubGraphsNodes" );
1241   SUPERV::ListOfNodes_var RetVal = new SUPERV::ListOfNodes ;
1242   if ( DataFlowEditor()->IsEditing() ) {
1243     SUPERV::ListOfNodes * aGraphNodes = Nodes() ;
1244     int i ;
1245 // ComputingNodes
1246     for ( i = 0 ; i < (int ) aGraphNodes->CNodes.length() ; i++ ) {
1247       SUPERV::CNode_var aNode = (aGraphNodes->CNodes)[ i ] ;
1248       if ( aNode->SubGraph() == aSubGraphNumber ) {
1249         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
1250       }
1251     }
1252 // FactoryNodes
1253     for ( i = 0 ; i < (int ) aGraphNodes->FNodes.length() ; i++ ) {
1254       SUPERV::FNode_var aNode = (aGraphNodes->FNodes)[ i ] ;
1255       if ( aNode->SubGraph() == aSubGraphNumber ) {
1256         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
1257       }
1258     }
1259 // InLineNodes
1260     for ( i = 0 ; i < (int ) aGraphNodes->INodes.length() ; i++ ) {
1261       SUPERV::INode_var aNode = (aGraphNodes->INodes)[ i ] ;
1262       if ( aNode->SubGraph() == aSubGraphNumber ) {
1263         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
1264       }
1265     }
1266 // GOTONodes
1267     for ( i = 0 ; i < (int ) aGraphNodes->GNodes.length() ; i++ ) {
1268       SUPERV::GNode_var aNode = (aGraphNodes->GNodes)[ i ] ;
1269       if ( aNode->SubGraph() == aSubGraphNumber ) {
1270         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
1271       }
1272     }
1273 // LoopNodes
1274     for ( i = 0 ; i < (int ) aGraphNodes->LNodes.length() ; i++ ) {
1275       SUPERV::LNode_var aNode = (aGraphNodes->LNodes)[ i ] ;
1276       if ( aNode->SubGraph() == aSubGraphNumber ) {
1277         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
1278       }
1279     }
1280 // EndLoopNodes
1281     for ( i = 0 ; i < (int ) aGraphNodes->ELNodes.length() ; i++ ) {
1282       SUPERV::ELNode_var aNode = (aGraphNodes->ELNodes)[ i ] ;
1283       if ( aNode->SubGraph() == aSubGraphNumber ) {
1284         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
1285       }
1286     }
1287 // SwitchNodes
1288     for ( i = 0 ; i < (int ) aGraphNodes->SNodes.length() ; i++ ) {
1289       SUPERV::SNode_var aNode = (aGraphNodes->SNodes)[ i ] ;
1290       if ( aNode->SubGraph() == aSubGraphNumber ) {
1291         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
1292       }
1293     }
1294 // EndSwitchNodes
1295     for ( i = 0 ; i < (int ) aGraphNodes->ESNodes.length() ; i++ ) {
1296       SUPERV::ESNode_var aNode = (aGraphNodes->ESNodes)[ i ] ;
1297       if ( aNode->SubGraph() == aSubGraphNumber ) {
1298         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
1299       }
1300     }
1301   }
1302   endService( "Graph_Impl::SubGraphsNodes" );
1303   return ( RetVal._retn() ) ;
1304 }
1305
1306 bool Graph_Impl::Merge(const SUPERV::Graph_ptr aGraph ) {
1307 //  beginService( "Graph_Impl::Merge" );
1308   bool RetVal = true ;
1309   map< string , int > aMapOfNodes ;
1310   RetVal = Merge( aGraph , aMapOfNodes ) ;
1311 //  endService( "Graph_Impl::Merge" );
1312   return RetVal ;
1313 }
1314
1315 bool Graph_Impl::Merge(const SUPERV::Graph_ptr aGraph , map< string , int > & aMapOfNodes ) {
1316   beginService( "Graph_Impl::Merge" );
1317   bool RetVal = true ;
1318   if ( DataFlowEditor()->IsEditing() ) {
1319     SUPERV::ListOfNodes * aGraphNodes = aGraph->Nodes() ;
1320     int i ;
1321     SUPERV::Port_ptr aPort ;
1322 //    SUPERV::StreamPort_ptr aStreamPort ;
1323 // ComputingNodes
1324     for ( i = 0 ; i < (int ) aGraphNodes->CNodes.length() ; i++ ) {
1325       SUPERV::CNode_var aNode = (aGraphNodes->CNodes)[ i ] ;
1326       SUPERV::CNode_ptr myNode = CNode( *(aNode->Service()) ) ;
1327       if ( !CORBA::is_nil( myNode ) ) {
1328         myNode->SetName( aNode->Name() ) ;
1329         myNode->SetAuthor( aNode->Author() ) ;
1330         myNode->SetComment( aNode->Comment() ) ;
1331         myNode->Coords( aNode->X() , aNode->Y() ) ;
1332         string * aNodetheName = new string( aNode->Name() ) ;
1333         aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
1334         delete aNodetheName ;
1335         RetVal = true ;
1336       }
1337       else {
1338         RetVal = false ;
1339         break ;
1340       }
1341 // The following informations are now in the service from SALOME_ModuleCatalog
1342 //      SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
1343 //      int j ;
1344 //      for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
1345 //        if ( myStreamPorts[ j ]->IsInput() && myStreamPorts[ j ]->IsDataStream() ) {
1346 //          aStreamPort = myNode->InStreamPort( myStreamPorts[ j ]->Name() , myStreamPorts[ j ]->Type() ) ;
1347 //        }
1348 //        else if ( myStreamPorts[ j ]->IsDataStream() ) {
1349 //          aStreamPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name() , myStreamPorts[ j ]->Type() ) ;
1350 //        }
1351 //      }
1352     }
1353 // FactoryNodes
1354     if ( RetVal ) {
1355       for ( i = 0 ; i < (int ) aGraphNodes->FNodes.length() ; i++ ) {
1356         SUPERV::FNode_var aNode = (aGraphNodes->FNodes)[ i ] ;
1357         SUPERV::FNode_ptr myNode = FNode( aNode->GetComponentName() ,
1358                                           aNode->GetInterfaceName() ,
1359                                           *(aNode->Service()) ) ;
1360         if ( !CORBA::is_nil( myNode ) ) {
1361           myNode->SetName( aNode->Name() ) ;
1362           myNode->SetAuthor( aNode->Author() ) ;
1363           myNode->SetComment( aNode->Comment() ) ;
1364           myNode->Coords( aNode->X() , aNode->Y() ) ;
1365           string * aNodetheName = new string( aNode->Name() ) ;
1366           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
1367           delete aNodetheName ;
1368           RetVal = true ;
1369         }
1370         else {
1371           RetVal = false ;
1372           break ;
1373         }
1374 // The following informations are now in the service from SALOME_ModuleCatalog
1375 //        SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
1376 //        int j ;
1377 //        for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
1378 //          if ( myStreamPorts[ j ]->IsInput() && myStreamPorts[ j ]->IsDataStream() ) {
1379 //            aStreamPort = myNode->InStreamPort( myStreamPorts[ j ]->Name() , myStreamPorts[ j ]->Type() ) ;
1380 //          }
1381 //          else if ( myStreamPorts[ j ]->IsDataStream() ) {
1382 //            aStreamPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name() , myStreamPorts[ j ]->Type() ) ;
1383 //          }
1384 //        }
1385       }
1386     }
1387 // InLineNodes
1388     if ( RetVal ) {
1389       for ( i = 0 ; i < (int ) aGraphNodes->INodes.length() ; i++ ) {
1390         SUPERV::INode_var aNode = (aGraphNodes->INodes)[ i ] ;
1391         SUPERV::INode_ptr myNode = INode( aNode->PyFuncName() , *(aNode->PyFunction()) ) ;
1392         if ( !CORBA::is_nil( myNode ) ) {
1393           myNode->SetName( aNode->Name() ) ;
1394           myNode->SetAuthor( aNode->Author() ) ;
1395           myNode->SetComment( aNode->Comment() ) ;
1396           myNode->Coords( aNode->X() , aNode->Y() ) ;
1397           string * aNodetheName = new string( aNode->Name() ) ;
1398           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
1399           delete aNodetheName ;
1400           SUPERV::ListOfPorts myPorts = *(aNode->Ports()) ;
1401           int j ;
1402           for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
1403             if ( myPorts[ j ]->IsInput() ) {
1404               aPort = myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
1405             }
1406             else {
1407               aPort = myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
1408             }
1409           }
1410           if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
1411             SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
1412             for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
1413               if ( myStreamPorts[ j ]->IsInput() ) {
1414                 aPort = myNode->InStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
1415               }
1416               else {
1417                 aPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
1418               }
1419             }
1420           }
1421           RetVal = true ;
1422         }
1423         else {
1424           RetVal = false ;
1425           break ;
1426         }
1427       }
1428     }
1429 // GOTONodes
1430     if ( RetVal ) {
1431       for ( i = 0 ; i < (int ) aGraphNodes->GNodes.length() ; i++ ) {
1432         SUPERV::GNode_var aNode = (aGraphNodes->GNodes)[ i ] ;
1433         SUPERV::GNode_ptr myNode = GNode( aNode->PyFuncName() , *(aNode->PyFunction()) , aNode->Coupled()->Name() ) ;
1434         if ( !CORBA::is_nil( myNode ) ) {
1435           myNode->SetName( aNode->Name() ) ;
1436           myNode->SetAuthor( aNode->Author() ) ;
1437           myNode->SetComment( aNode->Comment() ) ;
1438           myNode->Coords( aNode->X() , aNode->Y() ) ;
1439           string * aNodetheName = new string( aNode->Name() ) ;
1440           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
1441           delete aNodetheName ;
1442           SUPERV::ListOfPorts myPorts = *(aNode->Ports()) ;
1443           int j ;
1444           for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
1445             if ( myPorts[ j ]->IsInput() ) {
1446               aPort = myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
1447             }
1448             else {
1449               aPort = myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
1450             }
1451           }
1452           if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
1453             SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
1454             for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
1455               if ( myStreamPorts[ j ]->IsInput() ) {
1456                 aPort = myNode->InStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
1457               }
1458               else {
1459                 aPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
1460               }
1461             }
1462           }
1463           RetVal = true ;
1464         }
1465         else {
1466           RetVal = false ;
1467           break ;
1468         }
1469       }
1470     }
1471 // LoopNodes
1472     if ( RetVal ) {
1473       for ( i = 0 ; i < (int ) aGraphNodes->LNodes.length() ; i++ ) {
1474         SUPERV::LNode_var aNode = (aGraphNodes->LNodes)[ i ] ;
1475         SUPERV::INode_ptr anEndOfLoop ;
1476         SUPERV::LNode_ptr myNode = LNode( aNode->PyInitName() ,
1477                                           *(aNode->PyInit()) ,
1478                                           aNode->PyMoreName() ,
1479                                           *(aNode->PyMore()) ,
1480                                           aNode->PyNextName() ,
1481                                           *(aNode->PyNext()) ,
1482                                           anEndOfLoop ) ;
1483         if ( !CORBA::is_nil( myNode ) ) {
1484           myNode->SetName( aNode->Name() ) ;
1485           myNode->SetAuthor( aNode->Author() ) ;
1486           myNode->SetComment( aNode->Comment() ) ;
1487           myNode->Coords( aNode->X() , aNode->Y() ) ;
1488           string * aNodetheName = new string( aNode->Name() ) ;
1489           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
1490           delete aNodetheName ;
1491           SUPERV::ListOfPorts myPorts = *(aNode->Ports()) ;
1492           int j ;
1493           for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
1494             if ( myPorts[ j ]->IsInput() ) {
1495               aPort = myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
1496             }
1497             else {
1498               aPort = myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
1499             }
1500           }
1501           if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
1502             SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
1503             for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
1504               if ( myStreamPorts[ j ]->IsInput() ) {
1505                 aPort = myNode->InStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
1506               }
1507               else {
1508                 aPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
1509               }
1510             }
1511           }
1512           SUPERV::INode_ptr myEndOfLoop = aNode->Coupled() ;
1513           anEndOfLoop->SetName( myEndOfLoop->Name() ) ;
1514           anEndOfLoop->SetAuthor( myEndOfLoop->Author() ) ;
1515           anEndOfLoop->SetComment( myEndOfLoop->Comment() ) ;
1516           anEndOfLoop->Coords( myEndOfLoop->X() , myEndOfLoop->Y() ) ;
1517           anEndOfLoop->SetPyFunction( myEndOfLoop->PyFuncName() , *(myEndOfLoop->PyFunction()) ) ;
1518           aNodetheName = new string( myEndOfLoop->Name() ) ;
1519           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( anEndOfLoop->Name() ) ;
1520           if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
1521             SUPERV::ListOfStreamPorts myStreamLoopPorts = *(myEndOfLoop->StreamPorts()) ;
1522             for ( j = 0 ; j < (int ) myStreamLoopPorts.length() ; j++ ) {
1523               if ( myStreamLoopPorts[ j ]->IsInput() ) {
1524                 aPort = myNode->InStreamPort( myStreamLoopPorts[ j ]->Name() , StringToDataStreamType( myStreamLoopPorts[ j ]->Type() ) , myStreamLoopPorts[ j ]->Dependency() ) ;
1525               }
1526               else {
1527                 aPort = myNode->OutStreamPort( myStreamLoopPorts[ j ]->Name() , StringToDataStreamType( myStreamLoopPorts[ j ]->Type() ) , myStreamLoopPorts[ j ]->Dependency() ) ;
1528               }
1529             }
1530           }
1531           delete aNodetheName ;
1532           RetVal = true ;
1533         }
1534         else {
1535           RetVal = false ;
1536           break ;
1537         }
1538       }
1539     }
1540 // SwitchNodes
1541     if ( RetVal ) {
1542       for ( i = 0 ; i < (int ) aGraphNodes->SNodes.length() ; i++ ) {
1543         SUPERV::SNode_var aNode = (aGraphNodes->SNodes)[ i ] ;
1544         SUPERV::INode_ptr anEndOfSwitch ;
1545         SUPERV::SNode_ptr myNode = SNode( aNode->PyFuncName() , *(aNode->PyFunction()) , anEndOfSwitch ) ;
1546         if ( !CORBA::is_nil( myNode ) ) {
1547           myNode->SetName( aNode->Name() ) ;
1548           myNode->SetAuthor( aNode->Author() ) ;
1549           myNode->SetComment( aNode->Comment() ) ;
1550           myNode->Coords( aNode->X() , aNode->Y() ) ;
1551           string * aNodetheName = new string( aNode->Name() ) ;
1552           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
1553           delete aNodetheName ;
1554           SUPERV::ListOfPorts myPorts = *(aNode->Ports()) ;
1555           int j ;
1556           for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
1557             if ( myPorts[ j ]->IsInput() ) {
1558               aPort = myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
1559             }
1560             else {
1561               aPort = myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
1562             }
1563           }
1564           if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
1565             SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
1566             for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
1567               if ( myStreamPorts[ j ]->IsInput() ) {
1568                 aPort = myNode->InStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
1569               }
1570               else {
1571                 aPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
1572               }
1573             }
1574           }
1575           SUPERV::INode_ptr myEndOfSwitch = aNode->Coupled() ;
1576           anEndOfSwitch->SetName( myEndOfSwitch->Name() ) ;
1577           anEndOfSwitch->SetAuthor( myEndOfSwitch->Author() ) ;
1578           anEndOfSwitch->SetComment( myEndOfSwitch->Comment() ) ;
1579           anEndOfSwitch->Coords( myEndOfSwitch->X() , myEndOfSwitch->Y() ) ;
1580           anEndOfSwitch->SetPyFunction( myEndOfSwitch->PyFuncName() , *(myEndOfSwitch->PyFunction()) ) ;
1581           aNodetheName = new string( myEndOfSwitch->Name() ) ;
1582           aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( anEndOfSwitch->Name() ) ;
1583           delete aNodetheName ;
1584           myPorts = *(myEndOfSwitch->Ports()) ;
1585           for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
1586             if ( myPorts[ j ]->IsInput() ) {
1587               aPort = myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
1588             }
1589             else {
1590               aPort = myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
1591             }
1592           }
1593           if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
1594             SUPERV::ListOfStreamPorts myStreamSwitchPorts = *(myEndOfSwitch->StreamPorts()) ;
1595             for ( j = 0 ; j < (int ) myStreamSwitchPorts.length() ; j++ ) {
1596               if ( myStreamSwitchPorts[ j ]->IsInput() ) {
1597                 aPort = myNode->InStreamPort( myStreamSwitchPorts[ j ]->Name() , StringToDataStreamType( myStreamSwitchPorts[ j ]->Type() ) , myStreamSwitchPorts[ j ]->Dependency() ) ;
1598               }
1599               else {
1600                 aPort = myNode->OutStreamPort( myStreamSwitchPorts[ j ]->Name() , StringToDataStreamType( myStreamSwitchPorts[ j ]->Type() ) , myStreamSwitchPorts[ j ]->Dependency() ) ;
1601               }
1602             }
1603           }
1604           RetVal = true ;
1605         }
1606         else {
1607           RetVal = false ;
1608           break ;
1609         }
1610       }
1611     }
1612     if ( RetVal ) {
1613       SUPERV::ListOfLinks * aGraphLinks = aGraph->GLinks() ;
1614       SUPERV::ListOfPorts * aGraphPorts = aGraph->Ports() ;
1615 //      cout << "Graph_Impl::Merge " << aGraphLinks->length() << " links " << aGraphPorts->length() << " GraphPorts"
1616 //           << endl ;
1617       for ( i = 0 ; i < (int ) aGraphLinks->length() ; i++ ) {
1618         SUPERV::Link_var aLink = (*aGraphLinks)[ i ] ;
1619         SUPERV::Port_var OutPort = aLink->OutPort() ;
1620         SUPERV::Port_var InPort = aLink->InPort() ;
1621         string * aLinkFromNodeName = new string( OutPort->Node()->Name() ) ;
1622         string * aLinkToNodeName = new string( InPort->Node()->Name() ) ;
1623         RetVal = DataFlowEditor()->AddLink( DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] )->Name() ,
1624                                            OutPort->Name() ,
1625                                            DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] )->Name() ,
1626                                            InPort->Name() ) ;
1627         if ( RetVal ) {
1628           int j ;
1629           for ( j = 1 ; j <= aLink->CoordsSize() ; j++ ) {
1630             long X , Y ;
1631             RetVal = aLink->Coords( j , X , Y ) ;
1632             if ( !RetVal )
1633               break ;
1634             RetVal = DataFlowEditor()->AddLinkCoord( DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] )->Name() ,
1635                                                      OutPort->Name() ,
1636                                                      DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] )->Name() ,
1637                                                      InPort->Name() ,
1638                                                      j , X , Y ) ;
1639             if ( !RetVal ) {
1640               break ;
1641             }
1642           }
1643         }
1644         delete aLinkFromNodeName ;
1645         delete aLinkToNodeName ;
1646         if ( !RetVal ) {
1647           break ;
1648         }
1649       }
1650       if ( RetVal ) {
1651         for ( i = 0 ; i < (int ) aGraphPorts->length() ; i++ ) {
1652           SUPERV::Port_var aPort = (*aGraphPorts)[ i ] ;
1653           if ( !aPort->IsGate() ) {
1654             MESSAGE( "Graph_Impl::Merge " << i << ". " << aPort->Node()->Name() << " " << aPort->Name() ) ;
1655             char * aPortName = aPort->Name() ;
1656             char * aNodeName = new char[ strlen( aPortName ) + 1 ] ;
1657             strcpy( aNodeName , aPortName ) ;
1658             char * thePortName = strchr( aNodeName , '\\' ) ;
1659             thePortName[ 0 ] = '\0' ;
1660             bool hasinput = aGraph->Node( aNodeName )->Port( thePortName + 1 )->HasInput() ;
1661 //            cout << "Graph_Impl::Merge " << " aNodeName " << aNodeName << " aPort " << thePortName + 1
1662 //                 << " HasInput " << hasinput << endl ;
1663             if ( hasinput ) {
1664               RetVal = DataFlowEditor()->AddInputData( DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aNodeName ] )->Name() ,
1665                                                        thePortName + 1 ,
1666                                                        *(aPort->ToAny()) ) ;
1667             }
1668             delete [] aNodeName ;
1669             if ( !RetVal ) {
1670               break ;
1671             }
1672           }
1673         }
1674       }
1675     }
1676   }
1677   MESSAGE( "Graph_Impl::Merge returns " << RetVal ) ;
1678   endService( "Graph_Impl::Merge" );
1679   return RetVal ;
1680 }
1681
1682 SUPERV::StreamGraph_ptr Graph_Impl::ToStreamGraph() {
1683   SUPERV::StreamGraph_var iobject = SUPERV::StreamGraph::_nil() ;
1684   beginService( "Graph_Impl::ToStreamGraph" );
1685   if ( IsStreamGraph() ) {
1686 //  StreamGraph_Impl * myStreamGraph = new StreamGraph_Impl( _Orb , _Poa , _ContId ,
1687 //                                          instanceName() , interfaceName() ) ;
1688 //  PortableServer::ObjectId * id = myStreamGraph->getId() ;
1689 //  CORBA::Object_var obj = _poa->id_to_reference(*id);
1690     iobject = SUPERV::StreamGraph::_narrow( ObjRef() ) ;
1691     if ( CORBA::is_nil( iobject ) ) {
1692       MESSAGE( "ToStreamGraph of " << Name() << " (IsStreamGraph) --> nil reference" ) ;
1693     }
1694   }
1695   else {
1696     MESSAGE( "ToStreamGraph of " << Name() << " (IsNOTStreamGraph) --> nil reference" ) ;
1697   }
1698   endService( "Graph_Impl::ToStreamGraph" );
1699   return SUPERV::StreamGraph::_duplicate( iobject ) ;
1700 }
1701
1702