1 | |
---|
2 | |
---|
3 | #include <iostream> |
---|
4 | |
---|
5 | #include "GWt_LigneFaisceau.h" |
---|
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 "mixedTools.h" |
---|
12 | |
---|
13 | #include <Wt/WComboBox> |
---|
14 | #include <Wt/WVBoxLayout> |
---|
15 | |
---|
16 | GWt_LigneFaisceau::GWt_LigneFaisceau(PspaApplication* ps) : pspa_(ps), nObjets_(NULL) |
---|
17 | { |
---|
18 | beamLayout_ = new WHBoxLayout(); |
---|
19 | decorationStyle().setBackgroundColor (WColor("orange")); |
---|
20 | |
---|
21 | //box_= new WBoxLayout(Wt::WBoxLayout::LeftToRight); |
---|
22 | //setLayout(box_); |
---|
23 | setLayout(beamLayout_); |
---|
24 | |
---|
25 | int nElts= nomdElements::getNumberOfElements(); |
---|
26 | nObjets_= new Compteur[nElts]; |
---|
27 | for(int k = 0; k < nElts; k++) { |
---|
28 | typedElement eType= (typedElement)k; |
---|
29 | acceptDrops(nomdElements::getImageFromType(eType)); |
---|
30 | } |
---|
31 | |
---|
32 | // ajouter cette image ??? |
---|
33 | // acceptDrops("icons/final.jpg"); |
---|
34 | |
---|
35 | } |
---|
36 | |
---|
37 | string GWt_LigneFaisceau::createLabel(nomdElements el,int n) |
---|
38 | { |
---|
39 | string str; |
---|
40 | if(n < 10) { |
---|
41 | str= el.getElementLabel()+"0"+mixedTools::intToString(n); |
---|
42 | } else { |
---|
43 | str= el.getElementLabel()+mixedTools::intToString(n); |
---|
44 | } |
---|
45 | return str; |
---|
46 | } |
---|
47 | |
---|
48 | void GWt_LigneFaisceau::dropEvent(WDropEvent evt) |
---|
49 | { |
---|
50 | nomdElements e(evt.mimeType()); |
---|
51 | typedElement eType = e.getElementType(); |
---|
52 | int cnts= pspa_->getDataManager()->beamLineSize(); |
---|
53 | cout<<"GWt_LigneFaisceau::dropEvent "<<e.getElementName()<<" ("<< cnts <<")"<< endl; |
---|
54 | |
---|
55 | //cout << "GWt_LigneFaisceau::dropEvent " << evt.mimeType() << " " << eType << endl; |
---|
56 | if(eType == inconnu) { |
---|
57 | cout << "GWt_LigneFaisceau::element type " << eType << " inconnu " << endl; |
---|
58 | return; |
---|
59 | } |
---|
60 | |
---|
61 | pspa_->addConsoleMessage(e.getElementName()); |
---|
62 | abstractElement* ptr = pspa_->getDataManager()->addElement(eType); |
---|
63 | ptr->setLabel(createLabel(e,nObjets_[eType].incr())); |
---|
64 | cout << " je vais ajouter l'element " << ptr->getName().getElementName() << " de type " << ptr->getName().getElementType() << endl; |
---|
65 | // GWt_abstractElement* gw = GWt_abstractElement::ajoute(pspa_,ptr,evt.mimeType()); |
---|
66 | GWt_abstractElement* gw = GWt_abstractElement::ajoute(pspa_,ptr); |
---|
67 | if(gw == NULL) return; |
---|
68 | |
---|
69 | gw->updateLabelWidget(); |
---|
70 | |
---|
71 | ////////////////////////////////////////////////////////////////// |
---|
72 | ////////////////////// ORIGINE /////////////////////////////////// |
---|
73 | |
---|
74 | //beamLayout_->addWidget(gw->getWidget()); |
---|
75 | //pspa_->updateSelections(); |
---|
76 | |
---|
77 | ////////////////////// ESSAI //////////////////////////////////////////// |
---|
78 | |
---|
79 | //box_->addWidget(gw->getWidget(),0,Wt::AlignJustify); |
---|
80 | beamLayout_->insertWidget(cnts,gw->getWidget()); |
---|
81 | beamLayout_->addStretch(1); |
---|
82 | pspa_->updateSelections(); |
---|
83 | |
---|
84 | cout << "number of items in the layout= " << beamLayout_->count() << endl; |
---|
85 | for(int k = 0; k < beamLayout_->count(); k++) |
---|
86 | { |
---|
87 | WLayoutItem *wi= beamLayout_->itemAt(k); |
---|
88 | WWidget *w= wi->widget(); |
---|
89 | cout << w->objectName() << ", " << w->id() << endl; |
---|
90 | } |
---|
91 | ////////////////////////////////////////////////////////////////// |
---|
92 | |
---|
93 | // pourVoir |
---|
94 | int nElts= pspa_->getDataManager()->beamLineSize(); |
---|
95 | cout << "GWt_LigneFaisceau:: nElts= " << nElts << endl; |
---|
96 | unsigned int k; |
---|
97 | for(k = 0; k < (unsigned)nElts; k++) { |
---|
98 | abstractElement* ptr= pspa_->getDataManager()->getCollection()->getElementPointer(k); |
---|
99 | string label= ptr->getLabel(); |
---|
100 | cout << "GWt_LigneFaisceau:: " << label << " dans la liste" << endl; |
---|
101 | } |
---|
102 | |
---|
103 | } |
---|
104 | |
---|
105 | void GWt_LigneFaisceau::restoreElementCollection() |
---|
106 | { |
---|
107 | beamLayout_->clear(); |
---|
108 | |
---|
109 | delete[] nObjets_; |
---|
110 | // nomdElements ee; |
---|
111 | int nElements= nomdElements ::getNumberOfElements(); |
---|
112 | nObjets_= new Compteur[nElements]; |
---|
113 | |
---|
114 | int nbElem = pspa_->getDataManager()->beamLineSize(); |
---|
115 | unsigned int k; |
---|
116 | for(k = 0; k < (unsigned)nbElem; k++) |
---|
117 | { |
---|
118 | abstractElement* ptr = pspa_->getDataManager()->getCollection()->getElementPointer(k); |
---|
119 | GWt_abstractElement* gw = GWt_abstractElement::ajoute(pspa_,ptr); |
---|
120 | if(gw == NULL) { |
---|
121 | cerr << "GWt_LigneFaisceau::restaure element type " << ptr->getName().getElementName() << " inconnu " << endl; |
---|
122 | } |
---|
123 | |
---|
124 | gw->updateLabelWidget(); |
---|
125 | // nObjets_[eType].incr(); |
---|
126 | nObjets_[ptr->getName().getElementType()].incr(); |
---|
127 | beamLayout_->addWidget(gw->getWidget()); |
---|
128 | } |
---|
129 | |
---|
130 | pspa_->updateSelections(); |
---|
131 | } |
---|