source: Sophya/trunk/SophyaPI/PIext/pihisto2d.cc@ 206

Last change on this file since 206 was 205, checked in by ercodmgr, 27 years ago

1/ Adaptation pour passage en double de trace en coordonnees graphiques
User (UC) (float -> double)
2/ Adaptation pour passage en double pour les ArrayAdapter

Reza 1/03/99

File size: 22.3 KB
Line 
1#include <stdio.h>
2#include "piapplgen.h"
3#include "pihisto2d.h"
4#include "nbrandom.h"
5
6static int dbg = 0;
7
8//++
9// Class PIHisto2D,PIH2DWdg,H2WinArg
10// Lib PI
11// include pihisto2d.h
12//
13// Classes de dessin des histogrammes a 2 dimensions.
14//--
15
16//++
17// Titre Dessin d'un histogramme 2D.
18//--
19
20//++
21PIHisto2D::PIHisto2D(Histo2D* histo, bool ad)
22//
23// Createur d'une classe de dessin pour l'histogramme 2D histo.
24//--
25: PIDrawer(), mHisto(histo)
26{
27mAdDO = ad; // Flag pour suppression automatique de mHisto
28
29mLogScale = 10.;
30mFPoints = 0.5;
31
32UseColors();
33UseDisplay();
34UseDyn();
35UseFrac();
36}
37
38//++
39PIHisto2D::~PIHisto2D()
40//
41// Destructeur.
42//--
43{
44if(mAdDO) delete mHisto;
45}
46
47//++
48void PIHisto2D::UseColors(bool fg, CMapId cmap)
49//
50// Choix de la couleur si fg=true
51// (pour la couleur cmap cf picmap.h).
52//--
53{
54mFgCol = fg; mCmap = cmap;
55}
56
57//++
58void PIHisto2D::UseScale(unsigned short type,float logscale)
59//
60// Pour changer les echelles.
61//| Type = 0 : echelle lineaire
62//| = 1 : echelle log10
63//| - Explication du codage en type=1 (log10) :
64//| 1-/ map lineaire :
65//| [0,1] -> [lmin,lmax]
66//| f -> F = lmin+f*(lmax-lmin)
67//| 2-/ transformation log10 :
68//| [lmin,lmax] -> [log10(lmin),log10(lmax)]
69//| F -> LF = lg10(F)
70//| 3-/ rescaling entre 0 et 1 :
71//| [log10(lmin),log10(lmax)] -> [0,1]
72//| LF -> (LF-log10(lmin))/(log10(lmax)-log10(lmin))
73//| soit en definissant logscale = lmax/lmin
74//| LF = log10(1.+f*(logscale-1))/log10(logscale)
75//--
76{
77if(type==0) mTypScal = 0;
78if(type==1) {
79 mTypScal = 1;
80 if(logscale>1.) mLogScale = logscale;
81} else mTypScal = 0;
82}
83
84//++
85void PIHisto2D::UseDisplay(unsigned short type, float fnpt)
86//
87// Type de Display
88//| Type = 0 : carres de tailles variables
89//| Type = 1 : nuages de points
90//| Le nombre de points a utiliser est fnpt*N
91//| ou N est le nombre de pixels ecran contenu
92//| dans un bin de l'histogramme.
93//| Type = 2 : code a la "hbook2" " .+123...9AB...YZ*"
94//| (cf detail PIHisto2D::HPrint2)
95//| Type = 3 : carres de tailles fixes (couleur).
96//--
97{
98if(fnpt<0.) fnpt=0; else if(fnpt>1.) fnpt=1.;
99if(type==0) mTypDisp = 0;
100else if(type==1) { mTypDisp = 1; mFPoints = fnpt;}
101else if(type==2) mTypDisp = 2;
102else if(type==3) mTypDisp = 3;
103else mTypDisp = 1;
104}
105
106//++
107void PIHisto2D::UseDyn(float hmin, float hmax)
108//
109// Gestion de la dynamique a representer:
110// la dynamique va etre transformee de [hmin,hmax] vers [0,1].
111//--
112{
113if(hmin>=hmax) {hmin = mHisto->VMin(); hmax = mHisto->VMax();}
114if(hmin>=hmax) hmax = hmin+1.;
115mHMin = hmin; mHMax = hmax;
116}
117
118//++
119void PIHisto2D::UseFrac(float frmin, float frmax)
120//
121// Pour definir la fraction de la dynamique a dessiner:
122//| Certains type de display (f=[0,1] cf PIHisto2D::UseDyn),
123//| - on ne dessine rien si f <= frmin
124//| - on limite l'excursion a f*frmax cad [...,frmax]
125//--
126{
127if(frmax<=0. || frmax>1.) frmax = 1.;
128if(frmin>=frmax) {frmin=0.1; frmax=0.9;}
129mFracMin = frmin; mFracMax = frmax;
130}
131
132//++
133void PIHisto2D::Print(int lp)
134//
135// Print de l'etat des options du display.
136//--
137{
138printf("PIHisto2D::Print FgCol=%d Cmap=%d TypScal=%d TypDisp=%d (FPoints=%g)\n"
139 ,(int)mFgCol,(int)mCmap,mTypScal,mTypDisp,mFPoints);
140printf(" Dyn=%g,%g Frac=%g,%g LogSc=%g H=%lx\n"
141 ,mHMin,mHMax,mFracMin,mFracMax,mLogScale,(long)mHisto);
142if(lp<1) return;
143mHisto->PrintStatus();
144}
145
146//++
147void PIHisto2D::UpdateLimits()
148//
149// Definition des tailles graphiques en fonction
150// des caracteristiques de l'histogramme a dessiner.
151//--
152{
153 if(!mHisto) return;
154 SetLimits(mHisto->XMin(), mHisto->XMax(), mHisto->YMin() , mHisto->YMax());
155 SetAxesFlags(kBoxAxes | kExtTicks | kLabels);
156}
157
158//++
159void PIHisto2D::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
160//
161// Dessin de l'histogramme.
162//--
163{
164if(!mHisto) return;
165// Caracteristiques histogramme
166double dx = mHisto->WBinX(),dy = mHisto->WBinY();
167double p1dx,p1dy;
168g->DGrC2UC(1.f,1.f,p1dx,p1dy);
169
170// Gamme a representer entre [0,1] mais >=fracmin et scale fracmax
171float fracmin=FMin(), fracmax=FMax();
172float llscale = (float) log10((double)LogScale());
173
174// gestion Couleurs.
175PIColorMap* cmap=NULL;
176PIColors coul = g->GetForeground();
177int ncol = 0;
178if (mFgCol) {
179 cmap = new PIColorMap(mCmap); ncol = cmap->NCol();
180 if(mTypDisp==3) fracmin=-1.;
181}
182
183// gestion epaisseur de ligne
184if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
185
186// gestion Markers ou plot avec des points.
187PIMarker Mk = g->GetMarker();
188int MkSz = g->GetMarkerSize();
189int npt = 1;
190if(mTypDisp==1) {
191 g->SelMarker(1,PI_DotMarker);
192 npt = (int) ((float)NPixBin(g)*FPoints()); if(npt<=0) npt = 2;
193}
194
195// gestion Font.
196PIFontAtt FontAtt = g->GetFontAtt();
197int FontSize = g->GetFontSize();
198if(mTypDisp==2) {
199 double dxg,dyg,dg;
200 g->DUC2GrC(dx,dy,dxg,dyg);
201 dg =(dxg<dyg) ? dxg : dyg;
202 int npix = (int) (dg*0.9); if(npix<8) npix = 8;
203 //printf("PIHisto2D::Draw_Font H dx=%g dy=%g, G dx=%g dy=%g, npix = %g,%d\n"
204 // ,dx,dy,dxg,dyg,dg,npix);
205 g->SelFontSzPt(npix,PI_RomanFont);
206 fracmin = 0;
207}
208
209// Print();
210
211// Plot de l'histogramme
212for (int i=0; i<mHisto->NBinX(); i++)
213for (int j=0; j<mHisto->NBinY(); j++) {
214
215 float left0,bottom0;
216 mHisto->BinLowEdge(i,j,left0,bottom0);
217
218 // Gestion de la dynamique a dessiner
219 float frac = ((*mHisto)(i,j)-HMin())/(HMax()-HMin());
220 if(frac<0.) continue;
221 if(mTypScal==1) { // echelle log10
222 frac = log10(1.+frac*(LogScale()-1.))/llscale;
223 if(frac<0.) continue;
224 }
225 if(frac<=fracmin) continue;
226 if(frac>1.) frac = 1.;
227 float fracred = frac * fracmax;
228
229 // Gestion de la couleur
230 int icol = 0;
231 if (cmap) {
232 icol = int( (float) ncol*frac );
233 if(icol>=ncol) icol = ncol-1; else if(icol<0) icol=0;
234 g->SelForeground(*cmap,icol);
235 }
236
237// Pour ne pas dessiner en dehors des axes
238 if ( (left0+dx/2. < xmin) || (left0+dx/2. > xmax) ||
239 (bottom0+dy/2. < ymin) || (bottom0+dy/2. > ymax) ) continue;
240
241 // Dessin proprement dit selon le choix graphique.
242 if(mTypDisp==0) {
243 //..... carres de tailles variables
244 double left = left0 + 0.5*(1.-fracred)*dx, width = fracred*dx;
245 double bottom = bottom0 + 0.5*(1.-fracred)*dy, height = fracred*dy;
246 if (cmap) g->DrawFBox(left,bottom,width,height);
247 else g->DrawBox(left,bottom,width,height);
248 } else if(mTypDisp==1) {
249 //..... nuage de points .....
250 int ipt = int( (float) npt *frac );
251 for(int k=0;k<ipt;k++) {
252 double x = left0 + frand01()*dx;
253 double y = bottom0 + frand01()*dy;
254 g->DrawMarker(x,y);
255 }
256 } else if(mTypDisp==2) {
257 //..... type hbook2/hprint .+23-Z*
258 char c[2];
259 c[0] = HPrint2(frac); c[1]='\0';
260 double x = left0 + dx/2.;
261 double y = bottom0 + dy/2.;
262 g->DrawString(x,y,c);
263 } else if(mTypDisp==3) {
264 //..... carres de tailles fixes (avec gestion de continuite)
265 if (cmap) g->DrawFBox(left0,bottom0,dx+p1dx,dy+p1dy);
266 else g->DrawBox(left0,bottom0,dx+p1dx,dy+p1dy);
267 }
268
269}
270
271// Remise dans les conditions ulterieures pour la suite du graphique.
272g->SelMarker(MkSz,Mk);
273g->SelForeground(coul);
274g->SelFontSzPt(FontSize,FontAtt);
275if (cmap) delete cmap;
276
277// Fin du dessin, ecriture de la statistique.
278DrawStats(g);
279}
280
281//++
282void PIHisto2D::DrawStats(PIGraphicUC* g)
283//
284// Dessin des informations statistiques de l'histogramme.
285//--
286{
287 // Une boite dans le coin superieur droit
288 if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
289 double cellHeight = (YMax() - YMin()) * 0.05;
290 double cellWidth = (XMax() - XMin()) * 0.23;
291 g->DrawLine(XMax() - cellWidth, YMax(),
292 XMax() - cellWidth, YMax() - cellHeight);
293 g->DrawLine(XMax() - cellWidth, YMax() - cellHeight,
294 XMax() , YMax() - cellHeight);
295 char label[50];
296 sprintf(label, "N = %.6g", mHisto->NData());
297 g->SelFontSz((YMax() - YMin())/30);
298 g->DrawString(XMax() - cellWidth*0.9, YMax() - cellHeight*0.8, label);
299 printf("H[%d,%d] Dynamique: [%g,%g] Frac [%g,%g]\n"
300 ,mHisto->NBinX(),mHisto->NBinY(),HMin(),HMax(),FMin(),FMax());
301}
302
303//++
304char PIHisto2D::HPrint2(float f)
305//
306// Codage des valeurs en caracteres (fct privee).
307//| f entre [0,1] mappee entre valeur=[0,37]
308//| si <0 alors =0, si >1 alors 1
309//| Display 4 ==> 4<=valeur<5
310//| C ==> 12<=valeur<13
311//| ==> valeur<=0
312//| * ==> valeur>=1
313//| . ==> 0<valeur<1
314//|------------------------------------------
315//| C1111111111222222222233333333
316//| C01234567890123456789012345678901234567
317//| " .+23456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*"
318//|------------------------------------------
319//--
320{
321char str[39] = " .+23456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*";
322int i;
323if(f<=0.) i = 0;
324else if(f>=1.) i = 37;
325else { i = (int) (f*36.); i++;}
326if(i<0) i=0; else if (i>=38) i = 37;
327return str[i];
328}
329
330//++
331int PIHisto2D::NPixBin(PIGraphicUC* g)
332//
333// Nombre de pixels ecran dans un bin d'histogramme
334// (fct privee).
335//--
336{
337double dx = mHisto->WBinX(),dy = mHisto->WBinY();
338double dxg,dyg;
339g->DUC2GrC(dx,dy,dxg,dyg);
340int np = (int) dxg * (int) dyg;
341//printf("PIHisto2D::NPixBin H dx=%g dy=%g, G dx=%g dy=%g, np = %d\n"
342// ,dx,dy,dxg,dyg,np);
343return np;
344}
345
346
347/////////////////////////////////////////////////////////////////
348// Classe PIH2DWdg
349/////////////////////////////////////////////////////////////////
350//++
351// Titre Widget de dessin d'un histogramme 2D.
352//--
353
354static H2WinArg* h2dWinArg=NULL;
355static int nb_h2dWinArg = 0;
356
357//++
358PIH2DWdg::PIH2DWdg(PIContainerGen *par, char *nom, int sx, int sy, int px, int py)
359//
360// Createur d'un Widget de dessin d'histogramme 2D.
361// Le menu pour choisir les options d'affichage apparait
362// suite au clic du bouton-3 de la souris (cf H2WinArg::H2WinArg).
363//--
364: PIScDrawWdg(par,nom,sx,sy,px,py)
365{
366if (!h2dWinArg) h2dWinArg = new H2WinArg(this);
367nb_h2dWinArg++;
368if(dbg) printf("PIH2DWdg::PIH2DWdg %lx h2dWinArg=%lx %d\n"
369 ,(long)this,(long)h2dWinArg,nb_h2dWinArg);
370mPih = NULL;
371// Pour afficher le menu option de trace
372ActivateButton(3);
373}
374
375//++
376PIH2DWdg::~PIH2DWdg()
377//
378// Destructeur.
379//--
380{
381nb_h2dWinArg--;
382if (nb_h2dWinArg == 0) {
383 h2dWinArg->Hide();
384 delete h2dWinArg;
385 h2dWinArg=NULL;
386}
387if(dbg) printf("PIH2DWdg::~PIH2DWdg h2dWinArg=%lx %d\n"
388 ,(long)h2dWinArg,nb_h2dWinArg);
389if (mPih) delete mPih;
390}
391
392//++
393void PIH2DWdg::SetHisto(Histo2D* histo)
394//
395// Pour connecter un histogramme 2D au Widget.
396//--
397{
398if (!histo) return;
399if (mPih) delete mPih;
400mPih = new PIHisto2D(histo, true);
401AddScDrawer(mPih);
402if(dbg) printf("PIH2DWdg::SetHisto mPih=%lx\n",(long)mPih);
403}
404
405//++
406void PIH2DWdg::SetPIHisto(PIHisto2D* pih2)
407//
408// Pour connecter un traceur (Drawer) d'histo 2D au Widget.
409//--
410{
411if (!pih2) return;
412if (mPih) delete mPih;
413mPih = pih2;
414AddScDrawer(mPih);
415if(dbg) printf("PIH2DWdg::SetPIHisto mPih=%lx\n",(long)mPih);
416}
417
418//++
419string PIH2DWdg::GetClickText(double x, double y)
420//
421// Quand on click (and drag) le bouton-1, affichage
422// des positions x,y et de la valeur du bin de l'histogramme 2D.
423//--
424{
425int i,j;
426char str[128];
427
428if ((!mPih) || (!mPih->Histogram())) {
429 sprintf(str,"X=%g Y=%g ???",x,y);
430 return((string)str);
431}
432
433Histo2D* h = mPih->Histogram();
434
435h->FindBin(x,y,i,j);
436if(i<0 || i>=h->NBinX() || j<0 || j>=h->NBinY())
437 sprintf(str,"x= %g y= %g ???",x,y);
438else sprintf(str,"x= %g y= %g v= %g",x,y,(*h)(i,j));
439
440return((string)str);
441}
442
443//++
444void PIH2DWdg::But3Press(int x, int y)
445//
446// Gestion de l'utilisation du bouton-3 de la souris.
447// Un seul objet est cree pour tous les histogrammes 2D.
448// Il est connecte a un histogramme donnee par l'action du
449// du bouton-3 de la souris dans la fenetre contenant
450// le dessin de l'histogramme (cf H2WinArg::H2WinArg).
451//--
452{
453h2dWinArg->SetPIH2DWdg(this);
454h2dWinArg->SetMsgParent((PIMsgHandler*)this);
455if(!h2dWinArg->Visible()) h2dWinArg->Show();
456if(dbg) printf("PIH2DWdg::But3Press(%d,%d) h2dWinArg=%lx\n"
457 ,x,y,(long)h2dWinArg);
458}
459
460
461/////////////////////////////////////////////////////////////////
462// Classe H2WinArg
463/////////////////////////////////////////////////////////////////
464//++
465// Titre Fenetre de dialogue pour le choix des options..
466//--
467
468//++
469H2WinArg::H2WinArg(PIH2DWdg *par)
470//
471// Creation de la fenetre de gestion des parametres
472// des dessins des histogrammes 2D. Cette fenetre de
473// dialogue est partagee par tous les widget de dessin
474// des histogrammes 2D. Pour la faire apparaitre pour la
475// faire apparaitre la premiere fois, cliquez avec le bouton
476// numero 3 de la souris (bouton de droite) dans la fenetre
477// de dessin de l'histogramme. Si elle est deja presente,
478// pour la connecter a une autre fenetre de dessin cliquez avec
479// le meme bouton dans cette fenetre.
480//--
481//++
482//| - Menu 1: Choix du type de display
483//| Carres variables, nuages de points, caracteres a la hbook2
484//| et carres de tailles fixe (couleur ou niveauz de gris).
485//| - Menu 2: Choix du type d'echelle
486//| Lineaire ou logarithmique
487//| - Menu 3: Choix de la couleur
488//| noir et blanc, niveau de gris et couleurs diverses.
489//| - Champ texte Dyn: Pour donner la dynamique, si min>=max
490//| alors prend le min et le max de l'histogramme
491//| - Champ texte Frac: fraction mini et maxi
492//| (cf PIHisto2D::UseFrac)
493//| - Champ texte LogScal: niveau de scaling pour le choix d'une
494//| echelle logarithmique (cf PIHisto2D::UseScale)
495//--
496//++
497//| - Curseur interactif PerPt: pourcentage de points a dessiner
498//| dans chaque bin (cf PIHisto2D::UseDisplay)
499//| - Bouton Apply: dessiner avec les options affichees
500//| - Bouton Dismiss: fermeture de la fenetre de dialogue.
501//| - Bouton Get: re-prendre les valeurs de display stoquees
502//| pour un histogramme donne.
503//| - Bouton Print: Imprimer les caracteristiques du display
504//| et de l'histogramme.
505//--
506: PIWindow((PIMsgHandler *)par, "Options", PIWK_dialog,250,260,150,150)
507{
508string sdum;
509if(dbg) printf("H2WinArg::H2WinArg %lx par=%lx\n",(long)this,(long)par);
510
511mH2Wdg = NULL;
512
513// Valeurs par defaut
514mFgCol = false;
515mCmap = CMAP_GREYINV32;
516mTypScal = 0;
517mTypDisp = 0;
518mFPoints = 0.5;
519mHMin = 1.;
520mHMax = -1.;
521mFracMin = 0.1;
522mFracMax = 0.9;
523mLogScale = 10.;
524
525// Taille automatique
526int bsx, bsy;
527PIApplicationPrefCompSize(bsx, bsy); // environ 6 lettres
528int spx = (bsx>=10) ? bsx/10 : 1; // intervalle entre lettres X
529int spy = (bsy>=5) ? bsy/5 : 1; // intervalle entre lettres Y
530int wszx = 5*spx+bsx+int(2.5*bsx); // Taille fenetre en X
531int wszy = 11*spy+8.5*bsy; // Taille fenetre en Y
532SetSize(wszx, wszy);
533
534// menus bar
535 int cpx = 2*spx, cpy = 2*spy;
536mOPop[0] = new PIOptMenu(this, "optmen-h2d-1" ,2*bsx,bsy,cpx,cpy);
537mOPop[0]->AppendItem("Carres Var." , 6101);
538mOPop[0]->AppendItem("....." , 6102);
539mOPop[0]->AppendItem(".+12..Z*" , 6103);
540mOPop[0]->AppendItem("Carres Pleins", 6104);
541sdum = "Carres Var."; mOPop[0]->SetValueStr(sdum);
542mOPop[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
543
544 cpy += bsy+spy;
545mOPop[1] = new PIOptMenu(this, "optmen-h2d-2",2*bsx,bsy,cpx,cpy);
546mOPop[1]->AppendItem("Lineaire", 6201);
547mOPop[1]->AppendItem("Log10" , 6202);
548sdum = "Lineaire"; mOPop[1]->SetValueStr(sdum);
549mOPop[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
550
551 cpy += bsy+spy;
552mOPop[2] = new PIOptMenu(this, "optmen-h2d-3",2*bsx,bsy,cpx,cpy);
553mOPop[2]->AppendItem("Black&White", 6301);
554mOPop[2]->AppendItem("Grey32" , 6302);
555mOPop[2]->AppendItem("GreyInv32" , 6303);
556mOPop[2]->AppendItem("ColRJ32" , 6304);
557mOPop[2]->AppendItem("ColBR32" , 6305);
558mOPop[2]->AppendItem("ColRV32" , 6306);
559mOPop[2]->AppendItem("Grey128" , 6307);
560mOPop[2]->AppendItem("GreyInv128", 6308);
561mOPop[2]->AppendItem("ColRJ128" , 6309);
562mOPop[2]->AppendItem("ColBR128" , 6310);
563mOPop[2]->AppendItem("Col16" , 6311);
564sdum = "Black&White"; mOPop[2]->SetValueStr(sdum);
565mOPop[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
566
567// Labels et zone de saisie texte
568 cpy += 2*(bsy+spy);
569mLab[0] = new PILabel(this, " Dyn: ",bsx,bsy,cpx,cpy);
570mLab[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
571mText[0] = new PIText(this, "Dynamique" ,int(2.5*bsx),bsy,cpx+bsx+spx,cpy);
572mText[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
573 cpy += bsy+spy;
574mLab[1] = new PILabel(this, " Frac: ",bsx,bsy,cpx,cpy);
575mLab[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
576mText[1] = new PIText(this, "Fraction" ,int(2.5*bsx),bsy,cpx+bsx+spx,cpy);
577mText[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
578 cpy += bsy+spy;
579mLab[2] = new PILabel(this, " LogScal: ",bsx,bsy,cpx,cpy);
580mLab[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
581mText[2] = new PIText(this, "LogScale" ,int(2.5*bsx),bsy,cpx+bsx+spx,cpy);
582mText[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
583SetText();
584
585// Labels et curseur mobile
586cpy += bsy+spy;
587mLab[3] = new PILabel(this, " PerPt: ",bsx,bsy,cpx,cpy+0.25*bsy);
588mLab[3]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
589mPScal = new PIScale(this,"FracPoints",6401,kSDirLtoR
590 ,int(2.5*bsx),1.25*bsy,cpx+bsx+spx,cpy);
591mPScal->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
592mPScal->SetMinMax(0,100);
593int imfp = mFPoints*100.f; mPScal->SetValue(imfp);
594
595// Boutons
596 cpx = 2*bsx+5*spx, cpy = 2*spy;
597mBut[0] = new PIButton(this, "Apply", 6001,bsx,bsy,cpx,cpy);
598mBut[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
599 cpy += bsy+spy;
600mBut[1] = new PIButton(this, "Dismiss",6002,bsx,bsy,cpx,cpy);
601mBut[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
602 cpy += bsy+spy;
603mBut[2] = new PIButton(this, "Get" , 6003,bsx,bsy,cpx,cpy);
604mBut[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
605 cpy += bsy+spy;
606mBut[3] = new PIButton(this, "Print", 6004,bsx,bsy,cpx,cpy);
607mBut[3]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
608// FinishCreate();
609}
610
611//++
612H2WinArg::~H2WinArg()
613//
614// Destructeur.
615//--
616{
617int i;
618if(dbg) printf("H2WinArg::~H2WinArg %lx\n",(long)this);
619for(i=0;i<3;i++) delete mOPop[i];
620for(i=0;i<4;i++) delete mBut[i];
621for(i=0;i<4;i++) delete mLab[i];
622for(i=0;i<3;i++) delete mText[i];
623delete mPScal;
624}
625
626//++
627void H2WinArg::SetText()
628//
629// Gestion des fenetres de saisie de texte.
630//--
631{
632string sdum;
633char str[256];
634sprintf(str,"%g %g",mHMin,mHMax);
635mText[0]->SetText(str);
636sprintf(str,"%g %g",mFracMin,mFracMax);
637mText[1]->SetText(str);
638sprintf(str,"%g",mLogScale);
639mText[2]->SetText(str);
640
641if(mTypDisp==0) { sdum="Carres Var."; mOPop[0]->SetValueStr(sdum);}
642else if(mTypDisp==1) { sdum="....."; mOPop[0]->SetValueStr(sdum);}
643else if(mTypDisp==2) { sdum=".+12..Z*"; mOPop[0]->SetValueStr(sdum);}
644else if(mTypDisp==3) { sdum="Carres Pleins"; mOPop[0]->SetValueStr(sdum);}
645
646if(mTypScal==0) { sdum="Lineaire"; mOPop[1]->SetValueStr(sdum);}
647else if(mTypScal==1) { sdum="Log10"; mOPop[1]->SetValueStr(sdum);}
648
649if(!mFgCol) { sdum="Black&White";mOPop[2]->SetValueStr(sdum);}
650else {
651 if(mCmap==CMAP_GREY32) { sdum="Grey32"; mOPop[2]->SetValueStr(sdum);}
652 else if(mCmap==CMAP_GREYINV32) { sdum="GreyInv32"; mOPop[2]->SetValueStr(sdum);}
653 else if(mCmap==CMAP_COLRJ32) { sdum="ColRJ32"; mOPop[2]->SetValueStr(sdum);}
654 else if(mCmap==CMAP_COLBR32) { sdum="ColBR32"; mOPop[2]->SetValueStr(sdum);}
655 else if(mCmap==CMAP_COLRV32) { sdum="ColRV32"; mOPop[2]->SetValueStr(sdum);}
656 else if(mCmap==CMAP_GREY128) { sdum="Grey128"; mOPop[2]->SetValueStr(sdum);}
657 else if(mCmap==CMAP_GREYINV128) { sdum="GreyInv128"; mOPop[2]->SetValueStr(sdum);}
658 else if(mCmap==CMAP_COLRJ128) { sdum="ColRJ128"; mOPop[2]->SetValueStr(sdum);}
659 else if(mCmap==CMAP_COLBR128) { sdum="ColBR128"; mOPop[2]->SetValueStr(sdum);}
660 else if(mCmap==CMAP_COL16) { sdum="Col16"; mOPop[2]->SetValueStr(sdum);}
661}
662
663if(dbg)printf("H2WinArg::SetText\n");
664}
665
666//++
667void H2WinArg::GetText()
668//
669// Gestion des fenetres de saisie de texte.
670//--
671{
672sscanf(mText[0]->GetText().c_str(),"%g %g",&mHMin,&mHMax);
673sscanf(mText[1]->GetText().c_str(),"%g %g",&mFracMin,&mFracMax);
674sscanf(mText[2]->GetText().c_str(),"%g",&mLogScale);
675if(dbg) printf("H2WinArg::GetText\n");
676}
677
678//++
679void H2WinArg::SetPIH2DWdg(PIH2DWdg* h2wdg)
680//
681// Connexion du widget de representation d'un histogramme 2D
682// avec la fenetre de gestion des parametres.
683//--
684{
685mH2Wdg = h2wdg;
686if(dbg) printf("H2WinArg::SetPIH2DWdg mH2Wdg = %lx\n",(long)mH2Wdg);
687}
688
689//++
690void H2WinArg::Process(PIMessage msg, PIMsgHandler* sender, void*)
691//
692// Gestions des messages.
693//--
694{
695if(dbg) printf("PIH2DWdg::Process(%d-%d , %lx ...) \n"
696 ,(int)UserMsg(msg),(int)ModMsg(msg), (long)sender);
697
698if(!mH2Wdg) return;
699PIHisto2D* mpih = mH2Wdg->GetPIHisto();
700if(!mpih) return;
701
702int opt = UserMsg(msg);
703 if (opt == 6101) { mTypDisp = 0; }
704else if (opt == 6102) { mTypDisp = 1; }
705else if (opt == 6103) { mTypDisp = 2; }
706else if (opt == 6104) { mTypDisp = 3; }
707
708else if (opt == 6201) { mTypScal = 0; }
709else if (opt == 6202) { mTypScal = 1; }
710
711else if (opt == 6301) { mFgCol = false; }
712else if (opt == 6302) { mFgCol = true; mCmap = CMAP_GREY32; }
713else if (opt == 6303) { mFgCol = true; mCmap = CMAP_GREYINV32; }
714else if (opt == 6304) { mFgCol = true; mCmap = CMAP_COLRJ32; }
715else if (opt == 6305) { mFgCol = true; mCmap = CMAP_COLBR32; }
716else if (opt == 6306) { mFgCol = true; mCmap = CMAP_COLRV32; }
717else if (opt == 6307) { mFgCol = true; mCmap = CMAP_GREY128; }
718else if (opt == 6308) { mFgCol = true; mCmap = CMAP_GREYINV128; }
719else if (opt == 6309) { mFgCol = true; mCmap = CMAP_COLRJ128; }
720else if (opt == 6310) { mFgCol = true; mCmap = CMAP_COLBR128; }
721else if (opt == 6311) { mFgCol = true; mCmap = CMAP_COL16; }
722
723else if (opt == 6401) mFPoints = mPScal->GetValue()/100.;
724
725else if (opt==6001) {
726 GetText();
727 mpih->UseColors(mFgCol, mCmap);
728 mpih->UseScale(mTypScal,mLogScale);
729 mpih->UseDisplay(mTypDisp,mFPoints);
730 mpih->UseDyn(mHMin,mHMax);
731 mpih->UseFrac(mFracMin,mFracMax);
732 mH2Wdg->Refresh(); // On rafraichit le dessin (tout le PIScDrawWdg)
733}
734else if (opt==6002) {
735 this->Hide();
736}
737else if (opt==6003) {
738 mFgCol = mpih->Color();
739 mCmap = mpih->ColMap();
740 mTypScal = mpih->TypScale();
741 mTypDisp = mpih->TypDisplay();
742 mFPoints = mpih->FPoints();
743 mHMin = mpih->HMin();
744 mHMax = mpih->HMax();
745 mFracMin = mpih->FMin();
746 mFracMax = mpih->FMax();
747 mLogScale = mpih->LogScale();
748 SetText();
749}
750else if (opt==6004) {
751 mpih->Print(2);
752}
753
754if(dbg) {
755 printf("H2WinArg::Process opt=%d col=%d,%d scal=%d disp=%d npt=%g\n"
756 ,opt,(int) mFgCol,(int) mCmap,mTypScal,mTypDisp,mFPoints);
757 printf(" min,max= %g,%g frac= %g,%g logsc= %g\n"
758 ,mHMin,mHMax,mFracMin,mFracMax,mLogScale);
759}
760
761}
Note: See TracBrowser for help on using the repository browser.