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

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

Correction de problèmes avec le softwarePanel

File size: 16.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_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,this);
132
133  // push back on sections vector
134  sections_.push_back(newSection);
135
136  Wt::WContainerWidget* container = new Wt::WContainerWidget();
137  Wt::WGridLayout* containerLayout = new Wt::WGridLayout();
138  containerLayout->setContentsMargins(0,0,0,0);
139
140  // push back on User interface
141  containerLayout->addWidget(newSection,0,0);
142 
143  // add buttons
144  containerLayout->addWidget(createAddDeletePushButtons(),0,1);
145
146  container->setLayout(containerLayout);
147 
148  // add to sections
149  contenuSections_->addWidget(container); 
150}
151
152
153// void GWt_softwarePanel::disableSectionExecute()
154// {
155//   exec_go_->setDisabled(true);
156// }
157
158
159// void GWt_softwarePanel::checkSectionSelection()
160// {
161//   if ( selectedSections_.empty() ) return;
162 
163//   // traitement de la premiere ligne
164//   // on impose le depart du calcul au premier element
165//   string premier = dtmanage_->getLabelFromElementNumero(1);
166//   (*selectedSections_.begin())->debut->setText(premier);
167 
168//   string currentString =  (*selectedSections_.begin())->fin->text().toUTF8();
169//   int current = dtmanage_->getNumeroFromElementLabel(currentString);
170   
171//   // si la fin est mal definie on prend toute la config par defaut
172//   if ( current <= 0 || current > dtmanage_->getBeamLineSize() )
173//     {
174//       current = dtmanage_->getBeamLineSize();
175//       currentString =  dtmanage_->getLabelFromElementNumero(current);
176//       (*selectedSections_.begin())->fin->setText(currentString);
177//     }
178//   current++;
179//   currentString = dtmanage_->getLabelFromElementNumero(current);
180 
181//   // traitement des suivantes (on avance d'un cran dans la liste)
182//   list<GWt_sectionToExecute*>::iterator itr, itr0;
183//   itr0 = selectedSections_.begin();
184//   itr0++;
185//   for (itr = itr0; itr != selectedSections_.end(); itr++)
186//     {
187//       // debut
188//       if ( current > dtmanage_->getBeamLineSize() )
189//         {
190//        GWt_dialog warningDialog("PSPA :: verification des sections", " bad section definition !", GWt_dialog::Error,true,true);
191//        warningDialog.exec();
192//        return;
193//         }
194     
195//       (*itr)->debut->setText(currentString);
196//       // fin
197//       string finString =  (*itr)->fin->text().toUTF8();
198     
199//       int numeroFin = dtmanage_->getNumeroFromElementLabel( finString);
200     
201//       if ( numeroFin < current || numeroFin > dtmanage_->getBeamLineSize())
202//         {
203//        GWt_dialog warningDialog("PSPA : Checking of sections", " bad section definition !", GWt_dialog::Error, true,true);
204//        warningDialog.exec();
205//        return;
206//         }
207     
208//       // preparation de la ligne suivante
209//       current = numeroFin +1;
210//       currentString = dtmanage_->getLabelFromElementNumero(current);
211//     }
212 
213//   if (!areDataCoherent()) {
214//     GWt_dialog warningDialog("PSPA : verification des sections", " donnees incoherentes !", GWt_dialog::Error,true,true);
215//     warningDialog.exec();
216//   }
217//   else
218//     {
219//       exec_go_->setDisabled(false);
220       
221//         // All ok, then put colors on beamLine
222//         list<GWt_sectionToExecute*>::iterator itr2;
223//         for(itr2 = selectedSections_.begin();itr2 != selectedSections_.end(); itr2++)
224//         {
225//             string debString = (*itr2)->debut->text().toUTF8();
226//             string finString = (*itr2)->fin->text().toUTF8();
227           
228           
229//             int debut = dtmanage_->getNumeroFromElementLabel(debString);
230//             int fin = dtmanage_->getNumeroFromElementLabel(finString);
231// /**
232//  for (int i=debut; i=<fin; i++) {
233//                 getBeamLine()->getAbstractElement(i)->setBGColor(
234               
235//             }
236//             nomDeLogiciel prog = nomDeLogiciel ( (*itr)->selection->currentIndex() );
237//             dtmanage_->addSectionToExecute(debut,fin,prog);
238// */
239//         }
240//     }
241   
242
243// }
244
245bool GWt_softwarePanel::updateSectionSelection()
246{
247  if ( dtmanage_->getJobListSize() == 0 ) return false;
248 
249  // traitement de la premiere ligne
250  // on impose le depart du calcul au premier element
251  string premier = dtmanage_->getLabelFromElementNumero(1);
252  if (sections_.size() > 0) {
253    sections_[0]->setFirstElementCurrentSelection(premier);
254  }
255 
256  Wt::WString currentString =  sections_[0]->getLastElementCurrentText();
257  int current = dtmanage_->getNumeroFromElementLabel(currentString.toUTF8());
258 
259  // si la fin est mal definie on prend toute la config par defaut
260  if ( current <= 0 || current > dtmanage_->getBeamLineSize() )
261  {
262    current = dtmanage_->getBeamLineSize();
263    currentString =  dtmanage_->getLabelFromElementNumero(current);
264    if (sections_.size() > 0) {
265      sections_[0]->setLastElementCurrentSelection(currentString);
266//...
267    }
268  }
269  current++;
270  currentString = dtmanage_->getLabelFromElementNumero(current);
271 
272  // traitement des suivantes (on avance d'un cran dans la liste)
273  for (int a = 1; a< sections_.size(); a++)
274    {
275      // debut
276      if ( current > dtmanage_->getBeamLineSize() )
277        {
278          GWt_dialog warningDialog("PSPA :: verification des sections", " bad section definition 1 !", GWt_dialog::Error,true,true);
279          warningDialog.exec();
280          return false;
281        }
282     
283      sections_[a]->setFirstElementCurrentSelection(currentString);
284
285      // fin
286      string finString =  sections_[a]->getLastElementCurrentText().toUTF8();
287     
288      int numeroFin = dtmanage_->getNumeroFromElementLabel( finString);
289     
290      if ( numeroFin < current || numeroFin > dtmanage_->getBeamLineSize())
291        {
292          GWt_dialog warningDialog("PSPA : Checking of sections", " bad section definition 2 !", GWt_dialog::Error, true,true);
293          warningDialog.exec();
294          return false;
295        }
296     
297      // preparation de la ligne suivante
298      current = numeroFin +1;
299      currentString = dtmanage_->getLabelFromElementNumero(current);
300    }
301  //  exec_go_->setDisabled(false);
302
303  if (!areDataCoherent()) {
304    exec_go_->disable();
305  } else {
306    exec_go_->enable();
307  }
308
309  return true;
310}
311
312
313bool GWt_softwarePanel::areDataCoherent()
314{
315  bool caMarche = true;
316
317  // initialize dataManager
318  dtmanage_->initializeExecution();
319 
320  // intialize User Interface
321  if (pspa_->getBeamLine()) {
322    pspa_->getBeamLine()->initializeSoftwares();
323  }
324 
325  string diagnosticErrors;
326  string diagnosticWarnings;
327 
328  for (int a = 0; a< sections_.size(); a++)
329  {
330    string debString = sections_[a]->getFirstElementCurrentText().toUTF8();
331    string finString = sections_[a]->getLastElementCurrentText().toUTF8();
332   
333    int debut = pspa_->getBeamLine()->getAbstractElementIndexFromLabel(debString)+1; // FIXME : Should NOT be +1
334    int fin = pspa_->getBeamLine()->getAbstractElementIndexFromLabel(finString)+1; // FIXME : Should NOT be +1
335   
336    nomDeLogiciel prog = nomDeLogiciel ( sections_[a]->getSoftwareCurrentText().toUTF8());
337    dtmanage_->addSectionToExecute(pspa_->getBeamLine()->getAbstractElement(debut),
338                                   debut,
339                                   pspa_->getBeamLine()->getAbstractElement(fin),
340                                   fin,
341                                   dtmanage_->createSoftwareConnexion(prog));
342   
343    diagnosticErrors = "";
344    diagnosticWarnings = "";
345
346    // check sections
347    for (int i=debut-1; i<fin; i++) {
348      if (pspa_->getBeamLine()) {
349        if (pspa_->getBeamLine()->getAbstractElement(i)) {
350          trivaluedBool tb = pspa_->getBeamLine()->getAbstractElement(i)->setSoftware(prog.getString());
351          if (tb  == TBoolError ) {
352            diagnosticErrors += pspa_->getBeamLine()->getAbstractElement(i)->getLabel() + " is not allowed with "+ prog.getString()+"<br /> ";
353
354            caMarche = false;
355
356            // intialize thissoftware
357            pspa_->getBeamLine()->getAbstractElement(i)->setSoftware(nomDeLogiciel::unknownSoftware);
358
359          } else if ( tb == TBoolIgnore ) {
360            diagnosticWarnings += pspa_->getBeamLine()->getAbstractElement(i)->getLabel() + " will be ignored by  "+ prog.getString()+"<br /> ";
361           
362
363          }
364          pspa_->getBeamLine()->update(i);
365        }
366      }
367    }
368    // set errors and warnings
369    sections_[a]->setErrors(diagnosticErrors);
370    sections_[a]->setWarnings(diagnosticWarnings);
371  }
372   
373  return caMarche;
374}
375
376void GWt_softwarePanel::deleteSectionToExecuteW()
377{
378/*  if ( dtmanage_->getJobListSize() == 0 ) return;
379  // delete from dataManager
380  dtmanage_->clearSectionToExecute(dtmanage_->getJobListSize()-1);
381
382  // delete from User Interface
383  sections_.pop_back();
384*/
385}
386
387
388void GWt_softwarePanel::updateSections()
389{
390  // update all sections in order to manage new/deleted items
391  for (int a = 0; a< sections_.size(); a++) {
392    fillComboWithElements(sections_[a]->getFirstElement());
393    fillComboWithElements(sections_[a]->getLastElement());
394
395    sections_[a]->getFirstElement()->setEnabled (true);
396    sections_[a]->getLastElement()->setEnabled (true);
397  }
398  if (sections_.size() == 0) {
399    return;
400  }
401  // the first element will always be the first element of the beamLine
402  sections_[0]->getFirstElement()->setCurrentIndex(0);
403  sections_[0]->getFirstElement()->setEnabled (false);
404
405  // the last element will always be the last element of the beamLine
406  sections_[sections_.size()-1]->getLastElement()->setCurrentIndex(sections_[sections_.size()-1]->getLastElement()->count());
407  sections_[sections_.size()-1]->getLastElement()->setEnabled (false);
408
409  // set default values
410
411  // update
412  updateSectionSelection();
413}
414
415
416
417/*
418 string GWt_softwarePanel::getSelection()
419{
420  list<GWt_sectionToExecute*>::iterator itr = selectedSections_.begin();
421  string str = (*itr)->fin->text().toUTF8();
422  return str;
423}
424*/
425
426void GWt_softwarePanel::executer()
427{
428
429  if (!areDataCoherent()) {
430    //    GWt_dialog warningDialog("PSPA : verification des sections", " donnees incoherentes !", GWt_dialog::Error,true,true);
431    //    warningDialog.exec();
432    //    exec_go_->setDisabled(true);
433    return;
434  }
435 
436  // GWt_console* console = NULL;
437  // if (static_cast<GWt_console*> (wApp->findWidget ("console"))) {
438  //   console = static_cast<GWt_console*> (wApp->findWidget ("console"));
439  //   console->addConsoleMessage(string("on va peut etre y arriver"));
440  // }
441 
442  static_cast<GWt_globalParameters*>(pspa_->getGlobalParam())->updateGlobals();
443 
444  GWt_dialog calculDialog("Calcul en cours", "Veuillez patienter...", GWt_dialog::Wait, true,false);
445  calculDialog.show();
446   
447  wApp->processEvents();
448 
449  if (!dtmanage_->executeAll()) {
450    GWt_dialog warningDialog("PSPA : Echec", " echec lors de l'exÈcution !", GWt_dialog::Error, true,true);
451    warningDialog.exec();
452  }
453     
454  //  exec_go_->setDisabled(true);
455  calculDialog.hide(); 
456  pspa_->faireDessin();
457}
458
459
460void GWt_softwarePanel::fillComboWithElements(Wt::WComboBox* cBox) {
461  if (cBox == NULL) return;
462
463  // get the last item selected
464  WString selectedString = cBox->currentText ();
465  cBox->clear();
466
467  for (int a=0; a< pspa_->getBeamLine()->getBeamLineSize(); a++) {
468    abstractElement* abs = pspa_->getBeamLine()->getAbstractElement(a);
469    if (abs != NULL){
470      cBox->addItem(abs->getLabel());
471    }
472  }
473 
474  for (int a=0; a<cBox->count(); a++) {
475    if (cBox->itemText (a) == selectedString) {
476      cBox->setCurrentIndex(a);
477    }
478  }
479  cBox->refresh();
480}
481
482
483void GWt_softwarePanel::fillComboWithSoftwares(Wt::WComboBox* cBox) {
484  if (cBox == NULL) return;
485  cBox->clear();
486
487  unsigned nb = nomDeLogiciel::getNumberOfSoftwares();
488  unsigned k;
489  for(k = 0; k < nb; k++) {
490    cBox->addItem(nomDeLogiciel(k).getString());
491  }
492  cBox->refresh();
493}
494
495
496Wt::WContainerWidget* GWt_softwarePanel::createAddDeletePushButtons() {
497
498  WContainerWidget* buttonContainer= new WContainerWidget();
499 
500  Wt::WHBoxLayout* buttonContainerLayout = new Wt::WHBoxLayout();
501  buttonContainerLayout->setContentsMargins(0,0,0,0);
502  // preparation du bouton add
503  WPushButton* exec_add = new WPushButton("+");
504  exec_add->clicked().connect(this, &GWt_softwarePanel::addSectionToExecuteW);
505  exec_add->setStyleClass("roundButton");
506  exec_add->setMaximumSize(20,20);
507  exec_add->setToolTip("Add new section");
508 
509  // preparation du bouton delete
510  WPushButton* exec_delete = new WPushButton("-");
511  //  warningsContainer_->setStyleClass("warningsContainer");
512  exec_delete->clicked().connect(this, &GWt_softwarePanel::deleteSectionToExecuteW);
513  exec_delete->setStyleClass("roundButton");
514  exec_delete->setMaximumSize(20,20);
515  exec_delete->setToolTip("Remove this section");
516
517  buttonContainerLayout->addWidget(exec_add);
518  buttonContainerLayout->addWidget(exec_delete);
519
520  buttonContainer->setLayout(buttonContainerLayout);
521
522  return buttonContainer;
523}
Note: See TracBrowser for help on using the repository browser.