Index: trunk/SophyaPI/PIext/cxxexecwin.cc
===================================================================
--- trunk/SophyaPI/PIext/cxxexecwin.cc	(revision 1268)
+++ trunk/SophyaPI/PIext/cxxexecwin.cc	(revision 1269)
@@ -2,9 +2,15 @@
 // Classe CxxExecOptWindow : Option Window for CxxExecutor
 // (c) DAPNIA (CEA)                 LAL (IN2P3/CNRS)
-//                           R. Ansari  10/2000
+//                           R. Ansari  C.Magneville 10/2000
 
 #include "cxxexecutor.h"
 #include "cxxexecwin.h"
 
+// --------------------------------------------------------------------
+// --------------------------------------------------------------------
+// ------------- Fenetre dde commande pour le CxxExecutor -------------
+// --------------------------------------------------------------------
+// --------------------------------------------------------------------
+
 /* --Methode-- */
 CxxExecWind::CxxExecWind(PIStdImgApp* par, CxxExecutor * cxxexec)
@@ -13,7 +19,15 @@
   dap = par;
   cxxex = cxxexec;
+  mFName[0] = "";
+  mFName[1] = "";
 
   int bsx, bsy, szx, szy;
   int px, py, spx, spy;
+  int xtext, ytext;
+
+  ////////////////////////////////////
+  //       Window Definition        //
+  ////////////////////////////////////
+
   // On definit la taille a partir de la taille par defaut des composantes 
   PIApplicationPrefCompSize(bsx, bsy);
@@ -21,45 +35,101 @@
   spx = bsx/6;
   spy = bsy/6;
-  szx = 8*bsx+2*spx;   
-  szy = 10*bsy+8*spy;
+  xtext = 8*bsx;
+  ytext = 8*bsy;
+  szx = xtext+2*spx;   
+  szy = 2*ytext+5*bsy+10*spy;
   SetSize(szx, szy);
 
-// Creation de champs "labels"
-  px = (szx-6*bsx)/2;
-  py = 2*spy;
-  mLab = new PILabel(this, "File", bsx*6, bsy, bsx, py);
-  mLab->SetLabel("No File Name");
-  mLab->SetBorderWidth(1);
-  mLab->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
-  
-  px = spx;
-  py = 4*spy+bsy;
+  ////////////////////////////////////
+  //       User Function Code       //
+  ////////////////////////////////////
 
 // Creation du champ texte 
