0023634: Eliminate Polyline and Polygon usage in drawers
[occt.git] / src / V3d / V3d_View_4.cxx
CommitLineData
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/***********************************************************************
19
20 FONCTION :
21 ----------
22 Classe V3d_View :
23
24 HISTORIQUE DES MODIFICATIONS :
25 --------------------------------
26 16-08-98 : CAL ; S3892. Ajout grilles 3d.
27 16-09-98 : BGN ; Points d'entree du Triedre (S3819, Phase 1)
28 21-09-98 : CAL ; Activation de l'echo que si CSF_GraphicEcho est definie.
29 22-09-98 : BGN ; S3989 (anciennement S3819)
30 TypeOfTriedron* from Aspect (pas V3d)
31 02.15.100 : JR : Clutter
32 28/05/02 : VSV: ZBUFFER mode of Trihedron
33
34************************************************************************/
35
36#define IMP240100 //GG
37// -> In Compute() method call MyViewer->ShowGridEcho()
38
39
40/*----------------------------------------------------------------------*/
41/*
42 * Includes
43 */
44#include <V3d_View.jxx>
45
46#include <TColStd_Array2OfReal.hxx>
47
48#include <gp_Dir2d.hxx>
49
50#include <Aspect.hxx>
51
52#include <V3d_RectangularGrid.hxx>
53#include <V3d_CircularGrid.hxx>
54
81bba717 55// For the echo of the chosen point
7fd59977 56#include <Visual3d_TransientManager.hxx>
57
58/*----------------------------------------------------------------------*/
59/*
60 * Constant
61 */
62
81bba717 63#define MYEPSILON1 0.0001 // Comparison with 0.0
c6541a0c 64#define MYEPSILON2 M_PI / 180. // Delta between 2 angles
7fd59977 65
7fd59977 66/*----------------------------------------------------------------------*/
67
b8ddfc2f 68void V3d_View::SetGrid (const gp_Ax3& aPlane, const Handle(Aspect_Grid)& aGrid)
69{
7fd59977 70 MyPlane = aPlane;
71 MyGrid = aGrid;
72
b8ddfc2f 73 Standard_Real xl, yl, zl;
74 Standard_Real xdx, xdy, xdz;
75 Standard_Real ydx, ydy, ydz;
76 Standard_Real dx, dy, dz;
7fd59977 77 aPlane.Location ().Coord (xl, yl, zl);
78 aPlane.XDirection ().Coord (xdx, xdy, xdz);
79 aPlane.YDirection ().Coord (ydx, ydy, ydz);
80 aPlane.Direction ().Coord (dx, dy, dz);
81
b8ddfc2f 82 Standard_Real CosAlpha = Cos (MyGrid->RotationAngle ());
83 Standard_Real SinAlpha = Sin (MyGrid->RotationAngle ());
7fd59977 84
b8ddfc2f 85 TColStd_Array2OfReal Trsf1 (1, 4, 1, 4);
7fd59977 86 Trsf1 (4, 4) = 1.0;
87 Trsf1 (4, 1) = Trsf1 (4, 2) = Trsf1 (4, 3) = 0.0;
88 // Translation
89 Trsf1 (1, 4) = xl,
90 Trsf1 (2, 4) = yl,
91 Trsf1 (3, 4) = zl;
81bba717 92 // Transformation change of marker
7fd59977 93 Trsf1 (1, 1) = xdx,
94 Trsf1 (2, 1) = xdy,
95 Trsf1 (3, 1) = xdz,
96 Trsf1 (1, 2) = ydx,
97 Trsf1 (2, 2) = ydy,
98 Trsf1 (3, 2) = ydz,
99 Trsf1 (1, 3) = dx,
100 Trsf1 (2, 3) = dy,
101 Trsf1 (3, 3) = dz;
102
b8ddfc2f 103 TColStd_Array2OfReal Trsf2 (1, 4, 1, 4);
7fd59977 104 Trsf2 (4, 4) = 1.0;
105 Trsf2 (4, 1) = Trsf2 (4, 2) = Trsf2 (4, 3) = 0.0;
81bba717 106 // Translation of the origin
7fd59977 107 Trsf2 (1, 4) = -MyGrid->XOrigin (),
108 Trsf2 (2, 4) = -MyGrid->YOrigin (),
109 Trsf2 (3, 4) = 0.0;
81bba717 110 // Rotation Alpha around axis -Z
7fd59977 111 Trsf2 (1, 1) = CosAlpha,
112 Trsf2 (2, 1) = -SinAlpha,
113 Trsf2 (3, 1) = 0.0,
114 Trsf2 (1, 2) = SinAlpha,
115 Trsf2 (2, 2) = CosAlpha,
116 Trsf2 (3, 2) = 0.0,
117 Trsf2 (1, 3) = 0.0,
118 Trsf2 (2, 3) = 0.0,
119 Trsf2 (3, 3) = 1.0;
120
b8ddfc2f 121 Standard_Real valuetrsf;
122 Standard_Real valueoldtrsf;
123 Standard_Real valuenewtrsf;
124 Standard_Integer i, j, k;
81bba717 125 // Calculation of the product of matrices
7fd59977 126 for (i=1; i<=4; i++)
127 for (j=1; j<=4; j++) {
128 MyTrsf (i, j) = 0.0;
129 for (k=1; k<=4; k++) {
130 valueoldtrsf = Trsf1 (i, k);
131 valuetrsf = Trsf2 (k, j);
132 valuenewtrsf = MyTrsf (i, j) + valueoldtrsf * valuetrsf;
133 MyTrsf (i, j) = valuenewtrsf;
134 }
135 }
7fd59977 136}
137
b8ddfc2f 138void V3d_View::SetGridActivity (const Standard_Boolean AFlag)
139{
7fd59977 140 if (AFlag) MyGrid->Activate ();
141 else MyGrid->Deactivate ();
7fd59977 142}
143
b8ddfc2f 144void V3d_View::SetGridGraphicValues (const Handle(Aspect_Grid)& )
145{
7fd59977 146}
147
b8ddfc2f 148Graphic3d_Vertex V3d_View::Compute (const Graphic3d_Vertex & AVertex) const
149{
150 Graphic3d_Vertex CurPoint, NewPoint;
151 Standard_Real X1, Y1, Z1, X2, Y2, Z2;
152 Standard_Real XPp, YPp;
7fd59977 153
154 MyView->ViewOrientation ().ViewReferencePlane ().Coord (X1, Y1, Z1);
155 MyPlane.Direction ().Coord (X2, Y2, Z2);
156
b8ddfc2f 157 gp_Dir VPN (X1, Y1, Z1);
158 gp_Dir GPN (X2, Y2, Z2);
7fd59977 159
160 AVertex.Coord (X1, Y1, Z1);
161 Project (X1, Y1, Z1, XPp, YPp);
162
81bba717 163 // Casw when the plane of the grid and the plane of the view
164 // are perpendicular to MYEPSILON2 close radians
c6541a0c 165 if (Abs (VPN.Angle (GPN) - M_PI / 2.) < MYEPSILON2) {
7fd59977 166 NewPoint.SetCoord (X1, Y1, Z1);
7fd59977 167#ifdef IMP240100
168 MyViewer->ShowGridEcho(this,NewPoint);
7fd59977 169#endif //IMP240100
170 return NewPoint;
171 }
172
b8ddfc2f 173 Standard_Boolean IsRectangular =
7fd59977 174 MyGrid->IsKind (STANDARD_TYPE (Aspect_RectangularGrid));
175
b8ddfc2f 176 Graphic3d_Vertex P1;
7fd59977 177
b8ddfc2f 178 Standard_Real XO = 0.0, YO = 0.0;
179 Standard_Real XOp, YOp;
180 Standard_Real XAp, YAp;
181 Standard_Real XBp, YBp;
7fd59977 182
183 X1 = XO, Y1 = YO, Z1 = 0.0;
81bba717 184 // MyTrsf * Point to return to the plane of 3D grid
7fd59977 185 P1.SetCoord (X1, Y1, Z1);
186 CurPoint = V3d_View::TrsPoint (P1, MyTrsf);
187 CurPoint.Coord (X2, Y2, Z2);
188 Project (X2, Y2, Z2, XOp, YOp);
189 XPp = XPp - XOp, YPp = YPp - YOp;
190
b8ddfc2f 191 if (IsRectangular) {
192 Standard_Real XS, YS;
193 Handle(Aspect_RectangularGrid) theGrid =
7fd59977 194 *(Handle(Aspect_RectangularGrid) *) &MyGrid;
195 XS = theGrid->XStep (), YS = theGrid->YStep ();
196
197 X1 = XO + XS, Y1 = YO, Z1 = 0.0;
81bba717 198 // MyTrsf * Point to return to the plane of 3D grid
7fd59977 199 P1.SetCoord (X1, Y1, Z1);
200 CurPoint = V3d_View::TrsPoint (P1, MyTrsf);
201 CurPoint.Coord (X2, Y2, Z2);
202 Project (X2, Y2, Z2, XAp, YAp);
203 XAp = XAp - XOp, YAp = YAp - YOp;
204
7fd59977 205 X1 = XO, Y1 = YO + YS, Z1 = 0.0;
81bba717 206 // MyTrsf * Point to return to the plane of 3D grid
7fd59977 207 P1.SetCoord (X1, Y1, Z1);
208 CurPoint = V3d_View::TrsPoint (P1, MyTrsf);
209 CurPoint.Coord (X2, Y2, Z2);
210 Project (X2, Y2, Z2, XBp, YBp);
211 XBp = XBp - XOp, YBp = YBp - YOp;
212
b8ddfc2f 213 Standard_Real Determin = XAp*YBp - XBp*YAp;
7fd59977 214
215 Z1 = 0.0;
216 if (Abs (Determin) > MYEPSILON1) {
217 X1 = (YBp*XPp - XBp*YPp) / Determin;
218 Y1 = (XAp*YPp - YAp*XPp) / Determin;
219 X1 = (X1 > 0. ?
220 Standard_Real (Standard_Integer (Abs (X1)+0.5)) * XS :
221 - Standard_Real (Standard_Integer (Abs (X1)+0.5)) * XS);
222 Y1 = (Y1 > 0. ?
223 Standard_Real (Standard_Integer (Abs (Y1)+0.5)) * YS :
224 - Standard_Real (Standard_Integer (Abs (Y1)+0.5)) * YS);
81bba717 225 // MyTrsf * Point to return to the plane of 3D grid
7fd59977 226 P1.SetCoord (X1, Y1, Z1);
227 CurPoint = V3d_View::TrsPoint (P1, MyTrsf);
228 CurPoint.Coord (X2, Y2, Z2);
229 }
230 else {
b8ddfc2f 231 //cout << "*****************" << endl;
232 //cout << "Zero Determinant!" << endl;
233 //cout << "*****************" << endl;
7fd59977 234 AVertex.Coord (X2, Y2, Z2);
235 CurPoint.SetCoord (X2, Y2, Z2);
236 }
237 } // IsRectangular
b8ddfc2f 238 else {
239 Standard_Real RS;
240 Standard_Integer DN;
241 Standard_Real Alpha;
242 Handle(Aspect_CircularGrid) theGrid =
7fd59977 243 *(Handle(Aspect_CircularGrid) *) &MyGrid;
244 RS = theGrid->RadiusStep ();
245 DN = theGrid->DivisionNumber ();
c6541a0c 246 Alpha = M_PI / Standard_Real (DN);
7fd59977 247
b8ddfc2f 248 Standard_Real DistOP = Sqrt (XPp*XPp + YPp*YPp);
7fd59977 249
b8ddfc2f 250 Standard_Integer i, ICur=0;
251 Standard_Real Angle, AngleCur;
252 Standard_Real XCurp=0, YCurp=0;
253 gp_Dir2d OP (XPp, YPp);
c6541a0c 254 AngleCur = 2 * M_PI;
7fd59977 255 for (i=1; i<=DN*2; i++) {
256 X1 = XO + Cos (Alpha * i) * RS,
257 Y1 = YO + Sin (Alpha * i) * RS,
258 Z1 = 0.0;
81bba717 259 // MyTrsf * Point to return to the plane of 3D grid
7fd59977 260 P1.SetCoord (X1, Y1, Z1);
261 CurPoint = V3d_View::TrsPoint (P1, MyTrsf);
262 CurPoint.Coord (X2, Y2, Z2);
263 Project (X2, Y2, Z2, XAp, YAp);
264 XAp = XAp - XOp, YAp = YAp - YOp;
265 gp_Dir2d OA (XAp, YAp);
266 Angle = OP.Angle (OA);
267 if (Abs (AngleCur) > Abs (Angle)) {
268 ICur = i;
269 AngleCur = Angle;
270 XCurp = XAp, YCurp = YAp;
7fd59977 271 }
272
7fd59977 273 } // for (i=1; i<=DN*2; i++)
274
b8ddfc2f 275 Standard_Real DistOCur = Sqrt (XCurp*XCurp + YCurp*YCurp);
7fd59977 276
81bba717 277 // Determination of the circle of the grid closest to P
b8ddfc2f 278 Standard_Integer N = Standard_Integer (DistOP / DistOCur + 0.5);
279 Standard_Real Radius = N * RS;
7fd59977 280
281 X1 = Cos (Alpha * ICur) * Radius,
282 Y1 = Sin (Alpha * ICur) * Radius,
283 Z1 = 0.0;
284
81bba717 285 // MyTrsf * Point to return to the plane of 3D grid
7fd59977 286 P1.SetCoord (X1, Y1, Z1);
287 CurPoint = V3d_View::TrsPoint (P1, MyTrsf);
288 CurPoint.Coord (X2, Y2, Z2);
289 } // IsCircular
290
291 NewPoint.SetCoord (CurPoint.X (), CurPoint.Y (), CurPoint.Z ());
292
7fd59977 293#ifdef IMP240100
294 MyViewer->ShowGridEcho(this,NewPoint);
7fd59977 295#endif //IMP240100
296 return NewPoint;
297}
298
299// Triedron methods : the Triedron is a non-zoomable object.
300
301void V3d_View::ZBufferTriedronSetup(const Quantity_NameOfColor XColor,
302 const Quantity_NameOfColor YColor,
303 const Quantity_NameOfColor ZColor,
304 const Standard_Real SizeRatio,
305 const Standard_Real AxisDiametr,
306 const Standard_Integer NbFacettes)
307{
308 MyView->ZBufferTriedronSetup(XColor, YColor, ZColor, SizeRatio, AxisDiametr, NbFacettes);
309}
310
311void V3d_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition APosition,
b8ddfc2f 312 const Quantity_NameOfColor AColor, const Standard_Real AScale, const V3d_TypeOfVisualization AMode )
313{
7fd59977 314 MyView->TriedronDisplay (APosition, AColor, AScale, (AMode == V3d_WIREFRAME));
315}
316
b8ddfc2f 317void V3d_View::TriedronErase ( )
318{
7fd59977 319 MyView->TriedronErase ( );
320}
321
b8ddfc2f 322void V3d_View::TriedronEcho (const Aspect_TypeOfTriedronEcho AType )
323{
7fd59977 324 MyView->TriedronEcho (AType);
325}
326
327void V3d_View::GetGraduatedTrihedron(/* Names of axes */
13a22457
S
328 TCollection_ExtendedString &xname,
329 TCollection_ExtendedString &yname,
330 TCollection_ExtendedString &zname,
7fd59977 331 /* Draw names */
332 Standard_Boolean& xdrawname,
333 Standard_Boolean& ydrawname,
334 Standard_Boolean& zdrawname,
335 /* Draw values */
336 Standard_Boolean& xdrawvalues,
337 Standard_Boolean& ydrawvalues,
338 Standard_Boolean& zdrawvalues,
339 /* Draw grid */
340 Standard_Boolean& drawgrid,
341 /* Draw axes */
342 Standard_Boolean& drawaxes,
343 /* Number of splits along axes */
344 Standard_Integer& nbx,
345 Standard_Integer& nby,
346 Standard_Integer& nbz,
347 /* Offset for drawing values */
348 Standard_Integer& xoffset,
349 Standard_Integer& yoffset,
350 Standard_Integer& zoffset,
351 /* Offset for drawing names of axes */
352 Standard_Integer& xaxisoffset,
353 Standard_Integer& yaxisoffset,
354 Standard_Integer& zaxisoffset,
355 /* Draw tickmarks */
356 Standard_Boolean& xdrawtickmarks,
357 Standard_Boolean& ydrawtickmarks,
358 Standard_Boolean& zdrawtickmarks,
359 /* Length of tickmarks */
360 Standard_Integer& xtickmarklength,
361 Standard_Integer& ytickmarklength,
362 Standard_Integer& ztickmarklength,
363 /* Grid color */
364 Quantity_Color& gridcolor,
365 /* X name color */
366 Quantity_Color& xnamecolor,
367 /* Y name color */
368 Quantity_Color& ynamecolor,
369 /* Z name color */
370 Quantity_Color& znamecolor,
371 /* X color of axis and values */
372 Quantity_Color& xcolor,
373 /* Y color of axis and values */
374 Quantity_Color& ycolor,
375 /* Z color of axis and values */
376 Quantity_Color& zcolor,
377 /* Name of font for names of axes */
13a22457 378 TCollection_AsciiString &fontOfNames,
7fd59977 379 /* Style of names of axes */
eeaaaefb 380 Font_FontAspect& styleOfNames,
7fd59977 381 /* Size of names of axes */
382 Standard_Integer& sizeOfNames,
383 /* Name of font for values */
13a22457 384 TCollection_AsciiString &fontOfValues,
7fd59977 385 /* Style of values */
eeaaaefb 386 Font_FontAspect& styleOfValues,
7fd59977 387 /* Size of values */
388 Standard_Integer& sizeOfValues) const
389{
390 MyView->GetGraduatedTrihedron(/* Names of axes */
391 xname,
392 yname,
393 zname,
394 /* Draw names */
395 xdrawname,
396 ydrawname,
397 zdrawname,
398 /* Draw values */
399 xdrawvalues,
400 ydrawvalues,
401 zdrawvalues,
402 /* Draw grid */
403 drawgrid,
404 /* Draw axes */
405 drawaxes,
406 /* Number of splits along axes */
407 nbx,
408 nby,
409 nbz,
410 /* Offset for drawing values */
411 xoffset,
412 yoffset,
413 zoffset,
414 /* Offset for drawing names of axes */
415 xaxisoffset,
416 yaxisoffset,
417 zaxisoffset,
418 /* Draw tickmarks */
419 xdrawtickmarks,
420 ydrawtickmarks,
421 zdrawtickmarks,
422 /* Length of tickmarks */
423 xtickmarklength,
424 ytickmarklength,
425 ztickmarklength,
426 /* Grid color */
427 gridcolor,
428 /* X name color */
429 xnamecolor,
430 /* Y name color */
431 ynamecolor,
432 /* Z name color */
433 znamecolor,
434 /* X color of axis and values */
435 xcolor,
436 /* Y color of axis and values */
437 ycolor,
438 /* Z color of axis and values */
439 zcolor,
440 /* Name of font for names of axes */
441 fontOfNames,
442 /* Style of names of axes */
443 styleOfNames,
444 /* Size of names of axes */
445 sizeOfNames,
446 /* Name of font for values */
447 fontOfValues,
448 /* Style of values */
449 styleOfValues,
450 /* Size of values */
451 sizeOfValues);
452}
453
454void V3d_View::GraduatedTrihedronDisplay(/* Names of axes */
13a22457
S
455 const TCollection_ExtendedString &xname,
456 const TCollection_ExtendedString &yname,
457 const TCollection_ExtendedString &zname,
7fd59977 458 /* Draw names */
459 const Standard_Boolean xdrawname,
460 const Standard_Boolean ydrawname,
461 const Standard_Boolean zdrawname,
462 /* Draw values */
463 const Standard_Boolean xdrawvalues,
464 const Standard_Boolean ydrawvalues,
465 const Standard_Boolean zdrawvalues,
466 /* Draw grid */
467 const Standard_Boolean drawgrid,
468 /* Draw axes */
469 const Standard_Boolean drawaxes,
470 /* Number of splits along axes */
471 const Standard_Integer nbx,
472 const Standard_Integer nby,
473 const Standard_Integer nbz,
474 /* Offset for drawing values */
475 const Standard_Integer xoffset,
476 const Standard_Integer yoffset,
477 const Standard_Integer zoffset,
478 /* Offset for drawing names of axes */
479 const Standard_Integer xaxisoffset,
480 const Standard_Integer yaxisoffset,
481 const Standard_Integer zaxisoffset,
482 /* Draw tickmarks */
483 const Standard_Boolean xdrawtickmarks,
484 const Standard_Boolean ydrawtickmarks,
485 const Standard_Boolean zdrawtickmarks,
486 /* Length of tickmarks */
487 const Standard_Integer xtickmarklength,
488 const Standard_Integer ytickmarklength,
489 const Standard_Integer ztickmarklength,
490 /* Grid color */
491 const Quantity_Color& gridcolor,
492 /* X name color */
493 const Quantity_Color& xnamecolor,
494 /* Y name color */
495 const Quantity_Color& ynamecolor,
496 /* Z name color */
497 const Quantity_Color& znamecolor,
498 /* X color of axis and values */
499 const Quantity_Color& xcolor,
500 /* Y color of axis and values */
501 const Quantity_Color& ycolor,
502 /* Z color of axis and values */
503 const Quantity_Color& zcolor,
504 /* Name of font for names of axes */
13a22457 505 const TCollection_AsciiString &fontOfNames,
7fd59977 506 /* Style of names of axes */
eeaaaefb 507 const Font_FontAspect styleOfNames,
7fd59977 508 /* Size of names of axes */
509 const Standard_Integer sizeOfNames,
510 /* Name of font for values */
13a22457 511 const TCollection_AsciiString &fontOfValues,
7fd59977 512 /* Style of values */
eeaaaefb 513 const Font_FontAspect styleOfValues,
7fd59977 514 /* Size of values */
515 const Standard_Integer sizeOfValues)
516{
517 MyView->GraduatedTrihedronDisplay(/* Names of axes */
518 xname,
519 yname,
520 zname,
521 /* Draw names */
522 xdrawname,
523 ydrawname,
524 zdrawname,
525 /* Draw values */
526 xdrawvalues,
527 ydrawvalues,
528 zdrawvalues,
529 /* Draw grid */
530 drawgrid,
531 /* Draw axes */
532 drawaxes,
533 /* Number of splits along axes */
534 nbx,
535 nby,
536 nbz,
537 /* Offset for drawing values */
538 xoffset,
539 yoffset,
540 zoffset,
541 /* Offset for drawing names of axes */
542 xaxisoffset,
543 yaxisoffset,
544 zaxisoffset,
545 /* Draw tickmarks */
546 xdrawtickmarks,
547 ydrawtickmarks,
548 zdrawtickmarks,
549 /* Length of tickmarks */
550 xtickmarklength,
551 ytickmarklength,
552 ztickmarklength,
553 /* Grid color */
554 gridcolor,
555 /* X name color */
556 xnamecolor,
557 /* Y name color */
558 ynamecolor,
559 /* Z name color */
560 znamecolor,
561 /* X color of axis and values */
562 xcolor,
563 /* Y color of axis and values */
564 ycolor,
565 /* Z color of axis and values */
566 zcolor,
567 /* Name of font for names of axes */
568 fontOfNames,
569 /* Style of names of axes */
570 styleOfNames,
571 /* Size of names of axes */
572 sizeOfNames,
573 /* Name of font for values */
574 fontOfValues,
575 /* Style of values */
576 styleOfValues,
577 /* Size of values */
578 sizeOfValues);
579}
580
581void V3d_View::GraduatedTrihedronErase()
582{
583 MyView->GraduatedTrihedronErase();
584}