1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-03 17:56:21 +03:00

0027763: Visualization - remove V3d_View::Print() method

Dependency from FreeImagePlus.dll (but not FreeImage.dll) has been removed.

Method V3d_View::Export() has been marked as deprecated.

Added Standard_DISABLE_DEPRECATION_WARNINGS and Standard_ENABLE_DEPRECATION_WARNINGS
to eliminate compiler warnings for using deprecated APIs within Draw Harness for testing.

compatibility with gcc 4.5-
This commit is contained in:
kgv 2016-08-10 23:32:50 +03:00 committed by bugmaster
parent 3a17b16845
commit 60273f7774
30 changed files with 92 additions and 1622 deletions

View File

@ -473,29 +473,23 @@ endif()
# FREEIMAGE
# search for CSF_FREEIMAGE variable in EXTERNLIB of each being used toolkit
OCCT_IS_PRODUCT_REQUIRED (CSF_FREEIMAGE CAN_USE_FREEIMAGE)
OCCT_IS_PRODUCT_REQUIRED (CSF_FreeImagePlus CAN_USE_FREEIMAGEPLUS)
OCCT_IS_PRODUCT_REQUIRED (CSF_FreeImagePlus CAN_USE_FREEIMAGE)
if (CAN_USE_FREEIMAGE OR CAN_USE_FREEIMAGEPLUS)
if (CAN_USE_FREEIMAGE)
set (USE_FREEIMAGE OFF CACHE BOOL "${USE_FREEIMAGE_DESCR}")
if (USE_FREEIMAGE)
add_definitions (-DHAVE_FREEIMAGE)
OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/freeimage")
OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/freeimageplus")
else()
OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_FREEIMAGE")
OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_FREEIMAGEPLUS")
OCCT_CHECK_AND_UNSET ("INSTALL_FREEIMAGE")
OCCT_CHECK_AND_UNSET ("INSTALL_FREEIMAGEPLUS")
endif()
else()
OCCT_CHECK_AND_UNSET ("USE_FREEIMAGE")
OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_FREEIMAGE")
OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_FREEIMAGEPLUS")
OCCT_CHECK_AND_UNSET ("INSTALL_FREEIMAGE")
OCCT_CHECK_AND_UNSET ("INSTALL_FREEIMAGEPLUS")
endif()
# GL2PS

View File

@ -1,9 +0,0 @@
#freeimageplus
if (WIN32)
if (3RDPARTY_FREEIMAGE_DIR AND NOT 3RDPARTY_FREEIMAGEPLUS_DIR)
set (3RDPARTY_FREEIMAGEPLUS_DIR "${3RDPARTY_FREEIMAGE_DIR}" CACHE PATH "The directory containing freeimageplus" FORCE)
endif()
THIRDPARTY_PRODUCT("FREEIMAGEPLUS" "FreeImagePlus.h" "freeimageplus" "freeimageplusd")
endif()

View File

@ -51,7 +51,7 @@ if (WIN32)
endif()
if (USE_FREEIMAGE)
set (CSF_FreeImagePlus "freeimage.lib freeimageplus.lib")
set (CSF_FreeImagePlus "freeimage.lib")
else()
set (CSF_FreeImagePlus)
endif()

View File

@ -72,7 +72,6 @@ INSTALL_MESSAGE (INSTALL_SAMPLES "OCCT samples")
INSTALL_MESSAGE (INSTALL_TEST_CASES "non-regression OCCT test scripts")
INSTALL_MESSAGE (INSTALL_DOC_Overview "OCCT overview documentation (HTML format)")
INSTALL_MESSAGE (INSTALL_FREEIMAGE "FreeImage binaries")
INSTALL_MESSAGE (INSTALL_FREEIMAGEPLUS "FreeImagePlus binaries")
INSTALL_MESSAGE (INSTALL_FREETYPE "FreeType binaries")
INSTALL_MESSAGE (INSTALL_GL2PS "GL2PS binaries")
INSTALL_MESSAGE (INSTALL_TBB "TBB binaries")

View File

