Changeset c5a2722f in sasview


Ignore:
Timestamp:
Jan 18, 2018 9:44:26 AM (7 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
Branches:
ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
ba01ad1
Parents:
2d466e4
Message:

Complex constraint widget updating the main constraint widget and fitting tabs

Location:
src/sas/qtgui/Perspectives/Fitting
Files:
3 edited

Legend:

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

    r2d466e4 rc5a2722f  
    1515# Local UI 
    1616from sas.qtgui.Perspectives.Fitting.UI.ComplexConstraintUI import Ui_ComplexConstraintUI 
     17from sas.qtgui.Perspectives.Fitting.Constraints import Constraint 
    1718 
    1819class ComplexConstraint(QtWidgets.QDialog, Ui_ComplexConstraintUI): 
     
    5253        self.cmdHelp.clicked.connect(self.onHelp) 
    5354        self.cmdRevert.clicked.connect(self.onRevert) 
    54         #self.txtConstraint.editingFinished.connect(self.validateFormula) 
     55        self.txtConstraint.editingFinished.connect(self.validateFormula) 
    5556 
    5657        self.cbParam1.currentIndexChanged.connect(self.onParamIndexChange) 
     
    9596            self.txtParam.setText(self.tab_names[0] + ":" + self.cbParam1.currentText()) 
    9697        else: 
    97             self.txtConstraint.setText(self.cbParam2.currentText()) 
     98            self.txtConstraint.setText(self.tab_names[1] + "." + self.cbParam2.currentText()) 
    9899        pass 
    99100 
     
    148149            return False 
    149150 
    150         param_str = str(self.params[1]) 
     151        # M1.scale  --> model_str='M1', constraint_text='scale' 
     152        param_str = self.cbParam2.currentText() 
    151153        constraint_text = constraint_text.strip() 
     154        model_str = constraint_text[:constraint_text.index('.')] 
     155        #constraint_text = constraint_text[constraint_text.index('.')+1:] 
     156 
     157        # 0. Has to contain the model name 
     158        if model_str != self.txtName2.text(): 
     159            return False 
     160 
     161        # Remove model name from constraint text 
     162        constraint_text = constraint_text.replace(model_str+".",'') 
    152163 
    153164        # 1. just the parameter 
     
    161172        parameter_string_end = parameter_string_start + len(param_str) 
    162173 
    163         # 3. parameter name should be a separate word, but can have "()[]*+-/ " around 
    164         valid_neighbours = "()[]*+-/ " 
    165         has_only_parameter = False 
    166         start_loc = parameter_string_start -1 
    167         end_loc = parameter_string_end 
    168         if not any([constraint_text[start_loc] == char for char in valid_neighbours]): 
    169             return False 
    170         if end_loc < len(constraint_text): 
    171             if not any([constraint_text[end_loc] == char for char in valid_neighbours]): 
    172                 return False 
    173  
    174         # 4. replace parameter name with "1" and try to evaluate the expression 
     174        # 3. replace parameter name with "1" and try to evaluate the expression 
    175175        try: 
    176176            expression_to_evaluate = constraint_text.replace(param_str, "1.0") 
     
    185185        return True 
    186186 
     187    def constraint(self): 
     188        """ 
     189        Return the generated constraint as tuple (model1, param1, operator, constraint) 
     190        """ 
     191        return (self.txtName1.text(), self.cbParam1.currentText(), self.cbOperator.currentText(), self.txtConstraint.text()) 
     192 
    187193    def onHelp(self): 
    188194        """ 
  • src/sas/qtgui/Perspectives/Fitting/ConstraintWidget.py

    r2d466e4 rc5a2722f  
    1010from sas.qtgui.Perspectives.Fitting.FittingWidget import FittingWidget 
    1111from sas.qtgui.Perspectives.Fitting.ComplexConstraint import ComplexConstraint 
     12from sas.qtgui.Perspectives.Fitting.Constraints import Constraint 
    1213 
    1314class ConstraintWidget(QtWidgets.QWidget, Ui_ConstraintWidgetUI): 
     
    431432        return True 
    432433 
     434    def getObjectByName(self, name): 
     435        for object_name in ObjectLibrary.listObjects(): 
     436            object = ObjectLibrary.getObject(object_name) 
     437            if isinstance(object, FittingWidget): 
     438                try: 
     439                    if object.kernel_module.name == name: 
     440                        return object 
     441                except AttributeError: 
     442                    # Disregard atribute errors - empty fit widgets 
     443                    continue 
     444        return None 
     445 
    433446    def showMultiConstraint(self): 
    434447        """ 
     
    444457            return 
    445458 
    446         #constraint = Constraint() 
    447         #c_text = cc_widget.txtConstraint.text() 
    448         pass 
     459        constraint = Constraint() 
     460        model1, param1, operator, constraint_text = cc_widget.constraint() 
     461 
     462        constraint.func = constraint_text 
     463        # constraint.param = param1 
     464        # Find the right tab 
     465        constrained_tab = self.getObjectByName(model1) 
     466        if constrained_tab is None: 
     467            return 
     468 
     469        # Find the constrained parameter row 
     470        constrained_row = constrained_tab.getRowFromName(param1) 
     471 
     472        # Update the tab 
     473        constrained_tab.addConstraintToRow(constraint, constrained_row) 
     474        pass 
  • src/sas/qtgui/Perspectives/Fitting/FittingWidget.py

    r2d466e4 rc5a2722f  
    601601        Return list of all parameters for the current model 
    602602        """ 
    603         #params = [] 
    604         #for row in range(self._model_model.rowCount()): 
    605         #    params.append(self._model_model.item(row).text()) 
    606         #return params 
    607603        return [self._model_model.item(row).text() for row in range(self._model_model.rowCount())] 
    608604 
     
    625621            self._model_model.item(row, column).setEditable(fields_enabled) 
    626622        self._model_model.blockSignals(False) 
     623 
     624    def addConstraintToRow(self, constraint=None, row=0): 
     625        """ 
     626        Adds the constraint object to requested row 
     627        """ 
     628        # Create a new item and add the Constraint object as a child 
     629        assert(isinstance(constraint, Constraint)) 
     630        assert(0<=row<=self._model_model.rowCount()) 
     631 
     632        item = QtGui.QStandardItem() 
     633        item.setData(constraint) 
     634        self._model_model.item(row, 1).setChild(0, item) 
     635        # Set min/max to the value constrained 
     636        self.constraintAddedSignal.emit([row]) 
     637        # Show visual hints for the constraint 
     638        font = QtGui.QFont() 
     639        font.setItalic(True) 
     640        brush = QtGui.QBrush(QtGui.QColor('blue')) 
     641        self.modifyViewOnRow(row, font=font, brush=brush) 
     642        self.communicate.statusBarUpdateSignal.emit('Constraint added') 
    627643 
    628644    def addSimpleConstraint(self): 
     
    759775            if func == value: 
    760776                return "" 
     777 
    761778            return model_name + "." 
    762779        params = [(self._model_model.item(s, 0).text(), 
    763                     preamble(s) +self._model_model.item(s, 1).child(0).data().func) 
     780                    #preamble(s) +self._model_model.item(s, 1).child(0).data().func) 
     781                    self._model_model.item(s, 1).child(0).data().func) 
    764782                    for s in range(param_number) if self.rowHasConstraint(s)] 
    765783        return params 
Note: See TracChangeset for help on using the changeset viewer.