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

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

Changement de la couleur des sections selectionnes + plein dautres choses

File size: 12.6 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
114void 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
206void GWt_softwarePanel::updateSectionSelection()
207{
208  if ( selectedSections_.empty() ) return;
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;
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;
253        }
254     
255      // preparation de la ligne suivante
256      current = numeroFin +1;
257      currentString = dtmanage_->getLabelFromElementNumero(current);
258    }
259  exec_go_->setDisabled(false);
260
261}
262
263
264bool GWt_softwarePanel::areDataCoherent()
265{
266    bool caMarche = true;
267    dtmanage_->initializeExecution();
268    string diagnostic;
269   
270    list<GWt_sectionToExecute*>::iterator itr;
271    for(itr = selectedSections_.begin(); itr != selectedSections_.end(); itr++)
272    {
273        string debString = (*itr)->debut->text().toUTF8();
274        string finString = (*itr)->fin->text().toUTF8();
275       
276        int debut = dtmanage_->getNumeroFromElementLabel(debString);
277        int fin = dtmanage_->getNumeroFromElementLabel(finString);
278        nomDeLogiciel prog = nomDeLogiciel ( (*itr)->selection->currentIndex() );
279        dtmanage_->addSectionToExecute(debut,fin,prog);
280       
281        // check sections
282        for (int i=debut-1; i<fin; i++) {
283            if (pspa_->getBeamLine()) {
284                if (pspa_->getBeamLine()->getAbstractElement(i)) {
285                    if (!pspa_->getBeamLine()->getAbstractElement(i)->setSoftware(prog.getString())) {
286                        diagnostic += pspa_->getBeamLine()->getAbstractElement(i)->getLabel()+ "could not be associate with "+ prog.getString()+" ";
287                        caMarche = false;
288                    } else {
289                        pspa_->getBeamLine()->update(i);
290                    }
291                }
292            }
293        }
294    }
295   
296//    trivaluedBool essai = dtmanage_->checkExecute(diagnostic);
297
298    if ( caMarche == false ) {
299        GWt_dialog calculDialog("PSPA check execute : ERROR", diagnostic , GWt_dialog::Error,true,true);
300        calculDialog.exec();
301/*
302 } else if ( essai == warning )  {
303        GWt_dialog calculDialog("PSPA check execute : warning ", diagnostic , GWt_dialog::Warning, false,true);
304        calculDialog.exec();
305*/
306    }
307   
308    return caMarche;
309}
310
311void GWt_softwarePanel::deleteSectionToExecuteW()
312{
313  if ( selectedSections_.empty() ) return;
314  disableSectionExecute();
315  selectedSections_.back()->ligneDeWidget->clear();
316  delete selectedSections_.back()->ligneDeWidget;
317  selectedSections_.pop_back();
318}
319
320
321void GWt_softwarePanel::updateSelections()
322{
323  string premierText, dernierText;
324  if ( selectedSections_.size() > 0 )
325    {
326      premierText = dtmanage_->getLabelFromElementNumero(1);
327      dernierText = dtmanage_->getLabelFromElementNumero( dtmanage_->getBeamLineSize() );
328      (*selectedSections_.begin())->debut->setText(premierText);
329      (*selectedSections_.begin())->fin->setText(dernierText);
330    }
331 
332  cout << "PspaApplication::updateSelections(): " << premierText << " à  " << dernierText << endl;
333}
334
335
336string GWt_softwarePanel::getSelection()
337{
338  list<GWt_sectionToExecute*>::iterator itr = selectedSections_.begin();
339  string str = (*itr)->fin->text().toUTF8();
340  return str;
341}
342
343
344void GWt_softwarePanel::executer()
345{
346    if (!areDataCoherent()) {
347      //    GWt_dialog warningDialog("PSPA : verification des sections", " donnees incoherentes !", GWt_dialog::Error,true,true);
348      //    warningDialog.exec();
349    exec_go_->setDisabled(true);
350    return;
351    }
352
353  GWt_console* console = NULL;
354  if (static_cast<GWt_console*> (wApp->findWidget ("console"))) {
355    console = static_cast<GWt_console*> (wApp->findWidget ("console"));
356    console->addConsoleMessage(string("on va peut etre y arriver"));
357  }
358 
359  static_cast<GWt_globalParameters*>(pspa_->getGlobalParam())->updateGlobals();
360 
361  GWt_dialog calculDialog("Calcul en cours", "Veuillez patienter...", GWt_dialog::Wait, true,false);
362  calculDialog.show();
363   
364  wApp->processEvents();
365 
366  if (!dtmanage_->executeAll()) {
367    GWt_dialog warningDialog("PSPA : Echec", " echec lors de l'exÈcution !", GWt_dialog::Error, true,true);
368    warningDialog.exec();
369  }
370     
371  exec_go_->setDisabled(true);
372  calculDialog.hide(); 
373  pspa_->faireDessin();
374}
Note: See TracBrowser for help on using the repository browser.