1 | |
---|
2 | |
---|
3 | import copy |
---|
4 | |
---|
5 | class PageState(object): |
---|
6 | """ |
---|
7 | Contains info to reconstruct a page |
---|
8 | |
---|
9 | """ |
---|
10 | def __init__(self, parent,model=None, data=None): |
---|
11 | |
---|
12 | """ |
---|
13 | Initialization of the Panel |
---|
14 | |
---|
15 | """ |
---|
16 | #TODO: remove this once the inheritence is cleaned up |
---|
17 | ## Data member to store the dispersion object created |
---|
18 | self._disp_obj_dict = {} |
---|
19 | ## reset True change the state of exsiting button |
---|
20 | self.reset = False |
---|
21 | #Data used for fitting |
---|
22 | self.data = data |
---|
23 | #engine type |
---|
24 | self.engine_type = None |
---|
25 | # flag to allow data2D plot |
---|
26 | self.enable2D = False |
---|
27 | # model on which the fit would be performed |
---|
28 | self.model = model |
---|
29 | #if not hasattr(self.model, "_persistency_dict"): |
---|
30 | # self.model._persistency_dict = {} |
---|
31 | #self.model._persistency_dict = copy.deepcopy(model._persistency_dict) |
---|
32 | #fit page manager |
---|
33 | self.manager = None |
---|
34 | #Store the parent of this panel parent |
---|
35 | # For this application fitpanel is the parent |
---|
36 | self.parent = parent |
---|
37 | # Event_owner is the owner of model event |
---|
38 | self.event_owner = None |
---|
39 | ##page name |
---|
40 | self.page_name = "" |
---|
41 | # Contains link between model ,all its parameters, and panel organization |
---|
42 | self.parameters =[] |
---|
43 | # Contains list of parameters that cannot be fitted and reference to |
---|
44 | #panel objects |
---|
45 | self.fixed_param =[] |
---|
46 | # Contains list of parameters with dispersity and reference to |
---|
47 | #panel objects |
---|
48 | self.fittable_param =[] |
---|
49 | ## orientation parameters |
---|
50 | self.orientation_params=[] |
---|
51 | ## orientation parmaters for gaussian dispersity |
---|
52 | self.orientation_params_disp=[] |
---|
53 | ## smearer info |
---|
54 | self.smearer=None |
---|
55 | #list of dispersion paramaters |
---|
56 | self.disp_list =[] |
---|
57 | if self.model !=None: |
---|
58 | self.disp_list = self.model.getDispParamList() |
---|
59 | self._disp_obj_dict={} |
---|
60 | self.disp_cb_dict={} |
---|
61 | self.values=[] |
---|
62 | self.weights=[] |
---|
63 | |
---|
64 | #contains link between a model and selected parameters to fit |
---|
65 | self.param_toFit =[] |
---|
66 | ##dictionary of model type and model class |
---|
67 | self.model_list_box = None |
---|
68 | ## save the state of the context menu |
---|
69 | self.saved_states={} |
---|
70 | ## save selection of combobox |
---|
71 | self.formfactorcombobox = None |
---|
72 | self.structurecombobox = None |
---|
73 | ## radio box to select type of model |
---|
74 | self.shape_rbutton = False |
---|
75 | self.shape_indep_rbutton = False |
---|
76 | self.struct_rbutton = False |
---|
77 | self.plugin_rbutton = False |
---|
78 | ## the indice of the current selection |
---|
79 | self.disp_box = 0 |
---|
80 | ## Qrange |
---|
81 | ## Q range |
---|
82 | self.qmin= 0.001 |
---|
83 | self.qmax= 0.1 |
---|
84 | self.npts = None |
---|
85 | self.name="" |
---|
86 | self.multi_factor = None |
---|
87 | ## enable smearering state |
---|
88 | self.enable_smearer = False |
---|
89 | self.disable_smearer = True |
---|
90 | ## disperity selection |
---|
91 | self.enable_disp= False |
---|
92 | self.disable_disp= True |
---|
93 | ## plot 2D data |
---|
94 | self.enable2D= False |
---|
95 | ## state of selected all check button |
---|
96 | self.cb1 = False |
---|
97 | ## store value of chisqr |
---|
98 | self.tcChi= None |
---|
99 | |
---|
100 | def clone(self): |
---|
101 | """ |
---|
102 | """ |
---|
103 | model=None |
---|
104 | if self.model !=None: |
---|
105 | model = self.model.clone() |
---|
106 | |
---|
107 | obj = PageState( self.parent,model= model ) |
---|
108 | obj.data = copy.deepcopy(self.data) |
---|
109 | obj.model_list_box = copy.deepcopy(self.model_list_box) |
---|
110 | obj.engine_type = copy.deepcopy(self.engine_type) |
---|
111 | |
---|
112 | obj.formfactorcombobox= self.formfactorcombobox |
---|
113 | obj.structurecombobox =self.structurecombobox |
---|
114 | |
---|
115 | obj.shape_rbutton = self.shape_rbutton |
---|
116 | obj.shape_indep_rbutton = self.shape_indep_rbutton |
---|
117 | obj.struct_rbutton = self.struct_rbutton |
---|
118 | obj.plugin_rbutton = self.plugin_rbutton |
---|
119 | |
---|
120 | obj.manager = self.manager |
---|
121 | obj.event_owner = self.event_owner |
---|
122 | obj.disp_list = copy.deepcopy(self.disp_list) |
---|
123 | |
---|
124 | obj.enable2D = copy.deepcopy(self.enable2D) |
---|
125 | obj.parameters = copy.deepcopy(self.parameters) |
---|
126 | obj.fixed_param = copy.deepcopy(self.fixed_param) |
---|
127 | obj.fittable_param = copy.deepcopy(self.fittable_param) |
---|
128 | obj.orientation_params = copy.deepcopy(self.orientation_params) |
---|
129 | obj.orientation_params_disp = copy.deepcopy(self.orientation_params_disp) |
---|
130 | obj.enable_disp = copy.deepcopy(self.enable_disp) |
---|
131 | obj.disable_disp = copy.deepcopy(self.disable_disp) |
---|
132 | obj.tcChi = self.tcChi |
---|
133 | |
---|
134 | if len(self._disp_obj_dict)>0: |
---|
135 | for k , v in self._disp_obj_dict.iteritems(): |
---|
136 | obj._disp_obj_dict[k]= v |
---|
137 | if len(self.disp_cb_dict)>0: |
---|
138 | for k , v in self.disp_cb_dict.iteritems(): |
---|
139 | obj.disp_cb_dict[k]= v |
---|
140 | |
---|
141 | obj.values = copy.deepcopy(self.values) |
---|
142 | obj.weights = copy.deepcopy(self.weights) |
---|
143 | obj.enable_smearer = copy.deepcopy(self.enable_smearer) |
---|
144 | obj.disable_smearer = copy.deepcopy(self.disable_smearer) |
---|
145 | |
---|
146 | obj.disp_box = copy.deepcopy(self.disp_box) |
---|
147 | obj.qmin = copy.deepcopy(self.qmin) |
---|
148 | obj.qmax = copy.deepcopy(self.qmax) |
---|
149 | obj.multi_factor = copy.deepcopy(self.multi_factor) |
---|
150 | obj.npts = copy.deepcopy(self.npts ) |
---|
151 | obj.cb1 = copy.deepcopy(self.cb1) |
---|
152 | obj.smearer = copy.deepcopy(self.smearer) |
---|
153 | |
---|
154 | for name, state in self.saved_states.iteritems(): |
---|
155 | copy_name = copy.deepcopy(name) |
---|
156 | copy_state = state.clone() |
---|
157 | obj.saved_states[copy_name]= copy_state |
---|
158 | return obj |
---|
159 | |
---|
160 | |
---|
161 | def old__repr__(self): |
---|
162 | """ |
---|
163 | output string for printing |
---|
164 | |
---|
165 | """ |
---|
166 | rep = "\n\nState name: %s\n"%self.name |
---|
167 | rep +="data : %s\n"% str(self.data) |
---|
168 | rep += "Plotting Range: min: %s, max: %s, steps: %s\n"%(str(self.qmin), |
---|
169 | str(self.qmax),str(self.npts)) |
---|
170 | rep +="model : %s\n\n"% str(self.model) |
---|
171 | rep +="number parameters(self.parameters): %s\n"%len(self.parameters) |
---|
172 | for item in self.parameters: |
---|
173 | rep += "parameter name: %s \n"%str(item[1]) |
---|
174 | rep += "value: %s\n"%str(item[2]) |
---|
175 | rep += "selected: %s\n"%str(item[0]) |
---|
176 | rep += "error displayed : %s \n"%str(item[4][0]) |
---|
177 | rep += "error value:%s \n"%str(item[4][1]) |
---|
178 | rep += "minimum displayed : %s \n"%str(item[5][0]) |
---|
179 | rep += "minimum value : %s \n"%str(item[5][1]) |
---|
180 | rep += "maximum displayed : %s \n"%str(item[6][0]) |
---|
181 | rep += "maximum value : %s \n"%str(item[6][1]) |
---|
182 | rep += "parameter unit: %s\n\n"%str(item[7]) |
---|
183 | rep +="number orientation parameters" |
---|
184 | rep +="(self.orientation_params): %s\n"%len(self.orientation_params) |
---|
185 | for item in self.orientation_params: |
---|
186 | rep += "parameter name: %s \n"%str(item[1]) |
---|
187 | rep += "value: %s\n"%str(item[2]) |
---|
188 | rep += "selected: %s\n"%str(item[0]) |
---|
189 | rep += "error displayed : %s \n"%str(item[4][0]) |
---|
190 | rep += "error value:%s \n"%str(item[4][1]) |
---|
191 | rep += "minimum displayed : %s \n"%str(item[5][0]) |
---|
192 | rep += "minimum value : %s \n"%str(item[5][1]) |
---|
193 | rep += "maximum displayed : %s \n"%str(item[6][0]) |
---|
194 | rep += "maximum value : %s \n"%str(item[6][1]) |
---|
195 | rep += "parameter unit: %s\n\n"%str(item[7]) |
---|
196 | rep +="number dispersity parameters" |
---|
197 | rep +="(self.orientation_params_disp): %s\n"%len(self.orientation_params_disp) |
---|
198 | for item in self.orientation_params_disp: |
---|
199 | rep += "parameter name: %s \n"%str(item[1]) |
---|
200 | rep += "value: %s\n"%str(item[2]) |
---|
201 | rep += "selected: %s\n"%str(item[0]) |
---|
202 | rep += "error displayed : %s \n"%str(item[4][0]) |
---|
203 | rep += "error value:%s \n"%str(item[4][1]) |
---|
204 | rep += "minimum displayed : %s \n"%str(item[5][0]) |
---|
205 | rep += "minimum value : %s \n"%str(item[5][1]) |
---|
206 | rep += "maximum displayed : %s \n"%str(item[6][0]) |
---|
207 | rep += "maximum value : %s \n"%str(item[6][1]) |
---|
208 | rep += "parameter unit: %s\n\n"%str(item[7]) |
---|
209 | return rep |
---|
210 | |
---|