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 #include <OpenGl_PrinterContext.hxx>
23 OpenGl_PrinterContext* OpenGl_PrinterContext::g_PrinterContext = NULL;
24 GLCONTEXT OpenGl_PrinterContext::g_ContextId = NULL;
26 //=======================================================================
27 //function : OpenGl_PrinterContext
28 //purpose : Constructor
29 //=======================================================================
31 OpenGl_PrinterContext::OpenGl_PrinterContext (GLCONTEXT theCtx) :
32 myCtx (theCtx), myProjTransform (0, 3, 0, 3), myLayerViewportX (0),
33 myLayerViewportY (0), myScaleX (1.0f), myScaleY (1.0f)
35 // assign global instance to the current object
38 g_PrinterContext = this;
42 // init projection matrix
43 Standard_Real anInitValue = 0.0;
44 myProjTransform.Init (anInitValue);
45 myProjTransform (0,0) = 1.0f;
46 myProjTransform (1,1) = 1.0f;
47 myProjTransform (2,2) = 1.0f;
48 myProjTransform (3,3) = 1.0f;
51 //=======================================================================
52 //function : ~OpenGl_PrinterContext
53 //purpose : Destructor
54 //=======================================================================
56 OpenGl_PrinterContext::~OpenGl_PrinterContext ()
58 // unassign global instance
59 if (g_PrinterContext == this)
62 g_PrinterContext = NULL;
66 //=======================================================================
67 //function : GetProjTransformation
68 //purpose : Get view projection transformation matrix.
69 //=======================================================================
71 void OpenGl_PrinterContext::GetProjTransformation (GLfloat theMatrix[16])
73 for (int i = 0, k = 0; i < 4; i++)
74 for (int j = 0; j < 4; j++, k++)
75 theMatrix[k] = (GLfloat)myProjTransform (i,j);
78 //=======================================================================
79 //function : SetProjTransformation
80 //purpose : Set view projection transformation matrix for printing purposes.
81 // theProjTransform parameter should be an 4x4 array.
82 //=======================================================================
84 bool OpenGl_PrinterContext::SetProjTransformation (TColStd_Array2OfReal& thePrj)
86 if (thePrj.RowLength () != 4 || thePrj.ColLength () != 4)
89 myProjTransform = thePrj;
94 //=======================================================================
95 //function : Deactivate
96 //purpose : Deactivate PrinterContext object.
97 // Useful when you need to redraw in usual mode the same
98 // OpenGl context that you used for printing right after printing,
99 // before the OpenGl_PrinterContext instance destroyed
100 //=======================================================================
102 void OpenGl_PrinterContext::Deactivate ()
104 // unassign global instance
105 if (g_PrinterContext == this)
108 g_PrinterContext = NULL;
113 //=======================================================================
114 //function : GetInstance
115 //purpose : Get the PrinterContext instance assigned for OpenGl context.
116 // Return NULL, if there is no current printing operation and
117 // there is no assigned instance for "theCtx" OpenGl context.
118 //=======================================================================
120 OpenGl_PrinterContext* OpenGl_PrinterContext::GetPrinterContext (GLCONTEXT theCtx)
122 if (g_ContextId == theCtx)
123 return g_PrinterContext;