Index: /trunk/SophyaPI/PI/pihisto2d.cc
===================================================================
--- /trunk/SophyaPI/PI/pihisto2d.cc	(revision 81)
+++ /trunk/SophyaPI/PI/pihisto2d.cc	(revision 82)
@@ -1,32 +1,138 @@
 #include <stdio.h>
 #include "pihisto2d.h"
-
-#include PIMENU_H
-
+#include "nbrandom.h"
+
+static int dbg = 0;
+
+//++
 PIHisto2D::PIHisto2D(Histo2D* histo, bool ad)
 : PIScDrawer(), mHisto(histo)
-{
-  mAdDO = ad;     // Flag pour suppression automatique de mHisto  
-  UseColors();
-}
-
+//
+//	Createur d'une classe de dessin pour l'histogramme 2D histo.
+//--
+{
+mAdDO = ad;     // Flag pour suppression automatique de mHisto  
+
+mLogScale = 10.;
+mFPoints = 0.5;
+
+UseColors();
+UseDisplay();
+UseDyn();
+UseFrac();
+}
+
+//++
 PIHisto2D::~PIHisto2D()
-{
-  if (mAdDO)
-    delete mHisto;
-}
-
-void
-PIHisto2D::UseColors(bool fg, CMapId cmap)
-{
-  mFgCol = fg; mCmap = cmap;
-}
-
-void
-PIHisto2D::UpdateSize()
+//
+//	Destructeur.
+//--
+{
+if(mAdDO) delete mHisto;
+}
+
+//++
+void PIHisto2D::UseColors(bool fg, CMapId cmap)
+//
+//	Choix de la couleur si fg=true
+//	(pour la couleur cmap cf picmap.h).
+//--
+{
+mFgCol = fg; mCmap = cmap;
+}
+
+//++
+void PIHisto2D::UseScale(unsigned short type,float logscale)
+//
+//	Pour changer les echelles.
+//| Type = 0 : echelle lineaire
+//|      = 1 : echelle log10
+//| - Explication du codage en type=1 (log10) :
+//|   1-/ map lineaire :
+//|       [0,1] -> [lmin,lmax]
+//|       f     -> F = lmin+f*(lmax-lmin)
+//|   2-/ transformation log10 :
+//|       [lmin,lmax] -> [log10(lmin),log10(lmax)]
+//|       F           -> LF = lg10(F)
+//|   3-/ rescaling entre 0 et 1 :
+//|       [log10(lmin),log10(lmax)] -> [0,1]
+//|       LF -> (LF-log10(lmin))/(log10(lmax)-log10(lmin))
+//|       soit en definissant logscale = lmax/lmin
+//|       LF = log10(1.+f*(logscale-1))/log10(logscale)
+//--
+{
+if(type==0) mTypScal = 0;
+if(type==1) {
+  mTypScal = 1;
+  if(logscale>1.) mLogScale = logscale;
+} else mTypScal = 0;
+}
+
+//++
+void PIHisto2D::UseDisplay(unsigned short type, float fnpt)
+//
+//	Type de Display
+//| Type = 0 : carres de tailles variables
+//| Type = 1 : nuages de points
+//|            Le nombre de points a utiliser est fnpt*N
+//|            ou N est le nombre de pixels ecran contenu
+//|            dans un bin de l'histogramme.
+//| Type = 2 : code a la "hbook2"
+//| Type = 3 : carres de tailles fixes en couleur
+//--
+{
+if(fnpt<0.) fnpt=0; else if(fnpt>1.) fnpt=1.;
+if(type==0)        mTypDisp = 0;
+else if(type==1) { mTypDisp = 1; mFPoints = fnpt;}
+else if(type==2)   mTypDisp = 2;
+else if(type==3)   mTypDisp = 3;
+else               mTypDisp = 1;
+}
+
+//++
+void PIHisto2D::UseDyn(float hmin, float hmax)
+//
+//	Gestion de la dynamique a representer:
+//	la dynamique va etre transformee de [hmin,hmax] vers [0,1].
+//--
+{
+if(hmin>=hmax) {hmin = mHisto->VMin(); hmax = mHisto->VMax();}
+if(hmin>=hmax) hmax = hmin+1.;
+mHMin = hmin; mHMax = hmax;
+}
+
+//++
+void PIHisto2D::UseFrac(float frmin, float frmax)
+//
+//	Pour definir la fraction de la dynamique a dessiner:
+//| Pour certains type de display (f=[0,1] cf UseDyn),
+//|    - on ne dessine rien si f <= frmin
+//|    - on limite l'excursion a f*frmax cad [...,frmax]
+//--
+{
+if(frmax<=0. || frmax>1.) frmax = 1.;
+if(frmin>=frmax) {frmin=0.1; frmax=0.9;}
+mFracMin = frmin; mFracMax = frmax;
+}
+
+//++
+void PIHisto2D::Print(int lp)
+//
+//	Print de l'etat des options du display.
+//--
+{
+printf("PIHisto2D::Print FgCol=%d Cmap=%d TypScal=%d TypDisp=%d (FPoints=%g)\n"
+      ,(int)mFgCol,(int)mCmap,mTypScal,mTypDisp,mFPoints);
+printf("                 Dyn=%g,%g Frac=%g,%g LogSc=%g H=%lx\n"
+      ,mHMin,mHMax,mFracMin,mFracMax,mLogScale,(long)mHisto);
+if(lp<1) return;
+mHisto->PrintStatus();
+}
+
+void PIHisto2D::UpdateSize()
 {
   if (!mDrawer) return;
   if (mDrawer->LimitsFixed()) return;
-  if (!mHisto)  return;
+  if(!mHisto) return;
   // Commencer par trouver nos limites
   
@@ -37,7 +143,7 @@
   float ymin = mHisto->YMin();
   
-  if (mDrawWdg) 
+  if (mDrawWdg)
     mDrawWdg->SetLimits(xmin, xmax, ymin, ymax);
-  else 
+  else
     mDrawer->SetLimits(xmin, xmax, ymin, ymax);
 
@@ -45,55 +151,125 @@
 }
 
