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 
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 
110  USD_API
111  bool SetVariantSelection(const std::string &variantName);
112 
115  USD_API
116  bool ClearVariantSelection();
117 
121  USD_API
122  bool BlockVariantSelection();
123 
136  USD_API
138  GetVariantEditTarget(const SdfLayerHandle &layer = SdfLayerHandle()) const;
139 
164  USD_API
165  std::pair<UsdStagePtr, UsdEditTarget>
166  GetVariantEditContext(const SdfLayerHandle &layer = SdfLayerHandle()) const;
167 
168 
170  UsdPrim const &GetPrim() const { return _prim; }
171 
172 
174  std::string const &GetName() const { return _variantSetName; }
175 
176 
179  bool IsValid() const {
180  return static_cast<bool>(_prim);
181  }
182 
184  explicit operator bool() const {
185  return IsValid();
186  }
187 
188 private:
189  UsdVariantSet(const UsdPrim &prim,
190  const std::string &variantSetName)
191  : _prim(prim)
192  , _variantSetName(variantSetName)
193  {
194  }
195 
196  SdfPrimSpecHandle _CreatePrimSpecForEditing();
197  SdfVariantSetSpecHandle _AddVariantSet(UsdListPosition position);
198 
199  UsdPrim _prim;
200  std::string _variantSetName;
201 
202  friend class UsdPrim;
203  friend class UsdVariantSets;
204 };
205 
206 
207 // TODO:
208 // VariantSet Names are stored as SdListOps, but a VariantSet is an actual spec
209 // (like a Prim). Is it important to make that distinction here?
210 
223 public:
224 
236  USD_API
237  UsdVariantSet AddVariantSet(const std::string& variantSetName,
239 
240  // TODO: don't we want remove and reorder, clear, etc. also?
241 
245  USD_API
246  bool GetNames(std::vector<std::string>* names) const;
247 
249  USD_API
250  std::vector<std::string> GetNames() const;
251 
252  UsdVariantSet operator[](const std::string& variantSetName) const {
253  return GetVariantSet(variantSetName);
254  }
255 
259  USD_API
260  UsdVariantSet GetVariantSet(const std::string& variantSetName) const;
261 
264  USD_API
265  bool HasVariantSet(const std::string& variantSetName) const;
266 
270  USD_API
271  std::string GetVariantSelection(const std::string& variantSetName) const;
272 
273  USD_API
274  bool SetSelection(const std::string& variantSetName,
275  const std::string& variantName);
276 
280  USD_API
282 
283 
284 private:
285  explicit UsdVariantSets(const UsdPrim& prim)
286  : _prim(prim)
287  {
288  /* NOTHING */
289  }
290 
291  UsdPrim _prim;
292 
293  friend class UsdPrim;
294 };
295 
296 
297 PXR_NAMESPACE_CLOSE_SCOPE
298 
299 #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:94
UsdListPosition
Specifies a position to add items to lists.
Definition: common.h:88
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 bool BlockVariantSelection()
Block any weaker selections for this VariantSet by authoring an empty string at the stage's current E...
USD_API UsdEditTarget GetVariantEditTarget(const SdfLayerHandle &layer=SdfLayerHandle()) const
Return a UsdEditTarget that edits the currently selected variant in this VariantSet in layer.
std::map< std::string, std::string > SdfVariantSelectionMap
A map of reference variant set names to variants in those sets.
Definition: types.h:284
USD_API UsdVariantSet GetVariantSet(const std::string &variantSetName) const
Return a UsdVariantSet object for variantSetName.
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 ClearVariantSelection()
Clear any selection for this VariantSet from the current EditTarget.
UsdPrim const & GetPrim() const
Return this VariantSet's held prim.
Definition: variantSets.h:170
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.
std::string const & GetName() const
Return this VariantSet's name.
Definition: variantSets.h:174
Defines a mapping from scene graph paths to Sdf spec paths in a SdfLayer where edits should be direct...
Definition: editTarget.h:78
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:132
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,...
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
USD_API bool HasVariantSet(const std::string &variantSetName) const
Returns true if a VariantSet named variantSetName exists on the originating prim.
USD_API std::vector< std::string > GetNames() const
Return a list of all VariantSets authored on the originating UsdPrim.
USD_API SdfVariantSelectionMap GetAllVariantSelections() const
Returns the composed map of all variant selections authored on the the originating UsdPrim,...
USD_API std::string GetVariantSelection() const
Return the variant selection for this VariantSet.
Represents a prim description in an SdfLayer object.
Definition: primSpec.h:74
bool IsValid() const
Is this UsdVariantSet object usable? If not, calling any of its other methods is likely to crash.
Definition: variantSets.h:179
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::vector< std::string > GetVariantNames() const
Return the composed variant names for this VariantSet, ordered lexicographically.
USD_API std::string GetVariantSelection(const std::string &variantSetName) const
Return the composed variant selection for the VariantSet named variantSetName.
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:222
USD_API bool HasAuthoredVariant(const std::string &variantName) const
Returns true if this VariantSet already possesses a variant.
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.