Loading...
Searching...
No Matches
usdaFileFormat.h
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_USD_SDF_USDA_FILE_FORMAT_H
8#define PXR_USD_SDF_USDA_FILE_FORMAT_H
9
10#include "pxr/pxr.h"
14#include "pxr/usd/sdf/api.h"
17#include "pxr/usd/sdf/fileVersion.h"
18
19#include <iosfwd>
20#include <string>
21
22PXR_NAMESPACE_OPEN_SCOPE
23
24SDF_API
25extern TfEnvSetting<std::string> USD_WRITE_NEW_USDA_FILES_AS_VERSION;
26
27#define SDF_USDA_FILE_FORMAT_TOKENS \
28 ((Id, "usda")) \
29 ((Version, "1.0"))
30
31TF_DECLARE_PUBLIC_TOKENS(SdfUsdaFileFormatTokens, SDF_API, SDF_USDA_FILE_FORMAT_TOKENS);
32
34
35SDF_DECLARE_HANDLES(SdfSpec);
36
37class ArAsset;
38
45SDF_API
46extern TfEnvSetting<int> SDF_TEXTFILE_SIZE_WARNING_MB;
47
53{
54public:
55 // SdfFileFormat overrides.
56 SDF_API
57 virtual SdfAbstractDataRefPtr InitData(
58 const FileFormatArguments& args) const override;
59
60 SDF_API
61 virtual bool CanRead(const std::string &file) const override;
62
63 SDF_API
64 virtual bool Read(
65 SdfLayer* layer,
66 const std::string& resolvedPath,
67 bool metadataOnly) const override;
68
71 SDF_API
72 virtual bool WriteToFile(
73 const SdfLayer& layer,
74 const std::string& filePath,
75 const std::string& comment = std::string(),
76 const FileFormatArguments& args = FileFormatArguments()) const override;
77
80 SDF_API
81 virtual bool SaveToFile(
82 const SdfLayer& layer,
83 const std::string& filePath,
84 const std::string& comment = std::string(),
85 const FileFormatArguments& args = FileFormatArguments()) const override;
86
87 SDF_API
88 virtual bool ReadFromString(
89 SdfLayer* layer,
90 const std::string& str) const override;
91
92 SDF_API
93 virtual bool WriteToString(
94 const SdfLayer& layer,
95 std::string* str,
96 const std::string& comment = std::string()) const override;
97
98 SDF_API
99 virtual bool WriteToStream(
100 const SdfSpecHandle &spec,
101 std::ostream& out,
102 size_t indent) const override;
103
104public:
110
112 static SdfFileVersion GetMinInputVersion();
113
115 static SdfFileVersion GetMinOutputVersion();
116
118 static SdfFileVersion GetMaxInputVersion();
119
121 static SdfFileVersion GetMaxOutputVersion();
122
124 static SdfFileVersion GetDefaultOutputVersion();
125
127
128protected:
129 SDF_FILE_FORMAT_FACTORY_ACCESS;
130
132 SDF_API
134
136 SDF_API
138
144 SDF_API
145 explicit SdfUsdaFileFormat(const TfToken& formatId,
146 const TfToken& versionString = TfToken(),
147 const TfToken& target = TfToken());
148
150 SDF_API
152 const std::string& resolvedPath,
153 const std::shared_ptr<ArAsset>& asset) const;
154
156 SDF_API
158 SdfLayer* layer,
159 const std::string& resolvedPath,
160 const std::shared_ptr<ArAsset>& asset,
161 bool metadataOnly) const;
162
163private:
164 // Override to return false. Reloading anonymous text layers clears their
165 // content.
166 SDF_API virtual bool _ShouldSkipAnonymousReload() const override;
167
168 friend class SdfUsdFileFormat;
169};
170
171PXR_NAMESPACE_CLOSE_SCOPE
172
173#endif // PXR_USD_SDF_USDA_FILE_FORMAT_H
Interface for accessing the contents of an asset.
Definition: asset.h:27
Base class for file format implementations.
Definition: fileFormat.h:50
std::map< std::string, std::string > FileFormatArguments
Type for specifying additional file format-specific arguments to the various API below.
Definition: fileFormat.h:102
A scene description container that can combine with other such containers to form simple component as...
Definition: layer.h:84
Base class for all Sdf spec classes.
Definition: spec.h:33
File format for USD files.
Definition: usdFileFormat.h:44
File format used by textual USD files.
static SdfFileVersion GetMaxOutputVersion()
Return the maximum version that it is possible for the software to write.
static SdfFileVersion GetMinOutputVersion()
Return the minimum version that it is possible for the software to write.
static SdfFileVersion GetDefaultOutputVersion()
Return the default version for newly created files.
static SdfFileVersion GetMaxInputVersion()
Return the maximum version that is is possible for the software to read.
virtual SDF_API bool SaveToFile(const SdfLayer &layer, const std::string &filePath, const std::string &comment=std::string(), const FileFormatArguments &args=FileFormatArguments()) const override
SaveToFile writes the layer contents to the file starting with the loaded layer's file version and up...
virtual SDF_API bool WriteToStream(const SdfSpecHandle &spec, std::ostream &out, size_t indent) const override
Write the provided spec to out indented indent levels.
SDF_API bool _CanReadFromAsset(const std::string &resolvedPath, const std::shared_ptr< ArAsset > &asset) const
Return true if layer can be read from asset at resolvedPath.
static SdfFileVersion GetMinInputVersion()
These methods return version info for the current version of the SdfUsdaFileFormat.
virtual SDF_API bool Read(SdfLayer *layer, const std::string &resolvedPath, bool metadataOnly) const override
Reads scene description from the asset specified by resolvedPath into the layer layer.
SDF_API bool _ReadFromAsset(SdfLayer *layer, const std::string &resolvedPath, const std::shared_ptr< ArAsset > &asset, bool metadataOnly) const
Read layer from asset at resolvedPath into layer.
SDF_API SdfUsdaFileFormat()
Constructor.
virtual SDF_API bool ReadFromString(SdfLayer *layer, const std::string &str) const override
Reads data in the string str into the layer layer.
virtual SDF_API bool WriteToFile(const SdfLayer &layer, const std::string &filePath, const std::string &comment=std::string(), const FileFormatArguments &args=FileFormatArguments()) const override
WriteToFile writes the layer contents to the file starting with the default output version and upgrad...
virtual SDF_API SdfAbstractDataRefPtr InitData(const FileFormatArguments &args) const override
This method allows the file format to bind to whatever data container is appropriate.
virtual SDF_API bool WriteToString(const SdfLayer &layer, std::string *str, const std::string &comment=std::string()) const override
Writes the content in layer to the string str.
virtual SDF_API ~SdfUsdaFileFormat()
Destructor.
SDF_API SdfUsdaFileFormat(const TfToken &formatId, const TfToken &versionString=TfToken(), const TfToken &target=TfToken())
Constructor.
virtual SDF_API bool CanRead(const std::string &file) const override
Returns true if file can be read by this format.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Standard pointer typedefs.
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:72
Environment setting variable.
This file defines some macros that are useful for declaring and using static TfTokens.
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:92