1 | |
---|
2 | #include <Wt/WBreak> |
---|
3 | #include <Wt/WPushButton> |
---|
4 | |
---|
5 | #include <Wt/WGridLayout> |
---|
6 | #include <Wt/WVBoxLayout> |
---|
7 | #include <Wt/WHBoxLayout> |
---|
8 | |
---|
9 | #include <Wt/WCssDecorationStyle> |
---|
10 | |
---|
11 | #include "GWt_sectorParameters.h" |
---|
12 | #include "dataManager.h" |
---|
13 | #include "mixedTools.h" |
---|
14 | |
---|
15 | #define BAVARD 0 |
---|
16 | |
---|
17 | void GWt_sectorParameters::setText(WText *st) |
---|
18 | { |
---|
19 | status_ = st; |
---|
20 | } |
---|
21 | |
---|
22 | void GWt_sectorParameters::execDialog_deprecated() |
---|
23 | { |
---|
24 | #if BAVARD > 0 |
---|
25 | cout << "***********************************" << endl; |
---|
26 | cout << " GWt_sectorParameters::execDialog() " << endl << endl; |
---|
27 | #endif |
---|
28 | |
---|
29 | dialog_ = new WDialog("sectors into beam line"); |
---|
30 | dialog_->contents()->setMinimumSize(800,WLength::Auto); |
---|
31 | |
---|
32 | dialog_->contents()->addWidget(new WText("geometry : ")); |
---|
33 | dialog_->contents()->addWidget(new WLineEdit("CIRCULAR")); |
---|
34 | dialog_->contents()->addWidget(new WBreak()); |
---|
35 | dialog_->contents()->addWidget(new WBreak()); |
---|
36 | |
---|
37 | gb_ = new WGroupBox("sectors",dialog_->contents()); |
---|
38 | // createSector(); |
---|
39 | |
---|
40 | dialog_->contents()->addWidget(new WBreak()); |
---|
41 | |
---|
42 | WContainerWidget *wb = new WContainerWidget(); |
---|
43 | wb->setStyleClass("buttons"); |
---|
44 | WPushButton *ok = new WPushButton("Ok",wb); |
---|
45 | ok->decorationStyle().setBackgroundColor(WColor("#87CEFA")); |
---|
46 | ok->clicked().connect(dialog_, &WDialog::accept); |
---|
47 | WPushButton *no = new WPushButton("Cancel",wb); |
---|
48 | no->clicked().connect(dialog_, &WDialog::reject); |
---|
49 | dialog_->contents()->addWidget(wb); |
---|
50 | |
---|
51 | dialog_->finished().connect(this,&GWt_sectorParameters::dialogDone); |
---|
52 | dialog_->exec(WAnimation(WAnimation::SlideInFromTop)); |
---|
53 | } |
---|
54 | |
---|
55 | void GWt_sectorParameters::createSector_deprecated() |
---|
56 | { |
---|
57 | #if BAVARD > 0 |
---|
58 | cout << "***********************************" << endl; |
---|
59 | cout << " GWt_sectorParameters::createSector() " << endl << endl; |
---|
60 | #endif |
---|
61 | |
---|
62 | WHBoxLayout* hbox= new WHBoxLayout(); |
---|
63 | hbox->setContentsMargins(0,0,0,0); |
---|
64 | |
---|
65 | /* vector<statements> v = getSectors(); |
---|
66 | |
---|
67 | hbox->addWidget(new WText("name : ")); |
---|
68 | sLabel_= new WLineEdit(v.at(0).first); |
---|
69 | hbox->addWidget(sLabel_); |
---|
70 | hbox->addWidget(new WText("from : ")); |
---|
71 | firstElement_ = new WLineEdit(v.at(0).second.at(0)); |
---|
72 | hbox->addWidget(firstElement_); |
---|
73 | hbox->addWidget(new WText("to : ")); |
---|
74 | lastElement_ = new WLineEdit(v.at(0).second.at(1)); |
---|
75 | hbox->addWidget(lastElement_); |
---|
76 | hbox->addWidget(new WText("reflection : ")); |
---|
77 | reflection_ = new WCheckBox(); |
---|
78 | reflection_->setChecked(false); // default: Unchecked |
---|
79 | if(v.at(0).second.at(2) == "Checked") reflection_->setChecked(true); |
---|
80 | hbox->addWidget(reflection_); |
---|
81 | hbox->addWidget(new WText("repeat : ")); |
---|
82 | repeat_ = new WLineEdit(v.at(0).second.at(3)); |
---|
83 | repeat_->setTextSize(2); |
---|
84 | hbox->addWidget(repeat_); |
---|
85 | |
---|
86 | WContainerWidget* bs= buttons_deprecated(cnt_.size()); |
---|
87 | hbox->addWidget(bs); |
---|
88 | |
---|
89 | WContainerWidget *w1 = new WContainerWidget(); |
---|
90 | w1->setLayout(hbox); |
---|
91 | |
---|
92 | WVBoxLayout* vbox= new WVBoxLayout(); |
---|
93 | vbox->setContentsMargins(0,0,0,0); |
---|
94 | vbox->addWidget(w1); |
---|
95 | vbox->addStretch(10); |
---|
96 | |
---|
97 | WContainerWidget *w2 = new WContainerWidget(); |
---|
98 | w2->setLayout(vbox); |
---|
99 | |
---|
100 | WGridLayout *grid = new WGridLayout(); |
---|
101 | grid->setContentsMargins(0,0,0,0); |
---|
102 | grid->addWidget(w2,0,0); |
---|
103 | grid->setColumnStretch(0,1); |
---|
104 | |
---|
105 | WContainerWidget *w3 = new WContainerWidget(); |
---|
106 | std::stringstream st; |
---|
107 | st << cnt_.size(); |
---|
108 | w3->setObjectName(st.str()); |
---|
109 | cnt_.push_back(w3); |
---|
110 | |
---|
111 | w3->setLayout(grid); |
---|
112 | gb_->addWidget(w3); |
---|
113 | */ |
---|
114 | } |
---|
115 | |
---|
116 | WContainerWidget* GWt_sectorParameters::buttons_deprecated(int num) |
---|
117 | { |
---|
118 | #if BAVARD > 0 |
---|
119 | cout << "***********************************" << endl; |
---|
120 | cout << " GWt_sectorParameters::buttons()" << endl << endl; |
---|
121 | #endif |
---|
122 | |
---|
123 | WHBoxLayout* hbox = new WHBoxLayout(); |
---|
124 | hbox->setContentsMargins(0,0,0,0); |
---|
125 | |
---|
126 | WPushButton* add = new WPushButton("+"); |
---|
127 | add->clicked().connect(this,&GWt_sectorParameters::add); |
---|
128 | add->setStyleClass("roundButton"); |
---|
129 | add->setMaximumSize(20,20); |
---|
130 | add->setToolTip("Add new section"); |
---|
131 | hbox->addWidget(add); |
---|
132 | |
---|
133 | WPushButton* cancel = new WPushButton("-"); |
---|
134 | cancel->clicked().connect(boost::bind(&GWt_sectorParameters::cancel,this,num)); |
---|
135 | cancel->setStyleClass("roundButton"); |
---|
136 | cancel->setMaximumSize(20,20); |
---|
137 | cancel->setToolTip("Remove this section"); |
---|
138 | hbox->addWidget(cancel); |
---|
139 | |
---|
140 | WContainerWidget* wb= new WContainerWidget(); |
---|
141 | wb->setLayout(hbox); |
---|
142 | return wb; |
---|
143 | } |
---|
144 | |
---|
145 | void GWt_sectorParameters::dialogDone(WDialog::DialogCode code) |
---|
146 | { |
---|
147 | #if BAVARD > 0 |
---|
148 | cout << "***********************************" << endl; |
---|
149 | cout << " GWt_sectorParameters::dialogDone() " << endl << endl; |
---|
150 | #endif |
---|
151 | |
---|
152 | if (code == WDialog::Accepted) { |
---|
153 | setStatus("OK..."); |
---|
154 | setAttributes(); |
---|
155 | // setSectors(sectors_); |
---|
156 | } else { |
---|
157 | setStatus("Cancelled!"); |
---|
158 | //cnt_.clear(); |
---|
159 | } |
---|
160 | |
---|
161 | /*#if BAVARD > 0 |
---|
162 | cout << "dialogDone():: sectors_.size()= " << sectors_.size() << endl; |
---|
163 | for(int i = 0; i < sectors_.size(); i++) { |
---|
164 | cout << "name= " << sectors_.at(i).first << ", de " << sectors_.at(i).second.at(0) << ", Ã " << sectors_.at(i).second.at(1) << ", reflection = " << sectors_.at(i).second.at(2) << ", repeat= " << sectors_.at(i).second.at(3) << endl << endl; |
---|
165 | } |
---|
166 | #endif |
---|
167 | */ |
---|
168 | cnt_.clear(); |
---|
169 | } |
---|
170 | |
---|
171 | void GWt_sectorParameters::add() |
---|
172 | { |
---|
173 | #if BAVARD > 0 |
---|
174 | cout << "***********************************" << endl; |
---|
175 | cout << " GWt_sectorParameters::add() " << endl << endl; |
---|
176 | #endif |
---|
177 | |
---|
178 | setStatus("add sector"); |
---|
179 | setAttributes(); |
---|
180 | // createSector(); |
---|
181 | } |
---|
182 | |
---|
183 | void GWt_sectorParameters::cancel(int num) |
---|
184 | { |
---|
185 | #if BAVARD > 0 |
---|
186 | cout << "***********************************" << endl; |
---|
187 | cout << " GWt_sectorParameters::cancel() " << endl << endl; |
---|
188 | #endif |
---|
189 | |
---|
190 | setStatus("delete sector"); |
---|
191 | std::stringstream st; |
---|
192 | st << num; |
---|
193 | std::string ref = st.str(); |
---|
194 | |
---|
195 | for(unsigned int k = 0; k < cnt_.size(); k++) { |
---|
196 | cout << "sectors[" << k << "]= " << cnt_[k]->objectName(); |
---|
197 | if(cnt_[k]->objectName() == st.str()) { |
---|
198 | cout << " : cancelled" << endl; |
---|
199 | gb_->removeWidget(cnt_[k]); |
---|
200 | delete cnt_[k]; |
---|
201 | cnt_.erase(cnt_.begin()+k); |
---|
202 | } else { |
---|
203 | cout << " : kept" << endl; |
---|
204 | } |
---|
205 | } |
---|
206 | } |
---|
207 | |
---|
208 | void GWt_sectorParameters::setAttributes() |
---|
209 | { |
---|
210 | #if BAVARD > 0 |
---|
211 | cout << "***********************************" << endl; |
---|
212 | cout << " GWt_sectorParameters::setAttributes() " << endl << endl; |
---|
213 | #endif |
---|
214 | |
---|
215 | string txt = ""; |
---|
216 | txt = sLabel_->text().toUTF8(); |
---|
217 | sectors_.push_back(statements(txt,vector<string>())); |
---|
218 | txt = firstElement_->text().toUTF8(); |
---|
219 | sectors_.back().second.push_back(txt); |
---|
220 | txt = lastElement_->text().toUTF8(); |
---|
221 | sectors_.back().second.push_back(txt); |
---|
222 | // checkState() retourne : Unchecked = 0, |
---|
223 | // PartiallyChecked = 1, |
---|
224 | // Checked = 2 |
---|
225 | txt = "Unchecked"; |
---|
226 | if(reflection_->checkState() > 0) txt = "Checked"; |
---|
227 | sectors_.back().second.push_back(txt); |
---|
228 | txt = repeat_->text().toUTF8(); |
---|
229 | sectors_.back().second.push_back(txt); |
---|
230 | } |
---|
231 | |
---|
232 | void GWt_sectorParameters::setStatus(const WString& str) |
---|
233 | { |
---|
234 | status_->setText(str); |
---|
235 | } |
---|