Commit | Line | Data |
---|---|---|
b311480e | 1 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
2 | // | |
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. | |
7 | // | |
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. | |
10 | // | |
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. | |
17 | ||
7fd59977 | 18 | // Modified 23/02/98 : FMN ; Remplacement PI par Standard_PI |
19 | ||
20 | #define CSR577 //GG 25/09/00 Avoid to have unaccuracy coordinates computation | |
21 | // when the grid is activated. | |
22 | ||
23 | #define xTRACE | |
24 | ||
25 | #include <Aspect_RectangularGrid.ixx> | |
26 | ||
27 | ||
28 | Aspect_RectangularGrid::Aspect_RectangularGrid( | |
29 | const Quantity_Length aXStep, | |
30 | const Quantity_Length aYStep, | |
31 | const Quantity_Length anXOrigin, | |
32 | const Quantity_Length anYOrigin, | |
33 | const Quantity_PlaneAngle aFirstAngle, | |
34 | const Quantity_PlaneAngle aSecondAngle, | |
35 | const Quantity_PlaneAngle aRotationAngle) | |
36 | :Aspect_Grid(anXOrigin,anYOrigin,aRotationAngle),myXStep(aXStep),myYStep(aYStep),myFirstAngle(aFirstAngle),mySecondAngle(aSecondAngle) | |
37 | ||
38 | { | |
39 | Standard_NumericError_Raise_if(!CheckAngle (aFirstAngle,mySecondAngle), | |
40 | "networks are parallel"); | |
41 | ||
42 | Standard_NegativeValue_Raise_if(aXStep < 0. , "invalid x step"); | |
43 | Standard_NegativeValue_Raise_if(aYStep < 0. , "invalid y step"); | |
44 | Standard_NullValue_Raise_if(aXStep == 0. , "invalid x step"); | |
45 | Standard_NullValue_Raise_if(aYStep == 0. , "invalid y step"); | |
46 | } | |
47 | ||
48 | ||
49 | ||
50 | void Aspect_RectangularGrid::SetXStep(const Quantity_Length aStep) { | |
51 | Standard_NegativeValue_Raise_if(aStep < 0. , "invalid x step"); | |
52 | Standard_NullValue_Raise_if(aStep == 0. , "invalid y step"); | |
53 | myXStep = aStep; | |
54 | Init(); | |
55 | UpdateDisplay(); | |
56 | } | |
57 | ||
58 | void Aspect_RectangularGrid::SetYStep(const Quantity_Length aStep) { | |
59 | Standard_NegativeValue_Raise_if(aStep < 0. , "invalid x step"); | |
60 | Standard_NullValue_Raise_if(aStep == 0. , "invalid y step"); | |
61 | myYStep = aStep; | |
62 | Init(); | |
63 | UpdateDisplay(); | |
64 | } | |
65 | ||
66 | void Aspect_RectangularGrid::SetAngle(const Quantity_PlaneAngle anAngle1, | |
67 | const Quantity_PlaneAngle anAngle2){ | |
68 | ||
69 | Standard_NumericError_Raise_if(!CheckAngle (anAngle1,anAngle2 ), | |
70 | "axis are parallel"); | |
71 | myFirstAngle = anAngle1; | |
72 | mySecondAngle = anAngle2; | |
73 | Init(); | |
74 | UpdateDisplay(); | |
75 | } | |
76 | ||
77 | void Aspect_RectangularGrid::SetGridValues( | |
78 | const Quantity_Length theXOrigin, | |
79 | const Quantity_Length theYOrigin, | |
80 | const Quantity_Length theXStep, | |
81 | const Quantity_Length theYStep, | |
82 | const Quantity_PlaneAngle theRotationAngle) { | |
83 | ||
84 | myXOrigin = theXOrigin; | |
85 | myYOrigin = theYOrigin; | |
86 | Standard_NegativeValue_Raise_if(theXStep < 0. , "invalid x step"); | |
87 | Standard_NullValue_Raise_if(theXStep == 0. , "invalid x step"); | |
88 | myXStep = theXStep; | |
89 | Standard_NegativeValue_Raise_if(theYStep < 0. , "invalid y step"); | |
90 | Standard_NullValue_Raise_if(theYStep == 0. , "invalid y step"); | |
91 | myYStep = theYStep; | |
92 | myRotationAngle = theRotationAngle; | |
93 | Init(); | |
94 | UpdateDisplay(); | |
95 | } | |
96 | ||
97 | void Aspect_RectangularGrid::Compute(const Quantity_Length X, | |
98 | const Quantity_Length Y, | |
99 | Quantity_Length& gridX, | |
100 | Quantity_Length& gridY) const { | |
101 | Standard_Real D1 = b1 * X - a1 * Y - c1; | |
102 | Standard_Real D2 = b2 * X - a2 * Y - c2; | |
103 | Standard_Integer n1 = Standard_Integer ( Abs(D1)/myXStep + 0.5); | |
104 | Standard_Integer n2 = Standard_Integer ( Abs(D2)/myYStep + 0.5); | |
105 | Standard_Real offset1 = c1 + Standard_Real(n1) * Sign (myXStep , D1); | |
106 | Standard_Real offset2 = c2 + Standard_Real(n2) * Sign (myYStep , D2); | |
107 | #ifdef CSR577 | |
108 | Standard_Real Delta = a1*b2 - b1*a2; | |
109 | gridX = ( offset2*a1 - offset1*a2) /Delta; | |
110 | gridY = ( offset2*b1 - offset1*b2) /Delta; | |
111 | #else | |
112 | Standard_Real Delta = b1*a2 - a1*b2; | |
113 | gridX = ( offset1*a2 - offset2*a1) /Delta; | |
114 | gridY = ( offset1*b2 - offset2*b1) /Delta; | |
115 | #endif | |
116 | #ifdef TRACE | |
117 | cout << "Aspect_RectangularGrid::Compute (" << Quantity_Length (X) << ", " | |
118 | << Quantity_Length (Y) << ", " << Quantity_Length (gridX) << ", " | |
119 | << Quantity_Length (gridY) << ")" << endl; | |
120 | #endif | |
121 | } | |
122 | ||
123 | Quantity_Length Aspect_RectangularGrid::XStep() const { | |
124 | return myXStep; | |
125 | } | |
126 | ||
127 | Quantity_Length Aspect_RectangularGrid::YStep() const { | |
128 | return myYStep; | |
129 | } | |
130 | ||
131 | Quantity_Length Aspect_RectangularGrid::FirstAngle() const { | |
132 | return myFirstAngle; | |
133 | } | |
134 | ||
135 | Quantity_Length Aspect_RectangularGrid::SecondAngle() const { | |
136 | return mySecondAngle; | |
137 | } | |
138 | ||
139 | void Aspect_RectangularGrid::Init () { | |
140 | ||
141 | //+zov Fixing CTS17856 | |
142 | // a1 = Cos (myFirstAngle + RotationAngle() ); | |
143 | // b1 = Sin (myFirstAngle + RotationAngle() ); | |
144 | // c1 = XOrigin() * b1 - YOrigin() * a1; | |
145 | // | |
c6541a0c D |
146 | // a2 = Cos (mySecondAngle + RotationAngle() + M_PI / 2.); |
147 | // b2 = Sin (mySecondAngle + RotationAngle() + M_PI / 2.); | |
7fd59977 | 148 | // c2 = XOrigin() * b2 - YOrigin() * a2; |
149 | ||
150 | #ifdef CSR577 | |
151 | Standard_Real angle1 = myFirstAngle + RotationAngle(); | |
152 | Standard_Real angle2 = mySecondAngle + RotationAngle(); | |
153 | if ( angle1 != 0. ) { | |
154 | a1 = -Sin (angle1); | |
155 | b1 = Cos (angle1); | |
156 | c1 = XOrigin() * b1 - YOrigin() * a1; | |
157 | } else { | |
158 | a1 = 0.; b1 = 1.; c1 = XOrigin(); | |
159 | } | |
160 | ||
161 | if ( angle2 != 0. ) { | |
c6541a0c | 162 | angle2 += M_PI / 2.; |
7fd59977 | 163 | a2 = -Sin (angle2); |
164 | b2 = Cos (angle2); | |
165 | c2 = XOrigin() * b2 - YOrigin() * a2; | |
166 | } else { | |
167 | a2 = -1.; b2 = 0.; c2 = YOrigin(); | |
168 | } | |
169 | #else | |
170 | a1 = -Sin (myFirstAngle + RotationAngle()); | |
171 | b1 = Cos (myFirstAngle + RotationAngle()); | |
172 | c1 = XOrigin() * b1 - YOrigin() * a1; | |
173 | ||
c6541a0c D |
174 | a2 = -Sin (mySecondAngle + RotationAngle() + M_PI / 2.); |
175 | b2 = Cos (mySecondAngle + RotationAngle() + M_PI / 2.); | |
7fd59977 | 176 | c2 = XOrigin() * b2 - YOrigin() * a2; |
177 | #endif | |
178 | //-zov | |
179 | } | |
180 | ||
181 | Standard_Boolean Aspect_RectangularGrid::CheckAngle(const Standard_Real alpha, | |
182 | const Standard_Real beta) const { | |
c6541a0c | 183 | return (Abs( Sin(alpha) * Cos(beta + M_PI / 2.) - Cos(alpha) * Sin(beta + M_PI / 2.)) != 0) ; |
7fd59977 | 184 | } |
185 | ||
186 |