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 can only inherit from another applied API
84 /// schema or directly from APISchemaBase. Similarly, a non-applied API schema
85 /// can only inherit from a non-applied API Schema or directly from
86 /// APISchemaBase. 'usdGenSchema' attempts to issue a warning if it detects
87 /// an incompatibility.
88 ///
89 /// \note A multiple-apply API schema may not inherit from a single-apply API
90 /// schema and vice versa.
91 ///
92 /// \note When the bool-conversion operator is invoked on an applied API
93 /// schema, it evaluates to true only if the application of the API schema has
94 /// been recorded on the prim via a call to the auto-generated Apply() method.
95 ///
96 ///
97 ///
99 {
100 public:
101  /// Compile time constant representing what kind of schema this class is.
102  ///
103  /// \sa UsdSchemaKind
105 
106  /// Construct a UsdAPISchemaBase on UsdPrim \p prim .
107  /// Equivalent to UsdAPISchemaBase::Get(prim.GetStage(), prim.GetPath())
108  /// for a \em valid \p prim, but will not immediately throw an error for
109  /// an invalid \p prim
110  explicit UsdAPISchemaBase(const UsdPrim& prim=UsdPrim())
111  : UsdSchemaBase(prim)
112  {
113  }
114 
115  /// Construct a UsdAPISchemaBase on the prim held by \p schemaObj .
116  /// Should be preferred over UsdAPISchemaBase(schemaObj.GetPrim()),
117  /// as it preserves SchemaBase state.
118  explicit UsdAPISchemaBase(const UsdSchemaBase& schemaObj)
119  : UsdSchemaBase(schemaObj)
120  {
121  }
122 
123  /// Destructor.
124  USD_API
125  virtual ~UsdAPISchemaBase() = 0;
126 
127  /// Return a vector of names of all pre-declared attributes for this schema
128  /// class and all its ancestor classes. Does not include attributes that
129  /// may be authored by custom/extended methods of the schemas involved.
130  USD_API
131  static const TfTokenVector &
132  GetSchemaAttributeNames(bool includeInherited=true);
133 
134 
135 protected:
136  /// Returns the kind of schema this class belongs to.
137  ///
138  /// \sa UsdSchemaKind
139  USD_API
140  UsdSchemaKind _GetSchemaKind() const override;
141 
142 private:
143  // needs to invoke _GetStaticTfType.
144  friend class UsdSchemaRegistry;
145  USD_API
146  static const TfType &_GetStaticTfType();
147 
148  static bool _IsTypedSchema();
149 
150  // override SchemaBase virtuals.
151  USD_API
152  const TfType &_GetTfType() const override;
153 
154 public:
155  // ===================================================================== //
156  // Feel free to add custom code below this line, it will be preserved by
157  // the code generator.
158  //
159  // Just remember to:
160  // - Close the class declaration with };
161  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
162  // - Close the include guard with #endif
163  // ===================================================================== //
164  // --(BEGIN CUSTOM CODE)--
165 
166 protected:
167  /// Construct a multiple-apply UsdAPISchemaBase on UsdPrim \p prim with
168  /// the specified \p instanceName.
169  explicit UsdAPISchemaBase(const UsdPrim& prim,
170  const TfToken &instanceName)
171  : UsdSchemaBase(prim)
172  , _instanceName(instanceName)
173  {
174  }
175 
176  /// Construct a multiple-apply UsdAPISchemaBase on the prim held by
177  /// \p schemaObj with the given \p instanceName.
178  explicit UsdAPISchemaBase(const UsdSchemaBase& schemaObj,
179  const TfToken &instanceName)
180  : UsdSchemaBase(schemaObj)
181  , _instanceName(instanceName)
182  {
183  }
184 
185  /// Returns the instance name of the API schema object belonging to a
186  /// multiple-apply API schema.
187  ///
188  /// The returned instance name will be empty for non-applied and
189  /// single-apply API schemas.
190  const TfToken &_GetInstanceName() const {
191  return _instanceName;
192  }
193 
194  /// Returns a vector of names of API schema objects belonging to a
195  /// multiple-apply API schema applied to a given prim.
196  USD_API
198  const TfType &schemaType);
199 
200 protected:
201  /// Check whether this APISchema object is valid for the currently held
202  /// prim.
203  ///
204  /// If this is an applied API schema, this returns true if the held prim
205  /// is valid and already has the API schema applied to it, along with the
206  /// instanceName (in the case of multiple-apply). The instanceName should
207  /// not be empty in the case of a multiple-apply API schema.
208  ///
209  /// This check is performed when clients invoke the explicit bool conversion
210  /// operator, implemented in UsdSchemaBase.
211  ///
212  /// \sa UsdPrim::HasAPI()
213  USD_API
214  bool _IsCompatible() const override;
215 
216 private:
217  // The instance name associated with this schema object, if it is a
218  // multiple-apply API schema. For example, in the case of UsdCollectionAPI,
219  // this will hold the name of the collection.
220  TfToken _instanceName;
221 };
222 
224 
225 #endif
USD_API UsdSchemaKind _GetSchemaKind() const override
#define USD_API
Definition: api.h:23
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
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
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