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