Loading...
Searching...
No Matches
layer.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_USD_SDF_LAYER_H
8#define PXR_USD_SDF_LAYER_H
9
11
12#include "pxr/pxr.h"
13#include "pxr/usd/sdf/api.h"
14#include "pxr/usd/sdf/data.h"
16#include "pxr/usd/sdf/identity.h"
17#include "pxr/usd/sdf/layerHints.h"
20#include "pxr/usd/sdf/path.h"
21#include "pxr/usd/sdf/proxyTypes.h"
22#include "pxr/usd/sdf/spec.h"
23#include "pxr/usd/sdf/types.h"
24#include "pxr/usd/ar/ar.h"
28#include "pxr/base/vt/value.h"
30
31#include <atomic>
32#include <functional>
33#include <memory>
34#include <optional>
35#include <set>
36#include <string>
37#include <vector>
38
39PXR_NAMESPACE_OPEN_SCOPE
40
43
44class SdfChangeList;
45struct Sdf_AssetInfo;
46
82 : public TfRefBase
83 , public TfWeakBase
84{
85public:
87 SDF_API
88 virtual ~SdfLayer();
89
91 SdfLayer(const SdfLayer&) = delete;
92 SdfLayer& operator=(const SdfLayer&) = delete;
93
97
100 SDF_API const SdfSchemaBase& GetSchema() const;
101
103 SDF_API const SdfFileFormatConstPtr& GetFileFormat() const;
104
107 typedef std::map<std::string, std::string> FileFormatArguments;
108
112
118 SDF_API
119 static SdfLayerRefPtr CreateNew(const std::string &identifier,
120 const FileFormatArguments &args =
122
129 SDF_API
130 static SdfLayerRefPtr CreateNew(const SdfFileFormatConstPtr& fileFormat,
131 const std::string &identifier,
132 const FileFormatArguments &args =
134
143 SDF_API
144 static SdfLayerRefPtr New(const SdfFileFormatConstPtr& fileFormat,
145 const std::string &identifier,
146 const FileFormatArguments &args =
148
155 SDF_API
156 static SdfLayerHandle Find(
157 const std::string &identifier,
159
170 SDF_API
171 static SdfLayerHandle FindRelativeToLayer(
172 const SdfLayerHandle &anchor,
173 const std::string &identifier,
175
182 SDF_API
184 const std::string &identifier,
186
197 SDF_API
199 const SdfLayerHandle &anchor,
200 const std::string &identifier,
202
216 SDF_API
218 const std::string &layerPath,
219 bool metadataOnly = false,
220 const std::string& tag = std::string());
221
223 SDF_API
224 SdfDataRefPtr GetMetadata() const;
225
229 SDF_API
231
233 SDF_API
234 static SdfLayerHandleSet GetLoadedLayers();
235
237 SDF_API
238 bool IsEmpty() const;
239
247 SDF_API
248 bool StreamsData() const;
249
255 SDF_API
256 bool IsDetached() const;
257
260 SDF_API
261 void TransferContent(const SdfLayerHandle& layer);
262
277 SDF_API
279 const std::string& tag = std::string(),
281
283 SDF_API
285 const std::string &tag, const SdfFileFormatConstPtr &format,
287
289 SDF_API
290 bool IsAnonymous() const;
291
294 SDF_API
295 static bool IsAnonymousLayerIdentifier(const std::string& identifier);
296
299 SDF_API
301 const std::string& identifier);
302
306
316 SDF_API
317 bool Save(bool force = false) const;
318
331 SDF_API
332 bool Export(const std::string& filename,
333 const std::string& comment = std::string(),
334 const FileFormatArguments& args = FileFormatArguments()) const;
335
340 SDF_API
341 bool ExportToString(std::string* result) const;
342
346 SDF_API
347 bool ImportFromString(const std::string &string);
348
356 SDF_API
357 void Clear();
358
380 SDF_API
381 bool Reload(bool force = false);
382
389 SDF_API
390 static bool ReloadLayers(const std::set<SdfLayerHandle>& layers,
391 bool force = false);
392
398 SDF_API
399 bool Import(const std::string &layerPath);
400
404
407 SDF_API
408 std::set<std::string> GetExternalReferences() const;
409
412 SDF_API
414 const std::string &oldAssetPath,
415 const std::string &newAssetPath=std::string());
416
424 SDF_API
425 std::set<std::string> GetCompositionAssetDependencies() const;
426
436 SDF_API
438 const std::string &oldAssetPath,
439 const std::string &newAssetPath=std::string());
440
449 SDF_API
450 std::set<std::string> GetExternalAssetDependencies() const;
451
471
474 SDF_API
475 static bool SplitIdentifier(
476 const std::string& identifier,
477 std::string* layerPath,
478 FileFormatArguments* arguments);
479
485 SDF_API
486 static std::pair<std::string, std::string> SplitIdentifier(
487 const std::string& identifier);
488
490 SDF_API
491 static std::string CreateIdentifier(
492 const std::string& layerPath,
493 const FileFormatArguments& arguments);
494
496 SDF_API
497 const std::string& GetIdentifier() const;
498
502 SDF_API
503 void SetIdentifier(const std::string& identifier);
504
509 SDF_API
511
515 SDF_API
516 std::string GetDisplayName() const;
517
520 SDF_API
522
525 SDF_API
526 const std::string& GetRealPath() const;
527
532 SDF_API
533 std::string GetFileExtension() const;
534
540 SDF_API
541 const std::string& GetVersion() const;
542
547 SDF_API
548 const std::string& GetRepositoryPath() const;
549
551 SDF_API
552 const std::string& GetAssetName() const;
553
556 SDF_API
557 const VtValue& GetAssetInfo() const;
558
574 SDF_API
575 std::string ComputeAbsolutePath(const std::string& assetPath) const;
576
578
589
592 SDF_API
593 SdfSpecType GetSpecType(const SdfPath& path) const;
594
596 SDF_API
597 bool HasSpec(const SdfPath& path) const;
598
600 SDF_API
601 std::vector<TfToken> ListFields(const SdfPath& path) const;
602
605 SDF_API
606 bool HasField(const SdfPath& path, const TfToken& fieldName,
607 VtValue *value=NULL) const;
608 SDF_API
609 bool HasField(const SdfPath& path, const TfToken& fieldName,
610 SdfAbstractDataValue *value) const;
611
615 template <class T>
616 bool HasField(const SdfPath& path, const TfToken &name,
617 T* value) const
618 {
619 if (!value) {
620 return HasField(path, name, static_cast<VtValue *>(NULL));
621 }
622
623 SdfAbstractDataTypedValue<T> outValue(value);
624 const bool hasValue = HasField(
625 path, name, static_cast<SdfAbstractDataValue *>(&outValue));
626
627 if (std::is_same<T, SdfValueBlock>::value) {
628 return hasValue && outValue.isValueBlock;
629 }
630
631 return hasValue && (!outValue.isValueBlock);
632 }
633
636 std::type_info const &GetFieldTypeid(
637 const SdfPath &path, const TfToken &name) const {
638 return _data->GetTypeid(path, name);
639 }
640
644 SDF_API
645 bool HasFieldDictKey(const SdfPath& path,
646 const TfToken &fieldName,
647 const TfToken &keyPath,
648 VtValue *value=NULL) const;
649 SDF_API
650 bool HasFieldDictKey(const SdfPath& path,
651 const TfToken &fieldName,
652 const TfToken &keyPath,
653 SdfAbstractDataValue *value) const;
654
659 template <class T>
660 bool HasFieldDictKey(const SdfPath& path, const TfToken &name,
661 const TfToken &keyPath, T* value) const
662 {
663 if (!value) {
664 return HasFieldDictKey(path, name, keyPath,
665 static_cast<VtValue *>(NULL));
666 }
667
668 SdfAbstractDataTypedValue<T> outValue(value);
669 return HasFieldDictKey(path, name, keyPath,
670 static_cast<SdfAbstractDataValue *>(&outValue));
671 }
672
673
676 SDF_API
678 const TfToken& fieldName) const;
679
682 template <class T>
683 inline T GetFieldAs(const SdfPath& path,
684 const TfToken& fieldName, const T& defaultValue = T()) const
685 {
686 return _data->GetAs<T>(path, fieldName, defaultValue);
687 }
688
692 SDF_API
694 const TfToken& fieldName,
695 const TfToken& keyPath) const;
696
698 SDF_API
699 void SetField(const SdfPath& path, const TfToken& fieldName,
700 const VtValue& value);
701 SDF_API
702 void SetField(const SdfPath& path, const TfToken& fieldName,
703 const SdfAbstractDataConstValue& value);
704
706 template <class T>
707 void SetField(const SdfPath& path, const TfToken& fieldName,
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 a
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 SetField(path, fieldName, VtValue(val));
718 }
719
722 SDF_API
724 const TfToken& fieldName,
725 const TfToken& keyPath,
726 const VtValue& value);
727 SDF_API
728 void SetFieldDictValueByKey(const SdfPath& path,
729 const TfToken& fieldName,
730 const TfToken& keyPath,
731 const SdfAbstractDataConstValue& value);
732
735 template <class T>
737 const TfToken& fieldName,
738 const TfToken& keyPath,
739 const T& val)
740 {
741 // Ideally, this would make use of the SdfAbstractDataConstValue
742 // API to avoid unnecessarily copying the value into a VtValue.
743 // However, Sdf needs to create a VtValue for change processing.
744 // If the underlying SdAbstractData implementation also needs
745 // VtValue, using the SdfAbstractDataConstValue API would cause
746 // another copy to be made. So, it's more efficient to just create
747 // the VtValue once here and push that along.
748 SetFieldDictValueByKey(path, fieldName, keyPath, VtValue(val));
749 }
750
752 SDF_API
753 void EraseField(const SdfPath& path, const TfToken& fieldName);
754
758 SDF_API
760 const TfToken& fieldName,
761 const TfToken& keyPath);
762
765
769 typedef std::function<void(const SdfPath&)> TraversalFunction;
770
771 // Traverse will perform a traversal of the scene description hierarchy
772 // rooted at \a path, calling \a func on each spec that it finds.
773 SDF_API
774 void Traverse(const SdfPath& path, const TraversalFunction& func);
775
777
780
784 SDF_API
786
788 SDF_API
789 void SetColorConfiguration(const SdfAssetPath &colorConfiguration);
790
793 SDF_API
795
798 SDF_API
800
808 SDF_API
810
813 SDF_API
815
818 SDF_API
820
823 SDF_API
825
829 SDF_API
830 std::string GetComment() const;
831
833 SDF_API
834 void SetComment(const std::string &comment);
835
841 SDF_API
843
853 SDF_API
855
862 SDF_API
863 void SetDefaultPrim(const TfToken &name);
864
867 SDF_API
869
872 SDF_API
874
882 SDF_API
884
893 SDF_API
895
899 SDF_API
900 std::string GetDocumentation() const;
901
903 SDF_API
904 void SetDocumentation(const std::string &documentation);
905
913 SDF_API
914 double GetStartTimeCode() const;
915
917 SDF_API
918 void SetStartTimeCode(double startTimecode);
919
921 SDF_API
922 bool HasStartTimeCode() const;
923
925 SDF_API
927
934 SDF_API
935 double GetEndTimeCode() const;
936
938 SDF_API
939 void SetEndTimeCode(double endTimeCode);
940
942 SDF_API
943 bool HasEndTimeCode() const;
944
946 SDF_API
948
963 SDF_API
964 double GetTimeCodesPerSecond() const;
965
967 SDF_API
968 void SetTimeCodesPerSecond(double timeCodesPerSecond);
969
971 SDF_API
973
975 SDF_API
977
987 SDF_API
988 double GetFramesPerSecond() const;
989
991 SDF_API
992 void SetFramesPerSecond(double framesPerSecond);
993
995 SDF_API
996 bool HasFramesPerSecond() const;
997
999 SDF_API
1001
1003 SDF_API
1005
1007 SDF_API
1008 void SetFramePrecision(int framePrecision);
1009
1011 SDF_API
1012 bool HasFramePrecision() const;
1013
1015 SDF_API
1017
1019 SDF_API
1020 std::string GetOwner() const;
1021
1023 SDF_API
1024 void SetOwner(const std::string& owner);
1025
1027 SDF_API
1028 bool HasOwner() const;
1029
1031 SDF_API
1033
1036 SDF_API
1037 std::string GetSessionOwner() const;
1038
1041 SDF_API
1042 void SetSessionOwner(const std::string& owner);
1043
1045 SDF_API
1046 bool HasSessionOwner() const;
1047
1048 // Clear the session owner opinion.
1049 SDF_API
1050 void ClearSessionOwner();
1051
1053 SDF_API
1055
1057 SDF_API
1059
1065 SDF_API
1067
1069 SDF_API
1071
1073 SDF_API
1075
1077 SDF_API
1079
1082 SDF_API
1084
1086 SDF_API
1087 void SetExpressionVariables(const VtDictionary& expressionVars);
1088
1090 SDF_API
1092
1094 SDF_API
1096
1100
1101 // Type for root prims view.
1103
1105 SDF_API
1107
1112 SDF_API
1113 void SetRootPrims(const SdfPrimSpecHandleVector &rootPrims);
1114
1120 SDF_API
1121 bool InsertRootPrim(const SdfPrimSpecHandle &prim, int index = -1);
1122
1124 SDF_API
1125 void RemoveRootPrim(const SdfPrimSpecHandle &prim);
1126
1129 SDF_API
1131
1144 SDF_API
1145 void RemovePrimIfInert(SdfPrimSpecHandle prim);
1146
1153 SDF_API
1154 void RemovePropertyIfHasOnlyRequiredFields(SdfPropertySpecHandle prop);
1155
1161 SDF_API
1163
1168 SDF_API
1170
1179 SDF_API
1180 void SetRootPrimOrder(const std::vector<TfToken>& names);
1181
1184 SDF_API
1185 void InsertInRootPrimOrder(const TfToken &name, int index = -1);
1186
1188 SDF_API
1190
1192 SDF_API
1194
1200 SDF_API
1201 void ApplyRootPrimOrder(std::vector<TfToken> *vec) const;
1202
1206
1219 SDF_API
1221
1223 SDF_API
1224 void SetSubLayerPaths(const std::vector<std::string>& newPaths);
1225
1227 SDF_API
1228 size_t GetNumSubLayerPaths() const;
1229
1233 SDF_API
1234 void InsertSubLayerPath(const std::string& path, int index = -1);
1235
1237 SDF_API
1238 void RemoveSubLayerPath(int index);
1239
1241 SDF_API
1242 SdfLayerOffsetVector GetSubLayerOffsets() const;
1243
1245 SDF_API
1247
1249 SDF_API
1250 void SetSubLayerOffset(const SdfLayerOffset& offset, int index);
1251
1255
1264 SDF_API
1266
1269 SDF_API
1270 void SetRelocates(const SdfRelocates& relocates);
1271
1276 SDF_API
1277 bool HasRelocates() const;
1278
1280 SDF_API
1282
1284
1305
1322 {
1323 public:
1327
1330 {
1331 _includeAll = true;
1332 _include.clear();
1333 return *this;
1334 }
1335
1338 SDF_API
1339 DetachedLayerRules& Include(const std::vector<std::string>& patterns);
1340
1343 SDF_API
1344 DetachedLayerRules& Exclude(const std::vector<std::string>& patterns);
1345
1346 bool IncludedAll() const { return _includeAll; }
1347 const std::vector<std::string>& GetIncluded() const { return _include; }
1348 const std::vector<std::string>& GetExcluded() const { return _exclude; }
1349
1357 SDF_API
1358 bool IsIncluded(const std::string& identifier) const;
1359
1360 private:
1361 friend class SdfLayer;
1362
1363 std::vector<std::string> _include;
1364 std::vector<std::string> _exclude;
1365 bool _includeAll = false;
1366 };
1367
1390 SDF_API
1392
1394 SDF_API
1396
1400 SDF_API
1401 static bool IsIncludedByDetachedLayerRules(const std::string& identifier);
1402
1404
1407
1409 SDF_API
1410 static std::set<std::string> GetMutedLayers();
1411
1413 SDF_API
1414 bool IsMuted() const;
1415
1417 SDF_API
1418 static bool IsMuted(const std::string &path);
1419
1422 SDF_API
1423 void SetMuted(bool muted);
1424
1426 SDF_API
1427 static void AddToMutedLayers(const std::string &mutedPath);
1428
1430 SDF_API
1431 static void RemoveFromMutedLayers(const std::string &mutedPath);
1432
1436
1446 SDF_API
1447 SdfPrimSpecHandle GetPseudoRoot() const;
1448
1455 SDF_API
1456 SdfSpecHandle GetObjectAtPath(const SdfPath &path);
1457
1463 SDF_API
1464 SdfPrimSpecHandle GetPrimAtPath(const SdfPath &path);
1465
1471 SDF_API
1472 SdfPropertySpecHandle GetPropertyAtPath(const SdfPath &path);
1473
1479 SDF_API
1480 SdfAttributeSpecHandle GetAttributeAtPath(const SdfPath &path);
1481
1487 SDF_API
1488 SdfRelationshipSpecHandle GetRelationshipAtPath(const SdfPath &path);
1489
1493
1497 SDF_API
1498 bool PermissionToEdit() const;
1499
1502 SDF_API
1503 bool PermissionToSave() const;
1504
1506 SDF_API
1507 void SetPermissionToEdit(bool allow);
1508
1510 SDF_API
1511 void SetPermissionToSave(bool allow);
1512
1516
1540 SDF_API
1543 SdfNamespaceEditDetailVector* details = NULL) const;
1544
1548 SDF_API
1550
1554
1557 SDF_API
1558 SdfLayerStateDelegateBasePtr GetStateDelegate() const;
1559
1563 SDF_API
1564 void SetStateDelegate(const SdfLayerStateDelegateBaseRefPtr& delegate);
1565
1568 SDF_API
1569 bool IsDirty() const;
1570
1572
1575 SDF_API
1576 std::set<double> ListAllTimeSamples() const;
1577
1578 SDF_API
1579 std::set<double>
1580 ListTimeSamplesForPath(const SdfPath& path) const;
1581
1582 SDF_API
1583 bool GetBracketingTimeSamples(double time, double* tLower, double* tUpper);
1584
1585 SDF_API
1586 size_t GetNumTimeSamplesForPath(const SdfPath& path) const;
1587
1588 SDF_API
1589 bool GetBracketingTimeSamplesForPath(const SdfPath& path,
1590 double time,
1591 double* tLower, double* tUpper) const;
1592
1599 SDF_API
1600 bool GetPreviousTimeSampleForPath(const SdfPath& path, double time,
1601 double* tPrevious) const;
1602
1603 SDF_API
1604 bool QueryTimeSample(const SdfPath& path, double time,
1605 VtValue *value=NULL) const;
1606
1607 SDF_API
1608 bool QueryTimeSample(const SdfPath& path, double time,
1609 SdfAbstractDataValue *value) const;
1610
1611 template <class T>
1612 bool QueryTimeSample(const SdfPath& path, double time,
1613 T* data) const
1614 {
1615 if (!data) {
1616 return QueryTimeSample(path, time);
1617 }
1618
1619 SdfAbstractDataTypedValue<T> outValue(data);
1620 const bool hasValue = QueryTimeSample(
1621 path, time, static_cast<SdfAbstractDataValue *>(&outValue));
1622
1623 if (std::is_same<T, SdfValueBlock>::value) {
1624 return hasValue && outValue.isValueBlock;
1625 }
1626
1627 return hasValue && (!outValue.isValueBlock);
1628 }
1629
1632 SDF_API
1633 const std::type_info &
1634 QueryTimeSampleTypeid(const SdfPath &path, double time) const;
1635
1636 SDF_API
1637 void SetTimeSample(const SdfPath& path, double time,
1638 const VtValue & value);
1639
1640 SDF_API
1641 void SetTimeSample(const SdfPath& path, double time,
1642 const SdfAbstractDataConstValue& value);
1643
1644 template <class T>
1645 void SetTimeSample(const SdfPath& path, double time,
1646 const T& value)
1647 {
1648 const SdfAbstractDataConstTypedValue<T> inValue(&value);
1649 const SdfAbstractDataConstValue& untypedInValue = inValue;
1650 return SetTimeSample(path, time, untypedInValue);
1651 }
1652
1653 SDF_API
1654 void EraseTimeSample(const SdfPath& path, double time);
1655
1657
1658 // Debugging
1659 // @{
1660
1661 SDF_API
1662 static void DumpLayerInfo();
1663
1664 // Write this layer's SdfData to a file in a simple generic format.
1665 SDF_API
1666 bool WriteDataFile(const std::string &filename);
1667
1668 // @}
1669
1677 SDF_API
1679 const SdfLayerHandle& layer,
1680 bool processPropertyFields = true) const;
1681
1682protected:
1683 // Private constructor -- use New(), FindOrCreate(), etc.
1684 // Precondition: _layerRegistryMutex must be locked.
1685 SdfLayer(const SdfFileFormatConstPtr& fileFormat,
1686 const std::string &identifier,
1687 const std::string &realPath = std::string(),
1688 const ArAssetInfo& assetInfo = ArAssetInfo(),
1690 bool validateAuthoring = false);
1691
1692private:
1693 // Create a new layer.
1694 // Precondition: _layerRegistryMutex must be locked.
1695 static SdfLayerRefPtr _CreateNew(
1696 SdfFileFormatConstPtr fileFormat,
1697 const std::string& identifier,
1698 const FileFormatArguments& args,
1699 bool saveLayer = true);
1700
1701 static SdfLayerRefPtr _CreateNewWithFormat(
1702 const SdfFileFormatConstPtr &fileFormat,
1703 const std::string& identifier,
1704 const std::string& realPath,
1705 const ArAssetInfo& assetInfo = ArAssetInfo(),
1707
1708 static SdfLayerRefPtr _CreateAnonymousWithFormat(
1709 const SdfFileFormatConstPtr &fileFormat,
1710 const std::string& tag,
1711 const FileFormatArguments& args);
1712
1713 // Finish initializing this layer (which may have succeeded or not)
1714 // and publish the results to other threads by unlocking the mutex.
1715 // Sets _initializationWasSuccessful.
1716 void _FinishInitialization(bool success);
1717
1718 // Layers retrieved from the layer registry may still be in the
1719 // process of having their contents initialized. Other threads
1720 // retrieving layers from the registry must wait until initialization
1721 // is complete, using this method.
1722 // Returns _initializationWasSuccessful.
1723 //
1724 // Callers *must* be holding an SdfLayerRefPtr to this layer to
1725 // ensure that it is not deleted out from under them, in
1726 // case initialization fails. (This method cannot acquire the
1727 // reference itself internally without being susceptible to a race.)
1728 bool _WaitForInitializationAndCheckIfSuccessful();
1729
1730 // Returns whether or not this layer should post change
1731 // notification. This simply returns (!_GetIsLoading())
1732 bool _ShouldNotify() const;
1733
1734 // This function keeps track of the last state of IsDirty() before
1735 // updating it. It returns false if the last saved dirty state is the
1736 // same than the current state. It returns true if the state differs and
1737 // will update the 'last dirty state' to the current state. So, after
1738 // returning true, it would return false for subsequent calls until the
1739 // IsDirty() state would change again...
1740 bool _UpdateLastDirtinessState() const;
1741
1742 // Returns a handle to the spec at the given path if it exists and matches
1743 // type T.
1744 template <class T>
1745 SdfHandle<T> _GetSpecAtPath(const SdfPath& path);
1746
1747 // Returns true if a spec can be retrieved at the given path, false
1748 // otherwise. This function will return the canonicalized path to the
1749 // spec as well as the spec type.
1750 bool _CanGetSpecAtPath(const SdfPath& path,
1751 SdfPath* canonicalPath, SdfSpecType* specType) const;
1752
1756 void _InitializeFromIdentifier(
1757 const std::string &identifier,
1758 const std::string &realPath = std::string(),
1759 const std::string &fileVersion = std::string(),
1760 const ArAssetInfo& assetInfo = ArAssetInfo());
1761
1762 // Helper for computing the necessary information to lookup a layer
1763 // in the registry or open the layer.
1764 struct _FindOrOpenLayerInfo;
1765 static bool _ComputeInfoToFindOrOpenLayer(
1766 const std::string& identifier,
1768 _FindOrOpenLayerInfo* info,
1769 bool computeAssetInfo = false);
1770
1771 // Open a layer, adding an entry to the registry and releasing
1772 // the registry lock.
1773 // Precondition: _layerRegistryMutex must be locked.
1774 template <class Lock>
1775 static SdfLayerRefPtr _OpenLayerAndUnlockRegistry(
1776 Lock &lock,
1777 const _FindOrOpenLayerInfo& info,
1778 bool metadataOnly);
1779
1780 // Helper function for finding a layer with \p identifier and \p args.
1781 // \p lock must be unlocked initially and will be locked by this
1782 // function when needed. See docs for \p retryAsWriter argument on
1783 // _TryToFindLayer for details on the final state of the lock when
1784 // this function returns.
1785 template <class ScopedLock>
1786 static SdfLayerRefPtr
1787 _Find(const std::string &identifier,
1788 const FileFormatArguments &args,
1789 ScopedLock &lock, bool retryAsWriter);
1790
1791 // Helper function to try to find the layer with \p identifier and
1792 // pre-resolved path \p resolvedPath in the registry. Caller must hold
1793 // registry \p lock for reading. If \p retryAsWriter is false, lock is
1794 // released upon return. Otherwise the lock is released upon return if a
1795 // layer is found successfully. If no layer is found then the lock is
1796 // upgraded to a writer lock upon return. Note that this upgrade may not be
1797 // atomic, but this function ensures that if upon return there does not
1798 // exist a matching layer in the registry.
1799 template <class ScopedLock>
1800 static SdfLayerRefPtr
1801 _TryToFindLayer(const std::string &identifier,
1802 const ArResolvedPath &resolvedPath,
1803 ScopedLock &lock, bool retryAsWriter);
1804
1812 bool _IsInert(const SdfPath &path, bool ignoreChildren,
1813 bool requiredFieldOnlyPropertiesAreInert = false) const;
1814
1818 bool _IsInertSubtree(const SdfPath &path) const;
1819
1825 void _RemoveIfInert(const SdfSpec& spec);
1826
1831 bool _RemoveInertDFS(SdfPrimSpecHandle prim);
1832
1835 void _RemoveInertToRootmost(SdfPrimSpecHandle prim);
1836
1838 bool _ValidateAuthoring() const { return _validateAuthoring; }
1839
1841 std::string _GetMutedPath() const;
1842
1843 // If old and new asset path is given, rename all external prim
1844 // composition dependency referring to the old path.
1845 void _UpdatePrimCompositionDependencyPaths(
1846 const SdfPrimSpecHandle &parent,
1847 const std::string &oldLayerPath,
1848 const std::string &newLayerPath);
1849
1850 // Set the clean state to the current state.
1851 void _MarkCurrentStateAsClean() const;
1852
1853 // Return the field definition for \p fieldName if \p fieldName is a
1854 // required field for the spec type identified by \p path.
1855 inline SdfSchema::FieldDefinition const *
1856 _GetRequiredFieldDef(const SdfPath &path,
1857 const TfToken &fieldName,
1858 SdfSpecType specType = SdfSpecTypeUnknown) const;
1859
1860 // Return the field definition for \p fieldName if \p fieldName is a
1861 // required field for \p specType subject to \p schema.
1862 static inline SdfSchema::FieldDefinition const *
1863 _GetRequiredFieldDef(const SdfSchemaBase &schema,
1864 const TfToken &fieldName,
1865 SdfSpecType specType);
1866
1867 // Helper to list all fields on \p data at \p path subject to \p schema.
1868 static std::vector<TfToken>
1869 _ListFields(SdfSchemaBase const &schema,
1870 SdfAbstractData const &data, const SdfPath& path);
1871
1872 // Helper for HasField for \p path in \p data subject to \p schema.
1873 static inline bool
1874 _HasField(const SdfSchemaBase &schema,
1875 const SdfAbstractData &data,
1876 const SdfPath& path,
1877 const TfToken& fieldName,
1878 VtValue *value);
1879
1880 // Helper to get a field value for \p path in \p data subject to \p schema.
1881 static inline VtValue
1882 _GetField(const SdfSchemaBase &schema,
1883 const SdfAbstractData &data,
1884 const SdfPath& path,
1885 const TfToken& fieldName);
1886
1887 // Set a value.
1888 template <class T>
1889 void _SetValue(const TfToken& key, T value);
1890
1891 // Get a value.
1892 template <class T>
1893 T _GetValue(const TfToken& key) const;
1894
1895 enum _ReloadResult { _ReloadFailed, _ReloadSucceeded, _ReloadSkipped };
1896 _ReloadResult _Reload(bool force);
1897
1898 // Reads contents of asset specified by \p identifier with resolved
1899 // path \p resolvedPath into this layer.
1900 bool _Read(const std::string& identifier,
1901 const ArResolvedPath& resolvedPath,
1902 bool metadataOnly);
1903
1904 // Saves this layer if it is dirty or the layer doesn't already exist
1905 // on disk. If \p force is true, the layer will be written out
1906 // regardless of those conditions.
1907 bool _Save(bool force) const;
1908
1909 // Helper for Save and Export, checks whether or not writing to \p
1910 // newFileName with \p format is supported and issues diagnostics and
1911 // returns false if not.
1912 bool _CheckFormatWritability(bool isSave,
1913 SdfFileFormatConstPtr format,
1914 const std::string &newFileName) const;
1915
1916 // Swap contents of _data and data. This operation does not register
1917 // inverses or emit change notification.
1918 void _SwapData(SdfAbstractDataRefPtr &data);
1919
1920 // Set _data to \p newData and send coarse DidReplaceLayerContent
1921 // invalidation notice.
1922 void _AdoptData(const SdfAbstractDataRefPtr &newData);
1923
1924 // Helper function which will process incoming data to this layer in a
1925 // generic way.
1926 // If \p processPropertyFields is false, this method will not
1927 // consider property spec fields. In some cases, this can avoid expensive
1928 // operations which would pull large amounts of data.
1929 template<typename DeleteSpecFunc, typename CreateSpecFunc,
1930 typename GetFieldValuesFunc, typename SetFieldFunc,
1931 typename ErrorFunc>
1932 void _ProcessIncomingData(const SdfAbstractDataPtr &newData,
1933 const SdfSchemaBase *newDataSchema,
1934 bool processPropertyFields,
1935 const DeleteSpecFunc &deleteSpecFunc,
1936 const CreateSpecFunc &createSpecFunc,
1937 const GetFieldValuesFunc &getFieldValuesFunc,
1938 const SetFieldFunc &setFieldFunc,
1939 const ErrorFunc &errorFunc) const;
1940
1941 // Set _data to match data, calling other primitive setter methods to
1942 // provide fine-grained inverses and notification. If \p data might adhere
1943 // to a different schema than this layer's, pass a pointer to it as \p
1944 // newDataSchema. In this case, check to see if fields from \p data are
1945 // known to this layer's schema, and if not, omit them and issue a TfError
1946 // with SdfAuthoringErrorUnrecognizedFields, but continue to set all other
1947 // known fields.
1948 void _SetData(const SdfAbstractDataPtr &newData,
1949 const SdfSchemaBase *newDataSchema=nullptr);
1950
1951 // Returns const handle to _data.
1952 SdfAbstractDataConstPtr _GetData() const;
1953
1954 // Returns a new SdfAbstractData object for this layer.
1955 SdfAbstractDataRefPtr _CreateData() const;
1956
1957 // Inverse primitive for setting a single field. The previous value for the
1958 // field may be given via \p oldValue. If \p oldValue is non-nullptr, the
1959 // VtValue it points to will be moved-from after the function completes. If
1960 // \p oldValue is nullptr, the old field value will be retrieved
1961 // automatically.
1962 template <class T>
1963 void _PrimSetField(const SdfPath& path,
1964 const TfToken& fieldName,
1965 const T& value,
1966 VtValue *oldValue = nullptr,
1967 bool useDelegate = true);
1968
1969 // Inverse primitive for setting a single key in a dict-valued field. The
1970 // previous dictionary value for the field (*not* the individual entry) may
1971 // be supplied via \p oldValue. If \p oldValue is non-nullptr, the VtValue
1972 // it points to will be moved-from after the function completes. If \p
1973 // oldValue is nullptr, the old field value will be retrieved automatically.
1974 template <class T>
1975 void _PrimSetFieldDictValueByKey(const SdfPath& path,
1976 const TfToken& fieldName,
1977 const TfToken& keyPath,
1978 const T& value,
1979 VtValue *oldValue = nullptr,
1980 bool useDelegate = true);
1981
1982 // Primitive for appending a child to the list of children.
1983 template <class T>
1984 void _PrimPushChild(const SdfPath& parentPath,
1985 const TfToken& fieldName,
1986 const T& value,
1987 bool useDelegate = true);
1988 template <class T>
1989 void _PrimPopChild(const SdfPath& parentPath,
1990 const TfToken& fieldName,
1991 bool useDelegate = true);
1992
1993 // Move all the fields at all paths at or below \a oldPath to be
1994 // at a corresponding location at or below \a newPath. This does
1995 // not update the children fields of the parents of these paths.
1996 bool _MoveSpec(const SdfPath &oldPath, const SdfPath &newPath);
1997
1998 // Inverse primitive for moving a spec.
1999 void _PrimMoveSpec(const SdfPath &oldPath, const SdfPath &newPath,
2000 bool useDelegate = true);
2001
2002 // Create a new spec of type \p specType at \p path.
2003 // Returns true if spec was successfully created, false otherwise.
2004 bool _CreateSpec(const SdfPath& path, SdfSpecType specType, bool inert);
2005
2006 // Delete all the fields at or below the specified path. This does
2007 // not update the children field of the parent of \a path.
2008 bool _DeleteSpec(const SdfPath &path);
2009
2010 // Inverse primitive for deleting a spec.
2011 void _PrimCreateSpec(const SdfPath &path, SdfSpecType specType, bool inert,
2012 bool useDelegate = true);
2013
2014 // Inverse primitive for deleting a spec.
2015 void _PrimDeleteSpec(const SdfPath &path, bool inert,
2016 bool useDelegate = true);
2017
2018 // Inverse primitive for setting time samples.
2019 template <class T>
2020 void _PrimSetTimeSample(const SdfPath& path, double time,
2021 const T& value,
2022 bool useDelegate = true);
2023
2024 // Helper method for Traverse. Visits the children of \a path using the
2025 // specified \a ChildPolicy.
2026 template <typename ChildPolicy>
2027 void _TraverseChildren(const SdfPath &path, const TraversalFunction &func);
2028
2029private:
2030 SdfLayerHandle _self;
2031
2032 // File format and arguments for this layer.
2033 SdfFileFormatConstPtr _fileFormat;
2034 FileFormatArguments _fileFormatArgs;
2035
2036 // Cached reference to the _fileFormat's schema -- we need access to this to
2037 // be as fast as possible since we look at it on every SetField(), for
2038 // example.
2039 const SdfSchemaBase &_schema;
2040
2041 // Registry of Sdf Identities
2042 mutable Sdf_IdentityRegistry _idRegistry;
2043
2044 // The underlying SdfData which stores all the data in the layer.
2045 SdfAbstractDataRefPtr _data;
2046
2047 // The state delegate for this layer.
2048 SdfLayerStateDelegateBaseRefPtr _stateDelegate;
2049
2050 // Dispatcher used in layer initialization, letting waiters participate in
2051 // loading instead of just busy-waiting.
2052 WorkDispatcher _initDispatcher;
2053
2054 // Atomic variable protecting layer initialization -- the interval between
2055 // adding a layer to the layer registry and finishing the process of
2056 // initializing its contents, at which point we can truly publish the layer
2057 // for consumption by concurrent threads. We add the layer to the registry
2058 // before initialization completes so that other threads can discover and
2059 // wait for it to finish initializing.
2060 std::atomic<bool> _initializationComplete;
2061
2062 // This is an optional<bool> that is only set once initialization
2063 // is complete, before _initializationComplete is set.
2064 std::optional<bool> _initializationWasSuccessful;
2065
2066 // remembers the last 'IsDirty' state.
2067 mutable bool _lastDirtyState;
2068
2069 // Asset information for this layer.
2070 std::unique_ptr<Sdf_AssetInfo> _assetInfo;
2071
2072 // Modification timestamp of the backing file asset when last read.
2073 mutable VtValue _assetModificationTime;
2074
2075 // All external asset dependencies, with their modification timestamps, of
2076 // the layer when last read.
2077 mutable VtDictionary _externalAssetModificationTimes;
2078
2079 // Mutable revision number for cache invalidation.
2080 mutable size_t _mutedLayersRevisionCache;
2081
2082 // Cache of whether or not this layer is muted. Only valid if
2083 // _mutedLayersRevisionCache is up-to-date with the global revision number.
2084 mutable bool _isMutedCache;
2085
2086 // Layer permission bits.
2087 bool _permissionToEdit;
2088 bool _permissionToSave;
2089
2090 // Whether layer edits are validated.
2091 bool _validateAuthoring;
2092
2093 // Layer hints as of the most recent save operation.
2094 mutable SdfLayerHints _hints;
2095
2096 // Allow access to _ValidateAuthoring() and _IsInert().
2097 friend class SdfSpec;
2098 friend class SdfPropertySpec;
2099 friend class SdfAttributeSpec;
2100
2101 friend class Sdf_ChangeManager;
2102
2103 // Allow access to _CreateSpec and _DeleteSpec and _MoveSpec
2104 template <class ChildPolicy> friend class Sdf_ChildrenUtils;
2105
2106 // Give the file format access to our data. Limit breaking encapsulation
2107 // to the base SdFileFormat class so we don't have to friend every
2108 // implementation here.
2109 friend class SdfFileFormat;
2110
2111 // Give layer state delegates access to our data as well as to
2112 // the various _Prim functions.
2113 friend class SdfLayerStateDelegateBase;
2114};
2115
2116PXR_NAMESPACE_CLOSE_SCOPE
2117
2118#endif // PXR_USD_SDF_LAYER_H
Contains information about a resolved asset.
Definition assetInfo.h:25
Represents a resolved asset path.
The fully-typed container for a field value in an SdfAbstractData.
A type-erased container for a const field value in an SdfAbstractData.
Interface for scene description data storage.
The fully-typed container for a field value in an SdfAbstractData.
A type-erased container for a field value in an SdfAbstractData.
Contains an asset path and optional evaluated and resolved paths.
Definition assetPath.h:79
A subclass of SdfPropertySpec that holds typed data.
A description of an arbitrarily complex namespace edit.
A list of scene description modifications, organized by the namespace paths where the changes occur.
Definition changeList.h:36
Provides a view onto an object's children.
Base class for file format implementations.
Definition fileFormat.h:50
SdfHandle is a smart ptr that calls IsDormant() on the pointed-to object as an extra expiration check...
Object used to specify detached layers.
Definition layer.h:1322
DetachedLayerRules & IncludeAll()
Include all layers in the detached layer set.
Definition layer.h:1329
SDF_API DetachedLayerRules & Include(const std::vector< std::string > &patterns)
Include layers whose identifiers contain any of the strings in patterns in the detached layer set.
SDF_API DetachedLayerRules & Exclude(const std::vector< std::string > &patterns)
Exclude layers whose identifiers contain any of the strings in patterns from the detached layer set.
DetachedLayerRules()=default
A default constructed rules object Excludes all layers from the detached layer set.
SDF_API bool IsIncluded(const std::string &identifier) const
Returns true if identifier is included in the detached layer set, false otherwise.
Contains hints about layer contents that may be used to accelerate certain composition operations.
Definition layerHints.h:17
A scene description container that can combine with other such containers to form simple component as...
Definition layer.h:84
SDF_API void RemoveFromRootPrimOrderByIndex(int index)
Removes a root prim name from the root prim order by index.
SDF_API bool Import(const std::string &layerPath)
Imports the content of the given layer path, replacing the content of the current layer.
bool HasField(const SdfPath &path, const TfToken &name, T *value) const
Returns true if the object has a non-empty value with name name and type T.
Definition layer.h:616
SDF_API TfToken GetColorManagementSystem() const
Returns the color management system used to interpret the color configuration asset-path authored in ...
SDF_API SdfRelocates GetRelocates() const
Get the list of relocates specified in this layer's metadata.
static SDF_API void RemoveFromMutedLayers(const std::string &mutedPath)
Remove the specified path from the muted layers set.
SDF_API bool IsMuted() const
Returns true if the current layer is muted.
SDF_API double GetEndTimeCode() const
Returns the layer's end timeCode.
SDF_API void ClearCustomLayerData()
Clears out the CustomLayerData dictionary associated with this layer.
SDF_API void ClearTimeCodesPerSecond()
Clear the timeCodesPerSecond opinion.
SDF_API SdfSubLayerProxy GetSubLayerPaths() const
Returns a proxy for this layer's sublayers.
SDF_API std::set< std::string > GetCompositionAssetDependencies() const
Return paths of all assets this layer depends on due to composition fields.
SDF_API bool StreamsData() const
Returns true if this layer streams data from its serialized data store on demand, false otherwise.
SDF_API void SetFieldDictValueByKey(const SdfPath &path, const TfToken &fieldName, const TfToken &keyPath, const VtValue &value)
Set the value of the given path and fieldName.
SDF_API void InsertInRootPrimOrder(const TfToken &name, int index=-1)
Adds a new root prim name in the root prim order.
static SDF_API void AddToMutedLayers(const std::string &mutedPath)
Add the specified path to the muted layers set.
SDF_API void SetFramesPerSecond(double framesPerSecond)
Sets the layer's frames per second.
SDF_API bool UpdateCompositionAssetDependency(const std::string &oldAssetPath, const std::string &newAssetPath=std::string())
Updates the asset path of a composation dependency in this layer.
virtual SDF_API ~SdfLayer()
Destructor.
static SDF_API SdfLayerRefPtr CreateAnonymous(const std::string &tag, const SdfFileFormatConstPtr &format, const FileFormatArguments &args=FileFormatArguments())
Create an anonymous layer with a specific format.
SDF_API bool HasFramePrecision() const
Returns true if the layer has a frames precision opinion.
SDF_API bool HasSessionOwner() const
Returns true if the layer has a session owner opinion.
SDF_API SdfNameOrderProxy GetRootPrimOrder() const
Returns the list of prim names for this layer's reorder rootPrims statement.
SDF_API bool IsDirty() const
Returns true if the layer is dirty, i.e.
SDF_API bool HasSpec(const SdfPath &path) const
Return whether a spec exists at path.
SDF_API bool ImportFromString(const std::string &string)
Reads this layer from the given string.
SDF_API void SetFramePrecision(int framePrecision)
Sets the layer's frame precision.
SDF_API std::vector< TfToken > ListFields(const SdfPath &path) const
Return the names of all the fields that are set at path.
static SDF_API SdfLayerHandle FindRelativeToLayer(const SdfLayerHandle &anchor, const std::string &identifier, const FileFormatArguments &args=FileFormatArguments())
Return an existing layer with the given identifier and args.
SDF_API SdfNamespaceEditDetail::Result CanApply(const SdfBatchNamespaceEdit &, SdfNamespaceEditDetailVector *details=NULL) const
Check if a batch of namespace edits will succeed.
SDF_API SdfDataRefPtr GetMetadata() const
Returns the data from the absolute root path of this layer.
SDF_API const SdfSchemaBase & GetSchema() const
Returns the schema this layer adheres to.
SDF_API void SetPermissionToEdit(bool allow)
Sets permission to edit.
static SDF_API bool IsMuted(const std::string &path)
Returns true if the specified layer path is muted.
SDF_API bool IsEmpty() const
Returns whether this layer has no significant data.
SDF_API std::string GetOwner() const
Returns the layer's owner.
SDF_API void EraseField(const SdfPath &path, const TfToken &fieldName)
Remove the field at path and fieldName, if one exists.
SDF_API int GetFramePrecision() const
Returns the layer's frame precision.
SDF_API void SetPermissionToSave(bool allow)
Sets permission to save.
void SetFieldDictValueByKey(const SdfPath &path, const TfToken &fieldName, const TfToken &keyPath, const T &val)
Set the value of the given path and fieldName.
Definition layer.h:736
SDF_API bool HasFramesPerSecond() const
Returns true if the layer has a frames per second opinion.
SDF_API bool HasOwner() const
Returns true if the layer has an owner opinion.
SDF_API void SetField(const SdfPath &path, const TfToken &fieldName, const VtValue &value)
Set the value of the given path and fieldName.
static SDF_API bool SplitIdentifier(const std::string &identifier, std::string *layerPath, FileFormatArguments *arguments)
Splits the given layer identifier into its constituent layer path and arguments.
SDF_API void ClearEndTimeCode()
Clear the endTimeCode opinion.
SDF_API const ArResolvedPath & GetResolvedPath() const
Returns the resolved path for this layer.
static SDF_API bool IsAnonymousLayerIdentifier(const std::string &identifier)
Returns true if the identifier is an anonymous layer unique identifier.
SDF_API void SetCustomLayerData(const VtDictionary &value)
Sets the CustomLayerData dictionary associated with this layer.
SDF_API void SetIdentifier(const std::string &identifier)
Sets the layer identifier.
SDF_API bool GetHasOwnedSubLayers() const
Returns true if the layer's sublayers are expected to have owners.
static SDF_API SdfLayerRefPtr OpenAsAnonymous(const std::string &layerPath, bool metadataOnly=false, const std::string &tag=std::string())
Load the given layer from disk as a new anonymous layer.
SDF_API const std::string & GetIdentifier() const
Returns the layer identifier.
static SDF_API SdfLayerHandleSet GetLoadedLayers()
Returns handles for all layers currently held by the layer registry.
SDF_API const std::string & GetRepositoryPath() const
Returns the layer identifier in asset path form.
SDF_API void ScheduleRemoveIfInert(const SdfSpec &spec)
Cause spec to be removed if it no longer affects the scene when the last change block is closed,...
SDF_API void SetSessionOwner(const std::string &owner)
Sets the layer's session owner.
SDF_API VtDictionary GetCustomLayerData() const
Returns the CustomLayerData dictionary associated with this layer.
static SDF_API SdfPath ConvertDefaultPrimTokenToPath(const TfToken &defaultPrim)
Converts the given defaultPrim token into a prim path.
SDF_API bool HasCustomLayerData() const
Returns true if CustomLayerData is authored on the layer.
SDF_API void RemovePrimIfInert(SdfPrimSpecHandle prim)
Removes scene description that does not affect the scene in the layer namespace beginning with prim.
static SDF_API 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.
SDF_API void SetRootPrims(const SdfPrimSpecHandleVector &rootPrims)
Sets a new vector of root prims.
SDF_API void SetColorManagementSystem(const TfToken &cms)
Sets the color management system used to interpret the color configuration asset-path authored this l...
SDF_API SdfLayerOffsetVector GetSubLayerOffsets() const
Returns the layer offsets for all the subLayer paths.
std::function< void(const SdfPath &)> TraversalFunction
Callback function for Traverse.
Definition layer.h:769
SDF_API size_t GetNumSubLayerPaths() const
Returns the number of sublayer paths (and offsets).
SDF_API bool HasDefaultPrim()
Return true if the default prim metadata is set in this layer.
SDF_API SdfPrimSpecHandle GetPseudoRoot() const
Returns the layer's pseudo-root prim.
SDF_API std::string GetDocumentation() const
Returns the documentation string for this layer.
SDF_API const FileFormatArguments & GetFileFormatArguments() const
Returns the file format-specific arguments used during the construction of this layer.
SDF_API void ClearStartTimeCode()
Clear the startTimeCode opinion.
SDF_API bool UpdateExternalReference(const std::string &oldAssetPath, const std::string &newAssetPath=std::string())
SDF_API bool HasEndTimeCode() const
Returns true if the layer has an endTimeCode opinion.
SDF_API const std::string & GetRealPath() const
Returns the resolved path for this layer.
SDF_API void RemovePropertyIfHasOnlyRequiredFields(SdfPropertySpecHandle prop)
Removes prop if it has only required fields (i.e.
SDF_API bool PermissionToSave() const
Returns true if the caller is allowed to save the layer to its existing fileName and false otherwise.
SDF_API bool HasFieldDictKey(const SdfPath &path, const TfToken &fieldName, const TfToken &keyPath, VtValue *value=NULL) const
Return whether a value exists for the given path and fieldName and keyPath.
SDF_API double GetFramesPerSecond() const
Returns the layer's frames per second.
SDF_API SdfSpecHandle GetObjectAtPath(const SdfPath &path)
Returns the object at the given path.
SDF_API SdfLayerOffset GetSubLayerOffset(int index) const
Returns the layer offset for the subLayer path at the given index.
std::type_info const & GetFieldTypeid(const SdfPath &path, const TfToken &name) const
Return the type of the value for name on spec path.
Definition layer.h:636
SDF_API bool HasColorManagementSystem() const
Returns true if colorManagementSystem metadata is set in this layer.
SDF_API bool HasField(const SdfPath &path, const TfToken &fieldName, VtValue *value=NULL) const
Return whether a value exists for the given path and fieldName.
SDF_API VtValue GetField(const SdfPath &path, const TfToken &fieldName) const
Return the value for the given path and fieldName.
SDF_API bool IsDetached() const
Returns true if this layer is detached from its serialized data store, false otherwise.
SDF_API SdfPrimSpecHandle GetPrimAtPath(const SdfPath &path)
Returns the prim at the given path.
SDF_API void RemoveFromRootPrimOrder(const TfToken &name)
Removes a root prim name from the root prim order.
SDF_API bool PermissionToEdit() const
Returns true if the caller is allowed to modify the layer and false otherwise.
SDF_API VtDictionary GetExpressionVariables() const
Returns the expression variables dictionary authored on this layer.
SDF_API void SetRootPrimOrder(const std::vector< TfToken > &names)
Given a list of (possible sparse) prim names, authors a reorder rootPrims statement for this prim.
SDF_API void ClearFramesPerSecond()
Clear the framesPerSecond opinion.
static SDF_API const DetachedLayerRules & GetDetachedLayerRules()
Returns the current rules for the detached layer set.
static SDF_API TfToken ConvertDefaultPrimPathToToken(const SdfPath &primPath)
Converts the path primPath into a token value that can be used to set the default prim metadata for t...
SDF_API SdfPath GetDefaultPrimAsPath() const
Return this layer's default prim metadata interpreted as an absolute prim path regardless of whether ...
SDF_API void UpdateAssetInfo()
Update layer asset information.
SDF_API bool HasStartTimeCode() const
Returns true if the layer has a startTimeCode opinion.
static SDF_API SdfLayerRefPtr CreateAnonymous(const std::string &tag=std::string(), const FileFormatArguments &args=FileFormatArguments())
Creates a new anonymous layer with an optional tag.
SDF_API SdfPropertySpecHandle GetPropertyAtPath(const SdfPath &path)
Returns a property at the given path.
SDF_API void ClearRelocates()
Clears the layer relocates opinion in the layer's metadata.
SDF_API void ClearColorConfiguration()
Clears the color configuration metadata authored in this layer.
SDF_API double GetTimeCodesPerSecond() const
Returns the layer's timeCodes per second.
SDF_API bool IsAnonymous() const
Returns true if this layer is an anonymous layer.
SDF_API const VtValue & GetAssetInfo() const
Returns resolve information from the last time the layer identifier was resolved.
SDF_API SdfAssetPath GetColorConfiguration() const
Returns the color configuration asset-path for this layer.
SDF_API void SetRelocates(const SdfRelocates &relocates)
Set the entire list of namespace relocations specified on this layer to relocates.
SDF_API bool Apply(const SdfBatchNamespaceEdit &)
Performs a batch of namespace edits.
SDF_API std::set< std::string > GetExternalReferences() const
SDF_API bool ExportToString(std::string *result) const
Writes this layer to the given string.
SDF_API void Clear()
Clears the layer of all content.
SDF_API void SetColorConfiguration(const SdfAssetPath &colorConfiguration)
Sets the color configuration asset-path for this layer.
SDF_API std::string GetFileExtension() const
Returns the file extension to use for this layer.
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 void SetOwner(const std::string &owner)
Sets the layer's owner.
SDF_API RootPrimsView GetRootPrims() const
Returns a vector of the layer's root prims.
SDF_API void SetExpressionVariables(const VtDictionary &expressionVars)
Sets the expression variables dictionary for this layer.
SDF_API TfToken GetDefaultPrim() const
Return the defaultPrim metadata for this layer.
SDF_API SdfLayerHints GetHints() const
Return hints about the layer's current contents.
SDF_API void SetDocumentation(const std::string &documentation)
Sets the documentation string for this layer.
static SDF_API SdfLayerRefPtr FindOrOpen(const std::string &identifier, const FileFormatArguments &args=FileFormatArguments())
Return an existing layer with the given identifier and args, or else load it.
SDF_API std::string GetComment() const
Returns the comment string for this layer.
static SDF_API bool ReloadLayers(const std::set< SdfLayerHandle > &layers, bool force=false)
Reloads the specified layers.
SDF_API void RemoveRootPrim(const SdfPrimSpecHandle &prim)
Remove a root prim.
SDF_API bool HasExpressionVariables() const
Returns true if expression variables are authored on this layer.
SDF_API void ClearExpressionVariables()
Clears the expression variables dictionary authored on this layer.
SDF_API SdfChangeList CreateDiff(const SdfLayerHandle &layer, bool processPropertyFields=true) const
Returns a SdfChangeList containing the minimal edits that would be needed to transform this layer to ...
SDF_API const std::type_info & QueryTimeSampleTypeid(const SdfPath &path, double time) const
If there is a time sample authored at time, return its value's typeid(), otherwise return typeid(void...
T GetFieldAs(const SdfPath &path, const TfToken &fieldName, const T &defaultValue=T()) const
Return the value for the given path and fieldName.
Definition layer.h:683
SDF_API bool InsertRootPrim(const SdfPrimSpecHandle &prim, int index=-1)
Adds a new root prim at the given index.
SDF_API void SetEndTimeCode(double endTimeCode)
Sets the layer's end timeCode.
static SDF_API SdfLayerRefPtr CreateNew(const std::string &identifier, const FileFormatArguments &args=FileFormatArguments())
Creates a new empty layer with the given identifier.
SDF_API bool Reload(bool force=false)
Reloads the layer from its persistent representation.
SDF_API void ClearColorManagementSystem()
Clears the 'colorManagementSystem' metadata authored in this layer.
SDF_API void InsertSubLayerPath(const std::string &path, int index=-1)
Inserts new sublayer path at the given index.
SDF_API const SdfFileFormatConstPtr & GetFileFormat() const
Returns the file format used by this layer.
void SetField(const SdfPath &path, const TfToken &fieldName, const T &val)
Set the value of the given path and fieldName.
Definition layer.h:707
SDF_API void SetMuted(bool muted)
Mutes the current layer if muted is true, and unmutes it otherwise.
SDF_API void SetStateDelegate(const SdfLayerStateDelegateBaseRefPtr &delegate)
Sets the state delegate used to manage this layer's authoring state.
SDF_API void ApplyRootPrimOrder(std::vector< TfToken > *vec) const
Reorders the given list of prim names according to the reorder rootPrims statement for this layer.
SDF_API const std::string & GetAssetName() const
Returns the asset name associated with this layer.
SDF_API SdfLayerStateDelegateBasePtr GetStateDelegate() const
Returns the state delegate used to manage this layer's authoring state.
SDF_API void ClearDefaultPrim()
Clear the default prim metadata for this layer.
SDF_API bool HasColorConfiguration() const
Returns true if color configuration metadata is set in this layer.
static SDF_API std::set< std::string > GetMutedLayers()
Returns the set of muted layer paths.
SDF_API double GetStartTimeCode() const
Returns the layer's start timeCode.
SDF_API bool HasTimeCodesPerSecond() const
Returns true if the layer has a timeCodesPerSecond opinion.
SDF_API void SetSubLayerPaths(const std::vector< std::string > &newPaths)
Sets the paths of the layer's sublayers.
SDF_API std::string GetDisplayName() const
Returns the layer's display name.
SDF_API bool GetPreviousTimeSampleForPath(const SdfPath &path, double time, double *tPrevious) const
Returns the previous time sample authored just before the querying time.
static SDF_API SdfLayerHandle Find(const std::string &identifier, const FileFormatArguments &args=FileFormatArguments())
Return an existing layer with the given identifier and args.
SDF_API void SetTimeCodesPerSecond(double timeCodesPerSecond)
Sets the layer's timeCodes per second.
SDF_API void SetComment(const std::string &comment)
Sets the comment string for this layer.
SDF_API void RemoveSubLayerPath(int index)
Removes sublayer path at the given index.
SDF_API std::string ComputeAbsolutePath(const std::string &assetPath) const
Returns the path to the asset specified by assetPath using this layer to anchor the path if necessary...
SDF_API void SetDefaultPrim(const TfToken &name)
Set the default prim metadata for this layer.
SDF_API SdfAttributeSpecHandle GetAttributeAtPath(const SdfPath &path)
Returns an attribute at the given path.
SDF_API void ClearFramePrecision()
Clear the framePrecision opinion.
SDF_API VtValue GetFieldDictValueByKey(const SdfPath &path, const TfToken &fieldName, const TfToken &keyPath) const
Return the value for the given path and fieldName at keyPath.
static SDF_API std::pair< std::string, std::string > SplitIdentifier(const std::string &identifier)
Splits the given layer identifier and returns its constituent layer path and arguments as a pair of s...
SDF_API bool Save(bool force=false) const
Returns true if successful, false if an error occurred.
bool HasFieldDictKey(const SdfPath &path, const TfToken &name, const TfToken &keyPath, T *value) const
Returns true if the object has a non-empty value with name name and keyPath and type T.
Definition layer.h:660
static SDF_API void SetDetachedLayerRules(const DetachedLayerRules &mask)
Sets the rules specifying detached layers.
SDF_API std::set< std::string > GetExternalAssetDependencies() const
Returns a set of resolved paths to all external asset dependencies the layer needs to generate its co...
SDF_API void SetStartTimeCode(double startTimecode)
Sets the layer's start timeCode.
SDF_API void RemoveInertSceneDescription()
Removes all scene description in this layer that does not affect the scene.
std::map< std::string, std::string > FileFormatArguments
Type for specifying additional file format-specific arguments to layer API.
Definition layer.h:107
static SDF_API SdfLayerRefPtr FindOrOpenRelativeToLayer(const SdfLayerHandle &anchor, const std::string &identifier, const FileFormatArguments &args=FileFormatArguments())
Return an existing layer with the given identifier and args, or else load it.
SDF_API SdfSpecType GetSpecType(const SdfPath &path) const
Return the spec type for path.
SDF_API void TransferContent(const SdfLayerHandle &layer)
Copies the content of the given layer into this layer.
static SDF_API bool IsIncludedByDetachedLayerRules(const std::string &identifier)
Returns whether the given layer identifier is included in the current rules for the detached layer se...
SDF_API const std::string & GetVersion() const
Returns the asset system version of this layer.
static SDF_API std::string GetDisplayNameFromIdentifier(const std::string &identifier)
Returns the display name for the given identifier, using the same rules as GetDisplayName.
SDF_API bool Export(const std::string &filename, const std::string &comment=std::string(), const FileFormatArguments &args=FileFormatArguments()) const
Exports this layer to a file.
SDF_API void SetHasOwnedSubLayers(bool)
Sets whether the layer's sublayers are expected to have owners.
SDF_API std::string GetSessionOwner() const
Returns the layer's session owner.
SDF_API void EraseFieldDictValueByKey(const SdfPath &path, const TfToken &fieldName, const TfToken &keyPath)
Remove the field at path and fieldName and keyPath, if one exists.
SdfLayer(const SdfLayer &)=delete
Noncopyable.
SDF_API void SetSubLayerOffset(const SdfLayerOffset &offset, int index)
Sets the layer offset for the subLayer path at the given index.
static SDF_API SdfLayerRefPtr New(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.
SDF_API SdfRelationshipSpecHandle GetRelationshipAtPath(const SdfPath &path)
Returns a relationship at the given path.
SDF_API void ClearOwner()
Clear the owner opinion.
SDF_API bool HasRelocates() const
Returns true if this layer's metadata has any relocates opinion, including that there should be no re...
Represents a time offset and scale between layers.
Definition layerOffset.h:44
Maintains authoring state information for an associated layer.
Represents a single list of list editing operations.
Definition listProxy.h:37
A path value used to locate objects in layers or scenegraphs.
Definition path.h:281
Base class for SdfAttributeSpec and SdfRelationshipSpec.
Class defining various attributes for a field.
Definition schema.h:56
Generic class that provides information about scene description fields but doesn't actually provide a...
Definition schema.h:45
Base class for all Sdf spec classes.
Definition spec.h:33
Enable a concrete base class for use with TfRefPtr.
Definition refBase.h:56
Token for efficient comparison, assignment, and hashing of known strings.
Definition token.h:71
Enable a concrete base class for use with TfWeakPtr.
Definition weakBase.h:124
A map with string keys and VtValue values.
Definition dictionary.h:52
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition value.h:90
A work dispatcher runs concurrent tasks.
Definition dispatcher.h:228
Standard pointer typedefs.
#define TF_DECLARE_WEAK_PTRS(type)
Define standard weak pointer types.
Definition declarePtrs.h:45
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition declarePtrs.h:72
std::vector< SdfNamespaceEditDetail > SdfNamespaceEditDetailVector
A sequence of SdfNamespaceEditDetail.
Result
Validity of an edit.
Basic Sdf data types.
SdfSpecType
An enum that specifies the type of an object.
Definition types.h:71
std::vector< SdfRelocate > SdfRelocates
A vector of relocation source path to target path pairs.
Definition types.h:277