3
0

AddTransition.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 <AzCore/Asset/AssetCommon.h>
  9. #include <Tests/UI/UIFixture.h>
  10. #include <Tests/TestAssetCode/AnimGraphFactory.h>
  11. #include <EMotionFX/Source/AnimGraphStateMachine.h>
  12. #include <EMotionFX/Source/AnimGraphMotionNode.h>
  13. #include <EMotionStudio/EMStudioSDK/Source/EMStudioManager.h>
  14. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphPlugin.h>
  15. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/GraphNode.h>
  16. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/BlendGraphWidget.h>
  17. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/BlendGraphViewWidget.h>
  18. #include <Integration/Assets/AnimGraphAsset.h>
  19. #include <QApplication>
  20. #include <QtTest>
  21. namespace QTest
  22. {
  23. extern int Q_TESTLIB_EXPORT defaultMouseDelay();
  24. } // namespace QTest
  25. namespace EMotionFX
  26. {
  27. class CanAddTransitionAnimGraph
  28. : public TwoMotionNodeAnimGraph
  29. {
  30. public:
  31. CanAddTransitionAnimGraph()
  32. {
  33. GetMotionNodeA()->SetName("node0");
  34. GetMotionNodeA()->SetVisualPos(0, 0);
  35. GetMotionNodeB()->SetName("node1");
  36. GetMotionNodeB()->SetVisualPos(100, 0);
  37. }
  38. };
  39. TEST_F(UIFixture, CanAddTransition)
  40. {
  41. RecordProperty("test_case_id", "C21948784");
  42. AnimGraphFactory::ReflectTestTypes(GetSerializeContext());
  43. EMotionFX::Integration::AnimGraphAsset* animGraphAsset = aznew EMotionFX::Integration::AnimGraphAsset();
  44. animGraphAsset->SetData(AnimGraphFactory::Create<CanAddTransitionAnimGraph>().release());
  45. auto animGraph = static_cast<TwoMotionNodeAnimGraph*>(animGraphAsset->GetAnimGraph());
  46. animGraph->InitAfterLoading();
  47. AZ::Data::Asset<EMotionFX::Integration::AnimGraphAsset> asset(animGraphAsset, AZ::Data::AssetLoadBehavior::Default);
  48. AZ::Data::AssetBus::Broadcast(&AZ::Data::AssetEvents::OnAssetReady, asset);
  49. const AnimGraphMotionNode* nodeA = animGraph->GetMotionNodeA();
  50. const AnimGraphMotionNode* nodeB = animGraph->GetMotionNodeB();
  51. EMStudio::GetMainWindow()->ApplicationModeChanged("AnimGraph");
  52. auto animGraphPlugin = static_cast<EMStudio::AnimGraphPlugin*>(EMStudio::GetPluginManager()->FindActivePlugin(EMStudio::AnimGraphPlugin::CLASS_ID));
  53. ASSERT_TRUE(animGraphPlugin) << "AnimGraph plugin not found!";
  54. EMStudio::AnimGraphModel& model = animGraphPlugin->GetAnimGraphModel();
  55. EXPECT_EQ(model.rowCount(), 1) << "AnimGraph does not exist in the model";
  56. animGraphPlugin->SetActiveAnimGraph(animGraphAsset->GetAnimGraph());
  57. EMStudio::BlendGraphWidget* blendGraphWidget = animGraphPlugin->GetGraphWidget();
  58. // The NodeGraph filters out non-visible nodes for efficiency. Resize
  59. // the graph to allow the nodes to be visible
  60. blendGraphWidget->resize(200, 200);
  61. // Zoom to show the whole graph. This updates the visibility flags of
  62. // the nodes
  63. animGraphPlugin->GetViewWidget()->ZoomSelected();
  64. const EMStudio::GraphNode* graphNodeForMotionNode0 = blendGraphWidget->GetActiveGraph()->FindGraphNode(nodeA);
  65. const EMStudio::GraphNode* graphNodeForMotionNode1 = blendGraphWidget->GetActiveGraph()->FindGraphNode(nodeB);
  66. const QPoint begin(graphNodeForMotionNode0->GetFinalRect().topRight() + QPoint(-2, 2));
  67. const QPoint end(graphNodeForMotionNode1->GetFinalRect().topLeft() + QPoint(2, 2));
  68. QTest::mousePress(static_cast<QWidget*>(blendGraphWidget), Qt::LeftButton, Qt::NoModifier, begin);
  69. {
  70. // QTest::mouseMove uses QCursor::setPos to generate a MouseMove
  71. // event to send to the resulting widget. This won't happen if the
  72. // widget isn't visible. So we need to send the event directly.
  73. QMouseEvent moveEvent(QMouseEvent::MouseMove, end, Qt::LeftButton, Qt::NoButton, Qt::NoModifier);
  74. moveEvent.setTimestamp(QTest::lastMouseTimestamp += QTest::defaultMouseDelay());
  75. QApplication::instance()->notify(blendGraphWidget, &moveEvent);
  76. }
  77. QTest::mouseRelease(static_cast<QWidget*>(blendGraphWidget), Qt::LeftButton, Qt::NoModifier, end);
  78. // Ensure the transition was added to the root state machine
  79. ASSERT_EQ(animGraphAsset->GetAnimGraph()->GetRootStateMachine()->GetNumTransitions(), 1);
  80. // Ensure the transition is in the AnimGraphModel
  81. AnimGraphStateTransition* transition = animGraphAsset->GetAnimGraph()->GetRootStateMachine()->GetTransition(0);
  82. const QModelIndexList matches = model.match(
  83. /* starting index = */ model.index(0, 0, model.index(0, 0)),
  84. /* role = */ EMStudio::AnimGraphModel::ROLE_POINTER,
  85. /* value = */ QVariant::fromValue(static_cast<void*>(transition)),
  86. /* hits =*/ 1,
  87. Qt::MatchExactly
  88. );
  89. EXPECT_EQ(matches.size(), 1);
  90. QApplication::processEvents();
  91. }
  92. } // namespace EMotionFX