Search in sources :

Example 6 with CvValue

use of jmri.jmrit.symbolicprog.CvValue in project JMRI by JMRI.

the class PaneProgPane method nextWrite.

boolean nextWrite() {
    log.debug("start nextWrite");
    // look for possible variables
    while ((varList.size() > 0) && (varListIndex < varList.size())) {
        int varNum = varList.get(varListIndex);
        int vState = _varModel.getState(varNum);
        VariableValue var = _varModel.getVariable(varNum);
        if (log.isDebugEnabled()) {
            log.debug("nextWrite var index " + varNum + " state " + VariableValue.stateNameFromValue(vState) + " isToWrite: " + var.isToWrite() + " label:" + var.label());
        }
        varListIndex++;
        if (var.isToWrite()) {
            log.debug("start write of variable " + _varModel.getLabel(varNum));
            executeWrite(var);
            if (log.isDebugEnabled()) {
                log.debug("return from starting var write");
            }
            // only make one request at a time!
            return true;
        }
    }
    // check for CVs to handle (e.g. for CV table)
    while (cvListIterator != null && cvListIterator.hasNext()) {
        int cvNum = cvListIterator.next();
        CvValue cv = _cvModel.getCvByRow(cvNum);
        if (log.isDebugEnabled()) {
            log.debug("nextWrite cv index " + cvNum + " state " + cv.getState());
        }
        if (cv.isToWrite()) {
            if (log.isDebugEnabled()) {
                log.debug("start write of cv index " + cvNum);
            }
            setBusy(true);
            if (_programmingCV != null) {
                log.error("listener already set at write start");
            }
            _programmingCV = _cvModel.getCvByRow(cvNum);
            _read = false;
            // get notified when that state changes so can repeat
            _programmingCV.addPropertyChangeListener(this);
            // and make the write request
            // _programmingCV.setToWrite(false);  // CVs set this themselves
            _programmingCV.write(_cvModel.getStatusLabel());
            if (log.isDebugEnabled()) {
                log.debug("return from starting cv write");
            }
            // only make one request at a time!
            return true;
        }
    }
    // check for Indexed CVs to handle (e.g. for Indexed CV table)
    while ((indexedCvList.size() > 0) && (indexedCvListIndex < indexedCvList.size())) {
        int indxVarNum = indexedCvList.get(indexedCvListIndex);
        int indxState = _varModel.getState(indxVarNum);
        if (log.isDebugEnabled()) {
            log.debug("nextWrite indexed cv @ row index " + indexedCvListIndex + " state " + indxState);
        }
        VariableValue iCv = _varModel.getVariable(indxVarNum);
        indexedCvListIndex++;
        if (iCv.isToWrite()) {
            String sz = "start write of indexed cv " + (_indexedCvModel.getCvByRow(indexedCvListIndex - 1)).cvName();
            if (log.isDebugEnabled()) {
                log.debug(sz);
            }
            setBusy(true);
            if (_programmingIndexedCV != null) {
                log.error("listener already set at read start");
            }
            _programmingIndexedCV = _varModel.getVariable(indxVarNum);
            _read = true;
            // get notified when that state changes so can repeat
            _programmingIndexedCV.addPropertyChangeListener(this);
            // _programmingIndexedCV.setToWrite(false);  // CVs set this themselves
            // and make the write request
            _programmingIndexedCV.writeAll();
            if (log.isDebugEnabled()) {
                log.debug("return from starting indexed CV read");
            }
            // only make one request at a time!
            return true;
        }
    }
    // nothing to program, end politely
    if (log.isDebugEnabled()) {
        log.debug("nextWrite found nothing to do");
    }
    writeChangesButton.setSelected(false);
    writeAllButton.setSelected(false);
    setBusy(false);
    container.paneFinished();
    log.debug("return from nextWrite with nothing to do");
    return false;
}
Also used : VariableValue(jmri.jmrit.symbolicprog.VariableValue) CvValue(jmri.jmrit.symbolicprog.CvValue)

Example 7 with CvValue

use of jmri.jmrit.symbolicprog.CvValue in project JMRI by JMRI.

the class PaneProgPane method setToWrite.

/**
     * Set the "ToWrite" parameter in all variables and CVs on this pane
     *
     * @param justChanges  true if this is read changes, false if read all
     * @param startProcess true if this is the start of processing, false if
     *                     cleaning up at end
     */
