// 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 "GWt_softwarePanel.h" #include "GWt_dialog.h" #include "GWt_console.h" #include "GWt_globalParameters.h" GWt_softwarePanel::GWt_softwarePanel(dataManager* dataManager,PspaApplication* pspa) : WContainerWidget() { dtmanage_ = dataManager; pspa_ = pspa; setMaximumSize(600,150); setMinimumSize(600,150); // 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 add WPushButton* exec_add = new WPushButton("add"); exec_add->clicked().connect(this, &GWt_softwarePanel::addSectionToExecuteW); // preparation du bouton delete WPushButton* exec_delete = new WPushButton("delete"); exec_delete->clicked().connect(this, &GWt_softwarePanel::deleteSectionToExecuteW); // 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_add); contenuSections_->addWidget(exec_delete); // 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() { // disableSectionExecute(); string premierText, dernierText; if(selectedSections_.size() == 0) { premierText = dtmanage_->getLabelFromElementNumero(1); dernierText = dtmanage_->getLabelFromElementNumero(dtmanage_->getBeamLineSize()); } else { dernierText = selectedSections_.back()->fin->text().toUTF8(); int dernierNumero = dtmanage_->getNumeroFromElementLabel(dernierText); dernierNumero++; if ( dernierNumero <= dtmanage_->getBeamLineSize() ) { premierText = dtmanage_->getLabelFromElementNumero(dernierNumero); } else { premierText = dtmanage_->getLabelFromElementNumero(dtmanage_->getBeamLineSize()); } dernierText = premierText; } // cout << "PspaApplication::addSectionToExecute() : " << premierText << " √† " << dernierText << endl; WContainerWidget* newSection = new WContainerWidget; selectedSections_.push_back(new GWt_sectionToExecute); selectedSections_.back()->debut = new WLineEdit(); selectedSections_.back()->debut->setDisabled(true); selectedSections_.back()->debut->setText(premierText); selectedSections_.back()->fin = new WLineEdit(); // selectedSections_.back()->fin->changed().connect(this,&GWt_softwarePanel::disableSectionExecute); selectedSections_.back()->fin->setText(dernierText); selectedSections_.back()->selection = new WComboBox(); selectedSections_.back()->ligneDeWidget = newSection; newSection->addWidget(new WText(" from : ")); newSection->addWidget(selectedSections_.back()->debut); newSection->addWidget(new WText(" to : ")); newSection->addWidget(selectedSections_.back()->fin); newSection->addWidget(selectedSections_.back()->selection); contenuSections_->addWidget(newSection); unsigned nb = nomDeLogiciel::getNumberOfSoftwares(); unsigned k; for(k = 0; k < nb; k++) { selectedSections_.back()->selection->addItem(nomDeLogiciel(k).getString()); } } // 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 ( selectedSections_.empty() ) return false; // 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 false; } (*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 false; } // preparation de la ligne suivante current = numeroFin +1; currentString = dtmanage_->getLabelFromElementNumero(current); } // exec_go_->setDisabled(false); return true; } bool GWt_softwarePanel::areDataCoherent() { bool caMarche = true; trivaluedBool tbResume = TBoolOk; dtmanage_->initializeExecution(); string diagnostic; list::iterator itr; for(itr = selectedSections_.begin(); itr != selectedSections_.end(); itr++) { string debString = (*itr)->debut->text().toUTF8(); string finString = (*itr)->fin->text().toUTF8(); int debut = dtmanage_->getNumeroFromElementLabel(debString); int fin = dtmanage_->getNumeroFromElementLabel(finString); nomDeLogiciel prog = nomDeLogiciel ( (*itr)->selection->currentIndex() ); dtmanage_->addSectionToExecute(debut,fin,prog); // 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 ) { diagnostic += pspa_->getBeamLine()->getAbstractElement(i)->getNomdElement().getElementName() + " is not allowed with "+ prog.getString()+"\n "; caMarche = false; tbResume = tb; } else if ( tb == TBoolIgnore ) { diagnostic += pspa_->getBeamLine()->getAbstractElement(i)->getNomdElement().getElementName() + " will be ignored by "+ prog.getString()+"\n "; if ( tbResume != TBoolError ) tbResume = tb; } else { pspa_->getBeamLine()->update(i); } } } } } if ( tbResume == TBoolError ) { GWt_dialog calculDialog("PSPA check execute : ERROR", diagnostic , GWt_dialog::Error,true,true); calculDialog.exec(); } else if (tbResume == TBoolIgnore ) { GWt_dialog calculDialog("PSPA check execute : WARNING", diagnostic , GWt_dialog::Warning,false,true); calculDialog.exec(); } /* } else if ( essai == warning ) { GWt_dialog calculDialog("PSPA check execute : warning ", diagnostic , GWt_dialog::Warning, false,true); calculDialog.exec(); */ return caMarche; } void GWt_softwarePanel::deleteSectionToExecuteW() { if ( selectedSections_.empty() ) return; // disableSectionExecute(); selectedSections_.back()->ligneDeWidget->clear(); delete selectedSections_.back()->ligneDeWidget; selectedSections_.pop_back(); } void GWt_softwarePanel::updateSelections() { string premierText, dernierText; if ( selectedSections_.size() > 0 ) { premierText = dtmanage_->getLabelFromElementNumero(1); dernierText = dtmanage_->getLabelFromElementNumero( dtmanage_->getBeamLineSize() ); (*selectedSections_.begin())->debut->setText(premierText); (*selectedSections_.begin())->fin->setText(dernierText); } cout << "PspaApplication::updateSelections(): " << premierText << " √† " << dernierText << endl; } string GWt_softwarePanel::getSelection() { list::iterator itr = selectedSections_.begin(); string str = (*itr)->fin->text().toUTF8(); return str; } void GWt_softwarePanel::executer() { if ( !updateSectionSelection() ) return; 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(); }