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

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

Renommage de toutes les classes d’élément dans le GWt_ par GWt_elementXXX

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