X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=blobdiff_plain;f=src%2FOpenGl%2FOpenGl_PrinterContext.cxx;h=189e1751b8166833106c56fd8c6b9a28e69ee114;hp=335984400170a68a326af7f9fae66205f40f267f;hb=00ea319b16d13f35bfc6f832ad5027d1a8283fdc;hpb=b311480ed597aed47b7bfbf01ddcebb41202bd53 diff --git a/src/OpenGl/OpenGl_PrinterContext.cxx b/src/OpenGl/OpenGl_PrinterContext.cxx index 3359844001..189e1751b8 100644 --- a/src/OpenGl/OpenGl_PrinterContext.cxx +++ b/src/OpenGl/OpenGl_PrinterContext.cxx @@ -1,126 +1,107 @@ // Created on: 2011-05-20 // Created by: Anton POLETAEV -// Copyright (c) 2011-2012 OPEN CASCADE SAS +// Copyright (c) 2011-2014 OPEN CASCADE SAS // -// The content of this file is subject to the Open CASCADE Technology Public -// License Version 6.5 (the "License"). You may not use the content of this file -// except in compliance with the License. Please obtain a copy of the License -// at http://www.opencascade.org and read it completely before using this file. +// This file is part of Open CASCADE Technology software library. // -// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its -// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. // -// The Original Code and all software distributed under the License is -// distributed on an "AS IS" basis, without warranty of any kind, and the -// Initial Developer hereby disclaims all such warranties, including without -// limitation, any warranties of merchantability, fitness for a particular -// purpose or non-infringement. Please see the License for the specific terms -// and conditions governing the rights and limitations under the License. - +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. +#include #include -OpenGl_PrinterContext* OpenGl_PrinterContext::g_PrinterContext = NULL; -GLCONTEXT OpenGl_PrinterContext::g_ContextId = NULL; +IMPLEMENT_STANDARD_HANDLE (OpenGl_PrinterContext, Standard_Transient) +IMPLEMENT_STANDARD_RTTIEXT(OpenGl_PrinterContext, Standard_Transient) //======================================================================= //function : OpenGl_PrinterContext -//purpose : Constructor +//purpose : //======================================================================= +OpenGl_PrinterContext::OpenGl_PrinterContext() +: myProjTransform (0, 3, 0, 3), + myScaleX (1.0f), + myScaleY (1.0f), + myLayerViewportX (0), + myLayerViewportY (0) -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 + // identity 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; + myProjTransform (0, 0) = 1.0; + myProjTransform (1, 1) = 1.0; + myProjTransform (2, 2) = 1.0; + myProjTransform (3, 3) = 1.0; + SetProjTransformation (myProjTransform); } -//======================================================================= -//function : ~OpenGl_PrinterContext -//purpose : Destructor -//======================================================================= - -OpenGl_PrinterContext::~OpenGl_PrinterContext () +// ======================================================================= +// function : ~OpenGl_PrinterContext +// purpose : +// ======================================================================= +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]) +// ======================================================================= +// function : LoadProjTransformation +// purpose : +// ======================================================================= +void OpenGl_PrinterContext::LoadProjTransformation() { - for (int i = 0, k = 0; i < 4; i++) - for (int j = 0; j < 4; j++, k++) - theMatrix[k] = (GLfloat)myProjTransform (i,j); +#if !defined(GL_ES_VERSION_2_0) + glLoadMatrixf ((GLfloat* )myProjMatrixGl); +#endif } -//======================================================================= -//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) +// ======================================================================= +// function : SetProjTransformation +// purpose : Set view projection transformation matrix for printing purposes. +// theProjTransform parameter should be an 4x4 array. +// ======================================================================= +bool OpenGl_PrinterContext::SetProjTransformation (const TColStd_Array2OfReal& thePrj) { if (thePrj.RowLength () != 4 || thePrj.ColLength () != 4) + { return false; + } myProjTransform = thePrj; - + for (int i = 0, k = 0; i < 4; i++) + { + for (int j = 0; j < 4; j++, k++) + { + myProjMatrixGl[k] = (Standard_ShortReal )myProjTransform (i, j); + } + } 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 () +// ======================================================================= +// function : SetScale +// purpose : +// ======================================================================= +void OpenGl_PrinterContext::SetScale (const Standard_ShortReal theScaleX, + const Standard_ShortReal theScaleY) { - // unassign global instance - if (g_PrinterContext == this) - { - g_ContextId = NULL; - g_PrinterContext = NULL; - } + myScaleX = theScaleX; + myScaleY = theScaleY; } - -//======================================================================= -//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) +// ======================================================================= +// function : SetLayerViewport +// purpose : +// ======================================================================= +void OpenGl_PrinterContext::SetLayerViewport (const Standard_Integer theViewportX, + const Standard_Integer theViewportY) { - if (g_ContextId == theCtx) - return g_PrinterContext; - else - return NULL; + myLayerViewportX = theViewportX; + myLayerViewportY = theViewportY; }