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