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