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