@ -430,7 +430,6 @@ proc wokdep:SearchFreeImage {theErrInc theErrLib32 theErrLib64 theErrBin32 theEr
# binary distribution has another layout
set aFImageDist "Dist"
set aFImagePlusDist "Wrapper/FreeImagePlus/dist"
set isFound "true"
set aFImageHPath [wokdep:SearchHeader "FreeImage.h"]
@ -440,21 +439,12 @@ proc wokdep:SearchFreeImage {theErrInc theErrLib32 theErrLib64 theErrBin32 theEr
lappend ::CSF_OPT_INC "$aPath/include"
} elseif { "$aPath" != "" && [file exists "$aPath/$aFImageDist/FreeImage.h"] } {
lappend ::CSF_OPT_INC "$aPath/$aFImageDist"
if { [file exists "$aPath/$aFImagePlusDist/FreeImagePlus.h"] } {
lappend ::CSF_OPT_INC "$aPath/$aFImagePlusDist"
}
} else {
lappend anErrInc "Error: 'FreeImage.h' not found (FreeImage)"
set isFound "false"
}
}
set aFImagePlusHPath [wokdep:SearchHeader "FreeImagePlus.h"]
if { "$::tcl_platform(platform)" == "windows" && "$aFImagePlusHPath" == "" } {
lappend anErrInc "Error: 'FreeImagePlus.h' not found (FreeImage)"
set isFound "false"
}
foreach anArchIter {64 32} {
set aFImageLibPath [wokdep:SearchLib "freeimage" "$anArchIter"]
if { "$aFImageLibPath" == "" } {
@ -466,10 +456,6 @@ proc wokdep:SearchFreeImage {theErrInc theErrLib32 theErrLib64 theErrBin32 theEr
set aFImageLibPath [wokdep:SearchLib "freeimage" "$anArchIter" "$aPath/$aFImageDist"]
if { "$aFImageLibPath" != "" } {
lappend ::CSF_OPT_LIB$anArchIter "$aPath/$aFImageDist"
set aFImagePlusLibPath [wokdep:SearchLib "freeimageplus" "$anArchIter" "$aPath/$aFImagePlusDist"]
if { "$aFImagePlusLibPath" != "" } {
lappend ::CSF_OPT_LIB$anArchIter "$aPath/$aFImagePlusDist"
}
} else {
lappend anErrLib$anArchIter "Error: '${::SYS_LIB_PREFIX}freeimage.${::SYS_LIB_SUFFIX}' not found (FreeImage)"
if { "$::ARCH" == "$anArchIter"} { set isFound "false" }
@ -477,28 +463,18 @@ proc wokdep:SearchFreeImage {theErrInc theErrLib32 theErrLib64 theErrBin32 theEr
}
}
if { "$::tcl_platform(platform)" == "windows" } {
set aFImagePlusLibPath [wokdep:SearchLib "freeimageplus" "$anArchIter"]
if { "$aFImagePlusLibPath" == "" } {
lappend anErrLib$anArchIter "Error: '${::SYS_LIB_PREFIX}freeimageplus.${::SYS_LIB_SUFFIX}' not found (FreeImage)"
if { "$::ARCH" == "$anArchIter"} { set isFound "false" }
}
set aFImageDllPath [wokdep:SearchBin "freeimage.dll" "$anArchIter"]
set aFImagePlusDllPath [wokdep:SearchBin "freeimageplus.dll" "$anArchIter"]
if { "$aFImageDllPath" == "" || "$aFImagePlusDllPath" == "" } {
set aFImageDllPath [wokdep:SearchBin "freeimage.dll" "$anArchIter"]
if { "$aFImageDllPath" == "" } {
set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{freeimage}*] "$::VCVER" "$anArchIter" ]
set aFImageDllPath [wokdep:SearchBin "freeimage.dll" "$anArchIter" "$aPath/bin"]
set aFImagePlusDllPath [wokdep:SearchBin "freeimageplus.dll" "$anArchIter" "$aPath/bin"]
if { "$aFImageDllPath" != "" && "$aFImagePlusDllPath" != "" } {
set aFImageDllPath [wokdep:SearchBin "freeimage.dll" "$anArchIter" "$aPath/bin"]
if { "$aFImageDllPath" != "" } {
lappend ::CSF_OPT_BIN$anArchIter "$aPath/bin"
} else {
set aFImageDllPath [wokdep:SearchBin "freeimage.dll" "$anArchIter" "$aPath/$aFImageDist"]
set aFImagePlusDllPath [wokdep:SearchBin "freeimageplus.dll" "$anArchIter" "$aPath/$aFImagePlusDist"]
if { "$aFImageDllPath" != "" && "$aFImagePlusDllPath" != "" } {
set aFImageDllPath [wokdep:SearchBin "freeimage.dll" "$anArchIter" "$aPath/$aFImageDist"]
if { "$aFImageDllPath" != "" } {
lappend ::CSF_OPT_BIN$anArchIter "$aPath/$aFImageDist"
lappend ::CSF_OPT_BIN$anArchIter "$aPath/$aFImagePlusDist"
} else {
lappend anErrBin$anArchIter "Error: 'freeimage.dll' or 'freeimageplus.dll' not found (FreeImage)"
lappend anErrBin$anArchIter "Error: 'freeimage.dll' is not found (FreeImage)"
if { "$::ARCH" == "$anArchIter"} { set isFound "false" }
}
}

View File

@ -1076,7 +1076,7 @@ proc osutils:csfList { theOS theCsfLibsMap theCsfFrmsMap } {
set aLibsMap(CSF_TclTkLibs) "tk8.6"
if { "$::HAVE_FREEIMAGE" == "true" } {
if { "$theOS" == "wnt" } {
set aLibsMap(CSF_FreeImagePlus) "FreeImage FreeImagePlus"
set aLibsMap(CSF_FreeImagePlus) "FreeImage"
} else {
set aLibsMap(CSF_FreeImagePlus) "freeimage"
}

View File

@ -6,7 +6,6 @@ if /I "%VCVER%" == "@COMPILER@" (
set "TK_DIR=@3RDPARTY_TK_DLL_DIR@"
set "FREETYPE_DIR=@3RDPARTY_FREETYPE_DLL_DIR@"
set "FREEIMAGE_DIR=@3RDPARTY_FREEIMAGE_DLL_DIR@"
set "FREEIMAGEPLUS_DIR=@3RDPARTY_FREEIMAGEPLUS_DLL_DIR@"
set "GL2PS_DIR=@3RDPARTY_GL2PS_DLL_DIR@"
set "TBB_DIR=@3RDPARTY_TBB_DLL_DIR@"
set "VTK_DIR=@3RDPARTY_VTK_DLL_DIR@"

View File

@ -8,7 +8,6 @@ if /I "%VCVER%" == "@COMPILER@" (
set "TK_DIR=@USED_3RDPARTY_TK_DIR@"
set "FREETYPE_DIR=@USED_3RDPARTY_FREETYPE_DIR@"
set "FREEIMAGE_DIR=@USED_3RDPARTY_FREEIMAGE_DIR@"
set "FREEIMAGEPLUS_DIR=@USED_3RDPARTY_FREEIMAGEPLUS_DIR@"
set "GL2PS_DIR=@USED_3RDPARTY_GL2PS_DIR@"
set "TBB_DIR=@USED_3RDPARTY_TBB_DIR@"
set "VTK_DIR=@USED_3RDPARTY_VTK_DIR@"

View File

@ -29,7 +29,6 @@ if not ["%TCL_DIR%"] == [""] set "PATH=%TCL_DIR%;%PATH%"
if not ["%TK_DIR%"] == [""] set "PATH=%TK_DIR%;%PATH%"
if not ["%FREETYPE_DIR%"] == [""] set "PATH=%FREETYPE_DIR%;%PATH%"
if not ["%FREEIMAGE_DIR%"] == [""] set "PATH=%FREEIMAGE_DIR%;%PATH%"
if not ["%FREEIMAGEPLUS_DIR%"] == [""] set "PATH=%FREEIMAGEPLUS_DIR%;%PATH%"
if not ["%GL2PS_DIR%"] == [""] set "PATH=%GL2PS_DIR%;%PATH%"
if not ["%TBB_DIR%"] == [""] set "PATH=%TBB_DIR%;%PATH%"
if not ["%VTK_DIR%"] == [""] set "PATH=%VTK_DIR%;%PATH%"

View File

@ -1021,12 +1021,25 @@ The following type definitions in OCCT has been modified to use C++11 types:
For most applications this change should be transparent, since the size of types have not been changed.
@subsection upgrade_710_ffp Programmable Pipeline
Fixed-function pipeline has been already deprecated since OCCT 7.0.0.
Release 7.1.0 disables this functionality by default in favor of Programmable Pipeline (based on GLSL programs).
This also means that method *V3d_View::Export()* based on gl2ps library and requiring disabled by default functionality has been deprecated as well.
Applications should explicitly enable deprecated functionality by setting OpenGl_Caps::ffpEnable flag to TRUE within OpenGl_GraphicDriver::ChangeOptions() before creating the viewer to use V3d_View::Export(),
but being aware that this functionality is likely to be removed in a next OCCT release.
Thus the recommended way to generate vector image of a 3D model or scene is to use application-level solution independent from OpenGL.
@subsection upgrade_710_removed Removed features
The following obsolete features have been removed:
* Obsolete Antialiasing API V3d_View::SetAntialiasingOn(). This method was intended to activate deprecated OpenGL functionality (GL_POLYGON_SMOOTH, GL_LINE_SMOOTH, GL_POINT_SMOOTH).
Instead of old API, application should request MSAA buffers for antialiasing by assigning Graphic3d_RenderingParams::NbMsaaSamples property of structure returned by V3d_View::ChangeRenderingParams().
* Prs3d_Drawer::ShadingAspectGlobal() flag has been removed as not used. Corresponding calls can be removed safely from the application code.
* ZClipping planes and ZCueing (methods V3d_View::SetZClippingType(), ::SetZCueingOn() and V3d_View::others).
* Obsolete Antialiasing API *V3d_View::SetAntialiasingOn()*. This method was intended to activate deprecated OpenGL functionality (GL_POLYGON_SMOOTH, GL_LINE_SMOOTH, GL_POINT_SMOOTH).
Instead of old API, application should request MSAA buffers for antialiasing by assigning *Graphic3d_RenderingParams::NbMsaaSamples* property of structure returned by *V3d_View::ChangeRenderingParams()*.
* *Prs3d_Drawer::ShadingAspectGlobal()* flag has been removed as not used. Corresponding calls can be removed safely from the application code.
* ZClipping planes and ZCueing (methods *V3d_View::SetZClippingType()*, *::SetZCueingOn()* and V3d_View::others).
ZClipping planes can be replaced by general-purpose clipping planes (application should update plane definion manually).
* 3D viewer printing API *V3d_View::Print()* has been removed. This functionality was available on Windows platforms only.
Applications should use general image dump API *V3d_View::ToPixMap()* and manage printing using platform-specific API at application level.
Text resolution can be managed by rendering parameter *Graphic3d_RenderingParams::Resolution*, returned by *V3d_View::ChangeRenderingParams()*.

View File

@ -1,43 +0,0 @@
// Created by: NW,JPB,CAL
// Copyright (c) 1991-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _Aspect_PrintAlgo_HeaderFile
#define _Aspect_PrintAlgo_HeaderFile
//! Defines print algorithm
//! Aspect_PrintAlgo:
//! 1) PA_STRETCH - Stretch offscreen printing frame
//! if its dimensions are smaller than
//! the printer's printing area dimensions;
//! This algorithm is more reliable as it
//! works on any hardware and is recommended
//! to be used with average printing resolutions,
//! as it more RAM memory dependent than PA_TILE;
//! Stretching is performend using bicubic interpolation
//! algorithm from FreeImage library if OCCT is built
//! with FreeImage support, otherwise Windows API
//! StretchBlt() function in STRETCH_HALFTONE mode
//! is used;
//! 2) PA_TILE - If the offscreen printing frame dimensions
//! are smaller than the printer's printing
//! area dimensions - use multiple printing
//! frames to cover the whole printing area
enum Aspect_PrintAlgo
{
Aspect_PA_STRETCH,
Aspect_PA_TILE
};
#endif // _Aspect_PrintAlgo_HeaderFile

View File

@ -30,7 +30,6 @@ Aspect_HatchStyle.hxx
Aspect_IdentDefinitionError.hxx
Aspect_InteriorStyle.hxx
Aspect_PolygonOffsetMode.hxx
Aspect_PrintAlgo.hxx
Aspect_RectangularGrid.cxx
Aspect_RectangularGrid.hxx
Aspect_RenderingContext.hxx

View File

@ -15,7 +15,6 @@
#define _Graphic3d_CView_HeaderFile
#include <Aspect_Handle.hxx>
#include <Aspect_PrintAlgo.hxx>
#include <Aspect_RenderingContext.hxx>
#include <Aspect_TypeOfTriedronEcho.hxx>
#include <Aspect_TypeOfTriedronPosition.hxx>
@ -297,27 +296,6 @@ public:
//! Dump active rendering buffer into specified memory buffer.
virtual Standard_Boolean BufferDump (Image_PixMap& theImage, const Graphic3d_BufferType& theBufferType) = 0;
//! Print the contents of the view to the printer.
//! @param thePrinterDC pass the PrinterDeviceContext (HDC)
//! @param theToShowBackground when set to FALSE then print the view without background
//! color (background is white) else set to TRUE for printing
//! with current background color
//! @param theFileName if != NULL, then the view will be printed to a file
//! @param thePrintAlgorithm select print algorithm: stretch, tile
//! @param theScaleFactor scaling coefficient, used internally to scale the printings
//! accordingly to the scale factor selected in the printer properties dialog
//! @return Standard_True if the data is passed to the printer, otherwise Standard_False if
//! the print operation failed due to the printer errors, or lack of system memory. This might be related
//! to insufficient memory or some internal errors.
//! All this errors are indicated by the message boxes (on level of OpenGl_GraphicDriver).
//! Warning: This function can reuse FBO assigned to the view, please take it into account
//! if you use it for your purposes.
virtual Standard_Boolean Print (const Aspect_Handle thePrinterDC,
const Standard_Boolean theToShowBackground,
const Standard_CString theFileName,
const Aspect_PrintAlgo thePrintAlgorithm = Aspect_PA_STRETCH,
const Standard_Real theScaleFactor = 1.0) = 0;
//! Export scene into the one of the Vector graphics formats (SVG, PS, PDF...).
//! In contrast to Bitmaps, Vector graphics is scalable (so you may got quality benefits
//! on printing to laser printer). Notice however that results may differ a lot and

View File

@ -41,7 +41,6 @@
#include <Graphic3d_BufferType.hxx>
#include <Aspect_GenId.hxx>
#include <Aspect_Handle.hxx>
#include <Aspect_PrintAlgo.hxx>
#include <Graphic3d_ExportFormat.hxx>
#include <Graphic3d_SortType.hxx>
#include <Graphic3d_ZLayerId.hxx>

View File

@ -30,7 +30,6 @@ OpenGl_Workspace.hxx
OpenGl_Workspace.cxx
OpenGl_View.hxx
OpenGl_View.cxx
OpenGl_View_Print.cxx
OpenGl_View_Raytrace.cxx
OpenGl_View_Redraw.cxx
OpenGl_Light.hxx
@ -43,8 +42,6 @@ OpenGl_Matrix.hxx
OpenGl_MatrixState.hxx
OpenGl_NamedStatus.hxx
OpenGl_TextParam.hxx
OpenGl_PrinterContext.hxx
OpenGl_PrinterContext.cxx
OpenGl_LineAttributes.hxx
OpenGl_LineAttributes.cxx
OpenGl_Window.hxx

View File

@ -25,7 +25,6 @@
#include <Aspect_TypeOfTriedronPosition.hxx>
#include <Aspect_TypeOfTriedronEcho.hxx>
#include <Aspect_Handle.hxx>
#include <Aspect_PrintAlgo.hxx>
#include <Aspect_RenderingContext.hxx>
#include <gp_Ax2.hxx>
#include <Graphic3d_CView.hxx>

View File

@ -1,105 +0,0 @@
// Created on: 2011-05-20
// Created by: Anton POLETAEV
// Copyright (c) 2011-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <OpenGl_GlCore11.hxx>
#include <OpenGl_PrinterContext.hxx>
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_PrinterContext,Standard_Transient)
//=======================================================================
//function : OpenGl_PrinterContext
//purpose :
//=======================================================================
OpenGl_PrinterContext::OpenGl_PrinterContext()
: myProjTransform (0, 3, 0, 3),
myScaleX (1.0f),
myScaleY (1.0f),
myLayerViewportX (0),
myLayerViewportY (0)
{
// identity projection matrix
Standard_Real anInitValue = 0.0;
myProjTransform.Init (anInitValue);
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 :
// =======================================================================
OpenGl_PrinterContext::~OpenGl_PrinterContext()
{
//
}
// =======================================================================
// function : ProjTransformation
// purpose :
// =======================================================================
OpenGl_Mat4 OpenGl_PrinterContext::ProjTransformation()
{
return OpenGl_Mat4::Map (myProjMatrixGl);
}
// =======================================================================
// 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 : SetScale
// purpose :
// =======================================================================
void OpenGl_PrinterContext::SetScale (const Standard_ShortReal theScaleX,
const Standard_ShortReal theScaleY)
{
myScaleX = theScaleX;
myScaleY = theScaleY;
}
// =======================================================================
// function : SetLayerViewport
// purpose :
// =======================================================================
void OpenGl_PrinterContext::SetLayerViewport (const Standard_Integer theViewportX,
const Standard_Integer theViewportY)
{
myLayerViewportX = theViewportX;
myLayerViewportY = theViewportY;
}

View File

@ -1,91 +0,0 @@
// Created on: 2011-05-20
// Created by: Anton POLETAEV
// Copyright (c) 2011-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _OPENGL_PRINTERCONTEXT_H
#define _OPENGL_PRINTERCONTEXT_H
#include <Standard_Type.hxx>
#include <TColStd_Array2OfReal.hxx>
#include <OpenGl_Vec.hxx>
//! Class provides specific information for redrawing view to offscreen buffer
//! on printing. The information is: projection matrixes for tiling,
//! scaling factors for text/markers and layer viewport dimensions.
class OpenGl_PrinterContext : public Standard_Transient
{
public:
//! Constructor
OpenGl_PrinterContext();
//! Destructor
virtual ~OpenGl_PrinterContext();
//! Get view projection transformation matrix.
inline const TColStd_Array2OfReal& GetProjTransformation() const
{
return myProjTransform;
}
//! Set view projection transformation matrix for printing/tiling purposes
//! theProjTransform parameter should be an 4x4 array.
bool SetProjTransformation (const TColStd_Array2OfReal& theProjTransform);
//! Returns projection matrix.
OpenGl_Mat4 ProjTransformation();
//! Get text/markers scale factor
inline void GetScale (Standard_ShortReal& theScaleX,
Standard_ShortReal& theScaleY) const
{
theScaleX = myScaleX;
theScaleY = myScaleY;
}
//! Set text scale factor
void SetScale (const Standard_ShortReal theScaleX,
const Standard_ShortReal theScaleY);
//! Get layer viewport dimensions
inline void GetLayerViewport (Standard_Integer& theViewportX,
Standard_Integer& theViewportY) const
{
theViewportX = myLayerViewportX;
theViewportY = myLayerViewportY;
}
//! Set layer viewport dimensions
void SetLayerViewport (const Standard_Integer theViewportX,
const Standard_Integer theViewportY);
private:
TColStd_Array2OfReal myProjTransform;
Standard_ShortReal myProjMatrixGl[16];
Standard_ShortReal myScaleX;
Standard_ShortReal myScaleY;
Standard_Integer myLayerViewportX;
Standard_Integer myLayerViewportY;
public:
DEFINE_STANDARD_RTTIEXT(OpenGl_PrinterContext,Standard_Transient) // Type definition
};
DEFINE_STANDARD_HANDLE(OpenGl_PrinterContext, Standard_Transient)
#endif

View File

@ -429,8 +429,7 @@ void OpenGl_Text::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
myProjMatrix.Convert (aCtx->ProjectionState.Current());
// use highlight color or colors from aspect
render (theWorkspace->PrinterContext(),
aCtx,
render (aCtx,
*aTextAspect,
theWorkspace->TextColor(),
theWorkspace->TextSubtitleColor(),
@ -459,12 +458,11 @@ void OpenGl_Text::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
// function : Render
// purpose :
// =======================================================================
void OpenGl_Text::Render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
const Handle(OpenGl_Context)& theCtx,
const OpenGl_AspectText& theTextAspect,
const unsigned int theResolution) const
void OpenGl_Text::Render (const Handle(OpenGl_Context)& theCtx,
const OpenGl_AspectText& theTextAspect,
const unsigned int theResolution) const
{
render (thePrintCtx, theCtx, theTextAspect,
render (theCtx, theTextAspect,
theTextAspect.Aspect()->ColorRGBA(),
theTextAspect.Aspect()->ColorSubTitleRGBA(),
theResolution);
@ -474,10 +472,9 @@ void OpenGl_Text::Render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
// function : setupMatrix
// purpose :
// =======================================================================
void OpenGl_Text::setupMatrix (const Handle(OpenGl_PrinterContext)& thePrintCtx,
const Handle(OpenGl_Context)& theCtx,
const OpenGl_AspectText& theTextAspect,
const OpenGl_Vec3 theDVec) const
void OpenGl_Text::setupMatrix (const Handle(OpenGl_Context)& theCtx,
const OpenGl_AspectText& theTextAspect,
const OpenGl_Vec3 theDVec) const
{
OpenGl_Mat4d aModViewMat;
OpenGl_Mat4d aProjectMat;
@ -541,22 +538,6 @@ void OpenGl_Text::setupMatrix (const Handle(OpenGl_PrinterContext)& thePrintCtx,
if (!theTextAspect.Aspect()->GetTextZoomable())
{
#ifdef _WIN32
// if the context has assigned printer context, use it's parameters
if (!thePrintCtx.IsNull())
{
// get printing scaling in x and y dimensions
GLfloat aTextScalex = 1.0f, aTextScaley = 1.0f;
thePrintCtx->GetScale (aTextScalex, aTextScaley);
// text should be scaled in all directions with same
// factor to save its proportions, so use height (y) scaling
// as it is better for keeping text/3d graphics proportions
Graphic3d_TransformUtils::Scale<GLdouble> (aModViewMat, aTextScaley, aTextScaley, aTextScaley);
}
#else
(void )thePrintCtx;
#endif
Graphic3d_TransformUtils::Scale<GLdouble> (aModViewMat, myScaleHeight, myScaleHeight, myScaleHeight);
}
}
@ -590,14 +571,8 @@ void OpenGl_Text::setupMatrix (const Handle(OpenGl_PrinterContext)& thePrintCtx,
// function : drawText
// purpose :
// =======================================================================
void OpenGl_Text::drawText (const Handle(OpenGl_PrinterContext)& ,
const Handle(OpenGl_Context)& theCtx,
#ifdef HAVE_GL2PS
const OpenGl_AspectText& theTextAspect) const
#else
const OpenGl_AspectText& ) const
#endif
void OpenGl_Text::drawText (const Handle(OpenGl_Context)& theCtx,
const OpenGl_AspectText& theTextAspect) const
{
#ifdef HAVE_GL2PS
if (theCtx->IsFeedback())
@ -606,6 +581,8 @@ void OpenGl_Text::drawText (const Handle(OpenGl_PrinterContext)& ,
exportText (myString, myIs2d, theTextAspect, (Standard_Integer )myExportHeight);
return;
}
#else
(void )theTextAspect;
#endif
if (myVertsVbo.Length() != myTextures.Length()
@ -724,12 +701,11 @@ Handle(OpenGl_Font) OpenGl_Text::FindFont (const Handle(OpenGl_Context)& theCtx,
// function : render
// purpose :
// =======================================================================
void OpenGl_Text::render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
const Handle(OpenGl_Context)& theCtx,
const OpenGl_AspectText& theTextAspect,
const OpenGl_Vec4& theColorText,
const OpenGl_Vec4& theColorSubs,
const unsigned int theResolution) const
void OpenGl_Text::render (const Handle(OpenGl_Context)& theCtx,
const OpenGl_AspectText& theTextAspect,
const OpenGl_Vec4& theColorText,
const OpenGl_Vec4& theColorSubs,
const unsigned int theResolution) const
{
if (myString.IsEmpty())
{
@ -902,7 +878,7 @@ void OpenGl_Text::render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
if (theCtx->core11 != NULL)
{
theCtx->SetColor4fv (theColorSubs);
setupMatrix (thePrintCtx, theCtx, theTextAspect, OpenGl_Vec3 (0.0f, 0.0f, 0.00001f));
setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (0.0f, 0.0f, 0.00001f));
glBindTexture (GL_TEXTURE_2D, 0);
glBegin (GL_QUADS);
@ -918,14 +894,14 @@ void OpenGl_Text::render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
case Aspect_TODT_DEKALE:
{
theCtx->SetColor4fv (theColorSubs);
setupMatrix (thePrintCtx, theCtx, theTextAspect, OpenGl_Vec3 (+1.0f, +1.0f, 0.00001f));
drawText (thePrintCtx, theCtx, theTextAspect);
setupMatrix (thePrintCtx, theCtx, theTextAspect, OpenGl_Vec3 (-1.0f, -1.0f, 0.00001f));
drawText (thePrintCtx, theCtx, theTextAspect);
setupMatrix (thePrintCtx, theCtx, theTextAspect, OpenGl_Vec3 (-1.0f, +1.0f, 0.00001f));
drawText (thePrintCtx, theCtx, theTextAspect);
setupMatrix (thePrintCtx, theCtx, theTextAspect, OpenGl_Vec3 (+1.0f, -1.0f, 0.00001f));
drawText (thePrintCtx, theCtx, theTextAspect);
setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (+1.0f, +1.0f, 0.00001f));
drawText (theCtx, theTextAspect);
setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (-1.0f, -1.0f, 0.00001f));
drawText (theCtx, theTextAspect);
setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (-1.0f, +1.0f, 0.00001f));
drawText (theCtx, theTextAspect);
setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (+1.0f, -1.0f, 0.00001f));
drawText (theCtx, theTextAspect);
break;
}
case Aspect_TODT_DIMENSION:
@ -937,8 +913,8 @@ void OpenGl_Text::render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
// main draw call
theCtx->SetColor4fv (theColorText);
setupMatrix (thePrintCtx, theCtx, theTextAspect, OpenGl_Vec3 (0.0f, 0.0f, 0.0f));
drawText (thePrintCtx, theCtx, theTextAspect);
setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (0.0f, 0.0f, 0.0f));
drawText (theCtx, theTextAspect);
if (!myIs2d)
{
@ -955,7 +931,7 @@ void OpenGl_Text::render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
if (theTextAspect.Aspect()->DisplayType() == Aspect_TODT_DIMENSION)
{
setupMatrix (thePrintCtx, theCtx, theTextAspect, OpenGl_Vec3 (0.0f, 0.0f, 0.00001f));
setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (0.0f, 0.0f, 0.00001f));
glDisable (GL_BLEND);
if (!myIs2d)

View File

@ -30,8 +30,6 @@
#include <gp_Ax2.hxx>
class OpenGl_PrinterContext;
//! Text rendering
class OpenGl_Text : public OpenGl_Element
{
@ -104,10 +102,9 @@ public: //! @name methods for compatibility with layers
const OpenGl_TextParam& theParams);
//! Perform rendering
Standard_EXPORT void Render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
const Handle(OpenGl_Context)& theCtx,
const OpenGl_AspectText& theTextAspect,
const unsigned int theResolution = Graphic3d_RenderingParams::THE_DEFAULT_RESOLUTION) const;
Standard_EXPORT void Render (const Handle(OpenGl_Context)& theCtx,
const OpenGl_AspectText& theTextAspect,
const unsigned int theResolution = Graphic3d_RenderingParams::THE_DEFAULT_RESOLUTION) const;
protected:
@ -123,23 +120,20 @@ private:
void releaseVbos (OpenGl_Context* theCtx);
//! Setup matrix.
void setupMatrix (const Handle(OpenGl_PrinterContext)& thePrintCtx,
const Handle(OpenGl_Context)& theCtx,
const OpenGl_AspectText& theTextAspect,
const OpenGl_Vec3 theDVec) const;
void setupMatrix (const Handle(OpenGl_Context)& theCtx,
const OpenGl_AspectText& theTextAspect,
const OpenGl_Vec3 theDVec) const;
//! Draw arrays of vertices.
void drawText (const Handle(OpenGl_PrinterContext)& thePrintCtx,
const Handle(OpenGl_Context)& theCtx,
const OpenGl_AspectText& theTextAspect) const;
void drawText (const Handle(OpenGl_Context)& theCtx,
const OpenGl_AspectText& theTextAspect) const;
//! Main rendering code
void render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
const Handle(OpenGl_Context)& theCtx,
const OpenGl_AspectText& theTextAspect,
const OpenGl_Vec4& theColorText,
const OpenGl_Vec4& theColorSubs,
const unsigned int theResolution) const;
void render (const Handle(OpenGl_Context)& theCtx,
const OpenGl_AspectText& theTextAspect,
const OpenGl_Vec4& theColorText,
const OpenGl_Vec4& theColorSubs,
const unsigned int theResolution) const;
protected:

View File

@ -167,27 +167,6 @@ public:
Standard_EXPORT virtual Standard_Boolean BufferDump (Image_PixMap& theImage,
const Graphic3d_BufferType& theBufferType) Standard_OVERRIDE;
//! Print the contents of the view to the printer.
//! @param thePrinterDC pass the PrinterDeviceContext (HDC)
//! @param theToShowBackground when set to FALSE then print the view without background
//! color (background is white) else set to TRUE for printing
//! with current background color
//! @param theFileName if != NULL, then the view will be printed to a file
//! @param thePrintAlgorithm select print algorithm: stretch, tile
//! @param theScaleFactor scaling coefficient, used internally to scale the printings
//! accordingly to the scale factor selected in the printer properties dialog
//! @return Standard_True if the data is passed to the printer, otherwise Standard_False if
//! the print operation failed due to the printer errors, or lack of system memory. This might be related
//! to insufficient memory or some internal errors.
//! All this errors are indicated by the message boxes (on level of OpenGl_GraphicDriver).
//! Warning: This function can reuse FBO assigned to the view, please take it into account
//! if you use it for your purposes.
Standard_EXPORT virtual Standard_Boolean Print (const Aspect_Handle thePrinterDC,
const Standard_Boolean theToShowBackground,
const Standard_CString theFileName,
const Aspect_PrintAlgo thePrintAlgorithm = Aspect_PA_STRETCH,
const Standard_Real theScaleFactor = 1.0) Standard_OVERRIDE;
//! Export scene into the one of the Vector graphics formats (SVG, PS, PDF...).
//! In contrast to Bitmaps, Vector graphics is scalable (so you may got quality benefits
//! on printing to laser printer). Notice however that results may differ a lot and

View File

@ -1,772 +0,0 @@
// Created on: 2011-09-20
// Created by: Sergey ZERCHANINOV
// Copyright (c) 2011-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <OpenGl_GlCore11.hxx>
#include <OpenGl_FrameBuffer.hxx>
#include <TColStd_Array2OfReal.hxx>
#include <Graphic3d_GraphicDriver.hxx>
#include <OpenGl_PrinterContext.hxx>
#include <OpenGl_Workspace.hxx>
#include <OpenGl_View.hxx>
#include <Standard_NotImplemented.hxx>
#if (defined(_WIN32) || defined(__WIN32__)) && defined(HAVE_FREEIMAGE)
#include <NCollection_Handle.hxx>
#include <FreeImagePlus.h>
#ifdef _MSC_VER
#pragma comment( lib, "FreeImage.lib" )
#pragma comment( lib, "FreeImagePlus.lib" )
#endif
typedef NCollection_Handle<fipImage> FipHandle;
#endif
#ifdef _WIN32
#ifndef HAVE_FREEIMAGE
// =======================================================================
// function : initBitmapBuffer
// purpose : init device independent bitmap to hold printing data
// =======================================================================
static void initBitmapBuffer (const HDC theMemoryDC,
HBITMAP &theMemoryBmp,
const Standard_Integer theBmpWidth,
const Standard_Integer theBmpHeight,
VOID* &theBufferPtr)
{
// define compatible bitmap
BITMAPINFO aBitmapData;
memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
aBitmapData.bmiHeader.biWidth = theBmpWidth;
aBitmapData.bmiHeader.biHeight = theBmpHeight;
aBitmapData.bmiHeader.biPlanes = 1;
aBitmapData.bmiHeader.biBitCount = 24;
aBitmapData.bmiHeader.biXPelsPerMeter = 0;
aBitmapData.bmiHeader.biYPelsPerMeter = 0;
aBitmapData.bmiHeader.biClrUsed = 0;
aBitmapData.bmiHeader.biClrImportant = 0;
aBitmapData.bmiHeader.biCompression = BI_RGB;
aBitmapData.bmiHeader.biSizeImage = 0;
// Create Device Independent Bitmap
theMemoryBmp = CreateDIBSection (theMemoryDC, &aBitmapData, DIB_RGB_COLORS,
&theBufferPtr, NULL, 0);
}
#else /* HAVE_FREEIMAGE */
// =======================================================================
// function : imagePasteDC
// purpose : copy the data from image buffer to the device context
// =======================================================================
static bool imagePasteDC(HDC theDstDC, FipHandle theImage, int theOffsetX,
int theOffsetY, int theWidth, int theHeight,
int theLeft = 0, int theTop = 0)
{
// get image parameters
BITMAPINFO* aBitmapData = theImage->getInfo ();
SetStretchBltMode (theDstDC, STRETCH_HALFTONE);
// organize blocks data passing if memory isn't enough to pass all the data
// at once
int aLinesComplete = 0, aMaxBlockWidth = theHeight, aBlockWidth = 0,
aPassed = 0, aInverseLine = 0, aScan = 0;
BYTE *aDataPtr = 0;
while (aMaxBlockWidth >= 1 && aLinesComplete < theHeight)
{
// how much lines still to pass
aBlockWidth = theHeight - aLinesComplete;
// normalize count of lines to pass to maximum lines count at one pass.
if (aBlockWidth > aMaxBlockWidth)
aBlockWidth = aMaxBlockWidth;
// access image data at the start scan line, we need to calculate scan from
// the bottom of image (image is bottom-left, the src coord is top-left)
aInverseLine = theTop + aBlockWidth + aLinesComplete;
aScan = theImage->getHeight() - aInverseLine;
aDataPtr = theImage->getScanLine (aScan);
if (!aDataPtr)
return false;
// try to pass block to the device
if (aBlockWidth > 0)
{
// instead of banded output we provide blocked as it isn't always passed
// to printer as it is expected
aPassed = SetDIBitsToDevice (theDstDC, theOffsetX,
theOffsetY + aLinesComplete,
theWidth, aBlockWidth, theLeft, 0,
0, aBlockWidth,
aDataPtr, aBitmapData, DIB_RGB_COLORS);
// if result is bad, try to decrease band width
if (aPassed != aBlockWidth)
{
aMaxBlockWidth = aMaxBlockWidth >> 1;
aLinesComplete = 0;
}
else
aLinesComplete += aBlockWidth;
}
}
// check for total failure
if (aMaxBlockWidth < 1)
return false;
return true;
}
// =======================================================================
// function : imageStretchDC
// purpose : copy pixels from image to dc by stretching them
// =======================================================================
static bool imageStretchDC(HDC theDstDC, FipHandle theImage, int theOffsetX,
int theOffsetY, int theWidth, int theHeight)
{
// access to raw image data
BYTE *aDataPtr = theImage->accessPixels ();
if (!aDataPtr)
return false;
// get image parameters
unsigned int widthPx = theImage->getWidth ();
unsigned int heightPx = theImage->getHeight ();
BITMAPINFO* aBitmapData = theImage->getInfo ();
SetStretchBltMode (theDstDC, STRETCH_HALFTONE);
// pass lines and check if operation is succesfull
int aPassed = 0;
aPassed = StretchDIBits (theDstDC, theOffsetX, theOffsetY, theWidth,
theHeight, 0, 0, widthPx, heightPx, aDataPtr,
aBitmapData, DIB_RGB_COLORS, SRCCOPY);
if ((unsigned)aPassed != heightPx)
return false;
return true;
}
#endif /* HAVE_FREEIMAGE */
// =======================================================================
// function : getNearestPowOfTwo
// purpose : get the nearest power of two for theNumber
// =======================================================================
static GLsizei getNearestPowOfTwo (const GLsizei theNumber)
{
GLsizei aLast = 1;
for (GLsizei p2 = 1; p2 <= theNumber; aLast = p2, p2 <<= 1);
return aLast;
}
// =======================================================================
// function : getMaxFrameSize
// purpose : get the maximum possible frame size
// =======================================================================
static void getMaxFrameSize(Standard_Integer& theWidth,
Standard_Integer& theHeight)
{
GLsizei aMaxX, aMaxY;
GLint aVpDim[2];
GLint aTexDim = 2048;
glGetIntegerv (GL_MAX_VIEWPORT_DIMS, (GLint*) &aVpDim);
glGetIntegerv (GL_MAX_TEXTURE_SIZE, &aTexDim);
(aVpDim[0] >= aTexDim) ? aMaxX = (GLsizei) aTexDim :
aMaxX = getNearestPowOfTwo((GLsizei)aVpDim[0]);
(aVpDim[1] >= aTexDim) ? aMaxY = (GLsizei) aTexDim :
aMaxY = getNearestPowOfTwo((GLsizei)aVpDim[1]);
theWidth = (Standard_Integer)aMaxX;
theHeight = (Standard_Integer)aMaxY;
}
// =======================================================================
// function : fitDimensionsRatio
// purpose : calculate correct width/height ratio for theWidth and
// theHeight parameters
// =======================================================================
static void fitDimensionsRatio (Standard_Integer& theWidth,
Standard_Integer& theHeight,
const Standard_Real theViewRatio)
{
// set dimensions in accordance with the viewratio
if (theHeight < theWidth/theViewRatio)
theWidth = (Standard_Integer)(theHeight*theViewRatio);
if (theWidth < theHeight*theViewRatio)
theHeight = (Standard_Integer)(theWidth/theViewRatio);
}
// =======================================================================
// function : initBufferStretch
// purpose : calculate initialization sizes for frame buffer
// when the stretch algorithm is selected
// =======================================================================
static void initBufferStretch (Standard_Integer& theFrameWidth,
Standard_Integer& theFrameHeight,
const int theViewWidth,
const int theViewHeight)
{
// Calculate correct width/height for framebuffer
Standard_Real aViewRatio = (Standard_Real)theViewWidth/theViewHeight;
fitDimensionsRatio (theFrameWidth, theFrameHeight, aViewRatio);
// downscale the framebuffer if it is too large
Standard_Real aWidthRate = (Standard_Real)theFrameWidth /theViewWidth;
Standard_Real aHeightRate = (Standard_Real)theFrameHeight/theViewHeight;
if ((aWidthRate > 1 && aHeightRate > 1 && aWidthRate >= aHeightRate) ||
(aWidthRate > 1 && aHeightRate <= 1))
{
theFrameWidth = (Standard_Integer)(theFrameWidth /aWidthRate);
theFrameHeight = (Standard_Integer)(theFrameHeight/aWidthRate);
}
else if ((aWidthRate > 1 && aHeightRate > 1 && aWidthRate < aHeightRate) ||
(aWidthRate <= 1 && aHeightRate > 1))
{
theFrameWidth = (Standard_Integer)(theFrameWidth /aHeightRate);
theFrameHeight = (Standard_Integer)(theFrameHeight/aHeightRate);
}
}
// =======================================================================
// function : initBufferTiling
// purpose : calculate initialization sizes for frame buffer
// when the tile algorithm is selected
// =======================================================================
static void initBufferTiling (Standard_Integer& theFrameWidth,
Standard_Integer &theFrameHeight,
const int theViewWidth,
const int theViewHeight)
{
// fit framebuffer into the printing area
if (theFrameWidth > theViewWidth)
theFrameWidth = theViewWidth;
if (theFrameHeight > theViewHeight)
theFrameHeight = theViewHeight;
}
#endif /* _WIN32 */
// =======================================================================
// function : Print
// purpose :
// =======================================================================
Standard_Boolean OpenGl_View::Print (const Aspect_Handle thePrinterDC,
const Standard_Boolean theToShowBackground,
const Standard_CString theFileName,
const Aspect_PrintAlgo thePrintAlgorithm,
const Standard_Real theScaleFactor)
{
#ifdef _WIN32
if (!myWorkspace->Activate())
{
//MessageBox (NULL, "Print failed: can't setup the view for printing.",
// "The operation couldn't be completed.", MB_OK);
return Standard_False;
}
Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
// printer page dimensions
HDC hPrnDC = (HDC) thePrinterDC;
int devWidth = GetDeviceCaps (hPrnDC, HORZRES);
int devHeight = GetDeviceCaps (hPrnDC, VERTRES);
// if context is actually a memory dc, try to retrieve bitmap dimensions
// (memory dc could be used for testing purposes)
if (GetObjectType (hPrnDC) == OBJ_MEMDC)
{
// memory dc dimensions
BITMAP aBitmapInfo;
HBITMAP aMemoryBitmap = (HBITMAP) GetCurrentObject (hPrnDC, OBJ_BITMAP);
if (aMemoryBitmap)
if (GetObject (aMemoryBitmap, sizeof (BITMAP), &aBitmapInfo))
{
devWidth = aBitmapInfo.bmWidth;
devHeight = aBitmapInfo.bmHeight;
}
}
Standard_Integer tempWidth = (Standard_Integer) devWidth;
Standard_Integer tempHeight = (Standard_Integer) devHeight;
// view dimensions
int viewWidth = myWindow->Width();
int viewHeight = myWindow->Height();
if (viewWidth == 0 || viewHeight == 0)
{
//MessageBox (NULL, "Print failed: can't setup the view for printing.",
// "The operation couldn't be completed.", MB_OK);
return Standard_False;
}
// calculate correct width/height ratio
Standard_Real viewRatio = (Standard_Real)viewWidth/viewHeight;
fitDimensionsRatio(tempWidth, tempHeight, viewRatio);
// width and height for printing area
int width = (int) (tempWidth * theScaleFactor);
int height = (int) (tempHeight * theScaleFactor);
// device independent bitmap for the whole view
#ifdef HAVE_FREEIMAGE
FipHandle aViewImage = NULL;
BYTE* aViewBuffer = NULL;
#else
HDC hMemDC = CreateCompatibleDC (hPrnDC);
HBITMAP hViewBitmap = NULL;
HGDIOBJ hViewBitmapOld = NULL;
VOID* aViewBuffer = NULL;
#endif
// Frame buffer initialization
OpenGl_FrameBuffer* aFrameBuffer = NULL;
OpenGl_FrameBuffer* aPrevBuffer = myFBO.operator->();
Standard_Integer aFrameWidth (0), aFrameHeight (0),
aPrevBufferX (0), aPrevBufferY (0);
bool IsTiling = (thePrintAlgorithm == Aspect_PA_TILE);
// try to use existing frame buffer
if (aPrevBuffer)
{
GLsizei aPrevWidth = aPrevBuffer->GetSizeX();
GLsizei aPrevHeight = aPrevBuffer->GetSizeY();
bool isUsable = false;
// check if its possible to use previous frame buffer
if (!IsTiling && aPrevWidth >= width && aPrevHeight >= height)
{
aFrameWidth = (Standard_Integer) width;
aFrameHeight = (Standard_Integer) height;
isUsable = true;
}
else if (IsTiling)
{
// use previous frame buffer with its dimensions
aFrameWidth = aPrevWidth;
aFrameHeight = aPrevHeight;
isUsable = true;
}
// if it is enough memory for image paste dc operation
if (isUsable)
{
#ifdef HAVE_FREEIMAGE
// try to allocate fipImage and necessary resources
fipImage* anImagePtr = new fipImage (FIT_BITMAP, aFrameWidth,
aFrameHeight, 24);
// if allocated successfully
if (anImagePtr->isValid())
{
aViewImage = anImagePtr;
aViewBuffer = aViewImage->accessPixels ();
}
else
delete anImagePtr;
if (!aViewBuffer)
{
isUsable = false;
aViewBuffer = NULL;
aViewImage = NULL;
}
#else
// try to allocate compatible bitmap and necessary resources
initBitmapBuffer (hMemDC, hViewBitmap,
aFrameWidth, aFrameHeight, aViewBuffer);
if (!aViewBuffer)
{
isUsable = false;
if (hViewBitmap)
DeleteObject (hViewBitmap);
hViewBitmap = NULL;
}
else
hViewBitmapOld = SelectObject (hMemDC, hViewBitmap);
#endif
}
// use previous frame buffer
if (isUsable)
{
aPrevBufferX = aPrevWidth;
aPrevBufferY = aPrevHeight;
aFrameBuffer = aPrevBuffer;
aFrameBuffer->ChangeViewport (aFrameWidth, aFrameHeight);
}
}
// if previous buffer cannot be used, try to init a new one
if (!aFrameBuffer)
{
aFrameBuffer = new OpenGl_FrameBuffer();
// try to create the framebuffer with the best possible size
Standard_Integer aMaxWidth(0), aMaxHeight(0);
getMaxFrameSize (aMaxWidth, aMaxHeight);
while (aMaxWidth > 1 && aMaxHeight > 1)
{
aFrameWidth = aMaxWidth;
aFrameHeight = aMaxHeight;
// calculate dimensions for different printing algorithms
if (!IsTiling)
initBufferStretch (aFrameWidth, aFrameHeight, width, height);
else
initBufferTiling (aFrameWidth, aFrameHeight, width, height);
// try to initialize framebuffer
if (aFrameBuffer->Init (aCtx, aFrameWidth, aFrameHeight, GL_RGBA8, GL_DEPTH24_STENCIL8))
{
#ifdef HAVE_FREEIMAGE
// try to allocate fipImage and necessary resources
fipImage* anImagePtr = new fipImage (FIT_BITMAP, aFrameWidth,
aFrameHeight, 24);
// if allocated successfully
if (anImagePtr->isValid())
{
aViewImage = anImagePtr;
aViewBuffer = aViewImage->accessPixels ();
}
else
delete anImagePtr;
if (!aViewBuffer)
{
aFrameBuffer->Release (aCtx.operator->());
aViewBuffer = NULL;
aViewImage = NULL;
}
else
break;
#else
// try to allocate compatible bitmap and necessary resources
initBitmapBuffer (hMemDC, hViewBitmap,
aFrameWidth, aFrameHeight, aViewBuffer);
if (!aViewBuffer)
{
if (hViewBitmap)
DeleteObject (hViewBitmap);
aFrameBuffer->Release (aCtx.operator->());
hViewBitmap = NULL;
}
else
{
hViewBitmapOld = SelectObject (hMemDC, hViewBitmap);
break;
}
#endif
}
// not initialized, decrease dimensions
aMaxWidth = aMaxWidth >> 1;
aMaxHeight = aMaxHeight >> 1;
}
// check if there are proper dimensions
if (aMaxWidth <= 1 || aMaxHeight <= 1)
{
MessageBox (NULL, "Print failed: can't allocate buffer for printing.",
"The operation couldn't be completed.", MB_OK);
if (aFrameBuffer)
delete aFrameBuffer;
#ifndef HAVE_FREEIMAGE
if (hMemDC)
DeleteDC (hMemDC);
#endif
return Standard_False;
}
}
// setup printing context and viewport
myWorkspace->PrinterContext() = new OpenGl_PrinterContext();
myWorkspace->PrinterContext()->SetLayerViewport ((GLsizei )aFrameWidth, (GLsizei )aFrameHeight);
GLint aViewPortBack[4];
GLint anAlignBack = 1;
glGetIntegerv (GL_VIEWPORT, aViewPortBack);
glGetIntegerv (GL_PACK_ALIGNMENT, &anAlignBack);
glPixelStorei (GL_PACK_ALIGNMENT, 4);
// start document if the printer context is not actually a memory dc
// (memory dc could be used for testing purposes)
DOCINFO di;
if (GetObjectType (hPrnDC) == OBJ_DC)
{
// Initialize printing procedure
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = "Open Cascade Document - print v3d view";
di.lpszOutput = theFileName;
// if can't print the document
if (StartDoc (hPrnDC, &di) <= 0 || StartPage (hPrnDC) <= 0)
{
MessageBox (NULL, "Print failed: printer can't start operation.",
"The operation couldn't be completed.", MB_OK);
#ifndef HAVE_FREEIMAGE
if (hViewBitmap)
{
SelectObject (hMemDC, hViewBitmapOld);
DeleteObject (hViewBitmap);
}
DeleteDC (hMemDC);
#endif
myWorkspace->PrinterContext().Nullify();
return Standard_False;
}
}
// calculate offset for centered printing
int aDevOffx = (int)(devWidth - width) /2;
int aDevOffy = (int)(devHeight - height)/2;
// operation complete flag
bool isDone = true;
// Set up status for printing
if (!theToShowBackground)
{
myWorkspace->NamedStatus |= OPENGL_NS_WHITEBACK;
}
// switch to mono camera for image dump
const Graphic3d_Camera::Projection aProjectType = myCamera->ProjectionType() != Graphic3d_Camera::Projection_Stereo
? myCamera->ProjectionType()
: Graphic3d_Camera::Projection_Perspective;
if (!IsTiling)
{
myWorkspace->PrinterContext()->SetScale ((GLfloat )aFrameWidth /viewWidth, (GLfloat )aFrameHeight/viewHeight);
redraw (aProjectType, aFrameBuffer);
if (!myTransientDrawToFront)
{
// render to FBO only if allowed to render to back buffer
myBackBufferRestored = Standard_True;
myIsImmediateDrawn = Standard_False;
redrawImmediate (aProjectType, NULL, aFrameBuffer);
myBackBufferRestored = Standard_False;
myIsImmediateDrawn = Standard_False;
}
glReadPixels (0, 0, aFrameWidth, aFrameHeight,
GL_BGR_EXT, GL_UNSIGNED_BYTE, (GLvoid* )aViewBuffer);
// copy result to the printer device and check for errors
#ifdef HAVE_FREEIMAGE
if (!aViewImage->rescale(width, height, FILTER_BICUBIC) ||
!imagePasteDC (hPrnDC, aViewImage, aDevOffx, aDevOffy, width, height))
isDone = imageStretchDC (hPrnDC, aViewImage, aDevOffx, aDevOffy,
width, height);
#else
if (width > aFrameWidth && height > aFrameHeight)
{
SetStretchBltMode (hPrnDC, STRETCH_HALFTONE);
isDone = (StretchBlt (hPrnDC, aDevOffx, aDevOffy, width, height,
hMemDC, 0, 0, aFrameWidth, aFrameHeight, SRCCOPY) != 0); // to avoid warning C4800
}
else
{
isDone = (BitBlt (hPrnDC, aDevOffx, aDevOffy, width, height,
hMemDC, 0, 0, SRCCOPY) != 0); // to avoid warning C4800
}
#endif
}
else
{
// calculate total count of frames and cropping size
Standard_Integer aPxCropx = 0;
Standard_Integer aPxCropy = 0;
Standard_Integer aTotalx =
(Standard_Integer)floor ((float)width /aFrameWidth);
Standard_Integer aTotaly =
(Standard_Integer)floor ((float)height/aFrameHeight);
if (width %aFrameWidth != 0)
{
aPxCropx = (aFrameWidth - width%aFrameWidth)/2;
aTotalx++;
}
if (height%aFrameHeight != 0)
{
aPxCropy = (aFrameHeight - height%aFrameHeight)/2;
aTotaly++;
}
int anOddPixelx = (width %aFrameWidth) %2;
int anOddPixely = (height%aFrameHeight)%2;
// calculate scale factor for full frames
Standard_Real aScalex = (Standard_Real)width /aFrameWidth;
Standard_Real aScaley = (Standard_Real)height/aFrameHeight;
// calculate and set the text scaling factor for printing context
GLfloat aScaleRatex = (GLfloat)aFrameWidth /viewWidth;
GLfloat aScaleRatey = (GLfloat)aFrameHeight/viewHeight;
myWorkspace->PrinterContext()->SetScale (aScaleRatex * (GLfloat )aScalex, aScaleRatey * (GLfloat )aScaley);
// initialize projection matrix for printer context
TColStd_Array2OfReal aProj (0, 3, 0, 3);
Standard_Real aDef = 0;
aProj.Init (aDef);
aProj(2,2) = 1.0;
aProj(3,3) = 1.0;
// projection matrix offsets for printer context
// offsets are even numbers
Standard_Real aOffsetx(0), aOffsety(0);
aOffsetx = -(aTotalx-1);
aOffsety = -(aTotaly-1);
// rect of frame image that will be copied
// and coordinates in view image where to put it
Standard_Integer aLeft = 0, aRight = 0, aBottom = 0, aTop = 0;
Standard_Integer aSubLeft = (Standard_Integer)aDevOffx;
Standard_Integer aSubTop = (Standard_Integer)aDevOffy;
// draw sequence of full frames
for (int i = 0; i < aTotalx; i++)
{
// offsets are even numbers
aOffsety = -(aTotaly-1);
aSubTop = (Standard_Integer)aDevOffy;
// calculate cropped frame rect
aLeft = (i == 0) ? aPxCropx : 0;
aRight = (i == aTotalx-1) ? aFrameWidth-(aPxCropx+anOddPixelx) :
aFrameWidth;
for (int j = 0; j < aTotaly; j++)
{
// no offset for single frames
aProj(3,0) = (aTotalx == 1) ? 0 : -aOffsetx;
aProj(3,1) = (aTotaly == 1) ? 0 : aOffsety;
// set projection matrix
aProj(0,0) = aScalex;
aProj(1,1) = aScaley;
myWorkspace->PrinterContext()->SetProjTransformation (aProj);
// calculate cropped frame rect
aTop = (j == 0) ? aPxCropy : 0;
aBottom = (j == aTotaly-1) ? aFrameHeight-(aPxCropy+anOddPixely) :
aFrameHeight;
// draw to the offscreen buffer and capture the result
redraw (aProjectType, aFrameBuffer);
if (!myTransientDrawToFront)
{
// render to FBO only if forces to render to back buffer
myBackBufferRestored = Standard_True;
myIsImmediateDrawn = Standard_False;
redrawImmediate (aProjectType, NULL, aFrameBuffer);
myBackBufferRestored = Standard_False;
myIsImmediateDrawn = Standard_False;
}
glReadPixels (0, 0, aFrameWidth, aFrameHeight,
GL_BGR_EXT, GL_UNSIGNED_BYTE, (GLvoid* )aViewBuffer);
#ifdef HAVE_FREEIMAGE
// cut out pixels that are out of printing area
isDone = imagePasteDC (hPrnDC, aViewImage, aSubLeft, aSubTop,
aRight-aLeft, aBottom-aTop, aLeft, aTop);
#else
isDone = (BitBlt (hPrnDC, aSubLeft, aSubTop, aRight-aLeft, aBottom-aTop,
hMemDC, aLeft, aTop, SRCCOPY) != 0); // to avoid warning C4800
#endif
// stop operation if errors
if (!isDone)
break;
// calculate new view offset for y-coordinate
aOffsety += 2.0;
aSubTop += aBottom-aTop;
}
// stop operation if errors
if (!isDone)
break;
// calculate new view offset for x-coordinate
aOffsetx += 2.0;
aSubLeft += aRight-aLeft;
}
}
// complete printing or indicate an error
if (GetObjectType (hPrnDC) == OBJ_DC && isDone == true)
{
EndPage (hPrnDC);
EndDoc (hPrnDC);
}
else if (isDone == false)
{
MessageBox (NULL, "Print failed: insufficient memory or spool error.\nPlease use smaller printer resolution.",
"The opeartion couldn't be completed.", MB_OK);
if (GetObjectType (hPrnDC) == OBJ_DC)
AbortDoc (hPrnDC);
}
// return OpenGl to the previous state
glPixelStorei (GL_PACK_ALIGNMENT, anAlignBack);
aFrameBuffer->UnbindBuffer (aCtx);
glViewport (aViewPortBack[0], aViewPortBack[1],
aViewPortBack[2], aViewPortBack[3]);
if (aPrevBuffer)
{
aPrevBuffer->ChangeViewport (aPrevBufferX, aPrevBufferY);
}
else
{
aFrameBuffer->Release (aCtx.operator->());
delete aFrameBuffer;
}
// delete resources
#ifndef HAVE_FREEIMAGE
if (hViewBitmap)
{
SelectObject (hMemDC, hViewBitmapOld);
DeleteObject (hViewBitmap);
}
DeleteDC (hMemDC);
#endif
// Reset status after printing
myWorkspace->NamedStatus &= ~OPENGL_NS_WHITEBACK;
myWorkspace->PrinterContext().Nullify();
return (Standard_Boolean) isDone;
#else // not _WIN32
(void )thePrinterDC;
(void )theToShowBackground;
(void )theFileName;
(void )thePrintAlgorithm;
(void )theScaleFactor;
Standard_NotImplemented::Raise ("OpenGl_View::Print is implemented only on Windows");
myWorkspace->PrinterContext().Nullify();
return Standard_False;
#endif
}

View File

@ -34,7 +34,6 @@
#include <OpenGl_Trihedron.hxx>
#include <OpenGl_GraduatedTrihedron.hxx>
#include <OpenGl_PrimitiveArray.hxx>
#include <OpenGl_PrinterContext.hxx>
#include <OpenGl_ShaderManager.hxx>
#include <OpenGl_ShaderProgram.hxx>
#include <OpenGl_Structure.hxx>
@ -1116,17 +1115,6 @@ void OpenGl_View::renderScene (Graphic3d_Camera::Projection theProjection,
{
const Handle(OpenGl_Context)& aContext = myWorkspace->GetGlContext();
#ifdef _WIN32
// set printing scale/tiling transformation
Handle(OpenGl_PrinterContext) aPrintContext = myWorkspace->PrinterContext();
if (!aPrintContext.IsNull())
{
aContext->ProjectionState.Push();
aContext->ProjectionState.SetCurrent (aPrintContext->ProjTransformation() * aContext->ProjectionState.Current());
aContext->ApplyProjectionMatrix();
}
#endif
// Specify clipping planes in view transformation space
aContext->ChangeClipping().RemoveAll (aContext);
if (!myClipPlanes.IsEmpty())
@ -1239,15 +1227,6 @@ void OpenGl_View::renderScene (Graphic3d_Camera::Projection theProjection,
{
aContext->ShaderManager()->RevertClippingState();
}
#ifdef _WIN32
// set printing scale/tiling transformation
if (!aPrintContext.IsNull())
{
aContext->ProjectionState.Pop();
aContext->ApplyProjectionMatrix();
}
#endif
}
// =======================================================================

View File

@ -23,7 +23,6 @@
#include <OpenGl_FrameBuffer.hxx>
#include <OpenGl_Matrix.hxx>
#include <OpenGl_NamedStatus.hxx>
#include <OpenGl_PrinterContext.hxx>
#include <OpenGl_RenderFilter.hxx>
#include <OpenGl_ShaderObject.hxx>
#include <OpenGl_ShaderProgram.hxx>
@ -150,8 +149,6 @@ public:
return wasUsed;
}
Handle(OpenGl_PrinterContext)& PrinterContext() { return myPrintContext; }
//! @return true if usage of Z buffer is enabled.
Standard_Boolean& UseZBuffer() { return myUseZBuffer; }
@ -356,7 +353,6 @@ protected: //! @name protected fields
OpenGl_View* myView;
Handle(OpenGl_Window) myWindow;
Handle(OpenGl_Context) myGlContext;
Handle(OpenGl_PrinterContext) myPrintContext;
Standard_Boolean myUseZBuffer;
Standard_Boolean myUseDepthWrite;
Standard_Boolean myUseGLLight;

View File

@ -45,6 +45,25 @@
#endif
#endif
// Disable warnings about deprecated features.
// This is useful for sections of code kept for backward compatibility and scheduled for removal.
#if defined(__ICL) || defined (__INTEL_COMPILER)
#define Standard_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:1478))
#define Standard_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop))
#elif defined(_MSC_VER)
#define Standard_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:4996))
#define Standard_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop))
#elif (defined(__GNUC__) && __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__)
// available since at least gcc 4.2 (maybe earlier), however only gcc 4.6+ supports this pragma inside the function body
// CLang also supports this gcc syntax (in addition to "clang diagnostic ignored")
#define Standard_DISABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
#define Standard_ENABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic warning \"-Wdeprecated-declarations\"")
#else
#define Standard_DISABLE_DEPRECATION_WARNINGS
#define Standard_ENABLE_DEPRECATION_WARNINGS
#endif
//======================================================
// Windows-specific definitions
//======================================================

View File

@ -41,7 +41,6 @@ V3d_View_2.cxx
V3d_View_3.cxx
V3d_View_4.cxx
V3d_View_5.cxx
V3d_View_Print.cxx
V3d_Viewer.cxx
V3d_Viewer.hxx
V3d_Viewer_1.cxx

View File

@ -22,7 +22,6 @@
#include <Aspect_GradientBackground.hxx>
#include <Aspect_GradientFillMethod.hxx>
#include <Aspect_Handle.hxx>
#include <Aspect_PrintAlgo.hxx>
#include <Aspect_RenderingContext.hxx>
#include <Aspect_TypeOfTriedronPosition.hxx>
#include <Aspect_TypeOfTriedronEcho.hxx>
@ -806,40 +805,11 @@ public:
//! Returns FALSE when the dump has failed
Standard_EXPORT Standard_Boolean Dump (const Standard_CString theFile, const Graphic3d_BufferType& theBufferType = Graphic3d_BT_RGB);
//! print the contents of the view to printer with preview.
//! <thePrintDC> : If you have already an PrinterDeviceContext (HDC),
//! then you can pass it to the print routines.
//! If you don't have an PrinterDeviceContext, then this parameter should
//! be NULL.
//! <theShowDialog> : If thePrintDC == NULL, then you can force the print routines to
//! open a Print Dialog box.
//! If you want to do this, then set showDialog to TRUE
//! If you don't want to see a dialog (only possible, if you have a hPrnDC
//! or the dialog box was opened once before) then set <theShowDialog> to FALSE.
//! <theShowBackground> : When set to FALSE then print the view without background color
//! (background is white)
//! else set to TRUE for printing with current background color.
//! <theFilename>: If != NULL, then the view will be printed to a file.
//! <thePrintAlgorithm>: If you want to select the print algorithm, then you can
//! specify one of existing algorithms: Aspect_PA_STRETCH, Aspect_PA_TILE.
//! Returns Standard_True if the data is passed to the printer, otherwise
//! Standard_False if the print operation failed. This might be related to
//! insufficient memory or some internal errors. All this errors are
//! indicated by the message boxes (on level of OpenGl_GraphicDriver).
//! Warning: This function can reuse FBO assigned to the
//! view on level of OpenGl_GraphicDriver; Please take it into account if
//! you use it for your purposes;
//! Warning: Works only under Windows.
Standard_EXPORT Standard_Boolean Print (const Aspect_Handle thePrintDC = 0,
const Standard_Boolean theShowDialog = Standard_True,
const Standard_Boolean theShowBackground = Standard_True,
const Standard_CString theFilename = NULL,
const Aspect_PrintAlgo thePrintAlgorithm = Aspect_PA_STRETCH) const;
//! Export scene into the one of the Vector graphics formats (SVG, PS, PDF...).
//! In contrast to Bitmaps, Vector graphics is scalable (so you may got quality benefits
//! on printing to laser printer). Notice however that results may differ a lot and
//! do not contain some elements.
Standard_DEPRECATED("Export to Vector graphic is incompatible with Programmable Pipeline and should not be used")
Standard_EXPORT Standard_Boolean Export (const Standard_CString theFileName,
const Graphic3d_ExportFormat theFormat,
const Graphic3d_SortType theSortType = Graphic3d_ST_BSP_Tree);

View File

@ -1,156 +0,0 @@
// Created by: THA
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
// e-mail t-hartl@muenchen.matra-dtv.fr
/************************************************************************/
/* Includes */
/************************************************************************/
#ifdef _WIN32
#include <windows.h>
#if defined(_MSC_VER)
#pragma comment( lib, "comdlg32.lib" )
#endif
#endif
#include <Aspect_GradientBackground.hxx>
#include <Aspect_Grid.hxx>
#include <Aspect_Window.hxx>
#include <Bnd_Box.hxx>
#include <gp_Ax3.hxx>
#include <gp_Dir.hxx>
#include <Graphic3d_Group.hxx>
#include <Graphic3d_Structure.hxx>
#include <Graphic3d_TextureEnv.hxx>
#include <Graphic3d_Vector.hxx>
#include <Quantity_Color.hxx>
#include <Standard_MultiplyDefined.hxx>
#include <Standard_NotImplemented.hxx>
#include <Standard_TypeMismatch.hxx>
#include <V3d_BadValue.hxx>
#include <V3d_Light.hxx>
#include <V3d_UnMapped.hxx>
#include <V3d_View.hxx>
#include <V3d_Viewer.hxx>
#ifdef _WIN32
struct Device
{
Device();
~Device();
PRINTDLG _pd;
};
//**********************************************************************
static Device device;
//**********************************************************************
Device::Device()
{
memset(&_pd, 0, sizeof(PRINTDLG));
_pd.hDevNames = NULL;
_pd.hDevMode = NULL;
_pd.lStructSize = sizeof(PRINTDLG);
}
//**********************************************************************
Device::~Device()
{
// :TODO:
if (_pd.hDevNames) GlobalFree(_pd.hDevNames);
if (_pd.hDevMode) GlobalFree(_pd.hDevMode);
if (_pd.hDC) DeleteDC(_pd.hDC);
}
#endif
//=============================================================================
//function : Print
//purpose :
//=============================================================================
Standard_Boolean V3d_View::Print (const Aspect_Handle thePrintDC,
const Standard_Boolean theShowDialog,
const Standard_Boolean theShowBackground,
const Standard_CString theFilename,
const Aspect_PrintAlgo thePrintAlgorithm) const
{
#ifdef _WIN32
if (myView->IsDefined())
{
if (thePrintDC != NULL)
{
return myView->Print (thePrintDC, theShowBackground, theFilename, thePrintAlgorithm);
}
if (device._pd.hDC == NULL || theShowDialog)
{
if (device._pd.hDC)
DeleteDC (device._pd.hDC);
if (!theShowDialog)
{
device._pd.Flags = PD_RETURNDC | PD_NOSELECTION | PD_RETURNDEFAULT;
}
else
{
device._pd.Flags = PD_RETURNDC | PD_NOSELECTION;
}
BOOL ispd;
ispd = PrintDlg((LPPRINTDLG)(&(device._pd)));
if (!ispd)
{
return Standard_False;
}
if (!(device._pd.hDC))
{
if (device._pd.hDevNames)
{
GlobalFree (device._pd.hDevNames);
device._pd.hDevNames = NULL;
}
if (device._pd.hDevMode)
{
GlobalFree (device._pd.hDevMode);
device._pd.hDevMode = NULL;
}
MessageBox (0, "Couldn't create Printer Device Context", "Error", MB_OK | MB_ICONSTOP);
return Standard_False;
}
}
// process scale factor accordingly to the new printing approach
DEVMODE* aMode = (LPDEVMODE)GlobalLock(device._pd.hDevMode);
// convert percents to multiplication factor, 100% = 1.0
Standard_Real aScaleFactor = (Standard_Real) aMode->dmScale / 100.0;
GlobalUnlock (device._pd.hDevMode);
return myView->Print (device._pd.hDC, theShowBackground, theFilename, thePrintAlgorithm, aScaleFactor);
}
#else
(void )thePrintDC;
(void )theShowDialog;
(void )theShowBackground;
(void )theFilename;
(void )thePrintAlgorithm;
Standard_NotImplemented::Raise ("V3d_View::Print is implemented only on Windows");
#endif
return Standard_False;
}

View File

@ -49,7 +49,6 @@
#include <Draw_Interpretor.hxx>
#include <Draw.hxx>
#include <Draw_Appli.hxx>
#include <Aspect_PrintAlgo.hxx>
#include <Image_AlienPixMap.hxx>
#include <OpenGl_GraphicDriver.hxx>
#include <OSD_Timer.hxx>
@ -82,11 +81,6 @@
#if defined(_WIN32)
#include <WNT_WClass.hxx>
#include <WNT_Window.hxx>
#if defined(_MSC_VER)
#define _CRT_SECURE_NO_DEPRECATE
#pragma warning (disable:4996)
#endif
#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
#include <Cocoa_Window.hxx>
#else
@ -3384,7 +3378,9 @@ static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** arg
try
{
Standard_DISABLE_DEPRECATION_WARNINGS
if (!V3dView->Export (argv[1], anExpFormat))
Standard_ENABLE_DEPRECATION_WARNINGS
{
di << "Error: export of image to " << aFormatStr << " failed!\n";
}
@ -4277,172 +4273,6 @@ static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer th
return 0;
}
//==============================================================================
//function : VPrintView
//purpose : Test printing algorithm, print the view to image file with given
// width and height. Printing implemented only for WNT.
//==============================================================================
static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
const char** argv)
{
#ifndef _WIN32
(void )argc;
(void )argv;
di << "Printing implemented only for WNT!\n";
return 0;
#else
Handle(AIS_InteractiveContext) aContextAIS = NULL;
Handle(V3d_View) aView = NULL;
aContextAIS = ViewerTest::GetAISContext();
if (!aContextAIS.IsNull())
{
const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
Vwr->InitActiveViews();
if(Vwr->MoreActiveViews())
aView = Vwr->ActiveView();
}
// check for errors
if (aView.IsNull())
{
di << "Call vinit before!\n";
return 1;
}
else if (argc < 4)
{
di << "Use: " << argv[0];
di << " width height filename [print algo=0] [tile_width tile_height]\n";
di << "width, height of the intermediate buffer for operation\n";
di << "algo : {0|1}\n";
di << " 0 - stretch algorithm\n";
di << " 1 - tile algorithm\n";
di << "test printing algorithms into an intermediate buffer\n";
di << "using specific tile size if provided\n";
di << "with saving output to an image file\n";
return 1;
}
// get the input params
Standard_Integer aWidth = Draw::Atoi (argv[1]);
Standard_Integer aHeight = Draw::Atoi (argv[2]);
Standard_Integer aMode = 0;
TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
if (argc >= 5)
aMode = Draw::Atoi (argv[4]);
Standard_Integer aTileWidth = 0;
Standard_Integer aTileHeight = 0;
Standard_Boolean isTileSizeProvided = Standard_False;
if (argc == 7)
{
isTileSizeProvided = Standard_True;
aTileWidth = Draw::Atoi (argv[5]);
aTileHeight = Draw::Atoi (argv[6]);
}
// check the input parameters
if (aWidth <= 0 || aHeight <= 0)
{
di << "Width and height must be positive values!\n";
return 1;
}
if (aMode != 0 && aMode != 1)
aMode = 0;
// define compatible bitmap
HDC anDC = CreateCompatibleDC(0);
BITMAPINFO aBitmapData;
memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
aBitmapData.bmiHeader.biWidth = aWidth ;
aBitmapData.bmiHeader.biHeight = aHeight;
aBitmapData.bmiHeader.biPlanes = 1;
aBitmapData.bmiHeader.biBitCount = 24;
aBitmapData.bmiHeader.biXPelsPerMeter = 0;
aBitmapData.bmiHeader.biYPelsPerMeter = 0;
aBitmapData.bmiHeader.biClrUsed = 0;
aBitmapData.bmiHeader.biClrImportant = 0;
aBitmapData.bmiHeader.biCompression = BI_RGB;
aBitmapData.bmiHeader.biSizeImage = 0;
// Create Device Independent Bitmap
void* aBitsOut = NULL;
HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
&aBitsOut, NULL, 0);
HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
if (aBitsOut != NULL)
{
if (aMode == 0)
isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
else
{
if (isTileSizeProvided)
{
Handle(Graphic3d_CView) aGraphicView = ViewerTest::CurrentView()->View();
Handle(Standard_Transient) anOldBuffer = aGraphicView->FBO();
Handle(Standard_Transient) aNewBuffer = aGraphicView->FBOCreate (aTileWidth, aTileHeight);
aGraphicView->SetFBO (aNewBuffer);
isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
aGraphicView->FBORelease (aNewBuffer);
aGraphicView->SetFBO (anOldBuffer);
}
else
{
isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
}
}
// successfully printed into an intermediate buffer
if (isPrinted)
{
Image_PixMap aWrapper;
aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
aWrapper.SetTopDown (false);
Image_AlienPixMap anImageBitmap;
anImageBitmap.InitCopy (aWrapper);
isSaved = anImageBitmap.Save (aFileName);
}
else
{
di << "Print operation failed due to printing errors or\n";
di << "insufficient memory available\n";
di << "Please, try to use smaller dimensions for this test\n";
di << "command, as it allocates intermediate buffer for storing\n";
di << "the result\n";
}
}
else
{
di << "Can't allocate memory for intermediate buffer\n";
di << "Please use smaller dimensions\n";
}
if (aMemoryBitmap)
{
SelectObject (anDC, anOldBitmap);
DeleteObject (aMemoryBitmap);
DeleteDC(anDC);
}
if (!isSaved)
{
di << "Save to file operation failed. This operation may fail\n";
di << "if you don't have enough available memory, then you can\n";
di << "use smaller dimensions for the output file\n";
return 1;
}
return 0;
#endif
}
//==============================================================================
//function : VZLayer
//purpose : Test z layer operations for v3d viewer
@ -9229,9 +9059,6 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
" - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
" - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
__FILE__,VGraduatedTrihedron,group);
theCommands.Add("vprintview" ,
"vprintview : width height filename [algo=0] [tile_width tile_height] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
__FILE__,VPrintView,group);
theCommands.Add("vzlayer",
"vzlayer add/del/get/settings/enable/disable [id]\n"
" add - add new z layer to viewer and print its id\n"

View File

@ -1,44 +0,0 @@
puts "========"
puts "OCC22337"
puts "Test vprintview with new camera and shaders"
puts "========"
pload ALL
vinit
box b 10 10 10
vdisplay b
vrotate 1 0 0
vfit
vsetdispmode 1
# test vprintview work
# make sure that the images with forced tiles and without are the same
vcamera -ortho
vfit
set aTitle "ortho"
vprintview 512 512 $imagedir/${casename}_${aTitle}.png rgb
set aTitle "ortho-tiles"
vprintview 512 512 $imagedir/${casename}_${aTitle}.png rgb 1 256 256
vcamera -persp
vfit
set aTitle "persp"
vprintview 512 512 $imagedir/${casename}_${aTitle}.png rgb
set aTitle "persp-tiles"
vprintview 512 512 $imagedir/${casename}_${aTitle}.png rgb 1 256 256
vshaderprog phong
vcamera -ortho
vfit
set aTitle "ortho-shader"
vprintview 512 512 $imagedir/${casename}_${aTitle}.png rgb
set aTitle "ortho-shader-tiles"
vprintview 512 512 $imagedir/${casename}_${aTitle}.png rgb 1 256 256
vcamera -persp
vfit
set aTitle "persp-shader"
vprintview 512 512 $imagedir/${casename}_${aTitle}.png rgb
set aTitle "persp-shader-tiles"
vprintview 512 512 $imagedir/${casename}_${aTitle}.png rgb 1 256 256