1 | // Module PI : Peida Interactive PIGraphicPS
|
---|
2 | // Trace graphiques en PostScript R. Ansari 97
|
---|
3 | // LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA
|
---|
4 |
|
---|
5 | #include <stdio.h>
|
---|
6 |
|
---|
7 | #include "pigraphps.h"
|
---|
8 |
|
---|
9 | //++
|
---|
10 | // Class PIGraphicPS
|
---|
11 | // Lib PI
|
---|
12 | // include pigraphps.h
|
---|
13 | //
|
---|
14 | // Classe les services de tracé graphique avec sortie PostScript
|
---|
15 | // Toutes les méthodes de tracé de "PIGraphic" sont redéfinies pour
|
---|
16 | // produire du PostScript
|
---|
17 | //--
|
---|
18 | //++
|
---|
19 | // Links Parent
|
---|
20 | // PIGraphic
|
---|
21 | //--
|
---|
22 | //++
|
---|
23 | // Links Voir aussi
|
---|
24 | // PSFile
|
---|
25 | //--
|
---|
26 |
|
---|
27 | //++
|
---|
28 | // Titre Constructeurs, méthodes
|
---|
29 | //--
|
---|
30 | //++
|
---|
31 | // PIGraphicPS(PSFile * psf, double x0, double y0, double dx, double dy)
|
---|
32 | // Création d'un objet "PIGraphicPS" à partir d'un objet "PSFIle* psf".
|
---|
33 | // "(x0, y0)" détermine l'origine du nouveau bloc rectangulaire sur
|
---|
34 | // la page et "dx, dy" l'extension du bloc.
|
---|
35 | // PIGraphicPS(PSFile * psf, PIWdg* wdg, double ofx, double ofy)
|
---|
36 | // Création d'un objet "PIGraphicPS" à partir d'un objet "PSFIle* psf"
|
---|
37 | //| x0 = wdg->XPos()+ofx y0 = wdg->YPos()+ofy
|
---|
38 | //| dx = wdg->XSize() dy = wdg->YSize()
|
---|
39 | //
|
---|
40 | // int kind()
|
---|
41 | // Renvoie le type ("= PI_PSFileGraphics")
|
---|
42 | //--
|
---|
43 |
|
---|
44 | /* --Methode-- */
|
---|
45 | PIGraphicPS::PIGraphicPS(PSFile * psf, PIWdg* wdg, double ofx, double ofy)
|
---|
46 | : PIGraphicGen()
|
---|
47 | {
|
---|
48 | BuildFromPSFile(psf, (double)wdg->XPos()+ofx, (double)wdg->YPos()+ofy,
|
---|
49 | (double)wdg->XSize(), (double)wdg->YSize() );
|
---|
50 | }
|
---|
51 |
|
---|
52 | /* --Methode-- */
|
---|
53 | PIGraphicPS::PIGraphicPS(PSFile * psf, double x0, double y0, double dx, double dy)
|
---|
54 | : PIGraphicGen()
|
---|
55 | {
|
---|
56 | BuildFromPSFile(psf, x0, y0, dx, dy);
|
---|
57 | }
|
---|
58 |
|
---|
59 | /* --Methode-- */
|
---|
60 | PIGraphicPS::~PIGraphicPS()
|
---|
61 | {
|
---|
62 | mPSOut->EndBloc();
|
---|
63 | }
|
---|
64 |
|
---|
65 | /* --Methode-- */
|
---|
66 | int PIGraphicPS::kind()
|
---|
67 | {
|
---|
68 | return PI_PSFileGraphics;
|
---|
69 | }
|
---|
70 |
|
---|
71 |
|
---|
72 | /* --Methode-- */
|
---|
73 | void PIGraphicPS::BuildFromPSFile(PSFile * psf, double x0, double y0, double dx, double dy)
|
---|
74 | {
|
---|
75 | mPSOut = psf;
|
---|
76 |
|
---|
77 | mGOm = PI_GOCopy;
|
---|
78 |
|
---|
79 | mFCol = mBCol = PI_Grey;
|
---|
80 | SelForeground(PI_Black);
|
---|
81 | SelBackground(PI_White);
|
---|
82 | mLAtt = PI_ThinLine;
|
---|
83 | SelLine();
|
---|
84 | mFAtt = PI_BoldFont; mFSize = 0;
|
---|
85 | SelFont();
|
---|
86 | SelMarker(1, PI_DotMarker);
|
---|
87 |
|
---|
88 | if (psf) psf->NewBloc(x0, y0, dx, dy, dx, dy);
|
---|
89 | mXmin = mYmin = 0.;
|
---|
90 | mXmax = dx; mYmax = dy;
|
---|
91 | mFCfMap.red = mFCfMap.blue = mFCfMap.blue = 0;
|
---|
92 | mBCfMap = mFCfMap;
|
---|
93 | }
|
---|
94 |
|
---|
95 | /* --Methode-- */
|
---|
96 | void PIGraphicPS::GetGrSpace(PIGrCoord& xmin, PIGrCoord& xmax, PIGrCoord& ymin, PIGrCoord& ymax)
|
---|
97 | {
|
---|
98 | xmin = ymin = 0;
|
---|
99 | xmax = mXmax; ymax = mYmax;
|
---|
100 | }
|
---|
101 |
|
---|
102 | /* --Methode-- */
|
---|
103 | void PIGraphicPS::Erase(PIGrCoord, PIGrCoord, PIGrCoord, PIGrCoord)
|
---|
104 | {
|
---|
105 | // A Faire ??? $CHECK$
|
---|
106 | return;
|
---|
107 | }
|
---|
108 |
|
---|
109 | /* --Methode-- */
|
---|
110 | void PIGraphicPS::DrawString(PIGrCoord x, PIGrCoord y, const char* s, int /*pos*/)
|
---|
111 | {
|
---|
112 | if(mPSOut)
|
---|
113 | mPSOut->DrawString((double)x,(double)y,s,mFCol,mFAtt,mFSize); /* $CHECK$ PIFontSize ?? */
|
---|
114 | return;
|
---|
115 | }
|
---|
116 |
|
---|
117 | /* --Methode-- */
|
---|
118 | void PIGraphicPS::DrawOpaqueString(PIGrCoord x, PIGrCoord y, const char* s, int /*pos*/)
|
---|
119 | {
|
---|
120 | if(mPSOut)
|
---|
121 | mPSOut->DrawString((double)x,(double)y,s,mFCol,mFAtt,mFSize); /* $CHECK$ PIFontSize ?? */
|
---|
122 | return;
|
---|
123 | }
|
---|
124 |
|
---|
125 |
|
---|
126 | /* --Methode-- */
|
---|
127 | void PIGraphicPS::DrawLine(PIGrCoord x1, PIGrCoord y1, PIGrCoord x2, PIGrCoord y2)
|
---|
128 | {
|
---|
129 | if(mPSOut)
|
---|
130 | mPSOut->DrawLine((double)x1,(double)y1,(double)x2,(double)y2,mFCol,mLAtt);
|
---|
131 | return;
|
---|
132 | }
|
---|
133 |
|
---|
134 |
|
---|
135 | /* --Methode-- */
|
---|
136 | void PIGraphicPS::DrawBox(PIGrCoord x0, PIGrCoord y0, PIGrCoord dx, PIGrCoord dy)
|
---|
137 | {
|
---|
138 | if(mPSOut)
|
---|
139 | mPSOut->DrawBox((double)x0,(double)y0,(double)dx,(double)dy,mFCol,mLAtt);
|
---|
140 | return;
|
---|
141 | }
|
---|
142 |
|
---|
143 | /* --Methode-- */
|
---|
144 | void PIGraphicPS::DrawFBox(PIGrCoord x0, PIGrCoord y0, PIGrCoord dx, PIGrCoord dy)
|
---|
145 | {
|
---|
146 | if(mPSOut)
|
---|
147 | mPSOut->DrawFBox((double)x0,(double)y0,(double)dx,(double)dy, mFCol, mFCol, mLAtt);
|
---|
148 | return;
|
---|
149 | }
|
---|
150 |
|
---|
151 | /* --Methode-- */
|
---|
152 | void PIGraphicPS::DrawCircle(PIGrCoord x0, PIGrCoord y0, PIGrCoord r)
|
---|
153 | {
|
---|
154 | if(mPSOut)
|
---|
155 | mPSOut->DrawCircle((double)x0,(double)y0,(double)r,mFCol,mLAtt);
|
---|
156 | return;
|
---|
157 | }
|
---|
158 |
|
---|
159 | /* --Methode-- */
|
---|
160 | void PIGraphicPS::DrawFCircle(PIGrCoord x0, PIGrCoord y0, PIGrCoord r)
|
---|
161 | {
|
---|
162 | if(mPSOut)
|
---|
163 | mPSOut->DrawFCircle((double)x0,(double)y0,(double)r,mFCol,mFCol,mLAtt);
|
---|
164 | return;
|
---|
165 | }
|
---|
166 |
|
---|
167 | /* --Methode-- */
|
---|
168 | void PIGraphicPS::DrawOval(PIGrCoord x0, PIGrCoord y0, PIGrCoord dx, PIGrCoord dy)
|
---|
169 | {
|
---|
170 | // $CHECK$ Reza/ Nicolas 12 Nov 98 - A faire
|
---|
171 | }
|
---|
172 |
|
---|
173 | /* --Methode-- */
|
---|
174 | void PIGraphicPS::DrawFOval(PIGrCoord x0, PIGrCoord y0, PIGrCoord dx, PIGrCoord dy)
|
---|
175 | {
|
---|
176 | // $CHECK$ Reza/ Nicolas 12 Nov 98 - A faire
|
---|
177 | }
|
---|
178 |
|
---|
179 | /* --Methode-- */
|
---|
180 | void PIGraphicPS::DrawPolygon(PIGrCoord *x, PIGrCoord *y, int n, bool cinc)
|
---|
181 | {
|
---|
182 | int i;
|
---|
183 | double *xtmp;
|
---|
184 | double *ytmp;
|
---|
185 |
|
---|
186 | if(! mPSOut) return;
|
---|
187 |
|
---|
188 | xtmp = new double[n];
|
---|
189 | ytmp = new double[n];
|
---|
190 | for(i = 0 ; i < n ; i++) {xtmp[i] = (double)x[i] ; ytmp[i] = (double)y[i] ; }
|
---|
191 | //double xoff,yoff;
|
---|
192 | //if (cinc) { xoff=yoff=0.; } // Coord en mode incremental
|
---|
193 | //else { xoff = (double)x[0]; yoff = (double)y[0]; } // Coord en mode absolu
|
---|
194 | //xtmp[0] = (double)x[0];
|
---|
195 | //ytmp[0] = (double)y[0];
|
---|
196 | //for(i=1;i<n;i++) {
|
---|
197 | // xtmp[i] = (double)x[i]-xoff;
|
---|
198 | // ytmp[i] = (double)y[i]-yoff;
|
---|
199 | //}
|
---|
200 | mPSOut->DrawPolygon(xtmp,ytmp,n,mFCol,mLAtt,cinc);
|
---|
201 | delete[] xtmp;
|
---|
202 | delete[] ytmp;
|
---|
203 |
|
---|
204 | return;
|
---|
205 | }
|
---|
206 |
|
---|
207 |
|
---|
208 | /* --Methode-- */
|
---|
209 | void PIGraphicPS::DrawFPolygon(PIGrCoord *x, PIGrCoord *y, int n, bool cinc)
|
---|
210 | {
|
---|
211 | int i;
|
---|
212 | double *xtmp;
|
---|
213 | double *ytmp;
|
---|
214 |
|
---|
215 | if(! mPSOut) return;
|
---|
216 |
|
---|
217 | xtmp = new double[n];
|
---|
218 | ytmp = new double[n];
|
---|
219 | for(i = 0 ; i < n ; i++) {xtmp[i] = (double)x[i] ; ytmp[i] = (double)y[i] ; }
|
---|
220 | //double xoff,yoff;
|
---|
221 | //if (cinc) { xoff=yoff=0.; } // Coord en mode incremental
|
---|
222 | //else { xoff = (double)x[0]; yoff = (double)y[0]; } // Coord en mode absolu
|
---|
223 | //xtmp[0] = (double)x[0];
|
---|
224 | //ytmp[0] = (double)y[0];
|
---|
225 | //for(i=1;i<n;i++) {
|
---|
226 | // xtmp[i] = (double)x[i]-xoff;
|
---|
227 | // ytmp[i] = (double)y[i]-yoff;
|
---|
228 | //}
|
---|
229 | mPSOut->DrawFPolygon(xtmp,ytmp,n,mFCol,mFCol,mLAtt,cinc);
|
---|
230 | delete[] xtmp;
|
---|
231 | delete[] ytmp;
|
---|
232 |
|
---|
233 | return;
|
---|
234 | }
|
---|
235 |
|
---|
236 | /* --Methode-- */
|
---|
237 | void PIGraphicPS::DrawArc(PIGrCoord x0, PIGrCoord y0, PIGrCoord dx, PIGrCoord dy,double degdeb, double degfin)
|
---|
238 | {
|
---|
239 | // $CHECK$ Reza/ Nicolas 12 Nov 98 - A faire
|
---|
240 | }
|
---|
241 |
|
---|
242 | /* --Methode-- */
|
---|
243 | void PIGraphicPS::DrawFArc(PIGrCoord x0, PIGrCoord y0, PIGrCoord dx, PIGrCoord dy,double degdeb, double degfin)
|
---|
244 | {
|
---|
245 | // $CHECK$ Reza/ Nicolas 12 Nov 98 - A faire
|
---|
246 | }
|
---|
247 |
|
---|
248 | /* --Methode-- */
|
---|
249 | void PIGraphicPS::DrawMarker(PIGrCoord x0, PIGrCoord y0)
|
---|
250 | {
|
---|
251 | if(mPSOut)
|
---|
252 | mPSOut->DrawMarker((double)x0,(double)y0,mMrk,mFCol,mMrkSz);
|
---|
253 | return;
|
---|
254 | }
|
---|
255 |
|
---|
256 | /* --Methode-- */
|
---|
257 | void PIGraphicPS::DrawMarkers(PIGrCoord *x, PIGrCoord *y, int n)
|
---|
258 | {
|
---|
259 | int i;
|
---|
260 | double *xtmp;
|
---|
261 | double *ytmp;
|
---|
262 |
|
---|
263 | if( !mPSOut) return;
|
---|
264 |
|
---|
265 | xtmp = new double[n];
|
---|
266 | ytmp = new double[n];
|
---|
267 | for(i=0;i<n;i++){
|
---|
268 | xtmp[i] = (double)x[i];
|
---|
269 | ytmp[i] = (double)y[i];
|
---|
270 | }
|
---|
271 | mPSOut->DrawMarkers(xtmp,ytmp,n,mMrk,mFCol, mMrkSz);
|
---|
272 | delete[] xtmp;
|
---|
273 | delete[] ytmp;
|
---|
274 |
|
---|
275 | return;
|
---|
276 | }
|
---|
277 |
|
---|
278 |
|
---|
279 | /* --Methode-- */
|
---|
280 | void PIGraphicPS::DrawPixmap(PIGrCoord x, PIGrCoord y, unsigned char *pix,
|
---|
281 | int sx, int sy, PIColorMap* cmap)
|
---|
282 | {
|
---|
283 | if ( (sx < 1) || (sy < 1) ) return;
|
---|
284 | if ((pix == NULL) || (cmap == NULL)) return;
|
---|
285 | if(mPSOut)
|
---|
286 | mPSOut->Image((double)x, (double)y, (double)sx, (double)sy, sx, sy, pix, cmap);
|
---|
287 | return;
|
---|
288 | }
|
---|
289 |
|
---|
290 | /* --Methode-- */
|
---|
291 | void PIGraphicPS::SelForeground(PIColors col)
|
---|
292 | {
|
---|
293 | mFCol = col;
|
---|
294 | return;
|
---|
295 | }
|
---|
296 |
|
---|
297 | /* --Methode-- */
|
---|
298 | void PIGraphicPS::SelBackground(PIColors col)
|
---|
299 | {
|
---|
300 | mBCol = col;
|
---|
301 | return;
|
---|
302 | }
|
---|
303 |
|
---|
304 | /* --Methode-- */
|
---|
305 | void PIGraphicPS::SelForeground(PIColorMap& cmap, int cid)
|
---|
306 | {
|
---|
307 | // A Faire Voir Nicolas
|
---|
308 | mFCfMap = cmap.GetColor(cid);
|
---|
309 | mFCol = PI_ColorFromMap;
|
---|
310 | mPSOut->SelForeground(cmap, cid) ;
|
---|
311 | return;
|
---|
312 | }
|
---|
313 |
|
---|
314 | /* --Methode-- */
|
---|
315 | void PIGraphicPS::SelBackground(PIColorMap& cmap, int cid)
|
---|
316 | {
|
---|
317 | // A Faire Voir Nicolas
|
---|
318 | mBCfMap = cmap.GetColor(cid);
|
---|
319 | mBCol = PI_ColorFromMap;
|
---|
320 | return;
|
---|
321 | }
|
---|
322 |
|
---|
323 | /* --Methode-- */
|
---|
324 | void PIGraphicPS::SelGOMode(PIGOMode mod)
|
---|
325 | {
|
---|
326 | mGOm = mod;
|
---|
327 | return;
|
---|
328 | }
|
---|
329 |
|
---|
330 | /* --Methode-- */
|
---|
331 | void PIGraphicPS::SelFontSzPt(int npt, PIFontAtt att)
|
---|
332 | {
|
---|
333 | mFSize = npt;
|
---|
334 | mFAtt = att;
|
---|
335 | return;
|
---|
336 | }
|
---|
337 |
|
---|
338 | static int fntsz[5] = {8,10,12,14,16};
|
---|
339 |
|
---|
340 | /* --Methode-- */
|
---|
341 | void PIGraphicPS::SelFont(PIFontSize sz, PIFontAtt att)
|
---|
342 | {
|
---|
343 | int i;
|
---|
344 | switch (sz) {
|
---|
345 | case PI_SmallSizeFont:
|
---|
346 | i = 0;
|
---|
347 | break;
|
---|
348 | case PI_NormalSizeFont:
|
---|
349 | i = 2;
|
---|
350 | break;
|
---|
351 | case PI_BigSizeFont:
|
---|
352 | i = 4;
|
---|
353 | break;
|
---|
354 | default:
|
---|
355 | i=2;
|
---|
356 | break;
|
---|
357 | }
|
---|
358 | mFSize = fntsz[i];
|
---|
359 | mFAtt = att;
|
---|
360 | return;
|
---|
361 | }
|
---|
362 |
|
---|
363 |
|
---|
364 |
|
---|
365 | /* --Methode-- */
|
---|
366 | void PIGraphicPS::SelLine(PILineAtt att)
|
---|
367 | {
|
---|
368 | mLAtt = att;
|
---|
369 | return;
|
---|
370 | }
|
---|
371 |
|
---|
372 |
|
---|
373 | /* --Methode-- */
|
---|
374 | void PIGraphicPS::SelMarker(int msz, PIMarker mrk)
|
---|
375 | {
|
---|
376 | if (msz > 1) { mMrk = mrk; mMrkSz = msz; }
|
---|
377 | else { mMrk = PI_DotMarker; mMrkSz = 1; }
|
---|
378 | return;
|
---|
379 | }
|
---|
380 |
|
---|
381 |
|
---|
382 | /* --Methode-- */
|
---|
383 | void PIGraphicPS::SetClipRectangle(PIGrCoord /*x0*/, PIGrCoord /*y0*/, PIGrCoord /*dx*/, PIGrCoord /*dy*/)
|
---|
384 | {
|
---|
385 | /* $CHECK$ A FAIRE , voir Nicolas */
|
---|
386 | return;
|
---|
387 | }
|
---|
388 |
|
---|
389 | /* --Methode-- */
|
---|
390 | void PIGraphicPS::ClearClipRectangle()
|
---|
391 | {
|
---|
392 | /* $CHECK$ A FAIRE , voir Nicolas */
|
---|
393 | return;
|
---|
394 | }
|
---|
395 |
|
---|
396 | /* --Methode-- */
|
---|
397 | PIColors PIGraphicPS::GetForeground()
|
---|
398 | {
|
---|
399 | return (mFCol);
|
---|
400 | }
|
---|
401 |
|
---|
402 | /* --Methode-- */
|
---|
403 | PIColors PIGraphicPS::GetBackground()
|
---|
404 | {
|
---|
405 | return (mBCol);
|
---|
406 | }
|
---|
407 |
|
---|
408 |
|
---|
409 | /* --Methode-- */
|
---|
410 | PIGOMode PIGraphicPS::GetGOMode()
|
---|
411 | {
|
---|
412 | return (mGOm);
|
---|
413 | }
|
---|
414 |
|
---|
415 | /* --Methode-- */
|
---|
416 | PIFontAtt PIGraphicPS::GetFontAtt()
|
---|
417 | {
|
---|
418 | return (mFAtt);
|
---|
419 | }
|
---|
420 |
|
---|
421 | /* --Methode-- */
|
---|
422 | int PIGraphicPS::GetFontSize()
|
---|
423 | {
|
---|
424 | return (mFSize);
|
---|
425 | }
|
---|
426 |
|
---|
427 | /* --Methode-- */
|
---|
428 | PILineAtt PIGraphicPS::GetLineAtt()
|
---|
429 | {
|
---|
430 | return (mLAtt);
|
---|
431 | }
|
---|
432 |
|
---|
433 | /* --Methode-- */
|
---|
434 | PIMarker PIGraphicPS::GetMarker()
|
---|
435 | {
|
---|
436 | return (mMrk);
|
---|
437 | }
|
---|
438 |
|
---|
439 | /* --Methode-- */
|
---|
440 | int PIGraphicPS::GetMarkerSize()
|
---|
441 | {
|
---|
442 | return (mMrkSz);
|
---|
443 | }
|
---|
444 |
|
---|
445 | /* --Methode-- */
|
---|
446 | int PIGraphicPS::GetFontHeight(int& asc, int& desc)
|
---|
447 | {
|
---|
448 | /* $CHECK$ A refaire , voir Nicolas */
|
---|
449 | asc = mFSize; desc = 0;
|
---|
450 | return(asc+desc);
|
---|
451 | }
|
---|
452 |
|
---|
453 |
|
---|
454 | /* --Methode-- */
|
---|
455 | PIGrCoord PIGraphicPS::CalcStringWidth(char const* s)
|
---|
456 | {
|
---|
457 | return((double)(mFSize*strlen(s)*0.5)); /* facteur 0.5 ad'hoc $CHECK$ Voir Nicolas ! */
|
---|
458 | }
|
---|
459 |
|
---|
460 | /* --Methode-- */
|
---|
461 | void PIGraphicPS::SaveGraphicAtt()
|
---|
462 | {
|
---|
463 | // Pour optimier l'implementation de PIBaseWdgGen
|
---|
464 | sFCol = mFCol; sBCol = mBCol;
|
---|
465 | sGOm = mGOm;
|
---|
466 | sFAtt = mFAtt; sFSize = mFSize;
|
---|
467 | sMrk = mMrk; sMrkSz = mMrkSz;
|
---|
468 | return;
|
---|
469 | }
|
---|
470 |
|
---|
471 |
|
---|
472 | /* --Methode-- */
|
---|
473 | void PIGraphicPS::RestoreGraphicAtt()
|
---|
474 | {
|
---|
475 | if (sFCol != PI_ColorFromMap) SelForeground(sFCol);
|
---|
476 | // else A faire Nicolas
|
---|
477 | if (sBCol != PI_ColorFromMap) SelBackground(sBCol);
|
---|
478 | // else A faire Nicolas
|
---|
479 | SelGOMode(sGOm);
|
---|
480 | SelFontSzPt(sFSize, sFAtt);
|
---|
481 | SelLine(sLAtt);
|
---|
482 | SelMarker(sMrkSz, sMrk);
|
---|
483 | return;
|
---|
484 | }
|
---|
485 |
|
---|
486 |
|
---|
487 |
|
---|
488 |
|
---|
489 |
|
---|