[3feed3e] | 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 | """ |
---|
[c70eb7c] | 12 | import copy |
---|
| 13 | |
---|
[3feed3e] | 14 | |
---|
| 15 | class DataState(object): |
---|
| 16 | """ |
---|
| 17 | Store information about data |
---|
| 18 | """ |
---|
| 19 | def __init__(self, data, parent=None): |
---|
| 20 | """ |
---|
| 21 | |
---|
| 22 | """ |
---|
| 23 | self.parent = parent |
---|
[584c4c4] | 24 | self.data = data |
---|
| 25 | self.name = "" |
---|
| 26 | self.path = None |
---|
[5c4b674] | 27 | self.theory_list = {} |
---|
[584c4c4] | 28 | self.message = "" |
---|
[c70eb7c] | 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 | else: |
---|
| 38 | _str += "Data: %s \n" % str(self.data) |
---|
| 39 | |
---|
| 40 | if self.theory_list: |
---|
| 41 | _str += "Theories available: \n" |
---|
| 42 | for id, item in self.theory_list.iteritems(): |
---|
| 43 | theory_data, theory_state = item |
---|
| 44 | _str += "Theory name : %s \n" % str(theory_data.name) |
---|
| 45 | _str += "Theory ID : %s \n" % str(id) |
---|
| 46 | else: |
---|
| 47 | for key , value in self.theory_list.iteritems(): |
---|
| 48 | theory_data, theory_state = value |
---|
| 49 | _str += "Theory with ID : %s \n" % str(key) |
---|
| 50 | _str += str(theory_data) |
---|
| 51 | _str += str(theory_state) |
---|
| 52 | return _str |
---|
| 53 | |
---|
| 54 | def clone(self): |
---|
| 55 | obj = DataState(copy.deepcopy(self.data)) |
---|
| 56 | obj.parent = self.parent |
---|
| 57 | obj.name = self.name |
---|
| 58 | obj.path = self.path |
---|
| 59 | obj.message = self.message |
---|
| 60 | obj.id = self.id |
---|
| 61 | for id, item in self.theory_list.iteritems(): |
---|
| 62 | theory_data, theory_state = item |
---|
| 63 | state = None |
---|
| 64 | if theory_state is not None: |
---|
| 65 | state = theory_state.clone() |
---|
| 66 | obj.theory_list[id] = [copy.deepcopy(theory_data), |
---|
| 67 | state] |
---|
| 68 | return obj |
---|
[3feed3e] | 69 | |
---|
| 70 | def set_name(self, name): |
---|
[584c4c4] | 71 | self.name = name |
---|
[c70eb7c] | 72 | |
---|
[3feed3e] | 73 | def get_name(self): |
---|
[584c4c4] | 74 | return self.name |
---|
[c70eb7c] | 75 | |
---|
[3feed3e] | 76 | def set_data(self, data): |
---|
[584c4c4] | 77 | self.data = data |
---|
[3feed3e] | 78 | |
---|
| 79 | def get_data(self): |
---|
[584c4c4] | 80 | return self.data |
---|
[3feed3e] | 81 | |
---|
| 82 | def set_path(self, path): |
---|
| 83 | """ |
---|
| 84 | Set the path of the loaded data |
---|
| 85 | """ |
---|
[584c4c4] | 86 | self.path = path |
---|
[3feed3e] | 87 | |
---|
| 88 | def get_path(self): |
---|
| 89 | """ |
---|
| 90 | return the path of the loaded data |
---|
| 91 | """ |
---|
[584c4c4] | 92 | return self.path |
---|
[3feed3e] | 93 | |
---|
[c70eb7c] | 94 | def set_theory(self, theory_data, theory_state=None): |
---|
[3feed3e] | 95 | """ |
---|
| 96 | """ |
---|
[c70eb7c] | 97 | self.theory_list[theory_data.id] = [theory_data, theory_state] |
---|
[3feed3e] | 98 | |
---|
| 99 | def get_theory(self): |
---|
[584c4c4] | 100 | return self.theory_list |
---|
[3feed3e] | 101 | |
---|
| 102 | def get_message(self): |
---|
| 103 | """ |
---|
| 104 | return message |
---|
| 105 | """ |
---|
[584c4c4] | 106 | return self.message |
---|
[3feed3e] | 107 | |
---|
| 108 | |
---|