ROS2SpawnerComponentController.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 "ROS2/Spawner/SpawnerBus.h"
  10. #include "ROS2SpawnPointComponent.h"
  11. #include <AzCore/Component/ComponentBus.h>
  12. #include <AzCore/Component/EntityId.h>
  13. #include <AzCore/Memory/Memory_fwd.h>
  14. #include <AzCore/Memory/SystemAllocator.h>
  15. #include <AzCore/base.h>
  16. #include <AzFramework/Spawnable/Spawnable.h>
  17. namespace ROS2
  18. {
  19. struct ROS2SpawnerServiceNames
  20. {
  21. AZ_TYPE_INFO(ROS2SpawnerServiceNames, "{10D75AAC-BD51-4F33-BCAA-9001CFA219AE}");
  22. AZStd::string m_availableSpawnableNamesServiceName = "get_available_spawnable_names";
  23. AZStd::string m_spawnEntityServiceName = "spawn_entity";
  24. AZStd::string m_deleteEntityServiceName = "delete_entity";
  25. AZStd::string m_spawnPointInfoServiceName = "get_spawn_point_info";
  26. AZStd::string m_spawnPointsNamesServiceName = "get_spawn_points_names";
  27. static void Reflect(AZ::ReflectContext* context);
  28. };
  29. class ROS2SpawnerComponentConfig final : public AZ::ComponentConfig
  30. {
  31. public:
  32. AZ_RTTI(ROS2SpawnerComponentConfig, "{ee71f892-006a-11ee-be56-0242ac120002}");
  33. ROS2SpawnerComponentConfig() = default;
  34. ~ROS2SpawnerComponentConfig() = default;
  35. static void Reflect(AZ::ReflectContext* context);
  36. AZ::EntityId m_editorEntityId;
  37. AZ::Transform m_defaultSpawnPose = { AZ::Vector3{ 0, 0, 0 }, AZ::Quaternion{ 0, 0, 0, 1 }, 1.0 };
  38. ROS2SpawnerServiceNames m_serviceNames;
  39. AZStd::unordered_map<AZStd::string, AZ::Data::Asset<AzFramework::Spawnable>> m_spawnables;
  40. bool m_supportWGS{ true };
  41. };
  42. class ROS2SpawnerComponentController : public SpawnerRequestsBus::Handler
  43. {
  44. public:
  45. AZ_TYPE_INFO(ROS2SpawnerComponentController, "{1e9e040c-006b-11ee-be56-0242ac120002}");
  46. ROS2SpawnerComponentController() = default;
  47. explicit ROS2SpawnerComponentController(const ROS2SpawnerComponentConfig& config);
  48. static void Reflect(AZ::ReflectContext* context);
  49. //////////////////////////////////////////////////////////////////////////
  50. // Controller component
  51. void Init();
  52. void Activate(AZ::EntityId entityId);
  53. void Deactivate();
  54. void SetConfiguration(const ROS2SpawnerComponentConfig& config);
  55. const ROS2SpawnerComponentConfig& GetConfiguration() const;
  56. //////////////////////////////////////////////////////////////////////////
  57. //////////////////////////////////////////////////////////////////////////
  58. // SpawnerRequestsBus::Handler overrides
  59. const AZ::Transform& GetDefaultSpawnPose() const override;
  60. SpawnPointInfoMap GetAllSpawnPointInfos() const override;
  61. //////////////////////////////////////////////////////////////////////////
  62. const ROS2SpawnerServiceNames& GetServiceNames() const;
  63. SpawnPointInfoMap GetSpawnPoints() const;
  64. AZ::EntityId GetEditorEntityId() const;
  65. AZStd::unordered_map<AZStd::string, AZ::Data::Asset<AzFramework::Spawnable>> GetSpawnables() const;
  66. bool GetSupportWGS() const;
  67. private:
  68. ROS2SpawnerComponentConfig m_config;
  69. };
  70. } // namespace ROS2