forked from PixarAnimationStudios/OpenUSD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
layer.h
1823 lines (1542 loc) · 68.9 KB
/
layer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_SDF_LAYER_H
#define PXR_USD_SDF_LAYER_H
/// \file sdf/layer.h
#include "pxr/pxr.h"
#include "pxr/usd/sdf/api.h"
#include "pxr/usd/sdf/data.h"
#include "pxr/usd/sdf/declareHandles.h"
#include "pxr/usd/sdf/identity.h"
#include "pxr/usd/sdf/layerHints.h"
#include "pxr/usd/sdf/layerOffset.h"
#include "pxr/usd/sdf/namespaceEdit.h"
#include "pxr/usd/sdf/path.h"
#include "pxr/usd/sdf/proxyTypes.h"
#include "pxr/usd/sdf/spec.h"
#include "pxr/usd/sdf/types.h"
#include "pxr/usd/ar/ar.h"
#include "pxr/usd/ar/assetInfo.h"
#include "pxr/usd/ar/resolvedPath.h"
#include "pxr/base/tf/declarePtrs.h"
#include "pxr/base/vt/value.h"
#include <boost/optional.hpp>
#include <atomic>
#include <functional>
#include <memory>
#include <set>
#include <string>
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
TF_DECLARE_WEAK_PTRS(SdfFileFormat);
TF_DECLARE_WEAK_AND_REF_PTRS(SdfLayerStateDelegateBase);
struct Sdf_AssetInfo;
/// \class SdfLayer
///
/// A unit of scene description that you combine with other units of scene
/// description to form a shot, model, set, shader, and so on.
///
/// SdfLayer objects provide a persistent way to store layers on the
/// filesystem in .menva files. Currently the supported file format is
/// <c>.menva</c>, the ASCII file format.
///
/// The FindOrOpen() method returns a new SdfLayer object with scene description
/// from a <c>.menva</c> file. Once read, a layer remembers which asset it was
/// read from. The Save() method saves the layer back out to the original file.
/// You can use the Export() method to write the layer to a different
/// location. You can use the GetIdentifier() method to get the layer's Id or
/// GetRealPath() to get the resolved, full file path.
///
/// Layers can have a timeCode range (startTimeCode and endTimeCode). This range
/// represents the suggested playback range, but has no impact on the extent of
/// the animation data that may be stored in the layer. The metadatum
/// "timeCodesPerSecond" is used to annotate how the time ordinate for samples
/// contained in the file scales to seconds. For example, if timeCodesPerSecond
/// is 24, then a sample at time ordinate 24 should be viewed exactly one second
/// after the sample at time ordinate 0.
///
/// Compared to Menv2x, layers are most closely analogous to
/// hooksets, <c>.hook</c> files, and <c>.cue</c> files.
///
/// \todo
/// \li Insert a discussion of subLayers semantics here.
///
/// \todo
/// \li Should have validate... methods for rootPrims
///
class SdfLayer
: public TfRefBase
, public TfWeakBase
{
public:
/// Destructor
SDF_API
virtual ~SdfLayer();
/// Noncopyable
SdfLayer(const SdfLayer&) = delete;
SdfLayer& operator=(const SdfLayer&) = delete;
///
/// \name Primary API
/// @{
/// Returns the schema this layer adheres to. This schema provides details
/// about the scene description that may be authored in this layer.
SDF_API const SdfSchemaBase& GetSchema() const;
/// Returns the file format used by this layer.
SDF_API const SdfFileFormatConstPtr& GetFileFormat() const;
/// Type for specifying additional file format-specific arguments to
/// layer API.
typedef std::map<std::string, std::string> FileFormatArguments;
/// Returns the file format-specific arguments used during the construction
/// of this layer.
SDF_API const FileFormatArguments& GetFileFormatArguments() const;
/// Creates a new empty layer with the given identifier.
///
/// Additional arguments may be supplied via the \p args parameter.
/// These arguments may control behavior specific to the layer's
/// file format.
SDF_API
static SdfLayerRefPtr CreateNew(const std::string &identifier,
const FileFormatArguments &args =
FileFormatArguments());
/// Creates a new empty layer with the given identifier for a given file
/// format class.
///
/// This function has the same behavior as the other CreateNew function,
/// but uses the explicitly-specified \p fileFormat instead of attempting
/// to discern the format from \p identifier.
SDF_API
static SdfLayerRefPtr CreateNew(const SdfFileFormatConstPtr& fileFormat,
const std::string &identifier,
const FileFormatArguments &args =
FileFormatArguments());
/// Creates a new empty layer with the given identifier for a given file
/// format class.
///
/// The new layer will not be dirty and will not be saved.
///
/// Additional arguments may be supplied via the \p args parameter.
/// These arguments may control behavior specific to the layer's
/// file format.
SDF_API
static SdfLayerRefPtr New(const SdfFileFormatConstPtr& fileFormat,
const std::string &identifier,
const FileFormatArguments &args =
FileFormatArguments());
/// Return an existing layer with the given \p identifier and \p args. If
/// the layer can't be found, an error is posted and a null layer is
/// returned.
///
/// Arguments in \p args will override any arguments specified in
/// \p identifier.
SDF_API
static SdfLayerHandle Find(
const std::string &identifier,
const FileFormatArguments &args = FileFormatArguments());
/// Return an existing layer with the given \p identifier and \p args.
/// The given \p identifier will be resolved relative to the \p anchor
/// layer. If the layer can't be found, an error is posted and a null
/// layer is returned.
///
/// If the \p anchor layer is invalid, a coding error is raised, and a null
/// handle is returned.
///
/// Arguments in \p args will override any arguments specified in
/// \p identifier.
SDF_API
static SdfLayerHandle FindRelativeToLayer(
const SdfLayerHandle &anchor,
const std::string &identifier,
const FileFormatArguments &args = FileFormatArguments());
/// Return an existing layer with the given \p identifier and \p args, or
/// else load it. If the layer can't be found or loaded, an error is posted
/// and a null layer is returned.
///
/// Arguments in \p args will override any arguments specified in
/// \p identifier.
SDF_API
static SdfLayerRefPtr FindOrOpen(
const std::string &identifier,
const FileFormatArguments &args = FileFormatArguments());
/// Return an existing layer with the given \p identifier and \p args, or
/// else load it. The given \p identifier will be resolved relative to the
/// \p anchor layer. If the layer can't be found or loaded, an error is
/// posted and a null layer is returned.
///
/// If the \p anchor layer is invalid, issues a coding error and returns
/// a null handle.
///
/// Arguments in \p args will override any arguments specified in
/// \p identifier.
SDF_API
static SdfLayerRefPtr FindOrOpenRelativeToLayer(
const SdfLayerHandle &anchor,
const std::string &identifier,
const FileFormatArguments &args = FileFormatArguments());
/// Load the given layer from disk as a new anonymous layer. If the
/// layer can't be found or loaded, an error is posted and a null
/// layer is returned.
///
/// The anonymous layer does not retain any knowledge of the backing
/// file on the filesystem.
///
/// \p metadataOnly is a flag that asks for only the layer metadata
/// to be read in, which can be much faster if that is all that is
/// required. Note that this is just a hint: some FileFormat readers
/// may disregard this flag and still fully populate the layer contents.
///
/// An optional \p tag may be specified. See CreateAnonymous for details.
SDF_API
static SdfLayerRefPtr OpenAsAnonymous(
const std::string &layerPath,
bool metadataOnly = false,
const std::string& tag = std::string());
/// Returns the data from the absolute root path of this layer.
SDF_API
SdfDataRefPtr GetMetadata() const;
/// Return hints about the layer's current contents. Any operation that
/// dirties the layer will invalidate all hints.
/// \sa SdfLayerHints
SDF_API
SdfLayerHints GetHints() const;
/// Returns handles for all layers currently held by the layer registry.
SDF_API
static SdfLayerHandleSet GetLoadedLayers();
/// Returns whether this layer has no significant data.
SDF_API
bool IsEmpty() const;
/// Copies the content of the given layer into this layer.
/// Source layer is unmodified.
SDF_API
void TransferContent(const SdfLayerHandle& layer);
/// Creates a new \e anonymous layer with an optional \p tag. An anonymous
/// layer is a layer with a system assigned identifier, that cannot be
/// saved to disk via Save(). Anonymous layers have an identifier, but no
/// real path or other asset information fields.
///
/// Anonymous layers may be tagged, which can be done to aid debugging
/// subsystems that make use of anonymous layers. The tag becomes the
/// display name of an anonymous layer, and is also included in the
/// generated identifier. Untagged anonymous layers have an empty display
/// name.
///
/// Additional arguments may be supplied via the \p args parameter.
/// These arguments may control behavior specific to the layer's
/// file format.
SDF_API
static SdfLayerRefPtr CreateAnonymous(
const std::string& tag = std::string(),
const FileFormatArguments& args = FileFormatArguments());
/// Create an anonymous layer with a specific \p format.
SDF_API
static SdfLayerRefPtr CreateAnonymous(
const std::string &tag, const SdfFileFormatConstPtr &format,
const FileFormatArguments& args = FileFormatArguments());
/// Returns true if this layer is an anonymous layer.
SDF_API
bool IsAnonymous() const;
/// Returns true if the \p identifier is an anonymous layer unique
/// identifier.
SDF_API
static bool IsAnonymousLayerIdentifier(const std::string& identifier);
/// Returns the display name for the given \p identifier, using the same
/// rules as GetDisplayName.
SDF_API
static std::string GetDisplayNameFromIdentifier(
const std::string& identifier);
/// @}
/// \name File I/O
/// @{
/// Returns \c true if successful, \c false if an error occurred.
/// Returns \c false if the layer has no remembered file name or the
/// layer type cannot be saved. The layer will not be overwritten if the
/// file exists and the layer is not dirty unless \p force is true.
SDF_API
bool Save(bool force = false) const;
/// Exports this layer to a file.
/// Returns \c true if successful, \c false if an error occurred.
///
/// If \p comment is not empty, the layer gets exported with the given
/// comment. Additional arguments may be supplied via the \p args parameter.
/// These arguments may control behavior specific to the exported layer's
/// file format.
///
/// Note that the file name or comment of the original layer is not
/// updated. This only saves a copy of the layer to the given filename.
/// Subsequent calls to Save() will still save the layer to it's
/// previously remembered file name.
SDF_API
bool Export(const std::string& filename,
const std::string& comment = std::string(),
const FileFormatArguments& args = FileFormatArguments()) const;
/// Writes this layer to the given string.
///
/// Returns \c true if successful and sets \p result, otherwise
/// returns \c false.
SDF_API
bool ExportToString(std::string* result) const;
/// Reads this layer from the given string.
///
/// Returns \c true if successful, otherwise returns \c false.
SDF_API
bool ImportFromString(const std::string &string);
/// Clears the layer of all content.
///
/// This restores the layer to a state as if it had just been created
/// with CreateNew(). This operation is Undo-able.
///
/// The fileName and whether journaling is enabled are not affected
/// by this method.
SDF_API
void Clear();
/// Reloads the layer from its persistent representation.
///
/// This restores the layer to a state as if it had just been created
/// with FindOrOpen(). This operation is Undo-able.
///
/// The fileName and whether journaling is enabled are not affected
/// by this method.
///
/// When called with force = false (the default), Reload attempts to
/// avoid reloading layers that have not changed on disk. It does so
/// by comparing the file's modification time (mtime) to when the
/// file was loaded. If the layer has unsaved modifications, this
/// mechanism is not used, and the layer is reloaded from disk. If the
/// layer has any
/// \ref GetExternalAssetDependencies "external asset dependencies"
/// their modification state will also be consulted when determining if
/// the layer needs to be reloaded.
///
/// Passing true to the \p force parameter overrides this behavior,
/// forcing the layer to be reloaded from disk regardless of whether
/// it has changed.
SDF_API
bool Reload(bool force = false);
/// Reloads the specified layers.
///
/// Returns \c false if one or more layers failed to reload.
///
/// See \c Reload() for a description of the \p force flag.
///
SDF_API
static bool ReloadLayers(const std::set<SdfLayerHandle>& layers,
bool force = false);
/// Imports the content of the given layer path, replacing the content
/// of the current layer.
/// Note: If the layer path is the same as the current layer's real path,
/// no action is taken (and a warning occurs). For this case use
/// Reload().
SDF_API
bool Import(const std::string &layerPath);
/// @}
/// \name External references
/// @{
/// Return paths of all external references of layer.
SDF_API
std::set<std::string> GetExternalReferences() const;
/// Updates the external references of the layer.
///
/// If only the old asset path is given, this update works as delete,
/// removing any sublayers or prims referencing the pathtype using the
/// old asset path as reference.
///
/// If new asset path is supplied, the update works as "rename", updating
/// any occurrence of the old reference to the new reference.
SDF_API
bool UpdateExternalReference(
const std::string &oldAssetPath,
const std::string &newAssetPath=std::string());
/// Returns a set of resolved paths to all external asset dependencies
/// the layer needs to generate its contents. These are additional asset
/// dependencies that are determined by the layer's
/// \ref SdfFileFormat::GetExternalAssetDependencies "file format" and
/// will be consulted during Reload() when determining if the layer needs
/// to be reloaded. This specifically does not include dependencies related
/// to composition, i.e. this will not include assets from references,
/// payloads, and sublayers.
SDF_API
std::set<std::string> GetExternalAssetDependencies() const;
/// @}
/// \name Identification
///
/// A layer's identifier is a string that uniquely identifies a layer.
/// At minimum, it is the string by which the layer was created, either
/// via FindOrOpen or CreateNew. If additional arguments were passed
/// to those functions, those arguments will be encoded in the identifier.
///
/// For example:
/// FindOrOpen('foo.sdf', args={'a':'b', 'c':'d'}).identifier
/// => "foo.sdf?sdf_args:a=b&c=d"
///
/// Note that this means the identifier may in general not be a path.
///
/// The identifier format is subject to change; consumers should NOT
/// parse layer identifiers themselves, but should use the supplied
/// SplitIdentifier and CreateIdentifier helper functions.
///
/// @{
/// Splits the given layer identifier into its constituent layer path
/// and arguments.
SDF_API
static bool SplitIdentifier(
const std::string& identifier,
std::string* layerPath,
FileFormatArguments* arguments);
/// Joins the given layer path and arguments into an identifier.
SDF_API
static std::string CreateIdentifier(
const std::string& layerPath,
const FileFormatArguments& arguments);
/// Returns the layer identifier.
SDF_API
const std::string& GetIdentifier() const;
/// Sets the layer identifier.
/// Note that the new identifier must have the same arguments (if any)
/// as the old identifier.
SDF_API
void SetIdentifier(const std::string& identifier);
/// Update layer asset information. Calling this method re-resolves the
/// layer identifier, which updates asset information such as the layer's
/// resolved path and other asset info. This may be used to update the
/// layer after external changes to the underlying asset system.
#if AR_VERSION == 1
SDF_API
void UpdateAssetInfo(const std::string& fileVersion = std::string());
#else
SDF_API
void UpdateAssetInfo();
#endif
/// Returns the layer's display name.
///
/// The display name is the base filename of the identifier.
SDF_API
std::string GetDisplayName() const;
/// Returns the resolved path for this layer. This is the path where
/// this layer exists or may exist after a call to Save().
SDF_API
const ArResolvedPath& GetResolvedPath() const;
/// Returns the resolved path for this layer. This is equivalent to
/// GetResolvedPath().GetPathString().
SDF_API
const std::string& GetRealPath() const;
/// Returns the file extension to use for this layer.
/// If this layer was loaded from disk, it should match the extension
/// of the file format it was loaded as; if this is an anonymous
/// in-memory layer it will be the default extension.
SDF_API
std::string GetFileExtension() const;
/// Returns the asset system version of this layer. If a layer is loaded
/// from a location that is not version managed, or a configured asset
/// system is not present when the layer is loaded or created, the version
/// is empty. By default, asset version tracking is disabled; this method
/// returns empty unless asset version tracking is enabled.
SDF_API
const std::string& GetVersion() const;
/// Returns the layer identifier in asset path form. In the presence of a
/// properly configured path resolver, the asset path is a double-slash
/// prefixed depot path. If the path resolver is not configured, the asset
/// path of a layer is empty.
SDF_API
const std::string& GetRepositoryPath() const;
/// Returns the asset name associated with this layer.
SDF_API
const std::string& GetAssetName() const;
/// Returns resolve information from the last time the layer identifier
/// was resolved.
SDF_API
const VtValue& GetAssetInfo() const;
/// Returns the path to the asset specified by \p assetPath using this layer
/// to anchor the path if necessary. Returns \p assetPath if it's empty or
/// an anonymous layer identifier.
///
/// This method can be used on asset paths that are authored in this layer
/// to create new asset paths that can be copied to other layers. These new
/// asset paths should refer to the same assets as the original asset
/// paths. For example, if the underlying ArResolver is filesystem-based and
/// \p assetPath is a relative filesystem path, this method might return the
/// absolute filesystem path using this layer's location as the anchor.
///
/// The returned path should in general not be assumed to be an absolute
/// filesystem path or any other specific form. It is "absolute" in that it
/// should resolve to the same asset regardless of what layer it's authored
/// in.
SDF_API
std::string ComputeAbsolutePath(const std::string& assetPath) const;
/// @}
/// \name Fields
///
/// All scene description for a given object is stored as a set of
/// key/value pairs called fields. These methods provide direct access to
/// those fields, though most clients should use the Spec API to ensure
/// data consistency.
///
/// These methods all take SdfPath to identify the queried spec.
///
/// @{
/// Return the spec type for \a path. This returns SdfSpecTypeUnknown if no
/// spec exists at \a path.
SDF_API
SdfSpecType GetSpecType(const SdfPath& path) const;
/// Return whether a spec exists at \a path.
SDF_API
bool HasSpec(const SdfPath& path) const;
/// Return the names of all the fields that are set at \p path.
SDF_API
std::vector<TfToken> ListFields(const SdfPath& path) const;
/// Return whether a value exists for the given \a path and \a fieldName.
/// Optionally returns the value if it exists.
SDF_API
bool HasField(const SdfPath& path, const TfToken& fieldName,
VtValue *value=NULL) const;
SDF_API
bool HasField(const SdfPath& path, const TfToken& fieldName,
SdfAbstractDataValue *value) const;
/// Returns \c true if the object has a non-empty value with name
/// \p name and type \p T. If value ptr is provided, returns the
/// value found.
template <class T>
bool HasField(const SdfPath& path, const TfToken &name,
T* value) const
{
if (!value) {
return HasField(path, name, static_cast<VtValue *>(NULL));
}
SdfAbstractDataTypedValue<T> outValue(value);
const bool hasValue = HasField(
path, name, static_cast<SdfAbstractDataValue *>(&outValue));
if (std::is_same<T, SdfValueBlock>::value) {
return hasValue && outValue.isValueBlock;
}
return hasValue && (!outValue.isValueBlock);
}
/// Return the type of the value for \p name on spec \p path. If no such
/// field exists, return typeid(void).
std::type_info const &GetFieldTypeid(
const SdfPath &path, const TfToken &name) const {
return _data->GetTypeid(path, name);
}
/// Return whether a value exists for the given \a path and \a fieldName and
/// \a keyPath. The \p keyPath is a ':'-separated path addressing an
/// element in sub-dictionaries. Optionally returns the value if it exists.
SDF_API
bool HasFieldDictKey(const SdfPath& path,
const TfToken &fieldName,
const TfToken &keyPath,
VtValue *value=NULL) const;
SDF_API
bool HasFieldDictKey(const SdfPath& path,
const TfToken &fieldName,
const TfToken &keyPath,
SdfAbstractDataValue *value) const;
/// Returns \c true if the object has a non-empty value with name \p name
/// and \p keyPath and type \p T. If value ptr is provided, returns the
/// value found. The \p keyPath is a ':'-separated path addressing an
/// element in sub-dictionaries.
template <class T>
bool HasFieldDictKey(const SdfPath& path, const TfToken &name,
const TfToken &keyPath, T* value) const
{
if (!value) {
return HasFieldDictKey(path, name, keyPath,
static_cast<VtValue *>(NULL));
}
SdfAbstractDataTypedValue<T> outValue(value);
return HasFieldDictKey(path, name, keyPath,
static_cast<SdfAbstractDataValue *>(&outValue));
}
/// Return the value for the given \a path and \a fieldName. Returns an
/// empty value if none is set.
SDF_API
VtValue GetField(const SdfPath& path,
const TfToken& fieldName) const;
/// Return the value for the given \a path and \a fieldName. Returns the
/// provided \a defaultValue value if none is set.
template <class T>
inline T GetFieldAs(const SdfPath& path,
const TfToken& fieldName, const T& defaultValue = T()) const
{
return _data->GetAs<T>(path, fieldName, defaultValue);
}
/// Return the value for the given \a path and \a fieldName at \p
/// keyPath. Returns an empty value if none is set. The \p keyPath is a
/// ':'-separated path addressing an element in sub-dictionaries.
SDF_API
VtValue GetFieldDictValueByKey(const SdfPath& path,
const TfToken& fieldName,
const TfToken& keyPath) const;
/// Set the value of the given \a path and \a fieldName.
SDF_API
void SetField(const SdfPath& path, const TfToken& fieldName,
const VtValue& value);
SDF_API
void SetField(const SdfPath& path, const TfToken& fieldName,
const SdfAbstractDataConstValue& value);
/// Set the value of the given \a path and \a fieldName.
template <class T>
void SetField(const SdfPath& path, const TfToken& fieldName,
const T& val)
{
// Ideally, this would make use of the SdfAbstractDataConstValue
// API to avoid unnecessarily copying the value into a VtValue.
// However, Sdf needs to create a VtValue for change processing.
// If the underlying SdAbstractData implementation also needs a
// VtValue, using the SdfAbstractDataConstValue API would cause
// another copy to be made. So, it's more efficient to just create
// the VtValue once here and push that along.
SetField(path, fieldName, VtValue(val));
}
/// Set the value of the given \a path and \a fieldName. The \p keyPath is a
/// ':'-separated path addressing an element in sub-dictionaries.
SDF_API
void SetFieldDictValueByKey(const SdfPath& path,
const TfToken& fieldName,
const TfToken& keyPath,
const VtValue& value);
SDF_API
void SetFieldDictValueByKey(const SdfPath& path,
const TfToken& fieldName,
const TfToken& keyPath,
const SdfAbstractDataConstValue& value);
/// Set the value of the given \a path and \a fieldName. The \p keyPath is
/// a ':'-separated path addressing an element in sub-dictionaries.
template <class T>
void SetFieldDictValueByKey(const SdfPath& path,
const TfToken& fieldName,
const TfToken& keyPath,
const T& val)
{
// Ideally, this would make use of the SdfAbstractDataConstValue
// API to avoid unnecessarily copying the value into a VtValue.
// However, Sdf needs to create a VtValue for change processing.
// If the underlying SdAbstractData implementation also needs
// VtValue, using the SdfAbstractDataConstValue API would cause
// another copy to be made. So, it's more efficient to just create
// the VtValue once here and push that along.
SetFieldDictValueByKey(path, fieldName, keyPath, VtValue(val));
}
/// Remove the field at \p path and \p fieldName, if one exists.
SDF_API
void EraseField(const SdfPath& path, const TfToken& fieldName);
/// Remove the field at \p path and \p fieldName and \p keyPath, if one
/// exists. The \p keyPath is a ':'-separated path addressing an
/// element in sub-dictionaries.
SDF_API
void EraseFieldDictValueByKey(const SdfPath& path,
const TfToken& fieldName,
const TfToken& keyPath);
/// \name Traversal
/// @{
/// Callback function for Traverse. This callback will be invoked with
/// the path of each spec that is visited.
/// \sa Traverse
typedef std::function<void(const SdfPath&)> TraversalFunction;
// Traverse will perform a traversal of the scene description hierarchy
// rooted at \a path, calling \a func on each spec that it finds.
SDF_API
void Traverse(const SdfPath& path, const TraversalFunction& func);
/// @}
/// \name Metadata
/// @{
/// Returns the color configuration asset-path for this layer.
///
/// The default value is an empty asset-path.
SDF_API
SdfAssetPath GetColorConfiguration() const;
/// Sets the color configuration asset-path for this layer.
SDF_API
void SetColorConfiguration(const SdfAssetPath &colorConfiguration);
/// Returns true if color configuration metadata is set in this layer.
/// \sa GetColorConfiguration(), SetColorConfiguration()
SDF_API
bool HasColorConfiguration() const;
/// Clears the color configuration metadata authored in this layer.
/// \sa HasColorConfiguration(), SetColorConfiguration()
SDF_API
void ClearColorConfiguration();
/// Returns the color management system used to interpret the color
/// configuration asset-path authored in this layer.
///
/// The default value is an empty token, which implies that the clients
/// will have to determine the color management system from the color
/// configuration asset path (i.e. from its file extension), if it's
/// specified.
SDF_API
TfToken GetColorManagementSystem() const;
/// Sets the color management system used to interpret the color
/// configuration asset-path authored this layer.
SDF_API
void SetColorManagementSystem(const TfToken &cms);
/// Returns true if colorManagementSystem metadata is set in this layer.
/// \sa GetColorManagementSystem(), SetColorManagementSystem()
SDF_API
bool HasColorManagementSystem() const;
/// Clears the 'colorManagementSystem' metadata authored in this layer.
/// \sa HascolorManagementSystem(), SetColorManagementSystem()
SDF_API
void ClearColorManagementSystem();
/// Returns the comment string for this layer.
///
/// The default value for comment is "".
SDF_API
std::string GetComment() const;
/// Sets the comment string for this layer.
SDF_API
void SetComment(const std::string &comment);
/// Return the defaultPrim metadata for this layer. This field
/// indicates the name of which root prim should be targeted by a reference
/// or payload to this layer that doesn't specify a prim path.
///
/// The default value is the empty token.
SDF_API
TfToken GetDefaultPrim() const;
/// Set the default prim metadata for this layer. The root prim with this
/// name will be targeted by a reference or a payload to this layer that
/// doesn't specify a prim path. Note that this must be a root prim
/// <b>name</b> not a path. E.g. "rootPrim" rather than "/rootPrim". See
/// GetDefaultPrim().
SDF_API
void SetDefaultPrim(const TfToken &name);
/// Clear the default prim metadata for this layer. See GetDefaultPrim()
/// and SetDefaultPrim().
SDF_API
void ClearDefaultPrim();
/// Return true if the default prim metadata is set in this layer. See
/// GetDefaultPrim() and SetDefaultPrim().
SDF_API
bool HasDefaultPrim();
/// Returns the documentation string for this layer.
///
/// The default value for documentation is "".
SDF_API
std::string GetDocumentation() const;
/// Sets the documentation string for this layer.
SDF_API
void SetDocumentation(const std::string &documentation);
/// Returns the layer's start timeCode.
///
/// The start and end timeCodes of a layer represent the suggested playback
/// range. However, time-varying content is not limited to the timeCode range
/// of the layer.
///
/// The default value for startTimeCode is 0.
SDF_API
double GetStartTimeCode() const;
/// Sets the layer's start timeCode.
SDF_API
void SetStartTimeCode(double startTimecode);
/// Returns true if the layer has a startTimeCode opinion.
SDF_API
bool HasStartTimeCode() const;
/// Clear the startTimeCode opinion.
SDF_API
void ClearStartTimeCode();
/// Returns the layer's end timeCode.
/// The start and end timeCode of a layer represent a suggested playback range.
/// However, time-varying content is not limited to the timeCode range of the
/// layer.
///
/// The default value for endTimeCode is 0.
SDF_API
double GetEndTimeCode() const;
/// Sets the layer's end timeCode.
SDF_API
void SetEndTimeCode(double endTimeCode);
/// Returns true if the layer has an endTimeCode opinion.
SDF_API
bool HasEndTimeCode() const;
/// Clear the endTimeCode opinion.
SDF_API
void ClearEndTimeCode();
/// Returns the layer's timeCodes per second.
///
/// Scales the time ordinate for samples contained in the file to seconds.
/// If timeCodesPerSecond is 24, then a sample at time ordinate 24 should
/// be viewed exactly one second after the sample at time ordinate 0.
///
/// If this layer doesn't have an authored value for timeCodesPerSecond, but
/// it does have an authored value for framesPerSecond, this method will
/// return the value of framesPerSecond. This "dynamic fallback" allows
/// layers to lock framesPerSecond and timeCodesPerSecond to the same value
/// by specifying only framesPerSecond.
///
/// The default value of timeCodesPerSecond (which is used only if there is
/// no authored value for either timeCodesPerSecond or framesPerSecond) is
/// 24.
SDF_API
double GetTimeCodesPerSecond() const;
/// Sets the layer's timeCodes per second
SDF_API
void SetTimeCodesPerSecond(double timeCodesPerSecond);
/// Returns true if the layer has a timeCodesPerSecond opinion.
SDF_API
bool HasTimeCodesPerSecond() const;
/// Clear the timeCodesPerSecond opinion.
SDF_API
void ClearTimeCodesPerSecond();
/// Returns the layer's frames per second.
///
/// This makes an advisory statement about how the contained data can be
/// most usefully consumed and presented. It's primarily an indication of
/// the expected playback rate for the data, but a timeline editing tool
/// might also want to use this to decide how to scale and label its
/// timeline.
///
/// The default value for framesPerSecond is 24.
SDF_API
double GetFramesPerSecond() const;
/// Sets the layer's frames per second
SDF_API
void SetFramesPerSecond(double framesPerSecond);
/// Returns true if the layer has a frames per second opinion.
SDF_API
bool HasFramesPerSecond() const;
/// Clear the framesPerSecond opinion.
SDF_API
void ClearFramesPerSecond();
/// Returns the layer's frame precision.
SDF_API
int GetFramePrecision() const;
/// Sets the layer's frame precision.
SDF_API
void SetFramePrecision(int framePrecision);
/// Returns true if the layer has a frames precision opinion.
SDF_API
bool HasFramePrecision() const;
/// Clear the framePrecision opinion.
SDF_API
void ClearFramePrecision();
/// Returns the layer's owner.
SDF_API
std::string GetOwner() const;
/// Sets the layer's owner.
SDF_API
void SetOwner(const std::string& owner);
/// Returns true if the layer has an owner opinion.
SDF_API
bool HasOwner() const;
/// Clear the owner opinion.
SDF_API
void ClearOwner();
/// Returns the layer's session owner.
/// Note: This should only be used by session layers.
SDF_API
std::string GetSessionOwner() const;
/// Sets the layer's session owner.
/// Note: This should only be used by session layers.
SDF_API
void SetSessionOwner(const std::string& owner);
/// Returns true if the layer has a session owner opinion.
SDF_API
bool HasSessionOwner() const;
// Clear the session owner opinion.
SDF_API
void ClearSessionOwner();
/// Returns true if the layer's sublayers are expected to have owners.
SDF_API
bool GetHasOwnedSubLayers() const;
/// Sets whether the layer's sublayers are expected to have owners.
SDF_API
void SetHasOwnedSubLayers(bool);
/// Returns the CustomLayerData dictionary associated with this layer.
///
/// This is a dictionary is custom metadata that is associated with
/// this layer. It allows users to encode any set of information for
/// human or program consumption.