Salome HOME
Fix for bug PAL78476: when out-port is added to study, it must try to put its value...
[modules/superv.git] / src / GraphBase / DataFlowBase_PortsOfNode.cxx
1 //  SUPERV GraphBase : contains fondamental classes for Services, Input Ports, Output Ports Links and Nodes.
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   : DataFlowBase_PortsOfNode.cxx
25 //  Author : Jean Rahuel, CEA
26 //  Module : SUPERV
27 //  $Header:
28
29 using namespace std;
30 #include "DataFlowBase_PortsOfNode.hxx"
31
32 GraphBase::PortsOfNode::PortsOfNode() :
33   GraphBase::Service::Service( SALOME_ModuleCatalog::Service() ) {
34 //  MESSAGE( "GraphBase::PortsOfNode::PortsOfNode "  << this ) ;
35 //  cout << "GraphBase::PortsOfNode::PortsOfNode "  << this << endl ;
36 //  cdebug << "GraphBase::PortsOfNode::PortsOfNode "  << this << endl ;
37   _NodeInPortsSize = 0 ;
38   _NodeOutPortsSize = 0 ;
39   _DataStreamInPortsNumber = 0 ;
40   _DataStreamOutPortsNumber = 0 ;
41 }
42
43 GraphBase::PortsOfNode::PortsOfNode( const char *DataFlowName ) :
44   GraphBase::Service::Service( SALOME_ModuleCatalog::Service() ) {
45 //  MESSAGE( "GraphBase::PortsOfNode::PortsOfNode "  << this ) ;
46 //  cout << "GraphBase::PortsOfNode::PortsOfNode "  << this << endl ;
47 //  cdebug << "GraphBase::PortsOfNode::PortsOfNode "  << this << endl ;
48   _NodeInPortsSize = 0 ;
49   _NodeOutPortsSize = 0 ;
50   _DataStreamInPortsNumber = 0 ;
51   _DataStreamOutPortsNumber = 0 ;
52 }
53
54 GraphBase::PortsOfNode::~PortsOfNode() {
55   cdebug << "GraphBase::PortsOfNode::~PortsOfNode "  << this 
56          << endl ;
57 //  int i ;
58 //  for ( i = 0 ; i < _NodeInPortsSize ; i++ ) {
59 //    delete _NodeInPorts[ i ] ;
60 //  }
61 //  for ( i = 0 ; i < _NodeOutPortsSize ; i++ ) {
62 //    delete _NodeOutPorts[ i ] ;
63 //  }
64 }
65
66 void GraphBase::PortsOfNode::DefPortsOfNode(
67                            CORBA::ORB_ptr ORB ,
68                            const SALOME_ModuleCatalog::Service& aService ,
69                            const char *const * NodeName ,
70                            const SUPERV::KindOfNode aKind ,
71                            int * Graph_prof_debug ,
72                            ofstream * Graph_fdebug ) {
73   int i ;
74   SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
75 //  MESSAGE( "DefPortsOfNode " << NodeName << " Graph_prof_debug  "
76 //           << Graph_prof_debug << " _prof_debug " << _prof_debug ) ;
77   cdebug_in << "DefPortsOfNode : " << *NodeName << " ServiceName " << aService.ServiceName << endl ;
78   const bool DataFlowOrComputing = (aKind == SUPERV::DataFlowGraph) ||
79                                    (aKind == SUPERV::ComputingNode) ||
80                                    (aKind == SUPERV::FactoryNode) ;
81 // WithInLoop : InitLoop or DoLoop
82   const bool WithInLoop = (aKind == SUPERV::LoopNode) || (aKind == SUPERV::EndLoopNode) ;
83 // WithInGate : InGate or Default
84   const bool WithInGate = (aKind == SUPERV::DataFlowGraph) || (aKind == SUPERV::DataStreamGraph) ||
85                           (aKind == SUPERV::ComputingNode) || (aKind == SUPERV::FactoryNode) ||
86                           (aKind == SUPERV::InLineNode) || (aKind == SUPERV::GOTONode) ||
87                           (aKind == SUPERV::LoopNode) || (aKind == SUPERV::EndLoopNode) ||
88                           (aKind == SUPERV::SwitchNode) || (aKind == SUPERV::EndSwitchNode) ||
89                           (aKind == SUPERV::MacroNode) ;
90 // WithOutGate : OutGate or Default
91   const bool WithOutGate = (aKind == SUPERV::DataFlowGraph) || (aKind == SUPERV::DataStreamGraph) ||
92                            (aKind == SUPERV::ComputingNode) || (aKind == SUPERV::FactoryNode) ||
93                            (aKind == SUPERV::InLineNode) || (aKind == SUPERV::GOTONode) ||
94                              /* asv : 15.12.04 : adding out gate ports for Loop/EndLoop, too. p2.5, PAL7385*/
95                            (aKind == SUPERV::LoopNode) || (aKind == SUPERV::EndLoopNode) ||
96                            (aKind == SUPERV::SwitchNode) || (aKind == SUPERV::EndSwitchNode) ||
97                            (aKind == SUPERV::MacroNode) ;
98   SUPERV::KindOfPort aPortKind = SUPERV::ServiceParameter ;
99   if ( aKind == SUPERV::InLineNode ) {
100     aPortKind = SUPERV::InLineParameter ;
101   }
102   else if ( aKind == SUPERV::LoopNode || aKind == SUPERV::EndLoopNode ) {
103     aPortKind = SUPERV::InLineParameter ;
104   }
105   else if ( aKind == SUPERV::SwitchNode || aKind == SUPERV::EndSwitchNode ) {
106     aPortKind = SUPERV::InLineParameter ;
107   }
108   else if ( aKind == SUPERV::GOTONode ) {
109     aPortKind = SUPERV::InLineParameter ;
110   }
111   else if ( aKind == SUPERV::MacroNode ) {
112     aPortKind = SUPERV::InLineParameter ;
113   }
114   for ( i = 0 ; i < _NodeInPortsSize ; i++ ) {
115     cdebug << "DefPortsOfNode delete In" << i << ". "  << _NodeInPorts[i] 
116            << endl ;
117     _MapOfNodeInPorts.erase( _NodeInPorts[i]->PortName() ) ;
118     delete _NodeInPorts[i] ;
119   }
120   _NodeInPorts.resize( 0 );
121   for ( i = 0 ; i < _NodeOutPortsSize ; i++ ) {
122     cdebug << "DefPortsOfNode delete Out" << i << ". " << _NodeOutPorts[i]->PortName() 
123            << endl ;
124     _MapOfNodeOutPorts.erase( _NodeOutPorts[i]->PortName() ) ;
125     delete _NodeOutPorts[i] ;
126   }
127   _NodeOutPorts.resize( 0 );
128
129   SetService( aService ) ;
130
131   int iVec = 0 ;
132   _NodeInPortsSize = aService.ServiceinParameter.length() ;
133   if ( WithInLoop ) {
134     SALOME_ModuleCatalog::ServicesParameter anInLoopParameter ;
135     _NodeInPortsSize = _NodeInPortsSize + 1 ;
136     iVec += 1 ;
137 //    char *aParametername = "InitLoop" ;
138 //    if ( aKind == SUPERV::EndLoopNode ) {
139       char * aParametername = "DoLoop" ;
140 //    }
141     anInLoopParameter.Parametertype = CORBA::string_dup( "long" ) ;
142     anInLoopParameter.Parametername = CORBA::string_dup( aParametername ) ;
143     if ( _NodeInPortsSize > (int ) _NodeInPorts.size() ) {
144       _NodeInPorts.resize( _NodeInPortsSize );
145     }
146     _MapOfNodeInPorts[ aParametername ] = iVec ;
147     _NodeInPorts[iVec-1] = new GraphBase::InPort( NodeName , anInLoopParameter ,
148                                                   SUPERV::LoopParameter );
149     _NodeInPorts[iVec-1]->SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
150     cdebug << "DefPortsOfNode : " << "_MapOfNodeInPorts[ " << aParametername
151            << " ] = " << iVec << " " << _NodeInPorts[iVec-1]->Kind() << " "
152             << _NodeInPorts[iVec-1]  << endl ;
153   }
154   if ( _NodeInPortsSize > (int ) _NodeInPorts.size() ) {
155     _NodeInPorts.resize(_NodeInPortsSize);
156   }
157   cdebug << "NodeInPortsSize " << _NodeInPortsSize << endl ;
158   for ( i = iVec ; i < _NodeInPortsSize ; i++ ) {
159     string _aParametername = CORBA::string_dup(aService.ServiceinParameter[i-iVec].Parametername) ;
160     const char *aParametername = _aParametername.c_str() ;
161     if ( _MapOfNodeInPorts[ aParametername ] ) {
162       if ( !DataFlowOrComputing &&
163            !strcmp( aParametername , "Gate" ) ) {
164       }
165       else {
166         cdebug << "Error, Parametername duplicated : " << aParametername
167                << endl ;
168       }
169     }
170     else {
171       _MapOfNodeInPorts[ aParametername ] = i+1 ;
172 //      cdebug << "DefPortsOfNode : " << "_MapOfNodeInPorts[ " << aParametername
173 //             << " ] = " << i+1 << endl ;
174       const SALOME_ModuleCatalog::ServicesParameter aServiceParameter = aService.ServiceinParameter[i-iVec] ;
175       _NodeInPorts[i] = new GraphBase::InPort( NodeName , aServiceParameter ,
176                                                aPortKind );
177       _NodeInPorts[i]->SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
178 //      cdebug << i << ". " << *_NodeInPorts[i] << " " << _NodeInPorts[i]->Kind() << endl ;
179     }
180   }
181   iVec += aService.ServiceinParameter.length() ;
182   if ( WithInGate ) {
183     SALOME_ModuleCatalog::ServicesParameter anInGateParameter ;
184     _NodeInPortsSize = _NodeInPortsSize + 1 ;
185     iVec += 1 ;
186     char *aParametername = "Gate" ;
187     if ( aKind == SUPERV::EndSwitchNode ) {
188       aParametername = "Default" ;
189     }
190     anInGateParameter.Parametertype = CORBA::string_dup( "long" ) ;
191     anInGateParameter.Parametername = CORBA::string_dup( aParametername ) ;
192     _NodeInPorts.resize( _NodeInPortsSize );
193     _MapOfNodeInPorts[ aParametername ] = iVec ;
194     _NodeInPorts[iVec-1] = new GraphBase::InPort( NodeName , anInGateParameter ,
195                                                   SUPERV::GateParameter );
196     _NodeInPorts[iVec-1]->SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
197 //    cdebug << "DefPortsOfNode : " << "_MapOfNodeInPorts[ " << aParametername
198 //           << " ] = " << iVec << " " << _NodeInPorts[iVec-1]->Kind() << " "
199 //            << _NodeInPorts[iVec-1]  << endl ;
200   }
201   
202   iVec = 0 ;
203   _NodeOutPortsSize = aService.ServiceoutParameter.length() ;
204   if ( WithInLoop ) {
205     SALOME_ModuleCatalog::ServicesParameter anOutLoopParameter ;
206     _NodeOutPortsSize = _NodeOutPortsSize + 1 ;
207     iVec += 1 ;
208     char *aParametername = "DoLoop" ;
209     anOutLoopParameter.Parametertype = CORBA::string_dup( "long" ) ;
210     anOutLoopParameter.Parametername = CORBA::string_dup( aParametername ) ;
211     if ( _NodeOutPortsSize > (int ) _NodeOutPorts.size() ) {
212       _NodeOutPorts.resize(_NodeOutPortsSize);
213     }
214     _MapOfNodeOutPorts[ aParametername ] = iVec ;
215     _NodeOutPorts[iVec-1] = new GraphBase::OutPort( NodeName , anOutLoopParameter ,
216                                                     SUPERV::LoopParameter );
217     _NodeOutPorts[iVec-1]->SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
218 //    cdebug << "DefPortsOfNode : " << "_MapOfNodeOutPorts[ " << aParametername
219 //           << " ] = " << iVec << " " << _NodeOutPorts[iVec-1]->Kind() << " "
220 //           << _NodeOutPorts[iVec-1]  << endl ;
221   }
222   if ( _NodeOutPortsSize > (int ) _NodeOutPorts.size() ) {
223     _NodeOutPorts.resize(_NodeOutPortsSize);
224   }
225   cdebug << "NodeOutPortsSize " << _NodeOutPortsSize << endl ;
226   for ( i = iVec ; i < _NodeOutPortsSize ; i++ ) {
227     string _aParametername = CORBA::string_dup(aService.ServiceoutParameter[i-iVec].Parametername) ;
228     const char *aParametername = _aParametername.c_str() ;
229     if ( _MapOfNodeOutPorts[ aParametername ] ) {
230       if ( !DataFlowOrComputing &&
231            !strcmp( aParametername , "Gate" ) ) {
232       }
233       else {
234         cdebug << "Error, Parametername duplicated : " << aParametername
235                << endl ;
236       }
237     }
238     else {
239 //      cdebug << "DefPortsOfNode : " << "_MapOfNodeOutPorts[ " << aParametername
240 //             << " ] = " << i+1 << endl ;
241       _MapOfNodeOutPorts[ aParametername ] = i+1 ;
242       const SALOME_ModuleCatalog::ServicesParameter aServiceParameter = aService.ServiceoutParameter[i-iVec] ;
243       _NodeOutPorts[i] = new GraphBase::OutPort( NodeName , aServiceParameter ,
244                                                  aPortKind );
245       _NodeOutPorts[i]->SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
246 //      cdebug << i << ". " << *_NodeOutPorts[i] << " " << _NodeOutPorts[i]->Kind() << endl ;
247     }
248   }
249   iVec += aService.ServiceoutParameter.length() ;
250   if ( WithOutGate ) {
251     SALOME_ModuleCatalog::ServicesParameter anOutGateParameter ;
252     _NodeOutPortsSize = _NodeOutPortsSize + 1 ;
253     iVec += 1 ;
254     char *aParametername = "Gate" ;
255     if ( aKind == SUPERV::SwitchNode ) {
256       aParametername = "Default" ;
257     }
258     anOutGateParameter.Parametertype = CORBA::string_dup( "long" ) ;
259     anOutGateParameter.Parametername = CORBA::string_dup( aParametername ) ;
260     _NodeOutPorts.resize(_NodeOutPortsSize);
261     _MapOfNodeOutPorts[ aParametername ] = iVec ;
262     _NodeOutPorts[iVec-1] = new GraphBase::OutPort( NodeName , anOutGateParameter ,
263                                                     SUPERV::GateParameter );
264     _NodeOutPorts[iVec-1]->SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
265 //    cdebug << "DefPortsOfNode : " << "_MapOfNodeOutPorts[ " << aParametername
266 //           << " ] = " << iVec << " " << _NodeOutPorts[iVec-1]->Kind() << " "
267 //           << _NodeOutPorts[iVec-1]  << endl ;
268   }
269   cdebug_out << "DefPortsOfNode : " << *NodeName << endl ;
270 }
271
272 GraphBase::InPort * GraphBase::PortsOfNode::AddInPort( CORBA::ORB_ptr ORB ,
273                                                        const char *const * NodeName ,
274                                                        const SUPERV::KindOfNode aKindOfNode ,
275                                                        const char * InputParameterName ,
276                                                        const char * InputParameterType ,
277                                                        SUPERV::KindOfPort aKindOfPort ,
278                                                        int index ,
279                                                        int * Graph_prof_debug ,
280                                                        ofstream * Graph_fdebug ) {
281 //  MESSAGE( "DefPortsOfNode " << *NodeName << " Graph_prof_debug "
282 //           << Graph_prof_debug << " _prof_debug " << _prof_debug ) ;
283   cdebug_in << "PortsOfNode::AddInPort : " << *NodeName << " " << aKindOfNode << " InputParameterName "
284             << InputParameterName << " InputParameterType " << InputParameterType << " aKindOfPort "
285             << aKindOfPort << " DataStreamInPortsNumber " << DataStreamInPortsNumber() << " _NodeInPortsSize "
286             << _NodeInPortsSize << " index " << index << endl ;
287   GraphBase::InPort * anInPort = NULL ;
288 //  int index = 0 ;
289   anInPort = GetChangeInPort( InputParameterName ) ;
290   if ( anInPort == NULL ) {
291     _NodeInPortsSize = _NodeInPortsSize + 1 ;
292     _NodeInPorts.resize(_NodeInPortsSize);
293     SALOME_ModuleCatalog::ServicesParameter aServiceParameter ;
294     aServiceParameter.Parametername = CORBA::string_dup( InputParameterName ) ;
295     aServiceParameter.Parametertype = CORBA::string_dup( InputParameterType ) ;
296     if ( index != -1 ) {
297     }
298     else if ( aKindOfPort == SUPERV::DataStreamParameter ) {
299       index = _NodeInPortsSize-2 ;
300       IncrDataStreamInPorts() ;
301     }
302     else {
303       index = _NodeInPortsSize-2 - DataStreamInPortsNumber() ;
304     }
305     if ( index >= 0 ) {
306       int i ;
307       for ( i = _NodeInPortsSize - 2 ; i >= index ; i-- ) {
308         _NodeInPorts[ i + 1 ] = _NodeInPorts[ i ] ; // Gate - Default
309         _MapOfNodeInPorts.erase( _NodeInPorts[ i + 1 ]->PortName() ) ;
310         _MapOfNodeInPorts[ _NodeInPorts[ i + 1 ]->PortName() ] =  i + 2 ;
311       }
312       _MapOfNodeInPorts[ InputParameterName ] = index + 1 ;
313       if ( aKindOfPort == SUPERV::DataStreamParameter ) {
314         _NodeInPorts[index] = new GraphBase::InDataStreamPort( NodeName ,
315                                                                aServiceParameter ) ;
316       }
317       else {
318         _NodeInPorts[index] = new GraphBase::InPort( NodeName ,
319                                                      aServiceParameter ,
320                                                      aKindOfPort ) ;
321       }
322       _NodeInPorts[index]->SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
323       anInPort = _NodeInPorts[index] ;
324       cdebug << "NodeInPorts[ " << index << " ]" << endl ;
325     }
326     else {
327       cdebug << "GraphBase::PortsOfNode::AddInPort ERROR index " << index << " _NodeInPortsSize "
328              << _NodeInPortsSize  << endl ;
329     }
330   }
331   else {
332     cdebug << "GraphBase::PortsOfNode::AddInPort InPort already exists" << endl ;
333     anInPort->Kind( aKindOfPort ) ;
334   }
335   cdebug << "GraphBase::PortsOfNode::AddInPort index " << index << " _NodeInPortsSize " << _NodeInPortsSize  << endl ;
336 //#if 0
337   int i ;
338   for ( i = 0 ; i < _NodeInPortsSize ; i++ ) {
339     cdebug << *NodeName << " _NodeInPorts[ " << i << " ] = " << _NodeInPorts[ i ]->PortName()
340            << " _MapOfNodeInPorts[ " << _NodeInPorts[ i ]->PortName() << " ] = "
341            << _MapOfNodeInPorts[ _NodeInPorts[ i ]->PortName() ] << " - 1 "
342            << _NodeInPorts[ i ]->Kind() << " Dependency " << _NodeInPorts[ i ]->Dependency() ;
343     if ( _NodeInPorts[ i ]->IsDataStream() ) {
344        SUPERV::KindOfSchema aKindOfSchema ;
345        SUPERV::KindOfInterpolation aKindOfInterpolation ;
346        SUPERV::KindOfExtrapolation aKindOfExtrapolation ;
347        ((GraphBase::InDataStreamPort * ) _NodeInPorts[ i ])->Params( aKindOfSchema , aKindOfInterpolation , aKindOfExtrapolation ) ;
348        cdebug << " " << aKindOfSchema << " " << aKindOfInterpolation << " " << aKindOfExtrapolation ;
349     }
350     if ( _NodeInPorts[ i ]->GetOutPort() ) {
351       cdebug << " <--OutPort " << _NodeInPorts[ i ]->GetOutPort()
352              << " " << _NodeInPorts[ i ]->GetOutPort()->NodeName()
353              << "(" << _NodeInPorts[ i ]->GetOutPort()->PortName() << ")" ;
354     }
355     else {
356       cdebug << " <--NOOutPort " << _NodeInPorts[ i ]->GetOutPort() ;
357     }
358     cdebug << " " << _NodeInPorts[ i ]->PortStatus() << endl ;
359   }
360 //#endif
361   cdebug_out << "GraphBase::PortsOfNode::AddInPort _NodeInPortsSize " << _NodeInPortsSize
362              << " " << anInPort->Kind() << endl ;
363   return anInPort ;
364 }
365
366 GraphBase::OutPort * GraphBase::PortsOfNode::AddOutPort( CORBA::ORB_ptr ORB ,
367                                                          const char * const * NodeName ,
368                                                          const SUPERV::KindOfNode aKindOfNode ,
369                                                          const char * OutputParameterName ,
370                                                          const char * OutputParameterType ,
371                                                          SUPERV::KindOfPort aKindOfPort ,
372                                                          int index ,
373                                                          int * Graph_prof_debug ,
374                                                          ofstream * Graph_fdebug ) {
375   cdebug_in << "GraphBase::PortsOfNode::AddOutPort : " << *NodeName << " " << aKindOfNode
376             << " OutputParameterName " << OutputParameterName << " OutputParameterType " << OutputParameterType
377             << " aKindOfPort " << aKindOfPort << " DataStreamOutPortsNumber " << DataStreamOutPortsNumber()
378             << " _NodeOutPortsSize " << _NodeOutPortsSize << " index " << index << endl ;
379   GraphBase::OutPort * anOutPort = NULL ;
380 //  int index = 0 ;
381   anOutPort = GetChangeOutPort( OutputParameterName ) ;
382   if ( anOutPort == NULL ) {
383     _NodeOutPortsSize = _NodeOutPortsSize + 1 ;
384     _NodeOutPorts.resize(_NodeOutPortsSize);
385     SALOME_ModuleCatalog::ServicesParameter aServiceParameter ;
386     aServiceParameter.Parametername = CORBA::string_dup( OutputParameterName ) ;
387     aServiceParameter.Parametertype = CORBA::string_dup( OutputParameterType ) ;
388     if ( index != -1 ) {
389     }
390     else if ( aKindOfPort == SUPERV::DataStreamParameter ) {
391       index = _NodeOutPortsSize-2 ;
392       IncrDataStreamOutPorts() ;
393     }
394     else {
395       index = _NodeOutPortsSize-2 - DataStreamOutPortsNumber() ;
396     }
397     if ( aKindOfNode == SUPERV::LoopNode || aKindOfNode == SUPERV::EndLoopNode ) {
398       index += 1 ;
399     }
400     if ( index >= 0 ) {
401       int i ;
402       for ( i = _NodeOutPortsSize - 2 ; i >= index ; i-- ) {
403         _NodeOutPorts[ i + 1 ] = _NodeOutPorts[ i ] ; // Gate - Default
404         _MapOfNodeOutPorts.erase( _NodeOutPorts[ i + 1 ]->PortName() ) ;
405         _MapOfNodeOutPorts[ _NodeOutPorts[ i + 1 ]->PortName() ] =  i + 2 ;
406       }
407       _MapOfNodeOutPorts[ OutputParameterName ] = index + 1 ;
408       if ( aKindOfPort == SUPERV::DataStreamParameter ) {
409         _NodeOutPorts[index] = new GraphBase::OutDataStreamPort( NodeName ,
410                                                                aServiceParameter ) ;
411       }
412       else {
413         _NodeOutPorts[index] = new GraphBase::OutPort( NodeName ,
414                                                        aServiceParameter ,
415                                                        aKindOfPort );
416       }
417 //    MESSAGE( "GraphBase::PortsOfNode::AddOutPort " << OutputParameterName << " --> SetDebug" ) ;
418       _NodeOutPorts[index]->SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
419       anOutPort = _NodeOutPorts[index] ;
420       cdebug << "NodeOutPorts[ " << index << " ]" << endl ;
421     }
422     else {
423       cdebug << "GraphBase::PortsOfNode::AddOutPort ERROR index " << index << " _NodeOutPortsSize "
424              << _NodeOutPortsSize  << endl ;
425     }
426   }
427   else {
428     cdebug << "GraphBase::PortsOfNode::AddOutPort OutPort already exists" << endl ;
429     anOutPort->Kind( aKindOfPort ) ;
430   }
431   cdebug << "GraphBase::PortsOfNode::AddOutPort index " << index << " _NodeOutPortsSize " << _NodeOutPortsSize  << endl ;
432 //#if 0
433   int i ;
434   for ( i = 0 ; i < _NodeOutPortsSize ; i++ ) {
435     cdebug << *NodeName << " _NodeOutPorts[ " << i << " ] = " << _NodeOutPorts[ i ]->PortName()
436            << " _MapOfNodeOutPorts[ " << _NodeOutPorts[ i ]->PortName() << " ] = "
437            << _MapOfNodeOutPorts[ _NodeOutPorts[ i ]->PortName() ] << " - 1 "
438            << _NodeOutPorts[ i ]->Kind() << " Dependency " << _NodeOutPorts[ i ]->Dependency() ;
439     if ( _NodeOutPorts[ i ]->IsDataStream() ) {
440        cdebug << " NumberOfValues " << ((GraphBase::OutDataStreamPort * ) _NodeOutPorts[ i ])->NumberOfValues() ;
441     }
442     cdebug << " " << _NodeOutPorts[ i ]->PortStatus() << endl ;
443   }
444 //#endif
445   cdebug_out << "GraphBase::PortsOfNode::AddOutPort _NodeOutPortsSize "
446              << _NodeOutPortsSize << " " << anOutPort->Kind() << endl ;
447   return anOutPort ;
448 }
449
450 void GraphBase::PortsOfNode::MoveInPort( const char * InputParameterName , int toindex ) {
451   int fromindex = _MapOfNodeInPorts[ InputParameterName ] - 1 ;
452   GraphBase::InPort * anInPort = _NodeInPorts[ toindex ] ;
453   _NodeInPorts[ toindex ] =  _NodeInPorts[ fromindex ] ;
454   _NodeInPorts[ fromindex ] = anInPort ;
455   _MapOfNodeInPorts.erase( _NodeInPorts[ toindex ]->PortName() ) ;
456   _MapOfNodeInPorts[ _NodeInPorts[ toindex ]->PortName() ] = toindex + 1  ;
457   _MapOfNodeInPorts.erase( _NodeInPorts[ fromindex ]->PortName() ) ;
458   _MapOfNodeInPorts[ _NodeInPorts[ fromindex ]->PortName() ] = fromindex + 1  ;
459 }
460
461 void GraphBase::PortsOfNode::MoveOutPort( const char * OutputParameterName , int toindex ) {
462   int fromindex = _MapOfNodeOutPorts[ OutputParameterName ] - 1 ;
463   GraphBase::OutPort * anOutPort = _NodeOutPorts[ toindex ] ;
464   _NodeOutPorts[ toindex ] =  _NodeOutPorts[ fromindex ] ;
465   _NodeOutPorts[ fromindex ] = anOutPort ;
466   _MapOfNodeOutPorts.erase( _NodeOutPorts[ toindex ]->PortName() ) ;
467   _MapOfNodeOutPorts[ _NodeOutPorts[ toindex ]->PortName() ] = toindex + 1  ;
468   _MapOfNodeOutPorts.erase( _NodeOutPorts[ fromindex ]->PortName() ) ;
469   _MapOfNodeOutPorts[ _NodeOutPorts[ fromindex ]->PortName() ] = fromindex + 1  ;
470 }
471
472 void GraphBase::PortsOfNode::DelInPort( const char * InputParameterName ) {
473   cdebug << "DefPortsOfNode::DelInPort : " << InputParameterName << endl ;
474   int index = _MapOfNodeInPorts[ InputParameterName ] -1 ;
475   if ( index >= 0 ) {
476     cdebug << "DefPortsOfNode::DelInPort : _NodeInPorts[" << index << "] "
477            << _NodeInPorts[ index ]->PortName() << " "
478            << _NodeInPorts[ index ]->NodeName() << endl ;
479     if ( _NodeInPorts[ index ]->IsDataStream() ) {
480       DecrDataStreamInPorts() ;
481     }
482     _MapOfNodeInPorts.erase( InputParameterName ) ;
483     _NodeInPorts[ index ]->destroy() ;
484     int i ;
485     for ( i = index ; i < _NodeInPortsSize - 1 ; i++ ) {
486       _MapOfNodeInPorts.erase( _NodeInPorts[ i+1 ]->PortName() ) ;
487       _MapOfNodeInPorts[ _NodeInPorts[ i+1 ]->PortName() ] = i+1 ;
488       _NodeInPorts[ i ] = _NodeInPorts[ i+1 ] ;
489     }
490     _NodeInPortsSize = _NodeInPortsSize - 1 ;
491     _NodeInPorts.resize( _NodeInPortsSize ) ;
492     for ( i = 0 ; i < _NodeInPortsSize ; i++ ) {
493       cdebug << "DefPortsOfNode::DelInPort ListOfInPorts : _NodeInPorts[" << i << "] "
494              << _NodeInPorts[ i ]->PortName() << " "
495              << _NodeInPorts[ i ]->NodeName() << endl ;
496     }
497   }
498   else {
499     cdebug << "DefPortsOfNode::DelInPort : index out of range ERROR " << index
500            << endl ;
501   }
502 }
503
504 void GraphBase::PortsOfNode::DelOutPort( const char * OutputParameterName ) {
505   cdebug << "DefPortsOfNode::DelOutPort : " << OutputParameterName << endl ;
506   int index = _MapOfNodeOutPorts[ OutputParameterName ] - 1 ;
507   if ( index >= 0 ) {
508     cdebug << "DefPortsOfNode::DelOutPort : _NodeOutPorts[" << index << "] "
509            << _NodeOutPorts[ index ]->PortName() << " "
510            << _NodeOutPorts[ index ]->NodeName() << endl ;
511     if ( _NodeOutPorts[ index ]->IsDataStream() ) {
512       DecrDataStreamOutPorts() ;
513     }
514     _MapOfNodeOutPorts.erase( OutputParameterName ) ;
515     _NodeOutPorts[ index ]->destroy() ;
516     int i ;
517     for ( i = index ; i < _NodeOutPortsSize - 1 ; i++ ) {
518       _MapOfNodeOutPorts.erase( _NodeOutPorts[ i+1 ]->PortName() ) ;
519       _MapOfNodeOutPorts[ _NodeOutPorts[ i+1 ]->PortName() ] = i+1 ;
520       _NodeOutPorts[ i ] = _NodeOutPorts[ i+1 ] ;
521     }
522     _NodeOutPortsSize = _NodeOutPortsSize - 1 ;
523     _NodeOutPorts.resize( _NodeOutPortsSize ) ;
524     for ( i = 0 ; i < _NodeOutPortsSize ; i++ ) {
525       cdebug << "DefPortsOfNode::DelOutPort ListOfOutPorts : _NodeOutPorts[" << i
526              << "] " << _NodeOutPorts[ i ]->PortName() << " "
527              << _NodeOutPorts[ i ]->NodeName() << endl ;
528     }
529   }
530   else {
531     cdebug << "DefPortsOfNode::DelOutPort : index out of range ERROR " << index
532            << endl ;
533   }
534 }
535
536 const GraphBase::InPort *GraphBase::PortsOfNode::GetInPort( const char *name) {
537  return GetChangeInPort( name ) ;
538 }
539
540 const GraphBase::OutPort *GraphBase::PortsOfNode::GetOutPort( const char *name) {
541  return GetChangeOutPort( name ) ;
542 }
543
544 GraphBase::InPort *GraphBase::PortsOfNode::GetChangeInPort( const char * name) {
545 //  cdebug_in << "GraphBase::PortsOfNode::GetChangeInPort " << name << endl;
546
547   GraphBase::InPort * pP = NULL;
548   if ( !_MapOfNodeInPorts.empty() ) {
549     int index = 0 ;
550     if ( !strcmp( name , "InGate" ) ) {
551       index = _MapOfNodeInPorts[ "Gate" ] ;
552     }
553     else {
554       index = _MapOfNodeInPorts[ name ] ;
555     }
556     if ( index > 0 ) {
557 //      cdebug << "GraphBase::PortsOfNode::GetChangeInPort _MapOfNodeInPorts[ "
558 //             << name << " ] : " << i-1 << " " << _NodeInPorts[ i-1 ]->NodeName()
559 //             << endl ;
560       pP = _NodeInPorts[ index-1 ] ;
561     }
562     else {
563       cdebug << "GraphBase::PortsOfNode::GetChangeInPort _MapOfNodeInPorts[ "
564              << name << " ] : " << index << " NOT FOUND. Known ports :" << endl ;
565 #if 1
566       map< string , int >::iterator aMapOfNodeInPortsIterator ;
567       int i = 0 ;
568       for ( aMapOfNodeInPortsIterator = _MapOfNodeInPorts.begin() ;
569             aMapOfNodeInPortsIterator != _MapOfNodeInPorts.end() ; aMapOfNodeInPortsIterator++ ) {
570         cdebug << "MapOfNodeInPorts" << i++ << " " << aMapOfNodeInPortsIterator->first << " --> "
571                << aMapOfNodeInPortsIterator->second << endl ;
572       }
573 #endif
574     }
575   }
576 //  cdebug_out << "GraphBase::PortsOfNode::GetChangeInPort " << endl;
577
578   return pP;
579 }
580
581 GraphBase::OutPort *GraphBase::PortsOfNode::GetChangeOutPort( const char * name ) {
582 //  cdebug_in << "GraphBase::PortsOfNode::GetChangeOutPort " << name << endl;
583
584   GraphBase::OutPort * pP = NULL;
585   if ( !_MapOfNodeOutPorts.empty() ) {
586     int index = 0 ;
587     if ( !strcmp( name , "OutGate" ) ) {
588       index = _MapOfNodeOutPorts[ "Gate" ] ;
589     }
590     else {
591       index = _MapOfNodeOutPorts[ name ] ;
592     }
593     if ( index > 0 ) {
594 //      cdebug << "GraphBase::PortsOfNode::GetChangeOutPort _MapOfNodeOutPorts[ "
595 //             << name << " ] : " << i-1 << " " << _NodeOutPorts[ i-1 ]->NodeName() << endl ;
596       pP = _NodeOutPorts[ index-1 ] ;
597     }
598     else {
599       cdebug << "GraphBase::PortsOfNode::GetChangeOutPort _MapOfNodeOutPorts[ "
600              << name << " ] : " << index << " NOT FOUND. Known ports :" << endl ;
601 #if 1
602       map< string , int >::iterator aMapOfNodeOutPortsIterator ;
603       int i = 0 ;
604       for ( aMapOfNodeOutPortsIterator = _MapOfNodeOutPorts.begin() ;
605             aMapOfNodeOutPortsIterator != _MapOfNodeOutPorts.end() ; aMapOfNodeOutPortsIterator++ ) {
606         cdebug << "MapOfNodeInPorts" << i++ << " " << aMapOfNodeOutPortsIterator->first << " --> "
607                << aMapOfNodeOutPortsIterator->second << endl ;
608       }
609 #endif
610     }
611   }
612   return pP;
613 }
614
615 void GraphBase::PortsOfNode::ListPorts( ostream & f,
616                                         const bool klink ) const {
617
618   int i ;
619
620   f << "      Input Ports : " ;
621   if ( klink ) {
622     f << GetNodeInPortsSize() << " port" 
623       << (GetNodeInPortsSize() > 1 ? "s" : "") << endl;
624
625     for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
626       f << "         Port "
627 //        << hex << GetNodeInPort(i) << dec << " "
628         << *(GetNodeInPort(i)) << " " ;
629       GetNodeInPort(i)->StringValue( f ) ;
630       f << endl;
631     }
632
633     f << "      Output Ports : " ;
634   }
635
636   f << GetNodeOutPortsSize() << " port" 
637     << (GetNodeOutPortsSize() > 1 ? "s" : "") << endl;
638
639   for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
640     f << "         Port "
641 //      << hex << GetNodeOutPort(i) << dec << " "
642       << *(GetNodeOutPort(i)) << " " ;
643     GetNodeOutPort(i)->StringValue( f ) ;
644     f << endl;
645   }
646
647   if ( !klink ) {
648     f << "      Output Ports : " ;
649     f << GetNodeInPortsSize() << " port" 
650       << (GetNodeInPortsSize() > 1 ? "s" : "") << endl;
651
652     for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
653       f << "         Port "
654 //        << hex << GetNodeInPort(i) << dec << " "
655         << *(GetNodeInPort(i)) << " " ;
656       GetNodeInPort(i)->StringValue( f ) ;
657       f << endl;
658     }
659   }
660
661 }
662
663 ostream & operator<< (ostream & f ,const SUPERV::KindOfNode & s ) {
664   switch (s) {
665   case SUPERV::ComputingNode :
666     f << "ComputingNode";
667     break;
668   case SUPERV::FactoryNode :
669     f << "FactoryNode";
670     break;
671   case SUPERV::InLineNode :
672     f << "InLineNode";
673     break;
674   case SUPERV::MacroNode :
675     f << "MacroNode";
676     break;
677   case SUPERV::DataFlowGraph :
678     f << "DataFlowGraph";
679     break;
680   case SUPERV::DataStreamGraph :
681     f << "DataStreamGraph";
682     break;
683   case SUPERV::LoopNode :
684     f << "LoopNode";
685     break;
686   case SUPERV::EndLoopNode :
687     f << "EndLoopNode";
688     break;
689   case SUPERV::SwitchNode :
690     f << "SwitchNode";
691     break;
692   case SUPERV::EndSwitchNode :
693     f << "EndSwitchNode";
694     break;
695   case SUPERV::GOTONode :
696     f << "GOTONode";
697     break;
698   default :
699     f << "UnknownKindOfNode";
700     break;
701   }
702
703   return f;
704 }
705