Search in sources :

Example 1 with GLGridResolution

use of maspack.render.GL.GLGridResolution in project artisynth_core by artisynth.

the class GridResolutionField method textToValue.

public Object textToValue(String text, BooleanHolder corrected, StringHolder errMsg) {
    corrected.value = false;
    ReaderTokenizer rtok = new ReaderTokenizer(new StringReader(text));
    double cellSize = 1;
    int numDivisions = 1;
    text = text.trim();
    if (text.equals("*")) {
        // return a resolution with 0 cellSize, indicating auto-sizing.
        return validValue(new GLGridResolution(0, 1), errMsg);
    }
    if (isBlank(text)) {
        return illegalValue("Void value not permited", errMsg);
    }
    try {
        if (rtok.nextToken() != ReaderTokenizer.TT_NUMBER) {
            return illegalValue("Improperly formed cell size", errMsg);
        }
        cellSize = rtok.nval;
        if (rtok.nextToken() == ReaderTokenizer.TT_EOF) {
            return validValue(new GLGridResolution(cellSize, 1), errMsg);
        } else if (rtok.ttype != '/') {
            return illegalValue("Expecting '/' after cell size", errMsg);
        }
        if (rtok.nextToken() != ReaderTokenizer.TT_NUMBER) {
            return illegalValue("Expecting number of cell divisions after '/'", errMsg);
        }
        if (rtok.nval < 1) {
            return illegalValue("number of cell divisions must be positive integer", errMsg);
        }
        numDivisions = (int) rtok.nval;
        if (numDivisions != rtok.nval) {
            corrected.value = true;
        }
        return validValue(new GLGridResolution(cellSize, numDivisions), errMsg);
    } catch (Exception e) {
        return illegalValue("Improperly formed resolution", errMsg);
    }
}
Also used : ReaderTokenizer(maspack.util.ReaderTokenizer) StringReader(java.io.StringReader) GLGridResolution(maspack.render.GL.GLGridResolution) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 GLGridResolution (maspack.render.GL.GLGridResolution)1 ReaderTokenizer (maspack.util.ReaderTokenizer)1