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

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

Désormais il est de nouveau possible d'ajouter des sections et dy affecter des softwares (ne marche pour le moment quavec la 1ere sectionToExecute. Autres améliorations et renommages

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