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