-
Notifications
You must be signed in to change notification settings - Fork 201
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-104215: improve renaming restriction on prim objects #475
Changes from 2 commits
c9100f7
54166d2
8f8295f
e21a130
4c67b69
97996bb
581932b
761143d
d58a028
20be9ac
ae2a7e0
bb1da2e
c4f247a
a45779c
b207895
890372d
a305af9
610f2ce
80aa35e
3cf2acc
7bb77b3
24001e3
7e66d41
22d6fc9
df3ff44
67fd431
7e8bef6
d84d82f
5d81f6c
ade83fa
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 |
---|---|---|
|
@@ -98,49 +98,66 @@ def assertStageAndPrimAccess( | |
def testRename(self): | ||
'''Rename USD node.''' | ||
|
||
# Select a USD object. | ||
ball35Path = ufe.Path([ | ||
mayaUtils.createUfePathSegment( | ||
"|world|transform1|proxyShape1"), | ||
usdUtils.createUfePathSegment("/Room_set/Props/Ball_35")]) | ||
ball35Item = ufe.Hierarchy.createItem(ball35Path) | ||
ball35Hierarchy = ufe.Hierarchy.hierarchy(ball35Item) | ||
propsItem = ball35Hierarchy.parent() | ||
# open usdCylinder.ma scene in test-samples | ||
mayaUtils.openCylinderScene() | ||
|
||
# clear selection to start off | ||
cmds.select(clear=True) | ||
|
||
# select a USD object. | ||
mayaPathSegment = mayaUtils.createUfePathSegment('|world|mayaUsdTransform|shape') | ||
usdPathSegment = usdUtils.createUfePathSegment('/pCylinder1') | ||
cylinderPath = ufe.Path([mayaPathSegment, usdPathSegment]) | ||
cylinderItem = ufe.Hierarchy.createItem(cylinderPath) | ||
cylinderHierarchy = ufe.Hierarchy.hierarchy(cylinderItem) | ||
propsItem = cylinderHierarchy.parent() | ||
|
||
propsHierarchy = ufe.Hierarchy.hierarchy(propsItem) | ||
propsChildrenPre = propsHierarchy.children() | ||
|
||
ufe.GlobalSelection.get().append(ball35Item) | ||
ufe.GlobalSelection.get().append(cylinderItem) | ||
|
||
# get the USD stage | ||
stage = mayaUsd.ufe.getStage(str(mayaPathSegment)) | ||
|
||
newName = 'Ball_35_Renamed' | ||
# check GetLayerStack behavior | ||
self.assertEqual(stage.GetLayerStack()[0], stage.GetSessionLayer()) | ||
self.assertEqual(stage.GetEditTarget().GetLayer(), stage.GetSessionLayer()) | ||
|
||
# set the edit target to the root layer | ||
stage.SetEditTarget(stage.GetRootLayer()) | ||
self.assertEqual(stage.GetEditTarget().GetLayer(), stage.GetRootLayer()) | ||
|
||
# rename | ||
newName = 'pCylinder1_Renamed' | ||
cmds.rename(newName) | ||
|
||
# The renamed item is in the selection. | ||
snIter = iter(ufe.GlobalSelection.get()) | ||
ball35RenItem = next(snIter) | ||
ball35RenName = str(ball35RenItem.path().back()) | ||
pCylinder1Item = next(snIter) | ||
pCylinder1RenName = str(pCylinder1Item.path().back()) | ||
|
||
self.assertEqual(ball35RenName, newName) | ||
self.assertEqual(pCylinder1RenName, newName) | ||
|
||
# MAYA-92350: should not need to re-bind hierarchy interface objects | ||
# with their item. | ||
propsHierarchy = ufe.Hierarchy.hierarchy(propsItem) | ||
propsChildren = propsHierarchy.children() | ||
|
||
self.assertEqual(len(propsChildren), len(propsChildrenPre)) | ||
self.assertIn(ball35RenItem, propsChildren) | ||
self.assertIn(pCylinder1Item, propsChildren) | ||
|
||
cmds.undo() | ||
|
||
def childrenNames(children): | ||
return [str(child.path().back()) for child in children] | ||
return [str(child.path().back()) for child in children] | ||
|
||
propsHierarchy = ufe.Hierarchy.hierarchy(propsItem) | ||
propsChildren = propsHierarchy.children() | ||
propsChildrenNames = childrenNames(propsChildren) | ||
|
||
self.assertNotIn(ball35RenName, propsChildrenNames) | ||
self.assertIn('Ball_35', propsChildrenNames) | ||
self.assertNotIn(pCylinder1RenName, propsChildrenNames) | ||
self.assertIn('pCylinder1', propsChildrenNames) | ||
self.assertEqual(len(propsChildren), len(propsChildrenPre)) | ||
|
||
cmds.redo() | ||
|
@@ -149,7 +166,52 @@ def childrenNames(children): | |
propsChildren = propsHierarchy.children() | ||
propsChildrenNames = childrenNames(propsChildren) | ||
|
||
self.assertIn(ball35RenName, propsChildrenNames) | ||
self.assertNotIn('Ball_35', propsChildrenNames) | ||
self.assertIn(pCylinder1RenName, propsChildrenNames) | ||
self.assertNotIn('pCylinder1', propsChildrenNames) | ||
self.assertEqual(len(propsChildren), len(propsChildrenPre)) | ||
ppt-adsk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def testRenameRestriction(self): | ||
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. How about "testRenameRestrictionSameLayerDef", or similar? 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. |
||
'''Restrict renaming USD node. Cannot rename a prim defined on another layer.''' | ||
|
||
# select a USD object. | ||
mayaPathSegment = mayaUtils.createUfePathSegment('|world|transform1|proxyShape1') | ||
usdPathSegment = usdUtils.createUfePathSegment('/Room_set/Props/Ball_35') | ||
ball35Path = ufe.Path([mayaPathSegment, usdPathSegment]) | ||
ball35Item = ufe.Hierarchy.createItem(ball35Path) | ||
|
||
ufe.GlobalSelection.get().append(ball35Item) | ||
|
||
# get the USD stage | ||
stage = mayaUsd.ufe.getStage(str(mayaPathSegment)) | ||
|
||
# check GetLayerStack behavior | ||
self.assertEqual(stage.GetLayerStack()[0], stage.GetSessionLayer()) | ||
self.assertEqual(stage.GetEditTarget().GetLayer(), stage.GetSessionLayer()) | ||
|
||
# expect the exception happens | ||
with self.assertRaises(RuntimeError): | ||
newName = 'Ball_35_Renamed' | ||
cmds.rename(newName) | ||
|
||
def testRenameRestriction2(self): | ||
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. How about "testRenameRestrictionOtherLayerOpinions", or similar? |
||
'''Restrict renaming USD node. Cannot rename a prim with definitions or opinions on other layers.''' | ||
|
||
# select a USD object. | ||
mayaPathSegment = mayaUtils.createUfePathSegment('|world|transform1|proxyShape1') | ||
usdPathSegment = usdUtils.createUfePathSegment('/Room_set/Props/Ball_35') | ||
ball35Path = ufe.Path([mayaPathSegment, usdPathSegment]) | ||
ball35Item = ufe.Hierarchy.createItem(ball35Path) | ||
|
||
ufe.GlobalSelection.get().append(ball35Item) | ||
|
||
# get the USD stage | ||
stage = mayaUsd.ufe.getStage(str(mayaPathSegment)) | ||
|
||
# set the edit target to Assembly_room_set.usda | ||
stage.SetEditTarget(stage.GetLayerStack()[2]) | ||
self.assertEqual(stage.GetEditTarget().GetLayer().GetDisplayName(), "Assembly_room_set.usda") | ||
|
||
# expect the exception happens | ||
with self.assertRaises(RuntimeError): | ||
newName = 'Ball_35_Renamed' | ||
cmds.rename(newName) | ||
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. @ppt-adsk I added two test cases for rename restriction operations:
If you think |
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.
We check here if the target layer has any opinions that affects selected prim. If it doesn't pass the check, we then find the possible target layer and append it's display name to the error message. Finally we throw a runtime_error message.