fbxxref.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /****************************************************************************************
  2. Copyright (C) 2015 Autodesk, Inc.
  3. All rights reserved.
  4. Use of this software is subject to the terms of the Autodesk license agreement
  5. provided at the time of installation or download, or which otherwise accompanies
  6. this software in either electronic or hard copy form.
  7. ****************************************************************************************/
  8. //! \file fbxxref.h
  9. #ifndef _FBXSDK_CORE_XREF_H_
  10. #define _FBXSDK_CORE_XREF_H_
  11. #include <fbxsdk/fbxsdk_def.h>
  12. #include <fbxsdk/core/base/fbxarray.h>
  13. #include <fbxsdk/core/base/fbxstring.h>
  14. #include <fbxsdk/fbxsdk_nsbegin.h>
  15. class FbxProperty;
  16. class FbxDocument;
  17. class FbxXRefManagerProject;
  18. /** This class manages external references to files.
  19. * \nosubgrouping
  20. */
  21. class FBXSDK_DLL FbxXRefManager
  22. {
  23. public:
  24. //! Default constructor.
  25. FbxXRefManager();
  26. //! Destructor.
  27. virtual ~FbxXRefManager();
  28. /**
  29. * \name Predefined Project Types
  30. */
  31. //@{
  32. //! This project represents an URL for storing temporary files.
  33. static const char* sTemporaryFileProject;
  34. //! This project represents an URL for configuration files.
  35. static const char* sConfigurationProject;
  36. //! This project represents an URL for storing localization files (that is not part of the asset library).
  37. static const char* sLocalizationProject;
  38. /** This project is used for creating the ".fbm" folders that are used for
  39. * storing embedded resources in FBX files.
  40. *
  41. * When not set, or if the folder is not writable, the ".fbm"
  42. * folder is created alongside the FBX file.
  43. *
  44. * If we cannot write in that folder, we look at the sTemporaryFileProject location.
  45. * If no folder is set in the sTemporaryFileProject location, or it is not
  46. * writable, the operating system's Temp folder becomes the location.
  47. */
  48. static const char* sEmbeddedFileProject;
  49. //@}
  50. /**
  51. * \name XRef URL properties
  52. */
  53. //@{
  54. /** Returns the number of URLs that are stored in a property.
  55. * \param pProperty The property.
  56. * \return The URL count.
  57. */
  58. static int GetUrlCount(FbxProperty const &pProperty);
  59. /** Returns the number of URLs that are stored in a string.
  60. * \param pUrl The string.
  61. * \return The URL count.
  62. */
  63. static int GetUrlCount(FbxString const& pUrl);
  64. /** Checks whether the URL at the given index stored in the property is relative or not.
  65. * \param pProperty The property.
  66. * \param pIndex The URL index.
  67. * \return \c True if the URL is relative, \c false if the URL is not relative.
  68. */
  69. static bool IsRelativeUrl (FbxProperty const &pProperty,int pIndex);
  70. /** Returns the URL stored in the property at the given index.
  71. * \param pProperty The property.
  72. * \param pIndex The URL index.
  73. * \return The URL
  74. */
  75. static FbxString GetUrl(FbxProperty const &pProperty,int pIndex);
  76. /** Tries to resolve the URL stored in the property at the given index.
  77. * \param pProperty The property.
  78. * \param pIndex The URL index.
  79. * \param pResolvedPath Filled with the resolved path.
  80. * \return \c True if the URL is resolved, return \c false if the URL is not resolved.
  81. */
  82. bool GetResolvedUrl (FbxProperty const &pProperty,int pIndex,FbxString & pResolvedPath) const;
  83. /** Tries to resolve the specified URL.
  84. * \param pUrl The specified URL.
  85. * \param pDoc The document whose ".fbm" folder is used to resolve the URL.
  86. * \param pResolvedPath Filled with the resolved path.
  87. * \return \c True if the URL is resolved, return \c false if the URL is not resolved.
  88. */
  89. bool GetResolvedUrl (const char* pUrl, FbxDocument* pDoc, FbxString& pResolvedPath) const;
  90. //@}
  91. /** Looks for the first file that matches a specified "pattern",
  92. * which is built as:
  93. *
  94. * if pOptExt is given: prefix*.ext
  95. * If pOptExt is NULL: prefix*
  96. * if pOptExt is "" or ".": prefix*.
  97. *
  98. * Returns the URL of the first matching files. This function cannot be
  99. * used to resolve folders, only files.
  100. *
  101. * If a document is given, we start by looking at the document's ".fbm" folder.
  102. * \param pPrefix The prefix of the pattern.
  103. * \param pOptExt The extension of the pattern.
  104. * \param pDoc The given document.
  105. * \param pResolvedPath Filled with the first matching URL.
  106. * \return \c True if one matching file is found, returns \c false if no matching file is found.
  107. */
  108. bool GetFirstMatchingUrl(const char* pPrefix, const char* pOptExt, const FbxDocument* pDoc, FbxString& pResolvedPath) const;
  109. /**
  110. * \name XRef Resolve URL and Projects
  111. */
  112. //@{
  113. /** Adds an XRef Project.
  114. * Note:Only one URL is associated with a project. Calling
  115. * this on an existing project replaces the project's existing URL.
  116. * \param pName The name of the project
  117. * \param pUrl The URL to be associated with the project.
  118. * \return \c True if the project is added successfully, \c false if no project is added.
  119. */
  120. bool AddXRefProject (const char *pName,const char *pUrl);
  121. /** Adds an XRef Project.
  122. * Note:Only one URL is associated with a project. Calling
  123. * this on an existing project replaces the project's existing URL.
  124. * \param pName The name of the project
  125. * \param pExtension The extension of the project.
  126. * \param pUrl The URL to be associated with the project.
  127. * \return \c True if the project is added successfully, returns \c false if no project is added.
  128. */
  129. bool AddXRefProject (const char *pName,const char *pExtension,const char *pUrl);
  130. /** Adds an XRef project based on the document's EmbeddedUrl
  131. * property if set, if EmbeddedUrl is not set, based on its current URL property.
  132. * \param pDoc The document used to name the project and to specify the URL.
  133. * \return \c True if the project is added successfully, returns \c false if no project is added.
  134. * \remarks The project name is set as the document name and the URL is set as EmbeddedUrl or URL of the document.
  135. */
  136. bool AddXRefProject (FbxDocument* pDoc);
  137. /** Removes an XRef Projects.
  138. * \param pName The name of the project to be removed.
  139. * \return \c True if the project is removed successfully, returns \c false if the project with the name does not exist.
  140. */
  141. bool RemoveXRefProject(const char *pName);
  142. /** Removes all XRef Projects.
  143. * \return \c True always.
  144. */
  145. bool RemoveAllXRefProjects();
  146. /** Returns the number of XRef Projects.
  147. * \return The number of XRef Projects.
  148. */
  149. int GetXRefProjectCount() const;
  150. /** Returns the name of the XRef project at the specified index.
  151. * \param pIndex The XRef project index.
  152. * \return The XRef project name.
  153. */
  154. const char *GetXRefProjectName(int pIndex) const;
  155. /** Returns the base URL for the given project.
  156. * \param pName The name of the given project
  157. * \return The base URL of the project or returns NULL if the project with the name is not found.
  158. */
  159. const char* GetXRefProjectUrl(const char* pName); // Should be const, will break AV.
  160. /** Returns the base URL for the given project.
  161. * \param pName The name of the given project
  162. * \return The base URL of the project or returns NULL if the project with the name is not found.
  163. */
  164. const char* GetXRefProjectUrl(const char* pName) const;
  165. /** Returns the base URL for the given project.
  166. * \param pIndex The index of the project.
  167. * \return The base URL of the project or NULL if the index is out of bounds.
  168. */
  169. const char* GetXRefProjectUrl(int pIndex) const;
  170. /** Checks if a project with the given name is defined in this manager.
  171. * \param pName The name of the project.
  172. * \return \c True if the project is defined in this manager, returns \c false if it isn't defined in this manager.
  173. */
  174. inline bool HasXRefProject( const char* pName ) { return GetXRefProjectUrl(pName) != NULL; }
  175. /** Tries to resolve an relative URL
  176. * \param pUrl The relative URL to be resolved.
  177. * \param pResolvePath Filled with the resolved path.
  178. * \return \c True if the URL is resolved, returns \c false if the URL is not resolved.
  179. */
  180. bool GetResolvedUrl (const char* pUrl,FbxString & pResolvePath) const;
  181. //@}
  182. private:
  183. FbxArray<FbxXRefManagerProject*> mProjects;
  184. static bool UrlExist(const char* pUrl);
  185. };
  186. #include <fbxsdk/fbxsdk_nsend.h>
  187. #endif /* _FBXSDK_CORE_XREF_H_ */