void setToWrite(boolean justChanges, boolean startProcess) {
    if (log.isDebugEnabled()) {
        log.debug("start setToWrite method with " + justChanges + "," + startProcess);
    }
    if (!container.isBusy() || // the frame has already setToWrite
    (!startProcess)) {
        // we want to setToWrite false if the pane's process is being stopped
        log.debug("about to start setToWrite of varList");
        for (int i = 0; i < varList.size(); i++) {
            int varNum = varList.get(i);
            VariableValue var = _varModel.getVariable(varNum);
            if (justChanges) {
                if (var.isChanged()) {
                    var.setToWrite(startProcess);
                } else {
                    var.setToWrite(false);
                }
            } else {
                var.setToWrite(startProcess);
            }
        }
        log.debug("about to start setToWrite of cvList");
        if (isCvTablePane) {
            // make sure list of CVs up to date if table
            setCvListFromTable();
        }
        for (int cvNum : cvList) {
            CvValue cv = _cvModel.getCvByRow(cvNum);
            if (justChanges) {
                if (VariableValue.considerChanged(cv)) {
                    cv.setToWrite(startProcess);
                } else {
                    cv.setToWrite(false);
                }
            } else {
                cv.setToWrite(startProcess);
            }
        }
        log.debug("about to start setToWrite of indexedCvList");
        for (int i = 0; i < indexedCvList.size(); i++) {
            CvValue icv = _indexedCvModel.getCvByRow(i);
            if (justChanges) {
                if (VariableValue.considerChanged(icv)) {
                    icv.setToWrite(startProcess);
                } else {
                    icv.setToWrite(false);
                }
            } else {
                icv.setToWrite(startProcess);
            }
        }
    }
    log.debug("end setToWrite method");
}
Also used : VariableValue(jmri.jmrit.symbolicprog.VariableValue) CvValue(jmri.jmrit.symbolicprog.CvValue)

Example 8 with CvValue

use of jmri.jmrit.symbolicprog.CvValue in project JMRI by JMRI.

the class PaneProgPane method makeOpsNeededSet.

/**
     * Produce a set of CVs that will be accessed when reading or writing the
     * contents of this pane.
     *
     * @param read    true if counting for read, false for write
     * @param changes true if counting for a *Changes operation; false, if
     *                counting for a *All operation
     * @param set     The set to fill. Any CVs already in here will not be
     *                duplicated, which provides a way to aggregate a set of CVs
     *                across multiple panes.
     * @return the same set as the parameter, for convenient chaining of
     *         operations.
     */
public Set<Integer> makeOpsNeededSet(boolean read, boolean changes, Set<Integer> set) {
    // scan the variable list
    for (int i = 0; i < varList.size(); i++) {
        int varNum = varList.get(i);
        VariableValue var = _varModel.getVariable(varNum);
        // must decide whether this one should be counted
        if (!changes || var.isChanged()) {
            CvValue[] cvs = var.usesCVs();
            for (CvValue cv : cvs) {
                // always of interest
                if (!changes || VariableValue.considerChanged(cv)) {
                    set.add(Integer.valueOf(cv.number()));
                }
            }
        }
    }
    return set;
}
Also used : VariableValue(jmri.jmrit.symbolicprog.VariableValue) CvValue(jmri.jmrit.symbolicprog.CvValue)

Example 9 with CvValue

use of jmri.jmrit.symbolicprog.CvValue in project JMRI by JMRI.

the class PaneProgPane method nextRead.

/**
     * If there are any more read operations to be done on this pane, do the
     * next one.
     * <P>
     * Each invocation of this method reads one variable or CV; completion of
     * that request will cause it to happen again, reading the next one, until
     * there's nothing left to read.
     * <P>
     * @return true is a read has been started, false if the pane is complete.
     */
