This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
variantSets.h
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_VARIANT_SETS_H
8#define PXR_USD_USD_VARIANT_SETS_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/editTarget.h"
14#include "pxr/usd/usd/prim.h"
15
17
18#include <string>
19#include <vector>
20
21PXR_NAMESPACE_OPEN_SCOPE
22
23
24SDF_DECLARE_HANDLES(SdfLayer);
25SDF_DECLARE_HANDLES(SdfPrimSpec);
26SDF_DECLARE_HANDLES(SdfVariantSetSpec);
27
28class SdfPath;
29
40public:
58 USD_API
59 bool AddVariant(const std::string& variantName,
61
64 USD_API
65 std::vector<std::string> GetVariantNames() const;
66
68 // named \p variantName in any layer.
69 USD_API
70 bool HasAuthoredVariant(const std::string& variantName) const;
71
74 USD_API
75 std::string GetVariantSelection() const;
76
82 USD_API
83 bool HasAuthoredVariantSelection(std::string *value = nullptr) const;
84
93 USD_API
94 bool SetVariantSelection(const std::string &variantName);
95
98 USD_API
100
104 USD_API
106
119 USD_API
121 GetVariantEditTarget(const SdfLayerHandle &layer = SdfLayerHandle()) const;
122
147 USD_API
148 std::pair<UsdStagePtr, UsdEditTarget>
149 GetVariantEditContext(const SdfLayerHandle &layer = SdfLayerHandle()) const;
150
151
153 UsdPrim const &GetPrim() const { return _prim; }
154
155
157 std::string const &GetName() const { return _variantSetName; }
158
159
162 bool IsValid() const {
163 return static_cast<bool>(_prim);
164 }
165
167 explicit operator bool() const {
168 return IsValid();
169 }
170
171private:
172 UsdVariantSet(const UsdPrim &prim,
173 const std::string &variantSetName)
174 : _prim(prim)
175 , _variantSetName(variantSetName)
176 {
177 }
178
179 SdfPrimSpecHandle _CreatePrimSpecForEditing();
180 SdfVariantSetSpecHandle _AddVariantSet(UsdListPosition position);
181
182 UsdPrim _prim;
183 std::string _variantSetName;
184
185 friend class UsdPrim;
186 friend class UsdVariantSets;
187};
188
189
190// TODO:
191// VariantSet Names are stored as SdListOps, but a VariantSet is an actual spec
192// (like a Prim). Is it important to make that distinction here?
193
206public:
207
219 USD_API
220 UsdVariantSet AddVariantSet(const std::string& variantSetName,
222
223 // TODO: don't we want remove and reorder, clear, etc. also?
224
228 USD_API
229 bool GetNames(std::vector<std::string>* names) const;
230
232 USD_API
233 std::vector<std::string> GetNames() const;
234
235 UsdVariantSet operator[](const std::string& variantSetName) const {
236 return GetVariantSet(variantSetName);
237 }
238
242 USD_API
243 UsdVariantSet GetVariantSet(const std::string& variantSetName) const;
244
247 USD_API
248 bool HasVariantSet(const std::string& variantSetName) const;
249
253 USD_API
254 std::string GetVariantSelection(const std::string& variantSetName) const;
255
256 USD_API
257 bool SetSelection(const std::string& variantSetName,
258 const std::string& variantName);
259
263 USD_API
265
266
267private:
268 explicit UsdVariantSets(const UsdPrim& prim)
269 : _prim(prim)
270 {
271 /* NOTHING */
272 }
273
274 UsdPrim _prim;
275
276 friend class UsdPrim;
277};
278
279
280PXR_NAMESPACE_CLOSE_SCOPE
281
282#endif //PXR_USD_USD_VARIANT_SETS_H
A scene description container that can combine with other such containers to form simple component as...
Definition: layer.h:84
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
Represents a prim description in an SdfLayer object.
Definition: primSpec.h:58
Represents a coherent set of alternate representations for part of a scene.
Defines a mapping from scene graph paths to Sdf spec paths in a SdfLayer where edits should be direct...
Definition: editTarget.h:64
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:117
A UsdVariantSet represents a single VariantSet in USD (e.g.
Definition: variantSets.h:39
USD_API std::string GetVariantSelection() const
Return the variant selection for this VariantSet.
std::string const & GetName() const
Return this VariantSet's name.
Definition: variantSets.h:157
USD_API bool AddVariant(const std::string &variantName, UsdListPosition position=UsdListPositionBackOfPrependList)
Author a variant spec for variantName in this VariantSet at the stage's current EditTarget,...
USD_API bool BlockVariantSelection()
Block any weaker selections for this VariantSet by authoring an empty string at the stage's current E...
UsdPrim const & GetPrim() const
Return this VariantSet's held prim.
Definition: variantSets.h:153
USD_API bool HasAuthoredVariant(const std::string &variantName) const
Returns true if this VariantSet already possesses a variant.
USD_API bool SetVariantSelection(const std::string &variantName)
Author a variant selection for this VariantSet, setting it to variantName in the stage's current Edit...
USD_API std::pair< UsdStagePtr, UsdEditTarget > GetVariantEditContext(const SdfLayerHandle &layer=SdfLayerHandle()) const
Helper function for configuring a UsdStage's EditTarget to author into the currently selected variant...
USD_API std::vector< std::string > GetVariantNames() const
Return the composed variant names for this VariantSet, ordered lexicographically.
USD_API bool HasAuthoredVariantSelection(std::string *value=nullptr) const
Returns true if there is a selection authored for this VariantSet in any layer.
USD_API UsdEditTarget GetVariantEditTarget(const SdfLayerHandle &layer=SdfLayerHandle()) const
Return a UsdEditTarget that edits the currently selected variant in this VariantSet in layer.
bool IsValid() const
Is this UsdVariantSet object usable? If not, calling any of its other methods is likely to crash.
Definition: variantSets.h:162
USD_API bool ClearVariantSelection()
Clear any selection for this VariantSet from the current EditTarget.
UsdVariantSets represents the collection of VariantSets that are present on a UsdPrim.
Definition: variantSets.h:205
USD_API std::string GetVariantSelection(const std::string &variantSetName) const
Return the composed variant selection for the VariantSet named variantSetName.
USD_API SdfVariantSelectionMap GetAllVariantSelections() const
Returns the composed map of all variant selections authored on the the originating UsdPrim,...
USD_API UsdVariantSet GetVariantSet(const std::string &variantSetName) const
Return a UsdVariantSet object for variantSetName.
USD_API std::vector< std::string > GetNames() const
Return a list of all VariantSets authored on the originating UsdPrim.
USD_API bool HasVariantSet(const std::string &variantSetName) const
Returns true if a VariantSet named variantSetName exists on the originating prim.
USD_API bool GetNames(std::vector< std::string > *names) const
Compute the list of all VariantSets authored on the originating UsdPrim.
USD_API UsdVariantSet AddVariantSet(const std::string &variantSetName, UsdListPosition position=UsdListPositionBackOfPrependList)
Find an existing, or create a new VariantSet on the originating UsdPrim, named variantSetName.
UsdListPosition
Specifies a position to add items to lists.
Definition: common.h:71
@ UsdListPositionBackOfPrependList
The position at the back of the prepend list.
Definition: common.h:81
std::map< std::string, std::string > SdfVariantSelectionMap
A map of reference variant set names to variants in those sets.
Definition: types.h:258