0026361: Visualization - move OpenGl_TextFormatter to Font_TextFormatter
[occt.git] / src / OpenGl / OpenGl_GraduatedTrihedron.hxx
CommitLineData
b311480e 1// Created on: 2011-09-20
2// Created by: Sergey ZERCHANINOV
a174a3c5 3// Copyright (c) 2011-2013 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
2166f0fa
SK
16#ifndef _OpenGl_GraduatedTrihedron_Header
17#define _OpenGl_GraduatedTrihedron_Header
18
a79f67f8 19#include <Graphic3d_GraduatedTrihedron.hxx>
20#include <gp_Ax1.hxx>
21#include <gp_Pnt.hxx>
22#include <gp_Dir.hxx>
23#include <NCollection_Array1.hxx>
24#include <OpenGl_AspectLine.hxx>
a174a3c5 25#include <OpenGl_Element.hxx>
a79f67f8 26#include <OpenGl_PrimitiveArray.hxx>
a174a3c5 27#include <OpenGl_Text.hxx>
2166f0fa 28
fd03ee4b 29class Visual3d_View;
2166f0fa
SK
30class OpenGl_View;
31
a79f67f8 32//! This class allows to render Graduated Trihedron, i.e. trihedron with grid.
33//! it is based on Graphic3d_GraduatedTrihedron parameters and support its customization
34//! on construction level only.
35//! @sa Graphic3d_GraduatedTrihedron
36class OpenGl_GraduatedTrihedron : public OpenGl_Element
37{
a174a3c5 38public:
2166f0fa 39
a79f67f8 40 DEFINE_STANDARD_ALLOC
2166f0fa 41
a174a3c5 42public:
43
536d98e2 44 //! Default constructor.
45 OpenGl_GraduatedTrihedron();
46
47 //! Destructor.
48 virtual ~OpenGl_GraduatedTrihedron();
a174a3c5 49
536d98e2 50 //! Draw the element.
a174a3c5 51 virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
a79f67f8 52
536d98e2 53 //! Release OpenGL resources.
10b9c7df 54 virtual void Release (OpenGl_Context* theCtx);
2166f0fa 55
536d98e2 56 //! Setup configuration.
57 void SetValues (const Handle(OpenGl_Context)& theCtx,
58 const Graphic3d_GraduatedTrihedron& theData);
59
a79f67f8 60 //! Sets up-to-date values of scene bounding box.
61 //! Can be used in callback mechanism to get up-to-date values.
62 //! @sa Graphic3d_GraduatedTrihedron::CubicAxesCallback
536d98e2 63 void SetMinMax (const OpenGl_Vec3& theMin,
64 const OpenGl_Vec3& theMax);
2166f0fa 65
a79f67f8 66private:
67
68 //! Axis of trihedron. It incapsulates geometry and style.
69 class Axis
70 {
71 public:
72
73 OpenGl_Vec3 Direction;
74 TEL_COLOUR NameColor;
75 OpenGl_AspectLine LineAspect;
76 mutable OpenGl_Text Label;
536d98e2 77 mutable OpenGl_PrimitiveArray Tickmark;
78 mutable OpenGl_PrimitiveArray Line;
79 mutable OpenGl_PrimitiveArray Arrow;
a79f67f8 80
81 public:
82
83 Axis (const Graphic3d_AxisAspect& theAspect = Graphic3d_AxisAspect(),
84 const OpenGl_Vec3& theDirection = OpenGl_Vec3 (1.0f, 0.0f, 0.0f));
85
536d98e2 86 ~Axis();
a79f67f8 87
536d98e2 88 Axis& operator= (const Axis& theOther);
a79f67f8 89
90 void InitArrow (const Handle(OpenGl_Context)& theContext,
91 const Standard_ShortReal theLength,
92 const OpenGl_Vec3& theNormal) const;
93
94 void InitTickmark (const Handle(OpenGl_Context)& theContext,
95 const OpenGl_Vec3& theDir) const;
96
97 void InitLine (const Handle(OpenGl_Context)& theContext,
98 const OpenGl_Vec3& theDir) const;
99
100 void Release (OpenGl_Context* theCtx);
536d98e2 101
a79f67f8 102 };
103
104private:
105
106 //! Struct for triple of orthonormal vectors
107 //! and origin point, and axes for tickmarks.
108 //! It may be not a right or left coordinate system.
109 struct GridAxes
110 {
111 public:
112 GridAxes()
113 : Origin (0, 0, 0)
114 {
115 Axes[0] = OpenGl_Vec3 (1.0f, 0.0f, 0.0f);
116 Axes[1] = OpenGl_Vec3 (0.0f, 1.0f, 0.0f);
117 Axes[2] = OpenGl_Vec3 (0.0f, 0.0f, 1.0f);
118
119 Ticks[0] = OpenGl_Vec3 (0.0f, 0.0f, 0.0f);
120 Ticks[1] = OpenGl_Vec3 (0.0f, 0.0f, 0.0f);
121 Ticks[2] = OpenGl_Vec3 (0.0f, 0.0f, 0.0f);
122 }
123
124 public: //! @name Main grid directions
125 OpenGl_Vec3 Origin;
126 OpenGl_Vec3 Axes[3];
127
128 public: //! @name Directions for tickmarks
129 OpenGl_Vec3 Ticks[3];
130 };
131
132private:
133
134 //! Gets normal of the view out of user.
135 //! @param theContext [in] OpenGL Context
136 //! @param theNormal [out] normal of the view out of user
137 //! @return distance corresponding to 1 pixel
138 Standard_ShortReal getNormal (const Handle(OpenGl_Context)& theContext,
139 OpenGl_Vec3& theNormal) const;
140
141 //! Gets distance to point (theX, theY, theZ) of bounding box along the normal
142 //! @param theNormal [in] normal of the view out of user
143 //! @param theCenter [in] geometry center of bounding box
144 //! @param theX [in] x of target point
145 //! @param theY [in] y of target point
146 //! @param theZ [in] z of terget point
147 Standard_ShortReal getDistanceToCorner (const OpenGl_Vec3& theNormal,
148 const OpenGl_Vec3& theCenter,
149 const Standard_ShortReal theX,
150 const Standard_ShortReal theY,
151 const Standard_ShortReal theZ) const;
152
153 //! Gets axes of grid
154 //! @param theCorners [in] the corners of grid
155 //! @param theGridAxes [out] grid axes, the base of graduated trihedron grid.
156 Standard_ExtCharacter getGridAxes (const Standard_ShortReal theCorners[8],
157 GridAxes& theGridAxes) const;
158
159 //! Render line from the transformed primitive array myLine
160 //! @param theWorkspace [in] the OpenGl Workspace
161 //! @param theMat [in] theMat that containes base transformation and is used for appling
162 //! translation and rotation
163 //! @param thaTx the X for vector of translation
164 //! @param thaTy the Y for vector of translation
165 //! @param thaTz the Z for vector of translation
536d98e2 166 void renderLine (const OpenGl_PrimitiveArray& theLine,
167 const Handle(OpenGl_Workspace)& theWorkspace,
168 const OpenGl_Mat4& theMat,
169 const Standard_ShortReal theXt,
170 const Standard_ShortReal theYt,
171 const Standard_ShortReal theZt) const;
a79f67f8 172
173 //! Render grid lines perpendecular the axis of input index
174 //! @param theWorkspace [in] the OpenGl Workspace
175 //! @param theIndex [in] index of axis
176 //! @param theGridAxes [in] grid axes
177 //! @param theMat [in] theMat that containes base transformation and is used for appling
178 //! translation and rotation
179 void renderGridPlane (const Handle(OpenGl_Workspace)& theWorkspace,
180 const Standard_Integer& theIndex,
181 const GridAxes& theGridAxes,
182 OpenGl_Mat4& theMat) const;
183
184
185 //! Render the axis of input index
186 //! @param theWorkspace [in] the OpenGl Workspace
187 //! @param theIndex [in] index of axis
188 //! @param theMat [in] theMat that containes base transformation and is used for appling
189 //! translation and rotation
190 void renderAxis (const Handle(OpenGl_Workspace)& theWorkspace,
191 const Standard_Integer& theIndex,
192 const OpenGl_Mat4& theMat) const;
193
194 //! Render grid labels, tickmark lines and labels
195 //! @param theWorkspace [in] the OpenGl Workspace
196 //! @param theMat [in] theMat that containes base transformation and is used for appling
197 //! translation and rotation
198 //! @param theIndex [in] index of axis
199 //! @param theGridAxes [in] grid axes
200 //! @param theDpix [in] distance corresponding to 1 pixel
201 void renderTickmarkLabels (const Handle(OpenGl_Workspace)& theWorkspace,
202 const OpenGl_Mat4& theMat,
203 const Standard_Integer theIndex,
204 const GridAxes& theGridAxes,
205 const Standard_ShortReal theDpix) const;
206
a79f67f8 207protected: //! @name Scene bounding box values
208
209 OpenGl_Vec3 myMin;
210 OpenGl_Vec3 myMax;
211
a174a3c5 212protected:
213
a79f67f8 214 Axis myAxes[3]; //!< Axes for trihedron
215
216 Graphic3d_GraduatedTrihedron myData;
217
218 OpenGl_AspectLine myGridLineAspect; //!< Color grid properties
219
220protected: //! @name Labels properties
221
a174a3c5 222 mutable OpenGl_Text myLabelValues;
223 mutable OpenGl_AspectText myAspectLabels;
224 mutable OpenGl_AspectText myAspectValues;
a174a3c5 225
a79f67f8 226private:
227
228 enum AxisFlags
229 {
230 XOO_XYO = 1 << 1,
231 XOO_XOZ = 1 << 2,
232 OYO_OYZ = 1 << 3,
233 OYO_XYO = 1 << 4,
234 OOZ_XOZ = 1 << 5,
235 OOZ_OYZ = 1 << 6,
236 OYZ_XYZ = 1 << 7,
237 XOZ_XYZ = 1 << 8,
238 XYO_XYZ = 1 << 9
239 };
a174a3c5 240
2166f0fa
SK
241};
242
243#endif //_OpenGl_GraduatedTrihedron_Header