2
0

ROS2GemUtilities.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 <AzCore/std/string/regex.h>
  9. #include <AzToolsFramework/API/EntityCompositionRequestBus.h>
  10. #include <ROS2/ROS2GemUtilities.h>
  11. namespace ROS2
  12. {
  13. AZ::ComponentId Utils::CreateComponent(const AZ::EntityId entityId, const AZ::Uuid componentType)
  14. {
  15. const AZ::ComponentTypeList componentsToAdd{ componentType };
  16. const AZStd::vector<AZ::EntityId> entityIds{ entityId };
  17. AzToolsFramework::EntityCompositionRequests::AddComponentsOutcome addComponentsOutcome = AZ::Failure(AZStd::string());
  18. AzToolsFramework::EntityCompositionRequestBus::BroadcastResult(
  19. addComponentsOutcome, &AzToolsFramework::EntityCompositionRequests::AddComponentsToEntities, entityIds, componentsToAdd);
  20. if (!addComponentsOutcome.IsSuccess())
  21. {
  22. AZ_Warning(
  23. "URDF importer",
  24. false,
  25. "Failed to create component %s, entity %s : %s",
  26. componentType.ToString<AZStd::string>().c_str(),
  27. entityId.ToString().c_str(),
  28. addComponentsOutcome.GetError().c_str());
  29. }
  30. const auto& added = addComponentsOutcome.GetValue().at(entityId).m_componentsAdded;
  31. if (!added.empty())
  32. {
  33. return added.front()->GetId();
  34. }
  35. return AZ::InvalidComponentId;
  36. }
  37. } // namespace ROS2