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

Last change on this file since 469 was 469, checked in by garnier, 11 years ago

Désormais il est de nouveau possible d'ajouter des sections et dy affecter des softwares (ne marche pour le moment quavec la 1ere sectionToExecute. Autres améliorations et renommages

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