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