Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Perspectives/Fitting/FittingWidget.py

    r0109f2a ra758043  
    4949 
    5050 
    51  
    5251TAB_MAGNETISM = 4 
    5352TAB_POLY = 3 
     
    6160 
    6261logger = logging.getLogger(__name__) 
    63  
    6462 
    6563class ToolTippedItemModel(QtGui.QStandardItemModel): 
     
    221219        # Utility variable to enable unselectable option in category combobox 
    222220        self._previous_category_index = 0 
    223         # Utility variables for multishell display 
    224         self._n_shells_row = 0 
    225         self._num_shell_params = 0 
     221        # Utility variable for multishell display 
     222        self._last_model_row = 0 
    226223        # Dictionary of {model name: model class} for the current category 
    227224        self.models = {} 
     
    268265        self.has_magnet_error_column = False 
    269266 
     267        # If the widget generated theory item, save it 
     268        self.theory_item = None 
     269 
    270270        # signal communicator 
    271271        self.communicate = self.parent.communicate 
     
    390390        # Tag along functionality 
    391391        self.label.setText("Data loaded from: ") 
    392         self.lblFilename.setText(self.logic.data.filename) 
     392        if self.logic.data.filename: 
     393            self.lblFilename.setText(self.logic.data.filename) 
     394        else: 
     395            self.lblFilename.setText(self.logic.data.name) 
    393396        self.updateQRange() 
    394397        # Switch off Data2D control 
     
    523526        # Signals from separate tabs asking for replot 
    524527        self.options_widget.plot_signal.connect(self.onOptionsUpdate) 
    525         self.options_widget.plot_signal.connect(self.onOptionsUpdate) 
    526528 
    527529        # Signals from other widgets 
     
    670672        Return list of all parameters for the current model 
    671673        """ 
    672         return [self._model_model.item(row).text() 
    673                 for row in range(self._model_model.rowCount()) 
    674                 if self.isCheckable(row)] 
     674        return [self._model_model.item(row).text() for row in range(self._model_model.rowCount())] 
    675675 
    676676    def modifyViewOnRow(self, row, font=None, brush=None): 
     
    700700        assert isinstance(constraint, Constraint) 
    701701        assert 0 <= row <= self._model_model.rowCount() 
    702         assert self.isCheckable(row) 
    703702 
    704703        item = QtGui.QStandardItem() 
     
    721720        max_col = self.lstParams.itemDelegate().param_max 
    722721        for row in self.selectedParameters(): 
    723             assert(self.isCheckable(row)) 
    724722            param = self._model_model.item(row, 0).text() 
    725723            value = self._model_model.item(row, 1).text() 
     
    764762        max_col = self.lstParams.itemDelegate().param_max 
    765763        for row in range(self._model_model.rowCount()): 
    766             if not self.isCheckable(row): 
    767                 continue 
    768764            if not self.rowHasConstraint(row): 
    769765                continue 
     
    794790        For the given row, return its constraint, if any 
    795791        """ 
    796         if self.isCheckable(row): 
     792        try: 
    797793            item = self._model_model.item(row, 1) 
    798             try: 
    799                 return item.child(0).data() 
    800             except AttributeError: 
    801                 # return none when no constraints 
    802                 pass 
    803         return None 
     794            return item.child(0).data() 
     795        except AttributeError: 
     796            # return none when no constraints 
     797            return None 
    804798 
    805799    def rowHasConstraint(self, row): 
     
    807801        Finds out if row of the main model has a constraint child 
    808802        """ 
    809         if self.isCheckable(row): 
    810             item = self._model_model.item(row, 1) 
    811             if item.hasChildren(): 
    812                 c = item.child(0).data() 
    813                 if isinstance(c, Constraint): 
    814                     return True 
     803        item = self._model_model.item(row, 1) 
     804        if item.hasChildren(): 
     805            c = item.child(0).data() 
     806            if isinstance(c, Constraint): 
     807                return True 
    815808        return False 
    816809 
     
    819812        Finds out if row of the main model has an active constraint child 
    820813        """ 
    821         if self.isCheckable(row): 
    822             item = self._model_model.item(row, 1) 
    823             if item.hasChildren(): 
    824                 c = item.child(0).data() 
    825                 if isinstance(c, Constraint) and c.active: 
    826                     return True 
     814        item = self._model_model.item(row, 1) 
     815        if item.hasChildren(): 
     816            c = item.child(0).data() 
     817            if isinstance(c, Constraint) and c.active: 
     818                return True 
    827819        return False 
    828820 
     
    831823        Finds out if row of the main model has an active, nontrivial constraint child 
    832824        """ 
    833         if self.isCheckable(row): 
    834             item = self._model_model.item(row, 1) 
    835             if item.hasChildren(): 
    836                 c = item.child(0).data() 
    837                 if isinstance(c, Constraint) and c.func and c.active: 
    838                     return True 
     825        item = self._model_model.item(row, 1) 
     826        if item.hasChildren(): 
     827            c = item.child(0).data() 
     828            if isinstance(c, Constraint) and c.func and c.active: 
     829                return True 
    839830        return False 
    840831 
     
    964955        model = self.cbModel.currentText() 
    965956 
    966         # empty combobox forced to be read 
     957        # Assure the control is active 
     958        if not self.cbModel.isEnabled(): 
     959            return 
     960        # Empty combobox forced to be read 
    967961        if not model: 
    968962            return 
    969         # Reset structure factor 
    970         self.cbStructureFactor.setCurrentIndex(0) 
    971963 
    972964        # Reset parameters to fit 
     
    975967        self.has_poly_error_column = False 
    976968 
    977         self.respondToModelStructure(model=model, structure_factor=None) 
     969        structure = None 
     970        if self.cbStructureFactor.isEnabled(): 
     971            structure = str(self.cbStructureFactor.currentText()) 
     972        self.respondToModelStructure(model=model, structure_factor=structure) 
    978973 
    979974    def onSelectBatchFilename(self, data_index): 
     
    11181113            self.disableModelCombo() 
    11191114            self.enableStructureCombo() 
     1115            # set the index to 0 
     1116            self.cbStructureFactor.setCurrentIndex(0) 
     1117            self.model_parameters = None 
    11201118            self._model_model.clear() 
    11211119            return 
     
    11421140        model_row = item.row() 
    11431141        name_index = self._poly_model.index(model_row, 0) 
    1144         parameter_name = str(name_index.data()).lower() # "distribution of sld" etc. 
    1145         if "distribution of" in parameter_name: 
     1142        parameter_name = str(name_index.data()) # "distribution of sld" etc. 
     1143        if "istribution of" in parameter_name: 
    11461144            # just the last word 
    11471145            parameter_name = parameter_name.rsplit()[-1] 
     
    15091507            raise ValueError('Fitting requires at least one parameter to optimize.') 
    15101508 
    1511         # Potential smearing added 
    1512         # Remember that smearing_min/max can be None -> 
    1513         # deal with it until Python gets discriminated unions 
    1514         self.addWeightingToData(data) 
    1515  
    15161509        # Get the constraints. 
    15171510        constraints = self.getComplexConstraintsForModel() 
     
    15301523            data = GuiUtils.dataFromItem(fit_index) 
    15311524            # Potential weights added directly to data 
    1532             self.addWeightingToData(data) 
     1525            weighted_data = self.addWeightingToData(data) 
    15331526            try: 
    1534                 fitter_single.set_model(model, fit_id, params_to_fit, data=data, 
     1527                fitter_single.set_model(model, fit_id, params_to_fit, data=weighted_data, 
    15351528                             constraints=constraints) 
    15361529            except ValueError as ex: 
    15371530                raise ValueError("Setting model parameters failed with: %s" % ex) 
    15381531 
    1539             qmin, qmax, _ = self.logic.computeRangeFromData(data) 
    1540             fitter_single.set_data(data=data, id=fit_id, smearer=smearer, qmin=qmin, 
     1532            qmin, qmax, _ = self.logic.computeRangeFromData(weighted_data) 
     1533            fitter_single.set_data(data=weighted_data, id=fit_id, smearer=smearer, qmin=qmin, 
    15411534                            qmax=qmax) 
    15421535            fitter_single.select_problem_for_fit(id=fit_id, value=1) 
     
    15681561            # internal so can use closure for param_dict 
    15691562            param_name = str(self._model_model.item(row, 0).text()) 
    1570             if not self.isCheckable(row) or param_name not in list(param_dict.keys()): 
     1563            if param_name not in list(param_dict.keys()): 
    15711564                return 
    15721565            # modify the param value 
     
    15801573            # Utility function for updateof polydispersity part of the main model 
    15811574            param_name = str(self._model_model.item(row, 0).text())+'.width' 
    1582             if not self.isCheckable(row) or param_name not in list(param_dict.keys()): 
     1575            if param_name not in list(param_dict.keys()): 
    15831576                return 
    15841577            # modify the param value 
     
    19291922        Adds weighting contribution to fitting data 
    19301923        """ 
     1924        new_data = copy.deepcopy(data) 
    19311925        # Send original data for weighting 
    19321926        weight = FittingUtilities.getWeight(data=data, is2d=self.is2D, flag=self.weighting) 
    19331927        if self.is2D: 
    1934             data.err_data = weight 
     1928            new_data.err_data = weight 
    19351929        else: 
    1936             data.dy = weight 
    1937         pass 
     1930            new_data.dy = weight 
     1931 
     1932        return new_data 
    19381933 
    19391934    def updateQRange(self): 
     
    19551950        # Crete/overwrite model items 
    19561951        self._model_model.clear() 
    1957         self._poly_model.clear() 
    1958         self._magnet_model.clear() 
    1959  
    1960         if model_name is None: 
    1961             if structure_factor not in (None, "None"): 
    1962                 # S(Q) on its own, treat the same as a form factor 
    1963                 self.kernel_module = None 
     1952 
     1953        # First, add parameters from the main model 
     1954        if model_name is not None: 
     1955            self.fromModelToQModel(model_name) 
     1956 
     1957        # Then, add structure factor derived parameters 
     1958        if structure_factor is not None and structure_factor != "None": 
     1959            if model_name is None: 
     1960                # Instantiate the current sasmodel for SF-only models 
     1961                self.kernel_module = self.models[structure_factor]() 
     1962            self.fromStructureFactorToQModel(structure_factor) 
     1963        else: 
     1964            # Allow the SF combobox visibility for the given sasmodel 
     1965            self.enableStructureFactorControl(structure_factor) 
     1966            if self.cbStructureFactor.isEnabled(): 
     1967                structure_factor = self.cbStructureFactor.currentText() 
    19641968                self.fromStructureFactorToQModel(structure_factor) 
    1965             else: 
    1966                 # No models selected 
    1967                 return 
    1968         else: 
    1969             self.fromModelToQModel(model_name) 
     1969 
     1970        # Then, add multishells 
     1971        if model_name is not None: 
     1972            # Multishell models need additional treatment 
    19701973            self.addExtraShells() 
    19711974 
    1972             if structure_factor not in (None, "None"): 
    1973                 # add S(Q) 
    1974                 self.fromStructureFactorToQModel(structure_factor) 
    1975             else: 
    1976                 # enable selection of S(Q) 
    1977                 self.enableStructureFactorControl(structure_factor) 
    1978  
    1979             # Add polydispersity to the model 
    1980             self.setPolyModel() 
    1981             # Add magnetic parameters to the model 
    1982             self.setMagneticModel() 
     1975        # Add polydispersity to the model 
     1976        self.setPolyModel() 
     1977        # Add magnetic parameters to the model 
     1978        self.setMagneticModel() 
    19831979 
    19841980        # Adjust the table cells width 
     
    20052001        """ 
    20062002        name = model_name 
     2003        kernel_module = None 
    20072004        if self.cbCategory.currentText() == CATEGORY_CUSTOM: 
    20082005            # custom kernel load requires full path 
     
    20102007        try: 
    20112008            kernel_module = generate.load_kernel_module(name) 
    2012         except ModuleNotFoundError: 
    2013             # maybe it's a recategorised custom model? 
    2014             name = os.path.join(ModelUtilities.find_plugins_dir(), model_name+".py") 
    2015             # If this rises, it's a valid problem. 
    2016             kernel_module = generate.load_kernel_module(name) 
     2009        except ModuleNotFoundError as ex: 
     2010            pass 
     2011 
     2012        if kernel_module is None: 
     2013            # mismatch between "name" attribute and actual filename. 
     2014            curr_model = self.models[model_name] 
     2015            name, _ = os.path.splitext(os.path.basename(curr_model.filename)) 
     2016            try: 
     2017                kernel_module = generate.load_kernel_module(name) 
     2018            except ModuleNotFoundError as ex: 
     2019                logging.error("Can't find the model "+ str(ex)) 
     2020                return 
    20172021 
    20182022        if hasattr(kernel_module, 'parameters'): 
     
    20452049        self.shell_names = self.shellNamesList() 
    20462050 
    2047         # Get new rows for QModel 
    2048         new_rows = FittingUtilities.addParametersToModel(self.model_parameters, self.kernel_module, self.is2D) 
    2049  
    2050         # Add heading row 
    2051         FittingUtilities.addHeadingRowToModel(self._model_model, model_name) 
    2052  
    2053         # Update QModel 
    2054         for row in new_rows: 
    2055             self._model_model.appendRow(row) 
     2051        # Update the QModel 
     2052        FittingUtilities.addParametersToModel( 
     2053                self.model_parameters, 
     2054                self.kernel_module, 
     2055                self.is2D, 
     2056                self._model_model, 
     2057                self.lstParams) 
     2058 
     2059        # Update the counter used for multishell display 
     2060        self._last_model_row = self._model_model.rowCount() 
    20562061 
    20572062    def fromStructureFactorToQModel(self, structure_factor): 
     
    20592064        Setting model parameters into QStandardItemModel based on selected _structure factor_ 
    20602065        """ 
    2061         s_kernel = self.models[structure_factor]() 
    2062         p_kernel = self.kernel_module 
    2063  
    2064         if p_kernel is None: 
    2065             # Not a product model, just S(Q) 
    2066             self.kernel_module = s_kernel 
    2067             params = modelinfo.ParameterTable(self.kernel_module._model_info.parameters.kernel_parameters) 
    2068             new_rows = FittingUtilities.addSimpleParametersToModel(params, self.is2D) 
    2069         else: 
    2070             p_pars_len = len(p_kernel._model_info.parameters.kernel_parameters) 
    2071             s_pars_len = len(s_kernel._model_info.parameters.kernel_parameters) 
    2072  
    2073             self.kernel_module = MultiplicationModel(p_kernel, s_kernel) 
    2074             all_params = self.kernel_module._model_info.parameters.kernel_parameters 
    2075             all_param_names = [param.name for param in all_params] 
    2076  
    2077             # S(Q) params from the product model are not necessarily the same as those from the S(Q) model; any 
    2078             # conflicting names with P(Q) params will cause a rename; we also lose radius_effective (for now...) 
    2079  
    2080             # TODO: merge rest of beta approx implementation in 
    2081             # This is to ensure compatibility when we merge beta approx support in...! 
    2082  
    2083             # radius_effective is always s_params[0] 
    2084  
    2085             # if radius_effective_mode is in all_params, then all_params contains radius_effective and we want to 
    2086             # keep it in the model 
    2087  
    2088             # if radius_effective_mode is NOT in all_params, then radius_effective should NOT be kept, because the user 
    2089             # cannot specify it themselves; but, make sure we only remove it if it's actually there in the first place 
    2090             # (sasmodels master removes it already) 
    2091             if "radius_effective_mode" in all_param_names: 
    2092                 # Show all parameters 
    2093                 s_params = modelinfo.ParameterTable(all_params[p_pars_len:p_pars_len+s_pars_len]) 
    2094                 s_params_orig = modelinfo.ParameterTable(s_kernel._model_info.parameters.kernel_parameters) 
    2095             else: 
    2096                 # Ensure radius_effective is not displayed 
    2097                 s_params_orig = modelinfo.ParameterTable(s_kernel._model_info.parameters.kernel_parameters[1:]) 
    2098                 if "radius_effective" in all_param_names: 
    2099                     s_params = modelinfo.ParameterTable(all_params[p_pars_len+1:p_pars_len+s_pars_len]) 
    2100                 else: 
    2101                     s_params = modelinfo.ParameterTable(all_params[p_pars_len:p_pars_len+s_pars_len-1]) 
    2102  
    2103             # Get new rows for QModel 
    2104             # Any renamed parameters are stored as data in the relevant item, for later handling 
    2105             new_rows = FittingUtilities.addSimpleParametersToModel(s_params, self.is2D, s_params_orig) 
    2106  
    2107             # TODO: merge rest of beta approx implementation in 
    2108             # These parameters are not part of P(Q) nor S(Q), but are added only to the product model (e.g. specifying 
    2109             # structure factor calculation mode) 
    2110             # product_params = all_params[p_pars_len+s_pars_len:] 
    2111  
    2112         # Add heading row 
    2113         FittingUtilities.addHeadingRowToModel(self._model_model, structure_factor) 
    2114  
    2115         # Update QModel 
    2116         for row in new_rows: 
    2117             self._model_model.appendRow(row) 
    2118             # disable fitting of parameters not listed in self.kernel_module (probably radius_effective) 
    2119             # if row[0].text() not in self.kernel_module.params.keys(): 
    2120             #     row_num = self._model_model.rowCount() - 1 
    2121             #     FittingUtilities.markParameterDisabled(self._model_model, row_num) 
     2066        if structure_factor is None or structure_factor=="None": 
     2067            return 
     2068        structure_module = generate.load_kernel_module(structure_factor) 
     2069        structure_parameters = modelinfo.make_parameter_table(getattr(structure_module, 'parameters', [])) 
     2070 
     2071        structure_kernel = self.models[structure_factor]() 
     2072        form_kernel = self.kernel_module 
     2073 
     2074        self.kernel_module = MultiplicationModel(form_kernel, structure_kernel) 
     2075 
     2076        # Update the QModel 
     2077        FittingUtilities.addSimpleParametersToModel( 
     2078                structure_parameters, 
     2079                self.is2D, 
     2080                self._model_model, 
     2081                self.lstParams) 
     2082 
     2083        # Any parameters removed from the structure factor when producing the product model, e.g. radius_effective, must 
     2084        # be disabled (greyed out, etc.) 
     2085        for r in range(self._last_model_row, self._model_model.rowCount()): 
     2086            param_name = self._model_model.item(r, 0).text() 
     2087            if param_name not in self.kernel_module.params.keys(): 
     2088                FittingUtilities.markParameterDisabled(self._model_model, r) 
     2089 
     2090        # Update the counter used for multishell display 
     2091        self._last_model_row = self._model_model.rowCount() 
    21222092 
    21232093    def haveParamsToFit(self): 
     
    21452115        model_row = item.row() 
    21462116        name_index = self._model_model.index(model_row, 0) 
    2147         name_item = self._model_model.itemFromIndex(name_index) 
    21482117 
    21492118        # Extract changed value. 
     
    21542123            return 
    21552124 
    2156         # if the item has user data, this is the actual parameter name (e.g. to handle duplicate names) 
    2157         if name_item.data(QtCore.Qt.UserRole): 
    2158             parameter_name = str(name_item.data(QtCore.Qt.UserRole)) 
    2159         else: 
    2160             parameter_name = str(self._model_model.data(name_index)) 
     2125        parameter_name = str(self._model_model.data(name_index)) # sld, background etc. 
    21612126 
    21622127        # Update the parameter value - note: this supports +/-inf as well 
     
    22572222        name = self.nameFromData(fitted_data) 
    22582223        # Notify the GUI manager so it can create the theory model in DataExplorer 
    2259         new_item = GuiUtils.createModelItemWithPlot(fitted_data, name=name) 
    2260         self.communicate.updateTheoryFromPerspectiveSignal.emit(new_item) 
     2224        self.theory_item = GuiUtils.createModelItemWithPlot(fitted_data, name=name) 
     2225        self.communicate.updateTheoryFromPerspectiveSignal.emit(self.theory_item) 
    22612226 
    22622227    def nameFromData(self, fitted_data): 
     
    22922257            completefn = self.methodCompleteForData() 
    22932258        smearer = self.smearing_widget.smearer() 
     2259        weight = FittingUtilities.getWeight(data=data, is2d=self.is2D, flag=self.weighting) 
     2260 
    22942261        # Awful API to a backend method. 
    22952262        calc_thread = self.methodCalculateForData()(data=data, 
     
    23002267                                               smearer=smearer, 
    23012268                                               state=None, 
    2302                                                weight=None, 
     2269                                               weight=weight, 
    23032270                                               fid=None, 
    23042271                                               toggle_mode_on=False, 
     
    23482315        residuals = self.calculateResiduals(fitted_data) 
    23492316        self.model_data = fitted_data 
    2350  
    2351         new_plots = [fitted_data, residuals] 
     2317        new_plots = [fitted_data] 
     2318        if residuals is not None: 
     2319            new_plots.append(residuals) 
     2320 
     2321        if self.data_is_loaded: 
     2322            GuiUtils.deleteRedundantPlots(self.all_data[self.data_index], new_plots) 
     2323        else: 
     2324            # delete theory items for the model, in order to get rid of any redundant items, e.g. beta(Q), S_eff(Q) 
     2325            self.communicate.deleteIntermediateTheoryPlotsSignal.emit(self.kernel_module.id) 
    23522326 
    23532327        # Create plots for intermediate product data 
     
    23642338            new_plots.append(sq_data) 
    23652339 
    2366         if self.data_is_loaded: 
    2367             GuiUtils.deleteRedundantPlots(self.all_data[self.data_index], new_plots) 
    2368  
    2369         # TODO: merge rest of beta approx implementation in 
    2370         # TODO: refactor 
    2371         # deal with constrained radius_effective 
    2372         # for row in range(self._model_model.rowCount()): 
    2373         #     if self._model_model.item(row, 0).text() == "radius_effective_mode": 
    2374         #         if GuiUtils.toDouble(self._model_model.item(row, 1).text()) == 0: 
    2375         #             return 
    2376         # radius_effective = intermediate_ER() 
    2377         # if radius_effective: 
    2378         #     for row in range(self._model_model.rowCount()): 
    2379         #         if self._model_model.item(row, 0).text() == "radius_effective": 
    2380         #             self._model_model.item(row, 1).setText(str(radius_effective)) 
    2381         #             break 
    2382  
     2340        # Update/generate plots 
    23832341        for plot in new_plots: 
    2384             if hasattr(plot, "id") and "esidual" in plot.id: 
    2385                 # TODO: fix updates to residuals plot 
    2386                 pass 
    2387             elif plot is not None: 
    2388                 self.communicate.plotUpdateSignal.emit([plot]) 
     2342            self.communicate.plotUpdateSignal.emit([plot]) 
    23892343 
    23902344    def complete2D(self, return_data): 
     
    24042358 
    24052359        # Modify fitted_data with weighting 
    2406         self.addWeightingToData(fitted_data) 
    2407  
    2408         self.createNewIndex(fitted_data) 
     2360        weighted_data = self.addWeightingToData(fitted_data) 
     2361 
     2362        self.createNewIndex(weighted_data) 
    24092363        # Calculate difference between return_data and logic.data 
    2410         self.chi2 = FittingUtilities.calculateChi2(fitted_data, self.logic.data) 
     2364        self.chi2 = FittingUtilities.calculateChi2(weighted_data, self.logic.data) 
    24112365        # Update the control 
    24122366        chi2_repr = "---" if self.chi2 is None else GuiUtils.formatNumber(self.chi2, high=True) 
    24132367        self.lblChi2Value.setText(chi2_repr) 
    24142368 
    2415         # self.communicate.plotUpdateSignal.emit([fitted_data]) 
    2416  
    24172369        # Plot residuals if actual data 
    24182370        if not self.data_is_loaded: 
    24192371            return 
    24202372 
    2421         residuals_plot = FittingUtilities.plotResiduals(self.data, fitted_data) 
     2373        residuals_plot = FittingUtilities.plotResiduals(self.data, weighted_data) 
    24222374        residuals_plot.id = "Residual " + residuals_plot.id 
    24232375        self.createNewIndex(residuals_plot) 
     
    24882440        self._poly_model.clear() 
    24892441 
     2442        parameters = self.model_parameters.form_volume_parameters 
     2443        if self.is2D: 
     2444            parameters += self.model_parameters.orientation_parameters 
     2445 
    24902446        [self.setPolyModelParameters(i, param) for i, param in \ 
    2491             enumerate(self.model_parameters.form_volume_parameters) if param.polydisperse] 
     2447            enumerate(parameters) if param.polydisperse] 
     2448 
    24922449        FittingUtilities.addPolyHeadersToModel(self._poly_model) 
    24932450 
     
    25692526        def updateFunctionCaption(row): 
    25702527            # Utility function for update of polydispersity function name in the main model 
    2571             if not self.isCheckable(row): 
    2572                 return 
    25732528            param_name = str(self._model_model.item(row, 0).text()) 
    25742529            if param_name !=  param.name: 
     
    27372692 
    27382693        self.lstParams.setIndexWidget(shell_index, func) 
    2739         self._n_shells_row = shell_row - 1 
     2694        self._last_model_row = self._model_model.rowCount() 
    27402695 
    27412696        # Set the index to the state-kept value 
     
    27482703        """ 
    27492704        # Find row location of the combobox 
    2750         first_row = self._n_shells_row + 1 
    2751         remove_rows = self._num_shell_params 
     2705        last_row = self._last_model_row 
     2706        remove_rows = self._model_model.rowCount() - last_row 
    27522707 
    27532708        if remove_rows > 1: 
    2754             self._model_model.removeRows(first_row, remove_rows) 
    2755  
    2756         new_rows = FittingUtilities.addShellsToModel(self.model_parameters, self._model_model, index, first_row) 
    2757         self._num_shell_params = len(new_rows) 
     2709            self._model_model.removeRows(last_row, remove_rows) 
     2710 
     2711        FittingUtilities.addShellsToModel( 
     2712                self.model_parameters, 
     2713                self._model_model, 
     2714                index, 
     2715                self.lstParams) 
    27582716 
    27592717        self.current_shell_displayed = index 
     
    28762834        # TODO: add polidyspersity and magnetism 
    28772835 
    2878  
    28792836    def updateUndo(self): 
    28802837        """ 
     
    29132870        if self.all_data: 
    29142871            index = self.all_data[self.data_index] 
     2872        else: 
     2873            index = self.theory_item 
    29152874        report_logic = ReportPageLogic(self, 
    29162875                                       kernel_module=self.kernel_module, 
     
    30362995        # first - regular params 
    30372996        param_list = [] 
     2997 
     2998        param_list.append(['model_name', str(self.cbModel.currentText())]) 
    30382999        def gatherParams(row): 
    30393000            """ 
     
    31223083        if lines[0] != 'sasview_parameter_values': 
    31233084            return False 
    3124         for line in lines[1:-1]: 
     3085 
     3086        model = lines[1].split(',') 
     3087 
     3088        if model[0] != 'model_name': 
     3089            return False 
     3090 
     3091        context['model_name'] = [model[1]] 
     3092        for line in lines[2:-1]: 
    31253093            if len(line) != 0: 
    31263094                item = line.split(',') 
     
    31483116                    except IndexError: 
    31493117                        pass 
     3118 
     3119        if str(self.cbModel.currentText()) != str(context['model_name'][0]): 
     3120            msg = QtWidgets.QMessageBox() 
     3121            msg.setIcon(QtWidgets.QMessageBox.Information) 
     3122            msg.setText("The model in the clipboard is not the same as the currently loaded model. \ 
     3123                         Not all parameters saved may paste correctly.") 
     3124            msg.setStandardButtons(QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel) 
     3125            result = msg.exec_() 
     3126            if result == QtWidgets.QMessageBox.Ok: 
     3127                pass 
     3128            else: 
     3129                return 
    31503130 
    31513131        self.updateFullModel(context) 
     
    31863166            param_repr = GuiUtils.formatNumber(param_dict[param_name][3+ioffset], high=True) 
    31873167            self._model_model.item(row, 3+ioffset).setText(param_repr) 
     3168            self.setFocus() 
     3169 
    31883170 
    31893171        # block signals temporarily, so we don't end up 
     
    31923174        self.iterateOverModel(updateFittedValues) 
    31933175        self._model_model.blockSignals(False) 
     3176 
    31943177 
    31953178    def updateFullPolyModel(self, param_dict): 
     
    32363219            param_repr = GuiUtils.formatNumber(param_dict[param_name][5+ioffset], high=True) 
    32373220            self._poly_model.item(row, 5+ioffset).setText(param_repr) 
     3221            self.setFocus() 
    32383222 
    32393223        # block signals temporarily, so we don't end up 
     
    32433227        self._poly_model.blockSignals(False) 
    32443228 
    3245  
Note: See TracChangeset for help on using the changeset viewer.