Skip to content

Commit

Permalink
fix: name map undescore methods that shouldn't be used (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
zevbo authored Sep 1, 2023
1 parent c495ea1 commit 5b9876b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 68 deletions.
62 changes: 0 additions & 62 deletions urdf_compose/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,74 +40,12 @@ def general_urdf_append(
"""


# A visualization tool for URDFTree would be super cool
# class URDFTree:
# """
# Represents a web of URDFObjects that can be connected
# """

# def __init__(
# self,
# urdf: URDFObj,
# *children: tuple[GenURDFTree, URDFConn],
# ):
# self.urdf = urdf
# self.children = children

# def connect_safe(self) -> ComposedURDFObj | URDFComposeError:
# children_urdfs = list[tuple[URDFObj, URDFDefConn]]()
# for tree, conn in self.children:
# obj = tree if isinstance(tree, URDFObj) else tree.connect_safe()
# if not isinstance(obj, URDFObj):
# return obj
# def_conn = resolve_conn(
# self.urdf,
# tree if isinstance(tree, URDFObj) else tree.urdf,
# conn,
# )
# if isinstance(def_conn, URDFComposeError):
# return def_conn
# children_urdfs.append((obj, def_conn))
# return general_urdf_append(self.urdf, children_urdfs, use_name_map=False)

# def connect(self, log_errored_urdf_dir: Path | None = None) -> ComposedURDFObj:
# result = self.connect_safe()
# if isinstance(result, URDFComposeError):
# if log_errored_urdf_dir is not None:
# result.save_to(log_errored_urdf_dir)
# raise result
# return result

# def __iter__(self) -> Iterator[URDFObj]:
# yield self.urdf
# for child, _ in self.children:
# if isinstance(child, URDFObj):
# yield child
# else:
# for urdf in child:
# yield urdf


def fix_urdf_obj_child(
c: URDFObjChild,
) -> tuple[URDFObjOrError, URDFConn]:
return c if isinstance(c, tuple) else (c, URDFConn())


# def branch(urdf: URDFObj, children: Iterable[TreeChild]) -> URDFTree:
# """
# Creates a URDFTree with urdf as the base, and where each value in children
# is directly connected to urdf

# Raises a runtime error if given two of the same urdfs.
# """
# children_trees_or_urdfs = [child[0] if isinstance(child, tuple) else child for child in children]
# children_urdfs = [tree_or_urdf for tree_or_urdf in children_trees_or_urdfs if isinstance(tree_or_urdf, URDFObj)]
# all_urdfs = [urdf] + children_urdfs'
# if len(all_urdfs) != len(set(all_urdfs)):
# raise RuntimeError("Attempted to create branch with two of the same URDFs. This is an illegal operation.")
# return URDFTree(urdf, *[fix_tree_child(c) for c in children])

T = TypeVar("T")


Expand Down
12 changes: 6 additions & 6 deletions urdf_compose/composed_urdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def construct(explicit_urdf: URDFObj) -> ComposedURDFNameMap:
name_to_urdf_and_og_name=name_to_urdf_and_og_name,
)

def incorporate(self, other_map: Self) -> None:
def _incorporate(self, other_map: Self) -> None:
overlapping_names = set(self.name_to_urdf_and_og_name.keys()).intersection(
other_map.name_to_urdf_and_og_name.keys()
)
Expand All @@ -85,13 +85,13 @@ def incorporate(self, other_map: Self) -> None:
self.name_map_lookup.update(other_map.name_map_lookup)
self.name_to_urdf_and_og_name.update(other_map.name_to_urdf_and_og_name)

def rename(self, name: str, new_name: str) -> None:
def _rename(self, name: str, new_name: str) -> None:
explicit_urdf, og_name = self.name_to_urdf_and_og_name[name]
self.name_map_lookup[explicit_urdf][og_name] = new_name
self.name_to_urdf_and_og_name[new_name] = (explicit_urdf, og_name)
del self.name_to_urdf_and_og_name[name]

def remove(self, name: str) -> None:
def _remove(self, name: str) -> None:
explicit_urdf, og_name = self.name_to_urdf_and_og_name[name]
del self.name_to_urdf_and_og_name[name]
name_map = self.name_map_lookup[explicit_urdf]
Expand Down Expand Up @@ -231,7 +231,7 @@ def rename_elements(self, name_map: dict[str, str]) -> None:
name_dict = frozenset([NAME_KEY, "link"])

for name, new_name in name_map.items():
self.name_map.rename(name, new_name)
self.name_map._rename(name, new_name)

def rename_element(el: ET.Element) -> None:
if has_name(el, name_dict) and (name := get_name(el, name_dict)) in name_map:
Expand Down Expand Up @@ -262,15 +262,15 @@ def remove_duplicate_materials(self, base_urdf: URDFObj) -> None:
self.getroot().remove(extend_el)
name = get_name(extend_el)
if name is not None:
self.name_map.remove(name)
self.name_map._remove(name)

def copy(self) -> ComposedURDFObj:
return ComposedURDFObj(copy.deepcopy(self.tree), self.name_map.copy())

def concatenate(self, obj: Self) -> None:
obj_copy = obj.copy()
obj_copy.outlaw_duplicates_with(self)
self.name_map.incorporate(obj_copy.name_map)
self.name_map._incorporate(obj_copy.name_map)
for el in obj_copy.getroot():
self.getroot().append(el)

Expand Down

0 comments on commit 5b9876b

Please sign in to comment.