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