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
1071 SDF_API
1073
1075 SDF_API
1077
1079 SDF_API
1081
1084 SDF_API
1086
1090 SDF_API
1091 void SetExpressionVariables(const VtDictionary& expressionVars);
1092
1094 SDF_API
1096
1098 SDF_API
1100
1104
1105 // Type for root prims view.
1107
1109 SDF_API
1111
1116 SDF_API
1117 void SetRootPrims(const SdfPrimSpecHandleVector &rootPrims);
1118
1124 SDF_API
1125 bool InsertRootPrim(const SdfPrimSpecHandle &prim, int index = -1);
1126
1128 SDF_API
1129 void RemoveRootPrim(const SdfPrimSpecHandle &prim);
1130
1133 SDF_API
1135
1148 SDF_API
1149 void RemovePrimIfInert(SdfPrimSpecHandle prim);
1150
1157 SDF_API
1158 void RemovePropertyIfHasOnlyRequiredFields(SdfPropertySpecHandle prop);
1159
1165 SDF_API
1167
1172 SDF_API
1174
1183 SDF_API
1184 void SetRootPrimOrder(const std::vector<TfToken>& names);
1185
1188 SDF_API
1189 void InsertInRootPrimOrder(const TfToken &name, int index = -1);
1190
1192 SDF_API
1194
1196 SDF_API
1198
1204 SDF_API
1205 void ApplyRootPrimOrder(std::vector<TfToken> *vec) const;
1206
1210
1223 SDF_API
1225
1227 SDF_API
1228 void SetSubLayerPaths(const std::vector<std::string>& newPaths);
1229
1231 SDF_API
1232 size_t GetNumSubLayerPaths() const;
1233
1237 SDF_API
1238 void InsertSubLayerPath(const std::string& path, int index = -1);
1239
1241 SDF_API
1242 void RemoveSubLayerPath(int index);
1243
1245 SDF_API
1246 SdfLayerOffsetVector GetSubLayerOffsets() const;
1247
1249 SDF_API
1251
1253 SDF_API
1254 void SetSubLayerOffset(const SdfLayerOffset& offset, int index);
1255
1259
1268 SDF_API
1270
1273 SDF_API
1274 void SetRelocates(const SdfRelocates& relocates);
1275
1280 SDF_API
1281 bool HasRelocates() const;
1282
1284 SDF_API
1286
1288
1309
1326 {
1327 public:
1331
1334 {
1335 _includeAll = true;
1336 _include.clear();
1337 return *this;
1338 }
1339
1342 SDF_API
1343 DetachedLayerRules& Include(const std::vector<std::string>& patterns);
1344
1347 SDF_API
1348 DetachedLayerRules& Exclude(const std::vector<std::string>& patterns);
1349
1350 bool IncludedAll() const { return _includeAll; }
1351 const std::vector<std::string>& GetIncluded() const { return _include; }
1352 const std::vector<std::string>& GetExcluded() const { return _exclude; }
1353
1361 SDF_API
1362 bool IsIncluded(const std::string& identifier) const;
1363
1364 private:
1365 friend class SdfLayer;
1366
1367 std::vector<std::string> _include;
1368 std::vector<std::string> _exclude;
1369 bool _includeAll = false;
1370 };
1371
1394 SDF_API
1396
1398 SDF_API
1400
1404 SDF_API
1405 static bool IsIncludedByDetachedLayerRules(const std::string& identifier);
1406
1408
1411
1413 SDF_API
1414 static std::set<std::string> GetMutedLayers();
1415
1417 SDF_API
1418 bool IsMuted() const;
1419
1421 SDF_API
1422 static bool IsMuted(const std::string &path);
1423
1426 SDF_API
1427 void SetMuted(bool muted);
1428
1430 SDF_API
1431 static void AddToMutedLayers(const std::string &mutedPath);
1432
1434 SDF_API
1435 static void RemoveFromMutedLayers(const std::string &mutedPath);
1436
1440
1450 SDF_API
1451 SdfPrimSpecHandle GetPseudoRoot() const;
1452
1459 SDF_API
1460 SdfSpecHandle GetObjectAtPath(const SdfPath &path);
1461
1467 SDF_API
1468 SdfPrimSpecHandle GetPrimAtPath(const SdfPath &path);
1469
1475 SDF_API
1476 SdfPropertySpecHandle GetPropertyAtPath(const SdfPath &path);
1477
1483 SDF_API
1484 SdfAttributeSpecHandle GetAttributeAtPath(const SdfPath &path);
1485
1491 SDF_API
1492 SdfRelationshipSpecHandle GetRelationshipAtPath(const SdfPath &path);
1493
1497
1501 SDF_API
1502 bool PermissionToEdit() const;
1503
1506 SDF_API
1507 bool PermissionToSave() const;
1508
1510 SDF_API
1511 void SetPermissionToEdit(bool allow);
1512
1514 SDF_API
1515 void SetPermissionToSave(bool allow);
1516
1520
1544 SDF_API
1547 SdfNamespaceEditDetailVector* details = NULL) const;
1548
1552 SDF_API
1554
1558
1561 SDF_API
1562 SdfLayerStateDelegateBasePtr GetStateDelegate() const;
1563
1567 SDF_API
1568 void SetStateDelegate(const SdfLayerStateDelegateBaseRefPtr& delegate);
1569
1572 SDF_API
1573 bool IsDirty() const;
1574
1576
1579 SDF_API
1580 std::set<double> ListAllTimeSamples() const;
1581
1582 SDF_API
1583 std::set<double>
1584 ListTimeSamplesForPath(const SdfPath& path) const;
1585
1586 SDF_API
1587 bool GetBracketingTimeSamples(double time, double* tLower, double* tUpper);
1588
1589 SDF_API
1590 size_t GetNumTimeSamplesForPath(const SdfPath& path) const;
1591
1592 SDF_API
1593 bool GetBracketingTimeSamplesForPath(const SdfPath& path,
1594 double time,
1595 double* tLower, double* tUpper) const;
1596
1603 SDF_API
1604 bool GetPreviousTimeSampleForPath(const SdfPath& path, double time,
1605 double* tPrevious) const;
1606
1607 SDF_API
1608 bool QueryTimeSample(const SdfPath& path, double time,
1609 VtValue *value=NULL) const;
1610
1611 SDF_API
1612 bool QueryTimeSample(const SdfPath& path, double time,
1613 SdfAbstractDataValue *value) const;
1614
1615 template <class T>
1616 bool QueryTimeSample(const SdfPath& path, double time,
1617 T* data) const
1618 {
1619 if (!data) {
1620 return QueryTimeSample(path, time);
1621 }
1622
1623 SdfAbstractDataTypedValue<T> outValue(data);
1624 const bool hasValue = QueryTimeSample(
1625 path, time, static_cast<SdfAbstractDataValue *>(&outValue));
1626
1627 if (std::is_same<T, SdfValueBlock>::value) {
1628 return hasValue && outValue.isValueBlock;
1629 }
1630
1631 return hasValue && (!outValue.isValueBlock);
1632 }
1633
1636 SDF_API
1637 const std::type_info &
1638 QueryTimeSampleTypeid(const SdfPath &path, double time) const;
1639
1640 SDF_API
1641 void SetTimeSample(const SdfPath& path, double time,
1642 const VtValue & value);
1643
1644 SDF_API
1645 void SetTimeSample(const SdfPath& path, double time,
1646 const SdfAbstractDataConstValue& value);
1647
1648 template <class T>
1649 void SetTimeSample(const SdfPath& path, double time,
1650 const T& value)
1651 {
1652 const SdfAbstractDataConstTypedValue<T> inValue(&value);
1653 const SdfAbstractDataConstValue& untypedInValue = inValue;
1654 return SetTimeSample(path, time, untypedInValue);
1655 }
1656
1657 SDF_API
1658 void EraseTimeSample(const SdfPath& path, double time);
1659
1661
1662 // Debugging
1663 // @{
1664
1665 SDF_API
1666 static void DumpLayerInfo();
1667
1668 // Write this layer's SdfData to a file in a simple generic format.
1669 SDF_API
1670 bool WriteDataFile(const std::string &filename);
1671
1672 // @}
1673
1681 SDF_API
1683 const SdfLayerHandle& layer,
1684 bool processPropertyFields = true) const;
1685
1686protected:
1687 // Private constructor -- use New(), FindOrCreate(), etc.
1688 // Precondition: _layerRegistryMutex must be locked.
1689 SdfLayer(const SdfFileFormatConstPtr& fileFormat,
1690 const std::string &identifier,
1691 const std::string &realPath = std::string(),
1692 const ArAssetInfo& assetInfo = ArAssetInfo(),
1694 bool validateAuthoring = false);
1695
1696private:
1697 // Create a new layer.
1698 // Precondition: _layerRegistryMutex must be locked.
1699 static SdfLayerRefPtr _CreateNew(
1700 SdfFileFormatConstPtr fileFormat,
1701 const std::string& identifier,
1702 const FileFormatArguments& args,
1703 bool saveLayer = true);
1704
1705 static SdfLayerRefPtr _CreateNewWithFormat(
1706 const SdfFileFormatConstPtr &fileFormat,
1707 const std::string& identifier,
1708 const std::string& realPath,
1709 const ArAssetInfo& assetInfo = ArAssetInfo(),
1711
1712 static SdfLayerRefPtr _CreateAnonymousWithFormat(
1713 const SdfFileFormatConstPtr &fileFormat,
1714 const std::string& tag,
1715 const FileFormatArguments& args);
1716
1717 // Finish initializing this layer (which may have succeeded or not)
1718 // and publish the results to other threads by unlocking the mutex.
1719 // Sets _initializationWasSuccessful.
1720 void _FinishInitialization(bool success);
1721
1722 // Layers retrieved from the layer registry may still be in the
1723 // process of having their contents initialized. Other threads
1724 // retrieving layers from the registry must wait until initialization
1725 // is complete, using this method.
1726 // Returns _initializationWasSuccessful.
1727 //
1728 // Callers *must* be holding an SdfLayerRefPtr to this layer to
1729 // ensure that it is not deleted out from under them, in
1730 // case initialization fails. (This method cannot acquire the
1731 // reference itself internally without being susceptible to a race.)
1732 bool _WaitForInitializationAndCheckIfSuccessful();
1733
1734 // Returns whether or not this layer should post change
1735 // notification. This simply returns (!_GetIsLoading())
1736 bool _ShouldNotify() const;
1737
1738 // This function keeps track of the last state of IsDirty() before
1739 // updating it. It returns false if the last saved dirty state is the
1740 // same than the current state. It returns true if the state differs and
1741 // will update the 'last dirty state' to the current state. So, after
1742 // returning true, it would return false for subsequent calls until the
1743 // IsDirty() state would change again...
1744 bool _UpdateLastDirtinessState() const;
1745
1746 // Returns a handle to the spec at the given path if it exists and matches
1747 // type T.
1748 template <class T>
1749 SdfHandle<T> _GetSpecAtPath(const SdfPath& path);
1750
1751 // Returns true if a spec can be retrieved at the given path, false
1752 // otherwise. This function will return the canonicalized path to the
1753 // spec as well as the spec type.
1754 bool _CanGetSpecAtPath(const SdfPath& path,
1755 SdfPath* canonicalPath, SdfSpecType* specType) const;
1756
1760 void _InitializeFromIdentifier(
1761 const std::string &identifier,
1762 const std::string &realPath = std::string(),
1763 const std::string &fileVersion = std::string(),
1764 const ArAssetInfo& assetInfo = ArAssetInfo());
1765
1766 // Helper for computing the necessary information to lookup a layer
1767 // in the registry or open the layer.
1768 struct _FindOrOpenLayerInfo;
1769 static bool _ComputeInfoToFindOrOpenLayer(
1770 const std::string& identifier,
1772 _FindOrOpenLayerInfo* info,
1773 bool computeAssetInfo = false);
1774
1775 // Open a layer, adding an entry to the registry and releasing
1776 // the registry lock.
1777 // Precondition: _layerRegistryMutex must be locked.
1778 template <class Lock>
1779 static SdfLayerRefPtr _OpenLayerAndUnlockRegistry(
1780 Lock &lock,
1781 const _FindOrOpenLayerInfo& info,
1782 bool metadataOnly);
1783
1784 // Helper function for finding a layer with \p identifier and \p args.
1785 // \p lock must be unlocked initially and will be locked by this
1786 // function when needed. See docs for \p retryAsWriter argument on
1787 // _TryToFindLayer for details on the final state of the lock when
1788 // this function returns.
1789 template <class ScopedLock>
1790 static SdfLayerRefPtr
1791 _Find(const std::string &identifier,
1792 const FileFormatArguments &args,
1793 ScopedLock &lock, bool retryAsWriter);
1794
1795 // Helper function to try to find the layer with \p identifier and
1796 // pre-resolved path \p resolvedPath in the registry. Caller must hold
1797 // registry \p lock for reading. If \p retryAsWriter is false, lock is
1798 // released upon return. Otherwise the lock is released upon return if a
1799 // layer is found successfully. If no layer is found then the lock is
1800 // upgraded to a writer lock upon return. Note that this upgrade may not be
1801 // atomic, but this function ensures that if upon return there does not
1802 // exist a matching layer in the registry.
1803 template <class ScopedLock>
1804 static SdfLayerRefPtr
1805 _TryToFindLayer(const std::string &identifier,
1806 const ArResolvedPath &resolvedPath,
1807 ScopedLock &lock, bool retryAsWriter);
1808
1816 bool _IsInert(const SdfPath &path, bool ignoreChildren,
1817 bool requiredFieldOnlyPropertiesAreInert = false) const;
1818
1822 bool _IsInertSubtree(const SdfPath &path) const;
1823
1829 void _RemoveIfInert(const SdfSpec& spec);
1830
1835 bool _RemoveInertDFS(SdfPrimSpecHandle prim);
1836
1839 void _RemoveInertToRootmost(SdfPrimSpecHandle prim);
1840
1842 bool _ValidateAuthoring() const { return _validateAuthoring; }
1843
1845 std::string _GetMutedPath() const;
1846
1847 // If old and new asset path is given, rename all external prim
1848 // composition dependency referring to the old path.
1849 void _UpdatePrimCompositionDependencyPaths(
1850 const SdfPrimSpecHandle &parent,
1851 const std::string &oldLayerPath,
1852 const std::string &newLayerPath);
1853
1854 // Set the clean state to the current state.
1855 void _MarkCurrentStateAsClean() const;
1856
1857 // Return the field definition for \p fieldName if \p fieldName is a
1858 // required field for the spec type identified by \p path.
1859 inline SdfSchema::FieldDefinition const *
1860 _GetRequiredFieldDef(const SdfPath &path,
1861 const TfToken &fieldName,
1862 SdfSpecType specType = SdfSpecTypeUnknown) const;
1863
1864 // Return the field definition for \p fieldName if \p fieldName is a
1865 // required field for \p specType subject to \p schema.
1866 static inline SdfSchema::FieldDefinition const *
1867 _GetRequiredFieldDef(const SdfSchemaBase &schema,
1868 const TfToken &fieldName,
1869 SdfSpecType specType);
1870
1871 // Helper to list all fields on \p data at \p path subject to \p schema.
1872 static std::vector<TfToken>
1873 _ListFields(SdfSchemaBase const &schema,
1874 SdfAbstractData const &data, const SdfPath& path);
1875
1876 // Helper for HasField for \p path in \p data subject to \p schema.
1877 static inline bool
1878 _HasField(const SdfSchemaBase &schema,
1879 const SdfAbstractData &data,
1880 const SdfPath& path,
1881 const TfToken& fieldName,
1882 VtValue *value);
1883
1884 // Helper to get a field value for \p path in \p data subject to \p schema.
1885 static inline VtValue
1886 _GetField(const SdfSchemaBase &schema,
1887 const SdfAbstractData &data,
1888 const SdfPath& path,
1889 const TfToken& fieldName);
1890
1891 // Set a value.
1892 template <class T>
1893 void _SetValue(const TfToken& key, T value);
1894
1895 // Get a value.
1896 template <class T>
1897 T _GetValue(const TfToken& key) const;
1898
1899 enum _ReloadResult { _ReloadFailed, _ReloadSucceeded, _ReloadSkipped };
1900 _ReloadResult _Reload(bool force);
1901
1902 // Reads contents of asset specified by \p identifier with resolved
1903 // path \p resolvedPath into this layer.
1904 bool _Read(const std::string& identifier,
1905 const ArResolvedPath& resolvedPath,
1906 bool metadataOnly);
1907
1908 // Saves this layer if it is dirty or the layer doesn't already exist
1909 // on disk. If \p force is true, the layer will be written out
1910 // regardless of those conditions.
1911 bool _Save(bool force) const;
1912
1913 // Helper for Save and Export, checks whether or not writing to \p
1914 // newFileName with \p format is supported and issues diagnostics and
1915 // returns false if not.
1916 bool _CheckFormatWritability(bool isSave,
1917 SdfFileFormatConstPtr format,
1918 const std::string &newFileName) const;
1919
1920 // Swap contents of _data and data. This operation does not register
1921 // inverses or emit change notification.
1922 void _SwapData(SdfAbstractDataRefPtr &data);
1923
1924 // Set _data to \p newData and send coarse DidReplaceLayerContent
1925 // invalidation notice.
1926 void _AdoptData(const SdfAbstractDataRefPtr &newData);
1927
1928 // Helper function which will process incoming data to this layer in a
1929 // generic way.
1930 // If \p processPropertyFields is false, this method will not
1931 // consider property spec fields. In some cases, this can avoid expensive
1932 // operations which would pull large amounts of data.
1933 template<typename DeleteSpecFunc, typename CreateSpecFunc,
1934 typename GetFieldValuesFunc, typename SetFieldFunc,
1935 typename ErrorFunc>
1936 void _ProcessIncomingData(const SdfAbstractDataPtr &newData,
1937 const SdfSchemaBase *newDataSchema,
1938 bool processPropertyFields,
1939 const DeleteSpecFunc &deleteSpecFunc,
1940 const CreateSpecFunc &createSpecFunc,
1941 const GetFieldValuesFunc &getFieldValuesFunc,
1942 const SetFieldFunc &setFieldFunc,
1943 const ErrorFunc &errorFunc) const;
1944
1945 // Set _data to match data, calling other primitive setter methods to
1946 // provide fine-grained inverses and notification. If \p data might adhere
1947 // to a different schema than this layer's, pass a pointer to it as \p
1948 // newDataSchema. In this case, check to see if fields from \p data are
1949 // known to this layer's schema, and if not, omit them and issue a TfError
1950 // with SdfAuthoringErrorUnrecognizedFields, but continue to set all other
1951 // known fields.
1952 void _SetData(const SdfAbstractDataPtr &newData,
1953 const SdfSchemaBase *newDataSchema=nullptr);
1954
1955 // Returns const handle to _data.
1956 SdfAbstractDataConstPtr _GetData() const;
1957
1958 // Returns a new SdfAbstractData object for this layer.
1959 SdfAbstractDataRefPtr _CreateData() const;
1960
1961 // Inverse primitive for setting a single field. The previous value for the
1962 // field may be given via \p oldValue. If \p oldValue is non-nullptr, the
1963 // VtValue it points to will be moved-from after the function completes. If
1964 // \p oldValue is nullptr, the old field value will be retrieved
1965 // automatically.
1966 template <class T>
1967 void _PrimSetField(const SdfPath& path,
1968 const TfToken& fieldName,
1969 const T& value,
1970 VtValue *oldValue = nullptr,
1971 bool useDelegate = true);
1972
1973 // Inverse primitive for setting a single key in a dict-valued field. The
1974 // previous dictionary value for the field (*not* the individual entry) may
1975 // be supplied via \p oldValue. If \p oldValue is non-nullptr, the VtValue
1976 // it points to will be moved-from after the function completes. If \p
1977 // oldValue is nullptr, the old field value will be retrieved automatically.
1978 template <class T>
1979 void _PrimSetFieldDictValueByKey(const SdfPath& path,
1980 const TfToken& fieldName,
1981 const TfToken& keyPath,
1982 const T& value,
1983 VtValue *oldValue = nullptr,
1984 bool useDelegate = true);
1985
1986 // Primitive for appending a child to the list of children.
1987 template <class T>
1988 void _PrimPushChild(const SdfPath& parentPath,
1989 const TfToken& fieldName,
1990 const T& value,
1991 bool useDelegate = true);
1992 template <class T>
1993 void _PrimPopChild(const SdfPath& parentPath,
1994 const TfToken& fieldName,
1995 bool useDelegate = true);
1996
1997 // Move all the fields at all paths at or below \a oldPath to be
1998 // at a corresponding location at or below \a newPath. This does
1999 // not update the children fields of the parents of these paths.
2000 bool _MoveSpec(const SdfPath &oldPath, const SdfPath &newPath);
2001
2002 // Inverse primitive for moving a spec.
2003 void _PrimMoveSpec(const SdfPath &oldPath, const SdfPath &newPath,
2004 bool useDelegate = true);
2005
2006 // Create a new spec of type \p specType at \p path.
2007 // Returns true if spec was successfully created, false otherwise.
2008 bool _CreateSpec(const SdfPath& path, SdfSpecType specType, bool inert);
2009
2010 // Delete all the fields at or below the specified path. This does
2011 // not update the children field of the parent of \a path.
2012 bool _DeleteSpec(const SdfPath &path);
2013
2014 // Inverse primitive for deleting a spec.
2015 void _PrimCreateSpec(const SdfPath &path, SdfSpecType specType, bool inert,
2016 bool useDelegate = true);
2017
2018 // Inverse primitive for deleting a spec.
2019 void _PrimDeleteSpec(const SdfPath &path, bool inert,
2020 bool useDelegate = true);
2021
2022 // Inverse primitive for setting time samples.
2023 template <class T>
2024 void _PrimSetTimeSample(const SdfPath& path, double time,
2025 const T& value,
2026 bool useDelegate = true);
2027
2028 // Helper method for Traverse. Visits the children of \a path using the
2029 // specified \a ChildPolicy.
2030 template <typename ChildPolicy>
2031 void _TraverseChildren(const SdfPath &path, const TraversalFunction &func);
2032
2033private:
2034 SdfLayerHandle _self;
2035
2036 // File format and arguments for this layer.
2037 SdfFileFormatConstPtr _fileFormat;
2038 FileFormatArguments _fileFormatArgs;
2039
2040 // Cached reference to the _fileFormat's schema -- we need access to this to
2041 // be as fast as possible since we look at it on every SetField(), for
2042 // example.
2043 const SdfSchemaBase &_schema;
2044
2045 // Registry of Sdf Identities
2046 mutable Sdf_IdentityRegistry _idRegistry;
2047
2048 // The underlying SdfData which stores all the data in the layer.
2049 SdfAbstractDataRefPtr _data;
2050
2051 // The state delegate for this layer.
2052 SdfLayerStateDelegateBaseRefPtr _stateDelegate;
2053
2054 // Dispatcher used in layer initialization, letting waiters participate in
2055 // loading instead of just busy-waiting.
2056 WorkDispatcher _initDispatcher;
2057
2058 // Atomic variable protecting layer initialization -- the interval between
2059 // adding a layer to the layer registry and finishing the process of
2060 // initializing its contents, at which point we can truly publish the layer
2061 // for consumption by concurrent threads. We add the layer to the registry
2062 // before initialization completes so that other threads can discover and
2063 // wait for it to finish initializing.
2064 std::atomic<bool> _initializationComplete;
2065
2066 // This is an optional<bool> that is only set once initialization
2067 // is complete, before _initializationComplete is set.
2068 std::optional<bool> _initializationWasSuccessful;
2069
2070 // remembers the last 'IsDirty' state.
2071 mutable bool _lastDirtyState;
2072
2073 // Asset information for this layer.
2074 std::unique_ptr<Sdf_AssetInfo> _assetInfo;
2075
2076 // Modification timestamp of the backing file asset when last read.
2077 mutable VtValue _assetModificationTime;
2078
2079 // All external asset dependencies, with their modification timestamps, of
2080 // the layer when last read.
2081 mutable VtDictionary _externalAssetModificationTimes;
2082
2083 // Mutable revision number for cache invalidation.
2084 mutable size_t _mutedLayersRevisionCache;
2085
2086 // Cache of whether or not this layer is muted. Only valid if
2087 // _mutedLayersRevisionCache is up-to-date with the global revision number.
2088 mutable bool _isMutedCache;
2089
2090 // Layer permission bits.
2091 bool _permissionToEdit;
2092 bool _permissionToSave;
2093
2094 // Whether layer edits are validated.
2095 bool _validateAuthoring;
2096
2097 // Layer hints as of the most recent save operation.
2098 mutable SdfLayerHints _hints;
2099
2100 // Allow access to _ValidateAuthoring() and _IsInert().
2101 friend class SdfSpec;
2102 friend class SdfPropertySpec;
2103 friend class SdfAttributeSpec;
2104
2105 friend class Sdf_ChangeManager;
2106
2107 // Allow access to _CreateSpec and _DeleteSpec and _MoveSpec
2108 template <class ChildPolicy> friend class Sdf_ChildrenUtils;
2109
2110 // Give the file format access to our data. Limit breaking encapsulation
2111 // to the base SdFileFormat class so we don't have to friend every
2112 // implementation here.
2113 friend class SdfFileFormat;
2114
2115 // Give layer state delegates access to our data as well as to
2116 // the various _Prim functions.
2117 friend class SdfLayerStateDelegateBase;
2118};
2119
2120PXR_NAMESPACE_CLOSE_SCOPE
2121
2122#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:1326
DetachedLayerRules & IncludeAll()
Include all layers in the detached layer set.
Definition layer.h:1333
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: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