boolean nextRead() {
    // look for possible variables
    if (log.isDebugEnabled()) {
        log.debug("nextRead scans " + varList.size() + " variables");
    }
    while ((varList.size() > 0) && (varListIndex < varList.size())) {
        int varNum = varList.get(varListIndex);
        int vState = _varModel.getState(varNum);
        VariableValue var = _varModel.getVariable(varNum);
        if (log.isDebugEnabled()) {
            log.debug("nextRead var index " + varNum + " state " + VariableValue.stateNameFromValue(vState) + " isToRead: " + var.isToRead() + " label: " + var.label());
        }
        varListIndex++;
        if (var.isToRead()) {
            if (log.isDebugEnabled()) {
                log.debug("start read of variable " + _varModel.getLabel(varNum));
            }
            executeRead(var);
            if (log.isDebugEnabled()) {
                log.debug("return from starting var read");
            }
            // only make one request at a time!
            return true;
        }
    }
    // found no variables needing read, try CVs
    if (log.isDebugEnabled()) {
        log.debug("nextRead scans " + cvList.size() + " CVs");
    }
    while (cvListIterator != null && cvListIterator.hasNext()) {
        int cvNum = cvListIterator.next();
        CvValue cv = _cvModel.getCvByRow(cvNum);
        if (log.isDebugEnabled()) {
            log.debug("nextRead cv index " + cvNum + " state " + cv.getState());
        }
        if (cv.isToRead()) {
            // always read UNKNOWN state
            if (log.isDebugEnabled()) {
                log.debug("start read of cv " + cvNum);
            }
            setBusy(true);
            if (_programmingCV != null) {
                log.error("listener already set at read start");
            }
            _programmingCV = _cvModel.getCvByRow(cvNum);
            _read = true;
            // get notified when that state changes so can repeat
            _programmingCV.addPropertyChangeListener(this);
            // and make the read request
            // _programmingCV.setToRead(false);  // CVs set this themselves
            _programmingCV.read(_cvModel.getStatusLabel());
            if (log.isDebugEnabled()) {
                log.debug("return from starting CV read");
            }
            // only make one request at a time!
            return true;
        }
    }
    // found no CVs needing read, try indexed CVs
    if (log.isDebugEnabled()) {
        log.debug("nextRead scans " + indexedCvList.size() + " indexed CVs");
    }
    while ((indexedCvList.size() > 0) && (indexedCvListIndex < indexedCvList.size())) {
        int indxVarNum = indexedCvList.get(indexedCvListIndex);
        int indxState = _varModel.getState(indxVarNum);
        if (log.isDebugEnabled()) {
            log.debug("nextRead indexed cv @ row index " + indexedCvListIndex + " state " + indxState);
        }
        VariableValue iCv = _varModel.getVariable(indxVarNum);
        indexedCvListIndex++;
        if (iCv.isToRead()) {
            String sz = "start read of indexed cv " + (_indexedCvModel.getCvByRow(indexedCvListIndex - 1)).cvName();
            if (log.isDebugEnabled()) {
                log.debug(sz);
            }
            setBusy(true);
            if (_programmingIndexedCV != null) {
                log.error("listener already set at read start");
            }
            _programmingIndexedCV = _varModel.getVariable(indxVarNum);
            _read = true;
            // get notified when that state changes so can repeat
            _programmingIndexedCV.addPropertyChangeListener(this);
            // and make the read request
            // _programmingIndexedCV.setToRead(false);  // CVs set this themselves
            _programmingIndexedCV.readAll();
            if (log.isDebugEnabled()) {
                log.debug("return from starting indexed CV read");
            }
            // only make one request at a time!
            return true;
        }
    }
    // nothing to program, end politely
    if (log.isDebugEnabled()) {
        log.debug("nextRead found nothing to do");
    }
    readChangesButton.setSelected(false);
    // reset both, as that's final state we want
    readAllButton.setSelected(false);
    setBusy(false);
    container.paneFinished();
    return false;
}
Also used : VariableValue(jmri.jmrit.symbolicprog.VariableValue) CvValue(jmri.jmrit.symbolicprog.CvValue)

Example 10 with CvValue

use of jmri.jmrit.symbolicprog.CvValue in project JMRI by JMRI.

the class PaneProgFrame method resetToDefaults.

/**
     * Reset all CV values to defaults stored earlier.
     * <p>
     * This will in turn update the variables.
     */
protected void resetToDefaults() {
    int n = defaultCvValues.length;
    for (int i = 0; i < n; i++) {
        CvValue cv = cvModel.getCvByNumber(defaultCvNumbers[i]);
        if (cv == null) {
            log.warn("Trying to set default in CV " + defaultCvNumbers[i] + " but didn't find the CV object");
        } else {
            cv.setValue(defaultCvValues[i]);
        }
    }
    n = defaultIndexedCvValues.length;
    for (int i = 0; i < n; i++) {
        CvValue cv = iCvModel.getCvByRow(i);
        if (cv == null) {
            log.warn("Trying to set default in indexed CV from row " + i + " but didn't find the CV object");
        } else {
            cv.setValue(defaultIndexedCvValues[i]);
        }
    }
}
Also used : CvValue(jmri.jmrit.symbolicprog.CvValue)

Aggregations

CvValue (jmri.jmrit.symbolicprog.CvValue)10 VariableValue (jmri.jmrit.symbolicprog.VariableValue)7 Font (java.awt.Font)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 JLabel (javax.swing.JLabel)1 JProgressBar (javax.swing.JProgressBar)1 JWindow (javax.swing.JWindow)1 DecoderFile (jmri.jmrit.decoderdefn.DecoderFile)1 Attribute (org.jdom2.Attribute)1 Element (org.jdom2.Element)1