1 // File: OpenGl_PrinterContext.cxx
2 // Created: 20.05.11 10:00:00
3 // Author: Anton POLETAEV
5 #include <OpenGl_PrinterContext.hxx>
7 OpenGl_PrinterContext* OpenGl_PrinterContext::g_PrinterContext = NULL;
8 GLCONTEXT OpenGl_PrinterContext::g_ContextId = NULL;
10 //=======================================================================
11 //function : OpenGl_PrinterContext
12 //purpose : Constructor
13 //=======================================================================
15 OpenGl_PrinterContext::OpenGl_PrinterContext (GLCONTEXT theCtx) :
16 myCtx (theCtx), myProjTransform (0, 3, 0, 3), myLayerViewportX (0),
17 myLayerViewportY (0), myScaleX (1.0f), myScaleY (1.0f)
19 // assign global instance to the current object
22 g_PrinterContext = this;
26 // init projection matrix
27 Standard_Real anInitValue = 0.0;
28 myProjTransform.Init (anInitValue);
29 myProjTransform (0,0) = 1.0f;
30 myProjTransform (1,1) = 1.0f;
31 myProjTransform (2,2) = 1.0f;
32 myProjTransform (3,3) = 1.0f;
35 //=======================================================================
36 //function : ~OpenGl_PrinterContext
37 //purpose : Destructor
38 //=======================================================================
40 OpenGl_PrinterContext::~OpenGl_PrinterContext ()
42 // unassign global instance
43 if (g_PrinterContext == this)
46 g_PrinterContext = NULL;
50 //=======================================================================
51 //function : GetProjTransformation
52 //purpose : Get view projection transformation matrix.
53 //=======================================================================
55 void OpenGl_PrinterContext::GetProjTransformation (GLfloat theMatrix[16])
57 for (int i = 0, k = 0; i < 4; i++)
58 for (int j = 0; j < 4; j++, k++)
59 theMatrix[k] = (GLfloat)myProjTransform (i,j);
62 //=======================================================================
63 //function : SetProjTransformation
64 //purpose : Set view projection transformation matrix for printing purposes.
65 // theProjTransform parameter should be an 4x4 array.
66 //=======================================================================
68 bool OpenGl_PrinterContext::SetProjTransformation (TColStd_Array2OfReal& thePrj)
70 if (thePrj.RowLength () != 4 || thePrj.ColLength () != 4)
73 myProjTransform = thePrj;
78 //=======================================================================
79 //function : Deactivate
80 //purpose : Deactivate PrinterContext object.
81 // Useful when you need to redraw in usual mode the same
82 // OpenGl context that you used for printing right after printing,
83 // before the OpenGl_PrinterContext instance destroyed
84 //=======================================================================
86 void OpenGl_PrinterContext::Deactivate ()
88 // unassign global instance
89 if (g_PrinterContext == this)
92 g_PrinterContext = NULL;
97 //=======================================================================
98 //function : GetInstance
99 //purpose : Get the PrinterContext instance assigned for OpenGl context.
100 // Return NULL, if there is no current printing operation and
101 // there is no assigned instance for "theCtx" OpenGl context.
102 //=======================================================================
104 OpenGl_PrinterContext* OpenGl_PrinterContext::GetPrinterContext (GLCONTEXT theCtx)
106 if (g_ContextId == theCtx)
107 return g_PrinterContext;