0026886: Visualization, TKV3d - eliminate global variables
[occt.git] / src / V3d / V3d_Viewer_3.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 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
973c2be1 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.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14/***********************************************************************
7fd59977 15 FONCTION :
16 ----------
17 Classe V3d_Viewer_3.cxx :
7fd59977 18 HISTORIQUE DES MODIFICATIONS :
19 --------------------------------
20 00-09-92 : GG ; Creation.
21 27-12-98 : FMN ; PERF: OPTIMISATION LOADER (LOPTIM)
7fd59977 22 REMARQUES :
23 -----------
7fd59977 24************************************************************************/
7fd59977 25// -> Remove the grid plane axis when it is requested.
26// -> Redraw the privilegied grid plane after any change
7fd59977 27/*----------------------------------------------------------------------*/
28/*
29 * Includes
30 */
31
42cf5bc1 32#include <Aspect_Background.hxx>
33#include <Aspect_GradientBackground.hxx>
34#include <Aspect_Grid.hxx>
35#include <gp_Ax3.hxx>
7fd59977 36#include <gp_Dir.hxx>
37#include <gp_Pnt.hxx>
b8ddfc2f 38#include <Graphic3d_ArrayOfSegments.hxx>
42cf5bc1 39#include <Graphic3d_AspectLine3d.hxx>
40#include <Graphic3d_AspectMarker3d.hxx>
41#include <Graphic3d_AspectText3d.hxx>
42#include <Graphic3d_GraphicDriver.hxx>
43#include <Graphic3d_Group.hxx>
44#include <Graphic3d_Structure.hxx>
45#include <Quantity_Color.hxx>
46#include <V3d_BadValue.hxx>
47#include <V3d_CircularGrid.hxx>
48#include <V3d_Light.hxx>
49#include <V3d_RectangularGrid.hxx>
50#include <V3d_View.hxx>
51#include <V3d_Viewer.hxx>
7fd59977 52
53/*----------------------------------------------------------------------*/
7fd59977 54
b8ddfc2f 55void V3d_Viewer::SetPrivilegedPlane(const gp_Ax3& aPlane)
56{
7fd59977 57 myPrivilegedPlane = aPlane;
7fd59977 58 Grid()->SetDrawMode(Grid()->DrawMode());
b8ddfc2f 59 for (InitActiveViews (); MoreActiveViews (); NextActiveViews ())
7fd59977 60 ActiveView ()->SetGrid (myPrivilegedPlane, Grid ());
b8ddfc2f 61 if(myDisplayPlane)
62 DisplayPrivilegedPlane(Standard_True,myDisplayPlaneLength);
63 else
7fd59977 64 Update();
7fd59977 65}
66
67/*----------------------------------------------------------------------*/
b8ddfc2f 68
69gp_Ax3 V3d_Viewer::PrivilegedPlane() const
70{
7fd59977 71 return myPrivilegedPlane;
7fd59977 72}
73
74/*----------------------------------------------------------------------*/
b8ddfc2f 75void V3d_Viewer::DisplayPrivilegedPlane(const Standard_Boolean OnOff, const Quantity_Length aSize)
76{
77 Standard_Boolean Change = (myDisplayPlane != OnOff);
7fd59977 78 myDisplayPlane = OnOff;
79 myDisplayPlaneLength = aSize;
80
b8ddfc2f 81 if(myDisplayPlane)
82 {
7fd59977 83 if(myPlaneStructure.IsNull()) {
c357e426 84 myPlaneStructure = new Graphic3d_Structure(StructureManager());
7fd59977 85 myPlaneStructure->SetInfiniteState(Standard_True);
86 myPlaneStructure->Display();
87 }
88 else
89 myPlaneStructure->Clear();
b8ddfc2f 90
b64d84be 91 Handle(Graphic3d_Group) Group = myPlaneStructure->NewGroup();
7fd59977 92
93 Handle(Graphic3d_AspectLine3d) LineAttrib = new Graphic3d_AspectLine3d() ;
94 LineAttrib->SetColor(Quantity_Color(Quantity_NOC_GRAY60));
95 Group->SetPrimitivesAspect(LineAttrib) ;
96
97 Handle(Graphic3d_AspectText3d) TextAttrib = new Graphic3d_AspectText3d();
98 TextAttrib->SetColor(Quantity_Color(Quantity_NOC_ROYALBLUE1));
99 Group->SetPrimitivesAspect(TextAttrib);
b8ddfc2f 100
101 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(6);
102
103 const gp_Pnt &p0 = myPrivilegedPlane.Location();
104
105 const gp_Pnt pX(p0.XYZ() + myDisplayPlaneLength*myPrivilegedPlane.XDirection().XYZ());
106 aPrims->AddVertex(p0);
107 aPrims->AddVertex(pX);
016e5959 108 Group->Text("X",Graphic3d_Vertex(pX.X(),pX.Y(),pX.Z()),1./81.);
b8ddfc2f 109
110 const gp_Pnt pY(p0.XYZ() + myDisplayPlaneLength*myPrivilegedPlane.YDirection().XYZ());
111 aPrims->AddVertex(p0);
112 aPrims->AddVertex(pY);
016e5959 113 Group->Text("Y",Graphic3d_Vertex(pY.X(),pY.Y(),pY.Z()),1./81.);
7fd59977 114
b8ddfc2f 115 const gp_Pnt pZ(p0.XYZ() + myDisplayPlaneLength*myPrivilegedPlane.Direction().XYZ());
116 aPrims->AddVertex(p0);
117 aPrims->AddVertex(pZ);
016e5959 118 Group->Text("Z",Graphic3d_Vertex(pZ.X(),pZ.Y(),pZ.Z()),1./81.);
b8ddfc2f 119
120 Group->AddPrimitiveArray(aPrims);
121
122 myPlaneStructure->Display();
123 }
124 else
125 {
7fd59977 126 if( !myPlaneStructure.IsNull() ) myPlaneStructure->Erase();
7fd59977 127 }
128 if(Change) Update();
129}
130
131/*----------------------------------------------------------------------*/