Index: Interface_Web/trunk/pspaWT/sources/userInterface/src/GWt_sectorParameters.cc
===================================================================
--- Interface_Web/trunk/pspaWT/sources/userInterface/src/GWt_sectorParameters.cc	(revision 431)
+++ Interface_Web/trunk/pspaWT/sources/userInterface/src/GWt_sectorParameters.cc	(revision 436)
@@ -3,6 +3,15 @@
 #include <Wt/WPushButton>
 
+#include <Wt/WGridLayout>
+#include <Wt/WVBoxLayout>
+#include <Wt/WHBoxLayout>
+
+#include <Wt/WCssDecorationStyle>
+
 #include "GWt_sectorParameters.h"
 #include "dataManager.h"
+#include "mixedTools.h"
+
+#define BAVARD 0
 
 GWt_sectorParameters::GWt_sectorParameters(dataManager* dt)
@@ -16,38 +25,32 @@
 }
 
-string* GWt_sectorParameters::getSectorParameters()
-{
-  string* param = dt_->getSectorParameters()->getParametersString();
-  envoi_[0] = param[0].c_str();
-  envoi_[1] = param[1].c_str();
-  envoi_[2] = param[2].c_str();
-  envoi_[3] = param[3].c_str();
-  envoi_[4] = param[4].c_str();
-  return param;
-}
-
 void GWt_sectorParameters::execDialog()
 {
-  dialog_ = new WDialog("sector parameters");
-  string* param = getSectorParameters();
-
-  new WText("geometry : ",dialog_->contents());
-  geometry_ = new WLineEdit(param[1].c_str(),dialog_->contents());
-  geometry_->disable();
-  new WBreak(dialog_->contents());
-  new WText("Enter number of cells : ",dialog_->contents());
-  nCells_ = new WLineEdit(param[2].c_str(),dialog_->contents());
-  new WBreak(dialog_->contents());
-  new WText("Enter cell length (m): ",dialog_->contents());
-  lCell_ = new WLineEdit(param[3].c_str(),dialog_->contents());
-  new WBreak(dialog_->contents());
-  new WText("Enter particle momentum (GeV/c) : ",dialog_->contents());
-  pc_ = new WLineEdit(param[4].c_str(),dialog_->contents());
-  new WBreak(dialog_->contents());
-
-  WPushButton *ok =  new WPushButton("Ok", dialog_->contents());
+#if BAVARD > 0
+  cout << "***********************************" << endl;
+  cout << " GWt_sectorParameters::execDialog() " << endl << endl;
+#endif
+
+  dialog_ = new WDialog("sectors into beam line");
+  dialog_->contents()->setMinimumSize(800,WLength::Auto);
+
+  dialog_->contents()->addWidget(new WText("geometry : "));
+  dialog_->contents()->addWidget(new WLineEdit("CIRCULAR"));
+  dialog_->contents()->addWidget(new WBreak());
+  dialog_->contents()->addWidget(new WBreak());
+
+  gb_ = new WGroupBox("sectors",dialog_->contents());
+  createSector();
+
+  dialog_->contents()->addWidget(new WBreak());
+
+  WContainerWidget *wb = new WContainerWidget();
+  wb->setStyleClass("buttons");
+  WPushButton *ok = new WPushButton("Ok",wb);
+  ok->decorationStyle().setBackgroundColor(WColor("#87CEFA"));
   ok->clicked().connect(dialog_, &WDialog::accept);
-  WPushButton *no = new WPushButton("Cancel", dialog_->contents());
+  WPushButton *no = new WPushButton("Cancel",wb);
   no->clicked().connect(dialog_, &WDialog::reject);
+  dialog_->contents()->addWidget(wb);
 
   dialog_->finished().connect(this,&GWt_sectorParameters::dialogDone);
@@ -55,39 +58,182 @@
 }
 
