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>
40 template <
typename T>
class PropertyTpl;
41 template <
typename T,
typename RangeT = T>
class RangedPropertyTpl;
45 template <
typename T>
struct property_type {};
46 template <
typename T>
struct property_type <const T > : property_type<T> {};
47 template <
typename T>
struct property_type < T& > : property_type<T> {};
48 template <>
struct property_type<void > {
static inline std::string to_string () {
return "void" ; } };
49 template <>
struct property_type<bool > {
static inline std::string to_string () {
return "bool" ; } };
50 template <>
struct property_type<int > {
static inline std::string to_string () {
return "int" ; } };
51 template <>
struct property_type<float > {
static inline std::string to_string () {
return "float" ; } };
52 template <>
struct property_type<std::string > {
static inline std::string to_string () {
return "string" ; } };
53 template <>
struct property_type<
osgVector2 > {
static inline std::string to_string () {
return "osgVector2" ; } };
54 template <>
struct property_type<
osgVector3 > {
static inline std::string to_string () {
return "osgVector3" ; } };
55 template <>
struct property_type<
osgVector4 > {
static inline std::string to_string () {
return "osgVector4" ; } };
56 template <>
struct property_type<
Configuration> {
static inline std::string to_string () {
return "Configuration"; } };
58 template <
typename T> QWidget* buildEditor (Property* ) {
return NULL; }
59 template <> QWidget* buildEditor<bool > (Property* property);
60 template <> QWidget* buildEditor<int > (Property* property);
61 template <> QWidget* buildEditor<float > (Property* property);
62 template <> QWidget* buildEditor<std::string > (Property* property);
63 template <> QWidget* buildEditor<osgVector2 > (Property* property);
64 template <> QWidget* buildEditor<osgVector3 > (Property* property);
65 template <> QWidget* buildEditor<osgVector4 > (Property* property);
66 template <> QWidget* buildEditor<Configuration> (Property* property);
76 bool set(
const bool & v);
77 bool set(
const int & v);
78 bool set(
const float & v);
79 bool set(
const std::string & v);
86 bool set(
const double& v);
89 bool set(
const QString& v);
92 bool set(
const QColor& v);
99 bool get(std::string & v);
134 virtual std::string
type() = 0;
173 inline void invalidGet()
const {
throw std::logic_error (
"Cannot read property " +
name_ +
"."); }
174 inline void invalidSet()
const {
throw std::logic_error (
"Cannot write property " +
name_ +
"."); }
180 typedef shared_ptr<VoidProperty>
Ptr_t;
183 virtual std::string
type() {
return details::property_type<void>::to_string(); }
185 template <
typename Obj,
typename ReturnType>
187 template <
typename Obj,
typename ReturnType>
211 template <
typename T>
216 typedef shared_ptr<PropertyTpl>
Ptr_t;
222 virtual std::string
type() {
return details::property_type<T>::to_string(); }
224 template <
typename Obj>
226 template <
typename Obj>
228 template <
typename Obj>
230 template <
typename Obj>
233 template <
typename Obj,
typename RetType>
235 RetType (Obj::*mem_get)()
const,
236 void (Obj::*mem_set)(
const T&))
239 Setter_t(boost::bind(mem_set, obj, _1)));
241 template <
typename Obj,
typename RetType>
243 RetType (Obj::*mem_get)()
const,
244 void (Obj::*mem_set)(T))
247 Setter_t(boost::bind(mem_set, obj, _1)));
249 template <
typename Obj,
typename RetType>
251 RetType (Obj::*mem_get)()
const)
255 template <
typename Obj>
257 void (Obj::*mem_set)(
const T&))
261 template <
typename Obj,
typename RetType>
263 void (Obj::*mem_set)(T))
285 return details::buildEditor<T>(
this);
297 template<
typename Scalar>
303 #if __cplusplus >= 201103L
304 min(std::numeric_limits<Scalar>::lowest()),
306 min(std::numeric_limits<Scalar>::quiet_NaN()),
308 max(std::numeric_limits<Scalar>::
max()),
309 step (static_cast<Scalar>(1)),
313 #if __cplusplus >= 201103L
314 inline bool hasMin ()
const {
return min > std::numeric_limits<Scalar>::lowest(); }
318 inline bool hasMax ()
const {
return max < std::numeric_limits<Scalar>::max(); }
321 void setRange(
const Scalar& minimum,
const Scalar& maximum)
322 {
min = minimum;
max = maximum; }
323 void setRange(
const Scalar& minimum,
const Scalar& maximum,
const Scalar& _step)
324 {
min = minimum;
max = maximum;
step = _step;}
327 template <
typename T,
typename RangeT>
332 typedef shared_ptr<RangedPropertyTpl>
Ptr_t;
338 template <
typename Obj,
typename RetType>
340 RetType (Obj::*mem_get)()
const,
341 void (Obj::*mem_set)(
const T&))
344 Setter_t(boost::bind(mem_set, obj, _1)));
346 template <
typename Obj,
typename RetType>
348 RetType (Obj::*mem_get)()
const,
349 void (Obj::*mem_set)(T))
352 Setter_t(boost::bind(mem_set, obj, _1)));
354 template <
typename Obj,
typename RetType>
356 RetType (Obj::*mem_get)()
const)
360 template <
typename Obj>
362 void (Obj::*mem_set)(
const T&))
366 template <
typename Obj,
typename RetType>
368 void (Obj::*mem_set)(T))
380 template <
typename T>
384 typedef shared_ptr<StoredPropertyTpl>
Ptr_t;
388 virtual std::string
type() {
return details::property_type<T>::to_string(); }
399 return details::buildEditor<T>(
this);
414 template <
typename T,
typename RangeT>
417 typedef shared_ptr<RangedStoredPropertyTpl>
Ptr_t;
462 typedef shared_ptr<EnumProperty>
Ptr_t;
465 virtual std::string
type() {
return "enum"; }
522 template <
typename T>
529 template <
typename T>
548 void addProperty(
const std::string& name,
const PropertyPtr_t& prop);
Definition: node-property.h:458
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:468
shared_ptr< EnumProperty > Ptr_t
Definition: node-property.h:462
bool impl_set(const int &value)
const MetaEnum * metaEnum() const
Definition: node-property.h:466
virtual QWidget * guiEditor()
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:464
virtual std::string type()
Definition: node-property.h:465
bool impl_set(const std::string &value)
Definition: node-property.h:493
Property * property(const std::string &name) const
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:523
void addProperty(const std::string &name, Property *prop)
Add a property and leave ownership.
void addProperty(const PropertyPtr_t &prop)
Add a property and take ownership.
void addProperty(Property *prop)
Add a property and leave ownership.
const PropertyMap_t & properties() const
Definition: node-property.h:539
bool hasProperty(const std::string &name) const
std::map< std::string, Wrapper > PropertyMap_t
Definition: node-property.h:503
PropertyMap_t properties_
Definition: node-property.h:506
bool setProperty(const std::string &name, const T &value)
Set a property and set this object as dirty.
Definition: node-property.h:530
bool callVoidProperty(const std::string &name) const
Definition: node-property.h:517
virtual void setDirty(bool dirty=true)=0
Called when a property is modified.
Definition: node-property.h:212
static Ptr_t create(const std::string &name, Obj *obj, RetType(Obj::*mem_get)() const, void(Obj::*mem_set)(T))
Definition: node-property.h:242
static Setter_t setterFromMemberFunction(Obj *obj, void(Obj::*mem_func)(const T &))
Definition: node-property.h:229
void getter(const Getter_t &g)
Definition: node-property.h:278
virtual bool impl_get(T &value)
Definition: node-property.h:290
static Getter_t getterFromMemberFunction(Obj *obj, const T &(Obj::*mem_func)() const)
Definition: node-property.h:225
void setter(const Setter_t &s)
Definition: node-property.h:281
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:234
virtual QWidget * guiEditor()
Definition: node-property.h:283
static Setter_t setterFromMemberFunction(Obj *obj, void(Obj::*mem_func)(T))
Definition: node-property.h:231
static Ptr_t create(const std::string &name, const Getter_t &g)
Definition: node-property.h:219
bool hasReadAccess() const
Definition: node-property.h:274
const Getter_t & getter() const
Definition: node-property.h:277
PropertyTpl(const std::string &name, const Getter_t &g, const Setter_t &s)
Definition: node-property.h:269
virtual std::string type()
Definition: node-property.h:222
static Ptr_t createRO(const std::string &name, Obj *obj, RetType(Obj::*mem_get)() const)
Definition: node-property.h:250
bool hasWriteAccess() const
Definition: node-property.h:275
boost::function< T(void)> Getter_t
Definition: node-property.h:215
shared_ptr< PropertyTpl > Ptr_t
Definition: node-property.h:216
static Ptr_t createWO(const std::string &name, Obj *obj, void(Obj::*mem_set)(T))
Definition: node-property.h:262
static Getter_t getterFromMemberFunction(Obj *obj, T(Obj::*mem_func)() const)
Definition: node-property.h:227
const Setter_t & setter() const
Definition: node-property.h:280
static Ptr_t create(const std::string &name, const Getter_t &g, const Setter_t &s)
Definition: node-property.h:218
boost::function< void(const T &)> Setter_t
Definition: node-property.h:214
static Ptr_t createWO(const std::string &name, Obj *obj, void(Obj::*mem_set)(const T &))
Definition: node-property.h:256
virtual bool impl_set(const T &value)
Definition: node-property.h:289
static Ptr_t create(const std::string &name, const Setter_t &s)
Definition: node-property.h:220
virtual ~PropertyTpl()
Definition: node-property.h:272
Abstract base class for runtime properties of Node.
Definition: node-property.h:71
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:173
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
virtual QWidget * guiEditor()
Definition: node-property.h:140
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:174
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)
bool set(const osgVector2 &v)
void valueChanged(const float &v)
void valueChanged(const osgVector2 &v)
virtual bool impl_get(float &v)
const std::string & name() const
Definition: node-property.h:136
bool set(const double &v)
virtual ~Property()
Definition: node-property.h:169
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:171
virtual bool impl_get(void)
Definition: node-property.h:328
boost::function< T(void)> Getter_t
Definition: node-property.h:331
boost::function< void(const T &)> Setter_t
Definition: node-property.h:330
virtual ~RangedPropertyTpl()
Definition: node-property.h:377
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:339
RangedPropertyTpl(const std::string &name, const Getter_t &g, const Setter_t &s)
Definition: node-property.h:374
static Ptr_t createWO(const std::string &name, Obj *obj, void(Obj::*mem_set)(T))
Definition: node-property.h:367
static Ptr_t create(const std::string &name, const Getter_t &g, const Setter_t &s)
Definition: node-property.h:334
static Ptr_t createWO(const std::string &name, Obj *obj, void(Obj::*mem_set)(const T &))
Definition: node-property.h:361
static Ptr_t create(const std::string &name, const Setter_t &s)
Definition: node-property.h:336
shared_ptr< RangedPropertyTpl > Ptr_t
Definition: node-property.h:332
static Ptr_t create(const std::string &name, const Getter_t &g)
Definition: node-property.h:335
static Ptr_t createRO(const std::string &name, Obj *obj, RetType(Obj::*mem_get)() const)
Definition: node-property.h:355
static Ptr_t create(const std::string &name, Obj *obj, RetType(Obj::*mem_get)() const, void(Obj::*mem_set)(T))
Definition: node-property.h:347
Definition: node-property.h:415
static Ptr_t create(const std::string &name)
Definition: node-property.h:419
virtual ~RangedStoredPropertyTpl()
Definition: node-property.h:424
RangedStoredPropertyTpl(const std::string &name)
Definition: node-property.h:421
shared_ptr< RangedStoredPropertyTpl > Ptr_t
Definition: node-property.h:417
Definition: node-property.h:381
bool hasReadAccess() const
Definition: node-property.h:394
bool impl_set(const T &v)
Definition: node-property.h:408
virtual std::string type()
Definition: node-property.h:388
const Callback_t & callback() const
Definition: node-property.h:402
bool impl_get(T &v)
Definition: node-property.h:409
Callback_t callback_
Definition: node-property.h:411
shared_ptr< StoredPropertyTpl > Ptr_t
Definition: node-property.h:384
StoredPropertyTpl(const std::string &name)
Definition: node-property.h:390
T value
Definition: node-property.h:405
virtual ~StoredPropertyTpl()
Definition: node-property.h:392
bool hasWriteAccess() const
Definition: node-property.h:395
virtual QWidget * guiEditor()
Definition: node-property.h:397
void callback(const Callback_t &s)
Definition: node-property.h:403
boost::function< void()> Callback_t
Definition: node-property.h:383
static Ptr_t create(const std::string &name)
Definition: node-property.h:386
Definition: node-property.h:177
VoidProperty(const std::string &name, const Function_t &f)
Definition: node-property.h:190
bool hasWriteAccess() const
Definition: node-property.h:196
shared_ptr< VoidProperty > Ptr_t
Definition: node-property.h:180
bool impl_get(void)
Definition: node-property.h:204
bool hasReadAccess() const
Definition: node-property.h:195
static Ptr_t create(const std::string &name, const Function_t &f)
Definition: node-property.h:182
virtual ~VoidProperty()
Definition: node-property.h:193
bool impl_set(void)
Definition: node-property.h:205
boost::function< void(void)> Function_t
Definition: node-property.h:179
virtual std::string type()
Definition: node-property.h:183
static Function_t memberFunction(Obj *obj, ReturnType(Obj::*mem_func)() const)
Definition: node-property.h:188
static Function_t memberFunction(Obj *obj, ReturnType(Obj::*mem_func)())
Definition: node-property.h:186
::osg::Vec3f osgVector3
Definition: config-osg.h:109
::osg::Vec2f osgVector2
Definition: config-osg.h:108
::osg::Vec4f osgVector4
Definition: config-osg.h:110
viewer::Configuration Configuration
Definition: configuration.hh:30
RangedPropertyTpl< osgVector2, float > RangedVector2Property
Definition: node-property.h:438
PropertyTpl< float > FloatProperty
Definition: node-property.h:429
PropertyTpl< osgVector4 > Vector4Property
Definition: node-property.h:433
PropertyTpl< osgVector3 > Vector3Property
Definition: node-property.h:432
RangedPropertyTpl< int > RangedIntProperty
Definition: node-property.h:436
MetaEnum * visibilityModeEnum()
RangedPropertyTpl< osgVector4, float > RangedVector4Property
Definition: node-property.h:440
PropertyTpl< bool > BoolProperty
Definition: node-property.h:427
PropertyTpl< osgVector2 > Vector2Property
Definition: node-property.h:431
MetaEnum * glImmediateModeEnum()
PropertyTpl< std::string > StringProperty
Definition: node-property.h:430
RangedPropertyTpl< float > RangedFloatProperty
Definition: node-property.h:437
MetaEnum * lightingModeEnum()
PropertyTpl< Configuration > ConfigurationProperty
Definition: node-property.h:434
RangedPropertyTpl< Configuration, float > RangedConfigurationProperty
Definition: node-property.h:441
MetaEnum * wireFrameModeEnum()
PropertyTpl< int > IntProperty
Definition: node-property.h:428
RangedPropertyTpl< osgVector3, float > RangedVector3Property
Definition: node-property.h:439
Definition: action-search-bar.hh:27
Definition: config-osg.h:145
Definition: node-property.h:496
Property * p
Definition: node-property.h:497
Wrapper(Property *p)
Definition: node-property.h:499
Property * operator->() const
Definition: node-property.h:501
Wrapper(PropertyPtr_t p)
Definition: node-property.h:500
PropertyPtr_t lock
Definition: node-property.h:498
Definition: node-property.h:298
Range()
Definition: node-property.h:302
bool hasMax() const
Definition: node-property.h:318
void setRange(const Scalar &minimum, const Scalar &maximum)
Definition: node-property.h:321
void setRange(const Scalar &minimum, const Scalar &maximum, const Scalar &_step)
Definition: node-property.h:323
bool hasMin() const
Definition: node-property.h:316
Scalar step
Definition: node-property.h:299
bool hasRange() const
Definition: node-property.h:319
bool adaptiveDecimal
Definition: node-property.h:300
Scalar max
Definition: node-property.h:299
Scalar min
Definition: node-property.h:299