Changeset 436 in PSPA for Interface_Web/trunk/pspaWT/sources/userInterface/src/GWt_sectorParameters.cc
- Timestamp:
- Nov 26, 2013, 5:36:11 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Interface_Web/trunk/pspaWT/sources/userInterface/src/GWt_sectorParameters.cc
r431 r436 3 3 #include <Wt/WPushButton> 4 4 5 #include <Wt/WGridLayout> 6 #include <Wt/WVBoxLayout> 7 #include <Wt/WHBoxLayout> 8 9 #include <Wt/WCssDecorationStyle> 10 5 11 #include "GWt_sectorParameters.h" 6 12 #include "dataManager.h" 13 #include "mixedTools.h" 14 15 #define BAVARD 0 7 16 8 17 GWt_sectorParameters::GWt_sectorParameters(dataManager* dt) … … 16 25 } 17 26 18 string* GWt_sectorParameters::getSectorParameters()19 {20 string* param = dt_->getSectorParameters()->getParametersString();21 envoi_[0] = param[0].c_str();22 envoi_[1] = param[1].c_str();23 envoi_[2] = param[2].c_str();24 envoi_[3] = param[3].c_str();25 envoi_[4] = param[4].c_str();26 return param;27 }28 29 27 void GWt_sectorParameters::execDialog() 30 28 { 31 dialog_ = new WDialog("sector parameters"); 32 string* param = getSectorParameters(); 33 34 new WText("geometry : ",dialog_->contents()); 35 geometry_ = new WLineEdit(param[1].c_str(),dialog_->contents()); 36 geometry_->disable(); 37 new WBreak(dialog_->contents()); 38 new WText("Enter number of cells : ",dialog_->contents()); 39 nCells_ = new WLineEdit(param[2].c_str(),dialog_->contents()); 40 new WBreak(dialog_->contents()); 41 new WText("Enter cell length (m): ",dialog_->contents()); 42 lCell_ = new WLineEdit(param[3].c_str(),dialog_->contents()); 43 new WBreak(dialog_->contents()); 44 new WText("Enter particle momentum (GeV/c) : ",dialog_->contents()); 45 pc_ = new WLineEdit(param[4].c_str(),dialog_->contents()); 46 new WBreak(dialog_->contents()); 47 48 WPushButton *ok = new WPushButton("Ok", dialog_->contents()); 29 #if BAVARD > 0 30 cout << "***********************************" << endl; 31 cout << " GWt_sectorParameters::execDialog() " << endl << endl; 32 #endif 33 34 dialog_ = new WDialog("sectors into beam line"); 35 dialog_->contents()->setMinimumSize(800,WLength::Auto); 36 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")); 49 51 ok->clicked().connect(dialog_, &WDialog::accept); 50 WPushButton *no = new WPushButton("Cancel", dialog_->contents());52 WPushButton *no = new WPushButton("Cancel",wb); 51 53 no->clicked().connect(dialog_, &WDialog::reject); 54 dialog_->contents()->addWidget(wb); 52 55 53 56 dialog_->finished().connect(this,&GWt_sectorParameters::dialogDone); … … 55 58 } 56 59 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 57 149 void GWt_sectorParameters::dialogDone(WDialog::DialogCode code) 58 150 { 151 #if BAVARD > 0 152 cout << "***********************************" << endl; 153 cout << " GWt_sectorParameters::dialogDone() " << endl << endl; 154 #endif 155 59 156 if (code == WDialog::Accepted) { 60 update(); 61 setStatus(); 157 setStatus("OK..."); 158 setAttributes(); 159 dt_->getSectorParameters()->setSectors(sectors_); 160 } else { 161 setStatus("Cancelled!"); 162 //cnt_.clear(); 62 163 } 63 return; 64 } 65 66 void GWt_sectorParameters::update() 67 { 68 envoi_[0] = string("4"); 69 envoi_[1] = geometry_->text().toUTF8(); 70 envoi_[2] = nCells_->text().toUTF8(); 71 envoi_[3] = lCell_->text().toUTF8(); 72 envoi_[4] = pc_->text().toUTF8(); 73 dt_->getSectorParameters()->setParametersString(envoi_); 74 } 75 76 void GWt_sectorParameters::renew() 77 { 78 string* param = getSectorParameters(); 79 setStatus(); 80 geometry_ = new WLineEdit(param[1].c_str()); 81 nCells_ = new WLineEdit(param[2].c_str()); 82 lCell_ = new WLineEdit(param[3].c_str()); 83 pc_ = new WLineEdit(param[4].c_str()); 84 } 85 86 void GWt_sectorParameters::setStatus() 87 { 88 WString out= WString("<p>geometry = "+envoi_[1]+"</p>" 89 "<p>number of cells = "+envoi_[2]+"</p>" 90 "<p>cell length = "+envoi_[3]+"</p>" 91 "<p>particle momentum = "+envoi_[4]+"</p>"); 92 status_->setText(out); 93 } 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(); 173 } 174 175 void GWt_sectorParameters::add() 176 { 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(); 185 } 186 187 void GWt_sectorParameters::cancel(int num) 188 { 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 } 210 } 211 212 void GWt_sectorParameters::setAttributes() 213 { 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); 234 } 235 236 void GWt_sectorParameters::setStatus(const WString& str) 237 { 238 status_->setText(str); 239 }
Note: See TracChangeset
for help on using the changeset viewer.