HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
collectionAPI.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 USD_GENERATED_COLLECTIONAPI_H
8 #define USD_GENERATED_COLLECTIONAPI_H
9 
10 /// \file usd/collectionAPI.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/usd/api.h"
15 #include "pxr/usd/usd/prim.h"
16 #include "pxr/usd/usd/stage.h"
17 #include "pxr/usd/usd/tokens.h"
18 
20 #include "pxr/usd/usd/primFlags.h"
21 #include "pxr/usd/usd/tokens.h"
23 
24 
25 #include "pxr/base/vt/value.h"
26 
27 #include "pxr/base/gf/vec3d.h"
28 #include "pxr/base/gf/vec3f.h"
29 #include "pxr/base/gf/matrix4d.h"
30 
31 #include "pxr/base/tf/token.h"
32 #include "pxr/base/tf/type.h"
33 
35 
36 class SdfAssetPath;
37 
38 // -------------------------------------------------------------------------- //
39 // COLLECTIONAPI //
40 // -------------------------------------------------------------------------- //
41 
42 /// \class UsdCollectionAPI
43 ///
44 /// A general purpose API schema used to describe a collection of prims
45 /// and properties within a scene. This API schema can be applied to a prim
46 /// multiple times with different instance names to define several collections
47 /// on a single prim.
48 ///
49 /// A collection's membership is specified one of two ways. The first way uses
50 /// the built-in relationships `includes` and `excludes`, and the attribute
51 /// `includeRoot` to determine membership. The second way is termed a
52 /// pattern-based collection, and uses the built-in attribute
53 /// `membershipExpression` to determine membership. Here we will refer to
54 /// collections using `includes`, `excludes` and `includeRoot` as being in
55 /// *relationship-mode* and those using the `membershipExpression` as being in
56 /// *expression-mode*.
57 ///
58 /// The `mode` attribute controls which mode the collection uses. When set to
59 /// `relationship` the collection is explicitly in *relationship-mode*, and when
60 /// set to `expression` it is explicitly in *expression-mode*. Properties
61 /// belonging to the non-selected mode are ignored. When `mode` is `automatic`
62 /// (the default), the mode is inferred from the collection's authored
63 /// properties: the collection is in *relationship-mode* when either or both of
64 /// its `includes` and `excludes` relationships have valid targets, or the
65 /// `includeRoot` attribute is set to `true`; otherwise it is in
66 /// *expression-mode* and the `membershipExpression` attribute applies.
67 ///
68 /// In *relationship-mode* the `includes` and `excludes` relationships specify
69 /// the collection members as a set of paths to include and a set of paths to
70 /// exclude. Whether or not the descendants of an included path belong to a
71 /// collection is decided by its expansion rule (see below). If the collection
72 /// excludes paths that are not descendent to included paths, the collection
73 /// implicitly includes the root path `</>`. If such a collection also
74 /// includes paths that are not descendent to the excluded paths, it is
75 /// considered invalid since the intent is ambiguous.
76 ///
77 /// In *expression-mode*, the pattern-based `membershipExpression` attribute is
78 /// used with the `expansionRule` attribute to determine collection membership.
79 /// See the detailed descriptions of the built-in properties below for more
80 /// details.
81 ///
82 /// \section usd_collectionapi_properties Collection API Properties
83 ///
84 /// The built-in properties for this schema are in the `collection:instanceName`
85 /// namespace, where `instanceName` is the user-provided applied API schema
86 /// instance name.
87 ///
88 /// <ul>
89 /// <li>`uniform token collection:instanceName:expansionRule` - in
90 /// *relationship-mode*, specifies how to expand the `includes` and `excludes`
91 /// relationship targets to determine the collection's members. In
92 /// *expression-mode*, specifies how matching scene objects against the
93 /// `membershipExpression` proceeds. Possible values include:
94 /// <ul>
95 /// <li>`expandPrims` - in *relationship-mode*, all the prims descendent
96 /// to the `includes` relationship targets (and not descendent to `excludes`
97 /// relationship targets) belong to the collection. Any `includes`-targeted
98 /// property paths also belong to the collection. This is the default
99 /// behavior. In *expression-mode*, the functions
100 /// UsdComputeIncludedObjectsFromCollection() and
101 /// UsdComputeIncludedPathsFromCollection() only test prims against the
102 /// `membershipExpression` to determine membership.
103 /// </li>
104 /// <li>`expandPrimsAndProperties` - like `expandPrims`, but in
105 /// *relationship-mode*, all properties on all included prims also belong to
106 /// the collection. In *expression-mode*, the functions
107 /// UsdComputeIncludedObjectsFromCollection() and
108 /// UsdComputeIncludedPathsFromCollection() test both prims and
109 /// properties against the `membershipExpression` to determine membership.
110 /// </li>
111 /// <li>`explicitOnly` - in *relationship-mode*, only paths in the
112 /// `includes` relationship targets and not those in the `excludes`
113 /// relationship targets belong to the collection. Does not apply to
114 /// *expression-mode*. If set in *expression-mode*, the functions
115 /// UsdComputeIncludedObjectsFromCollection() and
116 /// UsdComputeIncludedPathsFromCollection() return no results.
117 /// </li>
118 /// </ul>
119 /// </li>
120 ///
121 /// <li>`bool collection:instanceName:includeRoot` - boolean attribute
122 /// indicating whether the pseudo-root path `</>` should be counted as one
123 /// of the included target paths in *relationship-mode*. This separate attribute
124 /// is required because relationships cannot directly target the root. When
125 /// `expansionRule` is `explicitOnly`, this attribute is ignored. The fallback
126 /// value is false. When set to `true`, this collection is in
127 /// *relationship-mode*. This attribute is ignored in *expression-mode*. </li>
128 ///
129 /// <li>`rel collection:instanceName:includes` - in *relationship-mode*,
130 /// specifies a list of targets that are included in the collection. This can
131 /// target prims or properties directly. A collection can insert the rules of
132 /// another collection by making its `includes` relationship target the
133 /// `collection:otherInstanceName` property from the collection to be included
134 /// (see UsdCollectionAPI::GetCollectionAttr). Note that including another
135 /// collection does not guarantee the contents of that collection will be in the
136 /// final collection; instead, the rules are merged. This means, for example,
137 /// an exclude entry may exclude a portion of the included collection. When a
138 /// collection includes one or more collections, the order in which targets are
139 /// added to the includes relationship may become significant, if there are
140 /// conflicting opinions about the same path. Targets that are added later are
141 /// considered to be stronger than earlier targets for the same path. This
142 /// relationship is ignored in *expression-mode*.</li>
143 ///
144 /// <li>`rel collection:instanceName:excludes` - in *relationship-mode*,
145 /// specifies a list of targets that are excluded below the <b>included</b>
146 /// paths in this collection. This can target prims or properties directly, but
147 /// <b>cannot target another collection</b>. This is to keep the membership
148 /// determining logic simple, efficient and easier to reason about. Finally, it
149 /// is invalid for a collection to exclude paths that are not included in
150 /// it. The presence of such "orphaned" excluded paths will not affect the set
151 /// of paths included in the collection, but may affect the performance of
152 /// querying membership of a path in the collection (see
153 /// UsdCollectionMembershipQuery::IsPathIncluded) or of enumerating the
154 /// objects belonging to the collection (see
155 /// UsdCollectionAPI::ComputeIncludedObjects). This relationship is ignored in
156 /// *expression-mode*.</li>
157 ///
158 /// <li>`uniform opaque collection:instanceName` - opaque
159 /// attribute (meaning it can never have a value) that represents the collection
160 /// for the purpose of allowing another collection to include it in
161 /// *relationship-mode*. When this property is targeted by another collection's
162 /// `includes` relationship, the rules of this collection will be inserted
163 /// into the rules of the collection that includes it.</li>
164 ///
165 /// <li>`uniform pathExpression collection:instanceName:membershipExpression` -
166 /// in *expression-mode*, defines the SdfPathExpression used to test
167 /// objects for collection membership.</li>
168 ///
169 /// </ul>
170 ///
171 /// \subsection usd_collectionapi_implicit_inclusion Implicit Inclusion
172 ///
173 /// In some scenarios it is useful to express a collection that includes
174 /// everything except certain paths. To support this, a *relationship-mode*
175 /// collection that has an exclude that is not descendent to any include will
176 /// include the root path `</>`.
177 ///
178 /// \section usd_collectionapi_creating_cpp Creating Collections in C++
179 ///
180 /// \snippet examples_usd.cpp ApplyCollections
181 ///
182 ///
183 /// For any described attribute \em Fallback \em Value or \em Allowed \em Values below
184 /// that are text/tokens, the actual token is published and defined in \ref UsdTokens.
185 /// So to set an attribute to the value "rightHanded", use UsdTokens->rightHanded
186 /// as the value.
187 ///
189 {
190 public:
191  /// Compile time constant representing what kind of schema this class is.
192  ///
193  /// \sa UsdSchemaKind
195 
196  /// Construct a UsdCollectionAPI on UsdPrim \p prim with
197  /// name \p name . Equivalent to
198  /// UsdCollectionAPI::Get(
199  /// prim.GetStage(),
200  /// prim.GetPath().AppendProperty(
201  /// "collection:name"));
202  ///
203  /// for a \em valid \p prim, but will not immediately throw an error for
204  /// an invalid \p prim
206  const UsdPrim& prim=UsdPrim(), const TfToken &name=TfToken())
207  : UsdAPISchemaBase(prim, /*instanceName*/ name)
208  { }
209 
210  /// Construct a UsdCollectionAPI on the prim held by \p schemaObj with
211  /// name \p name. Should be preferred over
212  /// UsdCollectionAPI(schemaObj.GetPrim(), name), as it preserves
213  /// SchemaBase state.
215  const UsdSchemaBase& schemaObj, const TfToken &name)
216  : UsdAPISchemaBase(schemaObj, /*instanceName*/ name)
217  { }
218 
219  /// Destructor.
220  USD_API
221  virtual ~UsdCollectionAPI();
222 
223  /// Return a vector of names of all pre-declared attributes for this schema
224  /// class and all its ancestor classes. Does not include attributes that
225  /// may be authored by custom/extended methods of the schemas involved.
226  USD_API
227  static const TfTokenVector &
228  GetSchemaAttributeNames(bool includeInherited=true);
229 
230  /// Return a vector of names of all pre-declared attributes for this schema
231  /// class and all its ancestor classes for a given instance name. Does not
232  /// include attributes that may be authored by custom/extended methods of
233  /// the schemas involved. The names returned will have the proper namespace
234  /// prefix.
235  USD_API
236  static TfTokenVector
237  GetSchemaAttributeNames(bool includeInherited, const TfToken &instanceName);
238 
239  /// Returns the name of this multiple-apply schema instance
240  TfToken GetName() const {
241  return _GetInstanceName();
242  }
243 
244  /// Return a UsdCollectionAPI holding the prim adhering to this
245  /// schema at \p path on \p stage. If no prim exists at \p path on
246  /// \p stage, or if the prim at that path does not adhere to this schema,
247  /// return an invalid schema object. \p path must be of the format
248  /// <path>.collection:name .
249  ///
250  /// This is shorthand for the following:
251  ///
252  /// \code
253  /// TfToken name = SdfPath::StripNamespace(path.GetToken());
254  /// UsdCollectionAPI(
255  /// stage->GetPrimAtPath(path.GetPrimPath()), name);
256  /// \endcode
257  ///
258  USD_API
259  static UsdCollectionAPI
260  Get(const UsdStagePtr &stage, const SdfPath &path);
261 
262  /// Return a UsdCollectionAPI with name \p name holding the
263  /// prim \p prim. Shorthand for UsdCollectionAPI(prim, name);
264  USD_API
265  static UsdCollectionAPI
266  Get(const UsdPrim &prim, const TfToken &name);
267 
268  /// Return a vector of all named instances of UsdCollectionAPI on the
269  /// given \p prim.
270  USD_API
271  static std::vector<UsdCollectionAPI>
272  GetAll(const UsdPrim &prim);
273 
274  /// Checks if the given name \p baseName is the base name of a property
275  /// of CollectionAPI.
276  USD_API
277  static bool
278  IsSchemaPropertyBaseName(const TfToken &baseName);
279 
280  /// Checks if the given path \p path is of an API schema of type
281  /// CollectionAPI. If so, it stores the instance name of
282  /// the schema in \p name and returns true. Otherwise, it returns false.
283  USD_API
284  static bool
286 
287  /// Returns true if this <b>multiple-apply</b> API schema can be applied,
288  /// with the given instance name, \p name, to the given \p prim. If this
289  /// schema can not be a applied the prim, this returns false and, if
290  /// provided, populates \p whyNot with the reason it can not be applied.
291  ///
292  /// Note that if CanApply returns false, that does not necessarily imply
293  /// that calling Apply will fail. Callers are expected to call CanApply
294  /// before calling Apply if they want to ensure that it is valid to
295  /// apply a schema.
296  ///
297  /// \sa UsdPrim::GetAppliedSchemas()
298  /// \sa UsdPrim::HasAPI()
299  /// \sa UsdPrim::CanApplyAPI()
300  /// \sa UsdPrim::ApplyAPI()
301  /// \sa UsdPrim::RemoveAPI()
302  ///
303  USD_API
304  static bool
305  CanApply(const UsdPrim &prim, const TfToken &name,
306  std::string *whyNot=nullptr);
307 
308  /// Applies this <b>multiple-apply</b> API schema to the given \p prim
309  /// along with the given instance name, \p name.
310  ///
311  /// This information is stored by adding "CollectionAPI:<i>name</i>"
312  /// to the token-valued, listOp metadata \em apiSchemas on the prim.
313  /// For example, if \p name is 'instance1', the token
314  /// 'CollectionAPI:instance1' is added to 'apiSchemas'.
315  ///
316  /// \return A valid UsdCollectionAPI object is returned upon success.
317  /// An invalid (or empty) UsdCollectionAPI object is returned upon
318  /// failure. See \ref UsdPrim::ApplyAPI() for
319  /// conditions resulting in failure.
320  ///
321  /// \sa UsdPrim::GetAppliedSchemas()
322  /// \sa UsdPrim::HasAPI()
323  /// \sa UsdPrim::CanApplyAPI()
324  /// \sa UsdPrim::ApplyAPI()
325  /// \sa UsdPrim::RemoveAPI()
326  ///
327  USD_API
328  static UsdCollectionAPI
329  Apply(const UsdPrim &prim, const TfToken &name);
330 
331 protected:
332  /// Returns the kind of schema this class belongs to.
333  ///
334  /// \sa UsdSchemaKind
335  USD_API
336  UsdSchemaKind _GetSchemaKind() const override;
337 
338 private:
339  // needs to invoke _GetStaticTfType.
340  friend class UsdSchemaRegistry;
341  USD_API
342  static const TfType &_GetStaticTfType();
343 
344  static bool _IsTypedSchema();
345 
346  // override SchemaBase virtuals.
347  USD_API
348  const TfType &_GetTfType() const override;
349 
350 public:
351  // --------------------------------------------------------------------- //
352  // EXPANSIONRULE
353  // --------------------------------------------------------------------- //
354  /// Specifies how the paths that are included in
355  /// the collection must be expanded to determine its members.
356  ///
357  /// | ||
358  /// | -- | -- |
359  /// | Declaration | `uniform token expansionRule = "expandPrims"` |
360  /// | C++ Type | TfToken |
361  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token |
362  /// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
363  /// | \ref UsdTokens "Allowed Values" | explicitOnly, expandPrims, expandPrimsAndProperties |
364  USD_API
366 
367  /// See GetExpansionRuleAttr(), and also
368  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
369  /// If specified, author \p defaultValue as the attribute's default,
370  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
371  /// the default for \p writeSparsely is \c false.
372  USD_API
373  UsdAttribute CreateExpansionRuleAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
374 
375 public:
376  // --------------------------------------------------------------------- //
377  // INCLUDEROOT
378  // --------------------------------------------------------------------- //
379  /// Boolean attribute indicating whether the pseudo-root
380  /// path `</>` should be counted as one of the included target
381  /// paths. The fallback is false. This separate attribute is
382  /// required because relationships cannot directly target the root.
383  ///
384  /// | ||
385  /// | -- | -- |
386  /// | Declaration | `uniform bool includeRoot` |
387  /// | C++ Type | bool |
388  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Bool |
389  /// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
390  USD_API
392 
393  /// See GetIncludeRootAttr(), and also
394  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
395  /// If specified, author \p defaultValue as the attribute's default,
396  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
397  /// the default for \p writeSparsely is \c false.
398  USD_API
399  UsdAttribute CreateIncludeRootAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
400 
401 public:
402  // --------------------------------------------------------------------- //
403  // MEMBERSHIPEXPRESSION
404  // --------------------------------------------------------------------- //
405  /// Specifies a path expression that determines membership in this
406  /// collection.
407  ///
408  /// | ||
409  /// | -- | -- |
410  /// | Declaration | `uniform pathExpression membershipExpression` |
411  /// | C++ Type | SdfPathExpression |
412  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->PathExpression |
413  /// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
414  USD_API
416 
417  /// See GetMembershipExpressionAttr(), and also
418  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
419  /// If specified, author \p defaultValue as the attribute's default,
420  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
421  /// the default for \p writeSparsely is \c false.
422  USD_API
423  UsdAttribute CreateMembershipExpressionAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
424 
425 public:
426  // --------------------------------------------------------------------- //
427  // MODE
428  // --------------------------------------------------------------------- //
429  /// Specifies which mode the collection uses to determine
430  /// membership: `automatic`, `relationship`, or `expression`.
431  /// <ul>
432  /// <li>`automatic` - the collection's mode is inferred from its authored
433  /// properties. If either or both of the `includes` and `excludes`
434  /// relationships have valid targets, or the `includeRoot` attribute is set
435  /// to `true`, the collection is in *relationship-mode* and the
436  /// `membershipExpression` attribute is ignored. Otherwise, the collection
437  /// is in *expression-mode* and the `membershipExpression` attribute
438  /// applies. This is the default behavior and is backward compatible with
439  /// collections that predate this attribute.</li>
440  /// <li>`relationship` - the collection is explicitly in
441  /// *relationship-mode*. The `includes`, `excludes`, and `includeRoot`
442  /// attributes determine membership, and `membershipExpression` is
443  /// ignored.</li>
444  /// <li>`expression` - the collection is explicitly in *expression-mode*.
445  /// The `membershipExpression` attribute determines membership, and
446  /// `includes`, `excludes`, and `includeRoot` are ignored.</li>
447  /// </ul>
448  /// The fallback value is `automatic`.
449  ///
450  /// | ||
451  /// | -- | -- |
452  /// | Declaration | `uniform token mode = "automatic"` |
453  /// | C++ Type | TfToken |
454  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token |
455  /// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
456  /// | \ref UsdTokens "Allowed Values" | automatic, relationship, expression |
457  USD_API
458  UsdAttribute GetModeAttr() const;
459 
460  /// See GetModeAttr(), and also
461  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
462  /// If specified, author \p defaultValue as the attribute's default,
463  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
464  /// the default for \p writeSparsely is \c false.
465  USD_API
466  UsdAttribute CreateModeAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
467 
468 public:
469  // --------------------------------------------------------------------- //
470  // COLLECTION
471  // --------------------------------------------------------------------- //
472  /// This property represents the collection for the purpose of
473  /// allowing another collection to include it. When this property is
474  /// targeted by another collection's <i>includes</i> relationship, the rules
475  /// of this collection will be inserted into the rules of the collection
476  /// that includes it.
477  ///
478  ///
479  /// | ||
480  /// | -- | -- |
481  /// | Declaration | `uniform opaque __INSTANCE_NAME__` |
482  /// | C++ Type | SdfOpaqueValue |
483  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Opaque |
484  /// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
485  USD_API
487 
488  /// See GetCollectionAttr(), and also
489  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
490  /// If specified, author \p defaultValue as the attribute's default,
491  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
492  /// the default for \p writeSparsely is \c false.
493  USD_API
494  UsdAttribute CreateCollectionAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
495 
496 public:
497  // --------------------------------------------------------------------- //
498  // INCLUDES
499  // --------------------------------------------------------------------- //
500  /// Specifies a list of targets that are included in the collection.
501  /// This can target prims or properties directly. A collection can insert
502  /// the rules of another collection by making its <i>includes</i>
503  /// relationship target the <b>collection:{collectionName}</b> property on
504  /// the owning prim of the collection to be included
505  ///
506  USD_API
508 
509  /// See GetIncludesRel(), and also
510  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create
511  USD_API
513 
514 public:
515  // --------------------------------------------------------------------- //
516  // EXCLUDES
517  // --------------------------------------------------------------------- //
518  /// Specifies a list of targets that are excluded below
519  /// the included paths in this collection. This can target prims or
520  /// properties directly, but cannot target another collection. This is to
521  /// keep the membership determining logic simple, efficient and easier to
522  /// reason about. Finally, it is invalid for a collection to exclude
523  /// paths that are not included in it. The presence of such "orphaned"
524  /// excluded paths will not affect the set of paths included in the
525  /// collection, but may affect the performance of querying membership of
526  /// a path in the collection (see
527  /// UsdCollectionAPI::MembershipQuery::IsPathIncluded)
528  /// or of enumerating the objects belonging to the collection (see
529  /// UsdCollectionAPI::GetIncludedObjects).
530  ///
531  USD_API
533 
534  /// See GetExcludesRel(), and also
535  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create
536  USD_API
538 
539 public:
540  // ===================================================================== //
541  // Feel free to add custom code below this line, it will be preserved by
542  // the code generator.
543  //
544  // Just remember to:
545  // - Close the class declaration with };
546  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
547  // - Close the include guard with #endif
548  // ===================================================================== //
549  // --(BEGIN CUSTOM CODE)--
550 
551 public:
552  /// Returns the collection represented by the given collection path,
553  /// \p collectionPath on the given USD stage.
554  USD_API
555  static UsdCollectionAPI GetCollection(const UsdStagePtr &stage,
556  const SdfPath &collectionPath);
557 
558  /// Returns the schema object representing a collection named \p name on
559  /// the given \p prim.
560  USD_API
561  static UsdCollectionAPI GetCollection(const UsdPrim &prim,
562  const TfToken &name);
563 
564  /// Returns all the named collections on the given USD prim.
565  /// \deprecated Use GetAll(prim) instead.
566  USD_API
567  static std::vector<UsdCollectionAPI> GetAllCollections(const UsdPrim &prim);
568 
569  /// Returns the canonical path that represents this collection.
570  /// This points to the property named "collection:{collectionName}" on the
571  /// prim defining the collection. This is the path to be used to "include"
572  /// this collection in another collection.
573  ///
574  /// \sa GetCollectionAttr()
575  USD_API
576  SdfPath GetCollectionPath() const;
577 
578  /// Returns the canonical path to the collection named, \p name on the given
579  /// prim, \p prim.
580  ///
581  /// \sa GetCollectionPath()
582  USD_API
584  const UsdPrim &prim,
585  const TfToken &collectionName);
586 
587  /// Obtain a complete SdfPathExpression from this collection's
588  /// membershipExpression. First, UsdAttribute::Get() the value of
589  /// GetMembershipExpressionAttr(), then resolve any contained references.
590  /// Replace any remaining "weaker" references (%_) with
591  /// SdfPathExpression::Nothing(). Replace other references by recursively
592  /// resolving the expressions from the collections on the referenced prims.
593  /// If no such prims or no such collections exist, replace those references
594  /// with SdfPathExpression::Nothing() as well.
595  USD_API
597 
598  // Convenient alias for UsdCollectionMembershipQuery object
600 
601  /// Computes and returns a UsdCollectionMembershipQuery object which can
602  /// be used to query inclusion or exclusion of paths in the collection.
603  USD_API
605 
606  /// Populates the UsdCollectionMembershipQuery object with data from this
607  /// collection, so it can be used to query inclusion or exclusion of paths.
608  USD_API
610 
611  /// Return true if the collection cannot possibly include anything.
612  ///
613  /// For collections in relationships-mode, this is the case if the includes
614  /// relationship has no target paths, and the includeRoot attribute is
615  /// false.
616  ///
617  /// For collections in expression-mode, this is the case if the
618  /// membershipExpression attribute has either no opinion or if it is
619  /// SdfPathExpression::Nothing().
620  ///
621  /// Note that there may be cases where the collection includes no objects
622  /// despite HasNoIncludedPaths() returning false. For example, if the
623  /// included objects are unloaded, or if the included objects are also
624  /// excluded, or if an authored non-empty membershipExpression happens not
625  /// to match any objects on the stage.
626  USD_API
627  bool HasNoIncludedPaths() const;
628 
629  /// Return true if this collection is *relationships-mode*. That is, if it
630  /// uses the `includes` and `excludes` relationships to determine membership
631  /// and not the `membershipExpression` attribute. This is the case when the
632  /// `mode` attribute is set to `relationship`, or when the mode attribute is
633  /// set to `automatic` and either or both of its `includes` and `excludes`
634  /// relationships have valid targets, or the `includeRoot` attribute is set
635  /// `true`. This is equivalent to `!IsInExpressionMode()`.
636  USD_API
637  bool IsInRelationshipsMode() const;
638 
639  /// Return true if this collection is *expression-mode*. That is, if it
640  /// uses the `membershipExpression` attribute to determine membership and
641  /// not the `includes` and `excludes` relationships. This is the case when
642  /// the `mode` attribute is set to `expression`, or when the mode attribute
643  /// is set to `automatic` and none of the relationship-mode related
644  /// properties are authored. Equivalent to `!IsInRelationshipsMode()`.
645  bool IsInExpressionMode() const {
646  return !IsInRelationshipsMode();
647  }
648 
649  /// Returns all the usd objects that satisfy the predicate, \p pred in the
650  /// collection represented by the UsdCollectionMembershipQuery object, \p
651  /// query.
652  ///
653  /// The results depends on the load state of the UsdStage, \p stage.
654  USD_API
655  static std::set<UsdObject> ComputeIncludedObjects(
657  const UsdStageWeakPtr &stage,
659 
660  /// Returns all the paths that satisfy the predicate, \p pred in the
661  /// collection represented by the UsdCollectionMembershipQuery object, \p
662  /// query.
663  ///
664  /// The result depends on the load state of the UsdStage, \p stage.
665  USD_API
668  const UsdStageWeakPtr &stage,
670 
671  /// \anchor UsdCollectionAPI_AuthoringAPI
672  /// \name Collection Authoring API
673  ///
674  /// Convenience API for adding or removing prims and properties to (or
675  /// from) a collection..
676  ///
677  /// @{
678 
679  /// Includes or adds the given path, \p pathToInclude in the collection.
680  ///
681  /// This does nothing if the path is already included in the collection.
682  ///
683  /// This does not modify the expansion-rule of the collection. Hence, if the
684  /// expansionRule is <i>expandPrims</i> or <i>expandPrimsAndProperties</i>,
685  /// then the descendants of \p pathToInclude will be also included in the
686  /// collection unless explicitly excluded.
687  ///
688  /// \sa UsdCollectionAPI::ExcludePath()
689  USD_API
690  bool IncludePath(const SdfPath &pathToInclude) const;
691 
692  /// Excludes or removes the given path, \p pathToExclude from the collection.
693  ///
694  /// If the collection is empty, the collection becomes one that
695  /// includes all paths except the givne path. Otherwise, this does
696  /// nothing if the path is not included in the collection.
697  ///
698  /// This does not modify the expansion-rule of the collection. Hence, if the
699  /// expansionRule is <i>expandPrims</i> or <i>expandPrimsAndProperties</i>,
700  /// then the descendants of \p pathToExclude will also be excluded from the
701  /// collection, unless explicitly included.
702  ///
703  /// \sa UsdCollectionAPI::IncludePath()
704  USD_API
705  bool ExcludePath(const SdfPath &pathToExclude) const;
706 
707  /// @}
708 
709  /// Validates the collection by checking the following rules:
710  /// * a collection's expansionRule should be one of "explicitOnly",
711  /// "expandPrims" or "expandPrimsAndProperties".
712  /// * a collection should not have have a circular dependency on
713  /// another collection.
714  /// * a collection should not have both includes and excludes
715  /// among its top-level rules
716  USD_API
717  bool Validate(std::string *reason) const;
718 
719  /// Resets the collection by clearing both the includes and excludes
720  /// targets of the collection in the current UsdEditTarget.
721  ///
722  /// \note This does not modify the "includeRoot" attribute which is used
723  /// to include or exclude everything (i.e. the pseudoRoot) in the USD stage.
724  USD_API
725  bool ResetCollection() const;
726 
727  /// Blocks the targets of the includes and excludes relationships of the
728  /// collection, making it
729  /// <* <i>empty</i> if "includeRoot" is false (or unset) or
730  /// * <i>include everything</i> if "includeRoot" is true.
731  /// (assuming there are no opinions in stronger edit targets).
732  USD_API
733  bool BlockCollection() const;
734 
735  /// Test whether a given \p name contains the "collection:" prefix
736  ///
737  USD_API
738  static bool CanContainPropertyName(const TfToken &name);
739 
740 private:
741 
742  // Helper method for computing the UsdCollectionMembershipQuery object for
743  // a collection.
744  // This makes recursive calls if the collection includes other collections.
745  // \p chainedCollectionPaths is used to pass in the set of all seen and
746  // included collections in the dependency chain and is used to detect
747  // circular dependencies.
748  // If \p foundCircularDependency is not nullptr, it is set to true if a
749  // circular dependency is detected amongst the included collections.
750  // If it is nullptr, a warning is issued when a circular dependency is
751  // detected.
752  void _ComputeMembershipQueryImpl(
754  const SdfPathSet &chainedCollectionPaths,
755  bool *foundCircularDependency=nullptr) const;
756 
757  // The same as ResolveCompleteMembershipExpression(), but set
758  // `foundCircularDependency` to true if a circular dependency is encountered
759  // during resolution.
761  _ResolveCompleteMembershipExpression(bool *foundCircularDependency) const;
762 };
763 
765 
766 #endif
static USD_API UsdCollectionAPI Apply(const UsdPrim &prim, const TfToken &name)
USD_API UsdCollectionMembershipQuery ComputeMembershipQuery() const
GLenum query
Definition: glad.h:2772
USD_API bool BlockCollection() const
static USD_API SdfPath GetNamedCollectionPath(const UsdPrim &prim, const TfToken &collectionName)
static USD_API std::vector< UsdCollectionAPI > GetAllCollections(const UsdPrim &prim)
#define USD_API
Definition: api.h:23
USD_API UsdRelationship GetExcludesRel() const
USD_API bool HasNoIncludedPaths() const
USD_API UsdAttribute GetIncludeRootAttr() const
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
USD_API bool IncludePath(const SdfPath &pathToInclude) const
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
USD_API UsdRelationship CreateExcludesRel() const
Represents a flattened view of a collection. For more information about collections, please see UsdCollectionAPI as a way to encode and retrieve a collection from scene description. A UsdCollectionMembershipQuery object can be used to answer queries about membership of paths in the collection efficiently.
static USD_API bool CanApply(const UsdPrim &prim, const TfToken &name, std::string *whyNot=nullptr)
UsdStagePtr UsdStageWeakPtr
Definition: common.h:38
USD_API bool ResetCollection() const
USD_API UsdAttribute CreateModeAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USD_API SdfPathExpression ResolveCompleteMembershipExpression() const
USD_API UsdRelationship CreateIncludesRel() const
static USD_API UsdCollectionAPI Get(const UsdStagePtr &stage, const SdfPath &path)
USD_API UsdAttribute CreateExpansionRuleAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
const TfToken & _GetInstanceName() const
TfToken GetName() const
Returns the name of this multiple-apply schema instance.
Definition: token.h:70
static USD_API bool IsCollectionAPIPath(const SdfPath &path, TfToken *name)
USD_API SdfPath GetCollectionPath() const
static USD_API UsdCollectionAPI GetCollection(const UsdStagePtr &stage, const SdfPath &collectionPath)
USD_API UsdAttribute CreateMembershipExpressionAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USD_API bool Validate(std::string *reason) const
USD_API UsdAttribute GetMembershipExpressionAttr() const
USD_API UsdAttribute GetExpansionRuleAttr() const
Definition: prim.h:116
static USD_API bool IsSchemaPropertyBaseName(const TfToken &baseName)
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
GLuint const GLchar * name
Definition: glcorearb.h:786
Definition: path.h:280
USD_API UsdAttribute GetCollectionAttr() const
std::set< class SdfPath > SdfPathSet
A set of SdfPaths.
Definition: path.h:199
UsdSchemaKind
Definition: common.h:112
USD_API UsdAttribute CreateCollectionAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USD_API const Usd_PrimFlagsConjunction UsdPrimDefaultPredicate
USD_API UsdAttribute GetModeAttr() const
static const UsdSchemaKind schemaKind
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
USD_API UsdAttribute CreateIncludeRootAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
Definition: type.h:47
virtual USD_API ~UsdCollectionAPI()
Destructor.
static USD_API SdfPathSet ComputeIncludedPaths(const UsdCollectionMembershipQuery &query, const UsdStageWeakPtr &stage, const Usd_PrimFlagsPredicate &pred=UsdPrimDefaultPredicate)
Usd_CollectionMembershipQuery< UsdObjectCollectionExpressionEvaluator > UsdCollectionMembershipQuery
static USD_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
USD_API UsdSchemaKind _GetSchemaKind() const override
UsdCollectionAPI(const UsdPrim &prim=UsdPrim(), const TfToken &name=TfToken())
static USD_API std::vector< UsdCollectionAPI > GetAll(const UsdPrim &prim)
bool IsInExpressionMode() const
USD_API bool IsInRelationshipsMode() const
Definition: value.h:89
Multiple Apply API Schema.
static USD_API std::set< UsdObject > ComputeIncludedObjects(const UsdCollectionMembershipQuery &query, const UsdStageWeakPtr &stage, const Usd_PrimFlagsPredicate &pred=UsdPrimDefaultPredicate)
USD_API UsdRelationship GetIncludesRel() const
USD_API bool ExcludePath(const SdfPath &pathToExclude) const
UsdCollectionAPI(const UsdSchemaBase &schemaObj, const TfToken &name)
static USD_API bool CanContainPropertyName(const TfToken &name)