0022819: Redesign of OpenGl driver Additional integration
[occt.git] / src / OpenGl / OpenGl_GraphicDriver_Export.cxx
CommitLineData
7fd59977 1/************************************************************************/
2/* Includes */
3/************************************************************************/
4
2166f0fa 5#include <OpenGl_GraphicDriver.hxx>
7fd59977 6#include <OSD_Localizer.hxx>
7
8#ifdef HAVE_GL2PS
9#include <gl2ps.h>
10#endif
11
12#include <locale.h>
13
7fd59977 14/************************************************************************/
15/* Print Methods */
16/************************************************************************/
17
5cedc27f
K
18Standard_Boolean OpenGl_GraphicDriver::Export (const Standard_CString theFileName,
19 const Graphic3d_ExportFormat theFormat,
20 const Graphic3d_SortType theSortType,
21 const Standard_Integer theWidth,
22 const Standard_Integer theHeight,
23 const Graphic3d_CView& theView,
24 const Aspect_CLayer2d& theLayerUnder,
25 const Aspect_CLayer2d& theLayerOver,
26 const Standard_Real /*thePrecision*/,
27 const Standard_Address /*theProgressBarFunc*/,
28 const Standard_Address /*theProgressObject*/)
7fd59977 29{
30#ifdef HAVE_GL2PS
5cedc27f
K
31 Standard_Integer aFormat = -1;
32 Standard_Integer aSortType = Graphic3d_ST_BSP_Tree;
33 switch (theFormat)
7fd59977 34 {
5cedc27f
K
35 case Graphic3d_EF_PostScript:
36 aFormat = GL2PS_PS;
37 break;
38 case Graphic3d_EF_EnhPostScript:
39 aFormat = GL2PS_EPS;
40 break;
41 case Graphic3d_EF_TEX:
42 aFormat = GL2PS_TEX;
43 break;
44 case Graphic3d_EF_PDF:
45 aFormat = GL2PS_PDF;
46 break;
47 case Graphic3d_EF_SVG:
48 aFormat = GL2PS_SVG;
49 break;
50 case Graphic3d_EF_PGF:
51 aFormat = GL2PS_PGF;
52 break;
53 case Graphic3d_EF_EMF:
54 //aFormat = GL2PS_EMF;
55 aFormat = GL2PS_PGF + 1; // 6
56 break;
57 default:
58 // unsupported format
59 return Standard_False;
7fd59977 60 }
61
5cedc27f 62 switch (theSortType)
7fd59977 63 {
5cedc27f
K
64 case Graphic3d_ST_Simple:
65 aSortType = GL2PS_SIMPLE_SORT;
66 break;
67 case Graphic3d_ST_BSP_Tree:
68 aSortType = GL2PS_BSP_SORT;
69 break;
70 }
71
72 GLint aViewport[4];
73 aViewport[0] = 0;
74 aViewport[1] = 0;
75 aViewport[2] = theWidth;
76 aViewport[3] = theHeight;
7fd59977 77
5cedc27f
K
78 GLint aBufferSize = 1024 * 1024;
79 GLint anErrCode = GL2PS_SUCCESS;
7fd59977 80
5cedc27f
K
81 // gl2ps uses standard write functions and do not check locale
82 OSD_Localizer locate (LC_NUMERIC, "C");
7fd59977 83
5cedc27f 84 while (aBufferSize > 0)
7fd59977 85 {
5cedc27f
K
86 // current patch for EMF support in gl2ps uses WinAPI functions to create file
87 FILE* aFileH = (theFormat != Graphic3d_EF_EMF) ? fopen (theFileName, "wb") : NULL;
88 anErrCode = gl2psBeginPage ("", "", aViewport, aFormat, aSortType,
7fd59977 89 GL2PS_DRAW_BACKGROUND | GL2PS_OCCLUSION_CULL | GL2PS_BEST_ROOT/* | GL2PS_SIMPLE_LINE_OFFSET*/,
90 GL_RGBA, 0, NULL,
5cedc27f
K
91 0, 0, 0, aBufferSize, aFileH, theFileName);
92 if (anErrCode != GL2PS_SUCCESS)
93 {
94 // initialization failed
95 if (aFileH != NULL)
96 fclose (aFileH);
97 break;
98 }
99 Redraw (theView, theLayerUnder, theLayerOver);
100
101 anErrCode = gl2psEndPage();
102 if (aFileH != NULL)
103 fclose (aFileH);
104
105 if (anErrCode == GL2PS_OVERFLOW)
106 aBufferSize *= 2;
107 else
108 break;
7fd59977 109 }
110
111 locate.Restore();
5cedc27f
K
112 return anErrCode == GL2PS_SUCCESS;
113#else
114 return Standard_False;
7fd59977 115#endif
7fd59977 116}