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