Index: trunk/SophyaPI/PIext/piafitting.cc
===================================================================
--- trunk/SophyaPI/PIext/piafitting.cc	(revision 379)
+++ trunk/SophyaPI/PIext/piafitting.cc	(revision 381)
@@ -1,3 +1,3 @@
-//CMVBUG reste pb suivant:
+//CMVBUG reste pb suivant sous Linux-egcs (OSF1-cxx c'est ok):
 //openppf cmvwppf.ppf
 //fitw h1g g2 p:4500,45,10,900
@@ -53,5 +53,7 @@
   PIButton**   but; int nbut;
   PICheckBox** ckb; int nckb;
+  PIOptMenu**  pom; int npom;
   bool ReFillGData;
+  int saveI1,saveI2, saveJ1, saveJ2;
 };
 
@@ -358,8 +360,8 @@
 if(mOpt.lpg<0) mOpt.lpg = 0;
 mOpt.i1 = (mOpt.i1<0||mOpt.i1>=mNBinX)? 0: mOpt.i1;
-mOpt.i2 = (mOpt.i2<0||mOpt.i2>=mNBinX||mOpt.i2<mOpt.i1)? mNBinX-1: mOpt.i2;
+mOpt.i2 = (mOpt.i2<0||mOpt.i2>=mNBinX||mOpt.i2<=mOpt.i1)? mNBinX-1: mOpt.i2;
 if(mNVar>=2) {
   mOpt.j1 = (mOpt.j1<0||mOpt.j1>=mNBinY)? 0: mOpt.j1;
-  mOpt.j2 = (mOpt.j2<0||mOpt.j2>=mNBinY||mOpt.j2<mOpt.j1)? mNBinY-1: mOpt.j2;
+  mOpt.j2 = (mOpt.j2<0||mOpt.j2>=mNBinY||mOpt.j2<=mOpt.j1)? mNBinY-1: mOpt.j2;
 } else mOpt.j2 = mOpt.j1 = 0;
 if(mOpt.polcx==2) {
@@ -772,4 +774,5 @@
 {
 ReFillGData = false;
+saveI1 = saveI2 = saveJ1 = saveJ2 = 0;
 mDap = par;
 mFitter = fiter;
@@ -783,4 +786,5 @@
 nbut = 20;        but = new PIButton*[nbut];   {for(int i=0;i<nbut;i++) but[i]=NULL;}
 nckb = 20+npar;   ckb = new PICheckBox*[nckb]; {for(int i=0;i<nckb;i++) ckb[i]=NULL;}
+npom = 10;        pom = new PIOptMenu*[npom];  {for(int i=0;i<npom;i++) pom[i]=NULL;}
 
 // On definit la taille a partir de la taille par defaut des composantes
@@ -792,9 +796,9 @@
 
 int wszx = (5*bsx+5*spx)+spx;
-int wszy = 8*(bsy+spy)+npar*(bsy+spy)+spy;
+int wszy = 9*(bsy+spy)+npar*(bsy+spy)+spy;
 SetSize(wszx, wszy);
 int cpx,cpy;
 
-// 1 ere ligne
+// new ligne
 cpx=spx; cpy=spy;
 but[0] = new PIButton(this,"Fr.Last",111,bsx,bsy,cpx,cpy);
@@ -810,64 +814,78 @@
 ckb[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 
-// 2 ieme ligne
-cpx=spx; cpy += bsy+spy;
-ckb[2] = new PICheckBox(this,"Cent X",1003,bsx,bsy,cpx,cpy);
-ckb[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
+// new ligne
+cpx=spx; cpy += bsy+spy -spy;
+lab[0] = new PILabel(this,"- Center X -",2*bsx,bsy,cpx,cpy);
+lab[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
+cpx += 2*bsx+spx;
+lab[1] = new PILabel(this,"- Center Y -",2*bsx,bsy,cpx,cpy);
+lab[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
+
+// new ligne
+cpx=spx; cpy += bsy+spy -spy;
+pom[0] = new PIOptMenu(this,"No",bsx,bsy,cpx,cpy);
+  pom[0]->AppendItem("No",2001);
+  pom[0]->AppendItem("Value",2002);
+  pom[0]->AppendItem("Auto",2003);
+pom[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 cpx+=bsx+spx;
 txt[0] = new PIText(this,"",bsx,bsy,cpx,cpy);
 txt[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 cpx+=bsx+2*spx;
-ckb[3] = new PICheckBox(this,"Y",1004,bsx/2,bsy,cpx,cpy);
-ckb[3]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
-cpx+=bsx/2+spx;
+pom[1] = new PIOptMenu(this,"No",bsx,bsy,cpx,cpy);
+  pom[1]->AppendItem("No",2011);
+  pom[1]->AppendItem("Value",2012);
+  pom[1]->AppendItem("Auto",2013);
+pom[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
+cpx+=bsx+spx;
 txt[1] = new PIText(this,"",bsx,bsy,cpx,cpy);
 txt[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 
-// 3 ieme ligne
+// new ligne
 cpx=spx; cpy += bsy+spy;
-lab[0] = new PILabel(this,"Err cste",1.25*bsx,bsy,cpx,cpy);
-lab[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
+lab[2] = new PILabel(this,"Err cste",1.25*bsx,bsy,cpx,cpy);
+lab[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 cpx+=1.25*bsx+spx;
 txt[2] = new PIText(this,"",bsx,bsy,cpx,cpy);
 txt[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 cpx+=bsx+2*spx;
-lab[1] = new PILabel(this,"sqrt",bsx,bsy,cpx,cpy);
-lab[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
+lab[3] = new PILabel(this,"sqrt",bsx,bsy,cpx,cpy);
+lab[3]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 cpx+=bsx+spx;
 txt[3] = new PIText(this,"",bsx,bsy,cpx,cpy);
 txt[3]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 
-// 4 ieme ligne
+// new ligne
 cpx=spx; cpy += bsy+spy;
-lab[2] = new PILabel(this,"Stop Xi2",1.25*bsx,bsy,cpx,cpy);
-lab[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
+lab[4] = new PILabel(this,"Stop Xi2",1.25*bsx,bsy,cpx,cpy);
+lab[4]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 cpx+=1.25*bsx+spx;
 txt[4] = new PIText(this,"",bsx,bsy,cpx,cpy);
 txt[4]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 cpx+=bsx+spx;
-lab[3] = new PILabel(this,"Iter",bsx, bsy, cpx, cpy);
-lab[3]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
+lab[5] = new PILabel(this,"Iter",bsx, bsy, cpx, cpy);
+lab[5]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 cpx+=bsx+spx;
 txt[5] = new PIText(this,"",bsx,bsy,cpx,cpy);
 txt[5]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 
-// 5 ieme ligne
+// new ligne
 cpx=spx; cpy += bsy+spy;
-lab[4] = new PILabel(this,"Print",bsx,bsy,cpx,cpy);
-lab[4]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
+lab[6] = new PILabel(this,"Print",bsx,bsy,cpx,cpy);
+lab[6]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 cpx+=bsx+spx;
 txt[6] = new PIText(this,"",bsx/2,bsy,cpx,cpy);
 txt[6]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 cpx+=bsx/2+spx;
-lab[5] = new PILabel(this,"Debug",bsx,bsy,cpx,cpy);
-lab[5]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
+lab[7] = new PILabel(this,"Debug",bsx,bsy,cpx,cpy);
+lab[7]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 cpx+=bsx+spx;
 txt[7] = new PIText(this,"",bsx/2,bsy,cpx,cpy);
 txt[7]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 
-// 6 ieme ligne
+// new ligne
 cpx=spx; cpy += bsy+spy;
-lab[6] = new PILabel(this,"Range X",bsx,bsy,cpx,cpy);
-lab[6]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
+lab[8] = new PILabel(this,"Range X",bsx,bsy,cpx,cpy);
+lab[8]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 cpx+=bsx+spx;
 txt[8] = new PIText(this,"",0.75*bsx,bsy,cpx,cpy);
@@ -877,6 +895,6 @@
 txt[9]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 cpx+=0.75*bsx+spx;
-lab[7] = new PILabel(this,"Y",bsx/2,bsy,cpx,cpy);
-lab[7]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
+lab[9] = new PILabel(this,"Y",bsx/2,bsy,cpx,cpy);
+lab[9]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 cpx+=bsx/2+spx;
 txt[10] = new PIText(this,"",0.75*bsx,bsy,cpx,cpy);
@@ -886,5 +904,5 @@
 txt[11]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 
-// 7 ieme ligne
+// new ligne
 cpx=spx; cpy+=bsy+spy;
 but[2] = new PIButton(this, "Dismiss",777,bsx,bsy,cpx,cpy);
@@ -897,26 +915,26 @@
 but[4]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 cpx+=bsx+spx;
-lab[8] = new PILabel(this,fun.c_str(),bsx/2,bsy,cpx,cpy);
-lab[8]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
-
-// Parametres (npar lignes)
+lab[10] = new PILabel(this,fun.c_str(),bsx/2,bsy,cpx,cpy);
+lab[10]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
+
+// new lines: Parametres (npar lignes)
 cpx=spx; cpy+=bsy+spy;
-lab[9] = new PILabel(this,"Par",bsx/2,bsy,cpx,cpy);
-lab[9]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
+lab[11] = new PILabel(this,"Par",bsx/2,bsy,cpx,cpy);
+lab[11]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 cpx+=bsx/2+spx;
-lab[10] = new PILabel(this,"F",bsx/3,bsy,cpx,cpy);
-lab[10]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
+lab[12] = new PILabel(this,"F",bsx/3,bsy,cpx,cpy);
+lab[12]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 cpx+=bsx/3+spx;
-lab[11] = new PILabel(this,"Init",bsx,bsy,cpx,cpy);
-lab[11]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
-cpx+=bsx+spx;
-lab[12] = new PILabel(this,"Step",bsx,bsy,cpx,cpy);
-lab[12]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
-cpx+=bsx+spx;
-lab[13] = new PILabel(this,"Min",bsx,bsy,cpx,cpy);
+lab[13] = new PILabel(this,"Init",bsx,bsy,cpx,cpy);
 lab[13]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 cpx+=bsx+spx;
-lab[14] = new PILabel(this,"Max",bsx,bsy,cpx,cpy);
+lab[14] = new PILabel(this,"Step",bsx,bsy,cpx,cpy);
 lab[14]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
+cpx+=bsx+spx;
+lab[15] = new PILabel(this,"Min",bsx,bsy,cpx,cpy);
+lab[15]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
+cpx+=bsx+spx;
+lab[16] = new PILabel(this,"Max",bsx,bsy,cpx,cpy);
+lab[16]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 if(npar>0) {
   for(int i=0;i<npar;i++) {
@@ -949,8 +967,10 @@
 for(i=0;i<nbut;i++) if(but[i]) {delete but[i]; but[i]=NULL;}
 for(i=0;i<nckb;i++) if(ckb[i]) {delete ckb[i]; ckb[i]=NULL;}
+for(i=0;i<npom;i++) if(pom[i]) {delete pom[i]; pom[i]=NULL;}
 if(lab) {delete lab; lab=NULL; nlab=0;}
 if(txt) {delete txt; txt=NULL; ntxt=0;}
 if(but) {delete but; but=NULL; nbut=0;}
 if(ckb) {delete ckb; ckb=NULL; nckb=0;}
+if(pom) {delete pom; pom=NULL; npom=0;}
 }
 
@@ -973,6 +993,4 @@
 ckb[0]->SetState(mFitter->mOpt.okfun);
 ckb[1]->SetState(mFitter->mOpt.okres);
-ckb[2]->SetState((mFitter->mOpt.polcx>0)?true:false);
-ckb[3]->SetState((mFitter->mOpt.polcy>0)?true:false);
 if(npar>0)
   for(int i=0;i<npar;i++) ckb[20+i]->SetState((mFitter->mFix(i)>=1.)?true:false);
@@ -1007,5 +1025,5 @@
 void PIAFitterWind::Process(PIMessage msg, PIMsgHandler* sender, void* data)
 {
-int lp = 1;
+int lp = (mFitter->mOpt.lp>2)?1:0;;
 int npar = mFitter->mNPar;
 
@@ -1013,5 +1031,6 @@
 NamedObjMgr omg;
 if(omg.GetObj(mFitter->mNObj) == NULL) {
-  cout<<"PIAFitterWind::Process Error , Pas d'objet de nom "<<mFitter->mNObj<<endl;
+  cout<<"PIAFitterWind::Process Error , Pas d'objet de nom "
+      <<mFitter->mNObj<<endl;
   mFitter->ResetDPointer(); return;
 }
@@ -1019,9 +1038,8 @@
 // On recupere les champs textes
 string dum; char str[128];
-int lenxc=0, lenyc=0;
 dum=txt[0]->GetText(); strcpy(str,dum.c_str()); strip(str,'B',' ');
-  sscanf(str,"%lf",&(mFitter->mOpt.xc)); lenxc = strlen(str);
+  sscanf(str,"%lf",&(mFitter->mOpt.xc));
 dum=txt[1]->GetText(); strcpy(str,dum.c_str()); strip(str,'B',' ');
-  sscanf(str,"%lf",&(mFitter->mOpt.yc)); lenyc = strlen(str);
+  sscanf(str,"%lf",&(mFitter->mOpt.yc));
 dum=txt[2]->GetText(); strcpy(str,dum.c_str()); strip(str,'B',' ');
   sscanf(str,"%lf",&(mFitter->mOpt.err_e));
@@ -1037,11 +1055,25 @@
   sscanf(str,"%d",&(mFitter->mOpt.lpg));
 dum=txt[8]->GetText(); strcpy(str,dum.c_str()); strip(str,'B',' ');
+// Attention si les valeurs de mOpt.i1/.i2/.j1/.j2 ont ete changees
   sscanf(str,"%d",&(mFitter->mOpt.i1));
 dum=txt[9]->GetText(); strcpy(str,dum.c_str()); strip(str,'B',' ');
   sscanf(str,"%d",&(mFitter->mOpt.i2));
 dum=txt[10]->GetText(); strcpy(str,dum.c_str()); strip(str,'B',' ');
-sscanf(str,"%d",&(mFitter->mOpt.j1));
+  sscanf(str,"%d",&(mFitter->mOpt.j1));
 dum=txt[11]->GetText(); strcpy(str,dum.c_str()); strip(str,'B',' ');
   sscanf(str,"%d",&(mFitter->mOpt.j2));
+if(saveI1!=mFitter->mOpt.i1 || saveI2!=mFitter->mOpt.i2 ||
+   saveJ1!=mFitter->mOpt.j1 || saveJ2!=mFitter->mOpt.j2 ) {
+  if(lp)
+    cout<<"Range changed: I("<<saveI1<<","<<saveI2
+        <<") -> I("<<mFitter->mOpt.i1<<","<<mFitter->mOpt.i2
+        <<")  ou   J("<<saveJ1<<","<<saveJ2
+        <<") -> J("<<mFitter->mOpt.j1<<","<<mFitter->mOpt.j2
+        <<")"<<endl;
+  ReFillGData = true;
+  saveI1=mFitter->mOpt.i1; saveI2=mFitter->mOpt.i2;
+  saveJ1=mFitter->mOpt.j1; saveJ2=mFitter->mOpt.j2;
+}
+
 if(npar>0) {
   for(int i=0;i<npar;i++) {
@@ -1065,10 +1097,11 @@
   return;
 }
-if(msg ==666) {
+else if(msg ==666) {
   if(lp) cout<<"Refresh"<<endl;
+  mFitter->CheckOptions();
   if(ReFillGData) mFitter->FillGData();
   ReFillGData = false;
 }
-if(msg ==111) {
+else if(msg ==111) {
   if(lp) cout<<"Update from last"<<endl;
   mFitter->ResetOptions();
@@ -1078,5 +1111,5 @@
   ReFillGData = true;
 }
-if(msg ==222) {
+else if(msg ==222) {
   if(lp) cout<<"Default options/par"<<endl;
   mFitter->ResetOptions();
@@ -1084,6 +1117,7 @@
   ReFillGData = true;
 }
-if(msg ==333) {
+else if(msg ==333) {
   if(lp) cout<<"Do the fit"<<endl;
+  mFitter->CheckOptions();
   if(ReFillGData) mFitter->FillGData();
   ReFillGData = false;
@@ -1091,5 +1125,5 @@
   if(rc>=0) mFitter->FitFunRes();
 }
-if(msg==1001) {
+else if(msg==1001) {
   if(ckb[0]->GetState()) {
     if(lp) cout<<"Gen fitted function"<<endl;
@@ -1100,5 +1134,5 @@
   }
 }
-if(msg==1002) {
+else if(msg==1002) {
   if(ckb[1]->GetState()) {
     if(lp) cout<<"Gen fitted residus"<<endl;
@@ -1109,25 +1143,17 @@
   }
 }
-if(msg==1003) {
-  if(ckb[2]->GetState()) {
-    if(lp) cout<<"Centrage X"<<endl;
-    if(lenxc>0) mFitter->mOpt.polcx = 1; else mFitter->mOpt.polcx = 2;
-  } else if(!ckb[2]->GetState()) {
-    if(lp) cout<<"No Centrage X"<<endl;
-    mFitter->mOpt.polcx = 0;
-  }
+else if(2001<=msg && msg<=2003) {
+  mFitter->mOpt.polcx = msg-2001;
+  if(lp) cout<<"Centrage X polcx="<<mFitter->mOpt.polcx
+             <<" xc="<<mFitter->mOpt.xc<<endl;
   ReFillGData = true;
 }
-if(msg==1004) {
-  if(ckb[3]->GetState()) {
-    if(lp) cout<<"Centrage Y"<<endl;
-    if(lenyc>0) mFitter->mOpt.polcy = 1; else mFitter->mOpt.polcy = 2;
-  } else if(!ckb[3]->GetState()) {
-    if(lp) cout<<"No Centrage Y"<<endl;
-    mFitter->mOpt.polcy = 0;
-  }
+else if(2011<=msg && msg<=2013) {
+  mFitter->mOpt.polcx = msg-2011;
+  if(lp) cout<<"Centrage Y polcy="<<mFitter->mOpt.polcy
+             <<" yc="<<mFitter->mOpt.yc<<endl;
   ReFillGData = true;
 }
-if(msg>=1500 && msg<2000) {
+else if(msg>=1500 && msg<2000) {
   int ip = msg-1500;
   if(ckb[20+ip]->GetState()) {
