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("check/ok"); |
---|
46 | exec_ok->clicked().connect(this, &GWt_softwarePanel::checkSectionSelection); |
---|
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 | |
---|
65 | GWt_softwarePanel::~GWt_softwarePanel() { |
---|
66 | } |
---|
67 | |
---|
68 | |
---|
69 | void GWt_softwarePanel::addSectionToExecuteW() |
---|
70 | { |
---|
71 | |
---|
72 | disableSectionExecute(); |
---|
73 | |
---|
74 | string premierText, dernierText; |
---|
75 | if(selectedSections_.size() == 0) |
---|
76 | { |
---|
77 | premierText = dtmanage_->getLabelFromElementNumero(1); |
---|
78 | |
---|
79 | dernierText = dtmanage_->getLabelFromElementNumero(dtmanage_->getBeamLineSize()); |
---|
80 | } |
---|
81 | else |
---|
82 | { |
---|
83 | dernierText = selectedSections_.back()->fin->text().toUTF8(); |
---|
84 | int dernierNumero = dtmanage_->getNumeroFromElementLabel(dernierText); |
---|
85 | dernierNumero++; |
---|
86 | if ( dernierNumero <= dtmanage_->getBeamLineSize() ) |
---|
87 | { |
---|
88 | premierText = dtmanage_->getLabelFromElementNumero(dernierNumero); |
---|
89 | } |
---|
90 | else |
---|
91 | { |
---|
92 | premierText = dtmanage_->getLabelFromElementNumero(dtmanage_->getBeamLineSize()); |
---|
93 | } |
---|
94 | dernierText = premierText; |
---|
95 | } |
---|
96 | |
---|
97 | // cout << "PspaApplication::addSectionToExecute() : " << premierText << " ââ " << dernierText << endl; |
---|
98 | |
---|
99 | WContainerWidget* newSection = new WContainerWidget; |
---|
100 | |
---|
101 | selectedSections_.push_back(new GWt_sectionToExecute); |
---|
102 | selectedSections_.back()->debut = new WLineEdit(); |
---|
103 | selectedSections_.back()->debut->setDisabled(true); |
---|
104 | selectedSections_.back()->debut->setText(premierText); |
---|
105 | selectedSections_.back()->fin = new WLineEdit(); |
---|
106 | selectedSections_.back()->fin->changed().connect(this,&GWt_softwarePanel::disableSectionExecute); |
---|
107 | selectedSections_.back()->fin->setText(dernierText); |
---|
108 | selectedSections_.back()->selection = new WComboBox(); |
---|
109 | selectedSections_.back()->ligneDeWidget = newSection; |
---|
110 | newSection->addWidget(new WText(" from : ")); |
---|
111 | newSection->addWidget(selectedSections_.back()->debut); |
---|
112 | newSection->addWidget(new WText(" to : ")); |
---|
113 | newSection->addWidget(selectedSections_.back()->fin); |
---|
114 | newSection->addWidget(selectedSections_.back()->selection); |
---|
115 | |
---|
116 | contenuSections_->addWidget(newSection); |
---|
117 | unsigned nb = nomDeLogiciel::getNumberOfSoftwares(); |
---|
118 | unsigned k; |
---|
119 | for(k = 0; k < nb; k++) { |
---|
120 | selectedSections_.back()->selection->addItem(nomDeLogiciel(k).getString()); |
---|
121 | } |
---|
122 | } |
---|
123 | |
---|
124 | |
---|
125 | void GWt_softwarePanel::disableSectionExecute() |
---|
126 | { |
---|
127 | exec_go_->setDisabled(true); |
---|
128 | } |
---|
129 | |
---|
130 | |
---|
131 | void GWt_softwarePanel::checkSectionSelection() |
---|
132 | { |
---|
133 | if ( selectedSections_.empty() ) return; |
---|
134 | |
---|
135 | // traitement de la premiere ligne |
---|
136 | // on impose le depart du calcul au premier element |
---|
137 | string premier = dtmanage_->getLabelFromElementNumero(1); |
---|
138 | (*selectedSections_.begin())->debut->setText(premier); |
---|
139 | |
---|
140 | string currentString = (*selectedSections_.begin())->fin->text().toUTF8(); |
---|
141 | int current = dtmanage_->getNumeroFromElementLabel( currentString); |
---|
142 | |
---|
143 | cout << " numero " << current << endl; |
---|
144 | // si la fin est mal definie on prend toute la config par defaut |
---|
145 | if ( current <= 0 || current > dtmanage_->getBeamLineSize() ) |
---|
146 | { |
---|
147 | current = dtmanage_->getBeamLineSize(); |
---|
148 | currentString = dtmanage_->getLabelFromElementNumero(current); |
---|
149 | (*selectedSections_.begin())->fin->setText(currentString); |
---|
150 | } |
---|
151 | current++; |
---|
152 | currentString = dtmanage_->getLabelFromElementNumero(current); |
---|
153 | |
---|
154 | // traitement des suivantes (on avance d'un cran dans la liste) |
---|
155 | list<GWt_sectionToExecute*>::iterator itr, itr0; |
---|
156 | itr0 = selectedSections_.begin(); |
---|
157 | itr0++; |
---|
158 | for (itr = itr0; itr != selectedSections_.end(); itr++) |
---|
159 | { |
---|
160 | // debut |
---|
161 | if ( current >= dtmanage_->getBeamLineSize() ) |
---|
162 | { |
---|
163 | // GWt_tools::addConsoleMessage(" bad section definition ! \n "); |
---|
164 | GWt_dialog warningDialog("PSPA : VÃrification des sections", " bad section definition !", GWt_dialog::Error,true,true); |
---|
165 | warningDialog.exec(); |
---|
166 | return; |
---|
167 | } |
---|
168 | |
---|
169 | (*itr)->debut->setText(currentString); |
---|
170 | // fin |
---|
171 | string finString = (*itr)->fin->text().toUTF8(); |
---|
172 | |
---|
173 | int numeroFin = dtmanage_->getNumeroFromElementLabel( finString); |
---|
174 | |
---|
175 | if ( numeroFin <= current || numeroFin > dtmanage_->getBeamLineSize()) |
---|
176 | { |
---|
177 | // GWt_tools::addConsoleMessage(" bad section definition ! \n "); |
---|
178 | GWt_dialog warningDialog("PSPA : VÃrification des sections", " bad section definition !", GWt_dialog::Error, true,true); |
---|
179 | warningDialog.exec(); |
---|
180 | return; |
---|
181 | } |
---|
182 | |
---|
183 | // preparation de la ligne suivante |
---|
184 | current = numeroFin +1; |
---|
185 | currentString = dtmanage_->getLabelFromElementNumero(current); |
---|
186 | } |
---|
187 | |
---|
188 | if (!areDataCoherent()) { |
---|
189 | GWt_dialog warningDialog("PSPA : VÃrification des sections", " donnees incoherentes !", GWt_dialog::Error,true,true); |
---|
190 | warningDialog.exec(); |
---|
191 | } |
---|
192 | else |
---|
193 | { |
---|
194 | exec_go_->setDisabled(false); |
---|
195 | } |
---|
196 | } |
---|
197 | |
---|
198 | |
---|
199 | bool GWt_softwarePanel::areDataCoherent() |
---|
200 | { |
---|
201 | bool caMarche = true; |
---|
202 | dtmanage_->initializeExecution(); |
---|
203 | |
---|
204 | list<GWt_sectionToExecute*>::iterator itr; |
---|
205 | for(itr = selectedSections_.begin(); itr != selectedSections_.end(); itr++) |
---|
206 | { |
---|
207 | string debString = (*itr)->debut->text().toUTF8(); |
---|
208 | string finString = (*itr)->fin->text().toUTF8(); |
---|
209 | |
---|
210 | |
---|
211 | int debut = dtmanage_->getNumeroFromElementLabel(debString); |
---|
212 | int fin = dtmanage_->getNumeroFromElementLabel(finString); |
---|
213 | nomDeLogiciel prog = nomDeLogiciel ( (*itr)->selection->currentIndex() ); |
---|
214 | dtmanage_->addSectionToExecute(debut,fin,prog); |
---|
215 | } |
---|
216 | |
---|
217 | string diagnostic; |
---|
218 | trivaluedBool essai = dtmanage_->checkExecute(diagnostic); |
---|
219 | cout << " retour verif , essai = " << essai << endl; |
---|
220 | if ( essai == error ) { |
---|
221 | cout << " appli : erreur " << endl; |
---|
222 | caMarche = false; |
---|
223 | GWt_dialog calculDialog("PSPA check execute : ERROR", diagnostic , GWt_dialog::Error,true,true); |
---|
224 | calculDialog.exec(); |
---|
225 | } else if ( essai == warning ) { |
---|
226 | cout << " appli : warnig " << endl; |
---|
227 | caMarche = true; |
---|
228 | GWt_dialog calculDialog("PSPA check execute : warning ", diagnostic , GWt_dialog::Warning, false,true); |
---|
229 | calculDialog.exec(); |
---|
230 | } |
---|
231 | |
---|
232 | return caMarche; |
---|
233 | } |
---|
234 | |
---|
235 | |
---|
236 | void GWt_softwarePanel::deleteSectionToExecuteW() |
---|
237 | { |
---|
238 | if ( selectedSections_.empty() ) return; |
---|
239 | disableSectionExecute(); |
---|
240 | selectedSections_.back()->ligneDeWidget->clear(); |
---|
241 | delete selectedSections_.back()->ligneDeWidget; |
---|
242 | selectedSections_.pop_back(); |
---|
243 | } |
---|
244 | |
---|
245 | |
---|
246 | void GWt_softwarePanel::updateSelections() |
---|
247 | { |
---|
248 | string premierText, dernierText; |
---|
249 | if ( selectedSections_.size() > 0 ) |
---|
250 | { |
---|
251 | premierText = dtmanage_->getLabelFromElementNumero(1); |
---|
252 | dernierText = dtmanage_->getLabelFromElementNumero( dtmanage_->getBeamLineSize() ); |
---|
253 | (*selectedSections_.begin())->debut->setText(premierText); |
---|
254 | (*selectedSections_.begin())->fin->setText(dernierText); |
---|
255 | } |
---|
256 | |
---|
257 | cout << "PspaApplication::updateSelections(): " << premierText << " ââ " << dernierText << endl; |
---|
258 | } |
---|
259 | |
---|
260 | |
---|
261 | string GWt_softwarePanel::getSelection() |
---|
262 | { |
---|
263 | list<GWt_sectionToExecute*>::iterator itr = selectedSections_.begin(); |
---|
264 | string str = (*itr)->fin->text().toUTF8(); |
---|
265 | return str; |
---|
266 | } |
---|
267 | |
---|
268 | |
---|
269 | void GWt_softwarePanel::executer() |
---|
270 | { |
---|
271 | GWt_console* console = NULL; |
---|
272 | if ( static_cast<GWt_console*> (wApp->findWidget ("console"))) { |
---|
273 | GWt_console* console = static_cast<GWt_console*> (wApp->findWidget ("console")); |
---|
274 | console->addConsoleMessage(string("on va peut etre y arriver")); |
---|
275 | } |
---|
276 | |
---|
277 | |
---|
278 | static_cast<GWt_globalParameters*>(pspa_->getGlobalParam())->updateGlobals(); |
---|
279 | |
---|
280 | GWt_dialog calculDialog("Calcul en cours", "Veuillez patienter...", GWt_dialog::Wait, true,false); |
---|
281 | calculDialog.show(); |
---|
282 | |
---|
283 | wApp->processEvents(); |
---|
284 | |
---|
285 | string resultat; |
---|
286 | if ( !dtmanage_->executeAll(resultat)) { |
---|
287 | GWt_dialog warningDialog("PSPA : Echec", " echec lors de l'exÃcution !", GWt_dialog::Error, true,true); |
---|
288 | warningDialog.exec(); |
---|
289 | } |
---|
290 | // cout << " PspaApplication : retour d'execution resultat = " << resultat << endl; |
---|
291 | if (console) { |
---|
292 | console->addConsoleMessage(resultat); |
---|
293 | } |
---|
294 | // cout << " PspaApplication : affichage console termine " << endl; |
---|
295 | |
---|
296 | exec_go_->setDisabled(true); |
---|
297 | |
---|
298 | calculDialog.hide(); |
---|
299 | |
---|
300 | pspa_->faireDessin(); |
---|
301 | } |
---|
302 | |
---|
303 | |
---|