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-124484: Display Layers #2524

Merged
merged 1 commit into from
Aug 4, 2022
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
10 changes: 8 additions & 2 deletions test/lib/mayaUsd/fileio/testDisplayLayerSaveRestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ def testDisplayLayerSaveAndRestore(self):
if 'ufeMembers' not in cmds.listAttr('layer1'):
self.skipTest('Maya DisplayLayer does not support saving/restoring Ufe (non-Maya) members.')

# editDisplayLayerMembers became Ufe opt-in
kwArgs = {'fn' : True}
cmdHelp = cmds.help('editDisplayLayerMembers')
if '-ufeObjects' in cmdHelp:
kwArgs['ufeObjects'] = True

# Create some objects to add to layer.
cmds.CreatePolygonSphere()
cmds.CreatePolygonCube()
Expand All @@ -67,7 +73,7 @@ def testDisplayLayerSaveAndRestore(self):
cmds.editDisplayLayerMembers('layer1', '|pSphere1', '|stage1|stageShape1,/Sphere1', noRecurse=True)

# Verify they are in layer.
layerObjs = cmds.editDisplayLayerMembers('layer1', query=True, fn=True)
layerObjs = cmds.editDisplayLayerMembers('layer1', query=True, **kwArgs)
self.assertTrue('|pSphere1' in layerObjs)
self.assertTrue('|stage1|stageShape1,/Sphere1' in layerObjs)

Expand All @@ -81,7 +87,7 @@ def testDisplayLayerSaveAndRestore(self):
cmds.file(tempMayaFile, open=True)

# Verify the two objects (Maya and non-Maya are in layer).
layerObjs = cmds.editDisplayLayerMembers('layer1', query=True, fn=True)
layerObjs = cmds.editDisplayLayerMembers('layer1', query=True, **kwArgs)
self.assertTrue('|pSphere1' in layerObjs)
self.assertTrue('|stage1|stageShape1,/Sphere1' in layerObjs)

Expand Down
65 changes: 47 additions & 18 deletions test/lib/ufe/testDisplayLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ def setUp(self):
mo = om.MFnDisplayLayerManager.currentDisplayLayerManager() if mayaUtils.ufeSupportFixLevel() >= 2 else om.MFnDisplayLayerManager().currentDisplayLayerManager()
self.dlm = om.MFnDisplayLayerManager(mo)

# editDisplayLayerMembers became Ufe opt-in
self.kwArgsEditDisplayLayerMembers = {'fn' : True}
cmdHelp = cmds.help('editDisplayLayerMembers')
if '-ufeObjects' in cmdHelp:
self.kwArgsEditDisplayLayerMembers['ufeObjects'] = True

def displayLayer(self, layer_name):
displayLayerObjs = self.dlm.getAllDisplayLayers()
for dl in displayLayerObjs:
Expand All @@ -89,6 +95,29 @@ def _testLayerFromPath(self, pathStr, layerName):
self.assertTrue(layer.contains(pathStr))
self.assertTrue(pathStr in layer.getMembers().getSelectionStrings())

def testDisplayLayerQuery(self):
cmdHelp = cmds.help('editDisplayLayerMembers')
if '-ufeObjects' not in cmdHelp:
self.skipTest('Requires ufeObjects flag in editDisplayLayerMembers command.')

# First create a layer and add some Maya objects and USD prims to it.
cmds.createDisplayLayer(name='layer1', number=1, empty=True)
cmds.CreatePolygonSphere()
psPathStr = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()
stage = mayaUsd.lib.GetPrim(psPathStr).GetStage()
stage.DefinePrim('/Sphere1', 'Sphere')
cmds.editDisplayLayerMembers(self.LAYER1, '|pSphere1', self.SPHERE1, noRecurse=True)

# Query the display layer members (default) without ufe.
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, fn=True)
self.assertTrue('|pSphere1' in layerObjs)
self.assertFalse(self.SPHERE1 in layerObjs)

# Then query the display layer members with ufe.
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, fn=True, ufeObjects=True)
self.assertTrue('|pSphere1' in layerObjs)
self.assertTrue(self.SPHERE1 in layerObjs)

@unittest.skipUnless(mayaUtils.ufeSupportFixLevel() >= 2, "Requires Display Layer Ufe item rename fix.")
def testDisplayLayerItemRename(self):
# First create Display Layer and add some prims to it.
Expand All @@ -104,7 +133,7 @@ def testDisplayLayerItemRename(self):
cmds.editDisplayLayerMembers(self.LAYER1, self.SPHERE1, self.CUBE1, noRecurse=True)

