Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/* $Id: CreateFile.cpp,v 1.1 2000-12-29 10:27:29 geuzaine Exp $ */
#include "Gmsh.h"
#include "GmshUI.h"
#include "Mesh.h"
#include "Main.h"
#include "Draw.h"
#include "Context.h"
extern Context_T CTX;
extern Mesh M;
#ifdef _XMOTIF
#include <unistd.h>
#include "Widgets.h"
#include "XContext.h"
#include "XDump.h"
extern Widgets_T WID;
extern XContext_T XCTX;
#endif
#include "gl2ps.h"
#include "gl2gif.h"
#include "gl2jpeg.h"
#include "gl2ppm.h"
#include "gl2yuv.h"
void CreateFile (char *name, int format) {
FILE *tmp, *fp;
GLint size3d;
char cmd[1000], ext[10];
char *tmpFileName="tmp.xwd";
int res;
CTX.print.gl_fonts = 1;
switch(format){
case FORMAT_AUTO :
if(strlen(name) < 4)
Msg(ERROR, "Unknown Extension for Automatic Format Detection");
else{
strcpy(ext,name+(strlen(name)-4));
if(!strcmp(ext,".geo")) CreateFile(name, FORMAT_GEO);
else if(!strcmp(ext,".msh")) CreateFile(name, FORMAT_MSH);
else if(!strcmp(ext,".unv")) CreateFile(name, FORMAT_UNV);
else if(!strcmp(ext,".gif")) CreateFile(name, FORMAT_GIF);
else if(!strcmp(ext,".jpg")) CreateFile(name, FORMAT_JPEG);
else if(!strcmp(ext,".eps")) CreateFile(name, FORMAT_EPS);
else if(!strcmp(ext,".xpm")) CreateFile(name, FORMAT_XPM);
else if(!strcmp(ext,".ppm")) CreateFile(name, FORMAT_PPM);
else if(!strcmp(ext,".yuv")) CreateFile(name, FORMAT_YUV);
else {
if(strlen(name) < 5)
Msg(ERROR, "Unknown Extension for Automatic Format Detection");
else{
strcpy(ext,name+(strlen(name)-5));
if(!strcmp(ext,".jpeg")) CreateFile(name, FORMAT_JPEG);
else if(!strcmp(ext,".gref")) CreateFile(name, FORMAT_GREF);
else if(!strcmp(ext,".Gref")) CreateFile(name, FORMAT_GREF);
else Msg(ERROR, "Unknown Extension \"%s\" for Automatic Format Detection", ext);
}
}
}
break;
case FORMAT_GEO :
Print_Geo(&M, name);
break;
case FORMAT_MSH :
Print_Mesh(&M, name, FORMAT_MSH);
break;
case FORMAT_UNV :
Print_Mesh(&M, name, FORMAT_UNV);
break;
case FORMAT_GREF :
Print_Mesh(&M, name, FORMAT_GREF);
break;
#ifdef _XMOTIF
case FORMAT_XPM :
if(!(fp = fopen(name,"wb"))) {
Msg(WARNING, "Unable to Open File '%s'", name);
return;
}
Window_Dump(XCTX.display, XCTX.scrnum, XtWindow(WID.G.glw), fp);
Msg(INFOS, "XPM Creation Complete '%s'", name);
Msg (INFO, "Wrote File '%s'", name);
fclose(fp);
break;
#endif
case FORMAT_JPEG :
if(!(fp = fopen(name,"wb"))) {
Msg(WARNING, "Unable to Open File '%s'", name);
return;
}
Replot();
create_jpeg(fp, CTX.viewport[2]-CTX.viewport[0],
CTX.viewport[3]-CTX.viewport[1],
CTX.print.jpeg_quality);
Msg(INFOS, "JPEG Creation Complete '%s'", name);
Msg (INFO, "Wrote File '%s'", name);
fclose(fp);
break;
case FORMAT_GIF :
if(!(fp = fopen(name,"wb"))) {
Msg(WARNING, "Unable to Open File '%s'", name);
return;
}
Replot();
create_gif(fp, CTX.viewport[2]-CTX.viewport[0],
CTX.viewport[3]-CTX.viewport[1],
CTX.print.gif_dither,
CTX.print.gif_sort,
CTX.print.gif_interlace,
CTX.print.gif_transparent,
UNPACK_RED(CTX.color.bg),
UNPACK_GREEN(CTX.color.bg),
UNPACK_BLUE(CTX.color.bg));
Msg(INFOS, "GIF Creation Complete '%s'", name);
Msg (INFO, "Wrote File '%s'", name);
fclose(fp);
break;
case FORMAT_PPM :
if(!(fp = fopen(name,"wb"))) {
Msg(WARNING, "Unable to Open File '%s'", name);
return;
}
Replot();
create_ppm(fp, CTX.viewport[2]-CTX.viewport[0],
CTX.viewport[3]-CTX.viewport[1]);
Msg(INFOS, "PPM Creation Complete '%s'", name);
Msg (INFO, "Wrote File '%s'", name);
fclose(fp);
break;
case FORMAT_YUV :
if(!(fp = fopen(name,"wb"))) {
Msg(WARNING, "Unable to Open File '%s'", name);
return;
}
Replot();
create_yuv(fp, CTX.viewport[2]-CTX.viewport[0],
CTX.viewport[3]-CTX.viewport[1]);
Msg(INFOS, "YUV Creation Complete '%s'", name);
Msg (INFO, "Wrote File '%s'", name);
fclose(fp);
break;
case FORMAT_EPS :
switch(CTX.print.eps_quality){
#ifdef _XMOTIF
case 0 : // Bitmap EPS
if(!(fp = fopen(name,"w"))) {
Msg(WARNING, "Unable to Open File '%s'", name);
return;
}
if(!(tmp = fopen(tmpFileName,"w"))){
Msg(WARNING, "Unable to Open File '%s'", tmpFileName);
return;
}
Window_Dump(XCTX.display, XCTX.scrnum, XtWindow(WID.G.glw), tmp);
fclose(tmp);
sprintf(cmd, "xpr -device ps -gray 4 %s >%s", tmpFileName, name);
Msg(INFOS, "Executing '%s'", cmd);
system(cmd);
unlink(tmpFileName);
Msg(INFOS, "Bitmap EPS Creation Complete '%s'", name);
Msg (INFO, "Wrote File '%s'", name);
fclose(fp);
break;
#endif
default : // Vector EPS
if(!(fp = fopen(name,"w"))) {
Msg(WARNING, "Unable to Open File '%s'", name);
return;
}
CTX.print.gl_fonts = 0;
size3d = 0 ;
res = GL2PS_OVERFLOW ;
while(res == GL2PS_OVERFLOW){
size3d += 2048*2048 ;
gl2psBeginPage(TheBaseFileName, "Gmsh",
(CTX.print.eps_quality == 1 ? GL2PS_SIMPLE_SORT : GL2PS_BSP_SORT),
GL2PS_SIMPLE_LINE_OFFSET | GL2PS_DRAW_BACKGROUND,
GL_RGBA, 0, NULL, size3d, fp);
CTX.stream = TO_FILE ;
Init();
Draw();
CTX.stream = TO_SCREEN ;
res = gl2psEndPage();
}
Msg(INFOS, "EPS Creation Complete '%s'", name);
Msg (INFO, "Wrote File '%s'", name);
fclose(fp);
CTX.print.gl_fonts = 1;
break;
}
break ;
default :
Msg(WARNING, "Unknown Print Format");
break;
}
}