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

Last change on this file since 1971 was 1905, checked in by ansari, 24 years ago

Adaptation a l'introduction de la classe PIGraphicAtt - Reza 18/02/2002

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