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