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

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

bug #18 fixed

File size: 7.2 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),
34abstractElement_(NULL),
35elementName_(NULL),
36pspa_(pspa)
37{
38   
39    initialize_ligneFaisceau(NULL);
40}
41
42GWt_elementLigneFaisceau::GWt_elementLigneFaisceau(abstractElement* abstractElement, PspaApplication* pspa)
43: WContainerWidget(),
44firstTimeInsertMessage_(NULL),
45dropZoneLeft_(NULL),
46dropZoneRight_(NULL),
47abstractElement_(NULL),
48elementName_(NULL),
49pspa_(pspa)
50{
51    // set the css name
52    setObjectName("elementLigneFaisceau");
53
54    initialize_ligneFaisceau(abstractElement);
55}
56
57
58void GWt_elementLigneFaisceau::initialize_ligneFaisceau(abstractElement* abstractElement)
59{
60   
61    cout<<"new GWt_elementLigneFaisceau : "<< this << endl;
62   
63    // set layout
64    //     +----------+--------+---------+
65    //     |   (--->) |  ELEM  | (-----) |
66    //     +----------+--------+---------+
67    //     |             NAME            |
68    //     +----------+--------+---------+
69   
70   
71    WGridLayout *gridLayout = new WGridLayout();
72   
73    gridLayout->setContentsMargins(0,0,0,0);
74    gridLayout->setHorizontalSpacing    (0);
75    gridLayout->setVerticalSpacing      (0);
76   
77    // add first line :  initialize arrow and link images
78    dropZoneLeft_ = new GWt_dropZoneLigneFaisceau(pspa_);
79    dragElementZone_ = new WContainerWidget();
80    dropZoneRight_ = new GWt_dropZoneLigneFaisceau(pspa_);
81   
82    // change object name in order to manage css :
83    dragElementZone_->setStyleClass("beamLineIcon");
84    dropZoneRight_->resize(10,30);
85   
86   
87    WContainerWidget* arrow = new WContainerWidget();
88    new WImage(arrow);
89    arrow->resize(10,30);
90   
91    arrow->setStyleClass("elementLigneFaiseau_arrow");
92    dropZoneLeft_->addWidget(arrow);
93   
94    gridLayout->addWidget       (dropZoneLeft_,0,0);
95    gridLayout->addWidget       (dragElementZone_,0,1);
96    gridLayout->addWidget       (dropZoneRight_,0,2);
97   
98    // add the image if present
99    if (abstractElement != NULL) {
100        typedElement eType = abstractElement->getNomdElement().getElementType();
101       
102        switch (  eType ) {
103            case RFgun :
104                abstractElement_ = new GWt_rfgun(abstractElement, this);
105                break;
106            case drift :
107                abstractElement_ = new GWt_drift(abstractElement, this);
108                break;
109            case cell  :
110                abstractElement_ = new GWt_cell(abstractElement, this);
111                break;
112            case bend  :
113                abstractElement_ = new GWt_bend(abstractElement, this);
114                break;
115            case soleno  :
116                abstractElement_ = new GWt_soleno(abstractElement, this);
117                break;
118            case beam  :
119                abstractElement_ = new GWt_beam(abstractElement, this);
120                break;
121            case fit  :
122                abstractElement_ = new GWt_fit(abstractElement, this);
123                break;
124            case inconnu :
125                abstractElement_ = NULL;
126        }
127        if (abstractElement_ != NULL) {
128            dragElementZone_->addWidget(abstractElement_->getImage());
129            dragElementZone_->setMaximumSize(32,32);
130            dragElementZone_->setMinimumSize(32,32);
131            dragElementZone_->setToolTip(abstractElement_->print());
132        }
133    }
134    // add second line
135    if (abstractElement == NULL) {
136        elementName_ = new WText();
137    } else {
138        elementName_ = new WText(abstractElement->getLabel());
139    }
140   
141    gridLayout->addWidget       (elementName_,1,0,1,3,Wt::AlignCenter |Wt::AlignMiddle);
142   
143    gridLayout->setColumnStretch (0,1);
144    gridLayout->setColumnStretch (2,1);
145   
146    //  dragElementZone_->addWidget(firstTimeInsertMessage_);
147    //  gridLayout->addWidget   (new WText("Drag elements here"),0,0);
148   
149    // set layout
150    setLayout(gridLayout);
151    //addWidget(new WText("Drag elements here"));
152}
153
154
155GWt_elementLigneFaisceau::~GWt_elementLigneFaisceau()
156{
157}
158
159
160void GWt_elementLigneFaisceau::onClick(GWt_abstractElement* gw)
161{
162    cout << "mouse key was double clicked on this widget " << gw->getWidget()->id()<< endl;
163   
164    messageDropZone_ = new GWt_dialog("Question","Are you sure you want to delete the selected item?",GWt_dialog::Warning,true,true);
165   
166    WSignalMapper<GWt_abstractElement *> *MyMap = new WSignalMapper<GWt_abstractElement *>(this);
167    MyMap->mapped().connect(this, &GWt_elementLigneFaisceau::removeDone);
168    MyMap->mapConnect(messageDropZone_->finished(),gw);
169    messageDropZone_->exec();
170}
171
172
173void GWt_elementLigneFaisceau::removeDone(GWt_abstractElement* gw)
174{
175    if (messageDropZone_->result() == WDialog::Accepted) {
176        // FIXME
177        //    removeDropZone();
178    }
179}
180
181
182
183
184void GWt_elementLigneFaisceau::addElement(GWt_abstractElement* elem){
185   
186    clear();
187    abstractElement_ = elem;
188    addWidget(abstractElement_);
189    if (static_cast <WContainerWidget*> (parent())) {
190        WContainerWidget* wc = static_cast <WContainerWidget*> (parent());
191        WBoxLayout* layout = ((WBoxLayout*)(wc->layout()));
192        layout->setStretchFactor(this,0);
193    }
194   
195   
196    firstTimeInsertMessage_ = NULL;
197    dropZoneLeft_ = NULL;
198}
199
200std::string GWt_elementLigneFaisceau::getElementNumberInBeamLine(nomdElements elem){
201    string str = "";
202   
203    if (static_cast <WContainerWidget*> (parent())) {
204        WContainerWidget* wc = static_cast <WContainerWidget*> (parent());
205        for (int a=0; a<wc->count(); a++) {
206            if (static_cast <GWt_abstractElement*> (wc->widget (a))) {
207                //        GWt_abstractElement* ab = static_cast <GWt_abstractElement*> (wc->widget (a));
208                /*
209                 printf("1--->%d\n",ab->getElement());
210                 printf("2--->%d\n",ab->getElement()->getLenghtOfElement());
211                 printf("3--->%d\n",ab->getElement()->getName().getElementType());
212                 printf("4--->%d\n",elem.getElementType());
213                 
214                 if (static_cast <GWt_abstractElement*> (wc->widget (a))->getElement()->getName().getElementType() == elem.getElementType()) {
215                 pspa_->addConsoleMessage("type trouvé");
216                 } else {
217                 pspa_->addConsoleMessage("type trouvé NOT ");
218                 }
219                 */
220               
221            }
222        }
223       
224        int n = 999999;
225       
226        std::stringstream stream;
227        stream << n ;
228        std::string number(stream.str());
229       
230        if(n < 10) {
231            str= elem.getElementLabel()+"0"+number;
232        } else {
233            str= elem.getElementLabel()+number;
234        }
235    }
236   
237    return str;
238}
239
240void GWt_elementLigneFaisceau::setElementName(std::string label) {
241    elementName_->setText(label);
242}
243
Note: See TracBrowser for help on using the repository browser.