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