source: PSPA/Interface_Web/trunk/pspaWT/sources/userInterface/src/GWt_abstractElement.cc @ 431

Last change on this file since 431 was 431, checked in by touze, 11 years ago

systeme periodique (mailles) + multipoles + madx

File size: 5.2 KB
Line 
1
2#include <iostream>
3#include <string>
4#include <boost/variant.hpp>
5#include <boost/variant/get.hpp>
6
7#include "GWt_abstractElement.h"
8#include "GWt_elementLigneFaisceau.h"
9#include "GWt_rfgun.h"
10#include "GWt_drift.h"
11#include "GWt_cell.h"
12#include "GWt_bend.h"
13#include "GWt_soleno.h"
14#include "GWt_beam.h"
15#include "GWt_fit.h"
16//#include "GWt_snapshot.h"
17
18#include "GWt_draggableImage.h"
19#include "GWt_ligneFaisceau.h"
20
21#include "mixedTools.h"
22#include "nomdElements.h"
23
24#include <Wt/WText>
25#include <Wt/WLineEdit>
26#include <Wt/WBreak>
27#include <Wt/WApplication>
28#include <Wt/WMessageBox>
29
30
31GWt_abstractElement::GWt_abstractElement(abstractElement* elem)
32  : WContainerWidget()
33{
34  abstractElement_ = elem;
35}
36
37void GWt_abstractElement::initialize()
38{
39  image_ = new WImage(getBigImageURL(),this); // make image 
40  addWidget(image_);
41  updateLabelAndToolTipWidget();
42}
43
44string* GWt_abstractElement::beginDialog()
45{
46  string* param = abstractElement_->getParametersString();
47 
48  if ( param == NULL ) {
49    if ( static_cast<GWt_console*> (wApp->findWidget ("console"))) {
50      GWt_console* console = static_cast<GWt_console*> (wApp->findWidget ("console"));
51      console->addConsoleMessage(" GWt_abstractElement::beginDialog : empty parameter set for element " + abstractElement_->getNomdElement().getExpandedName());
52    }
53  }
54
55  int nbparam = atoi(param->c_str());
56  if ( nbparam != abstractElement_->getNbParams()) {
57    if ( static_cast<GWt_console*> (wApp->findWidget ("console"))) {
58      GWt_console* console = static_cast<GWt_console*> (wApp->findWidget ("console"));
59      console->addConsoleMessage(" element seems not to be a " + abstractElement_->getNomdElement().getExpandedName());
60    }
61  }
62 
63  dialog_ = new WDialog("element "+abstractElement_->getNomdElement().getExpandedName());
64  new WText(" label of the element : ",dialog_->contents());
65  labelEdit_ = new WLineEdit( (++param)->c_str(),dialog_->contents());
66  new WBreak(dialog_->contents());
67  return ++param;
68}
69
70void GWt_abstractElement::updateLabelAndToolTipWidget()
71{
72  if (abstractElement_ != NULL) {
73    elementLigneFaiseauContainer_->setElementLabel(abstractElement_->getLabel());
74    setToolTip(print());
75  }
76}
77
78void GWt_abstractElement::showParameters()
79{
80  initilializeDialog();
81  dialog_->show();
82}
83
84void GWt_abstractElement::deleteElement()
85{
86  StandardButton result = WMessageBox::show("PSPA : Delete element", WString("Delete '")+WString(getAbstractElement()->getLabel())+"' ?", Ok | Cancel);
87 
88  if (result == Cancel) {
89    return;
90  }
91  // get LigneFaiseau widget and add new elementLigneFaiseau
92  GWt_LigneFaisceau* ligneFaisceau = NULL;
93  if ( static_cast<GWt_LigneFaisceau*> (wApp->findWidget ("ligneFaisceau"))) {
94    ligneFaisceau = static_cast<GWt_LigneFaisceau*> (wApp->findWidget ("ligneFaisceau"));
95  } else {
96    return;
97  }
98 
99  ligneFaisceau->removeElement(this);
100}
101
102void GWt_abstractElement::createDragImage(WContainerWidget* w)
103{
104  GWt_draggableImage *result= new GWt_draggableImage(getBigImageURL(),w);
105 
106  /*
107   * Set the image to be draggable, showing the other image (dragImage)
108   * to be used as the widget that is visually dragged.
109   */
110  result->setDraggable(getMimeType(),new WImage(getSmallImageURL(),w),true);
111  result->setToolTip(getName());
112}
113
114void GWt_abstractElement::FileInput(ifstream& ifs)
115{
116  getAbstractElement()->FileInput(ifs);
117  initilializeDialog();
118  updateLabelAndToolTipWidget();
119 
120  // update parameters
121  GWt_LigneFaisceau* ligneFaisceau = NULL;
122  if ( static_cast<GWt_LigneFaisceau*> (wApp->findWidget ("ligneFaisceau"))) {
123    ligneFaisceau = static_cast<GWt_LigneFaisceau*> (wApp->findWidget ("ligneFaisceau"));
124    ligneFaisceau->update();
125  }
126}
127
128abstractElement* GWt_abstractElement::getAbstractElement() {
129  return abstractElement_;
130}
131
132WContainerWidget* GWt_abstractElement::getWidget() {
133  return wc_;
134}
135
136WImage* GWt_abstractElement::getImage() {
137  return image_;
138}
139
140variant<int, string, bool, float, NullType> GWt_abstractElement::getParamValue(string elem) 
141{
142  if(parameterMapValue.find(elem) == parameterMapValue.end()) {
143    return new NullType();
144  }
145 
146  std::map<std::string, variant<int, string, bool, float, NullType> >::iterator it;
147  it = parameterMapValue.find(elem);
148  variant <int, string, bool, float, NullType> value = it->second;
149 
150  try {
151    int pi = boost::get<int>(value);
152    printf("%s Type is int\n",elem.c_str());
153    return pi;
154  }
155  catch (boost::bad_get v) {
156    try {
157      string si = boost::get<string>(value);
158      printf("%s Type is string\n",elem.c_str());
159      return si;
160    }
161    catch (boost::bad_get v) {
162      try {
163        bool bi = boost::get<bool>(value);
164        printf("%s Type is bool\n",elem.c_str());
165        return bi;
166      }
167      catch (boost::bad_get v) {
168        printf("%s Type is NULL\n",elem.c_str());
169        return new NullType();
170      }
171    }
172  }
173  printf("%s Type is NULL NULL\n",elem.c_str());
174  return new NullType();
175}
176
177string GWt_abstractElement::getParamDescription(string elem)
178{   
179  if(parameterMapDescription.find(elem) == parameterMapDescription.end() ) {
180    printf("%s Descr is NULL NULL\n",elem.c_str());
181    return "";
182  } else {
183    printf("%s Descr is %s\n",elem.c_str(),parameterMapDescription.find(elem)->second.c_str());
184    return parameterMapDescription.find(elem)->second;
185  }
186}
Note: See TracBrowser for help on using the repository browser.