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
319 SDF_API
320 bool Save(bool force = false) const;
321
334 SDF_API
335 bool Export(const std::string& filename,
336 const std::string& comment = std::string(),
337 const FileFormatArguments& args = FileFormatArguments()) const;
338
343 SDF_API
344 bool ExportToString(std::string* result) const;
345
349 SDF_API
350 bool ImportFromString(const std::string &string);
351
359 SDF_API
360 void Clear();
361
383 SDF_API
384 bool Reload(bool force = false);
385
392 SDF_API
393 static bool ReloadLayers(const std::set<SdfLayerHandle>& layers,
394 bool force = false);
395
401 SDF_API
402 bool Import(const std::string &layerPath);
403
407
410 SDF_API
411 std::set<std::string> GetExternalReferences() const;
412
415 SDF_API
417 const std::string &oldAssetPath,
418 const std::string &newAssetPath=std::string());
419
427 SDF_API
428 std::set<std::string> GetCompositionAssetDependencies() const;
429
439 SDF_API
441 const std::string &oldAssetPath,
442 const std::string &newAssetPath=std::string());
443
452 SDF_API
453 std::set<std::string> GetExternalAssetDependencies() const;
454
474
477 SDF_API
478 static bool SplitIdentifier(
479 const std::string& identifier,
480 std::string* layerPath,
481 FileFormatArguments* arguments);
482
488 SDF_API
489 static std::pair<std::string, std::string> SplitIdentifier(
490 const std::string& identifier);
491
493 SDF_API
494 static std::string CreateIdentifier(
495 const std::string& layerPath,
496 const FileFormatArguments& arguments);
497
499 SDF_API
500 const std::string& GetIdentifier() const;
501
530 SDF_API
531 void SetIdentifier(const std::string& identifier);
532
540 SDF_API
542
546 SDF_API
547 std::string GetDisplayName() const;
548
551 SDF_API
553
556 SDF_API
557 const std::string& GetRealPath() const;
558
563 SDF_API
564 std::string GetFileExtension() const;
565
571 SDF_API
572 const std::string& GetVersion() const;
573
578 SDF_API
579 const std::string& GetRepositoryPath() const;
580
582 SDF_API
583 const std::string& GetAssetName() const;
584
587 SDF_API
588 const VtValue& GetAssetInfo() const;
589
605 SDF_API
606 std::string ComputeAbsolutePath(const std::string& assetPath) const;
607
609
620
623 SDF_API
624 SdfSpecType GetSpecType(const SdfPath& path) const;
625
627 SDF_API
628 bool HasSpec(const SdfPath& path) const;
629
631 SDF_API
632 std::vector<TfToken> ListFields(const SdfPath& path) const;
633
636 SDF_API
637 bool HasField(const SdfPath& path, const TfToken& fieldName,
638 VtValue *value=NULL) const;
639 SDF_API
640 bool HasField(const SdfPath& path, const TfToken& fieldName,
641 SdfAbstractDataValue *value) const;
642
646 template <class T>
647 bool HasField(const SdfPath& path, const TfToken &name,
648 T* value) const
649 {
650 if (!value) {
651 return HasField(path, name, static_cast<VtValue *>(NULL));
652 }
653
654 SdfAbstractDataTypedValue<T> outValue(value);
655 const bool hasValue = HasField(
656 path, name, static_cast<SdfAbstractDataValue *>(&outValue));
657
658 if (std::is_same<T, SdfValueBlock>::value) {
659 return hasValue && outValue.isValueBlock;
660 }
661
662 return hasValue && (!outValue.isValueBlock);
663 }
664
667 std::type_info const &GetFieldTypeid(
668 const SdfPath &path, const TfToken &name) const {
669 return _data->GetTypeid(path, name);
670 }
671
675 SDF_API
676 bool HasFieldDictKey(const SdfPath& path,
677 const TfToken &fieldName,
678 const TfToken &keyPath,
679 VtValue *value=NULL) const;
680 SDF_API
681 bool HasFieldDictKey(const SdfPath& path,
682 const TfToken &fieldName,
683 const TfToken &keyPath,
684 SdfAbstractDataValue *value) const;
685
690 template <class T>
691 bool HasFieldDictKey(const SdfPath& path, const TfToken &name,
692 const TfToken &keyPath, T* value) const
693 {
694 if (!value) {
695 return HasFieldDictKey(path, name, keyPath,
696 static_cast<VtValue *>(NULL));
697 }
698
699 SdfAbstractDataTypedValue<T> outValue(value);
700 return HasFieldDictKey(path, name, keyPath,
701 static_cast<SdfAbstractDataValue *>(&outValue));
702 }
703
704
707 SDF_API
709 const TfToken& fieldName) const;
710
713 template <class T>
714 inline T GetFieldAs(const SdfPath& path,
715 const TfToken& fieldName, const T& defaultValue = T()) const
716 {
717 return _data->GetAs<T>(path, fieldName, defaultValue);
718 }
719
723 SDF_API
725 const TfToken& fieldName,
726 const TfToken& keyPath) const;
727
729 SDF_API
730 void SetField(const SdfPath& path, const TfToken& fieldName,
731 const VtValue& value);
732 SDF_API
733 void SetField(const SdfPath& path, const TfToken& fieldName,
734 const SdfAbstractDataConstValue& value);
735
737 template <class T>
738 void SetField(const SdfPath& path, const TfToken& fieldName,
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 a
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 SetField(path, fieldName, VtValue(val));
749 }
750
753 SDF_API
755 const TfToken& fieldName,
756 const TfToken& keyPath,
757 const VtValue& value);
758 SDF_API
759 void SetFieldDictValueByKey(const SdfPath& path,
760 const TfToken& fieldName,
761 const TfToken& keyPath,
762 const SdfAbstractDataConstValue& value);
763
766 template <class T>
768 const TfToken& fieldName,
769 const TfToken& keyPath,
770 const T& val)
771 {
772 // Ideally, this would make use of the SdfAbstractDataConstValue
773 // API to avoid unnecessarily copying the value into a VtValue.
774 // However, Sdf needs to create a VtValue for change processing.
775 // If the underlying SdAbstractData implementation also needs
776 // VtValue, using the SdfAbstractDataConstValue API would cause
777 // another copy to be made. So, it's more efficient to just create
778 // the VtValue once here and push that along.
779 SetFieldDictValueByKey(path, fieldName, keyPath, VtValue(val));
780 }
781
783 SDF_API
784 void EraseField(const SdfPath& path, const TfToken& fieldName);
785
789 SDF_API
791 const TfToken& fieldName,
792 const TfToken& keyPath);
793
796
800 typedef std::function<void(const SdfPath&)> TraversalFunction;
801
802 // Traverse will perform a traversal of the scene description hierarchy
803 // rooted at \a path, calling \a func on each spec that it finds.
804 SDF_API
805 void Traverse(const SdfPath& path, const TraversalFunction& func);
806
808
811
815 SDF_API
817
819 SDF_API
820 void SetColorConfiguration(const SdfAssetPath &colorConfiguration);
821
824 SDF_API
826
829 SDF_API
831
839 SDF_API
841
844 SDF_API
846
849 SDF_API
851
854 SDF_API
856
860 SDF_API
861 std::string GetComment() const;
862
864 SDF_API
865 void SetComment(const std::string &comment);
866
872 SDF_API
874
884 SDF_API
886
893 SDF_API
894 void SetDefaultPrim(const TfToken &name);
895
898 SDF_API
900
903 SDF_API
905
913 SDF_API
915
924 SDF_API
926
930 SDF_API
931 std::string GetDocumentation() const;
932
934 SDF_API
935 void SetDocumentation(const std::string &documentation);
936
944 SDF_API
945 double GetStartTimeCode() const;
946
948 SDF_API
949 void SetStartTimeCode(double startTimecode);
950
952 SDF_API
953 bool HasStartTimeCode() const;
954
956 SDF_API
958
965 SDF_API
966 double GetEndTimeCode() const;
967
969 SDF_API
970 void SetEndTimeCode(double endTimeCode);
971
973 SDF_API
974 bool HasEndTimeCode() const;
975
977 SDF_API
979
994 SDF_API
995 double GetTimeCodesPerSecond() const;
996
998 SDF_API
999 void SetTimeCodesPerSecond(double timeCodesPerSecond);
1000
1002 SDF_API
1004
1006 SDF_API
1008
1018 SDF_API
1019 double GetFramesPerSecond() const;
1020
1022 SDF_API
1023 void SetFramesPerSecond(double framesPerSecond);
1024
1026 SDF_API
1028
1030 SDF_API
1032
1034 SDF_API
1036
1038 SDF_API
1039 void SetFramePrecision(int framePrecision);
1040
1042 SDF_API
1043 bool HasFramePrecision() const;
1044
1046 SDF_API
1048
1050 SDF_API
1051 std::string GetOwner() const;
1052
1054 SDF_API
1055 void SetOwner(const std::string& owner);
1056
1058 SDF_API
1059 bool HasOwner() const;
1060
1062 SDF_API
1064
1067 SDF_API
1068 std::string GetSessionOwner() const;
1069
1072 SDF_API
1073 void SetSessionOwner(const std::string& owner);
1074
1076 SDF_API
1077 bool HasSessionOwner() const;
1078
1079 // Clear the session owner opinion.
1080 SDF_API
1081 void ClearSessionOwner();
1082
1084 SDF_API
1086
1088 SDF_API
1090
1096 SDF_API
1098
1102 SDF_API
1104
1106 SDF_API
1108
1110 SDF_API
1112
1115 SDF_API
1117
1121 SDF_API
1122 void SetExpressionVariables(const VtDictionary& expressionVars);
1123
1125 SDF_API
1127
1129 SDF_API
1131
1135
1136 // Type for root prims view.
1138
1140 SDF_API
1142
1147 SDF_API
1148 void SetRootPrims(const SdfPrimSpecHandleVector &rootPrims);
1149
1155 SDF_API
1156 bool InsertRootPrim(const SdfPrimSpecHandle &prim, int index = -1);
1157
1159 SDF_API
1160 void RemoveRootPrim(const SdfPrimSpecHandle &prim);
1161
1164 SDF_API
1166
1179 SDF_API
1180 void RemovePrimIfInert(SdfPrimSpecHandle prim);
1181
1188 SDF_API
1189 void RemovePropertyIfHasOnlyRequiredFields(SdfPropertySpecHandle prop);
1190
1196 SDF_API
1198
1203 SDF_API
1205
1214 SDF_API
1215 void SetRootPrimOrder(const std::vector<TfToken>& names);
1216
1219 SDF_API
1220 void InsertInRootPrimOrder(const TfToken &name, int index = -1);
1221
1223 SDF_API
1225
1227 SDF_API
1229
1235 SDF_API
1236 void ApplyRootPrimOrder(std::vector<TfToken> *vec) const;
1237
1241
1254 SDF_API
1256
1258 SDF_API
1259 void SetSubLayerPaths(const std::vector<std::string>& newPaths);
1260
1262 SDF_API
1263 size_t GetNumSubLayerPaths() const;
1264
1268 SDF_API
1269 void InsertSubLayerPath(const std::string& path, int index = -1);
1270
1272 SDF_API
1273 void RemoveSubLayerPath(int index);
1274
1276 SDF_API
1277 SdfLayerOffsetVector GetSubLayerOffsets() const;
1278
1280 SDF_API
1282
1284 SDF_API
1285 void SetSubLayerOffset(const SdfLayerOffset& offset, int index);
1286
1290
1299 SDF_API
1301
1304 SDF_API
1305 void SetRelocates(const SdfRelocates& relocates);
1306
1311 SDF_API
1312 bool HasRelocates() const;
1313
1315 SDF_API
1317
1319
1340
1357 {
1358 public:
1362
1365 {
1366 _includeAll = true;
1367 _include.clear();
1368 return *this;
1369 }
1370
1373 SDF_API
1374 DetachedLayerRules& Include(const std::vector<std::string>& patterns);
1375
1378 SDF_API
1379 DetachedLayerRules& Exclude(const std::vector<std::string>& patterns);
1380
1381 bool IncludedAll() const { return _includeAll; }
1382 const std::vector<std::string>& GetIncluded() const { return _include; }
1383 const std::vector<std::string>& GetExcluded() const { return _exclude; }
1384
1392 SDF_API
1393 bool IsIncluded(const std::string& identifier) const;
1394
1395 private:
1396 friend class SdfLayer;
1397
1398 std::vector<std::string> _include;
1399 std::vector<std::string> _exclude;
1400 bool _includeAll = false;
1401 };
1402
1425 SDF_API
1427
1429 SDF_API
1431
1435 SDF_API
1436 static bool IsIncludedByDetachedLayerRules(const std::string& identifier);
1437
1439
1442
1444 SDF_API
1445 static std::set<std::string> GetMutedLayers();
1446
1448 SDF_API
1449 bool IsMuted() const;
1450
1452 SDF_API
1453 static bool IsMuted(const std::string &path);
1454
1457 SDF_API
1458 void SetMuted(bool muted);
1459
1461 SDF_API
1462 static void AddToMutedLayers(const std::string &mutedPath);
1463
1465 SDF_API
1466 static void RemoveFromMutedLayers(const std::string &mutedPath);
1467
1471
1481 SDF_API
1482 SdfPrimSpecHandle GetPseudoRoot() const;
1483
1490 SDF_API
1491 SdfSpecHandle GetObjectAtPath(const SdfPath &path);
1492
1498 SDF_API
1499 SdfPrimSpecHandle GetPrimAtPath(const SdfPath &path);
1500
1506 SDF_API
1507 SdfPropertySpecHandle GetPropertyAtPath(const SdfPath &path);
1508
1514 SDF_API
1515 SdfAttributeSpecHandle GetAttributeAtPath(const SdfPath &path);
1516
1522 SDF_API
1523 SdfRelationshipSpecHandle GetRelationshipAtPath(const SdfPath &path);
1524
1528
1532 SDF_API
1533 bool PermissionToEdit() const;
1534
1537 SDF_API
1538 bool PermissionToSave() const;
1539
1541 SDF_API
1542 void SetPermissionToEdit(bool allow);
1543
1545 SDF_API
1546 void SetPermissionToSave(bool allow);
1547
1551
1575 SDF_API
1578 SdfNamespaceEditDetailVector* details = NULL) const;
1579
1583 SDF_API
1585
1589
1592 SDF_API
1593 SdfLayerStateDelegateBasePtr GetStateDelegate() const;
1594
1598 SDF_API
1599 void SetStateDelegate(const SdfLayerStateDelegateBaseRefPtr& delegate);
1600
1603 SDF_API
1604 bool IsDirty() const;
1605
1607
1610 SDF_API
1611 std::set<double> ListAllTimeSamples() const;
1612
1613 SDF_API
1614 std::set<double>
1615 ListTimeSamplesForPath(const SdfPath& path) const;
1616
1617 SDF_API
1618 bool GetBracketingTimeSamples(double time, double* tLower, double* tUpper);
1619
1620 SDF_API
1621 size_t GetNumTimeSamplesForPath(const SdfPath& path) const;
1622
1623 SDF_API
1624 bool GetBracketingTimeSamplesForPath(const SdfPath& path,
1625 double time,
1626 double* tLower, double* tUpper) const;
1627
1634 SDF_API
1635 bool GetPreviousTimeSampleForPath(const SdfPath& path, double time,
1636 double* tPrevious) const;
1637
1638 SDF_API
1639 bool QueryTimeSample(const SdfPath& path, double time,
1640 VtValue *value=NULL) const;
1641
1642 SDF_API
1643 bool QueryTimeSample(const SdfPath& path, double time,
1644 SdfAbstractDataValue *value) const;
1645
1646 template <class T>
1647 bool QueryTimeSample(const SdfPath& path, double time,
1648 T* data) const
1649 {
1650 if (!data) {
1651 return QueryTimeSample(path, time);
1652 }
1653
1654 SdfAbstractDataTypedValue<T> outValue(data);
1655 const bool hasValue = QueryTimeSample(
1656 path, time, static_cast<SdfAbstractDataValue *>(&outValue));
1657
1658 if (std::is_same<T, SdfValueBlock>::value) {
1659 return hasValue && outValue.isValueBlock;
1660 }
1661
1662 return hasValue && (!outValue.isValueBlock);
1663 }
1664
1667 SDF_API
1668 const std::type_info &
1669 QueryTimeSampleTypeid(const SdfPath &path, double time) const;
1670
1671 SDF_API
1672 void SetTimeSample(const SdfPath& path, double time,
1673 const VtValue & value);
1674
1675 SDF_API
1676 void SetTimeSample(const SdfPath& path, double time,
1677 const SdfAbstractDataConstValue& value);
1678
1679 template <class T>
1680 void SetTimeSample(const SdfPath& path, double time,
1681 const T& value)
1682 {
1683 const SdfAbstractDataConstTypedValue<T> inValue(&value);
1684 const SdfAbstractDataConstValue& untypedInValue = inValue;
1685 return SetTimeSample(path, time, untypedInValue);
1686 }
1687
1688 SDF_API
1689 void EraseTimeSample(const SdfPath& path, double time);
1690
1692
1693 // Debugging
1694 // @{
1695
1696 SDF_API
1697 static void DumpLayerInfo();
1698
1699 // Write this layer's SdfData to a file in a simple generic format.
1700 SDF_API
1701 bool WriteDataFile(const std::string &filename);
1702
1703 // @}
1704
1712 SDF_API
1714 const SdfLayerHandle& layer,
1715 bool processPropertyFields = true) const;
1716
1717protected:
1718 // Private constructor -- use New(), FindOrCreate(), etc.
1719 // Precondition: _layerRegistryMutex must be locked.
1720 SdfLayer(const SdfFileFormatConstPtr& fileFormat,
1721 const std::string &identifier,
1722 const std::string &realPath = std::string(),
1723 const ArAssetInfo& assetInfo = ArAssetInfo(),
1725 bool validateAuthoring = false);
1726
1727private:
1728 // Create a new layer.
1729 // Precondition: _layerRegistryMutex must be locked.
1730 static SdfLayerRefPtr _CreateNew(
1731 SdfFileFormatConstPtr fileFormat,
1732 const std::string& identifier,
1733 const FileFormatArguments& args,
1734 bool saveLayer = true);
1735
1736 static SdfLayerRefPtr _CreateNewWithFormat(
1737 const SdfFileFormatConstPtr &fileFormat,
1738 const std::string& identifier,
1739 const std::string& realPath,
1740 const ArAssetInfo& assetInfo = ArAssetInfo(),
1742
1743 static SdfLayerRefPtr _CreateAnonymousWithFormat(
1744 const SdfFileFormatConstPtr &fileFormat,
1745 const std::string& tag,
1746 const FileFormatArguments& args);
1747
1748 // Finish initializing this layer (which may have succeeded or not)
1749 // and publish the results to other threads by unlocking the mutex.
1750 // Sets _initializationWasSuccessful.
1751 void _FinishInitialization(bool success);
1752
1753 // Layers retrieved from the layer registry may still be in the
1754 // process of having their contents initialized. Other threads
1755 // retrieving layers from the registry must wait until initialization
1756 // is complete, using this method.
1757 // Returns _initializationWasSuccessful.
1758 //
1759 // Callers *must* be holding an SdfLayerRefPtr to this layer to
1760 // ensure that it is not deleted out from under them, in
1761 // case initialization fails. (This method cannot acquire the
1762 // reference itself internally without being susceptible to a race.)
1763 bool _WaitForInitializationAndCheckIfSuccessful();
1764
1765 // Returns whether or not this layer should post change
1766 // notification. This simply returns (!_GetIsLoading())
1767 bool _ShouldNotify() const;
1768
1769 // This function keeps track of the last state of IsDirty() before
1770 // updating it. It returns false if the last saved dirty state is the
1771 // same than the current state. It returns true if the state differs and
1772 // will update the 'last dirty state' to the current state. So, after
1773 // returning true, it would return false for subsequent calls until the
1774 // IsDirty() state would change again...
1775 bool _UpdateLastDirtinessState() const;
1776
1777 // Returns a handle to the spec at the given path if it exists and matches
1778 // type T.
1779 template <class T>
1780 SdfHandle<T> _GetSpecAtPath(const SdfPath& path);
1781
1782 // Returns true if a spec can be retrieved at the given path, false
1783 // otherwise. This function will return the canonicalized path to the
1784 // spec as well as the spec type.
1785 bool _CanGetSpecAtPath(const SdfPath& path,
1786 SdfPath* canonicalPath, SdfSpecType* specType) const;
1787
1791 void _InitializeFromIdentifier(
1792 const std::string &identifier,
1793 const std::string &realPath = std::string(),
1794 const std::string &fileVersion = std::string(),
1795 const ArAssetInfo& assetInfo = ArAssetInfo());
1796
1797 // Helper for computing the necessary information to lookup a layer
1798 // in the registry or open the layer.
1799 struct _FindOrOpenLayerInfo;
1800 static bool _ComputeInfoToFindOrOpenLayer(
1801 const std::string& identifier,
1803 _FindOrOpenLayerInfo* info,
1804 bool computeAssetInfo = false);
1805
1806 // Open a layer, adding an entry to the registry and releasing
1807 // the registry lock.
1808 // Precondition: _layerRegistryMutex must be locked.
1809 template <class Lock>
1810 static SdfLayerRefPtr _OpenLayerAndUnlockRegistry(
1811 Lock &lock,
1812 const _FindOrOpenLayerInfo& info,
1813 bool metadataOnly);
1814
1815 // Helper function for finding a layer with \p identifier and \p args.
1816 // \p lock must be unlocked initially and will be locked by this
1817 // function when needed. See docs for \p retryAsWriter argument on
1818 // _TryToFindLayer for details on the final state of the lock when
1819 // this function returns.
1820 template <class ScopedLock>
1821 static SdfLayerRefPtr
1822 _Find(const std::string &identifier,
1823 const FileFormatArguments &args,
1824 ScopedLock &lock, bool retryAsWriter);
1825
1826 // Helper function to try to find the layer with \p identifier and
1827 // pre-resolved path \p resolvedPath in the registry. Caller must hold
1828 // registry \p lock for reading. If \p retryAsWriter is false, lock is
1829 // released upon return. Otherwise the lock is released upon return if a
1830 // layer is found successfully. If no layer is found then the lock is
1831 // upgraded to a writer lock upon return. Note that this upgrade may not be
1832 // atomic, but this function ensures that if upon return there does not
1833 // exist a matching layer in the registry.
1834 template <class ScopedLock>
1835 static SdfLayerRefPtr
1836 _TryToFindLayer(const std::string &identifier,
1837 const ArResolvedPath &resolvedPath,
1838 ScopedLock &lock, bool retryAsWriter);
1839
1847 bool _IsInert(const SdfPath &path, bool ignoreChildren,
1848 bool requiredFieldOnlyPropertiesAreInert = false) const;
1849
1853 bool _IsInertSubtree(const SdfPath &path) const;
1854
1860 void _RemoveIfInert(const SdfSpec& spec);
1861
1866 bool _RemoveInertDFS(SdfPrimSpecHandle prim);
1867
1870 void _RemoveInertToRootmost(SdfPrimSpecHandle prim);
1871
1873 bool _ValidateAuthoring() const { return _validateAuthoring; }
1874
1876 std::string _GetMutedPath() const;
1877
1878 // If old and new asset path is given, rename all external prim
1879 // composition dependency referring to the old path.
1880 void _UpdatePrimCompositionDependencyPaths(
1881 const SdfPrimSpecHandle &parent,
1882 const std::string &oldLayerPath,
1883 const std::string &newLayerPath);
1884
1885 // Set the clean state to the current state.
1886 void _MarkCurrentStateAsClean() const;
1887
1888 // Return the field definition for \p fieldName if \p fieldName is a
1889 // required field for the spec type identified by \p path.
1890 inline SdfSchema::FieldDefinition const *
1891 _GetRequiredFieldDef(const SdfPath &path,
1892 const TfToken &fieldName,
1893 SdfSpecType specType = SdfSpecTypeUnknown) const;
1894
1895 // Return the field definition for \p fieldName if \p fieldName is a
1896 // required field for \p specType subject to \p schema.
1897 static inline SdfSchema::FieldDefinition const *
1898 _GetRequiredFieldDef(const SdfSchemaBase &schema,
1899 const TfToken &fieldName,
1900 SdfSpecType specType);
1901
1902 // Helper to list all fields on \p data at \p path subject to \p schema.
1903 static std::vector<TfToken>
1904 _ListFields(SdfSchemaBase const &schema,
1905 SdfAbstractData const &data, const SdfPath& path);
1906
1907 // Helper for HasField for \p path in \p data subject to \p schema.
1908 static inline bool
1909 _HasField(const SdfSchemaBase &schema,
1910 const SdfAbstractData &data,
1911 const SdfPath& path,
1912 const TfToken& fieldName,
1913 VtValue *value);
1914
1915 // Helper to get a field value for \p path in \p data subject to \p schema.
1916 static inline VtValue
1917 _GetField(const SdfSchemaBase &schema,
1918 const SdfAbstractData &data,
1919 const SdfPath& path,
1920 const TfToken& fieldName);
1921
1922 // Set a value.
1923 template <class T>
1924 void _SetValue(const TfToken& key, T value);
1925
1926 // Get a value.
1927 template <class T>
1928 T _GetValue(const TfToken& key) const;
1929
1930 enum _ReloadResult { _ReloadFailed, _ReloadSucceeded, _ReloadSkipped };
1931 _ReloadResult _Reload(bool force);
1932
1933 // Reads contents of asset specified by \p identifier with resolved
1934 // path \p resolvedPath into this layer.
1935 bool _Read(const std::string& identifier,
1936 const ArResolvedPath& resolvedPath,
1937 bool metadataOnly);
1938
1939 // Saves this layer if it is dirty or the layer doesn't already exist
1940 // on disk. If \p force is true, the layer will be written out
1941 // regardless of those conditions.
1942 bool _Save(bool force) const;
1943
1944 // Helper for Save and Export, checks whether or not writing to \p
1945 // newFileName with \p format is supported and issues diagnostics and
1946 // returns false if not.
1947 bool _CheckFormatWritability(bool isSave,
1948 SdfFileFormatConstPtr format,
1949 const std::string &newFileName) const;
1950
1951 // Swap contents of _data and data. This operation does not register
1952 // inverses or emit change notification.
1953 void _SwapData(SdfAbstractDataRefPtr &data);
1954
1955 // Set _data to \p newData and send coarse DidReplaceLayerContent
1956 // invalidation notice.
1957 void _AdoptData(const SdfAbstractDataRefPtr &newData);
1958
1959 // Helper function which will process incoming data to this layer in a
1960 // generic way.
1961 // If \p processPropertyFields is false, this method will not
1962 // consider property spec fields. In some cases, this can avoid expensive
1963 // operations which would pull large amounts of data.
1964 template<typename DeleteSpecFunc, typename CreateSpecFunc,
1965 typename GetFieldValuesFunc, typename SetFieldFunc,
1966 typename ErrorFunc>
1967 void _ProcessIncomingData(const SdfAbstractDataPtr &newData,
1968 const SdfSchemaBase *newDataSchema,
1969 bool processPropertyFields,
1970 const DeleteSpecFunc &deleteSpecFunc,
1971 const CreateSpecFunc &createSpecFunc,
1972 const GetFieldValuesFunc &getFieldValuesFunc,
1973 const SetFieldFunc &setFieldFunc,
1974 const ErrorFunc &errorFunc) const;
1975
1976 // Set _data to match data, calling other primitive setter methods to
1977 // provide fine-grained inverses and notification. If \p data might adhere
1978 // to a different schema than this layer's, pass a pointer to it as \p
1979 // newDataSchema. In this case, check to see if fields from \p data are
1980 // known to this layer's schema, and if not, omit them and issue a TfError
1981 // with SdfAuthoringErrorUnrecognizedFields, but continue to set all other
1982 // known fields.
1983 void _SetData(const SdfAbstractDataPtr &newData,
1984 const SdfSchemaBase *newDataSchema=nullptr);
1985
1986 // Returns const handle to _data.
1987 SdfAbstractDataConstPtr _GetData() const;
1988
1989 // Returns a new SdfAbstractData object for this layer.
1990 SdfAbstractDataRefPtr _CreateData() const;
1991
1992 // Inverse primitive for setting a single field. The previous value for the
1993 // field may be given via \p oldValue. If \p oldValue is non-nullptr, the
1994 // VtValue it points to will be moved-from after the function completes. If
1995 // \p oldValue is nullptr, the old field value will be retrieved
1996 // automatically.
1997 template <class T>
1998 void _PrimSetField(const SdfPath& path,
1999 const TfToken& fieldName,
2000 const T& value,
2001 VtValue *oldValue = nullptr,
2002 bool useDelegate = true);
2003
2004 // Inverse primitive for setting a single key in a dict-valued field. The
2005 // previous dictionary value for the field (*not* the individual entry) may
2006 // be supplied via \p oldValue. If \p oldValue is non-nullptr, the VtValue
2007 // it points to will be moved-from after the function completes. If \p
2008 // oldValue is nullptr, the old field value will be retrieved automatically.
2009 template <class T>
2010 void _PrimSetFieldDictValueByKey(const SdfPath& path,
2011 const TfToken& fieldName,
2012 const TfToken& keyPath,
2013 const T& value,
2014 VtValue *oldValue = nullptr,
2015 bool useDelegate = true);
2016
2017 // Primitive for appending a child to the list of children.
2018 template <class T>
2019 void _PrimPushChild(const SdfPath& parentPath,
2020 const TfToken& fieldName,
2021 const T& value,
2022 bool useDelegate = true);
2023 template <class T>
2024 void _PrimPopChild(const SdfPath& parentPath,
2025 const TfToken& fieldName,
2026 bool useDelegate = true);
2027
2028 // Move all the fields at all paths at or below \a oldPath to be
2029 // at a corresponding location at or below \a newPath. This does
2030 // not update the children fields of the parents of these paths.
2031 bool _MoveSpec(const SdfPath &oldPath, const SdfPath &newPath);
2032
2033 // Inverse primitive for moving a spec.
2034 void _PrimMoveSpec(const SdfPath &oldPath, const SdfPath &newPath,
2035 bool useDelegate = true);
2036
2037 // Create a new spec of type \p specType at \p path.
2038 // Returns true if spec was successfully created, false otherwise.
2039 bool _CreateSpec(const SdfPath& path, SdfSpecType specType, bool inert);
2040
2041 // Delete all the fields at or below the specified path. This does
2042 // not update the children field of the parent of \a path.
2043 bool _DeleteSpec(const SdfPath &path);
2044
2045 // Inverse primitive for deleting a spec.
2046 void _PrimCreateSpec(const SdfPath &path, SdfSpecType specType, bool inert,
2047 bool useDelegate = true);
2048
2049 // Inverse primitive for deleting a spec.
2050 void _PrimDeleteSpec(const SdfPath &path, bool inert,
2051 bool useDelegate = true);
2052
2053 // Inverse primitive for setting time samples.
2054 template <class T>
2055 void _PrimSetTimeSample(const SdfPath& path, double time,
2056 const T& value,
2057 bool useDelegate = true);
2058
2059 // Helper method for Traverse. Visits the children of \a path using the
2060 // specified \a ChildPolicy.
2061 template <typename ChildPolicy>
2062 void _TraverseChildren(const SdfPath &path, const TraversalFunction &func);
2063
2064private:
2065 SdfLayerHandle _self;
2066
2067 // File format and arguments for this layer.
2068 SdfFileFormatConstPtr _fileFormat;
2069 FileFormatArguments _fileFormatArgs;
2070
2071 // Cached reference to the _fileFormat's schema -- we need access to this to
2072 // be as fast as possible since we look at it on every SetField(), for
2073 // example.
2074 const SdfSchemaBase &_schema;
2075
2076 // Registry of Sdf Identities
2077 mutable Sdf_IdentityRegistry _idRegistry;
2078
2079 // The underlying SdfData which stores all the data in the layer.
2080 SdfAbstractDataRefPtr _data;
2081
2082 // The state delegate for this layer.
2083 SdfLayerStateDelegateBaseRefPtr _stateDelegate;
2084
2085 // Dispatcher used in layer initialization, letting waiters participate in
2086 // loading instead of just busy-waiting.
2087 WorkDispatcher _initDispatcher;
2088
2089 // Atomic variable protecting layer initialization -- the interval between
2090 // adding a layer to the layer registry and finishing the process of
2091 // initializing its contents, at which point we can truly publish the layer
2092 // for consumption by concurrent threads. We add the layer to the registry
2093 // before initialization completes so that other threads can discover and
2094 // wait for it to finish initializing.
2095 std::atomic<bool> _initializationComplete;
2096
2097 // This is an optional<bool> that is only set once initialization
2098 // is complete, before _initializationComplete is set.
2099 std::optional<bool> _initializationWasSuccessful;
2100
2101 // remembers the last 'IsDirty' state.
2102 mutable bool _lastDirtyState;
2103
2104 // Asset information for this layer.
2105 std::unique_ptr<Sdf_AssetInfo> _assetInfo;
2106
2107 // Modification timestamp of the backing file asset when last read.
2108 mutable VtValue _assetModificationTime;
2109
2110 // All external asset dependencies, with their modification timestamps, of
2111 // the layer when last read.
2112 mutable VtDictionary _externalAssetModificationTimes;
2113
2114 // Mutable revision number for cache invalidation.
2115 mutable size_t _mutedLayersRevisionCache;
2116
2117 // Cache of whether or not this layer is muted. Only valid if
2118 // _mutedLayersRevisionCache is up-to-date with the global revision number.
2119 mutable bool _isMutedCache;
2120
2121 // Layer permission bits.
2122 bool _permissionToEdit;
2123 bool _permissionToSave;
2124
2125 // Whether layer edits are validated.
2126 bool _validateAuthoring;
2127
2128 // Layer hints as of the most recent save operation.
2129 mutable SdfLayerHints _hints;
2130
2131 // Allow access to _ValidateAuthoring() and _IsInert().
2132 friend class SdfSpec;
2133 friend class SdfPropertySpec;
2134 friend class SdfAttributeSpec;
2135
2136 friend class Sdf_ChangeManager;
2137
2138 // Allow access to _CreateSpec and _DeleteSpec and _MoveSpec
2139 template <class ChildPolicy> friend class Sdf_ChildrenUtils;
2140
2141 // Give the file format access to our data. Limit breaking encapsulation
2142 // to the base SdFileFormat class so we don't have to friend every
2143 // implementation here.
2144 friend class SdfFileFormat;
2145
2146 // Give layer state delegates access to our data as well as to
2147 // the various _Prim functions.
2148 friend class SdfLayerStateDelegateBase;
2149};
2150
2151PXR_NAMESPACE_CLOSE_SCOPE
2152
2153#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:1357
DetachedLayerRules & IncludeAll()
Include all layers in the detached layer set.
Definition layer.h:1364
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:647
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:767
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:800
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:667
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:714
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:738
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:691
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:57
Generic class that provides information about scene description fields but doesn't actually provide a...
Definition schema.h:46
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:81
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:73
std::vector< SdfRelocate > SdfRelocates
A vector of relocation source path to target path pairs.
Definition types.h:279