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>
42template <
typename T,
typename RangeT = T>
43class RangedPropertyTpl;
48struct property_type {};
50struct property_type<const T> : property_type<T> {};
52struct property_type<T&> : property_type<T> {};
54struct property_type<void> {
55 static inline std::string to_string() {
return "void"; }
58struct property_type<bool> {
59 static inline std::string to_string() {
return "bool"; }
62struct property_type<int> {
63 static inline std::string to_string() {
return "int"; }
66struct property_type<float> {
67 static inline std::string to_string() {
return "float"; }
70struct 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"; }
91QWidget* buildEditor(Property* ) {
95QWidget* buildEditor<bool>(Property* property);
97QWidget* buildEditor<int>(Property* property);
99QWidget* buildEditor<float>(Property* property);
101QWidget* buildEditor<std::string>(Property* property);
103QWidget* buildEditor<osgVector2>(Property* property);
105QWidget* buildEditor<osgVector3>(Property* property);
107QWidget* buildEditor<osgVector4>(Property* property);
109QWidget* buildEditor<Configuration>(Property* property);
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);
177 virtual std::string
type() = 0;
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;
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);
277 typedef shared_ptr<PropertyTpl>
Ptr_t;
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>
316 RetType (Obj::*mem_get)() const,
317 void (Obj::*mem_set)(const T&)) {
319 Setter_t(boost::bind(mem_set, obj, _1)));
321 template <
typename Obj,
typename RetType>
323 RetType (Obj::*mem_get)() const,
324 void (Obj::*mem_set)(T)) {
326 Setter_t(boost::bind(mem_set, obj, _1)));
328 template <
typename Obj,
typename RetType>
330 RetType (Obj::*mem_get)() const) {
333 template <
typename Obj>
335 void (Obj::*mem_set)(const T&)) {
338 template <
typename Obj,
typename RetType>
340 void (Obj::*mem_set)(T)) {
358 virtual QWidget*
guiEditor() {
return details::buildEditor<T>(
this); }
383template <
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)),
400#if __cplusplus >= 201103L
401 inline bool hasMin()
const {
402 return min > std::numeric_limits<Scalar>::lowest();
408 return max < std::numeric_limits<Scalar>::max();
412 void setRange(
const Scalar& minimum,
const Scalar& maximum) {
416 void setRange(
const Scalar& minimum,
const Scalar& maximum,
417 const Scalar& _step) {
424template <
typename T,
typename RangeT>
429 typedef shared_ptr<RangedPropertyTpl>
Ptr_t;
442 template <
typename Obj,
typename RetType>
444 RetType (Obj::*mem_get)() const,
445 void (Obj::*mem_set)(const T&)) {
447 Setter_t(boost::bind(mem_set, obj, _1)));
449 template <
typename Obj,
typename RetType>
451 RetType (Obj::*mem_get)() const,
452 void (Obj::*mem_set)(T)) {
454 Setter_t(boost::bind(mem_set, obj, _1)));
456 template <
typename Obj,
typename RetType>
458 RetType (Obj::*mem_get)() const) {
461 template <
typename Obj>
463 void (Obj::*mem_set)(const T&)) {
466 template <
typename Obj,
typename RetType>
468 void (Obj::*mem_set)(T)) {
483 typedef shared_ptr<StoredPropertyTpl>
Ptr_t;
489 virtual std::string
type() {
return details::property_type<T>::to_string(); }
498 virtual QWidget*
guiEditor() {
return details::buildEditor<T>(
this); }
520template <
typename T,
typename RangeT>
522 public Range<RangeT> {
524 typedef shared_ptr<RangedStoredPropertyTpl>
Ptr_t;
571 typedef shared_ptr<EnumProperty>
Ptr_t;
577 virtual std::string
type() {
return "enum"; }
632 template <
typename T>
638 template <
typename T>
653 void addProperty(
const std::string& name,
const PropertyPtr_t& prop);
Definition node-property.h:567
bool impl_get(std::string &v)
Get the enum property as a string.
EnumProperty(const std::string &name, const MetaEnum *type, const Getter_t &g, const Setter_t &s)
Definition node-property.h:580
shared_ptr< EnumProperty > Ptr_t
Definition node-property.h:571
bool impl_set(const int &value)
boost::function< T(void)> Getter_t
Definition node-property.h:276
virtual QWidget * guiEditor()
const MetaEnum * metaEnum() const
Definition node-property.h:578
bool impl_get(int &v)
Get the enum property as an integer.
static Ptr_t create(const std::string &name, const MetaEnum *type, const Getter_t &g, const Setter_t &s)
Definition node-property.h:573
boost::function< void(const T &)> Setter_t
Definition node-property.h:275
virtual std::string type()
Definition node-property.h:577
bool impl_set(const std::string &value)
Definition node-property.h:605
void addProperty(const std::string &name, const PropertyPtr_t &prop)
Add a property and take ownership.
bool getProperty(const std::string &name, T &value) const
Definition node-property.h:633
void addProperty(const std::string &name, Property *prop)
Add a property and leave ownership.
const PropertyMap_t & properties() const
Definition node-property.h:647
void addProperty(const PropertyPtr_t &prop)
Add a property and take ownership.
void addProperty(Property *prop)
Add a property and leave ownership.
Property * property(const std::string &name) const
bool hasProperty(const std::string &name) const
std::map< std::string, Wrapper > PropertyMap_t
Definition node-property.h:614
PropertyMap_t properties_
Definition node-property.h:617
bool setProperty(const std::string &name, const T &value)
Set a property and set this object as dirty.
Definition node-property.h:639
bool callVoidProperty(const std::string &name) const
Definition node-property.h:628
virtual void setDirty(bool dirty=true)=0
Called when a property is modified.
Definition node-property.h:273
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
static Setter_t setterFromMemberFunction(Obj *obj, void(Obj::*mem_func)(const T &))
Definition node-property.h:304
void getter(const Getter_t &g)
Definition node-property.h:353
const Setter_t & setter() const
Definition node-property.h:355
virtual QWidget * guiEditor()
Definition node-property.h:358
virtual bool impl_get(T &value)
Definition node-property.h:369
static Getter_t getterFromMemberFunction(Obj *obj, const T &(Obj::*mem_func)() const)
Definition node-property.h:293
void setter(const Setter_t &s)
Definition node-property.h:356
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
boost::function< T(void)> Getter_t
Definition node-property.h:276
static Setter_t setterFromMemberFunction(Obj *obj, void(Obj::*mem_func)(T))
Definition node-property.h:309
const Getter_t & getter() const
Definition node-property.h:352
static Ptr_t create(const std::string &name, const Getter_t &g)
Definition node-property.h:283
bool hasReadAccess() const
Definition node-property.h:349
PropertyTpl(const std::string &name, const Getter_t &g, const Setter_t &s)
Definition node-property.h:344
virtual std::string type()
Definition node-property.h:290
static Ptr_t createRO(const std::string &name, Obj *obj, RetType(Obj::*mem_get)() const)
Definition node-property.h:329
bool hasWriteAccess() const
Definition node-property.h:350
shared_ptr< PropertyTpl > Ptr_t
Definition node-property.h:277
static Ptr_t createWO(const std::string &name, Obj *obj, void(Obj::*mem_set)(T))
Definition node-property.h:339
static Getter_t getterFromMemberFunction(Obj *obj, T(Obj::*mem_func)() const)
Definition node-property.h:299
static Ptr_t create(const std::string &name, const Getter_t &g, const Setter_t &s)
Definition node-property.h:279
boost::function< void(const T &)> Setter_t
Definition node-property.h:275
static Ptr_t createWO(const std::string &name, Obj *obj, void(Obj::*mem_set)(const T &))
Definition node-property.h:334
virtual bool impl_set(const T &value)
Definition node-property.h:361
static Ptr_t create(const std::string &name, const Setter_t &s)
Definition node-property.h:286
virtual ~PropertyTpl()
Definition node-property.h:347
Abstract base class for runtime properties of Node.
Definition node-property.h:114
virtual bool impl_get(std::string &v)
bool get(Configuration &v)
virtual bool impl_get(osgVector4 &v)
virtual bool impl_get(osgVector3 &v)
virtual bool impl_set(const std::string &v)
virtual bool impl_set(const osgVector3 &v)
bool set(const QColor &v)
void valueChanged(const int &v)
void invalidGet() const
Definition node-property.h:213
bool set(const QString &v)
bool set(const osgVector4 &v)
virtual bool impl_get(osgVector2 &v)
void valueChanged(const osgVector3 &v)
virtual bool hasReadAccess() const =0
void valueChanged(const std::string &v)
void valueChanged(const QString &v)
Property(const std::string &name)
virtual bool impl_get(bool &v)
void invalidSet() const
Definition node-property.h:216
virtual bool impl_get(int &v)
virtual bool hasWriteAccess() const =0
virtual bool impl_set(const osgVector2 &v)
void valueChanged(const double &v)
virtual bool impl_set(const bool &v)
virtual bool impl_set(const int &v)
bool set(const osgVector3 &v)
void valueChanged(const bool &v)
const std::string & name() const
Definition node-property.h:179
bool set(const osgVector2 &v)
void valueChanged(const float &v)
void valueChanged(const osgVector2 &v)
virtual bool impl_get(float &v)
bool set(const double &v)
virtual ~Property()
Definition node-property.h:209
virtual bool impl_set(const Configuration &v)
virtual bool impl_get(Configuration &v)
virtual bool impl_set(const osgVector4 &v)
virtual bool impl_set(const float &v)
bool set(const Configuration &v)
void valueChanged(const osgVector4 &v)
void valueChanged(const Configuration &v)
bool set(const std::string &v)
virtual bool impl_set(void)
void valueChanged(const QColor &v)
virtual std::string type()=0
const std::string name_
Definition node-property.h:211
virtual bool impl_get(void)
virtual QWidget * guiEditor()
Definition node-property.h:183
Definition node-property.h:425
boost::function< void(const T &)> Setter_t
Definition node-property.h:427
boost::function< T(void)> Getter_t
Definition node-property.h:428
virtual ~RangedPropertyTpl()
Definition node-property.h:476
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
RangedPropertyTpl(const std::string &name, const Getter_t &g, const Setter_t &s)
Definition node-property.h:472
static Ptr_t createWO(const std::string &name, Obj *obj, void(Obj::*mem_set)(T))
Definition node-property.h:467
static Ptr_t create(const std::string &name, const Getter_t &g, const Setter_t &s)
Definition node-property.h:431
static Ptr_t createWO(const std::string &name, Obj *obj, void(Obj::*mem_set)(const T &))
Definition node-property.h:462
static Ptr_t create(const std::string &name, const Setter_t &s)
Definition node-property.h:438
shared_ptr< RangedPropertyTpl > Ptr_t
Definition node-property.h:429
static Ptr_t create(const std::string &name, const Getter_t &g)
Definition node-property.h:435
static Ptr_t createRO(const std::string &name, Obj *obj, RetType(Obj::*mem_get)() const)
Definition node-property.h:457
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:522
static Ptr_t create(const std::string &name)
Definition node-property.h:526
virtual ~RangedStoredPropertyTpl()
Definition node-property.h:533
RangedStoredPropertyTpl(const std::string &name)
Definition node-property.h:530
shared_ptr< RangedStoredPropertyTpl > Ptr_t
Definition node-property.h:524
Definition node-property.h:480
bool hasReadAccess() const
Definition node-property.h:495
bool impl_set(const T &v)
Definition node-property.h:506
const Callback_t & callback() const
Definition node-property.h:500
virtual std::string type()
Definition node-property.h:489
virtual QWidget * guiEditor()
Definition node-property.h:498
bool impl_get(T &v)
Definition node-property.h:512
Callback_t callback_
Definition node-property.h:517
shared_ptr< StoredPropertyTpl > Ptr_t
Definition node-property.h:483
StoredPropertyTpl(const std::string &name)
Definition node-property.h:491
T value
Definition node-property.h:503
virtual ~StoredPropertyTpl()
Definition node-property.h:493
bool hasWriteAccess() const
Definition node-property.h:496
void callback(const Callback_t &s)
Definition node-property.h:501
boost::function< void()> Callback_t
Definition node-property.h:482
static Ptr_t create(const std::string &name)
Definition node-property.h:485
Definition node-property.h:221
void function(const Function_t &f)
Definition node-property.h:253
VoidProperty(const std::string &name, const Function_t &f)
Definition node-property.h:244
const Function_t & function() const
Definition node-property.h:252
bool hasWriteAccess() const
Definition node-property.h:250
shared_ptr< VoidProperty > Ptr_t
Definition node-property.h:224
bool impl_get(void)
Definition node-property.h:258
bool hasReadAccess() const
Definition node-property.h:249
static Ptr_t create(const std::string &name, const Function_t &f)
Definition node-property.h:226
virtual ~VoidProperty()
Definition node-property.h:247
boost::function< void(void)> Function_t
Definition node-property.h:223
bool impl_set(void)
Definition node-property.h:266
virtual std::string type()
Definition node-property.h:229
static Function_t memberFunction(Obj *obj, ReturnType(Obj::*mem_func)() const)
Definition node-property.h:239
static Function_t memberFunction(Obj *obj, ReturnType(Obj::*mem_func)())
Definition node-property.h:234
::osg::Vec3f osgVector3
Definition config-osg.h:99
::osg::Vec2f osgVector2
Definition config-osg.h:98
::osg::Vec4f osgVector4
Definition config-osg.h:100
viewer::Configuration Configuration
Definition configuration.hh:30
MetaEnum * glImmediateModeEnum()
PropertyTpl< osgVector4 > Vector4Property
Definition node-property.h:542
PropertyTpl< float > FloatProperty
Definition node-property.h:538
RangedPropertyTpl< int > RangedIntProperty
Definition node-property.h:545
PropertyTpl< std::string > StringProperty
Definition node-property.h:539
PropertyTpl< osgVector2 > Vector2Property
Definition node-property.h:540
PropertyTpl< osgVector3 > Vector3Property
Definition node-property.h:541
RangedPropertyTpl< osgVector3, float > RangedVector3Property
Definition node-property.h:548
RangedPropertyTpl< float > RangedFloatProperty
Definition node-property.h:546
MetaEnum * visibilityModeEnum()
PropertyTpl< bool > BoolProperty
Definition node-property.h:536
PropertyTpl< Configuration > ConfigurationProperty
Definition node-property.h:543
RangedPropertyTpl< osgVector4, float > RangedVector4Property
Definition node-property.h:549
RangedPropertyTpl< Configuration, float > RangedConfigurationProperty
Definition node-property.h:550
MetaEnum * lightingModeEnum()
RangedPropertyTpl< osgVector2, float > RangedVector2Property
Definition node-property.h:547
MetaEnum * wireFrameModeEnum()
PropertyTpl< int > IntProperty
Definition node-property.h:537
Definition action-search-bar.hh:27
#define __cplusplus
Definition moc_predefs.h:161
Definition config-osg.h:115
Definition node-property.h:607
Property * p
Definition node-property.h:608
Wrapper(Property *p)
Definition node-property.h:610
Wrapper(PropertyPtr_t p)
Definition node-property.h:611
Property * operator->() const
Definition node-property.h:612
PropertyPtr_t lock
Definition node-property.h:609
Definition node-property.h:384
Range()
Definition node-property.h:388
bool hasMax() const
Definition node-property.h:407
void setRange(const Scalar &minimum, const Scalar &maximum)
Definition node-property.h:412
void setRange(const Scalar &minimum, const Scalar &maximum, const Scalar &_step)
Definition node-property.h:416
bool hasMin() const
Definition node-property.h:405
Scalar step
Definition node-property.h:385
bool hasRange() const
Definition node-property.h:410
bool adaptiveDecimal
Definition node-property.h:386
Scalar max
Definition node-property.h:385
Scalar min
Definition node-property.h:385