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