source: PSPA/Interface_Web/trunk/pspaWT/sources/userInterface/src/GWt_pspaApplication.cc @ 381

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

complements graphiques, legendes et unification unites

File size: 31.2 KB
RevLine 
[41]1#include <stdio.h>
2#include <string.h>
[56]3#include <vector>
[198]4
[177]5#include "GWt_pspaApplication.h"
[254]6#include "GWt_ligneFaisceau.h"
[302]7#include "GWt_softwarePanel.h"
[177]8#include "GWt_globalParameters.h"
[233]9// #include "GWt_dialog.h"
[223]10#include "GWt_draggableImage.h"
[177]11#include "particleBeam.h"
12#include "bareParticle.h"
13#include "nomDeLogiciel.h"
14#include "mixedTools.h"
15#include "nomdElements.h"
[185]16#include "environmentVariables.h"
[242]17#include "GWt_console.h"
[336]18#include "GWt_serverFileSelector.h"
[230]19#include "trivaluedBool.h"
[177]20
[41]21#include <Wt/WGridLayout>
22#include <Wt/WVBoxLayout>
[54]23#include <Wt/WHBoxLayout>
[41]24#include <Wt/WImage>
[93]25#include <Wt/WMenu>
26#include <Wt/WStackedWidget>
[45]27#include <Wt/WBreak>
[140]28#include <Wt/WDialog>
[54]29#include <Wt/WStandardItemModel>
[173]30#include <Wt/WFileUpload>
[200]31#include <Wt/WPainter>
32#include <Wt/WPdfImage>
33#include <Wt/WRasterImage>
[256]34#include <Wt/WScrollArea>
[302]35#include <Wt/WLineEdit>
[324]36#include <Wt/WRadioButton>
[41]37
[54]38using namespace Wt::Chart;
[41]39
40/*
41 * The env argument contains information about the new session, and
42 * the initial request. It must be passed to the WApplication
43 * constructor so it is typically also an argument for your custom
44 * application constructor.
[272]45 */
[41]46
[379]47PspaApplication::PspaApplication(const WEnvironment& env) : 
48  WApplication(env),
49  applicationDefaultTitle_("portail PSPA"),
50  beamLine_(NULL),
51  extensionFile_(0)
[106]52{
[379]53  workingDir_ = WApplication::docRoot()+ "/"+WORKINGAREA;
54  nameOfCase_ = "pspa"; // default
[246]55   
[379]56  setTitle(applicationDefaultTitle_);  // application title
57  if (!wApp->environment().javaScript()) {
58    new WText("<i>This examples requires that javascript support is enabled.</i>",root());
59  }
[272]60   
[379]61  // register the absractElementFactory
62  abstractElementFactory_ = new GWt_abstractElementFactory();
63  abstractElementFactory_->setRFGunEnable(true);
64  abstractElementFactory_->setDriftEnable(true);
65  abstractElementFactory_->setCellEnable(true);
66  abstractElementFactory_->setBendEnable(true);
67  abstractElementFactory_->setSolenoEnable(true);
68  abstractElementFactory_->setBeamEnable(true);
69  abstractElementFactory_->setFitEnable(true);
70  abstractElementFactory_->setSnapshotEnable(true);
71 
72  // include the styleSheet
73  WContainerWidget *widroot = root();
74  useStyleSheet("htdocs/pspa.css");
75  dtmanage_ = new dataManager(this);
76  //    dtmanage_->setWorkingDir(workingDir_);
77 
78  /*
79   * The main layout is a 3x2 grid layout.
80   */
81  WGridLayout *layout = new WGridLayout();
82  //  layout->addWidget(createTitle("<a href='workingArea/parmin'> Menu (In future)</a>"), 0, 0, 1, 2);
83  //  layout->addWidget(createTitle("Menu (In future)"), 0, 0, 1, 2);
84 
85  WHBoxLayout *toolbarLayout = new WHBoxLayout();
86 
87  WPushButton* boutonSauve = new WPushButton();
88  WPushButton* boutonRestaure = new WPushButton();
89  WPushButton* boutonLoadNew = new WPushButton();
90  WPushButton* boutongraphicalAnalysis = new WPushButton();
91  WPushButton* boutonTrash = new WPushButton();
92 
93  boutonSauve->setStyleClass("saveButton");
94  boutonRestaure->setStyleClass("restoreButton");
95  boutonLoadNew->setStyleClass("loadNewButton");
96  boutongraphicalAnalysis->setStyleClass("histoButton");
97  boutonTrash->setStyleClass("trashButton");
98 
99  boutonSauve->setToolTip ("sauvegarder votre configuration");
100  boutonRestaure->setToolTip (" restaurer la configuration depuis le serveur");
101  boutonLoadNew->setToolTip ("charger une configuration");
102  boutongraphicalAnalysis->setToolTip ("analyse graphique");
103  boutonTrash->setToolTip ("tout effacer");
104 
105  boutonSauve->setMaximumSize(38,38);
106  boutonSauve->setMinimumSize(38,38);
107  boutonRestaure->setMaximumSize(38,38);
108  boutonRestaure->setMinimumSize(38,38);
109  boutonLoadNew->setMaximumSize(38,38);
110  boutonLoadNew->setMinimumSize(38,38);
111  boutongraphicalAnalysis->setMaximumSize(38,38);
112  boutongraphicalAnalysis->setMinimumSize(38,38);
113  boutonTrash->setMaximumSize(38,38);
114  boutonTrash->setMinimumSize(38,38);
115 
116  boutonSauve->clicked().connect(this, &PspaApplication::sauver);
117  boutonRestaure->clicked().connect(this, &PspaApplication::restaurer);
118  // Upload when the button is clicked.
119  // React to a succesfull upload.
120  boutonLoadNew->clicked().connect(this, &PspaApplication::openFileSelector);
121 
122  boutongraphicalAnalysis->clicked().connect(this, &PspaApplication::dialogOnGraphics);
123 
124  boutonTrash->clicked().connect(this, &PspaApplication::removeBeamLine);
125 
126  toolbarLayout->addWidget(boutonSauve , 0,Wt::AlignMiddle);
127  toolbarLayout->addWidget(boutonRestaure , 0,Wt::AlignMiddle);
128  toolbarLayout->addWidget(boutonLoadNew , 0,Wt::AlignMiddle);
129  toolbarLayout->addWidget(boutongraphicalAnalysis , 0,Wt::AlignMiddle);
130  toolbarLayout->addWidget(boutonTrash , 0,Wt::AlignMiddle);
131  toolbarLayout->addWidget(new WText("") , 1,Wt::AlignMiddle);
132 
133  WContainerWidget * layoutContainer = new WContainerWidget();
134  layoutContainer->setLayout(toolbarLayout);
135  layoutContainer->decorationStyle().setBackgroundImage ("/htdocs/fond_toolbar.png");
136  layout->addWidget(layoutContainer, 1, 0, 1, 2);
137  layout->addWidget(createPalette(), 2, 0, 4, 1);
138 
139  createBeamLine();
140 
141  WScrollArea* scroll = new  WScrollArea();
142  scroll->setWidget(beamLine_);
143  layout->addWidget(scroll, 2, 1, 1, 1);
144 
145 
146  // console_ = new WContainerWidget();
147  // console_->decorationStyle().setBackgroundColor (WColor("lightgray"));
148  // console_->setMaximumSize(600,200);
149  // layout->addWidget(console_, 3, 1);
150  // console_->setMinimumSize(300,100);
151  // console_->setOverflow(WContainerWidget::OverflowAuto);
152 
153 
154  console_ = new GWt_console();
155  console_->clear();
156  console_->decorationStyle().setBackgroundColor (WColor("lightgray"));
157  console_->setMaximumSize(600,200);
158  console_->setMinimumSize(300,100);
159  console_->setOverflow(WContainerWidget::OverflowAuto);
160  layout->addWidget(console_, 3, 2);
161 
162  //-----------
163  // A supprimer et a mettre en fenetre
164  globalParam_ = createGlobalParamWidget();
165  //  leDessin_ = new WContainerWidget();
166  //  leDessin_ = createDrawingWidget();
167  graphicsDialog_ = new GWt_dialog("graphical analysis",createDrawingWidget(),false);
168  graphicsDialog_->setMinimumSize(400,400);
169  graphicsDialog_->setClosable(true);
170 
171  executeWidget_ = new GWt_softwarePanel(dtmanage_,this);
172 
173  layout->addWidget( globalParam_, 3, 1);
174  //  layout->addWidget( leDessin_, 3, 2);
175  layout->addWidget( executeWidget_ , 4, 1);
176  //-----------
177 
178  layout->setColumnResizable(1);
179  layout->setRowResizable(2);
180  /*
181   * Let row 2 and column 1 take the excess space.
182   */
183  layout->setRowStretch(2, 1);
184  layout->setColumnStretch(1, 1);
185 
186  widroot->setLayout(layout);
[106]187}
188
[41]189WWidget* PspaApplication::createPalette()
190{
[324]191  WContainerWidget* palette = new WContainerWidget();
192  vector <GWt_abstractElement*> elems = abstractElementFactory_->getAllElements();
193  for (unsigned a = 0; a < elems.size(); a++) {
194    elems[a]->createDragImage(palette);
195    new WBreak(palette);
196  }
197
198  return palette; 
[41]199}
200
[324]201void PspaApplication::createDragImage(const char *url,const char *smallurl,const char *mimeType,WContainerWidget *p,WString())
[106]202{
[324]203  GWt_draggableImage *result = new GWt_draggableImage(url,p);
204 
205  /*
206   * Set the image to be draggable, showing the other image (dragImage)
207   * to be used as the widget that is visually dragged.
208   */
209  result->setDraggable(mimeType,new WImage(smallurl,p),true);
[106]210}
211
[305]212void PspaApplication::createBeamLine()
[41]213{
[379]214  extensionFile_= 0;
215  if (!beamLine_) {
216    beamLine_ = new GWt_LigneFaisceau(this);
217  } else {
218    beamLine_->clear();
219  }
220  beamLine_->setMinimumSize(300,100);
221  setTitle(applicationDefaultTitle_);
[41]222}
223
224WWidget* PspaApplication::createGlobalParamWidget()
225{
[272]226    WContainerWidget* globalParam = new GWt_globalParameters(this);
227    globalParam->setMaximumSize(600,150);
228    globalParam->setMinimumSize(600,150);
229    return globalParam;
[41]230}
231
[58]232
[233]233void PspaApplication::dialogOnGraphics()
234{
[324]235  graphicsDialog_->show();
[233]236}
237
[138]238WContainerWidget* PspaApplication::createDrawingWidget()
[114]239{
[324]240  WGridLayout *glayout= new WGridLayout();
241  WContainerWidget* dessin = new WContainerWidget();
242  dessin->setLayout(glayout);
[320]243
[324]244  group_ = new Wt::WButtonGroup(this);
245 
246  /////////////////////////////////////////////////////////////////////
247       
248  choixEnveloppeDessin_ = new WComboBox();
249  choixEnveloppeDessin_->addItem("x");
250  // choixEnveloppeDessin_->addItem("y");
251  Wt::WRadioButton *button1= new WRadioButton(" enveloppe");
252  group_->addButton(button1,1);
253  glayout->addWidget(button1,0,1);
254  glayout->addWidget(choixEnveloppeDessin_,0,2);
255  /////////////////////////////////////////////////////////////////////
[320]256
[324]257  choixElementDessin_ = new WComboBox();
[339]258  choixElementDessin_->setMinimumSize(50,10);
[324]259  choixTypeDessinFaisceau_ = new WComboBox();
260  choixTypeDessinFaisceau_->addItem("courant_snyder");
261  choixTypeDessinFaisceau_->addItem("macroparticles");
262  Wt::WRadioButton *button2= new WRadioButton(" phase space after element");
[333]263
[343]264  choixAbsPhase_ = new WComboBox();
265  choixAbsPhase_->addItem("x");
266  choixAbsPhase_->addItem("y");
[354]267  choixAbsPhase_->addItem("dz");
[343]268  choixAbsPhase_->addItem("xp");
269  choixAbsPhase_->addItem("yp");
270  choixAbsPhase_->addItem("dE/E");
271  choixAbsPhase_->setCurrentIndex(0);
272 
273  choixOrdPhase_ = new WComboBox();
274  choixOrdPhase_->addItem("x");
275  choixOrdPhase_->addItem("y");
[354]276  choixOrdPhase_->addItem("dz");
[343]277  choixOrdPhase_->addItem("xp");
278  choixOrdPhase_->addItem("yp");
279  choixOrdPhase_->addItem("dE/E");
280  choixOrdPhase_->setCurrentIndex(3);
281 
[324]282  group_->addButton(button2,2);
283  glayout->addWidget(button2,1,1);
284  glayout->addWidget(choixElementDessin_,1,2);
285  glayout->addWidget(choixTypeDessinFaisceau_,1,3);
[339]286  //  glayout->addWidget(new WText("abs. :"),2,2);
287  glayout->addWidget(choixAbsPhase_,2,2);
288  //  glayout->addWidget(new WText("ord. :"),2,4);
289  glayout->addWidget(choixOrdPhase_,2,3);
[324]290  /////////////////////////////////////////////////////////////////////
[320]291
[362]292  choixVariableHisto_= new WComboBox();
293  choixVariableHisto_->addItem("x");
294  choixVariableHisto_->addItem("y");
295  choixVariableHisto_->addItem("z");
[371]296  choixVariableHisto_->addItem("xp");
297  choixVariableHisto_->addItem("yp");
[362]298  choixVariableHisto_->addItem("dE/E");
[371]299  choixVariableHisto_->setCurrentIndex(5);
[362]300
[324]301  choixHistoDessin_ = new WComboBox();
[367]302  Wt::WRadioButton *button3= new WRadioButton(" histogram after element ");
[324]303  group_->addButton(button3,3);
[362]304
[339]305  glayout->addWidget(button3,3,1);
[367]306  glayout->addWidget(choixHistoDessin_,3,2);
307  glayout->addWidget(choixVariableHisto_,3,3);
[324]308  /////////////////////////////////////////////////////////////////////
309 
310  WPushButton *close= new WPushButton("close"); 
[339]311  glayout->addWidget(close,4,1);
[324]312  close->clicked().connect(this,&PspaApplication::closeGraphicDialog);
313 
314  WPushButton *draw= new WPushButton("draw"); 
[339]315  glayout->addWidget(draw,4,2,2,1);
[324]316  draw->clicked().connect(this,&PspaApplication::dessiner);
317  /////////////////////////////////////////////////////////////////////
318
319  toto_ = new WContainerWidget();
320  dessin->addWidget(toto_);
321  return dessin;
[114]322}
323
[324]324void PspaApplication::closeGraphicDialog()
325{
326  cout << " close graphicsDialog_" << endl;
[340]327  for(unsigned i = 0; i < eDialog_.size(); i++) eDialog_[i]->done(WDialog::Rejected);
328  eDialog_.clear();
[324]329  graphicsDialog_->done(WDialog::Rejected);
330}
[58]331
[324]332void PspaApplication::dessiner()
333{
334  int k= group_->checkedId();
335  cout << "dessiner k= " << k << endl;
[58]336
[324]337  switch(k) {
338  case  1: 
339    dessinerEnveloppe();
340    break;
341  case 2:
342    dessinerPhaseSpace();
343    break;
344  case 3:
345    dessinerHistogramme();
346    break;
347  default:
348    GWt_dialog graphicalWarning("graphical analysis","select a button",GWt_dialog::Warning,false,true);
349    graphicalWarning.exec();
350    break;
351  }
352}
[112]353
[347]354
[50]355void PspaApplication::sauver()
356{
[324]357  cout << " on sauve " << endl;
358  console_->addConsoleMessage("sauvegarde");
359 
360  dialogSave_ = new WDialog("save");
361  new WText("name of case : ",dialogSave_->contents());
362  saveNameEdit_ = new WLineEdit(nameOfCase_.c_str(), dialogSave_->contents());
363  WPushButton *annule = new WPushButton("cancel",dialogSave_->contents());
364  WPushButton *submit = new WPushButton("OK",dialogSave_->contents());
365  annule->clicked().connect(dialogSave_, &Wt::WDialog::reject);
366  submit->clicked().connect(dialogSave_, &Wt::WDialog::accept);
367  dialogSave_->finished().connect(this, &PspaApplication::dialogSaveDone);
368  dialogSave_->show();
[179]369}
370
[347]371
[185]372void PspaApplication::dialogSaveDone(WDialog::DialogCode code)
[179]373{
[347]374    if ( code != Wt::WDialog::Accepted ) {
375        return;
376    }
377    nameOfCase_ = saveNameEdit_->text().toUTF8();
378    delete dialogSave_;
379    dialogSave_ = NULL;
380
381    GWt_globalParameters* bibi = static_cast<GWt_globalParameters*>(globalParam_);
382    bibi->updateGlobals();
383    //  dtmanage_->saveConfiguration(nameOfCase_);
384    dtmanage_->saveConfiguration(sessionId(),nameOfCase_);
[50]385}
[41]386
[336]387
[50]388void PspaApplication::restaurer()
389{
[379]390  GWt_serverFileSelector * fs = new GWt_serverFileSelector("Select a configuration file",workingDir_);
391  string fileName = fs->exec();
392  nameOfCase_ = fileName;
393  if (fileName == "") {
394    return;
395  }
[375]396   
[379]397  removePathFromConfigName(nameOfCase_ );
398  cout << " nom sans path " << nameOfCase_ << endl;
399  removeExtensionFromConfigName(nameOfCase_);
400  cout << " nom sans extension " << nameOfCase_ << endl;
401  if (nameOfCase_ == "")
402    return;
403  cout << " je restaure le fichier " << fileName << endl;
404  dialogSave_ = NULL;
405 
406  bool test = dtmanage_->restoreElements(fileName);
407  if ( !test ) {
408    GWt_dialog restoreWarning(" element restoring", "failure in restoring elements from file : " + fileName , GWt_dialog::Error, false,true);
409    restoreWarning.exec();
410  } else {
411    // Change the window title
412    unsigned long found = fileName.find_last_of("/");
413    setTitle(applicationDefaultTitle_+" : "+fileName.substr(found+1));
414  }
415 
416  GWt_globalParameters* bibi = static_cast<GWt_globalParameters*>(globalParam_);
417  bibi->renew();
418 
419  console_->addConsoleMessage(string("...terminee"));
[50]420}
421
[174]422void PspaApplication::openFileSelector()
423{
[272]424   
[324]425  WContainerWidget *result = new WContainerWidget();
426  WVBoxLayout* myLayout = new WVBoxLayout();
[272]427   
[324]428  uploadFileSelectorWidget_ = new WFileUpload();
[272]429   
[324]430  uploadFileSelectorWidget_->setFileTextSize(40);
[272]431   
[324]432  myLayout->addWidget(new WText("Select the configuration file for pspa : "));
433  myLayout->addWidget(uploadFileSelectorWidget_);
[272]434   
[324]435  result->setLayout (myLayout);
[272]436   
[324]437  // Upload automatically when the user entered a file.
438  uploadFileSelectorWidget_->changed().connect(uploadFileSelectorWidget_, &WFileUpload::upload);
439 
440  // React to a succesfull upload.
441  uploadFileSelectorWidget_->uploaded().connect(this, &PspaApplication::chargerConfig);
442 
443  // React to a fileupload problem.
444  uploadFileSelectorWidget_->fileTooLarge().connect(this, &PspaApplication::fileTooLarge);
445 
446 
447  GWt_dialog* fileSelectorDialog = new GWt_dialog("Load a file",result,false);
448 
449  fileSelectorDialog->exec();
[174]450}
451
[173]452void PspaApplication::chargerConfig()
453{
[379]454  GWt_dialog*  message= new GWt_dialog("File successfully upload","The file has been correctly upload to" + uploadFileSelectorWidget_->spoolFileName(),GWt_dialog::Warning,false,true);
[272]455   
[379]456  string nomDuFichier = (uploadFileSelectorWidget_->clientFileName()).toUTF8();
457  cout << " fichier client : " << nomDuFichier << endl;
458  bool test = removeExtensionFromConfigName(nomDuFichier);
459  cout << " fichier client sans extension : " << nomDuFichier << endl;
460 
461  if ( test )
[185]462    {
[379]463      nameOfCase_ = nomDuFichier;
464      console_->addConsoleMessage(string("restauration..."));
465     
466      if ( !dtmanage_->restoreElements(uploadFileSelectorWidget_->spoolFileName()) ) {
467        GWt_dialog restoreWarning(" element restoring", "failure in restoring elements !", GWt_dialog::Error, false,true);
468        restoreWarning.exec();
469      }
470     
471      GWt_globalParameters* bibi = static_cast<GWt_globalParameters*>(globalParam_);
472      bibi->renew();
473     
474      console_->addConsoleMessage(string("...terminee"));
475      message->show();
[185]476    }
[173]477}
478
[175]479void PspaApplication::fileTooLarge()
480{
[379]481  std::stringstream stream;
482  stream << maximumRequestSize ();
483  std::string maxRequestSize(stream.str());
484 
485  std::string message = "This file is too large, please select a one\n";
486  message += "Maximum file size is "+ maxRequestSize;
487  message += " bytes\n";
[272]488   
[379]489  GWt_dialog*  messageBox= new GWt_dialog("Error during upload file" ,message ,GWt_dialog::Error,false,true);
490 
491  messageBox->show();
[175]492}
493
[56]494void PspaApplication::faireDessin()
495{
[324]496  choixElementDessin_->clear();
497  choixHistoDessin_->clear();
[343]498
499  int nombre = dtmanage_->getBeamLineSize(); 
[324]500  for(int i = 1; i <= nombre; i++) {
[343]501    abstractElement* elPtr = dtmanage_->getElementPointerFromNumero(i);
502    if(elPtr->getNomdElement().getElementType() == snapshot) continue;
503
504    choixElementDessin_->addItem(elPtr->getLabel());
505    choixHistoDessin_->addItem(elPtr->getLabel());
[324]506  } 
[138]507}
[114]508
[324]509void PspaApplication::dessinerPhaseSpace()
510{   
[272]511   
[333]512  int typeFaisceau = choixTypeDessinFaisceau_->currentIndex();
[324]513  int index = choixElementDessin_->currentIndex();
[381]514  string nameAbs = choixAbsPhase_->currentText().toUTF8();
515  string nameOrd = choixOrdPhase_->currentText().toUTF8();
516  if ( nameAbs == nameOrd ) {
[341]517        GWt_dialog phaseSpaceError(" graphical analysis", "the beam coordinates must be different !", GWt_dialog::Error, false,true);
518        phaseSpaceError.exec();
519        return;
520  }
521
[324]522  particleBeam* beam = dtmanage_->getDiagnosticBeam(index);
[272]523   
[324]524  if ( beam == NULL ) {
525    GWt_dialog warningBeamState(" graphical analysis", "the beam does not exist at the end of this element !", GWt_dialog::Error, false,true);
526    warningBeamState.exec();
527    return;
528  }
[333]529   
[341]530    toto_->clear();
[381]531    faireDessinPhaseSpace(toto_, beam, nameAbs, nameOrd, typeFaisceau);
532
533  // if ( typeFaisceau == 0 )
534  //   {
535  //     if ( !beam->momentRepresentationOk() ) beam->buildMomentRepresentation();
536  //     faireDessinTransport(toto_, beam, nameAbs, nameOrd );
537  //   }
538  // else if ( typeFaisceau == 1 )
539  //   {
540  //     if ( beam->particleRepresentationOk() ) faireDessinParmela(toto_, beam, nameAbs, nameOrd );
541  //     else {
542  //    GWt_dialog warningBeamState(" graphical analysis", "the beam state does not allow providing a drawing with macroparticles !", GWt_dialog::Error, false,true);
543  //    warningBeamState.exec();
544  //     }
545  //   }
546  // else {
547  //   GWt_dialog warningTypeDrawing(" graphical analysis", "type of  drawing not programmed !", GWt_dialog::Error, false,true);
548  //   warningTypeDrawing.exec();
549  // }
[149]550}
[138]551
[149]552void PspaApplication::dessinerEnveloppe()
553{
[324]554  toto_->clear();
555 
556  int typeEnveloppe = choixEnveloppeDessin_->currentIndex();
557  if ( typeEnveloppe == 0 )
[149]558    {
[324]559      faireDessinEnveloppe(toto_, "x");
[149]560    }
[324]561  else {
562    GWt_dialog warningTypeEnveloppe(" graphical analysis", "type of enveloppe drawing not programmed !", GWt_dialog::Error, false,true);
563    warningTypeEnveloppe.exec();
564  }
[105]565}
566
[149]567void PspaApplication::faireDessinEnveloppe(WContainerWidget* toto, string type)
568{
[272]569   
[324]570  GWt_dialog* envDialog = new GWt_dialog("enveloppe",toto,false);
[340]571  eDialog_.push_back(envDialog);
[324]572  envDialog->setMinimumSize(400,400);
573  envDialog->setClosable(true);
574  envDialog->show();
575     
[355]576  //  unsigned nbel = dtmanage_->getBeamLineSize();
[324]577  vector<double> xcor;
578  vector<double> ycor;
[381]579    string titre;
580    string legendx;
581    string legendy;
582    dtmanage_->donneesRmsEnveloppe(type,xcor,ycor, titre, legendx, legendy);
583    chartPlot2vec(envDialog->contents(), xcor, ycor, false,titre, legendx, legendy,500,300);
[370]584
[149]585}
586
[381]587void PspaApplication::faireDessinPhaseSpace(WContainerWidget* toto, particleBeam* beam, string namex, string namey, int typeFaisceau)
[105]588{
[381]589
590  vector<double> xcor;
591  vector<double> ycor;
592  vector<string> legende;
593  string titre;
594  bool pointsDrawing;
595  if ( typeFaisceau == 0 ) {
596    pointsDrawing = false;
597    titre = "phase space rms";
598    beam->donneesDessinEllipse(xcor,ycor,legende, namex, namey);
599  } else if (  typeFaisceau == 1 ) {
600    pointsDrawing = true;
601    titre = " phase space ";
602    beam->particlesPhaseSpaceData(xcor, ycor, legende, namex, namey);
603  } else {
604        GWt_dialog warningBeamState(" graphical analysis", "the beam state does not allow providing a drawing with macroparticles !", GWt_dialog::Error, false,true);
605        warningBeamState.exec();
606        return;
607  }
608
609
610  GWt_dialog* phaseSpaceDialog = new GWt_dialog("phase space",toto,false);
611  eDialog_.push_back(phaseSpaceDialog);
612  phaseSpaceDialog->setMinimumSize(400,400);
613  phaseSpaceDialog->setClosable(true);
614  new WText(nameOfCase_, phaseSpaceDialog->contents());
615 
616
617  for (int k=0 ; k < legende.size(); k++) {
618    new WBreak(phaseSpaceDialog->contents());
619    new WText(legende.at(k), phaseSpaceDialog->contents());
620  }
621  chartPlot2vec(phaseSpaceDialog->contents(), xcor, ycor,pointsDrawing ,titre, namex, namey,500,300);
622  phaseSpaceDialog->show();
623
624}
625
626
627
628void PspaApplication::faireDessinParmela(WContainerWidget* toto, particleBeam* beam, string namex, string namey )
629{
[333]630  cout << " faireDessinParmela " << endl;
[340]631  GWt_dialog* pointsDialog = new GWt_dialog("space phase",toto,false);
632  eDialog_.push_back(pointsDialog);
633  pointsDialog->setMinimumSize(400,400);
634  pointsDialog->setClosable(true);
635  // pointsDialog->show();
[341]636     
[381]637  new WText(nameOfCase_, pointsDialog->contents());
[333]638
[381]639
[354]640  vector<double> xcor;
641  vector<double> ycor;
[381]642  vector<string> legende;
643  beam->particlesPhaseSpaceData(xcor, ycor, legende, namex, namey);
644  for (int k=0 ; k < legende.size(); k++) {
645    new WBreak(pointsDialog->contents());
646    new WText(legende.at(k), pointsDialog->contents());
647  }
648  string titre = " phase space ";
649  chartPlot2vec(pointsDialog->contents(), xcor, ycor, true,titre,namex, namey,400,400);
[333]650
651
[272]652   
[341]653  pointsDialog->show();
[272]654   
[341]655  //  chart->setMargin(10, Top | Bottom);            // add margin vertically
656  //  chart->setMargin(WLength::Auto, Left | Right); // center horizontally
[56]657}
658
[381]659void PspaApplication::faireDessinTransport(WContainerWidget* toto, particleBeam* beam, string namex, string namey)
[86]660{
[340]661  GWt_dialog* ellipseDialog = new GWt_dialog("ellipse",toto,false);
662  eDialog_.push_back(ellipseDialog);
663  ellipseDialog->setMinimumSize(400,400);
664  ellipseDialog->setClosable(true);
665  ellipseDialog->show();
[356]666  new WText(nameOfCase_, ellipseDialog->contents());
[340]667 
668  vector<double> xcor;
669  vector<double> ycor;
[356]670  vector<string> legende;
[381]671  beam->donneesDessinEllipse(xcor,ycor,legende, namex, namey);
[371]672
[356]673  for (int k=0 ; k < legende.size(); k++) {
[371]674    new WBreak(ellipseDialog->contents());
[356]675    new WText(legende.at(k), ellipseDialog->contents());
676  }
[381]677  string titre = "phase space rms";
678  chartPlot2vec(ellipseDialog->contents(), xcor, ycor, false,titre, namex, namey,500,300);
[149]679}
680
[354]681
[381]682// parametre drawPoints : true = on trace des points (phase space) ; false = on trace des lignes (enveloppes...)
683void PspaApplication::chartPlot2vec(WContainerWidget* toto, vector<double>& xcor, vector<double>& ycor, bool drawPoints,string title,string legendx, string legendy,int width, int height, bool makeIcon)
[149]684{
[272]685    int nbpts = xcor.size();
[354]686    cout << " PspaApplication::chartPlot2vec nbpts = " << nbpts << endl;
[272]687    WStandardItemModel *model = new WStandardItemModel(nbpts, 2, toto);
688    for (int i = 0; i < nbpts; ++i) {
689        model->setData(i, 0, xcor.at(i));
690        model->setData(i, 1, ycor.at(i));
[354]691        //    cout << " PspaApplication::chartPlot2vec el= " << i+1 << " x= " << xcor.at(i) << " y= " << ycor.at(i) << endl;
[272]692    }
693   
694    WCartesianChart *chart = new WCartesianChart(toto);
[370]695    if (!makeIcon) {
[381]696        chart->setTitle(title);
[370]697    }
698    chart->initLayout();
[272]699   
700    chart->setModel(model);        // set the model
701    chart->setXSeriesColumn(0);    // set the column that holds the X data
[370]702    if (!makeIcon) {
703        chart->setLegendEnabled(true); // enable the legend
704    } else {
705        chart->setLegendEnabled(false); // enable the legend
706    }
[272]707   
708    chart->setType(ScatterPlot);   // set type to ScatterPlot
709   
710    // Typically, for mathematical functions, you want the axes to cross
711    // at the 0 mark:
712    chart->axis(XAxis).setLocation(ZeroValue);
713    chart->axis(YAxis).setLocation(ZeroValue);
[370]714
[272]715    // Provide space for the X and Y axis and title.
[381]716      chart->setPlotAreaPadding(80, Left);  // ?
717      chart->setPlotAreaPadding(40, Bottom);
718      chart->setPlotAreaPadding(60, Top);
719      if ( drawPoints ) {
720       WDataSeries s(1, PointSeries, Y1Axis);
721       chart->addSeries(s);   
722      } else {
[354]723       WDataSeries s(1, LineSeries, Y1Axis);
724       chart->addSeries(s);   
[381]725      }
[370]726       chart->resize(width, height); // WPaintedWidget must be given explicit size
727
[381]728
729       WAxis& axis = chart->axis(XAxis);
730       axis.setLabelFormat("%.3f");
731       //       axis.setGridLinesEnabled(true);
732       axis.setTitle(legendx);
733
734       WAxis& axey = chart->axis(YAxis);
735       axey.setTitle(legendy);
736       // axis = chart->axis(YAxis);
737       // axis.setLabelFormat("%.3f");
738       // axis.setGridLinesEnabled(true);
739       // axis.setTitle(legendy);
740
[370]741    if (makeIcon) {
742        chart->setPlotAreaPadding(0);
743        chart->setAxisPadding(0);
744        WFont xAxisFont = chart->axis(XAxis).labelFont();
745        xAxisFont.setSize(8);
746        WFont yAxisFont = chart->axis(YAxis).labelFont();
747        yAxisFont.setSize(8);
748        chart->axis(XAxis).setLabelFont(xAxisFont);
749        chart->axis(YAxis).setLabelFont(yAxisFont);
750    }
751
[208]752#ifdef HAS_IMAGEMAGIC
[272]753    Wt::WRasterImage pngImage("png", 600, 600);
[370]754    Wt::WPainter p(&pngImage);
[272]755    chart->paint(p);
756    std::string name;
757    name = workingDir_ + "/chart-"+sessionId ()+".png";
758    std::ofstream f(name.c_str(), std::ios::out |std::ios::trunc | std::ios::binary);
[354]759    pngImage.write(f);   
[272]760    new WText("<a href='workingArea/chart-"+sessionId ()+".png' target='_blank'>Afficher l'image</a>",toto);
761   
762     Wt::WPdfImage pdfImage("30cm", "30cm");
763     Wt::WPainter p1(&pdfImage);
[370]764    pdfImage.init();
765    chart->paint(p1);
766     name = workingDir_ + "/chart-"+sessionId ()+".pdf";
767     std::ofstream f1(name.c_str(), std::ios::out |std::ios::trunc | std::ios::binary);
[272]768     pdfImage.write(f1);
[208]769#endif
[86]770}
771
[58]772
[272]773WText* PspaApplication::createTitle(const WString& title)
[106]774{
[324]775  WText *result = new WText(title);
776  result->setInline(false);
777  result->setStyleClass("title");
778  result->setMinimumSize(30,30);
779 
780  return result;
[93]781}
[177]782
[226]783// void PspaApplication::addConsoleMessage(WString msg) {
784//   WText *w = new WText(console_);
785//   w->setTextFormat(PlainText);
786//   w->setText(msg);
787//   w->setInline(false);
[272]788
[226]789//   /*
790//    * Little javascript trick to make sure we scroll along with new content
791//    */
792//   WApplication *app = WApplication::instance();
793//   app->doJavaScript(console_->jsRef() + ".scrollTop += "
794//                     + console_->jsRef() + ".scrollHeight;");
[272]795
[226]796// }
[185]797
[341]798bool PspaApplication::removePathFromConfigName(string& config) {
799  string toExtract = workingDir_ + "/";
800  string::size_type nn = config.find(toExtract);
801  if ( nn == string::npos ) {
802        GWt_dialog checkremovePath(" checking config file name", " failed to recognize path name for file  " + config, GWt_dialog::Error,true,true);
803        checkremovePath.exec();
804    return false;
805  }
806  config.replace(nn, toExtract.size(), "");
807  return true;
808}
809
[185]810bool PspaApplication::removeExtensionFromConfigName(string& config)
811{
[272]812    //  string configName;
813    string extension(".save");
814    bool test = true;
[185]815    string::size_type nn = config.rfind('.');
[272]816    if ( nn == string::npos )
817    {
818        // pas de point
819        test = false;
820    }
[185]821    string fin = config.substr(nn);
[272]822    if ( fin != extension )
823    {
824        // l'extension n'est pas la bonne
825        test = false;
826    }
[185]827    if ( test )
[272]828    {
829        string::size_type count = config.length() - extension.length();
830        config = config.substr(0, count);
831    }
[185]832    else
[272]833    {
834        GWt_dialog checkConfigNameDialog(" checking config file name", " the file must have the extension " + extension, GWt_dialog::Error,true,true);
835        checkConfigNameDialog.exec();
836    }
[185]837    return test;
838}
[224]839
840void PspaApplication::dessinerHistogramme()
841{
[324]842  // pour mon test : histo en energie
843  toto_->clear();
844 
[340]845  GWt_dialog* histoDialog = new GWt_dialog("histogramme",toto_,false);
846  eDialog_.push_back(histoDialog);
847  histoDialog->setMinimumSize(400,400);
848  histoDialog->setClosable(true);
849 
[324]850  int index = choixHistoDessin_->currentIndex();   
851  particleBeam* beam = dtmanage_->getDiagnosticBeam(index);
852  if (beam == NULL) {
853    GWt_dialog warningBeamState("histogram","the beam does not exist at the end of this element !", GWt_dialog::Error, false,true);
854    warningBeamState.exec();
855    return;
856  }
857 
858  if (!beam->particleRepresentationOk()) {
859    GWt_dialog warningBeamState("histogram", "the beam state does not allow providing a drawing with macroparticles !", GWt_dialog::Error, false,true);
860    warningBeamState.exec();
861    return;
862  }
863
[362]864  histoDialog->show();
[324]865  vector<double> xcor;
866  vector<int> hist;
867  double out[3]= {0.0};
[362]868
[366]869  unsigned iabs= choixVariableHisto_->currentIndex(); 
[371]870  beam->histogramme(iabs,xcor,hist,out);
[362]871
[324]872  cout<<"xcor.size()= "<<xcor.size()<<", hist.size()= "<<hist.size()<<endl;
873  //////////////////////////////////////////////////////////////////////////////////
[340]874
875  WContainerWidget *w= histoDialog->contents();
[363]876  int n = hist.size();
877  int nbpts= 2*(n+1);
[324]878  WStandardItemModel *model = new WStandardItemModel(nbpts,2,w);
[377]879
[324]880  int j= 0;
881  model->setData(j,0,xcor[0]);
[363]882  model->setData(j,1,0.0);
883  j++;
884  model->setData(j,0,xcor[0]);
[324]885  model->setData(j,1,hist[0]);
886  j++;
[377]887
[363]888  for (int i = 1; i < n; ++i) {
889    model->setData(j,0,xcor[i]);
890    model->setData(j,1,hist[i-1]);
891    j++;
892    model->setData(j,0,xcor[i]);
893    model->setData(j,1,hist[i]);
894    j++;
[324]895  }
[377]896
[363]897  model->setData(j,0,xcor[n]);
898  model->setData(j,1,hist[n-1]);
899  j++;
900  model->setData(j,0,xcor[n]);
901  model->setData(j,1,0.0);
[377]902
[324]903  // legendes
[371]904  string unites[2];
905  if(iabs == 0 || iabs == 1 || iabs == 2) {
[381]906    unites[0]= unites[1]= " mm";
[371]907  }
908  if(iabs == 3 || iabs == 4) {
[377]909    unites[0]= unites[1]= " mrad";
[371]910  }
911  if(iabs == 5) {
912    unites[0]= " MeV"; unites[1]= " KeV";
913  }
914
[324]915  new WText(" entries : "+ mixedTools::intToString((int)out[0]),w);
916  new WBreak(w);
[371]917  new WText(" mean : "+ mixedTools::doubleToString(out[1])+unites[0],w);
918  new WBreak(w);
919  new WText(" sigma rms : "+ mixedTools::doubleToString(out[2])+unites[1],w);
920   
[324]921  WCartesianChart *chart = new WCartesianChart(w);
[362]922
[377]923  if(iabs == 0) chart->setTitle("x-coordinate");
924  if(iabs == 1) chart->setTitle("y-coordinate");
925  if(iabs == 2) chart->setTitle("z-coordinate");
926  if(iabs == 3) chart->setTitle("xp-divergence");
927  if(iabs == 4) chart->setTitle("yp-devergence");
928  if(iabs == 5) chart->setTitle("kinetic energy");
[371]929 
[324]930  chart->setModel(model);        // set the model
931  chart->setXSeriesColumn(0);    // set the column that holds the categories
932  chart->setLegendEnabled(false); // enable the legend
[272]933   
[324]934  // Provide space for the X and Y axis and title.
935  chart->setPlotAreaPadding(200, Right);
936  chart->setPlotAreaPadding(80, Left);
937  chart->setPlotAreaPadding(40, Top | Bottom);
[272]938   
[324]939  chart->setType(ScatterPlot);
[272]940   
[324]941  WAxis& axis = chart->axis(XAxis);
942  axis.setLabelFormat("%.3f");
943  axis.setGridLinesEnabled(true);
944
[381]945  if(iabs == 0) axis.setTitle(WString(" x (mm)"));
946  if(iabs == 1) axis.setTitle(WString(" y (mm)"));
947  if(iabs == 2) axis.setTitle(WString(" z (mm)"));
[377]948  if(iabs == 3) axis.setTitle(WString(" xp (mrad)"));
949  if(iabs == 4) axis.setTitle(WString(" yp (mrad)"));
950  if(iabs == 5) axis.setTitle(WString(" dEcin/Ecin (%)"));
951 
[324]952  chart->axis(Y1Axis).setGridLinesEnabled(true);
[362]953  //chart->axis(Y1Axis).setTitle(WString("legende y"));
[272]954   
[324]955  WDataSeries s(1, LineSeries);
956  s.setFillRange(ZeroValueFill);
957  chart->addSeries(s);
[272]958   
[324]959  chart->resize(800, 400);
960  chart->setMargin(10, Top | Bottom);
961  chart->setMargin(WLength::Auto, Left | Right);
[272]962   
[324]963  LegendLocation location = LegendOutside;
964  Side side = Right;
965  AlignmentFlag alignment = AlignMiddle;
966  chart->setLegendLocation(location, side, alignment);
967  chart->setLegendStyle(chart->legendFont(), WPen(black), WBrush(WColor(0xFF, 0xFA, 0xE5)));
[272]968}
[347]969
[376]970void PspaApplication::removeBeamLine() {
[379]971  createBeamLine();
[376]972}
Note: See TracBrowser for help on using the repository browser.