7fd59977 |
1 | #include <Prs2d_Axis.ixx> |
2 | #include <TCollection_ExtendedString.hxx> |
3 | |
4 | #define VERTEXMARKER 2 |
5 | #define DEFAULTMARKERSIZE 3.0 |
6 | #define XROTATE(x,y) ((x)*cosa - (y)*sina) |
7 | #define YROTATE(x,y) ((y)*cosa + (x)*sina) |
8 | #define ADDPIX 17 |
9 | |
10 | Prs2d_Axis::Prs2d_Axis( const Handle(Graphic2d_GraphicObject)& aGO, |
11 | const gp_Ax22d& anAx, |
12 | const Standard_Real aLength, |
13 | const Standard_Real anArrAngle, |
14 | const Standard_Real anArrLength, |
15 | const Prs2d_TypeOfArrow anArrType, |
16 | const Standard_Real aTxtScale ) |
17 | : |
18 | Graphic2d_Line( aGO ), |
19 | myXVertX( 1, 3 ), |
20 | myYVertX( 1, 3 ), |
21 | myXVertY( 1, 3 ), |
22 | myYVertY( 1, 3 ), |
23 | myArrType( anArrType ), |
24 | myisXY( Standard_True ), |
25 | myTextScale( aTxtScale ) |
26 | |
27 | { |
28 | Standard_Real X0, Y0, X1, Y1, X2, Y2; |
29 | |
30 | anAx.Location().Coord( X0, Y0 ); |
31 | anAx.XDirection().Coord( X1, Y1 ); |
32 | anAx.YDirection().Coord( X2, Y2 ); |
33 | |
34 | X1 = X0 + X1 * aLength; |
35 | Y1 = Y0 + Y1 * aLength; |
36 | X2 = X0 + X2 * aLength; |
37 | Y2 = Y0 + Y2 * aLength; |
38 | |
39 | myX0 = Standard_ShortReal( X0 ); |
40 | myY0 = Standard_ShortReal( Y0 ); |
41 | myX1 = Standard_ShortReal( X1 ); |
42 | myY1 = Standard_ShortReal( Y1 ); |
43 | myX2 = Standard_ShortReal( X2 ); |
44 | myY2 = Standard_ShortReal( Y2 ); |
45 | |
46 | myMinX = myX0; |
47 | myMinY = myY0; |
48 | myMaxX = myX0; |
49 | myMaxY = myY0; |
50 | |
51 | if ( myX1 < myMinX ) myMinX = myX1; |
52 | if ( myY1 < myMinY ) myMinY = myY1; |
53 | if ( myX1 > myMaxX ) myMaxX = myX1; |
54 | if ( myY1 > myMaxY ) myMaxY = myY1; |
55 | |
56 | if ( myX2 < myMinX ) myMinX = myX2; |
57 | if ( myY2 < myMinY ) myMinY = myY2; |
58 | if ( myX2 > myMaxX ) myMaxX = myX2; |
59 | if ( myY2 > myMaxY ) myMaxY = myY2; |
60 | |
c6541a0c |
61 | Standard_Real ArrAngle = M_PI/180.*anArrAngle, theAngle; |
7fd59977 |
62 | gp_Pnt2d theOrigine( 0., 0.), P1, P2, P3; |
63 | gp_Vec2d VX( 1., 0. ), VDir; |
64 | |
65 | P1 = gp_Pnt2d( X1, Y1 ); |
66 | P2 = gp_Pnt2d( anArrLength, anArrLength*Tan( ArrAngle/2. ) ); |
67 | P3 = gp_Pnt2d( anArrLength, -anArrLength*Tan( ArrAngle/2. ) ); |
68 | |
69 | VDir = gp_Vec2d( gp_Pnt2d( X1, Y1 ), gp_Pnt2d( X0, Y0 ) ); |
70 | theAngle = VX.Angle( VDir ); |
71 | |
72 | P2.Rotate( theOrigine, theAngle ); |
73 | P3.Rotate( theOrigine, theAngle ); |
74 | |
75 | P2.Translate( gp_Vec2d( theOrigine, P1 ) ); |
76 | P3.Translate( gp_Vec2d( theOrigine, P1 ) ); |
77 | |
78 | myXVertX(1) = Standard_ShortReal( P2.X() ); |
79 | myYVertX(1) = Standard_ShortReal( P2.Y() ); |
80 | myXVertX(2) = Standard_ShortReal( P1.X() ); |
81 | myYVertX(2) = Standard_ShortReal( P1.Y() ); |
82 | myXVertX(3) = Standard_ShortReal( P3.X() ); |
83 | myYVertX(3) = Standard_ShortReal( P3.Y() ); |
84 | |
85 | Standard_Integer i; |
86 | for ( i = 1; i <= 3; i++ ) { |
87 | if ( myXVertX(i) < myMinX ) myMinX = myXVertX(i); |
88 | if ( myYVertX(i) < myMinY ) myMinY = myYVertX(i); |
89 | if ( myXVertX(i) > myMaxX ) myMaxX = myXVertX(i); |
90 | if ( myYVertX(i) > myMaxY ) myMaxY = myYVertX(i); |
91 | } |
92 | |
93 | P1 = gp_Pnt2d( X2, Y2 );; |
94 | P2 = gp_Pnt2d( anArrLength, anArrLength*Tan( ArrAngle/2. ) ); |
95 | P3 = gp_Pnt2d( anArrLength, -anArrLength*Tan( ArrAngle/2. ) ); |
96 | |
97 | VDir = gp_Vec2d( gp_Pnt2d( X2, Y2 ), gp_Pnt2d( X0, Y0 ) ); |
98 | theAngle = VX.Angle( VDir ); |
99 | |
100 | P2.Rotate( theOrigine, theAngle ); |
101 | P3.Rotate( theOrigine, theAngle ); |
102 | |
103 | P2.Translate( gp_Vec2d( theOrigine, P1 ) ); |
104 | P3.Translate( gp_Vec2d( theOrigine, P1 ) ); |
105 | |
106 | myXVertY(1) = Standard_ShortReal( P2.X() ); |
107 | myYVertY(1) = Standard_ShortReal( P2.Y() ); |
108 | myXVertY(2) = Standard_ShortReal( P1.X() ); |
109 | myYVertY(2) = Standard_ShortReal( P1.Y() ); |
110 | myXVertY(3) = Standard_ShortReal( P3.X() ); |
111 | myYVertY(3) = Standard_ShortReal( P3.Y() ); |
112 | |
113 | for ( i = 1; i <= 3; i++ ) { |
114 | |
115 | if ( myXVertY(i) < myMinX ) myMinX = myXVertY(i); |
116 | if ( myYVertY(i) < myMinY ) myMinY = myYVertY(i); |
117 | if ( myXVertY(i) > myMaxX ) myMaxX = myXVertY(i); |
118 | if ( myYVertY(i) > myMaxY ) myMaxY = myYVertY(i); |
119 | |
120 | } |
121 | |
122 | myNumOfElem = 6; |
123 | myNumOfVert = 3; |
124 | |
125 | } |
126 | |
127 | Prs2d_Axis::Prs2d_Axis( const Handle(Graphic2d_GraphicObject)& aGO, |
128 | const gp_Ax2d& anAx, |
129 | const Standard_Real aLength, |
130 | const Standard_Real anArrAngle, |
131 | const Standard_Real anArrLength, |
132 | const Prs2d_TypeOfArrow anArrType, |
133 | const Standard_Real aTxtScale ) |
134 | : |
135 | Graphic2d_Line( aGO ), |
136 | |
137 | myX2( 0. ), |
138 | myY2( 0. ), |
139 | myXVertX( 1, 3 ), |
140 | myYVertX( 1, 3 ), |
141 | myXVertY( 1, 3 ), |
142 | myYVertY( 1, 3 ), |
143 | myArrType( anArrType ), |
144 | myisXY( Standard_False ), |
145 | myTextScale( aTxtScale ) |
146 | { |
147 | Standard_Real X0, Y0, X1, Y1; |
148 | |
149 | anAx.Location().Coord( X0, Y0 ); |
150 | anAx.Direction().Coord( X1, Y1 ); |
151 | |
152 | X1 = X0 + X1 * aLength; |
153 | Y1 = Y0 + Y1 * aLength; |
154 | |
155 | myX0 = Standard_ShortReal( X0 ); |
156 | myY0 = Standard_ShortReal( Y0 ); |
157 | myX1 = Standard_ShortReal( X1 ); |
158 | myY1 = Standard_ShortReal( Y1 ); |
159 | |
160 | myMinX = myX0; |
161 | myMinY = myY0; |
162 | myMaxX = myX0; |
163 | myMaxY = myY0; |
164 | |
165 | if ( myX1 < myMinX ) myMinX = myX1; |
166 | if ( myY1 < myMinY ) myMinY = myY1; |
167 | if ( myX1 > myMaxX ) myMaxX = myX1; |
168 | if ( myY1 > myMaxY ) myMaxY = myY1; |
169 | |
c6541a0c |
170 | Standard_Real ArrAngle = M_PI/180.*anArrAngle, theAngle; |
7fd59977 |
171 | gp_Pnt2d theOrigine( 0., 0.), P1, P2, P3; |
172 | gp_Vec2d VX( 1., 0. ), VDir; |
173 | |
174 | P1 = gp_Pnt2d( X0, Y0 ); |
175 | P2 = gp_Pnt2d( anArrLength, anArrLength*Tan( ArrAngle/2. ) ); |
176 | P3 = gp_Pnt2d( anArrLength, -anArrLength*Tan( ArrAngle/2. ) ); |
177 | |
178 | VDir = gp_Vec2d( gp_Pnt2d( X1, Y1 ), gp_Pnt2d( X0, Y0 ) ); |
179 | theAngle = VX.Angle( VDir ); |
180 | |
181 | P2.Rotate( theOrigine, theAngle ); |
182 | P3.Rotate( theOrigine, theAngle ); |
183 | |
184 | P2.Translate( gp_Vec2d( theOrigine, P1 ) ); |
185 | P3.Translate( gp_Vec2d( theOrigine, P1 ) ); |
186 | |
187 | myXVertX(1) = Standard_ShortReal( P2.X() ); |
188 | myYVertX(1) = Standard_ShortReal( P2.Y() ); |
189 | myXVertX(2) = Standard_ShortReal( P1.X() ); |
190 | myYVertX(2) = Standard_ShortReal( P1.Y() ); |
191 | myXVertX(3) = Standard_ShortReal( P3.X() ); |
192 | myYVertX(3) = Standard_ShortReal( P3.Y() ); |
193 | |
194 | for ( Standard_Integer i = 1; i <= 3; i++ ) { |
195 | if ( myXVertX(i) < myMinX ) myMinX = myXVertX(i); |
196 | if ( myYVertX(i) < myMinY ) myMinY = myYVertX(i); |
197 | if ( myXVertX(i) > myMaxX ) myMaxX = myXVertX(i); |
198 | if ( myYVertX(i) > myMaxY ) myMaxY = myYVertX(i); |
199 | } |
200 | myNumOfElem = 6; |
201 | myNumOfVert = 3; |
202 | |
203 | } |
204 | |
205 | Prs2d_Axis::Prs2d_Axis( const Handle(Graphic2d_GraphicObject)& aGO, |
206 | const gp_Lin2d& aLine, |
207 | const Standard_Real aLength, |
208 | const Standard_Real anArrAngle, |
209 | const Standard_Real anArrLength, |
210 | const Prs2d_TypeOfArrow anArrType, |
211 | const Standard_Real aTxtScale ) |
212 | : |
213 | Graphic2d_Line( aGO ), |
214 | |
215 | myX2( 0. ), |
216 | myY2( 0. ), |
217 | myXVertX( 1, 3 ), |
218 | myYVertX( 1, 3 ), |
219 | myXVertY( 1, 3 ), |
220 | myYVertY( 1, 3 ), |
221 | myArrType( anArrType ), |
222 | myisXY( Standard_False ), |
223 | myTextScale( aTxtScale ) |
224 | |
225 | { |
226 | Standard_Real X0, Y0, X1, Y1; |
227 | |
228 | aLine.Location().Coord( X0, Y0 ); |
229 | aLine.Direction().Coord( X1, Y1 ); |
230 | |
231 | X1 = X0 + X1 * aLength; |
232 | Y1 = Y0 + Y1 * aLength; |
233 | |
234 | myX0 = Standard_ShortReal( X0 ); |
235 | myY0 = Standard_ShortReal( Y0 ); |
236 | myX1 = Standard_ShortReal( X1 ); |
237 | myY1 = Standard_ShortReal( Y1 ); |
238 | |
239 | myMinX = myX0; |
240 | myMinY = myY0; |
241 | myMaxX = myX0; |
242 | myMaxY = myY0; |
243 | |
244 | if ( myX1 < myMinX ) myMinX = myX1; |
245 | if ( myY1 < myMinY ) myMinY = myY1; |
246 | if ( myX1 > myMaxX ) myMaxX = myX1; |
247 | if ( myY1 > myMaxY ) myMaxY = myY1; |
248 | |
c6541a0c |
249 | Standard_Real ArrAngle = M_PI/180.*anArrAngle, theAngle; |
7fd59977 |
250 | gp_Pnt2d theOrigine( 0., 0.), P1, P2, P3; |
251 | gp_Vec2d VX( 1., 0. ), VDir; |
252 | |
253 | P1 = gp_Pnt2d( X1, Y1 ); |
254 | P2 = gp_Pnt2d( anArrLength, anArrLength*Tan( ArrAngle/2. ) ); |
255 | P3 = gp_Pnt2d( anArrLength, -anArrLength*Tan( ArrAngle/2. ) ); |
256 | |
257 | VDir = gp_Vec2d( gp_Pnt2d( X1, Y1 ), gp_Pnt2d( X0, Y0 ) ); |
258 | theAngle = VX.Angle( VDir ); |
259 | |
260 | P2.Rotate( theOrigine, theAngle ); |
261 | P3.Rotate( theOrigine, theAngle ); |
262 | |
263 | P2.Translate( gp_Vec2d( theOrigine, P1 ) ); |
264 | P3.Translate( gp_Vec2d( theOrigine, P1 ) ); |
265 | |
266 | myXVertX(1) = Standard_ShortReal( P2.X() ); |
267 | myYVertX(1) = Standard_ShortReal( P2.Y() ); |
268 | myXVertX(2) = Standard_ShortReal( P1.X() ); |
269 | myYVertX(2) = Standard_ShortReal( P1.Y() ); |
270 | myXVertX(3) = Standard_ShortReal( P3.X() ); |
271 | myYVertX(3) = Standard_ShortReal( P3.Y() ); |
272 | |
273 | for ( Standard_Integer i = 1; i <= 3; i++ ) { |
274 | if ( myXVertX(i) < myMinX ) myMinX = myXVertX(i); |
275 | if ( myYVertX(i) < myMinY ) myMinY = myYVertX(i); |
276 | if ( myXVertX(i) > myMaxX ) myMaxX = myXVertX(i); |
277 | if ( myYVertX(i) > myMaxY ) myMaxY = myYVertX(i); |
278 | } |
279 | myNumOfElem = 6; |
280 | myNumOfVert = 3; |
281 | |
282 | } |
283 | |
284 | void Prs2d_Axis::Draw( const Handle(Graphic2d_Drawer)& aDrawer ) { |
285 | |
286 | Standard_Boolean IsIn = Standard_False; |
287 | |
288 | TCollection_ExtendedString txtX("X"); |
289 | TCollection_ExtendedString txtY("Y"); |
290 | |
291 | if ( !myGOPtr->IsTransformed() ) |
292 | IsIn = aDrawer->IsIn( myMinX, myMaxX, myMinY, myMaxY ); |
293 | else { |
294 | Standard_ShortReal minx, miny, maxx, maxy; |
295 | MinMax( minx, maxx, miny, maxy ); |
296 | IsIn = aDrawer->IsIn( minx, maxx, miny, maxy ); |
297 | } |
298 | |
299 | if ( IsIn ) { |
300 | |
301 | DrawLineAttrib( aDrawer ); |
302 | Standard_ShortReal dxx = aDrawer->Convert(17); |
303 | aDrawer->SetTextAttrib( myColorIndex, 0, 0, Standard_ShortReal(myTextScale*aDrawer->Scale()), |
304 | Standard_ShortReal(myTextScale*aDrawer->Scale()), Standard_False ); |
305 | Standard_ShortReal a = myX0, b = myY0, |
306 | c = myX1, d = myY1, |
307 | e = myX2, f = myY2, |
308 | t1 = myX1, t2 = myY1 + dxx, |
309 | tt1 = myX2 + dxx, tt2 = myY2; |
310 | TShort_Array1OfShortReal XpointX( 1, 3 ), YpointX( 1, 3 ), |
311 | XpointY( 1, 3 ), YpointY( 1, 3 ); |
312 | |
313 | if ( myGOPtr->IsTransformed () ) { |
314 | gp_GTrsf2d aTrsf = myGOPtr->Transform (); |
315 | Standard_Real a1, b1, a2, b2; |
316 | for ( Standard_Integer j = 1; j <= 3; j++ ) { |
317 | a1 = myXVertX(j); |
318 | b1 = myYVertX(j); |
319 | aTrsf.Transforms(a1, b1); |
320 | XpointX(j) = Standard_ShortReal(a1); |
321 | YpointX(j) = Standard_ShortReal(b1); |
322 | if ( myisXY ) { |
323 | a2 = myXVertY(j); |
324 | b2 = myYVertY(j); |
325 | aTrsf.Transforms( a2, b2 ); |
326 | XpointY(j) = Standard_ShortReal(a2); |
327 | YpointY(j) = Standard_ShortReal(b2); |
328 | } |
329 | } |
330 | |
331 | Standard_Real A, B, C, D, T1, T2; |
332 | A = a; |
333 | B = b; |
334 | C = c; |
335 | D = d; |
336 | T1 = t1; |
337 | T2 = t2; |
338 | aTrsf.Transforms( A, B ); |
339 | aTrsf.Transforms( C, D ); |
340 | aTrsf.Transforms( T1, T2 ); |
341 | a = Standard_ShortReal(A); |
342 | b = Standard_ShortReal(B); |
343 | c = Standard_ShortReal(C); |
344 | d = Standard_ShortReal(D); |
345 | t1 = Standard_ShortReal(T1); |
346 | t2 = Standard_ShortReal(T2); |
347 | |
348 | if ( myisXY ) { |
349 | Standard_Real E, F, TT1, TT2; |
350 | E = e; |
351 | F = f; |
352 | TT1 = tt1; |
353 | TT2 = tt2; |
354 | aTrsf.Transforms( E, F ); |
355 | aTrsf.Transforms( TT1, TT2 ); |
356 | e = Standard_ShortReal(E); |
357 | f = Standard_ShortReal(F); |
358 | tt1 = Standard_ShortReal(TT1); |
359 | tt2 = Standard_ShortReal(TT2); |
360 | } |
361 | } else { |
362 | XpointX.Assign( myXVertX ); |
363 | YpointX.Assign( myYVertX ); |
364 | if ( myisXY ) { |
365 | XpointY.Assign( myXVertY ); |
366 | YpointY.Assign( myYVertY ); |
367 | } |
368 | } // end if GO is transformed |
369 | |
370 | aDrawer->MapSegmentFromTo( a, b, c, d ); |
371 | aDrawer->MapTextFromTo( txtX, t1, t2, 0., 0., 0., Aspect_TOT_SOLID ); |
372 | |
373 | if ( myArrType == Prs2d_TOA_CLOSED || myArrType == Prs2d_TOA_FILLED ) |
374 | aDrawer->MapPolygonFromTo( XpointX, YpointX ); |
375 | else |
376 | aDrawer->MapPolylineFromTo( XpointX, YpointX ); |
377 | |
378 | if ( myisXY ) { |
379 | aDrawer->MapSegmentFromTo( a, b, e, f ); |
380 | aDrawer->MapTextFromTo( txtY, tt1, tt2, 0., 0., 0., Aspect_TOT_SOLID ); |
381 | if ( myArrType == Prs2d_TOA_CLOSED || myArrType == Prs2d_TOA_FILLED ) |
382 | aDrawer->MapPolygonFromTo( XpointY, YpointY ); |
383 | else |
384 | aDrawer->MapPolylineFromTo( XpointY, YpointY ); |
385 | |
386 | } |
387 | } // end if IsIn is true |
388 | |
389 | } |
390 | |
391 | void Prs2d_Axis::DrawElement( const Handle(Graphic2d_Drawer)& aDrawer, |
392 | const Standard_Integer anIndex) { |
393 | |
394 | Standard_Boolean IsIn = Standard_False; |
395 | |
396 | if ( ! myGOPtr->IsTransformed() ) |
397 | IsIn = aDrawer->IsIn( myMinX, myMaxX, myMinY, myMaxY ); |
398 | else { |
399 | Standard_ShortReal minx, miny, maxx, maxy; |
400 | MinMax( minx, maxx, miny, maxy ); |
401 | IsIn = aDrawer->IsIn( minx, maxx, miny, maxy ); |
402 | } |
403 | |
404 | if ( IsIn ) { |
405 | |
406 | DrawLineAttrib( aDrawer ); |
407 | // aDrawer->SetTextAttrib( myColorIndex, 0, 0, myTextScale*aDrawer->Scale(), |
408 | // myTextScale*aDrawer->Scale(), Standard_False ); |
409 | Standard_ShortReal dxx = aDrawer->Convert(17); |
410 | Standard_ShortReal a = myX0, b = myY0, |
411 | c = myX1, d = myY1, |
412 | e = myX2, f = myY2, |
413 | t1 = myX1, t2 = myY1 + dxx, |
414 | tt1 = myX2 + dxx, tt2 = myY2; |
415 | TShort_Array1OfShortReal Xpoint( 1, 3 ), Ypoint( 1, 3 ); |
416 | |
417 | if ( anIndex == 1 ) { |
418 | Xpoint.Assign( myXVertX ); |
419 | Ypoint.Assign( myYVertX ); |
420 | } else if ( anIndex == 2 ) { |
421 | Xpoint.Assign( myXVertY ); |
422 | Ypoint.Assign( myYVertY ); |
423 | } |
424 | |
425 | if ( myGOPtr->IsTransformed () ) { |
426 | gp_GTrsf2d aTrsf = myGOPtr->Transform (); |
427 | Standard_Real a1, b1, c1, d1, e1, f1, at1, at2, att1, att2; |
428 | |
429 | if ( anIndex == 1 ) { |
430 | for ( Standard_Integer j = 1; j <= 3; j++ ) { |
431 | a1 = Standard_Real( Xpoint(j) ); |
432 | b1 = Standard_Real( Xpoint(j) ); |
433 | aTrsf.Transforms( a1, b1 ); |
434 | Xpoint(j) = Standard_ShortReal( a1 ); |
435 | Ypoint(j) = Standard_ShortReal( b1 ); |
436 | } |
437 | } else if ( anIndex == 2 ) { |
438 | |
439 | for ( Standard_Integer j = 1; j <= 3; j++ ) { |
440 | a1 = Standard_Real( Xpoint(j) ); |
441 | b1 = Standard_Real( Xpoint(j) ); |
442 | aTrsf.Transforms( a1, b1 ); |
443 | Xpoint(j) = Standard_ShortReal( a1 ); |
444 | Ypoint(j) = Standard_ShortReal( b1 ); |
445 | } |
446 | } else if ( anIndex == 5 ) { |
447 | |
448 | a1 = Standard_Real( a ); |
449 | b1 = Standard_Real( b ); |
450 | c1 = Standard_Real( c ); |
451 | d1 = Standard_Real( d ); |
452 | aTrsf.Transforms( a1, b1 ); |
453 | aTrsf.Transforms( c1, d1 ); |
454 | a = Standard_ShortReal( a1 ); |
455 | b = Standard_ShortReal( b1 ); |
456 | c = Standard_ShortReal( c1 ); |
457 | d = Standard_ShortReal( d1 ); |
458 | |
459 | } else if ( anIndex == 6 ) { |
460 | a1 = Standard_Real( a ); |
461 | b1 = Standard_Real( b ); |
462 | e1 = Standard_Real( e ); |
463 | f1 = Standard_Real( f ); |
464 | aTrsf.Transforms( a1, b1 ); |
465 | aTrsf.Transforms( e1, f1 ); |
466 | a = Standard_ShortReal( a1 ); |
467 | b = Standard_ShortReal( b1); |
468 | e = Standard_ShortReal( e1 ); |
469 | f = Standard_ShortReal( f1); |
470 | |
471 | } else if ( anIndex == 3 ) { |
472 | c1 = Standard_Real( c ); |
473 | d1 = Standard_Real( d ); |
474 | at1 = Standard_Real( t1 ); |
475 | at2 = Standard_Real( t2 ); |
476 | aTrsf.Transforms( c1, d1 ); |
477 | aTrsf.Transforms( at1, at2 ); |
478 | c = Standard_ShortReal( c1 ); |
479 | d = Standard_ShortReal( d1); |
480 | t1 = Standard_ShortReal( at1 ); |
481 | t2 = Standard_ShortReal( at2); |
482 | |
483 | } else if ( anIndex == 4 ) { |
484 | e1 = Standard_Real( e ); |
485 | f1 = Standard_Real( f ); |
486 | att1 = Standard_Real( tt1 ); |
487 | att2 = Standard_Real( tt2 ); |
488 | aTrsf.Transforms( e1, f1 ); |
489 | aTrsf.Transforms( att1, att2 ); |
490 | e = Standard_ShortReal( e1 ); |
491 | f = Standard_ShortReal( f1); |
492 | tt1 = Standard_ShortReal( att1 ); |
493 | tt2 = Standard_ShortReal( att2); |
494 | |
495 | } |
496 | |
497 | } |
498 | |
499 | if ( anIndex == 1 || anIndex == 2 ) |
500 | if ( myArrType == Prs2d_TOA_CLOSED || myArrType == Prs2d_TOA_FILLED ) { |
501 | aDrawer->MapPolygonFromTo( Xpoint, Ypoint ); |
502 | } else { |
503 | aDrawer->MapPolylineFromTo( Xpoint, Ypoint ); |
504 | } |
505 | else if ( anIndex == 5 ) |
506 | aDrawer->MapSegmentFromTo( a, b, c, d ); |
507 | else if ( anIndex == 6 ) |
508 | aDrawer->MapSegmentFromTo( a, b, e, f ); |
509 | else if ( anIndex == 3 ) { |
510 | TCollection_ExtendedString txtX("X"); |
511 | aDrawer->MapTextFromTo( txtX, t1, t2, 0., 0., 0., Aspect_TOT_SOLID ); |
512 | } else if ( anIndex == 4 ) { |
513 | TCollection_ExtendedString txtY("Y"); |
514 | aDrawer->MapTextFromTo( txtY, tt1, tt2, 0., 0., 0., Aspect_TOT_SOLID ); |
515 | } |
516 | } // end if IsIn is true |
517 | |
518 | } |
519 | |
520 | void Prs2d_Axis::DrawVertex (const Handle(Graphic2d_Drawer)& aDrawer, |
521 | const Standard_Integer anIndex) { |
522 | |
523 | Standard_Boolean IsIn = Standard_False; |
524 | |
525 | if ( ! myGOPtr->IsTransformed() ) |
526 | IsIn = aDrawer->IsIn( myMinX, myMaxX, myMinY, myMaxY ); |
527 | else { |
528 | Standard_ShortReal minx, miny, maxx, maxy; |
529 | MinMax( minx, maxx, miny, maxy ); |
530 | IsIn = aDrawer->IsIn( minx, maxx, miny, maxy ); |
531 | } |
532 | if ( IsIn ) { |
533 | if ( anIndex == 1 || anIndex == 2 || anIndex == 3 ) { |
534 | Standard_ShortReal X=0., Y=0.; |
535 | if ( anIndex == 1 ) { |
536 | X = myX0; Y = myY0; |
537 | } else if ( anIndex == 2 ) { |
538 | X = myX1; Y = myY1; |
539 | } else if ( anIndex == 3 ) { |
540 | X = myX2; Y = myY2; |
541 | } |
542 | |
543 | DrawMarkerAttrib( aDrawer ); |
544 | if ( myGOPtr->IsTransformed() ) { |
545 | gp_GTrsf2d aTrsf = myGOPtr->Transform(); |
546 | Standard_Real A = Standard_Real( X ), B = Standard_Real( Y ); |
547 | aTrsf.Transforms( A, B ); |
548 | X = Standard_ShortReal( A ); |
549 | Y = Standard_ShortReal( B ); |
550 | } |
551 | aDrawer->MapMarkerFromTo(VERTEXMARKER,X,Y, DEFAULTMARKERSIZE,DEFAULTMARKERSIZE,0.0); |
552 | } |
553 | } |
554 | } |
555 | |
556 | Standard_Boolean Prs2d_Axis::Pick( const Standard_ShortReal X, |
557 | const Standard_ShortReal Y, |
558 | const Standard_ShortReal aPrecision, |
559 | const Handle(Graphic2d_Drawer)& aDrawer ) { |
560 | Standard_ShortReal SRX = X, SRY = Y; |
561 | Standard_Boolean Result = Standard_False; |
562 | |
563 | if ( IsInMinMax (X, Y, aPrecision) ) { |
564 | if ( myGOPtr->IsTransformed () ) { |
565 | gp_GTrsf2d aTrsf = ( myGOPtr->Transform() ).Inverted(); |
566 | Standard_Real RX = Standard_Real(SRX), RY = Standard_Real(SRY); |
567 | aTrsf.Transforms( RX, RY ); |
568 | SRX = Standard_ShortReal( RX ); |
569 | SRY = Standard_ShortReal( RY ); |
570 | } |
571 | |
572 | if ( Graphic2d_Primitive::IsOn( SRX, SRY, myX0, myY0, aPrecision ) ) { |
573 | SetPickedIndex(-1); |
574 | return Standard_True; |
575 | } else if ( Graphic2d_Primitive::IsOn( SRX, SRY, myX1, myY1, aPrecision ) ) { |
576 | SetPickedIndex(-2); |
577 | return Standard_True; |
578 | } else if ( Graphic2d_Primitive::IsOn( SRX, SRY, myX2, myY2, aPrecision ) ) { |
579 | SetPickedIndex(-3); |
580 | return Standard_True; |
581 | } |
582 | |
583 | for ( Standard_Integer i = 1; i < 3 ; i++) { |
584 | if ( IsOn( SRX, SRY, myXVertX(i), myYVertX(i), myXVertX(i+1), myYVertX( i+1 ), aPrecision ) ) { |
585 | SetPickedIndex(1); |
586 | return Standard_True; |
587 | } |
588 | if ( myisXY ) |
589 | if ( IsOn( SRX, SRY, myXVertY(i), myYVertY(i), myXVertY(i+1), myYVertY( i+1 ), aPrecision ) ) { |
590 | SetPickedIndex(2); |
591 | return Standard_True; |
592 | } |
593 | |
594 | } // end for |
595 | |
596 | if ( myArrType == Prs2d_TOA_CLOSED || myArrType == Prs2d_TOA_FILLED ) |
597 | if ( IsIn( SRX, SRY, myXVertX, myYVertX, aPrecision ) ) { |
598 | SetPickedIndex(1); |
599 | return Standard_True; |
600 | } |
601 | |
602 | if ( myisXY ) |
603 | if ( myArrType == Prs2d_TOA_CLOSED || myArrType == Prs2d_TOA_FILLED ) |
604 | if ( IsIn( SRX, SRY, myXVertY, myYVertY, aPrecision ) ) { |
605 | SetPickedIndex(2); |
606 | return Standard_True; |
607 | } |
608 | Standard_ShortReal width,height,xoffset,yoffset; |
609 | Standard_ShortReal hscale = Standard_ShortReal(myTextScale*aDrawer->Scale()), |
610 | wscale = Standard_ShortReal(myTextScale*aDrawer->Scale()); |
611 | Standard_ShortReal TX = X, TY = Y; |
612 | |
613 | aDrawer->SetTextAttrib( myColorIndex, 0, 0, hscale, wscale, Standard_False ); |
614 | TCollection_ExtendedString txt("X"); |
615 | if ( !aDrawer->GetTextSize( txt, width, height, xoffset, yoffset ) ) { |
616 | width = height = xoffset = yoffset = 0.; |
617 | } |
618 | Standard_ShortReal dxx = aDrawer->Convert(ADDPIX); |
619 | Standard_ShortReal cosa = Standard_ShortReal(Cos( 0. )), |
620 | sina = Standard_ShortReal(Sin( 0. )), |
621 | dx = TX- myX1, |
622 | dy = TY- myY1 - dxx, |
623 | x = XROTATE(dx,dy), |
624 | y = YROTATE(dx,dy); |
625 | |
626 | Result = (x >= -aPrecision + xoffset) |
627 | && (x <= width + xoffset + aPrecision) |
628 | && (y >= -yoffset - aPrecision) |
629 | && (y <= height - yoffset + aPrecision); |
630 | |
631 | if ( Result ) { |
632 | SetPickedIndex(3); |
633 | return Standard_True; |
634 | } |
635 | txt = TCollection_ExtendedString("Y"); |
636 | if ( !aDrawer->GetTextSize( txt, width, height, xoffset, yoffset ) ) { |
637 | width = height = xoffset = yoffset = 0.; |
638 | } |
639 | |
640 | dx = TX - myX2 - dxx; |
641 | dy = TY - myY2, |
642 | x = XROTATE(dx,dy), |
643 | y = YROTATE(dx,dy); |
644 | |
645 | Result = (x >= -aPrecision + xoffset) |
646 | && (x <= width + xoffset + aPrecision) |
647 | && (y >= -yoffset - aPrecision) |
648 | && (y <= height - yoffset + aPrecision); |
649 | |
650 | if ( Result ) { |
651 | SetPickedIndex( 4 ); |
652 | return Standard_True; |
653 | } |
654 | |
655 | if ( IsOn( SRX, SRY, myX0, myY0, myX1, myY1, aPrecision ) ) { |
656 | SetPickedIndex(5); |
657 | return Standard_True; |
658 | } |
659 | if ( myisXY ) |
660 | if ( IsOn( SRX, SRY, myX0, myY0, myX2, myY2, aPrecision ) ) { |
661 | SetPickedIndex(6); |
662 | return Standard_True; |
663 | } |
664 | |
665 | }// end if IsInMinMax is true |
666 | |
667 | return Standard_False; |
668 | |
669 | } |
670 | |
671 | void Prs2d_Axis::Save(Aspect_FStream& aFStream) const |
672 | { |
673 | } |
674 | |
675 | Prs2d_TypeOfArrow Prs2d_Axis::TypeOfArrow( ) const |
676 | { |
677 | return myArrType; |
678 | } |
679 | |
680 | const Handle(TColgp_HArray1OfPnt2d) Prs2d_Axis::ArrayOfPnt2d( ) const |
681 | { |
682 | Handle(TColgp_HArray1OfPnt2d) points = new TColgp_HArray1OfPnt2d( 1, 3 ); |
683 | |
684 | points->SetValue( 1, gp_Pnt2d( myX1, myY1 ) ); |
685 | points->SetValue( 2, gp_Pnt2d( myX0, myY0 ) ); |
686 | points->SetValue( 3, gp_Pnt2d( myX2, myY2 ) ); |
687 | return points; |
688 | } |
689 | |
690 | const Handle(TColgp_HArray1OfPnt2d) Prs2d_Axis::ArrayOfXArrowPnt2d( ) const |
691 | { |
692 | Handle(TColgp_HArray1OfPnt2d) points = new TColgp_HArray1OfPnt2d( 1, 3 ); |
693 | |
694 | for ( Standard_Integer i = 1; i <= 3; i++ ) |
695 | { |
696 | points->SetValue( i, gp_Pnt2d( myXVertX(i), myYVertX(i) ) ); |
697 | } |
698 | return points; |
699 | } |
700 | |
701 | const Handle(TColgp_HArray1OfPnt2d) Prs2d_Axis::ArrayOfYArrowPnt2d( ) const |
702 | { |
703 | Handle(TColgp_HArray1OfPnt2d) points = new TColgp_HArray1OfPnt2d( 1, 3 ); |
704 | |
705 | for ( Standard_Integer i = 1; i <= 3; i++ ) |
706 | { |
707 | points->SetValue( i, gp_Pnt2d( myXVertY(i), myYVertY(i) ) ); |
708 | } |
709 | return points; |
710 | } |
711 | |
712 | Standard_Real Prs2d_Axis::TextScale( ) const |
713 | { |
714 | return myTextScale; |
715 | } |
716 | |
717 | |