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 | |
---|
15 | |
---|
16 | #include <Wt/WCssDecorationStyle> |
---|
17 | #include <Wt/WSignalMapper> |
---|
18 | #include <Wt/WText> |
---|
19 | #include <Wt/WImage> |
---|
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 | |
---|
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 | |
---|
39 | initialize_ligneFaisceau(inconnu); |
---|
40 | } |
---|
41 | |
---|
42 | |
---|
43 | GWt_elementLigneFaisceau::GWt_elementLigneFaisceau(typedElement type, PspaApplication* pspa) |
---|
44 | : WContainerWidget(), |
---|
45 | firstTimeInsertMessage_(NULL), |
---|
46 | dropZoneLeft_(NULL), |
---|
47 | dropZoneRight_(NULL), |
---|
48 | GWt_abstractElement_(NULL), |
---|
49 | elementLabel_(NULL), |
---|
50 | pspa_(pspa) |
---|
51 | { |
---|
52 | // set the css name |
---|
53 | setObjectName("elementLigneFaisceau"); |
---|
54 | |
---|
55 | initialize_ligneFaisceau(type); |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | void GWt_elementLigneFaisceau::initialize_ligneFaisceau(typedElement eType) |
---|
60 | { |
---|
61 | |
---|
62 | cout<<"new GWt_elementLigneFaisceau : "<< this << endl; |
---|
63 | |
---|
64 | // set layout |
---|
65 | // +----------+--------+---------+ |
---|
66 | // | (--->) | ELEM | (-----) | |
---|
67 | // +----------+--------+---------+ |
---|
68 | // | NAME | |
---|
69 | // +----------+--------+---------+ |
---|
70 | |
---|
71 | |
---|
72 | WGridLayout *gridLayout = new WGridLayout(); |
---|
73 | |
---|
74 | gridLayout->setContentsMargins(0,0,0,0); |
---|
75 | gridLayout->setHorizontalSpacing (0); |
---|
76 | gridLayout->setVerticalSpacing (0); |
---|
77 | |
---|
78 | // add first line : initialize arrow and link images |
---|
79 | dropZoneLeft_ = new GWt_dropZoneLigneFaisceau(pspa_); |
---|
80 | dropZoneRight_ = new GWt_dropZoneLigneFaisceau(pspa_); |
---|
81 | |
---|
82 | // change object name in order to manage css : |
---|
83 | dropZoneLeft_->resize(10,30); |
---|
84 | dropZoneRight_->resize(10,30); |
---|
85 | |
---|
86 | gridLayout->addWidget (dropZoneLeft_,0,0); |
---|
87 | gridLayout->addWidget (dropZoneRight_,0,2); |
---|
88 | |
---|
89 | // add the image if present |
---|
90 | |
---|
91 | switch ( eType ) { |
---|
92 | case RFgun : |
---|
93 | GWt_abstractElement_ = new GWt_rfgun(this); |
---|
94 | break; |
---|
95 | case drift : |
---|
96 | GWt_abstractElement_ = new GWt_drift(this); |
---|
97 | break; |
---|
98 | case cell : |
---|
99 | GWt_abstractElement_ = new GWt_cell(this); |
---|
100 | break; |
---|
101 | case bend : |
---|
102 | GWt_abstractElement_ = new GWt_bend(this); |
---|
103 | break; |
---|
104 | case soleno : |
---|
105 | GWt_abstractElement_ = new GWt_soleno(this); |
---|
106 | break; |
---|
107 | case beam : |
---|
108 | GWt_abstractElement_ = new GWt_beam(this); |
---|
109 | break; |
---|
110 | case fit : |
---|
111 | GWt_abstractElement_ = new GWt_fit(this); |
---|
112 | break; |
---|
113 | case inconnu : |
---|
114 | GWt_abstractElement_ = NULL; |
---|
115 | } |
---|
116 | if (GWt_abstractElement_ != NULL) { |
---|
117 | gridLayout->addWidget (GWt_abstractElement_,0,1); |
---|
118 | GWt_abstractElement_->setMaximumSize(32,32); |
---|
119 | GWt_abstractElement_->setMinimumSize(32,32); |
---|
120 | } |
---|
121 | |
---|
122 | // add second line |
---|
123 | if (GWt_abstractElement_ == NULL) { |
---|
124 | elementLabel_ = new WText(); |
---|
125 | } else { |
---|
126 | elementLabel_ = new WText(GWt_abstractElement_->getAbstractElement()->getLabel()); |
---|
127 | } |
---|
128 | |
---|
129 | gridLayout->addWidget (elementLabel_,1,0,1,3,Wt::AlignCenter |Wt::AlignMiddle); |
---|
130 | |
---|
131 | gridLayout->setColumnStretch (0,1); |
---|
132 | gridLayout->setColumnStretch (2,1); |
---|
133 | |
---|
134 | // set layout |
---|
135 | setLayout(gridLayout); |
---|
136 | } |
---|
137 | |
---|
138 | |
---|
139 | GWt_elementLigneFaisceau::~GWt_elementLigneFaisceau() |
---|
140 | { |
---|
141 | } |
---|
142 | |
---|
143 | |
---|
144 | void GWt_elementLigneFaisceau::removeDone(GWt_abstractElement* gw) |
---|
145 | { |
---|
146 | if (messageDropZone_->result() == WDialog::Accepted) { |
---|
147 | // FIXME |
---|
148 | // removeDropZone(); |
---|
149 | } |
---|
150 | } |
---|
151 | |
---|
152 | |
---|
153 | void GWt_elementLigneFaisceau::addElement(GWt_abstractElement* elem){ |
---|
154 | |
---|
155 | clear(); |
---|
156 | GWt_abstractElement_ = elem; |
---|
157 | addWidget(GWt_abstractElement_); |
---|
158 | if (static_cast <WContainerWidget*> (parent())) { |
---|
159 | WContainerWidget* wc = static_cast <WContainerWidget*> (parent()); |
---|
160 | WBoxLayout* layout = ((WBoxLayout*)(wc->layout())); |
---|
161 | layout->setStretchFactor(this,0); |
---|
162 | } |
---|
163 | |
---|
164 | |
---|
165 | firstTimeInsertMessage_ = NULL; |
---|
166 | dropZoneLeft_ = NULL; |
---|
167 | } |
---|
168 | |
---|
169 | |
---|
170 | std::string GWt_elementLigneFaisceau::getElementNumberInBeamLine(nomdElements elem){ |
---|
171 | string str = ""; |
---|
172 | |
---|
173 | if (static_cast <WContainerWidget*> (parent())) { |
---|
174 | WContainerWidget* wc = static_cast <WContainerWidget*> (parent()); |
---|
175 | for (int a=0; a<wc->count(); a++) { |
---|
176 | if (static_cast <GWt_abstractElement*> (wc->widget (a))) { |
---|
177 | // GWt_abstractElement* ab = static_cast <GWt_abstractElement*> (wc->widget (a)); |
---|
178 | /* |
---|
179 | printf("1--->%d\n",ab->getElement()); |
---|
180 | printf("2--->%d\n",ab->getElement()->getLenghtOfElement()); |
---|
181 | printf("3--->%d\n",ab->getElement()->getName().getElementType()); |
---|
182 | printf("4--->%d\n",elem.getElementType()); |
---|
183 | |
---|
184 | if (static_cast <GWt_abstractElement*> (wc->widget (a))->getElement()->getName().getElementType() == elem.getElementType()) { |
---|
185 | pspa_->addConsoleMessage("type trouvÃ"); |
---|
186 | } else { |
---|
187 | pspa_->addConsoleMessage("type trouvà NOT "); |
---|
188 | } |
---|
189 | */ |
---|
190 | |
---|
191 | } |
---|
192 | } |
---|
193 | |
---|
194 | int n = 999999; |
---|
195 | |
---|
196 | std::stringstream stream; |
---|
197 | stream << n ; |
---|
198 | std::string number(stream.str()); |
---|
199 | |
---|
200 | if(n < 10) { |
---|
201 | str= elem.getElementLabel()+"0"+number; |
---|
202 | } else { |
---|
203 | str= elem.getElementLabel()+number; |
---|
204 | } |
---|
205 | } |
---|
206 | |
---|
207 | return str; |
---|
208 | } |
---|
209 | |
---|
210 | |
---|
211 | void GWt_elementLigneFaisceau::setElementLabel(std::string label) { |
---|
212 | if (elementLabel_) { |
---|
213 | elementLabel_->setText(label); |
---|
214 | } |
---|
215 | } |
---|
216 | |
---|