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 | |
---|
10 | #include "GWt_draggableImage.h" |
---|
11 | #include "GWt_ligneFaisceau.h" |
---|
12 | |
---|
13 | #include "mixedTools.h" |
---|
14 | #include "nomdElements.h" |
---|
15 | |
---|
16 | #include <Wt/WText> |
---|
17 | #include <Wt/WLineEdit> |
---|
18 | #include <Wt/WBreak> |
---|
19 | #include <Wt/WApplication> |
---|
20 | #include <Wt/WMessageBox> |
---|
21 | |
---|
22 | |
---|
23 | GWt_abstractElement::GWt_abstractElement(abstractElement* elem) |
---|
24 | : WContainerWidget() |
---|
25 | { |
---|
26 | abstractElement_ = elem; |
---|
27 | } |
---|
28 | |
---|
29 | void GWt_abstractElement::initialize() |
---|
30 | { |
---|
31 | image_ = new WImage(getBigImageURL(),this); // make image |
---|
32 | addWidget(image_); |
---|
33 | updateLabelAndToolTipWidget(); |
---|
34 | } |
---|
35 | |
---|
36 | string* GWt_abstractElement::beginDialog() |
---|
37 | { |
---|
38 | string* param = abstractElement_->getParametersString(); |
---|
39 | |
---|
40 | if ( param == NULL ) { |
---|
41 | if ( static_cast<GWt_console*> (wApp->findWidget ("console"))) { |
---|
42 | GWt_console* console = static_cast<GWt_console*> (wApp->findWidget ("console")); |
---|
43 | console->addConsoleMessage(" GWt_abstractElement::beginDialog : empty parameter set for element " + abstractElement_->getNomdElement().getExpandedName()); |
---|
44 | } |
---|
45 | } |
---|
46 | |
---|
47 | int nbparam = atoi(param->c_str()); |
---|
48 | if ( nbparam != abstractElement_->getNbParams()) { |
---|
49 | if ( static_cast<GWt_console*> (wApp->findWidget ("console"))) { |
---|
50 | GWt_console* console = static_cast<GWt_console*> (wApp->findWidget ("console")); |
---|
51 | console->addConsoleMessage(" element seems not to be a " + abstractElement_->getNomdElement().getExpandedName()); |
---|
52 | } |
---|
53 | } |
---|
54 | |
---|
55 | dialog_ = new WDialog("element "+abstractElement_->getNomdElement().getExpandedName()); |
---|
56 | new WText(" label of the element : ",dialog_->contents()); |
---|
57 | labelEdit_ = new WLineEdit( (++param)->c_str(),dialog_->contents()); |
---|
58 | new WBreak(dialog_->contents()); |
---|
59 | return ++param; |
---|
60 | } |
---|
61 | |
---|
62 | void GWt_abstractElement::updateLabelAndToolTipWidget() |
---|
63 | { |
---|
64 | if (abstractElement_ != NULL) { |
---|
65 | elementLigneFaiseauContainer_->setElementLabel(abstractElement_->getLabel()); |
---|
66 | setToolTip(print()); |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | void GWt_abstractElement::showParameters() |
---|
71 | { |
---|
72 | initilializeDialog(); |
---|
73 | dialog_->show(); |
---|
74 | } |
---|
75 | |
---|
76 | void GWt_abstractElement::deleteElement() |
---|
77 | { |
---|
78 | StandardButton result = WMessageBox::show("PSPA : Delete element", WString("Delete '")+WString(getAbstractElement()->getLabel())+"' ?", Ok | Cancel); |
---|
79 | |
---|
80 | if (result == Cancel) { |
---|
81 | return; |
---|
82 | } |
---|
83 | // get LigneFaiseau widget and add new elementLigneFaiseau |
---|
84 | GWt_ligneFaisceau* ligneFaisceau = NULL; |
---|
85 | if ( static_cast<GWt_ligneFaisceau*> (wApp->findWidget ("ligneFaisceau"))) { |
---|
86 | ligneFaisceau = static_cast<GWt_ligneFaisceau*> (wApp->findWidget ("ligneFaisceau")); |
---|
87 | } else { |
---|
88 | return; |
---|
89 | } |
---|
90 | |
---|
91 | ligneFaisceau->removeElement(this); |
---|
92 | } |
---|
93 | |
---|
94 | void GWt_abstractElement::createDragImage(WContainerWidget* w) |
---|
95 | { |
---|
96 | GWt_draggableImage *result= new GWt_draggableImage(getBigImageURL(),w); |
---|
97 | |
---|
98 | /* |
---|
99 | * Set the image to be draggable, showing the other image (dragImage) |
---|
100 | * to be used as the widget that is visually dragged. |
---|
101 | */ |
---|
102 | result->setDraggable(getMimeType(),new WImage(getSmallImageURL(),w),true); |
---|
103 | result->setToolTip(getName()); |
---|
104 | } |
---|
105 | |
---|
106 | void GWt_abstractElement::FileInput(ifstream& ifs) |
---|
107 | { |
---|
108 | getAbstractElement()->FileInput(ifs); |
---|
109 | initilializeDialog(); |
---|
110 | updateLabelAndToolTipWidget(); |
---|
111 | |
---|
112 | // update parameters |
---|
113 | GWt_ligneFaisceau* ligneFaisceau = NULL; |
---|
114 | if ( static_cast<GWt_ligneFaisceau*> (wApp->findWidget ("ligneFaisceau"))) { |
---|
115 | ligneFaisceau = static_cast<GWt_ligneFaisceau*> (wApp->findWidget ("ligneFaisceau")); |
---|
116 | ligneFaisceau->update(); |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | abstractElement* GWt_abstractElement::getAbstractElement() { |
---|
121 | return abstractElement_; |
---|
122 | } |
---|
123 | |
---|
124 | WContainerWidget* GWt_abstractElement::getWidget() { |
---|
125 | return wc_; |
---|
126 | } |
---|
127 | |
---|
128 | WImage* GWt_abstractElement::getImage() { |
---|
129 | return image_; |
---|
130 | } |
---|
131 | |
---|
132 | variant<int, string, bool, float, NullType> GWt_abstractElement::getParamValue(string elem) |
---|
133 | { |
---|
134 | if(parameterMapValue.find(elem) == parameterMapValue.end()) { |
---|
135 | return new NullType(); |
---|
136 | } |
---|
137 | |
---|
138 | std::map<std::string, variant<int, string, bool, float, NullType> >::iterator it; |
---|
139 | it = parameterMapValue.find(elem); |
---|
140 | variant <int, string, bool, float, NullType> value = it->second; |
---|
141 | |
---|
142 | try { |
---|
143 | int pi = boost::get<int>(value); |
---|
144 | printf("%s Type is int\n",elem.c_str()); |
---|
145 | return pi; |
---|
146 | } |
---|
147 | catch (boost::bad_get v) { |
---|
148 | try { |
---|
149 | string si = boost::get<string>(value); |
---|
150 | printf("%s Type is string\n",elem.c_str()); |
---|
151 | return si; |
---|
152 | } |
---|
153 | catch (boost::bad_get v) { |
---|
154 | try { |
---|
155 | bool bi = boost::get<bool>(value); |
---|
156 | printf("%s Type is bool\n",elem.c_str()); |
---|
157 | return bi; |
---|
158 | } |
---|
159 | catch (boost::bad_get v) { |
---|
160 | printf("%s Type is NULL\n",elem.c_str()); |
---|
161 | return new NullType(); |
---|
162 | } |
---|
163 | } |
---|
164 | } |
---|
165 | printf("%s Type is NULL NULL\n",elem.c_str()); |
---|
166 | return new NullType(); |
---|
167 | } |
---|
168 | |
---|
169 | string GWt_abstractElement::getParamDescription(string elem) |
---|
170 | { |
---|
171 | if(parameterMapDescription.find(elem) == parameterMapDescription.end() ) { |
---|
172 | printf("%s Descr is NULL NULL\n",elem.c_str()); |
---|
173 | return ""; |
---|
174 | } else { |
---|
175 | printf("%s Descr is %s\n",elem.c_str(),parameterMapDescription.find(elem)->second.c_str()); |
---|
176 | return parameterMapDescription.find(elem)->second; |
---|
177 | } |
---|
178 | } |
---|