HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Util.h
Go to the documentation of this file.
1 //
2 // Copyright Contributors to the MaterialX Project
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 
6 #ifndef MATERIALX_FORMAT_UTIL_H
7 #define MATERIALX_FORMAT_UTIL_H
8 
9 /// @file
10 /// Format utility methods
11 
12 #include <MaterialXCore/Document.h>
13 #include <MaterialXCore/Element.h>
15 
16 #include <MaterialXFormat/Export.h>
17 #include <MaterialXFormat/File.h>
18 #include <MaterialXFormat/XmlIo.h>
19 
21 
22 /// Read the given file and return a string containing its contents; if the read is not
23 /// successful, then the empty string is returned.
24 MX_FORMAT_API string readFile(const FilePath& file);
25 
26 /// Get all subdirectories for a given set of directories and search paths
27 MX_FORMAT_API void getSubdirectories(const FilePathVec& rootDirectories, const FileSearchPath& searchPath, FilePathVec& subDirectories);
28 
29 /// Scans for all documents under a root path and returns documents which can be loaded
30 MX_FORMAT_API void loadDocuments(const FilePath& rootPath,
31  const FileSearchPath& searchPath,
32  const StringSet& skipFiles,
33  const StringSet& includeFiles,
34  vector<DocumentPtr>& documents,
35  StringVec& documentsPaths,
36  const XmlReadOptions* readOptions = nullptr,
37  StringVec* errors = nullptr);
38 
39 /// Load a given MaterialX library into a document
40 MX_FORMAT_API void loadLibrary(const FilePath& file,
41  DocumentPtr doc,
42  const FileSearchPath& searchPath = FileSearchPath(),
43  const XmlReadOptions* readOptions = nullptr);
44 
45 /// Load all MaterialX files within the given library folders into a document,
46 /// using the given search path to locate the folders on the file system.
47 MX_FORMAT_API StringSet loadLibraries(const FilePathVec& libraryFolders,
48  const FileSearchPath& searchPath,
49  DocumentPtr doc,
50  const StringSet& excludeFiles = StringSet(),
51  const XmlReadOptions* readOptions = nullptr);
52 
53 /// Flatten all filenames in the given document, applying string resolvers at the
54 /// scope of each element and removing all fileprefix attributes.
55 /// @param doc The document to modify.
56 /// @param searchPath An optional search path for relative to absolute path conversion.
57 /// @param customResolver An optional custom resolver to apply.
58 MX_FORMAT_API void flattenFilenames(DocumentPtr doc, const FileSearchPath& searchPath = FileSearchPath(), StringResolverPtr customResolver = nullptr);
59 
60 /// Return a file search path containing the parent folder of each source URI in the given document.
62 
63 /// Return a file search path to the default data library folder.
64 /// The module path and all parent paths are examined to until either there is
65 /// no parent or the library folder is found.
67 
69 
70 #endif
MX_FORMAT_API void getSubdirectories(const FilePathVec &rootDirectories, const FileSearchPath &searchPath, FilePathVec &subDirectories)
Get all subdirectories for a given set of directories and search paths.
MATERIALX_NAMESPACE_BEGIN MX_FORMAT_API string readFile(const FilePath &file)
Definition: File.h:26
#define MATERIALX_NAMESPACE_BEGIN
Definition: Generated.h:25
vector< string > StringVec
A vector of strings.
Definition: Library.h:57
MX_FORMAT_API FileSearchPath getSourceSearchPath(ConstDocumentPtr doc)
Return a file search path containing the parent folder of each source URI in the given document...
#define MX_FORMAT_API
Definition: Export.h:18
MX_FORMAT_API void loadLibrary(const FilePath &file, DocumentPtr doc, const FileSearchPath &searchPath=FileSearchPath(), const XmlReadOptions *readOptions=nullptr)
Load a given MaterialX library into a document.
MX_FORMAT_API void loadDocuments(const FilePath &rootPath, const FileSearchPath &searchPath, const StringSet &skipFiles, const StringSet &includeFiles, vector< DocumentPtr > &documents, StringVec &documentsPaths, const XmlReadOptions *readOptions=nullptr, StringVec *errors=nullptr)
Scans for all documents under a root path and returns documents which can be loaded.
MX_FORMAT_API StringSet loadLibraries(const FilePathVec &libraryFolders, const FileSearchPath &searchPath, DocumentPtr doc, const StringSet &excludeFiles=StringSet(), const XmlReadOptions *readOptions=nullptr)
MX_FORMAT_API void flattenFilenames(DocumentPtr doc, const FileSearchPath &searchPath=FileSearchPath(), StringResolverPtr customResolver=nullptr)
shared_ptr< Document > DocumentPtr
A shared pointer to a Document.
Definition: Document.h:22
vector< FilePath > FilePathVec
Definition: File.h:19
shared_ptr< StringResolver > StringResolverPtr
A shared pointer to a StringResolver.
Definition: Element.h:66
std::set< string > StringSet
A set of strings.
Definition: Library.h:61
#define MATERIALX_NAMESPACE_END
Definition: Generated.h:26
MX_FORMAT_API FileSearchPath getDefaultDataSearchPath()
shared_ptr< const Document > ConstDocumentPtr
A shared pointer to a const Document.
Definition: Document.h:24