[0277d084] | 1 | |
---|
| 2 | import wx |
---|
| 3 | import wx.lib.newevent |
---|
| 4 | import numpy |
---|
| 5 | import copy |
---|
| 6 | import math |
---|
| 7 | from sans.models.dispersion_models import ArrayDispersion, GaussianDispersion |
---|
| 8 | |
---|
| 9 | from sans.guicomm.events import StatusEvent |
---|
| 10 | from sans.guiframe.utils import format_number |
---|
| 11 | (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() |
---|
| 12 | _BOX_WIDTH = 76 |
---|
| 13 | |
---|
| 14 | import basepage |
---|
| 15 | from basepage import BasicPage |
---|
| 16 | from basepage import PageInfoEvent |
---|
| 17 | |
---|
| 18 | class ModelPanel(BasicPage): |
---|
| 19 | """ |
---|
| 20 | FitPanel class contains fields allowing to display results when |
---|
| 21 | fitting a model and one data |
---|
| 22 | @note: For Fit to be performed the user should check at least |
---|
| 23 | one parameter on fit Panel window. |
---|
| 24 | """ |
---|
| 25 | ## Flag to tell the AUI manager to put this panel in the center pane |
---|
| 26 | CENTER_PANE = True |
---|
[693500a] | 27 | ## Internal name for the AUI manager |
---|
| 28 | window_name = "Theory model" |
---|
| 29 | ## Title to appear on top of the window |
---|
| 30 | window_caption = "Theory Model" |
---|
[0277d084] | 31 | def __init__(self,parent, page_info, model_list_box): |
---|
| 32 | BasicPage.__init__(self, parent, page_info , model_list_box) |
---|
| 33 | """ |
---|
| 34 | Initialization of the Panel |
---|
| 35 | """ |
---|
| 36 | self._fill_model_sizer( self.sizer1) |
---|
| 37 | self._fill_range_sizer() |
---|
| 38 | self.engine_type = None |
---|
| 39 | |
---|
| 40 | description="" |
---|
| 41 | if self.model!=None: |
---|
| 42 | |
---|
| 43 | description = self.model.description |
---|
| 44 | |
---|
| 45 | self.select_model(self.model) |
---|
| 46 | self.set_model_description(description,self.sizer2) |
---|
| 47 | |
---|
| 48 | def _on_display_description(self, event): |
---|
| 49 | """ |
---|
| 50 | Show or Hide description |
---|
| 51 | @param event: wx.EVT_RADIOBUTTON |
---|
| 52 | """ |
---|
| 53 | self._on_display_description_helper() |
---|
| 54 | |
---|
| 55 | self.SetScrollbars(20,20,25,65) |
---|
| 56 | self.Refresh() |
---|
| 57 | |
---|
| 58 | def _on_display_description_helper(self): |
---|
| 59 | """ |
---|
| 60 | Show or Hide description |
---|
| 61 | @param event: wx.EVT_RADIOBUTTON |
---|
| 62 | """ |
---|
| 63 | ## Show description |
---|
| 64 | if self.description_hide.GetValue(): |
---|
| 65 | self.sizer_description.Clear(True) |
---|
| 66 | |
---|
| 67 | else: |
---|
| 68 | description="Model contains no description" |
---|
| 69 | if self.model!=None: |
---|
| 70 | description = self.model.description |
---|
| 71 | if description.lstrip().rstrip() =="": |
---|
| 72 | description="Model contains no description" |
---|
| 73 | self.description = wx.StaticText( self,-1,str(description) ) |
---|
| 74 | self.sizer_description.Add( self.description, 1, wx.EXPAND | wx.ALL, 10 ) |
---|
| 75 | |
---|
| 76 | self.Layout() |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | def _fill_range_sizer(self): |
---|
| 80 | """ |
---|
| 81 | Fill the sizer containing the plotting range |
---|
| 82 | add access to npts |
---|
| 83 | """ |
---|
| 84 | ##The following 3 lines are for Mac. Let JHC know before modifying.. |
---|
| 85 | title = "Plotted Q Range" |
---|
| 86 | box_description= wx.StaticBox(self, -1,str(title)) |
---|
| 87 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 88 | |
---|
| 89 | sizer_npts= wx.GridSizer(1, 1,5, 5) |
---|
| 90 | self.npts = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
| 91 | self.npts.SetValue(format_number(self.num_points)) |
---|
| 92 | self.npts.SetToolTipString("Number of point to plot.") |
---|
| 93 | |
---|
| 94 | sizer_npts.Add(wx.StaticText(self, -1, 'Npts'),1, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 13) |
---|
| 95 | |
---|
| 96 | sizer_npts.Add(self.npts,1,wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
| 97 | self._set_range_sizer( title=title, box_sizer=boxsizer1, object= sizer_npts) |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | def _on_select_model(self, event): |
---|
| 101 | """ |
---|
| 102 | call back for model selection |
---|
| 103 | """ |
---|
| 104 | self._on_select_model_helper() |
---|
| 105 | #Reset dispersity that was not done in _on_select_model_helper() |
---|
| 106 | self._reset_dispersity() |
---|
| 107 | self.select_model(self.model) |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | def _fill_model_sizer(self, sizer): |
---|
| 111 | """ |
---|
| 112 | fill sizer containing model info |
---|
| 113 | """ |
---|
| 114 | ##The following 3 lines are for Mac. Let JHC know before modifying.. |
---|
| 115 | title = "Model" |
---|
| 116 | box_description= wx.StaticBox(self, -1,str(title)) |
---|
| 117 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 118 | |
---|
| 119 | id = wx.NewId() |
---|
| 120 | self.model_view =wx.Button(self,id,'View 2D', size=(80,23)) |
---|
| 121 | self.model_view.Bind(wx.EVT_BUTTON, self._onModel2D,id=id) |
---|
| 122 | self.model_view.SetToolTipString("View model in 2D") |
---|
| 123 | |
---|
| 124 | ## class base method to add view 2d button |
---|
| 125 | self._set_model_sizer(sizer=sizer,box_sizer=boxsizer1, title=title,object= self.model_view ) |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | #def _set_sizer_gaussian(self): |
---|
| 129 | def _set_sizer_dispersion(self, dispersity): |
---|
| 130 | """ |
---|
| 131 | draw sizer with gaussian, log or schulz dispersity parameters |
---|
| 132 | """ |
---|
| 133 | self.fittable_param=[] |
---|
| 134 | self.fixed_param=[] |
---|
| 135 | self.orientation_params_disp=[] |
---|
| 136 | #self.temp=[] |
---|
| 137 | |
---|
| 138 | self.sizer4_4.Clear(True) |
---|
| 139 | if self.model==None: |
---|
| 140 | ##no model is selected |
---|
| 141 | return |
---|
| 142 | if not self.enable_disp.GetValue(): |
---|
| 143 | ## the user didn't select dispersity display |
---|
| 144 | return |
---|
| 145 | self._reset_dispersity() |
---|
| 146 | # Create the dispersion objects |
---|
| 147 | for item in self.model.dispersion.keys(): |
---|
| 148 | #disp_model = GaussianDispersion() |
---|
| 149 | disp_model = dispersity() |
---|
| 150 | self._disp_obj_dict[item] = disp_model |
---|
| 151 | self.model.set_dispersion(item, disp_model) |
---|
| 152 | self.state._disp_obj_dict[item]= disp_model |
---|
| 153 | |
---|
| 154 | |
---|
| 155 | ix=0 |
---|
| 156 | iy=1 |
---|
[52efcc5] | 157 | disp = wx.StaticText(self, -1, ' ') |
---|
[0277d084] | 158 | self.sizer4_4.Add(disp,( iy, ix),(1,1), |
---|
| 159 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 160 | ix += 1 |
---|
[52efcc5] | 161 | values = wx.StaticText(self, -1, 'Sigma (STD)') |
---|
[1a94c36] | 162 | values.SetToolTipString("Polydispersity multiplied by the value of the original parameter.") |
---|
[0277d084] | 163 | self.sizer4_4.Add(values,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 164 | |
---|
| 165 | ix += 1 |
---|
| 166 | npts = wx.StaticText(self, -1, 'Npts') |
---|
[1a94c36] | 167 | npts.SetToolTipString("Number of points for weighting.") |
---|
[0277d084] | 168 | self.sizer4_4.Add(npts,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 169 | ix += 1 |
---|
| 170 | nsigmas = wx.StaticText(self, -1, 'Nsigmas') |
---|
[1a94c36] | 171 | nsigmas.SetToolTipString("Number of sigmas between which the range of the distribution function will be used for weighting. The value '3' covers 99.5% for Gaussian distribution function.") |
---|
[0277d084] | 172 | self.sizer4_4.Add(nsigmas,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 173 | |
---|
| 174 | for item in self.model.dispersion.keys(): |
---|
| 175 | if not item in self.model.orientation_params: |
---|
| 176 | self.disp_cb_dict[item]= None |
---|
| 177 | name1=item+".width" |
---|
| 178 | name2=item+".npts" |
---|
| 179 | name3=item+".nsigmas" |
---|
| 180 | iy += 1 |
---|
| 181 | for p in self.model.dispersion[item].keys(): |
---|
| 182 | if p=="width": |
---|
| 183 | ix = 0 |
---|
| 184 | name = wx.StaticText(self, -1, name1) |
---|
| 185 | self.sizer4_4.Add( name,( iy, ix),(1,1), |
---|
| 186 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 187 | ix = 1 |
---|
| 188 | value= self.model.getParam(name1) |
---|
| 189 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
| 190 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 191 | ctl1.SetToolTipString("Polydispersity multiplied by the value of the '%s'."%item) |
---|
[0277d084] | 192 | ctl1.SetValue(str (format_number(value))) |
---|
| 193 | self.sizer4_4.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 194 | self.fittable_param.append([None,name1,ctl1,None, |
---|
| 195 | None, None, None,None]) |
---|
| 196 | elif p=="npts": |
---|
| 197 | ix =2 |
---|
| 198 | value= self.model.getParam(name2) |
---|
| 199 | Tctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
| 200 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 201 | |
---|
[0277d084] | 202 | Tctl1.SetValue(str (format_number(value))) |
---|
| 203 | self.sizer4_4.Add(Tctl1, (iy,ix),(1,1), |
---|
| 204 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 205 | self.fixed_param.append([None,name2, Tctl1,None,None, |
---|
| 206 | None, None,None]) |
---|
| 207 | elif p=="nsigmas": |
---|
| 208 | ix =3 |
---|
| 209 | value= self.model.getParam(name3) |
---|
| 210 | Tctl2 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
| 211 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 212 | |
---|
[0277d084] | 213 | Tctl2.SetValue(str (format_number(value))) |
---|
| 214 | self.sizer4_4.Add(Tctl2, (iy,ix),(1,1), |
---|
| 215 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 216 | ix +=1 |
---|
| 217 | self.sizer4_4.Add((20,20), (iy,ix),(1,1), |
---|
| 218 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 219 | self.fixed_param.append([None,name3, Tctl2, |
---|
| 220 | None,None, None, None,None]) |
---|
| 221 | for item in self.model.dispersion.keys(): |
---|
| 222 | if item in self.model.orientation_params: |
---|
| 223 | self.disp_cb_dict[item]= None |
---|
| 224 | name1=item+".width" |
---|
| 225 | name2=item+".npts" |
---|
| 226 | name3=item+".nsigmas" |
---|
| 227 | iy += 1 |
---|
| 228 | for p in self.model.dispersion[item].keys(): |
---|
| 229 | if p=="width": |
---|
| 230 | ix = 0 |
---|
| 231 | name = wx.StaticText(self, -1, name1) |
---|
| 232 | self.sizer4_4.Add( name,( iy, ix),(1,1), |
---|
| 233 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 234 | if not self.enable2D: |
---|
| 235 | name.Hide() |
---|
| 236 | else: |
---|
| 237 | name.Show(True) |
---|
| 238 | ix = 1 |
---|
| 239 | value= self.model.getParam(name1) |
---|
| 240 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
| 241 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 242 | ctl1.SetToolTipString("Polydispersity multiplied by the value of '%s'."%item) |
---|
[0277d084] | 243 | ctl1.SetValue(str (format_number(value))) |
---|
| 244 | if not self.enable2D: |
---|
| 245 | ctl1.Hide() |
---|
| 246 | ctl1.Disable() |
---|
| 247 | else: |
---|
| 248 | ctl1.Show(True) |
---|
| 249 | ctl1.Enable() |
---|
| 250 | self.sizer4_4.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 251 | self.fittable_param.append([None,name1,ctl1,None, |
---|
| 252 | None, None, None,None]) |
---|
| 253 | self.orientation_params_disp.append([None,name1,ctl1,None, |
---|
| 254 | None, None, None,None]) |
---|
| 255 | elif p=="npts": |
---|
| 256 | ix =2 |
---|
| 257 | value= self.model.getParam(name2) |
---|
| 258 | Tctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
| 259 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 260 | |
---|
[0277d084] | 261 | Tctl1.SetValue(str (format_number(value))) |
---|
| 262 | if not self.enable2D: |
---|
| 263 | Tctl1.Hide() |
---|
| 264 | Tctl1.Disable() |
---|
| 265 | else: |
---|
| 266 | Tctl1.Show(True) |
---|
| 267 | Tctl1.Enable() |
---|
| 268 | self.sizer4_4.Add(Tctl1, (iy,ix),(1,1), |
---|
| 269 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 270 | self.fixed_param.append([None,name2, Tctl1,None,None, |
---|
| 271 | None, None,None]) |
---|
| 272 | self.orientation_params_disp.append([None,name2, Tctl1,None,None, |
---|
| 273 | None, None,None]) |
---|
| 274 | elif p=="nsigmas": |
---|
| 275 | ix =3 |
---|
| 276 | value= self.model.getParam(name3) |
---|
| 277 | Tctl2 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
| 278 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 279 | |
---|
[0277d084] | 280 | Tctl2.SetValue(str (format_number(value))) |
---|
| 281 | if not self.enable2D: |
---|
| 282 | Tctl2.Hide() |
---|
| 283 | Tctl2.Disable() |
---|
| 284 | else: |
---|
| 285 | Tctl2.Show(True) |
---|
| 286 | Tctl2.Enable() |
---|
| 287 | self.sizer4_4.Add(Tctl2, (iy,ix),(1,1), |
---|
| 288 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 289 | ix +=1 |
---|
| 290 | #self.sizer4_4.Add((20,20), (iy,ix),(1,1), |
---|
| 291 | #wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 292 | self.fixed_param.append([None,name3, Tctl2, |
---|
| 293 | None,None, None, None,None]) |
---|
| 294 | self.orientation_params_disp.append([None,name3, Tctl2, |
---|
| 295 | None,None, None, None,None]) |
---|
| 296 | |
---|
| 297 | msg = " Selected Distribution: Gaussian" |
---|
| 298 | wx.PostEvent(self.parent, StatusEvent( status= msg )) |
---|
| 299 | self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict) |
---|
| 300 | ix =0 |
---|
| 301 | iy +=1 |
---|
| 302 | #self.sizer4_4.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 303 | self.sizer4_4.Layout() |
---|
| 304 | self.sizer4.Layout() |
---|
| 305 | self.SetScrollbars(20,20,25,65) |
---|
| 306 | |
---|
| 307 | |
---|
| 308 | def _onModel2D(self, event): |
---|
| 309 | """ |
---|
| 310 | call manager to plot model in 2D |
---|
| 311 | """ |
---|
| 312 | # If the 2D display is not currently enabled, plot the model in 2D |
---|
| 313 | # and set the enable2D flag. |
---|
| 314 | |
---|
| 315 | if self.fitrange: |
---|
| 316 | self.enable2D = True |
---|
| 317 | |
---|
| 318 | if self.enable2D: |
---|
| 319 | self._draw_model() |
---|
| 320 | self.model_view.Disable() |
---|
| 321 | |
---|
| 322 | n = self.disp_box.GetCurrentSelection() |
---|
| 323 | dispersity= self.disp_box.GetClientData(n) |
---|
| 324 | #TODO:Find a better way to reinitialize the parameters containers |
---|
| 325 | # when resetting the page and 2D view is enable |
---|
| 326 | #self.set_model_param_sizer(self.model): called here is using a lot |
---|
| 327 | #of for loops and redraw the sizer again .How to avoid it? |
---|
| 328 | self.set_model_param_sizer(self.model) |
---|
| 329 | |
---|
| 330 | if len(self.orientation_params)>0: |
---|
| 331 | for item in self.orientation_params: |
---|
| 332 | if item[2]!=None: |
---|
| 333 | item[2].Enable() |
---|
| 334 | # same as above why do we have to redraw the sizer of dispersity to get |
---|
| 335 | # the appropriate value of parameters containers on reset page? |
---|
| 336 | # Reset containers of dispersity parameters for the appropriate dispersity |
---|
| 337 | #and model |
---|
| 338 | if self.disp_name.lower()in ["array","arraydispersion"]: |
---|
| 339 | self._set_sizer_arraydispersion() |
---|
| 340 | else: |
---|
| 341 | self._set_sizer_dispersion(dispersity) |
---|
| 342 | if len(self.orientation_params_disp)>0: |
---|
| 343 | |
---|
| 344 | for item in self.orientation_params_disp: |
---|
| 345 | if item[2]!=None: |
---|
| 346 | item[2].Enable() |
---|
| 347 | |
---|
| 348 | self.state.enable2D = copy.deepcopy(self.enable2D) |
---|
| 349 | self.Layout() |
---|
| 350 | ## post state to fit panel |
---|
| 351 | #self._undo.Enable(True) |
---|
| 352 | event = PageInfoEvent(page = self) |
---|
| 353 | wx.PostEvent(self.parent, event) |
---|
| 354 | |
---|
| 355 | |
---|
| 356 | def reset_page(self, state): |
---|
| 357 | """ |
---|
| 358 | reset the state |
---|
| 359 | """ |
---|
| 360 | self.reset_page_helper(state) |
---|
| 361 | |
---|
| 362 | |
---|
| 363 | def select_model(self, model): |
---|
| 364 | """ |
---|
| 365 | Select a new model |
---|
| 366 | @param model: model object |
---|
| 367 | """ |
---|
| 368 | self.model = model |
---|
| 369 | if self.model !=None: |
---|
| 370 | self.disp_list= self.model.getDispParamList() |
---|
| 371 | self.set_model_param_sizer(self.model) |
---|
| 372 | ## keep the sizer view consistent with the model menu selecting |
---|
| 373 | self._set_model_sizer_selection( self.model ) |
---|
| 374 | self.enable_disp.SetValue(False) |
---|
| 375 | self.disable_disp.SetValue(True) |
---|
| 376 | self.set_dispers_sizer() |
---|
| 377 | |
---|
| 378 | self.model_view.SetFocus() |
---|
| 379 | if self.model !=None: |
---|
| 380 | self._draw_model() |
---|
| 381 | self.state.structurecombobox = self.structurebox.GetCurrentSelection() |
---|
| 382 | self.state.formfactorcombobox = self.formfactorbox.GetCurrentSelection() |
---|
| 383 | |
---|
| 384 | ## post state to fit panel |
---|
| 385 | #self._undo.Enable(True) |
---|
| 386 | event = PageInfoEvent(page = self) |
---|
| 387 | wx.PostEvent(self.parent, event) |
---|
| 388 | |
---|
| 389 | |
---|
| 390 | def set_model_description(self,description,sizer): |
---|
| 391 | """ |
---|
| 392 | fill a sizer with description |
---|
| 393 | @param description: of type string |
---|
| 394 | @param sizer: wx.BoxSizer() |
---|
| 395 | """ |
---|
| 396 | |
---|
| 397 | sizer.Clear(True) |
---|
| 398 | box_description= wx.StaticBox(self, -1, 'Model Description') |
---|
| 399 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 400 | |
---|
| 401 | sizer_selection=wx.BoxSizer(wx.HORIZONTAL) |
---|
| 402 | self.description_hide = wx.RadioButton(self, -1, 'Hide', style=wx.RB_GROUP) |
---|
| 403 | self.description_show = wx.RadioButton(self, -1, 'Show') |
---|
| 404 | |
---|
| 405 | |
---|
| 406 | if description=="": |
---|
| 407 | self.description_hide.SetValue(True) |
---|
| 408 | description=" Description unavailable. Click for details" |
---|
| 409 | |
---|
| 410 | self.description = wx.StaticText( self,-1,str(description) ) |
---|
| 411 | |
---|
| 412 | self.Bind( wx.EVT_RADIOBUTTON, self._on_display_description, |
---|
| 413 | id=self.description_hide.GetId() ) |
---|
| 414 | |
---|
| 415 | self.Bind( wx.EVT_RADIOBUTTON, self._on_display_description, |
---|
| 416 | id=self.description_show.GetId() ) |
---|
| 417 | #MAC needs SetValue |
---|
| 418 | self.description_hide.SetValue(True) |
---|
| 419 | |
---|
| 420 | self.model_description = wx.Button(self,-1, label="Details", size=(80,23)) |
---|
| 421 | |
---|
| 422 | self.model_description.Bind(wx.EVT_BUTTON,self.on_button_clicked) |
---|
| 423 | self.model_description.SetToolTipString("Click Model Functions in HelpWindow...") |
---|
| 424 | self.model_description.SetFocus() |
---|
| 425 | sizer_selection.Add( self.description_show ) |
---|
| 426 | sizer_selection.Add( (20,20)) |
---|
| 427 | sizer_selection.Add( self.description_hide ) |
---|
| 428 | sizer_selection.Add((20,20),0, wx.LEFT|wx.RIGHT|wx.EXPAND,75) |
---|
| 429 | sizer_selection.Add( self.model_description ) |
---|
| 430 | |
---|
| 431 | |
---|
| 432 | self.sizer_description=wx.BoxSizer(wx.HORIZONTAL) |
---|
| 433 | self.sizer_description.Add( self.description, 1, wx.EXPAND | wx.ALL, 10 ) |
---|
| 434 | boxsizer1.Add( sizer_selection) |
---|
| 435 | boxsizer1.Add( (20,20)) |
---|
| 436 | boxsizer1.Add( self.sizer_description) |
---|
| 437 | |
---|
| 438 | self._on_display_description(event=None) |
---|
| 439 | sizer.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 440 | sizer.Layout() |
---|
| 441 | |
---|
| 442 | def on_button_clicked(self,event): |
---|
| 443 | """ |
---|
| 444 | #On 'More details' button |
---|
| 445 | """ |
---|
| 446 | from help_panel import HelpWindow |
---|
| 447 | |
---|
| 448 | if self.model == None: |
---|
| 449 | name = 'FuncHelp' |
---|
| 450 | else: |
---|
| 451 | name = self.model.name |
---|
[e071b1c] | 452 | frame = HelpWindow(None, -1, pageToOpen="media/model_functions.html") |
---|
[0277d084] | 453 | frame.Show(True) |
---|
| 454 | if frame.rhelp.HasAnchor(name): |
---|
| 455 | frame.rhelp.ScrollToAnchor(name) |
---|
| 456 | else: |
---|
| 457 | msg= "Model does not contains an available description " |
---|
| 458 | msg +="Please.Search in the Help window" |
---|
| 459 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
| 460 | |
---|
| 461 | |
---|
| 462 | |
---|
| 463 | def set_range(self, qmin_x, qmax_x, npts): |
---|
| 464 | """ |
---|
| 465 | Set the range for the plotted models |
---|
| 466 | @param qmin: minimum Q |
---|
| 467 | @param qmax: maximum Q |
---|
| 468 | @param npts: number of Q bins |
---|
| 469 | """ |
---|
| 470 | # Set the data members |
---|
| 471 | self.qmin_x = qmin_x |
---|
| 472 | self.qmax_x = qmax_x |
---|
| 473 | self.num_points = npts |
---|
| 474 | |
---|
| 475 | # Set the controls |
---|
| 476 | #For qmin and qmax, do not use format_number.(If do, qmin and max could be different from what is in the data.) |
---|
| 477 | |
---|
| 478 | self.qmin.SetValue(str(self.qmin_x)) |
---|
| 479 | self.qmax.SetValue(str(self.qmax_x)) |
---|
| 480 | self.npts.SetValue(format_number(self.num_points)) |
---|
| 481 | |
---|
| 482 | |
---|
| 483 | def set_model_param_sizer(self, model): |
---|
| 484 | """ |
---|
| 485 | Build the panel from the model content |
---|
| 486 | @param model: the model selected in combo box for fitting purpose |
---|
| 487 | """ |
---|
| 488 | self.sizer3.Clear(True) |
---|
| 489 | self.parameters = [] |
---|
| 490 | self.param_toFit=[] |
---|
| 491 | self.fixed_param=[] |
---|
| 492 | self.orientation_params=[] |
---|
| 493 | self.orientation_params_disp=[] |
---|
| 494 | #self.temp=[] |
---|
| 495 | if model ==None: |
---|
| 496 | ##no model avaiable to draw sizer |
---|
| 497 | self.sizer3.Layout() |
---|
| 498 | self.SetScrollbars(20,20,25,65) |
---|
| 499 | return |
---|
| 500 | box_description= wx.StaticBox(self, -1,str("Model Parameters")) |
---|
| 501 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 502 | sizer = wx.GridBagSizer(5,5) |
---|
| 503 | |
---|
| 504 | self.model = model |
---|
| 505 | self.set_model_description(self.model.description,self.sizer2) |
---|
| 506 | |
---|
| 507 | keys = self.model.getParamList() |
---|
| 508 | ##list of dispersion parameters |
---|
| 509 | self.disp_list=self.model.getDispParamList() |
---|
| 510 | |
---|
| 511 | keys.sort() |
---|
| 512 | |
---|
| 513 | iy = 0 |
---|
| 514 | ix = 0 |
---|
| 515 | self.text1_2 = wx.StaticText(self, -1, 'Names') |
---|
| 516 | sizer.Add(self.text1_2,(iy, ix),(1,1),\ |
---|
| 517 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 518 | ix +=1 |
---|
| 519 | self.text2_2 = wx.StaticText(self, -1, 'Values') |
---|
| 520 | sizer.Add(self.text2_2,(iy, ix),(1,1),\ |
---|
| 521 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 522 | ix +=1 |
---|
| 523 | self.text2_4 = wx.StaticText(self, -1, '[Units]') |
---|
| 524 | sizer.Add(self.text2_4,(iy, ix),(1,1),\ |
---|
| 525 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 526 | self.text2_4.Hide() |
---|
| 527 | |
---|
| 528 | for item in keys: |
---|
| 529 | if not item in self.disp_list and not item in self.model.orientation_params: |
---|
| 530 | iy += 1 |
---|
| 531 | ix = 0 |
---|
| 532 | name = wx.StaticText(self, -1,item) |
---|
| 533 | sizer.Add( name,( iy, ix),(1,1), |
---|
| 534 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 535 | |
---|
| 536 | ix += 1 |
---|
| 537 | value= self.model.getParam(item) |
---|
| 538 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
| 539 | style=wx.TE_PROCESS_ENTER) |
---|
| 540 | |
---|
| 541 | ctl1.SetValue(str (format_number(value))) |
---|
| 542 | |
---|
| 543 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 544 | ix +=1 |
---|
| 545 | # Units |
---|
| 546 | if self.model.details.has_key(item): |
---|
| 547 | units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
| 548 | else: |
---|
| 549 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
| 550 | sizer.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 551 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
| 552 | self.parameters.append([None,item, ctl1, |
---|
| 553 | None,None, None, None,None]) |
---|
| 554 | iy+=1 |
---|
| 555 | sizer.Add((10,10),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 556 | iy += 1 |
---|
| 557 | ix = 0 |
---|
| 558 | |
---|
| 559 | #Add tile for orientational angle parameters |
---|
| 560 | for item in keys: |
---|
| 561 | if item in self.model.orientation_params: |
---|
| 562 | orient_angle = wx.StaticText(self, -1, '[For 2D only]:') |
---|
| 563 | sizer.Add(orient_angle,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 564 | if not self.enable2D: |
---|
| 565 | orient_angle.Hide() |
---|
| 566 | else: |
---|
| 567 | orient_angle.Show(True) |
---|
| 568 | break |
---|
| 569 | |
---|
| 570 | for item in self.model.orientation_params: |
---|
| 571 | if not item in self.disp_list and item in keys: |
---|
| 572 | iy += 1 |
---|
| 573 | ix = 0 |
---|
| 574 | name = wx.StaticText(self, -1,item) |
---|
| 575 | sizer.Add( name,( iy, ix),(1,1), |
---|
| 576 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 577 | if not self.enable2D: |
---|
| 578 | name.Hide() |
---|
| 579 | else: |
---|
| 580 | name.Show(True) |
---|
| 581 | |
---|
| 582 | ix += 1 |
---|
| 583 | value= self.model.getParam(item) |
---|
| 584 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
| 585 | style=wx.TE_PROCESS_ENTER) |
---|
| 586 | |
---|
| 587 | ctl1.SetValue(str (format_number(value))) |
---|
| 588 | if not self.enable2D: |
---|
| 589 | ctl1.Hide() |
---|
| 590 | ctl1.Disable() |
---|
| 591 | else: |
---|
| 592 | ctl1.Show(True) |
---|
| 593 | ctl1.Enable() |
---|
| 594 | |
---|
| 595 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 596 | ix +=1 |
---|
| 597 | # Units |
---|
| 598 | if self.model.details.has_key(item): |
---|
| 599 | units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
| 600 | else: |
---|
| 601 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
| 602 | if not self.enable2D: |
---|
| 603 | units.Hide() |
---|
| 604 | else: |
---|
| 605 | units.Show(True) |
---|
| 606 | |
---|
| 607 | sizer.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 608 | #Save 2D orient. params |
---|
| 609 | #self.temp.append([name,ctl1,units,orient_angle]) |
---|
| 610 | |
---|
| 611 | |
---|
| 612 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
| 613 | self.parameters.append([None,item, ctl1, |
---|
| 614 | None,None, None, None,None]) |
---|
| 615 | self.orientation_params.append([None,item, ctl1, |
---|
[199cef2] | 616 | None,None, None, None,None]) |
---|
| 617 | iy += 1 |
---|
[0277d084] | 618 | |
---|
| 619 | #Display units text on panel |
---|
| 620 | for item in keys: |
---|
| 621 | self.text2_4.Show() |
---|
| 622 | |
---|
| 623 | boxsizer1.Add(sizer) |
---|
| 624 | self.sizer3.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 625 | self.sizer3.Layout() |
---|
| 626 | self.SetScrollbars(20,20,25,65) |
---|
| 627 | |
---|