1 // SUPERV Supervision : contains the implementation of interfaces of SuperVision described in SUPERV.idl
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : Graph_Impl.cxx
25 // Author : Jean Rahuel
35 //#include "utilities.h"
37 #include "StreamGraph_Impl.hxx"
39 #include "DataFlowEditor_DataFlow.hxx"
41 extern GraphExecutor::FiniteStateMachine * theAutomaton ;
43 static void CreateEditor( CORBA::ORB_ptr orb ,
44 const char *instanceName ,
45 const char *aDataFlowName ,
46 const SUPERV::KindOfNode aKindOfNode ,
48 GraphEditor::DataFlow ** aDataFlowEditor ) {
49 // string dbgfile = "/tmp/" ;
50 bool aXmlFile = false ;
52 dbgfile += instanceName ;
54 int lenname = strlen( aDataFlowName ) ;
55 char * theDataFlowName = new char [ lenname+1 ] ;
56 strcpy( theDataFlowName , aDataFlowName ) ;
57 if ( aDataFlowName ) {
58 if ( lenname > 4 && !strcmp( &aDataFlowName[ lenname - 4 ] , ".xml" ) ) {
59 strncpy( theDataFlowName , &aDataFlowName[ 0 ] , lenname-4 ) ;
60 theDataFlowName[ lenname-4 ] = '\0' ;
63 for ( i = lenname - 5 ; i >= 0 ; i-- ) {
64 if ( aDataFlowName[ i ] == '/' ) {
65 strncpy( theDataFlowName , &aDataFlowName[ i + 1 ] , lenname-5-i ) ;
66 theDataFlowName[ lenname-5-i ] = '\0' ;
72 strcpy( theDataFlowName , &aDataFlowName[ 0 ] ) ;
75 string theDataFlowInstanceName = theDataFlowName ;
77 theDataFlowInstanceName = theAutomaton->GraphInstanceName( theDataFlowName ) ;
79 dbgfile += theDataFlowInstanceName ;
80 dbgfile = dbgfile + "_" + theAutomaton->DbgFileNumber() + ".log" ;
81 SALOME_NamingService * NamingService = new SALOME_NamingService( orb ) ;
82 *aDataFlowEditor = new GraphEditor::DataFlow( orb , NamingService ,
83 theDataFlowInstanceName.c_str() , dbgfile.c_str() ,
85 MESSAGE( "CreateEditor " << theDataFlowName << " uniquely named " << theDataFlowInstanceName << " created with "
86 << dbgfile.c_str() ) ;
87 delete [] theDataFlowName ;
90 static void CreateEditor( CORBA::ORB_ptr orb ,
91 const char *instanceName ,
92 const char *aDataFlowName ,
93 const SUPERV::KindOfNode aKindOfNode ,
95 GraphExecutor::DataFlow ** aDataFlowExecutor ) {
96 // string dbgfile = "/tmp/" ;
98 dbgfile += instanceName ;
100 int lenname = strlen( aDataFlowName ) ;
101 char * theDataFlowName = new char [ lenname+1 ] ;
102 strcpy( theDataFlowName , aDataFlowName ) ;
103 if ( aDataFlowName ) {
104 strcpy( theDataFlowName , &aDataFlowName[ 0 ] ) ;
106 string theDataFlowInstanceName = theDataFlowName ;
107 dbgfile += theDataFlowInstanceName ;
108 dbgfile = dbgfile + "_" + theAutomaton->DbgFileNumber() ;
111 astr << theAutomaton->ExecNumber() ;
112 dbgfile += astr.str() ;
113 dbgfile += string( "_Exec.log" ) ;
115 SALOME_NamingService * NamingService = new SALOME_NamingService( orb ) ;
116 *aDataFlowExecutor = new GraphExecutor::DataFlow( orb , NamingService ,
117 theDataFlowInstanceName.c_str() , dbgfile.c_str() ,
119 MESSAGE( "CreateEditor " << theDataFlowName << " " << theDataFlowInstanceName << " created with "
120 << dbgfile.c_str() ) ;
121 delete [] theDataFlowName ;
124 Graph_Impl::Graph_Impl( CORBA::ORB_ptr orb ,
125 PortableServer::POA_ptr poa ,
126 PortableServer::ObjectId * contId ,
127 const char *instanceName ,
128 const char *interfaceName ,
129 const char *aDataFlowName ,
130 const SUPERV::KindOfNode aKindOfNode ) :
131 GNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowName , aKindOfNode ) {
132 // MESSAGE("Graph_Impl::Graph_Impl activate object instanceName("
133 // << instanceName << ") interfaceName(" << interfaceName << ") --> "
134 // << hex << (void *) this << dec )
135 // beginService( "Graph_Impl::Graph_Impl" );
136 _Orb = CORBA::ORB::_duplicate(orb);
139 if ( aKindOfNode == SUPERV::DataFlowGraph || aKindOfNode == SUPERV::MacroNode ) {
140 // MESSAGE( "Graph_Impl::Graph_Impl _poa->activate_object" );
142 _id = _poa->activate_object(_thisObj);
145 // MESSAGE( "Graph_Impl::Graph_Impl NO _poa->activate_object " );
148 if ( aKindOfNode == SUPERV::DataFlowGraph || aKindOfNode == SUPERV::DataStreamGraph ) {
150 GraphEditor::DataFlow * aDataFlowEditor ;
151 CreateEditor( orb , instanceName , aDataFlowName , aKindOfNode ,
152 dbgfile , &aDataFlowEditor ) ;
153 _DebugFileName = new char[ strlen( dbgfile.c_str() )+1 ] ;
154 strcpy( _DebugFileName , dbgfile.c_str() ) ;
156 _NamingService = new SALOME_NamingService( orb ) ;
157 DataFlowEditor( aDataFlowEditor ) ;
158 DataFlowEditor()->Graph()->SetGraphEditor( aDataFlowEditor ) ;
159 DataFlowEditor()->Graph()->SetObjImpl( this ) ;
161 pthread_mutex_init( &_MutexExecutorWait , NULL ) ;
162 // DataFlowExecutor( NULL ) ;
163 // endService( "Graph_Impl::Graph_Impl" );
166 Graph_Impl::Graph_Impl( CORBA::ORB_ptr orb ,
167 PortableServer::POA_ptr poa ,
168 PortableServer::ObjectId * contId ,
169 const char *instanceName ,
170 const char *interfaceName ,
171 GraphEditor::DataFlow * aDataFlowEditor ,
172 GraphEditor::InNode * aDataFlowNode ) :
173 GNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , aDataFlowNode ) {
174 // beginService( "Graph_Impl::Graph_Impl" );
175 // MESSAGE( aDataFlowEditor->Graph()->Name() << " " );
176 if ( aDataFlowEditor->Graph()->IsDataFlowNode() || aDataFlowNode->IsMacroNode() ) {
177 // MESSAGE( "Graph_Impl::Graph_Impl _poa->activate_object" );
179 _id = _poa->activate_object(_thisObj);
182 // MESSAGE( "Graph_Impl::Graph_Impl NO _poa->activate_object " );
184 _Orb = CORBA::ORB::_duplicate(orb);
187 DataFlowEditor( aDataFlowEditor ) ;
188 DataFlowEditor()->Graph()->SetGraphEditor( aDataFlowEditor ) ;
189 DataFlowEditor()->Graph()->SetObjImpl( this ) ;
190 pthread_mutex_init( &_MutexExecutorWait , NULL ) ;
191 // DataFlowExecutor( NULL ) ;
192 // endService( "Graph_Impl::Graph_Impl" );
195 Graph_Impl::Graph_Impl( CORBA::ORB_ptr orb ,
196 PortableServer::POA_ptr poa ,
197 PortableServer::ObjectId * contId ,
198 const char *instanceName ,
199 const char *interfaceName ,
200 GraphExecutor::DataFlow * aDataFlowExecutor ,
201 GraphExecutor::InNode * aDataFlowExecutorNode ) :
202 GNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowExecutor , aDataFlowExecutorNode ) {
203 // beginService( "Graph_Impl::Graph_Impl" );
204 // MESSAGE( aDataFlowExecutor->Graph()->Name() << " " );
205 if ( aDataFlowExecutor->Graph()->IsDataFlowNode() || aDataFlowExecutorNode->IsMacroNode() ) {
206 // MESSAGE( "Graph_Impl::Graph_Impl _poa->activate_object" );
208 _id = _poa->activate_object(_thisObj);
211 // MESSAGE( "Graph_Impl::Graph_Impl NO _poa->activate_object " );
213 _Orb = CORBA::ORB::_duplicate(orb);
216 DataFlowExecutor( aDataFlowExecutor ) ;
217 DataFlowExecutor()->Graph()->SetGraphExecutor( aDataFlowExecutor ) ;
218 DataFlowExecutor()->Graph()->SetObjImpl( this ) ;
219 pthread_mutex_init( &_MutexExecutorWait , NULL ) ;
220 // DataFlowExecutor( NULL ) ;
221 // endService( "Graph_Impl::Graph_Impl" );
224 Graph_Impl::Graph_Impl() {
227 Graph_Impl::~Graph_Impl() {
228 beginService( "Graph_Impl::~Graph_Impl" );
229 endService( "Graph_Impl::~Graph_Impl" );
232 void Graph_Impl::destroy() {
233 beginService( "Graph_Impl::destroy" );
234 _poa->deactivate_object(*_id) ;
235 CORBA::release(_poa) ;
237 _thisObj->_remove_ref();
238 // endService( "Graph_Impl::destroy" );
242 char* Graph_Impl::getIOR() {
244 return CORBA::string_dup( NULLSTRING ) ;
246 else if ( CORBA::is_nil( myServant ) ) {
247 PortableServer::ObjectId* id = getId();
248 CORBA::Object_var obj;
249 obj = _poa->id_to_reference(*id);
250 myServant = SUPERV::Graph::_narrow(obj);
252 return(CORBA::string_dup(_Orb->object_to_string(myServant)));
255 SUPERV::Graph_ptr Graph_Impl::Copy() {
256 beginService( "Graph_Impl::Copy" );
257 SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
259 Graph_Impl * myGraph ;
260 myGraph = new Graph_Impl( _Orb , _Poa, _ContId,
261 instanceName() , interfaceName() ,
262 DataFlowEditor()->Graph()->Name() , SUPERV::DataFlowGraph ) ;
263 PortableServer::ObjectId * id = myGraph->getId() ;
264 CORBA::Object_var obj = _poa->id_to_reference(*id);
265 iobject = SUPERV::Graph::_narrow(obj) ;
266 GraphBase::ListOfSGraphs * aListOfSGraphs = GetGraphs() ;
267 myGraph->LoadGraphs( aListOfSGraphs ) ;
269 endService( "Graph_Impl::Copy" );
270 return SUPERV::Graph::_duplicate(iobject) ;
273 void Graph_Impl::ReadOnly() {
274 DataFlowEditor()->ReadOnly() ;
277 SUPERV::INode_ptr Graph_Impl::Node() {
278 // beginService( "Graph_Impl::Node" );
279 PortableServer::ObjectId * id = getId() ;
280 CORBA::Object_var obj = _poa->id_to_reference(*id);
281 SUPERV::Graph_var iobject ;
282 iobject = SUPERV::Graph::_narrow(obj) ;
283 // endService( "Graph_Impl::Node" );
284 return SUPERV::Graph::_duplicate(iobject) ;
287 GraphBase::ListOfSGraphs * Graph_Impl::GetGraphs() {
288 return DataFlowEditor()->GetDataFlows() ;
291 bool Graph_Impl::LoadGraphs( GraphBase::ListOfSGraphs * aListOfDataFlows ) {
292 beginService( "Graph_Impl::LoadGraphs" );
293 bool RetVal = false ;
294 if ( DataFlowEditor()->IsEditing() ) {
295 // RetVal = DataFlowEditor()->LoadDataFlows( aListOfDataFlows ) ;
296 RetVal = LoadDataFlows( DataFlowEditor() , aListOfDataFlows , 0 ) ;
298 endService( "Graph_Impl::LoadGraphs" );
302 bool Graph_Impl::Import(const char * aXmlFile ) {
303 beginService( "Graph_Impl::Import" );
304 bool RetVal = false ;
305 if ( DataFlowEditor()->IsEditing() && !IsMacro() ) {
306 GraphBase::ListOfSGraphs aListOfDataFlows ;
307 RetVal = DataFlowEditor()->LoadXml( aXmlFile , aListOfDataFlows ) ;
308 if ( RetVal && aXmlFile != NULL ) {
309 // RetVal = DataFlowEditor()->LoadDataFlows( &aListOfDataFlows ) ;
310 RetVal = LoadDataFlows( DataFlowEditor() , &aListOfDataFlows , 0 ) ;
313 endService( "Graph_Impl::Import" );
317 bool Graph_Impl::Export(const char * anXmlFile ) {
318 beginService( "Graph_Impl::Export" );
319 bool RetVal = false ;
321 char * aFile = new char [ strlen( anXmlFile ) + 5 ] ;
322 strcpy( aFile , anXmlFile ) ;
323 int len = strlen( aFile ) ;
324 if ( !strcmp( &aFile[ len - 4 ] , ".xml" ) ) {
326 else if ( !strcmp( &aFile[ len - 3 ] , ".py" ) ) {
327 strcpy( &aFile[ len - 3 ] , ".xml" ) ;
328 len = strlen( aFile ) ;
331 strcat( aFile , ".xml" ) ;
332 len = strlen( aFile ) ;
334 RetVal = DataFlowEditor()->SaveXml( aFile ) ;
336 strcpy( &aFile[ len - 4 ] , ".py" ) ;
337 RetVal = DataFlowEditor()->SavePy( aFile ) ;
341 endService( "Graph_Impl::Export" );
345 SUPERV::CNode_ptr Graph_Impl::CNode( const SALOME_ModuleCatalog::Service &NodeService ) {
346 beginService( "Graph_Impl::CNode" );
347 SUPERV::CNode_var iobject = SUPERV::CNode::_nil() ;
348 if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() && !IsMacro() ) {
349 CNode_Impl * myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
350 instanceName() , interfaceName() ,
352 NodeService , NULLSTRING ,
353 SUPERV::ComputingNode , NULLSTRING ) ;
354 if ( myNode->DataFlowNode() ) {
355 PortableServer::ObjectId * id = myNode->getId() ;
356 CORBA::Object_var obj = _poa->id_to_reference(*id);
357 iobject = SUPERV::CNode::_narrow(obj) ;
358 myNode->SetObjRef( SUPERV::CNode::_duplicate( iobject ) ) ;
361 endService( "Graph_Impl::CNode" );
362 return SUPERV::CNode::_duplicate( iobject ) ;
365 SUPERV::FNode_ptr Graph_Impl::FNode( const char * NodeComponentName ,
366 const char * NodeInterfaceName ,
367 const SALOME_ModuleCatalog::Service &NodeService ) {
368 beginService( "Graph_Impl::FNode" );
369 SUPERV::FNode_var iobject = SUPERV::FNode::_nil() ;
370 if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() && !IsMacro() ) {
371 FNode_Impl * myNode = new FNode_Impl( _Orb , _Poa , _ContId ,
372 instanceName() , interfaceName() ,
376 NodeInterfaceName ) ;
377 if ( myNode->DataFlowNode() ) {
378 PortableServer::ObjectId * id = myNode->getId() ;
379 CORBA::Object_var obj = _poa->id_to_reference(*id);
380 iobject = SUPERV::FNode::_narrow(obj) ;
381 myNode->SetObjRef( SUPERV::FNode::_duplicate( iobject ) ) ;
384 endService( "Graph_Impl::FNode" );
385 return SUPERV::FNode::_duplicate( iobject ) ;
388 SUPERV::INode_ptr Graph_Impl::INode( const char * FuncName ,
389 const SUPERV::ListOfStrings & PythonFuntion ) {
390 beginService( "Graph_Impl::INode" );
391 SUPERV::INode_var iobject = SUPERV::INode::_nil() ;
392 if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() && !IsMacro() ) {
393 INode_Impl * myNode = new INode_Impl( _Orb , _Poa , _ContId ,
394 instanceName() , interfaceName() ,
396 FuncName , PythonFuntion ,
397 SUPERV::InLineNode ) ;
398 if ( myNode->DataFlowNode() ) {
399 PortableServer::ObjectId * id = myNode->getId() ;
400 CORBA::Object_var obj = _poa->id_to_reference(*id);
401 iobject = SUPERV::INode::_narrow(obj) ;
402 myNode->SetObjRef( SUPERV::INode::_duplicate( iobject ) ) ;
405 endService( "Graph_Impl::INode" );
406 return SUPERV::INode::_duplicate( iobject ) ;
410 SUPERV::GNode_ptr Graph_Impl::GNode( const char * FuncName ,
411 const SUPERV::ListOfStrings & PythonFuntion ,
412 const char * anInLineNode ) {
413 beginService( "Graph_Impl::GNode" );
414 SUPERV::GNode_var iobject = SUPERV::GNode::_nil() ;
415 if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() && !IsMacro() ) {
416 GNode_Impl * myNode = new GNode_Impl( _Orb , _Poa , _ContId ,
417 instanceName() , interfaceName() ,
419 FuncName , PythonFuntion ,
421 if ( myNode->DataFlowNode() ) {
422 PortableServer::ObjectId * id = myNode->getId() ;
423 CORBA::Object_var obj = _poa->id_to_reference(*id);
424 iobject = SUPERV::GNode::_narrow(obj) ;
425 myNode->SetObjRef( SUPERV::GNode::_duplicate( iobject ) ) ;
426 if ( strlen( anInLineNode ) ) {
427 GraphBase::InLineNode * CoupledINode = (GraphBase::InLineNode * ) DataFlowEditor()->Graph()->GetGraphNode( anInLineNode ) ;
428 if ( anInLineNode ) {
429 myNode->SetCoupled( anInLineNode ) ;
430 Link( myNode->Port( "OutGate" ) , CoupledINode->ObjRef()->Port( "InGate" ) ) ;
435 endService( "Graph_Impl::GNode" );
436 return SUPERV::GNode::_duplicate( iobject ) ;
439 SUPERV::LNode_ptr Graph_Impl::LNode( const char * InitName ,
440 const SUPERV::ListOfStrings & InitFunction ,
441 const char * MoreName ,
442 const SUPERV::ListOfStrings & MoreFunction ,
443 const char * NextName ,
444 const SUPERV::ListOfStrings & NextFunction ,
445 SUPERV::INode_out anEndOfLoop ) {
446 beginService( "Graph_Impl::LNode" );
447 SUPERV::LNode_var iobject = SUPERV::LNode::_nil() ;
448 SUPERV::ELNode_var iendobject = SUPERV::ELNode::_nil() ;
449 if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() && !IsMacro() ) {
450 GraphBase::ListOfFuncName FuncNameList ;
451 FuncNameList.resize(3) ;
452 FuncNameList[0] = InitName ;
453 FuncNameList[1] = MoreName ;
454 FuncNameList[2] = NextName ;
455 GraphBase::ListOfPythonFunctions PythonFunctionList ;
456 PythonFunctionList.resize(3) ;
457 PythonFunctionList[0] = &InitFunction ;
458 PythonFunctionList[1] = &MoreFunction ;
459 PythonFunctionList[2] = &NextFunction ;
460 LNode_Impl * myNode = new LNode_Impl( _Orb , _Poa , _ContId ,
461 instanceName() , interfaceName() ,
463 FuncNameList , PythonFunctionList ,
464 // InitName , InitFunction ,
465 // MoreName , MoreFunction ,
466 // NextName , NextFunction ,
468 if ( myNode->DataFlowNode() ) {
469 PortableServer::ObjectId * id = myNode->getId() ;
470 CORBA::Object_var obj = _poa->id_to_reference(*id);
471 iobject = SUPERV::LNode::_narrow(obj) ;
472 myNode->SetObjRef( SUPERV::LNode::_duplicate( iobject ) ) ;
474 SALOME_ModuleCatalog::Service aVoidService = SALOME_ModuleCatalog::Service() ;
476 if ( strlen( InitName ) ) {
477 anEndName = new char( 3 + strlen( InitName ) + 1 ) ;
478 strcpy( anEndName , "End" ) ;
479 strcat( anEndName , InitName ) ;
482 anEndName = new char( 3 + strlen( "Loop" ) + 1 ) ;
483 strcpy( anEndName , "EndLoop" ) ;
485 ELNode_Impl * myEndNode = new ELNode_Impl( _Orb , _Poa , _ContId ,
486 instanceName() , interfaceName() ,
489 SUPERV::EndLoopNode ) ;
490 PortableServer::ObjectId * endid = myEndNode->getId() ;
491 CORBA::Object_var endobj = _poa->id_to_reference(*endid);
492 iendobject = SUPERV::ELNode::_narrow(endobj) ;
493 myEndNode->SetObjRef( SUPERV::ELNode::_duplicate( iendobject ) ) ;
494 myNode->SetCoupled( myEndNode->BaseNode()->Name() ) ;
495 myEndNode->SetCoupled( myNode->BaseNode()->Name() ) ;
496 Link( myNode->Port( "DoLoop" ) , myEndNode->Port( "DoLoop" ) ) ;
497 Link( myEndNode->Port( "DoLoop" ) , myNode->Port( "InitLoop" ) ) ;
500 anEndOfLoop = SUPERV::ELNode::_duplicate( iendobject ) ;
501 endService( "Graph_Impl::LNode" );
502 return SUPERV::LNode::_duplicate( iobject ) ;
505 SUPERV::SNode_ptr Graph_Impl::SNode( const char * FuncName ,
506 const SUPERV::ListOfStrings & PythonFunction ,
507 SUPERV::INode_out anEndOfSwitch ) {
508 beginService( "Graph_Impl::SNode" );
509 SUPERV::SNode_var iobject = SUPERV::SNode::_nil() ;
510 SUPERV::ESNode_var iendobject = SUPERV::ESNode::_nil() ;
511 if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() && !IsMacro() ) {
512 SNode_Impl * myNode = new SNode_Impl( _Orb , _Poa , _ContId ,
513 instanceName() , interfaceName() ,
515 FuncName , PythonFunction ,
516 SUPERV::SwitchNode ) ;
517 if ( myNode->DataFlowNode() ) {
518 PortableServer::ObjectId * id = myNode->getId() ;
519 CORBA::Object_var obj = _poa->id_to_reference(*id);
520 iobject = SUPERV::SNode::_narrow(obj) ;
521 myNode->SetObjRef( SUPERV::SNode::_duplicate( iobject ) ) ;
523 string anEndName = "End" ;
524 if ( strlen( FuncName ) ) {
525 anEndName += FuncName ;
528 anEndName += "Switch" ;
530 // cout << "Graph_Impl::SNode anEndName " << (void *) FuncName << " " << FuncName
531 // << " " << strlen(FuncName) << " " << (void *) anEndName.c_str() << " "
532 // << anEndName.c_str() << endl ;
533 ESNode_Impl * myEndNode = new ESNode_Impl( _Orb , _Poa , _ContId ,
534 instanceName() , interfaceName() ,
537 SUPERV::EndSwitchNode ) ;
538 // cout << "Graph_Impl::SNode returned anEndName " << (void *) FuncName << " "
539 // << FuncName << " " << strlen(FuncName) << " " << (void *) anEndName.c_str()
540 // << " " << anEndName.c_str() << endl ;
541 PortableServer::ObjectId * endid = myEndNode->getId() ;
542 CORBA::Object_var endobj = _poa->id_to_reference(*endid);
543 iendobject = SUPERV::ESNode::_narrow(endobj) ;
544 myEndNode->SetObjRef( SUPERV::ESNode::_duplicate( iendobject ) ) ;
545 myNode->SetCoupled( myEndNode->BaseNode()->Name() ) ;
546 myEndNode->SetCoupled( myNode->BaseNode()->Name() ) ;
547 if ( !Link( myNode->Port( "Default" ) , myEndNode->Port( "Default" ) ) ) {
548 iobject = SUPERV::SNode::_nil() ;
549 iendobject = SUPERV::ESNode::_nil() ;
553 anEndOfSwitch = SUPERV::ESNode::_duplicate( iendobject ) ;
554 endService( "Graph_Impl::SNode" );
555 return SUPERV::SNode::_duplicate( iobject ) ;
558 // WARNING : THIS IS COMPLICATED :
559 bool Graph_Impl::LoadDataFlows( GraphEditor::DataFlow * aDataFlowEditor ,
560 GraphBase::ListOfSGraphs * aListOfDataFlows ,
562 beginService( "Graph_Impl::EditorLoadDataFlows" ) ;
563 SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
564 if ( !aDataFlowEditor->LoadDataFlow( &(*aListOfDataFlows)[ index ] ) ) {
565 MESSAGE("Graph_Impl::LoadDataFlows failed" ) ;
568 // That graph is not a StreamGraph :
569 else if ( !aDataFlowEditor->Graph()->HasDataStream() ) {
570 aDataFlowEditor->Graph()->Kind( SUPERV::DataFlowGraph ) ;
571 aDataFlowEditor->Graph()->SetGraphEditor( aDataFlowEditor ) ;
572 Graph_Impl * myGraph ;
573 // We create a Graph ObjRef for that graph
574 myGraph = new Graph_Impl( _Orb , _Poa, _ContId,
575 instanceName() , interfaceName() ,
576 aDataFlowEditor , NULL ) ;
577 PortableServer::ObjectId * id = myGraph->getId() ;
578 CORBA::Object_var obj = _poa->id_to_reference(*id) ;
579 iobject = SUPERV::Graph::_narrow( obj ) ;
580 myGraph->SetObjRef( SUPERV::Graph::_duplicate( iobject ) ) ;
581 GraphBase::Graph * aGraph = myGraph->DataFlowEditor()->Graph() ;
583 for ( i = 0 ; i < aGraph->GraphNodesSize() ; i++ ) {
584 if ( aGraph->GraphNodes( i )->IsMacroNode() ) {
585 GraphBase::GOTONode * aMacroNode = (GraphBase::GOTONode * ) aGraph->GraphNodes( i ) ;
589 // Creation of a GraphMacroNode in the current editor
590 SUPERV::Graph_var macroiobject = SUPERV::Graph::_nil() ;
591 string aMacroNodeName = string( "Macro_" ) + string( myGraph->Name() ) ;
592 Graph_Impl * myMacroNode ;
593 myMacroNode = new Graph_Impl( _Orb , _Poa, _ContId,
594 instanceName() , interfaceName() ,
595 aMacroNodeName.c_str() , SUPERV::MacroNode ) ;
596 id = myMacroNode->getId() ;
597 obj = _poa->id_to_reference(*id);
598 macroiobject = SUPERV::Graph::_narrow( obj ) ;
599 myMacroNode->DataFlowEditor( DataFlowEditor() ) ;
600 aMacroNode->SetGraphEditor( DataFlowEditor() ) ;
601 GraphEditor::InNode * aDataFlowNode = (GraphEditor::InNode * ) aMacroNode->GetInNode() ;
602 myMacroNode->DataFlowNode( aDataFlowNode ) ;
603 aDataFlowNode->SetObjRef( SUPERV::CNode::_duplicate( SUPERV::CNode::_narrow( obj ) ) ) ;
604 aDataFlowNode->SetObjImpl( this ) ;
610 char * aCoupledNodeName = aMacroNode->CoupledNodeName() ;
611 MESSAGE( "LoadDataFlows MacroNode " << aMacroNode->Name() << " --> " << aCoupledNodeName
612 << " to be searched among " << (*aListOfDataFlows).size() << " Graphs" ) ;
614 for ( index = 0 ; index < (int ) (*aListOfDataFlows).size() ; index++ ) {
615 if ( !strcmp( aCoupledNodeName , (*aListOfDataFlows)[index].Info.theName.c_str() ) ) {
617 // At first create the editor and a StreamGraph
618 GraphEditor::DataFlow * aMacroGraphDataFlowEditor ;
619 CreateEditor( _Orb , instanceName() , aCoupledNodeName , SUPERV::DataStreamGraph ,
620 dbgfile , &aMacroGraphDataFlowEditor ) ;
621 // if ( !aDataFlowEditor->LoadDataFlow( aDataFlowEditor , aListOfDataFlows , index ) ) {
622 MESSAGE( "RECURSIVE IMPORT OF GRAPHS OF MACRONODES :" << aCoupledNodeName ) ;
623 if ( !LoadDataFlows( aMacroGraphDataFlowEditor , aListOfDataFlows , index ) ) {
624 MESSAGE("Graph_Impl::LoadDataFlows failed" ) ;
628 // That graph is not a StreamGraph :
629 else if ( !aMacroGraphDataFlowEditor->Graph()->HasDataStream() ) {
630 aMacroGraphDataFlowEditor->Graph()->Kind( SUPERV::DataFlowGraph ) ;
631 aMacroGraphDataFlowEditor->Graph()->SetGraphEditor( aMacroGraphDataFlowEditor ) ;
632 Graph_Impl * myMacroGraph ;
633 // We create a Graph ObjRef for that graph
634 myMacroGraph = new Graph_Impl( _Orb , _Poa, _ContId,
635 instanceName() , interfaceName() ,
636 aMacroGraphDataFlowEditor , NULL ) ;
637 PortableServer::ObjectId * id = myMacroGraph->getId() ;
638 CORBA::Object_var obj = _poa->id_to_reference(*id);
639 SUPERV::Graph_var iobject = SUPERV::Graph::_narrow( obj ) ;
640 myMacroGraph->SetObjRef( SUPERV::Graph::_duplicate( iobject ) ) ;
642 GraphBase::Graph * aMacroGraph = myMacroGraph->DataFlowEditor()->Graph() ;
643 aMacroGraph->GraphMacroLevel( aGraph->GraphMacroLevel() + 1 ) ;
644 aMacroGraph->CoupledNode( aMacroNode ) ;
646 aMacroGraph->MacroObject( SUPERV::Graph::_duplicate( iobject ) ) ;
647 aMacroGraph->MacroObject( SUPERV::Graph::_duplicate( macroiobject ) ) ;
649 // Set the GraphMacroNode ObjRef in the MacroNode
650 aMacroNode->CoupledNode( aMacroGraph ) ;
651 aMacroNode->MacroObject( SUPERV::Graph::_duplicate( iobject ) ) ;
659 endService( "Graph_Impl::EditorLoadDataFlows" );
663 bool Graph_Impl::LoadDataFlows( GraphExecutor::DataFlow * aDataFlowExecutor ,
664 GraphBase::ListOfSGraphs * aListOfDataFlows ,
666 beginService( "Graph_Impl::ExecutorLoadDataFlows" ) ;
667 MESSAGE("Graph_Impl::LoadDataFlows index " << index << " " << (*aListOfDataFlows)[index].Info.theName.c_str() ) ;
668 SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
669 // That method is recursive :
670 // At first we load the supergraph with index = 0 :
671 // (After we load the graph corresponding to each MacroNode :)
672 if ( !aDataFlowExecutor->LoadDataFlow( &(*aListOfDataFlows)[ index ] ) ) {
673 MESSAGE("Graph_Impl::LoadDataFlows failed" ) ;
676 // That graph is not a StreamGraph :
677 else if ( !aDataFlowExecutor->Graph()->HasDataStream() ) {
678 aDataFlowExecutor->Graph()->Kind( SUPERV::DataFlowGraph ) ;
679 GraphEditor::DataFlow * aDataFlowEditor ;
680 aDataFlowEditor = theAutomaton->MapGraph( (*aListOfDataFlows)[index].Info.theName.c_str() )->GraphEditor() ;
681 aDataFlowEditor->Executor( aDataFlowExecutor ) ;
682 aDataFlowEditor->Graph()->SetGraphEditor( aDataFlowEditor ) ;
683 aDataFlowEditor->Graph()->SetGraphExecutor( aDataFlowExecutor ) ;
684 aDataFlowExecutor->Graph()->SetGraphEditor( aDataFlowEditor ) ;
685 aDataFlowExecutor->Graph()->SetGraphExecutor( aDataFlowExecutor ) ;
686 Graph_Impl * myGraph ;
687 // We create a Graph ObjRef for that graph
688 myGraph = new Graph_Impl( _Orb , _Poa, _ContId,
689 instanceName() , interfaceName() ,
690 aDataFlowExecutor , NULL ) ;
691 PortableServer::ObjectId * id = myGraph->getId() ;
692 CORBA::Object_var obj = _poa->id_to_reference(*id) ;
693 iobject = SUPERV::Graph::_narrow( obj ) ;
694 myGraph->SetObjRef( SUPERV::Graph::_duplicate( iobject ) ) ;
695 myGraph->DataFlowEditor( aDataFlowEditor ) ;
696 myGraph->DataFlowExecutor( aDataFlowExecutor ) ;
697 MESSAGE("ExecutorLoadDataFlows IsEditing " << myGraph->Name() << " "
698 << myGraph->DataFlowEditor() << " " << myGraph->DataFlowEditor()->IsEditing() << " "
699 << myGraph->DataFlowEditor()->Graph()->Name() << " "
700 << myGraph->DataFlowEditor()->Graph()->GraphEditor() << " "
701 << myGraph->DataFlowEditor()->Graph()->GraphEditor()->IsEditing() ) ;
702 GraphBase::Graph * aGraph = myGraph->DataFlowExecutor()->Graph() ;
704 // For the supergraph or each graph of MacroNodes we search MacroNodes recursively :
705 for ( i = 0 ; i < aGraph->GraphNodesSize() ; i++ ) {
706 if ( aGraph->GraphNodes( i )->IsMacroNode() ) {
707 GraphBase::GOTONode * aMacroNode = (GraphBase::GOTONode * ) aGraph->GraphNodes( i ) ;
711 // Creation of a GraphMacroNode ObjRef in the current executor
712 SUPERV::Graph_var macroiobject = SUPERV::Graph::_nil() ;
713 string aMacroNodeName = string( "Macro_" ) + string( aGraph->Name() ) ;
714 Graph_Impl * myMacroNode ;
715 myMacroNode = new Graph_Impl( _Orb , _Poa, _ContId,
716 instanceName() , interfaceName() ,
717 aMacroNodeName.c_str() , SUPERV::MacroNode ) ;
718 id = myMacroNode->getId() ;
719 obj = _poa->id_to_reference(*id);
720 macroiobject = SUPERV::Graph::_narrow( obj ) ;
721 myMacroNode->DataFlowEditor( DataFlowEditor() ) ;
722 myMacroNode->DataFlowExecutor( DataFlowExecutor() ) ;
723 aMacroNode->SetGraphEditor( DataFlowEditor() ) ;
724 GraphExecutor::InNode * aDataFlowExecutorNode = (GraphExecutor::InNode * ) aMacroNode->GetInNode() ;
725 myMacroNode->DataFlowNode( aDataFlowExecutorNode ) ;
726 aDataFlowExecutorNode->SetObjRef( SUPERV::CNode::_duplicate( SUPERV::CNode::_narrow( obj ) ) ) ;
727 aDataFlowExecutorNode->SetObjImpl( this ) ;
729 char * aCoupledNodeName = aMacroNode->CoupledNodeName() ;
730 MESSAGE( "LoadDataFlows MacroNode " << aMacroNode->Name() << " --> " << aCoupledNodeName
731 << " to be searched among " << (*aListOfDataFlows).size() << " Graphs" ) ;
733 for ( index = 0 ; index < (int ) (*aListOfDataFlows).size() ; index++ ) {
734 if ( !strcmp( aCoupledNodeName , (*aListOfDataFlows)[index].Info.theName.c_str() ) ) {
736 // At first create the editor and a StreamGraph
737 GraphExecutor::DataFlow * aMacroGraphDataFlowExecutor ;
738 CreateEditor( _Orb , instanceName() , aCoupledNodeName , SUPERV::DataStreamGraph ,
739 dbgfile , &aMacroGraphDataFlowExecutor ) ;
740 // if ( !aDataFlowEditor->LoadDataFlow( aDataFlowEditor , aListOfDataFlows , index ) ) {
741 MESSAGE( "RECURSIVE IMPORT OF GRAPHS OF MACRONODES :" << aCoupledNodeName ) ;
742 if ( !LoadDataFlows( aMacroGraphDataFlowExecutor , aListOfDataFlows , index ) ) {
743 MESSAGE("Graph_Impl::LoadDataFlows failed" ) ;
747 // That graph is not a StreamGraph :
748 else if ( !aMacroGraphDataFlowExecutor->Graph()->HasDataStream() ) {
749 aMacroGraphDataFlowExecutor->Graph()->Kind( SUPERV::DataFlowGraph ) ;
750 aMacroGraphDataFlowExecutor->Graph()->SetGraphExecutor( aMacroGraphDataFlowExecutor ) ;
751 GraphEditor::DataFlow * aDataFlow = theAutomaton->MapGraph( aCoupledNodeName )->GraphEditor() ;
752 if ( aDataFlow == NULL ) {
753 MESSAGE( "ExecutorLoadDataFlows NULL GraphEditor ERROR" ) ;
755 aMacroGraphDataFlowExecutor->Graph()->SetGraphEditor( aDataFlow ) ;
756 aMacroGraphDataFlowExecutor->Graph()->SetGraphExecutor( aMacroGraphDataFlowExecutor ) ;
757 aMacroGraphDataFlowExecutor->Graph()->SetGraphPorts() ;
758 Graph_Impl * myMacroGraph ;
759 // We create a Graph ObjRef for that graph
760 myMacroGraph = new Graph_Impl( _Orb , _Poa, _ContId,
761 instanceName() , interfaceName() ,
762 aMacroGraphDataFlowExecutor , NULL ) ;
763 PortableServer::ObjectId * id = myMacroGraph->getId() ;
764 CORBA::Object_var obj = _poa->id_to_reference(*id);
765 SUPERV::Graph_var iobject = SUPERV::Graph::_narrow( obj ) ;
766 myMacroGraph->SetObjRef( SUPERV::Graph::_duplicate( iobject ) ) ;
767 myMacroGraph->DataFlowEditor( aDataFlow ) ;
768 aDataFlow->Executor( aMacroGraphDataFlowExecutor ) ;
769 myMacroGraph->DebugFileName( (char * ) dbgfile.c_str() ) ;
771 GraphBase::Graph * aMacroGraph = myMacroGraph->DataFlowExecutor()->Graph() ;
772 aMacroGraph->GraphMacroLevel( aGraph->GraphMacroLevel() + 1 ) ;
774 // Set the MacroNode ObjRef in the GraphMacroNode
775 aMacroGraph->CoupledNode( aMacroNode ) ;
776 aMacroGraph->MacroObject( SUPERV::Graph::_duplicate( macroiobject ) ) ;
778 // Set the GraphMacroNode ObjRef in the MacroNode
779 aMacroNode->CoupledNode( aMacroGraph ) ;
780 aMacroNode->MacroObject( SUPERV::Graph::_duplicate( iobject ) ) ;
791 endService( "Graph_Impl::ExecutorLoadDataFlows" );
795 SUPERV::Graph_ptr Graph_Impl::MNode( const char * aXmlFileName ) {
796 beginService( "Graph_Impl::MNode" );
797 SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
798 if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() && !IsMacro() ) {
799 GraphBase::ListOfSGraphs aListOfDataFlows ;
801 // At first create the editor and a StreamGraph with the xml file
802 GraphEditor::DataFlow * aDataFlowEditor ;
803 CreateEditor( _Orb , instanceName() , aXmlFileName , SUPERV::DataStreamGraph ,
804 dbgfile , &aDataFlowEditor ) ;
805 int lenname = strlen( aXmlFileName ) ;
806 bool loaded = false ;
807 // Import of the xml file
808 if ( lenname > 4 && !strcmp( &aXmlFileName[ lenname - 4 ] , ".xml" ) ) {
809 loaded = aDataFlowEditor->LoadXml( aXmlFileName , aListOfDataFlows ) ;
811 iobject = MNode( aDataFlowEditor , aListOfDataFlows ) ;
818 // WARNING : THIS IS COMPLICATED :
819 // I should have to remove duplicated code ...
820 SUPERV::Graph_ptr Graph_Impl::MNode( GraphEditor::DataFlow * aMacroGraphDataFlowEditor ,
821 GraphBase::ListOfSGraphs aListOfDataFlows ) {
822 beginService( "Graph_Impl::MNode" ) ;
823 SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
824 SUPERV::Graph_var macroiobject = SUPERV::Graph::_nil() ;
827 if ( !aMacroGraphDataFlowEditor->LoadDataFlow( &aListOfDataFlows[ 0 ] ) ) {
828 MESSAGE("Graph_Impl::MNode LoadDataFlow failed" ) ;
832 // That graph is not a StreamGraph :
833 else if ( !aMacroGraphDataFlowEditor->Graph()->HasDataStream() ) {
834 aMacroGraphDataFlowEditor->Graph()->Kind( SUPERV::DataFlowGraph ) ;
835 aMacroGraphDataFlowEditor->Graph()->SetGraphEditor( aMacroGraphDataFlowEditor ) ;
836 Graph_Impl * myMacroGraph ;
837 // We create a Graph ObjRef for that graph
838 myMacroGraph = new Graph_Impl( _Orb , _Poa, _ContId,
839 instanceName() , interfaceName() ,
840 aMacroGraphDataFlowEditor , NULL ) ;
841 PortableServer::ObjectId * id = myMacroGraph->getId() ;
842 CORBA::Object_var obj = _poa->id_to_reference(*id);
843 iobject = SUPERV::Graph::_narrow( obj ) ;
844 myMacroGraph->SetObjRef( SUPERV::Graph::_duplicate( iobject ) ) ;
848 // Creation of a GraphMacroNode in the current editor
849 string aMacroNodeName = string( "Macro_" ) + string( myMacroGraph->Name() ) ;
850 Graph_Impl * myMacroNode ;
851 myMacroNode = new Graph_Impl( _Orb , _Poa, _ContId,
852 instanceName() , interfaceName() ,
853 aMacroNodeName.c_str() , SUPERV::MacroNode ) ;
854 id = myMacroNode->getId() ;
855 obj = _poa->id_to_reference(*id);
856 macroiobject = SUPERV::Graph::_narrow( obj ) ;
857 myMacroNode->DataFlowEditor( DataFlowEditor() ) ;
859 // Creation of the MacroNode itself in the current Graph
860 GraphBase::ListOfFuncName aFuncName ;
861 aFuncName.resize( 1 ) ;
863 SUPERV::ListOfStrings aListOfStrings ;
864 aListOfStrings.length( 1 ) ;
865 aListOfStrings[0] = "" ;
866 GraphBase::ListOfPythonFunctions aPythonFunction ;
867 aPythonFunction.resize( 1 ) ;
868 aPythonFunction[0] = &aListOfStrings ;
869 SALOME_ModuleCatalog::Service * aMacroNodeService = myMacroGraph->Service() ;
870 GraphEditor::InNode * aDataFlowNode = DataFlowEditor()->AddNode( *aMacroNodeService , "" , "" ,
871 aMacroNodeName.c_str() , SUPERV::MacroNode ,
872 aFuncName , aPythonFunction ) ;
873 aDataFlowNode->SetPythonFunction( "" , aListOfStrings ) ;
874 myMacroNode->DataFlowNode( aDataFlowNode ) ;
875 aDataFlowNode->ComputingNode()->SetService( *aMacroNodeService ) ;
876 aDataFlowNode->SetObjRef( SUPERV::CNode::_duplicate( SUPERV::CNode::_narrow( obj ) ) ) ;
877 aDataFlowNode->SetObjImpl( this ) ;
881 GraphBase::Graph * aGraph = myMacroGraph->DataFlowEditor()->Graph() ;
882 GraphBase::Graph * aGraphOfMacroGraph = myMacroNode->DataFlowEditor()->Graph() ;
883 GraphBase::Graph * aMacroGraph = myMacroNode->DataFlowNode()->GraphMacroNode() ;
884 aMacroGraph->Kind( SUPERV::MacroNode ) ;
885 aMacroGraph->SetGraphEditor( DataFlowEditor() ) ;
886 // Creation of the Ports of the MacroNode from the ports of the GraphMacroNode
887 aMacroGraph->SetMacroPorts( aGraph ) ;
888 // Valid ==> creation of Service and the ports of the current Graph
889 DataFlowEditor()->IsValid() ;
890 // Set the Input Datas from the GraphMacroNode to the current Graph
891 aMacroGraph->SetMacroDatas( aGraph , aGraphOfMacroGraph ) ;
892 aMacroGraphDataFlowEditor->UnValid() ;
893 // Set the MacroNode ObjRef in the GraphMacroNode
894 aGraph->CoupledNode( aMacroGraph ) ;
895 aGraph->MacroObject( SUPERV::Graph::_duplicate( macroiobject ) ) ;
896 // Set the GraphMacroNode ObjRef in the MacroNode
897 aMacroGraph->CoupledNode( aGraph ) ;
898 aMacroGraph->MacroObject( SUPERV::Graph::_duplicate( iobject ) ) ;
899 // aDataFlowNode->CoupledNode( aGraph ) ;
900 // aDataFlowNode->ComputingNode()->MacroObject( SUPERV::Graph::_duplicate( iobject ) ) ;
901 // Set the MacroLevel of that graph
902 aGraph->GraphMacroLevel( aGraphOfMacroGraph->GraphMacroLevel() + 1 ) ;
903 aMacroGraph->Coordinates( 0 , 0 ) ;
904 MESSAGE( "DataFlowNode Graph " << this << " DataFlowEditor " << DataFlowEditor() << " aDataFlowNode "
905 << aDataFlowNode << " " << aDataFlowNode->Name() << " created" ) ;
908 delete aMacroGraphDataFlowEditor ;
911 endService( "Graph_Impl::MNode" );
912 return SUPERV::Graph::_duplicate( macroiobject ) ;
915 SUPERV::Graph_ptr Graph_Impl::GraphMNode( SUPERV::Graph_ptr myMacroGraph ) {
916 SUPERV::Graph_var iobject = myMacroGraph ;
917 beginService( "Graph_Impl::GraphMNode" ) ;
919 // GraphBase::Graph * myMacroGraph = aGraph;
920 SUPERV::Graph_var macroiobject = SUPERV::StreamGraph::_nil() ;
921 // Creation of a GraphMacroNode in the current editor
923 string aMacroNodeName = string( "Macro_" ) + string( myMacroGraph->Name() ) ;
924 MESSAGE( "GraphMNode( " << myMacroGraph->Name() << " )" ) ;
925 Graph_Impl * myMacroNode ;
926 myMacroNode = new Graph_Impl( _Orb , _Poa, _ContId,
927 instanceName() , interfaceName() ,
928 aMacroNodeName.c_str() , SUPERV::MacroNode ) ;
929 PortableServer::ObjectId * id = myMacroNode->getId() ;
930 CORBA::Object_var obj = _poa->id_to_reference(*id);
931 macroiobject = SUPERV::Graph::_narrow( obj ) ;
932 myMacroNode->DataFlowEditor( DataFlowEditor() ) ;
934 // Creation of the MacroNode itself in the current Graph
935 GraphBase::ListOfFuncName aFuncName ;
936 aFuncName.resize( 1 ) ;
938 SUPERV::ListOfStrings aListOfStrings ;
939 aListOfStrings.length( 1 ) ;
940 aListOfStrings[0] = "" ;
941 GraphBase::ListOfPythonFunctions aPythonFunction ;
942 aPythonFunction.resize( 1 ) ;
943 aPythonFunction[0] = &aListOfStrings ;
944 SALOME_ModuleCatalog::Service * aMacroNodeService = myMacroGraph->Service() ;
945 GraphEditor::InNode * aDataFlowNode = DataFlowEditor()->AddNode( *aMacroNodeService , "" , "" ,
946 aMacroNodeName.c_str() , SUPERV::MacroNode ,
947 aFuncName , aPythonFunction ) ;
948 aDataFlowNode->SetPythonFunction( "" , aListOfStrings ) ;
949 myMacroNode->DataFlowNode( aDataFlowNode ) ;
950 aDataFlowNode->ComputingNode()->SetService( *aMacroNodeService ) ;
951 aDataFlowNode->SetObjRef( SUPERV::CNode::_duplicate( SUPERV::CNode::_narrow( obj ) ) ) ;
952 aDataFlowNode->SetObjImpl( this ) ;
956 // GraphBase::Graph * aGraph = myMacroGraph->DataFlowEditor()->Graph() ;
957 GraphBase::Graph * aGraph = DataFlowEditor()->Automaton()->MapGraph( myMacroGraph->Name() ) ;
958 GraphBase::Graph * aGraphOfMacroGraph = myMacroNode->DataFlowEditor()->Graph() ;
959 GraphBase::Graph * aMacroGraph = myMacroNode->DataFlowNode()->GraphMacroNode() ;
960 aMacroGraph->Kind( SUPERV::MacroNode ) ;
961 aMacroGraph->SetGraphEditor( DataFlowEditor() ) ;
962 // Creation of the Ports of the MacroNode from the ports of the GraphMacroNode
963 aMacroGraph->SetMacroPorts( aGraph ) ;
964 // Valid ==> creation of Service and the ports of the current Graph
965 DataFlowEditor()->IsValid() ;
966 // Set the Input Datas from the GraphMacroNode to the current Graph
967 aMacroGraph->SetMacroDatas( aGraph , aGraphOfMacroGraph ) ;
968 // aMacroGraphDataFlowEditor->UnValid() ;
969 aGraph->GraphEditor()->UnValid() ;
970 // Set the MacroNode ObjRef in the GraphMacroNode
971 aGraph->CoupledNode( aMacroGraph ) ;
972 aGraph->MacroObject( SUPERV::Graph::_duplicate( macroiobject ) ) ;
973 // Set the GraphMacroNode ObjRef in the MacroNode
974 aMacroGraph->CoupledNode( aGraph ) ;
975 aMacroGraph->MacroObject( SUPERV::Graph::_duplicate( iobject ) ) ;
976 // aDataFlowNode->CoupledNode( aGraph ) ;
977 // aDataFlowNode->ComputingNode()->MacroObject( SUPERV::Graph::_duplicate( iobject ) ) ;
978 // Set the MacroLevel of that graph
979 aGraph->GraphMacroLevel( aGraphOfMacroGraph->GraphMacroLevel() + 1 ) ;
980 aMacroGraph->Coordinates( 0 , 0 ) ;
981 MESSAGE( aGraph->Name() << "->CoupledNode()->GraphEditor() : " << aGraph->CoupledNode()->GraphEditor() ) ;
982 MESSAGE( aMacroGraph->Name() << "->CoupledNode()->GraphEditor() : " << aMacroGraph->CoupledNode()->GraphEditor() ) ;
983 MESSAGE( "DataFlowNode Graph " << this << " DataFlowEditor " << DataFlowEditor() << " aDataFlowNode "
984 << aDataFlowNode << " " << aDataFlowNode->Name() << " created" ) ;
986 endService( "Graph_Impl::GraphMNode" ) ;
987 return SUPERV::Graph::_duplicate( macroiobject ) ;
990 SUPERV::Graph_ptr Graph_Impl::FlowObjRef() {
991 beginService( "Graph_Impl::FlowObjRef" );
992 SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
994 iobject = SUPERV::Graph::_narrow( DataFlowNode()->GraphMacroNode()->MacroObject() ) ;
996 else if ( IsGraph() ) {
997 iobject = SUPERV::Graph::_narrow( DataFlowEditor()->Graph()->MacroObject() ) ;
999 if ( CORBA::is_nil( iobject ) ) {
1000 MESSAGE( "Graph_Impl::FlowObjRef() returns a NIL Object" ) ;
1002 endService( "Graph_Impl::FlowObjRef" );
1003 return SUPERV::Graph::_duplicate( iobject ) ;
1006 SUPERV::StreamGraph_ptr Graph_Impl::StreamObjRef() {
1007 beginService( "Graph_Impl::StreamObjRef" );
1008 SUPERV::StreamGraph_var iobject = SUPERV::StreamGraph::_nil() ;
1010 iobject = SUPERV::StreamGraph::_narrow( DataFlowNode()->GraphMacroNode()->MacroObject() ) ;
1012 else if ( IsGraph() || IsStreamGraph() ) {
1013 iobject = SUPERV::StreamGraph::_narrow( DataFlowEditor()->Graph()->MacroObject() ) ;
1015 if ( CORBA::is_nil( iobject ) ) {
1016 MESSAGE( "Graph_Impl::StreamObjRef() returns a NIL Object" ) ;
1018 endService( "Graph_Impl::StreamObjRef" );
1019 return SUPERV::StreamGraph::_duplicate( iobject ) ;
1022 SUPERV::CNode_ptr Graph_Impl::Node(char const * aNodeName ) {
1023 // beginService( "Graph_Impl::Node" );
1024 SUPERV::CNode_var iobject = SUPERV::CNode::_nil() ;
1026 if ( CORBA::is_nil( DataFlowEditor()->GetNode( aNodeName )->ObjRef() ) ) {
1027 CNode_Impl * myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
1028 instanceName() , interfaceName() ,
1030 DataFlowEditor()->GetNode( aNodeName ) ) ;
1031 PortableServer::ObjectId * id = myNode->getId() ;
1032 CORBA::Object_var obj = _poa->id_to_reference(*id);
1033 iobject = SUPERV::CNode::_narrow(obj) ;
1034 myNode->SetObjRef( SUPERV::CNode::_duplicate( iobject ) ) ;
1037 iobject = DataFlowEditor()->GetNode( aNodeName )->ObjRef() ;
1040 GraphEditor::InNode * anInNode = DataFlowEditor()->GetNode( aNodeName ) ;
1042 if ( CORBA::is_nil( anInNode->ObjRef() ) ) {
1043 SetNodeObjRef( anInNode ) ;
1045 iobject = anInNode->ObjRef() ;
1048 // endService( "Graph_Impl::Node" );
1049 return SUPERV::CNode::_duplicate( iobject ) ;
1052 SUPERV::Link_ptr Graph_Impl::Link( SUPERV::Port_ptr OutPort ,
1053 SUPERV::Port_ptr InPort ) {
1054 beginService( "Graph_Impl::Link" );
1055 SUPERV::Link_var iobject = SUPERV::Link::_nil() ;
1056 if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() &&
1057 !OutPort->IsDataStream() && !InPort->IsDataStream() && !IsMacro() ) {
1058 GraphBase::InPort * anInPort = DataFlowEditor()->GetNode( InPort->Node()->Name() )->ComputingNode()->GetChangeInPort( InPort->Name() ) ;
1059 GraphBase::OutPort * anOutPort = DataFlowEditor()->GetNode( OutPort->Node()->Name() )->ComputingNode()->GetChangeOutPort( OutPort->Name() ) ;
1060 if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
1061 const char * DataFlowOutNodeName = OutPort->Node()->Name() ;
1062 GraphEditor::InNode * DataFlowOutNode = DataFlowEditor()->GetNode( DataFlowOutNodeName ) ;
1063 const char * DataFlowInNodeName = InPort->Node()->Name() ;
1064 GraphEditor::InNode * DataFlowInNode = DataFlowEditor()->GetNode( DataFlowInNodeName ) ;
1065 if ( DataFlowOutNode && DataFlowInNode ) {
1067 Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
1068 instanceName() , interfaceName() ,
1074 true , false , Success ) ;
1076 PortableServer::ObjectId * id = myLink->getId() ;
1077 CORBA::Object_var obj = _poa->id_to_reference(*id);
1078 iobject = SUPERV::Link::_narrow(obj) ;
1079 anOutPort->AddInPortObjRef( anInPort , SUPERV::Link::_duplicate( iobject ) ) ;
1084 iobject = anOutPort->InPortObjRef( anInPort ) ;
1087 endService( "Graph_Impl::Link" );
1088 return SUPERV::Link::_duplicate( iobject ) ;
1091 // Only to see MacroNodes with actual GUI ... :
1092 #define GOTOMacroNode 0
1094 void Graph_Impl::SetNodeObjRef( GraphEditor::InNode * anInNode ) {
1095 MESSAGE("Graph_Impl::SetNodeObjRef " << anInNode->Name() << " " << anInNode->Kind() ) ;
1096 CORBA::Object_var obj ;
1097 if ( anInNode->IsComputingNode() ) {
1098 CNode_Impl * myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
1099 instanceName() , interfaceName() ,
1102 PortableServer::ObjectId * id = myNode->getId() ;
1103 obj = _poa->id_to_reference(*id);
1104 SUPERV::CNode_var iobject = SUPERV::CNode::_narrow(obj) ;
1105 myNode->SetObjRef( SUPERV::CNode::_duplicate( iobject ) ) ;
1107 else if ( anInNode->IsFactoryNode() ) {
1108 FNode_Impl * myNode = new FNode_Impl( _Orb , _Poa , _ContId ,
1109 instanceName() , interfaceName() ,
1112 PortableServer::ObjectId * id = myNode->getId() ;
1113 obj = _poa->id_to_reference(*id);
1114 SUPERV::FNode_var iobject = SUPERV::FNode::_narrow(obj) ;
1115 myNode->SetObjRef( SUPERV::FNode::_duplicate( iobject ) ) ;
1117 else if ( anInNode->IsInLineNode() ) {
1118 INode_Impl * myNode = new INode_Impl( _Orb , _Poa , _ContId ,
1119 instanceName() , interfaceName() ,
1122 PortableServer::ObjectId * id = myNode->getId() ;
1123 obj = _poa->id_to_reference(*id);
1124 SUPERV::INode_var iobject = SUPERV::INode::_narrow(obj) ;
1125 myNode->SetObjRef( SUPERV::INode::_duplicate( iobject ) ) ;
1128 else if ( anInNode->IsGOTONode() || anInNode->IsMacroNode() ) {
1129 if ( anInNode->IsMacroNode() ) {
1130 anInNode->ComputingNode()->Kind( SUPERV::GOTONode ) ;
1133 else if ( anInNode->IsGOTONode() ) {
1135 GNode_Impl * myNode = new GNode_Impl( _Orb , _Poa , _ContId ,
1136 instanceName() , interfaceName() ,
1139 PortableServer::ObjectId * id = myNode->getId() ;
1140 obj = _poa->id_to_reference(*id);
1141 SUPERV::GNode_var iobject = SUPERV::GNode::_narrow(obj) ;
1142 myNode->SetObjRef( SUPERV::GNode::_duplicate( iobject ) ) ;
1144 else if ( anInNode->IsMacroNode() ) {
1145 Graph_Impl * myNode = new Graph_Impl( _Orb , _Poa , _ContId ,
1146 instanceName() , interfaceName() ,
1149 PortableServer::ObjectId * id = myNode->getId() ;
1150 obj = _poa->id_to_reference(*id);
1151 SUPERV::Graph_var iobject = SUPERV::Graph::_narrow(obj) ;
1152 myNode->SetObjRef( SUPERV::Graph::_duplicate( iobject ) ) ;
1154 else if ( anInNode->IsLoopNode() ) {
1155 LNode_Impl * myNode = new LNode_Impl( _Orb , _Poa , _ContId ,
1156 instanceName() , interfaceName() ,
1159 PortableServer::ObjectId * id = myNode->getId() ;
1160 obj = _poa->id_to_reference(*id);
1161 SUPERV::LNode_var iobject = SUPERV::LNode::_narrow(obj) ;
1162 myNode->SetObjRef( SUPERV::LNode::_duplicate( iobject ) ) ;
1164 else if ( anInNode->IsEndLoopNode() ) {
1165 ELNode_Impl * myNode = new ELNode_Impl( _Orb , _Poa , _ContId ,
1166 instanceName() , interfaceName() ,
1169 PortableServer::ObjectId * id = myNode->getId() ;
1170 obj = _poa->id_to_reference(*id);
1171 SUPERV::ELNode_var iobject = SUPERV::ELNode::_narrow(obj) ;
1172 myNode->SetObjRef( SUPERV::ELNode::_duplicate( iobject ) ) ;
1174 else if ( anInNode->IsSwitchNode() ) {
1175 SNode_Impl * myNode = new SNode_Impl( _Orb , _Poa , _ContId ,
1176 instanceName() , interfaceName() ,
1179 PortableServer::ObjectId * id = myNode->getId() ;
1180 obj = _poa->id_to_reference(*id);
1181 SUPERV::SNode_var iobject = SUPERV::SNode::_narrow(obj) ;
1182 myNode->SetObjRef( SUPERV::SNode::_duplicate( iobject ) ) ;
1184 else if ( anInNode->IsEndSwitchNode() ) {
1185 ESNode_Impl * myNode = new ESNode_Impl( _Orb , _Poa , _ContId ,
1186 instanceName() , interfaceName() ,
1189 PortableServer::ObjectId * id = myNode->getId() ;
1190 obj = _poa->id_to_reference(*id);
1191 SUPERV::ESNode_var iobject = SUPERV::ESNode::_narrow(obj) ;
1192 myNode->SetObjRef( SUPERV::ESNode::_duplicate( iobject ) ) ;
1196 SUPERV::ListOfNodes_var Graph_Impl::SetNode( SUPERV::ListOfNodes_var RetVal ,
1197 GraphBase::ComputingNode * aNode ) {
1199 // if ( _DataFlowExecutor ) {
1200 if ( DataFlowExecutor() ) {
1201 MESSAGE("Graph_Impl::SetNode " << aNode->Name() << " " << aNode->Kind() << " "
1202 << DataFlowExecutor()->StateName( DataFlowExecutor()->AutomatonState( aNode->Name() ) ) ) ;
1205 MESSAGE("Graph_Impl::SetNode " << aNode->Name() << " " << aNode->Kind() ) ;
1207 if ( aNode->IsComputingNode() ) {
1208 index = RetVal->CNodes.length() ;
1209 RetVal->CNodes.length( index+1 );
1211 else if ( aNode->IsFactoryNode() ) {
1212 index = RetVal->FNodes.length() ;
1213 RetVal->FNodes.length( index+1 );
1215 else if ( aNode->IsInLineNode() ) {
1216 index = RetVal->INodes.length() ;
1217 RetVal->INodes.length( index+1 );
1220 else if ( aNode->IsGOTONode() || aNode->IsMacroNode() ) {
1222 else if ( aNode->IsGOTONode() ) {
1224 index = RetVal->GNodes.length() ;
1225 RetVal->GNodes.length( index+1 );
1227 else if ( aNode->IsMacroNode() ) {
1228 index = RetVal->Graphs.length() ;
1229 RetVal->Graphs.length( index+1 );
1231 else if ( aNode->IsLoopNode() ) {
1232 index = RetVal->LNodes.length() ;
1233 RetVal->LNodes.length( index+1 );
1235 else if ( aNode->IsEndLoopNode() ) {
1236 index = RetVal->ELNodes.length() ;
1237 RetVal->ELNodes.length( index+1 );
1239 else if ( aNode->IsSwitchNode() ) {
1240 index = RetVal->SNodes.length() ;
1241 RetVal->SNodes.length( index+1 );
1243 else if ( aNode->IsEndSwitchNode() ) {
1244 index = RetVal->ESNodes.length() ;
1245 RetVal->ESNodes.length( index+1 );
1247 if ( CORBA::is_nil( aNode->ObjRef() ) ) {
1248 SetNodeObjRef( (GraphEditor::InNode * ) aNode->GetInNode() ) ;
1250 SUPERV::CNode_var aNodeObjRef = aNode->ObjRef() ;
1251 if ( aNode->IsComputingNode() ) {
1252 RetVal->CNodes[index] = SUPERV::CNode::_duplicate( aNodeObjRef ) ;
1254 else if ( aNode->IsFactoryNode() ) {
1255 RetVal->FNodes[index] = SUPERV::FNode::_duplicate( SUPERV::FNode::_narrow( aNodeObjRef ) ) ;
1257 else if ( aNode->IsInLineNode() ) {
1258 RetVal->INodes[index] = SUPERV::INode::_duplicate( SUPERV::INode::_narrow( aNodeObjRef ) ) ;
1261 else if ( aNode->IsGOTONode() || aNode->IsMacroNode() ) {
1263 else if ( aNode->IsGOTONode() ) {
1265 RetVal->GNodes[index] = SUPERV::GNode::_duplicate( SUPERV::GNode::_narrow( aNodeObjRef ) ) ;
1267 else if ( aNode->IsMacroNode() ) {
1268 RetVal->Graphs[index] = SUPERV::Graph::_duplicate( SUPERV::Graph::_narrow( aNodeObjRef ) ) ;
1270 else if ( aNode->IsLoopNode() ) {
1271 RetVal->LNodes[index] = SUPERV::LNode::_duplicate( SUPERV::LNode::_narrow( aNodeObjRef ) ) ;
1273 else if ( aNode->IsEndLoopNode() ) {
1274 RetVal->ELNodes[index] = SUPERV::ELNode::_duplicate( SUPERV::ELNode::_narrow( aNodeObjRef ) ) ;
1276 else if ( aNode->IsSwitchNode() ) {
1277 RetVal->SNodes[index] = SUPERV::SNode::_duplicate( SUPERV::SNode::_narrow( aNodeObjRef ) ) ;
1279 else if ( aNode->IsEndSwitchNode() ) {
1280 RetVal->ESNodes[index] = SUPERV::ESNode::_duplicate( SUPERV::ESNode::_narrow( aNodeObjRef ) ) ;
1282 return ( RetVal._retn() ) ;
1285 SUPERV::ListOfNodes * Graph_Impl::Nodes() {
1286 SUPERV::ListOfNodes_var RetVal = new SUPERV::ListOfNodes;
1287 beginService( "Graph_Impl::Nodes" );
1288 RetVal->CNodes.length(0) ;
1289 RetVal->FNodes.length(0) ;
1290 RetVal->INodes.length(0) ;
1291 RetVal->LNodes.length(0) ;
1292 RetVal->SNodes.length(0) ;
1293 RetVal->GNodes.length(0) ;
1294 RetVal->Graphs.length(0) ;
1297 for ( i = 0 ; i < DataFlowEditor()->Graph()->GraphNodesSize() ; i++ ) {
1298 GraphBase::ComputingNode * aNode = DataFlowEditor()->Graph()->GraphNodes( i ) ;
1299 RetVal = SetNode( RetVal , aNode ) ;
1302 char * aStateG = "" ;
1303 if ( DataFlowExecutor() ) {
1304 aStateG = (char *) DataFlowExecutor()->StateName( DataFlowExecutor()->AutomatonState() ) ;
1306 MESSAGE("Graph_Impl::Nodes GraphState " << aStateG << " CNodes " << RetVal->CNodes.length() ) ;
1307 for ( i = 0 ; i < RetVal->CNodes.length() ; i++ ) {
1308 MESSAGE(" " << RetVal->CNodes[ i ] ->Name() ) ;
1310 MESSAGE("FNodes " << RetVal->FNodes.length() ) ;
1311 for ( i = 0 ; i < RetVal->FNodes.length() ; i++ ) {
1312 MESSAGE(" " << RetVal->FNodes[ i ] ->Name() ) ;
1314 MESSAGE("INodes " << RetVal->INodes.length() ) ;
1315 for ( i = 0 ; i < RetVal->INodes.length() ; i++ ) {
1316 MESSAGE(" " << RetVal->INodes[ i ] ->Name() ) ;
1318 MESSAGE("GNodes " << RetVal->GNodes.length() ) ;
1319 for ( i = 0 ; i < RetVal->GNodes.length() ; i++ ) {
1320 MESSAGE(" " << RetVal->GNodes[ i ] ->Name() ) ;
1322 MESSAGE("LNodes " << RetVal->LNodes.length() ) ;
1323 for ( i = 0 ; i < RetVal->LNodes.length() ; i++ ) {
1324 MESSAGE(" " << RetVal->LNodes[ i ] ->Name() ) ;
1326 MESSAGE("ELNodes " << RetVal->ELNodes.length() ) ;
1327 for ( i = 0 ; i < RetVal->ELNodes.length() ; i++ ) {
1328 MESSAGE(" " << RetVal->ELNodes[ i ] ->Name() ) ;
1330 MESSAGE("SNodes " << RetVal->SNodes.length() ) ;
1331 for ( i = 0 ; i < RetVal->SNodes.length() ; i++ ) {
1332 MESSAGE(" " << RetVal->SNodes[ i ] ->Name() ) ;
1334 MESSAGE("ESNodes " << RetVal->ESNodes.length() ) ;
1335 for ( i = 0 ; i < RetVal->ESNodes.length() ; i++ ) {
1336 MESSAGE(" " << RetVal->ESNodes[ i ] ->Name() ) ;
1338 MESSAGE("Graphs " << RetVal->Graphs.length() ) ;
1339 for ( i = 0 ; i < RetVal->Graphs.length() ; i++ ) {
1340 MESSAGE(" " << RetVal->Graphs[ i ] ->Name() ) ;
1342 if ( DataFlowExecutor() ) {
1343 DataFlowExecutor()->EventList() ;
1347 endService( "Graph_Impl::Nodes" );
1348 return ( RetVal._retn() ) ;
1351 SUPERV::ListOfLinks * Graph_Impl::GLinks() {
1352 return Links( NULL , NULL ) ;
1355 SUPERV::ListOfLinks * Graph_Impl::Links( GraphBase::ComputingNode * theNode ,
1356 const char * anInputParam ) {
1358 SUPERV::ListOfLinks_var RetVal = new SUPERV::ListOfLinks ;
1359 RetVal->length( 0 ) ;
1361 int i , j , countlink ;
1363 for ( i = 0 ; i < DataFlowEditor()->Graph()->GraphNodesSize() ; i++ ) {
1364 GraphEditor::InNode * aNode = NULL ;
1365 aNode = (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GraphNodes( i )->GetInNode() ;
1366 bool ToProcess = false ;
1367 if ( theNode == NULL ) {
1371 if ( !strcmp( theNode->Name() , aNode->Name() ) ) {
1372 if ( !theNode->IsEndSwitchNode() ) {
1376 else if ( theNode->IsEndSwitchNode() ) {
1381 for ( j = 0 ; j < aNode->GetNodeInPortsSize() ; j++ ) {
1382 GraphBase::InPort * anInPort = NULL ;
1383 anInPort = aNode->GetChangeNodeInPort( j ) ;
1384 if ( anInputParam == NULL ||
1385 !strcmp( anInPort->PortName() , anInputParam ) ) {
1386 GraphBase::OutPort * anOutPort = NULL ;
1387 anOutPort = anInPort->GetOutPort() ;
1388 if ( anOutPort && !anOutPort->IsDataStream() ) {
1389 if ( strcmp( anOutPort->NodeName() , Name() ) ) {
1390 // MESSAGE("Graph_Impl::Links " << anOutPort->NodeName() << "("
1391 // << anOutPort->PortName() << ") --> " << aNode->Name() << "("
1392 // << anInPort->PortName() << ")" ) ;
1393 if ( theNode == NULL ||
1394 ( theNode != NULL && !theNode->IsEndSwitchNode() &&
1395 !strcmp( theNode->Name() , aNode->Name() ) ) ) {
1396 if ( anInPort->IsLoop() || anOutPort->IsLoop() ||
1397 ( aNode->IsEndLoopNode() && !strcmp( aNode->CoupledNode()->Name() ,
1398 anOutPort->NodeName() ) ) ) {
1399 // MESSAGE( "Link " << anOutPort->NodeName() << "("
1400 // << anOutPort->PortName() << ") --> " << aNode->Name() << "("
1401 // << anInPort->PortName() << ")" << " ignored" ) ;
1403 else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
1405 beginService( "Graph_Impl::Links" );
1408 GraphEditor::InNode * anOutNode = NULL ;
1409 anOutNode = (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GetChangeGraphNode( anOutPort->NodeName() )->GetInNode() ;
1412 Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
1413 instanceName() , interfaceName() ,
1416 anInPort->PortName() ,
1418 anOutPort->PortName() ,
1419 false , true , Success ) ;
1421 PortableServer::ObjectId * id = myLink->getId() ;
1422 CORBA::Object_var obj = _poa->id_to_reference(*id);
1423 SUPERV::Link_var iobject ;
1424 iobject = SUPERV::Link::_narrow(obj) ;
1425 RetVal->length( countlink + 1 ) ;
1426 RetVal[ countlink++ ] = SUPERV::Link::_duplicate( iobject ) ;
1427 anOutPort->AddInPortObjRef( anInPort , SUPERV::Link::_duplicate( iobject ) ) ;
1432 RetVal->length( countlink + 1 ) ;
1433 RetVal[ countlink++ ] = SUPERV::Link::_duplicate( anOutPort->InPortObjRef( anInPort ) ) ;
1435 // MESSAGE( "Link " << anOutPort->NodeName() << "("
1436 // << anOutPort->PortName() << ") --> " << aNode->Name() << "("
1437 // << anInPort->PortName() << ")" << " selected" ) ;
1440 // MESSAGE( "Link " << anOutPort->NodeName() << "("
1441 // << anOutPort->PortName() << ") --> " << aNode->Name() << "("
1442 // << anInPort->PortName() << ")" << " skipped" ) ;
1449 for ( j = 0 ; j < aNode->GetNodeOutPortsSize() ; j++ ) {
1450 GraphBase::OutPort * anOutPort = aNode->GetChangeNodeOutPort( j ) ;
1451 // MESSAGE( "Graph_Impl::Links " << aNode->Name() << " Out" << j << " " << anOutPort->PortName() << " "
1452 // << anOutPort->PortStatus() << " PortConnected to " << anOutPort->InPortsSize() << " InPorts" ) ;
1454 for ( k = 0 ; k < anOutPort->InPortsSize() ; k++ ) {
1455 GraphBase::InPort * anInPort = anOutPort->ChangeInPorts( k ) ;
1456 // MESSAGE( " --> In" << k << " " << anInPort->NodeName() << " " << anInPort->PortName()
1457 // << " " << anInPort->PortStatus() ) ;
1458 if ( !anInPort->IsExternConnected() ) {
1459 GraphEditor::InNode * toNode = (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GetChangeGraphNode( anInPort->NodeName() )->GetInNode() ;
1460 if ( theNode == NULL ||
1461 !strcmp( theNode->Name() , aNode->Name() ) ) {
1462 if ( !anInPort->IsDataStream() ) {
1463 if ( theNode || ( toNode->IsEndSwitchNode() && !aNode->IsSwitchNode() ) ) {
1464 if ( anInputParam == NULL ||
1465 !strcmp( anInPort->PortName() , anInputParam ) ) {
1466 if ( anInPort->IsLoop() || anOutPort->IsLoop() ||
1467 ( toNode->IsEndLoopNode() && !strcmp( toNode->CoupledNode()->Name() ,
1468 anOutPort->NodeName() ) ) ) {
1469 // MESSAGE( "Link " << anOutPort->NodeName() << "("
1470 // << anOutPort->PortName() << ") --> " << toNode->Name() << "("
1471 // << anInPort->PortName() << ")" << " ignored" ) ;
1473 else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
1475 beginService( "Graph_Impl::Links" );
1479 Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
1480 instanceName() , interfaceName() ,
1483 anInPort->PortName() ,
1485 anOutPort->PortName() ,
1486 false , true , Success ) ;
1488 PortableServer::ObjectId * id = myLink->getId() ;
1489 CORBA::Object_var obj = _poa->id_to_reference(*id);
1490 SUPERV::Link_var iobject ;
1491 iobject = SUPERV::Link::_narrow(obj) ;
1492 RetVal->length( countlink + 1 ) ;
1493 RetVal[ countlink++ ] = SUPERV::Link::_duplicate( iobject ) ;
1494 anOutPort->AddInPortObjRef( anInPort , SUPERV::Link::_duplicate( iobject ) ) ;
1498 RetVal->length( countlink + 1 ) ;
1499 RetVal[ countlink++ ] = SUPERV::Link::_duplicate( SUPERV::Link::_narrow( anOutPort->InPortObjRef( anInPort ) ) ) ;
1501 // MESSAGE( "Link " << anOutPort->NodeName() << "("
1502 // << anOutPort->PortName() << ") --> " << toNode->Name() << "("
1503 // << anInPort->PortName() << ")" << " selected" ) ;
1506 // MESSAGE( "Link " << anOutPort->NodeName() << "("
1507 // << anOutPort->PortName() << ") --> " << toNode->Name() << "("
1508 // << anInPort->PortName() << ")" << " skipped" ) ;
1519 const char * NodeName = "" ;
1520 const char * InputParamName = "" ;
1522 NodeName = theNode->Name() ;
1524 if ( anInputParam ) {
1525 InputParamName = anInputParam ;
1527 MESSAGE( RetVal->length() << " Links of Node " << NodeName << " and of InPort " << InputParamName ) ;
1528 for ( i = 0 ; i < (int ) RetVal->length() ; i++ ) {
1529 MESSAGE( "Link " << RetVal[i]->OutPort()->Node()->Name() << "("
1530 << RetVal[i]->OutPort()->Name() << ") --> "
1531 << RetVal[i]->InPort()->Node()->Name() << "("
1532 << RetVal[i]->InPort()->Name() << ")" ) ;
1536 endService( "Graph_Impl::Links" );
1539 return ( RetVal._retn() ) ;
1542 Engines::Component_ptr Graph_Impl::ComponentRef( const char * aComputerContainer ,
1543 const char * aComponentName ) {
1544 Engines::Component_var objComponent = Engines::Component::_nil() ;
1546 Engines::Container_var myContainer ;
1547 DataFlowEditor()->Graph()->StartComponent( 0 , aComputerContainer , aComponentName ,
1548 myContainer , objComponent ) ;
1550 return Engines::Component::_duplicate( objComponent ) ;
1553 bool Graph_Impl::IsValid() {
1554 // beginService( "Graph_Impl::IsValid" );
1555 bool RetVal = false ;
1557 RetVal = DataFlowEditor()->IsValid() ;
1559 // endService( "Graph_Impl::IsValid" );
1562 bool Graph_Impl::IsExecutable() {
1563 // beginService( "Graph_Impl::IsExecutable" );
1564 bool RetVal = false ;
1566 RetVal = DataFlowEditor()->IsExecutable() ;
1568 // endService( "Graph_Impl::IsExecutable" );
1572 bool Graph_Impl::IsEditing() {
1573 // beginService( "Graph_Impl::IsEditing" );
1574 bool RetVal = false ;
1576 RetVal = DataFlowEditor()->IsEditing() ;
1578 // endService( "Graph_Impl::IsEditing" );
1581 bool Graph_Impl::IsExecuting() {
1582 // beginService( "Graph_Impl::IsExecuting" );
1583 bool RetVal = false ;
1585 RetVal = !DataFlowEditor()->IsEditing() ;
1587 // endService( "Graph_Impl::IsExecuting" );
1591 bool Graph_Impl::IsReadOnly() {
1592 // beginService( "Graph_Impl::IsExecuting" );
1593 bool RetVal = false ;
1595 RetVal = DataFlowEditor()->IsReadOnly() ;
1597 // endService( "Graph_Impl::IsExecuting" );
1601 long Graph_Impl::LevelMax() {
1602 // beginService( "Graph_Impl::LevelMax" );
1605 RetVal = DataFlowEditor()->LevelMax() ;
1607 // endService( "Graph_Impl::LevelMax" );
1610 SUPERV::ListOfNodes * Graph_Impl::LevelNodes(long aLevel ) {
1611 // beginService( "Graph_Impl::LevelNodes" );
1612 SUPERV::ListOfNodes_var RetVal = new SUPERV::ListOfNodes;
1615 SUPERV::ListOfStrings_var Nodes = DataFlowEditor()->LevelNodes( aLevel ) ;
1616 // RetVal->length( Nodes->length() );
1617 for ( i = 0 ; i < (int ) Nodes->length() ; i++ ) {
1618 // char * aNode = Nodes[ i ] ;
1619 GraphBase::ComputingNode * aNode = DataFlowEditor()->Graph()->GetChangeGraphNode( Nodes[ i ] ) ;
1620 RetVal = SetNode( RetVal , aNode ) ;
1621 // cout << "Graph_Impl::LevelNodes( " << aLevel << " ) " << aNode->Name() << endl ;
1622 // CNode_Impl * myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
1623 // instanceName() , interfaceName() ,
1624 // DataFlowEditor() ,
1625 // (GraphEditor::InNode * ) DataFlowEditor()->GetChangeGraphNode( aNode )->GetInNode() ) ;
1626 // PortableServer::ObjectId * id = myNode->getId() ;
1627 // CORBA::Object_var obj = _poa->id_to_reference(*id);
1628 // SUPERV::CNode_var iobject ;
1629 // iobject = SUPERV::CNode::_narrow(obj) ;
1630 // RetVal[i] = SUPERV::CNode::_duplicate( iobject ) ;
1633 // endService( "Graph_Impl::LevelNodes" );
1634 return ( RetVal._retn() ) ;
1636 long Graph_Impl::ThreadsMax() {
1637 // beginService( "Graph_Impl::ThreadsMax" );
1640 RetVal = DataFlowEditor()->ThreadsMax() ;
1642 // endService( "Graph_Impl::ThreadsMax" );
1645 long Graph_Impl::Threads() {
1646 // beginService( "Node_Impl::Threads" );
1647 long RetVal = false ;
1649 RetVal = DataFlowExecutor()->Threads() ;
1651 // endService( "Node_Impl::Threads" );
1654 long Graph_Impl::SuspendedThreads() {
1655 // beginService( "Node_Impl::SuspendedThreads" );
1656 long RetVal = false ;
1658 RetVal = DataFlowExecutor()->SuspendedThreads() ;
1660 // endService( "Node_Impl::SuspendedThreads" );
1664 bool Graph_Impl::Begin() {
1665 bool RetVal = false ;
1666 if ( DataFlowEditor()->IsEditing() ) {
1667 if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1668 perror("pthread_mutex_lock _MutexExecutorWait") ;
1671 if ( DataFlowExecutor() ) {
1672 MESSAGE( "Graph_Impl::Begin " << DataFlowExecutor()->Threads() << " threads" )
1673 if ( DataFlowExecutor()->Threads() ) {
1674 DataFlowExecutor()->JoinedWait() ;
1676 delete DataFlowExecutor() ;
1677 DataFlowExecutor( NULL ) ;
1678 DataFlowEditor()->Executor( NULL ) ;
1680 if ( DataFlowEditor()->IsExecutable() ) {
1681 DataFlowEditor()->EditedAfterExecution( false ) ;
1682 int _ExecNumber = theAutomaton->ExecNumber() ;
1683 char ExecNumber[30] ;
1684 sprintf( ExecNumber , "_%d" , _ExecNumber ) ;
1685 int len = strlen( _DebugFileName ) ;
1686 char * DebugFileName = new char [ len + strlen( ExecNumber ) + 6 ] ;
1687 strncpy( DebugFileName , _DebugFileName , len - 4 ) ;
1688 DebugFileName[ len - 4 ] = '\0' ;
1689 strcat( DebugFileName , ExecNumber ) ;
1690 strcat( DebugFileName , "_Exec.log" ) ;
1691 GraphExecutor::DataFlow * aDataFlowExecutor ;
1692 GraphBase::ListOfSGraphs * myListOfGraphs = DataFlowEditor()->GetDataFlows() ;
1694 for ( i = 0 ; i < (int ) myListOfGraphs->size() ; i++ ) {
1695 GraphEditor::DataFlow * aDataFlowEditor ;
1696 aDataFlowEditor = theAutomaton->MapGraph( (*myListOfGraphs)[ i ].Info.theName.c_str() )->GraphEditor() ;
1697 MESSAGE("myListOfGraphs" << i << " " << (*myListOfGraphs)[ i ].Info.theName.c_str() << " "
1698 << aDataFlowEditor << " IsEditing " << aDataFlowEditor->IsEditing() ) ;
1701 aDataFlowExecutor = new GraphExecutor::DataFlow( _Orb , _NamingService ,
1702 (*myListOfGraphs)[ 0 ].Info.theName.c_str() ,
1703 DebugFileName , Kind() ) ;
1704 DataFlowExecutor( aDataFlowExecutor ) ;
1705 MESSAGE( "Graph_Impl::Begin : DataFlowExecutor created" );
1706 RetVal = LoadDataFlows( DataFlowExecutor() , myListOfGraphs , 0 ) ;
1708 DataFlowExecutor()->Graph()->SetObjImpl( DataFlowEditor()->Graph()->ObjImpl() ) ;
1709 DataFlowEditor()->Executor( DataFlowExecutor() ) ;
1712 if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1713 perror("pthread_mutex_unlock _MutexExecutorWait") ;
1719 bool Graph_Impl::Run() {
1720 beginService( "Graph_Impl::Run" );
1721 bool RetVal = false ;
1722 if ( DataFlowEditor()->IsEditing() && !IsMacro() ) {
1723 MESSAGE( "Graph_Impl::Run " << DataFlowEditor()->Graph()->Name() << " " << DataFlowEditor() << " IsEditing" );
1724 if ( DataFlowEditor()->Graph()->GraphMacroLevel() ) {
1725 MESSAGE( "Graph_Impl::Run " << DataFlowEditor()->Graph()->Name() << " GraphMacroLevel "
1726 << DataFlowEditor()->Graph()->GraphMacroLevel() ) ;
1730 MESSAGE( "Graph_Impl::Run " << DataFlowEditor()->Graph()->Name() << " GraphMacroLevel "
1731 << DataFlowEditor()->Graph()->GraphMacroLevel() << " --> Begin()" ) ;
1735 MESSAGE( "Graph_Impl::Run " );
1736 DataFlowEditor()->Executing() ;
1737 RetVal = CNode_Impl::Run() ;
1740 else if ( !IsMacro() ) {
1741 MESSAGE( "Graph_Impl::Run " << DataFlowEditor()->Graph()->Name() << " " << DataFlowEditor()
1742 << " IsNOTEditing --> CNode_Impl::ReRun" );
1743 DataFlowEditor()->Executing() ;
1744 RetVal = CNode_Impl::ReRun() ;
1746 endService( "Graph_Impl::Run" );
1749 bool Graph_Impl::Start() {
1750 beginService( "Graph_Impl::Start" );
1751 bool RetVal = false ;
1753 if ( DataFlowEditor()->IsEditing() ) {
1754 MESSAGE( "Graph_Impl::Start IsEditing" );
1761 MESSAGE( "Graph_Impl::(Re)Start " );
1762 // Added by NKV to fix PAL6222 --> to be confirm by JR
1763 DataFlowEditor()->Executing() ;
1764 // End of NKV's correction
1765 RetVal = ReStart() ;
1768 endService( "Graph_Impl::Start" );
1772 bool Graph_Impl::EventNoW( SUPERV::CNode_out aNode ,
1773 SUPERV::GraphEvent & anEvent ,
1774 SUPERV::GraphState & aState ) {
1775 bool RetVal = false ;
1776 char * aNodeName = NULL ;
1777 SUPERV::GraphEvent theEvent = SUPERV::UndefinedEvent ;
1778 SUPERV::GraphState theState = SUPERV::UndefinedState ;
1779 if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1780 perror("pthread_mutex_lock _MutexExecutorWait") ;
1783 if ( DataFlowExecutor() && !IsMacro() &&
1784 ( DataFlowExecutor()->GetListSize() || !DataFlowEditor()->IsEditing() ) ) {
1785 RetVal = DataFlowExecutor()->Event( & aNodeName , theEvent , theState , false ) ;
1786 // endService( "Graph_Impl::Event" );
1787 if ( strlen( aNodeName ) ) {
1788 if ( strcmp( aNodeName , Name() ) ) {
1789 aNode = Node( aNodeName ) ;
1796 aNode = SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
1798 // cout << "Graph_Impl::EventNoW " << aNode->Name() << " QSize " << DataFlowExecutor()->GetListSize() << endl ;
1801 // cout << "Graph_Impl::EventNoW NO DataFlowExecutor() or QSize=0 " << endl ;
1803 if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1804 perror("pthread_mutex_unlock _MutexExecutorWait") ;
1807 anEvent = theEvent ;
1812 bool Graph_Impl::Event( SUPERV::CNode_out aNode ,
1813 SUPERV::GraphEvent & anEvent ,
1814 SUPERV::GraphState & aState ) {
1815 // beginService( "Graph_Impl::Event" );
1816 bool RetVal = false ;
1817 char * aNodeName = NULL ;
1818 SUPERV::GraphEvent theEvent = SUPERV::UndefinedEvent ;
1819 SUPERV::GraphState theState = SUPERV::UndefinedState ;
1820 if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1821 perror("pthread_mutex_lock _MutexExecutorWait") ;
1824 if ( DataFlowExecutor() && !IsMacro() &&
1825 ( DataFlowExecutor()->GetListSize() || !DataFlowEditor()->IsEditing() ) ){
1826 RetVal = DataFlowExecutor()->Event( & aNodeName , theEvent , theState ) ;
1827 // endService( "Graph_Impl::Event" );
1828 if ( strlen( aNodeName ) ) {
1829 if ( strcmp( aNodeName , Name() ) ) {
1830 aNode = Node( aNodeName ) ;
1837 aNode = SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
1839 // cout << "Graph_Impl::Event " << aNode->Name() << " QSize " << DataFlowExecutor()->GetListSize() << endl ;
1842 // cout << "Graph_Impl::Event NO DataFlowExecutor() or QSize=0 " << endl ;
1844 if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1845 perror("pthread_mutex_unlock _MutexExecutorWait") ;
1848 anEvent = theEvent ;
1853 bool Graph_Impl::EventW( SUPERV::CNode_out aNode ,
1854 SUPERV::GraphEvent & anEvent ,
1855 SUPERV::GraphState & aState ) {
1856 // beginService( "Graph_Impl::EventW" );
1857 bool RetVal = false ;
1858 char * aNodeName = NULL ;
1859 SUPERV::GraphEvent theEvent = SUPERV::UndefinedEvent ;
1860 SUPERV::GraphState theState = SUPERV::UndefinedState ;
1861 if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1862 perror("pthread_mutex_lock _MutexExecutorWait") ;
1865 if ( DataFlowExecutor() && !IsMacro() &&
1866 ( DataFlowExecutor()->GetListSize() || !DataFlowEditor()->IsEditing() ) ) {
1867 RetVal = DataFlowExecutor()->EventW( & aNodeName , theEvent , theState ) ;
1868 if ( RetVal && strcmp( aNodeName , Name() ) ) {
1869 aNode = Node( aNodeName ) ;
1875 if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1876 perror("pthread_mutex_unlock _MutexExecutorWait") ;
1879 anEvent = theEvent ;
1881 // endService( "Graph_Impl::EventW" );
1885 long Graph_Impl::EventQSize() {
1886 // beginService( "Graph_Impl::EventQSize" );
1888 if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1889 perror("pthread_mutex_lock _MutexExecutorWait") ;
1892 if ( DataFlowExecutor() && !IsMacro() ) {
1893 QSize = DataFlowExecutor()->EventQSize() ;
1895 if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1896 perror("pthread_mutex_unlock _MutexExecutorWait") ;
1899 // endService( "Graph_Impl::EventQSize" );
1903 long Graph_Impl::LastLevelDone() {
1904 // beginService( "Graph_Impl::LastLevelDone" );
1905 if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1906 perror("pthread_mutex_lock _MutexExecutorWait") ;
1910 if ( DataFlowExecutor() && !IsMacro() ) {
1911 RetVal = DataFlowExecutor()->LastLevelDone() ;
1913 if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1914 perror("pthread_mutex_unlock _MutexExecutorWait") ;
1917 // endService( "Graph_Impl::LastLevelDone" );
1921 long Graph_Impl::SubGraphsNumber() {
1922 // beginService( "Graph_Impl::SubGraphsNumber" );
1924 if ( DataFlowEditor()->IsExecutable() && !IsMacro() ) {
1925 RetVal = DataFlowEditor()->SubGraphsNumber() ;
1927 // endService( "Graph_Impl::SubGraphsNumber" );
1931 SUPERV::ListOfNodes * Graph_Impl::SubGraphsNodes( const long aSubGraphNumber ) {
1932 beginService( "Graph_Impl::SubGraphsNodes" );
1933 SUPERV::ListOfNodes_var RetVal = new SUPERV::ListOfNodes ;
1934 if ( DataFlowEditor()->IsEditing() && !IsMacro() ) {
1935 SUPERV::ListOfNodes * aGraphNodes = Nodes() ;
1938 for ( i = 0 ; i < (int ) aGraphNodes->CNodes.length() ; i++ ) {
1939 SUPERV::CNode_var aNode = (aGraphNodes->CNodes)[ i ] ;
1940 if ( aNode->SubGraph() == aSubGraphNumber ) {
1941 RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
1945 for ( i = 0 ; i < (int ) aGraphNodes->FNodes.length() ; i++ ) {
1946 SUPERV::FNode_var aNode = (aGraphNodes->FNodes)[ i ] ;
1947 if ( aNode->SubGraph() == aSubGraphNumber ) {
1948 RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
1952 for ( i = 0 ; i < (int ) aGraphNodes->INodes.length() ; i++ ) {
1953 SUPERV::INode_var aNode = (aGraphNodes->INodes)[ i ] ;
1954 if ( aNode->SubGraph() == aSubGraphNumber ) {
1955 RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
1959 for ( i = 0 ; i < (int ) aGraphNodes->GNodes.length() ; i++ ) {
1960 SUPERV::GNode_var aNode = (aGraphNodes->GNodes)[ i ] ;
1961 if ( aNode->SubGraph() == aSubGraphNumber ) {
1962 RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
1966 for ( i = 0 ; i < (int ) aGraphNodes->LNodes.length() ; i++ ) {
1967 SUPERV::LNode_var aNode = (aGraphNodes->LNodes)[ i ] ;
1968 if ( aNode->SubGraph() == aSubGraphNumber ) {
1969 RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
1973 for ( i = 0 ; i < (int ) aGraphNodes->ELNodes.length() ; i++ ) {
1974 SUPERV::ELNode_var aNode = (aGraphNodes->ELNodes)[ i ] ;
1975 if ( aNode->SubGraph() == aSubGraphNumber ) {
1976 RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
1980 for ( i = 0 ; i < (int ) aGraphNodes->SNodes.length() ; i++ ) {
1981 SUPERV::SNode_var aNode = (aGraphNodes->SNodes)[ i ] ;
1982 if ( aNode->SubGraph() == aSubGraphNumber ) {
1983 RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
1987 for ( i = 0 ; i < (int ) aGraphNodes->ESNodes.length() ; i++ ) {
1988 SUPERV::ESNode_var aNode = (aGraphNodes->ESNodes)[ i ] ;
1989 if ( aNode->SubGraph() == aSubGraphNumber ) {
1990 RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
1994 endService( "Graph_Impl::SubGraphsNodes" );
1995 return ( RetVal._retn() ) ;
1998 bool Graph_Impl::Merge(const SUPERV::Graph_ptr aGraph ) {
1999 // beginService( "Graph_Impl::Merge" );
2000 bool RetVal = true ;
2002 map< string , int > aMapOfNodes ;
2003 RetVal = Merge( aGraph , aMapOfNodes ) ;
2005 // endService( "Graph_Impl::Merge" );
2009 bool Graph_Impl::Merge(const SUPERV::Graph_ptr aGraph , map< string , int > & aMapOfNodes ) {
2010 beginService( "Graph_Impl::Merge" );
2011 bool RetVal = true ;
2012 if ( DataFlowEditor()->IsEditing() && !IsMacro() ) {
2013 SUPERV::ListOfNodes * aGraphNodes = aGraph->Nodes() ;
2015 SUPERV::Port_ptr aPort ;
2016 // SUPERV::StreamPort_ptr aStreamPort ;
2018 for ( i = 0 ; i < (int ) aGraphNodes->CNodes.length() ; i++ ) {
2019 SUPERV::CNode_var aNode = (aGraphNodes->CNodes)[ i ] ;
2020 SUPERV::CNode_ptr myNode = CNode( *(aNode->Service()) ) ;
2021 if ( !CORBA::is_nil( myNode ) ) {
2022 myNode->SetName( aNode->Name() ) ;
2023 myNode->SetAuthor( aNode->Author() ) ;
2024 myNode->SetComment( aNode->Comment() ) ;
2025 myNode->Coords( aNode->X() , aNode->Y() ) ;
2026 string * aNodetheName = new string( aNode->Name() ) ;
2027 aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
2028 delete aNodetheName ;
2035 // The following informations are now in the service from SALOME_ModuleCatalog
2036 // SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
2038 // for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
2039 // if ( myStreamPorts[ j ]->IsInput() && myStreamPorts[ j ]->IsDataStream() ) {
2040 // aStreamPort = myNode->InStreamPort( myStreamPorts[ j ]->Name() , myStreamPorts[ j ]->Type() ) ;
2042 // else if ( myStreamPorts[ j ]->IsDataStream() ) {
2043 // aStreamPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name() , myStreamPorts[ j ]->Type() ) ;
2049 for ( i = 0 ; i < (int ) aGraphNodes->FNodes.length() ; i++ ) {
2050 SUPERV::FNode_var aNode = (aGraphNodes->FNodes)[ i ] ;
2051 SUPERV::FNode_ptr myNode = FNode( aNode->GetComponentName() ,
2052 aNode->GetInterfaceName() ,
2053 *(aNode->Service()) ) ;
2054 if ( !CORBA::is_nil( myNode ) ) {
2055 myNode->SetName( aNode->Name() ) ;
2056 myNode->SetAuthor( aNode->Author() ) ;
2057 myNode->SetComment( aNode->Comment() ) ;
2058 myNode->Coords( aNode->X() , aNode->Y() ) ;
2059 string * aNodetheName = new string( aNode->Name() ) ;
2060 aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
2061 delete aNodetheName ;
2068 // The following informations are now in the service from SALOME_ModuleCatalog
2069 // SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
2071 // for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
2072 // if ( myStreamPorts[ j ]->IsInput() && myStreamPorts[ j ]->IsDataStream() ) {
2073 // aStreamPort = myNode->InStreamPort( myStreamPorts[ j ]->Name() , myStreamPorts[ j ]->Type() ) ;
2075 // else if ( myStreamPorts[ j ]->IsDataStream() ) {
2076 // aStreamPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name() , myStreamPorts[ j ]->Type() ) ;
2083 for ( i = 0 ; i < (int ) aGraphNodes->INodes.length() ; i++ ) {
2084 SUPERV::INode_var aNode = (aGraphNodes->INodes)[ i ] ;
2085 SUPERV::INode_ptr myNode = INode( aNode->PyFuncName() , *(aNode->PyFunction()) ) ;
2086 if ( !CORBA::is_nil( myNode ) ) {
2087 myNode->SetName( aNode->Name() ) ;
2088 myNode->SetAuthor( aNode->Author() ) ;
2089 myNode->SetComment( aNode->Comment() ) ;
2090 myNode->Coords( aNode->X() , aNode->Y() ) ;
2091 string * aNodetheName = new string( aNode->Name() ) ;
2092 aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
2093 delete aNodetheName ;
2094 SUPERV::ListOfPorts myPorts = *(aNode->Ports()) ;
2096 for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
2097 if ( myPorts[ j ]->IsInput() ) {
2098 aPort = myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2101 aPort = myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2104 if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
2105 SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
2106 for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
2107 if ( myStreamPorts[ j ]->IsInput() ) {
2108 aPort = myNode->InStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
2111 aPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
2125 for ( i = 0 ; i < (int ) aGraphNodes->GNodes.length() ; i++ ) {
2126 SUPERV::GNode_var aNode = (aGraphNodes->GNodes)[ i ] ;
2127 SUPERV::GNode_ptr myNode = GNode( aNode->PyFuncName() , *(aNode->PyFunction()) , aNode->Coupled()->Name() ) ;
2128 if ( !CORBA::is_nil( myNode ) ) {
2129 myNode->SetName( aNode->Name() ) ;
2130 myNode->SetAuthor( aNode->Author() ) ;
2131 myNode->SetComment( aNode->Comment() ) ;
2132 myNode->Coords( aNode->X() , aNode->Y() ) ;
2133 string * aNodetheName = new string( aNode->Name() ) ;
2134 aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
2135 delete aNodetheName ;
2136 SUPERV::ListOfPorts myPorts = *(aNode->Ports()) ;
2138 for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
2139 if ( myPorts[ j ]->IsInput() ) {
2140 aPort = myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2143 aPort = myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2146 if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
2147 SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
2148 for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
2149 if ( myStreamPorts[ j ]->IsInput() ) {
2150 aPort = myNode->InStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
2153 aPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
2167 for ( i = 0 ; i < (int ) aGraphNodes->LNodes.length() ; i++ ) {
2168 SUPERV::LNode_var aNode = (aGraphNodes->LNodes)[ i ] ;
2169 SUPERV::INode_ptr anEndOfLoop ;
2170 SUPERV::LNode_ptr myNode = LNode( aNode->PyInitName() ,
2171 *(aNode->PyInit()) ,
2172 aNode->PyMoreName() ,
2173 *(aNode->PyMore()) ,
2174 aNode->PyNextName() ,
2175 *(aNode->PyNext()) ,
2177 if ( !CORBA::is_nil( myNode ) ) {
2178 myNode->SetName( aNode->Name() ) ;
2179 myNode->SetAuthor( aNode->Author() ) ;
2180 myNode->SetComment( aNode->Comment() ) ;
2181 myNode->Coords( aNode->X() , aNode->Y() ) ;
2182 string * aNodetheName = new string( aNode->Name() ) ;
2183 aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
2184 delete aNodetheName ;
2185 SUPERV::ListOfPorts myPorts = *(aNode->Ports()) ;
2187 for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
2188 if ( myPorts[ j ]->IsInput() ) {
2189 aPort = myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2192 aPort = myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2195 if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
2196 SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
2197 for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
2198 if ( myStreamPorts[ j ]->IsInput() ) {
2199 aPort = myNode->InStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
2202 aPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
2206 SUPERV::INode_ptr myEndOfLoop = aNode->Coupled() ;
2207 anEndOfLoop->SetName( myEndOfLoop->Name() ) ;
2208 anEndOfLoop->SetAuthor( myEndOfLoop->Author() ) ;
2209 anEndOfLoop->SetComment( myEndOfLoop->Comment() ) ;
2210 anEndOfLoop->Coords( myEndOfLoop->X() , myEndOfLoop->Y() ) ;
2211 anEndOfLoop->SetPyFunction( myEndOfLoop->PyFuncName() , *(myEndOfLoop->PyFunction()) ) ;
2212 aNodetheName = new string( myEndOfLoop->Name() ) ;
2213 aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( anEndOfLoop->Name() ) ;
2214 if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
2215 SUPERV::ListOfStreamPorts myStreamLoopPorts = *(myEndOfLoop->StreamPorts()) ;
2216 for ( j = 0 ; j < (int ) myStreamLoopPorts.length() ; j++ ) {
2217 if ( myStreamLoopPorts[ j ]->IsInput() ) {
2218 aPort = myNode->InStreamPort( myStreamLoopPorts[ j ]->Name() , StringToDataStreamType( myStreamLoopPorts[ j ]->Type() ) , myStreamLoopPorts[ j ]->Dependency() ) ;
2221 aPort = myNode->OutStreamPort( myStreamLoopPorts[ j ]->Name() , StringToDataStreamType( myStreamLoopPorts[ j ]->Type() ) , myStreamLoopPorts[ j ]->Dependency() ) ;
2225 delete aNodetheName ;
2236 for ( i = 0 ; i < (int ) aGraphNodes->SNodes.length() ; i++ ) {
2237 SUPERV::SNode_var aNode = (aGraphNodes->SNodes)[ i ] ;
2238 SUPERV::INode_ptr anEndOfSwitch ;
2239 SUPERV::SNode_ptr myNode = SNode( aNode->PyFuncName() , *(aNode->PyFunction()) , anEndOfSwitch ) ;
2240 if ( !CORBA::is_nil( myNode ) ) {
2241 myNode->SetName( aNode->Name() ) ;
2242 myNode->SetAuthor( aNode->Author() ) ;
2243 myNode->SetComment( aNode->Comment() ) ;
2244 myNode->Coords( aNode->X() , aNode->Y() ) ;
2245 string * aNodetheName = new string( aNode->Name() ) ;
2246 aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( myNode->Name() ) ;
2247 delete aNodetheName ;
2248 SUPERV::ListOfPorts myPorts = *(aNode->Ports()) ;
2250 for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
2251 if ( myPorts[ j ]->IsInput() ) {
2252 aPort = myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2255 aPort = myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2258 if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
2259 SUPERV::ListOfStreamPorts myStreamPorts = *(aNode->StreamPorts()) ;
2260 for ( j = 0 ; j < (int ) myStreamPorts.length() ; j++ ) {
2261 if ( myStreamPorts[ j ]->IsInput() ) {
2262 aPort = myNode->InStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
2265 aPort = myNode->OutStreamPort( myStreamPorts[ j ]->Name() , StringToDataStreamType( myStreamPorts[ j ]->Type() ) , myStreamPorts[ j ]->Dependency() ) ;
2269 SUPERV::INode_ptr myEndOfSwitch = aNode->Coupled() ;
2270 anEndOfSwitch->SetName( myEndOfSwitch->Name() ) ;
2271 anEndOfSwitch->SetAuthor( myEndOfSwitch->Author() ) ;
2272 anEndOfSwitch->SetComment( myEndOfSwitch->Comment() ) ;
2273 anEndOfSwitch->Coords( myEndOfSwitch->X() , myEndOfSwitch->Y() ) ;
2274 anEndOfSwitch->SetPyFunction( myEndOfSwitch->PyFuncName() , *(myEndOfSwitch->PyFunction()) ) ;
2275 aNodetheName = new string( myEndOfSwitch->Name() ) ;
2276 aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->Graph()->GetGraphNodeIndex( anEndOfSwitch->Name() ) ;
2277 delete aNodetheName ;
2278 myPorts = *(myEndOfSwitch->Ports()) ;
2279 for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
2280 if ( myPorts[ j ]->IsInput() ) {
2281 aPort = myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2284 aPort = myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
2287 if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
2288 SUPERV::ListOfStreamPorts myStreamSwitchPorts = *(myEndOfSwitch->StreamPorts()) ;
2289 for ( j = 0 ; j < (int ) myStreamSwitchPorts.length() ; j++ ) {
2290 if ( myStreamSwitchPorts[ j ]->IsInput() ) {
2291 aPort = myNode->InStreamPort( myStreamSwitchPorts[ j ]->Name() , StringToDataStreamType( myStreamSwitchPorts[ j ]->Type() ) , myStreamSwitchPorts[ j ]->Dependency() ) ;
2294 aPort = myNode->OutStreamPort( myStreamSwitchPorts[ j ]->Name() , StringToDataStreamType( myStreamSwitchPorts[ j ]->Type() ) , myStreamSwitchPorts[ j ]->Dependency() ) ;
2307 SUPERV::ListOfLinks * aGraphLinks = aGraph->GLinks() ;
2308 SUPERV::ListOfPorts * aGraphPorts = aGraph->Ports() ;
2309 // cout << "Graph_Impl::Merge " << aGraphLinks->length() << " links " << aGraphPorts->length() << " GraphPorts"
2311 for ( i = 0 ; i < (int ) aGraphLinks->length() ; i++ ) {
2312 SUPERV::Link_var aLink = (*aGraphLinks)[ i ] ;
2313 SUPERV::Port_var OutPort = aLink->OutPort() ;
2314 SUPERV::Port_var InPort = aLink->InPort() ;
2315 string * aLinkFromNodeName = new string( OutPort->Node()->Name() ) ;
2316 string * aLinkToNodeName = new string( InPort->Node()->Name() ) ;
2317 RetVal = DataFlowEditor()->AddLink( DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] )->Name() ,
2319 DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] )->Name() ,
2323 for ( j = 1 ; j <= aLink->CoordsSize() ; j++ ) {
2325 RetVal = aLink->Coords( j , X , Y ) ;
2328 RetVal = DataFlowEditor()->AddLinkCoord( DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] )->Name() ,
2330 DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] )->Name() ,
2338 delete aLinkFromNodeName ;
2339 delete aLinkToNodeName ;
2345 for ( i = 0 ; i < (int ) aGraphPorts->length() ; i++ ) {
2346 SUPERV::Port_var aPort = (*aGraphPorts)[ i ] ;
2347 if ( !aPort->IsGate() ) {
2348 MESSAGE( "Graph_Impl::Merge " << i << ". " << aPort->Node()->Name() << " " << aPort->Name() ) ;
2349 char * aPortName = aPort->Name() ;
2350 char * aNodeName = new char[ strlen( aPortName ) + 1 ] ;
2351 strcpy( aNodeName , aPortName ) ;
2352 // char * thePortName = strchr( aNodeName , '\\' ) ;
2353 char * thePortName = aNodeName ;
2354 while ( ( thePortName = strchr( thePortName , '_' ) ) ) {
2355 if ( thePortName[1] == '_' ) {
2356 thePortName[ 0 ] = '\0' ;
2360 thePortName = &thePortName[2] ;
2363 bool hasinput = aGraph->Node( aNodeName )->Port( thePortName + 2 )->HasInput() ;
2364 // cout << "Graph_Impl::Merge " << " aNodeName " << aNodeName << " aPort " << thePortName + 1
2365 // << " HasInput " << hasinput << endl ;
2367 RetVal = DataFlowEditor()->AddInputData( DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aNodeName ] )->Name() ,
2369 *(aPort->ToAny()) ) ;
2371 delete [] aNodeName ;
2380 MESSAGE( "Graph_Impl::Merge returns " << RetVal ) ;
2381 endService( "Graph_Impl::Merge" );
2385 SUPERV::StreamGraph_ptr Graph_Impl::ToStreamGraph() {
2386 SUPERV::StreamGraph_var iobject = SUPERV::StreamGraph::_nil() ;
2387 beginService( "Graph_Impl::ToStreamGraph" );
2388 if ( IsStreamGraph() && !IsMacro() ) {
2389 // StreamGraph_Impl * myStreamGraph = new StreamGraph_Impl( _Orb , _Poa , _ContId ,
2390 // instanceName() , interfaceName() ) ;
2391 // PortableServer::ObjectId * id = myStreamGraph->getId() ;
2392 // CORBA::Object_var obj = _poa->id_to_reference(*id);
2393 iobject = SUPERV::StreamGraph::_narrow( ObjRef() ) ;
2394 if ( CORBA::is_nil( iobject ) ) {
2395 MESSAGE( "ToStreamGraph of " << Name() << " (IsStreamGraph) --> nil reference" ) ;
2399 MESSAGE( "ToStreamGraph of " << Name() << " (IsNOTStreamGraph) --> nil reference" ) ;
2401 endService( "Graph_Impl::ToStreamGraph" );
2402 return SUPERV::StreamGraph::_duplicate( iobject ) ;