HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dependentNamespaceEditUtils.h
Go to the documentation of this file.
1 //
2 // Copyright 2024 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_PCP_DEPENDENT_NAMESPACE_EDIT_UTILS_H
8 #define PXR_USD_PCP_DEPENDENT_NAMESPACE_EDIT_UTILS_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/usd/pcp/api.h"
12 #include "pxr/usd/pcp/cache.h"
13 #include "pxr/usd/sdf/path.h"
15 #include "pxr/base/tf/hash.h"
16 #include "pxr/base/tf/token.h"
17 #include "pxr/base/vt/value.h"
18 
19 #include <string>
20 #include <unordered_map>
21 #include <vector>
22 
24 
27 
28 /// Structure for bundling all the edits that need to be performed in order to
29 /// perform a namespace edit and fix up downstream composition dependencies on
30 /// dependent prim indexes in dependent PcpCaches. This is the return value of
31 /// PcpGatherDependentNamespaceEdits.
33 public:
34  /// Description of an edit to a prim spec composition field, such as
35  /// references, inherits, or relocates.
37  /// Layer containing the prim spec to edit.
38  SdfLayerHandle layer;
39 
40  /// Path of the prim spec to edit.
42 
43  /// Name of the composition field.
45 
46  /// New value of the composition field to set.
48  };
49 
50  /// List of all composition fields edits to perform.
51  std::vector<CompositionFieldEdit> compositionFieldEdits;
52 
53  /// Description of move edit which consists of the old (source) path and the
54  /// new (destination) path.
58  };
59  using MoveEditDescriptionVector = std::vector<MoveEditDescription>;
60 
61  /// Map of layer to the spec moves edits to perform on the layer.
62  using LayerSpecMoveEdits = std::unordered_map<
63  SdfLayerHandle, MoveEditDescriptionVector, TfHash>;
65 
66  /// Map of layer to relocates value to set in the layer metadata relocates
67  /// field.
68  using LayerRelocatesEdits =
69  std::unordered_map<SdfLayerHandle, SdfRelocates, TfHash>;
71 
72  /// Errors encountered during the processing of the dependent namespace
73  /// edits.
74  std::vector<std::string> errors;
75 
76  /// Warnings encountered during the processing of the dependent namespace
77  /// edits.
78  std::vector<std::string> warnings;
79 
80  /// Lists of composed prim paths in each affected cache whose prim indexes
81  /// will need to be recomputed after the changes in this object are applied.
82  /// This information can be useful during change processing and notification
83  /// to help report the intended effects of all the layer spec edits that are
84  /// performed during a namespace edit.
85  std::unordered_map<const PcpCache *, MoveEditDescriptionVector>
87 };
88 
89 /// Given a prim spec move edit from \p oldPrimPath to \p newPrimPath and the
90 /// \p affectedLayers on which this spec move will be performed, this function
91 /// finds all prim indexes already cached in each PcpCache in \p dependentCaches
92 /// that would be affected by these edits and computes a full set of edits that
93 /// would be required to maintain these dependent prim indexes' composed prim
94 /// stacks, possibly moving the prim index to a new prim path if necessary.
95 /// If \p addRelocatesToLayerStack is provided, this will also add a new
96 /// relocates edit to the necessary layers in the layer stack that moves
97 /// oldPrimPath to newPrimPath. The layer \p addRelocatesToLayerStackEditLayer
98 /// provided is only relevant when the relocates layer stack is also provided as
99 /// it determines which specific layer in the layer stack will have a new
100 /// relocates entry added to it (see PcpLayerRelocatesEditBuilder).
101 PCP_API
104  const SdfPath &oldPrimPath,
105  const SdfPath &newPrimPath,
106  const SdfLayerHandleVector &affectedLayers,
107  const PcpLayerStackRefPtr &addRelocatesToLayerStack,
108  const SdfLayerHandle &addRelocatesToLayerStackEditLayer,
109  const std::vector<const PcpCache *> &dependentCaches);
110 
111 /// Gathers the list of layers that need to be edited to perform the spec move
112 /// from \p oldSpecPath to \p newSpecPath on the given \p layerStack.
113 ///
114 /// If any errors are encountered where the spec would not be able to performed
115 /// on a layer that needs to be edited, those errors will be added to \p errors.
116 /// Layers with errors are still included in the returned result regardless.
117 PCP_API
118 SdfLayerHandleVector
120  const PcpLayerStackRefPtr &layerStack,
121  const SdfPath &oldSpecPath,
122  const SdfPath &newSpecPath,
123  std::vector<std::string> *errors);
124 
126 
127 #endif // PXR_USD_PCP_NAMESPACE_EDITS_H
TF_DECLARE_REF_PTRS(PcpLayerStack)
Definition: layer.h:81
PCP_API SdfLayerHandleVector PcpGatherLayersToEditForSpecMove(const PcpLayerStackRefPtr &layerStack, const SdfPath &oldSpecPath, const SdfPath &newSpecPath, std::vector< std::string > *errors)
std::vector< std::string > warnings
Definition: hash.h:472
std::unordered_map< SdfLayerHandle, SdfRelocates, TfHash > LayerRelocatesEdits
Definition: token.h:70
PCP_API PcpDependentNamespaceEdits PcpGatherDependentNamespaceEdits(const SdfPath &oldPrimPath, const SdfPath &newPrimPath, const SdfLayerHandleVector &affectedLayers, const PcpLayerStackRefPtr &addRelocatesToLayerStack, const SdfLayerHandle &addRelocatesToLayerStackEditLayer, const std::vector< const PcpCache * > &dependentCaches)
std::vector< CompositionFieldEdit > compositionFieldEdits
List of all composition fields edits to perform.
std::vector< std::string > errors
VtValue newFieldValue
New value of the composition field to set.
std::unordered_map< SdfLayerHandle, MoveEditDescriptionVector, TfHash > LayerSpecMoveEdits
Map of layer to the spec moves edits to perform on the layer.
Definition: path.h:273
std::unordered_map< const PcpCache *, MoveEditDescriptionVector > dependentCachePathChanges
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
SdfLayerHandle layer
Layer containing the prim spec to edit.
std::vector< MoveEditDescription > MoveEditDescriptionVector
PXR_NAMESPACE_OPEN_SCOPE SDF_DECLARE_HANDLES(SdfLayer)
Definition: value.h:146
#define PCP_API
Definition: api.h:23