GraphDocumentView.cpp 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 <AtomToolsFramework/Graph/GraphDocumentRequestBus.h>
  9. #include <AtomToolsFramework/Graph/GraphDocumentView.h>
  10. #include <AzCore/Settings/SettingsRegistryMergeUtils.h>
  11. namespace AtomToolsFramework
  12. {
  13. GraphDocumentView::GraphDocumentView(
  14. const AZ::Crc32& toolId, const AZ::Uuid& documentId, GraphViewSettingsPtr graphViewSettingsPtr, QWidget* parent)
  15. : GraphView(toolId, GraphCanvas::GraphId(), graphViewSettingsPtr, parent)
  16. , m_documentId(documentId)
  17. {
  18. AtomToolsDocumentNotificationBus::Handler::BusConnect(m_toolId);
  19. OnDocumentOpened(m_documentId);
  20. m_openedBefore = false;
  21. // Monitor graph settings changes and refresh the graph view if the view settings change
  22. if (auto registry = AZ::SettingsRegistry::Get())
  23. {
  24. m_graphViewSettingsNotifyEventHandler = registry->RegisterNotifier(
  25. [this](const AZ::SettingsRegistryInterface::NotifyEventArgs& notifyEventArgs)
  26. {
  27. if (AZ::SettingsRegistryMergeUtils::IsPathAncestorDescendantOrEqual(
  28. "/O3DE/Atom/GraphView/ViewSettings", notifyEventArgs.m_jsonKeyPath))
  29. {
  30. OnSettingsChanged();
  31. }
  32. });
  33. }
  34. }
  35. GraphDocumentView::~GraphDocumentView()
  36. {
  37. AtomToolsDocumentNotificationBus::Handler::BusDisconnect();
  38. }
  39. void GraphDocumentView::OnDocumentOpened(const AZ::Uuid& documentId)
  40. {
  41. if (m_documentId == documentId)
  42. {
  43. GraphCanvas::GraphId activeGraphId = GraphCanvas::GraphId();
  44. GraphDocumentRequestBus::EventResult(activeGraphId, m_documentId, &GraphDocumentRequestBus::Events::GetGraphId);
  45. SetActiveGraphId(activeGraphId, true);
  46. // Show the entire graph and center the view the first time a graph is opened
  47. if (!m_openedBefore && activeGraphId.IsValid())
  48. {
  49. GraphCanvas::ViewId viewId;
  50. GraphCanvas::SceneRequestBus::EventResult(viewId, activeGraphId, &GraphCanvas::SceneRequests::GetViewId);
  51. GraphCanvas::ViewRequestBus::Event(viewId, &GraphCanvas::ViewRequests::ShowEntireGraph);
  52. m_openedBefore = true;
  53. }
  54. return;
  55. }
  56. SetActiveGraphId(GraphCanvas::GraphId(), false);
  57. }
  58. void GraphDocumentView::OnDocumentClosed([[maybe_unused]] const AZ::Uuid& documentId)
  59. {
  60. if (m_documentId == documentId)
  61. {
  62. SetActiveGraphId(GraphCanvas::GraphId(), true);
  63. }
  64. }
  65. void GraphDocumentView::OnDocumentDestroyed([[maybe_unused]] const AZ::Uuid& documentId)
  66. {
  67. if (m_documentId == documentId)
  68. {
  69. SetActiveGraphId(GraphCanvas::GraphId(), true);
  70. }
  71. }
  72. void GraphDocumentView::OnSettingsChanged()
  73. {
  74. if (m_activeGraphId.IsValid())
  75. {
  76. GraphCanvas::AssetEditorSettingsNotificationBus::Event(
  77. m_toolId, &GraphCanvas::AssetEditorSettingsNotifications::OnSettingsChanged);
  78. GraphCanvas::ViewRequestBus::Event(m_activeGraphId, &GraphCanvas::ViewRequests::RefreshView);
  79. }
  80. }
  81. } // namespace AtomToolsFramework