source: sasview/src/sas/perspectives/fitting/models.py @ 0c4bca6

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 0c4bca6 was b9a5f0e, checked in by krzywon, 10 years ago

90% complete with the conversion.

  • Property mode set to 100644
File size: 45.2 KB
RevLine 
[61184df]1"""
2    Utilities to manage models
3"""
[d89f09b]4import wx
[b30f001]5import imp
[9466f2d6]6import os
7import sys
8import math
[d89f09b]9import os.path
[33afff7]10# Time is needed by the log method
11import time
[23ccf07]12import logging
[5d1c1f4]13import py_compile
[96814e1]14import shutil
[79492222]15from sas.guiframe.events import StatusEvent
[33afff7]16# Explicitly import from the pluginmodel module so that py2exe
17# places it in the distribution. The Model1DPlugin class is used
18# as the base class of plug-in models.
[79492222]19from sas.models.pluginmodel import Model1DPlugin
20from sas.models.BaseComponent import BaseComponent
21from sas.guiframe.CategoryInstaller import CategoryInstaller
[9466f2d6]22   
[f32d144]23PLUGIN_DIR = 'plugin_models'
24
[df7a7e3]25def get_model_python_path():
26    return os.path.dirname(__file__)
27
[9466f2d6]28
[b30f001]29def log(message):
[5062bbf]30    """
[61184df]31        Log a message in a file located in the user's home directory
[5062bbf]32    """
[94d6752]33    dir = os.path.join(os.path.expanduser("~"), '.sasview', PLUGIN_DIR)
[b30ed8f]34    out = open(os.path.join(dir, "plugins.log"), 'a')
[b30f001]35    out.write("%10g%s\n" % (time.clock(), message))
36    out.close()
37
[9466f2d6]38
[bfe4644]39def _check_plugin(model, name):
40    """
[5062bbf]41    Do some checking before model adding plugins in the list
42   
43    :param model: class model to add into the plugin list
44    :param name:name of the module plugin
45   
46    :return model: model if valid model or None if not valid
47   
[bfe4644]48    """
[116e1a7]49    #Check if the plugin is of type Model1DPlugin
[bfe4644]50    if not issubclass(model, Model1DPlugin):
[61184df]51        msg = "Plugin %s must be of type Model1DPlugin \n" % str(name)
[bfe4644]52        log(msg)
[8d78399]53        return None
[f32d144]54    if model.__name__ != "Model":
55        msg = "Plugin %s class name must be Model \n" % str(name)
[bfe4644]56        log(msg)
[8d78399]57        return None
[bfe4644]58    try:
[f32d144]59        new_instance = model()
[bfe4644]60    except:
[f32d144]61        msg = "Plugin %s error in __init__ \n\t: %s %s\n" % (str(name),
[61184df]62                                    str(sys.exc_type), sys.exc_value)
[bfe4644]63        log(msg)
[8d78399]64        return None
[bfe4644]65   
[f32d144]66    if hasattr(new_instance, "function"):
[bfe4644]67        try:
[f32d144]68            value = new_instance.function()
[bfe4644]69        except:
[f32d144]70            msg = "Plugin %s: error writing function \n\t :%s %s\n " % (str(name),
[61184df]71                                    str(sys.exc_type), sys.exc_value)
[f32d144]72            log(msg)
73            return None
[bfe4644]74    else:
[f32d144]75        msg = "Plugin  %s needs a method called function \n" % str(name)
76        log(msg)
77        return None
[bfe4644]78    return model
79 
[f32d144]80 
[5d1c1f4]81def find_plugins_dir():
[5062bbf]82    """
[96814e1]83        Find path of the plugins directory.
84        The plugin directory is located in the user's home directory.
[5062bbf]85    """
[94d6752]86    dir = os.path.join(os.path.expanduser("~"), '.sasview', PLUGIN_DIR)
[96814e1]87   
88    # If the plugin directory doesn't exist, create it
[a0986f6]89    if not os.path.isdir(dir):
[96814e1]90        os.makedirs(dir)
91       
[8ab3302]92    # Find paths needed
93    try:
94        # For source
95        if os.path.isdir(os.path.dirname(__file__)):
[f32d144]96            p_dir = os.path.join(os.path.dirname(__file__), PLUGIN_DIR)
[8ab3302]97        else:
98            raise
99    except:
100        # Check for data path next to exe/zip file.
101        #Look for maximum n_dir up of the current dir to find plugins dir
102        n_dir = 12
103        p_dir = None
104        f_dir = os.path.join(os.path.dirname(__file__))
105        for i in range(n_dir):
106            if i > 1:
107                f_dir, _ = os.path.split(f_dir)
108            plugin_path = os.path.join(f_dir, PLUGIN_DIR)
109            if os.path.isdir(plugin_path):
110                p_dir = plugin_path
111                break
112        if not p_dir:
113            raise
[96814e1]114    # Place example user models as needed
[19e614a]115    if os.path.isdir(p_dir):
116        for file in os.listdir(p_dir):
117            file_path = os.path.join(p_dir, file)
118            if os.path.isfile(file_path):
119                if file.split(".")[-1] == 'py' and\
120                    file.split(".")[0] != '__init__':
121                    if not os.path.isfile(os.path.join(dir, file)):
122                        shutil.copy(file_path, dir)
123
[5d1c1f4]124    return dir
125
[f32d144]126
[5d1c1f4]127class ReportProblem:
128    def __nonzero__(self):
129        type, value, traceback = sys.exc_info()
130        if type is not None and issubclass(type, py_compile.PyCompileError):
131            print "Problem with", repr(value)
132            raise type, value, traceback
133        return 1
134   
135report_problem = ReportProblem()
136
[f32d144]137
[5d1c1f4]138def compile_file(dir):
139    """
140    Compile a py file
141    """
142    try:
143        import compileall
[f32d144]144        compileall.compile_dir(dir=dir, ddir=dir, force=1,
145                               quiet=report_problem)
[5d1c1f4]146    except:
147        type, value, traceback = sys.exc_info()
148        return value
149    return None
150
[f32d144]151
[5d1c1f4]152def _findModels(dir):
153    """
154    """
155    # List of plugin objects
156    plugins = {}
157    # Go through files in plug-in directory
158    #always recompile the folder plugin
159    dir = find_plugins_dir()
[a0986f6]160    if not os.path.isdir(dir):
[b9a5f0e]161        msg = "SasView couldn't locate Model plugin folder."
[a0986f6]162        msg += """ "%s" does not exist""" % dir
163        logging.warning(msg)
164        return plugins
165    else:
166        log("looking for models in: %s" % str(dir))
[5d1c1f4]167        compile_file(dir)
[a0986f6]168        logging.info("pluging model dir: %s\n" % str(dir))
[1c66bc5]169    try:
170        list = os.listdir(dir)
171        for item in list:
172            toks = os.path.splitext(os.path.basename(item))
[f32d144]173            if toks[1] == '.py' and not toks[0] == '__init__':
[1c66bc5]174                name = toks[0]
175           
176                path = [os.path.abspath(dir)]
177                file = None
178                try:
179                    (file, path, info) = imp.find_module(name, path)
[f32d144]180                    module = imp.load_module(name, file, item, info)
[1c66bc5]181                    if hasattr(module, "Model"):
182                        try:
[f32d144]183                            if _check_plugin(module.Model, name) != None:
[b2d9826]184                                plugins[name] = module.Model
[1c66bc5]185                        except:
[f32d144]186                            msg = "Error accessing Model"
187                            msg += "in %s\n  %s %s\n" % (name,
[bfe4644]188                                    str(sys.exc_type), sys.exc_value)
189                            log(msg)
[1c66bc5]190                except:
[f32d144]191                    msg = "Error accessing Model"
192                    msg += " in %s\n  %s %s \n" % (name,
[bfe4644]193                                    str(sys.exc_type), sys.exc_value)
194                    log(msg)
[1c66bc5]195                finally:
[a92d51b]196             
[f32d144]197                    if not file == None:
[1c66bc5]198                        file.close()
199    except:
[33afff7]200        # Don't deal with bad plug-in imports. Just skip.
[23ccf07]201        msg = "Could not import model plugin: %s\n" % sys.exc_value
202        log(msg)
[1c66bc5]203        pass
204    return plugins
[bb18ef1]205
[f32d144]206
[bb18ef1]207class ModelList(object):
208    """
[5062bbf]209    Contains dictionary of model and their type
[bb18ef1]210    """
211    def __init__(self):
[5062bbf]212        """
213        """
214        self.mydict = {}
[bb18ef1]215       
216    def set_list(self, name, mylist):
217        """
[5062bbf]218        :param name: the type of the list
219        :param mylist: the list to add
220       
[bb18ef1]221        """
222        if name not in self.mydict.keys():
[916f5c0]223            self.reset_list(name, mylist)
[bb18ef1]224           
[916f5c0]225    def reset_list(self, name, mylist):
226        """
227        :param name: the type of the list
228        :param mylist: the list to add
229        """
[f32d144]230        self.mydict[name] = mylist
[bb18ef1]231           
232    def get_list(self):
233        """
[5062bbf]234        return all the list stored in a dictionary object
[bb18ef1]235        """
236        return self.mydict
237       
[f32d144]238       
[bb9f322]239class ModelManagerBase:
[5062bbf]240    """
[61184df]241        Base class for the model manager
[5062bbf]242    """
[bb18ef1]243    ## external dict for models
244    model_combobox = ModelList()
[116e1a7]245    ## Dictionary of form factor models
[bb18ef1]246    form_factor_dict = {}
[116e1a7]247    ## dictionary of structure factor models
[bb18ef1]248    struct_factor_dict = {}
[116e1a7]249    ##list of shape models -- this is superseded by categories
250#    shape_list = []
251    ## shape independent model list-- this is superseded by categories
252#    shape_indep_list = []
[f32d144]253    ##list of structure factors
[b2d9826]254    struct_list = []
[116e1a7]255    ##list of model allowing multiplication by a structure factor
[b2d9826]256    multiplication_factor = []
[116e1a7]257    ##list of multifunctional shapes (i.e. that have user defined number of levels
[b2d9826]258    multi_func_list = []
[116e1a7]259    ## list of added models -- currently python models found in the plugin dir.
[b2d9826]260    plugins = []
[bb18ef1]261    ## Event owner (guiframe)
[d89f09b]262    event_owner = None
[9466f2d6]263    last_time_dir_modified = 0
[f32d144]264   
[6bbeacd4]265    def __init__(self):
266        """
267        """
[df7a7e3]268        self.model_dictionary = {}
[b2d9826]269        self.stored_plugins = {}
[6bbeacd4]270        self._getModelList()
271       
[9466f2d6]272    def findModels(self):
273        """
274        find  plugin model in directory of plugin .recompile all file
275        in the directory if file were modified
276        """
[23ccf07]277        temp = {}
[9466f2d6]278        if self.is_changed():
[a0986f6]279            return  _findModels(dir)
[23ccf07]280        logging.info("pluging model : %s\n" % str(temp))
281        return temp
282       
[d89f09b]283    def _getModelList(self):
284        """
[5062bbf]285        List of models we want to make available by default
286        for this application
287   
288        :return: the next free event ID following the new menu events
[e7b1ccf]289       
[d89f09b]290        """
[df7a7e3]291
[116e1a7]292        ## NOTE: as of April 26, 2014, as part of first pass on fixing categories,
293        ## all the appends to shape_list or shape_independent_list are
294        ## commented out.  They should be possible to remove.  They are in
295        ## fact a "category" of model whereas the other list are actually
296        ## "attributes" of a model.  In other words is it a structure factor
297        ## that can be used against a form factor, is it a form factor that is
298        ## knows how to be multiplied by a structure factor, does it have user
299        ## defined number of parameters, etc.
300        ##
301        ## We hope this whole list will be superseded by the new C models
302        ## structure where each model will provide a method to interrogate it
303        ## about its "attributes" -- then this long list becomes a loop reading
304        ## each model in the category list to populate the "attribute"lists. 
305        ## We should also refactor the whole category vs attribute list
306        ## structure when doing this as now the attribute lists think they are
307        ## also category lists.
308        ##
309        ##   -PDB  April 26, 2014
[df7a7e3]310
[7c8d3093]311        # regular model names only
312        self.model_name_list = []
[79492222]313        from sas.models.SphereModel import SphereModel
[df7a7e3]314        self.model_dictionary[SphereModel.__name__] = SphereModel
[116e1a7]315#        self.shape_list.append(SphereModel)
[376916c]316        self.multiplication_factor.append(SphereModel)
[7c8d3093]317        self.model_name_list.append(SphereModel.__name__)
[442895f]318       
[79492222]319        from sas.models.BinaryHSModel import BinaryHSModel
[df7a7e3]320        self.model_dictionary[BinaryHSModel.__name__] = BinaryHSModel
[116e1a7]321#        self.shape_list.append(BinaryHSModel)
[7c8d3093]322        self.model_name_list.append(BinaryHSModel.__name__)
[1a395a6]323                       
[79492222]324        from sas.models.FuzzySphereModel import FuzzySphereModel
[df7a7e3]325        self.model_dictionary[FuzzySphereModel.__name__] = FuzzySphereModel
[116e1a7]326#        self.shape_list.append(FuzzySphereModel)
[ce07fa8]327        self.multiplication_factor.append(FuzzySphereModel)
[7c8d3093]328        self.model_name_list.append(FuzzySphereModel.__name__)
[3764dbd7]329                       
[79492222]330        from sas.models.RaspBerryModel import RaspBerryModel
[df7a7e3]331        self.model_dictionary[RaspBerryModel.__name__] = RaspBerryModel
[116e1a7]332#        self.shape_list.append(RaspBerryModel)
[3764dbd7]333        self.model_name_list.append(RaspBerryModel.__name__)
334               
[79492222]335        from sas.models.CoreShellModel import CoreShellModel
[df7a7e3]336        self.model_dictionary[CoreShellModel.__name__] = CoreShellModel
[116e1a7]337#        self.shape_list.append(CoreShellModel)
[5eb9154]338        self.multiplication_factor.append(CoreShellModel)
[7c8d3093]339        self.model_name_list.append(CoreShellModel.__name__)
[4523b68]340       
[79492222]341        from sas.models.Core2ndMomentModel import Core2ndMomentModel
[df7a7e3]342        self.model_dictionary[Core2ndMomentModel.__name__] = Core2ndMomentModel
[116e1a7]343#        self.shape_list.append(Core2ndMomentModel)
[7289627]344        self.model_name_list.append(Core2ndMomentModel.__name__)
345       
[79492222]346        from sas.models.CoreMultiShellModel import CoreMultiShellModel
[df7a7e3]347        self.model_dictionary[CoreMultiShellModel.__name__] = CoreMultiShellModel
[116e1a7]348#        self.shape_list.append(CoreMultiShellModel)
[4523b68]349        self.multiplication_factor.append(CoreMultiShellModel)
[a1b2471]350        self.multi_func_list.append(CoreMultiShellModel)
[fb59ed9]351
[79492222]352        from sas.models.VesicleModel import VesicleModel
[df7a7e3]353        self.model_dictionary[VesicleModel.__name__] = VesicleModel
[116e1a7]354#        self.shape_list.append(VesicleModel)
[5eb9154]355        self.multiplication_factor.append(VesicleModel)
[7c8d3093]356        self.model_name_list.append(VesicleModel.__name__)
[5eb9154]357       
[79492222]358        from sas.models.MultiShellModel import MultiShellModel
[df7a7e3]359        self.model_dictionary[MultiShellModel.__name__] = MultiShellModel
[116e1a7]360#        self.shape_list.append(MultiShellModel)
[5eb9154]361        self.multiplication_factor.append(MultiShellModel)
[7c8d3093]362        self.model_name_list.append(MultiShellModel.__name__)
[eddff027]363       
[79492222]364        from sas.models.OnionExpShellModel import OnionExpShellModel
[df7a7e3]365        self.model_dictionary[OnionExpShellModel.__name__] = OnionExpShellModel
[116e1a7]366#        self.shape_list.append(OnionExpShellModel)
[1a395a6]367        self.multiplication_factor.append(OnionExpShellModel)
368        self.multi_func_list.append(OnionExpShellModel)
[463eb76e]369                         
[79492222]370        from sas.models.SphericalSLDModel import SphericalSLDModel
[df7a7e3]371        self.model_dictionary[SphericalSLDModel.__name__] = SphericalSLDModel
[116e1a7]372#        self.shape_list.append(SphericalSLDModel)
[1a395a6]373        self.multiplication_factor.append(SphericalSLDModel)
374        self.multi_func_list.append(SphericalSLDModel)
[a8d3b4f]375
[cee6867]376       
[79492222]377        from sas.models.LinearPearlsModel import LinearPearlsModel
[df7a7e3]378        self.model_dictionary[LinearPearlsModel.__name__] = LinearPearlsModel
[116e1a7]379#        self.shape_list.append(LinearPearlsModel)
[d9547e7]380        self.model_name_list.append(LinearPearlsModel.__name__)
381         
[79492222]382        from sas.models.PearlNecklaceModel import PearlNecklaceModel
[df7a7e3]383        self.model_dictionary[PearlNecklaceModel.__name__] = PearlNecklaceModel
[116e1a7]384#        self.shape_list.append(PearlNecklaceModel)
[7c8d3093]385        self.model_name_list.append(PearlNecklaceModel.__name__)
[4ad076b]386        #self.multiplication_factor.append(PearlNecklaceModel)
387       
[79492222]388        from sas.models.CylinderModel import CylinderModel
[df7a7e3]389        self.model_dictionary[CylinderModel.__name__] = CylinderModel
[116e1a7]390#        self.shape_list.append(CylinderModel)
[eddff027]391        self.multiplication_factor.append(CylinderModel)
[7c8d3093]392        self.model_name_list.append(CylinderModel.__name__)
[eddff027]393       
[79492222]394        from sas.models.CoreShellCylinderModel import CoreShellCylinderModel
[df7a7e3]395        self.model_dictionary[CoreShellCylinderModel.__name__] = CoreShellCylinderModel
[116e1a7]396#        self.shape_list.append(CoreShellCylinderModel)
[5eb9154]397        self.multiplication_factor.append(CoreShellCylinderModel)
[7c8d3093]398        self.model_name_list.append(CoreShellCylinderModel.__name__)
[cee6867]399       
[79492222]400        from sas.models.CoreShellBicelleModel import CoreShellBicelleModel
[df7a7e3]401        self.model_dictionary[CoreShellBicelleModel.__name__] = CoreShellBicelleModel
[116e1a7]402#        self.shape_list.append(CoreShellBicelleModel)
[543d1bd]403        self.multiplication_factor.append(CoreShellBicelleModel)
404        self.model_name_list.append(CoreShellBicelleModel.__name__)
405               
[79492222]406        from sas.models.HollowCylinderModel import HollowCylinderModel
[df7a7e3]407        self.model_dictionary[HollowCylinderModel.__name__] = HollowCylinderModel
[116e1a7]408#        self.shape_list.append(HollowCylinderModel)
[5eb9154]409        self.multiplication_factor.append(HollowCylinderModel)
[7c8d3093]410        self.model_name_list.append(HollowCylinderModel.__name__)
[eddff027]411             
[79492222]412        from sas.models.FlexibleCylinderModel import FlexibleCylinderModel
[df7a7e3]413        self.model_dictionary[FlexibleCylinderModel.__name__] = FlexibleCylinderModel
[116e1a7]414#        self.shape_list.append(FlexibleCylinderModel)
[7c8d3093]415        self.model_name_list.append(FlexibleCylinderModel.__name__)
[72f719b]416
[79492222]417        from sas.models.FlexCylEllipXModel import FlexCylEllipXModel
[df7a7e3]418        self.model_dictionary[FlexCylEllipXModel.__name__] = FlexCylEllipXModel
[116e1a7]419#        self.shape_list.append(FlexCylEllipXModel)
[7c8d3093]420        self.model_name_list.append(FlexCylEllipXModel.__name__)
[eddff027]421       
[79492222]422        from sas.models.StackedDisksModel import StackedDisksModel
[df7a7e3]423        self.model_dictionary[StackedDisksModel.__name__] = StackedDisksModel
[116e1a7]424#        self.shape_list.append(StackedDisksModel)
[5eb9154]425        self.multiplication_factor.append(StackedDisksModel)
[7c8d3093]426        self.model_name_list.append(StackedDisksModel.__name__)
[eddff027]427       
[79492222]428        from sas.models.ParallelepipedModel import ParallelepipedModel
[df7a7e3]429        self.model_dictionary[ParallelepipedModel.__name__] = ParallelepipedModel
[116e1a7]430#        self.shape_list.append(ParallelepipedModel)
[72f719b]431        self.multiplication_factor.append(ParallelepipedModel)
[7c8d3093]432        self.model_name_list.append(ParallelepipedModel.__name__)
[cee6867]433       
[79492222]434        from sas.models.CSParallelepipedModel import CSParallelepipedModel
[df7a7e3]435        self.model_dictionary[CSParallelepipedModel.__name__] = CSParallelepipedModel
[116e1a7]436#        self.shape_list.append(CSParallelepipedModel)
[fb59ed9]437        self.multiplication_factor.append(CSParallelepipedModel)
[7c8d3093]438        self.model_name_list.append(CSParallelepipedModel.__name__)
[fb59ed9]439       
[79492222]440        from sas.models.EllipticalCylinderModel import EllipticalCylinderModel
[df7a7e3]441        self.model_dictionary[EllipticalCylinderModel.__name__] = EllipticalCylinderModel
[116e1a7]442#        self.shape_list.append(EllipticalCylinderModel)
[72f719b]443        self.multiplication_factor.append(EllipticalCylinderModel)
[7c8d3093]444        self.model_name_list.append(EllipticalCylinderModel.__name__)
[fb59ed9]445       
[79492222]446        from sas.models.BarBellModel import BarBellModel
[df7a7e3]447        self.model_dictionary[BarBellModel.__name__] = BarBellModel
[116e1a7]448#        self.shape_list.append(BarBellModel)
[7c8d3093]449        self.model_name_list.append(BarBellModel.__name__)
[fb59ed9]450        # not implemeted yet!
451        #self.multiplication_factor.append(BarBellModel)
452       
[79492222]453        from sas.models.CappedCylinderModel import CappedCylinderModel
[df7a7e3]454        self.model_dictionary[CappedCylinderModel.__name__] = CappedCylinderModel
[116e1a7]455 #       self.shape_list.append(CappedCylinderModel)
[7c8d3093]456        self.model_name_list.append(CappedCylinderModel.__name__)
[fb59ed9]457        # not implemeted yet!
458        #self.multiplication_factor.append(CappedCylinderModel)
459       
[79492222]460        from sas.models.EllipsoidModel import EllipsoidModel
[df7a7e3]461        self.model_dictionary[EllipsoidModel.__name__] = EllipsoidModel
[116e1a7]462#        self.shape_list.append(EllipsoidModel)
[376916c]463        self.multiplication_factor.append(EllipsoidModel)
[7c8d3093]464        self.model_name_list.append(EllipsoidModel.__name__)
[eddff027]465     
[79492222]466        from sas.models.CoreShellEllipsoidModel import CoreShellEllipsoidModel
[df7a7e3]467        self.model_dictionary[CoreShellEllipsoidModel.__name__] = CoreShellEllipsoidModel
[116e1a7]468#        self.shape_list.append(CoreShellEllipsoidModel)
[5eb9154]469        self.multiplication_factor.append(CoreShellEllipsoidModel)
[7c8d3093]470        self.model_name_list.append(CoreShellEllipsoidModel.__name__)
[02cc1ea]471
[79492222]472        from sas.models.CoreShellEllipsoidXTModel import CoreShellEllipsoidXTModel
[02cc1ea]473        self.model_dictionary[CoreShellEllipsoidXTModel.__name__] = CoreShellEllipsoidXTModel
474#        self.shape_list.append(CoreShellEllipsoidXTModel)
475        self.multiplication_factor.append(CoreShellEllipsoidXTModel)
476        self.model_name_list.append(CoreShellEllipsoidXTModel.__name__)
[bb18ef1]477         
[79492222]478        from sas.models.TriaxialEllipsoidModel import TriaxialEllipsoidModel
[df7a7e3]479        self.model_dictionary[TriaxialEllipsoidModel.__name__] = TriaxialEllipsoidModel
[116e1a7]480#        self.shape_list.append(TriaxialEllipsoidModel)
[9002927]481        self.multiplication_factor.append(TriaxialEllipsoidModel)
[7c8d3093]482        self.model_name_list.append(TriaxialEllipsoidModel.__name__)
[e65050e]483       
[79492222]484        from sas.models.LamellarModel import LamellarModel
[df7a7e3]485        self.model_dictionary[LamellarModel.__name__] = LamellarModel
[116e1a7]486#        self.shape_list.append(LamellarModel)
[7c8d3093]487        self.model_name_list.append(LamellarModel.__name__)
[e65050e]488       
[79492222]489        from sas.models.LamellarFFHGModel import LamellarFFHGModel
[df7a7e3]490        self.model_dictionary[LamellarFFHGModel.__name__] = LamellarFFHGModel
[116e1a7]491#        self.shape_list.append(LamellarFFHGModel)
[7c8d3093]492        self.model_name_list.append(LamellarFFHGModel.__name__)
[e65050e]493       
[79492222]494        from sas.models.LamellarPSModel import LamellarPSModel
[df7a7e3]495        self.model_dictionary[LamellarPSModel.__name__] = LamellarPSModel
[116e1a7]496#        self.shape_list.append(LamellarPSModel)
[7c8d3093]497        self.model_name_list.append(LamellarPSModel.__name__)
[7a69683]498     
[79492222]499        from sas.models.LamellarPSHGModel import LamellarPSHGModel
[df7a7e3]500        self.model_dictionary[LamellarPSHGModel.__name__] = LamellarPSHGModel
[116e1a7]501#        self.shape_list.append(LamellarPSHGModel)
[7c8d3093]502        self.model_name_list.append(LamellarPSHGModel.__name__)
[fb59ed9]503       
[79492222]504        from sas.models.LamellarPCrystalModel import LamellarPCrystalModel
[df7a7e3]505        self.model_dictionary[LamellarPCrystalModel.__name__] = LamellarPCrystalModel
[116e1a7]506#        self.shape_list.append(LamellarPCrystalModel)
[7c8d3093]507        self.model_name_list.append(LamellarPCrystalModel.__name__)
[fb59ed9]508       
[79492222]509        from sas.models.SCCrystalModel import SCCrystalModel
[df7a7e3]510        self.model_dictionary[SCCrystalModel.__name__] = SCCrystalModel
[116e1a7]511#        self.shape_list.append(SCCrystalModel)
[7c8d3093]512        self.model_name_list.append(SCCrystalModel.__name__)
[fb59ed9]513       
[79492222]514        from sas.models.FCCrystalModel import FCCrystalModel
[df7a7e3]515        self.model_dictionary[FCCrystalModel.__name__] = FCCrystalModel
[116e1a7]516#        self.shape_list.append(FCCrystalModel)
[7c8d3093]517        self.model_name_list.append(FCCrystalModel.__name__)
[fb59ed9]518       
[79492222]519        from sas.models.BCCrystalModel import BCCrystalModel
[df7a7e3]520        self.model_dictionary[BCCrystalModel.__name__] = BCCrystalModel
[116e1a7]521#        self.shape_list.append(BCCrystalModel)
[7c8d3093]522        self.model_name_list.append(BCCrystalModel.__name__)
[7a69683]523     
[f32d144]524        ## Structure factor
[79492222]525        from sas.models.SquareWellStructure import SquareWellStructure
[df7a7e3]526        self.model_dictionary[SquareWellStructure.__name__] = SquareWellStructure
[bb18ef1]527        self.struct_list.append(SquareWellStructure)
[7c8d3093]528        self.model_name_list.append(SquareWellStructure.__name__)
[8346667]529       
[79492222]530        from sas.models.HardsphereStructure import HardsphereStructure
[df7a7e3]531        self.model_dictionary[HardsphereStructure.__name__] = HardsphereStructure
[bb18ef1]532        self.struct_list.append(HardsphereStructure)
[7c8d3093]533        self.model_name_list.append(HardsphereStructure.__name__)
[bb18ef1]534         
[79492222]535        from sas.models.StickyHSStructure import StickyHSStructure
[df7a7e3]536        self.model_dictionary[StickyHSStructure.__name__] = StickyHSStructure
[bb18ef1]537        self.struct_list.append(StickyHSStructure)
[7c8d3093]538        self.model_name_list.append(StickyHSStructure.__name__)
[8346667]539       
[79492222]540        from sas.models.HayterMSAStructure import HayterMSAStructure
[df7a7e3]541        self.model_dictionary[HayterMSAStructure.__name__] = HayterMSAStructure
[bb18ef1]542        self.struct_list.append(HayterMSAStructure)
[7c8d3093]543        self.model_name_list.append(HayterMSAStructure.__name__)
[a8d3b4f]544
545
[fb59ed9]546        ##shape-independent models
[79492222]547        from sas.models.PowerLawAbsModel import PowerLawAbsModel
[df7a7e3]548        self.model_dictionary[PowerLawAbsModel.__name__] = PowerLawAbsModel
[116e1a7]549#        self.shape_indep_list.append(PowerLawAbsModel)
[7c8d3093]550        self.model_name_list.append(PowerLawAbsModel.__name__)
[ce07fa8]551       
[79492222]552        from sas.models.BEPolyelectrolyte import BEPolyelectrolyte
[df7a7e3]553        self.model_dictionary[BEPolyelectrolyte.__name__] = BEPolyelectrolyte
[116e1a7]554#        self.shape_indep_list.append(BEPolyelectrolyte)
[7c8d3093]555        self.model_name_list.append(BEPolyelectrolyte.__name__)
[bb18ef1]556        self.form_factor_dict[str(wx.NewId())] =  [SphereModel]
[fb59ed9]557       
[79492222]558        from sas.models.BroadPeakModel import BroadPeakModel
[df7a7e3]559        self.model_dictionary[BroadPeakModel.__name__] = BroadPeakModel
[116e1a7]560#        self.shape_indep_list.append(BroadPeakModel)
[7c8d3093]561        self.model_name_list.append(BroadPeakModel.__name__)
[fb59ed9]562       
[79492222]563        from sas.models.CorrLengthModel import CorrLengthModel
[df7a7e3]564        self.model_dictionary[CorrLengthModel.__name__] = CorrLengthModel
[116e1a7]565#        self.shape_indep_list.append(CorrLengthModel)
[7c8d3093]566        self.model_name_list.append(CorrLengthModel.__name__)
[fb59ed9]567       
[79492222]568        from sas.models.DABModel import DABModel
[df7a7e3]569        self.model_dictionary[DABModel.__name__] = DABModel
[116e1a7]570#        self.shape_indep_list.append(DABModel)
[7c8d3093]571        self.model_name_list.append(DABModel.__name__)
[442895f]572       
[79492222]573        from sas.models.DebyeModel import DebyeModel
[df7a7e3]574        self.model_dictionary[DebyeModel.__name__] = DebyeModel
[116e1a7]575#        self.shape_indep_list.append(DebyeModel)
[7c8d3093]576        self.model_name_list.append(DebyeModel.__name__)
[ce07fa8]577       
[79492222]578        from sas.models.FractalModel import FractalModel
[df7a7e3]579        self.model_dictionary[FractalModel.__name__] = FractalModel
[116e1a7]580#        self.shape_indep_list.append(FractalModel)
[7c8d3093]581        self.model_name_list.append(FractalModel.__name__)
[bb18ef1]582       
[79492222]583        from sas.models.FractalCoreShellModel import FractalCoreShellModel
[df7a7e3]584        self.model_dictionary[FractalCoreShellModel.__name__] = FractalCoreShellModel
[116e1a7]585#        self.shape_indep_list.append(FractalCoreShellModel)
[7c8d3093]586        self.model_name_list.append(FractalCoreShellModel.__name__)
[fb59ed9]587       
[79492222]588        from sas.models.GaussLorentzGelModel import GaussLorentzGelModel
[df7a7e3]589        self.model_dictionary[GaussLorentzGelModel.__name__] = GaussLorentzGelModel
[116e1a7]590#        self.shape_indep_list.append(GaussLorentzGelModel)
[7c8d3093]591        self.model_name_list.append(GaussLorentzGelModel.__name__)
[fb59ed9]592               
[79492222]593        from sas.models.GuinierModel import GuinierModel
[df7a7e3]594        self.model_dictionary[GuinierModel.__name__] = GuinierModel
[116e1a7]595#        self.shape_indep_list.append(GuinierModel)
[7c8d3093]596        self.model_name_list.append(GuinierModel.__name__)
[fb59ed9]597       
[79492222]598        from sas.models.GuinierPorodModel import GuinierPorodModel
[df7a7e3]599        self.model_dictionary[GuinierPorodModel.__name__] = GuinierPorodModel
[116e1a7]600#        self.shape_indep_list.append(GuinierPorodModel)
[7c8d3093]601        self.model_name_list.append(GuinierPorodModel.__name__)
[fb59ed9]602
[79492222]603        from sas.models.LorentzModel import LorentzModel
[df7a7e3]604        self.model_dictionary[LorentzModel.__name__] = LorentzModel
[116e1a7]605#        self.shape_indep_list.append(LorentzModel)
[7c8d3093]606        self.model_name_list.append(LorentzModel.__name__)
[51da9dc]607
[79492222]608        from sas.models.MassFractalModel import MassFractalModel
[df7a7e3]609        self.model_dictionary[MassFractalModel.__name__] = MassFractalModel
[116e1a7]610#        self.shape_indep_list.append(MassFractalModel)
[51da9dc]611        self.model_name_list.append(MassFractalModel.__name__)
612       
[79492222]613        from sas.models.MassSurfaceFractal import MassSurfaceFractal
[df7a7e3]614        self.model_dictionary[MassSurfaceFractal.__name__] = MassSurfaceFractal
[116e1a7]615#        self.shape_indep_list.append(MassSurfaceFractal)
[51da9dc]616        self.model_name_list.append(MassSurfaceFractal.__name__)
[442895f]617       
[79492222]618        from sas.models.PeakGaussModel import PeakGaussModel
[df7a7e3]619        self.model_dictionary[PeakGaussModel.__name__] = PeakGaussModel
[116e1a7]620#        self.shape_indep_list.append(PeakGaussModel)
[7c8d3093]621        self.model_name_list.append(PeakGaussModel.__name__)
[cee6867]622       
[79492222]623        from sas.models.PeakLorentzModel import PeakLorentzModel
[df7a7e3]624        self.model_dictionary[PeakLorentzModel.__name__] = PeakLorentzModel
[116e1a7]625#        self.shape_indep_list.append(PeakLorentzModel)
[f32d144]626        self.model_name_list.append(PeakLorentzModel.__name__)
[cee6867]627       
[79492222]628        from sas.models.Poly_GaussCoil import Poly_GaussCoil
[df7a7e3]629        self.model_dictionary[Poly_GaussCoil.__name__] = Poly_GaussCoil
[116e1a7]630#        self.shape_indep_list.append(Poly_GaussCoil)
[7c8d3093]631        self.model_name_list.append(Poly_GaussCoil.__name__)
[fb59ed9]632       
[79492222]633        from sas.models.PolymerExclVolume import PolymerExclVolume
[df7a7e3]634        self.model_dictionary[PolymerExclVolume.__name__] = PolymerExclVolume
[116e1a7]635#        self.shape_indep_list.append(PolymerExclVolume)
[7c8d3093]636        self.model_name_list.append(PolymerExclVolume.__name__)
[fb59ed9]637       
[79492222]638        from sas.models.PorodModel import PorodModel
[df7a7e3]639        self.model_dictionary[PorodModel.__name__] = PorodModel
[116e1a7]640#        self.shape_indep_list.append(PorodModel)
[f32d144]641        self.model_name_list.append(PorodModel.__name__)
[442895f]642       
[79492222]643        from sas.models.RPA10Model import RPA10Model
[df7a7e3]644        self.model_dictionary[RPA10Model.__name__] = RPA10Model
[116e1a7]645#        self.shape_indep_list.append(RPA10Model)
[fb59ed9]646        self.multi_func_list.append(RPA10Model)
[51da9dc]647
[79492222]648        from sas.models.StarPolymer import StarPolymer
[df7a7e3]649        self.model_dictionary[StarPolymer.__name__] = StarPolymer
[116e1a7]650#        self.shape_indep_list.append(StarPolymer)
[082c565]651        self.model_name_list.append(StarPolymer.__name__)
652
[79492222]653        from sas.models.SurfaceFractalModel import SurfaceFractalModel
[df7a7e3]654        self.model_dictionary[SurfaceFractalModel.__name__] = SurfaceFractalModel
[116e1a7]655#        self.shape_indep_list.append(SurfaceFractalModel)
[51da9dc]656        self.model_name_list.append(SurfaceFractalModel.__name__)
[81bece4]657       
[79492222]658        from sas.models.TeubnerStreyModel import TeubnerStreyModel
[df7a7e3]659        self.model_dictionary[TeubnerStreyModel.__name__] = TeubnerStreyModel
[116e1a7]660#        self.shape_indep_list.append(TeubnerStreyModel)
[7c8d3093]661        self.model_name_list.append(TeubnerStreyModel.__name__)
[a269378]662
[79492222]663        from sas.models.TwoLorentzianModel import TwoLorentzianModel
[df7a7e3]664        self.model_dictionary[TwoLorentzianModel.__name__] = TwoLorentzianModel
[116e1a7]665#        self.shape_indep_list.append(TwoLorentzianModel)
[7c8d3093]666        self.model_name_list.append(TwoLorentzianModel.__name__)
[fb59ed9]667       
[79492222]668        from sas.models.TwoPowerLawModel import TwoPowerLawModel
[df7a7e3]669        self.model_dictionary[TwoPowerLawModel.__name__] = TwoPowerLawModel
[116e1a7]670#        self.shape_indep_list.append(TwoPowerLawModel)
[7c8d3093]671        self.model_name_list.append(TwoPowerLawModel.__name__)
[fb59ed9]672       
[79492222]673        from sas.models.UnifiedPowerRgModel import UnifiedPowerRgModel
[df7a7e3]674        self.model_dictionary[UnifiedPowerRgModel.__name__] = UnifiedPowerRgModel
[116e1a7]675#        self.shape_indep_list.append(UnifiedPowerRgModel)
[fb59ed9]676        self.multi_func_list.append(UnifiedPowerRgModel)
[5da3cc5]677
[79492222]678        from sas.models.LineModel import LineModel
[df7a7e3]679        self.model_dictionary[LineModel.__name__] = LineModel
[116e1a7]680#        self.shape_indep_list.append(LineModel)
[7c8d3093]681        self.model_name_list.append(LineModel.__name__)
[5062bbf]682       
[79492222]683        from sas.models.ReflectivityModel import ReflectivityModel
[df7a7e3]684        self.model_dictionary[ReflectivityModel.__name__] = ReflectivityModel
[116e1a7]685#        self.shape_indep_list.append(ReflectivityModel)
[fb59ed9]686        self.multi_func_list.append(ReflectivityModel)
[1cc23fd]687       
[79492222]688        from sas.models.ReflectivityIIModel import ReflectivityIIModel
[df7a7e3]689        self.model_dictionary[ReflectivityIIModel.__name__] = ReflectivityIIModel
[116e1a7]690#        self.shape_indep_list.append(ReflectivityIIModel)
[1cc23fd]691        self.multi_func_list.append(ReflectivityIIModel)
[0da4eba]692       
[79492222]693        from sas.models.GelFitModel import GelFitModel
[df7a7e3]694        self.model_dictionary[GelFitModel.__name__] = GelFitModel
[116e1a7]695#        self.shape_indep_list.append(GelFitModel)
[0da4eba]696        self.model_name_list.append(GelFitModel.__name__)
[657e52c]697
[79492222]698        from sas.models.PringlesModel import PringlesModel
[a9fec15]699        self.model_dictionary[PringlesModel.__name__] = PringlesModel
[116e1a7]700#        self.shape_indep_list.append(PringlesModel)
[a9fec15]701        self.model_name_list.append(PringlesModel.__name__)
702
[79492222]703        from sas.models.RectangularPrismModel import RectangularPrismModel
[201af9f]704        self.model_dictionary[RectangularPrismModel.__name__] = RectangularPrismModel
[116e1a7]705#        self.shape_list.append(RectangularPrismModel)
[201af9f]706        self.multiplication_factor.append(RectangularPrismModel)
707        self.model_name_list.append(RectangularPrismModel.__name__)
708
[79492222]709        from sas.models.RectangularHollowPrismInfThinWallsModel import RectangularHollowPrismInfThinWallsModel
[201af9f]710        self.model_dictionary[RectangularHollowPrismInfThinWallsModel.__name__] = RectangularHollowPrismInfThinWallsModel
[116e1a7]711#        self.shape_list.append(RectangularHollowPrismInfThinWallsModel)
[201af9f]712        self.multiplication_factor.append(RectangularHollowPrismInfThinWallsModel)
713        self.model_name_list.append(RectangularHollowPrismInfThinWallsModel.__name__)
714
[79492222]715        from sas.models.RectangularHollowPrismModel import RectangularHollowPrismModel
[201af9f]716        self.model_dictionary[RectangularHollowPrismModel.__name__] = RectangularHollowPrismModel
[116e1a7]717#        self.shape_list.append(RectangularHollowPrismModel)
[201af9f]718        self.multiplication_factor.append(RectangularHollowPrismModel)
719        self.model_name_list.append(RectangularHollowPrismModel.__name__)
720
[79492222]721        from sas.models.MicelleSphCoreModel import MicelleSphCoreModel
[0d41aeed]722        self.model_dictionary[MicelleSphCoreModel.__name__] = MicelleSphCoreModel
723#        self.shape_list.append(MicelleSphCoreModel)
724        self.multiplication_factor.append(MicelleSphCoreModel)
725        self.model_name_list.append(MicelleSphCoreModel.__name__)
726
727
[79492222]728        #from sas.models.FractalO_Z import FractalO_Z
[df7a7e3]729        #self.model_dictionary[FractalO_Z.__name__] = FractalO_Z
730        #self.shape_indep_list.append(FractalO_Z)
731        #self.model_name_list.append(FractalO_Z.__name__)
732   
[49b7efa]733        #Looking for plugins
[9466f2d6]734        self.stored_plugins = self.findModels()
[b2d9826]735        self.plugins = self.stored_plugins.values()
[ea5fa58]736        for name, plug in self.stored_plugins.iteritems():
737            self.model_dictionary[name] = plug
738           
[b2d9826]739        self._get_multifunc_models()
740       
[d89f09b]741        return 0
742
[9466f2d6]743    def is_changed(self):
744        """
745        check the last time the plugin dir has changed and return true
746         is the directory was modified else return false
747        """
748        is_modified = False
[96814e1]749        plugin_dir = find_plugins_dir()
750        if os.path.isdir(plugin_dir):
[f32d144]751            temp = os.path.getmtime(plugin_dir)
[9466f2d6]752            if  self.last_time_dir_modified != temp:
753                is_modified = True
754                self.last_time_dir_modified = temp
[bb9f322]755       
[9466f2d6]756        return is_modified
[d89f09b]757   
[b2d9826]758    def update(self):
759        """
[f32d144]760        return a dictionary of model if
[9466f2d6]761        new models were added else return empty dictionary
[b2d9826]762        """
[9466f2d6]763        new_plugins = self.findModels()
764        if len(new_plugins) > 0:
765            for name, plug in  new_plugins.iteritems():
766                if name not in self.stored_plugins.keys():
767                    self.stored_plugins[name] = plug
768                    self.plugins.append(plug)
[ea5fa58]769                    self.model_dictionary[name] = plug
[9466f2d6]770            self.model_combobox.set_list("Customized Models", self.plugins)
771            return self.model_combobox.get_list()
772        else:
773            return {}
[5d1c1f4]774   
[916f5c0]775    def pulgins_reset(self):
776        """
777        return a dictionary of model
778        """
779        self.plugins = []
780        new_plugins = _findModels(dir)
781        for name, plug in  new_plugins.iteritems():
782            for stored_name, stored_plug in self.stored_plugins.iteritems():
783                if name == stored_name:
784                    del self.stored_plugins[name]
[ea5fa58]785                    del self.model_dictionary[name]
[916f5c0]786                    break
787            self.stored_plugins[name] = plug
788            self.plugins.append(plug)
[ea5fa58]789            self.model_dictionary[name] = plug
[19e614a]790
[916f5c0]791        self.model_combobox.reset_list("Customized Models", self.plugins)
792        return self.model_combobox.get_list()
793       
[116e1a7]794##   I believe the next four methods are for the old form factor GUI
795##   where the dropdown showed a list of categories which then rolled out
796##   in a second dropdown to the side. Some testing shows they indeed no longer
797##   seem to be called.  If no problems are found during testing of release we
798##   can remove this huge chunck of stuff.
799##
800##   -PDB  April 26, 2014
801
802#   def populate_menu(self, modelmenu, event_owner):
803#       """
804#       Populate a menu with our models
805#       
806#       :param id: first menu event ID to use when binding the menu events
807#       :param modelmenu: wx.Menu object to populate
808#       :param event_owner: wx object to bind the menu events to
809#       
810#       :return: the next free event ID following the new menu events
811#       
812#       """
813#
[bb18ef1]814        ## Fill model lists
[116e1a7]815#        self._getModelList()
[bb18ef1]816        ## store reference to model menu of guiframe
[116e1a7]817#        self.modelmenu = modelmenu
[bb18ef1]818        ## guiframe reference
[116e1a7]819#        self.event_owner = event_owner
[bb18ef1]820       
[116e1a7]821#        shape_submenu = wx.Menu()
822#        shape_indep_submenu = wx.Menu()
823#        structure_factor = wx.Menu()
824#        added_models = wx.Menu()
825#        multip_models = wx.Menu()
[bb18ef1]826        ## create menu with shape
[116e1a7]827#        self._fill_simple_menu(menuinfo=["Shapes",
828#                                         shape_submenu,
829#                                         " simple shape"],
830#                         list1=self.shape_list)
831       
832#        self._fill_simple_menu(menuinfo=["Shape-Independent",
833#                                         shape_indep_submenu,
834#                                         "List of shape-independent models"],
835#                         list1=self.shape_indep_list)
836       
837#        self._fill_simple_menu(menuinfo=["Structure Factors",
838#                                         structure_factor,
839#                                         "List of Structure factors models"],
840#                                list1=self.struct_list)
841       
842#        self._fill_plugin_menu(menuinfo=["Customized Models", added_models,
843#                                            "List of additional models"],
844#                                 list1=self.plugins)
845       
846#        self._fill_menu(menuinfo=["P(Q)*S(Q)", multip_models,
847#                                  "mulplication of 2 models"],
848#                                   list1=self.multiplication_factor,
849#                                   list2=self.struct_list)
850#        return 0
[d89f09b]851   
[116e1a7]852#    def _fill_plugin_menu(self, menuinfo, list1):
853#        """
854#        fill the plugin menu with costumized models
855#        """
856#        print ("got to fill plugin menu")
857#        if len(list1) == 0:
858#            id = wx.NewId()
859#            msg = "No model available check plugins.log for errors to fix problem"
860#            menuinfo[1].Append(int(id), "Empty", msg)
861#        self._fill_simple_menu(menuinfo, list1)
862       
863#   def _fill_simple_menu(self, menuinfo, list1):
864#       """
865#       Fill the menu with list item
866#       
867#       :param modelmenu: the menu to fill
868#       :param menuinfo: submenu item for the first column of this modelmenu
869#                        with info.Should be a list :
870#                        [name(string) , menu(wx.menu), help(string)]
871#       :param list1: contains item (form factor )to fill modelmenu second column
872#       
873#       """
874#       if len(list1) > 0:
875#           self.model_combobox.set_list(menuinfo[0], list1)
[e7b1ccf]876           
[116e1a7]877#            for item in list1:
878#                try:
879#                    id = wx.NewId()
880#                    struct_factor = item()
881#                    struct_name = struct_factor.__class__.__name__
882#                    if hasattr(struct_factor, "name"):
883#                        struct_name = struct_factor.name
884#                       
885#                    menuinfo[1].Append(int(id), struct_name, struct_name)
886#                    if not  item in self.struct_factor_dict.itervalues():
887#                        self.struct_factor_dict[str(id)] = item
888#                    wx.EVT_MENU(self.event_owner, int(id), self._on_model)
889#                except:
890#                    msg = "Error Occured: %s" % sys.exc_value
891#                    wx.PostEvent(self.event_owner, StatusEvent(status=msg))
892#               
893#        id = wx.NewId()
894#        self.modelmenu.AppendMenu(id, menuinfo[0], menuinfo[1], menuinfo[2])
895#       
896#    def _fill_menu(self, menuinfo, list1, list2):
897#        """
898#        Fill the menu with list item
899#       
900#        :param menuinfo: submenu item for the first column of this modelmenu
901#                         with info.Should be a list :
902#                         [name(string) , menu(wx.menu), help(string)]
903#        :param list1: contains item (form factor )to fill modelmenu second column
904#        :param list2: contains item (Structure factor )to fill modelmenu
905#                third column
906#               
907#        """
908#        if len(list1) > 0:
909#            self.model_combobox.set_list(menuinfo[0], list1)
910#           
911#            for item in list1:
912#                form_factor = item()
913#                form_name = form_factor.__class__.__name__
914#                if hasattr(form_factor, "name"):
915#                    form_name = form_factor.name
916#                ### store form factor to return to other users
917#                newmenu = wx.Menu()
918#                if len(list2) > 0:
919#                    for model  in list2:
920#                        id = wx.NewId()
921#                        struct_factor = model()
922#                        name = struct_factor.__class__.__name__
923#                        if hasattr(struct_factor, "name"):
924#                            name = struct_factor.name
925#                        newmenu.Append(id, name, name)
926#                        wx.EVT_MENU(self.event_owner, int(id), self._on_model)
927#                        ## save form_fact and struct_fact
928#                        self.form_factor_dict[int(id)] = [form_factor,
929#                                                          struct_factor]
930#                       
931#                form_id = wx.NewId()
932#                menuinfo[1].AppendMenu(int(form_id), form_name,
933#                                       newmenu, menuinfo[2])
934#        id = wx.NewId()
935#        self.modelmenu.AppendMenu(id, menuinfo[0], menuinfo[1], menuinfo[2])
[bb18ef1]936       
[d89f09b]937    def _on_model(self, evt):
938        """
[5062bbf]939        React to a model menu event
940       
941        :param event: wx menu event
942       
[d89f09b]943        """
[bb18ef1]944        if int(evt.GetId()) in self.form_factor_dict.keys():
[79492222]945            from sas.models.MultiplicationModel import MultiplicationModel
[df7a7e3]946            self.model_dictionary[MultiplicationModel.__name__] = MultiplicationModel
[bb18ef1]947            model1, model2 = self.form_factor_dict[int(evt.GetId())]
[f32d144]948            model = MultiplicationModel(model1, model2)
[bb18ef1]949        else:
[f32d144]950            model = self.struct_factor_dict[str(evt.GetId())]()
[61184df]951       
952        #TODO: investigate why the following two lines were left in the code
953        #      even though the ModelEvent class doesn't exist
954        #evt = ModelEvent(model=model)
955        #wx.PostEvent(self.event_owner, evt)
[d89f09b]956       
[fb59ed9]957    def _get_multifunc_models(self):
958        """
959        Get the multifunctional models
960        """
961        for item in self.plugins:
962            try:
963                # check the multiplicity if any
964                if item.multiplicity_info[0] > 1:
965                    self.multi_func_list.append(item)
966            except:
967                # pass to other items
968                pass
969                   
[f32d144]970    def get_model_list(self):
[5062bbf]971        """
[f32d144]972        return dictionary of models for fitpanel use
[5062bbf]973       
974        """
[116e1a7]975        ## Model_list now only contains attribute lists not category list.
976        ## Eventually this should be in one master list -- read in category
977        ## list then pull those models that exist and get attributes then add
978        ## to list ..and if model does not exist remove from list as now
979        ## and update json file.
980        ##
981        ## -PDB   April 26, 2014
982       
983#        self.model_combobox.set_list("Shapes", self.shape_list)
984#        self.model_combobox.set_list("Shape-Independent",
985#                                     self.shape_indep_list)
[6bbeacd4]986        self.model_combobox.set_list("Structure Factors", self.struct_list)
987        self.model_combobox.set_list("Customized Models", self.plugins)
988        self.model_combobox.set_list("P(Q)*S(Q)", self.multiplication_factor)
[f32d144]989        self.model_combobox.set_list("multiplication",
990                                     self.multiplication_factor)
[e87f9fc]991        self.model_combobox.set_list("Multi-Functions", self.multi_func_list)
[b2d9826]992        return self.model_combobox.get_list()
[d89f09b]993   
[7c8d3093]994    def get_model_name_list(self):
995        """
996        return regular model name list
997        """
998        return self.model_name_list
[df7a7e3]999
1000    def get_model_dictionary(self):
1001        """
1002        return dictionary linking model names to objects
1003        """
1004        return self.model_dictionary
[376916c]1005 
[bb18ef1]1006       
[bb9f322]1007class ModelManager(object):
1008    """
[f32d144]1009    implement model
[bb9f322]1010    """
1011    __modelmanager = ModelManagerBase()
[657e52c]1012    cat_model_list = [model_name for model_name \
1013                      in __modelmanager.model_dictionary.keys() \
1014                      if model_name not in __modelmanager.stored_plugins.keys()]
1015
1016    CategoryInstaller.check_install(model_list=cat_model_list)
[bb9f322]1017    def findModels(self):
1018        return self.__modelmanager.findModels()
1019   
1020    def _getModelList(self):
1021        return self.__modelmanager._getModelList()
1022   
1023    def is_changed(self):
1024        return self.__modelmanager.is_changed()
1025   
1026    def update(self):
1027        return self.__modelmanager.update()
1028   
[916f5c0]1029    def pulgins_reset(self):
1030        return self.__modelmanager.pulgins_reset()
1031   
[bb9f322]1032    def populate_menu(self, modelmenu, event_owner):
1033        return self.__modelmanager.populate_menu(modelmenu, event_owner)
1034   
1035    def _on_model(self, evt):
1036        return self.__modelmanager._on_model(evt)
1037   
1038    def _get_multifunc_models(self):
1039        return self.__modelmanager._get_multifunc_models()
1040   
[f32d144]1041    def get_model_list(self):
[bb9f322]1042        return self.__modelmanager.get_model_list()
[bb18ef1]1043   
[7c8d3093]1044    def get_model_name_list(self):
1045        return self.__modelmanager.get_model_name_list()
[df7a7e3]1046
1047    def get_model_dictionary(self):
1048        return self.__modelmanager.get_model_dictionary()
Note: See TracBrowser for help on using the repository browser.