Pārlūkot izejas kodu

extend functionality of FrameConversion.py (#772)

* add additional logic to apply ROS2Frame conversion to overrides
* since the ROS2FrameComponent is not mentioned directly in the patch path use the ROS2FrameComponent field names to correctly identify replacements

Signed-off-by: Mateusz Żak <[email protected]>
Mateusz Żak 10 mēneši atpakaļ
vecāks
revīzija
aa4489c5f2

+ 21 - 6
Gems/ROS2/Code/Source/Frame/Conversions/FrameConversion.py

@@ -12,7 +12,7 @@ import decimal
 
 
 def find_and_replace(data):
 def find_and_replace(data):
 
 
-    def search_for_components(item, foundComponents):
+    def search_for_components(item, foundComponents, insidePatches=False):
         if isinstance(item, dict):
         if isinstance(item, dict):
             if "Components" in item:
             if "Components" in item:
                 foundComponents = True
                 foundComponents = True
@@ -32,13 +32,28 @@ def find_and_replace(data):
                     modifiedElement["ROS2FrameConfiguration"] = modifiedElement["m_template"]
                     modifiedElement["ROS2FrameConfiguration"] = modifiedElement["m_template"]
                     del modifiedElement["m_template"]
                     del modifiedElement["m_template"]
                     item = modifiedElement
                     item = modifiedElement
-            if "op" in item and item["op"] == "replace" and "path" in item:
-                item["path"] = item["path"].replace("ROS2FrameComponent/m_template", "ROS2FrameEditorComponent/ROS2FrameConfiguration")
-            for value in item.values():
-                search_for_components(value, foundComponents)
+
+            # Check if inside "Patches" section
+            if "Patches" in item:
+                insidePatches = True
+
+            # Only apply path changes inside "Patches"
+            if insidePatches and "op" in item and "path" in item:
+                # We directly look for the ROS2FrameComponent fields and replace "m_template" with "ROS2FrameConfiguration"
+                if any(substring in item["path"] for substring in [
+                    "m_template/Namespace Configuration",
+                    "m_template/Frame Name",
+                    "m_template/Publish Transform",
+                    "m_template/Joint Name"
+                ]):
+                    item["path"] = item["path"].replace("m_template", "ROS2FrameConfiguration")
+
+            for key, value in item.items():
+                search_for_components(value, foundComponents, insidePatches)
+
         elif isinstance(item, list):
         elif isinstance(item, list):
             for element in item:
             for element in item:
-                search_for_components(element, foundComponents)
+                search_for_components(element, foundComponents, insidePatches)
 
 
     search_for_components(data, False)
     search_for_components(data, False)