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-126141 allow creating prims in weaker layers. #2720

Merged
merged 1 commit into from
Nov 16, 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
6 changes: 0 additions & 6 deletions lib/mayaUsd/ufe/UsdUndoAddNewPrimCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ UsdUndoAddNewPrimCommand::UsdUndoAddNewPrimCommand(
_newUfePath = appendToPath(ufePath, newPrimName);
}

const bool allowStronger = true;
ufe::applyCommandRestriction(
usdSceneItem->prim(),
"add new [" + _newUfePath.back().string() + "] under ",
allowStronger);

// Build (and store) the usd path for the new prim with the unique name.
PXR_NS::SdfPath usdItemPath = usdSceneItem->prim().GetPath();
_primPath = usdItemPath.AppendChild(PXR_NS::TfToken(newPrimName));
Expand Down
4 changes: 4 additions & 0 deletions lib/mayaUsd/ufe/UsdUndoAddNewPrimCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ namespace MAYAUSD_NS_DEF {
namespace ufe {

//! \brief Undoable command for add new prim
//
// This command is not restricted: it is always possible to create a new
// prim even in weaker layer since the new prim, by the fact that it is new
// cannot have an already-existing opinon that would shadow it.
class MAYAUSD_CORE_PUBLIC UsdUndoAddNewPrimCommand : public Ufe::UndoableCommand
{
public:
Expand Down
97 changes: 97 additions & 0 deletions test/lib/ufe/testContextOps.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import mayaUtils
import usdUtils
import ufeUtils
import mayaUsd

from pxr import UsdGeom
from pxr import UsdShade
Expand Down Expand Up @@ -402,6 +403,102 @@ def testAddNewPrim(self):
self.assertEqual(ufeObs.nbAddNotif(), 2)
self.assertEqual(ufeObs.nbDeleteNotif(), 2)

def testAddNewPrimInWeakerLayer(self):
cmds.file(new=True, force=True)

# Create a proxy shape with empty stage to start with.
import mayaUsd_createStageWithNewLayer
proxyShape = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()

# Create our UFE notification observer
ufeObs = TestAddPrimObserver()
ufe.Scene.addObserver(ufeObs)

# Create a ContextOps interface for the proxy shape.
proxyShapePath = ufe.Path([mayaUtils.createUfePathSegment(proxyShape)])
proxyShapeItem = ufe.Hierarchy.createItem(proxyShapePath)
contextOps = ufe.ContextOps.contextOps(proxyShapeItem)

# Create a sub-layers SubLayerA.
stage = mayaUsd.lib.GetPrim(proxyShape).GetStage()
rootLayer = stage.GetRootLayer()
subLayerA = cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=False, addAnonymous="SubLayerA")[0]

# Add a new prim.
cmd = contextOps.doOpCmd(['Add New Prim', 'Xform'])
self.assertIsNotNone(cmd)
ufeObs.reset()
ufeCmd.execute(cmd)

# Ensure we got the correct UFE notifs.
self.assertEqual(ufeObs.nbAddNotif(), 1)
self.assertEqual(ufeObs.nbDeleteNotif(), 0)

# The proxy shape should now have a single UFE child item.
proxyShapehier = ufe.Hierarchy.hierarchy(proxyShapeItem)
self.assertTrue(proxyShapehier.hasChildren())
self.assertEqual(len(proxyShapehier.children()), 1)

# Add a new prim to the prim we just added.
cmds.pickWalk(d='down')

# Get the scene item from the UFE selection.
snIter = iter(ufe.GlobalSelection.get())
xformItem = next(snIter)

# Create a ContextOps interface for it.
contextOps = ufe.ContextOps.contextOps(xformItem)

# Add a new prim.
cmd = contextOps.doOpCmd(['Add New Prim', 'Xform'])
self.assertIsNotNone(cmd)
ufeObs.reset()
ufeCmd.execute(cmd)

# Ensure we got the correct UFE notifs.
self.assertEqual(ufeObs.nbAddNotif(), 1)
self.assertEqual(ufeObs.nbDeleteNotif(), 0)

# The xform prim should now have a single UFE child item.
xformHier = ufe.Hierarchy.hierarchy(xformItem)
self.assertTrue(xformHier.hasChildren())
self.assertEqual(len(xformHier.children()), 1)

# Set target to the weaker sub-layer.
cmds.mayaUsdEditTarget(proxyShape, edit=True, editTarget=subLayerA)

# Add another prim
cmd = contextOps.doOpCmd(['Add New Prim', 'Capsule'])
self.assertIsNotNone(cmd)
ufeObs.reset()
ufeCmd.execute(cmd)

# Ensure we got the correct UFE notifs.
self.assertEqual(ufeObs.nbAddNotif(), 1)
self.assertEqual(ufeObs.nbDeleteNotif(), 0)

# The xform prim should now have two UFE child items.
self.assertTrue(xformHier.hasChildren())
self.assertEqual(len(xformHier.children()), 2)

# Undo will remove the new prim, meaning one less child.
ufeObs.reset()
cmds.undo()
self.assertTrue(xformHier.hasChildren())
self.assertEqual(len(xformHier.children()), 1)

# Ensure we got the correct UFE notifs.
self.assertEqual(ufeObs.nbAddNotif(), 0)
self.assertEqual(ufeObs.nbDeleteNotif(), 1)

cmds.redo()
self.assertTrue(xformHier.hasChildren())
self.assertEqual(len(xformHier.children()), 2)

# Ensure we got the correct UFE notifs.
self.assertEqual(ufeObs.nbAddNotif(), 1)
self.assertEqual(ufeObs.nbDeleteNotif(), 1)

@unittest.skipUnless(Usd.GetVersion() >= (0, 21, 8), 'Requires CanApplySchema from USD')
def testMaterialBinding(self):
"""This test builds a material using only Ufe pre-4.10 capabilities."""
Expand Down