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"; }
91 QWidget* buildEditor(Property* ) {
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);
177 virtual std::string
type() = 0;
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);
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;
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);
272 template <
typename T>
273 class PropertyTpl :
public Property {
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); }
383 template <
typename Scalar>
390 #if __cplusplus >= 201103L
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) {
424 template <
typename T,
typename RangeT>
425 class RangedPropertyTpl :
public PropertyTpl<T>,
public Range<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)) {
479 template <
typename 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); }
520 template <
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"; }
593 bool impl_set(
const std::string& value);
620 virtual void setDirty(
bool dirty =
true) = 0;
632 template <
typename T>
638 template <
typename T>
653 void addProperty(
const std::string& name,
const PropertyPtr_t& prop);
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
viewer::Configuration Configuration
Definition: configuration.hh:30
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
virtual QWidget * guiEditor()
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
virtual void setDirty(bool dirty=true)=0
Called when a property is modified.
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
Scalar min
Definition: node-property.h:385
::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
void addProperty(const PropertyPtr_t &prop)
Add a property and take ownership.
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
virtual bool impl_set(void)
static Ptr_t create(const std::string &name, const MetaEnum *type, const Getter_t &g, const Setter_t &s)
Definition: node-property.h:573
Scalar max
Definition: node-property.h:385
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
virtual bool impl_get(void)
Definition: action-search-bar.hh:26
virtual QWidget * guiEditor()
Definition: node-property.h:183
shared_ptr< RangedPropertyTpl > Ptr_t
Definition: node-property.h:429
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
bool hasProperty(const std::string &name) const
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
virtual bool hasReadAccess() const =0
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
virtual std::string type()=0
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
Property(const std::string &name)
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
virtual bool hasWriteAccess() const =0
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
Property * property(const std::string &name) const
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