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

Last change on this file since 232 was 232, checked in by lemeur, 11 years ago

ajustement parametres graphiques

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