source: PSPA/Interface_Web/trunk/pspaWT/sources/userInterface/src/GWt_ligneFaisceau.cc @ 481

Last change on this file since 481 was 481, checked in by garnier, 10 years ago

Suppression de methodes deprecated et de quelques warning de compilation

File size: 9.1 KB
Line 
1#include <iostream>
2
3#include "GWt_elementLigneFaisceau.h"
4#include "GWt_ligneFaisceau.h"
5#include "GWt_sector.h"
6#include "abstractElement.h"
7#include "nomDeLogiciel.h"
8
9#include "mixedTools.h"
10
11#include <Wt/WVBoxLayout>
12
13
14GWt_ligneFaisceau::GWt_ligneFaisceau(dataManager* data,GWt_sector* sect) :
15WContainerWidget(),
16dataManager_(data),
17UI_sector_(sect)
18{
19 
20  ligneFaisceauLayout_ = new WHBoxLayout();
21  ligneFaisceauLayout_->setContentsMargins(0,0,0,0);
22  ligneFaisceauLayout_->setSpacing(0);
23 
24  setLayout(ligneFaisceauLayout_);
25
26  // set the object name
27  setObjectName("ligneFaisceau");
28  buildBeamLineWidget();
29}
30
31
32void GWt_ligneFaisceau::clear() 
33{
34  ligneFaisceauLayout_->clear();
35
36  // add the first drop zone
37  decorationStyle().setBorder (WBorder (WBorder::Dotted));
38  allDropZone_ = new GWt_dropZoneLigneFaisceau(dataManager_,this);
39  WVBoxLayout* fit = new WVBoxLayout();
40  allDropZone_->setLayout(fit);
41 
42  fit->addWidget(new WText("Drag elements here...."),1,Wt::AlignCenter |Wt::AlignMiddle);
43  ligneFaisceauLayout_->addWidget(allDropZone_,1);
44}
45
46
47GWt_abstractElement* GWt_ligneFaisceau::addElement(nomdElements::typedElement eType){
48  return addElement(eType,NULL);
49}
50
51GWt_abstractElement* GWt_ligneFaisceau::addElement(nomdElements::typedElement eType, GWt_dropZoneLigneFaisceau* dropContainer )
52{
53 
54 
55  GWt_abstractElement* UIabstractElement = NULL;
56 
57  // Add this element to the DataManager
58
59  // create a new abstractElement
60    // FIXME : To be move in an abstractFactory in the controler !!
61    abstractElement* currentElement = NULL;
62    switch (  eType ) {
63      case nomdElements::RFgun :
64        currentElement = new elementRfgun();
65        break;
66      case nomdElements::drift :
67        currentElement = new elementDrift();
68        break;
69      case nomdElements::cell  :
70        currentElement = new elementCell();
71        break;
72      case nomdElements::bend  :
73        currentElement = new elementBend();
74        break;
75      case nomdElements::soleno  :
76        currentElement = new elementSoleno();
77        break;
78      case nomdElements::beam  :
79        currentElement = new elementBeam();
80        break;
81      case nomdElements::fit  :
82        currentElement = new elementFit();
83        break;
84      case nomdElements::mpole  :
85        currentElement = new elementMultipole();
86        break;
87      case nomdElements::snapshot :
88      {
89        // FIXME : Snapshot a gérér
90/*        int incr = dataManager_->getPspaApplication()->getExtensionFile();
91        incr++;
92        dataManager_->getPspaApplication()->setExtensionFile(incr);
93*/
94        currentElement = new elementSnapshot();
95        break;
96      }
97    }
98
99   
100    // look for the previous element
101    abstractElement* previousElement = NULL;
102   
103    for (int a=0; a< ligneFaisceauLayout_->count(); a++) {
104      GWt_elementLigneFaisceau* elem = static_cast <GWt_elementLigneFaisceau*> (ligneFaisceauLayout_->itemAt(a)->widget ());
105      if (elem) {
106        if (elem->getDropZoneRight() == dropContainer) {
107          previousElement = elem->getGWt_AbstractElement()->getAbstractElement();
108        }
109      }
110    }
111
112    getUISector()->getSectorControler()->addElementAfter(currentElement,previousElement );
113 
114  buildBeamLineWidget();
115  getUISector()->getExecuteWidget()->displayFromControler();
116
117  return UIabstractElement;
118
119}
120
121
122void GWt_ligneFaisceau::manageLineFaisceauLayout_deprecated() {
123  // special : hide/setVisible arrow :
124  for (int a=0; a< ligneFaisceauLayout_->count(); a++) {
125    if (GWt_elementLigneFaisceau* elem = dynamic_cast <GWt_elementLigneFaisceau*> (ligneFaisceauLayout_->itemAt(a)->widget ())) {
126     
127      // update labels
128      if (elem->getGWt_AbstractElement()) { 
129          elem->getGWt_AbstractElement()->updateLabelAndToolTipWidget();
130        }
131      //  one element
132      if ((a == 0) && (a == (ligneFaisceauLayout_->count()-1))) {
133        elem->getDropZoneLeft()->setStyleClass("elementLigneFaiseau_transparent");
134        elem->getDropZoneRight()->setStyleClass("elementLigneFaiseau_transparent");
135       
136        // first
137      } else if (a == 0){
138        elem->getDropZoneLeft()->setStyleClass("elementLigneFaiseau_transparent");
139        elem->getDropZoneRight()->setStyleClass("elementLigneFaiseau_line");
140       
141        // last
142      } else if (a == (ligneFaisceauLayout_->count()-1)){
143        elem->getDropZoneLeft()->setStyleClass("elementLigneFaiseau_line");
144        elem->getDropZoneRight()->setStyleClass("elementLigneFaiseau_transparent");
145       
146       
147        // middle elements
148      } else {
149        elem->getDropZoneLeft()->setStyleClass("elementLigneFaiseau_line");
150        elem->getDropZoneRight()->setStyleClass("elementLigneFaiseau_line");
151      }
152    }
153  }
154 
155  // insure that there is still the dropzone !
156  if (ligneFaisceauLayout_->count() == 0) {
157    clear();
158  }
159 
160  // FIXME
161  UI_sector_->getExecuteWidget()->updateSections();
162}
163
164
165void GWt_ligneFaisceau::buildBeamLineWidget() {
166  // clear the layout and set default text
167  clear();
168  bool first = true;
169
170  // Get the dataManager's sector
171  // rebuild the beamLine
172
173  GWt_elementLigneFaisceau* elemLigneFaisceau = NULL;
174  for (unsigned int i =0; i< UI_sector_->getSectorControler()->getSectionsToExecute().size(); i++) {
175    std::vector <abstractElement*> abstractElem = UI_sector_->getSectorControler()->getSectionsToExecute()[i]->getElements();
176    for (unsigned int j=0; j< abstractElem.size(); j++) {
177
178      elemLigneFaisceau = new GWt_elementLigneFaisceau(dataManager_,
179                                                       this,
180                                                       abstractElem[j],UI_sector_->getSectorControler()->getSectionsToExecute()[i]->getSoftware()->getColor());
181     
182      // remove default text
183      if (first) {
184        first = false;
185        ligneFaisceauLayout_->clear();
186        ligneFaisceauLayout_->addWidget(elemLigneFaisceau);
187
188        elemLigneFaisceau->getDropZoneLeft()->setStyleClass("elementLigneFaiseau_transparent");
189        elemLigneFaisceau->getDropZoneRight()->setStyleClass("elementLigneFaiseau_line");
190     
191      } else {
192        ligneFaisceauLayout_->addWidget(elemLigneFaisceau);
193
194        elemLigneFaisceau->getDropZoneLeft()->setStyleClass( "elementLigneFaiseau_line");
195        elemLigneFaisceau->getDropZoneRight()->setStyleClass("elementLigneFaiseau_line");
196      }
197     
198    }
199  }
200  // remove last line
201  if (elemLigneFaisceau != NULL) {
202    elemLigneFaisceau->getDropZoneRight()->setStyleClass("elementLigneFaiseau_transparent");
203  }
204 
205}
206
207
208void GWt_ligneFaisceau::update() {
209  manageLineFaisceauLayout_deprecated();
210}
211
212
213void GWt_ligneFaisceau::removeElement(GWt_abstractElement* GWt_abstractElement) {
214  if (GWt_abstractElement == NULL)
215    return;
216 
217  // remove Widget
218  // - GWt_abstractElement is an element of the GWt_elementLigneFaisceau_
219 
220  int index = -1;
221  for (int a=0; a< ligneFaisceauLayout_->count(); a++) {
222    GWt_elementLigneFaisceau* elem = static_cast <GWt_elementLigneFaisceau*> (ligneFaisceauLayout_->itemAt(a)->widget ());
223    if (elem) {
224      if (elem->getGWt_AbstractElement() == GWt_abstractElement) {
225        index = a;
226      }
227    }
228  }
229 
230  if (index != -1) {
231    // remove element from the list
232    //        pspa_->getDataManager()->removeElement(GWt_abstractElement->getElement()->getLabel());
233   
234    ligneFaisceauLayout_->removeItem(ligneFaisceauLayout_->itemAt(index));
235    delete GWt_abstractElement;
236   
237    // manage widgets if necessary
238    manageLineFaisceauLayout_deprecated();
239  }
240}
241
242
243abstractElement* GWt_ligneFaisceau::getAbstractElement(int i){
244    int index = 0;
245    if (i < 0) {
246        return NULL;
247    }
248   
249    for (int a=0; a< ligneFaisceauLayout_->count(); a++) {
250        if (ligneFaisceauLayout_->itemAt(a)) {
251           
252            if (GWt_elementLigneFaisceau* elem = dynamic_cast <GWt_elementLigneFaisceau*> (ligneFaisceauLayout_->itemAt(a)->widget ())) {
253              if (index == i) {
254                if (elem->getGWt_AbstractElement()) {
255                  return elem->getGWt_AbstractElement()->getAbstractElement();
256                }
257           }
258             index ++;
259        }
260    }
261  }
262  return NULL;
263}
264
265
266
267int GWt_ligneFaisceau::getAbstractElementNumeroFromLabel(std::string txt){
268  int index = 1;
269  if (txt == "") {
270    return NULL;
271  }
272 
273  for (int a=0; a< ligneFaisceauLayout_->count(); a++) {
274    if (ligneFaisceauLayout_->itemAt(a)) {
275     
276      if (GWt_elementLigneFaisceau* elem = dynamic_cast <GWt_elementLigneFaisceau*> (ligneFaisceauLayout_->itemAt(a)->widget ())) {
277        if (elem->getGWt_AbstractElement()) {
278          if (elem->getGWt_AbstractElement()->getAbstractElement()->getLabel() == txt) {
279            return index;
280          }
281        }
282        index ++;
283      }
284    }
285  }
286  return NULL;
287 
288}
289
290
291
292
293int GWt_ligneFaisceau::getBeamLineSize() {
294  int count = 0;
295  for (int a=0; a< ligneFaisceauLayout_->count(); a++) {
296    if (dynamic_cast <GWt_elementLigneFaisceau*> (ligneFaisceauLayout_->itemAt(a)->widget ())) {
297      count ++;
298    }
299  }
300  return count;
301}
302
303
304vector <abstractElement*> GWt_ligneFaisceau::getAllAbstractElements()
305{
306  vector <abstractElement*> elems;
307  for (int a=0; a< ligneFaisceauLayout_->count(); a++) {
308    if (GWt_elementLigneFaisceau* elem = dynamic_cast <GWt_elementLigneFaisceau*> (ligneFaisceauLayout_->itemAt(a)->widget ())) {
309      elems.push_back(elem->getGWt_AbstractElement()->getAbstractElement());
310    }
311  }
312  return elems;
313}
Note: See TracBrowser for help on using the repository browser.