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