Changeset ba01ad1 in sasview for src/sas


Ignore:
Timestamp:
Jan 19, 2018 6:02:09 AM (6 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:
0764593
Parents:
c5a2722f
Message:

Added batch fit constraints.
Cleaned up interactions between constraints in various tabs

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

Legend:

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

    rc5a2722f rba01ad1  
    152152        param_str = self.cbParam2.currentText() 
    153153        constraint_text = constraint_text.strip() 
    154         model_str = constraint_text[:constraint_text.index('.')] 
    155         #constraint_text = constraint_text[constraint_text.index('.')+1:] 
     154        model_str = self.txtName2.text() 
    156155 
    157156        # 0. Has to contain the model name 
     
    159158            return False 
    160159 
    161         # Remove model name from constraint text 
     160        # Remove model name from constraint 
    162161        constraint_text = constraint_text.replace(model_str+".",'') 
    163162 
  • src/sas/qtgui/Perspectives/Fitting/ConstraintWidget.py

    rc5a2722f rba01ad1  
    2525        # Remember previous content of modified cell 
    2626        self.current_cell = "" 
     27 
     28        # Tabs used in simultaneous fitting 
     29        # tab_name : True/False 
     30        self.tabs_for_fitting = {} 
    2731 
    2832        # Set up the widgets 
     
    7579 
    7680        # QTableWidgets 
    77         self.tblTabList.cellChanged.connect(self.onMonikerEdit) 
     81        self.tblTabList.cellChanged.connect(self.onTabCellEdit) 
    7882        self.tblTabList.cellDoubleClicked.connect(self.onTabCellEntered) 
    7983        self.tblConstraints.cellChanged.connect(self.onConstraintChange) 
    8084 
    8185        # External signals 
    82         self.parent.tabsModifiedSignal.connect(self.initializeFitList) 
     86        #self.parent.tabsModifiedSignal.connect(self.initializeFitList) 
     87        self.parent.tabsModifiedSignal.connect(self.onModifiedTabs) 
    8388 
    8489    def updateSignalsFromTab(self, tab=None): 
     
    95100        single fit/batch fit 
    96101        """ 
     102        source = self.sender().objectName() 
     103        self.currentType = "BatchPage" if source == "btnBatch" else "FitPage" 
     104        self.initializeFitList() 
     105 
     106    def onSpecialCaseChange(self, index): 
     107        """ 
     108        Respond to the combobox change for special case constraint sets 
     109        """ 
    97110        pass 
    98111 
    99     def onSpecialCaseChange(self, index): 
    100         """ 
    101         Respond to the combobox change for special case constraint sets 
     112    def onFit(self): 
     113        """ 
     114        Perform the constrained/simultaneous fit 
    102115        """ 
    103116        pass 
    104117 
    105     def onFit(self): 
    106         """ 
    107         Perform the constrained/simultaneous fit 
     118    def onHelp(self): 
     119        """ 
     120        Display the help page 
    108121        """ 
    109122        pass 
    110123 
    111     def onHelp(self): 
    112         """ 
    113         Display the help page 
    114         """ 
    115         pass 
    116  
    117     def onMonikerEdit(self, row, column): 
    118         """ 
    119         Modify the model moniker 
    120         """ 
     124    def onTabCellEdit(self, row, column): 
     125        """ 
     126        Respond to check/uncheck and to modify the model moniker actions 
     127        """ 
     128        item = self.tblTabList.item(row, column) 
     129        if column == 0: 
     130            # Update the tabs for fitting list 
     131            tab_name = item.text() 
     132            self.tabs_for_fitting[tab_name] = (item.checkState() == QtCore.Qt.Checked) 
     133            # Enable fitting only when there are models to fit 
     134            self.cmdFit.setEnabled(any(self.tabs_for_fitting.values())) 
     135 
    121136        if column not in self.editable_tab_columns: 
    122137            return 
    123         item = self.tblTabList.item(row, column) 
    124138        new_moniker = item.data(0) 
    125139 
     
    131145            item.setBackground(QtCore.Qt.red) 
    132146            self.cmdFit.setEnabled(False) 
    133         else: 
    134             self.tblTabList.blockSignals(True) 
    135             item.setBackground(QtCore.Qt.white) 
    136             self.tblTabList.blockSignals(False) 
    137             self.cmdFit.setEnabled(True) 
    138             if not self.current_cell: 
    139                 return 
    140             # Remember the value 
    141             if self.current_cell not in self.available_tabs: 
    142                 return 
    143             temp_tab = self.available_tabs[self.current_cell] 
    144             # Remove the key from the dictionaries 
    145             self.available_tabs.pop(self.current_cell, None) 
    146             # Change the model name 
    147             model = temp_tab.kernel_module 
    148             model.name = new_moniker 
    149             # Replace constraint name 
    150             temp_tab.replaceConstraintName(self.current_cell, new_moniker) 
    151             # Reinitialize the display 
    152             self.initializeFitList() 
    153         pass 
     147            return 
     148        self.tblTabList.blockSignals(True) 
     149        item.setBackground(QtCore.Qt.white) 
     150        self.tblTabList.blockSignals(False) 
     151        self.cmdFit.setEnabled(True) 
     152        if not self.current_cell: 
     153            return 
     154        # Remember the value 
     155        if self.current_cell not in self.available_tabs: 
     156            return 
     157        temp_tab = self.available_tabs[self.current_cell] 
     158        # Remove the key from the dictionaries 
     159        self.available_tabs.pop(self.current_cell, None) 
     160        # Change the model name 
     161        model = temp_tab.kernel_module 
     162        model.name = new_moniker 
     163        # Replace constraint name 
     164        temp_tab.replaceConstraintName(self.current_cell, new_moniker) 
     165        # Reinitialize the display 
     166        self.initializeFitList() 
    154167 
    155168    def onConstraintChange(self, row, column): 
    156169        """ 
    157170        Modify the constraint in-place. 
    158         Tricky. 
    159         """ 
    160         pass 
     171        """ 
     172        item = self.tblConstraints.item(row, column) 
     173        if column == 0: 
     174            # Update the tabs for fitting list 
     175            constraint = self.available_constraints[row] 
     176            constraint.active = (item.checkState() == QtCore.Qt.Checked) 
    161177 
    162178    def onTabCellEntered(self, row, column): 
     
    168184            return 
    169185        self.current_cell = self.tblTabList.item(row, column).data(0) 
     186 
     187    def onModifiedTabs(self): 
     188        """ 
     189        Respond to tabs being deleted by deleting involved constraints 
     190 
     191        This should probably be done in FittingWidget as it is the owner of 
     192        all the fitting data, but I want to keep the FW oblivious about 
     193        dependence on other FW tabs, so enforcing the constraint deletion here. 
     194        """ 
     195        # Get the list of all constraints from querying the table 
     196        #constraints = getConstraintsForModel() 
     197 
     198        # Get the current list of tabs 
     199        #tabs = ObjectLibrary.listObjects() 
     200 
     201        # Check if any of the constraint dependencies got deleted 
     202        # Check the list of constraints 
     203        self.initializeFitList() 
     204        pass 
    170205 
    171206    def isTabImportable(self, tab): 
     
    339374        Update a single line of the table widget with tab info 
    340375        """ 
    341         model = ObjectLibrary.getObject(tab).kernel_module 
     376        fit_page = ObjectLibrary.getObject(tab) 
     377        model = fit_page.kernel_module 
    342378        if model is None: 
    343379            return 
     
    345381        model_name = model.id 
    346382        moniker = model.name 
    347         model_data = ObjectLibrary.getObject(tab).data 
     383        model_data = fit_page.data 
    348384        model_filename = model_data.filename 
    349         self.available_tabs[moniker] = ObjectLibrary.getObject(tab) 
     385        self.available_tabs[moniker] = fit_page 
    350386 
    351387        # Update the model table widget 
    352         #item = QtWidgets.QTableWidgetItem(tab_name) 
    353         #item.setCheckState(QtCore.Qt.Checked) 
    354         #item.setFlags( QtCore.Qt.ItemIsSelectable |  QtCore.Qt.ItemIsEnabled ) 
    355388        pos = self.tblTabList.rowCount() 
    356389        self.tblTabList.insertRow(pos) 
    357390        item = self.uneditableItem(tab_name) 
    358391        item.setFlags(item.flags() ^ QtCore.Qt.ItemIsUserCheckable) 
    359         item.setCheckState(QtCore.Qt.Checked) 
     392        if tab_name in self.tabs_for_fitting: 
     393            state = QtCore.Qt.Checked if self.tabs_for_fitting[tab_name] else QtCore.Qt.Unchecked 
     394            item.setCheckState(state) 
     395        else: 
     396            item.setCheckState(QtCore.Qt.Checked) 
     397            self.tabs_for_fitting[tab_name] = True 
     398 
    360399        self.tblTabList.setItem(pos, 0, item) 
    361400        self.tblTabList.setItem(pos, 1, self.uneditableItem(model_name)) 
     
    369408 
    370409        # Check if any constraints present in tab 
    371         constraints = ObjectLibrary.getObject(tab).getConstraintsForModel() 
     410        constraint_names = fit_page.getConstraintsForModel() 
     411        constraints = fit_page.getConstraintObjectsForModel() 
    372412        if not constraints:  
    373413            return 
    374414        self.tblConstraints.setEnabled(True) 
    375         for constraint in constraints: 
     415        for constraint, constraint_name in zip(constraints, constraint_names): 
    376416            # Create the text for widget item 
    377             label = moniker + ":"+ constraint[0] + " = " + constraint[1] 
     417            label = moniker + ":"+ constraint_name[0] + " = " + constraint_name[1] 
     418            pos = self.tblConstraints.rowCount() 
     419            self.available_constraints[pos] = constraint 
    378420 
    379421            # Show the text in the constraint table 
    380             item = QtWidgets.QTableWidgetItem(label) 
     422            item = self.uneditableItem(label) 
     423            item.setFlags(item.flags() ^ QtCore.Qt.ItemIsUserCheckable) 
    381424            item.setCheckState(QtCore.Qt.Checked) 
    382             pos = self.tblConstraints.rowCount() 
    383425            self.tblConstraints.insertRow(pos) 
    384426            self.tblConstraints.setItem(pos, 0, item) 
    385             self.available_constraints[pos] = constraints 
    386427 
    387428    def initializeFitList(self): 
     
    461502 
    462503        constraint.func = constraint_text 
    463         # constraint.param = param1 
     504        constraint.param = param1 
    464505        # Find the right tab 
    465506        constrained_tab = self.getObjectByName(model1) 
  • src/sas/qtgui/Perspectives/Fitting/Constraints.py

    • Property mode changed from 100755 to 100644
    reae226b rba01ad1  
    77        self._param = param 
    88        self._func = func 
    9         self.active = False 
     9        self.active = True 
    1010        self._min = min 
    1111        self._max = max 
     
    5353    def delete(self, constraint=None): 
    5454        pass 
    55  
    56  
    57 class ConstrainedParameters(object): 
    58     """ 
    59     Representation of two constrained parameters 
    60     """ 
    61     def __init__(self, parent=None): 
    62         pass 
    63  
    64     def add(self, constraint=None): 
    65         pass 
    66  
    67     def delete(self, constraint=None): 
    68         pass 
    69  
  • src/sas/qtgui/Perspectives/Fitting/FittingWidget.py

    rc5a2722f rba01ad1  
    783783        return params 
    784784 
     785    def getConstraintObjectsForModel(self): 
     786        """ 
     787        Returns Constraint objects present on the whole model 
     788        """ 
     789        param_number = self._model_model.rowCount() 
     790        constraints = [self._model_model.item(s, 1).child(0).data() 
     791                       for s in range(param_number) if self.rowHasConstraint(s)] 
     792 
     793        return constraints 
     794 
    785795    def showModelDescription(self): 
    786796        """ 
Note: See TracChangeset for help on using the changeset viewer.