1 | // |
---|
2 | // GWt_softwarePanel.cpp |
---|
3 | // PSPA |
---|
4 | // |
---|
5 | // Created by Garnier Laurent on 30/01/13. |
---|
6 | // Copyright (c) 2013 Garnier Laurent. All rights reserved. |
---|
7 | // |
---|
8 | |
---|
9 | #include <Wt/WLineEdit> |
---|
10 | #include <Wt/WText> |
---|
11 | #include <Wt/WComboBox> |
---|
12 | #include <Wt/WPanel> |
---|
13 | #include <Wt/WBreak> |
---|
14 | #include <Wt/WApplication> |
---|
15 | |
---|
16 | #include "GWt_softwarePanel.h" |
---|
17 | #include "GWt_dialog.h" |
---|
18 | #include "GWt_console.h" |
---|
19 | #include "GWt_globalParameters.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 | disableSectionExecute(); |
---|
70 | |
---|
71 | string premierText, dernierText; |
---|
72 | if(selectedSections_.size() == 0) { |
---|
73 | premierText = dtmanage_->getLabelFromElementNumero(1); |
---|
74 | dernierText = dtmanage_->getLabelFromElementNumero(dtmanage_->getBeamLineSize()); |
---|
75 | } else { |
---|
76 | dernierText = selectedSections_.back()->fin->text().toUTF8(); |
---|
77 | int dernierNumero = dtmanage_->getNumeroFromElementLabel(dernierText); |
---|
78 | dernierNumero++; |
---|
79 | if ( dernierNumero <= dtmanage_->getBeamLineSize() ) { |
---|
80 | premierText = dtmanage_->getLabelFromElementNumero(dernierNumero); |
---|
81 | } else { |
---|
82 | premierText = dtmanage_->getLabelFromElementNumero(dtmanage_->getBeamLineSize()); |
---|
83 | } |
---|
84 | dernierText = premierText; |
---|
85 | } |
---|
86 | |
---|
87 | // cout << "PspaApplication::addSectionToExecute() : " << premierText << " ââ " << dernierText << endl; |
---|
88 | |
---|
89 | WContainerWidget* newSection = new WContainerWidget; |
---|
90 | |
---|
91 | selectedSections_.push_back(new GWt_sectionToExecute); |
---|
92 | selectedSections_.back()->debut = new WLineEdit(); |
---|
93 | selectedSections_.back()->debut->setDisabled(true); |
---|
94 | selectedSections_.back()->debut->setText(premierText); |
---|
95 | selectedSections_.back()->fin = new WLineEdit(); |
---|
96 | selectedSections_.back()->fin->changed().connect(this,&GWt_softwarePanel::disableSectionExecute); |
---|
97 | selectedSections_.back()->fin->setText(dernierText); |
---|
98 | selectedSections_.back()->selection = new WComboBox(); |
---|
99 | selectedSections_.back()->ligneDeWidget = newSection; |
---|
100 | newSection->addWidget(new WText(" from : ")); |
---|
101 | newSection->addWidget(selectedSections_.back()->debut); |
---|
102 | newSection->addWidget(new WText(" to : ")); |
---|
103 | newSection->addWidget(selectedSections_.back()->fin); |
---|
104 | newSection->addWidget(selectedSections_.back()->selection); |
---|
105 | |
---|
106 | contenuSections_->addWidget(newSection); |
---|
107 | unsigned nb = nomDeLogiciel::getNumberOfSoftwares(); |
---|
108 | unsigned k; |
---|
109 | for(k = 0; k < nb; k++) { |
---|
110 | selectedSections_.back()->selection->addItem(nomDeLogiciel(k).getString()); |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|
114 | |
---|
115 | void GWt_softwarePanel::disableSectionExecute() |
---|
116 | { |
---|
117 | exec_go_->setDisabled(true); |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | // void GWt_softwarePanel::checkSectionSelection() |
---|
122 | // { |
---|
123 | // if ( selectedSections_.empty() ) return; |
---|
124 | |
---|
125 | // // traitement de la premiere ligne |
---|
126 | // // on impose le depart du calcul au premier element |
---|
127 | // string premier = dtmanage_->getLabelFromElementNumero(1); |
---|
128 | // (*selectedSections_.begin())->debut->setText(premier); |
---|
129 | |
---|
130 | // string currentString = (*selectedSections_.begin())->fin->text().toUTF8(); |
---|
131 | // int current = dtmanage_->getNumeroFromElementLabel(currentString); |
---|
132 | |
---|
133 | // // si la fin est mal definie on prend toute la config par defaut |
---|
134 | // if ( current <= 0 || current > dtmanage_->getBeamLineSize() ) |
---|
135 | // { |
---|
136 | // current = dtmanage_->getBeamLineSize(); |
---|
137 | // currentString = dtmanage_->getLabelFromElementNumero(current); |
---|
138 | // (*selectedSections_.begin())->fin->setText(currentString); |
---|
139 | // } |
---|
140 | // current++; |
---|
141 | // currentString = dtmanage_->getLabelFromElementNumero(current); |
---|
142 | |
---|
143 | // // traitement des suivantes (on avance d'un cran dans la liste) |
---|
144 | // list<GWt_sectionToExecute*>::iterator itr, itr0; |
---|
145 | // itr0 = selectedSections_.begin(); |
---|
146 | // itr0++; |
---|
147 | // for (itr = itr0; itr != selectedSections_.end(); itr++) |
---|
148 | // { |
---|
149 | // // debut |
---|
150 | // if ( current > dtmanage_->getBeamLineSize() ) |
---|
151 | // { |
---|
152 | // GWt_dialog warningDialog("PSPA :: verification des sections", " bad section definition !", GWt_dialog::Error,true,true); |
---|
153 | // warningDialog.exec(); |
---|
154 | // return; |
---|
155 | // } |
---|
156 | |
---|
157 | // (*itr)->debut->setText(currentString); |
---|
158 | // // fin |
---|
159 | // string finString = (*itr)->fin->text().toUTF8(); |
---|
160 | |
---|
161 | // int numeroFin = dtmanage_->getNumeroFromElementLabel( finString); |
---|
162 | |
---|
163 | // if ( numeroFin < current || numeroFin > dtmanage_->getBeamLineSize()) |
---|
164 | // { |
---|
165 | // GWt_dialog warningDialog("PSPA : Checking of sections", " bad section definition !", GWt_dialog::Error, true,true); |
---|
166 | // warningDialog.exec(); |
---|
167 | // return; |
---|
168 | // } |
---|
169 | |
---|
170 | // // preparation de la ligne suivante |
---|
171 | // current = numeroFin +1; |
---|
172 | // currentString = dtmanage_->getLabelFromElementNumero(current); |
---|
173 | // } |
---|
174 | |
---|
175 | // if (!areDataCoherent()) { |
---|
176 | // GWt_dialog warningDialog("PSPA : verification des sections", " donnees incoherentes !", GWt_dialog::Error,true,true); |
---|
177 | // warningDialog.exec(); |
---|
178 | // } |
---|
179 | // else |
---|
180 | // { |
---|
181 | // exec_go_->setDisabled(false); |
---|
182 | |
---|
183 | // // All ok, then put colors on beamLine |
---|
184 | // list<GWt_sectionToExecute*>::iterator itr2; |
---|
185 | // for(itr2 = selectedSections_.begin();itr2 != selectedSections_.end(); itr2++) |
---|
186 | // { |
---|
187 | // string debString = (*itr2)->debut->text().toUTF8(); |
---|
188 | // string finString = (*itr2)->fin->text().toUTF8(); |
---|
189 | |
---|
190 | |
---|
191 | // int debut = dtmanage_->getNumeroFromElementLabel(debString); |
---|
192 | // int fin = dtmanage_->getNumeroFromElementLabel(finString); |
---|
193 | // /** |
---|
194 | // for (int i=debut; i=<fin; i++) { |
---|
195 | // getBeamLine()->getAbstractElement(i)->setBGColor( |
---|
196 | |
---|
197 | // } |
---|
198 | // nomDeLogiciel prog = nomDeLogiciel ( (*itr)->selection->currentIndex() ); |
---|
199 | // dtmanage_->addSectionToExecute(debut,fin,prog); |
---|
200 | // */ |
---|
201 | // } |
---|
202 | // } |
---|
203 | |
---|
204 | |
---|
205 | // } |
---|
206 | |
---|
207 | void GWt_softwarePanel::updateSectionSelection() |
---|
208 | { |
---|
209 | if ( selectedSections_.empty() ) return; |
---|
210 | |
---|
211 | // traitement de la premiere ligne |
---|
212 | // on impose le depart du calcul au premier element |
---|
213 | string premier = dtmanage_->getLabelFromElementNumero(1); |
---|
214 | (*selectedSections_.begin())->debut->setText(premier); |
---|
215 | |
---|
216 | string currentString = (*selectedSections_.begin())->fin->text().toUTF8(); |
---|
217 | int current = dtmanage_->getNumeroFromElementLabel(currentString); |
---|
218 | |
---|
219 | // si la fin est mal definie on prend toute la config par defaut |
---|
220 | if ( current <= 0 || current > dtmanage_->getBeamLineSize() ) |
---|
221 | { |
---|
222 | current = dtmanage_->getBeamLineSize(); |
---|
223 | currentString = dtmanage_->getLabelFromElementNumero(current); |
---|
224 | (*selectedSections_.begin())->fin->setText(currentString); |
---|
225 | } |
---|
226 | current++; |
---|
227 | currentString = dtmanage_->getLabelFromElementNumero(current); |
---|
228 | |
---|
229 | // traitement des suivantes (on avance d'un cran dans la liste) |
---|
230 | list<GWt_sectionToExecute*>::iterator itr, itr0; |
---|
231 | itr0 = selectedSections_.begin(); |
---|
232 | itr0++; |
---|
233 | for (itr = itr0; itr != selectedSections_.end(); itr++) |
---|
234 | { |
---|
235 | // debut |
---|
236 | if ( current > dtmanage_->getBeamLineSize() ) |
---|
237 | { |
---|
238 | GWt_dialog warningDialog("PSPA :: verification des sections", " bad section definition !", GWt_dialog::Error,true,true); |
---|
239 | warningDialog.exec(); |
---|
240 | return; |
---|
241 | } |
---|
242 | |
---|
243 | (*itr)->debut->setText(currentString); |
---|
244 | // fin |
---|
245 | string finString = (*itr)->fin->text().toUTF8(); |
---|
246 | |
---|
247 | int numeroFin = dtmanage_->getNumeroFromElementLabel( finString); |
---|
248 | |
---|
249 | if ( numeroFin < current || numeroFin > dtmanage_->getBeamLineSize()) |
---|
250 | { |
---|
251 | GWt_dialog warningDialog("PSPA : Checking of sections", " bad section definition !", GWt_dialog::Error, true,true); |
---|
252 | warningDialog.exec(); |
---|
253 | return; |
---|
254 | } |
---|
255 | |
---|
256 | // preparation de la ligne suivante |
---|
257 | current = numeroFin +1; |
---|
258 | currentString = dtmanage_->getLabelFromElementNumero(current); |
---|
259 | } |
---|
260 | exec_go_->setDisabled(false); |
---|
261 | |
---|
262 | |
---|
263 | // All ok, then put colors on beamLine |
---|
264 | list<GWt_sectionToExecute*>::iterator itr2; |
---|
265 | for(itr2 = selectedSections_.begin();itr2 != selectedSections_.end(); itr2++) |
---|
266 | { |
---|
267 | string debString = (*itr2)->debut->text().toUTF8(); |
---|
268 | string finString = (*itr2)->fin->text().toUTF8(); |
---|
269 | |
---|
270 | |
---|
271 | int debut = dtmanage_->getNumeroFromElementLabel(debString); |
---|
272 | int fin = dtmanage_->getNumeroFromElementLabel(finString); |
---|
273 | /** |
---|
274 | for (int i=debut; i=<fin; i++) { |
---|
275 | getBeamLine()->getAbstractElement(i)->setBGColor( |
---|
276 | |
---|
277 | } |
---|
278 | nomDeLogiciel prog = nomDeLogiciel ( (*itr)->selection->currentIndex() ); |
---|
279 | dtmanage_->addSectionToExecute(debut,fin,prog); |
---|
280 | */ |
---|
281 | } |
---|
282 | } |
---|
283 | |
---|
284 | |
---|
285 | bool GWt_softwarePanel::areDataCoherent() |
---|
286 | { |
---|
287 | bool caMarche = true; |
---|
288 | dtmanage_->initializeExecution(); |
---|
289 | |
---|
290 | list<GWt_sectionToExecute*>::iterator itr; |
---|
291 | for(itr = selectedSections_.begin(); itr != selectedSections_.end(); itr++) |
---|
292 | { |
---|
293 | string debString = (*itr)->debut->text().toUTF8(); |
---|
294 | string finString = (*itr)->fin->text().toUTF8(); |
---|
295 | |
---|
296 | int debut = dtmanage_->getNumeroFromElementLabel(debString); |
---|
297 | int fin = dtmanage_->getNumeroFromElementLabel(finString); |
---|
298 | nomDeLogiciel prog = nomDeLogiciel ( (*itr)->selection->currentIndex() ); |
---|
299 | dtmanage_->addSectionToExecute(debut,fin,prog); |
---|
300 | } |
---|
301 | |
---|
302 | string diagnostic; |
---|
303 | trivaluedBool essai = dtmanage_->checkExecute(diagnostic); |
---|
304 | if ( essai == error ) { |
---|
305 | caMarche = false; |
---|
306 | GWt_dialog calculDialog("PSPA check execute : ERROR", diagnostic , GWt_dialog::Error,true,true); |
---|
307 | calculDialog.exec(); |
---|
308 | } else if ( essai == warning ) { |
---|
309 | caMarche = true; |
---|
310 | GWt_dialog calculDialog("PSPA check execute : warning ", diagnostic , GWt_dialog::Warning, false,true); |
---|
311 | calculDialog.exec(); |
---|
312 | } |
---|
313 | |
---|
314 | return caMarche; |
---|
315 | } |
---|
316 | |
---|
317 | void GWt_softwarePanel::deleteSectionToExecuteW() |
---|
318 | { |
---|
319 | if ( selectedSections_.empty() ) return; |
---|
320 | disableSectionExecute(); |
---|
321 | selectedSections_.back()->ligneDeWidget->clear(); |
---|
322 | delete selectedSections_.back()->ligneDeWidget; |
---|
323 | selectedSections_.pop_back(); |
---|
324 | } |
---|
325 | |
---|
326 | |
---|
327 | void GWt_softwarePanel::updateSelections() |
---|
328 | { |
---|
329 | string premierText, dernierText; |
---|
330 | if ( selectedSections_.size() > 0 ) |
---|
331 | { |
---|
332 | premierText = dtmanage_->getLabelFromElementNumero(1); |
---|
333 | dernierText = dtmanage_->getLabelFromElementNumero( dtmanage_->getBeamLineSize() ); |
---|
334 | (*selectedSections_.begin())->debut->setText(premierText); |
---|
335 | (*selectedSections_.begin())->fin->setText(dernierText); |
---|
336 | } |
---|
337 | |
---|
338 | cout << "PspaApplication::updateSelections(): " << premierText << " ââ " << dernierText << endl; |
---|
339 | } |
---|
340 | |
---|
341 | |
---|
342 | string GWt_softwarePanel::getSelection() |
---|
343 | { |
---|
344 | list<GWt_sectionToExecute*>::iterator itr = selectedSections_.begin(); |
---|
345 | string str = (*itr)->fin->text().toUTF8(); |
---|
346 | return str; |
---|
347 | } |
---|
348 | |
---|
349 | |
---|
350 | void GWt_softwarePanel::executer() |
---|
351 | { |
---|
352 | if (!areDataCoherent()) { |
---|
353 | // GWt_dialog warningDialog("PSPA : verification des sections", " donnees incoherentes !", GWt_dialog::Error,true,true); |
---|
354 | // warningDialog.exec(); |
---|
355 | exec_go_->setDisabled(true); |
---|
356 | return; |
---|
357 | } |
---|
358 | |
---|
359 | GWt_console* console = NULL; |
---|
360 | if (static_cast<GWt_console*> (wApp->findWidget ("console"))) { |
---|
361 | console = static_cast<GWt_console*> (wApp->findWidget ("console")); |
---|
362 | console->addConsoleMessage(string("on va peut etre y arriver")); |
---|
363 | } |
---|
364 | |
---|
365 | static_cast<GWt_globalParameters*>(pspa_->getGlobalParam())->updateGlobals(); |
---|
366 | |
---|
367 | GWt_dialog calculDialog("Calcul en cours", "Veuillez patienter...", GWt_dialog::Wait, true,false); |
---|
368 | calculDialog.show(); |
---|
369 | |
---|
370 | wApp->processEvents(); |
---|
371 | |
---|
372 | if (!dtmanage_->executeAll()) { |
---|
373 | GWt_dialog warningDialog("PSPA : Echec", " echec lors de l'exÃcution !", GWt_dialog::Error, true,true); |
---|
374 | warningDialog.exec(); |
---|
375 | } |
---|
376 | |
---|
377 | exec_go_->setDisabled(true); |
---|
378 | calculDialog.hide(); |
---|
379 | pspa_->faireDessin(); |
---|
380 | } |
---|