소스 검색

Fix of three minor bugs in Articulations in ROS 2 gem: (#844)

- Invalid default for topic name
- "Find all values" button gives correct values for :
   JointsManipulationEditorComponent, JointsPositionsEditorComponent
- Add undo batch to trigger prefab modification.

Signed-off-by: Michał Pełka <[email protected]>
Michał Pełka 4 달 전
부모
커밋
9b6d5a0ed4

+ 4 - 0
Gems/ROS2/Code/Include/ROS2/Frame/ROS2FrameEditorComponent.h

@@ -75,6 +75,10 @@ namespace ROS2
         AZ::EntityId GetFrameParent() const override;
         AZStd::set<AZ::EntityId> GetFrameChildren() const override;
 
+
+        //! Get the configuration of this component.
+        ROS2FrameConfiguration GetConfiguration() const;
+
     private:
         AZ::Crc32 OnFrameConfigurationChange();
 

+ 5 - 0
Gems/ROS2/Code/Source/Frame/ROS2FrameEditorComponent.cpp

@@ -177,4 +177,9 @@ namespace ROS2
         gameEntity->CreateComponent<ROS2FrameComponent>(m_configuration);
     }
 
+    ROS2FrameConfiguration ROS2FrameEditorComponent::GetConfiguration() const
+    {
+        return m_configuration;
+    }
+
 } // namespace ROS2

+ 8 - 5
Gems/ROS2Controllers/Code/Source/Manipulation/JointsManipulationEditorComponent.cpp

@@ -13,6 +13,7 @@
 #include <AzCore/Component/TransformBus.h>
 #include <AzCore/Serialization/EditContext.h>
 #include <AzCore/std/functional.h>
+#include <AzToolsFramework/API/ToolsApplicationAPI.h>
 #include <ROS2/Frame/ROS2FrameEditorComponent.h>
 #include <ROS2/ROS2GemUtilities.h>
 #include <ROS2/Utilities/ROS2Names.h>
@@ -94,6 +95,7 @@ namespace ROS2Controllers
 
     AZ::Crc32 JointsManipulationEditorComponent::ReloadJoints()
     {
+        AzToolsFramework::ScopedUndoBatch undo("ReloadJoints");
         // create backup of the configuration
         AZStd::unordered_map<AZStd::string, float> configBackup;
         for (const auto& [jointName, jointValue] : m_initialPositions)
@@ -110,7 +112,7 @@ namespace ROS2Controllers
 
             const bool hasNonFixedJoints = JointUtils::HasNonFixedJoints(entity);
 
-            AZStd::string jointName(frameEditorComponent->GetJointName().GetCStr());
+            const AZStd::string jointName(frameEditorComponent->GetConfiguration().m_jointName);
             if (!jointName.empty() && hasNonFixedJoints)
             {
                 m_initialPositions.emplace_back(AZStd::make_pair(jointName, configBackup[jointName]));
@@ -121,14 +123,15 @@ namespace ROS2Controllers
             {
                 for (const auto& entityId : childrenEntityIds)
                 {
-                    AZ::Entity* entity = nullptr;
-                    AZ::ComponentApplicationBus::BroadcastResult(entity, &AZ::ComponentApplicationBus::Events::FindEntity, entityId);
-                    getAllJointsHierarchy(entity);
+                    AZ::Entity* childEntity = nullptr;
+                    AZ::ComponentApplicationBus::BroadcastResult(childEntity, &AZ::ComponentApplicationBus::Events::FindEntity, entityId);
+                    AZ_Assert(childEntity, "Entity not found!");
+                    getAllJointsHierarchy(childEntity);
                 }
             }
         };
         getAllJointsHierarchy(GetEntity());
-
+        undo.MarkEntityDirty(GetEntity()->GetId());
         return AZ::Edit::PropertyRefreshLevels::EntireTree;
     }
 } // namespace ROS2Controllers

+ 9 - 6
Gems/ROS2Controllers/Code/Source/Manipulation/JointsPositionsEditorComponent.cpp

@@ -15,6 +15,7 @@
 #include <AzCore/Serialization/EditContext.h>
 #include <AzCore/Serialization/SerializeContext.h>
 
+#include <AzToolsFramework/API/ToolsApplicationAPI.h>
 #include <AzToolsFramework/ToolsComponents/EditorComponentBase.h>
 #include <ROS2/Frame/ROS2FrameEditorComponent.h>
 #include <ROS2/ROS2GemUtilities.h>
@@ -25,7 +26,7 @@ namespace ROS2Controllers
     JointsPositionsEditorComponent::JointsPositionsEditorComponent()
     {
         m_topicConfiguration.m_type = "std_msgs::msg::Float64MultiArray";
-        m_topicConfiguration.m_topic = "/position_controller/commands";
+        m_topicConfiguration.m_topic = "position_controller/commands";
     }
 
     void JointsPositionsEditorComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
@@ -77,6 +78,7 @@ namespace ROS2Controllers
 
     AZ::Crc32 JointsPositionsEditorComponent::FindAllJoints()
     {
+        AzToolsFramework::ScopedUndoBatch undo("FindAllJoints");
         m_jointNames.clear();
         AZStd::function<void(const AZ::Entity* entity)> getAllJointsHierarchy = [&](const AZ::Entity* entity)
         {
@@ -86,7 +88,7 @@ namespace ROS2Controllers
 
             const bool hasNonFixedJoints = JointUtils::HasNonFixedJoints(entity);
 
-            AZStd::string jointName(frameEditorComponent->GetJointName().GetCStr());
+            const AZStd::string jointName(frameEditorComponent->GetJointName().GetCStr());
             if (!jointName.empty() && hasNonFixedJoints)
             {
                 m_jointNames.emplace_back(jointName);
@@ -97,14 +99,15 @@ namespace ROS2Controllers
             {
                 for (const auto& entityId : childrenEntityIds)
                 {
-                    AZ::Entity* entity = nullptr;
-                    AZ::ComponentApplicationBus::BroadcastResult(entity, &AZ::ComponentApplicationBus::Events::FindEntity, entityId);
-                    getAllJointsHierarchy(entity);
+                    AZ::Entity* childEntity = nullptr;
+                    AZ::ComponentApplicationBus::BroadcastResult(childEntity, &AZ::ComponentApplicationBus::Events::FindEntity, entityId);
+                    AZ_Assert(childEntity, "Entity not found!");
+                    getAllJointsHierarchy(childEntity);
                 }
             }
         };
         getAllJointsHierarchy(GetEntity());
-
+        undo.MarkEntityDirty(GetEntity()->GetId());
         return AZ::Edit::PropertyRefreshLevels::EntireTree;
     }