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-266 Fixed bad USD/UFE notifications #3278

Merged
merged 3 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
14 changes: 11 additions & 3 deletions lib/usdUfe/ufe/StagesSubject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,11 +452,19 @@ void StagesSubject::stageChanged(
sendObjectAdd(sceneItem);
sentNotif = true;
break;
} else if (
}
// Note : Do nothing here with didRemoveInertPrim and didRemoveNonInertPrim.
// Indeed, we can get these if prim specs are removed from some layers, but it
// does not mean that the prim is not longer in the composed stage. If the prim
// was actually gone, we would either get an invalid prim (in which case we
// would not even get here, and would send a object destroyed" notif in the else
// bellow), or we would fall into the "HasInfoChange : Active" case bellow. If
// nothing else sends a notif in the loop (typically via the info change :
// active) we do not want to send the fallback notif, so act as if a notif was
// sent.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Note : Do nothing here with didRemoveInertPrim and didRemoveNonInertPrim.
// Indeed, we can get these if prim specs are removed from some layers, but it
// does not mean that the prim is not longer in the composed stage. If the prim
// was actually gone, we would either get an invalid prim (in which case we
// would not even get here, and would send a object destroyed" notif in the else
// bellow), or we would fall into the "HasInfoChange : Active" case bellow. If
// nothing else sends a notif in the loop (typically via the info change :
// active) we do not want to send the fallback notif, so act as if a notif was
// sent.
// Note : Do nothing here with didRemoveInertPrim and didRemoveNonInertPrim.
// Indeed, we can get these if prim specs are removed from some layers, but it
// does not mean that the prim is no longer in the composed stage. If the prim
// was actually gone, we would either get an invalid prim (in which case we
// would not even get here, and would send a object destroyed" notif in the else
// below), or we would fall into the "HasInfoChange : Active" case below. If
// nothing else sends a notif in the loop (typically via the info change :
// active) we do not want to send the fallback notif, so act as if a notif was
// sent.

Minor typos. If you add only this commit (changing just the comment) then there is no need to re-run the preflight.

else if (
entry->flags.didRemoveInertPrim || entry->flags.didRemoveNonInertPrim) {
sendObjectPostDelete(sceneItem);
sentNotif = true;
break;
seando-adsk marked this conversation as resolved.
Show resolved Hide resolved
}

// Special case for "active" metadata.
Expand Down
7 changes: 6 additions & 1 deletion lib/usdUfe/ufe/UsdUndoAddNewPrimCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,12 @@ UsdUndoAddNewPrimCommand::Ptr UsdUndoAddNewPrimCommand::create(
Ufe::Selection getNewSelectionFromCommand(const UsdUndoAddNewPrimCommand& cmd)
{
Ufe::Selection newSelection;
newSelection.append(Ufe::Hierarchy::createItem(cmd.newUfePath()));
const auto newItem = Ufe::Hierarchy::createItem(cmd.newUfePath());
// The add operation may have failed (for example, if attempting to edit instance proxies).
// Appending a null item throws an exception, which we dont want in this case.
if (newItem) {
newSelection.append(Ufe::Hierarchy::createItem(cmd.newUfePath()));
}
return newSelection;
}

Expand Down
4 changes: 2 additions & 2 deletions test/lib/ufe/testDeleteCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,10 @@ def testDeleteRestrictionHierarchyWithChildrenInSessionLayer(self):
stage.DefinePrim('/TreeBase/newChild', 'Xform')
stage.SetEditTarget(stage.GetRootLayer())

# delete two USD prims and Maya's shape
# Delete the /TreeBase prim, at the usd root.
ufeObs.reset()
cmds.delete('|Tree_usd|Tree_usdShape,/TreeBase')
self.assertEqual(ufeObs.nbDeleteNotif() , 2)
self.assertEqual(ufeObs.nbDeleteNotif() , 1)
self.assertFalse(stage.GetPrimAtPath('/TreeBase'))
self.assertFalse(stage.GetPrimAtPath('/TreeBase/leavesXform/leaves'))
self.assertFalse(stage.GetPrimAtPath('/TreeBase/trunk'))
Expand Down
46 changes: 45 additions & 1 deletion test/lib/ufe/testObservableScene.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@
import fixturesUtils

from maya import standalone
from maya import cmds
import mayaUtils

from pxr import Usd
import ufe

from mayaUsd import lib as mayaUsdLib

import os
import sys
import unittest
Expand Down Expand Up @@ -58,10 +63,15 @@ def notifications(self):
return [self.add, self.delete, self.pathChange, self.subtreeInvalidate, self.composite]

class UFEObservableSceneTest(unittest.TestCase):


pluginsLoaded = False

@classmethod
def setUpClass(cls):
fixturesUtils.readOnlySetUpClass(__file__, loadPlugin=False)

if not cls.pluginsLoaded:
cls.pluginsLoaded = mayaUtils.isMayaUsdPluginLoaded()

@classmethod
def tearDownClass(cls):
Expand Down Expand Up @@ -120,6 +130,40 @@ def testObservableScene(self):
# ufe.Scene.notify(ufe.ObjectAdd(itemB))
# ufe.Scene.notify(ufe.ObjectAdd(itemC))

def testInertPrimAddRemoveNotifications(self):

cmds.file(new=True, force=True)

usdFilePath = cmds.internalVar(utd=1) + '/testInertPrimAddRemove.usda'
stage = Usd.Stage.CreateNew(usdFilePath)

fooPath = '/foo'
stage.DefinePrim(fooPath, 'Xform')

# Save out the file, and bring it back into Maya under a proxy shape.
stage.GetRootLayer().Save()
proxyShape = cmds.createNode('mayaUsdProxyShape')
cmds.setAttr('mayaUsdProxyShape1.filePath', usdFilePath, type='string')

stage = mayaUsdLib.GetPrim(proxyShape).GetStage()

# Work on the session layer, to easily clear changes.
sessionLayer = stage.GetSessionLayer()
stage.SetEditTarget(sessionLayer)

snObs = TestObserver()
ufe.Scene.addObserver(snObs)

# Deactivate the prim...expect object delete notif.
fooPrim = stage.GetPrimAtPath(fooPath)
fooPrim.SetActive(False)
self.checkNotifications(snObs, [0,1,0,0,0,0])

# Clear session layer, expect an object added notif, as the inactive
# state was cleared from the session layer.
sessionLayer.Clear()
self.checkNotifications(snObs, [1,1,0,0,0,0])


if __name__ == '__main__':
unittest.main(verbosity=2)
Loading