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