// 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_sector.h" #include "GWt_globalParameters.h" #include "GWt_sectionToExecute.h" #include "GWt_pspaApplication.h" #define BAVARD 0 GWt_softwarePanel::GWt_softwarePanel(dataManager* dataManager,GWt_sector* sect) : WContainerWidget(), dtmanage_(dataManager), UIsector_(sect) { // le panel WPanel *panelLogiciels = new WPanel(this); panelLogiciels->setTitle(" sections of beam line for executing softwares "); contenuSections_ = new WContainerWidget(); contenuSections_->addWidget(new WBreak()); contenuSections_->addWidget(new WBreak()); displayFromControler(); panelLogiciels->setCentralWidget(contenuSections_); } GWt_softwarePanel::~GWt_softwarePanel() { } void GWt_softwarePanel::displayFromControler() { #if BAVARD > 0 cout << "***********************************" << endl; cout << " GWt_softwarePanel::addSectionToExecuteW() " << endl<clear(); // Get all sectionsToExecute from this sector if (!UIsector_->getSectorControler()) { return; } if (UIsector_->getSectorControler()->getSectionsToExecute().size() == 0) { // FIXME : Add a message to tell the user to add first an element } else { unsigned int firstSectionToExecuteIndex = 0; for (unsigned int a=0; agetSectorControler()->getSectionsToExecute().size(); a++) { abstractElement* premierElement = NULL; abstractElement* dernierElement = NULL; 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 to first lineFromCombo->setCurrentIndex(firstSectionToExecuteIndex); // set to last lineToCombo->setCurrentIndex(firstSectionToExecuteIndex + (unsigned int)UIsector_->getSectorControler()->getSectionsToExecute()[a]->getElements().size() - 1); WComboBox* softCombo = new WComboBox(); sectionToExecute* sect = UIsector_->getSectorControler()->getSectionsToExecute()[a]; fillComboWithSoftwares(softCombo,UIsector_->getSectorControler()->getSectionsToExecute()[a]->getSoftware()->getName()); // disable the "to" comboBox lineToCombo->disable(); // disable the first "from" comboBox if (a==0) { lineFromCombo->disable(); } // disable the last "to" comboBox if (a==UIsector_->getSectorControler()->getSectionsToExecute().size()-1) { lineToCombo->disable(); } // Add the sectionToExecute Widget GWt_sectionToExecute* newSection = new GWt_sectionToExecute(lineFromCombo,lineToCombo,softCombo,createAddDeletePushButtons(a),UIsector_->getSectorControler()->getSectionsToExecute()[a],UIsector_); /* // FIXME ? stringstream st; st << UIsectionsToExecute_deprecated_.size(); // this is the mean to identify this section! newSection->setObjectName(st.str()); // push back on sections vector UIsectionsToExecute_deprecated_.push_back(newSection); */ contenuSections_->addWidget(newSection); // updateSections(); firstSectionToExecuteIndex += UIsector_->getSectorControler()->getSectionsToExecute()[a]->getElements().size(); } } } void GWt_softwarePanel::updateSections() { #if BAVARD > 0 cout << "***********************************" << endl; cout << " GWt_softwarePanel::updateSections() " << endl<getFirstElement()); fillComboWithElements(UIsectionsToExecute_deprecated_[a]->getLastElement()); UIsectionsToExecute_deprecated_[a]->getFirstElement()->setEnabled (true); UIsectionsToExecute_deprecated_[a]->getLastElement()->setEnabled (true); } if (UIsectionsToExecute_deprecated_;.size() == 0) { return; } // the first element will always be the first element of the beamLine UIsectionsToExecute_deprecated_[0]->getFirstElement()->setCurrentIndex(0); UIsectionsToExecute_deprecated_[0]->getFirstElement()->setEnabled (false); // the last element will always be the last element of the beamLine UIsectionsToExecute_deprecated_[UIsectionsToExecute_deprecated_.size()-1]->getLastElement()->setCurrentIndex(UIsectionsToExecute_deprecated_[UIsectionsToExecute_deprecated_;.size()-1]->getLastElement()->count()); UIsectionsToExecute_deprecated_[UIsectionsToExecute_deprecated_.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 = ""; if (UIsector_->getSectorControler()) { if (UIsector_->getSectorControler()->getSectionsToExecute().size() > 0) { if (UIsector_->getSectorControler()->getSectionsToExecute()[0]->getElements().size() > 0) { premier = UIsector_->getSectorControler()->getSectionsToExecute()[0]->getElements()[0]->getLabel(); } } } // FIXME : A réécrire /* if (UIsectionsToExecute_deprecated_.size() > 0) { UIsectionsToExecute_deprecated_[0]->setFirstElementCurrentSelection(premier); } Wt::WString currentString = UIsectionsToExecute_deprecated_[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 (UIsectionsToExecute_deprecated_.size() > 0) { UIsectionsToExecute_deprecated_[0]->setLastElementCurrentSelection(currentString); //... } } current++; currentString = dtmanage_->getLabelFromElementNumero(current); // traitement des suivantes (on avance d'un cran dans la liste) for (int a = 1; a< UIsectionsToExecute_deprecated_;.size(); a++) { // debut if ( current > dtmanage_->getBeamLineSize() ) { UIsectionsToExecute_deprecated_;[a]->setErrors("This section element could not be after previous session last element"); exec_go_->disable(); return false; } UIsectionsToExecute_deprecated_;[a]->setFirstElementCurrentSelection(currentString); // fin string finString = UIsectionsToExecute_deprecated_;[a]->getLastElementCurrentText().toUTF8(); int numeroFin = dtmanage_->getNumeroFromElementLabel( finString); if ( numeroFin < current) { UIsectionsToExecute_deprecated_;[a]->setErrors("Last section element should be after first section element"); exec_go_->disable(); return false; } if (numeroFin > dtmanage_->getBeamLineSize()) { UIsectionsToExecute_deprecated_;[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; } void GWt_softwarePanel::addSectionToExecute() { // We put the last element of the previous sectionToExecute inside // Get the last element from previous section if (!UIsector_->getSectorControler()) { return; } unsigned long s = UIsector_->getSectorControler()->getSectionsToExecute().size(); if (s > 0) { abstractElement* abs = UIsector_->getSectorControler()->getSectionsToExecute()[s-1]->getLastElement(); UIsector_->getSectorControler()->addSectionToExecute(new sectionToExecute(abs,NULL,dtmanage_,UIsector_->getSectorControler())); UIsector_->getSectorControler()->getSectionsToExecute()[s-1]->removeLastElement(); } displayFromControler(); UIsector_->getBeamLineWidget()->buildBeamLineWidget(); } void GWt_softwarePanel::deleteSectionToExecute(int sectionLabel) { #if BAVARD > 0 cout << "***********************************" << endl; cout << " GWt_softwarePanel::deleteSectionToExecuteW()" << endl<getJobListSize() == 0 ) return; for (unsigned int sectionIndex = 0; sectionIndex< UIsectionsToExecute_deprecated_.size(); sectionIndex++) { if (UIsectionsToExecute_deprecated_[sectionIndex]->objectName() == sectionName) { // delete from dataManager UIsector_->getSectorControler()->clearSectionToExecute(sectionIndex); // delete from User Interface contenuSections_->removeWidget(UIsectionsToExecute_deprecated_[sectionIndex]); delete UIsectionsToExecute_deprecated_[sectionIndex]; UIsectionsToExecute_deprecated_.erase (UIsectionsToExecute_deprecated_.begin()+sectionIndex); } } */ displayFromControler(); } void GWt_softwarePanel::fillComboWithElements(Wt::WComboBox* cBox) { if (cBox == NULL) return; if (!UIsector_->getSectorControler()) { return; } for (unsigned int a=0; a < UIsector_->getSectorControler()->getSectionsToExecute().size(); a++) { for(unsigned int b=0; b < UIsector_->getSectorControler()->getSectionsToExecute()[a]->getElements().size(); b++) { abstractElement* abs = UIsector_->getSectorControler()->getSectionsToExecute()[a]->getElements()[b]; if (abs != NULL) { cBox->addItem(abs->getLabel()); } } } } void GWt_softwarePanel::fillComboWithSoftwares(Wt::WComboBox* cBox, std::string selected) { #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()); if (nomDeLogiciel(k).getString() == selected) { cBox->setCurrentIndex(cBox->count()-1); } } 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::addSectionToExecute); 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::deleteSectionToExecute, 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; }