semantic_digital_twin.adapters.world_entity_kwargs_tracker#

Classes#

KinematicStructureEntityKwargsTracker

Keeps track of the kinematic structure entities that have been parsed in a from_json call from SubclassJSONSerializer.

Module Contents#

class semantic_digital_twin.adapters.world_entity_kwargs_tracker.KinematicStructureEntityKwargsTracker#

Keeps track of the kinematic structure entities that have been parsed in a from_json call from SubclassJSONSerializer. Usage:

Top-level object must create a new tracker, optionally using a world instance if present, and pass it along:

tracker = KinematicStructureEntityKwargsTracker.from_world(world) SubclassJSONSerializer.from_json(json_data, **tracker.create_from_json_kwargs())

Objects that create kinematic structure entities:
def _from_json(cls, data: Dict[str, Any], **kwargs) -> Self:

new_instance = cls(…) tracker = KinematicStructureEntityKwargsTracker.from_kwargs(kwargs) tracker.add_kinematic_structure_entity(new_instance) …

Objects that need kinematic structure entities for parsing:
def _from_json(cls, data: Dict[str, Any], **kwargs) -> Self:

tracker = KinematicStructureEntityKwargsTracker.from_kwargs(kwargs) entity = tracker.get_kinematic_structure_entity(name_of_entity) …

classmethod from_kwargs(from_json_kwargs) typing_extensions.Self#

Retrieve the tracker from the kwargs, or initialize a new one if it doesn’t exist. Adds itself to the kwargs so that it is available for future from_json calls. :param from_json_kwargs: the **kwargs of a from_json call.

classmethod from_world(world: semantic_digital_twin.world.World) typing_extensions.Self#

Create a new tracker from a world. :param world: A world instance that will be used as a backup to look for world entities.

create_kwargs() typing_extensions.Dict[str, typing_extensions.Self]#

Creates a new kwargs that contains the tracker. The top-level object that calls from_json should add this to its kwargs. :return: A new kwargs dict with the tracker.

add_to_kwargs(kwargs: typing_extensions.Dict[str, typing_extensions.Any])#

Adds the current instance to the provided keyword arguments dictionary, using a specific key internally defined within the instance.

Parameters:

kwargs – A dictionary to which the current instance will be added. The specific key is determined by the internal attribute of the instance.

Returns:

None

add_kinematic_structure_entity(kinematic_structure_entity: semantic_digital_twin.world_description.world_entity.KinematicStructureEntity)#

Add a new kinematic structure entity to the tracker, to make it available for parsing in future from_json calls.

has_kinematic_structure_entity(id: uuid.UUID) bool#
get_kinematic_structure_entity(id: uuid.UUID) semantic_digital_twin.world_description.world_entity.KinematicStructureEntity#

Retrieve a kinematic structure entity by its UUID.

This method attempts to find a kinematic structure entity from the internal collection. If the entity is not found and a world object is available, it will try to retrieve the entity by its UUID from the world object.

Parameters:

id – The UUID of the kinematic structure entity to retrieve.

Returns:

The kinematic structure entity corresponding to the specified UUID, or None if not found.