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