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

Last change on this file since 651 was 548, checked in by ercodmgr, 26 years ago

Ajout trace en medaillon - Reza 4/11/99

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