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

UsdView: Display resolved labels in prim rollover window #3460

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions pxr/usdImaging/usdviewq/appController.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from functools import cmp_to_key

# Usd Library Components
from pxr import Usd, UsdGeom, UsdShade, UsdUtils, UsdImagingGL, Glf, Sdf, Tf, Ar
from pxr import Usd, UsdGeom, UsdShade, UsdUtils, UsdImagingGL, Glf, Sdf, Tf, Ar, UsdSemantics
from pxr import UsdAppUtils
from pxr.UsdAppUtils.complexityArgs import RefinementComplexities
from pxr.UsdUtils.constantsGroup import ConstantsGroup
Expand All @@ -36,7 +36,7 @@
from .attributeViewContextMenu import AttributeViewContextMenu
from .customAttributes import (_GetCustomAttributes, CustomAttribute,
BoundingBoxAttribute, LocalToWorldXformAttribute,
ResolvedBoundMaterial)
ResolvedBoundMaterial, ResolvedLabelsAttribute)
from .primTreeWidget import PrimTreeWidget, PrimViewColumnIndex
from .primViewItem import PrimViewItem
from .variantComboBox import VariantComboBox
Expand All @@ -57,7 +57,7 @@
PropTreeWidgetTypeIsRel, PrimNotFoundException,
GetRootLayerStackInfo, HasSessionVis, GetEnclosingModelPrim,
GetPrimsLoadability, ClearColors,
HighlightColors, KeyboardShortcuts, PrintWarning)
HighlightColors, KeyboardShortcuts, PrintWarning, TruncateMiddle)

from .settings import StateSource, ConfigManager
from .usdviewApi import UsdviewApi
Expand Down Expand Up @@ -5165,6 +5165,16 @@ def _HTMLEscape(s):
if currProtoPath.HasPrefix(path):
currProtoPath = currProtoPath.MakeRelativePath(path)
propertyStr += "<br> -- <em>instance of prototype &lt;%s&gt;</em>" % str(currProtoPath)

# Semantic information
primResolvedLabelsProp = ResolvedLabelsAttribute(currentPrim=prim, rootDataModel=None)
primResolvedLabels = primResolvedLabelsProp.Get(self._dataModel.currentFrame)
if primResolvedLabels:
propertyStr += "<br> -- <em>%s</em> = %s" %\
(
primResolvedLabelsProp.GetName().lower(),
TruncateMiddle(str(primResolvedLabels), max_length=round(1.5*self._maxToolTipWidth()))
)

# Material info - this IS expected
materialStr = "<hr><b>Material assignment:</b>"
Expand Down Expand Up @@ -5202,6 +5212,17 @@ def _HTMLEscape(s):
materialStr += "<br><small><em>Material binding "\
"relationship: %s</em></small>" % str(bindingRelPath)

# Semantic information
mtlResolvedLabelsProp = ResolvedLabelsAttribute(currentPrim=material.GetPrim(), rootDataModel=None)
mtlResolvedLabels = mtlResolvedLabelsProp.Get(self._dataModel.currentFrame)
if mtlResolvedLabels:
materialStr += "<br><small><em>%s: %s</em></small>" %\
(
mtlResolvedLabelsProp.GetName(),
TruncateMiddle(str(mtlResolvedLabels), max_length=round(1.5*self._maxToolTipWidth()))
)


if not gotValidMaterial:
materialStr += "<small><em>No assigned Material!</em></small>"

Expand Down
22 changes: 22 additions & 0 deletions pxr/usdImaging/usdviewq/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,28 @@ def arrayToStr(a):

return result[:500]

def TruncateMiddle(text, max_length=125, ellipsis='...'):
"""Truncate a string to a maximum length, replacing the middle with an
ellipsis if necessary. If the string is already shorter than the maximum
length, it is returned unchanged.

Args:
text (str): The string to truncate.
max_length (int): The maximum length of the returned string.
ellipsis (str): The string to insert in the middle of the truncated
string. Defaults to '...'.
Returns:
str: The truncated string.
"""
if len(text) <= max_length:
return text

# Calculate the number of characters to keep on each side
side_length = (max_length - len(ellipsis)) // 2

# Truncate the string and add ellipsis
return text[:side_length] + ellipsis + text[-side_length:]

# Return a string that reports size in metric units (units of 1000, not 1024).
def ReportMetricSize(sizeInBytes):
if sizeInBytes == 0:
Expand Down
Loading