Skip to content

Commit

Permalink
MAYA-105277: address feedbacks.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamed Sabri committed Oct 27, 2020
1 parent 688b46a commit 0977cf1
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 46 deletions.
10 changes: 3 additions & 7 deletions lib/mayaUsd/ufe/ProxyShapeHierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,8 @@ Ufe::SceneItem::Ptr ProxyShapeHierarchy::insertChild(
const Ufe::SceneItem::Ptr& pos
)
{
#ifdef UFE_V2_FEATURES_AVAILABLE
auto insertChildCommand = insertChildCmd(child, pos);
return insertChildCommand->insertedChild();
#else
return nullptr;
#endif
}

Ufe::SceneItem::Ptr ProxyShapeHierarchy::createGroup(const Ufe::Selection& selection, const Ufe::PathComponent& name) const
Expand Down Expand Up @@ -257,11 +253,11 @@ Ufe::UndoableCommand::Ptr ProxyShapeHierarchy::reorderCmd(const Ufe::SceneItemLi
orderedTokens.emplace_back(downcast(item)->prim().GetPath().GetNameToken());
}

// TODO HS Oct 23, 2020, grab any child and pass it to UsdUndoReorderCommand
// in order to get the parent out of it.
// create a reorder command and pass in the parent and its ordered children list
const auto& childPrim = downcast((*orderedList.begin()))->prim();
const auto& parentPrim = childPrim.GetParent();

return UsdUndoReorderCommand::create(childPrim, orderedTokens);
return UsdUndoReorderCommand::create(parentPrim, orderedTokens);
}
#endif

Expand Down
18 changes: 7 additions & 11 deletions lib/mayaUsd/ufe/UsdHierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,8 @@ Ufe::SceneItem::Ptr UsdHierarchy::insertChild(
const Ufe::SceneItem::Ptr& pos
)
{
#ifdef UFE_V2_FEATURES_AVAILABLE
auto insertChildCommand = insertChildCmd(child, pos);
return insertChildCommand->insertedChild();
#else
return nullptr;
#endif
}

// Create a transform.
Expand Down Expand Up @@ -248,17 +244,17 @@ Ufe::SceneItem::Ptr UsdHierarchy::defaultParent() const
#if UFE_PREVIEW_VERSION_NUM >= 2026
Ufe::UndoableCommand::Ptr UsdHierarchy::reorderCmd(const Ufe::SceneItemList& orderedList) const
{
std::vector<TfToken> orderedTokens;
std::vector<TfToken> orderedTokens;

for (const auto& item : orderedList) {
orderedTokens.emplace_back(downcast(item)->prim().GetPath().GetNameToken());
}
for (const auto& item : orderedList) {
orderedTokens.emplace_back(downcast(item)->prim().GetPath().GetNameToken());
}

// TODO HS Oct 23, 2020, grab any child and pass it to UsdUndoReorderCommand
// in order to get the parent out of it.
// create a reorder command and pass in the parent and its reordered children list
const auto& childPrim = downcast((*orderedList.begin()))->prim();
const auto& parentPrim = childPrim.GetParent();

return UsdUndoReorderCommand::create(childPrim, orderedTokens);
return UsdUndoReorderCommand::create(parentPrim, orderedTokens);
}
#endif

