HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
attributeSpec.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_ATTRIBUTE_SPEC_H
8 #define PXR_USD_SDF_ATTRIBUTE_SPEC_H
9 
10 /// \file sdf/attributeSpec.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/sdf/api.h"
15 #include "pxr/usd/sdf/path.h"
17 #include "pxr/usd/sdf/types.h"
18 #include "pxr/base/tf/enum.h"
19 
21 
22 class TsSpline;
23 
24 /// \class SdfAttributeSpec
25 ///
26 /// A subclass of SdfPropertySpec that holds typed data.
27 ///
28 /// Attributes are typed data containers that can optionally hold any
29 /// and all of the following:
30 /// \li A single default value.
31 /// \li An array of knot values describing how the value varies over time.
32 /// \li A dictionary of posed values, indexed by name.
33 ///
34 /// The values contained in an attribute must all be of the same type. In the
35 /// Python API the \c typeName property holds the attribute type. In the C++
36 /// API, you can get the attribute type using the GetTypeName() method. In
37 /// addition, all values, including all knot values, must be the same shape.
38 /// For information on shapes, see the VtShape class reference in the C++
39 /// documentation.
40 ///
42 {
43  SDF_DECLARE_SPEC(SdfAttributeSpec, SdfPropertySpec);
44 
45 public:
48 
49  ///
50  /// \name Spec construction
51  /// @{
52 
53  /// Constructs a new prim attribute instance.
54  ///
55  /// Creates and returns a new attribute for the given prim.
56  /// The \p owner will own the newly created attribute.
57  SDF_API
58  static SdfAttributeSpecHandle
59  New(const SdfPrimSpecHandle& owner,
60  const std::string& name, const SdfValueTypeName& typeName,
62  bool custom = false);
63 
64  /// @}
65 
66  /// \name Connections
67  /// @{
68 
69  /// Returns a proxy for editing the attribute's connection paths.
70  ///
71  /// The returned proxy, which is an SdfListEditorProxy, modifies the
72  /// SdfListOp that represents this attribute's connections.
73  SDF_API
75 
76  /// Returns \c true if any connection paths are set on this attribute.
77  SDF_API
78  bool HasConnectionPaths() const;
79 
80  /// Clears the connection paths for this attribute.
81  SDF_API
82  void ClearConnectionPaths();
83 
84  /// @}
85  /// \name Attribute value API
86  /// @{
87 
88  /// Returns the allowed tokens metadata for this attribute.
89  /// Consumers may use this metadata to define a set of predefined
90  /// options for this attribute's value. However, this metadata is
91  /// purely advisory. It is up to the consumer to perform any
92  /// validation against this set of tokens, if desired.
93  SDF_API
94  VtTokenArray GetAllowedTokens() const;
95 
96  /// Sets the allowed tokens metadata for this attribute.
97  SDF_API
98  void SetAllowedTokens(const VtTokenArray& allowedTokens);
99 
100  /// Returns true if allowed tokens metadata is set for this attribute.
101  SDF_API
102  bool HasAllowedTokens() const;
103 
104  /// Clears the allowed tokens metadata for this attribute.
105  SDF_API
106  void ClearAllowedTokens();
107 
108  /// Returns the limits dictionary for this attribute.
109  SDF_API
110  VtDictionary GetLimits() const;
111 
112  /// Sets the limits dictionary for this attribute.
113  SDF_API
114  void SetLimits(const VtDictionary& limits);
115 
116  /// Returns true if limits metadata is set for this attribute.
117  SDF_API
118  bool HasLimits() const;
119 
120  /// Clears the limits metadata for this attribute.
121  SDF_API
122  void ClearLimits();
123 
124  /// Returns the display unit of the attribute.
125  SDF_API
126  TfEnum GetDisplayUnit() const;
127 
128  /// Sets the display unit of the attribute.
129  SDF_API
130  void SetDisplayUnit(const TfEnum& displayUnit);
131 
132  /// Returns true if a display unit is set for this attribute.
133  SDF_API
134  bool HasDisplayUnit() const;
135 
136  /// Clears the display unit of the attribute.
137  SDF_API
138  void ClearDisplayUnit();
139 
140  /// Returns the color space in which a color or texture valued attribute
141  /// is authored. Refer to GfColorSpaceNames for the list of built in
142  /// color spaces.
143  SDF_API
144  TfToken GetColorSpace() const;
145 
146  /// Sets the color space in which a color or texture valued attribute is
147  /// authored.
148  SDF_API
149  void SetColorSpace(const TfToken &colorSpace);
150 
151  /// Returns true if this attribute has a colorSpace value authored.
152  SDF_API
153  bool HasColorSpace() const;
154 
155  /// Clears the colorSpace metadata value set on this attribute.
156  SDF_API
157  void ClearColorSpace();
158 
159  /// Returns the array size constraint value for this attribute.
160  ///
161  /// For array-valued attributes, this value encodes information about the
162  /// expected number of elements and the tuple-length (i.e., column count):
163  ///
164  /// \li If the value is 0 (the fallback), the array is dynamic and its size
165  /// is unrestricted.
166  /// \li If the value is greater than 0, it indicates the exact, fixed size
167  /// of the array.
168  /// \li If the value is less than 0, its absolute value is the array's
169  /// tuple-length. The array's size is unrestricted, but must be a multiple
170  /// of this tuple-length.
171  SDF_API
172  int64_t GetArraySizeConstraint() const;
173 
174  /// Sets the array size constraint value for this attribute.
175  ///
176  /// \sa GetArraySizeConstraint() for a description of this value's encoding.
177  SDF_API
178  void SetArraySizeConstraint(int64_t constraint);
179 
180  /// Returns \c true if this attribute has an array size constraint value
181  /// authored.
182  SDF_API
183  bool HasArraySizeConstraint() const;
184 
185  /// Clears the array size constraint value for this attribute.
186  SDF_API
188 
189  /// @}
190  /// \name Spec properties
191  /// @{
192 
193  /// Returns the roleName for this attribute's typeName.
194  ///
195  /// If the typeName has no roleName, return empty token.
196  SDF_API
197  TfToken GetRoleName() const;
198 
199  /// @}
200 
201  /// \name Spline API
202  /// @{
203  /// Returns true if this attribute has a TsSpline value authored.
204  SDF_API
205  bool HasSpline() const;
206 
207  /// Returns the TsSpline at this attribute spec if a spec exists, otherwise
208  /// an empty spline is returned.
209  SDF_API
210  TsSpline GetSpline() const;
211 
212  /// Set the provided value as the spline for this attribute spec.
213  SDF_API
214  void SetSpline(const TsSpline& value);
215 
216  /// Clear the spline from this attribute spec.
217  SDF_API
218  void ClearSpline();
219 
220  /// @}
221 
222  /// \name Time-sample API
223  /// @{
224  /// Returns the entire set of time samples.
225  SDF_API
227 
228  SDF_API
229  std::set<double> ListTimeSamples() const;
230 
231  SDF_API
232  size_t GetNumTimeSamples() const;
233 
234  SDF_API
235  bool GetBracketingTimeSamples(double time, double* tLower,
236  double* tUpper) const;
237 
238  SDF_API
239  bool QueryTimeSample(double time, VtValue *value=NULL) const;
240  SDF_API
241  bool QueryTimeSample(double time, SdfAbstractDataValue *value) const;
242 
243  template <class T>
244  bool QueryTimeSample(double time, T* data) const
245  {
246  if (!data) {
247  return QueryTimeSample(time);
248  }
249 
250  SdfAbstractDataTypedValue<T> outValue(data);
251  const bool hasValue = QueryTimeSample(
252  time, static_cast<SdfAbstractDataValue *>(&outValue));
253 
255  return hasValue && outValue.isValueBlock;
256  }
257 
258  return hasValue && (!outValue.isValueBlock);
259  }
260 
261  SDF_API
262  void SetTimeSample(double time, const VtValue & value);
263  SDF_API
264  void SetTimeSample(double time, const SdfAbstractDataConstValue& value);
265 
266  template <class T>
267  void SetTimeSample(double time, const T& value)
268  {
269  const SdfAbstractDataConstTypedValue<T> inValue(&value);
270  const SdfAbstractDataConstValue& untypedInValue = inValue;
271  return SetTimeSample(time, untypedInValue);
272  }
273 
274  SDF_API
275  void EraseTimeSample(double time);
276 
277  /// @}
278 };
279 
280 /// Convenience function to create an attributeSpec on a primSpec at the given
281 /// path, and any necessary parent primSpecs, in the given layer.
282 ///
283 /// If an attributeSpec already exists at the given path,
284 /// author typeName, variability, and custom according to passed arguments
285 /// and return an attribute spec handle.
286 ///
287 /// Any newly created prim specs have SdfSpecifierOver and an empty type (as if
288 /// created by SdfJustCreatePrimInLayer()). attrPath must be a valid prim
289 /// property path (see SdfPath::IsPrimPropertyPath()). Return false and issue
290 /// an error if we fail to author the required scene description.
291 SDF_API
292 SdfAttributeSpecHandle
294  const SdfLayerHandle &layer,
295  const SdfPath &attrPath,
296  const SdfValueTypeName &typeName,
298  bool isCustom = false);
299 
300 /// Convenience function to create an attributeSpec on a primSpec at the given
301 /// path, and any necessary parent primSpecs, in the given layer.
302 ///
303 /// If an attributeSpec already exists at the given path, just author typeName,
304 /// variability, and custom according to passed arguments and return true.
305 ///
306 /// Any newly created prim specs have SdfSpecifierOver and an empty type (as if
307 /// created by SdfJustCreatePrimInLayer()). attrPath must be a valid prim
308 /// property path (see SdfPath::IsPrimPropertyPath()). Return false and issue
309 /// an error if we fail to author the required scene description.
310 ///
311 /// Differs only from SdfCreatePrimAttributeInLayer only in that a bool, not
312 /// a handle, is returned.
313 SDF_API
314 bool
316  const SdfLayerHandle &layer,
317  const SdfPath &attrPath,
318  const SdfValueTypeName &typeName,
320  bool isCustom = false);
321 
323 
324 #endif // PXR_USD_SDF_ATTRIBUTE_SPEC_H
SDF_API void ClearSpline()
Clear the spline from this attribute spec.
SDF_API SdfConnectionsProxy GetConnectionPathList() const
SDF_API bool QueryTimeSample(double time, VtValue *value=NULL) const
GT_API const UT_StringHolder time
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
GLsizei const GLfloat * value
Definition: glcorearb.h:824
static SDF_API SdfAttributeSpecHandle New(const SdfPrimSpecHandle &owner, const std::string &name, const SdfValueTypeName &typeName, SdfVariability variability=SdfVariabilityVarying, bool custom=false)
SdfAttributeSpec This
Definition: attributeSpec.h:46
SDF_API bool HasSpline() const
SDF_API bool HasConnectionPaths() const
Returns true if any connection paths are set on this attribute.
Definition: enum.h:119
SdfPropertySpec Parent
Definition: attributeSpec.h:47
SDF_API void SetSpline(const TsSpline &value)
Set the provided value as the spline for this attribute spec.
SDF_API TsSpline GetSpline() const
SDF_API VtTokenArray GetAllowedTokens() const
bool QueryTimeSample(double time, T *data) const
SDF_API void ClearAllowedTokens()
Clears the allowed tokens metadata for this attribute.
SDF_API void ClearColorSpace()
Clears the colorSpace metadata value set on this attribute.
GLenum GLuint GLint GLint layer
Definition: glcorearb.h:1299
SDF_API void EraseTimeSample(double time)
Definition: token.h:70
SDF_API bool SdfJustCreatePrimAttributeInLayer(const SdfLayerHandle &layer, const SdfPath &attrPath, const SdfValueTypeName &typeName, SdfVariability variability=SdfVariabilityVarying, bool isCustom=false)
SDF_API bool HasColorSpace() const
Returns true if this attribute has a colorSpace value authored.
SDF_API SdfTimeSampleMap GetTimeSampleMap() const
SDF_API bool HasAllowedTokens() const
Returns true if allowed tokens metadata is set for this attribute.
SDF_API size_t GetNumTimeSamples() const
void SetTimeSample(double time, const T &value)
SDF_API std::set< double > ListTimeSamples() const
GLuint const GLchar * name
Definition: glcorearb.h:786
SDF_API bool HasArraySizeConstraint() const
Definition: path.h:280
SDF_API bool HasLimits() const
Returns true if limits metadata is set for this attribute.
SDF_API void ClearDisplayUnit()
Clears the display unit of the attribute.
SdfVariability
Definition: types.h:159
SDF_API void SetLimits(const VtDictionary &limits)
Sets the limits dictionary for this attribute.
#define SDF_API
Definition: api.h:23
SDF_API void SetDisplayUnit(const TfEnum &displayUnit)
Sets the display unit of the attribute.
SDF_API void SetColorSpace(const TfToken &colorSpace)
SDF_API void ClearConnectionPaths()
Clears the connection paths for this attribute.
SDF_API TfToken GetColorSpace() const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
SDF_API SdfAttributeSpecHandle SdfCreatePrimAttributeInLayer(const SdfLayerHandle &layer, const SdfPath &attrPath, const SdfValueTypeName &typeName, SdfVariability variability=SdfVariabilityVarying, bool isCustom=false)
SDF_API bool GetBracketingTimeSamples(double time, double *tLower, double *tUpper) const
SDF_API TfToken GetRoleName() const
SDF_API bool HasDisplayUnit() const
Returns true if a display unit is set for this attribute.
SDF_API VtDictionary GetLimits() const
Returns the limits dictionary for this attribute.
SDF_API void ClearArraySizeConstraint()
Clears the array size constraint value for this attribute.
SDF_API void ClearLimits()
Clears the limits metadata for this attribute.
SDF_API void SetArraySizeConstraint(int64_t constraint)
std::map< double, VtValue > SdfTimeSampleMap
A map from sample times to sample values.
Definition: types.h:280
Definition: value.h:89
SDF_API int64_t GetArraySizeConstraint() const
Definition: format.h:1821
SDF_API TfEnum GetDisplayUnit() const
Returns the display unit of the attribute.
SDF_API void SetTimeSample(double time, const VtValue &value)
SDF_API void SetAllowedTokens(const VtTokenArray &allowedTokens)
Sets the allowed tokens metadata for this attribute.