Changeset 43eb424 in sasview
- Timestamp:
- Mar 11, 2009 7:29:23 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:
- 0f7b597
- Parents:
- b2f5bcb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/models.py
r28ea782 r43eb424 66 66 pass 67 67 return plugins 68 69 70 68 class ModelManager: 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 69 70 ## Dictionary of models 71 model_list = {} 72 indep_model_list = {} 73 model_list_box = {} 74 custom_models={} 84 75 plugins=[] 85 ## Event owner (guiframe) 76 indep_model=[] 77 ## Event owner 86 78 event_owner = None 87 79 … … 94 86 @return: the next free event ID following the new menu events 95 87 """ 96 ## form factor 88 self.model_list = {} 89 self.model_list_box = {} 90 91 97 92 from sans.models.SphereModel import SphereModel 98 self. shape_list.append(SphereModel)93 self.model_list[str(wx.NewId())] = SphereModel 99 94 100 95 from sans.models.CylinderModel import CylinderModel 101 self. shape_list.append(CylinderModel)96 self.model_list[str(wx.NewId())] =CylinderModel 102 97 103 98 from sans.models.CoreShellModel import CoreShellModel 104 self. shape_list.append(CoreShellModel)99 self.model_list[str(wx.NewId())] = CoreShellModel 105 100 106 101 from sans.models.CoreShellCylinderModel import CoreShellCylinderModel 107 self. shape_list.append(CoreShellCylinderModel)102 self.model_list[str(wx.NewId())] =CoreShellCylinderModel 108 103 109 104 from sans.models.EllipticalCylinderModel import EllipticalCylinderModel 110 self. shape_list.append(EllipticalCylinderModel)105 self.model_list[str(wx.NewId())] =EllipticalCylinderModel 111 106 112 107 from sans.models.EllipsoidModel import EllipsoidModel 113 self.shape_list.append(EllipsoidModel) 114 108 self.model_list[str(wx.NewId())] = EllipsoidModel 109 110 from sans.models.SquareWellStructure import SquareWellStructure 111 self.model_list[str(wx.NewId())] = SquareWellStructure 112 113 from sans.models.HardsphereStructure import HardsphereStructure 114 self.model_list[str(wx.NewId())] = HardsphereStructure 115 116 from sans.models.StickyHSStructure import StickyHSStructure 117 self.model_list[str(wx.NewId())] = StickyHSStructure 118 119 from sans.models.HayterMSAStructure import HayterMSAStructure 120 self.model_list[str(wx.NewId())] = HayterMSAStructure 121 115 122 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) 121 122 from sans.models.SquareWellStructure import SquareWellStructure 123 self.struct_list.append(SquareWellStructure) 124 125 from sans.models.HardsphereStructure import HardsphereStructure 126 self.struct_list.append(HardsphereStructure) 127 128 from sans.models.StickyHSStructure import StickyHSStructure 129 self.struct_list.append(StickyHSStructure) 130 131 from sans.models.HayterMSAStructure import HayterMSAStructure 132 self.struct_list.append(HayterMSAStructure) 133 134 135 ##shape-independent models 123 self.model_list[str(wx.NewId())] = LineModel 124 125 126 model_info="shape-independent models" 127 136 128 from sans.models.BEPolyelectrolyte import BEPolyelectrolyte 137 self. shape_indep_list.append(BEPolyelectrolyte )138 self.form_factor_dict[str(wx.NewId())] = [SphereModel]129 self.indep_model.append(BEPolyelectrolyte ) 130 139 131 from sans.models.DABModel import DABModel 140 self. shape_indep_list.append(DABModel )132 self.indep_model.append(DABModel ) 141 133 142 134 from sans.models.GuinierModel import GuinierModel 143 self. shape_indep_list.append(GuinierModel )135 self.indep_model.append(GuinierModel ) 144 136 145 137 from sans.models.DebyeModel import DebyeModel 146 self.shape_indep_list.append(DebyeModel ) 147 148 from sans.models.PorodModel import PorodModel 149 self.shape_indep_list.append(PorodModel ) 138 self.indep_model.append(DebyeModel ) 150 139 151 140 from sans.models.FractalModel import FractalModel … … 153 142 def _Fractal(self, x): 154 143 return FractalModel._Fractal(self, math.fabs(x)) 155 self. shape_indep_list.append(FractalAbsModel)144 self.indep_model.append(FractalAbsModel) 156 145 157 146 from sans.models.LorentzModel import LorentzModel 158 self. shape_indep_list.append( LorentzModel)147 self.indep_model.append( LorentzModel) 159 148 160 149 from sans.models.PowerLawModel import PowerLawModel … … 165 154 except: 166 155 print sys.exc_value 167 self. shape_indep_list.append( PowerLawAbsModel )156 self.indep_model.append( PowerLawAbsModel ) 168 157 from sans.models.TeubnerStreyModel import TeubnerStreyModel 169 self. shape_indep_list.append(TeubnerStreyModel )158 self.indep_model.append(TeubnerStreyModel ) 170 159 171 160 #Looking for plugins … … 184 173 @return: the next free event ID following the new menu events 185 174 """ 186 ## Fill model lists187 175 self._getModelList() 188 ## store reference to model menu of guiframe189 self.modelmenu = modelmenu190 ## guiframe reference191 176 self.event_owner = event_owner 192 193 194 shape_submenu = wx.Menu() 195 shape_indep_submenu = wx.Menu() 196 structure_factor = wx.Menu() 177 shape_submenu= wx.Menu() 178 indep_submenu = wx.Menu() 197 179 added_models = wx.Menu() 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) 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") 214 218 return 0 215 219 216 def _fill_simple_menu(self,menuinfo, list1):217 """218 Fill the menu with list item219 @param modelmenu: the menu to fill220 @param menuinfo: submenu item for the first column of this modelmenu221 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 column224 """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)] =item230 struct_factor=item()231 struct_name = struct_factor.__class__.__name__232 if hasattr(struct_factor, "name"):233 struct_name = struct_factor.name234 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)]= item238 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 item248 @param menuinfo: submenu item for the first column of this modelmenu249 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 column252 @param list2: contains item (Structure factor )to fill modelmenu third column253 """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.name260 ### store form factor to return to other users261 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.name269 newmenu.Append(id,name, name)270 wx.EVT_MENU(self.event_owner, int(id), self._on_model)271 ## save form_fact and struct_fact272 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)] =item276 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 285 220 def _on_model(self, evt): 286 221 """ … … 288 223 @param event: wx menu event 289 224 """ 290 if int(evt.GetId()) in self.form_factor_dict.keys():291 from sans.models.MultiplicationModel import MultiplicationModel292 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)225 if str(evt.GetId()) in self.model_list.keys(): 226 # Notify the application manager that a new model has been set 227 #self.app_manager.set_model(self.model_list[str(evt.GetId())]()) 228 229 #TODO: post a model event to update all panels that need 230 #evt = ModelEvent(model=self.model_list[str(evt.GetId())]()) 231 232 model = self.model_list[str(evt.GetId())] 233 evt = ModelEvent(model= model ) 234 wx.PostEvent(self.event_owner, evt) 300 235 301 236 def get_model_list(self): 302 237 """ @ return dictionary of models for fitpanel use """ 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 238 return self.model_list_box 239 310 240 311 241
Note: See TracChangeset
for help on using the changeset viewer.