Karana.KUtils.Prefab#
Prefab base class and associated classes/functions.
Attributes#
Classes#
Module Contents#
- class Karana.KUtils.Prefab.Config(/, **data: Any)[source]#
Bases:
Karana.KUtils.DataStruct.DataStruct,Karana.KUtils.DataStruct.NestedBaseMixinBase class for Prefab Config.
- class Karana.KUtils.Prefab.Context(/, **data: Any)[source]#
Bases:
Karana.KUtils.DataStruct.DataStruct,Karana.KUtils.DataStruct.NestedBaseMixinBase class for Prefab Context.
- class Karana.KUtils.Prefab.Params(/, **data: Any)[source]#
Bases:
Karana.KUtils.DataStruct.DataStruct,Karana.KUtils.DataStruct.NestedBaseMixinBase class for Prefab Params.
- Karana.KUtils.Prefab.ConfigType#
- Karana.KUtils.Prefab.ContextType#
- Karana.KUtils.Prefab.ParamsType#
- class Karana.KUtils.Prefab.PrefabDS(/, **data: Any)[source]#
Bases:
Karana.KUtils.DataStruct.DataStruct,Karana.KUtils.DataStruct.NestedBaseMixin,Generic[ConfigType,ContextType,ParamsType]DataStruct for a Prefab.
Classes derived from Prefab may derive from this and override toDS/fromDS as desired. However, this should work for most Prefabs as is.
- Parameters:
name (str) – Name of the instance.
config (SerializeAsAny[Config]) – Config for the Prefab.
context (SerializeAsAny[Context]) – Context for the Prefab.
params (SerializeAsAny[Params]) – Params for the Prefab.
children (list[SerializeAsAny["PrefabDS"]]) – Children Prefabs of this Prefab.
class_name (str) – The fully qualified class name. Used to create a new instance of the class from this DataStruct.
- name: str#
- config: pydantic.SerializeAsAny[ConfigType]#
- context: pydantic.SerializeAsAny[ContextType]#
- params: pydantic.SerializeAsAny[ParamsType]#
- class_name: str#
- toPrefab(parent: Prefab[Any, Any, Any] | None) Prefab[Any, Any, Any][source]#
Convert this PrefabDS to an instance of the associated Prefab.
This will also create instances of any children Prefabs if applicable. :param parent: The parent to attach this Prefab to. :type parent: Prefab[Any, Any, Any] | None
- Returns:
An instance of the associated Prefab.
- Return type:
Prefab[Any, Any, Any]
- class Karana.KUtils.Prefab.Prefab(name: str, config: ConfigType, context: ContextType, params: ParamsType, parent_prefab: Prefab[Any, Any, Any] | None = None)[source]#
Bases:
Karana.Core.Base,Generic[ConfigType,ContextType,ParamsType]The Prefab class holds a prefab for a simulation.
Prefabs typically consist of one or more of the following: * Bodies * Models * Other prefabs
- config#
The configuration for the prefab.
- Type:
ConfigType
- context#
The context for the prefab.
- Type:
ContextType
- params#
The parameters for the Prefab.
- Type:
ParamsType
- config: ConfigType#
- context: ContextType#
- params: ParamsType#
- property parent: Prefab[Any, Any, Any] | None#
Returns the parent prefab of this prefab.
- Returns:
The parent prefab of this prefab if it exists.
- Return type:
“Prefab[Any, Any, Any] | None”
- runBeforeInitialSetParent()[source]#
Add any logic/commands that should run before the parent Prefab is set to this method.
This method runs during construction just before the parent Prefab is set.
- checkParentCompatible(parent: Prefab[Any, Any, Any] | None) bool[source]#
Check whether the parent Prefab this Prefab is becoming a child of is compatible.
- Parameters:
parent (Prefab | None) – The parent Prefab this Prefab is becoming a child of. Can be None if there is no parent.
- Returns:
True if the parent prefab is compatible, False otherwise.
- Return type:
bool
- checkChildCompatible(child: Prefab[Any, Any, Any]) bool[source]#
Check whether Prefab becoming a child of this Prefab is compatible.
- Parameters:
child (Prefab) – The Prefab becoming a child of this Prefab.
- Returns:
True if the child prefab is compatible, False otherwise.
- Return type:
bool
- addChildPrefabs() None[source]#
Add child prefabs to this prefab.
Override this method and add any child prefabs needed by this prefab.
- addMultibodyObjects() None[source]#
Add any multibody objects used by this prefab.
Override this method and add any multibody objects (e.g., PhysicalBodys, Nodes, etc.) used by this prefab.
- addKModels() None[source]#
Add KModels needed by this prefab.
Override this method and add any KModels needed by this prefab.
- connectKModels() None[source]#
Add any connections needed by KModels.
Override this method and add logic to connect KModels in this prefab to other KModels.
- toDS() PrefabDS[Config, Context, Params][source]#
Create a PrefabDS from this Prefab.
- Returns:
The DataStruct that represents this Prefab.
- Return type:
- classmethod fromDS(data_struct: PrefabDS, parent: Prefab[Any, Any, Any] | None) Self[source]#
Convert the PrefabDS to an instance of this Prefab.
This will also create instances of the associated children if applicable.
- requestFromHierarchy(path: str, fn: Callable[[Prefab[Any, Any, Any]], T | None], path_root: Prefab[Any, Any, Any] | None = None) list[Prefab.requestFromHierarchy.T][source]#
Make a request to the current hierarchy of prefabs.
This works by finding all the prefabs in the hierarchy that match the given path as searched from the path_root. If the path_root is None, then the root of the Prefab hierarchy is used. The provided fn is run on all the returned Prefab’s, and any non-None values returned from it are combined into a list and returned.
- Parameters:
path (str) – The path to use when finding prefabs in the hierarchy. This supports filesystem-like syntax, so globbing, wildcards, etc. can be used.
fn (Callable[[Prefab[Any, Any, Any]], T | None]) – The function to run on each Prefab matching path from the hierarchy.
path_root ("Prefab[Any, Any, Any] | None") – The root to search from. If None is provided, then the root of the hierarchy is used.
- Returns:
A list of objects returned by user provided function mapped over the Prefabs matching the path query.
- Return type:
list[T]