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

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

Amelioration dans le design du GUI des elementsFaisceau

File size: 5.6 KB
RevLine 
[106]1
[168]2#include <iostream>
3#include <string>
[320]4#include <boost/variant.hpp>
5#include <boost/variant/get.hpp>
[168]6
[106]7#include "GWt_abstractElement.h"
[266]8#include "GWt_elementLigneFaisceau.h"
[156]9#include "GWt_rfgun.h"
[125]10#include "GWt_drift.h"
11#include "GWt_cell.h"
12#include "GWt_bend.h"
13#include "GWt_soleno.h"
[179]14#include "GWt_beam.h"
[225]15#include "GWt_fit.h"
[343]16#include "GWt_snapshot.h"
[292]17#include "GWt_draggableImage.h"
[300]18#include "GWt_ligneFaisceau.h"
[125]19
20#include "mixedTools.h"
21#include "nomdElements.h"
22
[106]23#include <Wt/WText>
[225]24#include <Wt/WLineEdit>
[226]25#include <Wt/WBreak>
[240]26#include <Wt/WApplication>
[301]27#include <Wt/WMessageBox>
[106]28
[320]29
[289]30GWt_abstractElement::GWt_abstractElement(abstractElement* elem)
[272]31: WContainerWidget()
[106]32{
[272]33    abstractElement_ = elem;
[266]34}
[106]35
[167]36
[294]37void GWt_abstractElement::initialize()
38{
39    // make image
40    image_ = new WImage(getBigImageURL(),this);
41   
[299]42    addWidget(image_);
[308]43    updateLabelAndToolTipWidget();
[294]44}
45
46
[225]47string* GWt_abstractElement::beginDialog()
48{
[343]49  string* param = abstractElement_-> getParametersString();
[272]50   
[343]51  if ( param == NULL )
[225]52    {
[343]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().getElementName());
[272]56        }
[225]57    }
[343]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())
[225]63    {
[272]64        if ( static_cast<GWt_console*> (wApp->findWidget ("console"))) {
[343]65          GWt_console* console = static_cast<GWt_console*> (wApp->findWidget ("console"));
66          console->addConsoleMessage(" element seems not to be a " + abstractElement_->getNomdElement().getElementName());
[272]67        }
[225]68    }
[343]69 
70  dialog_ = new WDialog("element " + abstractElement_->getNomdElement().getElementName());
[272]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;
[225]77}
78
[308]79void GWt_abstractElement::updateLabelAndToolTipWidget()
[106]80{
[359]81    if (abstractElement_ != NULL) {
[305]82    elementLigneFaiseauContainer_->setElementLabel(abstractElement_->getLabel());
[308]83    setToolTip(print());
[359]84    }
[106]85}
86
[365]87void GWt_abstractElement::showParameters()
[106]88{
[343]89  initilializeDialog();
90  dialog_->show();
[106]91}
92
93
[365]94void GWt_abstractElement::deleteElement()
[294]95{
[305]96    StandardButton result = WMessageBox::show("PSPA : Delete element", WString("Delete '")+WString(getAbstractElement()->getLabel())+"' ?", Ok | Cancel);
[299]97
[301]98    if (result == Cancel ) {
99        return;
100    }
[299]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);
[294]110}
111
[106]112WContainerWidget* GWt_abstractElement::getWidget() {
[272]113    return wc_;
[106]114}
[125]115
[305]116abstractElement* GWt_abstractElement::getAbstractElement() {
[272]117    return abstractElement_;
[168]118}
119
[125]120
[292]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);
[322]130    result->setToolTip(getName());
131
[292]132}
133
134WImage* GWt_abstractElement::getImage() {
135    return image_;
136}
[308]137
138
139void GWt_abstractElement::FileInput(ifstream& ifs){
140    getAbstractElement()->FileInput(ifs);
[310]141    initilializeDialog();
142    updateLabelAndToolTipWidget();
[311]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    }
[308]150}
[320]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}
[365]205
206
Note: See TracBrowser for help on using the repository browser.