ROS2FrameEditorSystemComponent.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 "ROS2FrameEditorSystemComponent.h"
  9. #include "NamespaceComputation.h"
  10. #include "ROS2FrameEditorComponent.h"
  11. #include "ROS2FrameSystemBus.h"
  12. #include <AzCore/Component/ComponentApplicationBus.h>
  13. #include <AzCore/Component/ComponentBus.h>
  14. #include <AzCore/Component/Entity.h>
  15. #include <AzCore/Component/EntityId.h>
  16. #include <AzCore/std/containers/set.h>
  17. #include <AzCore/std/containers/vector.h>
  18. #include <AzCore/std/string/string.h>
  19. #include <AzToolsFramework/ToolsComponents/TransformComponent.h>
  20. #include <ROS2/Frame/ROS2FrameComponent.h>
  21. #include <ROS2/Frame/ROS2FrameEditorComponentBus.h>
  22. #include <ROS2/ROS2NamesBus.h>
  23. namespace ROS2
  24. {
  25. ROS2FrameEditorSystemComponent::ROS2FrameEditorSystemComponent()
  26. : ROS2FrameGameSystemComponent()
  27. {
  28. }
  29. void ROS2FrameEditorSystemComponent::Reflect(AZ::ReflectContext* context)
  30. {
  31. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  32. {
  33. serialize->Class<ROS2FrameEditorSystemComponent, AZ::Component>()->Version(1)->Attribute(
  34. AZ::Edit::Attributes::SystemComponentTags, AZStd::vector<AZ::Crc32>({ AZ_CRC_CE("AssetBuilder") }));
  35. }
  36. }
  37. void ROS2FrameEditorSystemComponent::Activate()
  38. {
  39. ROS2FrameGameSystemComponent::Activate();
  40. }
  41. void ROS2FrameEditorSystemComponent::Deactivate()
  42. {
  43. for (const auto& id : m_registeredEntities)
  44. {
  45. AZ::TransformNotificationBus::MultiHandler::BusDisconnect(id);
  46. AzToolsFramework::EntitySelectionEvents::Bus::MultiHandler::BusDisconnect(id);
  47. }
  48. ROS2FrameGameSystemComponent::Deactivate();
  49. }
  50. void ROS2FrameEditorSystemComponent::RegisterFrame(const AZ::EntityId& frameToRegister)
  51. {
  52. ROS2FrameGameSystemComponent::RegisterFrame(frameToRegister);
  53. AzToolsFramework::EntitySelectionEvents::Bus::MultiHandler::BusConnect(frameToRegister);
  54. AZ::TransformNotificationBus::MultiHandler::BusConnect(frameToRegister);
  55. }
  56. void ROS2FrameEditorSystemComponent::UnregisterFrame(const AZ::EntityId& frameToUnregister)
  57. {
  58. AZ::TransformNotificationBus::MultiHandler::BusDisconnect(frameToUnregister);
  59. AzToolsFramework::EntitySelectionEvents::Bus::MultiHandler::BusDisconnect(frameToUnregister);
  60. ROS2FrameGameSystemComponent::UnregisterFrame(frameToUnregister);
  61. }
  62. void ROS2FrameEditorSystemComponent::OnSelected()
  63. {
  64. // find which frame entity was selected
  65. AZStd::vector<AZ::EntityId> selectedEntityId;
  66. AzToolsFramework::ToolsApplicationRequests::Bus::BroadcastResult(
  67. selectedEntityId, &AzToolsFramework::ToolsApplicationRequests::GetSelectedEntities);
  68. // update
  69. for (const auto& selectedEntityId : selectedEntityId)
  70. {
  71. ROS2FrameEditorComponentBus::Event(selectedEntityId, &ROS2FrameEditorComponentRequests::UpdateNamespace);
  72. }
  73. }
  74. void ROS2FrameEditorSystemComponent::OnParentChanged([[maybe_unused]] AZ::EntityId oldParent, AZ::EntityId newParent)
  75. {
  76. AZStd::vector<AZ::EntityId> children;
  77. AZ::TransformBus::EventResult(children, newParent, &AZ::TransformBus::Events::GetEntityAndAllDescendants);
  78. // update
  79. for (const auto& child : children)
  80. {
  81. ROS2FrameEditorComponentBus::Event(child, &ROS2FrameEditorComponentRequests::UpdateNamespace);
  82. }
  83. }
  84. } // namespace ROS2