[c77d859] | 1 | |
---|
[340c2b3] | 2 | import sys |
---|
| 3 | import os |
---|
[c77d859] | 4 | import wx |
---|
| 5 | import numpy |
---|
[a074145] | 6 | import time |
---|
[ef26c83] | 7 | import copy |
---|
[904168e1] | 8 | import math |
---|
[edd166b] | 9 | import string |
---|
[340c2b3] | 10 | from wx.lib.scrolledpanel import ScrolledPanel |
---|
[ecf26e1] | 11 | from sans.guiframe.panel_base import PanelBase |
---|
[ef26c83] | 12 | from sans.guiframe.utils import format_number, check_float |
---|
[3cd5806] | 13 | from sans.guiframe.events import PanelOnFocusEvent |
---|
[4ce74917] | 14 | from sans.guiframe.events import StatusEvent |
---|
[20b228a0] | 15 | from sans.guiframe.events import AppendBookmarkEvent |
---|
[ecf26e1] | 16 | from sans.guiframe.dataFitting import Data2D |
---|
| 17 | from sans.guiframe.dataFitting import Data1D |
---|
| 18 | from sans.guiframe.dataFitting import check_data_validity |
---|
| 19 | from sans.dataloader.data_info import Detector |
---|
| 20 | from sans.dataloader.data_info import Source |
---|
[cfc0913] | 21 | import pagestate |
---|
| 22 | from pagestate import PageState |
---|
[ecf26e1] | 23 | |
---|
[ef26c83] | 24 | (PageInfoEvent, EVT_PAGE_INFO) = wx.lib.newevent.NewEvent() |
---|
| 25 | (PreviousStateEvent, EVT_PREVIOUS_STATE) = wx.lib.newevent.NewEvent() |
---|
| 26 | (NextStateEvent, EVT_NEXT_STATE) = wx.lib.newevent.NewEvent() |
---|
[f72333f] | 27 | |
---|
[e7b1ccf] | 28 | _BOX_WIDTH = 76 |
---|
[6bbeacd4] | 29 | _QMIN_DEFAULT = 0.0005 |
---|
| 30 | _QMAX_DEFAULT = 0.5 |
---|
[6d8053c] | 31 | _NPTS_DEFAULT = 50 |
---|
[ef26c83] | 32 | #Control panel width |
---|
| 33 | if sys.platform.count("win32") > 0: |
---|
[b421b1a] | 34 | PANEL_WIDTH = 450 |
---|
[f1aa385] | 35 | FONT_VARIANT = 0 |
---|
[35c9d31] | 36 | ON_MAC = False |
---|
[9170547] | 37 | else: |
---|
[c99a6c5] | 38 | PANEL_WIDTH = 500 |
---|
[f1aa385] | 39 | FONT_VARIANT = 1 |
---|
[35c9d31] | 40 | ON_MAC = True |
---|
[6bbeacd4] | 41 | |
---|
| 42 | |
---|
[015d109] | 43 | class BasicPage(ScrolledPanel, PanelBase): |
---|
[c77d859] | 44 | """ |
---|
[5062bbf] | 45 | This class provide general structure of fitpanel page |
---|
[c77d859] | 46 | """ |
---|
[ef26c83] | 47 | ## Internal name for the AUI manager |
---|
[6bbeacd4] | 48 | window_name = "Fit Page" |
---|
[b787e68c] | 49 | ## Title to appear on top of the window |
---|
[6bbeacd4] | 50 | window_caption = "Fit Page " |
---|
[59a7f2d] | 51 | |
---|
[ef26c83] | 52 | def __init__(self, parent, color='blue', **kwargs): |
---|
[5062bbf] | 53 | """ |
---|
| 54 | """ |
---|
[015d109] | 55 | ScrolledPanel.__init__(self, parent, **kwargs) |
---|
[e030625] | 56 | PanelBase.__init__(self, parent) |
---|
[340c2b3] | 57 | self.SetupScrolling() |
---|
[ef26c83] | 58 | #Set window's font size |
---|
[f1aa385] | 59 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
[6bbeacd4] | 60 | |
---|
| 61 | self.SetBackgroundColour(color) |
---|
[c77d859] | 62 | ## parent of the page |
---|
| 63 | self.parent = parent |
---|
[77e23a2] | 64 | ## manager is the fitting plugin |
---|
[c77d859] | 65 | ## owner of the page (fitting plugin) |
---|
[4a7ad5f] | 66 | self.event_owner = None |
---|
[ef26c83] | 67 | ## current model |
---|
[ffa69b6] | 68 | self.model = None |
---|
[ecf26e1] | 69 | self.index_model = None |
---|
[cfc0913] | 70 | ## data |
---|
[ffa69b6] | 71 | self.data = None |
---|
[cc31608] | 72 | #list of available data |
---|
| 73 | self.data_list = [] |
---|
[e575db9] | 74 | self.mask = None |
---|
[ecf26e1] | 75 | self.uid = wx.NewId() |
---|
[5e48acb] | 76 | self.graph_id = None |
---|
[4225aed] | 77 | #Q range for data set |
---|
[a6d3553] | 78 | self.qmin_data_set = numpy.inf |
---|
[4225aed] | 79 | self.qmax_data_set = None |
---|
[67ae937] | 80 | self.npts_data_set = 0 |
---|
[0b12abb5] | 81 | ## Q range |
---|
[f95301b] | 82 | self.qmin = None |
---|
| 83 | self.qmax = None |
---|
[6bbeacd4] | 84 | self.qmax_x = _QMAX_DEFAULT |
---|
| 85 | self.qmin_x = _QMIN_DEFAULT |
---|
| 86 | self.npts_x = _NPTS_DEFAULT |
---|
[0b12abb5] | 87 | ## total number of point: float |
---|
| 88 | self.npts = None |
---|
| 89 | ## default fitengine type |
---|
[e3d1423] | 90 | self.engine_type = 'scipy' |
---|
[0b12abb5] | 91 | ## smear default |
---|
| 92 | self.current_smearer = None |
---|
| 93 | ## 2D smear accuracy default |
---|
| 94 | self.smear2d_accuracy = 'Low' |
---|
[ef26c83] | 95 | ## slit smear: |
---|
[0b12abb5] | 96 | self.dxl = None |
---|
| 97 | self.dxw = None |
---|
[ef26c83] | 98 | ## pinhole smear |
---|
[0b12abb5] | 99 | self.dx_min = None |
---|
| 100 | self.dx_max = None |
---|
| 101 | |
---|
| 102 | self.disp_cb_dict = {} |
---|
| 103 | |
---|
[ffa69b6] | 104 | self.state = PageState(parent=parent) |
---|
[c77d859] | 105 | ## dictionary containing list of models |
---|
[6bbeacd4] | 106 | self.model_list_box = {} |
---|
| 107 | |
---|
[c77d859] | 108 | ## Data member to store the dispersion object created |
---|
| 109 | self._disp_obj_dict = {} |
---|
[cfc0913] | 110 | ## selected parameters to apply dispersion |
---|
[ef26c83] | 111 | self.disp_cb_dict = {} |
---|
[997131a] | 112 | ## smearer object |
---|
[69f9084] | 113 | self.enable2D = False |
---|
[cdb042d] | 114 | self.is_mac = ON_MAC |
---|
[330573d] | 115 | |
---|
[c77d859] | 116 | ##list of model parameters. each item must have same length |
---|
| 117 | ## each item related to a given parameters |
---|
| 118 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
[4a7ad5f] | 119 | self.parameters = [] |
---|
[fb59ed9] | 120 | # non-fittable parameter whose value is astring |
---|
| 121 | self.str_parameters = [] |
---|
[c77d859] | 122 | ## list of parameters to fit , must be like self.parameters |
---|
[4a7ad5f] | 123 | self.param_toFit = [] |
---|
[c77d859] | 124 | ## list of looking like parameters but with non fittable parameters info |
---|
[4a7ad5f] | 125 | self.fixed_param = [] |
---|
[c77d859] | 126 | ## list of looking like parameters but with fittable parameters info |
---|
[4a7ad5f] | 127 | self.fittable_param = [] |
---|
[c77d859] | 128 | ##list of dispersion parameters |
---|
[4a7ad5f] | 129 | self.disp_list = [] |
---|
| 130 | self.disp_name = "" |
---|
[ffa69b6] | 131 | |
---|
[780d095] | 132 | ## list of orientation parameters |
---|
[4a7ad5f] | 133 | self.orientation_params = [] |
---|
| 134 | self.orientation_params_disp = [] |
---|
| 135 | if self.model != None: |
---|
| 136 | self.disp_list = self.model.getDispParamList() |
---|
[8960479] | 137 | self.temp_multi_functional = False |
---|
[c77d859] | 138 | ##enable model 2D draw |
---|
[4a7ad5f] | 139 | self.enable2D = False |
---|
[c77d859] | 140 | ## check that the fit range is correct to plot the model again |
---|
[4a7ad5f] | 141 | self.fitrange = True |
---|
[1b69256] | 142 | ## Create memento to save the current state |
---|
[4a7ad5f] | 143 | self.state = PageState(parent=self.parent, |
---|
| 144 | model=self.model, data=self.data) |
---|
[240b9966] | 145 | ## flag to determine if state has change |
---|
[4a7ad5f] | 146 | self.state_change = False |
---|
[71f0373] | 147 | ## save customized array |
---|
[4a7ad5f] | 148 | self.values = [] |
---|
| 149 | self.weights = [] |
---|
[a074145] | 150 | ## retrieve saved state |
---|
[4a7ad5f] | 151 | self.number_saved_state = 0 |
---|
[a074145] | 152 | ## dictionary of saved state |
---|
[ef26c83] | 153 | self.saved_states = {} |
---|
[1b69256] | 154 | ## Create context menu for page |
---|
| 155 | self.popUpMenu = wx.Menu() |
---|
[6bbeacd4] | 156 | |
---|
[6d91073] | 157 | id = wx.NewId() |
---|
[ef26c83] | 158 | self._keep = wx.MenuItem(self.popUpMenu, id, "Add bookmark", |
---|
[4a7ad5f] | 159 | " Keep the panel status to recall it later") |
---|
[6d91073] | 160 | self.popUpMenu.AppendItem(self._keep) |
---|
[2657df9] | 161 | self._keep.Enable(False) |
---|
[20b228a0] | 162 | self._set_bookmark_flag(False) |
---|
| 163 | self._set_save_flag(False) |
---|
[9bc499b6] | 164 | wx.EVT_MENU(self, id, self.on_bookmark) |
---|
[6d91073] | 165 | self.popUpMenu.AppendSeparator() |
---|
| 166 | |
---|
[60132ef] | 167 | ## Default locations |
---|
[ef26c83] | 168 | self._default_save_location = os.getcwd() |
---|
[a074145] | 169 | ## save initial state on context menu |
---|
[1b69256] | 170 | #self.onSave(event=None) |
---|
[a074145] | 171 | self.Bind(wx.EVT_CONTEXT_MENU, self.onContextMenu) |
---|
[2296316] | 172 | |
---|
| 173 | # bind key event |
---|
| 174 | self.Bind(wx.EVT_LEFT_DOWN, self.on_left_down) |
---|
[c31fd9f] | 175 | |
---|
[cfc0913] | 176 | ## create the basic structure of the panel with empty sizer |
---|
| 177 | self.define_page_structure() |
---|
[ef26c83] | 178 | ## drawing Initial dispersion parameters sizer |
---|
[c77d859] | 179 | self.set_dispers_sizer() |
---|
[20b228a0] | 180 | |
---|
[c77d859] | 181 | ## layout |
---|
| 182 | self.set_layout() |
---|
[92f5521a] | 183 | |
---|
[ecf26e1] | 184 | def set_index_model(self, index): |
---|
| 185 | """ |
---|
| 186 | Index related to this page |
---|
| 187 | """ |
---|
| 188 | self.index_model = index |
---|
| 189 | |
---|
| 190 | def create_default_data(self): |
---|
| 191 | """ |
---|
[ef26c83] | 192 | Given the user selection, creates a 1D or 2D data |
---|
[ecf26e1] | 193 | Only when the page is on theory mode. |
---|
| 194 | """ |
---|
[6e4c9fe] | 195 | if not hasattr(self, "model_view"): |
---|
| 196 | return |
---|
| 197 | toggle_mode_on = self.model_view.IsEnabled() |
---|
| 198 | if toggle_mode_on: |
---|
| 199 | if self.enable2D and not check_data_validity(self.data): |
---|
| 200 | self._create_default_2d_data() |
---|
| 201 | else: |
---|
| 202 | self._create_default_1d_data() |
---|
[33477fd] | 203 | if self.model != None: |
---|
| 204 | if not self.data.is_data: |
---|
| 205 | self._manager.page_finder[self.uid].set_fit_data(data=[self.data]) |
---|
| 206 | self.on_smear_helper(update=True) |
---|
[ef26c83] | 207 | self.state.enable_smearer = self.enable_smearer.GetValue() |
---|
| 208 | self.state.disable_smearer = self.disable_smearer.GetValue() |
---|
[33477fd] | 209 | self.state.pinhole_smearer = self.pinhole_smearer.GetValue() |
---|
| 210 | self.state.slit_smearer = self.slit_smearer.GetValue() |
---|
[ecf26e1] | 211 | |
---|
| 212 | def _create_default_1d_data(self): |
---|
| 213 | """ |
---|
[ef26c83] | 214 | Create default data for fitting perspective |
---|
[ecf26e1] | 215 | Only when the page is on theory mode. |
---|
| 216 | :warning: This data is never plotted. |
---|
| 217 | |
---|
| 218 | """ |
---|
[ef26c83] | 219 | x = numpy.linspace(start=self.qmin_x, stop=self.qmax_x, |
---|
[ecf26e1] | 220 | num=self.npts_x, endpoint=True) |
---|
| 221 | self.data = Data1D(x=x) |
---|
[ef26c83] | 222 | self.data.xaxis('\\rm{Q}', "A^{-1}") |
---|
[ecf26e1] | 223 | self.data.yaxis('\\rm{Intensity}', "cm^{-1}") |
---|
| 224 | self.data.is_data = False |
---|
[ef26c83] | 225 | self.data.id = str(self.uid) + " data" |
---|
| 226 | self.data.group_id = str(self.uid) + " Model1D" |
---|
[ecf26e1] | 227 | |
---|
| 228 | def _create_default_2d_data(self): |
---|
| 229 | """ |
---|
| 230 | Create 2D data by default |
---|
| 231 | Only when the page is on theory mode. |
---|
| 232 | :warning: This data is never plotted. |
---|
| 233 | """ |
---|
| 234 | self.data = Data2D() |
---|
[2e95da4] | 235 | qmax = self.qmax_x / math.sqrt(2) |
---|
[ecf26e1] | 236 | self.data.xaxis('\\rm{Q_{x}}', 'A^{-1}') |
---|
| 237 | self.data.yaxis('\\rm{Q_{y}}', 'A^{-1}') |
---|
| 238 | self.data.is_data = False |
---|
[ef26c83] | 239 | self.data.id = str(self.uid) + " data" |
---|
| 240 | self.data.group_id = str(self.uid) + " Model2D" |
---|
| 241 | ## Default values |
---|
| 242 | self.data.detector.append(Detector()) |
---|
[ecf26e1] | 243 | index = len(self.data.detector) - 1 |
---|
[ef26c83] | 244 | self.data.detector[index].distance = 8000 # mm |
---|
| 245 | self.data.source.wavelength = 6 # A |
---|
[ecf26e1] | 246 | self.data.detector[index].pixel_size.x = 5 # mm |
---|
| 247 | self.data.detector[index].pixel_size.y = 5 # mm |
---|
| 248 | self.data.detector[index].beam_center.x = qmax |
---|
| 249 | self.data.detector[index].beam_center.y = qmax |
---|
| 250 | ## create x_bins and y_bins of the model 2D |
---|
[ef26c83] | 251 | #pixel_width_x = self.data.detector[index].pixel_size.x |
---|
| 252 | #pixel_width_y = self.data.detector[index].pixel_size.y |
---|
| 253 | #center_x = self.data.detector[index].beam_center.x/pixel_width_x |
---|
| 254 | #center_y = self.data.detector[index].beam_center.y/pixel_width_y |
---|
| 255 | # theory default: assume the beam |
---|
[ecf26e1] | 256 | #center is located at the center of sqr detector |
---|
[ef26c83] | 257 | xmax = qmax |
---|
[32cd80c] | 258 | xmin = -qmax |
---|
| 259 | ymax = qmax |
---|
| 260 | ymin = -qmax |
---|
[ecf26e1] | 261 | qstep = self.npts_x |
---|
[2e95da4] | 262 | |
---|
[ef26c83] | 263 | x = numpy.linspace(start=xmin, stop=xmax, num=qstep, endpoint=True) |
---|
[ecf26e1] | 264 | y = numpy.linspace(start=ymin, stop=ymax, num=qstep, endpoint=True) |
---|
| 265 | ## use data info instead |
---|
| 266 | new_x = numpy.tile(x, (len(y), 1)) |
---|
| 267 | new_y = numpy.tile(y, (len(x), 1)) |
---|
[ef26c83] | 268 | new_y = new_y.swapaxes(0, 1) |
---|
[ecf26e1] | 269 | # all data reuire now in 1d array |
---|
| 270 | qx_data = new_x.flatten() |
---|
| 271 | qy_data = new_y.flatten() |
---|
[ef26c83] | 272 | q_data = numpy.sqrt(qx_data * qx_data + qy_data * qy_data) |
---|
[ecf26e1] | 273 | # set all True (standing for unmasked) as default |
---|
| 274 | mask = numpy.ones(len(qx_data), dtype=bool) |
---|
| 275 | # calculate the range of qx and qy: this way, |
---|
| 276 | # it is a little more independent |
---|
[ef26c83] | 277 | #x_size = xmax - xmin |
---|
| 278 | #y_size = ymax - ymin |
---|
[ecf26e1] | 279 | # store x and y bin centers in q space |
---|
[ef26c83] | 280 | x_bins = x |
---|
| 281 | y_bins = y |
---|
[ecf26e1] | 282 | # bin size: x- & y-directions |
---|
[ef26c83] | 283 | #xstep = x_size / len(x_bins - 1) |
---|
| 284 | #ystep = y_size / len(y_bins - 1) |
---|
[32cd80c] | 285 | |
---|
[ecf26e1] | 286 | self.data.source = Source() |
---|
[32cd80c] | 287 | self.data.data = numpy.ones(len(mask)) |
---|
[ecf26e1] | 288 | self.data.err_data = numpy.ones(len(mask)) |
---|
[ef26c83] | 289 | self.data.qx_data = qx_data |
---|
| 290 | self.data.qy_data = qy_data |
---|
| 291 | self.data.q_data = q_data |
---|
| 292 | self.data.mask = mask |
---|
| 293 | self.data.x_bins = x_bins |
---|
| 294 | self.data.y_bins = y_bins |
---|
[ecf26e1] | 295 | # max and min taking account of the bin sizes |
---|
[ef26c83] | 296 | self.data.xmin = xmin |
---|
[ecf26e1] | 297 | self.data.xmax = xmax |
---|
[ef26c83] | 298 | self.data.ymin = ymin |
---|
| 299 | self.data.ymax = ymax |
---|
[2e95da4] | 300 | |
---|
[3cd5806] | 301 | def on_set_focus(self, event): |
---|
| 302 | """ |
---|
[dafc36f] | 303 | On Set Focus, update guimanger and menu |
---|
[3cd5806] | 304 | """ |
---|
| 305 | if self._manager is not None: |
---|
| 306 | wx.PostEvent(self._manager.parent, PanelOnFocusEvent(panel=self)) |
---|
[58fc26c] | 307 | self.on_tap_focus() |
---|
[dafc36f] | 308 | |
---|
[58fc26c] | 309 | def on_tap_focus(self): |
---|
| 310 | """ |
---|
| 311 | Update menu1 on cliking the page tap |
---|
| 312 | """ |
---|
| 313 | if self._manager.menu1 != None: |
---|
| 314 | chain_menu = self._manager.menu1.FindItemById(\ |
---|
[ef26c83] | 315 | self._manager.id_reset_flag) |
---|
[58fc26c] | 316 | chain_menu.Enable(self.batch_on) |
---|
| 317 | sim_menu = self._manager.menu1.FindItemById(self._manager.id_simfit) |
---|
[fa02d95] | 318 | flag = self.data.is_data\ |
---|
[ef26c83] | 319 | and (self.model != None) |
---|
[fa02d95] | 320 | sim_menu.Enable(not self.batch_on and flag) |
---|
| 321 | batch_menu = self._manager.menu1.FindItemById(self._manager.id_batchfit) |
---|
[ef26c83] | 322 | batch_menu.Enable(self.batch_on and flag) |
---|
[58fc26c] | 323 | |
---|
[6f2c919] | 324 | class ModelTextCtrl(wx.TextCtrl): |
---|
| 325 | """ |
---|
[5062bbf] | 326 | Text control for model and fit parameters. |
---|
| 327 | Binds the appropriate events for user interactions. |
---|
| 328 | Default callback methods can be overwritten on initialization |
---|
| 329 | |
---|
| 330 | :param kill_focus_callback: callback method for EVT_KILL_FOCUS event |
---|
| 331 | :param set_focus_callback: callback method for EVT_SET_FOCUS event |
---|
| 332 | :param mouse_up_callback: callback method for EVT_LEFT_UP event |
---|
| 333 | :param text_enter_callback: callback method for EVT_TEXT_ENTER event |
---|
| 334 | |
---|
[6f2c919] | 335 | """ |
---|
[39b7019] | 336 | ## Set to True when the mouse is clicked while the whole string is selected |
---|
| 337 | full_selection = False |
---|
| 338 | ## Call back for EVT_SET_FOCUS events |
---|
| 339 | _on_set_focus_callback = None |
---|
| 340 | |
---|
[ef26c83] | 341 | def __init__(self, parent, id=-1, |
---|
| 342 | value=wx.EmptyString, |
---|
| 343 | pos=wx.DefaultPosition, |
---|
[4a7ad5f] | 344 | size=wx.DefaultSize, |
---|
[ef26c83] | 345 | style=0, |
---|
[4a7ad5f] | 346 | validator=wx.DefaultValidator, |
---|
| 347 | name=wx.TextCtrlNameStr, |
---|
| 348 | kill_focus_callback=None, |
---|
| 349 | set_focus_callback=None, |
---|
| 350 | mouse_up_callback=None, |
---|
[ef26c83] | 351 | text_enter_callback=None): |
---|
[7975f2b] | 352 | |
---|
[4a7ad5f] | 353 | wx.TextCtrl.__init__(self, parent, id, value, pos, |
---|
| 354 | size, style, validator, name) |
---|
[6f2c919] | 355 | |
---|
[156a0b2] | 356 | # Bind appropriate events |
---|
| 357 | self._on_set_focus_callback = parent.onSetFocus \ |
---|
| 358 | if set_focus_callback is None else set_focus_callback |
---|
| 359 | self.Bind(wx.EVT_SET_FOCUS, self._on_set_focus) |
---|
[7609f1a] | 360 | self.Bind(wx.EVT_KILL_FOCUS, self._silent_kill_focus \ |
---|
[ef26c83] | 361 | if kill_focus_callback is None else kill_focus_callback) |
---|
[6f2c919] | 362 | self.Bind(wx.EVT_TEXT_ENTER, parent._onparamEnter \ |
---|
| 363 | if text_enter_callback is None else text_enter_callback) |
---|
[ef26c83] | 364 | if not ON_MAC: |
---|
| 365 | self.Bind(wx.EVT_LEFT_UP, self._highlight_text \ |
---|
[35c9d31] | 366 | if mouse_up_callback is None else mouse_up_callback) |
---|
[39b7019] | 367 | |
---|
| 368 | def _on_set_focus(self, event): |
---|
| 369 | """ |
---|
[5062bbf] | 370 | Catch when the text control is set in focus to highlight the whole |
---|
| 371 | text if necessary |
---|
| 372 | |
---|
| 373 | :param event: mouse event |
---|
| 374 | |
---|
[39b7019] | 375 | """ |
---|
| 376 | event.Skip() |
---|
| 377 | self.full_selection = True |
---|
| 378 | return self._on_set_focus_callback(event) |
---|
| 379 | |
---|
| 380 | def _highlight_text(self, event): |
---|
| 381 | """ |
---|
[5062bbf] | 382 | Highlight text of a TextCtrl only of no text has be selected |
---|
| 383 | |
---|
| 384 | :param event: mouse event |
---|
| 385 | |
---|
[39b7019] | 386 | """ |
---|
| 387 | # Make sure the mouse event is available to other listeners |
---|
| 388 | event.Skip() |
---|
[ef26c83] | 389 | control = event.GetEventObject() |
---|
[39b7019] | 390 | if self.full_selection: |
---|
| 391 | self.full_selection = False |
---|
| 392 | # Check that we have a TextCtrl |
---|
| 393 | if issubclass(control.__class__, wx.TextCtrl): |
---|
[ef26c83] | 394 | # Check whether text has been selected, |
---|
[39b7019] | 395 | # if not, select the whole string |
---|
| 396 | (start, end) = control.GetSelection() |
---|
[ef26c83] | 397 | if start == end: |
---|
| 398 | control.SetSelection(-1, -1) |
---|
[7609f1a] | 399 | |
---|
[ef26c83] | 400 | def _silent_kill_focus(self, event): |
---|
[7609f1a] | 401 | """ |
---|
[3c44c66] | 402 | Save the state of the page |
---|
[7609f1a] | 403 | """ |
---|
[3c44c66] | 404 | |
---|
[7609f1a] | 405 | event.Skip() |
---|
| 406 | pass |
---|
| 407 | |
---|
[ffa69b6] | 408 | def set_page_info(self, page_info): |
---|
| 409 | """ |
---|
[5062bbf] | 410 | set some page important information at once |
---|
[ffa69b6] | 411 | """ |
---|
[ef26c83] | 412 | ##window_name |
---|
[ffa69b6] | 413 | self.window_name = page_info.window_name |
---|
| 414 | ##window_caption |
---|
| 415 | self.window_caption = page_info.window_caption |
---|
| 416 | ## manager is the fitting plugin |
---|
[ef26c83] | 417 | self._manager = page_info.manager |
---|
[ffa69b6] | 418 | ## owner of the page (fitting plugin) |
---|
[ef26c83] | 419 | self.event_owner = page_info.event_owner |
---|
| 420 | ## current model |
---|
[ffa69b6] | 421 | self.model = page_info.model |
---|
| 422 | ## data |
---|
| 423 | self.data = page_info.data |
---|
| 424 | ## dictionary containing list of models |
---|
| 425 | self.model_list_box = page_info.model_list_box |
---|
| 426 | ## Data member to store the dispersion object created |
---|
| 427 | self.populate_box(dict=self.model_list_box) |
---|
| 428 | |
---|
[ef26c83] | 429 | def onContextMenu(self, event): |
---|
[a074145] | 430 | """ |
---|
[5062bbf] | 431 | Retrieve the state selected state |
---|
[a074145] | 432 | """ |
---|
[6d1235b] | 433 | # Skipping the save state functionality for release 0.9.0 |
---|
[dad49a0] | 434 | #return |
---|
[6d1235b] | 435 | |
---|
[a074145] | 436 | pos = event.GetPosition() |
---|
| 437 | pos = self.ScreenToClient(pos) |
---|
[1b69256] | 438 | |
---|
[ef26c83] | 439 | self.PopupMenu(self.popUpMenu, pos) |
---|
[1b69256] | 440 | |
---|
| 441 | def onUndo(self, event): |
---|
| 442 | """ |
---|
[5062bbf] | 443 | Cancel the previous action |
---|
[1b69256] | 444 | """ |
---|
[ef26c83] | 445 | event = PreviousStateEvent(page=self) |
---|
[330573d] | 446 | wx.PostEvent(self.parent, event) |
---|
| 447 | |
---|
[1b69256] | 448 | def onRedo(self, event): |
---|
| 449 | """ |
---|
[ef26c83] | 450 | Restore the previous action cancelled |
---|
[1b69256] | 451 | """ |
---|
[ef26c83] | 452 | event = NextStateEvent(page=self) |
---|
[330573d] | 453 | wx.PostEvent(self.parent, event) |
---|
[5062bbf] | 454 | |
---|
[c77d859] | 455 | def define_page_structure(self): |
---|
| 456 | """ |
---|
[5062bbf] | 457 | Create empty sizer for a panel |
---|
[c77d859] | 458 | """ |
---|
[ef26c83] | 459 | self.vbox = wx.BoxSizer(wx.VERTICAL) |
---|
[c77d859] | 460 | self.sizer0 = wx.BoxSizer(wx.VERTICAL) |
---|
| 461 | self.sizer1 = wx.BoxSizer(wx.VERTICAL) |
---|
| 462 | self.sizer2 = wx.BoxSizer(wx.VERTICAL) |
---|
| 463 | self.sizer3 = wx.BoxSizer(wx.VERTICAL) |
---|
| 464 | self.sizer4 = wx.BoxSizer(wx.VERTICAL) |
---|
| 465 | self.sizer5 = wx.BoxSizer(wx.VERTICAL) |
---|
[0a518e4c] | 466 | self.sizer6 = wx.BoxSizer(wx.VERTICAL) |
---|
[c77d859] | 467 | |
---|
[ef26c83] | 468 | self.sizer0.SetMinSize((PANEL_WIDTH, -1)) |
---|
| 469 | self.sizer1.SetMinSize((PANEL_WIDTH, -1)) |
---|
| 470 | self.sizer2.SetMinSize((PANEL_WIDTH, -1)) |
---|
| 471 | self.sizer3.SetMinSize((PANEL_WIDTH, -1)) |
---|
| 472 | self.sizer4.SetMinSize((PANEL_WIDTH, -1)) |
---|
| 473 | self.sizer5.SetMinSize((PANEL_WIDTH, -1)) |
---|
| 474 | self.sizer6.SetMinSize((PANEL_WIDTH, -1)) |
---|
[8bd4dc0] | 475 | |
---|
[c77d859] | 476 | self.vbox.Add(self.sizer0) |
---|
| 477 | self.vbox.Add(self.sizer1) |
---|
| 478 | self.vbox.Add(self.sizer2) |
---|
| 479 | self.vbox.Add(self.sizer3) |
---|
| 480 | self.vbox.Add(self.sizer4) |
---|
| 481 | self.vbox.Add(self.sizer5) |
---|
[0b12abb5] | 482 | self.vbox.Add(self.sizer6) |
---|
[a074145] | 483 | |
---|
[c77d859] | 484 | def set_layout(self): |
---|
| 485 | """ |
---|
[5062bbf] | 486 | layout |
---|
[c77d859] | 487 | """ |
---|
| 488 | self.vbox.Layout() |
---|
[ef26c83] | 489 | self.vbox.Fit(self) |
---|
[c77d859] | 490 | self.SetSizer(self.vbox) |
---|
| 491 | self.Centre() |
---|
[340c2b3] | 492 | |
---|
[ef26c83] | 493 | def set_owner(self, owner): |
---|
| 494 | """ |
---|
[5062bbf] | 495 | set owner of fitpage |
---|
| 496 | |
---|
| 497 | :param owner: the class responsible of plotting |
---|
| 498 | |
---|
[c77d859] | 499 | """ |
---|
[ef26c83] | 500 | self.event_owner = owner |
---|
[cfc0913] | 501 | self.state.event_owner = owner |
---|
[7609f1a] | 502 | |
---|
[c8deee5] | 503 | def get_state(self): |
---|
| 504 | """ |
---|
| 505 | """ |
---|
| 506 | return self.state |
---|
[cc31608] | 507 | |
---|
[2f189dc] | 508 | def get_data(self): |
---|
| 509 | """ |
---|
[ef26c83] | 510 | return the current data |
---|
[2f189dc] | 511 | """ |
---|
[ef26c83] | 512 | return self.data |
---|
[7609f1a] | 513 | |
---|
[cc31608] | 514 | def get_data_list(self): |
---|
| 515 | """ |
---|
[ef26c83] | 516 | return the current data |
---|
[cc31608] | 517 | """ |
---|
[ef26c83] | 518 | return self.data_list |
---|
[cc31608] | 519 | |
---|
[c77d859] | 520 | def set_manager(self, manager): |
---|
| 521 | """ |
---|
[5062bbf] | 522 | set panel manager |
---|
| 523 | |
---|
| 524 | :param manager: instance of plugin fitting |
---|
| 525 | |
---|
[c77d859] | 526 | """ |
---|
[ef26c83] | 527 | self._manager = manager |
---|
[cfc0913] | 528 | self.state.manager = manager |
---|
[c77d859] | 529 | |
---|
| 530 | def populate_box(self, dict): |
---|
| 531 | """ |
---|
[5062bbf] | 532 | Store list of model |
---|
| 533 | |
---|
| 534 | :param dict: dictionary containing list of models |
---|
| 535 | |
---|
[c77d859] | 536 | """ |
---|
| 537 | self.model_list_box = dict |
---|
[cfc0913] | 538 | self.state.model_list_box = self.model_list_box |
---|
[6bbeacd4] | 539 | self.initialize_combox() |
---|
[c77d859] | 540 | |
---|
[ef26c83] | 541 | def initialize_combox(self): |
---|
[ffa69b6] | 542 | """ |
---|
[ef26c83] | 543 | put default value in the combobox |
---|
[ffa69b6] | 544 | """ |
---|
| 545 | ## fill combox box |
---|
| 546 | if self.model_list_box is None: |
---|
| 547 | return |
---|
[4a7ad5f] | 548 | if len(self.model_list_box) > 0: |
---|
| 549 | self._populate_box(self.formfactorbox, |
---|
| 550 | self.model_list_box["Shapes"]) |
---|
[ffa69b6] | 551 | |
---|
[4a7ad5f] | 552 | if len(self.model_list_box) > 0: |
---|
| 553 | self._populate_box(self.structurebox, |
---|
[ffa69b6] | 554 | self.model_list_box["Structure Factors"]) |
---|
[4a7ad5f] | 555 | self.structurebox.Insert("None", 0, None) |
---|
[ffa69b6] | 556 | self.structurebox.SetSelection(0) |
---|
| 557 | self.structurebox.Hide() |
---|
| 558 | self.text2.Hide() |
---|
| 559 | self.structurebox.Disable() |
---|
| 560 | self.text2.Disable() |
---|
| 561 | |
---|
| 562 | if self.model.__class__ in self.model_list_box["P(Q)*S(Q)"]: |
---|
| 563 | self.structurebox.Show() |
---|
| 564 | self.text2.Show() |
---|
| 565 | self.structurebox.Enable() |
---|
[ef26c83] | 566 | self.text2.Enable() |
---|
[ffa69b6] | 567 | |
---|
[c77d859] | 568 | def set_dispers_sizer(self): |
---|
| 569 | """ |
---|
[5062bbf] | 570 | fill sizer containing dispersity info |
---|
[c77d859] | 571 | """ |
---|
| 572 | self.sizer4.Clear(True) |
---|
[ef26c83] | 573 | name = "Polydispersity and Orientational Distribution" |
---|
| 574 | box_description = wx.StaticBox(self, -1, name) |
---|
[de5036c] | 575 | box_description.SetForegroundColour(wx.BLUE) |
---|
[c77d859] | 576 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 577 | #---------------------------------------------------- |
---|
[4a7ad5f] | 578 | self.disable_disp = wx.RadioButton(self, -1, 'Off', (10, 10), |
---|
| 579 | style=wx.RB_GROUP) |
---|
[fa58441] | 580 | self.enable_disp = wx.RadioButton(self, -1, 'On', (10, 30)) |
---|
[6f23daf] | 581 | # best size for MAC and PC |
---|
| 582 | if ON_MAC: |
---|
[ef26c83] | 583 | size_q = (30, 20) |
---|
[6f23daf] | 584 | else: |
---|
[ef26c83] | 585 | size_q = (20, 15) |
---|
| 586 | self.disp_help_bt = wx.Button(self, wx.NewId(), '?', |
---|
| 587 | style=wx.BU_EXACTFIT, |
---|
[6f23daf] | 588 | size=size_q) |
---|
[ef26c83] | 589 | self.disp_help_bt.Bind(wx.EVT_BUTTON, |
---|
| 590 | self.on_pd_help_clicked, id=self.disp_help_bt.GetId()) |
---|
| 591 | self.disp_help_bt.SetToolTipString("Helps for Polydispersion.") |
---|
[cfc0913] | 592 | |
---|
[4a7ad5f] | 593 | self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, |
---|
| 594 | id=self.disable_disp.GetId()) |
---|
| 595 | self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, |
---|
| 596 | id=self.enable_disp.GetId()) |
---|
[ff8f99b] | 597 | #MAC needs SetValue |
---|
| 598 | self.disable_disp.SetValue(True) |
---|
[c77d859] | 599 | sizer_dispersion = wx.BoxSizer(wx.HORIZONTAL) |
---|
[ef26c83] | 600 | sizer_dispersion.Add((20, 20)) |
---|
| 601 | name = "" # Polydispersity and \nOrientational Distribution " |
---|
| 602 | sizer_dispersion.Add(wx.StaticText(self, -1, name)) |
---|
| 603 | sizer_dispersion.Add(self.enable_disp) |
---|
| 604 | sizer_dispersion.Add((20, 20)) |
---|
| 605 | sizer_dispersion.Add(self.disable_disp) |
---|
| 606 | sizer_dispersion.Add((25, 20)) |
---|
[2296316] | 607 | sizer_dispersion.Add(self.disp_help_bt) |
---|
[c77d859] | 608 | |
---|
[ef26c83] | 609 | ## fill a sizer for dispersion |
---|
| 610 | boxsizer1.Add(sizer_dispersion, 0, |
---|
| 611 | wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, |
---|
| 612 | border=5) |
---|
| 613 | self.sizer4_4 = wx.GridBagSizer(6, 5) |
---|
[2296316] | 614 | |
---|
[ef26c83] | 615 | boxsizer1.Add(self.sizer4_4) |
---|
[c77d859] | 616 | #----------------------------------------------------- |
---|
[ef26c83] | 617 | self.sizer4.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) |
---|
[3b605bb] | 618 | self.sizer4_4.Layout() |
---|
[c77d859] | 619 | self.sizer4.Layout() |
---|
[3b605bb] | 620 | self.Layout() |
---|
[340c2b3] | 621 | |
---|
[3b605bb] | 622 | self.Refresh() |
---|
[71f0373] | 623 | ## saving the state of enable dispersity button |
---|
[ef26c83] | 624 | self.state.enable_disp = self.enable_disp.GetValue() |
---|
| 625 | self.state.disable_disp = self.disable_disp.GetValue() |
---|
[ce92ded] | 626 | self.SetupScrolling() |
---|
[a074145] | 627 | |
---|
| 628 | def onResetModel(self, event): |
---|
| 629 | """ |
---|
[5062bbf] | 630 | Reset model state |
---|
[a074145] | 631 | """ |
---|
[20b228a0] | 632 | menu = event.GetEventObject() |
---|
[ef26c83] | 633 | ## post help message for the selected model |
---|
[20b228a0] | 634 | msg = menu.GetHelpString(event.GetId()) |
---|
[ef26c83] | 635 | msg += " reloaded" |
---|
[20b228a0] | 636 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
[01642fec] | 637 | self.Show(False) |
---|
[20b228a0] | 638 | name = menu.GetLabel(event.GetId()) |
---|
[cbf01fd] | 639 | self._on_select_model_helper() |
---|
[93f0a862] | 640 | if self.model != None: |
---|
| 641 | self.m_name = self.model.name |
---|
[a074145] | 642 | if name in self.saved_states.keys(): |
---|
| 643 | previous_state = self.saved_states[name] |
---|
[f20767b] | 644 | ## reset state of checkbox,textcrtl and regular parameters value |
---|
[01642fec] | 645 | |
---|
[ef26c83] | 646 | self.reset_page(previous_state) |
---|
[93f0a862] | 647 | self.state.m_name = self.m_name |
---|
[01642fec] | 648 | self.Show(True) |
---|
[2296316] | 649 | |
---|
[aad74b3] | 650 | def on_preview(self, event): |
---|
[2296316] | 651 | """ |
---|
| 652 | Report the current fit results |
---|
[ef26c83] | 653 | """ |
---|
[2296316] | 654 | # Get plot image from plotpanel |
---|
| 655 | images, canvases = self.get_images() |
---|
| 656 | # get the report dialog |
---|
| 657 | self.state.report(images, canvases) |
---|
| 658 | |
---|
[ef26c83] | 659 | def on_save(self, event): |
---|
[9bc499b6] | 660 | """ |
---|
[5062bbf] | 661 | Save the current state into file |
---|
[ef26c83] | 662 | """ |
---|
[bb70474] | 663 | self.save_current_state() |
---|
| 664 | new_state = self.state.clone() |
---|
| 665 | # Ask the user the location of the file to write to. |
---|
| 666 | path = None |
---|
[ef26c83] | 667 | if self.parent != None: |
---|
[baf1ef3] | 668 | self._default_save_location = \ |
---|
| 669 | self.parent.parent._default_save_location |
---|
[bb70474] | 670 | dlg = wx.FileDialog(self, "Choose a file", self._default_save_location, |
---|
[baf1ef3] | 671 | self.window_caption, "*.fitv", wx.SAVE) |
---|
| 672 | |
---|
[bb70474] | 673 | if dlg.ShowModal() == wx.ID_OK: |
---|
| 674 | path = dlg.GetPath() |
---|
| 675 | self._default_save_location = os.path.dirname(path) |
---|
[baf1ef3] | 676 | self.parent.parent._default_save_location =\ |
---|
| 677 | self._default_save_location |
---|
[bb70474] | 678 | else: |
---|
| 679 | return None |
---|
[23cdeab] | 680 | # MAC always needs the extension for saving |
---|
| 681 | extens = ".fitv" |
---|
| 682 | # Make sure the ext included in the file name |
---|
| 683 | fName = os.path.splitext(path)[0] + extens |
---|
[bb70474] | 684 | #the manager write the state into file |
---|
[23cdeab] | 685 | self._manager.save_fit_state(filepath=fName, fitstate=new_state) |
---|
[ef26c83] | 686 | return new_state |
---|
[0b12abb5] | 687 | |
---|
[07c8630] | 688 | def on_copy(self, event): |
---|
| 689 | """ |
---|
| 690 | Copy Parameter values to the clipboad |
---|
| 691 | """ |
---|
| 692 | if event != None: |
---|
| 693 | event.Skip() |
---|
[2d603a2] | 694 | # It seems MAC needs wxCallAfter |
---|
[6694604] | 695 | wx.CallAfter(self.get_copy) |
---|
[2d603a2] | 696 | |
---|
[07c8630] | 697 | def on_paste(self, event): |
---|
| 698 | """ |
---|
| 699 | Paste Parameter values to the panel if possible |
---|
| 700 | """ |
---|
| 701 | if event != None: |
---|
| 702 | event.Skip() |
---|
[ef26c83] | 703 | # It seems MAC needs wxCallAfter for the setvalues |
---|
| 704 | # for multiple textctrl items, otherwise it tends to crash once a while |
---|
[6694604] | 705 | wx.CallAfter(self.get_paste) |
---|
[07c8630] | 706 | # messages depending on the flag |
---|
[977a965] | 707 | #self._copy_info(True) |
---|
[07c8630] | 708 | |
---|
| 709 | def _copy_info(self, flag): |
---|
| 710 | """ |
---|
| 711 | Send event dpemding on flag |
---|
| 712 | |
---|
| 713 | : Param flag: flag that distinguish event |
---|
| 714 | """ |
---|
| 715 | # messages depending on the flag |
---|
| 716 | if flag == None: |
---|
| 717 | msg = " Parameter values are copied to the clipboard..." |
---|
| 718 | infor = 'warning' |
---|
| 719 | elif flag: |
---|
| 720 | msg = " Parameter values are pasted from the clipboad..." |
---|
| 721 | infor = "warning" |
---|
| 722 | else: |
---|
| 723 | msg = "Error was occured " |
---|
| 724 | msg += ": No valid parameter values to paste from the clipboard..." |
---|
| 725 | infor = "error" |
---|
| 726 | # inform msg to wx |
---|
[ef26c83] | 727 | wx.PostEvent(self.parent.parent, |
---|
| 728 | StatusEvent(status=msg, info=infor)) |
---|
[07c8630] | 729 | |
---|
[20b228a0] | 730 | def _get_time_stamp(self): |
---|
| 731 | """ |
---|
| 732 | return time and date stings |
---|
| 733 | """ |
---|
[ef26c83] | 734 | # date and time |
---|
| 735 | year, month, day, hour, minute, second, tda, ty, tm_isdst \ |
---|
| 736 | = time.localtime() |
---|
| 737 | current_time = str(hour) + ":" + str(minute) + ":" + str(second) |
---|
| 738 | current_date = str(month) + "/" + str(day) + "/" + str(year) |
---|
[20b228a0] | 739 | return current_time, current_date |
---|
| 740 | |
---|
[9bc499b6] | 741 | def on_bookmark(self, event): |
---|
[00c3aac] | 742 | """ |
---|
[5062bbf] | 743 | save history of the data and model |
---|
[00c3aac] | 744 | """ |
---|
[ef26c83] | 745 | if self.model == None: |
---|
| 746 | msg = "Can not bookmark; Please select Data and Model first..." |
---|
[4470b10] | 747 | wx.MessageBox(msg, 'Info') |
---|
[ef26c83] | 748 | return |
---|
[0b12abb5] | 749 | self.save_current_state() |
---|
| 750 | new_state = self.state.clone() |
---|
| 751 | ##Add model state on context menu |
---|
| 752 | self.number_saved_state += 1 |
---|
[20b228a0] | 753 | current_time, current_date = self._get_time_stamp() |
---|
[ef26c83] | 754 | #name= self.model.name+"[%g]"%self.number_saved_state |
---|
| 755 | name = "Fitting: %g]" % self.number_saved_state |
---|
| 756 | name += self.model.__class__.__name__ |
---|
[20b228a0] | 757 | name += "bookmarked at %s on %s" % (current_time, current_date) |
---|
[ef26c83] | 758 | self.saved_states[name] = new_state |
---|
[0b12abb5] | 759 | |
---|
| 760 | ## Add item in the context menu |
---|
[ef26c83] | 761 | msg = "Model saved at %s on %s" % (current_time, current_date) |
---|
| 762 | ## post help message for the selected model |
---|
| 763 | msg += " Saved! right click on this page to retrieve this model" |
---|
| 764 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
[0b12abb5] | 765 | |
---|
[1258aa3] | 766 | id = wx.NewId() |
---|
[ef26c83] | 767 | self.popUpMenu.Append(id, name, str(msg)) |
---|
[1258aa3] | 768 | wx.EVT_MENU(self, id, self.onResetModel) |
---|
[ef26c83] | 769 | wx.PostEvent(self.parent.parent, |
---|
| 770 | AppendBookmarkEvent(title=name, |
---|
| 771 | hint=str(msg), |
---|
| 772 | handler=self._back_to_bookmark)) |
---|
| 773 | |
---|
| 774 | def _back_to_bookmark(self, event): |
---|
[95b2bad] | 775 | """ |
---|
| 776 | Back to bookmark |
---|
| 777 | """ |
---|
| 778 | self._manager.on_perspective(event) |
---|
| 779 | self.onResetModel(event) |
---|
[7fd4afd] | 780 | self._draw_model() |
---|
[bb8a180] | 781 | |
---|
[0b12abb5] | 782 | def old_on_bookmark(self, event): |
---|
| 783 | """ |
---|
| 784 | save history of the data and model |
---|
| 785 | """ |
---|
[ef26c83] | 786 | if self.model == None: |
---|
| 787 | msg = "Can not bookmark; Please select Data and Model first..." |
---|
[0b12abb5] | 788 | wx.MessageBox(msg, 'Info') |
---|
[ef26c83] | 789 | return |
---|
| 790 | if hasattr(self, "enable_disp"): |
---|
[fc6ea43] | 791 | self.state.enable_disp = copy.deepcopy(self.enable_disp.GetValue()) |
---|
[a074145] | 792 | if hasattr(self, "disp_box"): |
---|
[fc6ea43] | 793 | self.state.disp_box = copy.deepcopy(self.disp_box.GetSelection()) |
---|
[edd166b] | 794 | |
---|
[ef26c83] | 795 | self.state.model.name = self.model.name |
---|
[c99a6c5] | 796 | |
---|
| 797 | #Remember fit engine_type for fit panel |
---|
[ef26c83] | 798 | if self.engine_type == None: |
---|
[edd166b] | 799 | self.engine_type = "scipy" |
---|
[ef26c83] | 800 | if self._manager != None: |
---|
[3cd5806] | 801 | self._manager._on_change_engine(engine=self.engine_type) |
---|
[c99a6c5] | 802 | |
---|
[edd166b] | 803 | self.state.engine_type = self.engine_type |
---|
[b421b1a] | 804 | |
---|
[a074145] | 805 | new_state = self.state.clone() |
---|
[f20767b] | 806 | new_state.model.name = self.state.model.name |
---|
| 807 | |
---|
[c477b31] | 808 | new_state.enable2D = copy.deepcopy(self.enable2D) |
---|
[a074145] | 809 | ##Add model state on context menu |
---|
| 810 | self.number_saved_state += 1 |
---|
[ef26c83] | 811 | name = self.model.__class__.__name__ + "[%g]" % self.number_saved_state |
---|
| 812 | self.saved_states[name] = new_state |
---|
[a074145] | 813 | |
---|
| 814 | ## Add item in the context menu |
---|
[fc6ea43] | 815 | |
---|
[ef26c83] | 816 | year, month, day, hour, minute, second, tda, ty, tm_isdst \ |
---|
| 817 | = time.localtime() |
---|
| 818 | my_time = str(hour) + " : " + str(minute) + " : " + str(second) + " " |
---|
| 819 | date = str(month) + "|" + str(day) + "|" + str(year) |
---|
| 820 | msg = "Model saved at %s on %s" % (my_time, date) |
---|
| 821 | ## post help message for the selected model |
---|
| 822 | msg += " Saved! right click on this page to retrieve this model" |
---|
| 823 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
[a074145] | 824 | |
---|
| 825 | id = wx.NewId() |
---|
[ef26c83] | 826 | self.popUpMenu.Append(id, name, str(msg)) |
---|
[a074145] | 827 | wx.EVT_MENU(self, id, self.onResetModel) |
---|
| 828 | |
---|
[1328e03] | 829 | def onSetFocus(self, evt): |
---|
[77e23a2] | 830 | """ |
---|
[ef26c83] | 831 | highlight the current textcrtl and hide the error text control shown |
---|
[5062bbf] | 832 | after fitting |
---|
[77e23a2] | 833 | """ |
---|
[1328e03] | 834 | return |
---|
[c77d859] | 835 | |
---|
| 836 | def read_file(self, path): |
---|
| 837 | """ |
---|
[5062bbf] | 838 | Read two columns file |
---|
| 839 | |
---|
| 840 | :param path: the path to the file to read |
---|
| 841 | |
---|
[c77d859] | 842 | """ |
---|
| 843 | try: |
---|
[ef26c83] | 844 | if path == None: |
---|
| 845 | wx.PostEvent(self.parent.parent, |
---|
| 846 | StatusEvent(status=" Selected Distribution was not loaded: %s" % path)) |
---|
[c77d859] | 847 | return None, None |
---|
| 848 | input_f = open(path, 'r') |
---|
| 849 | buff = input_f.read() |
---|
| 850 | lines = buff.split('\n') |
---|
| 851 | |
---|
| 852 | angles = [] |
---|
[ef26c83] | 853 | weights = [] |
---|
[c77d859] | 854 | for line in lines: |
---|
| 855 | toks = line.split() |
---|
[502de0a] | 856 | try: |
---|
| 857 | angle = float(toks[0]) |
---|
| 858 | weight = float(toks[1]) |
---|
| 859 | except: |
---|
| 860 | # Skip non-data lines |
---|
| 861 | pass |
---|
| 862 | angles.append(angle) |
---|
| 863 | weights.append(weight) |
---|
[c77d859] | 864 | return numpy.array(angles), numpy.array(weights) |
---|
| 865 | except: |
---|
[ef26c83] | 866 | raise |
---|
[5062bbf] | 867 | |
---|
[cfc0913] | 868 | def createMemento(self): |
---|
| 869 | """ |
---|
[5062bbf] | 870 | return the current state of the page |
---|
[cfc0913] | 871 | """ |
---|
| 872 | return self.state.clone() |
---|
| 873 | |
---|
| 874 | def save_current_state(self): |
---|
| 875 | """ |
---|
[5062bbf] | 876 | Store current state |
---|
[cfc0913] | 877 | """ |
---|
[e3d1423] | 878 | self.state.engine_type = copy.deepcopy(self.engine_type) |
---|
[0aeabc6] | 879 | ## save model option |
---|
[ef26c83] | 880 | if self.model != None: |
---|
| 881 | self.disp_list = self.model.getDispParamList() |
---|
| 882 | self.state.disp_list = copy.deepcopy(self.disp_list) |
---|
[87fbc60] | 883 | self.state.model = self.model.clone() |
---|
[0b12abb5] | 884 | #save radiobutton state for model selection |
---|
| 885 | self.state.shape_rbutton = self.shape_rbutton.GetValue() |
---|
| 886 | self.state.shape_indep_rbutton = self.shape_indep_rbutton.GetValue() |
---|
| 887 | self.state.struct_rbutton = self.struct_rbutton.GetValue() |
---|
| 888 | self.state.plugin_rbutton = self.plugin_rbutton.GetValue() |
---|
| 889 | #model combobox |
---|
[ef26c83] | 890 | self.state.structurebox = self.structurebox.GetLabel() |
---|
| 891 | self.state.formfactorbox = self.formfactorbox.GetLabel() |
---|
[0b12abb5] | 892 | |
---|
[c477b31] | 893 | self.state.enable2D = copy.deepcopy(self.enable2D) |
---|
[ef26c83] | 894 | self.state.values = copy.deepcopy(self.values) |
---|
| 895 | self.state.weights = copy.deepcopy(self.weights) |
---|
| 896 | ## save data |
---|
| 897 | self.state.data = copy.deepcopy(self.data) |
---|
[0b12abb5] | 898 | self.state.qmax_x = self.qmax_x |
---|
| 899 | self.state.qmin_x = self.qmin_x |
---|
[55bb249c] | 900 | self.state.dI_noweight = copy.deepcopy(self.dI_noweight.GetValue()) |
---|
| 901 | self.state.dI_didata = copy.deepcopy(self.dI_didata.GetValue()) |
---|
| 902 | self.state.dI_sqrdata = copy.deepcopy(self.dI_sqrdata.GetValue()) |
---|
| 903 | self.state.dI_idata = copy.deepcopy(self.dI_idata.GetValue()) |
---|
[db8590a] | 904 | self.state.dq_l = self.dq_l |
---|
| 905 | self.state.dq_r = self.dq_r |
---|
[ef26c83] | 906 | if hasattr(self, "enable_disp"): |
---|
| 907 | self.state.enable_disp = self.enable_disp.GetValue() |
---|
[fc6ea43] | 908 | self.state.disable_disp = self.disable_disp.GetValue() |
---|
| 909 | |
---|
[6e4c9fe] | 910 | self.state.smearer = copy.deepcopy(self.current_smearer) |
---|
[ef26c83] | 911 | if hasattr(self, "enable_smearer"): |
---|
[4a7ad5f] | 912 | self.state.enable_smearer = \ |
---|
| 913 | copy.deepcopy(self.enable_smearer.GetValue()) |
---|
| 914 | self.state.disable_smearer = \ |
---|
| 915 | copy.deepcopy(self.disable_smearer.GetValue()) |
---|
[7609f1a] | 916 | |
---|
[4a7ad5f] | 917 | self.state.pinhole_smearer = \ |
---|
| 918 | copy.deepcopy(self.pinhole_smearer.GetValue()) |
---|
[ef26c83] | 919 | self.state.slit_smearer = copy.deepcopy(self.slit_smearer.GetValue()) |
---|
[7609f1a] | 920 | |
---|
[ef26c83] | 921 | if len(self._disp_obj_dict) > 0: |
---|
| 922 | for k, v in self._disp_obj_dict.iteritems(): |
---|
| 923 | self.state._disp_obj_dict[k] = v |
---|
| 924 | |
---|
[71f0373] | 925 | self.state.values = copy.deepcopy(self.values) |
---|
| 926 | self.state.weights = copy.deepcopy(self.weights) |
---|
[0aeabc6] | 927 | ## save plotting range |
---|
[b787e68c] | 928 | self._save_plotting_range() |
---|
[d2d0cfdf] | 929 | |
---|
[2296316] | 930 | self.state.orientation_params = [] |
---|
| 931 | self.state.orientation_params_disp = [] |
---|
| 932 | self.state.parameters = [] |
---|
| 933 | self.state.fittable_param = [] |
---|
| 934 | self.state.fixed_param = [] |
---|
| 935 | self.state.str_parameters = [] |
---|
[f20767b] | 936 | |
---|
[cfc0913] | 937 | ## save checkbutton state and txtcrtl values |
---|
[ef26c83] | 938 | self._copy_parameters_state(self.str_parameters, |
---|
[2296316] | 939 | self.state.str_parameters) |
---|
[fc6ea43] | 940 | self._copy_parameters_state(self.orientation_params, |
---|
| 941 | self.state.orientation_params) |
---|
| 942 | self._copy_parameters_state(self.orientation_params_disp, |
---|
| 943 | self.state.orientation_params_disp) |
---|
[f20767b] | 944 | |
---|
[d2d0cfdf] | 945 | self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
[4a7ad5f] | 946 | self._copy_parameters_state(self.fittable_param, |
---|
| 947 | self.state.fittable_param) |
---|
[d2d0cfdf] | 948 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
[3c44c66] | 949 | #save chisqr |
---|
| 950 | self.state.tcChi = self.tcChi.GetValue() |
---|
| 951 | |
---|
[52cac46] | 952 | def save_current_state_fit(self): |
---|
| 953 | """ |
---|
[5062bbf] | 954 | Store current state for fit_page |
---|
[52cac46] | 955 | """ |
---|
| 956 | ## save model option |
---|
[ef26c83] | 957 | if self.model != None: |
---|
| 958 | self.disp_list = self.model.getDispParamList() |
---|
| 959 | self.state.disp_list = copy.deepcopy(self.disp_list) |
---|
[52cac46] | 960 | self.state.model = self.model.clone() |
---|
[9bc499b6] | 961 | if hasattr(self, "engine_type"): |
---|
| 962 | self.state.engine_type = copy.deepcopy(self.engine_type) |
---|
| 963 | |
---|
[52cac46] | 964 | self.state.enable2D = copy.deepcopy(self.enable2D) |
---|
[ef26c83] | 965 | self.state.values = copy.deepcopy(self.values) |
---|
| 966 | self.state.weights = copy.deepcopy(self.weights) |
---|
| 967 | ## save data |
---|
| 968 | self.state.data = copy.deepcopy(self.data) |
---|
[52cac46] | 969 | |
---|
[ef26c83] | 970 | if hasattr(self, "enable_disp"): |
---|
| 971 | self.state.enable_disp = self.enable_disp.GetValue() |
---|
[52cac46] | 972 | self.state.disable_disp = self.disable_disp.GetValue() |
---|
| 973 | |
---|
[6e4c9fe] | 974 | self.state.smearer = copy.deepcopy(self.current_smearer) |
---|
[ef26c83] | 975 | if hasattr(self, "enable_smearer"): |
---|
[4a7ad5f] | 976 | self.state.enable_smearer = \ |
---|
| 977 | copy.deepcopy(self.enable_smearer.GetValue()) |
---|
| 978 | self.state.disable_smearer = \ |
---|
| 979 | copy.deepcopy(self.disable_smearer.GetValue()) |
---|
[52cac46] | 980 | |
---|
[4a7ad5f] | 981 | self.state.pinhole_smearer = \ |
---|
| 982 | copy.deepcopy(self.pinhole_smearer.GetValue()) |
---|
[ef26c83] | 983 | self.state.slit_smearer = copy.deepcopy(self.slit_smearer.GetValue()) |
---|
[55bb249c] | 984 | self.state.dI_noweight = copy.deepcopy(self.dI_noweight.GetValue()) |
---|
| 985 | self.state.dI_didata = copy.deepcopy(self.dI_didata.GetValue()) |
---|
| 986 | self.state.dI_sqrdata = copy.deepcopy(self.dI_sqrdata.GetValue()) |
---|
[ef26c83] | 987 | self.state.dI_idata = copy.deepcopy(self.dI_idata.GetValue()) |
---|
| 988 | if hasattr(self, "disp_box"): |
---|
[52cac46] | 989 | self.state.disp_box = self.disp_box.GetCurrentSelection() |
---|
| 990 | |
---|
[4a7ad5f] | 991 | if len(self.disp_cb_dict) > 0: |
---|
| 992 | for k, v in self.disp_cb_dict.iteritems(): |
---|
[52cac46] | 993 | |
---|
[ef26c83] | 994 | if v == None: |
---|
[4a7ad5f] | 995 | self.state.disp_cb_dict[k] = v |
---|
[52cac46] | 996 | else: |
---|
| 997 | try: |
---|
[4a7ad5f] | 998 | self.state.disp_cb_dict[k] = v.GetValue() |
---|
[52cac46] | 999 | except: |
---|
[4a7ad5f] | 1000 | self.state.disp_cb_dict[k] = None |
---|
[52cac46] | 1001 | |
---|
[4a7ad5f] | 1002 | if len(self._disp_obj_dict) > 0: |
---|
[ef26c83] | 1003 | for k, v in self._disp_obj_dict.iteritems(): |
---|
[4a7ad5f] | 1004 | self.state._disp_obj_dict[k] = v |
---|
[52cac46] | 1005 | |
---|
| 1006 | self.state.values = copy.deepcopy(self.values) |
---|
| 1007 | self.state.weights = copy.deepcopy(self.weights) |
---|
[b421b1a] | 1008 | |
---|
[52cac46] | 1009 | ## save plotting range |
---|
| 1010 | self._save_plotting_range() |
---|
| 1011 | |
---|
| 1012 | ## save checkbutton state and txtcrtl values |
---|
| 1013 | self._copy_parameters_state(self.orientation_params, |
---|
| 1014 | self.state.orientation_params) |
---|
| 1015 | self._copy_parameters_state(self.orientation_params_disp, |
---|
| 1016 | self.state.orientation_params_disp) |
---|
| 1017 | self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
[4a7ad5f] | 1018 | self._copy_parameters_state(self.fittable_param, |
---|
| 1019 | self.state.fittable_param) |
---|
[52cac46] | 1020 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
[a074145] | 1021 | |
---|
[ef26c83] | 1022 | def check_invalid_panel(self): |
---|
[ffa69b6] | 1023 | """ |
---|
[5062bbf] | 1024 | check if the user can already perform some action with this panel |
---|
[ef26c83] | 1025 | """ |
---|
[4470b10] | 1026 | if self.data is None: |
---|
| 1027 | self.disable_smearer.SetValue(True) |
---|
| 1028 | self.disable_disp.SetValue(True) |
---|
| 1029 | msg = "Please load Data and select Model to start..." |
---|
[ffa69b6] | 1030 | wx.MessageBox(msg, 'Info') |
---|
| 1031 | return True |
---|
[5062bbf] | 1032 | |
---|
[e88ebfd] | 1033 | def set_model_state(self, state): |
---|
| 1034 | """ |
---|
| 1035 | reset page given a model state |
---|
| 1036 | """ |
---|
| 1037 | self.disp_cb_dict = state.disp_cb_dict |
---|
| 1038 | self.disp_list = state.disp_list |
---|
| 1039 | |
---|
| 1040 | ## set the state of the radio box |
---|
[ef26c83] | 1041 | self.shape_rbutton.SetValue(state.shape_rbutton) |
---|
[e88ebfd] | 1042 | self.shape_indep_rbutton.SetValue(state.shape_indep_rbutton) |
---|
| 1043 | self.struct_rbutton.SetValue(state.struct_rbutton) |
---|
| 1044 | self.plugin_rbutton.SetValue(state.plugin_rbutton) |
---|
| 1045 | |
---|
| 1046 | ## fill model combobox |
---|
| 1047 | self._show_combox_helper() |
---|
| 1048 | #select the current model |
---|
[d40038e] | 1049 | try: |
---|
| 1050 | # to support older version |
---|
| 1051 | formfactor_pos = int(state.formfactorcombobox) |
---|
| 1052 | except: |
---|
| 1053 | formfactor_pos = 0 |
---|
| 1054 | for ind_form in range(self.formfactorbox.GetCount()): |
---|
[cce182ae] | 1055 | if self.formfactorbox.GetString(ind_form) == \ |
---|
| 1056 | state.formfactorcombobox: |
---|
[d40038e] | 1057 | formfactor_pos = int(ind_form) |
---|
| 1058 | break |
---|
| 1059 | |
---|
| 1060 | self.formfactorbox.Select(formfactor_pos) |
---|
| 1061 | |
---|
| 1062 | try: |
---|
| 1063 | # to support older version |
---|
| 1064 | structfactor_pos = int(state.structurecombobox) |
---|
| 1065 | except: |
---|
| 1066 | structfactor_pos = 0 |
---|
| 1067 | for ind_struct in range(self.structurebox.GetCount()): |
---|
[cce182ae] | 1068 | if self.structurebox.GetString(ind_struct) == \ |
---|
| 1069 | state.structurecombobox: |
---|
[d40038e] | 1070 | structfactor_pos = int(ind_struct) |
---|
| 1071 | break |
---|
| 1072 | |
---|
| 1073 | self.structurebox.SetSelection(structfactor_pos) |
---|
| 1074 | |
---|
[e88ebfd] | 1075 | if state.multi_factor != None: |
---|
| 1076 | self.multifactorbox.SetSelection(state.multi_factor) |
---|
| 1077 | |
---|
[ef26c83] | 1078 | ## reset state of checkbox,textcrtl and regular parameters value |
---|
[e88ebfd] | 1079 | self._reset_parameters_state(self.orientation_params_disp, |
---|
| 1080 | state.orientation_params_disp) |
---|
| 1081 | self._reset_parameters_state(self.orientation_params, |
---|
| 1082 | state.orientation_params) |
---|
| 1083 | self._reset_parameters_state(self.str_parameters, |
---|
| 1084 | state.str_parameters) |
---|
[ef26c83] | 1085 | self._reset_parameters_state(self.parameters, state.parameters) |
---|
| 1086 | ## display dispersion info layer |
---|
[e88ebfd] | 1087 | self.enable_disp.SetValue(state.enable_disp) |
---|
| 1088 | self.disable_disp.SetValue(state.disable_disp) |
---|
| 1089 | |
---|
| 1090 | if hasattr(self, "disp_box"): |
---|
[ef26c83] | 1091 | self.disp_box.SetSelection(state.disp_box) |
---|
| 1092 | n = self.disp_box.GetCurrentSelection() |
---|
| 1093 | dispersity = self.disp_box.GetClientData(n) |
---|
| 1094 | name = dispersity.__name__ |
---|
[e88ebfd] | 1095 | |
---|
| 1096 | self._set_dipers_Param(event=None) |
---|
| 1097 | |
---|
| 1098 | if name == "ArrayDispersion": |
---|
| 1099 | |
---|
| 1100 | for item in self.disp_cb_dict.keys(): |
---|
| 1101 | |
---|
[ef26c83] | 1102 | if hasattr(self.disp_cb_dict[item], "SetValue"): |
---|
[e88ebfd] | 1103 | self.disp_cb_dict[item].SetValue(\ |
---|
| 1104 | state.disp_cb_dict[item]) |
---|
| 1105 | # Create the dispersion objects |
---|
| 1106 | from sans.models.dispersion_models import ArrayDispersion |
---|
| 1107 | disp_model = ArrayDispersion() |
---|
[ef26c83] | 1108 | if hasattr(state, "values") and \ |
---|
[e88ebfd] | 1109 | self.disp_cb_dict[item].GetValue() == True: |
---|
[ef26c83] | 1110 | if len(state.values) > 0: |
---|
| 1111 | self.values = state.values |
---|
| 1112 | self.weights = state.weights |
---|
[e88ebfd] | 1113 | disp_model.set_weights(self.values, |
---|
[ef26c83] | 1114 | state.weights) |
---|
[e88ebfd] | 1115 | else: |
---|
| 1116 | self._reset_dispersity() |
---|
| 1117 | |
---|
| 1118 | self._disp_obj_dict[item] = disp_model |
---|
[ef26c83] | 1119 | # Set the new model as the dispersion object |
---|
[e88ebfd] | 1120 | #for the selected parameter |
---|
| 1121 | self.model.set_dispersion(item, disp_model) |
---|
| 1122 | |
---|
| 1123 | self.model._persistency_dict[item] = \ |
---|
| 1124 | [state.values, state.weights] |
---|
| 1125 | |
---|
| 1126 | else: |
---|
| 1127 | keys = self.model.getParamList() |
---|
| 1128 | for item in keys: |
---|
| 1129 | if item in self.disp_list and \ |
---|
[ef26c83] | 1130 | not item in self.model.details: |
---|
[e88ebfd] | 1131 | self.model.details[item] = ["", None, None] |
---|
[ef26c83] | 1132 | for k, v in self.state.disp_cb_dict.iteritems(): |
---|
| 1133 | self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) |
---|
[e88ebfd] | 1134 | self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) |
---|
[ef26c83] | 1135 | ## smearing info restore |
---|
[e88ebfd] | 1136 | if hasattr(self, "enable_smearer"): |
---|
[ef26c83] | 1137 | ## set smearing value whether or not the data |
---|
[e88ebfd] | 1138 | #contain the smearing info |
---|
| 1139 | self.enable_smearer.SetValue(state.enable_smearer) |
---|
| 1140 | self.disable_smearer.SetValue(state.disable_smearer) |
---|
[ef26c83] | 1141 | self.onSmear(event=None) |
---|
[e88ebfd] | 1142 | self.pinhole_smearer.SetValue(state.pinhole_smearer) |
---|
| 1143 | self.slit_smearer.SetValue(state.slit_smearer) |
---|
[55bb249c] | 1144 | |
---|
| 1145 | self.dI_noweight.SetValue(state.dI_noweight) |
---|
| 1146 | self.dI_didata.SetValue(state.dI_didata) |
---|
| 1147 | self.dI_sqrdata.SetValue(state.dI_sqrdata) |
---|
| 1148 | self.dI_idata.SetValue(state.dI_idata) |
---|
| 1149 | |
---|
[e88ebfd] | 1150 | ## we have two more options for smearing |
---|
[ef26c83] | 1151 | if self.pinhole_smearer.GetValue(): |
---|
| 1152 | self.onPinholeSmear(event=None) |
---|
| 1153 | elif self.slit_smearer.GetValue(): |
---|
| 1154 | self.onSlitSmear(event=None) |
---|
[e88ebfd] | 1155 | |
---|
| 1156 | ## reset state of checkbox,textcrtl and dispersity parameters value |
---|
[ef26c83] | 1157 | self._reset_parameters_state(self.fittable_param, state.fittable_param) |
---|
| 1158 | self._reset_parameters_state(self.fixed_param, state.fixed_param) |
---|
[e88ebfd] | 1159 | |
---|
| 1160 | ## draw the model with previous parameters value |
---|
| 1161 | self._onparamEnter_helper() |
---|
[ef26c83] | 1162 | self.select_param(event=None) |
---|
[e88ebfd] | 1163 | #Save state_fit |
---|
| 1164 | self.save_current_state_fit() |
---|
| 1165 | self._lay_out() |
---|
| 1166 | self.Refresh() |
---|
| 1167 | |
---|
[240b9966] | 1168 | def reset_page_helper(self, state): |
---|
[cfc0913] | 1169 | """ |
---|
[5062bbf] | 1170 | Use page_state and change the state of existing page |
---|
| 1171 | |
---|
| 1172 | :precondition: the page is already drawn or created |
---|
| 1173 | |
---|
| 1174 | :postcondition: the state of the underlying data change as well as the |
---|
[71f0373] | 1175 | state of the graphic interface |
---|
[cfc0913] | 1176 | """ |
---|
[4a7ad5f] | 1177 | if state == None: |
---|
[ef26c83] | 1178 | return |
---|
[2296316] | 1179 | # set data, etc. from the state |
---|
[2657df9] | 1180 | # reset page between theory and fitting from bookmarking |
---|
| 1181 | #if state.data == None: |
---|
| 1182 | # data = None |
---|
| 1183 | #else: |
---|
| 1184 | data = state.data |
---|
| 1185 | |
---|
| 1186 | if data == None: |
---|
| 1187 | data_min = state.qmin |
---|
| 1188 | data_max = state.qmax |
---|
| 1189 | self.qmin_x = data_min |
---|
| 1190 | self.qmax_x = data_max |
---|
| 1191 | self.qmin.SetValue(str(data_min)) |
---|
| 1192 | self.qmax.SetValue(str(data_max)) |
---|
| 1193 | |
---|
| 1194 | self.state.data = data |
---|
| 1195 | self.state.qmin = self.qmin_x |
---|
| 1196 | self.state.qmax = self.qmax_x |
---|
| 1197 | else: |
---|
| 1198 | self.set_data(data) |
---|
| 1199 | |
---|
[ef26c83] | 1200 | self.enable2D = state.enable2D |
---|
[0b12abb5] | 1201 | self.engine_type = state.engine_type |
---|
| 1202 | |
---|
| 1203 | self.disp_cb_dict = state.disp_cb_dict |
---|
| 1204 | self.disp_list = state.disp_list |
---|
[e3d1423] | 1205 | |
---|
[0b12abb5] | 1206 | ## set the state of the radio box |
---|
[ef26c83] | 1207 | self.shape_rbutton.SetValue(state.shape_rbutton) |
---|
[0b12abb5] | 1208 | self.shape_indep_rbutton.SetValue(state.shape_indep_rbutton) |
---|
[e3d1423] | 1209 | self.struct_rbutton.SetValue(state.struct_rbutton) |
---|
[0b12abb5] | 1210 | self.plugin_rbutton.SetValue(state.plugin_rbutton) |
---|
| 1211 | |
---|
| 1212 | ## fill model combobox |
---|
| 1213 | self._show_combox_helper() |
---|
| 1214 | #select the current model |
---|
[d40038e] | 1215 | try: |
---|
| 1216 | # to support older version |
---|
| 1217 | formfactor_pos = int(state.formfactorcombobox) |
---|
| 1218 | except: |
---|
| 1219 | formfactor_pos = 0 |
---|
| 1220 | for ind_form in range(self.formfactorbox.GetCount()): |
---|
[8df5faa] | 1221 | if self.formfactorbox.GetString(ind_form) == (state.formfactorcombobox): |
---|
[d40038e] | 1222 | formfactor_pos = int(ind_form) |
---|
| 1223 | break |
---|
| 1224 | |
---|
| 1225 | self.formfactorbox.Select(formfactor_pos) |
---|
| 1226 | |
---|
| 1227 | try: |
---|
| 1228 | # to support older version |
---|
| 1229 | structfactor_pos = int(state.structurecombobox) |
---|
| 1230 | except: |
---|
| 1231 | structfactor_pos = 0 |
---|
| 1232 | for ind_struct in range(self.structurebox.GetCount()): |
---|
[8df5faa] | 1233 | if self.structurebox.GetString(ind_struct) == (state.structurecombobox) > 0: |
---|
[d40038e] | 1234 | structfactor_pos = int(ind_struct) |
---|
| 1235 | break |
---|
| 1236 | |
---|
| 1237 | self.structurebox.SetSelection(structfactor_pos) |
---|
| 1238 | |
---|
[4523b68] | 1239 | if state.multi_factor != None: |
---|
[cf6a192] | 1240 | self.multifactorbox.SetSelection(state.multi_factor) |
---|
[4523b68] | 1241 | |
---|
[0b12abb5] | 1242 | #reset the fitting engine type |
---|
| 1243 | self.engine_type = state.engine_type |
---|
[ef26c83] | 1244 | #draw the pnael according to the new model parameter |
---|
[0b12abb5] | 1245 | self._on_select_model(event=None) |
---|
[93f0a862] | 1246 | |
---|
[2657df9] | 1247 | # take care of 2D button |
---|
| 1248 | if data == None and self.model_view.IsEnabled(): |
---|
| 1249 | if self.enable2D: |
---|
[6371c9c] | 1250 | self.model_view.SetLabel("2D Mode") |
---|
[2657df9] | 1251 | else: |
---|
[6371c9c] | 1252 | self.model_view.SetLabel("1D Mode") |
---|
[2657df9] | 1253 | # else: |
---|
| 1254 | |
---|
[ef26c83] | 1255 | if self._manager != None and self.engine_type != None: |
---|
[3cd5806] | 1256 | self._manager._on_change_engine(engine=self.engine_type) |
---|
[0b12abb5] | 1257 | ## set the select all check box to the a given state |
---|
| 1258 | self.cb1.SetValue(state.cb1) |
---|
| 1259 | |
---|
| 1260 | ## reset state of checkbox,textcrtl and regular parameters value |
---|
| 1261 | self._reset_parameters_state(self.orientation_params_disp, |
---|
| 1262 | state.orientation_params_disp) |
---|
| 1263 | self._reset_parameters_state(self.orientation_params, |
---|
| 1264 | state.orientation_params) |
---|
[fb59ed9] | 1265 | self._reset_parameters_state(self.str_parameters, |
---|
| 1266 | state.str_parameters) |
---|
[ef26c83] | 1267 | self._reset_parameters_state(self.parameters, state.parameters) |
---|
| 1268 | ## display dispersion info layer |
---|
[0b12abb5] | 1269 | self.enable_disp.SetValue(state.enable_disp) |
---|
| 1270 | self.disable_disp.SetValue(state.disable_disp) |
---|
[2296316] | 1271 | # If the polydispersion is ON |
---|
| 1272 | if state.enable_disp: |
---|
| 1273 | # reset dispersion according the state |
---|
[0b12abb5] | 1274 | self._set_dipers_Param(event=None) |
---|
[2296316] | 1275 | self._reset_page_disp_helper(state) |
---|
[ef26c83] | 1276 | ##plotting range restore |
---|
[0b12abb5] | 1277 | self._reset_plotting_range(state) |
---|
| 1278 | ## smearing info restore |
---|
| 1279 | if hasattr(self, "enable_smearer"): |
---|
[ef26c83] | 1280 | ## set smearing value whether or not the data |
---|
[4a7ad5f] | 1281 | #contain the smearing info |
---|
[0b12abb5] | 1282 | self.enable_smearer.SetValue(state.enable_smearer) |
---|
| 1283 | self.disable_smearer.SetValue(state.disable_smearer) |
---|
[ef26c83] | 1284 | self.onSmear(event=None) |
---|
[0b12abb5] | 1285 | self.pinhole_smearer.SetValue(state.pinhole_smearer) |
---|
| 1286 | self.slit_smearer.SetValue(state.slit_smearer) |
---|
[ea8283d] | 1287 | try: |
---|
| 1288 | self.dI_noweight.SetValue(state.dI_noweight) |
---|
| 1289 | self.dI_didata.SetValue(state.dI_didata) |
---|
| 1290 | self.dI_sqrdata.SetValue(state.dI_sqrdata) |
---|
| 1291 | self.dI_idata.SetValue(state.dI_idata) |
---|
| 1292 | except: |
---|
| 1293 | # to support older state file formats |
---|
| 1294 | self.dI_noweight.SetValue(False) |
---|
| 1295 | self.dI_didata.SetValue(True) |
---|
| 1296 | self.dI_sqrdata.SetValue(False) |
---|
| 1297 | self.dI_idata.SetValue(False) |
---|
| 1298 | |
---|
[0b12abb5] | 1299 | ## we have two more options for smearing |
---|
[ef26c83] | 1300 | if self.pinhole_smearer.GetValue(): |
---|
| 1301 | self.onPinholeSmear(event=None) |
---|
| 1302 | elif self.slit_smearer.GetValue(): |
---|
| 1303 | self.onSlitSmear(event=None) |
---|
[55bb249c] | 1304 | |
---|
[0b12abb5] | 1305 | ## reset state of checkbox,textcrtl and dispersity parameters value |
---|
[ef26c83] | 1306 | self._reset_parameters_state(self.fittable_param, state.fittable_param) |
---|
| 1307 | self._reset_parameters_state(self.fixed_param, state.fixed_param) |
---|
[0b12abb5] | 1308 | |
---|
| 1309 | ## draw the model with previous parameters value |
---|
| 1310 | self._onparamEnter_helper() |
---|
[3c44c66] | 1311 | #reset the value of chisqr when not consistent with the value computed |
---|
| 1312 | self.tcChi.SetValue(str(self.state.tcChi)) |
---|
[0b12abb5] | 1313 | ## reset context menu items |
---|
| 1314 | self._reset_context_menu() |
---|
[3c44c66] | 1315 | |
---|
[0b12abb5] | 1316 | ## set the value of the current state to the state given as parameter |
---|
[ef26c83] | 1317 | self.state = state.clone() |
---|
[93f0a862] | 1318 | self.state.m_name = self.m_name |
---|
[0b12abb5] | 1319 | |
---|
[2296316] | 1320 | def _reset_page_disp_helper(self, state): |
---|
| 1321 | """ |
---|
| 1322 | Help to rest page for dispersions |
---|
| 1323 | """ |
---|
| 1324 | keys = self.model.getParamList() |
---|
| 1325 | for item in keys: |
---|
| 1326 | if item in self.disp_list and \ |
---|
[ef26c83] | 1327 | not item in self.model.details: |
---|
[2296316] | 1328 | self.model.details[item] = ["", None, None] |
---|
| 1329 | #for k,v in self.state.disp_cb_dict.iteritems(): |
---|
[ef26c83] | 1330 | self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) |
---|
[2296316] | 1331 | self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) |
---|
| 1332 | self.values = copy.deepcopy(state.values) |
---|
| 1333 | self.weights = copy.deepcopy(state.weights) |
---|
| 1334 | |
---|
| 1335 | for key, disp in state._disp_obj_dict.iteritems(): |
---|
| 1336 | # From saved file, disp_model can not be sent in model obj. |
---|
| 1337 | # it will be sent as a string here, then converted to model object. |
---|
| 1338 | if disp.__class__.__name__ == 'str': |
---|
[ef26c83] | 1339 | com_str = "from sans.models.dispersion_models " |
---|
[2296316] | 1340 | com_str += "import %s as disp_func" |
---|
| 1341 | exec com_str % disp |
---|
| 1342 | disp_model = disp_func() |
---|
[f20767b] | 1343 | else: |
---|
[2296316] | 1344 | disp_model = disp |
---|
[edd166b] | 1345 | |
---|
[ef26c83] | 1346 | self._disp_obj_dict[key] = disp_model |
---|
[2296316] | 1347 | param_name = key.split('.')[0] |
---|
| 1348 | # Try to set dispersion only when available |
---|
[ef26c83] | 1349 | # for eg., pass the orient. angles for 1D Cal |
---|
[2296316] | 1350 | try: |
---|
| 1351 | self.model.set_dispersion(param_name, disp_model) |
---|
| 1352 | self.model._persistency_dict[key] = \ |
---|
| 1353 | [state.values, state.weights] |
---|
| 1354 | except: |
---|
| 1355 | pass |
---|
| 1356 | selection = self._find_polyfunc_selection(disp_model) |
---|
| 1357 | for list in self.fittable_param: |
---|
| 1358 | if list[1] == key and list[7] != None: |
---|
| 1359 | list[7].SetSelection(selection) |
---|
[ef26c83] | 1360 | # For the array disp_model, set the values and weights |
---|
[2296316] | 1361 | if selection == 1: |
---|
[ef26c83] | 1362 | disp_model.set_weights(self.values[key], |
---|
| 1363 | self.weights[key]) |
---|
[2296316] | 1364 | try: |
---|
| 1365 | # Diables all fittable params for array |
---|
| 1366 | list[0].SetValue(False) |
---|
| 1367 | list[0].Disable() |
---|
| 1368 | list[2].Disable() |
---|
| 1369 | list[5].Disable() |
---|
| 1370 | list[6].Disable() |
---|
| 1371 | except: |
---|
| 1372 | pass |
---|
| 1373 | # For array, disable all fixed params |
---|
| 1374 | if selection == 1: |
---|
| 1375 | for item in self.fixed_param: |
---|
| 1376 | if item[1].split(".")[0] == key.split(".")[0]: |
---|
| 1377 | # try it and pass it for the orientation for 1D |
---|
| 1378 | try: |
---|
| 1379 | item[2].Disable() |
---|
| 1380 | except: |
---|
| 1381 | pass |
---|
[5582a9f1] | 1382 | |
---|
[2296316] | 1383 | # Make sure the check box updated when all checked |
---|
| 1384 | if self.cb1.GetValue(): |
---|
[ef26c83] | 1385 | self.select_all_param(None) |
---|
[2296316] | 1386 | |
---|
[c77d859] | 1387 | def _selectDlg(self): |
---|
| 1388 | """ |
---|
[5062bbf] | 1389 | open a dialog file to selected the customized dispersity |
---|
[c77d859] | 1390 | """ |
---|
[ef26c83] | 1391 | if self.parent != None: |
---|
[baf1ef3] | 1392 | self._default_save_location = \ |
---|
| 1393 | self.parent.parent._default_save_location |
---|
[60132ef] | 1394 | dlg = wx.FileDialog(self, "Choose a weight file", |
---|
[ef26c83] | 1395 | self._default_save_location, "", |
---|
[4a7ad5f] | 1396 | "*.*", wx.OPEN) |
---|
[c77d859] | 1397 | path = None |
---|
| 1398 | if dlg.ShowModal() == wx.ID_OK: |
---|
| 1399 | path = dlg.GetPath() |
---|
| 1400 | dlg.Destroy() |
---|
| 1401 | return path |
---|
[5062bbf] | 1402 | |
---|
[a074145] | 1403 | def _reset_context_menu(self): |
---|
| 1404 | """ |
---|
[5062bbf] | 1405 | reset the context menu |
---|
[a074145] | 1406 | """ |
---|
| 1407 | for name, state in self.state.saved_states.iteritems(): |
---|
| 1408 | self.number_saved_state += 1 |
---|
| 1409 | ## Add item in the context menu |
---|
| 1410 | id = wx.NewId() |
---|
[4a7ad5f] | 1411 | msg = 'Save model and state %g' % self.number_saved_state |
---|
| 1412 | self.popUpMenu.Append(id, name, msg) |
---|
[a074145] | 1413 | wx.EVT_MENU(self, id, self.onResetModel) |
---|
| 1414 | |
---|
[0aeabc6] | 1415 | def _reset_plotting_range(self, state): |
---|
[cfc0913] | 1416 | """ |
---|
[5062bbf] | 1417 | Reset the plotting range to a given state |
---|
[cfc0913] | 1418 | """ |
---|
[f95301b] | 1419 | self.qmin.SetValue(str(state.qmin)) |
---|
[ef26c83] | 1420 | self.qmax.SetValue(str(state.qmax)) |
---|
[0b12abb5] | 1421 | |
---|
[240b9966] | 1422 | def _save_typeOfmodel(self): |
---|
| 1423 | """ |
---|
[5062bbf] | 1424 | save radiobutton containing the type model that can be selected |
---|
[240b9966] | 1425 | """ |
---|
| 1426 | self.state.shape_rbutton = self.shape_rbutton.GetValue() |
---|
| 1427 | self.state.shape_indep_rbutton = self.shape_indep_rbutton.GetValue() |
---|
| 1428 | self.state.struct_rbutton = self.struct_rbutton.GetValue() |
---|
| 1429 | self.state.plugin_rbutton = self.plugin_rbutton.GetValue() |
---|
[ef26c83] | 1430 | self.state.structurebox = self.structurebox.GetLabel() |
---|
| 1431 | self.state.formfactorbox = self.formfactorbox.GetLabel() |
---|
[c99a6c5] | 1432 | |
---|
[240b9966] | 1433 | ## post state to fit panel |
---|
[ef26c83] | 1434 | event = PageInfoEvent(page=self) |
---|
[240b9966] | 1435 | wx.PostEvent(self.parent, event) |
---|
[3595309d] | 1436 | |
---|
[ef26c83] | 1437 | def _save_plotting_range(self): |
---|
[cfc0913] | 1438 | """ |
---|
[ef26c83] | 1439 | save the state of plotting range |
---|
[cfc0913] | 1440 | """ |
---|
[b787e68c] | 1441 | self.state.qmin = self.qmin_x |
---|
[ef26c83] | 1442 | self.state.qmax = self.qmax_x |
---|
[6bbeacd4] | 1443 | self.state.npts = self.npts_x |
---|
[cfc0913] | 1444 | |
---|
[c77d859] | 1445 | def _onparamEnter_helper(self): |
---|
| 1446 | """ |
---|
[ef26c83] | 1447 | check if values entered by the user are changed and valid to replot |
---|
[5062bbf] | 1448 | model |
---|
[c77d859] | 1449 | """ |
---|
[ef26c83] | 1450 | # Flag to register when a parameter has changed. |
---|
[7975f2b] | 1451 | is_modified = False |
---|
[4a7ad5f] | 1452 | self.fitrange = True |
---|
[51a71a3] | 1453 | is_2Ddata = False |
---|
[3a37fe0] | 1454 | #self._undo.Enable(True) |
---|
[51a71a3] | 1455 | # check if 2d data |
---|
[4a7ad5f] | 1456 | if self.data.__class__.__name__ == "Data2D": |
---|
[51a71a3] | 1457 | is_2Ddata = True |
---|
[ef26c83] | 1458 | if self.model != None: |
---|
[edd166b] | 1459 | try: |
---|
[4a7ad5f] | 1460 | is_modified = self._check_value_enter(self.fittable_param, |
---|
| 1461 | is_modified) |
---|
| 1462 | is_modified = self._check_value_enter(self.fixed_param, |
---|
| 1463 | is_modified) |
---|
| 1464 | is_modified = self._check_value_enter(self.parameters, |
---|
[ef26c83] | 1465 | is_modified) |
---|
[edd166b] | 1466 | except: |
---|
| 1467 | pass |
---|
[c99a6c5] | 1468 | |
---|
[c77d859] | 1469 | # Here we should check whether the boundaries have been modified. |
---|
[ef26c83] | 1470 | # If qmin and qmax have been modified, update qmin and qmax and |
---|
[c77d859] | 1471 | # set the is_modified flag to True |
---|
[f95301b] | 1472 | if self._validate_qrange(self.qmin, self.qmax): |
---|
| 1473 | tempmin = float(self.qmin.GetValue()) |
---|
[7975f2b] | 1474 | if tempmin != self.qmin_x: |
---|
| 1475 | self.qmin_x = tempmin |
---|
[c77d859] | 1476 | is_modified = True |
---|
[7975f2b] | 1477 | tempmax = float(self.qmax.GetValue()) |
---|
| 1478 | if tempmax != self.qmax_x: |
---|
| 1479 | self.qmax_x = tempmax |
---|
[c77d859] | 1480 | is_modified = True |
---|
[b787e68c] | 1481 | |
---|
[51a71a3] | 1482 | if is_2Ddata: |
---|
[ef26c83] | 1483 | # set mask |
---|
[51a71a3] | 1484 | is_modified = self._validate_Npts() |
---|
[247cb58] | 1485 | |
---|
[51a71a3] | 1486 | else: |
---|
[ef26c83] | 1487 | self.fitrange = False |
---|
[d2c4c06] | 1488 | |
---|
| 1489 | if not self.data.is_data: |
---|
| 1490 | is_modified = True |
---|
| 1491 | |
---|
[c77d859] | 1492 | ## if any value is modify draw model with new value |
---|
[51a71a3] | 1493 | if not self.fitrange: |
---|
[247cb58] | 1494 | #self.btFit.Disable() |
---|
[ef26c83] | 1495 | if is_2Ddata: |
---|
| 1496 | self.btEditMask.Disable() |
---|
[51a71a3] | 1497 | else: |
---|
[ef26c83] | 1498 | if is_2Ddata and self.data.is_data and not self.batch_on: |
---|
[054f004] | 1499 | self.btEditMask.Enable(True) |
---|
[51a71a3] | 1500 | if is_modified and self.fitrange: |
---|
[ecf26e1] | 1501 | # Theory case: need to get npts value to draw |
---|
| 1502 | self.npts_x = float(self.Npts_total.GetValue()) |
---|
| 1503 | self.create_default_data() |
---|
[ef26c83] | 1504 | self.state_change = True |
---|
| 1505 | self._draw_model() |
---|
[7975f2b] | 1506 | self.Refresh() |
---|
| 1507 | return is_modified |
---|
| 1508 | |
---|
[35c9d31] | 1509 | def _update_paramv_on_fit(self): |
---|
| 1510 | """ |
---|
[5062bbf] | 1511 | make sure that update param values just before the fitting |
---|
[35c9d31] | 1512 | """ |
---|
| 1513 | #flag for qmin qmax check values |
---|
[7609f1a] | 1514 | flag = True |
---|
[51a71a3] | 1515 | self.fitrange = True |
---|
[35c9d31] | 1516 | is_modified = False |
---|
[51a71a3] | 1517 | |
---|
[66ff250] | 1518 | #wx.PostEvent(self._manager.parent, StatusEvent(status=" \ |
---|
| 1519 | #updating ... ",type="update")) |
---|
[4fbc93e] | 1520 | |
---|
[35c9d31] | 1521 | ##So make sure that update param values on_Fit. |
---|
| 1522 | #self._undo.Enable(True) |
---|
[ef26c83] | 1523 | if self.model != None: |
---|
[33477fd] | 1524 | if self.Npts_total.GetValue() != self.Npts_fit.GetValue(): |
---|
| 1525 | if not self.data.is_data: |
---|
| 1526 | self._manager.page_finder[self.uid].set_fit_data(data=\ |
---|
[ef26c83] | 1527 | [self.data]) |
---|
[35c9d31] | 1528 | ##Check the values |
---|
[ef26c83] | 1529 | self._check_value_enter(self.fittable_param, is_modified) |
---|
| 1530 | self._check_value_enter(self.fixed_param, is_modified) |
---|
| 1531 | self._check_value_enter(self.parameters, is_modified) |
---|
[35c9d31] | 1532 | |
---|
| 1533 | # If qmin and qmax have been modified, update qmin and qmax and |
---|
[ef26c83] | 1534 | # Here we should check whether the boundaries have been modified. |
---|
[7975f2b] | 1535 | # If qmin and qmax have been modified, update qmin and qmax and |
---|
| 1536 | # set the is_modified flag to True |
---|
[f95301b] | 1537 | self.fitrange = self._validate_qrange(self.qmin, self.qmax) |
---|
[51a71a3] | 1538 | if self.fitrange: |
---|
[f95301b] | 1539 | tempmin = float(self.qmin.GetValue()) |
---|
[7975f2b] | 1540 | if tempmin != self.qmin_x: |
---|
| 1541 | self.qmin_x = tempmin |
---|
| 1542 | tempmax = float(self.qmax.GetValue()) |
---|
| 1543 | if tempmax != self.qmax_x: |
---|
| 1544 | self.qmax_x = tempmax |
---|
[7609f1a] | 1545 | if tempmax == tempmin: |
---|
[ef26c83] | 1546 | flag = False |
---|
[7609f1a] | 1547 | temp_smearer = None |
---|
| 1548 | if not self.disable_smearer.GetValue(): |
---|
[ef26c83] | 1549 | temp_smearer = self.current_smearer |
---|
[7609f1a] | 1550 | if self.slit_smearer.GetValue(): |
---|
| 1551 | flag = self.update_slit_smear() |
---|
| 1552 | elif self.pinhole_smearer.GetValue(): |
---|
| 1553 | flag = self.update_pinhole_smear() |
---|
| 1554 | else: |
---|
[6bbeacd4] | 1555 | self._manager.set_smearer(smearer=temp_smearer, |
---|
[66ff250] | 1556 | uid=self.uid, |
---|
[ecf26e1] | 1557 | fid=self.data.id, |
---|
[ef26c83] | 1558 | qmin=float(self.qmin_x), |
---|
| 1559 | qmax=float(self.qmax_x), |
---|
[ecf26e1] | 1560 | enable_smearer=not self.disable_smearer.GetValue(), |
---|
[6bbeacd4] | 1561 | draw=False) |
---|
[4fbc93e] | 1562 | elif not self._is_2D(): |
---|
[3cd5806] | 1563 | self._manager.set_smearer(smearer=temp_smearer, |
---|
[4a7ad5f] | 1564 | qmin=float(self.qmin_x), |
---|
[ef26c83] | 1565 | uid=self.uid, |
---|
[ecf26e1] | 1566 | fid=self.data.id, |
---|
[ef26c83] | 1567 | qmax=float(self.qmax_x), |
---|
[ecf26e1] | 1568 | enable_smearer=not self.disable_smearer.GetValue(), |
---|
[18e430a] | 1569 | draw=False) |
---|
[0cf97c5] | 1570 | if self.data != None: |
---|
[ef26c83] | 1571 | index_data = ((self.qmin_x <= self.data.x) & \ |
---|
[0cf97c5] | 1572 | (self.data.x <= self.qmax_x)) |
---|
[ef26c83] | 1573 | val = str(len(self.data.x[index_data == True])) |
---|
[0cf97c5] | 1574 | self.Npts_fit.SetValue(val) |
---|
| 1575 | else: |
---|
| 1576 | # No data in the panel |
---|
| 1577 | try: |
---|
| 1578 | self.npts_x = float(self.Npts_total.GetValue()) |
---|
| 1579 | except: |
---|
| 1580 | flag = False |
---|
| 1581 | return flag |
---|
[51a71a3] | 1582 | flag = True |
---|
[4fbc93e] | 1583 | if self._is_2D(): |
---|
[ef26c83] | 1584 | # only 2D case set mask |
---|
[51a71a3] | 1585 | flag = self._validate_Npts() |
---|
| 1586 | if not flag: |
---|
| 1587 | return flag |
---|
[ef26c83] | 1588 | else: |
---|
| 1589 | flag = False |
---|
| 1590 | else: |
---|
[7975f2b] | 1591 | flag = False |
---|
[51a71a3] | 1592 | |
---|
[ef26c83] | 1593 | #For invalid q range, disable the mask editor and fit button, vs. |
---|
[51a71a3] | 1594 | if not self.fitrange: |
---|
[55a3257] | 1595 | if self._is_2D(): |
---|
| 1596 | self.btEditMask.Disable() |
---|
[51a71a3] | 1597 | else: |
---|
[33477fd] | 1598 | if self._is_2D() and self.data.is_data and not self.batch_on: |
---|
[55a3257] | 1599 | self.btEditMask.Enable(True) |
---|
[51a71a3] | 1600 | |
---|
[7609f1a] | 1601 | if not flag: |
---|
[4a7ad5f] | 1602 | msg = "Cannot Plot or Fit :Must select a " |
---|
| 1603 | msg += " model or Fitting range is not valid!!! " |
---|
| 1604 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
[51a71a3] | 1605 | |
---|
[33477fd] | 1606 | try: |
---|
| 1607 | self.save_current_state() |
---|
| 1608 | except: |
---|
| 1609 | pass |
---|
[4470b10] | 1610 | |
---|
[ef26c83] | 1611 | return flag |
---|
[acd0bda3] | 1612 | |
---|
[c99a6c5] | 1613 | def _is_modified(self, is_modified): |
---|
[acd0bda3] | 1614 | """ |
---|
[5062bbf] | 1615 | return to self._is_modified |
---|
[acd0bda3] | 1616 | """ |
---|
[c99a6c5] | 1617 | return is_modified |
---|
[acd0bda3] | 1618 | |
---|
[4a7ad5f] | 1619 | def _reset_parameters_state(self, listtorestore, statelist): |
---|
[cfc0913] | 1620 | """ |
---|
[5062bbf] | 1621 | Reset the parameters at the given state |
---|
[cfc0913] | 1622 | """ |
---|
[4a7ad5f] | 1623 | if len(statelist) == 0 or len(listtorestore) == 0: |
---|
[6999659] | 1624 | return |
---|
[ef26c83] | 1625 | if len(statelist) != len(listtorestore): |
---|
[cfc0913] | 1626 | return |
---|
[c99a6c5] | 1627 | |
---|
[cfc0913] | 1628 | for j in range(len(listtorestore)): |
---|
| 1629 | item_page = listtorestore[j] |
---|
| 1630 | item_page_info = statelist[j] |
---|
| 1631 | ##change the state of the check box for simple parameters |
---|
[ef26c83] | 1632 | if item_page[0] != None: |
---|
[cfc0913] | 1633 | item_page[0].SetValue(item_page_info[0]) |
---|
[ef26c83] | 1634 | if item_page[2] != None: |
---|
[cfc0913] | 1635 | item_page[2].SetValue(item_page_info[2]) |
---|
[2296316] | 1636 | if item_page[2].__class__.__name__ == "ComboBox": |
---|
[ef26c83] | 1637 | if item_page_info[2] in self.model.fun_list: |
---|
| 1638 | fun_val = self.model.fun_list[item_page_info[2]] |
---|
| 1639 | self.model.setParam(item_page_info[1], fun_val) |
---|
| 1640 | if item_page[3] != None: |
---|
[cfc0913] | 1641 | ## show or hide text +/- |
---|
| 1642 | if item_page_info[2]: |
---|
| 1643 | item_page[3].Show(True) |
---|
| 1644 | else: |
---|
| 1645 | item_page[3].Hide() |
---|
[ef26c83] | 1646 | if item_page[4] != None: |
---|
[cfc0913] | 1647 | ## show of hide the text crtl for fitting error |
---|
| 1648 | if item_page_info[4][0]: |
---|
| 1649 | item_page[4].Show(True) |
---|
| 1650 | item_page[4].SetValue(item_page_info[4][1]) |
---|
| 1651 | else: |
---|
| 1652 | item_page[3].Hide() |
---|
[ef26c83] | 1653 | if item_page[5] != None: |
---|
[cfc0913] | 1654 | ## show of hide the text crtl for fitting error |
---|
[2296316] | 1655 | item_page[5].Show(item_page_info[5][0]) |
---|
| 1656 | item_page[5].SetValue(item_page_info[5][1]) |
---|
| 1657 | |
---|
[ef26c83] | 1658 | if item_page[6] != None: |
---|
[cfc0913] | 1659 | ## show of hide the text crtl for fitting error |
---|
[2296316] | 1660 | item_page[6].Show(item_page_info[6][0]) |
---|
| 1661 | item_page[6].SetValue(item_page_info[6][1]) |
---|
| 1662 | |
---|
| 1663 | def _reset_strparam_state(self, listtorestore, statelist): |
---|
| 1664 | """ |
---|
| 1665 | Reset the string parameters at the given state |
---|
| 1666 | """ |
---|
| 1667 | if len(statelist) == 0: |
---|
| 1668 | return |
---|
| 1669 | |
---|
| 1670 | listtorestore = copy.deepcopy(statelist) |
---|
| 1671 | |
---|
| 1672 | for j in range(len(listtorestore)): |
---|
| 1673 | item_page = listtorestore[j] |
---|
| 1674 | item_page_info = statelist[j] |
---|
| 1675 | ##change the state of the check box for simple parameters |
---|
| 1676 | |
---|
[ef26c83] | 1677 | if item_page[0] != None: |
---|
[2296316] | 1678 | item_page[0].SetValue(format_number(item_page_info[0], True)) |
---|
| 1679 | |
---|
| 1680 | if item_page[2] != None: |
---|
| 1681 | param_name = item_page_info[1] |
---|
| 1682 | value = item_page_info[2] |
---|
| 1683 | selection = value |
---|
[ef26c83] | 1684 | if value in self.model.fun_list: |
---|
[2296316] | 1685 | selection = self.model.fun_list[value] |
---|
| 1686 | item_page[2].SetValue(selection) |
---|
| 1687 | self.model.setParam(param_name, selection) |
---|
[5062bbf] | 1688 | |
---|
[cfc0913] | 1689 | def _copy_parameters_state(self, listtocopy, statelist): |
---|
| 1690 | """ |
---|
[ef26c83] | 1691 | copy the state of button |
---|
[5062bbf] | 1692 | |
---|
| 1693 | :param listtocopy: the list of check button to copy |
---|
| 1694 | :param statelist: list of state object to store the current state |
---|
| 1695 | |
---|
[cfc0913] | 1696 | """ |
---|
[ef26c83] | 1697 | if len(listtocopy) == 0: |
---|
[cfc0913] | 1698 | return |
---|
[1c1436d] | 1699 | |
---|
[cfc0913] | 1700 | for item in listtocopy: |
---|
[f20767b] | 1701 | |
---|
[cfc0913] | 1702 | checkbox_state = None |
---|
[ef26c83] | 1703 | if item[0] != None: |
---|
| 1704 | checkbox_state = item[0].GetValue() |
---|
[cfc0913] | 1705 | parameter_name = item[1] |
---|
| 1706 | parameter_value = None |
---|
[ef26c83] | 1707 | if item[2] != None: |
---|
[cfc0913] | 1708 | parameter_value = item[2].GetValue() |
---|
| 1709 | static_text = None |
---|
[ef26c83] | 1710 | if item[3] != None: |
---|
[cfc0913] | 1711 | static_text = item[3].IsShown() |
---|
| 1712 | error_value = None |
---|
| 1713 | error_state = None |
---|
[ef26c83] | 1714 | if item[4] != None: |
---|
[cfc0913] | 1715 | error_value = item[4].GetValue() |
---|
| 1716 | error_state = item[4].IsShown() |
---|
| 1717 | |
---|
| 1718 | min_value = None |
---|
| 1719 | min_state = None |
---|
[ef26c83] | 1720 | if item[5] != None: |
---|
[cfc0913] | 1721 | min_value = item[5].GetValue() |
---|
| 1722 | min_state = item[5].IsShown() |
---|
| 1723 | |
---|
| 1724 | max_value = None |
---|
| 1725 | max_state = None |
---|
[ef26c83] | 1726 | if item[6] != None: |
---|
[cfc0913] | 1727 | max_value = item[6].GetValue() |
---|
| 1728 | max_state = item[6].IsShown() |
---|
[ef26c83] | 1729 | unit = None |
---|
| 1730 | if item[7] != None: |
---|
[240b9966] | 1731 | unit = item[7].GetLabel() |
---|
[cfc0913] | 1732 | |
---|
| 1733 | statelist.append([checkbox_state, parameter_name, parameter_value, |
---|
[ef26c83] | 1734 | static_text, [error_state, error_value], |
---|
| 1735 | [min_state, min_value], |
---|
| 1736 | [max_state, max_value], unit]) |
---|
[cfc0913] | 1737 | |
---|
[c77d859] | 1738 | def _set_model_sizer_selection(self, model): |
---|
| 1739 | """ |
---|
[5062bbf] | 1740 | Display the sizer according to the type of the current model |
---|
[c77d859] | 1741 | """ |
---|
[5062bbf] | 1742 | if model == None: |
---|
[70c57ebf] | 1743 | return |
---|
[ef26c83] | 1744 | if hasattr(model, "s_model"): |
---|
[c77d859] | 1745 | |
---|
[4a7ad5f] | 1746 | class_name = model.s_model.__class__ |
---|
| 1747 | name = model.s_model.name |
---|
| 1748 | flag = (name != "NoStructure") |
---|
| 1749 | if flag and \ |
---|
| 1750 | (class_name in self.model_list_box["Structure Factors"]): |
---|
[6dc9ad8] | 1751 | self.structurebox.Show() |
---|
[ef26c83] | 1752 | self.text2.Show() |
---|
[3b605bb] | 1753 | self.structurebox.Enable() |
---|
[c097f02] | 1754 | self.text2.Enable() |
---|
[c77d859] | 1755 | items = self.structurebox.GetItems() |
---|
| 1756 | self.sizer1.Layout() |
---|
[340c2b3] | 1757 | |
---|
[c77d859] | 1758 | for i in range(len(items)): |
---|
[ef26c83] | 1759 | if items[i] == str(name): |
---|
[c77d859] | 1760 | self.structurebox.SetSelection(i) |
---|
| 1761 | break |
---|
| 1762 | |
---|
[ef26c83] | 1763 | if hasattr(model, "p_model"): |
---|
[72f719b] | 1764 | class_name = model.p_model.__class__ |
---|
| 1765 | name = model.p_model.name |
---|
[c77d859] | 1766 | self.formfactorbox.Clear() |
---|
| 1767 | |
---|
| 1768 | for k, list in self.model_list_box.iteritems(): |
---|
[ef26c83] | 1769 | if k in["P(Q)*S(Q)", "Shapes"] and \ |
---|
| 1770 | class_name in self.model_list_box["Shapes"]: |
---|
[c77d859] | 1771 | self.shape_rbutton.SetValue(True) |
---|
[376916c] | 1772 | ## fill the form factor list with new model |
---|
[ef26c83] | 1773 | self._populate_box(self.formfactorbox, |
---|
| 1774 | self.model_list_box["Shapes"]) |
---|
[376916c] | 1775 | items = self.formfactorbox.GetItems() |
---|
| 1776 | ## set comboxbox to the selected item |
---|
| 1777 | for i in range(len(items)): |
---|
[ef26c83] | 1778 | if items[i] == str(name): |
---|
[376916c] | 1779 | self.formfactorbox.SetSelection(i) |
---|
| 1780 | break |
---|
| 1781 | return |
---|
| 1782 | elif k == "Shape-Independent": |
---|
[c77d859] | 1783 | self.shape_indep_rbutton.SetValue(True) |
---|
| 1784 | elif k == "Structure Factors": |
---|
[ef26c83] | 1785 | self.struct_rbutton.SetValue(True) |
---|
| 1786 | elif k == "Multi-Functions": |
---|
[fb59ed9] | 1787 | continue |
---|
[c77d859] | 1788 | else: |
---|
| 1789 | self.plugin_rbutton.SetValue(True) |
---|
[376916c] | 1790 | |
---|
[c77d859] | 1791 | if class_name in list: |
---|
| 1792 | ## fill the form factor list with new model |
---|
| 1793 | self._populate_box(self.formfactorbox, list) |
---|
| 1794 | items = self.formfactorbox.GetItems() |
---|
| 1795 | ## set comboxbox to the selected item |
---|
| 1796 | for i in range(len(items)): |
---|
[ef26c83] | 1797 | if items[i] == str(name): |
---|
[c77d859] | 1798 | self.formfactorbox.SetSelection(i) |
---|
| 1799 | break |
---|
| 1800 | break |
---|
| 1801 | else: |
---|
[cdbe88e] | 1802 | ## Select the model from the menu |
---|
[c77d859] | 1803 | class_name = model.__class__ |
---|
| 1804 | name = model.name |
---|
| 1805 | self.formfactorbox.Clear() |
---|
| 1806 | items = self.formfactorbox.GetItems() |
---|
[376916c] | 1807 | |
---|
[ef26c83] | 1808 | for k, list in self.model_list_box.iteritems(): |
---|
| 1809 | if k in["P(Q)*S(Q)", "Shapes"] and \ |
---|
| 1810 | class_name in self.model_list_box["Shapes"]: |
---|
[3b605bb] | 1811 | if class_name in self.model_list_box["P(Q)*S(Q)"]: |
---|
[6dc9ad8] | 1812 | self.structurebox.Show() |
---|
| 1813 | self.text2.Show() |
---|
[3b605bb] | 1814 | self.structurebox.Enable() |
---|
[cdbe88e] | 1815 | self.structurebox.SetSelection(0) |
---|
[c097f02] | 1816 | self.text2.Enable() |
---|
[3b605bb] | 1817 | else: |
---|
[6dc9ad8] | 1818 | self.structurebox.Hide() |
---|
| 1819 | self.text2.Hide() |
---|
[3b605bb] | 1820 | self.structurebox.Disable() |
---|
| 1821 | self.structurebox.SetSelection(0) |
---|
[c097f02] | 1822 | self.text2.Disable() |
---|
[3b605bb] | 1823 | |
---|
[c77d859] | 1824 | self.shape_rbutton.SetValue(True) |
---|
[376916c] | 1825 | ## fill the form factor list with new model |
---|
[ef26c83] | 1826 | self._populate_box(self.formfactorbox, |
---|
| 1827 | self.model_list_box["Shapes"]) |
---|
[376916c] | 1828 | items = self.formfactorbox.GetItems() |
---|
| 1829 | ## set comboxbox to the selected item |
---|
| 1830 | for i in range(len(items)): |
---|
[ef26c83] | 1831 | if items[i] == str(name): |
---|
[376916c] | 1832 | self.formfactorbox.SetSelection(i) |
---|
| 1833 | break |
---|
| 1834 | return |
---|
| 1835 | elif k == "Shape-Independent": |
---|
[c77d859] | 1836 | self.shape_indep_rbutton.SetValue(True) |
---|
| 1837 | elif k == "Structure Factors": |
---|
[cdbe88e] | 1838 | self.struct_rbutton.SetValue(True) |
---|
[ef26c83] | 1839 | elif k == "Multi-Functions": |
---|
[fb59ed9] | 1840 | continue |
---|
[c77d859] | 1841 | else: |
---|
| 1842 | self.plugin_rbutton.SetValue(True) |
---|
| 1843 | if class_name in list: |
---|
[3b605bb] | 1844 | self.structurebox.SetSelection(0) |
---|
| 1845 | self.structurebox.Disable() |
---|
[ef26c83] | 1846 | self.text2.Disable() |
---|
[376916c] | 1847 | ## fill the form factor list with new model |
---|
[c77d859] | 1848 | self._populate_box(self.formfactorbox, list) |
---|
| 1849 | items = self.formfactorbox.GetItems() |
---|
| 1850 | ## set comboxbox to the selected item |
---|
| 1851 | for i in range(len(items)): |
---|
[ef26c83] | 1852 | if items[i] == str(name): |
---|
[c77d859] | 1853 | self.formfactorbox.SetSelection(i) |
---|
| 1854 | break |
---|
| 1855 | break |
---|
[7fd4afd] | 1856 | |
---|
[e3f6ef5] | 1857 | def _draw_model(self, update_chisqr=True, source='model'): |
---|
[c77d859] | 1858 | """ |
---|
[5062bbf] | 1859 | Method to draw or refresh a plotted model. |
---|
| 1860 | The method will use the data member from the model page |
---|
| 1861 | to build a call to the fitting perspective manager. |
---|
[2296316] | 1862 | |
---|
| 1863 | :param chisqr: update chisqr value [bool] |
---|
[c77d859] | 1864 | """ |
---|
[7fd4afd] | 1865 | wx.CallAfter(self._draw_model_after, update_chisqr, source) |
---|
| 1866 | |
---|
| 1867 | def _draw_model_after(self, update_chisqr=True, source='model'): |
---|
| 1868 | """ |
---|
| 1869 | Method to draw or refresh a plotted model. |
---|
| 1870 | The method will use the data member from the model page |
---|
| 1871 | to build a call to the fitting perspective manager. |
---|
| 1872 | |
---|
| 1873 | :param chisqr: update chisqr value [bool] |
---|
| 1874 | """ |
---|
[6bbeacd4] | 1875 | #if self.check_invalid_panel(): |
---|
| 1876 | # return |
---|
[ef26c83] | 1877 | if self.model != None: |
---|
| 1878 | temp_smear = None |
---|
[fca9cbd9] | 1879 | if hasattr(self, "enable_smearer"): |
---|
[7609f1a] | 1880 | if not self.disable_smearer.GetValue(): |
---|
[ef26c83] | 1881 | temp_smear = self.current_smearer |
---|
[f7ef313] | 1882 | # compute weight for the current data |
---|
| 1883 | from .utils import get_weight |
---|
| 1884 | flag = self.get_weight_flag() |
---|
| 1885 | weight = get_weight(data=self.data, is2d=self._is_2D(), flag=flag) |
---|
[fa65e99] | 1886 | toggle_mode_on = self.model_view.IsEnabled() |
---|
[01642fec] | 1887 | is_2d = self._is_2D() |
---|
[ef26c83] | 1888 | self._manager.draw_model(self.model, |
---|
[f72333f] | 1889 | data=self.data, |
---|
[ef26c83] | 1890 | smearer=temp_smear, |
---|
| 1891 | qmin=float(self.qmin_x), |
---|
[484faf7] | 1892 | qmax=float(self.qmax_x), |
---|
[66ff250] | 1893 | page_id=self.uid, |
---|
[ef26c83] | 1894 | toggle_mode_on=toggle_mode_on, |
---|
| 1895 | state=self.state, |
---|
[01642fec] | 1896 | enable2D=is_2d, |
---|
[55bb249c] | 1897 | update_chisqr=update_chisqr, |
---|
[e3f6ef5] | 1898 | source='model', |
---|
[55bb249c] | 1899 | weight=weight) |
---|
[71f0373] | 1900 | |
---|
[a1b2471] | 1901 | def _on_show_sld(self, event=None): |
---|
| 1902 | """ |
---|
| 1903 | Plot SLD profile |
---|
| 1904 | """ |
---|
| 1905 | # get profile data |
---|
[ef26c83] | 1906 | x, y = self.model.getProfile() |
---|
[a1b2471] | 1907 | |
---|
| 1908 | from danse.common.plottools import Data1D |
---|
[da9ac4e6] | 1909 | #from sans.perspectives.theory.profile_dialog import SLDPanel |
---|
| 1910 | from sans.guiframe.local_perspectives.plotting.profile_dialog \ |
---|
| 1911 | import SLDPanel |
---|
[ef26c83] | 1912 | sld_data = Data1D(x, y) |
---|
[a1b2471] | 1913 | sld_data.name = 'SLD' |
---|
[fb59ed9] | 1914 | sld_data.axes = self.sld_axes |
---|
[ef26c83] | 1915 | self.panel = SLDPanel(self, data=sld_data, axes=self.sld_axes, id=-1) |
---|
| 1916 | self.panel.ShowModal() |
---|
[a1b2471] | 1917 | |
---|
[ef26c83] | 1918 | def _set_multfactor_combobox(self, multiplicity=10): |
---|
[4523b68] | 1919 | """ |
---|
| 1920 | Set comboBox for muitfactor of CoreMultiShellModel |
---|
[fb59ed9] | 1921 | :param multiplicit: no. of multi-functionality |
---|
[4523b68] | 1922 | """ |
---|
[fb59ed9] | 1923 | # build content of the combobox |
---|
[ef26c83] | 1924 | for idx in range(0, multiplicity): |
---|
| 1925 | self.multifactorbox.Append(str(idx), int(idx)) |
---|
[4523b68] | 1926 | self._hide_multfactor_combobox() |
---|
| 1927 | |
---|
[ef26c83] | 1928 | def _show_multfactor_combobox(self): |
---|
[4523b68] | 1929 | """ |
---|
| 1930 | Show the comboBox of muitfactor of CoreMultiShellModel |
---|
[ef26c83] | 1931 | """ |
---|
[4523b68] | 1932 | if not self.mutifactor_text.IsShown(): |
---|
| 1933 | self.mutifactor_text.Show(True) |
---|
[fb59ed9] | 1934 | self.mutifactor_text1.Show(True) |
---|
[4523b68] | 1935 | if not self.multifactorbox.IsShown(): |
---|
[ef26c83] | 1936 | self.multifactorbox.Show(True) |
---|
[4523b68] | 1937 | |
---|
[ef26c83] | 1938 | def _hide_multfactor_combobox(self): |
---|
[4523b68] | 1939 | """ |
---|
| 1940 | Hide the comboBox of muitfactor of CoreMultiShellModel |
---|
[ef26c83] | 1941 | """ |
---|
[4523b68] | 1942 | if self.mutifactor_text.IsShown(): |
---|
| 1943 | self.mutifactor_text.Hide() |
---|
[fb59ed9] | 1944 | self.mutifactor_text1.Hide() |
---|
[4523b68] | 1945 | if self.multifactorbox.IsShown(): |
---|
[ef26c83] | 1946 | self.multifactorbox.Hide() |
---|
[4523b68] | 1947 | |
---|
[0b12abb5] | 1948 | def _show_combox_helper(self): |
---|
[c77d859] | 1949 | """ |
---|
[0b12abb5] | 1950 | Fill panel's combo box according to the type of model selected |
---|
[c77d859] | 1951 | """ |
---|
[0b12abb5] | 1952 | if self.shape_rbutton.GetValue(): |
---|
[376916c] | 1953 | ##fill the combobox with form factor list |
---|
[3b605bb] | 1954 | self.structurebox.SetSelection(0) |
---|
| 1955 | self.structurebox.Disable() |
---|
[c77d859] | 1956 | self.formfactorbox.Clear() |
---|
[ef26c83] | 1957 | self._populate_box(self.formfactorbox, |
---|
| 1958 | self.model_list_box["Shapes"]) |
---|
[0b12abb5] | 1959 | if self.shape_indep_rbutton.GetValue(): |
---|
[376916c] | 1960 | ##fill the combobox with shape independent factor list |
---|
[3b605bb] | 1961 | self.structurebox.SetSelection(0) |
---|
| 1962 | self.structurebox.Disable() |
---|
[c77d859] | 1963 | self.formfactorbox.Clear() |
---|
[ef26c83] | 1964 | self._populate_box(self.formfactorbox, |
---|
| 1965 | self.model_list_box["Shape-Independent"]) |
---|
[0b12abb5] | 1966 | if self.struct_rbutton.GetValue(): |
---|
[376916c] | 1967 | ##fill the combobox with structure factor list |
---|
[3b605bb] | 1968 | self.structurebox.SetSelection(0) |
---|
| 1969 | self.structurebox.Disable() |
---|
[c77d859] | 1970 | self.formfactorbox.Clear() |
---|
[ef26c83] | 1971 | self._populate_box(self.formfactorbox, |
---|
| 1972 | self.model_list_box["Structure Factors"]) |
---|
[0b12abb5] | 1973 | if self.plugin_rbutton.GetValue(): |
---|
[376916c] | 1974 | ##fill the combobox with form factor list |
---|
[3b605bb] | 1975 | self.structurebox.Disable() |
---|
[c77d859] | 1976 | self.formfactorbox.Clear() |
---|
[ef26c83] | 1977 | self._populate_box(self.formfactorbox, |
---|
| 1978 | self.model_list_box["Customized Models"]) |
---|
[3595309d] | 1979 | |
---|
[0b12abb5] | 1980 | def _show_combox(self, event=None): |
---|
| 1981 | """ |
---|
| 1982 | Show combox box associate with type of model selected |
---|
| 1983 | """ |
---|
[dbbdf11] | 1984 | self.Show(False) |
---|
[0b12abb5] | 1985 | self._show_combox_helper() |
---|
[77e23a2] | 1986 | self._on_select_model(event=None) |
---|
[dbbdf11] | 1987 | self.Show(True) |
---|
[3595309d] | 1988 | self._save_typeOfmodel() |
---|
[3b605bb] | 1989 | self.sizer4_4.Layout() |
---|
[9853ad0] | 1990 | self.sizer4.Layout() |
---|
[3b605bb] | 1991 | self.Layout() |
---|
| 1992 | self.Refresh() |
---|
[340c2b3] | 1993 | |
---|
[c77d859] | 1994 | def _populate_box(self, combobox, list): |
---|
| 1995 | """ |
---|
[5062bbf] | 1996 | fill combox box with dict item |
---|
| 1997 | |
---|
| 1998 | :param list: contains item to fill the combox |
---|
[c77d859] | 1999 | item must model class |
---|
| 2000 | """ |
---|
[f74673c] | 2001 | mlist = [] |
---|
[c77d859] | 2002 | for models in list: |
---|
[ef26c83] | 2003 | model = models() |
---|
[c77d859] | 2004 | name = model.__class__.__name__ |
---|
[ef26c83] | 2005 | if models.__name__ != "NoStructure": |
---|
[0a518e4c] | 2006 | if hasattr(model, "name"): |
---|
| 2007 | name = model.name |
---|
[ef26c83] | 2008 | mlist.append((name, models)) |
---|
[f74673c] | 2009 | |
---|
| 2010 | # Sort the models |
---|
[8df5faa] | 2011 | mlist_sorted = sorted(mlist) |
---|
[f74673c] | 2012 | for item in mlist_sorted: |
---|
[ef26c83] | 2013 | combobox.Append(item[0], item[1]) |
---|
[c77d859] | 2014 | return 0 |
---|
[6bbeacd4] | 2015 | |
---|
[6e9976b] | 2016 | def _onQrangeEnter(self, event): |
---|
| 2017 | """ |
---|
[5062bbf] | 2018 | Check validity of value enter in the Q range field |
---|
[6bbeacd4] | 2019 | |
---|
| 2020 | """ |
---|
| 2021 | tcrtl = event.GetEventObject() |
---|
| 2022 | #Clear msg if previously shown. |
---|
| 2023 | msg = "" |
---|
| 2024 | wx.PostEvent(self.parent, StatusEvent(status=msg)) |
---|
| 2025 | # Flag to register when a parameter has changed. |
---|
| 2026 | is_modified = False |
---|
| 2027 | if tcrtl.GetValue().lstrip().rstrip() != "": |
---|
| 2028 | try: |
---|
| 2029 | value = float(tcrtl.GetValue()) |
---|
| 2030 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
| 2031 | # If qmin and qmax have been modified, update qmin and qmax |
---|
[f95301b] | 2032 | if self._validate_qrange(self.qmin, self.qmax): |
---|
| 2033 | tempmin = float(self.qmin.GetValue()) |
---|
[6bbeacd4] | 2034 | if tempmin != self.qmin_x: |
---|
| 2035 | self.qmin_x = tempmin |
---|
| 2036 | tempmax = float(self.qmax.GetValue()) |
---|
| 2037 | if tempmax != self.qmax_x: |
---|
| 2038 | self.qmax_x = tempmax |
---|
| 2039 | else: |
---|
| 2040 | tcrtl.SetBackgroundColour("pink") |
---|
[ef26c83] | 2041 | msg = "Model Error:wrong value entered: %s" % sys.exc_value |
---|
[6bbeacd4] | 2042 | wx.PostEvent(self.parent, StatusEvent(status=msg)) |
---|
[ef26c83] | 2043 | return |
---|
[6bbeacd4] | 2044 | except: |
---|
| 2045 | tcrtl.SetBackgroundColour("pink") |
---|
[ef26c83] | 2046 | msg = "Model Error:wrong value entered: %s" % sys.exc_value |
---|
[6bbeacd4] | 2047 | wx.PostEvent(self.parent, StatusEvent(status=msg)) |
---|
[ef26c83] | 2048 | return |
---|
[6bbeacd4] | 2049 | #Check if # of points for theory model are valid(>0). |
---|
| 2050 | if self.npts != None: |
---|
| 2051 | if check_float(self.npts): |
---|
| 2052 | temp_npts = float(self.npts.GetValue()) |
---|
[ef26c83] | 2053 | if temp_npts != self.num_points: |
---|
[6bbeacd4] | 2054 | self.num_points = temp_npts |
---|
| 2055 | is_modified = True |
---|
| 2056 | else: |
---|
| 2057 | msg = "Cannot Plot :No npts in that Qrange!!! " |
---|
| 2058 | wx.PostEvent(self.parent, StatusEvent(status=msg)) |
---|
| 2059 | else: |
---|
[ef26c83] | 2060 | tcrtl.SetBackgroundColour("pink") |
---|
| 2061 | msg = "Model Error:wrong value entered!!!" |
---|
| 2062 | wx.PostEvent(self.parent, StatusEvent(status=msg)) |
---|
[6bbeacd4] | 2063 | self.save_current_state() |
---|
| 2064 | event = PageInfoEvent(page=self) |
---|
| 2065 | wx.PostEvent(self.parent, event) |
---|
| 2066 | self.state_change = False |
---|
| 2067 | #Draw the model for a different range |
---|
[b582d6bc] | 2068 | if not self.data.is_data: |
---|
| 2069 | self.create_default_data() |
---|
[6bbeacd4] | 2070 | self._draw_model() |
---|
| 2071 | |
---|
| 2072 | def _theory_qrange_enter(self, event): |
---|
| 2073 | """ |
---|
| 2074 | Check validity of value enter in the Q range field |
---|
[6e9976b] | 2075 | """ |
---|
| 2076 | |
---|
[ef26c83] | 2077 | tcrtl = event.GetEventObject() |
---|
[6e9976b] | 2078 | #Clear msg if previously shown. |
---|
[ef26c83] | 2079 | msg = "" |
---|
| 2080 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
[6e9976b] | 2081 | # Flag to register when a parameter has changed. |
---|
| 2082 | is_modified = False |
---|
[ef26c83] | 2083 | if tcrtl.GetValue().lstrip().rstrip() != "": |
---|
[6e9976b] | 2084 | try: |
---|
| 2085 | value = float(tcrtl.GetValue()) |
---|
| 2086 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
| 2087 | |
---|
| 2088 | # If qmin and qmax have been modified, update qmin and qmax |
---|
[6bbeacd4] | 2089 | if self._validate_qrange(self.theory_qmin, self.theory_qmax): |
---|
| 2090 | tempmin = float(self.theory_qmin.GetValue()) |
---|
| 2091 | if tempmin != self.theory_qmin_x: |
---|
| 2092 | self.theory_qmin_x = tempmin |
---|
| 2093 | tempmax = float(self.theory_qmax.GetValue()) |
---|
[6e9976b] | 2094 | if tempmax != self.qmax_x: |
---|
[6bbeacd4] | 2095 | self.theory_qmax_x = tempmax |
---|
[6e9976b] | 2096 | else: |
---|
| 2097 | tcrtl.SetBackgroundColour("pink") |
---|
[ef26c83] | 2098 | msg = "Model Error:wrong value entered: %s" % sys.exc_value |
---|
| 2099 | wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) |
---|
| 2100 | return |
---|
[6e9976b] | 2101 | except: |
---|
| 2102 | tcrtl.SetBackgroundColour("pink") |
---|
[ef26c83] | 2103 | msg = "Model Error:wrong value entered: %s" % sys.exc_value |
---|
| 2104 | wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) |
---|
| 2105 | return |
---|
[6e9976b] | 2106 | #Check if # of points for theory model are valid(>0). |
---|
[ef26c83] | 2107 | if self.Npts_total.IsEditable(): |
---|
[0cf97c5] | 2108 | if check_float(self.Npts_total): |
---|
| 2109 | temp_npts = float(self.Npts_total.GetValue()) |
---|
[ef26c83] | 2110 | if temp_npts != self.num_points: |
---|
[6e9976b] | 2111 | self.num_points = temp_npts |
---|
| 2112 | is_modified = True |
---|
| 2113 | else: |
---|
[ef26c83] | 2114 | msg = "Cannot Plot :No npts in that Qrange!!! " |
---|
| 2115 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
[6e9976b] | 2116 | else: |
---|
[ef26c83] | 2117 | tcrtl.SetBackgroundColour("pink") |
---|
| 2118 | msg = "Model Error:wrong value entered!!!" |
---|
| 2119 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
[6e9976b] | 2120 | self.save_current_state() |
---|
[ef26c83] | 2121 | event = PageInfoEvent(page=self) |
---|
[6e9976b] | 2122 | wx.PostEvent(self.parent, event) |
---|
[ef26c83] | 2123 | self.state_change = False |
---|
[484faf7] | 2124 | #Draw the model for a different range |
---|
[ecf26e1] | 2125 | self.create_default_data() |
---|
[484faf7] | 2126 | self._draw_model() |
---|
[6e9976b] | 2127 | |
---|
[ef26c83] | 2128 | def _on_select_model_helper(self): |
---|
[c77d859] | 2129 | """ |
---|
[5062bbf] | 2130 | call back for model selection |
---|
[c77d859] | 2131 | """ |
---|
[376916c] | 2132 | ## reset dictionary containing reference to dispersion |
---|
| 2133 | self._disp_obj_dict = {} |
---|
[ef26c83] | 2134 | self.disp_cb_dict = {} |
---|
[8960479] | 2135 | self.temp_multi_functional = False |
---|
[c77d859] | 2136 | f_id = self.formfactorbox.GetCurrentSelection() |
---|
[ff8f99b] | 2137 | #For MAC |
---|
| 2138 | form_factor = None |
---|
| 2139 | if f_id >= 0: |
---|
[0b12abb5] | 2140 | form_factor = self.formfactorbox.GetClientData(f_id) |
---|
[9170547] | 2141 | |
---|
[376916c] | 2142 | if not form_factor in self.model_list_box["multiplication"]: |
---|
[6dc9ad8] | 2143 | self.structurebox.Hide() |
---|
[ef26c83] | 2144 | self.text2.Hide() |
---|
[3b605bb] | 2145 | self.structurebox.Disable() |
---|
| 2146 | self.structurebox.SetSelection(0) |
---|
[c097f02] | 2147 | self.text2.Disable() |
---|
[87fbc60] | 2148 | else: |
---|
[6dc9ad8] | 2149 | self.structurebox.Show() |
---|
| 2150 | self.text2.Show() |
---|
[87fbc60] | 2151 | self.structurebox.Enable() |
---|
[c097f02] | 2152 | self.text2.Enable() |
---|
[4523b68] | 2153 | |
---|
[ef26c83] | 2154 | if form_factor != None: |
---|
| 2155 | # set multifactor for Mutifunctional models |
---|
[e87f9fc] | 2156 | if form_factor().__class__ in self.model_list_box["Multi-Functions"]: |
---|
[4523b68] | 2157 | m_id = self.multifactorbox.GetCurrentSelection() |
---|
[fb59ed9] | 2158 | multiplicity = form_factor().multiplicity_info[0] |
---|
| 2159 | self.multifactorbox.Clear() |
---|
| 2160 | self._set_multfactor_combobox(multiplicity) |
---|
| 2161 | self._show_multfactor_combobox() |
---|
[ef26c83] | 2162 | #ToDo: this info should be called directly from the model |
---|
| 2163 | text = form_factor().multiplicity_info[1] # 'No. of Shells: ' |
---|
[fb59ed9] | 2164 | |
---|
| 2165 | self.mutifactor_text.SetLabel(text) |
---|
[ef26c83] | 2166 | if m_id > multiplicity - 1: |
---|
[fb59ed9] | 2167 | # default value |
---|
| 2168 | m_id = 1 |
---|
| 2169 | |
---|
[4523b68] | 2170 | self.multi_factor = self.multifactorbox.GetClientData(m_id) |
---|
[ef26c83] | 2171 | if self.multi_factor == None: |
---|
| 2172 | self.multi_factor = 0 |
---|
[4523b68] | 2173 | form_factor = form_factor(int(self.multi_factor)) |
---|
[fb59ed9] | 2174 | self.multifactorbox.SetSelection(m_id) |
---|
| 2175 | # Check len of the text1 and max_multiplicity |
---|
| 2176 | text = '' |
---|
| 2177 | if form_factor.multiplicity_info[0] == len(form_factor.multiplicity_info[2]): |
---|
| 2178 | text = form_factor.multiplicity_info[2][self.multi_factor] |
---|
| 2179 | self.mutifactor_text1.SetLabel(text) |
---|
| 2180 | # Check if model has get sld profile. |
---|
| 2181 | if len(form_factor.multiplicity_info[3]) > 0: |
---|
| 2182 | self.sld_axes = form_factor.multiplicity_info[3] |
---|
| 2183 | self.show_sld_button.Show(True) |
---|
| 2184 | else: |
---|
| 2185 | self.sld_axes = "" |
---|
| 2186 | |
---|
[4523b68] | 2187 | else: |
---|
| 2188 | self._hide_multfactor_combobox() |
---|
[a1b2471] | 2189 | self.show_sld_button.Hide() |
---|
[4523b68] | 2190 | form_factor = form_factor() |
---|
| 2191 | self.multi_factor = None |
---|
| 2192 | else: |
---|
| 2193 | self._hide_multfactor_combobox() |
---|
[a1b2471] | 2194 | self.show_sld_button.Hide() |
---|
[ef26c83] | 2195 | self.multi_factor = None |
---|
[4523b68] | 2196 | |
---|
[3b605bb] | 2197 | s_id = self.structurebox.GetCurrentSelection() |
---|
[ef26c83] | 2198 | struct_factor = self.structurebox.GetClientData(s_id) |
---|
[4523b68] | 2199 | |
---|
[ef26c83] | 2200 | if struct_factor != None: |
---|
[9853ad0] | 2201 | from sans.models.MultiplicationModel import MultiplicationModel |
---|
[ef26c83] | 2202 | self.model = MultiplicationModel(form_factor, struct_factor()) |
---|
[8960479] | 2203 | # multifunctional form factor |
---|
| 2204 | if len(form_factor.non_fittable) > 0: |
---|
| 2205 | self.temp_multi_functional = True |
---|
[c77d859] | 2206 | else: |
---|
[fbf4bf8] | 2207 | if form_factor != None: |
---|
[ef26c83] | 2208 | self.model = form_factor |
---|
[fbf4bf8] | 2209 | else: |
---|
| 2210 | self.model = None |
---|
| 2211 | return self.model |
---|
[4523b68] | 2212 | |
---|
[cfc0913] | 2213 | ## post state to fit panel |
---|
[ef26c83] | 2214 | self.state.parameters = [] |
---|
| 2215 | self.state.model = self.model |
---|
[4523b68] | 2216 | self.state.qmin = self.qmin_x |
---|
| 2217 | self.state.multi_factor = self.multi_factor |
---|
[ef26c83] | 2218 | self.disp_list = self.model.getDispParamList() |
---|
[f20767b] | 2219 | self.state.disp_list = self.disp_list |
---|
[fadf925] | 2220 | self.on_set_focus(None) |
---|
[ef26c83] | 2221 | self.Layout() |
---|
[c99a6c5] | 2222 | |
---|
[85b3971] | 2223 | def _validate_qrange(self, qmin_ctrl, qmax_ctrl): |
---|
| 2224 | """ |
---|
[5062bbf] | 2225 | Verify that the Q range controls have valid values |
---|
| 2226 | and that Qmin < Qmax. |
---|
| 2227 | |
---|
| 2228 | :param qmin_ctrl: text control for Qmin |
---|
| 2229 | :param qmax_ctrl: text control for Qmax |
---|
| 2230 | |
---|
[ef26c83] | 2231 | :return: True is the Q range is value, False otherwise |
---|
[5062bbf] | 2232 | |
---|
[85b3971] | 2233 | """ |
---|
| 2234 | qmin_validity = check_float(qmin_ctrl) |
---|
| 2235 | qmax_validity = check_float(qmax_ctrl) |
---|
| 2236 | if not (qmin_validity and qmax_validity): |
---|
| 2237 | return False |
---|
| 2238 | else: |
---|
| 2239 | qmin = float(qmin_ctrl.GetValue()) |
---|
| 2240 | qmax = float(qmax_ctrl.GetValue()) |
---|
[e0e22f2c] | 2241 | if qmin < qmax: |
---|
[ef26c83] | 2242 | #Make sure to set both colours white. |
---|
[85b3971] | 2243 | qmin_ctrl.SetBackgroundColour(wx.WHITE) |
---|
| 2244 | qmin_ctrl.Refresh() |
---|
| 2245 | qmax_ctrl.SetBackgroundColour(wx.WHITE) |
---|
| 2246 | qmax_ctrl.Refresh() |
---|
| 2247 | else: |
---|
| 2248 | qmin_ctrl.SetBackgroundColour("pink") |
---|
| 2249 | qmin_ctrl.Refresh() |
---|
| 2250 | qmax_ctrl.SetBackgroundColour("pink") |
---|
| 2251 | qmax_ctrl.Refresh() |
---|
[ef26c83] | 2252 | msg = "Invalid Q range: Q min must be smaller than Q max" |
---|
| 2253 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
[85b3971] | 2254 | return False |
---|
| 2255 | return True |
---|
[51a71a3] | 2256 | |
---|
[ef26c83] | 2257 | def _validate_Npts(self): |
---|
[51a71a3] | 2258 | """ |
---|
[5062bbf] | 2259 | Validate the number of points for fitting is more than 10 points. |
---|
| 2260 | If valid, setvalues Npts_fit otherwise post msg. |
---|
[51a71a3] | 2261 | """ |
---|
| 2262 | #default flag |
---|
| 2263 | flag = True |
---|
[1a74523] | 2264 | # Theory |
---|
| 2265 | if self.data == None and self.enable2D: |
---|
| 2266 | return flag |
---|
[166f2f8] | 2267 | for data in self.data_list: |
---|
| 2268 | # q value from qx and qy |
---|
[ef26c83] | 2269 | radius = numpy.sqrt(data.qx_data * data.qx_data + |
---|
| 2270 | data.qy_data * data.qy_data) |
---|
[166f2f8] | 2271 | #get unmasked index |
---|
| 2272 | index_data = (float(self.qmin.GetValue()) <= radius) & \ |
---|
| 2273 | (radius <= float(self.qmax.GetValue())) |
---|
[ef26c83] | 2274 | index_data = (index_data) & (data.mask) |
---|
[166f2f8] | 2275 | index_data = (index_data) & (numpy.isfinite(data.data)) |
---|
[7609f1a] | 2276 | |
---|
[166f2f8] | 2277 | if len(index_data[index_data]) < 10: |
---|
| 2278 | # change the color pink. |
---|
| 2279 | self.qmin.SetBackgroundColour("pink") |
---|
| 2280 | self.qmin.Refresh() |
---|
| 2281 | self.qmax.SetBackgroundColour("pink") |
---|
| 2282 | self.qmax.Refresh() |
---|
[ef26c83] | 2283 | msg = "Npts of Data Error :No or too little npts of %s." % data.name |
---|
| 2284 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
[166f2f8] | 2285 | self.fitrange = False |
---|
| 2286 | flag = False |
---|
| 2287 | else: |
---|
[ef26c83] | 2288 | self.Npts_fit.SetValue(str(len(index_data[index_data == True]))) |
---|
[166f2f8] | 2289 | self.fitrange = True |
---|
[51a71a3] | 2290 | |
---|
| 2291 | return flag |
---|
[94078a8] | 2292 | |
---|
[ef26c83] | 2293 | def _validate_Npts_1D(self): |
---|
[94078a8] | 2294 | """ |
---|
| 2295 | Validate the number of points for fitting is more than 5 points. |
---|
| 2296 | If valid, setvalues Npts_fit otherwise post msg. |
---|
| 2297 | """ |
---|
| 2298 | #default flag |
---|
| 2299 | flag = True |
---|
| 2300 | # Theory |
---|
| 2301 | if self.data == None: |
---|
| 2302 | return flag |
---|
| 2303 | for data in self.data_list: |
---|
| 2304 | # q value from qx and qy |
---|
[ef26c83] | 2305 | radius = data.x |
---|
[94078a8] | 2306 | #get unmasked index |
---|
| 2307 | index_data = (float(self.qmin.GetValue()) <= radius) & \ |
---|
| 2308 | (radius <= float(self.qmax.GetValue())) |
---|
| 2309 | index_data = (index_data) & (numpy.isfinite(data.y)) |
---|
| 2310 | |
---|
| 2311 | if len(index_data[index_data]) < 5: |
---|
| 2312 | # change the color pink. |
---|
| 2313 | self.qmin.SetBackgroundColour("pink") |
---|
| 2314 | self.qmin.Refresh() |
---|
| 2315 | self.qmax.SetBackgroundColour("pink") |
---|
| 2316 | self.qmax.Refresh() |
---|
[ef26c83] | 2317 | msg = "Npts of Data Error :No or too little npts of %s." % data.name |
---|
| 2318 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
[94078a8] | 2319 | self.fitrange = False |
---|
| 2320 | flag = False |
---|
| 2321 | else: |
---|
[ef26c83] | 2322 | self.Npts_fit.SetValue(str(len(index_data[index_data == True]))) |
---|
[94078a8] | 2323 | self.fitrange = True |
---|
| 2324 | |
---|
| 2325 | return flag |
---|
[51a71a3] | 2326 | |
---|
[c77d859] | 2327 | def _check_value_enter(self, list, modified): |
---|
| 2328 | """ |
---|
[5062bbf] | 2329 | :param list: model parameter and panel info |
---|
| 2330 | :Note: each item of the list should be as follow: |
---|
| 2331 | item=[check button state, parameter's name, |
---|
[ef26c83] | 2332 | paramater's value, string="+/-", |
---|
| 2333 | parameter's error of fit, |
---|
| 2334 | parameter's minimum value, |
---|
| 2335 | parrameter's maximum value , |
---|
[5062bbf] | 2336 | parameter's units] |
---|
[ef26c83] | 2337 | """ |
---|
| 2338 | is_modified = modified |
---|
| 2339 | if len(list) == 0: |
---|
[c99a6c5] | 2340 | return is_modified |
---|
[c77d859] | 2341 | for item in list: |
---|
[edd166b] | 2342 | #skip angle parameters for 1D |
---|
[ef26c83] | 2343 | if not self.enable2D: |
---|
[edd166b] | 2344 | if item in self.orientation_params: |
---|
| 2345 | continue |
---|
| 2346 | #try: |
---|
| 2347 | name = str(item[1]) |
---|
| 2348 | |
---|
[ef26c83] | 2349 | if string.find(name, ".npts") == -1 and \ |
---|
| 2350 | string.find(name, ".nsigmas") == -1: |
---|
| 2351 | ## check model parameters range |
---|
| 2352 | param_min = None |
---|
| 2353 | param_max = None |
---|
[7975f2b] | 2354 | |
---|
[c985bef] | 2355 | ## check minimun value |
---|
[ef26c83] | 2356 | if item[5] != None and item[5] != "": |
---|
| 2357 | if item[5].GetValue().lstrip().rstrip() != "": |
---|
[edd166b] | 2358 | try: |
---|
| 2359 | param_min = float(item[5].GetValue()) |
---|
[ef26c83] | 2360 | if not self._validate_qrange(item[5], item[2]): |
---|
[7975f2b] | 2361 | if numpy.isfinite(param_min): |
---|
| 2362 | item[2].SetValue(format_number(param_min)) |
---|
[6e9976b] | 2363 | |
---|
| 2364 | item[5].SetBackgroundColour(wx.WHITE) |
---|
| 2365 | item[2].SetBackgroundColour(wx.WHITE) |
---|
| 2366 | |
---|
[edd166b] | 2367 | except: |
---|
| 2368 | msg = "Wrong Fit parameter range entered " |
---|
[ef26c83] | 2369 | wx.PostEvent(self.parent.parent, |
---|
| 2370 | StatusEvent(status=msg)) |
---|
[edd166b] | 2371 | raise ValueError, msg |
---|
[c985bef] | 2372 | is_modified = True |
---|
[77e23a2] | 2373 | ## check maximum value |
---|
[ef26c83] | 2374 | if item[6] != None and item[6] != "": |
---|
| 2375 | if item[6].GetValue().lstrip().rstrip() != "": |
---|
| 2376 | try: |
---|
[edd166b] | 2377 | param_max = float(item[6].GetValue()) |
---|
[ef26c83] | 2378 | if not self._validate_qrange(item[2], item[6]): |
---|
[7975f2b] | 2379 | if numpy.isfinite(param_max): |
---|
[ef26c83] | 2380 | item[2].SetValue(format_number(param_max)) |
---|
[6e9976b] | 2381 | |
---|
| 2382 | item[6].SetBackgroundColour(wx.WHITE) |
---|
| 2383 | item[2].SetBackgroundColour(wx.WHITE) |
---|
[edd166b] | 2384 | except: |
---|
| 2385 | msg = "Wrong Fit parameter range entered " |
---|
[ef26c83] | 2386 | wx.PostEvent(self.parent.parent, |
---|
| 2387 | StatusEvent(status=msg)) |
---|
[edd166b] | 2388 | raise ValueError, msg |
---|
[c985bef] | 2389 | is_modified = True |
---|
[7975f2b] | 2390 | |
---|
[ef26c83] | 2391 | if param_min != None and param_max != None: |
---|
[85b3971] | 2392 | if not self._validate_qrange(item[5], item[6]): |
---|
[ef26c83] | 2393 | msg = "Wrong Fit range entered for parameter " |
---|
| 2394 | msg += "name %s of model %s " % (name, self.model.name) |
---|
| 2395 | wx.PostEvent(self.parent.parent, |
---|
| 2396 | StatusEvent(status=msg)) |
---|
[7975f2b] | 2397 | |
---|
[ef26c83] | 2398 | if name in self.model.details.keys(): |
---|
[2296316] | 2399 | self.model.details[name][1:3] = param_min, param_max |
---|
[edd166b] | 2400 | is_modified = True |
---|
| 2401 | else: |
---|
[ef26c83] | 2402 | self.model.details[name] = ["", param_min, param_max] |
---|
[7975f2b] | 2403 | is_modified = True |
---|
[ef26c83] | 2404 | try: |
---|
[2296316] | 2405 | # Check if the textctr is enabled |
---|
| 2406 | if item[2].IsEnabled(): |
---|
[ef26c83] | 2407 | value = float(item[2].GetValue()) |
---|
[2296316] | 2408 | item[2].SetBackgroundColour("white") |
---|
| 2409 | # If the value of the parameter has changed, |
---|
| 2410 | # +update the model and set the is_modified flag |
---|
| 2411 | if value != self.model.getParam(name) and \ |
---|
| 2412 | numpy.isfinite(value): |
---|
| 2413 | self.model.setParam(name, value) |
---|
[6e9976b] | 2414 | except: |
---|
[7987962] | 2415 | item[2].SetBackgroundColour("pink") |
---|
[6e9976b] | 2416 | msg = "Wrong Fit parameter value entered " |
---|
[ef26c83] | 2417 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
[7975f2b] | 2418 | |
---|
[ef26c83] | 2419 | return is_modified |
---|
[c77d859] | 2420 | |
---|
| 2421 | def _set_dipers_Param(self, event): |
---|
| 2422 | """ |
---|
[5062bbf] | 2423 | respond to self.enable_disp and self.disable_disp radio box. |
---|
[ef26c83] | 2424 | The dispersity object is reset inside the model into Gaussian. |
---|
| 2425 | When the user select yes , this method display a combo box for |
---|
| 2426 | more selection when the user selects No,the combo box disappears. |
---|
[5062bbf] | 2427 | Redraw the model with the default dispersity (Gaussian) |
---|
[c77d859] | 2428 | """ |
---|
[4470b10] | 2429 | ## On selction if no model exists. |
---|
[ef26c83] | 2430 | if self.model == None: |
---|
[4470b10] | 2431 | self.disable_disp.SetValue(True) |
---|
[ef26c83] | 2432 | msg = "Please select a Model first..." |
---|
[4470b10] | 2433 | wx.MessageBox(msg, 'Info') |
---|
[ef26c83] | 2434 | wx.PostEvent(self._manager.parent, |
---|
| 2435 | StatusEvent(status="Polydispersion: %s" % msg)) |
---|
[4470b10] | 2436 | return |
---|
| 2437 | |
---|
[1c1436d] | 2438 | self._reset_dispersity() |
---|
[1467e1a6] | 2439 | |
---|
[ef26c83] | 2440 | if self.model == None: |
---|
[70c57ebf] | 2441 | self.model_disp.Hide() |
---|
| 2442 | self.sizer4_4.Clear(True) |
---|
| 2443 | return |
---|
[b421b1a] | 2444 | |
---|
[1c1436d] | 2445 | if self.enable_disp.GetValue(): |
---|
| 2446 | ## layout for model containing no dispersity parameters |
---|
[f20767b] | 2447 | |
---|
[ef26c83] | 2448 | self.disp_list = self.model.getDispParamList() |
---|
[f20767b] | 2449 | |
---|
[ef26c83] | 2450 | if len(self.disp_list) == 0 and len(self.disp_cb_dict) == 0: |
---|
| 2451 | self._layout_sizer_noDipers() |
---|
[c77d859] | 2452 | else: |
---|
[ef26c83] | 2453 | ## set gaussian sizer |
---|
[1c1436d] | 2454 | self._on_select_Disp(event=None) |
---|
| 2455 | else: |
---|
| 2456 | self.sizer4_4.Clear(True) |
---|
[f20767b] | 2457 | |
---|
[ef26c83] | 2458 | ## post state to fit panel |
---|
[1c1436d] | 2459 | self.save_current_state() |
---|
[ef26c83] | 2460 | if event != None: |
---|
| 2461 | event = PageInfoEvent(page=self) |
---|
[240b9966] | 2462 | wx.PostEvent(self.parent, event) |
---|
[1467e1a6] | 2463 | #draw the model with the current dispersity |
---|
[f20767b] | 2464 | self._draw_model() |
---|
[f1aa385] | 2465 | self.sizer4_4.Layout() |
---|
| 2466 | self.sizer5.Layout() |
---|
[71f0373] | 2467 | self.Layout() |
---|
[ef26c83] | 2468 | self.Refresh() |
---|
[3b605bb] | 2469 | |
---|
[c77d859] | 2470 | def _layout_sizer_noDipers(self): |
---|
| 2471 | """ |
---|
[5062bbf] | 2472 | Draw a sizer with no dispersity info |
---|
[c77d859] | 2473 | """ |
---|
[ef26c83] | 2474 | ix = 0 |
---|
| 2475 | iy = 1 |
---|
| 2476 | self.fittable_param = [] |
---|
| 2477 | self.fixed_param = [] |
---|
| 2478 | self.orientation_params_disp = [] |
---|
[1c1436d] | 2479 | |
---|
[c77d859] | 2480 | self.sizer4_4.Clear(True) |
---|
[01b6bd0] | 2481 | text = "No polydispersity available for this model" |
---|
| 2482 | model_disp = wx.StaticText(self, -1, text) |
---|
[ef26c83] | 2483 | self.sizer4_4.Add(model_disp, (iy, ix), (1, 1), |
---|
| 2484 | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) |
---|
[dcf29d7] | 2485 | self.sizer4_4.Layout() |
---|
[c77d859] | 2486 | self.sizer4.Layout() |
---|
[340c2b3] | 2487 | |
---|
[c77d859] | 2488 | def _reset_dispersity(self): |
---|
| 2489 | """ |
---|
[5062bbf] | 2490 | put gaussian dispersity into current model |
---|
[c77d859] | 2491 | """ |
---|
[ef26c83] | 2492 | if len(self.param_toFit) > 0: |
---|
[1c1436d] | 2493 | for item in self.fittable_param: |
---|
[513115c] | 2494 | if item in self.param_toFit: |
---|
[1c1436d] | 2495 | self.param_toFit.remove(item) |
---|
[edd166b] | 2496 | |
---|
[1c1436d] | 2497 | for item in self.orientation_params_disp: |
---|
[513115c] | 2498 | if item in self.param_toFit: |
---|
[1c1436d] | 2499 | self.param_toFit.remove(item) |
---|
[513115c] | 2500 | |
---|
[ef26c83] | 2501 | self.fittable_param = [] |
---|
| 2502 | self.fixed_param = [] |
---|
| 2503 | self.orientation_params_disp = [] |
---|
| 2504 | self.values = {} |
---|
| 2505 | self.weights = {} |
---|
[f20767b] | 2506 | |
---|
[ef26c83] | 2507 | from sans.models.dispersion_models import GaussianDispersion |
---|
| 2508 | if len(self.disp_cb_dict) == 0: |
---|
[e2f7b92] | 2509 | self.save_current_state() |
---|
[3b605bb] | 2510 | self.sizer4_4.Clear(True) |
---|
| 2511 | self.Layout() |
---|
[ef26c83] | 2512 | return |
---|
| 2513 | if (len(self.disp_cb_dict) > 0): |
---|
[f20767b] | 2514 | for p in self.disp_cb_dict: |
---|
[ef26c83] | 2515 | # The parameter was un-selected. |
---|
| 2516 | # Go back to Gaussian model (with 0 pts) |
---|
[f20767b] | 2517 | disp_model = GaussianDispersion() |
---|
| 2518 | |
---|
[ff8f99b] | 2519 | self._disp_obj_dict[p] = disp_model |
---|
[ef26c83] | 2520 | # Set the new model as the dispersion object |
---|
| 2521 | # for the selected parameter |
---|
[f20767b] | 2522 | try: |
---|
[ef26c83] | 2523 | self.model.set_dispersion(p, disp_model) |
---|
[f20767b] | 2524 | except: |
---|
[c985bef] | 2525 | |
---|
[f20767b] | 2526 | pass |
---|
[7975f2b] | 2527 | |
---|
[240b9966] | 2528 | ## save state into |
---|
| 2529 | self.save_current_state() |
---|
[ef26c83] | 2530 | self.Layout() |
---|
[c985bef] | 2531 | self.Refresh() |
---|
[7975f2b] | 2532 | |
---|
[ef26c83] | 2533 | def _on_select_Disp(self, event): |
---|
[c77d859] | 2534 | """ |
---|
[5062bbf] | 2535 | allow selecting different dispersion |
---|
| 2536 | self.disp_list should change type later .now only gaussian |
---|
[c77d859] | 2537 | """ |
---|
[2296316] | 2538 | self._set_sizer_dispersion() |
---|
| 2539 | |
---|
[6e9150d] | 2540 | ## Redraw the model |
---|
[ef26c83] | 2541 | self._draw_model() |
---|
[3a37fe0] | 2542 | #self._undo.Enable(True) |
---|
[ef26c83] | 2543 | event = PageInfoEvent(page=self) |
---|
[3b9e023] | 2544 | wx.PostEvent(self.parent, event) |
---|
| 2545 | |
---|
[7975f2b] | 2546 | self.sizer4_4.Layout() |
---|
| 2547 | self.sizer4.Layout() |
---|
[36cb4d2f] | 2548 | self.SetupScrolling() |
---|
[340c2b3] | 2549 | |
---|
[ef26c83] | 2550 | def _on_disp_func(self, event=None): |
---|
[c77d859] | 2551 | """ |
---|
[2296316] | 2552 | Select a distribution function for the polydispersion |
---|
[f20767b] | 2553 | |
---|
[ef26c83] | 2554 | :Param event: ComboBox event |
---|
[2296316] | 2555 | """ |
---|
| 2556 | # get ready for new event |
---|
| 2557 | if event != None: |
---|
| 2558 | event.Skip() |
---|
| 2559 | # Get event object |
---|
[ef26c83] | 2560 | disp_box = event.GetEventObject() |
---|
[2296316] | 2561 | |
---|
| 2562 | # Try to select a Distr. function |
---|
[ef26c83] | 2563 | try: |
---|
[2296316] | 2564 | disp_box.SetBackgroundColour("white") |
---|
| 2565 | selection = disp_box.GetCurrentSelection() |
---|
| 2566 | param_name = disp_box.Name.split('.')[0] |
---|
| 2567 | disp_name = disp_box.GetValue() |
---|
[ef26c83] | 2568 | dispersity = disp_box.GetClientData(selection) |
---|
[2296316] | 2569 | |
---|
| 2570 | #disp_model = GaussianDispersion() |
---|
| 2571 | disp_model = dispersity() |
---|
| 2572 | # Get param names to reset the values of the param |
---|
| 2573 | name1 = param_name + ".width" |
---|
| 2574 | name2 = param_name + ".npts" |
---|
| 2575 | name3 = param_name + ".nsigmas" |
---|
| 2576 | # Check Disp. function whether or not it is 'array' |
---|
| 2577 | if disp_name.lower() == "array": |
---|
[ef26c83] | 2578 | value2 = "" |
---|
| 2579 | value3 = "" |
---|
[2296316] | 2580 | value1 = self._set_array_disp(name=name1, disp=disp_model) |
---|
| 2581 | else: |
---|
| 2582 | self._del_array_values(name1) |
---|
| 2583 | #self._reset_array_disp(param_name) |
---|
| 2584 | self._disp_obj_dict[name1] = disp_model |
---|
| 2585 | self.model.set_dispersion(param_name, disp_model) |
---|
[ef26c83] | 2586 | self.state._disp_obj_dict[name1] = disp_model |
---|
[2296316] | 2587 | |
---|
[ef26c83] | 2588 | value1 = str(format_number(self.model.getParam(name1), True)) |
---|
| 2589 | value2 = str(format_number(self.model.getParam(name2))) |
---|
| 2590 | value3 = str(format_number(self.model.getParam(name3))) |
---|
[2296316] | 2591 | # Reset fittable polydispersin parameter value |
---|
[513115c] | 2592 | for item in self.fittable_param: |
---|
[ef26c83] | 2593 | if item[1] == name1: |
---|
| 2594 | item[2].SetValue(value1) |
---|
[2296316] | 2595 | item[5].SetValue("") |
---|
| 2596 | item[6].SetValue("") |
---|
| 2597 | # Disable for array |
---|
| 2598 | if disp_name.lower() == "array": |
---|
| 2599 | item[0].SetValue(False) |
---|
| 2600 | item[0].Disable() |
---|
| 2601 | item[2].Disable() |
---|
[ace0e33] | 2602 | item[3].Show(False) |
---|
| 2603 | item[4].Show(False) |
---|
[2296316] | 2604 | item[5].Disable() |
---|
| 2605 | item[6].Disable() |
---|
| 2606 | else: |
---|
| 2607 | item[0].Enable() |
---|
| 2608 | item[2].Enable() |
---|
| 2609 | item[5].Enable() |
---|
[ef26c83] | 2610 | item[6].Enable() |
---|
[2296316] | 2611 | break |
---|
| 2612 | # Reset fixed polydispersion params |
---|
| 2613 | for item in self.fixed_param: |
---|
| 2614 | if item[1] == name2: |
---|
| 2615 | item[2].SetValue(value2) |
---|
| 2616 | # Disable Npts for array |
---|
| 2617 | if disp_name.lower() == "array": |
---|
| 2618 | item[2].Disable() |
---|
| 2619 | else: |
---|
| 2620 | item[2].Enable() |
---|
| 2621 | if item[1] == name3: |
---|
[ef26c83] | 2622 | item[2].SetValue(value3) |
---|
[2296316] | 2623 | # Disable Nsigs for array |
---|
| 2624 | if disp_name.lower() == "array": |
---|
| 2625 | item[2].Disable() |
---|
| 2626 | else: |
---|
| 2627 | item[2].Enable() |
---|
| 2628 | |
---|
| 2629 | # Make sure the check box updated when all checked |
---|
| 2630 | if self.cb1.GetValue(): |
---|
[fc1761b] | 2631 | #self.select_all_param(None) |
---|
| 2632 | self.get_all_checked_params() |
---|
[2296316] | 2633 | |
---|
| 2634 | # update params |
---|
[ef26c83] | 2635 | self._update_paramv_on_fit() |
---|
[2296316] | 2636 | # draw |
---|
| 2637 | self._draw_model() |
---|
| 2638 | self.Refresh() |
---|
| 2639 | except: |
---|
| 2640 | # Error msg |
---|
| 2641 | msg = "Error occurred:" |
---|
| 2642 | msg += " Could not select the distribution function..." |
---|
| 2643 | msg += " Please select another distribution function." |
---|
| 2644 | disp_box.SetBackgroundColour("pink") |
---|
| 2645 | # Focus on Fit button so that users can see the pinky box |
---|
| 2646 | self.btFit.SetFocus() |
---|
[ef26c83] | 2647 | wx.PostEvent(self.parent.parent, |
---|
[2296316] | 2648 | StatusEvent(status=msg, info="error")) |
---|
| 2649 | |
---|
| 2650 | def _set_array_disp(self, name=None, disp=None): |
---|
| 2651 | """ |
---|
| 2652 | Set array dispersion |
---|
| 2653 | |
---|
| 2654 | :param name: name of the parameter for the dispersion to be set |
---|
| 2655 | :param disp: the polydisperion object |
---|
| 2656 | """ |
---|
[ef26c83] | 2657 | # The user wants this parameter to be averaged. |
---|
[2296316] | 2658 | # Pop up the file selection dialog. |
---|
| 2659 | path = self._selectDlg() |
---|
| 2660 | # Array data |
---|
| 2661 | values = [] |
---|
| 2662 | weights = [] |
---|
| 2663 | # If nothing was selected, just return |
---|
| 2664 | if path is None: |
---|
| 2665 | self.disp_cb_dict[name].SetValue(False) |
---|
| 2666 | #self.noDisper_rbox.SetValue(True) |
---|
| 2667 | return |
---|
| 2668 | self._default_save_location = os.path.dirname(path) |
---|
[baf1ef3] | 2669 | if self.parent != None: |
---|
| 2670 | self.parent.parent._default_save_location =\ |
---|
| 2671 | self._default_save_location |
---|
[f20767b] | 2672 | |
---|
[ef26c83] | 2673 | basename = os.path.basename(path) |
---|
| 2674 | values, weights = self.read_file(path) |
---|
[3b9e023] | 2675 | |
---|
[2296316] | 2676 | # If any of the two arrays is empty, notify the user that we won't |
---|
| 2677 | # proceed |
---|
[ef26c83] | 2678 | if len(self.param_toFit) > 0: |
---|
[2296316] | 2679 | if name in self.param_toFit: |
---|
| 2680 | self.param_toFit.remove(name) |
---|
| 2681 | |
---|
| 2682 | # Tell the user that we are about to apply the distribution |
---|
| 2683 | msg = "Applying loaded %s distribution: %s" % (name, path) |
---|
[ef26c83] | 2684 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
[6b39d58] | 2685 | self._set_array_disp_model(name=name, disp=disp, |
---|
| 2686 | values=values, weights=weights) |
---|
| 2687 | return basename |
---|
| 2688 | |
---|
[ef26c83] | 2689 | def _set_array_disp_model(self, name=None, disp=None, |
---|
[6b39d58] | 2690 | values=[], weights=[]): |
---|
| 2691 | """ |
---|
| 2692 | Set array dispersion model |
---|
| 2693 | |
---|
| 2694 | :param name: name of the parameter for the dispersion to be set |
---|
| 2695 | :param disp: the polydisperion object |
---|
| 2696 | """ |
---|
[2296316] | 2697 | disp.set_weights(values, weights) |
---|
| 2698 | self._disp_obj_dict[name] = disp |
---|
| 2699 | self.model.set_dispersion(name.split('.')[0], disp) |
---|
[ef26c83] | 2700 | self.state._disp_obj_dict[name] = disp |
---|
[2296316] | 2701 | self.values[name] = values |
---|
| 2702 | self.weights[name] = weights |
---|
| 2703 | # Store the object to make it persist outside the |
---|
| 2704 | # scope of this method |
---|
| 2705 | #TODO: refactor model to clean this up? |
---|
| 2706 | self.state.values = {} |
---|
| 2707 | self.state.weights = {} |
---|
| 2708 | self.state.values = copy.deepcopy(self.values) |
---|
| 2709 | self.state.weights = copy.deepcopy(self.weights) |
---|
| 2710 | |
---|
[ef26c83] | 2711 | # Set the new model as the dispersion object for the |
---|
[2296316] | 2712 | #selected parameter |
---|
| 2713 | #self.model.set_dispersion(p, disp_model) |
---|
[ef26c83] | 2714 | # Store a reference to the weights in the model object |
---|
[2296316] | 2715 | #so that |
---|
| 2716 | # it's not lost when we use the model within another thread. |
---|
| 2717 | #TODO: total hack - fix this |
---|
[ef26c83] | 2718 | self.state.model = self.model.clone() |
---|
[2296316] | 2719 | self.model._persistency_dict[name.split('.')[0]] = \ |
---|
| 2720 | [values, weights] |
---|
| 2721 | self.state.model._persistency_dict[name.split('.')[0]] = \ |
---|
[ef26c83] | 2722 | [values, weights] |
---|
[6b39d58] | 2723 | |
---|
[ef26c83] | 2724 | def _del_array_values(self, name=None): |
---|
[2296316] | 2725 | """ |
---|
| 2726 | Reset array dispersion |
---|
[f20767b] | 2727 | |
---|
[ef26c83] | 2728 | :param name: name of the parameter for the dispersion to be set |
---|
[2296316] | 2729 | """ |
---|
| 2730 | # Try to delete values and weight of the names array dic if exists |
---|
| 2731 | try: |
---|
| 2732 | del self.values[name] |
---|
| 2733 | del self.weights[name] |
---|
| 2734 | # delete all other dic |
---|
| 2735 | del self.state.values[name] |
---|
| 2736 | del self.state.weights[name] |
---|
[ef26c83] | 2737 | del self.model._persistency_dict[name.split('.')[0]] |
---|
[2296316] | 2738 | del self.state.model._persistency_dict[name.split('.')[0]] |
---|
| 2739 | except: |
---|
| 2740 | pass |
---|
| 2741 | |
---|
[7975f2b] | 2742 | def _lay_out(self): |
---|
| 2743 | """ |
---|
[5062bbf] | 2744 | returns self.Layout |
---|
| 2745 | |
---|
| 2746 | :Note: Mac seems to like this better when self. |
---|
| 2747 | Layout is called after fitting. |
---|
[7975f2b] | 2748 | """ |
---|
| 2749 | self._sleep4sec() |
---|
| 2750 | self.Layout() |
---|
[ef26c83] | 2751 | return |
---|
[7975f2b] | 2752 | |
---|
| 2753 | def _sleep4sec(self): |
---|
| 2754 | """ |
---|
[12eac73] | 2755 | sleep for 1 sec only applied on Mac |
---|
[ef26c83] | 2756 | Note: This 1sec helps for Mac not to crash on self. |
---|
| 2757 | Layout after self._draw_model |
---|
[7975f2b] | 2758 | """ |
---|
| 2759 | if ON_MAC == True: |
---|
[12eac73] | 2760 | time.sleep(1) |
---|
[f72333f] | 2761 | |
---|
[ef26c83] | 2762 | def _find_polyfunc_selection(self, disp_func=None): |
---|
[2296316] | 2763 | """ |
---|
[ef26c83] | 2764 | FInd Comboox selection from disp_func |
---|
[2296316] | 2765 | |
---|
| 2766 | :param disp_function: dispersion distr. function |
---|
| 2767 | """ |
---|
| 2768 | # List of the poly_model name in the combobox |
---|
[ef26c83] | 2769 | list = ["RectangleDispersion", "ArrayDispersion", |
---|
| 2770 | "LogNormalDispersion", "GaussianDispersion", |
---|
| 2771 | "SchulzDispersion"] |
---|
[2296316] | 2772 | |
---|
| 2773 | # Find the selection |
---|
| 2774 | try: |
---|
| 2775 | selection = list.index(disp_func.__class__.__name__) |
---|
| 2776 | return selection |
---|
| 2777 | except: |
---|
[ef26c83] | 2778 | return 3 |
---|
[2296316] | 2779 | |
---|
[ef26c83] | 2780 | def on_reset_clicked(self, event): |
---|
[904168e1] | 2781 | """ |
---|
[5062bbf] | 2782 | On 'Reset' button for Q range clicked |
---|
[904168e1] | 2783 | """ |
---|
[7609f1a] | 2784 | flag = True |
---|
[904168e1] | 2785 | ##For 3 different cases: Data2D, Data1D, and theory |
---|
[06aa2eeb] | 2786 | if self.model == None: |
---|
[ef26c83] | 2787 | msg = "Please select a model first..." |
---|
[06aa2eeb] | 2788 | wx.MessageBox(msg, 'Info') |
---|
| 2789 | flag = False |
---|
| 2790 | return |
---|
| 2791 | |
---|
| 2792 | elif self.data.__class__.__name__ == "Data2D": |
---|
[ef26c83] | 2793 | data_min = 0 |
---|
| 2794 | x = max(math.fabs(self.data.xmin), math.fabs(self.data.xmax)) |
---|
| 2795 | y = max(math.fabs(self.data.ymin), math.fabs(self.data.ymax)) |
---|
[904168e1] | 2796 | self.qmin_x = data_min |
---|
| 2797 | self.qmax_x = math.sqrt(x*x + y*y) |
---|
[3b70cc7] | 2798 | #self.data.mask = numpy.ones(len(self.data.data),dtype=bool) |
---|
[f72333f] | 2799 | # check smearing |
---|
| 2800 | if not self.disable_smearer.GetValue(): |
---|
[ef26c83] | 2801 | ## set smearing value whether or |
---|
| 2802 | # not the data contain the smearing info |
---|
[f72333f] | 2803 | if self.pinhole_smearer.GetValue(): |
---|
| 2804 | flag = self.update_pinhole_smear() |
---|
| 2805 | else: |
---|
| 2806 | flag = True |
---|
[06aa2eeb] | 2807 | |
---|
| 2808 | elif self.data == None: |
---|
| 2809 | self.qmin_x = _QMIN_DEFAULT |
---|
| 2810 | self.qmax_x = _QMAX_DEFAULT |
---|
[ef26c83] | 2811 | self.num_points = _NPTS_DEFAULT |
---|
[06aa2eeb] | 2812 | self.state.npts = self.num_points |
---|
| 2813 | |
---|
[6318298] | 2814 | elif self.data.__class__.__name__ != "Data2D": |
---|
[904168e1] | 2815 | self.qmin_x = min(self.data.x) |
---|
| 2816 | self.qmax_x = max(self.data.x) |
---|
[7609f1a] | 2817 | # check smearing |
---|
| 2818 | if not self.disable_smearer.GetValue(): |
---|
[ef26c83] | 2819 | ## set smearing value whether or |
---|
| 2820 | # not the data contain the smearing info |
---|
[7609f1a] | 2821 | if self.slit_smearer.GetValue(): |
---|
| 2822 | flag = self.update_slit_smear() |
---|
| 2823 | elif self.pinhole_smearer.GetValue(): |
---|
| 2824 | flag = self.update_pinhole_smear() |
---|
| 2825 | else: |
---|
| 2826 | flag = True |
---|
[904168e1] | 2827 | else: |
---|
[06aa2eeb] | 2828 | flag = False |
---|
[7975f2b] | 2829 | |
---|
[7609f1a] | 2830 | if flag == False: |
---|
[ef26c83] | 2831 | msg = "Cannot Plot :Must enter a number!!! " |
---|
| 2832 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
[51a71a3] | 2833 | else: |
---|
| 2834 | # set relative text ctrs. |
---|
[f95301b] | 2835 | self.qmin.SetValue(str(self.qmin_x)) |
---|
[51a71a3] | 2836 | self.qmax.SetValue(str(self.qmax_x)) |
---|
| 2837 | self.set_npts2fit() |
---|
[ef26c83] | 2838 | # At this point, some button and variables satatus (disabled?) |
---|
| 2839 | # should be checked such as color that should be reset to |
---|
| 2840 | # white in case that it was pink. |
---|
[51a71a3] | 2841 | self._onparamEnter_helper() |
---|
| 2842 | |
---|
[7609f1a] | 2843 | self.save_current_state() |
---|
[904168e1] | 2844 | self.state.qmin = self.qmin_x |
---|
| 2845 | self.state.qmax = self.qmax_x |
---|
[00c3aac] | 2846 | |
---|
[904168e1] | 2847 | #reset the q range values |
---|
| 2848 | self._reset_plotting_range(self.state) |
---|
| 2849 | self._draw_model() |
---|
[2296316] | 2850 | |
---|
| 2851 | def get_images(self): |
---|
| 2852 | """ |
---|
| 2853 | Get the images of the plots corresponding this panel for report |
---|
| 2854 | |
---|
| 2855 | : return graphs: list of figures |
---|
| 2856 | : TODO: Move to guiframe |
---|
| 2857 | """ |
---|
| 2858 | # set list of graphs |
---|
| 2859 | graphs = [] |
---|
| 2860 | canvases = [] |
---|
| 2861 | # call gui_manager |
---|
| 2862 | gui_manager = self.parent.parent |
---|
| 2863 | # loops through the panels [dic] |
---|
[c572e5e] | 2864 | for item1, item2 in gui_manager.plot_panels.iteritems(): |
---|
[ef26c83] | 2865 | data_title = self.data.group_id |
---|
[2296316] | 2866 | # try to get all plots belonging to this control panel |
---|
[ef26c83] | 2867 | try: |
---|
| 2868 | if item2.group_id == data_title or \ |
---|
[e89c135] | 2869 | item2.group_id.count("res" + str(self.graph_id)) or \ |
---|
[8e671c39] | 2870 | item2.group_id.count(str(self.uid)) > 0: |
---|
[ef26c83] | 2871 | # append to the list |
---|
| 2872 | graphs.append(item2.figure) |
---|
| 2873 | canvases.append(item2.canvas) |
---|
| 2874 | except: |
---|
| 2875 | # Not for control panels |
---|
| 2876 | pass |
---|
[2296316] | 2877 | # return the list of graphs |
---|
| 2878 | return graphs, canvases |
---|
[904168e1] | 2879 | |
---|
[ef26c83] | 2880 | def on_model_help_clicked(self, event): |
---|
[7ad6ff5] | 2881 | """ |
---|
[5062bbf] | 2882 | on 'More details' button |
---|
[7ad6ff5] | 2883 | """ |
---|
[484faf7] | 2884 | from help_panel import HelpWindow |
---|
[70b760da] | 2885 | from sans.models import get_data_path |
---|
[c77d859] | 2886 | |
---|
[2296316] | 2887 | # Get models help model_function path |
---|
[70b760da] | 2888 | path = get_data_path(media='media') |
---|
[ef26c83] | 2889 | model_path = os.path.join(path, "model_functions.html") |
---|
[7ad6ff5] | 2890 | if self.model == None: |
---|
| 2891 | name = 'FuncHelp' |
---|
| 2892 | else: |
---|
[500f9f2] | 2893 | name = self.formfactorbox.GetValue() |
---|
[ef26c83] | 2894 | frame = HelpWindow(None, -1, pageToOpen=model_path) |
---|
[19e614a] | 2895 | # If model name exists and model is not a custom model |
---|
| 2896 | if frame.rhelp.HasAnchor(name) and not self.plugin_rbutton.GetValue(): |
---|
[6f140f2] | 2897 | frame.Show(True) |
---|
[7ad6ff5] | 2898 | frame.rhelp.ScrollToAnchor(name) |
---|
| 2899 | else: |
---|
[ef26c83] | 2900 | if self.model != None: |
---|
| 2901 | frame.Destroy() |
---|
| 2902 | msg = 'Model description:\n' |
---|
| 2903 | if str(self.model.description).rstrip().lstrip() == '': |
---|
| 2904 | msg += "Sorry, no information is available for this model." |
---|
| 2905 | else: |
---|
| 2906 | msg += self.model.description + '\n' |
---|
| 2907 | info = "Info" |
---|
| 2908 | wx.MessageBox(msg, info) |
---|
| 2909 | else: |
---|
| 2910 | frame.Show(True) |
---|
[2296316] | 2911 | |
---|
| 2912 | def on_pd_help_clicked(self, event): |
---|
| 2913 | """ |
---|
| 2914 | Button event for PD help |
---|
| 2915 | """ |
---|
| 2916 | from help_panel import HelpWindow |
---|
[ef26c83] | 2917 | import sans.models as models |
---|
[2296316] | 2918 | |
---|
| 2919 | # Get models help model_function path |
---|
| 2920 | path = models.get_data_path(media='media') |
---|
[ef26c83] | 2921 | pd_path = os.path.join(path, "pd_help.html") |
---|
[2296316] | 2922 | |
---|
[ef26c83] | 2923 | frame = HelpWindow(None, -1, pageToOpen=pd_path) |
---|
[2296316] | 2924 | frame.Show(True) |
---|
| 2925 | |
---|
| 2926 | def on_left_down(self, event): |
---|
| 2927 | """ |
---|
| 2928 | Get key stroke event |
---|
| 2929 | """ |
---|
| 2930 | # Figuring out key combo: Cmd for copy, Alt for paste |
---|
| 2931 | if event.CmdDown() and event.ShiftDown(): |
---|
| 2932 | flag = self.get_paste() |
---|
| 2933 | elif event.CmdDown(): |
---|
| 2934 | flag = self.get_copy() |
---|
| 2935 | else: |
---|
| 2936 | event.Skip() |
---|
| 2937 | return |
---|
| 2938 | # make event free |
---|
| 2939 | event.Skip() |
---|
| 2940 | |
---|
[951a2f5] | 2941 | def get_copy(self): |
---|
| 2942 | """ |
---|
| 2943 | Get copy params to clipboard |
---|
| 2944 | """ |
---|
[ef26c83] | 2945 | content = self.get_copy_params() |
---|
[951a2f5] | 2946 | flag = self.set_clipboard(content) |
---|
[ef26c83] | 2947 | self._copy_info(flag) |
---|
| 2948 | return flag |
---|
[2296316] | 2949 | |
---|
[ef26c83] | 2950 | def get_copy_params(self): |
---|
[2296316] | 2951 | """ |
---|
| 2952 | Get the string copies of the param names and values in the tap |
---|
[ef26c83] | 2953 | """ |
---|
[2296316] | 2954 | content = 'sansview_parameter_values:' |
---|
[ef26c83] | 2955 | # Do it if params exist |
---|
| 2956 | if self.parameters != []: |
---|
[2296316] | 2957 | |
---|
[ef26c83] | 2958 | # go through the parameters |
---|
| 2959 | string = self._get_copy_helper(self.parameters, |
---|
[2296316] | 2960 | self.orientation_params) |
---|
| 2961 | content += string |
---|
| 2962 | |
---|
| 2963 | # go through the fittables |
---|
[ef26c83] | 2964 | string = self._get_copy_helper(self.fittable_param, |
---|
[2296316] | 2965 | self.orientation_params_disp) |
---|
| 2966 | content += string |
---|
| 2967 | |
---|
| 2968 | # go through the fixed params |
---|
[ef26c83] | 2969 | string = self._get_copy_helper(self.fixed_param, |
---|
[2296316] | 2970 | self.orientation_params_disp) |
---|
| 2971 | content += string |
---|
| 2972 | |
---|
| 2973 | # go through the str params |
---|
[ef26c83] | 2974 | string = self._get_copy_helper(self.str_parameters, |
---|
[2296316] | 2975 | self.orientation_params) |
---|
| 2976 | content += string |
---|
[951a2f5] | 2977 | return content |
---|
| 2978 | else: |
---|
| 2979 | return False |
---|
| 2980 | |
---|
[ef26c83] | 2981 | def set_clipboard(self, content=None): |
---|
[951a2f5] | 2982 | """ |
---|
| 2983 | Put the string to the clipboard |
---|
[ef26c83] | 2984 | """ |
---|
[951a2f5] | 2985 | if not content: |
---|
| 2986 | return False |
---|
[2296316] | 2987 | if wx.TheClipboard.Open(): |
---|
| 2988 | wx.TheClipboard.SetData(wx.TextDataObject(str(content))) |
---|
| 2989 | wx.TheClipboard.Close() |
---|
[951a2f5] | 2990 | return True |
---|
[2296316] | 2991 | return None |
---|
| 2992 | |
---|
| 2993 | def _get_copy_helper(self, param, orient_param): |
---|
| 2994 | """ |
---|
| 2995 | Helping get value and name of the params |
---|
| 2996 | |
---|
| 2997 | : param param: parameters |
---|
| 2998 | : param orient_param = oritational params |
---|
| 2999 | : return content: strings [list] [name,value:....] |
---|
| 3000 | """ |
---|
| 3001 | content = '' |
---|
| 3002 | # go through the str params |
---|
[ef26c83] | 3003 | for item in param: |
---|
[1ac202f] | 3004 | # copy only the params shown |
---|
| 3005 | if not item[2].IsShown(): |
---|
| 3006 | continue |
---|
[68a921f] | 3007 | disfunc = '' |
---|
| 3008 | try: |
---|
| 3009 | if item[7].__class__.__name__ == 'ComboBox': |
---|
[706667b] | 3010 | disfunc = str(item[7].GetValue()) |
---|
[68a921f] | 3011 | except: |
---|
| 3012 | pass |
---|
[706667b] | 3013 | |
---|
[2296316] | 3014 | # 2D |
---|
[25c0def] | 3015 | if self.data.__class__.__name__ == "Data2D": |
---|
[fc1761b] | 3016 | try: |
---|
| 3017 | check = item[0].GetValue() |
---|
| 3018 | except: |
---|
| 3019 | check = None |
---|
[2296316] | 3020 | name = item[1] |
---|
| 3021 | value = item[2].GetValue() |
---|
| 3022 | # 1D |
---|
| 3023 | else: |
---|
| 3024 | ## for 1D all parameters except orientation |
---|
| 3025 | if not item[1] in orient_param: |
---|
[fc1761b] | 3026 | try: |
---|
| 3027 | check = item[0].GetValue() |
---|
| 3028 | except: |
---|
| 3029 | check = None |
---|
[2296316] | 3030 | name = item[1] |
---|
| 3031 | value = item[2].GetValue() |
---|
[706667b] | 3032 | |
---|
[2296316] | 3033 | # add to the content |
---|
[68a921f] | 3034 | if disfunc != '': |
---|
[706667b] | 3035 | |
---|
[68a921f] | 3036 | disfunc = ',' + disfunc |
---|
[706667b] | 3037 | # TODO: to support array func for copy/paste |
---|
[ace0e33] | 3038 | try: |
---|
| 3039 | if disfunc.count('array') > 0: |
---|
| 3040 | disfunc += ',' |
---|
| 3041 | for val in self.values[name]: |
---|
| 3042 | disfunc += ' ' + str(val) |
---|
| 3043 | disfunc += ',' |
---|
| 3044 | for weight in self.weights[name]: |
---|
| 3045 | disfunc += ' ' + str(weight) |
---|
| 3046 | except: |
---|
| 3047 | pass |
---|
[ef26c83] | 3048 | content += name + ',' + str(check) + ',' + value + disfunc + ':' |
---|
[68a921f] | 3049 | |
---|
[2296316] | 3050 | return content |
---|
[951a2f5] | 3051 | |
---|
[ef26c83] | 3052 | def get_clipboard(self): |
---|
[951a2f5] | 3053 | """ |
---|
| 3054 | Get strings in the clipboard |
---|
| 3055 | """ |
---|
[ef26c83] | 3056 | text = "" |
---|
| 3057 | # Get text from the clip board |
---|
[951a2f5] | 3058 | if wx.TheClipboard.Open(): |
---|
[25c0def] | 3059 | if wx.TheClipboard.IsSupported(wx.DataFormat(wx.DF_TEXT)): |
---|
| 3060 | data = wx.TextDataObject() |
---|
| 3061 | # get wx dataobject |
---|
| 3062 | success = wx.TheClipboard.GetData(data) |
---|
| 3063 | # get text |
---|
| 3064 | text = data.GetText() |
---|
| 3065 | # close clipboard |
---|
| 3066 | wx.TheClipboard.Close() |
---|
[951a2f5] | 3067 | return text |
---|
[2296316] | 3068 | |
---|
[951a2f5] | 3069 | def get_paste(self): |
---|
| 3070 | """ |
---|
| 3071 | Paste params from the clipboard |
---|
| 3072 | """ |
---|
| 3073 | text = self.get_clipboard() |
---|
[817991b] | 3074 | flag = self.get_paste_params(text) |
---|
| 3075 | self._copy_info(flag) |
---|
| 3076 | return flag |
---|
[951a2f5] | 3077 | |
---|
[ef26c83] | 3078 | def get_paste_params(self, text=''): |
---|
[2296316] | 3079 | """ |
---|
| 3080 | Get the string copies of the param names and values in the tap |
---|
[ef26c83] | 3081 | """ |
---|
| 3082 | context = {} |
---|
| 3083 | # put the text into dictionary |
---|
[2296316] | 3084 | lines = text.split(':') |
---|
| 3085 | if lines[0] != 'sansview_parameter_values': |
---|
[977a965] | 3086 | self._copy_info(False) |
---|
[2296316] | 3087 | return False |
---|
| 3088 | for line in lines[1:-1]: |
---|
| 3089 | if len(line) != 0: |
---|
[25c0def] | 3090 | item = line.split(',') |
---|
[fc1761b] | 3091 | check = item[1] |
---|
[2296316] | 3092 | name = item[0] |
---|
[fc1761b] | 3093 | value = item[2] |
---|
[2296316] | 3094 | # Transfer the text to content[dictionary] |
---|
[fc1761b] | 3095 | context[name] = [check, value] |
---|
[68a921f] | 3096 | # ToDo: PlugIn this poly disp function for pasting |
---|
[706667b] | 3097 | try: |
---|
[fc1761b] | 3098 | poly_func = item[3] |
---|
[ace0e33] | 3099 | context[name].append(poly_func) |
---|
| 3100 | try: |
---|
[ef26c83] | 3101 | # take the vals and weights for array |
---|
[fc1761b] | 3102 | array_values = item[4].split(' ') |
---|
| 3103 | array_weights = item[5].split(' ') |
---|
[ace0e33] | 3104 | val = [float(a_val) for a_val in array_values[1:]] |
---|
| 3105 | weit = [float(a_weit) for a_weit in array_weights[1:]] |
---|
| 3106 | |
---|
| 3107 | context[name].append(val) |
---|
| 3108 | context[name].append(weit) |
---|
| 3109 | except: |
---|
| 3110 | raise |
---|
[706667b] | 3111 | except: |
---|
[ace0e33] | 3112 | poly_func = '' |
---|
| 3113 | context[name].append(poly_func) |
---|
[706667b] | 3114 | |
---|
[ef26c83] | 3115 | # Do it if params exist |
---|
[2296316] | 3116 | if self.parameters != []: |
---|
[ef26c83] | 3117 | # go through the parameters |
---|
| 3118 | self._get_paste_helper(self.parameters, |
---|
[2296316] | 3119 | self.orientation_params, context) |
---|
| 3120 | |
---|
| 3121 | # go through the fittables |
---|
[ef26c83] | 3122 | self._get_paste_helper(self.fittable_param, |
---|
| 3123 | self.orientation_params_disp, |
---|
[706667b] | 3124 | context) |
---|
[2296316] | 3125 | |
---|
| 3126 | # go through the fixed params |
---|
[ef26c83] | 3127 | self._get_paste_helper(self.fixed_param, |
---|
[2296316] | 3128 | self.orientation_params_disp, context) |
---|
| 3129 | |
---|
| 3130 | # go through the str params |
---|
[ef26c83] | 3131 | self._get_paste_helper(self.str_parameters, |
---|
[2296316] | 3132 | self.orientation_params, context) |
---|
[6b39d58] | 3133 | |
---|
[817991b] | 3134 | return True |
---|
| 3135 | return None |
---|
[2296316] | 3136 | |
---|
| 3137 | def _get_paste_helper(self, param, orient_param, content): |
---|
| 3138 | """ |
---|
| 3139 | Helping set values of the params |
---|
| 3140 | |
---|
| 3141 | : param param: parameters |
---|
| 3142 | : param orient_param: oritational params |
---|
[ef26c83] | 3143 | : param content: dictionary [ name, value: name1.value1,...] |
---|
[2296316] | 3144 | """ |
---|
| 3145 | # go through the str params |
---|
[ef26c83] | 3146 | for item in param: |
---|
[2296316] | 3147 | # 2D |
---|
[25c0def] | 3148 | if self.data.__class__.__name__ == "Data2D": |
---|
[2296316] | 3149 | name = item[1] |
---|
| 3150 | if name in content.keys(): |
---|
[fc1761b] | 3151 | check = content[name][0] |
---|
| 3152 | pd = content[name][1] |
---|
[706667b] | 3153 | if name.count('.') > 0: |
---|
| 3154 | try: |
---|
[ace0e33] | 3155 | float(pd) |
---|
[706667b] | 3156 | except: |
---|
[01642fec] | 3157 | #continue |
---|
| 3158 | if not pd and pd != '': |
---|
| 3159 | continue |
---|
[ace0e33] | 3160 | item[2].SetValue(str(pd)) |
---|
[01642fec] | 3161 | if item in self.fixed_param and pd == '': |
---|
| 3162 | # Only array func has pd == '' case. |
---|
| 3163 | item[2].Enable(False) |
---|
[706667b] | 3164 | if item[2].__class__.__name__ == "ComboBox": |
---|
[ef26c83] | 3165 | if content[name][1] in self.model.fun_list: |
---|
[fc1761b] | 3166 | fun_val = self.model.fun_list[content[name][1]] |
---|
[25c0def] | 3167 | self.model.setParam(name, fun_val) |
---|
[706667b] | 3168 | |
---|
[fc1761b] | 3169 | value = content[name][1:] |
---|
[ace0e33] | 3170 | self._paste_poly_help(item, value) |
---|
[fc1761b] | 3171 | if check == 'True': |
---|
| 3172 | is_true = True |
---|
| 3173 | elif check == 'False': |
---|
| 3174 | is_true = False |
---|
| 3175 | else: |
---|
| 3176 | is_true = None |
---|
| 3177 | if is_true != None: |
---|
| 3178 | item[0].SetValue(is_true) |
---|
| 3179 | # 1D |
---|
[2296316] | 3180 | else: |
---|
| 3181 | ## for 1D all parameters except orientation |
---|
| 3182 | if not item[1] in orient_param: |
---|
| 3183 | name = item[1] |
---|
| 3184 | if name in content.keys(): |
---|
[fc1761b] | 3185 | check = content[name][0] |
---|
[ef26c83] | 3186 | # Avoid changing combox content |
---|
[fc1761b] | 3187 | value = content[name][1:] |
---|
[ace0e33] | 3188 | pd = value[0] |
---|
[706667b] | 3189 | if name.count('.') > 0: |
---|
| 3190 | try: |
---|
[ace0e33] | 3191 | pd = float(pd) |
---|
[706667b] | 3192 | except: |
---|
[01642fec] | 3193 | #continue |
---|
| 3194 | if not pd and pd != '': |
---|
| 3195 | continue |
---|
[ace0e33] | 3196 | item[2].SetValue(str(pd)) |
---|
| 3197 | if item in self.fixed_param and pd == '': |
---|
| 3198 | # Only array func has pd == '' case. |
---|
| 3199 | item[2].Enable(False) |
---|
[d8c54ead] | 3200 | if item[2].__class__.__name__ == "ComboBox": |
---|
[ef26c83] | 3201 | if value[0] in self.model.fun_list: |
---|
[706667b] | 3202 | fun_val = self.model.fun_list[value[0]] |
---|
[25c0def] | 3203 | self.model.setParam(name, fun_val) |
---|
[d8c54ead] | 3204 | # save state |
---|
[ace0e33] | 3205 | self._paste_poly_help(item, value) |
---|
[fc1761b] | 3206 | if check == 'True': |
---|
| 3207 | is_true = True |
---|
| 3208 | elif check == 'False': |
---|
| 3209 | is_true = False |
---|
| 3210 | else: |
---|
| 3211 | is_true = None |
---|
| 3212 | if is_true != None: |
---|
| 3213 | item[0].SetValue(is_true) |
---|
[ace0e33] | 3214 | |
---|
| 3215 | def _paste_poly_help(self, item, value): |
---|
| 3216 | """ |
---|
| 3217 | Helps get paste for poly function |
---|
| 3218 | |
---|
| 3219 | :param item: Gui param items |
---|
| 3220 | :param value: the values for parameter ctrols |
---|
| 3221 | """ |
---|
[6b39d58] | 3222 | is_array = False |
---|
[ace0e33] | 3223 | if len(value[1]) > 0: |
---|
| 3224 | # Only for dispersion func.s |
---|
| 3225 | try: |
---|
| 3226 | item[7].SetValue(value[1]) |
---|
| 3227 | selection = item[7].GetCurrentSelection() |
---|
[01642fec] | 3228 | name = item[7].Name |
---|
| 3229 | param_name = name.split('.')[0] |
---|
[25c0def] | 3230 | dispersity = item[7].GetClientData(selection) |
---|
[ace0e33] | 3231 | disp_model = dispersity() |
---|
| 3232 | # Only for array disp |
---|
| 3233 | try: |
---|
| 3234 | pd_vals = numpy.array(value[2]) |
---|
| 3235 | pd_weights = numpy.array(value[3]) |
---|
| 3236 | if len(pd_vals) > 0 and len(pd_vals) > 0: |
---|
| 3237 | if len(pd_vals) == len(pd_weights): |
---|
[6b39d58] | 3238 | self._set_disp_array_cb(item=item) |
---|
[ef26c83] | 3239 | self._set_array_disp_model(name=name, |
---|
[6b39d58] | 3240 | disp=disp_model, |
---|
[ef26c83] | 3241 | values=pd_vals, |
---|
[6b39d58] | 3242 | weights=pd_weights) |
---|
| 3243 | is_array = True |
---|
[ace0e33] | 3244 | except: |
---|
[ef26c83] | 3245 | pass |
---|
[6b39d58] | 3246 | if not is_array: |
---|
| 3247 | self._disp_obj_dict[name] = disp_model |
---|
[ef26c83] | 3248 | self.model.set_dispersion(name, |
---|
[6b39d58] | 3249 | disp_model) |
---|
| 3250 | self.state._disp_obj_dict[name] = \ |
---|
| 3251 | disp_model |
---|
| 3252 | self.model.set_dispersion(param_name, disp_model) |
---|
| 3253 | self.state.values = self.values |
---|
[ef26c83] | 3254 | self.state.weights = self.weights |
---|
[6b39d58] | 3255 | self.model._persistency_dict[param_name] = \ |
---|
[ef26c83] | 3256 | [self.state.values, |
---|
[25c0def] | 3257 | self.state.weights] |
---|
[6b39d58] | 3258 | |
---|
[ace0e33] | 3259 | except: |
---|
[ef26c83] | 3260 | print "Error in BasePage._paste_poly_help: %s" % sys.exc_value |
---|
[6b39d58] | 3261 | |
---|
| 3262 | def _set_disp_array_cb(self, item): |
---|
| 3263 | """ |
---|
| 3264 | Set cb for array disp |
---|
| 3265 | """ |
---|
| 3266 | item[0].SetValue(False) |
---|
| 3267 | item[0].Enable(False) |
---|
| 3268 | item[2].Enable(False) |
---|
| 3269 | item[3].Show(False) |
---|
| 3270 | item[4].Show(False) |
---|
| 3271 | item[5].SetValue('') |
---|
| 3272 | item[5].Enable(False) |
---|
| 3273 | item[6].SetValue('') |
---|
| 3274 | item[6].Enable(False) |
---|
[25c0def] | 3275 | |
---|
| 3276 | def update_pinhole_smear(self): |
---|
| 3277 | """ |
---|
| 3278 | Method to be called by sub-classes |
---|
| 3279 | TODO: this method doesn't belong here |
---|
| 3280 | """ |
---|
| 3281 | print "BasicPage.update_pinhole_smear was called: skipping" |
---|
| 3282 | return |
---|