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