HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
primCompositionQuery.h
Go to the documentation of this file.
1 //
2 // Copyright 2019 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_PRIM_COMPOSITION_QUERY_H
8 #define PXR_USD_USD_PRIM_COMPOSITION_QUERY_H
9 
10 /// \file usd/primCompositionQuery.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/usd/api.h"
14 #include "pxr/usd/usd/prim.h"
15 
16 #include "pxr/usd/pcp/node.h"
17 #include "pxr/usd/pcp/primIndex.h"
18 
19 #include <memory>
20 
22 
23 /// \class UsdPrimCompositionQueryArc
24 ///
25 /// This represents a composition arc that is returned by a
26 /// UsdPrimCompositionQuery. It contains the node in the composition graph that
27 /// is the target of this arc as well as access to information about how the
28 /// arc was introduced to the composition graph.
29 ///
30 /// \section UsdQueryRootArc Root Arc
31 /// If this arc's \ref GetArcType "arc type" is \ref PcpArcType "PcpArcTypeRoot",
32 /// then this arc represents the root node of the graph. The composition graph's
33 /// root arc is not an authored arc; it exists to target the root node of the
34 /// graph which represents any local opinions that may be defined for the prim
35 /// in the root layer stack.
37 {
38 public:
39  ~UsdPrimCompositionQueryArc() = default;
40 
41  /// \name Target and Introducing Nodes
42  /// These functions access either the target or the introducing nodes in
43  /// the composition graph that this arc represents. The returned node from
44  /// GetTargetNode(), along with a layer obtained from the layer stack
45  /// accessible through the node's GetLayerStack() function, can be used to
46  /// create a \ref UsdEditTarget to direct edits to the target of the arc.
47  /// The same can be done with the introducing node but there are additional
48  /// functions below that are more convenient for directly editing the
49  /// included arcs.
50  ///
51  /// It is important to be aware that the nodes returned by GetTargetNode()
52  /// and GetIntroducingNode() are only valid through the collective lifetime
53  /// of the UsdCompositionQuery and all the UsdPrimCompositionQueryArcs the
54  /// query returns. After the query and all the arcs have gone out of scope
55  /// every PcpNodeRef returned by these two functions will become immediately
56  /// invalid and its behavior will be undefined.
57  /// @{
58 
59  /// Returns the targeted node of this composition arc.
60  USD_API
61  PcpNodeRef GetTargetNode() const;
62 
63  /// Returns the node that introduces this arc into composition graph. This
64  /// is the node where the authored composition opinion exists and is not
65  /// necessarily the target node's parent. If this arc is the
66  /// \ref UsdQueryRootArc "root arc" then this function returns the same
67  /// node as GetTargetNode which is the root node of the composition graph.
68  USD_API
70 
71  /// @}
72 
73  /// \name Arc Target Details
74  /// @{
75 
76  /// Returns the root layer of the layer stack that holds the prim spec
77  /// targeted by this composition arc.
78  USD_API
79  SdfLayerHandle GetTargetLayer() const;
80 
81  /// Returns the path of the prim spec that is targeted by this composition
82  /// arc in the target layer stack.
83  USD_API
84  SdfPath GetTargetPrimPath() const;
85 
86  /// Creates and returns a resolve target that, when passed to a
87  /// UsdAttributeQuery for one of this prim's attributes, causes value
88  /// resolution to only consider node sites weaker than this arc, up to and
89  /// and including this arc's site itself.
90  ///
91  /// If \p subLayer is provided, it must be a layer in this arc's layer stack
92  /// and it will further limit value resolution to only the weaker layers up
93  /// to and including \p subLayer within this layer stack. (This is only with
94  /// respect to this arc; all layers will still be considered in the arcs
95  /// weaker than this arc).
96  USD_API
98  const SdfLayerHandle &subLayer = nullptr) const;
99 
100  /// Creates and returns a resolve target that, when passed to a
101  /// UsdAttributeQuery for one of this prim's attributes, causes value
102  /// resolution to only consider node sites stronger than this arc, not
103  /// including this arc itself (unless \p subLayer is provided).
104  ///
105  /// If \p subLayer is provided, it must be a layer in this arc's layer stack
106  /// and it will cause value resolution to additionally consider layers in
107  /// this arc but only if they are stronger than subLayer within this arc's
108  /// layer stack.
109  USD_API
111  const SdfLayerHandle &subLayer = nullptr) const;
112 
113  /// @}
114 
115  /// \name Arc Editing
116  /// This set of functions returns information about where the specific
117  /// opinions are authored that cause this arc to be included in the
118  /// composition graph. They can be used to edit the composition arcs
119  /// themselves.
120  /// @{
121 
122  /// Returns the specific layer in the layer stack that adds this arc to the
123  /// composition graph. This layer combined with the path returned from
124  /// GetIntroducingPrimPath can be used to find the prim spec which owns
125  /// the field that ultimately causes this arc to exist. If this arc is
126  /// the \ref UsdQueryRootArc "root arc" of the composition graph, it is not
127  /// an authored composition arc and this returns a null layer handle.
128  USD_API
129  SdfLayerHandle GetIntroducingLayer() const;
130 
131  /// Returns the path of the prim that introduces this arc to the composition
132  /// graph within the layer in which the composition opinion is authored.
133  /// This path combined with the layer returned from GetIntroducingLayer
134  /// can be used to find the prim spec which owns the field that ultimately
135  /// causes this arc to exist. If this arc is the
136  /// \ref UsdQueryRootArc "root arc" of the composition graph, it is not an
137  /// authored composition arc and this returns an empty path.
138  USD_API
140 
141  /// Gets the list editor and authored SdfReference value that introduces
142  /// this arc to the composition graph for reference arcs. If this arc's
143  /// type is reference, \p editor will be set to the reference list editor
144  /// of the introducing prim spec and \p ref will be set to the authored
145  /// value of the SdfReference in the reference list.
146  ///
147  /// This returns true if the \ref GetArcType "arc type" is
148  /// \ref PcpArcType "reference" and there are no errors; it returns false
149  /// for all other arc types.
150  USD_API
152  SdfReference *ref) const;
153 
154  /// Gets the list editor and authored SdfPayload value that introduces
155  /// this arc to the composition graph for payload arcs. If this arc's
156  /// type is payload, \p editor will be set to the payload list editor
157  /// of the introducing prim spec and \p payload will be set to the authored
158  /// value of the SdfPayload in the payload list.
159  ///
160  /// This returns true if the \ref GetArcType "arc type" is
161  /// \ref PcpArcType "payload" and there are no errors; it returns false
162  /// for all other arc types.
163  USD_API
165  SdfPayload *payload) const;
166 
167  /// Gets the list editor and authored SdfPath value that introduced
168  /// this arc to the composition graph for class arcs. If this arc's
169  /// type is inherit or specialize, \p editor will be set to the
170  /// corresponding path list editor of the introducing prim spec and \p path
171  /// will be set to the authored value of the SdfPath in the path list.
172  ///
173  /// This returns true if the \ref GetArcType "arc type" is either
174  /// \ref PcpArcType "inherit" or \ref PcpArcType "specialize" and
175  /// there are no errors; it returns false for all other arc types.
176  USD_API
178  SdfPath *path) const;
179 
180  /// Gets the list editor and authored string value that introduces
181  /// this arc to the composition graph for variant arcs. If this arc's
182  /// type is variant, \p editor will be set to the name list editor
183  /// of the introducing prim spec and \p name will be set to the authored
184  /// value of the variant set name in the name list.
185  ///
186  /// This returns true if the \ref GetArcType "arc type" is
187  /// \ref PcpArcType "variant" and there are no errors; it returns false
188  /// for all other arc types.
189  USD_API
191  std::string *name) const;
192 
193  /// @}
194 
195  /// \name Arc classification
196  /// Queries about the arc that are useful for classifying the arc for
197  /// filtering.
198  /// @{
199 
200  /// Returns the arc type.
201  USD_API
202  PcpArcType GetArcType() const;
203 
204  /// Returns whether this arc was implicitly added to this prim meaning it
205  /// exists because of the introduction of another composition arc. These
206  /// will typically exist due to inherits or specializes that are authored
207  /// across a reference.
208  USD_API
209  bool IsImplicit() const;
210 
211  /// Returns whether this arc is ancestral, i.e. it exists because it was
212  /// composed in by a namespace parent's prim index.
213  USD_API
214  bool IsAncestral() const;
215 
216  /// Returns whether the target node of this arc contributes any local spec
217  /// opinions that are composed for the prim.
218  USD_API
219  bool HasSpecs() const;
220 
221  /// Returns whether the composition opinion that introduces this arc
222  /// is authored in the root layer stack. This returns true for any arcs
223  /// where the composition opinion can be authored in the root layer stack.
224  /// This is always true for the root arc.
225  USD_API
226  bool IsIntroducedInRootLayerStack() const;
227 
228  /// Returns whether the composition opinion that introduces this arc is
229  /// authored directly on the prim's prim spec within the root layer stack.
230  /// This is always true for the root arc.
231  USD_API
232  bool IsIntroducedInRootLayerPrimSpec() const;
233 
234  /// @}
235 
236 private:
237  // These will only be created by a UsdPrimCompositionQuery itself.
240 
241  PcpNodeRef _node;
242  PcpNodeRef _originalIntroducedNode;
243  PcpNodeRef _introducingNode;
244 
245  std::shared_ptr<PcpPrimIndex> _primIndex;
246 };
247 
248 /// \class UsdPrimCompositionQuery
249 ///
250 /// Object for making optionally filtered composition queries about a prim.
251 /// It creates a list of strength ordering UsdPrimCompositionQueryArc that
252 /// can be filtered by a combination of criteria and returned.
253 ///
254 /// \section UsdPrimCompositionQuery_Invalidation Invalidation
255 /// This object does not listen for change notification. If a consumer is
256 /// holding on to a UsdPrimCompositionQuery, it is their responsibility to
257 /// dispose of it in response to a resync change to the associated prim.
258 /// Failing to do so may result in incorrect values or crashes due to
259 /// dereferencing invalid objects.
261 {
262 public:
263  /// Choices for filtering composition arcs based on arc type
264  enum class ArcTypeFilter
265  {
266  All = 0,
267 
268  // Single arc types
269  Reference,
270  Payload,
271  Inherit,
272  Specialize,
273  Variant,
274 
275  // Related arc types
278 
279  // Inverse of related arc types
282  NotVariant
283  };
284 
285  /// Choices for filtering composition arcs on dependency type. This can
286  /// be direct (arc introduced at the prim's level in namespace) or ancestral
287  /// (arc introduced by a namespace parent of the prim).
289  {
290  All = 0,
291 
292  Direct,
293  Ancestral
294  };
295 
296  /// Choices for filtering composition arcs based on where the arc is
297  /// introduced.
299  {
300  All = 0,
301 
302  // Indicates that we only want arcs that are authored somewhere in the
303  // root layer stack.
305 
306  // Indicates that we only want arcs that are authored directly in the
307  // in the prim's prim spec in the root layer stack.
309  };
310 
311  /// Choices for filtering composition arcs on whether the node contributes
312  /// specs to the prim.
313  enum class HasSpecsFilter
314  {
315  All = 0,
316 
317  HasSpecs,
318  HasNoSpecs
319  };
320 
321  /// Aggregate filter for filtering composition arcs by the previously
322  /// defined criteria.
323  struct Filter
324  {
325  /// Filters by arc type
327 
328  /// Filters by dependency type, direct or ancestral.
330 
331  /// Filters by where the arc is introduced
333 
334  /// Filters by whether the arc provides specs for the prim.
336 
337  Filter() {};
338 
339  bool operator==(const Filter &rhs) {
341  arcTypeFilter == rhs.arcTypeFilter &&
344  };
345 
346  bool operator!=(const Filter &rhs) {
347  return !(*this == rhs);
348  };
349  };
350 
351  /// Returns a prim composition query for the given \p prim with a preset
352  /// filter that only returns reference arcs that are not ancestral.
353  USD_API
355 
356  /// Returns a prim composition query for the given \p prim with a preset
357  /// filter that only returns inherit arcs that are not ancestral.
358  USD_API
360 
361  /// Returns a prim composition query for the given \p prim with a preset
362  /// filter that only returns direct arcs that were introduced by opinions
363  /// defined in a layer in the root layer stack.
364  USD_API
366 
367  /// Create a prim composition query for the \p with the given option
368  /// \p filter.
369  USD_API
370  UsdPrimCompositionQuery(const UsdPrim & prim,
371  const Filter &filter = Filter());
372 
373  ~UsdPrimCompositionQuery() = default;
374 
375  /// Change the filter for this query.
376  USD_API
377  void SetFilter(const Filter &filter);
378 
379  /// Return a copy of the current filter parameters.
380  USD_API
381  Filter GetFilter() const;
382 
383  /// Return a list of composition arcs for this query's prim using the
384  /// current query filter. The composition arcs are always returned in order
385  /// from strongest to weakest regardless of the filter.
386  USD_API
387  std::vector<UsdPrimCompositionQueryArc> GetCompositionArcs();
388 
389 private:
390  UsdPrim _prim;
391  Filter _filter;
392  std::shared_ptr<PcpPrimIndex> _expandedPrimIndex;
393  std::vector<UsdPrimCompositionQueryArc> _unfilteredArcs;
394 };
395 
396 
398 
399 #endif // PXR_USD_USD_PRIM_COMPOSITION_QUERY_H
400 
#define USD_API
Definition: api.h:23
USD_API bool IsImplicit() const
USD_API PcpNodeRef GetTargetNode() const
Returns the targeted node of this composition arc.
ArcIntroducedFilter arcIntroducedFilter
Filters by where the arc is introduced.
~UsdPrimCompositionQueryArc()=default
bool operator==(const Filter &rhs)
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
USD_API SdfLayerHandle GetIntroducingLayer() const
static USD_API UsdPrimCompositionQuery GetDirectRootLayerArcs(const UsdPrim &prim)
ArcTypeFilter arcTypeFilter
Filters by arc type.
USD_API SdfPath GetTargetPrimPath() const
USD_API SdfLayerHandle GetTargetLayer() const
USD_API bool IsIntroducedInRootLayerPrimSpec() const
bool operator!=(const Filter &rhs)
ArcTypeFilter
Choices for filtering composition arcs based on arc type.
USD_API PcpArcType GetArcType() const
Returns the arc type.
USD_API std::vector< UsdPrimCompositionQueryArc > GetCompositionArcs()
GLint ref
Definition: glcorearb.h:124
USD_API PcpNodeRef GetIntroducingNode() const
static USD_API UsdPrimCompositionQuery GetDirectInherits(const UsdPrim &prim)
HasSpecsFilter hasSpecsFilter
Filters by whether the arc provides specs for the prim.
USD_API UsdResolveTarget MakeResolveTargetUpTo(const SdfLayerHandle &subLayer=nullptr) const
USD_API void SetFilter(const Filter &filter)
Change the filter for this query.
USD_API bool GetIntroducingListEditor(SdfReferenceEditorProxy *editor, SdfReference *ref) const
~UsdPrimCompositionQuery()=default
Definition: prim.h:116
GLuint const GLchar * name
Definition: glcorearb.h:786
Definition: path.h:273
static USD_API UsdPrimCompositionQuery GetDirectReferences(const UsdPrim &prim)
USD_API Filter GetFilter() const
Return a copy of the current filter parameters.
USD_API UsdResolveTarget MakeResolveTargetStrongerThan(const SdfLayerHandle &subLayer=nullptr) const
USD_API SdfPath GetIntroducingPrimPath() const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
USD_API bool IsIntroducedInRootLayerStack() const
USD_API bool HasSpecs() const
USD_API bool IsAncestral() const
DependencyTypeFilter dependencyTypeFilter
Filters by dependency type, direct or ancestral.
USD_API UsdPrimCompositionQuery(const UsdPrim &prim, const Filter &filter=Filter())
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1297
PcpArcType
Definition: types.h:27