0024552: Convertation of the generic classes to the non-generic (BndLib).
[occt.git] / src / OpenGl / OpenGl_View.hxx
CommitLineData
b311480e 1// Created on: 2011-09-20
2// Created by: Sergey ZERCHANINOV
973c2be1 3// Copyright (c) 2011-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
973c2be1 7// This library is free software; you can redistribute it and / or modify it
8// under the terms of the GNU Lesser General Public version 2.1 as published
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_View_Header
17#define _OpenGl_View_Header
18
19#include <MMgt_TShared.hxx>
20#include <Standard_DefineHandle.hxx>
21
22#include <TColStd_Array2OfReal.hxx>
23#include <NCollection_List.hxx>
24
25#include <Quantity_NameOfColor.hxx>
26#include <Aspect_FillMethod.hxx>
27#include <Aspect_GradientFillMethod.hxx>
28#include <Aspect_TypeOfTriedronPosition.hxx>
29#include <Aspect_CLayer2d.hxx>
30
31#include <InterfaceGraphic_Graphic3d.hxx>
32#include <InterfaceGraphic_Visual3d.hxx>
33
34#include <Graphic3d_CView.hxx>
35#include <Graphic3d_CGraduatedTrihedron.hxx>
51b10cd4 36#include <Graphic3d_SequenceOfHClipPlane.hxx>
2166f0fa
SK
37#include <Visual3d_TypeOfSurfaceDetail.hxx>
38
39#include <OpenGl_telem_view.hxx>
59f45b7c 40#include <OpenGl_LayerList.hxx>
2166f0fa 41#include <OpenGl_Light.hxx>
2166f0fa 42
bf75be98 43#include <Handle_OpenGl_Context.hxx>
392ac980 44#include <Handle_OpenGl_GraphicDriver.hxx>
fd4a6963 45#include <Handle_OpenGl_Display.hxx>
2166f0fa
SK
46#include <Handle_OpenGl_Workspace.hxx>
47#include <Handle_OpenGl_View.hxx>
bf75be98 48#include <Handle_OpenGl_Texture.hxx>
2166f0fa
SK
49
50struct OPENGL_BG_TEXTURE
51{
52 Tuint TexId;
53 Tint Width;
54 Tint Height;
55 Aspect_FillMethod Style;
56};
57
58struct OPENGL_BG_GRADIENT
59{
60 TEL_COLOUR color1;
61 TEL_COLOUR color2;
62 Aspect_GradientFillMethod type;
63};
64
65struct OPENGL_EXTRA_REP
66{
67 Tfloat vrp[3];
68 Tfloat vpn[3];
69 Tfloat vup[3];
70 TEL_VIEW_MAPPING map;
71 Tfloat scaleFactors[3];
72};
73
2166f0fa
SK
74struct OPENGL_ZCLIP
75{
76 struct {
77 Standard_Boolean IsOn;
78 Standard_ShortReal Limit; /* in the range [0., 1.] */
79 } Back;
80 struct {
81 Standard_Boolean IsOn;
82 Standard_ShortReal Limit; /* in the range [0., 1.] */
83 } Front;
84};
85
86struct OPENGL_FOG
87{
88 Standard_Boolean IsOn;
89 Standard_ShortReal Front; /* in the range [0., 1.] */
90 Standard_ShortReal Back; /* in the range [0., 1.] */
91 TEL_COLOUR Color;
92};
93
a174a3c5 94class OpenGl_GraduatedTrihedron;
2166f0fa 95class OpenGl_Structure;
a174a3c5 96class OpenGl_Trihedron;
97class Handle(OpenGl_PrinterContext);
392ac980 98class OpenGl_StateCounter;
2166f0fa
SK
99
100class OpenGl_View : public MMgt_TShared
101{
102 public:
392ac980 103 OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext, OpenGl_StateCounter* theCounter);
2166f0fa
SK
104 virtual ~OpenGl_View ();
105
bf75be98 106 void ReleaseGlResources (const Handle(OpenGl_Context)& theCtx);
107
108 void SetTextureEnv (const Handle(OpenGl_Context)& theCtx,
109 const Handle(Graphic3d_TextureEnv)& theTexture);
e276548b 110 void SetSurfaceDetail (const Visual3d_TypeOfSurfaceDetail AMode);
2166f0fa
SK
111 void SetBackfacing (const Standard_Integer AMode);
112 void SetLights (const CALL_DEF_VIEWCONTEXT &AContext);
113 void SetAntiAliasing (const Standard_Boolean AMode) { myAntiAliasing = AMode; }
51b10cd4 114 void SetClipPlanes (const Graphic3d_SequenceOfHClipPlane &thePlanes) { myClipPlanes = thePlanes; }
2166f0fa
SK
115 void SetVisualisation (const CALL_DEF_VIEWCONTEXT &AContext);
116
bf75be98 117 void SetClipLimit (const Graphic3d_CView& theCView);
fd4a6963 118 void SetMapping (const Handle(OpenGl_Display)& theGlDisplay, const Graphic3d_CView& theCView);
bf75be98 119 void SetOrientation (const Graphic3d_CView& theCView);
2166f0fa 120
bf75be98 121 void SetFog (const Graphic3d_CView& theCView, const Standard_Boolean theFlag);
2166f0fa 122
a174a3c5 123 void TriedronDisplay (const Handle(OpenGl_Context)& theCtx,
124 const Aspect_TypeOfTriedronPosition thePosition,
125 const Quantity_NameOfColor theColor,
126 const Standard_Real theScale,
127 const Standard_Boolean theAsWireframe);
128 void TriedronErase (const Handle(OpenGl_Context)& theCtx);
2166f0fa 129
a174a3c5 130 void GraduatedTrihedronDisplay (const Handle(OpenGl_Context)& theCtx,
131 const Graphic3d_CGraduatedTrihedron& theCubic);
132 void GraduatedTrihedronErase (const Handle(OpenGl_Context)& theCtx);
2166f0fa
SK
133
134 Standard_Boolean ProjectObjectToRaster (const Standard_Integer w, const Standard_Integer h,
135 const Standard_ShortReal x, const Standard_ShortReal y, const Standard_ShortReal z,
136 Standard_ShortReal &xr, Standard_ShortReal &yr);
137 Standard_Boolean ProjectRasterToObject (const Standard_Integer w, const Standard_Integer h,
138 const Standard_Integer xr, const Standard_Integer yr,
139 Standard_ShortReal &x, Standard_ShortReal &y, Standard_ShortReal &z);
140 Standard_Boolean ProjectRasterToObjectWithRay (const Standard_Integer w, const Standard_Integer h,
141 const Standard_Integer xr, const Standard_Integer yr,
142 Standard_ShortReal &x, Standard_ShortReal &y, Standard_ShortReal &z,
143 Standard_ShortReal &dx, Standard_ShortReal &dy, Standard_ShortReal &dz);
144 void GetMatrices (TColStd_Array2OfReal& theMatOrient,
145 TColStd_Array2OfReal& theMatMapping,
146 const Standard_Boolean theIsCustom) const;
147
148 Standard_Real Height () const { return (myExtra.map.window.xmax - myExtra.map.window.xmin); }
149 Standard_Real Width () const { return (myExtra.map.window.ymax - myExtra.map.window.ymin); }
150
151 Standard_Integer Backfacing () const { return myBackfacing; }
152
30f0ad28 153 const TEL_TRANSFORM_PERSISTENCE * BeginTransformPersistence (const Handle(OpenGl_Context)& theCtx,
154 const TEL_TRANSFORM_PERSISTENCE *theTransPers);
155 void EndTransformPersistence (const Handle(OpenGl_Context)& theCtx);
2166f0fa 156
59f45b7c 157 //! Add structure to display list with specified priority.
158 //! The structure will be added to associated with it z layer.
159 //! If the z layer is not presented in the view, the structure will
160 //! be displayed in default bottom-level z layer.
161 void DisplayStructure (const OpenGl_Structure *theStructure,
162 const Standard_Integer thePriority);
163
164 //! Erase structure from display list.
165 void EraseStructure (const OpenGl_Structure *theStructure);
166
167 //! Insert a new top-level z layer with ID <theLayerId>
168 void AddZLayer (const Standard_Integer theLayerId);
169
170 //! Remove a z layer with ID <theLayerId>
171 void RemoveZLayer (const Standard_Integer theLayerId);
172
173 //! Display structure in z layer with ID <theNewLayerId>
174 //! If the layer with ID <theNewLayerId> is not presented in the view,
175 //! the structure will be displayed in default bottom-level layer.
176 void ChangeZLayer (const OpenGl_Structure *theStructure,
177 const Standard_Integer theNewLayerId);
2166f0fa
SK
178
179 void CreateBackgroundTexture (const Standard_CString AFileName, const Aspect_FillMethod AFillStyle);
180 void SetBackgroundTextureStyle (const Aspect_FillMethod FillStyle);
181 void SetBackgroundGradient (const Quantity_Color& AColor1, const Quantity_Color& AColor2, const Aspect_GradientFillMethod AType);
182 void SetBackgroundGradientType (const Aspect_GradientFillMethod AType);
183
a174a3c5 184 void Render (const Handle(OpenGl_PrinterContext)& thePrintContext,
185 const Handle(OpenGl_Workspace)& theWorkspace,
186 const Graphic3d_CView& theCView,
187 const Aspect_CLayer2d& theCUnderLayer,
188 const Aspect_CLayer2d& theCOverLayer);
2166f0fa 189
e276548b 190
191 void DrawBackground (const Handle(OpenGl_Workspace)& theWorkspace);
192
193 //! Returns list of OpenGL Z-layers.
194 const OpenGl_LayerList& LayerList() const { return myZLayers; }
195
196 //! Returns list of openGL light sources.
197 const OpenGl_ListOfLight& LightList() const { return myLights; }
198
199 //! Returns OpenGL environment map.
200 const Handle(OpenGl_Texture)& TextureEnv() const { return myTextureEnv; }
201
202 //! Returns visualization mode for objects in the view.
203 Visual3d_TypeOfSurfaceDetail SurfaceDetail() const { return mySurfaceDetail; }
204
205#ifdef HAVE_OPENCL
206 //! Returns modification state for ray-tracing.
207 Standard_Size ModificationState() const { return myModificationState; }
208#endif
209
a174a3c5 210public:
211
212 DEFINE_STANDARD_RTTI(OpenGl_View) // Type definition
2166f0fa
SK
213
214 protected:
215
216 void RenderStructs (const Handle(OpenGl_Workspace) &AWorkspace);
a174a3c5 217 void RedrawLayer2d (const Handle(OpenGl_PrinterContext)& thePrintContext,
a174a3c5 218 const Graphic3d_CView& theCView,
219 const Aspect_CLayer2d& theCLayer);
2166f0fa 220
bf75be98 221 Handle(OpenGl_Texture) myTextureEnv;
2166f0fa
SK
222 Visual3d_TypeOfSurfaceDetail mySurfaceDetail; //WSSurfaceDetail
223 Standard_Integer myBackfacing; //WSBackfacing
224
225 OPENGL_BG_TEXTURE myBgTexture; //WSBgTexture
226 OPENGL_BG_GRADIENT myBgGradient; //WSBgGradient
227
228 //{ myViewRep
229 Tmatrix3 myOrientationMatrix;
230 Tmatrix3 myMappingMatrix;
231
232 //Tint shield_indicator;
233 //TEL_COLOUR shield_colour;
234 //Tint border_indicator;
235 //TEL_COLOUR border_colour;
236 //Tint active_status;
237
238 OPENGL_ZCLIP myZClip;
2166f0fa
SK
239 OPENGL_EXTRA_REP myExtra;
240 //}
241
51b10cd4 242 Graphic3d_SequenceOfHClipPlane myClipPlanes;
4269bd1b 243
2166f0fa 244 OPENGL_FOG myFog;
a174a3c5 245 OpenGl_Trihedron* myTrihedron;
246 OpenGl_GraduatedTrihedron* myGraduatedTrihedron;
2166f0fa
SK
247
248 //View_LABViewContext
249 int myVisualization;
250 int myIntShadingMethod;
251
252 //View_LABLight
253 OpenGl_ListOfLight myLights;
254
255 //View_LABPlane
256 //View_LABAliasing
257 Standard_Boolean myAntiAliasing;
258
259 //View_LABDepthCueing - fixed index used
260
59f45b7c 261 OpenGl_LayerList myZLayers;
2166f0fa 262
2166f0fa
SK
263 const TEL_TRANSFORM_PERSISTENCE *myTransPers;
264 Standard_Boolean myIsTransPers;
265
392ac980 266 OpenGl_StateCounter* myStateCounter;
267
268 Standard_Size myCurrOrientationState; // <-- delete it after merge with new camera
269 Standard_Size myCurrViewMappingState; // <-- delete it after merge with new camera
270 Standard_Size myCurrLightSourceState;
271
272 typedef std::pair<Standard_Size, Standard_Size> StateInfo;
273
274 StateInfo myLastOrientationState;
275 StateInfo myLastViewMappingState;
276 StateInfo myLastLightSourceState;
30f0ad28 277
e276548b 278#ifdef HAVE_OPENCL
279 Standard_Size myModificationState;
280#endif
281
2166f0fa 282 public:
1c35b92f 283 DEFINE_STANDARD_ALLOC
2166f0fa
SK
284};
285
286#endif //_OpenGl_View_Header