MockGraphCanvas.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  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 <Tests/MockGraphCanvas.h>
  9. namespace MockGraphCanvasServices
  10. {
  11. // MockSlotComponent
  12. void MockSlotComponent::Reflect(AZ::ReflectContext* context)
  13. {
  14. if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  15. {
  16. serializeContext->Class<MockSlotComponent, AZ::Component>()
  17. ->Version(0)
  18. ;
  19. }
  20. }
  21. AZ::Entity* MockSlotComponent::CreateCoreSlotEntity()
  22. {
  23. AZ::Entity* entity = aznew AZ::Entity("Slot");
  24. return entity;
  25. }
  26. MockSlotComponent::MockSlotComponent(const GraphCanvas::SlotType& slotType)
  27. : m_slotType(slotType)
  28. {
  29. }
  30. MockSlotComponent::MockSlotComponent(const GraphCanvas::SlotType& slotType, const GraphCanvas::SlotConfiguration& configuration)
  31. : m_slotType(slotType)
  32. , m_slotConfiguration(configuration)
  33. {
  34. }
  35. void MockSlotComponent::Activate()
  36. {
  37. }
  38. void MockSlotComponent::Deactivate()
  39. {
  40. }
  41. // MockDataSlotComponent
  42. void MockDataSlotComponent::Reflect(AZ::ReflectContext* context)
  43. {
  44. if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  45. {
  46. serializeContext->Class<MockDataSlotComponent, MockSlotComponent>()
  47. ->Version(0)
  48. ;
  49. }
  50. }
  51. AZ::Entity* MockDataSlotComponent::CreateDataSlot(const GraphCanvas::DataSlotConfiguration& dataSlotConfiguration)
  52. {
  53. AZ::Entity* entity = MockSlotComponent::CreateCoreSlotEntity();
  54. MockDataSlotComponent* dataSlot = aznew MockDataSlotComponent(dataSlotConfiguration);
  55. if (!entity->AddComponent(dataSlot))
  56. {
  57. delete dataSlot;
  58. delete entity;
  59. return nullptr;
  60. }
  61. return entity;
  62. }
  63. MockDataSlotComponent::MockDataSlotComponent()
  64. : MockSlotComponent(GraphCanvas::SlotTypes::DataSlot)
  65. {
  66. }
  67. MockDataSlotComponent::MockDataSlotComponent(const GraphCanvas::DataSlotConfiguration& dataSlotConfiguration)
  68. : MockSlotComponent(GraphCanvas::SlotTypes::DataSlot, dataSlotConfiguration)
  69. , m_dataSlotConfiguration(dataSlotConfiguration)
  70. {
  71. }
  72. void MockDataSlotComponent::Activate()
  73. {
  74. GraphCanvas::DataSlotRequestBus::Handler::BusConnect(GetEntityId());
  75. }
  76. void MockDataSlotComponent::Deactivate()
  77. {
  78. GraphCanvas::DataSlotRequestBus::Handler::BusDisconnect();
  79. }
  80. bool MockDataSlotComponent::ConvertToReference([[maybe_unused]] bool isNewSlot)
  81. {
  82. return false;
  83. }
  84. bool MockDataSlotComponent::CanConvertToReference([[maybe_unused]] bool isNewSlot) const
  85. {
  86. return false;
  87. }
  88. bool MockDataSlotComponent::IsUserSlot() const
  89. {
  90. return false;
  91. }
  92. bool MockDataSlotComponent::ConvertToValue()
  93. {
  94. return false;
  95. }
  96. bool MockDataSlotComponent::CanConvertToValue() const
  97. {
  98. return false;
  99. }
  100. GraphCanvas::DataSlotType MockDataSlotComponent::GetDataSlotType() const
  101. {
  102. return m_dataSlotConfiguration.m_dataSlotType;
  103. }
  104. GraphCanvas::DataValueType MockDataSlotComponent::GetDataValueType() const
  105. {
  106. return m_dataSlotConfiguration.m_dataValueType;
  107. }
  108. AZ::Uuid MockDataSlotComponent::GetDataTypeId() const
  109. {
  110. return m_dataSlotConfiguration.m_typeId;
  111. }
  112. void MockDataSlotComponent::SetDataTypeId(AZ::Uuid typeId)
  113. {
  114. m_dataSlotConfiguration.m_typeId = typeId;
  115. }
  116. const GraphCanvas::Styling::StyleHelper* MockDataSlotComponent::GetDataColorPalette() const
  117. {
  118. return nullptr;
  119. }
  120. size_t MockDataSlotComponent::GetContainedTypesCount() const
  121. {
  122. return m_dataSlotConfiguration.m_containerTypeIds.size();
  123. }
  124. AZ::Uuid MockDataSlotComponent::GetContainedTypeId(size_t index) const
  125. {
  126. return m_dataSlotConfiguration.m_containerTypeIds[index];
  127. }
  128. const GraphCanvas::Styling::StyleHelper* MockDataSlotComponent::GetContainedTypeColorPalette([[maybe_unused]] size_t index) const
  129. {
  130. return nullptr;
  131. }
  132. void MockDataSlotComponent::SetDataAndContainedTypeIds(AZ::Uuid typeId, const AZStd::vector<AZ::Uuid>& typeIds, GraphCanvas::DataValueType valueType)
  133. {
  134. AZ_UNUSED(typeId);
  135. AZ_UNUSED(typeIds);
  136. AZ_UNUSED(valueType);
  137. }
  138. // MockExecutionSlotComponent
  139. void MockExecutionSlotComponent::Reflect(AZ::ReflectContext* context)
  140. {
  141. if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  142. {
  143. serializeContext->Class<MockExecutionSlotComponent, MockSlotComponent>()
  144. ->Version(0)
  145. ;
  146. }
  147. }
  148. AZ::Entity* MockExecutionSlotComponent::CreateExecutionSlot(const AZ::EntityId& nodeId, const GraphCanvas::SlotConfiguration& slotConfiguration)
  149. {
  150. AZ_UNUSED(nodeId);
  151. AZ::Entity* entity = MockSlotComponent::CreateCoreSlotEntity();
  152. MockExecutionSlotComponent* executionSlot = aznew MockExecutionSlotComponent(slotConfiguration);
  153. if (!entity->AddComponent(executionSlot))
  154. {
  155. delete executionSlot;
  156. delete entity;
  157. return nullptr;
  158. }
  159. return entity;
  160. }
  161. MockExecutionSlotComponent::MockExecutionSlotComponent()
  162. : MockSlotComponent(GraphCanvas::SlotTypes::ExecutionSlot)
  163. {
  164. }
  165. MockExecutionSlotComponent::MockExecutionSlotComponent(const GraphCanvas::SlotConfiguration& slotConfiguration)
  166. : MockSlotComponent(GraphCanvas::SlotTypes::ExecutionSlot, slotConfiguration)
  167. , m_executionSlotConfiguration(slotConfiguration)
  168. {
  169. }
  170. // MockExtenderSlotComponent
  171. void MockExtenderSlotComponent::Reflect(AZ::ReflectContext* context)
  172. {
  173. if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  174. {
  175. serializeContext->Class<MockExtenderSlotComponent, MockSlotComponent>()
  176. ->Version(0)
  177. ;
  178. }
  179. }
  180. AZ::Entity* MockExtenderSlotComponent::CreateExtenderSlot(const AZ::EntityId& nodeId, const GraphCanvas::ExtenderSlotConfiguration& slotConfiguration)
  181. {
  182. AZ_UNUSED(nodeId);
  183. AZ::Entity* entity = MockSlotComponent::CreateCoreSlotEntity();
  184. MockExtenderSlotComponent* extenderSlot = aznew MockExtenderSlotComponent(slotConfiguration);
  185. if (!entity->AddComponent(extenderSlot))
  186. {
  187. delete extenderSlot;
  188. delete entity;
  189. return nullptr;
  190. }
  191. return entity;
  192. }
  193. MockExtenderSlotComponent::MockExtenderSlotComponent()
  194. : MockSlotComponent(GraphCanvas::SlotTypes::ExtenderSlot)
  195. {
  196. }
  197. MockExtenderSlotComponent::MockExtenderSlotComponent(const GraphCanvas::ExtenderSlotConfiguration& slotConfiguration)
  198. : MockSlotComponent(GraphCanvas::SlotTypes::ExtenderSlot, slotConfiguration)
  199. , m_extenderSlotConfiguration(slotConfiguration)
  200. {
  201. }
  202. void MockExtenderSlotComponent::Activate()
  203. {
  204. GraphCanvas::ExtenderSlotRequestBus::Handler::BusConnect(GetEntityId());
  205. }
  206. void MockExtenderSlotComponent::Deactivate()
  207. {
  208. GraphCanvas::ExtenderSlotRequestBus::Handler::BusDisconnect();
  209. }
  210. void MockExtenderSlotComponent::TriggerExtension()
  211. {
  212. }
  213. GraphCanvas::Endpoint MockExtenderSlotComponent::ExtendForConnectionProposal(const GraphCanvas::ConnectionId& connectionId, const GraphCanvas::Endpoint& endpoint)
  214. {
  215. AZ_UNUSED(connectionId);
  216. AZ_UNUSED(endpoint);
  217. return GraphCanvas::Endpoint();
  218. }
  219. // MockNodeComponent
  220. void MockNodeComponent::Reflect(AZ::ReflectContext* context)
  221. {
  222. if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  223. {
  224. serializeContext->Class<MockNodeComponent, AZ::Component>()
  225. ->Version(0)
  226. ;
  227. }
  228. }
  229. AZ::Entity* MockNodeComponent::CreateCoreNodeEntity(const GraphCanvas::NodeConfiguration& config)
  230. {
  231. // Create this Node's entity.
  232. AZ::Entity* entity = aznew AZ::Entity();
  233. entity->CreateComponent<MockNodeComponent>(config);
  234. return entity;
  235. }
  236. MockNodeComponent::MockNodeComponent(const GraphCanvas::NodeConfiguration& config)
  237. : m_configuration(config)
  238. {
  239. }
  240. void MockNodeComponent::Activate()
  241. {
  242. GraphCanvas::NodeRequestBus::Handler::BusConnect(GetEntityId());
  243. }
  244. void MockNodeComponent::Deactivate()
  245. {
  246. GraphCanvas::NodeRequestBus::Handler::BusDisconnect();
  247. }
  248. void MockNodeComponent::SetTooltip(const AZStd::string& tooltip)
  249. {
  250. m_configuration.SetTooltip(tooltip);
  251. }
  252. const AZStd::string MockNodeComponent::GetTooltip() const
  253. {
  254. return m_configuration.GetTooltip();
  255. }
  256. void MockNodeComponent::SetShowInOutliner(bool showInOutliner)
  257. {
  258. m_configuration.SetShowInOutliner(showInOutliner);
  259. }
  260. bool MockNodeComponent::ShowInOutliner() const
  261. {
  262. return m_configuration.GetShowInOutliner();
  263. }
  264. void MockNodeComponent::AddSlot(const AZ::EntityId& slotId)
  265. {
  266. AZ_Assert(slotId.IsValid(), "Slot entity (ID: %s) is not valid!", slotId.ToString().data());
  267. m_slotIds.emplace_back(slotId);
  268. }
  269. void MockNodeComponent::RemoveSlot(const AZ::EntityId& slotId)
  270. {
  271. AZ_Assert(slotId.IsValid(), "Slot (ID: %s) is not valid!", slotId.ToString().data());
  272. auto entry = AZStd::find(m_slotIds.begin(), m_slotIds.end(), slotId);
  273. AZ_Assert(entry != m_slotIds.end(), "Slot (ID: %s) is unknown", slotId.ToString().data());
  274. if (entry != m_slotIds.end())
  275. {
  276. m_slotIds.erase(entry);
  277. }
  278. }
  279. AZStd::vector<AZ::EntityId> MockNodeComponent::GetSlotIds() const
  280. {
  281. return m_slotIds;
  282. }
  283. AZStd::vector<GraphCanvas::SlotId> MockNodeComponent::GetVisibleSlotIds() const
  284. {
  285. return m_slotIds;
  286. }
  287. AZStd::vector<GraphCanvas::SlotId> MockNodeComponent::FindVisibleSlotIdsByType([[maybe_unused]] const GraphCanvas::ConnectionType& connectionType, [[maybe_unused]] const GraphCanvas::SlotType& slotType) const
  288. {
  289. AZStd::vector<GraphCanvas::SlotId> empty;
  290. return empty;
  291. }
  292. bool MockNodeComponent::HasConnections() const
  293. {
  294. bool hasConnections = false;
  295. for (auto slotId : m_slotIds)
  296. {
  297. GraphCanvas::SlotRequestBus::EventResult(hasConnections, slotId, &GraphCanvas::SlotRequests::HasConnections);
  298. if (hasConnections)
  299. {
  300. break;
  301. }
  302. }
  303. return hasConnections;
  304. }
  305. AZStd::any* MockNodeComponent::GetUserData()
  306. {
  307. return &m_userData;
  308. }
  309. bool MockNodeComponent::IsWrapped() const
  310. {
  311. return false;
  312. }
  313. void MockNodeComponent::SetWrappingNode([[maybe_unused]] const AZ::EntityId& wrappingNode)
  314. {
  315. }
  316. AZ::EntityId MockNodeComponent::GetWrappingNode() const
  317. {
  318. return AZ::EntityId();
  319. }
  320. void MockNodeComponent::SignalBatchedConnectionManipulationBegin()
  321. {
  322. }
  323. void MockNodeComponent::SignalBatchedConnectionManipulationEnd()
  324. {
  325. }
  326. GraphCanvas::RootGraphicsItemEnabledState MockNodeComponent::UpdateEnabledState()
  327. {
  328. return GraphCanvas::RootGraphicsItemEnabledState::ES_Enabled;
  329. }
  330. bool MockNodeComponent::IsHidingUnusedSlots() const
  331. {
  332. return false;
  333. }
  334. void MockNodeComponent::ShowAllSlots()
  335. {
  336. }
  337. void MockNodeComponent::HideUnusedSlots()
  338. {
  339. }
  340. bool MockNodeComponent::HasHideableSlots() const
  341. {
  342. return false;
  343. }
  344. void MockNodeComponent::SignalConnectionMoveBegin([[maybe_unused]] const GraphCanvas::ConnectionId& connectionId)
  345. {
  346. }
  347. void MockNodeComponent::SignalNodeAboutToBeDeleted()
  348. {
  349. }
  350. // MockGraphCanvasSystemComponent
  351. void MockGraphCanvasSystemComponent::Reflect(AZ::ReflectContext* context)
  352. {
  353. if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  354. {
  355. serializeContext->Class<MockGraphCanvasSystemComponent, AZ::Component>()
  356. ->Version(0)
  357. ;
  358. }
  359. }
  360. void MockGraphCanvasSystemComponent::Activate()
  361. {
  362. GraphCanvas::GraphCanvasRequestBus::Handler::BusConnect();
  363. }
  364. void MockGraphCanvasSystemComponent::Deactivate()
  365. {
  366. GraphCanvas::GraphCanvasRequestBus::Handler::BusDisconnect();
  367. }
  368. AZ::Entity* MockGraphCanvasSystemComponent::CreateBookmarkAnchor() const
  369. {
  370. return nullptr;
  371. }
  372. AZ::Entity* MockGraphCanvasSystemComponent::CreateScene() const
  373. {
  374. AZ::Entity* entity = aznew AZ::Entity("GraphCanvasScene");
  375. return entity;
  376. }
  377. AZ::Entity* MockGraphCanvasSystemComponent::CreateCoreNode() const
  378. {
  379. return nullptr;
  380. }
  381. AZ::Entity* MockGraphCanvasSystemComponent::CreateGeneralNode([[maybe_unused]] const char* nodeType) const
  382. {
  383. // Create this Node's entity.
  384. AZ::Entity* entity = MockNodeComponent::CreateCoreNodeEntity();
  385. return entity;
  386. }
  387. AZ::Entity* MockGraphCanvasSystemComponent::CreateCommentNode() const
  388. {
  389. return nullptr;
  390. }
  391. AZ::Entity* MockGraphCanvasSystemComponent::CreateWrapperNode([[maybe_unused]] const char* nodeType) const
  392. {
  393. return nullptr;
  394. }
  395. AZ::Entity* MockGraphCanvasSystemComponent::CreateNodeGroup() const
  396. {
  397. return nullptr;
  398. }
  399. AZ::Entity* MockGraphCanvasSystemComponent::CreateCollapsedNodeGroup([[maybe_unused]] const GraphCanvas::CollapsedNodeGroupConfiguration& groupedNodeConfiguration) const
  400. {
  401. return nullptr;
  402. }
  403. AZ::Entity* MockGraphCanvasSystemComponent::CreateSlot(const AZ::EntityId& nodeId, const GraphCanvas::SlotConfiguration& slotConfiguration) const
  404. {
  405. if (const GraphCanvas::DataSlotConfiguration* dataSlotConfiguration = azrtti_cast<const GraphCanvas::DataSlotConfiguration*>(&slotConfiguration))
  406. {
  407. return MockDataSlotComponent::CreateDataSlot((*dataSlotConfiguration));
  408. }
  409. else if (const GraphCanvas::ExecutionSlotConfiguration* executionSlotConfiguration = azrtti_cast<const GraphCanvas::ExecutionSlotConfiguration*>(&slotConfiguration))
  410. {
  411. return MockExecutionSlotComponent::CreateExecutionSlot(nodeId, (*executionSlotConfiguration));
  412. }
  413. else if (const GraphCanvas::ExtenderSlotConfiguration* extenderSlotConfiguration = azrtti_cast<const GraphCanvas::ExtenderSlotConfiguration*>(&slotConfiguration))
  414. {
  415. return MockExtenderSlotComponent::CreateExtenderSlot(nodeId, (*extenderSlotConfiguration));
  416. }
  417. else
  418. {
  419. AZ_Error("GraphCanvas", false, "Trying to create using an unknown Slot Configuration");
  420. }
  421. return nullptr;
  422. }
  423. GraphCanvas::NodePropertyDisplay* MockGraphCanvasSystemComponent::CreateBooleanNodePropertyDisplay([[maybe_unused]] GraphCanvas::BooleanDataInterface* dataInterface) const
  424. {
  425. return nullptr;
  426. }
  427. GraphCanvas::NodePropertyDisplay* MockGraphCanvasSystemComponent::CreateNumericNodePropertyDisplay([[maybe_unused]] GraphCanvas::NumericDataInterface* dataInterface) const
  428. {
  429. return nullptr;
  430. }
  431. GraphCanvas::NodePropertyDisplay* MockGraphCanvasSystemComponent::CreateComboBoxNodePropertyDisplay([[maybe_unused]] GraphCanvas::ComboBoxDataInterface* dataInterface) const
  432. {
  433. return nullptr;
  434. }
  435. GraphCanvas::NodePropertyDisplay* MockGraphCanvasSystemComponent::CreateEntityIdNodePropertyDisplay([[maybe_unused]] GraphCanvas::EntityIdDataInterface* dataInterface) const
  436. {
  437. return nullptr;
  438. }
  439. GraphCanvas::NodePropertyDisplay* MockGraphCanvasSystemComponent::CreateReadOnlyNodePropertyDisplay([[maybe_unused]] GraphCanvas::ReadOnlyDataInterface* dataInterface) const
  440. {
  441. return nullptr;
  442. }
  443. GraphCanvas::NodePropertyDisplay* MockGraphCanvasSystemComponent::CreateStringNodePropertyDisplay([[maybe_unused]] GraphCanvas::StringDataInterface* dataInterface) const
  444. {
  445. return nullptr;
  446. }
  447. GraphCanvas::NodePropertyDisplay* MockGraphCanvasSystemComponent::CreateVectorNodePropertyDisplay([[maybe_unused]] GraphCanvas::VectorDataInterface* dataInterface) const
  448. {
  449. return nullptr;
  450. }
  451. GraphCanvas::NodePropertyDisplay* MockGraphCanvasSystemComponent::CreateAssetIdNodePropertyDisplay([[maybe_unused]] GraphCanvas::AssetIdDataInterface* dataInterface) const
  452. {
  453. return nullptr;
  454. }
  455. AZ::Entity* MockGraphCanvasSystemComponent::CreatePropertySlot([[maybe_unused]] const AZ::EntityId& nodeId, [[maybe_unused]] const AZ::Crc32& propertyId, [[maybe_unused]] const GraphCanvas::SlotConfiguration& slotConfiguration) const
  456. {
  457. return nullptr;
  458. }
  459. }