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

Last change on this file since 379 was 379, checked in by touze, 12 years ago

ajout d'une extension de fichier pour les cliches

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