Salome HOME
d123cf02f46d2a6630fd7ac332b5c8a4fda80a10
[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                                     const SUPERV::KindOfNode aKindOfGraphNode ) :
40 //  Graph_Impl(orb, poa, contId, instanceName, interfaceName, aDataFlowName , SUPERV::DataStreamGraph ) {
41   Graph_Impl(orb, poa, contId, instanceName, interfaceName, aDataFlowName , aKindOfGraphNode ) {
42 //  MESSAGE("StreamGraph_Impl::StreamGraph_Impl activate object instanceName("
43 //          << instanceName << ") interfaceName(" << interfaceName << ") --> "
44 //          << hex << (void *) this << dec )
45   beginService( "StreamGraph_Impl::StreamGraph_Impl" );
46   _thisObj = this ;
47   _id = _poa->activate_object(_thisObj);
48   _Orb = CORBA::ORB::_duplicate(orb);
49   _Poa = poa ;
50   _ContId = contId ;
51
52   endService( "StreamGraph_Impl::StreamGraph_Impl" );
53 }
54
55 StreamGraph_Impl::StreamGraph_Impl( CORBA::ORB_ptr orb ,
56                         PortableServer::POA_ptr poa ,
57                         PortableServer::ObjectId * contId , 
58                         const char *instanceName ,
59                         const char *interfaceName ,
60                         GraphEditor::DataFlow * aDataFlowEditor ,
61                         GraphEditor::InNode * aDataFlowNode ) :
62   Graph_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , aDataFlowNode ) {
63   beginService( "StreamGraph_Impl::StreamGraph_Impl" );
64   if ( aDataFlowEditor->Graph()->IsDataStreamNode() ||
65        ( aDataFlowNode && aDataFlowNode->IsMacroNode() ) ) {
66     MESSAGE( "StreamGraph_Impl::StreamGraph_Impl _poa->activate_object" );
67     _thisObj = this ;
68     _id = _poa->activate_object(_thisObj);
69   }
70   else {
71     MESSAGE( "StreamGraph_Impl::StreamGraph_Impl NO _poa->activate_object " );
72   }
73   _Orb = CORBA::ORB::_duplicate(orb);
74   _Poa = poa ;
75   _ContId = contId ;
76   endService( "StreamGraph_Impl::StreamGraph_Impl" );  
77 }
78
79 StreamGraph_Impl::StreamGraph_Impl() {
80 }
81
82 StreamGraph_Impl::~StreamGraph_Impl() {
83   beginService( "StreamGraph_Impl::~StreamGraph_Impl" );
84   endService( "StreamGraph_Impl::~StreamGraph_Impl" );
85 }
86
87 void StreamGraph_Impl::destroy() {
88   beginService( "StreamGraph_Impl::destroy" );
89   _poa->deactivate_object(*_id) ;
90 //  CORBA::release(_poa) ;
91   delete(_id) ;
92 //  _thisObj->_remove_ref();
93   endService( "StreamGraph_Impl::destroy" );
94 }
95
96 SUPERV::StreamGraph_ptr StreamGraph_Impl::StreamCopy() {
97   beginService( "StreamGraph_Impl::StreamCopy" );
98   SUPERV::StreamGraph_var iobject = SUPERV::StreamGraph::_nil() ;
99   if ( !IsMacro() ) {
100     StreamGraph_Impl * myStreamGraph ;
101     myStreamGraph = new StreamGraph_Impl( _Orb , _Poa, _ContId,
102                                           instanceName() , interfaceName() ,
103                                           DataFlowEditor()->Graph()->Name() ) ;
104     PortableServer::ObjectId * id = myStreamGraph->getId() ;
105     CORBA::Object_var obj = _poa->id_to_reference(*id);
106     iobject = SUPERV::StreamGraph::_narrow(obj) ;
107     GraphBase::ListOfSGraphs * aListOfSGraphs = GetGraphs() ;
108     myStreamGraph->LoadGraphs( aListOfSGraphs ) ;
109   }
110   endService( "StreamGraph_Impl::StreamCopy" );
111   return SUPERV::StreamGraph::_duplicate(iobject) ;
112 }
113
114 SUPERV::StreamGraph_ptr StreamGraph_Impl::StreamMNode( const char * aXmlFileName ) {
115   beginService( "StreamGraph_Impl::StreamMNode" );
116   SUPERV::StreamGraph_var streamiobject = SUPERV::StreamGraph::_nil() ;
117   SUPERV::StreamGraph_var macroiobject = SUPERV::StreamGraph::_nil() ;
118 #if 0
119   string dbgfile ;
120   GraphEditor::DataFlow * aDataFlowEditor ;
121   CreateEditor( _Orb , instanceName() , aXmlFileName , SUPERV::DataStreamGraph ,
122                 dbgfile , &aDataFlowEditor ) ;
123   int lenname = strlen( aXmlFileName ) ;
124   bool created = false ;
125   if ( lenname > 4 && !strcmp( &aXmlFileName[ lenname - 4 ] , ".xml" ) ) {
126     created = aDataFlowEditor->LoadXml( aXmlFileName ) ;
127   }
128   if ( created ) {
129     StreamGraph_Impl * myStreamGraph ;
130     myStreamGraph = new StreamGraph_Impl( _Orb , _Poa, _ContId,
131                                           instanceName() , interfaceName() ,
132                                           aDataFlowEditor , NULL ) ;
133     PortableServer::ObjectId * id = myStreamGraph->getId() ;
134     CORBA::Object_var obj = _poa->id_to_reference(*id);
135     streamiobject = SUPERV::StreamGraph::_narrow( obj ) ;
136     myStreamGraph->SetObjRef( SUPERV::StreamGraph::_duplicate( streamiobject ) ) ;
137
138     StreamGraph_Impl * myStreamMacroNode ;
139     myStreamMacroNode = new StreamGraph_Impl( _Orb , _Poa, _ContId,
140                                               instanceName() , interfaceName() ,
141                                               aXmlFileName , SUPERV::StreamMacroNode ) ;
142     id = myStreamMacroNode->getId() ;
143     obj = _poa->id_to_reference(*id);
144     macroiobject = SUPERV::StreamGraph::_narrow( obj ) ;
145     myStreamMacroNode->DataFlowEditor( DataFlowEditor() ) ;
146     myStreamMacroNode->DataFlowEditor()->Graph()->SetObjImpl( this ) ;
147     myStreamMacroNode->SetObjRef( SUPERV::CNode::_duplicate( SUPERV::CNode::_narrow( obj ) ) ) ;
148     char * aMacroNodeName = myStreamGraph->Name() ;
149     GraphBase::ListOfFuncName aFuncName ;
150     aFuncName.resize( 1 ) ;
151     aFuncName[0] = "" ;
152     SUPERV::ListOfStrings aListOfStrings ;
153     aListOfStrings.length( 1 ) ;
154     aListOfStrings[0] = "" ;
155     GraphBase::ListOfPythonFunctions aPythonFunction ;
156     aPythonFunction.resize( 1 ) ;
157     aPythonFunction[0] = &aListOfStrings ;
158     SALOME_ModuleCatalog::Service * aMacroNodeService = myStreamGraph->Service() ;
159     GraphEditor::InNode * aDataFlowNode = DataFlowEditor()->AddNode( *aMacroNodeService , "" , "" ,
160                                                                      aMacroNodeName , SUPERV::StreamMacroNode ,
161                                                                      aFuncName , aPythonFunction ) ;
162     myStreamMacroNode->DataFlowNode( aDataFlowNode ) ;
163     myStreamGraph->MacroObject( SUPERV::StreamGraph::_duplicate( macroiobject ) ) ;
164     myStreamMacroNode->MacroObject( SUPERV::StreamGraph::_duplicate( streamiobject ) ) ;
165     MESSAGE( "DataFlowNode Graph " << this << " DataFlowEditor " << DataFlowEditor() << " aDataFlowNode "
166              << aDataFlowNode << " " << aDataFlowNode->Name()
167              << " created" ) ;
168   }
169   else {
170     delete aDataFlowEditor ;
171   }
172 #endif
173   endService( "StreamGraph_Impl::StreamMNode" );
174   return SUPERV::StreamGraph::_duplicate( macroiobject ) ;
175 }
176
177 SUPERV::StreamGraph_ptr StreamGraph_Impl::StreamGraphMNode( SUPERV::StreamGraph_ptr myMacroStreamGraph ) {
178   SUPERV::StreamGraph_var iobject = myMacroStreamGraph ;
179 //  GraphBase::Graph * myMacroGraph = aGraph;
180   SUPERV::StreamGraph_var macroiobject = SUPERV::StreamGraph::_nil() ;
181   beginService( "StreamGraph_Impl::StreamGraphMNode" ) ;
182   endService( "StreamGraph_Impl::StreamGraphMNode" ) ;
183   return SUPERV::StreamGraph::_duplicate( macroiobject ) ;
184 }
185
186 SUPERV::StreamLink_ptr StreamGraph_Impl::StreamLink(  SUPERV::StreamPort_ptr OutStreamPort ,
187                                                       SUPERV::StreamPort_ptr InStreamPort ) {
188   beginService( "StreamGraph_Impl::StreamLink" );
189   SUPERV::StreamLink_var iobject = SUPERV::StreamLink::_nil() ;
190   if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() && !IsMacro() &&
191        OutStreamPort->IsDataStream() && InStreamPort->IsDataStream() ) {
192     GraphBase::InPort * anInPort = DataFlowEditor()->GetNode( InStreamPort->Node()->Name() )->ComputingNode()->GetChangeInPort( InStreamPort->Name() ) ;
193     GraphBase::OutPort * anOutPort = DataFlowEditor()->GetNode( OutStreamPort->Node()->Name() )->ComputingNode()->GetChangeOutPort( OutStreamPort->Name() ) ;
194     if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
195       const char * DataFlowOutNodeName = OutStreamPort->Node()->Name() ;
196       GraphEditor::InNode * DataFlowOutNode = DataFlowEditor()->GetNode( DataFlowOutNodeName ) ;
197       const char * DataFlowInNodeName = InStreamPort->Node()->Name() ;
198       GraphEditor::InNode * DataFlowInNode = DataFlowEditor()->GetNode( DataFlowInNodeName ) ;
199       if ( DataFlowOutNode && DataFlowInNode ) {
200         bool Success ;
201         StreamLink_Impl * myStreamLink = new StreamLink_Impl( _Orb , _Poa , _ContId ,
202                                             instanceName() , interfaceName() ,
203                                             DataFlowEditor() ,
204                                             DataFlowInNode ,
205                                             InStreamPort->Name() ,
206                                             DataFlowOutNode ,
207                                             OutStreamPort->Name() ,
208                                             true , Success ) ;
209         if ( Success ) {
210           PortableServer::ObjectId * id = myStreamLink->getId() ;
211           CORBA::Object_var obj = _poa->id_to_reference(*id);
212           iobject = SUPERV::StreamLink::_narrow(obj) ;
213           anOutPort->AddInPortObjRef( anInPort , SUPERV::StreamLink::_duplicate(iobject) ) ;
214           DataFlowEditor()->UnValid() ;
215         }
216       }
217     }
218     else {
219       iobject = SUPERV::StreamLink::_narrow( anOutPort->InPortObjRef( anInPort ) ) ;
220     }
221   }
222   endService( "StreamGraph_Impl::StreamLink" );
223   return SUPERV::StreamLink::_duplicate(iobject) ;
224 }
225
226 SUPERV::ListOfStreamLinks * StreamGraph_Impl::GStreamLinks() {
227   return StreamLinks( NULL , NULL ) ;
228 }
229
230 SUPERV::ListOfStreamLinks * StreamGraph_Impl::StreamLinks( GraphBase::ComputingNode * theNode ,
231                                                            const char * anInputParam ) {
232   bool begin = true ;
233   SUPERV::ListOfStreamLinks_var RetVal = new SUPERV::ListOfStreamLinks ;
234   if ( !IsMacro() ) {
235     int i , j , countlink ;
236     countlink = 0 ;
237     for ( i = 0 ; i < DataFlowEditor()->Graph()->GraphNodesSize() ; i++ ) {
238       GraphEditor::InNode * aNode = NULL ;
239       aNode = (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GraphNodes( i )->GetInNode() ;
240       bool ToProcess = false ;
241       if ( theNode == NULL ) {
242         ToProcess = true ;
243       }
244       else {
245         if ( !strcmp( theNode->Name() , aNode->Name() ) ) {
246           if ( !theNode->IsEndSwitchNode() ) {
247             ToProcess = true ;
248           }
249         }
250         else if ( theNode->IsEndSwitchNode() ) {
251           ToProcess = true ;
252         }
253       }
254       if ( ToProcess ) {
255         for ( j = 0 ; j < aNode->GetNodeInPortsSize() ; j++ ) {
256           GraphBase::InPort * anInPort = NULL ;
257           anInPort = aNode->GetChangeNodeInPort( j ) ;
258           if ( anInputParam == NULL ||
259                !strcmp( anInPort->PortName() , anInputParam ) ) {
260             GraphBase::OutPort * anOutPort = NULL ;
261             anOutPort = anInPort->GetOutPort() ;
262             if ( anOutPort && anOutPort->IsDataStream() ) {
263               if ( strcmp( anOutPort->NodeName() , Name() ) ) {
264                 MESSAGE("StreamGraph_Impl::StreamLinks " << anOutPort->NodeName() << "("
265                         << anOutPort->PortName() << ") --> " << aNode->Name() << "("
266                         << anInPort->PortName() << ")" ) ;
267                 if ( theNode == NULL ||
268 //PAL8521
269 //JR 14.02.2005 : Debug : we must see also that links !
270 //                     ( theNode != NULL && !theNode->IsEndSwitchNode() &&
271                        !strcmp( theNode->Name() , aNode->Name() ) ) {
272                   if ( anInPort->IsLoop() || anOutPort->IsLoop() ||
273                        ( aNode->IsEndLoopNode() && !strcmp( aNode->CoupledNode()->Name() ,
274                                                             anOutPort->NodeName() ) ) ) {
275                     MESSAGE( "StreamLink " << anOutPort->NodeName() << "("
276                             << anOutPort->PortName() << ") --> " << aNode->Name() << "("
277                             << anInPort->PortName() << ")" << " ignored" ) ;
278                   }
279                   else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
280                     if ( begin ) {
281                       beginService( "StreamGraph_Impl::StreamLinks" );
282                       begin = false ;
283                     }
284                     GraphEditor::InNode * anOutNode = NULL ;
285                     anOutNode = (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GetChangeGraphNode( anOutPort->NodeName() )->GetInNode() ;
286                     if ( anOutNode ) {
287                       bool Success ;
288                       StreamLink_Impl * myStreamLink = new StreamLink_Impl(
289                                             _Orb , _Poa , _ContId ,
290                                             instanceName() , interfaceName() ,
291                                             DataFlowEditor() ,
292                                             aNode ,
293                                             anInPort->PortName() ,
294                                             anOutNode ,
295                                             anOutPort->PortName() ,
296                                             false , Success ) ;
297                       if ( Success ) {
298                         PortableServer::ObjectId * id = myStreamLink->getId() ;
299                         CORBA::Object_var obj = _poa->id_to_reference(*id);
300                         SUPERV::StreamLink_var iobject ;
301                         iobject = SUPERV::StreamLink::_narrow(obj) ;
302                         RetVal->length( countlink + 1 ) ;
303                         RetVal[ countlink++ ] = SUPERV::StreamLink::_duplicate( iobject ) ;
304                         anOutPort->AddInPortObjRef( anInPort , SUPERV::StreamLink::_duplicate( iobject ) ) ;
305                         MESSAGE( "Link" << countlink-1 << " "
306                                  << RetVal[countlink-1]->OutStreamPort()->Node()->Name() << "("
307                                  << RetVal[countlink-1]->OutStreamPort()->Name() << ") --> "
308                                  << RetVal[countlink-1]->InStreamPort()->Node()->Name() << "("
309                                  << RetVal[countlink-1]->InStreamPort()->Name() << ")" ) ;
310                       }
311                     }
312                   }
313                   else {
314                     RetVal->length( countlink + 1 ) ;
315                     RetVal[ countlink++ ] = SUPERV::StreamLink::_duplicate( SUPERV::StreamLink::_narrow( anOutPort->InPortObjRef( anInPort ) ) ) ;
316                     MESSAGE( "Link" << countlink-1 << " "
317                              << RetVal[countlink-1]->OutStreamPort()->Node()->Name() << "("
318                              << RetVal[countlink-1]->OutStreamPort()->Name() << ") --> "
319                              << RetVal[countlink-1]->InStreamPort()->Node()->Name() << "("
320                              << RetVal[countlink-1]->InStreamPort()->Name() << ")" ) ;
321                   }
322                 }
323               }
324             }
325           }
326         }
327       }
328       for ( j = 0 ; j < aNode->GetNodeOutPortsSize() ; j++ ) {
329         GraphBase::OutPort * anOutPort = aNode->GetChangeNodeOutPort( j ) ;
330         int k ;
331         for ( k = 0 ; k < anOutPort->InPortsSize() ; k++ ) {
332           GraphBase::InPort * anInPort = anOutPort->ChangeInPorts( k ) ;
333           GraphEditor::InNode * toNode = (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GetChangeGraphNode( anInPort->NodeName() )->GetInNode() ;
334           if ( theNode == NULL ||
335                !strcmp( theNode->Name() , aNode->Name() ) ) {
336             if ( anInPort->IsDataStream() ) {
337 //PAL8521
338 //JR 14.02.2005 : Debug : we must see also that links !
339 //              if ( theNode || ( toNode->IsEndSwitchNode() && !aNode->IsSwitchNode() ) ) {
340                 if ( anInputParam == NULL ||
341                      !strcmp( anInPort->PortName() , anInputParam ) ) {
342                   MESSAGE( "StreamLink " << anOutPort->NodeName() << "("
343                            << anOutPort->PortName() << ") --> " << toNode->Name() << "("
344                            << anInPort->PortName() << ")" ) ;
345                   MESSAGE( "           IOR " << DataFlowEditor()->ObjectToString( anOutPort->InPortObjRef( anInPort ) ) ) ;
346                   if ( anInPort->IsLoop() || anOutPort->IsLoop() ||
347                        ( toNode->IsEndLoopNode() && !strcmp( toNode->CoupledNode()->Name() ,
348                                                              anOutPort->NodeName() ) ) ) {
349                     MESSAGE( "StreamLink " << anOutPort->NodeName() << "("
350                              << anOutPort->PortName() << ") --> " << toNode->Name() << "("
351                              << anInPort->PortName() << ")" << " ignored" ) ;
352                   }
353                   else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
354                     if ( begin ) {
355                       beginService( "Graph_Impl::StreamLinks" );
356                       begin = false ;
357                     }
358                     bool Success ;
359                     StreamLink_Impl * myStreamLink = new StreamLink_Impl(
360                                           _Orb , _Poa , _ContId ,
361                                           instanceName() , interfaceName() ,
362                                           DataFlowEditor() ,
363                                           toNode ,
364                                           anInPort->PortName() ,
365                                           aNode ,
366                                           anOutPort->PortName() ,
367                                           false , Success ) ;
368                     if ( Success ) {
369                       PortableServer::ObjectId * id = myStreamLink->getId() ;
370                       CORBA::Object_var obj = _poa->id_to_reference(*id);
371                       SUPERV::StreamLink_var iobject ;
372                       iobject = SUPERV::StreamLink::_narrow(obj) ;
373                       RetVal->length( countlink + 1 ) ;
374                       RetVal[ countlink++ ] = SUPERV::StreamLink::_duplicate( iobject ) ;
375                       anOutPort->AddInPortObjRef( anInPort , SUPERV::StreamLink::_duplicate( iobject ) ) ;
376                       MESSAGE( "Link" << countlink-1 << " "
377                                << RetVal[countlink-1]->OutStreamPort()->Node()->Name() << "("
378                                << RetVal[countlink-1]->OutStreamPort()->Name() << ") --> "
379                                << RetVal[countlink-1]->InStreamPort()->Node()->Name() << "("
380                                << RetVal[countlink-1]->InStreamPort()->Name() << ")" ) ;
381                     }
382                   }
383                   else {
384                     RetVal->length( countlink + 1 ) ;
385                     RetVal[ countlink++ ] = SUPERV::StreamLink::_duplicate( SUPERV::StreamLink::_narrow( anOutPort->InPortObjRef( anInPort ) ) ) ;
386                     MESSAGE( "Link" << countlink-1 << " "
387                              << RetVal[countlink-1]->OutStreamPort()->Node()->Name() << "("
388                              << RetVal[countlink-1]->OutStreamPort()->Name() << ") --> "
389                              << RetVal[countlink-1]->InStreamPort()->Node()->Name() << "("
390                              << RetVal[countlink-1]->InStreamPort()->Name() << ")" ) ;
391                   }
392                 }
393                 else {
394                   MESSAGE( "StreamLink " << anOutPort->NodeName() << "("
395                            << anOutPort->PortName() << ") --> " << toNode->Name() << "("
396                            << anInPort->PortName() << ")" << " skipped" ) ;
397                 }
398 //            }
399             }
400           }
401         }
402       }
403     }
404 //#if 0
405     const char * NodeName = "" ;
406     const char * InputParamName = "" ;
407     if ( theNode ) {
408       NodeName = theNode->Name() ;
409     }
410     if ( anInputParam ) {
411       InputParamName = anInputParam ;
412     }
413     MESSAGE( RetVal->length() << " StreamLinks of Node " << NodeName << " and of InPort " << InputParamName ) ;
414     for ( i = 0 ; i < (int ) RetVal->length() ; i++ ) {
415       MESSAGE( "Link" << i << " " << RetVal[i]->OutStreamPort()->Node()->Name() << "("
416                << RetVal[i]->OutStreamPort()->Name() << ") --> "
417                << RetVal[i]->InStreamPort()->Node()->Name() << "("
418                << RetVal[i]->InStreamPort()->Name() << ")" ) ;
419     }
420 //#endif
421     if ( !begin ) {
422       endService( "StreamGraph_Impl::StreamLinks" );
423     }
424   }
425   return ( RetVal._retn() ) ;
426 }
427
428 bool StreamGraph_Impl::SetStreamParams( const long Timeout ,
429                                         const SUPERV::KindOfDataStreamTrace DataStreamTrace ,
430                                         const double  DeltaTime ) {
431   bool sts = false ;
432   if ( !IsMacro() ) {
433     sts = DataFlowEditor()->StreamGraph()->SetStreamParams( Timeout , DataStreamTrace , DeltaTime ) ;
434     if ( sts ) {
435       DataFlowEditor()->UnValid() ;
436     }
437   }
438   return sts ;
439 }
440
441 void StreamGraph_Impl::StreamParams( long & Timeout ,
442                                      SUPERV::KindOfDataStreamTrace & DataStreamTrace ,
443                                      double & DeltaTime ) {
444   if ( !IsMacro() ) {
445     DataFlowEditor()->StreamGraph()->StreamParams( Timeout , DataStreamTrace , DeltaTime ) ;
446   }
447 }
448
449 long StreamGraph_Impl::SubStreamGraphsNumber() {
450 //  beginService( "StreamGraph_Impl::StreamGraphsNumber" );
451   long RetVal = 0 ;
452   if ( DataFlowEditor()->IsExecutable() && !IsMacro() ) {
453     RetVal =  DataFlowEditor()->SubStreamGraphsNumber() ;
454   }
455 //  endService( "StreamGraph_Impl::SubStreamGraphsNumber" );
456   return RetVal ;
457 }
458
459 SUPERV::ListOfNodes * StreamGraph_Impl::SubStreamGraphsNodes( const long aSubStreamGraphNumber ) {
460   beginService( "StreamGraph_Impl::SubStreamGraphsNodes" );
461   SUPERV::ListOfNodes_var RetVal = new SUPERV::ListOfNodes ;
462   if ( DataFlowEditor()->IsEditing() && !IsMacro() ) {
463     SUPERV::ListOfNodes * aGraphNodes = Nodes() ;
464     int i ;
465 // ComputingNodes
466     for ( i = 0 ; i < (int ) aGraphNodes->CNodes.length() ; i++ ) {
467       SUPERV::CNode_var aNode = (aGraphNodes->CNodes)[ i ] ;
468       if ( aNode->SubStreamGraph() == aSubStreamGraphNumber ) {
469         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
470       }
471     }
472 // FactoryNodes
473     for ( i = 0 ; i < (int ) aGraphNodes->FNodes.length() ; i++ ) {
474       SUPERV::FNode_var aNode = (aGraphNodes->FNodes)[ i ] ;
475       if ( aNode->SubStreamGraph() == aSubStreamGraphNumber ) {
476         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
477       }
478     }
479 // InLineNodes
480     for ( i = 0 ; i < (int ) aGraphNodes->INodes.length() ; i++ ) {
481       SUPERV::INode_var aNode = (aGraphNodes->INodes)[ i ] ;
482       if ( aNode->SubStreamGraph() == aSubStreamGraphNumber ) {
483         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
484       }
485     }
486 // GOTONodes
487     for ( i = 0 ; i < (int ) aGraphNodes->GNodes.length() ; i++ ) {
488       SUPERV::GNode_var aNode = (aGraphNodes->GNodes)[ i ] ;
489       if ( aNode->SubStreamGraph() == aSubStreamGraphNumber ) {
490         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
491       }
492     }
493 // LoopNodes
494     for ( i = 0 ; i < (int ) aGraphNodes->LNodes.length() ; i++ ) {
495       SUPERV::LNode_var aNode = (aGraphNodes->LNodes)[ i ] ;
496       if ( aNode->SubStreamGraph() == aSubStreamGraphNumber ) {
497         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
498       }
499     }
500 // EndLoopNodes
501     for ( i = 0 ; i < (int ) aGraphNodes->ELNodes.length() ; i++ ) {
502       SUPERV::ELNode_var aNode = (aGraphNodes->ELNodes)[ i ] ;
503       if ( aNode->SubStreamGraph() == aSubStreamGraphNumber ) {
504         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
505       }
506     }
507 // SwitchNodes
508     for ( i = 0 ; i < (int ) aGraphNodes->SNodes.length() ; i++ ) {
509       SUPERV::SNode_var aNode = (aGraphNodes->SNodes)[ i ] ;
510       if ( aNode->SubStreamGraph() == aSubStreamGraphNumber ) {
511         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
512       }
513     }
514 // EndSwitchNodes
515     for ( i = 0 ; i < (int ) aGraphNodes->ESNodes.length() ; i++ ) {
516       SUPERV::ESNode_var aNode = (aGraphNodes->ESNodes)[ i ] ;
517       if ( aNode->SubStreamGraph() == aSubStreamGraphNumber ) {
518         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
519       }
520     }
521   }
522   endService( "StreamGraph_Impl::SubStreamGraphsNodes" );
523   return ( RetVal._retn() ) ;
524 }
525
526 SUPERV::Graph_ptr StreamGraph_Impl::ToFlowGraph() {
527   SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
528   beginService( "StreamGraph_Impl::ToFlowGraph" );
529   if ( !IsMacro() ) {
530 //    Graph_Impl * myFlowGraph = new Graph_Impl( _Orb , _Poa , _ContId ,
531 //                                               instanceName() , interfaceName() ) ;
532 //    PortableServer::ObjectId * id = myFlowGraph->getId() ;
533 //    CORBA::Object_var obj = _poa->id_to_reference(*id);
534     if ( !CORBA::is_nil( DataFlowEditor()->StreamGraph()->ObjRef() ) ) {
535       iobject = SUPERV::Graph::_narrow( DataFlowEditor()->StreamGraph()->ObjRef() ) ;
536     }
537   }
538   endService( "StreamGraph_Impl::ToFlowGraph" );
539   return SUPERV::Graph::_duplicate( iobject ) ;
540 }
541
542 bool StreamGraph_Impl::StreamMerge(const SUPERV::StreamGraph_ptr aStreamGraph ) {
543   beginService( "StreamGraph_Impl::StreamMerge" );
544   bool RetVal = false ;
545   if ( !IsMacro() ) {
546     map< string , int > aMapOfNodes ;
547     RetVal = Merge( aStreamGraph , aMapOfNodes ) ;
548     if ( RetVal ) {
549       SUPERV::ListOfStreamLinks * aGraphLinks = aStreamGraph->GStreamLinks() ;
550       SUPERV::ListOfStreamPorts * aGraphPorts = aStreamGraph->StreamPorts() ;
551   //cout << "Graph_Impl::StreamMerge " << aGraphLinks->length() << " links " << aGraphPorts->length()
552 //           << " GraphPorts" << endl ;
553       int i ;
554       for ( i = 0 ; i < (int ) aGraphLinks->length() ; i++ ) {
555         SUPERV::StreamLink_var aLink = (*aGraphLinks)[ i ] ;
556         SUPERV::StreamPort_var OutPort = aLink->OutStreamPort() ;
557         SUPERV::StreamPort_var InPort = aLink->InStreamPort() ;
558         string * aLinkFromNodeName = new string( OutPort->Node()->Name() ) ;
559         string * aLinkToNodeName = new string( InPort->Node()->Name() ) ;
560   //cout << "Graph_Impl::StreamMerge " << aLinkFromNodeName << "(" << OutPort->Name() << ") ---> "
561 //             << aLinkToNodeName << "(" << InPort->Name() << ")" << endl ;
562         RetVal = DataFlowEditor()->AddLink( DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] )->Name() ,
563                                             OutPort->Name() ,
564                                             DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] )->Name() ,
565                                             InPort->Name() ) ;
566   //cout << "Graph_Impl::StreamMerge " << aLinkFromNodeName << "(" << OutPort->Name() << ") ---> "
567 //           << aLinkToNodeName << "(" << InPort->Name() << ") RetVal" << RetVal << endl ;
568         if ( RetVal ) {
569           int j ;
570           for ( j = 1 ; j <= aLink->CoordsSize() ; j++ ) {
571             long X , Y ;
572             RetVal = aLink->Coords( j , X , Y ) ;
573             if ( !RetVal )
574               break ;
575             RetVal = DataFlowEditor()->AddLinkCoord( DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] )->Name() ,
576                                                      OutPort->Name() ,
577                                                      DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] )->Name() ,
578                                                      InPort->Name() ,
579                                                      j , X , Y ) ;
580             if ( !RetVal ) {
581               break ;
582             }
583           }
584         }
585         delete aLinkFromNodeName ;
586         delete aLinkToNodeName ;
587         if ( !RetVal ) {
588           break ;
589         }
590       }
591       if ( RetVal ) {
592         for ( i = 0 ; i < (int ) aGraphPorts->length() ; i++ ) {
593           SUPERV::StreamPort_var aPort = (*aGraphPorts)[ i ] ;
594           if ( !aPort->IsGate() ) {
595             MESSAGE( "Graph_Impl::StreamMerge " << i << ". " << aPort->Node()->Name() << " " << aPort->Name() ) ;
596             char * aPortName = aPort->Name() ;
597             char * aNodeName = new char[ strlen( aPortName ) + 1 ] ;
598             strcpy( aNodeName , aPortName ) ;
599 //            char * thePortName = strchr( aNodeName , '\\' ) ;
600             char * thePortName = strchr( aNodeName , '_' ) ;
601             thePortName[ 0 ] = '\0' ;
602             bool hasinput = aStreamGraph->Node( aNodeName )->Port( thePortName + 1 )->HasInput() ;
603 //            cout << "Graph_Impl::StreamMerge " << " aNodeName " << aNodeName << " aPort " << thePortName + 1
604 //                 << " HasInput " << hasinput << endl ;
605             if ( hasinput ) {
606               RetVal = DataFlowEditor()->AddInputData( DataFlowEditor()->StreamGraph()->GetGraphNode( aMapOfNodes[ aNodeName ] )->Name() ,
607                                                        thePortName + 1 ,
608                                                        *(aPort->ToAny()) ) ;
609             }
610             delete [] aNodeName ;
611             if ( !RetVal ) {
612               break ;
613             }
614           }
615         }
616       }
617     }
618   }
619   endService( "StreamGraph_Impl::StreamMerge" );
620   return RetVal ;
621 }
622