[178] | 1 | #include <iostream> |
---|
| 2 | |
---|
[265] | 3 | #include "GWt_elementLigneFaisceau.h" |
---|
[198] | 4 | #include "nomdElements.h" |
---|
[242] | 5 | #include "GWt_console.h" |
---|
[248] | 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" |
---|
[343] | 14 | #include "GWt_snapshot.h" |
---|
[178] | 15 | |
---|
[248] | 16 | |
---|
[178] | 17 | #include <Wt/WCssDecorationStyle> |
---|
[186] | 18 | #include <Wt/WSignalMapper> |
---|
[178] | 19 | #include <Wt/WText> |
---|
[198] | 20 | #include <Wt/WImage> |
---|
| 21 | #include <Wt/WHBoxLayout> |
---|
[239] | 22 | #include <Wt/WGridLayout> |
---|
[246] | 23 | #include <Wt/WLength> |
---|
| 24 | #include <Wt/WVBoxLayout> |
---|
[267] | 25 | #include <Wt/WApplication> |
---|
[178] | 26 | |
---|
[272] | 27 | #define PSPA_DEBUG 1 |
---|
[246] | 28 | |
---|
[292] | 29 | GWt_elementLigneFaisceau::GWt_elementLigneFaisceau(PspaApplication* pspa) |
---|
[379] | 30 | : WContainerWidget(), |
---|
| 31 | firstTimeInsertMessage_(NULL), |
---|
| 32 | dropZoneLeft_(NULL), |
---|
| 33 | dropZoneRight_(NULL), |
---|
| 34 | GWt_abstractElement_(NULL), |
---|
| 35 | elementLabel_(NULL), |
---|
| 36 | pspa_(pspa) |
---|
[178] | 37 | { |
---|
[379] | 38 | initialize_ligneFaisceau(inconnu); |
---|
[178] | 39 | } |
---|
| 40 | |
---|
[305] | 41 | |
---|
[379] | 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) |
---|
[178] | 50 | { |
---|
[379] | 51 | // set the css name |
---|
| 52 | setObjectName("elementLigneFaisceau"); |
---|
| 53 | initialize_ligneFaisceau(type); |
---|
[178] | 54 | } |
---|
| 55 | |
---|
[305] | 56 | void GWt_elementLigneFaisceau::initialize_ligneFaisceau(typedElement eType) |
---|
[379] | 57 | { |
---|
| 58 | cout<<"new GWt_elementLigneFaisceau : "<< this << endl; |
---|
[248] | 59 | |
---|
[379] | 60 | // set layout |
---|
| 61 | // +----------+--------+---------+ |
---|
| 62 | // | (--->) | ELEM | (-----) | |
---|
| 63 | // +----------+--------+---------+ |
---|
| 64 | |
---|
[248] | 65 | |
---|
[379] | 66 | WGridLayout *gridLayout = new WGridLayout(); |
---|
[248] | 67 | |
---|
[379] | 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 |
---|
[272] | 95 | |
---|
[379] | 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; |
---|
[347] | 125 | } |
---|
[379] | 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()); |
---|
[347] | 147 | } |
---|
[379] | 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(); |
---|
[382] | 154 | WHBoxLayout* hLayoutActions = new WHBoxLayout(); |
---|
[379] | 155 | actions->setStyleClass("beamLineElementActions"); |
---|
| 156 | actions->setPositionScheme(Wt::Static); |
---|
| 157 | |
---|
[382] | 158 | actions->setLayout(hLayoutActions); |
---|
| 159 | hLayoutActions->setContentsMargins(0,0,0,0); |
---|
[379] | 160 | |
---|
| 161 | actionParameters_ = new WText(" "); |
---|
| 162 | actionTrash_ = new WText(" "); |
---|
| 163 | |
---|
[365] | 164 | // set tooltips |
---|
[379] | 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 | |
---|
[382] | 180 | hLayoutActions->addWidget(actionParameters_); |
---|
| 181 | hLayoutActions->addWidget(actionTrash_); |
---|
[379] | 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); |
---|
[178] | 201 | } |
---|
| 202 | |
---|
[379] | 203 | GWt_elementLigneFaisceau::~GWt_elementLigneFaisceau() |
---|
| 204 | {} |
---|
[223] | 205 | |
---|
[379] | 206 | void GWt_elementLigneFaisceau::update() |
---|
[178] | 207 | { |
---|
[379] | 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()); |
---|
[375] | 212 | } |
---|
[379] | 213 | } |
---|
[375] | 214 | } |
---|
| 215 | |
---|
[347] | 216 | void GWt_elementLigneFaisceau::setBGColor(const WColor c) { |
---|
[379] | 217 | elementContainer_->decorationStyle().setBackgroundColor (c); |
---|
[347] | 218 | } |
---|
| 219 | |
---|
[265] | 220 | void GWt_elementLigneFaisceau::removeDone(GWt_abstractElement* gw) |
---|
[186] | 221 | { |
---|
[379] | 222 | if (messageDropZone_->result() == WDialog::Accepted) { |
---|
| 223 | // FIXME |
---|
| 224 | // removeDropZone(); |
---|
| 225 | } |
---|
[199] | 226 | } |
---|
[186] | 227 | |
---|
[343] | 228 | void GWt_elementLigneFaisceau::addElement(GWt_abstractElement* elem) |
---|
[359] | 229 | { |
---|
[379] | 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 | } |
---|
[359] | 238 | |
---|
[379] | 239 | firstTimeInsertMessage_ = NULL; |
---|
| 240 | dropZoneLeft_ = NULL; |
---|
[198] | 241 | } |
---|
| 242 | |
---|
[305] | 243 | |
---|
[379] | 244 | std::string GWt_elementLigneFaisceau::getElementNumberInBeamLine(nomdElements elem) |
---|
| 245 | { |
---|
| 246 | string str = ""; |
---|
[272] | 247 | |
---|
[379] | 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 "); |
---|
[272] | 263 | } |
---|
[379] | 264 | */ |
---|
[272] | 265 | |
---|
[379] | 266 | } |
---|
[198] | 267 | } |
---|
| 268 | |
---|
[379] | 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; |
---|
[198] | 283 | } |
---|
[264] | 284 | |
---|
[305] | 285 | |
---|
| 286 | void GWt_elementLigneFaisceau::setElementLabel(std::string label) { |
---|
[379] | 287 | if (elementLabel_) { |
---|
| 288 | elementLabel_->setText(label.substr(0,10)); |
---|
| 289 | elementLabel_->setToolTip(label); |
---|
| 290 | } |
---|
[264] | 291 | } |
---|
[365] | 292 | |
---|
| 293 | |
---|
| 294 | void GWt_elementLigneFaisceau::mouseWentOut() { |
---|
[379] | 295 | actionParameters_->setStyleClass("Button WhiteButton HiddenButton parameters"); |
---|
| 296 | actionTrash_->setStyleClass("Button WhiteButton HiddenButton trash"); |
---|
[365] | 297 | } |
---|
| 298 | |
---|
| 299 | |
---|
| 300 | void GWt_elementLigneFaisceau::mouseWentOver() { |
---|
[379] | 301 | actionParameters_->setStyleClass("Button WhiteButton ContrastButton parameters"); |
---|
| 302 | actionTrash_->setStyleClass("Button WhiteButton ContrastButton trash"); |
---|
[369] | 303 | } |
---|