Skip to content

Commit

Permalink
Merge pull request #867 from Autodesk/sabri/MAYA-105277/reorder_suppo…
Browse files Browse the repository at this point in the history
…rt_ufe

MAYA-105277: Initial work to support None-destructive reorder ( move ) of prims relative to their siblings.
  • Loading branch information
Krystian Ligenza authored Oct 28, 2020
2 parents c082142 + 520b36d commit f144c43
Show file tree
Hide file tree
Showing 12 changed files with 578 additions and 28 deletions.
2 changes: 2 additions & 0 deletions lib/mayaUsd/ufe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ if(CMAKE_UFE_V2_FEATURES_AVAILABLE)
UsdUndoAddNewPrimCommand.cpp
UsdUndoCreateGroupCommand.cpp
UsdUndoInsertChildCommand.cpp
UsdUndoReorderCommand.cpp
)
if(UFE_PREVIEW_VERSION_NUM GREATER_EQUAL 2022)
target_sources(${PROJECT_NAME}
Expand Down Expand Up @@ -93,6 +94,7 @@ if(CMAKE_UFE_V2_FEATURES_AVAILABLE)
UsdUndoAddNewPrimCommand.h
UsdUndoCreateGroupCommand.h
UsdUndoInsertChildCommand.h
UsdUndoReorderCommand.h
)
endif()

Expand Down
27 changes: 19 additions & 8 deletions lib/mayaUsd/ufe/ProxyShapeHierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#ifdef UFE_V2_FEATURES_AVAILABLE
#include <mayaUsd/ufe/UsdUndoInsertChildCommand.h>
#include <mayaUsd/ufe/UsdUndoCreateGroupCommand.h>
#include <mayaUsd/ufe/UsdUndoReorderCommand.h>
#endif