# Verify they are in layer.
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, fn=True)
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, **self.kwArgsEditDisplayLayerMembers)
self.assertTrue(self.CUBE1 in layerObjs)
self.assertTrue(self.SPHERE1 in layerObjs)
self.assertFalse(self.NEW_SPHERE1 in layerObjs)
Expand All @@ -118,7 +147,7 @@ def testDisplayLayerItemRename(self):
# Rename the Sphere and make sure it is still in the layer.
cmds.select(self.SPHERE1, replace=True)
cmds.rename('NewSphere1')
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, fn=True)
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, **self.kwArgsEditDisplayLayerMembers)
self.assertTrue(self.CUBE1 in layerObjs)
self.assertFalse(self.SPHERE1 in layerObjs)
self.assertTrue(self.NEW_SPHERE1 in layerObjs)
Expand All @@ -130,7 +159,7 @@ def testDisplayLayerItemRename(self):

# Undo the rename.
cmds.undo()
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, fn=True)
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, **self.kwArgsEditDisplayLayerMembers)
self.assertTrue(self.CUBE1 in layerObjs)
self.assertTrue(self.SPHERE1 in layerObjs)
self.assertFalse(self.NEW_SPHERE1 in layerObjs)
Expand All @@ -142,7 +171,7 @@ def testDisplayLayerItemRename(self):

# Redo the rename.
cmds.redo()
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, fn=True)
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, **self.kwArgsEditDisplayLayerMembers)
self.assertTrue(self.CUBE1 in layerObjs)
self.assertFalse(self.SPHERE1 in layerObjs)
self.assertTrue(self.NEW_SPHERE1 in layerObjs)
Expand All @@ -169,13 +198,13 @@ def testDisplayLayerItemRenameParent(self):
# Rename the Xform1 (parent of Sphere1) and make sure Sphere1 is still in the layer.
cmds.select(self.XFORM1, replace=True)
cmds.rename('NewXform1')
layerObjs = cmds.editDisplayLayerMembers(self.DEFAULT_LAYER, query=True, fn=True)
layerObjs = cmds.editDisplayLayerMembers(self.DEFAULT_LAYER, query=True, **self.kwArgsEditDisplayLayerMembers)
self.assertFalse(self.XFORM1 in layerObjs)
self.assertTrue(self.NEW_XFORM1 in layerObjs)
self.assertFalse(self.XFORM1_SPHERE1 in layerObjs)
self.assertFalse(self.NEW_XFORM1_SPHERE1 in layerObjs)

layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, fn=True)
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, **self.kwArgsEditDisplayLayerMembers)
self.assertFalse(self.XFORM1 in layerObjs)
self.assertFalse(self.NEW_XFORM1 in layerObjs)
self.assertFalse(self.XFORM1_SPHERE1 in layerObjs)
Expand All @@ -199,7 +228,7 @@ def testDisplayLayerItemReparent(self):
cmds.editDisplayLayerMembers(self.LAYER1, self.SPHERE1, self.CUBE1, noRecurse=True)

# Verify they are in layer.
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, fn=True)
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, **self.kwArgsEditDisplayLayerMembers)
self.assertTrue(self.CUBE1 in layerObjs)
self.assertTrue(self.SPHERE1 in layerObjs)
self.assertFalse(self.XFORM1 in layerObjs)
Expand All @@ -210,7 +239,7 @@ def testDisplayLayerItemReparent(self):

# Reparent the Sphere and make sure it is still in the layer.
cmds.parent(self.SPHERE1, self.XFORM1)
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, fn=True)
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, **self.kwArgsEditDisplayLayerMembers)
self.assertTrue(self.CUBE1 in layerObjs)
self.assertTrue(self.XFORM1_SPHERE1 in layerObjs)
self.assertFalse(self.XFORM1 in layerObjs)
Expand All @@ -221,7 +250,7 @@ def testDisplayLayerItemReparent(self):

# Undo the reparent.
cmds.undo()
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, fn=True)
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, **self.kwArgsEditDisplayLayerMembers)
self.assertTrue(self.CUBE1 in layerObjs)
self.assertTrue(self.SPHERE1 in layerObjs)
self.assertFalse(self.XFORM1 in layerObjs)
Expand All @@ -232,7 +261,7 @@ def testDisplayLayerItemReparent(self):

