gepetto-viewer
5.2.0
An user-friendly Graphical Interface
|
Go to the documentation of this file.
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)) {
345 :
Property(name), getter_(g), setter_(s) {}
358 virtual QWidget*
guiEditor() {
return details::buildEditor<T>(
this); }
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)),
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);
bool hasReadAccess() const
Definition: node-property.h:349
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
virtual std::string type()
Definition: node-property.h:577
bool setProperty(const std::string &name, const T &value)
Set a property and set this object as dirty.
Definition: node-property.h:639
bool impl_get(int &v)
Get the enum property as an integer.
void invalidGet() const
Definition: node-property.h:213
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.
void setRange(const Scalar &minimum, const Scalar &maximum, const Scalar &_step)
Definition: node-property.h:416
static Getter_t getterFromMemberFunction(Obj *obj, const T &(Obj::*mem_func)() const)
Definition: node-property.h:293
PropertyTpl< bool > BoolProperty
Definition: node-property.h:536
void callback(const Callback_t &s)
Definition: node-property.h:501
virtual ~PropertyTpl()
Definition: node-property.h:347
virtual QWidget * guiEditor()
static Ptr_t create(const std::string &name, const Function_t &f)
Definition: node-property.h:226
boost::function< void()> Callback_t
Definition: node-property.h:482
PropertyTpl< int > IntProperty
Definition: node-property.h:537
static Ptr_t createWO(const std::string &name, Obj *obj, void(Obj::*mem_set)(T))
Definition: node-property.h:339
Definition: action-search-bar.hh:27
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
bool impl_set(const T &v)
Definition: node-property.h:506
::osg::Vec3f osgVector3
Definition: config-osg.h:99
RangedPropertyTpl< osgVector2, float > RangedVector2Property
Definition: node-property.h:547
const std::string & name() const
Definition: node-property.h:179
RangedPropertyTpl< Configuration, float > RangedConfigurationProperty
Definition: node-property.h:550
Property * p
Definition: node-property.h:608
RangedPropertyTpl(const std::string &name, const Getter_t &g, const Setter_t &s)
Definition: node-property.h:472
boost::function< T(void)> Getter_t
Definition: node-property.h:276
static Ptr_t createRO(const std::string &name, Obj *obj, RetType(Obj::*mem_get)() const)
Definition: node-property.h:457
bool adaptiveDecimal
Definition: node-property.h:386
Definition: node-property.h:607
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
virtual ~RangedStoredPropertyTpl()
Definition: node-property.h:533
PropertyTpl< std::string > StringProperty
Definition: node-property.h:539
bool hasWriteAccess() const
Definition: node-property.h:496
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
bool hasWriteAccess() const
Definition: node-property.h:250
::osg::Vec2f osgVector2
Definition: config-osg.h:98
VoidProperty(const std::string &name, const Function_t &f)
Definition: node-property.h:244
bool hasReadAccess() const
Definition: node-property.h:249
Definition: node-property.h:384
virtual QWidget * guiEditor()
Definition: node-property.h:358
PropertyTpl< osgVector4 > Vector4Property
Definition: node-property.h:542
bool hasMin() const
Definition: node-property.h:405
Definition: node-property.h:221
PropertyTpl(const std::string &name, const Getter_t &g, const Setter_t &s)
Definition: node-property.h:344
virtual bool impl_set(void)
virtual ~StoredPropertyTpl()
Definition: node-property.h:493
shared_ptr< VoidProperty > Ptr_t
Definition: node-property.h:224
PropertyPtr_t lock
Definition: node-property.h:609
static Ptr_t create(const std::string &name)
Definition: node-property.h:526
shared_ptr< PropertyTpl > Ptr_t
Definition: node-property.h:277
virtual bool impl_get(void)
bool hasReadAccess() const
Definition: node-property.h:495
const PropertyMap_t & properties() const
Definition: node-property.h:647
MetaEnum * glImmediateModeEnum()
virtual ~VoidProperty()
Definition: node-property.h:247
bool getProperty(const std::string &name, T &value) const
Definition: node-property.h:633
bool hasWriteAccess() const
Definition: node-property.h:350
Scalar step
Definition: node-property.h:385
bool hasMax() const
Definition: node-property.h:407
PropertyMap_t properties_
Definition: node-property.h:617
virtual QWidget * guiEditor()
Definition: node-property.h:183
StoredPropertyTpl(const std::string &name)
Definition: node-property.h:491
virtual std::string type()
Definition: node-property.h:229
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
Property * property(const std::string &name) const
#define __cplusplus
Definition: moc_predefs.h:137
PropertyTpl< Configuration > ConfigurationProperty
Definition: node-property.h:543
static Setter_t setterFromMemberFunction(Obj *obj, void(Obj::*mem_func)(T))
Definition: node-property.h:309
boost::function< void(void)> Function_t
Definition: node-property.h:223
Scalar max
Definition: node-property.h:385
static Ptr_t createRO(const std::string &name, Obj *obj, RetType(Obj::*mem_get)() const)
Definition: node-property.h:329
PropertyTpl< float > FloatProperty
Definition: node-property.h:538
viewer::Configuration Configuration
Definition: configuration.hh:30
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
const Setter_t & setter() const
Definition: node-property.h:355
virtual bool hasReadAccess() const =0
Scalar min
Definition: node-property.h:385
static Ptr_t create(const std::string &name, const MetaEnum *type, const Getter_t &g, const Setter_t &s)
Definition: node-property.h:573
PropertyTpl< osgVector2 > Vector2Property
Definition: node-property.h:540
const MetaEnum * metaEnum() const
Definition: node-property.h:578
static Ptr_t createWO(const std::string &name, Obj *obj, void(Obj::*mem_set)(const T &))
Definition: node-property.h:334
bool impl_set(const int &value)
boost::function< T(void)> Getter_t
Definition: node-property.h:428
std::map< std::string, Wrapper > PropertyMap_t
Definition: node-property.h:614
virtual std::string type()=0
T value
Definition: node-property.h:503
shared_ptr< RangedStoredPropertyTpl > Ptr_t
Definition: node-property.h:524
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 Getter_t &g)
Definition: node-property.h:283
virtual ~Property()
Definition: node-property.h:209
Definition: node-property.h:605
bool hasRange() const
Definition: node-property.h:410
static Ptr_t create(const std::string &name, const Getter_t &g)
Definition: node-property.h:435
virtual bool impl_get(T &value)
Definition: node-property.h:369
shared_ptr< RangedPropertyTpl > Ptr_t
Definition: node-property.h:429
boost::function< void(const T &)> Setter_t
Definition: node-property.h:275
const Callback_t & callback() const
Definition: node-property.h:500
PropertyTpl< osgVector3 > Vector3Property
Definition: node-property.h:541
Range()
Definition: node-property.h:388
void addProperty(const PropertyPtr_t &prop)
Add a property and take ownership.
RangedPropertyTpl< int > RangedIntProperty
Definition: node-property.h:545
static Getter_t getterFromMemberFunction(Obj *obj, T(Obj::*mem_func)() const)
Definition: node-property.h:299
MetaEnum * lightingModeEnum()
bool impl_get(void)
Definition: node-property.h:258
static Function_t memberFunction(Obj *obj, ReturnType(Obj::*mem_func)())
Definition: node-property.h:234
Property * operator->() const
Definition: node-property.h:612
static Ptr_t create(const std::string &name)
Definition: node-property.h:485
RangedPropertyTpl< osgVector3, float > RangedVector3Property
Definition: node-property.h:548
virtual QWidget * guiEditor()
Definition: node-property.h:498
Definition: node-property.h:567
RangedPropertyTpl< osgVector4, float > RangedVector4Property
Definition: node-property.h:549
void getter(const Getter_t &g)
Definition: node-property.h:353
Callback_t callback_
Definition: node-property.h:517
void invalidSet() const
Definition: node-property.h:216
virtual bool impl_set(const T &value)
Definition: node-property.h:361
static Ptr_t create(const std::string &name, const Getter_t &g, const Setter_t &s)
Definition: node-property.h:431
Wrapper(PropertyPtr_t p)
Definition: node-property.h:611
const Getter_t & getter() const
Definition: node-property.h:352
MetaEnum * visibilityModeEnum()
::osg::Vec4f osgVector4
Definition: config-osg.h:100
virtual bool hasWriteAccess() const =0
Definition: node-property.h:480
Definition: node-property.h:521
Definition: node-property.h:41
RangedPropertyTpl< float > RangedFloatProperty
Definition: node-property.h:546
shared_ptr< StoredPropertyTpl > Ptr_t
Definition: node-property.h:483
Abstract base class for runtime properties of Node.
Definition: node-property.h:114
static Function_t memberFunction(Obj *obj, ReturnType(Obj::*mem_func)() const)
Definition: node-property.h:239
Property(const std::string &name)
Wrapper(Property *p)
Definition: node-property.h:610
bool impl_get(T &v)
Definition: node-property.h:512
bool hasProperty(const std::string &name) const
bool impl_set(void)
Definition: node-property.h:266
shared_ptr< EnumProperty > Ptr_t
Definition: node-property.h:571
void setter(const Setter_t &s)
Definition: node-property.h:356
static Setter_t setterFromMemberFunction(Obj *obj, void(Obj::*mem_func)(const T &))
Definition: node-property.h:304
static Ptr_t createWO(const std::string &name, Obj *obj, void(Obj::*mem_set)(T))
Definition: node-property.h:467
MetaEnum * wireFrameModeEnum()
Definition: node-property.h:43
virtual std::string type()
Definition: node-property.h:489
static Ptr_t create(const std::string &name, const Setter_t &s)
Definition: node-property.h:438
void setRange(const Scalar &minimum, const Scalar &maximum)
Definition: node-property.h:412
EnumProperty(const std::string &name, const MetaEnum *type, const Getter_t &g, const Setter_t &s)
Definition: node-property.h:580
const std::string name_
Definition: node-property.h:211
RangedStoredPropertyTpl(const std::string &name)
Definition: node-property.h:530
virtual std::string type()
Definition: node-property.h:290
Definition: config-osg.h:115