Index: trunk/SophyaPI/PIext/piafitting.cc
===================================================================
--- trunk/SophyaPI/PIext/piafitting.cc	(revision 389)
+++ trunk/SophyaPI/PIext/piafitting.cc	(revision 390)
@@ -118,4 +118,7 @@
 //|      F : initialisation a partir des resultats et de l'etat du fit precedent
 //|          (option non prioritaire sur les definitions p:,s:,m:,M:,f:o:)
+//|      a : initialisation automatique des parametres du fit (si disponible)
+//|          (option non prioritaire sur les definitions p:,s:,m:,M:,f:o:
+//|           et sur l'initialisation pa l'option "F")
 //|      f : generation d'un Objet identique contenant la fonction fittee
 //|      r : generation d'un Objet identique contenant les residus
@@ -176,5 +179,5 @@
 , mFit(NULL)
 , mV(NULL), mH(NULL), mM(NULL), mH2(NULL), mIm(NULL), mG(NULL)
-, mFunction(NULL), mFName(""), mFunc(NULL)
+, mFunction(NULL), mFName(""), mFunc(NULL), mFitUserFunc(false)
 , mDlUFunc(NULL), mNameFitFunc(""), mFitFunc(NULL), mFitFuncDer(NULL)
 , mUFNVar(0), mUFNPar(0)
@@ -249,4 +252,5 @@
 mOpt.i1 = mOpt.j1 = mOpt.i2 = mOpt.j2 = -1;
 mOpt.fromlastfit = false;
+mOpt.autoinifit = false;
 }
 
@@ -263,4 +267,5 @@
 if(strstr(opt.c_str(),",F,"))  // init options/param a partir du fit precedent
   {mOpt = mOptSave; mOpt.fromlastfit = true;}
+if(strstr(opt.c_str(),",a,")) mOpt.autoinifit = true; // init auto par fit
 if(strstr(opt.c_str(),",r,")) mOpt.okres = true;  // residus
 if(strstr(opt.c_str(),",f,")) mOpt.okfun = true;  // fonction fittee
@@ -436,5 +441,5 @@
     <<" TypE="<<mOpt.err_e<<","<<mOpt.err_E
     <<" StpX2="<<mOpt.stc2<<" Nstep="<<mOpt.nstep<<endl
-    <<" Init.LFit="<<mOpt.fromlastfit
+    <<" Init.LFit="<<mOpt.fromlastfit<<" AutoIni.Fit="<<mOpt.autoinifit
     <<" lp,lpg="<<mOpt.lp<<","<<mOpt.lpg<<endl;
 return;
@@ -504,8 +509,10 @@
 if(mFunc!=NULL)     {delete mFunc;     mFunc=NULL;}
 mNPar=0;
