ROS2SpawnPointComponentController.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. #ifndef WITH_GAZEBO_MSGS
  9. static_assert(false, "This file should not be included in the build, without WITH_GAZEBO_MSGS defined.");
  10. #endif
  11. #include "Spawner/ROS2SpawnPointComponentController.h"
  12. #include "Spawner/ROS2SpawnerComponentController.h"
  13. #include <AzCore/Component/TransformBus.h>
  14. #include <AzCore/Serialization/EditContext.h>
  15. #include <AzCore/Serialization/SerializeContext.h>
  16. namespace ROS2
  17. {
  18. void ROS2SpawnPointComponentConfig::Reflect(AZ::ReflectContext* context)
  19. {
  20. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  21. {
  22. serializeContext->Class<ROS2SpawnPointComponentConfig, AZ::ComponentConfig>()
  23. ->Version(1)
  24. ->Field("Name", &ROS2SpawnPointComponentConfig::m_name)
  25. ->Field("Info", &ROS2SpawnPointComponentConfig::m_info);
  26. if (auto editContext = serializeContext->GetEditContext())
  27. {
  28. editContext
  29. ->Class<ROS2SpawnPointComponentConfig>("ROS2SpawnPointComponentConfig", "Config for the ROS2 Spawn Point Component")
  30. ->ClassElement(AZ::Edit::ClassElements::EditorData, "Stores information about available spawn point")
  31. ->DataElement(AZ::Edit::UIHandlers::Default, &ROS2SpawnPointComponentConfig::m_name, "Name", "Name")
  32. ->DataElement(
  33. AZ::Edit::UIHandlers::Default, &ROS2SpawnPointComponentConfig::m_info, "Info", "Spawn point detailed description");
  34. }
  35. }
  36. }
  37. void ROS2SpawnPointComponentController::Reflect(AZ::ReflectContext* context)
  38. {
  39. ROS2SpawnPointComponentConfig::Reflect(context);
  40. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  41. {
  42. serializeContext->Class<ROS2SpawnPointComponentController>()->Version(1)->Field(
  43. "Configuration", &ROS2SpawnPointComponentController::m_config);
  44. AZ::EditContext* editContext = serializeContext->GetEditContext();
  45. if (editContext)
  46. {
  47. editContext
  48. ->Class<ROS2SpawnPointComponentController>("ROS2SpawnPointController", "Controller for the ROS2 Spawn Point Component")
  49. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  50. ->DataElement(AZ::Edit::UIHandlers::Default, &ROS2SpawnPointComponentController::m_config)
  51. ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly);
  52. }
  53. }
  54. }
  55. ROS2SpawnPointComponentController::ROS2SpawnPointComponentController(const ROS2SpawnPointComponentConfig& config)
  56. {
  57. SetConfiguration(config);
  58. }
  59. void ROS2SpawnPointComponentController::SetConfiguration(const ROS2SpawnPointComponentConfig& config)
  60. {
  61. m_config = config;
  62. }
  63. const ROS2SpawnPointComponentConfig& ROS2SpawnPointComponentController::GetConfiguration() const
  64. {
  65. return m_config;
  66. }
  67. void ROS2SpawnPointComponentController::Activate(AZ::EntityId entityId)
  68. {
  69. m_config.m_editorEntityId = entityId;
  70. }
  71. void ROS2SpawnPointComponentController::Deactivate()
  72. {
  73. }
  74. AZStd::pair<AZStd::string, SpawnPointInfo> ROS2SpawnPointComponentController::GetInfo() const
  75. {
  76. AZ::Transform transform = { AZ::Vector3{ 0, 0, 0 }, AZ::Quaternion{ 0, 0, 0, 1.0 }, 1.0 };
  77. AZ::TransformBus::EventResult(transform, m_config.m_editorEntityId, &AZ::TransformBus::Events::GetWorldTM);
  78. return { m_config.m_name, SpawnPointInfo{ m_config.m_info, transform } };
  79. }
  80. } // namespace ROS2