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

Last change on this file since 449 was 449, checked in by garnier, 11 years ago

Modifications en vue de changer l'interface utilisateur

File size: 8.4 KB
Line 
1#include <iostream>
2
3#include "GWt_elementLigneFaisceau.h"
4#include "GWt_ligneFaisceau.h"
5
6#include "nomDeLogiciel.h"
7
8#include "mixedTools.h"
9
10#include <Wt/WVBoxLayout>
11
12
13GWt_LigneFaisceau::GWt_LigneFaisceau(PspaApplication* ps) :
14  WContainerWidget(),
15  pspa_(ps)
16{
17 
18  ligneFaisceauLayout_ = new WHBoxLayout();
19  ligneFaisceauLayout_->setContentsMargins(0,0,0,0);
20  ligneFaisceauLayout_->setSpacing(0);
21 
22  setLayout(ligneFaisceauLayout_);
23
24  // set the object name
25  setObjectName("ligneFaisceau");
26  clear();
27}
28
29
30void GWt_LigneFaisceau::clear() 
31{
32  ligneFaisceauLayout_->clear();
33
34  // add the first drop zone
35  decorationStyle().setBorder (WBorder (WBorder::Dotted));
36  allDropZone_ = new GWt_dropZoneLigneFaisceau(pspa_,this);
37  WVBoxLayout* fit = new WVBoxLayout();
38  allDropZone_->setLayout(fit);
39 
40  fit->addWidget(new WText("Drag elements here...."),1,Wt::AlignCenter |Wt::AlignMiddle);
41  ligneFaisceauLayout_->addWidget(allDropZone_,1);
42}
43
44
45GWt_abstractElement* GWt_LigneFaisceau::addElement(nomdElements::typedElement eType){
46  return addElement(eType,NULL);
47}
48
49GWt_abstractElement* GWt_LigneFaisceau::addElement(nomdElements::typedElement eType, GWt_dropZoneLigneFaisceau* dropContainer )
50{
51
52  GWt_abstractElement* GWtAbstractElem = NULL; 
53  cout << " addElement::element : " << nomdElements::getLabelFromType(eType) << endl;
54   
55  // 3 cases :
56  // -dropContainer is an element of the ligneFaisceauLayout_
57  // -dropContainer is an element of the GWt_elementLigneFaisceau_
58  // -dropContainer is NULL, insert in the last element
59 
60  if(eType == nomdElements::inconnu) {
61    cout << "GWt_LigneFaisceau::element type " << eType << " inconnu " << endl;
62    return NULL;
63  }
64 
65  // add the element to the datamanager
66 
67  // first time we insert an element :
68  GWt_elementLigneFaisceau* firstElemIsElement = dynamic_cast <GWt_elementLigneFaisceau*> (ligneFaisceauLayout_->itemAt(0)->widget());
69
70  if( (ligneFaisceauLayout_->count() == 1) && (!firstElemIsElement) ) {
71    int index = indexOf(dropContainer);
72    if( (index != -1) || (dropContainer == NULL) ) { // found
73      // remove global drop zone
74      ligneFaisceauLayout_->clear();
75      // add first element
76      GWt_elementLigneFaisceau* elemLigneFaisceau = new GWt_elementLigneFaisceau(eType,pspa_,this);
77      ligneFaisceauLayout_->addWidget(elemLigneFaisceau,1);
78      GWtAbstractElem = elemLigneFaisceau->getGWt_AbstractElement();
79      // remove arrow from begin and end
80     
81    } else { // error
82      return NULL;
83    }
84  } else {
85    int index = -1;
86    for (int a=0; a< ligneFaisceauLayout_->count(); a++) {
87      GWt_elementLigneFaisceau* elem = static_cast <GWt_elementLigneFaisceau*> (ligneFaisceauLayout_->itemAt(a)->widget ());
88      if (elem) {
89        if (elem->getDropZoneLeft() == dropContainer) {
90          index = a;
91        }
92        if (elem->getDropZoneRight() == dropContainer) {
93          index = a+1;
94        }
95      }
96     
97    }
98   
99    //  ligneFaisceauLayout_->addWidget(new GWt_elementLigneFaiseau(ptr),0);
100    GWt_elementLigneFaisceau* elemLigneFaisceau = new GWt_elementLigneFaisceau(eType, pspa_,this);
101    if (index != -1) {
102      ligneFaisceauLayout_->insertWidget(index,elemLigneFaisceau,1);
103      GWtAbstractElem = elemLigneFaisceau->getGWt_AbstractElement();
104    } else {
105      ligneFaisceauLayout_->addWidget(elemLigneFaisceau,1);
106      GWtAbstractElem = elemLigneFaisceau->getGWt_AbstractElement();
107    }
108  }
109  manageLineFaisceauLayout();
110 
111  return GWtAbstractElem;
112}
113
114
115void GWt_LigneFaisceau::manageLineFaisceauLayout() {
116  // special : hide/setVisible arrow :
117  for (int a=0; a< ligneFaisceauLayout_->count(); a++) {
118    if (GWt_elementLigneFaisceau* elem = dynamic_cast <GWt_elementLigneFaisceau*> (ligneFaisceauLayout_->itemAt(a)->widget ())) {
119     
120      // update labels
121      if (elem->getGWt_AbstractElement()) { 
122          elem->getGWt_AbstractElement()->updateLabelAndToolTipWidget();
123        }
124      //  one element
125      if ((a == 0) && (a == (ligneFaisceauLayout_->count()-1))) {
126        elem->getDropZoneLeft()->setStyleClass("elementLigneFaiseau_transparent");
127        elem->getDropZoneRight()->setStyleClass("elementLigneFaiseau_transparent");
128       
129        // first
130      } else if (a == 0){
131        elem->getDropZoneLeft()->setStyleClass("elementLigneFaiseau_transparent");
132        elem->getDropZoneRight()->setStyleClass("elementLigneFaiseau_line");
133       
134        // last
135      } else if (a == (ligneFaisceauLayout_->count()-1)){
136        elem->getDropZoneLeft()->setStyleClass("elementLigneFaiseau_line");
137        elem->getDropZoneRight()->setStyleClass("elementLigneFaiseau_transparent");
138       
139       
140        // middle elements
141      } else {
142        elem->getDropZoneLeft()->setStyleClass("elementLigneFaiseau_line");
143        elem->getDropZoneRight()->setStyleClass("elementLigneFaiseau_line");
144      }
145    }
146  }
147 
148  // insure that there is still the dropzone !
149  if (ligneFaisceauLayout_->count() == 0) {
150    clear();
151  }
152 
153  pspa_->getExecuteWidget()->updateSections();
154}
155
156
157
158void GWt_LigneFaisceau::update() {
159  manageLineFaisceauLayout();
160}
161
162
163void GWt_LigneFaisceau::removeElement(GWt_abstractElement* GWt_abstractElement) {
164  if (GWt_abstractElement == NULL)
165    return;
166 
167  // remove Widget
168  // - GWt_abstractElement is an element of the GWt_elementLigneFaisceau_
169 
170  int index = -1;
171  for (int a=0; a< ligneFaisceauLayout_->count(); a++) {
172    GWt_elementLigneFaisceau* elem = static_cast <GWt_elementLigneFaisceau*> (ligneFaisceauLayout_->itemAt(a)->widget ());
173    if (elem) {
174      if (elem->getGWt_AbstractElement() == GWt_abstractElement) {
175        index = a;
176      }
177    }
178  }
179 
180  if (index != -1) {
181    // remove element from the list
182    //        pspa_->getDataManager()->removeElement(GWt_abstractElement->getElement()->getLabel());
183   
184    ligneFaisceauLayout_->removeItem(ligneFaisceauLayout_->itemAt(index));
185    delete GWt_abstractElement;
186   
187    // manage widgets if necessary
188    manageLineFaisceauLayout();
189  }
190}
191
192
193abstractElement* GWt_LigneFaisceau::getAbstractElement(int i){
194    int index = 0;
195    if (i < 0) {
196        return NULL;
197    }
198   
199    for (int a=0; a< ligneFaisceauLayout_->count(); a++) {
200        if (ligneFaisceauLayout_->itemAt(a)) {
201           
202            if (GWt_elementLigneFaisceau* elem = dynamic_cast <GWt_elementLigneFaisceau*> (ligneFaisceauLayout_->itemAt(a)->widget ())) {
203                if (index == i) {
204                    if (elem->getGWt_AbstractElement()) {
205                        return elem->getGWt_AbstractElement()->getAbstractElement();
206                    }
207                }
208                index ++;
209            }
210        }
211    }
212    return NULL;
213}
214
215
216
217int GWt_LigneFaisceau::getAbstractElementNumeroFromLabel(std::string txt){
218    int index = 1;
219    if (txt == "") {
220        return NULL;
221    }
222   
223    for (int a=0; a< ligneFaisceauLayout_->count(); a++) {
224        if (ligneFaisceauLayout_->itemAt(a)) {
225           
226            if (GWt_elementLigneFaisceau* elem = dynamic_cast <GWt_elementLigneFaisceau*> (ligneFaisceauLayout_->itemAt(a)->widget ())) {
227                if (elem->getGWt_AbstractElement()) {
228                    if (elem->getGWt_AbstractElement()->getAbstractElement()->getLabel() == txt) {
229                        return index;
230                    }
231                }
232                index ++;
233            }
234        }
235    }
236    return NULL;
237   
238}
239
240
241
242
243int GWt_LigneFaisceau::getBeamLineSize() {
244  int count = 0;
245  for (int a=0; a< ligneFaisceauLayout_->count(); a++) {
246    if (dynamic_cast <GWt_elementLigneFaisceau*> (ligneFaisceauLayout_->itemAt(a)->widget ())) {
247      count ++;
248    }
249  }
250  return count;
251}
252
253
254vector <abstractElement*> GWt_LigneFaisceau::getAllAbstractElements()
255{
256  vector <abstractElement*> elems;
257  for (int a=0; a< ligneFaisceauLayout_->count(); a++) {
258    if (GWt_elementLigneFaisceau* elem = dynamic_cast <GWt_elementLigneFaisceau*> (ligneFaisceauLayout_->itemAt(a)->widget ())) {
259      elems.push_back(elem->getGWt_AbstractElement()->getAbstractElement());
260    }
261  }
262  return elems;
263}
264
265void GWt_LigneFaisceau::update(int i){
266    int index = 0;
267   
268    // first if 1
269    //    i--;
270   
271    for (int a=0; a< ligneFaisceauLayout_->count(); a++) {
272        if (GWt_elementLigneFaisceau* elem = dynamic_cast <GWt_elementLigneFaisceau*> (ligneFaisceauLayout_->itemAt(a)->widget ())) {
273            if (index == i) {
274                elem->update();
275            }
276            index ++;
277        }
278    }
279}
280
281
282void GWt_LigneFaisceau::initializeSoftwares()
283{   
284  vector <abstractElement*> elems = getAllAbstractElements();
285  cout << "GWt_LigneFaisceau::initializeSoftwares() " << elems.size() << endl;
286
287  for (int a = 0; a < elems.size(); a++) {
288    elems[a]->setSoftware( NULL );
289  }
290}
291
292
Note: See TracBrowser for help on using the repository browser.