0025785: Visualization - introduce AIS_ColorScale presentation for Color Scale
[occt.git] / src / V3d / V3d_View_Print.cxx
CommitLineData
b311480e 1// Created by: THA
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
7fd59977 15// e-mail t-hartl@muenchen.matra-dtv.fr
16
17/************************************************************************/
18/* Includes */
19/************************************************************************/
20
21#ifdef WNT
22#include <windows.h>
23#pragma comment( lib, "comdlg32.lib" )
24#endif
25
42cf5bc1 26
42cf5bc1 27#include <Aspect_GradientBackground.hxx>
28#include <Aspect_Grid.hxx>
29#include <Aspect_Window.hxx>
30#include <Bnd_Box.hxx>
31#include <gp_Ax3.hxx>
32#include <gp_Dir.hxx>
33#include <Graphic3d_Group.hxx>
34#include <Graphic3d_Structure.hxx>
35#include <Graphic3d_TextureEnv.hxx>
36#include <Graphic3d_Vector.hxx>
37#include <Quantity_Color.hxx>
38#include <Standard_MultiplyDefined.hxx>
7fd59977 39#include <Standard_NotImplemented.hxx>
42cf5bc1 40#include <Standard_TypeMismatch.hxx>
41#include <V3d_BadValue.hxx>
42#include <V3d_LayerMgr.hxx>
43#include <V3d_Light.hxx>
44#include <V3d_UnMapped.hxx>
45#include <V3d_View.hxx>
46#include <V3d_Viewer.hxx>
47#include <Visual3d_View.hxx>
7fd59977 48
49#ifdef WNT
50struct Device
51{
52 Device();
53 ~Device();
54
55 PRINTDLG _pd;
56};
57
58//**********************************************************************
59
60static Device device;
61
62//**********************************************************************
63
64Device::Device()
65{
66 memset(&_pd, 0, sizeof(PRINTDLG));
67 _pd.hDevNames = NULL;
68 _pd.hDevMode = NULL;
69 _pd.lStructSize = sizeof(PRINTDLG);
70}
71
72//**********************************************************************
73
74Device::~Device()
75{
76 // :TODO:
77 if (_pd.hDevNames) GlobalFree(_pd.hDevNames);
78 if (_pd.hDevMode) GlobalFree(_pd.hDevMode);
79 if (_pd.hDC) DeleteDC(_pd.hDC);
80}
81#endif
82
83/************************************************************************/
84/* Print Method */
85/************************************************************************/
86
7edf74fd
A
87Standard_Boolean V3d_View::Print (const Aspect_Handle hPrnDC,
88 const Standard_Boolean showDialog,
89 const Standard_Boolean showBackground,
90 const Standard_CString filename,
91 const Aspect_PrintAlgo printAlgorithm) const
7fd59977 92{
93#ifdef WNT
94 if( MyView->IsDefined() )
95 {
96 if (hPrnDC != NULL)
97 {
7edf74fd
A
98 return MyView->Print(hPrnDC, showBackground,
99 filename, printAlgorithm) ;
100
7fd59977 101 }
102
103 if (device._pd.hDC == NULL || showDialog )
104 {
105 if (device._pd.hDC)
106 DeleteDC(device._pd.hDC);
107 if ( !showDialog )
108 {
109 device._pd.Flags = PD_RETURNDC | PD_NOSELECTION | PD_RETURNDEFAULT;
110 }
111 else
112 {
113 device._pd.Flags = PD_RETURNDC | PD_NOSELECTION;
114 }
115
116 BOOL ispd;
117 ispd = PrintDlg((LPPRINTDLG)(&(device._pd)));
118
119 if (!ispd)
120 {
7edf74fd 121 return Standard_False;
7fd59977 122 }
123
124 if (!(device._pd.hDC))
125 {
126 if (device._pd.hDevNames)
127 {
128 GlobalFree(device._pd.hDevNames);
129 device._pd.hDevNames = NULL;
130 }
131 if (device._pd.hDevMode)
132 {
133 GlobalFree(device._pd.hDevMode);
134 device._pd.hDevMode = NULL;
135 }
136 MessageBox(0, "Couldn't create Printer Device Context", "Error", MB_OK | MB_ICONSTOP);
7edf74fd 137 return Standard_False;
7fd59977 138 }
139 }
7edf74fd
A
140
141 // process scale factor accordingly to the new printing approach
142 DEVMODE* aMode = (LPDEVMODE)GlobalLock(device._pd.hDevMode);
143
144 // convert percents to multiplication factor, 100% = 1.0
145 Standard_Real aScaleFactor = (Standard_Real) aMode->dmScale / 100.0;
146 GlobalUnlock (device._pd.hDevMode);
147 return MyView->Print(device._pd.hDC, showBackground,
148 filename, printAlgorithm, aScaleFactor) ;
7fd59977 149 }
150#else
151 Standard_NotImplemented::Raise ("V3d_View::Print is implemented only on Windows");
152#endif
7edf74fd 153 return Standard_False;
7fd59977 154}