-  mText = new PIText(this, "helptext", true, true, bsx*8, 8*bsy, px, py);
-// mText->SetMutiLineMode(true);
-  mText->SetTextEditable(true);
-  mText->SetText("");
-  mText->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
-
-// Creation de bouton d'action 
-
-  py += 2*spy+8*bsy;
-  px = (szx-6*bsx-8*spx)/2;
-  mBut[0] = new PIButton(this, "Exec",  400, bsx*1.2, bsy, px, py);
-  px += 1.2*bsx+2*spx;
-  mBut[1] = new PIButton(this, "Open",  500, bsx*1.2, bsy, px, py);
-  px += 1.2*bsx+2*spx;
-  mBut[2] = new PIButton(this, "Save",  600, bsx*1.2, bsy, px, py);
-  px += 1.2*bsx+2*spx;
-  mBut[3] = new PIButton(this, "Save As",  660, bsx*1.2, bsy, px, py);
-  px += 1.2*bsx+2*spx;
-  mBut[4] = new PIButton(this, "Dismiss",  700, bsx*1.2, bsy, px, py);
-
-//  Taille et position proportionnelles a la taille de la fenetre pour les elements
+  px = spx;
+  py = spy;
+  mText[0] = new PIText(this,"helptext",true,true,xtext,0.75*ytext,px,py);
+  mText[0]->SetTextEditable(true);
+  mText[0]->SetText("");
+
+// Creation du champ titre, des boutons d'action et label fichier
+  px = spx;
+  py += (int)(spy+0.75*ytext);
+  mLab[3] = new PILabel(this,"FileFunc",xtext,bsy,px,py);
+  mLab[3]->SetLabel("");
+  mLab[3]->SetBorderWidth(1);
+  px = spx;
+  py += spy+bsy;
+  mLab[0] = new PILabel(this,"Function",2*bsx,bsy,px,py);
+  mLab[0]->SetLabel("User Function Code");
+  mLab[0]->SetBorderWidth(1);
+  px += spx+2*bsx;
+  mBut[0] = new PIButton(this,"Open",500,bsx,bsy,px,py);
+  px += bsx+spx;
+  mBut[1] = new PIButton(this,"Save",510,bsx,bsy,px,py);
+  px += bsx+spx;
+  mBut[2] = new PIButton(this,"Save As",520,bsx,bsy,px,py);
+  px += bsx+spx;
+  mBut[3] = new PIButton(this,"Reset Name",530,1.5*bsx,bsy,px,py);
+
+  ////////////////////////////////////
+  //           User Code            //
+  ////////////////////////////////////
+
+// Creation du champ texte 
+  px = spx;
+  py += 2*spy+bsy;
+  mText[1] = new PIText(this,"helptext",true,true,xtext,1.25*ytext,px,py);
+  mText[1]->SetTextEditable(true);
+  mText[1]->SetText("");
+
+// Creation du champ titre, des boutons d'action et label fichier
+  px = spx;
+  py += (int)(spy+1.25*ytext);
+  mLab[4] = new PILabel(this,"FileCode",xtext,bsy,px,py);
+  mLab[4]->SetLabel("");
+  mLab[4]->SetBorderWidth(1);
+  px = spx;
+  py += spy+bsy;
+  mLab[1] = new PILabel(this,"Code",2*bsx,bsy,px,py);
+  mLab[1]->SetLabel("User Code");
+  mLab[1]->SetBorderWidth(1);
+  px += spx+2*bsx;
+  mBut[4] = new PIButton(this,"Open",501,bsx,bsy,px,py);
+  px += bsx+spx;
+  mBut[5] = new PIButton(this,"Save",511,bsx,bsy,px,py);
+  px += bsx+spx;
+  mBut[6] = new PIButton(this,"Save As",521,bsx,bsy,px,py);
+  px += bsx+spx;
+  mBut[7] = new PIButton(this,"Reset Name",531,1.5*bsx,bsy,px,py);
+
+  ////////////////////////////////////
+  //     Buttons for execution      //
+  ////////////////////////////////////
+
+// Creation du champ titre pour le code
+  px = spx;
+  py += 2*spy+bsy;
+  mLab[2] = new PILabel(this, "Execute",2*bsx,bsy,px,py);
+  mLab[2]->SetLabel("Execute :");
+  mLab[2]->SetBorderWidth(1);
+
+// Creation des boutons d'action 
+  px += (int)(szx/2 - 1.2*bsx - spx);
+  mBut[8] = new PIButton(this,"Exec",600,1.2*bsx,bsy,px,py);
+  px += (int)(1.2*bsx+spx);
+  mBut[9] = new PIButton(this,"Dismiss",601,1.2*bsx,bsy,px,py);
+
+  ////////////////////////////////////
+  //  Set Attributes for Elements   //
+  ////////////////////////////////////
+
   for(int ii=0; ii<5; ii++) 
+    mLab[ii]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
+  for(int ii=0; ii<10; ii++) 
     mBut[ii]->SetBinding(PIBK_elastic , PIBK_elastic , PIBK_elastic , PIBK_elastic);
-
-  // Notre File Chooser
+  for(int ii=0; ii<2; ii++) 
+    mText[ii]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
+
+  // File Chooser
   pfc = new PIFileChooser(this,"CxxExec-FileChooser", 5000); 
 }
@@ -68,16 +138,16 @@
 CxxExecWind::~CxxExecWind()
 {
-  delete mLab;
-  delete mText;
-  for(int i=0; i<5; i++)   delete mBut[i];
+  for(int i=0; i<5; i++)  delete mLab[i];
+  for(int i=0; i<10; i++) delete mBut[i];
+  for(int i=0; i<2; i++)  delete mText[i];
   delete pfc;
 }
 
-
 /* --Methode-- */
 void CxxExecWind::Show()
 {
-  mLab->SetLabel(flnm);
-  PIWindow::Show();
+mLab[3]->SetLabel(mFName[0]);
+mLab[4]->SetLabel(mFName[1]);
+PIWindow::Show();
 }
 
