HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
apiSchemaBase.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_APISCHEMABASE_H
8 #define USD_GENERATED_APISCHEMABASE_H
9 
10 /// \file usd/apiSchemaBase.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/usd/api.h"
14 #include "pxr/usd/usd/schemaBase.h"
15 #include "pxr/usd/usd/prim.h"
16 #include "pxr/usd/usd/stage.h"
17 
18 #include "pxr/base/vt/value.h"
19 
20 #include "pxr/base/gf/vec3d.h"
21 #include "pxr/base/gf/vec3f.h"
22 #include "pxr/base/gf/matrix4d.h"
23 
24 #include "pxr/base/tf/token.h"
25 #include "pxr/base/tf/type.h"
26 
28 
29 class SdfAssetPath;
30 
31 // -------------------------------------------------------------------------- //
32 // APISCHEMABASE //
33 // -------------------------------------------------------------------------- //
34 
35 /// \class UsdAPISchemaBase
36 ///
37 /// The base class for all \em API schemas.
38 ///
39 /// An API schema provides an interface to a prim's qualities, but does not
40 /// specify a typeName for the underlying prim. The prim's qualities include
41 /// its inheritance structure, attributes, relationships etc. Since it cannot
42 /// provide a typeName, an API schema is considered to be non-concrete.
43 ///
44 /// To auto-generate an API schema using usdGenSchema, simply leave the
45 /// typeName empty and make it inherit from "/APISchemaBase" or from another
46 /// API schema. See UsdModelAPI, UsdClipsAPI and UsdCollectionAPI for examples.
47 ///
48 /// API schemas are classified into applied and non-applied API schemas.
49 /// The author of an API schema has to decide on the type of API schema
50 /// at the time of its creation by setting customData['apiSchemaType'] in the
51 /// schema definition (i.e. in the associated primSpec inside the schema.usda
52 /// file). UsdAPISchemaBase implements methods that are used to record the
53 /// application of an API schema on a USD prim.
54 ///
55 /// If an API schema only provides an interface to set certain core bits of
56 /// metadata (like UsdModelAPI, which sets model kind and UsdClipsAPI, which
57 /// sets clips-related metadata) OR if the API schema can apply to any type of
58 /// prim or only to a known fixed set of prim types OR if there is no use of
59 /// recording the application of the API schema, in such cases, it would be
60 /// better to make it a non-applied API schema. Examples of non-applied API
61 /// schemas include UsdModelAPI, UsdClipsAPI, UsdShadeConnectableAPI and
62 /// UsdGeomPrimvarsAPI.
63 ///
64 /// If there is a need to discover (or record) whether a prim contains or
65 /// subscribes to a given API schema, it would be advantageous to make the API
66 /// schema be "applied". In general, API schemas that add one or more properties
67 /// to a prim should be tagged as applied API schemas. A public Apply() method
68 /// is generated for applied API schemas by usdGenSchema. An applied API schema
69 /// must be applied to a prim via a call to the generated Apply() method, for
70 /// the schema object to evaluate to true when converted to a bool using the
71 /// explicit bool conversion operator. Examples of applied API schemas include
72 /// UsdCollectionAPI, UsdGeomModelAPI and UsdGeomMotionAPI
73 ///
74 /// \subsection usd_apischemabase_single_vs_multiple_apply Single vs. Multiple Apply API Schemas
75 ///
76 /// Applied API schemas can further be classified into single-apply and
77 /// multiple-apply API schemas. As the name suggests, a single-apply API schema
78 /// can only be applied once to a prim. A multiple-apply API schema can be
79 /// applied multiple times with different 'instanceName' values. An example of
80 /// a multiple-apply API schema is UsdCollectionAPI, where the API schema is
81 /// applied to a prim once for every collection owned by the prim.
82 ///
83 /// \note An applied API schema must only inherit directly from APISchemaBase.
84 /// 'usdGenSchema' will issue a warning if it detects applied API schemas
85 /// that don't inherit from APISchemaBase, or inherit from something other than
86 /// APISchemaBase.
87 ///
88 /// \note When the bool-conversion operator is invoked on an applied API
89 /// schema, it evaluates to true only if the application of the API schema has
90 /// been recorded on the prim via a call to the auto-generated Apply() method.
91 ///
92 ///
93 ///
95 {
96 public:
97  /// Compile time constant representing what kind of schema this class is.
98  ///
99  /// \sa UsdSchemaKind
101 
102  /// Construct a UsdAPISchemaBase on UsdPrim \p prim .
103  /// Equivalent to UsdAPISchemaBase::Get(prim.GetStage(), prim.GetPath())
104  /// for a \em valid \p prim, but will not immediately throw an error for
105  /// an invalid \p prim
106  explicit UsdAPISchemaBase(const UsdPrim& prim=UsdPrim())
107  : UsdSchemaBase(prim)
108  {
109  }
110 
111  /// Construct a UsdAPISchemaBase on the prim held by \p schemaObj .
112  /// Should be preferred over UsdAPISchemaBase(schemaObj.GetPrim()),
113  /// as it preserves SchemaBase state.
114  explicit UsdAPISchemaBase(const UsdSchemaBase& schemaObj)
115  : UsdSchemaBase(schemaObj)
116  {
117  }
118 
119  /// Destructor.
120  USD_API
121  virtual ~UsdAPISchemaBase() = 0;
122 
123  /// Return a vector of names of all pre-declared attributes for this schema
124  /// class and all its ancestor classes. Does not include attributes that
125  /// may be authored by custom/extended methods of the schemas involved.
126  USD_API
127  static const TfTokenVector &
128  GetSchemaAttributeNames(bool includeInherited=true);
129 
130 
131 protected:
132  /// Returns the kind of schema this class belongs to.
133  ///
134  /// \sa UsdSchemaKind
135  USD_API
136  UsdSchemaKind _GetSchemaKind() const override;
137 
138 private:
139  // needs to invoke _GetStaticTfType.
140  friend class UsdSchemaRegistry;
141  USD_API
142  static const TfType &_GetStaticTfType();
143 
144  static bool _IsTypedSchema();
145 
146  // override SchemaBase virtuals.
147  USD_API
148  const TfType &_GetTfType() const override;
149 
150 public:
151  // ===================================================================== //
152  // Feel free to add custom code below this line, it will be preserved by
153  // the code generator.
154  //
155  // Just remember to:
156  // - Close the class declaration with };
157  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
158  // - Close the include guard with #endif
159  // ===================================================================== //
160  // --(BEGIN CUSTOM CODE)--
161 
162 protected:
163  /// Construct a multiple-apply UsdAPISchemaBase on UsdPrim \p prim with
164  /// the specified \p instanceName.
165  explicit UsdAPISchemaBase(const UsdPrim& prim,
166  const TfToken &instanceName)
167  : UsdSchemaBase(prim)
168  , _instanceName(instanceName)
169  {
170  }
171 
172  /// Construct a multiple-apply UsdAPISchemaBase on the prim held by
173  /// \p schemaObj with the given \p instanceName.
174  explicit UsdAPISchemaBase(const UsdSchemaBase& schemaObj,
175  const TfToken &instanceName)
176  : UsdSchemaBase(schemaObj)
177  , _instanceName(instanceName)
178  {
179  }
180 
181  /// Returns the instance name of the API schema object belonging to a
182  /// multiple-apply API schema.
183  ///
184  /// The returned instance name will be empty for non-applied and
185  /// single-apply API schemas.
186  const TfToken &_GetInstanceName() const {
187  return _instanceName;
188  }
189 
190  /// Returns a vector of names of API schema objects belonging to a
191  /// multiple-apply API schema applied to a given prim.
192  USD_API
194  const TfType &schemaType);
195 
196 protected:
197  /// Check whether this APISchema object is valid for the currently held
198  /// prim.
199  ///
200  /// If this is an applied API schema, this returns true if the held prim
201  /// is valid and already has the API schema applied to it, along with the
202  /// instanceName (in the case of multiple-apply). The instanceName should
203  /// not be empty in the case of a multiple-apply API schema.
204  ///
205  /// This check is performed when clients invoke the explicit bool conversion
206  /// operator, implemented in UsdSchemaBase.
207  ///
208  /// \sa UsdPrim::HasAPI()
209  USD_API
210  bool _IsCompatible() const override;
211 
212 private:
213  // The instance name associated with this schema object, if it is a
214  // multiple-apply API schema. For example, in the case of UsdCollectionAPI,
215  // this will hold the name of the collection.
216  TfToken _instanceName;
217 };
218 
220 
221 #endif
USD_API UsdSchemaKind _GetSchemaKind() const override
#define USD_API
Definition: api.h:23
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
static USD_API TfTokenVector _GetMultipleApplyInstanceNames(const UsdPrim &prim, const TfType &schemaType)
const TfToken & _GetInstanceName() const
Definition: token.h:70
UsdAPISchemaBase(const UsdPrim &prim=UsdPrim())
UsdAPISchemaBase(const UsdSchemaBase &schemaObj, const TfToken &instanceName)
UsdAPISchemaBase(const UsdSchemaBase &schemaObj)
Definition: prim.h:116
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
UsdAPISchemaBase(const UsdPrim &prim, const TfToken &instanceName)
UsdSchemaKind
Definition: common.h:112
virtual USD_API ~UsdAPISchemaBase()=0
Destructor.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
static USD_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
Definition: type.h:47
static const UsdSchemaKind schemaKind
USD_API bool _IsCompatible() const override