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

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

update de la visu

File size: 16.6 KB
Line 
1#include <stdio.h>
2#include <string.h>
3#include <stdlib.h>
4#include <vector>
5
6#include <Wt/WLineEdit>
7#include <Wt/WText>
8#include <Wt/WGridLayout>
9#include <Wt/WVBoxLayout>
10#include <Wt/WHBoxLayout>
11#include <Wt/WImage>
12#include <Wt/WMenu>
13#include <Wt/WStackedWidget>
14//#include <Wt/WTextArea>
15#include <Wt/WBreak>
16#include <Wt/WStandardItemModel>
17#include <Wt/Chart/WCartesianChart>
18
19#include "GWt_pspaApplication.h"
20#include "GWt_LigneFaisceau.h"
21#include "GWt_globalParameters.h"
22#include "bareParticle.h"
23#include "nomDeLogiciel.h"
24#include "mixedTools.h"
25
26using namespace Wt::Chart;
27
28
29
30
31/*
32 * The env argument contains information about the new session, and
33 * the initial request. It must be passed to the WApplication
34 * constructor so it is typically also an argument for your custom
35 * application constructor.
36*/
37
38
39WWidget* PspaApplication::createPalette()
40{
41  WContainerWidget* palette=new WContainerWidget();
42  //  palette->setLayout(new WVBoxLayout());
43
44  createDragImage("icons/drift.jpg",
45                  "icons/drift.jpg","icons/drift.jpg", palette,"drift");
46  new WBreak(palette);
47
48  createDragImage("icons/cell.jpg",
49                  "icons/cell.jpg","icons/cell.jpg", palette,"cell");
50  new WBreak(palette);
51
52  createDragImage("icons/beam.jpg",
53                  "icons/beam.jpg","icons/beam.jpg", palette,"beam");
54  new WBreak(palette);
55
56  createDragImage("icons/bend.jpg",
57                  "icons/bend.jpg","icons/bend.jpg", palette,"bend");
58  new WBreak(palette);
59
60  createDragImage("icons/final.jpg",
61                  "icons/final.jpg","icons/final.jpg", palette,"final");
62  new WBreak(palette);
63
64  createDragImage("icons/lens.jpg",
65                  "icons/lens.jpg","icons/lens.jpg", palette,"lens");
66  new WBreak(palette);
67
68  palette->setMinimumSize(100,300);
69
70  return palette;
71}
72
73WWidget* PspaApplication::createBeamLine()
74{
75  WContainerWidget* beamLine=new GWt_LigneFaisceau(this);
76  beamLine->setMinimumSize(300,100);
77  return beamLine;
78}
79
80WWidget* PspaApplication::createGlobalParamWidget()
81{
82   WContainerWidget* globalParam =new GWt_globalParameters(this);
83  globalParam->setMaximumSize(600,150);
84  globalParam->setMinimumSize(600,150);
85  return globalParam;
86}
87
88WWidget* PspaApplication::createExecuteWidget()
89{
90
91  WContainerWidget* executeW =new WContainerWidget();
92
93
94  //   WVBoxLayout* executeLayout = new WVBoxLayout();
95
96  //  executeW->decorationStyle().setBackgroundColor (WColor("yellow"));
97  executeW->setMaximumSize(600,150);
98  executeW->setMinimumSize(600,150);
99
100 
101
102
103    //    executeLayout->addWidget(boutonGo);
104
105  // bouton execute
106    exec_go_ = new WPushButton("execute!");
107    //    exec_go_->setMinimumSize(300,300);
108    exec_go_->setDisabled(true);
109    exec_go_->clicked().connect(this, &PspaApplication::executer);
110  // preparation du bouton add
111  WPushButton* exec_add = new WPushButton("add");
112  exec_add->clicked().connect(this, &PspaApplication::addSectionToExecuteW);
113
114  // preparation du bouton delete
115  WPushButton* exec_delete = new WPushButton("delete");
116  exec_delete->clicked().connect(this, &PspaApplication::deleteSectionToExecuteW);
117
118  // preparation du bouton push_ok
119  WPushButton* exec_ok = new WPushButton("check/ok");
120  exec_ok->clicked().connect(this, &PspaApplication::checkSectionSelection);
121
122
123  // le panel
124  WPanel *panelLogiciels = new WPanel(executeW);
125  panelLogiciels->setTitle(" sections of beam Line for executing softwares ");
126
127  contenuSections_ = new WContainerWidget();
128
129  contenuSections_->addWidget( exec_add);
130  contenuSections_->addWidget( exec_delete);
131  contenuSections_->addWidget( exec_ok);
132    contenuSections_->addWidget(exec_go_);
133  contenuSections_->addWidget(new WBreak());
134  contenuSections_->addWidget(new WBreak());
135    addSectionToExecuteW();
136
137  panelLogiciels->setCentralWidget(contenuSections_);
138  //executeLayout->addWidget(executeW);
139
140  //    executeW->setLayout(executeLayout);
141
142
143  return executeW;
144}
145
146void PspaApplication::addSectionToExecuteW()
147{
148  unsigned k;
149  string premierText, dernierText;
150
151  disableSectionExecute();
152
153
154  if ( selectedSections_.size() == 0)
155    {
156      premierText = "1";
157      dernierText = mixedTools::intToString( dtmanage_->beamLineSize() );
158    }
159  else 
160    {
161      dernierText = selectedSections_.back()->fin->text().toUTF8();
162      int dernierNumero = atoi(dernierText.c_str());
163      dernierNumero++;
164      if ( dernierNumero <= dtmanage_->beamLineSize() )
165        {
166          premierText = mixedTools::intToString(dernierNumero);   
167          dernierText = premierText;
168        }
169      else 
170        {
171          premierText = mixedTools::intToString( dtmanage_->beamLineSize() );
172          dernierText = premierText;
173        }
174    }
175
176
177  WContainerWidget* newSection = new WContainerWidget;
178
179  selectedSections_.push_back(new GWt_sectionToExecute);
180  selectedSections_.back()->debut = new WLineEdit();
181  selectedSections_.back()->debut->setDisabled(true);
182  selectedSections_.back()->debut->setText(premierText);
183
184  selectedSections_.back()->fin = new WLineEdit();
185  selectedSections_.back()->fin->changed().connect(this, &PspaApplication::disableSectionExecute);
186
187  selectedSections_.back()->fin->setText(dernierText);
188  selectedSections_.back()->selection = new WComboBox();
189
190  selectedSections_.back()->ligneDeWidget = newSection;
191
192
193  // contenuSections_->addWidget(new WText(" from : "));
194  // contenuSections_->addWidget(selectedSections_.back()->debut);
195  // contenuSections_->addWidget(new WText(" to : "));
196  // contenuSections_->addWidget(selectedSections_.back()->fin);
197  // contenuSections_->addWidget(selectedSections_.back()->selection);
198
199  //  newSection->addWidget(new WBreak());
200  newSection->addWidget(new WText(" from : "));
201  newSection->addWidget(selectedSections_.back()->debut);
202  newSection->addWidget(new WText(" to : "));
203  newSection->addWidget(selectedSections_.back()->fin);
204  newSection->addWidget(selectedSections_.back()->selection);
205
206
207    contenuSections_->addWidget(newSection);
208
209
210  unsigned nb = nomDeLogiciel::getNumberOfSoftwares();
211  for ( k=0; k < nb; k++) selectedSections_.back()->selection->addItem( nomDeLogiciel(k).getString() );
212}
213
214
215void PspaApplication::disableSectionExecute()
216{
217    exec_go_->setDisabled(true);
218}
219
220void PspaApplication::checkSectionSelection()
221{
222  if ( selectedSections_.empty() ) return;
223
224  // traitement de la premiere ligne
225  (*selectedSections_.begin())->debut->setText("1");
226  string currentString =  (*selectedSections_.begin())->fin->text().toUTF8();
227  int current = atoi ( currentString.c_str() );
228  if ( current <= 0 ) 
229    {
230      (*selectedSections_.begin())->fin->setText("1");
231      current = 1;
232    }
233  current++;
234  if ( current > dtmanage_->beamLineSize() ) current = dtmanage_->beamLineSize();
235  currentString = mixedTools::intToString(current);
236   
237
238  // traitement des suivantes (on avance d'un cran dans la liste)
239  list<GWt_sectionToExecute*>::iterator itr, itr0;
240  itr0= selectedSections_.begin();
241  itr0++;
242  for (itr= itr0; itr != selectedSections_.end(); itr++)
243    {
244      //      string debString = (*itr)->debut->text().toUTF8();
245      // debut
246      (*itr)->debut->setText(  currentString );
247      // fin
248      string finString =  (*itr)->fin->text().toUTF8();
249      if ( atoi(finString.c_str() ) < current)
250        {
251          (*itr)->fin->setText(  currentString );
252        }
253
254      // preparation de la ligne suivante
255      finString =  (*itr)->fin->text().toUTF8();
256      current = atoi(finString.c_str()) +1;
257      if ( current > dtmanage_->beamLineSize() ) current = dtmanage_->beamLineSize();
258      currentString = mixedTools::intToString(current);
259    }
260  exec_go_->setDisabled(false);
261}
262
263void PspaApplication::deleteSectionToExecuteW()
264{
265  if ( selectedSections_.empty() ) return;
266  disableSectionExecute();
267  selectedSections_.back()->ligneDeWidget->clear();
268  delete selectedSections_.back()->ligneDeWidget;
269  selectedSections_.pop_back();
270}
271
272PspaApplication::PspaApplication(const WEnvironment& env)
273  : WApplication(env)
274{
275  setTitle("portail PSPA");                               // application title
276
277
278  if (wApp->environment().javaScript()) {
279
280    WContainerWidget *w = root();
281
282    w->setStyleClass("PSPA");
283
284    dtmanage_ = new dataManager();
285
286    /*
287     * The main layout is a 3x2 grid layout.
288     */
289    WGridLayout *layout = new WGridLayout();
290    layout->addWidget(createTitle("Menu (In future)"), 0, 0, 1, 2);
291
292    WHBoxLayout *toolbarLayout = new WHBoxLayout();
293    WPushButton* boutonSauve = new WPushButton(" sauvegarder la config");
294    WPushButton* boutonRestaure = new WPushButton(" restaurer la config");
295    boutonSauve->setMinimumSize(30,30);
296    boutonRestaure->setMinimumSize(30,30);
297
298    toolbarLayout->addWidget(boutonSauve , 1);
299    toolbarLayout->addWidget(boutonRestaure , 1);
300    boutonSauve->clicked().connect(this, &PspaApplication::sauver);
301    boutonRestaure->clicked().connect(this, &PspaApplication::restaurer);
302    layout->addLayout(toolbarLayout, 1, 0, 1, 2);
303
304    //    layout->addWidget(createPalette(), 2, 0, 2, 1);
305    layout->addWidget(createPalette(), 2, 0, 4, 1);
306
307    beamLine_ = createBeamLine();
308    layout->addWidget(beamLine_, 2, 1, 1, 1);
309
310    console_ = new WTextArea();
311    console_->setMaximumSize(600,200);
312    layout->addWidget(console_, 3, 1);
313    console_->setMinimumSize(300,100);
314
315
316    //-----------
317    // A supprimer et a mettre en fenetre
318    globalParam_ = createGlobalParamWidget();
319    leDessin_ = new WContainerWidget();
320    WWidget* executeWidget = createExecuteWidget();
321   
322    layout->addWidget( globalParam_, 4, 1);
323    layout->addWidget( leDessin_, 5, 1);
324    layout->addWidget( executeWidget , 5, 1);
325    //-----------
326
327
328
329    layout->setColumnResizable(1);
330    layout->setRowResizable(2);
331    /*
332     * Let row 2 and column 1 take the excess space.
333     */
334    layout->setRowStretch(2, 1);
335    layout->setColumnStretch(1, 1);
336
337    w->setLayout(layout);
338
339
340    dtmanage_ = new dataManager();
341
342
343
344
345  } else {
346    new WText("<i>This examples requires that javascript support is enabled.</i>",root());
347  }
348
349}
350
351void PspaApplication::createDragImage(const char *url, const char *smallurl,
352                        const char *mimeType,
353                                      WContainerWidget *p,WString name)
354{
355  WImage *result = new WImage(url,name,p);
356  WImage *dragImage = new WImage(smallurl,name, p);
357
358  /*
359   * Set the image to be draggable, showing the other image (dragImage)
360   * to be used as the widget that is visually dragged.
361   */
362  //  printf(" setDraggable %s \n",mimeType);
363  result->setDraggable(mimeType, dragImage, true);
364
365}
366
367
368// void PspaApplication::executer()
369// {
370//   addConsoleMessage(string("on va peut etre y arriver"));
371//   static_cast<GWt_globalParameters*>(globalParam_)->updateGlobals();
372
373//   int debut, fin;
374//   nomDeLogiciel prog;
375//   dtmanage_->clearSectionToExecute();
376//   list<GWt_sectionToExecute*>::iterator itr;
377//   for (itr= selectedSections_.begin(); itr != selectedSections_.end(); itr++)
378//     {
379//       string debString = (*itr)->debut->text().toUTF8();
380//       string finString = (*itr)->fin->text().toUTF8();
381//       debut = atoi( debString.c_str()  );
382//       fin = atoi(  finString.c_str() );
383//       prog = nomDeLogiciel ( (*itr)->selection->currentIndex() );
384//       dtmanage_->addSectionToExecute(debut, fin, prog);
385//     }
386
387//   string resultat = dtmanage_->executeAll();
388//   addConsoleMessage(resultat);
389//   faireDessin();
390// }
391
392void PspaApplication::executer()
393{
394  addConsoleMessage(string("on va peut etre y arriver"));
395  static_cast<GWt_globalParameters*>(globalParam_)->updateGlobals();
396
397  int debut, fin;
398  nomDeLogiciel prog;
399  list<GWt_sectionToExecute*>::iterator itr;
400  dtmanage_->initializeExecution();
401  for (itr= selectedSections_.begin(); itr != selectedSections_.end(); itr++)
402    {
403      string debString = (*itr)->debut->text().toUTF8();
404      string finString = (*itr)->fin->text().toUTF8();
405      debut = atoi( debString.c_str()  );
406      fin = atoi(  finString.c_str() );
407      prog = nomDeLogiciel ( (*itr)->selection->currentIndex() );
408      cout << " PspaApplication::executer() on lance l'execution de : " << prog.getString() << endl;
409      string resul;
410        if ( prog == nomDeLogiciel::parmela ) 
411          {
412            resul = dtmanage_->executeParmela( debut, fin);
413                    faireDessin();
414            addConsoleMessage(resul);
415          }
416        else if ( prog == nomDeLogiciel::transport ) 
417          {
418            resul = dtmanage_->executeTransport( debut, fin);
419            faireDessinTransport();
420            addConsoleMessage(resul);
421          }
422        else 
423          {
424            resul =  " unknown software -- STOP \n ";   
425            addConsoleMessage(resul);
426            break;
427          }
428    }
429}
430
431
432void PspaApplication::sauver()
433{
434  cout << " on sauve " << endl;
435  addConsoleMessage("sauvegarde");
436  GWt_globalParameters* bibi = static_cast<GWt_globalParameters*>(globalParam_);
437  bibi->updateGlobals();
438  dtmanage_->saveAll();
439
440}
441
442void PspaApplication::restaurer()
443{
444
445  addConsoleMessage(string("restauration..."));
446
447  dtmanage_->restoreAll();
448
449  GWt_globalParameters* bibi = static_cast<GWt_globalParameters*>(globalParam_);
450  bibi->renew();
451
452  GWt_LigneFaisceau* bobo = static_cast<GWt_LigneFaisceau*>(beamLine_);
453
454  bobo->restoreElementCollection();
455  addConsoleMessage(string("...terminee"));
456}
457
458
459
460void PspaApplication::faireDessin()
461{
462  WContainerWidget* toto = leDessin_;
463  toto->clear();
464       new WText("emittance", toto);
465  vector<bareParticle>& partic = dtmanage_->getCurrentBeam().getParticleVector();
466
467
468  WStandardItemModel *model = new WStandardItemModel(partic.size(), 3, toto);
469  //    model->setHeaderData(0, WString("X"));
470  //   model->setHeaderData(1, WString("Y = sin(X)"));
471
472
473  for (unsigned i = 0; i < partic.size(); ++i) {
474    double x= partic.at(i).getPosition().getComponent(0);
475    double begamz = partic.at(i).getBetaGamma().getComponent(2);
476    double xp = partic.at(i).getBetaGamma().getComponent(0)/begamz;
477    //    cout << "x = " << x << " xp= " << xp << endl;
478    model->setData(i, 0, 10*x);
479    model->setData(i, 1,1.e3*xp);
480    model->setData(i, 2,2.e3*xp);
481  }
482
483  WCartesianChart *chart = new WCartesianChart(toto);
484  chart->setModel(model);        // set the model
485  chart->setXSeriesColumn(0);    // set the column that holds the X data
486  chart->setLegendEnabled(true); // enable the legend
487
488  chart->setType(ScatterPlot);   // set type to ScatterPlot
489
490  // Typically, for mathematical functions, you want the axes to cross
491  // at the 0 mark:
492   chart->axis(XAxis).setLocation(ZeroValue);
493   chart->axis(YAxis).setLocation(ZeroValue);
494
495  // Provide space for the X and Y axis and title.
496  chart->setPlotAreaPadding(80, Left);
497  chart->setPlotAreaPadding(40, Top | Bottom);
498  // Add the curves
499  WDataSeries s(1, PointSeries, Y1Axis);
500  //  s.setShadow(WShadow(3, 3, WColor(0, 0, 0, 127), 3));
501  //    s.setMarker(SquareMarker);
502  //  s.setMarkerSize(600.);
503  //  cout << "le marker est : " << s.marker() << endl;
504     chart->addSeries(s);
505
506  chart->resize(300, 300); // WPaintedWidget must be given explicit size
507
508  //  chart->setMargin(10, Top | Bottom);            // add margin vertically
509  //  chart->setMargin(WLength::Auto, Left | Right); // center horizontally
510}
511
512
513// void PspaApplication::addElemToGlobals()
514// {
515//   static_cast<GWt_globalParameters*>(globalParam_)->addElem();
516// }
517
518void PspaApplication::faireDessinTransport()
519{
520  WContainerWidget* toto = leDessin_;
521  toto->clear();
522  new WText("emittance transport", toto);
523
524  vector<double> xcor;
525  vector<double> ycor;
526  dtmanage_->getCurrentBeam().donneesDessinEllipseXxp(xcor,ycor);
527  int nbpts = xcor.size();
528  cout << " PspaApplication::faireDessinTransport() nbpts = " << nbpts << endl;
529  WStandardItemModel *model = new WStandardItemModel(nbpts, 2, toto);
530  for (int i = 0; i < nbpts; ++i) {
531    model->setData(i, 0, xcor.at(i));
532    model->setData(i, 1, ycor.at(i));
533  }
534
535  WCartesianChart *chart = new WCartesianChart(toto);
536  chart->setModel(model);        // set the model
537  chart->setXSeriesColumn(0);    // set the column that holds the X data
538  chart->setLegendEnabled(true); // enable the legend
539
540  chart->setType(ScatterPlot);   // set type to ScatterPlot
541
542  // Typically, for mathematical functions, you want the axes to cross
543  // at the 0 mark:
544   chart->axis(XAxis).setLocation(ZeroValue);
545   chart->axis(YAxis).setLocation(ZeroValue);
546
547  // Provide space for the X and Y axis and title.
548  chart->setPlotAreaPadding(80, Left);
549  chart->setPlotAreaPadding(40, Top | Bottom);
550  // Add the curves
551  WDataSeries s(1, CurveSeries, Y1Axis);
552     chart->addSeries(s);
553
554  chart->resize(300, 300); // WPaintedWidget must be given explicit size
555
556}
557
558
559
560
561void PspaApplication::updateSelections()
562{
563  string premierText, dernierText;
564  if ( selectedSections_.size() > 0 )
565    {
566      premierText = "1";
567      dernierText = mixedTools::intToString( dtmanage_->beamLineSize() );
568      (*selectedSections_.begin())->debut->setText(premierText);
569      (*selectedSections_.begin())->fin->setText(dernierText);
570    }
571
572}
573
574WText* PspaApplication::createTitle(const WString& title) {
575  WText *result = new WText(title);
576  result->setInline(false);
577  result->setStyleClass("title");
578  result->setMinimumSize(30,30);
579 
580  return result;
581}
Note: See TracBrowser for help on using the repository browser.