Salome HOME
There was an error in the update of OutPort of Loop/EndLoopNodes (not used in the...
[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 //JR Debug 01.09.2005 : GraphEditGraphSwitchs for AddOutPort and not in AddInPort ???
402 //    if ( aKindOfNode == SUPERV::LoopNode || aKindOfNode == SUPERV::EndLoopNode ) {
403 //      index += 1 ;
404 //    }
405     if ( index >= 0 ) {
406       int i ;
407       for ( i = _NodeOutPortsSize - 2 ; i >= index ; i-- ) {
408         _NodeOutPorts[ i + 1 ] = _NodeOutPorts[ i ] ; // Gate - Default
409         _MapOfNodeOutPorts.erase( _NodeOutPorts[ i + 1 ]->PortName() ) ;
410         _MapOfNodeOutPorts[ _NodeOutPorts[ i + 1 ]->PortName() ] =  i + 2 ;
411       }
412       _MapOfNodeOutPorts[ OutputParameterName ] = index + 1 ;
413       if ( aKindOfPort == SUPERV::DataStreamParameter ) {
414         _NodeOutPorts[index] = new GraphBase::OutDataStreamPort( NodeName ,
415                                                                aServiceParameter ) ;
416       }
417       else {
418         _NodeOutPorts[index] = new GraphBase::OutPort( NodeName ,
419                                                        aServiceParameter ,
420                                                        aKindOfPort );
421       }
422 //    MESSAGE( "GraphBase::PortsOfNode::AddOutPort " << OutputParameterName << " --> SetDebug" ) ;
423       _NodeOutPorts[index]->SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
424       anOutPort = _NodeOutPorts[index] ;
425       cdebug << "NodeOutPorts[ " << index << " ]" << endl ;
426     }
427     else {
428       cdebug << "GraphBase::PortsOfNode::AddOutPort ERROR index " << index << " _NodeOutPortsSize "
429              << _NodeOutPortsSize  << endl ;
430     }
431   }
432   else {
433     cdebug << "GraphBase::PortsOfNode::AddOutPort OutPort already exists" << endl ;
434     anOutPort->Kind( aKindOfPort ) ;
435   }
436   cdebug << "GraphBase::PortsOfNode::AddOutPort index " << index << " _NodeOutPortsSize " << _NodeOutPortsSize  << endl ;
437 //#if 0
438   int i ;
439   for ( i = 0 ; i < _NodeOutPortsSize ; i++ ) {
440     cdebug << *NodeName << " _NodeOutPorts[ " << i << " ] = " << _NodeOutPorts[ i ]->PortName()
441            << " _MapOfNodeOutPorts[ " << _NodeOutPorts[ i ]->PortName() << " ] = "
442            << _MapOfNodeOutPorts[ _NodeOutPorts[ i ]->PortName() ] << " - 1 "
443            << _NodeOutPorts[ i ]->Kind() << " Dependency " << _NodeOutPorts[ i ]->Dependency() ;
444     if ( _NodeOutPorts[ i ]->IsDataStream() ) {
445        cdebug << " NumberOfValues " << ((GraphBase::OutDataStreamPort * ) _NodeOutPorts[ i ])->NumberOfValues() ;
446     }
447     cdebug << " " << _NodeOutPorts[ i ]->PortStatus() << endl ;
448   }
449 //#endif
450   cdebug_out << "GraphBase::PortsOfNode::AddOutPort _NodeOutPortsSize "
451              << _NodeOutPortsSize << " " << anOutPort->Kind() << endl ;
452   return anOutPort ;
453 }
454
455 void GraphBase::PortsOfNode::MoveInPort( const char * InputParameterName , int toindex ) {
456   int fromindex = _MapOfNodeInPorts[ InputParameterName ] - 1 ;
457   GraphBase::InPort * anInPort = _NodeInPorts[ toindex ] ;
458   _NodeInPorts[ toindex ] =  _NodeInPorts[ fromindex ] ;
459   _NodeInPorts[ fromindex ] = anInPort ;
460   _MapOfNodeInPorts.erase( _NodeInPorts[ toindex ]->PortName() ) ;
461   _MapOfNodeInPorts[ _NodeInPorts[ toindex ]->PortName() ] = toindex + 1  ;
462   _MapOfNodeInPorts.erase( _NodeInPorts[ fromindex ]->PortName() ) ;
463   _MapOfNodeInPorts[ _NodeInPorts[ fromindex ]->PortName() ] = fromindex + 1  ;
464 }
465
466 void GraphBase::PortsOfNode::MoveOutPort( const char * OutputParameterName , int toindex ) {
467   int fromindex = _MapOfNodeOutPorts[ OutputParameterName ] - 1 ;
468   GraphBase::OutPort * anOutPort = _NodeOutPorts[ toindex ] ;
469   _NodeOutPorts[ toindex ] =  _NodeOutPorts[ fromindex ] ;
470   _NodeOutPorts[ fromindex ] = anOutPort ;
471   _MapOfNodeOutPorts.erase( _NodeOutPorts[ toindex ]->PortName() ) ;
472   _MapOfNodeOutPorts[ _NodeOutPorts[ toindex ]->PortName() ] = toindex + 1  ;
473   _MapOfNodeOutPorts.erase( _NodeOutPorts[ fromindex ]->PortName() ) ;
474   _MapOfNodeOutPorts[ _NodeOutPorts[ fromindex ]->PortName() ] = fromindex + 1  ;
475 }
476
477 void GraphBase::PortsOfNode::DelInPort( const char * InputParameterName ) {
478   cdebug << "DefPortsOfNode::DelInPort : " << InputParameterName << endl ;
479   int index = _MapOfNodeInPorts[ InputParameterName ] -1 ;
480   if ( index >= 0 ) {
481     cdebug << "DefPortsOfNode::DelInPort : _NodeInPorts[" << index << "] "
482            << _NodeInPorts[ index ]->PortName() << " "
483            << _NodeInPorts[ index ]->NodeName() << endl ;
484 //PAL9122
485 //JR Debug 08.06.2005 : RemoveOutPort was missing
486     _NodeInPorts[ index ]->RemoveOutPort() ;
487     if ( _NodeInPorts[ index ]->IsDataStream() ) {
488       DecrDataStreamInPorts() ;
489     }
490     _MapOfNodeInPorts.erase( InputParameterName ) ;
491     _NodeInPorts[ index ]->destroy() ;
492     int i ;
493     for ( i = index ; i < _NodeInPortsSize - 1 ; i++ ) {
494       _MapOfNodeInPorts.erase( _NodeInPorts[ i+1 ]->PortName() ) ;
495       _MapOfNodeInPorts[ _NodeInPorts[ i+1 ]->PortName() ] = i+1 ;
496       _NodeInPorts[ i ] = _NodeInPorts[ i+1 ] ;
497     }
498     _NodeInPortsSize = _NodeInPortsSize - 1 ;
499     _NodeInPorts.resize( _NodeInPortsSize ) ;
500     for ( i = 0 ; i < _NodeInPortsSize ; i++ ) {
501       cdebug << "DefPortsOfNode::DelInPort ListOfInPorts : _NodeInPorts[" << i << "] "
502              << _NodeInPorts[ i ]->PortName() << " "
503              << _NodeInPorts[ i ]->NodeName() << endl ;
504     }
505   }
506   else {
507     cdebug << "DefPortsOfNode::DelInPort : index out of range ERROR " << index
508            << endl ;
509   }
510 }
511
512 void GraphBase::PortsOfNode::DelOutPort( const char * OutputParameterName ) {
513   cdebug << "DefPortsOfNode::DelOutPort : " << OutputParameterName << endl ;
514   int index = _MapOfNodeOutPorts[ OutputParameterName ] - 1 ;
515   if ( index >= 0 ) {
516     cdebug << "DefPortsOfNode::DelOutPort : _NodeOutPorts[" << index << "] "
517            << _NodeOutPorts[ index ]->PortName() << " "
518            << _NodeOutPorts[ index ]->NodeName() << endl ;
519     if ( _NodeOutPorts[ index ]->IsDataStream() ) {
520       DecrDataStreamOutPorts() ;
521     }
522     _MapOfNodeOutPorts.erase( OutputParameterName ) ;
523     _NodeOutPorts[ index ]->destroy() ;
524     int i ;
525     for ( i = index ; i < _NodeOutPortsSize - 1 ; i++ ) {
526       _MapOfNodeOutPorts.erase( _NodeOutPorts[ i+1 ]->PortName() ) ;
527       _MapOfNodeOutPorts[ _NodeOutPorts[ i+1 ]->PortName() ] = i+1 ;
528       _NodeOutPorts[ i ] = _NodeOutPorts[ i+1 ] ;
529     }
530     _NodeOutPortsSize = _NodeOutPortsSize - 1 ;
531     _NodeOutPorts.resize( _NodeOutPortsSize ) ;
532     for ( i = 0 ; i < _NodeOutPortsSize ; i++ ) {
533       cdebug << "DefPortsOfNode::DelOutPort ListOfOutPorts : _NodeOutPorts[" << i
534              << "] " << _NodeOutPorts[ i ]->PortName() << " "
535              << _NodeOutPorts[ i ]->NodeName() << endl ;
536     }
537   }
538   else {
539     cdebug << "DefPortsOfNode::DelOutPort : index out of range ERROR " << index
540            << endl ;
541   }
542 }
543
544 const GraphBase::InPort *GraphBase::PortsOfNode::GetInPort( const char *name) {
545  return GetChangeInPort( name ) ;
546 }
547
548 const GraphBase::OutPort *GraphBase::PortsOfNode::GetOutPort( const char *name) {
549  return GetChangeOutPort( name ) ;
550 }
551
552 GraphBase::InPort *GraphBase::PortsOfNode::GetChangeInPort( const char * name) {
553 #if PortsOfNodeTrace
554   cdebug_in << "GraphBase::PortsOfNode::GetChangeInPort Service " << ServiceName()
555             << " of OutPort " << name << endl;
556 #endif
557
558   GraphBase::InPort * pP = NULL;
559   if ( !_MapOfNodeInPorts.empty() ) {
560     int index = 0 ;
561     if ( !strcmp( name , "InGate" ) ) {
562       index = _MapOfNodeInPorts[ "Gate" ] ;
563     }
564     else {
565       index = _MapOfNodeInPorts[ name ] ;
566     }
567     if ( index > 0 ) {
568 #if PortsOfNodeTrace
569       cdebug << "GraphBase::PortsOfNode::GetChangeInPort _MapOfNodeInPorts[ "
570              << name << " ] : " << index-1 << " " << _NodeInPorts[ index-1 ]->NodeName()
571              << endl ;
572 #endif
573       pP = _NodeInPorts[ index-1 ] ;
574     }
575     else {
576 #if PortsOfNodeTrace
577       cdebug << "GraphBase::PortsOfNode::GetChangeInPort Service " << ServiceName()
578              << " _MapOfNodeInPorts[ " << name << " ] : " << index << " NOT FOUND. Known ports :"
579              << endl ;
580       map< string , int >::iterator aMapOfNodeInPortsIterator ;
581       int i = 0 ;
582       for ( aMapOfNodeInPortsIterator = _MapOfNodeInPorts.begin() ;
583             aMapOfNodeInPortsIterator != _MapOfNodeInPorts.end() ; aMapOfNodeInPortsIterator++ ) {
584         cdebug << "MapOfNodeInPorts" << i++ << " " << aMapOfNodeInPortsIterator->first << " --> "
585                << aMapOfNodeInPortsIterator->second << endl ;
586       }
587 #endif
588     }
589   }
590 #if PortsOfNodeTrace
591   cdebug_out << "GraphBase::PortsOfNode::GetChangeInPort " << endl;
592 #endif
593
594   return pP;
595 }
596
597 GraphBase::OutPort *GraphBase::PortsOfNode::GetChangeOutPort( const char * name ) {
598 #if PortsOfNodeTrace
599   cdebug_in << "GraphBase::PortsOfNode::GetChangeOutPort " << name << endl;
600 #endif
601
602   GraphBase::OutPort * pP = NULL;
603   if ( !_MapOfNodeOutPorts.empty() ) {
604     int index = 0 ;
605     if ( !strcmp( name , "OutGate" ) ) {
606       index = _MapOfNodeOutPorts[ "Gate" ] ;
607     }
608     else {
609       index = _MapOfNodeOutPorts[ name ] ;
610     }
611     if ( index > 0 ) {
612 #if PortsOfNodeTrace
613       cdebug << "GraphBase::PortsOfNode::GetChangeOutPort _MapOfNodeOutPorts[ "
614              << name << " ] : " << index-1 << " " << _NodeOutPorts[ index-1 ]->NodeName() << endl ;
615 #endif
616       pP = _NodeOutPorts[ index-1 ] ;
617     }
618     else {
619 #if PortsOfNodeTrace
620       cdebug << "GraphBase::PortsOfNode::GetChangeOutPort _MapOfNodeOutPorts[ "
621              << name << " ] : " << index << " NOT FOUND. Known ports :" << endl ;
622       map< string , int >::iterator aMapOfNodeOutPortsIterator ;
623       int i = 0 ;
624       for ( aMapOfNodeOutPortsIterator = _MapOfNodeOutPorts.begin() ;
625             aMapOfNodeOutPortsIterator != _MapOfNodeOutPorts.end() ; aMapOfNodeOutPortsIterator++ ) {
626         cdebug << "MapOfNodeInPorts" << i++ << " " << aMapOfNodeOutPortsIterator->first << " --> "
627                << aMapOfNodeOutPortsIterator->second << endl ;
628       }
629 #endif
630     }
631   }
632 #if PortsOfNodeTrace
633   cdebug_out << "GraphBase::PortsOfNode::GetChangeOutPort " << endl;
634 #endif
635   return pP;
636 }
637
638 void GraphBase::PortsOfNode::ListPorts( ostream & f,
639                                         const bool klink ) const {
640
641   int i ;
642
643   f << "      Input Ports : " ;
644   if ( klink ) {
645     f << GetNodeInPortsSize() << " port" 
646       << (GetNodeInPortsSize() > 1 ? "s" : "") << endl;
647
648     for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
649       f << "         Port "
650 //        << hex << GetNodeInPort(i) << dec << " "
651         << *(GetNodeInPort(i)) << " " ;
652       GetNodeInPort(i)->StringValue( f ) ;
653       f << endl;
654     }
655
656     f << "      Output Ports : " ;
657   }
658
659   f << GetNodeOutPortsSize() << " port" 
660     << (GetNodeOutPortsSize() > 1 ? "s" : "") << endl;
661
662   for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
663     f << "         Port "
664 //      << hex << GetNodeOutPort(i) << dec << " "
665       << *(GetNodeOutPort(i)) << " " ;
666     GetNodeOutPort(i)->StringValue( f ) ;
667     f << endl;
668   }
669
670   if ( !klink ) {
671     f << "      Output Ports : " ;
672     f << GetNodeInPortsSize() << " port" 
673       << (GetNodeInPortsSize() > 1 ? "s" : "") << endl;
674
675     for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
676       f << "         Port "
677 //        << hex << GetNodeInPort(i) << dec << " "
678         << *(GetNodeInPort(i)) << " " ;
679       GetNodeInPort(i)->StringValue( f ) ;
680       f << endl;
681     }
682   }
683
684 }
685
686 ostream & operator<< (ostream & f ,const SUPERV::KindOfNode & s ) {
687   switch (s) {
688   case SUPERV::ComputingNode :
689     f << "ComputingNode";
690     break;
691   case SUPERV::FactoryNode :
692     f << "FactoryNode";
693     break;
694   case SUPERV::InLineNode :
695     f << "InLineNode";
696     break;
697   case SUPERV::MacroNode :
698     f << "MacroNode";
699     break;
700   case SUPERV::DataFlowGraph :
701     f << "DataFlowGraph";
702     break;
703   case SUPERV::DataStreamGraph :
704     f << "DataStreamGraph";
705     break;
706   case SUPERV::LoopNode :
707     f << "LoopNode";
708     break;
709   case SUPERV::EndLoopNode :
710     f << "EndLoopNode";
711     break;
712   case SUPERV::SwitchNode :
713     f << "SwitchNode";
714     break;
715   case SUPERV::EndSwitchNode :
716     f << "EndSwitchNode";
717     break;
718   case SUPERV::GOTONode :
719     f << "GOTONode";
720     break;
721   default :
722     f << "UnknownKindOfNode";
723     break;
724   }
725
726   return f;
727 }
728