0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / Aspect / Aspect_CircularGrid.cxx
... / ...
CommitLineData
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.hxx>
17#include <Aspect_Grid.hxx>
18#include <Standard_NegativeValue.hxx>
19#include <Standard_NullValue.hxx>
20#include <Standard_NumericError.hxx>
21#include <Standard_Type.hxx>
22
23Aspect_CircularGrid::Aspect_CircularGrid
24 (const Quantity_Length aRadiusStep,
25 const Standard_Integer aDivisionNumber,
26 const Quantity_Length anXOrigin,
27 const Quantity_Length anYOrigin,
28 const Quantity_PlaneAngle aRotationAngle)
29:Aspect_Grid(anXOrigin,anYOrigin,aRotationAngle),myRadiusStep(aRadiusStep),
30myDivisionNumber(aDivisionNumber) {
31 }
32
33void Aspect_CircularGrid::SetRadiusStep(const Standard_Real aRadiusStep) {
34 Standard_NegativeValue_Raise_if(aRadiusStep < 0., "invalid radius step");
35 Standard_NullValue_Raise_if(aRadiusStep == 0. , "invalid radius step");
36 myRadiusStep= aRadiusStep;
37 Init();
38 UpdateDisplay();
39}
40void Aspect_CircularGrid::SetDivisionNumber(const Standard_Integer aNumber) {
41 Standard_NegativeValue_Raise_if(aNumber < 0., "invalid division number");
42 Standard_NullValue_Raise_if(aNumber == 0. , "invalid division number");
43 myDivisionNumber = aNumber;
44 Init();
45 UpdateDisplay();
46}
47void Aspect_CircularGrid::SetGridValues
48 (const Quantity_Length theXOrigin,
49 const Quantity_Length theYOrigin,
50 const Quantity_Length theRadiusStep,
51 const Standard_Integer theDivisionNumber,
52 const Quantity_PlaneAngle theRotationAngle) {
53 myXOrigin = theXOrigin;
54 myYOrigin = theYOrigin;
55 Standard_NegativeValue_Raise_if(theRadiusStep < 0., "invalid radius step");
56 Standard_NullValue_Raise_if(theRadiusStep == 0. , "invalid radius step");
57 myRadiusStep= theRadiusStep;
58 Standard_NegativeValue_Raise_if(theDivisionNumber < 0., "invalid division number");
59 Standard_NullValue_Raise_if(theDivisionNumber == 0. , "invalid division number");
60 myDivisionNumber = theDivisionNumber;
61 myRotationAngle = theRotationAngle;
62 Init();
63 UpdateDisplay();
64}
65void Aspect_CircularGrid::Compute(const Quantity_Length X,
66 const Quantity_Length Y,
67 Quantity_Length& gridX,
68 Quantity_Length& gridY) const {
69
70 Standard_Real xo = XOrigin();
71 Standard_Real yo = YOrigin();
72 Standard_Real d = Sqrt( (xo-X)*(xo-X) + (yo-Y)*(yo-Y) );
73 Standard_Integer n = (Standard_Integer ) ( d/myRadiusStep + 0.5 ) ;
74 Standard_Real radius = Standard_Real(n) * myRadiusStep;
75 Standard_Real cosinus = (X-xo)/d;
76 Standard_Real a = ACos(cosinus);
77 Standard_Real ra = RotationAngle();
78 if ( Y < yo ) a = 2 * M_PI - a;
79 n = (Standard_Integer ) ((a-ra)/myAlpha + Sign(0.5, a-ra)) ;
80
81 Standard_Real cs=0,sn=0;
82 Standard_Boolean done = Standard_False;
83 Standard_Integer nmax = 2*myDivisionNumber;
84 Standard_Integer nquad,qmax;
85
86 if( ra == 0. ) {
87 nquad = 4; qmax = nmax/nquad;
88 if( (n == 0) || (!(nmax % nquad) && !(n % qmax)) ) {
89 Standard_Integer q = n/qmax;
90 switch (q) {
91 default:
92 case 0:
93 cs = 1.; sn = 0.;
94 break;
95 case 1:
96 cs = 0.; sn = 1.;
97 break;
98 case 2:
99 cs = -1.; sn = 0.;
100 break;
101 case 3:
102 cs = 0.; sn = -1.;
103 break;
104 }
105 done = Standard_True;
106 } else {
107 nquad = 2; qmax = nmax/nquad;
108 if( !(nmax % nquad) && !(n % qmax) ) {
109 Standard_Integer q = n/qmax;
110 switch (q) {
111 default:
112 case 0:
113 cs = 1.; sn = 0.;
114 break;
115 case 1:
116 cs = -1.; sn = 0.;
117 break;
118 }
119 done = Standard_True;
120 }
121 }
122 }
123
124 if( !done ) {
125 Standard_Real ang = ra + Standard_Real(n)*myAlpha;
126 cs = Cos(ang); sn = Sin(ang);
127 }
128 gridX = xo + cs * radius;
129 gridY = yo + sn * radius;
130}
131
132Quantity_Length Aspect_CircularGrid::RadiusStep() const {
133 return myRadiusStep;
134}
135
136Standard_Integer Aspect_CircularGrid::DivisionNumber () const {
137return myDivisionNumber;
138}
139
140void Aspect_CircularGrid::Init () {
141 myAlpha = M_PI / Standard_Real(myDivisionNumber);
142 myA1 = Cos(myAlpha); myB1=Sin(myAlpha);
143}