HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
propertySpec.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 PXR_USD_SDF_PROPERTY_SPEC_H
8 #define PXR_USD_SDF_PROPERTY_SPEC_H
9 
10 /// \file sdf/propertySpec.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/sdf/api.h"
15 #include "pxr/usd/sdf/spec.h"
17 #include "pxr/usd/sdf/proxyTypes.h"
18 #include "pxr/usd/sdf/types.h"
19 
20 #include "pxr/base/vt/value.h"
21 
23 #include "pxr/base/tf/token.h"
24 
25 #include <iosfwd>
26 #include <string>
27 
29 
30 /// \class SdfPropertySpec
31 ///
32 /// Base class for SdfAttributeSpec and SdfRelationshipSpec.
33 ///
34 /// Scene Spec Attributes (SdfAttributeSpec) and Relationships
35 /// (SdfRelationshipSpec) are the basic properties that make up Scene Spec Prims
36 /// (SdfPrimSpec). They share many qualities and can sometimes be treated
37 /// uniformly. The common qualities are provided by this base class.
38 ///
39 /// NOTE: Do not use Python reserved words and keywords as attribute names.
40 /// This will cause attribute resolution to fail.
41 ///
42 class SdfPropertySpec : public SdfSpec
43 {
44  SDF_DECLARE_ABSTRACT_SPEC(SdfPropertySpec, SdfSpec);
45 
46 public:
47  ///
48  /// \name Name
49  /// @{
50 
51  /// Returns the property's name.
52  SDF_API
53  const std::string &GetName() const;
54 
55  /// Returns the property's name, as a token.
56  SDF_API
57  TfToken GetNameToken() const;
58 
59  /// Returns true if setting the property spec's name to \p newName
60  /// will succeed.
61  ///
62  /// Returns false if it won't, and sets \p whyNot with a string
63  /// describing why not.
64  SDF_API
65  bool CanSetName(const std::string &newName, std::string *whyNot) const;
66 
67  /// Sets the property's name.
68  ///
69  /// A Prim's properties must be unique by name. Setting the
70  /// name to the same name as an existing property is an error.
71  ///
72  /// Setting \p validate to false, will skip validation of the newName
73  /// (that is, CanSetName will not be called).
74  SDF_API
75  bool SetName(const std::string &newName, bool validate = true);
76 
77  /// Returns true if the given name is considered a valid name for a
78  /// property. A valid name is not empty, and does not use invalid
79  /// characters (such as '/', '[', or '.').
80  SDF_API
81  static bool IsValidName(const std::string &name);
82 
83  /// @}
84  /// \name Ownership
85  /// @{
86 
87  /// Returns the owner prim or relationship of this property.
88  SDF_API
89  SdfSpecHandle GetOwner() const;
90 
91  /// @}
92  /// \name Metadata
93  /// @{
94 
95  /// Returns the property's custom data.
96  ///
97  /// The default value for custom data is an empty dictionary.
98  ///
99  /// Custom data is for use by plugins or other non-tools supplied
100  /// extensions that need to be able to store data attached to arbitrary
101  /// scene objects. Note that if the only objects you want to store data
102  /// on are prims, using custom attributes is probably a better choice.
103  /// But if you need to possibly store this data on attributes or
104  /// relationships or as annotations on reference arcs, then custom data
105  /// is an appropriate choice.
106  SDF_API
108 
109  /// Returns the asset info dictionary for this property.
110  ///
111  /// The default value is an empty dictionary.
112  ///
113  /// The asset info dictionary is used to annotate SdfAssetPath-valued
114  /// attributes pointing to the root-prims of assets (generally organized
115  /// as models) with various data related to asset management. For example,
116  /// asset name, root layer identifier, asset version etc.
117  ///
118  /// \note It is only valid to author assetInfo on attributes that are of
119  /// type SdfAssetPath.
120  ///
121  SDF_API
123 
124  /// Sets a property custom data entry.
125  ///
126  /// If \p value is empty, then this removes the given custom data entry.
127  SDF_API
128  void SetCustomData(const std::string &name, const VtValue &value);
129 
130  /// Sets a asset info entry for this property.
131  ///
132  /// If \p value is empty, then this removes the given asset info entry.
133  ///
134  /// \sa GetAssetInfo()
135  ///
136  SDF_API
137  void SetAssetInfo(const std::string& name, const VtValue& value);
138 
139  /// Returns the displayGroup string for this property spec.
140  ///
141  /// The default value for displayGroup is empty string.
142  SDF_API
143  std::string GetDisplayGroup() const;
144 
145  /// Sets the displayGroup string for this property spec.
146  SDF_API
147  void SetDisplayGroup(const std::string &value);
148 
149  /// Returns the displayName string for this property spec.
150  ///
151  /// The default value for displayName is empty string.
152  SDF_API
153  std::string GetDisplayName() const;
154 
155  /// Sets the displayName string for this property spec.
156  SDF_API
157  void SetDisplayName(const std::string &value);
158 
159  /// Returns the documentation string for this property spec.
160  ///
161  /// The default value for documentation is empty string.
162  SDF_API
163  std::string GetDocumentation() const;
164 
165  /// Sets the documentation string for this property spec.
166  SDF_API
167  void SetDocumentation(const std::string &value);
168 
169  /// Returns whether this property spec will be hidden in browsers.
170  ///
171  /// The default value for hidden is false.
172  SDF_API
173  bool GetHidden() const;
174 
175  /// Sets whether this property spec will be hidden in browsers.
176  SDF_API
177  void SetHidden(bool value);
178 
179  /// Returns the property's permission restriction.
180  ///
181  /// The default value for permission is SdfPermissionPublic.
182  SDF_API
184 
185  /// Sets the property's permission restriction.
186  SDF_API
187  void SetPermission(SdfPermission value);
188 
189  /// Returns the prefix string for this property spec.
190  ///
191  /// The default value for prefix is "".
192  SDF_API
193  std::string GetPrefix() const;
194 
195  /// Sets the prefix string for this property spec.
196  SDF_API
197  void SetPrefix(const std::string &value);
198 
199  /// Returns the suffix string for this property spec.
200  ///
201  /// The default value for suffix is "".
202  SDF_API
203  std::string GetSuffix() const;
204 
205  /// Sets the suffix string for this property spec.
206  SDF_API
207  void SetSuffix(const std::string &value);
208 
209  /// Returns the property's symmetric peer.
210  ///
211  /// The default value for the symmetric peer is an empty string.
212  SDF_API
213  std::string GetSymmetricPeer() const;
214 
215  /// Sets the property's symmetric peer.
216  ///
217  /// If \p peerName is empty, then this removes any symmetric peer for the
218  /// given property.
219  SDF_API
220  void SetSymmetricPeer(const std::string &peerName);
221 
222  /// Returns the property's symmetry arguments.
223  ///
224  /// The default value for symmetry arguments is an empty dictionary.
225  SDF_API
227 
228  /// Sets a property symmetry argument.
229  ///
230  /// If \p value is empty, then this removes the argument with the given
231  /// \p name.
232  SDF_API
233  void SetSymmetryArgument(const std::string &name, const VtValue &value);
234 
235  /// Returns the property's symmetry function.
236  ///
237  /// The default value for the symmetry function is an empty token.
238  SDF_API
240 
241  /// Sets the property's symmetry function.
242  ///
243  /// If \p functionName is empty, then this removes any symmetry function
244  /// for the given property.
245  SDF_API
246  void SetSymmetryFunction(const TfToken &functionName);
247 
248  /// @}
249  /// \name Property value API
250  /// @{
251 
252  /// Returns the TfType representing the value type this property holds.
253  SDF_API
254  TfType GetValueType() const;
255 
256  /// Returns the name of the value type that this property holds.
257  ///
258  /// Returns the typename used to represent the types of value held by
259  /// this attribute.
260  SDF_API
262 
263  /// Returns the attribute's default value.
264  ///
265  /// If it doesn't have a default value, an empty VtValue is returned.
266  SDF_API
267  VtValue GetDefaultValue() const;
268 
269  /// Sets the attribute's default value.
270  ///
271  /// Returns true if successful, false otherwise. Fails if \p defaultValue
272  /// has wrong type.
273  SDF_API
274  bool SetDefaultValue(const VtValue &defaultValue);
275 
276  /// Returns true if a default value is set for this attribute.
277  SDF_API
278  bool HasDefaultValue() const;
279 
280  /// Clear the attribute's default value.
281  SDF_API
282  void ClearDefaultValue();
283 
284  /// @}
285  /// \name Spec properties
286  /// @{
287 
288  /// Returns the comment string for this property spec.
289  ///
290  /// The default value for comment is "".
291  SDF_API
292  std::string GetComment() const;
293 
294  /// Sets the comment string for this property spec.
295  SDF_API
296  void SetComment(const std::string &value);
297 
298  /// Returns true if this spec declares a custom property
299  SDF_API
300  bool IsCustom() const;
301 
302  /// Sets whether this spec declares a custom property
303  SDF_API
304  void SetCustom(bool custom);
305 
306  /// Returns the variability of the property.
307  ///
308  /// An attribute's variability may be \c Varying (the default),
309  /// \c Uniform, \c Config, or \c Computed.
310  ///
311  /// A relationship's variability may be \c Varying or \c Uniform (the
312  /// default)
313  ///
314  /// <ul>
315  /// <li>\c Varying attributes may be directly authored, animated and
316  /// affected by \p Actions. They are the most flexible.
317  /// Varying relationships can have a default and an anim spline,
318  /// in addition to a list of targets.
319  ///
320  /// <li>\c Uniform attributes may be authored only with non-animated
321  /// values (default values). They cannot be affected by \p Actions,
322  /// but they can be connected to other Uniform attributes.
323  /// Uniform relationships have a list of targets but do not have
324  /// default or anim spline values.
325  ///
326  /// <li>\c Config attributes are the same as Uniform except that a Prim
327  /// can choose to alter its collection of built-in properties based
328  /// on the values of its Config attributes.
329  ///
330  /// <li>\c Computed attributes may not be authored in scene description.
331  /// Prims determine the values of their Computed attributes through
332  /// Prim-specific computation. They may not be connected.
333  /// </ul>
334  SDF_API
336 
337  /// Returns true if this PropertySpec has no significant data other than
338  /// just what is necessary for instantiation.
339  ///
340  /// For example, "double foo" has only required fields, but "double foo = 3"
341  /// has more than just what is required.
342  ///
343  /// This is similar to IsInert except that IsInert will always return false
344  /// even for properties that have only required fields; PropertySpecs are
345  /// never considered inert because even a spec with only required fields
346  /// will cause instantiation of on-demand properties.
347  ///
348  SDF_API
349  bool HasOnlyRequiredFields() const;
350 
351 private:
352  inline TfToken _GetAttributeValueTypeName() const;
353 };
354 
356 
357 #endif // #ifndef PXR_USD_SDF_PROPERTY_SPEC_H
SDF_API void SetPermission(SdfPermission value)
Sets the property's permission restriction.
SDF_API bool GetHidden() const
SDF_API SdfDictionaryProxy GetCustomData() const
SDF_API bool HasOnlyRequiredFields() const
SDF_API void SetDisplayGroup(const std::string &value)
Sets the displayGroup string for this property spec.
SDF_API void SetDocumentation(const std::string &value)
Sets the documentation string for this property spec.
SDF_API VtValue GetDefaultValue() const
SDF_API const std::string & GetName() const
Returns the property's name.
SDF_API void SetCustom(bool custom)
Sets whether this spec declares a custom property.
GLsizei const GLfloat * value
Definition: glcorearb.h:824
SDF_API std::string GetDisplayName() const
SDF_API void SetSymmetryFunction(const TfToken &functionName)
Definition: spec.h:32
SDF_API void SetSuffix(const std::string &value)
Sets the suffix string for this property spec.
SDF_API SdfDictionaryProxy GetSymmetryArguments() const
SDF_API bool SetDefaultValue(const VtValue &defaultValue)
SDF_API SdfSpecHandle GetOwner() const
Returns the owner prim or relationship of this property.
SDF_API void SetHidden(bool value)
Sets whether this property spec will be hidden in browsers.
SDF_API void SetComment(const std::string &value)
Sets the comment string for this property spec.
SDF_API SdfValueTypeName GetTypeName() const
SDF_API TfType GetValueType() const
Returns the TfType representing the value type this property holds.
SDF_API std::string GetPrefix() const
Definition: token.h:70
static SDF_API bool IsValidName(const std::string &name)
SDF_API void SetPrefix(const std::string &value)
Sets the prefix string for this property spec.
SDF_API SdfVariability GetVariability() const
SDF_API void SetCustomData(const std::string &name, const VtValue &value)
SDF_API std::string GetDisplayGroup() const
SDF_API TfToken GetNameToken() const
Returns the property's name, as a token.
SDF_API bool SetName(const std::string &newName, bool validate=true)
GLuint const GLchar * name
Definition: glcorearb.h:786
SDF_API TfToken GetSymmetryFunction() const
SDF_API SdfDictionaryProxy GetAssetInfo() const
SDF_API std::string GetComment() const
SdfVariability
Definition: types.h:156
SDF_API bool IsCustom() const
Returns true if this spec declares a custom property.
SDF_API std::string GetDocumentation() const
#define SDF_API
Definition: api.h:23
SDF_API void SetSymmetricPeer(const std::string &peerName)
SDF_API std::string GetSymmetricPeer() const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
SDF_API bool CanSetName(const std::string &newName, std::string *whyNot) const
SDF_API void SetAssetInfo(const std::string &name, const VtValue &value)
SDF_API bool HasDefaultValue() const
Returns true if a default value is set for this attribute.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
Definition: type.h:47
SDF_API SdfPermission GetPermission() const
SDF_API std::string GetSuffix() const
SDF_API void SetDisplayName(const std::string &value)
Sets the displayName string for this property spec.
Definition: value.h:146
SDF_API void SetSymmetryArgument(const std::string &name, const VtValue &value)
SDF_API void ClearDefaultValue()
Clear the attribute's default value.
SdfPermission
Definition: types.h:132