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
RevLine 
[112]1#include <iostream>
2
[266]3#include "GWt_elementLigneFaisceau.h"
[255]4#include "GWt_ligneFaisceau.h"
[343]5
[401]6#include "nomDeLogiciel.h"
[167]7
[118]8#include "mixedTools.h"
[48]9
10#include <Wt/WVBoxLayout>
11
[167]12
[186]13GWt_LigneFaisceau::GWt_LigneFaisceau(PspaApplication* ps) :
[343]14  WContainerWidget(),
[379]15  pspa_(ps)
[48]16{
[343]17 
18  ligneFaisceauLayout_ = new WHBoxLayout();
19  ligneFaisceauLayout_->setContentsMargins(0,0,0,0);
20  ligneFaisceauLayout_->setSpacing(0);
21 
[401]22  setLayout(ligneFaisceauLayout_);
23
[343]24  // set the object name
[401]25  setObjectName("ligneFaisceau");
[343]26  clear();
[305]27}
28
29
[343]30void GWt_LigneFaisceau::clear() 
31{
32  ligneFaisceauLayout_->clear();
[305]33
[343]34  // add the first drop zone
35  decorationStyle().setBorder (WBorder (WBorder::Dotted));
[449]36  allDropZone_ = new GWt_dropZoneLigneFaisceau(pspa_,this);
[343]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);
[272]42}
[248]43
[256]44
[418]45GWt_abstractElement* GWt_LigneFaisceau::addElement(nomdElements::typedElement eType){
[343]46  return addElement(eType,NULL);
[48]47}
[167]48
[418]49GWt_abstractElement* GWt_LigneFaisceau::addElement(nomdElements::typedElement eType, GWt_dropZoneLigneFaisceau* dropContainer )
[343]50{
[248]51
[379]52  GWt_abstractElement* GWtAbstractElem = NULL; 
[431]53  cout << " addElement::element : " << nomdElements::getLabelFromType(eType) << endl;
[273]54   
[343]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 
[418]60  if(eType == nomdElements::inconnu) {
[343]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());
[379]69
70  if( (ligneFaisceauLayout_->count() == 1) && (!firstElemIsElement) ) {
71    int index = indexOf(dropContainer);
72    if( (index != -1) || (dropContainer == NULL) ) { // found
[343]73      // remove global drop zone
74      ligneFaisceauLayout_->clear();
75      // add first element
[449]76      GWt_elementLigneFaisceau* elemLigneFaisceau = new GWt_elementLigneFaisceau(eType,pspa_,this);
[343]77      ligneFaisceauLayout_->addWidget(elemLigneFaisceau,1);
78      GWtAbstractElem = elemLigneFaisceau->getGWt_AbstractElement();
79      // remove arrow from begin and end
80     
81    } else { // error
82      return NULL;
[273]83    }
[343]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    }
[299]98   
[343]99    //  ligneFaisceauLayout_->addWidget(new GWt_elementLigneFaiseau(ptr),0);
[449]100    GWt_elementLigneFaisceau* elemLigneFaisceau = new GWt_elementLigneFaisceau(eType, pspa_,this);
[343]101    if (index != -1) {
102      ligneFaisceauLayout_->insertWidget(index,elemLigneFaisceau,1);
103      GWtAbstractElem = elemLigneFaisceau->getGWt_AbstractElement();
[273]104    } else {
[343]105      ligneFaisceauLayout_->addWidget(elemLigneFaisceau,1);
106      GWtAbstractElem = elemLigneFaisceau->getGWt_AbstractElement();
[267]107    }
[343]108  }
109  manageLineFaisceauLayout();
110 
111  return GWtAbstractElem;
[284]112}
113
114
115void GWt_LigneFaisceau::manageLineFaisceauLayout() {
[343]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
[359]121      if (elem->getGWt_AbstractElement()) { 
122          elem->getGWt_AbstractElement()->updateLabelAndToolTipWidget();
123        }
[343]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      }
[282]145    }
[343]146  }
147 
148  // insure that there is still the dropzone !
149  if (ligneFaisceauLayout_->count() == 0) {
150    clear();
151  }
152 
[401]153  pspa_->getExecuteWidget()->updateSections();
[299]154}
155
156
[305]157
158void GWt_LigneFaisceau::update() {
[343]159  manageLineFaisceauLayout();
[305]160}
161
162
163void GWt_LigneFaisceau::removeElement(GWt_abstractElement* GWt_abstractElement) {
[343]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());
[282]183   
[343]184    ligneFaisceauLayout_->removeItem(ligneFaisceauLayout_->itemAt(index));
185    delete GWt_abstractElement;
[299]186   
[343]187    // manage widgets if necessary
188    manageLineFaisceauLayout();
189  }
[305]190}
191
192
193abstractElement* GWt_LigneFaisceau::getAbstractElement(int i){
[359]194    int index = 0;
195    if (i < 0) {
196        return NULL;
[305]197    }
[359]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;
[248]213}
214
[305]215
[418]216
217int GWt_LigneFaisceau::getAbstractElementNumeroFromLabel(std::string txt){
218    int index = 1;
[401]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
[418]241
242
[305]243int GWt_LigneFaisceau::getBeamLineSize() {
[343]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 ++;
[305]248    }
[343]249  }
250  return count;
[305]251}
252
[359]253
[343]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());
[305]260    }
[343]261  }
262  return elems;
[305]263}
264
[359]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) {
[375]274                elem->update();
[359]275            }
276            index ++;
277        }
278    }
279}
280
[401]281
[431]282void GWt_LigneFaisceau::initializeSoftwares()
283{   
[401]284  vector <abstractElement*> elems = getAllAbstractElements();
[431]285  cout << "GWt_LigneFaisceau::initializeSoftwares() " << elems.size() << endl;
286
287  for (int a = 0; a < elems.size(); a++) {
288    elems[a]->setSoftware( NULL );
289  }
[401]290}
291
292
Note: See TracBrowser for help on using the repository browser.