Skip to content

Commit 100f1f9

Browse files
agb63pixar-oss
authored andcommitted
usdUtils: Fix shownIf param name fixup bug
Puts a temporary workaround in place to avoid fixing up param names inside `shownIf` expressions multiple times, yielding doubled-up (or more) "input" namespaces. Once SdfBooleanExpression has been wrapped to Python, we should make UpdateSchemaWithSdrNode() use it directly. (Internal change: 2385379)
1 parent 4b6aed8 commit 100f1f9

File tree

4 files changed

+55
-8
lines changed

4 files changed

+55
-8
lines changed

pxr/usd/usdUtils/testenv/testUsdUtilsUpdateSchemaWithSdrNode/baseline/resultUIHints.usda

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class "TestUIHintsAPI" (
1616
}
1717
)
1818
{
19-
reorder properties = ["inputs:allowedTokens", "inputs:allowedTokensAndValueLabels", "inputs:arrayDynamic", "inputs:arraySizeAndTuples", "inputs:arraySizeTuplesMismatch", "inputs:arrayStatic", "inputs:arrayTuples", "inputs:convertedShownIf", "inputs:displayGroup", "inputs:displayName", "inputs:floatArrayTupleConversion2", "inputs:floatArrayTupleConversion3", "inputs:floatArrayTupleConversion4", "inputs:hardAndSoftLimits", "inputs:hardClobberSoftLimits", "inputs:hardDemoteToSoftLimits", "inputs:hardLimitsBasic", "inputs:help", "inputs:hidden", "inputs:inClosedGroup", "inputs:inOpenGroup", "inputs:inOpenNestedGroup", "inputs:inShownIfGroup", "inputs:intArrayTupleConversion2", "inputs:intArrayTupleConversion3", "inputs:intArrayTupleConversion4", "inputs:shownIf", "inputs:softCantClobberHardLimits", "inputs:softLimitsBasic", "inputs:softPromoteToHardLimits", "inputs:sparseSpecificationLimits", "inputs:valueLabels"]
19+
reorder properties = ["inputs:allowedTokens", "inputs:allowedTokensAndValueLabels", "inputs:arrayDynamic", "inputs:arraySizeAndTuples", "inputs:arraySizeTuplesMismatch", "inputs:arrayStatic", "inputs:arrayTuples", "inputs:convertedShownIf", "inputs:displayGroup", "inputs:displayName", "inputs:floatArrayTupleConversion2", "inputs:floatArrayTupleConversion3", "inputs:floatArrayTupleConversion4", "inputs:hardAndSoftLimits", "inputs:hardClobberSoftLimits", "inputs:hardDemoteToSoftLimits", "inputs:hardLimitsBasic", "inputs:help", "inputs:hidden", "inputs:inClosedGroup", "inputs:inOpenGroup", "inputs:inOpenNestedGroup", "inputs:inShownIfGroup", "inputs:intArrayTupleConversion2", "inputs:intArrayTupleConversion3", "inputs:intArrayTupleConversion4", "inputs:shownIf", "inputs:shownIfParamNameSubStrings", "inputs:softCantClobberHardLimits", "inputs:softLimitsBasic", "inputs:softPromoteToHardLimits", "inputs:some_param", "inputs:some_param_also", "inputs:sparseSpecificationLimits", "inputs:valueLabels"]
2020
token inputs:allowedTokens = "foo" (
2121
allowedTokens = ["foo", "bar", "baz"]
2222
)
@@ -148,6 +148,11 @@ class "TestUIHintsAPI" (
148148
string shownIf = "inputs:hidden >= 1"
149149
}
150150
)
151+
int inputs:shownIfParamNameSubStrings = 1 (
152+
uiHints = {
153+
string shownIf = "inputs:some_param >= inputs:some_param_also"
154+
}
155+
)
151156
int inputs:softCantClobberHardLimits = 1 (
152157
limits = {
153158
dictionary hard = {
@@ -176,6 +181,8 @@ class "TestUIHintsAPI" (
176181
}
177182
}
178183
)
184+
int inputs:some_param = 1
185+
int inputs:some_param_also = 1
179186
int inputs:sparseSpecificationLimits = 1 (
180187
limits = {
181188
dictionary hard = {

pxr/usd/usdUtils/testenv/testUsdUtilsUpdateSchemaWithSdrNode/testUIHints.usda

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,16 @@ def Shader "TestUIHintsAPI" (
225225
token shownIf = "hidden >= 1"
226226
}
227227
)
228+
229+
# Regression test case (USD-11606) - if a shownIf expression references a
230+
# param name that has another param name as a substring, the "inputs"
231+
# namespace would get prepended multiple times (for example here,
232+
# "inputs:inputs:some_param_also")
233+
int inputs:some_param = 1
234+
int inputs:some_param_also = 1
235+
int inputs:shownIfParamNameSubStrings = 1 (
236+
sdrMetadata = {
237+
token shownIf = "some_param >= some_param_also"
238+
}
239+
)
228240
}

pxr/usd/usdUtils/updateSchemaWithSdrNode.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -788,16 +788,17 @@ def _recordAttrInfo(attrName, sdrProp):
788788
for attr in attrsWithShownIf:
789789
attrHints = UsdUI.AttributeHints(attr)
790790
if attrHints:
791-
expr = attrHints.GetShownIf()
792-
for sourceName, finalName in attrRenames.items():
793-
expr = expr.replace(sourceName, finalName)
794-
attrHints.SetShownIf(expr)
791+
# XXX: Should be using Sdf.BooleanExpression.RenameVariables()
792+
# directly here, but it hasn't been wrapped yet
793+
attrHints.SetShownIf(
794+
UsdUtils._BooleanExpressionRenameVariables(
795+
attrHints.GetShownIf(), attrRenames))
795796

796797
pagesShownIf = sdrNode.GetPagesShownIf()
797798
for page, expr in pagesShownIf.items():
798-
for sourceName, finalName in attrRenames.items():
799-
expr = expr.replace(sourceName, finalName)
800-
pagesShownIf[page] = expr
799+
# XXX: Ditto above
800+
pagesShownIf[page] = \
801+
UsdUtils._BooleanExpressionRenameVariables(expr, attrRenames)
801802

802803
if pagesShownIf:
803804
primHints.SetDisplayGroupsShownIf(pagesShownIf)

pxr/usd/usdUtils/wrapPipeline.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,39 @@
1010

1111
#include "pxr/usd/usdUtils/pipeline.h"
1212

13+
#include "pxr/usd/sdf/booleanExpression.h"
1314
#include "pxr/usd/usd/prim.h"
1415

1516
#include "pxr/base/tf/pyResultConversions.h"
17+
#include "pxr/base/vt/dictionary.h"
18+
#include "pxr/base/vt/value.h"
1619
#include "pxr/external/boost/python/return_by_value.hpp"
1720

1821
PXR_NAMESPACE_USING_DIRECTIVE
1922

2023
using namespace pxr_boost::python;
2124

25+
// XXX: Temporary workaround for use by UpdateSchemaWithSdrNode(). Once
26+
// SdfBooleanExpression is wrapped to Python we can do away with this.
27+
static std::string
28+
_BooleanExpressionRenameVariables(
29+
const std::string& expr,
30+
const VtDictionary& renames)
31+
{
32+
auto transform = [&](const TfToken& name) {
33+
const auto it = renames.find(name);
34+
if (it == renames.end() || !it->second.IsHolding<std::string>()) {
35+
return name;
36+
}
37+
else {
38+
return TfToken(it->second.UncheckedGet<std::string>());
39+
}
40+
};
41+
42+
const SdfBooleanExpression expression(expr);
43+
return expression.RenameVariables(transform).GetText();
44+
}
45+
2246
void wrapPipeline()
2347
{
2448
def("GetAlphaAttributeNameForColor", UsdUtilsGetAlphaAttributeNameForColor, arg("colorAttrName"));
@@ -42,4 +66,7 @@ void wrapPipeline()
4266
"GetPrimaryCameraName",
4367
UsdUtilsGetPrimaryCameraName,
4468
arg("forceDefault")=false);
69+
70+
def("_BooleanExpressionRenameVariables",
71+
&_BooleanExpressionRenameVariables);
4572
}

0 commit comments

Comments
 (0)