// 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" GWt_softwarePanel::GWt_softwarePanel(dataManager* dataManager,PspaApplication* pspa) : WContainerWidget() { dtmanage_ = dataManager; pspa_ = pspa; // bouton execute exec_go_ = new WPushButton("execute!"); // exec_go_->setMinimumSize(300,300); // exec_go_->setDisabled(true); exec_go_->clicked().connect(this, &GWt_softwarePanel::executer); // preparation du bouton push_ok // WPushButton* exec_ok = new WPushButton("ok"); // exec_ok->clicked().connect(this, &GWt_softwarePanel::updateSectionSelection); // le panel WPanel *panelLogiciels = new WPanel(this); panelLogiciels->setTitle(" sections of beam line for executing softwares "); contenuSections_ = new WContainerWidget(); // contenuSections_->addWidget(exec_ok); contenuSections_->addWidget(exec_go_); contenuSections_->addWidget(new WBreak()); contenuSections_->addWidget(new WBreak()); addSectionToExecuteW(); panelLogiciels->setCentralWidget(contenuSections_); } GWt_softwarePanel::~GWt_softwarePanel() { } void GWt_softwarePanel::addSectionToExecuteW() { abstractElement* premierElement; abstractElement* dernierElement; int premierIndex = 0; int dernierIndex = 0; // if there is no section if(sections_.size() == 0) { premierElement = pspa_->getBeamLine()->getAbstractElement(0); premierIndex = 0; // if this is not the first : // - first element will be the last of the previous section // (or the same if it is the last of the beam line) // - lastElement will be the last of the beam line // - software will be the first of the list } else { dernierElement = pspa_->getBeamLine()->getAbstractElement(pspa_->getBeamLine()->getBeamLineSize()-1); dernierIndex = pspa_->getBeamLine()->getBeamLineSize()-1; premierElement = dernierElement; premierIndex = dernierIndex; /* int indexOfLastElementOfLastSection = dtmanage_->getJobListAt(dtmanage_->getJobListSize()-1)->getLastElementNumberInSection(); // if there are still elements at the end if (pspa_->getBeamLine()->getAbstractElement(indexOfLastElementOfLastSection+1) != NULL ) { premierIndex = indexOfLastElementOfLastSection+1; premierElement = pspa_->getBeamLine()->getAbstractElement(indexOfLastElementOfLastSection+1); // if this is the last element } else { premierIndex = indexOfLastElementOfLastSection; premierElement = pspa_->getBeamLine()->getAbstractElement(indexOfLastElementOfLastSection); } */ } dernierElement = pspa_->getBeamLine()->getAbstractElement(pspa_->getBeamLine()->getBeamLineSize()-1); dernierIndex = pspa_->getBeamLine()->getBeamLineSize()-1; // cout << "PspaApplication::addSectionToExecute() : " << premierText << " à " << dernierText << endl; abstractSoftware* soft = NULL; dtmanage_->addSectionToExecute(premierElement,premierIndex, dernierElement, dernierIndex, soft); std::string premierElementLabel = ""; std::string dernierElementLabel = ""; if (premierElement) { premierElementLabel = premierElement->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::disableSectionExecute() // { // exec_go_->setDisabled(true); // } // void GWt_softwarePanel::checkSectionSelection() // { // if ( selectedSections_.empty() ) return; // // traitement de la premiere ligne // // on impose le depart du calcul au premier element // string premier = dtmanage_->getLabelFromElementNumero(1); // (*selectedSections_.begin())->debut->setText(premier); // string currentString = (*selectedSections_.begin())->fin->text().toUTF8(); // int current = dtmanage_->getNumeroFromElementLabel(currentString); // // 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); // (*selectedSections_.begin())->fin->setText(currentString); // } // current++; // currentString = dtmanage_->getLabelFromElementNumero(current); // // traitement des suivantes (on avance d'un cran dans la liste) // list::iterator itr, itr0; // itr0 = selectedSections_.begin(); // itr0++; // for (itr = itr0; itr != selectedSections_.end(); itr++) // { // // debut // if ( current > dtmanage_->getBeamLineSize() ) // { // GWt_dialog warningDialog("PSPA :: verification des sections", " bad section definition !", GWt_dialog::Error,true,true); // warningDialog.exec(); // return; // } // (*itr)->debut->setText(currentString); // // fin // string finString = (*itr)->fin->text().toUTF8(); // int numeroFin = dtmanage_->getNumeroFromElementLabel( finString); // if ( numeroFin < current || numeroFin > dtmanage_->getBeamLineSize()) // { // GWt_dialog warningDialog("PSPA : Checking of sections", " bad section definition !", GWt_dialog::Error, true,true); // warningDialog.exec(); // return; // } // // preparation de la ligne suivante // current = numeroFin +1; // currentString = dtmanage_->getLabelFromElementNumero(current); // } // if (!areDataCoherent()) { // GWt_dialog warningDialog("PSPA : verification des sections", " donnees incoherentes !", GWt_dialog::Error,true,true); // warningDialog.exec(); // } // else // { // exec_go_->setDisabled(false); // // All ok, then put colors on beamLine // list::iterator itr2; // for(itr2 = selectedSections_.begin();itr2 != selectedSections_.end(); itr2++) // { // string debString = (*itr2)->debut->text().toUTF8(); // string finString = (*itr2)->fin->text().toUTF8(); // int debut = dtmanage_->getNumeroFromElementLabel(debString); // int fin = dtmanage_->getNumeroFromElementLabel(finString); // /** // for (int i=debut; i=getAbstractElement(i)->setBGColor( // } // nomDeLogiciel prog = nomDeLogiciel ( (*itr)->selection->currentIndex() ); // dtmanage_->addSectionToExecute(debut,fin,prog); // */ // } // } // } bool GWt_softwarePanel::updateSectionSelection() { if ( dtmanage_->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()) { exec_go_->disable(); } else { exec_go_->enable(); } return true; } bool GWt_softwarePanel::areDataCoherent() { bool caMarche = true; // initialize dataManager dtmanage_->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()->getAbstractElementIndexFromLabel(debString)+1; // FIXME : Should NOT be +1 int fin = pspa_->getBeamLine()->getAbstractElementIndexFromLabel(finString)+1; // FIXME : Should NOT be +1 nomDeLogiciel prog = nomDeLogiciel ( sections_[a]->getSoftwareCurrentText().toUTF8()); dtmanage_->addSectionToExecute(pspa_->getBeamLine()->getAbstractElement(debut), debut, pspa_->getBeamLine()->getAbstractElement(fin), fin, dtmanage_->createSoftwareConnexion(prog)); diagnosticErrors = ""; diagnosticWarnings = ""; // check sections for (int i=debut-1; igetBeamLine()) { if (pspa_->getBeamLine()->getAbstractElement(i)) { trivaluedBool tb = pspa_->getBeamLine()->getAbstractElement(i)->setSoftware(prog.getString()); if (tb == TBoolError ) { diagnosticErrors += pspa_->getBeamLine()->getAbstractElement(i)->getLabel() + " is not allowed with "+ prog.getString()+"
"; caMarche = false; // intialize thissoftware pspa_->getBeamLine()->getAbstractElement(i)->setSoftware(nomDeLogiciel::unknownSoftware); } else if ( tb == TBoolIgnore ) { diagnosticWarnings += pspa_->getBeamLine()->getAbstractElement(i)->getLabel() + " will be ignored by "+ prog.getString()+"
"; } pspa_->getBeamLine()->update(i); } } } // set errors and warnings sections_[a]->setErrors(diagnosticErrors); sections_[a]->setWarnings(diagnosticWarnings); } return caMarche; } void GWt_softwarePanel::deleteSectionToExecuteW(int sectionLabel) { stringstream st; st << sectionLabel; std::string sectionName = st.str(); if ( dtmanage_->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::updateSections() { // update all sections in order to manage new/deleted items for (int a = 0; a< sections_.size(); a++) { fillComboWithElements(sections_[a]->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 // update updateSectionSelection(); } /* string GWt_softwarePanel::getSelection() { list::iterator itr = selectedSections_.begin(); string str = (*itr)->fin->text().toUTF8(); return str; } */ void GWt_softwarePanel::executer() { if (!areDataCoherent()) { // GWt_dialog warningDialog("PSPA : verification des sections", " donnees incoherentes !", GWt_dialog::Error,true,true); // warningDialog.exec(); // exec_go_->setDisabled(true); return; } // GWt_console* console = NULL; // if (static_cast (wApp->findWidget ("console"))) { // console = static_cast (wApp->findWidget ("console")); // console->addConsoleMessage(string("on va peut etre y arriver")); // } static_cast(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; acount(); a++) { if (cBox->itemText (a) == selectedString) { cBox->setCurrentIndex(a); } } cBox->refresh(); } void GWt_softwarePanel::fillComboWithSoftwares(Wt::WComboBox* cBox) { if (cBox == NULL) return; cBox->clear(); unsigned nb = nomDeLogiciel::getNumberOfSoftwares(); unsigned k; for(k = 0; k < nb; k++) { cBox->addItem(nomDeLogiciel(k).getString()); } 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; }