Loading...
Searching...
No Matches
layer.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the Apache License, Version 2.0 (the "Apache License")
5// with the following modification; you may not use this file except in
6// compliance with the Apache License and the following modification to it:
7// Section 6. Trademarks. is deleted and replaced with:
8//
9// 6. Trademarks. This License does not grant permission to use the trade
10// names, trademarks, service marks, or product names of the Licensor
11// and its affiliates, except as required to comply with Section 4(c) of
12// the License and to reproduce the content of the NOTICE file.
13//
14// You may obtain a copy of the Apache License at
15//
16// http://www.apache.org/licenses/LICENSE-2.0
17//
18// Unless required by applicable law or agreed to in writing, software
19// distributed under the Apache License with the above modification is
20// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21// KIND, either express or implied. See the Apache License for the specific
22// language governing permissions and limitations under the Apache License.
23//
24#ifndef PXR_USD_SDF_LAYER_H
25#define PXR_USD_SDF_LAYER_H
26
28
29#include "pxr/pxr.h"
30#include "pxr/usd/sdf/api.h"
31#include "pxr/usd/sdf/data.h"
33#include "pxr/usd/sdf/identity.h"
34#include "pxr/usd/sdf/layerHints.h"
37#include "pxr/usd/sdf/path.h"
38#include "pxr/usd/sdf/proxyTypes.h"
39#include "pxr/usd/sdf/spec.h"
40#include "pxr/usd/sdf/types.h"
41#include "pxr/usd/ar/ar.h"
45#include "pxr/base/vt/value.h"
47
48#include <boost/optional.hpp>
49
50#include <atomic>
51#include <functional>
52#include <memory>
53#include <set>
54#include <string>
55#include <vector>
56
57PXR_NAMESPACE_OPEN_SCOPE
58
61
62struct Sdf_AssetInfo;
63
99 : public TfRefBase
100 , public TfWeakBase
101{
102public:
104 SDF_API
105 virtual ~SdfLayer();
106
108 SdfLayer(const SdfLayer&) = delete;
109 SdfLayer& operator=(const SdfLayer&) = delete;
110
114
117 SDF_API const SdfSchemaBase& GetSchema() const;
118
120 SDF_API const SdfFileFormatConstPtr& GetFileFormat() const;
121
124 typedef std::map<std::string, std::string> FileFormatArguments;
125
129
135 SDF_API
136 static SdfLayerRefPtr CreateNew(const std::string &identifier,
137 const FileFormatArguments &args =
139
146 SDF_API
147 static SdfLayerRefPtr CreateNew(const SdfFileFormatConstPtr& fileFormat,
148 const std::string &identifier,
149 const FileFormatArguments &args =
151
160 SDF_API
161 static SdfLayerRefPtr New(const SdfFileFormatConstPtr& fileFormat,
162 const std::string &identifier,
163 const FileFormatArguments &args =
165
172 SDF_API
173 static SdfLayerHandle Find(
174 const std::string &identifier,
176
187 SDF_API
188 static SdfLayerHandle FindRelativeToLayer(
189 const SdfLayerHandle &anchor,
190 const std::string &identifier,
192
199 SDF_API
201 const std::string &identifier,
203
214 SDF_API
216 const SdfLayerHandle &anchor,
217 const std::string &identifier,
219
233 SDF_API
235 const std::string &layerPath,
236 bool metadataOnly = false,
237 const std::string& tag = std::string());
238
240 SDF_API
241 SdfDataRefPtr GetMetadata() const;
242
246 SDF_API
248
250 SDF_API
251 static SdfLayerHandleSet GetLoadedLayers();
252
254 SDF_API
255 bool IsEmpty() const;
256
264 SDF_API
265 bool StreamsData() const;
266
272 SDF_API
273 bool IsDetached() const;
274
277 SDF_API
278 void TransferContent(const SdfLayerHandle& layer);
279
294 SDF_API
296 const std::string& tag = std::string(),
298
300 SDF_API
302 const std::string &tag, const SdfFileFormatConstPtr &format,
304
306 SDF_API
307 bool IsAnonymous() const;
308
311 SDF_API
312 static bool IsAnonymousLayerIdentifier(const std::string& identifier);
313
316 SDF_API
318 const std::string& identifier);
319
323
328 SDF_API
329 bool Save(bool force = false) const;
330
343 SDF_API
344 bool Export(const std::string& filename,
345 const std::string& comment = std::string(),
346 const FileFormatArguments& args = FileFormatArguments()) const;
347
352 SDF_API
353 bool ExportToString(std::string* result) const;
354
358 SDF_API
359 bool ImportFromString(const std::string &string);
360
368 SDF_API
369 void Clear();
370
392 SDF_API
393 bool Reload(bool force = false);
394
401 SDF_API
402 static bool ReloadLayers(const std::set<SdfLayerHandle>& layers,
403 bool force = false);
404
410 SDF_API
411 bool Import(const std::string &layerPath);
412
416
419 SDF_API
420 std::set<std::string> GetExternalReferences() const;
421
424 SDF_API
426 const std::string &oldAssetPath,
427 const std::string &newAssetPath=std::string());
428
436 SDF_API
437 std::set<std::string> GetCompositionAssetDependencies() const;
438
448 SDF_API
450 const std::string &oldAssetPath,
451 const std::string &newAssetPath=std::string());
452
461 SDF_API
462 std::set<std::string> GetExternalAssetDependencies() const;
463
483
486 SDF_API
487 static bool SplitIdentifier(
488 const std::string& identifier,
489 std::string* layerPath,
490 FileFormatArguments* arguments);
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
505 SDF_API
506 void SetIdentifier(const std::string& identifier);
507
512 SDF_API
514
518 SDF_API
519 std::string GetDisplayName() const;
520
523 SDF_API
525
528 SDF_API
529 const std::string& GetRealPath() const;
530
535 SDF_API
536 std::string GetFileExtension() const;
537
543 SDF_API
544 const std::string& GetVersion() const;
545
550 SDF_API
551 const std::string& GetRepositoryPath() const;
552
554 SDF_API
555 const std::string& GetAssetName() const;
556
559 SDF_API
560 const VtValue& GetAssetInfo() const;
561
577 SDF_API
578 std::string ComputeAbsolutePath(const std::string& assetPath) const;
579
581
592
595 SDF_API
596 SdfSpecType GetSpecType(const SdfPath& path) const;
597
599 SDF_API
600 bool HasSpec(const SdfPath& path) const;
601
603 SDF_API
604 std::vector<TfToken> ListFields(const SdfPath& path) const;
605
608 SDF_API
609 bool HasField(const SdfPath& path, const TfToken& fieldName,
610 VtValue *value=NULL) const;
611 SDF_API
612 bool HasField(const SdfPath& path, const TfToken& fieldName,
613 SdfAbstractDataValue *value) const;
614
618 template <class T>
619 bool HasField(const SdfPath& path, const TfToken &name,
620 T* value) const
621 {
622 if (!value) {
623 return HasField(path, name, static_cast<VtValue *>(NULL));
624 }
625
626 SdfAbstractDataTypedValue<T> outValue(value);
627 const bool hasValue = HasField(
628 path, name, static_cast<SdfAbstractDataValue *>(&outValue));
629
630 if (std::is_same<T, SdfValueBlock>::value) {
631 return hasValue && outValue.isValueBlock;
632 }
633
634 return hasValue && (!outValue.isValueBlock);
635 }
636
639 std::type_info const &GetFieldTypeid(
640 const SdfPath &path, const TfToken &name) const {
641 return _data->GetTypeid(path, name);
642 }
643
647 SDF_API
648 bool HasFieldDictKey(const SdfPath& path,
649 const TfToken &fieldName,
650 const TfToken &keyPath,
651 VtValue *value=NULL) const;
652 SDF_API
653 bool HasFieldDictKey(const SdfPath& path,
654 const TfToken &fieldName,
655 const TfToken &keyPath,
656 SdfAbstractDataValue *value) const;
657
662 template <class T>
663 bool HasFieldDictKey(const SdfPath& path, const TfToken &name,
664 const TfToken &keyPath, T* value) const
665 {
666 if (!value) {
667 return HasFieldDictKey(path, name, keyPath,
668 static_cast<VtValue *>(NULL));
669 }
670
671 SdfAbstractDataTypedValue<T> outValue(value);
672 return HasFieldDictKey(path, name, keyPath,
673 static_cast<SdfAbstractDataValue *>(&outValue));
674 }
675
676
679 SDF_API
681 const TfToken& fieldName) const;
682
685 template <class T>
686 inline T GetFieldAs(const SdfPath& path,
687 const TfToken& fieldName, const T& defaultValue = T()) const
688 {
689 return _data->GetAs<T>(path, fieldName, defaultValue);
690 }
691
695 SDF_API
697 const TfToken& fieldName,
698 const TfToken& keyPath) const;
699
701 SDF_API
702 void SetField(const SdfPath& path, const TfToken& fieldName,
703 const VtValue& value);
704 SDF_API
705 void SetField(const SdfPath& path, const TfToken& fieldName,
706 const SdfAbstractDataConstValue& value);
707
709 template <class T>
710 void SetField(const SdfPath& path, const TfToken& fieldName,
711 const T& val)
712 {
713 // Ideally, this would make use of the SdfAbstractDataConstValue
714 // API to avoid unnecessarily copying the value into a VtValue.
715 // However, Sdf needs to create a VtValue for change processing.
716 // If the underlying SdAbstractData implementation also needs a
717 // VtValue, using the SdfAbstractDataConstValue API would cause
718 // another copy to be made. So, it's more efficient to just create
719 // the VtValue once here and push that along.
720 SetField(path, fieldName, VtValue(val));
721 }
722
725 SDF_API
727 const TfToken& fieldName,
728 const TfToken& keyPath,
729 const VtValue& value);
730 SDF_API
731 void SetFieldDictValueByKey(const SdfPath& path,
732 const TfToken& fieldName,
733 const TfToken& keyPath,
734 const SdfAbstractDataConstValue& value);
735
738 template <class T>
740 const TfToken& fieldName,
741 const TfToken& keyPath,
742 const T& val)
743 {
744 // Ideally, this would make use of the SdfAbstractDataConstValue
745 // API to avoid unnecessarily copying the value into a VtValue.
746 // However, Sdf needs to create a VtValue for change processing.
747 // If the underlying SdAbstractData implementation also needs
748 // VtValue, using the SdfAbstractDataConstValue API would cause
749 // another copy to be made. So, it's more efficient to just create
750 // the VtValue once here and push that along.
751 SetFieldDictValueByKey(path, fieldName, keyPath, VtValue(val));
752 }
753
755 SDF_API
756 void EraseField(const SdfPath& path, const TfToken& fieldName);
757
761 SDF_API
763 const TfToken& fieldName,
764 const TfToken& keyPath);
765
768
772 typedef std::function<void(const SdfPath&)> TraversalFunction;
773
774 // Traverse will perform a traversal of the scene description hierarchy
775 // rooted at \a path, calling \a func on each spec that it finds.
776 SDF_API
777 void Traverse(const SdfPath& path, const TraversalFunction& func);
778
780
783
787 SDF_API
789
791 SDF_API
792 void SetColorConfiguration(const SdfAssetPath &colorConfiguration);
793
796 SDF_API
798
801 SDF_API
803
811 SDF_API
813
816 SDF_API
818
821 SDF_API
823
826 SDF_API
828
832 SDF_API
833 std::string GetComment() const;
834
836 SDF_API
837 void SetComment(const std::string &comment);
838
844 SDF_API
846
852 SDF_API
853 void SetDefaultPrim(const TfToken &name);
854
857 SDF_API
859
862 SDF_API
864
868 SDF_API
869 std::string GetDocumentation() const;
870
872 SDF_API
873 void SetDocumentation(const std::string &documentation);
874
882 SDF_API
883 double GetStartTimeCode() const;
884
886 SDF_API
887 void SetStartTimeCode(double startTimecode);
888
890 SDF_API
891 bool HasStartTimeCode() const;
892
894 SDF_API
896
903 SDF_API
904 double GetEndTimeCode() const;
905
907 SDF_API
908 void SetEndTimeCode(double endTimeCode);
909
911 SDF_API
912 bool HasEndTimeCode() const;
913
915 SDF_API
917
932 SDF_API
933 double GetTimeCodesPerSecond() const;
934
936 SDF_API
937 void SetTimeCodesPerSecond(double timeCodesPerSecond);
938
940 SDF_API
942
944 SDF_API
946
956 SDF_API
957 double GetFramesPerSecond() const;
958
960 SDF_API
961 void SetFramesPerSecond(double framesPerSecond);
962
964 SDF_API
965 bool HasFramesPerSecond() const;
966
968 SDF_API
970
972 SDF_API
973 int GetFramePrecision() const;
974
976 SDF_API
977 void SetFramePrecision(int framePrecision);
978
980 SDF_API
981 bool HasFramePrecision() const;
982
984 SDF_API
986
988 SDF_API
989 std::string GetOwner() const;
990
992 SDF_API
993 void SetOwner(const std::string& owner);
994
996 SDF_API
997 bool HasOwner() const;
998
1000 SDF_API
1002
1005 SDF_API
1006 std::string GetSessionOwner() const;
1007
1010 SDF_API
1011 void SetSessionOwner(const std::string& owner);
1012
1014 SDF_API
1015 bool HasSessionOwner() const;
1016
1017 // Clear the session owner opinion.
1018 SDF_API
1019 void ClearSessionOwner();
1020
1022 SDF_API
1024
1026 SDF_API
1028
1034 SDF_API
1036
1038 SDF_API
1040
1042 SDF_API
1044
1046 SDF_API
1048
1051 SDF_API
1053
1055 SDF_API
1056 void SetExpressionVariables(const VtDictionary& expressionVars);
1057
1059 SDF_API
1061
1063 SDF_API
1065
1069
1070 // Type for root prims view.
1072
1074 SDF_API
1076
1081 SDF_API
1082 void SetRootPrims(const SdfPrimSpecHandleVector &rootPrims);
1083
1089 SDF_API
1090 bool InsertRootPrim(const SdfPrimSpecHandle &prim, int index = -1);
1091
1093 SDF_API
1094 void RemoveRootPrim(const SdfPrimSpecHandle &prim);
1095
1098 SDF_API
1100
1113 SDF_API
1114 void RemovePrimIfInert(SdfPrimSpecHandle prim);
1115
1122 SDF_API
1123 void RemovePropertyIfHasOnlyRequiredFields(SdfPropertySpecHandle prop);
1124
1130 SDF_API
1132
1137 SDF_API
1139
1148 SDF_API
1149 void SetRootPrimOrder(const std::vector<TfToken>& names);
1150
1153 SDF_API
1154 void InsertInRootPrimOrder(const TfToken &name, int index = -1);
1155
1157 SDF_API
1159
1161 SDF_API
1163
1169 SDF_API
1170 void ApplyRootPrimOrder(std::vector<TfToken> *vec) const;
1171
1175
1188 SDF_API
1190
1192 SDF_API
1193 void SetSubLayerPaths(const std::vector<std::string>& newPaths);
1194
1196 SDF_API
1197 size_t GetNumSubLayerPaths() const;
1198
1202 SDF_API
1203 void InsertSubLayerPath(const std::string& path, int index = -1);
1204
1206 SDF_API
1207 void RemoveSubLayerPath(int index);
1208
1210 SDF_API
1211 SdfLayerOffsetVector GetSubLayerOffsets() const;
1212
1214 SDF_API
1216
1218 SDF_API
1219 void SetSubLayerOffset(const SdfLayerOffset& offset, int index);
1220
1222
1243
1260 {
1261 public:
1265
1268 {
1269 _includeAll = true;
1270 _include.clear();
1271 return *this;
1272 }
1273
1276 SDF_API
1277 DetachedLayerRules& Include(const std::vector<std::string>& patterns);
1278
1281 SDF_API
1282 DetachedLayerRules& Exclude(const std::vector<std::string>& patterns);
1283
1284 bool IncludedAll() const { return _includeAll; }
1285 const std::vector<std::string>& GetIncluded() const { return _include; }
1286 const std::vector<std::string>& GetExcluded() const { return _exclude; }
1287
1295 SDF_API
1296 bool IsIncluded(const std::string& identifier) const;
1297
1298 private:
1299 friend class SdfLayer;
1300
1301 std::vector<std::string> _include;
1302 std::vector<std::string> _exclude;
1303 bool _includeAll = false;
1304 };
1305
1328 SDF_API
1330
1332 SDF_API
1334
1338 SDF_API
1339 static bool IsIncludedByDetachedLayerRules(const std::string& identifier);
1340
1342
1345
1347 SDF_API
1348 static std::set<std::string> GetMutedLayers();
1349
1351 SDF_API
1352 bool IsMuted() const;
1353
1355 SDF_API
1356 static bool IsMuted(const std::string &path);
1357
1360 SDF_API
1361 void SetMuted(bool muted);
1362
1364 SDF_API
1365 static void AddToMutedLayers(const std::string &mutedPath);
1366
1368 SDF_API
1369 static void RemoveFromMutedLayers(const std::string &mutedPath);
1370
1374
1383 SDF_API
1384 SdfPrimSpecHandle GetPseudoRoot() const;
1385
1392 SDF_API
1393 SdfSpecHandle GetObjectAtPath(const SdfPath &path);
1394
1400 SDF_API
1401 SdfPrimSpecHandle GetPrimAtPath(const SdfPath &path);
1402
1408 SDF_API
1409 SdfPropertySpecHandle GetPropertyAtPath(const SdfPath &path);
1410
1416 SDF_API
1417 SdfAttributeSpecHandle GetAttributeAtPath(const SdfPath &path);
1418
1424 SDF_API
1425 SdfRelationshipSpecHandle GetRelationshipAtPath(const SdfPath &path);
1426
1430
1434 SDF_API
1435 bool PermissionToEdit() const;
1436
1439 SDF_API
1440 bool PermissionToSave() const;
1441
1443 SDF_API
1444 void SetPermissionToEdit(bool allow);
1445
1447 SDF_API
1448 void SetPermissionToSave(bool allow);
1449
1453
1477 SDF_API
1480 SdfNamespaceEditDetailVector* details = NULL) const;
1481
1485 SDF_API
1487
1491
1494 SDF_API
1495 SdfLayerStateDelegateBasePtr GetStateDelegate() const;
1496
1500 SDF_API
1501 void SetStateDelegate(const SdfLayerStateDelegateBaseRefPtr& delegate);
1502
1505 SDF_API
1506 bool IsDirty() const;
1507
1509
1512 SDF_API
1513 std::set<double> ListAllTimeSamples() const;
1514
1515 SDF_API
1516 std::set<double>
1517 ListTimeSamplesForPath(const SdfPath& path) const;
1518
1519 SDF_API
1520 bool GetBracketingTimeSamples(double time, double* tLower, double* tUpper);
1521
1522 SDF_API
1523 size_t GetNumTimeSamplesForPath(const SdfPath& path) const;
1524
1525 SDF_API
1526 bool GetBracketingTimeSamplesForPath(const SdfPath& path,
1527 double time,
1528 double* tLower, double* tUpper);
1529
1530 SDF_API
1531 bool QueryTimeSample(const SdfPath& path, double time,
1532 VtValue *value=NULL) const;
1533 SDF_API
1534 bool QueryTimeSample(const SdfPath& path, double time,
1535 SdfAbstractDataValue *value) const;
1536
1537 template <class T>
1538 bool QueryTimeSample(const SdfPath& path, double time,
1539 T* data) const
1540 {
1541 if (!data) {
1542 return QueryTimeSample(path, time);
1543 }
1544
1545 SdfAbstractDataTypedValue<T> outValue(data);
1546 const bool hasValue = QueryTimeSample(
1547 path, time, static_cast<SdfAbstractDataValue *>(&outValue));
1548
1549 if (std::is_same<T, SdfValueBlock>::value) {
1550 return hasValue && outValue.isValueBlock;
1551 }
1552
1553 return hasValue && (!outValue.isValueBlock);
1554 }
1555
1556 SDF_API
1557 void SetTimeSample(const SdfPath& path, double time,
1558 const VtValue & value);
1559 SDF_API
1560 void SetTimeSample(const SdfPath& path, double time,
1561 const SdfAbstractDataConstValue& value);
1562
1563 template <class T>
1564 void SetTimeSample(const SdfPath& path, double time,
1565 const T& value)
1566 {
1567 const SdfAbstractDataConstTypedValue<T> inValue(&value);
1568 const SdfAbstractDataConstValue& untypedInValue = inValue;
1569 return SetTimeSample(path, time, untypedInValue);
1570 }
1571
1572 SDF_API
1573 void EraseTimeSample(const SdfPath& path, double time);
1574
1576
1577 // Debugging
1578 // @{
1579
1580 SDF_API
1581 static void DumpLayerInfo();
1582
1583 // Write this layer's SdfData to a file in a simple generic format.
1584 SDF_API
1585 bool WriteDataFile(const std::string &filename);
1586
1587 // @}
1588
1589protected:
1590 // Private constructor -- use New(), FindOrCreate(), etc.
1591 // Precondition: _layerRegistryMutex must be locked.
1592 SdfLayer(const SdfFileFormatConstPtr& fileFormat,
1593 const std::string &identifier,
1594 const std::string &realPath = std::string(),
1595 const ArAssetInfo& assetInfo = ArAssetInfo(),
1597 bool validateAuthoring = false);
1598
1599private:
1600 // Create a new layer.
1601 // Precondition: _layerRegistryMutex must be locked.
1602 static SdfLayerRefPtr _CreateNew(
1603 SdfFileFormatConstPtr fileFormat,
1604 const std::string& identifier,
1605 const FileFormatArguments& args,
1606 bool saveLayer = true);
1607
1608 static SdfLayerRefPtr _CreateNewWithFormat(
1609 const SdfFileFormatConstPtr &fileFormat,
1610 const std::string& identifier,
1611 const std::string& realPath,
1612 const ArAssetInfo& assetInfo = ArAssetInfo(),
1614
1615 static SdfLayerRefPtr _CreateAnonymousWithFormat(
1616 const SdfFileFormatConstPtr &fileFormat,
1617 const std::string& tag,
1618 const FileFormatArguments& args);
1619
1620 // Finish initializing this layer (which may have succeeded or not)
1621 // and publish the results to other threads by unlocking the mutex.
1622 // Sets _initializationWasSuccessful.
1623 void _FinishInitialization(bool success);
1624
1625 // Layers retrieved from the layer registry may still be in the
1626 // process of having their contents initialized. Other threads
1627 // retrieving layers from the registry must wait until initialization
1628 // is complete, using this method.
1629 // Returns _initializationWasSuccessful.
1630 //
1631 // Callers *must* be holding an SdfLayerRefPtr to this layer to
1632 // ensure that it is not deleted out from under them, in
1633 // case initialization fails. (This method cannot acquire the
1634 // reference itself internally without being susceptible to a race.)
1635 bool _WaitForInitializationAndCheckIfSuccessful();
1636
1637 // Returns whether or not this layer should post change
1638 // notification. This simply returns (!_GetIsLoading())
1639 bool _ShouldNotify() const;
1640
1641 // This function keeps track of the last state of IsDirty() before
1642 // updating it. It returns false if the last saved dirty state is the
1643 // same than the current state. It returns true if the state differs and
1644 // will update the 'last dirty state' to the current state. So, after
1645 // returning true, it would return false for subsequent calls until the
1646 // IsDirty() state would change again...
1647 bool _UpdateLastDirtinessState() const;
1648
1649 // Returns a handle to the spec at the given path if it exists and matches
1650 // type T.
1651 template <class T>
1652 SdfHandle<T> _GetSpecAtPath(const SdfPath& path);
1653
1654 // Returns true if a spec can be retrieved at the given path, false
1655 // otherwise. This function will return the canonicalized path to the
1656 // spec as well as the spec type.
1657 bool _CanGetSpecAtPath(const SdfPath& path,
1658 SdfPath* canonicalPath, SdfSpecType* specType) const;
1659
1663 void _InitializeFromIdentifier(
1664 const std::string &identifier,
1665 const std::string &realPath = std::string(),
1666 const std::string &fileVersion = std::string(),
1667 const ArAssetInfo& assetInfo = ArAssetInfo());
1668
1669 // Helper for computing the necessary information to lookup a layer
1670 // in the registry or open the layer.
1671 struct _FindOrOpenLayerInfo;
1672 static bool _ComputeInfoToFindOrOpenLayer(
1673 const std::string& identifier,
1675 _FindOrOpenLayerInfo* info,
1676 bool computeAssetInfo = false);
1677
1678 // Open a layer, adding an entry to the registry and releasing
1679 // the registry lock.
1680 // Precondition: _layerRegistryMutex must be locked.
1681 template <class Lock>
1682 static SdfLayerRefPtr _OpenLayerAndUnlockRegistry(
1683 Lock &lock,
1684 const _FindOrOpenLayerInfo& info,
1685 bool metadataOnly);
1686
1687 // Helper function for finding a layer with \p identifier and \p args.
1688 // \p lock must be unlocked initially and will be locked by this
1689 // function when needed. See docs for \p retryAsWriter argument on
1690 // _TryToFindLayer for details on the final state of the lock when
1691 // this function returns.
1692 template <class ScopedLock>
1693 static SdfLayerRefPtr
1694 _Find(const std::string &identifier,
1695 const FileFormatArguments &args,
1696 ScopedLock &lock, bool retryAsWriter);
1697
1698 // Helper function to try to find the layer with \p identifier and
1699 // pre-resolved path \p resolvedPath in the registry. Caller must hold
1700 // registry \p lock for reading. If \p retryAsWriter is false, lock is
1701 // released upon return. Otherwise the lock is released upon return if a
1702 // layer is found successfully. If no layer is found then the lock is
1703 // upgraded to a writer lock upon return. Note that this upgrade may not be
1704 // atomic, but this function ensures that if upon return there does not
1705 // exist a matching layer in the registry.
1706 template <class ScopedLock>
1707 static SdfLayerRefPtr
1708 _TryToFindLayer(const std::string &identifier,
1709 const ArResolvedPath &resolvedPath,
1710 ScopedLock &lock, bool retryAsWriter);
1711
1719 bool _IsInert(const SdfPath &path, bool ignoreChildren,
1720 bool requiredFieldOnlyPropertiesAreInert = false) const;
1721
1725 bool _IsInertSubtree(const SdfPath &path) const;
1726
1732 void _RemoveIfInert(const SdfSpec& spec);
1733
1738 bool _RemoveInertDFS(SdfPrimSpecHandle prim);
1739
1742 void _RemoveInertToRootmost(SdfPrimSpecHandle prim);
1743
1745 bool _ValidateAuthoring() const { return _validateAuthoring; }
1746
1748 std::string _GetMutedPath() const;
1749
1750 // If old and new asset path is given, rename all external prim
1751 // composition dependency referring to the old path.
1752 void _UpdatePrimCompositionDependencyPaths(
1753 const SdfPrimSpecHandle &parent,
1754 const std::string &oldLayerPath,
1755 const std::string &newLayerPath);
1756
1757 // Set the clean state to the current state.
1758 void _MarkCurrentStateAsClean() const;
1759
1760 // Return the field definition for \p fieldName if \p fieldName is a
1761 // required field for the spec type identified by \p path.
1762 inline SdfSchema::FieldDefinition const *
1763 _GetRequiredFieldDef(const SdfPath &path,
1764 const TfToken &fieldName,
1765 SdfSpecType specType = SdfSpecTypeUnknown) const;
1766
1767 // Return the field definition for \p fieldName if \p fieldName is a
1768 // required field for \p specType subject to \p schema.
1769 static inline SdfSchema::FieldDefinition const *
1770 _GetRequiredFieldDef(const SdfSchemaBase &schema,
1771 const TfToken &fieldName,
1772 SdfSpecType specType);
1773
1774 // Helper to list all fields on \p data at \p path subject to \p schema.
1775 static std::vector<TfToken>
1776 _ListFields(SdfSchemaBase const &schema,
1777 SdfAbstractData const &data, const SdfPath& path);
1778
1779 // Helper for HasField for \p path in \p data subject to \p schema.
1780 static inline bool
1781 _HasField(const SdfSchemaBase &schema,
1782 const SdfAbstractData &data,
1783 const SdfPath& path,
1784 const TfToken& fieldName,
1785 VtValue *value);
1786
1787 // Helper to get a field value for \p path in \p data subject to \p schema.
1788 static inline VtValue
1789 _GetField(const SdfSchemaBase &schema,
1790 const SdfAbstractData &data,
1791 const SdfPath& path,
1792 const TfToken& fieldName);
1793
1794 // Set a value.
1795 template <class T>
1796 void _SetValue(const TfToken& key, T value);
1797
1798 // Get a value.
1799 template <class T>
1800 T _GetValue(const TfToken& key) const;
1801
1802 enum _ReloadResult { _ReloadFailed, _ReloadSucceeded, _ReloadSkipped };
1803 _ReloadResult _Reload(bool force);
1804
1805 // Reads contents of asset specified by \p identifier with resolved
1806 // path \p resolvedPath into this layer.
1807 bool _Read(const std::string& identifier,
1808 const ArResolvedPath& resolvedPath,
1809 bool metadataOnly);
1810
1811 // Saves this layer if it is dirty or the layer doesn't already exist
1812 // on disk. If \p force is true, the layer will be written out
1813 // regardless of those conditions.
1814 bool _Save(bool force) const;
1815
1816 // A helper method used by Save and Export.
1817 // This method allows Save to specify the existing file format and Export
1818 // to use the format provided by the file extension in newFileName. If no
1819 // file format can be discovered from the file name, the existing file
1820 // format associated with the layer will be used in both cases. This allows
1821 // users to export and save to any file name, regardless of extension.
1822 bool _WriteToFile(const std::string& newFileName,
1823 const std::string& comment,
1824 SdfFileFormatConstPtr fileFormat = TfNullPtr,
1826 const;
1827
1828 // Swap contents of _data and data. This operation does not register
1829 // inverses or emit change notification.
1830 void _SwapData(SdfAbstractDataRefPtr &data);
1831
1832 // Set _data to \p newData and send coarse DidReplaceLayerContent
1833 // invalidation notice.
1834 void _AdoptData(const SdfAbstractDataRefPtr &newData);
1835
1836 // Set _data to match data, calling other primitive setter methods to
1837 // provide fine-grained inverses and notification. If \p data might adhere
1838 // to a different schema than this layer's, pass a pointer to it as \p
1839 // newDataSchema. In this case, check to see if fields from \p data are
1840 // known to this layer's schema, and if not, omit them and issue a TfError
1841 // with SdfAuthoringErrorUnrecognizedFields, but continue to set all other
1842 // known fields.
1843 void _SetData(const SdfAbstractDataPtr &newData,
1844 const SdfSchemaBase *newDataSchema=nullptr);
1845
1846 // Returns const handle to _data.
1847 SdfAbstractDataConstPtr _GetData() const;
1848
1849 // Returns a new SdfAbstractData object for this layer.
1850 SdfAbstractDataRefPtr _CreateData() const;
1851
1852 // Inverse primitive for setting a single field. The previous value for the
1853 // field may be given via \p oldValue. If \p oldValue is non-nullptr, the
1854 // VtValue it points to will be moved-from after the function completes. If
1855 // \p oldValue is nullptr, the old field value will be retrieved
1856 // automatically.
1857 template <class T>
1858 void _PrimSetField(const SdfPath& path,
1859 const TfToken& fieldName,
1860 const T& value,
1861 VtValue *oldValue = nullptr,
1862 bool useDelegate = true);
1863
1864 // Inverse primitive for setting a single key in a dict-valued field. The
1865 // previous dictionary value for the field (*not* the individual entry) may
1866 // be supplied via \p oldValue. If \p oldValue is non-nullptr, the VtValue
1867 // it points to will be moved-from after the function completes. If \p
1868 // oldValue is nullptr, the old field value will be retrieved automatically.
1869 template <class T>
1870 void _PrimSetFieldDictValueByKey(const SdfPath& path,
1871 const TfToken& fieldName,
1872 const TfToken& keyPath,
1873 const T& value,
1874 VtValue *oldValue = nullptr,
1875 bool useDelegate = true);
1876
1877 // Primitive for appending a child to the list of children.
1878 template <class T>
1879 void _PrimPushChild(const SdfPath& parentPath,
1880 const TfToken& fieldName,
1881 const T& value,
1882 bool useDelegate = true);
1883 template <class T>
1884 void _PrimPopChild(const SdfPath& parentPath,
1885 const TfToken& fieldName,
1886 bool useDelegate = true);
1887
1888 // Move all the fields at all paths at or below \a oldPath to be
1889 // at a corresponding location at or below \a newPath. This does
1890 // not update the children fields of the parents of these paths.
1891 bool _MoveSpec(const SdfPath &oldPath, const SdfPath &newPath);
1892
1893 // Inverse primitive for moving a spec.
1894 void _PrimMoveSpec(const SdfPath &oldPath, const SdfPath &newPath,
1895 bool useDelegate = true);
1896
1897 // Create a new spec of type \p specType at \p path.
1898 // Returns true if spec was successfully created, false otherwise.
1899 bool _CreateSpec(const SdfPath& path, SdfSpecType specType, bool inert);
1900
1901 // Delete all the fields at or below the specified path. This does
1902 // not update the children field of the parent of \a path.
1903 bool _DeleteSpec(const SdfPath &path);
1904
1905 // Inverse primitive for deleting a spec.
1906 void _PrimCreateSpec(const SdfPath &path, SdfSpecType specType, bool inert,
1907 bool useDelegate = true);
1908
1909 // Inverse primitive for deleting a spec.
1910 void _PrimDeleteSpec(const SdfPath &path, bool inert,
1911 bool useDelegate = true);
1912
1913 // Inverse primitive for setting time samples.
1914 template <class T>
1915 void _PrimSetTimeSample(const SdfPath& path, double time,
1916 const T& value,
1917 bool useDelegate = true);
1918
1919 // Helper method for Traverse. Visits the children of \a path using the
1920 // specified \a ChildPolicy.
1921 template <typename ChildPolicy>
1922 void _TraverseChildren(const SdfPath &path, const TraversalFunction &func);
1923
1924private:
1925 SdfLayerHandle _self;
1926
1927 // File format and arguments for this layer.
1928 SdfFileFormatConstPtr _fileFormat;
1929 FileFormatArguments _fileFormatArgs;
1930
1931 // Cached reference to the _fileFormat's schema -- we need access to this to
1932 // be as fast as possible since we look at it on every SetField(), for
1933 // example.
1934 const SdfSchemaBase &_schema;
1935
1936 // Registry of Sdf Identities
1937 mutable Sdf_IdentityRegistry _idRegistry;
1938
1939 // The underlying SdfData which stores all the data in the layer.
1940 SdfAbstractDataRefPtr _data;
1941
1942 // The state delegate for this layer.
1943 SdfLayerStateDelegateBaseRefPtr _stateDelegate;
1944
1945 // Dispatcher used in layer initialization, letting waiters participate in
1946 // loading instead of just busy-waiting.
1947 WorkDispatcher _initDispatcher;
1948
1949 // Atomic variable protecting layer initialization -- the interval between
1950 // adding a layer to the layer registry and finishing the process of
1951 // initializing its contents, at which point we can truly publish the layer
1952 // for consumption by concurrent threads. We add the layer to the registry
1953 // before initialization completes so that other threads can discover and
1954 // wait for it to finish initializing.
1955 std::atomic<bool> _initializationComplete;
1956
1957 // This is an optional<bool> that is only set once initialization
1958 // is complete, before _initializationComplete is set.
1959 boost::optional<bool> _initializationWasSuccessful;
1960
1961 // remembers the last 'IsDirty' state.
1962 mutable bool _lastDirtyState;
1963
1964 // Asset information for this layer.
1965 std::unique_ptr<Sdf_AssetInfo> _assetInfo;
1966
1967 // Modification timestamp of the backing file asset when last read.
1968 mutable VtValue _assetModificationTime;
1969
1970 // All external asset dependencies, with their modification timestamps, of
1971 // the layer when last read.
1972 mutable VtDictionary _externalAssetModificationTimes;
1973
1974 // Mutable revision number for cache invalidation.
1975 mutable size_t _mutedLayersRevisionCache;
1976
1977 // Cache of whether or not this layer is muted. Only valid if
1978 // _mutedLayersRevisionCache is up-to-date with the global revision number.
1979 mutable bool _isMutedCache;
1980
1981 // Layer permission bits.
1982 bool _permissionToEdit;
1983 bool _permissionToSave;
1984
1985 // Whether layer edits are validated.
1986 bool _validateAuthoring;
1987
1988 // Layer hints as of the most recent save operation.
1989 mutable SdfLayerHints _hints;
1990
1991 // Allow access to _ValidateAuthoring() and _IsInert().
1992 friend class SdfSpec;
1993 friend class SdfPropertySpec;
1994 friend class SdfAttributeSpec;
1995
1996 friend class Sdf_ChangeManager;
1997
1998 // Allow access to _CreateSpec and _DeleteSpec and _MoveSpec
1999 template <class ChildPolicy> friend class Sdf_ChildrenUtils;
2000
2001 // Give the file format access to our data. Limit breaking encapsulation
2002 // to the base SdFileFormat class so we don't have to friend every
2003 // implementation here.
2004 friend class SdfFileFormat;
2005
2006 // Give layer state delegates access to our data as well as to
2007 // the various _Prim functions.
2008 friend class SdfLayerStateDelegateBase;
2009};
2010
2011PXR_NAMESPACE_CLOSE_SCOPE
2012
2013#endif // PXR_USD_SDF_LAYER_H
Contains information about a resolved asset.
Definition: assetInfo.h:42
Represents a resolved asset path.
Definition: resolvedPath.h:40
The fully-typed container for a field value in an SdfAbstractData.
Definition: abstractData.h:562
A type-erased container for a const field value in an SdfAbstractData.
Definition: abstractData.h:520
Interface for scene description data storage.
Definition: abstractData.h:74
The fully-typed container for a field value in an SdfAbstractData.
Definition: abstractData.h:467
A type-erased container for a field value in an SdfAbstractData.
Definition: abstractData.h:416
Contains an asset path and an optional resolved path.
Definition: assetPath.h:47
A subclass of SdfPropertySpec that holds typed data.
Definition: attributeSpec.h:57
A description of an arbitrarily complex namespace edit.
Provides a view onto an object's children.
Definition: childrenView.h:222
Base class for file format implementations.
Definition: fileFormat.h:67
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:1260
DetachedLayerRules & IncludeAll()
Include all layers in the detached layer set.
Definition: layer.h:1267
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:34
A scene description container that can combine with other such containers to form simple component as...
Definition: layer.h:101
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:619
SDF_API TfToken GetColorManagementSystem() const
Returns the color management system used to interpret the color configuration asset-path authored in ...
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.
std::map< std::string, std::string > FileFormatArguments
Type for specifying additional file format-specific arguments to layer API.
Definition: layer.h:124
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:739
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.
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.
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:639
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.
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 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 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.
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:686
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:710
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.
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.
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:663
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.
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.
std::function< void(const SdfPath &)> TraversalFunction
Callback function for Traverse.
Definition: layer.h:772
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.
Represents a time offset and scale between layers.
Definition: layerOffset.h:61
Maintains authoring state information for an associated layer.
Represents a single list of list editing operations.
Definition: listProxy.h:54
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:291
Base class for SdfAttributeSpec and SdfRelationshipSpec.
Definition: propertySpec.h:60
Class defining various attributes for a field.
Definition: schema.h:73
Generic class that provides information about scene description fields but doesn't actually provide a...
Definition: schema.h:62
Base class for all Sdf spec classes.
Definition: spec.h:50
Enable a concrete base class for use with TfRefPtr.
Definition: refBase.h:71
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:141
A map with string keys and VtValue values.
Definition: dictionary.h:60
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:164
A work dispatcher runs concurrent tasks.
Definition: dispatcher.h:76
Standard pointer typedefs.
#define TF_DECLARE_WEAK_PTRS(type)
Define standard weak pointer types.
Definition: declarePtrs.h:62
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:89
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:85