7fd59977 |
1 | /*********************************************************************** |
2 | |
3 | FONCTION : |
4 | ---------- |
5 | Classe V3d_CircularGrid : |
6 | |
81bba717 |
7 | VERSION HISTORY : |
7fd59977 |
8 | -------------------------------- |
7fd59977 |
9 | IMP230300: GG The color fields and methods have moved in Aspect_Grid |
10 | |
11 | |
12 | ************************************************************************/ |
13 | |
14 | #define IMP200100 //GG |
15 | // -> Compute the case Aspect_GDM_None |
16 | // -> Initialize the grid size according to the |
17 | // viewer default size. |
18 | |
19 | #define IMP200300 //GG |
20 | // -> Recompute the grid when any graphic parameter is |
21 | // modified. |
22 | |
23 | #define IMP300300 //GG |
24 | // -> Draw circles with 2 colors (tenth and normal colors) |
25 | |
26 | /*----------------------------------------------------------------------*/ |
27 | /* |
28 | * Includes |
29 | */ |
30 | |
31 | #include <V3d_CircularGrid.ixx> |
32 | |
33 | #include <TColStd_Array2OfReal.hxx> |
34 | #include <Graphic3d_AspectLine3d.hxx> |
35 | #include <Graphic3d_AspectMarker3d.hxx> |
36 | #include <Graphic3d_Vertex.hxx> |
37 | #include <Graphic3d_Array1OfVertex.hxx> |
38 | #include <Visual3d_ViewManager.hxx> |
39 | #include <V3d_Viewer.hxx> |
40 | |
41 | /*----------------------------------------------------------------------*/ |
42 | /* |
43 | * Constant |
44 | */ |
45 | |
46 | #define NO_TRACE_MINMAX |
47 | #define NO_TRACE_MAKE |
48 | #define NO_TRACE_VALUES |
49 | |
50 | #define DIVISION 8 |
51 | #define MYMINMAX 25. |
52 | #define MYFACTOR 50. |
53 | |
54 | /*----------------------------------------------------------------------*/ |
55 | |
56 | V3d_CircularGrid::V3d_CircularGrid (const V3d_ViewerPointer& aViewer, const Quantity_Color& aColor, const Quantity_Color& aTenthColor): |
57 | Aspect_CircularGrid (1.,8), |
58 | myStructure (new Graphic3d_Structure (aViewer->Viewer ())), |
59 | myGroup1 (new Graphic3d_Group (myStructure)), |
60 | myGroup2 (new Graphic3d_Group (myStructure)), |
61 | // myColor (aColor), |
62 | // myTenthColor (aTenthColor), |
63 | myViewer (aViewer), |
64 | myCurAreDefined (Standard_False) |
65 | { |
66 | myColor = aColor; |
67 | myTenthColor = aTenthColor; |
68 | |
69 | myStructure->SetInfiniteState (Standard_True); |
70 | |
71 | Standard_Real step = 10.; |
72 | #ifdef IMP200100 |
73 | Standard_Real size = myViewer->DefaultViewSize()/2.; |
74 | SetGraphicValues (size, step/MYFACTOR); |
75 | #else |
76 | SetGraphicValues (25., step/MYFACTOR); |
77 | #endif |
78 | SetRadiusStep (step); |
79 | } |
80 | |
81 | void V3d_CircularGrid::SetColors (const Quantity_Color& aColor, const Quantity_Color& aTenthColor) { |
82 | if( myColor != aColor || myTenthColor != aTenthColor ) { |
83 | myColor = aColor; |
84 | myTenthColor = aTenthColor; |
85 | myCurAreDefined = Standard_False; |
86 | UpdateDisplay(); |
87 | } |
88 | } |
89 | |
90 | void V3d_CircularGrid::Display () { |
91 | myStructure->Display (1); |
92 | } |
93 | |
94 | void V3d_CircularGrid::Erase () const { |
95 | myStructure->Erase (); |
96 | } |
97 | |
98 | Standard_Boolean V3d_CircularGrid::IsDisplayed () const { |
99 | return myStructure->IsDisplayed (); |
100 | } |
101 | |
102 | void V3d_CircularGrid::UpdateDisplay () { |
103 | #ifdef TRACE_MINMAX |
104 | cout << "V3d_CircularGrid::UpdateDisplay ()\n"; |
105 | #endif |
106 | |
107 | gp_Ax3 ThePlane; |
108 | ThePlane = myViewer->PrivilegedPlane (); |
109 | |
110 | Standard_Boolean MakeTransform = Standard_False; |
111 | Standard_Real xl, yl, zl; |
112 | Standard_Real xdx, xdy, xdz; |
113 | Standard_Real ydx, ydy, ydz; |
114 | Standard_Real dx, dy, dz; |
115 | ThePlane.Location ().Coord (xl, yl, zl); |
116 | ThePlane.XDirection ().Coord (xdx, xdy, xdz); |
117 | ThePlane.YDirection ().Coord (ydx, ydy, ydz); |
118 | ThePlane.Direction ().Coord (dx, dy, dz); |
119 | if (! myCurAreDefined) |
120 | MakeTransform = Standard_True; |
121 | else { |
122 | if (RotationAngle () != myCurAngle |
123 | || XOrigin () != myCurXo || YOrigin () != myCurYo) |
124 | MakeTransform = Standard_True; |
125 | if (! MakeTransform) { |
126 | Standard_Real curxl, curyl, curzl; |
127 | Standard_Real curxdx, curxdy, curxdz; |
128 | Standard_Real curydx, curydy, curydz; |
129 | Standard_Real curdx, curdy, curdz; |
130 | myCurViewPlane.Location ().Coord (curxl, curyl, curzl); |
131 | myCurViewPlane.XDirection ().Coord (curxdx, curxdy, curxdz); |
132 | myCurViewPlane.YDirection ().Coord (curydx, curydy, curydz); |
133 | myCurViewPlane.Direction ().Coord (curdx, curdy, curdz); |
134 | if (xl != curxl || yl != curyl || zl != curzl |
135 | || xdx != curxdx || xdy != curxdy || xdz != curxdz |
136 | || ydx != curydx || ydy != curydy || ydz != curydz |
137 | || dx != curdx || dy != curdy || dz != curdz) |
138 | MakeTransform = Standard_True; |
139 | } |
140 | } |
141 | |
142 | if (MakeTransform) { |
143 | #ifdef TRACE_MAKE |
144 | cout << "MakeTransform" << endl; |
145 | #endif |
146 | Standard_Real CosAlpha = Cos (RotationAngle ()); |
147 | Standard_Real SinAlpha = Sin (RotationAngle ()); |
148 | TColStd_Array2OfReal Trsf (1, 4, 1, 4); |
149 | Trsf (4, 4) = 1.0; |
150 | Trsf (4, 1) = Trsf (4, 2) = Trsf (4, 3) = 0.0; |
151 | // Translation |
152 | Trsf (1, 4) = xl, |
153 | Trsf (2, 4) = yl, |
154 | Trsf (3, 4) = zl; |
81bba717 |
155 | // Transformation change of marker |
7fd59977 |
156 | Trsf (1, 1) = xdx, |
157 | Trsf (2, 1) = xdy, |
158 | Trsf (3, 1) = xdz, |
159 | Trsf (1, 2) = ydx, |
160 | Trsf (2, 2) = ydy, |
161 | Trsf (3, 2) = ydz, |
162 | Trsf (1, 3) = dx, |
163 | Trsf (2, 3) = dy, |
164 | Trsf (3, 3) = dz; |
165 | myStructure->SetTransform (Trsf, Graphic3d_TOC_REPLACE); |
166 | |
81bba717 |
167 | // Translation of the origin |
7fd59977 |
168 | Trsf (1, 4) = -XOrigin (), |
169 | Trsf (2, 4) = -YOrigin (), |
170 | Trsf (3, 4) = 0.0; |
81bba717 |
171 | // Rotation Alpha around axis -Z |
7fd59977 |
172 | Trsf (1, 1) = CosAlpha, |
173 | Trsf (2, 1) = -SinAlpha, |
174 | Trsf (3, 1) = 0.0, |
175 | Trsf (1, 2) = SinAlpha, |
176 | Trsf (2, 2) = CosAlpha, |
177 | Trsf (3, 2) = 0.0, |
178 | Trsf (1, 3) = 0.0, |
179 | Trsf (2, 3) = 0.0, |
180 | Trsf (3, 3) = 1.0; |
181 | myStructure->SetTransform (Trsf,Graphic3d_TOC_POSTCONCATENATE); |
182 | |
7fd59977 |
183 | |
184 | #ifdef TRACE_VALUES |
185 | Standard_Integer i, j; |
186 | TColStd_Array2OfReal TheMatrix (1, 4, 1, 4); |
187 | myStructure->Transform (TheMatrix); |
188 | |
189 | for (i=1; i<=4; i++) { |
190 | for (j=1; j<=4; j++) |
191 | cout << TheMatrix (i, j) << "\t"; |
192 | cout << endl; |
193 | } |
194 | #endif |
195 | |
196 | myCurAngle = RotationAngle (); |
197 | myCurXo = XOrigin (), myCurYo = YOrigin (); |
198 | myCurViewPlane = ThePlane; |
199 | } |
200 | |
201 | switch (DrawMode ()) { |
202 | default: |
203 | case Aspect_GDM_Points: |
204 | if (! myCurAreDefined || myCurAreDefined && |
205 | myCurDrawMode == Aspect_GDM_Lines) |
206 | myGroup2->Clear (); |
207 | DefinePoints (); |
208 | myCurDrawMode = Aspect_GDM_Points; |
209 | break; |
210 | case Aspect_GDM_Lines: |
211 | DefineLines (); |
212 | myCurDrawMode = Aspect_GDM_Lines; |
213 | break; |
214 | #ifdef IMP210100 |
215 | case Aspect_GDM_None: |
216 | myCurDrawMode = Aspect_GDM_None; |
217 | break; |
218 | #endif |
219 | } |
220 | myCurAreDefined = Standard_True; |
221 | |
222 | #ifdef TRACE_VALUES |
223 | Standard_Real a11, a12, a13, a21, a22, a23, a31, a32, a33; |
224 | ThePlane.XDirection ().Coord (a11, a12, a13); |
225 | ThePlane.YDirection ().Coord (a21, a22, a23); |
226 | ThePlane.Direction ().Coord (a31, a32, a33); |
227 | cout << "Test Plane XDirection " << a11 << ", " << a12 << ", " << a13 << endl; |
228 | cout << "Test Plane YDirection " << a21 << ", " << a22 << ", " << a23 << endl; |
229 | cout << "Test Plane Direction " << a31 << ", " << a32 << ", " << a33 << endl; |
230 | #endif |
231 | } |
232 | |
233 | void V3d_CircularGrid::DefineLines () { |
234 | |
235 | Handle(Graphic3d_AspectLine3d) LineAttrib = new Graphic3d_AspectLine3d (); |
236 | LineAttrib->SetColor (myColor); |
237 | LineAttrib->SetType (Aspect_TOL_SOLID); |
238 | LineAttrib->SetWidth (1.0); |
239 | |
240 | Standard_Real r; |
241 | Standard_Real aStep = RadiusStep (); |
242 | Standard_Real aDivision = DivisionNumber (); |
c6541a0c |
243 | Standard_Real alpha = M_PI / aDivision; |
7fd59977 |
244 | |
245 | Standard_Integer Division = (Standard_Integer )( (aDivision >= DIVISION ? aDivision : DIVISION)); |
246 | Graphic3d_Array1OfVertex Cercle (0, 2*Division); |
247 | Standard_Real xl, yl, zl = myOffSet; |
248 | |
249 | Standard_Integer i; |
250 | |
251 | Graphic3d_Vertex P1, P2; |
252 | |
253 | Standard_Boolean MakeDiametres = Standard_False; |
254 | if (! myCurAreDefined || myCurDrawMode == Aspect_GDM_Points) |
255 | MakeDiametres = Standard_True; |
256 | else { |
257 | if (aDivision != myCurDivi) |
258 | MakeDiametres = Standard_True; |
259 | } |
260 | |
261 | if (MakeDiametres) { |
262 | #ifdef TRACE_MAKE |
263 | cout << "MakeDiametres" << endl; |
264 | #endif |
265 | // diametres |
266 | myGroup1->Clear (); |
267 | #ifdef IMP300300 |
268 | LineAttrib->SetColor (myTenthColor); |
269 | #endif |
270 | myGroup1->SetGroupPrimitivesAspect (LineAttrib); |
271 | myGroup1->BeginPrimitives (); |
272 | P1.SetCoord (0.0, 0.0, -zl); |
273 | for (i=1; i<=2*aDivision; i++) { |
274 | xl = Cos (alpha*i)*myRadius; |
275 | yl = Sin (alpha*i)*myRadius; |
276 | P2.SetCoord (xl, yl, -zl); |
277 | myGroup1->Polyline (P1, P2, Standard_False); |
278 | } |
279 | myGroup1->EndPrimitives (); |
280 | myGroup1->SetMinMaxValues |
281 | (-myRadius, -myRadius, 0.0, myRadius, myRadius, 0.0); |
282 | } |
283 | |
284 | Standard_Boolean MakeCercles = Standard_False; |
285 | if (! myCurAreDefined || myCurDrawMode == Aspect_GDM_Points) |
286 | MakeCercles = Standard_True; |
287 | else { |
288 | if (aStep != myCurStep || aDivision != myCurDivi) |
289 | MakeCercles = Standard_True; |
290 | } |
291 | |
292 | if (MakeCercles) { |
293 | #ifdef TRACE_MAKE |
294 | cout << "MakeCercles" << endl; |
295 | #endif |
81bba717 |
296 | // circles |
7fd59977 |
297 | #ifdef IMP300300 |
298 | Standard_Integer nblines = 0; |
299 | #endif |
300 | myGroup2->Clear (); |
301 | #ifndef IMP300300 |
302 | myGroup2->SetGroupPrimitivesAspect (LineAttrib); |
303 | #endif |
304 | myGroup2->BeginPrimitives (); |
c6541a0c |
305 | alpha = M_PI / Division; |
7fd59977 |
306 | for (r=aStep; r<=myRadius; r+=aStep) { |
307 | for (i=0; i<=2*Division; i++) { |
308 | xl = Cos (alpha*i)*r; |
309 | yl = Sin (alpha*i)*r; |
310 | Cercle (i).SetCoord (xl, yl, -zl); |
311 | } |
312 | #ifdef IMP300300 |
313 | if (Modulus (nblines, 10) != 0) { |
314 | myGroup2->Polyline (Cercle, Standard_False); |
315 | } else { |
316 | LineAttrib->SetColor (myTenthColor); |
317 | myGroup2->SetPrimitivesAspect (LineAttrib); |
318 | myGroup2->Polyline (Cercle, Standard_False); |
319 | LineAttrib->SetColor (myColor); |
320 | myGroup2->SetPrimitivesAspect (LineAttrib); |
321 | } |
322 | nblines++; |
323 | #else |
324 | myGroup2->Polyline (Cercle, Standard_False); |
325 | #endif |
326 | } |
327 | myGroup2->EndPrimitives (); |
328 | myGroup2->SetMinMaxValues |
329 | (-myRadius, -myRadius, 0.0, myRadius, myRadius, 0.0); |
330 | } |
331 | myCurStep = aStep, myCurDivi = (Standard_Integer ) aDivision; |
332 | } |
333 | |
334 | void V3d_CircularGrid::DefinePoints () { |
335 | |
336 | Handle(Graphic3d_AspectMarker3d) MarkerAttrib = new Graphic3d_AspectMarker3d (); |
337 | MarkerAttrib->SetColor (myColor); |
338 | MarkerAttrib->SetType (Aspect_TOM_POINT); |
339 | MarkerAttrib->SetScale (3.); |
340 | |
341 | Standard_Real r; |
342 | Standard_Real aStep = RadiusStep (); |
343 | Standard_Real aDivision = DivisionNumber (); |
c6541a0c |
344 | Standard_Real alpha = M_PI / aDivision; |
7fd59977 |
345 | |
346 | Graphic3d_Array1OfVertex Cercle (0,(Standard_Integer )(2*aDivision)); |
347 | Standard_Real xl, yl, zl = myOffSet; |
348 | |
349 | Standard_Integer i; |
350 | |
351 | Graphic3d_Vertex Point (0.0, 0.0, -zl); |
352 | |
353 | Standard_Boolean MakeDiametres = Standard_False; |
354 | if (! myCurAreDefined || myCurDrawMode == Aspect_GDM_Lines) |
355 | MakeDiametres = Standard_True; |
356 | else { |
357 | if (aDivision != myCurDivi || aStep != myCurStep) |
358 | MakeDiametres = Standard_True; |
359 | } |
360 | |
361 | if (MakeDiametres) { |
362 | #ifdef TRACE_MAKE |
363 | cout << "MakeDiametres" << endl; |
364 | #endif |
81bba717 |
365 | // diameters |
7fd59977 |
366 | myGroup1->Clear (); |
367 | myGroup1->SetGroupPrimitivesAspect (MarkerAttrib); |
368 | myGroup1->BeginPrimitives (); |
369 | myGroup1->Marker (Point, Standard_False); |
370 | for (r=aStep; r<=myRadius; r+=aStep) { |
371 | for (i=0; i<=2*aDivision; i++) { |
372 | xl = Cos (alpha*i)*r; |
373 | yl = Sin (alpha*i)*r; |
374 | Cercle (i).SetCoord (xl, yl, -zl); |
375 | } |
376 | myGroup1->MarkerSet (Cercle, Standard_False); |
377 | } |
378 | myGroup1->EndPrimitives (); |
379 | myGroup1->SetMinMaxValues |
380 | (-myRadius, -myRadius, 0.0, myRadius, myRadius, 0.0); |
381 | } |
382 | myCurStep = aStep, myCurDivi = (Standard_Integer ) aDivision; |
383 | } |
384 | |
385 | void V3d_CircularGrid::GraphicValues (Standard_Real& theRadius, Standard_Real& theOffSet) const { |
386 | |
387 | theRadius = myRadius; |
388 | theOffSet = myOffSet; |
389 | } |
390 | |
391 | void V3d_CircularGrid::SetGraphicValues (const Standard_Real theRadius, const Standard_Real theOffSet) { |
392 | |
393 | #ifdef TRACE_MINMAX |
394 | cout << "theRadius " << theRadius << " theOffSet " << theOffSet << endl; |
395 | #endif |
396 | if (! myCurAreDefined) { |
397 | myRadius = theRadius; |
398 | myOffSet = theOffSet; |
399 | } |
400 | if (myRadius != theRadius) { |
401 | myRadius = theRadius; |
402 | myCurAreDefined = Standard_False; |
403 | } |
404 | if (myOffSet != theOffSet) { |
405 | myOffSet = theOffSet; |
406 | myCurAreDefined = Standard_False; |
407 | } |
408 | #ifdef IMP200300 |
409 | if( !myCurAreDefined ) UpdateDisplay(); |
410 | #endif |
411 | } |