Changeset 43eb424 in sasview for sansview


Ignore:
Timestamp:
Mar 11, 2009 7:29:23 PM (15 years ago)
Author:
Gervaise Alina <gervyh@…>
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
Message:

reverse version

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sansview/perspectives/fitting/models.py

    r28ea782 r43eb424  
    6666        pass 
    6767    return plugins 
    68  
    69  
    7068class 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={} 
    8475    plugins=[] 
    85     ## Event owner (guiframe) 
     76    indep_model=[] 
     77    ## Event owner 
    8678    event_owner = None 
    8779     
     
    9486            @return: the next free event ID following the new menu events 
    9587        """ 
    96         ## form factor 
     88        self.model_list = {} 
     89        self.model_list_box = {} 
     90        
     91         
    9792        from sans.models.SphereModel import SphereModel 
    98         self.shape_list.append(SphereModel) 
     93        self.model_list[str(wx.NewId())] =  SphereModel 
    9994         
    10095        from sans.models.CylinderModel import CylinderModel 
    101         self.shape_list.append(CylinderModel) 
     96        self.model_list[str(wx.NewId())] =CylinderModel 
    10297       
    10398        from sans.models.CoreShellModel import CoreShellModel 
    104         self.shape_list.append(CoreShellModel) 
     99        self.model_list[str(wx.NewId())] = CoreShellModel  
    105100         
    106101        from sans.models.CoreShellCylinderModel import CoreShellCylinderModel 
    107         self.shape_list.append(CoreShellCylinderModel) 
     102        self.model_list[str(wx.NewId())] =CoreShellCylinderModel 
    108103         
    109104        from sans.models.EllipticalCylinderModel import EllipticalCylinderModel 
    110         self.shape_list.append(EllipticalCylinderModel) 
     105        self.model_list[str(wx.NewId())] =EllipticalCylinderModel 
    111106         
    112107        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         
    115122        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         
    136128        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         
    139131        from sans.models.DABModel import DABModel 
    140         self.shape_indep_list.append(DABModel ) 
     132        self.indep_model.append(DABModel ) 
    141133         
    142134        from sans.models.GuinierModel import GuinierModel 
    143         self.shape_indep_list.append(GuinierModel ) 
     135        self.indep_model.append(GuinierModel ) 
    144136         
    145137        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 ) 
    150139         
    151140        from sans.models.FractalModel import FractalModel 
     
    153142            def _Fractal(self, x): 
    154143                return FractalModel._Fractal(self, math.fabs(x)) 
    155         self.shape_indep_list.append(FractalAbsModel) 
     144        self.indep_model.append(FractalAbsModel) 
    156145         
    157146        from sans.models.LorentzModel import LorentzModel 
    158         self.shape_indep_list.append( LorentzModel)  
     147        self.indep_model.append( LorentzModel)  
    159148             
    160149        from sans.models.PowerLawModel import PowerLawModel 
     
    165154                except: 
    166155                    print sys.exc_value   
    167         self.shape_indep_list.append( PowerLawAbsModel ) 
     156        self.indep_model.append( PowerLawAbsModel ) 
    168157        from sans.models.TeubnerStreyModel import TeubnerStreyModel 
    169         self.shape_indep_list.append(TeubnerStreyModel ) 
     158        self.indep_model.append(TeubnerStreyModel ) 
    170159     
    171160        #Looking for plugins 
     
    184173            @return: the next free event ID following the new menu events 
    185174        """ 
    186         ## Fill model lists 
    187175        self._getModelList() 
    188         ## store reference to model menu of guiframe 
    189         self.modelmenu = modelmenu 
    190         ## guiframe reference 
    191176        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() 
    197179        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") 
    214218        return 0 
    215219     
    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          
    285220    def _on_model(self, evt): 
    286221        """ 
     
    288223            @param event: wx menu event 
    289224        """ 
    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) 
     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) 
    300235         
    301236    def get_model_list(self):     
    302237        """ @ 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     
    310240     
    311241     
Note: See TracChangeset for help on using the changeset viewer.