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