Ignore:
Timestamp:
Nov 16, 2018 3:05:20 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:
09e0c32
Parents:
baeac95
Message:

Reworked the complex constraint functionality SASVIEW-1019

File:
1 edited

Legend:

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

    re5ae812 recc5d043  
    2222    Constraints Dialog to select the desired parameter/model constraints. 
    2323    """ 
    24  
     24    fitCompleteSignal = QtCore.pyqtSignal(tuple) 
    2525    def __init__(self, parent=None): 
    2626        super(ConstraintWidget, self).__init__() 
     
    9393        self.cmdFit.clicked.connect(self.onFit) 
    9494        self.cmdHelp.clicked.connect(self.onHelp) 
     95        self.cmdAdd.clicked.connect(self.showMultiConstraint) 
    9596        self.chkChain.toggled.connect(self.onChainFit) 
    9697 
     
    100101        self.tblConstraints.cellChanged.connect(self.onConstraintChange) 
    101102 
     103        # Internal signals 
     104        self.fitCompleteSignal.connect(self.fitComplete) 
     105 
    102106        # External signals 
    103107        self.parent.tabsModifiedSignal.connect(self.initializeFitList) 
     
    156160        fitter = Fit() 
    157161        fitter.fitter_id = self.page_id 
    158  
    159         # Notify the parent about fitting started 
    160         self.parent.fittingStartedSignal.emit(tabs_to_fit) 
    161162 
    162163        # prepare fitting problems for each tab 
     
    177178        except ValueError: 
    178179            # No parameters selected in one of the tabs 
    179             no_params_msg = "Fitting can not be performed.\n" +\ 
     180            no_params_msg = "Fitting cannot be performed.\n" +\ 
    180181                            "Not all tabs chosen for fitting have parameters selected for fitting." 
    181182            QtWidgets.QMessageBox.warning(self, 
     
    200201        batch_inputs = {} 
    201202        batch_outputs = {} 
     203 
     204        # Notify the parent about fitting started 
     205        self.parent.fittingStartedSignal.emit(tabs_to_fit) 
    202206 
    203207        # new fit thread object 
     
    292296        """ 
    293297        item = self.tblConstraints.item(row, column) 
    294         if column == 0: 
    295             # Update the tabs for fitting list 
    296             constraint = self.available_constraints[row] 
    297             constraint.active = (item.checkState() == QtCore.Qt.Checked) 
     298        if column != 0: return 
     299        # Update the tabs for fitting list 
     300        constraint = self.available_constraints[row] 
     301        constraint.active = (item.checkState() == QtCore.Qt.Checked) 
     302        # Update the constraint formula 
     303        constraint = self.available_constraints[row] 
     304        function = item.text() 
     305        # remove anything left of '=' to get the constraint 
     306        function = function[function.index('=')+1:] 
     307        # No check on function here - trust the user (R) 
     308        if function != constraint.func: 
     309            #from sas.sascalc.fit.expression import compile_constraints 
     310            constraint.func = function 
    298311 
    299312    def onTabCellEntered(self, row, column): 
     
    307320 
    308321    def onFitComplete(self, result): 
     322        """ 
     323        Send the fit complete signal to main thread 
     324        """ 
     325        self.fitCompleteSignal.emit(result) 
     326 
     327    def fitComplete(self, result): 
    309328        """ 
    310329        Respond to the successful fit complete signal 
     
    383402        msg = "Fitting failed: %s s.\n" % reason 
    384403        self.parent.communicate.statusBarUpdateSignal.emit(msg) 
    385   
     404 
    386405    def isTabImportable(self, tab): 
    387406        """ 
     
    596615            # Show the text in the constraint table 
    597616            item = self.uneditableItem(label) 
     617            item = QtWidgets.QTableWidgetItem(label) 
    598618            item.setFlags(item.flags() ^ QtCore.Qt.ItemIsUserCheckable) 
    599619            item.setCheckState(QtCore.Qt.Checked) 
     
    664684        return None 
    665685 
     686    def onAcceptConstraint(self, con_tuple): 
     687        """ 
     688        Receive constraint tuple from the ComplexConstraint dialog and adds contraint 
     689        """ 
     690        #"M1, M2, M3" etc 
     691        model_name, constraint = con_tuple 
     692        constrained_tab = self.getObjectByName(model_name) 
     693        if constrained_tab is None: 
     694            return 
     695 
     696        # Find the constrained parameter row 
     697        constrained_row = constrained_tab.getRowFromName(constraint.param) 
     698 
     699        # Update the tab 
     700        constrained_tab.addConstraintToRow(constraint, constrained_row) 
     701 
    666702    def showMultiConstraint(self): 
    667703        """ 
     
    669705        """ 
    670706        selected_rows = self.selectedParameters(self.tblTabList) 
    671         assert(len(selected_rows)==2) 
     707        if len(selected_rows)!=2: 
     708            msg = "Please select two fit pages from the Source Choice table." 
     709            msgbox = QtWidgets.QMessageBox(self.parent) 
     710            msgbox.setIcon(QtWidgets.QMessageBox.Warning) 
     711            msgbox.setText(msg) 
     712            msgbox.setWindowTitle("2 fit page constraints") 
     713            retval = msgbox.exec_() 
     714            return 
    672715 
    673716        tab_list = [ObjectLibrary.getObject(self.tblTabList.item(s, 0).data(0)) for s in selected_rows] 
    674717        # Create and display the widget for param1 and param2 
    675718        cc_widget = ComplexConstraint(self, tabs=tab_list) 
     719        cc_widget.constraintReadySignal.connect(self.onAcceptConstraint) 
     720 
    676721        if cc_widget.exec_() != QtWidgets.QDialog.Accepted: 
    677722            return 
    678  
    679         constraint = Constraint() 
    680         model1, param1, operator, constraint_text = cc_widget.constraint() 
    681  
    682         constraint.func = constraint_text 
    683         # param1 is the parameter we're constraining 
    684         constraint.param = param1 
    685  
    686         # Find the right tab 
    687         constrained_tab = self.getObjectByName(model1) 
    688         if constrained_tab is None: 
    689             return 
    690  
    691         # Find the constrained parameter row 
    692         constrained_row = constrained_tab.getRowFromName(param1) 
    693  
    694         # Update the tab 
    695         constrained_tab.addConstraintToRow(constraint, constrained_row) 
    696723 
    697724    def getFitPage(self): 
Note: See TracChangeset for help on using the changeset viewer.