@@ -85,77 +155,115 @@
 void CxxExecWind::Process(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
 {
-
-  switch (UserMsg(msg))  {
-
-    case 400:    // Bouton Execute C++
-      {
+  msg = UserMsg(msg);
+  switch (msg)  {
+    case 600:    // Bouton Execute C++
       dap->SetBusy();
-      mBut[0]->SetUnSensitive();
-      string localkey = "c++exec";
-      vector<string> localtokens;
-      string localstr = mText->GetText();
-      localtokens.push_back(localstr);
-      cxxex->Execute(localkey,localtokens,localstr);
-      mBut[0]->SetSensitive();
+      mBut[8]->SetUnSensitive();
+      cxxex->ExecuteCXX(mText[1]->GetText(),mText[0]->GetText());
+      mBut[8]->SetSensitive();
       dap->SetReady();
       break;
-      }
-
-    case 500:    // Open File
+    case 601:   // Bouton Dismiss - On cache la fenetre
+      this->Hide();
+      break;
+    case 500:    // Open File for Function
+    case 501:    // Open File for Code
+      {
+      int i = msg-500;
       pfc->AcceptNewFile(false); 
-      pfc->SetMsg(5500);
+      pfc->SetMsg(5500+i);
       dap->SetBlocked();
       pfc->Show();
       break;
-    
-    case 5500:  // Return from open-file dialog
+      }
+    case 5500:  // Return from open-file dialog for Function
+    case 5501:  // Return from open-file dialog for Code
+      {
+      int i = msg-5500;
+      dap->SetBusy();
+      if(data) {
+	mFName[i] = pfc->GetFileName();
+	mLab[3+i]->SetLabel(mFName[i]);
+        string code = stringfrfile(mFName[i]);
+	mText[i]->SetText(code);
+      }
+      dap->SetReady();
+      break;
+      }
+    case 510:  // Save for Function
+    case 511:  // Save for Code
+    case 520:  // Save-File for Function
+    case 521:  // Save-File for Code
+      {
+      int i = msg%10;
+      if( msg<515 && mFName[i].length()>0 ) {
+        string code = mText[i]->GetText();
+        filefrstring(mFName[i],code);
+      } else {
+	pfc->AcceptNewFile(true); 
+	pfc->SetMsg(5520+i);
+	dap->SetBlocked();
+	pfc->Show();	
+      }
+      break;
+      }
+    case 5520:  // Return from Save-file dialog for Function
+    case 5521:  // Return from Save-file dialog for Code
+      {
+      int i = msg-5520;
       dap->SetBusy();
       if (data) {
-	flnm = pfc->GetFileName();
-	mLab->SetLabel(flnm);
-	// We have to read the file 
-	mText->SetText("REZA A FAIRE \n Fichier non lu !");
+	mFName[i] = pfc->GetFileName();
+	mLab[3+i]->SetLabel(mFName[i]);
+        string code = mText[i]->GetText();
+        filefrstring(mFName[i],code);
       }
       dap->SetReady();
       break;
-
-    case 600:
-    case 660:
-      if ( (UserMsg(msg) == 600) && (flnm.length() > 0) ) {
-	cerr << " REZA A FAIRE ! Il faut sauver le champ texte ds fichier "
-	     << flnm << endl;
-      }
-      else {
-	pfc->AcceptNewFile(true); 
-	pfc->SetMsg(5600);
-	dap->SetBlocked();
-	pfc->Show();	
-      }
-      break;
-
-    case 5600:  // Return from Save-file dialog
-      dap->SetBusy();
-      if (data) {
-	flnm = pfc->GetFileName();
-	mLab->SetLabel(flnm);
-	// We have to save to the file 
-	cerr << " REZA A FAIRE ! Il faut sauver le champ texte ds fichier (2)"
-	     << flnm << endl;
-      }
-      dap->SetReady();
-      break;
-
-    case 700:   // Bouton Dismiss - On cache la fenetre
-      this->Hide();
-      break;
+      }
+    case 530:  // Reset name for Function
+    case 531:  // Reset name for Code
+      {
+      int i = msg-530;
+      mFName[i] = "";
+      mLab[3+i]->SetLabel(mFName[i]);
+      }
   }
 
   // In case of compile errors, we end-up here !    
-  mBut[0]->SetSensitive();
+  mBut[8]->SetSensitive();
   dap->SetReady();
   return;
 }
 
-// --------------------------------------------------------------------
+/* --Methode-- */
+void CxxExecWind::filefrstring(string filename,string& code)
+{
+if(filename.size()<1) return;
+if(code.size()<1) return;
+ofstream os(filename.c_str(),ios::out);
+if(!os)
+  {cout<<"CxxExecWind::filefrstring: unable to open "<<filename<<endl;
+   return;}
+os<<code<<endl;
+}
+
+/* --Methode-- */
+string CxxExecWind::stringfrfile(string filename)
+{
+string code = "";
+if(filename.size()<1) return code;
+ifstream is(filename.c_str(),ios::in);
+if(!is)
+  {cout<<"CxxExecWind::stringfrfile: unable to open "<<filename<<endl;
+   return code;}
+char c;
+while(is.get(c)) code += c;
+return code;
+}
+
+// --------------------------------------------------------------------
+// --------------------------------------------------------------------
+// --------------- Fenetre d'option pour le CxxExecutor ---------------
 // --------------------------------------------------------------------
 // --------------------------------------------------------------------
@@ -171,66 +279,68 @@
   int bsx, bsy, szx, szy;
   int px, py, spx, spy;
+  int xtext;
   // On definit la taille a partir de la taille par defaut des composantes 
   PIApplicationPrefCompSize(bsx, bsy);
   // On redefinit la taille de la fenetre
-  spx = bsx/6;
+  spx = bsx/12; if(spx<2) spx=2;
   spy = bsy/6;
-  szx = 7*bsx+5*spx;   
-  szy = 6*bsy+12*spy;
+  xtext = 7*bsx;
+  szx = (int)(xtext+1.5*bsx+3*spx);
+  szy = 6*bsy+7*spy;
   SetSize(szx, szy);
 
 // Creation de champs "labels"
-  px = (szx-6*bsx)/2;
-  py = 2*spy;
-  mTit = new PILabel(this, "CxxExecutor Options", bsx*6, bsy, bsx, py);
+  px = (szx-xtext)/2;
+  py = spy;
+  mTit = new PILabel(this,"CxxExecutor Options",xtext,bsy,px,py);
   mTit->SetBorderWidth(1);
-  
-  px = 2*spx;
-  py = 4*spy+bsy;
-  mLab[0] = new PILabel(this, "Include Files", bsx*2, bsy, px, py);
-  py += spy+bsy;
-  mLab[1] = new PILabel(this, "Compile Options", bsx*2, bsy, px, py);
-  py += spy+bsy;
-  mLab[2] = new PILabel(this, "Link Options", bsx*2, bsy, px, py);
-  py += spy+bsy;
-  mLab[3] = new PILabel(this, "Libraries", bsx*2, bsy, px, py);
-
-  px = 3*spx+2*bsx;
-  py = 4*spy+bsy;
-
-// Creation de champs textes 
-  mText[0] = new PIText(this, "IncFiles", bsx*5, bsy, px, py);
+
+// Creation des labels et des champs texte
+  px = spx;
+  py += spy+bsy;
+  mLab[0] = new PILabel(this,"Include Files",1.5*bsx,bsy,px,py);
+  px += (int)(1.5*bsx+spx);
+  mText[0] = new PIText(this,"IncFiles",xtext,bsy,px,py);
   mText[0]->SetText("");
-  py += spy+bsy;
-  mText[1] = new PIText(this, "CompOpt", bsx*5, bsy, px, py);
+
+  px = spx;
+  py += spy+bsy;
+  mLab[1] = new PILabel(this,"Compile Opt.",1.5*bsx,bsy,px,py);
+  px += (int)(1.5*bsx+spx);
+  mText[1] = new PIText(this,"CompOpt",xtext,bsy,px,py);
   mText[1]->SetText("");
-  py += spy+bsy;
-  mText[2] = new PIText(this, "LinkOpt", bsx*5, bsy, px, py);
+
+  px = spx;
+  py += spy+bsy;
+  mLab[2] = new PILabel(this,"Link Options",1.5*bsx,bsy,px,py);
+  px += (int)(1.5*bsx+spx);
+  mText[2] = new PIText(this,"LinkOpt",xtext,bsy,px,py);
   mText[2]->SetText("");
-  py += spy+bsy;
-  mText[3] = new PIText(this, "LinkLib", bsx*5, bsy, px, py);
+
+  px = spx;
+  py += spy+bsy;
+  mLab[3] = new PILabel(this,"Libraries",1.5*bsx,bsy,px,py);
+  px += (int)(1.5*bsx+spx);
+  mText[3] = new PIText(this,"LinkLib",xtext,bsy,px,py);
   mText[3]->SetText("");
 
 // Creation de bouton d'action 
 
-  py += 3*spy+bsy;
-  px = (szx-6*bsx-6*spx)/2;
-  mBut[0] = new PIButton(this, "Set Options",  500, bsx*2, bsy, px, py);
-  px += 2*bsx+2*spx;
-  mBut[1] = new PIButton(this, "Get Option",  600, bsx*2, bsy, px, py);
-  px += 2*bsx+2*spx;
-  mBut[2] = new PIButton(this, "Dismiss",  700, bsx*2, bsy, px, py);
+  px = (int)(szx/2 - 1.5*bsx - spx - 1.5*bsx/2.);
+  py += spy+bsy;
+  mBut[0] = new PIButton(this,"Set Options",500,1.5*bsx,bsy,px,py);
+  px += (int)(1.5*bsx+spx);
+  mBut[1] = new PIButton(this,"Get Options",600,1.5*bsx,bsy,px,py);
+  px += (int)(1.5*bsx+spx);
+  mBut[2] = new PIButton(this,"Dismiss",700,1.5*bsx, bsy,px,py);
 
 //  Taille et position proportionnelles a la taille de la fenetre pour les elements
   mTit->SetBinding(PIBK_elastic , PIBK_elastic , PIBK_elastic , PIBK_elastic);
-
-  for(int i=0; i<4; i++) {
+  for(int i=0; i<4; i++)
     mLab[i]->SetBinding(PIBK_elastic , PIBK_elastic , PIBK_elastic , PIBK_elastic);
-
+  for(int i=0; i<4; i++)
     mText[i]->SetBinding(PIBK_elastic , PIBK_elastic , PIBK_elastic , PIBK_elastic);
-  }
-  for(int ii=0; ii<3; ii++) 
-    mBut[ii]->SetBinding(PIBK_elastic , PIBK_elastic , PIBK_elastic , PIBK_elastic);
-
+  for(int i=0; i<3; i++) 
+    mBut[i]->SetBinding(PIBK_elastic , PIBK_elastic , PIBK_elastic , PIBK_elastic);
 }
 
@@ -238,14 +348,9 @@
 CxxOptionWind::~CxxOptionWind()
 {
-  for(int i=0; i<4; i++) {
-    delete mLab[i];
-    delete mText[i];
-  }
   delete mTit;
-  delete mBut[0]; 
-  delete mBut[1]; 
-  delete mBut[2]; 
-}
-
+  for(int i=0; i<4; i++) delete mLab[i];
+  for(int i=0; i<3; i++) delete mBut[i];
+  for(int i=0; i<4; i++) delete mText[i];
+}
 
 /* --Methode-- */
