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 displayName Metadata to Prim Spec #2055

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions pxr/usd/sdf/schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,8 @@ SdfSchemaBase::_RegisterStandardFields()
SdfMetadataDisplayGroupTokens->core)
.MetadataField(SdfFieldKeys->DisplayGroupOrder,
SdfMetadataDisplayGroupTokens->core)
.MetadataField(SdfFieldKeys->DisplayName,
erslavin marked this conversation as resolved.
Show resolved Hide resolved
SdfMetadataDisplayGroupTokens->core)
.MetadataField(SdfFieldKeys->Documentation,
SdfMetadataDisplayGroupTokens->core)
.MetadataField(SdfFieldKeys->Hidden,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

class MfScope "Rig"
{
def MfScope "Leg"
def MfScope "Leg" (
displayName = "Foo"
)
{
custom double kneeFB (
displayName = "LkneeFB"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

class MfScope "Rig"
{
def MfScope "Leg"
def MfScope "Leg" (
displayName = "Foo"
)
{
custom rel foo = </Rig/Leg.kneeFB> (
displayName = "Lfoo"
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 @@ -523,6 +523,7 @@ void wrapPrimSpec()
.setattr("AnyTypeToken", SdfTokens->AnyTypeToken)
.setattr("CommentKey", SdfFieldKeys->Comment)
.setattr("CustomDataKey", SdfFieldKeys->CustomData)
.setattr("DisplayName", SdfFieldKeys->DisplayName)
.setattr("DocumentationKey", SdfFieldKeys->Documentation)
.setattr("HiddenKey", SdfFieldKeys->Hidden)
.setattr("InheritPathsKey", SdfFieldKeys->InheritPaths)
Expand Down
1 change: 1 addition & 0 deletions pxr/usd/usd/testenv/testUsdMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ int main() {
_VerifyMetadata(prim, true, SdfFieldKeys->Active);
_VerifyMetadata(prim, true, SdfFieldKeys->Hidden);
_VerifyMetadata(prim, TfToken("DummyType"), SdfFieldKeys->TypeName);
_VerifyMetadata(prim, string("Display Name"), SdfFieldKeys->DisplayName);

// attribute metadata
_VerifyMetadata(attr, string("hello"), SdfFieldKeys->Comment);
Expand Down
7 changes: 7 additions & 0 deletions pxr/usd/usd/testenv/testUsdMetadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,13 @@ def test_DisplayName(self):
attr = foo.CreateAttribute("attr", Sdf.ValueTypeNames.String)
rel = foo.CreateRelationship("rel")

# verify display name metadata on prim
self.assertEqual(foo.GetMetadata("displayName"), None)
self.assertEqual(foo.HasAuthoredMetadata("displayName"), False)
self.assertEqual(foo.SetMetadata("displayName", "foo"), True)
self.assertEqual(foo.GetMetadata("displayName"), "foo")
self.assertEqual(foo.HasAuthoredMetadata("displayName"), True)

spiffmon marked this conversation as resolved.
Show resolved Hide resolved
for prop in [attr, rel]:
self.assertEqual(prop.GetDisplayName(), "")
self.assertFalse(prop.HasAuthoredDisplayName())
Expand Down
4 changes: 3 additions & 1 deletion pxr/usd/usd/testenv/testUsdSchemaRegistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ def test_PrimMetadata(self):
self.assertTrue(primDef)

self.assertEqual(set(primDef.ListMetadataFields()),
set(["typeName", "testCustomMetadata", "hidden", "documentation"]))
set(["typeName", "testCustomMetadata", "hidden", "documentation", "displayName"]))
self.assertEqual(primDef.GetMetadata("typeName"), "MetadataTest")
self.assertEqual(primDef.GetMetadata("displayName"), "Display Name")
self.assertEqual(primDef.GetMetadata("documentation"),
"Testing documentation metadata")
self.assertEqual(primDef.GetMetadata("hidden"), True)
Expand Down Expand Up @@ -419,6 +420,7 @@ def _VerifyExpectedPrimData(layer, path, expectedPrimFields,
# Expected fields and properties from the concrete schema.
concretePrimDefPrimFields = {
"apiSchemas" : Sdf.TokenListOp.CreateExplicit([]),
"displayName": "Display Name",
"documentation" : concretePrimDef.GetDocumentation(),
"hidden" : True,
"testCustomMetadata" : "garply",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class "AbstractTest" (
}

class MetadataTest "MetadataTest" (
displayName = "Display Name"
doc = "Testing documentation metadata"
hidden = true
testCustomMetadata = "garply"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class "AbstractTest" (

class MetadataTest "MetadataTest" (
inherits = </AbstractTest>
displayName = "Display Name"
spiffmon marked this conversation as resolved.
Show resolved Hide resolved
doc = "Testing documentation metadata"
hidden = true
testCustomMetadata = "garply"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ def "foo" {

}

def "g" {
def "g" (
displayName = "testDisplayName"
)
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,37 @@ def _search(appController, searchTerm, expectedItems):

def _testSearchBasic(appController):
_search(appController, 'f', ['f', 'foo'])

# with the prim display name option on, the text
# will be the display name, not the prim name
_search(appController, 'g', ['testDisplayName'])

# On an invalid search, the old term will remain
_search(appController, 'xxx', ['testDisplayName'])

# Do a regex based search
_search(appController, 'f.*', ['f', 'foo'])

# search based on display name
_search(appController, "test", ['testDisplayName'])

def _testSearchNoPrimDisplayName(appController):
"""
Performs a test of the search capability of usdview
without the default "Show Prim Display Names" on.
Without this option on, search will only look at
prim identifers and will not consider the display
name metadata.
"""
# this searches specifically for a known display name
# which should fail - the rest of the searches
# should only look at prim names until the option is turned back on
appController._dataModel.viewSettings.showPrimDisplayNames = False
_search(appController, 'test', [])

# the block of _search calls only look at prim names
# not display names
_search(appController, 'f', ['f', 'foo'])
_search(appController, 'g', ['g'])

# On an invalid search, the old term will remain
Expand All @@ -57,5 +88,11 @@ def _testSearchBasic(appController):
# Do a regex based search
_search(appController, 'f.*', ['f', 'foo'])

appController._dataModel.viewSettings.showPrimDisplayNames = True
_search(appController, 'g', ['testDisplayName'])

def testUsdviewInputFunction(appController):
_testSearchBasic(appController)

# test with prim display name off
_testSearchNoPrimDisplayName(appController)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ def Xform "Shapes" (
{
variantSet "a_shapeVariant" = {
"capsule" {
def Capsule "Pill"
def Capsule "Pill" (
displayName = "CapsuleDisplayName"
)
{
double3 xformOp:translate = (0, 0, 0)
uniform token[] xformOpOrder = ["xformOp:translate"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
FIRST_VARIANT = 'a_shapeVariant'
SECOND_VARIANT = 'b_shapeVariant'

from pxr.Usdviewq.qt import QtWidgets
from pxr.Usdviewq.qt import QtWidgets, QtCore

def _setupWidgets(appController):
# Select our prim with the variant authored
Expand Down Expand Up @@ -128,6 +128,19 @@ def _testAllExpanded(appController):
_selectVariant(appController, CAPSULE[VARIANT_INFO_POS], FIRST_VARIANT)
_expandPrims(appController, ["/spheres", "/A", "/A/B", "/A/B/C"])
initialExpandedPrims = _getExpandedPrims(appController)

# test to see if the display name of the capsule is showing
prim = appController._dataModel.stage.GetPrimAtPath("/Shapes/Pill")
item = appController._primToItemMap.get(prim)
assert item._nameData(QtCore.Qt.DisplayRole) == "CapsuleDisplayName"

# clear the a-variant and just select the b-variant
_selectVariant(appController, 0, FIRST_VARIANT)
spiffmon marked this conversation as resolved.
Show resolved Hide resolved
_selectVariant(appController, CAPSULE[VARIANT_INFO_POS], SECOND_VARIANT)
prim = appController._dataModel.stage.GetPrimAtPath("/Shapes/Pill")
item = appController._primToItemMap.get(prim)
assert item._nameData(QtCore.Qt.DisplayRole) == "Pill"

_selectVariant(appController, CAPSULE[VARIANT_INFO_POS], FIRST_VARIANT)
_selectVariant(appController, CONE[VARIANT_INFO_POS], FIRST_VARIANT)
expandedPrims = _getExpandedPrims(appController)
Expand Down
38 changes: 30 additions & 8 deletions pxr/usdImaging/usdviewq/appController.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,9 @@ def __init__(self, parserData, resolverContextFn):
self._ui.actionShow_Abstract_Prims.triggered.connect(
self._toggleShowAbstractPrims)

self._ui.actionShow_Prim_DisplayName.triggered.connect(
self._toggleShowPrimDisplayName)

# Since setting column visibility is probably not a common
# operation, it's actually good to have Columns at the end.
self._ui.menuShow.addSeparator()
Expand Down Expand Up @@ -2185,16 +2188,28 @@ def _findPrims(self, pattern, useRegex=True):
pattern = pattern.lower()
isMatch = lambda x: pattern in x.lower()

matches = [prim.GetPath() for prim
in Usd.PrimRange.Stage(self._dataModel.stage,
self._displayPredicate)
if isMatch(prim.GetName())]
if self._dataModel.viewSettings.showPrimDisplayNames:
matches = [prim.GetPath() for prim
in Usd.PrimRange.Stage(self._dataModel.stage,
self._displayPredicate)
if ((prim.HasAuthoredMetadata("displayName") and isMatch(prim.GetMetadata("displayName"))) or isMatch(prim.GetName()))]
spiffmon marked this conversation as resolved.
Show resolved Hide resolved
else:
matches = [prim.GetPath() for prim
in Usd.PrimRange.Stage(self._dataModel.stage,
self._displayPredicate)
if isMatch(prim.GetName())]

if self._dataModel.viewSettings.showAllPrototypePrims:
for prototype in self._dataModel.stage.GetPrototypes():
matches += [prim.GetPath() for prim
in Usd.PrimRange(prototype, self._displayPredicate)
if isMatch(prim.GetName())]
if self._dataModel.viewSettings.showPrimDisplayNames:
for prototype in self._dataModel.stage.GetPrototypes():
matches += [prim.GetPath() for prim
in Usd.PrimRange(prototype, self._displayPredicate)
if ((prim.HasAuthoredMetadata("displayName") and isMatch(prim.GetMetadata("displayName"))) or isMatch(prim.GetName()))]
spiffmon marked this conversation as resolved.
Show resolved Hide resolved
else:
for prototype in self._dataModel.stage.GetPrototypes():
matches += [prim.GetPath() for prim
in Usd.PrimRange(prototype, self._displayPredicate)
if isMatch(prim.GetName())]

return matches

Expand Down Expand Up @@ -3189,6 +3204,11 @@ def _toggleShowAbstractPrims(self):
self._dataModel.selection.removeAbstractPrims()
self._resetPrimView()

def _toggleShowPrimDisplayName(self):
self._dataModel.viewSettings.showPrimDisplayNames = (
self._ui.actionShow_Prim_DisplayName.isChecked())
self._resetPrimView()
spiffmon marked this conversation as resolved.
Show resolved Hide resolved

def _toggleRolloverPrimInfo(self):
self._dataModel.viewSettings.rolloverPrimInfo = (
self._ui.actionRollover_Prim_Info.isChecked())
Expand Down Expand Up @@ -5233,6 +5253,8 @@ def _refreshShowPrimMenu(self):
self._dataModel.viewSettings.showUndefinedPrims)
self._ui.actionShow_Abstract_Prims.setChecked(
self._dataModel.viewSettings.showAbstractPrims)
self._ui.actionShow_Prim_DisplayName.setChecked(
self._dataModel.viewSettings.showPrimDisplayNames)

def _refreshRedrawOnScrub(self):
self._ui.redrawOnScrub.setChecked(
Expand Down
9 changes: 9 additions & 0 deletions pxr/usdImaging/usdviewq/mainWindowUI.ui
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
<addaction name="actionShow_All_Prototype_Prims"/>
<addaction name="actionShow_Undefined_Prims"/>
<addaction name="actionShow_Abstract_Prims"/>
<addaction name="actionShow_Prim_DisplayName" />
</widget>
<addaction name="menuNavigation"/>
<addaction name="menuShow"/>
Expand Down Expand Up @@ -2660,6 +2661,14 @@
<string>Abstract Prims (Classes)</string>
</property>
</action>
<action name="actionShow_Prim_DisplayName">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Use Display Name (Prims)</string>
</property>
</action>
spiffmon marked this conversation as resolved.
Show resolved Hide resolved
<action name="actionPick_Prims">
<property name="checkable">
<bool>true</bool>
Expand Down
12 changes: 10 additions & 2 deletions pxr/usdImaging/usdviewq/primViewItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ def _extractInfo(self, info):
isVisibilityInherited,
self.visVaries,
self.name,
self.typeName ) = info
self.typeName,
self.displayName ) = info

parent = self.parent()
parentIsPrimViewItem = isinstance(parent, PrimViewItem)
Expand Down Expand Up @@ -227,7 +228,10 @@ def _GetForegroundColor(self):

def _nameData(self, role):
if role == QtCore.Qt.DisplayRole:
return self.name
if self._appController._dataModel.viewSettings.showPrimDisplayNames:
return self.displayName if self.displayName != "" else self.name
else:
return self.name
elif role == QtCore.Qt.FontRole:
# Abstract prims are also considered defined; since we want
# to distinguish abstract defined prims from non-abstract
Expand Down Expand Up @@ -256,6 +260,10 @@ def _nameData(self, role):
toolTip = 'Inactive ' + toolTip
elif self.isInstance:
toolTip = 'Instanced ' + toolTip

# tooltip should always show both name and display name
toolTip = toolTip + "<br>Name: " + self.name + "<br>Display Name: " + self.displayName
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @erslavin - I was not very clear in my request. If a prim has a displayName, then we should show both name and displayName regardless of the "Show Display Names" setting. But if a prim has no displayName, then I don't think we need to add anything here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified to conform to this behavior


if self.hasArcs:
toolTip = toolTip + "<br>Has composition arcs"
return toolTip
Expand Down
13 changes: 13 additions & 0 deletions pxr/usdImaging/usdviewq/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ UsdviewqUtils::PrimInfo::PrimInfo(const UsdPrim &prim, const UsdTimeCode time)
else
name = _tokens->root.GetString();
typeName = prim.GetTypeName().GetString();

// nv begin #prim-display-name
spiffmon marked this conversation as resolved.
Show resolved Hide resolved

if (prim.HasAuthoredMetadata(SdfFieldKeys->DisplayName))
{
prim.GetMetadata<std::string>(SdfFieldKeys->DisplayName, &displayName);
spiffmon marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
displayName = "";
}

// nv end
}

/*static*/
Expand Down
4 changes: 4 additions & 0 deletions pxr/usdImaging/usdviewq/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ class UsdviewqUtils {
bool visVaries;
std::string name;
std::string typeName;

// nv begin #prim-display-name
std::string displayName;
// nv end
spiffmon marked this conversation as resolved.
Show resolved Hide resolved
};

/// For the given \p stage and \p schemaType, return all active, defined
Expand Down
11 changes: 11 additions & 0 deletions pxr/usdImaging/usdviewq/viewSettingsDataModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def __init__(self, rootDataModel, parent):

self._showUndefinedPrims = self.stateProperty("showUndefinedPrims", default=False)
self._showAbstractPrims = self.stateProperty("showAbstractPrims", default=False)
self._showPrimDisplayNames = self.stateProperty("showPrimDisplayNames", default=True)
self._rolloverPrimInfo = self.stateProperty("rolloverPrimInfo", default=False)
self._displayCameraOracles = self.stateProperty("cameraOracles", default=False)
self._cameraMaskMode = self.stateProperty("cameraMaskMode", default=CameraMaskModes.NONE)
Expand Down Expand Up @@ -259,6 +260,7 @@ def onSaveState(self, state):
state["showAllMasterPrims"] = self._showAllPrototypePrims
state["showUndefinedPrims"] = self._showUndefinedPrims
state["showAbstractPrims"] = self._showAbstractPrims
state["showPrimDisplayNames"] = self._showPrimDisplayNames
state["rolloverPrimInfo"] = self._rolloverPrimInfo
state["cameraOracles"] = self._displayCameraOracles
state["cameraMaskMode"] = self._cameraMaskMode
Expand Down Expand Up @@ -635,6 +637,15 @@ def showAbstractPrims(self):
def showAbstractPrims(self, value):
self._showAbstractPrims = value

@property
def showPrimDisplayNames(self):
return self._showPrimDisplayNames

@showPrimDisplayNames.setter
@invisibleViewSetting
def showPrimDisplayNames(self, value):
self._showPrimDisplayNames = value

@property
def rolloverPrimInfo(self):
return self._rolloverPrimInfo
Expand Down
Loading