+mFitUserFunc = false;
 
 if(func == mNameFitFunc) { // Fonction utilisateur
   mFunc = new GeneralFunc(mUFNVar,mUFNPar,mFitFunc,mFitFuncDer);
   mNPar = mUFNPar;
+  mFitUserFunc = true;
   cout<<"Fonction utilisateur nvar="<<mUFNVar<<", npar="<<mNPar<<endl;
 } else if(func[0]=='p' && mNVar==1) { //polynome
@@ -596,4 +603,57 @@
 
 /* --Methode-- */
+void PIAFitter::AutoIniFit(void)
+// Initialisation automatique des parametres du fit
+{
+cout<<"CMV: to be done : PIAFitter::AutoIniFit"<<endl;
+if(mFitUserFunc) { // Fonction utilisateur
+  cout<<"PIAFitter::AutoIniFit : Fonction utilisateur, pas d'init auto"<<endl;
+
+} else if(mFName[0]=='p' && mNVar==1) { //poly 1D
+  cout<<"PIAFitter::AutoIniFit : Auto Init type polynome 1D"<<endl;
+
+} else if(mFName[0]=='e' && mNVar==1) { //expo+pol 1D
+  cout<<"PIAFitter::AutoIniFit : Auto Init type expo+pol 1D"<<endl;
+
+} else if(mFName[0]=='g' && mNVar==1) { //gauss en haut 1D
+  cout<<"PIAFitter::AutoIniFit : Auto Init type gauss_haut+pol 1D"<<endl;
+
+} else if(mFName[0]=='G' && mNVar==1) { //gauss en vol 1D
+  cout<<"PIAFitter::AutoIniFit : Auto Init type gauss_vol+pol 1D"<<endl;
+
+} else if(mFName[0]=='p' && mNVar==2) { //poly 2D
+  cout<<"PIAFitter::AutoIniFit : Auto Init type polynome 2D"<<endl;
+
+} else if((mFName[0]=='G'||mFName[0]=='d') && mNVar==2) { //gauss+fond en vol
+  cout<<"PIAFitter::AutoIniFit : Auto Init type gauss_vol+fond 2D"<<endl;
+
+} else if(mFName[0]=='D' && mNVar==2) { //DLgauss+fond en vol 2D
+  cout<<"PIAFitter::AutoIniFit : Auto Init type DLgauss_vol+fond 2D"<<endl;
+  Vector dum(mNPar);
+  dum = mPar;  mPar(6)=0.5;   mPar(7)=dum(6);
+  dum = mStep; mStep(6)=0.05; mStep(7)=dum(6);
+  dum = mMin;  mMin(6)=0.;    mMin(7)=dum(6);
+  dum = mMax;  mMax(6)=10.;   mMax(7)=dum(6);
+  dum = mFix;  mFix(6)=1.1;   mFix(7)=dum(6);
+
+} else if(mFName[0]=='M' && mNVar==2) { //Moffat+fond en vol 2D
+  cout<<"PIAFitter::AutoIniFit : Auto Init type moffat_vol+fond 2D"<<endl;
+  Vector dum(mNPar);
+  dum = mPar;  mPar(6)=2.5;   mPar(7)=dum(6);
+  dum = mStep; mStep(6)=0.05; mStep(7)=dum(6);
+  dum = mMin;  mMin(6)=1.2;   mMin(7)=dum(6);
+  dum = mMax;  mMax(6)=10.;   mMax(7)=dum(6);
+  dum = mFix;  mFix(6)=1.1;   mFix(7)=dum(6);
+
+} else {
+  cout<<"PIAFitter::AutoIniFit : Fonction "<<mFName
+      <<", \n  pas d'init auto en dim "<<mNVar<<endl;
+  return;
+}
+
+return;
+}
+
+/* --Methode-- */
 void PIAFitter::InitParFromLastFit(void)
 // Initialisation du fit a partir des resultats du fit precedent
@@ -625,4 +685,5 @@
 if(mNPar==0) return;
 ReSetParam();
+if(mOpt.autoinifit)  AutoIniFit();
 if(mOpt.fromlastfit) InitParFromLastFit();
 Vector* v=NULL; string* s=NULL;
@@ -913,7 +974,7 @@
 
 // Alloc de la taille
-nlab = 14+npar;   lab = new PILabel*[nlab];    {for(int i=0;i<nlab;i++) lab[i]=NULL;}
+nlab = 13+npar;   lab = new PILabel*[nlab];    {for(int i=0;i<nlab;i++) lab[i]=NULL;}
 ntxt = 10+4*npar; txt = new PIText*[ntxt];     {for(int i=0;i<ntxt;i++) txt[i]=NULL;}
-nbut = 5;         but = new PIButton*[nbut];   {for(int i=0;i<nbut;i++) but[i]=NULL;}
+nbut = 6;         but = new PIButton*[nbut];   {for(int i=0;i<nbut;i++) but[i]=NULL;}
 nckb = 2+npar;    ckb = new PICheckBox*[nckb]; {for(int i=0;i<nckb;i++) ckb[i]=NULL;}
 npom = 3;         pom = new PIOptMenu*[npom];  {for(int i=0;i<npom;i++) pom[i]=NULL;}
@@ -933,5 +994,6 @@
 // new ligne
 cpx = spx; cpy = spy;
-string dum = "Object: "+mFitter->mNObj+" , Fun: "+mFitter->mFName;
+string dum = "Object: "+mFitter->mNObj+" , Fun: ";
+if(mFitter->mFitUserFunc) dum+=mFitter->mNameFitFunc; else dum+=mFitter->mFName;
 lab[0] = new PILabel(this,dum.c_str(),4*bsx,bsy,cpx,cpy);
 lab[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
@@ -1039,26 +1101,26 @@
 but[4]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 cpx += bsx+spx;
-lab[7] = new PILabel(this,mFitter->mFName.c_str(),2*bsx,bsy,cpx,cpy);
-lab[7]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
+but[5] = new PIButton(this, "Ini Auto",444,bsx,bsy,cpx,cpy);
+but[5]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 
 // new ligne
 cpx = spx; cpy += bsy+spy;
-lab[8] = new PILabel(this,"Par",bsx/2,bsy,cpx,cpy);
+lab[7] = new PILabel(this,"Par",bsx/2,bsy,cpx,cpy);
+lab[7]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
+cpx += int(bsx/2.+spx);
+lab[8] = new PILabel(this,"Fx",bsx/3,bsy,cpx,cpy);
 lab[8]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
-cpx += int(bsx/2.+spx);
-lab[9] = new PILabel(this,"Fx",bsx/3,bsy,cpx,cpy);
+cpx += int(bsx/3.+spx);
+lab[9] = new PILabel(this,"Init",bsx,bsy,cpx,cpy);
 lab[9]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
-cpx += int(bsx/3.+spx);
-lab[10] = new PILabel(this,"Init",bsx,bsy,cpx,cpy);
+cpx += bsx+spx;
+lab[10] = new PILabel(this,"Step",bsx,bsy,cpx,cpy);
 lab[10]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 cpx += bsx+spx;
-lab[11] = new PILabel(this,"Step",bsx,bsy,cpx,cpy);
+lab[11] = new PILabel(this,"Min",bsx,bsy,cpx,cpy);
 lab[11]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 cpx += bsx+spx;
-lab[12] = new PILabel(this,"Min",bsx,bsy,cpx,cpy);
+lab[12] = new PILabel(this,"Max",bsx,bsy,cpx,cpy);
 lab[12]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
-cpx += bsx+spx;
-lab[13] = new PILabel(this,"Max",bsx,bsy,cpx,cpy);
-lab[13]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 
 // new lines: Parametres (npar lignes)
@@ -1067,9 +1129,9 @@
     cpx = spx; cpy += bsy+spy;
     char str[8]; sprintf(str,"P%d",i);
-    lab[14+i] = new PILabel(this,str,bsx/2,bsy,cpx,cpy);
-    lab[14+i]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
+    lab[13+i] = new PILabel(this,str,bsx/2,bsy,cpx,cpy);
+    lab[13+i]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
     cpx += int(bsx/2.+spx);
     // Attention pas de message entre 1500 et 2000 (permet 500 parametres!)
-    ckb[2+i] = new PICheckBox(this,"",1500+i,bsx/3,bsy,cpx,cpy+bsy/2);
+    ckb[2+i] = new PICheckBox(this,"",1500+i,bsx/3,bsy,cpx,cpy+spy);
     ckb[2+i]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
     cpx+=int(bsx/3.+spx);
@@ -1251,4 +1313,8 @@
   if(rc>=0) mFitter->FitFunRes();
 }
+else if(msg ==444) {
+  if(lp) cout<<"Automatic initialisation"<<endl;
+  mFitter->AutoIniFit();
+}
 else if(msg==1001) {
   if(ckb[0]->GetState()) {
Index: trunk/SophyaPI/PIext/piafitting.h
===================================================================
--- trunk/SophyaPI/PIext/piafitting.h	(revision 389)
+++ trunk/SophyaPI/PIext/piafitting.h	(revision 390)
@@ -50,5 +50,5 @@
   int lp,lpg;
   int i1,i2,j1,j2;
-  bool fromlastfit;
+  bool fromlastfit,autoinifit;
 } DFOPTIONS ;
 
@@ -62,4 +62,5 @@
 void DecodeFunction(string func);
 void ReSetParam(void);
+void AutoIniFit(void);
 void InitParFromLastFit(void);
 void DecodeParam(string par,string step,string min,string max,string fix);
@@ -88,4 +89,5 @@
 GeneralFunction* mFunction; string mFName;
 // Gestion de fonction de fit definie par l'utilisateur
+bool mFitUserFunc;
 GeneralFunc* mFunc;
 PDynLinkMgr* mDlUFunc;
