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

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

Creation du module PIext en regroupant des fichiers de Drawer/Wdg pour
Objets ds PEIDA/Outils++, Images++, ... et des classes de ProgPI,
lie a piapp (PIStdImgApp, NamedObjMgr, ...) Reza 18/12/98

File size: 22.1 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,float,float, float, float)
160//
161// Dessin de l'histogramme.
162//--
163{
164if(!mHisto) return;
165// Caracteristiques histogramme
166float dx = mHisto->WBinX(),dy = mHisto->WBinY();
167float 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 float 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 // Dessin proprement dit selon le choix graphique.
238 if(mTypDisp==0) {
239 //..... carres de tailles variables
240 float left = left0 + 0.5*(1.-fracred)*dx, width = fracred*dx;
241 float bottom = bottom0 + 0.5*(1.-fracred)*dy, height = fracred*dy;
242 if (cmap) g->DrawFBox(left,bottom,width,height);
243 else g->DrawBox(left,bottom,width,height);
244 } else if(mTypDisp==1) {
245 //..... nuage de points .....
246 int ipt = int( (float) npt *frac );
247 for(int k=0;k<ipt;k++) {
248 float x = left0 + frand01()*dx;
249 float y = bottom0 + frand01()*dy;
250 g->DrawMarker(x,y);
251 }
252 } else if(mTypDisp==2) {
253 //..... type hbook2/hprint .+23-Z*
254 char c[2];
255 c[0] = HPrint2(frac); c[1]='\0';
256 float x = left0 + dx/2.;
257 float y = bottom0 + dy/2.;
258 g->DrawString(x,y,c);
259 } else if(mTypDisp==3) {
260 //..... carres de tailles fixes (avec gestion de continuite)
261 if (cmap) g->DrawFBox(left0,bottom0,dx+p1dx,dy+p1dy);
262 else g->DrawBox(left0,bottom0,dx+p1dx,dy+p1dy);
263 }
264
265}
266
267// Remise dans les conditions ulterieures pour la suite du graphique.
268g->SelMarker(MkSz,Mk);
269g->SelForeground(coul);
270g->SelFontSzPt(FontSize,FontAtt);
271if (cmap) delete cmap;
272
273// Fin du dessin, ecriture de la statistique.
274DrawStats(g);
275}
276
277//++
278void PIHisto2D::DrawStats(PIGraphicUC* g)
279//
280// Dessin des informations statistiques de l'histogramme.
281//--
282{
283 // Une boite dans le coin superieur droit
284 if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
285 float cellHeight = (YMax() - YMin()) * 0.05;
286 float cellWidth = (XMax() - XMin()) * 0.23;
287 g->DrawLine(XMax() - cellWidth, YMax(),
288 XMax() - cellWidth, YMax() - cellHeight);
289 g->DrawLine(XMax() - cellWidth, YMax() - cellHeight,
290 XMax() , YMax() - cellHeight);
291 char label[50];
292 sprintf(label, "N = %.6g", mHisto->NData());
293 g->SelFontSz((YMax() - YMin())/30);
294 g->DrawString(XMax() - cellWidth*0.9, YMax() - cellHeight*0.8, label);
295 printf("H[%d,%d] Dynamique: [%g,%g] Frac [%g,%g]\n"
296 ,mHisto->NBinX(),mHisto->NBinY(),HMin(),HMax(),FMin(),FMax());
297}
298
299//++
300char PIHisto2D::HPrint2(float f)
301//
302// Codage des valeurs en caracteres (fct privee).
303//| f entre [0,1] mappee entre valeur=[0,37]
304//| si <0 alors =0, si >1 alors 1
305//| Display 4 ==> 4<=valeur<5
306//| C ==> 12<=valeur<13
307//| ==> valeur<=0
308//| * ==> valeur>=1
309//| . ==> 0<valeur<1
310//|------------------------------------------
311//| C1111111111222222222233333333
312//| C01234567890123456789012345678901234567
313//| " .+23456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*"
314//|------------------------------------------
315//--
316{
317char str[39] = " .+23456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*";
318int i;
319if(f<=0.) i = 0;
320else if(f>=1.) i = 37;
321else { i = (int) (f*36.); i++;}
322if(i<0) i=0; else if (i>=38) i = 37;
323return str[i];
324}
325
326//++
327int PIHisto2D::NPixBin(PIGraphicUC* g)
328//
329// Nombre de pixels ecran dans un bin d'histogramme
330// (fct privee).
331//--
332{
333float dx = mHisto->WBinX(),dy = mHisto->WBinY();
334float dxg,dyg;
335g->DUC2GrC(dx,dy,dxg,dyg);
336int np = (int) dxg * (int) dyg;
337//printf("PIHisto2D::NPixBin H dx=%g dy=%g, G dx=%g dy=%g, np = %d\n"
338// ,dx,dy,dxg,dyg,np);
339return np;
340}
341
342
343/////////////////////////////////////////////////////////////////
344// Classe PIH2DWdg
345/////////////////////////////////////////////////////////////////
346//++
347// Titre Widget de dessin d'un histogramme 2D.
348//--
349
350static H2WinArg* h2dWinArg=NULL;
351static int nb_h2dWinArg = 0;
352
353//++
354PIH2DWdg::PIH2DWdg(PIContainerGen *par, char *nom, int sx, int sy, int px, int py)
355//
356// Createur d'un Widget de dessin d'histogramme 2D.
357// Le menu pour choisir les options d'affichage apparait
358// suite au clic du bouton-3 de la souris (cf H2WinArg::H2WinArg).
359//--
360: PIScDrawWdg(par,nom,sx,sy,px,py)
361{
362if (!h2dWinArg) h2dWinArg = new H2WinArg(this);
363nb_h2dWinArg++;
364if(dbg) printf("PIH2DWdg::PIH2DWdg %lx h2dWinArg=%lx %d\n"
365 ,(long)this,(long)h2dWinArg,nb_h2dWinArg);
366mPih = NULL;
367// Pour afficher le menu option de trace
368ActivateButton(3);
369}
370
371//++
372PIH2DWdg::~PIH2DWdg()
373//
374// Destructeur.
375//--
376{
377nb_h2dWinArg--;
378if (nb_h2dWinArg == 0) {
379 h2dWinArg->Hide();
380 delete h2dWinArg;
381 h2dWinArg=NULL;
382}
383if(dbg) printf("PIH2DWdg::~PIH2DWdg h2dWinArg=%lx %d\n"
384 ,(long)h2dWinArg,nb_h2dWinArg);
385if (mPih) delete mPih;
386}
387
388//++
389void PIH2DWdg::SetHisto(Histo2D* histo)
390//
391// Pour connecter un histogramme 2D au Widget.
392//--
393{
394if (!histo) return;
395if (mPih) delete mPih;
396mPih = new PIHisto2D(histo, true);
397AddScDrawer(mPih);
398if(dbg) printf("PIH2DWdg::SetHisto mPih=%lx\n",(long)mPih);
399}
400
401//++
402void PIH2DWdg::SetPIHisto(PIHisto2D* pih2)
403//
404// Pour connecter un traceur (Drawer) d'histo 2D au Widget.
405//--
406{
407if (!pih2) return;
408if (mPih) delete mPih;
409mPih = pih2;
410AddScDrawer(mPih);
411if(dbg) printf("PIH2DWdg::SetPIHisto mPih=%lx\n",(long)mPih);
412}
413
414//++
415string PIH2DWdg::GetClickText(float x, float y)
416//
417// Quand on click (and drag) le bouton-1, affichage
418// des positions x,y et de la valeur du bin de l'histogramme 2D.
419//--
420{
421int i,j;
422char str[128];
423
424if ((!mPih) || (!mPih->Histogram())) {
425 sprintf(str,"X=%g Y=%g ???",x,y);
426 return((string)str);
427}
428
429Histo2D* h = mPih->Histogram();
430
431h->FindBin(x,y,i,j);
432if(i<0 || i>=h->NBinX() || j<0 || j>=h->NBinY())
433 sprintf(str,"x= %g y= %g ???",x,y);
434else sprintf(str,"x= %g y= %g v= %g",x,y,(*h)(i,j));
435
436return((string)str);
437}
438
439//++
440void PIH2DWdg::But3Press(int x, int y)
441//
442// Gestion de l'utilisation du bouton-3 de la souris.
443// Un seul objet est cree pour tous les histogrammes 2D.
444// Il est connecte a un histogramme donnee par l'action du
445// du bouton-3 de la souris dans la fenetre contenant
446// le dessin de l'histogramme (cf H2WinArg::H2WinArg).
447//--
448{
449h2dWinArg->SetPIH2DWdg(this);
450h2dWinArg->SetMsgParent((PIMsgHandler*)this);
451if(!h2dWinArg->Visible()) h2dWinArg->Show();
452if(dbg) printf("PIH2DWdg::But3Press(%d,%d) h2dWinArg=%lx\n"
453 ,x,y,(long)h2dWinArg);
454}
455
456
457/////////////////////////////////////////////////////////////////
458// Classe H2WinArg
459/////////////////////////////////////////////////////////////////
460//++
461// Titre Fenetre de dialogue pour le choix des options..
462//--
463
464//++
465H2WinArg::H2WinArg(PIH2DWdg *par)
466//
467// Creation de la fenetre de gestion des parametres
468// des dessins des histogrammes 2D. Cette fenetre de
469// dialogue est partagee par tous les widget de dessin
470// des histogrammes 2D. Pour la faire apparaitre pour la
471// faire apparaitre la premiere fois, cliquez avec le bouton
472// numero 3 de la souris (bouton de droite) dans la fenetre
473// de dessin de l'histogramme. Si elle est deja presente,
474// pour la connecter a une autre fenetre de dessin cliquez avec
475// le meme bouton dans cette fenetre.
476//--
477//++
478//| - Menu 1: Choix du type de display
479//| Carres variables, nuages de points, caracteres a la hbook2
480//| et carres de tailles fixe (couleur ou niveauz de gris).
481//| - Menu 2: Choix du type d'echelle
482//| Lineaire ou logarithmique
483//| - Menu 3: Choix de la couleur
484//| noir et blanc, niveau de gris et couleurs diverses.
485//| - Champ texte Dyn: Pour donner la dynamique, si min>=max
486//| alors prend le min et le max de l'histogramme
487//| - Champ texte Frac: fraction mini et maxi
488//| (cf PIHisto2D::UseFrac)
489//| - Champ texte LogScal: niveau de scaling pour le choix d'une
490//| echelle logarithmique (cf PIHisto2D::UseScale)
491//--
492//++
493//| - Curseur interactif PerPt: pourcentage de points a dessiner
494//| dans chaque bin (cf PIHisto2D::UseDisplay)
495//| - Bouton Apply: dessiner avec les options affichees
496//| - Bouton Dismiss: fermeture de la fenetre de dialogue.
497//| - Bouton Get: re-prendre les valeurs de display stoquees
498//| pour un histogramme donne.
499//| - Bouton Print: Imprimer les caracteristiques du display
500//| et de l'histogramme.
501//--
502: PIWindow((PIMsgHandler *)par, "Options", PIWK_dialog,250,260,150,150)
503{
504string sdum;
505if(dbg) printf("H2WinArg::H2WinArg %lx par=%lx\n",(long)this,(long)par);
506
507mH2Wdg = NULL;
508
509// Valeurs par defaut
510mFgCol = false;
511mCmap = CMAP_GREYINV32;
512mTypScal = 0;
513mTypDisp = 0;
514mFPoints = 0.5;
515mHMin = 1.;
516mHMax = -1.;
517mFracMin = 0.1;
518mFracMax = 0.9;
519mLogScale = 10.;
520
521// Taille automatique
522int bsx, bsy;
523PIApplicationPrefCompSize(bsx, bsy); // environ 6 lettres
524int spx = (bsx>=10) ? bsx/10 : 1; // intervalle entre lettres X
525int spy = (bsy>=5) ? bsy/5 : 1; // intervalle entre lettres Y
526int wszx = 5*spx+bsx+int(2.5*bsx); // Taille fenetre en X
527int wszy = 11*spy+8.5*bsy; // Taille fenetre en Y
528SetSize(wszx, wszy);
529
530// menus bar
531 int cpx = 2*spx, cpy = 2*spy;
532mOPop[0] = new PIOptMenu(this, "optmen-h2d-1" ,2*bsx,bsy,cpx,cpy);
533mOPop[0]->AppendItem("Carres Var." , 6101);
534mOPop[0]->AppendItem("....." , 6102);
535mOPop[0]->AppendItem(".+12..Z*" , 6103);
536mOPop[0]->AppendItem("Carres Pleins", 6104);
537sdum = "Carres Var."; mOPop[0]->SetValueStr(sdum);
538mOPop[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
539
540 cpy += bsy+spy;
541mOPop[1] = new PIOptMenu(this, "optmen-h2d-2",2*bsx,bsy,cpx,cpy);
542mOPop[1]->AppendItem("Lineaire", 6201);
543mOPop[1]->AppendItem("Log10" , 6202);
544sdum = "Lineaire"; mOPop[1]->SetValueStr(sdum);
545mOPop[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
546
547 cpy += bsy+spy;
548mOPop[2] = new PIOptMenu(this, "optmen-h2d-3",2*bsx,bsy,cpx,cpy);
549mOPop[2]->AppendItem("Black&White", 6301);
550mOPop[2]->AppendItem("Grey32" , 6302);
551mOPop[2]->AppendItem("GreyInv32" , 6303);
552mOPop[2]->AppendItem("ColRJ32" , 6304);
553mOPop[2]->AppendItem("ColBR32" , 6305);
554mOPop[2]->AppendItem("ColRV32" , 6306);
555mOPop[2]->AppendItem("Grey128" , 6307);
556mOPop[2]->AppendItem("GreyInv128", 6308);
557mOPop[2]->AppendItem("ColRJ128" , 6309);
558mOPop[2]->AppendItem("ColBR128" , 6310);
559mOPop[2]->AppendItem("Col16" , 6311);
560sdum = "Black&White"; mOPop[2]->SetValueStr(sdum);
561mOPop[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
562
563// Labels et zone de saisie texte
564 cpy += 2*(bsy+spy);
565mLab[0] = new PILabel(this, " Dyn: ",bsx,bsy,cpx,cpy);
566mLab[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
567mText[0] = new PIText(this, "Dynamique" ,int(2.5*bsx),bsy,cpx+bsx+spx,cpy);
568mText[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
569 cpy += bsy+spy;
570mLab[1] = new PILabel(this, " Frac: ",bsx,bsy,cpx,cpy);
571mLab[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
572mText[1] = new PIText(this, "Fraction" ,int(2.5*bsx),bsy,cpx+bsx+spx,cpy);
573mText[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
574 cpy += bsy+spy;
575mLab[2] = new PILabel(this, " LogScal: ",bsx,bsy,cpx,cpy);
576mLab[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
577mText[2] = new PIText(this, "LogScale" ,int(2.5*bsx),bsy,cpx+bsx+spx,cpy);
578mText[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
579SetText();
580
581// Labels et curseur mobile
582cpy += bsy+spy;
583mLab[3] = new PILabel(this, " PerPt: ",bsx,bsy,cpx,cpy+0.25*bsy);
584mLab[3]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
585mPScal = new PIScale(this,"FracPoints",6401,kSDirLtoR
586 ,int(2.5*bsx),1.25*bsy,cpx+bsx+spx,cpy);
587mPScal->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
588mPScal->SetMinMax(0,100);
589int imfp = mFPoints*100.f; mPScal->SetValue(imfp);
590
591// Boutons
592 cpx = 2*bsx+5*spx, cpy = 2*spy;
593mBut[0] = new PIButton(this, "Apply", 6001,bsx,bsy,cpx,cpy);
594mBut[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
595 cpy += bsy+spy;
596mBut[1] = new PIButton(this, "Dismiss",6002,bsx,bsy,cpx,cpy);
597mBut[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
598 cpy += bsy+spy;
599mBut[2] = new PIButton(this, "Get" , 6003,bsx,bsy,cpx,cpy);
600mBut[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
601 cpy += bsy+spy;
602mBut[3] = new PIButton(this, "Print", 6004,bsx,bsy,cpx,cpy);
603mBut[3]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
604// FinishCreate();
605}
606
607//++
608H2WinArg::~H2WinArg()
609//
610// Destructeur.
611//--
612{
613int i;
614if(dbg) printf("H2WinArg::~H2WinArg %lx\n",(long)this);
615for(i=0;i<3;i++) delete mOPop[i];
616for(i=0;i<4;i++) delete mBut[i];
617for(i=0;i<4;i++) delete mLab[i];
618for(i=0;i<3;i++) delete mText[i];
619delete mPScal;
620}
621
622//++
623void H2WinArg::SetText()
624//
625// Gestion des fenetres de saisie de texte.
626//--
627{
628string sdum;
629char str[256];
630sprintf(str,"%g %g",mHMin,mHMax);
631mText[0]->SetText(str);
632sprintf(str,"%g %g",mFracMin,mFracMax);
633mText[1]->SetText(str);
634sprintf(str,"%g",mLogScale);
635mText[2]->SetText(str);
636
637if(mTypDisp==0) { sdum="Carres Var."; mOPop[0]->SetValueStr(sdum);}
638else if(mTypDisp==1) { sdum="....."; mOPop[0]->SetValueStr(sdum);}
639else if(mTypDisp==2) { sdum=".+12..Z*"; mOPop[0]->SetValueStr(sdum);}
640else if(mTypDisp==3) { sdum="Carres Pleins"; mOPop[0]->SetValueStr(sdum);}
641
642if(mTypScal==0) { sdum="Lineaire"; mOPop[1]->SetValueStr(sdum);}
643else if(mTypScal==1) { sdum="Log10"; mOPop[1]->SetValueStr(sdum);}
644
645if(!mFgCol) { sdum="Black&White";mOPop[2]->SetValueStr(sdum);}
646else {
647 if(mCmap==CMAP_GREY32) { sdum="Grey32"; mOPop[2]->SetValueStr(sdum);}
648 else if(mCmap==CMAP_GREYINV32) { sdum="GreyInv32"; mOPop[2]->SetValueStr(sdum);}
649 else if(mCmap==CMAP_COLRJ32) { sdum="ColRJ32"; mOPop[2]->SetValueStr(sdum);}
650 else if(mCmap==CMAP_COLBR32) { sdum="ColBR32"; mOPop[2]->SetValueStr(sdum);}
651 else if(mCmap==CMAP_COLRV32) { sdum="ColRV32"; mOPop[2]->SetValueStr(sdum);}
652 else if(mCmap==CMAP_GREY128) { sdum="Grey128"; mOPop[2]->SetValueStr(sdum);}
653 else if(mCmap==CMAP_GREYINV128) { sdum="GreyInv128"; mOPop[2]->SetValueStr(sdum);}
654 else if(mCmap==CMAP_COLRJ128) { sdum="ColRJ128"; mOPop[2]->SetValueStr(sdum);}
655 else if(mCmap==CMAP_COLBR128) { sdum="ColBR128"; mOPop[2]->SetValueStr(sdum);}
656 else if(mCmap==CMAP_COL16) { sdum="Col16"; mOPop[2]->SetValueStr(sdum);}
657}
658
659if(dbg)printf("H2WinArg::SetText\n");
660}
661
662//++
663void H2WinArg::GetText()
664//
665// Gestion des fenetres de saisie de texte.
666//--
667{
668sscanf(mText[0]->GetText().c_str(),"%g %g",&mHMin,&mHMax);
669sscanf(mText[1]->GetText().c_str(),"%g %g",&mFracMin,&mFracMax);
670sscanf(mText[2]->GetText().c_str(),"%g",&mLogScale);
671if(dbg) printf("H2WinArg::GetText\n");
672}
673
674//++
675void H2WinArg::SetPIH2DWdg(PIH2DWdg* h2wdg)
676//
677// Connexion du widget de representation d'un histogramme 2D
678// avec la fenetre de gestion des parametres.
679//--
680{
681mH2Wdg = h2wdg;
682if(dbg) printf("H2WinArg::SetPIH2DWdg mH2Wdg = %lx\n",(long)mH2Wdg);
683}
684
685//++
686void H2WinArg::Process(PIMessage msg, PIMsgHandler* sender, void*)
687//
688// Gestions des messages.
689//--
690{
691if(dbg) printf("PIH2DWdg::Process(%d-%d , %lx ...) \n"
692 ,(int)UserMsg(msg),(int)ModMsg(msg), (long)sender);
693
694if(!mH2Wdg) return;
695PIHisto2D* mpih = mH2Wdg->GetPIHisto();
696if(!mpih) return;
697
698int opt = UserMsg(msg);
699 if (opt == 6101) { mTypDisp = 0; }
700else if (opt == 6102) { mTypDisp = 1; }
701else if (opt == 6103) { mTypDisp = 2; }
702else if (opt == 6104) { mTypDisp = 3; }
703
704else if (opt == 6201) { mTypScal = 0; }
705else if (opt == 6202) { mTypScal = 1; }
706
707else if (opt == 6301) { mFgCol = false; }
708else if (opt == 6302) { mFgCol = true; mCmap = CMAP_GREY32; }
709else if (opt == 6303) { mFgCol = true; mCmap = CMAP_GREYINV32; }
710else if (opt == 6304) { mFgCol = true; mCmap = CMAP_COLRJ32; }
711else if (opt == 6305) { mFgCol = true; mCmap = CMAP_COLBR32; }
712else if (opt == 6306) { mFgCol = true; mCmap = CMAP_COLRV32; }
713else if (opt == 6307) { mFgCol = true; mCmap = CMAP_GREY128; }
714else if (opt == 6308) { mFgCol = true; mCmap = CMAP_GREYINV128; }
715else if (opt == 6309) { mFgCol = true; mCmap = CMAP_COLRJ128; }
716else if (opt == 6310) { mFgCol = true; mCmap = CMAP_COLBR128; }
717else if (opt == 6311) { mFgCol = true; mCmap = CMAP_COL16; }
718
719else if (opt == 6401) mFPoints = mPScal->GetValue()/100.;
720
721else if (opt==6001) {
722 GetText();
723 mpih->UseColors(mFgCol, mCmap);
724 mpih->UseScale(mTypScal,mLogScale);
725 mpih->UseDisplay(mTypDisp,mFPoints);
726 mpih->UseDyn(mHMin,mHMax);
727 mpih->UseFrac(mFracMin,mFracMax);
728 mH2Wdg->Refresh(); // On rafraichit le dessin (tout le PIScDrawWdg)
729}
730else if (opt==6002) {
731 this->Hide();
732}
733else if (opt==6003) {
734 mFgCol = mpih->Color();
735 mCmap = mpih->ColMap();
736 mTypScal = mpih->TypScale();
737 mTypDisp = mpih->TypDisplay();
738 mFPoints = mpih->FPoints();
739 mHMin = mpih->HMin();
740 mHMax = mpih->HMax();
741 mFracMin = mpih->FMin();
742 mFracMax = mpih->FMax();
743 mLogScale = mpih->LogScale();
744 SetText();
745}
746else if (opt==6004) {
747 mpih->Print(2);
748}
749
750if(dbg) {
751 printf("H2WinArg::Process opt=%d col=%d,%d scal=%d disp=%d npt=%g\n"
752 ,opt,(int) mFgCol,(int) mCmap,mTypScal,mTypDisp,mFPoints);
753 printf(" min,max= %g,%g frac= %g,%g logsc= %g\n"
754 ,mHMin,mHMax,mFracMin,mFracMax,mLogScale);
755}
756
757}
Note: See TracBrowser for help on using the repository browser.