Ignore:
Timestamp:
Sep 21, 2017 3:12:37 PM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
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, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
12d3e0e
Parents:
ce81f70 (diff), d76c43a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into ticket-887-reorg

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/fitting/models.py

    r12f7f24 r724af06  
    1414import py_compile 
    1515import shutil 
     16from copy import copy 
     17 
    1618from sasmodels.sasview_model import load_custom_model, load_standard_models 
     19 
    1720# Explicitly import from the pluginmodel module so that py2exe 
    1821# places it in the distribution. The Model1DPlugin class is used 
     
    2124from sas.sascalc.fit.pluginmodel import Model1DPlugin 
    2225from sas.sasgui.guiframe.CategoryInstaller import CategoryInstaller 
     26from sas.sasgui.perspectives.fitting.fitpage import CUSTOM_MODEL 
    2327 
    2428logger = logging.getLogger(__name__) 
     
    265269        temp = {} 
    266270        if self.is_changed(): 
    267             return  _find_models() 
     271            temp =  _find_models() 
     272            self.last_time_dir_modified = time.time() 
     273            return temp 
    268274        logger.info("plugin model : %s" % str(temp)) 
    269275        return temp 
     
    278284        """ 
    279285 
    280         # regular model names only 
     286        # Regular model names only 
    281287        self.model_name_list = [] 
    282288 
    283         #Build list automagically from sasmodels package 
     289        # Build list automagically from sasmodels package 
    284290        for model in load_standard_models(): 
    285291            self.model_dictionary[model.name] = model 
     
    293299                self.model_name_list.append(model.name) 
    294300 
    295         #Looking for plugins 
     301        # Looking for plugins 
    296302        self.stored_plugins = self.findModels() 
    297303        self.plugins = self.stored_plugins.values() 
    298304        for name, plug in self.stored_plugins.iteritems(): 
    299305            self.model_dictionary[name] = plug 
     306            # TODO: Remove 'hasattr' statements when old style plugin models 
     307            # are no longer supported. All sasmodels models will have 
     308            # the required attributes. 
     309            if hasattr(plug, 'is_structure_factor') and plug.is_structure_factor: 
     310                self.struct_list.append(plug) 
     311                self.plugins.remove(plug) 
     312            elif hasattr(plug, 'is_form_factor') and plug.is_form_factor: 
     313                self.multiplication_factor.append(plug) 
     314            if hasattr(plug, 'is_multiplicity_model') and plug.is_multiplicity_model: 
     315                self.multi_func_list.append(plug) 
    300316 
    301317        self._get_multifunc_models() 
     
    312328        if os.path.isdir(plugin_dir): 
    313329            temp = os.path.getmtime(plugin_dir) 
    314             if  self.last_time_dir_modified != temp: 
     330            if  self.last_time_dir_modified < temp: 
    315331                is_modified = True 
    316332                self.last_time_dir_modified = temp 
     
    323339        new models were added else return empty dictionary 
    324340        """ 
     341        self.plugins = [] 
    325342        new_plugins = self.findModels() 
    326         if len(new_plugins) > 0: 
    327             for name, plug in  new_plugins.iteritems(): 
    328                 if name not in self.stored_plugins.keys(): 
    329                     self.stored_plugins[name] = plug 
    330                     self.plugins.append(plug) 
    331                     self.model_dictionary[name] = plug 
    332             self.model_combobox.set_list("Plugin Models", self.plugins) 
     343        if new_plugins: 
     344            for name, plug in  new_plugins.items(): 
     345                self.stored_plugins[name] = plug 
     346                self.plugins.append(plug) 
     347                self.model_dictionary[name] = plug 
     348            self.model_combobox.set_list(CUSTOM_MODEL, self.plugins) 
    333349            return self.model_combobox.get_list() 
    334350        else: 
     
    340356        """ 
    341357        self.plugins = [] 
    342         new_plugins = _find_models() 
    343         for name, plug in  new_plugins.iteritems(): 
    344             for stored_name, stored_plug in self.stored_plugins.iteritems(): 
    345                 if name == stored_name: 
    346                     del self.stored_plugins[name] 
    347                     del self.model_dictionary[name] 
    348                     break 
     358        self.stored_plugins = _find_models() 
     359        structure_names = [model.name for model in self.struct_list] 
     360        form_names = [model.name for model in self.multiplication_factor] 
     361 
     362        # Remove all plugin structure factors and form factors 
     363        for name in copy(structure_names): 
     364            if '[plug-in]' in name: 
     365                i = structure_names.index(name) 
     366                del self.struct_list[i] 
     367                structure_names.remove(name) 
     368        for name in copy(form_names): 
     369            if '[plug-in]' in name: 
     370                i = form_names.index(name) 
     371                del self.multiplication_factor[i] 
     372                form_names.remove(name) 
     373 
     374        # Add new plugin structure factors and form factors 
     375        for name, plug in self.stored_plugins.iteritems(): 
     376            if plug.is_structure_factor: 
     377                if name in structure_names: 
     378                    # Delete the old model from self.struct list 
     379                    i = structure_names.index(name) 
     380                    del self.struct_list[i] 
     381                # Add the new model to self.struct_list 
     382                self.struct_list.append(plug) 
     383            elif plug.is_form_factor: 
     384                if name in form_names: 
     385                    # Delete the old model from self.multiplication_factor 
     386                    i = form_names.index(name) 
     387                    del self.multiplication_factor[i] 
     388                # Add the new model to self.multiplication_factor 
     389                self.multiplication_factor.append(plug) 
     390 
     391            # Add references to the updated model 
    349392            self.stored_plugins[name] = plug 
    350             self.plugins.append(plug) 
     393            if not plug.is_structure_factor: 
     394                # Don't show S(Q) models in the 'Plugin Models' dropdown 
     395                self.plugins.append(plug) 
    351396            self.model_dictionary[name] = plug 
    352397 
    353398        self.model_combobox.reset_list("Plugin Models", self.plugins) 
     399        self.model_combobox.reset_list("Structure Factors", self.struct_list) 
     400        self.model_combobox.reset_list("P(Q)*S(Q)", self.multiplication_factor) 
     401 
    354402        return self.model_combobox.get_list() 
    355403 
Note: See TracChangeset for help on using the changeset viewer.