-
Notifications
You must be signed in to change notification settings - Fork 203
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-107600 - UFE/MEL - make select command UFE aware #921
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,26 +53,19 @@ def setUp(self): | |
# hierarchy and the USD hierarchy. | ||
mayaUtils.openTestScene("parentCmd", "simpleSceneMayaPlusUSD_TRS.ma") | ||
|
||
# Clear selection to start off | ||
cmds.select(clear=True) | ||
|
||
def runTestSelection(self, selectCmd): | ||
'''Run the replace selection test, using the argument command to | ||
replace the selection with a single scene item.''' | ||
|
||
# Create multiple scene items. We will alternate between selecting a | ||
# Maya item and a USD item, 3 items each data model, one item at a | ||
# time, so we select 6 different items, one at a time. | ||
shapeSegment = mayaUtils.createUfePathSegment( | ||
"|world|mayaUsdProxy1|mayaUsdProxyShape1") | ||
"|mayaUsdProxy1|mayaUsdProxyShape1") | ||
ufeNames = ["cubeXform", "cylinderXform", "sphereXform"] | ||
mayaNames = ["pCube1", "pCylinder1", "pSphere1"] | ||
usdPaths = [] | ||
for n in ["/" + o for o in ufeNames]: | ||
usdPaths.append(ufe.Path( | ||
[shapeSegment, usdUtils.createUfePathSegment(n)])) | ||
mayaPaths = [] | ||
for n in ["|world|" + o for o in mayaNames]: | ||
for n in ["|" + o for o in mayaNames]: | ||
mayaPaths.append(ufe.Path(mayaUtils.createUfePathSegment(n))) | ||
|
||
# Create a list of paths by alternating USD objects and Maya objects | ||
|
@@ -81,15 +74,22 @@ def runTestSelection(self, selectCmd): | |
paths = [j for i in zipped for j in i] | ||
|
||
# Create items for all paths. | ||
items = [ufe.Hierarchy.createItem(p) for p in paths] | ||
self.items = [ufe.Hierarchy.createItem(p) for p in paths] | ||
|
||
# Clear selection to start off | ||
cmds.select(clear=True) | ||
|
||
def runTestSelection(self, selectCmd): | ||
'''Run the replace selection test, using the argument command to | ||
replace the selection with a single scene item.''' | ||
|
||
# Clear the selection. | ||
globalSn = ufe.GlobalSelection.get() | ||
globalSn.clear() | ||
self.assertTrue(globalSn.empty()) | ||
|
||
# Select all items in turn. | ||
for item in items: | ||
for item in self.items: | ||
selectCmd(item) | ||
|
||
# Item in the selection should be the last item in our list. | ||
|
@@ -98,12 +98,12 @@ def snFront(sn): | |
return next(iter(sn)) if \ | ||
ufe.VersionInfo.getMajorVersion() == 1 else sn.front() | ||
|
||
self.assertEqual(snFront(globalSn), items[-1]) | ||
self.assertEqual(snFront(globalSn), self.items[-1]) | ||
|
||
# Check undo. For this purpose, re-create the list of items in reverse | ||
# order. Because we're already at the last item, we skip the last one | ||
# (i.e. last item is -1, so start at -2, and increment by -1). | ||
rItems = items[-2::-1] | ||
rItems = self.items[-2::-1] | ||
|
||
# Undo until the first element, checking the selection as we go. | ||
for i in rItems: | ||
|
@@ -112,7 +112,7 @@ def snFront(sn): | |
self.assertEqual(snFront(globalSn), i) | ||
|
||
# Check redo. | ||
fItems = items[1:] | ||
fItems = self.items[1:] | ||
|
||
# Redo until the last element, checking the selection as we go. | ||
for i in fItems: | ||
|
@@ -127,18 +127,140 @@ def selectCmd(item): | |
ufeSelectCmd.replaceWith(sn) | ||
self.runTestSelection(selectCmd) | ||
|
||
@unittest.skipUnless(ufeUtils.ufeFeatureSetVersion() >= 2, 'testMayaSelect only available in UFE v2 or greater.') | ||
@unittest.skipUnless(((ufeUtils.ufeFeatureSetVersion() >= 2) and (mayaUtils.previewReleaseVersion() >= 121)), 'testMayaSelect only available in UFE v2 or greater and Maya Preview Release 121 or later.') | ||
def testMayaSelect(self): | ||
# At time of writing (17-May-2020), Maya select command does not | ||
# accept UFE path strings. Use Maya select for Maya scene items, | ||
# and UFE select for non-Maya scene items. | ||
# Maya PR 121 now has support for UFE path string in select command. | ||
def selectCmd(item): | ||
if item.runTimeId() == 1: | ||
# Single path segment. Simply pop the |world head of path. | ||
p = str(item.path().popHead()) | ||
cmds.select(p) | ||
else: | ||
sn = ufe.Selection() | ||
sn.append(item) | ||
ufeSelectCmd.replaceWith(sn) | ||
cmds.select(ufe.PathString.string(item.path())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to use ufeSelectCmd - just use Maya select directly with path string. |
||
self.runTestSelection(selectCmd) | ||
|
||
@unittest.skipUnless(((ufeUtils.ufeFeatureSetVersion() >= 2) and (mayaUtils.previewReleaseVersion() >= 121)), 'testMayaSelectFlags only available in UFE v2 or greater and Maya Preview Release 121 or later.') | ||
def testMayaSelectFlags(self): | ||
Comment on lines
+137
to
+138
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New select test that tests all the various select command flags that are supported by UFE now. |
||
# Maya PR 121 now has support for UFE path string in select command. | ||
|
||
# Clear the selection. | ||
globalSn = ufe.GlobalSelection.get() | ||
globalSn.clear() | ||
self.assertTrue(globalSn.empty()) | ||
|
||
# Incrementally add to the selection all items in turn. | ||
# Also testing undo/redo along the way. | ||
cnt = 0 | ||
for item in self.items: | ||
cnt += 1 | ||
cmds.select(ufe.PathString.string(item.path()), add=True) | ||
self.assertEqual(cnt, len(globalSn)) | ||
self.assertTrue(globalSn.contains(item.path())) | ||
|
||
cmds.undo() | ||
self.assertEqual(cnt-1, len(globalSn)) | ||
self.assertFalse(globalSn.contains(item.path())) | ||
|
||
cmds.redo() | ||
self.assertEqual(cnt, len(globalSn)) | ||
self.assertTrue(globalSn.contains(item.path())) | ||
|
||
# Since we added all the items to the global selection, it | ||
# should have all of them. | ||
self.assertEqual(len(globalSn), len(self.items)) | ||
|
||
# Ensure the global selection order is the same as our item order. | ||
itemIt = iter(self.items) | ||
for selIt in globalSn: | ||
self.assertEqual(selIt, next(itemIt)) | ||
|
||
# Incrementally remove from the selection all items in turn. | ||
# Also testing undo/redo along the way. | ||
for item in self.items: | ||
cnt -= 1 | ||
cmds.select(ufe.PathString.string(item.path()), deselect=True) | ||
self.assertEqual(cnt, len(globalSn)) | ||
self.assertFalse(globalSn.contains(item.path())) | ||
|
||
cmds.undo() | ||
self.assertEqual(cnt+1, len(globalSn)) | ||
self.assertTrue(globalSn.contains(item.path())) | ||
|
||
cmds.redo() | ||
self.assertEqual(cnt, len(globalSn)) | ||
self.assertFalse(globalSn.contains(item.path())) | ||
|
||
# Since we removed all items from global selection it | ||
# should be empty now. | ||
self.assertTrue(globalSn.empty()) | ||
|
||
# Incrementally toggle selection state of all items in turn. | ||
# Since they all start unselected, they will toggle to selected. | ||
# Also testing undo/redo along the way. | ||
globalSn.clear() | ||
self.assertTrue(globalSn.empty()) | ||
cnt = 0 | ||
for item in self.items: | ||
cnt += 1 | ||
cmds.select(ufe.PathString.string(item.path()), toggle=True) | ||
self.assertEqual(cnt, len(globalSn)) | ||
self.assertTrue(globalSn.contains(item.path())) | ||
|
||
cmds.undo() | ||
self.assertEqual(cnt-1, len(globalSn)) | ||
self.assertFalse(globalSn.contains(item.path())) | ||
|
||
cmds.redo() | ||
self.assertEqual(cnt, len(globalSn)) | ||
self.assertTrue(globalSn.contains(item.path())) | ||
|
||
# Since we toggled each item to selected, we should have all | ||
# of them on the global selection. | ||
self.assertEqual(len(globalSn), len(self.items)) | ||
|
||
# Incrementally toggle selection state of all items in turn. | ||
# Since they all start selected, they will toggle to unselected. | ||
# Also testing undo/redo along the way. | ||
for item in self.items: | ||
cnt -= 1 | ||
cmds.select(ufe.PathString.string(item.path()), toggle=True) | ||
self.assertEqual(cnt, len(globalSn)) | ||
self.assertFalse(globalSn.contains(item.path())) | ||
|
||
cmds.undo() | ||
self.assertEqual(cnt+1, len(globalSn)) | ||
self.assertTrue(globalSn.contains(item.path())) | ||
|
||
cmds.redo() | ||
self.assertEqual(cnt, len(globalSn)) | ||
self.assertFalse(globalSn.contains(item.path())) | ||
|
||
# Since we toggled all items to unselected, the global selection | ||
# should be empty now. | ||
self.assertTrue(globalSn.empty()) | ||
|
||
# Select all the items at once, replacing the existing selection. | ||
# Also testing undo/redo. | ||
pathStrings = [ufe.PathString.string(i.path()) for i in self.items] | ||
cmds.select(*pathStrings, replace=True) | ||
self.assertEqual(len(globalSn), len(self.items)) | ||
|
||
# Ensure the global selection order is the same as our item order. | ||
itemIt = iter(self.items) | ||
for selIt in globalSn: | ||
self.assertEqual(selIt, next(itemIt)) | ||
|
||
cmds.undo() | ||
self.assertEqual(0, len(globalSn)) | ||
self.assertTrue(globalSn.empty()) | ||
|
||
cmds.redo() | ||
self.assertEqual(len(globalSn), len(self.items)) | ||
|
||
# Ensure the global selection order is the same as our item order. | ||
itemIt = iter(self.items) | ||
for selIt in globalSn: | ||
self.assertEqual(selIt, next(itemIt)) | ||
|
||
# With all items selected (and in same order as item order) | ||
# "select -add" the first item which will move it to the end. | ||
first = self.items[0] | ||
self.assertEqual(globalSn.front(), first) | ||
cmds.select(ufe.PathString.string(first.path()), add=True) | ||
self.assertTrue(globalSn.contains(first.path())) | ||
self.assertEqual(globalSn.back(), first) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the block above from the test into the setUp() method so it will be called by each test (including my new one). I store the created scene items.