0022627: Change OCCT memory management defaults
[occt.git] / src / OpenGl / OpenGl_PrinterContext.cxx
CommitLineData
7edf74fd
A
1// File: OpenGl_PrinterContext.cxx
2// Created: 20.05.11 10:00:00
3// Author: Anton POLETAEV
4
5#include <OpenGl_PrinterContext.hxx>
6
7OpenGl_PrinterContext* OpenGl_PrinterContext::g_PrinterContext = NULL;
2166f0fa 8GLCONTEXT OpenGl_PrinterContext::g_ContextId = NULL;
7edf74fd
A
9
10//=======================================================================
11//function : OpenGl_PrinterContext
12//purpose : Constructor
13//=======================================================================
14
15OpenGl_PrinterContext::OpenGl_PrinterContext (GLCONTEXT theCtx) :
16 myCtx (theCtx), myProjTransform (0, 3, 0, 3), myLayerViewportX (0),
17 myLayerViewportY (0), myScaleX (1.0f), myScaleY (1.0f)
18{
19 // assign global instance to the current object
20 if (myCtx != NULL)
21 {
22 g_PrinterContext = this;
23 g_ContextId = myCtx;
24 }
25
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;
33}
34
35//=======================================================================
36//function : ~OpenGl_PrinterContext
37//purpose : Destructor
38//=======================================================================
39
40OpenGl_PrinterContext::~OpenGl_PrinterContext ()
41{
42 // unassign global instance
43 if (g_PrinterContext == this)
44 {
45 g_ContextId = NULL;
46 g_PrinterContext = NULL;
47 }
48}
49
50//=======================================================================
51//function : GetProjTransformation
52//purpose : Get view projection transformation matrix.
53//=======================================================================
54
55void OpenGl_PrinterContext::GetProjTransformation (GLfloat theMatrix[16])
56{
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);
60}
61
62//=======================================================================
63//function : SetProjTransformation
64//purpose : Set view projection transformation matrix for printing purposes.
65// theProjTransform parameter should be an 4x4 array.
66//=======================================================================
67
68bool OpenGl_PrinterContext::SetProjTransformation (TColStd_Array2OfReal& thePrj)
69{
70 if (thePrj.RowLength () != 4 || thePrj.ColLength () != 4)
71 return false;
72
73 myProjTransform = thePrj;
74
75 return true;
76}
77
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//=======================================================================
85
86void OpenGl_PrinterContext::Deactivate ()
87{
88 // unassign global instance
89 if (g_PrinterContext == this)
90 {
91 g_ContextId = NULL;
92 g_PrinterContext = NULL;
93 }
94}
95
96
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//=======================================================================
103
104OpenGl_PrinterContext* OpenGl_PrinterContext::GetPrinterContext (GLCONTEXT theCtx)
105{
106 if (g_ContextId == theCtx)
107 return g_PrinterContext;
108 else
109 return NULL;
110}