diff --git a/pyrobosim/pyrobosim/core/locations.py b/pyrobosim/pyrobosim/core/locations.py index d1ab0912..47235b6f 100644 --- a/pyrobosim/pyrobosim/core/locations.py +++ b/pyrobosim/pyrobosim/core/locations.py @@ -47,6 +47,16 @@ def add_metadata(cls, filename): cls.metadata.add(filename) + @classmethod + def clearout_metadata(cls): + """ + Clear out old location metadata. + """ + if not hasattr(cls, "metadata"): + cls.metadata = EntityMetadata() + cls.metadata.data = {} + cls.metadata.sources = [] + def __init__( self, name=None, diff --git a/pyrobosim/pyrobosim/core/objects.py b/pyrobosim/pyrobosim/core/objects.py index 6a4d8fcc..f29a3c17 100644 --- a/pyrobosim/pyrobosim/core/objects.py +++ b/pyrobosim/pyrobosim/core/objects.py @@ -48,6 +48,16 @@ def add_metadata(cls, filename): cls.metadata.add(filename) + @classmethod + def clearout_metadata(cls): + """ + Clear out old object metadata. + """ + if not hasattr(cls, "metadata"): + cls.metadata = EntityMetadata() + cls.metadata.data = {} + cls.metadata.sources = [] + def __init__( self, name=None, diff --git a/pyrobosim/pyrobosim/core/world.py b/pyrobosim/pyrobosim/core/world.py index b145fc1b..098d8d18 100644 --- a/pyrobosim/pyrobosim/core/world.py +++ b/pyrobosim/pyrobosim/core/world.py @@ -96,17 +96,11 @@ def set_metadata(self, locations=None, objects=None): :param objects: Path(s) to object metadata YAML file(s). :type objects: str | list[str] | None """ - if isinstance(locations, list): - for location in locations: - Location.add_metadata(location) - elif isinstance(locations, str): - Location.add_metadata(locations) + # Clear out old metadata + Location.clearout_metadata() + Object.clearout_metadata() - if isinstance(objects, list): - for object in objects: - Object.add_metadata(object) - elif isinstance(objects, str): - Object.add_metadata(objects) + self.add_metadata(locations, objects) def add_metadata(self, locations=None, objects=None): """