source: PSPA/Interface_Web/trunk/pspaWT/sources/userInterface/src/GWt_elementLigneFaisceau.cc @ 336

Last change on this file since 336 was 336, checked in by garnier, 12 years ago

bug #43 fixed

File size: 5.8 KB
Line 
1#include <iostream>
2
3#include "GWt_elementLigneFaisceau.h"
4#include "nomdElements.h"
5#include "GWt_console.h"
6#include "abstractElement.h"
7#include "GWt_rfgun.h"
8#include "GWt_drift.h"
9#include "GWt_cell.h"
10#include "GWt_bend.h"
11#include "GWt_soleno.h"
12#include "GWt_beam.h"
13#include "GWt_fit.h"
14
15
16#include <Wt/WCssDecorationStyle>
17#include <Wt/WSignalMapper>
18#include <Wt/WText>
19#include <Wt/WImage>
20#include <Wt/WHBoxLayout>
21#include <Wt/WGridLayout>
22#include <Wt/WLength>
23#include <Wt/WVBoxLayout>
24#include <Wt/WApplication>
25
26#define PSPA_DEBUG 1
27
28
29GWt_elementLigneFaisceau::GWt_elementLigneFaisceau(PspaApplication* pspa)
30: WContainerWidget(),
31firstTimeInsertMessage_(NULL),
32dropZoneLeft_(NULL),
33dropZoneRight_(NULL),
34GWt_abstractElement_(NULL),
35elementLabel_(NULL),
36pspa_(pspa)
37{
38   
39    initialize_ligneFaisceau(inconnu);
40}
41
42
43GWt_elementLigneFaisceau::GWt_elementLigneFaisceau(typedElement type, PspaApplication* pspa)
44: WContainerWidget(),
45firstTimeInsertMessage_(NULL),
46dropZoneLeft_(NULL),
47dropZoneRight_(NULL),
48GWt_abstractElement_(NULL),
49elementLabel_(NULL),
50pspa_(pspa)
51{
52    // set the css name
53    setObjectName("elementLigneFaisceau");
54
55    initialize_ligneFaisceau(type);
56}
57
58
59void GWt_elementLigneFaisceau::initialize_ligneFaisceau(typedElement eType)
60{
61   
62    cout<<"new GWt_elementLigneFaisceau : "<< this << endl;
63   
64    // set layout
65    //     +----------+--------+---------+
66    //     |   (--->) |  ELEM  | (-----) |
67    //     +----------+--------+---------+
68    //     |             NAME            |
69    //     +----------+--------+---------+
70   
71   
72    WGridLayout *gridLayout = new WGridLayout();
73   
74    gridLayout->setContentsMargins(0,0,0,0);
75    gridLayout->setHorizontalSpacing    (0);
76    gridLayout->setVerticalSpacing      (0);
77   
78    // add first line :  initialize arrow and link images
79    dropZoneLeft_ = new GWt_dropZoneLigneFaisceau(pspa_);
80    dropZoneRight_ = new GWt_dropZoneLigneFaisceau(pspa_);
81   
82    // change object name in order to manage css :
83    dropZoneLeft_->resize(10,30);
84    dropZoneRight_->resize(10,30);
85   
86    gridLayout->addWidget       (dropZoneLeft_,0,0);
87    gridLayout->addWidget       (dropZoneRight_,0,2);
88   
89    // add the image if present
90   
91    switch (  eType ) {
92        case RFgun :
93            GWt_abstractElement_ = new GWt_rfgun(this);
94            break;
95        case drift :
96            GWt_abstractElement_ = new GWt_drift(this);
97            break;
98        case cell  :
99            GWt_abstractElement_ = new GWt_cell(this);
100            break;
101        case bend  :
102            GWt_abstractElement_ = new GWt_bend(this);
103            break;
104        case soleno  :
105            GWt_abstractElement_ = new GWt_soleno(this);
106            break;
107        case beam  :
108            GWt_abstractElement_ = new GWt_beam(this);
109            break;
110        case fit  :
111            GWt_abstractElement_ = new GWt_fit(this);
112            break;
113        case inconnu :
114            GWt_abstractElement_ = NULL;
115    }
116    if (GWt_abstractElement_ != NULL) {
117        gridLayout->addWidget   (GWt_abstractElement_,0,1);
118        GWt_abstractElement_->setMaximumSize(32,32);
119        GWt_abstractElement_->setMinimumSize(32,32);
120    }
121   
122    // add second line
123    if (GWt_abstractElement_ == NULL) {
124        elementLabel_ = new WText();
125    } else {
126        elementLabel_ = new WText(GWt_abstractElement_->getAbstractElement()->getLabel());
127    }
128   
129    gridLayout->addWidget       (elementLabel_,1,0,1,3,Wt::AlignCenter |Wt::AlignMiddle);
130   
131    gridLayout->setColumnStretch (0,1);
132    gridLayout->setColumnStretch (2,1);
133   
134    // set layout
135    setLayout(gridLayout);
136}
137
138
139GWt_elementLigneFaisceau::~GWt_elementLigneFaisceau()
140{
141}
142
143
144void GWt_elementLigneFaisceau::removeDone(GWt_abstractElement* gw)
145{
146    if (messageDropZone_->result() == WDialog::Accepted) {
147        // FIXME
148        //    removeDropZone();
149    }
150}
151
152
153void GWt_elementLigneFaisceau::addElement(GWt_abstractElement* elem){
154   
155    clear();
156    GWt_abstractElement_ = elem;
157    addWidget(GWt_abstractElement_);
158    if (static_cast <WContainerWidget*> (parent())) {
159        WContainerWidget* wc = static_cast <WContainerWidget*> (parent());
160        WBoxLayout* layout = ((WBoxLayout*)(wc->layout()));
161        layout->setStretchFactor(this,0);
162    }
163   
164   
165    firstTimeInsertMessage_ = NULL;
166    dropZoneLeft_ = NULL;
167}
168
169
170std::string GWt_elementLigneFaisceau::getElementNumberInBeamLine(nomdElements elem){
171    string str = "";
172   
173    if (static_cast <WContainerWidget*> (parent())) {
174        WContainerWidget* wc = static_cast <WContainerWidget*> (parent());
175        for (int a=0; a<wc->count(); a++) {
176            if (static_cast <GWt_abstractElement*> (wc->widget (a))) {
177                //        GWt_abstractElement* ab = static_cast <GWt_abstractElement*> (wc->widget (a));
178                /*
179                 printf("1--->%d\n",ab->getElement());
180                 printf("2--->%d\n",ab->getElement()->getLenghtOfElement());
181                 printf("3--->%d\n",ab->getElement()->getName().getElementType());
182                 printf("4--->%d\n",elem.getElementType());
183                 
184                 if (static_cast <GWt_abstractElement*> (wc->widget (a))->getElement()->getName().getElementType() == elem.getElementType()) {
185                 pspa_->addConsoleMessage("type trouvÈ");
186                 } else {
187                 pspa_->addConsoleMessage("type trouvÈ NOT ");
188                 }
189                 */
190               
191            }
192        }
193       
194        int n = 999999;
195       
196        std::stringstream stream;
197        stream << n ;
198        std::string number(stream.str());
199       
200        if(n < 10) {
201            str= elem.getElementLabel()+"0"+number;
202        } else {
203            str= elem.getElementLabel()+number;
204        }
205    }
206   
207    return str;
208}
209
210
211void GWt_elementLigneFaisceau::setElementLabel(std::string label) {
212    if (elementLabel_) {
213        elementLabel_->setText(label);
214    }
215}
216
Note: See TracBrowser for help on using the repository browser.