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 8 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
30 changes: 30 additions & 0 deletions pxr/usd/usd/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
24 changes: 24 additions & 0 deletions pxr/usd/usd/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,30 @@ class UsdObject {
USD_API
bool HasAuthoredDocumentation() const;

/// Return this property's display name (metadata). This returns the
spiffmon marked this conversation as resolved.
Show resolved Hide resolved
/// 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;

// --------------------------------------------------------------------- //
/// @}
// --------------------------------------------------------------------- //
Expand Down
27 changes: 0 additions & 27 deletions pxr/usd/usd/property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,33 +116,6 @@ UsdProperty::SetNestedDisplayGroups(const std::vector<std::string>& 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
{
Expand Down
24 changes: 0 additions & 24 deletions pxr/usd/usd/property.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,30 +173,6 @@ class UsdProperty : public UsdObject {
bool SetNestedDisplayGroups(
const std::vector<std::string>& 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).
///
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
12 changes: 12 additions & 0 deletions pxr/usd/usd/testenv/testUsdMetadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,18 @@ def test_DisplayName(self):
attr = foo.CreateAttribute("attr", Sdf.ValueTypeNames.String)
rel = foo.CreateRelationship("rel")

# verify display name metadata on prim
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.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(), "")
self.assertFalse(prop.HasAuthoredDisplayName())
Expand Down
5 changes: 5 additions & 0 deletions pxr/usd/usd/wrapObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
5 changes: 0 additions & 5 deletions pxr/usd/usd/wrapProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
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 @@ -48,6 +48,46 @@ def _search(appController, searchTerm, expectedItems):
_assertSelectedPrim(appController, item)

def _testSearchBasic(appController):
# by default the prim display name option is on
# so since neither 'f' nor 'foo' have authored
# 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
# 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
# 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'])

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'])

Expand All @@ -57,5 +97,11 @@ def _testSearchBasic(appController):
# Do a regex based search
_search(appController, 'f.*', ['f', 'foo'])

appController._dataModel.viewSettings.showPrimDisplayNames = True
_search(appController, 'test', ['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 @@ -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, '')
spiffmon marked this conversation as resolved.
Show resolved Hide resolved
CAPSULE = (1, 'capsule')
CONE = (2, 'cone')
CUBE = (3, 'cube')
Expand All @@ -36,7 +39,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 +131,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, 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)
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#usda 1.0

def Xform "f" {
def Xform "f" (
)
{
int a = 5
float y = 6
string z = "hello"
Expand Down
Loading