From 87c79a6f8ecbd31290c602801ba8977f0aa334bb Mon Sep 17 00:00:00 2001 From: Hamed Sabri Date: Wed, 15 Jul 2020 11:13:00 -0400 Subject: [PATCH 1/5] MAYA-104858: fix regression after UsdUndoAddNewPrimCommand was added. --- lib/mayaUsd/ufe/UsdContextOps.cpp | 61 -------------------- lib/mayaUsd/ufe/UsdUndoAddNewPrimCommand.cpp | 2 +- 2 files changed, 1 insertion(+), 62 deletions(-) diff --git a/lib/mayaUsd/ufe/UsdContextOps.cpp b/lib/mayaUsd/ufe/UsdContextOps.cpp index cd1f4a881c..8b2975c800 100644 --- a/lib/mayaUsd/ufe/UsdContextOps.cpp +++ b/lib/mayaUsd/ufe/UsdContextOps.cpp @@ -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() { @@ -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(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. diff --git a/lib/mayaUsd/ufe/UsdUndoAddNewPrimCommand.cpp b/lib/mayaUsd/ufe/UsdUndoAddNewPrimCommand.cpp index cde5ba01af..8a93229832 100644 --- a/lib/mayaUsd/ufe/UsdUndoAddNewPrimCommand.cpp +++ b/lib/mayaUsd/ufe/UsdUndoAddNewPrimCommand.cpp @@ -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 + std::to_string(1)); // Ensure the requested name is unique. auto newPrimName = uniqueChildName(usdSceneItem, _newUfePath); From 324bff09d53cab1f693fed35c9f0a293b435a34c Mon Sep 17 00:00:00 2001 From: Hamed Sabri Date: Wed, 15 Jul 2020 22:20:48 -0400 Subject: [PATCH 2/5] address feedback. --- lib/mayaUsd/ufe/UsdUndoAddNewPrimCommand.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mayaUsd/ufe/UsdUndoAddNewPrimCommand.cpp b/lib/mayaUsd/ufe/UsdUndoAddNewPrimCommand.cpp index 8a93229832..a0d8b22aee 100644 --- a/lib/mayaUsd/ufe/UsdUndoAddNewPrimCommand.cpp +++ b/lib/mayaUsd/ufe/UsdUndoAddNewPrimCommand.cpp @@ -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 + std::to_string(1)); + _newUfePath = appendToPath(ufePath, name + 1); // Ensure the requested name is unique. auto newPrimName = uniqueChildName(usdSceneItem, _newUfePath); From ccf6173342f8a28749c85f19cf226752e56fb9ed Mon Sep 17 00:00:00 2001 From: Hamed Sabri Date: Thu, 16 Jul 2020 09:04:07 -0400 Subject: [PATCH 3/5] Revert "address feedback." This reverts commit 324bff09d53cab1f693fed35c9f0a293b435a34c. --- lib/mayaUsd/ufe/UsdUndoAddNewPrimCommand.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mayaUsd/ufe/UsdUndoAddNewPrimCommand.cpp b/lib/mayaUsd/ufe/UsdUndoAddNewPrimCommand.cpp index a0d8b22aee..8a93229832 100644 --- a/lib/mayaUsd/ufe/UsdUndoAddNewPrimCommand.cpp +++ b/lib/mayaUsd/ufe/UsdUndoAddNewPrimCommand.cpp @@ -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 + 1); + _newUfePath = appendToPath(ufePath, name + std::to_string(1)); // Ensure the requested name is unique. auto newPrimName = uniqueChildName(usdSceneItem, _newUfePath); From 340fc5da4764a11d9b6fe5f0bdacff31334ea4c1 Mon Sep 17 00:00:00 2001 From: Hamed Sabri Date: Thu, 16 Jul 2020 09:13:12 -0400 Subject: [PATCH 4/5] Address the feedback yet again. Missed the quotes. Feeling good about this already :) --- lib/mayaUsd/ufe/UsdUndoAddNewPrimCommand.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mayaUsd/ufe/UsdUndoAddNewPrimCommand.cpp b/lib/mayaUsd/ufe/UsdUndoAddNewPrimCommand.cpp index 8a93229832..209b368fc0 100644 --- a/lib/mayaUsd/ufe/UsdUndoAddNewPrimCommand.cpp +++ b/lib/mayaUsd/ufe/UsdUndoAddNewPrimCommand.cpp @@ -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 + std::to_string(1)); + _newUfePath = appendToPath(ufePath, name + '1'); // Ensure the requested name is unique. auto newPrimName = uniqueChildName(usdSceneItem, _newUfePath); From bd0942a2a477a2f029c212cfe345067d70065aaa Mon Sep 17 00:00:00 2001 From: Tim Fowler Date: Thu, 16 Jul 2020 16:05:05 -0400 Subject: [PATCH 5/5] MAYA-104858 Fix group cmd test --- test/lib/ufe/testGroupCmd.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/lib/ufe/testGroupCmd.py b/test/lib/ufe/testGroupCmd.py index da354d7576..3823dbb50e 100644 --- a/test/lib/ufe/testGroupCmd.py +++ b/test/lib/ufe/testGroupCmd.py @@ -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)