Changeset 28ea782 in sasview
- Timestamp:
- Mar 11, 2009 5:05:09 PM (16 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- b2f5bcb
- Parents:
- 6df36b3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/models.py
r8346667 r28ea782 66 66 pass 67 67 return plugins 68 69 68 70 class ModelManager: 69 70 ## Dictionary of models 71 model_list = {} 72 indep_model_list = {} 73 model_list_box = {} 74 custom_models={} 71 ## external dict for models 72 form_factor_dict_for_combox = {} 73 ## Dictionary of form models 74 form_factor_dict = {} 75 ## dictionary of other 76 struct_factor_dict = {} 77 ##list of form factors 78 shape_list =[] 79 ## independent shape model list 80 shape_indep_list = [] 81 ##list of structure factors 82 struct_list= [] 83 ## list of added models 75 84 plugins=[] 76 indep_model=[] 77 ## Event owner 85 ## Event owner (guiframe) 78 86 event_owner = None 79 87 … … 86 94 @return: the next free event ID following the new menu events 87 95 """ 88 self.model_list = {} 89 self.model_list_box = {} 90 91 96 ## form factor 92 97 from sans.models.SphereModel import SphereModel 93 self. model_list[str(wx.NewId())] = SphereModel98 self.shape_list.append(SphereModel) 94 99 95 100 from sans.models.CylinderModel import CylinderModel 96 self. model_list[str(wx.NewId())] =CylinderModel101 self.shape_list.append(CylinderModel) 97 102 98 103 from sans.models.CoreShellModel import CoreShellModel 99 self. model_list[str(wx.NewId())] = CoreShellModel104 self.shape_list.append(CoreShellModel) 100 105 101 106 from sans.models.CoreShellCylinderModel import CoreShellCylinderModel 102 self. model_list[str(wx.NewId())] =CoreShellCylinderModel107 self.shape_list.append(CoreShellCylinderModel) 103 108 104 109 from sans.models.EllipticalCylinderModel import EllipticalCylinderModel 105 self. model_list[str(wx.NewId())] =EllipticalCylinderModel110 self.shape_list.append(EllipticalCylinderModel) 106 111 107 112 from sans.models.EllipsoidModel import EllipsoidModel 108 self.model_list[str(wx.NewId())] = EllipsoidModel 113 self.shape_list.append(EllipsoidModel) 114 115 from sans.models.LineModel import LineModel 116 self.shape_list.append(LineModel) 117 118 ## Structure factor 119 from sans.models.NoStructure import NoStructure 120 self.struct_list.append(NoStructure) 109 121 110 122 from sans.models.SquareWellStructure import SquareWellStructure 111 self. model_list[str(wx.NewId())] = SquareWellStructure123 self.struct_list.append(SquareWellStructure) 112 124 113 125 from sans.models.HardsphereStructure import HardsphereStructure 114 self. model_list[str(wx.NewId())] = HardsphereStructure115 126 self.struct_list.append(HardsphereStructure) 127 116 128 from sans.models.StickyHSStructure import StickyHSStructure 117 self. model_list[str(wx.NewId())] = StickyHSStructure129 self.struct_list.append(StickyHSStructure) 118 130 119 131 from sans.models.HayterMSAStructure import HayterMSAStructure 120 self.model_list[str(wx.NewId())] = HayterMSAStructure 121 122 from sans.models.LineModel import LineModel 123 self.model_list[str(wx.NewId())] = LineModel 124 125 126 model_info="shape-independent models" 127 132 self.struct_list.append(HayterMSAStructure) 133 134 135 ##shape-independent models 128 136 from sans.models.BEPolyelectrolyte import BEPolyelectrolyte 129 self. indep_model.append(BEPolyelectrolyte )130 137 self.shape_indep_list.append(BEPolyelectrolyte ) 138 self.form_factor_dict[str(wx.NewId())] = [SphereModel] 131 139 from sans.models.DABModel import DABModel 132 self. indep_model.append(DABModel )140 self.shape_indep_list.append(DABModel ) 133 141 134 142 from sans.models.GuinierModel import GuinierModel 135 self. indep_model.append(GuinierModel )143 self.shape_indep_list.append(GuinierModel ) 136 144 137 145 from sans.models.DebyeModel import DebyeModel 138 self.indep_model.append(DebyeModel ) 146 self.shape_indep_list.append(DebyeModel ) 147 148 from sans.models.PorodModel import PorodModel 149 self.shape_indep_list.append(PorodModel ) 139 150 140 151 from sans.models.FractalModel import FractalModel … … 142 153 def _Fractal(self, x): 143 154 return FractalModel._Fractal(self, math.fabs(x)) 144 self. indep_model.append(FractalAbsModel)155 self.shape_indep_list.append(FractalAbsModel) 145 156 146 157 from sans.models.LorentzModel import LorentzModel 147 self. indep_model.append( LorentzModel)158 self.shape_indep_list.append( LorentzModel) 148 159 149 160 from sans.models.PowerLawModel import PowerLawModel … … 154 165 except: 155 166 print sys.exc_value 156 self. indep_model.append( PowerLawAbsModel )167 self.shape_indep_list.append( PowerLawAbsModel ) 157 168 from sans.models.TeubnerStreyModel import TeubnerStreyModel 158 self. indep_model.append(TeubnerStreyModel )169 self.shape_indep_list.append(TeubnerStreyModel ) 159 170 160 171 #Looking for plugins … … 173 184 @return: the next free event ID following the new menu events 174 185 """ 186 ## Fill model lists 175 187 self._getModelList() 188 ## store reference to model menu of guiframe 189 self.modelmenu = modelmenu 190 ## guiframe reference 176 191 self.event_owner = event_owner 177 shape_submenu= wx.Menu() 178 indep_submenu = wx.Menu() 192 193 194 shape_submenu = wx.Menu() 195 shape_indep_submenu = wx.Menu() 196 structure_factor = wx.Menu() 179 197 added_models = wx.Menu() 180 for id_str,value in self.model_list.iteritems(): 181 item = self.model_list[id_str]() 182 name = item.__class__.__name__ 183 if hasattr(item, "name"): 184 name = item.name 185 self.model_list_box[name] =value 186 shape_submenu.Append(int(id_str), name, name) 187 wx.EVT_MENU(event_owner, int(id_str), self._on_model) 188 modelmenu.AppendMenu(wx.NewId(), "Shapes...", shape_submenu, "List of shape-based models") 189 id = wx.NewId() 190 if len(self.indep_model_list) == 0: 191 for items in self.indep_model: 192 #if item not in self.indep_model_list.values(): 193 #self.indep_model_list[str(id)] = item 194 self.model_list[str(id)]=items 195 item=items() 196 name = item.__class__.__name__ 197 if hasattr(item, "name"): 198 name = item.name 199 indep_submenu.Append(id,name, name) 200 self.model_list_box[name] =items 201 wx.EVT_MENU(event_owner, int(id), self._on_model) 202 id = wx.NewId() 203 modelmenu.AppendMenu(wx.NewId(), "Shape-independent...", indep_submenu, "List of shape-independent models") 204 id = wx.NewId() 205 if len(self.custom_models) == 0: 206 for items in self.plugins: 207 #if item not in self.custom_models.values(): 208 #self.custom_models[str(id)] = item 209 self.model_list[str(id)]=items 210 name = items.__name__ 211 if hasattr(items, "name"): 212 name = items.name 213 added_models.Append(id, name, name) 214 self.model_list_box[name] =items 215 wx.EVT_MENU(event_owner, int(id), self._on_model) 216 id = wx.NewId() 217 modelmenu.AppendMenu(wx.NewId(),"Added models...", added_models, "List of additional models") 198 ## create menu with shape 199 self._fill_menu( menuinfo = ["shapes...",shape_submenu," simple shape"], 200 list1 = self.shape_list, 201 list2 = self.struct_list ) 202 self._fill_menu( menuinfo = ["Shape-independent...",shape_indep_submenu, 203 "List of shape-independent models"], 204 list1 = self.shape_indep_list, 205 list2 = self.struct_list ) 206 207 self._fill_simple_menu( menuinfo= ["Structure Factors...",structure_factor, 208 "List of Structure factors models" ], 209 list1= self.struct_list ) 210 211 self._fill_simple_menu( menuinfo = ["Added models...", added_models, 212 "List of additional models"], 213 list1= self.plugins) 218 214 return 0 219 215 216 def _fill_simple_menu(self,menuinfo, list1): 217 """ 218 Fill the menu with list item 219 @param modelmenu: the menu to fill 220 @param menuinfo: submenu item for the first column of this modelmenu 221 with info.Should be a list : 222 [name(string) , menu(wx.menu), help(string)] 223 @param list1: contains item (form factor )to fill modelmenu second column 224 """ 225 if len(list1)>0: 226 for item in list1: 227 id = wx.NewId() 228 if not item in self.form_factor_dict_for_combox.itervalues(): 229 self.form_factor_dict_for_combox[int(id)] =item 230 struct_factor=item() 231 struct_name = struct_factor.__class__.__name__ 232 if hasattr(struct_factor, "name"): 233 struct_name = struct_factor.name 234 235 menuinfo[1].Append(int(id),struct_name,struct_name) 236 if not item in self.struct_factor_dict.itervalues(): 237 self.struct_factor_dict[str(id)]= item 238 wx.EVT_MENU(self.event_owner, int(id), self._on_model) 239 240 id = wx.NewId() 241 self.modelmenu.AppendMenu(id, menuinfo[0],menuinfo[1],menuinfo[2]) 242 243 244 245 def _fill_menu(self,menuinfo, list1,list2 ): 246 """ 247 Fill the menu with list item 248 @param menuinfo: submenu item for the first column of this modelmenu 249 with info.Should be a list : 250 [name(string) , menu(wx.menu), help(string)] 251 @param list1: contains item (form factor )to fill modelmenu second column 252 @param list2: contains item (Structure factor )to fill modelmenu third column 253 """ 254 for item in list1: 255 256 form_factor= item() 257 form_name = form_factor.__class__.__name__ 258 if hasattr(form_factor, "name"): 259 form_name = form_factor.name 260 ### store form factor to return to other users 261 newmenu= wx.Menu() 262 if len(list2)>0: 263 for model in list2: 264 id = wx.NewId() 265 struct_factor = model() 266 name = struct_factor.__class__.__name__ 267 if hasattr(struct_factor, "name"): 268 name = struct_factor.name 269 newmenu.Append(id,name, name) 270 wx.EVT_MENU(self.event_owner, int(id), self._on_model) 271 ## save form_fact and struct_fact 272 self.form_factor_dict[int(id)] = [form_factor,struct_factor] 273 274 if not item in self.form_factor_dict_for_combox.itervalues(): 275 self.form_factor_dict_for_combox[int(id)] =item 276 277 form_id= wx.NewId() 278 menuinfo[1].AppendMenu(int(form_id), form_name,newmenu,menuinfo[2]) 279 id=wx.NewId() 280 self.modelmenu.AppendMenu(id,menuinfo[0],menuinfo[1], menuinfo[2]) 281 282 283 284 220 285 def _on_model(self, evt): 221 286 """ … … 223 288 @param event: wx menu event 224 289 """ 225 if str(evt.GetId()) in self.model_list.keys():226 # Notify the application manager that a new model has been set227 #self.app_manager.set_model(self.model_list[str(evt.GetId())]())228 229 #TODO: post a model event to update all panels that need230 #evt = ModelEvent(model=self.model_list[str(evt.GetId())]())231 232 model = self.model_list[str(evt.GetId())]233 evt = ModelEvent(model= model )234 290 if int(evt.GetId()) in self.form_factor_dict.keys(): 291 from sans.models.MultiplicationModel import MultiplicationModel 292 model1, model2 = self.form_factor_dict[int(evt.GetId())] 293 model = MultiplicationModel(model1, model2) 294 295 else: 296 model= self.struct_factor_dict[str(evt.GetId())]() 297 298 evt = ModelEvent( model= model ) 299 wx.PostEvent(self.event_owner, evt) 235 300 236 301 def get_model_list(self): 237 302 """ @ return dictionary of models for fitpanel use """ 238 return self.model_list_box 239 303 return self.form_factor_dict_for_combox 304 305 306 def get_form_struct(self): 307 """ retunr list of form structures""" 308 return self.struct_list 309 240 310 241 311
Note: See TracChangeset
for help on using the changeset viewer.