# Redo the reparent.
cmds.redo()
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, fn=True)
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, **self.kwArgsEditDisplayLayerMembers)
self.assertTrue(self.CUBE1 in layerObjs)
self.assertTrue(self.XFORM1_SPHERE1 in layerObjs)
self.assertFalse(self.XFORM1 in layerObjs)
Expand All @@ -255,7 +284,7 @@ def testDisplayLayerItemDelete(self):
cmds.editDisplayLayerMembers(self.LAYER1, self.SPHERE1, self.CUBE1, noRecurse=True)

# Verify they are in layer.
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, fn=True)
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, **self.kwArgsEditDisplayLayerMembers)
self.assertTrue(self.CUBE1 in layerObjs)
self.assertTrue(self.SPHERE1 in layerObjs)
self.assertFalse(self.NEW_SPHERE1 in layerObjs)
Expand All @@ -265,7 +294,7 @@ def testDisplayLayerItemDelete(self):

# Delete the Sphere and make sure it is removed from the layer.
cmds.delete(self.SPHERE1)
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, fn=True)
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, **self.kwArgsEditDisplayLayerMembers)
self.assertTrue(self.CUBE1 in layerObjs)
self.assertFalse(self.SPHERE1 in layerObjs)

Expand Down Expand Up @@ -301,15 +330,15 @@ def testDisplayLayerClear(self):
# Verify that both prims are in layer.
# Note: the editDisplayLayerMembers command only returns valid prims.
# But the MFnDisplayLayer will return all prims (including invalid ones).
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, fn=True)
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, **self.kwArgsEditDisplayLayerMembers)
self.assertTrue(self.CUBE1 in layerObjs)
self.assertFalse(self.INVALID_PRIM in layerObjs)
self._testLayerFromPath(self.CUBE1, self.LAYER1)
self._testLayerFromPath(self.INVALID_PRIM, self.LAYER1)

# Now clear the layer and make sure both prims (valid and invalid) got removed.
cmds.editDisplayLayerMembers(self.LAYER1, clear=True)
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, fn=True)
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, **self.kwArgsEditDisplayLayerMembers)
self.assertIsNone(layerObjs)
self.assertFalse(layer1.contains(self.CUBE1))
self.assertFalse(layer1.contains(self.INVALID_PRIM))
Expand All @@ -333,7 +362,7 @@ def testDisplayLayerSubtreeInvalidate(self):
# Create a display layer and add the Sphere1 prim (currently the one under the Xform1).
cmds.createDisplayLayer(name=self.LAYER1, number=1, empty=True)
cmds.editDisplayLayerMembers(self.LAYER1, self.XFORM1_SPHERE1, noRecurse=True)
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, fn=True)
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, **self.kwArgsEditDisplayLayerMembers)
self.assertFalse(self.XFORM1_CUBE1 in layerObjs)
self.assertTrue(self.XFORM1_SPHERE1 in layerObjs)

Expand All @@ -347,7 +376,7 @@ def testDisplayLayerSubtreeInvalidate(self):

# The Cube1 should not be in the display layer.
# The Sphere1 prim should still be in the display layer, but as an invalid path.
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, fn=True)
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, **self.kwArgsEditDisplayLayerMembers)
self.assertIsNone(layerObjs)
self._testLayerFromPath(self.XFORM1_SPHERE1, self.LAYER1)

Expand All @@ -356,7 +385,7 @@ def testDisplayLayerSubtreeInvalidate(self):
ufeCmd.execute(cmd)

# The Sphere1 should be back (as valid path) in the display layer.
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, fn=True)
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, **self.kwArgsEditDisplayLayerMembers)
self.assertFalse(self.XFORM1_CUBE1 in layerObjs)
self.assertTrue(self.XFORM1_SPHERE1 in layerObjs)
self._testLayerFromPath(self.XFORM1_SPHERE1, self.LAYER1)
Expand All @@ -368,7 +397,7 @@ def testDisplayLayerSubtreeInvalidate(self):
model.SetKind(Kind.Tokens.group)

# The Sphere1 should still be in the display layer as valid path.
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, fn=True)
layerObjs = cmds.editDisplayLayerMembers(self.LAYER1, query=True, **self.kwArgsEditDisplayLayerMembers)
self.assertFalse(self.XFORM1_CUBE1 in layerObjs)
self.assertTrue(self.XFORM1_SPHERE1 in layerObjs)
self._testLayerFromPath(self.XFORM1_SPHERE1, self.LAYER1)