Salome HOME
If there is a syntax error in a python function (InLine Node), the states
[modules/superv.git] / src / Supervision / StreamGraph_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   : StreamGraph_Impl.cxx
25 //  Author : Jean Rahuel
26 //  Module : SUPERV
27 //  $Header: 
28
29 using namespace std;
30
31 #include "StreamGraph_Impl.hxx"
32
33 StreamGraph_Impl::StreamGraph_Impl( CORBA::ORB_ptr orb ,
34                                     PortableServer::POA_ptr poa ,
35                                     PortableServer::ObjectId * contId , 
36                                     const char *instanceName ,
37                                     const char *interfaceName ,
38                                     const char *aDataFlowName ) :
39   Graph_Impl(orb, poa, contId, instanceName, interfaceName, aDataFlowName , SUPERV::DataStreamGraph ) {
40 //  MESSAGE("StreamGraph_Impl::StreamGraph_Impl activate object instanceName("
41 //          << instanceName << ") interfaceName(" << interfaceName << ") --> "
42 //          << hex << (void *) this << dec )
43   beginService( "StreamGraph_Impl::StreamGraph_Impl" );
44   _thisObj = this ;
45   _id = _poa->activate_object(_thisObj);
46   _Orb = CORBA::ORB::_duplicate(orb);
47   _Poa = poa ;
48   _ContId = contId ;
49
50   endService( "StreamGraph_Impl::StreamGraph_Impl" );
51 }
52
53 StreamGraph_Impl::StreamGraph_Impl() {
54 }
55
56 StreamGraph_Impl::~StreamGraph_Impl() {
57   beginService( "StreamGraph_Impl::~StreamGraph_Impl" );
58   endService( "StreamGraph_Impl::~StreamGraph_Impl" );
59 }
60
61 void StreamGraph_Impl::destroy() {
62   beginService( "StreamGraph_Impl::destroy" );
63   _poa->deactivate_object(*_id) ;
64   CORBA::release(_poa) ;
65   delete(_id) ;
66   _thisObj->_remove_ref();
67   endService( "StreamGraph_Impl::destroy" );
68 }
69
70 SUPERV::StreamGraph_ptr StreamGraph_Impl::StreamCopy() {
71   beginService( "StreamGraph_Impl::StreamCopy" );
72   StreamGraph_Impl * myStreamGraph ;
73   myStreamGraph = new StreamGraph_Impl( _Orb , _Poa, _ContId,
74                                         instanceName() , interfaceName() ,
75                                         DataFlowEditor()->Graph()->Name() ) ;
76   PortableServer::ObjectId * id = myStreamGraph->getId() ;
77   CORBA::Object_var obj = _poa->id_to_reference(*id);
78   SUPERV::StreamGraph_var iobject ;
79   iobject = SUPERV::StreamGraph::_narrow(obj) ;
80   GraphBase::SGraph * aSGraph = GetGraph() ;
81   myStreamGraph->LoadGraph( aSGraph ) ;
82   endService( "StreamGraph_Impl::StreamCopy" );
83   return SUPERV::StreamGraph::_duplicate(iobject) ;
84 }
85
86 SUPERV::StreamLink_ptr StreamGraph_Impl::StreamLink(  SUPERV::StreamPort_ptr OutStreamPort ,
87                                                       SUPERV::StreamPort_ptr InStreamPort ) {
88   beginService( "StreamGraph_Impl::StreamLink" );
89   SUPERV::StreamLink_var iobject = SUPERV::StreamLink::_nil() ;
90   if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() &&
91        OutStreamPort->IsDataStream() && InStreamPort->IsDataStream() ) {
92     GraphBase::InPort * anInPort = DataFlowEditor()->GetNode( InStreamPort->Node()->Name() )->ComputingNode()->GetChangeInPort( InStreamPort->Name() ) ;
93     GraphBase::OutPort * anOutPort = DataFlowEditor()->GetNode( OutStreamPort->Node()->Name() )->ComputingNode()->GetChangeOutPort( OutStreamPort->Name() ) ;
94     if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
95       const char * DataFlowOutNodeName = OutStreamPort->Node()->Name() ;
96       GraphEditor::InNode * DataFlowOutNode = DataFlowEditor()->GetNode( DataFlowOutNodeName ) ;
97       const char * DataFlowInNodeName = InStreamPort->Node()->Name() ;
98       GraphEditor::InNode * DataFlowInNode = DataFlowEditor()->GetNode( DataFlowInNodeName ) ;
99       if ( DataFlowOutNode && DataFlowInNode ) {
100         bool Success ;
101         StreamLink_Impl * myStreamLink = new StreamLink_Impl( _Orb , _Poa , _ContId ,
102                                             instanceName() , interfaceName() ,
103                                             DataFlowEditor() ,
104                                             DataFlowInNode ,
105                                             InStreamPort->Name() ,
106                                             DataFlowOutNode ,
107                                             OutStreamPort->Name() ,
108                                             true , Success ) ;
109         if ( Success ) {
110           PortableServer::ObjectId * id = myStreamLink->getId() ;
111           CORBA::Object_var obj = _poa->id_to_reference(*id);
112           iobject = SUPERV::StreamLink::_narrow(obj) ;
113           anOutPort->AddInPortObjRef( anInPort , SUPERV::StreamLink::_duplicate(iobject) ) ;
114         }
115       }
116     }
117     else {
118       iobject = SUPERV::StreamLink::_narrow( anOutPort->InPortObjRef( anInPort ) ) ;
119     }
120   }
121   endService( "StreamGraph_Impl::StreamLink" );
122   return SUPERV::StreamLink::_duplicate(iobject) ;
123 }
124
125 SUPERV::ListOfStreamLinks * StreamGraph_Impl::GStreamLinks() {
126   return StreamLinks( NULL , NULL ) ;
127 }
128
129 SUPERV::ListOfStreamLinks * StreamGraph_Impl::StreamLinks( GraphBase::ComputingNode * theNode ,
130                                                            const char * anInputParam ) {
131   bool begin = true ;
132   SUPERV::ListOfStreamLinks_var RetVal = new SUPERV::ListOfStreamLinks ;
133   int i , j , countlink ;
134   countlink = 0 ;
135   for ( i = 0 ; i < DataFlowEditor()->Graph()->GraphNodesSize() ; i++ ) {
136     GraphEditor::InNode * aNode = NULL ;
137     aNode = (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GraphNodes( i )->GetInNode() ;
138     bool ToProcess = false ;
139     if ( theNode == NULL ) {
140       ToProcess = true ;
141     }
142     else {
143       if ( !strcmp( theNode->Name() , aNode->Name() ) ) {
144         if ( !theNode->IsEndSwitchNode() ) {
145           ToProcess = true ;
146         }
147       }
148       else if ( theNode->IsEndSwitchNode() ) {
149         ToProcess = true ;
150       }
151     }
152     if ( ToProcess ) {
153       for ( j = 0 ; j < aNode->GetNodeInPortsSize() ; j++ ) {
154         GraphBase::InPort * anInPort = NULL ;
155         anInPort = aNode->GetChangeNodeInPort( j ) ;
156         if ( anInputParam == NULL ||
157              !strcmp( anInPort->PortName() , anInputParam ) ) {
158           GraphBase::OutPort * anOutPort = NULL ;
159           anOutPort = anInPort->GetOutPort() ;
160           if ( anOutPort && anOutPort->IsDataStream() ) {
161             if ( strcmp( anOutPort->NodeName() , Name() ) ) {
162               MESSAGE("StreamGraph_Impl::StreamLinks " << anOutPort->NodeName() << "("
163                       << anOutPort->PortName() << ") --> " << aNode->Name() << "("
164                       << anInPort->PortName() << ")" ) ;
165               if ( theNode == NULL ||
166                    ( theNode != NULL && !theNode->IsEndSwitchNode() &&
167                      !strcmp( theNode->Name() , aNode->Name() ) ) ) {
168                 if ( anInPort->IsLoop() || anOutPort->IsLoop() ||
169                      ( aNode->IsEndLoopNode() && !strcmp( aNode->CoupledNode()->Name() ,
170                                                           anOutPort->NodeName() ) ) ) {
171                   MESSAGE( "StreamLink " << anOutPort->NodeName() << "("
172                           << anOutPort->PortName() << ") --> " << aNode->Name() << "("
173                           << anInPort->PortName() << ")" << " ignored" ) ;
174                 }
175                 else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
176                   if ( begin ) {
177                     beginService( "StreamGraph_Impl::StreamLinks" );
178                     begin = false ;
179                   }
180                   GraphEditor::InNode * anOutNode = NULL ;
181                   anOutNode = (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GetChangeGraphNode( anOutPort->NodeName() )->GetInNode() ;
182                   if ( anOutNode ) {
183                     bool Success ;
184                     StreamLink_Impl * myStreamLink = new StreamLink_Impl(
185                                           _Orb , _Poa , _ContId ,
186                                           instanceName() , interfaceName() ,
187                                           DataFlowEditor() ,
188                                           aNode ,
189                                           anInPort->PortName() ,
190                                           anOutNode ,
191                                           anOutPort->PortName() ,
192                                           false , Success ) ;
193                     if ( Success ) {
194                       PortableServer::ObjectId * id = myStreamLink->getId() ;
195                       CORBA::Object_var obj = _poa->id_to_reference(*id);
196                       SUPERV::StreamLink_var iobject ;
197                       iobject = SUPERV::StreamLink::_narrow(obj) ;
198                       RetVal->length( countlink + 1 ) ;
199                       RetVal[ countlink++ ] = SUPERV::StreamLink::_duplicate( iobject ) ;
200                       anOutPort->AddInPortObjRef( anInPort , SUPERV::StreamLink::_duplicate( iobject ) ) ;
201                       MESSAGE( "Link" << countlink-1 << " "
202                                << RetVal[countlink-1]->OutStreamPort()->Node()->Name() << "("
203                                << RetVal[countlink-1]->OutStreamPort()->Name() << ") --> "
204                                << RetVal[countlink-1]->InStreamPort()->Node()->Name() << "("
205                                << RetVal[countlink-1]->InStreamPort()->Name() << ")" ) ;
206                     }
207                   }
208                 }
209                 else {
210                   RetVal->length( countlink + 1 ) ;
211                   RetVal[ countlink++ ] = SUPERV::StreamLink::_duplicate( SUPERV::StreamLink::_narrow( anOutPort->InPortObjRef( anInPort ) ) ) ;
212                   MESSAGE( "Link" << countlink-1 << " "
213                            << RetVal[countlink-1]->OutStreamPort()->Node()->Name() << "("
214                            << RetVal[countlink-1]->OutStreamPort()->Name() << ") --> "
215                            << RetVal[countlink-1]->InStreamPort()->Node()->Name() << "("
216                            << RetVal[countlink-1]->InStreamPort()->Name() << ")" ) ;
217                 }
218               }
219             }
220           }
221         }
222       }
223     }
224     for ( j = 0 ; j < aNode->GetNodeOutPortsSize() ; j++ ) {
225       GraphBase::OutPort * anOutPort = aNode->GetChangeNodeOutPort( j ) ;
226       int k ;
227       for ( k = 0 ; k < anOutPort->InPortsSize() ; k++ ) {
228         GraphBase::InPort * anInPort = anOutPort->ChangeInPorts( k ) ;
229         GraphEditor::InNode * toNode = (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GetChangeGraphNode( anInPort->NodeName() )->GetInNode() ;
230         if ( theNode == NULL ||
231              !strcmp( theNode->Name() , aNode->Name() ) ) {
232           if ( anInPort->IsDataStream() ) {
233             if ( theNode || ( toNode->IsEndSwitchNode() && !aNode->IsSwitchNode() ) ) {
234               if ( anInputParam == NULL ||
235                    !strcmp( anInPort->PortName() , anInputParam ) ) {
236                 MESSAGE( "StreamLink " << anOutPort->NodeName() << "("
237                          << anOutPort->PortName() << ") --> " << toNode->Name() << "("
238                          << anInPort->PortName() << ")" ) ;
239                 MESSAGE( "           IOR " << DataFlowEditor()->ObjectToString( anOutPort->InPortObjRef( anInPort ) ) ) ;
240                 if ( anInPort->IsLoop() || anOutPort->IsLoop() ||
241                      ( toNode->IsEndLoopNode() && !strcmp( toNode->CoupledNode()->Name() ,
242                                                            anOutPort->NodeName() ) ) ) {
243                   MESSAGE( "StreamLink " << anOutPort->NodeName() << "("
244                            << anOutPort->PortName() << ") --> " << toNode->Name() << "("
245                            << anInPort->PortName() << ")" << " ignored" ) ;
246                 }
247                 else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
248                   if ( begin ) {
249                     beginService( "Graph_Impl::StreamLinks" );
250                     begin = false ;
251                   }
252                   bool Success ;
253                   StreamLink_Impl * myStreamLink = new StreamLink_Impl(
254                                         _Orb , _Poa , _ContId ,
255                                         instanceName() , interfaceName() ,
256                                         DataFlowEditor() ,
257                                         toNode ,
258                                         anInPort->PortName() ,
259                                         aNode ,
260                                         anOutPort->PortName() ,
261                                         false , Success ) ;
262                   if ( Success ) {
263                     PortableServer::ObjectId * id = myStreamLink->getId() ;
264                     CORBA::Object_var obj = _poa->id_to_reference(*id);
265                     SUPERV::StreamLink_var iobject ;
266                     iobject = SUPERV::StreamLink::_narrow(obj) ;
267                     RetVal->length( countlink + 1 ) ;
268                     RetVal[ countlink++ ] = SUPERV::StreamLink::_duplicate( iobject ) ;
269                     anOutPort->AddInPortObjRef( anInPort , SUPERV::StreamLink::_duplicate( iobject ) ) ;
270                     MESSAGE( "Link" << countlink-1 << " "
271                              << RetVal[countlink-1]->OutStreamPort()->Node()->Name() << "("
272                              << RetVal[countlink-1]->OutStreamPort()->Name() << ") --> "
273                              << RetVal[countlink-1]->InStreamPort()->Node()->Name() << "("
274                              << RetVal[countlink-1]->InStreamPort()->Name() << ")" ) ;
275                   }
276                 }
277                 else {
278                   RetVal->length( countlink + 1 ) ;
279                   RetVal[ countlink++ ] = SUPERV::StreamLink::_duplicate( SUPERV::StreamLink::_narrow( anOutPort->InPortObjRef( anInPort ) ) ) ;
280                   MESSAGE( "Link" << countlink-1 << " "
281                            << RetVal[countlink-1]->OutStreamPort()->Node()->Name() << "("
282                            << RetVal[countlink-1]->OutStreamPort()->Name() << ") --> "
283                            << RetVal[countlink-1]->InStreamPort()->Node()->Name() << "("
284                            << RetVal[countlink-1]->InStreamPort()->Name() << ")" ) ;
285                 }
286               }
287               else {
288                 MESSAGE( "StreamLink " << anOutPort->NodeName() << "("
289                          << anOutPort->PortName() << ") --> " << toNode->Name() << "("
290                          << anInPort->PortName() << ")" << " skipped" ) ;
291               }
292             }
293           }
294         }
295       }
296     }
297   }
298 //#if 0
299   const char * NodeName = "" ;
300   const char * InputParamName = "" ;
301   if ( theNode ) {
302     NodeName = theNode->Name() ;
303   }
304   if ( anInputParam ) {
305     InputParamName = anInputParam ;
306   }
307   MESSAGE( RetVal->length() << " StreamLinks of Node " << NodeName << " and of InPort " << InputParamName ) ;
308   for ( i = 0 ; i < (int ) RetVal->length() ; i++ ) {
309     MESSAGE( "Link" << i << " " << RetVal[i]->OutStreamPort()->Node()->Name() << "("
310              << RetVal[i]->OutStreamPort()->Name() << ") --> "
311              << RetVal[i]->InStreamPort()->Node()->Name() << "("
312              << RetVal[i]->InStreamPort()->Name() << ")" ) ;
313   }
314 //#endif
315   if ( !begin ) {
316     endService( "StreamGraph_Impl::StreamLinks" );
317   }
318   return ( RetVal._retn() ) ;
319 }
320
321 bool StreamGraph_Impl::SetStreamParams( const long Timeout ,
322                                         const SUPERV::KindOfDataStreamTrace DataStreamTrace ,
323                                         const double  DeltaTime ) {
324   bool sts = DataFlowEditor()->StreamGraph()->SetStreamParams( Timeout , DataStreamTrace , DeltaTime ) ;
325   DataFlowEditor()->UnValid() ;
326   return sts ;
327 }
328
329 void StreamGraph_Impl::StreamParams( long & Timeout ,
330                                      SUPERV::KindOfDataStreamTrace & DataStreamTrace ,
331                                      double & DeltaTime ) {
332   DataFlowEditor()->StreamGraph()->StreamParams( Timeout , DataStreamTrace , DeltaTime ) ;
333 }
334
335 long StreamGraph_Impl::SubStreamGraphsNumber() {
336 //  beginService( "StreamGraph_Impl::StreamGraphsNumber" );
337   long RetVal = 0 ;
338   if ( DataFlowEditor()->IsExecutable() ) {
339     RetVal =  DataFlowEditor()->SubStreamGraphsNumber() ;
340   }
341 //  endService( "StreamGraph_Impl::SubStreamGraphsNumber" );
342   return RetVal ;
343 }
344
345 SUPERV::ListOfNodes * StreamGraph_Impl::SubStreamGraphsNodes( const long aSubStreamGraphNumber ) {
346   beginService( "StreamGraph_Impl::SubStreamGraphsNodes" );
347   SUPERV::ListOfNodes_var RetVal = new SUPERV::ListOfNodes ;
348   if ( DataFlowEditor()->IsEditing() ) {
349     SUPERV::ListOfNodes * aGraphNodes = Nodes() ;
350     int i ;
351 // ComputingNodes
352     for ( i = 0 ; i < (int ) aGraphNodes->CNodes.length() ; i++ ) {
353       SUPERV::CNode_var aNode = (aGraphNodes->CNodes)[ i ] ;
354       if ( aNode->SubStreamGraph() == aSubStreamGraphNumber ) {
355         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
356       }
357     }
358 // FactoryNodes
359     for ( i = 0 ; i < (int ) aGraphNodes->FNodes.length() ; i++ ) {
360       SUPERV::FNode_var aNode = (aGraphNodes->FNodes)[ i ] ;
361       if ( aNode->SubStreamGraph() == aSubStreamGraphNumber ) {
362         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
363       }
364     }
365 // InLineNodes
366     for ( i = 0 ; i < (int ) aGraphNodes->INodes.length() ; i++ ) {
367       SUPERV::INode_var aNode = (aGraphNodes->INodes)[ i ] ;
368       if ( aNode->SubStreamGraph() == aSubStreamGraphNumber ) {
369         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
370       }
371     }
372 // GOTONodes
373     for ( i = 0 ; i < (int ) aGraphNodes->GNodes.length() ; i++ ) {
374       SUPERV::GNode_var aNode = (aGraphNodes->GNodes)[ i ] ;
375       if ( aNode->SubStreamGraph() == aSubStreamGraphNumber ) {
376         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
377       }
378     }
379 // LoopNodes
380     for ( i = 0 ; i < (int ) aGraphNodes->LNodes.length() ; i++ ) {
381       SUPERV::LNode_var aNode = (aGraphNodes->LNodes)[ i ] ;
382       if ( aNode->SubStreamGraph() == aSubStreamGraphNumber ) {
383         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
384       }
385     }
386 // EndLoopNodes
387     for ( i = 0 ; i < (int ) aGraphNodes->ELNodes.length() ; i++ ) {
388       SUPERV::ELNode_var aNode = (aGraphNodes->ELNodes)[ i ] ;
389       if ( aNode->SubStreamGraph() == aSubStreamGraphNumber ) {
390         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
391       }
392     }
393 // SwitchNodes
394     for ( i = 0 ; i < (int ) aGraphNodes->SNodes.length() ; i++ ) {
395       SUPERV::SNode_var aNode = (aGraphNodes->SNodes)[ i ] ;
396       if ( aNode->SubStreamGraph() == aSubStreamGraphNumber ) {
397         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
398       }
399     }
400 // EndSwitchNodes
401     for ( i = 0 ; i < (int ) aGraphNodes->ESNodes.length() ; i++ ) {
402       SUPERV::ESNode_var aNode = (aGraphNodes->ESNodes)[ i ] ;
403       if ( aNode->SubStreamGraph() == aSubStreamGraphNumber ) {
404         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
405       }
406     }
407   }
408   endService( "StreamGraph_Impl::SubStreamGraphsNodes" );
409   return ( RetVal._retn() ) ;
410 }
411
412 SUPERV::Graph_ptr StreamGraph_Impl::ToFlowGraph() {
413   SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
414   beginService( "StreamGraph_Impl::ToFlowGraph" );
415 //  Graph_Impl * myFlowGraph = new Graph_Impl( _Orb , _Poa , _ContId ,
416 //                                             instanceName() , interfaceName() ) ;
417 //  PortableServer::ObjectId * id = myFlowGraph->getId() ;
418 //  CORBA::Object_var obj = _poa->id_to_reference(*id);
419   if ( !CORBA::is_nil( DataFlowEditor()->StreamGraph()->ObjRef() ) ) {
420     iobject = SUPERV::Graph::_narrow( DataFlowEditor()->StreamGraph()->ObjRef() ) ;
421   }
422   endService( "StreamGraph_Impl::ToFlowGraph" );
423   return SUPERV::Graph::_duplicate( iobject ) ;
424 }
425
426 bool StreamGraph_Impl::StreamMerge(const SUPERV::StreamGraph_ptr aStreamGraph ) {
427   beginService( "StreamGraph_Impl::StreamMerge" );
428   map< string , int > aMapOfNodes ;
429   bool RetVal = Merge( aStreamGraph , aMapOfNodes ) ;
430   if ( RetVal ) {
431     SUPERV::ListOfStreamLinks * aGraphLinks = aStreamGraph->GStreamLinks() ;
432     SUPERV::ListOfStreamPorts * aGraphPorts = aStreamGraph->StreamPorts() ;
433     cout << "Graph_Impl::Merge " << aGraphLinks->length() << " links " << aGraphPorts->length() << " GraphPorts"
434          << endl ;
435     int i ;
436     for ( i = 0 ; i < (int ) aGraphLinks->length() ; i++ ) {
437       SUPERV::StreamLink_var aLink = (*aGraphLinks)[ i ] ;
438       SUPERV::StreamPort_var OutPort = aLink->OutStreamPort() ;
439       SUPERV::StreamPort_var InPort = aLink->InStreamPort() ;
440       string * aLinkFromNodeName = new string( OutPort->Node()->Name() ) ;
441       string * aLinkToNodeName = new string( InPort->Node()->Name() ) ;
442       cout << "Graph_Impl::Merge " << aLinkFromNodeName << "(" << OutPort->Name() << ") ---> "
443            << aLinkToNodeName << "(" << InPort->Name() << ")" << endl ;
444       RetVal = DataFlowEditor()->AddLink( DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] )->Name() ,
445                                           OutPort->Name() ,
446                                           DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] )->Name() ,
447                                           InPort->Name() ) ;
448       cout << "Graph_Impl::Merge " << aLinkFromNodeName << "(" << OutPort->Name() << ") ---> "
449            << aLinkToNodeName << "(" << InPort->Name() << ") RetVal" << RetVal << endl ;
450       if ( RetVal ) {
451         int j ;
452         for ( j = 1 ; j <= aLink->CoordsSize() ; j++ ) {
453           long X , Y ;
454           RetVal = aLink->Coords( j , X , Y ) ;
455           if ( !RetVal )
456             break ;
457           RetVal = DataFlowEditor()->AddLinkCoord( DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] )->Name() ,
458                                                    OutPort->Name() ,
459                                                    DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] )->Name() ,
460                                                    InPort->Name() ,
461                                                    j , X , Y ) ;
462           if ( !RetVal ) {
463             break ;
464           }
465         }
466       }
467       delete aLinkFromNodeName ;
468       delete aLinkToNodeName ;
469       if ( !RetVal ) {
470         break ;
471       }
472     }
473     if ( RetVal ) {
474       for ( i = 0 ; i < (int ) aGraphPorts->length() ; i++ ) {
475         SUPERV::StreamPort_var aPort = (*aGraphPorts)[ i ] ;
476         if ( !aPort->IsGate() ) {
477           MESSAGE( "Graph_Impl::Merge " << i << ". " << aPort->Node()->Name() << " " << aPort->Name() ) ;
478           char * aPortName = aPort->Name() ;
479           char * aNodeName = new char[ strlen( aPortName ) + 1 ] ;
480           strcpy( aNodeName , aPortName ) ;
481           char * thePortName = strchr( aNodeName , '\\' ) ;
482           thePortName[ 0 ] = '\0' ;
483           bool hasinput = aStreamGraph->Node( aNodeName )->Port( thePortName + 1 )->HasInput() ;
484 //          cout << "Graph_Impl::Merge " << " aNodeName " << aNodeName << " aPort " << thePortName + 1
485 //               << " HasInput " << hasinput << endl ;
486           if ( hasinput ) {
487             RetVal = DataFlowEditor()->AddInputData( DataFlowEditor()->StreamGraph()->GetGraphNode( aMapOfNodes[ aNodeName ] )->Name() ,
488                                                      thePortName + 1 ,
489                                                      *(aPort->ToAny()) ) ;
490           }
491           delete [] aNodeName ;
492           if ( !RetVal ) {
493             break ;
494           }
495         }
496       }
497     }
498   }
499   endService( "StreamGraph_Impl::StreamMerge" );
500   return RetVal ;
501 }
502