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
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
66    unsigned long firstSectionToExecuteIndex = 0;
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     
85      // set to first
86      lineFromCombo->setCurrentIndex(firstSectionToExecuteIndex);
87      // set to last
88      lineToCombo->setCurrentIndex(firstSectionToExecuteIndex + UIsector_->getSectorControler()->getSectionsToExecute()[a]->getElements().size() - 1);
89     
90      WComboBox* softCombo = new WComboBox();
91      sector * sector = UIsector_->getSectorControler();
92      sectionToExecute* sect = UIsector_->getSectorControler()->getSectionsToExecute()[a];
93      abstractSoftware* abs = sect->getSoftware();
94     
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     
109      // Add the sectionToExecute Widget
110      GWt_sectionToExecute* newSection = new GWt_sectionToExecute(lineFromCombo,lineToCombo,softCombo,createAddDeletePushButtons(a),UIsector_->getSectorControler()->getSectionsToExecute()[a],UIsector_);
111     
112/*      // FIXME ?
113      stringstream st;
114      st << UIsectionsToExecute_deprecated_.size();
115     
116      // this is the mean to identify this section!
117      newSection->setObjectName(st.str());
118     
119      // push back on sections vector
120      UIsectionsToExecute_deprecated_.push_back(newSection);
121*/
122      contenuSections_->addWidget(newSection);
123//      updateSections();
124
125      firstSectionToExecuteIndex += UIsector_->getSectorControler()->getSectionsToExecute()[a]->getElements().size();
126    }
127  }
128 }
129
130void GWt_softwarePanel::updateSections()
131{
132#if BAVARD > 0
133  cout << "***********************************" << endl;
134  cout << " GWt_softwarePanel::updateSections() " << endl<<endl;
135#endif
136
137  /*
138  // update all sections in order to manage new/deleted items
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);
144  }
145 
146  if (UIsectionsToExecute_deprecated_;.size() == 0) {
147    return;
148  }
149 
150  // the first element will always be the first element of the beamLine
151  UIsectionsToExecute_deprecated_[0]->getFirstElement()->setCurrentIndex(0);
152  UIsectionsToExecute_deprecated_[0]->getFirstElement()->setEnabled (false);
153
154  // the last element will always be the last element of the beamLine
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);
157
158  // set default values
159  updateSectionSelection();
160*/
161}
162
163bool GWt_softwarePanel::updateSectionSelection()
164{
165#if BAVARD > 0
166  cout << "***********************************" << endl;
167  cout << " GWt_softwarePanel::updateSectionSelection() " << endl<<endl;
168#endif
169
170  if ( dtmanage_->getJobListSize() == 0 ) return false;
171 
172  // traitement de la premiere ligne
173  // on impose le depart du calcul au premier element
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  /*
185  if (UIsectionsToExecute_deprecated_.size() > 0) {
186    UIsectionsToExecute_deprecated_[0]->setFirstElementCurrentSelection(premier);
187  }
188 
189  Wt::WString currentString =  UIsectionsToExecute_deprecated_[0]->getLastElementCurrentText();
190  int current = dtmanage_->getNumeroFromElementLabel(currentString.toUTF8());
191 
192  // si la fin est mal definie on prend toute la config par defaut
193  if ( current <= 0 || current > dtmanage_->getBeamLineSize() )
194    {
195      current = dtmanage_->getBeamLineSize();
196      currentString =  dtmanage_->getLabelFromElementNumero(current);
197      if (UIsectionsToExecute_deprecated_.size() > 0) {
198        UIsectionsToExecute_deprecated_[0]->setLastElementCurrentSelection(currentString);
199        //...
200      }
201    }
202  current++;
203  currentString = dtmanage_->getLabelFromElementNumero(current);
204 
205  // traitement des suivantes (on avance d'un cran dans la liste)
206  for (int a = 1; a< UIsectionsToExecute_deprecated_;.size(); a++)
207    {
208      // debut
209      if ( current > dtmanage_->getBeamLineSize() )
210        {
211          UIsectionsToExecute_deprecated_;[a]->setErrors("This section element could not be after previous session last element");
212          exec_go_->disable();
213          return false;
214        }
215     
216      UIsectionsToExecute_deprecated_;[a]->setFirstElementCurrentSelection(currentString);
217
218      // fin
219      string finString =  UIsectionsToExecute_deprecated_;[a]->getLastElementCurrentText().toUTF8();
220     
221      int numeroFin = dtmanage_->getNumeroFromElementLabel( finString);
222     
223      if ( numeroFin < current)
224      {
225        UIsectionsToExecute_deprecated_;[a]->setErrors("Last section element should be after first section element");
226        exec_go_->disable();
227        return false;
228      }
229
230      if (numeroFin > dtmanage_->getBeamLineSize())
231      {
232        UIsectionsToExecute_deprecated_;[a]->setErrors("Last section element number is greater than the beam line size");
233        exec_go_->disable();
234        return false;
235      }
236     
237      // preparation de la ligne suivante
238      current = numeroFin +1;
239      currentString = dtmanage_->getLabelFromElementNumero(current);
240    }
241  //  exec_go_->setDisabled(false);
242
243  if (!areDataCoherent()) {
244#if BAVARD > 0
245    cout << " GWt_softwarePanel::addSectionToExecuteW() DISABLE" << endl;
246#endif
247    exec_go_->disable();
248  } else {
249#if BAVARD > 0
250    cout << " GWt_softwarePanel::addSectionToExecuteW() ENABLE" << endl;
251#endif
252    exec_go_->enable();
253  }
254*/
255  return true;
256}
257
258
259void GWt_softwarePanel::addSectionToExecute() {
260  // We put the last element of the previous sectionToExecute inside
261 
262  // Get the last element from previous section
263  if (!UIsector_->getSectorControler()) {
264    return;
265  }
266  unsigned long s = UIsector_->getSectorControler()->getSectionsToExecute().size();
267  if (s > 0) {
268    abstractElement* abs = UIsector_->getSectorControler()->getSectionsToExecute()[s-1]->getLastElement();
269    UIsector_->getSectorControler()->addSectionToExecute(new sectionToExecute(abs,NULL));
270    UIsector_->getSectorControler()->getSectionsToExecute()[s-1]->removeLastElement();
271  }
272
273 
274  displayFromControler();
275  UIsector_->getBeamLineWidget()->buildBeamLineWidget();
276}
277
278
279void GWt_softwarePanel::deleteSectionToExecute(int sectionLabel)
280{
281#if BAVARD > 0
282  cout << "***********************************" << endl;
283  cout << " GWt_softwarePanel::deleteSectionToExecuteW()" << endl<<endl;
284#endif
285
286  stringstream st;
287  st << sectionLabel;
288  std::string sectionName = st.str();
289  //FIXME
290 
291/*  if ( dtmanage_->getJobListSize() == 0 ) return;
292  for (unsigned int sectionIndex = 0; sectionIndex< UIsectionsToExecute_deprecated_.size(); sectionIndex++) {
293    if (UIsectionsToExecute_deprecated_[sectionIndex]->objectName() == sectionName) {
294
295      // delete from dataManager
296      UIsector_->getSectorControler()->clearSectionToExecute(sectionIndex);
297
298      // delete from User Interface
299      contenuSections_->removeWidget(UIsectionsToExecute_deprecated_[sectionIndex]);
300      delete UIsectionsToExecute_deprecated_[sectionIndex];
301      UIsectionsToExecute_deprecated_.erase (UIsectionsToExecute_deprecated_.begin()+sectionIndex);
302    }
303  } 
304*/
305  displayFromControler();
306}
307
308
309void GWt_softwarePanel::fillComboWithElements(Wt::WComboBox* cBox) 
310{
311
312  if (cBox == NULL) return;
313
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      }
324    }
325  }
326}
327
328void GWt_softwarePanel::fillComboWithSoftwares(Wt::WComboBox* cBox, std::string selected)
329{
330#if BAVARD > 0
331  cout << "***********************************" << endl;
332  cout << " GWt_softwarePanel::fillComboWithSoftwares " << endl<<endl;
333#endif
334
335  if (cBox == NULL) return;
336  cBox->clear();
337
338  unsigned nb = nomDeLogiciel::getNumberOfSoftwares();
339  unsigned k;
340  for(k = 0; k <= nb; k++) { //xx
341    cBox->addItem(nomDeLogiciel(k).getString());
342    if (nomDeLogiciel(k).getString() == selected) {
343      cBox->setCurrentIndex(cBox->count()-1);
344    }
345  }
346  cBox->refresh();
347}
348
349Wt::WContainerWidget* GWt_softwarePanel::createAddDeletePushButtons(int sectionNumber) 
350{
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("+");
357  exec_add->clicked().connect(this, &GWt_softwarePanel::addSectionToExecute);
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");
365
366  exec_delete->clicked().connect(boost::bind(&GWt_softwarePanel::deleteSectionToExecute, this, sectionNumber));
367  exec_delete->setStyleClass("roundButton");
368  exec_delete->setMaximumSize(20,20);
369  exec_delete->setToolTip("Remove this section");
370
371  buttonContainerLayout->addWidget(exec_add);
372  buttonContainerLayout->addWidget(exec_delete);
373  buttonContainer->setLayout(buttonContainerLayout);
374
375  return buttonContainer;
376}
Note: See TracBrowser for help on using the repository browser.