All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
variantSets.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 PXR_USD_USD_VARIANT_SETS_H
25 #define PXR_USD_USD_VARIANT_SETS_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/editTarget.h"
31 #include "pxr/usd/usd/prim.h"
32 
33 #include "pxr/usd/sdf/declareHandles.h"
34 
35 #include <string>
36 #include <vector>
37 
38 PXR_NAMESPACE_OPEN_SCOPE
39 
40 
41 SDF_DECLARE_HANDLES(SdfLayer);
42 SDF_DECLARE_HANDLES(SdfPrimSpec);
43 SDF_DECLARE_HANDLES(SdfVariantSetSpec);
44 
45 class SdfPath;
46 
57 public:
75  USD_API
76  bool AddVariant(const std::string& variantName,
78 
81  USD_API
82  std::vector<std::string> GetVariantNames() const;
83 
85  // named \p variantName in any layer.
86  USD_API
87  bool HasAuthoredVariant(const std::string& variantName) const;
88 
91  USD_API
92  std::string GetVariantSelection() const;
93 
99  USD_API
100  bool HasAuthoredVariantSelection(std::string *value = nullptr) const;
101 
105  USD_API
106  bool SetVariantSelection(const std::string &variantName);
107 
110  USD_API
111  bool ClearVariantSelection();
112 
125  USD_API
127  GetVariantEditTarget(const SdfLayerHandle &layer = SdfLayerHandle()) const;
128 
153  USD_API
154  std::pair<UsdStagePtr, UsdEditTarget>
155  GetVariantEditContext(const SdfLayerHandle &layer = SdfLayerHandle()) const;
156 
157 
159  UsdPrim const &GetPrim() const { return _prim; }
160 
161 
163  std::string const &GetName() const { return _variantSetName; }
164 
165 
168  bool IsValid() const {
169  return static_cast<bool>(_prim);
170  }
171 
173  explicit operator bool() const {
174  return IsValid();
175  }
176 
177 private:
178  UsdVariantSet(const UsdPrim &prim,
179  const std::string &variantSetName)
180  : _prim(prim)
181  , _variantSetName(variantSetName)
182  {
183  }
184 
185  SdfPrimSpecHandle _CreatePrimSpecForEditing();
186  SdfVariantSetSpecHandle _AddVariantSet(UsdListPosition position);
187 
188  UsdPrim _prim;
189  std::string _variantSetName;
190 
191  friend class UsdPrim;
192  friend class UsdVariantSets;
193 };
194 
195 
196 // TODO:
197 // VariantSet Names are stored as SdListOps, but a VariantSet is an actual spec
198 // (like a Prim). Is it important to make that distinction here?
199 
212 public:
213 
225  USD_API
226  UsdVariantSet AddVariantSet(const std::string& variantSetName,
228 
229  // TODO: don't we want remove and reorder, clear, etc. also?
230 
234  USD_API
235  bool GetNames(std::vector<std::string>* names) const;
236 
238  USD_API
239  std::vector<std::string> GetNames() const;
240 
241  UsdVariantSet operator[](const std::string& variantSetName) const {
242  return GetVariantSet(variantSetName);
243  }
244 
248  USD_API
249  UsdVariantSet GetVariantSet(const std::string& variantSetName) const;
250 
253  USD_API
254  bool HasVariantSet(const std::string& variantSetName) const;
255 
259  USD_API
260  std::string GetVariantSelection(const std::string& variantSetName) const;
261 
262  USD_API
263  bool SetSelection(const std::string& variantSetName,
264  const std::string& variantName);
265 
269  USD_API
271 
272 
273 private:
274  explicit UsdVariantSets(const UsdPrim& prim)
275  : _prim(prim)
276  {
277  /* NOTHING */
278  }
279 
280  UsdPrim _prim;
281 
282  friend class UsdPrim;
283 };
284 
285 
286 PXR_NAMESPACE_CLOSE_SCOPE
287 
288 #endif //PXR_USD_USD_VARIANT_SETS_H
A unit of scene description that you combine with other units of scene description to form a shot...
Definition: layer.h:93
UsdListPosition
Specifies a position to add items to lists.
Definition: common.h:88
std::map< std::string, std::string > SdfVariantSelectionMap
A map of reference variant set names to variants in those sets.
Definition: types.h:264
USD_API std::vector< std::string > GetNames() const
Return a list of all VariantSets authored on the originating UsdPrim.
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 bool HasAuthoredVariant(const std::string &variantName) const
Returns true if this VariantSet already possesses a variant.
USD_API std::string GetVariantSelection() const
Return the variant selection for this VariantSet.
UsdPrim const & GetPrim() const
Return this VariantSet&#39;s held prim.
Definition: variantSets.h:159
USD_API std::vector< std::string > GetVariantNames() const
Return the composed variant names for this VariantSet, ordered lexicographically. ...
USD_API bool ClearVariantSelection()
Clear any selection for this VariantSet from the current EditTarget.
bool IsValid() const
Is this UsdVariantSet object usable? If not, calling any of its other methods is likely to crash...
Definition: variantSets.h:168
A UsdVariantSet represents a single VariantSet in USD (e.g.
Definition: variantSets.h:56
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:78
USD_API SdfVariantSelectionMap GetAllVariantSelections() const
Returns the composed map of all variant selections authored on the the originating UsdPrim...
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 AddVariant(const std::string &variantName, UsdListPosition position=UsdListPositionBackOfPrependList)
Author a variant spec for variantName in this VariantSet at the stage&#39;s current EditTarget, in the position specified by position.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
USD_API UsdVariantSet GetVariantSet(const std::string &variantSetName) const
Return a UsdVariantSet object for variantSetName.
USD_API bool HasVariantSet(const std::string &variantSetName) const
Returns true if a VariantSet named variantSetName exists on the originating prim. ...
Represents a prim description in an SdfLayer object.
Definition: primSpec.h:74
USD_API UsdEditTarget GetVariantEditTarget(const SdfLayerHandle &layer=SdfLayerHandle()) const
Return a UsdEditTarget that edits the currently selected variant in this VariantSet in layer...
USD_API bool SetVariantSelection(const std::string &variantName)
Author a variant selection for this VariantSet, setting it to variantName in the stage&#39;s current Edit...
USD_API std::pair< UsdStagePtr, UsdEditTarget > GetVariantEditContext(const SdfLayerHandle &layer=SdfLayerHandle()) const
Helper function for configuring a UsdStage&#39;s EditTarget to author into the currently selected variant...
The position at the back of the prepend list.
Definition: common.h:98
UsdVariantSets represents the collection of VariantSets that are present on a UsdPrim.
Definition: variantSets.h:211
USD_API std::string GetVariantSelection(const std::string &variantSetName) const
Return the composed variant selection for the VariantSet named variantSetName.
std::string const & GetName() const
Return this VariantSet&#39;s name.
Definition: variantSets.h:163
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.