HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
editTarget.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_USD_EDIT_TARGET_H
8 #define PXR_USD_USD_EDIT_TARGET_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/usd/usd/api.h"
14 #include "pxr/usd/pcp/node.h"
16 #include "pxr/usd/sdf/layer.h"
17 #include "pxr/usd/sdf/path.h"
18 #include "pxr/usd/sdf/primSpec.h"
20 
22 
23 
25 
26 /// \class UsdEditTarget
27 ///
28 /// Defines a mapping from scene graph paths to Sdf spec paths in a
29 /// SdfLayer where edits should be directed, or up to where to perform partial
30 /// composition.
31 ///
32 /// A UsdEditTarget can represent an arbitrary point in a composition graph for
33 /// the purposes of placing edits and resolving values. This enables editing
34 /// and resolving across references, classes, variants, and payloads.
35 ///
36 /// In the simplest case, an EditTarget represents a single layer in a stage's
37 /// local LayerStack. In this case, the mapping that transforms scene graph
38 /// paths to spec paths in the layer is the identity function. That is, the
39 /// UsdAttribute path '/World/Foo.avar' would map to the SdfPropertySpec path
40 /// '/World/Foo.avar'.
41 ///
42 /// For a more complex example, suppose '/World/Foo' in 'Shot.usda' is a
43 /// reference to '/Model' in 'Model.usda'. One can construct a UsdEditTarget
44 /// that maps scene graph paths from the 'Shot.usda' stage across the reference
45 /// to the appropriate paths in the 'Model.usda' layer. For example, the
46 /// UsdAttribute '/World/Foo.avar' would map to the SdfPropertySpec
47 /// '/Model.avar'. Paths in the stage composed at 'Shot.usda' that weren't
48 /// prefixed by '/World/Foo' would not have a valid mapping to 'Model.usda'.
49 ///
50 /// EditTargets may also work for any other kind of arc or series of arcs.
51 /// This allows for editing across variants, classes, and payloads, or in a
52 /// variant on the far side of a reference, for example.
53 ///
54 /// In addition to mapping scene paths to spec paths for editing, EditTargets
55 /// may also be used to identify points in the composition graph for partial
56 /// composition. Though it doesn't currently exist, a UsdCompose API that takes
57 /// UsdEditTarget arguments may someday be provided.
58 ///
59 /// For convenience and deployment ease, SdfLayerHandles will implicitly convert
60 /// to UsdEditTargets. A UsdEditTarget constructed in this way means direct
61 /// opinions in a layer in a stage's local LayerStack.
62 ///
64 {
65 public:
66 
67  /// Construct a null EditTarget. A null EditTarget will return paths
68  /// unchanged when asked to map paths.
69  USD_API
70  UsdEditTarget();
71 
72  /// Constructor. Allow implicit conversion from SdfLayerHandle.
73  /// EditTargets constructed in this way specify layers in the scene's local
74  /// LayerStack. This lets clients pass layers directly in this common case
75  /// without explicitly having to construct a \a UsdEditTarget instance.
76  /// To automatically supply the appropriate layer offset for the given
77  /// layer, see UsdStage::GetEditTargetForLayer().
78  USD_API
79  UsdEditTarget(const SdfLayerHandle &layer,
81 
82  /// Convenience implicit conversion from SdfLayerRefPtr. See above
83  /// constructor for more information.
84  USD_API
85  UsdEditTarget(const SdfLayerRefPtr &layer,
87 
88  /// Construct an EditTarget with \a layer and \a node. The mapping
89  /// will be used to map paths from the scene into the \a layer's namespace
90  /// given the \a PcpNodeRef \a node's mapping.
91  USD_API
92  UsdEditTarget(const SdfLayerHandle &layer, const PcpNodeRef &node);
93 
94  /// Convenience constructor taking SdfLayerRefPtr. See above
95  /// constructor for more information.
96  USD_API
97  UsdEditTarget(const SdfLayerRefPtr &layer, const PcpNodeRef &node);
98 
99  /// Convenience constructor for editing a direct variant in a local
100  /// LayerStack. The \p varSelPath must be a prim variant selection path
101  /// (see SdfPath::IsPrimVariantSelectionPath()).
102  USD_API
103  static UsdEditTarget
104  ForLocalDirectVariant(const SdfLayerHandle &layer,
105  const SdfPath &varSelPath);
106 
107  /// Equality comparison.
108  USD_API
109  bool operator==(const UsdEditTarget &other) const;
110 
111  /// Inequality comparison.
112  bool operator!=(const UsdEditTarget &other) const {
113  return !(*this == other);
114  }
115 
116  /// Return true if this EditTarget is null. Null EditTargets map
117  /// paths unchanged, and have no layer or LayerStack identifier.
118  bool IsNull() const { return *this == UsdEditTarget(); }
119 
120  /// Return true if this EditTarget is valid, false otherwise. Edit
121  /// targets are considered valid when they have a layer.
122  bool IsValid() const { return _layer; }
123 
124  /// Return the layer this EditTarget contains.
125  const SdfLayerHandle &GetLayer() const & { return _layer; }
126  SdfLayerHandle GetLayer() && { return std::move(_layer); }
127 
128  /// Map the provided \a scenePath into a SdfSpec path for the
129  /// EditTarget's layer, according to the EditTarget's mapping. Null edit
130  /// targets and EditTargets for which \a IsLocalLayer are true return
131  /// scenePath unchanged.
132  USD_API
133  SdfPath MapToSpecPath(const SdfPath &scenePath) const;
134 
135  /// Convenience function for getting the PrimSpec in the edit
136  /// target's layer for \a scenePath. This is equivalent to
137  /// target.GetLayer()->GetPrimAtPath(target.MapToSpecPath(scenePath)) if
138  /// target has a valid layer. If this target IsNull or there is no valid
139  /// mapping from \a scenePath to a SdfPrimSpec path in the layer, return
140  /// null.
141  USD_API
142  SdfPrimSpecHandle
143  GetPrimSpecForScenePath(const SdfPath &scenePath) const;
144 
145  /// Convenience function for getting the PropertySpec in the edit
146  /// target's layer for \a scenePath. This is equivalent to
147  /// target.GetLayer()->GetPropertyAtPath(target.MapToSpecPath(scenePath))
148  /// if target has a valid layer. If this target IsNull or there is no
149  /// valid mapping from \a scenePath to a SdfPropertySpec path in the layer,
150  /// return null.
151  USD_API
152  SdfPropertySpecHandle
153  GetPropertySpecForScenePath(const SdfPath &scenePath) const;
154 
155  /// Convenience function for getting the AttributeSpec in the edit
156  /// target's layer for \a scenePath. This is equivalent to
157  /// target.GetLayer()->GetAttributeAtPath(target.MapToSpecPath(scenePath))
158  /// if target has a valid layer. If this target IsNull or there is no
159  /// valid mapping from \a scenePath to a SdfAttributeSpec path
160  /// in the layer, return null.
161  USD_API
162  SdfAttributeSpecHandle
163  GetAttributeSpecForScenePath(const SdfPath &scenePath) const;
164 
165  /// Convenience function for getting the RelationshipSpec in the edit
166  /// target's layer for \a scenePath. This is equivalent to
167  /// target.GetLayer()->GetRelationshipAtPath(
168  /// target.MapToSpecPath(scenePath))
169  /// if target has a valid layer. If this target IsNull or there is no
170  /// valid mapping from \a scenePath to a SdfRelationshipSpec path
171  /// in the layer, return null.
172  USD_API
173  SdfRelationshipSpecHandle
174  GetRelationshipSpecForScenePath(const SdfPath &scenePath) const;
175 
176  /// Convenience function for getting the Spec in the edit
177  /// target's layer for \a scenePath. This is equivalent to
178  /// target.GetLayer()->GetObjectAtPath(target.MapToSpecPath(scenePath)) if
179  /// target has a valid layer. If this target IsNull or there is no valid
180  /// mapping from \a scenePath to a SdfSpec path in the layer, return
181  /// null.
182  USD_API
183  SdfSpecHandle
184  GetSpecForScenePath(const SdfPath &scenePath) const;
185 
186  /// Returns the PcpMapFunction representing the map from source
187  /// specs (including any variant selections) to the stage.
188  const PcpMapFunction &
189  GetMapFunction() const { return _mapping; }
190 
191  /// Return a new EditTarget composed over \a weaker. This is
192  /// typically used to make an EditTarget "explicit". For example, an edit
193  /// target with a layer but with no mapping and no LayerStack identifier
194  /// indicates a layer in the local LayerStack of a composed scene.
195  /// However, an EditTarget with the same layer but an explicit identity
196  /// mapping and the LayerStack identifier of the composed scene may be
197  /// desired. This can be obtained by composing a partial (e.g. layer only)
198  /// EditTarget over an explicit EditTarget with layer, mapping and layer
199  /// stack identifier.
200  USD_API
201  UsdEditTarget ComposeOver(const UsdEditTarget &weaker) const;
202 
203 private:
204 
205  UsdEditTarget(const SdfLayerHandle &layer,
206  const PcpMapFunction &mapping);
207 
208  SdfLayerHandle _layer;
209  PcpMapFunction _mapping;
210 };
211 
212 
214 
215 #endif // PXR_USD_USD_EDIT_TARGET_H
USD_API SdfPath MapToSpecPath(const SdfPath &scenePath) const
bool IsValid() const
Definition: editTarget.h:122
#define USD_API
Definition: api.h:23
USD_API SdfSpecHandle GetSpecForScenePath(const SdfPath &scenePath) const
PXR_NAMESPACE_OPEN_SCOPE TF_DECLARE_WEAK_PTRS(UsdStage)
bool operator!=(const UsdEditTarget &other) const
Inequality comparison.
Definition: editTarget.h:112
GLenum GLuint GLint GLint layer
Definition: glcorearb.h:1299
GLintptr offset
Definition: glcorearb.h:665
USD_API UsdEditTarget ComposeOver(const UsdEditTarget &weaker) const
bool IsNull() const
Definition: editTarget.h:118
const PcpMapFunction & GetMapFunction() const
Definition: editTarget.h:189
USD_API SdfPrimSpecHandle GetPrimSpecForScenePath(const SdfPath &scenePath) const
static USD_API UsdEditTarget ForLocalDirectVariant(const SdfLayerHandle &layer, const SdfPath &varSelPath)
Definition: path.h:273
USD_API SdfRelationshipSpecHandle GetRelationshipSpecForScenePath(const SdfPath &scenePath) const
USD_API SdfPropertySpecHandle GetPropertySpecForScenePath(const SdfPath &scenePath) const
const SdfLayerHandle & GetLayer() const &
Return the layer this EditTarget contains.
Definition: editTarget.h:125
USD_API SdfAttributeSpecHandle GetAttributeSpecForScenePath(const SdfPath &scenePath) const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
USD_API UsdEditTarget()
SdfLayerHandle GetLayer()&&
Definition: editTarget.h:126
USD_API bool operator==(const UsdEditTarget &other) const
Equality comparison.