0025765: Coding rules - clean up code from obsolete macro checks
[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/***********************************************************************
15
16 FONCTION :
17 ----------
18 Classe V3d_Viewer_3.cxx :
19
20 HISTORIQUE DES MODIFICATIONS :
21 --------------------------------
22 00-09-92 : GG ; Creation.
23 27-12-98 : FMN ; PERF: OPTIMISATION LOADER (LOPTIM)
24
25 REMARQUES :
26 -----------
27
28************************************************************************/
29
7fd59977 30// -> Remove the grid plane axis when it is requested.
31// -> Redraw the privilegied grid plane after any change
32
33/*----------------------------------------------------------------------*/
34/*
35 * Includes
36 */
37
38#include <V3d_Viewer.jxx>
39
40#include <Graphic3d_AspectLine3d.hxx>
41#include <Graphic3d_AspectText3d.hxx>
42#include <gp_Dir.hxx>
43#include <gp_Pnt.hxx>
44#include <Graphic3d_Structure.hxx>
45#include <Graphic3d_Group.hxx>
46
b8ddfc2f 47#include <Graphic3d_ArrayOfSegments.hxx>
7fd59977 48
49/*----------------------------------------------------------------------*/
50/*
51 * Static variable
52 */
53
7fd59977 54static TCollection_AsciiString _XLetter() {
55 static TCollection_AsciiString XLetter("X");
56return XLetter;
57}
58#define XLetter _XLetter()
59
60static TCollection_AsciiString _YLetter() {
61 static TCollection_AsciiString YLetter("Y");
62return YLetter;
63}
64#define YLetter _YLetter()
65
66static TCollection_AsciiString _ZLetter() {
67 static TCollection_AsciiString ZLetter("Z");
68return ZLetter;
69}
70#define ZLetter _ZLetter()
71
7fd59977 72/*----------------------------------------------------------------------*/
73
b8ddfc2f 74void V3d_Viewer::SetPrivilegedPlane(const gp_Ax3& aPlane)
75{
7fd59977 76 myPrivilegedPlane = aPlane;
7fd59977 77 Grid()->SetDrawMode(Grid()->DrawMode());
b8ddfc2f 78 for (InitActiveViews (); MoreActiveViews (); NextActiveViews ())
7fd59977 79 ActiveView ()->SetGrid (myPrivilegedPlane, Grid ());
b8ddfc2f 80 if(myDisplayPlane)
81 DisplayPrivilegedPlane(Standard_True,myDisplayPlaneLength);
82 else
7fd59977 83 Update();
7fd59977 84}
85
86/*----------------------------------------------------------------------*/
b8ddfc2f 87
88gp_Ax3 V3d_Viewer::PrivilegedPlane() const
89{
7fd59977 90 return myPrivilegedPlane;
7fd59977 91}
92
93/*----------------------------------------------------------------------*/
b8ddfc2f 94void V3d_Viewer::DisplayPrivilegedPlane(const Standard_Boolean OnOff, const Quantity_Length aSize)
95{
96 Standard_Boolean Change = (myDisplayPlane != OnOff);
7fd59977 97 myDisplayPlane = OnOff;
98 myDisplayPlaneLength = aSize;
99
b8ddfc2f 100 if(myDisplayPlane)
101 {
7fd59977 102 if(myPlaneStructure.IsNull()) {
103 myPlaneStructure = new Graphic3d_Structure(MyViewer);
104 myPlaneStructure->SetInfiniteState(Standard_True);
105 myPlaneStructure->Display();
106 }
107 else
108 myPlaneStructure->Clear();
b8ddfc2f 109
b64d84be 110 Handle(Graphic3d_Group) Group = myPlaneStructure->NewGroup();
7fd59977 111
112 Handle(Graphic3d_AspectLine3d) LineAttrib = new Graphic3d_AspectLine3d() ;
113 LineAttrib->SetColor(Quantity_Color(Quantity_NOC_GRAY60));
114 Group->SetPrimitivesAspect(LineAttrib) ;
115
116 Handle(Graphic3d_AspectText3d) TextAttrib = new Graphic3d_AspectText3d();
117 TextAttrib->SetColor(Quantity_Color(Quantity_NOC_ROYALBLUE1));
118 Group->SetPrimitivesAspect(TextAttrib);
b8ddfc2f 119
120 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(6);
121
122 const gp_Pnt &p0 = myPrivilegedPlane.Location();
123
124 const gp_Pnt pX(p0.XYZ() + myDisplayPlaneLength*myPrivilegedPlane.XDirection().XYZ());
125 aPrims->AddVertex(p0);
126 aPrims->AddVertex(pX);
127 Group->Text(XLetter.ToCString(),Graphic3d_Vertex(pX.X(),pX.Y(),pX.Z()),1./81.);
128
129 const gp_Pnt pY(p0.XYZ() + myDisplayPlaneLength*myPrivilegedPlane.YDirection().XYZ());
130 aPrims->AddVertex(p0);
131 aPrims->AddVertex(pY);
132 Group->Text(YLetter.ToCString(),Graphic3d_Vertex(pY.X(),pY.Y(),pY.Z()),1./81.);
7fd59977 133
b8ddfc2f 134 const gp_Pnt pZ(p0.XYZ() + myDisplayPlaneLength*myPrivilegedPlane.Direction().XYZ());
135 aPrims->AddVertex(p0);
136 aPrims->AddVertex(pZ);
137 Group->Text(ZLetter.ToCString(),Graphic3d_Vertex(pZ.X(),pZ.Y(),pZ.Z()),1./81.);
138
139 Group->AddPrimitiveArray(aPrims);
140
141 myPlaneStructure->Display();
142 }
143 else
144 {
7fd59977 145 if( !myPlaneStructure.IsNull() ) myPlaneStructure->Erase();
7fd59977 146 }
147 if(Change) Update();
148}
149
150/*----------------------------------------------------------------------*/