1 | import sys |
---|
2 | import wx |
---|
3 | import wx.lib.newevent |
---|
4 | import numpy |
---|
5 | import copy |
---|
6 | import math |
---|
7 | from sans.models.dispersion_models import ArrayDispersion, GaussianDispersion |
---|
8 | |
---|
9 | from sans.guicomm.events import StatusEvent |
---|
10 | from sans.guiframe.utils import format_number |
---|
11 | (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() |
---|
12 | _BOX_WIDTH = 80 |
---|
13 | |
---|
14 | |
---|
15 | |
---|
16 | |
---|
17 | class ModelPage(wx.ScrolledWindow): |
---|
18 | """ |
---|
19 | FitPanel class contains fields allowing to display results when |
---|
20 | fitting a model and one data |
---|
21 | @note: For Fit to be performed the user should check at least one parameter |
---|
22 | on fit Panel window. |
---|
23 | |
---|
24 | """ |
---|
25 | ## Internal name for the AUI manager |
---|
26 | window_name = "Fit page" |
---|
27 | ## Title to appear on top of the window |
---|
28 | window_caption = "Fit Page" |
---|
29 | name="" |
---|
30 | def __init__(self, parent,model,name, *args, **kwargs): |
---|
31 | wx.ScrolledWindow.__init__(self, parent, *args, **kwargs) |
---|
32 | """ |
---|
33 | Initialization of the Panel |
---|
34 | """ |
---|
35 | # model on which the fit would be performed |
---|
36 | self.model=model |
---|
37 | # Data member to store the dispersion object created |
---|
38 | self._disp_obj_dict = {} |
---|
39 | self.back_up_model= model.clone() |
---|
40 | #list of dispersion paramaters |
---|
41 | self.disp_list=[] |
---|
42 | try: |
---|
43 | self.disp_list=self.model.getDispParamList() |
---|
44 | except: |
---|
45 | pass |
---|
46 | self.manager = None |
---|
47 | self.parent = parent |
---|
48 | self.event_owner = None |
---|
49 | # this panel does contain data .existing data allow a different drawing |
---|
50 | #on set_model parameters |
---|
51 | self.data=None |
---|
52 | #panel interface |
---|
53 | self.vbox = wx.BoxSizer(wx.VERTICAL) |
---|
54 | self.sizer11 = wx.BoxSizer(wx.HORIZONTAL) |
---|
55 | #self.sizer10 = wx.GridBagSizer(5,5) |
---|
56 | self.sizer9 = wx.GridBagSizer(5,5) |
---|
57 | self.sizer8 = wx.GridBagSizer(5,5) |
---|
58 | self.sizer7 = wx.GridBagSizer(5,5) |
---|
59 | self.sizer6 = wx.GridBagSizer(5,5) |
---|
60 | self.sizer5 = wx.GridBagSizer(5,5) |
---|
61 | self.sizer4 = wx.GridBagSizer(5,5) |
---|
62 | |
---|
63 | #model selection |
---|
64 | self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) |
---|
65 | self.vbox.Add(self.sizer4) |
---|
66 | #model description |
---|
67 | self.vbox.Add(self.sizer11) |
---|
68 | #model paramaters layer |
---|
69 | self.vbox.Add(self.sizer5) |
---|
70 | #polydispersion selected |
---|
71 | self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) |
---|
72 | self.vbox.Add(self.sizer6) |
---|
73 | #combox box for type of dispersion |
---|
74 | self.vbox.Add(self.sizer7) |
---|
75 | #dispersion parameters layer |
---|
76 | self.vbox.Add(self.sizer8) |
---|
77 | # plotting range |
---|
78 | self.vbox.Add(self.sizer9) |
---|
79 | #close layer |
---|
80 | #self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) |
---|
81 | #self.vbox.Add(self.sizer10) |
---|
82 | |
---|
83 | |
---|
84 | #------------------ sizer 4 draw------------------------ |
---|
85 | |
---|
86 | ## structure combox box |
---|
87 | self.structbox = wx.ComboBox(self, -1) |
---|
88 | # define combox box |
---|
89 | self.modelbox = wx.ComboBox(self, -1) |
---|
90 | |
---|
91 | #enable model 2D draw |
---|
92 | self.enable2D= False |
---|
93 | self.fitrange= True |
---|
94 | #filling sizer2 |
---|
95 | ix = 0 |
---|
96 | iy = 1 |
---|
97 | self.sizer4.Add(wx.StaticText(self,-1,'Model'),(iy,ix),(1,1)\ |
---|
98 | , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
99 | ix += 1 |
---|
100 | self.sizer4.Add(self.modelbox,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
101 | ix +=1 |
---|
102 | self.text_mult= wx.StaticText(self,-1,' x ') |
---|
103 | self.sizer4.Add(self.text_mult,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
104 | ix += 1 |
---|
105 | self.sizer4.Add(self.structbox,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
106 | |
---|
107 | if hasattr(model ,"model2"): |
---|
108 | name= model.model2.name |
---|
109 | |
---|
110 | self.structbox.SetValue(name) |
---|
111 | if hasattr(model ,"model1"): |
---|
112 | name= model.model1.name |
---|
113 | items = self.modelbox.GetItems() |
---|
114 | self.modelbox.SetValue(name) |
---|
115 | else: |
---|
116 | #print "model view prev_model",name |
---|
117 | self.modelbox.SetValue( name ) |
---|
118 | ix += 1 |
---|
119 | id = wx.NewId() |
---|
120 | self.model_view =wx.Button(self,id,'View 2D') |
---|
121 | self.model_view.Bind(wx.EVT_BUTTON, self.onModel2D,id=id) |
---|
122 | self.model_view.SetToolTipString("View model in 2D") |
---|
123 | |
---|
124 | self.sizer4.Add(self.model_view,(iy,ix),(1,1),\ |
---|
125 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
126 | |
---|
127 | self.model_view.Enable() |
---|
128 | self.model_view.SetFocus() |
---|
129 | |
---|
130 | ix = 0 |
---|
131 | iy += 1 |
---|
132 | self.sizer4.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
133 | |
---|
134 | #----------sizer6------------------------------------------------- |
---|
135 | self.disable_disp = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP) |
---|
136 | self.enable_disp = wx.RadioButton(self, -1, 'Yes', (10, 30)) |
---|
137 | self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.disable_disp.GetId()) |
---|
138 | self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.enable_disp.GetId()) |
---|
139 | ix= 0 |
---|
140 | iy=1 |
---|
141 | self.sizer6.Add(wx.StaticText(self,-1,'Polydispersity: '),(iy,ix),(1,1)\ |
---|
142 | , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
143 | ix += 1 |
---|
144 | self.sizer6.Add(self.enable_disp ,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
145 | ix += 1 |
---|
146 | self.sizer6.Add(self.disable_disp ,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
147 | ix =0 |
---|
148 | iy+=1 |
---|
149 | self.sizer6.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
150 | |
---|
151 | |
---|
152 | #---------sizer 9 draw---------------------------------------- |
---|
153 | |
---|
154 | ## Q range |
---|
155 | self.qmin_x= 0.001 |
---|
156 | self.qmax_x= 0.1 |
---|
157 | self.num_points= 100 |
---|
158 | |
---|
159 | |
---|
160 | self.qmin = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) |
---|
161 | self.qmin.SetValue(format_number(self.qmin_x)) |
---|
162 | self.qmin.SetToolTipString("Minimun value of Q in linear scale.") |
---|
163 | self.qmin.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
164 | self.qmin.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) |
---|
165 | |
---|
166 | self.qmax = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) |
---|
167 | self.qmax.SetValue(format_number(self.qmax_x)) |
---|
168 | self.qmax.SetToolTipString("Maximum value of Q in linear scale.") |
---|
169 | self.qmax.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
170 | self.qmax.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) |
---|
171 | |
---|
172 | |
---|
173 | self.npts = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) |
---|
174 | self.npts.SetValue(format_number(self.num_points)) |
---|
175 | self.npts.SetToolTipString("Number of point to plot.") |
---|
176 | self.npts.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
177 | self.npts.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) |
---|
178 | |
---|
179 | ix = 0 |
---|
180 | iy = 1 |
---|
181 | self.sizer9.Add(wx.StaticText(self, -1, 'Plotting Range'),(iy, ix),(1,1),\ |
---|
182 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
183 | ix += 1 |
---|
184 | self.sizer9.Add(wx.StaticText(self, -1, 'Min'),(iy, ix),(1,1),\ |
---|
185 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
186 | ix += 1 |
---|
187 | self.sizer9.Add(wx.StaticText(self, -1, 'Max'),(iy, ix),(1,1),\ |
---|
188 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
189 | ix += 1 |
---|
190 | self.sizer9.Add(wx.StaticText(self, -1, 'Npts'),(iy, ix),(1,1),\ |
---|
191 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
192 | ix = 0 |
---|
193 | iy += 1 |
---|
194 | self.sizer9.Add(wx.StaticText(self, -1, 'Q range'),(iy, ix),(1,1),\ |
---|
195 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
196 | ix += 1 |
---|
197 | self.sizer9.Add(self.qmin,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
198 | ix += 1 |
---|
199 | self.sizer9.Add(self.qmax,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
200 | ix += 1 |
---|
201 | self.sizer9.Add(self.npts,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
202 | |
---|
203 | ix =0 |
---|
204 | iy+=1 |
---|
205 | self.sizer9.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
206 | |
---|
207 | # contains link between model ,all its parameters, and panel organization |
---|
208 | self.parameters=[] |
---|
209 | self.fixed_param=[] |
---|
210 | self.fittable_param=[] |
---|
211 | self.polydisp= {} |
---|
212 | #contains link between a model and selected parameters to fit |
---|
213 | self.param_toFit=[] |
---|
214 | |
---|
215 | #dictionary of model name and model class |
---|
216 | self.model_list_box={} |
---|
217 | #Draw initial panel |
---|
218 | #-----sizer 11--------------------model description------ |
---|
219 | if self.model!=None: |
---|
220 | self.set_panel(self.model) |
---|
221 | self.theta_cb=None |
---|
222 | |
---|
223 | |
---|
224 | self.vbox.Layout() |
---|
225 | self.vbox.Fit(self) |
---|
226 | self.SetSizer(self.vbox) |
---|
227 | self.SetScrollbars(20,20,55,40) |
---|
228 | |
---|
229 | self.Centre() |
---|
230 | self.Layout() |
---|
231 | self.parent.GetSizer().Layout() |
---|
232 | def set_model_description(self, model=None): |
---|
233 | |
---|
234 | if model !=None: |
---|
235 | description="description" |
---|
236 | else: |
---|
237 | description="" |
---|
238 | if hasattr(model,description.lower())and self.data==None: |
---|
239 | self.sizer11.Clear(True) |
---|
240 | self.box_description= wx.StaticBox(self, -1, 'Model Description') |
---|
241 | boxsizer1 = wx.StaticBoxSizer(self.box_description, wx.VERTICAL) |
---|
242 | boxsizer1.SetMinSize((320,20)) |
---|
243 | self.description = wx.StaticText(self,-1,str(model.description)) |
---|
244 | boxsizer1.Add(self.description, 0, wx.EXPAND) |
---|
245 | self.sizer11.Add(boxsizer1,1, wx.EXPAND | wx.ALL, 2) |
---|
246 | |
---|
247 | |
---|
248 | def set_owner(self,owner): |
---|
249 | """ |
---|
250 | set owner of fitpage |
---|
251 | @param owner: the class responsible of plotting |
---|
252 | """ |
---|
253 | self.event_owner=owner |
---|
254 | |
---|
255 | |
---|
256 | def set_manager(self, manager): |
---|
257 | """ |
---|
258 | set panel manager |
---|
259 | @param manager: instance of plugin fitting |
---|
260 | """ |
---|
261 | self.manager = manager |
---|
262 | |
---|
263 | def populate_box(self, dict): |
---|
264 | """ |
---|
265 | Populate each combox box of each page |
---|
266 | @param page: the page to populate |
---|
267 | """ |
---|
268 | |
---|
269 | self.model_list_box = dict.get_list() |
---|
270 | |
---|
271 | for item , mylist in self.model_list_box.iteritems(): |
---|
272 | separator= "---%s---"%item |
---|
273 | self.modelbox.Append(separator,"separator") |
---|
274 | |
---|
275 | for models in mylist: |
---|
276 | model= models() |
---|
277 | name = model.__class__.__name__ |
---|
278 | if hasattr(model, "name"): |
---|
279 | name = model.name |
---|
280 | self.modelbox.Append(name,models) |
---|
281 | wx.EVT_COMBOBOX(self.modelbox,-1, self._on_select_model) |
---|
282 | if item == "Structure Factors" : |
---|
283 | for structs in mylist: |
---|
284 | struct= structs() |
---|
285 | name = struct.__class__.__name__ |
---|
286 | if hasattr(struct, "name"): |
---|
287 | name = struct.name |
---|
288 | self.structbox.Append(name,structs) |
---|
289 | wx.EVT_COMBOBOX(self.structbox,-1, self._on_select_model) |
---|
290 | |
---|
291 | return 0 |
---|
292 | |
---|
293 | |
---|
294 | def Set_DipersParam(self, event): |
---|
295 | if self.model ==None: |
---|
296 | msg= " Select non - model value:%s !"%self.model |
---|
297 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg)) |
---|
298 | return |
---|
299 | if self.enable_disp.GetValue(): |
---|
300 | if len(self.disp_list)==0: |
---|
301 | ix=0 |
---|
302 | iy=1 |
---|
303 | self.fittable_param=[] |
---|
304 | self.fixed_param=[] |
---|
305 | self.sizer8.Clear(True) |
---|
306 | model_disp = wx.StaticText(self, -1, 'No PolyDispersity for this model') |
---|
307 | self.sizer7.Add(model_disp,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
308 | self.vbox.Layout() |
---|
309 | self.SetScrollbars(20,20,55,40) |
---|
310 | self.Layout() |
---|
311 | self.parent.GetSizer().Layout() |
---|
312 | return |
---|
313 | else: |
---|
314 | if self.data !=None and self.model !=None: # allow to recognize data panel from model panel |
---|
315 | |
---|
316 | |
---|
317 | self.cb1.SetValue(False) |
---|
318 | self.select_all_param_helper() |
---|
319 | |
---|
320 | self.populate_disp_box() |
---|
321 | self.set_panel_dispers(self.disp_list) |
---|
322 | |
---|
323 | else: |
---|
324 | if self.data !=None and self.model!=None: |
---|
325 | if self.cb1.GetValue(): |
---|
326 | self.select_all_param_helper() |
---|
327 | |
---|
328 | if self.back_up_model!=None: |
---|
329 | keys = self.back_up_model.getDispParamList() |
---|
330 | keys.sort() |
---|
331 | #disperse param into the initial state |
---|
332 | for item in keys: |
---|
333 | value= self.back_up_model.getParam(item) |
---|
334 | self.model.setParam(item, value) |
---|
335 | self._draw_model() |
---|
336 | |
---|
337 | |
---|
338 | self.fittable_param=[] |
---|
339 | self.fixed_param=[] |
---|
340 | self.sizer7.Clear(True) |
---|
341 | self.sizer8.Clear(True) |
---|
342 | self.vbox.Layout() |
---|
343 | self.SetScrollbars(20,20,55,40) |
---|
344 | self.Layout() |
---|
345 | self.parent.GetSizer().Layout() |
---|
346 | |
---|
347 | def populate_disp_box(self): |
---|
348 | self.sizer7.Clear(True) |
---|
349 | if len(self.disp_list)>0: |
---|
350 | ix=0 |
---|
351 | iy=1 |
---|
352 | model_disp = wx.StaticText(self, -1, 'Model Disp') |
---|
353 | self.sizer7.Add(model_disp,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
354 | ix += 1 |
---|
355 | # set up the combox box |
---|
356 | id = 0 |
---|
357 | import sans.models.dispersion_models |
---|
358 | self.polydisp= sans.models.dispersion_models.models |
---|
359 | self.disp_box = wx.ComboBox(self, -1) |
---|
360 | self.disp_box.SetValue("GaussianModel") |
---|
361 | for k,v in self.polydisp.iteritems(): |
---|
362 | if str(v)=="MyModel": |
---|
363 | # Remove the option until the rest of the code is ready for it |
---|
364 | #self.disp_box.Insert("Select customized Model",id) |
---|
365 | pass |
---|
366 | else: |
---|
367 | self.disp_box.Insert(str(v),id) |
---|
368 | id+=1 |
---|
369 | |
---|
370 | wx.EVT_COMBOBOX(self.disp_box,-1, self._on_select_Disp) |
---|
371 | self.sizer7.Add(self.disp_box,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
372 | self.vbox.Layout() |
---|
373 | self.SetScrollbars(20,20,55,40) |
---|
374 | self.Layout() |
---|
375 | self.parent.GetSizer().Layout() |
---|
376 | |
---|
377 | |
---|
378 | def set_range(self, qmin_x, qmax_x, npts): |
---|
379 | """ |
---|
380 | Set the range for the plotted models |
---|
381 | @param qmin: minimum Q |
---|
382 | @param qmax: maximum Q |
---|
383 | @param npts: number of Q bins |
---|
384 | """ |
---|
385 | # Set the data members |
---|
386 | self.qmin_x = qmin_x |
---|
387 | self.qmax_x = qmax_x |
---|
388 | self.num_points = npts |
---|
389 | |
---|
390 | # Set the controls |
---|
391 | self.qmin.SetValue(format_number(self.qmin_x)) |
---|
392 | self.qmax.SetValue(format_number(self.qmax_x)) |
---|
393 | self.npts.SetValue(format_number(self.num_points)) |
---|
394 | def checkFitRange(self): |
---|
395 | """ |
---|
396 | Check the validity of fitting range |
---|
397 | @note: qmin should always be less than qmax or else each control box |
---|
398 | background is colored in pink. |
---|
399 | """ |
---|
400 | |
---|
401 | flag = True |
---|
402 | valueMin = self.qmin.GetValue() |
---|
403 | valueMax = self.qmax.GetValue() |
---|
404 | # Check for possible values entered |
---|
405 | #print "fitpage: checkfitrange:",valueMin,valueMax |
---|
406 | try: |
---|
407 | if (float(valueMax)> float(valueMin)): |
---|
408 | self.qmax.SetBackgroundColour(wx.WHITE) |
---|
409 | self.qmin.SetBackgroundColour(wx.WHITE) |
---|
410 | else: |
---|
411 | flag = False |
---|
412 | self.qmin.SetBackgroundColour("pink") |
---|
413 | self.qmax.SetBackgroundColour("pink") |
---|
414 | except: |
---|
415 | flag = False |
---|
416 | self.qmin.SetBackgroundColour("pink") |
---|
417 | self.qmax.SetBackgroundColour("pink") |
---|
418 | |
---|
419 | self.qmin.Refresh() |
---|
420 | self.qmax.Refresh() |
---|
421 | return flag |
---|
422 | |
---|
423 | |
---|
424 | |
---|
425 | def onClose(self,event): |
---|
426 | """ close the page associated with this panel""" |
---|
427 | self.parent.onClose() |
---|
428 | |
---|
429 | |
---|
430 | |
---|
431 | def onModel2D(self, event): |
---|
432 | """ |
---|
433 | call manager to plot model in 2D |
---|
434 | """ |
---|
435 | # If the 2D display is not currently enabled, plot the model in 2D |
---|
436 | # and set the enable2D flag. |
---|
437 | if self.fitrange: |
---|
438 | self.enable2D = True |
---|
439 | |
---|
440 | if self.enable2D: |
---|
441 | self._draw_model() |
---|
442 | self.model_view.Disable() |
---|
443 | |
---|
444 | |
---|
445 | |
---|
446 | def select_model(self, model, name): |
---|
447 | """ |
---|
448 | Select a new model |
---|
449 | @param model: model object |
---|
450 | """ |
---|
451 | self.model = model |
---|
452 | self.parent.model_page.name = name |
---|
453 | self.parent.draw_model_name = name |
---|
454 | |
---|
455 | self.set_panel(model) |
---|
456 | self._draw_model() |
---|
457 | |
---|
458 | if hasattr(model ,"model2"): |
---|
459 | name= model.model2.name |
---|
460 | items = self.structbox.GetItems() |
---|
461 | for i in range(len(items)): |
---|
462 | if items[i]==name: |
---|
463 | self.structbox.SetSelection(i) |
---|
464 | |
---|
465 | if hasattr(model ,"model1"): |
---|
466 | name= model.model1.name |
---|
467 | items = self.modelbox.GetItems() |
---|
468 | for i in range(len(items)): |
---|
469 | if items[i]==name: |
---|
470 | self.modelbox.SetSelection(i) |
---|
471 | else: |
---|
472 | # Select the model from the combo box |
---|
473 | items = self.modelbox.GetItems() |
---|
474 | for i in range(len(items)): |
---|
475 | if items[i]==name: |
---|
476 | self.modelbox.SetSelection(i) |
---|
477 | self.structbox.SetValue("No Structure") |
---|
478 | |
---|
479 | self.model_view.SetFocus() |
---|
480 | |
---|
481 | def _on_select_Disp(self,event): |
---|
482 | """ |
---|
483 | allow selecting different dispersion |
---|
484 | self.disp_list should change type later .now only gaussian |
---|
485 | """ |
---|
486 | type =event.GetString() |
---|
487 | self.set_panel_dispers( self.disp_list,type ) |
---|
488 | |
---|
489 | def _on_select_model(self,event): |
---|
490 | """ |
---|
491 | react when a model is selected from page's combo box |
---|
492 | post an event to its owner to draw an appropriate theory |
---|
493 | """ |
---|
494 | self.disable_disp.SetValue(True) |
---|
495 | self.sizer8.Clear(True) |
---|
496 | self.sizer7.Clear(True) |
---|
497 | self.vbox.Layout() |
---|
498 | self.SetScrollbars(20,20,55,40) |
---|
499 | self.Layout() |
---|
500 | self.parent.GetSizer().Layout() |
---|
501 | form_factor =self.modelbox.GetClientData(self.modelbox.GetCurrentSelection()) |
---|
502 | struct_factor =self.structbox.GetClientData(self.structbox.GetCurrentSelection()) |
---|
503 | |
---|
504 | if form_factor!="separator": |
---|
505 | if struct_factor != None and struct_factor.__name__ != "NoStructure": |
---|
506 | from sans.models.MultiplicationModel import MultiplicationModel |
---|
507 | self.model= MultiplicationModel(form_factor(),struct_factor()) |
---|
508 | else: |
---|
509 | self.model= form_factor() |
---|
510 | else: |
---|
511 | self.model=None |
---|
512 | msg= " Select non - model value:%s !Please select another model"%name |
---|
513 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg)) |
---|
514 | |
---|
515 | self.set_model_description(self.model) |
---|
516 | self.set_panel(self.model) |
---|
517 | self.name= self.model.name |
---|
518 | self.model_view.SetFocus() |
---|
519 | self.parent.model_page.name= self.name |
---|
520 | self.parent.draw_model_name= self.name |
---|
521 | self._draw_model() |
---|
522 | |
---|
523 | def get_model_box(self): |
---|
524 | """ return reference to combox box self.model""" |
---|
525 | return self.modelbox |
---|
526 | |
---|
527 | |
---|
528 | def get_param_list(self): |
---|
529 | """ |
---|
530 | @return self.param_toFit: list containing references to TextCtrl |
---|
531 | checked.Theses TextCtrl will allow reference to parameters to fit. |
---|
532 | @raise: if return an empty list of parameter fit will nnote work |
---|
533 | properly so raise ValueError,"missing parameter to fit" |
---|
534 | """ |
---|
535 | if self.param_toFit !=[]: |
---|
536 | return self.param_toFit |
---|
537 | else: |
---|
538 | raise ValueError,"missing parameter to fit" |
---|
539 | |
---|
540 | |
---|
541 | def set_panel(self,model): |
---|
542 | """ |
---|
543 | Build the panel from the model content |
---|
544 | @param model: the model selected in combo box for fitting purpose |
---|
545 | """ |
---|
546 | |
---|
547 | self.sizer5.Clear(True) |
---|
548 | self.parameters = [] |
---|
549 | self.param_toFit=[] |
---|
550 | self.fixed_param=[] |
---|
551 | if model !=None: |
---|
552 | self.model = model |
---|
553 | |
---|
554 | self.set_model_description( self.model) |
---|
555 | |
---|
556 | keys = self.model.getParamList() |
---|
557 | #list of dispersion paramaters |
---|
558 | self.disp_list=self.model.getDispParamList() |
---|
559 | |
---|
560 | keys.sort() |
---|
561 | ik=0 |
---|
562 | im=1 |
---|
563 | |
---|
564 | iy = 1 |
---|
565 | ix = 0 |
---|
566 | self.cb1 = wx.CheckBox(self, -1,"Select all", (10, 10)) |
---|
567 | if self.data!=None: |
---|
568 | wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.select_all_param) |
---|
569 | self.cb1.SetValue(False) |
---|
570 | else: |
---|
571 | self.cb1.Disable() |
---|
572 | self.cb1.Hide() |
---|
573 | |
---|
574 | self.sizer5.Add(self.cb1,(iy, ix),(1,1),\ |
---|
575 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
576 | ix +=1 |
---|
577 | self.text2_2 = wx.StaticText(self, -1, 'Values') |
---|
578 | self.sizer5.Add(self.text2_2,(iy, ix),(1,1),\ |
---|
579 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
580 | ix +=2 |
---|
581 | self.text2_3 = wx.StaticText(self, -1, 'Errors') |
---|
582 | self.sizer5.Add(self.text2_3,(iy, ix),(1,1),\ |
---|
583 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
584 | self.text2_3.Hide() |
---|
585 | |
---|
586 | |
---|
587 | ix +=1 |
---|
588 | self.text2_4 = wx.StaticText(self, -1, 'Units') |
---|
589 | self.sizer5.Add(self.text2_4,(iy, ix),(1,1),\ |
---|
590 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
591 | self.text2_4.Hide() |
---|
592 | disp_list=self.model.getDispParamList() |
---|
593 | for item in keys: |
---|
594 | if not item in disp_list: |
---|
595 | iy += 1 |
---|
596 | ix = 0 |
---|
597 | |
---|
598 | cb = wx.CheckBox(self, -1, item, (10, 10)) |
---|
599 | if self.data!=None: |
---|
600 | cb.SetValue(False) |
---|
601 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
602 | else: |
---|
603 | cb.Disable() |
---|
604 | self.sizer5.Add( cb,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
605 | |
---|
606 | ix += 1 |
---|
607 | value= self.model.getParam(item) |
---|
608 | ctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
609 | ctl1.SetValue(str (format_number(value))) |
---|
610 | ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
611 | ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
612 | self.sizer5.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
613 | |
---|
614 | ix += 1 |
---|
615 | text2=wx.StaticText(self, -1, '+/-') |
---|
616 | self.sizer5.Add(text2,(iy, ix),(1,1),\ |
---|
617 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
618 | text2.Hide() |
---|
619 | ix += 1 |
---|
620 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
621 | self.sizer5.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
622 | ctl2.Hide() |
---|
623 | |
---|
624 | ix +=1 |
---|
625 | # Units |
---|
626 | try: |
---|
627 | units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
628 | except: |
---|
629 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
630 | self.sizer5.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
631 | |
---|
632 | self.parameters.append([cb,ctl1,text2,ctl2]) |
---|
633 | |
---|
634 | iy+=1 |
---|
635 | self.sizer5.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
636 | |
---|
637 | #Display units text on panel |
---|
638 | for item in keys: |
---|
639 | if self.model.details[item][0]!='': |
---|
640 | self.text2_4.Show() |
---|
641 | break |
---|
642 | else: |
---|
643 | self.text2_4.Hide() |
---|
644 | |
---|
645 | self.vbox.Layout() |
---|
646 | self.SetScrollbars(20,20,55,40) |
---|
647 | self.Layout() |
---|
648 | self.parent.GetSizer().Layout() |
---|
649 | |
---|
650 | |
---|
651 | |
---|
652 | def _selectDlg(self): |
---|
653 | import os |
---|
654 | dlg = wx.FileDialog(self, "Choose a weight file", os.getcwd(), "", "*.*", wx.OPEN) |
---|
655 | path = None |
---|
656 | if dlg.ShowModal() == wx.ID_OK: |
---|
657 | path = dlg.GetPath() |
---|
658 | dlg.Destroy() |
---|
659 | return path |
---|
660 | def read_file(self, path): |
---|
661 | try: |
---|
662 | if path==None: |
---|
663 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
664 | " Selected Distribution was not loaded: %s"%path)) |
---|
665 | return None, None |
---|
666 | input_f = open(path, 'r') |
---|
667 | buff = input_f.read() |
---|
668 | lines = buff.split('\n') |
---|
669 | |
---|
670 | angles = [] |
---|
671 | weights=[] |
---|
672 | for line in lines: |
---|
673 | toks = line.split() |
---|
674 | if len(toks)==2: |
---|
675 | try: |
---|
676 | angle = float(toks[0]) |
---|
677 | weight = float(toks[1]) |
---|
678 | except: |
---|
679 | # Skip non-data lines |
---|
680 | pass |
---|
681 | angles.append(angle) |
---|
682 | weights.append(weight) |
---|
683 | return numpy.array(angles), numpy.array(weights) |
---|
684 | except: |
---|
685 | raise |
---|
686 | |
---|
687 | |
---|
688 | def select_disp_angle(self, event): |
---|
689 | """ |
---|
690 | Event for when a user select a parameter to average over. |
---|
691 | @param event: check box event |
---|
692 | """ |
---|
693 | |
---|
694 | |
---|
695 | # Go through the list of dispersion check boxes to identify which one has changed |
---|
696 | for p in self.disp_cb_dict: |
---|
697 | # Catch which one of the box was just checked or unchecked. |
---|
698 | if event.GetEventObject() == self.disp_cb_dict[p]: |
---|
699 | |
---|
700 | |
---|
701 | if self.disp_cb_dict[p].GetValue() == True: |
---|
702 | # The user wants this parameter to be averaged. |
---|
703 | # Pop up the file selection dialog. |
---|
704 | path = self._selectDlg() |
---|
705 | |
---|
706 | # If nothing was selected, just return |
---|
707 | if path is None: |
---|
708 | self.disp_cb_dict[p].SetValue(False) |
---|
709 | return |
---|
710 | |
---|
711 | try: |
---|
712 | values,weights = self.read_file(path) |
---|
713 | except: |
---|
714 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
715 | "Could not read input file")) |
---|
716 | return |
---|
717 | |
---|
718 | # If any of the two arrays is empty, notify the user that we won't |
---|
719 | # proceed |
---|
720 | if values is None or weights is None: |
---|
721 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
722 | "The loaded %s distrubtion is corrupted or empty" % p)) |
---|
723 | return |
---|
724 | |
---|
725 | # Tell the user that we are about to apply the distribution |
---|
726 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
727 | "Applying loaded %s distribution: %s" % (p, path))) |
---|
728 | |
---|
729 | # Create the dispersion objects |
---|
730 | disp_model = ArrayDispersion() |
---|
731 | disp_model.set_weights(values, weights) |
---|
732 | # Store the object to make it persist outside the scope of this method |
---|
733 | #TODO: refactor model to clean this up? |
---|
734 | self._disp_obj_dict[p] = disp_model |
---|
735 | |
---|
736 | # Set the new model as the dispersion object for the selected parameter |
---|
737 | self.model.set_dispersion(p, disp_model) |
---|
738 | |
---|
739 | |
---|
740 | # Redraw the model |
---|
741 | self._draw_model() |
---|
742 | |
---|
743 | else: |
---|
744 | # The parameter was un-selected. Go back to Gaussian model (with 0 pts) |
---|
745 | disp_model = GaussianDispersion() |
---|
746 | # Store the object to make it persist outside the scope of this method |
---|
747 | #TODO: refactor model to clean this up? |
---|
748 | self._disp_obj_dict[p] = disp_model |
---|
749 | |
---|
750 | # Set the new model as the dispersion object for the selected parameter |
---|
751 | self.model.set_dispersion(p, disp_model) |
---|
752 | |
---|
753 | # Redraw the model |
---|
754 | self._draw_model() |
---|
755 | return |
---|
756 | |
---|
757 | |
---|
758 | |
---|
759 | |
---|
760 | def set_panel_dispers(self, disp_list, type="GaussianModel" ): |
---|
761 | """ |
---|
762 | """ |
---|
763 | |
---|
764 | self.fittable_param=[] |
---|
765 | self.fixed_param=[] |
---|
766 | |
---|
767 | ix=0 |
---|
768 | iy=1 |
---|
769 | ### this will become a separate method |
---|
770 | if type== "Select customized Model": |
---|
771 | ix=0 |
---|
772 | iy=1 |
---|
773 | self.sizer8.Clear(True) |
---|
774 | disp1 = wx.StaticText(self, -1, 'Array Dispersion') |
---|
775 | self.sizer8.Add(disp1,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
776 | |
---|
777 | # Look for model parameters to which we can apply an ArrayDispersion model |
---|
778 | # Add a check box for each parameter. |
---|
779 | self.disp_cb_dict = {} |
---|
780 | for p in self.model.dispersion.keys(): |
---|
781 | ix+=1 |
---|
782 | self.disp_cb_dict[p] = wx.CheckBox(self, -1, p, (10, 10)) |
---|
783 | |
---|
784 | wx.EVT_CHECKBOX(self, self.disp_cb_dict[p].GetId(), self.select_disp_angle) |
---|
785 | self.sizer8.Add(self.disp_cb_dict[p], (iy, ix), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
786 | |
---|
787 | ix =0 |
---|
788 | iy +=1 |
---|
789 | self.sizer8.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
790 | self.vbox.Layout() |
---|
791 | self.SetScrollbars(20,20,55,40) |
---|
792 | self.Layout() |
---|
793 | self.parent.GetSizer().Layout() |
---|
794 | |
---|
795 | if type== "GaussianModel" : |
---|
796 | |
---|
797 | self.sizer8.Clear(True) |
---|
798 | disp = wx.StaticText(self, -1, 'Dispersion') |
---|
799 | self.sizer8.Add(disp,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
800 | ix += 1 |
---|
801 | values = wx.StaticText(self, -1, 'Values') |
---|
802 | self.sizer8.Add(values,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
803 | ix +=2 |
---|
804 | self.text2_3 = wx.StaticText(self, -1, 'Errors') |
---|
805 | self.sizer8.Add(self.text2_3,(iy, ix),(1,1),\ |
---|
806 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
807 | self.text2_3.Hide() |
---|
808 | |
---|
809 | ix += 1 |
---|
810 | npts = wx.StaticText(self, -1, 'Npts') |
---|
811 | self.sizer8.Add(npts,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
812 | ix += 1 |
---|
813 | nsigmas = wx.StaticText(self, -1, 'Nsigmas') |
---|
814 | self.sizer8.Add(nsigmas,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
815 | |
---|
816 | disp_list.sort() |
---|
817 | #print disp_list,self.model.dispersion |
---|
818 | for item in self.model.dispersion.keys(): |
---|
819 | name1=item+".width" |
---|
820 | name2=item+".npts" |
---|
821 | name3=item+".nsigmas" |
---|
822 | iy += 1 |
---|
823 | for p in self.model.dispersion[item].keys(): |
---|
824 | #print "name 1 2 3", name1, name2, name3 |
---|
825 | if p=="width": |
---|
826 | ix = 0 |
---|
827 | cb = wx.CheckBox(self, -1, name1, (10, 10)) |
---|
828 | if self.data !=None: |
---|
829 | cb.SetValue(False) |
---|
830 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
831 | else: |
---|
832 | cb.Disable() |
---|
833 | self.sizer8.Add( cb,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
834 | ix = 1 |
---|
835 | value= self.model.getParam(name1) |
---|
836 | ctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
837 | ctl1.SetValue(str (format_number(value))) |
---|
838 | ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
839 | ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
840 | self.sizer8.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
841 | |
---|
842 | ix = 2 |
---|
843 | text2=wx.StaticText(self, -1, '+/-') |
---|
844 | self.sizer8.Add(text2,(iy, ix),(1,1),\ |
---|
845 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
846 | text2.Hide() |
---|
847 | ix = 3 |
---|
848 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
849 | self.sizer8.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
850 | ctl2.Hide() |
---|
851 | self.fittable_param.append([cb,ctl1,text2,ctl2]) |
---|
852 | |
---|
853 | |
---|
854 | elif p=="npts": |
---|
855 | ix =4 |
---|
856 | value= self.model.getParam(name2) |
---|
857 | Tctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER) |
---|
858 | Tctl.SetValue(str (format_number(value))) |
---|
859 | Tctl.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
860 | Tctl.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
861 | self.sizer8.Add(Tctl, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
862 | self.fixed_param.append([name2, Tctl]) |
---|
863 | elif p=="nsigmas": |
---|
864 | ix =5 |
---|
865 | value= self.model.getParam(name3) |
---|
866 | Tctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER) |
---|
867 | Tctl.SetValue(str (format_number(value))) |
---|
868 | Tctl.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
869 | Tctl.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
870 | self.sizer8.Add(Tctl, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
871 | self.fixed_param.append([name3, Tctl]) |
---|
872 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
873 | " Selected Distribution: Gaussian")) |
---|
874 | ix =0 |
---|
875 | iy +=1 |
---|
876 | self.sizer8.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
877 | self.vbox.Layout() |
---|
878 | self.SetScrollbars(20,20,55,40) |
---|
879 | self.Layout() |
---|
880 | self.parent.GetSizer().Layout() |
---|
881 | |
---|
882 | def checkFitValues(self,val_min, val_max): |
---|
883 | """ |
---|
884 | Check the validity of input values |
---|
885 | """ |
---|
886 | flag = True |
---|
887 | min_value = val_min.GetValue() |
---|
888 | max_value = val_max.GetValue() |
---|
889 | # Check for possible values entered |
---|
890 | if min_value.lstrip().rstrip() =="-inf": |
---|
891 | min_value= -numpy.inf |
---|
892 | if max_value.lstrip().rstrip() =="+inf": |
---|
893 | max_value= numpy.inf |
---|
894 | if min_value==-numpy.inf and max_value== numpy.inf: |
---|
895 | val_min.SetBackgroundColour(wx.WHITE) |
---|
896 | val_min.Refresh() |
---|
897 | val_max.SetBackgroundColour(wx.WHITE) |
---|
898 | val_max.Refresh() |
---|
899 | return flag |
---|
900 | elif max_value== numpy.inf: |
---|
901 | try: |
---|
902 | float(min_value) |
---|
903 | val_min.SetBackgroundColour(wx.WHITE) |
---|
904 | val_min.Refresh() |
---|
905 | except: |
---|
906 | flag = False |
---|
907 | val_min.SetBackgroundColour("pink") |
---|
908 | val_min.Refresh() |
---|
909 | return flag |
---|
910 | elif min_value==-numpy.inf: |
---|
911 | try: |
---|
912 | float(max_value) |
---|
913 | val_max.SetBackgroundColour(wx.WHITE) |
---|
914 | val_max.Refresh() |
---|
915 | except: |
---|
916 | flag = False |
---|
917 | val_max.SetBackgroundColour("pink") |
---|
918 | val_max.Refresh() |
---|
919 | return flag |
---|
920 | else: |
---|
921 | if (float(min_value)< float(max_value)): |
---|
922 | val_min.SetBackgroundColour(wx.WHITE) |
---|
923 | val_min.Refresh() |
---|
924 | else: |
---|
925 | flag = False |
---|
926 | val_min.SetBackgroundColour("pink") |
---|
927 | val_min.Refresh() |
---|
928 | return flag |
---|
929 | |
---|
930 | |
---|
931 | def _onparamEnter(self,event): |
---|
932 | """ |
---|
933 | when enter value on panel redraw model according to changed |
---|
934 | """ |
---|
935 | self.set_model_parameter() |
---|
936 | |
---|
937 | def set_model_parameter(self): |
---|
938 | """ |
---|
939 | """ |
---|
940 | if len(self.parameters) !=0 and self.model !=None: |
---|
941 | # Flag to register when a parameter has changed. |
---|
942 | is_modified = False |
---|
943 | for item in self.fittable_param: |
---|
944 | try: |
---|
945 | name=str(item[0].GetLabelText()) |
---|
946 | value= float(item[1].GetValue()) |
---|
947 | # If the value of the parameter has changed, |
---|
948 | # update the model and set the is_modified flag |
---|
949 | if value != self.model.getParam(name): |
---|
950 | self.model.setParam(name,value) |
---|
951 | is_modified = True |
---|
952 | |
---|
953 | except: |
---|
954 | #raise |
---|
955 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
956 | "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) |
---|
957 | return |
---|
958 | |
---|
959 | |
---|
960 | for item in self.fixed_param: |
---|
961 | try: |
---|
962 | name=str(item[0]) |
---|
963 | value= float(item[1].GetValue()) |
---|
964 | # If the value of the parameter has changed, |
---|
965 | # update the model and set the is_modified flag |
---|
966 | if value != self.model.getParam(name): |
---|
967 | self.model.setParam(name,value) |
---|
968 | is_modified = True |
---|
969 | |
---|
970 | except: |
---|
971 | raise |
---|
972 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
973 | "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) |
---|
974 | |
---|
975 | for item in self.parameters: |
---|
976 | try: |
---|
977 | name=str(item[0].GetLabelText()) |
---|
978 | value= float(item[1].GetValue()) |
---|
979 | # If the value of the parameter has changed, |
---|
980 | # update the model and set the is_modified flag |
---|
981 | if value != self.model.getParam(name): |
---|
982 | self.model.setParam(name,value) |
---|
983 | is_modified = True |
---|
984 | |
---|
985 | except: |
---|
986 | #raise |
---|
987 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
988 | "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) |
---|
989 | return |
---|
990 | |
---|
991 | |
---|
992 | # Here we should check whether the boundaries have been modified. |
---|
993 | # If qmin and qmax have been modified, update qmin and qmax and |
---|
994 | # set the is_modified flag to True |
---|
995 | from sans.guiframe.utils import check_value |
---|
996 | if check_value( self.qmin, self.qmax): |
---|
997 | if float(self.qmin.GetValue()) != self.qmin_x: |
---|
998 | self.qmin_x = float(self.qmin.GetValue()) |
---|
999 | is_modified = True |
---|
1000 | if float(self.qmax.GetValue()) != self.qmax_x: |
---|
1001 | self.qmax_x = float(self.qmax.GetValue()) |
---|
1002 | is_modified = True |
---|
1003 | self.fitrange = True |
---|
1004 | else: |
---|
1005 | self.fitrange = False |
---|
1006 | if float(self.npts.GetValue()) != self.num_points: |
---|
1007 | self.num_points = float(self.npts.GetValue()) |
---|
1008 | is_modified = True |
---|
1009 | |
---|
1010 | if is_modified: |
---|
1011 | self._draw_model() |
---|
1012 | |
---|
1013 | def _draw_model(self): |
---|
1014 | """ |
---|
1015 | Method to draw or refresh a plotted model. |
---|
1016 | The method will use the data member from the model page |
---|
1017 | to build a call to the fitting perspective manager. |
---|
1018 | |
---|
1019 | [Note to coder: This way future changes will be done in only one place.] |
---|
1020 | """ |
---|
1021 | if self.model !=None: |
---|
1022 | self.manager.draw_model(self.model, self.model.name, data=self.data, |
---|
1023 | qmin=self.qmin_x, qmax=self.qmax_x, |
---|
1024 | qstep= self.num_points, |
---|
1025 | enable2D=self.enable2D) |
---|
1026 | |
---|
1027 | def select_param(self,event): |
---|
1028 | """ |
---|
1029 | |
---|
1030 | """ |
---|
1031 | pass |
---|
1032 | def select_all_param(self,event): |
---|
1033 | """ |
---|
1034 | |
---|
1035 | """ |
---|
1036 | pass |
---|
1037 | def select_all_param_helper(self): |
---|
1038 | """ |
---|
1039 | Allows selecting or delecting button |
---|
1040 | """ |
---|
1041 | self.param_toFit=[] |
---|
1042 | if self.parameters !=[]: |
---|
1043 | if self.cb1.GetValue()==True: |
---|
1044 | for item in self.parameters: |
---|
1045 | item[0].SetValue(True) |
---|
1046 | list= [item[0],item[1],item[2],item[3]] |
---|
1047 | self.param_toFit.append(list ) |
---|
1048 | if len(self.fittable_param)>0: |
---|
1049 | for item in self.fittable_param: |
---|
1050 | item[0].SetValue(True) |
---|
1051 | list= [item[0],item[1],item[2],item[3]] |
---|
1052 | self.param_toFit.append(list ) |
---|
1053 | else: |
---|
1054 | for item in self.parameters: |
---|
1055 | item[0].SetValue(False) |
---|
1056 | for item in self.fittable_param: |
---|
1057 | item[0].SetValue(False) |
---|
1058 | self.param_toFit=[] |
---|
1059 | |
---|
1060 | |
---|
1061 | |
---|