Changeset 1269 in Sophya for trunk/SophyaPI/PIext/cxxexecwin.cc


Ignore:
Timestamp:
Nov 1, 2000, 6:30:27 PM (25 years ago)
Author:
ercodmgr
Message:

Retour de ExecuteCXX pour CxxExecWind
Finalisation de CxxExecWind cmv 1/11/00

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PIext/cxxexecwin.cc

    r1268 r1269  
    22// Classe CxxExecOptWindow : Option Window for CxxExecutor
    33// (c) DAPNIA (CEA)                 LAL (IN2P3/CNRS)
    4 //                           R. Ansari  10/2000
     4//                           R. Ansari  C.Magneville 10/2000
    55
    66#include "cxxexecutor.h"
    77#include "cxxexecwin.h"
    88
     9// --------------------------------------------------------------------
     10// --------------------------------------------------------------------
     11// ------------- Fenetre dde commande pour le CxxExecutor -------------
     12// --------------------------------------------------------------------
     13// --------------------------------------------------------------------
     14
    915/* --Methode-- */
    1016CxxExecWind::CxxExecWind(PIStdImgApp* par, CxxExecutor * cxxexec)
     
    1319  dap = par;
    1420  cxxex = cxxexec;
     21  mFName[0] = "";
     22  mFName[1] = "";
    1523
    1624  int bsx, bsy, szx, szy;
    1725  int px, py, spx, spy;
     26  int xtext, ytext;
     27
     28  ////////////////////////////////////
     29  //       Window Definition        //
     30  ////////////////////////////////////
     31
    1832  // On definit la taille a partir de la taille par defaut des composantes
    1933  PIApplicationPrefCompSize(bsx, bsy);
     
    2135  spx = bsx/6;
    2236  spy = bsy/6;
    23   szx = 8*bsx+2*spx;   
    24   szy = 10*bsy+8*spy;
     37  xtext = 8*bsx;
     38  ytext = 8*bsy;
     39  szx = xtext+2*spx;   
     40  szy = 2*ytext+5*bsy+10*spy;
    2541  SetSize(szx, szy);
    2642
    27 // Creation de champs "labels"
    28   px = (szx-6*bsx)/2;
    29   py = 2*spy;
    30   mLab = new PILabel(this, "File", bsx*6, bsy, bsx, py);
    31   mLab->SetLabel("No File Name");
    32   mLab->SetBorderWidth(1);
    33   mLab->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
    34  
    35   px = spx;
    36   py = 4*spy+bsy;
     43  ////////////////////////////////////
     44  //       User Function Code       //
     45  ////////////////////////////////////
    3746
    3847// Creation du champ texte
    39   mText = new PIText(this, "helptext", true, true, bsx*8, 8*bsy, px, py);
    40 // mText->SetMutiLineMode(true);
    41   mText->SetTextEditable(true);
    42   mText->SetText("");
    43   mText->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
    44 
    45 // Creation de bouton d'action
    46 
    47   py += 2*spy+8*bsy;
    48   px = (szx-6*bsx-8*spx)/2;
    49   mBut[0] = new PIButton(this, "Exec",  400, bsx*1.2, bsy, px, py);
    50   px += 1.2*bsx+2*spx;
    51   mBut[1] = new PIButton(this, "Open",  500, bsx*1.2, bsy, px, py);
    52   px += 1.2*bsx+2*spx;
    53   mBut[2] = new PIButton(this, "Save",  600, bsx*1.2, bsy, px, py);
    54   px += 1.2*bsx+2*spx;
    55   mBut[3] = new PIButton(this, "Save As",  660, bsx*1.2, bsy, px, py);
    56   px += 1.2*bsx+2*spx;
    57   mBut[4] = new PIButton(this, "Dismiss",  700, bsx*1.2, bsy, px, py);
    58 
    59 //  Taille et position proportionnelles a la taille de la fenetre pour les elements
     48  px = spx;
     49  py = spy;
     50  mText[0] = new PIText(this,"helptext",true,true,xtext,0.75*ytext,px,py);
     51  mText[0]->SetTextEditable(true);
     52  mText[0]->SetText("");
     53
     54// Creation du champ titre, des boutons d'action et label fichier
     55  px = spx;
     56  py += (int)(spy+0.75*ytext);
     57  mLab[3] = new PILabel(this,"FileFunc",xtext,bsy,px,py);
     58  mLab[3]->SetLabel("");
     59  mLab[3]->SetBorderWidth(1);
     60  px = spx;
     61  py += spy+bsy;
     62  mLab[0] = new PILabel(this,"Function",2*bsx,bsy,px,py);
     63  mLab[0]->SetLabel("User Function Code");
     64  mLab[0]->SetBorderWidth(1);
     65  px += spx+2*bsx;
     66  mBut[0] = new PIButton(this,"Open",500,bsx,bsy,px,py);
     67  px += bsx+spx;
     68  mBut[1] = new PIButton(this,"Save",510,bsx,bsy,px,py);
     69  px += bsx+spx;
     70  mBut[2] = new PIButton(this,"Save As",520,bsx,bsy,px,py);
     71  px += bsx+spx;
     72  mBut[3] = new PIButton(this,"Reset Name",530,1.5*bsx,bsy,px,py);
     73
     74  ////////////////////////////////////
     75  //           User Code            //
     76  ////////////////////////////////////
     77
     78// Creation du champ texte
     79  px = spx;
     80  py += 2*spy+bsy;
     81  mText[1] = new PIText(this,"helptext",true,true,xtext,1.25*ytext,px,py);
     82  mText[1]->SetTextEditable(true);
     83  mText[1]->SetText("");
     84
     85// Creation du champ titre, des boutons d'action et label fichier
     86  px = spx;
     87  py += (int)(spy+1.25*ytext);
     88  mLab[4] = new PILabel(this,"FileCode",xtext,bsy,px,py);
     89  mLab[4]->SetLabel("");
     90  mLab[4]->SetBorderWidth(1);
     91  px = spx;
     92  py += spy+bsy;
     93  mLab[1] = new PILabel(this,"Code",2*bsx,bsy,px,py);
     94  mLab[1]->SetLabel("User Code");
     95  mLab[1]->SetBorderWidth(1);
     96  px += spx+2*bsx;
     97  mBut[4] = new PIButton(this,"Open",501,bsx,bsy,px,py);
     98  px += bsx+spx;
     99  mBut[5] = new PIButton(this,"Save",511,bsx,bsy,px,py);
     100  px += bsx+spx;
     101  mBut[6] = new PIButton(this,"Save As",521,bsx,bsy,px,py);
     102  px += bsx+spx;
     103  mBut[7] = new PIButton(this,"Reset Name",531,1.5*bsx,bsy,px,py);
     104
     105  ////////////////////////////////////
     106  //     Buttons for execution      //
     107  ////////////////////////////////////
     108
     109// Creation du champ titre pour le code
     110  px = spx;
     111  py += 2*spy+bsy;
     112  mLab[2] = new PILabel(this, "Execute",2*bsx,bsy,px,py);
     113  mLab[2]->SetLabel("Execute :");
     114  mLab[2]->SetBorderWidth(1);
     115
     116// Creation des boutons d'action
     117  px += (int)(szx/2 - 1.2*bsx - spx);
     118  mBut[8] = new PIButton(this,"Exec",600,1.2*bsx,bsy,px,py);
     119  px += (int)(1.2*bsx+spx);
     120  mBut[9] = new PIButton(this,"Dismiss",601,1.2*bsx,bsy,px,py);
     121
     122  ////////////////////////////////////
     123  //  Set Attributes for Elements   //
     124  ////////////////////////////////////
     125
    60126  for(int ii=0; ii<5; ii++)
     127    mLab[ii]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
     128  for(int ii=0; ii<10; ii++)
    61129    mBut[ii]->SetBinding(PIBK_elastic , PIBK_elastic , PIBK_elastic , PIBK_elastic);
    62 
    63   // Notre File Chooser
     130  for(int ii=0; ii<2; ii++)
     131    mText[ii]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
     132
     133  // File Chooser
    64134  pfc = new PIFileChooser(this,"CxxExec-FileChooser", 5000);
    65135}
     
    68138CxxExecWind::~CxxExecWind()
    69139{
    70   delete mLab;
    71   delete mText;
    72   for(int i=0; i<5; i++)   delete mBut[i];
     140  for(int i=0; i<5; i++)  delete mLab[i];
     141  for(int i=0; i<10; i++) delete mBut[i];
     142  for(int i=0; i<2; i++)  delete mText[i];
    73143  delete pfc;
    74144}
    75145
    76 
    77146/* --Methode-- */
    78147void CxxExecWind::Show()
    79148{
    80   mLab->SetLabel(flnm);
    81   PIWindow::Show();
     149mLab[3]->SetLabel(mFName[0]);
     150mLab[4]->SetLabel(mFName[1]);
     151PIWindow::Show();
    82152}
    83153
     
    85155void CxxExecWind::Process(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
    86156{
    87 
    88   switch (UserMsg(msg))  {
    89 
    90     case 400:    // Bouton Execute C++
    91       {
     157  msg = UserMsg(msg);
     158  switch (msg)  {
     159    case 600:    // Bouton Execute C++
    92160      dap->SetBusy();
    93       mBut[0]->SetUnSensitive();
    94       string localkey = "c++exec";
    95       vector<string> localtokens;
    96       string localstr = mText->GetText();
    97       localtokens.push_back(localstr);
    98       cxxex->Execute(localkey,localtokens,localstr);
    99       mBut[0]->SetSensitive();
     161      mBut[8]->SetUnSensitive();
     162      cxxex->ExecuteCXX(mText[1]->GetText(),mText[0]->GetText());
     163      mBut[8]->SetSensitive();
    100164      dap->SetReady();
    101165      break;
    102       }
    103 
    104     case 500:    // Open File
     166    case 601:   // Bouton Dismiss - On cache la fenetre
     167      this->Hide();
     168      break;
     169    case 500:    // Open File for Function
     170    case 501:    // Open File for Code
     171      {
     172      int i = msg-500;
    105173      pfc->AcceptNewFile(false);
    106       pfc->SetMsg(5500);
     174      pfc->SetMsg(5500+i);
    107175      dap->SetBlocked();
    108176      pfc->Show();
    109177      break;
    110    
    111     case 5500:  // Return from open-file dialog
     178      }
     179    case 5500:  // Return from open-file dialog for Function
     180    case 5501:  // Return from open-file dialog for Code
     181      {
     182      int i = msg-5500;
     183      dap->SetBusy();
     184      if(data) {
     185        mFName[i] = pfc->GetFileName();
     186        mLab[3+i]->SetLabel(mFName[i]);
     187        string code = stringfrfile(mFName[i]);
     188        mText[i]->SetText(code);
     189      }
     190      dap->SetReady();
     191      break;
     192      }
     193    case 510:  // Save for Function
     194    case 511:  // Save for Code
     195    case 520:  // Save-File for Function
     196    case 521:  // Save-File for Code
     197      {
     198      int i = msg%10;
     199      if( msg<515 && mFName[i].length()>0 ) {
     200        string code = mText[i]->GetText();
     201        filefrstring(mFName[i],code);
     202      } else {
     203        pfc->AcceptNewFile(true);
     204        pfc->SetMsg(5520+i);
     205        dap->SetBlocked();
     206        pfc->Show();   
     207      }
     208      break;
     209      }
     210    case 5520:  // Return from Save-file dialog for Function
     211    case 5521:  // Return from Save-file dialog for Code
     212      {
     213      int i = msg-5520;
    112214      dap->SetBusy();
    113215      if (data) {
    114         flnm = pfc->GetFileName();
    115         mLab->SetLabel(flnm);
    116         // We have to read the file
    117         mText->SetText("REZA A FAIRE \n Fichier non lu !");
     216        mFName[i] = pfc->GetFileName();
     217        mLab[3+i]->SetLabel(mFName[i]);
     218        string code = mText[i]->GetText();
     219        filefrstring(mFName[i],code);
    118220      }
    119221      dap->SetReady();
    120222      break;
    121 
    122     case 600:
    123     case 660:
    124       if ( (UserMsg(msg) == 600) && (flnm.length() > 0) ) {
    125         cerr << " REZA A FAIRE ! Il faut sauver le champ texte ds fichier "
    126              << flnm << endl;
    127       }
    128       else {
    129         pfc->AcceptNewFile(true);
    130         pfc->SetMsg(5600);
    131         dap->SetBlocked();
    132         pfc->Show();   
    133       }
    134       break;
    135 
    136     case 5600:  // Return from Save-file dialog
    137       dap->SetBusy();
    138       if (data) {
    139         flnm = pfc->GetFileName();
    140         mLab->SetLabel(flnm);
    141         // We have to save to the file
    142         cerr << " REZA A FAIRE ! Il faut sauver le champ texte ds fichier (2)"
    143              << flnm << endl;
    144       }
    145       dap->SetReady();
    146       break;
    147 
    148     case 700:   // Bouton Dismiss - On cache la fenetre
    149       this->Hide();
    150       break;
     223      }
     224    case 530:  // Reset name for Function
     225    case 531:  // Reset name for Code
     226      {
     227      int i = msg-530;
     228      mFName[i] = "";
     229      mLab[3+i]->SetLabel(mFName[i]);
     230      }
    151231  }
    152232
    153233  // In case of compile errors, we end-up here !   
    154   mBut[0]->SetSensitive();
     234  mBut[8]->SetSensitive();
    155235  dap->SetReady();
    156236  return;
    157237}
    158238
    159 // --------------------------------------------------------------------
     239/* --Methode-- */
     240void CxxExecWind::filefrstring(string filename,string& code)
     241{
     242if(filename.size()<1) return;
     243if(code.size()<1) return;
     244ofstream os(filename.c_str(),ios::out);
     245if(!os)
     246  {cout<<"CxxExecWind::filefrstring: unable to open "<<filename<<endl;
     247   return;}
     248os<<code<<endl;
     249}
     250
     251/* --Methode-- */
     252string CxxExecWind::stringfrfile(string filename)
     253{
     254string code = "";
     255if(filename.size()<1) return code;
     256ifstream is(filename.c_str(),ios::in);
     257if(!is)
     258  {cout<<"CxxExecWind::stringfrfile: unable to open "<<filename<<endl;
     259   return code;}
     260char c;
     261while(is.get(c)) code += c;
     262return code;
     263}
     264
     265// --------------------------------------------------------------------
     266// --------------------------------------------------------------------
     267// --------------- Fenetre d'option pour le CxxExecutor ---------------
    160268// --------------------------------------------------------------------
    161269// --------------------------------------------------------------------
     
    171279  int bsx, bsy, szx, szy;
    172280  int px, py, spx, spy;
     281  int xtext;
    173282  // On definit la taille a partir de la taille par defaut des composantes
    174283  PIApplicationPrefCompSize(bsx, bsy);
    175284  // On redefinit la taille de la fenetre
    176   spx = bsx/6;
     285  spx = bsx/12; if(spx<2) spx=2;
    177286  spy = bsy/6;
    178   szx = 7*bsx+5*spx;   
    179   szy = 6*bsy+12*spy;
     287  xtext = 7*bsx;
     288  szx = (int)(xtext+1.5*bsx+3*spx);
     289  szy = 6*bsy+7*spy;
    180290  SetSize(szx, szy);
    181291
    182292// Creation de champs "labels"
    183   px = (szx-6*bsx)/2;
    184   py = 2*spy;
    185   mTit = new PILabel(this, "CxxExecutor Options", bsx*6, bsy, bsx, py);
     293  px = (szx-xtext)/2;
     294  py = spy;
     295  mTit = new PILabel(this,"CxxExecutor Options",xtext,bsy,px,py);
    186296  mTit->SetBorderWidth(1);
    187  
    188   px = 2*spx;
    189   py = 4*spy+bsy;
    190   mLab[0] = new PILabel(this, "Include Files", bsx*2, bsy, px, py);
    191   py += spy+bsy;
    192   mLab[1] = new PILabel(this, "Compile Options", bsx*2, bsy, px, py);
    193   py += spy+bsy;
    194   mLab[2] = new PILabel(this, "Link Options", bsx*2, bsy, px, py);
    195   py += spy+bsy;
    196   mLab[3] = new PILabel(this, "Libraries", bsx*2, bsy, px, py);
    197 
    198   px = 3*spx+2*bsx;
    199   py = 4*spy+bsy;
    200 
    201 // Creation de champs textes
    202   mText[0] = new PIText(this, "IncFiles", bsx*5, bsy, px, py);
     297
     298// Creation des labels et des champs texte
     299  px = spx;
     300  py += spy+bsy;
     301  mLab[0] = new PILabel(this,"Include Files",1.5*bsx,bsy,px,py);
     302  px += (int)(1.5*bsx+spx);
     303  mText[0] = new PIText(this,"IncFiles",xtext,bsy,px,py);
    203304  mText[0]->SetText("");
    204   py += spy+bsy;
    205   mText[1] = new PIText(this, "CompOpt", bsx*5, bsy, px, py);
     305
     306  px = spx;
     307  py += spy+bsy;
     308  mLab[1] = new PILabel(this,"Compile Opt.",1.5*bsx,bsy,px,py);
     309  px += (int)(1.5*bsx+spx);
     310  mText[1] = new PIText(this,"CompOpt",xtext,bsy,px,py);
    206311  mText[1]->SetText("");
    207   py += spy+bsy;
    208   mText[2] = new PIText(this, "LinkOpt", bsx*5, bsy, px, py);
     312
     313  px = spx;
     314  py += spy+bsy;
     315  mLab[2] = new PILabel(this,"Link Options",1.5*bsx,bsy,px,py);
     316  px += (int)(1.5*bsx+spx);
     317  mText[2] = new PIText(this,"LinkOpt",xtext,bsy,px,py);
    209318  mText[2]->SetText("");
    210   py += spy+bsy;
    211   mText[3] = new PIText(this, "LinkLib", bsx*5, bsy, px, py);
     319
     320  px = spx;
     321  py += spy+bsy;
     322  mLab[3] = new PILabel(this,"Libraries",1.5*bsx,bsy,px,py);
     323  px += (int)(1.5*bsx+spx);
     324  mText[3] = new PIText(this,"LinkLib",xtext,bsy,px,py);
    212325  mText[3]->SetText("");
    213326
    214327// Creation de bouton d'action
    215328
    216   py += 3*spy+bsy;
    217   px = (szx-6*bsx-6*spx)/2;
    218   mBut[0] = new PIButton(this, "Set Options",  500, bsx*2, bsy, px, py);
    219   px += 2*bsx+2*spx;
    220   mBut[1] = new PIButton(this, "Get Option",  600, bsx*2, bsy, px, py);
    221   px += 2*bsx+2*spx;
    222   mBut[2] = new PIButton(this, "Dismiss",  700, bsx*2, bsy, px, py);
     329  px = (int)(szx/2 - 1.5*bsx - spx - 1.5*bsx/2.);
     330  py += spy+bsy;
     331  mBut[0] = new PIButton(this,"Set Options",500,1.5*bsx,bsy,px,py);
     332  px += (int)(1.5*bsx+spx);
     333  mBut[1] = new PIButton(this,"Get Options",600,1.5*bsx,bsy,px,py);
     334  px += (int)(1.5*bsx+spx);
     335  mBut[2] = new PIButton(this,"Dismiss",700,1.5*bsx, bsy,px,py);
    223336
    224337//  Taille et position proportionnelles a la taille de la fenetre pour les elements
    225338  mTit->SetBinding(PIBK_elastic , PIBK_elastic , PIBK_elastic , PIBK_elastic);
    226 
    227   for(int i=0; i<4; i++) {
     339  for(int i=0; i<4; i++)
    228340    mLab[i]->SetBinding(PIBK_elastic , PIBK_elastic , PIBK_elastic , PIBK_elastic);
    229 
     341  for(int i=0; i<4; i++)
    230342    mText[i]->SetBinding(PIBK_elastic , PIBK_elastic , PIBK_elastic , PIBK_elastic);
    231   }
    232   for(int ii=0; ii<3; ii++)
    233     mBut[ii]->SetBinding(PIBK_elastic , PIBK_elastic , PIBK_elastic , PIBK_elastic);
    234 
     343  for(int i=0; i<3; i++)
     344    mBut[i]->SetBinding(PIBK_elastic , PIBK_elastic , PIBK_elastic , PIBK_elastic);
    235345}
    236346
     
    238348CxxOptionWind::~CxxOptionWind()
    239349{
    240   for(int i=0; i<4; i++) {
    241     delete mLab[i];
    242     delete mText[i];
    243   }
    244350  delete mTit;
    245   delete mBut[0];
    246   delete mBut[1];
    247   delete mBut[2];
    248 }
    249 
     351  for(int i=0; i<4; i++) delete mLab[i];
     352  for(int i=0; i<3; i++) delete mBut[i];
     353  for(int i=0; i<4; i++) delete mText[i];
     354}
    250355
    251356/* --Methode-- */
     
    255360  mText[1]->SetText(cxxex->GetCompileOpt());
    256361  mText[2]->SetText(cxxex->GetLinkOpt());
    257   mText[2]->SetText(cxxex->GetLinkLibs());
     362  mText[3]->SetText(cxxex->GetLinkLibs());
    258363  PIWindow::Show();
    259364}
     
    262367void CxxOptionWind::Process(PIMessage msg, PIMsgHandler* /*sender*/, void* /*data*/)
    263368{
    264 
    265369  string opt;
    266  
    267370  switch (UserMsg(msg))  {
    268 
    269371    case 500:    // Bouton Set Options
    270 // On recupere les textes des 3 champs :
    271372      opt = mText[0]->GetText();
    272373      cxxex->FillInclude(opt);
     
    278379      cxxex->FillLinkLibs(opt);
    279380      break;
    280 
    281381    case 600:    // Bouton Get Options
    282382      mText[0]->SetText(cxxex->GetInclude());
    283383      mText[1]->SetText(cxxex->GetCompileOpt());
    284384      mText[2]->SetText(cxxex->GetLinkOpt());
    285       mText[2]->SetText(cxxex->GetLinkLibs());
    286       break;
    287 
     385      mText[3]->SetText(cxxex->GetLinkLibs());
     386      break;
    288387    case 700:   // Bouton Dismiss - On cache la fenetre
    289388      this->Hide();
    290389      break;
    291390  }
    292    
    293391return;
    294392}
    295 
    296 
Note: See TracChangeset for help on using the changeset viewer.