GraphModelSystemComponent.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 <GraphModelSystemComponent.h>
  9. #include <AzCore/RTTI/BehaviorContext.h>
  10. #include <AzCore/Serialization/SerializeContext.h>
  11. #include <AzCore/Serialization/EditContext.h>
  12. #include <AzCore/Serialization/EditContextConstants.inl>
  13. // Graph Model
  14. #include <GraphModel/GraphModelBus.h>
  15. #include <GraphModel/Model/Connection.h>
  16. #include <GraphModel/Model/Graph.h>
  17. #include <GraphModel/Model/DataType.h>
  18. #include <GraphModel/Model/Node.h>
  19. #include <GraphModel/Model/Slot.h>
  20. #include <GraphModel/Model/Module/InputOutputNodes.h>
  21. #include <GraphModel/Model/Module/ModuleNode.h>
  22. #include <GraphModel/Integration/GraphCanvasMetadata.h>
  23. #include <GraphModel/Integration/NodePalette/InputOutputNodePaletteItem.h>
  24. #include <GraphModel/Integration/NodePalette/GraphCanvasNodePaletteItems.h>
  25. #include <GraphModel/Integration/NodePalette/ModuleNodePaletteItem.h>
  26. namespace GraphModel
  27. {
  28. void GraphModelSystemComponent::Reflect(AZ::ReflectContext* context)
  29. {
  30. // Reflect core graph classes
  31. GraphModel::Graph::Reflect(context);
  32. GraphModel::DataType::Reflect(context);
  33. GraphModelIntegration::GraphCanvasMetadata::Reflect(context);
  34. // Mime Events for Graph Canvas nodes
  35. GraphModelIntegration::CreateGraphCanvasNodeMimeEvent::Reflect(context);
  36. GraphModelIntegration::CreateNodeGroupNodeMimeEvent::Reflect(context);
  37. GraphModelIntegration::CreateCommentNodeMimeEvent::Reflect(context);
  38. // Reflect all the nodes needed to support ModuleNode
  39. GraphModel::BaseInputOutputNode::Reflect(context);
  40. GraphModel::GraphInputNode::Reflect(context);
  41. GraphModel::GraphOutputNode::Reflect(context);
  42. GraphModel::ModuleNode::Reflect(context);
  43. GraphModelIntegration::CreateInputOutputNodeMimeEvent<GraphModel::GraphInputNode>::Reflect(context);
  44. GraphModelIntegration::CreateInputOutputNodeMimeEvent<GraphModel::GraphOutputNode>::Reflect(context);
  45. GraphModelIntegration::CreateModuleNodeMimeEvent::Reflect(context);
  46. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  47. {
  48. serialize->Class<GraphModelSystemComponent, AZ::Component>()
  49. ->Version(0)
  50. ;
  51. serialize->RegisterGenericType<GraphModel::NodePtrList>();
  52. serialize->RegisterGenericType<GraphModel::SlotPtrList>();
  53. if (AZ::EditContext* ec = serialize->GetEditContext())
  54. {
  55. ec->Class<GraphModelSystemComponent>("GraphModel", "A generic node graph data model")
  56. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  57. ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System", 0xc94d118b))
  58. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  59. ;
  60. }
  61. }
  62. if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  63. {
  64. behaviorContext->EBus<GraphModelIntegration::GraphManagerRequestBus>("GraphManagerRequestBus")
  65. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  66. ->Attribute(AZ::Script::Attributes::Category, "Editor")
  67. ->Attribute(AZ::Script::Attributes::Module, GraphCanvas::EditorGraphModuleName)
  68. ->Event("GetGraph", &GraphModelIntegration::GraphManagerRequests::GetGraph)
  69. ;
  70. behaviorContext->EBus<GraphModelIntegration::GraphControllerRequestBus>("GraphControllerRequestBus")
  71. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  72. ->Attribute(AZ::Script::Attributes::Category, "Editor")
  73. ->Attribute(AZ::Script::Attributes::Module, GraphCanvas::EditorGraphModuleName)
  74. ->Event("AddNode", &GraphModelIntegration::GraphControllerRequests::AddNode)
  75. ->Event("RemoveNode", &GraphModelIntegration::GraphControllerRequests::RemoveNode)
  76. ->Event("WrapNode", &GraphModelIntegration::GraphControllerRequests::WrapNode)
  77. ->Event("AddConnection", &GraphModelIntegration::GraphControllerRequests::AddConnection)
  78. ->Event("AddConnectionBySlotId", &GraphModelIntegration::GraphControllerRequests::AddConnectionBySlotId)
  79. ->Event("AreSlotsConnected", &GraphModelIntegration::GraphControllerRequests::AreSlotsConnected)
  80. ->Event("RemoveConnection", &GraphModelIntegration::GraphControllerRequests::RemoveConnection)
  81. ->Event("ExtendSlot", &GraphModelIntegration::GraphControllerRequests::ExtendSlot)
  82. ;
  83. behaviorContext->Class<GraphModel::SlotId>("GraphModelSlotId")
  84. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  85. ->Attribute(AZ::Script::Attributes::Category, "Editor")
  86. ->Attribute(AZ::Script::Attributes::Module, GraphCanvas::EditorGraphModuleName)
  87. ->Constructor<const GraphModel::SlotName&>()
  88. ->Constructor<const GraphModel::SlotName&, GraphModel::SlotSubId>()
  89. ->Property("name", BehaviorValueProperty(&GraphModel::SlotId::m_name))
  90. ->Property("subId", BehaviorValueProperty(&GraphModel::SlotId::m_subId))
  91. ;
  92. }
  93. }
  94. void GraphModelSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  95. {
  96. provided.push_back(AZ_CRC_CE("GraphModelService"));
  97. }
  98. void GraphModelSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  99. {
  100. incompatible.push_back(AZ_CRC_CE("GraphModelService"));
  101. }
  102. void GraphModelSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  103. {
  104. AZ_UNUSED(required);
  105. }
  106. void GraphModelSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
  107. {
  108. AZ_UNUSED(dependent);
  109. }
  110. void GraphModelSystemComponent::Init()
  111. {
  112. }
  113. void GraphModelSystemComponent::Activate()
  114. {
  115. m_graphControllerManager = AZStd::make_unique<GraphModelIntegration::GraphControllerManager>();
  116. }
  117. void GraphModelSystemComponent::Deactivate()
  118. {
  119. m_graphControllerManager.reset();
  120. }
  121. }