]> SALOME platform Git repositories - modules/superv.git/blob - src/GraphBase/DataFlowBase_Port.cxx
Salome HOME
NRI : First integration.
[modules/superv.git] / src / GraphBase / DataFlowBase_Port.cxx
1 using namespace std;
2 //=============================================================================
3 // File      : DataFlowBase_Port.cxx
4 // Created   : 2002
5 // Author    : Jean Rahuel, CEA
6 // Project   : SALOME
7 // $Header:
8 //=============================================================================
9
10 #include "DataFlowBase_Port.hxx"
11
12 //GraphBase::Port::~Port() {
13 //  cout << "Port::~Port()" << endl ;
14 //}
15
16 bool GraphBase::Port::AddCoord( const int nxy , const int *x ,
17                                 const int *y ) {
18   int i ;
19   if ( IsEndSwitch() ) {
20     return false ;
21   }
22   else {
23     _X.resize( nxy ) ;
24     _Y.resize( nxy ) ;
25     for ( i = 0 ; i < nxy ; i++ ) {
26       _X[ i ] = x[ i ] ;
27       _Y[ i ] = y[ i ] ;
28     }
29   }
30   return true ;
31 }
32
33 bool GraphBase::Port::AddCoord( const int index ,
34                                 const int x , const int y ) {
35   if ( IsEndSwitch() ) {
36     return false ;
37   }
38   else {
39     if ( index <= 0 || index > _X.size()+1 )
40       return false ;
41     _X.resize( _X.size()+1 ) ;
42     _Y.resize( _Y.size()+1 ) ;
43     int i ;
44     for ( i = _X.size() - 1 ; i >= index  ; i-- ) {
45       _X[ i ] = _X[ i-1 ] ;
46       _Y[ i ] = _Y[ i-1 ] ;
47     }
48     _X[ index - 1 ] = x ;
49     _Y[ index - 1 ] = y ;
50 //    cdebug << "AddCoord " << NodeName() << "(" << PortName() << ") ["
51 //           << index-1 << "] " << x << " " << y << endl ;
52 //    for ( i = 0 ; i <  _X.size() ; i++ ) {
53 //      cdebug << " [" << i << "] " << _X[ i ] << " " << _Y[ i ] << endl ;
54 //    }
55   }
56   return true ;
57 }
58
59 bool GraphBase::Port::ChangeCoord( const int index ,
60                                    const int x ,
61                                    const int y ) {
62   if ( IsEndSwitch() ) {
63     return false ;
64   }
65   else {
66     if ( index <= 0 || index > _X.size() )
67       return false ;
68     _X[ index - 1 ] = x ;
69     _Y[ index - 1 ] = y ;
70 //    cdebug << "ChangeCoord " << NodeName() << "(" << PortName() << ") ["
71 //           << index-1 << "] " << x << " " << y << endl ;
72 //    int i ;
73 //    for ( i = 0 ; i <  _X.size() ; i++ ) {
74 //      cdebug << " [" << i << "] " << _X[ i ] << " " << _Y[ i ] << endl ;
75 //    }
76   }
77   return true ;
78 }
79
80 bool GraphBase::Port::RemoveCoord( const int index ) {
81   if ( IsEndSwitch() ) {
82     return false ;
83   }
84   else {
85     if ( index <= 0 || index > _X.size() )
86       return false ;
87     int i ;
88     for ( i = index - 1 ; i < _X.size() - 1 ; i++ ) {
89       _X[ i ] = _X[ i+1 ] ;
90       _Y[ i ] = _Y[ i+1 ] ;
91     }
92     _X.resize( _X.size()-1 ) ;
93     _Y.resize( _Y.size()-1 ) ;
94   }
95   return true ;
96 }
97
98 bool GraphBase::Port::RemoveCoords() {
99   if ( IsEndSwitch() ) {
100     return false ;
101   }
102   else {
103     _X.resize( 0 ) ;
104     _Y.resize( 0 ) ;
105   }
106   return true ;
107 }
108
109 int GraphBase::Port::GetCoord() const {
110   int npt ;
111   if ( IsEndSwitch() ) {
112     return false ;
113   }
114   else {
115     npt = _X.size() ;
116   }
117   return npt ;
118 }
119
120 bool GraphBase::Port::GetCoord( int *x , int *y ) const {
121   int i ;
122   if ( IsEndSwitch() ) {
123     return false ;
124   }
125   else {
126     for ( i = 0 ; i < _X.size() ; i++ ) {
127       x[ i ] = _X[ i ] ;
128       y[ i ] = _Y[ i ] ;
129     }
130   }
131   return true ;
132 }
133
134 const GraphBase::ListOfCoords * GraphBase::Port::Coords() const {
135   GraphBase::ListOfCoords * _list_Coords = new GraphBase::ListOfCoords ;
136   int i ;
137   if ( !IsEndSwitch() ) {
138     _list_Coords->resize( _X.size() );
139     for ( i = 0 ; i < _X.size() ; i++ ) {
140       (*_list_Coords)[ i ].theX = _X[ i ] ;
141       (*_list_Coords)[ i ].theY = _Y[ i ] ;
142     }
143   }
144   return _list_Coords ;
145 }
146
147 bool GraphBase::Port::GetCoord( const int index , long &x , long &y ) const {
148   if ( IsEndSwitch() ) {
149     return false ;
150   }
151   else {
152     if ( index <= 0 || index > _X.size() )
153       return false ;
154     x = _X[ index - 1 ] ;
155     y = _Y[ index - 1 ] ;
156 //    cdebug << "GetCoord " << NodeName() << "(" << PortName() << ") ["
157 //           << index-1 << "] " << x << " " << y << endl ;
158 //    int i ;
159 //    for ( i = 0 ; i <  _X.size() ; i++ ) {
160 //      cdebug << " [" << i << "] " << _X[ i ] << " " << _Y[ i ] << endl ;
161 //    }
162   }
163   return true ;
164 }
165
166 ostream & operator<< (ostream & f ,const SUPERV::KindOfPort & s ) {
167   switch (s) {
168   case SUPERV::ServiceParameter :
169     f << "ServiceParameter";
170     break;
171   case SUPERV::GateParameter :
172     f << "GateParameter";
173     break;
174   case SUPERV::LoopParameter :
175     f << "LoopParameter";
176     break;
177   case SUPERV::InLineParameter :
178     f << "InLineParameter";
179     break;
180   case SUPERV::SwitchParameter :
181     f << "SwitchParameter";
182     break;
183   case SUPERV::EndSwitchParameter :
184     f << "EndSwitchParameter";
185     break;
186   default :
187     f << "UnknownKindOfPort";
188     break;
189   }
190
191   return f;
192 }
193