AGX Dynamics 2.42.1.1
Loading...
Searching...
No Matches
EntityModel.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#ifndef AGXDATA_ENTITY_MODEL_H
18#define AGXDATA_ENTITY_MODEL_H
19
20
21#include <agx/Vector.h>
22#include <agx/HashTable.h>
23#include <agx/String.h>
24#include <agx/Model.h>
25#include <agx/agxCore_export.h>
26#include <agxData/EntityPtr.h>
29#include <agxData/Attribute.h>
30
31
32#define AGX_ENTITY_NAMESPACE ""
33
34namespace agx
35{
36 class TiXmlElement;
37 class Device;
38 class EntityParameter;
39 class NameSpace;
40}
41
42namespace agxData
43{
44 class EntityData;
45
49
52
55
57
64 {
65 public:
68
69 public:
70 static EntityModel *load(agx::TiXmlElement *eEntity, agx::Device *device);
71 virtual void configure(agx::TiXmlElement *eEntity);
72
73 static bool findEntityPath(const agx::Path& entityPath, agx::Path& fullEntityPath, agx::String& filePath, agx::String& classPath, agx::TiXmlElement *relativeRoot = nullptr, agxIO::Environment::Type envType = agxIO::Environment::RUNTIME_PATH);
74
76
77
78
79
80 static void setThreadSafe(bool flag);
81 static bool getThreadSafe();
82 public:
84
86
87 public:
88 EntityModel(const agx::Name& name);
89
93 EntityModel* getSource();
94 const EntityModel* getSource() const;
95
100 void addAttribute(Attribute *attribute);
101
105 const AttributePtrVector& getAttributes() const;
106
111 const Attribute* getAttribute(const agx::Name& name) const;
112
113
114 void setUseInstanceTable(bool flag);
115 bool useInstanceTable() const;
116
117 void setHasConstructor(bool flag);
118 bool hasConstructor() const;
119
124
125
129 size_t getNumBytes();
130 size_t getNumBytes(agx::Device *device);
131
135 void print(std::ostream& stream) const;
136 void print() const;
137
140
141 virtual void shutdownCleanup() {}
142
143 public:
144 virtual EntityData *createData(EntityStorage *storage);
145
146 class Loader;
147
148 template <typename T>
149 class LoaderT;
150
151 virtual void initAttributeAccessors() {}
153
154 protected:
155 virtual ~EntityModel();
156
157 // void registerStorage(EntityStorage *storage);
158 // void unregisterStorage(EntityStorage *storage);
160 void addChild(EntityModel *child);
163
164 private:
165 friend class EntityStorage;
166
167 struct SharedBuffer
168 {
169 agx::Name name;
170 Format *format;
171 };
172
173 struct SharedStorage
174 {
175 EntityModel *entity;
176 agx::Name name;
177 };
178
179 typedef agx::Vector<SharedBuffer> SharedBufferVector;
180 typedef agx::Vector<SharedStorage> SharedStorageVector;
181 const SharedBufferVector& getSharedBuffers() const;
182 const SharedStorageVector& getSharedStorages() const;
183
184 void addSharedBuffer(SharedBuffer buffer);
185 void addSharedStorage(SharedStorage storage);
186
187 private:
188 static void initDefaultEntity();
189
190 static bool s_threadSafe;
191
192 // EntityModel *m_parent;
193 EntityModelPtrVector m_children;
194 AttributePtrVector m_attributes;
195 SharedBufferVector m_sharedBuffers;
196 SharedStorageVector m_sharedStorages;
197 EntityStorage *m_defaultStorage;
198 bool m_useInstanceTable;
199 bool m_hasConstructor;
200 // EntityStoragePtrVector m_activeStorages;
201 };
202
203 class AGXCORE_EXPORT EntityModel::Loader
204 {
205 public:
206 Loader(const char *modelPath);
207 virtual EntityModel *load() = 0;
208 virtual ~Loader();
209 };
210
211 template <typename T>
213 {
214 public:
215 LoaderT(const char *modelPath) : EntityModel::Loader(modelPath) {}
216 virtual EntityModel *load() { return new T(); }
217 virtual ~LoaderT() {}
218 };
219
220
221
222 /* Implementation */
223 AGX_FORCE_INLINE bool EntityModel::getThreadSafe() { return s_threadSafe; }
224 AGX_FORCE_INLINE bool EntityModel::hasConstructor() const { return m_hasConstructor; }
225
226
227 AGX_FORCE_INLINE const AttributePtrVector& EntityModel::getAttributes() const { return m_attributes; }
228 AGX_FORCE_INLINE const EntityModel::SharedBufferVector& EntityModel::getSharedBuffers() const { return m_sharedBuffers; }
229 AGX_FORCE_INLINE const EntityModel::SharedStorageVector& EntityModel::getSharedStorages() const { return m_sharedStorages; }
230
231 AGX_FORCE_INLINE const EntityModel* EntityModel::getSource() const { return dynamic_cast<const EntityModel *>(Model::getSource()); }
232 AGX_FORCE_INLINE EntityModel* EntityModel::getSource() { return dynamic_cast<EntityModel *>(Model::getSource()); }
233
234
235 // Implementation of EntityPtr is located in EntityStorage.h due to include loops
236}
237
239AGX_TYPE_BINDING(agxData::EntityInstance, "EntityInstance")
240AGX_TYPE_BINDING(agxData::EntityRange, "EntityRange")
241
242#undef AGX_ENTITY_NAMESPACE
243#endif /* _AGXDATA_ENTITY_MODEL_H_ */
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGX_TYPE_BINDING(_Type, _Name)
Definition: Type.h:179
#define AGXCORE_EXPORT
An abstract attribute description, part of an Entity.
Definition: Attribute.h:58
virtual EntityModel * load()
Definition: EntityModel.h:216
LoaderT(const char *modelPath)
Definition: EntityModel.h:215
An abstract description of a data entity stored using SOA (structure of arrays) pattern in a EntitySt...
Definition: EntityModel.h:64
size_t getNumBytes(agx::Device *device)
static agx::Model * ClassModel()
void setHasConstructor(bool flag)
static bool getThreadSafe()
Definition: EntityModel.h:223
virtual void initAttributeAccessors()
Definition: EntityModel.h:151
static EntityModel * getRootModel()
bool hasConstructor() const
Definition: EntityModel.h:224
void setUseInstanceTable(bool flag)
Attribute * getAttribute(const agx::Name &name)
virtual void construct(agxData::EntityPtr)
Definition: EntityModel.h:152
static agx::Namespace * root()
void addChild(EntityModel *child)
const Attribute * getAttribute(const agx::Name &name) const
Loader(const char *modelPath)
const AttributePtrVector & getAttributes() const
Definition: EntityModel.h:227
virtual void shutdownCleanup()
Definition: EntityModel.h:141
void addAttribute(Attribute *attribute)
Add an attribute to the entity.
static bool findEntityPath(const agx::Path &entityPath, agx::Path &fullEntityPath, agx::String &filePath, agx::String &classPath, agx::TiXmlElement *relativeRoot=nullptr, agxIO::Environment::Type envType=agxIO::Environment::RUNTIME_PATH)
static ScalarAttributeT< EntityPtr > * instanceAttribute
Definition: EntityModel.h:67
void propagateNewAttribute(Attribute *attribute)
void removeChild(EntityModel *child)
void print() const
EntityPtr createInstanceWrapper()
agx::Event1< EntityStorage * > StorageEvent
Definition: EntityModel.h:83
void setBaseEntity(EntityModel *base)
void print(std::ostream &stream) const
Print the registered attributes.
static EntityModel * load(agx::TiXmlElement *eEntity, agx::Device *device)
EntityStorage * getDefaultStorage()
virtual EntityModel * load()=0
EntityModel * getSource()
Definition: EntityModel.h:232
virtual EntityData * createData(EntityStorage *storage)
static void setThreadSafe(bool flag)
EntityModel(const agx::Name &name)
StorageEvent storageCreationEvent
Definition: EntityModel.h:85
bool useInstanceTable() const
virtual void configure(agx::TiXmlElement *eEntity)
Accessor to a entity instance stored in a EntityStorage, to allow SOA (structure of arrays) data to b...
Definition: EntityPtr.h:52
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:73
A format is an implementation of a agxData::Type.
Definition: Format.h:64
Type
Specifies which path to access.
@ RUNTIME_PATH
Specifies paths for where to search for plugin's/runtime libraries.
An agx::Device is an abstract representation of a device on which data can be stored and processed.
Definition: Device.h:58
An event with one argument.
Definition: Event.h:103
Inheritance with partial specialization due to bug with ref_ptr containers.
A model is an abstract representation of the class of an agx::Object.
Definition: Model.h:41
Representation of a name string.
Definition: Name.h:33
A namespace is used as a group node in the agx::Model hierarchy.
Definition: Namespace.h:30
Representation of a path, a list of name components.
Definition: Path.h:33
Templated vector class.
Definition: agx/Vector.h:53
#define AGX_FORCE_INLINE
Definition: macros.h:58
Contains classes for low level data storage for AGX.
Definition: Container.h:23
AGXCORE_EXPORT bool hasEntity(const agx::Path &path)
agx::Vector< Attribute * > AttributePtrVector
Definition: EntityModel.h:47
agx::HashTable< Attribute *, EntityModel * > EntityDependencyTable
Definition: EntityModel.h:48
agx::Vector< EntityModel * > EntityModelPtrVector
Definition: EntityModel.h:46
AGXCORE_EXPORT EntityModel * getEntity(const agx::Path &path)
Get a entity with a specified path.
The agx namespace contains the dynamics/math part of the AGX Dynamics API.