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