namespace {
Expand Down Expand Up @@ -214,16 +215,12 @@ Ufe::InsertChildCommand::Ptr ProxyShapeHierarchy::insertChildCmd(
}

Ufe::SceneItem::Ptr ProxyShapeHierarchy::insertChild(
const Ufe::SceneItem::Ptr& ,
const Ufe::SceneItem::Ptr&
const Ufe::SceneItem::Ptr& child,
const Ufe::SceneItem::Ptr& pos
)
{
// Should be possible to implement trivially when support for returning the
// result of the parent command (MAYA-105278) is implemented. For now,
// Ufe::Hierarchy::insertChildCmd() returns a base class
// Ufe::UndoableCommand::Ptr object, from which we can't retrieve the added
// child. PPT, 13-Jul-2020.
return nullptr;
auto insertChildCommand = insertChildCmd(child, pos);
return insertChildCommand->insertedChild();
}

Ufe::SceneItem::Ptr ProxyShapeHierarchy::createGroup(const Ufe::Selection& selection, const Ufe::PathComponent& name) const
Expand All @@ -247,6 +244,20 @@ Ufe::UndoableCommand::Ptr ProxyShapeHierarchy::createGroupCmd(const Ufe::Selecti
return UsdUndoCreateGroupCommand::create(usdItem, selection, name.string());
}

#if UFE_PREVIEW_VERSION_NUM >= 2026
Ufe::UndoableCommand::Ptr ProxyShapeHierarchy::reorderCmd(const Ufe::SceneItemList& orderedList) const
{
std::vector<TfToken> orderedTokens;

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

// create a reorder command and pass in the parent and its ordered children list
return UsdUndoReorderCommand::create(getUsdRootPrim(), orderedTokens);
}
#endif

Ufe::SceneItem::Ptr ProxyShapeHierarchy::defaultParent() const
{
// Maya shape nodes cannot be unparented.
Expand Down
13 changes: 7 additions & 6 deletions lib/mayaUsd/ufe/ProxyShapeHierarchy.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,17 @@ class MAYAUSD_CORE_PUBLIC ProxyShapeHierarchy : public Ufe::Hierarchy
#endif

#ifdef UFE_V2_FEATURES_AVAILABLE
Ufe::InsertChildCommand::Ptr insertChildCmd(const Ufe::SceneItem::Ptr& child, const Ufe::SceneItem::Ptr& pos) override;

Ufe::SceneItem::Ptr createGroup(const Ufe::Selection& selection, const Ufe::PathComponent& name) const override;
Ufe::UndoableCommand::Ptr createGroupCmd(const Ufe::Selection& selection, const Ufe::PathComponent& name) const override;

Ufe::SceneItem::Ptr defaultParent() const override;
Ufe::SceneItem::Ptr insertChild(
const Ufe::SceneItem::Ptr& child,
const Ufe::SceneItem::Ptr& pos
) override;

Ufe::SceneItem::Ptr insertChild(const Ufe::SceneItem::Ptr& child,const Ufe::SceneItem::Ptr& pos) override;
Ufe::InsertChildCommand::Ptr insertChildCmd(const Ufe::SceneItem::Ptr& child, const Ufe::SceneItem::Ptr& pos) override;

#if UFE_PREVIEW_VERSION_NUM >= 2026
Ufe::UndoableCommand::Ptr reorderCmd(const Ufe::SceneItemList& orderedList) const override;
#endif
#endif

private:
Expand Down
27 changes: 19 additions & 8 deletions lib/mayaUsd/ufe/UsdHierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#ifdef UFE_V2_FEATURES_AVAILABLE
#include <mayaUsd/ufe/UsdUndoCreateGroupCommand.h>
#include <mayaUsd/ufe/UsdUndoInsertChildCommand.h>
#include <mayaUsd/ufe/UsdUndoReorderCommand.h>
#endif

namespace {
Expand Down Expand Up @@ -201,16 +202,12 @@ Ufe::InsertChildCommand::Ptr UsdHierarchy::insertChildCmd(
}

Ufe::SceneItem::Ptr UsdHierarchy::insertChild(
const Ufe::SceneItem::Ptr& ,
const Ufe::SceneItem::Ptr&
const Ufe::SceneItem::Ptr& child,
const Ufe::SceneItem::Ptr& pos
)
{
// Should be possible to implement trivially when support for returning the
// result of the parent command (MAYA-105278) is implemented. For now,
// Ufe::Hierarchy::insertChildCmd() returns a base class
// Ufe::UndoableCommand::Ptr object, from which we can't retrieve the added
// child. PPT, 13-Jul-2020.
return nullptr;
auto insertChildCommand = insertChildCmd(child, pos);
return insertChildCommand->insertedChild();
}

// Create a transform.
Expand Down Expand Up @@ -244,6 +241,20 @@ Ufe::SceneItem::Ptr UsdHierarchy::defaultParent() const
return createItem(proxyShapePath);
}

#if UFE_PREVIEW_VERSION_NUM >= 2026
Ufe::UndoableCommand::Ptr UsdHierarchy::reorderCmd(const Ufe::SceneItemList& orderedList) const
{
std::vector<TfToken> orderedTokens;

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

// create a reorder command and pass in the parent and its reordered children list
return UsdUndoReorderCommand::create(downcast(sceneItem())->prim(), orderedTokens);
}
#endif

#endif // UFE_V2_FEATURES_AVAILABLE

} // namespace ufe
Expand Down
14 changes: 8 additions & 6 deletions lib/mayaUsd/ufe/UsdHierarchy.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,17 @@ class MAYAUSD_CORE_PUBLIC UsdHierarchy : public Ufe::Hierarchy
#endif

#ifdef UFE_V2_FEATURES_AVAILABLE
Ufe::InsertChildCommand::Ptr insertChildCmd(const Ufe::SceneItem::Ptr& child, const Ufe::SceneItem::Ptr& pos) override;

Ufe::SceneItem::Ptr createGroup(const Ufe::Selection& selection, const Ufe::PathComponent& name) const override;
Ufe::UndoableCommand::Ptr createGroupCmd(const Ufe::Selection& selection, const Ufe::PathComponent& name) const override;

Ufe::SceneItem::Ptr defaultParent() const override;
Ufe::SceneItem::Ptr insertChild(
const Ufe::SceneItem::Ptr& child,
const Ufe::SceneItem::Ptr& pos
) override;

Ufe::SceneItem::Ptr insertChild(const Ufe::SceneItem::Ptr& child,const Ufe::SceneItem::Ptr& pos) override;
Ufe::InsertChildCommand::Ptr insertChildCmd(const Ufe::SceneItem::Ptr& child, const Ufe::SceneItem::Ptr& pos) override;

#if UFE_PREVIEW_VERSION_NUM >= 2026
Ufe::UndoableCommand::Ptr reorderCmd(const Ufe::SceneItemList& orderedList) const override;
#endif
#endif

private:
Expand Down
74 changes: 74 additions & 0 deletions lib/mayaUsd/ufe/UsdUndoReorderCommand.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//
// Copyright 2020 Autodesk
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "UsdUndoReorderCommand.h"

#include <ufe/log.h>

#include <mayaUsdUtils/util.h>

namespace MAYAUSD_NS_DEF {
namespace ufe {

UsdUndoReorderCommand::UsdUndoReorderCommand(const UsdPrim& parentPrim, const std::vector<TfToken>& tokenList)
: Ufe::UndoableCommand()
, _parentPrim(parentPrim)
, _orderedTokens(tokenList)
{
}

UsdUndoReorderCommand::~UsdUndoReorderCommand()
{
}

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

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

parentPrimSpec->SetNameChildrenOrder(_orderedTokens);

return true;
}

void UsdUndoReorderCommand::undo()
{
try {
if (!reorder()) {
UFE_LOG("reorder undo failed");
}
}
catch (const std::exception& e) {
UFE_LOG(e.what());
throw; // re-throw the same exception
}
}

void UsdUndoReorderCommand::redo()
{
if (!reorder()) {
UFE_LOG("reorder redo failed");
}
}

} // namespace ufe
} // namespace MayaUsd
60 changes: 60 additions & 0 deletions lib/mayaUsd/ufe/UsdUndoReorderCommand.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// Copyright 2020 Autodesk
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#pragma once

