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

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

Positionnement fenetres, nouvelles commandes (piapp), Gestion fenetre des options Histo-2D Reza 03/03/99

File size: 22.5 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::ActivateSpecializedControls()
445// Pour activer les contrôles spécifiques pour l'affichage Histo-2D
446//--
447{
448h2dWinArg->SetPIH2DWdg(this);
449h2dWinArg->SetMsgParent((PIMsgHandler*)this);
450if(!h2dWinArg->Visible()) h2dWinArg->Show();
451}
452
453//++
454void PIH2DWdg::But3Press(int x, int y)
455//
456// Gestion de l'utilisation du bouton-3 de la souris.
457// Un seul objet est cree pour tous les histogrammes 2D.
458// Il est connecte a un histogramme donnee par l'action du
459// du bouton-3 de la souris dans la fenetre contenant
460// le dessin de l'histogramme (cf H2WinArg::H2WinArg).
461//--
462{
463ActivateSpecializedControls();
464if(dbg) printf("PIH2DWdg::But3Press(%d,%d) h2dWinArg=%lx\n"
465 ,x,y,(long)h2dWinArg);
466}
467
468
469/////////////////////////////////////////////////////////////////
470// Classe H2WinArg
471/////////////////////////////////////////////////////////////////
472//++
473// Titre Fenetre de dialogue pour le choix des options..
474//--
475
476//++
477H2WinArg::H2WinArg(PIH2DWdg *par)
478//
479// Creation de la fenetre de gestion des parametres
480// des dessins des histogrammes 2D. Cette fenetre de
481// dialogue est partagee par tous les widget de dessin
482// des histogrammes 2D. Pour la faire apparaitre pour la
483// faire apparaitre la premiere fois, cliquez avec le bouton
484// numero 3 de la souris (bouton de droite) dans la fenetre
485// de dessin de l'histogramme. Si elle est deja presente,
486// pour la connecter a une autre fenetre de dessin cliquez avec
487// le meme bouton dans cette fenetre.
488//--
489//++
490//| - Menu 1: Choix du type de display
491//| Carres variables, nuages de points, caracteres a la hbook2
492//| et carres de tailles fixe (couleur ou niveauz de gris).
493//| - Menu 2: Choix du type d'echelle
494//| Lineaire ou logarithmique
495//| - Menu 3: Choix de la couleur
496//| noir et blanc, niveau de gris et couleurs diverses.
497//| - Champ texte Dyn: Pour donner la dynamique, si min>=max
498//| alors prend le min et le max de l'histogramme
499//| - Champ texte Frac: fraction mini et maxi
500//| (cf PIHisto2D::UseFrac)
501//| - Champ texte LogScal: niveau de scaling pour le choix d'une
502//| echelle logarithmique (cf PIHisto2D::UseScale)
503//--
504//++
505//| - Curseur interactif PerPt: pourcentage de points a dessiner
506//| dans chaque bin (cf PIHisto2D::UseDisplay)
507//| - Bouton Apply: dessiner avec les options affichees
508//| - Bouton Dismiss: fermeture de la fenetre de dialogue.
509//| - Bouton Get: re-prendre les valeurs de display stoquees
510//| pour un histogramme donne.
511//| - Bouton Print: Imprimer les caracteristiques du display
512//| et de l'histogramme.
513//--
514: PIWindow((PIMsgHandler *)par, "Options", PIWK_dialog,250,260,150,150)
515{
516string sdum;
517if(dbg) printf("H2WinArg::H2WinArg %lx par=%lx\n",(long)this,(long)par);
518
519mH2Wdg = NULL;
520
521// Valeurs par defaut
522mFgCol = false;
523mCmap = CMAP_GREYINV32;
524mTypScal = 0;
525mTypDisp = 0;
526mFPoints = 0.5;
527mHMin = 1.;
528mHMax = -1.;
529mFracMin = 0.1;
530mFracMax = 0.9;
531mLogScale = 10.;
532
533// Taille automatique
534int bsx, bsy;
535PIApplicationPrefCompSize(bsx, bsy); // environ 6 lettres
536int spx = (bsx>=10) ? bsx/10 : 1; // intervalle entre lettres X
537int spy = (bsy>=5) ? bsy/5 : 1; // intervalle entre lettres Y
538int wszx = 5*spx+bsx+int(2.5*bsx); // Taille fenetre en X
539int wszy = 11*spy+8.5*bsy; // Taille fenetre en Y
540SetSize(wszx, wszy);
541
542// menus bar
543 int cpx = 2*spx, cpy = 2*spy;
544mOPop[0] = new PIOptMenu(this, "optmen-h2d-1" ,2*bsx,bsy,cpx,cpy);
545mOPop[0]->AppendItem("Carres Var." , 6101);
546mOPop[0]->AppendItem("....." , 6102);
547mOPop[0]->AppendItem(".+12..Z*" , 6103);
548mOPop[0]->AppendItem("Carres Pleins", 6104);
549sdum = "Carres Var."; mOPop[0]->SetValueStr(sdum);
550mOPop[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
551
552 cpy += bsy+spy;
553mOPop[1] = new PIOptMenu(this, "optmen-h2d-2",2*bsx,bsy,cpx,cpy);
554mOPop[1]->AppendItem("Lineaire", 6201);
555mOPop[1]->AppendItem("Log10" , 6202);
556sdum = "Lineaire"; mOPop[1]->SetValueStr(sdum);
557mOPop[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
558
559 cpy += bsy+spy;
560mOPop[2] = new PIOptMenu(this, "optmen-h2d-3",2*bsx,bsy,cpx,cpy);
561mOPop[2]->AppendItem("Black&White", 6301);
562mOPop[2]->AppendItem("Grey32" , 6302);
563mOPop[2]->AppendItem("GreyInv32" , 6303);
564mOPop[2]->AppendItem("ColRJ32" , 6304);
565mOPop[2]->AppendItem("ColBR32" , 6305);
566mOPop[2]->AppendItem("ColRV32" , 6306);
567mOPop[2]->AppendItem("Grey128" , 6307);
568mOPop[2]->AppendItem("GreyInv128", 6308);
569mOPop[2]->AppendItem("ColRJ128" , 6309);
570mOPop[2]->AppendItem("ColBR128" , 6310);
571mOPop[2]->AppendItem("Col16" , 6311);
572sdum = "Black&White"; mOPop[2]->SetValueStr(sdum);
573mOPop[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
574
575// Labels et zone de saisie texte
576 cpy += 2*(bsy+spy);
577mLab[0] = new PILabel(this, " Dyn: ",bsx,bsy,cpx,cpy);
578mLab[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
579mText[0] = new PIText(this, "Dynamique" ,int(2.5*bsx),bsy,cpx+bsx+spx,cpy);
580mText[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
581 cpy += bsy+spy;
582mLab[1] = new PILabel(this, " Frac: ",bsx,bsy,cpx,cpy);
583mLab[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
584mText[1] = new PIText(this, "Fraction" ,int(2.5*bsx),bsy,cpx+bsx+spx,cpy);
585mText[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
586 cpy += bsy+spy;
587mLab[2] = new PILabel(this, " LogScal: ",bsx,bsy,cpx,cpy);
588mLab[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
589mText[2] = new PIText(this, "LogScale" ,int(2.5*bsx),bsy,cpx+bsx+spx,cpy);
590mText[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
591SetText();
592
593// Labels et curseur mobile
594cpy += bsy+spy;
595mLab[3] = new PILabel(this, " PerPt: ",bsx,bsy,cpx,cpy+0.25*bsy);
596mLab[3]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
597mPScal = new PIScale(this,"FracPoints",6401,kSDirLtoR
598 ,int(2.5*bsx),1.25*bsy,cpx+bsx+spx,cpy);
599mPScal->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
600mPScal->SetMinMax(0,100);
601int imfp = mFPoints*100.f; mPScal->SetValue(imfp);
602
603// Boutons
604 cpx = 2*bsx+5*spx, cpy = 2*spy;
605mBut[0] = new PIButton(this, "Apply", 6001,bsx,bsy,cpx,cpy);
606mBut[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
607 cpy += bsy+spy;
608mBut[1] = new PIButton(this, "Dismiss",6002,bsx,bsy,cpx,cpy);
609mBut[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
610 cpy += bsy+spy;
611mBut[2] = new PIButton(this, "Get" , 6003,bsx,bsy,cpx,cpy);
612mBut[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
613 cpy += bsy+spy;
614mBut[3] = new PIButton(this, "Print", 6004,bsx,bsy,cpx,cpy);
615mBut[3]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
616// FinishCreate();
617}
618
619//++
620H2WinArg::~H2WinArg()
621//
622// Destructeur.
623//--
624{
625int i;
626if(dbg) printf("H2WinArg::~H2WinArg %lx\n",(long)this);
627for(i=0;i<3;i++) delete mOPop[i];
628for(i=0;i<4;i++) delete mBut[i];
629for(i=0;i<4;i++) delete mLab[i];
630for(i=0;i<3;i++) delete mText[i];
631delete mPScal;
632}
633
634//++
635void H2WinArg::SetText()
636//
637// Gestion des fenetres de saisie de texte.
638//--
639{
640string sdum;
641char str[256];
642sprintf(str,"%g %g",mHMin,mHMax);
643mText[0]->SetText(str);
644sprintf(str,"%g %g",mFracMin,mFracMax);
645mText[1]->SetText(str);
646sprintf(str,"%g",mLogScale);
647mText[2]->SetText(str);
648
649if(mTypDisp==0) { sdum="Carres Var."; mOPop[0]->SetValueStr(sdum);}
650else if(mTypDisp==1) { sdum="....."; mOPop[0]->SetValueStr(sdum);}
651else if(mTypDisp==2) { sdum=".+12..Z*"; mOPop[0]->SetValueStr(sdum);}
652else if(mTypDisp==3) { sdum="Carres Pleins"; mOPop[0]->SetValueStr(sdum);}
653
654if(mTypScal==0) { sdum="Lineaire"; mOPop[1]->SetValueStr(sdum);}
655else if(mTypScal==1) { sdum="Log10"; mOPop[1]->SetValueStr(sdum);}
656
657if(!mFgCol) { sdum="Black&White";mOPop[2]->SetValueStr(sdum);}
658else {
659 if(mCmap==CMAP_GREY32) { sdum="Grey32"; mOPop[2]->SetValueStr(sdum);}
660 else if(mCmap==CMAP_GREYINV32) { sdum="GreyInv32"; mOPop[2]->SetValueStr(sdum);}
661 else if(mCmap==CMAP_COLRJ32) { sdum="ColRJ32"; mOPop[2]->SetValueStr(sdum);}
662 else if(mCmap==CMAP_COLBR32) { sdum="ColBR32"; mOPop[2]->SetValueStr(sdum);}
663 else if(mCmap==CMAP_COLRV32) { sdum="ColRV32"; mOPop[2]->SetValueStr(sdum);}
664 else if(mCmap==CMAP_GREY128) { sdum="Grey128"; mOPop[2]->SetValueStr(sdum);}
665 else if(mCmap==CMAP_GREYINV128) { sdum="GreyInv128"; mOPop[2]->SetValueStr(sdum);}
666 else if(mCmap==CMAP_COLRJ128) { sdum="ColRJ128"; mOPop[2]->SetValueStr(sdum);}
667 else if(mCmap==CMAP_COLBR128) { sdum="ColBR128"; mOPop[2]->SetValueStr(sdum);}
668 else if(mCmap==CMAP_COL16) { sdum="Col16"; mOPop[2]->SetValueStr(sdum);}
669}
670
671if(dbg)printf("H2WinArg::SetText\n");
672}
673
674//++
675void H2WinArg::GetText()
676//
677// Gestion des fenetres de saisie de texte.
678//--
679{
680sscanf(mText[0]->GetText().c_str(),"%g %g",&mHMin,&mHMax);
681sscanf(mText[1]->GetText().c_str(),"%g %g",&mFracMin,&mFracMax);
682sscanf(mText[2]->GetText().c_str(),"%g",&mLogScale);
683if(dbg) printf("H2WinArg::GetText\n");
684}
685
686//++
687void H2WinArg::SetPIH2DWdg(PIH2DWdg* h2wdg)
688//
689// Connexion du widget de representation d'un histogramme 2D
690// avec la fenetre de gestion des parametres.
691//--
692{
693mH2Wdg = h2wdg;
694if(dbg) printf("H2WinArg::SetPIH2DWdg mH2Wdg = %lx\n",(long)mH2Wdg);
695}
696
697//++
698void H2WinArg::Process(PIMessage msg, PIMsgHandler* sender, void*)
699//
700// Gestions des messages.
701//--
702{
703if(dbg) printf("PIH2DWdg::Process(%d-%d , %lx ...) \n"
704 ,(int)UserMsg(msg),(int)ModMsg(msg), (long)sender);
705
706if(!mH2Wdg) return;
707PIHisto2D* mpih = mH2Wdg->GetPIHisto();
708if(!mpih) return;
709
710int opt = UserMsg(msg);
711 if (opt == 6101) { mTypDisp = 0; }
712else if (opt == 6102) { mTypDisp = 1; }
713else if (opt == 6103) { mTypDisp = 2; }
714else if (opt == 6104) { mTypDisp = 3; }
715
716else if (opt == 6201) { mTypScal = 0; }
717else if (opt == 6202) { mTypScal = 1; }
718
719else if (opt == 6301) { mFgCol = false; }
720else if (opt == 6302) { mFgCol = true; mCmap = CMAP_GREY32; }
721else if (opt == 6303) { mFgCol = true; mCmap = CMAP_GREYINV32; }
722else if (opt == 6304) { mFgCol = true; mCmap = CMAP_COLRJ32; }
723else if (opt == 6305) { mFgCol = true; mCmap = CMAP_COLBR32; }
724else if (opt == 6306) { mFgCol = true; mCmap = CMAP_COLRV32; }
725else if (opt == 6307) { mFgCol = true; mCmap = CMAP_GREY128; }
726else if (opt == 6308) { mFgCol = true; mCmap = CMAP_GREYINV128; }
727else if (opt == 6309) { mFgCol = true; mCmap = CMAP_COLRJ128; }
728else if (opt == 6310) { mFgCol = true; mCmap = CMAP_COLBR128; }
729else if (opt == 6311) { mFgCol = true; mCmap = CMAP_COL16; }
730
731else if (opt == 6401) mFPoints = mPScal->GetValue()/100.;
732
733else if (opt==6001) {
734 GetText();
735 mpih->UseColors(mFgCol, mCmap);
736 mpih->UseScale(mTypScal,mLogScale);
737 mpih->UseDisplay(mTypDisp,mFPoints);
738 mpih->UseDyn(mHMin,mHMax);
739 mpih->UseFrac(mFracMin,mFracMax);
740 mH2Wdg->Refresh(); // On rafraichit le dessin (tout le PIScDrawWdg)
741}
742else if (opt==6002) {
743 this->Hide();
744}
745else if (opt==6003) {
746 mFgCol = mpih->Color();
747 mCmap = mpih->ColMap();
748 mTypScal = mpih->TypScale();
749 mTypDisp = mpih->TypDisplay();
750 mFPoints = mpih->FPoints();
751 mHMin = mpih->HMin();
752 mHMax = mpih->HMax();
753 mFracMin = mpih->FMin();
754 mFracMax = mpih->FMax();
755 mLogScale = mpih->LogScale();
756 SetText();
757}
758else if (opt==6004) {
759 mpih->Print(2);
760}
761
762if(dbg) {
763 printf("H2WinArg::Process opt=%d col=%d,%d scal=%d disp=%d npt=%g\n"
764 ,opt,(int) mFgCol,(int) mCmap,mTypScal,mTypDisp,mFPoints);
765 printf(" min,max= %g,%g frac= %g,%g logsc= %g\n"
766 ,mHMin,mHMax,mFracMin,mFracMax,mLogScale);
767}
768
769}
Note: See TracBrowser for help on using the repository browser.