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 | sld_data = Data1D(x,y) |
---|
1284 | sld_data.name = 'SLD' |
---|
1285 | sld_data.axes = self.sld_axes |
---|
1286 | self.panel = SLDPanel(self, data=sld_data,axes =self.sld_axes,id =-1 ) |
---|
1287 | self.panel.ShowModal() |
---|
1288 | |
---|
1289 | def _set_multfactor_combobox(self, multiplicity=10): |
---|
1290 | """ |
---|
1291 | Set comboBox for muitfactor of CoreMultiShellModel |
---|
1292 | :param multiplicit: no. of multi-functionality |
---|
1293 | """ |
---|
1294 | # build content of the combobox |
---|
1295 | for idx in range(0,multiplicity): |
---|
1296 | self.multifactorbox.Append(str(idx),int(idx)) |
---|
1297 | #self.multifactorbox.SetSelection(1) |
---|
1298 | self._hide_multfactor_combobox() |
---|
1299 | |
---|
1300 | def _show_multfactor_combobox(self): |
---|
1301 | """ |
---|
1302 | Show the comboBox of muitfactor of CoreMultiShellModel |
---|
1303 | """ |
---|
1304 | if not self.mutifactor_text.IsShown(): |
---|
1305 | self.mutifactor_text.Show(True) |
---|
1306 | self.mutifactor_text1.Show(True) |
---|
1307 | if not self.multifactorbox.IsShown(): |
---|
1308 | self.multifactorbox.Show(True) |
---|
1309 | |
---|
1310 | def _hide_multfactor_combobox(self): |
---|
1311 | """ |
---|
1312 | Hide the comboBox of muitfactor of CoreMultiShellModel |
---|
1313 | """ |
---|
1314 | if self.mutifactor_text.IsShown(): |
---|
1315 | self.mutifactor_text.Hide() |
---|
1316 | self.mutifactor_text1.Hide() |
---|
1317 | if self.multifactorbox.IsShown(): |
---|
1318 | self.multifactorbox.Hide() |
---|
1319 | |
---|
1320 | |
---|
1321 | def _show_combox(self, event): |
---|
1322 | """ |
---|
1323 | Show combox box associate with type of model selected |
---|
1324 | |
---|
1325 | """ |
---|
1326 | ## Don't want to populate combo box again if the event comes from check box |
---|
1327 | if self.shape_rbutton.GetValue()and\ |
---|
1328 | event.GetEventObject()==self.shape_rbutton: |
---|
1329 | ##fill the combobox with form factor list |
---|
1330 | self.structurebox.SetSelection(0) |
---|
1331 | self.structurebox.Disable() |
---|
1332 | self.formfactorbox.Clear() |
---|
1333 | self._populate_box( self.formfactorbox,self.model_list_box["Shapes"]) |
---|
1334 | |
---|
1335 | if self.shape_indep_rbutton.GetValue()and\ |
---|
1336 | event.GetEventObject()==self.shape_indep_rbutton: |
---|
1337 | ##fill the combobox with shape independent factor list |
---|
1338 | self.structurebox.SetSelection(0) |
---|
1339 | self.structurebox.Disable() |
---|
1340 | self.formfactorbox.Clear() |
---|
1341 | self._populate_box( self.formfactorbox, |
---|
1342 | self.model_list_box["Shape-Independent"]) |
---|
1343 | |
---|
1344 | if self.struct_rbutton.GetValue() and\ |
---|
1345 | event.GetEventObject()==self.struct_rbutton: |
---|
1346 | ##fill the combobox with structure factor list |
---|
1347 | self.structurebox.SetSelection(0) |
---|
1348 | self.structurebox.Disable() |
---|
1349 | self.formfactorbox.Clear() |
---|
1350 | self._populate_box( self.formfactorbox, |
---|
1351 | self.model_list_box["Structure Factors"]) |
---|
1352 | |
---|
1353 | if self.plugin_rbutton.GetValue()and\ |
---|
1354 | event.GetEventObject()==self.plugin_rbutton: |
---|
1355 | |
---|
1356 | ##fill the combobox with form factor list |
---|
1357 | self.structurebox.Disable() |
---|
1358 | self.formfactorbox.Clear() |
---|
1359 | self._populate_box( self.formfactorbox, |
---|
1360 | self.model_list_box["Customized Models"]) |
---|
1361 | |
---|
1362 | self._on_select_model(event=None) |
---|
1363 | self._save_typeOfmodel() |
---|
1364 | self.sizer4_4.Layout() |
---|
1365 | self.sizer4.Layout() |
---|
1366 | self.Layout() |
---|
1367 | self.Refresh() |
---|
1368 | self.SetScrollbars(20,20,25,65) |
---|
1369 | |
---|
1370 | def _populate_box(self, combobox, list): |
---|
1371 | """ |
---|
1372 | fill combox box with dict item |
---|
1373 | |
---|
1374 | :param list: contains item to fill the combox |
---|
1375 | item must model class |
---|
1376 | """ |
---|
1377 | for models in list: |
---|
1378 | model= models() |
---|
1379 | name = model.__class__.__name__ |
---|
1380 | if models.__name__!="NoStructure": |
---|
1381 | if hasattr(model, "name"): |
---|
1382 | name = model.name |
---|
1383 | combobox.Append(name,models) |
---|
1384 | |
---|
1385 | return 0 |
---|
1386 | |
---|
1387 | def _onparamEnter(self,event): |
---|
1388 | """ |
---|
1389 | when enter value on panel redraw model according to changed |
---|
1390 | |
---|
1391 | """ |
---|
1392 | tcrtl= event.GetEventObject() |
---|
1393 | |
---|
1394 | #Clear msg if previously shown. |
---|
1395 | msg= "" |
---|
1396 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
1397 | |
---|
1398 | ## save current state |
---|
1399 | self.save_current_state() |
---|
1400 | if event !=None: |
---|
1401 | #self._undo.Enable(True) |
---|
1402 | event = PageInfoEvent(page = self) |
---|
1403 | wx.PostEvent(self.parent, event) |
---|
1404 | |
---|
1405 | if check_float(tcrtl): |
---|
1406 | |
---|
1407 | self._onparamEnter_helper() |
---|
1408 | #event.Skip() |
---|
1409 | else: |
---|
1410 | msg= "Cannot Plot :Must enter a number!!! " |
---|
1411 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
1412 | #event.Skip() |
---|
1413 | return |
---|
1414 | |
---|
1415 | def _onQrangeEnter(self, event): |
---|
1416 | """ |
---|
1417 | Check validity of value enter in the Q range field |
---|
1418 | |
---|
1419 | """ |
---|
1420 | |
---|
1421 | tcrtl= event.GetEventObject() |
---|
1422 | #Clear msg if previously shown. |
---|
1423 | msg= "" |
---|
1424 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
1425 | # Flag to register when a parameter has changed. |
---|
1426 | is_modified = False |
---|
1427 | if tcrtl.GetValue().lstrip().rstrip()!="": |
---|
1428 | try: |
---|
1429 | value = float(tcrtl.GetValue()) |
---|
1430 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
1431 | |
---|
1432 | # If qmin and qmax have been modified, update qmin and qmax |
---|
1433 | if self._validate_qrange( self.qmin, self.qmax): |
---|
1434 | tempmin = float(self.qmin.GetValue()) |
---|
1435 | if tempmin != self.qmin_x: |
---|
1436 | self.qmin_x = tempmin |
---|
1437 | tempmax = float(self.qmax.GetValue()) |
---|
1438 | if tempmax != self.qmax_x: |
---|
1439 | self.qmax_x = tempmax |
---|
1440 | else: |
---|
1441 | tcrtl.SetBackgroundColour("pink") |
---|
1442 | msg= "Model Error:wrong value entered : %s"% sys.exc_value |
---|
1443 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
1444 | return |
---|
1445 | |
---|
1446 | except: |
---|
1447 | tcrtl.SetBackgroundColour("pink") |
---|
1448 | msg= "Model Error:wrong value entered : %s"% sys.exc_value |
---|
1449 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
1450 | return |
---|
1451 | #Check if # of points for theory model are valid(>0). |
---|
1452 | if self.npts != None: |
---|
1453 | if check_float(self.npts): |
---|
1454 | temp_npts = float(self.npts.GetValue()) |
---|
1455 | if temp_npts != self.num_points: |
---|
1456 | self.num_points = temp_npts |
---|
1457 | is_modified = True |
---|
1458 | else: |
---|
1459 | msg= "Cannot Plot :No npts in that Qrange!!! " |
---|
1460 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
1461 | |
---|
1462 | else: |
---|
1463 | tcrtl.SetBackgroundColour("pink") |
---|
1464 | msg= "Model Error:wrong value entered!!!" |
---|
1465 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
1466 | |
---|
1467 | #self._undo.Enable(True) |
---|
1468 | self.save_current_state() |
---|
1469 | event = PageInfoEvent(page = self) |
---|
1470 | wx.PostEvent(self.parent, event) |
---|
1471 | self.state_change= False |
---|
1472 | #Draw the model for a different range |
---|
1473 | self._draw_model() |
---|
1474 | |
---|
1475 | def _on_select_model_helper(self): |
---|
1476 | """ |
---|
1477 | call back for model selection |
---|
1478 | |
---|
1479 | """ |
---|
1480 | ## reset dictionary containing reference to dispersion |
---|
1481 | self._disp_obj_dict = {} |
---|
1482 | self.disp_cb_dict ={} |
---|
1483 | |
---|
1484 | f_id = self.formfactorbox.GetCurrentSelection() |
---|
1485 | #For MAC |
---|
1486 | form_factor = None |
---|
1487 | if f_id >= 0: |
---|
1488 | form_factor = self.formfactorbox.GetClientData( f_id ) |
---|
1489 | |
---|
1490 | if not form_factor in self.model_list_box["multiplication"]: |
---|
1491 | self.structurebox.Hide() |
---|
1492 | self.text2.Hide() |
---|
1493 | self.structurebox.Disable() |
---|
1494 | self.structurebox.SetSelection(0) |
---|
1495 | self.text2.Disable() |
---|
1496 | else: |
---|
1497 | self.structurebox.Show() |
---|
1498 | self.text2.Show() |
---|
1499 | self.structurebox.Enable() |
---|
1500 | self.text2.Enable() |
---|
1501 | |
---|
1502 | if form_factor != None: |
---|
1503 | # set multifactor for Mutifunctional models |
---|
1504 | if form_factor().__class__ in self.model_list_box["Multi-Functions"]: |
---|
1505 | m_id = self.multifactorbox.GetCurrentSelection() |
---|
1506 | multiplicity = form_factor().multiplicity_info[0] |
---|
1507 | self.multifactorbox.Clear() |
---|
1508 | #self.mutifactor_text.SetLabel(form_factor().details[]) |
---|
1509 | self._set_multfactor_combobox(multiplicity) |
---|
1510 | self._show_multfactor_combobox() |
---|
1511 | text = form_factor().multiplicity_info[1]#'No. of Shells: ' |
---|
1512 | |
---|
1513 | #self.mutifactor_text.Clear() |
---|
1514 | self.mutifactor_text.SetLabel(text) |
---|
1515 | |
---|
1516 | # Check max value |
---|
1517 | if m_id > multiplicity -1: |
---|
1518 | # default value |
---|
1519 | m_id = 1 |
---|
1520 | self.multi_factor = self.multifactorbox.GetClientData(m_id) |
---|
1521 | if self.multi_factor == None: self.multi_factor =1 |
---|
1522 | form_factor = form_factor(int(self.multi_factor)) |
---|
1523 | self.multifactorbox.SetSelection(m_id) |
---|
1524 | # Check len of the text1 and max_multiplicity |
---|
1525 | text = '' |
---|
1526 | if form_factor.multiplicity_info[0] == len(form_factor.multiplicity_info[2]): |
---|
1527 | text = form_factor.multiplicity_info[2][self.multi_factor] |
---|
1528 | self.mutifactor_text1.SetLabel(text) |
---|
1529 | # Check if model has get sld profile. |
---|
1530 | if len(form_factor.multiplicity_info[3]) > 0: |
---|
1531 | self.sld_axes = form_factor.multiplicity_info[3] |
---|
1532 | self.show_sld_button.Show(True) |
---|
1533 | else: |
---|
1534 | self.sld_axes = "" |
---|
1535 | else: |
---|
1536 | self._hide_multfactor_combobox() |
---|
1537 | self.show_sld_button.Hide() |
---|
1538 | form_factor = form_factor() |
---|
1539 | self.multi_factor = None |
---|
1540 | else: |
---|
1541 | self._hide_multfactor_combobox() |
---|
1542 | self.show_sld_button.Hide() |
---|
1543 | self.multi_factor = None |
---|
1544 | |
---|
1545 | s_id = self.structurebox.GetCurrentSelection() |
---|
1546 | struct_factor = self.structurebox.GetClientData( s_id ) |
---|
1547 | |
---|
1548 | if struct_factor !=None: |
---|
1549 | from sans.models.MultiplicationModel import MultiplicationModel |
---|
1550 | self.model= MultiplicationModel(form_factor,struct_factor()) |
---|
1551 | |
---|
1552 | else: |
---|
1553 | if form_factor != None: |
---|
1554 | self.model= form_factor |
---|
1555 | else: |
---|
1556 | self.model = None |
---|
1557 | return self.model |
---|
1558 | |
---|
1559 | ## post state to fit panel |
---|
1560 | self.state.parameters =[] |
---|
1561 | self.state.model =self.model |
---|
1562 | self.state.qmin = self.qmin_x |
---|
1563 | self.state.multi_factor = self.multi_factor |
---|
1564 | self.disp_list =self.model.getDispParamList() |
---|
1565 | self.state.disp_list = self.disp_list |
---|
1566 | self.Layout() |
---|
1567 | |
---|
1568 | def _validate_qrange(self, qmin_ctrl, qmax_ctrl): |
---|
1569 | """ |
---|
1570 | Verify that the Q range controls have valid values |
---|
1571 | and that Qmin < Qmax. |
---|
1572 | |
---|
1573 | :param qmin_ctrl: text control for Qmin |
---|
1574 | :param qmax_ctrl: text control for Qmax |
---|
1575 | |
---|
1576 | :return: True is the Q range is value, False otherwise |
---|
1577 | |
---|
1578 | """ |
---|
1579 | qmin_validity = check_float(qmin_ctrl) |
---|
1580 | qmax_validity = check_float(qmax_ctrl) |
---|
1581 | if not (qmin_validity and qmax_validity): |
---|
1582 | return False |
---|
1583 | else: |
---|
1584 | qmin = float(qmin_ctrl.GetValue()) |
---|
1585 | qmax = float(qmax_ctrl.GetValue()) |
---|
1586 | if qmin < qmax: |
---|
1587 | #Make sure to set both colours white. |
---|
1588 | qmin_ctrl.SetBackgroundColour(wx.WHITE) |
---|
1589 | qmin_ctrl.Refresh() |
---|
1590 | qmax_ctrl.SetBackgroundColour(wx.WHITE) |
---|
1591 | qmax_ctrl.Refresh() |
---|
1592 | else: |
---|
1593 | qmin_ctrl.SetBackgroundColour("pink") |
---|
1594 | qmin_ctrl.Refresh() |
---|
1595 | qmax_ctrl.SetBackgroundColour("pink") |
---|
1596 | qmax_ctrl.Refresh() |
---|
1597 | msg= "Invalid Q range: Q min must be smaller than Q max" |
---|
1598 | wx.PostEvent(self.parent, StatusEvent(status = msg)) |
---|
1599 | return False |
---|
1600 | return True |
---|
1601 | |
---|
1602 | def _check_value_enter(self, list, modified): |
---|
1603 | """ |
---|
1604 | :param list: model parameter and panel info |
---|
1605 | each item of the list should be as follow: :: |
---|
1606 | |
---|
1607 | item = [cb state, name, value, "+/-", error of fit, min, max , units] |
---|
1608 | |
---|
1609 | """ |
---|
1610 | is_modified = modified |
---|
1611 | if len(list)==0: |
---|
1612 | return is_modified |
---|
1613 | for item in list: |
---|
1614 | #skip angle parameters for 1D |
---|
1615 | if not self.enable2D: |
---|
1616 | if item in self.orientation_params: |
---|
1617 | continue |
---|
1618 | #try: |
---|
1619 | name = str(item[1]) |
---|
1620 | |
---|
1621 | try: |
---|
1622 | value= float(item[2].GetValue()) |
---|
1623 | # If the value of the parameter has changed, |
---|
1624 | # +update the model and set the is_modified flag |
---|
1625 | if value != self.model.getParam(name) and numpy.isfinite(value): |
---|
1626 | self.model.setParam(name,value) |
---|
1627 | is_modified = True |
---|
1628 | except: |
---|
1629 | msg = "Wrong parameter value entered " |
---|
1630 | wx.PostEvent(self.parent, StatusEvent(status = msg)) |
---|
1631 | |
---|
1632 | return is_modified |
---|
1633 | |
---|
1634 | def _set_dipers_Param(self, event): |
---|
1635 | """ |
---|
1636 | respond to self.enable_disp and self.disable_disp radio box. |
---|
1637 | The dispersity object is reset inside the model into Gaussian. |
---|
1638 | When the user select yes , this method display a combo box for more selection |
---|
1639 | when the user selects No,the combo box disappears. |
---|
1640 | Redraw the model with the default dispersity (Gaussian) |
---|
1641 | |
---|
1642 | """ |
---|
1643 | |
---|
1644 | self._reset_dispersity() |
---|
1645 | |
---|
1646 | if self.model ==None: |
---|
1647 | self.model_disp.Hide() |
---|
1648 | self.disp_box.Hide() |
---|
1649 | self.sizer4_4.Clear(True) |
---|
1650 | return |
---|
1651 | |
---|
1652 | if self.enable_disp.GetValue(): |
---|
1653 | self.model_disp.Show(True) |
---|
1654 | self.disp_box.Show(True) |
---|
1655 | ## layout for model containing no dispersity parameters |
---|
1656 | |
---|
1657 | self.disp_list= self.model.getDispParamList() |
---|
1658 | |
---|
1659 | if len(self.disp_list)==0 and len(self.disp_cb_dict)==0: |
---|
1660 | self._layout_sizer_noDipers() |
---|
1661 | else: |
---|
1662 | ## set gaussian sizer |
---|
1663 | self._on_select_Disp(event=None) |
---|
1664 | else: |
---|
1665 | self.model_disp.Hide() |
---|
1666 | self.disp_box.Hide() |
---|
1667 | self.disp_box.SetSelection(0) |
---|
1668 | self.sizer4_4.Clear(True) |
---|
1669 | |
---|
1670 | ## post state to fit panel |
---|
1671 | self.save_current_state() |
---|
1672 | if event !=None: |
---|
1673 | #self._undo.Enable(True) |
---|
1674 | event = PageInfoEvent(page = self) |
---|
1675 | wx.PostEvent(self.parent, event) |
---|
1676 | #draw the model with the current dispersity |
---|
1677 | self._draw_model() |
---|
1678 | self.sizer4_4.Layout() |
---|
1679 | self.sizer5.Layout() |
---|
1680 | self.Layout() |
---|
1681 | self.Refresh() |
---|
1682 | |
---|
1683 | |
---|
1684 | def _layout_sizer_noDipers(self): |
---|
1685 | """ |
---|
1686 | Draw a sizer with no dispersity info |
---|
1687 | |
---|
1688 | """ |
---|
1689 | ix=0 |
---|
1690 | iy=1 |
---|
1691 | self.fittable_param=[] |
---|
1692 | self.fixed_param=[] |
---|
1693 | self.orientation_params_disp=[] |
---|
1694 | |
---|
1695 | self.model_disp.Hide() |
---|
1696 | self.disp_box.Hide() |
---|
1697 | self.sizer4_4.Clear(True) |
---|
1698 | model_disp = wx.StaticText(self, -1, 'No PolyDispersity for this model') |
---|
1699 | self.sizer4_4.Add(model_disp,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
1700 | self.sizer4_4.Layout() |
---|
1701 | self.sizer4.Layout() |
---|
1702 | self.SetScrollbars(20,20,25,65) |
---|
1703 | |
---|
1704 | |
---|
1705 | def _reset_dispersity(self): |
---|
1706 | """ |
---|
1707 | put gaussian dispersity into current model |
---|
1708 | |
---|
1709 | """ |
---|
1710 | if len(self.param_toFit)>0: |
---|
1711 | for item in self.fittable_param: |
---|
1712 | if item in self.param_toFit: |
---|
1713 | self.param_toFit.remove(item) |
---|
1714 | |
---|
1715 | for item in self.orientation_params_disp: |
---|
1716 | if item in self.param_toFit: |
---|
1717 | self.param_toFit.remove(item) |
---|
1718 | |
---|
1719 | self.fittable_param=[] |
---|
1720 | self.fixed_param=[] |
---|
1721 | self.orientation_params_disp=[] |
---|
1722 | self.values=[] |
---|
1723 | self.weights=[] |
---|
1724 | |
---|
1725 | from sans.models.dispersion_models import GaussianDispersion, ArrayDispersion |
---|
1726 | if len(self.disp_cb_dict)==0: |
---|
1727 | self.save_current_state() |
---|
1728 | self.sizer4_4.Clear(True) |
---|
1729 | self.Layout() |
---|
1730 | |
---|
1731 | return |
---|
1732 | if (len(self.disp_cb_dict)>0) : |
---|
1733 | for p in self.disp_cb_dict: |
---|
1734 | # The parameter was un-selected. Go back to Gaussian model (with 0 pts) |
---|
1735 | disp_model = GaussianDispersion() |
---|
1736 | |
---|
1737 | self._disp_obj_dict[p] = disp_model |
---|
1738 | # Set the new model as the dispersion object for the selected parameter |
---|
1739 | try: |
---|
1740 | self.model.set_dispersion(p, disp_model) |
---|
1741 | except: |
---|
1742 | |
---|
1743 | pass |
---|
1744 | |
---|
1745 | ## save state into |
---|
1746 | self.save_current_state() |
---|
1747 | self.Layout() |
---|
1748 | self.Refresh() |
---|
1749 | |
---|
1750 | |
---|
1751 | def _on_select_Disp(self,event): |
---|
1752 | """ |
---|
1753 | allow selecting different dispersion |
---|
1754 | self.disp_list should change type later .now only gaussian |
---|
1755 | |
---|
1756 | """ |
---|
1757 | n = self.disp_box.GetCurrentSelection() |
---|
1758 | name = self.disp_box.GetValue() |
---|
1759 | dispersity= self.disp_box.GetClientData(n) |
---|
1760 | self.disp_name = name |
---|
1761 | |
---|
1762 | if name.lower() == "array": |
---|
1763 | self._set_sizer_arraydispersion() |
---|
1764 | else: |
---|
1765 | self._set_sizer_dispersion(dispersity= dispersity) |
---|
1766 | |
---|
1767 | self.state.disp_box= n |
---|
1768 | ## Redraw the model |
---|
1769 | self._draw_model() |
---|
1770 | #self._undo.Enable(True) |
---|
1771 | event = PageInfoEvent(page = self) |
---|
1772 | wx.PostEvent(self.parent, event) |
---|
1773 | |
---|
1774 | self.sizer4_4.Layout() |
---|
1775 | self.sizer4.Layout() |
---|
1776 | self.SetScrollbars(20,20,25,65) |
---|
1777 | |
---|
1778 | def _set_sizer_arraydispersion(self): |
---|
1779 | """ |
---|
1780 | draw sizer with array dispersity parameters |
---|
1781 | |
---|
1782 | """ |
---|
1783 | |
---|
1784 | if len(self.param_toFit)>0: |
---|
1785 | for item in self.fittable_param: |
---|
1786 | if item in self.param_toFit: |
---|
1787 | self.param_toFit.remove(item) |
---|
1788 | for item in self.orientation_params_disp: |
---|
1789 | if item in self.param_toFit: |
---|
1790 | self.param_toFit.remove(item) |
---|
1791 | for item in self.model.details.keys(): |
---|
1792 | if item in self.model.fixed: |
---|
1793 | del self.model.details [item] |
---|
1794 | |
---|
1795 | self.fittable_param=[] |
---|
1796 | self.fixed_param=[] |
---|
1797 | self.orientation_params_disp=[] |
---|
1798 | self.sizer4_4.Clear(True) |
---|
1799 | self._reset_dispersity() |
---|
1800 | ix=0 |
---|
1801 | iy=1 |
---|
1802 | disp1 = wx.StaticText(self, -1, 'Array Dispersion') |
---|
1803 | self.sizer4_4.Add(disp1,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
1804 | |
---|
1805 | # Look for model parameters to which we can apply an ArrayDispersion model |
---|
1806 | # Add a check box for each parameter. |
---|
1807 | self.disp_cb_dict = {} |
---|
1808 | ix+=1 |
---|
1809 | self.noDisper_rbox = wx.RadioButton(self, -1,"None", (10, 10),style= wx.RB_GROUP) |
---|
1810 | self.Bind(wx.EVT_RADIOBUTTON,self.select_disp_angle , id=self.noDisper_rbox.GetId()) |
---|
1811 | #MAC needs SetValue |
---|
1812 | self.noDisper_rbox.SetValue(True) |
---|
1813 | self.sizer4_4.Add(self.noDisper_rbox, (iy, ix), |
---|
1814 | (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1815 | |
---|
1816 | for p in self.model.dispersion.keys(): |
---|
1817 | if not p in self.model.orientation_params: |
---|
1818 | ix+=1 |
---|
1819 | self.disp_cb_dict[p] = wx.RadioButton(self, -1, p, (10, 10)) |
---|
1820 | self.state.disp_cb_dict[p]= self.disp_cb_dict[p].GetValue() |
---|
1821 | self.Bind(wx.EVT_RADIOBUTTON, self.select_disp_angle, id=self.disp_cb_dict[p].GetId()) |
---|
1822 | self.sizer4_4.Add(self.disp_cb_dict[p], (iy, ix), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1823 | |
---|
1824 | for p in self.model.dispersion.keys(): |
---|
1825 | if p in self.model.orientation_params: |
---|
1826 | ix+=1 |
---|
1827 | self.disp_cb_dict[p] = wx.RadioButton(self, -1, p, (10, 10)) |
---|
1828 | self.state.disp_cb_dict[p]= self.disp_cb_dict[p].GetValue() |
---|
1829 | if not (self.enable2D or self.data.__class__.__name__ =="Data2D"): |
---|
1830 | self.disp_cb_dict[p].Hide() |
---|
1831 | else: |
---|
1832 | self.disp_cb_dict[p].Show(True) |
---|
1833 | self.Bind(wx.EVT_RADIOBUTTON, self.select_disp_angle, id=self.disp_cb_dict[p].GetId()) |
---|
1834 | self.sizer4_4.Add(self.disp_cb_dict[p], (iy, ix), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1835 | |
---|
1836 | |
---|
1837 | ix =0 |
---|
1838 | iy +=1 |
---|
1839 | self.sizer4_4.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
1840 | self.Layout() |
---|
1841 | |
---|
1842 | self.state.orientation_params =[] |
---|
1843 | self.state.orientation_params_disp =[] |
---|
1844 | self.state.parameters =[] |
---|
1845 | self.state.fittable_param =[] |
---|
1846 | self.state.fixed_param =[] |
---|
1847 | |
---|
1848 | ## save checkbutton state and txtcrtl values |
---|
1849 | self._copy_parameters_state(self.orientation_params, |
---|
1850 | self.state.orientation_params) |
---|
1851 | |
---|
1852 | self._copy_parameters_state(self.orientation_params_disp, |
---|
1853 | self.state.orientation_params_disp) |
---|
1854 | |
---|
1855 | self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
1856 | self._copy_parameters_state(self.fittable_param, self.state.fittable_param) |
---|
1857 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
1858 | |
---|
1859 | ## post state to fit panel |
---|
1860 | event = PageInfoEvent(page = self) |
---|
1861 | wx.PostEvent(self.parent, event) |
---|
1862 | |
---|
1863 | def _set_range_sizer(self, title, box_sizer=None, object1=None,object=None): |
---|
1864 | """ |
---|
1865 | Fill the Q range sizer |
---|
1866 | |
---|
1867 | """ |
---|
1868 | self.sizer5.Clear(True) |
---|
1869 | #-------------------------------------------------------------- |
---|
1870 | if box_sizer == None: |
---|
1871 | box_description= wx.StaticBox(self, -1,str(title)) |
---|
1872 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
1873 | else: |
---|
1874 | #for MAC |
---|
1875 | boxsizer1 = box_sizer |
---|
1876 | |
---|
1877 | self.qmin = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20),style=wx.TE_PROCESS_ENTER, |
---|
1878 | kill_focus_callback = self._onQrangeEnter, |
---|
1879 | text_enter_callback = self._onQrangeEnter) |
---|
1880 | self.qmin.SetValue(str(self.qmin_x)) |
---|
1881 | self.qmin.SetToolTipString("Minimun value of Q in linear scale.") |
---|
1882 | |
---|
1883 | self.qmax = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20),style=wx.TE_PROCESS_ENTER, |
---|
1884 | kill_focus_callback = self._onQrangeEnter, |
---|
1885 | text_enter_callback = self._onQrangeEnter) |
---|
1886 | self.qmax.SetValue(str(self.qmax_x)) |
---|
1887 | self.qmax.SetToolTipString("Maximum value of Q in linear scale.") |
---|
1888 | |
---|
1889 | id = wx.NewId() |
---|
1890 | self.reset_qrange =wx.Button(self,id,'Reset',size=(70,23)) |
---|
1891 | |
---|
1892 | self.reset_qrange.Bind(wx.EVT_BUTTON, self.on_reset_clicked,id=id) |
---|
1893 | self.reset_qrange.SetToolTipString("Reset Q range to the default values") |
---|
1894 | |
---|
1895 | sizer_horizontal=wx.BoxSizer(wx.HORIZONTAL) |
---|
1896 | sizer= wx.GridSizer(3, 3,2, 5) |
---|
1897 | |
---|
1898 | sizer.Add(wx.StaticText(self, -1, ' Q range')) |
---|
1899 | sizer.Add(wx.StaticText(self, -1, ' Min')) |
---|
1900 | sizer.Add(wx.StaticText(self, -1, ' Max')) |
---|
1901 | sizer.Add(self.reset_qrange) |
---|
1902 | |
---|
1903 | sizer.Add(self.qmin) |
---|
1904 | sizer.Add(self.qmax) |
---|
1905 | sizer_horizontal.Add(sizer) |
---|
1906 | if object!=None: |
---|
1907 | sizer_horizontal.Add(object) |
---|
1908 | |
---|
1909 | if object1!=None: |
---|
1910 | boxsizer1.Add(object1) |
---|
1911 | boxsizer1.Add((10,10)) |
---|
1912 | boxsizer1.Add(sizer_horizontal) |
---|
1913 | ## save state |
---|
1914 | self.save_current_state() |
---|
1915 | #---------------------------------------------------------------- |
---|
1916 | self.sizer5.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
1917 | self.sizer5.Layout() |
---|
1918 | |
---|
1919 | def _fill_save_sizer(self): |
---|
1920 | """ |
---|
1921 | Draw the layout for saving option |
---|
1922 | |
---|
1923 | """ |
---|
1924 | # Skipping save state functionality for release 0.9.0 |
---|
1925 | return |
---|
1926 | |
---|
1927 | self.sizer6.Clear(True) |
---|
1928 | box_description= wx.StaticBox(self, -1,"Save Model") |
---|
1929 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
1930 | sizer_save = wx.BoxSizer(wx.HORIZONTAL) |
---|
1931 | |
---|
1932 | self.btSave_title = wx.StaticText(self, -1, 'Save the current Model') |
---|
1933 | self.btSave = wx.Button(self,wx.NewId(),'Save') |
---|
1934 | self.btSave.Bind(wx.EVT_BUTTON, self.onSave,id= self.btSave.GetId()) |
---|
1935 | self.btSave.SetToolTipString("Save the current Model") |
---|
1936 | |
---|
1937 | sizer_save.Add(self.btSave_title) |
---|
1938 | sizer_save.Add((20,20),0, wx.LEFT|wx.RIGHT|wx.EXPAND,45) |
---|
1939 | |
---|
1940 | sizer_save.Add(self.btSave) |
---|
1941 | |
---|
1942 | boxsizer1.Add(sizer_save) |
---|
1943 | self.sizer6.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
1944 | self.sizer6.Layout() |
---|
1945 | self.SetScrollbars(20,20,25,65) |
---|
1946 | |
---|
1947 | def _lay_out(self): |
---|
1948 | """ |
---|
1949 | returns self.Layout |
---|
1950 | |
---|
1951 | :Note: Mac seems to like this better when self.Layout |
---|
1952 | is called after fitting. |
---|
1953 | |
---|
1954 | """ |
---|
1955 | self._sleep4sec() |
---|
1956 | self.Layout() |
---|
1957 | #self._sleep4sec() |
---|
1958 | return |
---|
1959 | |
---|
1960 | def _sleep4sec(self): |
---|
1961 | """ |
---|
1962 | sleep for 1 sec only applied on Mac |
---|
1963 | |
---|
1964 | :Note: This 1sec helps for Mac not to crash on |
---|
1965 | self.layout after self._draw_model |
---|
1966 | |
---|
1967 | """ |
---|
1968 | if ON_MAC == True: |
---|
1969 | time.sleep(1) |
---|
1970 | |
---|
1971 | def on_reset_clicked(self,event): |
---|
1972 | """ |
---|
1973 | On 'Reset' button for Q range clicked |
---|
1974 | |
---|
1975 | """ |
---|
1976 | ##For 3 different cases: Data2D, Data1D, and theory |
---|
1977 | if self.data.__class__.__name__ == "Data2D": |
---|
1978 | data_min= 0 |
---|
1979 | x= max(math.fabs(self.data.xmin), math.fabs(self.data.xmax)) |
---|
1980 | y= max(math.fabs(self.data.ymin), math.fabs(self.data.ymax)) |
---|
1981 | self.qmin_x = data_min |
---|
1982 | self.qmax_x = math.sqrt(x*x + y*y) |
---|
1983 | elif self.data.__class__.__name__ == "Data1D": |
---|
1984 | self.qmin_x = min(self.data.x) |
---|
1985 | self.qmax_x = max(self.data.x) |
---|
1986 | else: |
---|
1987 | self.qmin_x = _QMIN_DEFAULT |
---|
1988 | self.qmax_x = _QMAX_DEFAULT |
---|
1989 | self.num_points = _NPTS_DEFAULT |
---|
1990 | self.state.npts = self.num_points |
---|
1991 | |
---|
1992 | self.state.qmin = self.qmin_x |
---|
1993 | self.state.qmax = self.qmax_x |
---|
1994 | |
---|
1995 | #reset the q range values |
---|
1996 | self._reset_plotting_range(self.state) |
---|
1997 | #Re draw plot |
---|
1998 | self._draw_model() |
---|