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