/* * 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 #include #include namespace EMotionFX { class CanChangeParametersInSimulatedObjectFixture : public UIFixture { public: }; TEST_F(CanChangeParametersInSimulatedObjectFixture, CanChangeParametersInSimulatedObject) { RecordProperty("test_case_id", "C14519563"); AutoRegisteredActor actor = ActorFactory::CreateAndInit(7, "CanAddToSimulatedObjectActor"); ActorInstance* actorInstance = ActorInstance::Create(actor.get()); // Change the Editor mode to Simulated Objects EMStudio::GetMainWindow()->ApplicationModeChanged("SimulatedObjects"); // Select the newly created actor instance AZStd::string result; EXPECT_TRUE(CommandSystem::GetCommandManager()->ExecuteCommand( AZStd::string{"Select -actorInstanceID "} + AZStd::to_string(actorInstance->GetID()), result)) << result.c_str(); EMotionFX::SkeletonOutlinerPlugin* skeletonOutliner = static_cast( EMStudio::GetPluginManager()->FindActivePlugin(EMotionFX::SkeletonOutlinerPlugin::CLASS_ID)); EXPECT_TRUE(skeletonOutliner); ReselectingTreeView* skeletonTreeView = skeletonOutliner->GetDockWidget()->findChild("EMFX.SkeletonOutlinerPlugin.SkeletonOutlinerTreeView"); EXPECT_TRUE(skeletonTreeView); const QAbstractItemModel* skeletonModel = skeletonTreeView->model(); QModelIndexList indexList; skeletonTreeView->RecursiveGetAllChildren(skeletonModel->index(0, 0), indexList); EXPECT_EQ(indexList.size(), 7); SelectIndexes(indexList, skeletonTreeView, 2, 4); // Bring up the contextMenu so we can add joints to the simulated object const QRect rect = skeletonTreeView->visualRect(indexList[3]); EXPECT_TRUE(rect.isValid()); BringUpContextMenu(skeletonTreeView, rect); QMenu* contextMenu = skeletonOutliner->GetDockWidget()->findChild("EMFX.SkeletonOutlinerPlugin.ContextMenu"); EXPECT_TRUE(contextMenu); QAction* simulatedObjectAction; EXPECT_TRUE(UIFixture::GetActionFromContextMenu(simulatedObjectAction, contextMenu, "Simulated object")); QMenu* simulatedObjectMenu = simulatedObjectAction->menu(); EXPECT_TRUE(simulatedObjectMenu); QAction* addSelectedJointAction; EXPECT_TRUE(UIFixture::GetActionFromContextMenu(addSelectedJointAction, simulatedObjectMenu, "Add selected joints")); QMenu* addSelectedJointMenu = addSelectedJointAction->menu(); EXPECT_TRUE(addSelectedJointMenu); QAction* newSimulatedObjectAction; EXPECT_TRUE(UIFixture::GetActionFromContextMenu(newSimulatedObjectAction, addSelectedJointMenu, "")); newSimulatedObjectAction->trigger(); EMStudio::InputDialogValidatable* inputDialog = qobject_cast(FindTopLevelWidget("EMFX.SimulatedObjectActionManager.SimulatedObjectDialog")); ASSERT_NE(inputDialog, nullptr) << "Cannot find input dialog."; inputDialog->SetText("TestObj"); inputDialog->accept(); // Find the Simulated Object Manager and its button EMotionFX::SimulatedObjectWidget* simulatedObjectWidget = static_cast( EMStudio::GetPluginManager()->FindActivePlugin(EMotionFX::SimulatedObjectWidget::CLASS_ID)); ASSERT_TRUE(simulatedObjectWidget) << "Simulated Object plugin not found!"; ReselectingTreeView* treeView = simulatedObjectWidget->GetDockWidget()->findChild("EMFX.SimulatedObjectWidget.TreeView"); ASSERT_TRUE(treeView); const SimulatedObjectModel* model = reinterpret_cast(treeView->model()); indexList.clear(); treeView->RecursiveGetAllChildren(model->index(0, 0), indexList); EXPECT_EQ(indexList.size(), 4); SelectIndexes(indexList, treeView, 1, 3); // Check all joints have a false AutoExclusion for (int i = 1; i <= 3; ++i) { SimulatedJoint* joint = indexList[i].data(SimulatedObjectModel::ROLE_JOINT_PTR).value(); EXPECT_FALSE(joint->IsGeometricAutoExclusion()); } const SimulatedJointWidget* simulatedJointWidget = simulatedObjectWidget->GetSimulatedJointWidget(); EXPECT_TRUE(simulatedJointWidget) << "SimulatedJointWidget not found."; ObjectEditor* objectEditor = simulatedJointWidget->findChild("EMFX.SimulatedJointWidget.SimulatedJointEditor"); EXPECT_TRUE(objectEditor) << "Can't find Object Editor"; AzToolsFramework::ReflectedPropertyEditor* propertyEditor = objectEditor->findChild("PropertyEditor"); EXPECT_TRUE(propertyEditor) << "Can't find RPE"; AzToolsFramework::PropertyRowWidget* checkBoxWidget = reinterpret_cast( GetNamedPropertyRowWidgetFromReflectedPropertyEditor(propertyEditor, "Geometric auto exclude")); EXPECT_TRUE(checkBoxWidget) << "Geometric Auto Exclude not found"; AzToolsFramework::PropertyCheckBoxCtrl* checkBoxCtrl = reinterpret_cast(checkBoxWidget->GetChildWidget()); EXPECT_TRUE(checkBoxCtrl); QCheckBox* checkBox = checkBoxCtrl->GetCheckBox(); EXPECT_TRUE(checkBox) << "CheckBox not found"; checkBox->click(); // Check all joints have a true AutoExclusion for (int i = 1; i <= 3; ++i) { SimulatedJoint* joint = indexList[i].data(SimulatedObjectModel::ROLE_JOINT_PTR).value(); EXPECT_TRUE(joint->IsGeometricAutoExclusion()); } QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); actorInstance->Destroy(); } } // namespace EMotionFX