NamespaceComputation.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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/EntityId.h>
  10. #include <AzCore/std/containers/vector.h>
  11. #include <AzCore/std/string/string.h>
  12. #include <ROS2/Frame/ROS2FrameConfiguration.h>
  13. namespace ROS2
  14. {
  15. //! This method computes the namespace for a given entity based on the provided configuration.
  16. //! It considers the namespace strategy defined in the configuration and the entity's position in the hierarchy
  17. AZStd::string ComputeNamespace(AZ::EntityId entity);
  18. //! This method computes the namespace for vector of configurations and associated names.
  19. //! The configurations are expected to be ordered from the root to the leaf entity.
  20. AZStd::string ComputeNamespace(const AZStd::vector<AZStd::pair<AZStd::string, ROS2FrameConfiguration>>& configurations);
  21. //! Gets the namespaced name for the given entity, combining its namespace and frame name.
  22. //! for empty namespace, it returns just the name
  23. //! for non-empty namespace, it returns namespace/name
  24. AZStd::string GetNamespacedName(const AZStd::string& namespaceName, const AZStd::string& name);
  25. //! returns true if the entity has a ROS2FrameComponent or ROS2FrameEditorComponent
  26. //! @note to be used in Game and Editor contexts
  27. bool HasROS2FrameComponent(AZ::EntityId id);
  28. //! Returns all ancestor entities of the given entity that have a TransformComponent, including the entity itself.
  29. //! the root entity (e.g. level) is the last element in the vector
  30. //! @note to be used in Game and Editor contexts
  31. AZStd::vector<AZ::EntityId> GetAllAncestorTransformBus(const AZ::EntityId& id);
  32. //! Filters the given list of entity IDs and returns only those that have a ROS2FrameComponent or ROS2FrameEditorComponent.
  33. //! @note to be used in Game and Editor contexts
  34. AZStd::vector<AZ::EntityId> GetEntitiesWithROS2FrameComponent(const AZStd::vector<AZ::EntityId>& predecessors);
  35. //! Returns the first entity that has a ROS2FrameComponent or ROS2FrameEditorComponent.
  36. AZ::EntityId GetFirstEntityWithROS2FrameComponent(const AZStd::vector<AZ::EntityId>& predecessors);
  37. //! Returns the last entity that has a ROS2FrameComponent or ROS2FrameEditorComponent.
  38. AZ::EntityId GetLastEntityWithROS2FrameComponent(const AZStd::vector<AZ::EntityId>& predecessors);
  39. //! Global frame name in ros2 ecosystem.
  40. //! It is configurable through Settings Registry at /O3DE/ROS2/GlobalFrameName
  41. //! If not configured, it defaults to "odom".
  42. //! If empty, root frame is not published by the simulator.
  43. //! It is typically "odom", "map", "world".
  44. AZStd::string GetGlobalFrameIDFromRegistry();
  45. } // namespace ROS2