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