0024381: Visualization, TKOpenGl - revise matrices stack and usage of temporary matrices
[occt.git] / src / OpenGl / OpenGl_PrinterContext.cxx
CommitLineData
b311480e 1// Created on: 2011-05-20
2// Created by: Anton POLETAEV
973c2be1 3// Copyright (c) 2011-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
a174a3c5 16#include <OpenGl_GlCore11.hxx>
7edf74fd
A
17#include <OpenGl_PrinterContext.hxx>
18
a174a3c5 19IMPLEMENT_STANDARD_HANDLE (OpenGl_PrinterContext, Standard_Transient)
20IMPLEMENT_STANDARD_RTTIEXT(OpenGl_PrinterContext, Standard_Transient)
7edf74fd
A
21
22//=======================================================================
23//function : OpenGl_PrinterContext
a174a3c5 24//purpose :
7edf74fd 25//=======================================================================
a174a3c5 26OpenGl_PrinterContext::OpenGl_PrinterContext()
27: myProjTransform (0, 3, 0, 3),
a174a3c5 28 myScaleX (1.0f),
2f6cb3ac 29 myScaleY (1.0f),
30 myLayerViewportX (0),
31 myLayerViewportY (0)
ca3c13d1 32
7edf74fd 33{
a174a3c5 34 // identity projection matrix
7edf74fd
A
35 Standard_Real anInitValue = 0.0;
36 myProjTransform.Init (anInitValue);
a174a3c5 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);
7edf74fd
A
42}
43
a174a3c5 44// =======================================================================
45// function : ~OpenGl_PrinterContext
46// purpose :
47// =======================================================================
48OpenGl_PrinterContext::~OpenGl_PrinterContext()
7edf74fd 49{
a174a3c5 50 //
7edf74fd
A
51}
52
a174a3c5 53// =======================================================================
c827ea3a 54// function : ProjTransformation
a174a3c5 55// purpose :
56// =======================================================================
c827ea3a 57OpenGl_Mat4 OpenGl_PrinterContext::ProjTransformation()
7edf74fd 58{
c827ea3a 59 return OpenGl_Mat4::Map (myProjMatrixGl);
7edf74fd
A
60}
61
a174a3c5 62// =======================================================================
63// function : SetProjTransformation
64// purpose : Set view projection transformation matrix for printing purposes.
65// theProjTransform parameter should be an 4x4 array.
66// =======================================================================
67bool OpenGl_PrinterContext::SetProjTransformation (const TColStd_Array2OfReal& thePrj)
7edf74fd
A
68{
69 if (thePrj.RowLength () != 4 || thePrj.ColLength () != 4)
a174a3c5 70 {
7edf74fd 71 return false;
a174a3c5 72 }
7edf74fd
A
73
74 myProjTransform = thePrj;
a174a3c5 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 }
7edf74fd
A
82 return true;
83}
84
a174a3c5 85// =======================================================================
86// function : SetScale
87// purpose :
88// =======================================================================
89void OpenGl_PrinterContext::SetScale (const Standard_ShortReal theScaleX,
90 const Standard_ShortReal theScaleY)
7edf74fd 91{
a174a3c5 92 myScaleX = theScaleX;
93 myScaleY = theScaleY;
7edf74fd
A
94}
95
a174a3c5 96// =======================================================================
97// function : SetLayerViewport
98// purpose :
99// =======================================================================
100void OpenGl_PrinterContext::SetLayerViewport (const Standard_Integer theViewportX,
101 const Standard_Integer theViewportY)
7edf74fd 102{
a174a3c5 103 myLayerViewportX = theViewportX;
104 myLayerViewportY = theViewportY;
7edf74fd 105}