GraphControllerManager.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. // AZ
  9. #include <AzCore/std/smart_ptr/make_shared.h>
  10. // Graph Canvas
  11. #include <GraphCanvas/GraphCanvasBus.h>
  12. // Graph Model
  13. #include <GraphModel/Integration/GraphControllerManager.h>
  14. namespace GraphModelIntegration
  15. {
  16. GraphControllerManager::GraphControllerManager()
  17. {
  18. GraphManagerRequestBus::Handler::BusConnect();
  19. }
  20. GraphControllerManager::~GraphControllerManager()
  21. {
  22. GraphManagerRequestBus::Handler::BusDisconnect();
  23. }
  24. AZ::Entity* GraphControllerManager::CreateScene(GraphModel::GraphPtr graph, const GraphCanvas::EditorId editorId)
  25. {
  26. AZ::Entity* scene = nullptr;
  27. GraphCanvas::GraphCanvasRequestBus::BroadcastResult(scene, &GraphCanvas::GraphCanvasRequests::CreateSceneAndActivate);
  28. // Set the EditorId for the new scene
  29. const AZ::EntityId& sceneId = scene->GetId();
  30. GraphCanvas::SceneRequestBus::Event(sceneId, &GraphCanvas::SceneRequests::SetEditorId, editorId);
  31. // Create a graph controller for the new scene
  32. CreateGraphController(sceneId, graph);
  33. return scene;
  34. }
  35. void GraphControllerManager::RemoveScene(const GraphCanvas::GraphId& sceneId)
  36. {
  37. DeleteGraphController(sceneId);
  38. }
  39. void GraphControllerManager::CreateGraphController(const GraphCanvas::GraphId& sceneId, GraphModel::GraphPtr graph)
  40. {
  41. m_graphControllers[sceneId] = AZStd::make_shared<GraphController>(graph, sceneId);
  42. }
  43. void GraphControllerManager::DeleteGraphController(const GraphCanvas::GraphId& sceneId)
  44. {
  45. m_graphControllers.erase(sceneId);
  46. }
  47. GraphModel::GraphPtr GraphControllerManager::GetGraph(const GraphCanvas::GraphId& sceneId)
  48. {
  49. const auto it = m_graphControllers.find(sceneId);
  50. return it != m_graphControllers.end() ? it->second->GetGraph() : nullptr;
  51. }
  52. const GraphModelSerialization& GraphControllerManager::GetSerializedMappings()
  53. {
  54. return m_serialization;
  55. }
  56. void GraphControllerManager::SetSerializedMappings(const GraphModelSerialization& serialization)
  57. {
  58. m_serialization = serialization;
  59. }
  60. } // namespace GraphModelIntegration