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

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

Suppression de la classe "elementsCollection" et bug fixed #20

File size: 4.2 KB
Line 
1
2#include <iostream>
3#include <string>
4
5#include "GWt_abstractElement.h"
6#include "GWt_elementLigneFaisceau.h"
7#include "GWt_rfgun.h"
8#include "GWt_drift.h"
9#include "GWt_cell.h"
10#include "GWt_bend.h"
11#include "GWt_soleno.h"
12#include "GWt_beam.h"
13#include "GWt_fit.h"
14#include "GWt_draggableImage.h"
15#include "GWt_ligneFaisceau.h"
16
17#include "mixedTools.h"
18#include "nomdElements.h"
19
20#include <Wt/WText>
21#include <Wt/WLineEdit>
22#include <Wt/WBreak>
23#include <Wt/WApplication>
24#include <Wt/WMessageBox>
25
26GWt_abstractElement::GWt_abstractElement(abstractElement* elem)
27: WContainerWidget()
28{
29    abstractElement_ = elem;
30    setStyleClass("beamLineIcon");
31
32}
33
34
35void GWt_abstractElement::initialize()
36{
37    // make image
38    image_ = new WImage(getBigImageURL(),this);
39   
40    // activate slots
41    image_->doubleClicked().connect(this,&GWt_abstractElement::doubleClicked);
42    image_->clicked().connect(this,&GWt_abstractElement::clicked);
43    addWidget(image_);
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().getElementName());
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().getElementName());
67        }
68    }
69   
70    dialog_ = new WDialog("element " + abstractElement_->getNomdElement().getElementName());
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::updateLabelWidget()
80{
81    elementLigneFaiseauContainer_->setElementLabel(abstractElement_->getLabel());
82}
83
84void GWt_abstractElement::clicked()
85{
86    dialog_->show();
87}
88
89
90void GWt_abstractElement::doubleClicked()
91{
92    StandardButton result = WMessageBox::show("PSPA : Delete element", WString("Delete '")+WString(getAbstractElement()->getLabel())+"' ?", Ok | Cancel);
93
94    if (result == Cancel ) {
95        return;
96    }
97    // get LigneFaiseau widget and add new elementLigneFaiseau
98    GWt_LigneFaisceau* ligneFaisceau = NULL;
99    if ( static_cast<GWt_LigneFaisceau*> (wApp->findWidget ("ligneFaisceau"))) {
100        ligneFaisceau = static_cast<GWt_LigneFaisceau*> (wApp->findWidget ("ligneFaisceau"));
101    } else {
102        return;
103    }
104   
105    ligneFaisceau->removeElement(this);
106}
107
108
109WContainerWidget* GWt_abstractElement::getWidget() {
110    return wc_;
111}
112
113abstractElement* GWt_abstractElement::getAbstractElement() {
114    return abstractElement_;
115}
116
117GWt_abstractElement* GWt_abstractElement::ajoute(abstractElement* ptr)
118{
119    /*
120     typedElement eType = ptr->getNomdElement().getElementType();
121     
122     switch (  eType ) {
123     case RFgun : return new GWt_rfgun(ptr);
124     case drift : return new GWt_drift(ptr);
125     case cell  : return new GWt_cell(ptr);
126     case bend  : return new GWt_bend(ptr);
127     case soleno  : return new GWt_soleno(ptr);
128     case beam  : return new GWt_beam(ptr);
129     case fit  : return new GWt_fit(ptr);
130     case inconnu : return NULL;
131     default : return NULL;
132     }
133     */
134    return NULL;
135}
136
137
138void GWt_abstractElement::createDragImage(WContainerWidget* w){
139
140    GWt_draggableImage *result = new GWt_draggableImage(getBigImageURL(),w);
141
142    /*
143     * Set the image to be draggable, showing the other image (dragImage)
144     * to be used as the widget that is visually dragged.
145     */
146    result->setDraggable(getMimeType(),new WImage(getSmallImageURL(),w),true);
147}
148
149WImage* GWt_abstractElement::getImage() {
150    return image_;
151}
Note: See TracBrowser for help on using the repository browser.