GraphElement.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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/RTTI/BehaviorContext.h>
  10. #include <AzCore/Serialization/SerializeContext.h>
  11. // Graph Model
  12. #include <GraphModel/Model/Graph.h>
  13. #include <GraphModel/Model/GraphContext.h>
  14. #include <GraphModel/Model/GraphElement.h>
  15. namespace GraphModel
  16. {
  17. void GraphElement::Reflect(AZ::ReflectContext* context)
  18. {
  19. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  20. {
  21. serializeContext->Class<GraphElement>()
  22. ->Version(0)
  23. ;
  24. serializeContext->RegisterGenericType<GraphElementPtr>();
  25. }
  26. if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  27. {
  28. behaviorContext->Class<GraphElement>("GraphModelGraphElement")
  29. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  30. ->Attribute(AZ::Script::Attributes::Category, "Editor")
  31. ->Attribute(AZ::Script::Attributes::Module, "editor.graph")
  32. ->Method("GetGraph", &GraphElement::GetGraph)
  33. ->Method("GetGraphContext", &GraphElement::GetGraphContext)
  34. ;
  35. }
  36. }
  37. GraphElement::GraphElement(GraphPtr graph)
  38. : m_graph(graph)
  39. {
  40. }
  41. GraphPtr GraphElement::GetGraph() const
  42. {
  43. return m_graph.lock();
  44. }
  45. GraphContextPtr GraphElement::GetGraphContext() const
  46. {
  47. GraphPtr graph = m_graph.lock();
  48. return graph ? graph->GetContext() : nullptr;
  49. }
  50. } // namespace GraphModel