OpenSceneGraph 3.6.5
PropertyManager
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2018 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef PROPERTYMANAGER
15#define PROPERTYMANAGER 1
16
17#include <osg/UserDataContainer>
18#include <osg/ValueObject>
19#include <osg/ImageSequence>
20#include <osgGA/GUIEventHandler>
21
23
24#include <sstream>
25
26namespace osgPresentation
27{
28
30{
31public:
32
35 osg::Object(pm,copyop) {}
36
38
39
41 template<typename T>
42 bool getProperty(const std::string& name, T& value) const
43 {
44 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
45 return getUserValue(name, value);
46 }
47
51 template<typename T>
52 void setProperty(const std::string& name, const T& value)
53 {
54 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
55 return setUserValue(name, value);
56 }
57
58 int ref() const { return osg::Referenced::ref(); }
59 int unref() const { return osg::Referenced::unref(); }
60
61protected:
62
63 mutable OpenThreads::Mutex _mutex;
64
65};
66
67extern OSGPRESENTATION_EXPORT const osg::Object* getUserObject(const osg::NodePath& nodepath, const std::string& name);
68
69template<typename T>
70bool getUserValue(const osg::NodePath& nodepath, const std::string& name, T& value)
71{
72 typedef osg::TemplateValueObject<T> UserValueObject;
73 const osg::Object* object = getUserObject(nodepath, name);
74 const UserValueObject* uvo = dynamic_cast<const UserValueObject*>(object);
75
76 if (uvo)
77 {
78 value = uvo->getValue();
79 return true;
80 }
81 else
82 {
83 return false;
84 }
85}
86
87extern OSGPRESENTATION_EXPORT bool containsPropertyReference(const std::string& str);
88
90{
91 PropertyReader(const osg::NodePath& nodePath, const std::string& str):
92 _errorGenerated(false),
93 _nodePath(nodePath),
94 _sstream(str) {}
95
96 template<typename T>
97 bool read(T& value)
98 {
99 // skip white space.
100 while(!_sstream.fail() && _sstream.peek()==' ') _sstream.ignore();
101
102 // check to see if a &propertyName is used.
103 if (_sstream.peek()=='$')
104 {
105 std::string propertyName;
106 _sstream.ignore(1);
107 _sstream >> propertyName;
108 OSG_NOTICE<<"Reading propertyName="<<propertyName<<std::endl;
109 if (!_sstream.fail() && !propertyName.empty()) return getUserValue(_nodePath, propertyName, value);
110 else return false;
111 }
112 else
113 {
114 _sstream >> value;
115 OSG_NOTICE<<"Reading value="<<value<<std::endl;
116 return !_sstream.fail();
117 }
118 }
119
120 template<typename T>
121 PropertyReader& operator>>( T& value ) { if (!read(value)) _errorGenerated=true; return *this; }
122
123 bool ok() { return !_sstream.fail() && !_errorGenerated; }
124 bool fail() { return _sstream.fail() || _errorGenerated; }
125
128 std::istringstream _sstream;
129};
130
131
133{
134public:
136 _firstTime(DBL_MAX),
137 _latestTime(0.0),
138 _pause(false),
139 _pauseTime(0.0) {}
140
142 PropertyManager* getPropertyManager() const { return _pm.get(); }
143
144 typedef std::map<double, osg::ref_ptr<osg::UserDataContainer> > KeyFrameMap;
145
147 const KeyFrameMap& getKeyFrameMap() const { return _keyFrameMap; }
148
149 void addKeyFrame(double time, osg::UserDataContainer* udc)
150 {
151 _keyFrameMap[time] = udc;
152 }
153
154 virtual void reset();
155
156 void setPause(bool pause);
157 bool getPause() const { return _pause; }
158
159 double getAnimationTime() const;
160
161 virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
162
163 virtual void update(osg::Node& node);
164
165
166protected:
167
169
172
174
177 bool _pause;
179
180};
181
182
183
197
207
208}
209
210#endif
#define OSG_NOTICE
Definition Notify:86
The core osg library provides the basic scene graph classes such as Nodes, State and Drawables,...
Definition AlphaFunc:19
std::vector< Node * > NodePath
A vector of Nodes pointers which is used to describe the path from a root node to a descendant.
Definition Node:47
The osgPresentation library is a NodeKit that extends the core scene graph to support 3D scene graph ...
Definition AnimationMaterial:26
bool getUserValue(const osg::NodePath &nodepath, const std::string &name, T &value)
Definition PropertyManager:70
OSGPRESENTATION_EXPORT const osg::Object * getUserObject(const osg::NodePath &nodepath, const std::string &name)
OSGPRESENTATION_EXPORT bool containsPropertyReference(const std::string &str)
Deprecated.
Definition Callback:215
Copy Op(erator) used to control whether shallow or deep copy is used during copy construction and clo...
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
Image Buffer class.
Definition ImageSequence:29
Base class for all internal nodes in the scene graph.
Definition Node:72
Visitor for type safe operations on osg::Nodes.
Definition NodeVisitor:82
Base class/standard interface for objects which require IO support, cloning and reference counting.
Definition Object:61
void setUserValue(const std::string &name, const T &value)
Convenience method that creates the osg::TemplateValueObject<T> to store the specified value and adds...
Definition ValueObject:377
Object()
Construct an object.
Definition Object:69
bool getUserValue(const std::string &name, T &value) const
Convenience method that casts the named UserObject to osg::TemplateValueObject<T> and gets the value.
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
int unref() const
Decrement the reference count by one, indicating that a pointer to this object is no longer referenci...
Definition Referenced:178
int ref() const
Increment the reference count by one, indicating that this object has another pointer which is refere...
Definition Referenced:161
Internal structure for storing all user data.
Definition UserDataContainer:26
Definition ValueObject:283
Definition GUIActionAdapter:62
Event class for storing Keyboard, mouse and window events.
Definition GUIEventAdapter:82
GUIEventHandler provides a basic interface for any class which wants to handle a GUI Events.
Definition GUIEventHandler:50
Definition PropertyManager:30
int unref() const
Definition PropertyManager:59
META_Object(osgPresentation, PropertyManager) template< typename T > bool getProperty(const std
Convenience method that casts the named UserObject to osg::TemplateValueObject<T> and gets the value.
Definition PropertyManager:37
PropertyManager(const PropertyManager &pm, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition PropertyManager:34
OpenThreads::Mutex _mutex
Definition PropertyManager:63
PropertyManager()
Definition PropertyManager:33
int ref() const
Definition PropertyManager:58
PropertyReader & operator>>(T &value)
Definition PropertyManager:121
osg::NodePath _nodePath
Definition PropertyManager:127
PropertyReader(const osg::NodePath &nodePath, const std::string &str)
Definition PropertyManager:91
bool ok()
Definition PropertyManager:123
bool read(T &value)
Definition PropertyManager:97
std::istringstream _sstream
Definition PropertyManager:128
bool fail()
Definition PropertyManager:124
bool _errorGenerated
Definition PropertyManager:126
double _firstTime
Definition PropertyManager:175
PropertyManager * getPropertyManager() const
Definition PropertyManager:142
double _latestTime
Definition PropertyManager:176
void assign(osg::UserDataContainer *destination, osg::UserDataContainer *source)
const KeyFrameMap & getKeyFrameMap() const
Definition PropertyManager:147
virtual void update(osg::Node &node)
KeyFrameMap & getKeyFrameMap()
Definition PropertyManager:146
KeyFrameMap _keyFrameMap
Definition PropertyManager:173
void setPropertyManager(PropertyManager *pm)
Definition PropertyManager:141
bool getPause() const
Definition PropertyManager:157
PropertyAnimation()
Definition PropertyManager:135
double _pauseTime
Definition PropertyManager:178
bool _pause
Definition PropertyManager:177
virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)
Callback method called by the NodeVisitor when visiting a node.
osg::ref_ptr< PropertyManager > _pm
Definition PropertyManager:168
std::map< double, osg::ref_ptr< osg::UserDataContainer > > KeyFrameMap
Definition PropertyManager:144
void addKeyFrame(double time, osg::UserDataContainer *udc)
Definition PropertyManager:149
void assign(osg::UserDataContainer *udc, osg::Object *obj)
ImageSequenceUpdateCallback(osg::ImageSequence *is, PropertyManager *pm, const std::string &propertyName)
Definition PropertyManager:186
osg::ref_ptr< osg::ImageSequence > _imageSequence
Definition PropertyManager:193
virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)
Callback method called by the NodeVisitor when visiting a node.
std::string _propertyName
Definition PropertyManager:195
osg::ref_ptr< PropertyManager > _propertyManager
Definition PropertyManager:194
virtual bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &)
Deprecated, Handle events, return true if handled, false otherwise.
osg::ref_ptr< PropertyManager > _propertyManager
Definition PropertyManager:205
PropertyEventCallback(PropertyManager *pm)
Definition PropertyManager:200
#define OSGPRESENTATION_EXPORT
Definition Export:38

osg logo
Generated at Sun Jul 20 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.