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

LOOKDEVX-991 Improve usability of NoExec commands #2737

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 12 additions & 2 deletions lib/mayaUsd/ufe/UsdSceneItemOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ bool UsdSceneItemOps::deleteItem()

#ifdef UFE_V4_FEATURES_AVAILABLE
#if (UFE_PREVIEW_VERSION_NUM >= 4033)
Ufe::UndoableCommand::Ptr UsdSceneItemOps::duplicateItemCmdNoExecute()
#if (UFE_PREVIEW_VERSION_NUM >= 4041)
Ufe::SceneItemResultUndoableCommand::Ptr
#else
Ufe::UndoableCommand::Ptr
#endif
UsdSceneItemOps::duplicateItemCmdNoExecute()
{
return UsdUndoDuplicateCommand::create(fItem);
}
Expand All @@ -100,7 +105,12 @@ Ufe::SceneItem::Ptr UsdSceneItemOps::duplicateItem()

#ifdef UFE_V4_FEATURES_AVAILABLE
#if (UFE_PREVIEW_VERSION_NUM >= 4033)
Ufe::UndoableCommand::Ptr UsdSceneItemOps::renameItemCmdNoExecute(const Ufe::PathComponent& newName)
#if (UFE_PREVIEW_VERSION_NUM >= 4041)
Ufe::SceneItemResultUndoableCommand::Ptr
#else
Ufe::UndoableCommand::Ptr
#endif
UsdSceneItemOps::renameItemCmdNoExecute(const Ufe::PathComponent& newName)
{
return UsdUndoRenameCommand::create(fItem, newName);
}
Expand Down
9 changes: 9 additions & 0 deletions lib/mayaUsd/ufe/UsdSceneItemOps.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,24 @@ class MAYAUSD_CORE_PUBLIC UsdSceneItemOps : public Ufe::SceneItemOps
bool deleteItem() override;
#ifdef UFE_V4_FEATURES_AVAILABLE
#if (UFE_PREVIEW_VERSION_NUM >= 4033)
#if (UFE_PREVIEW_VERSION_NUM >= 4041)
Ufe::SceneItemResultUndoableCommand::Ptr duplicateItemCmdNoExecute() override;
#else
Ufe::UndoableCommand::Ptr duplicateItemCmdNoExecute() override;
#endif
#endif
#endif
Ufe::Duplicate duplicateItemCmd() override;
Ufe::SceneItem::Ptr duplicateItem() override;
#ifdef UFE_V4_FEATURES_AVAILABLE
#if (UFE_PREVIEW_VERSION_NUM >= 4033)
#if (UFE_PREVIEW_VERSION_NUM >= 4041)
Ufe::SceneItemResultUndoableCommand::Ptr
renameItemCmdNoExecute(const Ufe::PathComponent& newName) override;
#else
Ufe::UndoableCommand::Ptr renameItemCmdNoExecute(const Ufe::PathComponent& newName) override;
#endif
#endif
#endif
Ufe::Rename renameItemCmd(const Ufe::PathComponent& newName) override;
Ufe::SceneItem::Ptr renameItem(const Ufe::PathComponent& newName) override;
Expand Down
4 changes: 4 additions & 0 deletions lib/mayaUsd/ufe/UsdUndoDuplicateCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ namespace MAYAUSD_NS_DEF {
namespace ufe {

UsdUndoDuplicateCommand::UsdUndoDuplicateCommand(const UsdSceneItem::Ptr& srcItem)
#if (UFE_PREVIEW_VERSION_NUM >= 4041)
: Ufe::SceneItemResultUndoableCommand()
#else
: Ufe::UndoableCommand()
#endif
, _ufeSrcPath(srcItem->path())
{
auto srcPrim = srcItem->prim();
Expand Down
7 changes: 7 additions & 0 deletions lib/mayaUsd/ufe/UsdUndoDuplicateCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ namespace MAYAUSD_NS_DEF {
namespace ufe {

//! \brief UsdUndoDuplicateCommand
#if (UFE_PREVIEW_VERSION_NUM >= 4041)
class MAYAUSD_CORE_PUBLIC UsdUndoDuplicateCommand : public Ufe::SceneItemResultUndoableCommand
#else
class MAYAUSD_CORE_PUBLIC UsdUndoDuplicateCommand : public Ufe::UndoableCommand
#endif
{
public:
typedef std::shared_ptr<UsdUndoDuplicateCommand> Ptr;
Expand All @@ -50,6 +54,9 @@ class MAYAUSD_CORE_PUBLIC UsdUndoDuplicateCommand : public Ufe::UndoableCommand
static UsdUndoDuplicateCommand::Ptr create(const UsdSceneItem::Ptr& srcItem);

UsdSceneItem::Ptr duplicatedItem() const;
#if (UFE_PREVIEW_VERSION_NUM >= 4041)
Ufe::SceneItem::Ptr sceneItem() const override { return duplicatedItem(); }
#endif

UFE_V2(void execute() override;)
void undo() override;
Expand Down
4 changes: 4 additions & 0 deletions lib/mayaUsd/ufe/UsdUndoRenameCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ namespace ufe {
UsdUndoRenameCommand::UsdUndoRenameCommand(
const UsdSceneItem::Ptr& srcItem,
const Ufe::PathComponent& newName)
#if (UFE_PREVIEW_VERSION_NUM >= 4041)
: Ufe::SceneItemResultUndoableCommand()
#else
: Ufe::UndoableCommand()
#endif
, _ufeSrcItem(srcItem)
, _ufeDstItem(nullptr)
, _stage(_ufeSrcItem->prim().GetStage())
Expand Down
7 changes: 7 additions & 0 deletions lib/mayaUsd/ufe/UsdUndoRenameCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ namespace MAYAUSD_NS_DEF {
namespace ufe {

//! \brief UsdUndoRenameCommand
#if (UFE_PREVIEW_VERSION_NUM >= 4041)
class MAYAUSD_CORE_PUBLIC UsdUndoRenameCommand : public Ufe::SceneItemResultUndoableCommand
#else
class MAYAUSD_CORE_PUBLIC UsdUndoRenameCommand : public Ufe::UndoableCommand
#endif
{
public:
typedef std::shared_ptr<UsdUndoRenameCommand> Ptr;
Expand All @@ -45,6 +49,9 @@ class MAYAUSD_CORE_PUBLIC UsdUndoRenameCommand : public Ufe::UndoableCommand
create(const UsdSceneItem::Ptr& srcItem, const Ufe::PathComponent& newName);

UsdSceneItem::Ptr renamedItem() const;
#if (UFE_PREVIEW_VERSION_NUM >= 4041)
Ufe::SceneItem::Ptr sceneItem() const override { return renamedItem(); }
#endif

private:
bool renameRedo();
Expand Down
11 changes: 8 additions & 3 deletions test/lib/ufe/testBatchOpsHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,21 @@ def testUfeDuplicateRelationships(self):
self.assertIsNotNone(batchOpsHandler)

# Duplicating without batching means the new plane will not see the new material:
dGeom = ufe.SceneItemOps.sceneItemOps(geomItem).duplicateItemCmd()
dGeom = ufe.SceneItemOps.sceneItemOps(geomItem).duplicateItemCmdNoExecute()
dGeom.execute()
dMat = ufe.SceneItemOps.sceneItemOps(matItem).duplicateItemCmd()

dGeomPrim = usdUtils.getPrimFromSceneItem(dGeom.item)
dGeomPrim = usdUtils.getPrimFromSceneItem(dGeom.sceneItem)
self.assertEqual(dGeomPrim.GetPath(), Sdf.Path("/pPlane7"))
dGeomBindAPI = UsdShade.MaterialBindingAPI(dGeomPrim)
# Points to original ss3SG, we would like ss3SG1
self.assertEqual(dGeomBindAPI.GetDirectBinding().GetMaterialPath(), Sdf.Path("/mtl/ss3SG"))

dMat.undoableCommand.undo()
dGeom.undoableCommand.undo()
dGeom.undo()

undoneGeomItem = ufeUtils.createUfeSceneItem(shapeNode, '/pPlane7')
self.assertIsNone(undoneGeomItem)

sel = ufe.Selection()
sel.append(geomItem)
Expand Down
86 changes: 86 additions & 0 deletions test/lib/ufe/testRename.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import fixturesUtils
import mayaUtils
import testUtils
import ufeUtils
import usdUtils
import mayaUsd_createStageWithNewLayer

Expand Down Expand Up @@ -792,6 +793,91 @@ def testPaths(self, shapeStage, cubeName):

testPaths(self, shapeStage, "pCube1")

def testUfeRenameCommandAPI(self):
'''Test that the rename command can be invoked using the 3 known APIs.'''

testFile = testUtils.getTestScene('MaterialX', 'BatchOpsTestScene.usda')
shapeNode,shapeStage = mayaUtils.createProxyFromFile(testFile)

# Test NoExecute API:
geomItem = ufeUtils.createUfeSceneItem(shapeNode, '/pPlane1')
self.assertIsNotNone(geomItem)

renameCmd = ufe.SceneItemOps.sceneItemOps(geomItem).renameItemCmdNoExecute(ufe.PathComponent("carotte"))
self.assertIsNotNone(renameCmd)
renameCmd.execute()

nonExistentItem = ufeUtils.createUfeSceneItem(shapeNode, '/pPlane1')
self.assertIsNone(nonExistentItem)

carotteItem = ufeUtils.createUfeSceneItem(shapeNode, '/carotte')
self.assertIsNotNone(carotteItem)
self.assertEqual(carotteItem, renameCmd.sceneItem)

renameCmd.undo()

geomItem = ufeUtils.createUfeSceneItem(shapeNode, '/pPlane1')
self.assertIsNotNone(geomItem)
nonExistentItem = ufeUtils.createUfeSceneItem(shapeNode, '/carotte')
self.assertIsNone(nonExistentItem)

renameCmd.redo()

nonExistentItem = ufeUtils.createUfeSceneItem(shapeNode, '/pPlane1')
self.assertIsNone(nonExistentItem)

carotteItem = ufeUtils.createUfeSceneItem(shapeNode, '/carotte')
self.assertIsNotNone(carotteItem)
self.assertEqual(carotteItem, renameCmd.sceneItem)

renameCmd.undo()

# Test Exec but undoable API:
geomItem = ufeUtils.createUfeSceneItem(shapeNode, '/pPlane1')
self.assertIsNotNone(geomItem)

renameCmd = ufe.SceneItemOps.sceneItemOps(geomItem).renameItemCmd(ufe.PathComponent("carotte"))
self.assertIsNotNone(renameCmd)

nonExistentItem = ufeUtils.createUfeSceneItem(shapeNode, '/pPlane1')
self.assertIsNone(nonExistentItem)

carotteItem = ufeUtils.createUfeSceneItem(shapeNode, '/carotte')
self.assertIsNotNone(carotteItem)
self.assertEqual(carotteItem, renameCmd.item)

renameCmd.undoableCommand.undo()

geomItem = ufeUtils.createUfeSceneItem(shapeNode, '/pPlane1')
self.assertIsNotNone(geomItem)
nonExistentItem = ufeUtils.createUfeSceneItem(shapeNode, '/carotte')
self.assertIsNone(nonExistentItem)

renameCmd.undoableCommand.redo()

nonExistentItem = ufeUtils.createUfeSceneItem(shapeNode, '/pPlane1')
self.assertIsNone(nonExistentItem)

carotteItem = ufeUtils.createUfeSceneItem(shapeNode, '/carotte')
self.assertIsNotNone(carotteItem)
self.assertEqual(carotteItem, renameCmd.item)

renameCmd.undoableCommand.undo()

# Test non-undoable API:
geomItem = ufeUtils.createUfeSceneItem(shapeNode, '/pPlane1')
self.assertIsNotNone(geomItem)

renamedItem = ufe.SceneItemOps.sceneItemOps(geomItem).renameItem(ufe.PathComponent("carotte"))
self.assertIsNotNone(renameCmd)

nonExistentItem = ufeUtils.createUfeSceneItem(shapeNode, '/pPlane1')
self.assertIsNone(nonExistentItem)

carotteItem = ufeUtils.createUfeSceneItem(shapeNode, '/carotte')
self.assertIsNotNone(carotteItem)
self.assertEqual(carotteItem, renamedItem)


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