Ignore:
Timestamp:
Nov 21, 2018 6:39:24 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:
f2e199e
Parents:
44c15fc (diff), fb39f28 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'ESS_GUI_project_save' into ESS_GUI

File:
1 edited

Legend:

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

    rc4c4957 r21e71f1  
    2323    Constraints Dialog to select the desired parameter/model constraints. 
    2424    """ 
     25    fitCompleteSignal = QtCore.pyqtSignal(tuple) 
     26    batchCompleteSignal = QtCore.pyqtSignal(tuple) 
     27    fitFailedSignal = QtCore.pyqtSignal(tuple) 
    2528 
    2629    def __init__(self, parent=None): 
     
    3235        # To keep with previous SasView values, use 300 as the start offset 
    3336        self.page_id = 301 
     37        self.tab_id = self.page_id 
    3438 
    3539        # Are we chain fitting? 
     
    6064        Set up various widget states 
    6165        """ 
     66        # disable special cases until properly defined 
     67        self.label.setVisible(False) 
     68        self.cbCases.setVisible(False) 
     69 
    6270        labels = ['FitPage', 'Model', 'Data', 'Mnemonic'] 
    6371        # tab widget - headers 
     
    7987        self.tblConstraints.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.Stretch) 
    8088        self.tblConstraints.setEnabled(False) 
     89        header = self.tblConstraints.horizontalHeaderItem(0) 
     90        header.setToolTip("Double click a row below to edit the constraint.") 
    8191 
    8292        self.tblConstraints.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) 
     
    93103        self.cmdFit.clicked.connect(self.onFit) 
    94104        self.cmdHelp.clicked.connect(self.onHelp) 
     105        self.cmdAdd.clicked.connect(self.showMultiConstraint) 
    95106        self.chkChain.toggled.connect(self.onChainFit) 
    96107 
     
    100111        self.tblConstraints.cellChanged.connect(self.onConstraintChange) 
    101112 
     113        # Internal signals 
     114        self.fitCompleteSignal.connect(self.fitComplete) 
     115        self.batchCompleteSignal.connect(self.batchComplete) 
     116        self.fitFailedSignal.connect(self.fitFailed) 
     117 
    102118        # External signals 
    103119        self.parent.tabsModifiedSignal.connect(self.initializeFitList) 
     
    156172        fitter = Fit() 
    157173        fitter.fitter_id = self.page_id 
    158  
    159         # Notify the parent about fitting started 
    160         self.parent.fittingStartedSignal.emit(tabs_to_fit) 
    161174 
    162175        # prepare fitting problems for each tab 
     
    168181        try: 
    169182            for tab in tabs_to_fit: 
     183                if not self.isTabImportable(tab): continue 
    170184                tab_object = ObjectLibrary.getObject(tab) 
    171185                if tab_object is None: 
     
    177191        except ValueError: 
    178192            # No parameters selected in one of the tabs 
    179             no_params_msg = "Fitting can not be performed.\n" +\ 
     193            no_params_msg = "Fitting cannot be performed.\n" +\ 
    180194                            "Not all tabs chosen for fitting have parameters selected for fitting." 
    181195            QtWidgets.QMessageBox.warning(self, 
     
    200214        batch_inputs = {} 
    201215        batch_outputs = {} 
     216 
     217        # Notify the parent about fitting started 
     218        self.parent.fittingStartedSignal.emit(tabs_to_fit) 
    202219 
    203220        # new fit thread object 
     
    223240 
    224241        #disable the Fit button 
     242        self.cmdFit.setStyleSheet('QPushButton {color: red;}') 
    225243        self.cmdFit.setText('Running...') 
    226244        self.parent.communicate.statusBarUpdateSignal.emit('Fitting started...') 
     
    292310        """ 
    293311        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) 
     312        if column != 0: return 
     313        # Update the tabs for fitting list 
     314        constraint = self.available_constraints[row] 
     315        constraint.active = (item.checkState() == QtCore.Qt.Checked) 
     316        # Update the constraint formula 
     317        constraint = self.available_constraints[row] 
     318        function = item.text() 
     319        # remove anything left of '=' to get the constraint 
     320        function = function[function.index('=')+1:] 
     321        # No check on function here - trust the user (R) 
     322        if function != constraint.func: 
     323            # This becomes rather difficult to validate now. 
     324            # Turn off validation for Edit Constraint 
     325            constraint.func = function 
     326            constraint.validate = False 
    298327 
    299328    def onTabCellEntered(self, row, column): 
     
    308337    def onFitComplete(self, result): 
    309338        """ 
     339        Send the fit complete signal to main thread 
     340        """ 
     341        self.fitCompleteSignal.emit(result) 
     342 
     343    def fitComplete(self, result): 
     344        """ 
    310345        Respond to the successful fit complete signal 
    311346        """ 
    312347        #re-enable the Fit button 
     348        self.cmdFit.setStyleSheet('QPushButton {color: black;}') 
    313349        self.cmdFit.setText("Fit") 
    314350        self.cmdFit.setEnabled(True) 
     
    347383    def onBatchFitComplete(self, result): 
    348384        """ 
     385        Send the fit complete signal to main thread 
     386        """ 
     387        self.batchCompleteSignal.emit(result) 
     388 
     389    def batchComplete(self, result): 
     390        """ 
    349391        Respond to the successful batch fit complete signal 
    350392        """ 
    351393        #re-enable the Fit button 
     394        self.cmdFit.setStyleSheet('QPushButton {color: black;}') 
    352395        self.cmdFit.setText("Fit") 
    353396        self.cmdFit.setEnabled(True) 
     
    375418    def onFitFailed(self, reason): 
    376419        """ 
     420        Send the fit failed signal to main thread 
     421        """ 
     422        self.fitFailedSignal.emit(result) 
     423 
     424    def fitFailed(self, reason): 
     425        """ 
    377426        Respond to fitting failure. 
    378427        """ 
    379428        #re-enable the Fit button 
     429        self.cmdFit.setStyleSheet('QPushButton {color: black;}') 
    380430        self.cmdFit.setText("Fit") 
    381431        self.cmdFit.setEnabled(True) 
     
    386436        msg = "Fitting failed: %s s.\n" % reason 
    387437        self.parent.communicate.statusBarUpdateSignal.emit(msg) 
    388   
     438 
    389439    def isTabImportable(self, tab): 
    390440        """ 
     
    599649            # Show the text in the constraint table 
    600650            item = self.uneditableItem(label) 
     651            item = QtWidgets.QTableWidgetItem(label) 
    601652            item.setFlags(item.flags() ^ QtCore.Qt.ItemIsUserCheckable) 
    602653            item.setCheckState(QtCore.Qt.Checked) 
     
    667718        return None 
    668719 
     720    def onAcceptConstraint(self, con_tuple): 
     721        """ 
     722        Receive constraint tuple from the ComplexConstraint dialog and adds contraint 
     723        """ 
     724        #"M1, M2, M3" etc 
     725        model_name, constraint = con_tuple 
     726        constrained_tab = self.getObjectByName(model_name) 
     727        if constrained_tab is None: 
     728            return 
     729 
     730        # Find the constrained parameter row 
     731        constrained_row = constrained_tab.getRowFromName(constraint.param) 
     732 
     733        # Update the tab 
     734        constrained_tab.addConstraintToRow(constraint, constrained_row) 
     735 
     736        # Select this parameter for adjusting/fitting 
     737        constrained_tab.selectCheckbox(constrained_row) 
     738 
     739 
    669740    def showMultiConstraint(self): 
    670741        """ 
     
    672743        """ 
    673744        selected_rows = self.selectedParameters(self.tblTabList) 
    674         assert(len(selected_rows)==2) 
     745        if len(selected_rows)!=2: 
     746            msg = "Please select two fit pages from the Source Choice table." 
     747            msgbox = QtWidgets.QMessageBox(self.parent) 
     748            msgbox.setIcon(QtWidgets.QMessageBox.Warning) 
     749            msgbox.setText(msg) 
     750            msgbox.setWindowTitle("2 fit page constraints") 
     751            retval = msgbox.exec_() 
     752            return 
    675753 
    676754        tab_list = [ObjectLibrary.getObject(self.tblTabList.item(s, 0).data(0)) for s in selected_rows] 
    677755        # Create and display the widget for param1 and param2 
    678756        cc_widget = ComplexConstraint(self, tabs=tab_list) 
     757        cc_widget.constraintReadySignal.connect(self.onAcceptConstraint) 
     758 
    679759        if cc_widget.exec_() != QtWidgets.QDialog.Accepted: 
    680760            return 
    681761 
    682         constraint = Constraint() 
    683         model1, param1, operator, constraint_text = cc_widget.constraint() 
    684  
    685         constraint.func = constraint_text 
    686         # param1 is the parameter we're constraining 
    687         constraint.param = param1 
    688  
    689         # Find the right tab 
    690         constrained_tab = self.getObjectByName(model1) 
    691         if constrained_tab is None: 
    692             return 
    693  
    694         # Find the constrained parameter row 
    695         constrained_row = constrained_tab.getRowFromName(param1) 
    696  
    697         # Update the tab 
    698         constrained_tab.addConstraintToRow(constraint, constrained_row) 
     762    def getFitPage(self): 
     763        """ 
     764        Retrieves the state of this page 
     765        """ 
     766        param_list = [] 
     767 
     768        param_list.append(['is_constraint', 'True']) 
     769        param_list.append(['data_id', "cs_tab"+str(self.page_id)]) 
     770        param_list.append(['current_type', self.currentType]) 
     771        param_list.append(['is_chain_fitting', str(self.is_chain_fitting)]) 
     772        param_list.append(['special_case', self.cbCases.currentText()]) 
     773 
     774        return param_list 
     775 
     776    def getFitModel(self): 
     777        """ 
     778        Retrieves current model 
     779        """ 
     780        model_list = [] 
     781 
     782        checked_models = {} 
     783        for row in range(self.tblTabList.rowCount()): 
     784            model_name = self.tblTabList.item(row,1).data(0) 
     785            active = self.tblTabList.item(row,0).checkState()# == QtCore.Qt.Checked 
     786            checked_models[model_name] = str(active) 
     787 
     788        checked_constraints = {} 
     789        for row in range(self.tblConstraints.rowCount()): 
     790            model_name = self.tblConstraints.item(row,0).data(0) 
     791            active = self.tblConstraints.item(row,0).checkState()# == QtCore.Qt.Checked 
     792            checked_constraints[model_name] = str(active) 
     793 
     794        model_list.append(['checked_models', checked_models]) 
     795        model_list.append(['checked_constraints', checked_constraints]) 
     796        return model_list 
     797 
     798    def createPageForParameters(self, parameters=None): 
     799        """ 
     800        Update the page with passed parameter values 
     801        """ 
     802        # checked models 
     803        if not 'checked_models' in parameters: 
     804            return 
     805        models = parameters['checked_models'][0] 
     806        for model, check_state in models.items(): 
     807            for row in range(self.tblTabList.rowCount()): 
     808                model_name = self.tblTabList.item(row,1).data(0) 
     809                if model_name != model: 
     810                    continue 
     811                # check/uncheck item 
     812                self.tblTabList.item(row,0).setCheckState(int(check_state)) 
     813 
     814        if not 'checked_constraints' in parameters: 
     815            return 
     816        # checked constraints 
     817        models = parameters['checked_constraints'][0] 
     818        for model, check_state in models.items(): 
     819            for row in range(self.tblConstraints.rowCount()): 
     820                model_name = self.tblConstraints.item(row,0).data(0) 
     821                if model_name != model: 
     822                    continue 
     823                # check/uncheck item 
     824                self.tblConstraints.item(row,0).setCheckState(int(check_state)) 
     825 
     826        # fit/batch radio 
     827        isBatch = parameters['current_type'][0] == 'BatchPage' 
     828        if isBatch: 
     829            self.btnBatch.toggle() 
     830 
     831        # chain 
     832        is_chain = parameters['is_chain_fitting'][0] == 'True' 
     833        if isBatch: 
     834            self.chkChain.setChecked(is_chain) 
Note: See TracChangeset for help on using the changeset viewer.