[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" |
---|
[455] | 19 | #include "GWt_sector.h" |
---|
[302] | 20 | #include "GWt_globalParameters.h" |
---|
[401] | 21 | #include "GWt_sectionToExecute.h" |
---|
[427] | 22 | #include "GWt_pspaApplication.h" |
---|
[302] | 23 | |
---|
[431] | 24 | #define BAVARD 0 |
---|
| 25 | |
---|
[455] | 26 | GWt_softwarePanel::GWt_softwarePanel(dataManager* dataManager,GWt_sector* sect) |
---|
| 27 | : WContainerWidget(), |
---|
| 28 | dtmanage_(dataManager), |
---|
| 29 | UIsector_(sect) |
---|
[343] | 30 | { |
---|
[401] | 31 | |
---|
[343] | 32 | // le panel |
---|
| 33 | WPanel *panelLogiciels = new WPanel(this); |
---|
[401] | 34 | panelLogiciels->setTitle(" sections of beam line for executing softwares "); |
---|
[343] | 35 | |
---|
| 36 | contenuSections_ = new WContainerWidget(); |
---|
| 37 | contenuSections_->addWidget(new WBreak()); |
---|
| 38 | contenuSections_->addWidget(new WBreak()); |
---|
[468] | 39 | displayFromControler(); |
---|
[343] | 40 | |
---|
| 41 | panelLogiciels->setCentralWidget(contenuSections_); |
---|
[302] | 42 | } |
---|
| 43 | |
---|
| 44 | GWt_softwarePanel::~GWt_softwarePanel() { |
---|
| 45 | } |
---|
| 46 | |
---|
[468] | 47 | void GWt_softwarePanel::displayFromControler() |
---|
[427] | 48 | { |
---|
[431] | 49 | #if BAVARD > 0 |
---|
| 50 | cout << "***********************************" << endl; |
---|
| 51 | cout << " GWt_softwarePanel::addSectionToExecuteW() " << endl<<endl; |
---|
| 52 | #endif |
---|
| 53 | |
---|
[468] | 54 | // Clear all |
---|
| 55 | contenuSections_->clear(); |
---|
[427] | 56 | |
---|
[468] | 57 | // Get all sectionsToExecute from this sector |
---|
| 58 | if (!UIsector_->getSectorControler()) { |
---|
| 59 | return; |
---|
[343] | 60 | } |
---|
| 61 | |
---|
[468] | 62 | if (UIsector_->getSectorControler()->getSectionsToExecute().size() == 0) { |
---|
| 63 | // FIXME : Add a message to tell the user to add first an element |
---|
| 64 | } else { |
---|
[471] | 65 | |
---|
[474] | 66 | unsigned int firstSectionToExecuteIndex = 0; |
---|
[468] | 67 | for (unsigned int a=0; a<UIsector_->getSectorControler()->getSectionsToExecute().size(); a++) { |
---|
| 68 | abstractElement* premierElement = NULL; |
---|
| 69 | abstractElement* dernierElement = NULL; |
---|
| 70 | |
---|
| 71 | std::string premierElementLabel = ""; |
---|
| 72 | std::string dernierElementLabel = ""; |
---|
| 73 | if (premierElement) { |
---|
| 74 | premierElementLabel = premierElement->getLabel(); |
---|
| 75 | } |
---|
| 76 | if (dernierElement) { |
---|
| 77 | dernierElementLabel = dernierElement->getLabel(); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | WComboBox* lineFromCombo = new WComboBox(); |
---|
| 81 | WComboBox* lineToCombo = new WComboBox(); |
---|
| 82 | fillComboWithElements(lineFromCombo); |
---|
| 83 | fillComboWithElements(lineToCombo); |
---|
| 84 | |
---|
[469] | 85 | // set to first |
---|
[471] | 86 | lineFromCombo->setCurrentIndex(firstSectionToExecuteIndex); |
---|
[469] | 87 | // set to last |
---|
[474] | 88 | lineToCombo->setCurrentIndex(firstSectionToExecuteIndex + (unsigned int)UIsector_->getSectorControler()->getSectionsToExecute()[a]->getElements().size() - 1); |
---|
[468] | 89 | |
---|
| 90 | WComboBox* softCombo = new WComboBox(); |
---|
[469] | 91 | sectionToExecute* sect = UIsector_->getSectorControler()->getSectionsToExecute()[a]; |
---|
[468] | 92 | |
---|
[469] | 93 | fillComboWithSoftwares(softCombo,UIsector_->getSectorControler()->getSectionsToExecute()[a]->getSoftware()->getName()); |
---|
| 94 | |
---|
| 95 | // disable the "to" comboBox |
---|
| 96 | lineToCombo->disable(); |
---|
| 97 | |
---|
| 98 | // disable the first "from" comboBox |
---|
| 99 | if (a==0) { |
---|
| 100 | lineFromCombo->disable(); |
---|
| 101 | } |
---|
| 102 | // disable the last "to" comboBox |
---|
| 103 | if (a==UIsector_->getSectorControler()->getSectionsToExecute().size()-1) { |
---|
| 104 | lineToCombo->disable(); |
---|
| 105 | } |
---|
| 106 | |
---|
[468] | 107 | // Add the sectionToExecute Widget |
---|
[469] | 108 | GWt_sectionToExecute* newSection = new GWt_sectionToExecute(lineFromCombo,lineToCombo,softCombo,createAddDeletePushButtons(a),UIsector_->getSectorControler()->getSectionsToExecute()[a],UIsector_); |
---|
[468] | 109 | |
---|
[480] | 110 | /* // FIXME ? |
---|
| 111 | stringstream st; |
---|
| 112 | st << UIsectionsToExecute_deprecated_.size(); |
---|
| 113 | |
---|
| 114 | // this is the mean to identify this section! |
---|
| 115 | newSection->setObjectName(st.str()); |
---|
| 116 | |
---|
| 117 | // push back on sections vector |
---|
| 118 | UIsectionsToExecute_deprecated_.push_back(newSection); |
---|
| 119 | */ |
---|
| 120 | contenuSections_->addWidget(newSection); |
---|
| 121 | // updateSections(); |
---|
[468] | 122 | |
---|
[471] | 123 | firstSectionToExecuteIndex += UIsector_->getSectorControler()->getSectionsToExecute()[a]->getElements().size(); |
---|
[468] | 124 | } |
---|
[343] | 125 | } |
---|
[468] | 126 | } |
---|
[401] | 127 | |
---|
[431] | 128 | void GWt_softwarePanel::updateSections() |
---|
| 129 | { |
---|
| 130 | #if BAVARD > 0 |
---|
| 131 | cout << "***********************************" << endl; |
---|
| 132 | cout << " GWt_softwarePanel::updateSections() " << endl<<endl; |
---|
| 133 | #endif |
---|
[469] | 134 | |
---|
| 135 | /* |
---|
[431] | 136 | // update all sections in order to manage new/deleted items |
---|
[471] | 137 | for (int a = 0; a < UIsectionsToExecute_deprecated_.size(); a++) { |
---|
| 138 | fillComboWithElements(UIsectionsToExecute_deprecated_[a]->getFirstElement()); |
---|
| 139 | fillComboWithElements(UIsectionsToExecute_deprecated_[a]->getLastElement()); |
---|
| 140 | UIsectionsToExecute_deprecated_[a]->getFirstElement()->setEnabled (true); |
---|
| 141 | UIsectionsToExecute_deprecated_[a]->getLastElement()->setEnabled (true); |
---|
[431] | 142 | } |
---|
| 143 | |
---|
[471] | 144 | if (UIsectionsToExecute_deprecated_;.size() == 0) { |
---|
[431] | 145 | return; |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | // the first element will always be the first element of the beamLine |
---|
[471] | 149 | UIsectionsToExecute_deprecated_[0]->getFirstElement()->setCurrentIndex(0); |
---|
| 150 | UIsectionsToExecute_deprecated_[0]->getFirstElement()->setEnabled (false); |
---|
[431] | 151 | |
---|
| 152 | // the last element will always be the last element of the beamLine |
---|
[471] | 153 | UIsectionsToExecute_deprecated_[UIsectionsToExecute_deprecated_.size()-1]->getLastElement()->setCurrentIndex(UIsectionsToExecute_deprecated_[UIsectionsToExecute_deprecated_;.size()-1]->getLastElement()->count()); |
---|
| 154 | UIsectionsToExecute_deprecated_[UIsectionsToExecute_deprecated_.size()-1]->getLastElement()->setEnabled(false); |
---|
[431] | 155 | |
---|
| 156 | // set default values |
---|
| 157 | updateSectionSelection(); |
---|
[469] | 158 | */ |
---|
[431] | 159 | } |
---|
| 160 | |
---|
[367] | 161 | bool GWt_softwarePanel::updateSectionSelection() |
---|
[302] | 162 | { |
---|
[431] | 163 | #if BAVARD > 0 |
---|
| 164 | cout << "***********************************" << endl; |
---|
| 165 | cout << " GWt_softwarePanel::updateSectionSelection() " << endl<<endl; |
---|
| 166 | #endif |
---|
| 167 | |
---|
[401] | 168 | if ( dtmanage_->getJobListSize() == 0 ) return false; |
---|
[343] | 169 | |
---|
| 170 | // traitement de la premiere ligne |
---|
| 171 | // on impose le depart du calcul au premier element |
---|
[455] | 172 | string premier = ""; |
---|
| 173 | if (UIsector_->getSectorControler()) { |
---|
| 174 | if (UIsector_->getSectorControler()->getSectionsToExecute().size() > 0) { |
---|
| 175 | if (UIsector_->getSectorControler()->getSectionsToExecute()[0]->getElements().size() > 0) { |
---|
| 176 | premier = UIsector_->getSectorControler()->getSectionsToExecute()[0]->getElements()[0]->getLabel(); |
---|
| 177 | } |
---|
| 178 | } |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | // FIXME : A réécrire |
---|
| 182 | /* |
---|
[471] | 183 | if (UIsectionsToExecute_deprecated_.size() > 0) { |
---|
| 184 | UIsectionsToExecute_deprecated_[0]->setFirstElementCurrentSelection(premier); |
---|
[401] | 185 | } |
---|
[343] | 186 | |
---|
[471] | 187 | Wt::WString currentString = UIsectionsToExecute_deprecated_[0]->getLastElementCurrentText(); |
---|
[401] | 188 | int current = dtmanage_->getNumeroFromElementLabel(currentString.toUTF8()); |
---|
| 189 | |
---|
[343] | 190 | // si la fin est mal definie on prend toute la config par defaut |
---|
| 191 | if ( current <= 0 || current > dtmanage_->getBeamLineSize() ) |
---|
[431] | 192 | { |
---|
| 193 | current = dtmanage_->getBeamLineSize(); |
---|
| 194 | currentString = dtmanage_->getLabelFromElementNumero(current); |
---|
[471] | 195 | if (UIsectionsToExecute_deprecated_.size() > 0) { |
---|
| 196 | UIsectionsToExecute_deprecated_[0]->setLastElementCurrentSelection(currentString); |
---|
[431] | 197 | //... |
---|
| 198 | } |
---|
[302] | 199 | } |
---|
[343] | 200 | current++; |
---|
| 201 | currentString = dtmanage_->getLabelFromElementNumero(current); |
---|
| 202 | |
---|
| 203 | // traitement des suivantes (on avance d'un cran dans la liste) |
---|
[471] | 204 | for (int a = 1; a< UIsectionsToExecute_deprecated_;.size(); a++) |
---|
[302] | 205 | { |
---|
[343] | 206 | // debut |
---|
| 207 | if ( current > dtmanage_->getBeamLineSize() ) |
---|
[302] | 208 | { |
---|
[471] | 209 | UIsectionsToExecute_deprecated_;[a]->setErrors("This section element could not be after previous session last element"); |
---|
[412] | 210 | exec_go_->disable(); |
---|
| 211 | return false; |
---|
[302] | 212 | } |
---|
[343] | 213 | |
---|
[471] | 214 | UIsectionsToExecute_deprecated_;[a]->setFirstElementCurrentSelection(currentString); |
---|
[401] | 215 | |
---|
[343] | 216 | // fin |
---|
[471] | 217 | string finString = UIsectionsToExecute_deprecated_;[a]->getLastElementCurrentText().toUTF8(); |
---|
[343] | 218 | |
---|
| 219 | int numeroFin = dtmanage_->getNumeroFromElementLabel( finString); |
---|
| 220 | |
---|
[412] | 221 | if ( numeroFin < current) |
---|
| 222 | { |
---|
[471] | 223 | UIsectionsToExecute_deprecated_;[a]->setErrors("Last section element should be after first section element"); |
---|
[412] | 224 | exec_go_->disable(); |
---|
| 225 | return false; |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | if (numeroFin > dtmanage_->getBeamLineSize()) |
---|
| 229 | { |
---|
[471] | 230 | UIsectionsToExecute_deprecated_;[a]->setErrors("Last section element number is greater than the beam line size"); |
---|
[412] | 231 | exec_go_->disable(); |
---|
| 232 | return false; |
---|
| 233 | } |
---|
[343] | 234 | |
---|
| 235 | // preparation de la ligne suivante |
---|
| 236 | current = numeroFin +1; |
---|
| 237 | currentString = dtmanage_->getLabelFromElementNumero(current); |
---|
[302] | 238 | } |
---|
[367] | 239 | // exec_go_->setDisabled(false); |
---|
[401] | 240 | |
---|
| 241 | if (!areDataCoherent()) { |
---|
[431] | 242 | #if BAVARD > 0 |
---|
| 243 | cout << " GWt_softwarePanel::addSectionToExecuteW() DISABLE" << endl; |
---|
| 244 | #endif |
---|
[401] | 245 | exec_go_->disable(); |
---|
| 246 | } else { |
---|
[431] | 247 | #if BAVARD > 0 |
---|
| 248 | cout << " GWt_softwarePanel::addSectionToExecuteW() ENABLE" << endl; |
---|
| 249 | #endif |
---|
[401] | 250 | exec_go_->enable(); |
---|
| 251 | } |
---|
[455] | 252 | */ |
---|
[367] | 253 | return true; |
---|
[302] | 254 | } |
---|
| 255 | |
---|
[431] | 256 | |
---|
[468] | 257 | void GWt_softwarePanel::addSectionToExecute() { |
---|
| 258 | // We put the last element of the previous sectionToExecute inside |
---|
[401] | 259 | |
---|
[468] | 260 | // Get the last element from previous section |
---|
| 261 | if (!UIsector_->getSectorControler()) { |
---|
| 262 | return; |
---|
[401] | 263 | } |
---|
[471] | 264 | unsigned long s = UIsector_->getSectorControler()->getSectionsToExecute().size(); |
---|
[468] | 265 | if (s > 0) { |
---|
| 266 | abstractElement* abs = UIsector_->getSectorControler()->getSectionsToExecute()[s-1]->getLastElement(); |
---|
[474] | 267 | UIsector_->getSectorControler()->addSectionToExecute(new sectionToExecute(abs,NULL,dtmanage_,UIsector_->getSectorControler())); |
---|
[471] | 268 | UIsector_->getSectorControler()->getSectionsToExecute()[s-1]->removeLastElement(); |
---|
[468] | 269 | } |
---|
[419] | 270 | |
---|
[468] | 271 | |
---|
| 272 | displayFromControler(); |
---|
[471] | 273 | UIsector_->getBeamLineWidget()->buildBeamLineWidget(); |
---|
[468] | 274 | } |
---|
[431] | 275 | |
---|
[401] | 276 | |
---|
[468] | 277 | void GWt_softwarePanel::deleteSectionToExecute(int sectionLabel) |
---|
[302] | 278 | { |
---|
[436] | 279 | #if BAVARD > 0 |
---|
| 280 | cout << "***********************************" << endl; |
---|
| 281 | cout << " GWt_softwarePanel::deleteSectionToExecuteW()" << endl<<endl; |
---|
| 282 | #endif |
---|
| 283 | |
---|
[407] | 284 | stringstream st; |
---|
| 285 | st << sectionLabel; |
---|
| 286 | std::string sectionName = st.str(); |
---|
[471] | 287 | //FIXME |
---|
[407] | 288 | |
---|
[471] | 289 | /* if ( dtmanage_->getJobListSize() == 0 ) return; |
---|
| 290 | for (unsigned int sectionIndex = 0; sectionIndex< UIsectionsToExecute_deprecated_.size(); sectionIndex++) { |
---|
| 291 | if (UIsectionsToExecute_deprecated_[sectionIndex]->objectName() == sectionName) { |
---|
[401] | 292 | |
---|
[407] | 293 | // delete from dataManager |
---|
[455] | 294 | UIsector_->getSectorControler()->clearSectionToExecute(sectionIndex); |
---|
[407] | 295 | |
---|
| 296 | // delete from User Interface |
---|
[471] | 297 | contenuSections_->removeWidget(UIsectionsToExecute_deprecated_[sectionIndex]); |
---|
| 298 | delete UIsectionsToExecute_deprecated_[sectionIndex]; |
---|
| 299 | UIsectionsToExecute_deprecated_.erase (UIsectionsToExecute_deprecated_.begin()+sectionIndex); |
---|
[407] | 300 | } |
---|
| 301 | } |
---|
[471] | 302 | */ |
---|
[468] | 303 | displayFromControler(); |
---|
[302] | 304 | } |
---|
| 305 | |
---|
[405] | 306 | |
---|
[431] | 307 | void GWt_softwarePanel::fillComboWithElements(Wt::WComboBox* cBox) |
---|
| 308 | { |
---|
[401] | 309 | |
---|
[468] | 310 | if (cBox == NULL) return; |
---|
[455] | 311 | |
---|
[468] | 312 | if (!UIsector_->getSectorControler()) { |
---|
| 313 | return; |
---|
| 314 | } |
---|
| 315 | for (unsigned int a=0; a < UIsector_->getSectorControler()->getSectionsToExecute().size(); a++) { |
---|
| 316 | for(unsigned int b=0; b < UIsector_->getSectorControler()->getSectionsToExecute()[a]->getElements().size(); b++) { |
---|
| 317 | |
---|
| 318 | abstractElement* abs = UIsector_->getSectorControler()->getSectionsToExecute()[a]->getElements()[b]; |
---|
| 319 | if (abs != NULL) { |
---|
| 320 | cBox->addItem(abs->getLabel()); |
---|
| 321 | } |
---|
[401] | 322 | } |
---|
| 323 | } |
---|
| 324 | } |
---|
| 325 | |
---|
[469] | 326 | void GWt_softwarePanel::fillComboWithSoftwares(Wt::WComboBox* cBox, std::string selected) |
---|
[431] | 327 | { |
---|
| 328 | #if BAVARD > 0 |
---|
| 329 | cout << "***********************************" << endl; |
---|
| 330 | cout << " GWt_softwarePanel::fillComboWithSoftwares " << endl<<endl; |
---|
| 331 | #endif |
---|
[401] | 332 | |
---|
| 333 | if (cBox == NULL) return; |
---|
| 334 | cBox->clear(); |
---|
| 335 | |
---|
| 336 | unsigned nb = nomDeLogiciel::getNumberOfSoftwares(); |
---|
| 337 | unsigned k; |
---|
[431] | 338 | for(k = 0; k <= nb; k++) { //xx |
---|
[401] | 339 | cBox->addItem(nomDeLogiciel(k).getString()); |
---|
[469] | 340 | if (nomDeLogiciel(k).getString() == selected) { |
---|
| 341 | cBox->setCurrentIndex(cBox->count()-1); |
---|
| 342 | } |
---|
[401] | 343 | } |
---|
[405] | 344 | cBox->refresh(); |
---|
[401] | 345 | } |
---|
| 346 | |
---|
[431] | 347 | Wt::WContainerWidget* GWt_softwarePanel::createAddDeletePushButtons(int sectionNumber) |
---|
| 348 | { |
---|
[401] | 349 | WContainerWidget* buttonContainer= new WContainerWidget(); |
---|
| 350 | |
---|
| 351 | Wt::WHBoxLayout* buttonContainerLayout = new Wt::WHBoxLayout(); |
---|
| 352 | buttonContainerLayout->setContentsMargins(0,0,0,0); |
---|
| 353 | // preparation du bouton add |
---|
| 354 | WPushButton* exec_add = new WPushButton("+"); |
---|
[468] | 355 | exec_add->clicked().connect(this, &GWt_softwarePanel::addSectionToExecute); |
---|
[401] | 356 | exec_add->setStyleClass("roundButton"); |
---|
| 357 | exec_add->setMaximumSize(20,20); |
---|
| 358 | exec_add->setToolTip("Add new section"); |
---|
| 359 | |
---|
| 360 | // preparation du bouton delete |
---|
| 361 | WPushButton* exec_delete = new WPushButton("-"); |
---|
| 362 | // warningsContainer_->setStyleClass("warningsContainer"); |
---|
[407] | 363 | |
---|
[468] | 364 | exec_delete->clicked().connect(boost::bind(&GWt_softwarePanel::deleteSectionToExecute, this, sectionNumber)); |
---|
[401] | 365 | exec_delete->setStyleClass("roundButton"); |
---|
| 366 | exec_delete->setMaximumSize(20,20); |
---|
[405] | 367 | exec_delete->setToolTip("Remove this section"); |
---|
[401] | 368 | |
---|
| 369 | buttonContainerLayout->addWidget(exec_add); |
---|
| 370 | buttonContainerLayout->addWidget(exec_delete); |
---|
| 371 | buttonContainer->setLayout(buttonContainerLayout); |
---|
| 372 | |
---|
| 373 | return buttonContainer; |
---|
[413] | 374 | } |
---|