-
Notifications
You must be signed in to change notification settings - Fork 37
/
userelement.py
60 lines (51 loc) · 2.04 KB
/
userelement.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from .exception import fatal, warning
class UserElement:
"""
Common class for all types of elements (volume, source or actor)
Manager a dict (Box) for user parameters: user_info
Check that all the required keys are provided
"""
def __init__(self, user_info):
# set the user info (a kind of dict)
# check everything is there (except for solid building)
check_user_info(user_info) # removed to avoid circular import
# self.check_user_info()
self.user_info = user_info
# check type_name
if self.user_info.type_name != self.type_name:
fatal(
f"Error, the type_name inside the user_info is different "
f"from the type_name of the class: {self.user_info} in the "
f"class {self.__name__} {self.type_name}"
)
# by default the name is a unique id (uuid)
if not self.user_info.name:
fatal(
f"Error a {self.user_info.volume_type} must have "
f"a valid name, while it is {self.user_info.name}"
)
# debug
self.verbose_getstate = False
self.verbose_close = False
@staticmethod
def set_default_user_info(user_info):
# Should be overwritten by subclass
pass
def __str__(self):
s = f"Element: {self.user_info}"
return s
def set_simulation(self, simulation):
self.simulation = simulation
if simulation is not None:
self.verbose_getstate = self.simulation.verbose_getstate
self.verbose_close = self.simulation.verbose_close
def check_user_info(user_info):
# get a fake ui to compare
from .userinfo import UserInfo
ref_ui = UserInfo(user_info.element_type, user_info.type_name)
for val in ref_ui.__dict__:
if val not in user_info.__dict__:
fatal(f'Cannot find "{val}" in {user_info}')
for val in user_info.__dict__:
if val not in ref_ui.__dict__.keys():
warning(f'Unused param "{val}" in {user_info}')