Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BlockVariantSelection to VariantSets #1340

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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