source: PSPA/Interface_Web/trunk/pspaWT/sources/userInterface/src/GWt_accelerator.cc @ 474

Last change on this file since 474 was 474, checked in by garnier, 10 years ago

prise en charge de la restauration dun fichier de sauvegarde

File size: 24.1 KB
Line 
1#include "GWt_accelerator.h"
2#include "GWt_sector.h"
3
4#include <Wt/WLabel>
5#include <Wt/WPanel>
6#include <Wt/WColor>
7#include <Wt/WVBoxLayout>
8#include <Wt/WHBoxLayout>
9#include <Wt/WComboBox>
10#include <Wt/WRadioButton>
11#include <Wt/WPushButton>
12#include <Wt/WGroupBox>
13#include <Wt/WStandardItemModel>
14
15#include <string>
16
17//- Ouvrir le premier secteur quand il est chargé
18//- Ajouter les sectionToExecute
19//- Fixer le addConsoleMessage()
20//- remise a jour des éléments si on on change un bout de section
21
22GWt_accelerator::GWt_accelerator(WContainerWidget* parent, dataManager* dt) :
23WContainerWidget(parent),
24dataManager_(dt)
25{
26  setObjectName("accelerator");
27  addStyleClass("acceleratorPanel");
28  nameOfCase_ = "pspa"; // default  // FIXME
29 
30
31  WContainerWidget* menu = new WContainerWidget(this);
32  menu->addStyleClass("acceleratorMenu");
33 
34  //  Wt::WHBoxLayout* hTopLineLayout = new WHBoxLayout();
35  //  topLine->setLayout(hTopLineLayout);
36 
37  new WLabel("my accelerator ",menu);
38
39 
40  // Parameters
41  WPushButton* actionParameters = new WPushButton("",menu);
42  // set tooltips
43  actionParameters->setToolTip("change parameters");
44 
45  // Set class for actions elements
46  actionParameters->setStyleClass("Button WhiteButton parameters");
47  actionParameters->setMaximumSize(32,32);
48  actionParameters->setMinimumSize(32,32);
49 
50  // Add sector
51  WPushButton* addSectorParameters = new WPushButton("",menu);
52  // set tooltips
53  addSectorParameters->setToolTip("add a sector");
54 
55  // Set class for actions elements
56  addSectorParameters->setStyleClass("Button WhiteButton addSector");
57  addSectorParameters->setMaximumSize(32,32);
58  addSectorParameters->setMinimumSize(32,32);
59 
60  // Run
61  WPushButton* runParameters = new WPushButton("",menu);
62  // set tooltips
63  runParameters->setToolTip("run this accelerator");
64 
65  // Set class for actions elements
66  runParameters->setStyleClass("Button WhiteButton run");
67  runParameters->setMaximumSize(32,32);
68  runParameters->setMinimumSize(32,32);
69 
70  WPushButton* boutongraphicalAnalysis = new WPushButton("",menu);
71  boutongraphicalAnalysis->setStyleClass("histoButton");
72  boutongraphicalAnalysis->setToolTip ("analyse graphique");
73  boutongraphicalAnalysis->setMaximumSize(32,32);
74  boutongraphicalAnalysis->setMinimumSize(32,32);
75
76 
77  new WBreak(this);
78 
79  WScrollArea* scrollWidget = new WScrollArea(this);
80
81  WContainerWidget* acceleratorScrollArea = new WContainerWidget();
82  scrollWidget->setWidget(acceleratorScrollArea);
83  acceleratorScrollArea->setStyleClass("acceleratorContent");
84
85  WContainerWidget* acceleratorGlobalView = new WGroupBox("Global view",acceleratorScrollArea);
86  acceleratorDetailledView_ = new WGroupBox("Detailled view",acceleratorScrollArea);
87
88  acceleratorGlobalViewLayout_= new WHBoxLayout();
89  acceleratorGlobalView->setLayout(acceleratorGlobalViewLayout_);
90
91  // read configuration
92  readConfiguration();
93
94  // Actions
95  addSectorParameters->clicked().connect(this,&GWt_accelerator::addSector);
96  runParameters->clicked().connect(this,&GWt_accelerator::run);
97  boutongraphicalAnalysis->clicked().connect(this, &GWt_accelerator::dialogOnGraphics);
98
99  graphicsDialog_ = new GWt_dialog("graphical analysis",createDrawingWidget(),false);
100  graphicsDialog_->setMinimumSize(400,400);
101  graphicsDialog_->setClosable(true);
102  graphicsDialog_->hide();
103 
104}
105
106
107GWt_accelerator::~GWt_accelerator()
108{
109}
110
111void GWt_accelerator::addSector()
112{
113  sector* sect = getDataManager()->addNewSector();
114  new GWt_sector(this,sect);
115}
116
117
118void GWt_accelerator::readConfiguration()
119{
120  std::vector <sector*> sect = dataManager_->getSectors();
121  if (sect.size() == 0) {
122    // Add the first sector
123    addSector();
124  } else {
125    for (unsigned long a=0; a< sect.size(); a++) {
126      new GWt_sector(this,sect[a]);
127    }
128  }
129}
130
131
132void GWt_accelerator::run()
133{
134  cout << "***********************************" << endl;
135  cout << " GWt_softwarePanel::executer() " << endl<<endl;
136 
137  if (!areDataCoherent()) {
138    return;
139  }
140 
141  //static_cast<GWt_globalParameters*>(pspa_->getGlobalParam())->updateGlobals();
142 
143  GWt_dialog calculDialog("Calcul en cours", "Veuillez patienter...", GWt_dialog::Wait, true,false);
144  calculDialog.show();
145 
146  wApp->processEvents();
147 
148  if (!getDataManager()->executeAll()) {
149    GWt_dialog warningDialog("PSPA : Echec", " echec lors de l'exécution !", GWt_dialog::Error, true,true);
150    warningDialog.exec();
151  }
152 
153  //  exec_go_->setDisabled(true);
154  calculDialog.hide();
155  faireDessin();
156}
157
158void GWt_accelerator::faireDessin()
159{
160  choixElementDessin_->clear();
161  choixHistoDessin_->clear();
162 
163  for (unsigned k = 0; k < getDataManager()->getSectors().size(); k++) {
164    sector* sector = getDataManager()->getSectors()[k];
165    for (unsigned l = 0; l < sector->getSectionsToExecute().size(); l++) {
166      sectionToExecute* section = sector->getSectionsToExecute()[l];
167      for (unsigned m = 0; m < section->getElements().size(); m++) {
168       
169        abstractElement* elPtr = section->getElements()[m];
170        //    if(elPtr->getNomdElement().getElementType() == snapshot) continue;
171       
172        choixElementDessin_->addItem(elPtr->getLabel());
173        choixHistoDessin_->addItem(elPtr->getLabel());
174      }
175    }
176  }
177}
178
179WContainerWidget* GWt_accelerator::createDrawingWidget()
180{
181  WGridLayout *glayout= new WGridLayout();
182  WContainerWidget* dessin = new WContainerWidget();
183  dessin->setLayout(glayout);
184 
185  group_ = new Wt::WButtonGroup(this);
186 
187  /////////////////////////////////////////////////////////////////////
188 
189  choixEnveloppeDessin_ = new WComboBox();
190  choixEnveloppeDessin_->addItem("x");
191  // choixEnveloppeDessin_->addItem("y");
192  Wt::WRadioButton *button1= new WRadioButton(" enveloppe");
193  group_->addButton(button1,1);
194  glayout->addWidget(button1,0,1);
195  glayout->addWidget(choixEnveloppeDessin_,0,2);
196  /////////////////////////////////////////////////////////////////////
197 
198  choixElementDessin_ = new WComboBox();
199  choixElementDessin_->setMinimumSize(50,10);
200  choixTypeDessinFaisceau_ = new WComboBox();
201  choixTypeDessinFaisceau_->addItem("courant_snyder");
202  choixTypeDessinFaisceau_->addItem("macroparticles");
203  Wt::WRadioButton *button2= new WRadioButton(" phase space after element");
204 
205  choixAbsPhase_ = new WComboBox();
206  choixAbsPhase_->addItem("x");
207  choixAbsPhase_->addItem("y");
208  choixAbsPhase_->addItem("dz");
209  choixAbsPhase_->addItem("xp");
210  choixAbsPhase_->addItem("yp");
211  choixAbsPhase_->addItem("dE/E");
212  choixAbsPhase_->setCurrentIndex(0);
213 
214  choixOrdPhase_ = new WComboBox();
215  choixOrdPhase_->addItem("x");
216  choixOrdPhase_->addItem("y");
217  choixOrdPhase_->addItem("dz");
218  choixOrdPhase_->addItem("xp");
219  choixOrdPhase_->addItem("yp");
220  choixOrdPhase_->addItem("dE/E");
221  choixOrdPhase_->setCurrentIndex(3);
222 
223  group_->addButton(button2,2);
224  glayout->addWidget(button2,1,1);
225  glayout->addWidget(choixElementDessin_,1,2);
226  glayout->addWidget(choixTypeDessinFaisceau_,1,3);
227  //  glayout->addWidget(new WText("abs. :"),2,2);
228  glayout->addWidget(choixAbsPhase_,2,2);
229  //  glayout->addWidget(new WText("ord. :"),2,4);
230  glayout->addWidget(choixOrdPhase_,2,3);
231  /////////////////////////////////////////////////////////////////////
232 
233  choixVariableHisto_= new WComboBox();
234  choixVariableHisto_->addItem("x");
235  choixVariableHisto_->addItem("y");
236  choixVariableHisto_->addItem("z");
237  choixVariableHisto_->addItem("xp");
238  choixVariableHisto_->addItem("yp");
239  choixVariableHisto_->addItem("dE/E");
240  choixVariableHisto_->setCurrentIndex(5);
241 
242  choixHistoDessin_ = new WComboBox();
243  Wt::WRadioButton *button3= new WRadioButton(" histogram after element ");
244  group_->addButton(button3,3);
245 
246  glayout->addWidget(button3,3,1);
247  glayout->addWidget(choixHistoDessin_,3,2);
248  glayout->addWidget(choixVariableHisto_,3,3);
249  /////////////////////////////////////////////////////////////////////
250 
251  WPushButton *close= new WPushButton("close");
252  glayout->addWidget(close,4,1);
253  close->clicked().connect(this,&GWt_accelerator::closeGraphicDialog);
254 
255  WPushButton *draw= new WPushButton("draw");
256  glayout->addWidget(draw,4,2,2,1);
257  draw->clicked().connect(this,&GWt_accelerator::dessiner);
258  /////////////////////////////////////////////////////////////////////
259 
260  toto_ = new WContainerWidget();
261  dessin->addWidget(toto_);
262  return dessin;
263}
264
265
266void GWt_accelerator::dialogOnGraphics()
267{
268  graphicsDialog_->show();
269}
270
271
272void GWt_accelerator::closeGraphicDialog()
273{
274  cout << " close graphicsDialog_" << endl;
275  for(unsigned i = 0; i < eDialog_.size(); i++) eDialog_[i]->done(WDialog::Rejected);
276  eDialog_.clear();
277  graphicsDialog_->done(WDialog::Rejected);
278}
279
280
281
282void GWt_accelerator::dessiner()
283{
284  int k= group_->checkedId();
285  cout << "dessiner k= " << k << endl;
286 
287  switch(k) {
288    case  1:
289      dessinerEnveloppe();
290      break;
291    case 2:
292      dessinerPhaseSpace();
293      break;
294    case 3:
295      dessinerHistogramme();
296      break;
297    default:
298      GWt_dialog graphicalWarning("graphical analysis","select a button",GWt_dialog::Warning,false,true);
299      graphicalWarning.exec();
300      break;
301  }
302}
303
304void GWt_accelerator::dessinerPhaseSpace()
305{
306 
307  int typeFaisceau = choixTypeDessinFaisceau_->currentIndex();
308  //  int index = choixElementDessin_->currentIndex();
309  string nameAbs = choixAbsPhase_->currentText().toUTF8();
310  string nameOrd = choixOrdPhase_->currentText().toUTF8();
311  if ( nameAbs == nameOrd ) {
312    GWt_dialog phaseSpaceError(" graphical analysis", "the beam coordinates must be different !", GWt_dialog::Error, false,true);
313    phaseSpaceError.exec();
314    return;
315  }
316  string elementLabel = choixElementDessin_->currentText().toUTF8();
317  particleBeam* beam = dataManager_->getDiagnosticBeam_deprecated(elementLabel);
318  //  particleBeam* beam = dtmanage_->getDiagnosticBeam(index);
319 
320  if ( beam == NULL ) {
321    GWt_dialog warningBeamState(" graphical analysis", "the beam does not exist at the end of this element !", GWt_dialog::Error, false,true);
322    warningBeamState.exec();
323    return;
324  }
325 
326  toto_->clear();
327  faireDessinPhaseSpace(toto_, beam, elementLabel, nameAbs, nameOrd, typeFaisceau);
328 
329  // if ( typeFaisceau == 0 )
330  //   {
331  //     if ( !beam->momentRepresentationOk() ) beam->buildMomentRepresentation();
332  //     faireDessinTransport(toto_, beam, nameAbs, nameOrd );
333  //   }
334  // else if ( typeFaisceau == 1 )
335  //   {
336  //     if ( beam->particleRepresentationOk() ) faireDessinParmela(toto_, beam, nameAbs, nameOrd );
337  //     else {
338  //    GWt_dialog warningBeamState(" graphical analysis", "the beam state does not allow providing a drawing with macroparticles !", GWt_dialog::Error, false,true);
339  //    warningBeamState.exec();
340  //     }
341  //   }
342  // else {
343  //   GWt_dialog warningTypeDrawing(" graphical analysis", "type of  drawing not programmed !", GWt_dialog::Error, false,true);
344  //   warningTypeDrawing.exec();
345  // }
346}
347
348void GWt_accelerator::dessinerEnveloppe()
349{
350  toto_->clear();
351 
352  int typeEnveloppe = choixEnveloppeDessin_->currentIndex();
353  if ( typeEnveloppe == 0 )
354  {
355    faireDessinEnveloppe(toto_, "x");
356  }
357  else {
358    GWt_dialog warningTypeEnveloppe(" graphical analysis", "type of enveloppe drawing not programmed !", GWt_dialog::Error, false,true);
359    warningTypeEnveloppe.exec();
360  }
361}
362
363void GWt_accelerator::faireDessinEnveloppe(WContainerWidget* toto, string type)
364{
365 
366  std::time_t result = std::time(NULL);
367 
368  GWt_dialog* envDialog = new GWt_dialog(WString("enveloppe&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(")+std::asctime(std::localtime(&result))+")",toto,false);
369  eDialog_.push_back(envDialog);
370  envDialog->setMinimumSize(400,400);
371  envDialog->setClosable(true);
372  envDialog->show();
373 
374  //  unsigned nbel = dtmanage_->getBeamLineSize();
375  vector<double> xcor;
376  vector<double> ycor;
377  string titre;
378  string legendx;
379  string legendy;
380  dataManager_->donneesRmsEnveloppe(type,xcor,ycor,titre,legendx,legendy);
381 
382  Wt::Chart::SeriesType seriesType = Wt::Chart::LineSeries;
383  Wt::Chart::FillRangeType fillRange = Wt::Chart::NoFill;
384  Wt::Chart::AxisValue location = Wt::Chart::ZeroValue;
385  bool isGridLinesEnabled = false;
386  chartPlot2vec(envDialog->contents(),xcor,ycor,seriesType,fillRange,location,isGridLinesEnabled,titre,legendx,legendy,500,300);
387}
388
389void GWt_accelerator::faireDessinPhaseSpace(WContainerWidget* toto, particleBeam* beam, string elementLabel, string namex, string namey, int typeFaisceau)
390{
391 
392  vector<double> xcor;
393  vector<double> ycor;
394  vector<string> legende;
395  string titre;
396  Wt::Chart::SeriesType seriesType;
397 
398  if ( typeFaisceau == 0 ) {
399    seriesType = Wt::Chart::LineSeries;
400    titre = "phase space rms";
401    beam->donneesDessinEllipse(xcor,ycor,legende,namex,namey);
402  } else if (  typeFaisceau == 1 ) {
403    seriesType = Wt::Chart::PointSeries;
404    titre = " phase space ";
405    beam->particlesPhaseSpaceData(xcor,ycor,legende,namex,namey);
406    // for ( int kk=0; kk < xcor.size(); kk++)
407    //   {
408    //  cout << " dess. phas. x= " << xcor.at(kk) << " x'= " << ycor.at(kk) << endl;
409    //   }
410  } else {
411    GWt_dialog warningBeamState(" graphical analysis", "the beam state does not allow providing a drawing with macroparticles !", GWt_dialog::Error, false,true);
412    warningBeamState.exec();
413    return;
414  }
415 
416  std::time_t result = std::time(NULL);
417  GWt_dialog* phaseSpaceDialog = new GWt_dialog(WString("phase space&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(")+std::asctime(std::localtime(&result))+")",toto,false);
418  eDialog_.push_back(phaseSpaceDialog);
419  phaseSpaceDialog->setMinimumSize(400,400);
420  phaseSpaceDialog->setClosable(true);
421  new WText(" case : " + nameOfCase_, phaseSpaceDialog->contents());
422  new WBreak(phaseSpaceDialog->contents());
423  new WText(" after element :  " + elementLabel, phaseSpaceDialog->contents());
424 
425  for (int k=0 ; k < (int)legende.size(); k++) {
426    new WBreak(phaseSpaceDialog->contents());
427    new WText(legende.at(k), phaseSpaceDialog->contents());
428  }
429 
430  Wt::Chart::FillRangeType fillRange = Wt::Chart::NoFill;
431  Wt::Chart::AxisValue location = Wt::Chart::ZeroValue;
432  bool isGridLinesEnabled = false;
433  chartPlot2vec(phaseSpaceDialog->contents(),xcor,ycor,seriesType,fillRange,location,isGridLinesEnabled,titre,namex,namey,500,300);
434 
435  phaseSpaceDialog->show();
436}
437
438
439void GWt_accelerator::dessinerHistogramme()
440{
441  toto_->clear();
442 
443  // std::time_t result = std::time(NULL);
444  // GWt_dialog* histoDialog = new GWt_dialog(WString("histogramme&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(")+std::asctime(std::localtime(&result))+")",toto_,false);
445  // eDialog_.push_back(histoDialog);
446  // histoDialog->setMinimumSize(400,400);
447  // histoDialog->setClosable(true);
448 
449  string elementLabel = choixHistoDessin_->currentText().toUTF8();
450  particleBeam* beam = dataManager_->getDiagnosticBeam_deprecated(elementLabel);
451  if (beam == NULL) {
452    GWt_dialog warningBeamState("histogram","the beam does not exist at the end of this element !", GWt_dialog::Error, false,true);
453    warningBeamState.exec();
454    return;
455  }
456 
457  if (!beam->particleRepresentationOk()) {
458    GWt_dialog warningBeamState("histogram", "the beam state does not allow providing a drawing with macroparticles !", GWt_dialog::Error, false,true);
459    warningBeamState.exec();
460    return;
461  }
462 
463  unsigned iabs= choixVariableHisto_->currentIndex();
464  vector<double> xcor;
465  vector<int> hist;
466  //  double out[3]= {0.0};
467  vector<string> legende;
468  beam->histogramme(iabs,xcor,hist,legende);
469 
470  cout<<"xcor.size()= "<<xcor.size()<<", hist.size()= "<<hist.size()<<endl;
471  //////////////////////////////////////////////////////////////////////////////////
472 
473  int n = hist.size();
474  vector<double> x;
475  x.resize(2*n+2);
476  vector<double> y;
477  y.resize(2*n+2);
478 
479  int j= 0;
480  x.at(j)= xcor[0];
481  y.at(j)= 0.0;
482  j++;
483  x.at(j)= xcor[0];
484  y.at(j)= hist[0];
485  j++;
486 
487  for (int i = 1; i < n; ++i) {
488    x.at(j)= xcor[i];
489    y.at(j)= hist[i-1];
490    j++;
491    x.at(j)= xcor[i];
492    y.at(j)= hist[i];
493    j++;
494  }
495 
496  x.at(j)= xcor[n];
497  y.at(j)= hist[n-1];
498  j++;
499  x.at(j)= xcor[n];
500  y.at(j)= 0.0;
501  //////////////////////////////////////////////////////////////////////////////////
502  std::time_t result = std::time(NULL);
503  GWt_dialog* histoDialog = new GWt_dialog(WString("histogramme&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(")+std::asctime(std::localtime(&result))+")",toto_,false);
504  eDialog_.push_back(histoDialog);
505  histoDialog->setMinimumSize(400,400);
506  histoDialog->setClosable(true);
507 
508  histoDialog->show();
509 
510  WContainerWidget *w= histoDialog->contents();
511 
512  // // legendes
513  // string unites[2];
514  // if(iabs == 0 || iabs == 1 || iabs == 2) {
515  //   unites[0]= unites[1]= " mm";
516  // }
517  // if(iabs == 3 || iabs == 4) {
518  //   unites[0]= unites[1]= " mrad";
519  // }
520  // if(iabs == 5) {
521  //   unites[0]= " MeV"; unites[1]= " KeV";
522  // }
523 
524  new WText(" case : " + nameOfCase_, w);
525  new WBreak(w);
526  new WText(" after element :  " + elementLabel, w);
527 
528  for (int k=0 ; k < (int)legende.size(); k++) {
529    new WBreak(w);
530    new WText(legende.at(k), w);
531  }
532 
533 
534  // new WText(" entries : "+ mixedTools::intToString((int)out[0]),w);
535  // new WBreak(w);
536  // new WText(" mean : "+ mixedTools::doubleToString(out[1])+unites[0],w);
537  // new WBreak(w);
538  // new WText(" sigma rms : "+ mixedTools::doubleToString(out[2])+unites[1],w);
539  //////////////////////////////////////////////////////////////////////////////////
540 
541  string titre;
542  if(iabs == 0) titre="x-coordinate";
543  if(iabs == 1) titre="y-coordinate";
544  if(iabs == 2) titre="z-coordinate";
545  if(iabs == 3) titre="xp-divergence";
546  if(iabs == 4) titre="yp-devergence";
547  if(iabs == 5) titre="kinetic energy";
548 
549  string xname;
550  if(iabs == 0) xname=" x (mm)";
551  if(iabs == 1) xname=" y (mm)";
552  if(iabs == 2) xname=" z (mm)";
553  if(iabs == 3) xname=" xp (mrad)";
554  if(iabs == 4) xname=" yp (mrad)";
555  if(iabs == 5) xname=" dEcin/Ecin (%)";
556 
557  string yname;
558  Wt::Chart::SeriesType seriesType = Wt::Chart::LineSeries;
559  Wt::Chart::FillRangeType fillRange = Wt::Chart::ZeroValueFill;
560  Wt::Chart::AxisValue location = Wt::Chart::MinimumValue;
561  bool isGridLinesEnabled = true;
562  chartPlot2vec(w,x,y,seriesType,fillRange,location,isGridLinesEnabled,titre,xname,yname,500,300);
563}
564
565
566
567void GWt_accelerator::chartPlot2vec(WContainerWidget* toto,vector<double>& xcor,vector<double>& ycor,Wt::Chart::SeriesType seriesType,Wt::Chart::FillRangeType fillRange,Wt::Chart::AxisValue value,bool isGridLinesEnables,string title,string legendx,string legendy,int width,int height,bool makeIcon)
568{
569  int nbpts = xcor.size();
570  cout << " PspaApplication::chartPlot2vec nbpts = " << nbpts << endl;
571 
572  WStandardItemModel *model = new WStandardItemModel(nbpts, 2, toto);
573  for (int i = 0; i < nbpts; ++i) {
574    model->setData(i, 0, xcor.at(i));
575    model->setData(i, 1, ycor.at(i));
576    //        cout << " PspaApplication::chartPlot2vec el= " << i+1 << " x= " << xcor.at(i) << " y= " << ycor.at(i) << endl;
577  }
578  //  cout << " PspaApplication::chartPlot2vec FLAG 0 " << endl;
579  Wt::Chart::WCartesianChart *chart = new Wt::Chart::WCartesianChart(toto);
580  if (!makeIcon) chart->setTitle(title);
581  chart->initLayout();
582  chart->setModel(model);        // set the model
583  chart->setXSeriesColumn(0);    // set the column that holds the X data
584 
585  chart->setType(Wt::Chart::ScatterPlot);   // set type to ScatterPlot
586  chart->setLegendEnabled(false); // enable the legend
587 
588  // Provide space for the X and Y axis and title.
589  chart->setPlotAreaPadding(80, Left);
590  chart->setPlotAreaPadding(40, Bottom);
591  chart->setPlotAreaPadding(60, Top);
592 
593  // Typically, for mathematical functions, you want the axes to cross
594  // at the 0 mark (value= ZeroValue)
595  chart->axis(Wt::Chart::XAxis).setLocation(value);
596  chart->axis(Wt::Chart::YAxis).setLocation(value);
597 
598  //  cout << " PspaApplication::chartPlot2vec FLAG 1 " << endl;
599 
600  Wt::Chart::WDataSeries s(1,seriesType);
601  s.setPen(WColor("red"));
602  s.setFillRange(fillRange);
603  chart->addSeries(s);
604 
605  Wt::Chart::WAxis& axis = chart->axis(Wt::Chart::XAxis);
606  axis.setLabelFormat("%.3f");
607  axis.setTitle(legendx);
608 
609  chart->axis(Wt::Chart::Y1Axis).setTitle(legendy);
610 
611  if(isGridLinesEnables) {
612    axis.setGridLinesEnabled(true);
613    chart->axis(Wt::Chart::Y1Axis).setGridLinesEnabled(true);
614  }
615  //   cout << " PspaApplication::chartPlot2vec FLAG 2 " << endl;
616 
617  chart->resize(width,height); // WPaintedWidget must be given explicit size
618  chart->setMargin(10, Top | Bottom); // ?
619  chart->setMargin(WLength::Auto, Left | Right); //?
620 
621  if (makeIcon) {
622    chart->setLegendEnabled(false); // enable the legend
623    chart->setPlotAreaPadding(0);
624    chart->setAxisPadding(0);
625    WFont xAxisFont = chart->axis(Wt::Chart::XAxis).labelFont();
626    xAxisFont.setSize(8);
627    WFont yAxisFont = chart->axis(Wt::Chart::YAxis).labelFont();
628    yAxisFont.setSize(8);
629    chart->axis(Wt::Chart::XAxis).setLabelFont(xAxisFont);
630    chart->axis(Wt::Chart::YAxis).setLabelFont(yAxisFont);
631  }
632  //  cout << " PspaApplication::chartPlot2vec FLAG 3 " << endl;
633 
634#ifdef HAS_IMAGEMAGIC
635 
636  //  cout << " PspaApplication::chartPlot2vec FLAG MAGIC " << endl;
637 
638  // no background
639  chart->setBackground(WBrush(Wt::NoBrush));
640 
641  // axis black
642  chart->axis(XAxis).setPen(WColor("black"));
643  chart->axis(YAxis).setPen(WColor("black"));
644 
645  std::string name;
646  /*
647   Wt::WRasterImage pngImage("png", 1000, 1000);
648   Wt::WPainter p(&pngImage);
649   chart->paint(p);
650   name = workingDir_ + "/chart-"+sessionId ()+".png";
651   std::ofstream f(name.c_str(), std::ios::out |std::ios::trunc | std::ios::binary);
652   pngImage.write(f);
653   */
654 
655  Wt::WPdfImage pdfImage("1000", "600");
656  {
657    Wt::WPainter p1(&pdfImage);
658    chart->paint(p1);
659  }
660 
661  name = workingDir_ + "/chart-"+sessionId ()+".pdf";
662  std::ofstream f1(name.c_str(), std::ios::out | std::ios::binary);
663  pdfImage.write(f1);
664 
665  new WText("<a href='workingArea/chart-"+sessionId ()+".pdf' target='_blank'>Sauvegarder l'image</a>",toto);
666 
667#endif
668  //  cout << " PspaApplication::chartPlot2vec FLAG FIN" << endl;
669 
670}
671
672
673bool GWt_accelerator::areDataCoherent()
674{
675  // FIXME
676  cout << "***********************************" << endl;
677  cout << "**  To be move in controler  **" << endl;
678  cout << "***********************************" << endl;
679  return true;
680#if BAVARD > 0
681  cout << "***********************************" << endl;
682  cout << " GWt_softwarePanel::areDataCoherent() " << endl<<endl;
683#endif
684 
685  bool caMarche = true;
686  /*
687   // initialize dataManager
688   dtmanage_->initializeExecution();
689   
690   // intialize User Interface
691   if (pspa_->getBeamLine_deprecated()) {
692   pspa_->getBeamLine_deprecated()->initializeSoftwares();
693   }
694   
695   string diagnosticErrors;
696   string diagnosticWarnings;
697   for (int a = 0; a < sections_.size(); a++)
698   {
699   string debString= sections_[a]->getFirstElementCurrentText().toUTF8();
700   string finString= sections_[a]->getLastElementCurrentText().toUTF8();
701   int debut = pspa_->getBeamLine_deprecated()->getAbstractElementNumeroFromLabel(debString);
702   int fin = pspa_->getBeamLine_deprecated()->getAbstractElementNumeroFromLabel(finString);
703   
704   string currentSoft= sections_[a]->getSoftwareCurrentText().toUTF8();
705   nomDeLogiciel prog = nomDeLogiciel(currentSoft);
706   sectionToExecute* sectToExec = dtmanage_->addSectionToExecute(pspa_->getBeamLine_deprecated()->getAbstractElement(debut),debut,pspa_->getBeamLine_deprecated()->getAbstractElement(fin),fin,prog);
707   
708   abstractSoftware* softToExec = sectToExec->getSoftware();
709   diagnosticErrors = "";
710   diagnosticWarnings = "";
711   for(int i = debut-1; i < fin; i++) // check sections
712   {
713   if (!pspa_->getBeamLine_deprecated()) continue;
714   abstractElement* elPtr= pspa_->getBeamLine_deprecated()->getAbstractElement(i);
715   if (!elPtr) continue;
716   
717   trivaluedBool tb = softToExec->doAcceptElement(elPtr->getNomdElement().getElementType());
718   cout << " GWt_softwarePanel::areDataCoherent() el " << elPtr->getLabel() << " tb= " << tb << endl;
719   if (tb  == TBoolOk ) {
720   elPtr->setSoftware(softToExec);
721   } else {
722   elPtr->setSoftware(NULL);
723   if (tb == TBoolIgnore) {
724   if(prog.getString() != "unknownSoftware") diagnosticWarnings += elPtr->getLabel() + " will be ignored by  "+ prog.getString() + "<br /> ";
725   } else {
726   // j'insiste pour remettre le nom generique de l'element refuse (glm / 30/03/2013)
727   diagnosticErrors += elPtr->getNomdElement().getExpandedName() + " is not allowed with " + prog.getString() + "<br /> ";
728   caMarche = false;
729   }
730   }
731   pspa_->getBeamLine_deprecated()->update(i);
732   } //i
733   
734   // set errors and warnings
735   sections_[a]->setErrors(diagnosticErrors);
736   sections_[a]->setWarnings(diagnosticWarnings);
737   }//a
738   */
739  return caMarche;
740}
741
Note: See TracBrowser for help on using the repository browser.