SnapProviderRegistry#
- class omni.kit.manipulator.tool.snap.SnapProviderRegistry#
Bases:
objectA registry for managing SnapProvider instances as a singleton.
This class handles the registration and unregistration of SnapProvider classes, which are used for snapping objects in a 3D environment. It allows subscribing and unsubscribing to registry change events, enabling other parts of the application to react to changes in the SnapProvider ecosystem.
Methods
__init__()Initializes the SnapProviderRegistry singleton instance.
destroy()Destroys the singleton instance of the SnapProviderRegistry.
Gets the singleton instance of the SnapProviderRegistry.
Retrieves a registered SnapProvider class by its name.
register_provider(provider_class)Registers a new SnapProvider class to the registry.
subscribe_to_registry_change(callback)Subscribes a callback to the event that is triggered when the provider registry changes.
unregister_provider(provider_class)Unregisters an existing SnapProvider class from the registry.
Unsubscribes a previously subscribed callback from the registry change event.
Attributes
Gets all provider classes.
- __init__()#
Initializes the SnapProviderRegistry singleton instance.
- Raises:
RuntimeError – If an instance already exists.
- destroy()#
Destroys the singleton instance of the SnapProviderRegistry.
- classmethod get_instance() SnapProviderRegistry#
Gets the singleton instance of the SnapProviderRegistry.
- Returns:
The singleton instance of the registry.
- Return type:
- get_provider_class_by_name(
- name: str,
Retrieves a registered SnapProvider class by its name.
- Parameters:
name (str) – The name of the provider class to retrieve.
- Returns:
The provider class if found, otherwise None.
- Return type:
Type[SnapProvider] or None
- register_provider(
- provider_class: Type[SnapProvider],
Registers a new SnapProvider class to the registry.
- Parameters:
provider_class (Type[SnapProvider]) – The class of the provider to be registered.
- Raises:
ValueError – If a provider with the same name is already registered.
- subscribe_to_registry_change(
- callback: Callable[[], None],
Subscribes a callback to the event that is triggered when the provider registry changes.
- Parameters:
callback (Callable[[], None]) – The callback to be invoked when the registry changes. It is called immediately before function returns.
- Returns:
An ID that can be used to unsubscribe the callback later.
- Return type:
int
- unregister_provider(
- provider_class: Type[SnapProvider],
Unregisters an existing SnapProvider class from the registry.
- Parameters:
provider_class (Type[SnapProvider]) – The class of the provider to be unregistered.
- unsubscribe_to_registry_change(id: int)#
Unsubscribes a previously subscribed callback from the registry change event.
- Parameters:
id (int) – The ID returned by subscribe_to_registry_change when the callback was initially subscribed.
- property providers: Dict[str, Type[SnapProvider]]#
Gets all provider classes.
- Returns:
A dictionary mapping provider names to their respective SnapProvider classes.
- Return type:
Dict[str, Type[SnapProvider]]