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