Skip to content

Commit

Permalink
Merge pull request #663 from Autodesk/sabrih/MAYA-104858/fix_regression
Browse files Browse the repository at this point in the history
MAYA-104858: fix regression after UsdUndoAddNewPrimCommand was introduced.
  • Loading branch information
Krystian Ligenza authored Jul 19, 2020
2 parents 7e14067 + bd0942a commit 8daa8f2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 63 deletions.
61 changes: 0 additions & 61 deletions lib/mayaUsd/ufe/UsdContextOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,63 +93,6 @@ class SetVariantSelectionUndoableCommand : public Ufe::UndoableCommand
const std::string fNewSelection;
};

#if UFE_PREVIEW_VERSION_NUM < 2017
//! \brief Undoable command for add new prim
class AddNewPrimUndoableCommand : public Ufe::UndoableCommand
{
public:
AddNewPrimUndoableCommand(const MayaUsd::ufe::UsdSceneItem::Ptr& usdSceneItem,
const Ufe::ContextOps::ItemPath& itemPath)
: Ufe::UndoableCommand()
{
// First get the stage from the proxy shape.
auto ufePath = usdSceneItem->path();
auto segments = ufePath.getSegments();
auto dagSegment = segments[0];
_stage = MayaUsd::ufe::getStage(Ufe::Path(dagSegment));
if (_stage) {
// Rename the new prim for uniqueness, if needed.
// When we have a gateway type node, the prim we'll be adding will be
// in a different runtime (USD vs Maya). So technically just appending
// itemPath[1] isn't correct. But in this case it is only used by
// uniqueChildName() which just takes the back of the path for child
// name, so it's fine.
Ufe::Path newUfePath = ufePath + (itemPath[1] + std::to_string(1));
auto newPrimName = uniqueChildName(usdSceneItem, newUfePath);

// Build (and store) the path for the new prim with the unique name.
PXR_NS::SdfPath usdItemPath = usdSceneItem->prim().GetPath();
_primPath = usdItemPath.AppendChild(PXR_NS::TfToken(newPrimName));

// The type of prim we were asked to create.
// Note: "Def" means create typeless prim.
_primToken = (itemPath[1] == kUSDDefPrimItem) ? TfToken() : TfToken(itemPath[1]);
}
}

void undo() override
{
if (_stage) {
_stage->RemovePrim(_primPath);
}
}

void redo() override
{
if (_stage) {
auto newPrim = _stage->DefinePrim(_primPath, _primToken);
if (!newPrim.IsValid())
TF_RUNTIME_ERROR("Failed to create new prim type: %s", _primToken.GetText());
}
}

private:
PXR_NS::UsdStageWeakPtr _stage;
PXR_NS::SdfPath _primPath;
PXR_NS::TfToken _primToken;
};
#endif

const char* selectUSDFileScript = R"(
global proc string SelectUSDFileForAddReference()
{
Expand Down Expand Up @@ -417,11 +360,7 @@ Ufe::UndoableCommand::Ptr UsdContextOps::doOpCmd(const ItemPath& itemPath)

// At this point we know we have 2 arguments to execute the operation.
// itemPath[1] contains the new prim type to create.
#if UFE_PREVIEW_VERSION_NUM < 2017
return std::make_shared<AddNewPrimUndoableCommand>(fItem, itemPath);
#else
return UsdUndoAddNewPrimCommand::create(fItem, itemPath[1], itemPath[1]);
#endif
}
else if (itemPath[0] == kUSDLayerEditorItem) {
// Just open the editor directly and return null so we don't have undo.
Expand Down
2 changes: 1 addition & 1 deletion lib/mayaUsd/ufe/UsdUndoAddNewPrimCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ UsdUndoAddNewPrimCommand::UsdUndoAddNewPrimCommand(const UsdSceneItem::Ptr& usdS
_stage = usdSceneItem->prim().GetStage();
if (_stage) {
// Append the parent path and the requested name into a full ufe path.
_newUfePath = appendToPath(ufePath, name);
_newUfePath = appendToPath(ufePath, name + '1');

// Ensure the requested name is unique.
auto newPrimName = uniqueChildName(usdSceneItem, _newUfePath);
Expand Down
5 changes: 4 additions & 1 deletion test/lib/ufe/testGroupCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,12 @@ def testUsdGroup(self):
parentChildrenPost = parentHierarchy.children()
self.assertEqual(len(parentChildrenPost), 34)

newGroupPath = parentPath + newGroupName
# The command will now append a number 1 at the end to match the naming
# convention in Maya.
newGroupPath = parentPath + ufe.PathComponent("newGroup1")

childPaths = set([child.path() for child in parentChildrenPost])

self.assertTrue(newGroupPath in childPaths)
self.assertTrue(ball25Path not in childPaths)
self.assertTrue(ball35Path not in childPaths)
Expand Down

0 comments on commit 8daa8f2

Please sign in to comment.