1 // File: OpenGl_PrinterContext.hxx
2 // Created: 20.05.11 10:00:00
3 // Author: Anton POLETAEV
5 #ifndef _OPENGL_PRINTERCONTEXT_H
6 #define _OPENGL_PRINTERCONTEXT_H
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>
18 #include <OpenGl_Workspace.hxx>
20 class Standard_Transient;
21 class Handle(Standard_Type);
22 class Handle(MMgt_TShared);
23 class OpenGl_PrinterContext;
25 DEFINE_STANDARD_HANDLE(OpenGl_PrinterContext,MMgt_TShared)
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().
33 class OpenGl_PrinterContext : public MMgt_TShared
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);
43 //! Get view projection transformation matrix.
44 const TColStd_Array2OfReal& GetProjTransformation ()
46 return myProjTransform;
49 //! Get view projection transformation matrix.
50 void GetProjTransformation (GLfloat theMatrix[16]);
52 //! Get text/markers scale factor
53 void GetScale (GLfloat& theScaleX, GLfloat& theScaleY)
59 //! Get layer viewport dimensions
60 void GetLayerViewport (GLsizei& theViewportX,
61 GLsizei& theViewportY)
63 theViewportX = myLayerViewportX;
64 theViewportY = myLayerViewportY;
70 OpenGl_PrinterContext (GLCONTEXT theCtx);
73 virtual ~OpenGl_PrinterContext ();
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.
81 //! Set view projection transformation matrix for printing/tiling purposes
82 //! theProjTransform parameter should be an 4x4 array.
83 bool SetProjTransformation (TColStd_Array2OfReal& theProjTransform);
85 //! Set text scale factor
86 void SetScale (GLfloat theScaleX, GLfloat theScaleY)
92 //! Set layer viewport dimensions
93 void SetLayerViewport (GLsizei theViewportX,
96 myLayerViewportX = theViewportX;
97 myLayerViewportY = theViewportY;
102 static OpenGl_PrinterContext* g_PrinterContext;
103 static GLCONTEXT g_ContextId;
104 TColStd_Array2OfReal myProjTransform;
107 GLsizei myLayerViewportX;
108 GLsizei myLayerViewportY;
111 // the printer context could be created only in method call_togl_print
112 /*friend Standard_Boolean call_togl_print (CALL_DEF_VIEW *, CALL_DEF_LAYER *,
114 const Aspect_Drawable, const int,
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);