0022337: V3d_View::Print crashes in OCCT 6.5.0
[occt.git] / src / OpenGl / OpenGl_PrinterContext.hxx
CommitLineData
7edf74fd
A
1// File: OpenGl_PrinterContext.hxx
2// Created: 20.05.11 10:00:00
3// Author: Anton POLETAEV
4
5#ifndef _OPENGL_PRINTERCONTEXT_H
6#define _OPENGL_PRINTERCONTEXT_H
7
8#include <MMgt_TShared.hxx>
9#include <Standard.hxx>
10#include <Standard_DefineHandle.hxx>
11#include <Handle_MMgt_TShared.hxx>
12#include <OpenGl_tgl_all.hxx>
13#include <NCollection_DataMap.hxx>
14#include <InterfaceGraphic_Graphic3d.hxx>
15#include <InterfaceGraphic_Visual3d.hxx>
16#include <TColStd_Array2OfReal.hxx>
17
18class Standard_Transient;
19class Handle(Standard_Type);
20class Handle(MMgt_TShared);
21class OpenGl_PrinterContext;
22
23DEFINE_STANDARD_HANDLE(OpenGl_PrinterContext,MMgt_TShared)
24
25//! Class provides specific information for redrawing view to offscreen buffer
26//! on printing. The information is: projection matrixes for tiling,
27//! scaling factors for text/markers and layer viewport dimensions.
28//! The OpenGl_PrinterContext class allows to have only one global instance
29//! that can be accessed by GetPrinterContext() during printing operation.
30//! The class instance can be created only by call_togl_print().
31class OpenGl_PrinterContext : public MMgt_TShared
32{
33
34public:
35
36 //! Get the PrinterContext instance assigned for OpenGl context.
37 //! Return NULL, if there is no current printing operation and
38 //! there is no assigned instance for "theCtx" OpenGl context.
39 static OpenGl_PrinterContext* GetPrinterContext(GLCONTEXT theCtx);
40
41 //! Get view projection transformation matrix.
42 const TColStd_Array2OfReal& GetProjTransformation ()
43 {
44 return myProjTransform;
45 }
46
47 //! Get view projection transformation matrix.
48 void GetProjTransformation (GLfloat theMatrix[16]);
49
50 //! Get text/markers scale factor
51 void GetScale (GLfloat& theScaleX, GLfloat& theScaleY)
52 {
53 theScaleX = myScaleX;
54 theScaleY = myScaleY;
55 }
56
57 //! Get layer viewport dimensions
58 void GetLayerViewport (GLsizei& theViewportX,
59 GLsizei& theViewportY)
60 {
61 theViewportX = myLayerViewportX;
62 theViewportY = myLayerViewportY;
63 }
64
65private:
66
67 //! Constructor
68 OpenGl_PrinterContext (GLCONTEXT theCtx);
69
70 //! Destructor
71 virtual ~OpenGl_PrinterContext ();
72
73 //! Deactivate current printing context.
74 //! Useful when you need to redraw in usual mode the same OpenGl context
75 //! that you used for printing right after printing, before the
76 //! OpenGl_PrinterContext instance destroyed.
77 void Deactivate ();
78
79 //! Set view projection transformation matrix for printing/tiling purposes
80 //! theProjTransform parameter should be an 4x4 array.
81 bool SetProjTransformation (TColStd_Array2OfReal& theProjTransform);
82
83 //! Set text scale factor
84 void SetScale (GLfloat theScaleX, GLfloat theScaleY)
85 {
86 myScaleX = theScaleX;
87 myScaleY = theScaleY;
88 }
89
90 //! Set layer viewport dimensions
91 void SetLayerViewport (GLsizei theViewportX,
92 GLsizei theViewportY)
93 {
94 myLayerViewportX = theViewportX;
95 myLayerViewportY = theViewportY;
96 }
97
98private:
99
100 static OpenGl_PrinterContext* g_PrinterContext;
101 static GLCONTEXT g_ContextId;
102 TColStd_Array2OfReal myProjTransform;
103 GLfloat myScaleX;
104 GLfloat myScaleY;
105 GLsizei myLayerViewportX;
106 GLsizei myLayerViewportY;
107 GLCONTEXT myCtx;
108
109 // the printer context could be created only in method call_togl_print
110 friend Standard_Boolean call_togl_print (CALL_DEF_VIEW *, CALL_DEF_LAYER *,
111 CALL_DEF_LAYER *,
112 const Aspect_Drawable, const int,
113 const char*, const int, const float);
114};
115
116#endif