2
0

ROS2SimulationInterfacesEditorSystemComponent.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 "ROS2SimulationInterfacesEditorSystemComponent.h"
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. #include <SimulationInterfaces/ROS2SimulationInterfacesTypeIds.h>
  11. namespace ROS2SimulationInterfaces
  12. {
  13. AZ_COMPONENT_IMPL(
  14. ROS2SimulationInterfacesEditorSystemComponent,
  15. "ROS2SimulationInterfacesEditorSystemComponent",
  16. ROS2SimulationInterfacesEditorSystemComponentTypeId,
  17. BaseSystemComponent);
  18. void ROS2SimulationInterfacesEditorSystemComponent::Reflect(AZ::ReflectContext* context)
  19. {
  20. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  21. {
  22. serializeContext->Class<ROS2SimulationInterfacesEditorSystemComponent, ROS2SimulationInterfacesSystemComponent>()->Version(0);
  23. }
  24. }
  25. ROS2SimulationInterfacesEditorSystemComponent::ROS2SimulationInterfacesEditorSystemComponent()
  26. : m_nodeHandler(
  27. [this](std::shared_ptr<rclcpp::Node> node)
  28. {
  29. if (!m_systemComponentActivated)
  30. {
  31. ROS2SimulationInterfacesSystemComponent::Activate();
  32. m_systemComponentActivated = true;
  33. }
  34. else
  35. {
  36. ROS2SimulationInterfacesSystemComponent::Deactivate();
  37. m_systemComponentActivated = false;
  38. }
  39. })
  40. {
  41. }
  42. ROS2SimulationInterfacesEditorSystemComponent::~ROS2SimulationInterfacesEditorSystemComponent() = default;
  43. void ROS2SimulationInterfacesEditorSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  44. {
  45. BaseSystemComponent::GetProvidedServices(provided);
  46. provided.push_back(AZ_CRC_CE("ROS2SimulationInterfacesEditorService"));
  47. }
  48. void ROS2SimulationInterfacesEditorSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  49. {
  50. BaseSystemComponent::GetIncompatibleServices(incompatible);
  51. incompatible.push_back(AZ_CRC_CE("ROS2SimulationInterfacesEditorService"));
  52. }
  53. void ROS2SimulationInterfacesEditorSystemComponent::GetRequiredServices(
  54. [[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& required)
  55. {
  56. BaseSystemComponent::GetRequiredServices(required);
  57. required.push_back(AZ_CRC_CE("ROS2EditorService"));
  58. }
  59. void ROS2SimulationInterfacesEditorSystemComponent::GetDependentServices(
  60. [[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& dependent)
  61. {
  62. BaseSystemComponent::GetDependentServices(dependent);
  63. }
  64. void ROS2SimulationInterfacesEditorSystemComponent::Activate()
  65. {
  66. AzToolsFramework::EditorEvents::Bus::Handler::BusConnect();
  67. ROS2::ROS2Interface::Get()->ConnectOnNodeChanged(m_nodeHandler);
  68. }
  69. void ROS2SimulationInterfacesEditorSystemComponent::Deactivate()
  70. {
  71. m_nodeHandler.Disconnect();
  72. AzToolsFramework::EditorEvents::Bus::Handler::BusDisconnect();
  73. }
  74. } // namespace ROS2SimulationInterfaces