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

MAYA-106630 - See which prims have a composition arc including a variant #816

Merged
merged 1 commit into from
Oct 6, 2020
Merged
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
2 changes: 2 additions & 0 deletions lib/mayaUsd/resources/icons/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ if (CMAKE_UFE_V2_FEATURES_AVAILABLE)
BlendShape
Camera
Capsule
CompArcBadge
CompArcBadgeV
Cone
Cube
Cylinder
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
130 changes: 130 additions & 0 deletions lib/mayaUsd/ufe/UsdUIInfoHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,53 @@
#include "UsdUIInfoHandler.h"
#include "UsdSceneItem.h"

#if UFE_PREVIEW_VERSION_NUM >= 2024
#include <pxr/usd/usd/variantSets.h>
#include <pxr/usd/sdf/schema.h> // SdfFieldKeys
#include <pxr/usd/sdf/listOp.h> // SdfReferenceListOp/SdfPayloadListOp/SdfPathListOp
#endif

#include <maya/MDoubleArray.h>
#include <maya/MGlobal.h>

#include <map>
#include <vector>

#if UFE_PREVIEW_VERSION_NUM >= 2024
namespace
{
// Simple helper to add the metadata strings to the end of the input tooltip string.
// Depending on the count, will add singular string or plural (with count).
void addMetadataStrings(const int nb, std::string& tooltip, bool& needComma, const std::string& singular, const std::string& plural)
{
if (nb <= 0) return;
if (tooltip.empty())
tooltip += "<b>Introduced Composition Arcs:</b> ";
if (needComma)
tooltip += ", ";
if (nb == 1) {
tooltip += singular;
}
else {
tooltip += std::to_string(nb);
tooltip += " ";
tooltip += plural;
}
needComma = true;
}

// Simple template helper function to handle all the various types of listOps.
template<typename T>
void addMetadataCount(const T& op, std::string& tooltip, bool& needComma, const std::string& singular, const std::string& plural)
{
T::ItemVector refs;
op.ApplyOperations(&refs);
if (!refs.empty()) {
addMetadataStrings(refs.size(), tooltip, needComma, singular, plural);
}
}
}
#endif

