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

Last change on this file since 418 was 418, checked in by lemeur, 11 years ago

definition des compatibilites des elements dans les software

File size: 5.6 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_snapshot.h"
17#include "GWt_draggableImage.h"
18#include "GWt_ligneFaisceau.h"
19
20#include "mixedTools.h"
21#include "nomdElements.h"
22
23#include <Wt/WText>
24#include <Wt/WLineEdit>
25#include <Wt/WBreak>
26#include <Wt/WApplication>
27#include <Wt/WMessageBox>
28
29
30GWt_abstractElement::GWt_abstractElement(abstractElement* elem)
31: WContainerWidget()
32{
33    abstractElement_ = elem;
34}
35
36
37void GWt_abstractElement::initialize()
38{
39    // make image
40    image_ = new WImage(getBigImageURL(),this);
41   
42    addWidget(image_);
43    updateLabelAndToolTipWidget();
44}
45
46
47string* GWt_abstractElement::beginDialog()
48{
49  string* param = abstractElement_-> getParametersString();
50   
51  if ( param == NULL )
52    {
53      if ( static_cast<GWt_console*> (wApp->findWidget ("console"))) {
54        GWt_console* console = static_cast<GWt_console*> (wApp->findWidget ("console"));
55        console->addConsoleMessage(" GWt_abstractElement::beginDialog : empty parameter set for element " + abstractElement_->getNomdElement().getExpandedName());
56        }
57    }
58  //   int compteur = -1;
59 
60  //  int nbparam = atoi(param[++compteur].c_str());
61  int nbparam = atoi(param->c_str());
62  if ( nbparam != abstractElement_->getNbParams())
63    {
64        if ( static_cast<GWt_console*> (wApp->findWidget ("console"))) {
65          GWt_console* console = static_cast<GWt_console*> (wApp->findWidget ("console"));
66          console->addConsoleMessage(" element seems not to be a " + abstractElement_->getNomdElement().getExpandedName());
67        }
68    }
69 
70  dialog_ = new WDialog("element " + abstractElement_->getNomdElement().getExpandedName());
71    new WText(" label of the element : ",dialog_->contents());
72    //  labelEdit_ = new WLineEdit(param[++compteur].c_str(), dialog_->contents());
73   
74    labelEdit_ = new WLineEdit( (++param)->c_str(), dialog_->contents());
75    new WBreak(dialog_->contents());
76    return ++param;
77}
78
79void GWt_abstractElement::updateLabelAndToolTipWidget()
80{
81    if (abstractElement_ != NULL) {
82    elementLigneFaiseauContainer_->setElementLabel(abstractElement_->getLabel());
83    setToolTip(print());
84    }
85}
86
87void GWt_abstractElement::showParameters()
88{
89  initilializeDialog();
90  dialog_->show();
91}
92
93
94void GWt_abstractElement::deleteElement()
95{
96    StandardButton result = WMessageBox::show("PSPA : Delete element", WString("Delete '")+WString(getAbstractElement()->getLabel())+"' ?", Ok | Cancel);
97
98    if (result == Cancel ) {
99        return;
100    }
101    // get LigneFaiseau widget and add new elementLigneFaiseau
102    GWt_LigneFaisceau* ligneFaisceau = NULL;
103    if ( static_cast<GWt_LigneFaisceau*> (wApp->findWidget ("ligneFaisceau"))) {
104        ligneFaisceau = static_cast<GWt_LigneFaisceau*> (wApp->findWidget ("ligneFaisceau"));
105    } else {
106        return;
107    }
108   
109    ligneFaisceau->removeElement(this);
110}
111
112WContainerWidget* GWt_abstractElement::getWidget() {
113    return wc_;
114}
115
116abstractElement* GWt_abstractElement::getAbstractElement() {
117    return abstractElement_;
118}
119
120
121void GWt_abstractElement::createDragImage(WContainerWidget* w){
122
123    GWt_draggableImage *result = new GWt_draggableImage(getBigImageURL(),w);
124
125    /*
126     * Set the image to be draggable, showing the other image (dragImage)
127     * to be used as the widget that is visually dragged.
128     */
129    result->setDraggable(getMimeType(),new WImage(getSmallImageURL(),w),true);
130    result->setToolTip(getName());
131
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}
205
206
Note: See TracBrowser for help on using the repository browser.