ROS2EditorSystemComponent.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 "ROS2EditorSystemComponent.h"
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. #include <Frame/ROS2FrameEditorComponent.h>
  11. #include <ROS2/ROS2TypeIds.h>
  12. namespace ROS2
  13. {
  14. AZ_COMPONENT_IMPL(ROS2EditorSystemComponent, "ROS2EditorSystemComponent", ROS2EditorSystemComponentTypeId, BaseSystemComponent);
  15. void ROS2EditorSystemComponent::Reflect(AZ::ReflectContext* context)
  16. {
  17. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  18. {
  19. serializeContext->Class<ROS2EditorSystemComponent, ROS2SystemComponent>()->Version(0);
  20. }
  21. }
  22. ROS2EditorSystemComponent::ROS2EditorSystemComponent()
  23. {
  24. if (ROS2EditorInterface::Get() == nullptr)
  25. {
  26. ROS2EditorInterface::Register(this);
  27. }
  28. }
  29. ROS2EditorSystemComponent::~ROS2EditorSystemComponent()
  30. {
  31. if (ROS2EditorInterface::Get() == this)
  32. {
  33. ROS2EditorInterface::Unregister(this);
  34. }
  35. }
  36. void ROS2EditorSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  37. {
  38. BaseSystemComponent::GetProvidedServices(provided);
  39. provided.push_back(AZ_CRC_CE("ROS2EditorService"));
  40. }
  41. void ROS2EditorSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  42. {
  43. BaseSystemComponent::GetIncompatibleServices(incompatible);
  44. incompatible.push_back(AZ_CRC_CE("ROS2EditorService"));
  45. }
  46. void ROS2EditorSystemComponent::GetRequiredServices([[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& required)
  47. {
  48. BaseSystemComponent::GetRequiredServices(required);
  49. }
  50. void ROS2EditorSystemComponent::GetDependentServices([[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& dependent)
  51. {
  52. BaseSystemComponent::GetDependentServices(dependent);
  53. }
  54. void ROS2EditorSystemComponent::Activate()
  55. {
  56. AzToolsFramework::EditorEntityContextNotificationBus::Handler::BusConnect();
  57. AzToolsFramework::EditorEvents::Bus::Handler::BusConnect();
  58. ROS2NamesRequestBus::Handler::BusConnect();
  59. }
  60. void ROS2EditorSystemComponent::Deactivate()
  61. {
  62. ROS2NamesRequestBus::Handler::BusDisconnect();
  63. AzToolsFramework::EditorEvents::Bus::Handler::BusDisconnect();
  64. AzToolsFramework::EditorEntityContextNotificationBus::Handler::BusDisconnect();
  65. }
  66. void ROS2EditorSystemComponent::OnStartPlayInEditorBegin()
  67. {
  68. ROS2NamesRequestBus::Handler::BusDisconnect(); // ROS2NamesRequestBus will be handled by ROS2SystemComponent
  69. ROS2SystemComponent::Activate();
  70. }
  71. void ROS2EditorSystemComponent::OnStopPlayInEditor()
  72. {
  73. ROS2SystemComponent::Deactivate();
  74. ROS2NamesRequestBus::Handler::BusConnect(); // ROS2NamesRequestBus will not be handled by ROS2SystemComponent anymore
  75. }
  76. AZ::Component* ROS2EditorSystemComponent::CreateROS2FrameEditorComponent(AZ::Entity& entity)
  77. {
  78. return CreateComponent<ROS2FrameEditorComponent>(entity);
  79. }
  80. AZ::Component* ROS2EditorSystemComponent::CreateROS2FrameEditorComponent(
  81. AZ::Entity& entity, const ROS2::ROS2FrameConfiguration& frameConfiguration)
  82. {
  83. return CreateComponent<ROS2FrameEditorComponent>(entity, frameConfiguration);
  84. }
  85. } // namespace ROS2