Salome HOME
6602d2c7fdc10d8db64bf54e941a1badf02e7bbd
[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                      ( theNode != NULL && !theNode->IsEndSwitchNode() &&
269                        !strcmp( theNode->Name() , aNode->Name() ) ) ) {
270                   if ( anInPort->IsLoop() || anOutPort->IsLoop() ||
271                        ( aNode->IsEndLoopNode() && !strcmp( aNode->CoupledNode()->Name() ,
272                                                             anOutPort->NodeName() ) ) ) {
273                     MESSAGE( "StreamLink " << anOutPort->NodeName() << "("
274                             << anOutPort->PortName() << ") --> " << aNode->Name() << "("
275                             << anInPort->PortName() << ")" << " ignored" ) ;
276                   }
277                   else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
278                     if ( begin ) {
279                       beginService( "StreamGraph_Impl::StreamLinks" );
280                       begin = false ;
281                     }
282                     GraphEditor::InNode * anOutNode = NULL ;
283                     anOutNode = (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GetChangeGraphNode( anOutPort->NodeName() )->GetInNode() ;
284                     if ( anOutNode ) {
285                       bool Success ;
286                       StreamLink_Impl * myStreamLink = new StreamLink_Impl(
287                                             _Orb , _Poa , _ContId ,
288                                             instanceName() , interfaceName() ,
289                                             DataFlowEditor() ,
290                                             aNode ,
291                                             anInPort->PortName() ,
292                                             anOutNode ,
293                                             anOutPort->PortName() ,
294                                             false , Success ) ;
295                       if ( Success ) {
296                         PortableServer::ObjectId * id = myStreamLink->getId() ;
297                         CORBA::Object_var obj = _poa->id_to_reference(*id);
298                         SUPERV::StreamLink_var iobject ;
299                         iobject = SUPERV::StreamLink::_narrow(obj) ;
300                         RetVal->length( countlink + 1 ) ;
301                         RetVal[ countlink++ ] = SUPERV::StreamLink::_duplicate( iobject ) ;
302                         anOutPort->AddInPortObjRef( anInPort , SUPERV::StreamLink::_duplicate( iobject ) ) ;
303                         MESSAGE( "Link" << countlink-1 << " "
304                                  << RetVal[countlink-1]->OutStreamPort()->Node()->Name() << "("
305                                  << RetVal[countlink-1]->OutStreamPort()->Name() << ") --> "
306                                  << RetVal[countlink-1]->InStreamPort()->Node()->Name() << "("
307                                  << RetVal[countlink-1]->InStreamPort()->Name() << ")" ) ;
308                       }
309                     }
310                   }
311                   else {
312                     RetVal->length( countlink + 1 ) ;
313                     RetVal[ countlink++ ] = SUPERV::StreamLink::_duplicate( SUPERV::StreamLink::_narrow( anOutPort->InPortObjRef( anInPort ) ) ) ;
314                     MESSAGE( "Link" << countlink-1 << " "
315                              << RetVal[countlink-1]->OutStreamPort()->Node()->Name() << "("
316                              << RetVal[countlink-1]->OutStreamPort()->Name() << ") --> "
317                              << RetVal[countlink-1]->InStreamPort()->Node()->Name() << "("
318                              << RetVal[countlink-1]->InStreamPort()->Name() << ")" ) ;
319                   }
320                 }
321               }
322             }
323           }
324         }
325       }
326       for ( j = 0 ; j < aNode->GetNodeOutPortsSize() ; j++ ) {
327         GraphBase::OutPort * anOutPort = aNode->GetChangeNodeOutPort( j ) ;
328         int k ;
329         for ( k = 0 ; k < anOutPort->InPortsSize() ; k++ ) {
330           GraphBase::InPort * anInPort = anOutPort->ChangeInPorts( k ) ;
331           GraphEditor::InNode * toNode = (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GetChangeGraphNode( anInPort->NodeName() )->GetInNode() ;
332           if ( theNode == NULL ||
333                !strcmp( theNode->Name() , aNode->Name() ) ) {
334             if ( anInPort->IsDataStream() ) {
335               if ( theNode || ( toNode->IsEndSwitchNode() && !aNode->IsSwitchNode() ) ) {
336                 if ( anInputParam == NULL ||
337                      !strcmp( anInPort->PortName() , anInputParam ) ) {
338                   MESSAGE( "StreamLink " << anOutPort->NodeName() << "("
339                            << anOutPort->PortName() << ") --> " << toNode->Name() << "("
340                            << anInPort->PortName() << ")" ) ;
341                   MESSAGE( "           IOR " << DataFlowEditor()->ObjectToString( anOutPort->InPortObjRef( anInPort ) ) ) ;
342                   if ( anInPort->IsLoop() || anOutPort->IsLoop() ||
343                        ( toNode->IsEndLoopNode() && !strcmp( toNode->CoupledNode()->Name() ,
344                                                              anOutPort->NodeName() ) ) ) {
345                     MESSAGE( "StreamLink " << anOutPort->NodeName() << "("
346                              << anOutPort->PortName() << ") --> " << toNode->Name() << "("
347                              << anInPort->PortName() << ")" << " ignored" ) ;
348                   }
349                   else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
350                     if ( begin ) {
351                       beginService( "Graph_Impl::StreamLinks" );
352                       begin = false ;
353                     }
354                     bool Success ;
355                     StreamLink_Impl * myStreamLink = new StreamLink_Impl(
356                                           _Orb , _Poa , _ContId ,
357                                           instanceName() , interfaceName() ,
358                                           DataFlowEditor() ,
359                                           toNode ,
360                                           anInPort->PortName() ,
361                                           aNode ,
362                                           anOutPort->PortName() ,
363                                           false , Success ) ;
364                     if ( Success ) {
365                       PortableServer::ObjectId * id = myStreamLink->getId() ;
366                       CORBA::Object_var obj = _poa->id_to_reference(*id);
367                       SUPERV::StreamLink_var iobject ;
368                       iobject = SUPERV::StreamLink::_narrow(obj) ;
369                       RetVal->length( countlink + 1 ) ;
370                       RetVal[ countlink++ ] = SUPERV::StreamLink::_duplicate( iobject ) ;
371                       anOutPort->AddInPortObjRef( anInPort , SUPERV::StreamLink::_duplicate( iobject ) ) ;
372                       MESSAGE( "Link" << countlink-1 << " "
373                                << RetVal[countlink-1]->OutStreamPort()->Node()->Name() << "("
374                                << RetVal[countlink-1]->OutStreamPort()->Name() << ") --> "
375                                << RetVal[countlink-1]->InStreamPort()->Node()->Name() << "("
376                                << RetVal[countlink-1]->InStreamPort()->Name() << ")" ) ;
377                     }
378                   }
379                   else {
380                     RetVal->length( countlink + 1 ) ;
381                     RetVal[ countlink++ ] = SUPERV::StreamLink::_duplicate( SUPERV::StreamLink::_narrow( anOutPort->InPortObjRef( anInPort ) ) ) ;
382                     MESSAGE( "Link" << countlink-1 << " "
383                              << RetVal[countlink-1]->OutStreamPort()->Node()->Name() << "("
384                              << RetVal[countlink-1]->OutStreamPort()->Name() << ") --> "
385                              << RetVal[countlink-1]->InStreamPort()->Node()->Name() << "("
386                              << RetVal[countlink-1]->InStreamPort()->Name() << ")" ) ;
387                   }
388                 }
389                 else {
390                   MESSAGE( "StreamLink " << anOutPort->NodeName() << "("
391                            << anOutPort->PortName() << ") --> " << toNode->Name() << "("
392                            << anInPort->PortName() << ")" << " skipped" ) ;
393                 }
394               }
395             }
396           }
397         }
398       }
399     }
400 //#if 0
401     const char * NodeName = "" ;
402     const char * InputParamName = "" ;
403     if ( theNode ) {
404       NodeName = theNode->Name() ;
405     }
406     if ( anInputParam ) {
407       InputParamName = anInputParam ;
408     }
409     MESSAGE( RetVal->length() << " StreamLinks of Node " << NodeName << " and of InPort " << InputParamName ) ;
410     for ( i = 0 ; i < (int ) RetVal->length() ; i++ ) {
411       MESSAGE( "Link" << i << " " << RetVal[i]->OutStreamPort()->Node()->Name() << "("
412                << RetVal[i]->OutStreamPort()->Name() << ") --> "
413                << RetVal[i]->InStreamPort()->Node()->Name() << "("
414                << RetVal[i]->InStreamPort()->Name() << ")" ) ;
415     }
416 //#endif
417     if ( !begin ) {
418       endService( "StreamGraph_Impl::StreamLinks" );
419     }
420   }
421   return ( RetVal._retn() ) ;
422 }
423
424 bool StreamGraph_Impl::SetStreamParams( const long Timeout ,
425                                         const SUPERV::KindOfDataStreamTrace DataStreamTrace ,
426                                         const double  DeltaTime ) {
427   bool sts = false ;
428   if ( !IsMacro() ) {
429     sts = DataFlowEditor()->StreamGraph()->SetStreamParams( Timeout , DataStreamTrace , DeltaTime ) ;
430     if ( sts ) {
431       DataFlowEditor()->UnValid() ;
432     }
433   }
434   return sts ;
435 }
436
437 void StreamGraph_Impl::StreamParams( long & Timeout ,
438                                      SUPERV::KindOfDataStreamTrace & DataStreamTrace ,
439                                      double & DeltaTime ) {
440   if ( !IsMacro() ) {
441     DataFlowEditor()->StreamGraph()->StreamParams( Timeout , DataStreamTrace , DeltaTime ) ;
442   }
443 }
444
445 long StreamGraph_Impl::SubStreamGraphsNumber() {
446 //  beginService( "StreamGraph_Impl::StreamGraphsNumber" );
447   long RetVal = 0 ;
448   if ( DataFlowEditor()->IsExecutable() && !IsMacro() ) {
449     RetVal =  DataFlowEditor()->SubStreamGraphsNumber() ;
450   }
451 //  endService( "StreamGraph_Impl::SubStreamGraphsNumber" );
452   return RetVal ;
453 }
454
455 SUPERV::ListOfNodes * StreamGraph_Impl::SubStreamGraphsNodes( const long aSubStreamGraphNumber ) {
456   beginService( "StreamGraph_Impl::SubStreamGraphsNodes" );
457   SUPERV::ListOfNodes_var RetVal = new SUPERV::ListOfNodes ;
458   if ( DataFlowEditor()->IsEditing() && !IsMacro() ) {
459     SUPERV::ListOfNodes * aGraphNodes = Nodes() ;
460     int i ;
461 // ComputingNodes
462     for ( i = 0 ; i < (int ) aGraphNodes->CNodes.length() ; i++ ) {
463       SUPERV::CNode_var aNode = (aGraphNodes->CNodes)[ i ] ;
464       if ( aNode->SubStreamGraph() == aSubStreamGraphNumber ) {
465         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
466       }
467     }
468 // FactoryNodes
469     for ( i = 0 ; i < (int ) aGraphNodes->FNodes.length() ; i++ ) {
470       SUPERV::FNode_var aNode = (aGraphNodes->FNodes)[ i ] ;
471       if ( aNode->SubStreamGraph() == aSubStreamGraphNumber ) {
472         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
473       }
474     }
475 // InLineNodes
476     for ( i = 0 ; i < (int ) aGraphNodes->INodes.length() ; i++ ) {
477       SUPERV::INode_var aNode = (aGraphNodes->INodes)[ i ] ;
478       if ( aNode->SubStreamGraph() == aSubStreamGraphNumber ) {
479         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
480       }
481     }
482 // GOTONodes
483     for ( i = 0 ; i < (int ) aGraphNodes->GNodes.length() ; i++ ) {
484       SUPERV::GNode_var aNode = (aGraphNodes->GNodes)[ i ] ;
485       if ( aNode->SubStreamGraph() == aSubStreamGraphNumber ) {
486         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
487       }
488     }
489 // LoopNodes
490     for ( i = 0 ; i < (int ) aGraphNodes->LNodes.length() ; i++ ) {
491       SUPERV::LNode_var aNode = (aGraphNodes->LNodes)[ i ] ;
492       if ( aNode->SubStreamGraph() == aSubStreamGraphNumber ) {
493         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
494       }
495     }
496 // EndLoopNodes
497     for ( i = 0 ; i < (int ) aGraphNodes->ELNodes.length() ; i++ ) {
498       SUPERV::ELNode_var aNode = (aGraphNodes->ELNodes)[ i ] ;
499       if ( aNode->SubStreamGraph() == aSubStreamGraphNumber ) {
500         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
501       }
502     }
503 // SwitchNodes
504     for ( i = 0 ; i < (int ) aGraphNodes->SNodes.length() ; i++ ) {
505       SUPERV::SNode_var aNode = (aGraphNodes->SNodes)[ i ] ;
506       if ( aNode->SubStreamGraph() == aSubStreamGraphNumber ) {
507         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
508       }
509     }
510 // EndSwitchNodes
511     for ( i = 0 ; i < (int ) aGraphNodes->ESNodes.length() ; i++ ) {
512       SUPERV::ESNode_var aNode = (aGraphNodes->ESNodes)[ i ] ;
513       if ( aNode->SubStreamGraph() == aSubStreamGraphNumber ) {
514         RetVal = SetNode( RetVal , DataFlowEditor()->Graph()->GetChangeGraphNode( aNode->Name() ) ) ;
515       }
516     }
517   }
518   endService( "StreamGraph_Impl::SubStreamGraphsNodes" );
519   return ( RetVal._retn() ) ;
520 }
521
522 SUPERV::Graph_ptr StreamGraph_Impl::ToFlowGraph() {
523   SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
524   beginService( "StreamGraph_Impl::ToFlowGraph" );
525   if ( !IsMacro() ) {
526 //    Graph_Impl * myFlowGraph = new Graph_Impl( _Orb , _Poa , _ContId ,
527 //                                               instanceName() , interfaceName() ) ;
528 //    PortableServer::ObjectId * id = myFlowGraph->getId() ;
529 //    CORBA::Object_var obj = _poa->id_to_reference(*id);
530     if ( !CORBA::is_nil( DataFlowEditor()->StreamGraph()->ObjRef() ) ) {
531       iobject = SUPERV::Graph::_narrow( DataFlowEditor()->StreamGraph()->ObjRef() ) ;
532     }
533   }
534   endService( "StreamGraph_Impl::ToFlowGraph" );
535   return SUPERV::Graph::_duplicate( iobject ) ;
536 }
537
538 bool StreamGraph_Impl::StreamMerge(const SUPERV::StreamGraph_ptr aStreamGraph ) {
539   beginService( "StreamGraph_Impl::StreamMerge" );
540   bool RetVal = false ;
541   if ( !IsMacro() ) {
542     map< string , int > aMapOfNodes ;
543     RetVal = Merge( aStreamGraph , aMapOfNodes ) ;
544     if ( RetVal ) {
545       SUPERV::ListOfStreamLinks * aGraphLinks = aStreamGraph->GStreamLinks() ;
546       SUPERV::ListOfStreamPorts * aGraphPorts = aStreamGraph->StreamPorts() ;
547   //cout << "Graph_Impl::StreamMerge " << aGraphLinks->length() << " links " << aGraphPorts->length()
548 //           << " GraphPorts" << endl ;
549       int i ;
550       for ( i = 0 ; i < (int ) aGraphLinks->length() ; i++ ) {
551         SUPERV::StreamLink_var aLink = (*aGraphLinks)[ i ] ;
552         SUPERV::StreamPort_var OutPort = aLink->OutStreamPort() ;
553         SUPERV::StreamPort_var InPort = aLink->InStreamPort() ;
554         string * aLinkFromNodeName = new string( OutPort->Node()->Name() ) ;
555         string * aLinkToNodeName = new string( InPort->Node()->Name() ) ;
556   //cout << "Graph_Impl::StreamMerge " << aLinkFromNodeName << "(" << OutPort->Name() << ") ---> "
557 //             << aLinkToNodeName << "(" << InPort->Name() << ")" << endl ;
558         RetVal = DataFlowEditor()->AddLink( DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] )->Name() ,
559                                             OutPort->Name() ,
560                                             DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] )->Name() ,
561                                             InPort->Name() ) ;
562   //cout << "Graph_Impl::StreamMerge " << aLinkFromNodeName << "(" << OutPort->Name() << ") ---> "
563 //           << aLinkToNodeName << "(" << InPort->Name() << ") RetVal" << RetVal << endl ;
564         if ( RetVal ) {
565           int j ;
566           for ( j = 1 ; j <= aLink->CoordsSize() ; j++ ) {
567             long X , Y ;
568             RetVal = aLink->Coords( j , X , Y ) ;
569             if ( !RetVal )
570               break ;
571             RetVal = DataFlowEditor()->AddLinkCoord( DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] )->Name() ,
572                                                      OutPort->Name() ,
573                                                      DataFlowEditor()->Graph()->GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] )->Name() ,
574                                                      InPort->Name() ,
575                                                      j , X , Y ) ;
576             if ( !RetVal ) {
577               break ;
578             }
579           }
580         }
581         delete aLinkFromNodeName ;
582         delete aLinkToNodeName ;
583         if ( !RetVal ) {
584           break ;
585         }
586       }
587       if ( RetVal ) {
588         for ( i = 0 ; i < (int ) aGraphPorts->length() ; i++ ) {
589           SUPERV::StreamPort_var aPort = (*aGraphPorts)[ i ] ;
590           if ( !aPort->IsGate() ) {
591             MESSAGE( "Graph_Impl::StreamMerge " << i << ". " << aPort->Node()->Name() << " " << aPort->Name() ) ;
592             char * aPortName = aPort->Name() ;
593             char * aNodeName = new char[ strlen( aPortName ) + 1 ] ;
594             strcpy( aNodeName , aPortName ) ;
595 //            char * thePortName = strchr( aNodeName , '\\' ) ;
596             char * thePortName = strchr( aNodeName , '_' ) ;
597             thePortName[ 0 ] = '\0' ;
598             bool hasinput = aStreamGraph->Node( aNodeName )->Port( thePortName + 1 )->HasInput() ;
599 //            cout << "Graph_Impl::StreamMerge " << " aNodeName " << aNodeName << " aPort " << thePortName + 1
600 //                 << " HasInput " << hasinput << endl ;
601             if ( hasinput ) {
602               RetVal = DataFlowEditor()->AddInputData( DataFlowEditor()->StreamGraph()->GetGraphNode( aMapOfNodes[ aNodeName ] )->Name() ,
603                                                        thePortName + 1 ,
604                                                        *(aPort->ToAny()) ) ;
605             }
606             delete [] aNodeName ;
607             if ( !RetVal ) {
608               break ;
609             }
610           }
611         }
612       }
613     }
614   }
615   endService( "StreamGraph_Impl::StreamMerge" );
616   return RetVal ;
617 }
618