SimulatedObjectModel.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. #pragma once
  9. #if !defined(Q_MOC_RUN)
  10. #include <AzCore/RTTI/TypeInfo.h>
  11. #include <EMotionFX/Source/Actor.h>
  12. #include <EMotionFX/Source/ActorInstance.h>
  13. #include <EMotionFX/Source/Node.h>
  14. #include <QtCore/QAbstractItemModel>
  15. #include <QtCore/QItemSelectionModel>
  16. #include <Editor/ActorEditorBus.h>
  17. #include <MCore/Source/Command.h>
  18. #include <EMotionFX/Source/SimulatedObjectSetup.h>
  19. #include <QIcon>
  20. #endif
  21. namespace EMotionFX
  22. {
  23. class Skeleton;
  24. class SimulatedCommon;
  25. class SimulatedObject;
  26. class SimulatedJoint;
  27. // Simulated object model
  28. // Columns: Node Name
  29. class SimulatedObjectModel
  30. : public QAbstractItemModel
  31. {
  32. Q_OBJECT // AUTOMOC
  33. public:
  34. enum ColumnIndex
  35. {
  36. COLUMN_NAME
  37. };
  38. enum Role
  39. {
  40. ROLE_OBJECT_PTR = Qt::UserRole,
  41. ROLE_OBJECT_INDEX,
  42. ROLE_OBJECT_NAME,
  43. ROLE_JOINT_PTR,
  44. ROLE_JOINT_BOOL,
  45. ROLE_ACTOR_PTR
  46. };
  47. SimulatedObjectModel();
  48. ~SimulatedObjectModel() override;
  49. // QAbstractItemModel override
  50. QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
  51. QModelIndex parent(const QModelIndex& child) const override;
  52. int rowCount(const QModelIndex& parent = QModelIndex()) const override;
  53. int columnCount(const QModelIndex& parent = QModelIndex()) const override;
  54. QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
  55. QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
  56. Qt::ItemFlags flags(const QModelIndex& index) const override;
  57. const QItemSelectionModel* GetSelectionModel() const { return m_selectionModel; }
  58. QItemSelectionModel* GetSelectionModel() { return m_selectionModel; }
  59. const Actor* GetActor() const { return m_actor; }
  60. void SetActor(Actor* actor);
  61. void SetActorInstance(ActorInstance* actorInstance);
  62. QModelIndex GetModelIndexByObjectIndex(size_t objectIndex);
  63. QModelIndex FindModelIndex(SimulatedObject* object);
  64. void AddJointsToSelection(QItemSelection& selection, size_t objectIndex, const AZStd::vector<size_t>& jointIndices);
  65. private:
  66. // Command callbacks.
  67. void RegisterCommandCallbacks();
  68. void PreAddObject();
  69. void PostAddObject();
  70. void PreRemoveObject(size_t objectIndex);
  71. void PostRemoveObject();
  72. void PostObjectChanged();
  73. // Callbacks
  74. #define SIMULATEDOBJECTMODEL_CALLBACK(CLASSNAME) \
  75. class CLASSNAME \
  76. : public MCore::Command::Callback \
  77. { \
  78. public: \
  79. explicit CLASSNAME(SimulatedObjectModel* simulatedObjectModel, bool executePreUndo = false, bool executePreCommand = false) \
  80. : MCore::Command::Callback(executePreUndo, executePreCommand) \
  81. , m_simulatedObjectModel(simulatedObjectModel) \
  82. {} \
  83. bool Execute(MCore::Command * command, const MCore::CommandLine & commandLine) override; \
  84. bool Undo(MCore::Command * command, const MCore::CommandLine & commandLine) override; \
  85. private: \
  86. SimulatedObjectModel* m_simulatedObjectModel; \
  87. }; \
  88. friend class CLASSNAME;
  89. SIMULATEDOBJECTMODEL_CALLBACK(CommandAddSimulatedObjectPreCallback);
  90. SIMULATEDOBJECTMODEL_CALLBACK(CommandAddSimulatedObjectPostCallback);
  91. SIMULATEDOBJECTMODEL_CALLBACK(CommandRemoveSimulatedObjectPreCallback);
  92. SIMULATEDOBJECTMODEL_CALLBACK(CommandRemoveSimulatedObjectPostCallback);
  93. SIMULATEDOBJECTMODEL_CALLBACK(CommandAdjustSimulatedObjectPostCallback);
  94. SIMULATEDOBJECTMODEL_CALLBACK(CommandAddSimulatedJointsPreCallback);
  95. SIMULATEDOBJECTMODEL_CALLBACK(CommandAddSimulatedJointsPostCallback);
  96. SIMULATEDOBJECTMODEL_CALLBACK(CommandRemoveSimulatedJointsPreCallback);
  97. SIMULATEDOBJECTMODEL_CALLBACK(CommandRemoveSimulatedJointsPostCallback);
  98. SIMULATEDOBJECTMODEL_CALLBACK(CommandAdjustSimulatedJointPostCallback);
  99. static int s_columnCount;
  100. static const char* s_simulatedObjectIconPath;
  101. void InitModel(Actor* actor);
  102. AZStd::vector<MCore::Command::Callback*> m_commandCallbacks;
  103. Skeleton* m_skeleton = nullptr;
  104. Actor* m_actor = nullptr;
  105. ActorInstance* m_actorInstance = nullptr;
  106. QItemSelectionModel* m_selectionModel = nullptr;
  107. QIcon m_objectIcon;
  108. };
  109. } // namespace EMotionFX