Ignore:
Timestamp:
Nov 14, 2018 5:43:28 AM (5 years ago)
Author:
Piotr Rozyczko <piotr.rozyczko@…>
Branches:
ESS_GUI, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
ecc5d043
Parents:
e5ae812
Message:

Added Edit to single page constraint SASVIEW-1043

File:
1 edited

Legend:

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

    re5ae812 rbaeac95  
    622622        to_string = "to its current value" if num_rows == 1 else "to their current values" 
    623623        has_constraints = any([self.rowHasConstraint(i) for i in rows]) 
     624        has_real_constraints = any([self.rowHasActiveConstraint(i) for i in rows]) 
    624625 
    625626        self.actionSelect = QtWidgets.QAction(self) 
     
    639640        self.actionRemoveConstraint.setText(QtCore.QCoreApplication.translate("self", "Remove constraint")) 
    640641 
     642        self.actionEditConstraint = QtWidgets.QAction(self) 
     643        self.actionEditConstraint.setObjectName("actionEditConstrain") 
     644        self.actionEditConstraint.setText(QtCore.QCoreApplication.translate("self", "Edit constraint")) 
     645 
    641646        self.actionMultiConstrain = QtWidgets.QAction(self) 
    642647        self.actionMultiConstrain.setObjectName("actionMultiConstrain") 
     
    653658        if has_constraints: 
    654659            menu.addAction(self.actionRemoveConstraint) 
     660            if num_rows == 1 and has_real_constraints: 
     661                menu.addAction(self.actionEditConstraint) 
    655662            #if num_rows == 1: 
    656663            #    menu.addAction(self.actionEditConstraint) 
     
    663670        self.actionConstrain.triggered.connect(self.addSimpleConstraint) 
    664671        self.actionRemoveConstraint.triggered.connect(self.deleteConstraint) 
     672        self.actionEditConstraint.triggered.connect(self.editConstraint) 
    665673        self.actionMutualMultiConstrain.triggered.connect(self.showMultiConstraint) 
    666674        self.actionSelect.triggered.connect(self.selectParameters) 
     
    700708        new_func = c_text.replace(param_used, updated_param_used) 
    701709        constraint.func = new_func 
     710        constraint.value_ex = updated_param_used 
    702711        # Which row is the constrained parameter in? 
    703712        row = self.getRowFromName(constraint.param) 
     713 
     714        # what is the parameter to constraint to? 
     715        constraint.value = param_used 
    704716 
    705717        # Create a new item and add the Constraint object as a child 
     
    797809            self.modifyViewOnRow(row, font=font, brush=brush) 
    798810        self.communicate.statusBarUpdateSignal.emit('Constraint added') 
     811 
     812    def editConstraint(self): 
     813        """ 
     814        Delete constraints from selected parameters. 
     815        """ 
     816        params_list = [s.data() for s in self.lstParams.selectionModel().selectedRows() 
     817                   if self.isCheckable(s.row())] 
     818        assert len(params_list) == 1 
     819        row = self.lstParams.selectionModel().selectedRows()[0].row() 
     820        constraint = self.getConstraintForRow(row) 
     821        # Create and display the widget for param1 and param2 
     822        mc_widget = MultiConstraint(self, params=params_list, constraint=constraint) 
     823        # Check if any of the parameters are polydisperse 
     824        if not np.any([FittingUtilities.isParamPolydisperse(p, self.model_parameters, is2D=self.is2D) for p in params_list]): 
     825            # no parameters are pd - reset the text to not show the warning 
     826            mc_widget.lblWarning.setText("") 
     827        if mc_widget.exec_() != QtWidgets.QDialog.Accepted: 
     828            return 
     829 
     830        constraint = Constraint() 
     831        c_text = mc_widget.txtConstraint.text() 
     832 
     833        # widget.params[0] is the parameter we're constraining 
     834        constraint.param = mc_widget.params[0] 
     835        # parameter should have the model name preamble 
     836        model_name = self.kernel_module.name 
     837        # param_used is the parameter we're using in constraining function 
     838        param_used = mc_widget.params[1] 
     839        # Replace param_used with model_name.param_used 
     840        updated_param_used = model_name + "." + param_used 
     841        # Update constraint with new values 
     842        constraint.func = c_text 
     843        constraint.value_ex = updated_param_used 
     844        constraint.value = param_used 
     845 
     846        # Which row is the constrained parameter in? 
     847        row = self.getRowFromName(constraint.param) 
     848 
     849        # Create a new item and add the Constraint object as a child 
     850        self.addConstraintToRow(constraint=constraint, row=row) 
    799851 
    800852    def deleteConstraint(self): 
     
    36033655                value = constraint.value 
    36043656                func = constraint.func 
    3605                 cons = (value, func) 
     3657                value_ex = constraint.value_ex 
     3658                param = constraint.param 
     3659 
     3660                cons = (value, param, value_ex, func) 
    36063661 
    36073662            param_list.append([param_name, param_checked, param_value, param_error, param_min, param_max, cons]) 
     
    38533908            # constraints 
    38543909            cons = param_dict[param_name][4+ioffset] 
    3855             if cons is not None and cons: 
     3910            if cons is not None and len(cons)==4: 
    38563911                value = cons[0] 
    3857                 function = cons[1] 
     3912                param = cons[1] 
     3913                value_ex = cons[2] 
     3914                function = cons[3] 
    38583915                constraint = Constraint() 
    38593916                constraint.value = value 
    38603917                constraint.func = function 
     3918                constraint.param = param 
     3919                constraint.value_ex = value_ex 
    38613920                self.addConstraintToRow(constraint=constraint, row=row) 
    38623921 
Note: See TracChangeset for help on using the changeset viewer.