HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
labelsAPI.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 USDSEMANTICS_GENERATED_LABELSAPI_H
8 #define USDSEMANTICS_GENERATED_LABELSAPI_H
9 
10 /// \file usdSemantics/labelsAPI.h
11 
12 #include "pxr/pxr.h"
15 #include "pxr/usd/usd/prim.h"
16 #include "pxr/usd/usd/stage.h"
18 
19 #include "pxr/base/vt/value.h"
20 
21 #include "pxr/base/gf/vec3d.h"
22 #include "pxr/base/gf/vec3f.h"
23 #include "pxr/base/gf/matrix4d.h"
24 
25 #include "pxr/base/tf/token.h"
26 #include "pxr/base/tf/type.h"
27 
29 
30 class SdfAssetPath;
31 
32 // -------------------------------------------------------------------------- //
33 // SEMANTICSLABELSAPI //
34 // -------------------------------------------------------------------------- //
35 
36 /// \class UsdSemanticsLabelsAPI
37 ///
38 /// Application of labels for a prim for a taxonomy specified by the
39 /// schema's instance name.
40 ///
41 /// See `UsdSemanticsLabelsQuery` for more information about computations and
42 /// inheritance of semantics.
43 ///
45 {
46 public:
47  /// Compile time constant representing what kind of schema this class is.
48  ///
49  /// \sa UsdSchemaKind
51 
52  /// Construct a UsdSemanticsLabelsAPI on UsdPrim \p prim with
53  /// name \p name . Equivalent to
54  /// UsdSemanticsLabelsAPI::Get(
55  /// prim.GetStage(),
56  /// prim.GetPath().AppendProperty(
57  /// "semantics:labels:name"));
58  ///
59  /// for a \em valid \p prim, but will not immediately throw an error for
60  /// an invalid \p prim
62  const UsdPrim& prim=UsdPrim(), const TfToken &name=TfToken())
63  : UsdAPISchemaBase(prim, /*instanceName*/ name)
64  { }
65 
66  /// Construct a UsdSemanticsLabelsAPI on the prim held by \p schemaObj with
67  /// name \p name. Should be preferred over
68  /// UsdSemanticsLabelsAPI(schemaObj.GetPrim(), name), as it preserves
69  /// SchemaBase state.
71  const UsdSchemaBase& schemaObj, const TfToken &name)
72  : UsdAPISchemaBase(schemaObj, /*instanceName*/ name)
73  { }
74 
75  /// Destructor.
77  virtual ~UsdSemanticsLabelsAPI();
78 
79  /// Return a vector of names of all pre-declared attributes for this schema
80  /// class and all its ancestor classes. Does not include attributes that
81  /// may be authored by custom/extended methods of the schemas involved.
83  static const TfTokenVector &
84  GetSchemaAttributeNames(bool includeInherited=true);
85 
86  /// Return a vector of names of all pre-declared attributes for this schema
87  /// class and all its ancestor classes for a given instance name. Does not
88  /// include attributes that may be authored by custom/extended methods of
89  /// the schemas involved. The names returned will have the proper namespace
90  /// prefix.
92  static TfTokenVector
93  GetSchemaAttributeNames(bool includeInherited, const TfToken &instanceName);
94 
95  /// Returns the name of this multiple-apply schema instance
96  TfToken GetName() const {
97  return _GetInstanceName();
98  }
99 
100  /// Return a UsdSemanticsLabelsAPI holding the prim adhering to this
101  /// schema at \p path on \p stage. If no prim exists at \p path on
102  /// \p stage, or if the prim at that path does not adhere to this schema,
103  /// return an invalid schema object. \p path must be of the format
104  /// <path>.semantics:labels:name .
105  ///
106  /// This is shorthand for the following:
107  ///
108  /// \code
109  /// TfToken name = SdfPath::StripNamespace(path.GetToken());
110  /// UsdSemanticsLabelsAPI(
111  /// stage->GetPrimAtPath(path.GetPrimPath()), name);
112  /// \endcode
113  ///
115  static UsdSemanticsLabelsAPI
116  Get(const UsdStagePtr &stage, const SdfPath &path);
117 
118  /// Return a UsdSemanticsLabelsAPI with name \p name holding the
119  /// prim \p prim. Shorthand for UsdSemanticsLabelsAPI(prim, name);
121  static UsdSemanticsLabelsAPI
122  Get(const UsdPrim &prim, const TfToken &name);
123 
124  /// Return a vector of all named instances of UsdSemanticsLabelsAPI on the
125  /// given \p prim.
127  static std::vector<UsdSemanticsLabelsAPI>
128  GetAll(const UsdPrim &prim);
129 
130  /// Checks if the given name \p baseName is the base name of a property
131  /// of SemanticsLabelsAPI.
133  static bool
134  IsSchemaPropertyBaseName(const TfToken &baseName);
135 
136  /// Checks if the given path \p path is of an API schema of type
137  /// SemanticsLabelsAPI. If so, it stores the instance name of
138  /// the schema in \p name and returns true. Otherwise, it returns false.
140  static bool
142 
143  /// Returns true if this <b>multiple-apply</b> API schema can be applied,
144  /// with the given instance name, \p name, to the given \p prim. If this
145  /// schema can not be a applied the prim, this returns false and, if
146  /// provided, populates \p whyNot with the reason it can not be applied.
147  ///
148  /// Note that if CanApply returns false, that does not necessarily imply
149  /// that calling Apply will fail. Callers are expected to call CanApply
150  /// before calling Apply if they want to ensure that it is valid to
151  /// apply a schema.
152  ///
153  /// \sa UsdPrim::GetAppliedSchemas()
154  /// \sa UsdPrim::HasAPI()
155  /// \sa UsdPrim::CanApplyAPI()
156  /// \sa UsdPrim::ApplyAPI()
157  /// \sa UsdPrim::RemoveAPI()
158  ///
160  static bool
161  CanApply(const UsdPrim &prim, const TfToken &name,
162  std::string *whyNot=nullptr);
163 
164  /// Applies this <b>multiple-apply</b> API schema to the given \p prim
165  /// along with the given instance name, \p name.
166  ///
167  /// This information is stored by adding "SemanticsLabelsAPI:<i>name</i>"
168  /// to the token-valued, listOp metadata \em apiSchemas on the prim.
169  /// For example, if \p name is 'instance1', the token
170  /// 'SemanticsLabelsAPI:instance1' is added to 'apiSchemas'.
171  ///
172  /// \return A valid UsdSemanticsLabelsAPI object is returned upon success.
173  /// An invalid (or empty) UsdSemanticsLabelsAPI object is returned upon
174  /// failure. See \ref UsdPrim::ApplyAPI() for
175  /// conditions resulting in failure.
176  ///
177  /// \sa UsdPrim::GetAppliedSchemas()
178  /// \sa UsdPrim::HasAPI()
179  /// \sa UsdPrim::CanApplyAPI()
180  /// \sa UsdPrim::ApplyAPI()
181  /// \sa UsdPrim::RemoveAPI()
182  ///
184  static UsdSemanticsLabelsAPI
185  Apply(const UsdPrim &prim, const TfToken &name);
186 
187 protected:
188  /// Returns the kind of schema this class belongs to.
189  ///
190  /// \sa UsdSchemaKind
192  UsdSchemaKind _GetSchemaKind() const override;
193 
194 private:
195  // needs to invoke _GetStaticTfType.
196  friend class UsdSchemaRegistry;
198  static const TfType &_GetStaticTfType();
199 
200  static bool _IsTypedSchema();
201 
202  // override SchemaBase virtuals.
204  const TfType &_GetTfType() const override;
205 
206 public:
207  // --------------------------------------------------------------------- //
208  // LABELS
209  // --------------------------------------------------------------------- //
210  /// Array of labels specified directly at this prim.
211  ///
212  /// | ||
213  /// | -- | -- |
214  /// | Declaration | `token[] __INSTANCE_NAME__ = []` |
215  /// | C++ Type | VtArray<TfToken> |
216  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->TokenArray |
218  UsdAttribute GetLabelsAttr() const;
219 
220  /// See GetLabelsAttr(), and also
221  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
222  /// If specified, author \p defaultValue as the attribute's default,
223  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
224  /// the default for \p writeSparsely is \c false.
226  UsdAttribute CreateLabelsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
227 
228 public:
229  // ===================================================================== //
230  // Feel free to add custom code below this line, it will be preserved by
231  // the code generator.
232  //
233  // Just remember to:
234  // - Close the class declaration with };
235  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
236  // - Close the include guard with #endif
237  // ===================================================================== //
238  // --(BEGIN CUSTOM CODE)--
239  /// Get the instance names (taxonomies) of all applications of
240  /// UsdSemanticsLabelsAPI for the specified prim.
241  ///
242  /// Prefer `UsdSemanticsLabelsAPI::GetAll(prim)` if the instances of
243  /// the schema may be needed.
244  ///
245  /// Prefer `prim.HasAPI<UsdSemanticsLabelsAPI>(taxonomy)` for checking
246  /// if a taxonomy has been directly applied to the prim.
247  ///
248  /// \sa ComputeInheritedTaxonomies
249  /// \sa GetAll
251  static std::vector<TfToken> GetDirectTaxonomies(const UsdPrim& prim);
252 
253  /// Get the unique instance names (taxonomies) of all applications of
254  /// UsdSemanticsLabelsAPI for the specified prim and its ancestors.
255  ///
256  /// \sa GetDirectTaxonomies
258  static std::vector<TfToken> ComputeInheritedTaxonomies(
259  const UsdPrim& prim);
260 };
261 
263 
264 #endif
static USDSEMANTICS_API std::vector< TfToken > ComputeInheritedTaxonomies(const UsdPrim &prim)
virtual USDSEMANTICS_API ~UsdSemanticsLabelsAPI()
Destructor.
static USDSEMANTICS_API bool IsSchemaPropertyBaseName(const TfToken &baseName)
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
UsdSemanticsLabelsAPI(const UsdPrim &prim=UsdPrim(), const TfToken &name=TfToken())
Definition: labelsAPI.h:61
#define USDSEMANTICS_API
Definition: api.h:23
USDSEMANTICS_API UsdAttribute GetLabelsAttr() const
static USDSEMANTICS_API UsdSemanticsLabelsAPI Apply(const UsdPrim &prim, const TfToken &name)
const TfToken & _GetInstanceName() const
Definition: token.h:70
USDSEMANTICS_API UsdAttribute CreateLabelsAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
Definition: prim.h:116
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
GLuint const GLchar * name
Definition: glcorearb.h:786
static USDSEMANTICS_API bool IsSemanticsLabelsAPIPath(const SdfPath &path, TfToken *name)
Definition: path.h:273
USDSEMANTICS_API UsdSchemaKind _GetSchemaKind() const override
UsdSchemaKind
Definition: common.h:112
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
static USDSEMANTICS_API std::vector< TfToken > GetDirectTaxonomies(const UsdPrim &prim)
static USDSEMANTICS_API std::vector< UsdSemanticsLabelsAPI > GetAll(const UsdPrim &prim)
static USDSEMANTICS_API UsdSemanticsLabelsAPI Get(const UsdStagePtr &stage, const SdfPath &path)
TfToken GetName() const
Returns the name of this multiple-apply schema instance.
Definition: labelsAPI.h:96
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
Definition: type.h:47
UsdSemanticsLabelsAPI(const UsdSchemaBase &schemaObj, const TfToken &name)
Definition: labelsAPI.h:70
static USDSEMANTICS_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
static USDSEMANTICS_API bool CanApply(const UsdPrim &prim, const TfToken &name, std::string *whyNot=nullptr)
Definition: value.h:146
Multiple Apply API Schema.
static const UsdSchemaKind schemaKind
Definition: labelsAPI.h:50