AGX Dynamics  2.37.2.0
Model.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx 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 
30 namespace agx
31 {
33 
34 
41  {
42  public:
43  static Model *ClassModel();
44 
48  static agx::Namespace *root();
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);
58  static agx::Path getPath(const agx::String& filePath, agxIO::Environment::Type pathType = agxIO::Environment::RUNTIME_PATH);
59 
64  static agx::String getFileSystemRoot(agx::TiXmlElement *element, agxIO::Environment::Type pathType = agxIO::Environment::RUNTIME_PATH);
65 
69  static agx::Path getNamespace(agx::TiXmlElement *element, agxIO::Environment::Type pathType = agxIO::Environment::RUNTIME_PATH);
70  static agx::Path getNamespace(const agx::String& filePath, agxIO::Environment::Type pathType = agxIO::Environment::RUNTIME_PATH);
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
94  agx::String fullName() const;
95 
96  // path:implementation
97  agx::String fullPath() const;
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 
142  agx::String fullInheritancePath() const;
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 
220  AGX_FORCE_INLINE Model *Model::getSource() { return m_source; }
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; }
224  AGX_FORCE_INLINE bool Model::isShutdown() const { return m_isShutdown; }
225 
226 }
227 
228 #ifdef _MSC_VER
229 # pragma warning(pop)
230 #endif
231 
232 
233 #endif /* AGX_MODEL_H */
bool isShutdown() const
Definition: Model.h:224
bool m_isShutdown
Definition: Model.h:197
Representation of a path, a list of name components.
Definition: Path.h:32
agx::Namespace * getNamespace()
Definition: Model.h:209
A component is an object containing other objects, enabling hierarchical structuring.
Definition: Component.h:38
A model is an abstract representation of the class of an agx::Object.
Definition: Model.h:40
bool AGXPHYSICS_EXPORT isShutdown()
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
Representation of a name string.
Definition: Name.h:32
#define AGX_FORCE_INLINE
Definition: Object.h:59
agx::Model * getSource()
Definition: Model.h:220
const agx::Name & getImplementationName() const
Definition: Model.h:207
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
bool is() const
Subclass test.
#define agxAssert(expr)
Definition: debug.h:143
Type
Specifies which path to access.
Definition: Environment.h:47
const agx::String & getSourcePath() const
Definition: Model.h:223
AGXCORE_EXPORT Component * root()
A namespace is used as a group node in the agx::Model hierarchy.
Definition: Namespace.h:29
Specifies paths for where to search for plugin&#39;s/runtime libraries.
Definition: Environment.h:49
#define AGXCORE_EXPORT
agx::Object is a refcounted object with a name.
Definition: Object.h:58
agx::Path getPath() const