0024276: Memory leak due to a static variable
[occt.git] / src / OpenGl / OpenGl_View.hxx
CommitLineData
b311480e 1// Created on: 2011-09-20
2// Created by: Sergey ZERCHANINOV
3// Copyright (c) 2011-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
2166f0fa
SK
20#ifndef _OpenGl_View_Header
21#define _OpenGl_View_Header
22
23#include <MMgt_TShared.hxx>
24#include <Standard_DefineHandle.hxx>
25
26#include <TColStd_Array2OfReal.hxx>
27#include <NCollection_List.hxx>
28
29#include <Quantity_NameOfColor.hxx>
30#include <Aspect_FillMethod.hxx>
31#include <Aspect_GradientFillMethod.hxx>
32#include <Aspect_TypeOfTriedronPosition.hxx>
33#include <Aspect_CLayer2d.hxx>
34
35#include <InterfaceGraphic_Graphic3d.hxx>
36#include <InterfaceGraphic_Visual3d.hxx>
37
38#include <Graphic3d_CView.hxx>
39#include <Graphic3d_CGraduatedTrihedron.hxx>
4269bd1b 40#include <Graphic3d_SetOfHClipPlane.hxx>
2166f0fa
SK
41#include <Visual3d_TypeOfSurfaceDetail.hxx>
42
43#include <OpenGl_telem_view.hxx>
59f45b7c 44#include <OpenGl_LayerList.hxx>
2166f0fa 45#include <OpenGl_Light.hxx>
2166f0fa 46
bf75be98 47#include <Handle_OpenGl_Context.hxx>
fd4a6963 48#include <Handle_OpenGl_Display.hxx>
2166f0fa
SK
49#include <Handle_OpenGl_Workspace.hxx>
50#include <Handle_OpenGl_View.hxx>
bf75be98 51#include <Handle_OpenGl_Texture.hxx>
2166f0fa
SK
52
53struct OPENGL_BG_TEXTURE
54{
55 Tuint TexId;
56 Tint Width;
57 Tint Height;
58 Aspect_FillMethod Style;
59};
60
61struct OPENGL_BG_GRADIENT
62{
63 TEL_COLOUR color1;
64 TEL_COLOUR color2;
65 Aspect_GradientFillMethod type;
66};
67
68struct OPENGL_EXTRA_REP
69{
70 Tfloat vrp[3];
71 Tfloat vpn[3];
72 Tfloat vup[3];
73 TEL_VIEW_MAPPING map;
74 Tfloat scaleFactors[3];
75};
76
2166f0fa
SK
77struct OPENGL_ZCLIP
78{
79 struct {
80 Standard_Boolean IsOn;
81 Standard_ShortReal Limit; /* in the range [0., 1.] */
82 } Back;
83 struct {
84 Standard_Boolean IsOn;
85 Standard_ShortReal Limit; /* in the range [0., 1.] */
86 } Front;
87};
88
89struct OPENGL_FOG
90{
91 Standard_Boolean IsOn;
92 Standard_ShortReal Front; /* in the range [0., 1.] */
93 Standard_ShortReal Back; /* in the range [0., 1.] */
94 TEL_COLOUR Color;
95};
96
a174a3c5 97class OpenGl_GraduatedTrihedron;
2166f0fa 98class OpenGl_Structure;
a174a3c5 99class OpenGl_Trihedron;
100class Handle(OpenGl_PrinterContext);
2166f0fa
SK
101
102class OpenGl_View : public MMgt_TShared
103{
104 public:
105 OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext);
106 virtual ~OpenGl_View ();
107
bf75be98 108 void ReleaseGlResources (const Handle(OpenGl_Context)& theCtx);
109
110 void SetTextureEnv (const Handle(OpenGl_Context)& theCtx,
111 const Handle(Graphic3d_TextureEnv)& theTexture);
2166f0fa
SK
112 void SetSurfaceDetail (const Visual3d_TypeOfSurfaceDetail AMode) { mySurfaceDetail = AMode; }
113 void SetBackfacing (const Standard_Integer AMode);
114 void SetLights (const CALL_DEF_VIEWCONTEXT &AContext);
115 void SetAntiAliasing (const Standard_Boolean AMode) { myAntiAliasing = AMode; }
4269bd1b 116 void SetClipPlanes (const Graphic3d_SetOfHClipPlane &thePlanes) { myClipPlanes = thePlanes; }
2166f0fa
SK
117 void SetVisualisation (const CALL_DEF_VIEWCONTEXT &AContext);
118
bf75be98 119 void SetClipLimit (const Graphic3d_CView& theCView);
fd4a6963 120 void SetMapping (const Handle(OpenGl_Display)& theGlDisplay, const Graphic3d_CView& theCView);
bf75be98 121 void SetOrientation (const Graphic3d_CView& theCView);
2166f0fa 122
bf75be98 123 void SetFog (const Graphic3d_CView& theCView, const Standard_Boolean theFlag);
2166f0fa 124
a174a3c5 125 void TriedronDisplay (const Handle(OpenGl_Context)& theCtx,
126 const Aspect_TypeOfTriedronPosition thePosition,
127 const Quantity_NameOfColor theColor,
128 const Standard_Real theScale,
129 const Standard_Boolean theAsWireframe);
130 void TriedronErase (const Handle(OpenGl_Context)& theCtx);
2166f0fa 131
a174a3c5 132 void GraduatedTrihedronDisplay (const Handle(OpenGl_Context)& theCtx,
133 const Graphic3d_CGraduatedTrihedron& theCubic);
134 void GraduatedTrihedronErase (const Handle(OpenGl_Context)& theCtx);
2166f0fa
SK
135
136 Standard_Boolean ProjectObjectToRaster (const Standard_Integer w, const Standard_Integer h,
137 const Standard_ShortReal x, const Standard_ShortReal y, const Standard_ShortReal z,
138 Standard_ShortReal &xr, Standard_ShortReal &yr);
139 Standard_Boolean ProjectRasterToObject (const Standard_Integer w, const Standard_Integer h,
140 const Standard_Integer xr, const Standard_Integer yr,
141 Standard_ShortReal &x, Standard_ShortReal &y, Standard_ShortReal &z);
142 Standard_Boolean ProjectRasterToObjectWithRay (const Standard_Integer w, const Standard_Integer h,
143 const Standard_Integer xr, const Standard_Integer yr,
144 Standard_ShortReal &x, Standard_ShortReal &y, Standard_ShortReal &z,
145 Standard_ShortReal &dx, Standard_ShortReal &dy, Standard_ShortReal &dz);
146 void GetMatrices (TColStd_Array2OfReal& theMatOrient,
147 TColStd_Array2OfReal& theMatMapping,
148 const Standard_Boolean theIsCustom) const;
149
150 Standard_Real Height () const { return (myExtra.map.window.xmax - myExtra.map.window.xmin); }
151 Standard_Real Width () const { return (myExtra.map.window.ymax - myExtra.map.window.ymin); }
152
153 Standard_Integer Backfacing () const { return myBackfacing; }
154
155 const TEL_TRANSFORM_PERSISTENCE * BeginTransformPersistence ( const TEL_TRANSFORM_PERSISTENCE *ATransPers );
156 void EndTransformPersistence ();
157
59f45b7c 158 //! Add structure to display list with specified priority.
159 //! The structure will be added to associated with it z layer.
160 //! If the z layer is not presented in the view, the structure will
161 //! be displayed in default bottom-level z layer.
162 void DisplayStructure (const OpenGl_Structure *theStructure,
163 const Standard_Integer thePriority);
164
165 //! Erase structure from display list.
166 void EraseStructure (const OpenGl_Structure *theStructure);
167
168 //! Insert a new top-level z layer with ID <theLayerId>
169 void AddZLayer (const Standard_Integer theLayerId);
170
171 //! Remove a z layer with ID <theLayerId>
172 void RemoveZLayer (const Standard_Integer theLayerId);
173
174 //! Display structure in z layer with ID <theNewLayerId>
175 //! If the layer with ID <theNewLayerId> is not presented in the view,
176 //! the structure will be displayed in default bottom-level layer.
177 void ChangeZLayer (const OpenGl_Structure *theStructure,
178 const Standard_Integer theNewLayerId);
2166f0fa
SK
179
180 void CreateBackgroundTexture (const Standard_CString AFileName, const Aspect_FillMethod AFillStyle);
181 void SetBackgroundTextureStyle (const Aspect_FillMethod FillStyle);
182 void SetBackgroundGradient (const Quantity_Color& AColor1, const Quantity_Color& AColor2, const Aspect_GradientFillMethod AType);
183 void SetBackgroundGradientType (const Aspect_GradientFillMethod AType);
184
a174a3c5 185 void Render (const Handle(OpenGl_PrinterContext)& thePrintContext,
186 const Handle(OpenGl_Workspace)& theWorkspace,
187 const Graphic3d_CView& theCView,
188 const Aspect_CLayer2d& theCUnderLayer,
189 const Aspect_CLayer2d& theCOverLayer);
2166f0fa 190
a174a3c5 191public:
192
193 DEFINE_STANDARD_RTTI(OpenGl_View) // Type definition
2166f0fa
SK
194
195 protected:
196
197 void RenderStructs (const Handle(OpenGl_Workspace) &AWorkspace);
a174a3c5 198 void RedrawLayer2d (const Handle(OpenGl_PrinterContext)& thePrintContext,
199 const Handle(OpenGl_Workspace)& theWorkspace,
200 const Graphic3d_CView& theCView,
201 const Aspect_CLayer2d& theCLayer);
2166f0fa 202
bf75be98 203 Handle(OpenGl_Texture) myTextureEnv;
2166f0fa
SK
204 Visual3d_TypeOfSurfaceDetail mySurfaceDetail; //WSSurfaceDetail
205 Standard_Integer myBackfacing; //WSBackfacing
206
207 OPENGL_BG_TEXTURE myBgTexture; //WSBgTexture
208 OPENGL_BG_GRADIENT myBgGradient; //WSBgGradient
209
210 //{ myViewRep
211 Tmatrix3 myOrientationMatrix;
212 Tmatrix3 myMappingMatrix;
213
214 //Tint shield_indicator;
215 //TEL_COLOUR shield_colour;
216 //Tint border_indicator;
217 //TEL_COLOUR border_colour;
218 //Tint active_status;
219
220 OPENGL_ZCLIP myZClip;
2166f0fa
SK
221 OPENGL_EXTRA_REP myExtra;
222 //}
223
4269bd1b 224 Graphic3d_SetOfHClipPlane myClipPlanes;
225
2166f0fa 226 OPENGL_FOG myFog;
a174a3c5 227 OpenGl_Trihedron* myTrihedron;
228 OpenGl_GraduatedTrihedron* myGraduatedTrihedron;
2166f0fa
SK
229
230 //View_LABViewContext
231 int myVisualization;
232 int myIntShadingMethod;
233
234 //View_LABLight
235 OpenGl_ListOfLight myLights;
236
237 //View_LABPlane
238 //View_LABAliasing
239 Standard_Boolean myAntiAliasing;
240
241 //View_LABDepthCueing - fixed index used
242
59f45b7c 243 OpenGl_LayerList myZLayers;
2166f0fa 244
2166f0fa
SK
245 const TEL_TRANSFORM_PERSISTENCE *myTransPers;
246 Standard_Boolean myIsTransPers;
247
2166f0fa 248 public:
1c35b92f 249 DEFINE_STANDARD_ALLOC
2166f0fa
SK
250};
251
252#endif //_OpenGl_View_Header