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

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

Début de stockage de façon plus générique des parametres (ne change rien pour le moment)

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}
133
134WImage* GWt_abstractElement::getImage() {
135    return image_;
136}
137
138
139void GWt_abstractElement::FileInput(ifstream& ifs){
140    getAbstractElement()->FileInput(ifs);
141    initilializeDialog();
142    updateLabelAndToolTipWidget();
143
144// update parameters
145    GWt_LigneFaisceau* ligneFaisceau = NULL;
146    if ( static_cast<GWt_LigneFaisceau*> (wApp->findWidget ("ligneFaisceau"))) {
147        ligneFaisceau = static_cast<GWt_LigneFaisceau*> (wApp->findWidget ("ligneFaisceau"));
148        ligneFaisceau->update();
149    }
150}
151
152
153
154variant<int, string, bool, float, NullType> GWt_abstractElement::getParamValue(string elem) {
155
156    if (parameterMapValue.find(elem) == parameterMapValue.end() )
157    {
158        return new NullType();
159    }
160
161    std::map<std::string, variant<int, string, bool, float, NullType> >::iterator it;
162    it = parameterMapValue.find(elem);
163   
164    variant <int, string, bool, float, NullType> value = it->second;
165   
166    try {
167        int pi = boost::get<int>(value);
168        printf("%s Type is int\n",elem.c_str());
169        return pi;
170    }
171    catch (boost::bad_get v) {
172        try {
173            string si = boost::get<string>(value);
174            printf("%s Type is string\n",elem.c_str());
175            return si;
176        }
177        catch (boost::bad_get v) {
178            try {
179                bool bi = boost::get<bool>(value);
180                printf("%s Type is bool\n",elem.c_str());
181                return bi;
182            }
183            catch (boost::bad_get v) {
184                printf("%s Type is NULL\n",elem.c_str());
185                return new NullType();
186            }
187        }
188    }
189    printf("%s Type is NULL NULL\n",elem.c_str());
190    return new NullType();
191}
192
193
194string GWt_abstractElement::getParamDescription(string elem) {
195   
196    if (parameterMapDescription.find(elem) == parameterMapDescription.end() )
197    {
198        printf("%s Descr is NULL NULL\n",elem.c_str());
199        return "";
200    } else {
201        printf("%s Descr is %s\n",elem.c_str(),parameterMapDescription.find(elem)->second.c_str());
202        return parameterMapDescription.find(elem)->second;
203    }
204}
Note: See TracBrowser for help on using the repository browser.