MockGraphCanvas.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. // AZ ...
  10. #include <AzCore/Component/EntityId.h>
  11. #include <AzCore/EBus/EBus.h>
  12. // Graph Canvas ...
  13. #include <GraphCanvas/Components/Nodes/NodeBus.h>
  14. #include <GraphCanvas/Components/Slots/SlotBus.h>
  15. #include <GraphCanvas/Components/Slots/Data/DataSlotBus.h>
  16. #include <GraphCanvas/Components/Slots/Extender/ExtenderSlotBus.h>
  17. #include <GraphCanvas/Editor/EditorTypes.h>
  18. #include <GraphCanvas/GraphCanvasBus.h>
  19. namespace AZ
  20. {
  21. class ReflectContext;
  22. }
  23. namespace MockGraphCanvasServices
  24. {
  25. //! This mocks the GraphCanvas::SlotComponent component.
  26. //! This component is added to a SlotEntity that is created when a Slot is added to a Node.
  27. class MockSlotComponent
  28. : public AZ::Component
  29. {
  30. public:
  31. AZ_COMPONENT(MockSlotComponent, "{030690A4-6D16-4770-89B8-20A2EDF48D87}");
  32. static void Reflect(AZ::ReflectContext* context);
  33. static AZ::Entity* CreateCoreSlotEntity();
  34. MockSlotComponent() = default;
  35. explicit MockSlotComponent(const GraphCanvas::SlotType& slotType);
  36. MockSlotComponent(const GraphCanvas::SlotType& slotType, const GraphCanvas::SlotConfiguration& configuration);
  37. ~MockSlotComponent() override = default;
  38. // Component overrides ...
  39. void Activate() override;
  40. void Deactivate() override;
  41. protected:
  42. GraphCanvas::SlotType m_slotType;
  43. GraphCanvas::SlotConfiguration m_slotConfiguration;
  44. };
  45. //! This mocks the GraphCanvas::DataSlotComponent component.
  46. //! This component is the specific instance of a SlotComponent that is
  47. //! added to a SlotEntity when a DataSlot is added to a Node.
  48. //! Implements the GraphCanvas::DataSlotRequestBus for tests which involve data slots.
  49. class MockDataSlotComponent
  50. : public MockSlotComponent
  51. , public GraphCanvas::DataSlotRequestBus::Handler
  52. {
  53. public:
  54. AZ_COMPONENT(MockDataSlotComponent, "{0E2E8F38-3B7B-427D-ABD6-38C68FDEFE88}", MockSlotComponent);
  55. static void Reflect(AZ::ReflectContext* context);
  56. static AZ::Entity* CreateDataSlot(const GraphCanvas::DataSlotConfiguration& dataSlotConfiguration);
  57. MockDataSlotComponent();
  58. MockDataSlotComponent(const GraphCanvas::DataSlotConfiguration& dataSlotConfiguration);
  59. ~MockDataSlotComponent() = default;
  60. // Component overrides ...
  61. void Activate() override;
  62. void Deactivate() override;
  63. // GraphCanvas::DataSlotRequestBus overrides ...
  64. bool ConvertToReference(bool isNewSlot = false) override;
  65. bool CanConvertToReference(bool isNewSlot = false) const override;
  66. bool ConvertToValue() override;
  67. bool CanConvertToValue() const override;
  68. bool IsUserSlot() const override;
  69. GraphCanvas::DataSlotType GetDataSlotType() const override;
  70. GraphCanvas::DataValueType GetDataValueType() const override;
  71. AZ::Uuid GetDataTypeId() const override;
  72. void SetDataTypeId(AZ::Uuid typeId) override;
  73. const GraphCanvas::Styling::StyleHelper* GetDataColorPalette() const override;
  74. size_t GetContainedTypesCount() const override;
  75. AZ::Uuid GetContainedTypeId(size_t index) const override;
  76. const GraphCanvas::Styling::StyleHelper* GetContainedTypeColorPalette(size_t index) const override;
  77. void SetDataAndContainedTypeIds(AZ::Uuid typeId, const AZStd::vector<AZ::Uuid>& typeIds, GraphCanvas::DataValueType valueType) override;
  78. private:
  79. MockDataSlotComponent(const MockDataSlotComponent&) = delete;
  80. MockDataSlotComponent& operator=(const MockDataSlotComponent&) = delete;
  81. GraphCanvas::DataSlotConfiguration m_dataSlotConfiguration;
  82. };
  83. //! This mocks the GraphCanvas::ExecutionSlotComponent component.
  84. //! This component is the specific instance of a SlotComponent that is
  85. //! added to a SlotEntity when an ExecutionSlot is added to a Node.
  86. class MockExecutionSlotComponent
  87. : public MockSlotComponent
  88. {
  89. public:
  90. AZ_COMPONENT(MockExecutionSlotComponent, "{3E12451C-65EB-45A6-AC98-437F06021359}", MockSlotComponent);
  91. static void Reflect(AZ::ReflectContext* reflectContext);
  92. static AZ::Entity* CreateExecutionSlot(const AZ::EntityId& nodeId, const GraphCanvas::SlotConfiguration& slotConfiguration);
  93. MockExecutionSlotComponent();
  94. explicit MockExecutionSlotComponent(const GraphCanvas::SlotConfiguration& slotConfiguration);
  95. ~MockExecutionSlotComponent() = default;
  96. protected:
  97. MockExecutionSlotComponent(const MockExecutionSlotComponent&) = delete;
  98. MockExecutionSlotComponent& operator=(const MockExecutionSlotComponent&) = delete;
  99. GraphCanvas::SlotConfiguration m_executionSlotConfiguration;
  100. };
  101. //! This mocks the GraphCanvas::ExtenderSlotComponent component.
  102. //! This component is the specific instance of a SlotComponent that is
  103. //! added to a SlotEntity when an ExtenderSlot is added to a Node.
  104. //! Implements the GraphCanvas::ExtenderSlotRequestBus for tests which involve extender slots.
  105. class MockExtenderSlotComponent
  106. : public MockSlotComponent
  107. , public GraphCanvas::ExtenderSlotRequestBus::Handler
  108. {
  109. public:
  110. AZ_COMPONENT(MockExtenderSlotComponent, "{0CAE942E-5E4E-42EC-8F63-809A4DE317C0}", MockSlotComponent);
  111. static void Reflect(AZ::ReflectContext* reflectContext);
  112. static AZ::Entity* CreateExtenderSlot(const AZ::EntityId& nodeId, const GraphCanvas::ExtenderSlotConfiguration& slotConfiguration);
  113. MockExtenderSlotComponent();
  114. explicit MockExtenderSlotComponent(const GraphCanvas::ExtenderSlotConfiguration& slotConfiguration);
  115. ~MockExtenderSlotComponent() = default;
  116. // Component overrides ...
  117. void Activate() override;
  118. void Deactivate() override;
  119. ////
  120. // ExtenderSlotComponent overrides ...
  121. void TriggerExtension() override;
  122. GraphCanvas::Endpoint ExtendForConnectionProposal(const GraphCanvas::ConnectionId& connectionId, const GraphCanvas::Endpoint& endpoint) override;
  123. protected:
  124. MockExtenderSlotComponent(const MockExtenderSlotComponent&) = delete;
  125. MockExtenderSlotComponent& operator=(const MockExtenderSlotComponent&) = delete;
  126. GraphCanvas::ExtenderSlotConfiguration m_extenderSlotConfiguration;
  127. };
  128. //! This mocks the GraphCanvas::NodeComponent component.
  129. //! This component is added to a Node entity when a Node is added to the graph.
  130. //! Implements the GraphCanvas::NodeRequestBus for tests that invole nodes.
  131. class MockNodeComponent
  132. : public AZ::Component
  133. , public GraphCanvas::NodeRequestBus::Handler
  134. {
  135. public:
  136. AZ_COMPONENT(MockNodeComponent, "{886E7216-FD58-442B-AF1E-1AC7174885F8}", AZ::Component);
  137. static void Reflect(AZ::ReflectContext* context);
  138. static AZ::Entity* CreateCoreNodeEntity(const GraphCanvas::NodeConfiguration& config = GraphCanvas::NodeConfiguration());
  139. MockNodeComponent() = default;
  140. MockNodeComponent(const GraphCanvas::NodeConfiguration& config);
  141. ~MockNodeComponent() override = default;
  142. // Component overrides ...
  143. void Activate() override;
  144. void Deactivate() override;
  145. // GraphCanvas::NodeRequestBus overrides ...
  146. void SetTooltip(const AZStd::string& tooltip) override;
  147. const AZStd::string GetTooltip() const override;
  148. void SetShowInOutliner(bool showInOutliner) override;
  149. bool ShowInOutliner() const override;
  150. void AddSlot(const AZ::EntityId& slotId) override;
  151. void RemoveSlot(const AZ::EntityId& slotId) override;
  152. AZStd::vector<AZ::EntityId> GetSlotIds() const override;
  153. AZStd::vector<GraphCanvas::SlotId> GetVisibleSlotIds() const override;
  154. AZStd::vector<GraphCanvas::SlotId> FindVisibleSlotIdsByType(const GraphCanvas::ConnectionType& connectionType, const GraphCanvas::SlotType& slotType) const override;
  155. bool HasConnections() const override;
  156. AZStd::any* GetUserData() override;
  157. bool IsWrapped() const override;
  158. void SetWrappingNode(const AZ::EntityId& wrappingNode) override;
  159. AZ::EntityId GetWrappingNode() const override;
  160. void SignalBatchedConnectionManipulationBegin() override;
  161. void SignalBatchedConnectionManipulationEnd() override;
  162. GraphCanvas::RootGraphicsItemEnabledState UpdateEnabledState() override;
  163. bool IsHidingUnusedSlots() const override;
  164. void ShowAllSlots() override;
  165. void HideUnusedSlots() override;
  166. bool HasHideableSlots() const override;
  167. void SignalConnectionMoveBegin(const GraphCanvas::ConnectionId& connectionId) override;
  168. void SignalNodeAboutToBeDeleted() override;
  169. protected:
  170. /// This node's slots
  171. AZStd::vector<AZ::EntityId> m_slotIds;
  172. /// Serialized configuration settings
  173. GraphCanvas::NodeConfiguration m_configuration;
  174. /// Stores custom user data for this node
  175. AZStd::any m_userData;
  176. };
  177. //! This mocks the GraphCanvas::GraphCanvasSystemComponent component.
  178. //! This component is created and added to the system entity created in our GraphModelIntegrationTest::TestEnvironment
  179. //! because this component implements the GraphCanvas::GraphCanvasRequestBus that is
  180. //! the entry point bus for performing basic GraphCanvas operations such as creating
  181. //! a new scene, creating nodes, creating slots, etc...
  182. class MockGraphCanvasSystemComponent
  183. : public AZ::Component
  184. , private GraphCanvas::GraphCanvasRequestBus::Handler
  185. {
  186. public:
  187. AZ_COMPONENT(MockGraphCanvasSystemComponent, "{03D5474F-5FF3-4D7B-B578-2C3EC132E921}");
  188. static void Reflect(AZ::ReflectContext* context);
  189. MockGraphCanvasSystemComponent() = default;
  190. ~MockGraphCanvasSystemComponent() override = default;
  191. private:
  192. // Component overrides ...
  193. void Activate() override;
  194. void Deactivate() override;
  195. // GraphCanvas::GraphCanvasRequestBus overrides ...
  196. AZ::Entity* CreateBookmarkAnchor() const override;
  197. AZ::Entity* CreateScene() const override;
  198. AZ::Entity* CreateCoreNode() const override;
  199. AZ::Entity* CreateGeneralNode(const char* nodeType) const override;
  200. AZ::Entity* CreateCommentNode() const override;
  201. AZ::Entity* CreateWrapperNode(const char* nodeType) const override;
  202. AZ::Entity* CreateNodeGroup() const override;
  203. AZ::Entity* CreateCollapsedNodeGroup(const GraphCanvas::CollapsedNodeGroupConfiguration& groupedNodeConfiguration) const override;
  204. AZ::Entity* CreateSlot(const AZ::EntityId& nodeId, const GraphCanvas::SlotConfiguration& slotConfiguration) const override;
  205. GraphCanvas::NodePropertyDisplay* CreateBooleanNodePropertyDisplay(GraphCanvas::BooleanDataInterface* dataInterface) const override;
  206. GraphCanvas::NodePropertyDisplay* CreateNumericNodePropertyDisplay(GraphCanvas::NumericDataInterface* dataInterface) const override;
  207. GraphCanvas::NodePropertyDisplay* CreateComboBoxNodePropertyDisplay(GraphCanvas::ComboBoxDataInterface* dataInterface) const override;
  208. GraphCanvas::NodePropertyDisplay* CreateEntityIdNodePropertyDisplay(GraphCanvas::EntityIdDataInterface* dataInterface) const override;
  209. GraphCanvas::NodePropertyDisplay* CreateReadOnlyNodePropertyDisplay(GraphCanvas::ReadOnlyDataInterface* dataInterface) const override;
  210. GraphCanvas::NodePropertyDisplay* CreateStringNodePropertyDisplay(GraphCanvas::StringDataInterface* dataInterface) const override;
  211. GraphCanvas::NodePropertyDisplay* CreateVectorNodePropertyDisplay(GraphCanvas::VectorDataInterface* dataInterface) const override;
  212. GraphCanvas::NodePropertyDisplay* CreateAssetIdNodePropertyDisplay(GraphCanvas::AssetIdDataInterface* dataInterface) const override;
  213. AZ::Entity* CreatePropertySlot(const AZ::EntityId& nodeId, const AZ::Crc32& propertyId, const GraphCanvas::SlotConfiguration& slotConfiguration) const override;
  214. };
  215. }