MAYAUSD_NS_DEF {
namespace ufe {
Expand Down Expand Up @@ -73,11 +116,19 @@ bool UsdUIInfoHandler::treeViewCellInfo(const Ufe::SceneItem::Ptr& item, Ufe::Ce
return changed;
}

#if UFE_PREVIEW_VERSION_NUM >= 2024
Ufe::UIInfoHandler::Icon UsdUIInfoHandler::treeViewIcon(const Ufe::SceneItem::Ptr& item) const
#else
std::string UsdUIInfoHandler::treeViewIcon(const Ufe::SceneItem::Ptr& item) const
#endif
Comment on lines +119 to +123
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In UFE v0.2.24, I changed the return type.

{
// Special case for nullptr input.
if (!item) {
#if UFE_PREVIEW_VERSION_NUM >= 2024
return Ufe::UIInfoHandler::Icon("out_USD_UsdTyped.png"); // Default USD icon
#else
return "out_USD_UsdTyped.png"; // Default USD icon
#endif
}

// We support these node types directly.
Expand Down Expand Up @@ -106,14 +157,93 @@ std::string UsdUIInfoHandler::treeViewIcon(const Ufe::SceneItem::Ptr& item) cons
{"Volume", "out_USD_Volume.png"}
};

#if UFE_PREVIEW_VERSION_NUM >= 2024
Ufe::UIInfoHandler::Icon icon; // Default is empty (no icon and no badge).
#endif

const auto search = supportedTypes.find(item->nodeType());
if (search != supportedTypes.cend()) {
#if UFE_PREVIEW_VERSION_NUM >= 2024
icon.baseIcon = search->second;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Save the base icon but don't return yet. We'll look for a badge icon below.

#else
return search->second;
#endif
}

#if UFE_PREVIEW_VERSION_NUM >= 2024
// Check if we have any composition meta data - if yes we display a special badge.
UsdSceneItem::Ptr usdItem = std::dynamic_pointer_cast<UsdSceneItem>(item);
if (usdItem)
{
// Variants
if (!usdItem->prim().GetVariantSets().GetNames().empty())
{
icon.badgeIcon = "out_USD_CompArcBadgeV.png";
icon.pos = Ufe::UIInfoHandler::LowerRight;
}
Comment on lines +179 to +183
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we have any variants, then use the composition arc icon with V.

else
{
// Composition related metadata.
static const std::vector<PXR_NS::TfToken> compKeys = {
PXR_NS::SdfFieldKeys->References, SdfFieldKeys->Payload, SdfFieldKeys->InheritPaths, SdfFieldKeys->Specializes};
for (const auto& k : compKeys)
{
if (usdItem->prim().HasMetadata(k))
{
icon.badgeIcon = "out_USD_CompArcBadge.png";
icon.pos = Ufe::UIInfoHandler::LowerRight;
break;
}
}
Comment on lines +186 to +197
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Otherwise look and see if we have any of the meta data types: references, payload, inheritpaths, specializes. If yes, then add the composition arc badge icon.

}
}

return icon;
#else
// No specific node type icon was found.
return "";
#endif
}

#if UFE_PREVIEW_VERSION_NUM >= 2024
std::string UsdUIInfoHandler::treeViewTooltip(const Ufe::SceneItem::Ptr& item) const
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Override this new method added in UFE v0.2.24.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We again check each of the types, but this time we must check them all and add a count of how many of each type we found. Here performance should not be a concern since this method is called "on-demand" when the user hovers for a tooltip.

{
std::string tooltip;

UsdSceneItem::Ptr usdItem = std::dynamic_pointer_cast<UsdSceneItem>(item);
if (usdItem)
{
// Composition related metadata.
bool needComma = false;
PXR_NS::SdfReferenceListOp referenceOp;
if (usdItem->prim().GetMetadata(PXR_NS::SdfFieldKeys->References, &referenceOp)) {
addMetadataCount<PXR_NS::SdfReferenceListOp>(referenceOp, tooltip, needComma, "Reference", "References");
}

PXR_NS::SdfPayloadListOp payloadOp;
if (usdItem->prim().GetMetadata(PXR_NS::SdfFieldKeys->Payload, &payloadOp)) {
addMetadataCount<PXR_NS::SdfPayloadListOp>(payloadOp, tooltip, needComma, "Payload", "Payloads");
}

PXR_NS::SdfPathListOp inheritOp;
if (usdItem->prim().GetMetadata(PXR_NS::SdfFieldKeys->InheritPaths, &inheritOp)) {
addMetadataCount<PXR_NS::SdfPathListOp>(inheritOp, tooltip, needComma, "Inherit", "Inherits");
}

PXR_NS::SdfPathListOp specializeOp;
if (usdItem->prim().GetMetadata(PXR_NS::SdfFieldKeys->Specializes, &specializeOp)) {
addMetadataCount<PXR_NS::SdfPathListOp>(specializeOp, tooltip, needComma, "Specialize", "Specializes");
}

// Variants
const auto& variants = usdItem->prim().GetVariantSets().GetNames();
if (!variants.empty()) {
addMetadataStrings(variants.size(), tooltip, needComma, "Variant", "Variants");
}
}
return tooltip;
}
#endif

std::string UsdUIInfoHandler::getLongRunTimeLabel() const
{
Expand Down
5 changes: 5 additions & 0 deletions lib/mayaUsd/ufe/UsdUIInfoHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ class MAYAUSD_CORE_PUBLIC UsdUIInfoHandler : public Ufe::UIInfoHandler

// Ufe::UIInfoHandler overrides
bool treeViewCellInfo(const Ufe::SceneItem::Ptr& item, Ufe::CellInfo& info) const override;
#if UFE_PREVIEW_VERSION_NUM >= 2024
Ufe::UIInfoHandler::Icon treeViewIcon(const Ufe::SceneItem::Ptr& item) const override;
std::string treeViewTooltip(const Ufe::SceneItem::Ptr& item) const override;
#else
std::string treeViewIcon(const Ufe::SceneItem::Ptr& item) const override;
#endif
std::string getLongRunTimeLabel() const override;
}; // UsdUIInfoHandler

Expand Down
6 changes: 6 additions & 0 deletions test/lib/ufe/testUIInfoHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,9 @@ def testUIInfo(self):
# Strikeout should be be set and the text fg color changed.
self.assertTrue(ci.fontStrikeout)
self.assertTrue(initTextFgClr != ci.textFgColor)

if(os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') >= '2024'):
# Ball_3 should have a specific node type icon set and no badge.
icon = ufeUIInfo.treeViewIcon(ball3Hier)
self.assertEqual(icon.baseIcon, "out_USD_Sphere.png")
self.assertFalse(icon.badgeIcon) # empty string
Comment on lines +79 to +83
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added a test for the icon. I didn't bother testing the tooltip because the test would be meaningless - either there is or isn't a tooltip. I would not want to check the actual tooltip text.