0023006: Improvement to debug memory leaks and insufficient memory growths.
[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
2166f0fa
SK
18#include <OpenGl_Workspace.hxx>
19
7edf74fd
A
20class Standard_Transient;
21class Handle(Standard_Type);
22class Handle(MMgt_TShared);
23class OpenGl_PrinterContext;
24
25DEFINE_STANDARD_HANDLE(OpenGl_PrinterContext,MMgt_TShared)
26
27//! Class provides specific information for redrawing view to offscreen buffer
28//! on printing. The information is: projection matrixes for tiling,
29//! scaling factors for text/markers and layer viewport dimensions.
30//! The OpenGl_PrinterContext class allows to have only one global instance
31//! that can be accessed by GetPrinterContext() during printing operation.
32//! The class instance can be created only by call_togl_print().
33class OpenGl_PrinterContext : public MMgt_TShared
34{
35
36public:
37
38 //! Get the PrinterContext instance assigned for OpenGl context.
39 //! Return NULL, if there is no current printing operation and
40 //! there is no assigned instance for "theCtx" OpenGl context.
41 static OpenGl_PrinterContext* GetPrinterContext(GLCONTEXT theCtx);
42
43 //! Get view projection transformation matrix.
44 const TColStd_Array2OfReal& GetProjTransformation ()
45 {
46 return myProjTransform;
47 }
48
49 //! Get view projection transformation matrix.
50 void GetProjTransformation (GLfloat theMatrix[16]);
51
52 //! Get text/markers scale factor
53 void GetScale (GLfloat& theScaleX, GLfloat& theScaleY)
54 {
55 theScaleX = myScaleX;
56 theScaleY = myScaleY;
57 }
58
59 //! Get layer viewport dimensions
60 void GetLayerViewport (GLsizei& theViewportX,
61 GLsizei& theViewportY)
62 {
63 theViewportX = myLayerViewportX;
64 theViewportY = myLayerViewportY;
65 }
66
67private:
68
69 //! Constructor
70 OpenGl_PrinterContext (GLCONTEXT theCtx);
71
72 //! Destructor
73 virtual ~OpenGl_PrinterContext ();
74
75 //! Deactivate current printing context.
76 //! Useful when you need to redraw in usual mode the same OpenGl context
77 //! that you used for printing right after printing, before the
78 //! OpenGl_PrinterContext instance destroyed.
79 void Deactivate ();
80
81 //! Set view projection transformation matrix for printing/tiling purposes
82 //! theProjTransform parameter should be an 4x4 array.
83 bool SetProjTransformation (TColStd_Array2OfReal& theProjTransform);
84
85 //! Set text scale factor
86 void SetScale (GLfloat theScaleX, GLfloat theScaleY)
87 {
88 myScaleX = theScaleX;
89 myScaleY = theScaleY;
90 }
91
92 //! Set layer viewport dimensions
93 void SetLayerViewport (GLsizei theViewportX,
94 GLsizei theViewportY)
95 {
96 myLayerViewportX = theViewportX;
97 myLayerViewportY = theViewportY;
98 }
99
100private:
101
102 static OpenGl_PrinterContext* g_PrinterContext;
103 static GLCONTEXT g_ContextId;
104 TColStd_Array2OfReal myProjTransform;
105 GLfloat myScaleX;
106 GLfloat myScaleY;
107 GLsizei myLayerViewportX;
108 GLsizei myLayerViewportY;
109 GLCONTEXT myCtx;
110
111 // the printer context could be created only in method call_togl_print
2166f0fa 112 /*friend Standard_Boolean call_togl_print (CALL_DEF_VIEW *, CALL_DEF_LAYER *,
7edf74fd
A
113 CALL_DEF_LAYER *,
114 const Aspect_Drawable, const int,
2166f0fa
SK
115 const char*, const int, const float);*/
116 friend Standard_Boolean OpenGl_Workspace::Print (const Graphic3d_CView& ACView,
117 const Aspect_CLayer2d& ACUnderLayer,
118 const Aspect_CLayer2d& ACOverLayer,
119 const Aspect_Handle hPrintDC,
120 const Standard_Boolean showBackground,
121 const Standard_CString filename,
122 const Aspect_PrintAlgo printAlgorithm,
123 const Standard_Real theScaleFactor);
7edf74fd
A
124};
125
126#endif