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 /***********************************************************************
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
34 ************************************************************************/
36 #define IMP240100 //GG
37 // -> In Compute() method call MyViewer->ShowGridEcho()
40 /*----------------------------------------------------------------------*/
44 #include <V3d_View.jxx>
46 #include <TColStd_Array2OfReal.hxx>
48 #include <gp_Dir2d.hxx>
52 #include <V3d_RectangularGrid.hxx>
53 #include <V3d_CircularGrid.hxx>
55 // For the echo of the chosen point
56 #include <Visual3d_TransientManager.hxx>
58 /*----------------------------------------------------------------------*/
63 // in case NO_TRACE_ECHO and NO_TRACE_POINTS, in V3d_View_4.cxx and
64 // V3d_View.cxx, suspend MyGridEchoStructure and MyGridEchoGroup in cdl
66 #define NO_TRACE_VALUES
67 #define NO_TRACE_POINTS
69 #define MYEPSILON1 0.0001 // Comparison with 0.0
70 #define MYEPSILON2 M_PI / 180. // Delta between 2 angles
73 #include <Graphic3d_AspectLine3d.hxx>
74 #include <Graphic3d_AspectText3d.hxx>
78 #include <Visual3d_ViewOrientation.hxx>
81 #if defined TRACE_VALUES || defined TRACE_POINTS
82 static char *CAR [26] = {"a", "b", "c", "d", "e", "f", "g", "h",
83 "i", "j", "k", "l", "m", "n", "o", "p",
84 "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
87 /*----------------------------------------------------------------------*/
89 void V3d_View::SetGrid (const gp_Ax3& aPlane, const Handle(Aspect_Grid)& aGrid) {
95 if (MyGrid->IsKind (STANDARD_TYPE (Aspect_RectangularGrid))) {
96 cout << "Aspect_RectangularGrid" << endl;
97 Handle(Aspect_RectangularGrid) theGrid = *(Handle(Aspect_RectangularGrid) *) &MyGrid;
98 cout << "\tOrigine : " << theGrid->XOrigin () << ", "
99 << theGrid->YOrigin () << endl;
100 cout << "\tAngle : " << theGrid->RotationAngle () << endl;
101 cout << "\tSteps : " << theGrid->XStep () << ", "
102 << theGrid->YStep () << endl;
105 cout << "Aspect_CircularGrid" << endl;
106 Handle(Aspect_CircularGrid) theGrid = *(Handle(Aspect_CircularGrid) *) &MyGrid;
107 cout << "\tOrigine : " << theGrid->XOrigin () << ", "
108 << theGrid->YOrigin () << endl;
109 cout << "\tAngle : " << theGrid->RotationAngle () << endl;
110 cout << "\tRadiusStep, Division : " << theGrid->RadiusStep ()
111 << ", " << theGrid->DivisionNumber () << endl;
116 Standard_Real xl, yl, zl;
117 Standard_Real xdx, xdy, xdz;
118 Standard_Real ydx, ydy, ydz;
119 Standard_Real dx, dy, dz;
120 aPlane.Location ().Coord (xl, yl, zl);
121 aPlane.XDirection ().Coord (xdx, xdy, xdz);
122 aPlane.YDirection ().Coord (ydx, ydy, ydz);
123 aPlane.Direction ().Coord (dx, dy, dz);
126 cout << "Grid Plane " << xl << ", " << yl << ", " << zl << endl;
127 cout << "\tLocation " << xl << ", " << yl << ", " << zl << endl;
128 cout << "\tDirection " << dx << ", " << dy << ", " << dz << endl;
129 cout << "\tXDirection " << xdx << ", " << xdy << ", " << xdz << endl;
130 cout << "\tYDirection " << ydx << ", " << ydy << ", " << ydz << endl;
133 Standard_Real CosAlpha = Cos (MyGrid->RotationAngle ());
134 Standard_Real SinAlpha = Sin (MyGrid->RotationAngle ());
136 TColStd_Array2OfReal Trsf1 (1, 4, 1, 4);
138 Trsf1 (4, 1) = Trsf1 (4, 2) = Trsf1 (4, 3) = 0.0;
143 // Transformation change of marker
154 TColStd_Array2OfReal Trsf2 (1, 4, 1, 4);
156 Trsf2 (4, 1) = Trsf2 (4, 2) = Trsf2 (4, 3) = 0.0;
157 // Translation of the origin
158 Trsf2 (1, 4) = -MyGrid->XOrigin (),
159 Trsf2 (2, 4) = -MyGrid->YOrigin (),
161 // Rotation Alpha around axis -Z
162 Trsf2 (1, 1) = CosAlpha,
163 Trsf2 (2, 1) = -SinAlpha,
165 Trsf2 (1, 2) = SinAlpha,
166 Trsf2 (2, 2) = CosAlpha,
172 Standard_Real valuetrsf;
173 Standard_Real valueoldtrsf;
174 Standard_Real valuenewtrsf;
175 Standard_Integer i, j, k;
176 // Calculation of the product of matrices
178 for (j=1; j<=4; j++) {
180 for (k=1; k<=4; k++) {
181 valueoldtrsf = Trsf1 (i, k);
182 valuetrsf = Trsf2 (k, j);
183 valuenewtrsf = MyTrsf (i, j) + valueoldtrsf * valuetrsf;
184 MyTrsf (i, j) = valuenewtrsf;
190 void V3d_View::SetGridActivity (const Standard_Boolean AFlag) {
192 if (AFlag) MyGrid->Activate ();
193 else MyGrid->Deactivate ();
197 void V3d_View::SetGridGraphicValues (const Handle(Aspect_Grid)&
204 Standard_Real XSize, YSize, Radius, OffSet;
205 if (aGrid->IsKind (STANDARD_TYPE (V3d_RectangularGrid))) {
206 cout << "V3d_RectangularGrid" << endl;
207 Handle(V3d_RectangularGrid) theGrid = *(Handle(V3d_RectangularGrid) *) &aGrid;
208 theGrid->GraphicValues (XSize, YSize, OffSet);
209 cout << "\tSizes : " << XSize << ", " << YSize << endl;
210 cout << "\tOffSet : " << OffSet << endl;
213 cout << "V3d_CircularGrid" << endl;
214 Handle(V3d_CircularGrid) theGrid = *(Handle(V3d_CircularGrid) *) &aGrid;
215 theGrid->GraphicValues (Radius, OffSet);
216 cout << "\tRadius : " << Radius << endl;
217 cout << "\tOffSet : " << OffSet << endl;
223 Graphic3d_Vertex V3d_View::Compute (const Graphic3d_Vertex & AVertex) const {
225 Graphic3d_Vertex CurPoint, NewPoint;
226 Standard_Real X1, Y1, Z1, X2, Y2, Z2;
227 Standard_Real XPp, YPp;
229 MyView->ViewOrientation ().ViewReferencePlane ().Coord (X1, Y1, Z1);
230 MyPlane.Direction ().Coord (X2, Y2, Z2);
232 gp_Dir VPN (X1, Y1, Z1);
233 gp_Dir GPN (X2, Y2, Z2);
236 cout << "View Plane : " << X1 << ", " << Y1 << ", " << Z1 << endl;
237 cout << "Grid Plane " << X2 << ", " << Y2 << ", " << Z2 << endl;
238 cout << "Angle VPN GPN : " << VPN.Angle (GPN) << endl;
241 AVertex.Coord (X1, Y1, Z1);
242 Project (X1, Y1, Z1, XPp, YPp);
245 cout << "AVertex : " << X1 << ", " << Y1 << ", " << Z1 << endl;
248 // Casw when the plane of the grid and the plane of the view
249 // are perpendicular to MYEPSILON2 close radians
250 if (Abs (VPN.Angle (GPN) - M_PI / 2.) < MYEPSILON2) {
251 NewPoint.SetCoord (X1, Y1, Z1);
253 TextAttrib->SetColor (Quantity_Color (Quantity_NOC_RED));
254 MyGridEchoGroup->SetPrimitivesAspect (TextAttrib);
255 MyGridEchoGroup->Text ("Q", NewPoint, 1./81.);
256 MyGridEchoGroup->Polyline (AVertex, NewPoint);
260 MyViewer->ShowGridEcho(this,NewPoint);
263 char *trace_echo = NULL;
264 trace_echo = (char *)(getenv ("CSF_GraphicEcho"));
266 MyGridEchoGroup->Clear ();
267 MyGridEchoGroup->Marker (NewPoint);
268 Visual3d_TransientManager::BeginDraw
269 (MyView, Standard_False, Standard_False);
270 Visual3d_TransientManager::DrawStructure (MyGridEchoStructure);
271 Visual3d_TransientManager::EndDraw (Standard_True);
279 Handle(Graphic3d_AspectLine3d) LineAttrib = new Graphic3d_AspectLine3d ();
280 Handle(Graphic3d_AspectText3d) TextAttrib = new Graphic3d_AspectText3d ();
282 MyGridEchoGroup->Clear ();
284 LineAttrib->SetColor (Quantity_Color (Quantity_NOC_RED));
285 MyGridEchoGroup->SetGroupPrimitivesAspect (LineAttrib);
287 TextAttrib->SetColor (Quantity_Color (Quantity_NOC_RED));
288 MyGridEchoGroup->SetGroupPrimitivesAspect (TextAttrib);
290 MyGridEchoGroup->Text ("P", AVertex, 1./81.);
291 CurPoint.SetCoord (AVertex.X (), AVertex.Y (), AVertex.Z ());
293 TextAttrib->SetColor (Quantity_Color (Quantity_NOC_GREEN));
294 MyGridEchoGroup->SetPrimitivesAspect (TextAttrib);
297 Standard_Boolean IsRectangular =
298 MyGrid->IsKind (STANDARD_TYPE (Aspect_RectangularGrid));
302 Standard_Real XO = 0.0, YO = 0.0;
303 Standard_Real XOp, YOp;
304 Standard_Real XAp, YAp;
305 Standard_Real XBp, YBp;
307 X1 = XO, Y1 = YO, Z1 = 0.0;
308 // MyTrsf * Point to return to the plane of 3D grid
309 P1.SetCoord (X1, Y1, Z1);
310 CurPoint = V3d_View::TrsPoint (P1, MyTrsf);
311 CurPoint.Coord (X2, Y2, Z2);
312 Project (X2, Y2, Z2, XOp, YOp);
313 XPp = XPp - XOp, YPp = YPp - YOp;
316 MyGridEchoGroup->Text ("O", CurPoint, 1./81.);
320 cout << "Projection de P : " << XPp << ", " << YPp << endl;
321 cout << "Projection de O : " << XOp << ", " << YOp << endl;
325 Standard_Real XS, YS;
326 Handle(Aspect_RectangularGrid) theGrid =
327 *(Handle(Aspect_RectangularGrid) *) &MyGrid;
328 XS = theGrid->XStep (), YS = theGrid->YStep ();
330 X1 = XO + XS, Y1 = YO, Z1 = 0.0;
331 // MyTrsf * Point to return to the plane of 3D grid
332 P1.SetCoord (X1, Y1, Z1);
333 CurPoint = V3d_View::TrsPoint (P1, MyTrsf);
334 CurPoint.Coord (X2, Y2, Z2);
335 Project (X2, Y2, Z2, XAp, YAp);
336 XAp = XAp - XOp, YAp = YAp - YOp;
339 MyGridEchoGroup->Text ("A", CurPoint, 1./81.);
342 X1 = XO, Y1 = YO + YS, Z1 = 0.0;
343 // MyTrsf * Point to return to the plane of 3D grid
344 P1.SetCoord (X1, Y1, Z1);
345 CurPoint = V3d_View::TrsPoint (P1, MyTrsf);
346 CurPoint.Coord (X2, Y2, Z2);
347 Project (X2, Y2, Z2, XBp, YBp);
348 XBp = XBp - XOp, YBp = YBp - YOp;
351 MyGridEchoGroup->Text ("B", CurPoint, 1./81.);
355 cout << "Projection de A : " << XAp << ", " << YAp << endl;
356 cout << "Projection de B : " << XBp << ", " << YBp << endl;
359 Standard_Real Determin = XAp*YBp - XBp*YAp;
362 if (Abs (Determin) > MYEPSILON1) {
363 X1 = (YBp*XPp - XBp*YPp) / Determin;
364 Y1 = (XAp*YPp - YAp*XPp) / Determin;
366 Standard_Real (Standard_Integer (Abs (X1)+0.5)) * XS :
367 - Standard_Real (Standard_Integer (Abs (X1)+0.5)) * XS);
369 Standard_Real (Standard_Integer (Abs (Y1)+0.5)) * YS :
370 - Standard_Real (Standard_Integer (Abs (Y1)+0.5)) * YS);
372 cout << "Chosen point : " << X1 << ", " << Y1 << endl;
374 // MyTrsf * Point to return to the plane of 3D grid
375 P1.SetCoord (X1, Y1, Z1);
376 CurPoint = V3d_View::TrsPoint (P1, MyTrsf);
377 CurPoint.Coord (X2, Y2, Z2);
380 cout << "*****************" << endl;
381 cout << "Zero Determinant!" << endl;
382 cout << "*****************" << endl;
384 cout << "Zero Determinant !" << endl;
386 AVertex.Coord (X2, Y2, Z2);
387 CurPoint.SetCoord (X2, Y2, Z2);
394 Handle(Aspect_CircularGrid) theGrid =
395 *(Handle(Aspect_CircularGrid) *) &MyGrid;
396 RS = theGrid->RadiusStep ();
397 DN = theGrid->DivisionNumber ();
398 Alpha = M_PI / Standard_Real (DN);
400 Standard_Real DistOP = Sqrt (XPp*XPp + YPp*YPp);
402 Standard_Integer i, ICur=0;
403 Standard_Real Angle, AngleCur;
404 Standard_Real XCurp=0, YCurp=0;
405 gp_Dir2d OP (XPp, YPp);
407 for (i=1; i<=DN*2; i++) {
408 X1 = XO + Cos (Alpha * i) * RS,
409 Y1 = YO + Sin (Alpha * i) * RS,
411 // MyTrsf * Point to return to the plane of 3D grid
412 P1.SetCoord (X1, Y1, Z1);
413 CurPoint = V3d_View::TrsPoint (P1, MyTrsf);
414 CurPoint.Coord (X2, Y2, Z2);
415 Project (X2, Y2, Z2, XAp, YAp);
416 XAp = XAp - XOp, YAp = YAp - YOp;
417 gp_Dir2d OA (XAp, YAp);
418 Angle = OP.Angle (OA);
419 if (Abs (AngleCur) > Abs (Angle)) {
422 XCurp = XAp, YCurp = YAp;
424 cout << "Angle between OP and O" << CAR [i-1]
425 << " : " << Angle << endl;
430 MyGridEchoGroup->Text (CAR [i-1], CurPoint, 1./81.);
432 } // for (i=1; i<=DN*2; i++)
434 Standard_Real DistOCur = Sqrt (XCurp*XCurp + YCurp*YCurp);
436 // Determination of the circle of the grid closest to P
437 Standard_Integer N = Standard_Integer (DistOP / DistOCur + 0.5);
438 Standard_Real Radius = N * RS;
440 cout << "Circle : " << N << " Radius : " << Radius << endl;
443 X1 = Cos (Alpha * ICur) * Radius,
444 Y1 = Sin (Alpha * ICur) * Radius,
448 cout << "Chosen Point : " << X1 << ", " << Y1 << endl;
450 // MyTrsf * Point to return to the plane of 3D grid
451 P1.SetCoord (X1, Y1, Z1);
452 CurPoint = V3d_View::TrsPoint (P1, MyTrsf);
453 CurPoint.Coord (X2, Y2, Z2);
456 NewPoint.SetCoord (CurPoint.X (), CurPoint.Y (), CurPoint.Z ());
459 TextAttrib->SetColor (Quantity_Color (Quantity_NOC_RED));
460 MyGridEchoGroup->SetPrimitivesAspect (TextAttrib);
461 MyGridEchoGroup->Text ("Q", NewPoint, 1./81.);
462 MyGridEchoGroup->Polyline (AVertex, NewPoint);
466 MyViewer->ShowGridEcho(this,NewPoint);
469 char *trace_echo = NULL;
470 trace_echo = (char *)(getenv ("CSF_GraphicEcho"));
472 MyGridEchoGroup->Clear ();
473 MyGridEchoGroup->Marker (NewPoint);
474 Visual3d_TransientManager::BeginDraw
475 (MyView, Standard_False, Standard_False);
476 Visual3d_TransientManager::DrawStructure (MyGridEchoStructure);
477 Visual3d_TransientManager::EndDraw (Standard_True);
484 // Triedron methods : the Triedron is a non-zoomable object.
486 void V3d_View::ZBufferTriedronSetup(const Quantity_NameOfColor XColor,
487 const Quantity_NameOfColor YColor,
488 const Quantity_NameOfColor ZColor,
489 const Standard_Real SizeRatio,
490 const Standard_Real AxisDiametr,
491 const Standard_Integer NbFacettes)
493 MyView->ZBufferTriedronSetup(XColor, YColor, ZColor, SizeRatio, AxisDiametr, NbFacettes);
496 void V3d_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition APosition,
497 const Quantity_NameOfColor AColor, const Standard_Real AScale, const V3d_TypeOfVisualization AMode ) {
499 MyView->TriedronDisplay (APosition, AColor, AScale, (AMode == V3d_WIREFRAME));
502 void V3d_View::TriedronErase ( ) {
504 MyView->TriedronErase ( );
507 void V3d_View::TriedronEcho (const Aspect_TypeOfTriedronEcho AType ) {
509 MyView->TriedronEcho (AType);
512 void V3d_View::GetGraduatedTrihedron(/* Names of axes */
513 TCollection_ExtendedString &xname,
514 TCollection_ExtendedString &yname,
515 TCollection_ExtendedString &zname,
517 Standard_Boolean& xdrawname,
518 Standard_Boolean& ydrawname,
519 Standard_Boolean& zdrawname,
521 Standard_Boolean& xdrawvalues,
522 Standard_Boolean& ydrawvalues,
523 Standard_Boolean& zdrawvalues,
525 Standard_Boolean& drawgrid,
527 Standard_Boolean& drawaxes,
528 /* Number of splits along axes */
529 Standard_Integer& nbx,
530 Standard_Integer& nby,
531 Standard_Integer& nbz,
532 /* Offset for drawing values */
533 Standard_Integer& xoffset,
534 Standard_Integer& yoffset,
535 Standard_Integer& zoffset,
536 /* Offset for drawing names of axes */
537 Standard_Integer& xaxisoffset,
538 Standard_Integer& yaxisoffset,
539 Standard_Integer& zaxisoffset,
541 Standard_Boolean& xdrawtickmarks,
542 Standard_Boolean& ydrawtickmarks,
543 Standard_Boolean& zdrawtickmarks,
544 /* Length of tickmarks */
545 Standard_Integer& xtickmarklength,
546 Standard_Integer& ytickmarklength,
547 Standard_Integer& ztickmarklength,
549 Quantity_Color& gridcolor,
551 Quantity_Color& xnamecolor,
553 Quantity_Color& ynamecolor,
555 Quantity_Color& znamecolor,
556 /* X color of axis and values */
557 Quantity_Color& xcolor,
558 /* Y color of axis and values */
559 Quantity_Color& ycolor,
560 /* Z color of axis and values */
561 Quantity_Color& zcolor,
562 /* Name of font for names of axes */
563 TCollection_AsciiString &fontOfNames,
564 /* Style of names of axes */
565 OSD_FontAspect& styleOfNames,
566 /* Size of names of axes */
567 Standard_Integer& sizeOfNames,
568 /* Name of font for values */
569 TCollection_AsciiString &fontOfValues,
570 /* Style of values */
571 OSD_FontAspect& styleOfValues,
573 Standard_Integer& sizeOfValues) const
575 MyView->GetGraduatedTrihedron(/* Names of axes */
591 /* Number of splits along axes */
595 /* Offset for drawing values */
599 /* Offset for drawing names of axes */
607 /* Length of tickmarks */
619 /* X color of axis and values */
621 /* Y color of axis and values */
623 /* Z color of axis and values */
625 /* Name of font for names of axes */
627 /* Style of names of axes */
629 /* Size of names of axes */
631 /* Name of font for values */
633 /* Style of values */
639 void V3d_View::GraduatedTrihedronDisplay(/* Names of axes */
640 const TCollection_ExtendedString &xname,
641 const TCollection_ExtendedString &yname,
642 const TCollection_ExtendedString &zname,
644 const Standard_Boolean xdrawname,
645 const Standard_Boolean ydrawname,
646 const Standard_Boolean zdrawname,
648 const Standard_Boolean xdrawvalues,
649 const Standard_Boolean ydrawvalues,
650 const Standard_Boolean zdrawvalues,
652 const Standard_Boolean drawgrid,
654 const Standard_Boolean drawaxes,
655 /* Number of splits along axes */
656 const Standard_Integer nbx,
657 const Standard_Integer nby,
658 const Standard_Integer nbz,
659 /* Offset for drawing values */
660 const Standard_Integer xoffset,
661 const Standard_Integer yoffset,
662 const Standard_Integer zoffset,
663 /* Offset for drawing names of axes */
664 const Standard_Integer xaxisoffset,
665 const Standard_Integer yaxisoffset,
666 const Standard_Integer zaxisoffset,
668 const Standard_Boolean xdrawtickmarks,
669 const Standard_Boolean ydrawtickmarks,
670 const Standard_Boolean zdrawtickmarks,
671 /* Length of tickmarks */
672 const Standard_Integer xtickmarklength,
673 const Standard_Integer ytickmarklength,
674 const Standard_Integer ztickmarklength,
676 const Quantity_Color& gridcolor,
678 const Quantity_Color& xnamecolor,
680 const Quantity_Color& ynamecolor,
682 const Quantity_Color& znamecolor,
683 /* X color of axis and values */
684 const Quantity_Color& xcolor,
685 /* Y color of axis and values */
686 const Quantity_Color& ycolor,
687 /* Z color of axis and values */
688 const Quantity_Color& zcolor,
689 /* Name of font for names of axes */
690 const TCollection_AsciiString &fontOfNames,
691 /* Style of names of axes */
692 const OSD_FontAspect styleOfNames,
693 /* Size of names of axes */
694 const Standard_Integer sizeOfNames,
695 /* Name of font for values */
696 const TCollection_AsciiString &fontOfValues,
697 /* Style of values */
698 const OSD_FontAspect styleOfValues,
700 const Standard_Integer sizeOfValues)
702 MyView->GraduatedTrihedronDisplay(/* Names of axes */
718 /* Number of splits along axes */
722 /* Offset for drawing values */
726 /* Offset for drawing names of axes */
734 /* Length of tickmarks */
746 /* X color of axis and values */
748 /* Y color of axis and values */
750 /* Z color of axis and values */
752 /* Name of font for names of axes */
754 /* Style of names of axes */
756 /* Size of names of axes */
758 /* Name of font for values */
760 /* Style of values */
766 void V3d_View::GraduatedTrihedronErase()
768 MyView->GraduatedTrihedronErase();