0024847: CLang warnings -Wdeprecated-writable-strings in OpenGl_Display
[occt.git] / src / OpenGl / OpenGl_View.hxx
1 // Created on: 2011-09-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
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>
36 #include <Graphic3d_SequenceOfHClipPlane.hxx>
37 #include <Graphic3d_ZLayerSettings.hxx>
38 #include <Visual3d_TypeOfSurfaceDetail.hxx>
39
40 #include <OpenGl_LayerList.hxx>
41 #include <OpenGl_Light.hxx>
42 #include <OpenGl_LineAttributes.hxx>
43
44 #include <Handle_OpenGl_Context.hxx>
45 #include <Handle_OpenGl_GraphicDriver.hxx>
46 #include <Handle_OpenGl_Workspace.hxx>
47 #include <Handle_OpenGl_View.hxx>
48 #include <Handle_OpenGl_Texture.hxx>
49
50 struct OPENGL_BG_TEXTURE
51 {
52   Tuint             TexId;
53   Tint              Width;
54   Tint              Height;
55   Aspect_FillMethod Style;
56 };
57
58 struct OPENGL_BG_GRADIENT
59 {
60   TEL_COLOUR color1;
61   TEL_COLOUR color2;
62   Aspect_GradientFillMethod type;
63 };
64
65 struct OPENGL_ZCLIP
66 {
67   struct {
68     Standard_Boolean   IsOn;
69     Standard_ShortReal Limit; /* in the range [0., 1.] */
70   } Back;
71   struct {
72     Standard_Boolean   IsOn;
73     Standard_ShortReal Limit; /* in the range [0., 1.] */
74   } Front;
75 };
76
77 struct OPENGL_FOG
78 {
79   Standard_Boolean   IsOn;
80   Standard_ShortReal Front; /* in the range [0., 1.] */
81   Standard_ShortReal Back; /* in the range [0., 1.] */
82   TEL_COLOUR         Color;
83 };
84
85 struct OpenGl_Matrix;
86 class OpenGl_GraduatedTrihedron;
87 class OpenGl_Structure;
88 class OpenGl_Trihedron;
89 class Handle(OpenGl_PrinterContext);
90 class OpenGl_StateCounter;
91
92 class OpenGl_View : public MMgt_TShared
93 {
94  public:
95   OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext, OpenGl_StateCounter* theCounter);
96   virtual ~OpenGl_View ();
97
98   void ReleaseGlResources (const Handle(OpenGl_Context)& theCtx);
99
100   void SetTextureEnv (const Handle(OpenGl_Context)&       theCtx,
101                       const Handle(Graphic3d_TextureEnv)& theTexture);
102   void SetSurfaceDetail (const Visual3d_TypeOfSurfaceDetail AMode);
103   void SetBackfacing (const Standard_Integer AMode);
104   void SetLights (const CALL_DEF_VIEWCONTEXT &AContext);
105   void SetAntiAliasing (const Standard_Boolean AMode) { myAntiAliasing = AMode; }
106   void SetClipPlanes (const Graphic3d_SequenceOfHClipPlane &thePlanes) { myClipPlanes = thePlanes; }
107   void SetVisualisation (const CALL_DEF_VIEWCONTEXT &AContext);
108
109   void SetCamera (const Handle(Graphic3d_Camera)& theCamera) { myCamera = theCamera; }
110
111   void SetClipLimit (const Graphic3d_CView& theCView);
112
113   void SetFog (const Graphic3d_CView& theCView, const Standard_Boolean theFlag);
114
115   void TriedronDisplay (const Handle(OpenGl_Context)&       theCtx,
116                         const Aspect_TypeOfTriedronPosition thePosition,
117                         const Quantity_NameOfColor          theColor,
118                         const Standard_Real                 theScale,
119                         const Standard_Boolean              theAsWireframe);
120   void TriedronErase (const Handle(OpenGl_Context)& theCtx);
121
122   void GraduatedTrihedronDisplay (const Handle(OpenGl_Context)&        theCtx,
123                                   const Graphic3d_CGraduatedTrihedron& theCubic);
124   void GraduatedTrihedronErase (const Handle(OpenGl_Context)& theCtx);
125
126   Standard_Real Height () const { return myCamera->ViewDimensions().X(); }
127   Standard_Real Width () const { return myCamera->ViewDimensions().Y(); }
128
129   Standard_Integer Backfacing () const { return myBackfacing; }
130
131   const TEL_TRANSFORM_PERSISTENCE * BeginTransformPersistence (const Handle(OpenGl_Context)& theCtx,
132                                                                const TEL_TRANSFORM_PERSISTENCE *theTransPers);
133   void EndTransformPersistence (const Handle(OpenGl_Context)& theCtx);
134
135   //! Add structure to display list with specified priority.
136   //! The structure will be added to associated with it z layer.
137   //! If the z layer is not presented in the view, the structure will
138   //! be displayed in default bottom-level z layer.
139   void DisplayStructure (const OpenGl_Structure* theStructure,
140                          const Standard_Integer  thePriority);
141
142   //! Erase structure from display list.
143   void EraseStructure (const OpenGl_Structure* theStructure);
144
145   //! Add structure to the list of immediate structures.
146   void DisplayImmediateStructure (const OpenGl_Structure* theStructure);
147
148   //! Erase structure from display list.
149   void EraseImmediateStructure (const OpenGl_Structure* theStructure);
150
151   //! Insert a new top-level z layer with ID <theLayerId>
152   void AddZLayer (const Standard_Integer theLayerId);
153
154   //! Remove a z layer with ID <theLayerId>
155   void RemoveZLayer (const Standard_Integer theLayerId);
156
157   //! Display structure in z layer with ID <theNewLayerId>
158   //! If the layer with ID <theNewLayerId> is not presented in the view,
159   //! the structure will be displayed in default bottom-level layer.
160   void ChangeZLayer (const OpenGl_Structure *theStructure,
161                      const Standard_Integer  theNewLayerId);
162
163   //! Sets the settings for a single Z layer of specified view.
164   void SetZLayerSettings (const Standard_Integer theLayerId,
165                           const Graphic3d_ZLayerSettings theSettings);
166
167   void CreateBackgroundTexture (const Standard_CString AFileName, const Aspect_FillMethod AFillStyle);
168   void SetBackgroundTextureStyle (const Aspect_FillMethod FillStyle);
169   void SetBackgroundGradient (const Quantity_Color& AColor1, const Quantity_Color& AColor2, const Aspect_GradientFillMethod AType);
170   void SetBackgroundGradientType (const Aspect_GradientFillMethod AType);
171
172   void Render (const Handle(OpenGl_PrinterContext)& thePrintContext,
173                const Handle(OpenGl_Workspace)&      theWorkspace,
174                const Graphic3d_CView&               theCView,
175                const Aspect_CLayer2d&               theCUnderLayer,
176                const Aspect_CLayer2d&               theCOverLayer);
177
178
179   void DrawBackground (OpenGl_Workspace& theWorkspace);
180
181   //! Returns list of OpenGL Z-layers.
182   const OpenGl_LayerList& LayerList() const { return myZLayers; }
183
184   //! Returns list of openGL light sources.
185   const OpenGl_ListOfLight& LightList() const { return myLights; }
186
187   //! Returns OpenGL environment map.
188   const Handle(OpenGl_Texture)& TextureEnv() const { return myTextureEnv; }
189
190   //! Returns visualization mode for objects in the view.
191   Visual3d_TypeOfSurfaceDetail SurfaceDetail() const { return mySurfaceDetail; }
192
193   void GetMatrices (TColStd_Array2OfReal&  theMatOrient,
194                     TColStd_Array2OfReal&  theMatMapping) const;
195
196   //! Returns list of immediate structures rendered on top of main presentation
197   const OpenGl_SequenceOfStructure& ImmediateStructures() const
198   {
199     return myImmediateList;
200   }
201
202   //! Returns modification state for ray-tracing.
203   Standard_Size ModificationState() const { return myModificationState; }
204
205 protected:
206
207   void RenderStructs (const Handle(OpenGl_Workspace) &AWorkspace);
208   void RedrawLayer2d (const Handle(OpenGl_PrinterContext)& thePrintContext,
209                       const Graphic3d_CView&               theCView,
210                       const Aspect_CLayer2d&               theCLayer);
211
212   //! Redraw contents of model scene: clipping planes,
213   //! lights, structures. The peculiar properties of "scene" is that
214   //! it requires empty Z-Buffer and uses projection and orientation
215   //! matrices supplied by 3d view.
216   //! @param thePrintCtx [in] printer context which facilitates tiled printing.
217   //! @param theWorkspace [in] rendering workspace.
218   //! @param theCView [in] view data.
219   //! @param theProjection [in] view projection matrix.
220   //! @param theOrientation [in] view orientation matrix.
221   void RedrawScene (const Handle(OpenGl_PrinterContext)& thePrintContext,
222                     const Handle(OpenGl_Workspace)& theWorkspace,
223                     const OpenGl_Matrix* theProjection,
224                     const OpenGl_Matrix* theOrientation);
225
226   Handle(OpenGl_LineAttributes) myLineAttribs;
227   Handle(OpenGl_Texture)        myTextureEnv;
228   Visual3d_TypeOfSurfaceDetail  mySurfaceDetail;
229   Standard_Integer              myBackfacing;
230
231   OPENGL_BG_TEXTURE  myBgTexture;
232   OPENGL_BG_GRADIENT myBgGradient;
233
234   OPENGL_ZCLIP   myZClip;
235
236   Graphic3d_SequenceOfHClipPlane myClipPlanes;
237   
238   Handle(Graphic3d_Camera) myCamera;
239
240   OPENGL_FOG myFog;
241   OpenGl_Trihedron*          myTrihedron;
242   OpenGl_GraduatedTrihedron* myGraduatedTrihedron;
243
244   //View_LABViewContext
245   int myVisualization;
246   int myIntShadingMethod;
247
248   //View_LABLight
249   OpenGl_ListOfLight myLights;
250
251   //View_LABPlane
252   //View_LABAliasing
253   Standard_Boolean myAntiAliasing;
254
255   //View_LABDepthCueing - fixed index used
256
257   OpenGl_LayerList           myZLayers;       //!< main list of displayed structure, sorted by layers
258   OpenGl_SequenceOfStructure myImmediateList; //!< list of immediate structures rendered on top of main presentation
259
260   const TEL_TRANSFORM_PERSISTENCE *myTransPers;
261   Standard_Boolean myIsTransPers;
262
263   //! Modification state
264   Standard_Size myProjectionState;
265   Standard_Size myModelViewState;
266   OpenGl_StateCounter* myStateCounter;
267
268   Standard_Size myCurrLightSourceState;
269
270   typedef std::pair<Standard_Size, Standard_Size> StateInfo;
271
272   StateInfo myLastOrientationState;
273   StateInfo myLastViewMappingState;
274   StateInfo myLastLightSourceState;
275
276   Standard_Size myModificationState;
277
278 public:
279
280   DEFINE_STANDARD_ALLOC
281   DEFINE_STANDARD_RTTI(OpenGl_View) // Type definition
282
283 };
284
285 #endif // _OpenGl_View_Header