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