Skip to content

Commit 775d5de

Browse files
authored
Merge pull request #4036 from dj-mcg/pr/Invalidate_Subtree_on_Prim_Delete
Update change processing code
2 parents 1e26e8b + d959c05 commit 775d5de

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

lib/usdUfe/ufe/StagesSubject.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,27 @@ void StagesSubject::stageChanged(
528528
Ufe::SceneItem::Ptr sceneItem = Ufe::Hierarchy::createItem(ufePath);
529529
if (!sceneItem || InAddOrDeleteOperation::inAddOrDeleteOperation()) {
530530
sendObjectDestroyed(ufePath);
531+
532+
// If we are not in an add or delete operation, and a prim is
533+
// removed, we need to trigger a subtree invalidation. This is
534+
// necessary in order to prevent stale items from being kept in
535+
// the global selection set.
536+
// Note: at the point of this notif the prim is not valid anymore
537+
// and thus we cannot create a scene item to simply remove
538+
// the item from selection list.
539+
if (!InAddOrDeleteOperation::inAddOrDeleteOperation()) {
540+
auto parentPath = changedPath.GetParentPath();
541+
const auto parentUfePath = parentPath == SdfPath::AbsoluteRootPath()
542+
? stagePath(sender)
543+
: stagePath(sender)
544+
+ Ufe::PathSegment(
545+
parentPath.GetString(), UsdUfe::getUsdRunTimeId(), '/');
546+
547+
auto parentItem = Ufe::Hierarchy::createItem(parentUfePath);
548+
if (parentItem) {
549+
sendSubtreeInvalidate(parentItem);
550+
}
551+
}
531552
} else {
532553
sendSubtreeInvalidate(sceneItem);
533554
}

test/lib/ufe/testSelection.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def testMayaSelectAddFirst(self):
307307
for sel, expected in zip(globalSn, reversedItems):
308308
self.assertEqual(sel, expected)
309309

310-
@unittest.skipUnless(mayaUtils.mayaMajorVersion() >= 2023, 'Requires Maya fixes only avaiable in Maya 2023 or greater.')
310+
@unittest.skipUnless(mayaUtils.mayaMajorVersion() >= 2023, 'Requires Maya fixes only available in Maya 2023 or greater.')
311311
def testMayaSelectMuteLayer(self):
312312
'''Stale selection items must be removed on mute layer.'''
313313

@@ -382,6 +382,37 @@ def testMayaSelectMuteLayer(self):
382382

383383
self.assertTrue(sn.empty())
384384

385+
@unittest.skipUnless(mayaUtils.mayaMajorVersion() >= 2023, 'Requires Maya fixes only available in Maya 2023 or greater.')
386+
def testMayaSelectRemoveSelectedPrim(self):
387+
'''Stale selection items must be removed when a prim is deleted'''
388+
389+
# Create new stage
390+
import mayaUsd_createStageWithNewLayer
391+
proxyShapePathStr = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()
392+
proxyShapePath = ufe.PathString.path(proxyShapePathStr)
393+
proxyShapeItem = ufe.Hierarchy.createItem(proxyShapePath)
394+
proxyShapeContextOps = ufe.ContextOps.contextOps(proxyShapeItem)
395+
stage = mayaUsd.lib.GetPrim(proxyShapePathStr).GetStage()
396+
397+
# Create a prim that we will delete
398+
proxyShapeContextOps.doOp(['Add New Prim', 'Capsule'])
399+
400+
capsulePathStr = '%s,/Capsule1' % proxyShapePathStr
401+
capsulePath = ufe.PathString.path(capsulePathStr)
402+
capsuleItem = ufe.Hierarchy.createItem(capsulePath)
403+
404+
# Select the prim. When the prim is removed from the stage the prim
405+
# should be removed from the global selection
406+
sn = ufe.GlobalSelection.get()
407+
sn.clear()
408+
sn.append(capsuleItem)
409+
self.assertTrue(sn.contains(capsulePath))
410+
411+
stage.RemovePrim("/Capsule1")
412+
413+
# Should be nothing on the selection list.
414+
self.assertTrue(sn.empty())
415+
385416
@unittest.skipUnless(mayaUtils.mayaMajorVersion() >= 2023, 'Requires Maya fixes only available in Maya 2023 or greater.')
386417
def testMayaSelectSwitchVariant(self):
387418
'''Stale selection items must be removed on variant switch.'''

0 commit comments

Comments
 (0)