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