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