GraphModelSystemComponent.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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/GraphContext.h>
  18. #include <GraphModel/Model/DataType.h>
  19. #include <GraphModel/Model/Node.h>
  20. #include <GraphModel/Model/Slot.h>
  21. #include <GraphModel/Model/Module/InputOutputNodes.h>
  22. #include <GraphModel/Model/Module/ModuleNode.h>
  23. #include <GraphModel/Integration/GraphCanvasMetadata.h>
  24. #include <GraphModel/Integration/NodePalette/InputOutputNodePaletteItem.h>
  25. #include <GraphModel/Integration/NodePalette/GraphCanvasNodePaletteItems.h>
  26. #include <GraphModel/Integration/NodePalette/ModuleNodePaletteItem.h>
  27. namespace GraphModel
  28. {
  29. void GraphModelSystemComponent::Reflect(AZ::ReflectContext* context)
  30. {
  31. // Reflect core graph classes
  32. DataType::Reflect(context);
  33. GraphContext::Reflect(context);
  34. GraphElement::Reflect(context);
  35. SlotId::Reflect(context);
  36. Slot::Reflect(context);
  37. Node::Reflect(context);
  38. Connection::Reflect(context);
  39. Graph::Reflect(context);
  40. // Reflect module node data types
  41. BaseInputOutputNode::Reflect(context);
  42. GraphInputNode::Reflect(context);
  43. GraphOutputNode::Reflect(context);
  44. ModuleNode::Reflect(context);
  45. // Reflect data types for integrating graph model with graph canvas
  46. GraphModelIntegration::GraphCanvasMetadata::Reflect(context);
  47. GraphModelIntegration::GraphCanvasSelectionData::Reflect(context);
  48. // Reflect MIME events for graph canvas nodes
  49. GraphModelIntegration::CreateGraphCanvasNodeMimeEvent::Reflect(context);
  50. GraphModelIntegration::CreateNodeGroupNodeMimeEvent::Reflect(context);
  51. GraphModelIntegration::CreateCommentNodeMimeEvent::Reflect(context);
  52. // Reflect MIME events for module node
  53. GraphModelIntegration::CreateInputOutputNodeMimeEvent<GraphInputNode>::Reflect(context);
  54. GraphModelIntegration::CreateInputOutputNodeMimeEvent<GraphOutputNode>::Reflect(context);
  55. GraphModelIntegration::CreateModuleNodeMimeEvent::Reflect(context);
  56. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  57. {
  58. serializeContext->Class<GraphModelSystemComponent, AZ::Component>()
  59. ->Version(0)
  60. ;
  61. if (auto editContext = serializeContext->GetEditContext())
  62. {
  63. editContext->Class<GraphModelSystemComponent>("GraphModel", "A generic node graph data model")
  64. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  65. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  66. ;
  67. }
  68. }
  69. if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  70. {
  71. behaviorContext->EBus<GraphModelIntegration::GraphManagerRequestBus>("GraphManagerRequestBus")
  72. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  73. ->Attribute(AZ::Script::Attributes::Category, "Editor")
  74. ->Attribute(AZ::Script::Attributes::Module, "editor.graph")
  75. ->Event("GetGraph", &GraphModelIntegration::GraphManagerRequests::GetGraph)
  76. ;
  77. behaviorContext->EBus<GraphModelIntegration::GraphControllerRequestBus>("GraphControllerRequestBus")
  78. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  79. ->Attribute(AZ::Script::Attributes::Category, "Editor")
  80. ->Attribute(AZ::Script::Attributes::Module, "editor.graph")
  81. ->Event("AddNode", &GraphModelIntegration::GraphControllerRequests::AddNode)
  82. ->Event("RemoveNode", &GraphModelIntegration::GraphControllerRequests::RemoveNode)
  83. ->Event("GetPosition", &GraphModelIntegration::GraphControllerRequests::GetPosition)
  84. ->Event("WrapNode", &GraphModelIntegration::GraphControllerRequests::WrapNode)
  85. ->Event("WrapNodeOrdered", &GraphModelIntegration::GraphControllerRequests::WrapNodeOrdered)
  86. ->Event("UnwrapNode", &GraphModelIntegration::GraphControllerRequests::UnwrapNode)
  87. ->Event("IsNodeWrapped", &GraphModelIntegration::GraphControllerRequests::IsNodeWrapped)
  88. ->Event("SetWrapperNodeActionString", &GraphModelIntegration::GraphControllerRequests::SetWrapperNodeActionString)
  89. ->Event("AddConnection", &GraphModelIntegration::GraphControllerRequests::AddConnection)
  90. ->Event("AddConnectionBySlotId", &GraphModelIntegration::GraphControllerRequests::AddConnectionBySlotId)
  91. ->Event("AreSlotsConnected", &GraphModelIntegration::GraphControllerRequests::AreSlotsConnected)
  92. ->Event("RemoveConnection", &GraphModelIntegration::GraphControllerRequests::RemoveConnection)
  93. ->Event("ExtendSlot", &GraphModelIntegration::GraphControllerRequests::ExtendSlot)
  94. ->Event("GetNodeById", &GraphModelIntegration::GraphControllerRequests::GetNodeById)
  95. ->Event("GetNodesFromGraphNodeIds", &GraphModelIntegration::GraphControllerRequests::GetNodesFromGraphNodeIds)
  96. ->Event("GetNodeIdByNode", &GraphModelIntegration::GraphControllerRequests::GetNodeIdByNode)
  97. ->Event("GetSlotIdBySlot", &GraphModelIntegration::GraphControllerRequests::GetSlotIdBySlot)
  98. ->Event("GetNodes", &GraphModelIntegration::GraphControllerRequests::GetNodes)
  99. ->Event("GetSelectedNodes", &GraphModelIntegration::GraphControllerRequests::GetSelectedNodes)
  100. ->Event("SetSelected", &GraphModelIntegration::GraphControllerRequests::SetSelected)
  101. ->Event("ClearSelection", &GraphModelIntegration::GraphControllerRequests::ClearSelection)
  102. ->Event("EnableNode", &GraphModelIntegration::GraphControllerRequests::EnableNode)
  103. ->Event("DisableNode", &GraphModelIntegration::GraphControllerRequests::DisableNode)
  104. ->Event("CenterOnNodes", &GraphModelIntegration::GraphControllerRequests::CenterOnNodes)
  105. ->Event("GetMajorPitch", &GraphModelIntegration::GraphControllerRequests::GetMajorPitch)
  106. ;
  107. }
  108. }
  109. void GraphModelSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  110. {
  111. provided.push_back(AZ_CRC_CE("GraphModelService"));
  112. }
  113. void GraphModelSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  114. {
  115. incompatible.push_back(AZ_CRC_CE("GraphModelService"));
  116. }
  117. void GraphModelSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  118. {
  119. AZ_UNUSED(required);
  120. }
  121. void GraphModelSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
  122. {
  123. AZ_UNUSED(dependent);
  124. }
  125. void GraphModelSystemComponent::Init()
  126. {
  127. }
  128. void GraphModelSystemComponent::Activate()
  129. {
  130. m_graphControllerManager = AZStd::make_unique<GraphModelIntegration::GraphControllerManager>();
  131. }
  132. void GraphModelSystemComponent::Deactivate()
  133. {
  134. m_graphControllerManager.reset();
  135. }
  136. }