[302] | 1 | // GWt_softwarePanel.cpp |
---|
| 2 | // PSPA |
---|
| 3 | // |
---|
| 4 | // Created by Garnier Laurent on 30/01/13. |
---|
| 5 | // Copyright (c) 2013 Garnier Laurent. All rights reserved. |
---|
| 6 | // |
---|
| 7 | |
---|
| 8 | #include <Wt/WLineEdit> |
---|
| 9 | #include <Wt/WText> |
---|
| 10 | #include <Wt/WComboBox> |
---|
| 11 | #include <Wt/WPanel> |
---|
| 12 | #include <Wt/WBreak> |
---|
| 13 | #include <Wt/WApplication> |
---|
[401] | 14 | #include <Wt/WVBoxLayout> |
---|
[302] | 15 | |
---|
| 16 | #include "GWt_softwarePanel.h" |
---|
| 17 | #include "GWt_dialog.h" |
---|
| 18 | #include "GWt_console.h" |
---|
| 19 | #include "GWt_globalParameters.h" |
---|
[401] | 20 | #include "GWt_sectionToExecute.h" |
---|
[427] | 21 | #include "GWt_pspaApplication.h" |
---|
[302] | 22 | |
---|
[431] | 23 | #define BAVARD 0 |
---|
| 24 | |
---|
[302] | 25 | GWt_softwarePanel::GWt_softwarePanel(dataManager* dataManager,PspaApplication* pspa) |
---|
[343] | 26 | : WContainerWidget() |
---|
| 27 | { |
---|
| 28 | dtmanage_ = dataManager; |
---|
| 29 | pspa_ = pspa; |
---|
[401] | 30 | |
---|
[343] | 31 | // bouton execute |
---|
| 32 | exec_go_ = new WPushButton("execute!"); |
---|
| 33 | exec_go_->clicked().connect(this, &GWt_softwarePanel::executer); |
---|
[427] | 34 | |
---|
[343] | 35 | // le panel |
---|
| 36 | WPanel *panelLogiciels = new WPanel(this); |
---|
[401] | 37 | panelLogiciels->setTitle(" sections of beam line for executing softwares "); |
---|
[343] | 38 | |
---|
| 39 | contenuSections_ = new WContainerWidget(); |
---|
| 40 | contenuSections_->addWidget(exec_go_); |
---|
| 41 | contenuSections_->addWidget(new WBreak()); |
---|
| 42 | contenuSections_->addWidget(new WBreak()); |
---|
| 43 | addSectionToExecuteW(); |
---|
| 44 | |
---|
| 45 | panelLogiciels->setCentralWidget(contenuSections_); |
---|
[302] | 46 | } |
---|
| 47 | |
---|
| 48 | GWt_softwarePanel::~GWt_softwarePanel() { |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | void GWt_softwarePanel::addSectionToExecuteW() |
---|
[427] | 52 | { |
---|
[431] | 53 | #if BAVARD > 0 |
---|
| 54 | cout << "***********************************" << endl; |
---|
| 55 | cout << " GWt_softwarePanel::addSectionToExecuteW() " << endl<<endl; |
---|
| 56 | #endif |
---|
| 57 | |
---|
[401] | 58 | abstractElement* premierElement; |
---|
| 59 | abstractElement* dernierElement; |
---|
| 60 | |
---|
| 61 | int premierIndex = 0; |
---|
| 62 | int dernierIndex = 0; |
---|
[427] | 63 | |
---|
[431] | 64 | cout << "sections_.size() = " << sections_.size() << endl; |
---|
| 65 | |
---|
[427] | 66 | // if there is no section |
---|
[405] | 67 | if(sections_.size() == 0) { |
---|
[427] | 68 | premierElement = pspa_->getBeamLine()->getAbstractElement(0); |
---|
| 69 | premierIndex = 0; |
---|
| 70 | |
---|
| 71 | // if this is not the first : |
---|
| 72 | // - first element will be the last of the previous section |
---|
| 73 | // (or the same if it is the last of the beam line) |
---|
| 74 | // - lastElement will be the last of the beam line |
---|
| 75 | // - software will be the first of the list |
---|
| 76 | |
---|
[343] | 77 | } else { |
---|
[405] | 78 | dernierElement = pspa_->getBeamLine()->getAbstractElement(pspa_->getBeamLine()->getBeamLineSize()-1); |
---|
| 79 | dernierIndex = pspa_->getBeamLine()->getBeamLineSize()-1; |
---|
[427] | 80 | |
---|
[405] | 81 | premierElement = dernierElement; |
---|
| 82 | premierIndex = dernierIndex; |
---|
[343] | 83 | } |
---|
| 84 | |
---|
[405] | 85 | dernierElement = pspa_->getBeamLine()->getAbstractElement(pspa_->getBeamLine()->getBeamLineSize()-1); |
---|
| 86 | dernierIndex = pspa_->getBeamLine()->getBeamLineSize()-1; |
---|
[343] | 87 | |
---|
[431] | 88 | dtmanage_->addSectionToExecute(premierElement,premierIndex,dernierElement,dernierIndex,nomDeLogiciel()); |
---|
[401] | 89 | |
---|
| 90 | std::string premierElementLabel = ""; |
---|
| 91 | std::string dernierElementLabel = ""; |
---|
| 92 | if (premierElement) { |
---|
| 93 | premierElementLabel = premierElement->getLabel(); |
---|
[343] | 94 | } |
---|
[401] | 95 | if (dernierElement) { |
---|
| 96 | dernierElementLabel = dernierElement->getLabel(); |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | WComboBox* lineFromCombo = new WComboBox(); |
---|
| 100 | WComboBox* lineToCombo = new WComboBox(); |
---|
| 101 | fillComboWithElements(lineFromCombo); |
---|
| 102 | fillComboWithElements(lineToCombo); |
---|
| 103 | |
---|
[405] | 104 | // set selection |
---|
| 105 | lineFromCombo->setCurrentIndex(premierIndex); |
---|
| 106 | lineToCombo->setCurrentIndex(dernierIndex); |
---|
| 107 | |
---|
[401] | 108 | WComboBox* softCombo = new WComboBox(); |
---|
| 109 | fillComboWithSoftwares(softCombo); |
---|
| 110 | |
---|
[431] | 111 | GWt_sectionToExecute* newSection = new GWt_sectionToExecute(lineFromCombo,lineToCombo,softCombo,createAddDeletePushButtons(sections_.size()),this); |
---|
[401] | 112 | |
---|
[407] | 113 | stringstream st; |
---|
| 114 | st << sections_.size(); |
---|
| 115 | |
---|
| 116 | // this is the mean to identify this section! |
---|
| 117 | newSection->setObjectName(st.str()); |
---|
| 118 | |
---|
[401] | 119 | // push back on sections vector |
---|
[405] | 120 | sections_.push_back(newSection); |
---|
[411] | 121 | contenuSections_->addWidget(newSection); |
---|
| 122 | updateSections(); |
---|
[302] | 123 | } |
---|
| 124 | |
---|
[431] | 125 | void GWt_softwarePanel::updateSections() |
---|
| 126 | { |
---|
| 127 | #if BAVARD > 0 |
---|
| 128 | cout << "***********************************" << endl; |
---|
| 129 | cout << " GWt_softwarePanel::updateSections() " << endl<<endl; |
---|
| 130 | #endif |
---|
| 131 | |
---|
| 132 | // update all sections in order to manage new/deleted items |
---|
| 133 | for (int a = 0; a < sections_.size(); a++) { |
---|
| 134 | fillComboWithElements(sections_[a]->getFirstElement()); |
---|
| 135 | fillComboWithElements(sections_[a]->getLastElement()); |
---|
| 136 | sections_[a]->getFirstElement()->setEnabled (true); |
---|
| 137 | sections_[a]->getLastElement()->setEnabled (true); |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | if (sections_.size() == 0) { |
---|
| 141 | return; |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | // the first element will always be the first element of the beamLine |
---|
| 145 | sections_[0]->getFirstElement()->setCurrentIndex(0); |
---|
| 146 | sections_[0]->getFirstElement()->setEnabled (false); |
---|
| 147 | |
---|
| 148 | // the last element will always be the last element of the beamLine |
---|
| 149 | sections_[sections_.size()-1]->getLastElement()->setCurrentIndex(sections_[sections_.size()-1]->getLastElement()->count()); |
---|
| 150 | sections_[sections_.size()-1]->getLastElement()->setEnabled(false); |
---|
| 151 | |
---|
| 152 | // set default values |
---|
| 153 | updateSectionSelection(); |
---|
| 154 | } |
---|
| 155 | |
---|
[367] | 156 | bool GWt_softwarePanel::updateSectionSelection() |
---|
[302] | 157 | { |
---|
[431] | 158 | #if BAVARD > 0 |
---|
| 159 | cout << "***********************************" << endl; |
---|
| 160 | cout << " GWt_softwarePanel::updateSectionSelection() " << endl<<endl; |
---|
| 161 | #endif |
---|
| 162 | |
---|
[401] | 163 | if ( dtmanage_->getJobListSize() == 0 ) return false; |
---|
[343] | 164 | |
---|
| 165 | // traitement de la premiere ligne |
---|
| 166 | // on impose le depart du calcul au premier element |
---|
| 167 | string premier = dtmanage_->getLabelFromElementNumero(1); |
---|
[405] | 168 | if (sections_.size() > 0) { |
---|
| 169 | sections_[0]->setFirstElementCurrentSelection(premier); |
---|
[401] | 170 | } |
---|
[343] | 171 | |
---|
[405] | 172 | Wt::WString currentString = sections_[0]->getLastElementCurrentText(); |
---|
[401] | 173 | int current = dtmanage_->getNumeroFromElementLabel(currentString.toUTF8()); |
---|
| 174 | |
---|
[343] | 175 | // si la fin est mal definie on prend toute la config par defaut |
---|
| 176 | if ( current <= 0 || current > dtmanage_->getBeamLineSize() ) |
---|
[431] | 177 | { |
---|
| 178 | current = dtmanage_->getBeamLineSize(); |
---|
| 179 | currentString = dtmanage_->getLabelFromElementNumero(current); |
---|
| 180 | if (sections_.size() > 0) { |
---|
| 181 | sections_[0]->setLastElementCurrentSelection(currentString); |
---|
| 182 | //... |
---|
| 183 | } |
---|
[302] | 184 | } |
---|
[343] | 185 | current++; |
---|
| 186 | currentString = dtmanage_->getLabelFromElementNumero(current); |
---|
| 187 | |
---|
| 188 | // traitement des suivantes (on avance d'un cran dans la liste) |
---|
[405] | 189 | for (int a = 1; a< sections_.size(); a++) |
---|
[302] | 190 | { |
---|
[343] | 191 | // debut |
---|
| 192 | if ( current > dtmanage_->getBeamLineSize() ) |
---|
[302] | 193 | { |
---|
[412] | 194 | sections_[a]->setErrors("This section element could not be after previous session last element"); |
---|
| 195 | exec_go_->disable(); |
---|
| 196 | return false; |
---|
[302] | 197 | } |
---|
[343] | 198 | |
---|
[405] | 199 | sections_[a]->setFirstElementCurrentSelection(currentString); |
---|
[401] | 200 | |
---|
[343] | 201 | // fin |
---|
[405] | 202 | string finString = sections_[a]->getLastElementCurrentText().toUTF8(); |
---|
[343] | 203 | |
---|
| 204 | int numeroFin = dtmanage_->getNumeroFromElementLabel( finString); |
---|
| 205 | |
---|
[412] | 206 | if ( numeroFin < current) |
---|
| 207 | { |
---|
| 208 | sections_[a]->setErrors("Last section element should be after first section element"); |
---|
| 209 | exec_go_->disable(); |
---|
| 210 | return false; |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | if (numeroFin > dtmanage_->getBeamLineSize()) |
---|
| 214 | { |
---|
| 215 | sections_[a]->setErrors("Last section element number is greater than the beam line size"); |
---|
| 216 | exec_go_->disable(); |
---|
| 217 | return false; |
---|
| 218 | } |
---|
[343] | 219 | |
---|
| 220 | // preparation de la ligne suivante |
---|
| 221 | current = numeroFin +1; |
---|
| 222 | currentString = dtmanage_->getLabelFromElementNumero(current); |
---|
[302] | 223 | } |
---|
[367] | 224 | // exec_go_->setDisabled(false); |
---|
[401] | 225 | |
---|
| 226 | if (!areDataCoherent()) { |
---|
[431] | 227 | #if BAVARD > 0 |
---|
| 228 | cout << " GWt_softwarePanel::addSectionToExecuteW() DISABLE" << endl; |
---|
| 229 | #endif |
---|
[401] | 230 | exec_go_->disable(); |
---|
| 231 | } else { |
---|
[431] | 232 | #if BAVARD > 0 |
---|
| 233 | cout << " GWt_softwarePanel::addSectionToExecuteW() ENABLE" << endl; |
---|
| 234 | #endif |
---|
[401] | 235 | exec_go_->enable(); |
---|
| 236 | } |
---|
| 237 | |
---|
[367] | 238 | return true; |
---|
[302] | 239 | } |
---|
| 240 | |
---|
| 241 | bool GWt_softwarePanel::areDataCoherent() |
---|
| 242 | { |
---|
[431] | 243 | #if BAVARD > 0 |
---|
| 244 | cout << "***********************************" << endl; |
---|
| 245 | cout << " GWt_softwarePanel::areDataCoherent() " << endl<<endl; |
---|
| 246 | #endif |
---|
| 247 | |
---|
[371] | 248 | bool caMarche = true; |
---|
[401] | 249 | |
---|
| 250 | // initialize dataManager |
---|
[371] | 251 | dtmanage_->initializeExecution(); |
---|
[401] | 252 | |
---|
| 253 | // intialize User Interface |
---|
| 254 | if (pspa_->getBeamLine()) { |
---|
| 255 | pspa_->getBeamLine()->initializeSoftwares(); |
---|
| 256 | } |
---|
[431] | 257 | |
---|
[401] | 258 | string diagnosticErrors; |
---|
| 259 | string diagnosticWarnings; |
---|
[431] | 260 | for (int a = 0; a < sections_.size(); a++) |
---|
[418] | 261 | { |
---|
[431] | 262 | string debString= sections_[a]->getFirstElementCurrentText().toUTF8(); |
---|
| 263 | string finString= sections_[a]->getLastElementCurrentText().toUTF8(); |
---|
[418] | 264 | int debut = pspa_->getBeamLine()->getAbstractElementNumeroFromLabel(debString); |
---|
| 265 | int fin = pspa_->getBeamLine()->getAbstractElementNumeroFromLabel(finString); |
---|
[419] | 266 | |
---|
[431] | 267 | string currentSoft= sections_[a]->getSoftwareCurrentText().toUTF8(); |
---|
| 268 | nomDeLogiciel prog = nomDeLogiciel(currentSoft); |
---|
| 269 | sectionToExecute* sectToExec = dtmanage_->addSectionToExecute(pspa_->getBeamLine()->getAbstractElement(debut),debut,pspa_->getBeamLine()->getAbstractElement(fin),fin,prog); |
---|
| 270 | |
---|
[419] | 271 | abstractSoftware* softToExec = sectToExec->getSoftware(); |
---|
[418] | 272 | diagnosticErrors = ""; |
---|
| 273 | diagnosticWarnings = ""; |
---|
[431] | 274 | for(int i = debut-1; i < fin; i++) // check sections |
---|
| 275 | { |
---|
| 276 | if (!pspa_->getBeamLine()) continue; |
---|
| 277 | abstractElement* elPtr= pspa_->getBeamLine()->getAbstractElement(i); |
---|
| 278 | if (!elPtr) continue; |
---|
[401] | 279 | |
---|
[431] | 280 | trivaluedBool tb = softToExec->doAcceptElement(elPtr->getNomdElement().getElementType()); |
---|
| 281 | if (tb == TBoolOk ) { |
---|
| 282 | elPtr->setSoftware(softToExec); |
---|
| 283 | } else { |
---|
| 284 | elPtr->setSoftware(NULL); |
---|
| 285 | if (tb == TBoolIgnore) { |
---|
| 286 | if(prog.getString() != "unknownSoftware") diagnosticWarnings += elPtr->getLabel() + " will be ignored by "+ prog.getString() + "<br /> "; |
---|
[418] | 287 | } else { |
---|
[431] | 288 | // j'insiste pour remettre le nom generique de l'element refuse (glm / 30/03/2013) |
---|
| 289 | diagnosticErrors += elPtr->getNomdElement().getExpandedName() + " is not allowed with " + prog.getString() + "<br /> "; |
---|
| 290 | caMarche = false; |
---|
[418] | 291 | } |
---|
| 292 | } |
---|
[431] | 293 | pspa_->getBeamLine()->update(i); |
---|
| 294 | } //i |
---|
| 295 | |
---|
[418] | 296 | // set errors and warnings |
---|
| 297 | sections_[a]->setErrors(diagnosticErrors); |
---|
| 298 | sections_[a]->setWarnings(diagnosticWarnings); |
---|
[431] | 299 | }//a |
---|
[359] | 300 | |
---|
[371] | 301 | return caMarche; |
---|
[302] | 302 | } |
---|
| 303 | |
---|
[407] | 304 | void GWt_softwarePanel::deleteSectionToExecuteW(int sectionLabel) |
---|
[302] | 305 | { |
---|
[407] | 306 | stringstream st; |
---|
| 307 | st << sectionLabel; |
---|
| 308 | std::string sectionName = st.str(); |
---|
| 309 | |
---|
| 310 | if ( dtmanage_->getJobListSize() == 0 ) return; |
---|
| 311 | for (unsigned int sectionIndex = 0; sectionIndex< sections_.size(); sectionIndex++) { |
---|
| 312 | if (sections_[sectionIndex]->objectName() == sectionName) { |
---|
[401] | 313 | |
---|
[407] | 314 | // delete from dataManager |
---|
| 315 | dtmanage_->clearSectionToExecute(sectionIndex); |
---|
| 316 | |
---|
| 317 | // delete from User Interface |
---|
| 318 | contenuSections_->removeWidget(sections_[sectionIndex]); |
---|
| 319 | delete sections_[sectionIndex]; |
---|
| 320 | sections_.erase (sections_.begin()+sectionIndex); |
---|
| 321 | } |
---|
| 322 | } |
---|
[302] | 323 | } |
---|
| 324 | |
---|
[431] | 325 | void GWt_softwarePanel::executer() |
---|
[302] | 326 | { |
---|
[431] | 327 | cout << "***********************************" << endl; |
---|
| 328 | cout << " GWt_softwarePanel::executer() " << endl<<endl; |
---|
[405] | 329 | |
---|
[401] | 330 | if (!areDataCoherent()) { |
---|
[358] | 331 | return; |
---|
[427] | 332 | } |
---|
[401] | 333 | |
---|
[431] | 334 | //static_cast<GWt_globalParameters*>(pspa_->getGlobalParam())->updateGlobals(); |
---|
[343] | 335 | |
---|
| 336 | GWt_dialog calculDialog("Calcul en cours", "Veuillez patienter...", GWt_dialog::Wait, true,false); |
---|
| 337 | calculDialog.show(); |
---|
[302] | 338 | |
---|
[343] | 339 | wApp->processEvents(); |
---|
| 340 | |
---|
| 341 | if (!dtmanage_->executeAll()) { |
---|
[431] | 342 | GWt_dialog warningDialog("PSPA : Echec", " echec lors de l'exécution !", GWt_dialog::Error, true,true); |
---|
[343] | 343 | warningDialog.exec(); |
---|
| 344 | } |
---|
| 345 | |
---|
[367] | 346 | // exec_go_->setDisabled(true); |
---|
[343] | 347 | calculDialog.hide(); |
---|
| 348 | pspa_->faireDessin(); |
---|
[302] | 349 | } |
---|
[401] | 350 | |
---|
[431] | 351 | void GWt_softwarePanel::fillComboWithElements(Wt::WComboBox* cBox) |
---|
| 352 | { |
---|
[401] | 353 | if (cBox == NULL) return; |
---|
| 354 | |
---|
| 355 | // get the last item selected |
---|
[431] | 356 | WString selectedString = cBox->currentText(); |
---|
[401] | 357 | cBox->clear(); |
---|
| 358 | |
---|
[431] | 359 | for(int a = 0; a < pspa_->getBeamLine()->getBeamLineSize(); a++) { |
---|
[401] | 360 | abstractElement* abs = pspa_->getBeamLine()->getAbstractElement(a); |
---|
[431] | 361 | if (abs != NULL) { |
---|
[401] | 362 | cBox->addItem(abs->getLabel()); |
---|
| 363 | } |
---|
| 364 | } |
---|
| 365 | |
---|
[431] | 366 | for(int a = 0; a < cBox->count(); a++) { |
---|
[401] | 367 | if (cBox->itemText (a) == selectedString) { |
---|
| 368 | cBox->setCurrentIndex(a); |
---|
| 369 | } |
---|
| 370 | } |
---|
[405] | 371 | cBox->refresh(); |
---|
[401] | 372 | } |
---|
| 373 | |
---|
[431] | 374 | void GWt_softwarePanel::fillComboWithSoftwares(Wt::WComboBox* cBox) |
---|
| 375 | { |
---|
| 376 | #if BAVARD > 0 |
---|
| 377 | cout << "***********************************" << endl; |
---|
| 378 | cout << " GWt_softwarePanel::fillComboWithSoftwares " << endl<<endl; |
---|
| 379 | #endif |
---|
[401] | 380 | |
---|
| 381 | if (cBox == NULL) return; |
---|
| 382 | cBox->clear(); |
---|
| 383 | |
---|
| 384 | unsigned nb = nomDeLogiciel::getNumberOfSoftwares(); |
---|
| 385 | unsigned k; |
---|
[431] | 386 | for(k = 0; k <= nb; k++) { //xx |
---|
[401] | 387 | cBox->addItem(nomDeLogiciel(k).getString()); |
---|
| 388 | } |
---|
[431] | 389 | cBox->setCurrentIndex(nb); // xx |
---|
[405] | 390 | cBox->refresh(); |
---|
[401] | 391 | } |
---|
| 392 | |
---|
[431] | 393 | Wt::WContainerWidget* GWt_softwarePanel::createAddDeletePushButtons(int sectionNumber) |
---|
| 394 | { |
---|
[401] | 395 | WContainerWidget* buttonContainer= new WContainerWidget(); |
---|
| 396 | |
---|
| 397 | Wt::WHBoxLayout* buttonContainerLayout = new Wt::WHBoxLayout(); |
---|
| 398 | buttonContainerLayout->setContentsMargins(0,0,0,0); |
---|
| 399 | // preparation du bouton add |
---|
| 400 | WPushButton* exec_add = new WPushButton("+"); |
---|
| 401 | exec_add->clicked().connect(this, &GWt_softwarePanel::addSectionToExecuteW); |
---|
| 402 | exec_add->setStyleClass("roundButton"); |
---|
| 403 | exec_add->setMaximumSize(20,20); |
---|
| 404 | exec_add->setToolTip("Add new section"); |
---|
| 405 | |
---|
| 406 | // preparation du bouton delete |
---|
| 407 | WPushButton* exec_delete = new WPushButton("-"); |
---|
| 408 | // warningsContainer_->setStyleClass("warningsContainer"); |
---|
[407] | 409 | |
---|
| 410 | exec_delete->clicked().connect(boost::bind(&GWt_softwarePanel::deleteSectionToExecuteW, this, sectionNumber)); |
---|
[401] | 411 | exec_delete->setStyleClass("roundButton"); |
---|
| 412 | exec_delete->setMaximumSize(20,20); |
---|
[405] | 413 | exec_delete->setToolTip("Remove this section"); |
---|
[401] | 414 | |
---|
| 415 | buttonContainerLayout->addWidget(exec_add); |
---|
| 416 | buttonContainerLayout->addWidget(exec_delete); |
---|
| 417 | buttonContainer->setLayout(buttonContainerLayout); |
---|
| 418 | |
---|
| 419 | return buttonContainer; |
---|
[413] | 420 | } |
---|