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

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

Passage en blanc des elements ignorés dans la beamLine

File size: 16.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_globalParameters.h"
20#include "GWt_sectionToExecute.h"
21
22
23GWt_softwarePanel::GWt_softwarePanel(dataManager* dataManager,PspaApplication* pspa)
24  : WContainerWidget() 
25{
26  dtmanage_ = dataManager;
27  pspa_ = pspa;
28 
29  // bouton execute
30  exec_go_ = new WPushButton("execute!");
31  //    exec_go_->setMinimumSize(300,300);
32  //  exec_go_->setDisabled(true);
33  exec_go_->clicked().connect(this, &GWt_softwarePanel::executer);
34 
35   
36  // preparation du bouton push_ok
37  //  WPushButton* exec_ok = new WPushButton("ok");
38  //  exec_ok->clicked().connect(this, &GWt_softwarePanel::updateSectionSelection);
39 
40  // le panel
41  WPanel *panelLogiciels = new WPanel(this);
42  panelLogiciels->setTitle(" sections of beam line for executing softwares ");
43 
44  contenuSections_ = new WContainerWidget();
45  //  contenuSections_->addWidget(exec_ok);
46  contenuSections_->addWidget(exec_go_);
47  contenuSections_->addWidget(new WBreak());
48  contenuSections_->addWidget(new WBreak());
49  addSectionToExecuteW();
50 
51  panelLogiciels->setCentralWidget(contenuSections_);
52}
53
54GWt_softwarePanel::~GWt_softwarePanel() {
55}
56
57void GWt_softwarePanel::addSectionToExecuteW()
58{   
59 
60  abstractElement* premierElement;
61  abstractElement* dernierElement;
62
63  int premierIndex = 0;
64  int dernierIndex = 0;
65
66    // if there is no section
67  if(sections_.size() == 0) {
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     
77  } else {
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
88    if (pspa_->getBeamLine()->getAbstractElement(indexOfLastElementOfLastSection+1) != NULL ) {
89      premierIndex = indexOfLastElementOfLastSection+1;
90      premierElement = pspa_->getBeamLine()->getAbstractElement(indexOfLastElementOfLastSection+1);
91
92      // if this is the last element
93    } else {
94      premierIndex = indexOfLastElementOfLastSection;
95      premierElement = pspa_->getBeamLine()->getAbstractElement(indexOfLastElementOfLastSection);
96       
97    }
98 */
99  }
100 
101  dernierElement = pspa_->getBeamLine()->getAbstractElement(pspa_->getBeamLine()->getBeamLineSize()-1);
102  dernierIndex = pspa_->getBeamLine()->getBeamLineSize()-1;
103  //  cout << "PspaApplication::addSectionToExecute() : " << premierText << " à  " << dernierText << endl;
104 
105 
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();
113  }
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
124  // set selection
125  lineFromCombo->setCurrentIndex(premierIndex);
126  lineToCombo->setCurrentIndex(dernierIndex);
127
128  WComboBox* softCombo = new WComboBox();
129  fillComboWithSoftwares(softCombo);
130
131  GWt_sectionToExecute* newSection = new GWt_sectionToExecute(lineFromCombo, lineToCombo, softCombo,createAddDeletePushButtons(sections_.size()),this);
132
133  stringstream st;
134  st << sections_.size();
135
136  // this is the mean to identify this section!
137  newSection->setObjectName(st.str());
138
139  // push back on sections vector
140  sections_.push_back(newSection);
141
142  contenuSections_->addWidget(newSection);
143 
144  updateSections();
145}
146
147
148// void GWt_softwarePanel::disableSectionExecute()
149// {
150//   exec_go_->setDisabled(true);
151// }
152
153
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
240bool GWt_softwarePanel::updateSectionSelection()
241{
242  if ( dtmanage_->getJobListSize() == 0 ) return false;
243 
244  // traitement de la premiere ligne
245  // on impose le depart du calcul au premier element
246  string premier = dtmanage_->getLabelFromElementNumero(1);
247  if (sections_.size() > 0) {
248    sections_[0]->setFirstElementCurrentSelection(premier);
249  }
250 
251  Wt::WString currentString =  sections_[0]->getLastElementCurrentText();
252  int current = dtmanage_->getNumeroFromElementLabel(currentString.toUTF8());
253 
254  // si la fin est mal definie on prend toute la config par defaut
255  if ( current <= 0 || current > dtmanage_->getBeamLineSize() )
256  {
257    current = dtmanage_->getBeamLineSize();
258    currentString =  dtmanage_->getLabelFromElementNumero(current);
259    if (sections_.size() > 0) {
260      sections_[0]->setLastElementCurrentSelection(currentString);
261//...
262    }
263  }
264  current++;
265  currentString = dtmanage_->getLabelFromElementNumero(current);
266 
267  // traitement des suivantes (on avance d'un cran dans la liste)
268  for (int a = 1; a< sections_.size(); a++)
269    {
270      // debut
271      if ( current > dtmanage_->getBeamLineSize() )
272        {
273          sections_[a]->setErrors("This section element could not be after previous session last element");
274          exec_go_->disable();
275          return false;
276        }
277     
278      sections_[a]->setFirstElementCurrentSelection(currentString);
279
280      // fin
281      string finString =  sections_[a]->getLastElementCurrentText().toUTF8();
282     
283      int numeroFin = dtmanage_->getNumeroFromElementLabel( finString);
284     
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      }
298     
299      // preparation de la ligne suivante
300      current = numeroFin +1;
301      currentString = dtmanage_->getLabelFromElementNumero(current);
302    }
303  //  exec_go_->setDisabled(false);
304
305  if (!areDataCoherent()) {
306    exec_go_->disable();
307  } else {
308    exec_go_->enable();
309  }
310
311  return true;
312}
313
314
315bool GWt_softwarePanel::areDataCoherent()
316{
317  bool caMarche = true;
318
319  // initialize dataManager
320  dtmanage_->initializeExecution();
321 
322  // intialize User Interface
323  if (pspa_->getBeamLine()) {
324    pspa_->getBeamLine()->initializeSoftwares();
325  }
326 
327  string diagnosticErrors;
328  string diagnosticWarnings;
329 
330  for (int a = 0; a< sections_.size(); a++)
331  {
332    string debString = sections_[a]->getFirstElementCurrentText().toUTF8();
333    string finString = sections_[a]->getLastElementCurrentText().toUTF8();
334   
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   
338    nomDeLogiciel prog = nomDeLogiciel ( sections_[a]->getSoftwareCurrentText().toUTF8());
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 ) {
354            diagnosticErrors += pspa_->getBeamLine()->getAbstractElement(i)->getLabel() + " is not allowed with "+ prog.getString()+"<br /> ";
355
356            caMarche = false;
357
358            // intialize thissoftware
359            pspa_->getBeamLine()->getAbstractElement(i)->setSoftware(nomDeLogiciel::unknownSoftware);
360
361          } else if ( tb == TBoolIgnore ) {
362            diagnosticWarnings += pspa_->getBeamLine()->getAbstractElement(i)->getLabel() + " will be ignored by  "+ prog.getString()+"<br /> ";
363           
364
365          }
366          pspa_->getBeamLine()->update(i);
367        }
368      }
369    }
370    // set errors and warnings
371    sections_[a]->setErrors(diagnosticErrors);
372    sections_[a]->setWarnings(diagnosticWarnings);
373  }
374   
375  return caMarche;
376}
377
378void GWt_softwarePanel::deleteSectionToExecuteW(int sectionLabel)
379{
380  stringstream st;
381  st << sectionLabel;
382  std::string sectionName = st.str();
383 
384  if ( dtmanage_->getJobListSize() == 0 ) return;
385  for (unsigned int sectionIndex = 0; sectionIndex< sections_.size(); sectionIndex++) {
386    if (sections_[sectionIndex]->objectName() == sectionName) {
387
388      // delete from dataManager
389      dtmanage_->clearSectionToExecute(sectionIndex);
390
391      // delete from User Interface
392      contenuSections_->removeWidget(sections_[sectionIndex]);
393      delete sections_[sectionIndex];
394      sections_.erase (sections_.begin()+sectionIndex);
395    }
396  } 
397}
398
399
400void GWt_softwarePanel::updateSections()
401{
402  // update all sections in order to manage new/deleted items
403  for (int a = 0; a< sections_.size(); a++) {
404    fillComboWithElements(sections_[a]->getFirstElement());
405    fillComboWithElements(sections_[a]->getLastElement());
406
407    sections_[a]->getFirstElement()->setEnabled (true);
408    sections_[a]->getLastElement()->setEnabled (true);
409  }
410  if (sections_.size() == 0) {
411    return;
412  }
413  // the first element will always be the first element of the beamLine
414  sections_[0]->getFirstElement()->setCurrentIndex(0);
415  sections_[0]->getFirstElement()->setEnabled (false);
416
417  // the last element will always be the last element of the beamLine
418  sections_[sections_.size()-1]->getLastElement()->setCurrentIndex(sections_[sections_.size()-1]->getLastElement()->count());
419  sections_[sections_.size()-1]->getLastElement()->setEnabled (false);
420
421  // set default values
422
423  // update
424  updateSectionSelection();
425}
426
427
428
429/*
430 string GWt_softwarePanel::getSelection()
431{
432  list<GWt_sectionToExecute*>::iterator itr = selectedSections_.begin();
433  string str = (*itr)->fin->text().toUTF8();
434  return str;
435}
436*/
437
438void GWt_softwarePanel::executer()
439{
440
441  if (!areDataCoherent()) {
442    //    GWt_dialog warningDialog("PSPA : verification des sections", " donnees incoherentes !", GWt_dialog::Error,true,true);
443    //    warningDialog.exec();
444    //    exec_go_->setDisabled(true);
445    return;
446  }
447 
448  // GWt_console* console = NULL;
449  // if (static_cast<GWt_console*> (wApp->findWidget ("console"))) {
450  //   console = static_cast<GWt_console*> (wApp->findWidget ("console"));
451  //   console->addConsoleMessage(string("on va peut etre y arriver"));
452  // }
453 
454  static_cast<GWt_globalParameters*>(pspa_->getGlobalParam())->updateGlobals();
455 
456  GWt_dialog calculDialog("Calcul en cours", "Veuillez patienter...", GWt_dialog::Wait, true,false);
457  calculDialog.show();
458   
459  wApp->processEvents();
460 
461  if (!dtmanage_->executeAll()) {
462    GWt_dialog warningDialog("PSPA : Echec", " echec lors de l'exÈcution !", GWt_dialog::Error, true,true);
463    warningDialog.exec();
464  }
465     
466  //  exec_go_->setDisabled(true);
467  calculDialog.hide(); 
468  pspa_->faireDessin();
469}
470
471
472void GWt_softwarePanel::fillComboWithElements(Wt::WComboBox* cBox) {
473  if (cBox == NULL) return;
474
475  // get the last item selected
476  WString selectedString = cBox->currentText ();
477  cBox->clear();
478
479  for (int a=0; a< pspa_->getBeamLine()->getBeamLineSize(); a++) {
480    abstractElement* abs = pspa_->getBeamLine()->getAbstractElement(a);
481    if (abs != NULL){
482      cBox->addItem(abs->getLabel());
483    }
484  }
485 
486  for (int a=0; a<cBox->count(); a++) {
487    if (cBox->itemText (a) == selectedString) {
488      cBox->setCurrentIndex(a);
489    }
490  }
491  cBox->refresh();
492}
493
494
495void GWt_softwarePanel::fillComboWithSoftwares(Wt::WComboBox* cBox) {
496  if (cBox == NULL) return;
497  cBox->clear();
498
499  unsigned nb = nomDeLogiciel::getNumberOfSoftwares();
500  unsigned k;
501  for(k = 0; k < nb; k++) {
502    cBox->addItem(nomDeLogiciel(k).getString());
503  }
504  cBox->refresh();
505}
506
507
508Wt::WContainerWidget* GWt_softwarePanel::createAddDeletePushButtons(int sectionNumber) {
509
510  WContainerWidget* buttonContainer= new WContainerWidget();
511 
512  Wt::WHBoxLayout* buttonContainerLayout = new Wt::WHBoxLayout();
513  buttonContainerLayout->setContentsMargins(0,0,0,0);
514  // preparation du bouton add
515  WPushButton* exec_add = new WPushButton("+");
516  exec_add->clicked().connect(this, &GWt_softwarePanel::addSectionToExecuteW);
517  exec_add->setStyleClass("roundButton");
518  exec_add->setMaximumSize(20,20);
519  exec_add->setToolTip("Add new section");
520 
521  // preparation du bouton delete
522  WPushButton* exec_delete = new WPushButton("-");
523  //  warningsContainer_->setStyleClass("warningsContainer");
524
525  exec_delete->clicked().connect(boost::bind(&GWt_softwarePanel::deleteSectionToExecuteW, this, sectionNumber));
526  exec_delete->setStyleClass("roundButton");
527  exec_delete->setMaximumSize(20,20);
528  exec_delete->setToolTip("Remove this section");
529
530  buttonContainerLayout->addWidget(exec_add);
531  buttonContainerLayout->addWidget(exec_delete);
532
533  buttonContainer->setLayout(buttonContainerLayout);
534
535  return buttonContainer;
536}
Note: See TracBrowser for help on using the repository browser.