0022792: Globally defined symbol PI conflicts with VTK definition (Intel compiler)
[occt.git] / src / Prs2d / Prs2d_Angle.cxx
1 #include <Prs2d_Angle.ixx>
2 #include <gp_Vec2d.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 7
9
10 Prs2d_Angle::Prs2d_Angle( const Handle(Graphic2d_GraphicObject)& aGO,
11                           const gp_Pnt2d&                   anAttachPnt1,
12                           const gp_Pnt2d&                   anAttachPnt2,
13                           const gp_Pnt2d&                   anAttachPnt3,
14                           const Quantity_Length             aRadius,
15                           const TCollection_ExtendedString& aText,
16                           const Standard_Real               aTxtScale,
17                           const Standard_Real               anArrAngle,
18                           const Standard_Real               anArrLength,
19                           const Prs2d_TypeOfArrow           anArrType,
20                           const Prs2d_ArrowSide             anArrow,
21                           const Standard_Boolean            IsRevArrow ) 
22   
23  :     Prs2d_Dimension( aGO, aText, aTxtScale, anArrAngle, 
24                        anArrLength, anArrType, anArrow, IsRevArrow ),
25        myCentX( Standard_ShortReal( anAttachPnt1.X() ) ),
26        myCentY( Standard_ShortReal( anAttachPnt1.Y() ) ),
27        myRad( Standard_ShortReal( aRadius ) ) 
28 {
29    
30   SetSymbolCode( 176 );
31   gp_Vec2d V1( anAttachPnt1, anAttachPnt2 );
32   gp_Vec2d V2( anAttachPnt1, anAttachPnt3 );
33   gp_Vec2d VX( 1., 0. );
34   myFAngle = Standard_ShortReal( VX.Angle(V1) );
35   mySAngle = Standard_ShortReal( VX.Angle(V2) );
36   
37   //myRad = Standard_ShortReal(anAttachPnt1.Distance( anOffsetPoint ));
38   if ( myRad <= ShortRealEpsilon ())
39      Graphic2d_CircleDefinitionError::Raise ("The radius = 0." );
40
41   Standard_ShortReal TwoPI = Standard_ShortReal(2. * M_PI);
42   while( myFAngle < 0. ) myFAngle += TwoPI;
43   while( myFAngle > 2. * M_PI ) myFAngle -= TwoPI;
44   while( mySAngle < 0. ) mySAngle += TwoPI;
45   while( mySAngle > 2. * M_PI ) mySAngle -= TwoPI;
46   if ( mySAngle < myFAngle ) mySAngle += TwoPI;
47
48   if ( ( mySAngle - myFAngle < ShortRealEpsilon() ) || 
49        ( mySAngle - myFAngle >= TwoPI ) ) {
50          myFAngle = 0.;
51          mySAngle = TwoPI;
52          myMinX = myCentX - myRad;
53          myMinY = myCentY - myRad;
54          myMaxX = myCentX + myRad;
55          myMaxY = myCentY + myRad;
56   } else {
57          Standard_ShortReal Acur,Xcur,Ycur,Xsav;
58          myMinX = myMaxX = Standard_ShortReal(Cos(myFAngle));
59          myMinY = myMaxY = Standard_ShortReal(Sin(myFAngle));
60          Xcur = Standard_ShortReal(Cos(mySAngle));
61          Ycur = Standard_ShortReal(Sin(mySAngle));
62          myMinX = myMinX < Xcur ? myMinX : Xcur;
63          myMinY = myMinY < Ycur ? myMinY : Ycur;
64          myMaxX = myMaxX > Xcur ? myMaxX : Xcur;
65          myMaxY = myMaxY > Ycur ? myMaxY : Ycur;
66
67      for ( Acur = 0., Xcur = 1., Ycur = 0.; 
68            Acur < mySAngle; Acur += Standard_ShortReal(M_PI / 2.)) {
69            if ( Acur > myFAngle ) {
70            myMinX = ( myMinX < Xcur ? myMinX : Xcur );
71            myMaxX = ( myMaxX < Xcur ? Xcur : myMaxX );
72            myMinY = ( myMinY < Ycur ? myMinY : Ycur );
73            myMaxY = ( myMaxY < Ycur ? Ycur : myMaxY );
74             }
75         Xsav = Xcur; Xcur = -Ycur; Ycur = Xsav;
76          }
77        myMinX = myCentX + myRad * myMinX;
78        myMaxX = myCentX + myRad * myMaxX;
79        myMinY = myCentY + myRad * myMinY;
80        myMaxY = myCentY + myRad * myMaxY;
81   }
82
83   // Arrows
84
85   Standard_Real ArrAngle = M_PI/180.*anArrAngle;
86      
87   gp_Pnt2d theOrigine(0.,0.);
88   gp_Pnt2d P1, P2, P3;
89   gp_Vec2d VDir;
90   Standard_Real theAngle;
91
92   if ( ( myArrow == Prs2d_AS_FIRSTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) ) {
93     P1 = gp_Pnt2d( myCentX + myRad * Cos(myFAngle),
94                myCentY + myRad * Sin(myFAngle) );
95   
96     P2 = gp_Pnt2d( anArrLength,  anArrLength*Tan( ArrAngle/2. ) );
97     P3 = gp_Pnt2d( anArrLength, -anArrLength*Tan( ArrAngle/2. ) );
98   
99     VDir = V1.Rotated(M_PI/2);
100     theAngle = VX.Angle( VDir );
101     P2.Rotate( theOrigine, theAngle );
102     P3.Rotate( theOrigine, theAngle );
103   
104     P2.Translate( gp_Vec2d( theOrigine, P1 ) );
105     P3.Translate( gp_Vec2d( theOrigine, P1 ) );
106   
107     myXVert1(1) = Standard_ShortReal( P2.X() );
108     myYVert1(1) = Standard_ShortReal( P2.Y() );
109     myXVert1(2) = Standard_ShortReal( P1.X() );
110     myYVert1(2) = Standard_ShortReal( P1.Y() );
111     myXVert1(3) = Standard_ShortReal( P3.X() );
112     myYVert1(3) = Standard_ShortReal( P3.Y() );
113
114     for ( Standard_Integer i = 1; i <= 3; i++ ) {
115           if ( myXVert1(i) < myMinX ) myMinX = myXVert1(i);
116           if ( myYVert1(i) < myMinY ) myMinY = myYVert1(i);
117           if ( myXVert1(i) > myMaxX ) myMaxX = myXVert1(i);
118           if ( myYVert1(i) > myMaxY ) myMaxY = myYVert1(i);
119           
120     }
121   } // end if myArrow is FIRSTAR or BOTHAR
122  
123   if ( ( myArrow == Prs2d_AS_LASTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) ){
124     P1 = gp_Pnt2d ( myCentX + myRad * Cos(mySAngle),
125                     myCentY + myRad * Sin(mySAngle) );
126   
127     P2 = gp_Pnt2d( anArrLength,  anArrLength*Tan( ArrAngle/2. ) );
128     P3 = gp_Pnt2d( anArrLength, -anArrLength*Tan( ArrAngle/2. ) );
129   
130     VDir = V2.Rotated(-M_PI/2);
131     theAngle = VX.Angle( VDir );
132
133     P2.Rotate( theOrigine, theAngle );
134     P3.Rotate( theOrigine, theAngle );
135   
136     P2.Translate( gp_Vec2d( theOrigine, P1 ) );
137     P3.Translate( gp_Vec2d( theOrigine, P1 ) );
138   
139     myXVert2(1) = Standard_ShortReal( P2.X() );
140     myYVert2(1) = Standard_ShortReal( P2.Y() );
141     myXVert2(2) = Standard_ShortReal( P1.X() );
142     myYVert2(2) = Standard_ShortReal( P1.Y() );
143     myXVert2(3) = Standard_ShortReal( P3.X() );
144     myYVert2(3) = Standard_ShortReal( P3.Y() );
145
146     for ( Standard_Integer i = 1; i <= 3; i++ ) {
147           if ( myXVert2(i) < myMinX ) myMinX = myXVert2(i);
148           if ( myYVert2(i) < myMinY ) myMinY = myYVert2(i);
149           if ( myXVert2(i) > myMaxX ) myMaxX = myXVert2(i);
150           if ( myYVert2(i) > myMaxY ) myMaxY = myYVert2(i);
151           
152     }
153  } // end if myArrow is FIRSTAR or BOTHAR
154
155   myNumOfElem = 4;
156   myNumOfVert = 3;
157
158 }
159
160 void Prs2d_Angle::Values( gp_Pnt2d        & aPnt1,
161                           gp_Pnt2d        & aPnt2,
162                           gp_Pnt2d        & aPnt3,
163                           Quantity_Length & aRad ) const {
164
165    aPnt1.SetCoord( myCentX, myCentY );
166    gp_Vec2d VX( myRad, 0. ), V2, V3;
167    V2 = VX.Rotated( myFAngle );  
168    aPnt2 = aPnt1.Translated( V2 );
169    V3 = VX.Rotated( mySAngle ); 
170    aPnt3 = aPnt1.Translated( V3 );
171    aRad = myRad;
172 }
173
174 void Prs2d_Angle::Draw( const Handle(Graphic2d_Drawer)& aDrawer ) {
175
176   Standard_Boolean IsIn = Standard_False;
177
178   if ( !myGOPtr->IsTransformed() )
179     IsIn = aDrawer->IsIn( myMinX, myMaxX, myMinY, myMaxY );
180   else {
181     Standard_ShortReal minx, miny, maxx, maxy;
182     MinMax( minx, maxx, miny, maxy );
183     IsIn = aDrawer->IsIn( minx, maxx, miny, maxy );
184   }
185
186   if ( IsIn ) {
187
188     DrawLineAttrib(aDrawer);
189     Standard_ShortReal theScale = Standard_ShortReal(myTextScale*aDrawer->Scale());
190     aDrawer->SetTextAttrib( myColorIndex, myTextFont, 0.0, theScale, theScale, Standard_False );
191     
192     // Text 
193     /*Standard_ShortReal dxx = aDrawer->Convert(ADDPIX);
194     gp_Pnt2d P1 = gp_Pnt2d( myCentX + ( dxx + myRad ) * Cos(myFAngle),
195                             myCentY + ( dxx + myRad ) * Sin(myFAngle) );
196   
197     gp_Pnt2d P2 = gp_Pnt2d( myCentX + ( dxx + myRad ) * Cos(mySAngle),
198                             myCentY + ( dxx + myRad ) * Sin(mySAngle) );
199   
200
201     gp_Pnt2d theCent(myCentX, myCentY);
202     gp_Vec2d V1( theCent, P1), V2( theCent, P2), VX(1., 0.);
203     Standard_Real delta = V1.Angle(V2);
204     gp_Vec2d textV1 = V1.Rotated( delta/2 );
205     Standard_Real theAngle = VX.Angle(textV1);
206     gp_Pnt2d pntText = theCent.Translated(textV1);
207     Standard_Real txtX, txtY;
208     pntText.Coord(txtX, txtY);
209     Standard_ShortReal txtAngle = Standard_ShortReal( theAngle + 3*M_PI/2);
210     
211     Standard_ShortReal ws, hs;
212     aDrawer->GetTextSize( myText, ws, hs );
213     Standard_Real theSmbX, theSmbY;
214     Standard_ShortReal ddd = aDrawer->Convert(2);
215     gp_Vec2d theVec = VX.Rotated( txtAngle );
216     theVec *= ( ws + ddd );
217     gp_Pnt2d pntSymb = pntText.Translated( theVec );
218     pntSymb.Coord( theSmbX, theSmbY );*/ //correct by enk Fri Nov 29 15:17 2002
219     
220     /////////////////////////////////////////
221     Standard_ShortReal txtAngle=Standard_ShortReal(myAbsAngle);
222     Standard_Real theSmbX,theSmbY;
223     theSmbX=myAbsX;
224     theSmbY=myAbsY;
225     /////////////////////////////////////////
226     Standard_ShortReal a = myCentX, b = myCentY, c = myRad, e = myFAngle, f = mySAngle,
227                        t1 = Standard_ShortReal(myAbsX), t2 = Standard_ShortReal(myAbsY),
228                        ts1 = Standard_ShortReal(theSmbX), ts2 = Standard_ShortReal(theSmbY);
229     
230     TShort_Array1OfShortReal Xpoint1( 1, 3 ), Ypoint1( 1, 3 ), 
231                              Xpoint2( 1, 3 ), Ypoint2( 1, 3 );
232
233     if ( myGOPtr->IsTransformed () ) {
234
235       gp_GTrsf2d aTrsf = myGOPtr->Transform ();
236       
237       if ( ( myArrow == Prs2d_AS_FIRSTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) ){
238     
239         Standard_Real a1, b1;
240         for ( Standard_Integer j = 1; j <= 3; j++ ) {
241                      a1 = Standard_Real( myXVert1(j) );
242                      b1 = Standard_Real( myYVert1(j) );
243                      aTrsf.Transforms (a1, b1);
244                      Xpoint1(j) = Standard_ShortReal(a1);
245                      Ypoint1(j) = Standard_ShortReal(b1);
246          }
247       } // end if myArrow is FIRSTAR ot BOTHAR
248    
249       if ( ( myArrow == Prs2d_AS_LASTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) ) {
250         
251         Standard_Real c1, d1;
252
253         for ( Standard_Integer j = 1; j <= 3; j++ ) {
254                      c1 = Standard_Real( myXVert2(j) );
255                      d1 = Standard_Real( myYVert2(j) );
256                      aTrsf.Transforms (c1, d1);
257                      Xpoint2(j) = Standard_ShortReal(c1);
258                      Ypoint2(j) = Standard_ShortReal(d1);
259          }
260       } // end if myArrow is LASTAR ot BOTHAR   
261
262       Standard_Real A, B, E, F, 
263                     X0, Y0, X1, Y1, X2, Y2, T1, T2;
264       A = Standard_Real( a ); 
265       B = Standard_Real( b );
266       E = Standard_Real( e ); 
267       F = Standard_Real( f );
268       T1 = Standard_Real( t1 );
269       T2 = Standard_Real( t2);
270           aTrsf.Transforms( A, B );
271           aTrsf.Transforms( T1, T2 );
272       a = Standard_ShortReal( A ); 
273       b = Standard_ShortReal( B );
274       t1 = Standard_ShortReal( T1 ); 
275       t2 = Standard_ShortReal( T2 );
276       A = Standard_Real( ts1 );
277       B = Standard_Real( ts2 );    
278           aTrsf.Transforms( A, B );
279       ts1 = Standard_ShortReal( A );
280       ts2 = Standard_ShortReal( B );
281
282           if ( Abs(f-e) < Standard_ShortReal(2. * M_PI) ) {
283             aTrsf.SetValue( 1, 3, 0.0 );
284             aTrsf.SetValue( 2, 3, 0.0 );
285
286             X1 = Cos(E); 
287             Y1 = Sin(E );
288             X2 = Cos(F); 
289             Y2 = Sin(F );
290             aTrsf.Transforms( X1, Y1 ); 
291             aTrsf.Transforms( X2, Y2 ); 
292             X0 = Y0 = 0.;
293             aTrsf.Transforms( X0, Y0 );
294             X1 -= X0; 
295             Y1 -= Y0;
296             X2 -= X0; 
297             Y2 -= Y0;
298             c = myRad * Standard_ShortReal( Sqrt(X1*X1 + Y1*Y1) );
299             e = Standard_ShortReal( atan2(Y1,X1) );
300             f = Standard_ShortReal( atan2(Y2,X2) );
301             if ( aTrsf.IsNegative() ) {
302               Standard_ShortReal t = e; e = f; f = t; 
303             }
304           } // end if Abs(f-e) < 2PI
305    } else {
306    
307     if ( ( myArrow == Prs2d_AS_FIRSTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) ){
308       Xpoint1.Assign( myXVert1 );
309       Ypoint1.Assign( myYVert1 );
310     }
311     if ( ( myArrow == Prs2d_AS_LASTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) ) {
312       Xpoint2.Assign( myXVert2 );
313       Ypoint2.Assign( myYVert2 );
314     }
315         
316    } // end if GO is transformed
317
318    aDrawer->MapArcFromTo( a, b, c, e, f );
319    aDrawer->MapTextFromTo( myText, t1, t2, txtAngle, 0., 0., Aspect_TOT_SOLID );
320
321    if ( myIsSymbol ) {
322       aDrawer->SetTextAttrib( myColorIndex, mySymbFont, 0, Standard_ShortReal(myTextScale*aDrawer->Scale()), 
323                               Standard_ShortReal(myTextScale*aDrawer->Scale()), Standard_False );
324 //      TCollection_ExtendedString txtSymb( char( SymbolCode() ) );
325       Standard_Character code = SymbolCode();
326       TCollection_ExtendedString txtSymb( code );
327       Standard_ShortReal dx=0.,dy=0.;
328       aDrawer->MapTextFromTo( txtSymb, ts1, ts2, txtAngle, dx, dy, Aspect_TOT_SOLID );
329     }
330
331
332    if ( ( myArrow == Prs2d_AS_FIRSTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) ){
333      if ( myArrType == Prs2d_TOA_CLOSED || myArrType == Prs2d_TOA_FILLED ) {
334        aDrawer->MapPolygonFromTo( Xpoint1, Ypoint1 );
335      } else {
336        aDrawer->MapPolylineFromTo( Xpoint1, Ypoint1 );
337      } 
338    }
339
340    if ( ( myArrow == Prs2d_AS_LASTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) ){
341      if ( myArrType == Prs2d_TOA_CLOSED || myArrType == Prs2d_TOA_FILLED ) {
342        aDrawer->MapPolygonFromTo( Xpoint2, Ypoint2 );
343      } else {
344        aDrawer->MapPolylineFromTo( Xpoint2, Ypoint2 );
345      } 
346    }
347    
348   } // end if IsIn is true
349 }
350
351 void Prs2d_Angle::DrawElement( const Handle(Graphic2d_Drawer)& aDrawer,
352                                const Standard_Integer anIndex) {
353   Standard_Boolean IsIn = Standard_False;
354
355   if ( ! myGOPtr->IsTransformed() )
356     IsIn = aDrawer->IsIn( myMinX, myMaxX, myMinY, myMaxY );
357   else {
358     Standard_ShortReal minx, miny, maxx, maxy;
359     MinMax( minx, maxx, miny, maxy );
360     IsIn = aDrawer->IsIn( minx, maxx, miny, maxy );
361   }
362
363   if ( IsIn ) {
364
365     DrawLineAttrib( aDrawer );
366     //  aDrawer->SetTextAttrib( myColorIndex, myTextFont, 0, myTextScale*aDrawer->Scale(), 
367     //                          myTextScale*aDrawer->Scale(), Standard_False );
368     
369     // Text 
370     /*
371     Standard_ShortReal dxx = aDrawer->Convert(ADDPIX);
372     gp_Pnt2d P1 = gp_Pnt2d( myCentX + ( dxx + myRad ) * Cos(myFAngle),
373                             myCentY + ( dxx + myRad ) * Sin(myFAngle) );
374   
375     gp_Pnt2d P2 = gp_Pnt2d( myCentX + ( dxx + myRad ) * Cos(mySAngle),
376                             myCentY + ( dxx + myRad ) * Sin(mySAngle) );
377   
378
379     gp_Pnt2d theCent(myCentX, myCentY);
380     gp_Vec2d V1( theCent, P1), V2( theCent, P2), VX(1, 0);
381     Standard_Real delta = V1.Angle(V2);
382     gp_Vec2d textV1 = V1.Rotated( delta/2 );
383     Standard_Real theAngle = VX.Angle(textV1);
384     gp_Pnt2d pntText = theCent.Translated(textV1);
385     Standard_Real txtX, txtY;
386     pntText.Coord(txtX, txtY);
387     Standard_ShortReal txtAngle = Standard_ShortReal( theAngle + 3*M_PI/2);*/
388     //correct by enk Mon Dec 2 11:39 2002
389     
390     
391     /////////////////////////////////////////
392     Standard_ShortReal txtAngle=Standard_ShortReal(myAbsAngle);
393     Standard_Real theSmbX,theSmbY;
394     theSmbX=myAbsX;
395     theSmbY=myAbsY;
396     /////////////////////////////////////////
397     Standard_ShortReal a = myCentX, b = myCentY, c = myRad, e = myFAngle, 
398                        f = mySAngle,t1 = Standard_ShortReal( myAbsX ),
399                        t2 = Standard_ShortReal( myAbsY );
400     TShort_Array1OfShortReal Xpoint( 1, 3 ), Ypoint( 1, 3 ); 
401
402     if ( anIndex == 1 ) {
403      Xpoint.Assign( myXVert1 );
404      Ypoint.Assign( myYVert1 );
405     } else if ( anIndex == 2 ) {
406      Xpoint.Assign( myXVert2 );
407      Ypoint.Assign( myYVert2 );    
408     } 
409
410     if ( myGOPtr->IsTransformed () ) {
411       gp_GTrsf2d aTrsf = myGOPtr->Transform ();
412       Standard_Real a1, b1;
413       
414       if ( anIndex == 1 ) {      
415         for ( Standard_Integer j = 1; j <= 3; j++ ) {
416                      a1 = Standard_Real( Xpoint(j) );
417                      b1 = Standard_Real( Xpoint(j) );
418                      aTrsf.Transforms( a1, b1 );
419                      Xpoint(j) = Standard_ShortReal( a1 );
420                      Ypoint(j) = Standard_ShortReal( b1 );
421          }
422       } else if ( anIndex == 2 ) {
423
424         for ( Standard_Integer j = 1; j <= 3; j++ ) {
425                      a1 = Standard_Real( Xpoint(j) );
426                      b1 = Standard_Real( Xpoint(j) );
427                      aTrsf.Transforms( a1, b1 );
428                      Xpoint(j) = Standard_ShortReal( a1 );
429                      Ypoint(j) = Standard_ShortReal( b1 );
430          }
431       } else if ( anIndex == 4 ) {
432
433           Standard_Real A, B, E, F, 
434                     X0, Y0, X1, Y1, X2, Y2;
435           A = Standard_Real( a ); 
436           B = Standard_Real( b );
437           E = Standard_Real( e ); 
438           F = Standard_Real( f );
439           aTrsf.Transforms( A, B );
440           a = Standard_ShortReal( A ); 
441           b = Standard_ShortReal( B );
442       
443               if ( Abs(f-e) < Standard_ShortReal(2. * M_PI) ) {
444                 aTrsf.SetValue( 1, 3, 0.0 );
445                 aTrsf.SetValue( 2, 3, 0.0 );
446                 X1 = Cos(E); 
447                 Y1 = Sin(E );
448                 X2 = Cos(F); 
449                 Y2 = Sin(F );
450                 aTrsf.Transforms( X1, Y1 ); 
451                 aTrsf.Transforms( X2, Y2 ); 
452                 X0 = Y0 = 0.;
453                 aTrsf.Transforms( X0, Y0 );
454                 X1 -= X0; 
455                 Y1 -= Y0;
456                 X2 -= X0; 
457                 Y2 -= Y0;
458                 c = myRad * Standard_ShortReal( Sqrt(X1*X1 + Y1*Y1) );
459                 e = Standard_ShortReal( atan2(Y1,X1) );
460                 f = Standard_ShortReal( atan2(Y2,X2) );
461                 if ( aTrsf.IsNegative() ) {
462                   Standard_ShortReal t = e; e = f; f = t; 
463                 }
464               } // end if Abs(f-e) < 2PI
465          
466         } else if ( anIndex == 3 ) {
467                  a1 = Standard_Real( t1 );
468                  b1 = Standard_Real( t2);
469                  aTrsf.Transforms( a1, b1 );
470                  t1 = Standard_ShortReal( a1 );
471                  t2 = Standard_ShortReal( b1);
472       }
473     } 
474
475     if ( anIndex == 1 || anIndex == 2 ) 
476       if ( myArrType == Prs2d_TOA_CLOSED || myArrType == Prs2d_TOA_FILLED ) {
477             aDrawer->MapPolygonFromTo( Xpoint, Ypoint );
478       } else {
479         aDrawer->MapPolylineFromTo( Xpoint, Ypoint );
480       } 
481     else if ( anIndex == 4 )
482         aDrawer->MapArcFromTo( a, b, c, e, f );
483     else if ( anIndex == 3 )
484         aDrawer->MapTextFromTo( myText, t1, t2, txtAngle, 0., 0., Aspect_TOT_SOLID );
485   
486   } // end if IsIn is true 
487
488 }
489
490 void Prs2d_Angle::DrawVertex (const Handle(Graphic2d_Drawer)& aDrawer,
491                               const Standard_Integer anIndex) {
492
493   Standard_Boolean IsIn = Standard_False;
494
495   if ( ! myGOPtr->IsTransformed() )
496     IsIn = aDrawer->IsIn( myMinX, myMaxX, myMinY, myMaxY );
497   else {
498     Standard_ShortReal minx, miny, maxx, maxy;
499     MinMax( minx, maxx, miny, maxy );
500     IsIn = aDrawer->IsIn( minx, maxx, miny, maxy );
501   }
502   
503   if ( IsIn  ) {
504    if ( anIndex > 0 && anIndex < 4 ) {
505     DrawMarkerAttrib( aDrawer );
506     Standard_ShortReal X=0.,Y=0.;
507     if ( anIndex == 1 ) {
508         X = myCentX; Y = myCentY; 
509     } else if ( anIndex == 2 ) {
510         X = Standard_ShortReal(myCentX + myRad *Cos( myFAngle ));
511         Y = Standard_ShortReal(myCentY + myRad *Sin( myFAngle ));
512     } else if ( anIndex == 3 ) {
513         X = Standard_ShortReal( myCentX + myRad *Cos( mySAngle ) );
514         Y = Standard_ShortReal( myCentY + myRad *Sin( mySAngle ) );
515     }
516     if ( myGOPtr->IsTransformed() ) {
517         gp_GTrsf2d aTrsf = myGOPtr->Transform ();
518         Standard_Real A, B;
519         A = Standard_Real( X );
520         B = Standard_Real( Y );
521         aTrsf.Transforms (A, B);
522         X = Standard_ShortReal( A );
523         Y = Standard_ShortReal( B );
524     } 
525      aDrawer->MapMarkerFromTo( VERTEXMARKER, X, Y,
526                         DEFAULTMARKERSIZE,DEFAULTMARKERSIZE, 0.0 );
527     }
528   }  // end if IsIn is true         
529
530 }
531
532 Standard_Boolean Prs2d_Angle::Pick( const Standard_ShortReal X,
533                                     const Standard_ShortReal Y,
534                                     const Standard_ShortReal aPrecision,
535                                     const Handle(Graphic2d_Drawer)& aDrawer) {
536
537   Standard_Boolean Result = Standard_False;
538   Standard_ShortReal SRX = X, SRY = Y;
539
540   if ( IsInMinMax( X, Y, aPrecision ) ) {
541
542     if ( myGOPtr->IsTransformed() ) {
543           gp_GTrsf2d aTrsf = ( myGOPtr->Transform() ).Inverted ();
544           Standard_Real RX = Standard_Real( SRX ), RY = Standard_Real( SRY );
545           aTrsf.Transforms( RX, RY );
546           SRX = Standard_ShortReal( RX ); 
547           SRY = Standard_ShortReal( RY );
548     }
549     Standard_ShortReal x1 = Standard_ShortReal(myRad *Cos( myFAngle ) + myCentX),
550                        y1 = Standard_ShortReal(myRad *Sin( myFAngle ) + myCentY),
551                        x2 = Standard_ShortReal(myRad *Cos( mySAngle ) + myCentX),
552                        y2 = Standard_ShortReal(myRad *Sin( mySAngle ) + myCentY);
553
554
555      if ( Graphic2d_Primitive::IsOn( SRX, SRY, myCentX, myCentY, aPrecision ) ) {
556          SetPickedIndex(-1);    
557          return Standard_True;
558       } else if ( Graphic2d_Primitive::IsOn( SRX, SRY, x1, y1, aPrecision ) ) {
559          SetPickedIndex(-2);    
560          return Standard_True;
561       } else if ( Graphic2d_Primitive::IsOn( SRX, SRY, x2, y2, aPrecision ) ) {
562          SetPickedIndex(-3);    
563          return Standard_True;
564       }
565
566       if ( ( myArrow == Prs2d_AS_FIRSTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) ) {
567        for ( Standard_Integer i = 1; i < 3 ; i++)
568          if ( IsOn( SRX, SRY, myXVert1(i), myYVert1(i), myXVert1(i+1), myYVert1( i+1 ), aPrecision ) ) {
569            SetPickedIndex(1);
570            return Standard_True;
571         }
572         
573            if ( myArrType == Prs2d_TOA_CLOSED || myArrType == Prs2d_TOA_FILLED ) 
574             if ( IsIn( SRX, SRY,  myXVert1, myYVert1, aPrecision ) ) {
575                SetPickedIndex(1);
576                return Standard_True;
577         }
578       } // end if myArrow == FIRSTAR or BOTHAR
579
580     if ( ( myArrow == Prs2d_AS_LASTAR ) || ( myArrow == Prs2d_AS_BOTHAR ) ){
581       for ( Standard_Integer i = 1; i < 3 ; i++)
582             if ( IsOn( SRX, SRY, myXVert2(i), myYVert2(i), myXVert2(i+1), myYVert2( i+1 ), aPrecision ) ) {
583                SetPickedIndex(2);
584                return Standard_True;
585             }
586         
587           if ( myArrType == Prs2d_TOA_CLOSED || myArrType == Prs2d_TOA_FILLED ) 
588        if ( IsIn( SRX, SRY, myXVert2, myYVert2, aPrecision ) ) {
589               SetPickedIndex(2);
590               return Standard_True;
591        }
592     } // end if myArrow == LASTAR or BOTHAR
593
594     Standard_ShortReal width,height,xoffset,yoffset;
595     Standard_ShortReal hscale = Standard_ShortReal(myTextScale*aDrawer->Scale()),
596                        wscale = Standard_ShortReal(myTextScale*aDrawer->Scale());
597     Standard_ShortReal TX = X, TY = Y;
598     
599     aDrawer->SetTextAttrib( myColorIndex, myTextFont, 0, hscale, wscale, Standard_False );
600     if ( !aDrawer->GetTextSize( myText, width, height, xoffset, yoffset ) ) {
601       width = height = xoffset = yoffset = 0.;
602     }
603     // Text 
604     /*Standard_ShortReal dxx = aDrawer->Convert(ADDPIX);
605     gp_Pnt2d P1 = gp_Pnt2d( myCentX + ( dxx + myRad ) * Cos(myFAngle),
606                             myCentY + ( dxx + myRad ) * Sin(myFAngle) );
607   
608     gp_Pnt2d P2 = gp_Pnt2d( myCentX + ( dxx + myRad ) * Cos(mySAngle),
609                             myCentY + ( dxx + myRad ) * Sin(mySAngle) );
610   
611
612     gp_Pnt2d theCent(myCentX, myCentY);
613     gp_Vec2d V1( theCent, P1), V2( theCent, P2), VX(1, 0);
614     Standard_Real delta = V1.Angle(V2);
615     gp_Vec2d textV1 = V1.Rotated( delta/2 );
616     Standard_Real theAngle = VX.Angle(textV1);
617     gp_Pnt2d pntText = theCent.Translated(textV1);
618     Standard_Real txtX, txtY;
619     pntText.Coord(txtX, txtY);
620     Standard_ShortReal txtAngle = Standard_ShortReal( theAngle + 3*M_PI/2);*/
621     //correct by enk Mon Dec 2 11:41 2002
622
623     /////////////////////////////////////////
624     Standard_Real txtX,txtY,txtA;
625     txtX=myAbsX;
626     txtY=myAbsY;
627     txtA=myAbsAngle;
628     Standard_ShortReal txtAngle=Standard_ShortReal(txtA);
629     /////////////////////////////////////////   
630     
631     Standard_ShortReal cosa = Standard_ShortReal(Cos( -txtAngle )),
632                        sina = Standard_ShortReal(Sin( -txtAngle )),
633                        dx = TX - Standard_ShortReal(txtX),
634                        dy = TY - Standard_ShortReal(txtY), 
635                        x = XROTATE(dx,dy),
636                        y = YROTATE(dx,dy);
637
638     Result   =   (x >= -aPrecision + xoffset)            
639             &&   (x <= width + xoffset + aPrecision)
640             &&   (y >= -yoffset - aPrecision) 
641             &&   (y <= height - yoffset + aPrecision);
642   
643     if ( Result ) {
644       SetPickedIndex(3);
645       return Standard_True;
646     }
647
648     if ( Abs( Sqrt( (myCentX - SRX)*(myCentX - SRX) + 
649         (myCentY - SRY)*(myCentY - SRY) ) - myRad ) < aPrecision ) {
650       SetPickedIndex(4);
651       return Standard_True;
652     }
653     
654   }     // end if IsInMinMax is true 
655
656   return Standard_False;
657 }
658
659 void Prs2d_Angle::Save(Aspect_FStream& aFStream) const
660 {
661 }