RTFX  0.3
Real time special effects collaborative visualization and production library.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
RTFXData.h
Go to the documentation of this file.
1 #ifndef __RTFX_DATA__
2 #define __RTFX_DATA__
3 
25 #include "RTFXBoostIncludes.h"
26 #include "RTFXMath.h"
27 #include "RTFXRecorder.h"
28 #include "RTFXHelpers.h"
29 #include "RTFXProperty.h"
30 #include "RTFXObject.h"
31 #include "RTFXCamera.h"
32 #include "RTFXLight.h"
33 #include "RTFXGeometry.h"
34 #include "RTFXSkeleton.h"
35 #include "RTFXParticleSystem.h"
36 #include "RTFXRaw.h"
37 #include "RTFXScript.h"
38 #include "RTFXCustom.h"
39 
40 using namespace std;
41 
42 namespace RTFX
43 {
61  class RTFXAPI RTFXData
62  {
63  public:
65  RTFXData();
67  ~RTFXData();
68 
71  void DeleteObjectMemoryMap();
72 
74  void DeletePropertyMemoryMap();
75 
77  void DeleteParentMemoryVector();
78 
80  void DeleteChildrenMemoryVector();
81 
83  void SetID( boost::uuids::uuid _id );
84 
86  void SetRoot( bool _root );
87 
89  void SetName( std::string _name );
90 
92  void SetDescription( std::string _description );
93 
95  boost::uuids::uuid GetID();
96 
98  bool GetRoot();
99 
101  std::string GetName();
102 
104  std::string GetDescription();
105 
107  void AddProperty( RTFXProperty * _property );
108 
110  bool PropertyExists( boost::uuids::uuid _id, std::string _propertyName );
111 
113  void DeleteProperty( boost::uuids::uuid _id, std::string _propertyName );
114 
116  RTFXProperty * GetProperty( boost::uuids::uuid _id, std::string _propertyName );
117 
119  void AddObject( RTFXObject * _object );
120 
122  bool ObjectExists( boost::uuids::uuid _id );
123 
125  bool ObjectExists( std::string _name );
126 
128  RTFXObject * GetAnObject( boost::uuids::uuid _id );
129 
131  RTFXObject * GetAnObject( std::string _name );
132 
134  void DeleteObject( boost::uuids::uuid _id );
135 
137  void DeleteObject( std::string _name );
138 
140  void DeleteAllWithOwner( boost::uuids::uuid _id );
141 
143  std::vector<RTFXData *> * GetParents();
144 
146  std::vector<RTFXData *> * GetChildren();
147 
149  void AddParent( RTFXData * _parent );
150 
152  void AddChild( RTFXData * _child );
153 
155  RTFXData * FindParent( std::string _name );
156 
158  RTFXData * FindChild( std::string _name );
159 
161  void DeleteParent( std::string _name );
162 
167  std::vector<RTFXProperty *> GetChangedProperties();
168 
170  vector<RTFXObject *> GetNewObjects();
171 
178  RTFXData * GetUpdated();
179 
181  void Rebuild();
182 
184  RTFXObject * FindObjectInGraph( boost::uuids::uuid _id );
185 
188  RTFXProperty * FindPropertyNotAtObjectLevel( boost::uuids::uuid _id, std::string _propertyName );
189 
191  RTFXData * FindChild( boost::uuids::uuid _id );
192 
194  vector<RTFXObject *> GetAllObjects();
195 
197  unsigned int NumberOfObjectsOfType( unsigned int _type );
198 
200  bool AreThereAnyObjectsOfType( unsigned int _type );
201 
203  vector<RTFXObject *> GetObjectsOfType( RTFXObject::RTFXObjectType _objectType );
204 
207  void Merge( RTFXData * _other );
208 
210  RTFXBIGINT GetNumObjects();
211 
213  boost::uuids::uuid GetObjectIDOfTypeAtIndex( unsigned int _type, unsigned int _idx );
214 
215 
217  void UpdateProcessCompleted();
218 
220  void SetLocks( bool _useLocks )
221  {
222  useLocks = _useLocks;
223  }
224 
226  bool GetLockStatus()
227  {
228  return useLocks;
229  }
230 
232  void RemoveObjectReferences( boost::uuids::uuid _id );
233 
235  void RemovePropertyReferences( boost::uuids::uuid _owner, string _name );
236 
238  void AssignOwner( boost::uuids::uuid _owner )
239  {
240  // Object owners
241  std::map<boost::uuids::uuid, RTFXObject *>::iterator iter_ = objectMap.begin();
242  while ( iter_ != objectMap.end() )
243  {
244  // If the owner is NIL, give it an owner
245  if ( ( (*iter_).second )->GetOwner() == boost::uuids::nil_uuid() )
246  {
247  ( (*iter_).second )->SetOwner( _owner );
248  }
249  iter_ ++;
250  }
251 
252  // Property owners
253  std::map< pair<boost::uuids::uuid, std::string>, RTFXProperty *>::iterator iter2_ = propertyMap.begin();
254  while ( iter2_ != propertyMap.end() )
255  {
256  // if the owner is NIL, give it an owner
257  if ( ( (*iter2_).second )->GetOwner() == boost::uuids::nil_uuid() )
258  ( (*iter2_).second )->SetOwner( _owner );
259  iter2_ ++;
260  }
261  }
262 
263  private:
265  bool MergeObject( RTFXObject * _obj );
266 
268  bool MergeProperty( RTFXProperty * _prop );
269 
271  bool useLocks;
272 
274  RTFXObject * FindAnObject( boost::uuids::uuid _id )
275  {
276  RTFXObject * ptr_ = NULL;
277 
278  {
279  debug( ostringstream().flush() << "RTFXData::FindAnObject: by id - " << boost::lexical_cast<string>(_id) << endl );
280  if ( ObjectExists( _id ) )
281  {
282  ptr_ = objectMap[ _id ];
283  debug( ostringstream().flush() << "RTFXData::FindAnObject: object exists - " << ptr_->GetName() << endl );
284  }
285  else
286  debug( ostringstream().flush() << "RTFXData::FindAnObject: by id - object not found" << endl );
287  }
288  return ptr_;
289  }
290 
292  RTFXObject * FindAnObject( std::string _name )
293  {
294  RTFXObject * ptr_ = NULL;
295 
296  {
297  debug( ostringstream().flush() << "RTFXData::FindAnObject: by name - " << _name << endl );
298  if ( ObjectExists( _name ) )
299  ptr_ = FindAnObject( objectMapByName[ _name ] );
300  else
301  debug( ostringstream().flush() << "RTFXData::FindAnObject: by name - object not found" << endl );
302  }
303  return ptr_;
304  }
305 
307  boost::mutex graphLock;
308 
310  boost::uuids::uuid id;
311 
313  bool isRoot;
314 
316  std::string name;
317 
319  std::string description;
320 
322  std::map< pair<boost::uuids::uuid, std::string>, RTFXProperty *> propertyMap;
323 
325  std::map<boost::uuids::uuid, RTFXObject *> objectMap;
326 
330  std::map<std::string, boost::uuids::uuid> objectMapByName;
331 
333  std::vector<RTFXData *> parents;
334 
336  std::vector<RTFXData *> children;
337 
339  std::map<RTFXObject::RTFXObjectType, std::vector<boost::uuids::uuid> > listOfObjectIdsByType;
340 
342  //boost::recursive_mutex objectMutex;
343 
344  friend class boost::serialization::access;
345 
346  template<class Archive>
347  void serialize( Archive &_ar, const unsigned int _version )
348  {
349  _ar & id & isRoot & name & description;
350  _ar & objectMap & objectMapByName;
351  _ar & propertyMap & children & listOfObjectIdsByType; // & objectMap & children;
352  };
353  };
354 
359  RTFXAPI void Serialize( RTFXData * _graph, string &_output );
360 
365  RTFXAPI RTFXData * Deserialize( string &_data );
366 
368  RTFXAPI void SerializeText( RTFXData * _graph, string &_output );
369 
371  RTFXAPI RTFXData * DeserializeText( string &_data );
372 }
373 
374 #endif