1 | |
---|
2 | import sys, os |
---|
3 | import wx |
---|
4 | import numpy |
---|
5 | import time |
---|
6 | import copy |
---|
7 | import math |
---|
8 | import string |
---|
9 | from sans.guiframe.utils import format_number,check_float |
---|
10 | from sans.guicomm.events import StatusEvent |
---|
11 | import pagestate |
---|
12 | from pagestate import PageState |
---|
13 | (PageInfoEvent, EVT_PAGE_INFO) = wx.lib.newevent.NewEvent() |
---|
14 | (PreviousStateEvent, EVT_PREVIOUS_STATE) = wx.lib.newevent.NewEvent() |
---|
15 | (NextStateEvent, EVT_NEXT_STATE) = wx.lib.newevent.NewEvent() |
---|
16 | _BOX_WIDTH = 76 |
---|
17 | _QMIN_DEFAULT = 0.001 |
---|
18 | _QMAX_DEFAULT = 0.13 |
---|
19 | _NPTS_DEFAULT = 50 |
---|
20 | #Control panel width |
---|
21 | if sys.platform.count("darwin")==0: |
---|
22 | PANEL_WIDTH = 450 |
---|
23 | FONT_VARIANT = 0 |
---|
24 | ON_MAC = False |
---|
25 | else: |
---|
26 | PANEL_WIDTH = 500 |
---|
27 | FONT_VARIANT = 1 |
---|
28 | ON_MAC = True |
---|
29 | |
---|
30 | class BasicPage(wx.ScrolledWindow): |
---|
31 | """ |
---|
32 | This class provide general structure of fitpanel page |
---|
33 | |
---|
34 | """ |
---|
35 | ## Internal name for the AUI manager |
---|
36 | window_name = "Basic Page" |
---|
37 | ## Title to appear on top of the window |
---|
38 | window_caption = "Basic page " |
---|
39 | |
---|
40 | def __init__(self,parent, page_info= None, model_list_box=None): |
---|
41 | wx.ScrolledWindow.__init__(self, parent, |
---|
42 | style= wx.FULL_REPAINT_ON_RESIZE ) |
---|
43 | #Set window's font size |
---|
44 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
45 | |
---|
46 | ## parent of the page |
---|
47 | self.parent = parent |
---|
48 | self.model_list_box = model_list_box |
---|
49 | self.model = None |
---|
50 | self.manager = None |
---|
51 | self.data = None |
---|
52 | ## owner of the page (fitting plugin) |
---|
53 | self.event_owner = None |
---|
54 | |
---|
55 | if page_info is not None: |
---|
56 | ## manager is the fitting plugin |
---|
57 | self.manager= page_info.manager |
---|
58 | ## owner of the page (fitting plugin) |
---|
59 | self.event_owner= page_info.event_owner |
---|
60 | ## current model |
---|
61 | self.model = page_info.model |
---|
62 | ## data |
---|
63 | self.data = page_info.data |
---|
64 | ## dictionary containing list of models |
---|
65 | self.model_list_box = page_info.model_list_box |
---|
66 | ##window_name |
---|
67 | self.window_name = page_info.window_name |
---|
68 | ##window_caption |
---|
69 | self.window_caption = page_info.window_caption |
---|
70 | ## Data member to store the dispersion object created |
---|
71 | self._disp_obj_dict = {} |
---|
72 | ## selected parameters to apply dispersion |
---|
73 | self.disp_cb_dict ={} |
---|
74 | |
---|
75 | ## smearer object |
---|
76 | self.smearer = None |
---|
77 | |
---|
78 | ##list of model parameters. each item must have same length |
---|
79 | ## each item related to a given parameters |
---|
80 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
81 | self.parameters=[] |
---|
82 | # non-fittable parameter whose value is astring |
---|
83 | self.str_parameters = [] |
---|
84 | ## list of parameters to fit , must be like self.parameters |
---|
85 | self.param_toFit=[] |
---|
86 | ## list of looking like parameters but with non fittable parameters info |
---|
87 | self.fixed_param=[] |
---|
88 | ## list of looking like parameters but with fittable parameters info |
---|
89 | self.fittable_param=[] |
---|
90 | ##list of dispersion parameters |
---|
91 | self.disp_list=[] |
---|
92 | self.disp_name="" |
---|
93 | ## list of orientation parameters |
---|
94 | self.orientation_params=[] |
---|
95 | self.orientation_params_disp=[] |
---|
96 | if self.model != None: |
---|
97 | self.disp_list= self.model.getDispParamList() |
---|
98 | self.multi_factor = None |
---|
99 | ##enable model 2D draw |
---|
100 | self.enable2D= False |
---|
101 | ## check that the fit range is correct to plot the model again |
---|
102 | self.fitrange= True |
---|
103 | |
---|
104 | ## Q range |
---|
105 | self.qmin_x= _QMIN_DEFAULT |
---|
106 | self.qmax_x= _QMAX_DEFAULT |
---|
107 | self.num_points= _NPTS_DEFAULT |
---|
108 | |
---|
109 | ## Create memento to save the current state |
---|
110 | self.state= PageState(parent= self.parent,model=self.model, data=self.data) |
---|
111 | ## flag to determine if state has change |
---|
112 | self.state_change= False |
---|
113 | ## save customized array |
---|
114 | self.values=[] |
---|
115 | self.weights=[] |
---|
116 | ## retrieve saved state |
---|
117 | self.number_saved_state= 0 |
---|
118 | ## dictionary of saved state |
---|
119 | self.saved_states={} |
---|
120 | |
---|
121 | ## Create context menu for page |
---|
122 | self.popUpMenu = wx.Menu() |
---|
123 | #id = wx.NewId() |
---|
124 | #self._undo = wx.MenuItem(self.popUpMenu,id, "Undo","cancel the previous action") |
---|
125 | #self.popUpMenu.AppendItem(self._undo) |
---|
126 | #self._undo.Enable(False) |
---|
127 | #wx.EVT_MENU(self, id, self.onUndo) |
---|
128 | |
---|
129 | #id = wx.NewId() |
---|
130 | #self._redo = wx.MenuItem(self.popUpMenu,id,"Redo"," Restore the previous action") |
---|
131 | #self.popUpMenu.AppendItem(self._redo) |
---|
132 | #self._redo.Enable(False) |
---|
133 | #wx.EVT_MENU(self, id, self.onRedo) |
---|
134 | #self.popUpMenu.AppendSeparator() |
---|
135 | #if sys.platform.count("win32")>0: |
---|
136 | id = wx.NewId() |
---|
137 | self._keep = wx.MenuItem(self.popUpMenu,id,"BookMark"," Keep the panel status to recall it later") |
---|
138 | self.popUpMenu.AppendItem(self._keep) |
---|
139 | self._keep.Enable(True) |
---|
140 | wx.EVT_MENU(self, id, self.onSave) |
---|
141 | self.popUpMenu.AppendSeparator() |
---|
142 | |
---|
143 | ## Default locations |
---|
144 | self._default_save_location = os.getcwd() |
---|
145 | ## save initial state on context menu |
---|
146 | #self.onSave(event=None) |
---|
147 | self.Bind(wx.EVT_CONTEXT_MENU, self.onContextMenu) |
---|
148 | |
---|
149 | ## create the basic structure of the panel with empty sizer |
---|
150 | self.define_page_structure() |
---|
151 | ## drawing Initial dispersion parameters sizer |
---|
152 | self.set_dispers_sizer() |
---|
153 | self._fill_save_sizer() |
---|
154 | ## layout |
---|
155 | self.set_layout() |
---|
156 | |
---|
157 | class ModelTextCtrl(wx.TextCtrl): |
---|
158 | """ |
---|
159 | Text control for model and fit parameters. |
---|
160 | Binds the appropriate events for user interactions. |
---|
161 | Default callback methods can be overwritten on initialization |
---|
162 | |
---|
163 | :param kill_focus_callback: callback method for EVT_KILL_FOCUS event |
---|
164 | :param set_focus_callback: callback method for EVT_SET_FOCUS event |
---|
165 | :param mouse_up_callback: callback method for EVT_LEFT_UP event |
---|
166 | :param text_enter_callback: callback method for EVT_TEXT_ENTER event |
---|
167 | |
---|
168 | """ |
---|
169 | ## Set to True when the mouse is clicked while the whole string is selected |
---|
170 | full_selection = False |
---|
171 | ## Call back for EVT_SET_FOCUS events |
---|
172 | _on_set_focus_callback = None |
---|
173 | |
---|
174 | def __init__(self, parent, id=-1, value=wx.EmptyString, pos=wx.DefaultPosition, |
---|
175 | size=wx.DefaultSize, style=0, validator=wx.DefaultValidator, name=wx.TextCtrlNameStr, |
---|
176 | kill_focus_callback = None, set_focus_callback = None, |
---|
177 | mouse_up_callback = None, text_enter_callback = None): |
---|
178 | |
---|
179 | wx.TextCtrl.__init__(self, parent, id, value, pos, size, style, validator, name) |
---|
180 | |
---|
181 | # Bind appropriate events |
---|
182 | self._on_set_focus_callback = parent.onSetFocus \ |
---|
183 | if set_focus_callback is None else set_focus_callback |
---|
184 | self.Bind(wx.EVT_SET_FOCUS, self._on_set_focus) |
---|
185 | self.Bind(wx.EVT_KILL_FOCUS, parent._onparamEnter \ |
---|
186 | if kill_focus_callback is None else kill_focus_callback) |
---|
187 | self.Bind(wx.EVT_TEXT_ENTER, parent._onparamEnter \ |
---|
188 | if text_enter_callback is None else text_enter_callback) |
---|
189 | if not ON_MAC : |
---|
190 | self.Bind(wx.EVT_LEFT_UP, self._highlight_text \ |
---|
191 | if mouse_up_callback is None else mouse_up_callback) |
---|
192 | |
---|
193 | def _on_set_focus(self, event): |
---|
194 | """ |
---|
195 | Catch when the text control is set in focus to highlight the whole |
---|
196 | text if necessary |
---|
197 | |
---|
198 | :param event: mouse event |
---|
199 | """ |
---|
200 | |
---|
201 | event.Skip() |
---|
202 | self.full_selection = True |
---|
203 | return self._on_set_focus_callback(event) |
---|
204 | |
---|
205 | |
---|
206 | |
---|
207 | def _highlight_text(self, event): |
---|
208 | """ |
---|
209 | Highlight text of a TextCtrl only of no text has be selected |
---|
210 | |
---|
211 | :param event: mouse event |
---|
212 | |
---|
213 | """ |
---|
214 | # Make sure the mouse event is available to other listeners |
---|
215 | event.Skip() |
---|
216 | control = event.GetEventObject() |
---|
217 | if self.full_selection: |
---|
218 | self.full_selection = False |
---|
219 | # Check that we have a TextCtrl |
---|
220 | if issubclass(control.__class__, wx.TextCtrl): |
---|
221 | # Check whether text has been selected, |
---|
222 | # if not, select the whole string |
---|
223 | (start, end) = control.GetSelection() |
---|
224 | if start==end: |
---|
225 | control.SetSelection(-1,-1) |
---|
226 | |
---|
227 | def onContextMenu(self, event): |
---|
228 | """ |
---|
229 | Retrieve the state selected state |
---|
230 | |
---|
231 | """ |
---|
232 | pos = event.GetPosition() |
---|
233 | pos = self.ScreenToClient(pos) |
---|
234 | self.PopupMenu(self.popUpMenu, pos) |
---|
235 | |
---|
236 | def onUndo(self, event): |
---|
237 | """ |
---|
238 | Cancel the previous action |
---|
239 | |
---|
240 | """ |
---|
241 | event = PreviousStateEvent(page = self) |
---|
242 | wx.PostEvent(self.parent, event) |
---|
243 | |
---|
244 | def onRedo(self, event): |
---|
245 | """ |
---|
246 | Restore the previous action canceled |
---|
247 | |
---|
248 | """ |
---|
249 | event = NextStateEvent(page= self) |
---|
250 | wx.PostEvent(self.parent, event) |
---|
251 | |
---|
252 | def define_page_structure(self): |
---|
253 | """ |
---|
254 | Create empty sizer for a panel |
---|
255 | |
---|
256 | """ |
---|
257 | self.vbox = wx.BoxSizer(wx.VERTICAL) |
---|
258 | self.sizer0 = wx.BoxSizer(wx.VERTICAL) |
---|
259 | self.sizer1 = wx.BoxSizer(wx.VERTICAL) |
---|
260 | self.sizer2 = wx.BoxSizer(wx.VERTICAL) |
---|
261 | self.sizer3 = wx.BoxSizer(wx.VERTICAL) |
---|
262 | self.sizer4 = wx.BoxSizer(wx.VERTICAL) |
---|
263 | self.sizer5 = wx.BoxSizer(wx.VERTICAL) |
---|
264 | self.sizer6 = wx.BoxSizer(wx.VERTICAL) |
---|
265 | |
---|
266 | self.sizer0.SetMinSize((PANEL_WIDTH,-1)) |
---|
267 | self.sizer1.SetMinSize((PANEL_WIDTH,-1)) |
---|
268 | self.sizer2.SetMinSize((PANEL_WIDTH,-1)) |
---|
269 | self.sizer3.SetMinSize((PANEL_WIDTH,-1)) |
---|
270 | self.sizer4.SetMinSize((PANEL_WIDTH,-1)) |
---|
271 | self.sizer5.SetMinSize((PANEL_WIDTH,-1)) |
---|
272 | #self.sizer6.SetMinSize((375,-1)) |
---|
273 | |
---|
274 | self.vbox.Add(self.sizer0) |
---|
275 | self.vbox.Add(self.sizer1) |
---|
276 | self.vbox.Add(self.sizer2) |
---|
277 | self.vbox.Add(self.sizer3) |
---|
278 | self.vbox.Add(self.sizer4) |
---|
279 | self.vbox.Add(self.sizer5) |
---|
280 | #self.vbox.Add(self.sizer6) |
---|
281 | |
---|
282 | |
---|
283 | def set_layout(self): |
---|
284 | """ |
---|
285 | layout |
---|
286 | |
---|
287 | """ |
---|
288 | self.vbox.Layout() |
---|
289 | self.vbox.Fit(self) |
---|
290 | self.SetSizer(self.vbox) |
---|
291 | self.set_scroll() |
---|
292 | self.Centre() |
---|
293 | |
---|
294 | def set_scroll(self): |
---|
295 | """ |
---|
296 | """ |
---|
297 | self.SetScrollbars(20,20,25,65) |
---|
298 | self.Layout() |
---|
299 | self.SetAutoLayout(True) |
---|
300 | |
---|
301 | def set_owner(self, owner): |
---|
302 | """ |
---|
303 | set owner of fitpage |
---|
304 | @param owner: the class responsible of plotting |
---|
305 | """ |
---|
306 | self.event_owner = owner |
---|
307 | self.state.event_owner = owner |
---|
308 | |
---|
309 | def set_manager(self, manager): |
---|
310 | """ |
---|
311 | set panel manager |
---|
312 | |
---|
313 | :param manager: instance of plugin fitting |
---|
314 | """ |
---|
315 | self.manager = manager |
---|
316 | self.state.manager = manager |
---|
317 | |
---|
318 | def populate_box(self, dict): |
---|
319 | """ |
---|
320 | Store list of model |
---|
321 | |
---|
322 | :param dict: dictionary containing list of models |
---|
323 | |
---|
324 | """ |
---|
325 | self.model_list_box = dict |
---|
326 | self.state.model_list_box = self.model_list_box |
---|
327 | |
---|
328 | def set_dispers_sizer(self): |
---|
329 | """ |
---|
330 | fill sizer containing dispersity info |
---|
331 | |
---|
332 | """ |
---|
333 | self.sizer4.Clear(True) |
---|
334 | name = "Polydispersity and Orientational Distribution" |
---|
335 | box_description= wx.StaticBox(self, -1,name) |
---|
336 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
337 | #---------------------------------------------------- |
---|
338 | self.disable_disp = wx.RadioButton(self, -1, 'Off', (10, 10), style=wx.RB_GROUP) |
---|
339 | self.enable_disp = wx.RadioButton(self, -1, 'On', (10, 30)) |
---|
340 | |
---|
341 | self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, id=self.disable_disp.GetId()) |
---|
342 | self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, id=self.enable_disp.GetId()) |
---|
343 | #MAC needs SetValue |
---|
344 | self.disable_disp.SetValue(True) |
---|
345 | sizer_dispersion = wx.BoxSizer(wx.HORIZONTAL) |
---|
346 | sizer_dispersion.Add((20,20)) |
---|
347 | name=""#Polydispersity and \nOrientational Distribution " |
---|
348 | sizer_dispersion.Add(wx.StaticText(self,-1,name)) |
---|
349 | sizer_dispersion.Add(self.enable_disp ) |
---|
350 | sizer_dispersion.Add((20,20)) |
---|
351 | sizer_dispersion.Add(self.disable_disp ) |
---|
352 | sizer_dispersion.Add((10,10)) |
---|
353 | |
---|
354 | ## fill a sizer with the combobox to select dispersion type |
---|
355 | sizer_select_dispers = wx.BoxSizer(wx.HORIZONTAL) |
---|
356 | self.model_disp = wx.StaticText(self, -1, 'Distribution Function ') |
---|
357 | |
---|
358 | import sans.models.dispersion_models |
---|
359 | self.polydisp= sans.models.dispersion_models.models |
---|
360 | self.disp_box = wx.ComboBox(self, -1) |
---|
361 | |
---|
362 | for key, value in self.polydisp.iteritems(): |
---|
363 | name = str(key) |
---|
364 | self.disp_box.Append(name,value) |
---|
365 | self.disp_box.SetStringSelection("gaussian") |
---|
366 | wx.EVT_COMBOBOX(self.disp_box,-1, self._on_select_Disp) |
---|
367 | |
---|
368 | sizer_select_dispers.Add((10,10)) |
---|
369 | sizer_select_dispers.Add(self.model_disp) |
---|
370 | sizer_select_dispers.Add(self.disp_box,0, |
---|
371 | wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE,border=5) |
---|
372 | |
---|
373 | self.model_disp.Hide() |
---|
374 | self.disp_box.Hide() |
---|
375 | |
---|
376 | boxsizer1.Add( sizer_dispersion,0, |
---|
377 | wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE,border=5) |
---|
378 | #boxsizer1.Add( (10,10) ) |
---|
379 | boxsizer1.Add( sizer_select_dispers ) |
---|
380 | self.sizer4_4 = wx.GridBagSizer(5,5) |
---|
381 | boxsizer1.Add( self.sizer4_4 ) |
---|
382 | #----------------------------------------------------- |
---|
383 | self.sizer4.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
384 | self.sizer4_4.Layout() |
---|
385 | self.sizer4.Layout() |
---|
386 | self.Layout() |
---|
387 | self.SetScrollbars(20,20,25,65) |
---|
388 | self.Refresh() |
---|
389 | ## saving the state of enable dispersity button |
---|
390 | self.state.enable_disp= self.enable_disp.GetValue() |
---|
391 | self.state.disable_disp= self.disable_disp.GetValue() |
---|
392 | |
---|
393 | |
---|
394 | def select_disp_angle(self, event): |
---|
395 | """ |
---|
396 | Event for when a user select a parameter to average over. |
---|
397 | |
---|
398 | :param event: radiobutton event |
---|
399 | """ |
---|
400 | self.values=[] |
---|
401 | self.weights=[] |
---|
402 | if event.GetEventObject()==self.noDisper_rbox: |
---|
403 | if self.noDisper_rbox.GetValue(): |
---|
404 | #No array dispersity apply yet |
---|
405 | self._reset_dispersity() |
---|
406 | ## Redraw the model ??? |
---|
407 | self._draw_model() |
---|
408 | # Go through the list of dispersion check boxes to identify which one has changed |
---|
409 | for p in self.disp_cb_dict: |
---|
410 | self.state.disp_cb_dict[p]= self.disp_cb_dict[p].GetValue() |
---|
411 | # Catch which one of the box was just checked or unchecked. |
---|
412 | if event.GetEventObject() == self.disp_cb_dict[p]: |
---|
413 | if self.disp_cb_dict[p].GetValue() == True: |
---|
414 | |
---|
415 | ##Temp. FIX for V1.0 regarding changing checkbox to radiobutton. |
---|
416 | ##This (self._reset_dispersity) should be removed when the array dispersion is fixed. |
---|
417 | self._reset_dispersity() |
---|
418 | |
---|
419 | # The user wants this parameter to be averaged. |
---|
420 | # Pop up the file selection dialog. |
---|
421 | path = self._selectDlg() |
---|
422 | |
---|
423 | # If nothing was selected, just return |
---|
424 | if path is None: |
---|
425 | self.disp_cb_dict[p].SetValue(False) |
---|
426 | self.noDisper_rbox.SetValue(True) |
---|
427 | return |
---|
428 | try: |
---|
429 | self._default_save_location = os.path.dirname(path) |
---|
430 | except: |
---|
431 | pass |
---|
432 | try: |
---|
433 | self.values,self.weights = self.read_file(path) |
---|
434 | except: |
---|
435 | msg="Could not read input file" |
---|
436 | wx.PostEvent(self.parent, StatusEvent(status= msg)) |
---|
437 | return |
---|
438 | |
---|
439 | # If any of the two arrays is empty, notify the user that we won't |
---|
440 | # proceed |
---|
441 | if self.values is None or self.weights is None or \ |
---|
442 | self.values ==[] or self.weights ==[]: |
---|
443 | wx.PostEvent(self.parent, StatusEvent(status=\ |
---|
444 | "The loaded %s distrubtion is corrupted or empty" % p)) |
---|
445 | return |
---|
446 | |
---|
447 | # Tell the user that we are about to apply the distribution |
---|
448 | wx.PostEvent(self.parent, StatusEvent(status=\ |
---|
449 | "Applying loaded %s distribution: %s" % (p, path))) |
---|
450 | |
---|
451 | # Create the dispersion objects |
---|
452 | from sans.models.dispersion_models import ArrayDispersion |
---|
453 | disp_model = ArrayDispersion() |
---|
454 | disp_model.set_weights(self.values, self.weights) |
---|
455 | |
---|
456 | # Store the object to make it persist outside the scope of this method |
---|
457 | #TODO: refactor model to clean this up? |
---|
458 | self._disp_obj_dict[p] = disp_model |
---|
459 | self.state._disp_obj_dict [p]= disp_model |
---|
460 | self.state.values=[] |
---|
461 | self.state.weights=[] |
---|
462 | self.state.values = copy.deepcopy(self.values) |
---|
463 | self.state.weights = copy.deepcopy(self.weights) |
---|
464 | # Set the new model as the dispersion object for the selected parameter |
---|
465 | self.model.set_dispersion(p, disp_model) |
---|
466 | # Store a reference to the weights in the model object so that |
---|
467 | # it's not lost when we use the model within another thread. |
---|
468 | #TODO: total hack - fix this |
---|
469 | self.state.model= self.model.clone() |
---|
470 | |
---|
471 | self.model._persistency_dict = {} |
---|
472 | self.model._persistency_dict[p] = [self.values, self.weights] |
---|
473 | self.state.model._persistency_dict[p] = [self.values, self.weights] |
---|
474 | else: |
---|
475 | self._reset_dispersity() |
---|
476 | |
---|
477 | ## Redraw the model |
---|
478 | self._draw_model() |
---|
479 | |
---|
480 | ## post state to fit panel |
---|
481 | event = PageInfoEvent(page = self) |
---|
482 | wx.PostEvent(self.parent, event) |
---|
483 | |
---|
484 | def onResetModel(self, event): |
---|
485 | """ |
---|
486 | Reset model state |
---|
487 | |
---|
488 | """ |
---|
489 | ## post help message for the selected model |
---|
490 | msg = self.popUpMenu.GetHelpString(event.GetId()) |
---|
491 | msg +=" reloaded" |
---|
492 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
493 | |
---|
494 | name= self.popUpMenu.GetLabel(event.GetId()) |
---|
495 | self._on_select_model_helper() |
---|
496 | |
---|
497 | if name in self.saved_states.keys(): |
---|
498 | previous_state = self.saved_states[name] |
---|
499 | ## reset state of checkbox,textcrtl and regular parameters value |
---|
500 | self.reset_page(previous_state) |
---|
501 | |
---|
502 | |
---|
503 | def onSave(self, event): |
---|
504 | """ |
---|
505 | save history of the data and model |
---|
506 | |
---|
507 | """ |
---|
508 | if self.model==None: |
---|
509 | return |
---|
510 | self.save_current_state() |
---|
511 | """ |
---|
512 | if hasattr(self,"enable_disp"): |
---|
513 | self.state.enable_disp = copy.deepcopy(self.enable_disp.GetValue()) |
---|
514 | if hasattr(self, "disp_box"): |
---|
515 | self.state.disp_box = copy.deepcopy(self.disp_box.GetSelection()) |
---|
516 | |
---|
517 | self.state.model.name= self.model.name |
---|
518 | """ |
---|
519 | new_state = self.state.clone() |
---|
520 | new_state.model.name = self.state.model.name |
---|
521 | |
---|
522 | new_state.enable2D = copy.deepcopy(self.enable2D) |
---|
523 | ##Add model state on context menu |
---|
524 | self.number_saved_state += 1 |
---|
525 | #name= self.model.name+"[%g]"%self.number_saved_state |
---|
526 | name= self.model.__class__.__name__+"[%g]"%self.number_saved_state |
---|
527 | self.saved_states[name]= new_state |
---|
528 | |
---|
529 | ## Add item in the context menu |
---|
530 | |
---|
531 | year, month, day,hour,minute,second,tda,ty,tm_isdst= time.localtime() |
---|
532 | my_time= str(hour)+" : "+str(minute)+" : "+str(second)+" " |
---|
533 | date= str( month)+"|"+str(day)+"|"+str(year) |
---|
534 | msg= "Model saved at %s on %s"%(my_time, date) |
---|
535 | ## post help message for the selected model |
---|
536 | msg +=" Saved! right click on this page to retrieve this model" |
---|
537 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
538 | |
---|
539 | id = wx.NewId() |
---|
540 | self.popUpMenu.Append(id,name,str(msg)) |
---|
541 | wx.EVT_MENU(self, id, self.onResetModel) |
---|
542 | |
---|
543 | def onSetFocus(self, evt): |
---|
544 | """ |
---|
545 | highlight the current textcrtl and hide the error text control shown |
---|
546 | after fitting |
---|
547 | :Not implemented. |
---|
548 | """ |
---|
549 | return |
---|
550 | |
---|
551 | def read_file(self, path): |
---|
552 | """ |
---|
553 | Read two columns file |
---|
554 | |
---|
555 | :param path: the path to the file to read |
---|
556 | """ |
---|
557 | try: |
---|
558 | if path==None: |
---|
559 | wx.PostEvent(self.parent, StatusEvent(status=\ |
---|
560 | " Selected Distribution was not loaded: %s"%path)) |
---|
561 | return None, None |
---|
562 | input_f = open(path, 'r') |
---|
563 | buff = input_f.read() |
---|
564 | lines = buff.split('\n') |
---|
565 | |
---|
566 | angles = [] |
---|
567 | weights=[] |
---|
568 | for line in lines: |
---|
569 | toks = line.split() |
---|
570 | try: |
---|
571 | angle = float(toks[0]) |
---|
572 | weight = float(toks[1]) |
---|
573 | except: |
---|
574 | # Skip non-data lines |
---|
575 | pass |
---|
576 | angles.append(angle) |
---|
577 | weights.append(weight) |
---|
578 | return numpy.array(angles), numpy.array(weights) |
---|
579 | except: |
---|
580 | raise |
---|
581 | |
---|
582 | |
---|
583 | def createMemento(self): |
---|
584 | """ |
---|
585 | return the current state of the page |
---|
586 | """ |
---|
587 | return self.state.clone() |
---|
588 | |
---|
589 | |
---|
590 | def save_current_state(self): |
---|
591 | """ |
---|
592 | Store current state |
---|
593 | |
---|
594 | """ |
---|
595 | ## save model option |
---|
596 | if self.model!= None: |
---|
597 | self.disp_list= self.model.getDispParamList() |
---|
598 | self.state.disp_list= copy.deepcopy(self.disp_list) |
---|
599 | self.state.model = self.model.clone() |
---|
600 | |
---|
601 | self.state.enable2D = copy.deepcopy(self.enable2D) |
---|
602 | self.state.values= copy.deepcopy(self.values) |
---|
603 | self.state.weights = copy.deepcopy( self.weights) |
---|
604 | ## save data |
---|
605 | self.state.data= copy.deepcopy(self.data) |
---|
606 | try: |
---|
607 | n = self.disp_box.GetCurrentSelection() |
---|
608 | dispersity= self.disp_box.GetClientData(n) |
---|
609 | name= dispersity.__name__ |
---|
610 | self.disp_name = name |
---|
611 | if name == "GaussianDispersion" : |
---|
612 | if hasattr(self,"cb1"): |
---|
613 | self.state.cb1= self.cb1.GetValue() |
---|
614 | except: |
---|
615 | pass |
---|
616 | |
---|
617 | if hasattr(self,"enable_disp"): |
---|
618 | self.state.enable_disp= self.enable_disp.GetValue() |
---|
619 | self.state.disable_disp = self.disable_disp.GetValue() |
---|
620 | |
---|
621 | self.state.smearer = copy.deepcopy(self.smearer) |
---|
622 | if hasattr(self,"enable_smearer"): |
---|
623 | self.state.enable_smearer = copy.deepcopy(self.enable_smearer.GetValue()) |
---|
624 | self.state.disable_smearer = copy.deepcopy(self.disable_smearer.GetValue()) |
---|
625 | |
---|
626 | if hasattr(self,"disp_box"): |
---|
627 | self.state.disp_box = self.disp_box.GetCurrentSelection() |
---|
628 | |
---|
629 | if len(self.disp_cb_dict)>0: |
---|
630 | for k , v in self.disp_cb_dict.iteritems(): |
---|
631 | |
---|
632 | if v ==None : |
---|
633 | self.state.disp_cb_dict[k]= v |
---|
634 | else: |
---|
635 | try: |
---|
636 | self.state.disp_cb_dict[k]=v.GetValue() |
---|
637 | except: |
---|
638 | self.state.disp_cb_dict[k]= None |
---|
639 | |
---|
640 | if len(self._disp_obj_dict)>0: |
---|
641 | for k , v in self._disp_obj_dict.iteritems(): |
---|
642 | |
---|
643 | self.state._disp_obj_dict[k]= v |
---|
644 | |
---|
645 | |
---|
646 | self.state.values = copy.deepcopy(self.values) |
---|
647 | self.state.weights = copy.deepcopy(self.weights) |
---|
648 | ## save plotting range |
---|
649 | self._save_plotting_range() |
---|
650 | |
---|
651 | self.state.orientation_params =[] |
---|
652 | self.state.orientation_params_disp =[] |
---|
653 | self.state.parameters =[] |
---|
654 | self.state.fittable_param =[] |
---|
655 | self.state.fixed_param =[] |
---|
656 | |
---|
657 | |
---|
658 | ## save checkbutton state and txtcrtl values |
---|
659 | self._copy_parameters_state(self.orientation_params, |
---|
660 | self.state.orientation_params) |
---|
661 | self._copy_parameters_state(self.orientation_params_disp, |
---|
662 | self.state.orientation_params_disp) |
---|
663 | |
---|
664 | self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
665 | self._copy_parameters_state(self.fittable_param, self.state.fittable_param) |
---|
666 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
667 | |
---|
668 | def reset_page_helper(self, state): |
---|
669 | """ |
---|
670 | Use page_state and change the state of existing page |
---|
671 | |
---|
672 | :precondition: the page is already drawn or created |
---|
673 | |
---|
674 | :postcondition: the state of the underlying data change as well as the |
---|
675 | state of the graphic interface |
---|
676 | """ |
---|
677 | if state ==None: |
---|
678 | #self._undo.Enable(False) |
---|
679 | return |
---|
680 | |
---|
681 | self.model= state.model |
---|
682 | self.data = state.data |
---|
683 | if self.data !=None: |
---|
684 | from DataLoader.qsmearing import smear_selection |
---|
685 | self.smearer= smear_selection( self.data ) |
---|
686 | self.enable2D= state.enable2D |
---|
687 | self.engine_type = state.engine_type |
---|
688 | |
---|
689 | self.disp_cb_dict = state.disp_cb_dict |
---|
690 | self.disp_list = state.disp_list |
---|
691 | |
---|
692 | ## set the state of the radio box |
---|
693 | self.shape_rbutton.SetValue(state.shape_rbutton ) |
---|
694 | self.shape_indep_rbutton.SetValue(state.shape_indep_rbutton) |
---|
695 | self.struct_rbutton.SetValue(state.struct_rbutton ) |
---|
696 | self.plugin_rbutton.SetValue(state.plugin_rbutton) |
---|
697 | ##draw sizer containing model parameters value for the current model |
---|
698 | self._set_model_sizer_selection( self.model ) |
---|
699 | self.set_model_param_sizer(self.model) |
---|
700 | |
---|
701 | ## reset value of combox box |
---|
702 | self.structurebox.SetSelection(state.structurecombobox ) |
---|
703 | self.formfactorbox.SetSelection(state.formfactorcombobox) |
---|
704 | if state.multi_factor != None: |
---|
705 | self.multifactorbox.SetSelection(state.multi_factor) |
---|
706 | #draw the pnael according to the new model parameter |
---|
707 | self._on_select_model(event=None) |
---|
708 | |
---|
709 | ## enable the view 2d button if this is a modelpage type |
---|
710 | if hasattr(self,"model_view"): |
---|
711 | if self.enable2D: |
---|
712 | self.model_view.Disable() |
---|
713 | else: |
---|
714 | self.model_view.Enable() |
---|
715 | ## set the select all check box to the a given state |
---|
716 | if hasattr(self, "cb1"): |
---|
717 | self.cb1.SetValue(state.cb1) |
---|
718 | |
---|
719 | ## reset state of checkbox,textcrtl and regular parameters value |
---|
720 | |
---|
721 | self._reset_parameters_state(self.orientation_params_disp, |
---|
722 | state.orientation_params_disp) |
---|
723 | self._reset_parameters_state(self.orientation_params, |
---|
724 | state.orientation_params) |
---|
725 | self._reset_parameters_state(self.str_parameters, |
---|
726 | state.str_parameters) |
---|
727 | self._reset_parameters_state(self.parameters,state.parameters) |
---|
728 | ## display dispersion info layer |
---|
729 | self.enable_disp.SetValue(state.enable_disp) |
---|
730 | self.disable_disp.SetValue(state.disable_disp) |
---|
731 | |
---|
732 | if hasattr(self, "disp_box"): |
---|
733 | |
---|
734 | self.disp_box.SetSelection(state.disp_box) |
---|
735 | n= self.disp_box.GetCurrentSelection() |
---|
736 | dispersity= self.disp_box.GetClientData(n) |
---|
737 | name= dispersity.__name__ |
---|
738 | |
---|
739 | self._set_dipers_Param(event=None) |
---|
740 | |
---|
741 | if name=="ArrayDispersion": |
---|
742 | |
---|
743 | for item in self.disp_cb_dict.keys(): |
---|
744 | |
---|
745 | if hasattr(self.disp_cb_dict[item],"SetValue") : |
---|
746 | self.disp_cb_dict[item].SetValue(state.disp_cb_dict[item]) |
---|
747 | # Create the dispersion objects |
---|
748 | from sans.models.dispersion_models import ArrayDispersion |
---|
749 | disp_model = ArrayDispersion() |
---|
750 | if hasattr(state,"values")and self.disp_cb_dict[item].GetValue()==True: |
---|
751 | if len(state.values)>0: |
---|
752 | self.values=state.values |
---|
753 | self.weights=state.weights |
---|
754 | disp_model.set_weights(self.values, state.weights) |
---|
755 | else: |
---|
756 | self._reset_dispersity() |
---|
757 | |
---|
758 | self._disp_obj_dict[item] = disp_model |
---|
759 | # Set the new model as the dispersion object for the selected parameter |
---|
760 | self.model.set_dispersion(item, disp_model) |
---|
761 | |
---|
762 | self.model._persistency_dict[item] = [state.values, state.weights] |
---|
763 | |
---|
764 | else: |
---|
765 | keys = self.model.getParamList() |
---|
766 | for item in keys: |
---|
767 | if item in self.disp_list and not self.model.details.has_key(item): |
---|
768 | self.model.details[item]=["",None,None] |
---|
769 | for k,v in self.state.disp_cb_dict.iteritems(): |
---|
770 | self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) |
---|
771 | self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) |
---|
772 | |
---|
773 | ##plotting range restore |
---|
774 | self._reset_plotting_range(state) |
---|
775 | |
---|
776 | ## smearing info restore |
---|
777 | if hasattr(self,"enable_smearer"): |
---|
778 | ## set smearing value whether or not the data contain the smearing info |
---|
779 | self.enable_smearer.SetValue(state.enable_smearer) |
---|
780 | self.disable_smearer.SetValue(state.disable_smearer) |
---|
781 | self.onSmear(event=None) |
---|
782 | |
---|
783 | ## reset state of checkbox,textcrtl and dispersity parameters value |
---|
784 | self._reset_parameters_state(self.fittable_param,state.fittable_param) |
---|
785 | self._reset_parameters_state(self.fixed_param,state.fixed_param) |
---|
786 | |
---|
787 | ## draw the model with previous parameters value |
---|
788 | self._onparamEnter_helper() |
---|
789 | |
---|
790 | ## reset context menu items |
---|
791 | self._reset_context_menu() |
---|
792 | ## set the value of the current state to the state given as parameter |
---|
793 | self.state = state.clone() |
---|
794 | self._draw_model() |
---|
795 | |
---|
796 | def _selectDlg(self): |
---|
797 | """ |
---|
798 | open a dialog file to selected the customized dispersity |
---|
799 | |
---|
800 | """ |
---|
801 | import os |
---|
802 | dlg = wx.FileDialog(self, "Choose a weight file", |
---|
803 | self._default_save_location , "", "*.*", wx.OPEN) |
---|
804 | path = None |
---|
805 | if dlg.ShowModal() == wx.ID_OK: |
---|
806 | path = dlg.GetPath() |
---|
807 | dlg.Destroy() |
---|
808 | return path |
---|
809 | |
---|
810 | def _reset_context_menu(self): |
---|
811 | """ |
---|
812 | reset the context menu |
---|
813 | |
---|
814 | """ |
---|
815 | for name, state in self.state.saved_states.iteritems(): |
---|
816 | self.number_saved_state += 1 |
---|
817 | ## Add item in the context menu |
---|
818 | id = wx.NewId() |
---|
819 | self.popUpMenu.Append(id,name, 'Save model and state %g'%self.number_saved_state) |
---|
820 | wx.EVT_MENU(self, id, self.onResetModel) |
---|
821 | |
---|
822 | |
---|
823 | def _reset_plotting_range(self, state): |
---|
824 | """ |
---|
825 | Reset the plotting range to a given state |
---|
826 | |
---|
827 | """ |
---|
828 | self.qmin.SetValue(str(state.qmin)) |
---|
829 | self.qmax.SetValue(str(state.qmax)) |
---|
830 | if self.state.npts!=None: |
---|
831 | self.npts.SetValue(str(state.npts)) |
---|
832 | |
---|
833 | |
---|
834 | def _save_typeOfmodel(self): |
---|
835 | """ |
---|
836 | save radiobutton containing the type model that can be selected |
---|
837 | |
---|
838 | """ |
---|
839 | self.state.shape_rbutton = self.shape_rbutton.GetValue() |
---|
840 | self.state.shape_indep_rbutton = self.shape_indep_rbutton.GetValue() |
---|
841 | self.state.struct_rbutton = self.struct_rbutton.GetValue() |
---|
842 | self.state.plugin_rbutton = self.plugin_rbutton.GetValue() |
---|
843 | self.state.structurebox= self.structurebox.GetCurrentSelection() |
---|
844 | self.state.formfactorbox = self.formfactorbox.GetCurrentSelection() |
---|
845 | |
---|
846 | #self._undo.Enable(True) |
---|
847 | ## post state to fit panel |
---|
848 | event = PageInfoEvent(page = self) |
---|
849 | wx.PostEvent(self.parent, event) |
---|
850 | |
---|
851 | |
---|
852 | def _save_plotting_range(self ): |
---|
853 | """ |
---|
854 | save the state of plotting range |
---|
855 | |
---|
856 | """ |
---|
857 | self.state.qmin = self.qmin_x |
---|
858 | self.state.qmax = self.qmax_x |
---|
859 | if self.npts!=None: |
---|
860 | self.state.npts= self.num_points |
---|
861 | |
---|
862 | |
---|
863 | def _onparamEnter_helper(self): |
---|
864 | """ |
---|
865 | check if values entered by the user are changed and valid to replot |
---|
866 | model |
---|
867 | use : _check_value_enter |
---|
868 | |
---|
869 | """ |
---|
870 | # Flag to register when a parameter has changed. |
---|
871 | is_modified = False |
---|
872 | #self._undo.Enable(True) |
---|
873 | if self.model !=None: |
---|
874 | try: |
---|
875 | is_modified =self._check_value_enter( self.fittable_param ,is_modified) |
---|
876 | is_modified =self._check_value_enter( self.fixed_param ,is_modified) |
---|
877 | is_modified =self._check_value_enter( self.parameters ,is_modified) |
---|
878 | except: |
---|
879 | pass |
---|
880 | #if is_modified: |
---|
881 | # Here we should check whether the boundaries have been modified. |
---|
882 | # If qmin and qmax have been modified, update qmin and qmax and |
---|
883 | # set the is_modified flag to True |
---|
884 | if self._validate_qrange(self.qmin, self.qmax): |
---|
885 | tempmin = float(self.qmin.GetValue()) |
---|
886 | if tempmin != self.qmin_x: |
---|
887 | self.qmin_x = tempmin |
---|
888 | is_modified = True |
---|
889 | tempmax = float(self.qmax.GetValue()) |
---|
890 | if tempmax != self.qmax_x: |
---|
891 | self.qmax_x = tempmax |
---|
892 | is_modified = True |
---|
893 | self.fitrange = True |
---|
894 | else: |
---|
895 | self.fitrange = False |
---|
896 | if self.npts != None: |
---|
897 | if check_float(self.npts): |
---|
898 | temp_npts = float(self.npts.GetValue()) |
---|
899 | if temp_npts != self.num_points: |
---|
900 | self.num_points = temp_npts |
---|
901 | is_modified = True |
---|
902 | else: |
---|
903 | msg= "Cannot Plot :Must enter a number!!! " |
---|
904 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
905 | |
---|
906 | |
---|
907 | ## if any value is modify draw model with new value |
---|
908 | if is_modified: |
---|
909 | self.state_change= True |
---|
910 | self._draw_model() |
---|
911 | self.Refresh() |
---|
912 | return is_modified |
---|
913 | |
---|
914 | |
---|
915 | def _is_modified(self, is_modified): |
---|
916 | """ |
---|
917 | return to self._is_modified |
---|
918 | |
---|
919 | """ |
---|
920 | return is_modified |
---|
921 | |
---|
922 | def _reset_parameters_state(self, listtorestore,statelist): |
---|
923 | """ |
---|
924 | Reset the parameters at the given state |
---|
925 | |
---|
926 | """ |
---|
927 | if len(statelist)==0 or len(listtorestore)==0 : |
---|
928 | return |
---|
929 | if len(statelist)!= len(listtorestore) : |
---|
930 | return |
---|
931 | |
---|
932 | for j in range(len(listtorestore)): |
---|
933 | item_page = listtorestore[j] |
---|
934 | item_page_info = statelist[j] |
---|
935 | ##change the state of the check box for simple parameters |
---|
936 | if item_page[0]!=None: |
---|
937 | item_page[0].SetValue(item_page_info[0]) |
---|
938 | |
---|
939 | if item_page[2]!=None: |
---|
940 | item_page[2].SetValue(item_page_info[2]) |
---|
941 | |
---|
942 | if item_page[3]!=None: |
---|
943 | ## show or hide text +/- |
---|
944 | if item_page_info[2]: |
---|
945 | item_page[3].Show(True) |
---|
946 | else: |
---|
947 | item_page[3].Hide() |
---|
948 | if item_page[4]!=None: |
---|
949 | ## show of hide the text crtl for fitting error |
---|
950 | if item_page_info[4][0]: |
---|
951 | item_page[4].Show(True) |
---|
952 | item_page[4].SetValue(item_page_info[4][1]) |
---|
953 | else: |
---|
954 | item_page[3].Hide() |
---|
955 | if item_page[5]!=None: |
---|
956 | ## show of hide the text crtl for fitting error |
---|
957 | if item_page_info[5][0]: |
---|
958 | item_page[5].Show(True) |
---|
959 | item_page[5].SetValue(item_page_info[5][1]) |
---|
960 | else: |
---|
961 | item_page[5].Hide() |
---|
962 | |
---|
963 | if item_page[6]!=None: |
---|
964 | ## show of hide the text crtl for fitting error |
---|
965 | if item_page_info[6][0]: |
---|
966 | item_page[6].Show(True) |
---|
967 | item_page[6].SetValue(item_page_info[6][1]) |
---|
968 | else: |
---|
969 | item_page[6].Hide() |
---|
970 | |
---|
971 | def _copy_parameters_state(self, listtocopy, statelist): |
---|
972 | """ |
---|
973 | copy the state of button |
---|
974 | |
---|
975 | :param listtocopy: the list of widgets 's state to copy |
---|
976 | :param statelist: container for the state of widgets that must be copied |
---|
977 | |
---|
978 | """ |
---|
979 | if len(listtocopy)==0: |
---|
980 | return |
---|
981 | |
---|
982 | for item in listtocopy: |
---|
983 | |
---|
984 | checkbox_state = None |
---|
985 | if item[0]!= None: |
---|
986 | checkbox_state= item[0].GetValue() |
---|
987 | parameter_name = item[1] |
---|
988 | parameter_value = None |
---|
989 | if item[2]!=None: |
---|
990 | parameter_value = item[2].GetValue() |
---|
991 | static_text = None |
---|
992 | if item[3]!=None: |
---|
993 | static_text = item[3].IsShown() |
---|
994 | error_value = None |
---|
995 | error_state = None |
---|
996 | if item[4]!= None: |
---|
997 | error_value = item[4].GetValue() |
---|
998 | error_state = item[4].IsShown() |
---|
999 | |
---|
1000 | min_value = None |
---|
1001 | min_state = None |
---|
1002 | if item[5]!= None: |
---|
1003 | min_value = item[5].GetValue() |
---|
1004 | min_state = item[5].IsShown() |
---|
1005 | |
---|
1006 | max_value = None |
---|
1007 | max_state = None |
---|
1008 | if item[6]!= None: |
---|
1009 | max_value = item[6].GetValue() |
---|
1010 | max_state = item[6].IsShown() |
---|
1011 | unit=None |
---|
1012 | if item[7]!=None: |
---|
1013 | unit = item[7].GetLabel() |
---|
1014 | |
---|
1015 | statelist.append([checkbox_state, parameter_name, parameter_value, |
---|
1016 | static_text ,[error_state,error_value], |
---|
1017 | [min_state,min_value],[max_state , max_value],unit]) |
---|
1018 | |
---|
1019 | def _set_model_sizer_selection(self, model): |
---|
1020 | """ |
---|
1021 | Display the sizer according to the type of the current model |
---|
1022 | |
---|
1023 | """ |
---|
1024 | if model ==None: |
---|
1025 | return |
---|
1026 | if hasattr(model ,"s_model"): |
---|
1027 | |
---|
1028 | class_name= model.s_model.__class__ |
---|
1029 | name= model.s_model.name |
---|
1030 | flag= name != "NoStructure" |
---|
1031 | if flag and (class_name in self.model_list_box["Structure Factors"]): |
---|
1032 | self.structurebox.Show() |
---|
1033 | self.text2.Show() |
---|
1034 | self.structurebox.Enable() |
---|
1035 | self.text2.Enable() |
---|
1036 | items = self.structurebox.GetItems() |
---|
1037 | self.sizer1.Layout() |
---|
1038 | self.SetScrollbars(20,20,25,65) |
---|
1039 | for i in range(len(items)): |
---|
1040 | if items[i]== str(name): |
---|
1041 | self.structurebox.SetSelection(i) |
---|
1042 | break |
---|
1043 | |
---|
1044 | if hasattr(model ,"p_model"): |
---|
1045 | class_name = model.p_model.__class__ |
---|
1046 | name = model.p_model.name |
---|
1047 | self.formfactorbox.Clear() |
---|
1048 | |
---|
1049 | for k, list in self.model_list_box.iteritems(): |
---|
1050 | if k in["P(Q)*S(Q)","Shapes" ] and class_name in self.model_list_box["Shapes"]: |
---|
1051 | self.shape_rbutton.SetValue(True) |
---|
1052 | ## fill the form factor list with new model |
---|
1053 | self._populate_box(self.formfactorbox,self.model_list_box["Shapes"]) |
---|
1054 | items = self.formfactorbox.GetItems() |
---|
1055 | ## set comboxbox to the selected item |
---|
1056 | for i in range(len(items)): |
---|
1057 | if items[i]== str(name): |
---|
1058 | self.formfactorbox.SetSelection(i) |
---|
1059 | break |
---|
1060 | return |
---|
1061 | elif k == "Shape-Independent": |
---|
1062 | self.shape_indep_rbutton.SetValue(True) |
---|
1063 | elif k == "Structure Factors": |
---|
1064 | self.struct_rbutton.SetValue(True) |
---|
1065 | elif k == "Multi-Functions": |
---|
1066 | continue |
---|
1067 | else: |
---|
1068 | self.plugin_rbutton.SetValue(True) |
---|
1069 | |
---|
1070 | if class_name in list: |
---|
1071 | ## fill the form factor list with new model |
---|
1072 | self._populate_box(self.formfactorbox, list) |
---|
1073 | items = self.formfactorbox.GetItems() |
---|
1074 | ## set comboxbox to the selected item |
---|
1075 | for i in range(len(items)): |
---|
1076 | if items[i]== str(name): |
---|
1077 | self.formfactorbox.SetSelection(i) |
---|
1078 | break |
---|
1079 | break |
---|
1080 | else: |
---|
1081 | |
---|
1082 | ## Select the model from the menu |
---|
1083 | class_name = model.__class__ |
---|
1084 | name = model.name |
---|
1085 | self.formfactorbox.Clear() |
---|
1086 | items = self.formfactorbox.GetItems() |
---|
1087 | |
---|
1088 | for k, list in self.model_list_box.iteritems(): |
---|
1089 | if k in["P(Q)*S(Q)","Shapes" ] and class_name in self.model_list_box["Shapes"]: |
---|
1090 | if class_name in self.model_list_box["P(Q)*S(Q)"]: |
---|
1091 | self.structurebox.Show() |
---|
1092 | self.text2.Show() |
---|
1093 | self.structurebox.Enable() |
---|
1094 | self.structurebox.SetSelection(0) |
---|
1095 | self.text2.Enable() |
---|
1096 | else: |
---|
1097 | self.structurebox.Hide() |
---|
1098 | self.text2.Hide() |
---|
1099 | self.structurebox.Disable() |
---|
1100 | self.structurebox.SetSelection(0) |
---|
1101 | self.text2.Disable() |
---|
1102 | |
---|
1103 | self.shape_rbutton.SetValue(True) |
---|
1104 | ## fill the form factor list with new model |
---|
1105 | self._populate_box(self.formfactorbox,self.model_list_box["Shapes"]) |
---|
1106 | items = self.formfactorbox.GetItems() |
---|
1107 | ## set comboxbox to the selected item |
---|
1108 | for i in range(len(items)): |
---|
1109 | if items[i]== str(name): |
---|
1110 | self.formfactorbox.SetSelection(i) |
---|
1111 | break |
---|
1112 | return |
---|
1113 | elif k == "Shape-Independent": |
---|
1114 | self.shape_indep_rbutton.SetValue(True) |
---|
1115 | elif k == "Structure Factors": |
---|
1116 | self.struct_rbutton.SetValue(True) |
---|
1117 | elif k == "Multi-Functions": |
---|
1118 | continue |
---|
1119 | else: |
---|
1120 | self.plugin_rbutton.SetValue(True) |
---|
1121 | if class_name in list: |
---|
1122 | self.structurebox.SetSelection(0) |
---|
1123 | self.structurebox.Disable() |
---|
1124 | self.text2.Disable() |
---|
1125 | ## fill the form factor list with new model |
---|
1126 | self._populate_box(self.formfactorbox, list) |
---|
1127 | items = self.formfactorbox.GetItems() |
---|
1128 | ## set comboxbox to the selected item |
---|
1129 | for i in range(len(items)): |
---|
1130 | if items[i]== str(name): |
---|
1131 | self.formfactorbox.SetSelection(i) |
---|
1132 | break |
---|
1133 | break |
---|
1134 | |
---|
1135 | def _draw_model(self): |
---|
1136 | """ |
---|
1137 | Method to draw or refresh a plotted model. |
---|
1138 | The method will use the data member from the model page |
---|
1139 | to build a call to the fitting perspective manager. |
---|
1140 | |
---|
1141 | :Note to coder: This way future changes will be done in only one place. |
---|
1142 | |
---|
1143 | """ |
---|
1144 | if self.model !=None: |
---|
1145 | temp_smear=None |
---|
1146 | if hasattr(self, "enable_smearer"): |
---|
1147 | if self.enable_smearer.GetValue(): |
---|
1148 | temp_smear= self.smearer |
---|
1149 | |
---|
1150 | self.manager.draw_model(self.model, data=self.data, |
---|
1151 | smearer= temp_smear, |
---|
1152 | qmin=float(self.qmin_x), |
---|
1153 | qmax=float(self.qmax_x), |
---|
1154 | qstep= float(self.num_points), |
---|
1155 | enable2D=self.enable2D) |
---|
1156 | |
---|
1157 | def _set_model_sizer(self,sizer, box_sizer, title="", object=None): |
---|
1158 | """ |
---|
1159 | Use lists to fill a sizer for model info |
---|
1160 | |
---|
1161 | """ |
---|
1162 | |
---|
1163 | sizer.Clear(True) |
---|
1164 | ##For MAC, this should defined here. |
---|
1165 | if box_sizer == None: |
---|
1166 | box_description= wx.StaticBox(self, -1,str(title)) |
---|
1167 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
1168 | else: |
---|
1169 | boxsizer1 = box_sizer |
---|
1170 | sizer_buttons = wx.BoxSizer(wx.HORIZONTAL) |
---|
1171 | #-------------------------------------------------------- |
---|
1172 | self.shape_rbutton = wx.RadioButton(self, -1, 'Shapes', style=wx.RB_GROUP) |
---|
1173 | self.shape_indep_rbutton = wx.RadioButton(self, -1, "Shape-Independent") |
---|
1174 | self.struct_rbutton = wx.RadioButton(self, -1, "Structure Factor ") |
---|
1175 | self.plugin_rbutton = wx.RadioButton(self, -1, "Customized Models") |
---|
1176 | |
---|
1177 | self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, |
---|
1178 | id= self.shape_rbutton.GetId() ) |
---|
1179 | self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, |
---|
1180 | id= self.shape_indep_rbutton.GetId() ) |
---|
1181 | self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, |
---|
1182 | id= self.struct_rbutton.GetId() ) |
---|
1183 | self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, |
---|
1184 | id= self.plugin_rbutton.GetId() ) |
---|
1185 | #MAC needs SetValue |
---|
1186 | self.shape_rbutton.SetValue(True) |
---|
1187 | |
---|
1188 | sizer_radiobutton = wx.GridSizer(2, 2,5, 5) |
---|
1189 | sizer_radiobutton.Add(self.shape_rbutton) |
---|
1190 | sizer_radiobutton.Add(self.shape_indep_rbutton) |
---|
1191 | sizer_radiobutton.Add(self.plugin_rbutton) |
---|
1192 | sizer_radiobutton.Add(self.struct_rbutton) |
---|
1193 | |
---|
1194 | sizer_buttons.Add(sizer_radiobutton) |
---|
1195 | # detail button |
---|
1196 | if object !=None: |
---|
1197 | sizer_buttons.Add((50,0)) |
---|
1198 | sizer_buttons.Add(object) |
---|
1199 | |
---|
1200 | sizer_selection = wx.BoxSizer(wx.HORIZONTAL) |
---|
1201 | mutifactor_selection = wx.BoxSizer(wx.HORIZONTAL) |
---|
1202 | self.text1 = wx.StaticText( self,-1,"" ) |
---|
1203 | self.text2 = wx.StaticText( self,-1,"P(Q)*S(Q)" ) |
---|
1204 | self.mutifactor_text = wx.StaticText( self,-1,"No. of Shells: " ) |
---|
1205 | self.mutifactor_text1 = wx.StaticText( self,-1,"" ) |
---|
1206 | self.show_sld_button = wx.Button( self,-1,"Show SLD Profile" ) |
---|
1207 | self.show_sld_button.Bind(wx.EVT_BUTTON,self._on_show_sld) |
---|
1208 | self.formfactorbox = wx.ComboBox(self, -1,style=wx.CB_READONLY) |
---|
1209 | if self.model!=None: |
---|
1210 | self.formfactorbox.SetValue(self.model.name) |
---|
1211 | |
---|
1212 | |
---|
1213 | self.structurebox = wx.ComboBox(self, -1,style=wx.CB_READONLY) |
---|
1214 | self.multifactorbox = wx.ComboBox(self, -1,style=wx.CB_READONLY) |
---|
1215 | wx.EVT_COMBOBOX(self.formfactorbox,-1, self._on_select_model) |
---|
1216 | wx.EVT_COMBOBOX(self.structurebox,-1, self._on_select_model) |
---|
1217 | wx.EVT_COMBOBOX(self.multifactorbox,-1, self._on_select_model) |
---|
1218 | |
---|
1219 | ## fill combox box |
---|
1220 | if len(self.model_list_box)>0: |
---|
1221 | self._populate_box( self.formfactorbox,self.model_list_box["Shapes"]) |
---|
1222 | |
---|
1223 | if len(self.model_list_box)>0: |
---|
1224 | self._populate_box( self.structurebox, |
---|
1225 | self.model_list_box["Structure Factors"]) |
---|
1226 | self.structurebox.Insert("None", 0,None) |
---|
1227 | self.structurebox.SetSelection(0) |
---|
1228 | self.structurebox.Hide() |
---|
1229 | self.text2.Hide() |
---|
1230 | self.structurebox.Disable() |
---|
1231 | self.text2.Disable() |
---|
1232 | |
---|
1233 | if self.model.__class__ in self.model_list_box["P(Q)*S(Q)"]: |
---|
1234 | self.structurebox.Show() |
---|
1235 | self.text2.Show() |
---|
1236 | self.structurebox.Enable() |
---|
1237 | self.text2.Enable() |
---|
1238 | |
---|
1239 | ## check model type to show sizer |
---|
1240 | if self.model !=None: |
---|
1241 | self._set_model_sizer_selection( self.model ) |
---|
1242 | |
---|
1243 | sizer_selection.Add(self.text1) |
---|
1244 | sizer_selection.Add((5,5)) |
---|
1245 | sizer_selection.Add(self.formfactorbox) |
---|
1246 | sizer_selection.Add((5,5)) |
---|
1247 | sizer_selection.Add(self.text2) |
---|
1248 | sizer_selection.Add((5,5)) |
---|
1249 | sizer_selection.Add(self.structurebox) |
---|
1250 | #sizer_selection.Add((5,5)) |
---|
1251 | mutifactor_selection.Add((10,5)) |
---|
1252 | mutifactor_selection.Add(self.mutifactor_text) |
---|
1253 | mutifactor_selection.Add(self.multifactorbox) |
---|
1254 | mutifactor_selection.Add((5,5)) |
---|
1255 | mutifactor_selection.Add(self.mutifactor_text1) |
---|
1256 | mutifactor_selection.Add((10,5)) |
---|
1257 | mutifactor_selection.Add(self.show_sld_button) |
---|
1258 | |
---|
1259 | boxsizer1.Add( sizer_buttons ) |
---|
1260 | boxsizer1.Add( (15,15)) |
---|
1261 | boxsizer1.Add( sizer_selection ) |
---|
1262 | boxsizer1.Add( (10,10)) |
---|
1263 | boxsizer1.Add(mutifactor_selection) |
---|
1264 | |
---|
1265 | self._set_multfactor_combobox() |
---|
1266 | self.multifactorbox.SetSelection(1) |
---|
1267 | self.show_sld_button.Hide() |
---|
1268 | |
---|
1269 | #-------------------------------------------------------- |
---|
1270 | sizer.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
1271 | sizer.Layout() |
---|
1272 | self.SetScrollbars(20,20,25,65) |
---|
1273 | |
---|
1274 | def _on_show_sld(self, event=None): |
---|
1275 | """ |
---|
1276 | Plot SLD profile |
---|
1277 | """ |
---|
1278 | # get profile data |
---|
1279 | x,y=self.model.getProfile() |
---|
1280 | |
---|
1281 | from danse.common.plottools import Data1D |
---|
1282 | #from profile_dialog import SLDPanel |
---|
1283 | from sans.guiframe.local_perspectives.plotting.profile_dialog \ |
---|
1284 | import SLDPanel |
---|
1285 | sld_data = Data1D(x,y) |
---|
1286 | sld_data.name = 'SLD' |
---|
1287 | sld_data.axes = self.sld_axes |
---|
1288 | self.panel = SLDPanel(self, data=sld_data,axes =self.sld_axes,id =-1 ) |
---|
1289 | self.panel.ShowModal() |
---|
1290 | |
---|
1291 | def _set_multfactor_combobox(self, multiplicity=10): |
---|
1292 | """ |
---|
1293 | Set comboBox for muitfactor of CoreMultiShellModel |
---|
1294 | :param multiplicit: no. of multi-functionality |
---|
1295 | """ |
---|
1296 | # build content of the combobox |
---|
1297 | for idx in range(0,multiplicity): |
---|
1298 | self.multifactorbox.Append(str(idx),int(idx)) |
---|
1299 | #self.multifactorbox.SetSelection(1) |
---|
1300 | self._hide_multfactor_combobox() |
---|
1301 | |
---|
1302 | def _show_multfactor_combobox(self): |
---|
1303 | """ |
---|
1304 | Show the comboBox of muitfactor of CoreMultiShellModel |
---|
1305 | """ |
---|
1306 | if not self.mutifactor_text.IsShown(): |
---|
1307 | self.mutifactor_text.Show(True) |
---|
1308 | self.mutifactor_text1.Show(True) |
---|
1309 | if not self.multifactorbox.IsShown(): |
---|
1310 | self.multifactorbox.Show(True) |
---|
1311 | |
---|
1312 | def _hide_multfactor_combobox(self): |
---|
1313 | """ |
---|
1314 | Hide the comboBox of muitfactor of CoreMultiShellModel |
---|
1315 | """ |
---|
1316 | if self.mutifactor_text.IsShown(): |
---|
1317 | self.mutifactor_text.Hide() |
---|
1318 | self.mutifactor_text1.Hide() |
---|
1319 | if self.multifactorbox.IsShown(): |
---|
1320 | self.multifactorbox.Hide() |
---|
1321 | |
---|
1322 | |
---|
1323 | def _show_combox(self, event): |
---|
1324 | """ |
---|
1325 | Show combox box associate with type of model selected |
---|
1326 | |
---|
1327 | """ |
---|
1328 | ## Don't want to populate combo box again if the event comes from check box |
---|
1329 | if self.shape_rbutton.GetValue()and\ |
---|
1330 | event.GetEventObject()==self.shape_rbutton: |
---|
1331 | ##fill the combobox with form factor list |
---|
1332 | self.structurebox.SetSelection(0) |
---|
1333 | self.structurebox.Disable() |
---|
1334 | self.formfactorbox.Clear() |
---|
1335 | self._populate_box( self.formfactorbox,self.model_list_box["Shapes"]) |
---|
1336 | |
---|
1337 | if self.shape_indep_rbutton.GetValue()and\ |
---|
1338 | event.GetEventObject()==self.shape_indep_rbutton: |
---|
1339 | ##fill the combobox with shape independent factor list |
---|
1340 | self.structurebox.SetSelection(0) |
---|
1341 | self.structurebox.Disable() |
---|
1342 | self.formfactorbox.Clear() |
---|
1343 | self._populate_box( self.formfactorbox, |
---|
1344 | self.model_list_box["Shape-Independent"]) |
---|
1345 | |
---|
1346 | if self.struct_rbutton.GetValue() and\ |
---|
1347 | event.GetEventObject()==self.struct_rbutton: |
---|
1348 | ##fill the combobox with structure factor list |
---|
1349 | self.structurebox.SetSelection(0) |
---|
1350 | self.structurebox.Disable() |
---|
1351 | self.formfactorbox.Clear() |
---|
1352 | self._populate_box( self.formfactorbox, |
---|
1353 | self.model_list_box["Structure Factors"]) |
---|
1354 | |
---|
1355 | if self.plugin_rbutton.GetValue()and\ |
---|
1356 | event.GetEventObject()==self.plugin_rbutton: |
---|
1357 | |
---|
1358 | ##fill the combobox with form factor list |
---|
1359 | self.structurebox.Disable() |
---|
1360 | self.formfactorbox.Clear() |
---|
1361 | self._populate_box( self.formfactorbox, |
---|
1362 | self.model_list_box["Customized Models"]) |
---|
1363 | |
---|
1364 | self._on_select_model(event=None) |
---|
1365 | self._save_typeOfmodel() |
---|
1366 | self.sizer4_4.Layout() |
---|
1367 | self.sizer4.Layout() |
---|
1368 | self.Layout() |
---|
1369 | self.Refresh() |
---|
1370 | self.SetScrollbars(20,20,25,65) |
---|
1371 | |
---|
1372 | def _populate_box(self, combobox, list): |
---|
1373 | """ |
---|
1374 | fill combox box with dict item |
---|
1375 | |
---|
1376 | :param list: contains item to fill the combox |
---|
1377 | item must model class |
---|
1378 | """ |
---|
1379 | for models in list: |
---|
1380 | model= models() |
---|
1381 | name = model.__class__.__name__ |
---|
1382 | if models.__name__!="NoStructure": |
---|
1383 | if hasattr(model, "name"): |
---|
1384 | name = model.name |
---|
1385 | combobox.Append(name,models) |
---|
1386 | |
---|
1387 | return 0 |
---|
1388 | |
---|
1389 | def _onparamEnter(self,event): |
---|
1390 | """ |
---|
1391 | when enter value on panel redraw model according to changed |
---|
1392 | |
---|
1393 | """ |
---|
1394 | tcrtl= event.GetEventObject() |
---|
1395 | |
---|
1396 | #Clear msg if previously shown. |
---|
1397 | msg= "" |
---|
1398 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
1399 | |
---|
1400 | ## save current state |
---|
1401 | self.save_current_state() |
---|
1402 | if event !=None: |
---|
1403 | #self._undo.Enable(True) |
---|
1404 | event = PageInfoEvent(page = self) |
---|
1405 | wx.PostEvent(self.parent, event) |
---|
1406 | |
---|
1407 | if check_float(tcrtl): |
---|
1408 | |
---|
1409 | self._onparamEnter_helper() |
---|
1410 | #event.Skip() |
---|
1411 | else: |
---|
1412 | msg= "Cannot Plot :Must enter a number!!! " |
---|
1413 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
1414 | #event.Skip() |
---|
1415 | return |
---|
1416 | |
---|
1417 | def _onQrangeEnter(self, event): |
---|
1418 | """ |
---|
1419 | Check validity of value enter in the Q range field |
---|
1420 | |
---|
1421 | """ |
---|
1422 | |
---|
1423 | tcrtl= event.GetEventObject() |
---|
1424 | #Clear msg if previously shown. |
---|
1425 | msg= "" |
---|
1426 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
1427 | # Flag to register when a parameter has changed. |
---|
1428 | is_modified = False |
---|
1429 | if tcrtl.GetValue().lstrip().rstrip()!="": |
---|
1430 | try: |
---|
1431 | value = float(tcrtl.GetValue()) |
---|
1432 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
1433 | |
---|
1434 | # If qmin and qmax have been modified, update qmin and qmax |
---|
1435 | if self._validate_qrange( self.qmin, self.qmax): |
---|
1436 | tempmin = float(self.qmin.GetValue()) |
---|
1437 | if tempmin != self.qmin_x: |
---|
1438 | self.qmin_x = tempmin |
---|
1439 | tempmax = float(self.qmax.GetValue()) |
---|
1440 | if tempmax != self.qmax_x: |
---|
1441 | self.qmax_x = tempmax |
---|
1442 | else: |
---|
1443 | tcrtl.SetBackgroundColour("pink") |
---|
1444 | msg= "Model Error:wrong value entered : %s"% sys.exc_value |
---|
1445 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
1446 | return |
---|
1447 | |
---|
1448 | except: |
---|
1449 | tcrtl.SetBackgroundColour("pink") |
---|
1450 | msg= "Model Error:wrong value entered : %s"% sys.exc_value |
---|
1451 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
1452 | return |
---|
1453 | #Check if # of points for theory model are valid(>0). |
---|
1454 | if self.npts != None: |
---|
1455 | if check_float(self.npts): |
---|
1456 | temp_npts = float(self.npts.GetValue()) |
---|
1457 | if temp_npts != self.num_points: |
---|
1458 | self.num_points = temp_npts |
---|
1459 | is_modified = True |
---|
1460 | else: |
---|
1461 | msg= "Cannot Plot :No npts in that Qrange!!! " |
---|
1462 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
1463 | |
---|
1464 | else: |
---|
1465 | tcrtl.SetBackgroundColour("pink") |
---|
1466 | msg= "Model Error:wrong value entered!!!" |
---|
1467 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
1468 | |
---|
1469 | #self._undo.Enable(True) |
---|
1470 | self.save_current_state() |
---|
1471 | event = PageInfoEvent(page = self) |
---|
1472 | wx.PostEvent(self.parent, event) |
---|
1473 | self.state_change= False |
---|
1474 | #Draw the model for a different range |
---|
1475 | self._draw_model() |
---|
1476 | |
---|
1477 | def _on_select_model_helper(self): |
---|
1478 | """ |
---|
1479 | call back for model selection |
---|
1480 | |
---|
1481 | """ |
---|
1482 | ## reset dictionary containing reference to dispersion |
---|
1483 | self._disp_obj_dict = {} |
---|
1484 | self.disp_cb_dict ={} |
---|
1485 | |
---|
1486 | f_id = self.formfactorbox.GetCurrentSelection() |
---|
1487 | #For MAC |
---|
1488 | form_factor = None |
---|
1489 | if f_id >= 0: |
---|
1490 | form_factor = self.formfactorbox.GetClientData( f_id ) |
---|
1491 | |
---|
1492 | if not form_factor in self.model_list_box["multiplication"]: |
---|
1493 | self.structurebox.Hide() |
---|
1494 | self.text2.Hide() |
---|
1495 | self.structurebox.Disable() |
---|
1496 | self.structurebox.SetSelection(0) |
---|
1497 | self.text2.Disable() |
---|
1498 | else: |
---|
1499 | self.structurebox.Show() |
---|
1500 | self.text2.Show() |
---|
1501 | self.structurebox.Enable() |
---|
1502 | self.text2.Enable() |
---|
1503 | |
---|
1504 | if form_factor != None: |
---|
1505 | # set multifactor for Mutifunctional models |
---|
1506 | if form_factor().__class__ in self.model_list_box["Multi-Functions"]: |
---|
1507 | m_id = self.multifactorbox.GetCurrentSelection() |
---|
1508 | multiplicity = form_factor().multiplicity_info[0] |
---|
1509 | self.multifactorbox.Clear() |
---|
1510 | #self.mutifactor_text.SetLabel(form_factor().details[]) |
---|
1511 | self._set_multfactor_combobox(multiplicity) |
---|
1512 | self._show_multfactor_combobox() |
---|
1513 | text = form_factor().multiplicity_info[1]#'No. of Shells: ' |
---|
1514 | |
---|
1515 | #self.mutifactor_text.Clear() |
---|
1516 | self.mutifactor_text.SetLabel(text) |
---|
1517 | |
---|
1518 | # Check max value |
---|
1519 | if m_id > multiplicity -1: |
---|
1520 | # default value |
---|
1521 | m_id = 1 |
---|
1522 | self.multi_factor = self.multifactorbox.GetClientData(m_id) |
---|
1523 | if self.multi_factor == None: self.multi_factor =1 |
---|
1524 | form_factor = form_factor(int(self.multi_factor)) |
---|
1525 | self.multifactorbox.SetSelection(m_id) |
---|
1526 | # Check len of the text1 and max_multiplicity |
---|
1527 | text = '' |
---|
1528 | if form_factor.multiplicity_info[0] == len(form_factor.multiplicity_info[2]): |
---|
1529 | text = form_factor.multiplicity_info[2][self.multi_factor] |
---|
1530 | self.mutifactor_text1.SetLabel(text) |
---|
1531 | # Check if model has get sld profile. |
---|
1532 | if len(form_factor.multiplicity_info[3]) > 0: |
---|
1533 | self.sld_axes = form_factor.multiplicity_info[3] |
---|
1534 | self.show_sld_button.Show(True) |
---|
1535 | else: |
---|
1536 | self.sld_axes = "" |
---|
1537 | else: |
---|
1538 | self._hide_multfactor_combobox() |
---|
1539 | self.show_sld_button.Hide() |
---|
1540 | form_factor = form_factor() |
---|
1541 | self.multi_factor = None |
---|
1542 | else: |
---|
1543 | self._hide_multfactor_combobox() |
---|
1544 | self.show_sld_button.Hide() |
---|
1545 | self.multi_factor = None |
---|
1546 | |
---|
1547 | s_id = self.structurebox.GetCurrentSelection() |
---|
1548 | struct_factor = self.structurebox.GetClientData( s_id ) |
---|
1549 | |
---|
1550 | if struct_factor !=None: |
---|
1551 | from sans.models.MultiplicationModel import MultiplicationModel |
---|
1552 | self.model= MultiplicationModel(form_factor,struct_factor()) |
---|
1553 | |
---|
1554 | else: |
---|
1555 | if form_factor != None: |
---|
1556 | self.model= form_factor |
---|
1557 | else: |
---|
1558 | self.model = None |
---|
1559 | return self.model |
---|
1560 | |
---|
1561 | ## post state to fit panel |
---|
1562 | self.state.parameters =[] |
---|
1563 | self.state.model =self.model |
---|
1564 | self.state.qmin = self.qmin_x |
---|
1565 | self.state.multi_factor = self.multi_factor |
---|
1566 | self.disp_list =self.model.getDispParamList() |
---|
1567 | self.state.disp_list = self.disp_list |
---|
1568 | self.Layout() |
---|
1569 | |
---|
1570 | def _validate_qrange(self, qmin_ctrl, qmax_ctrl): |
---|
1571 | """ |
---|
1572 | Verify that the Q range controls have valid values |
---|
1573 | and that Qmin < Qmax. |
---|
1574 | |
---|
1575 | :param qmin_ctrl: text control for Qmin |
---|
1576 | :param qmax_ctrl: text control for Qmax |
---|
1577 | |
---|
1578 | :return: True is the Q range is value, False otherwise |
---|
1579 | |
---|
1580 | """ |
---|
1581 | qmin_validity = check_float(qmin_ctrl) |
---|
1582 | qmax_validity = check_float(qmax_ctrl) |
---|
1583 | if not (qmin_validity and qmax_validity): |
---|
1584 | return False |
---|
1585 | else: |
---|
1586 | qmin = float(qmin_ctrl.GetValue()) |
---|
1587 | qmax = float(qmax_ctrl.GetValue()) |
---|
1588 | if qmin < qmax: |
---|
1589 | #Make sure to set both colours white. |
---|
1590 | qmin_ctrl.SetBackgroundColour(wx.WHITE) |
---|
1591 | qmin_ctrl.Refresh() |
---|
1592 | qmax_ctrl.SetBackgroundColour(wx.WHITE) |
---|
1593 | qmax_ctrl.Refresh() |
---|
1594 | else: |
---|
1595 | qmin_ctrl.SetBackgroundColour("pink") |
---|
1596 | qmin_ctrl.Refresh() |
---|
1597 | qmax_ctrl.SetBackgroundColour("pink") |
---|
1598 | qmax_ctrl.Refresh() |
---|
1599 | msg= "Invalid Q range: Q min must be smaller than Q max" |
---|
1600 | wx.PostEvent(self.parent, StatusEvent(status = msg)) |
---|
1601 | return False |
---|
1602 | return True |
---|
1603 | |
---|
1604 | def _check_value_enter(self, list, modified): |
---|
1605 | """ |
---|
1606 | :param list: model parameter and panel info |
---|
1607 | each item of the list should be as follow: :: |
---|
1608 | |
---|
1609 | item = [cb state, name, value, "+/-", error of fit, min, max , units] |
---|
1610 | |
---|
1611 | """ |
---|
1612 | is_modified = modified |
---|
1613 | if len(list)==0: |
---|
1614 | return is_modified |
---|
1615 | for item in list: |
---|
1616 | #skip angle parameters for 1D |
---|
1617 | if not self.enable2D: |
---|
1618 | if item in self.orientation_params: |
---|
1619 | continue |
---|
1620 | #try: |
---|
1621 | name = str(item[1]) |
---|
1622 | |
---|
1623 | try: |
---|
1624 | value= float(item[2].GetValue()) |
---|
1625 | # If the value of the parameter has changed, |
---|
1626 | # +update the model and set the is_modified flag |
---|
1627 | if value != self.model.getParam(name) and numpy.isfinite(value): |
---|
1628 | self.model.setParam(name,value) |
---|
1629 | is_modified = True |
---|
1630 | except: |
---|
1631 | msg = "Wrong parameter value entered " |
---|
1632 | wx.PostEvent(self.parent, StatusEvent(status = msg)) |
---|
1633 | |
---|
1634 | return is_modified |
---|
1635 | |
---|
1636 | def _set_dipers_Param(self, event): |
---|
1637 | """ |
---|
1638 | respond to self.enable_disp and self.disable_disp radio box. |
---|
1639 | The dispersity object is reset inside the model into Gaussian. |
---|
1640 | When the user select yes , this method display a combo box for more selection |
---|
1641 | when the user selects No,the combo box disappears. |
---|
1642 | Redraw the model with the default dispersity (Gaussian) |
---|
1643 | |
---|
1644 | """ |
---|
1645 | |
---|
1646 | self._reset_dispersity() |
---|
1647 | |
---|
1648 | if self.model ==None: |
---|
1649 | self.model_disp.Hide() |
---|
1650 | self.disp_box.Hide() |
---|
1651 | self.sizer4_4.Clear(True) |
---|
1652 | return |
---|
1653 | |
---|
1654 | if self.enable_disp.GetValue(): |
---|
1655 | self.model_disp.Show(True) |
---|
1656 | self.disp_box.Show(True) |
---|
1657 | ## layout for model containing no dispersity parameters |
---|
1658 | |
---|
1659 | self.disp_list= self.model.getDispParamList() |
---|
1660 | |
---|
1661 | if len(self.disp_list)==0 and len(self.disp_cb_dict)==0: |
---|
1662 | self._layout_sizer_noDipers() |
---|
1663 | else: |
---|
1664 | ## set gaussian sizer |
---|
1665 | self._on_select_Disp(event=None) |
---|
1666 | else: |
---|
1667 | self.model_disp.Hide() |
---|
1668 | self.disp_box.Hide() |
---|
1669 | self.disp_box.SetSelection(0) |
---|
1670 | self.sizer4_4.Clear(True) |
---|
1671 | |
---|
1672 | ## post state to fit panel |
---|
1673 | self.save_current_state() |
---|
1674 | if event !=None: |
---|
1675 | #self._undo.Enable(True) |
---|
1676 | event = PageInfoEvent(page = self) |
---|
1677 | wx.PostEvent(self.parent, event) |
---|
1678 | #draw the model with the current dispersity |
---|
1679 | self._draw_model() |
---|
1680 | self.sizer4_4.Layout() |
---|
1681 | self.sizer5.Layout() |
---|
1682 | self.Layout() |
---|
1683 | self.Refresh() |
---|
1684 | |
---|
1685 | |
---|
1686 | def _layout_sizer_noDipers(self): |
---|
1687 | """ |
---|
1688 | Draw a sizer with no dispersity info |
---|
1689 | |
---|
1690 | """ |
---|
1691 | ix=0 |
---|
1692 | iy=1 |
---|
1693 | self.fittable_param=[] |
---|
1694 | self.fixed_param=[] |
---|
1695 | self.orientation_params_disp=[] |
---|
1696 | |
---|
1697 | self.model_disp.Hide() |
---|
1698 | self.disp_box.Hide() |
---|
1699 | self.sizer4_4.Clear(True) |
---|
1700 | model_disp = wx.StaticText(self, -1, 'No PolyDispersity for this model') |
---|
1701 | self.sizer4_4.Add(model_disp,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
1702 | self.sizer4_4.Layout() |
---|
1703 | self.sizer4.Layout() |
---|
1704 | self.SetScrollbars(20,20,25,65) |
---|
1705 | |
---|
1706 | |
---|
1707 | def _reset_dispersity(self): |
---|
1708 | """ |
---|
1709 | put gaussian dispersity into current model |
---|
1710 | |
---|
1711 | """ |
---|
1712 | if len(self.param_toFit)>0: |
---|
1713 | for item in self.fittable_param: |
---|
1714 | if item in self.param_toFit: |
---|
1715 | self.param_toFit.remove(item) |
---|
1716 | |
---|
1717 | for item in self.orientation_params_disp: |
---|
1718 | if item in self.param_toFit: |
---|
1719 | self.param_toFit.remove(item) |
---|
1720 | |
---|
1721 | self.fittable_param=[] |
---|
1722 | self.fixed_param=[] |
---|
1723 | self.orientation_params_disp=[] |
---|
1724 | self.values=[] |
---|
1725 | self.weights=[] |
---|
1726 | |
---|
1727 | from sans.models.dispersion_models import GaussianDispersion, ArrayDispersion |
---|
1728 | if len(self.disp_cb_dict)==0: |
---|
1729 | self.save_current_state() |
---|
1730 | self.sizer4_4.Clear(True) |
---|
1731 | self.Layout() |
---|
1732 | |
---|
1733 | return |
---|
1734 | if (len(self.disp_cb_dict)>0) : |
---|
1735 | for p in self.disp_cb_dict: |
---|
1736 | # The parameter was un-selected. Go back to Gaussian model (with 0 pts) |
---|
1737 | disp_model = GaussianDispersion() |
---|
1738 | |
---|
1739 | self._disp_obj_dict[p] = disp_model |
---|
1740 | # Set the new model as the dispersion object for the selected parameter |
---|
1741 | try: |
---|
1742 | self.model.set_dispersion(p, disp_model) |
---|
1743 | except: |
---|
1744 | |
---|
1745 | pass |
---|
1746 | |
---|
1747 | ## save state into |
---|
1748 | self.save_current_state() |
---|
1749 | self.Layout() |
---|
1750 | self.Refresh() |
---|
1751 | |
---|
1752 | |
---|
1753 | def _on_select_Disp(self,event): |
---|
1754 | """ |
---|
1755 | allow selecting different dispersion |
---|
1756 | self.disp_list should change type later .now only gaussian |
---|
1757 | |
---|
1758 | """ |
---|
1759 | n = self.disp_box.GetCurrentSelection() |
---|
1760 | name = self.disp_box.GetValue() |
---|
1761 | dispersity= self.disp_box.GetClientData(n) |
---|
1762 | self.disp_name = name |
---|
1763 | |
---|
1764 | if name.lower() == "array": |
---|
1765 | self._set_sizer_arraydispersion() |
---|
1766 | else: |
---|
1767 | self._set_sizer_dispersion(dispersity= dispersity) |
---|
1768 | |
---|
1769 | self.state.disp_box= n |
---|
1770 | ## Redraw the model |
---|
1771 | self._draw_model() |
---|
1772 | #self._undo.Enable(True) |
---|
1773 | event = PageInfoEvent(page = self) |
---|
1774 | wx.PostEvent(self.parent, event) |
---|
1775 | |
---|
1776 | self.sizer4_4.Layout() |
---|
1777 | self.sizer4.Layout() |
---|
1778 | self.SetScrollbars(20,20,25,65) |
---|
1779 | |
---|
1780 | def _set_sizer_arraydispersion(self): |
---|
1781 | """ |
---|
1782 | draw sizer with array dispersity parameters |
---|
1783 | |
---|
1784 | """ |
---|
1785 | |
---|
1786 | if len(self.param_toFit)>0: |
---|
1787 | for item in self.fittable_param: |
---|
1788 | if item in self.param_toFit: |
---|
1789 | self.param_toFit.remove(item) |
---|
1790 | for item in self.orientation_params_disp: |
---|
1791 | if item in self.param_toFit: |
---|
1792 | self.param_toFit.remove(item) |
---|
1793 | for item in self.model.details.keys(): |
---|
1794 | if item in self.model.fixed: |
---|
1795 | del self.model.details [item] |
---|
1796 | |
---|
1797 | self.fittable_param=[] |
---|
1798 | self.fixed_param=[] |
---|
1799 | self.orientation_params_disp=[] |
---|
1800 | self.sizer4_4.Clear(True) |
---|
1801 | self._reset_dispersity() |
---|
1802 | ix=0 |
---|
1803 | iy=1 |
---|
1804 | disp1 = wx.StaticText(self, -1, 'Array Dispersion') |
---|
1805 | self.sizer4_4.Add(disp1,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
1806 | |
---|
1807 | # Look for model parameters to which we can apply an ArrayDispersion model |
---|
1808 | # Add a check box for each parameter. |
---|
1809 | self.disp_cb_dict = {} |
---|
1810 | ix+=1 |
---|
1811 | self.noDisper_rbox = wx.RadioButton(self, -1,"None", (10, 10),style= wx.RB_GROUP) |
---|
1812 | self.Bind(wx.EVT_RADIOBUTTON,self.select_disp_angle , id=self.noDisper_rbox.GetId()) |
---|
1813 | #MAC needs SetValue |
---|
1814 | self.noDisper_rbox.SetValue(True) |
---|
1815 | self.sizer4_4.Add(self.noDisper_rbox, (iy, ix), |
---|
1816 | (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1817 | |
---|
1818 | for p in self.model.dispersion.keys(): |
---|
1819 | if not p in self.model.orientation_params: |
---|
1820 | ix+=1 |
---|
1821 | self.disp_cb_dict[p] = wx.RadioButton(self, -1, p, (10, 10)) |
---|
1822 | self.state.disp_cb_dict[p]= self.disp_cb_dict[p].GetValue() |
---|
1823 | self.Bind(wx.EVT_RADIOBUTTON, self.select_disp_angle, id=self.disp_cb_dict[p].GetId()) |
---|
1824 | self.sizer4_4.Add(self.disp_cb_dict[p], (iy, ix), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1825 | |
---|
1826 | for p in self.model.dispersion.keys(): |
---|
1827 | if p in self.model.orientation_params: |
---|
1828 | ix+=1 |
---|
1829 | self.disp_cb_dict[p] = wx.RadioButton(self, -1, p, (10, 10)) |
---|
1830 | self.state.disp_cb_dict[p]= self.disp_cb_dict[p].GetValue() |
---|
1831 | if not (self.enable2D or self.data.__class__.__name__ =="Data2D"): |
---|
1832 | self.disp_cb_dict[p].Hide() |
---|
1833 | else: |
---|
1834 | self.disp_cb_dict[p].Show(True) |
---|
1835 | self.Bind(wx.EVT_RADIOBUTTON, self.select_disp_angle, id=self.disp_cb_dict[p].GetId()) |
---|
1836 | self.sizer4_4.Add(self.disp_cb_dict[p], (iy, ix), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1837 | |
---|
1838 | |
---|
1839 | ix =0 |
---|
1840 | iy +=1 |
---|
1841 | self.sizer4_4.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
1842 | self.Layout() |
---|
1843 | |
---|
1844 | self.state.orientation_params =[] |
---|
1845 | self.state.orientation_params_disp =[] |
---|
1846 | self.state.parameters =[] |
---|
1847 | self.state.fittable_param =[] |
---|
1848 | self.state.fixed_param =[] |
---|
1849 | |
---|
1850 | ## save checkbutton state and txtcrtl values |
---|
1851 | self._copy_parameters_state(self.orientation_params, |
---|
1852 | self.state.orientation_params) |
---|
1853 | |
---|
1854 | self._copy_parameters_state(self.orientation_params_disp, |
---|
1855 | self.state.orientation_params_disp) |
---|
1856 | |
---|
1857 | self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
1858 | self._copy_parameters_state(self.fittable_param, self.state.fittable_param) |
---|
1859 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
1860 | |
---|
1861 | ## post state to fit panel |
---|
1862 | event = PageInfoEvent(page = self) |
---|
1863 | wx.PostEvent(self.parent, event) |
---|
1864 | |
---|
1865 | def _set_range_sizer(self, title, box_sizer=None, object1=None,object=None): |
---|
1866 | """ |
---|
1867 | Fill the Q range sizer |
---|
1868 | |
---|
1869 | """ |
---|
1870 | self.sizer5.Clear(True) |
---|
1871 | #-------------------------------------------------------------- |
---|
1872 | if box_sizer == None: |
---|
1873 | box_description= wx.StaticBox(self, -1,str(title)) |
---|
1874 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
1875 | else: |
---|
1876 | #for MAC |
---|
1877 | boxsizer1 = box_sizer |
---|
1878 | |
---|
1879 | self.qmin = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20),style=wx.TE_PROCESS_ENTER, |
---|
1880 | kill_focus_callback = self._onQrangeEnter, |
---|
1881 | text_enter_callback = self._onQrangeEnter) |
---|
1882 | self.qmin.SetValue(str(self.qmin_x)) |
---|
1883 | self.qmin.SetToolTipString("Minimun value of Q in linear scale.") |
---|
1884 | |
---|
1885 | self.qmax = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20),style=wx.TE_PROCESS_ENTER, |
---|
1886 | kill_focus_callback = self._onQrangeEnter, |
---|
1887 | text_enter_callback = self._onQrangeEnter) |
---|
1888 | self.qmax.SetValue(str(self.qmax_x)) |
---|
1889 | self.qmax.SetToolTipString("Maximum value of Q in linear scale.") |
---|
1890 | |
---|
1891 | id = wx.NewId() |
---|
1892 | self.reset_qrange =wx.Button(self,id,'Reset',size=(70,23)) |
---|
1893 | |
---|
1894 | self.reset_qrange.Bind(wx.EVT_BUTTON, self.on_reset_clicked,id=id) |
---|
1895 | self.reset_qrange.SetToolTipString("Reset Q range to the default values") |
---|
1896 | |
---|
1897 | sizer_horizontal=wx.BoxSizer(wx.HORIZONTAL) |
---|
1898 | sizer= wx.GridSizer(3, 3,2, 5) |
---|
1899 | |
---|
1900 | sizer.Add(wx.StaticText(self, -1, ' Q range')) |
---|
1901 | sizer.Add(wx.StaticText(self, -1, ' Min')) |
---|
1902 | sizer.Add(wx.StaticText(self, -1, ' Max')) |
---|
1903 | sizer.Add(self.reset_qrange) |
---|
1904 | |
---|
1905 | sizer.Add(self.qmin) |
---|
1906 | sizer.Add(self.qmax) |
---|
1907 | sizer_horizontal.Add(sizer) |
---|
1908 | if object!=None: |
---|
1909 | sizer_horizontal.Add(object) |
---|
1910 | |
---|
1911 | if object1!=None: |
---|
1912 | boxsizer1.Add(object1) |
---|
1913 | boxsizer1.Add((10,10)) |
---|
1914 | boxsizer1.Add(sizer_horizontal) |
---|
1915 | ## save state |
---|
1916 | self.save_current_state() |
---|
1917 | #---------------------------------------------------------------- |
---|
1918 | self.sizer5.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
1919 | self.sizer5.Layout() |
---|
1920 | |
---|
1921 | def _fill_save_sizer(self): |
---|
1922 | """ |
---|
1923 | Draw the layout for saving option |
---|
1924 | |
---|
1925 | """ |
---|
1926 | # Skipping save state functionality for release 0.9.0 |
---|
1927 | return |
---|
1928 | |
---|
1929 | self.sizer6.Clear(True) |
---|
1930 | box_description= wx.StaticBox(self, -1,"Save Model") |
---|
1931 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
1932 | sizer_save = wx.BoxSizer(wx.HORIZONTAL) |
---|
1933 | |
---|
1934 | self.btSave_title = wx.StaticText(self, -1, 'Save the current Model') |
---|
1935 | self.btSave = wx.Button(self,wx.NewId(),'Save') |
---|
1936 | self.btSave.Bind(wx.EVT_BUTTON, self.onSave,id= self.btSave.GetId()) |
---|
1937 | self.btSave.SetToolTipString("Save the current Model") |
---|
1938 | |
---|
1939 | sizer_save.Add(self.btSave_title) |
---|
1940 | sizer_save.Add((20,20),0, wx.LEFT|wx.RIGHT|wx.EXPAND,45) |
---|
1941 | |
---|
1942 | sizer_save.Add(self.btSave) |
---|
1943 | |
---|
1944 | boxsizer1.Add(sizer_save) |
---|
1945 | self.sizer6.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
1946 | self.sizer6.Layout() |
---|
1947 | self.SetScrollbars(20,20,25,65) |
---|
1948 | |
---|
1949 | def _lay_out(self): |
---|
1950 | """ |
---|
1951 | returns self.Layout |
---|
1952 | |
---|
1953 | :Note: Mac seems to like this better when self.Layout |
---|
1954 | is called after fitting. |
---|
1955 | |
---|
1956 | """ |
---|
1957 | self._sleep4sec() |
---|
1958 | self.Layout() |
---|
1959 | #self._sleep4sec() |
---|
1960 | return |
---|
1961 | |
---|
1962 | def _sleep4sec(self): |
---|
1963 | """ |
---|
1964 | sleep for 1 sec only applied on Mac |
---|
1965 | |
---|
1966 | :Note: This 1sec helps for Mac not to crash on |
---|
1967 | self.layout after self._draw_model |
---|
1968 | |
---|
1969 | """ |
---|
1970 | if ON_MAC == True: |
---|
1971 | time.sleep(1) |
---|
1972 | |
---|
1973 | def on_reset_clicked(self,event): |
---|
1974 | """ |
---|
1975 | On 'Reset' button for Q range clicked |
---|
1976 | |
---|
1977 | """ |
---|
1978 | ##For 3 different cases: Data2D, Data1D, and theory |
---|
1979 | if self.data.__class__.__name__ == "Data2D": |
---|
1980 | data_min= 0 |
---|
1981 | x= max(math.fabs(self.data.xmin), math.fabs(self.data.xmax)) |
---|
1982 | y= max(math.fabs(self.data.ymin), math.fabs(self.data.ymax)) |
---|
1983 | self.qmin_x = data_min |
---|
1984 | self.qmax_x = math.sqrt(x*x + y*y) |
---|
1985 | elif self.data.__class__.__name__ == "Data1D": |
---|
1986 | self.qmin_x = min(self.data.x) |
---|
1987 | self.qmax_x = max(self.data.x) |
---|
1988 | else: |
---|
1989 | self.qmin_x = _QMIN_DEFAULT |
---|
1990 | self.qmax_x = _QMAX_DEFAULT |
---|
1991 | self.num_points = _NPTS_DEFAULT |
---|
1992 | self.state.npts = self.num_points |
---|
1993 | |
---|
1994 | self.state.qmin = self.qmin_x |
---|
1995 | self.state.qmax = self.qmax_x |
---|
1996 | |
---|
1997 | #reset the q range values |
---|
1998 | self._reset_plotting_range(self.state) |
---|
1999 | #Re draw plot |
---|
2000 | self._draw_model() |
---|