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> |
c5751993 | 37 | #include <Graphic3d_ZLayerSettings.hxx> |
2166f0fa SK |
38 | #include <Visual3d_TypeOfSurfaceDetail.hxx> |
39 | ||
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 | |
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 | ||
2166f0fa SK |
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 | ||
b5ac8292 | 85 | struct OpenGl_Matrix; |
a174a3c5 | 86 | class OpenGl_GraduatedTrihedron; |
2166f0fa | 87 | class OpenGl_Structure; |
a174a3c5 | 88 | class OpenGl_Trihedron; |
89 | class Handle(OpenGl_PrinterContext); | |
392ac980 | 90 | class OpenGl_StateCounter; |
2166f0fa SK |
91 | |
92 | class OpenGl_View : public MMgt_TShared | |
93 | { | |
94 | public: | |
392ac980 | 95 | OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext, OpenGl_StateCounter* theCounter); |
2166f0fa SK |
96 | virtual ~OpenGl_View (); |
97 | ||
bf75be98 | 98 | void ReleaseGlResources (const Handle(OpenGl_Context)& theCtx); |
99 | ||
100 | void SetTextureEnv (const Handle(OpenGl_Context)& theCtx, | |
101 | const Handle(Graphic3d_TextureEnv)& theTexture); | |
e276548b | 102 | void SetSurfaceDetail (const Visual3d_TypeOfSurfaceDetail AMode); |
2166f0fa SK |
103 | void SetBackfacing (const Standard_Integer AMode); |
104 | void SetLights (const CALL_DEF_VIEWCONTEXT &AContext); | |
105 | void SetAntiAliasing (const Standard_Boolean AMode) { myAntiAliasing = AMode; } | |
51b10cd4 | 106 | void SetClipPlanes (const Graphic3d_SequenceOfHClipPlane &thePlanes) { myClipPlanes = thePlanes; } |
2166f0fa SK |
107 | void SetVisualisation (const CALL_DEF_VIEWCONTEXT &AContext); |
108 | ||
b5ac8292 | 109 | void SetCamera (const Handle(Graphic3d_Camera)& theCamera) { myCamera = theCamera; } |
110 | ||
bf75be98 | 111 | void SetClipLimit (const Graphic3d_CView& theCView); |
2166f0fa | 112 | |
bf75be98 | 113 | void SetFog (const Graphic3d_CView& theCView, const Standard_Boolean theFlag); |
2166f0fa | 114 | |
a174a3c5 | 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); | |
2166f0fa | 121 | |
a174a3c5 | 122 | void GraduatedTrihedronDisplay (const Handle(OpenGl_Context)& theCtx, |
123 | const Graphic3d_CGraduatedTrihedron& theCubic); | |
124 | void GraduatedTrihedronErase (const Handle(OpenGl_Context)& theCtx); | |
2166f0fa | 125 | |
b5ac8292 | 126 | Standard_Real Height () const { return myCamera->ViewDimensions().X(); } |
127 | Standard_Real Width () const { return myCamera->ViewDimensions().Y(); } | |
2166f0fa SK |
128 | |
129 | Standard_Integer Backfacing () const { return myBackfacing; } | |
130 | ||
30f0ad28 | 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); | |
2166f0fa | 134 | |
59f45b7c | 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. | |
679ecdee | 139 | void DisplayStructure (const OpenGl_Structure* theStructure, |
59f45b7c | 140 | const Standard_Integer thePriority); |
141 | ||
142 | //! Erase structure from display list. | |
679ecdee | 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); | |
59f45b7c | 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); | |
2166f0fa | 162 | |
c5751993 | 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 | ||
2166f0fa SK |
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 | ||
a174a3c5 | 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); | |
2166f0fa | 177 | |
e276548b | 178 | |
fc73a202 | 179 | void DrawBackground (OpenGl_Workspace& theWorkspace); |
e276548b | 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 | ||
b5ac8292 | 193 | void GetMatrices (TColStd_Array2OfReal& theMatOrient, |
194 | TColStd_Array2OfReal& theMatMapping) const; | |
195 | ||
679ecdee | 196 | //! Returns list of immediate structures rendered on top of main presentation |
197 | const OpenGl_SequenceOfStructure& ImmediateStructures() const | |
198 | { | |
199 | return myImmediateList; | |
200 | } | |
201 | ||
e276548b | 202 | //! Returns modification state for ray-tracing. |
203 | Standard_Size ModificationState() const { return myModificationState; } | |
e276548b | 204 | |
679ecdee | 205 | protected: |
2166f0fa SK |
206 | |
207 | void RenderStructs (const Handle(OpenGl_Workspace) &AWorkspace); | |
a174a3c5 | 208 | void RedrawLayer2d (const Handle(OpenGl_PrinterContext)& thePrintContext, |
a174a3c5 | 209 | const Graphic3d_CView& theCView, |
210 | const Aspect_CLayer2d& theCLayer); | |
2166f0fa | 211 | |
b5ac8292 | 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 | ||
bf75be98 | 226 | Handle(OpenGl_Texture) myTextureEnv; |
2166f0fa SK |
227 | Visual3d_TypeOfSurfaceDetail mySurfaceDetail; //WSSurfaceDetail |
228 | Standard_Integer myBackfacing; //WSBackfacing | |
229 | ||
230 | OPENGL_BG_TEXTURE myBgTexture; //WSBgTexture | |
231 | OPENGL_BG_GRADIENT myBgGradient; //WSBgGradient | |
232 | ||
2166f0fa | 233 | OPENGL_ZCLIP myZClip; |
2166f0fa | 234 | |
51b10cd4 | 235 | Graphic3d_SequenceOfHClipPlane myClipPlanes; |
4269bd1b | 236 | |
b5ac8292 | 237 | Handle(Graphic3d_Camera) myCamera; |
238 | ||
2166f0fa | 239 | OPENGL_FOG myFog; |
a174a3c5 | 240 | OpenGl_Trihedron* myTrihedron; |
241 | OpenGl_GraduatedTrihedron* myGraduatedTrihedron; | |
2166f0fa SK |
242 | |
243 | //View_LABViewContext | |
244 | int myVisualization; | |
245 | int myIntShadingMethod; | |
246 | ||
247 | //View_LABLight | |
248 | OpenGl_ListOfLight myLights; | |
249 | ||
250 | //View_LABPlane | |
251 | //View_LABAliasing | |
252 | Standard_Boolean myAntiAliasing; | |
253 | ||
254 | //View_LABDepthCueing - fixed index used | |
255 | ||
679ecdee | 256 | OpenGl_LayerList myZLayers; //!< main list of displayed structure, sorted by layers |
257 | OpenGl_SequenceOfStructure myImmediateList; //!< list of immediate structures rendered on top of main presentation | |
2166f0fa | 258 | |
2166f0fa SK |
259 | const TEL_TRANSFORM_PERSISTENCE *myTransPers; |
260 | Standard_Boolean myIsTransPers; | |
261 | ||
b5ac8292 | 262 | //! Modification state |
263 | Standard_Size myProjectionState; | |
264 | Standard_Size myModelViewState; | |
392ac980 | 265 | OpenGl_StateCounter* myStateCounter; |
266 | ||
392ac980 | 267 | Standard_Size myCurrLightSourceState; |
268 | ||
269 | typedef std::pair<Standard_Size, Standard_Size> StateInfo; | |
270 | ||
271 | StateInfo myLastOrientationState; | |
272 | StateInfo myLastViewMappingState; | |
273 | StateInfo myLastLightSourceState; | |
30f0ad28 | 274 | |
e276548b | 275 | Standard_Size myModificationState; |
e276548b | 276 | |
679ecdee | 277 | public: |
278 | ||
1c35b92f | 279 | DEFINE_STANDARD_ALLOC |
679ecdee | 280 | DEFINE_STANDARD_RTTI(OpenGl_View) // Type definition |
281 | ||
2166f0fa SK |
282 | }; |
283 | ||
679ecdee | 284 | #endif // _OpenGl_View_Header |