blueprints.utils.naming module#
- class blueprints.utils.naming.NameManager[source]#
Bases:
objectThe Namemanager is a attribute of the root Thing in a kinematic tree. It resolves name conflicts by finding synonymous Things and renaming them by adding a numeration. If a renamin results in a new naming conflicts, another round of renaming is applied unti all conflicts are resolved.
For example, if there are four Geoms in a kinematic tree that are named by the user respectively:
USERNAMES#"rock", "rock", "rock_(1)", "stone"
A name conflict exists for the first two geoms. The name conflict resolving after the first round would result in the names
RENAMING (1)#"rock_(0)", "rock_(1)", "rock_(0)", "stone"
Now a name conflict for the first and the third name exists, because the user name for the third Geom coincidentally alligns with the numeration scheme of the resolver. Therefore a second renaming round results in the names
RENAMING (2)#"rock_(0)_(0)", "rock_(1)", "rock_(0)_(1)", "stone"
The cascading of numerations can be avoided by not ending user defined names with
"_(<int>)".- root#
The root node for which the NameManager resolves nameing conflicts.
- Type:
ThingType
- type_scopes#
Identical names only result in conflicts if they are given to Thing of the same type. The type_scopes dict splits the name resolving for all objects of one type.
- Type:
dict
- class blueprints.utils.naming.TypeScope[source]#
Bases:
objectThis class upon initialization resolves name conflicts for all elements of a specifig Type. After renaming of assigned Things by the user, the register method is called automatically to resolve potentially new conflicts.
- descendants#
A list of all Things that are captured under the TypeScope.
- Type:
list
- name_manager#
The NameManager to which the TypeScope is assigned.
- Type:
- name_scopes#
A dictionary containing the NameScopes for each user defined name.
- Type:
dict
- __init__(name_manager, descendants)[source]#
Upon initialization name conflicts are resolved for all descendants.
- Parameters:
name_manager (
NameManager) – The NameManager to which the TypeScope is assigned.descendants (
list) – A list of all Things that are captured under the TypeScope.
- register()[source]#
Calling this method resolves name conflicts for all assigned descendants of root. After a assigned Thing is renamed register is called automatically to resolve potential new conflicts.
- synonyms()[source]#
This method gathers Things that are synomymous (share the same name). This method takes renaming into acount, so after one round of renaming has taken place, calling this method again, will result in synonyms according to the previous renaming.
- Returns:
Keys of the dictionary are names and the values are lists containing all Things under the scope of the given name.
- Return type:
dict
- class blueprints.utils.naming.NameScope[source]#
Bases:
objectThe NameScope class resolves the name conflicts for Things of the same Type and the same assigned name (either by the user or by a previous name conflict resolving iteration).
- descendants#
- Type:
list
- A list of all descendants of the same Type with the same name.
- The TypeScope to which the NameScope is assigned.
- __init__(type_scope, name, descendants)[source]#
After the initialization the name conflicts for all given devendents are resolved.
- Parameters:
type_scope (
TypeScope) – The TypeScope to which the NameScope is assigned.name (
str) – The initial name of all Things assigned to the NameScope.descendants (
list) – A list of all descendants of the same Type with the same name.
- register()[source]#
This method assignes all descendants to this NameScope. Afterwards a unique name can be requested by the descendant.