[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/WHBoxLayout> |
---|
[239] | 21 | #include <Wt/WGridLayout> |
---|
[246] | 22 | #include <Wt/WLength> |
---|
| 23 | #include <Wt/WVBoxLayout> |
---|
[267] | 24 | #include <Wt/WApplication> |
---|
[178] | 25 | |
---|
[272] | 26 | #define PSPA_DEBUG 1 |
---|
[246] | 27 | |
---|
[292] | 28 | GWt_elementLigneFaisceau::GWt_elementLigneFaisceau(PspaApplication* pspa) |
---|
[379] | 29 | : WContainerWidget(), |
---|
| 30 | firstTimeInsertMessage_(NULL), |
---|
| 31 | dropZoneLeft_(NULL), |
---|
| 32 | dropZoneRight_(NULL), |
---|
| 33 | GWt_abstractElement_(NULL), |
---|
| 34 | elementLabel_(NULL), |
---|
| 35 | pspa_(pspa) |
---|
[178] | 36 | { |
---|
[418] | 37 | initialize_ligneFaisceau(nomdElements::inconnu); |
---|
[178] | 38 | } |
---|
| 39 | |
---|
[305] | 40 | |
---|
[418] | 41 | GWt_elementLigneFaisceau::GWt_elementLigneFaisceau(nomdElements::typedElement type,PspaApplication* pspa) |
---|
[379] | 42 | : WContainerWidget(), |
---|
| 43 | firstTimeInsertMessage_(NULL), |
---|
| 44 | dropZoneLeft_(NULL), |
---|
| 45 | dropZoneRight_(NULL), |
---|
| 46 | GWt_abstractElement_(NULL), |
---|
| 47 | elementLabel_(NULL), |
---|
| 48 | pspa_(pspa) |
---|
[178] | 49 | { |
---|
[379] | 50 | // set the css name |
---|
| 51 | setObjectName("elementLigneFaisceau"); |
---|
| 52 | initialize_ligneFaisceau(type); |
---|
[178] | 53 | } |
---|
| 54 | |
---|
[418] | 55 | void GWt_elementLigneFaisceau::initialize_ligneFaisceau(nomdElements::typedElement eType) |
---|
[379] | 56 | { |
---|
| 57 | cout<<"new GWt_elementLigneFaisceau : "<< this << endl; |
---|
[248] | 58 | |
---|
[379] | 59 | // set layout |
---|
| 60 | // +----------+--------+---------+ |
---|
| 61 | // | (--->) | ELEM | (-----) | |
---|
| 62 | // +----------+--------+---------+ |
---|
| 63 | |
---|
| 64 | WGridLayout *gridLayout = new WGridLayout(); |
---|
[248] | 65 | |
---|
[379] | 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 |
---|
[272] | 93 | |
---|
[379] | 94 | switch ( eType ) { |
---|
[418] | 95 | case nomdElements::RFgun : |
---|
[379] | 96 | GWt_abstractElement_ = new GWt_rfgun(this); |
---|
| 97 | break; |
---|
[418] | 98 | case nomdElements::drift : |
---|
[379] | 99 | GWt_abstractElement_ = new GWt_drift(this); |
---|
| 100 | break; |
---|
[418] | 101 | case nomdElements::cell : |
---|
[379] | 102 | GWt_abstractElement_ = new GWt_cell(this); |
---|
| 103 | break; |
---|
[418] | 104 | case nomdElements::bend : |
---|
[379] | 105 | GWt_abstractElement_ = new GWt_bend(this); |
---|
| 106 | break; |
---|
[418] | 107 | case nomdElements::soleno : |
---|
[379] | 108 | GWt_abstractElement_ = new GWt_soleno(this); |
---|
| 109 | break; |
---|
[418] | 110 | case nomdElements::beam : |
---|
[379] | 111 | GWt_abstractElement_ = new GWt_beam(this); |
---|
| 112 | break; |
---|
[418] | 113 | case nomdElements::fit : |
---|
[379] | 114 | GWt_abstractElement_ = new GWt_fit(this); |
---|
| 115 | break; |
---|
[418] | 116 | case nomdElements::snapshot : |
---|
[379] | 117 | { |
---|
| 118 | int incr = pspa_->getExtensionFile(); |
---|
| 119 | incr++; |
---|
| 120 | pspa_->setExtensionFile(incr); |
---|
| 121 | GWt_abstractElement_ = new GWt_snapshot(this,incr); |
---|
| 122 | break; |
---|
[347] | 123 | } |
---|
[418] | 124 | case nomdElements::inconnu : |
---|
[379] | 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()); |
---|
[347] | 145 | } |
---|
[379] | 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(); |
---|
[382] | 152 | WHBoxLayout* hLayoutActions = new WHBoxLayout(); |
---|
[379] | 153 | actions->setStyleClass("beamLineElementActions"); |
---|
| 154 | actions->setPositionScheme(Wt::Static); |
---|
| 155 | |
---|
[382] | 156 | actions->setLayout(hLayoutActions); |
---|
| 157 | hLayoutActions->setContentsMargins(0,0,0,0); |
---|
[379] | 158 | |
---|
| 159 | actionParameters_ = new WText(" "); |
---|
| 160 | actionTrash_ = new WText(" "); |
---|
| 161 | |
---|
[365] | 162 | // set tooltips |
---|
[379] | 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 | |
---|
[382] | 178 | hLayoutActions->addWidget(actionParameters_); |
---|
| 179 | hLayoutActions->addWidget(actionTrash_); |
---|
[379] | 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); |
---|
[178] | 199 | } |
---|
| 200 | |
---|
[379] | 201 | GWt_elementLigneFaisceau::~GWt_elementLigneFaisceau() |
---|
| 202 | {} |
---|
[223] | 203 | |
---|
[379] | 204 | void GWt_elementLigneFaisceau::update() |
---|
[178] | 205 | { |
---|
[379] | 206 | if (getGWt_AbstractElement()->getAbstractElement()) { |
---|
| 207 | if (getGWt_AbstractElement()->getAbstractElement()->getAbstractSoftware()) { |
---|
[418] | 208 | // setBGColor(WColor(getGWt_AbstractElement()->getAbstractElement()->getAbstractSoftware()->getColor())); |
---|
| 209 | setBGColor(WColor(getGWt_AbstractElement()->getAbstractElement()->getAbstractSoftware()->getNomDeLogiciel()->getColor())); |
---|
[379] | 210 | softwareName_->setText(getGWt_AbstractElement()->getAbstractElement()->getAbstractSoftware()->getName()); |
---|
[401] | 211 | |
---|
| 212 | // no abstract software |
---|
| 213 | } else { |
---|
| 214 | setBGColor(WColor("#FFFFFF")); |
---|
| 215 | softwareName_->setText(""); |
---|
[375] | 216 | } |
---|
[379] | 217 | } |
---|
[375] | 218 | } |
---|
| 219 | |
---|
[347] | 220 | void GWt_elementLigneFaisceau::setBGColor(const WColor c) { |
---|
[379] | 221 | elementContainer_->decorationStyle().setBackgroundColor (c); |
---|
[347] | 222 | } |
---|
| 223 | |
---|
[265] | 224 | void GWt_elementLigneFaisceau::removeDone(GWt_abstractElement* gw) |
---|
[186] | 225 | { |
---|
[379] | 226 | if (messageDropZone_->result() == WDialog::Accepted) { |
---|
| 227 | // FIXME |
---|
| 228 | // removeDropZone(); |
---|
| 229 | } |
---|
[199] | 230 | } |
---|
[186] | 231 | |
---|
[343] | 232 | void GWt_elementLigneFaisceau::addElement(GWt_abstractElement* elem) |
---|
[359] | 233 | { |
---|
[379] | 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 | } |
---|
[359] | 242 | |
---|
[379] | 243 | firstTimeInsertMessage_ = NULL; |
---|
| 244 | dropZoneLeft_ = NULL; |
---|
[198] | 245 | } |
---|
| 246 | |
---|
[305] | 247 | |
---|
[379] | 248 | std::string GWt_elementLigneFaisceau::getElementNumberInBeamLine(nomdElements elem) |
---|
| 249 | { |
---|
| 250 | string str = ""; |
---|
[272] | 251 | |
---|
[379] | 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 "); |
---|
[272] | 267 | } |
---|
[379] | 268 | */ |
---|
[272] | 269 | |
---|
[379] | 270 | } |
---|
[198] | 271 | } |
---|
| 272 | |
---|
[379] | 273 | int n = 999999; |
---|
| 274 | |
---|
| 275 | std::stringstream stream; |
---|
| 276 | stream << n ; |
---|
| 277 | std::string number(stream.str()); |
---|
| 278 | |
---|
| 279 | if(n < 10) { |
---|
[418] | 280 | str= elem.getGenericLabel()+"0"+number; |
---|
[379] | 281 | } else { |
---|
[418] | 282 | str= elem.getGenericLabel()+number; |
---|
[379] | 283 | } |
---|
| 284 | } |
---|
| 285 | |
---|
| 286 | return str; |
---|
[198] | 287 | } |
---|
[264] | 288 | |
---|
[305] | 289 | |
---|
| 290 | void GWt_elementLigneFaisceau::setElementLabel(std::string label) { |
---|
[379] | 291 | if (elementLabel_) { |
---|
| 292 | elementLabel_->setText(label.substr(0,10)); |
---|
| 293 | elementLabel_->setToolTip(label); |
---|
| 294 | } |
---|
[264] | 295 | } |
---|
[365] | 296 | |
---|
| 297 | |
---|
| 298 | void GWt_elementLigneFaisceau::mouseWentOut() { |
---|
[379] | 299 | actionParameters_->setStyleClass("Button WhiteButton HiddenButton parameters"); |
---|
| 300 | actionTrash_->setStyleClass("Button WhiteButton HiddenButton trash"); |
---|
[365] | 301 | } |
---|
| 302 | |
---|
| 303 | |
---|
| 304 | void GWt_elementLigneFaisceau::mouseWentOver() { |
---|
[379] | 305 | actionParameters_->setStyleClass("Button WhiteButton ContrastButton parameters"); |
---|
| 306 | actionTrash_->setStyleClass("Button WhiteButton ContrastButton trash"); |
---|
[369] | 307 | } |
---|