| 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 <Visual3d_TypeOfSurfaceDetail.hxx> |
| 38 | |
| 39 | #include <OpenGl_LayerList.hxx> |
| 40 | #include <OpenGl_Light.hxx> |
| 41 | |
| 42 | #include <Handle_OpenGl_Context.hxx> |
| 43 | #include <Handle_OpenGl_GraphicDriver.hxx> |
| 44 | #include <Handle_OpenGl_Display.hxx> |
| 45 | #include <Handle_OpenGl_Workspace.hxx> |
| 46 | #include <Handle_OpenGl_View.hxx> |
| 47 | #include <Handle_OpenGl_Texture.hxx> |
| 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 | |
| 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 | |
| 84 | struct OpenGl_Matrix; |
| 85 | class OpenGl_GraduatedTrihedron; |
| 86 | class OpenGl_Structure; |
| 87 | class OpenGl_Trihedron; |
| 88 | class Handle(OpenGl_PrinterContext); |
| 89 | class OpenGl_StateCounter; |
| 90 | |
| 91 | class OpenGl_View : public MMgt_TShared |
| 92 | { |
| 93 | public: |
| 94 | OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext, OpenGl_StateCounter* theCounter); |
| 95 | virtual ~OpenGl_View (); |
| 96 | |
| 97 | void ReleaseGlResources (const Handle(OpenGl_Context)& theCtx); |
| 98 | |
| 99 | void SetTextureEnv (const Handle(OpenGl_Context)& theCtx, |
| 100 | const Handle(Graphic3d_TextureEnv)& theTexture); |
| 101 | void SetSurfaceDetail (const Visual3d_TypeOfSurfaceDetail AMode); |
| 102 | void SetBackfacing (const Standard_Integer AMode); |
| 103 | void SetLights (const CALL_DEF_VIEWCONTEXT &AContext); |
| 104 | void SetAntiAliasing (const Standard_Boolean AMode) { myAntiAliasing = AMode; } |
| 105 | void SetClipPlanes (const Graphic3d_SequenceOfHClipPlane &thePlanes) { myClipPlanes = thePlanes; } |
| 106 | void SetVisualisation (const CALL_DEF_VIEWCONTEXT &AContext); |
| 107 | |
| 108 | void SetCamera (const Handle(Graphic3d_Camera)& theCamera) { myCamera = theCamera; } |
| 109 | |
| 110 | void SetClipLimit (const Graphic3d_CView& theCView); |
| 111 | |
| 112 | void SetFog (const Graphic3d_CView& theCView, const Standard_Boolean theFlag); |
| 113 | |
| 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); |
| 120 | |
| 121 | void GraduatedTrihedronDisplay (const Handle(OpenGl_Context)& theCtx, |
| 122 | const Graphic3d_CGraduatedTrihedron& theCubic); |
| 123 | void GraduatedTrihedronErase (const Handle(OpenGl_Context)& theCtx); |
| 124 | |
| 125 | Standard_Real Height () const { return myCamera->ViewDimensions().X(); } |
| 126 | Standard_Real Width () const { return myCamera->ViewDimensions().Y(); } |
| 127 | |
| 128 | Standard_Integer Backfacing () const { return myBackfacing; } |
| 129 | |
| 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); |
| 133 | |
| 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. |
| 138 | void DisplayStructure (const OpenGl_Structure* theStructure, |
| 139 | const Standard_Integer thePriority); |
| 140 | |
| 141 | //! Erase structure from display list. |
| 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); |
| 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); |
| 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 | |
| 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); |
| 172 | |
| 173 | |
| 174 | void DrawBackground (OpenGl_Workspace& theWorkspace); |
| 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 | |
| 188 | void GetMatrices (TColStd_Array2OfReal& theMatOrient, |
| 189 | TColStd_Array2OfReal& theMatMapping) const; |
| 190 | |
| 191 | //! Returns list of immediate structures rendered on top of main presentation |
| 192 | const OpenGl_SequenceOfStructure& ImmediateStructures() const |
| 193 | { |
| 194 | return myImmediateList; |
| 195 | } |
| 196 | |
| 197 | //! Returns modification state for ray-tracing. |
| 198 | Standard_Size ModificationState() const { return myModificationState; } |
| 199 | |
| 200 | protected: |
| 201 | |
| 202 | void RenderStructs (const Handle(OpenGl_Workspace) &AWorkspace); |
| 203 | void RedrawLayer2d (const Handle(OpenGl_PrinterContext)& thePrintContext, |
| 204 | const Graphic3d_CView& theCView, |
| 205 | const Aspect_CLayer2d& theCLayer); |
| 206 | |
| 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 | |
| 221 | Handle(OpenGl_Texture) myTextureEnv; |
| 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 | OPENGL_ZCLIP myZClip; |
| 229 | |
| 230 | Graphic3d_SequenceOfHClipPlane myClipPlanes; |
| 231 | |
| 232 | Handle(Graphic3d_Camera) myCamera; |
| 233 | |
| 234 | OPENGL_FOG myFog; |
| 235 | OpenGl_Trihedron* myTrihedron; |
| 236 | OpenGl_GraduatedTrihedron* myGraduatedTrihedron; |
| 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 | |
| 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 |
| 253 | |
| 254 | const TEL_TRANSFORM_PERSISTENCE *myTransPers; |
| 255 | Standard_Boolean myIsTransPers; |
| 256 | |
| 257 | //! Modification state |
| 258 | Standard_Size myProjectionState; |
| 259 | Standard_Size myModelViewState; |
| 260 | OpenGl_StateCounter* myStateCounter; |
| 261 | |
| 262 | Standard_Size myCurrLightSourceState; |
| 263 | |
| 264 | typedef std::pair<Standard_Size, Standard_Size> StateInfo; |
| 265 | |
| 266 | StateInfo myLastOrientationState; |
| 267 | StateInfo myLastViewMappingState; |
| 268 | StateInfo myLastLightSourceState; |
| 269 | |
| 270 | Standard_Size myModificationState; |
| 271 | |
| 272 | public: |
| 273 | |
| 274 | DEFINE_STANDARD_ALLOC |
| 275 | DEFINE_STANDARD_RTTI(OpenGl_View) // Type definition |
| 276 | |
| 277 | }; |
| 278 | |
| 279 | #endif // _OpenGl_View_Header |