/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include #include #include #include #include #include #include #include #include #include #include #include #include namespace QTest { extern int Q_TESTLIB_EXPORT defaultMouseDelay(); } // namespace QTest namespace EMotionFX { class CanAddTransitionAnimGraph : public TwoMotionNodeAnimGraph { public: CanAddTransitionAnimGraph() { GetMotionNodeA()->SetName("node0"); GetMotionNodeA()->SetVisualPos(0, 0); GetMotionNodeB()->SetName("node1"); GetMotionNodeB()->SetVisualPos(100, 0); } }; TEST_F(UIFixture, CanAddTransition) { RecordProperty("test_case_id", "C21948784"); AnimGraphFactory::ReflectTestTypes(GetSerializeContext()); EMotionFX::Integration::AnimGraphAsset* animGraphAsset = aznew EMotionFX::Integration::AnimGraphAsset(); animGraphAsset->SetData(AnimGraphFactory::Create().release()); auto animGraph = static_cast(animGraphAsset->GetAnimGraph()); animGraph->InitAfterLoading(); AZ::Data::Asset asset(animGraphAsset); AZ::Data::AssetBus::Broadcast(&AZ::Data::AssetEvents::OnAssetReady, asset); const AnimGraphMotionNode* nodeA = animGraph->GetMotionNodeA(); const AnimGraphMotionNode* nodeB = animGraph->GetMotionNodeB(); EMStudio::GetMainWindow()->ApplicationModeChanged("AnimGraph"); auto animGraphPlugin = static_cast(EMStudio::GetPluginManager()->FindActivePlugin(EMStudio::AnimGraphPlugin::CLASS_ID)); ASSERT_TRUE(animGraphPlugin) << "AnimGraph plugin not found!"; EMStudio::AnimGraphModel& model = animGraphPlugin->GetAnimGraphModel(); EXPECT_EQ(model.rowCount(), 1) << "AnimGraph does not exist in the model"; animGraphPlugin->SetActiveAnimGraph(animGraphAsset->GetAnimGraph()); EMStudio::BlendGraphWidget* blendGraphWidget = animGraphPlugin->GetGraphWidget(); // The NodeGraph filters out non-visible nodes for efficiency. Resize // the graph to allow the nodes to be visible blendGraphWidget->resize(200, 200); // Zoom to show the whole graph. This updates the visibility flags of // the nodes animGraphPlugin->GetViewWidget()->ZoomSelected(); const EMStudio::GraphNode* graphNodeForMotionNode0 = blendGraphWidget->GetActiveGraph()->FindGraphNode(nodeA); const EMStudio::GraphNode* graphNodeForMotionNode1 = blendGraphWidget->GetActiveGraph()->FindGraphNode(nodeB); const QPoint begin(graphNodeForMotionNode0->GetFinalRect().topRight() + QPoint(-2, 2)); const QPoint end(graphNodeForMotionNode1->GetFinalRect().topLeft() + QPoint(2, 2)); QTest::mousePress(static_cast(blendGraphWidget), Qt::LeftButton, Qt::NoModifier, begin); { // QTest::mouseMove uses QCursor::setPos to generate a MouseMove // event to send to the resulting widget. This won't happen if the // widget isn't visible. So we need to send the event directly. QMouseEvent moveEvent(QMouseEvent::MouseMove, end, Qt::LeftButton, Qt::NoButton, Qt::NoModifier); moveEvent.setTimestamp(QTest::lastMouseTimestamp += QTest::defaultMouseDelay()); QApplication::instance()->notify(blendGraphWidget, &moveEvent); } QTest::mouseRelease(static_cast(blendGraphWidget), Qt::LeftButton, Qt::NoModifier, end); // Ensure the transition was added to the root state machine ASSERT_EQ(animGraphAsset->GetAnimGraph()->GetRootStateMachine()->GetNumTransitions(), 1); // Ensure the transition is in the AnimGraphModel AnimGraphStateTransition* transition = animGraphAsset->GetAnimGraph()->GetRootStateMachine()->GetTransition(0); const QModelIndexList matches = model.match( /* starting index = */ model.index(0, 0, model.index(0, 0)), /* role = */ EMStudio::AnimGraphModel::ROLE_POINTER, /* value = */ QVariant::fromValue(static_cast(transition)), /* hits =*/ 1, Qt::MatchExactly ); EXPECT_EQ(matches.size(), 1); QApplication::processEvents(); } } // namespace EMotionFX