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