0024381: Visualization, TKOpenGl - revise matrices stack and usage of temporary matrices
[occt.git] / src / OpenGl / OpenGl_PrinterContext.cxx
1 // Created on: 2011-05-20
2 // Created by: Anton POLETAEV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <OpenGl_GlCore11.hxx>
17 #include <OpenGl_PrinterContext.hxx>
18
19 IMPLEMENT_STANDARD_HANDLE (OpenGl_PrinterContext, Standard_Transient)
20 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_PrinterContext, Standard_Transient)
21
22 //=======================================================================
23 //function : OpenGl_PrinterContext
24 //purpose  :
25 //=======================================================================
26 OpenGl_PrinterContext::OpenGl_PrinterContext()
27 : myProjTransform  (0, 3, 0, 3),
28   myScaleX (1.0f),
29   myScaleY (1.0f),
30   myLayerViewportX (0),
31   myLayerViewportY (0)
32
33 {
34   // identity projection matrix
35   Standard_Real anInitValue = 0.0;
36   myProjTransform.Init (anInitValue);
37   myProjTransform (0, 0)  = 1.0;
38   myProjTransform (1, 1)  = 1.0;
39   myProjTransform (2, 2)  = 1.0;
40   myProjTransform (3, 3)  = 1.0;
41   SetProjTransformation (myProjTransform);
42 }
43
44 // =======================================================================
45 // function : ~OpenGl_PrinterContext
46 // purpose  :
47 // =======================================================================
48 OpenGl_PrinterContext::~OpenGl_PrinterContext()
49 {
50   //
51 }
52
53 // =======================================================================
54 // function : ProjTransformation
55 // purpose  :
56 // =======================================================================
57 OpenGl_Mat4 OpenGl_PrinterContext::ProjTransformation()
58 {
59   return OpenGl_Mat4::Map (myProjMatrixGl);
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 bool OpenGl_PrinterContext::SetProjTransformation (const TColStd_Array2OfReal& thePrj)
68 {
69   if (thePrj.RowLength () != 4 || thePrj.ColLength () != 4)
70   {
71     return false;
72   }
73
74   myProjTransform = thePrj;
75   for (int i = 0, k = 0; i < 4; i++)
76   {
77     for (int j = 0; j < 4; j++, k++)
78     {
79       myProjMatrixGl[k] = (Standard_ShortReal )myProjTransform (i, j);
80     }
81   }
82   return true;
83 }
84
85 // =======================================================================
86 // function : SetScale
87 // purpose  :
88 // =======================================================================
89 void OpenGl_PrinterContext::SetScale (const Standard_ShortReal theScaleX,
90                                       const Standard_ShortReal theScaleY)
91 {
92   myScaleX = theScaleX;
93   myScaleY = theScaleY;
94 }
95
96 // =======================================================================
97 // function : SetLayerViewport
98 // purpose  :
99 // =======================================================================
100 void OpenGl_PrinterContext::SetLayerViewport (const Standard_Integer theViewportX,
101                                               const Standard_Integer theViewportY)
102 {
103   myLayerViewportX = theViewportX;
104   myLayerViewportY = theViewportY;
105 }