Salome HOME
Dump Bathymetry data to python script (Feature #13).
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_AISCurve.cxx
1 #include "HYDROGUI_AISCurve.h"
2
3 #include "CurveCreator_Curve.hxx"
4
5
6
7 #include <AIS_Point.hxx>
8
9 #include <AIS_Line.hxx>
10
11 #include <gp_Pnt.hxx>
12
13 #include <gp_Lin.hxx>
14
15 #include <Geom_CartesianPoint.hxx>
16
17
18
19 HYDROGUI_AISCurveSection::HYDROGUI_AISCurveSection( Handle_AIS_InteractiveContext theContext, 
20
21                                                    CurveCreator_Curve* theCurve, int theSection) :
22
23   myCurve(theCurve), mySection(theSection), myContext(theContext), myIsHL(false)
24
25 {
26
27   buildSection();
28
29 }
30
31
32
33 HYDROGUI_AISCurveSection::~HYDROGUI_AISCurveSection()
34
35 {
36
37   Erase();
38
39   for( int i = 0 ; i < myObjects.size() ; i++ ){
40
41     myObjects[i].Nullify();
42
43   }
44
45   myObjects.clear();
46
47 }
48
49
50
51 Quantity_Color HYDROGUI_AISCurveSection::getActiveColor()
52
53 {
54
55   if( myIsHL ){
56
57     return Quantity_Color( 1., 0., 0., Quantity_TOC_RGB );
58
59   }
60
61   return Quantity_Color( 0., 1., 0., Quantity_TOC_RGB );
62
63 }
64
65
66
67 void  HYDROGUI_AISCurveSection::highlight( bool isHL )
68
69 {
70
71   myIsHL = isHL;
72
73   Quantity_Color aColor = getActiveColor();
74
75   for( int i = 0 ; i < myObjects.size() ; i++ ){
76
77     myObjects[i]->SetColor(aColor);
78
79     myContext->Display(myObjects[i]);
80
81   }
82
83 }
84
85
86
87 void HYDROGUI_AISCurveSection::Display()
88
89 {
90
91   for( int i = 0 ; i < myObjects.size() ; i++ ){
92
93     myContext->Display(myObjects[i]);
94
95   }
96
97 }
98
99
100
101 void HYDROGUI_AISCurveSection::Erase()
102
103 {
104
105   for( int i = 0 ; i < myObjects.size() ; i++ ){
106
107     myContext->Erase(myObjects[i]);
108
109   }
110
111 }
112
113
114
115 void HYDROGUI_AISCurveSection::buildSection()
116
117 {
118
119   int aSectSize = myCurve->getNbPoints( mySection );
120
121   double anX;
122
123   double anY;
124
125   double aZ;
126
127   int i = 0; 
128
129   for( ; i < ( aSectSize - 1 ) ; i++ ){
130
131     Handle_AIS_Point anAISPnt = getAISPoint(i);
132
133     myObjects.push_back( anAISPnt );
134
135     Handle_AIS_Line aLine = getAISLine( i, i+1 );
136
137     myObjects.push_back( aLine );
138
139   }
140
141   if( aSectSize != 0 ){
142
143     Handle_AIS_Point anAISPnt = getAISPoint(i); 
144
145     myObjects.push_back( anAISPnt );
146
147     if( myCurve->isClosed(mySection) && ( aSectSize > 1 ) ){
148
149       Handle_AIS_Line aLine = getAISLine( i, 0 );
150
151       myObjects.push_back( aLine );
152
153     }
154
155   }
156
157 }
158
159
160
161 Handle_AIS_Point HYDROGUI_AISCurveSection::getAISPoint( int theIndx )
162
163 {
164
165   double anX;
166
167   double anY;
168
169   double aZ;
170
171   getPoint( theIndx, anX, anY, aZ );
172
173   gp_Pnt aPoint( anX, anY, aZ);
174
175   AIS_Point* aPnt = new AIS_Point( new Geom_CartesianPoint(aPoint));
176
177   return aPnt;
178
179 }
180
181
182
183 Handle_AIS_Line HYDROGUI_AISCurveSection::getAISLine( int theIndx1, int theIndx2 )
184
185 {
186
187   double anX;
188
189   double anY;
190
191   double aZ;
192
193   getPoint( theIndx1, anX, anY, aZ );
194
195   gp_Pnt aPoint1( anX, anY, aZ);
196
197   double anX2;
198
199   double anY2;
200
201   double aZ2;
202
203   getPoint( theIndx2, anX2, anY2, aZ2 );
204
205 //MTN to avoid crash during line construction
206
207   if( ( anX == anX2 ) && ( anY == anY2 ) && (aZ == aZ2 ) ){
208
209     aZ2 += 1e-7;
210
211   }
212
213   gp_Pnt aPoint2( anX2, anY2, aZ2 );
214
215   AIS_Line* aLine = new AIS_Line( new Geom_CartesianPoint(aPoint1), new Geom_CartesianPoint(aPoint2) );
216
217   return aLine;
218
219 }
220
221
222
223 void HYDROGUI_AISCurveSection::getPoint( int theIndx, double& theX, double& theY, double& theZ )
224
225 {
226
227   CurveCreator::Dimension aDim = myCurve->getDimension();
228
229   CurveCreator::Coordinates aCoords = myCurve->getCoordinates( mySection, theIndx );
230
231   theX = aCoords[0];
232
233   theY = aCoords[1];
234
235   theZ = 0.;
236
237   if( aDim == CurveCreator::Dim3d ){
238
239     theZ = aCoords[2];
240
241   }
242
243 }
244
245
246
247 /******************************* HYDROGUI_AISCurve ********************************************/
248
249 HYDROGUI_AISCurve::HYDROGUI_AISCurve( CurveCreator_Curve* theCurve, Handle_AIS_InteractiveContext theContext ) :
250
251   CurveCreator_Listener(), myCurve(theCurve), myContext( theContext )
252
253 {
254
255   myCurve->setListener(this);
256
257   buildCurve();
258
259 }
260
261
262
263 HYDROGUI_AISCurve::~HYDROGUI_AISCurve(void)
264
265 {
266
267 }
268
269
270
271 void HYDROGUI_AISCurve::setCurve( CurveCreator_Curve* theCurve )
272
273 {
274
275   myCurve = theCurve;
276
277   buildCurve();
278
279 }
280
281
282
283 void HYDROGUI_AISCurve::Display()
284
285 {
286
287   for( int i = 0 ; i < myCurveRepresentation.size() ; i++ ){
288
289     myCurveRepresentation[i]->Display();
290
291   }
292
293 }
294
295
296
297 void HYDROGUI_AISCurve::buildCurve()
298
299 {
300
301   for( int i = 0 ; i < myCurveRepresentation.size() ; i++ ){
302
303     myCurveRepresentation[i]->Erase();
304
305     delete myCurveRepresentation[i];
306
307   }
308
309   myCurveRepresentation.clear();
310
311   for( int i = 0 ; i < myCurve->getNbSections() ; i++ ){
312
313     HYDROGUI_AISCurveSection* aSection = new HYDROGUI_AISCurveSection( myContext, myCurve, i);
314
315     myCurveRepresentation.push_back( aSection );
316
317     myCurveRepresentation[i]->Display();
318
319   }
320
321 }
322
323
324
325 void HYDROGUI_AISCurve::pointInserted( int theSection, int theIndx )
326
327 {
328
329   buildCurve();
330
331 }
332
333
334
335 void HYDROGUI_AISCurve::highlightSection( int theSection, bool isHL )
336
337 {
338
339   if( theSection >= myCurveRepresentation.size() )
340
341     return;
342
343   myCurveRepresentation[theSection]->highlight(isHL);
344
345 }
346