OpenCOVER
GenericGuiObject.h
Go to the documentation of this file.
1/* This file is part of COVISE.
2
3 You can use it under the terms of the GNU Lesser General Public License
4 version 2.1 or later, see lgpl-2.1.txt.
5
6 * License: LGPL 2+ */
7
8/****************************************************************************\
9 ** (C)2010 Visenso **
10 ** **
11 ** Description: GenericGuiObject **
12 ** Provides a generic object with parameters displayed in **
13 ** vr-prepare. **
14 ** **
15 ** Author: C. Spenrath **
16 ** **
17 ** **
18 ** Use: **
19 ** Let your objects inherit from GenericGuiObject. **
20 ** Call guiToRenderMsg(msg) in your plugins guiToRenderMsg function. **
21 ** **
22 ** You add params by calling addGuiParam* in the objects **
23 ** constructor. Use setValue and getValue to access the value. **
24 ** setValue forwards to change to vr-prepare. You can override **
25 ** guiParamChanged to act on param changes from vr-prepare. **
26 ** **
27 ** Use addNextPresStepAllowed to add a param which controls whether **
28 ** the next PresentationStep is allowed. You have to make sure the **
29 ** value is correct all the time. **
30 ** **
31\****************************************************************************/
32
33#ifndef _GENERIC_GUI_OBJECT_H
34#define _GENERIC_GUI_OBJECT_H
35
36#include <osg/Matrix>
37#include <osg/Vec3>
38
39#include <util/coExport.h>
40#include <cover/coTabletUI.h>
41
42#include <string>
43#include <sstream>
44#include <map>
45#include <cstring>
46#include <cstdlib>
47
48namespace opencover
49{
50
51class GenericGuiObject;
52class PLUGIN_UTILEXPORT GuiTuiMapper
53{
54public:
58 int getParentID(std::string &name);
59 std::map<std::string, GenericGuiObject *> parents;
60
61private:
62 static GuiTuiMapper *inst;
63};
64
65class PLUGIN_UTILEXPORT GuiParam
66{
67 friend class GenericGuiObject; // GenericGuiObject needs access to setValueFromGui
68
69public:
70 GuiParam(std::string parentName, std::string name)
71 : parentName_(parentName)
72 , name_(name)
73 {
74 e = GuiTuiMapper::instance()->parents[parentName];
75 };
76 virtual ~GuiParam(){};
77
78 std::string getName()
79 {
80 return name_;
81 };
82 virtual int getType() = 0;
83
84protected:
85 virtual void setValueFromGui(const char *value) = 0;
86 virtual std::string getValueAsString() = 0;
87 virtual std::string getDefaultValueAsString() = 0;
91
92private:
93 std::string parentName_;
94 std::string name_;
95};
96
97class PLUGIN_UTILEXPORT GuiParamBool : public GuiParam, public coTUIListener
98{
99public:
100 GuiParamBool(std::string parentName, std::string name, bool defaultValue);
102
104 {
105 return 0;
106 };
107 bool getValue()
108 {
109 return value_;
110 };
111 void setValue(bool value)
112 {
113 bool c = (value != value_);
114 value_ = value;
115 if (c)
116 sendChangeToGui();
117 tuiToggleButton->setState(value);
118 };
119
120private:
121 void setValueFromGui(const char *value)
122 {
123 value_ = (strcmp(value, "0") != 0);
124 };
125 std::string getValueAsString()
126 {
127 return value_ ? "1" : "0";
128 };
129 std::string getDefaultValueAsString()
130 {
131 return defaultValue_ ? "1" : "0";
132 };
133
134 bool value_, defaultValue_;
135 virtual void tabletEvent(coTUIElement *tUIItem);
136 coTUIToggleButton *tuiToggleButton;
137};
138
139class PLUGIN_UTILEXPORT GuiParamInt : public GuiParam, public coTUIListener
140{
141public:
142 GuiParamInt(std::string parentName, std::string name, int defaultValue);
144
146 {
147 return 1;
148 };
150 {
151 return value_;
152 };
153 void setValue(int value)
154 {
155 bool c = (value != value_);
156 value_ = value;
157 if (c)
158 sendChangeToGui();
159 tuiEdit->setValue(value);
160 };
161
162private:
163 void setValueFromGui(const char *value)
164 {
165 value_ = atoi(value);
166 };
167 std::string getValueAsString()
168 {
169 std::stringstream sstr;
170 sstr << value_;
171 return sstr.str();
172 };
173 std::string getDefaultValueAsString()
174 {
175 std::stringstream sstr;
176 sstr << defaultValue_;
177 return sstr.str();
178 };
179
180 int value_, defaultValue_;
181 virtual void tabletEvent(coTUIElement *tUIItem);
182 coTUIEditIntField *tuiEdit;
183 coTUILabel *tuiLabel;
184};
185
186class PLUGIN_UTILEXPORT GuiParamFloat : public GuiParam, public coTUIListener
187{
188public:
189 GuiParamFloat(std::string parentName, std::string name, float defaultValue);
191
193 {
194 return 2;
195 };
196 float getValue()
197 {
198 return value_;
199 };
200 void setValue(float value)
201 {
202 bool c = (value != value_);
203 value_ = value;
204 if (c)
205 sendChangeToGui();
206 };
207
208private:
209 void setValueFromGui(const char *value)
210 {
211 value_ = atof(value);
212 };
213 std::string getValueAsString()
214 {
215 std::stringstream sstr;
216 sstr << value_;
217 return sstr.str();
218 };
219 std::string getDefaultValueAsString()
220 {
221 std::stringstream sstr;
222 sstr << defaultValue_;
223 return sstr.str();
224 };
225
226 float value_, defaultValue_;
227 virtual void tabletEvent(coTUIElement *tUIItem);
228 coTUIEditFloatField *tuiEdit;
229 coTUILabel *tuiLabel;
230};
231
232class PLUGIN_UTILEXPORT GuiParamString : public GuiParam, public coTUIListener
233{
234public:
235 GuiParamString(std::string parentName, std::string name, std::string defaultValue);
237
239 {
240 return 3;
241 };
242 std::string getValue()
243 {
244 return value_;
245 };
246 void setValue(std::string value)
247 {
248 bool c = (value != value_);
249 value_ = value;
250 if (c)
251 sendChangeToGui();
252 };
253
254private:
255 void setValueFromGui(const char *value)
256 {
257 value_ = std::string(value);
258 };
259 std::string getValueAsString()
260 {
261 return value_;
262 };
263 std::string getDefaultValueAsString()
264 {
265 return defaultValue_;
266 };
267
268 std::string value_, defaultValue_;
269 virtual void tabletEvent(coTUIElement *tUIItem);
270 coTUIEditField *tuiEdit;
271 coTUILabel *tuiLabel;
272};
273
274class PLUGIN_UTILEXPORT GuiParamVec3 : public GuiParam
275{
276public:
277 GuiParamVec3(std::string parentName, std::string name, osg::Vec3 defaultValue)
278 : GuiParam(parentName, name)
279 , value_(defaultValue)
280 , defaultValue_(defaultValue)
281 {
282 registerAtGui();
283 };
285
287 {
288 return 4;
289 };
290 osg::Vec3 getValue()
291 {
292 return value_;
293 };
294 void setValue(osg::Vec3 value)
295 {
296 bool c = (value != value_);
297 value_ = value;
298 if (c)
299 sendChangeToGui();
300 };
301
302private:
303 void setValueFromGui(const char *value)
304 {
305 std::stringstream sstr(value);
306 std::string s;
307 for (int i = 0; i < 3; ++i)
308 {
309 getline(sstr, s, '/');
310 value_[i] = atof(s.c_str());
311 }
312 };
313 std::string getValueAsString()
314 {
315 std::stringstream sstr;
316 sstr << value_[0] << "/" << value_[1] << "/" << value_[2];
317 return sstr.str();
318 };
319 std::string getDefaultValueAsString()
320 {
321 std::stringstream sstr;
322 sstr << defaultValue_[0] << "/" << defaultValue_[1] << "/" << defaultValue_[2];
323 return sstr.str();
324 };
325
326 osg::Vec3 value_, defaultValue_;
327};
328
329class PLUGIN_UTILEXPORT GuiParamMatrix : public GuiParam
330{
331public:
332 GuiParamMatrix(std::string parentName, std::string name, osg::Matrix defaultValue)
333 : GuiParam(parentName, name)
334 , value_(defaultValue)
335 , defaultValue_(defaultValue)
336 {
337 registerAtGui();
338 };
340
342 {
343 return 5;
344 };
345 osg::Matrix getValue()
346 {
347 return value_;
348 };
349 void setValue(osg::Matrix value)
350 {
351 bool c = (value != value_);
352 value_ = value;
353 if (c)
354 sendChangeToGui();
355 };
356
357private:
358 void setValueFromGui(const char *value)
359 {
360 std::stringstream sstr(value);
361 std::string s;
362 for (int i = 0; i < 4; ++i)
363 for (int j = 0; j < 4; ++j)
364 {
365 getline(sstr, s, '/');
366 value_(i, j) = atof(s.c_str());
367 }
368 };
369 std::string getValueAsString()
370 {
371 std::stringstream sstr;
372 sstr << value_(0, 0) << "/" << value_(0, 1) << "/" << value_(0, 2) << "/" << value_(0, 3) << "/" << value_(1, 0) << "/" << value_(1, 1) << "/" << value_(1, 2) << "/" << value_(1, 3) << "/" << value_(2, 0) << "/" << value_(2, 1) << "/" << value_(2, 2) << "/" << value_(2, 3) << "/" << value_(3, 0) << "/" << value_(3, 1) << "/" << value_(3, 2) << "/" << value_(3, 3);
373 return sstr.str();
374 };
375 std::string getDefaultValueAsString()
376 {
377 std::stringstream sstr;
378 sstr << defaultValue_(0, 0) << "/" << defaultValue_(0, 1) << "/" << defaultValue_(0, 2) << "/" << defaultValue_(0, 3) << "/" << defaultValue_(1, 0) << "/" << defaultValue_(1, 1) << "/" << defaultValue_(1, 2) << "/" << defaultValue_(1, 3) << "/" << defaultValue_(2, 0) << "/" << defaultValue_(2, 1) << "/" << defaultValue_(2, 2) << "/" << defaultValue_(2, 3) << "/" << defaultValue_(3, 0) << "/" << defaultValue_(3, 1) << "/" << defaultValue_(3, 2) << "/" << defaultValue_(3, 3);
379 return sstr.str();
380 };
381
382 osg::Matrix value_, defaultValue_;
383};
384
385class PLUGIN_UTILEXPORT GenericGuiObject
386{
387public:
388 GenericGuiObject(std::string genericObjectName);
390
392
393 GuiParamBool *addGuiParamBool(std::string paramName, bool defaultValue);
394 GuiParamInt *addGuiParamInt(std::string paramName, int defaultValue);
395 GuiParamFloat *addGuiParamFloat(std::string paramName, float defaultValue);
396 GuiParamString *addGuiParamString(std::string paramName, std::string defaultValue);
397 GuiParamVec3 *addGuiParamVec3(std::string paramName, osg::Vec3 defaultValue);
398 GuiParamMatrix *addGuiParamMatrix(std::string paramName, osg::Matrix defaultValue);
399
400 void guiToRenderMsg(const char *msg);
403 {
404 ParamPos++;
405 return (ParamPos - 1);
406 };
407 virtual void guiParamChanged(GuiParam *guiParam)
408 {
409 (void)guiParam;
410 };
411
412protected:
413private:
414 std::string genericObjectName_;
415 std::map<std::string, GuiParam *> guiParams_;
416 int ParamPos;
417};
418}
419#endif
Tablet user interface proxy classes.
Definition: ARToolKit.h:33
Definition: coTabletUI.h:672
Action listener for events triggered by any coTUIElement.
Definition: coTUIListener.h:61
Definition: GenericGuiObject.h:53
GuiTuiMapper()
Definition: GenericGuiObject.h:55
~GuiTuiMapper()
Definition: GenericGuiObject.h:56
int getParentID(std::string &name)
static GuiTuiMapper * instance()
std::map< std::string, GenericGuiObject * > parents
Definition: GenericGuiObject.h:59
Definition: GenericGuiObject.h:66
virtual std::string getDefaultValueAsString()=0
virtual ~GuiParam()
Definition: GenericGuiObject.h:76
GuiParam(std::string parentName, std::string name)
Definition: GenericGuiObject.h:70
virtual int getType()=0
virtual void setValueFromGui(const char *value)=0
virtual std::string getValueAsString()=0
GenericGuiObject * e
Definition: GenericGuiObject.h:90
std::string getName()
Definition: GenericGuiObject.h:78
Definition: GenericGuiObject.h:98
GuiParamBool(std::string parentName, std::string name, bool defaultValue)
int getType()
Definition: GenericGuiObject.h:103
bool getValue()
Definition: GenericGuiObject.h:107
void setValue(bool value)
Definition: GenericGuiObject.h:111
Definition: GenericGuiObject.h:140
void setValue(int value)
Definition: GenericGuiObject.h:153
int getValue()
Definition: GenericGuiObject.h:149
GuiParamInt(std::string parentName, std::string name, int defaultValue)
int getType()
Definition: GenericGuiObject.h:145
Definition: GenericGuiObject.h:187
float getValue()
Definition: GenericGuiObject.h:196
GuiParamFloat(std::string parentName, std::string name, float defaultValue)
int getType()
Definition: GenericGuiObject.h:192
void setValue(float value)
Definition: GenericGuiObject.h:200
Definition: GenericGuiObject.h:233
int getType()
Definition: GenericGuiObject.h:238
void setValue(std::string value)
Definition: GenericGuiObject.h:246
std::string getValue()
Definition: GenericGuiObject.h:242
GuiParamString(std::string parentName, std::string name, std::string defaultValue)
Definition: GenericGuiObject.h:275
osg::Vec3 getValue()
Definition: GenericGuiObject.h:290
~GuiParamVec3()
Definition: GenericGuiObject.h:284
int getType()
Definition: GenericGuiObject.h:286
GuiParamVec3(std::string parentName, std::string name, osg::Vec3 defaultValue)
Definition: GenericGuiObject.h:277
void setValue(osg::Vec3 value)
Definition: GenericGuiObject.h:294
Definition: GenericGuiObject.h:330
int getType()
Definition: GenericGuiObject.h:341
~GuiParamMatrix()
Definition: GenericGuiObject.h:339
osg::Matrix getValue()
Definition: GenericGuiObject.h:345
GuiParamMatrix(std::string parentName, std::string name, osg::Matrix defaultValue)
Definition: GenericGuiObject.h:332
void setValue(osg::Matrix value)
Definition: GenericGuiObject.h:349
Definition: GenericGuiObject.h:386
int getNextPos()
Definition: GenericGuiObject.h:402
GuiParamVec3 * addGuiParamVec3(std::string paramName, osg::Vec3 defaultValue)
GuiParamMatrix * addGuiParamMatrix(std::string paramName, osg::Matrix defaultValue)
GuiParamBool * addNextPresStepAllowed(bool defaultValue)
GuiParamFloat * addGuiParamFloat(std::string paramName, float defaultValue)
GuiParamString * addGuiParamString(std::string paramName, std::string defaultValue)
coTUITab * tab
Definition: GenericGuiObject.h:401
GuiParamInt * addGuiParamInt(std::string paramName, int defaultValue)
void guiToRenderMsg(const char *msg)
GuiParamBool * addGuiParamBool(std::string paramName, bool defaultValue)
virtual void guiParamChanged(GuiParam *guiParam)
Definition: GenericGuiObject.h:407
GenericGuiObject(std::string genericObjectName)