ROS2SpawnPointComponentController.cpp 3.7 KB

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