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