source: PSPA/Interface_Web/trunk/pspaWT/sources/userInterface/src/GWt_abstractElement.cc @ 322

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

Correction du bug #15

File size: 5.8 KB
Line 
1
2#include <iostream>
3#include <string>
4#include <boost/variant.hpp>
5#include <boost/variant/get.hpp>
6
7#include "GWt_abstractElement.h"
8#include "GWt_elementLigneFaisceau.h"
9#include "GWt_rfgun.h"
10#include "GWt_drift.h"
11#include "GWt_cell.h"
12#include "GWt_bend.h"
13#include "GWt_soleno.h"
14#include "GWt_beam.h"
15#include "GWt_fit.h"
16#include "GWt_draggableImage.h"
17#include "GWt_ligneFaisceau.h"
18
19#include "mixedTools.h"
20#include "nomdElements.h"
21
22#include <Wt/WText>
23#include <Wt/WLineEdit>
24#include <Wt/WBreak>
25#include <Wt/WApplication>
26#include <Wt/WMessageBox>
27
28
29GWt_abstractElement::GWt_abstractElement(abstractElement* elem)
30: WContainerWidget()
31{
32    abstractElement_ = elem;
33    setStyleClass("beamLineIcon");
34}
35
36
37void GWt_abstractElement::initialize()
38{
39    // make image
40    image_ = new WImage(getBigImageURL(),this);
41   
42    // activate slots
43    image_->doubleClicked().connect(this,&GWt_abstractElement::doubleClicked);
44    image_->clicked().connect(this,&GWt_abstractElement::clicked);
45    addWidget(image_);
46    updateLabelAndToolTipWidget();
47}
48
49
50string* GWt_abstractElement::beginDialog()
51{
52    string* param = abstractElement_-> getParametersString();
53   
54    if ( param == NULL )
55    {
56        if ( static_cast<GWt_console*> (wApp->findWidget ("console"))) {
57            GWt_console* console = static_cast<GWt_console*> (wApp->findWidget ("console"));
58            console->addConsoleMessage(" GWt_abstractElement::beginDialog : empty parameter set for element " + abstractElement_->getNomdElement().getElementName());
59        }
60    }
61    //   int compteur = -1;
62   
63    //  int nbparam = atoi(param[++compteur].c_str());
64    int nbparam = atoi(param->c_str());
65    if ( nbparam != abstractElement_->getNbParams())
66    {
67        if ( static_cast<GWt_console*> (wApp->findWidget ("console"))) {
68            GWt_console* console = static_cast<GWt_console*> (wApp->findWidget ("console"));
69            console->addConsoleMessage(" element seems not to be a " + abstractElement_->getNomdElement().getElementName());
70        }
71    }
72   
73    dialog_ = new WDialog("element " + abstractElement_->getNomdElement().getElementName());
74    new WText(" label of the element : ",dialog_->contents());
75    //  labelEdit_ = new WLineEdit(param[++compteur].c_str(), dialog_->contents());
76   
77    labelEdit_ = new WLineEdit( (++param)->c_str(), dialog_->contents());
78    new WBreak(dialog_->contents());
79    return ++param;
80}
81
82void GWt_abstractElement::updateLabelAndToolTipWidget()
83{
84    elementLigneFaiseauContainer_->setElementLabel(abstractElement_->getLabel());
85    setToolTip(print());
86}
87
88void GWt_abstractElement::clicked()
89{
90    initilializeDialog();
91    dialog_->show();
92}
93
94
95void GWt_abstractElement::doubleClicked()
96{
97    StandardButton result = WMessageBox::show("PSPA : Delete element", WString("Delete '")+WString(getAbstractElement()->getLabel())+"' ?", Ok | Cancel);
98
99    if (result == Cancel ) {
100        return;
101    }
102    // get LigneFaiseau widget and add new elementLigneFaiseau
103    GWt_LigneFaisceau* ligneFaisceau = NULL;
104    if ( static_cast<GWt_LigneFaisceau*> (wApp->findWidget ("ligneFaisceau"))) {
105        ligneFaisceau = static_cast<GWt_LigneFaisceau*> (wApp->findWidget ("ligneFaisceau"));
106    } else {
107        return;
108    }
109   
110    ligneFaisceau->removeElement(this);
111}
112
113
114WContainerWidget* GWt_abstractElement::getWidget() {
115    return wc_;
116}
117
118abstractElement* GWt_abstractElement::getAbstractElement() {
119    return abstractElement_;
120}
121
122
123void GWt_abstractElement::createDragImage(WContainerWidget* w){
124
125    GWt_draggableImage *result = new GWt_draggableImage(getBigImageURL(),w);
126
127    /*
128     * Set the image to be draggable, showing the other image (dragImage)
129     * to be used as the widget that is visually dragged.
130     */
131    result->setDraggable(getMimeType(),new WImage(getSmallImageURL(),w),true);
132    result->setToolTip(getName());
133
134}
135
136WImage* GWt_abstractElement::getImage() {
137    return image_;
138}
139
140
141void GWt_abstractElement::FileInput(ifstream& ifs){
142    getAbstractElement()->FileInput(ifs);
143    initilializeDialog();
144    updateLabelAndToolTipWidget();
145
146// update parameters
147    GWt_LigneFaisceau* ligneFaisceau = NULL;
148    if ( static_cast<GWt_LigneFaisceau*> (wApp->findWidget ("ligneFaisceau"))) {
149        ligneFaisceau = static_cast<GWt_LigneFaisceau*> (wApp->findWidget ("ligneFaisceau"));
150        ligneFaisceau->update();
151    }
152}
153
154
155
156variant<int, string, bool, float, NullType> GWt_abstractElement::getParamValue(string elem) {
157
158    if (parameterMapValue.find(elem) == parameterMapValue.end() )
159    {
160        return new NullType();
161    }
162
163    std::map<std::string, variant<int, string, bool, float, NullType> >::iterator it;
164    it = parameterMapValue.find(elem);
165   
166    variant <int, string, bool, float, NullType> value = it->second;
167   
168    try {
169        int pi = boost::get<int>(value);
170        printf("%s Type is int\n",elem.c_str());
171        return pi;
172    }
173    catch (boost::bad_get v) {
174        try {
175            string si = boost::get<string>(value);
176            printf("%s Type is string\n",elem.c_str());
177            return si;
178        }
179        catch (boost::bad_get v) {
180            try {
181                bool bi = boost::get<bool>(value);
182                printf("%s Type is bool\n",elem.c_str());
183                return bi;
184            }
185            catch (boost::bad_get v) {
186                printf("%s Type is NULL\n",elem.c_str());
187                return new NullType();
188            }
189        }
190    }
191    printf("%s Type is NULL NULL\n",elem.c_str());
192    return new NullType();
193}
194
195
196string GWt_abstractElement::getParamDescription(string elem) {
197   
198    if (parameterMapDescription.find(elem) == parameterMapDescription.end() )
199    {
200        printf("%s Descr is NULL NULL\n",elem.c_str());
201        return "";
202    } else {
203        printf("%s Descr is %s\n",elem.c_str(),parameterMapDescription.find(elem)->second.c_str());
204        return parameterMapDescription.find(elem)->second;
205    }
206}
Note: See TracBrowser for help on using the repository browser.