Index: trunk/SophyaPI/PIext/piafitting.cc
===================================================================
--- trunk/SophyaPI/PIext/piafitting.cc	(revision 1111)
+++ trunk/SophyaPI/PIext/piafitting.cc	(revision 1200)
@@ -42,5 +42,5 @@
 class PIAFitterWind :  public PIWindow {
 public :
-		PIAFitterWind(PIStdImgApp* par, PIAFitter* fiter);
+		PIAFitterWind(PIStdImgApp* par, PIAFitter* fiter,string func);
   virtual	~PIAFitterWind();
   virtual void  Show();
@@ -50,4 +50,5 @@
   PIStdImgApp* mDap;
   PIAFitter*   mFitter;
+  string mFunc;
   PILabel**    lab; int nlab;
   PIText**     txt; int ntxt;
@@ -56,6 +57,8 @@
   PIOptMenu**  pom; int npom;
   bool ReFillGData;
+  bool ReDecodeFunc;
+  double ErrValue;
   int saveI1,saveI2, saveJ1, saveJ2;
-  double ErrValue;
+  double saveErrValue,saveXC,saveYC;
 };
 
@@ -184,5 +187,5 @@
 , mPar(1), mStep(1), mMin(1), mMax(1), mFix(1)
 , mParSave(1), mStepSave(1), mMinSave(1), mMaxSave(1), mFixSave(1)
-, mFit(NULL)
+, mFit(NULL),ApplyXYcentering(false)
 , mV(NULL), mH(NULL), mM(NULL), mH2(NULL), mIm(NULL), mG(NULL)
 , mFunction(NULL), mFName(""), mFunc(NULL)
@@ -549,5 +552,5 @@
   else if(mH2) mOpt.xc = (mH2->XMin()+mH2->XMax())/2.;
   else if(mG)  {double mini,maxi; mG->GetMnMx(2,mini,maxi); mOpt.xc=(mini+maxi)/2.;}
-  else if(mIm) {mOpt.xc = mIm->XOrg() * mIm->XPixSize()*(mOpt.i2-mOpt.i1+1)/2.;}
+  else if(mIm) {mOpt.xc = mIm->XOrg() + mIm->XPixSize()*(mOpt.i2-mOpt.i1+1)/2.;}
 }
 if(mOpt.polcy==2 && mNVar>=2) {
@@ -555,5 +558,5 @@
   if(mH2) mOpt.yc = (mH2->YMin()+mH2->YMax())/2.;
   if(mG)  {double mini,maxi; mG->GetMnMx(12,mini,maxi); mOpt.yc=(mini+maxi)/2.;}
-  if(mIm) {mOpt.yc = mIm->YOrg() * mIm->YPixSize()*(mOpt.j2-mOpt.j1+1)/2.;}
+  if(mIm) {mOpt.yc = mIm->YOrg() + mIm->YPixSize()*(mOpt.j2-mOpt.j1+1)/2.;}
 }
 if(mOpt.err_e>0.) mOpt.err_E=-1.;
@@ -612,5 +615,8 @@
 
   // Remplissage de generalfitdata
-  if(mFName[0]=='p') {x -= mOpt.xc; if(mNVar>=2) y -= mOpt.yc;}
+  if(ApplyXYcentering) { // pour fitlin
+    if(mOpt.polcx>0) x-=mOpt.xc;
+    if(mNVar>=2 && mOpt.polcy>0) y-=mOpt.yc;
+  }
   if(mNVar==1)      mGData->AddData1(x,f,e);
   else if(mNVar==2) mGData->AddData2(x,y,f,e);
@@ -645,4 +651,5 @@
 // Fonction a fitter
 // ATTENTION: cette methode a besoin que les donnees soient lues
