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