NamespaceConfiguration.cpp 2.6 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. #include <AzCore/Serialization/EditContext.h>
  9. #include <AzCore/Serialization/EditContextConstants.inl>
  10. #include <ROS2/Frame/NamespaceConfiguration.h>
  11. #include <ROS2/ROS2NamesBus.h>
  12. namespace ROS2
  13. {
  14. AZ::Outcome<void, AZStd::string> NamespaceConfiguration::ValidateNamespaceField(void* newValue, const AZ::Uuid& valueType)
  15. {
  16. AZ::Outcome<void, AZStd::string> outcome;
  17. ROS2NamesRequestBus::BroadcastResult(outcome, &ROS2NamesRequests::ValidateNamespaceField, newValue, valueType);
  18. return outcome;
  19. }
  20. bool NamespaceConfiguration::IsNamespaceCustom() const
  21. {
  22. return m_namespaceStrategy == NamespaceConfiguration::NamespaceStrategy::Custom;
  23. }
  24. void NamespaceConfiguration::Reflect(AZ::ReflectContext* context)
  25. {
  26. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  27. {
  28. serializeContext->Class<NamespaceConfiguration>()
  29. ->Version(1)
  30. ->Field("Namespace Strategy", &NamespaceConfiguration::m_namespaceStrategy)
  31. ->Field("Namespace", &NamespaceConfiguration::m_customNamespace);
  32. if (AZ::EditContext* ec = serializeContext->GetEditContext())
  33. {
  34. ec->Class<NamespaceConfiguration>("Namespace Configuration", "Handles ROS2 namespaces")
  35. ->DataElement(
  36. AZ::Edit::UIHandlers::ComboBox,
  37. &NamespaceConfiguration::m_namespaceStrategy,
  38. "Namespace strategy",
  39. "Determines how namespace for frames and topics is created from the hierarchy")
  40. ->EnumAttribute(NamespaceConfiguration::NamespaceStrategy::Default, "Default")
  41. ->EnumAttribute(NamespaceConfiguration::NamespaceStrategy::Empty, "Empty")
  42. ->EnumAttribute(NamespaceConfiguration::NamespaceStrategy::FromEntityName, "Generate from entity name")
  43. ->EnumAttribute(NamespaceConfiguration::NamespaceStrategy::Custom, "Custom")
  44. ->DataElement(AZ::Edit::UIHandlers::Default, &NamespaceConfiguration::m_customNamespace, "Namespace", "Namespace")
  45. ->Attribute(AZ::Edit::Attributes::Visibility, &NamespaceConfiguration::IsNamespaceCustom)
  46. ->Attribute(AZ::Edit::Attributes::ChangeValidate, &NamespaceConfiguration::ValidateNamespaceField);
  47. }
  48. }
  49. }
  50. } // namespace ROS2