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