1 // Created on: 2011-05-20
2 // Created by: Anton POLETAEV
3 // Copyright (c) 2011-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 #ifndef _OPENGL_PRINTERCONTEXT_H
22 #define _OPENGL_PRINTERCONTEXT_H
24 #include <OpenGl_GlCore11.hxx>
26 #include <MMgt_TShared.hxx>
27 #include <Standard.hxx>
28 #include <Standard_DefineHandle.hxx>
29 #include <Handle_MMgt_TShared.hxx>
30 #include <NCollection_DataMap.hxx>
31 #include <InterfaceGraphic_Graphic3d.hxx>
32 #include <InterfaceGraphic_Visual3d.hxx>
33 #include <TColStd_Array2OfReal.hxx>
35 #include <OpenGl_Workspace.hxx>
37 class Standard_Transient;
38 class Handle(Standard_Type);
39 class Handle(MMgt_TShared);
40 class OpenGl_PrinterContext;
42 DEFINE_STANDARD_HANDLE(OpenGl_PrinterContext,MMgt_TShared)
44 //! Class provides specific information for redrawing view to offscreen buffer
45 //! on printing. The information is: projection matrixes for tiling,
46 //! scaling factors for text/markers and layer viewport dimensions.
47 //! The OpenGl_PrinterContext class allows to have only one global instance
48 //! that can be accessed by GetPrinterContext() during printing operation.
49 //! The class instance can be created only by call_togl_print().
50 class OpenGl_PrinterContext : public MMgt_TShared
55 //! Get the PrinterContext instance assigned for OpenGl context.
56 //! Return NULL, if there is no current printing operation and
57 //! there is no assigned instance for "theCtx" OpenGl context.
58 static OpenGl_PrinterContext* GetPrinterContext(GLCONTEXT theCtx);
60 //! Get view projection transformation matrix.
61 const TColStd_Array2OfReal& GetProjTransformation ()
63 return myProjTransform;
66 //! Get view projection transformation matrix.
67 void GetProjTransformation (GLfloat theMatrix[16]);
69 //! Get text/markers scale factor
70 void GetScale (GLfloat& theScaleX, GLfloat& theScaleY)
76 //! Get layer viewport dimensions
77 void GetLayerViewport (GLsizei& theViewportX,
78 GLsizei& theViewportY)
80 theViewportX = myLayerViewportX;
81 theViewportY = myLayerViewportY;
87 OpenGl_PrinterContext (GLCONTEXT theCtx);
90 virtual ~OpenGl_PrinterContext ();
92 //! Deactivate current printing context.
93 //! Useful when you need to redraw in usual mode the same OpenGl context
94 //! that you used for printing right after printing, before the
95 //! OpenGl_PrinterContext instance destroyed.
98 //! Set view projection transformation matrix for printing/tiling purposes
99 //! theProjTransform parameter should be an 4x4 array.
100 bool SetProjTransformation (TColStd_Array2OfReal& theProjTransform);
102 //! Set text scale factor
103 void SetScale (GLfloat theScaleX, GLfloat theScaleY)
105 myScaleX = theScaleX;
106 myScaleY = theScaleY;
109 //! Set layer viewport dimensions
110 void SetLayerViewport (GLsizei theViewportX,
111 GLsizei theViewportY)
113 myLayerViewportX = theViewportX;
114 myLayerViewportY = theViewportY;
119 static OpenGl_PrinterContext* g_PrinterContext;
120 static GLCONTEXT g_ContextId;
121 TColStd_Array2OfReal myProjTransform;
124 GLsizei myLayerViewportX;
125 GLsizei myLayerViewportY;
128 // the printer context could be created only in method call_togl_print
129 /*friend Standard_Boolean call_togl_print (CALL_DEF_VIEW *, CALL_DEF_LAYER *,
131 const Aspect_Drawable, const int,
132 const char*, const int, const float);*/
133 friend Standard_Boolean OpenGl_Workspace::Print (const Graphic3d_CView& ACView,
134 const Aspect_CLayer2d& ACUnderLayer,
135 const Aspect_CLayer2d& ACOverLayer,
136 const Aspect_Handle hPrintDC,
137 const Standard_Boolean showBackground,
138 const Standard_CString filename,
139 const Aspect_PrintAlgo printAlgorithm,
140 const Standard_Real theScaleFactor);