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 | #include "GWt_sectionToExecute.h" |
---|
20 | |
---|
21 | |
---|
22 | GWt_softwarePanel::GWt_softwarePanel(dataManager* dataManager,PspaApplication* pspa) |
---|
23 | : WContainerWidget() |
---|
24 | { |
---|
25 | dtmanage_ = dataManager; |
---|
26 | pspa_ = pspa; |
---|
27 | setMaximumSize(600,150); |
---|
28 | setMinimumSize(600,150); |
---|
29 | |
---|
30 | // bouton execute |
---|
31 | exec_go_ = new WPushButton("execute!"); |
---|
32 | // exec_go_->setMinimumSize(300,300); |
---|
33 | // exec_go_->setDisabled(true); |
---|
34 | exec_go_->clicked().connect(this, &GWt_softwarePanel::executer); |
---|
35 | |
---|
36 | // preparation du bouton add |
---|
37 | WPushButton* exec_add = new WPushButton("add"); |
---|
38 | exec_add->clicked().connect(this, &GWt_softwarePanel::addSectionToExecuteW); |
---|
39 | |
---|
40 | // preparation du bouton delete |
---|
41 | WPushButton* exec_delete = new WPushButton("delete"); |
---|
42 | exec_delete->clicked().connect(this, &GWt_softwarePanel::deleteSectionToExecuteW); |
---|
43 | |
---|
44 | // preparation du bouton push_ok |
---|
45 | // WPushButton* exec_ok = new WPushButton("ok"); |
---|
46 | // exec_ok->clicked().connect(this, &GWt_softwarePanel::updateSectionSelection); |
---|
47 | |
---|
48 | // le panel |
---|
49 | WPanel *panelLogiciels = new WPanel(this); |
---|
50 | panelLogiciels->setTitle(" sections of beam Line for executing softwares "); |
---|
51 | |
---|
52 | contenuSections_ = new WContainerWidget(); |
---|
53 | contenuSections_->addWidget(exec_add); |
---|
54 | contenuSections_->addWidget(exec_delete); |
---|
55 | // contenuSections_->addWidget(exec_ok); |
---|
56 | contenuSections_->addWidget(exec_go_); |
---|
57 | contenuSections_->addWidget(new WBreak()); |
---|
58 | contenuSections_->addWidget(new WBreak()); |
---|
59 | addSectionToExecuteW(); |
---|
60 | |
---|
61 | panelLogiciels->setCentralWidget(contenuSections_); |
---|
62 | } |
---|
63 | |
---|
64 | GWt_softwarePanel::~GWt_softwarePanel() { |
---|
65 | } |
---|
66 | |
---|
67 | void GWt_softwarePanel::addSectionToExecuteW() |
---|
68 | { |
---|
69 | |
---|
70 | abstractElement* premierElement; |
---|
71 | abstractElement* dernierElement; |
---|
72 | |
---|
73 | int premierIndex = 0; |
---|
74 | int dernierIndex = 0; |
---|
75 | |
---|
76 | // if this is the first section |
---|
77 | if(dtmanage_->getJobListSize() == 0) { |
---|
78 | premierElement = pspa_->getBeamLine()->getAbstractElement(0); |
---|
79 | dernierElement = pspa_->getBeamLine()->getAbstractElement(pspa_->getBeamLine()->getBeamLineSize()-1); |
---|
80 | premierIndex = 0; |
---|
81 | dernierIndex = pspa_->getBeamLine()->getBeamLineSize()-1; |
---|
82 | |
---|
83 | // if this is not the first : |
---|
84 | // - first element will be the last of the previous section |
---|
85 | // (or the same if it is the last of the beam line) |
---|
86 | // - lastElement will be the last of the beam line |
---|
87 | // - software will be the first of the list |
---|
88 | |
---|
89 | } else { |
---|
90 | int indexOfLastElementOfLastSection = dtmanage_->getJobListAt(dtmanage_->getJobListSize()-1)->getLastElementNumberInSection(); |
---|
91 | if (pspa_->getBeamLine()->getAbstractElement(indexOfLastElementOfLastSection+1) != NULL ) { |
---|
92 | premierIndex = indexOfLastElementOfLastSection+1; |
---|
93 | premierElement = pspa_->getBeamLine()->getAbstractElement(indexOfLastElementOfLastSection+1); |
---|
94 | } else { |
---|
95 | premierIndex = indexOfLastElementOfLastSection; |
---|
96 | premierElement = pspa_->getBeamLine()->getAbstractElement(indexOfLastElementOfLastSection); |
---|
97 | |
---|
98 | } |
---|
99 | dernierIndex = dtmanage_->getJobListSize()-1; |
---|
100 | dernierElement = pspa_->getBeamLine()->getAbstractElement(pspa_->getBeamLine()->getBeamLineSize()-1); |
---|
101 | } |
---|
102 | |
---|
103 | // cout << "PspaApplication::addSectionToExecute() : " << premierText << " ââ " << dernierText << endl; |
---|
104 | |
---|
105 | |
---|
106 | abstractSoftware* soft = NULL; |
---|
107 | dtmanage_->addSectionToExecute(premierElement,premierIndex, dernierElement, dernierIndex, soft); |
---|
108 | |
---|
109 | std::string premierElementLabel = ""; |
---|
110 | std::string dernierElementLabel = ""; |
---|
111 | if (premierElement) { |
---|
112 | premierElementLabel = premierElement->getLabel(); |
---|
113 | } |
---|
114 | |
---|
115 | if (dernierElement) { |
---|
116 | dernierElementLabel = dernierElement->getLabel(); |
---|
117 | } |
---|
118 | |
---|
119 | WLineEdit* lineFrom = new WLineEdit(premierElementLabel); |
---|
120 | WLineEdit* lineTo = new WLineEdit(dernierElementLabel); |
---|
121 | |
---|
122 | WComboBox* lineFromCombo = new WComboBox(); |
---|
123 | WComboBox* lineToCombo = new WComboBox(); |
---|
124 | fillComboWithElements(lineFromCombo); |
---|
125 | fillComboWithElements(lineToCombo); |
---|
126 | |
---|
127 | WComboBox* softCombo = new WComboBox(); |
---|
128 | fillComboWithSoftwares(softCombo); |
---|
129 | |
---|
130 | GWt_sectionToExecute* newSectionOld = new GWt_sectionToExecute(lineFrom, lineTo, softCombo); |
---|
131 | GWt_sectionToExecute* newSection = new GWt_sectionToExecute(lineFromCombo, lineToCombo, softCombo); |
---|
132 | |
---|
133 | // push back on sections vector |
---|
134 | sections.push_back(newSectionOld); |
---|
135 | sections.push_back(newSection); |
---|
136 | |
---|
137 | // push back on User interface |
---|
138 | contenuSections_->addWidget(newSectionOld); |
---|
139 | contenuSections_->addWidget(newSection); |
---|
140 | |
---|
141 | |
---|
142 | |
---|
143 | } |
---|
144 | |
---|
145 | |
---|
146 | // void GWt_softwarePanel::disableSectionExecute() |
---|
147 | // { |
---|
148 | // exec_go_->setDisabled(true); |
---|
149 | // } |
---|
150 | |
---|
151 | |
---|
152 | // void GWt_softwarePanel::checkSectionSelection() |
---|
153 | // { |
---|
154 | // if ( selectedSections_.empty() ) return; |
---|
155 | |
---|
156 | // // traitement de la premiere ligne |
---|
157 | // // on impose le depart du calcul au premier element |
---|
158 | // string premier = dtmanage_->getLabelFromElementNumero(1); |
---|
159 | // (*selectedSections_.begin())->debut->setText(premier); |
---|
160 | |
---|
161 | // string currentString = (*selectedSections_.begin())->fin->text().toUTF8(); |
---|
162 | // int current = dtmanage_->getNumeroFromElementLabel(currentString); |
---|
163 | |
---|
164 | // // si la fin est mal definie on prend toute la config par defaut |
---|
165 | // if ( current <= 0 || current > dtmanage_->getBeamLineSize() ) |
---|
166 | // { |
---|
167 | // current = dtmanage_->getBeamLineSize(); |
---|
168 | // currentString = dtmanage_->getLabelFromElementNumero(current); |
---|
169 | // (*selectedSections_.begin())->fin->setText(currentString); |
---|
170 | // } |
---|
171 | // current++; |
---|
172 | // currentString = dtmanage_->getLabelFromElementNumero(current); |
---|
173 | |
---|
174 | // // traitement des suivantes (on avance d'un cran dans la liste) |
---|
175 | // list<GWt_sectionToExecute*>::iterator itr, itr0; |
---|
176 | // itr0 = selectedSections_.begin(); |
---|
177 | // itr0++; |
---|
178 | // for (itr = itr0; itr != selectedSections_.end(); itr++) |
---|
179 | // { |
---|
180 | // // debut |
---|
181 | // if ( current > dtmanage_->getBeamLineSize() ) |
---|
182 | // { |
---|
183 | // GWt_dialog warningDialog("PSPA :: verification des sections", " bad section definition !", GWt_dialog::Error,true,true); |
---|
184 | // warningDialog.exec(); |
---|
185 | // return; |
---|
186 | // } |
---|
187 | |
---|
188 | // (*itr)->debut->setText(currentString); |
---|
189 | // // fin |
---|
190 | // string finString = (*itr)->fin->text().toUTF8(); |
---|
191 | |
---|
192 | // int numeroFin = dtmanage_->getNumeroFromElementLabel( finString); |
---|
193 | |
---|
194 | // if ( numeroFin < current || numeroFin > dtmanage_->getBeamLineSize()) |
---|
195 | // { |
---|
196 | // GWt_dialog warningDialog("PSPA : Checking of sections", " bad section definition !", GWt_dialog::Error, true,true); |
---|
197 | // warningDialog.exec(); |
---|
198 | // return; |
---|
199 | // } |
---|
200 | |
---|
201 | // // preparation de la ligne suivante |
---|
202 | // current = numeroFin +1; |
---|
203 | // currentString = dtmanage_->getLabelFromElementNumero(current); |
---|
204 | // } |
---|
205 | |
---|
206 | // if (!areDataCoherent()) { |
---|
207 | // GWt_dialog warningDialog("PSPA : verification des sections", " donnees incoherentes !", GWt_dialog::Error,true,true); |
---|
208 | // warningDialog.exec(); |
---|
209 | // } |
---|
210 | // else |
---|
211 | // { |
---|
212 | // exec_go_->setDisabled(false); |
---|
213 | |
---|
214 | // // All ok, then put colors on beamLine |
---|
215 | // list<GWt_sectionToExecute*>::iterator itr2; |
---|
216 | // for(itr2 = selectedSections_.begin();itr2 != selectedSections_.end(); itr2++) |
---|
217 | // { |
---|
218 | // string debString = (*itr2)->debut->text().toUTF8(); |
---|
219 | // string finString = (*itr2)->fin->text().toUTF8(); |
---|
220 | |
---|
221 | |
---|
222 | // int debut = dtmanage_->getNumeroFromElementLabel(debString); |
---|
223 | // int fin = dtmanage_->getNumeroFromElementLabel(finString); |
---|
224 | // /** |
---|
225 | // for (int i=debut; i=<fin; i++) { |
---|
226 | // getBeamLine()->getAbstractElement(i)->setBGColor( |
---|
227 | |
---|
228 | // } |
---|
229 | // nomDeLogiciel prog = nomDeLogiciel ( (*itr)->selection->currentIndex() ); |
---|
230 | // dtmanage_->addSectionToExecute(debut,fin,prog); |
---|
231 | // */ |
---|
232 | // } |
---|
233 | // } |
---|
234 | |
---|
235 | |
---|
236 | // } |
---|
237 | |
---|
238 | bool GWt_softwarePanel::updateSectionSelection() |
---|
239 | { |
---|
240 | if ( dtmanage_->getJobListSize() == 0 ) return false; |
---|
241 | |
---|
242 | // traitement de la premiere ligne |
---|
243 | // on impose le depart du calcul au premier element |
---|
244 | string premier = dtmanage_->getLabelFromElementNumero(1); |
---|
245 | if (sections.size() > 0) { |
---|
246 | sections[0]->setFirstElementLineEditCurrentText(premier); |
---|
247 | //... |
---|
248 | } |
---|
249 | |
---|
250 | Wt::WString currentString = sections[0]->getLastElementLineEditCurrentText(); |
---|
251 | int current = dtmanage_->getNumeroFromElementLabel(currentString.toUTF8()); |
---|
252 | |
---|
253 | // si la fin est mal definie on prend toute la config par defaut |
---|
254 | if ( current <= 0 || current > dtmanage_->getBeamLineSize() ) |
---|
255 | { |
---|
256 | current = dtmanage_->getBeamLineSize(); |
---|
257 | currentString = dtmanage_->getLabelFromElementNumero(current); |
---|
258 | if (sections.size() > 0) { |
---|
259 | sections[0]->setLastElementLineEditCurrentText(currentString); |
---|
260 | //... |
---|
261 | } |
---|
262 | } |
---|
263 | current++; |
---|
264 | currentString = dtmanage_->getLabelFromElementNumero(current); |
---|
265 | |
---|
266 | // traitement des suivantes (on avance d'un cran dans la liste) |
---|
267 | for (int a = 1; a< sections.size(); a++) |
---|
268 | { |
---|
269 | // debut |
---|
270 | if ( current > dtmanage_->getBeamLineSize() ) |
---|
271 | { |
---|
272 | GWt_dialog warningDialog("PSPA :: verification des sections", " bad section definition !", GWt_dialog::Error,true,true); |
---|
273 | warningDialog.exec(); |
---|
274 | return false; |
---|
275 | } |
---|
276 | |
---|
277 | sections[a]->setFirstElementLineEditCurrentText(currentString); |
---|
278 | //... |
---|
279 | // fin |
---|
280 | string finString = sections[a]->getLastElementLineEditCurrentText().toUTF8(); |
---|
281 | |
---|
282 | int numeroFin = dtmanage_->getNumeroFromElementLabel( finString); |
---|
283 | |
---|
284 | if ( numeroFin < current || numeroFin > dtmanage_->getBeamLineSize()) |
---|
285 | { |
---|
286 | GWt_dialog warningDialog("PSPA : Checking of sections", " bad section definition !", GWt_dialog::Error, true,true); |
---|
287 | warningDialog.exec(); |
---|
288 | return false; |
---|
289 | } |
---|
290 | |
---|
291 | // preparation de la ligne suivante |
---|
292 | current = numeroFin +1; |
---|
293 | currentString = dtmanage_->getLabelFromElementNumero(current); |
---|
294 | } |
---|
295 | // exec_go_->setDisabled(false); |
---|
296 | return true; |
---|
297 | } |
---|
298 | |
---|
299 | |
---|
300 | bool GWt_softwarePanel::areDataCoherent() |
---|
301 | { |
---|
302 | bool caMarche = true; |
---|
303 | trivaluedBool tbResume = TBoolOk; |
---|
304 | dtmanage_->initializeExecution(); |
---|
305 | string diagnostic; |
---|
306 | |
---|
307 | for (int a = 0; a< sections.size(); a++) |
---|
308 | { |
---|
309 | string debString = sections[a]->getFirstElementLineEditCurrentText().toUTF8(); |
---|
310 | string finString = sections[a]->getLastElementLineEditCurrentText().toUTF8(); |
---|
311 | |
---|
312 | int debut = pspa_->getBeamLine()->getAbstractElementIndexFromLabel(debString)+1; // FIXME : Should NOT be +1 |
---|
313 | int fin = pspa_->getBeamLine()->getAbstractElementIndexFromLabel(finString)+1; // FIXME : Should NOT be +1 |
---|
314 | |
---|
315 | nomDeLogiciel prog = nomDeLogiciel ( sections[a]->getSoftwareCurrentText().toUTF8()); |
---|
316 | dtmanage_->addSectionToExecute(pspa_->getBeamLine()->getAbstractElement(debut), |
---|
317 | debut, |
---|
318 | pspa_->getBeamLine()->getAbstractElement(fin), |
---|
319 | fin, |
---|
320 | dtmanage_->createSoftwareConnexion(prog)); |
---|
321 | |
---|
322 | // check sections |
---|
323 | for (int i=debut-1; i<fin; i++) { |
---|
324 | if (pspa_->getBeamLine()) { |
---|
325 | if (pspa_->getBeamLine()->getAbstractElement(i)) { |
---|
326 | trivaluedBool tb = pspa_->getBeamLine()->getAbstractElement(i)->setSoftware(prog.getString()); |
---|
327 | if (tb == TBoolError ) { |
---|
328 | diagnostic += pspa_->getBeamLine()->getAbstractElement(i)->getNomdElement().getElementName() + " is not allowed with "+ prog.getString()+"\n "; |
---|
329 | caMarche = false; |
---|
330 | tbResume = tb; |
---|
331 | } else if ( tb == TBoolIgnore ) { |
---|
332 | diagnostic += pspa_->getBeamLine()->getAbstractElement(i)->getNomdElement().getElementName() + " will be ignored by "+ prog.getString()+"\n "; |
---|
333 | if ( tbResume != TBoolError ) tbResume = tb; |
---|
334 | } else { |
---|
335 | pspa_->getBeamLine()->update(i); |
---|
336 | } |
---|
337 | } |
---|
338 | } |
---|
339 | } |
---|
340 | } |
---|
341 | |
---|
342 | if ( tbResume == TBoolError ) { |
---|
343 | GWt_dialog calculDialog("PSPA check execute : ERROR", diagnostic , GWt_dialog::Error,true,true); |
---|
344 | calculDialog.exec(); |
---|
345 | } else if (tbResume == TBoolIgnore ) { |
---|
346 | GWt_dialog calculDialog("PSPA check execute : WARNING", diagnostic , GWt_dialog::Warning,false,true); |
---|
347 | calculDialog.exec(); |
---|
348 | } |
---|
349 | |
---|
350 | /* |
---|
351 | } else if ( essai == warning ) { |
---|
352 | GWt_dialog calculDialog("PSPA check execute : warning ", diagnostic , GWt_dialog::Warning, false,true); |
---|
353 | calculDialog.exec(); |
---|
354 | */ |
---|
355 | |
---|
356 | return caMarche; |
---|
357 | } |
---|
358 | |
---|
359 | void GWt_softwarePanel::deleteSectionToExecuteW() |
---|
360 | { |
---|
361 | if ( dtmanage_->getJobListSize() == 0 ) return; |
---|
362 | // delete from dataManager |
---|
363 | dtmanage_->clearSectionToExecute(dtmanage_->getJobListSize()-1); |
---|
364 | |
---|
365 | // delete from User Interface |
---|
366 | sections.pop_back(); |
---|
367 | } |
---|
368 | |
---|
369 | |
---|
370 | void GWt_softwarePanel::updateSections() |
---|
371 | { |
---|
372 | // update all sections in order to manage new/deleted items |
---|
373 | for (int a = 0; a< sections.size(); a++) { |
---|
374 | fillComboWithElements(sections[a]->getFirstElement()); |
---|
375 | fillComboWithElements(sections[a]->getLastElement()); |
---|
376 | } |
---|
377 | |
---|
378 | string premierText, dernierText; |
---|
379 | if ( dtmanage_->getJobListSize() > 0 ) |
---|
380 | { |
---|
381 | premierText = dtmanage_->getLabelFromElementNumero(1); |
---|
382 | dernierText = dtmanage_->getLabelFromElementNumero( dtmanage_->getBeamLineSize() ); |
---|
383 | sections[0]->setFirstElementLineEditCurrentText(premierText); |
---|
384 | sections[0]->setLastElementLineEditCurrentText(dernierText); |
---|
385 | //... |
---|
386 | } |
---|
387 | } |
---|
388 | |
---|
389 | |
---|
390 | |
---|
391 | /* |
---|
392 | string GWt_softwarePanel::getSelection() |
---|
393 | { |
---|
394 | list<GWt_sectionToExecute*>::iterator itr = selectedSections_.begin(); |
---|
395 | string str = (*itr)->fin->text().toUTF8(); |
---|
396 | return str; |
---|
397 | } |
---|
398 | */ |
---|
399 | |
---|
400 | void GWt_softwarePanel::executer() |
---|
401 | { |
---|
402 | |
---|
403 | if ( !updateSectionSelection() ) return; |
---|
404 | |
---|
405 | |
---|
406 | if (!areDataCoherent()) { |
---|
407 | // GWt_dialog warningDialog("PSPA : verification des sections", " donnees incoherentes !", GWt_dialog::Error,true,true); |
---|
408 | // warningDialog.exec(); |
---|
409 | // exec_go_->setDisabled(true); |
---|
410 | return; |
---|
411 | } |
---|
412 | |
---|
413 | GWt_console* console = NULL; |
---|
414 | if (static_cast<GWt_console*> (wApp->findWidget ("console"))) { |
---|
415 | console = static_cast<GWt_console*> (wApp->findWidget ("console")); |
---|
416 | console->addConsoleMessage(string("on va peut etre y arriver")); |
---|
417 | } |
---|
418 | |
---|
419 | static_cast<GWt_globalParameters*>(pspa_->getGlobalParam())->updateGlobals(); |
---|
420 | |
---|
421 | GWt_dialog calculDialog("Calcul en cours", "Veuillez patienter...", GWt_dialog::Wait, true,false); |
---|
422 | calculDialog.show(); |
---|
423 | |
---|
424 | wApp->processEvents(); |
---|
425 | |
---|
426 | if (!dtmanage_->executeAll()) { |
---|
427 | GWt_dialog warningDialog("PSPA : Echec", " echec lors de l'exÃcution !", GWt_dialog::Error, true,true); |
---|
428 | warningDialog.exec(); |
---|
429 | } |
---|
430 | |
---|
431 | // exec_go_->setDisabled(true); |
---|
432 | calculDialog.hide(); |
---|
433 | pspa_->faireDessin(); |
---|
434 | } |
---|
435 | |
---|
436 | |
---|
437 | void GWt_softwarePanel::fillComboWithElements(Wt::WComboBox* cBox) { |
---|
438 | if (cBox == NULL) return; |
---|
439 | cBox->clear(); |
---|
440 | |
---|
441 | for (int a=0; a< pspa_->getBeamLine()->getBeamLineSize(); a++) { |
---|
442 | abstractElement* abs = pspa_->getBeamLine()->getAbstractElement(a); |
---|
443 | if (abs != NULL){ |
---|
444 | cBox->addItem(abs->getLabel()); |
---|
445 | } |
---|
446 | } |
---|
447 | } |
---|
448 | |
---|
449 | |
---|
450 | void GWt_softwarePanel::fillComboWithSoftwares(Wt::WComboBox* cBox) { |
---|
451 | if (cBox == NULL) return; |
---|
452 | cBox->clear(); |
---|
453 | |
---|
454 | unsigned nb = nomDeLogiciel::getNumberOfSoftwares(); |
---|
455 | unsigned k; |
---|
456 | for(k = 0; k < nb; k++) { |
---|
457 | cBox->addItem(nomDeLogiciel(k).getString()); |
---|
458 | } |
---|
459 | |
---|
460 | } |
---|