[446] | 1 | #include "GWt_accelerator.h" |
---|
| 2 | #include "GWt_sector.h" |
---|
[493] | 3 | #include "GWt_machine.h" |
---|
[446] | 4 | |
---|
| 5 | #include <Wt/WLabel> |
---|
| 6 | #include <Wt/WPanel> |
---|
| 7 | #include <Wt/WColor> |
---|
| 8 | #include <Wt/WVBoxLayout> |
---|
| 9 | #include <Wt/WHBoxLayout> |
---|
| 10 | #include <Wt/WComboBox> |
---|
[455] | 11 | #include <Wt/WRadioButton> |
---|
[446] | 12 | #include <Wt/WPushButton> |
---|
| 13 | #include <Wt/WGroupBox> |
---|
[455] | 14 | #include <Wt/WStandardItemModel> |
---|
[446] | 15 | |
---|
| 16 | #include <string> |
---|
| 17 | |
---|
[474] | 18 | //- Ouvrir le premier secteur quand il est chargé |
---|
[495] | 19 | //- Ajouter les computingBlocks |
---|
[474] | 20 | //- Fixer le addConsoleMessage() |
---|
| 21 | //- remise a jour des éléments si on on change un bout de section |
---|
| 22 | |
---|
[455] | 23 | GWt_accelerator::GWt_accelerator(WContainerWidget* parent, dataManager* dt) : |
---|
[446] | 24 | WContainerWidget(parent), |
---|
[455] | 25 | dataManager_(dt) |
---|
[446] | 26 | { |
---|
[493] | 27 | cout << " GWt_accelerator::GWt_accelerator CONSTRUCTION NOUVEL ACCELERATOR " << endl; |
---|
[446] | 28 | setObjectName("accelerator"); |
---|
| 29 | addStyleClass("acceleratorPanel"); |
---|
[455] | 30 | nameOfCase_ = "pspa"; // default // FIXME |
---|
| 31 | |
---|
| 32 | |
---|
[446] | 33 | WContainerWidget* menu = new WContainerWidget(this); |
---|
| 34 | menu->addStyleClass("acceleratorMenu"); |
---|
| 35 | |
---|
| 36 | // Wt::WHBoxLayout* hTopLineLayout = new WHBoxLayout(); |
---|
| 37 | // topLine->setLayout(hTopLineLayout); |
---|
| 38 | |
---|
| 39 | new WLabel("my accelerator ",menu); |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | // Parameters |
---|
| 43 | WPushButton* actionParameters = new WPushButton("",menu); |
---|
| 44 | // set tooltips |
---|
| 45 | actionParameters->setToolTip("change parameters"); |
---|
| 46 | |
---|
| 47 | // Set class for actions elements |
---|
| 48 | actionParameters->setStyleClass("Button WhiteButton parameters"); |
---|
| 49 | actionParameters->setMaximumSize(32,32); |
---|
| 50 | actionParameters->setMinimumSize(32,32); |
---|
| 51 | |
---|
| 52 | // Add sector |
---|
| 53 | WPushButton* addSectorParameters = new WPushButton("",menu); |
---|
| 54 | // set tooltips |
---|
| 55 | addSectorParameters->setToolTip("add a sector"); |
---|
| 56 | |
---|
| 57 | // Set class for actions elements |
---|
| 58 | addSectorParameters->setStyleClass("Button WhiteButton addSector"); |
---|
| 59 | addSectorParameters->setMaximumSize(32,32); |
---|
| 60 | addSectorParameters->setMinimumSize(32,32); |
---|
| 61 | |
---|
[493] | 62 | |
---|
[496] | 63 | // // expand machine |
---|
| 64 | // WPushButton* expandMachine = new WPushButton("init/expand machine",menu); |
---|
| 65 | // // set tooltips |
---|
| 66 | // expandMachine->setToolTip("expand the machine"); |
---|
| 67 | // // Set class for actions elements |
---|
| 68 | // expandMachine->setStyleClass("Button WhiteButton expand"); |
---|
| 69 | // expandMachine->setMaximumSize(128,32); |
---|
| 70 | // expandMachine->setMinimumSize(128,32); |
---|
[493] | 71 | |
---|
[496] | 72 | // // action |
---|
| 73 | // expandMachine->clicked().connect(this,&GWt_accelerator::expandMachine); |
---|
[493] | 74 | |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | |
---|
[446] | 78 | // Run |
---|
| 79 | WPushButton* runParameters = new WPushButton("",menu); |
---|
| 80 | // set tooltips |
---|
| 81 | runParameters->setToolTip("run this accelerator"); |
---|
| 82 | |
---|
| 83 | // Set class for actions elements |
---|
| 84 | runParameters->setStyleClass("Button WhiteButton run"); |
---|
| 85 | runParameters->setMaximumSize(32,32); |
---|
| 86 | runParameters->setMinimumSize(32,32); |
---|
| 87 | |
---|
[455] | 88 | WPushButton* boutongraphicalAnalysis = new WPushButton("",menu); |
---|
| 89 | boutongraphicalAnalysis->setStyleClass("histoButton"); |
---|
| 90 | boutongraphicalAnalysis->setToolTip ("analyse graphique"); |
---|
| 91 | boutongraphicalAnalysis->setMaximumSize(32,32); |
---|
| 92 | boutongraphicalAnalysis->setMinimumSize(32,32); |
---|
| 93 | |
---|
| 94 | |
---|
[446] | 95 | new WBreak(this); |
---|
| 96 | |
---|
| 97 | WScrollArea* scrollWidget = new WScrollArea(this); |
---|
| 98 | |
---|
| 99 | WContainerWidget* acceleratorScrollArea = new WContainerWidget(); |
---|
| 100 | scrollWidget->setWidget(acceleratorScrollArea); |
---|
| 101 | acceleratorScrollArea->setStyleClass("acceleratorContent"); |
---|
| 102 | |
---|
| 103 | WContainerWidget* acceleratorGlobalView = new WGroupBox("Global view",acceleratorScrollArea); |
---|
[493] | 104 | acceleratorDetailledView_ = new WGroupBox("Detailled view of sector",acceleratorScrollArea); |
---|
| 105 | acceleratorComputingView_ = new WGroupBox("Computing view",acceleratorScrollArea); |
---|
[446] | 106 | acceleratorGlobalViewLayout_= new WHBoxLayout(); |
---|
| 107 | acceleratorGlobalView->setLayout(acceleratorGlobalViewLayout_); |
---|
| 108 | |
---|
[474] | 109 | // read configuration |
---|
| 110 | readConfiguration(); |
---|
[446] | 111 | |
---|
| 112 | // Actions |
---|
| 113 | addSectorParameters->clicked().connect(this,&GWt_accelerator::addSector); |
---|
| 114 | runParameters->clicked().connect(this,&GWt_accelerator::run); |
---|
[455] | 115 | boutongraphicalAnalysis->clicked().connect(this, &GWt_accelerator::dialogOnGraphics); |
---|
[446] | 116 | |
---|
[455] | 117 | graphicsDialog_ = new GWt_dialog("graphical analysis",createDrawingWidget(),false); |
---|
| 118 | graphicsDialog_->setMinimumSize(400,400); |
---|
| 119 | graphicsDialog_->setClosable(true); |
---|
| 120 | graphicsDialog_->hide(); |
---|
[446] | 121 | |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | GWt_accelerator::~GWt_accelerator() |
---|
| 126 | { |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | void GWt_accelerator::addSector() |
---|
| 130 | { |
---|
[455] | 131 | sector* sect = getDataManager()->addNewSector(); |
---|
[474] | 132 | new GWt_sector(this,sect); |
---|
[446] | 133 | } |
---|
| 134 | |
---|
[474] | 135 | |
---|
| 136 | void GWt_accelerator::readConfiguration() |
---|
| 137 | { |
---|
| 138 | std::vector <sector*> sect = dataManager_->getSectors(); |
---|
| 139 | if (sect.size() == 0) { |
---|
| 140 | // Add the first sector |
---|
[493] | 141 | addSector(); |
---|
[474] | 142 | } else { |
---|
| 143 | for (unsigned long a=0; a< sect.size(); a++) { |
---|
| 144 | new GWt_sector(this,sect[a]); |
---|
| 145 | } |
---|
| 146 | } |
---|
[493] | 147 | // cout << " INTERVENTION GWt_accelerator::readConfiguration " << endl; |
---|
| 148 | // if ( dataManager_->getCurrentMachine() ) cout << " GWt_accelerator::readConfiguration nb elem. " << dataManager_->getCurrentMachine()->getNumberOfElements() << endl; |
---|
| 149 | |
---|
| 150 | new GWt_machine(this, dataManager_->getCurrentMachine()); |
---|
[474] | 151 | } |
---|
| 152 | |
---|
[496] | 153 | // void GWt_accelerator::expandMachine() { |
---|
| 154 | // cout << " coucou depuis GWt_accelerator::expandMachine() " << endl; |
---|
| 155 | // if (getDataManager()->expandMachine()) new GWt_machine(this, dataManager_->getCurrentMachine()); |
---|
| 156 | // } |
---|
[474] | 157 | |
---|
[446] | 158 | void GWt_accelerator::run() |
---|
| 159 | { |
---|
[468] | 160 | cout << "***********************************" << endl; |
---|
[493] | 161 | cout << " GWt_accelerator::executer() " << endl<<endl; |
---|
[468] | 162 | |
---|
| 163 | if (!areDataCoherent()) { |
---|
| 164 | return; |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | //static_cast<GWt_globalParameters*>(pspa_->getGlobalParam())->updateGlobals(); |
---|
| 168 | |
---|
| 169 | GWt_dialog calculDialog("Calcul en cours", "Veuillez patienter...", GWt_dialog::Wait, true,false); |
---|
| 170 | calculDialog.show(); |
---|
| 171 | |
---|
| 172 | wApp->processEvents(); |
---|
| 173 | |
---|
| 174 | if (!getDataManager()->executeAll()) { |
---|
| 175 | GWt_dialog warningDialog("PSPA : Echec", " echec lors de l'exécution !", GWt_dialog::Error, true,true); |
---|
| 176 | warningDialog.exec(); |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | // exec_go_->setDisabled(true); |
---|
| 180 | calculDialog.hide(); |
---|
| 181 | faireDessin(); |
---|
[446] | 182 | } |
---|
[455] | 183 | |
---|
[493] | 184 | |
---|
| 185 | // recuperer les noms d'elements pour remplir les combos des menus de graphique |
---|
[455] | 186 | void GWt_accelerator::faireDessin() |
---|
| 187 | { |
---|
| 188 | choixElementDessin_->clear(); |
---|
| 189 | choixHistoDessin_->clear(); |
---|
| 190 | |
---|
[493] | 191 | if ( getDataManager()->getCurrentMachine() ) { |
---|
| 192 | for (unsigned k = 0; k < getDataManager()->getCurrentMachine()->getComputingBlocks().size(); k++) { |
---|
| 193 | computingBlock* cpblk = getDataManager()->getCurrentMachine()->getComputingBlocks().at(k); |
---|
| 194 | for (unsigned l = 0; l < cpblk->getNumberOfElements(); l++) { |
---|
| 195 | abstractElement* elPtr = cpblk->getElement(k); |
---|
[455] | 196 | choixElementDessin_->addItem(elPtr->getLabel()); |
---|
| 197 | choixHistoDessin_->addItem(elPtr->getLabel()); |
---|
| 198 | } |
---|
| 199 | } |
---|
| 200 | } |
---|
[493] | 201 | // for (unsigned k = 0; k < getDataManager()->getSectors().size(); k++) { |
---|
| 202 | // sector* sector = getDataManager()->getSectors()[k]; |
---|
| 203 | // for (unsigned l = 0; l < sector->getSectionsToExecute().size(); l++) { |
---|
| 204 | // sectionToExecute* section = sector->getSectionsToExecute()[l]; |
---|
| 205 | // for (unsigned m = 0; m < section->getElements().size(); m++) { |
---|
| 206 | |
---|
| 207 | // abstractElement* elPtr = section->getElements()[m]; |
---|
| 208 | // // if(elPtr->getNomdElement().getElementType() == snapshot) continue; |
---|
| 209 | |
---|
| 210 | // choixElementDessin_->addItem(elPtr->getLabel()); |
---|
| 211 | // choixHistoDessin_->addItem(elPtr->getLabel()); |
---|
| 212 | // } |
---|
| 213 | // } |
---|
| 214 | // } |
---|
| 215 | |
---|
[455] | 216 | } |
---|
| 217 | |
---|
| 218 | WContainerWidget* GWt_accelerator::createDrawingWidget() |
---|
| 219 | { |
---|
| 220 | WGridLayout *glayout= new WGridLayout(); |
---|
| 221 | WContainerWidget* dessin = new WContainerWidget(); |
---|
| 222 | dessin->setLayout(glayout); |
---|
| 223 | |
---|
| 224 | group_ = new Wt::WButtonGroup(this); |
---|
| 225 | |
---|
| 226 | ///////////////////////////////////////////////////////////////////// |
---|
| 227 | |
---|
| 228 | choixEnveloppeDessin_ = new WComboBox(); |
---|
| 229 | choixEnveloppeDessin_->addItem("x"); |
---|
| 230 | // choixEnveloppeDessin_->addItem("y"); |
---|
| 231 | Wt::WRadioButton *button1= new WRadioButton(" enveloppe"); |
---|
| 232 | group_->addButton(button1,1); |
---|
| 233 | glayout->addWidget(button1,0,1); |
---|
| 234 | glayout->addWidget(choixEnveloppeDessin_,0,2); |
---|
| 235 | ///////////////////////////////////////////////////////////////////// |
---|
| 236 | |
---|
| 237 | choixElementDessin_ = new WComboBox(); |
---|
| 238 | choixElementDessin_->setMinimumSize(50,10); |
---|
| 239 | choixTypeDessinFaisceau_ = new WComboBox(); |
---|
| 240 | choixTypeDessinFaisceau_->addItem("courant_snyder"); |
---|
| 241 | choixTypeDessinFaisceau_->addItem("macroparticles"); |
---|
| 242 | Wt::WRadioButton *button2= new WRadioButton(" phase space after element"); |
---|
| 243 | |
---|
| 244 | choixAbsPhase_ = new WComboBox(); |
---|
| 245 | choixAbsPhase_->addItem("x"); |
---|
| 246 | choixAbsPhase_->addItem("y"); |
---|
| 247 | choixAbsPhase_->addItem("dz"); |
---|
| 248 | choixAbsPhase_->addItem("xp"); |
---|
| 249 | choixAbsPhase_->addItem("yp"); |
---|
| 250 | choixAbsPhase_->addItem("dE/E"); |
---|
| 251 | choixAbsPhase_->setCurrentIndex(0); |
---|
| 252 | |
---|
| 253 | choixOrdPhase_ = new WComboBox(); |
---|
| 254 | choixOrdPhase_->addItem("x"); |
---|
| 255 | choixOrdPhase_->addItem("y"); |
---|
| 256 | choixOrdPhase_->addItem("dz"); |
---|
| 257 | choixOrdPhase_->addItem("xp"); |
---|
| 258 | choixOrdPhase_->addItem("yp"); |
---|
| 259 | choixOrdPhase_->addItem("dE/E"); |
---|
| 260 | choixOrdPhase_->setCurrentIndex(3); |
---|
| 261 | |
---|
| 262 | group_->addButton(button2,2); |
---|
| 263 | glayout->addWidget(button2,1,1); |
---|
| 264 | glayout->addWidget(choixElementDessin_,1,2); |
---|
| 265 | glayout->addWidget(choixTypeDessinFaisceau_,1,3); |
---|
| 266 | // glayout->addWidget(new WText("abs. :"),2,2); |
---|
| 267 | glayout->addWidget(choixAbsPhase_,2,2); |
---|
| 268 | // glayout->addWidget(new WText("ord. :"),2,4); |
---|
| 269 | glayout->addWidget(choixOrdPhase_,2,3); |
---|
| 270 | ///////////////////////////////////////////////////////////////////// |
---|
| 271 | |
---|
| 272 | choixVariableHisto_= new WComboBox(); |
---|
| 273 | choixVariableHisto_->addItem("x"); |
---|
| 274 | choixVariableHisto_->addItem("y"); |
---|
| 275 | choixVariableHisto_->addItem("z"); |
---|
| 276 | choixVariableHisto_->addItem("xp"); |
---|
| 277 | choixVariableHisto_->addItem("yp"); |
---|
| 278 | choixVariableHisto_->addItem("dE/E"); |
---|
| 279 | choixVariableHisto_->setCurrentIndex(5); |
---|
| 280 | |
---|
| 281 | choixHistoDessin_ = new WComboBox(); |
---|
| 282 | Wt::WRadioButton *button3= new WRadioButton(" histogram after element "); |
---|
| 283 | group_->addButton(button3,3); |
---|
| 284 | |
---|
| 285 | glayout->addWidget(button3,3,1); |
---|
| 286 | glayout->addWidget(choixHistoDessin_,3,2); |
---|
| 287 | glayout->addWidget(choixVariableHisto_,3,3); |
---|
| 288 | ///////////////////////////////////////////////////////////////////// |
---|
| 289 | |
---|
| 290 | WPushButton *close= new WPushButton("close"); |
---|
| 291 | glayout->addWidget(close,4,1); |
---|
| 292 | close->clicked().connect(this,&GWt_accelerator::closeGraphicDialog); |
---|
| 293 | |
---|
| 294 | WPushButton *draw= new WPushButton("draw"); |
---|
| 295 | glayout->addWidget(draw,4,2,2,1); |
---|
| 296 | draw->clicked().connect(this,&GWt_accelerator::dessiner); |
---|
| 297 | ///////////////////////////////////////////////////////////////////// |
---|
| 298 | |
---|
| 299 | toto_ = new WContainerWidget(); |
---|
| 300 | dessin->addWidget(toto_); |
---|
| 301 | return dessin; |
---|
| 302 | } |
---|
| 303 | |
---|
| 304 | |
---|
| 305 | void GWt_accelerator::dialogOnGraphics() |
---|
| 306 | { |
---|
| 307 | graphicsDialog_->show(); |
---|
| 308 | } |
---|
| 309 | |
---|
| 310 | |
---|
| 311 | void GWt_accelerator::closeGraphicDialog() |
---|
| 312 | { |
---|
| 313 | cout << " close graphicsDialog_" << endl; |
---|
| 314 | for(unsigned i = 0; i < eDialog_.size(); i++) eDialog_[i]->done(WDialog::Rejected); |
---|
| 315 | eDialog_.clear(); |
---|
| 316 | graphicsDialog_->done(WDialog::Rejected); |
---|
| 317 | } |
---|
| 318 | |
---|
| 319 | |
---|
| 320 | |
---|
| 321 | void GWt_accelerator::dessiner() |
---|
| 322 | { |
---|
| 323 | int k= group_->checkedId(); |
---|
| 324 | cout << "dessiner k= " << k << endl; |
---|
| 325 | |
---|
| 326 | switch(k) { |
---|
| 327 | case 1: |
---|
| 328 | dessinerEnveloppe(); |
---|
| 329 | break; |
---|
| 330 | case 2: |
---|
| 331 | dessinerPhaseSpace(); |
---|
| 332 | break; |
---|
| 333 | case 3: |
---|
| 334 | dessinerHistogramme(); |
---|
| 335 | break; |
---|
| 336 | default: |
---|
| 337 | GWt_dialog graphicalWarning("graphical analysis","select a button",GWt_dialog::Warning,false,true); |
---|
| 338 | graphicalWarning.exec(); |
---|
| 339 | break; |
---|
| 340 | } |
---|
| 341 | } |
---|
| 342 | |
---|
| 343 | void GWt_accelerator::dessinerPhaseSpace() |
---|
| 344 | { |
---|
| 345 | |
---|
| 346 | int typeFaisceau = choixTypeDessinFaisceau_->currentIndex(); |
---|
| 347 | // int index = choixElementDessin_->currentIndex(); |
---|
| 348 | string nameAbs = choixAbsPhase_->currentText().toUTF8(); |
---|
| 349 | string nameOrd = choixOrdPhase_->currentText().toUTF8(); |
---|
| 350 | if ( nameAbs == nameOrd ) { |
---|
| 351 | GWt_dialog phaseSpaceError(" graphical analysis", "the beam coordinates must be different !", GWt_dialog::Error, false,true); |
---|
| 352 | phaseSpaceError.exec(); |
---|
| 353 | return; |
---|
| 354 | } |
---|
| 355 | string elementLabel = choixElementDessin_->currentText().toUTF8(); |
---|
| 356 | particleBeam* beam = dataManager_->getDiagnosticBeam_deprecated(elementLabel); |
---|
| 357 | // particleBeam* beam = dtmanage_->getDiagnosticBeam(index); |
---|
| 358 | |
---|
| 359 | if ( beam == NULL ) { |
---|
| 360 | GWt_dialog warningBeamState(" graphical analysis", "the beam does not exist at the end of this element !", GWt_dialog::Error, false,true); |
---|
| 361 | warningBeamState.exec(); |
---|
| 362 | return; |
---|
| 363 | } |
---|
| 364 | |
---|
| 365 | toto_->clear(); |
---|
| 366 | faireDessinPhaseSpace(toto_, beam, elementLabel, nameAbs, nameOrd, typeFaisceau); |
---|
| 367 | |
---|
| 368 | // if ( typeFaisceau == 0 ) |
---|
| 369 | // { |
---|
| 370 | // if ( !beam->momentRepresentationOk() ) beam->buildMomentRepresentation(); |
---|
| 371 | // faireDessinTransport(toto_, beam, nameAbs, nameOrd ); |
---|
| 372 | // } |
---|
| 373 | // else if ( typeFaisceau == 1 ) |
---|
| 374 | // { |
---|
| 375 | // if ( beam->particleRepresentationOk() ) faireDessinParmela(toto_, beam, nameAbs, nameOrd ); |
---|
| 376 | // else { |
---|
| 377 | // GWt_dialog warningBeamState(" graphical analysis", "the beam state does not allow providing a drawing with macroparticles !", GWt_dialog::Error, false,true); |
---|
| 378 | // warningBeamState.exec(); |
---|
| 379 | // } |
---|
| 380 | // } |
---|
| 381 | // else { |
---|
| 382 | // GWt_dialog warningTypeDrawing(" graphical analysis", "type of drawing not programmed !", GWt_dialog::Error, false,true); |
---|
| 383 | // warningTypeDrawing.exec(); |
---|
| 384 | // } |
---|
| 385 | } |
---|
| 386 | |
---|
| 387 | void GWt_accelerator::dessinerEnveloppe() |
---|
| 388 | { |
---|
| 389 | toto_->clear(); |
---|
| 390 | |
---|
| 391 | int typeEnveloppe = choixEnveloppeDessin_->currentIndex(); |
---|
| 392 | if ( typeEnveloppe == 0 ) |
---|
| 393 | { |
---|
| 394 | faireDessinEnveloppe(toto_, "x"); |
---|
| 395 | } |
---|
| 396 | else { |
---|
| 397 | GWt_dialog warningTypeEnveloppe(" graphical analysis", "type of enveloppe drawing not programmed !", GWt_dialog::Error, false,true); |
---|
| 398 | warningTypeEnveloppe.exec(); |
---|
| 399 | } |
---|
| 400 | } |
---|
| 401 | |
---|
| 402 | void GWt_accelerator::faireDessinEnveloppe(WContainerWidget* toto, string type) |
---|
| 403 | { |
---|
| 404 | |
---|
| 405 | std::time_t result = std::time(NULL); |
---|
| 406 | |
---|
| 407 | GWt_dialog* envDialog = new GWt_dialog(WString("enveloppe (")+std::asctime(std::localtime(&result))+")",toto,false); |
---|
| 408 | eDialog_.push_back(envDialog); |
---|
| 409 | envDialog->setMinimumSize(400,400); |
---|
| 410 | envDialog->setClosable(true); |
---|
| 411 | envDialog->show(); |
---|
| 412 | |
---|
| 413 | // unsigned nbel = dtmanage_->getBeamLineSize(); |
---|
| 414 | vector<double> xcor; |
---|
| 415 | vector<double> ycor; |
---|
| 416 | string titre; |
---|
| 417 | string legendx; |
---|
| 418 | string legendy; |
---|
| 419 | dataManager_->donneesRmsEnveloppe(type,xcor,ycor,titre,legendx,legendy); |
---|
| 420 | |
---|
| 421 | Wt::Chart::SeriesType seriesType = Wt::Chart::LineSeries; |
---|
| 422 | Wt::Chart::FillRangeType fillRange = Wt::Chart::NoFill; |
---|
| 423 | Wt::Chart::AxisValue location = Wt::Chart::ZeroValue; |
---|
| 424 | bool isGridLinesEnabled = false; |
---|
| 425 | chartPlot2vec(envDialog->contents(),xcor,ycor,seriesType,fillRange,location,isGridLinesEnabled,titre,legendx,legendy,500,300); |
---|
| 426 | } |
---|
| 427 | |
---|
| 428 | void GWt_accelerator::faireDessinPhaseSpace(WContainerWidget* toto, particleBeam* beam, string elementLabel, string namex, string namey, int typeFaisceau) |
---|
| 429 | { |
---|
| 430 | |
---|
| 431 | vector<double> xcor; |
---|
| 432 | vector<double> ycor; |
---|
| 433 | vector<string> legende; |
---|
| 434 | string titre; |
---|
| 435 | Wt::Chart::SeriesType seriesType; |
---|
| 436 | |
---|
| 437 | if ( typeFaisceau == 0 ) { |
---|
| 438 | seriesType = Wt::Chart::LineSeries; |
---|
| 439 | titre = "phase space rms"; |
---|
| 440 | beam->donneesDessinEllipse(xcor,ycor,legende,namex,namey); |
---|
| 441 | } else if ( typeFaisceau == 1 ) { |
---|
| 442 | seriesType = Wt::Chart::PointSeries; |
---|
| 443 | titre = " phase space "; |
---|
| 444 | beam->particlesPhaseSpaceData(xcor,ycor,legende,namex,namey); |
---|
| 445 | // for ( int kk=0; kk < xcor.size(); kk++) |
---|
| 446 | // { |
---|
| 447 | // cout << " dess. phas. x= " << xcor.at(kk) << " x'= " << ycor.at(kk) << endl; |
---|
| 448 | // } |
---|
| 449 | } else { |
---|
| 450 | GWt_dialog warningBeamState(" graphical analysis", "the beam state does not allow providing a drawing with macroparticles !", GWt_dialog::Error, false,true); |
---|
| 451 | warningBeamState.exec(); |
---|
| 452 | return; |
---|
| 453 | } |
---|
| 454 | |
---|
| 455 | std::time_t result = std::time(NULL); |
---|
| 456 | GWt_dialog* phaseSpaceDialog = new GWt_dialog(WString("phase space (")+std::asctime(std::localtime(&result))+")",toto,false); |
---|
| 457 | eDialog_.push_back(phaseSpaceDialog); |
---|
| 458 | phaseSpaceDialog->setMinimumSize(400,400); |
---|
| 459 | phaseSpaceDialog->setClosable(true); |
---|
| 460 | new WText(" case : " + nameOfCase_, phaseSpaceDialog->contents()); |
---|
| 461 | new WBreak(phaseSpaceDialog->contents()); |
---|
| 462 | new WText(" after element : " + elementLabel, phaseSpaceDialog->contents()); |
---|
| 463 | |
---|
| 464 | for (int k=0 ; k < (int)legende.size(); k++) { |
---|
| 465 | new WBreak(phaseSpaceDialog->contents()); |
---|
| 466 | new WText(legende.at(k), phaseSpaceDialog->contents()); |
---|
| 467 | } |
---|
| 468 | |
---|
| 469 | Wt::Chart::FillRangeType fillRange = Wt::Chart::NoFill; |
---|
| 470 | Wt::Chart::AxisValue location = Wt::Chart::ZeroValue; |
---|
| 471 | bool isGridLinesEnabled = false; |
---|
| 472 | chartPlot2vec(phaseSpaceDialog->contents(),xcor,ycor,seriesType,fillRange,location,isGridLinesEnabled,titre,namex,namey,500,300); |
---|
| 473 | |
---|
| 474 | phaseSpaceDialog->show(); |
---|
| 475 | } |
---|
| 476 | |
---|
| 477 | |
---|
| 478 | void GWt_accelerator::dessinerHistogramme() |
---|
| 479 | { |
---|
| 480 | toto_->clear(); |
---|
| 481 | |
---|
| 482 | // std::time_t result = std::time(NULL); |
---|
| 483 | // GWt_dialog* histoDialog = new GWt_dialog(WString("histogramme (")+std::asctime(std::localtime(&result))+")",toto_,false); |
---|
| 484 | // eDialog_.push_back(histoDialog); |
---|
| 485 | // histoDialog->setMinimumSize(400,400); |
---|
| 486 | // histoDialog->setClosable(true); |
---|
| 487 | |
---|
| 488 | string elementLabel = choixHistoDessin_->currentText().toUTF8(); |
---|
| 489 | particleBeam* beam = dataManager_->getDiagnosticBeam_deprecated(elementLabel); |
---|
| 490 | if (beam == NULL) { |
---|
| 491 | GWt_dialog warningBeamState("histogram","the beam does not exist at the end of this element !", GWt_dialog::Error, false,true); |
---|
| 492 | warningBeamState.exec(); |
---|
| 493 | return; |
---|
| 494 | } |
---|
| 495 | |
---|
| 496 | if (!beam->particleRepresentationOk()) { |
---|
| 497 | GWt_dialog warningBeamState("histogram", "the beam state does not allow providing a drawing with macroparticles !", GWt_dialog::Error, false,true); |
---|
| 498 | warningBeamState.exec(); |
---|
| 499 | return; |
---|
| 500 | } |
---|
| 501 | |
---|
| 502 | unsigned iabs= choixVariableHisto_->currentIndex(); |
---|
| 503 | vector<double> xcor; |
---|
| 504 | vector<int> hist; |
---|
| 505 | // double out[3]= {0.0}; |
---|
| 506 | vector<string> legende; |
---|
| 507 | beam->histogramme(iabs,xcor,hist,legende); |
---|
| 508 | |
---|
| 509 | cout<<"xcor.size()= "<<xcor.size()<<", hist.size()= "<<hist.size()<<endl; |
---|
| 510 | ////////////////////////////////////////////////////////////////////////////////// |
---|
| 511 | |
---|
| 512 | int n = hist.size(); |
---|
| 513 | vector<double> x; |
---|
| 514 | x.resize(2*n+2); |
---|
| 515 | vector<double> y; |
---|
| 516 | y.resize(2*n+2); |
---|
| 517 | |
---|
| 518 | int j= 0; |
---|
| 519 | x.at(j)= xcor[0]; |
---|
| 520 | y.at(j)= 0.0; |
---|
| 521 | j++; |
---|
| 522 | x.at(j)= xcor[0]; |
---|
| 523 | y.at(j)= hist[0]; |
---|
| 524 | j++; |
---|
| 525 | |
---|
| 526 | for (int i = 1; i < n; ++i) { |
---|
| 527 | x.at(j)= xcor[i]; |
---|
| 528 | y.at(j)= hist[i-1]; |
---|
| 529 | j++; |
---|
| 530 | x.at(j)= xcor[i]; |
---|
| 531 | y.at(j)= hist[i]; |
---|
| 532 | j++; |
---|
| 533 | } |
---|
| 534 | |
---|
| 535 | x.at(j)= xcor[n]; |
---|
| 536 | y.at(j)= hist[n-1]; |
---|
| 537 | j++; |
---|
| 538 | x.at(j)= xcor[n]; |
---|
| 539 | y.at(j)= 0.0; |
---|
| 540 | ////////////////////////////////////////////////////////////////////////////////// |
---|
| 541 | std::time_t result = std::time(NULL); |
---|
| 542 | GWt_dialog* histoDialog = new GWt_dialog(WString("histogramme (")+std::asctime(std::localtime(&result))+")",toto_,false); |
---|
| 543 | eDialog_.push_back(histoDialog); |
---|
| 544 | histoDialog->setMinimumSize(400,400); |
---|
| 545 | histoDialog->setClosable(true); |
---|
| 546 | |
---|
| 547 | histoDialog->show(); |
---|
| 548 | |
---|
| 549 | WContainerWidget *w= histoDialog->contents(); |
---|
| 550 | |
---|
| 551 | // // legendes |
---|
| 552 | // string unites[2]; |
---|
| 553 | // if(iabs == 0 || iabs == 1 || iabs == 2) { |
---|
| 554 | // unites[0]= unites[1]= " mm"; |
---|
| 555 | // } |
---|
| 556 | // if(iabs == 3 || iabs == 4) { |
---|
| 557 | // unites[0]= unites[1]= " mrad"; |
---|
| 558 | // } |
---|
| 559 | // if(iabs == 5) { |
---|
| 560 | // unites[0]= " MeV"; unites[1]= " KeV"; |
---|
| 561 | // } |
---|
| 562 | |
---|
| 563 | new WText(" case : " + nameOfCase_, w); |
---|
| 564 | new WBreak(w); |
---|
| 565 | new WText(" after element : " + elementLabel, w); |
---|
| 566 | |
---|
| 567 | for (int k=0 ; k < (int)legende.size(); k++) { |
---|
| 568 | new WBreak(w); |
---|
| 569 | new WText(legende.at(k), w); |
---|
| 570 | } |
---|
| 571 | |
---|
| 572 | |
---|
| 573 | // new WText(" entries : "+ mixedTools::intToString((int)out[0]),w); |
---|
| 574 | // new WBreak(w); |
---|
| 575 | // new WText(" mean : "+ mixedTools::doubleToString(out[1])+unites[0],w); |
---|
| 576 | // new WBreak(w); |
---|
| 577 | // new WText(" sigma rms : "+ mixedTools::doubleToString(out[2])+unites[1],w); |
---|
| 578 | ////////////////////////////////////////////////////////////////////////////////// |
---|
| 579 | |
---|
| 580 | string titre; |
---|
| 581 | if(iabs == 0) titre="x-coordinate"; |
---|
| 582 | if(iabs == 1) titre="y-coordinate"; |
---|
| 583 | if(iabs == 2) titre="z-coordinate"; |
---|
| 584 | if(iabs == 3) titre="xp-divergence"; |
---|
| 585 | if(iabs == 4) titre="yp-devergence"; |
---|
| 586 | if(iabs == 5) titre="kinetic energy"; |
---|
| 587 | |
---|
| 588 | string xname; |
---|
| 589 | if(iabs == 0) xname=" x (mm)"; |
---|
| 590 | if(iabs == 1) xname=" y (mm)"; |
---|
| 591 | if(iabs == 2) xname=" z (mm)"; |
---|
| 592 | if(iabs == 3) xname=" xp (mrad)"; |
---|
| 593 | if(iabs == 4) xname=" yp (mrad)"; |
---|
| 594 | if(iabs == 5) xname=" dEcin/Ecin (%)"; |
---|
| 595 | |
---|
| 596 | string yname; |
---|
| 597 | Wt::Chart::SeriesType seriesType = Wt::Chart::LineSeries; |
---|
| 598 | Wt::Chart::FillRangeType fillRange = Wt::Chart::ZeroValueFill; |
---|
| 599 | Wt::Chart::AxisValue location = Wt::Chart::MinimumValue; |
---|
| 600 | bool isGridLinesEnabled = true; |
---|
| 601 | chartPlot2vec(w,x,y,seriesType,fillRange,location,isGridLinesEnabled,titre,xname,yname,500,300); |
---|
| 602 | } |
---|
| 603 | |
---|
| 604 | |
---|
| 605 | |
---|
| 606 | void GWt_accelerator::chartPlot2vec(WContainerWidget* toto,vector<double>& xcor,vector<double>& ycor,Wt::Chart::SeriesType seriesType,Wt::Chart::FillRangeType fillRange,Wt::Chart::AxisValue value,bool isGridLinesEnables,string title,string legendx,string legendy,int width,int height,bool makeIcon) |
---|
| 607 | { |
---|
| 608 | int nbpts = xcor.size(); |
---|
| 609 | cout << " PspaApplication::chartPlot2vec nbpts = " << nbpts << endl; |
---|
| 610 | |
---|
| 611 | WStandardItemModel *model = new WStandardItemModel(nbpts, 2, toto); |
---|
| 612 | for (int i = 0; i < nbpts; ++i) { |
---|
| 613 | model->setData(i, 0, xcor.at(i)); |
---|
| 614 | model->setData(i, 1, ycor.at(i)); |
---|
| 615 | // cout << " PspaApplication::chartPlot2vec el= " << i+1 << " x= " << xcor.at(i) << " y= " << ycor.at(i) << endl; |
---|
| 616 | } |
---|
| 617 | // cout << " PspaApplication::chartPlot2vec FLAG 0 " << endl; |
---|
| 618 | Wt::Chart::WCartesianChart *chart = new Wt::Chart::WCartesianChart(toto); |
---|
| 619 | if (!makeIcon) chart->setTitle(title); |
---|
| 620 | chart->initLayout(); |
---|
| 621 | chart->setModel(model); // set the model |
---|
| 622 | chart->setXSeriesColumn(0); // set the column that holds the X data |
---|
| 623 | |
---|
| 624 | chart->setType(Wt::Chart::ScatterPlot); // set type to ScatterPlot |
---|
| 625 | chart->setLegendEnabled(false); // enable the legend |
---|
| 626 | |
---|
| 627 | // Provide space for the X and Y axis and title. |
---|
| 628 | chart->setPlotAreaPadding(80, Left); |
---|
| 629 | chart->setPlotAreaPadding(40, Bottom); |
---|
| 630 | chart->setPlotAreaPadding(60, Top); |
---|
| 631 | |
---|
| 632 | // Typically, for mathematical functions, you want the axes to cross |
---|
| 633 | // at the 0 mark (value= ZeroValue) |
---|
| 634 | chart->axis(Wt::Chart::XAxis).setLocation(value); |
---|
| 635 | chart->axis(Wt::Chart::YAxis).setLocation(value); |
---|
| 636 | |
---|
| 637 | // cout << " PspaApplication::chartPlot2vec FLAG 1 " << endl; |
---|
| 638 | |
---|
| 639 | Wt::Chart::WDataSeries s(1,seriesType); |
---|
| 640 | s.setPen(WColor("red")); |
---|
| 641 | s.setFillRange(fillRange); |
---|
| 642 | chart->addSeries(s); |
---|
| 643 | |
---|
| 644 | Wt::Chart::WAxis& axis = chart->axis(Wt::Chart::XAxis); |
---|
| 645 | axis.setLabelFormat("%.3f"); |
---|
| 646 | axis.setTitle(legendx); |
---|
| 647 | |
---|
| 648 | chart->axis(Wt::Chart::Y1Axis).setTitle(legendy); |
---|
| 649 | |
---|
| 650 | if(isGridLinesEnables) { |
---|
| 651 | axis.setGridLinesEnabled(true); |
---|
| 652 | chart->axis(Wt::Chart::Y1Axis).setGridLinesEnabled(true); |
---|
| 653 | } |
---|
| 654 | // cout << " PspaApplication::chartPlot2vec FLAG 2 " << endl; |
---|
| 655 | |
---|
| 656 | chart->resize(width,height); // WPaintedWidget must be given explicit size |
---|
| 657 | chart->setMargin(10, Top | Bottom); // ? |
---|
| 658 | chart->setMargin(WLength::Auto, Left | Right); //? |
---|
| 659 | |
---|
| 660 | if (makeIcon) { |
---|
| 661 | chart->setLegendEnabled(false); // enable the legend |
---|
| 662 | chart->setPlotAreaPadding(0); |
---|
| 663 | chart->setAxisPadding(0); |
---|
| 664 | WFont xAxisFont = chart->axis(Wt::Chart::XAxis).labelFont(); |
---|
| 665 | xAxisFont.setSize(8); |
---|
| 666 | WFont yAxisFont = chart->axis(Wt::Chart::YAxis).labelFont(); |
---|
| 667 | yAxisFont.setSize(8); |
---|
| 668 | chart->axis(Wt::Chart::XAxis).setLabelFont(xAxisFont); |
---|
| 669 | chart->axis(Wt::Chart::YAxis).setLabelFont(yAxisFont); |
---|
| 670 | } |
---|
| 671 | // cout << " PspaApplication::chartPlot2vec FLAG 3 " << endl; |
---|
| 672 | |
---|
| 673 | #ifdef HAS_IMAGEMAGIC |
---|
| 674 | |
---|
| 675 | // cout << " PspaApplication::chartPlot2vec FLAG MAGIC " << endl; |
---|
| 676 | |
---|
| 677 | // no background |
---|
| 678 | chart->setBackground(WBrush(Wt::NoBrush)); |
---|
| 679 | |
---|
| 680 | // axis black |
---|
| 681 | chart->axis(XAxis).setPen(WColor("black")); |
---|
| 682 | chart->axis(YAxis).setPen(WColor("black")); |
---|
| 683 | |
---|
| 684 | std::string name; |
---|
| 685 | /* |
---|
| 686 | Wt::WRasterImage pngImage("png", 1000, 1000); |
---|
| 687 | Wt::WPainter p(&pngImage); |
---|
| 688 | chart->paint(p); |
---|
| 689 | name = workingDir_ + "/chart-"+sessionId ()+".png"; |
---|
| 690 | std::ofstream f(name.c_str(), std::ios::out |std::ios::trunc | std::ios::binary); |
---|
| 691 | pngImage.write(f); |
---|
| 692 | */ |
---|
| 693 | |
---|
| 694 | Wt::WPdfImage pdfImage("1000", "600"); |
---|
| 695 | { |
---|
| 696 | Wt::WPainter p1(&pdfImage); |
---|
| 697 | chart->paint(p1); |
---|
| 698 | } |
---|
| 699 | |
---|
| 700 | name = workingDir_ + "/chart-"+sessionId ()+".pdf"; |
---|
| 701 | std::ofstream f1(name.c_str(), std::ios::out | std::ios::binary); |
---|
| 702 | pdfImage.write(f1); |
---|
| 703 | |
---|
| 704 | new WText("<a href='workingArea/chart-"+sessionId ()+".pdf' target='_blank'>Sauvegarder l'image</a>",toto); |
---|
| 705 | |
---|
| 706 | #endif |
---|
| 707 | // cout << " PspaApplication::chartPlot2vec FLAG FIN" << endl; |
---|
| 708 | |
---|
| 709 | } |
---|
| 710 | |
---|
| 711 | |
---|
[468] | 712 | bool GWt_accelerator::areDataCoherent() |
---|
| 713 | { |
---|
| 714 | // FIXME |
---|
| 715 | cout << "***********************************" << endl; |
---|
[493] | 716 | cout << "** GWt_accelerator::areDataCoherent() **" << endl; |
---|
[468] | 717 | cout << "***********************************" << endl; |
---|
[493] | 718 | if ( !dataManager_ ) return false; |
---|
| 719 | return dataManager_->areDataCoherent(); |
---|
| 720 | // return true; |
---|
[468] | 721 | |
---|
[493] | 722 | // bool caMarche = true; |
---|
[468] | 723 | /* |
---|
| 724 | // initialize dataManager |
---|
| 725 | dtmanage_->initializeExecution(); |
---|
| 726 | |
---|
| 727 | // intialize User Interface |
---|
[469] | 728 | if (pspa_->getBeamLine_deprecated()) { |
---|
| 729 | pspa_->getBeamLine_deprecated()->initializeSoftwares(); |
---|
[468] | 730 | } |
---|
| 731 | |
---|
| 732 | string diagnosticErrors; |
---|
| 733 | string diagnosticWarnings; |
---|
| 734 | for (int a = 0; a < sections_.size(); a++) |
---|
| 735 | { |
---|
| 736 | string debString= sections_[a]->getFirstElementCurrentText().toUTF8(); |
---|
| 737 | string finString= sections_[a]->getLastElementCurrentText().toUTF8(); |
---|
[469] | 738 | int debut = pspa_->getBeamLine_deprecated()->getAbstractElementNumeroFromLabel(debString); |
---|
| 739 | int fin = pspa_->getBeamLine_deprecated()->getAbstractElementNumeroFromLabel(finString); |
---|
[468] | 740 | |
---|
| 741 | string currentSoft= sections_[a]->getSoftwareCurrentText().toUTF8(); |
---|
| 742 | nomDeLogiciel prog = nomDeLogiciel(currentSoft); |
---|
[469] | 743 | sectionToExecute* sectToExec = dtmanage_->addSectionToExecute(pspa_->getBeamLine_deprecated()->getAbstractElement(debut),debut,pspa_->getBeamLine_deprecated()->getAbstractElement(fin),fin,prog); |
---|
[468] | 744 | |
---|
| 745 | abstractSoftware* softToExec = sectToExec->getSoftware(); |
---|
| 746 | diagnosticErrors = ""; |
---|
| 747 | diagnosticWarnings = ""; |
---|
| 748 | for(int i = debut-1; i < fin; i++) // check sections |
---|
| 749 | { |
---|
[469] | 750 | if (!pspa_->getBeamLine_deprecated()) continue; |
---|
| 751 | abstractElement* elPtr= pspa_->getBeamLine_deprecated()->getAbstractElement(i); |
---|
[468] | 752 | if (!elPtr) continue; |
---|
| 753 | |
---|
| 754 | trivaluedBool tb = softToExec->doAcceptElement(elPtr->getNomdElement().getElementType()); |
---|
| 755 | cout << " GWt_softwarePanel::areDataCoherent() el " << elPtr->getLabel() << " tb= " << tb << endl; |
---|
| 756 | if (tb == TBoolOk ) { |
---|
| 757 | elPtr->setSoftware(softToExec); |
---|
| 758 | } else { |
---|
| 759 | elPtr->setSoftware(NULL); |
---|
| 760 | if (tb == TBoolIgnore) { |
---|
| 761 | if(prog.getString() != "unknownSoftware") diagnosticWarnings += elPtr->getLabel() + " will be ignored by "+ prog.getString() + "<br /> "; |
---|
| 762 | } else { |
---|
| 763 | // j'insiste pour remettre le nom generique de l'element refuse (glm / 30/03/2013) |
---|
| 764 | diagnosticErrors += elPtr->getNomdElement().getExpandedName() + " is not allowed with " + prog.getString() + "<br /> "; |
---|
| 765 | caMarche = false; |
---|
| 766 | } |
---|
| 767 | } |
---|
[469] | 768 | pspa_->getBeamLine_deprecated()->update(i); |
---|
[468] | 769 | } //i |
---|
| 770 | |
---|
| 771 | // set errors and warnings |
---|
| 772 | sections_[a]->setErrors(diagnosticErrors); |
---|
| 773 | sections_[a]->setWarnings(diagnosticWarnings); |
---|
| 774 | }//a |
---|
| 775 | */ |
---|
[493] | 776 | // return caMarche; |
---|
[468] | 777 | } |
---|
[455] | 778 | |
---|