From c318924984eeea3a668d26cd909661e9e30283f6 Mon Sep 17 00:00:00 2001 From: aszabo Date: Tue, 5 Nov 2024 15:22:05 -0700 Subject: [PATCH] Added resolved labels to prim rollover in usdview --- pxr/usdImaging/usdviewq/appController.py | 27 +++++++++++++++++++++--- pxr/usdImaging/usdviewq/common.py | 22 +++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/pxr/usdImaging/usdviewq/appController.py b/pxr/usdImaging/usdviewq/appController.py index 8e66b7f9bf..82d32f5301 100644 --- a/pxr/usdImaging/usdviewq/appController.py +++ b/pxr/usdImaging/usdviewq/appController.py @@ -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 @@ -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 @@ -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 @@ -5165,6 +5165,16 @@ def _HTMLEscape(s): if currProtoPath.HasPrefix(path): currProtoPath = currProtoPath.MakeRelativePath(path) propertyStr += "
-- instance of prototype <%s>" % str(currProtoPath) + + # Semantic information + primResolvedLabelsProp = ResolvedLabelsAttribute(currentPrim=prim, rootDataModel=None) + primResolvedLabels = primResolvedLabelsProp.Get(self._dataModel.currentFrame) + if primResolvedLabels: + propertyStr += "
-- %s = %s" %\ + ( + primResolvedLabelsProp.GetName().lower(), + TruncateMiddle(str(primResolvedLabels), max_length=round(1.5*self._maxToolTipWidth())) + ) # Material info - this IS expected materialStr = "
Material assignment:" @@ -5202,6 +5212,17 @@ def _HTMLEscape(s): materialStr += "
Material binding "\ "relationship: %s" % str(bindingRelPath) + # Semantic information + mtlResolvedLabelsProp = ResolvedLabelsAttribute(currentPrim=material.GetPrim(), rootDataModel=None) + mtlResolvedLabels = mtlResolvedLabelsProp.Get(self._dataModel.currentFrame) + if mtlResolvedLabels: + materialStr += "
%s: %s" %\ + ( + mtlResolvedLabelsProp.GetName(), + TruncateMiddle(str(mtlResolvedLabels), max_length=round(1.5*self._maxToolTipWidth())) + ) + + if not gotValidMaterial: materialStr += "No assigned Material!" diff --git a/pxr/usdImaging/usdviewq/common.py b/pxr/usdImaging/usdviewq/common.py index af71123b00..d035a7374c 100644 --- a/pxr/usdImaging/usdviewq/common.py +++ b/pxr/usdImaging/usdviewq/common.py @@ -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: