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