-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
executable file
·79 lines (62 loc) · 1.98 KB
/
model.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
from .objects import Distance
from .objects import Environmental
from .objects import Grid
class Model:
"""
In this container all shellspec objects
that will be modelled + the orbit are stored.
"""
def __init__(self, name='', objects=[]):
"""
"""
# available objects and their names
self.__registered_objects = [obj.get_name() for obj in objects]
# set the object name and pass models
self.__name = name,
self.__objects = {obj.get_name():obj for obj in objects}
# some shellspec objects are common for every
# model -- if they are not provided, they will
# be attached automatically
if not self.has_object('distance'):
self.add_object(Distance())
if not self.has_object('grid'):
self.add_object(Grid())
if not self.has_object('enviromental'):
self.add_object(Environmental())
def add_object(self, obj):
"""
"""
# register the name
obj_name = obj.get_name()
# register the object
self.__registered_objects.append(obj_name)
self.__objects[obj_name] = obj
def has_object(self, objname):
"""
Checks that a shellspec object was registered.
"""
if objname.lower() in self.__registered_objects:
return True
else:
return False
def keys(self):
"""
Returns names of all registered objects
:return:
"""
return self.__registered_objects
def __getitem__(self, name):
"""
Returns an object.
"""
return self.__objects[name]
def __str__(self):
"""
Returns string representation of the class.
:return:
"""
string = ''
for objname in list(self.keys()):
string += str(self[objname])
return string