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