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

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

Changement de la couleur des sections selectionnes + plein dautres choses

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_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    // 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    if (abstractElement_ != NULL) {
85    elementLigneFaiseauContainer_->setElementLabel(abstractElement_->getLabel());
86    setToolTip(print());
87    }
88}
89
90void GWt_abstractElement::clicked()
91{
92  initilializeDialog();
93  dialog_->show();
94}
95
96
97void GWt_abstractElement::doubleClicked()
98{
99    StandardButton result = WMessageBox::show("PSPA : Delete element", WString("Delete '")+WString(getAbstractElement()->getLabel())+"' ?", Ok | Cancel);
100
101    if (result == Cancel ) {
102        return;
103    }
104    // get LigneFaiseau widget and add new elementLigneFaiseau
105    GWt_LigneFaisceau* ligneFaisceau = NULL;
106    if ( static_cast<GWt_LigneFaisceau*> (wApp->findWidget ("ligneFaisceau"))) {
107        ligneFaisceau = static_cast<GWt_LigneFaisceau*> (wApp->findWidget ("ligneFaisceau"));
108    } else {
109        return;
110    }
111   
112    ligneFaisceau->removeElement(this);
113}
114
115WContainerWidget* GWt_abstractElement::getWidget() {
116    return wc_;
117}
118
119abstractElement* GWt_abstractElement::getAbstractElement() {
120    return abstractElement_;
121}
122
123
124void GWt_abstractElement::createDragImage(WContainerWidget* w){
125
126    GWt_draggableImage *result = new GWt_draggableImage(getBigImageURL(),w);
127
128    /*
129     * Set the image to be draggable, showing the other image (dragImage)
130     * to be used as the widget that is visually dragged.
131     */
132    result->setDraggable(getMimeType(),new WImage(getSmallImageURL(),w),true);
133    result->setToolTip(getName());
134
135}
136
137WImage* GWt_abstractElement::getImage() {
138    return image_;
139}
140
141
142void GWt_abstractElement::FileInput(ifstream& ifs){
143    getAbstractElement()->FileInput(ifs);
144    initilializeDialog();
145    updateLabelAndToolTipWidget();
146
147// update parameters
148    GWt_LigneFaisceau* ligneFaisceau = NULL;
149    if ( static_cast<GWt_LigneFaisceau*> (wApp->findWidget ("ligneFaisceau"))) {
150        ligneFaisceau = static_cast<GWt_LigneFaisceau*> (wApp->findWidget ("ligneFaisceau"));
151        ligneFaisceau->update();
152    }
153}
154
155
156
157variant<int, string, bool, float, NullType> GWt_abstractElement::getParamValue(string elem) {
158
159    if (parameterMapValue.find(elem) == parameterMapValue.end() )
160    {
161        return new NullType();
162    }
163
164    std::map<std::string, variant<int, string, bool, float, NullType> >::iterator it;
165    it = parameterMapValue.find(elem);
166   
167    variant <int, string, bool, float, NullType> value = it->second;
168   
169    try {
170        int pi = boost::get<int>(value);
171        printf("%s Type is int\n",elem.c_str());
172        return pi;
173    }
174    catch (boost::bad_get v) {
175        try {
176            string si = boost::get<string>(value);
177            printf("%s Type is string\n",elem.c_str());
178            return si;
179        }
180        catch (boost::bad_get v) {
181            try {
182                bool bi = boost::get<bool>(value);
183                printf("%s Type is bool\n",elem.c_str());
184                return bi;
185            }
186            catch (boost::bad_get v) {
187                printf("%s Type is NULL\n",elem.c_str());
188                return new NullType();
189            }
190        }
191    }
192    printf("%s Type is NULL NULL\n",elem.c_str());
193    return new NullType();
194}
195
196
197string GWt_abstractElement::getParamDescription(string elem) {
198   
199    if (parameterMapDescription.find(elem) == parameterMapDescription.end() )
200    {
201        printf("%s Descr is NULL NULL\n",elem.c_str());
202        return "";
203    } else {
204        printf("%s Descr is %s\n",elem.c_str(),parameterMapDescription.find(elem)->second.c_str());
205        return parameterMapDescription.find(elem)->second;
206    }
207}
Note: See TracBrowser for help on using the repository browser.