[959eb01] | 1 | ################################################################################ |
---|
| 2 | #This software was developed by the University of Tennessee as part of the |
---|
| 3 | #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
| 4 | #project funded by the US National Science Foundation. |
---|
| 5 | # |
---|
| 6 | #See the license text in license.txt |
---|
| 7 | # |
---|
| 8 | #copyright 2010, University of Tennessee |
---|
| 9 | ################################################################################ |
---|
| 10 | """ |
---|
| 11 | """ |
---|
| 12 | import copy |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | class DataState(object): |
---|
| 16 | """ |
---|
| 17 | Store information about data |
---|
| 18 | """ |
---|
| 19 | def __init__(self, data=None, parent=None): |
---|
| 20 | """ |
---|
| 21 | |
---|
| 22 | """ |
---|
| 23 | self.parent = parent |
---|
| 24 | self.data = data |
---|
| 25 | self.name = "" |
---|
| 26 | self.path = None |
---|
| 27 | self.theory_list = {} |
---|
| 28 | self.message = "" |
---|
| 29 | self.id = None |
---|
| 30 | |
---|
| 31 | def __str__(self): |
---|
| 32 | _str = "" |
---|
| 33 | _str += "State with ID : %s \n" % str(self.id) |
---|
| 34 | if self.data is not None: |
---|
| 35 | _str += "Data name : %s \n" % str(self.data.name) |
---|
| 36 | _str += "Data ID : %s \n" % str(self.data.id) |
---|
| 37 | _str += "Theories available: %s \n" % len(self.theory_list) |
---|
| 38 | if self.theory_list: |
---|
[5251ec6] | 39 | for id, item in self.theory_list.items(): |
---|
[959eb01] | 40 | theory_data, theory_state = item |
---|
| 41 | _str += "Theory name : %s \n" % str(theory_data.name) |
---|
| 42 | _str += "Theory ID : %s \n" % str(id) |
---|
| 43 | _str += "Theory info: \n" |
---|
| 44 | _str += str(theory_data) |
---|
| 45 | |
---|
| 46 | return _str |
---|
| 47 | |
---|
| 48 | def clone(self): |
---|
| 49 | obj = DataState(copy.deepcopy(self.data)) |
---|
| 50 | obj.parent = self.parent |
---|
| 51 | obj.name = self.name |
---|
| 52 | obj.path = self.path |
---|
| 53 | obj.message = self.message |
---|
| 54 | obj.id = self.id |
---|
[5251ec6] | 55 | for id, item in self.theory_list.items(): |
---|
[959eb01] | 56 | theory_data, theory_state = item |
---|
| 57 | state = None |
---|
| 58 | if theory_state is not None: |
---|
| 59 | state = theory_state.clone() |
---|
| 60 | obj.theory_list[id] = [copy.deepcopy(theory_data), |
---|
| 61 | state] |
---|
| 62 | return obj |
---|
| 63 | |
---|
| 64 | def set_name(self, name): |
---|
| 65 | self.name = name |
---|
| 66 | |
---|
| 67 | def get_name(self): |
---|
| 68 | return self.name |
---|
| 69 | |
---|
| 70 | def set_data(self, data): |
---|
| 71 | """ |
---|
| 72 | """ |
---|
| 73 | self.data = data |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | def get_data(self): |
---|
| 77 | """ |
---|
| 78 | """ |
---|
| 79 | return self.data |
---|
| 80 | |
---|
| 81 | def set_path(self, path): |
---|
| 82 | """ |
---|
| 83 | Set the path of the loaded data |
---|
| 84 | """ |
---|
| 85 | self.path = path |
---|
| 86 | |
---|
| 87 | def get_path(self): |
---|
| 88 | """ |
---|
| 89 | return the path of the loaded data |
---|
| 90 | """ |
---|
| 91 | return self.path |
---|
| 92 | |
---|
| 93 | def set_theory(self, theory_data, theory_state=None): |
---|
| 94 | """ |
---|
| 95 | """ |
---|
| 96 | self.theory_list[theory_data.id] = [theory_data, theory_state] |
---|
[5251ec6] | 97 | data, state = list(self.theory_list.values())[0] |
---|
[959eb01] | 98 | |
---|
| 99 | def get_theory(self): |
---|
| 100 | return self.theory_list |
---|
| 101 | |
---|
| 102 | def get_message(self): |
---|
| 103 | """ |
---|
| 104 | return message |
---|
| 105 | """ |
---|
| 106 | return self.message |
---|
| 107 | |
---|