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