AGX Dynamics 2.38.0.0
Loading...
Searching...
No Matches
Model.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. 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 AGX_MODEL_H
18#define AGX_MODEL_H
19
20#include <agx/Component.h>
21#include <agx/Namespace.h>
22#include <agxIO/Environment.h>
23
24#ifdef _MSC_VER
25# pragma warning(push)
26# pragma warning( disable : 4251 ) // class X needs to have dll-interface to be used by clients of class Y
27#endif
28
29
30namespace agx
31{
33
34
41 {
42 public:
43 static Model *ClassModel();
44
49
50 using Object::getPath;
51
56 static agx::Path getPath(agx::TiXmlElement *element, agxIO::Environment::Type pathType = agxIO::Environment::RUNTIME_PATH);
57 static agx::Path getPath(agx::TiXmlElement *element, agx::Name& implementation, agxIO::Environment::Type pathType = agxIO::Environment::RUNTIME_PATH);
59
65
71
82 static bool getDiskPath(const Path& modelPath, Path& fullModelPath, String& filePath, TiXmlElement *relativeRoot, agxIO::Environment::Type envType, const String& fileExtension);
83
84 public:
85 Model(const agx::Name& name, const agx::Name& implementation = agx::Name());
86 Model(const agx::Name& name, agx::Model *source);
87
91 const agx::Name& getImplementationName() const;
92
93 // name:implementation
95
96 // path:implementation
98
102 agx::Model *getSource();
103
107 const agx::Model *getSource() const;
108
112 bool hasSource(const agx::Model *source) const;
113
115 bool hasParent(const agx::Model *parent) const;
116
120 bool is(const agx::Model *other) const;
121
122 using Referenced::is;
123
127 agx::Namespace *getNamespace();
128
132 const agx::Namespace *getNamespace() const;
133
137 // const ObjectPtrSet& getInstances() const;
138
143
144
148 const agx::String& getSourcePath() const;
149
150 // eg 'foo.bar:hej' --> path=foo.bar, implementation=hej
151 static void parsePathString(const agx::String& pathStr, agx::Path& path, agx::Name& implementation);
152
153 // Create and register a model
154 static agx::Model *createModel(const agx::Path& path, const agx::Name& implementation, agx::Model *source);
155
156 virtual void buildNavigationTree(agxJson::Value& eNode) const override;
157 public:
159 {
160 public:
161 Loader(const char *name, const char *fileExtension);
162
163 virtual ~Loader();
164 virtual Model *load(TiXmlElement *eModel, const Path& ns) = 0;
165
166 const char *getName() const;
167 const char *getFileExtension() const;
168 void addAlias(const char *alias);
169
170 private:
171 const char *m_name;
172 const char *m_fileExtension;
173 };
174
175 // TODO Make private?
176 void setSource(Model *source);
177 void setSourcePath(const String& path);
178 // static Model *createModel(const String& path, Model *source);
179
180 bool isShutdown() const;
181 protected:
182 virtual ~Model();
183
184 private:
185 friend class Object;
186 // void addInstance(Object *instance);
187 // void removeInstance(Object *instance);
188
189 private:
190 Name m_implementation;
191 String m_sourcePath;
192 ModelRef m_source;
193 // ObjectPtrSet m_instances;
194
195 protected:
196 friend class ModelCleanup;
198 };
199
200
201
202
203
204
205
206 /* Implementation */
207 AGX_FORCE_INLINE const Name& Model::getImplementationName() const { return m_implementation; }
208
210 {
211 agxAssert(!this->getContext() || dynamic_cast<Namespace *>(this->getContext()));
212 return static_cast<Namespace *>(this->getContext());
213 }
214
216 {
217 return const_cast<Model *>(this)->getNamespace();
218 }
219
221 AGX_FORCE_INLINE const Model *Model::getSource() const { return m_source; }
222 // AGX_FORCE_INLINE const ObjectPtrSet& Model::getInstances() const { return m_instances; }
223 AGX_FORCE_INLINE const String& Model::getSourcePath() const { return m_sourcePath; }
225
226}
227
228#ifdef _MSC_VER
229# pragma warning(pop)
230#endif
231
232
233#endif /* AGX_MODEL_H */
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGXCORE_EXPORT
Type
Specifies which path to access.
Definition: Environment.h:47
@ RUNTIME_PATH
Specifies paths for where to search for plugin's/runtime libraries.
Definition: Environment.h:49
A component is an object containing other objects, enabling hierarchical structuring.
Definition: Component.h:39
const char * getName() const
void addAlias(const char *alias)
const char * getFileExtension() const
Loader(const char *name, const char *fileExtension)
virtual Model * load(TiXmlElement *eModel, const Path &ns)=0
A model is an abstract representation of the class of an agx::Object.
Definition: Model.h:41
bool m_isShutdown
Definition: Model.h:197
agx::String fullName() const
static agx::Path getNamespace(agx::TiXmlElement *element, agxIO::Environment::Type pathType=agxIO::Environment::RUNTIME_PATH)
static agx::Path getPath(agx::TiXmlElement *element, agx::Name &implementation, agxIO::Environment::Type pathType=agxIO::Environment::RUNTIME_PATH)
const agx::String & getSourcePath() const
Definition: Model.h:223
bool is(const agx::Model *other) const
agx::Model * getSource()
Definition: Model.h:220
virtual ~Model()
Model(const agx::Name &name, const agx::Name &implementation=agx::Name())
bool hasParent(const agx::Model *parent) const
agx::String fullInheritancePath() const
The active instances of this model.
static agx::Path getNamespace(const agx::String &filePath, agxIO::Environment::Type pathType=agxIO::Environment::RUNTIME_PATH)
static agx::Namespace * root()
Model(const agx::Name &name, agx::Model *source)
const agx::Name & getImplementationName() const
Definition: Model.h:207
static void parsePathString(const agx::String &pathStr, agx::Path &path, agx::Name &implementation)
agx::Namespace * getNamespace()
Definition: Model.h:209
bool hasSource(const agx::Model *source) const
virtual void buildNavigationTree(agxJson::Value &eNode) const override
static agx::Model * createModel(const agx::Path &path, const agx::Name &implementation, agx::Model *source)
bool isShutdown() const
Definition: Model.h:224
static agx::Path getPath(agx::TiXmlElement *element, agxIO::Environment::Type pathType=agxIO::Environment::RUNTIME_PATH)
void setSource(Model *source)
static agx::String getFileSystemRoot(agx::TiXmlElement *element, agxIO::Environment::Type pathType=agxIO::Environment::RUNTIME_PATH)
static agx::Path getPath(const agx::String &filePath, agxIO::Environment::Type pathType=agxIO::Environment::RUNTIME_PATH)
static Model * ClassModel()
static bool getDiskPath(const Path &modelPath, Path &fullModelPath, String &filePath, TiXmlElement *relativeRoot, agxIO::Environment::Type envType, const String &fileExtension)
Locate a model definition file.
agx::String fullPath() const
void setSourcePath(const String &path)
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
agx::Object is a refcounted object with a name.
Definition: Object.h:59
agx::Object * getContext()
Definition: Object.h:372
Representation of a path, a list of name components.
Definition: Path.h:33
#define agxAssert(expr)
Definition: debug.h:143
#define AGX_FORCE_INLINE
Definition: macros.h:58
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
bool AGXPHYSICS_EXPORT isShutdown()
This method indicates if agx::shutdown() has been started or already done.