All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
relationship.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_RELATIONSHIPS_H
25 #define USD_RELATIONSHIPS_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 
32 #include "pxr/usd/sdf/path.h"
33 #include "pxr/base/vt/value.h"
34 
35 #include <string>
36 #include <vector>
37 
38 PXR_NAMESPACE_OPEN_SCOPE
39 
40 
41 class UsdRelationship;
42 
44 typedef std::vector<UsdRelationship> UsdRelationshipVector;
45 
128 class UsdRelationship : public UsdProperty {
129 public:
132  : UsdProperty(UsdTypeRelationship, Usd_PrimDataHandle(), SdfPath(),
133  TfToken())
134  {
135  }
136 
139 
140  // XXX Should the mutation API be changed to take UsdObject
141  // pointers so that we can enforce (as does Mf) that you can only
142  // target extant scenegraph objects? (Note the API would still need to
143  // validate those objects since it is easy to create a UsdAttribute
144  // or UsdRelationship object not backed by scene description).
145 
156  USD_API
157  bool AddTarget(const SdfPath& target,
159 
165  USD_API
166  bool RemoveTarget(const SdfPath& target) const;
167 
171  USD_API
172  bool BlockTargets() const;
173 
183  USD_API
184  bool SetTargets(const SdfPathVector& targets) const;
185 
192  USD_API
193  bool ClearTargets(bool removeSpec) const;
194 
202  USD_API
203  bool GetTargets(SdfPathVector* targets) const;
204 
227  USD_API
228  bool GetForwardedTargets(SdfPathVector* targets) const;
229 
233  USD_API
234  bool HasAuthoredTargets() const;
235 
237 
238 private:
239  friend class UsdObject;
240  friend class UsdPrim;
241  friend class Usd_PrimData;
242  template <class A0, class A1>
243  friend struct UsdPrim_TargetFinder;
244 
245  UsdRelationship(const Usd_PrimDataHandle &prim,
246  const SdfPath &proxyPrimPath,
247  const TfToken& relName)
248  : UsdProperty(UsdTypeRelationship, prim, proxyPrimPath, relName) {}
249 
250  UsdRelationship(UsdObjType objType,
251  const Usd_PrimDataHandle &prim,
252  const SdfPath &proxyPrimPath,
253  const TfToken &propName)
254  : UsdProperty(objType, prim, proxyPrimPath, propName) {}
255 
256  SdfRelationshipSpecHandle _CreateSpec(bool fallbackCustom=true) const;
257  bool _Create(bool fallbackCustom) const;
258 
259  bool _GetForwardedTargets(SdfPathVector* targets,
260  bool includeForwardingRels) const;
261 
262  bool _GetForwardedTargets(SdfPathSet* visited,
263  SdfPathSet* uniqueTargets,
264  SdfPathVector* targets,
265  bool includeForwardingRels) const;
266 
267  SdfPath _GetTargetForAuthoring(const SdfPath &targetPath,
268  std::string* whyNot = 0) const;
269 };
270 
271 
272 PXR_NAMESPACE_CLOSE_SCOPE
273 
274 #endif //USD_RELATIONSHIPS_H
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 ClearTargets(bool removeSpec) const
Remove all opinions about the target list from the current edit target.
USD_API bool GetForwardedTargets(SdfPathVector *targets) const
Compose this relationship&#39;s ultimate targets, taking into account &quot;relationship forwarding&quot;, and fill targets with the result.
USD_API bool RemoveTarget(const SdfPath &target) const
Removes target from the list of targets.
USD_API bool BlockTargets() const
Clears all target 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.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
USD_API bool SetTargets(const SdfPathVector &targets) const
Make the authoring layer&#39;s opinion of the targets list explicit, and set exactly to targets...
Base class for Usd scenegraph objects, providing common API.
Definition: object.h:129
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 HasAuthoredTargets() const
Returns true if any target path opinions have been authored.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
A UsdRelationship creates dependencies between scenegraph objects by allowing a prim to target other ...
Definition: relationship.h:128
UsdRelationship()
Construct an invalid relationship.
Definition: relationship.h:131
Base class for UsdAttribute and UsdRelationship scenegraph objects.
Definition: property.h:55
The position at the back of the prepend list.
Definition: common.h:120
USD_API bool GetTargets(SdfPathVector *targets) const
Compose this relationship&#39;s targets and fill targets with the result.
USD_API bool AddTarget(const SdfPath &target, UsdListPosition position=UsdListPositionBackOfPrependList) const
Adds target to the list of targets, in the position specified by position.