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