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

Last change on this file since 431 was 431, checked in by touze, 11 years ago

systeme periodique (mailles) + multipoles + madx

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