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