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

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

merge avec la branche 12_03_12-managerComboBox

File size: 8.6 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
[308]53GWt_abstractElement* GWt_LigneFaisceau::addElement(typedElement eType){
[343]54  return addElement(eType,NULL);
[48]55}
[167]56
[343]57GWt_abstractElement* GWt_LigneFaisceau::addElement(typedElement eType, GWt_dropZoneLigneFaisceau* dropContainer )
58{
[248]59
[379]60  GWt_abstractElement* GWtAbstractElem = NULL; 
[343]61  cout << " Entree 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 
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());
[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
[401]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
[305]248int GWt_LigneFaisceau::getBeamLineSize() {
[343]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 ++;
[305]253    }
[343]254  }
255  return count;
[305]256}
257
[359]258
[343]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());
[305]265    }
[343]266  }
267  return elems;
[305]268}
269
[359]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) {
[375]279                elem->update();
[359]280            }
281            index ++;
282        }
283    }
284}
285
[401]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.