summaryrefslogtreecommitdiff
path: root/src/OpenGl/OpenGl_PrinterContext.cxx
blob: 4e3d4b2a9cc9815c9b6b5c24899f7865f313e9b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// File:      OpenGl_PrinterContext.cxx
// Created:   20.05.11 10:00:00
// Author:    Anton POLETAEV

#include <OpenGl_PrinterContext.hxx>

OpenGl_PrinterContext* OpenGl_PrinterContext::g_PrinterContext = NULL;
GLCONTEXT              OpenGl_PrinterContext::g_ContextId      = NULL;

//=======================================================================
//function : OpenGl_PrinterContext
//purpose  : Constructor
//=======================================================================

OpenGl_PrinterContext::OpenGl_PrinterContext (GLCONTEXT theCtx) :
  myCtx (theCtx), myProjTransform (0, 3, 0, 3), myLayerViewportX (0),
  myLayerViewportY (0), myScaleX (1.0f), myScaleY (1.0f)
{
  // assign global instance to the current object
  if (myCtx != NULL)
  {
    g_PrinterContext = this;
    g_ContextId      = myCtx;
  }

  // init projection matrix
  Standard_Real anInitValue = 0.0;
  myProjTransform.Init (anInitValue);
  myProjTransform (0,0)  = 1.0f;
  myProjTransform (1,1)  = 1.0f;
  myProjTransform (2,2)  = 1.0f;
  myProjTransform (3,3)  = 1.0f;
}

//=======================================================================
//function : ~OpenGl_PrinterContext
//purpose  : Destructor
//=======================================================================

OpenGl_PrinterContext::~OpenGl_PrinterContext () 
{
  // unassign global instance
  if (g_PrinterContext == this)
  {
    g_ContextId      = NULL;
    g_PrinterContext = NULL;
  }
}

//=======================================================================
//function : GetProjTransformation
//purpose  : Get view projection transformation matrix.
//=======================================================================

void OpenGl_PrinterContext::GetProjTransformation (GLfloat theMatrix[16])
{
  for (int i = 0, k = 0; i < 4; i++)
    for (int j = 0; j < 4; j++, k++)
      theMatrix[k] = (GLfloat)myProjTransform (i,j);
}

//=======================================================================
//function : SetProjTransformation
//purpose  : Set view projection transformation matrix for printing purposes.
//           theProjTransform parameter should be an 4x4 array.
//=======================================================================

bool OpenGl_PrinterContext::SetProjTransformation (TColStd_Array2OfReal& thePrj)
{
  if (thePrj.RowLength () != 4 || thePrj.ColLength () != 4)
    return false;

  myProjTransform = thePrj;

  return true;
}

//=======================================================================
//function : Deactivate
//purpose  : Deactivate PrinterContext object.
//           Useful when you need to redraw in usual mode the same
//           OpenGl context that you used for printing right after printing,
//           before the OpenGl_PrinterContext instance destroyed
//=======================================================================

void OpenGl_PrinterContext::Deactivate ()
{
  // unassign global instance
  if (g_PrinterContext == this)
  {
    g_ContextId      = NULL;
    g_PrinterContext = NULL;
  }
}


//=======================================================================
//function : GetInstance
//purpose  : Get the PrinterContext instance assigned for OpenGl context.
//           Return NULL, if there is no current printing operation and
//           there is no assigned instance for "theCtx" OpenGl context.
//=======================================================================

OpenGl_PrinterContext* OpenGl_PrinterContext::GetPrinterContext (GLCONTEXT theCtx)
{
  if (g_ContextId == theCtx)
    return g_PrinterContext;
  else
    return NULL;
}