CanChangeParametersInSimulatedObject.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 <gtest/gtest.h>
  9. #include <QPushButton>
  10. #include <QAction>
  11. #include <QtTest>
  12. #include <AzToolsFramework/UI/PropertyEditor/PropertyCheckBoxCtrl.hxx>
  13. #include <AzToolsFramework/UI/PropertyEditor/PropertyRowWidget.hxx>
  14. #include <AzToolsFramework/UI/PropertyEditor/ReflectedPropertyEditor.hxx>
  15. #include <Editor/ObjectEditor.h>
  16. #include <Editor/Plugins/SkeletonOutliner/SkeletonOutlinerPlugin.h>
  17. #include <Editor/ReselectingTreeView.h>
  18. #include <Editor/Plugins/SimulatedObject/SimulatedJointWidget.h>
  19. #include <Editor/Plugins/SimulatedObject/SimulatedObjectWidget.h>
  20. #include <Tests/TestAssetCode/SimpleActors.h>
  21. #include <Tests/TestAssetCode/ActorFactory.h>
  22. #include <Tests/TestAssetCode/TestActorAssets.h>
  23. #include <Tests/UI/ModalPopupHandler.h>
  24. #include <Tests/UI/UIFixture.h>
  25. namespace EMotionFX
  26. {
  27. class CanChangeParametersInSimulatedObjectFixture
  28. : public UIFixture
  29. {
  30. public:
  31. };
  32. TEST_F(CanChangeParametersInSimulatedObjectFixture, CanChangeParametersInSimulatedObject)
  33. {
  34. RecordProperty("test_case_id", "C14519563");
  35. AZ::Data::AssetId actorAssetId("{5060227D-B6F4-422E-BF82-41AAC5F228A5}");
  36. AZ::Data::Asset<Integration::ActorAsset> actorAsset =
  37. TestActorAssets::CreateActorAssetAndRegister<SimpleJointChainActor>(actorAssetId, 7, "CanAddToSimulatedObjectActor");
  38. ActorInstance* actorInstance = ActorInstance::Create(actorAsset->GetActor());
  39. // Change the Editor mode to Simulated Objects
  40. EMStudio::GetMainWindow()->ApplicationModeChanged("SimulatedObjects");
  41. // Select the newly created actor instance
  42. AZStd::string result;
  43. EXPECT_TRUE(CommandSystem::GetCommandManager()->ExecuteCommand(
  44. AZStd::string{"Select -actorInstanceID "} + AZStd::to_string(actorInstance->GetID()), result)) << result.c_str();
  45. EMotionFX::SkeletonOutlinerPlugin* skeletonOutliner = static_cast<EMotionFX::SkeletonOutlinerPlugin*>(
  46. EMStudio::GetPluginManager()->FindActivePlugin(EMotionFX::SkeletonOutlinerPlugin::CLASS_ID));
  47. EXPECT_TRUE(skeletonOutliner);
  48. ReselectingTreeView* skeletonTreeView =
  49. skeletonOutliner->GetDockWidget()->findChild<ReselectingTreeView*>("EMFX.SkeletonOutlinerPlugin.SkeletonOutlinerTreeView");
  50. EXPECT_TRUE(skeletonTreeView);
  51. const QAbstractItemModel* skeletonModel = skeletonTreeView->model();
  52. QModelIndexList indexList;
  53. skeletonTreeView->RecursiveGetAllChildren(skeletonModel->index(0, 0, skeletonModel->index(0, 0)), indexList);
  54. EXPECT_EQ(indexList.size(), 7);
  55. SelectIndexes(indexList, skeletonTreeView, 2, 4);
  56. // Bring up the contextMenu so we can add joints to the simulated object
  57. const QRect rect = skeletonTreeView->visualRect(indexList[3]);
  58. EXPECT_TRUE(rect.isValid());
  59. BringUpContextMenu(skeletonTreeView, rect);
  60. QMenu* contextMenu = skeletonOutliner->GetDockWidget()->findChild<QMenu*>("EMFX.SkeletonOutlinerPlugin.ContextMenu");
  61. EXPECT_TRUE(contextMenu);
  62. QAction* addSelectedJointAction;
  63. EXPECT_TRUE(UIFixture::GetActionFromContextMenu(addSelectedJointAction, contextMenu, "Add to simulated object"));
  64. QMenu* addSelectedJointMenu = addSelectedJointAction->menu();
  65. EXPECT_TRUE(addSelectedJointMenu);
  66. QAction* newSimulatedObjectAction;
  67. EXPECT_TRUE(UIFixture::GetActionFromContextMenu(newSimulatedObjectAction, addSelectedJointMenu, "New simulated object..."));
  68. // Handle the add children dialog box.
  69. ModalPopupHandler messageBoxPopupHandler;
  70. messageBoxPopupHandler.WaitForPopupPressDialogButton<QMessageBox*>(QDialogButtonBox::No);
  71. newSimulatedObjectAction->trigger();
  72. EMStudio::InputDialogValidatable* inputDialog =
  73. qobject_cast<EMStudio::InputDialogValidatable*>(FindTopLevelWidget("EMFX.SimulatedObjectActionManager.SimulatedObjectDialog"));
  74. ASSERT_NE(inputDialog, nullptr) << "Cannot find input dialog.";
  75. inputDialog->SetText("TestObj");
  76. inputDialog->accept();
  77. // Find the Simulated Object Manager and its button
  78. EMotionFX::SimulatedObjectWidget* simulatedObjectWidget = static_cast<EMotionFX::SimulatedObjectWidget*>(
  79. EMStudio::GetPluginManager()->FindActivePlugin(EMotionFX::SimulatedObjectWidget::CLASS_ID));
  80. ASSERT_TRUE(simulatedObjectWidget) << "Simulated Object plugin not found!";
  81. ReselectingTreeView* treeView =
  82. simulatedObjectWidget->GetDockWidget()->findChild<ReselectingTreeView*>("EMFX.SimulatedObjectWidget.TreeView");
  83. ASSERT_TRUE(treeView);
  84. const SimulatedObjectModel* model = reinterpret_cast<SimulatedObjectModel*>(treeView->model());
  85. indexList.clear();
  86. treeView->RecursiveGetAllChildren(model->index(0, 0), indexList);
  87. EXPECT_EQ(indexList.size(), 4);
  88. SelectIndexes(indexList, treeView, 1, 3);
  89. // Check all joints have a false AutoExclusion
  90. for (int i = 1; i <= 3; ++i)
  91. {
  92. SimulatedJoint* joint = indexList[i].data(SimulatedObjectModel::ROLE_JOINT_PTR).value<SimulatedJoint*>();
  93. EXPECT_FALSE(joint->IsGeometricAutoExclusion());
  94. }
  95. const SimulatedJointWidget* simulatedJointWidget = simulatedObjectWidget->GetSimulatedJointWidget();
  96. EXPECT_TRUE(simulatedJointWidget) << "SimulatedJointWidget not found.";
  97. ObjectEditor* objectEditor = simulatedJointWidget->findChild<ObjectEditor*>("EMFX.SimulatedJointWidget.SimulatedJointEditor");
  98. EXPECT_TRUE(objectEditor) << "Can't find Object Editor";
  99. AzToolsFramework::ReflectedPropertyEditor* propertyEditor =
  100. objectEditor->findChild<AzToolsFramework::ReflectedPropertyEditor*>("PropertyEditor");
  101. EXPECT_TRUE(propertyEditor) << "Can't find RPE";
  102. AzToolsFramework::PropertyRowWidget* checkBoxWidget = reinterpret_cast<AzToolsFramework::PropertyRowWidget*>(
  103. GetNamedPropertyRowWidgetFromReflectedPropertyEditor(propertyEditor, "Geometric auto exclude"));
  104. EXPECT_TRUE(checkBoxWidget) << "Geometric Auto Exclude not found";
  105. AzToolsFramework::PropertyCheckBoxCtrl* checkBoxCtrl =
  106. reinterpret_cast<AzToolsFramework::PropertyCheckBoxCtrl*>(checkBoxWidget->GetChildWidget());
  107. EXPECT_TRUE(checkBoxCtrl);
  108. QCheckBox* checkBox = checkBoxCtrl->GetCheckBox();
  109. EXPECT_TRUE(checkBox) << "CheckBox not found";
  110. checkBox->click();
  111. // Check all joints have a true AutoExclusion
  112. for (int i = 1; i <= 3; ++i)
  113. {
  114. SimulatedJoint* joint = indexList[i].data(SimulatedObjectModel::ROLE_JOINT_PTR).value<SimulatedJoint*>();
  115. EXPECT_TRUE(joint->IsGeometricAutoExclusion());
  116. }
  117. QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  118. actorInstance->Destroy();
  119. }
  120. } // namespace EMotionFX