SimulatedObjectModelCallbacks.cpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 <EMotionFX/Source/Skeleton.h>
  9. #include <Source/Editor/SimulatedObjectModel.h>
  10. #include <EMotionFX/CommandSystem/Source/CommandManager.h>
  11. #include <EMotionFX/CommandSystem/Source/SimulatedObjectCommands.h>
  12. #include <Source/Editor/QtMetaTypes.h>
  13. namespace EMotionFX
  14. {
  15. bool SimulatedObjectModel::CommandAddSimulatedObjectPreCallback::Execute(MCore::Command* command, const MCore::CommandLine& commandLine)
  16. {
  17. AZ_UNUSED(command);
  18. AZ_UNUSED(commandLine);
  19. m_simulatedObjectModel->PreAddObject();
  20. return true;
  21. }
  22. bool SimulatedObjectModel::CommandAddSimulatedObjectPreCallback::Undo(MCore::Command* command, const MCore::CommandLine& commandLine)
  23. {
  24. AZ_UNUSED(commandLine);
  25. CommandAddSimulatedObject* commandAddSimulatedObject = static_cast<CommandAddSimulatedObject*>(command);
  26. m_simulatedObjectModel->PreRemoveObject(commandAddSimulatedObject->GetObjectIndex());
  27. return true;
  28. }
  29. bool SimulatedObjectModel::CommandAddSimulatedObjectPostCallback::Execute(MCore::Command* command, const MCore::CommandLine& commandLine)
  30. {
  31. AZ_UNUSED(command);
  32. AZ_UNUSED(commandLine);
  33. m_simulatedObjectModel->PostAddObject();
  34. return true;
  35. }
  36. bool SimulatedObjectModel::CommandAddSimulatedObjectPostCallback::Undo(MCore::Command* command, const MCore::CommandLine& commandLine)
  37. {
  38. AZ_UNUSED(command);
  39. AZ_UNUSED(commandLine);
  40. m_simulatedObjectModel->PostRemoveObject();
  41. return true;
  42. }
  43. bool SimulatedObjectModel::CommandRemoveSimulatedObjectPreCallback::Execute(MCore::Command* command, const MCore::CommandLine& commandLine)
  44. {
  45. AZ_UNUSED(commandLine);
  46. CommandRemoveSimulatedObject* commandRemoveSimulatedObject = static_cast<CommandRemoveSimulatedObject*>(command);
  47. m_simulatedObjectModel->PreRemoveObject(commandRemoveSimulatedObject->GetObjectIndex());
  48. return true;
  49. }
  50. bool SimulatedObjectModel::CommandRemoveSimulatedObjectPreCallback::Undo(MCore::Command* command, const MCore::CommandLine& commandLine)
  51. {
  52. AZ_UNUSED(command);
  53. AZ_UNUSED(commandLine);
  54. m_simulatedObjectModel->PreAddObject();
  55. return true;
  56. }
  57. bool SimulatedObjectModel::CommandRemoveSimulatedObjectPostCallback::Execute(MCore::Command* command, const MCore::CommandLine& commandLine)
  58. {
  59. AZ_UNUSED(command);
  60. AZ_UNUSED(commandLine);
  61. m_simulatedObjectModel->PostRemoveObject();
  62. return true;
  63. }
  64. bool SimulatedObjectModel::CommandRemoveSimulatedObjectPostCallback::Undo(MCore::Command* command, const MCore::CommandLine& commandLine)
  65. {
  66. AZ_UNUSED(command);
  67. AZ_UNUSED(commandLine);
  68. m_simulatedObjectModel->PostAddObject();
  69. return true;
  70. }
  71. bool SimulatedObjectModel::CommandAdjustSimulatedObjectPostCallback::Execute(MCore::Command* command, const MCore::CommandLine& commandLine)
  72. {
  73. AZ_UNUSED(commandLine);
  74. CommandAdjustSimulatedObject* commandAdjustSimulatedObject = static_cast<CommandAdjustSimulatedObject*>(command);
  75. const QModelIndex objectIndex = m_simulatedObjectModel->index(static_cast<int>(commandAdjustSimulatedObject->GetObjectIndex()), 0);
  76. m_simulatedObjectModel->dataChanged(objectIndex, objectIndex.sibling(objectIndex.row(), m_simulatedObjectModel->columnCount() - 1));
  77. return true;
  78. }
  79. bool SimulatedObjectModel::CommandAdjustSimulatedObjectPostCallback::Undo(MCore::Command* command, const MCore::CommandLine& commandLine)
  80. {
  81. return this->Execute(command, commandLine);
  82. }
  83. bool SimulatedObjectModel::CommandAddSimulatedJointsPreCallback::Execute(MCore::Command* command, const MCore::CommandLine& commandLine)
  84. {
  85. AZ_UNUSED(command);
  86. AZ_UNUSED(commandLine);
  87. m_simulatedObjectModel->beginResetModel();
  88. m_simulatedObjectModel->GetSelectionModel()->clearSelection();
  89. return true;
  90. }
  91. bool SimulatedObjectModel::CommandAddSimulatedJointsPreCallback::Undo(MCore::Command* command, const MCore::CommandLine& commandLine)
  92. {
  93. AZ_UNUSED(command);
  94. AZ_UNUSED(commandLine);
  95. m_simulatedObjectModel->beginResetModel();
  96. m_simulatedObjectModel->GetSelectionModel()->clearSelection();
  97. return true;
  98. }
  99. bool SimulatedObjectModel::CommandAddSimulatedJointsPostCallback::Execute(MCore::Command* command, const MCore::CommandLine& commandLine)
  100. {
  101. AZ_UNUSED(command);
  102. AZ_UNUSED(commandLine);
  103. m_simulatedObjectModel->endResetModel();
  104. return true;
  105. }
  106. bool SimulatedObjectModel::CommandAddSimulatedJointsPostCallback::Undo(MCore::Command* command, const MCore::CommandLine& commandLine)
  107. {
  108. AZ_UNUSED(command);
  109. AZ_UNUSED(commandLine);
  110. m_simulatedObjectModel->endResetModel();
  111. return true;
  112. }
  113. bool SimulatedObjectModel::CommandRemoveSimulatedJointsPreCallback::Execute(MCore::Command* command, const MCore::CommandLine& commandLine)
  114. {
  115. AZ_UNUSED(command);
  116. AZ_UNUSED(commandLine);
  117. m_simulatedObjectModel->beginResetModel();
  118. m_simulatedObjectModel->GetSelectionModel()->clearSelection();
  119. return true;
  120. }
  121. bool SimulatedObjectModel::CommandRemoveSimulatedJointsPreCallback::Undo(MCore::Command* command, const MCore::CommandLine& commandLine)
  122. {
  123. AZ_UNUSED(command);
  124. AZ_UNUSED(commandLine);
  125. m_simulatedObjectModel->beginResetModel();
  126. m_simulatedObjectModel->GetSelectionModel()->clearSelection();
  127. return true;
  128. }
  129. bool SimulatedObjectModel::CommandRemoveSimulatedJointsPostCallback::Execute(MCore::Command* command, const MCore::CommandLine& commandLine)
  130. {
  131. AZ_UNUSED(command);
  132. AZ_UNUSED(commandLine);
  133. m_simulatedObjectModel->endResetModel();
  134. return true;
  135. }
  136. bool SimulatedObjectModel::CommandRemoveSimulatedJointsPostCallback::Undo(MCore::Command* command, const MCore::CommandLine& commandLine)
  137. {
  138. AZ_UNUSED(command);
  139. AZ_UNUSED(commandLine);
  140. m_simulatedObjectModel->endResetModel();
  141. return true;
  142. }
  143. bool SimulatedObjectModel::CommandAdjustSimulatedJointPostCallback::Execute(MCore::Command* command, const MCore::CommandLine& commandLine)
  144. {
  145. AZ_UNUSED(commandLine);
  146. CommandAdjustSimulatedJoint* commandAdjustSimulatedJoint = static_cast<CommandAdjustSimulatedJoint*>(command);
  147. const QModelIndexList foundIndexes = m_simulatedObjectModel->match(
  148. /*start=*/m_simulatedObjectModel->index(0, 0),
  149. /*role=*/SimulatedObjectModel::ROLE_JOINT_PTR,
  150. /*value=*/QVariant::fromValue(commandAdjustSimulatedJoint->GetSimulatedJoint()),
  151. /*hits=*/1,
  152. /*flags=*/Qt::MatchExactly | Qt::MatchRecursive
  153. );
  154. if (foundIndexes.empty())
  155. {
  156. return false;
  157. }
  158. const QModelIndex jointIndex = foundIndexes[0];
  159. m_simulatedObjectModel->dataChanged(jointIndex, jointIndex.sibling(jointIndex.row(), m_simulatedObjectModel->columnCount() - 1));
  160. return true;
  161. }
  162. bool SimulatedObjectModel::CommandAdjustSimulatedJointPostCallback::Undo(MCore::Command* command, const MCore::CommandLine& commandLine)
  163. {
  164. return this->Execute(command, commandLine);
  165. }
  166. } // namespace EMotionFX