ROS2FrameEditorComponent.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #pragma once
  9. #include <AzCore/Component/Component.h>
  10. #include <AzCore/Component/EntityId.h>
  11. #include <AzFramework/Components/TransformComponent.h>
  12. #include <AzToolsFramework/ToolsComponents/EditorComponentBase.h>
  13. #include <ROS2/Frame/ROS2FrameComponentBus.h>
  14. #include <ROS2/Frame/ROS2FrameComponentInterface.h>
  15. #include <ROS2/Frame/ROS2FrameConfiguration.h>
  16. #include <ROS2/Frame/ROS2FrameEditorComponentBus.h>
  17. #include <ROS2/ROS2TypeIds.h>
  18. namespace ROS2
  19. {
  20. //! This component marks a reference frame for ROS 2 ecosystem.
  21. //! It serves as sensor data frame of reference and is responsible, through ROS2Transform, for publishing
  22. //! ros2 static and dynamic transforms (/tf_static, /tf). It also facilitates namespace handling.
  23. //! An entity can only have a single ROS2Frame on each level. Many ROS 2 Components require this component.
  24. //! @note A robot should have this component on every level of entity hierarchy (for each joint, fixed or dynamic)
  25. class ROS2FrameEditorComponent
  26. : public AzToolsFramework::Components::EditorComponentBase
  27. , public ROS2FrameEditorComponentBus::Handler
  28. , public ROS2FrameComponentBus::Handler
  29. , public AZ::EntityBus::Handler
  30. , public ROSFrameInterface
  31. {
  32. public:
  33. AZ_EDITOR_COMPONENT(
  34. ROS2FrameEditorComponent, ROS2FrameEditorComponentTypeId, AzToolsFramework::Components::EditorComponentBase, ROSFrameInterface);
  35. ROS2FrameEditorComponent() = default;
  36. ~ROS2FrameEditorComponent() = default;
  37. ROS2FrameEditorComponent(const ROS2FrameConfiguration ros2FrameConfiguration);
  38. // AzToolsFramework::Components::EditorComponentBase overrides
  39. void Init() override;
  40. void Activate() override;
  41. void Deactivate() override;
  42. void BuildGameEntity(AZ::Entity* gameEntity) override;
  43. static void Reflect(AZ::ReflectContext* context);
  44. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  45. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  46. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  47. // ROSFrameInterface overrides
  48. ROS2FrameConfiguration GetConfiguration() const override;
  49. void SetConfiguration(const ROS2FrameConfiguration& config) override;
  50. private:
  51. // ROS2FrameEditorComponentBus::Handler overrides
  52. AZStd::string GetNamespacedFrameID() const override;
  53. AZStd::string GetNamespacedJointName() const override;
  54. AZStd::string GetNamespace() const override;
  55. AZStd::string GetJointName() const override;
  56. AZStd::string GetFrameName() const override;
  57. void UpdateNamespace() override;
  58. AZStd::string GetGlobalFrameID() const override;
  59. AZ::EntityId GetFrameParent() const override;
  60. AZStd::set<AZ::EntityId> GetFrameDescendants() const override;
  61. void SetJointName(const AZStd::string& frameId) override;
  62. // AZ::EntityBus::Handler override.
  63. void OnEntityNameChanged(const AZStd::string& name) override;
  64. AZ::Crc32 OnFrameConfigurationChange();
  65. ROS2FrameConfiguration m_configuration;
  66. AZStd::string m_effectiveNamespace; //! <! Full namespace to show in the Editor
  67. AZStd::string m_fullName; //! <! Full frame name to show in the Editor (that will pbe published to ROS 2)
  68. };
  69. } // namespace ROS2