Commit | Line | Data |
---|---|---|
b311480e | 1 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
2 | // | |
3 | // The content of this file is subject to the Open CASCADE Technology Public | |
4 | // License Version 6.5 (the "License"). You may not use the content of this file | |
5 | // except in compliance with the License. Please obtain a copy of the License | |
6 | // at http://www.opencascade.org and read it completely before using this file. | |
7 | // | |
8 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
9 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
10 | // | |
11 | // The Original Code and all software distributed under the License is | |
12 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
13 | // Initial Developer hereby disclaims all such warranties, including without | |
14 | // limitation, any warranties of merchantability, fitness for a particular | |
15 | // purpose or non-infringement. Please see the License for the specific terms | |
16 | // and conditions governing the rights and limitations under the License. | |
17 | ||
7fd59977 | 18 | /************************************************************************/ |
19 | /* Includes */ | |
20 | /************************************************************************/ | |
21 | ||
2166f0fa | 22 | #include <OpenGl_GraphicDriver.hxx> |
86fa64d9 | 23 | #include <OpenGl_Context.hxx> |
24 | #include <OpenGl_CView.hxx> | |
7fd59977 | 25 | #include <OSD_Localizer.hxx> |
26 | ||
498ce577 | 27 | #ifdef HAVE_CONFIG_H |
28 | # include <config.h> | |
29 | #endif | |
30 | ||
7fd59977 | 31 | #ifdef HAVE_GL2PS |
32 | #include <gl2ps.h> | |
33 | #endif | |
34 | ||
35 | #include <locale.h> | |
36 | ||
7fd59977 | 37 | /************************************************************************/ |
38 | /* Print Methods */ | |
39 | /************************************************************************/ | |
40 | ||
5cedc27f K |
41 | Standard_Boolean OpenGl_GraphicDriver::Export (const Standard_CString theFileName, |
42 | const Graphic3d_ExportFormat theFormat, | |
43 | const Graphic3d_SortType theSortType, | |
44 | const Standard_Integer theWidth, | |
45 | const Standard_Integer theHeight, | |
46 | const Graphic3d_CView& theView, | |
47 | const Aspect_CLayer2d& theLayerUnder, | |
48 | const Aspect_CLayer2d& theLayerOver, | |
49 | const Standard_Real /*thePrecision*/, | |
50 | const Standard_Address /*theProgressBarFunc*/, | |
51 | const Standard_Address /*theProgressObject*/) | |
7fd59977 | 52 | { |
53 | #ifdef HAVE_GL2PS | |
86fa64d9 | 54 | // gl2psBeginPage() will call OpenGL functions |
55 | // so we should activate correct GL context before redraw scene call | |
56 | const OpenGl_CView* aCView = (const OpenGl_CView* )theView.ptrView; | |
57 | if (aCView == NULL || !aCView->WS->GetGlContext()->MakeCurrent()) | |
58 | { | |
59 | return Standard_False; | |
60 | } | |
61 | ||
5cedc27f K |
62 | Standard_Integer aFormat = -1; |
63 | Standard_Integer aSortType = Graphic3d_ST_BSP_Tree; | |
64 | switch (theFormat) | |
7fd59977 | 65 | { |
5cedc27f K |
66 | case Graphic3d_EF_PostScript: |
67 | aFormat = GL2PS_PS; | |
68 | break; | |
69 | case Graphic3d_EF_EnhPostScript: | |
70 | aFormat = GL2PS_EPS; | |
71 | break; | |
72 | case Graphic3d_EF_TEX: | |
73 | aFormat = GL2PS_TEX; | |
74 | break; | |
75 | case Graphic3d_EF_PDF: | |
76 | aFormat = GL2PS_PDF; | |
77 | break; | |
78 | case Graphic3d_EF_SVG: | |
79 | aFormat = GL2PS_SVG; | |
80 | break; | |
81 | case Graphic3d_EF_PGF: | |
82 | aFormat = GL2PS_PGF; | |
83 | break; | |
84 | case Graphic3d_EF_EMF: | |
85 | //aFormat = GL2PS_EMF; | |
86 | aFormat = GL2PS_PGF + 1; // 6 | |
87 | break; | |
88 | default: | |
89 | // unsupported format | |
90 | return Standard_False; | |
7fd59977 | 91 | } |
92 | ||
5cedc27f | 93 | switch (theSortType) |
7fd59977 | 94 | { |
5cedc27f K |
95 | case Graphic3d_ST_Simple: |
96 | aSortType = GL2PS_SIMPLE_SORT; | |
97 | break; | |
98 | case Graphic3d_ST_BSP_Tree: | |
99 | aSortType = GL2PS_BSP_SORT; | |
100 | break; | |
101 | } | |
102 | ||
103 | GLint aViewport[4]; | |
104 | aViewport[0] = 0; | |
105 | aViewport[1] = 0; | |
106 | aViewport[2] = theWidth; | |
107 | aViewport[3] = theHeight; | |
7fd59977 | 108 | |
5cedc27f K |
109 | GLint aBufferSize = 1024 * 1024; |
110 | GLint anErrCode = GL2PS_SUCCESS; | |
7fd59977 | 111 | |
5cedc27f K |
112 | // gl2ps uses standard write functions and do not check locale |
113 | OSD_Localizer locate (LC_NUMERIC, "C"); | |
7fd59977 | 114 | |
5cedc27f | 115 | while (aBufferSize > 0) |
7fd59977 | 116 | { |
5cedc27f K |
117 | // current patch for EMF support in gl2ps uses WinAPI functions to create file |
118 | FILE* aFileH = (theFormat != Graphic3d_EF_EMF) ? fopen (theFileName, "wb") : NULL; | |
119 | anErrCode = gl2psBeginPage ("", "", aViewport, aFormat, aSortType, | |
7fd59977 | 120 | GL2PS_DRAW_BACKGROUND | GL2PS_OCCLUSION_CULL | GL2PS_BEST_ROOT/* | GL2PS_SIMPLE_LINE_OFFSET*/, |
121 | GL_RGBA, 0, NULL, | |
5cedc27f K |
122 | 0, 0, 0, aBufferSize, aFileH, theFileName); |
123 | if (anErrCode != GL2PS_SUCCESS) | |
124 | { | |
125 | // initialization failed | |
126 | if (aFileH != NULL) | |
127 | fclose (aFileH); | |
128 | break; | |
129 | } | |
130 | Redraw (theView, theLayerUnder, theLayerOver); | |
131 | ||
132 | anErrCode = gl2psEndPage(); | |
133 | if (aFileH != NULL) | |
134 | fclose (aFileH); | |
135 | ||
136 | if (anErrCode == GL2PS_OVERFLOW) | |
137 | aBufferSize *= 2; | |
138 | else | |
139 | break; | |
7fd59977 | 140 | } |
141 | ||
142 | locate.Restore(); | |
5cedc27f K |
143 | return anErrCode == GL2PS_SUCCESS; |
144 | #else | |
145 | return Standard_False; | |
7fd59977 | 146 | #endif |
7fd59977 | 147 | } |