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_sector.h" |
---|
20 | #include "GWt_globalParameters.h" |
---|
21 | #include "GWt_sectionToExecute.h" |
---|
22 | #include "GWt_pspaApplication.h" |
---|
23 | |
---|
24 | #define BAVARD 0 |
---|
25 | |
---|
26 | GWt_softwarePanel::GWt_softwarePanel(dataManager* dataManager,GWt_sector* sect) |
---|
27 | : WContainerWidget(), |
---|
28 | dtmanage_(dataManager), |
---|
29 | UIsector_(sect) |
---|
30 | { |
---|
31 | |
---|
32 | // bouton execute |
---|
33 | exec_go_ = new WPushButton("execute!"); |
---|
34 | exec_go_->clicked().connect(this, &GWt_softwarePanel::executer); |
---|
35 | |
---|
36 | // le panel |
---|
37 | WPanel *panelLogiciels = new WPanel(this); |
---|
38 | panelLogiciels->setTitle(" sections of beam line for executing softwares "); |
---|
39 | |
---|
40 | contenuSections_ = new WContainerWidget(); |
---|
41 | contenuSections_->addWidget(exec_go_); |
---|
42 | contenuSections_->addWidget(new WBreak()); |
---|
43 | contenuSections_->addWidget(new WBreak()); |
---|
44 | addSectionToExecuteW(); |
---|
45 | |
---|
46 | panelLogiciels->setCentralWidget(contenuSections_); |
---|
47 | } |
---|
48 | |
---|
49 | GWt_softwarePanel::~GWt_softwarePanel() { |
---|
50 | } |
---|
51 | |
---|
52 | void GWt_softwarePanel::addSectionToExecuteW() |
---|
53 | { |
---|
54 | cout << "***********************************" << endl; |
---|
55 | cout << "* A réécrire *" << endl; |
---|
56 | cout << "***********************************" << endl; |
---|
57 | return; |
---|
58 | #if BAVARD > 0 |
---|
59 | cout << "***********************************" << endl; |
---|
60 | cout << " GWt_softwarePanel::addSectionToExecuteW() " << endl<<endl; |
---|
61 | #endif |
---|
62 | |
---|
63 | abstractElement* premierElement = NULL; |
---|
64 | abstractElement* dernierElement = NULL; |
---|
65 | |
---|
66 | int premierIndex = 0; |
---|
67 | int dernierIndex = 0; |
---|
68 | |
---|
69 | cout << "sections_.size() = " << sections_.size() << endl; |
---|
70 | /* |
---|
71 | // if there is no section |
---|
72 | if(sections_.size() == 0) { |
---|
73 | premierElement = pspa_->getBeamLine()->getAbstractElement(0); |
---|
74 | premierIndex = 0; |
---|
75 | |
---|
76 | // if this is not the first : |
---|
77 | // - first element will be the last of the previous section |
---|
78 | // (or the same if it is the last of the beam line) |
---|
79 | // - lastElement will be the last of the beam line |
---|
80 | // - software will be the first of the list |
---|
81 | |
---|
82 | } else { |
---|
83 | dernierElement = pspa_->getBeamLine()->getAbstractElement(pspa_->getBeamLine()->getBeamLineSize()-1); |
---|
84 | dernierIndex = pspa_->getBeamLine()->getBeamLineSize()-1; |
---|
85 | |
---|
86 | premierElement = dernierElement; |
---|
87 | premierIndex = dernierIndex; |
---|
88 | } |
---|
89 | |
---|
90 | dernierElement = pspa_->getBeamLine()->getAbstractElement(pspa_->getBeamLine()->getBeamLineSize()-1); |
---|
91 | dernierIndex = pspa_->getBeamLine()->getBeamLineSize()-1; |
---|
92 | |
---|
93 | dtmanage_->addSectionToExecute(premierElement,premierIndex,dernierElement,dernierIndex,nomDeLogiciel()); |
---|
94 | */ |
---|
95 | std::string premierElementLabel = ""; |
---|
96 | std::string dernierElementLabel = ""; |
---|
97 | if (premierElement) { |
---|
98 | premierElementLabel = premierElement->getLabel(); |
---|
99 | } |
---|
100 | if (dernierElement) { |
---|
101 | dernierElementLabel = dernierElement->getLabel(); |
---|
102 | } |
---|
103 | |
---|
104 | WComboBox* lineFromCombo = new WComboBox(); |
---|
105 | WComboBox* lineToCombo = new WComboBox(); |
---|
106 | fillComboWithElements(lineFromCombo); |
---|
107 | fillComboWithElements(lineToCombo); |
---|
108 | |
---|
109 | // set selection |
---|
110 | lineFromCombo->setCurrentIndex(premierIndex); |
---|
111 | lineToCombo->setCurrentIndex(dernierIndex); |
---|
112 | |
---|
113 | WComboBox* softCombo = new WComboBox(); |
---|
114 | fillComboWithSoftwares(softCombo); |
---|
115 | |
---|
116 | GWt_sectionToExecute* newSection = new GWt_sectionToExecute(lineFromCombo,lineToCombo,softCombo,createAddDeletePushButtons(sections_.size()),this,UIsector_); |
---|
117 | |
---|
118 | stringstream st; |
---|
119 | st << sections_.size(); |
---|
120 | |
---|
121 | // this is the mean to identify this section! |
---|
122 | newSection->setObjectName(st.str()); |
---|
123 | |
---|
124 | // push back on sections vector |
---|
125 | sections_.push_back(newSection); |
---|
126 | contenuSections_->addWidget(newSection); |
---|
127 | updateSections(); |
---|
128 | } |
---|
129 | |
---|
130 | void GWt_softwarePanel::updateSections() |
---|
131 | { |
---|
132 | #if BAVARD > 0 |
---|
133 | cout << "***********************************" << endl; |
---|
134 | cout << " GWt_softwarePanel::updateSections() " << endl<<endl; |
---|
135 | #endif |
---|
136 | |
---|
137 | // update all sections in order to manage new/deleted items |
---|
138 | for (int a = 0; a < sections_.size(); a++) { |
---|
139 | fillComboWithElements(sections_[a]->getFirstElement()); |
---|
140 | fillComboWithElements(sections_[a]->getLastElement()); |
---|
141 | sections_[a]->getFirstElement()->setEnabled (true); |
---|
142 | sections_[a]->getLastElement()->setEnabled (true); |
---|
143 | } |
---|
144 | |
---|
145 | if (sections_.size() == 0) { |
---|
146 | return; |
---|
147 | } |
---|
148 | |
---|
149 | // the first element will always be the first element of the beamLine |
---|
150 | sections_[0]->getFirstElement()->setCurrentIndex(0); |
---|
151 | sections_[0]->getFirstElement()->setEnabled (false); |
---|
152 | |
---|
153 | // the last element will always be the last element of the beamLine |
---|
154 | sections_[sections_.size()-1]->getLastElement()->setCurrentIndex(sections_[sections_.size()-1]->getLastElement()->count()); |
---|
155 | sections_[sections_.size()-1]->getLastElement()->setEnabled(false); |
---|
156 | |
---|
157 | // set default values |
---|
158 | updateSectionSelection(); |
---|
159 | } |
---|
160 | |
---|
161 | bool GWt_softwarePanel::updateSectionSelection() |
---|
162 | { |
---|
163 | #if BAVARD > 0 |
---|
164 | cout << "***********************************" << endl; |
---|
165 | cout << " GWt_softwarePanel::updateSectionSelection() " << endl<<endl; |
---|
166 | #endif |
---|
167 | |
---|
168 | if ( dtmanage_->getJobListSize() == 0 ) return false; |
---|
169 | |
---|
170 | // traitement de la premiere ligne |
---|
171 | // on impose le depart du calcul au premier element |
---|
172 | string premier = ""; |
---|
173 | if (UIsector_->getSectorControler()) { |
---|
174 | if (UIsector_->getSectorControler()->getSectionsToExecute().size() > 0) { |
---|
175 | if (UIsector_->getSectorControler()->getSectionsToExecute()[0]->getElements().size() > 0) { |
---|
176 | premier = UIsector_->getSectorControler()->getSectionsToExecute()[0]->getElements()[0]->getLabel(); |
---|
177 | } |
---|
178 | } |
---|
179 | } |
---|
180 | |
---|
181 | // FIXME : A réécrire |
---|
182 | /* |
---|
183 | if (sections_.size() > 0) { |
---|
184 | sections_[0]->setFirstElementCurrentSelection(premier); |
---|
185 | } |
---|
186 | |
---|
187 | Wt::WString currentString = sections_[0]->getLastElementCurrentText(); |
---|
188 | int current = dtmanage_->getNumeroFromElementLabel(currentString.toUTF8()); |
---|
189 | |
---|
190 | // si la fin est mal definie on prend toute la config par defaut |
---|
191 | if ( current <= 0 || current > dtmanage_->getBeamLineSize() ) |
---|
192 | { |
---|
193 | current = dtmanage_->getBeamLineSize(); |
---|
194 | currentString = dtmanage_->getLabelFromElementNumero(current); |
---|
195 | if (sections_.size() > 0) { |
---|
196 | sections_[0]->setLastElementCurrentSelection(currentString); |
---|
197 | //... |
---|
198 | } |
---|
199 | } |
---|
200 | current++; |
---|
201 | currentString = dtmanage_->getLabelFromElementNumero(current); |
---|
202 | |
---|
203 | // traitement des suivantes (on avance d'un cran dans la liste) |
---|
204 | for (int a = 1; a< sections_.size(); a++) |
---|
205 | { |
---|
206 | // debut |
---|
207 | if ( current > dtmanage_->getBeamLineSize() ) |
---|
208 | { |
---|
209 | sections_[a]->setErrors("This section element could not be after previous session last element"); |
---|
210 | exec_go_->disable(); |
---|
211 | return false; |
---|
212 | } |
---|
213 | |
---|
214 | sections_[a]->setFirstElementCurrentSelection(currentString); |
---|
215 | |
---|
216 | // fin |
---|
217 | string finString = sections_[a]->getLastElementCurrentText().toUTF8(); |
---|
218 | |
---|
219 | int numeroFin = dtmanage_->getNumeroFromElementLabel( finString); |
---|
220 | |
---|
221 | if ( numeroFin < current) |
---|
222 | { |
---|
223 | sections_[a]->setErrors("Last section element should be after first section element"); |
---|
224 | exec_go_->disable(); |
---|
225 | return false; |
---|
226 | } |
---|
227 | |
---|
228 | if (numeroFin > dtmanage_->getBeamLineSize()) |
---|
229 | { |
---|
230 | sections_[a]->setErrors("Last section element number is greater than the beam line size"); |
---|
231 | exec_go_->disable(); |
---|
232 | return false; |
---|
233 | } |
---|
234 | |
---|
235 | // preparation de la ligne suivante |
---|
236 | current = numeroFin +1; |
---|
237 | currentString = dtmanage_->getLabelFromElementNumero(current); |
---|
238 | } |
---|
239 | // exec_go_->setDisabled(false); |
---|
240 | |
---|
241 | if (!areDataCoherent()) { |
---|
242 | #if BAVARD > 0 |
---|
243 | cout << " GWt_softwarePanel::addSectionToExecuteW() DISABLE" << endl; |
---|
244 | #endif |
---|
245 | exec_go_->disable(); |
---|
246 | } else { |
---|
247 | #if BAVARD > 0 |
---|
248 | cout << " GWt_softwarePanel::addSectionToExecuteW() ENABLE" << endl; |
---|
249 | #endif |
---|
250 | exec_go_->enable(); |
---|
251 | } |
---|
252 | */ |
---|
253 | return true; |
---|
254 | } |
---|
255 | |
---|
256 | bool GWt_softwarePanel::areDataCoherent() |
---|
257 | { |
---|
258 | // FIXME |
---|
259 | cout << "***********************************" << endl; |
---|
260 | cout << "** To be move in controler **" << endl; |
---|
261 | cout << "***********************************" << endl; |
---|
262 | return true; |
---|
263 | #if BAVARD > 0 |
---|
264 | cout << "***********************************" << endl; |
---|
265 | cout << " GWt_softwarePanel::areDataCoherent() " << endl<<endl; |
---|
266 | #endif |
---|
267 | |
---|
268 | bool caMarche = true; |
---|
269 | /* |
---|
270 | // initialize dataManager |
---|
271 | dtmanage_->initializeExecution(); |
---|
272 | |
---|
273 | // intialize User Interface |
---|
274 | if (pspa_->getBeamLine()) { |
---|
275 | pspa_->getBeamLine()->initializeSoftwares(); |
---|
276 | } |
---|
277 | |
---|
278 | string diagnosticErrors; |
---|
279 | string diagnosticWarnings; |
---|
280 | for (int a = 0; a < sections_.size(); a++) |
---|
281 | { |
---|
282 | string debString= sections_[a]->getFirstElementCurrentText().toUTF8(); |
---|
283 | string finString= sections_[a]->getLastElementCurrentText().toUTF8(); |
---|
284 | int debut = pspa_->getBeamLine()->getAbstractElementNumeroFromLabel(debString); |
---|
285 | int fin = pspa_->getBeamLine()->getAbstractElementNumeroFromLabel(finString); |
---|
286 | |
---|
287 | string currentSoft= sections_[a]->getSoftwareCurrentText().toUTF8(); |
---|
288 | nomDeLogiciel prog = nomDeLogiciel(currentSoft); |
---|
289 | sectionToExecute* sectToExec = dtmanage_->addSectionToExecute(pspa_->getBeamLine()->getAbstractElement(debut),debut,pspa_->getBeamLine()->getAbstractElement(fin),fin,prog); |
---|
290 | |
---|
291 | abstractSoftware* softToExec = sectToExec->getSoftware(); |
---|
292 | diagnosticErrors = ""; |
---|
293 | diagnosticWarnings = ""; |
---|
294 | for(int i = debut-1; i < fin; i++) // check sections |
---|
295 | { |
---|
296 | if (!pspa_->getBeamLine()) continue; |
---|
297 | abstractElement* elPtr= pspa_->getBeamLine()->getAbstractElement(i); |
---|
298 | if (!elPtr) continue; |
---|
299 | |
---|
300 | trivaluedBool tb = softToExec->doAcceptElement(elPtr->getNomdElement().getElementType()); |
---|
301 | cout << " GWt_softwarePanel::areDataCoherent() el " << elPtr->getLabel() << " tb= " << tb << endl; |
---|
302 | if (tb == TBoolOk ) { |
---|
303 | elPtr->setSoftware(softToExec); |
---|
304 | } else { |
---|
305 | elPtr->setSoftware(NULL); |
---|
306 | if (tb == TBoolIgnore) { |
---|
307 | if(prog.getString() != "unknownSoftware") diagnosticWarnings += elPtr->getLabel() + " will be ignored by "+ prog.getString() + "<br /> "; |
---|
308 | } else { |
---|
309 | // j'insiste pour remettre le nom generique de l'element refuse (glm / 30/03/2013) |
---|
310 | diagnosticErrors += elPtr->getNomdElement().getExpandedName() + " is not allowed with " + prog.getString() + "<br /> "; |
---|
311 | caMarche = false; |
---|
312 | } |
---|
313 | } |
---|
314 | pspa_->getBeamLine()->update(i); |
---|
315 | } //i |
---|
316 | |
---|
317 | // set errors and warnings |
---|
318 | sections_[a]->setErrors(diagnosticErrors); |
---|
319 | sections_[a]->setWarnings(diagnosticWarnings); |
---|
320 | }//a |
---|
321 | */ |
---|
322 | return caMarche; |
---|
323 | } |
---|
324 | |
---|
325 | void GWt_softwarePanel::deleteSectionToExecuteW(int sectionLabel) |
---|
326 | { |
---|
327 | #if BAVARD > 0 |
---|
328 | cout << "***********************************" << endl; |
---|
329 | cout << " GWt_softwarePanel::deleteSectionToExecuteW()" << endl<<endl; |
---|
330 | #endif |
---|
331 | |
---|
332 | stringstream st; |
---|
333 | st << sectionLabel; |
---|
334 | std::string sectionName = st.str(); |
---|
335 | |
---|
336 | if ( dtmanage_->getJobListSize() == 0 ) return; |
---|
337 | for (unsigned int sectionIndex = 0; sectionIndex< sections_.size(); sectionIndex++) { |
---|
338 | if (sections_[sectionIndex]->objectName() == sectionName) { |
---|
339 | |
---|
340 | // delete from dataManager |
---|
341 | UIsector_->getSectorControler()->clearSectionToExecute(sectionIndex); |
---|
342 | |
---|
343 | // delete from User Interface |
---|
344 | contenuSections_->removeWidget(sections_[sectionIndex]); |
---|
345 | delete sections_[sectionIndex]; |
---|
346 | sections_.erase (sections_.begin()+sectionIndex); |
---|
347 | } |
---|
348 | } |
---|
349 | } |
---|
350 | |
---|
351 | void GWt_softwarePanel::executer() |
---|
352 | { |
---|
353 | cout << "***********************************" << endl; |
---|
354 | cout << " GWt_softwarePanel::executer() " << endl<<endl; |
---|
355 | |
---|
356 | if (!areDataCoherent()) { |
---|
357 | return; |
---|
358 | } |
---|
359 | |
---|
360 | //static_cast<GWt_globalParameters*>(pspa_->getGlobalParam())->updateGlobals(); |
---|
361 | |
---|
362 | GWt_dialog calculDialog("Calcul en cours", "Veuillez patienter...", GWt_dialog::Wait, true,false); |
---|
363 | calculDialog.show(); |
---|
364 | |
---|
365 | wApp->processEvents(); |
---|
366 | |
---|
367 | if (!dtmanage_->executeAll()) { |
---|
368 | GWt_dialog warningDialog("PSPA : Echec", " echec lors de l'exécution !", GWt_dialog::Error, true,true); |
---|
369 | warningDialog.exec(); |
---|
370 | } |
---|
371 | |
---|
372 | // exec_go_->setDisabled(true); |
---|
373 | calculDialog.hide(); |
---|
374 | UIsector_->getAccelerator()->faireDessin(); |
---|
375 | } |
---|
376 | |
---|
377 | void GWt_softwarePanel::fillComboWithElements(Wt::WComboBox* cBox) |
---|
378 | { |
---|
379 | // FIXME |
---|
380 | cout << "***********************************" << endl; |
---|
381 | cout << "** To be move in controler **" << endl; |
---|
382 | cout << "***********************************" << endl; |
---|
383 | return; |
---|
384 | |
---|
385 | /* if (cBox == NULL) return; |
---|
386 | |
---|
387 | // get the last item selected |
---|
388 | WString selectedString = cBox->currentText(); |
---|
389 | cBox->clear(); |
---|
390 | |
---|
391 | for(int a = 0; a < pspa_->getBeamLine()->getBeamLineSize(); a++) { |
---|
392 | abstractElement* abs = pspa_->getBeamLine()->getAbstractElement(a); |
---|
393 | if (abs != NULL) { |
---|
394 | cBox->addItem(abs->getLabel()); |
---|
395 | } |
---|
396 | } |
---|
397 | |
---|
398 | for(int a = 0; a < cBox->count(); a++) { |
---|
399 | if (cBox->itemText (a) == selectedString) { |
---|
400 | cBox->setCurrentIndex(a); |
---|
401 | } |
---|
402 | } |
---|
403 | cBox->refresh(); |
---|
404 | */ |
---|
405 | } |
---|
406 | |
---|
407 | void GWt_softwarePanel::fillComboWithSoftwares(Wt::WComboBox* cBox) |
---|
408 | { |
---|
409 | #if BAVARD > 0 |
---|
410 | cout << "***********************************" << endl; |
---|
411 | cout << " GWt_softwarePanel::fillComboWithSoftwares " << endl<<endl; |
---|
412 | #endif |
---|
413 | |
---|
414 | if (cBox == NULL) return; |
---|
415 | cBox->clear(); |
---|
416 | |
---|
417 | unsigned nb = nomDeLogiciel::getNumberOfSoftwares(); |
---|
418 | unsigned k; |
---|
419 | for(k = 0; k <= nb; k++) { //xx |
---|
420 | cBox->addItem(nomDeLogiciel(k).getString()); |
---|
421 | } |
---|
422 | cBox->setCurrentIndex(nb); // xx |
---|
423 | cBox->refresh(); |
---|
424 | } |
---|
425 | |
---|
426 | Wt::WContainerWidget* GWt_softwarePanel::createAddDeletePushButtons(int sectionNumber) |
---|
427 | { |
---|
428 | WContainerWidget* buttonContainer= new WContainerWidget(); |
---|
429 | |
---|
430 | Wt::WHBoxLayout* buttonContainerLayout = new Wt::WHBoxLayout(); |
---|
431 | buttonContainerLayout->setContentsMargins(0,0,0,0); |
---|
432 | // preparation du bouton add |
---|
433 | WPushButton* exec_add = new WPushButton("+"); |
---|
434 | exec_add->clicked().connect(this, &GWt_softwarePanel::addSectionToExecuteW); |
---|
435 | exec_add->setStyleClass("roundButton"); |
---|
436 | exec_add->setMaximumSize(20,20); |
---|
437 | exec_add->setToolTip("Add new section"); |
---|
438 | |
---|
439 | // preparation du bouton delete |
---|
440 | WPushButton* exec_delete = new WPushButton("-"); |
---|
441 | // warningsContainer_->setStyleClass("warningsContainer"); |
---|
442 | |
---|
443 | exec_delete->clicked().connect(boost::bind(&GWt_softwarePanel::deleteSectionToExecuteW, this, sectionNumber)); |
---|
444 | exec_delete->setStyleClass("roundButton"); |
---|
445 | exec_delete->setMaximumSize(20,20); |
---|
446 | exec_delete->setToolTip("Remove this section"); |
---|
447 | |
---|
448 | buttonContainerLayout->addWidget(exec_add); |
---|
449 | buttonContainerLayout->addWidget(exec_delete); |
---|
450 | buttonContainer->setLayout(buttonContainerLayout); |
---|
451 | |
---|
452 | return buttonContainer; |
---|
453 | } |
---|