Skip to content

Commit

Permalink
Add BlockVariantSelection to VariantSets
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisrydalch authored and pixar-oss committed Nov 4, 2020
1 parent 9742e38 commit fff8462
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pxr/usd/sdf/primSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,18 @@ SdfPrimSpec::SetVariantSelection(const std::string& variantSetName,
}
}

void
SdfPrimSpec::BlockVariantSelection(const std::string& variantSetName)
{
if (_ValidateEdit(SdfFieldKeys->VariantSelection)) {
SdfVariantSelectionProxy proxy = GetVariantSelections();
if (proxy) {
SdfChangeBlock block;
proxy[variantSetName] = std::string();
}
}
}

//
// Relocates
//
Expand Down
5 changes: 5 additions & 0 deletions pxr/usd/sdf/primSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,11 @@ class SdfPrimSpec : public SdfSpec
void SetVariantSelection(const std::string& variantSetName,
const std::string& variantName);

/// Blocks the variant selected for the given variant set by setting
/// the variant selection to empty.
SDF_API
void BlockVariantSelection(const std::string& variantSetName);

/// @}
/// \name Relocates
/// @{
Expand Down
1 change: 1 addition & 0 deletions pxr/usd/sdf/wrapPrimSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ void wrapPrimSpec()
.def("GetAttributeAtPath", &This::GetAttributeAtPath)
.def("GetRelationshipAtPath", &This::GetRelationshipAtPath)
.def("GetVariantNames", &This::GetVariantNames)
.def("BlockVariantSelection", &This::BlockVariantSelection)

.add_property("variantSelections",
&This::GetVariantSelections,
Expand Down
13 changes: 13 additions & 0 deletions pxr/usd/usd/testenv/testUsdVariants.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ def test_VariantSetAPI(self):
"localDanglingVariant"))
self.assertFalse(prim.GetVariantSets().HasVariantSet(
"referencedDanglingVariant"))
# ClearVariantSelection clears the variant set selection from the edit target,
# permitting any weaker layer selection to take effect
stage.SetEditTarget(stage.GetSessionLayer())
prim.GetVariantSet('modelingVariant').SetVariantSelection('Carton_Sealed')
self.assertEqual(prim.GetVariantSet('modelingVariant').GetVariantSelection(),
'Carton_Sealed')
prim.GetVariantSet('modelingVariant').ClearVariantSelection()
self.assertEqual(prim.GetVariantSet('modelingVariant').GetVariantSelection(),
'Carton_Opened')
# BlockVariantSelection sets the selection to empty, which blocks weaker variant
# selection opinions
prim.GetVariantSet('modelingVariant').BlockVariantSelection()
self.assertEqual(prim.GetVariantSet('modelingVariant').GetVariantSelection(), '')

def test_VariantSelectionPathAbstraction(self):
for fmt in allFormats:
Expand Down
11 changes: 11 additions & 0 deletions pxr/usd/usd/variantSets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@ UsdVariantSet::ClearVariantSelection()
return SetVariantSelection(string());
}

bool
UsdVariantSet::BlockVariantSelection()
{
if (SdfPrimSpecHandle spec = _CreatePrimSpecForEditing()) {
spec->BlockVariantSelection(_variantSetName);
return true;
}

return false;
}

UsdEditTarget
UsdVariantSet::GetVariantEditTarget(const SdfLayerHandle &layer) const
{
Expand Down
5 changes: 5 additions & 0 deletions pxr/usd/usd/variantSets.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ class UsdVariantSet {
USD_API
bool ClearVariantSelection();

/// Blocks any weaker selection for this VariantSet, setting it to empty in
/// the stage's current EditTarget. Return true on success, false otherwise.
USD_API
bool BlockVariantSelection();

/// Return a \a UsdEditTarget that edits the currently selected variant in
/// this VariantSet in \a layer. If there is no currently
/// selected variant in this VariantSet, return an invalid EditTarget.
Expand Down
1 change: 1 addition & 0 deletions pxr/usd/usd/wrapVariantSets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ void wrapUsdVariantSets()
.def("SetVariantSelection", &UsdVariantSet::SetVariantSelection,
arg("variantName"))
.def("ClearVariantSelection", &UsdVariantSet::ClearVariantSelection)
.def("BlockVariantSelection", &UsdVariantSet::BlockVariantSelection)
.def("GetVariantEditTarget", &UsdVariantSet::GetVariantEditTarget,
arg("layer")=SdfLayerHandle())
.def("GetVariantEditContext", _GetVariantEditContext,
Expand Down

0 comments on commit fff8462

Please sign in to comment.