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

Last change on this file since 418 was 418, checked in by lemeur, 11 years ago

definition des compatibilites des elements dans les software

File size: 8.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#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(nomdElements::typedElement eType){
54  return addElement(eType,NULL);
55}
56
57GWt_abstractElement* GWt_LigneFaisceau::addElement(nomdElements::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 == nomdElements::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
224
225int GWt_LigneFaisceau::getAbstractElementNumeroFromLabel(std::string txt){
226    int index = 1;
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
249
250
251int GWt_LigneFaisceau::getBeamLineSize() {
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 ++;
256    }
257  }
258  return count;
259}
260
261
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());
268    }
269  }
270  return elems;
271}
272
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) {
282                elem->update();
283            }
284            index ++;
285        }
286    }
287}
288
289
290void GWt_LigneFaisceau::initializeSoftwares(){
291   
292  vector <abstractElement*> elems = getAllAbstractElements();
293    for (int a=0; a< elems.size(); a++) {
294      //     elems[a]->setSoftware(nomDeLogiciel::unknownSoftware);
295      elems[a]->setSoftware( NULL );
296    }
297}
298
299
Note: See TracBrowser for help on using the repository browser.