From 605320847bf543dce1cd46f7c87d986d22abd783 Mon Sep 17 00:00:00 2001 From: Edward Slavin Date: Tue, 4 Oct 2022 17:12:36 -0400 Subject: [PATCH 1/9] Add displayName Metadata to Prim Spec - Added displayName metadata field to prims - Adjusted tests to test for and modify authored displayName metadata - Did not add Get/Set DisplayName methods to prims - all access should be via Get/Set Metadata to keep ABI compatibility --- pxr/usd/sdf/schema.cpp | 2 ++ .../testSdfParsing.testenv/187_displayName_metadata.sdf | 4 +++- .../baseline/187_displayName_metadata.sdf | 4 +++- pxr/usd/usd/testenv/testUsdMetadata.cpp | 1 + pxr/usd/usd/testenv/testUsdMetadata.py | 7 +++++++ pxr/usd/usd/testenv/testUsdSchemaRegistry.py | 4 +++- .../testUsdSchemaRegistry/resources/generatedSchema.usda | 1 + .../testenv/testUsdSchemaRegistry/resources/schema.usda | 1 + 8 files changed, 21 insertions(+), 3 deletions(-) diff --git a/pxr/usd/sdf/schema.cpp b/pxr/usd/sdf/schema.cpp index 8339962bd6..e0f37d3e1d 100644 --- a/pxr/usd/sdf/schema.cpp +++ b/pxr/usd/sdf/schema.cpp @@ -872,6 +872,8 @@ SdfSchemaBase::_RegisterStandardFields() SdfMetadataDisplayGroupTokens->core) .MetadataField(SdfFieldKeys->DisplayGroupOrder, SdfMetadataDisplayGroupTokens->core) + .MetadataField(SdfFieldKeys->DisplayName, + SdfMetadataDisplayGroupTokens->core) .MetadataField(SdfFieldKeys->Documentation, SdfMetadataDisplayGroupTokens->core) .MetadataField(SdfFieldKeys->Hidden, diff --git a/pxr/usd/sdf/testenv/testSdfParsing.testenv/187_displayName_metadata.sdf b/pxr/usd/sdf/testenv/testSdfParsing.testenv/187_displayName_metadata.sdf index 41becf9907..26ca5f621a 100644 --- a/pxr/usd/sdf/testenv/testSdfParsing.testenv/187_displayName_metadata.sdf +++ b/pxr/usd/sdf/testenv/testSdfParsing.testenv/187_displayName_metadata.sdf @@ -7,7 +7,9 @@ class MfScope "Rig" { - def MfScope "Leg" + def MfScope "Leg" ( + displayName = "Foo" + ) { custom double kneeFB ( displayName = "LkneeFB" diff --git a/pxr/usd/sdf/testenv/testSdfParsing.testenv/baseline/187_displayName_metadata.sdf b/pxr/usd/sdf/testenv/testSdfParsing.testenv/baseline/187_displayName_metadata.sdf index a67f44a7e2..2c37e53fee 100644 --- a/pxr/usd/sdf/testenv/testSdfParsing.testenv/baseline/187_displayName_metadata.sdf +++ b/pxr/usd/sdf/testenv/testSdfParsing.testenv/baseline/187_displayName_metadata.sdf @@ -7,7 +7,9 @@ class MfScope "Rig" { - def MfScope "Leg" + def MfScope "Leg" ( + displayName = "Foo" + ) { custom rel foo = ( displayName = "Lfoo" diff --git a/pxr/usd/usd/testenv/testUsdMetadata.cpp b/pxr/usd/usd/testenv/testUsdMetadata.cpp index d34bb90398..7099398280 100644 --- a/pxr/usd/usd/testenv/testUsdMetadata.cpp +++ b/pxr/usd/usd/testenv/testUsdMetadata.cpp @@ -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); diff --git a/pxr/usd/usd/testenv/testUsdMetadata.py b/pxr/usd/usd/testenv/testUsdMetadata.py index af0a116464..8f6602c907 100644 --- a/pxr/usd/usd/testenv/testUsdMetadata.py +++ b/pxr/usd/usd/testenv/testUsdMetadata.py @@ -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) + for prop in [attr, rel]: self.assertEqual(prop.GetDisplayName(), "") self.assertFalse(prop.HasAuthoredDisplayName()) diff --git a/pxr/usd/usd/testenv/testUsdSchemaRegistry.py b/pxr/usd/usd/testenv/testUsdSchemaRegistry.py index d374fe7ea1..7dd5747472 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaRegistry.py +++ b/pxr/usd/usd/testenv/testUsdSchemaRegistry.py @@ -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) @@ -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", diff --git a/pxr/usd/usd/testenv/testUsdSchemaRegistry/resources/generatedSchema.usda b/pxr/usd/usd/testenv/testUsdSchemaRegistry/resources/generatedSchema.usda index 50cf490576..a71e17d6b8 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaRegistry/resources/generatedSchema.usda +++ b/pxr/usd/usd/testenv/testUsdSchemaRegistry/resources/generatedSchema.usda @@ -19,6 +19,7 @@ class "AbstractTest" ( } class MetadataTest "MetadataTest" ( + displayName = "Display Name" doc = "Testing documentation metadata" hidden = true testCustomMetadata = "garply" diff --git a/pxr/usd/usd/testenv/testUsdSchemaRegistry/resources/schema.usda b/pxr/usd/usd/testenv/testUsdSchemaRegistry/resources/schema.usda index 4df1f42bc3..00aba542c6 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaRegistry/resources/schema.usda +++ b/pxr/usd/usd/testenv/testUsdSchemaRegistry/resources/schema.usda @@ -35,6 +35,7 @@ class "AbstractTest" ( class MetadataTest "MetadataTest" ( inherits = + displayName = "Display Name" doc = "Testing documentation metadata" hidden = true testCustomMetadata = "garply" From 60de1b9027481e0ad014316e808cf79065a7a0e9 Mon Sep 17 00:00:00 2001 From: Edward Slavin Date: Mon, 17 Oct 2022 13:30:32 -0400 Subject: [PATCH 2/9] OM-65968: displayName support for prims in usdview - Added context menu item to show prim display names (default = True) - Added support for showing prim display name in the prim tree - Added support for searching on prim display name in search box - Modified prim tree item tooltip to show both name and display name --- pxr/usdImaging/usdviewq/appController.py | 52 ++++++++++++++++--- pxr/usdImaging/usdviewq/mainWindowUI.ui | 9 ++++ pxr/usdImaging/usdviewq/primViewItem.py | 19 ++++++- pxr/usdImaging/usdviewq/utils.cpp | 13 +++++ pxr/usdImaging/usdviewq/utils.h | 4 ++ .../usdviewq/viewSettingsDataModel.py | 18 +++++++ pxr/usdImaging/usdviewq/wrapUtils.cpp | 6 ++- 7 files changed, 110 insertions(+), 11 deletions(-) diff --git a/pxr/usdImaging/usdviewq/appController.py b/pxr/usdImaging/usdviewq/appController.py index b3bd43cb5a..642efa1f96 100644 --- a/pxr/usdImaging/usdviewq/appController.py +++ b/pxr/usdImaging/usdviewq/appController.py @@ -982,6 +982,13 @@ def __init__(self, parserData, resolverContextFn): self._ui.actionShow_Abstract_Prims.triggered.connect( self._toggleShowAbstractPrims) + # nv begin #prim-display-name + + self._ui.actionShow_Prim_DisplayName.triggered.connect( + self._toggleShowPrimDisplayName) + + # nv end + # Since setting column visibility is probably not a common # operation, it's actually good to have Columns at the end. self._ui.menuShow.addSeparator() @@ -2185,16 +2192,31 @@ 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())] + # nv begin #prim-display-name + if self._dataModel.viewSettings.showPrimDisplayNames: + matches = [prim.GetPath() for prim + in Usd.PrimRange.Stage(self._dataModel.stage, + self._displayPredicate) + if (isMatch(prim.GetMetadata("displayName")) or isMatch(prim.GetName()))] + 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 (isMatch(prim.GetMetadata("displayName")) or isMatch(prim.GetName()))] + else: + for prototype in self._dataModel.stage.GetPrototypes(): + matches += [prim.GetPath() for prim + in Usd.PrimRange(prototype, self._displayPredicate) + if isMatch(prim.GetName())] + + #nv end return matches @@ -3189,6 +3211,15 @@ def _toggleShowAbstractPrims(self): self._dataModel.selection.removeAbstractPrims() self._resetPrimView() + # nv begin #prim-display-name + + def _toggleShowPrimDisplayName(self): + self._dataModel.viewSettings.showPrimDisplayNames = ( + self._ui.actionShow_Prim_DisplayName.isChecked()) + self._resetPrimView() + + # nv end + def _toggleRolloverPrimInfo(self): self._dataModel.viewSettings.rolloverPrimInfo = ( self._ui.actionRollover_Prim_Info.isChecked()) @@ -5234,6 +5265,11 @@ def _refreshShowPrimMenu(self): self._ui.actionShow_Abstract_Prims.setChecked( self._dataModel.viewSettings.showAbstractPrims) + # nv begin #prim-display-name + self._ui.actionShow_Prim_DisplayName.setChecked( + self._dataModel.viewSettings.showPrimDisplayNames) + # nv end + def _refreshRedrawOnScrub(self): self._ui.redrawOnScrub.setChecked( self._dataModel.viewSettings.redrawOnScrub) diff --git a/pxr/usdImaging/usdviewq/mainWindowUI.ui b/pxr/usdImaging/usdviewq/mainWindowUI.ui index 467f2dce25..6ca98d5397 100644 --- a/pxr/usdImaging/usdviewq/mainWindowUI.ui +++ b/pxr/usdImaging/usdviewq/mainWindowUI.ui @@ -159,6 +159,7 @@ + @@ -2660,6 +2661,14 @@ Abstract Prims (Classes) + + + true + + + Use Display Name (Prims) + + true diff --git a/pxr/usdImaging/usdviewq/primViewItem.py b/pxr/usdImaging/usdviewq/primViewItem.py index f8569a1b46..f8da64a7b1 100644 --- a/pxr/usdImaging/usdviewq/primViewItem.py +++ b/pxr/usdImaging/usdviewq/primViewItem.py @@ -129,6 +129,7 @@ def _isComputedDrawModeInherited(self, parentDrawModeIsInherited=None): return False def _extractInfo(self, info): + # nv begin #prim-display-name ( self.hasArcs, self.active, self.imageable, @@ -141,7 +142,10 @@ def _extractInfo(self, info): isVisibilityInherited, self.visVaries, self.name, - self.typeName ) = info + self.typeName, + self.displayName ) = info + + # nv end parent = self.parent() parentIsPrimViewItem = isinstance(parent, PrimViewItem) @@ -227,7 +231,12 @@ def _GetForegroundColor(self): def _nameData(self, role): if role == QtCore.Qt.DisplayRole: - return self.name + # nv begin #prim-display-name + if self._appController._dataModel.viewSettings.showPrimDisplayNames: + return self.displayName if self.displayName != "" else self.name + else: + return self.name + # nv end elif role == QtCore.Qt.FontRole: # Abstract prims are also considered defined; since we want # to distinguish abstract defined prims from non-abstract @@ -256,6 +265,12 @@ def _nameData(self, role): toolTip = 'Inactive ' + toolTip elif self.isInstance: toolTip = 'Instanced ' + toolTip + + # nv begin #prim-display-name + # tooltip should always show both name and display name + toolTip = toolTip + "
Name: " + self.name + "
Display Name: " + self.displayName + # nv end + if self.hasArcs: toolTip = toolTip + "
Has composition arcs" return toolTip diff --git a/pxr/usdImaging/usdviewq/utils.cpp b/pxr/usdImaging/usdviewq/utils.cpp index 3f563f810f..a003592242 100644 --- a/pxr/usdImaging/usdviewq/utils.cpp +++ b/pxr/usdImaging/usdviewq/utils.cpp @@ -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 + + if (prim.HasAuthoredMetadata(SdfFieldKeys->DisplayName)) + { + prim.GetMetadata(SdfFieldKeys->DisplayName, &displayName); + } + else + { + displayName = ""; + } + + // nv end } /*static*/ diff --git a/pxr/usdImaging/usdviewq/utils.h b/pxr/usdImaging/usdviewq/utils.h index 49887fdd16..ffbddde3bd 100644 --- a/pxr/usdImaging/usdviewq/utils.h +++ b/pxr/usdImaging/usdviewq/utils.h @@ -59,6 +59,10 @@ class UsdviewqUtils { bool visVaries; std::string name; std::string typeName; + + // nv begin #prim-display-name + std::string displayName; + // nv end }; /// For the given \p stage and \p schemaType, return all active, defined diff --git a/pxr/usdImaging/usdviewq/viewSettingsDataModel.py b/pxr/usdImaging/usdviewq/viewSettingsDataModel.py index 983cdb37c4..4ebf3c8fc8 100644 --- a/pxr/usdImaging/usdviewq/viewSettingsDataModel.py +++ b/pxr/usdImaging/usdviewq/viewSettingsDataModel.py @@ -195,6 +195,9 @@ def __init__(self, rootDataModel, parent): self._showUndefinedPrims = self.stateProperty("showUndefinedPrims", default=False) self._showAbstractPrims = self.stateProperty("showAbstractPrims", default=False) + # nv begin #prim-display-name + self._showPrimDisplayNames = self.stateProperty("showPrimDisplayNames", default=True) + # nv end self._rolloverPrimInfo = self.stateProperty("rolloverPrimInfo", default=False) self._displayCameraOracles = self.stateProperty("cameraOracles", default=False) self._cameraMaskMode = self.stateProperty("cameraMaskMode", default=CameraMaskModes.NONE) @@ -259,6 +262,9 @@ def onSaveState(self, state): state["showAllMasterPrims"] = self._showAllPrototypePrims state["showUndefinedPrims"] = self._showUndefinedPrims state["showAbstractPrims"] = self._showAbstractPrims + # nv begin #prim-display-name + state["showPrimDisplayNames"] = self._showPrimDisplayNames + # nv end state["rolloverPrimInfo"] = self._rolloverPrimInfo state["cameraOracles"] = self._displayCameraOracles state["cameraMaskMode"] = self._cameraMaskMode @@ -635,6 +641,18 @@ def showAbstractPrims(self): def showAbstractPrims(self, value): self._showAbstractPrims = value + # nv begin #prim-display-name + @property + def showPrimDisplayNames(self): + return self._showPrimDisplayNames + + @showPrimDisplayNames.setter + @invisibleViewSetting + def showPrimDisplayNames(self, value): + self._showPrimDisplayNames = value + + # nv end + @property def rolloverPrimInfo(self): return self._rolloverPrimInfo diff --git a/pxr/usdImaging/usdviewq/wrapUtils.cpp b/pxr/usdImaging/usdviewq/wrapUtils.cpp index 90ca2ab689..fd0ad1bbfb 100644 --- a/pxr/usdImaging/usdviewq/wrapUtils.cpp +++ b/pxr/usdImaging/usdviewq/wrapUtils.cpp @@ -48,6 +48,7 @@ _GetPrimInfo(UsdPrim const &prim, UsdTimeCode time) { UsdviewqUtils::PrimInfo info = UsdviewqUtils::GetPrimInfo(prim, time); + // nv begin #prim-display-name return boost::python::make_tuple(info.hasCompositionArcs, info.isActive, info.isImageable, @@ -60,7 +61,10 @@ _GetPrimInfo(UsdPrim const &prim, UsdTimeCode time) info.isVisibilityInherited, info.visVaries, info.name, - info.typeName); + info.typeName, + info.displayName); + + // nv end } } // anonymous namespace From b03192fed21df0d08b71c9a60d8ef8bd3ec27d01 Mon Sep 17 00:00:00 2001 From: Edward Slavin Date: Wed, 19 Oct 2022 16:02:38 -0400 Subject: [PATCH 3/9] Add displayName Metadata to PrimSpec - Augmented automated tests in usdview to account for displayName - Added displayName to field keys in wrapPrimSpec - Removed unnecessary comment blocks --- pxr/usd/sdf/wrapPrimSpec.cpp | 1 + .../testenv/testUsdviewPrimSearch/test.usda | 5 ++- .../testUsdviewPrimSearch.py | 37 +++++++++++++++++++ .../testUsdviewPrimTreeExpansion/test.usda | 4 +- .../testUsdviewPrimTreeExpansion.py | 15 +++++++- pxr/usdImaging/usdviewq/appController.py | 18 +-------- pxr/usdImaging/usdviewq/primViewItem.py | 7 ---- .../usdviewq/viewSettingsDataModel.py | 7 ---- 8 files changed, 61 insertions(+), 33 deletions(-) diff --git a/pxr/usd/sdf/wrapPrimSpec.cpp b/pxr/usd/sdf/wrapPrimSpec.cpp index fd77d6a529..145b51ea33 100644 --- a/pxr/usd/sdf/wrapPrimSpec.cpp +++ b/pxr/usd/sdf/wrapPrimSpec.cpp @@ -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) diff --git a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimSearch/test.usda b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimSearch/test.usda index 831991d5a3..8e285e9636 100644 --- a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimSearch/test.usda +++ b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimSearch/test.usda @@ -8,6 +8,9 @@ def "foo" { } -def "g" { +def "g" ( + displayName = "testDisplayName" +) +{ } diff --git a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimSearch/testUsdviewPrimSearch.py b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimSearch/testUsdviewPrimSearch.py index 78b82ca90b..da5509ad73 100644 --- a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimSearch/testUsdviewPrimSearch.py +++ b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimSearch/testUsdviewPrimSearch.py @@ -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 @@ -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) \ No newline at end of file diff --git a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimTreeExpansion/test.usda b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimTreeExpansion/test.usda index a7e2a183b0..7ed2075f30 100644 --- a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimTreeExpansion/test.usda +++ b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimTreeExpansion/test.usda @@ -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"] diff --git a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimTreeExpansion/testUsdviewPrimTreeExpansion.py b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimTreeExpansion/testUsdviewPrimTreeExpansion.py index 50e455e12e..7b35747d28 100644 --- a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimTreeExpansion/testUsdviewPrimTreeExpansion.py +++ b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimTreeExpansion/testUsdviewPrimTreeExpansion.py @@ -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 @@ -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) + _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) diff --git a/pxr/usdImaging/usdviewq/appController.py b/pxr/usdImaging/usdviewq/appController.py index 642efa1f96..1234eaa9d4 100644 --- a/pxr/usdImaging/usdviewq/appController.py +++ b/pxr/usdImaging/usdviewq/appController.py @@ -982,13 +982,9 @@ def __init__(self, parserData, resolverContextFn): self._ui.actionShow_Abstract_Prims.triggered.connect( self._toggleShowAbstractPrims) - # nv begin #prim-display-name - self._ui.actionShow_Prim_DisplayName.triggered.connect( self._toggleShowPrimDisplayName) - # nv end - # Since setting column visibility is probably not a common # operation, it's actually good to have Columns at the end. self._ui.menuShow.addSeparator() @@ -2192,12 +2188,11 @@ def _findPrims(self, pattern, useRegex=True): pattern = pattern.lower() isMatch = lambda x: pattern in x.lower() - # nv begin #prim-display-name if self._dataModel.viewSettings.showPrimDisplayNames: matches = [prim.GetPath() for prim in Usd.PrimRange.Stage(self._dataModel.stage, self._displayPredicate) - if (isMatch(prim.GetMetadata("displayName")) or isMatch(prim.GetName()))] + if ((prim.HasAuthoredMetadata("displayName") and isMatch(prim.GetMetadata("displayName"))) or isMatch(prim.GetName()))] else: matches = [prim.GetPath() for prim in Usd.PrimRange.Stage(self._dataModel.stage, @@ -2209,15 +2204,13 @@ def _findPrims(self, pattern, useRegex=True): for prototype in self._dataModel.stage.GetPrototypes(): matches += [prim.GetPath() for prim in Usd.PrimRange(prototype, self._displayPredicate) - if (isMatch(prim.GetMetadata("displayName")) or isMatch(prim.GetName()))] + if ((prim.HasAuthoredMetadata("displayName") and isMatch(prim.GetMetadata("displayName"))) or isMatch(prim.GetName()))] else: for prototype in self._dataModel.stage.GetPrototypes(): matches += [prim.GetPath() for prim in Usd.PrimRange(prototype, self._displayPredicate) if isMatch(prim.GetName())] - #nv end - return matches def _primViewFindNext(self): @@ -3211,15 +3204,11 @@ def _toggleShowAbstractPrims(self): self._dataModel.selection.removeAbstractPrims() self._resetPrimView() - # nv begin #prim-display-name - def _toggleShowPrimDisplayName(self): self._dataModel.viewSettings.showPrimDisplayNames = ( self._ui.actionShow_Prim_DisplayName.isChecked()) self._resetPrimView() - # nv end - def _toggleRolloverPrimInfo(self): self._dataModel.viewSettings.rolloverPrimInfo = ( self._ui.actionRollover_Prim_Info.isChecked()) @@ -5264,11 +5253,8 @@ def _refreshShowPrimMenu(self): self._dataModel.viewSettings.showUndefinedPrims) self._ui.actionShow_Abstract_Prims.setChecked( self._dataModel.viewSettings.showAbstractPrims) - - # nv begin #prim-display-name self._ui.actionShow_Prim_DisplayName.setChecked( self._dataModel.viewSettings.showPrimDisplayNames) - # nv end def _refreshRedrawOnScrub(self): self._ui.redrawOnScrub.setChecked( diff --git a/pxr/usdImaging/usdviewq/primViewItem.py b/pxr/usdImaging/usdviewq/primViewItem.py index f8da64a7b1..c79eedaf87 100644 --- a/pxr/usdImaging/usdviewq/primViewItem.py +++ b/pxr/usdImaging/usdviewq/primViewItem.py @@ -129,7 +129,6 @@ def _isComputedDrawModeInherited(self, parentDrawModeIsInherited=None): return False def _extractInfo(self, info): - # nv begin #prim-display-name ( self.hasArcs, self.active, self.imageable, @@ -145,8 +144,6 @@ def _extractInfo(self, info): self.typeName, self.displayName ) = info - # nv end - parent = self.parent() parentIsPrimViewItem = isinstance(parent, PrimViewItem) self.computedVis = parent.computedVis if parentIsPrimViewItem \ @@ -231,12 +228,10 @@ def _GetForegroundColor(self): def _nameData(self, role): if role == QtCore.Qt.DisplayRole: - # nv begin #prim-display-name if self._appController._dataModel.viewSettings.showPrimDisplayNames: return self.displayName if self.displayName != "" else self.name else: return self.name - # nv end elif role == QtCore.Qt.FontRole: # Abstract prims are also considered defined; since we want # to distinguish abstract defined prims from non-abstract @@ -266,10 +261,8 @@ def _nameData(self, role): elif self.isInstance: toolTip = 'Instanced ' + toolTip - # nv begin #prim-display-name # tooltip should always show both name and display name toolTip = toolTip + "
Name: " + self.name + "
Display Name: " + self.displayName - # nv end if self.hasArcs: toolTip = toolTip + "
Has composition arcs" diff --git a/pxr/usdImaging/usdviewq/viewSettingsDataModel.py b/pxr/usdImaging/usdviewq/viewSettingsDataModel.py index 4ebf3c8fc8..fd1067472b 100644 --- a/pxr/usdImaging/usdviewq/viewSettingsDataModel.py +++ b/pxr/usdImaging/usdviewq/viewSettingsDataModel.py @@ -195,9 +195,7 @@ def __init__(self, rootDataModel, parent): self._showUndefinedPrims = self.stateProperty("showUndefinedPrims", default=False) self._showAbstractPrims = self.stateProperty("showAbstractPrims", default=False) - # nv begin #prim-display-name self._showPrimDisplayNames = self.stateProperty("showPrimDisplayNames", default=True) - # nv end self._rolloverPrimInfo = self.stateProperty("rolloverPrimInfo", default=False) self._displayCameraOracles = self.stateProperty("cameraOracles", default=False) self._cameraMaskMode = self.stateProperty("cameraMaskMode", default=CameraMaskModes.NONE) @@ -262,9 +260,7 @@ def onSaveState(self, state): state["showAllMasterPrims"] = self._showAllPrototypePrims state["showUndefinedPrims"] = self._showUndefinedPrims state["showAbstractPrims"] = self._showAbstractPrims - # nv begin #prim-display-name state["showPrimDisplayNames"] = self._showPrimDisplayNames - # nv end state["rolloverPrimInfo"] = self._rolloverPrimInfo state["cameraOracles"] = self._displayCameraOracles state["cameraMaskMode"] = self._cameraMaskMode @@ -641,7 +637,6 @@ def showAbstractPrims(self): def showAbstractPrims(self, value): self._showAbstractPrims = value - # nv begin #prim-display-name @property def showPrimDisplayNames(self): return self._showPrimDisplayNames @@ -651,8 +646,6 @@ def showPrimDisplayNames(self): def showPrimDisplayNames(self, value): self._showPrimDisplayNames = value - # nv end - @property def rolloverPrimInfo(self): return self._rolloverPrimInfo From 8c1fafbca3ef65c03068775e395f2d211d276171 Mon Sep 17 00:00:00 2001 From: Edward Slavin Date: Mon, 28 Nov 2022 10:56:50 -0500 Subject: [PATCH 4/9] Add displayName Metadata to Prim Spec - Moved displayName related methods from UsdProperty to UsdObject - Adjusted tests to better conform to user search expectations --- pxr/usd/usd/object.cpp | 30 ++++++++++++++++ pxr/usd/usd/object.h | 24 +++++++++++++ pxr/usd/usd/property.cpp | 27 -------------- pxr/usd/usd/property.h | 24 ------------- pxr/usd/usd/testenv/testUsdMetadata.py | 13 ++++--- pxr/usd/usd/testenv/testUsdSchemaRegistry.py | 4 +-- .../resources/generatedSchema.usda | 1 - .../resources/schema.usda | 1 - pxr/usd/usd/wrapObject.cpp | 5 +++ pxr/usd/usd/wrapProperty.cpp | 5 --- .../testUsdviewPrimSearch.py | 36 ++++++++++++------- .../testUsdviewPrimTreeExpansion/test.usda | 1 + .../testUsdviewPrimTreeExpansion.py | 5 ++- .../testUsdviewPropertySearch/test.usda | 5 ++- pxr/usdImaging/usdviewq/appController.py | 8 +++-- pxr/usdImaging/usdviewq/primViewItem.py | 4 ++- pxr/usdImaging/usdviewq/utils.cpp | 8 ++--- pxr/usdImaging/usdviewq/utils.h | 3 -- pxr/usdImaging/usdviewq/wrapUtils.cpp | 4 --- 19 files changed, 111 insertions(+), 97 deletions(-) diff --git a/pxr/usd/usd/object.cpp b/pxr/usd/usd/object.cpp index 860f239e16..a4543d47e9 100644 --- a/pxr/usd/usd/object.cpp +++ b/pxr/usd/usd/object.cpp @@ -339,6 +339,36 @@ UsdObject::HasAuthoredDocumentation() const return HasAuthoredMetadata(SdfFieldKeys->Documentation); } +// ------------------------------------------------------------------------- // +// 'DisplayName' Metadata +// ------------------------------------------------------------------------- // + +std::string +UsdObject::GetDisplayName() const +{ + std::string result; + GetMetadata(SdfFieldKeys->DisplayName, &result); + return result; +} + +bool +UsdObject::SetDisplayName(const std::string& newDisplayName) const +{ + return SetMetadata(SdfFieldKeys->DisplayName, newDisplayName); +} + +bool +UsdObject::ClearDisplayName() const +{ + return ClearMetadata(SdfFieldKeys->DisplayName); +} + +bool +UsdObject::HasAuthoredDisplayName() const +{ + return HasAuthoredMetadata(SdfFieldKeys->DisplayName); +} + SdfSpecType UsdObject::_GetDefiningSpecType() const { diff --git a/pxr/usd/usd/object.h b/pxr/usd/usd/object.h index 49d9b9422a..c305e5f21a 100644 --- a/pxr/usd/usd/object.h +++ b/pxr/usd/usd/object.h @@ -626,6 +626,30 @@ class UsdObject { USD_API bool HasAuthoredDocumentation() const; + /// Return this property's display name (metadata). This returns the + /// empty string if no display name has been set. + /// \sa SetDisplayName() + USD_API + std::string GetDisplayName() const; + + /// Sets this property's display name (metadata). Returns true on success. + /// + /// DisplayName is meant to be a descriptive label, not necessarily an + /// alternate identifier; therefore there is no restriction on which + /// characters can appear in it. + USD_API + bool SetDisplayName(const std::string& name) const; + + /// Clears this property's display name (metadata) in the current EditTarget + /// (only). Returns true on success. + USD_API + bool ClearDisplayName() const; + + /// Returns true if displayName was explicitly authored and GetMetadata() + /// will return a meaningful value for displayName. + USD_API + bool HasAuthoredDisplayName() const; + // --------------------------------------------------------------------- // /// @} // --------------------------------------------------------------------- // diff --git a/pxr/usd/usd/property.cpp b/pxr/usd/usd/property.cpp index bafdb5bcc8..17b0b80c58 100644 --- a/pxr/usd/usd/property.cpp +++ b/pxr/usd/usd/property.cpp @@ -116,33 +116,6 @@ UsdProperty::SetNestedDisplayGroups(const std::vector& nestedGroups return SetDisplayGroup(SdfPath::JoinIdentifier(nestedGroups)); } - -std::string -UsdProperty::GetDisplayName() const -{ - std::string result; - GetMetadata(SdfFieldKeys->DisplayName, &result); - return result; -} - -bool -UsdProperty::SetDisplayName(const std::string& newDisplayName) const -{ - return SetMetadata(SdfFieldKeys->DisplayName, newDisplayName); -} - -bool -UsdProperty::ClearDisplayName() const -{ - return ClearMetadata(SdfFieldKeys->DisplayName); -} - -bool -UsdProperty::HasAuthoredDisplayName() const -{ - return HasAuthoredMetadata(SdfFieldKeys->DisplayName); -} - bool UsdProperty::IsCustom() const { diff --git a/pxr/usd/usd/property.h b/pxr/usd/usd/property.h index 5d621112c8..06d9d4e677 100644 --- a/pxr/usd/usd/property.h +++ b/pxr/usd/usd/property.h @@ -173,30 +173,6 @@ class UsdProperty : public UsdObject { bool SetNestedDisplayGroups( const std::vector& nestedGroups) const; - /// Return this property's display name (metadata). This returns the - /// empty string if no display name has been set. - /// \sa SetDisplayName() - USD_API - std::string GetDisplayName() const; - - /// Sets this property's display name (metadata). Returns true on success. - /// - /// DisplayName is meant to be a descriptive label, not necessarily an - /// alternate identifier; therefore there is no restriction on which - /// characters can appear in it. - USD_API - bool SetDisplayName(const std::string& name) const; - - /// Clears this property's display name (metadata) in the current EditTarget - /// (only). Returns true on success. - USD_API - bool ClearDisplayName() const; - - /// Returns true if displayName was explicitly authored and GetMetadata() - /// will return a meaningful value for displayName. - USD_API - bool HasAuthoredDisplayName() const; - /// Return true if this is a custom property (i.e., not part of a /// prim schema). /// diff --git a/pxr/usd/usd/testenv/testUsdMetadata.py b/pxr/usd/usd/testenv/testUsdMetadata.py index 8f6602c907..91d969c021 100644 --- a/pxr/usd/usd/testenv/testUsdMetadata.py +++ b/pxr/usd/usd/testenv/testUsdMetadata.py @@ -285,11 +285,16 @@ def test_DisplayName(self): 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.GetDisplayName(), "") + self.assertFalse(foo.HasAuthoredDisplayName()) + self.assertEqual(foo.SetDisplayName("foo"), True) + self.assertEqual(foo.GetDisplayName(), "foo") + self.assertTrue(foo.HasAuthoredDisplayName()) self.assertEqual(foo.GetMetadata("displayName"), "foo") - self.assertEqual(foo.HasAuthoredMetadata("displayName"), True) + self.assertEqual(foo.ClearDisplayName(), True) + self.assertEqual(foo.GetDisplayName(), "") + self.assertFalse(foo.HasAuthoredDisplayName()) + self.assertEqual(foo.GetMetadata("displayName"), None) for prop in [attr, rel]: self.assertEqual(prop.GetDisplayName(), "") diff --git a/pxr/usd/usd/testenv/testUsdSchemaRegistry.py b/pxr/usd/usd/testenv/testUsdSchemaRegistry.py index 7dd5747472..d374fe7ea1 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaRegistry.py +++ b/pxr/usd/usd/testenv/testUsdSchemaRegistry.py @@ -41,9 +41,8 @@ def test_PrimMetadata(self): self.assertTrue(primDef) self.assertEqual(set(primDef.ListMetadataFields()), - set(["typeName", "testCustomMetadata", "hidden", "documentation", "displayName"])) + set(["typeName", "testCustomMetadata", "hidden", "documentation"])) 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) @@ -420,7 +419,6 @@ 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", diff --git a/pxr/usd/usd/testenv/testUsdSchemaRegistry/resources/generatedSchema.usda b/pxr/usd/usd/testenv/testUsdSchemaRegistry/resources/generatedSchema.usda index a71e17d6b8..50cf490576 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaRegistry/resources/generatedSchema.usda +++ b/pxr/usd/usd/testenv/testUsdSchemaRegistry/resources/generatedSchema.usda @@ -19,7 +19,6 @@ class "AbstractTest" ( } class MetadataTest "MetadataTest" ( - displayName = "Display Name" doc = "Testing documentation metadata" hidden = true testCustomMetadata = "garply" diff --git a/pxr/usd/usd/testenv/testUsdSchemaRegistry/resources/schema.usda b/pxr/usd/usd/testenv/testUsdSchemaRegistry/resources/schema.usda index 00aba542c6..4df1f42bc3 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaRegistry/resources/schema.usda +++ b/pxr/usd/usd/testenv/testUsdSchemaRegistry/resources/schema.usda @@ -35,7 +35,6 @@ class "AbstractTest" ( class MetadataTest "MetadataTest" ( inherits = - displayName = "Display Name" doc = "Testing documentation metadata" hidden = true testCustomMetadata = "garply" diff --git a/pxr/usd/usd/wrapObject.cpp b/pxr/usd/usd/wrapObject.cpp index 14d86b5521..0102619bf9 100644 --- a/pxr/usd/usd/wrapObject.cpp +++ b/pxr/usd/usd/wrapObject.cpp @@ -260,6 +260,11 @@ void wrapUsdObject() .def("ClearDocumentation", &UsdObject::ClearDocumentation) .def("HasAuthoredDocumentation", &UsdObject::HasAuthoredDocumentation) + .def("GetDisplayName", &UsdObject::GetDisplayName) + .def("SetDisplayName", &UsdObject::SetDisplayName, arg("name")) + .def("ClearDisplayName", &UsdObject::ClearDisplayName) + .def("HasAuthoredDisplayName", &UsdObject::HasAuthoredDisplayName) + .def("GetNamespaceDelimiter", &UsdObject::GetNamespaceDelimiter) .staticmethod("GetNamespaceDelimiter") diff --git a/pxr/usd/usd/wrapProperty.cpp b/pxr/usd/usd/wrapProperty.cpp index 3b0b0341b5..b38a07c726 100644 --- a/pxr/usd/usd/wrapProperty.cpp +++ b/pxr/usd/usd/wrapProperty.cpp @@ -58,11 +58,6 @@ void wrapUsdProperty() .def("SetNestedDisplayGroups", &UsdProperty::SetNestedDisplayGroups, arg("nestedGroups")) - .def("GetDisplayName", &UsdProperty::GetDisplayName) - .def("SetDisplayName", &UsdProperty::SetDisplayName, arg("name")) - .def("ClearDisplayName", &UsdProperty::ClearDisplayName) - .def("HasAuthoredDisplayName", &UsdProperty::HasAuthoredDisplayName) - .def("GetPropertyStack", &UsdProperty::GetPropertyStack, arg("time")) .def("GetPropertyStackWithLayerOffsets", diff --git a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimSearch/testUsdviewPrimSearch.py b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimSearch/testUsdviewPrimSearch.py index da5509ad73..8c954c0438 100644 --- a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimSearch/testUsdviewPrimSearch.py +++ b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimSearch/testUsdviewPrimSearch.py @@ -48,20 +48,30 @@ def _search(appController, searchTerm, expectedItems): _assertSelectedPrim(appController, item) 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']) + # by default the prim display name option is on + # so since neither 'f' nor 'foo' have authored + # display names, and prim names aren't searched + # when the option is on, this should return nothing + _search(appController, 'f', []) + + # with the prim display name option on, search + # is only searching the display name value + # so a search that is targeting the prim name + # won't produce the prim name as a result + _search(appController, 'g', []) + + # On an invalid search, the results will be + # equivalent to what was previously there (which in + # this case is nothing...) + _search(appController, 'xxx', []) + + # Do a regex based search - again, this is + # not looking at prim names, so nothing should + # be returned + _search(appController, 'f.*', []) # search based on display name - _search(appController, "test", ['testDisplayName']) + _search(appController, 'test', ['testDisplayName']) def _testSearchNoPrimDisplayName(appController): """ @@ -89,7 +99,7 @@ def _testSearchNoPrimDisplayName(appController): _search(appController, 'f.*', ['f', 'foo']) appController._dataModel.viewSettings.showPrimDisplayNames = True - _search(appController, 'g', ['testDisplayName']) + _search(appController, 'test', ['testDisplayName']) def testUsdviewInputFunction(appController): _testSearchBasic(appController) diff --git a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimTreeExpansion/test.usda b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimTreeExpansion/test.usda index 7ed2075f30..06467e7a4a 100644 --- a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimTreeExpansion/test.usda +++ b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimTreeExpansion/test.usda @@ -2,6 +2,7 @@ def Xform "Shapes" ( add variantSets = ["a_shapeVariant", "b_shapeVariant"] + displayName = "Shapes" ) { variantSet "a_shapeVariant" = { diff --git a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimTreeExpansion/testUsdviewPrimTreeExpansion.py b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimTreeExpansion/testUsdviewPrimTreeExpansion.py index 7b35747d28..5a7d5f4b5a 100644 --- a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimTreeExpansion/testUsdviewPrimTreeExpansion.py +++ b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimTreeExpansion/testUsdviewPrimTreeExpansion.py @@ -24,6 +24,9 @@ # # positions and names of our variants +# special case entry for 0, which represents a non-selection +# in the variant selection combo box +EMPTY = (0, '') CAPSULE = (1, 'capsule') CONE = (2, 'cone') CUBE = (3, 'cube') @@ -135,7 +138,7 @@ def _testAllExpanded(appController): assert item._nameData(QtCore.Qt.DisplayRole) == "CapsuleDisplayName" # clear the a-variant and just select the b-variant - _selectVariant(appController, 0, FIRST_VARIANT) + _selectVariant(appController, EMPTY[VARIANT_INFO_POS], FIRST_VARIANT) _selectVariant(appController, CAPSULE[VARIANT_INFO_POS], SECOND_VARIANT) prim = appController._dataModel.stage.GetPrimAtPath("/Shapes/Pill") item = appController._primToItemMap.get(prim) diff --git a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPropertySearch/test.usda b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPropertySearch/test.usda index 3bcb3e91c1..6ff7cff9fd 100644 --- a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPropertySearch/test.usda +++ b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPropertySearch/test.usda @@ -1,6 +1,9 @@ #usda 1.0 -def Xform "f" { +def Xform "f" ( + displayName = "f" +) +{ int a = 5 float y = 6 string z = "hello" diff --git a/pxr/usdImaging/usdviewq/appController.py b/pxr/usdImaging/usdviewq/appController.py index 1234eaa9d4..2bb9f1e0bb 100644 --- a/pxr/usdImaging/usdviewq/appController.py +++ b/pxr/usdImaging/usdviewq/appController.py @@ -2189,10 +2189,11 @@ def _findPrims(self, pattern, useRegex=True): isMatch = lambda x: pattern in x.lower() if self._dataModel.viewSettings.showPrimDisplayNames: - matches = [prim.GetPath() for prim + 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()))] + if (prim.HasAuthoredDisplayName() and + isMatch(prim.GetDisplayName()))] else: matches = [prim.GetPath() for prim in Usd.PrimRange.Stage(self._dataModel.stage, @@ -2204,7 +2205,8 @@ def _findPrims(self, pattern, useRegex=True): 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()))] + if (prim.HasAuthoredDisplayName() and + isMatch(prim.GetDisplayName()))] else: for prototype in self._dataModel.stage.GetPrototypes(): matches += [prim.GetPath() for prim diff --git a/pxr/usdImaging/usdviewq/primViewItem.py b/pxr/usdImaging/usdviewq/primViewItem.py index c79eedaf87..87ab334a77 100644 --- a/pxr/usdImaging/usdviewq/primViewItem.py +++ b/pxr/usdImaging/usdviewq/primViewItem.py @@ -262,7 +262,9 @@ def _nameData(self, role): toolTip = 'Instanced ' + toolTip # tooltip should always show both name and display name - toolTip = toolTip + "
Name: " + self.name + "
Display Name: " + self.displayName + toolTip = toolTip + "
Name: " + self.name + if self.displayName != "": + toolTip = toolTip + "
Display Name: " + self.displayName if self.hasArcs: toolTip = toolTip + "
Has composition arcs" diff --git a/pxr/usdImaging/usdviewq/utils.cpp b/pxr/usdImaging/usdviewq/utils.cpp index a003592242..57825b5bf7 100644 --- a/pxr/usdImaging/usdviewq/utils.cpp +++ b/pxr/usdImaging/usdviewq/utils.cpp @@ -105,18 +105,14 @@ UsdviewqUtils::PrimInfo::PrimInfo(const UsdPrim &prim, const UsdTimeCode time) name = _tokens->root.GetString(); typeName = prim.GetTypeName().GetString(); - // nv begin #prim-display-name - - if (prim.HasAuthoredMetadata(SdfFieldKeys->DisplayName)) + if (prim.HasAuthoredDisplayName()) { - prim.GetMetadata(SdfFieldKeys->DisplayName, &displayName); + displayName = prim.GetDisplayName(); } else { displayName = ""; } - - // nv end } /*static*/ diff --git a/pxr/usdImaging/usdviewq/utils.h b/pxr/usdImaging/usdviewq/utils.h index ffbddde3bd..5f515bf7ee 100644 --- a/pxr/usdImaging/usdviewq/utils.h +++ b/pxr/usdImaging/usdviewq/utils.h @@ -59,10 +59,7 @@ class UsdviewqUtils { bool visVaries; std::string name; std::string typeName; - - // nv begin #prim-display-name std::string displayName; - // nv end }; /// For the given \p stage and \p schemaType, return all active, defined diff --git a/pxr/usdImaging/usdviewq/wrapUtils.cpp b/pxr/usdImaging/usdviewq/wrapUtils.cpp index fd0ad1bbfb..954c961a06 100644 --- a/pxr/usdImaging/usdviewq/wrapUtils.cpp +++ b/pxr/usdImaging/usdviewq/wrapUtils.cpp @@ -47,8 +47,6 @@ static tuple _GetPrimInfo(UsdPrim const &prim, UsdTimeCode time) { UsdviewqUtils::PrimInfo info = UsdviewqUtils::GetPrimInfo(prim, time); - - // nv begin #prim-display-name return boost::python::make_tuple(info.hasCompositionArcs, info.isActive, info.isImageable, @@ -63,8 +61,6 @@ _GetPrimInfo(UsdPrim const &prim, UsdTimeCode time) info.name, info.typeName, info.displayName); - - // nv end } } // anonymous namespace From 69c2bb06d5324fa0b456dad646f7f5b35945d8c8 Mon Sep 17 00:00:00 2001 From: Edward Slavin Date: Mon, 28 Nov 2022 14:13:58 -0500 Subject: [PATCH 5/9] Add displayName Metadata to Prim Spec - Rolled back changes to search - Updated condition to match on display name if authored or on name if not --- .../testUsdviewPrimSearch.py | 11 +++++----- .../testUsdviewPrimTreeExpansion/test.usda | 1 - .../testUsdviewPropertySearch/test.usda | 1 - pxr/usdImaging/usdviewq/appController.py | 22 +++++++++++-------- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimSearch/testUsdviewPrimSearch.py b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimSearch/testUsdviewPrimSearch.py index 8c954c0438..022ff19382 100644 --- a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimSearch/testUsdviewPrimSearch.py +++ b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimSearch/testUsdviewPrimSearch.py @@ -50,9 +50,8 @@ def _search(appController, searchTerm, expectedItems): def _testSearchBasic(appController): # by default the prim display name option is on # so since neither 'f' nor 'foo' have authored - # display names, and prim names aren't searched - # when the option is on, this should return nothing - _search(appController, 'f', []) + # display names, it will search the prim name + _search(appController, 'f', ['f', 'foo']) # with the prim display name option on, search # is only searching the display name value @@ -66,9 +65,9 @@ def _testSearchBasic(appController): _search(appController, 'xxx', []) # Do a regex based search - again, this is - # not looking at prim names, so nothing should - # be returned - _search(appController, 'f.*', []) + # not looking at prim names here not display names + # since they aren't authored + _search(appController, 'f.*', ['f', 'foo']) # search based on display name _search(appController, 'test', ['testDisplayName']) diff --git a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimTreeExpansion/test.usda b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimTreeExpansion/test.usda index 06467e7a4a..7ed2075f30 100644 --- a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimTreeExpansion/test.usda +++ b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimTreeExpansion/test.usda @@ -2,7 +2,6 @@ def Xform "Shapes" ( add variantSets = ["a_shapeVariant", "b_shapeVariant"] - displayName = "Shapes" ) { variantSet "a_shapeVariant" = { diff --git a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPropertySearch/test.usda b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPropertySearch/test.usda index 6ff7cff9fd..5023130efe 100644 --- a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPropertySearch/test.usda +++ b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPropertySearch/test.usda @@ -1,7 +1,6 @@ #usda 1.0 def Xform "f" ( - displayName = "f" ) { int a = 5 diff --git a/pxr/usdImaging/usdviewq/appController.py b/pxr/usdImaging/usdviewq/appController.py index 2bb9f1e0bb..513ca012f7 100644 --- a/pxr/usdImaging/usdviewq/appController.py +++ b/pxr/usdImaging/usdviewq/appController.py @@ -2188,12 +2188,14 @@ def _findPrims(self, pattern, useRegex=True): pattern = pattern.lower() isMatch = lambda x: pattern in x.lower() + matches = [] if self._dataModel.viewSettings.showPrimDisplayNames: - matches = [prim.GetPath() for prim - in Usd.PrimRange.Stage(self._dataModel.stage, - self._displayPredicate) - if (prim.HasAuthoredDisplayName() and - isMatch(prim.GetDisplayName()))] + for prim in Usd.PrimRange.Stage(self._dataModel.stage, self._displayPredicate): + if prim.HasAuthoredDisplayName(): + if isMatch(prim.GetDisplayName()): + matches.append(prim.GetPath()) + elif isMatch(prim.GetName()): + matches.append(prim.GetPath()) else: matches = [prim.GetPath() for prim in Usd.PrimRange.Stage(self._dataModel.stage, @@ -2203,10 +2205,12 @@ def _findPrims(self, pattern, useRegex=True): if self._dataModel.viewSettings.showAllPrototypePrims: 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.HasAuthoredDisplayName() and - isMatch(prim.GetDisplayName()))] + for prim in Usd.PrimRange(prototype, self._displayPredicate): + if prim.HasAuthoredDisplayName(): + if isMatch(prim.GetDisplayName()): + matches.append(prim.GetPath()) + elif isMatch(prim.GetName()): + matches.append(prim.GetPath()) else: for prototype in self._dataModel.stage.GetPrototypes(): matches += [prim.GetPath() for prim From b83ead3baa2571a758fdea949a3a3bb15482ec74 Mon Sep 17 00:00:00 2001 From: Edward Slavin Date: Mon, 28 Nov 2022 14:54:44 -0500 Subject: [PATCH 6/9] Add displayName Metadata to Prim Spec - Ensured .ui file was saved from Qt designer --- pxr/usdImaging/usdviewq/mainWindowUI.ui | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pxr/usdImaging/usdviewq/mainWindowUI.ui b/pxr/usdImaging/usdviewq/mainWindowUI.ui index 6ca98d5397..e4fbb8ee61 100644 --- a/pxr/usdImaging/usdviewq/mainWindowUI.ui +++ b/pxr/usdImaging/usdviewq/mainWindowUI.ui @@ -159,7 +159,7 @@ - + @@ -1651,7 +1651,7 @@ 0 0 1145 - 20 + 21
From eb47cb75768439281c92c7ed80b45bd6356df154 Mon Sep 17 00:00:00 2001 From: Edward Slavin Date: Tue, 29 Nov 2022 07:52:17 -0500 Subject: [PATCH 7/9] Add displayName Metadata to Prim Spec - Refactored out pattern match code into separate method to avoid code duplication across prim and prototype search paths - Fixed documentation issue --- .../testUsdviewPrimSearch.py | 2 +- pxr/usdImaging/usdviewq/appController.py | 83 ++++++++++++------- 2 files changed, 52 insertions(+), 33 deletions(-) diff --git a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimSearch/testUsdviewPrimSearch.py b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimSearch/testUsdviewPrimSearch.py index 022ff19382..4043d631e2 100644 --- a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimSearch/testUsdviewPrimSearch.py +++ b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPrimSearch/testUsdviewPrimSearch.py @@ -65,7 +65,7 @@ def _testSearchBasic(appController): _search(appController, 'xxx', []) # Do a regex based search - again, this is - # not looking at prim names here not display names + # looking at prim names here not display names # since they aren't authored _search(appController, 'f.*', ['f', 'foo']) diff --git a/pxr/usdImaging/usdviewq/appController.py b/pxr/usdImaging/usdviewq/appController.py index 513ca012f7..ccd93364a3 100644 --- a/pxr/usdImaging/usdviewq/appController.py +++ b/pxr/usdImaging/usdviewq/appController.py @@ -2175,6 +2175,47 @@ def setFrameField(self, frame): # Prim/Attribute search functionality ===================================== + def _isMatch(self, pattern, isRegex, prim, useDisplayName): + """ + Determines if the given prim has a name that matches the + given pattern. If useDisplayName is True, the match + will be performed on the prim's display name (if authored) + and on the prim's name (if not). When useDisplayName is False, + the match is always performed against the prim's name. + + Args: + pattern (str): The pattern to use to match the name. Pattern + is either a sequence of characters or a regex + expression. If it is a regex expression, the + isRegex parameter should be set to True. + isRegex (bool): True if the given pattern is a regex expression + or False if just a sequence of characters. + prim (object): A python facing UsdPrim object on whos properties + should be matched by pattern. + useDisplayName (bool): True if the pattern match should be against + the displayName of the prim or False if + against the name of the prim. If this value is True + displayName will only be matched if it is authored, + otherwise the name of the prim will be used. + + Returns: + True if the pattern matches the specified prim content, False otherwise. + """ + if isRegex: + matchLambda = re.compile(pattern, re.IGNORECASE).search + else: + pattern = pattern.lower() + matchLambda = lambda x: pattern in x.lower() + + if useDisplayName: + if prim.HasAuthoredDisplayName(): + return matchLambda(prim.GetDisplayName()) + else: + return matchLambda(prim.GetName()) + else: + return matchLambda(prim.GetName()) + + def _findPrims(self, pattern, useRegex=True): """Search the Usd Stage for matching prims """ @@ -2182,40 +2223,18 @@ def _findPrims(self, pattern, useRegex=True): # down to simple search, as it's faster if useRegex and re.match("^[0-9_A-Za-z]+$", pattern): useRegex = False - if useRegex: - isMatch = re.compile(pattern, re.IGNORECASE).search - else: - pattern = pattern.lower() - isMatch = lambda x: pattern in x.lower() - - matches = [] - if self._dataModel.viewSettings.showPrimDisplayNames: - for prim in Usd.PrimRange.Stage(self._dataModel.stage, self._displayPredicate): - if prim.HasAuthoredDisplayName(): - if isMatch(prim.GetDisplayName()): - matches.append(prim.GetPath()) - elif isMatch(prim.GetName()): - matches.append(prim.GetPath()) - else: - matches = [prim.GetPath() for prim - in Usd.PrimRange.Stage(self._dataModel.stage, - self._displayPredicate) - if isMatch(prim.GetName())] + + matches = [prim.GetPath() for prim + in Usd.PrimRange.Stage(self._dataModel.stage, self._displayPredicate) + if self._isMatch(pattern, useRegex, prim, + self._dataModel.viewSettings.showPrimDisplayNames)] if self._dataModel.viewSettings.showAllPrototypePrims: - if self._dataModel.viewSettings.showPrimDisplayNames: - for prototype in self._dataModel.stage.GetPrototypes(): - for prim in Usd.PrimRange(prototype, self._displayPredicate): - if prim.HasAuthoredDisplayName(): - if isMatch(prim.GetDisplayName()): - matches.append(prim.GetPath()) - elif isMatch(prim.GetName()): - matches.append(prim.GetPath()) - else: - for prototype in self._dataModel.stage.GetPrototypes(): - matches += [prim.GetPath() for prim - in Usd.PrimRange(prototype, self._displayPredicate) - if isMatch(prim.GetName())] + for prototype in self._dataModel.stage.GetPrototypes(): + matches += [prim.GetPath() for prim + in Usd.PrimRange(prototype, self._displayPredicate) + if self._isMatch(pattern, useRegex, prim, + self._dataModel.viewSettings.showPrimDisplayNames)] return matches From 62192758cd39eed35a54055a40b48505ae256f7e Mon Sep 17 00:00:00 2001 From: Edward Slavin Date: Wed, 30 Nov 2022 08:02:46 -0500 Subject: [PATCH 8/9] Add displayName Metadata to Prim Spec - Adjusted usdview search matching logic to directly invoke GetDisplayName and compare to empty string to avoid overhead of calling HasAuthoredDisplayName followed by GetDisplayName --- pxr/usdImaging/usdviewq/appController.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pxr/usdImaging/usdviewq/appController.py b/pxr/usdImaging/usdviewq/appController.py index ccd93364a3..d117a5a2d7 100644 --- a/pxr/usdImaging/usdviewq/appController.py +++ b/pxr/usdImaging/usdviewq/appController.py @@ -2190,7 +2190,7 @@ def _isMatch(self, pattern, isRegex, prim, useDisplayName): isRegex parameter should be set to True. isRegex (bool): True if the given pattern is a regex expression or False if just a sequence of characters. - prim (object): A python facing UsdPrim object on whos properties + prim (object): A python facing UsdPrim object on whose properties should be matched by pattern. useDisplayName (bool): True if the pattern match should be against the displayName of the prim or False if @@ -2208,8 +2208,16 @@ def _isMatch(self, pattern, isRegex, prim, useDisplayName): matchLambda = lambda x: pattern in x.lower() if useDisplayName: - if prim.HasAuthoredDisplayName(): - return matchLambda(prim.GetDisplayName()) + # typically we would check prim.HasAuthoredDisplayName() + # rather than getting the display name and checking + # against the empty string, but HasAuthoredDisplayName + # does about the same amount of work of GetDisplayName + # so we'd be paying twice the price for each prim + # search, which on large scenes would be a big performance + # hit, so we do it this way instead + displayName = prim.GetDisplayName() + if displayName is not None and displayName != "": + return matchLambda(displayName) else: return matchLambda(prim.GetName()) else: From 835870dd0c0c2262f020d8fba3ff2188ba46713b Mon Sep 17 00:00:00 2001 From: Edward Slavin Date: Wed, 14 Dec 2022 08:39:36 -0500 Subject: [PATCH 9/9] Add displayName Metadta to Prim Spec - Modified comments appropriately for methods moved to UsdObject - Made checks for valid displayName more pythonic --- pxr/usd/usd/object.h | 6 +++--- pxr/usdImaging/usdviewq/appController.py | 2 +- pxr/usdImaging/usdviewq/primViewItem.py | 2 +- pxr/usdImaging/usdviewq/utils.cpp | 9 +-------- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/pxr/usd/usd/object.h b/pxr/usd/usd/object.h index c305e5f21a..f85ef29140 100644 --- a/pxr/usd/usd/object.h +++ b/pxr/usd/usd/object.h @@ -626,13 +626,13 @@ class UsdObject { USD_API bool HasAuthoredDocumentation() const; - /// Return this property's display name (metadata). This returns the + /// Return this objects's display name (metadata). This returns the /// empty string if no display name has been set. /// \sa SetDisplayName() USD_API std::string GetDisplayName() const; - /// Sets this property's display name (metadata). Returns true on success. + /// Sets this objects's display name (metadata). Returns true on success. /// /// DisplayName is meant to be a descriptive label, not necessarily an /// alternate identifier; therefore there is no restriction on which @@ -640,7 +640,7 @@ class UsdObject { USD_API bool SetDisplayName(const std::string& name) const; - /// Clears this property's display name (metadata) in the current EditTarget + /// Clears this objects's display name (metadata) in the current EditTarget /// (only). Returns true on success. USD_API bool ClearDisplayName() const; diff --git a/pxr/usdImaging/usdviewq/appController.py b/pxr/usdImaging/usdviewq/appController.py index d117a5a2d7..7bdbbafed0 100644 --- a/pxr/usdImaging/usdviewq/appController.py +++ b/pxr/usdImaging/usdviewq/appController.py @@ -2216,7 +2216,7 @@ def _isMatch(self, pattern, isRegex, prim, useDisplayName): # search, which on large scenes would be a big performance # hit, so we do it this way instead displayName = prim.GetDisplayName() - if displayName is not None and displayName != "": + if displayName: return matchLambda(displayName) else: return matchLambda(prim.GetName()) diff --git a/pxr/usdImaging/usdviewq/primViewItem.py b/pxr/usdImaging/usdviewq/primViewItem.py index 87ab334a77..aef2329dc8 100644 --- a/pxr/usdImaging/usdviewq/primViewItem.py +++ b/pxr/usdImaging/usdviewq/primViewItem.py @@ -263,7 +263,7 @@ def _nameData(self, role): # tooltip should always show both name and display name toolTip = toolTip + "
Name: " + self.name - if self.displayName != "": + if self.displayName: toolTip = toolTip + "
Display Name: " + self.displayName if self.hasArcs: diff --git a/pxr/usdImaging/usdviewq/utils.cpp b/pxr/usdImaging/usdviewq/utils.cpp index 57825b5bf7..11b07a9691 100644 --- a/pxr/usdImaging/usdviewq/utils.cpp +++ b/pxr/usdImaging/usdviewq/utils.cpp @@ -105,14 +105,7 @@ UsdviewqUtils::PrimInfo::PrimInfo(const UsdPrim &prim, const UsdTimeCode time) name = _tokens->root.GetString(); typeName = prim.GetTypeName().GetString(); - if (prim.HasAuthoredDisplayName()) - { - displayName = prim.GetDisplayName(); - } - else - { - displayName = ""; - } + displayName = prim.GetDisplayName(); } /*static*/