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 | // le panel |
---|
33 | WPanel *panelLogiciels = new WPanel(this); |
---|
34 | panelLogiciels->setTitle(" sections of beam line for executing softwares "); |
---|
35 | |
---|
36 | contenuSections_ = new WContainerWidget(); |
---|
37 | contenuSections_->addWidget(new WBreak()); |
---|
38 | contenuSections_->addWidget(new WBreak()); |
---|
39 | displayFromControler(); |
---|
40 | |
---|
41 | panelLogiciels->setCentralWidget(contenuSections_); |
---|
42 | } |
---|
43 | |
---|
44 | GWt_softwarePanel::~GWt_softwarePanel() { |
---|
45 | } |
---|
46 | |
---|
47 | void GWt_softwarePanel::displayFromControler() |
---|
48 | { |
---|
49 | #if BAVARD > 0 |
---|
50 | cout << "***********************************" << endl; |
---|
51 | cout << " GWt_softwarePanel::addSectionToExecuteW() " << endl<<endl; |
---|
52 | #endif |
---|
53 | |
---|
54 | // Clear all |
---|
55 | contenuSections_->clear(); |
---|
56 | |
---|
57 | // Get all sectionsToExecute from this sector |
---|
58 | if (!UIsector_->getSectorControler()) { |
---|
59 | return; |
---|
60 | } |
---|
61 | |
---|
62 | if (UIsector_->getSectorControler()->getSectionsToExecute().size() == 0) { |
---|
63 | // FIXME : Add a message to tell the user to add first an element |
---|
64 | } else { |
---|
65 | |
---|
66 | unsigned int firstSectionToExecuteIndex = 0; |
---|
67 | for (unsigned int a=0; a<UIsector_->getSectorControler()->getSectionsToExecute().size(); a++) { |
---|
68 | abstractElement* premierElement = NULL; |
---|
69 | abstractElement* dernierElement = NULL; |
---|
70 | |
---|
71 | std::string premierElementLabel = ""; |
---|
72 | std::string dernierElementLabel = ""; |
---|
73 | if (premierElement) { |
---|
74 | premierElementLabel = premierElement->getLabel(); |
---|
75 | } |
---|
76 | if (dernierElement) { |
---|
77 | dernierElementLabel = dernierElement->getLabel(); |
---|
78 | } |
---|
79 | |
---|
80 | WComboBox* lineFromCombo = new WComboBox(); |
---|
81 | WComboBox* lineToCombo = new WComboBox(); |
---|
82 | fillComboWithElements(lineFromCombo); |
---|
83 | fillComboWithElements(lineToCombo); |
---|
84 | |
---|
85 | // set to first |
---|
86 | lineFromCombo->setCurrentIndex(firstSectionToExecuteIndex); |
---|
87 | // set to last |
---|
88 | lineToCombo->setCurrentIndex(firstSectionToExecuteIndex + (unsigned int)UIsector_->getSectorControler()->getSectionsToExecute()[a]->getElements().size() - 1); |
---|
89 | |
---|
90 | WComboBox* softCombo = new WComboBox(); |
---|
91 | sectionToExecute* sect = UIsector_->getSectorControler()->getSectionsToExecute()[a]; |
---|
92 | |
---|
93 | fillComboWithSoftwares(softCombo,UIsector_->getSectorControler()->getSectionsToExecute()[a]->getSoftware()->getName()); |
---|
94 | |
---|
95 | // disable the "to" comboBox |
---|
96 | lineToCombo->disable(); |
---|
97 | |
---|
98 | // disable the first "from" comboBox |
---|
99 | if (a==0) { |
---|
100 | lineFromCombo->disable(); |
---|
101 | } |
---|
102 | // disable the last "to" comboBox |
---|
103 | if (a==UIsector_->getSectorControler()->getSectionsToExecute().size()-1) { |
---|
104 | lineToCombo->disable(); |
---|
105 | } |
---|
106 | |
---|
107 | // Add the sectionToExecute Widget |
---|
108 | GWt_sectionToExecute* newSection = new GWt_sectionToExecute(lineFromCombo,lineToCombo,softCombo,createAddDeletePushButtons(a),UIsector_->getSectorControler()->getSectionsToExecute()[a],UIsector_); |
---|
109 | |
---|
110 | /* // FIXME ? |
---|
111 | stringstream st; |
---|
112 | st << UIsectionsToExecute_deprecated_.size(); |
---|
113 | |
---|
114 | // this is the mean to identify this section! |
---|
115 | newSection->setObjectName(st.str()); |
---|
116 | |
---|
117 | // push back on sections vector |
---|
118 | UIsectionsToExecute_deprecated_.push_back(newSection); |
---|
119 | */ |
---|
120 | contenuSections_->addWidget(newSection); |
---|
121 | // updateSections(); |
---|
122 | |
---|
123 | firstSectionToExecuteIndex += UIsector_->getSectorControler()->getSectionsToExecute()[a]->getElements().size(); |
---|
124 | } |
---|
125 | } |
---|
126 | } |
---|
127 | |
---|
128 | void GWt_softwarePanel::updateSections() |
---|
129 | { |
---|
130 | #if BAVARD > 0 |
---|
131 | cout << "***********************************" << endl; |
---|
132 | cout << " GWt_softwarePanel::updateSections() " << endl<<endl; |
---|
133 | #endif |
---|
134 | |
---|
135 | /* |
---|
136 | // update all sections in order to manage new/deleted items |
---|
137 | for (int a = 0; a < UIsectionsToExecute_deprecated_.size(); a++) { |
---|
138 | fillComboWithElements(UIsectionsToExecute_deprecated_[a]->getFirstElement()); |
---|
139 | fillComboWithElements(UIsectionsToExecute_deprecated_[a]->getLastElement()); |
---|
140 | UIsectionsToExecute_deprecated_[a]->getFirstElement()->setEnabled (true); |
---|
141 | UIsectionsToExecute_deprecated_[a]->getLastElement()->setEnabled (true); |
---|
142 | } |
---|
143 | |
---|
144 | if (UIsectionsToExecute_deprecated_;.size() == 0) { |
---|
145 | return; |
---|
146 | } |
---|
147 | |
---|
148 | // the first element will always be the first element of the beamLine |
---|
149 | UIsectionsToExecute_deprecated_[0]->getFirstElement()->setCurrentIndex(0); |
---|
150 | UIsectionsToExecute_deprecated_[0]->getFirstElement()->setEnabled (false); |
---|
151 | |
---|
152 | // the last element will always be the last element of the beamLine |
---|
153 | UIsectionsToExecute_deprecated_[UIsectionsToExecute_deprecated_.size()-1]->getLastElement()->setCurrentIndex(UIsectionsToExecute_deprecated_[UIsectionsToExecute_deprecated_;.size()-1]->getLastElement()->count()); |
---|
154 | UIsectionsToExecute_deprecated_[UIsectionsToExecute_deprecated_.size()-1]->getLastElement()->setEnabled(false); |
---|
155 | |
---|
156 | // set default values |
---|
157 | updateSectionSelection(); |
---|
158 | */ |
---|
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 (UIsectionsToExecute_deprecated_.size() > 0) { |
---|
184 | UIsectionsToExecute_deprecated_[0]->setFirstElementCurrentSelection(premier); |
---|
185 | } |
---|
186 | |
---|
187 | Wt::WString currentString = UIsectionsToExecute_deprecated_[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 (UIsectionsToExecute_deprecated_.size() > 0) { |
---|
196 | UIsectionsToExecute_deprecated_[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< UIsectionsToExecute_deprecated_;.size(); a++) |
---|
205 | { |
---|
206 | // debut |
---|
207 | if ( current > dtmanage_->getBeamLineSize() ) |
---|
208 | { |
---|
209 | UIsectionsToExecute_deprecated_;[a]->setErrors("This section element could not be after previous session last element"); |
---|
210 | exec_go_->disable(); |
---|
211 | return false; |
---|
212 | } |
---|
213 | |
---|
214 | UIsectionsToExecute_deprecated_;[a]->setFirstElementCurrentSelection(currentString); |
---|
215 | |
---|
216 | // fin |
---|
217 | string finString = UIsectionsToExecute_deprecated_;[a]->getLastElementCurrentText().toUTF8(); |
---|
218 | |
---|
219 | int numeroFin = dtmanage_->getNumeroFromElementLabel( finString); |
---|
220 | |
---|
221 | if ( numeroFin < current) |
---|
222 | { |
---|
223 | UIsectionsToExecute_deprecated_;[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 | UIsectionsToExecute_deprecated_;[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 | |
---|
257 | void GWt_softwarePanel::addSectionToExecute() { |
---|
258 | // We put the last element of the previous sectionToExecute inside |
---|
259 | |
---|
260 | // Get the last element from previous section |
---|
261 | if (!UIsector_->getSectorControler()) { |
---|
262 | return; |
---|
263 | } |
---|
264 | unsigned long s = UIsector_->getSectorControler()->getSectionsToExecute().size(); |
---|
265 | if (s > 0) { |
---|
266 | abstractElement* abs = UIsector_->getSectorControler()->getSectionsToExecute()[s-1]->getLastElement(); |
---|
267 | UIsector_->getSectorControler()->addSectionToExecute(new sectionToExecute(abs,NULL,dtmanage_,UIsector_->getSectorControler())); |
---|
268 | UIsector_->getSectorControler()->getSectionsToExecute()[s-1]->removeLastElement(); |
---|
269 | } |
---|
270 | |
---|
271 | |
---|
272 | displayFromControler(); |
---|
273 | UIsector_->getBeamLineWidget()->buildBeamLineWidget(); |
---|
274 | } |
---|
275 | |
---|
276 | |
---|
277 | void GWt_softwarePanel::deleteSectionToExecute(int sectionLabel) |
---|
278 | { |
---|
279 | #if BAVARD > 0 |
---|
280 | cout << "***********************************" << endl; |
---|
281 | cout << " GWt_softwarePanel::deleteSectionToExecuteW()" << endl<<endl; |
---|
282 | #endif |
---|
283 | |
---|
284 | stringstream st; |
---|
285 | st << sectionLabel; |
---|
286 | std::string sectionName = st.str(); |
---|
287 | //FIXME |
---|
288 | |
---|
289 | /* if ( dtmanage_->getJobListSize() == 0 ) return; |
---|
290 | for (unsigned int sectionIndex = 0; sectionIndex< UIsectionsToExecute_deprecated_.size(); sectionIndex++) { |
---|
291 | if (UIsectionsToExecute_deprecated_[sectionIndex]->objectName() == sectionName) { |
---|
292 | |
---|
293 | // delete from dataManager |
---|
294 | UIsector_->getSectorControler()->clearSectionToExecute(sectionIndex); |
---|
295 | |
---|
296 | // delete from User Interface |
---|
297 | contenuSections_->removeWidget(UIsectionsToExecute_deprecated_[sectionIndex]); |
---|
298 | delete UIsectionsToExecute_deprecated_[sectionIndex]; |
---|
299 | UIsectionsToExecute_deprecated_.erase (UIsectionsToExecute_deprecated_.begin()+sectionIndex); |
---|
300 | } |
---|
301 | } |
---|
302 | */ |
---|
303 | displayFromControler(); |
---|
304 | } |
---|
305 | |
---|
306 | |
---|
307 | void GWt_softwarePanel::fillComboWithElements(Wt::WComboBox* cBox) |
---|
308 | { |
---|
309 | |
---|
310 | if (cBox == NULL) return; |
---|
311 | |
---|
312 | if (!UIsector_->getSectorControler()) { |
---|
313 | return; |
---|
314 | } |
---|
315 | for (unsigned int a=0; a < UIsector_->getSectorControler()->getSectionsToExecute().size(); a++) { |
---|
316 | for(unsigned int b=0; b < UIsector_->getSectorControler()->getSectionsToExecute()[a]->getElements().size(); b++) { |
---|
317 | |
---|
318 | abstractElement* abs = UIsector_->getSectorControler()->getSectionsToExecute()[a]->getElements()[b]; |
---|
319 | if (abs != NULL) { |
---|
320 | cBox->addItem(abs->getLabel()); |
---|
321 | } |
---|
322 | } |
---|
323 | } |
---|
324 | } |
---|
325 | |
---|
326 | void GWt_softwarePanel::fillComboWithSoftwares(Wt::WComboBox* cBox, std::string selected) |
---|
327 | { |
---|
328 | #if BAVARD > 0 |
---|
329 | cout << "***********************************" << endl; |
---|
330 | cout << " GWt_softwarePanel::fillComboWithSoftwares " << endl<<endl; |
---|
331 | #endif |
---|
332 | |
---|
333 | if (cBox == NULL) return; |
---|
334 | cBox->clear(); |
---|
335 | |
---|
336 | unsigned nb = nomDeLogiciel::getNumberOfSoftwares(); |
---|
337 | unsigned k; |
---|
338 | for(k = 0; k <= nb; k++) { //xx |
---|
339 | cBox->addItem(nomDeLogiciel(k).getString()); |
---|
340 | if (nomDeLogiciel(k).getString() == selected) { |
---|
341 | cBox->setCurrentIndex(cBox->count()-1); |
---|
342 | } |
---|
343 | } |
---|
344 | cBox->refresh(); |
---|
345 | } |
---|
346 | |
---|
347 | Wt::WContainerWidget* GWt_softwarePanel::createAddDeletePushButtons(int sectionNumber) |
---|
348 | { |
---|
349 | WContainerWidget* buttonContainer= new WContainerWidget(); |
---|
350 | |
---|
351 | Wt::WHBoxLayout* buttonContainerLayout = new Wt::WHBoxLayout(); |
---|
352 | buttonContainerLayout->setContentsMargins(0,0,0,0); |
---|
353 | // preparation du bouton add |
---|
354 | WPushButton* exec_add = new WPushButton("+"); |
---|
355 | exec_add->clicked().connect(this, &GWt_softwarePanel::addSectionToExecute); |
---|
356 | exec_add->setStyleClass("roundButton"); |
---|
357 | exec_add->setMaximumSize(20,20); |
---|
358 | exec_add->setToolTip("Add new section"); |
---|
359 | |
---|
360 | // preparation du bouton delete |
---|
361 | WPushButton* exec_delete = new WPushButton("-"); |
---|
362 | // warningsContainer_->setStyleClass("warningsContainer"); |
---|
363 | |
---|
364 | exec_delete->clicked().connect(boost::bind(&GWt_softwarePanel::deleteSectionToExecute, this, sectionNumber)); |
---|
365 | exec_delete->setStyleClass("roundButton"); |
---|
366 | exec_delete->setMaximumSize(20,20); |
---|
367 | exec_delete->setToolTip("Remove this section"); |
---|
368 | |
---|
369 | buttonContainerLayout->addWidget(exec_add); |
---|
370 | buttonContainerLayout->addWidget(exec_delete); |
---|
371 | buttonContainer->setLayout(buttonContainerLayout); |
---|
372 | |
---|
373 | return buttonContainer; |
---|
374 | } |
---|