source: PSPA/Interface_Web/branches/12_03_12-managerComboBox/pspaWT/sources/userInterface/src/GWt_ligneFaisceau.cc @ 397

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

Améliorations de l'interface graphique

File size: 8.6 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#include "nomDeLogiciel.h"
12
13#include "mixedTools.h"
14
15#include <Wt/WVBoxLayout>
16
17
18GWt_LigneFaisceau::GWt_LigneFaisceau(PspaApplication* ps) :
19  WContainerWidget(),
20  pspa_(ps)
21{
22 
23  cout<<"GWt_LigneFaisceau::GWt_LigneFaisceau() %d"<< this << "<---------------"<< endl;
24   
25  ligneFaisceauLayout_ = new WHBoxLayout();
26  //  decorationStyle().setBackgroundColor (WColor(245,245,245));
27  ligneFaisceauLayout_->setContentsMargins(0,0,0,0);
28  ligneFaisceauLayout_->setSpacing(0);
29 
30  setLayout(ligneFaisceauLayout_);
31
32  // set the object name
33  setObjectName("ligneFaisceau");
34  clear();
35}
36
37
38void GWt_LigneFaisceau::clear() 
39{
40  ligneFaisceauLayout_->clear();
41
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);
50}
51
52
53GWt_abstractElement* GWt_LigneFaisceau::addElement(typedElement eType){
54  return addElement(eType,NULL);
55}
56
57GWt_abstractElement* GWt_LigneFaisceau::addElement(typedElement eType, GWt_dropZoneLigneFaisceau* dropContainer )
58{
59
60  GWt_abstractElement* GWtAbstractElem = NULL; 
61  cout << " Entree addElement element " << nomdElements::getLabelFromType(eType) << endl;
62   
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 
68  if(eType == inconnu) {
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());
77
78  if( (ligneFaisceauLayout_->count() == 1) && (!firstElemIsElement) ) {
79    int index = indexOf(dropContainer);
80    if( (index != -1) || (dropContainer == NULL) ) { // found
81      // remove global drop zone
82      ligneFaisceauLayout_->clear();
83      // add first element
84      GWt_elementLigneFaisceau* elemLigneFaisceau = new GWt_elementLigneFaisceau(eType,pspa_);
85      ligneFaisceauLayout_->addWidget(elemLigneFaisceau,1);
86      GWtAbstractElem = elemLigneFaisceau->getGWt_AbstractElement();
87      // remove arrow from begin and end
88     
89    } else { // error
90      return NULL;
91    }
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    }
106   
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();
112    } else {
113      ligneFaisceauLayout_->addWidget(elemLigneFaisceau,1);
114      GWtAbstractElem = elemLigneFaisceau->getGWt_AbstractElement();
115    }
116  }
117  manageLineFaisceauLayout();
118 
119  return GWtAbstractElem;
120}
121
122
123void GWt_LigneFaisceau::manageLineFaisceauLayout() {
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
129      if (elem->getGWt_AbstractElement()) { 
130          elem->getGWt_AbstractElement()->updateLabelAndToolTipWidget();
131        }
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      }
153    }
154  }
155 
156  // insure that there is still the dropzone !
157  if (ligneFaisceauLayout_->count() == 0) {
158    clear();
159  }
160 
161  pspa_->getExecuteWidget()->updateSections();
162}
163
164
165
166void GWt_LigneFaisceau::update() {
167  manageLineFaisceauLayout();
168}
169
170
171void GWt_LigneFaisceau::removeElement(GWt_abstractElement* GWt_abstractElement) {
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());
191   
192    ligneFaisceauLayout_->removeItem(ligneFaisceauLayout_->itemAt(index));
193    delete GWt_abstractElement;
194   
195    // manage widgets if necessary
196    manageLineFaisceauLayout();
197  }
198}
199
200
201abstractElement* GWt_LigneFaisceau::getAbstractElement(int i){
202    int index = 0;
203    if (i < 0) {
204        return NULL;
205    }
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;
221}
222
223
224int GWt_LigneFaisceau::getAbstractElementIndexFromLabel(std::string txt){
225    int index = 0;
226    if (txt == "") {
227        return NULL;
228    }
229   
230    for (int a=0; a< ligneFaisceauLayout_->count(); a++) {
231        if (ligneFaisceauLayout_->itemAt(a)) {
232           
233            if (GWt_elementLigneFaisceau* elem = dynamic_cast <GWt_elementLigneFaisceau*> (ligneFaisceauLayout_->itemAt(a)->widget ())) {
234                if (elem->getGWt_AbstractElement()) {
235                    if (elem->getGWt_AbstractElement()->getAbstractElement()->getLabel() == txt) {
236                        return index;
237                    }
238                }
239                index ++;
240            }
241        }
242    }
243    return NULL;
244   
245}
246
247
248int GWt_LigneFaisceau::getBeamLineSize() {
249  int count = 0;
250  for (int a=0; a< ligneFaisceauLayout_->count(); a++) {
251    if (dynamic_cast <GWt_elementLigneFaisceau*> (ligneFaisceauLayout_->itemAt(a)->widget ())) {
252      count ++;
253    }
254  }
255  return count;
256}
257
258
259vector <abstractElement*> GWt_LigneFaisceau::getAllAbstractElements()
260{
261  vector <abstractElement*> elems;
262  for (int a=0; a< ligneFaisceauLayout_->count(); a++) {
263    if (GWt_elementLigneFaisceau* elem = dynamic_cast <GWt_elementLigneFaisceau*> (ligneFaisceauLayout_->itemAt(a)->widget ())) {
264      elems.push_back(elem->getGWt_AbstractElement()->getAbstractElement());
265    }
266  }
267  return elems;
268}
269
270void GWt_LigneFaisceau::update(int i){
271    int index = 0;
272   
273    // first if 1
274    //    i--;
275   
276    for (int a=0; a< ligneFaisceauLayout_->count(); a++) {
277        if (GWt_elementLigneFaisceau* elem = dynamic_cast <GWt_elementLigneFaisceau*> (ligneFaisceauLayout_->itemAt(a)->widget ())) {
278            if (index == i) {
279                elem->update();
280            }
281            index ++;
282        }
283    }
284}
285
286
287void GWt_LigneFaisceau::initializeSoftwares(){
288   
289  vector <abstractElement*> elems = getAllAbstractElements();
290    for (int a=0; a< elems.size(); a++) {
291        elems[a]->setSoftware(nomDeLogiciel::unknownSoftware);
292    }
293}
294
295
Note: See TracBrowser for help on using the repository browser.