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

Last change on this file since 371 was 371, checked in by touze, 11 years ago

nvx histos

File size: 13.0 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 = dtmanage_->getNumeroFromElementLabel(debString);
278      int fin = dtmanage_->getNumeroFromElementLabel(finString);
279      nomDeLogiciel prog = nomDeLogiciel ( (*itr)->selection->currentIndex() );
280      dtmanage_->addSectionToExecute(debut,fin,prog);
281       
282      // check sections
283      for (int i=debut-1; i<fin; i++) {
284        if (pspa_->getBeamLine()) {
285          if (pspa_->getBeamLine()->getAbstractElement(i)) {
286            trivaluedBool tb = pspa_->getBeamLine()->getAbstractElement(i)->setSoftware(prog.getString());
287            if (tb  == TBoolError ) {
288              diagnostic += pspa_->getBeamLine()->getAbstractElement(i)->getNomdElement().getElementName() + " is not allowed with "+ prog.getString()+"\n ";
289              caMarche = false;
290              tbResume = tb;
291            } else if ( tb == TBoolIgnore ) {
292              diagnostic += pspa_->getBeamLine()->getAbstractElement(i)->getNomdElement().getElementName() + " will be ignored by  "+ prog.getString()+"\n ";
293              if ( tbResume != TBoolError ) tbResume = tb;
294            } else {
295              pspa_->getBeamLine()->update(i);
296            }
297          }
298        }
299      }
300    }
301
302  if ( tbResume == TBoolError ) {
303    GWt_dialog calculDialog("PSPA check execute : ERROR", diagnostic , GWt_dialog::Error,true,true);
304    calculDialog.exec();
305  } else if (tbResume == TBoolIgnore ) {
306    GWt_dialog calculDialog("PSPA check execute : WARNING", diagnostic , GWt_dialog::Warning,false,true);
307    calculDialog.exec();
308  }
309
310  /*
311    } else if ( essai == warning )  {
312    GWt_dialog calculDialog("PSPA check execute : warning ", diagnostic , GWt_dialog::Warning, false,true);
313    calculDialog.exec();
314  */
315   
316  return caMarche;
317}
318
319void GWt_softwarePanel::deleteSectionToExecuteW()
320{
321  if ( selectedSections_.empty() ) return;
322  //  disableSectionExecute();
323  selectedSections_.back()->ligneDeWidget->clear();
324  delete selectedSections_.back()->ligneDeWidget;
325  selectedSections_.pop_back();
326}
327
328
329void GWt_softwarePanel::updateSelections()
330{
331  string premierText, dernierText;
332  if ( selectedSections_.size() > 0 )
333    {
334      premierText = dtmanage_->getLabelFromElementNumero(1);
335      dernierText = dtmanage_->getLabelFromElementNumero( dtmanage_->getBeamLineSize() );
336      (*selectedSections_.begin())->debut->setText(premierText);
337      (*selectedSections_.begin())->fin->setText(dernierText);
338    }
339 
340  cout << "PspaApplication::updateSelections(): " << premierText << " à  " << dernierText << endl;
341}
342
343
344string GWt_softwarePanel::getSelection()
345{
346  list<GWt_sectionToExecute*>::iterator itr = selectedSections_.begin();
347  string str = (*itr)->fin->text().toUTF8();
348  return str;
349}
350
351
352void GWt_softwarePanel::executer()
353{
354
355  if ( !updateSectionSelection() ) return;
356
357
358    if (!areDataCoherent()) {
359      //    GWt_dialog warningDialog("PSPA : verification des sections", " donnees incoherentes !", GWt_dialog::Error,true,true);
360      //    warningDialog.exec();
361      //    exec_go_->setDisabled(true);
362    return;
363    }
364
365  GWt_console* console = NULL;
366  if (static_cast<GWt_console*> (wApp->findWidget ("console"))) {
367    console = static_cast<GWt_console*> (wApp->findWidget ("console"));
368    console->addConsoleMessage(string("on va peut etre y arriver"));
369  }
370 
371  static_cast<GWt_globalParameters*>(pspa_->getGlobalParam())->updateGlobals();
372 
373  GWt_dialog calculDialog("Calcul en cours", "Veuillez patienter...", GWt_dialog::Wait, true,false);
374  calculDialog.show();
375   
376  wApp->processEvents();
377 
378  if (!dtmanage_->executeAll()) {
379    GWt_dialog warningDialog("PSPA : Echec", " echec lors de l'exÈcution !", GWt_dialog::Error, true,true);
380    warningDialog.exec();
381  }
382     
383  //  exec_go_->setDisabled(true);
384  calculDialog.hide(); 
385  pspa_->faireDessin();
386}
Note: See TracBrowser for help on using the repository browser.