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  ///
121  /// \deprecated
122  /// See UsdUIPropertyHints.
123  USD_API
124  std::string GetDisplayGroup() const;
125 
126  /// Sets this property's display group (metadata). Returns true on success.
127  ///
128  /// DisplayGroup provides UI hinting for grouping related properties
129  /// together for display. We define a convention for specifying nesting
130  /// of groups by recognizing the property namespace separator in
131  /// displayGroup as denoting group-nesting.
132  /// \sa SetNestedDisplayGroups()
133  ///
134  /// \deprecated
135  /// See UsdUIPropertyHints.
136  USD_API
137  bool SetDisplayGroup(const std::string& displayGroup) const;
138 
139  /// Clears this property's display group (metadata) in
140  /// the current EditTarget (only). Returns true on success.
141  ///
142  /// \deprecated
143  /// See UsdUIPropertyHints.
144  USD_API
145  bool ClearDisplayGroup() const;
146 
147  /// Returns true if displayGroup was explicitly authored and GetMetadata()
148  /// will return a meaningful value for displayGroup.
149  ///
150  /// \deprecated
151  /// See UsdUIPropertyHints.
152  USD_API
153  bool HasAuthoredDisplayGroup() const;
154 
155  /// Return this property's displayGroup as a sequence of groups to be
156  /// nested, or an empty vector if displayGroup is empty or not authored.
157  ///
158  /// \deprecated
159  /// See UsdUIPropertyHints.
160  USD_API
161  std::vector<std::string> GetNestedDisplayGroups() const;
162 
163  /// Sets this property's display group (metadata) to the nested sequence.
164  /// Returns true on success.
165  ///
166  /// A displayGroup set with this method can still be retrieved with
167  /// GetDisplayGroup(), with the namespace separator embedded in the result.
168  /// If \p nestedGroups is empty, we author an empty string for displayGroup.
169  /// \sa SetDisplayGroup()
170  ///
171  /// \deprecated
172  /// See UsdUIPropertyHints.
173  USD_API
175  const std::vector<std::string>& nestedGroups) const;
176 
177  /// Return true if this is a custom property (i.e., not part of a
178  /// prim schema).
179  ///
180  /// The 'custom' modifier in USD serves the same function as Alembic's
181  /// 'userProperties', which is to say as a categorization for ad hoc
182  /// client data not formalized into any schema, and therefore not
183  /// carrying an expectation of specific processing by consuming applications.
184  USD_API
185  bool IsCustom() const;
186 
187  /// Set the value for custom at the current EditTarget, return true on
188  /// success, false if the value can not be written.
189  ///
190  /// \b Note that this value should not be changed as it is typically either
191  /// automatically authored or provided by a property definition. This method
192  /// is provided primarily for fixing invalid scene description.
193  USD_API
194  bool SetCustom(bool isCustom) const;
195 
196  /// @}
197  /// \name Existence and Validity
198  /// @{
199 
200  /// Return true if this is a builtin property or if the strongest
201  /// authored SdfPropertySpec for this property's path matches this
202  /// property's dynamic type. That is, SdfRelationshipSpec in case this is a
203  /// UsdRelationship, and SdfAttributeSpec in case this is a UsdAttribute.
204  /// Return \c false if this property's prim has expired.
205  ///
206  /// For attributes, a \c true return does not imply that this attribute
207  /// possesses a value, only that has been declared, is of a certain type and
208  /// variability, and that it is safe to use to query and author values and
209  /// metadata.
210  USD_API
211  bool IsDefined() const;
212 
213  /// Return true if there are any authored opinions for this property
214  /// in any layer that contributes to this stage, false otherwise.
215  USD_API
216  bool IsAuthored() const;
217 
218  /// Return true if there is an SdfPropertySpec authored for this
219  /// property at the given \a editTarget, otherwise return false. Note
220  /// that this method does not do partial composition. It does not consider
221  /// whether authored scene description exists at \a editTarget or weaker,
222  /// only <b>exactly at</b> the given \a editTarget.
223  USD_API
224  bool IsAuthoredAt(const class UsdEditTarget &editTarget) const;
225 
226  /// @}
227 
228  // --------------------------------------------------------------------- //
229  /// \name Flattening
230  // --------------------------------------------------------------------- //
231 
232  /// Flattens this property to a property spec with the same name
233  /// beneath the given \p parent prim in the edit target of its owning stage.
234  ///
235  /// The \p parent prim may belong to a different stage than this property's
236  /// owning stage.
237  ///
238  /// Flattening authors all authored resolved values and metadata for
239  /// this property into the destination property spec. If this property
240  /// is a builtin property, fallback values and metadata will also be
241  /// authored if the destination property has a different fallback
242  /// value or no fallback value, or if the destination property has an
243  /// authored value that overrides its fallback.
244  ///
245  /// Attribute connections and relationship targets that target an
246  /// object beneath this property's owning prim will be remapped to
247  /// target objects beneath the destination \p parent prim.
248  ///
249  /// If the destination spec already exists, it will be overwritten.
250  ///
251  /// \sa UsdStage::Flatten
252  USD_API
253  UsdProperty FlattenTo(const UsdPrim &parent) const;
254 
255  /// \overload
256  /// Flattens this property to a property spec with the given
257  /// \p propName beneath the given \p parent prim in the edit target of its
258  /// owning stage.
259  ///
260  /// The \p parent prim may belong to a different stage than this property's
261  /// owning stage.
262  USD_API
263  UsdProperty FlattenTo(const UsdPrim &parent,
264  const TfToken &propName) const;
265 
266  /// \overload
267  /// Flattens this property to a property spec for the given
268  /// \p property in the edit target of its owning prim's stage.
269  ///
270  /// The \p property owning prim may belong to a different stage than this
271  /// property's owning stage.
272  USD_API
273  UsdProperty FlattenTo(const UsdProperty &property) const;
274 
275 protected:
276  template <class Derived>
278 
279  // Gets the targets of the given spec type. Returns true if an authored
280  // opinion is found and no composition errors occured. If foundErrors is
281  // provided, it will be set to true only if errors are encountered.
282  bool _GetTargets(SdfSpecType specType, SdfPathVector *out,
283  bool *foundErrors = nullptr) const;
284 
285 private:
286  friend class UsdAttribute;
287  friend class UsdObject;
288  friend class UsdPrim;
289  friend class UsdRelationship;
290  friend class Usd_PrimData;
291 
292  UsdProperty(UsdObjType objType,
293  const Usd_PrimDataHandle &prim,
294  const SdfPath &proxyPrimPath,
295  const TfToken &propName)
296  : UsdObject(objType, prim, proxyPrimPath, propName) {}
297 
298 };
299 
300 
302 
303 #endif // PXR_USD_USD_PROPERTY_H
USD_API bool IsDefined() const
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:277
GT_API const UT_StringHolder time
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
USD_API bool ClearDisplayGroup() const
UsdObjType
Definition: object.h:35
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:280
USD_API bool SetDisplayGroup(const std::string &displayGroup) const
USD_API SdfPropertySpecHandleVector GetPropertyStack(UsdTimeCode time=UsdTimeCode::Default()) const
USD_API bool SetCustom(bool isCustom) const
SdfSpecType
Definition: types.h:71
#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