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