// GWt_softwarePanel.cpp // PSPA // // Created by Garnier Laurent on 30/01/13. // Copyright (c) 2013 Garnier Laurent. All rights reserved. // #include #include #include #include #include #include #include #include "GWt_softwarePanel.h" #include "GWt_dialog.h" #include "GWt_console.h" #include "GWt_globalParameters.h" #include "GWt_sectionToExecute.h" #include "GWt_pspaApplication.h" #define BAVARD 0 GWt_softwarePanel::GWt_softwarePanel(dataManager* dataManager,PspaApplication* pspa) : WContainerWidget() { dtmanage_ = dataManager; pspa_ = pspa; // bouton execute exec_go_ = new WPushButton("execute!"); exec_go_->clicked().connect(this, &GWt_softwarePanel::executer); // le panel WPanel *panelLogiciels = new WPanel(this); panelLogiciels->setTitle(" sections of beam line for executing softwares "); contenuSections_ = new WContainerWidget(); contenuSections_->addWidget(exec_go_); contenuSections_->addWidget(new WBreak()); contenuSections_->addWidget(new WBreak()); addSectionToExecuteW(); panelLogiciels->setCentralWidget(contenuSections_); } GWt_softwarePanel::~GWt_softwarePanel() { } void GWt_softwarePanel::addSectionToExecuteW() { #if BAVARD > 0 cout << "***********************************" << endl; cout << " GWt_softwarePanel::addSectionToExecuteW() " << endl<getLabel(); } if (dernierElement) { dernierElementLabel = dernierElement->getLabel(); } WComboBox* lineFromCombo = new WComboBox(); WComboBox* lineToCombo = new WComboBox(); fillComboWithElements(lineFromCombo); fillComboWithElements(lineToCombo); // set selection lineFromCombo->setCurrentIndex(premierIndex); lineToCombo->setCurrentIndex(dernierIndex); WComboBox* softCombo = new WComboBox(); fillComboWithSoftwares(softCombo); GWt_sectionToExecute* newSection = new GWt_sectionToExecute(lineFromCombo,lineToCombo,softCombo,createAddDeletePushButtons(sections_.size()),this); stringstream st; st << sections_.size(); // this is the mean to identify this section! newSection->setObjectName(st.str()); // push back on sections vector sections_.push_back(newSection); contenuSections_->addWidget(newSection); updateSections(); } void GWt_softwarePanel::updateSections() { #if BAVARD > 0 cout << "***********************************" << endl; cout << " GWt_softwarePanel::updateSections() " << endl<getFirstElement()); fillComboWithElements(sections_[a]->getLastElement()); sections_[a]->getFirstElement()->setEnabled (true); sections_[a]->getLastElement()->setEnabled (true); } if (sections_.size() == 0) { return; } // the first element will always be the first element of the beamLine sections_[0]->getFirstElement()->setCurrentIndex(0); sections_[0]->getFirstElement()->setEnabled (false); // the last element will always be the last element of the beamLine sections_[sections_.size()-1]->getLastElement()->setCurrentIndex(sections_[sections_.size()-1]->getLastElement()->count()); sections_[sections_.size()-1]->getLastElement()->setEnabled(false); // set default values updateSectionSelection(); } bool GWt_softwarePanel::updateSectionSelection() { #if BAVARD > 0 cout << "***********************************" << endl; cout << " GWt_softwarePanel::updateSectionSelection() " << endl<getJobListSize() == 0 ) return false; // traitement de la premiere ligne // on impose le depart du calcul au premier element string premier = dtmanage_->getLabelFromElementNumero(1); if (sections_.size() > 0) { sections_[0]->setFirstElementCurrentSelection(premier); } Wt::WString currentString = sections_[0]->getLastElementCurrentText(); int current = dtmanage_->getNumeroFromElementLabel(currentString.toUTF8()); // si la fin est mal definie on prend toute la config par defaut if ( current <= 0 || current > dtmanage_->getBeamLineSize() ) { current = dtmanage_->getBeamLineSize(); currentString = dtmanage_->getLabelFromElementNumero(current); if (sections_.size() > 0) { sections_[0]->setLastElementCurrentSelection(currentString); //... } } current++; currentString = dtmanage_->getLabelFromElementNumero(current); // traitement des suivantes (on avance d'un cran dans la liste) for (int a = 1; a< sections_.size(); a++) { // debut if ( current > dtmanage_->getBeamLineSize() ) { sections_[a]->setErrors("This section element could not be after previous session last element"); exec_go_->disable(); return false; } sections_[a]->setFirstElementCurrentSelection(currentString); // fin string finString = sections_[a]->getLastElementCurrentText().toUTF8(); int numeroFin = dtmanage_->getNumeroFromElementLabel( finString); if ( numeroFin < current) { sections_[a]->setErrors("Last section element should be after first section element"); exec_go_->disable(); return false; } if (numeroFin > dtmanage_->getBeamLineSize()) { sections_[a]->setErrors("Last section element number is greater than the beam line size"); exec_go_->disable(); return false; } // preparation de la ligne suivante current = numeroFin +1; currentString = dtmanage_->getLabelFromElementNumero(current); } // exec_go_->setDisabled(false); if (!areDataCoherent()) { #if BAVARD > 0 cout << " GWt_softwarePanel::addSectionToExecuteW() DISABLE" << endl; #endif exec_go_->disable(); } else { #if BAVARD > 0 cout << " GWt_softwarePanel::addSectionToExecuteW() ENABLE" << endl; #endif exec_go_->enable(); } return true; } bool GWt_softwarePanel::areDataCoherent() { #if BAVARD > 0 cout << "***********************************" << endl; cout << " GWt_softwarePanel::areDataCoherent() " << endl<initializeExecution(); // intialize User Interface if (pspa_->getBeamLine()) { pspa_->getBeamLine()->initializeSoftwares(); } string diagnosticErrors; string diagnosticWarnings; for (int a = 0; a < sections_.size(); a++) { string debString= sections_[a]->getFirstElementCurrentText().toUTF8(); string finString= sections_[a]->getLastElementCurrentText().toUTF8(); int debut = pspa_->getBeamLine()->getAbstractElementNumeroFromLabel(debString); int fin = pspa_->getBeamLine()->getAbstractElementNumeroFromLabel(finString); string currentSoft= sections_[a]->getSoftwareCurrentText().toUTF8(); nomDeLogiciel prog = nomDeLogiciel(currentSoft); sectionToExecute* sectToExec = dtmanage_->addSectionToExecute(pspa_->getBeamLine()->getAbstractElement(debut),debut,pspa_->getBeamLine()->getAbstractElement(fin),fin,prog); abstractSoftware* softToExec = sectToExec->getSoftware(); diagnosticErrors = ""; diagnosticWarnings = ""; for(int i = debut-1; i < fin; i++) // check sections { if (!pspa_->getBeamLine()) continue; abstractElement* elPtr= pspa_->getBeamLine()->getAbstractElement(i); if (!elPtr) continue; trivaluedBool tb = softToExec->doAcceptElement(elPtr->getNomdElement().getElementType()); if (tb == TBoolOk ) { elPtr->setSoftware(softToExec); } else { elPtr->setSoftware(NULL); if (tb == TBoolIgnore) { if(prog.getString() != "unknownSoftware") diagnosticWarnings += elPtr->getLabel() + " will be ignored by "+ prog.getString() + "
"; } else { // j'insiste pour remettre le nom generique de l'element refuse (glm / 30/03/2013) diagnosticErrors += elPtr->getNomdElement().getExpandedName() + " is not allowed with " + prog.getString() + "
"; caMarche = false; } } pspa_->getBeamLine()->update(i); } //i // set errors and warnings sections_[a]->setErrors(diagnosticErrors); sections_[a]->setWarnings(diagnosticWarnings); }//a return caMarche; } void GWt_softwarePanel::deleteSectionToExecuteW(int sectionLabel) { #if BAVARD > 0 cout << "***********************************" << endl; cout << " GWt_softwarePanel::deleteSectionToExecuteW()" << endl<getJobListSize() == 0 ) return; for (unsigned int sectionIndex = 0; sectionIndex< sections_.size(); sectionIndex++) { if (sections_[sectionIndex]->objectName() == sectionName) { // delete from dataManager dtmanage_->clearSectionToExecute(sectionIndex); // delete from User Interface contenuSections_->removeWidget(sections_[sectionIndex]); delete sections_[sectionIndex]; sections_.erase (sections_.begin()+sectionIndex); } } } void GWt_softwarePanel::executer() { cout << "***********************************" << endl; cout << " GWt_softwarePanel::executer() " << endl<(pspa_->getGlobalParam())->updateGlobals(); GWt_dialog calculDialog("Calcul en cours", "Veuillez patienter...", GWt_dialog::Wait, true,false); calculDialog.show(); wApp->processEvents(); if (!dtmanage_->executeAll()) { GWt_dialog warningDialog("PSPA : Echec", " echec lors de l'exécution !", GWt_dialog::Error, true,true); warningDialog.exec(); } // exec_go_->setDisabled(true); calculDialog.hide(); pspa_->faireDessin(); } void GWt_softwarePanel::fillComboWithElements(Wt::WComboBox* cBox) { if (cBox == NULL) return; // get the last item selected WString selectedString = cBox->currentText(); cBox->clear(); for(int a = 0; a < pspa_->getBeamLine()->getBeamLineSize(); a++) { abstractElement* abs = pspa_->getBeamLine()->getAbstractElement(a); if (abs != NULL) { cBox->addItem(abs->getLabel()); } } for(int a = 0; a < cBox->count(); a++) { if (cBox->itemText (a) == selectedString) { cBox->setCurrentIndex(a); } } cBox->refresh(); } void GWt_softwarePanel::fillComboWithSoftwares(Wt::WComboBox* cBox) { #if BAVARD > 0 cout << "***********************************" << endl; cout << " GWt_softwarePanel::fillComboWithSoftwares " << endl<clear(); unsigned nb = nomDeLogiciel::getNumberOfSoftwares(); unsigned k; for(k = 0; k <= nb; k++) { //xx cBox->addItem(nomDeLogiciel(k).getString()); } cBox->setCurrentIndex(nb); // xx cBox->refresh(); } Wt::WContainerWidget* GWt_softwarePanel::createAddDeletePushButtons(int sectionNumber) { WContainerWidget* buttonContainer= new WContainerWidget(); Wt::WHBoxLayout* buttonContainerLayout = new Wt::WHBoxLayout(); buttonContainerLayout->setContentsMargins(0,0,0,0); // preparation du bouton add WPushButton* exec_add = new WPushButton("+"); exec_add->clicked().connect(this, &GWt_softwarePanel::addSectionToExecuteW); exec_add->setStyleClass("roundButton"); exec_add->setMaximumSize(20,20); exec_add->setToolTip("Add new section"); // preparation du bouton delete WPushButton* exec_delete = new WPushButton("-"); // warningsContainer_->setStyleClass("warningsContainer"); exec_delete->clicked().connect(boost::bind(&GWt_softwarePanel::deleteSectionToExecuteW, this, sectionNumber)); exec_delete->setStyleClass("roundButton"); exec_delete->setMaximumSize(20,20); exec_delete->setToolTip("Remove this section"); buttonContainerLayout->addWidget(exec_add); buttonContainerLayout->addWidget(exec_delete); buttonContainer->setLayout(buttonContainerLayout); return buttonContainer; }