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

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

Documentation PI - Reza 2/11/99

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