#include <ufe/undoableCommand.h>

#include <mayaUsd/base/api.h>

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

PXR_NAMESPACE_USING_DIRECTIVE

namespace MAYAUSD_NS_DEF {
namespace ufe {

//! \brief UsdUndoReorderCommand
class MAYAUSD_CORE_PUBLIC UsdUndoReorderCommand : public Ufe::UndoableCommand
{
public:
typedef std::shared_ptr<UsdUndoReorderCommand> Ptr;

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

// Delete the copy/move constructors assignment operators.
UsdUndoReorderCommand(const UsdUndoReorderCommand&) = delete;
UsdUndoReorderCommand& operator=(const UsdUndoReorderCommand&) = delete;
UsdUndoReorderCommand(UsdUndoReorderCommand&&) = delete;
UsdUndoReorderCommand& operator=(UsdUndoReorderCommand&&) = delete;

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

private:
bool reorder();

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

UsdPrim _parentPrim;

std::vector<TfToken> _orderedTokens;

}; // UsdUndoReorderCommand

} // namespace ufe
} // namespace MayaUsd
1 change: 1 addition & 0 deletions test/lib/ufe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ if(CMAKE_UFE_V2_FEATURES_AVAILABLE)
testObject3d.py
testRename.py
testParentCmd.py
testReorderCmd.py
testRotateCmd.py
testRotatePivot.py
testScaleCmd.py
Expand Down
Loading

0 comments on commit f144c43

Please sign in to comment.