[302] | 1 | // GWt_softwarePanel.cpp |
---|
| 2 | // PSPA |
---|
| 3 | // |
---|
[493] | 4 | // Created by Garnier Laurent on 30/01/13.// Copyright (c) 2013 Garnier Laurent. All rights reserved. |
---|
[302] | 5 | // |
---|
| 6 | |
---|
| 7 | #include <Wt/WLineEdit> |
---|
| 8 | #include <Wt/WText> |
---|
| 9 | #include <Wt/WComboBox> |
---|
| 10 | #include <Wt/WPanel> |
---|
| 11 | #include <Wt/WBreak> |
---|
| 12 | #include <Wt/WApplication> |
---|
[401] | 13 | #include <Wt/WVBoxLayout> |
---|
[302] | 14 | |
---|
| 15 | #include "GWt_softwarePanel.h" |
---|
| 16 | #include "GWt_dialog.h" |
---|
| 17 | #include "GWt_console.h" |
---|
[493] | 18 | #include "GWt_computingBlock.h" |
---|
[302] | 19 | #include "GWt_globalParameters.h" |
---|
[427] | 20 | #include "GWt_pspaApplication.h" |
---|
[493] | 21 | #include "GWt_machine.h" |
---|
| 22 | #define BAVARD 1 |
---|
[302] | 23 | |
---|
[495] | 24 | GWt_softwarePanel::GWt_softwarePanel(dataManager* dataManager,GWt_machine* mach) |
---|
[455] | 25 | : WContainerWidget(), |
---|
| 26 | dtmanage_(dataManager), |
---|
[493] | 27 | UImachine_(mach) |
---|
[343] | 28 | { |
---|
[401] | 29 | |
---|
[343] | 30 | // le panel |
---|
| 31 | WPanel *panelLogiciels = new WPanel(this); |
---|
[493] | 32 | panelLogiciels->setTitle(" Computing blocks "); |
---|
[343] | 33 | |
---|
| 34 | contenuSections_ = new WContainerWidget(); |
---|
| 35 | contenuSections_->addWidget(new WBreak()); |
---|
| 36 | contenuSections_->addWidget(new WBreak()); |
---|
[495] | 37 | cout << " GWt_softwarePanel::GWt_softwarePanel DISPLAY SOFTWARE PANEL " << endl; |
---|
[493] | 38 | displayFromControler(); |
---|
[343] | 39 | |
---|
| 40 | panelLogiciels->setCentralWidget(contenuSections_); |
---|
[302] | 41 | } |
---|
| 42 | |
---|
[495] | 43 | GWt_softwarePanel::~GWt_softwarePanel() { |
---|
[302] | 44 | } |
---|
| 45 | |
---|
[495] | 46 | void GWt_softwarePanel::displayFromControler() |
---|
[427] | 47 | { |
---|
[495] | 48 | cout << " GWt_softwarePanel::displayFromControler() " << endl<<endl; |
---|
[431] | 49 | |
---|
[468] | 50 | // Clear all |
---|
| 51 | contenuSections_->clear(); |
---|
[493] | 52 | |
---|
| 53 | |
---|
| 54 | // Get all sectionsToExecute from this machine |
---|
| 55 | if (!UImachine_->getMachineControler()) { |
---|
[495] | 56 | cout << " GWt_softwarePanel::displayFromControler() PAS DE MACHINE " << endl; |
---|
[468] | 57 | return; |
---|
[493] | 58 | } else { |
---|
[495] | 59 | cout << " GWt_softwarePanel::displayFromControler() MACHINE TROUVEE " << endl; |
---|
[343] | 60 | } |
---|
| 61 | |
---|
[493] | 62 | if (UImachine_->getMachineControler()->getComputingBlocks().size() == 0) { |
---|
[468] | 63 | // FIXME : Add a message to tell the user to add first an element |
---|
[495] | 64 | cout << " GWt_softwarePanel::displayFromControler() PAS DE BLOCK " << endl; |
---|
[468] | 65 | } else { |
---|
[495] | 66 | cout << " GWt_softwarePanel::displayFromControler() NOMBRE DE BLOCK " << UImachine_->getMachineControler()->getComputingBlocks().size() << endl; |
---|
[471] | 67 | |
---|
[493] | 68 | unsigned int firstElemeOfComputingBlockIndex = 0; |
---|
| 69 | |
---|
| 70 | for (unsigned int a=0; a<UImachine_->getMachineControler()->getComputingBlocks().size(); a++) { |
---|
[495] | 71 | cout << " GWt_softwarePanel::displayFromControler() BLOC No " << a+1 << endl; |
---|
[468] | 72 | abstractElement* premierElement = NULL; |
---|
| 73 | abstractElement* dernierElement = NULL; |
---|
| 74 | std::string premierElementLabel = ""; |
---|
| 75 | std::string dernierElementLabel = ""; |
---|
[493] | 76 | |
---|
| 77 | if ( !UImachine_->getMachineControler()->getComputingBlocks()[a]->isEmpty() ) { |
---|
| 78 | premierElement = UImachine_->getMachineControler()->getComputingBlocks()[a]->getFirstElement(); |
---|
| 79 | firstElemeOfComputingBlockIndex = UImachine_->getMachineControler()->getComputingBlocks()[a]->getRankOfFirstElement(); |
---|
| 80 | dernierElement = UImachine_->getMachineControler()->getComputingBlocks()[a]->getLastElement(); |
---|
[468] | 81 | } |
---|
[493] | 82 | |
---|
| 83 | |
---|
| 84 | if (premierElement) premierElementLabel = premierElement->getLabel(); |
---|
| 85 | if (dernierElement) dernierElementLabel = dernierElement->getLabel(); |
---|
[495] | 86 | cout << " GWt_softwarePanel::displayFromControler() dernier element a afficher " << dernierElementLabel << endl; |
---|
[468] | 87 | |
---|
| 88 | WComboBox* lineFromCombo = new WComboBox(); |
---|
| 89 | WComboBox* lineToCombo = new WComboBox(); |
---|
| 90 | fillComboWithElements(lineFromCombo); |
---|
| 91 | fillComboWithElements(lineToCombo); |
---|
| 92 | |
---|
[469] | 93 | // set to first |
---|
[493] | 94 | lineFromCombo->setCurrentIndex(firstElemeOfComputingBlockIndex); |
---|
[469] | 95 | // set to last |
---|
[493] | 96 | lineToCombo->setCurrentIndex(UImachine_->getMachineControler()->getComputingBlocks()[a]->getRankOfLastElement()); |
---|
[468] | 97 | WComboBox* softCombo = new WComboBox(); |
---|
| 98 | |
---|
[493] | 99 | fillComboWithSoftwares(softCombo,UImachine_->getMachineControler()->getComputingBlocks()[a]->getSoftware()->getName()); |
---|
[469] | 100 | |
---|
| 101 | // disable the "to" comboBox |
---|
| 102 | lineToCombo->disable(); |
---|
| 103 | |
---|
| 104 | // disable the first "from" comboBox |
---|
[493] | 105 | // if (a==0) { |
---|
| 106 | // lineFromCombo->disable(); |
---|
| 107 | // } |
---|
[401] | 108 | |
---|
[493] | 109 | // enable the last "to" comboBox |
---|
| 110 | if (a==UImachine_->getMachineControler()->getComputingBlocks().size()-1) { |
---|
| 111 | lineToCombo->enable(); |
---|
[455] | 112 | } |
---|
[343] | 113 | |
---|
[493] | 114 | // // Add computingBlock Widget |
---|
[343] | 115 | |
---|
[493] | 116 | // GWt_computingBlock* newBlock = new GWt_computingBlock(lineFromCombo,lineToCombo,softCombo,createAddDeletePushButtons(a),UImachine_->getMachineControler()->getComputingBlocks()[a],UImachine_); |
---|
| 117 | computingBlock* blocPtr = UImachine_->getMachineControler()->getComputingBlocks()[a]; |
---|
| 118 | GWt_computingBlock* newBlock = new GWt_computingBlock(lineFromCombo,lineToCombo,softCombo,createAddDeletePushButtons(blocPtr),blocPtr,UImachine_); |
---|
[412] | 119 | |
---|
[495] | 120 | cout << " GWt_softwarePanel::displayFromControler j'ajoute un bloc : " << newBlock << endl; |
---|
| 121 | cout << " GWt_softwarePanel::displayFromControler nb widget avant : " << contenuSections_->count() << endl; |
---|
[493] | 122 | contenuSections_->addWidget(newBlock); |
---|
[495] | 123 | cout << " GWt_softwarePanel::displayFromControler nb widget apres : " << contenuSections_->count() << endl; |
---|
[343] | 124 | |
---|
[302] | 125 | } |
---|
[401] | 126 | } |
---|
[302] | 127 | } |
---|
| 128 | |
---|
[495] | 129 | void GWt_softwarePanel::fillComboWithElements(Wt::WComboBox* cBox) |
---|
[302] | 130 | { |
---|
[436] | 131 | |
---|
[468] | 132 | if (cBox == NULL) return; |
---|
[455] | 133 | |
---|
[493] | 134 | if (!UImachine_->getMachineControler()) { |
---|
[468] | 135 | return; |
---|
| 136 | } |
---|
[493] | 137 | for(unsigned int b=0; b < UImachine_->getMachineControler()->getElements().size(); b++) { |
---|
[468] | 138 | |
---|
[493] | 139 | abstractElement* abs = UImachine_->getMachineControler()->getElements()[b]; |
---|
[468] | 140 | if (abs != NULL) { |
---|
| 141 | cBox->addItem(abs->getLabel()); |
---|
| 142 | } |
---|
[401] | 143 | } |
---|
| 144 | } |
---|
| 145 | |
---|
[495] | 146 | void GWt_softwarePanel::fillComboWithSoftwares(Wt::WComboBox* cBox, std::string selected) |
---|
[431] | 147 | { |
---|
| 148 | #if BAVARD > 0 |
---|
| 149 | cout << "***********************************" << endl; |
---|
| 150 | cout << " GWt_softwarePanel::fillComboWithSoftwares " << endl<<endl; |
---|
| 151 | #endif |
---|
[401] | 152 | |
---|
| 153 | if (cBox == NULL) return; |
---|
| 154 | cBox->clear(); |
---|
| 155 | |
---|
| 156 | unsigned nb = nomDeLogiciel::getNumberOfSoftwares(); |
---|
| 157 | unsigned k; |
---|
[431] | 158 | for(k = 0; k <= nb; k++) { //xx |
---|
[401] | 159 | cBox->addItem(nomDeLogiciel(k).getString()); |
---|
[469] | 160 | if (nomDeLogiciel(k).getString() == selected) { |
---|
| 161 | cBox->setCurrentIndex(cBox->count()-1); |
---|
| 162 | } |
---|
[401] | 163 | } |
---|
[405] | 164 | cBox->refresh(); |
---|
[401] | 165 | } |
---|
| 166 | |
---|
[493] | 167 | |
---|
[495] | 168 | Wt::WContainerWidget* GWt_softwarePanel::createAddDeletePushButtons(computingBlock* cpbl) |
---|
[431] | 169 | { |
---|
[401] | 170 | WContainerWidget* buttonContainer= new WContainerWidget(); |
---|
| 171 | |
---|
| 172 | Wt::WHBoxLayout* buttonContainerLayout = new Wt::WHBoxLayout(); |
---|
| 173 | buttonContainerLayout->setContentsMargins(0,0,0,0); |
---|
| 174 | // preparation du bouton add |
---|
| 175 | WPushButton* exec_add = new WPushButton("+"); |
---|
[495] | 176 | // exec_add->clicked().connect(this, &GWt_softwarePanel::addComputingBlock); |
---|
| 177 | exec_add->clicked().connect(boost::bind(&GWt_softwarePanel::addComputingBlock, this, cpbl)); |
---|
[401] | 178 | exec_add->setStyleClass("roundButton"); |
---|
| 179 | exec_add->setMaximumSize(20,20); |
---|
| 180 | exec_add->setToolTip("Add new section"); |
---|
| 181 | |
---|
| 182 | // preparation du bouton delete |
---|
| 183 | WPushButton* exec_delete = new WPushButton("-"); |
---|
| 184 | // warningsContainer_->setStyleClass("warningsContainer"); |
---|
[407] | 185 | |
---|
[495] | 186 | exec_delete->clicked().connect(boost::bind(&GWt_softwarePanel::deleteComputingBlock, this, cpbl)); |
---|
[401] | 187 | exec_delete->setStyleClass("roundButton"); |
---|
| 188 | exec_delete->setMaximumSize(20,20); |
---|
[405] | 189 | exec_delete->setToolTip("Remove this section"); |
---|
[401] | 190 | |
---|
| 191 | buttonContainerLayout->addWidget(exec_add); |
---|
| 192 | buttonContainerLayout->addWidget(exec_delete); |
---|
| 193 | buttonContainer->setLayout(buttonContainerLayout); |
---|
| 194 | |
---|
| 195 | return buttonContainer; |
---|
[413] | 196 | } |
---|
[493] | 197 | |
---|
[495] | 198 | void GWt_softwarePanel::addComputingBlock(computingBlock* cpbl) { |
---|
[493] | 199 | // We put the last element of the previous sectionToExecute inside |
---|
| 200 | |
---|
| 201 | if (!UImachine_->getMachineControler()) { |
---|
| 202 | return; |
---|
| 203 | } |
---|
| 204 | // UImachine_->getMachineControler()->openNewLastBlock(); |
---|
| 205 | UImachine_->getMachineControler()->openNewBlockAfter(cpbl); |
---|
| 206 | displayFromControler(); |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | |
---|
| 210 | |
---|
[495] | 211 | void GWt_softwarePanel::deleteComputingBlock(computingBlock* cpbl) |
---|
[493] | 212 | { |
---|
[495] | 213 | cout << " GWt_softwarePanel::deleteComputingBlock(computingBlock*)" << endl; |
---|
[493] | 214 | |
---|
| 215 | UImachine_->getMachineControler()->eraseComputingBlock(cpbl); |
---|
| 216 | displayFromControler(); |
---|
| 217 | } |
---|