[0277d084] | 1 | |
---|
| 2 | import wx |
---|
| 3 | import wx.lib.newevent |
---|
| 4 | import numpy |
---|
| 5 | import copy |
---|
| 6 | import math |
---|
[2f60121] | 7 | from sans.guiframe.panel_base import PanelBase |
---|
| 8 | from sans.models.dispersion_models import ArrayDispersion |
---|
| 9 | from sans.models.dispersion_models import GaussianDispersion |
---|
[0277d084] | 10 | from sans.guicomm.events import StatusEvent |
---|
| 11 | from sans.guiframe.utils import format_number |
---|
| 12 | import basepage |
---|
| 13 | from basepage import BasicPage |
---|
| 14 | from basepage import PageInfoEvent |
---|
[2f60121] | 15 | (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() |
---|
[0277d084] | 16 | |
---|
[2f60121] | 17 | _BOX_WIDTH = 76 |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | class ModelPanel(BasicPage, PanelBase): |
---|
[0277d084] | 21 | """ |
---|
[74755ff] | 22 | FitPanel class contains fields allowing to display results when |
---|
| 23 | fitting a model and one data |
---|
| 24 | |
---|
| 25 | :note: For Fit to be performed the user should check at least |
---|
[0277d084] | 26 | one parameter on fit Panel window. |
---|
| 27 | """ |
---|
| 28 | ## Flag to tell the AUI manager to put this panel in the center pane |
---|
| 29 | CENTER_PANE = True |
---|
[693500a] | 30 | ## Internal name for the AUI manager |
---|
| 31 | window_name = "Theory model" |
---|
| 32 | ## Title to appear on top of the window |
---|
| 33 | window_caption = "Theory Model" |
---|
[2f60121] | 34 | |
---|
| 35 | def __init__(self, parent, page_info, model_list_box): |
---|
| 36 | BasicPage.__init__(self, parent, page_info, model_list_box) |
---|
| 37 | PanelBase.__init__(self) |
---|
[0277d084] | 38 | """ |
---|
[74755ff] | 39 | Initialization of the Panel |
---|
[0277d084] | 40 | """ |
---|
| 41 | self._fill_model_sizer( self.sizer1) |
---|
| 42 | self._fill_range_sizer() |
---|
| 43 | self.engine_type = None |
---|
[2f60121] | 44 | description = "" |
---|
| 45 | if self.model != None: |
---|
[0277d084] | 46 | description = self.model.description |
---|
| 47 | self.select_model(self.model) |
---|
[2f60121] | 48 | self.set_model_description(description, self.sizer2) |
---|
[0277d084] | 49 | |
---|
| 50 | def _on_display_description(self, event): |
---|
| 51 | """ |
---|
[74755ff] | 52 | Show or Hide description |
---|
| 53 | |
---|
| 54 | :param event: wx.EVT_RADIOBUTTON |
---|
| 55 | |
---|
[0277d084] | 56 | """ |
---|
| 57 | self._on_display_description_helper() |
---|
[fc292d3] | 58 | self.SetupScrolling() |
---|
[0277d084] | 59 | self.Refresh() |
---|
| 60 | |
---|
| 61 | def _on_display_description_helper(self): |
---|
| 62 | """ |
---|
[74755ff] | 63 | Show or Hide description |
---|
| 64 | |
---|
| 65 | :param event: wx.EVT_RADIOBUTTON |
---|
| 66 | |
---|
[0277d084] | 67 | """ |
---|
| 68 | ## Show description |
---|
| 69 | if self.description_hide.GetValue(): |
---|
| 70 | self.sizer_description.Clear(True) |
---|
| 71 | else: |
---|
| 72 | description="Model contains no description" |
---|
[2f60121] | 73 | if self.model != None: |
---|
[0277d084] | 74 | description = self.model.description |
---|
[2f60121] | 75 | if description.lstrip().rstrip() == "": |
---|
[0277d084] | 76 | description="Model contains no description" |
---|
[2f60121] | 77 | self.description = wx.StaticText(self, -1, str(description)) |
---|
| 78 | self.sizer_description.Add(self.description, 1, |
---|
| 79 | wx.EXPAND|wx.ALL, 10) |
---|
[0277d084] | 80 | self.Layout() |
---|
| 81 | |
---|
| 82 | def _fill_range_sizer(self): |
---|
| 83 | """ |
---|
[74755ff] | 84 | Fill the sizer containing the plotting range |
---|
| 85 | add access to npts |
---|
| 86 | |
---|
[0277d084] | 87 | """ |
---|
| 88 | ##The following 3 lines are for Mac. Let JHC know before modifying.. |
---|
| 89 | title = "Plotted Q Range" |
---|
[2f60121] | 90 | box_description = wx.StaticBox(self, -1, str(title)) |
---|
[0277d084] | 91 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 92 | |
---|
[2f60121] | 93 | sizer_npts= wx.GridSizer(1, 1, 5, 5) |
---|
| 94 | self.npts = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), |
---|
| 95 | style=wx.TE_PROCESS_ENTER) |
---|
[0277d084] | 96 | self.npts.SetValue(format_number(self.num_points)) |
---|
| 97 | self.npts.SetToolTipString("Number of point to plot.") |
---|
[2f60121] | 98 | sizer_npts.Add(wx.StaticText(self, -1, 'Npts'), 1, |
---|
| 99 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 13) |
---|
| 100 | sizer_npts.Add(self.npts, 1, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
| 101 | self._set_range_sizer(title=title, box_sizer=boxsizer1, |
---|
| 102 | object=sizer_npts) |
---|
| 103 | |
---|
[0277d084] | 104 | def _on_select_model(self, event): |
---|
| 105 | """ |
---|
[74755ff] | 106 | call back for model selection |
---|
| 107 | |
---|
[0277d084] | 108 | """ |
---|
| 109 | self._on_select_model_helper() |
---|
| 110 | #Reset dispersity that was not done in _on_select_model_helper() |
---|
| 111 | self._reset_dispersity() |
---|
| 112 | self.select_model(self.model) |
---|
| 113 | |
---|
| 114 | def _fill_model_sizer(self, sizer): |
---|
| 115 | """ |
---|
[74755ff] | 116 | fill sizer containing model info |
---|
| 117 | |
---|
[0277d084] | 118 | """ |
---|
| 119 | ##The following 3 lines are for Mac. Let JHC know before modifying.. |
---|
| 120 | title = "Model" |
---|
[2f60121] | 121 | box_description = wx.StaticBox(self, -1, str(title)) |
---|
[0277d084] | 122 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 123 | id = wx.NewId() |
---|
[2f60121] | 124 | self.model_view = wx.Button(self, id,'View 2D', size=(80, 23)) |
---|
| 125 | self.model_view.Bind(wx.EVT_BUTTON, self._onModel2D, id=id) |
---|
[0277d084] | 126 | self.model_view.SetToolTipString("View model in 2D") |
---|
| 127 | ## class base method to add view 2d button |
---|
[2f60121] | 128 | self._set_model_sizer(sizer=sizer, box_sizer=boxsizer1, |
---|
| 129 | title=title, object=self.model_view) |
---|
[0277d084] | 130 | |
---|
| 131 | #def _set_sizer_gaussian(self): |
---|
| 132 | def _set_sizer_dispersion(self, dispersity): |
---|
| 133 | """ |
---|
[74755ff] | 134 | draw sizer with gaussian, log or schulz dispersity parameters |
---|
| 135 | |
---|
[0277d084] | 136 | """ |
---|
[2f60121] | 137 | self.fittable_param = [] |
---|
| 138 | self.fixed_param = [] |
---|
| 139 | self.orientation_params_disp = [] |
---|
[0277d084] | 140 | #self.temp=[] |
---|
| 141 | self.sizer4_4.Clear(True) |
---|
[2f60121] | 142 | if self.model == None: |
---|
[0277d084] | 143 | ##no model is selected |
---|
| 144 | return |
---|
| 145 | if not self.enable_disp.GetValue(): |
---|
| 146 | ## the user didn't select dispersity display |
---|
| 147 | return |
---|
| 148 | self._reset_dispersity() |
---|
| 149 | # Create the dispersion objects |
---|
| 150 | for item in self.model.dispersion.keys(): |
---|
| 151 | #disp_model = GaussianDispersion() |
---|
| 152 | disp_model = dispersity() |
---|
| 153 | self._disp_obj_dict[item] = disp_model |
---|
| 154 | self.model.set_dispersion(item, disp_model) |
---|
[2f60121] | 155 | self.state._disp_obj_dict[item] = disp_model |
---|
| 156 | ix = 0 |
---|
| 157 | iy = 1 |
---|
[52efcc5] | 158 | disp = wx.StaticText(self, -1, ' ') |
---|
[2f60121] | 159 | self.sizer4_4.Add(disp,(iy, ix), (1, 1), |
---|
[0277d084] | 160 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 161 | ix += 1 |
---|
[d7b7156] | 162 | values = wx.StaticText(self, -1, 'Sigma [A]') |
---|
[2f60121] | 163 | hint_msg = "Sigma(STD) in the A unit; the standard " |
---|
| 164 | hint_msg += "deviation from the mean value." |
---|
| 165 | values.SetToolTipString(hint_msg) |
---|
| 166 | self.sizer4_4.Add(values, (iy, ix), (1, 1), |
---|
| 167 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[0277d084] | 168 | ix += 1 |
---|
| 169 | npts = wx.StaticText(self, -1, 'Npts') |
---|
[2f60121] | 170 | hint_msg = "Number of sampling points for the numerical\n" |
---|
| 171 | hint_msg += "integration over the distribution function." |
---|
| 172 | npts.SetToolTipString(hint_msg) |
---|
| 173 | self.sizer4_4.Add(npts, (iy, ix), (1, 1), |
---|
| 174 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[0277d084] | 175 | ix += 1 |
---|
| 176 | nsigmas = wx.StaticText(self, -1, 'Nsigmas') |
---|
[2f60121] | 177 | hint_msg = "Number of sigmas between which the range\n" |
---|
| 178 | hint_msg += "of the distribution function will be used for " |
---|
| 179 | hint_msg += "weighting.\n The value '3' covers 99.5% for Gaussian " |
---|
| 180 | hint_msg += " distribution \n function." |
---|
| 181 | nsigmas.SetToolTipString(hint_msg) |
---|
| 182 | self.sizer4_4.Add(nsigmas, (iy, ix), |
---|
| 183 | (1, 1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[0277d084] | 184 | for item in self.model.dispersion.keys(): |
---|
| 185 | if not item in self.model.orientation_params: |
---|
[2f60121] | 186 | self.disp_cb_dict[item] = None |
---|
| 187 | name0 = "Distribution of " + item |
---|
| 188 | name1 = item + ".width" |
---|
[0277d084] | 189 | name2=item+".npts" |
---|
| 190 | name3=item+".nsigmas" |
---|
| 191 | iy += 1 |
---|
| 192 | for p in self.model.dispersion[item].keys(): |
---|
[2f60121] | 193 | if p == "width": |
---|
[0277d084] | 194 | ix = 0 |
---|
[d7b7156] | 195 | name = wx.StaticText(self, -1, name0) |
---|
[0277d084] | 196 | self.sizer4_4.Add( name,( iy, ix),(1,1), |
---|
| 197 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 198 | ix = 1 |
---|
| 199 | value= self.model.getParam(name1) |
---|
| 200 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
| 201 | style=wx.TE_PROCESS_ENTER) |
---|
[d7b7156] | 202 | ctl1.SetToolTipString("Absolute Sigma: \n\ |
---|
| 203 | 1) It is the STD (ratio*mean) of '%s' distribution.\n \ |
---|
| 204 | 2) It should not exceed Mean/(2*Nsigmas)." %item) |
---|
[0277d084] | 205 | ctl1.SetValue(str (format_number(value))) |
---|
| 206 | self.sizer4_4.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 207 | self.fittable_param.append([None,name1,ctl1,None, |
---|
| 208 | None, None, None,None]) |
---|
| 209 | elif p=="npts": |
---|
| 210 | ix =2 |
---|
| 211 | value= self.model.getParam(name2) |
---|
| 212 | Tctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
| 213 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 214 | |
---|
[0277d084] | 215 | Tctl1.SetValue(str (format_number(value))) |
---|
| 216 | self.sizer4_4.Add(Tctl1, (iy,ix),(1,1), |
---|
| 217 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 218 | self.fixed_param.append([None,name2, Tctl1,None,None, |
---|
| 219 | None, None,None]) |
---|
| 220 | elif p=="nsigmas": |
---|
| 221 | ix =3 |
---|
| 222 | value= self.model.getParam(name3) |
---|
| 223 | Tctl2 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
| 224 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 225 | |
---|
[0277d084] | 226 | Tctl2.SetValue(str (format_number(value))) |
---|
| 227 | self.sizer4_4.Add(Tctl2, (iy,ix),(1,1), |
---|
| 228 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 229 | ix +=1 |
---|
| 230 | self.sizer4_4.Add((20,20), (iy,ix),(1,1), |
---|
| 231 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 232 | self.fixed_param.append([None,name3, Tctl2, |
---|
| 233 | None,None, None, None,None]) |
---|
[d7b7156] | 234 | first_orient = True |
---|
[0277d084] | 235 | for item in self.model.dispersion.keys(): |
---|
| 236 | if item in self.model.orientation_params: |
---|
| 237 | self.disp_cb_dict[item]= None |
---|
[d7b7156] | 238 | name0="Distribution of " + item |
---|
[0277d084] | 239 | name1=item+".width" |
---|
| 240 | name2=item+".npts" |
---|
| 241 | name3=item+".nsigmas" |
---|
| 242 | iy += 1 |
---|
| 243 | for p in self.model.dispersion[item].keys(): |
---|
| 244 | if p=="width": |
---|
| 245 | ix = 0 |
---|
[d7b7156] | 246 | name = wx.StaticText(self, -1, name0) |
---|
[0277d084] | 247 | self.sizer4_4.Add( name,( iy, ix),(1,1), |
---|
| 248 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 249 | if not self.enable2D: |
---|
| 250 | name.Hide() |
---|
| 251 | else: |
---|
| 252 | name.Show(True) |
---|
| 253 | ix = 1 |
---|
| 254 | value= self.model.getParam(name1) |
---|
| 255 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
| 256 | style=wx.TE_PROCESS_ENTER) |
---|
[d7b7156] | 257 | ctl1.SetToolTipString("Absolute Sigma: \n\ |
---|
| 258 | 1) It is the STD (ratio*mean) of '%s' distribution."% \ |
---|
| 259 | item) |
---|
[0277d084] | 260 | ctl1.SetValue(str (format_number(value))) |
---|
| 261 | if not self.enable2D: |
---|
| 262 | ctl1.Hide() |
---|
| 263 | ctl1.Disable() |
---|
| 264 | else: |
---|
[d7b7156] | 265 | # in the case of 2D and angle parameter |
---|
| 266 | if first_orient: |
---|
| 267 | values.SetLabel('Sigma [A (or deg)]') |
---|
| 268 | values.SetToolTipString(\ |
---|
| 269 | "Sigma(STD) in the A or deg(for angles) unit;\n\ |
---|
| 270 | the standard deviation from the mean value.") |
---|
| 271 | first_orient = False |
---|
[0277d084] | 272 | ctl1.Show(True) |
---|
| 273 | ctl1.Enable() |
---|
| 274 | self.sizer4_4.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 275 | self.fittable_param.append([None,name1,ctl1,None, |
---|
| 276 | None, None, None,None]) |
---|
| 277 | self.orientation_params_disp.append([None,name1,ctl1,None, |
---|
| 278 | None, None, None,None]) |
---|
| 279 | elif p=="npts": |
---|
| 280 | ix =2 |
---|
| 281 | value= self.model.getParam(name2) |
---|
| 282 | Tctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
| 283 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 284 | |
---|
[0277d084] | 285 | Tctl1.SetValue(str (format_number(value))) |
---|
| 286 | if not self.enable2D: |
---|
| 287 | Tctl1.Hide() |
---|
| 288 | Tctl1.Disable() |
---|
| 289 | else: |
---|
| 290 | Tctl1.Show(True) |
---|
| 291 | Tctl1.Enable() |
---|
| 292 | self.sizer4_4.Add(Tctl1, (iy,ix),(1,1), |
---|
| 293 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 294 | self.fixed_param.append([None,name2, Tctl1,None,None, |
---|
| 295 | None, None,None]) |
---|
| 296 | self.orientation_params_disp.append([None,name2, Tctl1,None,None, |
---|
| 297 | None, None,None]) |
---|
| 298 | elif p=="nsigmas": |
---|
| 299 | ix =3 |
---|
| 300 | value= self.model.getParam(name3) |
---|
| 301 | Tctl2 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
| 302 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 303 | |
---|
[0277d084] | 304 | Tctl2.SetValue(str (format_number(value))) |
---|
| 305 | if not self.enable2D: |
---|
| 306 | Tctl2.Hide() |
---|
| 307 | Tctl2.Disable() |
---|
| 308 | else: |
---|
| 309 | Tctl2.Show(True) |
---|
| 310 | Tctl2.Enable() |
---|
| 311 | self.sizer4_4.Add(Tctl2, (iy,ix),(1,1), |
---|
| 312 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 313 | ix +=1 |
---|
| 314 | #self.sizer4_4.Add((20,20), (iy,ix),(1,1), |
---|
| 315 | #wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 316 | self.fixed_param.append([None,name3, Tctl2, |
---|
| 317 | None,None, None, None,None]) |
---|
| 318 | self.orientation_params_disp.append([None,name3, Tctl2, |
---|
| 319 | None,None, None, None,None]) |
---|
[d7b7156] | 320 | |
---|
[0277d084] | 321 | msg = " Selected Distribution: Gaussian" |
---|
| 322 | wx.PostEvent(self.parent, StatusEvent( status= msg )) |
---|
| 323 | self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict) |
---|
| 324 | ix =0 |
---|
| 325 | iy +=1 |
---|
| 326 | #self.sizer4_4.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 327 | self.sizer4_4.Layout() |
---|
| 328 | self.sizer4.Layout() |
---|
[fc292d3] | 329 | self.SetupScrolling() |
---|
[0277d084] | 330 | |
---|
| 331 | |
---|
| 332 | def _onModel2D(self, event): |
---|
| 333 | """ |
---|
[74755ff] | 334 | call manager to plot model in 2D |
---|
| 335 | |
---|
[0277d084] | 336 | """ |
---|
| 337 | # If the 2D display is not currently enabled, plot the model in 2D |
---|
| 338 | # and set the enable2D flag. |
---|
| 339 | |
---|
| 340 | if self.fitrange: |
---|
| 341 | self.enable2D = True |
---|
| 342 | |
---|
| 343 | if self.enable2D: |
---|
| 344 | self._draw_model() |
---|
| 345 | self.model_view.Disable() |
---|
| 346 | |
---|
| 347 | n = self.disp_box.GetCurrentSelection() |
---|
| 348 | dispersity= self.disp_box.GetClientData(n) |
---|
| 349 | #TODO:Find a better way to reinitialize the parameters containers |
---|
| 350 | # when resetting the page and 2D view is enable |
---|
| 351 | #self.set_model_param_sizer(self.model): called here is using a lot |
---|
| 352 | #of for loops and redraw the sizer again .How to avoid it? |
---|
| 353 | self.set_model_param_sizer(self.model) |
---|
| 354 | |
---|
| 355 | if len(self.orientation_params)>0: |
---|
| 356 | for item in self.orientation_params: |
---|
| 357 | if item[2]!=None: |
---|
| 358 | item[2].Enable() |
---|
| 359 | # same as above why do we have to redraw the sizer of dispersity to get |
---|
| 360 | # the appropriate value of parameters containers on reset page? |
---|
| 361 | # Reset containers of dispersity parameters for the appropriate dispersity |
---|
| 362 | #and model |
---|
| 363 | if self.disp_name.lower()in ["array","arraydispersion"]: |
---|
| 364 | self._set_sizer_arraydispersion() |
---|
| 365 | else: |
---|
| 366 | self._set_sizer_dispersion(dispersity) |
---|
| 367 | if len(self.orientation_params_disp)>0: |
---|
| 368 | |
---|
| 369 | for item in self.orientation_params_disp: |
---|
| 370 | if item[2]!=None: |
---|
| 371 | item[2].Enable() |
---|
| 372 | |
---|
| 373 | self.state.enable2D = copy.deepcopy(self.enable2D) |
---|
| 374 | self.Layout() |
---|
| 375 | ## post state to fit panel |
---|
| 376 | #self._undo.Enable(True) |
---|
| 377 | event = PageInfoEvent(page = self) |
---|
| 378 | wx.PostEvent(self.parent, event) |
---|
[fb59ed9] | 379 | |
---|
| 380 | def _set_fun_box_list(self,fun_box): |
---|
| 381 | """ |
---|
| 382 | Set the list of func for multifunctional models |
---|
| 383 | |
---|
| 384 | :param fun_box: function combo box |
---|
| 385 | """ |
---|
| 386 | # Check if it is multi_functional model |
---|
| 387 | if self.model.__class__ not in self.model_list_box["Multi-Functions"]: |
---|
| 388 | return None |
---|
| 389 | # Get the func name list |
---|
| 390 | list = self.model.fun_list |
---|
| 391 | |
---|
| 392 | if len(list) == 0: |
---|
| 393 | return None |
---|
| 394 | |
---|
| 395 | # build function (combo)box |
---|
| 396 | ind = 0 |
---|
| 397 | while(ind < len(list)): |
---|
| 398 | for key, val in list.iteritems(): |
---|
| 399 | if (val == ind): |
---|
| 400 | fun_box.Append(key,val) |
---|
| 401 | break |
---|
| 402 | ind += 1 |
---|
| 403 | |
---|
| 404 | def _on_fun_box(self,event): |
---|
| 405 | """ |
---|
| 406 | Select an func: Erf,Rparabola,LParabola... |
---|
| 407 | """ |
---|
| 408 | fun_val = None |
---|
| 409 | fun_box = event.GetEventObject() |
---|
| 410 | name = fun_box.Name |
---|
| 411 | value = fun_box.GetValue() |
---|
| 412 | if self.model.fun_list.has_key(value): |
---|
| 413 | fun_val = self.model.fun_list[value] |
---|
| 414 | |
---|
| 415 | self.model.setParam(name,fun_val) |
---|
| 416 | # save state |
---|
| 417 | self._copy_parameters_state(self.str_parameters, self.state.str_parameters) |
---|
| 418 | # update params |
---|
| 419 | #self._update_paramv_on_fit() |
---|
| 420 | |
---|
| 421 | # draw |
---|
| 422 | self._draw_model() |
---|
| 423 | self.Refresh() |
---|
| 424 | # get ready for new event |
---|
| 425 | event.Skip() |
---|
[0277d084] | 426 | |
---|
[3c44c66] | 427 | def set_data(self, list=[], state=None): |
---|
| 428 | """ |
---|
| 429 | Receive a list of data from gui_manager to plot theory |
---|
| 430 | """ |
---|
[e99126a] | 431 | pass |
---|
| 432 | |
---|
[0277d084] | 433 | def reset_page(self, state): |
---|
| 434 | """ |
---|
[74755ff] | 435 | reset the state |
---|
| 436 | |
---|
[0277d084] | 437 | """ |
---|
| 438 | self.reset_page_helper(state) |
---|
| 439 | |
---|
| 440 | |
---|
| 441 | def select_model(self, model): |
---|
| 442 | """ |
---|
[74755ff] | 443 | Select a new model |
---|
| 444 | |
---|
| 445 | :param model: model object |
---|
| 446 | |
---|
[0277d084] | 447 | """ |
---|
| 448 | self.model = model |
---|
| 449 | if self.model !=None: |
---|
| 450 | self.disp_list= self.model.getDispParamList() |
---|
| 451 | self.set_model_param_sizer(self.model) |
---|
| 452 | ## keep the sizer view consistent with the model menu selecting |
---|
| 453 | self._set_model_sizer_selection( self.model ) |
---|
| 454 | self.enable_disp.SetValue(False) |
---|
| 455 | self.disable_disp.SetValue(True) |
---|
| 456 | self.set_dispers_sizer() |
---|
| 457 | |
---|
| 458 | self.model_view.SetFocus() |
---|
| 459 | if self.model !=None: |
---|
| 460 | self._draw_model() |
---|
| 461 | self.state.structurecombobox = self.structurebox.GetCurrentSelection() |
---|
| 462 | self.state.formfactorcombobox = self.formfactorbox.GetCurrentSelection() |
---|
| 463 | |
---|
| 464 | ## post state to fit panel |
---|
| 465 | #self._undo.Enable(True) |
---|
| 466 | event = PageInfoEvent(page = self) |
---|
| 467 | wx.PostEvent(self.parent, event) |
---|
| 468 | |
---|
| 469 | |
---|
| 470 | def set_model_description(self,description,sizer): |
---|
| 471 | """ |
---|
[74755ff] | 472 | fill a sizer with description |
---|
| 473 | |
---|
| 474 | :param description: of type string |
---|
| 475 | :param sizer: wx.BoxSizer() |
---|
| 476 | |
---|
[0277d084] | 477 | """ |
---|
| 478 | |
---|
| 479 | sizer.Clear(True) |
---|
| 480 | box_description= wx.StaticBox(self, -1, 'Model Description') |
---|
| 481 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 482 | |
---|
| 483 | sizer_selection=wx.BoxSizer(wx.HORIZONTAL) |
---|
[2f60121] | 484 | self.description_hide = wx.RadioButton(self, -1, 'Hide', |
---|
| 485 | style=wx.RB_GROUP) |
---|
[0277d084] | 486 | self.description_show = wx.RadioButton(self, -1, 'Show') |
---|
| 487 | |
---|
| 488 | |
---|
[2f60121] | 489 | if description == "": |
---|
[0277d084] | 490 | self.description_hide.SetValue(True) |
---|
[2f60121] | 491 | description = " Description unavailable. Click for details" |
---|
[0277d084] | 492 | |
---|
| 493 | self.description = wx.StaticText( self,-1,str(description) ) |
---|
| 494 | |
---|
| 495 | self.Bind( wx.EVT_RADIOBUTTON, self._on_display_description, |
---|
| 496 | id=self.description_hide.GetId() ) |
---|
| 497 | |
---|
| 498 | self.Bind( wx.EVT_RADIOBUTTON, self._on_display_description, |
---|
| 499 | id=self.description_show.GetId() ) |
---|
| 500 | #MAC needs SetValue |
---|
| 501 | self.description_hide.SetValue(True) |
---|
| 502 | |
---|
| 503 | self.model_description = wx.Button(self,-1, label="Details", size=(80,23)) |
---|
| 504 | |
---|
| 505 | self.model_description.Bind(wx.EVT_BUTTON,self.on_button_clicked) |
---|
| 506 | self.model_description.SetToolTipString("Click Model Functions in HelpWindow...") |
---|
| 507 | self.model_description.SetFocus() |
---|
| 508 | sizer_selection.Add( self.description_show ) |
---|
| 509 | sizer_selection.Add( (20,20)) |
---|
| 510 | sizer_selection.Add( self.description_hide ) |
---|
| 511 | sizer_selection.Add((20,20),0, wx.LEFT|wx.RIGHT|wx.EXPAND,75) |
---|
| 512 | sizer_selection.Add( self.model_description ) |
---|
| 513 | |
---|
| 514 | |
---|
| 515 | self.sizer_description=wx.BoxSizer(wx.HORIZONTAL) |
---|
| 516 | self.sizer_description.Add( self.description, 1, wx.EXPAND | wx.ALL, 10 ) |
---|
| 517 | boxsizer1.Add( sizer_selection) |
---|
| 518 | boxsizer1.Add( (20,20)) |
---|
| 519 | boxsizer1.Add( self.sizer_description) |
---|
| 520 | |
---|
| 521 | self._on_display_description(event=None) |
---|
| 522 | sizer.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 523 | sizer.Layout() |
---|
| 524 | |
---|
| 525 | def on_button_clicked(self,event): |
---|
| 526 | """ |
---|
[74755ff] | 527 | On 'More details' button |
---|
[0277d084] | 528 | """ |
---|
| 529 | from help_panel import HelpWindow |
---|
| 530 | |
---|
| 531 | if self.model == None: |
---|
| 532 | name = 'FuncHelp' |
---|
| 533 | else: |
---|
| 534 | name = self.model.name |
---|
[e071b1c] | 535 | frame = HelpWindow(None, -1, pageToOpen="media/model_functions.html") |
---|
[0277d084] | 536 | frame.Show(True) |
---|
| 537 | if frame.rhelp.HasAnchor(name): |
---|
| 538 | frame.rhelp.ScrollToAnchor(name) |
---|
| 539 | else: |
---|
| 540 | msg= "Model does not contains an available description " |
---|
| 541 | msg +="Please.Search in the Help window" |
---|
| 542 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
| 543 | |
---|
| 544 | def set_range(self, qmin_x, qmax_x, npts): |
---|
| 545 | """ |
---|
[74755ff] | 546 | Set the range for the plotted models |
---|
| 547 | |
---|
| 548 | :param qmin: minimum Q |
---|
| 549 | :param qmax: maximum Q |
---|
| 550 | :param npts: number of Q bins |
---|
| 551 | |
---|
[0277d084] | 552 | """ |
---|
| 553 | # Set the data members |
---|
| 554 | self.qmin_x = qmin_x |
---|
| 555 | self.qmax_x = qmax_x |
---|
| 556 | self.num_points = npts |
---|
| 557 | # Set the controls |
---|
| 558 | #For qmin and qmax, do not use format_number.(If do, qmin and max could be different from what is in the data.) |
---|
| 559 | self.qmin.SetValue(str(self.qmin_x)) |
---|
| 560 | self.qmax.SetValue(str(self.qmax_x)) |
---|
| 561 | self.npts.SetValue(format_number(self.num_points)) |
---|
| 562 | |
---|
| 563 | def set_model_param_sizer(self, model): |
---|
| 564 | """ |
---|
[74755ff] | 565 | Build the panel from the model content |
---|
| 566 | |
---|
| 567 | :param model: the model selected in combo box for fitting purpose |
---|
| 568 | |
---|
[0277d084] | 569 | """ |
---|
| 570 | self.sizer3.Clear(True) |
---|
| 571 | self.parameters = [] |
---|
[fb59ed9] | 572 | self.str_parameters = [] |
---|
[0277d084] | 573 | self.param_toFit=[] |
---|
| 574 | self.fixed_param=[] |
---|
| 575 | self.orientation_params=[] |
---|
| 576 | self.orientation_params_disp=[] |
---|
| 577 | #self.temp=[] |
---|
| 578 | if model ==None: |
---|
| 579 | ##no model avaiable to draw sizer |
---|
| 580 | self.sizer3.Layout() |
---|
[fc292d3] | 581 | self.SetupScrolling() |
---|
[0277d084] | 582 | return |
---|
| 583 | box_description= wx.StaticBox(self, -1,str("Model Parameters")) |
---|
| 584 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 585 | sizer = wx.GridBagSizer(5,5) |
---|
| 586 | |
---|
| 587 | self.model = model |
---|
| 588 | self.set_model_description(self.model.description,self.sizer2) |
---|
| 589 | |
---|
| 590 | keys = self.model.getParamList() |
---|
| 591 | ##list of dispersion parameters |
---|
| 592 | self.disp_list=self.model.getDispParamList() |
---|
| 593 | |
---|
[db08737] | 594 | def custom_compare(a,b): |
---|
| 595 | """ |
---|
| 596 | Custom compare to order, first by alphabets then second by number. |
---|
| 597 | """ |
---|
[fb59ed9] | 598 | # number at the last digit |
---|
[db08737] | 599 | a_last = a[len(a)-1] |
---|
| 600 | b_last = b[len(b)-1] |
---|
[fb59ed9] | 601 | # default |
---|
[db08737] | 602 | num_a = None |
---|
| 603 | num_b = None |
---|
[fb59ed9] | 604 | # split the names |
---|
| 605 | a2 = a.lower().split('_') |
---|
| 606 | b2 = b.lower().split('_') |
---|
| 607 | # check length of a2, b2 |
---|
| 608 | len_a2 = len(a2) |
---|
| 609 | len_b2 = len(b2) |
---|
[db08737] | 610 | # check if it contains a int number(<10) |
---|
| 611 | try: |
---|
| 612 | num_a = int(a_last) |
---|
| 613 | except: pass |
---|
| 614 | try: |
---|
| 615 | num_b = int(b_last) |
---|
| 616 | except: pass |
---|
[fb59ed9] | 617 | # Put 'scale' near the top; happens |
---|
| 618 | # when numbered param name exists |
---|
| 619 | if a == 'scale': |
---|
| 620 | return -1 |
---|
[db08737] | 621 | # both have a number |
---|
| 622 | if num_a != None and num_b != None: |
---|
[fb59ed9] | 623 | if num_a > num_b: return -1 |
---|
| 624 | # same number |
---|
[db08737] | 625 | elif num_a == num_b: |
---|
[fb59ed9] | 626 | # different last names |
---|
| 627 | if a2[len_a2-1] != b2[len_b2-1] and num_a != 0: |
---|
| 628 | return -cmp(a2[len_a2-1], b2[len_b2-1]) |
---|
| 629 | else: |
---|
| 630 | return cmp(a, b) |
---|
| 631 | else: return 1 |
---|
[db08737] | 632 | # one of them has a number |
---|
[20905a0] | 633 | elif num_a != None: return 1 |
---|
| 634 | elif num_b != None: return -1 |
---|
[fb59ed9] | 635 | # no numbers |
---|
[20905a0] | 636 | else: return cmp(a.lower(), b.lower()) |
---|
[fb59ed9] | 637 | |
---|
[db08737] | 638 | keys.sort(custom_compare) |
---|
| 639 | |
---|
[0277d084] | 640 | |
---|
| 641 | iy = 0 |
---|
| 642 | ix = 0 |
---|
| 643 | self.text1_2 = wx.StaticText(self, -1, 'Names') |
---|
| 644 | sizer.Add(self.text1_2,(iy, ix),(1,1),\ |
---|
| 645 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 646 | ix +=1 |
---|
| 647 | self.text2_2 = wx.StaticText(self, -1, 'Values') |
---|
| 648 | sizer.Add(self.text2_2,(iy, ix),(1,1),\ |
---|
| 649 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 650 | ix +=1 |
---|
| 651 | self.text2_4 = wx.StaticText(self, -1, '[Units]') |
---|
| 652 | sizer.Add(self.text2_4,(iy, ix),(1,1),\ |
---|
| 653 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 654 | self.text2_4.Hide() |
---|
| 655 | |
---|
| 656 | for item in keys: |
---|
| 657 | if not item in self.disp_list and not item in self.model.orientation_params: |
---|
| 658 | iy += 1 |
---|
| 659 | ix = 0 |
---|
[fb59ed9] | 660 | if self.model.__class__ in self.model_list_box["Multi-Functions"]\ |
---|
| 661 | and item in self.model.non_fittable: |
---|
| 662 | non_fittable_name = wx.StaticText(self, -1, item ) |
---|
| 663 | sizer.Add(non_fittable_name,(iy, ix),(1,1),\ |
---|
| 664 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 665 | ## add parameter value |
---|
| 666 | ix += 1 |
---|
| 667 | value= self.model.getParam(item) |
---|
| 668 | if len(self.model.fun_list) > 0: |
---|
| 669 | num = item.split('_')[1][5:7] |
---|
| 670 | fun_box = wx.ComboBox(self, -1,size=(100,-1),style=wx.CB_READONLY, name = '%s'% item) |
---|
| 671 | self._set_fun_box_list(fun_box) |
---|
| 672 | fun_box.SetSelection(0) |
---|
| 673 | #self.fun_box.SetToolTipString("A function describing the interface") |
---|
| 674 | wx.EVT_COMBOBOX(fun_box,-1, self._on_fun_box) |
---|
| 675 | else: |
---|
| 676 | fun_box = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
| 677 | style=wx.TE_PROCESS_ENTER, name ='%s'% item) |
---|
| 678 | fun_box.SetToolTipString("Hit 'Enter' after typing.") |
---|
| 679 | fun_box.SetValue(format_number(value)) |
---|
| 680 | sizer.Add(fun_box, (iy,ix),(1,1), wx.EXPAND) |
---|
| 681 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
| 682 | self.str_parameters.append([None,item, fun_box, \ |
---|
| 683 | None,None,None,None,None]) |
---|
[0277d084] | 684 | else: |
---|
[fb59ed9] | 685 | name = wx.StaticText(self, -1,item) |
---|
| 686 | sizer.Add( name,( iy, ix),(1,1), |
---|
| 687 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 688 | |
---|
| 689 | ix += 1 |
---|
| 690 | value= self.model.getParam(item) |
---|
| 691 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
| 692 | style=wx.TE_PROCESS_ENTER) |
---|
| 693 | |
---|
| 694 | ctl1.SetValue(str (format_number(value))) |
---|
| 695 | |
---|
| 696 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 697 | ix +=1 |
---|
| 698 | # Units |
---|
| 699 | if self.model.details.has_key(item): |
---|
| 700 | units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
| 701 | else: |
---|
| 702 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
| 703 | sizer.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 704 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
| 705 | self.parameters.append([None,item, ctl1, |
---|
| 706 | None,None, None, None,None]) |
---|
[0277d084] | 707 | iy+=1 |
---|
| 708 | sizer.Add((10,10),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 709 | iy += 1 |
---|
| 710 | ix = 0 |
---|
| 711 | |
---|
| 712 | #Add tile for orientational angle parameters |
---|
| 713 | for item in keys: |
---|
| 714 | if item in self.model.orientation_params: |
---|
| 715 | orient_angle = wx.StaticText(self, -1, '[For 2D only]:') |
---|
| 716 | sizer.Add(orient_angle,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 717 | if not self.enable2D: |
---|
| 718 | orient_angle.Hide() |
---|
| 719 | else: |
---|
| 720 | orient_angle.Show(True) |
---|
| 721 | break |
---|
| 722 | |
---|
| 723 | for item in self.model.orientation_params: |
---|
| 724 | if not item in self.disp_list and item in keys: |
---|
| 725 | iy += 1 |
---|
| 726 | ix = 0 |
---|
| 727 | name = wx.StaticText(self, -1,item) |
---|
| 728 | sizer.Add( name,( iy, ix),(1,1), |
---|
| 729 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 730 | if not self.enable2D: |
---|
| 731 | name.Hide() |
---|
| 732 | else: |
---|
| 733 | name.Show(True) |
---|
| 734 | |
---|
| 735 | ix += 1 |
---|
| 736 | value= self.model.getParam(item) |
---|
| 737 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
| 738 | style=wx.TE_PROCESS_ENTER) |
---|
| 739 | |
---|
| 740 | ctl1.SetValue(str (format_number(value))) |
---|
| 741 | if not self.enable2D: |
---|
| 742 | ctl1.Hide() |
---|
| 743 | ctl1.Disable() |
---|
| 744 | else: |
---|
| 745 | ctl1.Show(True) |
---|
| 746 | ctl1.Enable() |
---|
| 747 | |
---|
| 748 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 749 | ix +=1 |
---|
| 750 | # Units |
---|
| 751 | if self.model.details.has_key(item): |
---|
| 752 | units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
| 753 | else: |
---|
| 754 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
| 755 | if not self.enable2D: |
---|
| 756 | units.Hide() |
---|
| 757 | else: |
---|
| 758 | units.Show(True) |
---|
| 759 | |
---|
| 760 | sizer.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 761 | #Save 2D orient. params |
---|
| 762 | #self.temp.append([name,ctl1,units,orient_angle]) |
---|
| 763 | |
---|
| 764 | |
---|
| 765 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
| 766 | self.parameters.append([None,item, ctl1, |
---|
| 767 | None,None, None, None,None]) |
---|
| 768 | self.orientation_params.append([None,item, ctl1, |
---|
[199cef2] | 769 | None,None, None, None,None]) |
---|
| 770 | iy += 1 |
---|
[0277d084] | 771 | |
---|
| 772 | #Display units text on panel |
---|
| 773 | for item in keys: |
---|
| 774 | self.text2_4.Show() |
---|
| 775 | |
---|
| 776 | boxsizer1.Add(sizer) |
---|
| 777 | self.sizer3.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 778 | self.sizer3.Layout() |
---|
[fc292d3] | 779 | self.SetupScrolling() |
---|
[0277d084] | 780 | |
---|