1 | #include <stdio.h> |
---|
2 | #include <ctime> |
---|
3 | |
---|
4 | #include "GWt_pspaApplication.h" |
---|
5 | #include "GWt_draggableImage.h" |
---|
6 | #include "GWt_abstractElementFactory.h" |
---|
7 | #include "GWt_serverFileSelector.h" |
---|
8 | #include "GWt_accelerator.h" |
---|
9 | #include "particleBeam.h" |
---|
10 | #include "bareParticle.h" |
---|
11 | #include "nomDeLogiciel.h" |
---|
12 | #include "mixedTools.h" |
---|
13 | #include "nomdElements.h" |
---|
14 | #include "environmentVariables.h" |
---|
15 | #include "trivaluedBool.h" |
---|
16 | |
---|
17 | #include <Wt/WGridLayout> |
---|
18 | #include <Wt/WVBoxLayout> |
---|
19 | #include <Wt/WHBoxLayout> |
---|
20 | #include <Wt/WImage> |
---|
21 | #include <Wt/WMenu> |
---|
22 | #include <Wt/WStackedWidget> |
---|
23 | #include <Wt/WBreak> |
---|
24 | #include <Wt/WStandardItemModel> |
---|
25 | #include <Wt/WFileUpload> |
---|
26 | #include <Wt/WPainter> |
---|
27 | #include <Wt/WScrollArea> |
---|
28 | #include <Wt/WRadioButton> |
---|
29 | #include <Wt/WMessageBox> |
---|
30 | #include <Wt/WScrollArea> |
---|
31 | #include <Wt/WLabel> |
---|
32 | |
---|
33 | #define HAS_IMAGEMAGIC 1 |
---|
34 | |
---|
35 | using namespace Wt::Chart; |
---|
36 | |
---|
37 | /* |
---|
38 | * The env argument contains information about the new session, and |
---|
39 | * the initial request. It must be passed to the WApplication |
---|
40 | * constructor so it is typically also an argument for your custom |
---|
41 | * application constructor. |
---|
42 | */ |
---|
43 | |
---|
44 | PspaApplication::PspaApplication(const WEnvironment& env) : |
---|
45 | WApplication(env), |
---|
46 | applicationDefaultTitle_("portail PSPA"), |
---|
47 | extensionFile_(0) |
---|
48 | { |
---|
49 | workingDir_ = WApplication::docRoot()+ "/"+WORKINGAREA; |
---|
50 | nameOfCase_ = "pspa"; // default |
---|
51 | |
---|
52 | setTitle(applicationDefaultTitle_); // application title |
---|
53 | if (!wApp->environment().javaScript()) { |
---|
54 | new WText("<i>This examples requires that javascript support is enabled.</i>",root()); |
---|
55 | } |
---|
56 | |
---|
57 | // register the absractElementFactory |
---|
58 | abstractElementFactory_ = new GWt_abstractElementFactory(); |
---|
59 | abstractElementFactory_->setRFGunEnable(true); |
---|
60 | abstractElementFactory_->setDriftEnable(true); |
---|
61 | abstractElementFactory_->setCellEnable(true); |
---|
62 | abstractElementFactory_->setBendEnable(true); |
---|
63 | abstractElementFactory_->setSolenoEnable(true); |
---|
64 | abstractElementFactory_->setBeamEnable(true); |
---|
65 | abstractElementFactory_->setFitEnable(true); |
---|
66 | abstractElementFactory_->setSnapshotEnable(true); |
---|
67 | abstractElementFactory_->setMPoleEnable(true); |
---|
68 | abstractElementFactory_->setQPoleEnable(true); |
---|
69 | abstractElementFactory_->setSPoleEnable(true); |
---|
70 | |
---|
71 | cout << " PspaApplication::PspaApplication abstractElementFactory REPUTEE CONSTRUITE " << endl; |
---|
72 | |
---|
73 | // include the styleSheetcd |
---|
74 | WContainerWidget *mainContainerWidget = root(); |
---|
75 | useStyleSheet("htdocs/pspa.css"); |
---|
76 | dtmanage_ = new dataManager(this); |
---|
77 | |
---|
78 | // The main layout is a 4x3 grid layout. |
---|
79 | WHBoxLayout *toolbarLayout = new WHBoxLayout(); |
---|
80 | |
---|
81 | WPushButton* boutonSauve = new WPushButton(); |
---|
82 | WPushButton* boutonRestaure = new WPushButton(); |
---|
83 | WPushButton* boutonLoadNew = new WPushButton(); |
---|
84 | WPushButton* boutonTrash = new WPushButton(); |
---|
85 | |
---|
86 | boutonSauve->setStyleClass("saveButton"); |
---|
87 | boutonRestaure->setStyleClass("restoreButton"); |
---|
88 | boutonLoadNew->setStyleClass("loadNewButton"); |
---|
89 | boutonTrash->setStyleClass("trashButton"); |
---|
90 | |
---|
91 | boutonSauve->setToolTip ("sauvegarder votre configuration"); |
---|
92 | boutonRestaure->setToolTip ("restaurer la configuration depuis le serveur"); |
---|
93 | boutonLoadNew->setToolTip ("charger une configuration"); |
---|
94 | boutonTrash->setToolTip ("supprimer l'accélerateur"); // FIXME ! a terminer |
---|
95 | |
---|
96 | boutonSauve->setMaximumSize(38,38); |
---|
97 | boutonSauve->setMinimumSize(38,38); |
---|
98 | boutonRestaure->setMaximumSize(38,38); |
---|
99 | boutonRestaure->setMinimumSize(38,38); |
---|
100 | boutonLoadNew->setMaximumSize(38,38); |
---|
101 | boutonLoadNew->setMinimumSize(38,38); |
---|
102 | boutonTrash->setMaximumSize(38,38); |
---|
103 | boutonTrash->setMinimumSize(38,38); |
---|
104 | |
---|
105 | boutonSauve->clicked().connect(this, &PspaApplication::sauver); |
---|
106 | boutonRestaure->clicked().connect(this, &PspaApplication::restaurer); |
---|
107 | // Upload when the button is clicked. React to a succesfull upload. |
---|
108 | boutonLoadNew->clicked().connect(this, &PspaApplication::openFileSelector); |
---|
109 | toolbarLayout->addWidget(boutonSauve , 0,Wt::AlignMiddle); |
---|
110 | toolbarLayout->addWidget(boutonRestaure , 0,Wt::AlignMiddle); |
---|
111 | toolbarLayout->addWidget(boutonLoadNew , 0,Wt::AlignMiddle); |
---|
112 | toolbarLayout->addWidget(boutonTrash , 0,Wt::AlignMiddle); |
---|
113 | toolbarLayout->addWidget(new WText("") , 1,Wt::AlignMiddle); |
---|
114 | |
---|
115 | WGridLayout* gridLayout = new WGridLayout(mainContainerWidget); |
---|
116 | |
---|
117 | WContainerWidget * toolbarLayoutContainer = new WContainerWidget(); |
---|
118 | toolbarLayoutContainer->setLayout(toolbarLayout); |
---|
119 | toolbarLayoutContainer->decorationStyle().setBackgroundImage ("/htdocs/fond_toolbar.png"); |
---|
120 | // menu menu on the top |
---|
121 | gridLayout->addWidget(toolbarLayoutContainer, 1,0,1,2); |
---|
122 | // palette on the left |
---|
123 | gridLayout->addWidget(createPalette(mainContainerWidget), 2, 0); |
---|
124 | |
---|
125 | // create accelerator main widget |
---|
126 | acceleratorContainerWidget_ = new WContainerWidget(); |
---|
127 | gridLayout->addWidget(acceleratorContainerWidget_, 2, 1); |
---|
128 | |
---|
129 | // Let column 2 take the excess space. |
---|
130 | gridLayout->setColumnStretch(1,1); |
---|
131 | // Let row 1 take the excess space. |
---|
132 | gridLayout->setRowStretch(2,1); |
---|
133 | |
---|
134 | |
---|
135 | // FIXME : Have to be move in GWt_accelerator |
---|
136 | createAccelerator(); |
---|
137 | |
---|
138 | // set auto scrollbar if needed |
---|
139 | mainContainerWidget->setOverflow(WContainerWidget::OverflowAuto); |
---|
140 | } |
---|
141 | |
---|
142 | |
---|
143 | void PspaApplication::createAccelerator() { |
---|
144 | new GWt_accelerator(acceleratorContainerWidget_,dtmanage_); |
---|
145 | new WBreak(acceleratorContainerWidget_); |
---|
146 | |
---|
147 | |
---|
148 | // --------------------------------------------------------------- |
---|
149 | // ********************* Ancien code : A supprimer *************** |
---|
150 | // --------------------------------------------------------------- |
---|
151 | |
---|
152 | /* |
---|
153 | WScrollArea* scroll = new WScrollArea(acceleratorContainerWidget_); |
---|
154 | scroll->setWidget(createBeamLine__deprecated()); |
---|
155 | scroll->setMinimumSize(300,150); |
---|
156 | */ |
---|
157 | |
---|
158 | new WBreak(acceleratorContainerWidget_); |
---|
159 | //----------- |
---|
160 | |
---|
161 | // A supprimer et a mettre en fenetre |
---|
162 | // xx globalParam_ = createGlobalParamWidget(); |
---|
163 | // xx mainGridLayout->addWidget(globalParam_,3,1); |
---|
164 | |
---|
165 | globalParam_ = new GWt_globalParameters(dtmanage_); |
---|
166 | sectorParam_ = new GWt_sectorParameters(); |
---|
167 | WWidget* dboard = createDashBoard(acceleratorContainerWidget_); |
---|
168 | dboard->setMinimumSize(300,100); |
---|
169 | |
---|
170 | new WBreak(acceleratorContainerWidget_); |
---|
171 | |
---|
172 | //----------- |
---|
173 | |
---|
174 | |
---|
175 | new WBreak(acceleratorContainerWidget_); |
---|
176 | |
---|
177 | console_ = new GWt_console(acceleratorContainerWidget_); |
---|
178 | console_->setMinimumSize(300,100); |
---|
179 | |
---|
180 | |
---|
181 | } |
---|
182 | |
---|
183 | WWidget* PspaApplication::createDashBoard(WContainerWidget* parent) |
---|
184 | { |
---|
185 | WContainerWidget *wt= new WContainerWidget(); |
---|
186 | wt->setStyleClass("text"); |
---|
187 | WText *st= new WText("Go ahead...",wt); |
---|
188 | |
---|
189 | WContainerWidget *buttons = new WContainerWidget(); |
---|
190 | buttons->setStyleClass("buttons"); |
---|
191 | WPushButton *button; |
---|
192 | button = new WPushButton("globalParameters",buttons); |
---|
193 | button->clicked().connect(this, &PspaApplication::messageBox1); |
---|
194 | button = new WPushButton("sectors", buttons); |
---|
195 | button->clicked().connect(this, &PspaApplication::messageBox2); |
---|
196 | |
---|
197 | styleSheet().addRule(".buttons","padding: 5px;"); |
---|
198 | styleSheet().addRule(".text", "padding: 4px 8px"); |
---|
199 | styleSheet().addRule("body", "margin: 0px;"); |
---|
200 | |
---|
201 | WContainerWidget *cnt = new WContainerWidget(); |
---|
202 | cnt->addWidget(buttons); |
---|
203 | cnt->addWidget(wt); |
---|
204 | |
---|
205 | WContainerWidget *result = new WContainerWidget(parent); |
---|
206 | WPanel *panel = new WPanel(result); |
---|
207 | panel->setTitle("dashboard"); |
---|
208 | panel->setCentralWidget(cnt); |
---|
209 | |
---|
210 | globalParam_->setText(st); |
---|
211 | sectorParam_->setText(st); |
---|
212 | return result; |
---|
213 | } |
---|
214 | |
---|
215 | void PspaApplication::messageBox1() |
---|
216 | { |
---|
217 | globalParam_->initilializeDialog(); |
---|
218 | return; |
---|
219 | } |
---|
220 | |
---|
221 | void PspaApplication::messageBox2() |
---|
222 | { |
---|
223 | sectorParam_->execDialog_deprecated(); |
---|
224 | return; |
---|
225 | } |
---|
226 | |
---|
227 | WWidget* PspaApplication::createPalette(WContainerWidget* parent) |
---|
228 | { |
---|
229 | WContainerWidget* palette = new WContainerWidget(parent); |
---|
230 | vector <GWt_abstractElement*> elems = abstractElementFactory_->getAllElements(); |
---|
231 | for (unsigned a = 0; a < elems.size(); a++) { |
---|
232 | elems[a]->createDragImage(palette); |
---|
233 | new WBreak(palette); |
---|
234 | } |
---|
235 | return palette; |
---|
236 | } |
---|
237 | |
---|
238 | void PspaApplication::createDragImage(const char *url,const char *smallurl,const char *mimeType,WContainerWidget *p,WString()) |
---|
239 | { |
---|
240 | GWt_draggableImage *result = new GWt_draggableImage(url,p); |
---|
241 | |
---|
242 | /* |
---|
243 | * Set the image to be draggable, showing the other image (dragImage) |
---|
244 | * to be used as the widget that is visually dragged. |
---|
245 | */ |
---|
246 | result->setDraggable(mimeType,new WImage(smallurl,p),true); |
---|
247 | } |
---|
248 | |
---|
249 | /*Wt::WWidget* PspaApplication::createBeamLine__deprecated() |
---|
250 | { |
---|
251 | extensionFile_= 0; |
---|
252 | if (!beamLine__deprecated_) { |
---|
253 | // FIXME : get the one of the first app/sector for the moment |
---|
254 | beamLine__deprecated_ = accel_toBeRenameAsLocal->firstSector__deprecated()->getUIBeamLine ? |
---|
255 | } else { |
---|
256 | beamLine_->clear(); |
---|
257 | } |
---|
258 | beamLine_->setMinimumSize(300,100); |
---|
259 | setTitle(applicationDefaultTitle_); |
---|
260 | |
---|
261 | return beamLine__deprecated_; |
---|
262 | } |
---|
263 | */ |
---|
264 | |
---|
265 | void PspaApplication::sauver() |
---|
266 | { |
---|
267 | cout << "***********************************" << endl; |
---|
268 | cout << " on sauve " << endl<<endl; |
---|
269 | |
---|
270 | console_->addConsoleMessage("sauvegarde \n"); |
---|
271 | dialogSave_ = new WDialog("save"); |
---|
272 | new WText("name of case : ",dialogSave_->contents()); |
---|
273 | saveNameEdit_ = new WLineEdit(nameOfCase_.c_str(), dialogSave_->contents()); |
---|
274 | WPushButton *annule = new WPushButton("cancel",dialogSave_->contents()); |
---|
275 | WPushButton *submit = new WPushButton("OK",dialogSave_->contents()); |
---|
276 | annule->clicked().connect(dialogSave_, &Wt::WDialog::reject); |
---|
277 | submit->clicked().connect(dialogSave_, &Wt::WDialog::accept); |
---|
278 | dialogSave_->finished().connect(this, &PspaApplication::dialogSaveDone); |
---|
279 | dialogSave_->show(); |
---|
280 | } |
---|
281 | |
---|
282 | void PspaApplication::dialogSaveDone(WDialog::DialogCode code) |
---|
283 | { |
---|
284 | if ( code != Wt::WDialog::Accepted ) { |
---|
285 | return; |
---|
286 | } |
---|
287 | nameOfCase_ = saveNameEdit_->text().toUTF8(); |
---|
288 | delete dialogSave_; |
---|
289 | dialogSave_ = NULL; |
---|
290 | |
---|
291 | //globalParam_->updateGlobals(); |
---|
292 | |
---|
293 | // dtmanage_->saveConfiguration(sessionId(),nameOfCase_); |
---|
294 | |
---|
295 | // en test: j'ajoute la sauvegarde sur .aml |
---|
296 | dtmanage_->writeToAMLFile(nameOfCase_); |
---|
297 | } |
---|
298 | |
---|
299 | void PspaApplication::restaurer() |
---|
300 | { |
---|
301 | cout << "***********************************" << endl; |
---|
302 | cout << " on restaure " << endl<<endl; |
---|
303 | |
---|
304 | GWt_serverFileSelector * fs = new GWt_serverFileSelector("Select a configuration file",workingDir_); |
---|
305 | string fileName = fs->exec(); |
---|
306 | nameOfCase_ = fileName; |
---|
307 | if (fileName == "") { |
---|
308 | return; |
---|
309 | } |
---|
310 | |
---|
311 | removePathFromConfigName(nameOfCase_); |
---|
312 | cout << " nom sans path " << nameOfCase_ << endl; |
---|
313 | removeExtensionFromConfigName(nameOfCase_, string(".aml")); |
---|
314 | // removeExtensionFromConfigName(nameOfCase_, string(".save")); |
---|
315 | cout << " nom sans extension " << nameOfCase_ << endl; |
---|
316 | if (nameOfCase_ == "") return; |
---|
317 | cout << " PspaApplication::restaure le fichier : " << fileName << endl; |
---|
318 | dialogSave_ = NULL; |
---|
319 | |
---|
320 | // bool test = dtmanage_->restoreElements(fileName); |
---|
321 | bool test = dtmanage_->restoreAMLElements(fileName); |
---|
322 | if ( !test ) { |
---|
323 | GWt_dialog restoreWarning(" element restoring", "failure in restoring elements from file : " + fileName , GWt_dialog::Error, false,true); |
---|
324 | restoreWarning.exec(); |
---|
325 | } else { |
---|
326 | // Change the window title |
---|
327 | unsigned long found = fileName.find_last_of("/"); |
---|
328 | setTitle(applicationDefaultTitle_+" : "+fileName.substr(found+1)); |
---|
329 | } |
---|
330 | |
---|
331 | // reload new elements in the GUI |
---|
332 | // FIXME : Don't do that in the futur ! |
---|
333 | // In the futur, we should be able to have lot of accelerator at the same time and each with ONE datamanager |
---|
334 | acceleratorContainerWidget_->clear(); |
---|
335 | createAccelerator(); |
---|
336 | |
---|
337 | globalParam_->renew(); |
---|
338 | //sectorParam_->renew(); |
---|
339 | console_->addConsoleMessage(WString("restauration terminee \n")); |
---|
340 | } |
---|
341 | |
---|
342 | void PspaApplication::openFileSelector() |
---|
343 | { |
---|
344 | WContainerWidget *result = new WContainerWidget(); |
---|
345 | WVBoxLayout* myLayout = new WVBoxLayout(); |
---|
346 | uploadFileSelectorWidget_ = new WFileUpload(); |
---|
347 | uploadFileSelectorWidget_->setFileTextSize(40); |
---|
348 | myLayout->addWidget(new WText("Select the configuration file for pspa : ")); |
---|
349 | myLayout->addWidget(uploadFileSelectorWidget_); |
---|
350 | result->setLayout (myLayout); |
---|
351 | |
---|
352 | // Upload automatically when the user entered a file. |
---|
353 | uploadFileSelectorWidget_->changed().connect(uploadFileSelectorWidget_, &WFileUpload::upload); |
---|
354 | |
---|
355 | // React to a succesfull upload. |
---|
356 | uploadFileSelectorWidget_->uploaded().connect(this, &PspaApplication::chargerConfig); |
---|
357 | |
---|
358 | // React to a fileupload problem. |
---|
359 | uploadFileSelectorWidget_->fileTooLarge().connect(this, &PspaApplication::fileTooLarge); |
---|
360 | |
---|
361 | GWt_dialog* fileSelectorDialog = new GWt_dialog("Load a file",result,false); |
---|
362 | fileSelectorDialog->exec(); |
---|
363 | } |
---|
364 | |
---|
365 | void PspaApplication::chargerConfig() |
---|
366 | { |
---|
367 | GWt_dialog* message= new GWt_dialog("File successfully upload","The file has been correctly upload to" + uploadFileSelectorWidget_->spoolFileName(),GWt_dialog::Warning,false,true); |
---|
368 | |
---|
369 | string nomDuFichier = (uploadFileSelectorWidget_->clientFileName()).toUTF8(); |
---|
370 | cout << " fichier client : " << nomDuFichier << endl; |
---|
371 | bool test = removeExtensionFromConfigName(nomDuFichier, string(".aml")); |
---|
372 | cout << " fichier client sans extension : " << nomDuFichier << endl; |
---|
373 | |
---|
374 | if ( test ) { |
---|
375 | nameOfCase_ = nomDuFichier; |
---|
376 | console_->addConsoleMessage(string("restauration...")); |
---|
377 | |
---|
378 | if ( !dtmanage_->restoreAMLElements(uploadFileSelectorWidget_->spoolFileName()) ) { |
---|
379 | GWt_dialog restoreWarning(" element restoring", "failure in restoring elements !", GWt_dialog::Error, false,true); |
---|
380 | restoreWarning.exec(); |
---|
381 | } |
---|
382 | |
---|
383 | globalParam_->renew(); |
---|
384 | //sectorParam_->renew(); |
---|
385 | console_->addConsoleMessage(string("rechargement de la config termine")); |
---|
386 | message->show(); |
---|
387 | } |
---|
388 | } |
---|
389 | |
---|
390 | void PspaApplication::fileTooLarge() |
---|
391 | { |
---|
392 | std::stringstream stream; |
---|
393 | stream << maximumRequestSize (); |
---|
394 | std::string maxRequestSize(stream.str()); |
---|
395 | |
---|
396 | std::string message = "This file is too large, please select a one\n"; |
---|
397 | message += "Maximum file size is "+ maxRequestSize; |
---|
398 | message += " bytes\n"; |
---|
399 | |
---|
400 | GWt_dialog* messageBox= new GWt_dialog("Error during upload file" ,message ,GWt_dialog::Error,false,true); |
---|
401 | messageBox->show(); |
---|
402 | } |
---|
403 | |
---|
404 | |
---|
405 | |
---|
406 | // void PspaApplication::faireDessinParmela(WContainerWidget* toto, particleBeam* beam, string namex, string namey ) |
---|
407 | // { |
---|
408 | // cout << " faireDessinParmela " << endl; |
---|
409 | // GWt_dialog* pointsDialog = new GWt_dialog("space phase",toto,false); |
---|
410 | // eDialog_.push_back(pointsDialog); |
---|
411 | // pointsDialog->setMinimumSize(400,400); |
---|
412 | // pointsDialog->setClosable(true); |
---|
413 | // // pointsDialog->show(); |
---|
414 | |
---|
415 | // new WText(nameOfCase_, pointsDialog->contents()); |
---|
416 | |
---|
417 | |
---|
418 | // vector<double> xcor; |
---|
419 | // vector<double> ycor; |
---|
420 | // vector<string> legende; |
---|
421 | // beam->particlesPhaseSpaceData(xcor, ycor, legende, namex, namey); |
---|
422 | // for (int k=0 ; k < legende.size(); k++) { |
---|
423 | // new WBreak(pointsDialog->contents()); |
---|
424 | // new WText(legende.at(k), pointsDialog->contents()); |
---|
425 | // } |
---|
426 | // string titre = " phase space "; |
---|
427 | // chartPlot2vec(pointsDialog->contents(), xcor, ycor, true,titre,namex, namey,400,400); |
---|
428 | |
---|
429 | |
---|
430 | |
---|
431 | // pointsDialog->show(); |
---|
432 | |
---|
433 | // // chart->setMargin(10, Top | Bottom); // add margin vertically |
---|
434 | // // chart->setMargin(WLength::Auto, Left | Right); // center horizontally |
---|
435 | // } |
---|
436 | |
---|
437 | // void PspaApplication::faireDessinTransport(WContainerWidget* toto, particleBeam* beam, string namex, string namey) |
---|
438 | // { |
---|
439 | // GWt_dialog* ellipseDialog = new GWt_dialog("ellipse",toto,false); |
---|
440 | // eDialog_.push_back(ellipseDialog); |
---|
441 | // ellipseDialog->setMinimumSize(400,400); |
---|
442 | // ellipseDialog->setClosable(true); |
---|
443 | // ellipseDialog->show(); |
---|
444 | // new WText(nameOfCase_, ellipseDialog->contents()); |
---|
445 | |
---|
446 | // vector<double> xcor; |
---|
447 | // vector<double> ycor; |
---|
448 | // vector<string> legende; |
---|
449 | // beam->donneesDessinEllipse(xcor,ycor,legende, namex, namey); |
---|
450 | |
---|
451 | // for (int k=0 ; k < legende.size(); k++) { |
---|
452 | // new WBreak(ellipseDialog->contents()); |
---|
453 | // new WText(legende.at(k), ellipseDialog->contents()); |
---|
454 | // } |
---|
455 | // string titre = "phase space rms"; |
---|
456 | // chartPlot2vec(ellipseDialog->contents(), xcor, ycor, false,titre, namex, namey,500,300); |
---|
457 | // } |
---|
458 | |
---|
459 | |
---|
460 | // // parametre drawPoints : true = on trace des points (phase space) ; false = on trace des lignes (enveloppes...) |
---|
461 | // void PspaApplication::chartPlot2vec(WContainerWidget* toto, vector<double>& xcor, vector<double>& ycor, bool drawPoints,string title,string legendx, string legendy,int width, int height, bool makeIcon) |
---|
462 | // { |
---|
463 | // int nbpts = xcor.size(); |
---|
464 | // cout << " PspaApplication::chartPlot2vec nbpts = " << nbpts << endl; |
---|
465 | // WStandardItemModel *model = new WStandardItemModel(nbpts, 2, toto); |
---|
466 | // for (int i = 0; i < nbpts; ++i) { |
---|
467 | // model->setData(i, 0, xcor.at(i)); |
---|
468 | // model->setData(i, 1, ycor.at(i)); |
---|
469 | // // cout << " PspaApplication::chartPlot2vec el= " << i+1 << " x= " << xcor.at(i) << " y= " << ycor.at(i) << endl; |
---|
470 | // } |
---|
471 | |
---|
472 | // WCartesianChart *chart = new WCartesianChart(toto); |
---|
473 | // if (!makeIcon) { |
---|
474 | // chart->setTitle(title); |
---|
475 | // } |
---|
476 | // chart->initLayout(); |
---|
477 | |
---|
478 | // chart->setModel(model); // set the model |
---|
479 | // chart->setXSeriesColumn(0); // set the column that holds the X data |
---|
480 | // if (!makeIcon) { |
---|
481 | // chart->setLegendEnabled(true); // enable the legend |
---|
482 | // } else { |
---|
483 | // chart->setLegendEnabled(false); // enable the legend |
---|
484 | // } |
---|
485 | |
---|
486 | // chart->setType(ScatterPlot); // set type to ScatterPlot |
---|
487 | |
---|
488 | // // Typically, for mathematical functions, you want the axes to cross |
---|
489 | // // at the 0 mark: |
---|
490 | // chart->axis(XAxis).setLocation(ZeroValue); |
---|
491 | // chart->axis(YAxis).setLocation(ZeroValue); |
---|
492 | |
---|
493 | // // Provide space for the X and Y axis and title. |
---|
494 | // chart->setPlotAreaPadding(80, Left); // ? |
---|
495 | // chart->setPlotAreaPadding(40, Bottom); |
---|
496 | // chart->setPlotAreaPadding(60, Top); |
---|
497 | // if ( drawPoints ) { |
---|
498 | // WDataSeries s(1, PointSeries, Y1Axis); |
---|
499 | // chart->addSeries(s); |
---|
500 | // } else { |
---|
501 | // WDataSeries s(1, LineSeries, Y1Axis); |
---|
502 | // chart->addSeries(s); |
---|
503 | // } |
---|
504 | // chart->resize(width, height); // WPaintedWidget must be given explicit size |
---|
505 | |
---|
506 | |
---|
507 | // WAxis& axis = chart->axis(XAxis); |
---|
508 | // axis.setLabelFormat("%.3f"); |
---|
509 | // // axis.setGridLinesEnabled(true); |
---|
510 | // axis.setTitle(legendx); |
---|
511 | |
---|
512 | // WAxis& axey = chart->axis(YAxis); |
---|
513 | // axey.setTitle(legendy); |
---|
514 | // // axis = chart->axis(YAxis); |
---|
515 | // // axis.setLabelFormat("%.3f"); |
---|
516 | // // axis.setGridLinesEnabled(true); |
---|
517 | // // axis.setTitle(legendy); |
---|
518 | |
---|
519 | // if (makeIcon) { |
---|
520 | // chart->setPlotAreaPadding(0); |
---|
521 | // chart->setAxisPadding(0); |
---|
522 | // WFont xAxisFont = chart->axis(XAxis).labelFont(); |
---|
523 | // xAxisFont.setSize(8); |
---|
524 | // WFont yAxisFont = chart->axis(YAxis).labelFont(); |
---|
525 | // yAxisFont.setSize(8); |
---|
526 | // chart->axis(XAxis).setLabelFont(xAxisFont); |
---|
527 | // chart->axis(YAxis).setLabelFont(yAxisFont); |
---|
528 | // } |
---|
529 | |
---|
530 | // #ifdef HAS_IMAGEMAGIC |
---|
531 | // /* Wt::WRasterImage pngImage("png", 600, 600); |
---|
532 | // Wt::WPainter p(&pngImage); |
---|
533 | // chart->paint(p); |
---|
534 | // std::string name; |
---|
535 | // name = workingDir_ + "/chart-"+sessionId ()+".png"; |
---|
536 | // std::ofstream f(name.c_str(), std::ios::out |std::ios::trunc | std::ios::binary); |
---|
537 | // pngImage.write(f); |
---|
538 | // new WText("<a href='workingArea/chart-"+sessionId ()+".png' target='_blank'>Afficher l'image</a>",toto); |
---|
539 | |
---|
540 | // Wt::WPdfImage pdfImage("30cm", "30cm"); |
---|
541 | // Wt::WPainter p1(&pdfImage); |
---|
542 | // pdfImage.init(); |
---|
543 | // chart->paint(p1); |
---|
544 | // name = workingDir_ + "/chart-"+sessionId ()+".pdf"; |
---|
545 | // std::ofstream f1(name.c_str(), std::ios::out |std::ios::trunc | std::ios::binary); |
---|
546 | // pdfImage.write(f1); |
---|
547 | // */ |
---|
548 | // #endif |
---|
549 | // } |
---|
550 | |
---|
551 | |
---|
552 | WText* PspaApplication::createTitle(const WString& title) |
---|
553 | { |
---|
554 | WText *result = new WText(title); |
---|
555 | result->setInline(false); |
---|
556 | result->setStyleClass("title"); |
---|
557 | result->setMinimumSize(30,30); |
---|
558 | |
---|
559 | return result; |
---|
560 | } |
---|
561 | |
---|
562 | // void PspaApplication::addConsoleMessage(WString msg) { |
---|
563 | // WText *w = new WText(console_); |
---|
564 | // w->setTextFormat(PlainText); |
---|
565 | // w->setText(msg); |
---|
566 | // w->setInline(false); |
---|
567 | |
---|
568 | // /* |
---|
569 | // * Little javascript trick to make sure we scroll along with new content |
---|
570 | // */ |
---|
571 | // WApplication *app = WApplication::instance(); |
---|
572 | // app->doJavaScript(console_->jsRef() + ".scrollTop += " |
---|
573 | // + console_->jsRef() + ".scrollHeight;"); |
---|
574 | |
---|
575 | // } |
---|
576 | |
---|
577 | bool PspaApplication::removePathFromConfigName(string& config) { |
---|
578 | string toExtract = workingDir_ + "/"; |
---|
579 | string::size_type nn = config.find(toExtract); |
---|
580 | if ( nn == string::npos ) { |
---|
581 | GWt_dialog checkremovePath(" checking config file name", " failed to recognize path name for file " + config, GWt_dialog::Error,true,true); |
---|
582 | checkremovePath.exec(); |
---|
583 | return false; |
---|
584 | } |
---|
585 | config.replace(nn, toExtract.size(), ""); |
---|
586 | return true; |
---|
587 | } |
---|
588 | |
---|
589 | bool PspaApplication::removeExtensionFromConfigName(string& config, string extension) |
---|
590 | { |
---|
591 | // string configName; |
---|
592 | // string extension(".save"); |
---|
593 | bool test = true; |
---|
594 | string::size_type nn = config.rfind('.'); |
---|
595 | if ( nn == string::npos ) |
---|
596 | { |
---|
597 | // pas de point |
---|
598 | test = false; |
---|
599 | } |
---|
600 | string fin = config.substr(nn); |
---|
601 | if ( fin != extension ) |
---|
602 | { |
---|
603 | // l'extension n'est pas la bonne |
---|
604 | test = false; |
---|
605 | } |
---|
606 | if ( test ) |
---|
607 | { |
---|
608 | string::size_type count = config.length() - extension.length(); |
---|
609 | config = config.substr(0, count); |
---|
610 | } |
---|
611 | else |
---|
612 | { |
---|
613 | GWt_dialog checkConfigNameDialog(" checking config file name", " the file must have the extension " + extension, GWt_dialog::Error,true,true); |
---|
614 | checkConfigNameDialog.exec(); |
---|
615 | } |
---|
616 | return test; |
---|
617 | } |
---|
618 | |
---|
619 | |
---|
620 | /* |
---|
621 | void PspaApplication::removeBeamLine() { |
---|
622 | createBeamLine__deprecated(); |
---|
623 | executeWidget_->updateSections(); |
---|
624 | } |
---|
625 | */ |
---|
626 | |
---|