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