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

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

debut des modifications pour le comboBox : changement de sectionToExecute

File size: 13.3 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
15#include "GWt_softwarePanel.h"
16#include "GWt_dialog.h"
17#include "GWt_console.h"
18#include "GWt_globalParameters.h"
19
20
21GWt_softwarePanel::GWt_softwarePanel(dataManager* dataManager,PspaApplication* pspa)
22  : WContainerWidget() 
23{
24  dtmanage_ = dataManager;
25  pspa_ = pspa;
26  setMaximumSize(600,150);
27  setMinimumSize(600,150);
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  // preparation du bouton add
36  WPushButton* exec_add = new WPushButton("add");
37  exec_add->clicked().connect(this, &GWt_softwarePanel::addSectionToExecuteW);
38   
39  // preparation du bouton delete
40  WPushButton* exec_delete = new WPushButton("delete");
41  exec_delete->clicked().connect(this, &GWt_softwarePanel::deleteSectionToExecuteW);
42   
43  // preparation du bouton push_ok
44  //  WPushButton* exec_ok = new WPushButton("ok");
45  //  exec_ok->clicked().connect(this, &GWt_softwarePanel::updateSectionSelection);
46 
47  // le panel
48  WPanel *panelLogiciels = new WPanel(this);
49  panelLogiciels->setTitle(" sections of beam Line for executing softwares ");
50 
51  contenuSections_ = new WContainerWidget();
52  contenuSections_->addWidget(exec_add);
53  contenuSections_->addWidget(exec_delete);
54  //  contenuSections_->addWidget(exec_ok);
55  contenuSections_->addWidget(exec_go_);
56  contenuSections_->addWidget(new WBreak());
57  contenuSections_->addWidget(new WBreak());
58  addSectionToExecuteW();
59 
60  panelLogiciels->setCentralWidget(contenuSections_);
61}
62
63GWt_softwarePanel::~GWt_softwarePanel() {
64}
65
66void GWt_softwarePanel::addSectionToExecuteW()
67{   
68  //  disableSectionExecute();
69 
70  string premierText, dernierText;
71  if(selectedSections_.size() == 0) {
72    premierText = dtmanage_->getLabelFromElementNumero(1); 
73    dernierText = dtmanage_->getLabelFromElementNumero(dtmanage_->getBeamLineSize());
74  } else {
75    dernierText = selectedSections_.back()->fin->text().toUTF8();
76    int dernierNumero = dtmanage_->getNumeroFromElementLabel(dernierText);
77    dernierNumero++;
78    if ( dernierNumero <= dtmanage_->getBeamLineSize() ) {
79      premierText = dtmanage_->getLabelFromElementNumero(dernierNumero);
80    } else {
81      premierText = dtmanage_->getLabelFromElementNumero(dtmanage_->getBeamLineSize());
82    }
83    dernierText = premierText;
84  }
85 
86  //  cout << "PspaApplication::addSectionToExecute() : " << premierText << " à  " << dernierText << endl;
87 
88  WContainerWidget* newSection = new WContainerWidget;
89   
90  selectedSections_.push_back(new GWt_sectionToExecute);
91  selectedSections_.back()->debut = new WLineEdit();
92  selectedSections_.back()->debut->setDisabled(true);
93  selectedSections_.back()->debut->setText(premierText);
94  selectedSections_.back()->fin = new WLineEdit();
95  //  selectedSections_.back()->fin->changed().connect(this,&GWt_softwarePanel::disableSectionExecute);
96  selectedSections_.back()->fin->setText(dernierText);
97  selectedSections_.back()->selection = new WComboBox();
98  selectedSections_.back()->ligneDeWidget = newSection;
99  newSection->addWidget(new WText(" from : "));
100  newSection->addWidget(selectedSections_.back()->debut);
101  newSection->addWidget(new WText(" to : "));
102  newSection->addWidget(selectedSections_.back()->fin);
103  newSection->addWidget(selectedSections_.back()->selection);
104 
105  contenuSections_->addWidget(newSection);
106  unsigned nb = nomDeLogiciel::getNumberOfSoftwares();
107  unsigned k;
108  for(k = 0; k < nb; k++) {
109    selectedSections_.back()->selection->addItem(nomDeLogiciel(k).getString());
110  }
111}
112
113
114// void GWt_softwarePanel::disableSectionExecute()
115// {
116//   exec_go_->setDisabled(true);
117// }
118
119
120// void GWt_softwarePanel::checkSectionSelection()
121// {
122//   if ( selectedSections_.empty() ) return;
123 
124//   // traitement de la premiere ligne
125//   // on impose le depart du calcul au premier element
126//   string premier = dtmanage_->getLabelFromElementNumero(1);
127//   (*selectedSections_.begin())->debut->setText(premier);
128 
129//   string currentString =  (*selectedSections_.begin())->fin->text().toUTF8();
130//   int current = dtmanage_->getNumeroFromElementLabel(currentString);
131   
132//   // si la fin est mal definie on prend toute la config par defaut
133//   if ( current <= 0 || current > dtmanage_->getBeamLineSize() )
134//     {
135//       current = dtmanage_->getBeamLineSize();
136//       currentString =  dtmanage_->getLabelFromElementNumero(current);
137//       (*selectedSections_.begin())->fin->setText(currentString);
138//     }
139//   current++;
140//   currentString = dtmanage_->getLabelFromElementNumero(current);
141 
142//   // traitement des suivantes (on avance d'un cran dans la liste)
143//   list<GWt_sectionToExecute*>::iterator itr, itr0;
144//   itr0 = selectedSections_.begin();
145//   itr0++;
146//   for (itr = itr0; itr != selectedSections_.end(); itr++)
147//     {
148//       // debut
149//       if ( current > dtmanage_->getBeamLineSize() )
150//         {
151//        GWt_dialog warningDialog("PSPA :: verification des sections", " bad section definition !", GWt_dialog::Error,true,true);
152//        warningDialog.exec();
153//        return;
154//         }
155     
156//       (*itr)->debut->setText(currentString);
157//       // fin
158//       string finString =  (*itr)->fin->text().toUTF8();
159     
160//       int numeroFin = dtmanage_->getNumeroFromElementLabel( finString);
161     
162//       if ( numeroFin < current || numeroFin > dtmanage_->getBeamLineSize())
163//         {
164//        GWt_dialog warningDialog("PSPA : Checking of sections", " bad section definition !", GWt_dialog::Error, true,true);
165//        warningDialog.exec();
166//        return;
167//         }
168     
169//       // preparation de la ligne suivante
170//       current = numeroFin +1;
171//       currentString = dtmanage_->getLabelFromElementNumero(current);
172//     }
173 
174//   if (!areDataCoherent()) {
175//     GWt_dialog warningDialog("PSPA : verification des sections", " donnees incoherentes !", GWt_dialog::Error,true,true);
176//     warningDialog.exec();
177//   }
178//   else
179//     {
180//       exec_go_->setDisabled(false);
181       
182//         // All ok, then put colors on beamLine
183//         list<GWt_sectionToExecute*>::iterator itr2;
184//         for(itr2 = selectedSections_.begin();itr2 != selectedSections_.end(); itr2++)
185//         {
186//             string debString = (*itr2)->debut->text().toUTF8();
187//             string finString = (*itr2)->fin->text().toUTF8();
188           
189           
190//             int debut = dtmanage_->getNumeroFromElementLabel(debString);
191//             int fin = dtmanage_->getNumeroFromElementLabel(finString);
192// /**
193//  for (int i=debut; i=<fin; i++) {
194//                 getBeamLine()->getAbstractElement(i)->setBGColor(
195               
196//             }
197//             nomDeLogiciel prog = nomDeLogiciel ( (*itr)->selection->currentIndex() );
198//             dtmanage_->addSectionToExecute(debut,fin,prog);
199// */
200//         }
201//     }
202   
203
204// }
205
206bool GWt_softwarePanel::updateSectionSelection()
207{
208  if ( selectedSections_.empty() ) return false;
209 
210  // traitement de la premiere ligne
211  // on impose le depart du calcul au premier element
212  string premier = dtmanage_->getLabelFromElementNumero(1);
213  (*selectedSections_.begin())->debut->setText(premier);
214 
215  string currentString =  (*selectedSections_.begin())->fin->text().toUTF8();
216  int current = dtmanage_->getNumeroFromElementLabel(currentString);
217   
218  // si la fin est mal definie on prend toute la config par defaut
219  if ( current <= 0 || current > dtmanage_->getBeamLineSize() )
220    {
221      current = dtmanage_->getBeamLineSize();
222      currentString =  dtmanage_->getLabelFromElementNumero(current);
223      (*selectedSections_.begin())->fin->setText(currentString);
224    }
225  current++;
226  currentString = dtmanage_->getLabelFromElementNumero(current);
227 
228  // traitement des suivantes (on avance d'un cran dans la liste)
229  list<GWt_sectionToExecute*>::iterator itr, itr0;
230  itr0 = selectedSections_.begin();
231  itr0++;
232  for (itr = itr0; itr != selectedSections_.end(); itr++)
233    {
234      // debut
235      if ( current > dtmanage_->getBeamLineSize() )
236        {
237          GWt_dialog warningDialog("PSPA :: verification des sections", " bad section definition !", GWt_dialog::Error,true,true);
238          warningDialog.exec();
239          return false;
240        }
241     
242      (*itr)->debut->setText(currentString);
243      // fin
244      string finString =  (*itr)->fin->text().toUTF8();
245     
246      int numeroFin = dtmanage_->getNumeroFromElementLabel( finString);
247     
248      if ( numeroFin < current || numeroFin > dtmanage_->getBeamLineSize())
249        {
250          GWt_dialog warningDialog("PSPA : Checking of sections", " bad section definition !", GWt_dialog::Error, true,true);
251          warningDialog.exec();
252          return false;
253        }
254     
255      // preparation de la ligne suivante
256      current = numeroFin +1;
257      currentString = dtmanage_->getLabelFromElementNumero(current);
258    }
259  //  exec_go_->setDisabled(false);
260  return true;
261}
262
263
264bool GWt_softwarePanel::areDataCoherent()
265{
266  bool caMarche = true;
267  trivaluedBool tbResume = TBoolOk;
268  dtmanage_->initializeExecution();
269  string diagnostic;
270   
271  list<GWt_sectionToExecute*>::iterator itr;
272  for(itr = selectedSections_.begin(); itr != selectedSections_.end(); itr++)
273    {
274      string debString = (*itr)->debut->text().toUTF8();
275      string finString = (*itr)->fin->text().toUTF8();
276     
277      int debut = pspa_->getBeamLine()->getAbstractElementIndexFromLabel(debString)+1; // FIXME : Should NOT be +1
278        int fin = pspa_->getBeamLine()->getAbstractElementIndexFromLabel(finString)+1; // FIXME : Should NOT be +1
279
280      nomDeLogiciel prog = nomDeLogiciel ( (*itr)->selection->currentIndex() );
281      dtmanage_->addSectionToExecute(pspa_->getBeamLine()->getAbstractElement(debut),
282                                     debut,
283                                     pspa_->getBeamLine()->getAbstractElement(fin),
284                                     fin,
285                                     dtmanage_->createSoftwareConnexion(prog));
286       
287      // check sections
288      for (int i=debut-1; i<fin; i++) {
289        if (pspa_->getBeamLine()) {
290          if (pspa_->getBeamLine()->getAbstractElement(i)) {
291            trivaluedBool tb = pspa_->getBeamLine()->getAbstractElement(i)->setSoftware(prog.getString());
292            if (tb  == TBoolError ) {
293              diagnostic += pspa_->getBeamLine()->getAbstractElement(i)->getNomdElement().getElementName() + " is not allowed with "+ prog.getString()+"\n ";
294              caMarche = false;
295              tbResume = tb;
296            } else if ( tb == TBoolIgnore ) {
297              diagnostic += pspa_->getBeamLine()->getAbstractElement(i)->getNomdElement().getElementName() + " will be ignored by  "+ prog.getString()+"\n ";
298              if ( tbResume != TBoolError ) tbResume = tb;
299            } else {
300              pspa_->getBeamLine()->update(i);
301            }
302          }
303        }
304      }
305    }
306
307  if ( tbResume == TBoolError ) {
308    GWt_dialog calculDialog("PSPA check execute : ERROR", diagnostic , GWt_dialog::Error,true,true);
309    calculDialog.exec();
310  } else if (tbResume == TBoolIgnore ) {
311    GWt_dialog calculDialog("PSPA check execute : WARNING", diagnostic , GWt_dialog::Warning,false,true);
312    calculDialog.exec();
313  }
314
315  /*
316    } else if ( essai == warning )  {
317    GWt_dialog calculDialog("PSPA check execute : warning ", diagnostic , GWt_dialog::Warning, false,true);
318    calculDialog.exec();
319  */
320   
321  return caMarche;
322}
323
324void GWt_softwarePanel::deleteSectionToExecuteW()
325{
326  if ( selectedSections_.empty() ) return;
327  //  disableSectionExecute();
328  selectedSections_.back()->ligneDeWidget->clear();
329  delete selectedSections_.back()->ligneDeWidget;
330  selectedSections_.pop_back();
331}
332
333
334void GWt_softwarePanel::updateSelections()
335{
336  string premierText, dernierText;
337  if ( selectedSections_.size() > 0 )
338    {
339      premierText = dtmanage_->getLabelFromElementNumero(1);
340      dernierText = dtmanage_->getLabelFromElementNumero( dtmanage_->getBeamLineSize() );
341      (*selectedSections_.begin())->debut->setText(premierText);
342      (*selectedSections_.begin())->fin->setText(dernierText);
343    }
344}
345
346
347string GWt_softwarePanel::getSelection()
348{
349  list<GWt_sectionToExecute*>::iterator itr = selectedSections_.begin();
350  string str = (*itr)->fin->text().toUTF8();
351  return str;
352}
353
354
355void GWt_softwarePanel::executer()
356{
357
358  if ( !updateSectionSelection() ) return;
359
360
361    if (!areDataCoherent()) {
362      //    GWt_dialog warningDialog("PSPA : verification des sections", " donnees incoherentes !", GWt_dialog::Error,true,true);
363      //    warningDialog.exec();
364      //    exec_go_->setDisabled(true);
365    return;
366    }
367
368  GWt_console* console = NULL;
369  if (static_cast<GWt_console*> (wApp->findWidget ("console"))) {
370    console = static_cast<GWt_console*> (wApp->findWidget ("console"));
371    console->addConsoleMessage(string("on va peut etre y arriver"));
372  }
373 
374  static_cast<GWt_globalParameters*>(pspa_->getGlobalParam())->updateGlobals();
375 
376  GWt_dialog calculDialog("Calcul en cours", "Veuillez patienter...", GWt_dialog::Wait, true,false);
377  calculDialog.show();
378   
379  wApp->processEvents();
380 
381  if (!dtmanage_->executeAll()) {
382    GWt_dialog warningDialog("PSPA : Echec", " echec lors de l'exÈcution !", GWt_dialog::Error, true,true);
383    warningDialog.exec();
384  }
385     
386  //  exec_go_->setDisabled(true);
387  calculDialog.hide(); 
388  pspa_->faireDessin();
389}
Note: See TracBrowser for help on using the repository browser.