All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
attribute.h
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef USD_ATTRIBUTE_H
25 #define USD_ATTRIBUTE_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/usd/api.h"
29 #include "pxr/usd/usd/common.h"
30 #include "pxr/usd/usd/property.h"
31 #include "pxr/usd/usd/resolveInfo.h"
32 
33 #include "pxr/usd/sdf/abstractData.h"
34 #include "pxr/usd/sdf/path.h"
35 #include "pxr/usd/sdf/types.h"
36 #include "pxr/base/vt/value.h"
37 #include "pxr/base/gf/interval.h"
38 
39 #include <string>
40 #include <type_traits>
41 #include <vector>
42 
43 PXR_NAMESPACE_OPEN_SCOPE
44 
45 
46 class UsdAttribute;
47 
49 typedef std::vector<UsdAttribute> UsdAttributeVector;
50 
176 class UsdAttribute : public UsdProperty {
177 public:
180  : UsdProperty(UsdTypeAttribute, Usd_PrimDataHandle(), SdfPath(),
181  TfToken())
182  {
183  }
184 
185  // --------------------------------------------------------------------- //
187  // --------------------------------------------------------------------- //
188 
190 
197  USD_API
199 
206  USD_API
207  bool SetVariability(SdfVariability variability) const;
208 
210  USD_API
212 
219  USD_API
220  bool SetTypeName(const SdfValueTypeName& typeName) const;
221 
223  USD_API
224  TfToken GetRoleName() const;
225 
227 
228  // --------------------------------------------------------------------- //
231  // --------------------------------------------------------------------- //
232 
234 
251  USD_API
252  bool GetTimeSamples(std::vector<double>* times) const;
253 
268  USD_API
269  bool GetTimeSamplesInInterval(const GfInterval& interval,
270  std::vector<double>* times) const;
271 
290  USD_API
291  static bool GetUnionedTimeSamples(const std::vector<UsdAttribute> &attrs,
292  std::vector<double> *times);
293 
313  USD_API
315  const std::vector<UsdAttribute> &attrs,
316  const GfInterval &interval,
317  std::vector<double> *times);
318 
328  USD_API
329  size_t GetNumTimeSamples() const;
330 
356  USD_API
357  bool GetBracketingTimeSamples(double desiredTime,
358  double* lower,
359  double* upper,
360  bool* hasTimeSamples) const;
361 
366  USD_API
367  bool HasValue() const;
368 
377  USD_API
378  bool HasAuthoredValueOpinion() const;
379 
383  USD_API
384  bool HasAuthoredValue() const;
385 
388  USD_API
389  bool HasFallbackValue() const;
390 
400  USD_API
401  bool ValueMightBeTimeVarying() const;
402 
434  template <typename T>
435  bool Get(T* value, UsdTimeCode time = UsdTimeCode::Default()) const {
436  static_assert(!std::is_const<T>::value, "");
437  static_assert(SdfValueTypeTraits<T>::IsValueType, "");
438  return _Get(value, time);
439  }
442  USD_API
443  bool Get(VtValue* value, UsdTimeCode time = UsdTimeCode::Default()) const;
444 
448  USD_API
451 
465  template <typename T>
466  bool Set(const T& value, UsdTimeCode time = UsdTimeCode::Default()) const {
467  static_assert(!std::is_pointer<T>::value, "");
468  static_assert(SdfValueTypeTraits<T>::IsValueType ||
469  std::is_same<T, SdfValueBlock>::value, "");
470  return _Set(value, time);
471  }
472 
476  USD_API
477  bool Set(const char* value, UsdTimeCode time = UsdTimeCode::Default()) const;
478 
480  USD_API
481  bool Set(const VtValue& value, UsdTimeCode time = UsdTimeCode::Default()) const;
482 
490  USD_API
491  bool Clear() const;
492 
499  USD_API
500  bool ClearAtTime(UsdTimeCode time) const;
501 
503  USD_API
504  bool ClearDefault() const;
505 
512  USD_API
513  void Block() const;
514 
516 
519 
530  USD_API
531  bool AddConnection(const SdfPath& source,
533 
539  USD_API
540  bool RemoveConnection(const SdfPath& source) const;
541 
545  USD_API
546  bool BlockConnections() const;
547 
556  USD_API
557  bool SetConnections(const SdfPathVector& sources) const;
558 
561  USD_API
562  bool ClearConnections() const;
563 
571  USD_API
572  bool GetConnections(SdfPathVector* sources) const;
573 
578  USD_API
579  bool HasAuthoredConnections() const;
580 
582 
583  // ---------------------------------------------------------------------- //
594  // ---------------------------------------------------------------------- //
595 
599  USD_API
600  TfToken GetColorSpace() const;
601 
605  USD_API
606  void SetColorSpace(const TfToken &colorSpace) const;
607 
610  USD_API
611  bool HasColorSpace() const;
612 
615  USD_API
616  bool ClearColorSpace() const;
617 
619 
620  // ---------------------------------------------------------------------- //
621  // Private Methods and Members
622  // ---------------------------------------------------------------------- //
623 private:
624  friend class UsdAttributeQuery;
625  friend class UsdObject;
626  friend class UsdPrim;
627  friend class UsdSchemaBase;
628  friend class Usd_PrimData;
629  friend struct UsdPrim_AttrConnectionFinder;
630 
631  UsdAttribute(const Usd_PrimDataHandle &prim,
632  const SdfPath &proxyPrimPath,
633  const TfToken &attrName)
634  : UsdProperty(UsdTypeAttribute, prim, proxyPrimPath, attrName) {}
635 
636  UsdAttribute(UsdObjType objType,
637  const Usd_PrimDataHandle &prim,
638  const SdfPath &proxyPrimPath,
639  const TfToken &propName)
640  : UsdProperty(objType, prim, proxyPrimPath, propName) {}
641 
642  SdfAttributeSpecHandle
643  _CreateSpec(const SdfValueTypeName &typeName, bool custom,
644  const SdfVariability &variability) const;
645 
646  // Like _CreateSpec(), but fail if this attribute is not built-in and there
647  // isn't already existing scene description to go on rather than stamping
648  // new information.
649  SdfAttributeSpecHandle _CreateSpec() const;
650 
651  bool _Create(const SdfValueTypeName &typeName, bool custom,
652  const SdfVariability &variability) const;
653 
654  template <typename T>
655  bool _Get(T* value, UsdTimeCode time) const;
656 
657  template <typename T>
658  bool _Set(const T& value, UsdTimeCode time) const;
659 
660  SdfPath
661  _GetPathForAuthoring(const SdfPath &path, std::string* whyNot) const;
662 };
663 
664 PXR_NAMESPACE_CLOSE_SCOPE
665 
666 #endif // USD_ATTRIBUTE_H
USD_API bool AddConnection(const SdfPath &source, UsdListPosition position=UsdListPositionBackOfPrependList) const
Adds source to the list of connections, in the position specified by position.
bool Set(const T &value, UsdTimeCode time=UsdTimeCode::Default()) const
Set the value of this attribute in the current UsdEditTarget to value at UsdTimeCode time...
Definition: attribute.h:466
USD_API bool SetVariability(SdfVariability variability) const
Set the value for variability at the current EditTarget, return true on success, false if the value c...
UsdObjType
Enum values to represent the various Usd object types.
Definition: object.h:48
UsdListPosition
Specifies a position to add items to lists.
Definition: common.h:110
USD_API bool SetTypeName(const SdfValueTypeName &typeName) const
Set the value for typeName at the current EditTarget, return true on success, false if the value can ...
USD_API UsdResolveInfo GetResolveInfo(UsdTimeCode time=UsdTimeCode::Default()) const
Perform value resolution to determine the source of the resolved value of this attribute at the reque...
USD_API SdfVariability GetVariability() const
An attribute&#39;s variability expresses whether it is intended to have time-samples (SdfVariabilityVaryi...
Object for efficiently making repeated queries for attribute values.
USD_API bool GetTimeSamplesInInterval(const GfInterval &interval, std::vector< double > *times) const
Populates a vector with authored sample times in interval.
Represents a value type name, i.e.
Definition: valueTypeName.h:83
USD_API bool GetTimeSamples(std::vector< double > *times) const
Populates a vector with authored sample times.
USD_API bool GetBracketingTimeSamples(double desiredTime, double *lower, double *upper, bool *hasTimeSamples) const
Populate lower and upper with the next greater and lesser value relative to the desiredTime.
Container for information about the source of an attribute&#39;s value, i.e.
Definition: resolveInfo.h:69
static USD_API bool GetUnionedTimeSamples(const std::vector< UsdAttribute > &attrs, std::vector< double > *times)
Populates the given vector, times with the union of all the authored sample times on all of the given...
Scenegraph object for authoring and retrieving numeric, string, and array valued data, sampled over time.
Definition: attribute.h:176
UsdAttribute()
Construct an invalid attribute.
Definition: attribute.h:179
USD_API bool ClearConnections() const
Remove all opinions about the connections list from the current edit target.
USD_API bool ValueMightBeTimeVarying() const
Return true if it is possible, but not certain, that this attribute&#39;s value changes over time...
USD_API bool HasAuthoredValueOpinion() const
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
USD_API bool HasAuthoredConnections() const
Return true if this attribute has any authored opinions regarding connections.
USD_API bool ClearColorSpace() const
Clears authored color-space value on the attribute.
USD_API bool HasAuthoredValue() const
Return true if this attribute has either an authored default value or authored time samples...
USD_API bool GetConnections(SdfPathVector *sources) const
Compose this attribute&#39;s connections and fill sources with the result.
USD_API bool HasColorSpace() const
Returns whether color-space is authored on the attribute.
USD_API bool RemoveConnection(const SdfPath &source) const
Removes target from the list of targets.
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:85
Base class for Usd scenegraph objects, providing common API.
Definition: object.h:129
SdfVariability
An enum that identifies variability types for attributes.
Definition: types.h:182
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a &quot;Prim&quot; as ...
Definition: prim.h:131
USD_API bool HasValue() const
Return true if this attribute has an authored default value, authored time samples or a fallback valu...
A basic mathematical interval class.
Definition: interval.h:50
USD_API TfToken GetColorSpace() const
Gets the color space in which the attribute is authored.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
bool Get(T *value, UsdTimeCode time=UsdTimeCode::Default()) const
Perform value resolution to fetch the value of this attribute at the requested UsdTimeCode time...
Definition: attribute.h:435
USD_API bool ClearAtTime(UsdTimeCode time) const
Clear the authored value for this attribute at the given time, at the current EditTarget and return t...
Base class for UsdAttribute and UsdRelationship scenegraph objects.
Definition: property.h:55
static constexpr UsdTimeCode Default()
Produce a UsdTimeCode representing the sentinel value for &#39;default&#39;.
Definition: timeCode.h:113
USD_API void SetColorSpace(const TfToken &colorSpace) const
Sets the color space of the attribute to colorSpace.
USD_API void Block() const
Remove all time samples on an attribute and author a block default value.
USD_API bool Clear() const
Clears the authored default value and all time samples for this attribute at the current EditTarget a...
USD_API bool HasFallbackValue() const
Return true if this attribute has a fallback value provided by a registered schema.
USD_API bool BlockConnections() const
Clears all connection edits from the current EditTarget, and makes the opinion explicit, which means we are effectively resetting the composed value of the targets list to empty.
The position at the back of the prepend list.
Definition: common.h:120
The base class for all schema types in Usd.
Definition: schemaBase.h:56
USD_API bool ClearDefault() const
Shorthand for ClearAtTime(UsdTimeCode::Default()).
USD_API SdfValueTypeName GetTypeName() const
Return the &quot;scene description&quot; value type name for this attribute.
static USD_API bool GetUnionedTimeSamplesInInterval(const std::vector< UsdAttribute > &attrs, const GfInterval &interval, std::vector< double > *times)
Populates the given vector, times with the union of all the authored sample times in the GfInterval...
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:182
USD_API bool SetConnections(const SdfPathVector &sources) const
Make the authoring layer&#39;s opinion of the connection list explicit, and set exactly to sources...
USD_API TfToken GetRoleName() const
Return the roleName for this attribute&#39;s typeName.
USD_API size_t GetNumTimeSamples() const
Returns the number of time samples that have been authored.