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

Last change on this file since 471 was 471, checked in by garnier, 11 years ago

Modification du softwarePanel, on peut désormais ajouter plusieurs sections et en changer le logiciel. Reste à faire les suppression de sections et les modifications de début/fin

File size: 12.4 KB
RevLine 
[302]1//  GWt_softwarePanel.cpp
2//  PSPA
3//
4//  Created by Garnier Laurent on 30/01/13.
5//  Copyright (c) 2013 Garnier Laurent. All rights reserved.
6//
7
8#include <Wt/WLineEdit>
9#include <Wt/WText>
10#include <Wt/WComboBox>
11#include <Wt/WPanel>
12#include <Wt/WBreak>
13#include <Wt/WApplication>
[401]14#include <Wt/WVBoxLayout>
[302]15
16#include "GWt_softwarePanel.h"
17#include "GWt_dialog.h"
18#include "GWt_console.h"
[455]19#include "GWt_sector.h"
[302]20#include "GWt_globalParameters.h"
[401]21#include "GWt_sectionToExecute.h"
[427]22#include "GWt_pspaApplication.h"
[302]23
[431]24#define BAVARD 0
25
[455]26GWt_softwarePanel::GWt_softwarePanel(dataManager* dataManager,GWt_sector* sect)
27  : WContainerWidget(),
28dtmanage_(dataManager),
29UIsector_(sect)
[343]30{
[401]31 
[343]32  // le panel
33  WPanel *panelLogiciels = new WPanel(this);
[401]34  panelLogiciels->setTitle(" sections of beam line for executing softwares ");
[343]35 
36  contenuSections_ = new WContainerWidget();
37  contenuSections_->addWidget(new WBreak());
38  contenuSections_->addWidget(new WBreak());
[468]39  displayFromControler();
[343]40 
41  panelLogiciels->setCentralWidget(contenuSections_);
[302]42}
43
44GWt_softwarePanel::~GWt_softwarePanel() {
45}
46
[468]47void GWt_softwarePanel::displayFromControler()
[427]48{     
[431]49#if BAVARD > 0
50  cout << "***********************************" << endl;
51  cout << " GWt_softwarePanel::addSectionToExecuteW() " << endl<<endl;
52#endif
53
[468]54  // Clear all
55  contenuSections_->clear();
[427]56 
[468]57  // Get all sectionsToExecute from this sector
58  if (!UIsector_->getSectorControler()) {
59    return;
[343]60  }
61 
[468]62  if (UIsector_->getSectorControler()->getSectionsToExecute().size() == 0) {
63    // FIXME : Add a message to tell the user to add first an element
64  } else {
[471]65
66    unsigned long firstSectionToExecuteIndex = 0;
[468]67    for (unsigned int a=0; a<UIsector_->getSectorControler()->getSectionsToExecute().size(); a++) {
68      abstractElement* premierElement = NULL;
69      abstractElement* dernierElement = NULL;
70     
71      std::string premierElementLabel = "";
72      std::string dernierElementLabel = "";
73      if (premierElement) {
74        premierElementLabel = premierElement->getLabel();
75      }
76      if (dernierElement) {
77        dernierElementLabel = dernierElement->getLabel();
78      }
79     
80      WComboBox* lineFromCombo = new WComboBox();
81      WComboBox* lineToCombo = new WComboBox();
82      fillComboWithElements(lineFromCombo);
83      fillComboWithElements(lineToCombo);
84     
[469]85      // set to first
[471]86      lineFromCombo->setCurrentIndex(firstSectionToExecuteIndex);
[469]87      // set to last
[471]88      lineToCombo->setCurrentIndex(firstSectionToExecuteIndex + UIsector_->getSectorControler()->getSectionsToExecute()[a]->getElements().size() - 1);
[468]89     
90      WComboBox* softCombo = new WComboBox();
[469]91      sector * sector = UIsector_->getSectorControler();
92      sectionToExecute* sect = UIsector_->getSectorControler()->getSectionsToExecute()[a];
93      abstractSoftware* abs = sect->getSoftware();
[468]94     
[469]95      fillComboWithSoftwares(softCombo,UIsector_->getSectorControler()->getSectionsToExecute()[a]->getSoftware()->getName());
96
97      // disable the "to" comboBox
98      lineToCombo->disable();
99
100      // disable the first "from" comboBox
101      if (a==0) {
102        lineFromCombo->disable();
103      }
104      // disable the last "to" comboBox
105      if (a==UIsector_->getSectorControler()->getSectionsToExecute().size()-1) {
106        lineToCombo->disable();
107      }
108     
[468]109      // Add the sectionToExecute Widget
[469]110      GWt_sectionToExecute* newSection = new GWt_sectionToExecute(lineFromCombo,lineToCombo,softCombo,createAddDeletePushButtons(a),UIsector_->getSectorControler()->getSectionsToExecute()[a],UIsector_);
[468]111     
[471]112/*      // FIXME ?
[468]113      stringstream st;
[471]114      st << UIsectionsToExecute_deprecated_.size();
[468]115     
116      // this is the mean to identify this section!
117      newSection->setObjectName(st.str());
118     
119      // push back on sections vector
[471]120      UIsectionsToExecute_deprecated_.push_back(newSection);
121*/
[468]122      contenuSections_->addWidget(newSection);
[469]123//      updateSections();
[468]124
[471]125      firstSectionToExecuteIndex += UIsector_->getSectorControler()->getSectionsToExecute()[a]->getElements().size();
[468]126    }
[343]127  }
[468]128 }
[401]129
[431]130void GWt_softwarePanel::updateSections()
131{
132#if BAVARD > 0
133  cout << "***********************************" << endl;
134  cout << " GWt_softwarePanel::updateSections() " << endl<<endl;
135#endif
[469]136
137  /*
[431]138  // update all sections in order to manage new/deleted items
[471]139  for (int a = 0; a < UIsectionsToExecute_deprecated_.size(); a++) {
140    fillComboWithElements(UIsectionsToExecute_deprecated_[a]->getFirstElement());
141    fillComboWithElements(UIsectionsToExecute_deprecated_[a]->getLastElement());
142    UIsectionsToExecute_deprecated_[a]->getFirstElement()->setEnabled (true);
143    UIsectionsToExecute_deprecated_[a]->getLastElement()->setEnabled (true);
[431]144  }
145 
[471]146  if (UIsectionsToExecute_deprecated_;.size() == 0) {
[431]147    return;
148  }
149 
150  // the first element will always be the first element of the beamLine
[471]151  UIsectionsToExecute_deprecated_[0]->getFirstElement()->setCurrentIndex(0);
152  UIsectionsToExecute_deprecated_[0]->getFirstElement()->setEnabled (false);
[431]153
154  // the last element will always be the last element of the beamLine
[471]155  UIsectionsToExecute_deprecated_[UIsectionsToExecute_deprecated_.size()-1]->getLastElement()->setCurrentIndex(UIsectionsToExecute_deprecated_[UIsectionsToExecute_deprecated_;.size()-1]->getLastElement()->count());
156  UIsectionsToExecute_deprecated_[UIsectionsToExecute_deprecated_.size()-1]->getLastElement()->setEnabled(false);
[431]157
158  // set default values
159  updateSectionSelection();
[469]160*/
[431]161}
162
[367]163bool GWt_softwarePanel::updateSectionSelection()
[302]164{
[431]165#if BAVARD > 0
166  cout << "***********************************" << endl;
167  cout << " GWt_softwarePanel::updateSectionSelection() " << endl<<endl;
168#endif
169
[401]170  if ( dtmanage_->getJobListSize() == 0 ) return false;
[343]171 
172  // traitement de la premiere ligne
173  // on impose le depart du calcul au premier element
[455]174  string premier = "";
175  if (UIsector_->getSectorControler()) {
176    if (UIsector_->getSectorControler()->getSectionsToExecute().size() > 0) {
177      if (UIsector_->getSectorControler()->getSectionsToExecute()[0]->getElements().size() > 0) {
178        premier = UIsector_->getSectorControler()->getSectionsToExecute()[0]->getElements()[0]->getLabel();
179      }
180    }
181  }
182 
183  // FIXME :  A réécrire
184  /*
[471]185  if (UIsectionsToExecute_deprecated_.size() > 0) {
186    UIsectionsToExecute_deprecated_[0]->setFirstElementCurrentSelection(premier);
[401]187  }
[343]188 
[471]189  Wt::WString currentString =  UIsectionsToExecute_deprecated_[0]->getLastElementCurrentText();
[401]190  int current = dtmanage_->getNumeroFromElementLabel(currentString.toUTF8());
191 
[343]192  // si la fin est mal definie on prend toute la config par defaut
193  if ( current <= 0 || current > dtmanage_->getBeamLineSize() )
[431]194    {
195      current = dtmanage_->getBeamLineSize();
196      currentString =  dtmanage_->getLabelFromElementNumero(current);
[471]197      if (UIsectionsToExecute_deprecated_.size() > 0) {
198        UIsectionsToExecute_deprecated_[0]->setLastElementCurrentSelection(currentString);
[431]199        //...
200      }
[302]201    }
[343]202  current++;
203  currentString = dtmanage_->getLabelFromElementNumero(current);
204 
205  // traitement des suivantes (on avance d'un cran dans la liste)
[471]206  for (int a = 1; a< UIsectionsToExecute_deprecated_;.size(); a++)
[302]207    {
[343]208      // debut
209      if ( current > dtmanage_->getBeamLineSize() )
[302]210        {
[471]211          UIsectionsToExecute_deprecated_;[a]->setErrors("This section element could not be after previous session last element");
[412]212          exec_go_->disable();
213          return false;
[302]214        }
[343]215     
[471]216      UIsectionsToExecute_deprecated_;[a]->setFirstElementCurrentSelection(currentString);
[401]217
[343]218      // fin
[471]219      string finString =  UIsectionsToExecute_deprecated_;[a]->getLastElementCurrentText().toUTF8();
[343]220     
221      int numeroFin = dtmanage_->getNumeroFromElementLabel( finString);
222     
[412]223      if ( numeroFin < current)
224      {
[471]225        UIsectionsToExecute_deprecated_;[a]->setErrors("Last section element should be after first section element");
[412]226        exec_go_->disable();
227        return false;
228      }
229
230      if (numeroFin > dtmanage_->getBeamLineSize())
231      {
[471]232        UIsectionsToExecute_deprecated_;[a]->setErrors("Last section element number is greater than the beam line size");
[412]233        exec_go_->disable();
234        return false;
235      }
[343]236     
237      // preparation de la ligne suivante
238      current = numeroFin +1;
239      currentString = dtmanage_->getLabelFromElementNumero(current);
[302]240    }
[367]241  //  exec_go_->setDisabled(false);
[401]242
243  if (!areDataCoherent()) {
[431]244#if BAVARD > 0
245    cout << " GWt_softwarePanel::addSectionToExecuteW() DISABLE" << endl;
246#endif
[401]247    exec_go_->disable();
248  } else {
[431]249#if BAVARD > 0
250    cout << " GWt_softwarePanel::addSectionToExecuteW() ENABLE" << endl;
251#endif
[401]252    exec_go_->enable();
253  }
[455]254*/
[367]255  return true;
[302]256}
257
[431]258
[468]259void GWt_softwarePanel::addSectionToExecute() {
260  // We put the last element of the previous sectionToExecute inside
[401]261 
[468]262  // Get the last element from previous section
263  if (!UIsector_->getSectorControler()) {
264    return;
[401]265  }
[471]266  unsigned long s = UIsector_->getSectorControler()->getSectionsToExecute().size();
[468]267  if (s > 0) {
268    abstractElement* abs = UIsector_->getSectorControler()->getSectionsToExecute()[s-1]->getLastElement();
[469]269    UIsector_->getSectorControler()->addSectionToExecute(new sectionToExecute(abs,NULL));
[471]270    UIsector_->getSectorControler()->getSectionsToExecute()[s-1]->removeLastElement();
[468]271  }
[419]272
[468]273 
274  displayFromControler();
[471]275  UIsector_->getBeamLineWidget()->buildBeamLineWidget();
[468]276}
[431]277
[401]278
[468]279void GWt_softwarePanel::deleteSectionToExecute(int sectionLabel)
[302]280{
[436]281#if BAVARD > 0
282  cout << "***********************************" << endl;
283  cout << " GWt_softwarePanel::deleteSectionToExecuteW()" << endl<<endl;
284#endif
285
[407]286  stringstream st;
287  st << sectionLabel;
288  std::string sectionName = st.str();
[471]289  //FIXME
[407]290 
[471]291/*  if ( dtmanage_->getJobListSize() == 0 ) return;
292  for (unsigned int sectionIndex = 0; sectionIndex< UIsectionsToExecute_deprecated_.size(); sectionIndex++) {
293    if (UIsectionsToExecute_deprecated_[sectionIndex]->objectName() == sectionName) {
[401]294
[407]295      // delete from dataManager
[455]296      UIsector_->getSectorControler()->clearSectionToExecute(sectionIndex);
[407]297
298      // delete from User Interface
[471]299      contenuSections_->removeWidget(UIsectionsToExecute_deprecated_[sectionIndex]);
300      delete UIsectionsToExecute_deprecated_[sectionIndex];
301      UIsectionsToExecute_deprecated_.erase (UIsectionsToExecute_deprecated_.begin()+sectionIndex);
[407]302    }
303  } 
[471]304*/
[468]305  displayFromControler();
[302]306}
307
[405]308
[431]309void GWt_softwarePanel::fillComboWithElements(Wt::WComboBox* cBox) 
310{
[401]311
[468]312  if (cBox == NULL) return;
[455]313
[468]314  if (!UIsector_->getSectorControler()) {
315    return;
316  }
317  for (unsigned int a=0; a < UIsector_->getSectorControler()->getSectionsToExecute().size(); a++) {
318    for(unsigned int b=0; b < UIsector_->getSectorControler()->getSectionsToExecute()[a]->getElements().size(); b++) {
319     
320      abstractElement* abs = UIsector_->getSectorControler()->getSectionsToExecute()[a]->getElements()[b];
321      if (abs != NULL) {
322        cBox->addItem(abs->getLabel());
323      }
[401]324    }
325  }
326}
327
[469]328void GWt_softwarePanel::fillComboWithSoftwares(Wt::WComboBox* cBox, std::string selected)
[431]329{
330#if BAVARD > 0
331  cout << "***********************************" << endl;
332  cout << " GWt_softwarePanel::fillComboWithSoftwares " << endl<<endl;
333#endif
[401]334
335  if (cBox == NULL) return;
336  cBox->clear();
337
338  unsigned nb = nomDeLogiciel::getNumberOfSoftwares();
339  unsigned k;
[431]340  for(k = 0; k <= nb; k++) { //xx
[401]341    cBox->addItem(nomDeLogiciel(k).getString());
[469]342    if (nomDeLogiciel(k).getString() == selected) {
343      cBox->setCurrentIndex(cBox->count()-1);
344    }
[401]345  }
[405]346  cBox->refresh();
[401]347}
348
[431]349Wt::WContainerWidget* GWt_softwarePanel::createAddDeletePushButtons(int sectionNumber) 
350{
[401]351  WContainerWidget* buttonContainer= new WContainerWidget();
352 
353  Wt::WHBoxLayout* buttonContainerLayout = new Wt::WHBoxLayout();
354  buttonContainerLayout->setContentsMargins(0,0,0,0);
355  // preparation du bouton add
356  WPushButton* exec_add = new WPushButton("+");
[468]357  exec_add->clicked().connect(this, &GWt_softwarePanel::addSectionToExecute);
[401]358  exec_add->setStyleClass("roundButton");
359  exec_add->setMaximumSize(20,20);
360  exec_add->setToolTip("Add new section");
361 
362  // preparation du bouton delete
363  WPushButton* exec_delete = new WPushButton("-");
364  //  warningsContainer_->setStyleClass("warningsContainer");
[407]365
[468]366  exec_delete->clicked().connect(boost::bind(&GWt_softwarePanel::deleteSectionToExecute, this, sectionNumber));
[401]367  exec_delete->setStyleClass("roundButton");
368  exec_delete->setMaximumSize(20,20);
[405]369  exec_delete->setToolTip("Remove this section");
[401]370
371  buttonContainerLayout->addWidget(exec_add);
372  buttonContainerLayout->addWidget(exec_delete);
373  buttonContainer->setLayout(buttonContainerLayout);
374
375  return buttonContainer;
[413]376}
Note: See TracBrowser for help on using the repository browser.