0022792: Globally defined symbol PI conflicts with VTK definition (Intel compiler)
[occt.git] / src / Prs2d / Prs2d_RadiusIndep.cxx
1 #include <Prs2d_RadiusIndep.ixx>
2
3 #define VERTEXMARKER 2
4 #define DEFAULTMARKERSIZE 3.0
5
6 Prs2d_RadiusIndep::Prs2d_RadiusIndep( const Handle(Graphic2d_GraphicObject) & aGO, 
7                                       const gp_Pnt2d                        & anAttachPnt, 
8                                       const gp_Pnt2d                        & aCenter,
9                                       const Standard_Real                     aRad,
10                                       const TCollection_ExtendedString      & aText,
11                                       const Standard_Real                     aLength, 
12                                       const Prs2d_TypeOfRadius                aTypeRad,
13                                       const Standard_Real                     aTxtScale ) 
14
15   : Graphic2d_Line( aGO ),
16   
17     myX1( Standard_ShortReal( anAttachPnt.X() ) ),
18         myY1( Standard_ShortReal( anAttachPnt.Y() ) ),
19         myX2( Standard_ShortReal( aCenter.X() ) ),
20         myY2( Standard_ShortReal( aCenter.Y() ) ),
21     myTextScale( Standard_ShortReal( aTxtScale ) ),
22     myText( aText ),
23     myXVert( 1, 3 ),
24         myYVert( 1, 3 ),
25     myIsSymbol( Standard_False ),
26     mySymbCode( 198 ),
27     myTextFont( 0 ),
28     mySymbFont( 0 ),
29     myAttPnt( anAttachPnt ),
30     myCenter( aCenter ),
31     myRadius( aRad ),
32     myLength( aLength ),
33     myRadType( aTypeRad )
34     
35 {
36    gp_Vec2d theVec1( gp_Pnt2d( myX2, myY2 ), gp_Pnt2d( myX1, myY1 ) );
37    gp_Vec2d theUnVec( 1., 0. );
38    myTextAng = Standard_ShortReal( theUnVec.Angle( theVec1 ) );
39    Standard_Real theLen = sqrt( (myX2-myX1)*(myX2-myX1) + (myY2-myY1)*(myY2-myY1) );
40    gp_Vec2d VecAdd = theVec1.Normalized();
41    theVec1.Normalize();
42    theVec1 *= ( theLen + aLength );
43    gp_Pnt2d P1 = aCenter.Translated( theVec1 );
44    myTextX = Standard_ShortReal( P1.X() );
45    myTextY = Standard_ShortReal( P1.Y() );
46    gp_Pnt2d PArr( myX1, myY1 );
47     
48    if ( ( theLen + aLength ) > theLen ) 
49      myInside = Standard_False;
50    else 
51      myInside = Standard_True;
52
53   switch( aTypeRad ) {
54    default:
55    case Prs2d_TOR_STANDARD : {
56
57      myX2 = Standard_ShortReal( P1.X() );
58          myY2 = Standard_ShortReal( P1.Y() );
59      if  ( ( theLen + aLength ) > theLen ) {
60          theVec1.Reverse();    
61      }
62    }
63    break;          
64    case Prs2d_TOR_CENTER : {
65      
66      if ( aLength > 0.0 ) {
67        myX1 = Standard_ShortReal( P1.X() );
68            myY1 = Standard_ShortReal( P1.Y() );
69        theVec1.Reverse();      
70      }
71    }
72    break;
73    case Prs2d_TOR_REVARROW : {
74        
75      myX2 = Standard_ShortReal( P1.X() );
76          myY2 = Standard_ShortReal( P1.Y() );
77      if  ( ( theLen + aLength ) <= theLen ) 
78          theVec1.Reverse();    
79      else 
80          VecAdd.Reverse();
81      Standard_Real Dt = sqrt( ( myX2 - myX1 )*( myX2 - myX1 ) + ( myY2 - myY1 )*( myY2 - myY1 ) );
82      VecAdd *= Dt/2;
83      gp_Pnt2d PTmpn = PArr.Translated( VecAdd );
84      myX1 = Standard_ShortReal( PTmpn.X() );
85      myY1 = Standard_ShortReal( PTmpn.Y() );
86    }
87
88    break;
89    case Prs2d_TOR_CENTREV : {
90
91      if ( aLength > 0.0 ) {
92        myX1 = Standard_ShortReal( P1.X() );
93            myY1 = Standard_ShortReal( P1.Y() );
94      } else { 
95        theVec1.Reverse();
96        Standard_Real Dt = sqrt( ( myX2 - myX1 )*( myX2 - myX1 ) + ( myY2 - myY1 )*( myY2 - myY1 ) );
97        VecAdd *= Dt/2;
98        gp_Pnt2d PTmpn = PArr.Translated( VecAdd );
99        myX1 = Standard_ShortReal( PTmpn.X() );
100        myY1 = Standard_ShortReal( PTmpn.Y() );
101      }
102     }
103     break;    
104    } // end switch
105
106    myMinX       = myX1;
107    myMinY       = myY1;
108    myMaxX       = myX1;
109    myMaxY       = myY1;
110
111    if ( myX2 < myMinX ) myMinX = myX2;
112    if ( myY2 < myMinY ) myMinY = myY2;
113    if ( myX2 > myMaxX ) myMaxX = myX2;
114    if ( myY2 > myMaxY ) myMaxY = myY2;
115    
116    Standard_Real ArrANG = M_PI / 6., theArrLN  = aRad/5., theANG;
117    gp_Pnt2d theOrig( 0., 0. ), P2, P3;
118    gp_Vec2d VX( 1., 0. );
119  
120    P2 = gp_Pnt2d( theArrLN,  theArrLN*Tan( ArrANG/2. ) );
121    P3 = gp_Pnt2d( theArrLN, -theArrLN*Tan( ArrANG/2. ) );
122    theVec1.Reverse();
123    theANG = VX.Angle( theVec1 );
124    P2.Rotate( theOrig, theANG );
125    P3.Rotate( theOrig, theANG );
126   
127    P2.Translate( gp_Vec2d( theOrig, PArr ) );
128    P3.Translate( gp_Vec2d( theOrig, PArr ) );
129   
130    myXVert(1) = Standard_ShortReal( P2.X() );
131    myYVert(1) = Standard_ShortReal( P2.Y() );
132    myXVert(2) = Standard_ShortReal( PArr.X() );
133    myYVert(2) = Standard_ShortReal( PArr.Y() );
134    myXVert(3) = Standard_ShortReal( P3.X() );
135    myYVert(3) = Standard_ShortReal( P3.Y() );
136
137    for ( Standard_Integer i = 1; i <= 3; i++ ) {
138            
139            if ( myXVert(i) < myMinX ) myMinX = myXVert(i);
140        if ( myYVert(i) < myMinY ) myMinY = myYVert(i);
141        if ( myXVert(i) > myMaxX ) myMaxX = myXVert(i);
142            if ( myYVert(i) > myMaxY ) myMaxY = myYVert(i);
143            
144    }
145 }
146
147 void Prs2d_RadiusIndep::Values(gp_Pnt2d& anAttPnt,
148                                gp_Pnt2d& aCenter,
149                                Standard_Real& aRad,
150                                TCollection_ExtendedString& aText,
151                                Standard_Real& aLength,
152                                Prs2d_TypeOfRadius& aTypeRad,
153                                Standard_Real& aTxtScale) const {
154
155     anAttPnt   = myAttPnt;
156     aCenter    = myCenter;
157     aRad       = myRadius;
158     aText      = myText;
159     aLength    = myLength;
160     aTypeRad   = myRadType;
161     aTxtScale  = myTextScale;
162 }
163
164 void Prs2d_RadiusIndep::Draw( const Handle(Graphic2d_Drawer)& aDrawer ) {
165
166   Standard_Boolean IsIn = Standard_False;
167
168   if ( ! myGOPtr->IsTransformed() )
169     IsIn = aDrawer->IsIn (myMinX,myMaxX,myMinY,myMaxY);
170   else {
171     Standard_ShortReal minx, miny, maxx, maxy;
172     MinMax(minx,maxx,miny,maxy);
173     IsIn = aDrawer->IsIn (minx,maxx,miny,maxy);
174   }
175
176   if ( IsIn ) {
177
178     DrawLineAttrib(aDrawer);
179     aDrawer->SetTextAttrib( myColorIndex, myTextFont, 0, Standard_ShortReal( myTextScale*aDrawer->Scale() ), 
180                             Standard_ShortReal( myTextScale*aDrawer->Scale()), Standard_False );
181
182     Standard_ShortReal aWidth, aHeight;
183     aDrawer->GetTextSize( myText, aWidth, aHeight );
184     Standard_ShortReal Xt = myTextX, Yt = myTextY;
185     if ( !myInside ) {
186         gp_Pnt2d P1( myX1, myY1 ), P2( myX2, myY2 ), 
187                  PT( myTextX, myTextY ), PTMP;
188         ( PT.IsEqual( P1, 0. ) ) 
189         ? PTMP.SetCoord( P2.X(), P2.Y() ) 
190         : PTMP.SetCoord( P1.X(), P1.Y() );
191         gp_Vec2d theVec1( PT, PTMP );
192         theVec1.Normalize();
193         theVec1 *= aWidth;
194         gp_Pnt2d PTT = PT.Translated( theVec1 );
195         Xt = Standard_ShortReal( PTT.X() ); 
196         Yt = Standard_ShortReal( PTT.Y() );
197     }
198
199     Standard_Real theSmbX = 0., theSmbY = 0.;
200     
201     if ( myIsSymbol ) {
202       aDrawer->SetTextAttrib( myColorIndex, mySymbFont, 0, Standard_ShortReal(myTextScale*aDrawer->Scale()), 
203                               Standard_ShortReal(myTextScale*aDrawer->Scale()), Standard_False );
204       TCollection_ExtendedString txtSymb = TCollection_ExtendedString( char( mySymbCode ) );
205       theSmbX = Xt; theSmbY = Yt;
206       gp_Pnt2d pntText( Xt, Yt );
207       Standard_ShortReal ws, hs;
208       aDrawer->GetTextSize( txtSymb, ws, hs );
209       Standard_ShortReal ddd = aDrawer->Convert(2);
210       gp_Vec2d VX( 1., 0. ), theVec;
211       theVec = VX.Rotated( myTextAng );
212       theVec *= ( ws + ddd );
213       gp_Pnt2d pntSymb = pntText.Translated( theVec );
214       Standard_Real txtX, txtY;
215       pntSymb.Coord( txtX, txtY );
216       Xt = Standard_ShortReal( txtX ); 
217       Yt = Standard_ShortReal( txtY );
218     } 
219
220     Standard_ShortReal a = myX1, b = myY1, 
221                        c = myX2, d = myY2,
222                        e = Xt,   f = Yt, 
223                        w = 0.,   h = Standard_ShortReal( aHeight/5 ),
224                        ts1 = Standard_ShortReal( theSmbX ), 
225                        ts2 = Standard_ShortReal( theSmbY );
226
227     TShort_Array1OfShortReal Xpoint( 1, 3 ), Ypoint( 1, 3 );
228     Xpoint.Assign( myXVert );
229     Ypoint.Assign( myYVert ); 
230
231     if ( myGOPtr->IsTransformed() ) {
232
233       gp_GTrsf2d aTrsf = myGOPtr->Transform();
234       Standard_Real A1, B1;
235       A1 = Standard_Real( a ); B1 = Standard_Real( b );
236       aTrsf.Transforms( A1, B1 );
237       a = Standard_ShortReal( A1 ); b = Standard_ShortReal( B1 );
238       A1 = Standard_Real( c ); B1 = Standard_Real( d );
239       aTrsf.Transforms( A1, B1 );
240       c = Standard_ShortReal( A1 ); d = Standard_ShortReal( B1 );
241       A1 = Standard_Real( e ); B1 = Standard_Real( f );
242       aTrsf.Transforms( A1, B1 );
243       e = Standard_ShortReal( A1 ); f = Standard_ShortReal( B1 );
244       A1 = Standard_Real( w ); B1 = Standard_Real( h );
245       aTrsf.Transforms( A1, B1 );
246       w = Standard_ShortReal( A1 ); h = Standard_ShortReal( B1 );
247       A1 = Standard_Real( ts1 ); B1 = Standard_Real( ts2 );
248       aTrsf.Transforms( A1, B1 );
249       ts1 = Standard_ShortReal( A1 ); ts2 = Standard_ShortReal( B1 );
250   
251       for ( int j = 1; j <= 3; j++ ) {
252            A1 = Standard_Real( myXVert(j) );
253            B1 = Standard_Real( myYVert(j) );
254        aTrsf.Transforms( A1, B1 );
255        Xpoint(j) = Standard_ShortReal(A1);
256            Ypoint(j) = Standard_ShortReal(B1);
257       }
258    
259      }
260
261      DrawLineAttrib( aDrawer );
262      aDrawer->MapSegmentFromTo( a, b, c, d );
263      aDrawer->MapPolygonFromTo( Xpoint, Ypoint);
264      if ( myIsSymbol ) {
265       aDrawer->SetTextAttrib( myColorIndex, mySymbFont, 0, Standard_ShortReal(myTextScale*aDrawer->Scale()), 
266                               Standard_ShortReal(myTextScale*aDrawer->Scale()), Standard_False );
267       TCollection_ExtendedString txtSymb = TCollection_ExtendedString( char( mySymbCode ) );
268       aDrawer->MapTextFromTo( txtSymb, ts1, ts2, myTextAng, 0., 0., Aspect_TOT_SOLID );
269     }
270
271      aDrawer->SetTextAttrib( myColorIndex, myTextFont, 0, Standard_ShortReal( myTextScale*aDrawer->Scale() ), 
272                             Standard_ShortReal( myTextScale*aDrawer->Scale()), Standard_False );
273
274      aDrawer->MapTextFromTo( myText, e, f, myTextAng, 0., 0., Aspect_TOT_SOLID ); 
275      
276   }
277 }
278
279 void Prs2d_RadiusIndep::DrawElement( const Handle(Graphic2d_Drawer)& /*aDrawer*/, 
280                                      const Standard_Integer /*anIndex*/ ) {
281
282 }
283
284 void Prs2d_RadiusIndep::DrawVertex( const Handle(Graphic2d_Drawer)& /*aDrawer*/, 
285                                     const Standard_Integer /*anIndex*/ ) {
286 }
287
288 Standard_Boolean Prs2d_RadiusIndep::Pick( const Standard_ShortReal X,
289                                           const Standard_ShortReal Y,
290                                           const Standard_ShortReal aPrecision,
291                                           const Handle(Graphic2d_Drawer)& /*aDrawer*/) {
292    Standard_ShortReal SRX = X, SRY = Y;
293    Standard_Boolean Result = Standard_False;
294    
295    if ( IsInMinMax( X, Y, aPrecision ) ) {
296       if ( myGOPtr->IsTransformed () ) {
297          gp_GTrsf2d aTrsf = ( myGOPtr->Transform() ).Inverted();
298          Standard_Real RX = Standard_Real(SRX), RY = Standard_Real(SRY);
299                  aTrsf.Transforms(RX, RY);
300                  SRX = Standard_ShortReal(RX);
301                  SRY = Standard_ShortReal(RY);
302       }
303    Result = IsOn( SRX, SRY, myX1, myY1, myX2, myY2, aPrecision );
304    }
305    return Result;
306
307 }
308
309 void Prs2d_RadiusIndep::SetTextScale( const Standard_Real aTxtScale ) {
310      myTextScale = Standard_ShortReal( aTxtScale );
311 }
312
313 void Prs2d_RadiusIndep::SetText( const TCollection_ExtendedString & aText ) {
314      myText = aText;
315 }
316
317 void Prs2d_RadiusIndep::DrawSymbol(const Standard_Boolean isDraw ) {
318   myIsSymbol = isDraw;
319 }
320  
321 void Prs2d_RadiusIndep::SetSymbolCode( const Standard_Integer aCode ) {
322   mySymbCode = aCode;
323 }
324
325 void Prs2d_RadiusIndep::SetTextFont(const Standard_Integer aTF) {
326     myTextFont = aTF;
327 }
328  
329 void Prs2d_RadiusIndep::SetFontOfSymb(const Standard_Integer aFS) {
330    mySymbFont = aFS;
331 }
332
333 Standard_Boolean Prs2d_RadiusIndep::IsDrawSymbol() const {
334   return myIsSymbol;
335 }
336
337 Standard_Integer Prs2d_RadiusIndep::SymbolCode() const {
338   return mySymbCode;
339  
340 }
341
342 Standard_Integer Prs2d_RadiusIndep::TextFont() const {
343   return myTextFont;
344 }
345  
346 Standard_Integer Prs2d_RadiusIndep::FontOfSymb() const {
347   return mySymbFont;
348 }
349
350 void Prs2d_RadiusIndep::Save(Aspect_FStream& aFStream) const
351 {
352 }