From 13a82e48133fc2808b5452b900bf7e5f8dc8ac3c Mon Sep 17 00:00:00 2001 From: "ADS\\spinell" Date: Fri, 28 May 2021 15:21:19 -0400 Subject: [PATCH 1/7] MAYA-110682 - On drag and drop of a layer with an editTarget, the editTarget moves to the root layer Add a new flag (moveSubPath) to the mayaUsdLayerEditor command --- lib/mayaUsd/commands/layerEditorCommand.cpp | 134 +++++++++++++++++++ lib/usd/ui/layerEditor/abstractCommandHook.h | 3 + lib/usd/ui/layerEditor/layerTreeModel.cpp | 4 +- lib/usd/ui/layerEditor/mayaCommandHook.cpp | 11 ++ lib/usd/ui/layerEditor/mayaCommandHook.h | 3 + test/lib/testMayaUsdLayerEditorCommands.py | 94 +++++++++++++ 6 files changed, 247 insertions(+), 2 deletions(-) diff --git a/lib/mayaUsd/commands/layerEditorCommand.cpp b/lib/mayaUsd/commands/layerEditorCommand.cpp index d456376c10..4e0ee6277e 100644 --- a/lib/mayaUsd/commands/layerEditorCommand.cpp +++ b/lib/mayaUsd/commands/layerEditorCommand.cpp @@ -45,6 +45,8 @@ const char kRemoveSubPathFlag[] = "rs"; const char kRemoveSubPathFlagL[] = "removeSubPath"; const char kReplaceSubPathFlag[] = "rp"; const char kReplaceSubPathFlagL[] = "replaceSubPath"; +const char kMoveSubPathFlag[] = "mv"; +const char kMoveSubPathFlagL[] = "moveSubPath"; const char kDiscardEditsFlag[] = "de"; const char kDiscardEditsFlagL[] = "discardEdits"; const char kClearLayerFlag[] = "cl"; @@ -64,6 +66,7 @@ enum class CmdId { kInsert, kRemove, + kMove, kReplace, kDiscardEdit, kClearLayer, @@ -301,6 +304,118 @@ class RemoveSubPath : public InsertRemoveSubPathBase } }; +// Move a sublayer into another layer. +class MoveSubPath : public BaseCmd +{ +public: + MoveSubPath() + : BaseCmd(CmdId::kMove) + { + } + + bool doIt(SdfLayerHandle layer) override + { + auto proxy = layer->GetSubLayerPaths(); + auto subPathIndex = proxy.Find(_path); + if (subPathIndex == size_t(-1)) { + std::string message = std::string("path ") + _path + + std::string(" not found on layer ") + layer->GetIdentifier(); + MPxCommand::displayError(message.c_str()); + return false; + } + + _oldIndex = subPathIndex; // save for undo + + SdfLayerHandle newParentLayer; + + if (layer->GetIdentifier() == _newParentLayer) { + + if (_newIndex > layer->GetNumSubLayerPaths() - 1) { + std::string message = std::string("Index ") + std::to_string(_newIndex) + + std::string(" out-of-bound for ") + layer->GetIdentifier(); + MPxCommand::displayError(message.c_str()); + return false; + } + + newParentLayer = layer; + } else { + newParentLayer = SdfLayer::Find(_newParentLayer); + if (!newParentLayer) { + std::string message = std::string("Layer ") + _newParentLayer + + std::string(" not found!"); + return false; + } + + if (_newIndex > newParentLayer->GetNumSubLayerPaths()) { + std::string message = std::string("Index ") + std::to_string(_newIndex) + + std::string(" out-of-bound for ") + newParentLayer->GetIdentifier(); + MPxCommand::displayError(message.c_str()); + return false; + } + + // make sure the subpath is not already in the new parent layer. + // Otherwise, the SdfLayer::InsertSubLayerPath() below will do nothing + // and the subpath will be removed from it's current parent. + if (newParentLayer->GetSubLayerPaths().Find(_path) != size_t(-1)) { + std::string message = std::string("SubPath ") + _path + + std::string(" already exist in layer ") + newParentLayer->GetIdentifier(); + MPxCommand::displayError(message.c_str()); + return false; + } + } + + // When the subLayer is moved inside the current parent, + // Remove it from it's current location and insert it into it's + // new location. The order of remove / insert is important + // oterwise InsertSubLayerPath() will fail because the subLayer + // already exists. + layer->RemoveSubLayerPath(subPathIndex); + newParentLayer->InsertSubLayerPath(_path, _newIndex); + + return true; + } + + bool undoIt(SdfLayerHandle layer) override + { + if (layer->GetIdentifier() == _newParentLayer) { + // When the subLayer is moved inside the current parent, + // Remove it from it's current location and insert it into it's + // new location. The order of remove / insert is important + // oterwise InsertSubLayerPath() will fail because the subLayer + // already exists. + layer->RemoveSubLayerPath(_newIndex); + layer->InsertSubLayerPath(_path, _oldIndex); + } else { + auto newParentLayer = SdfLayer::Find(_newParentLayer); + newParentLayer->RemoveSubLayerPath(_newIndex); + layer->InsertSubLayerPath(_path, _oldIndex); + } + + return true; + } + + std::string _path; + std::string _newParentLayer; + unsigned int _newIndex; + +private: + + static bool validateAndReportIndex(SdfLayerHandle layer, int index, int maxIndex) + { + if (index < 0 || index >= maxIndex) { + std::string message = std::string("Index ") + std::to_string(index) + + std::string(" out-of-bound for ") + layer->GetIdentifier(); + MPxCommand::displayError(message.c_str()); + return false; + } else { + return true; + } + } + +private: + unsigned int _oldIndex { 0 }; +}; + class ReplaceSubPath : public BaseCmd { public: @@ -548,6 +663,7 @@ MSyntax LayerEditorCommand::createSyntax() syntax.makeFlagMultiUse(kRemoveSubPathFlag); syntax.addFlag(kReplaceSubPathFlag, kReplaceSubPathFlagL, MSyntax::kString, MSyntax::kString); syntax.makeFlagMultiUse(kReplaceSubPathFlag); + syntax.addFlag(kMoveSubPathFlag, kMoveSubPathFlagL, MSyntax::kString, MSyntax::kString, MSyntax::kUnsigned); syntax.addFlag(kDiscardEditsFlag, kDiscardEditsFlagL); syntax.addFlag(kClearLayerFlag, kClearLayerFlagL); // parameter: new layer name @@ -630,6 +746,24 @@ MStatus LayerEditorCommand::parseArgs(const MArgList& argList) } } + if (argParser.isFlagSet(kMoveSubPathFlag)) { + auto cmd = std::make_shared(); + + MString subPath; + argParser.getFlagArgument(kMoveSubPathFlag, 0, subPath); + + MString newParentLayer; + argParser.getFlagArgument(kMoveSubPathFlag, 1, newParentLayer); + + unsigned int index {0}; + argParser.getFlagArgument(kMoveSubPathFlag, 2, index); + + cmd->_path = subPath.asUTF8(); + cmd->_newParentLayer = newParentLayer.asUTF8(); + cmd->_newIndex = index; + _subCommands.push_back(std::move(cmd)); + } + if (argParser.isFlagSet(kDiscardEditsFlag)) { auto cmd = std::make_shared(); _subCommands.push_back(std::move(cmd)); diff --git a/lib/usd/ui/layerEditor/abstractCommandHook.h b/lib/usd/ui/layerEditor/abstractCommandHook.h index f4a9020bf3..dc2c55d7d3 100644 --- a/lib/usd/ui/layerEditor/abstractCommandHook.h +++ b/lib/usd/ui/layerEditor/abstractCommandHook.h @@ -62,6 +62,9 @@ class AbstractCommandHook // replaces a path in the layer stack virtual void replaceSubLayerPath(UsdLayer usdLayer, Path oldPath, Path newPath) = 0; + // move a path at a given index inside the same layer or another layer. + virtual void moveSubLayerPath(Path path, UsdLayer oldParentUsdLayer, UsdLayer newParentUsdLayer, int index) = 0; + // discard edit on a layer virtual void discardEdits(UsdLayer usdLayer) = 0; diff --git a/lib/usd/ui/layerEditor/layerTreeModel.cpp b/lib/usd/ui/layerEditor/layerTreeModel.cpp index ffaae07220..ff0d776e53 100644 --- a/lib/usd/ui/layerEditor/layerTreeModel.cpp +++ b/lib/usd/ui/layerEditor/layerTreeModel.cpp @@ -177,14 +177,14 @@ bool LayerTreeModel::dropMimeData( auto oldParent = layerItem->parentLayerItem()->layer(); int index = (int)oldParent->GetSubLayerPaths().Find(layerItem->subLayerPath()); auto itemSubLayerPath = layerItem->subLayerPath(); - context.hook()->removeSubLayerPath(oldParent, itemSubLayerPath); + // When we are moving an item (underneath the same parent) // to a new location higher up we have to adjust the row // (new location) to account for the remove we just did. if (oldParent == parentItem->layer() && (index < row)) { row -= 1; } - context.hook()->insertSubLayerPath(parentItem->layer(), itemSubLayerPath, row); + context.hook()->moveSubLayerPath(itemSubLayerPath, oldParent, parentItem->layer(), row); } } } diff --git a/lib/usd/ui/layerEditor/mayaCommandHook.cpp b/lib/usd/ui/layerEditor/mayaCommandHook.cpp index 09b80a5b21..8b6be12863 100644 --- a/lib/usd/ui/layerEditor/mayaCommandHook.cpp +++ b/lib/usd/ui/layerEditor/mayaCommandHook.cpp @@ -108,6 +108,17 @@ void MayaCommandHook::removeSubLayerPath(UsdLayer usdLayer, Path path) executeMel(cmd); } +void MayaCommandHook::moveSubLayerPath(Path path, UsdLayer oldParentUsdLayer, UsdLayer newParentUsdLayer, int index) +{ + std::string cmd; + cmd = "mayaUsdLayerEditor -edit -moveSubPath "; + cmd += quote(path); + cmd += quote(newParentUsdLayer->GetIdentifier()); + cmd += std::to_string(index); + cmd += quote(oldParentUsdLayer->GetIdentifier()); + executeMel(cmd); +} + // replaces a path in the layer stack void MayaCommandHook::replaceSubLayerPath(UsdLayer usdLayer, Path oldPath, Path newPath) { diff --git a/lib/usd/ui/layerEditor/mayaCommandHook.h b/lib/usd/ui/layerEditor/mayaCommandHook.h index 0e97a2d066..371c70a843 100644 --- a/lib/usd/ui/layerEditor/mayaCommandHook.h +++ b/lib/usd/ui/layerEditor/mayaCommandHook.h @@ -44,6 +44,9 @@ class MayaCommandHook : public AbstractCommandHook // replaces a path in the layer stack void replaceSubLayerPath(UsdLayer usdLayer, Path oldPath, Path newPath) override; + // move a path at a given index inside the same layer or another layer. + void moveSubLayerPath(Path path, UsdLayer oldParentUsdLayer, UsdLayer newParentUsdLayer, int index) override; + // discard edit on a layer void discardEdits(UsdLayer usdLayer) override; diff --git a/test/lib/testMayaUsdLayerEditorCommands.py b/test/lib/testMayaUsdLayerEditorCommands.py index f42fd35583..231ad9df07 100644 --- a/test/lib/testMayaUsdLayerEditorCommands.py +++ b/test/lib/testMayaUsdLayerEditorCommands.py @@ -362,6 +362,100 @@ def setAndRemoveEditTargetRecursive(layer, index, editLayer): cmds.undo() self.assertEqual(path.normcase(stage.GetEditTarget().GetLayer().identifier), sharedLayer) + def testMoveSubPath(self): + """ test 'mayaUsdLayerEditor' command 'moveSubPath' paramater """ + + def moveSubPath(parentLayer, subPath, newParentLayer, index, originalSubLayerPaths, newSubLayerPaths): + cmds.mayaUsdLayerEditor(parentLayer.identifier, edit=True, moveSubPath=[subPath, newParentLayer.identifier, index]) + self.assertEqual(newParentLayer.subLayerPaths, newSubLayerPaths) + + cmds.undo() + self.assertEqual(newParentLayer.subLayerPaths, originalSubLayerPaths) + + cmds.redo() + self.assertEqual(newParentLayer.subLayerPaths, newSubLayerPaths) + + cmds.undo() + self.assertEqual(newParentLayer.subLayerPaths, originalSubLayerPaths) + + def moveElement(list, item, index): + l = list.copy() + l.remove(item) + l.insert(index, item) + return l + + shapePath, stage = getCleanMayaStage() + rootLayer = stage.GetRootLayer() + + layerId1 = cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, addAnonymous="MyLayer1")[0] + layerId2 = cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, addAnonymous="MyLayer2")[0] + layerId3 = cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, addAnonymous="MyLayer3")[0] + + originalSubLayerPaths = [layerId3, layerId2, layerId1] + self.assertEqual(rootLayer.subLayerPaths, originalSubLayerPaths) + + # Test moving each layers under the root layer to any valid index in the root layer + # and test out-of-bound index + for layer in originalSubLayerPaths: + for i in range(len(originalSubLayerPaths)): + expectedSubPath = moveElement(originalSubLayerPaths, layer, i) + moveSubPath(rootLayer, layer, rootLayer, i, originalSubLayerPaths, expectedSubPath) + + with self.assertRaises(RuntimeError): + cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, moveSubPath=[layer, rootLayer.identifier, len(originalSubLayerPaths)]) + self.assertEqual(rootLayer.subLayerPaths, originalSubLayerPaths) + + # + # Test moving sublayer (layer2 and layer3) inside a new parent layer (layer1) + # + + layer1 = Sdf.Layer.Find(layerId1) + self.assertTrue(len(layer1.subLayerPaths) == 0) + + # layer1 has no subLayer so index 1 is invalide + with self.assertRaises(RuntimeError): + cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, moveSubPath=[layerId3, layerId1, 1]) + self.assertTrue(len(layer1.subLayerPaths) == 0) + self.assertEqual(rootLayer.subLayerPaths, originalSubLayerPaths) + + # Move layer3 from the root layer inside layer1 at index 0 + cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, moveSubPath=[layerId3, layerId1, 0]) + self.assertEqual(rootLayer.subLayerPaths, [layerId2, layerId1]) + self.assertEqual(layer1.subLayerPaths, [layerId3]) + + # Move layer2 from the root layer inside layer1 at index 0 + cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, moveSubPath=[layerId2, layerId1, 0]) + self.assertEqual(rootLayer.subLayerPaths, [layerId1]) + self.assertEqual(layer1.subLayerPaths, [layerId2, layerId3]) + + cmds.undo() + self.assertEqual(rootLayer.subLayerPaths, [layerId2, layerId1]) + self.assertEqual(layer1.subLayerPaths, [layerId3]) + + # Move layer2 from the root layer inside layer1 at index 1 + cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, moveSubPath=[layerId2, layerId1, 1]) + self.assertEqual(rootLayer.subLayerPaths, [layerId1]) + self.assertEqual(layer1.subLayerPaths, [layerId3, layerId2]) + + cmds.undo() + self.assertEqual(rootLayer.subLayerPaths, [layerId2, layerId1]) + self.assertEqual(layer1.subLayerPaths, [layerId3]) + + # Undo moving layer3 inside layer1 + cmds.undo() + self.assertEqual(rootLayer.subLayerPaths, [layerId3, layerId2, layerId1]) + self.assertEqual(layer1.subLayerPaths, []) + + # Insert layer3 inside layer1 and try to move the layer3 from the root layer + # inside layer1. This should fail. + cmds.mayaUsdLayerEditor(layerId1, edit=True, insertSubPath=[0, layerId3]) + self.assertEqual(layer1.subLayerPaths, [layerId3]) + + with self.assertRaises(RuntimeError): + cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, moveSubPath=[layerId3, layerId1, 0]) + self.assertEqual(rootLayer.subLayerPaths, originalSubLayerPaths) + self.assertEqual(layer1.subLayerPaths, [layerId3]) + def testMuteLayer(self): """ test 'mayaUsdLayerEditor' command 'muteLayer' paramater """ From 9b269339fd4c40306dbb46e5eba05041f431b883 Mon Sep 17 00:00:00 2001 From: "ADS\\spinell" Date: Mon, 31 May 2021 05:30:17 -0400 Subject: [PATCH 2/7] MAYA-110682 - On drag and drop of a layer with an editTarget, the editTarget moves to the root layer Clang format --- lib/mayaUsd/commands/layerEditorCommand.cpp | 28 +++++--------------- lib/usd/ui/layerEditor/abstractCommandHook.h | 4 ++- lib/usd/ui/layerEditor/layerTreeModel.cpp | 3 ++- lib/usd/ui/layerEditor/mayaCommandHook.cpp | 6 ++++- lib/usd/ui/layerEditor/mayaCommandHook.h | 4 ++- 5 files changed, 20 insertions(+), 25 deletions(-) diff --git a/lib/mayaUsd/commands/layerEditorCommand.cpp b/lib/mayaUsd/commands/layerEditorCommand.cpp index 4e0ee6277e..35f1e91869 100644 --- a/lib/mayaUsd/commands/layerEditorCommand.cpp +++ b/lib/mayaUsd/commands/layerEditorCommand.cpp @@ -318,8 +318,8 @@ class MoveSubPath : public BaseCmd auto proxy = layer->GetSubLayerPaths(); auto subPathIndex = proxy.Find(_path); if (subPathIndex == size_t(-1)) { - std::string message = std::string("path ") + _path - + std::string(" not found on layer ") + layer->GetIdentifier(); + std::string message = std::string("path ") + _path + std::string(" not found on layer ") + + layer->GetIdentifier(); MPxCommand::displayError(message.c_str()); return false; } @@ -341,8 +341,8 @@ class MoveSubPath : public BaseCmd } else { newParentLayer = SdfLayer::Find(_newParentLayer); if (!newParentLayer) { - std::string message = std::string("Layer ") + _newParentLayer - + std::string(" not found!"); + std::string message + = std::string("Layer ") + _newParentLayer + std::string(" not found!"); return false; } @@ -360,7 +360,7 @@ class MoveSubPath : public BaseCmd std::string message = std::string("SubPath ") + _path + std::string(" already exist in layer ") + newParentLayer->GetIdentifier(); MPxCommand::displayError(message.c_str()); - return false; + return false; } } @@ -394,24 +394,10 @@ class MoveSubPath : public BaseCmd return true; } - std::string _path; - std::string _newParentLayer; + std::string _path; + std::string _newParentLayer; unsigned int _newIndex; -private: - - static bool validateAndReportIndex(SdfLayerHandle layer, int index, int maxIndex) - { - if (index < 0 || index >= maxIndex) { - std::string message = std::string("Index ") + std::to_string(index) - + std::string(" out-of-bound for ") + layer->GetIdentifier(); - MPxCommand::displayError(message.c_str()); - return false; - } else { - return true; - } - } - private: unsigned int _oldIndex { 0 }; }; diff --git a/lib/usd/ui/layerEditor/abstractCommandHook.h b/lib/usd/ui/layerEditor/abstractCommandHook.h index dc2c55d7d3..45b3cc3317 100644 --- a/lib/usd/ui/layerEditor/abstractCommandHook.h +++ b/lib/usd/ui/layerEditor/abstractCommandHook.h @@ -63,7 +63,9 @@ class AbstractCommandHook virtual void replaceSubLayerPath(UsdLayer usdLayer, Path oldPath, Path newPath) = 0; // move a path at a given index inside the same layer or another layer. - virtual void moveSubLayerPath(Path path, UsdLayer oldParentUsdLayer, UsdLayer newParentUsdLayer, int index) = 0; + virtual void + moveSubLayerPath(Path path, UsdLayer oldParentUsdLayer, UsdLayer newParentUsdLayer, int index) + = 0; // discard edit on a layer virtual void discardEdits(UsdLayer usdLayer) = 0; diff --git a/lib/usd/ui/layerEditor/layerTreeModel.cpp b/lib/usd/ui/layerEditor/layerTreeModel.cpp index ff0d776e53..6639404d94 100644 --- a/lib/usd/ui/layerEditor/layerTreeModel.cpp +++ b/lib/usd/ui/layerEditor/layerTreeModel.cpp @@ -184,7 +184,8 @@ bool LayerTreeModel::dropMimeData( if (oldParent == parentItem->layer() && (index < row)) { row -= 1; } - context.hook()->moveSubLayerPath(itemSubLayerPath, oldParent, parentItem->layer(), row); + context.hook()->moveSubLayerPath( + itemSubLayerPath, oldParent, parentItem->layer(), row); } } } diff --git a/lib/usd/ui/layerEditor/mayaCommandHook.cpp b/lib/usd/ui/layerEditor/mayaCommandHook.cpp index 8b6be12863..6f7ec4e103 100644 --- a/lib/usd/ui/layerEditor/mayaCommandHook.cpp +++ b/lib/usd/ui/layerEditor/mayaCommandHook.cpp @@ -108,7 +108,11 @@ void MayaCommandHook::removeSubLayerPath(UsdLayer usdLayer, Path path) executeMel(cmd); } -void MayaCommandHook::moveSubLayerPath(Path path, UsdLayer oldParentUsdLayer, UsdLayer newParentUsdLayer, int index) +void MayaCommandHook::moveSubLayerPath( + Path path, + UsdLayer oldParentUsdLayer, + UsdLayer newParentUsdLayer, + int index) { std::string cmd; cmd = "mayaUsdLayerEditor -edit -moveSubPath "; diff --git a/lib/usd/ui/layerEditor/mayaCommandHook.h b/lib/usd/ui/layerEditor/mayaCommandHook.h index 371c70a843..a989f6d466 100644 --- a/lib/usd/ui/layerEditor/mayaCommandHook.h +++ b/lib/usd/ui/layerEditor/mayaCommandHook.h @@ -45,7 +45,9 @@ class MayaCommandHook : public AbstractCommandHook void replaceSubLayerPath(UsdLayer usdLayer, Path oldPath, Path newPath) override; // move a path at a given index inside the same layer or another layer. - void moveSubLayerPath(Path path, UsdLayer oldParentUsdLayer, UsdLayer newParentUsdLayer, int index) override; + void + moveSubLayerPath(Path path, UsdLayer oldParentUsdLayer, UsdLayer newParentUsdLayer, int index) + override; // discard edit on a layer void discardEdits(UsdLayer usdLayer) override; From 030c88258634be2e29d527224f406ea791d3769d Mon Sep 17 00:00:00 2001 From: "ADS\\spinell" Date: Mon, 31 May 2021 05:33:18 -0400 Subject: [PATCH 3/7] MAYA-110682 - On drag and drop of a layer with an editTarget, the editTarget moves to the root layer Clang format --- lib/mayaUsd/commands/layerEditorCommand.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/mayaUsd/commands/layerEditorCommand.cpp b/lib/mayaUsd/commands/layerEditorCommand.cpp index 35f1e91869..816e3f4130 100644 --- a/lib/mayaUsd/commands/layerEditorCommand.cpp +++ b/lib/mayaUsd/commands/layerEditorCommand.cpp @@ -649,7 +649,12 @@ MSyntax LayerEditorCommand::createSyntax() syntax.makeFlagMultiUse(kRemoveSubPathFlag); syntax.addFlag(kReplaceSubPathFlag, kReplaceSubPathFlagL, MSyntax::kString, MSyntax::kString); syntax.makeFlagMultiUse(kReplaceSubPathFlag); - syntax.addFlag(kMoveSubPathFlag, kMoveSubPathFlagL, MSyntax::kString, MSyntax::kString, MSyntax::kUnsigned); + syntax.addFlag( + kMoveSubPathFlag, + kMoveSubPathFlagL, + MSyntax::kString, // path to move + MSyntax::kString, // new parent layer + MSyntax::kUnsigned); // layer index inside the new parent syntax.addFlag(kDiscardEditsFlag, kDiscardEditsFlagL); syntax.addFlag(kClearLayerFlag, kClearLayerFlagL); // parameter: new layer name From d2222b21e0528131148d44c0e62c9db249f5077b Mon Sep 17 00:00:00 2001 From: "ADS\\spinell" Date: Mon, 31 May 2021 05:36:56 -0400 Subject: [PATCH 4/7] MAYA-110682 - On drag and drop of a layer with an editTarget, the editTarget moves to the root layer Clang format --- lib/mayaUsd/commands/layerEditorCommand.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mayaUsd/commands/layerEditorCommand.cpp b/lib/mayaUsd/commands/layerEditorCommand.cpp index 816e3f4130..075464e22d 100644 --- a/lib/mayaUsd/commands/layerEditorCommand.cpp +++ b/lib/mayaUsd/commands/layerEditorCommand.cpp @@ -746,7 +746,7 @@ MStatus LayerEditorCommand::parseArgs(const MArgList& argList) MString newParentLayer; argParser.getFlagArgument(kMoveSubPathFlag, 1, newParentLayer); - unsigned int index {0}; + unsigned int index { 0 }; argParser.getFlagArgument(kMoveSubPathFlag, 2, index); cmd->_path = subPath.asUTF8(); From b7a5f42e944cefb1bf0b624b4d23a1737c66e207 Mon Sep 17 00:00:00 2001 From: "ADS\\spinell" Date: Mon, 7 Jun 2021 09:13:25 -0400 Subject: [PATCH 5/7] MAYA-110682 - On drag and drop of a layer with an editTarget, the editTarget moves to the root layer Fix preflight with python 2 --- test/lib/testMayaUsdLayerEditorCommands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib/testMayaUsdLayerEditorCommands.py b/test/lib/testMayaUsdLayerEditorCommands.py index 231ad9df07..593ce443b7 100644 --- a/test/lib/testMayaUsdLayerEditorCommands.py +++ b/test/lib/testMayaUsdLayerEditorCommands.py @@ -379,7 +379,7 @@ def moveSubPath(parentLayer, subPath, newParentLayer, index, originalSubLayerPat self.assertEqual(newParentLayer.subLayerPaths, originalSubLayerPaths) def moveElement(list, item, index): - l = list.copy() + l = list[:] #copy the list l.remove(item) l.insert(index, item) return l From dd65dfa2545dcef79d01afca1e5ded578a497456 Mon Sep 17 00:00:00 2001 From: "ADS\\spinell" Date: Mon, 14 Jun 2021 15:13:53 -0400 Subject: [PATCH 6/7] MAYA-110682 - On drag and drop of a layer with an editTarget, the editTarget moves to the root layer Quick refactoring --- lib/mayaUsd/commands/layerEditorCommand.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/mayaUsd/commands/layerEditorCommand.cpp b/lib/mayaUsd/commands/layerEditorCommand.cpp index 075464e22d..c58c304c06 100644 --- a/lib/mayaUsd/commands/layerEditorCommand.cpp +++ b/lib/mayaUsd/commands/layerEditorCommand.cpp @@ -305,11 +305,17 @@ class RemoveSubPath : public InsertRemoveSubPathBase }; // Move a sublayer into another layer. +// @param path The layer's path to move. +// @param newParentLayer The new parent layer's path +// @param newIndex The index where the moved layer will be in the new parent. class MoveSubPath : public BaseCmd { public: - MoveSubPath() + MoveSubPath(const std::string& path, const std::string& newParentLayer, unsigned newIndex) : BaseCmd(CmdId::kMove) + , _path(path) + , _newParentLayer(newParentLayer) + , _newIndex(newIndex) { } @@ -394,11 +400,10 @@ class MoveSubPath : public BaseCmd return true; } +private: std::string _path; std::string _newParentLayer; unsigned int _newIndex; - -private: unsigned int _oldIndex { 0 }; }; @@ -738,8 +743,6 @@ MStatus LayerEditorCommand::parseArgs(const MArgList& argList) } if (argParser.isFlagSet(kMoveSubPathFlag)) { - auto cmd = std::make_shared(); - MString subPath; argParser.getFlagArgument(kMoveSubPathFlag, 0, subPath); @@ -749,9 +752,8 @@ MStatus LayerEditorCommand::parseArgs(const MArgList& argList) unsigned int index { 0 }; argParser.getFlagArgument(kMoveSubPathFlag, 2, index); - cmd->_path = subPath.asUTF8(); - cmd->_newParentLayer = newParentLayer.asUTF8(); - cmd->_newIndex = index; + auto cmd = std::make_shared( + subPath.asUTF8(), newParentLayer.asUTF8(), index); _subCommands.push_back(std::move(cmd)); } From 6d4ab5993725f4230b6b4093b5a7e07849f8997c Mon Sep 17 00:00:00 2001 From: "ADS\\spinell" Date: Tue, 15 Jun 2021 14:27:09 -0400 Subject: [PATCH 7/7] MAYA-110682 - On drag and drop of a layer with an editTarget, the editTarget moves to the root layer clang format --- lib/mayaUsd/commands/layerEditorCommand.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mayaUsd/commands/layerEditorCommand.cpp b/lib/mayaUsd/commands/layerEditorCommand.cpp index c58c304c06..f225a59e47 100644 --- a/lib/mayaUsd/commands/layerEditorCommand.cpp +++ b/lib/mayaUsd/commands/layerEditorCommand.cpp @@ -306,7 +306,7 @@ class RemoveSubPath : public InsertRemoveSubPathBase // Move a sublayer into another layer. // @param path The layer's path to move. -// @param newParentLayer The new parent layer's path +// @param newParentLayer The new parent layer's path // @param newIndex The index where the moved layer will be in the new parent. class MoveSubPath : public BaseCmd {