Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[modules/superv.git] / src / GraphBase / DataFlowBase_Port.cxx
1 //  SUPERV GraphBase : contains fondamental classes for Services, Input Ports, Output Ports Links and Nodes.
2 //
3 //  Copyright (C) 2003  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : DataFlowBase_Port.cxx
8 //  Author : Jean Rahuel, CEA
9 //  Module : SUPERV
10 //  $Header:
11
12 using namespace std;
13 #include "DataFlowBase_Port.hxx"
14
15 //GraphBase::Port::~Port() {
16 //  cout << "Port::~Port()" << endl ;
17 //}
18
19 bool GraphBase::Port::AddCoord( const int nxy , const int *x ,
20                                 const int *y ) {
21   int i ;
22   if ( IsEndSwitch() ) {
23     return false ;
24   }
25   else {
26     _X.resize( nxy ) ;
27     _Y.resize( nxy ) ;
28     for ( i = 0 ; i < nxy ; i++ ) {
29       _X[ i ] = x[ i ] ;
30       _Y[ i ] = y[ i ] ;
31     }
32   }
33   return true ;
34 }
35
36 bool GraphBase::Port::AddCoord( const int index ,
37                                 const int x , const int y ) {
38   if ( IsEndSwitch() ) {
39     return false ;
40   }
41   else {
42     if ( index <= 0 || index > (int ) _X.size()+1 )
43       return false ;
44     _X.resize( _X.size()+1 ) ;
45     _Y.resize( _Y.size()+1 ) ;
46     int i ;
47     for ( i = _X.size() - 1 ; i >= index  ; i-- ) {
48       _X[ i ] = _X[ i-1 ] ;
49       _Y[ i ] = _Y[ i-1 ] ;
50     }
51     _X[ index - 1 ] = x ;
52     _Y[ index - 1 ] = y ;
53 //    cdebug << "AddCoord " << NodeName() << "(" << PortName() << ") ["
54 //           << index-1 << "] " << x << " " << y << endl ;
55 //    for ( i = 0 ; i <  _X.size() ; i++ ) {
56 //      cdebug << " [" << i << "] " << _X[ i ] << " " << _Y[ i ] << endl ;
57 //    }
58   }
59   return true ;
60 }
61
62 bool GraphBase::Port::ChangeCoord( const int index ,
63                                    const int x ,
64                                    const int y ) {
65   if ( IsEndSwitch() ) {
66     return false ;
67   }
68   else {
69     if ( index <= 0 || index > (int ) _X.size() )
70       return false ;
71     _X[ index - 1 ] = x ;
72     _Y[ index - 1 ] = y ;
73 //    cdebug << "ChangeCoord " << NodeName() << "(" << PortName() << ") ["
74 //           << index-1 << "] " << x << " " << y << endl ;
75 //    int i ;
76 //    for ( i = 0 ; i <  _X.size() ; i++ ) {
77 //      cdebug << " [" << i << "] " << _X[ i ] << " " << _Y[ i ] << endl ;
78 //    }
79   }
80   return true ;
81 }
82
83 bool GraphBase::Port::RemoveCoord( const int index ) {
84   if ( IsEndSwitch() ) {
85     return false ;
86   }
87   else {
88     if ( index <= 0 || index > (int ) _X.size() )
89       return false ;
90     int i ;
91     for ( i = index - 1 ; i < (int ) _X.size() - 1 ; i++ ) {
92       _X[ i ] = _X[ i+1 ] ;
93       _Y[ i ] = _Y[ i+1 ] ;
94     }
95     _X.resize( _X.size()-1 ) ;
96     _Y.resize( _Y.size()-1 ) ;
97   }
98   return true ;
99 }
100
101 bool GraphBase::Port::RemoveCoords() {
102   if ( IsEndSwitch() ) {
103     return false ;
104   }
105   else {
106     _X.resize( 0 ) ;
107     _Y.resize( 0 ) ;
108   }
109   return true ;
110 }
111
112 int GraphBase::Port::GetCoord() const {
113   int npt ;
114   if ( IsEndSwitch() ) {
115     return false ;
116   }
117   else {
118     npt = _X.size() ;
119   }
120   return npt ;
121 }
122
123 bool GraphBase::Port::GetCoord( int *x , int *y ) const {
124   int i ;
125   if ( IsEndSwitch() ) {
126     return false ;
127   }
128   else {
129     for ( i = 0 ; i < (int ) _X.size() ; i++ ) {
130       x[ i ] = _X[ i ] ;
131       y[ i ] = _Y[ i ] ;
132     }
133   }
134   return true ;
135 }
136
137 const GraphBase::ListOfCoords * GraphBase::Port::Coords() const {
138   GraphBase::ListOfCoords * _list_Coords = new GraphBase::ListOfCoords ;
139   int i ;
140   if ( !IsEndSwitch() ) {
141     _list_Coords->resize( _X.size() );
142     for ( i = 0 ; i < (int ) _X.size() ; i++ ) {
143       (*_list_Coords)[ i ].theX = _X[ i ] ;
144       (*_list_Coords)[ i ].theY = _Y[ i ] ;
145     }
146   }
147   return _list_Coords ;
148 }
149
150 bool GraphBase::Port::GetCoord( const int index , CORBA::Long &x , CORBA::Long &y ) const {
151   if ( IsEndSwitch() ) {
152     return false ;
153   }
154   else {
155     if ( index <= 0 || index > (int ) _X.size() )
156       return false ;
157     x = _X[ index - 1 ] ;
158     y = _Y[ index - 1 ] ;
159 //    cdebug << "GetCoord " << NodeName() << "(" << PortName() << ") ["
160 //           << index-1 << "] " << x << " " << y << endl ;
161 //    int i ;
162 //    for ( i = 0 ; i <  _X.size() ; i++ ) {
163 //      cdebug << " [" << i << "] " << _X[ i ] << " " << _Y[ i ] << endl ;
164 //    }
165   }
166   return true ;
167 }
168
169 ostream & operator<< (ostream & f ,const SUPERV::KindOfPort & s ) {
170   switch (s) {
171   case SUPERV::UndefinedParameter :
172     f << "UndefinedParameter";
173     break;
174   case SUPERV::ServiceParameter :
175     f << "ServiceParameter";
176     break;
177   case SUPERV::GateParameter :
178     f << "GateParameter";
179     break;
180   case SUPERV::InLineParameter :
181     f << "InLineParameter";
182     break;
183   case SUPERV::LoopParameter :
184     f << "LoopParameter";
185     break;
186   case SUPERV::SwitchParameter :
187     f << "SwitchParameter";
188     break;
189   case SUPERV::EndSwitchParameter :
190     f << "EndSwitchParameter";
191     break;
192   case SUPERV::GOTOParameter :
193     f << "GOTOParameter";
194     break;
195   case SUPERV::DataStreamParameter :
196     f << "DataStreamParameter";
197     break;
198   default :
199     f << "UnknownKindOfPort";
200     break;
201   }
202
203   return f;
204 }
205
206 ostream & operator<< (ostream & f ,const SALOME_ModuleCatalog::DataStreamDependency & s ) {
207   switch (s) {
208   case SALOME_ModuleCatalog::DATASTREAM_UNDEFINED :
209     f << "DATASTREAM_UNDEFINED";
210     break;
211   case SALOME_ModuleCatalog::DATASTREAM_TEMPORAL :
212     f << "DATASTREAM_TEMPORAL";
213     break;
214   case SALOME_ModuleCatalog::DATASTREAM_ITERATIVE :
215     f << "DATASTREAM_ITERATIVE";
216     break;
217   default :
218     f << "DATASTREAM_?";
219     break;
220   }
221
222   return f;
223 }
224
225 ostream & operator<< (ostream & f ,const StatusOfPort & s ) {
226   switch (s) {
227   case NotConnected :
228     f << "NotConnected";
229     break;
230   case PortConnected :
231     f << "PortConnected";
232     break;
233 //  case PortAndDataConnected :
234 //    f << "PortAndDataConnected";
235 //    break;
236   case DataConnected :
237     f << "DataConnected";
238     break;
239   case ExternConnected :
240     f << "ExternConnected";
241     break;
242   default :
243     f << "UnknownStatusOfPort";
244     break;
245   }
246
247   return f;
248 }