-
-void
-PIHisto2D::Draw(PIGraphicUC* g, float /*xmin*/, float /*ymin*/, float /*xmax*/, float /*ymax*/)
-{
-  if (!mHisto)  return;
-  float hmin = mHisto->VMin();
-  float hmax = mHisto->VMax();
-  if(hmin>=hmax) hmax = hmin+1.;
-  float dx = mHisto->WBinX();
-  float dy = mHisto->WBinY();
-  float fracmin=0.1, fracmax=0.8;
-
-  PIColorMap* cmap=NULL;
-  PIColors coul;
-  int ncol = 0;
-  if (mFgCol) { 
-    cmap = new PIColorMap(mCmap);
-    ncol = cmap->NCol();
-    coul = g->GetForeground();
-//    fracmin = 0.;
-//    fracmax = 1.;
+//++
+void PIHisto2D::Draw(PIGraphicUC* g,float,float, float, float)
+//
+//	Dessin de l'histogramme.
+//--
+{
+if(!mHisto) return;
+// Caracteristiques histogramme
+float dx = mHisto->WBinX(),dy = mHisto->WBinY();
+float p1dx,p1dy;
+g->DGrC2UC(1.f,1.f,p1dx,p1dy);
+
+// Gamme a representer entre [0,1] mais >=fracmin et scale fracmax
+float fracmin=FMin(), fracmax=FMax();
+float llscale = (float) log10((double)LogScale());
+
+// gestion Couleurs.
+PIColorMap* cmap=NULL;
+PIColors coul = g->GetForeground();
+int ncol = 0;
+if (mFgCol) {
+  cmap = new PIColorMap(mCmap); ncol = cmap->NCol();
+  if(mTypDisp==3) fracmin=-1.;
+}
+
+// gestion Markers ou plot avec des points.
+PIMarker Mk = g->GetMarker();
+int MkSz = g->GetMarkerSize();
+int npt = 1;
+if(mTypDisp==1) {
+  g->SelMarker(1,PI_DotMarker);
+  npt = (int) ((float)NPixBin(g)*FPoints()); if(npt<=0) npt = 2;
+}
+
+// gestion Font.
+PIFontAtt FontAtt = g->GetFontAtt();
+int FontSize = g->GetFontSize();
+if(mTypDisp==2) {
+  float dxg,dyg,dg;
+  g->DUC2GrC(dx,dy,dxg,dyg);
+  dg =(dxg<dyg) ? dxg : dyg;
+  int npix = (int) (dg*0.9); if(npix<8) npix = 8;
+  //printf("PIHisto2D::Draw_Font H dx=%g dy=%g, G dx=%g dy=%g, npix = %g,%d\n"
+  //      ,dx,dy,dxg,dyg,dg,npix);
+  g->SelFontSzPt(npix,PI_RomanFont);
+  fracmin = 0;
+}
+
+// Print();
+
+// Plot de l'histogramme
+for (int i=0; i<mHisto->NBinX(); i++)
+for (int j=0; j<mHisto->NBinY(); j++) {
+
+  float left0,bottom0;
+  mHisto->BinLowEdge(i,j,left0,bottom0);
+
+  // Gestion de la dynamique a dessiner
+  float frac = ((*mHisto)(i,j)-HMin())/(HMax()-HMin());
+  if(frac<0.) continue;
+  if(mTypScal==1) {              // echelle log10
+    frac = log10(1.+frac*(LogScale()-1.))/llscale;
+    if(frac<0.) continue;
   }
-
-  for (int i=0; i<mHisto->NBinX(); i++) {
-    for (int j=0; j<mHisto->NBinY(); j++) {
-      float left,bottom;
-      mHisto->BinLowEdge(i,j,left,bottom);
-      float frac = fracmax*((*mHisto)(i,j)-hmin)/(hmax-hmin);
-      if(frac<fracmin) continue;
-      float width = frac*dx;
-      float height = frac*dy;
-      left += 0.5*(1.-frac)*dx;
-      bottom += 0.5*(1.-frac)*dy;
-      if (cmap) {
-        int icol = ncol*(frac/fracmax);
-        if(icol>=ncol) icol = ncol-1; else if(icol<0) icol=0;
-        g->SelForeground(*cmap,icol);
-        g->DrawFBox(left,bottom,width,height);
-      }
-      else g->DrawBox(left,bottom,width,height);
+  if(frac<=fracmin) continue;
+  if(frac>1.) frac = 1.;
+  float fracred = frac * fracmax;
+
+  // Gestion de la couleur
+  int icol = 0;
+  if (cmap) {
+    icol = int( (float) ncol*frac );
+    if(icol>=ncol) icol = ncol-1; else if(icol<0) icol=0;
+    g->SelForeground(*cmap,icol);
+  }
+
+  // Dessin proprement dit selon le choix graphique.
+  if(mTypDisp==0) {
+    //..... carres de tailles variables
+    float left   = left0   + 0.5*(1.-fracred)*dx, width  = fracred*dx;
+    float bottom = bottom0 + 0.5*(1.-fracred)*dy, height = fracred*dy;
+    if (cmap) g->DrawFBox(left,bottom,width,height);
+    else      g->DrawBox(left,bottom,width,height);
+  } else if(mTypDisp==1) {
+    //..... nuage de points .....
+    int ipt  = int( (float) npt *frac );
+    for(int k=0;k<ipt;k++) {
+      float x = left0 + frand01()*dx;
+      float y = bottom0 + frand01()*dy;
+      g->DrawMarker(x,y);
     }
+  } else if(mTypDisp==2) {
+    //..... type hbook2/hprint .+23-Z*
+    char c[2];
+    c[0] = HPrint2(frac); c[1]='\0';
+    float x = left0 + dx/2.;
+    float y = bottom0 + dy/2.;
+    g->DrawString(x,y,c);
+  } else if(mTypDisp==3) {
+    //..... carres de tailles fixes (avec gestion de continuite)
+    if (cmap) g->DrawFBox(left0,bottom0,dx+p1dx,dy+p1dy);
+    else      g->DrawBox(left0,bottom0,dx+p1dx,dy+p1dy);
   }
-  if (cmap) { 
-    g->SelForeground(coul);
-    delete cmap;
-  }
-  DrawStats(g);
-}
-
-void
-PIHisto2D::DrawStats(PIGraphicUC* g)
+
+}
+
+// Remise dans les conditions ulterieures pour la suite du graphique.
+g->SelMarker(MkSz,Mk);
+g->SelForeground(coul);
+g->SelFontSzPt(FontSize,FontAtt);
+if (cmap) delete cmap;
+
+// Fin du dessin, ecriture de la statistique.
+DrawStats(g);
+}
+
+//++
+void PIHisto2D::DrawStats(PIGraphicUC* g)
+//
+//	Dessin des informations statistiques de l'histogramme.
+//--
 {
   if (!mDrawWdg) return;
@@ -109,5 +285,49 @@
   g->SelFontSz((mDrawWdg->YMax() - mDrawWdg->YMin())/30);
   g->DrawString(mDrawWdg->XMax() - cellWidth*0.9, mDrawWdg->YMax() - cellHeight*0.8, label);
-                       
+  printf("H[%d,%d] Dynamique: [%g,%g] Frac [%g,%g]\n"
+        ,mHisto->NBinX(),mHisto->NBinY(),HMin(),HMax(),FMin(),FMax());
+}
+
+//++
+char PIHisto2D::HPrint2(float f)
+//
+//	Codage des valeurs en caracteres (fct privee).
+//| f entre [0,1] mappee entre valeur=[0,37]
+//| si <0 alors =0, si >1 alors 1
+//| Display 4   ==> 4<=valeur<5
+//|         C   ==> 12<=valeur<13
+//|             ==> valeur<=0
+//|         *   ==> valeur>=1
+//|         .   ==> 0<valeur<1
+//|------------------------------------------
+//|            1111111111222222222233333333
+//|  01234567890123456789012345678901234567
+//| " .+23456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*"
+//|------------------------------------------
+//--
+{
+char str[39] = " .+23456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*";
+int i;
+if(f<=0.) i = 0;
+else if(f>=1.) i = 37;
+else { i = (int) (f*36.); i++;}
+if(i<0) i=0; else if (i>=38) i = 37;
+return str[i];
+}
+
+//++
+int PIHisto2D::NPixBin(PIGraphicUC* g)
+//
+//	Nombre de pixels ecran dans un bin d'histogramme
+//	(fct privee).
+//--
+{
+float dx = mHisto->WBinX(),dy = mHisto->WBinY();
+float dxg,dyg;
+g->DUC2GrC(dx,dy,dxg,dyg);
+int np = (int) dxg * (int) dyg;
+//printf("PIHisto2D::NPixBin H dx=%g dy=%g, G dx=%g dy=%g, np = %d\n"
+//      ,dx,dy,dxg,dyg,np);
+return np;
 }
 
@@ -118,41 +338,61 @@
 
 
-//  Le menu qui va servir a choisir l'option d'affichage suite au click 
-// de bouton-3
-static PIPUMenu* optmenh2d=NULL;
-static int nb_optmen = 0;
-
+static H2WinArg* h2dWinArg=NULL;
+static int nb_h2dWinArg = 0;
+
+//++
 PIH2DWdg::PIH2DWdg(PIContainerGen *par, char *nom, int sx, int sy, int px, int py)
+//
+//	Createur d'un Widget de dessin d'histogramme 2D.
+//	Le menu pour choisir l'option d'affichage apparait suite au clic
+//	du bouton-3 de la souris.
+//--
         : PIScDrawWdg(par,nom,sx,sy,px,py)
 {
-if (!optmenh2d) {
-  optmenh2d = new PIPUMenu((PIMsgHandler *)this, "TypeH2D");
-  optmenh2d->AppendItem("B&W", 6101);
-  optmenh2d->AppendItem("Gris", 6102);
-  optmenh2d->AppendItem("RJ32", 6103);
-  optmenh2d->AppendItem("BR32", 6104);
-  }
-nb_optmen++;
+if (!h2dWinArg) h2dWinArg = new H2WinArg(this);
+nb_h2dWinArg++;
+if(dbg) printf("PIH2DWdg::PIH2DWdg %lx h2dWinArg=%lx %d\n"
+              ,(long)this,(long)h2dWinArg,nb_h2dWinArg);
 mPih = NULL;
-ActivateButton(3); // Pour afficher le menu option de trace
-}
-
+// Pour afficher le menu option de trace
+ActivateButton(3);
+}
+
+//++
 PIH2DWdg::~PIH2DWdg()
-{
-nb_optmen--;
-if (nb_optmen == 0) { delete optmenh2d;  optmenh2d=NULL; }
-if (mPih)  delete mPih;
-}
-
-void PIH2DWdg::SetHisto(Histo2D* histo, bool fg, CMapId cmap)
+//
+//	Destructeur.
+//--
+{
+nb_h2dWinArg--;
+if (nb_h2dWinArg == 0) {
+  h2dWinArg->Hide();
+  delete h2dWinArg;
+  h2dWinArg=NULL;
+}
+if(dbg) printf("PIH2DWdg::~PIH2DWdg h2dWinArg=%lx %d\n"
+              ,(long)h2dWinArg,nb_h2dWinArg);
+if (mPih) delete mPih;
+}
+
+//++
+void PIH2DWdg::SetHisto(Histo2D* histo)
+//
+//	Pour connecter un histogramme 2D au Widget.
+//--
 {
 if (!histo) return;
 if (mPih)  delete mPih;
 mPih = new PIHisto2D(histo, true);
-mPih->UseColors(fg, cmap);
 AddScDrawer(mPih);
-}
-
+if(dbg) printf("PIH2DWdg::SetHisto mPih=%lx\n",(long)mPih);
+}
+
+//++
 string  PIH2DWdg::GetClickText(float x, float y)
+//
+//	Quand on click (and drag) le bouton-1, affichage
+//	des positions x,y et de la valeur du bin de l'histogramme 2D.
+//--
 {
 int i,j;
@@ -161,41 +401,255 @@
 if ((!mPih) || (!mPih->Histogram())) {
   sprintf(str,"X=%g Y=%g ???",x,y);
-  return((string)str); 
+  return((string)str);
 }
 
 Histo2D* h = mPih->Histogram();
-
 
 h->FindBin(x,y,i,j);
 if(i<0 || i>=h->NBinX() || j<0 || j>=h->NBinY())
-  sprintf(str,"X=%g Y=%g ???",x,y);
-else sprintf(str,"X=%g Y=%g v=%g",x,y,(*h)(i,j));
+  sprintf(str,"x= %g y= %g ???",x,y);
+else sprintf(str,"x= %g y= %g v= %g",x,y,(*h)(i,j));
 
 return((string)str);
 }
 
-void PIH2DWdg::Process(PIMessage msg, PIMsgHandler* sender, void* data)
-{
-//printf("PIH2DWdg::Process(%d-%d , %lx ...) \n", UserMsg(msg), ModMsg(msg), (long)sender);
-if (!mPih) return;
-if (sender == optmenh2d) { // On n'attend de message que de la part du menu 
-  int opt=6101;
-  bool fgc=false;
-  CMapId col=CMAP_GREYINV32;
-      
-  opt = UserMsg(msg);
-  if (opt == 6102) { fgc = true; col = CMAP_GREYINV32; }
-  else if (opt == 6103) { fgc = true;  col = CMAP_COLRJ32; }
-  else if (opt == 6104) { fgc = true; col = CMAP_COLBR32; }
-  mPih->UseColors(fgc, col);
-  mPih->Refresh();  // On rafraichit le dessin     
-}
-
-}
-
+//++
 void PIH2DWdg::But3Press(int x, int y)
-{
-//printf("PIH2DWdg::But3Press(%d %d ) \n", x, y);
-optmenh2d->SetMsgParent((PIMsgHandler*)this);
-optmenh2d->Show(this, x, y);
-}
+//
+//	Gestion de l'utilisation du bouton-3 de la souris.
+//	Un seul objet est cree pour tous les histogrammes 2D.
+//	Il est connecte a un histogramme donnee par l'action du
+//	du bouton-3 de la souris dans la fenetre contenant
+//	le dessin de l'histogramme.
+//--
+{
+h2dWinArg->SetPIH2DWdg(this);
+h2dWinArg->SetMsgParent((PIMsgHandler*)this);
+if(!h2dWinArg->Visible()) h2dWinArg->Show();
+if(dbg) printf("PIH2DWdg::But3Press(%d,%d) h2dWinArg=%lx\n"
+              ,x,y,(long)h2dWinArg);
+}
+
+
+/////////////////////////////////////////////////////////////////
+//  Classe H2WinArg
+/////////////////////////////////////////////////////////////////
+
+//++
+H2WinArg::H2WinArg(PIH2DWdg *par)
+//
+//	Creation de la fenetre de gestion des parametres
+//	des dessins des histogrammes 2D.
+//--
+: PIWindow((PIMsgHandler *)par, "Options", PIWK_dialog,250,260,150,150)
+{
+string sdum;
+if(dbg) printf("H2WinArg::H2WinArg %lx par=%lx\n",(long)this,(long)par);
+
+mH2Wdg = NULL;
+
+mFgCol    = false;
+mCmap     = CMAP_GREYINV32;
+mTypScal  = 0;
+mTypDisp  = 0;
+mFPoints  = 0.5;
+mHMin     = 1.;
+mHMax     = -1.;
+mFracMin  = 0.1;
+mFracMax  = 0.9;
+mLogScale = 10.;
+
+// menus bar
+mPop[0] = new PIPUMenu((PIMsgHandler *)this,"Display");
+mPop[0]->AppendItem("Carres Var."  , 6101);
+mPop[0]->AppendItem("....."        , 6102);
+mPop[0]->AppendItem(".+12..Z*"     , 6103);
+mPop[0]->AppendItem("Carres Pleins", 6104);
+mOPop[0] = new PIOptMenu(this,mPop[0],100,25,10,10);
+sdum = "Carres Var."; mOPop[0]->SetValueStr(sdum);
+
+mPop[1] = new PIPUMenu((PIMsgHandler *)this,"Scale");
+mPop[1]->AppendItem("Lineaire", 6201);
+mPop[1]->AppendItem("Log10"   , 6202);
+mOPop[1] = new PIOptMenu(this,mPop[1],100,25,10,40);
+sdum = "Lineaire"; mOPop[1]->SetValueStr(sdum);
+
+mPop[2] = new PIPUMenu((PIMsgHandler *)this,"Color");
+mPop[2]->AppendItem("B&W"      , 6301);
+mPop[2]->AppendItem("Grey32"   , 6302);
+mPop[2]->AppendItem("GreyInv32", 6303);
+mPop[2]->AppendItem("RJ32"     , 6304);
+mPop[2]->AppendItem("BR32"     , 6305);
+mPop[2]->AppendItem("RV32"     , 6306);
+mPop[2]->AppendItem("Arc16"    , 6307);
+mOPop[2] = new PIOptMenu(this,mPop[2],100,25,10,70);
+sdum = "B&W"; mOPop[2]->SetValueStr(sdum);
+
+// Labels et zone de saisie texte
+mLab[0] = new PILabel(this, "     Dyn: ",60,30,10,110); 
+mLab[1] = new PILabel(this, "    Frac: ",60,30,10,145);
+mLab[2] = new PILabel(this, " LogScal: ",60,30,10,180);
+
+mText[0] = new PIText(this, "Dynamique",150,30,80,110);
+mText[1] = new PIText(this, "Fraction" ,150,30,80,145);
+mText[2] = new PIText(this, "LogScale" ,150,30,80,180);
+SetText();
+
+// Labels et curseur mobile
+mLab[3] = new PILabel(this, "   PerPt: ",60,30,10,215);
+mPScal = new PIScale(this,"FracPoints",6401,true,150,20,80,215);
+mPScal->SetMinMax(0,100);
+int imfp = mFPoints*100.f;
+mPScal->SetValue(imfp);
+
+// Boutons
+mBut[0] = new PIButton(this, "Apply", 6001, 50, 20, 150,10);
+mBut[1] = new PIButton(this, "Close", 6002, 50, 20, 150,35);
+mBut[2] = new PIButton(this, "Get"  , 6003, 50, 20, 150,60);
+mBut[3] = new PIButton(this, "Print", 6004, 50, 20, 150,85);
+FinishCreate();
+}
+
+//++
+H2WinArg::~H2WinArg()
+//
+//	Destructeur.
+//--
+{
+int i;
+if(dbg) printf("H2WinArg::~H2WinArg %lx\n",(long)this);
+for(i=0;i<3;i++) {delete mPop[i]; delete mOPop[i];}
+for(i=0;i<4;i++) delete mBut[i];
+for(i=0;i<4;i++) delete mLab[i];
+for(i=0;i<3;i++) delete mText[i];
+delete mPScal;
+}
+
+//++
+void H2WinArg::SetText()
+//
+//	Gestion des fenetres de saisie de texte.
+//--
+{
+string sdum;
+char str[256];
+sprintf(str,"%g %g",mHMin,mHMax);
+mText[0]->SetText(str);
+sprintf(str,"%g %g",mFracMin,mFracMax);
+mText[1]->SetText(str);
+sprintf(str,"%g",mLogScale);
+mText[2]->SetText(str);
+
+if(mTypDisp==0)      { sdum="Carres Var.";   mOPop[0]->SetValueStr(sdum);}
+else if(mTypDisp==1) { sdum=".....";         mOPop[0]->SetValueStr(sdum);}
+else if(mTypDisp==2) { sdum=".+12..Z*";      mOPop[0]->SetValueStr(sdum);}
+else if(mTypDisp==3) { sdum="Carres Pleins"; mOPop[0]->SetValueStr(sdum);}
+
+if(mTypScal==0)      { sdum="Lineaire"; mOPop[1]->SetValueStr(sdum);}
+else if(mTypScal==1) { sdum="Log10";    mOPop[1]->SetValueStr(sdum);}
+
+if(!mFgCol)                      { sdum="B&W";       mOPop[2]->SetValueStr(sdum);}
+else {
+  if(mCmap==CMAP_GREY32)         { sdum="Grey32";    mOPop[2]->SetValueStr(sdum);}
+  else if(mCmap==CMAP_GREYINV32) { sdum="GreyInv32"; mOPop[2]->SetValueStr(sdum);}
+  else if(mCmap==CMAP_COLRJ32)   { sdum="RJ32";      mOPop[2]->SetValueStr(sdum);}
+  else if(mCmap==CMAP_COLBR32)   { sdum="BR32";      mOPop[2]->SetValueStr(sdum);}
+  else if(mCmap==CMAP_COLRV32)   { sdum="RV32";      mOPop[2]->SetValueStr(sdum);}
+  else if(mCmap==CMAP_COL16)     { sdum="Arc16";     mOPop[2]->SetValueStr(sdum);}
+}
+
+printf("H2WinArg::SetText\n");
+}
+
+//++
+void H2WinArg::GetText()
+//
+//	Gestion des fenetres de saisie de texte.
+//--
+{
+sscanf(mText[0]->GetText().c_str(),"%g %g",&mHMin,&mHMax);
+sscanf(mText[1]->GetText().c_str(),"%g %g",&mFracMin,&mFracMax);
+sscanf(mText[2]->GetText().c_str(),"%g",&mLogScale);
+if(dbg) printf("H2WinArg::GetText\n");
+}
+
+//++
+void H2WinArg::SetPIH2DWdg(PIH2DWdg* h2wdg)
+//
+//	Connexion du widget de representation d'un histogramme 2D
+//	avec la fenetre de gestion des parametres.
+//--
+{
+mH2Wdg = h2wdg;
+if(dbg) printf("H2WinArg::SetPIH2DWdg mH2Wdg = %lx\n",(long)mH2Wdg);
+}
+
+//++
+void H2WinArg::Process(PIMessage msg, PIMsgHandler* sender, void*)
+//
+//	Gestions des messages.
+//--
+{
+if(dbg) printf("PIH2DWdg::Process(%d-%d , %lx ...) \n"
+              ,(int)UserMsg(msg),(int)ModMsg(msg), (long)sender);
+
+if(!mH2Wdg) return;
+PIHisto2D* mpih = mH2Wdg->GetPIHisto();
+if(!mpih) return;
+
+int opt = UserMsg(msg);
+     if (opt == 6101) { mTypDisp = 0; }
+else if (opt == 6102) { mTypDisp = 1; }
+else if (opt == 6103) { mTypDisp = 2; }
+else if (opt == 6104) { mTypDisp = 3; }
+
+else if (opt == 6201) { mTypScal = 0; }
+else if (opt == 6202) { mTypScal = 1; }
+
+else if (opt == 6301) { mFgCol = false; }
+else if (opt == 6302) { mFgCol = true;  mCmap = CMAP_GREY32; }
+else if (opt == 6303) { mFgCol = true;  mCmap = CMAP_GREYINV32; }
+else if (opt == 6304) { mFgCol = true;  mCmap = CMAP_COLRJ32; }
+else if (opt == 6305) { mFgCol = true;  mCmap = CMAP_COLBR32; }
+else if (opt == 6306) { mFgCol = true;  mCmap = CMAP_COLRV32; }
+else if (opt == 6307) { mFgCol = true;  mCmap = CMAP_COL16; }
+
+else if (opt == 6401) mFPoints = mPScal->GetValue()/100.;
+
+else if (opt==6001) {
+  GetText();
+  mpih->UseColors(mFgCol, mCmap);
+  mpih->UseScale(mTypScal,mLogScale);
+  mpih->UseDisplay(mTypDisp,mFPoints);
+  mpih->UseDyn(mHMin,mHMax);
+  mpih->UseFrac(mFracMin,mFracMax);
+  mpih->Refresh();  // On rafraichit le dessin
+}
+else if (opt==6002) {
+  this->Hide();
+}
+else if (opt==6003) {
+  mFgCol    = mpih->Color();
+  mCmap     = mpih->ColMap();
+  mTypScal  = mpih->TypScale();
+  mTypDisp  = mpih->TypDisplay();
+  mFPoints  = mpih->FPoints();
+  mHMin     = mpih->HMin();
+  mHMax     = mpih->HMax();
+  mFracMin  = mpih->FMin();
+  mFracMax  = mpih->FMax();
+  mLogScale = mpih->LogScale();
+  SetText();
+}
+else if (opt==6004) {
+  mpih->Print(2);
+}
+
+if(dbg) {
+  printf("H2WinArg::Process opt=%d col=%d,%d scal=%d disp=%d npt=%g\n"
+        ,opt,(int) mFgCol,(int) mCmap,mTypScal,mTypDisp,mFPoints);
+  printf("                  min,max= %g,%g frac= %g,%g logsc= %g\n"
+        ,mHMin,mHMax,mFracMin,mFracMax,mLogScale);
+}
+
+}
Index: /trunk/SophyaPI/PI/pihisto2d.h
===================================================================
--- /trunk/SophyaPI/PI/pihisto2d.h	(revision 81)
+++ /trunk/SophyaPI/PI/pihisto2d.h	(revision 82)
@@ -1,8 +1,14 @@
 #ifndef PIHISTO2D_H
 #define PIHISTO2D_H
+
+#include "pisysdep.h"
+#include PIMENU_H 
+#include PIMENUBAR_H 
+#include PIOPTMENU_H
 
 #include "histos2.h"
 #include "piscdrawwdg.h"
 
+////////////////////////////////////////////////////////////////////
 class PIHisto2D : public PIScDrawer {
 public:
@@ -10,15 +16,41 @@
   virtual            ~PIHisto2D();
           void       UseColors(bool fg=false, CMapId cmap=CMAP_GREYINV32);
-  virtual void       Draw(PIGraphicUC* g, float xmin, float ymin, float xmax, float ymax);
+          void       UseScale(unsigned short type=0,float logscale=10.);
+          void       UseDisplay(unsigned short type=0, float fnpt=0.5);
+          void       UseDyn(float hmin=1., float hmax=-1.);
+          void       UseFrac(float frmin=0.1, float frmax=0.9);
+          void       Print(int lp=0);
+  virtual void       Draw(PIGraphicUC* g,float xmin,float ymin,float xmax,float ymax);
   virtual void       UpdateSize();
   virtual void       DrawStats(PIGraphicUC* g);
-  inline  Histo2D*   Histogram() { return(mHisto); }
+
+  inline Histo2D*       Histogram() { return(mHisto); }
+  inline bool           Color() { return(mFgCol); }
+  inline CMapId         ColMap() { return(mCmap); }
+  inline unsigned short TypScale() { return(mTypScal); }
+  inline unsigned short TypDisplay() { return(mTypDisp); }
+  inline float          FPoints() { return(mFPoints); }
+  inline float          HMax() { return(mHMax);}
+  inline float          HMin() { return(mHMin);}
+  inline float          FMax() { return(mFracMax);}
+  inline float          FMin() { return(mFracMin);}
+  inline float          LogScale() { return(mLogScale);}
 
 protected:
+  int NPixBin(PIGraphicUC* g);
+  char HPrint2(float f);
+
   Histo2D* mHisto;
   bool mFgCol;
   CMapId mCmap;
+  unsigned short mTypScal;
+  unsigned short mTypDisp;
+  float mFPoints;
+  float mHMin,mHMax;
+  float mFracMin,mFracMax;
+  float mLogScale;
 };
 
+////////////////////////////////////////////////////////////////////
 class PIH2DWdg : public PIScDrawWdg {
 public:
@@ -27,7 +59,6 @@
                      ~PIH2DWdg();
 
-  virtual void       Process(PIMessage msg, PIMsgHandler* sender, void* data=NULL);
-  void               SetHisto(Histo2D* histo, bool fg=false, CMapId cmap=CMAP_GREYINV32);
-
+  void               SetHisto(Histo2D* histo);
+  inline PIHisto2D*  GetPIHisto() {return mPih;}
 
   virtual string     GetClickText(float x, float y); 
@@ -39,3 +70,33 @@
 };
 
+////////////////////////////////////////////////////////////////////
+class H2WinArg : public PIWindow {
+public :
+               H2WinArg(PIH2DWdg *par);
+               ~H2WinArg();
+          void SetPIH2DWdg(PIH2DWdg* h2wdg);
+          void SetText();
+          void GetText();
+  virtual void Process(PIMessage msg, PIMsgHandler* sender, void* data=NULL);
+
+protected:
+  PIH2DWdg  * mH2Wdg;
+
+  PIPUMenu  * mPop[3];
+  PIOptMenu * mOPop[3];
+  PIButton  * mBut[4];
+  PILabel   * mLab[4];
+  PIText    * mText[3];
+  PIScale   * mPScal;
+
+  bool mFgCol;
+  CMapId mCmap;
+  unsigned short mTypScal;
+  unsigned short mTypDisp;
+  float mFPoints;
+  float mHMin,mHMax;
+  float mFracMin,mFracMax;
+  float mLogScale;
+};
+
 #endif
