source: Sophya/trunk/SophyaPI/PI/pigraphps.cc @ 4086

Last change on this file since 4086 was 4086, checked in by garnier, 11 years ago

before moving eventFilter

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