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

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

Correction d'un bug. La suppression d'un

élément est désormais effective

File size: 7.9 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, GWt_dropZoneLigneFaisceau* dropContainer )
48{
49 
50  GWt_abstractElement* UIabstractElement = NULL;
51 
52  // Add this element to the DataManager
53  // look for the previous element
54  abstractElement* previousElement = NULL;
55 
56  for (int a=0; a< ligneFaisceauLayout_->count(); a++) {
57    GWt_elementLigneFaisceau* elem = static_cast <GWt_elementLigneFaisceau*> (ligneFaisceauLayout_->itemAt(a)->widget ());
58    if (elem) {
59      if (elem->getDropZoneRight() == dropContainer) {
60        previousElement = elem->getGWt_AbstractElement()->getAbstractElement();
61      }
62    }
63  }
64 
65  getUISector()->getSectorControler()->addElementAfter(eType,previousElement );
66 
67  buildBeamLineWidget();
68  getUISector()->getExecuteWidget()->displayFromControler();
69
70  return UIabstractElement;
71
72}
73
74
75void GWt_ligneFaisceau::manageLineFaisceauLayout_deprecated() {
76  // special : hide/setVisible arrow :
77  for (int a=0; a< ligneFaisceauLayout_->count(); a++) {
78    if (GWt_elementLigneFaisceau* elem = dynamic_cast <GWt_elementLigneFaisceau*> (ligneFaisceauLayout_->itemAt(a)->widget ())) {
79     
80      // update labels
81      if (elem->getGWt_AbstractElement()) { 
82          elem->getGWt_AbstractElement()->updateLabelAndToolTipWidget();
83        }
84      //  one element
85      if ((a == 0) && (a == (ligneFaisceauLayout_->count()-1))) {
86        elem->getDropZoneLeft()->setStyleClass("elementLigneFaiseau_transparent");
87        elem->getDropZoneRight()->setStyleClass("elementLigneFaiseau_transparent");
88       
89        // first
90      } else if (a == 0){
91        elem->getDropZoneLeft()->setStyleClass("elementLigneFaiseau_transparent");
92        elem->getDropZoneRight()->setStyleClass("elementLigneFaiseau_line");
93       
94        // last
95      } else if (a == (ligneFaisceauLayout_->count()-1)){
96        elem->getDropZoneLeft()->setStyleClass("elementLigneFaiseau_line");
97        elem->getDropZoneRight()->setStyleClass("elementLigneFaiseau_transparent");
98       
99       
100        // middle elements
101      } else {
102        elem->getDropZoneLeft()->setStyleClass("elementLigneFaiseau_line");
103        elem->getDropZoneRight()->setStyleClass("elementLigneFaiseau_line");
104      }
105    }
106  }
107 
108  // insure that there is still the dropzone !
109  if (ligneFaisceauLayout_->count() == 0) {
110    clear();
111  }
112 
113  // FIXME
114  UI_sector_->getExecuteWidget()->updateSections();
115}
116
117
118void GWt_ligneFaisceau::buildBeamLineWidget() {
119  // clear the layout and set default text
120  clear();
121  bool first = true;
122
123  // Get the dataManager's sector
124  // rebuild the beamLine
125
126  GWt_elementLigneFaisceau* elemLigneFaisceau = NULL;
127  for (unsigned int i =0; i< UI_sector_->getSectorControler()->getSectionsToExecute().size(); i++) {
128    std::vector <abstractElement*> abstractElem = UI_sector_->getSectorControler()->getSectionsToExecute()[i]->getElements();
129    for (unsigned int j=0; j< abstractElem.size(); j++) {
130
131      elemLigneFaisceau = new GWt_elementLigneFaisceau(dataManager_,
132                                                       this,
133                                                       abstractElem[j],UI_sector_->getSectorControler()->getSectionsToExecute()[i]->getSoftware()->getColor());
134     
135      // remove default text
136      if (first) {
137        first = false;
138        ligneFaisceauLayout_->clear();
139        ligneFaisceauLayout_->addWidget(elemLigneFaisceau);
140
141        elemLigneFaisceau->getDropZoneLeft()->setStyleClass("elementLigneFaiseau_transparent");
142        elemLigneFaisceau->getDropZoneRight()->setStyleClass("elementLigneFaiseau_line");
143     
144      } else {
145        ligneFaisceauLayout_->addWidget(elemLigneFaisceau);
146
147        elemLigneFaisceau->getDropZoneLeft()->setStyleClass( "elementLigneFaiseau_line");
148        elemLigneFaisceau->getDropZoneRight()->setStyleClass("elementLigneFaiseau_line");
149      }
150     
151    }
152  }
153  // remove last line
154  if (elemLigneFaisceau != NULL) {
155    elemLigneFaisceau->getDropZoneRight()->setStyleClass("elementLigneFaiseau_transparent");
156  }
157 
158}
159
160
161void GWt_ligneFaisceau::update() {
162  manageLineFaisceauLayout_deprecated();
163}
164
165
166void GWt_ligneFaisceau::removeElement(GWt_abstractElement* GWt_abstractElement) {
167  if (GWt_abstractElement == NULL)
168    return;
169 
170  getUISector()->getSectorControler()->removeElement(GWt_abstractElement->getAbstractElement());
171 
172  buildBeamLineWidget();
173  getUISector()->getExecuteWidget()->displayFromControler();
174/*
175  // remove Widget
176  // - GWt_abstractElement is an element of the GWt_elementLigneFaisceau_
177 
178  int index = -1;
179  for (int a=0; a< ligneFaisceauLayout_->count(); a++) {
180    GWt_elementLigneFaisceau* elem = static_cast <GWt_elementLigneFaisceau*> (ligneFaisceauLayout_->itemAt(a)->widget ());
181    if (elem) {
182      if (elem->getGWt_AbstractElement() == GWt_abstractElement) {
183        index = a;
184      }
185    }
186  }
187 
188  if (index != -1) {
189    // remove element from the list
190    //        pspa_->getDataManager()->removeElement(GWt_abstractElement->getElement()->getLabel());
191   
192    ligneFaisceauLayout_->removeItem(ligneFaisceauLayout_->itemAt(index));
193    delete GWt_abstractElement;
194   
195    // manage widgets if necessary
196    manageLineFaisceauLayout_deprecated();
197  }
198*/
199}
200
201
202abstractElement* GWt_ligneFaisceau::getAbstractElement(int i){
203    int index = 0;
204    if (i < 0) {
205        return NULL;
206    }
207   
208    for (int a=0; a< ligneFaisceauLayout_->count(); a++) {
209        if (ligneFaisceauLayout_->itemAt(a)) {
210           
211            if (GWt_elementLigneFaisceau* elem = dynamic_cast <GWt_elementLigneFaisceau*> (ligneFaisceauLayout_->itemAt(a)->widget ())) {
212              if (index == i) {
213                if (elem->getGWt_AbstractElement()) {
214                  return elem->getGWt_AbstractElement()->getAbstractElement();
215                }
216           }
217             index ++;
218        }
219    }
220  }
221  return NULL;
222}
223
224
225
226int GWt_ligneFaisceau::getAbstractElementNumeroFromLabel(std::string txt){
227  int index = 1;
228  if (txt == "") {
229    return NULL;
230  }
231 
232  for (int a=0; a< ligneFaisceauLayout_->count(); a++) {
233    if (ligneFaisceauLayout_->itemAt(a)) {
234     
235      if (GWt_elementLigneFaisceau* elem = dynamic_cast <GWt_elementLigneFaisceau*> (ligneFaisceauLayout_->itemAt(a)->widget ())) {
236        if (elem->getGWt_AbstractElement()) {
237          if (elem->getGWt_AbstractElement()->getAbstractElement()->getLabel() == txt) {
238            return index;
239          }
240        }
241        index ++;
242      }
243    }
244  }
245  return NULL;
246 
247}
248
249
250
251
252int GWt_ligneFaisceau::getBeamLineSize() {
253  int count = 0;
254  for (int a=0; a< ligneFaisceauLayout_->count(); a++) {
255    if (dynamic_cast <GWt_elementLigneFaisceau*> (ligneFaisceauLayout_->itemAt(a)->widget ())) {
256      count ++;
257    }
258  }
259  return count;
260}
261
262
263vector <abstractElement*> GWt_ligneFaisceau::getAllAbstractElements()
264{
265  vector <abstractElement*> elems;
266  for (int a=0; a< ligneFaisceauLayout_->count(); a++) {
267    if (GWt_elementLigneFaisceau* elem = dynamic_cast <GWt_elementLigneFaisceau*> (ligneFaisceauLayout_->itemAt(a)->widget ())) {
268      elems.push_back(elem->getGWt_AbstractElement()->getAbstractElement());
269    }
270  }
271  return elems;
272}
Note: See TracBrowser for help on using the repository browser.