Expand Down
13 changes: 6 additions & 7 deletions lib/mayaUsd/ufe/UsdUndoReorderCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
namespace MAYAUSD_NS_DEF {
namespace ufe {

UsdUndoReorderCommand::UsdUndoReorderCommand(const UsdPrim& child, const std::vector<TfToken>& tokenList)
UsdUndoReorderCommand::UsdUndoReorderCommand(const UsdPrim& parentPrim, const std::vector<TfToken>& tokenList)
: Ufe::UndoableCommand()
, _childPrim(child)
, _parentPrim(parentPrim)
, _orderedTokens(tokenList)
{
}
Expand All @@ -33,18 +33,17 @@ UsdUndoReorderCommand::~UsdUndoReorderCommand()
{
}

UsdUndoReorderCommand::Ptr UsdUndoReorderCommand::create(const UsdPrim& child, const std::vector<TfToken>& tokenList)
UsdUndoReorderCommand::Ptr UsdUndoReorderCommand::create(const UsdPrim& parentPrim, const std::vector<TfToken>& tokenList)
{
if (!child) {
if (!parentPrim) {
return nullptr;
}
return std::make_shared<UsdUndoReorderCommand>(child, tokenList);
return std::make_shared<UsdUndoReorderCommand>(parentPrim, tokenList);
}

bool UsdUndoReorderCommand::reorder()
{
const auto& parentPrim = _childPrim.GetParent();
const auto& parentPrimSpec = MayaUsdUtils::getPrimSpecAtEditTarget(parentPrim);
const auto& parentPrimSpec = MayaUsdUtils::getPrimSpecAtEditTarget(_parentPrim);

parentPrimSpec->SetNameChildrenOrder(_orderedTokens);

Expand Down
9 changes: 5 additions & 4 deletions lib/mayaUsd/ufe/UsdUndoReorderCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
#include <ufe/undoableCommand.h>

#include <mayaUsd/base/api.h>
#include <mayaUsd/ufe/UsdSceneItem.h>

#include <pxr/usd/usd/prim.h>

PXR_NAMESPACE_USING_DIRECTIVE

Expand All @@ -31,7 +32,7 @@ class MAYAUSD_CORE_PUBLIC UsdUndoReorderCommand : public Ufe::UndoableCommand
public:
typedef std::shared_ptr<UsdUndoReorderCommand> Ptr;

UsdUndoReorderCommand(const UsdPrim& child, const std::vector<TfToken>& orderedTokens);
UsdUndoReorderCommand(const UsdPrim& parentPrim, const std::vector<TfToken>& orderedTokens);
~UsdUndoReorderCommand() override;

// Delete the copy/move constructors assignment operators.
Expand All @@ -41,15 +42,15 @@ class MAYAUSD_CORE_PUBLIC UsdUndoReorderCommand : public Ufe::UndoableCommand
UsdUndoReorderCommand& operator=(UsdUndoReorderCommand&&) = delete;

//! Create a UsdUndoReorderCommand
static UsdUndoReorderCommand::Ptr create(const UsdPrim& child, const std::vector<TfToken>& orderedTokens);
static UsdUndoReorderCommand::Ptr create(const UsdPrim& parentPrim, const std::vector<TfToken>& orderedTokens);

private:
bool reorder();

void undo() override;
void redo() override;

UsdPrim _childPrim;
UsdPrim _parentPrim;

std::vector<TfToken> _orderedTokens;

Expand Down
26 changes: 11 additions & 15 deletions test/lib/ufe/testReorderCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ def testReorderRelative(self):
''' Reorder (a.k.a move) objects relative to their siblings.
For relative moves, both positive and negative numbers may be specified.
'''
shapeSegment = mayaUtils.createUfePathSegment("|world|Primitives_usd|Primitives_usdShape")
cylinderPath = ufe.Path([shapeSegment, usdUtils.createUfePathSegment("/Xform1/Cylinder1")])
cylinderPath = ufe.PathString.path("|Primitives_usd|Primitives_usdShape,/Xform1/Cylinder1")
cylinderItem = ufe.Hierarchy.createItem(cylinderPath)

# start by getting the children from the parent node ( Xform1 )
Expand All @@ -89,18 +88,17 @@ def testFrontBackRelative(self):
'''
Reorder (a.k.a move) to front and back of the sibling list
'''
shapeSegment = mayaUtils.createUfePathSegment("|world|Primitives_usd|Primitives_usdShape")
cylinderPath = ufe.Path([shapeSegment, usdUtils.createUfePathSegment("/Xform1/Cylinder1")])
cylinderPath = ufe.PathString.path("|Primitives_usd|Primitives_usdShape,/Xform1/Cylinder1")
cylinderItem = ufe.Hierarchy.createItem(cylinderPath)

# make Cylinder1 the first sibling ( front )
cmds.reorder("|Primitives_usd|Primitives_usdShape,/Xform1/Cylinder1", front=True)
cmds.reorder(ufe.PathString.string(cylinderPath), front=True)

# check Cylinder1 position ( index ) after the move
self.assertEqual(findIndex(cylinderItem), 0)

# make Cylinder1 the last sibling ( back )
cmds.reorder("|Primitives_usd|Primitives_usdShape,/Xform1/Cylinder1", back=True)
cmds.reorder(ufe.PathString.string(cylinderPath), back=True)

# check Cylinder1 position ( index ) after the move
self.assertEqual(findIndex(cylinderItem), 7)
Expand All @@ -109,22 +107,20 @@ def testUndoRedo(self):
'''
Undo/Redo reorder command
'''
# create multiple items
shapeSegment = mayaUtils.createUfePathSegment("|world|Primitives_usd|Primitives_usdShape")

capsulePath = ufe.Path([shapeSegment, usdUtils.createUfePathSegment("/Xform1/Capsule1")])
# create multiple item
capsulePath = ufe.PathString.path("|Primitives_usd|Primitives_usdShape,/Xform1/Capsule1")
capsuleItem = ufe.Hierarchy.createItem(capsulePath)

conePath = ufe.Path([shapeSegment, usdUtils.createUfePathSegment("/Xform1/Cone1")])
conePath = ufe.PathString.path("|Primitives_usd|Primitives_usdShape,/Xform1/Cone1")
coneItem = ufe.Hierarchy.createItem(conePath)

cubePath = ufe.Path([shapeSegment, usdUtils.createUfePathSegment("/Xform1/Cube1")])
cubePath = ufe.PathString.path("|Primitives_usd|Primitives_usdShape,/Xform1/Cube1")
cubeItem = ufe.Hierarchy.createItem(cubePath)

# move items forward ( + )
cmds.reorder("|Primitives_usd|Primitives_usdShape,/Xform1/Capsule1", r=3)
cmds.reorder("|Primitives_usd|Primitives_usdShape,/Xform1/Cone1", r=3)
cmds.reorder("|Primitives_usd|Primitives_usdShape,/Xform1/Cube1", r=3)
cmds.reorder(ufe.PathString.string(capsulePath), r=3)
cmds.reorder(ufe.PathString.string(conePath), r=3)
cmds.reorder(ufe.PathString.string(cubePath), r=3)

# check positions
self.assertEqual(findIndex(capsuleItem), 1)
Expand Down
3 changes: 1 addition & 2 deletions test/testUtils/mayaUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ def openGroupBallsScene():
return openTestScene("groupBalls", "ballset.ma" )

def openPrimitivesScene():
filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "testSamples", "reorderCmd", "primitives.ma" )
cmds.file(filePath, force=True, open=True)
return openTestScene("reorderCmd", "primitives.ma" )

def createProxyAndStage():
"""
Expand Down

0 comments on commit 0977cf1

Please sign in to comment.