0025765: Coding rules - clean up code from obsolete macro checks
[occt.git] / src / Aspect / Aspect_CircularGrid.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 // Modified     23/02/98 : FMN ; Remplacement PI par Standard_PI
15
16 #include <Aspect_CircularGrid.ixx>
17 #include <Aspect_Grid.hxx>
18 #include <Standard_NumericError.hxx>
19 Aspect_CircularGrid::Aspect_CircularGrid
20      (const Quantity_Length aRadiusStep,
21       const Standard_Integer aDivisionNumber,
22       const Quantity_Length anXOrigin,
23       const Quantity_Length anYOrigin,
24       const Quantity_PlaneAngle aRotationAngle)
25 :Aspect_Grid(anXOrigin,anYOrigin,aRotationAngle),myRadiusStep(aRadiusStep),
26 myDivisionNumber(aDivisionNumber) {
27    }
28
29 void Aspect_CircularGrid::SetRadiusStep(const Standard_Real aRadiusStep) {
30   Standard_NegativeValue_Raise_if(aRadiusStep < 0., "invalid radius step");
31   Standard_NullValue_Raise_if(aRadiusStep == 0. , "invalid radius step");
32   myRadiusStep= aRadiusStep;
33   Init();
34   UpdateDisplay();
35 }
36 void Aspect_CircularGrid::SetDivisionNumber(const Standard_Integer aNumber) {
37   Standard_NegativeValue_Raise_if(aNumber < 0., "invalid division number");
38   Standard_NullValue_Raise_if(aNumber == 0. , "invalid division number");
39   myDivisionNumber = aNumber;
40   Init();
41   UpdateDisplay();
42 }
43 void Aspect_CircularGrid::SetGridValues
44      (const Quantity_Length theXOrigin,
45       const Quantity_Length theYOrigin,
46       const Quantity_Length theRadiusStep,
47       const Standard_Integer theDivisionNumber,
48       const Quantity_PlaneAngle theRotationAngle) {
49   myXOrigin = theXOrigin;
50   myYOrigin = theYOrigin;
51   Standard_NegativeValue_Raise_if(theRadiusStep < 0., "invalid radius step");
52   Standard_NullValue_Raise_if(theRadiusStep == 0. , "invalid radius step");
53   myRadiusStep= theRadiusStep;
54   Standard_NegativeValue_Raise_if(theDivisionNumber < 0., "invalid division number");
55   Standard_NullValue_Raise_if(theDivisionNumber == 0. , "invalid division number");
56   myDivisionNumber = theDivisionNumber;
57   myRotationAngle = theRotationAngle;
58   Init();
59   UpdateDisplay();
60 }
61 void Aspect_CircularGrid::Compute(const Quantity_Length X,
62                          const Quantity_Length Y,
63                          Quantity_Length& gridX,
64                          Quantity_Length& gridY) const {
65
66   Standard_Real xo = XOrigin();
67   Standard_Real yo = YOrigin();
68   Standard_Real d = Sqrt( (xo-X)*(xo-X) + (yo-Y)*(yo-Y) );
69   Standard_Integer n = (Standard_Integer ) ( d/myRadiusStep + 0.5 ) ;
70   Standard_Real radius = Standard_Real(n) * myRadiusStep;
71   Standard_Real cosinus = (X-xo)/d;
72   Standard_Real a = ACos(cosinus);
73   Standard_Real ra = RotationAngle();
74   if ( Y < yo ) a = 2 * M_PI - a;
75   n = (Standard_Integer ) ((a-ra)/myAlpha + Sign(0.5, a-ra)) ;
76
77   Standard_Real cs=0,sn=0;
78   Standard_Boolean done = Standard_False;
79   Standard_Integer nmax = 2*myDivisionNumber;
80   Standard_Integer nquad,qmax;
81
82   if( ra == 0. ) {
83     nquad = 4; qmax = nmax/nquad;
84     if( (n == 0) || (!(nmax % nquad) && !(n % qmax)) ) {
85       Standard_Integer q = n/qmax;
86       switch (q) {
87         default:
88         case 0:
89           cs = 1.; sn = 0.;
90           break;
91         case 1:
92           cs = 0.; sn = 1.;
93           break;
94         case 2:
95           cs = -1.; sn = 0.;
96           break;
97         case 3:
98           cs = 0.; sn = -1.;
99           break;
100       }
101       done = Standard_True;
102     } else {
103       nquad = 2; qmax = nmax/nquad;
104       if( !(nmax % nquad) && !(n % qmax) ) {
105         Standard_Integer q = n/qmax;
106         switch (q) {
107           default:
108           case 0:
109             cs = 1.; sn = 0.;
110             break;
111           case 1:
112             cs = -1.; sn = 0.;
113             break;
114         }
115         done = Standard_True;
116       }
117     }
118   } 
119
120   if( !done ) {
121     Standard_Real ang = ra + Standard_Real(n)*myAlpha;
122     cs = Cos(ang); sn = Sin(ang);
123   }
124   gridX = xo + cs * radius;
125   gridY = yo + sn * radius;
126 }
127
128 Quantity_Length Aspect_CircularGrid::RadiusStep() const {
129   return myRadiusStep;
130 }
131
132 Standard_Integer Aspect_CircularGrid::DivisionNumber () const {
133 return myDivisionNumber;
134 }
135
136 void Aspect_CircularGrid::Init () {
137   myAlpha = M_PI / Standard_Real(myDivisionNumber);
138   myA1 = Cos(myAlpha); myB1=Sin(myAlpha);
139 }