source: PSPA/Interface_Web/trunk/pspaWT/src/GWt_pspaApplication.cc @ 218

Last change on this file since 218 was 218, checked in by garnier, 12 years ago

ajout de charts : sans test avec pdf

File size: 28.0 KB
RevLine 
[41]1#include <stdio.h>
2#include <string.h>
[56]3#include <vector>
[198]4
[177]5#include "GWt_pspaApplication.h"
6#include "GWt_LigneFaisceau.h"
7#include "GWt_globalParameters.h"
8#include "GWt_dialog.h"
9#include "particleBeam.h"
10#include "bareParticle.h"
11#include "nomDeLogiciel.h"
12#include "mixedTools.h"
13#include "nomdElements.h"
[185]14#include "environmentVariables.h"
[177]15
[185]16
[41]17#include <Wt/WLineEdit>
18#include <Wt/WGridLayout>
19#include <Wt/WVBoxLayout>
[54]20#include <Wt/WHBoxLayout>
[41]21#include <Wt/WImage>
[93]22#include <Wt/WMenu>
23#include <Wt/WStackedWidget>
[45]24#include <Wt/WBreak>
[140]25#include <Wt/WDialog>
[54]26#include <Wt/WStandardItemModel>
[173]27#include <Wt/WFileUpload>
[200]28#include <Wt/WPainter>
29#include <Wt/WPdfImage>
30#include <Wt/WRasterImage>
[41]31
[54]32using namespace Wt::Chart;
[41]33
34/*
35 * The env argument contains information about the new session, and
36 * the initial request. It must be passed to the WApplication
37 * constructor so it is typically also an argument for your custom
38 * application constructor.
39*/
40
[106]41PspaApplication::PspaApplication(const WEnvironment& env) : WApplication(env)
42{
[179]43  nameOfCase_ = "pspa"; // default
44
45  setTitle("portail PSPA");                               // application title
[106]46  if (!wApp->environment().javaScript()) {
47    new WText("<i>This examples requires that javascript support is enabled.</i>",root());
48  }
49 
50  WContainerWidget *w = root();
51  w->setStyleClass("PSPA");
52  dtmanage_ = new dataManager();
[41]53
[106]54  /*
55   * The main layout is a 3x2 grid layout.
56   */
57  WGridLayout *layout = new WGridLayout();
[200]58  layout->addWidget(createTitle("<a href='../workingArea/parmin'> Menu (In future)</a>"), 0, 0, 1, 2);
[106]59  layout->addWidget(createTitle("Menu (In future)"), 0, 0, 1, 2);
[198]60
[106]61  WHBoxLayout *toolbarLayout = new WHBoxLayout();
62  WPushButton* boutonSauve = new WPushButton(" sauvegarder la config");
63  WPushButton* boutonRestaure = new WPushButton(" restaurer la config");
[176]64  WPushButton* boutonLoadNew = new WPushButton(" charger une nouvelle config");
[106]65  boutonSauve->setMinimumSize(30,30);
66  boutonRestaure->setMinimumSize(30,30);
[173]67  //  boutonLoadNew->setMinimumSize(30,30);
[106]68 
[173]69  // Upload when the button is clicked.
70  // React to a succesfull upload.
[174]71  boutonLoadNew->clicked().connect(this, &PspaApplication::openFileSelector);
[173]72
73
74
[106]75  toolbarLayout->addWidget(boutonSauve , 1);
76  toolbarLayout->addWidget(boutonRestaure , 1);
[173]77  toolbarLayout->addWidget(boutonLoadNew , 1);
[106]78  boutonSauve->clicked().connect(this, &PspaApplication::sauver);
79  boutonRestaure->clicked().connect(this, &PspaApplication::restaurer);
80  layout->addLayout(toolbarLayout, 1, 0, 1, 2);
81  layout->addWidget(createPalette(), 2, 0, 4, 1);
82 
83  beamLine_ = createBeamLine();
84  layout->addWidget(beamLine_, 2, 1, 1, 1);
85 
[177]86  console_ = new WContainerWidget();
[198]87  console_->decorationStyle().setBackgroundColor (WColor("lightgray")); 
[106]88  console_->setMaximumSize(600,200);
89  layout->addWidget(console_, 3, 1);
90  console_->setMinimumSize(300,100);
[177]91  console_->setOverflow(WContainerWidget::OverflowAuto); 
92
[106]93  //-----------
94  // A supprimer et a mettre en fenetre
95  globalParam_ = createGlobalParamWidget();
[114]96  //  leDessin_ = new WContainerWidget();
97  leDessin_ = createDrawingWidget();
98
99
100
[106]101  WWidget* executeWidget = createExecuteWidget();
[114]102
[106]103  layout->addWidget( globalParam_, 4, 1);
[111]104  layout->addWidget( leDessin_, 3, 2);
[106]105  layout->addWidget( executeWidget , 5, 1);
106  //-----------
107 
108  layout->setColumnResizable(1);
109  layout->setRowResizable(2);
110  /*
111   * Let row 2 and column 1 take the excess space.
112   */
113  layout->setRowStretch(2, 1);
114  layout->setColumnStretch(1, 1);
115 
116  w->setLayout(layout); 
117}
118
[41]119WWidget* PspaApplication::createPalette()
120{
121  WContainerWidget* palette=new WContainerWidget();
122  //  palette->setLayout(new WVBoxLayout());
123
[152]124  // nomdElements *e= new nomdElements();
125  // int nElts= e->getNumberOfElements();
126  // delete e;
127  //  nomdElements bidon;
128  int nElts= nomdElements::getNumberOfElements(); 
[41]129
[152]130  for(int k = 0; k < nElts; k++) {
131    typedElement eType= (typedElement)k;
[160]132    string image = nomdElements::getImageFromType(eType);
[152]133    createDragImage(image.c_str(),
[160]134                    image.c_str(),image.c_str(), palette,nomdElements::getLabelFromType(eType));
[45]135  new WBreak(palette);
[152]136  }
[41]137
138
[198]139  //  palette->setMinimumSize(100,300);
[41]140  return palette;
141}
142
[106]143void PspaApplication::createDragImage(const char *url,const char *smallurl,const char *mimeType,WContainerWidget *p,WString name)
144{
145  WImage *result = new WImage(url,p);
146  WImage *dragImage = new WImage(smallurl,p);
147
148  /*
149   * Set the image to be draggable, showing the other image (dragImage)
150   * to be used as the widget that is visually dragged.
151   */
[199]152  cout << "createDragImage" << dragImage<<endl;
[106]153  result->setDraggable(mimeType,dragImage,true);
154}
155
[41]156WWidget* PspaApplication::createBeamLine()
157{
[106]158  WContainerWidget* beamLine = new GWt_LigneFaisceau(this);
[93]159  beamLine->setMinimumSize(300,100);
[41]160  return beamLine;
161}
162
163WWidget* PspaApplication::createGlobalParamWidget()
164{
[106]165  WContainerWidget* globalParam = new GWt_globalParameters(this);
[58]166  globalParam->setMaximumSize(600,150);
167  globalParam->setMinimumSize(600,150);
[41]168  return globalParam;
169}
170
[58]171WWidget* PspaApplication::createExecuteWidget()
172{
[112]173
[106]174  WContainerWidget* executeW = new WContainerWidget();
[58]175  executeW->setMaximumSize(600,150);
176  executeW->setMinimumSize(600,150);
177
178  // bouton execute
[106]179  exec_go_ = new WPushButton("execute!");
180  //    exec_go_->setMinimumSize(300,300);
181  exec_go_->setDisabled(true);
182  exec_go_->clicked().connect(this, &PspaApplication::executer);
[112]183
[58]184  // preparation du bouton add
[59]185  WPushButton* exec_add = new WPushButton("add");
186  exec_add->clicked().connect(this, &PspaApplication::addSectionToExecuteW);
[106]187 
[59]188  // preparation du bouton delete
189  WPushButton* exec_delete = new WPushButton("delete");
190  exec_delete->clicked().connect(this, &PspaApplication::deleteSectionToExecuteW);
191
192  // preparation du bouton push_ok
193  WPushButton* exec_ok = new WPushButton("check/ok");
194  exec_ok->clicked().connect(this, &PspaApplication::checkSectionSelection);
[106]195 
[58]196  // le panel
197  WPanel *panelLogiciels = new WPanel(executeW);
198  panelLogiciels->setTitle(" sections of beam Line for executing softwares ");
199
[112]200  contenuSections_ = new WContainerWidget(); 
201  contenuSections_->addWidget(exec_add);
202  contenuSections_->addWidget(exec_delete);
203  contenuSections_->addWidget(exec_ok);
[106]204  contenuSections_->addWidget(exec_go_);
[59]205  contenuSections_->addWidget(new WBreak());
206  contenuSections_->addWidget(new WBreak());
[106]207  addSectionToExecuteW();
208 
[58]209  panelLogiciels->setCentralWidget(contenuSections_);
210  return executeW;
211}
212
[114]213
[138]214WContainerWidget* PspaApplication::createDrawingWidget()
[114]215{
216  WContainerWidget* dessin = new WContainerWidget();
217
[200]218
219  dessin->addWidget(new WText("graphic analysis :  "));
[138]220  dessin->addWidget(new WBreak());
[114]221  dessin->addWidget(new WText(" drawing after element :  "));
[138]222
223
224  choixElementDessin_ = new WComboBox();
[149]225
226  choixTypeDessinFaisceau_ = new WComboBox();
227  choixTypeDessinFaisceau_->addItem("courant_snyder");
228  choixTypeDessinFaisceau_->addItem("macroparticles");
229
[138]230  dessin->addWidget(choixElementDessin_);
[149]231  dessin->addWidget(choixTypeDessinFaisceau_);
[138]232  WPushButton* caroule = new WPushButton("dessiner");
233 dessin->addWidget(caroule);
234 caroule->clicked().connect(this, &PspaApplication::dessiner);
235  dessin->addWidget(new WBreak());
236
[149]237  WPushButton* okEnv = new WPushButton("draw enveloppe");
238
239  dessin->addWidget(new WText(" drawing enveloppe :  "));
240  choixEnveloppeDessin_ = new WComboBox();
241  choixEnveloppeDessin_->addItem("x");
242  choixEnveloppeDessin_->addItem("y");
243
244  dessin->addWidget(okEnv);
245 okEnv->clicked().connect(this, &PspaApplication::dessinerEnveloppe);
246
[138]247  toto_ = new WContainerWidget();
248  dessin->addWidget(toto_);
[114]249  return dessin;
250}
251
[58]252void PspaApplication::addSectionToExecuteW()
253{
[59]254
255  disableSectionExecute();
256
[112]257  string premierText, dernierText;
258  if(selectedSections_.size() == 0)
[58]259    {
[118]260      premierText = dtmanage_->getLabelFromElementNumero(1);
261
262      dernierText = dtmanage_->getLabelFromElementNumero(dtmanage_->beamLineSize());
[58]263    }
264  else 
265    {
[85]266      dernierText = selectedSections_.back()->fin->text().toUTF8();
[118]267      int dernierNumero = dtmanage_->getCollection()->getNumeroFromLabel(dernierText);
[85]268      dernierNumero++;
269      if ( dernierNumero <= dtmanage_->beamLineSize() )
270        {
[118]271          premierText = dtmanage_->getLabelFromElementNumero(dernierNumero);
[85]272        }
273      else 
274        {
[118]275          premierText = dtmanage_->getLabelFromElementNumero(dtmanage_->beamLineSize());
[85]276        }
[118]277      dernierText = premierText;
[58]278    }
[112]279 
[118]280  //  cout << "PspaApplication::addSectionToExecute() : " << premierText << " à  " << dernierText << endl;
[58]281
[59]282  WContainerWidget* newSection = new WContainerWidget;
283
[58]284  selectedSections_.push_back(new GWt_sectionToExecute);
285  selectedSections_.back()->debut = new WLineEdit();
[59]286  selectedSections_.back()->debut->setDisabled(true);
[58]287  selectedSections_.back()->debut->setText(premierText);
288  selectedSections_.back()->fin = new WLineEdit();
[112]289  selectedSections_.back()->fin->changed().connect(this,&PspaApplication::disableSectionExecute);
[58]290  selectedSections_.back()->fin->setText(dernierText);
291  selectedSections_.back()->selection = new WComboBox();
[59]292  selectedSections_.back()->ligneDeWidget = newSection;
293  newSection->addWidget(new WText(" from : "));
294  newSection->addWidget(selectedSections_.back()->debut);
295  newSection->addWidget(new WText(" to : "));
296  newSection->addWidget(selectedSections_.back()->fin);
297  newSection->addWidget(selectedSections_.back()->selection);
[58]298
[112]299  contenuSections_->addWidget(newSection);
[59]300  unsigned nb = nomDeLogiciel::getNumberOfSoftwares();
[112]301  unsigned k;
302  for(k = 0; k < nb; k++) {
303    selectedSections_.back()->selection->addItem(nomDeLogiciel(k).getString());
304  }
[58]305}
306
[59]307void PspaApplication::disableSectionExecute()
308{
[112]309  exec_go_->setDisabled(true);
[59]310}
[58]311
[59]312void PspaApplication::checkSectionSelection()
313{
314  if ( selectedSections_.empty() ) return;
[85]315
316  // traitement de la premiere ligne
[118]317  // on impose le depart du calcul au premier element
318  string premier = dtmanage_->getLabelFromElementNumero(1);
319  (*selectedSections_.begin())->debut->setText(premier);
320
[59]321  string currentString =  (*selectedSections_.begin())->fin->text().toUTF8();
[118]322  int current = dtmanage_->getCollection()->getNumeroFromLabel( currentString);
323
324  cout << " numero " << current << endl;
325  // si la fin est mal definie on prend toute la config par defaut
326  if ( current <= 0 || current > dtmanage_->beamLineSize() ) 
[59]327    {
[118]328      current = dtmanage_->beamLineSize();
329      currentString =  dtmanage_->getLabelFromElementNumero(current);
330      (*selectedSections_.begin())->fin->setText(currentString);
[59]331    }
[85]332  current++;
[118]333  currentString = dtmanage_->getLabelFromElementNumero(current);
[85]334   
335  // traitement des suivantes (on avance d'un cran dans la liste)
[59]336  list<GWt_sectionToExecute*>::iterator itr, itr0;
[112]337  itr0 = selectedSections_.begin();
[59]338  itr0++;
[112]339  for (itr = itr0; itr != selectedSections_.end(); itr++)
[59]340    {
[85]341      // debut
[118]342      if ( current >= dtmanage_->beamLineSize() ) 
343        {
344          addConsoleMessage(" bad section definition !  \n ");
[147]345          GWt_dialog warningDialog("PSPA : Vérification des sections", " bad section definition !", GWt_dialog::Error,true,true);
[143]346          warningDialog.exec();
[118]347          return;
348        }
349
[112]350      (*itr)->debut->setText(currentString);
[85]351      // fin
352      string finString =  (*itr)->fin->text().toUTF8();
[118]353
354      int numeroFin = dtmanage_->getCollection()->getNumeroFromLabel( finString);
355
356      if ( numeroFin <= current || numeroFin > dtmanage_->beamLineSize())
[59]357        {
[118]358          addConsoleMessage(" bad section definition !  \n ");
[147]359          GWt_dialog warningDialog("PSPA : Vérification des sections", " bad section definition !", GWt_dialog::Error, true,true);
[143]360          warningDialog.exec();
[118]361          return;
[59]362        }
363
[85]364      // preparation de la ligne suivante
[118]365      current = numeroFin +1;
366      currentString = dtmanage_->getLabelFromElementNumero(current);
[59]367    }
[112]368
[143]369  if (!areDataCoherent()) {
[166]370    GWt_dialog warningDialog("PSPA : Vérification des sections", " donnees incoherentes !", GWt_dialog::Error,true,true);
[143]371    warningDialog.exec();
372  }
[105]373  else 
374    {
375      exec_go_->setDisabled(false);
376    }
[59]377}
[112]378
[105]379bool PspaApplication::areDataCoherent() 
380{
[112]381  bool caMarche = true;
[105]382  dtmanage_->initializeExecution();
[112]383 
[105]384  list<GWt_sectionToExecute*>::iterator itr;
[112]385  for(itr = selectedSections_.begin(); itr != selectedSections_.end(); itr++)
[105]386    {
387      string debString = (*itr)->debut->text().toUTF8();
388      string finString = (*itr)->fin->text().toUTF8();
[118]389
390
391      int debut = dtmanage_->getCollection()->getNumeroFromLabel(debString);
392      int fin = dtmanage_->getCollection()->getNumeroFromLabel(finString);
[112]393      nomDeLogiciel prog = nomDeLogiciel ( (*itr)->selection->currentIndex() );
394      dtmanage_->addSectionToExecute(debut,fin,prog);
[105]395    }
[112]396
[105]397  string diagnostic = dtmanage_->checkExecute();
398  if ( !diagnostic.empty() )
399    {   
400      caMarche = false; 
401      addConsoleMessage(diagnostic.c_str());
[147]402      GWt_dialog calculDialog("PSPA : Erreur lors de check execute", diagnostic , GWt_dialog::Error,true,true);
[143]403      calculDialog.exec();
[105]404    }
405
406  return caMarche;
407}
408
[59]409void PspaApplication::deleteSectionToExecuteW()
410{
411  if ( selectedSections_.empty() ) return;
412  disableSectionExecute();
413  selectedSections_.back()->ligneDeWidget->clear();
414  delete selectedSections_.back()->ligneDeWidget;
415  selectedSections_.pop_back();
416}
417
[105]418void PspaApplication::executer()
419{
420  addConsoleMessage(string("on va peut etre y arriver"));
421  static_cast<GWt_globalParameters*>(globalParam_)->updateGlobals();
[139]422
[161]423  GWt_dialog calculDialog("Calcul en cours", "Veuillez patienter...", GWt_dialog::Wait, true,false);
[140]424  calculDialog.show();
425
[141]426  processEvents();     
427
[105]428  string resultat;
[143]429  if ( !dtmanage_->executeAll(resultat)) {
[147]430    GWt_dialog warningDialog("PSPA : Echec", " echec lors de l'exécution !", GWt_dialog::Error, true,true);
[143]431    warningDialog.exec();
432  }
[111]433  //  cout << " PspaApplication : retour d'execution resultat =  " << resultat << endl;
[105]434  addConsoleMessage(resultat);
[111]435  //  cout << " PspaApplication : affichage console termine  " << endl;
[138]436
[139]437  exec_go_->setDisabled(true);
438
[140]439  calculDialog.hide();
440
[105]441  faireDessin();
442}
443
[50]444void PspaApplication::sauver()
445{
446  cout << " on sauve " << endl;
[59]447  addConsoleMessage("sauvegarde");
[179]448
449  dialogSave_ = new WDialog("save");
450  new WText("name of case : ",dialogSave_->contents());
451  saveNameEdit_ = new WLineEdit(nameOfCase_.c_str(), dialogSave_->contents());
[185]452  WPushButton *annule = new WPushButton("cancel",dialogSave_->contents());
[179]453  WPushButton *submit = new WPushButton("OK",dialogSave_->contents());
[185]454  annule->clicked().connect(dialogSave_, &Wt::WDialog::reject);
[179]455  submit->clicked().connect(dialogSave_, &Wt::WDialog::accept);
456  dialogSave_->finished().connect(this, &PspaApplication::dialogSaveDone); 
457  dialogSave_->show();
458}
459
[185]460void PspaApplication::dialogSaveDone(WDialog::DialogCode code)
[179]461{
[185]462  if ( code != Wt::WDialog::Accepted ) { addConsoleMessage(" pas de sauvegarde"); return;}
[202]463  else { addConsoleMessage("sauvegarde sur repertoire : " + WORKINGAREA);}
[179]464  nameOfCase_ = saveNameEdit_->text().toUTF8();
465  cout << " PspaApplication::dialogSaveDone() nameOfCase_= " << nameOfCase_ << endl;
466  delete dialogSave_;
467  dialogSave_ = NULL;
[50]468  GWt_globalParameters* bibi = static_cast<GWt_globalParameters*>(globalParam_);
469  bibi->updateGlobals();
[179]470  dtmanage_->saveConfiguration(nameOfCase_);
[50]471}
[41]472
[179]473
474
[50]475void PspaApplication::restaurer()
476{
[196]477  addConsoleMessage(string("on va recharger..."));
478  dialogOpen_ = new WDialog("open");
479  new WText("name of case : ",dialogOpen_->contents());
480  openNameEdit_ = new WLineEdit(nameOfCase_.c_str(), dialogOpen_->contents());
481  WPushButton *annule = new WPushButton("cancel",dialogOpen_->contents());
482  WPushButton *submit = new WPushButton("OK",dialogOpen_->contents());
483  annule->clicked().connect(dialogOpen_, &Wt::WDialog::reject);
484  submit->clicked().connect(dialogOpen_, &Wt::WDialog::accept);
485  dialogOpen_->finished().connect(this, &PspaApplication::dialogOpenDone); 
486  dialogOpen_->show();
487}
[59]488
[196]489void PspaApplication::dialogOpenDone(WDialog::DialogCode code)
490{
491
492  if ( code != Wt::WDialog::Accepted ) { addConsoleMessage(" pas de restauration"); return;}
493  else { addConsoleMessage("restauration depuis le repertoire " + WORKINGAREA);}
494
495  nameOfCase_ = openNameEdit_->text().toUTF8();
496  cout << " PspaApplication::dialogOpenDone() nameOfCase_= " << nameOfCase_ << endl;
497  delete dialogOpen_;
498  dialogSave_ = NULL;
499
500
501  bool test = dtmanage_->restoreElements(WORKINGAREA +  nameOfCase_ +".save");
[189]502  if ( !test ) {
503        GWt_dialog restoreWarning(" element restoring", "failure in restoring elements !", GWt_dialog::Error, false,true);
504           restoreWarning.exec();
505  }
[50]506
507  GWt_globalParameters* bibi = static_cast<GWt_globalParameters*>(globalParam_);
508  bibi->renew();
509
510  GWt_LigneFaisceau* bobo = static_cast<GWt_LigneFaisceau*>(beamLine_);
[112]511  bobo->restoreElementCollection();
[50]512
[59]513  addConsoleMessage(string("...terminee"));
[50]514}
515
[174]516
517void PspaApplication::openFileSelector()
518{
519
520  WContainerWidget *result = new WContainerWidget();
[175]521  WVBoxLayout* myLayout = new WVBoxLayout();
522
[182]523  uploadFileSelectorWidget_ = new WFileUpload();
[175]524
[182]525  uploadFileSelectorWidget_->setFileTextSize(40);
[174]526 
[175]527  myLayout->addWidget(new WText("Select the configuration file for pspa : "));
[182]528  myLayout->addWidget(uploadFileSelectorWidget_);
[175]529
530  result->setLayout (myLayout);
531
[174]532  // Upload automatically when the user entered a file.
[182]533  uploadFileSelectorWidget_->changed().connect(uploadFileSelectorWidget_, &WFileUpload::upload);
[174]534 
535  // React to a succesfull upload.
[182]536  uploadFileSelectorWidget_->uploaded().connect(this, &PspaApplication::chargerConfig);
[174]537 
538  // React to a fileupload problem.
[182]539  uploadFileSelectorWidget_->fileTooLarge().connect(this, &PspaApplication::fileTooLarge);
[174]540 
541 
542  GWt_dialog* fileSelectorDialog = new GWt_dialog("Load a file",result,false);
543 
544  fileSelectorDialog->exec();
545}
546
547
[173]548void PspaApplication::chargerConfig()
549{
[182]550  GWt_dialog*  message= new GWt_dialog("File successfully upload","The file has been correctly upload to" + uploadFileSelectorWidget_->spoolFileName(),GWt_dialog::Warning,false,true);
[185]551
552  string nomDuFichier = (uploadFileSelectorWidget_->clientFileName()).toUTF8();
553  cout << " fichier client : " << nomDuFichier << endl;
554  bool test = removeExtensionFromConfigName(nomDuFichier);
555  cout << " fichier client sans extension : " << nomDuFichier << endl;
556
557  if ( test )
558    {
559      nameOfCase_ = nomDuFichier;
560      addConsoleMessage(string("restauration..."));
561
[189]562      if ( !dtmanage_->restoreElements(uploadFileSelectorWidget_->spoolFileName()) ) {
563        GWt_dialog restoreWarning(" element restoring", "failure in restoring elements !", GWt_dialog::Error, false,true);
564        restoreWarning.exec();
565      }
[185]566
567      GWt_globalParameters* bibi = static_cast<GWt_globalParameters*>(globalParam_);
568      bibi->renew();
569
570      GWt_LigneFaisceau* bobo = static_cast<GWt_LigneFaisceau*>(beamLine_);
571      bobo->restoreElementCollection();
572
573      addConsoleMessage(string("...terminee"));
574      message->show();
575    }
[173]576}
577
[174]578
[175]579void PspaApplication::fileTooLarge()
580{
581  std::stringstream stream;
582  stream << maximumRequestSize ();
583  std::string maxRequestSize(stream.str());
584
585  std::string message = "This file is too large, please select a one\n";
586  message += "Maximum file size is "+ maxRequestSize;
587  message += " bytes\n";
588
589  GWt_dialog*  messageBox= new GWt_dialog("Error during upload file" ,message ,GWt_dialog::Error,false,true);
590 
591  messageBox->show();
592}
593
594
[56]595void PspaApplication::faireDessin()
596{
[138]597  choixElementDessin_->clear();
598  int nombre = dtmanage_->beamLineSize();
599  for ( int numero =1; numero <= nombre; numero++)
600    {
601      choixElementDessin_->addItem(dtmanage_->getLabelFromElementNumero(numero));
602    }
[114]603
[138]604}
[114]605
[138]606void PspaApplication::dessiner()
607{
608 
609  toto_->clear();
[114]610
[149]611  int typeFaisceau = choixTypeDessinFaisceau_->currentIndex();
612
[138]613  int index = choixElementDessin_->currentIndex();
[190]614
615
[138]616  particleBeam* beam = dtmanage_->getDiagnosticBeam(index);
[190]617
618  if ( beam == NULL ) {
619        GWt_dialog warningBeamState(" graphical analysis", "the beam does not exist at the end of this element !", GWt_dialog::Error, false,true);
620          warningBeamState.exec();
621          return;
622    }
623
624
[149]625  if ( typeFaisceau == 0 ) 
626    {
627      if ( !beam->momentRepresentationOk() ) beam->buildMomentRepresentation();
628      faireDessinTransport(toto_, beam);
629    }
630  else if ( typeFaisceau == 1 ) 
631    {
632      if ( beam->particleRepresentationOk() ) faireDessinParmela(toto_, beam);
[166]633      else {
634        addConsoleMessage("the beam state does not allow providing a drawing"); 
635        GWt_dialog warningBeamState(" graphical analysis", "the beam state does not allow providing a drawing with macroparticles !", GWt_dialog::Error, false,true);
636          warningBeamState.exec();
637      }
[149]638    }
[166]639  else {
640    addConsoleMessage("type of  drawing not programmed");
641        GWt_dialog warningTypeDrawing(" graphical analysis", "type of  drawing not programmed !", GWt_dialog::Error, false,true);
642           warningTypeDrawing.exec();
643 }
[149]644  //////////////////////////////////////////
645}
[138]646
[149]647void PspaApplication::dessinerEnveloppe()
648{
649 
650  toto_->clear();
651
652  int typeEnveloppe = choixEnveloppeDessin_->currentIndex();
653  if ( typeEnveloppe == 0 ) 
654    {
655      faireDessinEnveloppe(toto_, "x");
656    }
[166]657  else {
658    addConsoleMessage("type of enveloppe drawing not programmed");
659        GWt_dialog warningTypeEnveloppe(" graphical analysis", "type of enveloppe drawing not programmed !", GWt_dialog::Error, false,true);
660           warningTypeEnveloppe.exec();
661  }
[138]662  //////////////////////////////////////////
[105]663}
664
[149]665void PspaApplication::faireDessinEnveloppe(WContainerWidget* toto, string type)
666{
[189]667       new WText(nameOfCase_ + " : enveloppe", toto);
[149]668       unsigned nbel = dtmanage_->beamLineSize();
[138]669
[149]670
671  vector<double> xcor;
672  vector<double> ycor;
673
674
675  dtmanage_->donneesRmsEnveloppe(type,1, nbel, xcor,ycor);
676
677    scatterPlot1D(toto,xcor,ycor);
678
679}
680
[138]681void PspaApplication::faireDessinParmela(WContainerWidget* toto, particleBeam* beam)
[105]682{
[138]683  vector<bareParticle>& partic = beam->getParticleVector();
[203]684  new WText(nameOfCase_ + " : espace de phase x,x' "+ " nb partic. "+ mixedTools::intToString(partic.size()), toto);
[56]685  WStandardItemModel *model = new WStandardItemModel(partic.size(), 3, toto);
686  //    model->setHeaderData(0, WString("X"));
687  //   model->setHeaderData(1, WString("Y = sin(X)"));
688
689
690  for (unsigned i = 0; i < partic.size(); ++i) {
691    double x= partic.at(i).getPosition().getComponent(0);
692    double begamz = partic.at(i).getBetaGamma().getComponent(2);
693    double xp = partic.at(i).getBetaGamma().getComponent(0)/begamz;
694    //    cout << "x = " << x << " xp= " << xp << endl;
[189]695    model->setData(i, 0, x);
[56]696    model->setData(i, 1,1.e3*xp);
697    model->setData(i, 2,2.e3*xp);
698  }
699
700  WCartesianChart *chart = new WCartesianChart(toto);
701  chart->setModel(model);        // set the model
702  chart->setXSeriesColumn(0);    // set the column that holds the X data
703  chart->setLegendEnabled(true); // enable the legend
704
705  chart->setType(ScatterPlot);   // set type to ScatterPlot
706
707  // Typically, for mathematical functions, you want the axes to cross
708  // at the 0 mark:
709   chart->axis(XAxis).setLocation(ZeroValue);
710   chart->axis(YAxis).setLocation(ZeroValue);
711
712  // Provide space for the X and Y axis and title.
713  chart->setPlotAreaPadding(80, Left);
714  chart->setPlotAreaPadding(40, Top | Bottom);
715  // Add the curves
716  WDataSeries s(1, PointSeries, Y1Axis);
717  //  s.setShadow(WShadow(3, 3, WColor(0, 0, 0, 127), 3));
[58]718  //    s.setMarker(SquareMarker);
[56]719  //  s.setMarkerSize(600.);
[59]720  //  cout << "le marker est : " << s.marker() << endl;
[56]721     chart->addSeries(s);
722
723  chart->resize(300, 300); // WPaintedWidget must be given explicit size
[200]724 
[56]725
[201]726#ifdef HAS_IMAGEMAGIC
[210]727 Wt::WRasterImage pngImage("png", 600, 600);
[209]728 Wt::WPainter p(&pngImage);
729 chart->paint(p);
[211]730 std::string name;
[213]731 name = WORKINGAREA+"/chart-"+sessionId ()+".png";
[211]732 std::ofstream f(name.c_str(), std::ios::out |std::ios::trunc | std::ios::binary);
[209]733 pngImage.write(f);
[216]734 new WText("<a href='workingArea/chart-"+sessionId ()+".png' target='_blank'>Afficher l'image</a>",toto);
[201]735#endif
[200]736
[56]737  //  chart->setMargin(10, Top | Bottom);            // add margin vertically
738  //  chart->setMargin(WLength::Auto, Left | Right); // center horizontally
739}
740
741
[58]742// void PspaApplication::addElemToGlobals()
743// {
744//   static_cast<GWt_globalParameters*>(globalParam_)->addElem();
745// }
746
[138]747void PspaApplication::faireDessinTransport(WContainerWidget* toto, particleBeam* beam)
[86]748{
[138]749  //  WContainerWidget* toto = static_cast<WContainerWidget*>(leDessin_);
[114]750  //  toto->clear();
[203]751  new WText(nameOfCase_ + " : emittance x,x' ", toto);
[86]752  vector<double> xcor;
753  vector<double> ycor;
[138]754  //  dtmanage_->getCurrentBeam()->donneesDessinEllipseXxp(xcor,ycor);
755  beam->donneesDessinEllipseXxp(xcor,ycor);
[149]756    scatterPlot1D(toto,xcor,ycor);
757
758}
759
760void PspaApplication::scatterPlot1D(WContainerWidget* toto, vector<double>& xcor, vector<double>& ycor)
761{
[86]762  int nbpts = xcor.size();
[149]763  cout << " PspaApplication::scatterPlot1D nbpts = " << nbpts << endl;
[86]764  WStandardItemModel *model = new WStandardItemModel(nbpts, 2, toto);
765  for (int i = 0; i < nbpts; ++i) {
766    model->setData(i, 0, xcor.at(i));
767    model->setData(i, 1, ycor.at(i));
[166]768    //    cout << " PspaApplication::scatterPlot1D el= " << i+1 << " x= " << xcor.at(i) << " y= " << ycor.at(i) << endl;
[86]769  }
770
771  WCartesianChart *chart = new WCartesianChart(toto);
772  chart->setModel(model);        // set the model
773  chart->setXSeriesColumn(0);    // set the column that holds the X data
774  chart->setLegendEnabled(true); // enable the legend
775
776  chart->setType(ScatterPlot);   // set type to ScatterPlot
777
778  // Typically, for mathematical functions, you want the axes to cross
779  // at the 0 mark:
780   chart->axis(XAxis).setLocation(ZeroValue);
781   chart->axis(YAxis).setLocation(ZeroValue);
782
783  // Provide space for the X and Y axis and title.
784  chart->setPlotAreaPadding(80, Left);
785  chart->setPlotAreaPadding(40, Top | Bottom);
786  // Add the curves
787  WDataSeries s(1, CurveSeries, Y1Axis);
[209]788  chart->addSeries(s);
[86]789
790  chart->resize(300, 300); // WPaintedWidget must be given explicit size
[208]791
792#ifdef HAS_IMAGEMAGIC
[210]793 Wt::WRasterImage pngImage("png", 600, 600);
[209]794 Wt::WPainter p(&pngImage);
[217]795 chart->setBackground (WBrush(WColor("white")));
796
[209]797 chart->paint(p);
[212]798 std::string name;
[213]799 name = WORKINGAREA+"/chart-"+sessionId ()+".png";
[212]800 std::ofstream f(name.c_str(), std::ios::out |std::ios::trunc | std::ios::binary);
[209]801 pngImage.write(f);
802
[215]803 new WText("<a href='workingArea/chart-"+sessionId ()+".png' target='_blank'>Afficher l'image</a>",toto);
[217]804
[218]805 /*
[217]806 Wt::WPdfImage pdfImage("30cm", "30cm");
807 Wt::WPainter p1(&pdfImage);
808 chart->paint(p1);
809 std::ofstream f1("chart.pdf", std::ios::out | std::ios::binary);
810 pdfImage.write(f1);
[218]811 */
[208]812#endif
[86]813}
814
[58]815void PspaApplication::updateSelections()
816{
817  string premierText, dernierText;
818  if ( selectedSections_.size() > 0 )
819    {
[118]820      premierText = dtmanage_->getLabelFromElementNumero(1);
821      dernierText = dtmanage_->getLabelFromElementNumero( dtmanage_->beamLineSize() );
[58]822      (*selectedSections_.begin())->debut->setText(premierText);
823      (*selectedSections_.begin())->fin->setText(dernierText);
824    }
[112]825
[118]826  cout << "PspaApplication::updateSelections(): " << premierText << " à  " << dernierText << endl;
[106]827}
[58]828
[106]829string PspaApplication::getSelection()
830{
831  list<GWt_sectionToExecute*>::iterator itr = selectedSections_.begin();
832  string str = (*itr)->fin->text().toUTF8();
833  return str;
[58]834}
[93]835
[106]836WText* PspaApplication::createTitle(const WString& title) 
837{
[93]838  WText *result = new WText(title);
839  result->setInline(false);
840  result->setStyleClass("title");
841  result->setMinimumSize(30,30);
842 
843  return result;
844}
[177]845
846void PspaApplication::addConsoleMessage(WString msg) {
847  WText *w = new WText(console_);
[193]848  w->setTextFormat(PlainText);
[177]849  w->setText(msg);
850  w->setInline(false);
851 
852  /*
853   * Little javascript trick to make sure we scroll along with new content
854   */
855  WApplication *app = WApplication::instance();
856  app->doJavaScript(console_->jsRef() + ".scrollTop += "
857                    + console_->jsRef() + ".scrollHeight;");
858 
859}
[185]860
[186]861
[185]862bool PspaApplication::removeExtensionFromConfigName(string& config)
863{
864  //  string configName;
865  string extension(".save");
866  bool test = true;
867    string::size_type nn = config.rfind('.');
868    if ( nn == string::npos ) 
869      {
870        // pas de point
871        test = false;
872      }
873    string fin = config.substr(nn);
874    if ( fin != extension ) 
875      {
876        // l'extension n'est pas la bonne
877        test = false;
878      }
879    if ( test )
880      {
881        string::size_type count = config.length() - extension.length();
882        config = config.substr(0, count);
883      }
884    else
885      {
886          GWt_dialog checkConfigNameDialog(" checking config file name", " the file must have the extension " + extension, GWt_dialog::Error,true,true);
887          checkConfigNameDialog.exec();
888      }
889    return test;
890}
Note: See TracBrowser for help on using the repository browser.