source: PSPA/Interface_Web/trunk/pspaWT/sources/userInterface/src/GWt_softwarePanel.cc @ 495

Last change on this file since 495 was 495, checked in by lemeur, 10 years ago

maj de History

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