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