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

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

Affichage du nom du cas test dans le titre de la fenetre + see History

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