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

Last change on this file since 413 was 413, checked in by lemeur, 11 years ago

vérification (dataManager) de la consécution des sections

File size: 16.8 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"
[302]21
22
23GWt_softwarePanel::GWt_softwarePanel(dataManager* dataManager,PspaApplication* pspa)
[343]24  : WContainerWidget() 
25{
26  dtmanage_ = dataManager;
27  pspa_ = pspa;
[401]28 
[343]29  // bouton execute
30  exec_go_ = new WPushButton("execute!");
31  //    exec_go_->setMinimumSize(300,300);
[367]32  //  exec_go_->setDisabled(true);
[343]33  exec_go_->clicked().connect(this, &GWt_softwarePanel::executer);
34 
[302]35   
[343]36  // preparation du bouton push_ok
[367]37  //  WPushButton* exec_ok = new WPushButton("ok");
38  //  exec_ok->clicked().connect(this, &GWt_softwarePanel::updateSectionSelection);
[343]39 
40  // le panel
41  WPanel *panelLogiciels = new WPanel(this);
[401]42  panelLogiciels->setTitle(" sections of beam line for executing softwares ");
[343]43 
44  contenuSections_ = new WContainerWidget();
[367]45  //  contenuSections_->addWidget(exec_ok);
[343]46  contenuSections_->addWidget(exec_go_);
47  contenuSections_->addWidget(new WBreak());
48  contenuSections_->addWidget(new WBreak());
49  addSectionToExecuteW();
50 
51  panelLogiciels->setCentralWidget(contenuSections_);
[302]52}
53
54GWt_softwarePanel::~GWt_softwarePanel() {
55}
56
57void GWt_softwarePanel::addSectionToExecuteW()
[343]58{   
59 
[401]60  abstractElement* premierElement;
61  abstractElement* dernierElement;
62
63  int premierIndex = 0;
64  int dernierIndex = 0;
65
[405]66    // if there is no section
67  if(sections_.size() == 0) {
[401]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;
80
81    premierElement = dernierElement;
82    premierIndex = dernierIndex;
83   
84/*    int indexOfLastElementOfLastSection = dtmanage_->getJobListAt(dtmanage_->getJobListSize()-1)->getLastElementNumberInSection();
85
86   
87    // if there are still elements at the end
[401]88    if (pspa_->getBeamLine()->getAbstractElement(indexOfLastElementOfLastSection+1) != NULL ) {
89      premierIndex = indexOfLastElementOfLastSection+1;
90      premierElement = pspa_->getBeamLine()->getAbstractElement(indexOfLastElementOfLastSection+1);
[405]91
92      // if this is the last element
[343]93    } else {
[401]94      premierIndex = indexOfLastElementOfLastSection;
95      premierElement = pspa_->getBeamLine()->getAbstractElement(indexOfLastElementOfLastSection);
96       
[302]97    }
[405]98 */
[343]99  }
100 
[405]101  dernierElement = pspa_->getBeamLine()->getAbstractElement(pspa_->getBeamLine()->getBeamLineSize()-1);
102  dernierIndex = pspa_->getBeamLine()->getBeamLineSize()-1;
[343]103  //  cout << "PspaApplication::addSectionToExecute() : " << premierText << " à  " << dernierText << endl;
104 
105 
[401]106  abstractSoftware* soft = NULL;
107  dtmanage_->addSectionToExecute(premierElement,premierIndex, dernierElement, dernierIndex, soft);
108
109  std::string premierElementLabel = "";
110  std::string dernierElementLabel = "";
111  if (premierElement) {
112    premierElementLabel = premierElement->getLabel();
[343]113  }
[401]114
115  if (dernierElement) {
116    dernierElementLabel = dernierElement->getLabel();
117  }
118
119  WComboBox* lineFromCombo = new WComboBox();
120  WComboBox* lineToCombo = new WComboBox();
121  fillComboWithElements(lineFromCombo);
122  fillComboWithElements(lineToCombo);
123
[405]124  // set selection
125  lineFromCombo->setCurrentIndex(premierIndex);
126  lineToCombo->setCurrentIndex(dernierIndex);
127
[401]128  WComboBox* softCombo = new WComboBox();
129  fillComboWithSoftwares(softCombo);
130
[407]131  GWt_sectionToExecute* newSection = new GWt_sectionToExecute(lineFromCombo, lineToCombo, softCombo,createAddDeletePushButtons(sections_.size()),this);
[401]132
[407]133  stringstream st;
134  st << sections_.size();
135
136  // this is the mean to identify this section!
137  newSection->setObjectName(st.str());
138
[401]139  // push back on sections vector
[405]140  sections_.push_back(newSection);
[401]141
[411]142  contenuSections_->addWidget(newSection);
[401]143 
[411]144  updateSections();
[302]145}
146
147
[367]148// void GWt_softwarePanel::disableSectionExecute()
149// {
150//   exec_go_->setDisabled(true);
151// }
[302]152
153
[358]154// void GWt_softwarePanel::checkSectionSelection()
155// {
156//   if ( selectedSections_.empty() ) return;
157 
158//   // traitement de la premiere ligne
159//   // on impose le depart du calcul au premier element
160//   string premier = dtmanage_->getLabelFromElementNumero(1);
161//   (*selectedSections_.begin())->debut->setText(premier);
162 
163//   string currentString =  (*selectedSections_.begin())->fin->text().toUTF8();
164//   int current = dtmanage_->getNumeroFromElementLabel(currentString);
165   
166//   // si la fin est mal definie on prend toute la config par defaut
167//   if ( current <= 0 || current > dtmanage_->getBeamLineSize() )
168//     {
169//       current = dtmanage_->getBeamLineSize();
170//       currentString =  dtmanage_->getLabelFromElementNumero(current);
171//       (*selectedSections_.begin())->fin->setText(currentString);
172//     }
173//   current++;
174//   currentString = dtmanage_->getLabelFromElementNumero(current);
175 
176//   // traitement des suivantes (on avance d'un cran dans la liste)
177//   list<GWt_sectionToExecute*>::iterator itr, itr0;
178//   itr0 = selectedSections_.begin();
179//   itr0++;
180//   for (itr = itr0; itr != selectedSections_.end(); itr++)
181//     {
182//       // debut
183//       if ( current > dtmanage_->getBeamLineSize() )
184//         {
185//        GWt_dialog warningDialog("PSPA :: verification des sections", " bad section definition !", GWt_dialog::Error,true,true);
186//        warningDialog.exec();
187//        return;
188//         }
189     
190//       (*itr)->debut->setText(currentString);
191//       // fin
192//       string finString =  (*itr)->fin->text().toUTF8();
193     
194//       int numeroFin = dtmanage_->getNumeroFromElementLabel( finString);
195     
196//       if ( numeroFin < current || numeroFin > dtmanage_->getBeamLineSize())
197//         {
198//        GWt_dialog warningDialog("PSPA : Checking of sections", " bad section definition !", GWt_dialog::Error, true,true);
199//        warningDialog.exec();
200//        return;
201//         }
202     
203//       // preparation de la ligne suivante
204//       current = numeroFin +1;
205//       currentString = dtmanage_->getLabelFromElementNumero(current);
206//     }
207 
208//   if (!areDataCoherent()) {
209//     GWt_dialog warningDialog("PSPA : verification des sections", " donnees incoherentes !", GWt_dialog::Error,true,true);
210//     warningDialog.exec();
211//   }
212//   else
213//     {
214//       exec_go_->setDisabled(false);
215       
216//         // All ok, then put colors on beamLine
217//         list<GWt_sectionToExecute*>::iterator itr2;
218//         for(itr2 = selectedSections_.begin();itr2 != selectedSections_.end(); itr2++)
219//         {
220//             string debString = (*itr2)->debut->text().toUTF8();
221//             string finString = (*itr2)->fin->text().toUTF8();
222           
223           
224//             int debut = dtmanage_->getNumeroFromElementLabel(debString);
225//             int fin = dtmanage_->getNumeroFromElementLabel(finString);
226// /**
227//  for (int i=debut; i=<fin; i++) {
228//                 getBeamLine()->getAbstractElement(i)->setBGColor(
229               
230//             }
231//             nomDeLogiciel prog = nomDeLogiciel ( (*itr)->selection->currentIndex() );
232//             dtmanage_->addSectionToExecute(debut,fin,prog);
233// */
234//         }
235//     }
236   
237
238// }
239
[367]240bool GWt_softwarePanel::updateSectionSelection()
[302]241{
[401]242  if ( dtmanage_->getJobListSize() == 0 ) return false;
[343]243 
244  // traitement de la premiere ligne
245  // on impose le depart du calcul au premier element
246  string premier = dtmanage_->getLabelFromElementNumero(1);
[405]247  if (sections_.size() > 0) {
248    sections_[0]->setFirstElementCurrentSelection(premier);
[401]249  }
[343]250 
[405]251  Wt::WString currentString =  sections_[0]->getLastElementCurrentText();
[401]252  int current = dtmanage_->getNumeroFromElementLabel(currentString.toUTF8());
253 
[343]254  // si la fin est mal definie on prend toute la config par defaut
255  if ( current <= 0 || current > dtmanage_->getBeamLineSize() )
[401]256  {
257    current = dtmanage_->getBeamLineSize();
258    currentString =  dtmanage_->getLabelFromElementNumero(current);
[405]259    if (sections_.size() > 0) {
260      sections_[0]->setLastElementCurrentSelection(currentString);
[401]261//...
[302]262    }
[401]263  }
[343]264  current++;
265  currentString = dtmanage_->getLabelFromElementNumero(current);
266 
267  // traitement des suivantes (on avance d'un cran dans la liste)
[405]268  for (int a = 1; a< sections_.size(); a++)
[302]269    {
[343]270      // debut
271      if ( current > dtmanage_->getBeamLineSize() )
[302]272        {
[412]273          sections_[a]->setErrors("This section element could not be after previous session last element");
274          exec_go_->disable();
275          return false;
[302]276        }
[343]277     
[405]278      sections_[a]->setFirstElementCurrentSelection(currentString);
[401]279
[343]280      // fin
[405]281      string finString =  sections_[a]->getLastElementCurrentText().toUTF8();
[343]282     
283      int numeroFin = dtmanage_->getNumeroFromElementLabel( finString);
284     
[412]285      if ( numeroFin < current)
286      {
287        sections_[a]->setErrors("Last section element should be after first section element");
288        exec_go_->disable();
289        return false;
290      }
291
292      if (numeroFin > dtmanage_->getBeamLineSize())
293      {
294        sections_[a]->setErrors("Last section element number is greater than the beam line size");
295        exec_go_->disable();
296        return false;
297      }
[343]298     
299      // preparation de la ligne suivante
300      current = numeroFin +1;
301      currentString = dtmanage_->getLabelFromElementNumero(current);
[302]302    }
[367]303  //  exec_go_->setDisabled(false);
[401]304
305  if (!areDataCoherent()) {
306    exec_go_->disable();
307  } else {
308    exec_go_->enable();
309  }
310
[367]311  return true;
[302]312}
313
314
315bool GWt_softwarePanel::areDataCoherent()
316{
[371]317  bool caMarche = true;
[401]318
319  // initialize dataManager
[371]320  dtmanage_->initializeExecution();
[401]321 
322  // intialize User Interface
323  if (pspa_->getBeamLine()) {
324    pspa_->getBeamLine()->initializeSoftwares();
325  }
326 
327  string diagnosticErrors;
328  string diagnosticWarnings;
329 
[405]330  for (int a = 0; a< sections_.size(); a++)
[401]331  {
[405]332    string debString = sections_[a]->getFirstElementCurrentText().toUTF8();
333    string finString = sections_[a]->getLastElementCurrentText().toUTF8();
[359]334   
[401]335    int debut = pspa_->getBeamLine()->getAbstractElementIndexFromLabel(debString)+1; // FIXME : Should NOT be +1
336    int fin = pspa_->getBeamLine()->getAbstractElementIndexFromLabel(finString)+1; // FIXME : Should NOT be +1
337   
[405]338    nomDeLogiciel prog = nomDeLogiciel ( sections_[a]->getSoftwareCurrentText().toUTF8());
[401]339    dtmanage_->addSectionToExecute(pspa_->getBeamLine()->getAbstractElement(debut),
340                                   debut,
341                                   pspa_->getBeamLine()->getAbstractElement(fin),
342                                   fin,
343                                   dtmanage_->createSoftwareConnexion(prog));
344   
345    diagnosticErrors = "";
346    diagnosticWarnings = "";
347
348    // check sections
349    for (int i=debut-1; i<fin; i++) {
350      if (pspa_->getBeamLine()) {
351        if (pspa_->getBeamLine()->getAbstractElement(i)) {
352          trivaluedBool tb = pspa_->getBeamLine()->getAbstractElement(i)->setSoftware(prog.getString());
353          if (tb  == TBoolError ) {
[413]354            // j'insiste pour remettre le nom generique de l'element refuse (glm / 30/03/2013)
355            diagnosticErrors += pspa_->getBeamLine()->getAbstractElement(i)->getNomdElement().getElementName() + " is not allowed with "+ prog.getString()+"<br /> ";
[401]356
357            caMarche = false;
358
359            // intialize thissoftware
360            pspa_->getBeamLine()->getAbstractElement(i)->setSoftware(nomDeLogiciel::unknownSoftware);
361
362          } else if ( tb == TBoolIgnore ) {
363            diagnosticWarnings += pspa_->getBeamLine()->getAbstractElement(i)->getLabel() + " will be ignored by  "+ prog.getString()+"<br /> ";
364           
365
366          }
367          pspa_->getBeamLine()->update(i);
368        }
[371]369      }
[302]370    }
[401]371    // set errors and warnings
[405]372    sections_[a]->setErrors(diagnosticErrors);
373    sections_[a]->setWarnings(diagnosticWarnings);
[371]374  }
[359]375   
[371]376  return caMarche;
[302]377}
378
[407]379void GWt_softwarePanel::deleteSectionToExecuteW(int sectionLabel)
[302]380{
[407]381  stringstream st;
382  st << sectionLabel;
383  std::string sectionName = st.str();
384 
385  if ( dtmanage_->getJobListSize() == 0 ) return;
386  for (unsigned int sectionIndex = 0; sectionIndex< sections_.size(); sectionIndex++) {
387    if (sections_[sectionIndex]->objectName() == sectionName) {
[401]388
[407]389      // delete from dataManager
390      dtmanage_->clearSectionToExecute(sectionIndex);
391
392      // delete from User Interface
393      contenuSections_->removeWidget(sections_[sectionIndex]);
394      delete sections_[sectionIndex];
395      sections_.erase (sections_.begin()+sectionIndex);
396    }
397  } 
[302]398}
399
400
[401]401void GWt_softwarePanel::updateSections()
[302]402{
[401]403  // update all sections in order to manage new/deleted items
[405]404  for (int a = 0; a< sections_.size(); a++) {
405    fillComboWithElements(sections_[a]->getFirstElement());
406    fillComboWithElements(sections_[a]->getLastElement());
407
408    sections_[a]->getFirstElement()->setEnabled (true);
409    sections_[a]->getLastElement()->setEnabled (true);
[401]410  }
[405]411  if (sections_.size() == 0) {
[401]412    return;
413  }
414  // the first element will always be the first element of the beamLine
[405]415  sections_[0]->getFirstElement()->setCurrentIndex(0);
416  sections_[0]->getFirstElement()->setEnabled (false);
417
[401]418  // the last element will always be the last element of the beamLine
[405]419  sections_[sections_.size()-1]->getLastElement()->setCurrentIndex(sections_[sections_.size()-1]->getLastElement()->count());
420  sections_[sections_.size()-1]->getLastElement()->setEnabled (false);
[401]421
422  // set default values
423
424  // update
425  updateSectionSelection();
[302]426}
427
428
[401]429
430/*
431 string GWt_softwarePanel::getSelection()
[302]432{
[343]433  list<GWt_sectionToExecute*>::iterator itr = selectedSections_.begin();
434  string str = (*itr)->fin->text().toUTF8();
435  return str;
[302]436}
[401]437*/
[302]438
439void GWt_softwarePanel::executer()
440{
[367]441
[401]442  if (!areDataCoherent()) {
443    //    GWt_dialog warningDialog("PSPA : verification des sections", " donnees incoherentes !", GWt_dialog::Error,true,true);
444    //    warningDialog.exec();
445    //    exec_go_->setDisabled(true);
[358]446    return;
[401]447  }
448 
[398]449  // GWt_console* console = NULL;
450  // if (static_cast<GWt_console*> (wApp->findWidget ("console"))) {
451  //   console = static_cast<GWt_console*> (wApp->findWidget ("console"));
452  //   console->addConsoleMessage(string("on va peut etre y arriver"));
453  // }
[343]454 
455  static_cast<GWt_globalParameters*>(pspa_->getGlobalParam())->updateGlobals();
456 
457  GWt_dialog calculDialog("Calcul en cours", "Veuillez patienter...", GWt_dialog::Wait, true,false);
458  calculDialog.show();
[302]459   
[343]460  wApp->processEvents();
461 
462  if (!dtmanage_->executeAll()) {
463    GWt_dialog warningDialog("PSPA : Echec", " echec lors de l'exÈcution !", GWt_dialog::Error, true,true);
464    warningDialog.exec();
465  }
466     
[367]467  //  exec_go_->setDisabled(true);
[343]468  calculDialog.hide(); 
469  pspa_->faireDessin();
[302]470}
[401]471
472
473void GWt_softwarePanel::fillComboWithElements(Wt::WComboBox* cBox) {
474  if (cBox == NULL) return;
475
476  // get the last item selected
477  WString selectedString = cBox->currentText ();
478  cBox->clear();
479
480  for (int a=0; a< pspa_->getBeamLine()->getBeamLineSize(); a++) {
481    abstractElement* abs = pspa_->getBeamLine()->getAbstractElement(a);
482    if (abs != NULL){
483      cBox->addItem(abs->getLabel());
484    }
485  }
486 
487  for (int a=0; a<cBox->count(); a++) {
488    if (cBox->itemText (a) == selectedString) {
489      cBox->setCurrentIndex(a);
490    }
491  }
[405]492  cBox->refresh();
[401]493}
494
495
496void GWt_softwarePanel::fillComboWithSoftwares(Wt::WComboBox* cBox) {
497  if (cBox == NULL) return;
498  cBox->clear();
499
500  unsigned nb = nomDeLogiciel::getNumberOfSoftwares();
501  unsigned k;
502  for(k = 0; k < nb; k++) {
503    cBox->addItem(nomDeLogiciel(k).getString());
504  }
[405]505  cBox->refresh();
[401]506}
507
508
[407]509Wt::WContainerWidget* GWt_softwarePanel::createAddDeletePushButtons(int sectionNumber) {
[401]510
511  WContainerWidget* buttonContainer= new WContainerWidget();
512 
513  Wt::WHBoxLayout* buttonContainerLayout = new Wt::WHBoxLayout();
514  buttonContainerLayout->setContentsMargins(0,0,0,0);
515  // preparation du bouton add
516  WPushButton* exec_add = new WPushButton("+");
517  exec_add->clicked().connect(this, &GWt_softwarePanel::addSectionToExecuteW);
518  exec_add->setStyleClass("roundButton");
519  exec_add->setMaximumSize(20,20);
520  exec_add->setToolTip("Add new section");
521 
522  // preparation du bouton delete
523  WPushButton* exec_delete = new WPushButton("-");
524  //  warningsContainer_->setStyleClass("warningsContainer");
[407]525
526  exec_delete->clicked().connect(boost::bind(&GWt_softwarePanel::deleteSectionToExecuteW, this, sectionNumber));
[401]527  exec_delete->setStyleClass("roundButton");
528  exec_delete->setMaximumSize(20,20);
[405]529  exec_delete->setToolTip("Remove this section");
[401]530
531  buttonContainerLayout->addWidget(exec_add);
532  buttonContainerLayout->addWidget(exec_delete);
533
534  buttonContainer->setLayout(buttonContainerLayout);
535
536  return buttonContainer;
[413]537}
Note: See TracBrowser for help on using the repository browser.