// 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_computingBlock.h" #include "GWt_globalParameters.h" #include "GWt_pspaApplication.h" #include "GWt_machine.h" #define BAVARD 1 GWt_softwarePanel::GWt_softwarePanel(dataManager* dataManager,GWt_machine* mach) : WContainerWidget(), dtmanage_(dataManager), UImachine_(mach) { // le panel WPanel *panelLogiciels = new WPanel(this); panelLogiciels->setTitle(" Computing blocks "); contenuSections_ = new WContainerWidget(); contenuSections_->addWidget(new WBreak()); contenuSections_->addWidget(new WBreak()); cout << " GWt_softwarePanel::GWt_softwarePanel DISPLAY SOFTWARE PANEL " << endl; displayFromControler(); panelLogiciels->setCentralWidget(contenuSections_); } GWt_softwarePanel::~GWt_softwarePanel() { } void GWt_softwarePanel::displayFromControler() { cout << " GWt_softwarePanel::displayFromControler() " << endl<clear(); // Get all sectionsToExecute from this machine if (!UImachine_->getMachineControler()) { cout << " GWt_softwarePanel::displayFromControler() PAS DE MACHINE " << endl; return; } else { cout << " GWt_softwarePanel::displayFromControler() MACHINE TROUVEE " << endl; } if (UImachine_->getMachineControler()->getComputingBlocks().size() == 0) { // FIXME : Add a message to tell the user to add first an element cout << " GWt_softwarePanel::displayFromControler() PAS DE BLOCK " << endl; } else { cout << " GWt_softwarePanel::displayFromControler() NOMBRE DE BLOCK " << UImachine_->getMachineControler()->getComputingBlocks().size() << endl; unsigned int firstElemeOfComputingBlockIndex = 0; for (unsigned int a=0; agetMachineControler()->getComputingBlocks().size(); a++) { cout << " GWt_softwarePanel::displayFromControler() BLOC No " << a+1 << endl; abstractElement* premierElement = NULL; abstractElement* dernierElement = NULL; std::string premierElementLabel = ""; std::string dernierElementLabel = ""; if ( !UImachine_->getMachineControler()->getComputingBlocks()[a]->isEmpty() ) { premierElement = UImachine_->getMachineControler()->getComputingBlocks()[a]->getFirstElement(); firstElemeOfComputingBlockIndex = UImachine_->getMachineControler()->getComputingBlocks()[a]->getRankOfFirstElement(); dernierElement = UImachine_->getMachineControler()->getComputingBlocks()[a]->getLastElement(); } if (premierElement) premierElementLabel = premierElement->getLabel(); if (dernierElement) dernierElementLabel = dernierElement->getLabel(); cout << " GWt_softwarePanel::displayFromControler() dernier element a afficher " << dernierElementLabel << endl; WComboBox* lineFromCombo = new WComboBox(); WComboBox* lineToCombo = new WComboBox(); fillComboWithElements(lineFromCombo); fillComboWithElements(lineToCombo); // set to first lineFromCombo->setCurrentIndex(firstElemeOfComputingBlockIndex); // set to last lineToCombo->setCurrentIndex(UImachine_->getMachineControler()->getComputingBlocks()[a]->getRankOfLastElement()); WComboBox* softCombo = new WComboBox(); fillComboWithSoftwares(softCombo,UImachine_->getMachineControler()->getComputingBlocks()[a]->getSoftware()->getName()); // disable the "to" comboBox lineToCombo->disable(); // disable the first "from" comboBox // if (a==0) { // lineFromCombo->disable(); // } // enable the last "to" comboBox if (a==UImachine_->getMachineControler()->getComputingBlocks().size()-1) { lineToCombo->enable(); } // // Add computingBlock Widget // GWt_computingBlock* newBlock = new GWt_computingBlock(lineFromCombo,lineToCombo,softCombo,createAddDeletePushButtons(a),UImachine_->getMachineControler()->getComputingBlocks()[a],UImachine_); computingBlock* blocPtr = UImachine_->getMachineControler()->getComputingBlocks()[a]; GWt_computingBlock* newBlock = new GWt_computingBlock(lineFromCombo,lineToCombo,softCombo,createAddDeletePushButtons(blocPtr),blocPtr,UImachine_); cout << " GWt_softwarePanel::displayFromControler j'ajoute un bloc : " << newBlock << endl; cout << " GWt_softwarePanel::displayFromControler nb widget avant : " << contenuSections_->count() << endl; contenuSections_->addWidget(newBlock); cout << " GWt_softwarePanel::displayFromControler nb widget apres : " << contenuSections_->count() << endl; } } } void GWt_softwarePanel::fillComboWithElements(Wt::WComboBox* cBox) { if (cBox == NULL) return; if (!UImachine_->getMachineControler()) { return; } for(unsigned int b=0; b < UImachine_->getMachineControler()->getElements().size(); b++) { abstractElement* abs = UImachine_->getMachineControler()->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(computingBlock* cpbl) { 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::addComputingBlock); exec_add->clicked().connect(boost::bind(&GWt_softwarePanel::addComputingBlock, this, cpbl)); 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::deleteComputingBlock, this, cpbl)); 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; } void GWt_softwarePanel::addComputingBlock(computingBlock* cpbl) { // We put the last element of the previous sectionToExecute inside if (!UImachine_->getMachineControler()) { return; } // UImachine_->getMachineControler()->openNewLastBlock(); UImachine_->getMachineControler()->openNewBlockAfter(cpbl); displayFromControler(); } void GWt_softwarePanel::deleteComputingBlock(computingBlock* cpbl) { cout << " GWt_softwarePanel::deleteComputingBlock(computingBlock*)" << endl; UImachine_->getMachineControler()->eraseComputingBlock(cpbl); displayFromControler(); }