source: Sophya/trunk/Poubelle/PI/pigraphps.cc@ 222

Last change on this file since 222 was 222, checked in by ansari, 26 years ago

Creation module DPC/PI Reza 09/04/99

File size: 9.7 KB
Line 
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-- */
45PIGraphicPS::PIGraphicPS(PSFile * psf, PIWdg* wdg, double ofx, double ofy)
46: PIGraphicGen()
47{
48BuildFromPSFile(psf, (double)wdg->XPos()+ofx, (double)wdg->YPos()+ofy,
49 (double)wdg->XSize(), (double)wdg->YSize() );
50}
51
52/* --Methode-- */
53PIGraphicPS::PIGraphicPS(PSFile * psf, double x0, double y0, double dx, double dy)
54: PIGraphicGen()
55{
56BuildFromPSFile(psf, x0, y0, dx, dy);
57}
58
59/* --Methode-- */
60PIGraphicPS::~PIGraphicPS()
61{
62mPSOut->EndBloc();
63}
64
65/* --Methode-- */
66int PIGraphicPS::kind()
67{
68return PI_PSFileGraphics;
69}
70
71
72/* --Methode-- */
73void PIGraphicPS::BuildFromPSFile(PSFile * psf, double x0, double y0, double dx, double dy)
74{
75mPSOut = psf;
76
77mGOm = PI_GOCopy;
78
79mFCol = mBCol = PI_Grey;
80SelForeground(PI_Black);
81SelBackground(PI_White);
82mLAtt = PI_ThinLine;
83SelLine();
84mFAtt = PI_BoldFont; mFSize = 0;
85SelFont();
86SelMarker(1, PI_DotMarker);
87
88if (psf) psf->NewBloc(x0, y0, dx, dy, dx, dy);
89mXmin = mYmin = 0.;
90mXmax = dx; mYmax = dy;
91mFCfMap.red = mFCfMap.blue = mFCfMap.blue = 0;
92mBCfMap = mFCfMap;
93}
94
95/* --Methode-- */
96void PIGraphicPS::GetGrSpace(PIGrCoord& xmin, PIGrCoord& xmax, PIGrCoord& ymin, PIGrCoord& ymax)
97{
98xmin = ymin = 0;
99xmax = mXmax; ymax = mYmax;
100}
101
102/* --Methode-- */
103void PIGraphicPS::Erase(PIGrCoord, PIGrCoord, PIGrCoord, PIGrCoord)
104{
105// A Faire ??? $CHECK$
106return;
107}
108
109/* --Methode-- */
110void PIGraphicPS::DrawString(PIGrCoord x, PIGrCoord y, const char* s, int /*pos*/)
111{
112if(mPSOut)
113 mPSOut->DrawString((double)x,(double)y,s,mFCol,mFAtt,mFSize); /* $CHECK$ PIFontSize ?? */
114return;
115}
116
117/* --Methode-- */
118void PIGraphicPS::DrawOpaqueString(PIGrCoord x, PIGrCoord y, const char* s, int /*pos*/)
119{
120if(mPSOut)
121 mPSOut->DrawString((double)x,(double)y,s,mFCol,mFAtt,mFSize); /* $CHECK$ PIFontSize ?? */
122return;
123}
124
125
126/* --Methode-- */
127void PIGraphicPS::DrawLine(PIGrCoord x1, PIGrCoord y1, PIGrCoord x2, PIGrCoord y2)
128{
129if(mPSOut)
130 mPSOut->DrawLine((double)x1,(double)y1,(double)x2,(double)y2,mFCol,mLAtt);
131return;
132}
133
134
135/* --Methode-- */
136void PIGraphicPS::DrawBox(PIGrCoord x0, PIGrCoord y0, PIGrCoord dx, PIGrCoord dy)
137{
138if(mPSOut)
139 mPSOut->DrawBox((double)x0,(double)y0,(double)dx,(double)dy,mFCol,mLAtt);
140return;
141}
142
143/* --Methode-- */
144void PIGraphicPS::DrawFBox(PIGrCoord x0, PIGrCoord y0, PIGrCoord dx, PIGrCoord dy)
145{
146if(mPSOut)
147 mPSOut->DrawFBox((double)x0,(double)y0,(double)dx,(double)dy, mFCol, mFCol, mLAtt);
148return;
149}
150
151/* --Methode-- */
152void PIGraphicPS::DrawCircle(PIGrCoord x0, PIGrCoord y0, PIGrCoord r)
153{
154if(mPSOut)
155 mPSOut->DrawCircle((double)x0,(double)y0,(double)r,mFCol,mLAtt);
156return;
157}
158
159/* --Methode-- */
160void PIGraphicPS::DrawFCircle(PIGrCoord x0, PIGrCoord y0, PIGrCoord r)
161{
162if(mPSOut)
163 mPSOut->DrawFCircle((double)x0,(double)y0,(double)r,mFCol,mFCol,mLAtt);
164return;
165}
166
167/* --Methode-- */
168void PIGraphicPS::DrawOval(PIGrCoord x0, PIGrCoord y0, PIGrCoord dx, PIGrCoord dy)
169{
170// $CHECK$ Reza/ Nicolas 12 Nov 98 - A faire
171}
172
173/* --Methode-- */
174void PIGraphicPS::DrawFOval(PIGrCoord x0, PIGrCoord y0, PIGrCoord dx, PIGrCoord dy)
175{
176// $CHECK$ Reza/ Nicolas 12 Nov 98 - A faire
177}
178
179/* --Methode-- */
180void PIGraphicPS::DrawPolygon(PIGrCoord *x, PIGrCoord *y, int n, bool cinc)
181{
182int i;
183double *xtmp;
184double *ytmp;
185
186if(! mPSOut) return;
187
188xtmp = new double[n];
189ytmp = new double[n];
190for(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//}
200mPSOut->DrawPolygon(xtmp,ytmp,n,mFCol,mLAtt,cinc);
201delete[] xtmp;
202delete[] ytmp;
203
204return;
205}
206
207
208/* --Methode-- */
209void PIGraphicPS::DrawFPolygon(PIGrCoord *x, PIGrCoord *y, int n, bool cinc)
210{
211int i;
212double *xtmp;
213double *ytmp;
214
215if(! mPSOut) return;
216
217xtmp = new double[n];
218ytmp = new double[n];
219for(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//}
229mPSOut->DrawFPolygon(xtmp,ytmp,n,mFCol,mFCol,mLAtt,cinc);
230delete[] xtmp;
231delete[] ytmp;
232
233return;
234}
235
236/* --Methode-- */
237void 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-- */
243void 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-- */
249void PIGraphicPS::DrawMarker(PIGrCoord x0, PIGrCoord y0)
250{
251if(mPSOut)
252 mPSOut->DrawMarker((double)x0,(double)y0,mMrk,mFCol,mMrkSz);
253return;
254}
255
256/* --Methode-- */
257void PIGraphicPS::DrawMarkers(PIGrCoord *x, PIGrCoord *y, int n)
258{
259int i;
260double *xtmp;
261double *ytmp;
262
263if( !mPSOut) return;
264
265xtmp = new double[n];
266ytmp = new double[n];
267for(i=0;i<n;i++){
268 xtmp[i] = (double)x[i];
269 ytmp[i] = (double)y[i];
270}
271mPSOut->DrawMarkers(xtmp,ytmp,n,mMrk,mFCol, mMrkSz);
272delete[] xtmp;
273delete[] ytmp;
274
275return;
276}
277
278
279/* --Methode-- */
280void PIGraphicPS::DrawPixmap(PIGrCoord x, PIGrCoord y, unsigned char *pix,
281 int sx, int sy, PIColorMap* cmap)
282{
283if ( (sx < 1) || (sy < 1) ) return;
284if ((pix == NULL) || (cmap == NULL)) return;
285if(mPSOut)
286 mPSOut->Image((double)x, (double)y, (double)sx, (double)sy, sx, sy, pix, cmap);
287return;
288}
289
290/* --Methode-- */
291void PIGraphicPS::SelForeground(PIColors col)
292{
293mFCol = col;
294return;
295}
296
297/* --Methode-- */
298void PIGraphicPS::SelBackground(PIColors col)
299{
300mBCol = col;
301return;
302}
303
304/* --Methode-- */
305void PIGraphicPS::SelForeground(PIColorMap& cmap, int cid)
306{
307// A Faire Voir Nicolas
308mFCfMap = cmap.GetColor(cid);
309mFCol = PI_ColorFromMap;
310mPSOut->SelForeground(cmap, cid) ;
311return;
312}
313
314/* --Methode-- */
315void PIGraphicPS::SelBackground(PIColorMap& cmap, int cid)
316{
317// A Faire Voir Nicolas
318mBCfMap = cmap.GetColor(cid);
319mBCol = PI_ColorFromMap;
320return;
321}
322
323/* --Methode-- */
324void PIGraphicPS::SelGOMode(PIGOMode mod)
325{
326mGOm = mod;
327return;
328}
329
330/* --Methode-- */
331void PIGraphicPS::SelFontSzPt(int npt, PIFontAtt att)
332{
333mFSize = npt;
334mFAtt = att;
335return;
336}
337
338static int fntsz[5] = {8,10,12,14,16};
339
340/* --Methode-- */
341void PIGraphicPS::SelFont(PIFontSize sz, PIFontAtt att)
342{
343int i;
344switch (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 }
358mFSize = fntsz[i];
359mFAtt = att;
360return;
361}
362
363
364
365/* --Methode-- */
366void PIGraphicPS::SelLine(PILineAtt att)
367{
368mLAtt = att;
369return;
370}
371
372
373/* --Methode-- */
374void PIGraphicPS::SelMarker(int msz, PIMarker mrk)
375{
376if (msz > 1) { mMrk = mrk; mMrkSz = msz; }
377else { mMrk = PI_DotMarker; mMrkSz = 1; }
378return;
379}
380
381
382/* --Methode-- */
383void PIGraphicPS::SetClipRectangle(PIGrCoord /*x0*/, PIGrCoord /*y0*/, PIGrCoord /*dx*/, PIGrCoord /*dy*/)
384{
385/* $CHECK$ A FAIRE , voir Nicolas */
386return;
387}
388
389/* --Methode-- */
390void PIGraphicPS::ClearClipRectangle()
391{
392/* $CHECK$ A FAIRE , voir Nicolas */
393return;
394}
395
396/* --Methode-- */
397PIColors PIGraphicPS::GetForeground()
398{
399return (mFCol);
400}
401
402/* --Methode-- */
403PIColors PIGraphicPS::GetBackground()
404{
405return (mBCol);
406}
407
408
409/* --Methode-- */
410PIGOMode PIGraphicPS::GetGOMode()
411{
412return (mGOm);
413}
414
415/* --Methode-- */
416PIFontAtt PIGraphicPS::GetFontAtt()
417{
418return (mFAtt);
419}
420
421/* --Methode-- */
422int PIGraphicPS::GetFontSize()
423{
424return (mFSize);
425}
426
427/* --Methode-- */
428PILineAtt PIGraphicPS::GetLineAtt()
429{
430return (mLAtt);
431}
432
433/* --Methode-- */
434PIMarker PIGraphicPS::GetMarker()
435{
436return (mMrk);
437}
438
439/* --Methode-- */
440int PIGraphicPS::GetMarkerSize()
441{
442return (mMrkSz);
443}
444
445/* --Methode-- */
446int PIGraphicPS::GetFontHeight(int& asc, int& desc)
447{
448/* $CHECK$ A refaire , voir Nicolas */
449asc = mFSize; desc = 0;
450return(asc+desc);
451}
452
453
454/* --Methode-- */
455PIGrCoord PIGraphicPS::CalcStringWidth(char const* s)
456{
457return((double)(mFSize*strlen(s)*0.5)); /* facteur 0.5 ad'hoc $CHECK$ Voir Nicolas ! */
458}
459
460/* --Methode-- */
461void PIGraphicPS::SaveGraphicAtt()
462{
463// Pour optimier l'implementation de PIBaseWdgGen
464sFCol = mFCol; sBCol = mBCol;
465sGOm = mGOm;
466sFAtt = mFAtt; sFSize = mFSize;
467sMrk = mMrk; sMrkSz = mMrkSz;
468return;
469}
470
471
472/* --Methode-- */
473void 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
Note: See TracBrowser for help on using the repository browser.