17 #ifndef GEPETTO_VIEWER_NODE_PROPERTY_HH 18 #define GEPETTO_VIEWER_NODE_PROPERTY_HH 24 #include <boost/bind.hpp> 25 #include <boost/function.hpp> 26 #include <boost/mpl/if.hpp> 42 template <
typename T,
typename RangeT = T>
48 struct property_type {};
50 struct property_type<const T> : property_type<T> {};
52 struct property_type<T&> : property_type<T> {};
54 struct property_type<void> {
55 static inline std::string to_string() {
return "void"; }
58 struct property_type<bool> {
59 static inline std::string to_string() {
return "bool"; }
62 struct property_type<int> {
63 static inline std::string to_string() {
return "int"; }
66 struct property_type<float> {
67 static inline std::string to_string() {
return "float"; }
70 struct property_type<std::string> {
71 static inline std::string to_string() {
return "string"; }
75 static inline std::string to_string() {
return "osgVector2"; }
79 static inline std::string to_string() {
return "osgVector3"; }
83 static inline std::string to_string() {
return "osgVector4"; }
87 static inline std::string to_string() {
return "Configuration"; }
95 QWidget* buildEditor<bool>(
Property* property);
97 QWidget* buildEditor<int>(
Property* property);
99 QWidget* buildEditor<float>(
Property* property);
101 QWidget* buildEditor<std::string>(
Property* property);
103 QWidget* buildEditor<osgVector2>(
Property* property);
105 QWidget* buildEditor<osgVector3>(
Property* property);
107 QWidget* buildEditor<osgVector4>(
Property* property);
109 QWidget* buildEditor<Configuration>(
Property* property);
119 bool set(
const bool& v);
120 bool set(
const int& v);
121 bool set(
const float& v);
122 bool set(
const std::string& v);
129 bool set(
const double& v);
132 bool set(
const QString& v);
135 bool set(
const QColor& v);
142 bool get(std::string& v);
151 bool get(QString& v);
156 void valueChanged(
void);
157 void valueChanged(
const bool& v);
158 void valueChanged(
const int& v);
159 void valueChanged(
const float& v);
160 void valueChanged(
const std::string& v);
167 void valueChanged(
const double& v);
169 void valueChanged(
const QString& v);
171 void valueChanged(
const QColor& v);
174 virtual bool hasReadAccess()
const = 0;
175 virtual bool hasWriteAccess()
const = 0;
177 virtual std::string type() = 0;
179 const std::string&
name()
const {
return name_; }
186 virtual bool impl_set(
void);
187 virtual bool impl_set(
const bool& v);
188 virtual bool impl_set(
const int& v);
189 virtual bool impl_set(
const float& v);
190 virtual bool impl_set(
const std::string& v);
196 virtual bool impl_get(
void);
197 virtual bool impl_get(
bool& v);
198 virtual bool impl_get(
int& v);
199 virtual bool impl_get(
float& v);
200 virtual bool impl_get(std::string& v);
214 throw std::logic_error(
"Cannot read property " + name_ +
".");
217 throw std::logic_error(
"Cannot write property " + name_ +
".");
224 typedef shared_ptr<VoidProperty>
Ptr_t;
226 static Ptr_t
create(
const std::string& name,
const Function_t& f) {
230 return details::property_type<void>::to_string();
233 template <
typename Obj,
typename ReturnType>
235 ReturnType (Obj::*mem_func)()) {
236 return boost::bind(mem_func, obj);
238 template <
typename Obj,
typename ReturnType>
240 ReturnType (Obj::*mem_func)()
const) {
241 return boost::bind(mem_func, obj);
252 const Function_t&
function()
const {
return function_; }
253 void function(
const Function_t& f) { function_ = f; }
255 QWidget* guiEditor();
259 if (!hasReadAccess()) {
269 Function_t function_;
272 template <
typename T>
277 typedef shared_ptr<PropertyTpl>
Ptr_t;
279 static Ptr_t
create(
const std::string& name,
const Getter_t& g,
283 static Ptr_t
create(
const std::string& name,
const Getter_t& g) {
284 return Ptr_t(
new PropertyTpl(name, g, Setter_t()));
286 static Ptr_t
create(
const std::string& name,
const Setter_t& s) {
287 return Ptr_t(
new PropertyTpl(name, Getter_t(), s));
290 virtual std::string
type() {
return details::property_type<T>::to_string(); }
292 template <
typename Obj>
294 const T& (Obj::*mem_func)()
296 return boost::bind(mem_func, obj);
298 template <
typename Obj>
300 T (Obj::*mem_func)()
const) {
301 return boost::bind(mem_func, obj);
303 template <
typename Obj>
305 Obj* obj,
void (Obj::*mem_func)(
const T&)) {
306 return boost::bind(mem_func, obj, _1);
308 template <
typename Obj>
310 void (Obj::*mem_func)(T)) {
311 return boost::bind(mem_func, obj, _1);
314 template <
typename Obj,
typename RetType>
315 static Ptr_t
create(
const std::string& name, Obj* obj,
316 RetType (Obj::*mem_get)()
const,
317 void (Obj::*mem_set)(
const T&)) {
318 return create(name, Getter_t(boost::bind(mem_get, obj)),
319 Setter_t(boost::bind(mem_set, obj, _1)));
321 template <
typename Obj,
typename RetType>
322 static Ptr_t
create(
const std::string& name, Obj* obj,
323 RetType (Obj::*mem_get)()
const,
324 void (Obj::*mem_set)(T)) {
325 return create(name, Getter_t(boost::bind(mem_get, obj)),
326 Setter_t(boost::bind(mem_set, obj, _1)));
328 template <
typename Obj,
typename RetType>
329 static Ptr_t
createRO(
const std::string& name, Obj* obj,
330 RetType (Obj::*mem_get)()
const) {
331 return create(name, Getter_t(boost::bind(mem_get, obj)));
333 template <
typename Obj>
334 static Ptr_t
createWO(
const std::string& name, Obj* obj,
335 void (Obj::*mem_set)(
const T&)) {
336 return create(name, Setter_t(boost::bind(mem_set, obj, _1)));
338 template <
typename Obj,
typename RetType>
339 static Ptr_t
createWO(
const std::string& name, Obj* obj,
340 void (Obj::*mem_set)(T)) {
341 return create(name, Setter_t(boost::bind(mem_set, obj, _1)));
344 PropertyTpl(
const std::string& name,
const Getter_t& g,
const Setter_t& s)
345 :
Property(name), getter_(g), setter_(s) {}
352 const Getter_t&
getter()
const {
return getter_; }
353 void getter(
const Getter_t& g) { getter_ = g; }
355 const Setter_t&
setter()
const {
return setter_; }
356 void setter(
const Setter_t& s) { setter_ = s; }
358 virtual QWidget*
guiEditor() {
return details::buildEditor<T>(
this); }
362 if (!hasWriteAccess()) {
370 if (!hasReadAccess()) {
383 template <
typename Scalar>
391 min(std::numeric_limits<Scalar>::lowest()),
393 min(std::numeric_limits<Scalar>::quiet_NaN()),
395 max(std::numeric_limits<Scalar>::max()),
396 step(static_cast<Scalar>(1)),
397 adaptiveDecimal(false) {
400 #if __cplusplus >= 201103L 401 inline bool hasMin()
const {
402 return min > std::numeric_limits<Scalar>::lowest();
405 inline bool hasMin()
const {
return min == min; }
408 return max < std::numeric_limits<Scalar>::max();
410 inline bool hasRange()
const {
return hasMin() && hasMax(); }
412 void setRange(
const Scalar& minimum,
const Scalar& maximum) {
416 void setRange(
const Scalar& minimum,
const Scalar& maximum,
417 const Scalar& _step) {
424 template <
typename T,
typename RangeT>
429 typedef shared_ptr<RangedPropertyTpl>
Ptr_t;
431 static Ptr_t
create(
const std::string& name,
const Getter_t& g,
435 static Ptr_t
create(
const std::string& name,
const Getter_t& g) {
438 static Ptr_t
create(
const std::string& name,
const Setter_t& s) {
442 template <
typename Obj,
typename RetType>
443 static Ptr_t
create(
const std::string& name, Obj* obj,
444 RetType (Obj::*mem_get)()
const,
445 void (Obj::*mem_set)(
const T&)) {
446 return create(name, Getter_t(boost::bind(mem_get, obj)),
447 Setter_t(boost::bind(mem_set, obj, _1)));
449 template <
typename Obj,
typename RetType>
450 static Ptr_t
create(
const std::string& name, Obj* obj,
451 RetType (Obj::*mem_get)()
const,
452 void (Obj::*mem_set)(T)) {
453 return create(name, Getter_t(boost::bind(mem_get, obj)),
454 Setter_t(boost::bind(mem_set, obj, _1)));
456 template <
typename Obj,
typename RetType>
457 static Ptr_t
createRO(
const std::string& name, Obj* obj,
458 RetType (Obj::*mem_get)()
const) {
459 return create(name, Getter_t(boost::bind(mem_get, obj)));
461 template <
typename Obj>
462 static Ptr_t
createWO(
const std::string& name, Obj* obj,
463 void (Obj::*mem_set)(
const T&)) {
464 return create(name, Setter_t(boost::bind(mem_set, obj, _1)));
466 template <
typename Obj,
typename RetType>
467 static Ptr_t
createWO(
const std::string& name, Obj* obj,
468 void (Obj::*mem_set)(T)) {
469 return create(name, Setter_t(boost::bind(mem_set, obj, _1)));
479 template <
typename T>
483 typedef shared_ptr<StoredPropertyTpl>
Ptr_t;
485 static Ptr_t
create(
const std::string& name) {
489 virtual std::string
type() {
return details::property_type<T>::to_string(); }
498 virtual QWidget*
guiEditor() {
return details::buildEditor<T>(
this); }
500 const Callback_t&
callback()
const {
return callback_; }
501 void callback(
const Callback_t& s) { callback_ = s; }
507 bool c(callback_ && value != v);
520 template <
typename T,
typename RangeT>
522 public Range<RangeT> {
524 typedef shared_ptr<RangedStoredPropertyTpl>
Ptr_t;
526 static Ptr_t
create(
const std::string& name) {
558 int from_string(
const std::string& s);
559 std::string to_string(
const int& v);
571 typedef shared_ptr<EnumProperty>
Ptr_t;
574 const Getter_t& g,
const Setter_t& s) {
577 virtual std::string
type() {
return "enum"; }
582 : IntProperty(name, g, s), metaEnum_(type) {}
584 virtual QWidget* guiEditor();
589 bool impl_set(
const int& value);
593 bool impl_set(
const std::string& value);
596 bool impl_get(
int& v);
599 bool impl_get(std::string& v);
611 Wrapper(PropertyPtr_t p) : p(p.get()), lock(p) {}
620 virtual void setDirty(
bool dirty =
true) = 0;
626 Property* property(
const std::string& name)
const;
629 return property(name)->get();
632 template <
typename T>
634 return property(name)->get(value);
638 template <
typename T>
640 bool res = property(name)->set(value);
641 if (res) this->setDirty();
645 bool hasProperty(
const std::string& name)
const;
647 const PropertyMap_t&
properties()
const {
return properties_; }
650 void addProperty(
const PropertyPtr_t& prop);
653 void addProperty(
const std::string& name,
const PropertyPtr_t& prop);
659 void addProperty(
const std::string& name,
Property* prop);
661 QWidget* guiEditor();
RangedPropertyTpl< Configuration, float > RangedConfigurationProperty
Definition: node-property.h:550
shared_ptr< StoredPropertyTpl > Ptr_t
Definition: node-property.h:483
static Ptr_t create(const std::string &name, const Getter_t &g)
Definition: node-property.h:435
T value
Definition: node-property.h:503
Range()
Definition: node-property.h:388
const std::string name_
Definition: node-property.h:211
StoredPropertyTpl(const std::string &name)
Definition: node-property.h:491
PropertyTpl< osgVector2 > Vector2Property
Definition: node-property.h:540
bool hasReadAccess() const
Definition: node-property.h:249
static Getter_t getterFromMemberFunction(Obj *obj, T(Obj::*mem_func)() const)
Definition: node-property.h:299
const Getter_t & getter() const
Definition: node-property.h:352
MetaEnum * wireFrameModeEnum()
bool impl_set(void)
Definition: node-property.h:266
static Ptr_t create(const std::string &name)
Definition: node-property.h:485
PropertyTpl< osgVector4 > Vector4Property
Definition: node-property.h:542
virtual QWidget * guiEditor()
Definition: node-property.h:498
virtual ~VoidProperty()
Definition: node-property.h:247
bool getProperty(const std::string &name, T &value) const
Definition: node-property.h:633
EnumProperty(const std::string &name, const MetaEnum *type, const Getter_t &g, const Setter_t &s)
Definition: node-property.h:580
shared_ptr< PropertyTpl > Ptr_t
Definition: node-property.h:277
static Function_t memberFunction(Obj *obj, ReturnType(Obj::*mem_func)())
Definition: node-property.h:234
::osg::Vec3f osgVector3
Definition: config-osg.h:99
static Setter_t setterFromMemberFunction(Obj *obj, void(Obj::*mem_func)(const T &))
Definition: node-property.h:304
static Ptr_t create(const std::string &name, const Getter_t &g, const Setter_t &s)
Definition: node-property.h:431
const std::string & name() const
Definition: node-property.h:179
MetaEnum * glImmediateModeEnum()
PropertyTpl< int > IntProperty
Definition: node-property.h:537
bool impl_set(const T &v)
Definition: node-property.h:506
MetaEnum * visibilityModeEnum()
static Ptr_t create(const std::string &name, Obj *obj, RetType(Obj::*mem_get)() const, void(Obj::*mem_set)(T))
Definition: node-property.h:450
Definition: node-property.h:605
Callback_t callback_
Definition: node-property.h:517
void callback(const Callback_t &s)
Definition: node-property.h:501
bool hasWriteAccess() const
Definition: node-property.h:496
static Ptr_t create(const std::string &name, Obj *obj, RetType(Obj::*mem_get)() const, void(Obj::*mem_set)(T))
Definition: node-property.h:322
void setter(const Setter_t &s)
Definition: node-property.h:356
Definition: node-property.h:521
virtual std::string type()
Definition: node-property.h:577
virtual ~RangedStoredPropertyTpl()
Definition: node-property.h:533
static Ptr_t create(const std::string &name)
Definition: node-property.h:526
Definition: node-property.h:384
::osg::Vec2f osgVector2
Definition: config-osg.h:98
PropertyMap_t properties_
Definition: node-property.h:617
static Ptr_t create(const std::string &name, Obj *obj, RetType(Obj::*mem_get)() const, void(Obj::*mem_set)(const T &))
Definition: node-property.h:315
static Function_t memberFunction(Obj *obj, ReturnType(Obj::*mem_func)() const)
Definition: node-property.h:239
::osg::Vec4f osgVector4
Definition: config-osg.h:100
shared_ptr< VoidProperty > Ptr_t
Definition: node-property.h:224
boost::function< void(void)> Function_t
Definition: node-property.h:223
static Ptr_t createWO(const std::string &name, Obj *obj, void(Obj::*mem_set)(T))
Definition: node-property.h:467
static Setter_t setterFromMemberFunction(Obj *obj, void(Obj::*mem_func)(T))
Definition: node-property.h:309
Property * p
Definition: node-property.h:608
shared_ptr< EnumProperty > Ptr_t
Definition: node-property.h:571
Definition: node-property.h:43
Definition: node-property.h:607
virtual ~PropertyTpl()
Definition: node-property.h:347
bool hasReadAccess() const
Definition: node-property.h:349
bool hasMax() const
Definition: node-property.h:407
RangedPropertyTpl< int > RangedIntProperty
Definition: node-property.h:545
Definition: node-property.h:221
PropertyTpl< std::string > StringProperty
Definition: node-property.h:539
virtual ~StoredPropertyTpl()
Definition: node-property.h:493
static Ptr_t create(const std::string &name, Obj *obj, RetType(Obj::*mem_get)() const, void(Obj::*mem_set)(const T &))
Definition: node-property.h:443
virtual bool impl_get(T &value)
Definition: node-property.h:369
boost::function< T(void)> Getter_t
Definition: node-property.h:428
static Ptr_t create(const std::string &name, const MetaEnum *type, const Getter_t &g, const Setter_t &s)
Definition: node-property.h:573
RangedPropertyTpl< float > RangedFloatProperty
Definition: node-property.h:546
static Ptr_t create(const std::string &name, const Getter_t &g)
Definition: node-property.h:283
Definition: action-search-bar.hh:27
virtual QWidget * guiEditor()
Definition: node-property.h:183
shared_ptr< RangedPropertyTpl > Ptr_t
Definition: node-property.h:429
#define __cplusplus
Definition: moc_predefs.h:135
RangedPropertyTpl< osgVector3, float > RangedVector3Property
Definition: node-property.h:548
boost::function< void(const T &)> Setter_t
Definition: node-property.h:427
static Ptr_t create(const std::string &name, const Setter_t &s)
Definition: node-property.h:286
virtual bool impl_set(const T &value)
Definition: node-property.h:361
bool hasWriteAccess() const
Definition: node-property.h:250
bool hasReadAccess() const
Definition: node-property.h:495
Definition: node-property.h:480
shared_ptr< RangedStoredPropertyTpl > Ptr_t
Definition: node-property.h:524
PropertyTpl< osgVector3 > Vector3Property
Definition: node-property.h:541
void setRange(const Scalar &minimum, const Scalar &maximum, const Scalar &_step)
Definition: node-property.h:416
Definition: node-property.h:41
virtual QWidget * guiEditor()
Definition: node-property.h:358
RangedPropertyTpl(const std::string &name, const Getter_t &g, const Setter_t &s)
Definition: node-property.h:472
PropertyTpl(const std::string &name, const Getter_t &g, const Setter_t &s)
Definition: node-property.h:344
bool hasMin() const
Definition: node-property.h:405
Scalar step
Definition: node-property.h:385
void getter(const Getter_t &g)
Definition: node-property.h:353
bool impl_get(T &v)
Definition: node-property.h:512
const MetaEnum * metaEnum() const
Definition: node-property.h:578
PropertyTpl< bool > BoolProperty
Definition: node-property.h:536
bool setProperty(const std::string &name, const T &value)
Set a property and set this object as dirty.
Definition: node-property.h:639
PropertyTpl< float > FloatProperty
Definition: node-property.h:538
const PropertyMap_t & properties() const
Definition: node-property.h:647
bool callVoidProperty(const std::string &name) const
Definition: node-property.h:628
virtual std::string type()
Definition: node-property.h:290
MetaEnum * lightingModeEnum()
const Callback_t & callback() const
Definition: node-property.h:500
Definition: config-osg.h:115
boost::function< void()> Callback_t
Definition: node-property.h:482
void setRange(const Scalar &minimum, const Scalar &maximum)
Definition: node-property.h:412
static Ptr_t create(const std::string &name, const Setter_t &s)
Definition: node-property.h:438
RangedPropertyTpl< osgVector4, float > RangedVector4Property
Definition: node-property.h:549
Abstract base class for runtime properties of Node.
Definition: node-property.h:114
virtual ~Property()
Definition: node-property.h:209
bool hasWriteAccess() const
Definition: node-property.h:350
VoidProperty(const std::string &name, const Function_t &f)
Definition: node-property.h:244
const Setter_t & setter() const
Definition: node-property.h:355
static Ptr_t create(const std::string &name, const Function_t &f)
Definition: node-property.h:226
bool hasRange() const
Definition: node-property.h:410
static Ptr_t createWO(const std::string &name, Obj *obj, void(Obj::*mem_set)(const T &))
Definition: node-property.h:334
Property * operator->() const
Definition: node-property.h:612
static Getter_t getterFromMemberFunction(Obj *obj, const T &(Obj::*mem_func)() const)
Definition: node-property.h:293
std::map< std::string, Wrapper > PropertyMap_t
Definition: node-property.h:614
PropertyPtr_t lock
Definition: node-property.h:609
static Ptr_t createRO(const std::string &name, Obj *obj, RetType(Obj::*mem_get)() const)
Definition: node-property.h:329
static Ptr_t createRO(const std::string &name, Obj *obj, RetType(Obj::*mem_get)() const)
Definition: node-property.h:457
static Ptr_t createWO(const std::string &name, Obj *obj, void(Obj::*mem_set)(T))
Definition: node-property.h:339
void invalidSet() const
Definition: node-property.h:216
Definition: node-property.h:567
PropertyTpl< Configuration > ConfigurationProperty
Definition: node-property.h:543
virtual ~RangedPropertyTpl()
Definition: node-property.h:476
static Ptr_t create(const std::string &name, const Getter_t &g, const Setter_t &s)
Definition: node-property.h:279
bool adaptiveDecimal
Definition: node-property.h:386
Wrapper(PropertyPtr_t p)
Definition: node-property.h:611
bool impl_get(void)
Definition: node-property.h:258
void invalidGet() const
Definition: node-property.h:213
boost::function< void(const T &)> Setter_t
Definition: node-property.h:275
Wrapper(Property *p)
Definition: node-property.h:610
RangedPropertyTpl< osgVector2, float > RangedVector2Property
Definition: node-property.h:547
static Ptr_t createWO(const std::string &name, Obj *obj, void(Obj::*mem_set)(const T &))
Definition: node-property.h:462
virtual std::string type()
Definition: node-property.h:229
boost::function< T(void)> Getter_t
Definition: node-property.h:276
virtual std::string type()
Definition: node-property.h:489
RangedStoredPropertyTpl(const std::string &name)
Definition: node-property.h:530