source: Sophya/trunk/Poubelle/PIext/pihisto2d.cc@ 438

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

Creation module DPC/PIext Reza 09/04/99

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