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

Last change on this file since 436 was 436, checked in by touze, 11 years ago

ajout de secteurs

File size: 13.1 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"
19#include "GWt_globalParameters.h"
[401]20#include "GWt_sectionToExecute.h"
[427]21#include "GWt_pspaApplication.h"
[302]22
[431]23#define BAVARD 0
24
[302]25GWt_softwarePanel::GWt_softwarePanel(dataManager* dataManager,PspaApplication* pspa)
[343]26  : WContainerWidget() 
27{
28  dtmanage_ = dataManager;
29  pspa_ = pspa;
[401]30 
[343]31  // bouton execute
32  exec_go_ = new WPushButton("execute!");
33  exec_go_->clicked().connect(this, &GWt_softwarePanel::executer);
[427]34
[343]35  // le panel
36  WPanel *panelLogiciels = new WPanel(this);
[401]37  panelLogiciels->setTitle(" sections of beam line for executing softwares ");
[343]38 
39  contenuSections_ = new WContainerWidget();
40  contenuSections_->addWidget(exec_go_);
41  contenuSections_->addWidget(new WBreak());
42  contenuSections_->addWidget(new WBreak());
43  addSectionToExecuteW();
44 
45  panelLogiciels->setCentralWidget(contenuSections_);
[302]46}
47
48GWt_softwarePanel::~GWt_softwarePanel() {
49}
50
51void GWt_softwarePanel::addSectionToExecuteW()
[427]52{     
[431]53#if BAVARD > 0
54  cout << "***********************************" << endl;
55  cout << " GWt_softwarePanel::addSectionToExecuteW() " << endl<<endl;
56#endif
57
[401]58  abstractElement* premierElement;
59  abstractElement* dernierElement;
60
61  int premierIndex = 0;
62  int dernierIndex = 0;
[427]63 
[431]64  cout << "sections_.size() = " << sections_.size() << endl;
65
[427]66  // if there is no section
[405]67  if(sections_.size() == 0) {
[427]68    premierElement = pspa_->getBeamLine()->getAbstractElement(0);
69    premierIndex = 0;
70   
71    // if this is not the first :
72    // - first element will be the last of the previous section
73    // (or the same if it is the last of the beam line)
74    // - lastElement will be the last of the beam line
75    // - software will be the first of the list
76   
[343]77  } else {
[405]78    dernierElement = pspa_->getBeamLine()->getAbstractElement(pspa_->getBeamLine()->getBeamLineSize()-1);
79    dernierIndex = pspa_->getBeamLine()->getBeamLineSize()-1;
[427]80   
[405]81    premierElement = dernierElement;
82    premierIndex = dernierIndex;
[343]83  }
84 
[405]85  dernierElement = pspa_->getBeamLine()->getAbstractElement(pspa_->getBeamLine()->getBeamLineSize()-1);
86  dernierIndex = pspa_->getBeamLine()->getBeamLineSize()-1;
[343]87 
[431]88  dtmanage_->addSectionToExecute(premierElement,premierIndex,dernierElement,dernierIndex,nomDeLogiciel());
[401]89
90  std::string premierElementLabel = "";
91  std::string dernierElementLabel = "";
92  if (premierElement) {
93    premierElementLabel = premierElement->getLabel();
[343]94  }
[401]95  if (dernierElement) {
96    dernierElementLabel = dernierElement->getLabel();
97  }
98
99  WComboBox* lineFromCombo = new WComboBox();
100  WComboBox* lineToCombo = new WComboBox();
101  fillComboWithElements(lineFromCombo);
102  fillComboWithElements(lineToCombo);
103
[405]104  // set selection
105  lineFromCombo->setCurrentIndex(premierIndex);
106  lineToCombo->setCurrentIndex(dernierIndex);
107
[401]108  WComboBox* softCombo = new WComboBox();
109  fillComboWithSoftwares(softCombo);
110
[431]111  GWt_sectionToExecute* newSection = new GWt_sectionToExecute(lineFromCombo,lineToCombo,softCombo,createAddDeletePushButtons(sections_.size()),this);
[401]112
[407]113  stringstream st;
114  st << sections_.size();
115
116  // this is the mean to identify this section!
117  newSection->setObjectName(st.str());
118
[401]119  // push back on sections vector
[405]120  sections_.push_back(newSection);
[411]121  contenuSections_->addWidget(newSection);
122  updateSections();
[302]123}
124
[431]125void GWt_softwarePanel::updateSections()
126{
127#if BAVARD > 0
128  cout << "***********************************" << endl;
129  cout << " GWt_softwarePanel::updateSections() " << endl<<endl;
130#endif
131
132  // update all sections in order to manage new/deleted items
133  for (int a = 0; a < sections_.size(); a++) {
134    fillComboWithElements(sections_[a]->getFirstElement());
135    fillComboWithElements(sections_[a]->getLastElement());
136    sections_[a]->getFirstElement()->setEnabled (true);
137    sections_[a]->getLastElement()->setEnabled (true);
138  }
139 
140  if (sections_.size() == 0) {
141    return;
142  }
143 
144  // the first element will always be the first element of the beamLine
145  sections_[0]->getFirstElement()->setCurrentIndex(0);
146  sections_[0]->getFirstElement()->setEnabled (false);
147
148  // the last element will always be the last element of the beamLine
149  sections_[sections_.size()-1]->getLastElement()->setCurrentIndex(sections_[sections_.size()-1]->getLastElement()->count());
150  sections_[sections_.size()-1]->getLastElement()->setEnabled(false);
151
152  // set default values
153  updateSectionSelection();
154}
155
[367]156bool GWt_softwarePanel::updateSectionSelection()
[302]157{
[431]158#if BAVARD > 0
159  cout << "***********************************" << endl;
160  cout << " GWt_softwarePanel::updateSectionSelection() " << endl<<endl;
161#endif
162
[401]163  if ( dtmanage_->getJobListSize() == 0 ) return false;
[343]164 
165  // traitement de la premiere ligne
166  // on impose le depart du calcul au premier element
167  string premier = dtmanage_->getLabelFromElementNumero(1);
[405]168  if (sections_.size() > 0) {
169    sections_[0]->setFirstElementCurrentSelection(premier);
[401]170  }
[343]171 
[405]172  Wt::WString currentString =  sections_[0]->getLastElementCurrentText();
[401]173  int current = dtmanage_->getNumeroFromElementLabel(currentString.toUTF8());
174 
[343]175  // si la fin est mal definie on prend toute la config par defaut
176  if ( current <= 0 || current > dtmanage_->getBeamLineSize() )
[431]177    {
178      current = dtmanage_->getBeamLineSize();
179      currentString =  dtmanage_->getLabelFromElementNumero(current);
180      if (sections_.size() > 0) {
181        sections_[0]->setLastElementCurrentSelection(currentString);
182        //...
183      }
[302]184    }
[343]185  current++;
186  currentString = dtmanage_->getLabelFromElementNumero(current);
187 
188  // traitement des suivantes (on avance d'un cran dans la liste)
[405]189  for (int a = 1; a< sections_.size(); a++)
[302]190    {
[343]191      // debut
192      if ( current > dtmanage_->getBeamLineSize() )
[302]193        {
[412]194          sections_[a]->setErrors("This section element could not be after previous session last element");
195          exec_go_->disable();
196          return false;
[302]197        }
[343]198     
[405]199      sections_[a]->setFirstElementCurrentSelection(currentString);
[401]200
[343]201      // fin
[405]202      string finString =  sections_[a]->getLastElementCurrentText().toUTF8();
[343]203     
204      int numeroFin = dtmanage_->getNumeroFromElementLabel( finString);
205     
[412]206      if ( numeroFin < current)
207      {
208        sections_[a]->setErrors("Last section element should be after first section element");
209        exec_go_->disable();
210        return false;
211      }
212
213      if (numeroFin > dtmanage_->getBeamLineSize())
214      {
215        sections_[a]->setErrors("Last section element number is greater than the beam line size");
216        exec_go_->disable();
217        return false;
218      }
[343]219     
220      // preparation de la ligne suivante
221      current = numeroFin +1;
222      currentString = dtmanage_->getLabelFromElementNumero(current);
[302]223    }
[367]224  //  exec_go_->setDisabled(false);
[401]225
226  if (!areDataCoherent()) {
[431]227#if BAVARD > 0
228    cout << " GWt_softwarePanel::addSectionToExecuteW() DISABLE" << endl;
229#endif
[401]230    exec_go_->disable();
231  } else {
[431]232#if BAVARD > 0
233    cout << " GWt_softwarePanel::addSectionToExecuteW() ENABLE" << endl;
234#endif
[401]235    exec_go_->enable();
236  }
237
[367]238  return true;
[302]239}
240
241bool GWt_softwarePanel::areDataCoherent()
242{
[431]243#if BAVARD > 0
244  cout << "***********************************" << endl;
245  cout << " GWt_softwarePanel::areDataCoherent() " << endl<<endl;
246#endif
247
[371]248  bool caMarche = true;
[401]249
250  // initialize dataManager
[371]251  dtmanage_->initializeExecution();
[401]252 
253  // intialize User Interface
254  if (pspa_->getBeamLine()) {
255    pspa_->getBeamLine()->initializeSoftwares();
256  }
[431]257       
[401]258  string diagnosticErrors;
259  string diagnosticWarnings;
[431]260  for (int a = 0; a < sections_.size(); a++) 
[418]261    {
[431]262      string debString= sections_[a]->getFirstElementCurrentText().toUTF8();
263      string finString= sections_[a]->getLastElementCurrentText().toUTF8();
[418]264      int debut = pspa_->getBeamLine()->getAbstractElementNumeroFromLabel(debString);
265      int fin = pspa_->getBeamLine()->getAbstractElementNumeroFromLabel(finString);
[419]266
[431]267      string currentSoft= sections_[a]->getSoftwareCurrentText().toUTF8();
268      nomDeLogiciel prog = nomDeLogiciel(currentSoft);
269      sectionToExecute* sectToExec = dtmanage_->addSectionToExecute(pspa_->getBeamLine()->getAbstractElement(debut),debut,pspa_->getBeamLine()->getAbstractElement(fin),fin,prog);
270
[419]271      abstractSoftware* softToExec = sectToExec->getSoftware(); 
[418]272      diagnosticErrors = "";
273      diagnosticWarnings = "";
[431]274      for(int i = debut-1; i < fin; i++) // check sections
275        {
276          if (!pspa_->getBeamLine()) continue;
277          abstractElement* elPtr= pspa_->getBeamLine()->getAbstractElement(i);   
278          if (!elPtr) continue; 
[401]279
[431]280          trivaluedBool tb = softToExec->doAcceptElement(elPtr->getNomdElement().getElementType());
281          if (tb  == TBoolOk ) {
282            elPtr->setSoftware(softToExec);
283          } else {
284            elPtr->setSoftware(NULL);
285            if (tb == TBoolIgnore) {
286              if(prog.getString() != "unknownSoftware") diagnosticWarnings += elPtr->getLabel() + " will be ignored by  "+ prog.getString() + "<br /> ";           
[418]287            } else {
[431]288              // j'insiste pour remettre le nom generique de l'element refuse (glm / 30/03/2013)
289              diagnosticErrors += elPtr->getNomdElement().getExpandedName() + " is not allowed with " + prog.getString() + "<br /> ";
290              caMarche = false;
[418]291            }
292          }
[431]293          pspa_->getBeamLine()->update(i);
294        } //i
295     
[418]296      // set errors and warnings
297      sections_[a]->setErrors(diagnosticErrors);
298      sections_[a]->setWarnings(diagnosticWarnings);
[431]299    }//a
[359]300   
[371]301  return caMarche;
[302]302}
303
[407]304void GWt_softwarePanel::deleteSectionToExecuteW(int sectionLabel)
[302]305{
[436]306#if BAVARD > 0
307  cout << "***********************************" << endl;
308  cout << " GWt_softwarePanel::deleteSectionToExecuteW()" << endl<<endl;
309#endif
310
[407]311  stringstream st;
312  st << sectionLabel;
313  std::string sectionName = st.str();
314 
315  if ( dtmanage_->getJobListSize() == 0 ) return;
316  for (unsigned int sectionIndex = 0; sectionIndex< sections_.size(); sectionIndex++) {
317    if (sections_[sectionIndex]->objectName() == sectionName) {
[401]318
[407]319      // delete from dataManager
320      dtmanage_->clearSectionToExecute(sectionIndex);
321
322      // delete from User Interface
323      contenuSections_->removeWidget(sections_[sectionIndex]);
324      delete sections_[sectionIndex];
325      sections_.erase (sections_.begin()+sectionIndex);
326    }
327  } 
[302]328}
329
[431]330void GWt_softwarePanel::executer()
[302]331{
[431]332  cout << "***********************************" << endl;
333  cout << " GWt_softwarePanel::executer() " << endl<<endl;
[405]334
[401]335  if (!areDataCoherent()) {
[358]336    return;
[427]337  } 
[401]338 
[431]339  //static_cast<GWt_globalParameters*>(pspa_->getGlobalParam())->updateGlobals();
[343]340 
341  GWt_dialog calculDialog("Calcul en cours", "Veuillez patienter...", GWt_dialog::Wait, true,false);
342  calculDialog.show();
[302]343   
[343]344  wApp->processEvents();
345 
346  if (!dtmanage_->executeAll()) {
[431]347    GWt_dialog warningDialog("PSPA : Echec", " echec lors de l'exécution !", GWt_dialog::Error, true,true);
[343]348    warningDialog.exec();
349  }
350     
[367]351  //  exec_go_->setDisabled(true);
[343]352  calculDialog.hide(); 
353  pspa_->faireDessin();
[302]354}
[401]355
[431]356void GWt_softwarePanel::fillComboWithElements(Wt::WComboBox* cBox) 
357{
[401]358  if (cBox == NULL) return;
359
360  // get the last item selected
[431]361  WString selectedString = cBox->currentText();
[401]362  cBox->clear();
363
[431]364  for(int a = 0; a < pspa_->getBeamLine()->getBeamLineSize(); a++) {
[401]365    abstractElement* abs = pspa_->getBeamLine()->getAbstractElement(a);
[431]366    if (abs != NULL) {
[401]367      cBox->addItem(abs->getLabel());
368    }
369  }
370 
[431]371  for(int a = 0; a < cBox->count(); a++) {
[401]372    if (cBox->itemText (a) == selectedString) {
373      cBox->setCurrentIndex(a);
374    }
375  }
[405]376  cBox->refresh();
[401]377}
378
[431]379void GWt_softwarePanel::fillComboWithSoftwares(Wt::WComboBox* cBox) 
380{
381#if BAVARD > 0
382  cout << "***********************************" << endl;
383  cout << " GWt_softwarePanel::fillComboWithSoftwares " << endl<<endl;
384#endif
[401]385
386  if (cBox == NULL) return;
387  cBox->clear();
388
389  unsigned nb = nomDeLogiciel::getNumberOfSoftwares();
390  unsigned k;
[431]391  for(k = 0; k <= nb; k++) { //xx
[401]392    cBox->addItem(nomDeLogiciel(k).getString());
393  }
[431]394  cBox->setCurrentIndex(nb); // xx
[405]395  cBox->refresh();
[401]396}
397
[431]398Wt::WContainerWidget* GWt_softwarePanel::createAddDeletePushButtons(int sectionNumber) 
399{
[401]400  WContainerWidget* buttonContainer= new WContainerWidget();
401 
402  Wt::WHBoxLayout* buttonContainerLayout = new Wt::WHBoxLayout();
403  buttonContainerLayout->setContentsMargins(0,0,0,0);
404  // preparation du bouton add
405  WPushButton* exec_add = new WPushButton("+");
406  exec_add->clicked().connect(this, &GWt_softwarePanel::addSectionToExecuteW);
407  exec_add->setStyleClass("roundButton");
408  exec_add->setMaximumSize(20,20);
409  exec_add->setToolTip("Add new section");
410 
411  // preparation du bouton delete
412  WPushButton* exec_delete = new WPushButton("-");
413  //  warningsContainer_->setStyleClass("warningsContainer");
[407]414
415  exec_delete->clicked().connect(boost::bind(&GWt_softwarePanel::deleteSectionToExecuteW, this, sectionNumber));
[401]416  exec_delete->setStyleClass("roundButton");
417  exec_delete->setMaximumSize(20,20);
[405]418  exec_delete->setToolTip("Remove this section");
[401]419
420  buttonContainerLayout->addWidget(exec_add);
421  buttonContainerLayout->addWidget(exec_delete);
422  buttonContainer->setLayout(buttonContainerLayout);
423
424  return buttonContainer;
[413]425}
Note: See TracBrowser for help on using the repository browser.