[3c44c66] | 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 | This module manages all data loaded into the application. Data_manager makes |
---|
| 12 | available all data loaded for the current perspective. |
---|
| 13 | |
---|
[f444b20] | 14 | All modules "creating Data" posts their data to data_manager . |
---|
| 15 | Data_manager make these new data available for all other perspectives. |
---|
[3c44c66] | 16 | """ |
---|
[f444b20] | 17 | import logging |
---|
[c5e84fb] | 18 | from sans.guiframe.data_state import DataState |
---|
[f444b20] | 19 | |
---|
[3c44c66] | 20 | class DataManager(object): |
---|
| 21 | """ |
---|
[f444b20] | 22 | Manage a list of data |
---|
[3c44c66] | 23 | """ |
---|
[f444b20] | 24 | def __init__(self): |
---|
[3c44c66] | 25 | """ |
---|
[aebc4cc] | 26 | Store opened path and data object created at the loading time |
---|
[f444b20] | 27 | :param auto_plot: if True the datamanager sends data to plotting |
---|
| 28 | plugin. |
---|
| 29 | :param auto_set_data: if True the datamanager sends to the current |
---|
| 30 | perspective |
---|
[4e9583c] | 31 | """ |
---|
[c5e84fb] | 32 | self._selected_data = {} |
---|
[f444b20] | 33 | self.stored_data = {} |
---|
[aebc4cc] | 34 | self.message = "" |
---|
[f444b20] | 35 | |
---|
| 36 | def add_data(self, data_list): |
---|
| 37 | """ |
---|
| 38 | receive a list of |
---|
| 39 | """ |
---|
[584c4c4] | 40 | self._selected_data = {} |
---|
[f444b20] | 41 | for data in data_list: |
---|
| 42 | if data.id in self.stored_data: |
---|
| 43 | msg = "Data manager already stores %s" % str(data.name) |
---|
| 44 | msg += "" |
---|
| 45 | logging.info(msg) |
---|
[c5e84fb] | 46 | data_state = DataState(data) |
---|
[584c4c4] | 47 | self._selected_data[data.id] = data_state |
---|
| 48 | self.stored_data[data.id] = data_state |
---|
[213892bc] | 49 | |
---|
[f444b20] | 50 | def set_auto_plot(self, flag=False): |
---|
| 51 | """ |
---|
| 52 | When flag is true the data is plotted automatically |
---|
| 53 | """ |
---|
| 54 | self._auto_set_data = flag |
---|
| 55 | |
---|
| 56 | def set_auto_set_data(self, flag=False): |
---|
| 57 | """ |
---|
| 58 | When flag is true the data is send to the current perspective |
---|
| 59 | automatically |
---|
| 60 | """ |
---|
| 61 | self._auto_set_data = flag |
---|
[3c44c66] | 62 | |
---|
[aebc4cc] | 63 | def get_message(self): |
---|
[3c44c66] | 64 | """ |
---|
[aebc4cc] | 65 | return message |
---|
[3c44c66] | 66 | """ |
---|
[aebc4cc] | 67 | return self.message |
---|
[3c44c66] | 68 | |
---|
[f444b20] | 69 | def get_by_id(self, id_list=None): |
---|
| 70 | """ |
---|
| 71 | get a list of data given a list of id |
---|
| 72 | """ |
---|
[584c4c4] | 73 | self._selected_data = {} |
---|
[f444b20] | 74 | for id in id_list: |
---|
| 75 | if id in self.stored_data: |
---|
[584c4c4] | 76 | self._selected_data[id] = self.stored_data[id] |
---|
[f444b20] | 77 | return self._selected_data |
---|
| 78 | |
---|
[213892bc] | 79 | def append_theory(self, data_id, theory): |
---|
| 80 | """ |
---|
| 81 | """ |
---|
| 82 | print "append theory", self.stored_data, data_id |
---|
| 83 | if data_id in self.stored_data: |
---|
| 84 | data_state = self.stored_data[data_id] |
---|
| 85 | data_state.set_theory(theory) |
---|
| 86 | |
---|
| 87 | def delete_data(self, data_id, theory_id, delete_all): |
---|
| 88 | """ |
---|
| 89 | """ |
---|
[6db811e] | 90 | if data_id in self.stored_data: |
---|
| 91 | del self.stored_data[data_id] |
---|
| 92 | if data_id in self._selected_data: |
---|
| 93 | del self._selected_data |
---|
| 94 | |
---|
[f444b20] | 95 | def delete_by_id(self, id_list=None): |
---|
[3c44c66] | 96 | """ |
---|
[aebc4cc] | 97 | save data and path |
---|
[3c44c66] | 98 | """ |
---|
[f444b20] | 99 | for id in id_list: |
---|
| 100 | if id in self.stored_data: |
---|
| 101 | del self.stored_data[id] |
---|
[584c4c4] | 102 | if id in self._selected_data: |
---|
| 103 | del self._selected_data[id] |
---|
[aebc4cc] | 104 | |
---|
[f444b20] | 105 | def get_by_name(self, name_list=None): |
---|
[3c44c66] | 106 | """ |
---|
[f444b20] | 107 | return a list of data given a list of data names |
---|
[3c44c66] | 108 | """ |
---|
[584c4c4] | 109 | self._selected_data = {} |
---|
[f444b20] | 110 | for selected_name in name_list: |
---|
[584c4c4] | 111 | for id, data_state in self.stored_data.iteritems(): |
---|
| 112 | if data_state.data.name == selected_name: |
---|
| 113 | self._selected_data[id] = data_state |
---|
[f444b20] | 114 | return self._selected_data |
---|
| 115 | |
---|
| 116 | def delete_by_name(self, name_list=None): |
---|
| 117 | """ |
---|
| 118 | save data and path |
---|
| 119 | """ |
---|
| 120 | for selected_name in name_list: |
---|
[584c4c4] | 121 | for id, data_state in self.stored_data.iteritems(): |
---|
| 122 | if data_state.data.name == selected_name: |
---|
| 123 | del self._selected_data[id] |
---|
| 124 | del self.stored_data[data.id] |
---|
[f444b20] | 125 | |
---|
| 126 | def get_selected_data(self): |
---|
| 127 | """ |
---|
| 128 | Send list of selected data |
---|
| 129 | """ |
---|
| 130 | return self._selected_data |
---|
| 131 | |
---|
| 132 | def get_all_data(self): |
---|
| 133 | """ |
---|
| 134 | return list of all available data |
---|
| 135 | """ |
---|
[584c4c4] | 136 | return self.stored_data |
---|
[f444b20] | 137 | |
---|
| 138 | |
---|
[3c44c66] | 139 | |
---|