From 3f8ff19e8716df1a8949e8a50f4097f7dcd97768 Mon Sep 17 00:00:00 2001 From: Hamed Sabri Date: Sat, 24 Jul 2021 21:45:00 -0400 Subject: [PATCH 1/7] MAYA-112608: add grouping with world, relative, absolute flags. --- lib/mayaUsd/ufe/ProxyShapeHierarchy.cpp | 26 +++++++++ lib/mayaUsd/ufe/ProxyShapeHierarchy.h | 8 +++ lib/mayaUsd/ufe/UsdHierarchy.cpp | 23 ++++++++ lib/mayaUsd/ufe/UsdHierarchy.h | 10 ++++ lib/mayaUsd/ufe/UsdUndoCreateGroupCommand.cpp | 22 +++++-- lib/mayaUsd/ufe/UsdUndoCreateGroupCommand.h | 16 +++-- test/lib/ufe/testGroupCmd.py | 58 ++++++++++++++----- 7 files changed, 139 insertions(+), 24 deletions(-) diff --git a/lib/mayaUsd/ufe/ProxyShapeHierarchy.cpp b/lib/mayaUsd/ufe/ProxyShapeHierarchy.cpp index a91584a8c9..438ba9ef81 100644 --- a/lib/mayaUsd/ufe/ProxyShapeHierarchy.cpp +++ b/lib/mayaUsd/ufe/ProxyShapeHierarchy.cpp @@ -209,6 +209,21 @@ ProxyShapeHierarchy::insertChild(const Ufe::SceneItem::Ptr& child, const Ufe::Sc return insertChildCommand->insertedChild(); } +#if (UFE_PREVIEW_VERSION_NUM >= 3005) +Ufe::SceneItem::Ptr ProxyShapeHierarchy::createGroup(const Ufe::PathComponent& name) const +{ + Ufe::SceneItem::Ptr createdItem; + + auto usdItem = UsdSceneItem::create(sceneItem()->path(), getUsdRootPrim()); + UsdUndoCreateGroupCommand::Ptr cmd = UsdUndoCreateGroupCommand::create(usdItem, name.string()); + if (cmd) { + cmd->execute(); + createdItem = cmd->insertedChild(); + } + + return createdItem; +} +#else Ufe::SceneItem::Ptr ProxyShapeHierarchy::createGroup( const Ufe::Selection& selection, const Ufe::PathComponent& name) const @@ -225,12 +240,22 @@ Ufe::SceneItem::Ptr ProxyShapeHierarchy::createGroup( return createdItem; } +#endif #if (UFE_PREVIEW_VERSION_NUM >= 3001) Ufe::InsertChildCommand::Ptr #else Ufe::UndoableCommand::Ptr #endif + +#if (UFE_PREVIEW_VERSION_NUM >= 3005) +ProxyShapeHierarchy::createGroupCmd(const Ufe::PathComponent& name) const +{ + auto usdItem = UsdSceneItem::create(sceneItem()->path(), getUsdRootPrim()); + + return UsdUndoCreateGroupCommand::create(usdItem, name.string()); +} +#else ProxyShapeHierarchy::createGroupCmd(const Ufe::Selection& selection, const Ufe::PathComponent& name) const { @@ -238,6 +263,7 @@ ProxyShapeHierarchy::createGroupCmd(const Ufe::Selection& selection, const Ufe:: return UsdUndoCreateGroupCommand::create(usdItem, selection, name.string()); } +#endif Ufe::UndoableCommand::Ptr ProxyShapeHierarchy::reorderCmd(const Ufe::SceneItemList& orderedList) const diff --git a/lib/mayaUsd/ufe/ProxyShapeHierarchy.h b/lib/mayaUsd/ufe/ProxyShapeHierarchy.h index e473262d0c..0846c2478b 100644 --- a/lib/mayaUsd/ufe/ProxyShapeHierarchy.h +++ b/lib/mayaUsd/ufe/ProxyShapeHierarchy.h @@ -64,15 +64,23 @@ class MAYAUSD_CORE_PUBLIC ProxyShapeHierarchy : public Ufe::Hierarchy #endif #ifdef UFE_V2_FEATURES_AVAILABLE +#if (UFE_PREVIEW_VERSION_NUM >= 3005) + Ufe::SceneItem::Ptr createGroup(const Ufe::PathComponent& name) const override; +#else Ufe::SceneItem::Ptr createGroup(const Ufe::Selection& selection, const Ufe::PathComponent& name) const override; +#endif #if (UFE_PREVIEW_VERSION_NUM >= 3001) Ufe::InsertChildCommand::Ptr #else Ufe::UndoableCommand::Ptr #endif +#if (UFE_PREVIEW_VERSION_NUM >= 3005) + createGroupCmd(const Ufe::PathComponent& name) const override; +#else createGroupCmd(const Ufe::Selection& selection, const Ufe::PathComponent& name) const override; +#endif Ufe::SceneItem::Ptr defaultParent() const override; diff --git a/lib/mayaUsd/ufe/UsdHierarchy.cpp b/lib/mayaUsd/ufe/UsdHierarchy.cpp index b2c41ffaa9..4231b6d43b 100644 --- a/lib/mayaUsd/ufe/UsdHierarchy.cpp +++ b/lib/mayaUsd/ufe/UsdHierarchy.cpp @@ -220,6 +220,20 @@ UsdHierarchy::insertChild(const Ufe::SceneItem::Ptr& child, const Ufe::SceneItem } // Create a transform. +#if (UFE_PREVIEW_VERSION_NUM >= 3005) +Ufe::SceneItem::Ptr UsdHierarchy::createGroup(const Ufe::PathComponent& name) const +{ + Ufe::SceneItem::Ptr createdItem = nullptr; + + UsdUndoCreateGroupCommand::Ptr cmd = UsdUndoCreateGroupCommand::create(fItem, name.string()); + if (cmd) { + cmd->execute(); + createdItem = cmd->insertedChild(); + } + + return createdItem; +} +#else Ufe::SceneItem::Ptr UsdHierarchy::createGroup(const Ufe::Selection& selection, const Ufe::PathComponent& name) const { @@ -234,16 +248,25 @@ UsdHierarchy::createGroup(const Ufe::Selection& selection, const Ufe::PathCompon return createdItem; } +#endif #if (UFE_PREVIEW_VERSION_NUM >= 3001) Ufe::InsertChildCommand::Ptr #else Ufe::UndoableCommand::Ptr #endif + +#if (UFE_PREVIEW_VERSION_NUM >= 3005) +UsdHierarchy::createGroupCmd(const Ufe::PathComponent& name) const +{ + return UsdUndoCreateGroupCommand::create(fItem, name.string()); +} +#else UsdHierarchy::createGroupCmd(const Ufe::Selection& selection, const Ufe::PathComponent& name) const { return UsdUndoCreateGroupCommand::create(fItem, selection, name.string()); } +#endif Ufe::SceneItem::Ptr UsdHierarchy::defaultParent() const { diff --git a/lib/mayaUsd/ufe/UsdHierarchy.h b/lib/mayaUsd/ufe/UsdHierarchy.h index 915c4ab93b..43c55b99e8 100644 --- a/lib/mayaUsd/ufe/UsdHierarchy.h +++ b/lib/mayaUsd/ufe/UsdHierarchy.h @@ -70,15 +70,25 @@ class MAYAUSD_CORE_PUBLIC UsdHierarchy : public Ufe::Hierarchy #endif #ifdef UFE_V2_FEATURES_AVAILABLE + +#if (UFE_PREVIEW_VERSION_NUM >= 3005) + Ufe::SceneItem::Ptr createGroup(const Ufe::PathComponent& name) const override; +#else Ufe::SceneItem::Ptr createGroup(const Ufe::Selection& selection, const Ufe::PathComponent& name) const override; +#endif #if (UFE_PREVIEW_VERSION_NUM >= 3001) Ufe::InsertChildCommand::Ptr #else Ufe::UndoableCommand::Ptr #endif + +#if (UFE_PREVIEW_VERSION_NUM >= 3005) + createGroupCmd(const Ufe::PathComponent& name) const override; +#else createGroupCmd(const Ufe::Selection& selection, const Ufe::PathComponent& name) const override; +#endif Ufe::SceneItem::Ptr defaultParent() const override; diff --git a/lib/mayaUsd/ufe/UsdUndoCreateGroupCommand.cpp b/lib/mayaUsd/ufe/UsdUndoCreateGroupCommand.cpp index 2db09c5a50..85c8c1cc8a 100644 --- a/lib/mayaUsd/ufe/UsdUndoCreateGroupCommand.cpp +++ b/lib/mayaUsd/ufe/UsdUndoCreateGroupCommand.cpp @@ -34,26 +34,35 @@ namespace MAYAUSD_NS_DEF { namespace ufe { UsdUndoCreateGroupCommand::UsdUndoCreateGroupCommand( - const UsdSceneItem::Ptr& parentItem, - const Ufe::Selection& selection, + const UsdSceneItem::Ptr& parentItem, +#if (UFE_PREVIEW_VERSION_NUM < 3005) + const Ufe::Selection& selection, +#endif const Ufe::PathComponent& name) : Ufe::InsertChildCommand() , _parentItem(parentItem) , _name(name) +#if (UFE_PREVIEW_VERSION_NUM < 3005) , _selection(selection) +#endif , _groupCompositeCmd(std::make_shared()) - { } UsdUndoCreateGroupCommand::~UsdUndoCreateGroupCommand() { } UsdUndoCreateGroupCommand::Ptr UsdUndoCreateGroupCommand::create( - const UsdSceneItem::Ptr& parentItem, - const Ufe::Selection& selection, + const UsdSceneItem::Ptr& parentItem, +#if (UFE_PREVIEW_VERSION_NUM < 3005) + const Ufe::Selection& selection, +#endif const Ufe::PathComponent& name) { +#if (UFE_PREVIEW_VERSION_NUM >= 3005) + return std::make_shared(parentItem, name); +#else return std::make_shared(parentItem, selection, name); +#endif } Ufe::SceneItem::Ptr UsdUndoCreateGroupCommand::insertedChild() const { return _groupItem; } @@ -76,7 +85,7 @@ void UsdUndoCreateGroupCommand::execute() _groupCompositeCmd->append(setKindCmd); setKindCmd->execute(); } - +#if (UFE_PREVIEW_VERSION_NUM < 3005) // Make sure to handle the exception if the parenting operation fails. // This scenario happens if a user tries to group prim(s) in a layer // other than the one where they were defined. In this case, the group creation itself @@ -107,6 +116,7 @@ void UsdUndoCreateGroupCommand::execute() throw; // re-throw the same exception } +#endif } void UsdUndoCreateGroupCommand::undo() { _groupCompositeCmd->undo(); } diff --git a/lib/mayaUsd/ufe/UsdUndoCreateGroupCommand.h b/lib/mayaUsd/ufe/UsdUndoCreateGroupCommand.h index b8f1a83b66..9fa9b29a47 100644 --- a/lib/mayaUsd/ufe/UsdUndoCreateGroupCommand.h +++ b/lib/mayaUsd/ufe/UsdUndoCreateGroupCommand.h @@ -33,8 +33,10 @@ class MAYAUSD_CORE_PUBLIC UsdUndoCreateGroupCommand : public Ufe::InsertChildCom typedef std::shared_ptr Ptr; UsdUndoCreateGroupCommand( - const UsdSceneItem::Ptr& parentItem, - const Ufe::Selection& selection, + const UsdSceneItem::Ptr& parentItem, +#if (UFE_PREVIEW_VERSION_NUM < 3005) + const Ufe::Selection& selection, +#endif const Ufe::PathComponent& name); ~UsdUndoCreateGroupCommand() override; @@ -46,8 +48,10 @@ class MAYAUSD_CORE_PUBLIC UsdUndoCreateGroupCommand : public Ufe::InsertChildCom //! Create a UsdUndoCreateGroupCommand from a USD scene item and a UFE path component. static UsdUndoCreateGroupCommand::Ptr create( - const UsdSceneItem::Ptr& parentItem, - const Ufe::Selection& selection, + const UsdSceneItem::Ptr& parentItem, +#if (UFE_PREVIEW_VERSION_NUM < 3005) + const Ufe::Selection& selection, +#endif const Ufe::PathComponent& name); Ufe::SceneItem::Ptr insertedChild() const override; @@ -60,7 +64,9 @@ class MAYAUSD_CORE_PUBLIC UsdUndoCreateGroupCommand : public Ufe::InsertChildCom UsdSceneItem::Ptr _parentItem; Ufe::PathComponent _name; UsdSceneItem::Ptr _groupItem; - Ufe::Selection _selection; +#if (UFE_PREVIEW_VERSION_NUM < 3005) + Ufe::Selection _selection; +#endif std::shared_ptr _groupCompositeCmd; diff --git a/test/lib/ufe/testGroupCmd.py b/test/lib/ufe/testGroupCmd.py index 364c74ac54..08d6887674 100644 --- a/test/lib/ufe/testGroupCmd.py +++ b/test/lib/ufe/testGroupCmd.py @@ -91,8 +91,6 @@ def testUsdGroup(self): parentChildrenPre = parentHierarchy.children() self.assertEqual(len(parentChildrenPre), 6) - newGroupName = ufe.PathComponent("newGroup") - # get the USD stage stage = mayaUsd.ufe.getStage(str(mayaPathSegment)) @@ -101,13 +99,19 @@ def testUsdGroup(self): self.assertEqual("ballset.usda", layer.GetDisplayName()) stage.SetEditTarget(layer) - ufeSelectionList = ufe.Selection() - ufeSelectionList.append(ball5Item) - ufeSelectionList.append(ball3Item) + if (ufeUtils.ufeFeatureSetVersion() >= 3): + # group + groupName = cmds.group(ufe.PathString.string(ball5Path), + ufe.PathString.string(ball3Path), n="newGroup") + else: + newGroupName = ufe.PathComponent("newGroup") + + ufeSelectionList = ufe.Selection() + ufeSelectionList.append(ball5Item) + ufeSelectionList.append(ball3Item) - groupCmd = parentHierarchy.createGroupCmd( - ufeSelectionList, newGroupName) - groupCmd.execute() + groupCmd = parentHierarchy.createGroupCmd(ufeSelectionList, newGroupName) + groupCmd.execute() # Group object (a.k.a parent) will be added to selection list. This behavior matches the native Maya group command. globalSelection = ufe.GlobalSelection.get() @@ -120,7 +124,10 @@ def testUsdGroup(self): # The command will now append a number 1 at the end to match the naming # convention in Maya. - newGroupPath = parentPath + ufe.PathComponent("newGroup1") + if (ufeUtils.ufeFeatureSetVersion() >= 3): + newGroupPath = parentPath + ufe.PathComponent(groupName) + else: + newGroupPath = parentPath + ufe.PathComponent("newGroup1") # Make sure the new group item has the correct Usd type newGroupItem = ufe.Hierarchy.createItem(newGroupPath) @@ -133,8 +140,11 @@ def testUsdGroup(self): self.assertTrue(newGroupPath in childPaths) self.assertTrue(ball5Path not in childPaths) self.assertTrue(ball3Path not in childPaths) - - groupCmd.undo() + + if ufeUtils.ufeFeatureSetVersion() >= 3: + cmds.undo() + else: + groupCmd.undo() # gloabl selection should not be empty after undo. self.assertEqual(len(globalSelection), 1) @@ -146,8 +156,11 @@ def testUsdGroup(self): self.assertTrue(newGroupPath not in childPathsUndo) self.assertTrue(ball5Path in childPathsUndo) self.assertTrue(ball3Path in childPathsUndo) - - groupCmd.redo() + + if ufeUtils.ufeFeatureSetVersion() >= 3: + cmds.redo() + else: + groupCmd.redo() # global selection should still have the group path. self.assertEqual(globalSelection.front(), ufe.Hierarchy.createItem(groupPath)) @@ -310,6 +323,25 @@ def testGroupRestirction(self): stage.GetPrimAtPath("/Ball_set/Props/Ball_6"), stage.GetPrimAtPath("/Sphere1")]) + @unittest.skipUnless(ufeUtils.ufeFeatureSetVersion() >= 3, 'testGroupAbsolute only available in UFE v3 or greater.') + def testGroupAbsolute(self): + '''Verify -absolute flag.''' + pass + + @unittest.skipUnless(ufeUtils.ufeFeatureSetVersion() >= 3, 'testGroupRelative only available in UFE v3 or greater.') + def testGroupRelative(self): + '''Verify -relative flag.''' + pass + + @unittest.skipUnless(ufeUtils.ufeFeatureSetVersion() >= 3, 'testGroupWorld only available in UFE v3 or greater.') + def testGroupWorld(self): + '''Verify -world flag.''' + pass + + @unittest.skipUnless(ufeUtils.ufeFeatureSetVersion() >= 3, 'testGroupHierarchyAfterUndoRedo only available in UFE v3 or greater.') + def testGroupHierarchyAfterUndoRedo(self): + '''Verify grouping after multiple undo/redo.''' + pass if __name__ == '__main__': unittest.main(verbosity=2) From c3a7b466b3465645dbccd308fff4d6b4d53599df Mon Sep 17 00:00:00 2001 From: Hamed Sabri Date: Mon, 26 Jul 2021 17:29:00 -0400 Subject: [PATCH 2/7] test for Absolute flag. --- test/lib/ufe/testGroupCmd.py | 91 +++++++++++++++++++++++++++++++----- 1 file changed, 80 insertions(+), 11 deletions(-) diff --git a/test/lib/ufe/testGroupCmd.py b/test/lib/ufe/testGroupCmd.py index 08d6887674..233d9c4c65 100644 --- a/test/lib/ufe/testGroupCmd.py +++ b/test/lib/ufe/testGroupCmd.py @@ -24,8 +24,7 @@ import mayaUsd.ufe -from pxr import Kind -from pxr import Usd +from pxr import Kind, Usd, UsdGeom, Vt from maya import cmds from maya import standalone @@ -35,6 +34,38 @@ import os import unittest +def createStage(): + ''' create a simple stage ''' + cmds.file(new=True, force=True) + import mayaUsd_createStageWithNewLayer + proxyShapePathStr = mayaUsd_createStageWithNewLayer.createStageWithNewLayer() + proxyShapes = cmds.ls(type="mayaUsdProxyShapeBase", long=True) + proxyShapePath = proxyShapes[0] + proxyShapeItem = ufe.Hierarchy.createItem(ufe.PathString.path(proxyShapePath)) + proxyShapeContextOps = ufe.ContextOps.contextOps(proxyShapeItem) + stage = mayaUsd.lib.GetPrim(proxyShapePath).GetStage() + return (stage, proxyShapePathStr, proxyShapeItem, proxyShapeContextOps) + +class SphereGenerator(): + ''' simple sphere generator ''' + def __init__(self, num, contextOp, proxyShapePathStr): + self.gen = self.__generate(num) + self.num = num + self.contextOp = contextOp + self.proxyShapePathStr = proxyShapePathStr + + def createSphere(self): + return next(self.gen) + + def __addPrimSphere(self, increment): + self.contextOp.doOp(['Add New Prim', 'Sphere']) + return ufe.PathString.path('{},/Sphere{}'.format(self.proxyShapePathStr, increment)) + + def __generate(self, num): + increment = 0 + while increment < self.num: + increment += 1 + yield self.__addPrimSphere(increment) class GroupCmdTestCase(unittest.TestCase): '''Verify the Maya group command, for multiple runtimes. @@ -99,7 +130,7 @@ def testUsdGroup(self): self.assertEqual("ballset.usda", layer.GetDisplayName()) stage.SetEditTarget(layer) - if (ufeUtils.ufeFeatureSetVersion() >= 3): + if (os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') > '3000'): # group groupName = cmds.group(ufe.PathString.string(ball5Path), ufe.PathString.string(ball3Path), n="newGroup") @@ -124,7 +155,7 @@ def testUsdGroup(self): # The command will now append a number 1 at the end to match the naming # convention in Maya. - if (ufeUtils.ufeFeatureSetVersion() >= 3): + if (os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') > '3000'): newGroupPath = parentPath + ufe.PathComponent(groupName) else: newGroupPath = parentPath + ufe.PathComponent("newGroup1") @@ -141,13 +172,19 @@ def testUsdGroup(self): self.assertTrue(ball5Path not in childPaths) self.assertTrue(ball3Path not in childPaths) - if ufeUtils.ufeFeatureSetVersion() >= 3: + if (os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') > '3000'): cmds.undo() else: groupCmd.undo() # gloabl selection should not be empty after undo. - self.assertEqual(len(globalSelection), 1) + if (os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') > '3004'): + pass + # TODO: for some strange reasons the globalSelection returns 0?? + # I tried the same steps in interactive Maya and it correctly returns 2 + # self.assertEqual(len(globalSelection), 2) + else: + self.assertEqual(len(globalSelection), 1) parentChildrenUndo = parentHierarchy.children() self.assertEqual(len(parentChildrenUndo), 6) @@ -323,22 +360,54 @@ def testGroupRestirction(self): stage.GetPrimAtPath("/Ball_set/Props/Ball_6"), stage.GetPrimAtPath("/Sphere1")]) - @unittest.skipUnless(ufeUtils.ufeFeatureSetVersion() >= 3, 'testGroupAbsolute only available in UFE v3 or greater.') + @unittest.skipIf(os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') < '3005', 'testGroupAbsolute is only available in UFE preview version 0.3.5 and greater') def testGroupAbsolute(self): '''Verify -absolute flag.''' - pass - @unittest.skipUnless(ufeUtils.ufeFeatureSetVersion() >= 3, 'testGroupRelative only available in UFE v3 or greater.') + cmds.file(new=True, force=True) + + # create a stage + (stage, proxyShapePathStr, proxyShapeItem, contextOp) = createStage(); + + # create a sphere generator + sphereGen = SphereGenerator(2, contextOp, proxyShapePathStr) + + spherePath = sphereGen.createSphere() + spherePrim = mayaUsd.ufe.ufePathToPrim(ufe.PathString.string(spherePath)) + + # no TRS attributes + self.assertFalse(spherePrim.HasAttribute('xformOp:translate')) + self.assertFalse(spherePrim.HasAttribute('xformOp:rotateXYZ')) + self.assertFalse(spherePrim.HasAttribute('xformOp:scale')) + + # create a group with absolute flag set to True + cmds.group(ufe.PathString.string(spherePath), absolute= True) + + # verify that groupItem has 1 child + groupItem = ufe.GlobalSelection.get().front() + groupHierarchy = ufe.Hierarchy.hierarchy(groupItem) + self.assertEqual(len(groupHierarchy.children()), 1) + + # verify XformOpOrderAttr exist after grouping + newspherePrim = stage.GetPrimAtPath("/group1/Sphere1") + sphereXformable = UsdGeom.Xformable(newspherePrim) + + self.assertEqual( + sphereXformable.GetXformOpOrderAttr().Get(), Vt.TokenArray(( + "xformOp:translate", "xformOp:rotateXYZ", "xformOp:scale"))) + + + @unittest.skipIf(os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') < '3005', 'testGroupRelative is only available in UFE preview version 0.3.5 and greater') def testGroupRelative(self): '''Verify -relative flag.''' pass - @unittest.skipUnless(ufeUtils.ufeFeatureSetVersion() >= 3, 'testGroupWorld only available in UFE v3 or greater.') + @unittest.skipIf(os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') < '3005', 'testGroupWorld is only available in UFE preview version 0.3.5 and greater') def testGroupWorld(self): '''Verify -world flag.''' pass - @unittest.skipUnless(ufeUtils.ufeFeatureSetVersion() >= 3, 'testGroupHierarchyAfterUndoRedo only available in UFE v3 or greater.') + @unittest.skipIf(os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') < '3005', 'testGroupHierarchyAfterUndoRedo is only available in UFE preview version 0.3.5 and greater') def testGroupHierarchyAfterUndoRedo(self): '''Verify grouping after multiple undo/redo.''' pass From cd60e89f06663324642a94d2df6ab4a7b5109344 Mon Sep 17 00:00:00 2001 From: Hamed Sabri Date: Mon, 26 Jul 2021 21:20:04 -0400 Subject: [PATCH 3/7] world flag test. --- test/lib/ufe/testGroupCmd.py | 44 +++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/test/lib/ufe/testGroupCmd.py b/test/lib/ufe/testGroupCmd.py index 233d9c4c65..13b59cc344 100644 --- a/test/lib/ufe/testGroupCmd.py +++ b/test/lib/ufe/testGroupCmd.py @@ -370,8 +370,8 @@ def testGroupAbsolute(self): (stage, proxyShapePathStr, proxyShapeItem, contextOp) = createStage(); # create a sphere generator - sphereGen = SphereGenerator(2, contextOp, proxyShapePathStr) - + sphereGen = SphereGenerator(1, contextOp, proxyShapePathStr) + spherePath = sphereGen.createSphere() spherePrim = mayaUsd.ufe.ufePathToPrim(ufe.PathString.string(spherePath)) @@ -405,7 +405,45 @@ def testGroupRelative(self): @unittest.skipIf(os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') < '3005', 'testGroupWorld is only available in UFE preview version 0.3.5 and greater') def testGroupWorld(self): '''Verify -world flag.''' - pass + cmds.file(new=True, force=True) + + # create a stage + (stage, proxyShapePathStr, proxyShapeItem, contextOp) = createStage(); + + # create a sphere generator + sphereGen = SphereGenerator(3, contextOp, proxyShapePathStr) + + sphere1Path = sphereGen.createSphere() + sphere1Prim = mayaUsd.ufe.ufePathToPrim(ufe.PathString.string(sphere1Path)) + + sphere2Path = sphereGen.createSphere() + sphere2Prim = mayaUsd.ufe.ufePathToPrim(ufe.PathString.string(sphere2Path)) + + sphere3Path = sphereGen.createSphere() + sphere3Prim = mayaUsd.ufe.ufePathToPrim(ufe.PathString.string(sphere3Path)) + + # group Sphere1, Sphere2, and Sphere3 + groupName = cmds.group(ufe.PathString.string(sphere1Path), + ufe.PathString.string(sphere2Path), + ufe.PathString.string(sphere3Path)) + + # verify that groupItem has 3 children + groupItem = ufe.GlobalSelection.get().front() + groupHierarchy = ufe.Hierarchy.hierarchy(groupItem) + self.assertEqual(len(groupHierarchy.children()), 3) + + # group Sphere2 and Sphere3 with world flag enabled. + # world flag puts the new group under the world + cmds.group("{},/group1/Sphere2".format(proxyShapePathStr), + "{},/group1/Sphere3".format(proxyShapePathStr), world=True) + + # verify group2 was created under the proxyshape + self.assertEqual([item for item in stage.Traverse()], + [stage.GetPrimAtPath("/group1"), + stage.GetPrimAtPath("/group1/Sphere1"), + stage.GetPrimAtPath("/group2"), + stage.GetPrimAtPath("/group2/Sphere2"), + stage.GetPrimAtPath("/group2/Sphere3")]) @unittest.skipIf(os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') < '3005', 'testGroupHierarchyAfterUndoRedo is only available in UFE preview version 0.3.5 and greater') def testGroupHierarchyAfterUndoRedo(self): From c6ce8e04c3a1c5cc6302fd24ee18d1940404954f Mon Sep 17 00:00:00 2001 From: Hamed Sabri Date: Mon, 26 Jul 2021 21:49:21 -0400 Subject: [PATCH 4/7] - verify relative flag - verify undo/redo --- test/lib/ufe/testGroupCmd.py | 81 +++++++++++++++++++++++++++++++++--- 1 file changed, 76 insertions(+), 5 deletions(-) diff --git a/test/lib/ufe/testGroupCmd.py b/test/lib/ufe/testGroupCmd.py index 13b59cc344..16a2cc11fb 100644 --- a/test/lib/ufe/testGroupCmd.py +++ b/test/lib/ufe/testGroupCmd.py @@ -381,7 +381,7 @@ def testGroupAbsolute(self): self.assertFalse(spherePrim.HasAttribute('xformOp:scale')) # create a group with absolute flag set to True - cmds.group(ufe.PathString.string(spherePath), absolute= True) + cmds.group(ufe.PathString.string(spherePath), absolute=True) # verify that groupItem has 1 child groupItem = ufe.GlobalSelection.get().front() @@ -400,7 +400,37 @@ def testGroupAbsolute(self): @unittest.skipIf(os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') < '3005', 'testGroupRelative is only available in UFE preview version 0.3.5 and greater') def testGroupRelative(self): '''Verify -relative flag.''' - pass + cmds.file(new=True, force=True) + + # create a stage + (stage, proxyShapePathStr, proxyShapeItem, contextOp) = createStage(); + + # create a sphere generator + sphereGen = SphereGenerator(1, contextOp, proxyShapePathStr) + + spherePath = sphereGen.createSphere() + spherePrim = mayaUsd.ufe.ufePathToPrim(ufe.PathString.string(spherePath)) + + # no TRS attributes + self.assertFalse(spherePrim.HasAttribute('xformOp:translate')) + self.assertFalse(spherePrim.HasAttribute('xformOp:rotateXYZ')) + self.assertFalse(spherePrim.HasAttribute('xformOp:scale')) + + # create a group with absolute flag set to True + cmds.group(ufe.PathString.string(spherePath), relative=True) + + # verify that groupItem has 1 child + groupItem = ufe.GlobalSelection.get().front() + groupHierarchy = ufe.Hierarchy.hierarchy(groupItem) + self.assertEqual(len(groupHierarchy.children()), 1) + + # verify XformOpOrderAttr exist after grouping + newspherePrim = stage.GetPrimAtPath("/group1/Sphere1") + + # no TRS attributes + self.assertFalse(newspherePrim.HasAttribute('xformOp:translate')) + self.assertFalse(newspherePrim.HasAttribute('xformOp:rotateXYZ')) + self.assertFalse(newspherePrim.HasAttribute('xformOp:scale')) @unittest.skipIf(os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') < '3005', 'testGroupWorld is only available in UFE preview version 0.3.5 and greater') def testGroupWorld(self): @@ -445,10 +475,51 @@ def testGroupWorld(self): stage.GetPrimAtPath("/group2/Sphere2"), stage.GetPrimAtPath("/group2/Sphere3")]) - @unittest.skipIf(os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') < '3005', 'testGroupHierarchyAfterUndoRedo is only available in UFE preview version 0.3.5 and greater') - def testGroupHierarchyAfterUndoRedo(self): + @unittest.skipIf(os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') < '3005', 'testGroupUndoRedo is only available in UFE preview version 0.3.5 and greater') + def testGroupUndoRedo(self): '''Verify grouping after multiple undo/redo.''' - pass + cmds.file(new=True, force=True) + + # create a stage + (stage, proxyShapePathStr, proxyShapeItem, contextOp) = createStage(); + + # create a sphere generator + sphereGen = SphereGenerator(3, contextOp, proxyShapePathStr) + + sphere1Path = sphereGen.createSphere() + sphere1Prim = mayaUsd.ufe.ufePathToPrim(ufe.PathString.string(sphere1Path)) + + sphere2Path = sphereGen.createSphere() + sphere2Prim = mayaUsd.ufe.ufePathToPrim(ufe.PathString.string(sphere2Path)) + + sphere3Path = sphereGen.createSphere() + sphere3Prim = mayaUsd.ufe.ufePathToPrim(ufe.PathString.string(sphere3Path)) + + # group Sphere1, Sphere2, and Sphere3 + groupName = cmds.group(ufe.PathString.string(sphere1Path), + ufe.PathString.string(sphere2Path), + ufe.PathString.string(sphere3Path)) + + # verify that groupItem has 3 children + groupItem = ufe.GlobalSelection.get().front() + groupHierarchy = ufe.Hierarchy.hierarchy(groupItem) + self.assertEqual(len(groupHierarchy.children()), 3) + + cmds.undo() + + self.assertEqual([item for item in stage.Traverse()], + [stage.GetPrimAtPath("/Sphere3"), + stage.GetPrimAtPath("/Sphere2"), + stage.GetPrimAtPath("/Sphere1")]) + + cmds.redo() + + self.assertEqual([item for item in stage.Traverse()], + [stage.GetPrimAtPath("/group1"), + stage.GetPrimAtPath("/group1/Sphere1"), + stage.GetPrimAtPath("/group1/Sphere2"), + stage.GetPrimAtPath("/group1/Sphere3")]) + if __name__ == '__main__': unittest.main(verbosity=2) From 7e578fb5eb589b61e28d2170dd98ec30ae4fe381 Mon Sep 17 00:00:00 2001 From: Hamed Sabri Date: Mon, 26 Jul 2021 22:06:16 -0400 Subject: [PATCH 5/7] Fix testUsdGroup to adopt to new interface changes. --- test/lib/ufe/testGroupCmd.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/lib/ufe/testGroupCmd.py b/test/lib/ufe/testGroupCmd.py index 16a2cc11fb..4802e501f5 100644 --- a/test/lib/ufe/testGroupCmd.py +++ b/test/lib/ufe/testGroupCmd.py @@ -131,6 +131,11 @@ def testUsdGroup(self): stage.SetEditTarget(layer) if (os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') > '3000'): + + globalSn = ufe.GlobalSelection.get() + globalSn.append(ball5Item) + globalSn.append(ball3Item) + # group groupName = cmds.group(ufe.PathString.string(ball5Path), ufe.PathString.string(ball3Path), n="newGroup") @@ -179,10 +184,7 @@ def testUsdGroup(self): # gloabl selection should not be empty after undo. if (os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') > '3004'): - pass - # TODO: for some strange reasons the globalSelection returns 0?? - # I tried the same steps in interactive Maya and it correctly returns 2 - # self.assertEqual(len(globalSelection), 2) + self.assertEqual(len(globalSelection), 2) else: self.assertEqual(len(globalSelection), 1) From 7705f64f4beb807d3dfa269c41766520ae8521a0 Mon Sep 17 00:00:00 2001 From: Hamed Sabri Date: Wed, 28 Jul 2021 06:49:30 -0400 Subject: [PATCH 6/7] fix copy-paste damage. --- test/lib/ufe/testGroupCmd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib/ufe/testGroupCmd.py b/test/lib/ufe/testGroupCmd.py index 4802e501f5..e2a7dea5b5 100644 --- a/test/lib/ufe/testGroupCmd.py +++ b/test/lib/ufe/testGroupCmd.py @@ -418,7 +418,7 @@ def testGroupRelative(self): self.assertFalse(spherePrim.HasAttribute('xformOp:rotateXYZ')) self.assertFalse(spherePrim.HasAttribute('xformOp:scale')) - # create a group with absolute flag set to True + # create a group with relative flag set to True cmds.group(ufe.PathString.string(spherePath), relative=True) # verify that groupItem has 1 child From f42f483d13a1bb26585c2660f5fb31a18dd99ded Mon Sep 17 00:00:00 2001 From: Hamed Sabri Date: Wed, 28 Jul 2021 12:24:26 -0400 Subject: [PATCH 7/7] address feedback. --- test/lib/ufe/testGroupCmd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/lib/ufe/testGroupCmd.py b/test/lib/ufe/testGroupCmd.py index e2a7dea5b5..a08d17f7ea 100644 --- a/test/lib/ufe/testGroupCmd.py +++ b/test/lib/ufe/testGroupCmd.py @@ -195,8 +195,8 @@ def testUsdGroup(self): self.assertTrue(newGroupPath not in childPathsUndo) self.assertTrue(ball5Path in childPathsUndo) self.assertTrue(ball3Path in childPathsUndo) - - if ufeUtils.ufeFeatureSetVersion() >= 3: + + if (os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') > '3000'): cmds.redo() else: groupCmd.redo()