HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
property.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_USD_PROPERTY_H
8 #define PXR_USD_USD_PROPERTY_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/usd/usd/api.h"
12 #include "pxr/usd/usd/common.h"
13 #include "pxr/usd/usd/object.h"
14 #include "pxr/usd/usd/prim.h"
15 
16 #include "pxr/usd/sdf/path.h"
18 #include "pxr/base/vt/value.h"
19 
21 
22 
23 class UsdProperty;
24 
25 /// \class UsdProperty
26 ///
27 /// Base class for UsdAttribute and UsdRelationship scenegraph objects.
28 ///
29 /// UsdProperty has a bool conversion operator that validates that the property
30 /// IsDefined() and thus valid for querying and authoring values and metadata.
31 /// This is a fairly expensive query that we do <b>not</b> cache, so if client
32 /// code retains UsdProperty objects it should manage its object validity
33 /// closely for performance. An ideal pattern is to listen for
34 /// UsdNotice::StageContentsChanged notifications, and revalidate/refetch
35 /// retained UsdObjects only then and otherwise use them without validity
36 /// checking.
37 ///
38 class UsdProperty : public UsdObject {
39 public:
40  /// Construct an invalid property.
42 
43  // --------------------------------------------------------------------- //
44  /// \name Object and Namespace Accessors
45  // --------------------------------------------------------------------- //
46 
47  /// @{
48 
49  /// Returns a strength-ordered list of property specs that provide
50  /// opinions for this property.
51  ///
52  /// If \p time is UsdTimeCode::Default(), *or* this property
53  /// is a UsdRelationship (which are never affected by clips), we will
54  /// not consider value clips for opinions. For any other \p time, for
55  /// a UsdAttribute, clips whose samples may contribute an opinion will
56  /// be included. These specs are ordered from strongest to weakest opinion,
57  /// although if \p time requires interpolation between two adjacent clips,
58  /// both clips will appear, sequentially.
59  ///
60  /// \note The results returned by this method are meant for debugging
61  /// and diagnostic purposes. It is **not** advisable to retain a
62  /// PropertyStack for the purposes of expedited value resolution for
63  /// properties, since the makeup of an attribute's PropertyStack may
64  /// itself be time-varying. To expedite repeated value resolution of
65  /// attributes, you should instead retain a \c UsdAttributeQuery .
66  ///
67  /// \sa UsdClipsAPI
68  USD_API
69  SdfPropertySpecHandleVector GetPropertyStack(
71 
72  /// Returns a strength-ordered list of property specs that provide
73  /// opinions for this property paired with the cumulative layer offset from
74  /// the stage's root layer to the layer containing the property spec.
75  ///
76  /// This behaves exactly the same as UsdProperty::GetPropertyStack with the
77  /// addition of providing the cumulative layer offset of each spec's layer.
78  ///
79  /// \note The results returned by this method are meant for debugging
80  /// and diagnostic purposes. It is **not** advisable to retain a
81  /// PropertyStack for the purposes of expedited value resolution for
82  /// properties, since the makeup of an attribute's PropertyStack may
83  /// itself be time-varying. To expedite repeated value resolution of
84  /// attributes, you should instead retain a \c UsdAttributeQuery .
85  USD_API
86  std::vector<std::pair<SdfPropertySpecHandle, SdfLayerOffset>>
89 
90  /// Return this property's name with all namespace prefixes removed,
91  /// i.e. the last component of the return value of GetName()
92  ///
93  /// This is generally the property's "client name"; property namespaces are
94  /// often used to group related properties together. The namespace prefixes
95  /// the property name but many consumers will care only about un-namespaced
96  /// name, i.e. its BaseName. For more information, see \ref Usd_Ordering
97  USD_API
98  TfToken GetBaseName() const;
99 
100  /// Return this property's complete namespace prefix. Return the empty
101  /// token if this property has no namespaces.
102  ///
103  /// This is the complement of GetBaseName(), although it does \em not
104  /// contain a trailing namespace delimiter
105  USD_API
106  TfToken GetNamespace() const;
107 
108  /// Return this property's name elements including namespaces and its base
109  /// name as the final element.
110  USD_API
111  std::vector<std::string> SplitName() const;
112 
113  /// @}
114  /// \name Core Metadata
115  /// @{
116 
117  /// Return this property's display group (metadata). This returns the
118  /// empty token if no display group has been set.
119  /// \sa SetDisplayGroup()
120  USD_API
121  std::string GetDisplayGroup() const;
122 
123  /// Sets this property's display group (metadata). Returns true on success.
124  ///
125  /// DisplayGroup provides UI hinting for grouping related properties
126  /// together for display. We define a convention for specifying nesting
127  /// of groups by recognizing the property namespace separator in
128  /// displayGroup as denoting group-nesting.
129  /// \sa SetNestedDisplayGroups()
130  USD_API
131  bool SetDisplayGroup(const std::string& displayGroup) const;
132 
133  /// Clears this property's display group (metadata) in
134  /// the current EditTarget (only). Returns true on success.
135  USD_API
136  bool ClearDisplayGroup() const;
137 
138  /// Returns true if displayGroup was explicitly authored and GetMetadata()
139  /// will return a meaningful value for displayGroup.
140  USD_API
141  bool HasAuthoredDisplayGroup() const;
142 
143  /// Return this property's displayGroup as a sequence of groups to be
144  /// nested, or an empty vector if displayGroup is empty or not authored.
145  USD_API
146  std::vector<std::string> GetNestedDisplayGroups() const;
147 
148  /// Sets this property's display group (metadata) to the nested sequence.
149  /// Returns true on success.
150  ///
151  /// A displayGroup set with this method can still be retrieved with
152  /// GetDisplayGroup(), with the namespace separator embedded in the result.
153  /// If \p nestedGroups is empty, we author an empty string for displayGroup.
154  /// \sa SetDisplayGroup()
155  USD_API
157  const std::vector<std::string>& nestedGroups) const;
158 
159  /// Return true if this is a custom property (i.e., not part of a
160  /// prim schema).
161  ///
162  /// The 'custom' modifier in USD serves the same function as Alembic's
163  /// 'userProperties', which is to say as a categorization for ad hoc
164  /// client data not formalized into any schema, and therefore not
165  /// carrying an expectation of specific processing by consuming applications.
166  USD_API
167  bool IsCustom() const;
168 
169  /// Set the value for custom at the current EditTarget, return true on
170  /// success, false if the value can not be written.
171  ///
172  /// \b Note that this value should not be changed as it is typically either
173  /// automatically authored or provided by a property definition. This method
174  /// is provided primarily for fixing invalid scene description.
175  USD_API
176  bool SetCustom(bool isCustom) const;
177 
178  /// @}
179  /// \name Existence and Validity
180  /// @{
181 
182  /// Return true if this is a builtin property or if the strongest
183  /// authored SdfPropertySpec for this property's path matches this
184  /// property's dynamic type. That is, SdfRelationshipSpec in case this is a
185  /// UsdRelationship, and SdfAttributeSpec in case this is a UsdAttribute.
186  /// Return \c false if this property's prim has expired.
187  ///
188  /// For attributes, a \c true return does not imply that this attribute
189  /// possesses a value, only that has been declared, is of a certain type and
190  /// variability, and that it is safe to use to query and author values and
191  /// metadata.
192  USD_API
193  bool IsDefined() const;
194 
195  /// Return true if there are any authored opinions for this property
196  /// in any layer that contributes to this stage, false otherwise.
197  USD_API
198  bool IsAuthored() const;
199 
200  /// Return true if there is an SdfPropertySpec authored for this
201  /// property at the given \a editTarget, otherwise return false. Note
202  /// that this method does not do partial composition. It does not consider
203  /// whether authored scene description exists at \a editTarget or weaker,
204  /// only <b>exactly at</b> the given \a editTarget.
205  USD_API
206  bool IsAuthoredAt(const class UsdEditTarget &editTarget) const;
207 
208  /// @}
209 
210  // --------------------------------------------------------------------- //
211  /// \name Flattening
212  // --------------------------------------------------------------------- //
213 
214  /// Flattens this property to a property spec with the same name
215  /// beneath the given \p parent prim in the edit target of its owning stage.
216  ///
217  /// The \p parent prim may belong to a different stage than this property's
218  /// owning stage.
219  ///
220  /// Flattening authors all authored resolved values and metadata for
221  /// this property into the destination property spec. If this property
222  /// is a builtin property, fallback values and metadata will also be
223  /// authored if the destination property has a different fallback
224  /// value or no fallback value, or if the destination property has an
225  /// authored value that overrides its fallback.
226  ///
227  /// Attribute connections and relationship targets that target an
228  /// object beneath this property's owning prim will be remapped to
229  /// target objects beneath the destination \p parent prim.
230  ///
231  /// If the destination spec already exists, it will be overwritten.
232  ///
233  /// \sa UsdStage::Flatten
234  USD_API
235  UsdProperty FlattenTo(const UsdPrim &parent) const;
236 
237  /// \overload
238  /// Flattens this property to a property spec with the given
239  /// \p propName beneath the given \p parent prim in the edit target of its
240  /// owning stage.
241  ///
242  /// The \p parent prim may belong to a different stage than this property's
243  /// owning stage.
244  USD_API
245  UsdProperty FlattenTo(const UsdPrim &parent,
246  const TfToken &propName) const;
247 
248  /// \overload
249  /// Flattens this property to a property spec for the given
250  /// \p property in the edit target of its owning prim's stage.
251  ///
252  /// The \p property owning prim may belong to a different stage than this
253  /// property's owning stage.
254  USD_API
255  UsdProperty FlattenTo(const UsdProperty &property) const;
256 
257 protected:
258  template <class Derived>
260 
261  // Gets the targets of the given spec type. Returns true if an authored
262  // opinion is found and no composition errors occured. If foundErrors is
263  // provided, it will be set to true only if errors are encountered.
264  bool _GetTargets(SdfSpecType specType, SdfPathVector *out,
265  bool *foundErrors = nullptr) const;
266 
267 private:
268  friend class UsdAttribute;
269  friend class UsdObject;
270  friend class UsdPrim;
271  friend class UsdRelationship;
272  friend class Usd_PrimData;
273 
274  UsdProperty(UsdObjType objType,
275  const Usd_PrimDataHandle &prim,
276  const SdfPath &proxyPrimPath,
277  const TfToken &propName)
278  : UsdObject(objType, prim, proxyPrimPath, propName) {}
279 
280 };
281 
282 
284 
285 #endif // PXR_USD_USD_PROPERTY_H
USD_API bool IsDefined() const
UsdObjType
Definition: object.h:34
static constexpr UsdTimeCode Default()
Definition: timeCode.h:113
#define USD_API
Definition: api.h:23
USD_API TfToken GetBaseName() const
UsdProperty(_Null< Derived >)
Definition: property.h:259
GT_API const UT_StringHolder time
USD_API bool ClearDisplayGroup() const
USD_API std::vector< std::string > GetNestedDisplayGroups() const
USD_API std::vector< std::pair< SdfPropertySpecHandle, SdfLayerOffset > > GetPropertyStackWithLayerOffsets(UsdTimeCode time=UsdTimeCode::Default()) const
bool _GetTargets(SdfSpecType specType, SdfPathVector *out, bool *foundErrors=nullptr) const
Definition: token.h:70
USD_API std::vector< std::string > SplitName() const
std::vector< class SdfPath > SdfPathVector
USD_API UsdProperty FlattenTo(const UsdPrim &parent) const
UsdProperty()
Construct an invalid property.
Definition: property.h:41
USD_API bool IsAuthoredAt(const class UsdEditTarget &editTarget) const
Definition: prim.h:116
USD_API TfToken GetNamespace() const
Definition: path.h:273
USD_API bool SetDisplayGroup(const std::string &displayGroup) const
USD_API SdfPropertySpecHandleVector GetPropertyStack(UsdTimeCode time=UsdTimeCode::Default()) const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
USD_API bool SetCustom(bool isCustom) const
SdfSpecType
Definition: types.h:68
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
USD_API std::string GetDisplayGroup() const
USD_API bool IsCustom() const
USD_API bool SetNestedDisplayGroups(const std::vector< std::string > &nestedGroups) const
USD_API bool IsAuthored() const
USD_API bool HasAuthoredDisplayGroup() const