CanEditAnimGraphNode.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzTest/AzTest.h>
  9. #include <QApplication>
  10. #include <QAction>
  11. #include <QtTest>
  12. #include <Tests/UI/AnimGraphUIFixture.h>
  13. #include <AzToolsFramework/UI/PropertyEditor/PropertyRowWidget.hxx>
  14. #include "AzToolsFramework/UI/PropertyEditor/PropertyStringLineEditCtrl.hxx"
  15. #include <EMotionFX/Source/AnimGraphMotionNode.h>
  16. #include <EMotionFX/Source/AnimGraphManager.h>
  17. #include <EMotionFX/CommandSystem/Source/CommandManager.h>
  18. #include <Source/Editor/PropertyWidgets/AnimGraphNodeNameHandler.h>
  19. #include <EMotionFX/Source/AnimGraphMotionNode.h>
  20. #include <EMotionStudio/EMStudioSDK/Source/EMStudioManager.h>
  21. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphPlugin.h>
  22. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/BlendGraphWidget.h>
  23. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AttributesWindow.h>
  24. #include <Source/Editor/ObjectEditor.h>
  25. #include <AzToolsFramework/UI/PropertyEditor/ReflectedPropertyEditor.hxx>
  26. namespace EMotionFX
  27. {
  28. TEST_F(UIFixture, CanEditAnimGraphNode)
  29. {
  30. /*
  31. Test Rail ID: C22083483
  32. Expected Result: Making changes to an AnimGraph Node through the Attributes Panel should reflect in the UI
  33. */
  34. RecordProperty("test_case_id", "C22083483");
  35. // Declare useful objects from other namespaces
  36. using AzToolsFramework::PropertyRowWidget;
  37. using AzToolsFramework::ReflectedPropertyEditor;
  38. using EMotionFX::AnimGraphNodeNameLineEdit;
  39. using AzToolsFramework::InstanceDataNode;
  40. // Typedefs to help minimize long defintions
  41. typedef AZStd::pair<InstanceDataNode*, PropertyRowWidget*> WidgetListItem;
  42. typedef AZStd::unordered_map<InstanceDataNode*, PropertyRowWidget*> WidgetList;
  43. // Constants
  44. const AZStd::string originalNodeName = "Original-Node";
  45. const AZStd::string motionNodeID = azrtti_typeid<AnimGraphMotionNode>().ToString<AZStd::string>();
  46. const QString newNodeName = "New-Node";
  47. // Load AnimGraph mode and get useful widgets/objects
  48. EMStudio::GetMainWindow()->ApplicationModeChanged("AnimGraph");
  49. auto animGraphPlugin = static_cast<EMStudio::AnimGraphPlugin*>(EMStudio::GetPluginManager()->FindActivePlugin(EMStudio::AnimGraphPlugin::CLASS_ID));
  50. EMStudio::BlendGraphWidget* graphWidget = animGraphPlugin->GetGraphWidget();
  51. ASSERT_TRUE(graphWidget) << "Failed retrieving BlendGraphWidget";
  52. EMStudio::AttributesWindow* attributesWindow = animGraphPlugin->GetAttributesWindow();
  53. ASSERT_TRUE(attributesWindow) << "Failed retrieving Attributes Window";
  54. // Handle for active AnimGraph
  55. AnimGraph* activeAnimGraph = nullptr;
  56. {
  57. const AZStd::string createAnimGraphCommand = "CreateAnimGraph";
  58. const AZStd::string createNodeCommand = "AnimGraphCreateNode -type " + motionNodeID + " -name " + originalNodeName + " -parentName Root -xPos 1 -yPos 1";
  59. AZStd::string result;
  60. // Create a new AnimGraph
  61. EXPECT_FALSE(animGraphPlugin->GetActiveAnimGraph()) << "Expected there to be no anim graph loaded";
  62. EXPECT_TRUE(CommandSystem::GetCommandManager()->ExecuteCommand(createAnimGraphCommand, result)) << result.c_str();
  63. activeAnimGraph = animGraphPlugin->GetActiveAnimGraph();
  64. ASSERT_TRUE(activeAnimGraph) << "An anim graph was not created with command: " << createAnimGraphCommand.c_str();
  65. // Create a new AnimGraph Node
  66. const size_t nodeCount = activeAnimGraph->GetNumNodes();
  67. EXPECT_TRUE(CommandSystem::GetCommandManager()->ExecuteCommand(createNodeCommand, result)) << result.c_str();
  68. EXPECT_EQ(activeAnimGraph->GetNumNodes(), nodeCount + 1) << "Expected one more anim graph node after running command: " << createNodeCommand.c_str();
  69. }
  70. // Ensure the name of the created node is as expected
  71. AnimGraphNode* node = activeAnimGraph->GetNode(activeAnimGraph->GetNumNodes() - 1);
  72. ASSERT_TRUE(node) << "Failed retrieving node from active animgraph";
  73. EXPECT_EQ(originalNodeName, node->GetName()) << "Expected the created node to have the name: " << originalNodeName.c_str();
  74. // Select the new Graph Node (via left mouse click)
  75. graphWidget->resize(200, 200);
  76. EXPECT_EQ(graphWidget->CalcNumSelectedNodes(), 0) << "Expected to have exactly zero (0) selected nodes";
  77. QRect nodeRect = graphWidget->GetActiveGraph()->FindGraphNode(node)->GetFinalRect();
  78. QTest::mouseClick(graphWidget, Qt::LeftButton, Qt::KeyboardModifiers(), nodeRect.center());
  79. EXPECT_EQ(graphWidget->CalcNumSelectedNodes(), 1) << "Expected to have exactly one (1) selected node";
  80. auto objectEditor = attributesWindow->findChild<ObjectEditor*>("EMFX.AttributesWindow.ObjectEditor");
  81. auto propertyEditor = objectEditor->findChild<ReflectedPropertyEditor*>("PropertyEditor");
  82. // Get list of all PropertyRowWidgets (and their InstanceDataNodes)
  83. const WidgetList list = propertyEditor->GetWidgets();
  84. ASSERT_GT(list.size(), 0) << "Did not find any PropertyRowWidgets";
  85. // Look for PropertyRowWidget for "Name"
  86. PropertyRowWidget* propertyRow = nullptr;
  87. for (const WidgetListItem& item : list)
  88. {
  89. if (item.second->objectName() == "Name")
  90. {
  91. propertyRow = item.second;
  92. }
  93. }
  94. ASSERT_TRUE(propertyRow) << "Could not find the 'Name' PropertyRowWidget";
  95. // Set the text for the textbox to edit AnimGraph Node name
  96. auto lineEdit = static_cast<AnimGraphNodeNameLineEdit*>(propertyRow->GetChildWidget());
  97. lineEdit->setText(newNodeName);
  98. // Push changes in text to the AnimGraph Node
  99. lineEdit->OnEditingFinished();
  100. // Validate the name for the Node has changed
  101. EXPECT_EQ(newNodeName, node->GetName()) << "Expected the created node to have the name: " << newNodeName.toStdString();
  102. // Unselect AnimGraphNode before cleanup
  103. QPoint pt = QPoint(nodeRect.left() - 2, nodeRect.top() - 2); // Some point to click NOT in the AnimGraphNode's rectangle
  104. QTest::mouseClick(graphWidget, Qt::LeftButton, Qt::KeyboardModifiers(), pt);
  105. EXPECT_EQ(graphWidget->CalcNumSelectedNodes(), 0) << "Expected to have exactly zero (0) selected nodes";
  106. } // CanEditAnimGraph
  107. } // EMotionFX namespace