+void GWt_sectorParameters::createSector()
+{
+#if BAVARD > 0
+  cout << "***********************************" << endl;
+  cout << " GWt_sectorParameters::createSector() " << endl << endl;
+#endif
+
+  WHBoxLayout* hbox= new WHBoxLayout();
+  hbox->setContentsMargins(0,0,0,0);
+
+  vector<statements> v = dt_->getSectorParameters()->getSectors();
+
+  hbox->addWidget(new WText("name&nbsp;:&nbsp;"));
+  sLabel_= new WLineEdit(v.at(0).first);
+  hbox->addWidget(sLabel_);
+  hbox->addWidget(new WText("from&nbsp;:&nbsp;"));
+  firstElement_ = new WLineEdit(v.at(0).second.at(0));
+  hbox->addWidget(firstElement_);
+  hbox->addWidget(new WText("to&nbsp;:&nbsp;"));
+  lastElement_ = new WLineEdit(v.at(0).second.at(1));
+  hbox->addWidget(lastElement_);
+  hbox->addWidget(new WText("reflection&nbsp;:&nbsp;"));
+  reflection_ = new WCheckBox();
+  reflection_->setChecked(false); // default: Unchecked
+  if(v.at(0).second.at(2) == "Checked") reflection_->setChecked(true);
+  hbox->addWidget(reflection_);
+  hbox->addWidget(new WText("repeat&nbsp;:&nbsp;"));
+  repeat_ = new WLineEdit(v.at(0).second.at(3));
+  repeat_->setTextSize(2); 
+  hbox->addWidget(repeat_);
+
+  WContainerWidget* bs= buttons(cnt_.size());
+  hbox->addWidget(bs);
+
+  WContainerWidget *w1 = new WContainerWidget();
+  w1->setLayout(hbox);
+
+  WVBoxLayout* vbox= new WVBoxLayout();
+  vbox->setContentsMargins(0,0,0,0);
+  vbox->addWidget(w1);
+  vbox->addStretch(10);
+
+  WContainerWidget *w2 = new WContainerWidget();
+  w2->setLayout(vbox);
+
+  WGridLayout *grid = new WGridLayout();
+  grid->setContentsMargins(0,0,0,0);
+  grid->addWidget(w2,0,0);
+  grid->setColumnStretch(0,1);
+
+  WContainerWidget *w3 = new WContainerWidget();
+  std::stringstream st; 
+  st << cnt_.size();
+  w3->setObjectName(st.str());
+  cnt_.push_back(w3);
+ 
+  w3->setLayout(grid); 
+  gb_->addWidget(w3); 
+}
+
+WContainerWidget* GWt_sectorParameters::buttons(int num)
+{
+#if BAVARD > 0
+  cout << "***********************************" << endl;
+  cout << " GWt_sectorParameters::buttons()" << endl << endl;
+#endif
+
+  WHBoxLayout* hbox = new WHBoxLayout();
+  hbox->setContentsMargins(0,0,0,0);
+  
+  WPushButton* add = new WPushButton("+");
+  add->clicked().connect(this,&GWt_sectorParameters::add);
+  add->setStyleClass("roundButton");
+  add->setMaximumSize(20,20);
+  add->setToolTip("Add new section");
+  hbox->addWidget(add);
+
+  WPushButton* cancel = new WPushButton("-");
+  cancel->clicked().connect(boost::bind(&GWt_sectorParameters::cancel,this,num));
+  cancel->setStyleClass("roundButton");
+  cancel->setMaximumSize(20,20);
+  cancel->setToolTip("Remove this section");
+  hbox->addWidget(cancel);
+
+  WContainerWidget* wb= new WContainerWidget();
+  wb->setLayout(hbox);
+  return wb;
+}
+
 void GWt_sectorParameters::dialogDone(WDialog::DialogCode code)
 {
+#if BAVARD > 0
+  cout << "***********************************" << endl;
+  cout << " GWt_sectorParameters::dialogDone() " << endl << endl;
+#endif
+
   if (code == WDialog::Accepted) {
-    update();
-    setStatus();
+    setStatus("OK...");
+    setAttributes();
+    dt_->getSectorParameters()->setSectors(sectors_);
+  } else {
+    setStatus("Cancelled!");
+    //cnt_.clear();
   }
-  return;
-}
-
-void GWt_sectorParameters::update()
-{
-  envoi_[0] = string("4");
-  envoi_[1] = geometry_->text().toUTF8();
-  envoi_[2] = nCells_->text().toUTF8();
-  envoi_[3] = lCell_->text().toUTF8();
-  envoi_[4] = pc_->text().toUTF8();
-  dt_->getSectorParameters()->setParametersString(envoi_);
-}
-
-void GWt_sectorParameters::renew()
-{
-  string* param = getSectorParameters();
-  setStatus();
-  geometry_ = new WLineEdit(param[1].c_str());
-  nCells_ = new WLineEdit(param[2].c_str());
-  lCell_ = new WLineEdit(param[3].c_str());
-  pc_ = new WLineEdit(param[4].c_str());
-}
-
-void GWt_sectorParameters::setStatus()
-{
-  WString out= WString("<p>geometry = "+envoi_[1]+"</p>"
-	               "<p>number of cells = "+envoi_[2]+"</p>"
-  	               "<p>cell length = "+envoi_[3]+"</p>"
-   	               "<p>particle momentum = "+envoi_[4]+"</p>");
-  status_->setText(out);
-}
+
+#if BAVARD > 0
+  cout << "dialogDone():: sectors_.size()= " << sectors_.size() << endl;
+  for(int i = 0; i < sectors_.size(); i++) {
+    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;
+  }
+#endif
+
+  cnt_.clear();
+}
+
+void GWt_sectorParameters::add()
+{
+#if BAVARD > 0
+  cout << "***********************************" << endl;
+  cout << " GWt_sectorParameters::add() " << endl << endl;
+#endif
+
+  setStatus("add sector");
+  setAttributes();
+  createSector();
+}
+
+void GWt_sectorParameters::cancel(int num)
+{
+#if BAVARD > 0
+  cout << "***********************************" << endl;
+  cout << " GWt_sectorParameters::cancel() " << endl << endl;
+#endif
+
+  setStatus("delete sector");
+  std::stringstream st;
+  st << num;
+  std::string ref = st.str();
+  
+  for(unsigned int k = 0; k < cnt_.size(); k++) {
+    cout << "sectors[" << k << "]= " << cnt_[k]->objectName();
+    if(cnt_[k]->objectName() == st.str()) {
+      cout << " : cancelled" << endl;
+      gb_->removeWidget(cnt_[k]);
+      delete cnt_[k];
+      cnt_.erase(cnt_.begin()+k); 
+    } else {
+      cout << " : kept" << endl;
+    }
+  }
+}
+
+void GWt_sectorParameters::setAttributes()
+{
+#if BAVARD > 0
+  cout << "***********************************" << endl;
+  cout << " GWt_sectorParameters::setAttributes() " << endl << endl;
+#endif
+
+  string txt = "";
+  txt = sLabel_->text().toUTF8();  
+  sectors_.push_back(statements(txt,vector<string>()));
+  txt = firstElement_->text().toUTF8();
+  sectors_.back().second.push_back(txt);
+  txt = lastElement_->text().toUTF8();
+  sectors_.back().second.push_back(txt);
+  // checkState() retourne : Unchecked = 0,
+  //                         PartiallyChecked = 1,
+  //                         Checked = 2
+  txt = "Unchecked";
+  if(reflection_->checkState() > 0) txt = "Checked";
+  sectors_.back().second.push_back(txt);
+  txt = repeat_->text().toUTF8();
+  sectors_.back().second.push_back(txt);
+}
+
+void GWt_sectorParameters::setStatus(const WString& str)
+{
+  status_->setText(str);
+}
