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

EMSUSD-791 - Add bulk editing support for unload and load with descendants #3496

Merged
merged 1 commit into from
Dec 7, 2023
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
35 changes: 35 additions & 0 deletions lib/usdUfe/ufe/UsdContextOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ void UsdContextOps::addBulkEditHeader(Ufe::ContextOps::Items& items) const
*
* "{countOfPrimsSelected} {PrimType} Prims Selected" - disbled item has no action
* -----------------
* Unload
* Load with Descendants
* Make Visible
* Make Invisible
* Activate Prim
Expand All @@ -504,6 +506,12 @@ Ufe::ContextOps::Items UsdContextOps::getBulkItems(const ItemPath& itemPath) con
if (itemPath.empty()) {
addBulkEditHeader(items);

// Unload
items.emplace_back(kUSDUnloadItem, kUSDUnloadLabel);

// Load With Descendants
items.emplace_back(kUSDLoadWithDescendantsItem, kUSDLoadWithDescendantsLabel);

// Visibility:
items.emplace_back(kUSDMakeVisibleItem, kUSDMakeVisibleLabel);
items.emplace_back(kUSDMakeInvisibleItem, kUSDMakeInvisibleLabel);
Expand Down Expand Up @@ -616,6 +624,33 @@ Ufe::UndoableCommand::Ptr UsdContextOps::doBulkOpCmd(const ItemPath& itemPath)
: nullptr;
};

// Unload:
if (itemPath[0u] == kUSDUnloadItem) {
for (auto& selItem : _bulkItems) {
UsdSceneItem::Ptr usdItem = std::dynamic_pointer_cast<UsdSceneItem>(selItem);
if (usdItem) {
auto cmd = std::make_shared<UsdUndoUnloadPayloadCommand>(usdItem->prim());
cmdList.emplace_back(cmd);
}
}
return compositeCmdReturn(_bulkItems);
}

// Load With Descendants:
if (itemPath[0u] == kUSDLoadWithDescendantsItem) {
for (auto& selItem : _bulkItems) {
UsdSceneItem::Ptr usdItem = std::dynamic_pointer_cast<UsdSceneItem>(selItem);
const UsdLoadPolicy policy = (itemPath[0u] == kUSDLoadWithDescendantsItem)
? UsdLoadWithDescendants
: UsdLoadWithoutDescendants;
if (usdItem) {
auto cmd = std::make_shared<UsdUndoLoadPayloadCommand>(usdItem->prim(), policy);
cmdList.emplace_back(cmd);
}
}
return compositeCmdReturn(_bulkItems);
}

// Prim Visibility:
const bool makeVisible = itemPath[0u] == kUSDMakeVisibleItem;
const bool makeInvisible = itemPath[0u] == kUSDMakeInvisibleItem;
Expand Down
47 changes: 45 additions & 2 deletions test/lib/ufe/testContextOps.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import maya.api.OpenMaya as om

import ufe
import usdUfe

import os
import unittest
Expand Down Expand Up @@ -188,8 +189,8 @@ def testGetBulkItems(self):

# Not supported in bulk (from UsdContextOps).
self.assertNotIn('Load', contextItemStrings)
self.assertNotIn('Load with Descendants', contextItemStrings)
self.assertNotIn('Unload', contextItemStrings)
self.assertIn('Load with Descendants', contextItemStrings)
self.assertIn('Unload', contextItemStrings)
self.assertNotIn('Variant Sets', contextItemStrings)
self.assertNotIn('Add New Prim', contextItemStrings)

Expand Down Expand Up @@ -500,6 +501,48 @@ def testDoBulkOp(self):
# Since the context item is in the selection, we get a bulk context.
self.contextOps = ufe.ContextOps.contextOps(self.ball35Item)

# Test Bulk Unload and Load with Descendants
payloadFile = testUtils.getTestScene('twoSpheres', 'sphere.usda')

def addPayLoads(payloadFile, ballPrims):
for ballPrim in ballPrims.values():
cmd = usdUfe.AddPayloadCommand(ballPrim, payloadFile, True)
self.assertIsNotNone(cmd)

# Verify state after add payload
cmd.execute()
self.assertTrue(ballPrim.HasPayload())
self.assertTrue(ballPrim.IsLoaded())

def verifyBulkPrimPayload(ballPrims, ifLoaded):
for ballPrim in ballPrims.values():
self.assertEqual(ballPrim.IsLoaded(), ifLoaded)

addPayLoads(payloadFile, ballPrims)

# Unload
cmd = self.contextOps.doOpCmd(['Unload'])
self.assertIsNotNone(cmd)
self.assertIsInstance(cmd, ufe.CompositeUndoableCommand)

ufeCmd.execute(cmd)
verifyBulkPrimPayload(ballPrims, False)
cmds.undo()
verifyBulkPrimPayload(ballPrims, True)

# Load with Descendants
# Unload the payloads first, using the unload command
ufeCmd.execute(cmd)
cmd = self.contextOps.doOpCmd(['Load with Descendants'])
self.assertIsNotNone(cmd)
self.assertIsInstance(cmd, ufe.CompositeUndoableCommand)

ufeCmd.execute(cmd)
verifyBulkPrimPayload(ballPrims, True)
cmds.undo()
verifyBulkPrimPayload(ballPrims, False)


# Change visility, undo/redo.
cmd = self.contextOps.doOpCmd(['Make Invisible'])
self.assertIsNotNone(cmd)
Expand Down