CanDeleteAnimGraphNode_AnimGraphModelUpdates.cpp 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphPlugin.h>
  9. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphActionManager.h>
  10. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/BlendGraphWidget.h>
  11. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/NodeGraph.h>
  12. #include <EMotionStudio/EMStudioSDK/Source/EMStudioManager.h>
  13. #include <EMotionFX/Source/AnimGraphManager.h>
  14. #include <EMotionFX/Source/AnimGraphStateMachine.h>
  15. #include <Tests/UI/CommandRunnerFixture.h>
  16. namespace EMotionFX
  17. {
  18. class CanDeleteAnimGraphNode
  19. : public CommandRunnerFixture
  20. {
  21. };
  22. TEST_P(CanDeleteAnimGraphNode, CanDeleteAnimGraphNode_AnimGraphModelUpdates)
  23. {
  24. ExecuteCommands(GetParam());
  25. const AZStd::vector<AZStd::string>& results = GetResults();
  26. const AnimGraphConnectionId connectionId = AnimGraphConnectionId::CreateFromString(results.back());
  27. // Pre checks
  28. const AnimGraph* animGraph = GetAnimGraphManager().FindAnimGraphByID(100);
  29. ASSERT_TRUE(animGraph) << "Anim Graph not created";
  30. AnimGraphNode* motionNode0 = animGraph->GetRootStateMachine()->FindChildNode("Motion0");
  31. ASSERT_TRUE(motionNode0) << "Motion0 node not created";
  32. AnimGraphNode* motionNode1 = animGraph->GetRootStateMachine()->FindChildNode("Motion1");
  33. ASSERT_TRUE(motionNode1) << "Motion1 node not created";
  34. AnimGraphStateTransition* connection = animGraph->RecursiveFindTransitionById(connectionId);
  35. ASSERT_TRUE(connection) << "Connection between motion nodes not created";
  36. EMStudio::AnimGraphPlugin* animGraphPlugin = static_cast<EMStudio::AnimGraphPlugin*>(EMStudio::GetPluginManager()->FindActivePlugin(EMStudio::AnimGraphPlugin::CLASS_ID));
  37. ASSERT_TRUE(animGraphPlugin) << "Anim Graph plugin did not load";
  38. EMStudio::AnimGraphModel& model = animGraphPlugin->GetAnimGraphModel();
  39. ASSERT_TRUE(model.FindFirstModelIndex(motionNode0).isValid()) << "Model index for motionNode0 is invalid";
  40. ASSERT_TRUE(model.FindFirstModelIndex(motionNode1).isValid()) << "Model index for motionNode1 is invalid";
  41. ASSERT_TRUE(model.FindFirstModelIndex(connection).isValid()) << "Model index for connection is invalid";
  42. // Select and delete the nodes and connections
  43. animGraphPlugin->GetGraphWidget()->GetActiveGraph()->SelectNodesInRect(QRect(-10, -10, 1000, 1000));
  44. animGraphPlugin->GetActionManager().DeleteSelectedNodes();
  45. // Post checks
  46. motionNode0 = animGraph->GetRootStateMachine()->FindChildNode("Motion0");
  47. ASSERT_FALSE(motionNode0) << "Motion0 node not deleted";
  48. motionNode1 = animGraph->GetRootStateMachine()->FindChildNode("Motion1");
  49. ASSERT_FALSE(motionNode1) << "Motion1 node not deleted";
  50. connection = animGraph->RecursiveFindTransitionById(connectionId);
  51. ASSERT_FALSE(connection) << "Connection between motion nodes not deleted";
  52. ASSERT_FALSE(model.FindFirstModelIndex(motionNode0).isValid()) << "Model index for motionNode0 is still valid";
  53. ASSERT_FALSE(model.FindFirstModelIndex(motionNode1).isValid()) << "Model index for motionNode1 is still valid";
  54. ASSERT_FALSE(model.FindFirstModelIndex(connection).isValid()) << "Model index for connection is still valid";
  55. }
  56. INSTANTIATE_TEST_CASE_P(CanDeleteAnimGraphNode_AnimGraphModelUpdates, CanDeleteAnimGraphNode,
  57. ::testing::Values(std::vector<std::string> {
  58. R"str(CreateAnimGraph -animGraphID 100)str",
  59. R"str(Select -animGraphID 100)str",
  60. R"str(AnimGraphCreateNode -animGraphID 100 -type {B8B8AAE6-E532-4BF8-898F-3D40AA41BC82} -parentName Root -xPos 0 -yPos 0 -name Motion0)str",
  61. R"str(AnimGraphCreateNode -animGraphID 100 -type {B8B8AAE6-E532-4BF8-898F-3D40AA41BC82} -parentName Root -xPos 50 -yPos 0 -name Motion1)str",
  62. R"str(AnimGraphCreateConnection -animGraphID 100 -sourceNode Motion0 -targetNode Motion1 -sourcePort 0 -targetPort 0 -startOffsetX 98 -startOffsetY 17 -endOffsetX 4 -endOffsetY 17 -transitionType {E69C8C6E-7066-43DD-B1BF-0D2FFBDDF457})str",
  63. // Don't add more commands here, the result of the CreateConnection command is used to find a pointer to that connection after the commands have been executed
  64. }
  65. ));
  66. } // end namespace EMotionFX