source: PSPA/Interface_Web/branches/12_03_12-managerComboBox/pspaWT/sources/userInterface/src/GWt_softwarePanel.cc @ 399

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

Mise en place des comboBox et changement de l'aspect visuel

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