1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 // Modified 23/02/98 : FMN ; Remplacement PI par Standard_PI
20 #define CSR577 //GG 25/09/00 Avoid to have unaccuracy coordinates computation
21 // when the grid is activated.
23 #define OCC192_193 // jfa 27/02/2002
24 // for big rotation angles - error of negative values expression in round numbers
28 #include <Aspect_CircularGrid.ixx>
29 #include <Aspect_Grid.hxx>
30 #include <Standard_NumericError.hxx>
31 Aspect_CircularGrid::Aspect_CircularGrid
32 (const Quantity_Length aRadiusStep,
33 const Standard_Integer aDivisionNumber,
34 const Quantity_Length anXOrigin,
35 const Quantity_Length anYOrigin,
36 const Quantity_PlaneAngle aRotationAngle)
37 :Aspect_Grid(anXOrigin,anYOrigin,aRotationAngle),myRadiusStep(aRadiusStep),
38 myDivisionNumber(aDivisionNumber) {
41 void Aspect_CircularGrid::SetRadiusStep(const Standard_Real aRadiusStep) {
42 Standard_NegativeValue_Raise_if(aRadiusStep < 0., "invalid radius step");
43 Standard_NullValue_Raise_if(aRadiusStep == 0. , "invalid radius step");
44 myRadiusStep= aRadiusStep;
48 void Aspect_CircularGrid::SetDivisionNumber(const Standard_Integer aNumber) {
49 Standard_NegativeValue_Raise_if(aNumber < 0., "invalid division number");
50 Standard_NullValue_Raise_if(aNumber == 0. , "invalid division number");
51 myDivisionNumber = aNumber;
55 void Aspect_CircularGrid::SetGridValues
56 (const Quantity_Length theXOrigin,
57 const Quantity_Length theYOrigin,
58 const Quantity_Length theRadiusStep,
59 const Standard_Integer theDivisionNumber,
60 const Quantity_PlaneAngle theRotationAngle) {
61 myXOrigin = theXOrigin;
62 myYOrigin = theYOrigin;
63 Standard_NegativeValue_Raise_if(theRadiusStep < 0., "invalid radius step");
64 Standard_NullValue_Raise_if(theRadiusStep == 0. , "invalid radius step");
65 myRadiusStep= theRadiusStep;
66 Standard_NegativeValue_Raise_if(theDivisionNumber < 0., "invalid division number");
67 Standard_NullValue_Raise_if(theDivisionNumber == 0. , "invalid division number");
68 myDivisionNumber = theDivisionNumber;
69 myRotationAngle = theRotationAngle;
73 void Aspect_CircularGrid::Compute(const Quantity_Length X,
74 const Quantity_Length Y,
75 Quantity_Length& gridX,
76 Quantity_Length& gridY) const {
79 if( X == 0. || Y == 0. ) {
80 cout << " Aspect_CircularGrid" << endl;
83 Standard_Real xo = XOrigin();
84 Standard_Real yo = YOrigin();
85 Standard_Real d = Sqrt( (xo-X)*(xo-X) + (yo-Y)*(yo-Y) );
86 Standard_Integer n = (Standard_Integer ) ( d/myRadiusStep + 0.5 ) ;
87 Standard_Real radius = Standard_Real(n) * myRadiusStep;
88 Standard_Real cosinus = (X-xo)/d;
89 Standard_Real a = ACos(cosinus);
90 Standard_Real ra = RotationAngle();
91 if ( Y < yo ) a = 2 * M_PI - a;
93 n = (Standard_Integer ) ((a-ra)/myAlpha + Sign(0.5, a-ra)) ;
95 n = (Standard_Integer ) ((a-ra)/myAlpha +0.5 ) ;
99 Standard_Real cs=0,sn=0;
100 Standard_Boolean done = Standard_False;
101 Standard_Integer nmax = 2*myDivisionNumber;
102 Standard_Integer nquad,qmax;
105 nquad = 4; qmax = nmax/nquad;
106 if( (n == 0) || (!(nmax % nquad) && !(n % qmax)) ) {
107 Standard_Integer q = n/qmax;
123 done = Standard_True;
125 nquad = 2; qmax = nmax/nquad;
126 if( !(nmax % nquad) && !(n % qmax) ) {
127 Standard_Integer q = n/qmax;
137 done = Standard_True;
143 Standard_Real ang = ra + Standard_Real(n)*myAlpha;
144 cs = Cos(ang); sn = Sin(ang);
147 Standard_Real ang = RotationAngle()+ Standard_Real(n)*myAlpha;
148 Standard_Real cs = Cos(ang);
149 Standard_Real sn = Sin(ang);
151 gridX = xo + cs * radius;
152 gridY = yo + sn * radius;
154 cout << "Aspect_CircularGrid::Compute (" << Quantity_Length (X) << ", "
155 << Quantity_Length (Y) << ", " << Quantity_Length (gridX) << ", "
156 << Quantity_Length (gridY) << ")" << endl;
160 Quantity_Length Aspect_CircularGrid::RadiusStep() const {
164 Standard_Integer Aspect_CircularGrid::DivisionNumber () const {
165 return myDivisionNumber;
168 void Aspect_CircularGrid::Init () {
169 myAlpha = M_PI / Standard_Real(myDivisionNumber);
170 myA1 = Cos(myAlpha); myB1=Sin(myAlpha);