Skip to content

Commit

Permalink
Fix rename
Browse files Browse the repository at this point in the history
  • Loading branch information
hwiedPro committed Sep 26, 2023
1 parent 685c201 commit 459e525
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
8 changes: 1 addition & 7 deletions phobos/ci/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,13 +571,7 @@ def process(self):
config = misc.merge_default(self.joints[jointname], _default)
joint.name = misc.edit_name_string(joint.name, **config.get("name_editing", {}))
if "$name_editing" in self.joints:
if self.joints["$name_editing"].get("joint_equals_link_name", False):
for joint in self.robot.joints:
self.robot.rename(targettype="joint", target=joint.name, replacements={
joint.name: joint.child if not joint.child.upper().endswith("_LINK") else joint.child[:-5]
})
else:
self.robot.rename("joints", self.robot.joints, **self.joints.get("$name_editing", {}))
self.robot.rename("joints", self.robot.joints, **self.joints.get("$name_editing", {}))
# as we mess manually with some names, we need to make sure the tree maps are up to date
self.robot.regenerate_tree_maps()

Expand Down
13 changes: 9 additions & 4 deletions phobos/core/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1850,7 +1850,7 @@ def rename_all(self, prefix=None, suffix=None, replacements=None, do_not_double=
self.rename(targettype, getattr(self, targettype), prefix=prefix, suffix=suffix, replacements=replacements,
do_not_double=do_not_double)

def rename(self, targettype, target, prefix=None, suffix=None, replacements=None, do_not_double=True):
def rename(self, targettype, target, prefix=None, suffix=None, replacements=None, do_not_double=True, joint_equals_link_name=False):
"""
Renames the target with the given args
Note: Override this in subclasses and call super at the beginning
Expand All @@ -1866,7 +1866,8 @@ def rename(self, targettype, target, prefix=None, suffix=None, replacements=None
if type(target) is list:
for t in target:
renamed_entities.update(self.rename(targettype, t, prefix=prefix, suffix=suffix,
replacements=replacements, do_not_double=do_not_double))
replacements=replacements, do_not_double=do_not_double,
joint_equals_link_name=joint_equals_link_name))
return renamed_entities
elif type(target) is not str:
target = str(target)
Expand All @@ -1878,10 +1879,14 @@ def rename(self, targettype, target, prefix=None, suffix=None, replacements=None
if suffix is not None and target.endswith(suffix):
suffix = None

if not prefix and not suffix and replacements == {}:
if not prefix and not suffix and replacements == {} and not joint_equals_link_name:
return renamed_entities

new_name = edit_name_string(target, prefix=prefix, suffix=suffix, replacements=replacements)
if targettype.startswith("joint") and joint_equals_link_name:
joint = self.get_joint(target)
new_name = joint.child if not joint.child.upper().endswith("_LINK") else joint.child[:-5]
else:
new_name = edit_name_string(target, prefix=prefix, suffix=suffix, replacements=replacements)
renamed_entities.update(self._rename(targettype, target, new_name))

if targettype in ['link', "links"]:
Expand Down

0 comments on commit 459e525

Please sign in to comment.