+//                                    (pour mopt.xc,yc et mNVar)
 {
 if(func.length()<=0)
@@ -660,5 +667,5 @@
   int degre=0; if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
   cout<<"Fit polynome 1D de degre "<<degre<<endl;
-  Polyn1D* myf = new Polyn1D(degre,mOpt.xc);
+  Polyn1D* myf = new Polyn1D(degre,((mOpt.polcx>0)?mOpt.xc:0.));
   mFunction = myf; mNPar = mFunction->NPar(); mFName = func;
 
@@ -667,6 +674,6 @@
   cout<<"Fit d'exponentielle+polynome 1D de degre "<<degre<<endl;
   Exp1DPol* myf;
-  if(degre>=0) myf = new Exp1DPol((unsigned int)degre,mOpt.xc);
-       else    myf = new Exp1DPol(mOpt.xc);
+  if(degre>=0) myf = new Exp1DPol((unsigned int)degre,((mOpt.polcx>0)?mOpt.xc:0.));
+       else    myf = new Exp1DPol(((mOpt.polcx>0)?mOpt.xc:0.));
   mFunction = myf; mNPar = mFunction->NPar(); mFName = func;
 
@@ -690,5 +697,6 @@
   int degre=0; if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
   cout<<"Fit polynome 2D de degre "<<degre<<endl;
-  Polyn2D* myf = new Polyn2D(degre,mOpt.xc,mOpt.yc);
+  Polyn2D* myf =
+    new Polyn2D(degre,((mOpt.polcx>0)?mOpt.xc:0.),((mOpt.polcy>0)?mOpt.yc:0.));
   mFunction = myf; mNPar = mFunction->NPar(); mFName = func;
 
@@ -1165,15 +1173,16 @@
 CheckOptions();
 if(mOpt.lp>0) PrintOptions();
+if(kw == "fitlin") ApplyXYcentering=true; else ApplyXYcentering=false;
 FillGData();
 DecodeFunction(tokens[1]);
 DecodeParam(mSp,mSs,mSm,mSM,mSf);
-if (kw == "fit") {
+if(kw == "fit") {
   int rc = DoFit();
   if(rc>=0) FitFunRes();
-} else if (kw == "fitlin") {
+} else if(kw == "fitlin") {
   LinFit();
-} else if (kw == "fitw") {
+} else if(kw == "fitw") {
   if(FWindFit!=NULL) {delete FWindFit; FWindFit=NULL;}
-  FWindFit = new PIAFitterWind(mApp,this);
+  FWindFit = new PIAFitterWind(mApp,this,tokens[1]);
   FWindFit->Show();
 }
@@ -1293,8 +1302,11 @@
 
 /* --Methode-- */
-PIAFitterWind::PIAFitterWind(PIStdImgApp* par, PIAFitter* fiter)
+PIAFitterWind::PIAFitterWind(PIStdImgApp* par, PIAFitter* fiter,string func)
 : PIWindow((PIMsgHandler*)par, "PIAFitter", PIWK_normal, 240, 240, 150, 150)
-, mDap(par), mFitter(fiter), ReFillGData(false)
-, saveI1(0), saveI2(0), saveJ1(0), saveJ2(0), ErrValue(1.)
+, mDap(par), mFitter(fiter), mFunc(func)
+, ReFillGData(false), ReDecodeFunc(false)
+, ErrValue(1.)
+, saveI1(0), saveI2(0), saveJ1(0), saveJ2(0)
+, saveErrValue(1.), saveXC(0.), saveYC(0.)
 {
 #ifdef SANS_EVOLPLANCK
@@ -1571,4 +1583,9 @@
   if(mFitter->mOpt.err_e>0. ) mFitter->mOpt.err_e = ErrValue;
   if(mFitter->mOpt.err_E>0. ) mFitter->mOpt.err_E = ErrValue;
+  if(saveErrValue!=ErrValue) {
+    if(lp) cout<<"ErrValue changed: "<<ErrValue<<endl;
+    ReFillGData = true;
+    saveErrValue = ErrValue;
+  }
 dum=txt[1]->GetText(); strcpy(str,dum.c_str()); strip(str,'B',' ');
   sscanf(str,"%d,%d",&(mFitter->mOpt.lp),&(mFitter->mOpt.lpg));
@@ -1602,4 +1619,10 @@
 dum=txt[9]->GetText(); strcpy(str,dum.c_str()); strip(str,'B',' ');
   sscanf(str,"%lf",&(mFitter->mOpt.yc));
+  if(saveXC!=mFitter->mOpt.xc || saveYC!=mFitter->mOpt.yc) {
+    if(lp) cout<<"mOpt.xc,yc changed: "<<mFitter->mOpt.xc
+               <<" , "<<mFitter->mOpt.xc<<endl;
+    ReFillGData = true; ReDecodeFunc = true;
+    saveXC = mFitter->mOpt.xc; saveYC = mFitter->mOpt.yc;
+  }
 
 if(npar>0) {
@@ -1640,6 +1663,11 @@
   if(lp) cout<<"Do the fit"<<endl;
   mFitter->CheckOptions();
-  if(ReFillGData) mFitter->FillGData();
+  if(ReFillGData) {
+    if(lp) cout<<"ReFill Data"<<endl;
+    mFitter->FillGData();
+  }
   ReFillGData = false;
+  if(ReDecodeFunc) mFitter->DecodeFunction(mFunc);
+  ReDecodeFunc = false;
   int rc = mFitter->DoFit();
   if(rc>=0) mFitter->FitFunRes();
@@ -1680,5 +1708,5 @@
   if(lp) cout<<"Centrage X polcx="<<mFitter->mOpt.polcx
              <<" xc="<<mFitter->mOpt.xc<<endl;
-  ReFillGData = true;
+  ReFillGData = true; ReDecodeFunc = true;
 }
 else if(2011<=msg && msg<=2013) {
@@ -1686,5 +1714,5 @@
   if(lp) cout<<"Centrage Y polcy="<<mFitter->mOpt.polcy
              <<" yc="<<mFitter->mOpt.yc<<endl;
-  ReFillGData = true;
+  ReFillGData = true; ReDecodeFunc = true;
 }
 else if(msg>=1500 && msg<2000) {
