HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
layer.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_USD_SDF_LAYER_H
25 #define PXR_USD_SDF_LAYER_H
26 
27 /// \file sdf/layer.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/sdf/api.h"
31 #include "pxr/usd/sdf/data.h"
33 #include "pxr/usd/sdf/identity.h"
34 #include "pxr/usd/sdf/layerHints.h"
37 #include "pxr/usd/sdf/path.h"
38 #include "pxr/usd/sdf/proxyTypes.h"
39 #include "pxr/usd/sdf/spec.h"
40 #include "pxr/usd/sdf/types.h"
41 #include "pxr/usd/ar/ar.h"
42 #include "pxr/usd/ar/assetInfo.h"
45 #include "pxr/base/vt/value.h"
47 
48 #include <atomic>
49 #include <functional>
50 #include <memory>
51 #include <optional>
52 #include <set>
53 #include <string>
54 #include <vector>
55 
57 
60 
61 struct Sdf_AssetInfo;
62 
63 /// \class SdfLayer
64 ///
65 /// A scene description container that can combine with other such containers
66 /// to form simple component assets, and successively larger aggregates. The
67 /// contents of an SdfLayer adhere to the SdfData data model. A layer can be
68 /// ephemeral, or be an asset accessed and serialized through the ArAsset and
69 /// ArResolver interfaces.
70 ///
71 /// The SdfLayer class provides a consistent API for accesing and serializing
72 /// scene description, using any data store provided by Ar plugins. Sdf
73 /// itself provides a UTF-8 text format for layers identified by the ".sdf"
74 /// identifier extension, but via the SdfFileFormat abstraction, allows
75 /// downstream modules and plugins to adapt arbitrary data formats to the
76 /// SdfData/SdfLayer model.
77 ///
78 /// The FindOrOpen() method returns a new SdfLayer object with scene
79 /// description from any supported asset format. Once read, a layer
80 /// remembers which asset it was read from. The Save() method saves the layer
81 /// back out to the original asset. You can use the Export() method to write
82 /// the layer to a different location. You can use the GetIdentifier() method
83 /// to get the layer's Id or GetRealPath() to get the resolved, full URI.
84 ///
85 /// Layer identifiers are UTF-8 encoded strings. A layer's file format is
86 /// determined via the identifier's extension (as resolved by Ar) with [A-Z]
87 /// (and no other characters) explicitly case folded.
88 ///
89 /// Layers can have a timeCode range (startTimeCode and endTimeCode). This range
90 /// represents the suggested playback range, but has no impact on the extent of
91 /// the animation data that may be stored in the layer. The metadatum
92 /// "timeCodesPerSecond" is used to annotate how the time ordinate for samples
93 /// contained in the file scales to seconds. For example, if timeCodesPerSecond
94 /// is 24, then a sample at time ordinate 24 should be viewed exactly one second
95 /// after the sample at time ordinate 0.
96 ///
97 class SdfLayer
98  : public TfRefBase
99  , public TfWeakBase
100 {
101 public:
102  /// Destructor
103  SDF_API
104  virtual ~SdfLayer();
105 
106  /// Noncopyable
107  SdfLayer(const SdfLayer&) = delete;
108  SdfLayer& operator=(const SdfLayer&) = delete;
109 
110  ///
111  /// \name Primary API
112  /// @{
113 
114  /// Returns the schema this layer adheres to. This schema provides details
115  /// about the scene description that may be authored in this layer.
116  SDF_API const SdfSchemaBase& GetSchema() const;
117 
118  /// Returns the file format used by this layer.
119  SDF_API const SdfFileFormatConstPtr& GetFileFormat() const;
120 
121  /// Type for specifying additional file format-specific arguments to
122  /// layer API.
123  typedef std::map<std::string, std::string> FileFormatArguments;
124 
125  /// Returns the file format-specific arguments used during the construction
126  /// of this layer.
128 
129  /// Creates a new empty layer with the given identifier.
130  ///
131  /// Additional arguments may be supplied via the \p args parameter.
132  /// These arguments may control behavior specific to the layer's
133  /// file format.
134  SDF_API
135  static SdfLayerRefPtr CreateNew(const std::string &identifier,
136  const FileFormatArguments &args =
138 
139  /// Creates a new empty layer with the given identifier for a given file
140  /// format class.
141  ///
142  /// This function has the same behavior as the other CreateNew function,
143  /// but uses the explicitly-specified \p fileFormat instead of attempting
144  /// to discern the format from \p identifier.
145  SDF_API
146  static SdfLayerRefPtr CreateNew(const SdfFileFormatConstPtr& fileFormat,
147  const std::string &identifier,
148  const FileFormatArguments &args =
150 
151  /// Creates a new empty layer with the given identifier for a given file
152  /// format class.
153  ///
154  /// The new layer will not be dirty and will not be saved.
155  ///
156  /// Additional arguments may be supplied via the \p args parameter.
157  /// These arguments may control behavior specific to the layer's
158  /// file format.
159  SDF_API
160  static SdfLayerRefPtr New(const SdfFileFormatConstPtr& fileFormat,
161  const std::string &identifier,
162  const FileFormatArguments &args =
164 
165  /// Return an existing layer with the given \p identifier and \p args. If
166  /// the layer can't be found, an error is posted and a null layer is
167  /// returned.
168  ///
169  /// Arguments in \p args will override any arguments specified in
170  /// \p identifier.
171  SDF_API
172  static SdfLayerHandle Find(
173  const std::string &identifier,
175 
176  /// Return an existing layer with the given \p identifier and \p args.
177  /// The given \p identifier will be resolved relative to the \p anchor
178  /// layer. If the layer can't be found, an error is posted and a null
179  /// layer is returned.
180  ///
181  /// If the \p anchor layer is invalid, a coding error is raised, and a null
182  /// handle is returned.
183  ///
184  /// Arguments in \p args will override any arguments specified in
185  /// \p identifier.
186  SDF_API
187  static SdfLayerHandle FindRelativeToLayer(
188  const SdfLayerHandle &anchor,
189  const std::string &identifier,
191 
192  /// Return an existing layer with the given \p identifier and \p args, or
193  /// else load it. If the layer can't be found or loaded, an error is posted
194  /// and a null layer is returned.
195  ///
196  /// Arguments in \p args will override any arguments specified in
197  /// \p identifier.
198  SDF_API
199  static SdfLayerRefPtr FindOrOpen(
200  const std::string &identifier,
202 
203  /// Return an existing layer with the given \p identifier and \p args, or
204  /// else load it. The given \p identifier will be resolved relative to the
205  /// \p anchor layer. If the layer can't be found or loaded, an error is
206  /// posted and a null layer is returned.
207  ///
208  /// If the \p anchor layer is invalid, issues a coding error and returns
209  /// a null handle.
210  ///
211  /// Arguments in \p args will override any arguments specified in
212  /// \p identifier.
213  SDF_API
215  const SdfLayerHandle &anchor,
216  const std::string &identifier,
218 
219  /// Load the given layer from disk as a new anonymous layer. If the
220  /// layer can't be found or loaded, an error is posted and a null
221  /// layer is returned.
222  ///
223  /// The anonymous layer does not retain any knowledge of the backing
224  /// file on the filesystem.
225  ///
226  /// \p metadataOnly is a flag that asks for only the layer metadata
227  /// to be read in, which can be much faster if that is all that is
228  /// required. Note that this is just a hint: some FileFormat readers
229  /// may disregard this flag and still fully populate the layer contents.
230  ///
231  /// An optional \p tag may be specified. See CreateAnonymous for details.
232  SDF_API
234  const std::string &layerPath,
235  bool metadataOnly = false,
236  const std::string& tag = std::string());
237 
238  /// Returns the data from the absolute root path of this layer.
239  SDF_API
240  SdfDataRefPtr GetMetadata() const;
241 
242  /// Return hints about the layer's current contents. Any operation that
243  /// dirties the layer will invalidate all hints.
244  /// \sa SdfLayerHints
245  SDF_API
246  SdfLayerHints GetHints() const;
247 
248  /// Returns handles for all layers currently held by the layer registry.
249  SDF_API
251 
252  /// Returns whether this layer has no significant data.
253  SDF_API
254  bool IsEmpty() const;
255 
256  /// Returns true if this layer streams data from its serialized data
257  /// store on demand, false otherwise.
258  ///
259  /// Layers with streaming data are treated differently to avoid pulling
260  /// in data unnecessarily. For example, reloading a streaming layer
261  /// will not perform fine-grained change notification, since doing
262  /// so would require the full contents of the layer to be loaded.
263  SDF_API
264  bool StreamsData() const;
265 
266  /// Returns true if this layer is detached from its serialized data
267  /// store, false otherwise.
268  ///
269  /// Detached layers are isolated from external changes to their serialized
270  /// data.
271  SDF_API
272  bool IsDetached() const;
273 
274  /// Copies the content of the given layer into this layer.
275  /// Source layer is unmodified.
276  SDF_API
277  void TransferContent(const SdfLayerHandle& layer);
278 
279  /// Creates a new \e anonymous layer with an optional \p tag. An anonymous
280  /// layer is a layer with a system assigned identifier, that cannot be
281  /// saved to disk via Save(). Anonymous layers have an identifier, but no
282  /// real path or other asset information fields.
283  ///
284  /// Anonymous layers may be tagged, which can be done to aid debugging
285  /// subsystems that make use of anonymous layers. The tag becomes the
286  /// display name of an anonymous layer, and is also included in the
287  /// generated identifier. Untagged anonymous layers have an empty display
288  /// name.
289  ///
290  /// Additional arguments may be supplied via the \p args parameter.
291  /// These arguments may control behavior specific to the layer's
292  /// file format.
293  SDF_API
295  const std::string& tag = std::string(),
297 
298  /// Create an anonymous layer with a specific \p format.
299  SDF_API
301  const std::string &tag, const SdfFileFormatConstPtr &format,
303 
304  /// Returns true if this layer is an anonymous layer.
305  SDF_API
306  bool IsAnonymous() const;
307 
308  /// Returns true if the \p identifier is an anonymous layer unique
309  /// identifier.
310  SDF_API
311  static bool IsAnonymousLayerIdentifier(const std::string& identifier);
312 
313  /// Returns the display name for the given \p identifier, using the same
314  /// rules as GetDisplayName.
315  SDF_API
317  const std::string& identifier);
318 
319  /// @}
320  /// \name File I/O
321  /// @{
322 
323  /// Returns \c true if successful, \c false if an error occurred.
324  /// Returns \c false if the layer has no remembered file name or the
325  /// layer type cannot be saved. The layer will not be overwritten if the
326  /// file exists and the layer is not dirty unless \p force is true.
327  SDF_API
328  bool Save(bool force = false) const;
329 
330  /// Exports this layer to a file.
331  /// Returns \c true if successful, \c false if an error occurred.
332  ///
333  /// If \p comment is not empty, the layer gets exported with the given
334  /// comment. Additional arguments may be supplied via the \p args parameter.
335  /// These arguments may control behavior specific to the exported layer's
336  /// file format.
337  ///
338  /// Note that the file name or comment of the original layer is not
339  /// updated. This only saves a copy of the layer to the given filename.
340  /// Subsequent calls to Save() will still save the layer to it's
341  /// previously remembered file name.
342  SDF_API
343  bool Export(const std::string& filename,
344  const std::string& comment = std::string(),
345  const FileFormatArguments& args = FileFormatArguments()) const;
346 
347  /// Writes this layer to the given string.
348  ///
349  /// Returns \c true if successful and sets \p result, otherwise
350  /// returns \c false.
351  SDF_API
352  bool ExportToString(std::string* result) const;
353 
354  /// Reads this layer from the given string.
355  ///
356  /// Returns \c true if successful, otherwise returns \c false.
357  SDF_API
358  bool ImportFromString(const std::string &string);
359 
360  /// Clears the layer of all content.
361  ///
362  /// This restores the layer to a state as if it had just been created
363  /// with CreateNew(). This operation is Undo-able.
364  ///
365  /// The fileName and whether journaling is enabled are not affected
366  /// by this method.
367  SDF_API
368  void Clear();
369 
370  /// Reloads the layer from its persistent representation.
371  ///
372  /// This restores the layer to a state as if it had just been created
373  /// with FindOrOpen(). This operation is Undo-able.
374  ///
375  /// The fileName and whether journaling is enabled are not affected
376  /// by this method.
377  ///
378  /// When called with force = false (the default), Reload attempts to
379  /// avoid reloading layers that have not changed on disk. It does so
380  /// by comparing the file's modification time (mtime) to when the
381  /// file was loaded. If the layer has unsaved modifications, this
382  /// mechanism is not used, and the layer is reloaded from disk. If the
383  /// layer has any
384  /// \ref GetExternalAssetDependencies "external asset dependencies"
385  /// their modification state will also be consulted when determining if
386  /// the layer needs to be reloaded.
387  ///
388  /// Passing true to the \p force parameter overrides this behavior,
389  /// forcing the layer to be reloaded from disk regardless of whether
390  /// it has changed.
391  SDF_API
392  bool Reload(bool force = false);
393 
394  /// Reloads the specified layers.
395  ///
396  /// Returns \c false if one or more layers failed to reload.
397  ///
398  /// See \c Reload() for a description of the \p force flag.
399  ///
400  SDF_API
401  static bool ReloadLayers(const std::set<SdfLayerHandle>& layers,
402  bool force = false);
403 
404  /// Imports the content of the given layer path, replacing the content
405  /// of the current layer.
406  /// Note: If the layer path is the same as the current layer's real path,
407  /// no action is taken (and a warning occurs). For this case use
408  /// Reload().
409  SDF_API
410  bool Import(const std::string &layerPath);
411 
412  /// @}
413  /// \name External references
414  /// @{
415 
416  /// \deprecated
417  /// Use GetCompositionAssetDependencies instead.
418  SDF_API
419  std::set<std::string> GetExternalReferences() const;
420 
421  /// \deprecated
422  /// Use UpdateCompositionAssetDependency instead.
423  SDF_API
425  const std::string &oldAssetPath,
426  const std::string &newAssetPath=std::string());
427 
428  /// Return paths of all assets this layer depends on due to composition
429  /// fields.
430  ///
431  /// This includes the paths of all layers referred to by reference,
432  /// payload, and sublayer fields in this layer. This function only returns
433  /// direct composition dependencies of this layer, i.e. it does not recurse
434  /// to find composition dependencies from its dependent layer assets.
435  SDF_API
436  std::set<std::string> GetCompositionAssetDependencies() const;
437 
438  /// Updates the asset path of a composation dependency in this layer.
439  ///
440  /// If \p newAssetPath is supplied, the update works as "rename", updating
441  /// any occurrence of \p oldAssetPath to \p newAssetPath in all reference,
442  /// payload, and sublayer fields.
443  ///
444  /// If \p newAssetPath is not given, this update behaves as a "delete",
445  /// removing all occurrences of \p oldAssetPath from all reference, payload,
446  /// and sublayer fields.
447  SDF_API
449  const std::string &oldAssetPath,
450  const std::string &newAssetPath=std::string());
451 
452  /// Returns a set of resolved paths to all external asset dependencies
453  /// the layer needs to generate its contents. These are additional asset
454  /// dependencies that are determined by the layer's
455  /// \ref SdfFileFormat::GetExternalAssetDependencies "file format" and
456  /// will be consulted during Reload() when determining if the layer needs
457  /// to be reloaded. This specifically does not include dependencies related
458  /// to composition, i.e. this will not include assets from references,
459  /// payloads, and sublayers.
460  SDF_API
461  std::set<std::string> GetExternalAssetDependencies() const;
462 
463  /// @}
464  /// \name Identification
465  ///
466  /// A layer's identifier is a string that uniquely identifies a layer.
467  /// At minimum, it is the string by which the layer was created, either
468  /// via FindOrOpen or CreateNew. If additional arguments were passed
469  /// to those functions, those arguments will be encoded in the identifier.
470  ///
471  /// For example:
472  /// FindOrOpen('foo.sdf', args={'a':'b', 'c':'d'}).identifier
473  /// => "foo.sdf:SDF_FORMAT_ARGS:a=b&c=d"
474  ///
475  /// Note that this means the identifier may in general not be a path.
476  ///
477  /// The identifier format is subject to change; consumers should NOT
478  /// parse layer identifiers themselves, but should use the supplied
479  /// SplitIdentifier and CreateIdentifier helper functions.
480  ///
481  /// @{
482 
483  /// Splits the given layer identifier into its constituent layer path
484  /// and arguments.
485  SDF_API
486  static bool SplitIdentifier(
487  const std::string& identifier,
488  std::string* layerPath,
489  FileFormatArguments* arguments);
490 
491  /// Joins the given layer path and arguments into an identifier.
492  SDF_API
494  const std::string& layerPath,
495  const FileFormatArguments& arguments);
496 
497  /// Returns the layer identifier.
498  SDF_API
499  const std::string& GetIdentifier() const;
500 
501  /// Sets the layer identifier.
502  /// Note that the new identifier must have the same arguments (if any)
503  /// as the old identifier.
504  SDF_API
505  void SetIdentifier(const std::string& identifier);
506 
507  /// Update layer asset information. Calling this method re-resolves the
508  /// layer identifier, which updates asset information such as the layer's
509  /// resolved path and other asset info. This may be used to update the
510  /// layer after external changes to the underlying asset system.
511  SDF_API
512  void UpdateAssetInfo();
513 
514  /// Returns the layer's display name.
515  ///
516  /// The display name is the base filename of the identifier.
517  SDF_API
518  std::string GetDisplayName() const;
519 
520  /// Returns the resolved path for this layer. This is the path where
521  /// this layer exists or may exist after a call to Save().
522  SDF_API
523  const ArResolvedPath& GetResolvedPath() const;
524 
525  /// Returns the resolved path for this layer. This is equivalent to
526  /// GetResolvedPath().GetPathString().
527  SDF_API
528  const std::string& GetRealPath() const;
529 
530  /// Returns the file extension to use for this layer.
531  /// If this layer was loaded from disk, it should match the extension
532  /// of the file format it was loaded as; if this is an anonymous
533  /// in-memory layer it will be the default extension.
534  SDF_API
536 
537  /// Returns the asset system version of this layer. If a layer is loaded
538  /// from a location that is not version managed, or a configured asset
539  /// system is not present when the layer is loaded or created, the version
540  /// is empty. By default, asset version tracking is disabled; this method
541  /// returns empty unless asset version tracking is enabled.
542  SDF_API
543  const std::string& GetVersion() const;
544 
545  /// Returns the layer identifier in asset path form. In the presence of a
546  /// properly configured path resolver, the asset path is a double-slash
547  /// prefixed depot path. If the path resolver is not configured, the asset
548  /// path of a layer is empty.
549  SDF_API
550  const std::string& GetRepositoryPath() const;
551 
552  /// Returns the asset name associated with this layer.
553  SDF_API
554  const std::string& GetAssetName() const;
555 
556  /// Returns resolve information from the last time the layer identifier
557  /// was resolved.
558  SDF_API
559  const VtValue& GetAssetInfo() const;
560 
561  /// Returns the path to the asset specified by \p assetPath using this layer
562  /// to anchor the path if necessary. Returns \p assetPath if it's empty or
563  /// an anonymous layer identifier.
564  ///
565  /// This method can be used on asset paths that are authored in this layer
566  /// to create new asset paths that can be copied to other layers. These new
567  /// asset paths should refer to the same assets as the original asset
568  /// paths. For example, if the underlying ArResolver is filesystem-based and
569  /// \p assetPath is a relative filesystem path, this method might return the
570  /// absolute filesystem path using this layer's location as the anchor.
571  ///
572  /// The returned path should in general not be assumed to be an absolute
573  /// filesystem path or any other specific form. It is "absolute" in that it
574  /// should resolve to the same asset regardless of what layer it's authored
575  /// in.
576  SDF_API
577  std::string ComputeAbsolutePath(const std::string& assetPath) const;
578 
579  /// @}
580 
581  /// \name Fields
582  ///
583  /// All scene description for a given object is stored as a set of
584  /// key/value pairs called fields. These methods provide direct access to
585  /// those fields, though most clients should use the Spec API to ensure
586  /// data consistency.
587  ///
588  /// These methods all take SdfPath to identify the queried spec.
589  ///
590  /// @{
591 
592  /// Return the spec type for \a path. This returns SdfSpecTypeUnknown if no
593  /// spec exists at \a path.
594  SDF_API
595  SdfSpecType GetSpecType(const SdfPath& path) const;
596 
597  /// Return whether a spec exists at \a path.
598  SDF_API
599  bool HasSpec(const SdfPath& path) const;
600 
601  /// Return the names of all the fields that are set at \p path.
602  SDF_API
603  std::vector<TfToken> ListFields(const SdfPath& path) const;
604 
605  /// Return whether a value exists for the given \a path and \a fieldName.
606  /// Optionally returns the value if it exists.
607  SDF_API
608  bool HasField(const SdfPath& path, const TfToken& fieldName,
609  VtValue *value=NULL) const;
610  SDF_API
611  bool HasField(const SdfPath& path, const TfToken& fieldName,
612  SdfAbstractDataValue *value) const;
613 
614  /// Returns \c true if the object has a non-empty value with name
615  /// \p name and type \p T. If value ptr is provided, returns the
616  /// value found.
617  template <class T>
618  bool HasField(const SdfPath& path, const TfToken &name,
619  T* value) const
620  {
621  if (!value) {
622  return HasField(path, name, static_cast<VtValue *>(NULL));
623  }
624 
625  SdfAbstractDataTypedValue<T> outValue(value);
626  const bool hasValue = HasField(
627  path, name, static_cast<SdfAbstractDataValue *>(&outValue));
628 
630  return hasValue && outValue.isValueBlock;
631  }
632 
633  return hasValue && (!outValue.isValueBlock);
634  }
635 
636  /// Return the type of the value for \p name on spec \p path. If no such
637  /// field exists, return typeid(void).
638  std::type_info const &GetFieldTypeid(
639  const SdfPath &path, const TfToken &name) const {
640  return _data->GetTypeid(path, name);
641  }
642 
643  /// Return whether a value exists for the given \a path and \a fieldName and
644  /// \a keyPath. The \p keyPath is a ':'-separated path addressing an
645  /// element in sub-dictionaries. Optionally returns the value if it exists.
646  SDF_API
647  bool HasFieldDictKey(const SdfPath& path,
648  const TfToken &fieldName,
649  const TfToken &keyPath,
650  VtValue *value=NULL) const;
651  SDF_API
652  bool HasFieldDictKey(const SdfPath& path,
653  const TfToken &fieldName,
654  const TfToken &keyPath,
655  SdfAbstractDataValue *value) const;
656 
657  /// Returns \c true if the object has a non-empty value with name \p name
658  /// and \p keyPath and type \p T. If value ptr is provided, returns the
659  /// value found. The \p keyPath is a ':'-separated path addressing an
660  /// element in sub-dictionaries.
661  template <class T>
662  bool HasFieldDictKey(const SdfPath& path, const TfToken &name,
663  const TfToken &keyPath, T* value) const
664  {
665  if (!value) {
666  return HasFieldDictKey(path, name, keyPath,
667  static_cast<VtValue *>(NULL));
668  }
669 
670  SdfAbstractDataTypedValue<T> outValue(value);
671  return HasFieldDictKey(path, name, keyPath,
672  static_cast<SdfAbstractDataValue *>(&outValue));
673  }
674 
675 
676  /// Return the value for the given \a path and \a fieldName. Returns an
677  /// empty value if none is set.
678  SDF_API
679  VtValue GetField(const SdfPath& path,
680  const TfToken& fieldName) const;
681 
682  /// Return the value for the given \a path and \a fieldName. Returns the
683  /// provided \a defaultValue value if none is set.
684  template <class T>
685  inline T GetFieldAs(const SdfPath& path,
686  const TfToken& fieldName, const T& defaultValue = T()) const
687  {
688  return _data->GetAs<T>(path, fieldName, defaultValue);
689  }
690 
691  /// Return the value for the given \a path and \a fieldName at \p
692  /// keyPath. Returns an empty value if none is set. The \p keyPath is a
693  /// ':'-separated path addressing an element in sub-dictionaries.
694  SDF_API
696  const TfToken& fieldName,
697  const TfToken& keyPath) const;
698 
699  /// Set the value of the given \a path and \a fieldName.
700  SDF_API
701  void SetField(const SdfPath& path, const TfToken& fieldName,
702  const VtValue& value);
703  SDF_API
704  void SetField(const SdfPath& path, const TfToken& fieldName,
706 
707  /// Set the value of the given \a path and \a fieldName.
708  template <class T>
709  void SetField(const SdfPath& path, const TfToken& fieldName,
710  const T& val)
711  {
712  // Ideally, this would make use of the SdfAbstractDataConstValue
713  // API to avoid unnecessarily copying the value into a VtValue.
714  // However, Sdf needs to create a VtValue for change processing.
715  // If the underlying SdAbstractData implementation also needs a
716  // VtValue, using the SdfAbstractDataConstValue API would cause
717  // another copy to be made. So, it's more efficient to just create
718  // the VtValue once here and push that along.
719  SetField(path, fieldName, VtValue(val));
720  }
721 
722  /// Set the value of the given \a path and \a fieldName. The \p keyPath is a
723  /// ':'-separated path addressing an element in sub-dictionaries.
724  SDF_API
725  void SetFieldDictValueByKey(const SdfPath& path,
726  const TfToken& fieldName,
727  const TfToken& keyPath,
728  const VtValue& value);
729  SDF_API
730  void SetFieldDictValueByKey(const SdfPath& path,
731  const TfToken& fieldName,
732  const TfToken& keyPath,
734 
735  /// Set the value of the given \a path and \a fieldName. The \p keyPath is
736  /// a ':'-separated path addressing an element in sub-dictionaries.
737  template <class T>
738  void SetFieldDictValueByKey(const SdfPath& path,
739  const TfToken& fieldName,
740  const TfToken& keyPath,
741  const T& val)
742  {
743  // Ideally, this would make use of the SdfAbstractDataConstValue
744  // API to avoid unnecessarily copying the value into a VtValue.
745  // However, Sdf needs to create a VtValue for change processing.
746  // If the underlying SdAbstractData implementation also needs
747  // VtValue, using the SdfAbstractDataConstValue API would cause
748  // another copy to be made. So, it's more efficient to just create
749  // the VtValue once here and push that along.
750  SetFieldDictValueByKey(path, fieldName, keyPath, VtValue(val));
751  }
752 
753  /// Remove the field at \p path and \p fieldName, if one exists.
754  SDF_API
755  void EraseField(const SdfPath& path, const TfToken& fieldName);
756 
757  /// Remove the field at \p path and \p fieldName and \p keyPath, if one
758  /// exists. The \p keyPath is a ':'-separated path addressing an
759  /// element in sub-dictionaries.
760  SDF_API
761  void EraseFieldDictValueByKey(const SdfPath& path,
762  const TfToken& fieldName,
763  const TfToken& keyPath);
764 
765  /// \name Traversal
766  /// @{
767 
768  /// Callback function for Traverse. This callback will be invoked with
769  /// the path of each spec that is visited.
770  /// \sa Traverse
771  typedef std::function<void(const SdfPath&)> TraversalFunction;
772 
773  // Traverse will perform a traversal of the scene description hierarchy
774  // rooted at \a path, calling \a func on each spec that it finds.
775  SDF_API
776  void Traverse(const SdfPath& path, const TraversalFunction& func);
777 
778  /// @}
779 
780  /// \name Metadata
781  /// @{
782 
783  /// Returns the color configuration asset-path for this layer.
784  ///
785  /// The default value is an empty asset-path.
786  SDF_API
788 
789  /// Sets the color configuration asset-path for this layer.
790  SDF_API
791  void SetColorConfiguration(const SdfAssetPath &colorConfiguration);
792 
793  /// Returns true if color configuration metadata is set in this layer.
794  /// \sa GetColorConfiguration(), SetColorConfiguration()
795  SDF_API
796  bool HasColorConfiguration() const;
797 
798  /// Clears the color configuration metadata authored in this layer.
799  /// \sa HasColorConfiguration(), SetColorConfiguration()
800  SDF_API
802 
803  /// Returns the color management system used to interpret the color
804  /// configuration asset-path authored in this layer.
805  ///
806  /// The default value is an empty token, which implies that the clients
807  /// will have to determine the color management system from the color
808  /// configuration asset path (i.e. from its file extension), if it's
809  /// specified.
810  SDF_API
812 
813  /// Sets the color management system used to interpret the color
814  /// configuration asset-path authored this layer.
815  SDF_API
816  void SetColorManagementSystem(const TfToken &cms);
817 
818  /// Returns true if colorManagementSystem metadata is set in this layer.
819  /// \sa GetColorManagementSystem(), SetColorManagementSystem()
820  SDF_API
821  bool HasColorManagementSystem() const;
822 
823  /// Clears the 'colorManagementSystem' metadata authored in this layer.
824  /// \sa HascolorManagementSystem(), SetColorManagementSystem()
825  SDF_API
827 
828  /// Returns the comment string for this layer.
829  ///
830  /// The default value for comment is "".
831  SDF_API
832  std::string GetComment() const;
833 
834  /// Sets the comment string for this layer.
835  SDF_API
836  void SetComment(const std::string &comment);
837 
838  /// Return the defaultPrim metadata for this layer. This field
839  /// indicates the name of which root prim should be targeted by a reference
840  /// or payload to this layer that doesn't specify a prim path.
841  ///
842  /// The default value is the empty token.
843  SDF_API
844  TfToken GetDefaultPrim() const;
845 
846  /// Set the default prim metadata for this layer. The root prim with this
847  /// name will be targeted by a reference or a payload to this layer that
848  /// doesn't specify a prim path. Note that this must be a root prim
849  /// <b>name</b> not a path. E.g. "rootPrim" rather than "/rootPrim". See
850  /// GetDefaultPrim().
851  SDF_API
852  void SetDefaultPrim(const TfToken &name);
853 
854  /// Clear the default prim metadata for this layer. See GetDefaultPrim()
855  /// and SetDefaultPrim().
856  SDF_API
857  void ClearDefaultPrim();
858 
859  /// Return true if the default prim metadata is set in this layer. See
860  /// GetDefaultPrim() and SetDefaultPrim().
861  SDF_API
862  bool HasDefaultPrim();
863 
864  /// Returns the documentation string for this layer.
865  ///
866  /// The default value for documentation is "".
867  SDF_API
869 
870  /// Sets the documentation string for this layer.
871  SDF_API
872  void SetDocumentation(const std::string &documentation);
873 
874  /// Returns the layer's start timeCode.
875  ///
876  /// The start and end timeCodes of a layer represent the suggested playback
877  /// range. However, time-varying content is not limited to the timeCode range
878  /// of the layer.
879  ///
880  /// The default value for startTimeCode is 0.
881  SDF_API
882  double GetStartTimeCode() const;
883 
884  /// Sets the layer's start timeCode.
885  SDF_API
886  void SetStartTimeCode(double startTimecode);
887 
888  /// Returns true if the layer has a startTimeCode opinion.
889  SDF_API
890  bool HasStartTimeCode() const;
891 
892  /// Clear the startTimeCode opinion.
893  SDF_API
894  void ClearStartTimeCode();
895 
896  /// Returns the layer's end timeCode.
897  /// The start and end timeCode of a layer represent a suggested playback range.
898  /// However, time-varying content is not limited to the timeCode range of the
899  /// layer.
900  ///
901  /// The default value for endTimeCode is 0.
902  SDF_API
903  double GetEndTimeCode() const;
904 
905  /// Sets the layer's end timeCode.
906  SDF_API
907  void SetEndTimeCode(double endTimeCode);
908 
909  /// Returns true if the layer has an endTimeCode opinion.
910  SDF_API
911  bool HasEndTimeCode() const;
912 
913  /// Clear the endTimeCode opinion.
914  SDF_API
915  void ClearEndTimeCode();
916 
917  /// Returns the layer's timeCodes per second.
918  ///
919  /// Scales the time ordinate for samples contained in the file to seconds.
920  /// If timeCodesPerSecond is 24, then a sample at time ordinate 24 should
921  /// be viewed exactly one second after the sample at time ordinate 0.
922  ///
923  /// If this layer doesn't have an authored value for timeCodesPerSecond, but
924  /// it does have an authored value for framesPerSecond, this method will
925  /// return the value of framesPerSecond. This "dynamic fallback" allows
926  /// layers to lock framesPerSecond and timeCodesPerSecond to the same value
927  /// by specifying only framesPerSecond.
928  ///
929  /// The default value of timeCodesPerSecond, used only if there is no
930  /// authored value for either timeCodesPerSecond or framesPerSecond, is 24.
931  SDF_API
932  double GetTimeCodesPerSecond() const;
933 
934  /// Sets the layer's timeCodes per second
935  SDF_API
936  void SetTimeCodesPerSecond(double timeCodesPerSecond);
937 
938  /// Returns true if the layer has a timeCodesPerSecond opinion.
939  SDF_API
940  bool HasTimeCodesPerSecond() const;
941 
942  /// Clear the timeCodesPerSecond opinion.
943  SDF_API
945 
946  /// Returns the layer's frames per second.
947  ///
948  /// This makes an advisory statement about how the contained data can be
949  /// most usefully consumed and presented. It's primarily an indication of
950  /// the expected playback rate for the data, but a timeline editing tool
951  /// might also want to use this to decide how to scale and label its
952  /// timeline.
953  ///
954  /// The default value for framesPerSecond is 24.
955  SDF_API
956  double GetFramesPerSecond() const;
957 
958  /// Sets the layer's frames per second
959  SDF_API
960  void SetFramesPerSecond(double framesPerSecond);
961 
962  /// Returns true if the layer has a frames per second opinion.
963  SDF_API
964  bool HasFramesPerSecond() const;
965 
966  /// Clear the framesPerSecond opinion.
967  SDF_API
968  void ClearFramesPerSecond();
969 
970  /// Returns the layer's frame precision.
971  SDF_API
972  int GetFramePrecision() const;
973 
974  /// Sets the layer's frame precision.
975  SDF_API
976  void SetFramePrecision(int framePrecision);
977 
978  /// Returns true if the layer has a frames precision opinion.
979  SDF_API
980  bool HasFramePrecision() const;
981 
982  /// Clear the framePrecision opinion.
983  SDF_API
984  void ClearFramePrecision();
985 
986  /// Returns the layer's owner.
987  SDF_API
988  std::string GetOwner() const;
989 
990  /// Sets the layer's owner.
991  SDF_API
992  void SetOwner(const std::string& owner);
993 
994  /// Returns true if the layer has an owner opinion.
995  SDF_API
996  bool HasOwner() const;
997 
998  /// Clear the owner opinion.
999  SDF_API
1000  void ClearOwner();
1001 
1002  /// Returns the layer's session owner.
1003  /// Note: This should only be used by session layers.
1004  SDF_API
1005  std::string GetSessionOwner() const;
1006 
1007  /// Sets the layer's session owner.
1008  /// Note: This should only be used by session layers.
1009  SDF_API
1010  void SetSessionOwner(const std::string& owner);
1011 
1012  /// Returns true if the layer has a session owner opinion.
1013  SDF_API
1014  bool HasSessionOwner() const;
1015 
1016  // Clear the session owner opinion.
1017  SDF_API
1018  void ClearSessionOwner();
1019 
1020  /// Returns true if the layer's sublayers are expected to have owners.
1021  SDF_API
1022  bool GetHasOwnedSubLayers() const;
1023 
1024  /// Sets whether the layer's sublayers are expected to have owners.
1025  SDF_API
1026  void SetHasOwnedSubLayers(bool);
1027 
1028  /// Returns the CustomLayerData dictionary associated with this layer.
1029  ///
1030  /// This is a dictionary is custom metadata that is associated with
1031  /// this layer. It allows users to encode any set of information for
1032  /// human or program consumption.
1033  SDF_API
1035 
1036  /// Sets the CustomLayerData dictionary associated with this layer.
1037  SDF_API
1038  void SetCustomLayerData(const VtDictionary& value);
1039 
1040  /// Returns true if CustomLayerData is authored on the layer.
1041  SDF_API
1042  bool HasCustomLayerData() const;
1043 
1044  /// Clears out the CustomLayerData dictionary associated with this layer.
1045  SDF_API
1046  void ClearCustomLayerData();
1047 
1048  /// Returns the expression variables dictionary authored on this layer.
1049  /// See \ref Sdf_Page_VariableExpressions for more details.
1050  SDF_API
1052 
1053  /// Sets the expression variables dictionary for this layer.
1054  SDF_API
1055  void SetExpressionVariables(const VtDictionary& expressionVars);
1056 
1057  /// Returns true if expression variables are authored on this layer.
1058  SDF_API
1059  bool HasExpressionVariables() const;
1060 
1061  /// Clears the expression variables dictionary authored on this layer.
1062  SDF_API
1063  void ClearExpressionVariables();
1064 
1065  /// @}
1066  /// \name Prims
1067  /// @{
1068 
1069  // Type for root prims view.
1071 
1072  /// Returns a vector of the layer's root prims
1073  SDF_API
1074  RootPrimsView GetRootPrims() const;
1075 
1076  /// Sets a new vector of root prims.
1077  /// You can re-order, insert and remove prims but cannot
1078  /// rename them this way. If any of the listed prims have
1079  /// an existing owner, they will be reparented.
1080  SDF_API
1081  void SetRootPrims(const SdfPrimSpecHandleVector &rootPrims);
1082 
1083  /// Adds a new root prim at the given index.
1084  /// If the index is -1, the prim is inserted at the end.
1085  /// The layer will take ownership of the prim, via a TfRefPtr.
1086  /// Returns true if successful, false if failed (for example,
1087  /// due to a duplicate name).
1088  SDF_API
1089  bool InsertRootPrim(const SdfPrimSpecHandle &prim, int index = -1);
1090 
1091  /// Remove a root prim.
1092  SDF_API
1093  void RemoveRootPrim(const SdfPrimSpecHandle &prim);
1094 
1095  /// Cause \p spec to be removed if it no longer affects the scene when the
1096  /// last change block is closed, or now if there are no change blocks.
1097  SDF_API
1098  void ScheduleRemoveIfInert(const SdfSpec& spec);
1099 
1100  /// Removes scene description that does not affect the scene in the
1101  /// layer namespace beginning with \p prim.
1102  ///
1103  /// Calling this method on a prim will only clean up prims with specifier
1104  /// 'over' that are not contributing any opinions. The \p prim will only
1105  /// be removed if all of its nameChildren are also inert. The hierarchy
1106  /// \p prim is defined in will be pruned up to the layer root for each
1107  /// successive inert parent that has specifier 'over'.
1108  ///
1109  /// note: PrimSpecs that contain any PropertySpecs, even PropertySpecs with
1110  /// required fields only (see PropertySpec::HasRequiredFieldsOnly)
1111  /// are not considered inert, and thus the prim won't be removed.
1112  SDF_API
1113  void RemovePrimIfInert(SdfPrimSpecHandle prim);
1114 
1115  /// Removes prop if it has only required fields (i.e. is not
1116  /// contributing any opinions to the scene other than property
1117  /// instantiation).
1118  ///
1119  /// The hierarchy \p prop is defined in will then be pruned up to the
1120  /// layer root for each successive inert parent.
1121  SDF_API
1122  void RemovePropertyIfHasOnlyRequiredFields(SdfPropertySpecHandle prop);
1123 
1124  /// Removes all scene description in this layer that does not affect the
1125  /// scene.
1126  ///
1127  /// This method walks the layer namespace hierarchy and removes any prims
1128  /// and that are not contributing any opinions.
1129  SDF_API
1131 
1132  /// Returns the list of prim names for this layer's reorder rootPrims
1133  /// statement.
1134  ///
1135  /// See SetRootPrimOrder() for more info.
1136  SDF_API
1138 
1139  /// Given a list of (possible sparse) prim names, authors a reorder
1140  /// rootPrims statement for this prim.
1141  ///
1142  /// This reorder statement can modify the order of root prims that have
1143  /// already been explicitly ordered with InsertRootPrim() or SetRootPrims();
1144  /// but only during composition. Therefore, GetRootPrims(),
1145  /// InsertRootPrim(), SetRootPrims(), etc. do not read, author, or pay any
1146  /// attention to this statement.
1147  SDF_API
1148  void SetRootPrimOrder(const std::vector<TfToken>& names);
1149 
1150  /// Adds a new root prim name in the root prim order.
1151  /// If the index is -1, the name is inserted at the end.
1152  SDF_API
1153  void InsertInRootPrimOrder(const TfToken &name, int index = -1);
1154 
1155  /// Removes a root prim name from the root prim order.
1156  SDF_API
1157  void RemoveFromRootPrimOrder(const TfToken & name);
1158 
1159  /// Removes a root prim name from the root prim order by index.
1160  SDF_API
1162 
1163  /// Reorders the given list of prim names according to the reorder rootPrims
1164  /// statement for this layer.
1165  ///
1166  /// This routine employs the standard list editing operations for ordered
1167  /// items in a ListEditor.
1168  SDF_API
1169  void ApplyRootPrimOrder(std::vector<TfToken> *vec) const;
1170 
1171  /// @}
1172  /// \name Sublayers
1173  /// @{
1174 
1175  /// Returns a proxy for this layer's sublayers.
1176  ///
1177  /// Sub-layers are the weaker layers directly included by this layer.
1178  /// They're in order from strongest to weakest and they're all weaker
1179  /// than this layer.
1180  ///
1181  /// Edits through the proxy changes the sublayers. If this layer does
1182  /// not have any sublayers the proxy is empty.
1183  ///
1184  /// Sub-layer paths are asset paths, and thus must contain valid asset path
1185  /// characters (UTF-8 without C0 and C1 controls). See SdfAssetPath for
1186  /// more details.
1187  SDF_API
1189 
1190  /// Sets the paths of the layer's sublayers.
1191  SDF_API
1192  void SetSubLayerPaths(const std::vector<std::string>& newPaths);
1193 
1194  /// Returns the number of sublayer paths (and offsets).
1195  SDF_API
1196  size_t GetNumSubLayerPaths() const;
1197 
1198  /// Inserts new sublayer path at the given index.
1199  ///
1200  /// The default index of -1 means to insert at the end.
1201  SDF_API
1202  void InsertSubLayerPath(const std::string& path, int index = -1);
1203 
1204  /// Removes sublayer path at the given index.
1205  SDF_API
1206  void RemoveSubLayerPath(int index);
1207 
1208  /// Returns the layer offsets for all the subLayer paths.
1209  SDF_API
1211 
1212  /// Returns the layer offset for the subLayer path at the given index.
1213  SDF_API
1215 
1216  /// Sets the layer offset for the subLayer path at the given index.
1217  SDF_API
1218  void SetSubLayerOffset(const SdfLayerOffset& offset, int index);
1219 
1220  /// @}
1221 
1222  /// \name Detached Layers
1223  ///
1224  /// Detached layers are layers that are detached from the serialized
1225  /// data store and isolated from any external changes to that serialized
1226  /// data.
1227  ///
1228  /// File format plugins may produce layers that maintain a persistent
1229  /// connection to their serialized representation to read data on-demand.
1230  /// For example, a file format might set up layers to hold an open file
1231  /// handle and read attribute time samples from it only when requested, to
1232  /// avoid pulling in unnecessary data. However, there may be times when
1233  /// keeping this connection is undesirable. In the previous example, a
1234  /// crash might occur if some other process were to change the file on
1235  /// disk, or users might be prevented from overwriting the file at all
1236  /// which could interfere with workflow.
1237  ///
1238  /// To avoid these problems, the functions below may be used to specify
1239  /// layers that are to be detached from the original serialized data.
1240  ///
1241  /// @{
1242 
1243  /// \class DetachedLayerRules
1244  ///
1245  /// Object used to specify detached layers. Layers may be included or
1246  /// excluded from the detached layer set by specifying simple substring
1247  /// patterns for layer identifiers. For example, the following will
1248  /// include all layers in the detached layer set, except for those whose
1249  /// identifiers contain the substring "sim" or "geom":
1250  ///
1251  /// \code
1252  /// SdfLayer::SetDetachedLayerRules(
1253  /// SdfLayer::DetachedLayerRules()
1254  /// .IncludeAll();
1255  /// .Exclude({"sim", "geom"})
1256  /// );
1257  /// \endcode
1259  {
1260  public:
1261  /// A default constructed rules object Excludes all layers from
1262  /// the detached layer set.
1263  DetachedLayerRules() = default;
1264 
1265  /// Include all layers in the detached layer set.
1267  {
1268  _includeAll = true;
1269  _include.clear();
1270  return *this;
1271  }
1272 
1273  /// Include layers whose identifiers contain any of the strings in
1274  /// \p patterns in the detached layer set.
1275  SDF_API
1276  DetachedLayerRules& Include(const std::vector<std::string>& patterns);
1277 
1278  /// Exclude layers whose identifiers contain any of the strings in
1279  /// \p patterns from the detached layer set.
1280  SDF_API
1281  DetachedLayerRules& Exclude(const std::vector<std::string>& patterns);
1282 
1283  bool IncludedAll() const { return _includeAll; }
1284  const std::vector<std::string>& GetIncluded() const { return _include; }
1285  const std::vector<std::string>& GetExcluded() const { return _exclude; }
1286 
1287  /// Returns true if \p identifier is included in the detached layer set,
1288  /// false otherwise.
1289  ///
1290  /// \p identifier is included if it matches an include pattern (or the
1291  /// mask includes all identifiers) and it does not match any of the
1292  /// exclude patterns. Anonymous layer identifiers are always excluded
1293  /// from the mask.
1294  SDF_API
1295  bool IsIncluded(const std::string& identifier) const;
1296 
1297  private:
1298  friend class SdfLayer;
1299 
1300  std::vector<std::string> _include;
1301  std::vector<std::string> _exclude;
1302  bool _includeAll = false;
1303  };
1304 
1305  /// Sets the rules specifying detached layers.
1306  ///
1307  /// Newly-created or opened layers whose identifiers are included in
1308  /// \p rules will be opened as detached layers. Existing layers that are now
1309  /// included or no longer included will be reloaded. Any unsaved
1310  /// modifications to those layers will be lost.
1311  ///
1312  /// This function is not thread-safe. It may not be run concurrently with
1313  /// any other functions that open, close, or read from any layers.
1314  ///
1315  /// The detached layer rules are initially set to exclude all layers.
1316  /// This may be overridden by setting the environment variables
1317  /// SDF_LAYER_INCLUDE_DETACHED and SDF_LAYER_EXCLUDE_DETACHED to specify
1318  /// the initial set of include and exclude patterns in the rules. These
1319  /// variables can be set to a comma-delimited list of patterns.
1320  /// SDF_LAYER_INCLUDE_DETACHED may also be set to "*" to include
1321  /// all layers. Note that these environment variables only set the initial
1322  /// state of the detached layer rules; these values may be overwritten by
1323  /// subsequent calls to this function.
1324  ///
1325  /// See SdfLayer::DetachedLayerRules::IsIncluded for details on how the
1326  /// rules are applied to layer identifiers.
1327  SDF_API
1328  static void SetDetachedLayerRules(const DetachedLayerRules& mask);
1329 
1330  /// Returns the current rules for the detached layer set.
1331  SDF_API
1332  static const DetachedLayerRules& GetDetachedLayerRules();
1333 
1334  /// Returns whether the given layer identifier is included in the
1335  /// current rules for the detached layer set. This is equivalent to
1336  /// GetDetachedLayerRules().IsIncluded(identifier).
1337  SDF_API
1338  static bool IsIncludedByDetachedLayerRules(const std::string& identifier);
1339 
1340  /// @}
1341 
1342  /// \name Muting
1343  /// @{
1344 
1345  /// Returns the set of muted layer paths.
1346  SDF_API
1347  static std::set<std::string> GetMutedLayers();
1348 
1349  /// Returns \c true if the current layer is muted.
1350  SDF_API
1351  bool IsMuted() const;
1352 
1353  /// Returns \c true if the specified layer path is muted.
1354  SDF_API
1355  static bool IsMuted(const std::string &path);
1356 
1357  /// Mutes the current layer if \p muted is \c true, and unmutes it
1358  /// otherwise.
1359  SDF_API
1360  void SetMuted(bool muted);
1361 
1362  /// Add the specified path to the muted layers set.
1363  SDF_API
1364  static void AddToMutedLayers(const std::string &mutedPath);
1365 
1366  /// Remove the specified path from the muted layers set.
1367  SDF_API
1368  static void RemoveFromMutedLayers(const std::string &mutedPath);
1369 
1370  /// @}
1371  /// \name Lookup
1372  /// @{
1373 
1374  /// Returns the layer's pseudo-root prim.
1375  ///
1376  /// The layer's root prims are namespace children of the pseudo-root.
1377  /// The pseudo-root exists to make the namespace hierarchy a tree
1378  /// instead of a forest. This simplifies the implementation of
1379  /// some algorithms.
1380  ///
1381  /// A layer always has a pseudo-root prim.
1382  SDF_API
1383  SdfPrimSpecHandle GetPseudoRoot() const;
1384 
1385  /// Returns the object at the given \p path.
1386  ///
1387  /// There is no distinction between an absolute and relative path
1388  /// at the SdLayer level.
1389  ///
1390  /// Returns \c NULL if there is no object at \p path.
1391  SDF_API
1392  SdfSpecHandle GetObjectAtPath(const SdfPath &path);
1393 
1394  /// Returns the prim at the given \p path.
1395  ///
1396  /// Returns \c NULL if there is no prim at \p path.
1397  /// This is simply a more specifically typed version of
1398  /// \c GetObjectAtPath().
1399  SDF_API
1400  SdfPrimSpecHandle GetPrimAtPath(const SdfPath &path);
1401 
1402  /// Returns a property at the given \p path.
1403  ///
1404  /// Returns \c NULL if there is no property at \p path.
1405  /// This is simply a more specifically typed version of
1406  /// \c GetObjectAtPath().
1407  SDF_API
1408  SdfPropertySpecHandle GetPropertyAtPath(const SdfPath &path);
1409 
1410  /// Returns an attribute at the given \p path.
1411  ///
1412  /// Returns \c NULL if there is no attribute at \p path.
1413  /// This is simply a more specifically typed version of
1414  /// \c GetObjectAtPath().
1415  SDF_API
1416  SdfAttributeSpecHandle GetAttributeAtPath(const SdfPath &path);
1417 
1418  /// Returns a relationship at the given \p path.
1419  ///
1420  /// Returns \c NULL if there is no relationship at \p path.
1421  /// This is simply a more specifically typed version of
1422  /// \c GetObjectAtPath().
1423  SDF_API
1424  SdfRelationshipSpecHandle GetRelationshipAtPath(const SdfPath &path);
1425 
1426  /// @}
1427  /// \name Permissions
1428  /// @{
1429 
1430  /// Returns true if the caller is allowed to modify the layer and
1431  /// false otherwise. A layer may have to perform some action to acquire
1432  /// permission to be edited.
1433  SDF_API
1434  bool PermissionToEdit() const;
1435 
1436  /// Returns true if the caller is allowed to save the layer to its
1437  /// existing fileName and false otherwise.
1438  SDF_API
1439  bool PermissionToSave() const;
1440 
1441  /// Sets permission to edit.
1442  SDF_API
1443  void SetPermissionToEdit(bool allow);
1444 
1445  /// Sets permission to save.
1446  SDF_API
1447  void SetPermissionToSave(bool allow);
1448 
1449  /// @}
1450  /// \name Batch namespace editing
1451  /// @{
1452 
1453  /// Check if a batch of namespace edits will succeed. This returns
1454  /// \c SdfNamespaceEditDetail::Okay if they will succeed as a batch,
1455  /// \c SdfNamespaceEditDetail::Unbatched if the edits will succeed but
1456  /// will be applied unbatched, and \c SdfNamespaceEditDetail::Error
1457  /// if they will not succeed. No edits will be performed in any case.
1458  ///
1459  /// If \p details is not \c NULL and the method does not return \c Okay
1460  /// then details about the problems will be appended to \p details. A
1461  /// problem may cause the method to return early, so \p details may not
1462  /// list every problem.
1463  ///
1464  /// Note that Sdf does not track backpointers so it's unable to fix up
1465  /// targets/connections to namespace edited objects. Clients must fix
1466  /// those to prevent them from falling off. In addition, this method
1467  /// will report failure if any relational attribute with a target to
1468  /// a namespace edited object is subsequently edited (in the same
1469  /// batch). Clients should perform edits on relational attributes
1470  /// first.
1471  ///
1472  /// Clients may wish to report unbatch details to the user to confirm
1473  /// that the edits should be applied unbatched. This will give the
1474  /// user a chance to correct any problems that cause batching to fail
1475  /// and try again.
1476  SDF_API
1479  SdfNamespaceEditDetailVector* details = NULL) const;
1480 
1481  /// Performs a batch of namespace edits. Returns \c true on success
1482  /// and \c false on failure. On failure, no namespace edits will have
1483  /// occurred.
1484  SDF_API
1485  bool Apply(const SdfBatchNamespaceEdit&);
1486 
1487  /// @}
1488  /// \name Layer state
1489  /// @{
1490 
1491  /// Returns the state delegate used to manage this layer's authoring
1492  /// state.
1493  SDF_API
1494  SdfLayerStateDelegateBasePtr GetStateDelegate() const;
1495 
1496  /// Sets the state delegate used to manage this layer's authoring
1497  /// state. The 'dirty' state of this layer will be transferred to
1498  /// the new delegate.
1499  SDF_API
1500  void SetStateDelegate(const SdfLayerStateDelegateBaseRefPtr& delegate);
1501 
1502  /// Returns \c true if the layer is dirty, i.e. has changed from
1503  /// its persistent representation.
1504  SDF_API
1505  bool IsDirty() const;
1506 
1507  /// @}
1508 
1509  /// \name Time-sample API
1510  /// @{
1511  SDF_API
1512  std::set<double> ListAllTimeSamples() const;
1513 
1514  SDF_API
1515  std::set<double>
1516  ListTimeSamplesForPath(const SdfPath& path) const;
1517 
1518  SDF_API
1519  bool GetBracketingTimeSamples(double time, double* tLower, double* tUpper);
1520 
1521  SDF_API
1522  size_t GetNumTimeSamplesForPath(const SdfPath& path) const;
1523 
1524  SDF_API
1525  bool GetBracketingTimeSamplesForPath(const SdfPath& path,
1526  double time,
1527  double* tLower, double* tUpper);
1528 
1529  SDF_API
1530  bool QueryTimeSample(const SdfPath& path, double time,
1531  VtValue *value=NULL) const;
1532  SDF_API
1533  bool QueryTimeSample(const SdfPath& path, double time,
1534  SdfAbstractDataValue *value) const;
1535 
1536  template <class T>
1537  bool QueryTimeSample(const SdfPath& path, double time,
1538  T* data) const
1539  {
1540  if (!data) {
1541  return QueryTimeSample(path, time);
1542  }
1543 
1544  SdfAbstractDataTypedValue<T> outValue(data);
1545  const bool hasValue = QueryTimeSample(
1546  path, time, static_cast<SdfAbstractDataValue *>(&outValue));
1547 
1549  return hasValue && outValue.isValueBlock;
1550  }
1551 
1552  return hasValue && (!outValue.isValueBlock);
1553  }
1554 
1555  SDF_API
1556  void SetTimeSample(const SdfPath& path, double time,
1557  const VtValue & value);
1558  SDF_API
1559  void SetTimeSample(const SdfPath& path, double time,
1561 
1562  template <class T>
1563  void SetTimeSample(const SdfPath& path, double time,
1564  const T& value)
1565  {
1566  const SdfAbstractDataConstTypedValue<T> inValue(&value);
1567  const SdfAbstractDataConstValue& untypedInValue = inValue;
1568  return SetTimeSample(path, time, untypedInValue);
1569  }
1570 
1571  SDF_API
1572  void EraseTimeSample(const SdfPath& path, double time);
1573 
1574  /// @}
1575 
1576  // Debugging
1577  // @{
1578 
1579  SDF_API
1580  static void DumpLayerInfo();
1581 
1582  // Write this layer's SdfData to a file in a simple generic format.
1583  SDF_API
1584  bool WriteDataFile(const std::string &filename);
1585 
1586  // @}
1587 
1588 protected:
1589  // Private constructor -- use New(), FindOrCreate(), etc.
1590  // Precondition: _layerRegistryMutex must be locked.
1591  SdfLayer(const SdfFileFormatConstPtr& fileFormat,
1592  const std::string &identifier,
1593  const std::string &realPath = std::string(),
1594  const ArAssetInfo& assetInfo = ArAssetInfo(),
1596  bool validateAuthoring = false);
1597 
1598 private:
1599  // Create a new layer.
1600  // Precondition: _layerRegistryMutex must be locked.
1601  static SdfLayerRefPtr _CreateNew(
1602  SdfFileFormatConstPtr fileFormat,
1603  const std::string& identifier,
1604  const FileFormatArguments& args,
1605  bool saveLayer = true);
1606 
1607  static SdfLayerRefPtr _CreateNewWithFormat(
1608  const SdfFileFormatConstPtr &fileFormat,
1609  const std::string& identifier,
1610  const std::string& realPath,
1611  const ArAssetInfo& assetInfo = ArAssetInfo(),
1613 
1614  static SdfLayerRefPtr _CreateAnonymousWithFormat(
1615  const SdfFileFormatConstPtr &fileFormat,
1616  const std::string& tag,
1617  const FileFormatArguments& args);
1618 
1619  // Finish initializing this layer (which may have succeeded or not)
1620  // and publish the results to other threads by unlocking the mutex.
1621  // Sets _initializationWasSuccessful.
1622  void _FinishInitialization(bool success);
1623 
1624  // Layers retrieved from the layer registry may still be in the
1625  // process of having their contents initialized. Other threads
1626  // retrieving layers from the registry must wait until initialization
1627  // is complete, using this method.
1628  // Returns _initializationWasSuccessful.
1629  //
1630  // Callers *must* be holding an SdfLayerRefPtr to this layer to
1631  // ensure that it is not deleted out from under them, in
1632  // case initialization fails. (This method cannot acquire the
1633  // reference itself internally without being susceptible to a race.)
1634  bool _WaitForInitializationAndCheckIfSuccessful();
1635 
1636  // Returns whether or not this layer should post change
1637  // notification. This simply returns (!_GetIsLoading())
1638  bool _ShouldNotify() const;
1639 
1640  // This function keeps track of the last state of IsDirty() before
1641  // updating it. It returns false if the last saved dirty state is the
1642  // same than the current state. It returns true if the state differs and
1643  // will update the 'last dirty state' to the current state. So, after
1644  // returning true, it would return false for subsequent calls until the
1645  // IsDirty() state would change again...
1646  bool _UpdateLastDirtinessState() const;
1647 
1648  // Returns a handle to the spec at the given path if it exists and matches
1649  // type T.
1650  template <class T>
1651  SdfHandle<T> _GetSpecAtPath(const SdfPath& path);
1652 
1653  // Returns true if a spec can be retrieved at the given path, false
1654  // otherwise. This function will return the canonicalized path to the
1655  // spec as well as the spec type.
1656  bool _CanGetSpecAtPath(const SdfPath& path,
1657  SdfPath* canonicalPath, SdfSpecType* specType) const;
1658 
1659  /// Initialize layer internals that are based on it's path.
1660  /// This includes the asset path and show path the layer to be loaded
1661  /// reflects at the point of initialization.
1662  void _InitializeFromIdentifier(
1663  const std::string &identifier,
1664  const std::string &realPath = std::string(),
1665  const std::string &fileVersion = std::string(),
1666  const ArAssetInfo& assetInfo = ArAssetInfo());
1667 
1668  // Helper for computing the necessary information to lookup a layer
1669  // in the registry or open the layer.
1670  struct _FindOrOpenLayerInfo;
1671  static bool _ComputeInfoToFindOrOpenLayer(
1672  const std::string& identifier,
1674  _FindOrOpenLayerInfo* info,
1675  bool computeAssetInfo = false);
1676 
1677  // Open a layer, adding an entry to the registry and releasing
1678  // the registry lock.
1679  // Precondition: _layerRegistryMutex must be locked.
1680  template <class Lock>
1681  static SdfLayerRefPtr _OpenLayerAndUnlockRegistry(
1682  Lock &lock,
1683  const _FindOrOpenLayerInfo& info,
1684  bool metadataOnly);
1685 
1686  // Helper function for finding a layer with \p identifier and \p args.
1687  // \p lock must be unlocked initially and will be locked by this
1688  // function when needed. See docs for \p retryAsWriter argument on
1689  // _TryToFindLayer for details on the final state of the lock when
1690  // this function returns.
1691  template <class ScopedLock>
1692  static SdfLayerRefPtr
1693  _Find(const std::string &identifier,
1694  const FileFormatArguments &args,
1695  ScopedLock &lock, bool retryAsWriter);
1696 
1697  // Helper function to try to find the layer with \p identifier and
1698  // pre-resolved path \p resolvedPath in the registry. Caller must hold
1699  // registry \p lock for reading. If \p retryAsWriter is false, lock is
1700  // released upon return. Otherwise the lock is released upon return if a
1701  // layer is found successfully. If no layer is found then the lock is
1702  // upgraded to a writer lock upon return. Note that this upgrade may not be
1703  // atomic, but this function ensures that if upon return there does not
1704  // exist a matching layer in the registry.
1705  template <class ScopedLock>
1706  static SdfLayerRefPtr
1707  _TryToFindLayer(const std::string &identifier,
1708  const ArResolvedPath &resolvedPath,
1709  ScopedLock &lock, bool retryAsWriter);
1710 
1711  /// Returns true if the spec at the specified path has no effect on the
1712  /// scene.
1713  ///
1714  /// If ignoreChildren is true, this will ignore prim and property
1715  /// children of prim specs. Property specs are always considered to be
1716  /// non-inert unless they have only required fields and
1717  /// requiredFieldOnlyPropertiesareInert is set to false.
1718  bool _IsInert(const SdfPath &path, bool ignoreChildren,
1719  bool requiredFieldOnlyPropertiesAreInert = false) const;
1720 
1721  /// Return true if the entire subtree rooted at \a path does not affect the
1722  /// scene. For this purpose, property specs that have only required fields
1723  /// are considered inert.
1724  bool _IsInertSubtree(const SdfPath &path) const;
1725 
1726  /// Cause \p spec to be removed if it does not affect the scene. This
1727  /// removes any empty descendants before checking if \p spec itself is
1728  /// inert. Property specs are always considered non-inert, so this will
1729  /// remove them if they have only required fields (see
1730  /// PropertySpec::HasOnlyRequiredFields). This also removes inert ancestors.
1731  void _RemoveIfInert(const SdfSpec& spec);
1732 
1733  /// Performs a depth first search of the namespace hierarchy, beginning at
1734  /// \p prim, removing prims that do not affect the scene. The return value
1735  /// indicates whether the prim passed in is now inert as a result of this
1736  /// call, and can itself be removed.
1737  bool _RemoveInertDFS(SdfPrimSpecHandle prim);
1738 
1739  /// If \p prim is inert (has no affect on the scene), removes prim, then
1740  /// prunes inert parent prims back to the root.
1741  void _RemoveInertToRootmost(SdfPrimSpecHandle prim);
1742 
1743  /// Returns whether this layer is validating authoring operations.
1744  bool _ValidateAuthoring() const { return _validateAuthoring; }
1745 
1746  /// Returns the path used in the muted layers set.
1747  std::string _GetMutedPath() const;
1748 
1749  // If old and new asset path is given, rename all external prim
1750  // composition dependency referring to the old path.
1751  void _UpdatePrimCompositionDependencyPaths(
1752  const SdfPrimSpecHandle &parent,
1753  const std::string &oldLayerPath,
1754  const std::string &newLayerPath);
1755 
1756  // Set the clean state to the current state.
1757  void _MarkCurrentStateAsClean() const;
1758 
1759  // Return the field definition for \p fieldName if \p fieldName is a
1760  // required field for the spec type identified by \p path.
1761  inline SdfSchema::FieldDefinition const *
1762  _GetRequiredFieldDef(const SdfPath &path,
1763  const TfToken &fieldName,
1764  SdfSpecType specType = SdfSpecTypeUnknown) const;
1765 
1766  // Return the field definition for \p fieldName if \p fieldName is a
1767  // required field for \p specType subject to \p schema.
1768  static inline SdfSchema::FieldDefinition const *
1769  _GetRequiredFieldDef(const SdfSchemaBase &schema,
1770  const TfToken &fieldName,
1771  SdfSpecType specType);
1772 
1773  // Helper to list all fields on \p data at \p path subject to \p schema.
1774  static std::vector<TfToken>
1775  _ListFields(SdfSchemaBase const &schema,
1776  SdfAbstractData const &data, const SdfPath& path);
1777 
1778  // Helper for HasField for \p path in \p data subject to \p schema.
1779  static inline bool
1780  _HasField(const SdfSchemaBase &schema,
1781  const SdfAbstractData &data,
1782  const SdfPath& path,
1783  const TfToken& fieldName,
1784  VtValue *value);
1785 
1786  // Helper to get a field value for \p path in \p data subject to \p schema.
1787  static inline VtValue
1788  _GetField(const SdfSchemaBase &schema,
1789  const SdfAbstractData &data,
1790  const SdfPath& path,
1791  const TfToken& fieldName);
1792 
1793  // Set a value.
1794  template <class T>
1795  void _SetValue(const TfToken& key, T value);
1796 
1797  // Get a value.
1798  template <class T>
1799  T _GetValue(const TfToken& key) const;
1800 
1801  enum _ReloadResult { _ReloadFailed, _ReloadSucceeded, _ReloadSkipped };
1802  _ReloadResult _Reload(bool force);
1803 
1804  // Reads contents of asset specified by \p identifier with resolved
1805  // path \p resolvedPath into this layer.
1806  bool _Read(const std::string& identifier,
1807  const ArResolvedPath& resolvedPath,
1808  bool metadataOnly);
1809 
1810  // Saves this layer if it is dirty or the layer doesn't already exist
1811  // on disk. If \p force is true, the layer will be written out
1812  // regardless of those conditions.
1813  bool _Save(bool force) const;
1814 
1815  // A helper method used by Save and Export.
1816  // This method allows Save to specify the existing file format and Export
1817  // to use the format provided by the file extension in newFileName. If no
1818  // file format can be discovered from the file name, the existing file
1819  // format associated with the layer will be used in both cases. This allows
1820  // users to export and save to any file name, regardless of extension.
1821  bool _WriteToFile(const std::string& newFileName,
1822  const std::string& comment,
1823  SdfFileFormatConstPtr fileFormat = TfNullPtr,
1825  const;
1826 
1827  // Swap contents of _data and data. This operation does not register
1828  // inverses or emit change notification.
1829  void _SwapData(SdfAbstractDataRefPtr &data);
1830 
1831  // Set _data to \p newData and send coarse DidReplaceLayerContent
1832  // invalidation notice.
1833  void _AdoptData(const SdfAbstractDataRefPtr &newData);
1834 
1835  // Set _data to match data, calling other primitive setter methods to
1836  // provide fine-grained inverses and notification. If \p data might adhere
1837  // to a different schema than this layer's, pass a pointer to it as \p
1838  // newDataSchema. In this case, check to see if fields from \p data are
1839  // known to this layer's schema, and if not, omit them and issue a TfError
1840  // with SdfAuthoringErrorUnrecognizedFields, but continue to set all other
1841  // known fields.
1842  void _SetData(const SdfAbstractDataPtr &newData,
1843  const SdfSchemaBase *newDataSchema=nullptr);
1844 
1845  // Returns const handle to _data.
1846  SdfAbstractDataConstPtr _GetData() const;
1847 
1848  // Returns a new SdfAbstractData object for this layer.
1849  SdfAbstractDataRefPtr _CreateData() const;
1850 
1851  // Inverse primitive for setting a single field. The previous value for the
1852  // field may be given via \p oldValue. If \p oldValue is non-nullptr, the
1853  // VtValue it points to will be moved-from after the function completes. If
1854  // \p oldValue is nullptr, the old field value will be retrieved
1855  // automatically.
1856  template <class T>
1857  void _PrimSetField(const SdfPath& path,
1858  const TfToken& fieldName,
1859  const T& value,
1860  VtValue *oldValue = nullptr,
1861  bool useDelegate = true);
1862 
1863  // Inverse primitive for setting a single key in a dict-valued field. The
1864  // previous dictionary value for the field (*not* the individual entry) may
1865  // be supplied via \p oldValue. If \p oldValue is non-nullptr, the VtValue
1866  // it points to will be moved-from after the function completes. If \p
1867  // oldValue is nullptr, the old field value will be retrieved automatically.
1868  template <class T>
1869  void _PrimSetFieldDictValueByKey(const SdfPath& path,
1870  const TfToken& fieldName,
1871  const TfToken& keyPath,
1872  const T& value,
1873  VtValue *oldValue = nullptr,
1874  bool useDelegate = true);
1875 
1876  // Primitive for appending a child to the list of children.
1877  template <class T>
1878  void _PrimPushChild(const SdfPath& parentPath,
1879  const TfToken& fieldName,
1880  const T& value,
1881  bool useDelegate = true);
1882  template <class T>
1883  void _PrimPopChild(const SdfPath& parentPath,
1884  const TfToken& fieldName,
1885  bool useDelegate = true);
1886 
1887  // Move all the fields at all paths at or below \a oldPath to be
1888  // at a corresponding location at or below \a newPath. This does
1889  // not update the children fields of the parents of these paths.
1890  bool _MoveSpec(const SdfPath &oldPath, const SdfPath &newPath);
1891 
1892  // Inverse primitive for moving a spec.
1893  void _PrimMoveSpec(const SdfPath &oldPath, const SdfPath &newPath,
1894  bool useDelegate = true);
1895 
1896  // Create a new spec of type \p specType at \p path.
1897  // Returns true if spec was successfully created, false otherwise.
1898  bool _CreateSpec(const SdfPath& path, SdfSpecType specType, bool inert);
1899 
1900  // Delete all the fields at or below the specified path. This does
1901  // not update the children field of the parent of \a path.
1902  bool _DeleteSpec(const SdfPath &path);
1903 
1904  // Inverse primitive for deleting a spec.
1905  void _PrimCreateSpec(const SdfPath &path, SdfSpecType specType, bool inert,
1906  bool useDelegate = true);
1907 
1908  // Inverse primitive for deleting a spec.
1909  void _PrimDeleteSpec(const SdfPath &path, bool inert,
1910  bool useDelegate = true);
1911 
1912  // Inverse primitive for setting time samples.
1913  template <class T>
1914  void _PrimSetTimeSample(const SdfPath& path, double time,
1915  const T& value,
1916  bool useDelegate = true);
1917 
1918  // Helper method for Traverse. Visits the children of \a path using the
1919  // specified \a ChildPolicy.
1920  template <typename ChildPolicy>
1921  void _TraverseChildren(const SdfPath &path, const TraversalFunction &func);
1922 
1923 private:
1924  SdfLayerHandle _self;
1925 
1926  // File format and arguments for this layer.
1927  SdfFileFormatConstPtr _fileFormat;
1928  FileFormatArguments _fileFormatArgs;
1929 
1930  // Cached reference to the _fileFormat's schema -- we need access to this to
1931  // be as fast as possible since we look at it on every SetField(), for
1932  // example.
1933  const SdfSchemaBase &_schema;
1934 
1935  // Registry of Sdf Identities
1936  mutable Sdf_IdentityRegistry _idRegistry;
1937 
1938  // The underlying SdfData which stores all the data in the layer.
1939  SdfAbstractDataRefPtr _data;
1940 
1941  // The state delegate for this layer.
1942  SdfLayerStateDelegateBaseRefPtr _stateDelegate;
1943 
1944  // Dispatcher used in layer initialization, letting waiters participate in
1945  // loading instead of just busy-waiting.
1946  WorkDispatcher _initDispatcher;
1947 
1948  // Atomic variable protecting layer initialization -- the interval between
1949  // adding a layer to the layer registry and finishing the process of
1950  // initializing its contents, at which point we can truly publish the layer
1951  // for consumption by concurrent threads. We add the layer to the registry
1952  // before initialization completes so that other threads can discover and
1953  // wait for it to finish initializing.
1954  std::atomic<bool> _initializationComplete;
1955 
1956  // This is an optional<bool> that is only set once initialization
1957  // is complete, before _initializationComplete is set.
1958  std::optional<bool> _initializationWasSuccessful;
1959 
1960  // remembers the last 'IsDirty' state.
1961  mutable bool _lastDirtyState;
1962 
1963  // Asset information for this layer.
1964  std::unique_ptr<Sdf_AssetInfo> _assetInfo;
1965 
1966  // Modification timestamp of the backing file asset when last read.
1967  mutable VtValue _assetModificationTime;
1968 
1969  // All external asset dependencies, with their modification timestamps, of
1970  // the layer when last read.
1971  mutable VtDictionary _externalAssetModificationTimes;
1972 
1973  // Mutable revision number for cache invalidation.
1974  mutable size_t _mutedLayersRevisionCache;
1975 
1976  // Cache of whether or not this layer is muted. Only valid if
1977  // _mutedLayersRevisionCache is up-to-date with the global revision number.
1978  mutable bool _isMutedCache;
1979 
1980  // Layer permission bits.
1981  bool _permissionToEdit;
1982  bool _permissionToSave;
1983 
1984  // Whether layer edits are validated.
1985  bool _validateAuthoring;
1986 
1987  // Layer hints as of the most recent save operation.
1988  mutable SdfLayerHints _hints;
1989 
1990  // Allow access to _ValidateAuthoring() and _IsInert().
1991  friend class SdfSpec;
1992  friend class SdfPropertySpec;
1993  friend class SdfAttributeSpec;
1994 
1995  friend class Sdf_ChangeManager;
1996 
1997  // Allow access to _CreateSpec and _DeleteSpec and _MoveSpec
1998  template <class ChildPolicy> friend class Sdf_ChildrenUtils;
1999 
2000  // Give the file format access to our data. Limit breaking encapsulation
2001  // to the base SdFileFormat class so we don't have to friend every
2002  // implementation here.
2003  friend class SdfFileFormat;
2004 
2005  // Give layer state delegates access to our data as well as to
2006  // the various _Prim functions.
2008 };
2009 
2011 
2012 #endif // PXR_USD_SDF_LAYER_H
static SDF_API SdfLayerRefPtr FindOrOpen(const std::string &identifier, const FileFormatArguments &args=FileFormatArguments())
SDF_API void ClearColorConfiguration()
std::vector< SdfNamespaceEditDetail > SdfNamespaceEditDetailVector
A sequence of SdfNamespaceEditDetail.
SDF_API bool HasDefaultPrim()
SDF_API void SetFieldDictValueByKey(const SdfPath &path, const TfToken &fieldName, const TfToken &keyPath, const VtValue &value)
Definition: layer.h:97
T GetFieldAs(const SdfPath &path, const TfToken &fieldName, const T &defaultValue=T()) const
Definition: layer.h:685
SDF_API SdfAssetPath GetColorConfiguration() const
SDF_API void EraseTimeSample(const SdfPath &path, double time)
const std::vector< std::string > & GetExcluded() const
Definition: layer.h:1285
DetachedLayerRules & IncludeAll()
Include all layers in the detached layer set.
Definition: layer.h:1266
Result
Validity of an edit.
GT_API const UT_StringHolder filename
SDF_API void SetSubLayerPaths(const std::vector< std::string > &newPaths)
Sets the paths of the layer's sublayers.
SDF_API bool WriteDataFile(const std::string &filename)
SDF_API void RemoveInertSceneDescription()
SDF_API bool InsertRootPrim(const SdfPrimSpecHandle &prim, int index=-1)
SDF_API bool HasEndTimeCode() const
Returns true if the layer has an endTimeCode opinion.
SDF_API void SetComment(const std::string &comment)
Sets the comment string for this layer.
SDF_API VtDictionary GetCustomLayerData() const
SDF_API void SetFramePrecision(int framePrecision)
Sets the layer's frame precision.
SDF_API std::string ComputeAbsolutePath(const std::string &assetPath) const
SDF_API std::set< std::string > GetExternalReferences() const
SDF_API void EraseFieldDictValueByKey(const SdfPath &path, const TfToken &fieldName, const TfToken &keyPath)
bool HasFieldDictKey(const SdfPath &path, const TfToken &name, const TfToken &keyPath, T *value) const
Definition: layer.h:662
SDF_API void RemovePropertyIfHasOnlyRequiredFields(SdfPropertySpecHandle prop)
SDF_API void SetDocumentation(const std::string &documentation)
Sets the documentation string for this layer.
SDF_API void ClearFramesPerSecond()
Clear the framesPerSecond opinion.
PXR_NAMESPACE_OPEN_SCOPE TF_DECLARE_WEAK_PTRS(SdfFileFormat)
static SDF_API SdfLayerRefPtr New(const SdfFileFormatConstPtr &fileFormat, const std::string &identifier, const FileFormatArguments &args=FileFormatArguments())
static SDF_API bool ReloadLayers(const std::set< SdfLayerHandle > &layers, bool force=false)
SDF_API bool IsMuted() const
Returns true if the current layer is muted.
SDF_API void SetStartTimeCode(double startTimecode)
Sets the layer's start timeCode.
SDF_API bool ExportToString(std::string *result) const
GT_API const UT_StringHolder time
SDF_API const VtValue & GetAssetInfo() const
static SDF_API bool SplitIdentifier(const std::string &identifier, std::string *layerPath, FileFormatArguments *arguments)
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
GLsizei const GLfloat * value
Definition: glcorearb.h:824
SDF_API bool HasStartTimeCode() const
Returns true if the layer has a startTimeCode opinion.
static SDF_API SdfLayerRefPtr FindOrOpenRelativeToLayer(const SdfLayerHandle &anchor, const std::string &identifier, const FileFormatArguments &args=FileFormatArguments())
SDF_API const std::string & GetAssetName() const
Returns the asset name associated with this layer.
SDF_API void SetDefaultPrim(const TfToken &name)
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
std::map< std::string, std::string > FileFormatArguments
Definition: layer.h:123
SDF_API bool QueryTimeSample(const SdfPath &path, double time, VtValue *value=NULL) const
SDF_API void ClearSessionOwner()
SDF_API SdfNameOrderProxy GetRootPrimOrder() const
std::type_info const & GetFieldTypeid(const SdfPath &path, const TfToken &name) const
Definition: layer.h:638
SDF_API bool HasSpec(const SdfPath &path) const
Return whether a spec exists at path.
SDF_API SdfAttributeSpecHandle GetAttributeAtPath(const SdfPath &path)
SDF_API void RemoveFromRootPrimOrderByIndex(int index)
Removes a root prim name from the root prim order by index.
SDF_API SdfRelationshipSpecHandle GetRelationshipAtPath(const SdfPath &path)
SDF_API void SetPermissionToEdit(bool allow)
Sets permission to edit.
SDF_API void Traverse(const SdfPath &path, const TraversalFunction &func)
TF_API const TfNullPtrType TfNullPtr
TF_DECLARE_WEAK_AND_REF_PTRS(SdfLayerStateDelegateBase)
Definition: spec.h:49
SDF_API bool HasSessionOwner() const
Returns true if the layer has a session owner opinion.
friend class Sdf_ChangeManager
Definition: layer.h:1995
SDF_API SdfPrimSpecHandle GetPseudoRoot() const
SDF_API bool PermissionToEdit() const
std::set< SdfHandleTo< SdfLayer >::Handle > SdfLayerHandleSet
static SDF_API SdfLayerRefPtr CreateAnonymous(const std::string &tag=std::string(), const FileFormatArguments &args=FileFormatArguments())
SDF_API void SetSubLayerOffset(const SdfLayerOffset &offset, int index)
Sets the layer offset for the subLayer path at the given index.
SDF_API void ScheduleRemoveIfInert(const SdfSpec &spec)
**But if you need a result
Definition: thread.h:613
std::function< void(const SdfPath &)> TraversalFunction
Definition: layer.h:771
static SDF_API std::string CreateIdentifier(const std::string &layerPath, const FileFormatArguments &arguments)
Joins the given layer path and arguments into an identifier.
SDF_API std::string GetDocumentation() const
SDF_API void SetPermissionToSave(bool allow)
Sets permission to save.
SDF_API bool Apply(const SdfBatchNamespaceEdit &)
SDF_API bool Import(const std::string &layerPath)
SDF_API const std::string & GetRepositoryPath() const
SDF_API SdfPrimSpecHandle GetPrimAtPath(const SdfPath &path)
SDF_API void SetTimeCodesPerSecond(double timeCodesPerSecond)
Sets the layer's timeCodes per second.
static SDF_API std::set< std::string > GetMutedLayers()
Returns the set of muted layer paths.
SDF_API std::set< double > ListTimeSamplesForPath(const SdfPath &path) const
SDF_API SdfLayerOffset GetSubLayerOffset(int index) const
Returns the layer offset for the subLayer path at the given index.
SDF_API double GetTimeCodesPerSecond() const
SDF_API void SetColorConfiguration(const SdfAssetPath &colorConfiguration)
Sets the color configuration asset-path for this layer.
SDF_API std::string GetSessionOwner() const
static SDF_API bool IsIncludedByDetachedLayerRules(const std::string &identifier)
SDF_API SdfSpecType GetSpecType(const SdfPath &path) const
SDF_API void SetEndTimeCode(double endTimeCode)
Sets the layer's end timeCode.
SDF_API bool Reload(bool force=false)
SDF_API double GetStartTimeCode() const
GLenum GLuint GLint GLint layer
Definition: glcorearb.h:1299
SDF_API size_t GetNumSubLayerPaths() const
Returns the number of sublayer paths (and offsets).
SDF_API SdfLayerOffsetVector GetSubLayerOffsets() const
Returns the layer offsets for all the subLayer paths.
SDF_API const SdfFileFormatConstPtr & GetFileFormat() const
Returns the file format used by this layer.
SDF_API void ClearOwner()
Clear the owner opinion.
SDF_API const FileFormatArguments & GetFileFormatArguments() const
SDF_API SdfDataRefPtr GetMetadata() const
Returns the data from the absolute root path of this layer.
SDF_API void RemoveRootPrim(const SdfPrimSpecHandle &prim)
Remove a root prim.
static SDF_API SdfLayerRefPtr OpenAsAnonymous(const std::string &layerPath, bool metadataOnly=false, const std::string &tag=std::string())
SDF_API void ClearFramePrecision()
Clear the framePrecision opinion.
SDF_API void SetStateDelegate(const SdfLayerStateDelegateBaseRefPtr &delegate)
SDF_API void SetColorManagementSystem(const TfToken &cms)
std::vector< SdfLayerOffset > SdfLayerOffsetVector
Definition: layerOffset.h:174
Definition: token.h:87
SDF_API bool HasField(const SdfPath &path, const TfToken &fieldName, VtValue *value=NULL) const
SDF_API void SetSessionOwner(const std::string &owner)
GLintptr offset
Definition: glcorearb.h:665
SDF_API void SetRootPrims(const SdfPrimSpecHandleVector &rootPrims)
SDF_API void SetCustomLayerData(const VtDictionary &value)
Sets the CustomLayerData dictionary associated with this layer.
SDF_API void EraseField(const SdfPath &path, const TfToken &fieldName)
Remove the field at path and fieldName, if one exists.
SDF_API std::set< std::string > GetCompositionAssetDependencies() const
SDF_API void ClearEndTimeCode()
Clear the endTimeCode opinion.
SDF_API bool HasCustomLayerData() const
Returns true if CustomLayerData is authored on the layer.
SDF_API bool UpdateExternalReference(const std::string &oldAssetPath, const std::string &newAssetPath=std::string())
SDF_API double GetFramesPerSecond() const
SDF_API void ClearDefaultPrim()
SDF_API void Clear()
static SDF_API std::string GetDisplayNameFromIdentifier(const std::string &identifier)
SDF_API VtValue GetFieldDictValueByKey(const SdfPath &path, const TfToken &fieldName, const TfToken &keyPath) const
SDF_API bool ImportFromString(const std::string &string)
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
SDF_API std::set< std::string > GetExternalAssetDependencies() const
const std::vector< std::string > & GetIncluded() const
Definition: layer.h:1284
GLint GLuint mask
Definition: glcorearb.h:124
SDF_API bool HasFramesPerSecond() const
Returns true if the layer has a frames per second opinion.
SdfPrimSpecView RootPrimsView
Returns a vector of the layer's root prims.
Definition: layer.h:1070
SDF_API void SetRootPrimOrder(const std::vector< TfToken > &names)
SDF_API bool Export(const std::string &filename, const std::string &comment=std::string(), const FileFormatArguments &args=FileFormatArguments()) const
SDF_API double GetEndTimeCode() const
SDF_API SdfLayerStateDelegateBasePtr GetStateDelegate() const
SDF_API DetachedLayerRules & Include(const std::vector< std::string > &patterns)
SDF_API void SetHasOwnedSubLayers(bool)
Sets whether the layer's sublayers are expected to have owners.
SDF_API const std::string & GetRealPath() const
SDF_API void ClearTimeCodesPerSecond()
Clear the timeCodesPerSecond opinion.
SDF_API void RemoveFromRootPrimOrder(const TfToken &name)
Removes a root prim name from the root prim order.
SDF_API TfToken GetColorManagementSystem() const
SDF_API bool HasTimeCodesPerSecond() const
Returns true if the layer has a timeCodesPerSecond opinion.
GLuint const GLchar * name
Definition: glcorearb.h:786
SDF_API void ClearExpressionVariables()
Clears the expression variables dictionary authored on this layer.
void SetFieldDictValueByKey(const SdfPath &path, const TfToken &fieldName, const TfToken &keyPath, const T &val)
Definition: layer.h:738
Definition: path.h:290
SdfLayer & operator=(const SdfLayer &)=delete
bool IncludedAll() const
Definition: layer.h:1283
SDF_API bool StreamsData() const
SDF_API DetachedLayerRules & Exclude(const std::vector< std::string > &patterns)
SDF_API bool HasFieldDictKey(const SdfPath &path, const TfToken &fieldName, const TfToken &keyPath, VtValue *value=NULL) const
SDF_API bool HasExpressionVariables() const
Returns true if expression variables are authored on this layer.
SDF_API bool GetBracketingTimeSamples(double time, double *tLower, double *tUpper)
SDF_API void SetFramesPerSecond(double framesPerSecond)
Sets the layer's frames per second.
SDF_API std::string GetDisplayName() const
SDF_API void UpdateAssetInfo()
SDF_API bool IsIncluded(const std::string &identifier) const
SDF_API bool UpdateCompositionAssetDependency(const std::string &oldAssetPath, const std::string &newAssetPath=std::string())
SDF_API const ArResolvedPath & GetResolvedPath() const
SdfLayer(const SdfLayer &)=delete
Noncopyable.
SDF_API SdfNamespaceEditDetail::Result CanApply(const SdfBatchNamespaceEdit &, SdfNamespaceEditDetailVector *details=NULL) const
static SDF_API void SetDetachedLayerRules(const DetachedLayerRules &mask)
SDF_API void InsertSubLayerPath(const std::string &path, int index=-1)
static SDF_API SdfLayerHandle FindRelativeToLayer(const SdfLayerHandle &anchor, const std::string &identifier, const FileFormatArguments &args=FileFormatArguments())
SDF_API SdfSpecHandle GetObjectAtPath(const SdfPath &path)
#define SDF_API
Definition: api.h:40
SDF_API void SetIdentifier(const std::string &identifier)
SDF_API void SetExpressionVariables(const VtDictionary &expressionVars)
Sets the expression variables dictionary for this layer.
SDF_API bool IsAnonymous() const
Returns true if this layer is an anonymous layer.
bool HasField(const SdfPath &path, const TfToken &name, T *value) const
Definition: layer.h:618
GLenum func
Definition: glcorearb.h:783
SDF_API std::string GetFileExtension() const
SDF_API void InsertInRootPrimOrder(const TfToken &name, int index=-1)
SDF_API void RemoveSubLayerPath(int index)
Removes sublayer path at the given index.
SDF_API void SetField(const SdfPath &path, const TfToken &fieldName, const VtValue &value)
Set the value of the given path and fieldName.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
SDF_API bool GetBracketingTimeSamplesForPath(const SdfPath &path, double time, double *tLower, double *tUpper)
SDF_API void TransferContent(const SdfLayerHandle &layer)
SIM_API const UT_StringHolder force
void SetField(const SdfPath &path, const TfToken &fieldName, const T &val)
Set the value of the given path and fieldName.
Definition: layer.h:709
bool QueryTimeSample(const SdfPath &path, double time, T *data) const
Definition: layer.h:1537
SDF_API bool HasColorManagementSystem() const
SDF_API VtDictionary GetExpressionVariables() const
SdfSpecType
Definition: types.h:85
SDF_API std::string GetOwner() const
Returns the layer's owner.
SDF_API void SetMuted(bool muted)
SDF_API void ClearCustomLayerData()
Clears out the CustomLayerData dictionary associated with this layer.
SDF_API bool PermissionToSave() const
virtual SDF_API ~SdfLayer()
Destructor.
SDF_API bool HasColorConfiguration() const
GLuint index
Definition: glcorearb.h:786
SDF_API bool HasOwner() const
Returns true if the layer has an owner opinion.
SDF_API void SetTimeSample(const SdfPath &path, double time, const VtValue &value)
GLuint GLfloat * val
Definition: glcorearb.h:1608
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
SDF_API bool IsDetached() const
SDF_API bool HasFramePrecision() const
Returns true if the layer has a frames precision opinion.
**If you just want to fire and args
Definition: thread.h:609
SDF_API int GetFramePrecision() const
Returns the layer's frame precision.
SDF_API void SetOwner(const std::string &owner)
Sets the layer's owner.
SDF_API const std::string & GetIdentifier() const
Returns the layer identifier.
SDF_API bool GetHasOwnedSubLayers() const
Returns true if the layer's sublayers are expected to have owners.
static SDF_API void RemoveFromMutedLayers(const std::string &mutedPath)
Remove the specified path from the muted layers set.
SDF_API RootPrimsView GetRootPrims() const
Returns a vector of the layer's root prims.
static SDF_API void AddToMutedLayers(const std::string &mutedPath)
Add the specified path to the muted layers set.
Definition: core.h:1131
SDF_API TfToken GetDefaultPrim() const
SDF_API std::vector< TfToken > ListFields(const SdfPath &path) const
Return the names of all the fields that are set at path.
SDF_API SdfPropertySpecHandle GetPropertyAtPath(const SdfPath &path)
static SDF_API void DumpLayerInfo()
SDF_API size_t GetNumTimeSamplesForPath(const SdfPath &path) const
SDF_API const std::string & GetVersion() const
SDF_API SdfSubLayerProxy GetSubLayerPaths() const
SDF_API void RemovePrimIfInert(SdfPrimSpecHandle prim)
static SDF_API const DetachedLayerRules & GetDetachedLayerRules()
Returns the current rules for the detached layer set.
static SDF_API SdfLayerRefPtr CreateNew(const std::string &identifier, const FileFormatArguments &args=FileFormatArguments())
SDF_API SdfLayerHints GetHints() const
static SDF_API SdfLayerHandleSet GetLoadedLayers()
Returns handles for all layers currently held by the layer registry.
SDF_API const SdfSchemaBase & GetSchema() const
SDF_API bool IsDirty() const
SDF_API void ApplyRootPrimOrder(std::vector< TfToken > *vec) const
SDF_API void ClearStartTimeCode()
Clear the startTimeCode opinion.
SDF_API void ClearColorManagementSystem()
Definition: value.h:164
SDF_API std::string GetComment() const
SDF_API bool Save(bool force=false) const
SDF_API VtValue GetField(const SdfPath &path, const TfToken &fieldName) const
static SDF_API bool IsAnonymousLayerIdentifier(const std::string &identifier)
Definition: format.h:895
SDF_API std::set< double > ListAllTimeSamples() const
SDF_API bool IsEmpty() const
Returns whether this layer has no significant data.
static SDF_API SdfLayerHandle Find(const std::string &identifier, const FileFormatArguments &args=FileFormatArguments())
void SetTimeSample(const SdfPath &path, double time, const T &value)
Definition: layer.h:1563