@@ -255,5 +360,5 @@
   mText[1]->SetText(cxxex->GetCompileOpt());
   mText[2]->SetText(cxxex->GetLinkOpt());
-  mText[2]->SetText(cxxex->GetLinkLibs());
+  mText[3]->SetText(cxxex->GetLinkLibs());
   PIWindow::Show();
 }
@@ -262,11 +367,7 @@
 void CxxOptionWind::Process(PIMessage msg, PIMsgHandler* /*sender*/, void* /*data*/)
 {
-
   string opt;
- 
   switch (UserMsg(msg))  {
-
     case 500:    // Bouton Set Options
-// On recupere les textes des 3 champs :
       opt = mText[0]->GetText();
       cxxex->FillInclude(opt);
@@ -278,19 +379,14 @@
       cxxex->FillLinkLibs(opt);
       break;
-
     case 600:    // Bouton Get Options
       mText[0]->SetText(cxxex->GetInclude());
       mText[1]->SetText(cxxex->GetCompileOpt());
       mText[2]->SetText(cxxex->GetLinkOpt());
-      mText[2]->SetText(cxxex->GetLinkLibs());
-      break;
-
+      mText[3]->SetText(cxxex->GetLinkLibs());
+      break;
     case 700:   // Bouton Dismiss - On cache la fenetre
       this->Hide();
       break;
   }
-    
 return;
 }
-
-
