1 | #include <iostream> |
---|
2 | |
---|
3 | #include "GWt_elementLigneFaisceau.h" |
---|
4 | #include "nomdElements.h" |
---|
5 | #include "GWt_console.h" |
---|
6 | #include "abstractElement.h" |
---|
7 | #include "GWt_rfgun.h" |
---|
8 | #include "GWt_drift.h" |
---|
9 | #include "GWt_cell.h" |
---|
10 | #include "GWt_bend.h" |
---|
11 | #include "GWt_soleno.h" |
---|
12 | #include "GWt_beam.h" |
---|
13 | #include "GWt_fit.h" |
---|
14 | #include "GWt_snapshot.h" |
---|
15 | |
---|
16 | |
---|
17 | #include <Wt/WCssDecorationStyle> |
---|
18 | #include <Wt/WSignalMapper> |
---|
19 | #include <Wt/WText> |
---|
20 | #include <Wt/WImage> |
---|
21 | #include <Wt/WHBoxLayout> |
---|
22 | #include <Wt/WGridLayout> |
---|
23 | #include <Wt/WLength> |
---|
24 | #include <Wt/WVBoxLayout> |
---|
25 | #include <Wt/WApplication> |
---|
26 | |
---|
27 | #define PSPA_DEBUG 1 |
---|
28 | |
---|
29 | GWt_elementLigneFaisceau::GWt_elementLigneFaisceau(PspaApplication* pspa) |
---|
30 | : WContainerWidget(), |
---|
31 | firstTimeInsertMessage_(NULL), |
---|
32 | dropZoneLeft_(NULL), |
---|
33 | dropZoneRight_(NULL), |
---|
34 | GWt_abstractElement_(NULL), |
---|
35 | elementLabel_(NULL), |
---|
36 | pspa_(pspa) |
---|
37 | { |
---|
38 | initialize_ligneFaisceau(inconnu); |
---|
39 | } |
---|
40 | |
---|
41 | |
---|
42 | GWt_elementLigneFaisceau::GWt_elementLigneFaisceau(typedElement type,PspaApplication* pspa) |
---|
43 | : WContainerWidget(), |
---|
44 | firstTimeInsertMessage_(NULL), |
---|
45 | dropZoneLeft_(NULL), |
---|
46 | dropZoneRight_(NULL), |
---|
47 | GWt_abstractElement_(NULL), |
---|
48 | elementLabel_(NULL), |
---|
49 | pspa_(pspa) |
---|
50 | { |
---|
51 | // set the css name |
---|
52 | setObjectName("elementLigneFaisceau"); |
---|
53 | initialize_ligneFaisceau(type); |
---|
54 | } |
---|
55 | |
---|
56 | void GWt_elementLigneFaisceau::initialize_ligneFaisceau(typedElement eType) |
---|
57 | { |
---|
58 | cout<<"new GWt_elementLigneFaisceau : "<< this << endl; |
---|
59 | |
---|
60 | // set layout |
---|
61 | // +----------+--------+---------+ |
---|
62 | // | (--->) | ELEM | (-----) | |
---|
63 | // +----------+--------+---------+ |
---|
64 | |
---|
65 | |
---|
66 | WGridLayout *gridLayout = new WGridLayout(); |
---|
67 | |
---|
68 | gridLayout->setContentsMargins(0,0,0,0); |
---|
69 | gridLayout->setHorizontalSpacing(0); |
---|
70 | gridLayout->setVerticalSpacing(0); |
---|
71 | |
---|
72 | // add first line : initialize arrow and link images |
---|
73 | dropZoneLeft_ = new GWt_dropZoneLigneFaisceau(pspa_); |
---|
74 | dropZoneRight_ = new GWt_dropZoneLigneFaisceau(pspa_); |
---|
75 | |
---|
76 | // change object name in order to manage css : |
---|
77 | dropZoneLeft_->resize(10,30); |
---|
78 | dropZoneRight_->resize(10,30); |
---|
79 | |
---|
80 | gridLayout->addWidget (dropZoneLeft_,0,0); |
---|
81 | gridLayout->addWidget (dropZoneRight_,0,2); |
---|
82 | |
---|
83 | // add first line : initialize arrow and link images |
---|
84 | dropZoneLeft_ = new GWt_dropZoneLigneFaisceau(pspa_); |
---|
85 | dropZoneRight_ = new GWt_dropZoneLigneFaisceau(pspa_); |
---|
86 | |
---|
87 | // change object name in order to manage css : |
---|
88 | dropZoneLeft_->resize(10,30); |
---|
89 | dropZoneRight_->resize(10,30); |
---|
90 | |
---|
91 | gridLayout->addWidget (dropZoneLeft_,0,0); |
---|
92 | gridLayout->addWidget (dropZoneRight_,0,2); |
---|
93 | |
---|
94 | // add the image if present |
---|
95 | |
---|
96 | switch ( eType ) { |
---|
97 | case RFgun : |
---|
98 | GWt_abstractElement_ = new GWt_rfgun(this); |
---|
99 | break; |
---|
100 | case drift : |
---|
101 | GWt_abstractElement_ = new GWt_drift(this); |
---|
102 | break; |
---|
103 | case cell : |
---|
104 | GWt_abstractElement_ = new GWt_cell(this); |
---|
105 | break; |
---|
106 | case bend : |
---|
107 | GWt_abstractElement_ = new GWt_bend(this); |
---|
108 | break; |
---|
109 | case soleno : |
---|
110 | GWt_abstractElement_ = new GWt_soleno(this); |
---|
111 | break; |
---|
112 | case beam : |
---|
113 | GWt_abstractElement_ = new GWt_beam(this); |
---|
114 | break; |
---|
115 | case fit : |
---|
116 | GWt_abstractElement_ = new GWt_fit(this); |
---|
117 | break; |
---|
118 | case snapshot : |
---|
119 | { |
---|
120 | int incr = pspa_->getExtensionFile(); |
---|
121 | incr++; |
---|
122 | pspa_->setExtensionFile(incr); |
---|
123 | GWt_abstractElement_ = new GWt_snapshot(this,incr); |
---|
124 | break; |
---|
125 | } |
---|
126 | case inconnu : |
---|
127 | GWt_abstractElement_ = NULL; |
---|
128 | } |
---|
129 | |
---|
130 | elementContainer_ = new WContainerWidget(); |
---|
131 | WVBoxLayout* vLayoutElementContainer = new WVBoxLayout(); |
---|
132 | vLayoutElementContainer->setContentsMargins(0,0,0,0); |
---|
133 | elementContainer_->setPadding (4); |
---|
134 | elementContainer_->setStyleClass("beamLineIcon"); |
---|
135 | elementContainer_->setLayout(vLayoutElementContainer); |
---|
136 | |
---|
137 | if (GWt_abstractElement_ != NULL) { |
---|
138 | vLayoutElementContainer->addWidget(GWt_abstractElement_); |
---|
139 | GWt_abstractElement_->setMaximumSize(64,40); |
---|
140 | GWt_abstractElement_->setMinimumSize(64,40); |
---|
141 | } |
---|
142 | |
---|
143 | if (GWt_abstractElement_ == NULL) { |
---|
144 | elementLabel_ = new WText(); |
---|
145 | } else { |
---|
146 | elementLabel_ = new WText(GWt_abstractElement_->getAbstractElement()->getLabel()); |
---|
147 | } |
---|
148 | |
---|
149 | vLayoutElementContainer->addWidget(elementLabel_,Wt::AlignCenter |Wt::AlignMiddle); |
---|
150 | // gridLayout->addWidget(elementLabel_,1,0,1,3,Wt::AlignCenter |Wt::AlignMiddle); |
---|
151 | |
---|
152 | // Add Actions |
---|
153 | WContainerWidget* actions = new WContainerWidget(); |
---|
154 | WHBoxLayout* hLayoutActions = new WHBoxLayout(); |
---|
155 | actions->setStyleClass("beamLineElementActions"); |
---|
156 | actions->setPositionScheme(Wt::Static); |
---|
157 | |
---|
158 | actions->setLayout(hLayoutActions); |
---|
159 | hLayoutActions->setContentsMargins(0,0,0,0); |
---|
160 | |
---|
161 | actionParameters_ = new WText(" "); |
---|
162 | actionTrash_ = new WText(" "); |
---|
163 | |
---|
164 | // set tooltips |
---|
165 | actionParameters_->setToolTip("change parameters"); |
---|
166 | actionTrash_->setToolTip("delete"); |
---|
167 | |
---|
168 | // Set class for actions elements |
---|
169 | actionParameters_->setStyleClass("Button WhiteButton HiddenButton parameters"); |
---|
170 | actionParameters_->setMaximumSize(32,32); |
---|
171 | actionParameters_->setMinimumSize(32,32); |
---|
172 | |
---|
173 | actionTrash_->setStyleClass("Button WhiteButton HiddenButton trash"); |
---|
174 | actionTrash_->setMaximumSize(32,32); |
---|
175 | actionTrash_->setMinimumSize(32,32); |
---|
176 | |
---|
177 | // Set the global action class |
---|
178 | actions->setOffsets(0); |
---|
179 | |
---|
180 | hLayoutActions->addWidget(actionParameters_); |
---|
181 | hLayoutActions->addWidget(actionTrash_); |
---|
182 | vLayoutElementContainer->addWidget(actions); |
---|
183 | |
---|
184 | // add software name |
---|
185 | softwareName_ = new WText(""); |
---|
186 | softwareName_->setStyleClass("softwareElementLigneFaisceauName"); |
---|
187 | vLayoutElementContainer->addWidget(softwareName_); |
---|
188 | |
---|
189 | gridLayout->addWidget (elementContainer_,0,1); |
---|
190 | gridLayout->setColumnStretch (0,1); |
---|
191 | gridLayout->setColumnStretch (2,1); |
---|
192 | |
---|
193 | // set layout |
---|
194 | setLayout(gridLayout); |
---|
195 | |
---|
196 | // enable signals |
---|
197 | elementContainer_->mouseWentOut().connect(this,&GWt_elementLigneFaisceau::mouseWentOut); |
---|
198 | elementContainer_->mouseWentOver().connect(this,&GWt_elementLigneFaisceau::mouseWentOver); |
---|
199 | actionParameters_->clicked().connect(GWt_abstractElement_,&GWt_abstractElement::showParameters); |
---|
200 | actionTrash_->clicked().connect(GWt_abstractElement_,&GWt_abstractElement::deleteElement); |
---|
201 | } |
---|
202 | |
---|
203 | GWt_elementLigneFaisceau::~GWt_elementLigneFaisceau() |
---|
204 | {} |
---|
205 | |
---|
206 | void GWt_elementLigneFaisceau::update() |
---|
207 | { |
---|
208 | if (getGWt_AbstractElement()->getAbstractElement()) { |
---|
209 | if (getGWt_AbstractElement()->getAbstractElement()->getAbstractSoftware()) { |
---|
210 | setBGColor(WColor(getGWt_AbstractElement()->getAbstractElement()->getAbstractSoftware()->getColor())); |
---|
211 | softwareName_->setText(getGWt_AbstractElement()->getAbstractElement()->getAbstractSoftware()->getName()); |
---|
212 | } |
---|
213 | } |
---|
214 | } |
---|
215 | |
---|
216 | void GWt_elementLigneFaisceau::setBGColor(const WColor c) { |
---|
217 | elementContainer_->decorationStyle().setBackgroundColor (c); |
---|
218 | } |
---|
219 | |
---|
220 | void GWt_elementLigneFaisceau::removeDone(GWt_abstractElement* gw) |
---|
221 | { |
---|
222 | if (messageDropZone_->result() == WDialog::Accepted) { |
---|
223 | // FIXME |
---|
224 | // removeDropZone(); |
---|
225 | } |
---|
226 | } |
---|
227 | |
---|
228 | void GWt_elementLigneFaisceau::addElement(GWt_abstractElement* elem) |
---|
229 | { |
---|
230 | clear(); |
---|
231 | GWt_abstractElement_ = elem; |
---|
232 | addWidget(GWt_abstractElement_); |
---|
233 | if (static_cast <WContainerWidget*> (parent())) { |
---|
234 | WContainerWidget* wc = static_cast <WContainerWidget*> (parent()); |
---|
235 | WBoxLayout* layout = ((WBoxLayout*)(wc->layout())); |
---|
236 | layout->setStretchFactor(this,0); |
---|
237 | } |
---|
238 | |
---|
239 | firstTimeInsertMessage_ = NULL; |
---|
240 | dropZoneLeft_ = NULL; |
---|
241 | } |
---|
242 | |
---|
243 | |
---|
244 | std::string GWt_elementLigneFaisceau::getElementNumberInBeamLine(nomdElements elem) |
---|
245 | { |
---|
246 | string str = ""; |
---|
247 | |
---|
248 | if (static_cast <WContainerWidget*> (parent())) { |
---|
249 | WContainerWidget* wc = static_cast <WContainerWidget*> (parent()); |
---|
250 | for (int a=0; a<wc->count(); a++) { |
---|
251 | if (static_cast <GWt_abstractElement*> (wc->widget (a))) { |
---|
252 | // GWt_abstractElement* ab = static_cast <GWt_abstractElement*> (wc->widget (a)); |
---|
253 | /* |
---|
254 | printf("1--->%d\n",ab->getElement()); |
---|
255 | printf("2--->%d\n",ab->getElement()->getLenghtOfElement()); |
---|
256 | printf("3--->%d\n",ab->getElement()->getName().getElementType()); |
---|
257 | printf("4--->%d\n",elem.getElementType()); |
---|
258 | |
---|
259 | if (static_cast <GWt_abstractElement*> (wc->widget (a))->getElement()->getName().getElementType() == elem.getElementType()) { |
---|
260 | pspa_->addConsoleMessage("type trouvÃ"); |
---|
261 | } else { |
---|
262 | pspa_->addConsoleMessage("type trouvà NOT "); |
---|
263 | } |
---|
264 | */ |
---|
265 | |
---|
266 | } |
---|
267 | } |
---|
268 | |
---|
269 | int n = 999999; |
---|
270 | |
---|
271 | std::stringstream stream; |
---|
272 | stream << n ; |
---|
273 | std::string number(stream.str()); |
---|
274 | |
---|
275 | if(n < 10) { |
---|
276 | str= elem.getElementLabel()+"0"+number; |
---|
277 | } else { |
---|
278 | str= elem.getElementLabel()+number; |
---|
279 | } |
---|
280 | } |
---|
281 | |
---|
282 | return str; |
---|
283 | } |
---|
284 | |
---|
285 | |
---|
286 | void GWt_elementLigneFaisceau::setElementLabel(std::string label) { |
---|
287 | if (elementLabel_) { |
---|
288 | elementLabel_->setText(label.substr(0,10)); |
---|
289 | elementLabel_->setToolTip(label); |
---|
290 | } |
---|
291 | } |
---|
292 | |
---|
293 | |
---|
294 | void GWt_elementLigneFaisceau::mouseWentOut() { |
---|
295 | actionParameters_->setStyleClass("Button WhiteButton HiddenButton parameters"); |
---|
296 | actionTrash_->setStyleClass("Button WhiteButton HiddenButton trash"); |
---|
297 | } |
---|
298 | |
---|
299 | |
---|
300 | void GWt_elementLigneFaisceau::mouseWentOver() { |
---|
301 | actionParameters_->setStyleClass("Button WhiteButton ContrastButton parameters"); |
---|
302 | actionTrash_->setStyleClass("Button WhiteButton ContrastButton trash"); |
---|
303 | } |
---|