From: <ha...@us...> - 2011-01-23 01:20:21
|
Revision: 15020 http://jmol.svn.sourceforge.net/jmol/?rev=15020&view=rev Author: hansonr Date: 2011-01-23 01:20:13 +0000 (Sun, 23 Jan 2011) Log Message: ----------- version=12.1.32_dev # bug fix: If a script such as "test.spt" creates a function # test(), then the next implicit script command "test.spt" will fail # bug fix: implicit script command XXXX.xxx loses case of filename # # code: ScriptVariable simplified # -- ScriptVariable[]objects --> (ArrayList<ScriptVariable>)value # new feature: <array1> | x # -- IN PLACE concatenation # -- array1 will be appended to # -- if x is an array of length n, then n elements will be added # -- works as a |= b # -- to append a full array as one element, use a |= [x] # -- to append with creating a NEW array, use a + x or a + [x] instead # bug fix: array appending appends string values # new feature: "unset" command same as "reset" # -- for example: # a = array([1,2,3],[4,5,6],[7,8,9]) # y = a[3] # unset a # show variables # y = [7,8,9]; # -- just looks better for variables # -- good to use this if just a small part of a large array # or hashtable is wanted and the rest can be discarded # new feature: sort/reverse does array sorting IN PLACE, not by copying # -- for example: # y = x.sort # x is sorted, and y is a copy of that # -- still need x = x.sort in general, because "x.sort" is not a command # new feature: array assignment is always by reference, as for JavaScript and Java # -- y = x[3], if x[3] = [3, 4, 5], assigns y to [3, 4, 5], so if later # one uses y[4] = "new", then at that point x[3] = [3, 4, 5, "new"] # -- y == x[3] distinction removed # new feature: x = intersection(plane, plane) # new feature: x = intersection(pt, plane) (i.e. line perp to plane through pt) # new feature: x = intersection(ptLine, vLine, plane) # new feature: x = intersection(ptLine, vLine, point) (i.e. plane perp to line through point -- projection of point onto line) # new feature: draw polygon @x @y where @x and @y are arrays of points and faces, respectively # bug fix: frame 0.0 does NOT enable all frames; breaks "quaternion" command # bug fix: isosurface fragment fix # bug fix: cartesian exporter capping cylinders flat and spherical both # bug fix: Jmol logo was missing from the Help>What's New window. # bug fix (improvement): the Help>User Guide window was too narrow. # bug fix: echo @x when x is an associative array # bug fix: write t.jvxl does not work for new solvent/molecular surfaces business Modified Paths: -------------- trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceGenerator.java trunk/Jmol/src/org/jmol/script/ScriptCompilationTokenParser.java trunk/Jmol/src/org/jmol/script/ScriptCompiler.java trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java trunk/Jmol/src/org/jmol/script/ScriptFunction.java trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java trunk/Jmol/src/org/jmol/script/ScriptVariable.java trunk/Jmol/src/org/jmol/script/Token.java trunk/Jmol/src/org/jmol/shape/FontLineShapeRenderer.java trunk/Jmol/src/org/jmol/shapesurface/Isosurface.java trunk/Jmol/src/org/jmol/util/Escape.java trunk/Jmol/src/org/jmol/viewer/ColorManager.java trunk/Jmol/src/org/jmol/viewer/Jmol.properties Modified: trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceGenerator.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceGenerator.java 2011-01-23 01:19:30 UTC (rev 15019) +++ trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceGenerator.java 2011-01-23 01:20:13 UTC (rev 15020) @@ -206,7 +206,7 @@ return atomDataServer; } - ColorEncoder getColorEncoder() { + public ColorEncoder getColorEncoder() { return params.colorEncoder; } Modified: trunk/Jmol/src/org/jmol/script/ScriptCompilationTokenParser.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptCompilationTokenParser.java 2011-01-23 01:19:30 UTC (rev 15019) +++ trunk/Jmol/src/org/jmol/script/ScriptCompilationTokenParser.java 2011-01-23 01:20:13 UTC (rev 15020) @@ -813,8 +813,7 @@ } if (tokenAttr(tokenAtomProperty, Token.strproperty) && tokenComparator.tok != Token.opEQ - && tokenComparator.tok != Token.opNE - && tokenComparator.tok != Token.opEQEQ) + && tokenComparator.tok != Token.opNE) return error(ERROR_tokenExpected, "== !="); if (getToken() == null) return error(ERROR_unrecognizedExpressionToken, "" + valuePeek()); Modified: trunk/Jmol/src/org/jmol/script/ScriptCompiler.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptCompiler.java 2011-01-23 01:19:30 UTC (rev 15019) +++ trunk/Jmol/src/org/jmol/script/ScriptCompiler.java 2011-01-23 01:20:13 UTC (rev 15020) @@ -736,15 +736,6 @@ atokenInfix = new Token[0]; return true; } - if (isNewSet && setEqualPt == Integer.MAX_VALUE && tokAt(2) == Token.per - && ltoken.size() == 4) { - // implicit script command - isNewSet = false; - String name = "" + tokenAt(1).value + "." + tokenAt(3).value; - ltoken.clear(); - addTokenToPrefix(Token.tokenScript); - addTokenToPrefix(new Token(Token.string, name)); - } setCommand(tokenAt(0)); int size = ltoken.size(); if (size == 1 && Token.tokAttr(tokCommand, Token.defaultON)) @@ -869,7 +860,7 @@ char ch2 = (ichToken + 1 >= cchScript ? 0 : script.charAt(ichToken + 1)); if (Token.tokAttr(tokCommand, Token.setparam) && ch == '=' || (isNewSet || isSetBrace) && (isAndEquals || ch == '.' || ch == '[')) { - setCommand(isAndEquals ? (ch == '=' && ch2 == '=' ? Token.tokenSetEqEq : Token.tokenSet) + setCommand(isAndEquals ? Token.tokenSet : ch == '[' && !isSetBrace ? Token.tokenSetArray : Token.tokenSetProperty); ltoken.add(0, tokenCommand); cchToken = 1; @@ -1119,41 +1110,50 @@ return ERROR(ERROR_badContext, ident); switch (theTok) { case Token.identifier: - if (nTokens == 0 && ident.charAt(0) == '\'') { - addTokenToPrefix(setCommand(Token.tokenScript)); - cchToken = 0; - return CONTINUE; - } - break; - case Token.andequals: - if (theTok == Token.andequals) { - if (nSemiSkip == forPoint3 && nTokens == ptSemi + 2) { - token = lastToken; - addTokenToPrefix(Token.tokenEquals); - addTokenToPrefix(token); - token = Token.getTokenFromName(ident.substring(0, 1)); - addTokenToPrefix(token); - addTokenToPrefix(Token.tokenLeftParen); - needRightParen = true; + if (nTokens == 0) { + if (ident.charAt(0) == '\'') { + addTokenToPrefix(setCommand(Token.tokenScript)); + cchToken = 0; return CONTINUE; } - checkNewSetCommand(); - if (tokCommand == Token.set) { - tokenAndEquals = Token.getTokenFromName(ident.substring(0, 1)); - setEqualPt = ichToken; - return OK; + if (ichToken + cchToken < cchScript && script.charAt(ichToken + cchToken) == '.') { + addTokenToPrefix(setCommand(Token.tokenScript)); + nTokens = 1; + cchToken = 0; + return CONTINUE; } - if (tokCommand == Token.slab || tokCommand == Token.depth) { - addTokenToPrefix(tokenCommand); - replaceCommand(Token.tokenSet); - tokenAndEquals = Token.getTokenFromName(ident.substring(0, 1)); - setEqualPt = ichToken; - return OK; - } - // otherwise ignore - return CONTINUE; } break; + case Token.andequals: + if (nSemiSkip == forPoint3 && nTokens == ptSemi + 2) { + token = lastToken; + addTokenToPrefix(Token.tokenEquals); + addTokenToPrefix(token); + token = Token.getTokenFromName(ident.substring(0, 1)); + addTokenToPrefix(token); + addTokenToPrefix(Token.tokenLeftParen); + needRightParen = true; + return CONTINUE; + } + // check to see if we have a command name that + // was not registered yet as a local variable: + // var color = 3 + // color += 3 + checkNewSetCommand(); + if (tokCommand == Token.set) { + tokenAndEquals = Token.getTokenFromName(ident.substring(0, 1)); + setEqualPt = ichToken; + return OK; + } + if (tokCommand == Token.slab || tokCommand == Token.depth) { + addTokenToPrefix(tokenCommand); + replaceCommand(Token.tokenSet); + tokenAndEquals = Token.getTokenFromName(ident.substring(0, 1)); + setEqualPt = ichToken; + return OK; + } + // otherwise ignore + return CONTINUE; case Token.end: case Token.endifcmd: if (flowContext != null) @@ -1211,7 +1211,6 @@ } break; case Token.opEQ: - case Token.opEQEQ: if (parenCount == 0 && bracketCount == 0) setEqualPt = ichToken; break; @@ -1603,7 +1602,7 @@ return CONTINUE; } if (nTokens == 2) { - if (theTok == Token.opEQ || theTok == Token.opEQEQ) { + if (theTok == Token.opEQ) { // we are looking at @x =.... just insert a SET command // and ignore the =. It's the same as set @x ... ltoken.add(0, Token.tokenSet); @@ -1635,7 +1634,7 @@ private Token setNewSetCommand(boolean isSetBrace, String ident) { tokCommand = Token.set; - isNewSet = !isSetBrace && !isUserFunction(ident); + isNewSet = (!isSetBrace && !isUserFunction(ident)); setBraceCount = (isSetBrace ? 1 : 0); bracketCount = 0; setEqualPt = Integer.MAX_VALUE; Modified: trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java 2011-01-23 01:19:30 UTC (rev 15019) +++ trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java 2011-01-23 01:20:13 UTC (rev 15020) @@ -1611,7 +1611,7 @@ ArrayList<ScriptVariable> sv = null; int nValues = 0; if (tokenValue.tok == Token.varray) { - sv = ((ScriptVariable) tokenValue).objects; + sv = ((ScriptVariable) tokenValue).getList(); if ((nValues = sv.size()) == 0) return; } @@ -2171,13 +2171,15 @@ continue; switch (tok = getToken(i).tok) { case Token.define: + if (++i == statementLength) + error(ERROR_invalidArgument); Object v; // compiler can indicate that a definition MUST // be interpreted as a String boolean forceString = (theToken.intValue == Token.string); // Object var_set; String s; - String var = parameterAsString(++i); + String var = parameterAsString(i); boolean isClauseDefine = (tokAt(i) == Token.expressionBegin); if (isClauseDefine) { ScriptVariable vt = parameterExpressionToken(++i); @@ -2265,13 +2267,14 @@ ArrayList<ScriptVariable> sv = (ArrayList<ScriptVariable>) v; BitSet bs = null; for (int k = 0; k < sv.size(); k++) { - if (sv.get(k).tok != Token.bitset) { + ScriptVariable svk = sv.get(k); + if (svk.tok != Token.bitset) { bs = null; break; - } else if (bs == null) { + } + if (bs == null) bs = new BitSet(); - } - bs.or((BitSet) sv.get(k).value); + bs.or((BitSet) svk.value); } fixed[j] = (bs == null ? ScriptVariable.getVariable(v) : new Token(Token.bitset, bs)); @@ -3221,6 +3224,7 @@ * @return atom bitset * @throws ScriptException */ + @SuppressWarnings("unchecked") private BitSet atomExpression(Token[] code, int pcStart, int pcStop, boolean allowRefresh, boolean allowUnderflow, boolean mustBeBitSet, boolean andNotDeleted) @@ -3472,7 +3476,6 @@ case Token.opGE: case Token.opGT: case Token.opEQ: - case Token.opEQEQ: case Token.opNE: if (pc + 1 == code.length) error(ERROR_invalidArgument); @@ -3485,7 +3488,7 @@ error(ERROR_invalidArgument); val = code[++pc].value; } - if (tokWhat == Token.configuration && tokOperator != Token.opEQ && tokOperator != Token.opEQEQ) + if (tokWhat == Token.configuration && tokOperator != Token.opEQ) error(ERROR_invalidArgument); if (isSyntaxCheck) { rpn.addX(new BitSet()); @@ -3579,7 +3582,7 @@ tokWhat = Token.file; isModel = false; } - if (tokWhat == -Token.model && tokOperator == Token.opEQ && tokOperator == Token.opEQEQ) { + if (tokWhat == -Token.model && tokOperator == Token.opEQ) { rpn.addX(bitSetForModelFileNumber(comparisonValue)); break; } @@ -3622,7 +3625,7 @@ if (val instanceof String) val = getStringObjectAsVariable((String) val, null); if (val instanceof ArrayList<?>) { - BitSet bs = Escape.unEscapeBitSetArray(val, true); + BitSet bs = ScriptVariable.unEscapeBitSetArray((ArrayList<ScriptVariable>)val, true); if (bs != null) val = bs; } else if (val instanceof String) { @@ -3745,7 +3748,6 @@ case Token.opGT: return BitSetUtil.newBitSet(comparisonValue + 1, atomCount); case Token.opEQ: - case Token.opEQEQ: return (comparisonValue < atomCount ? BitSetUtil.newBitSet( comparisonValue, comparisonValue + 1) : new BitSet()); case Token.opNE: @@ -3842,7 +3844,6 @@ imin = comparisonValue; break; case Token.opEQ: - case Token.opEQEQ: imax = comparisonValue; imin = comparisonValue - 1; break; @@ -3877,7 +3878,6 @@ match = (propertyValue > comparisonValue); break; case Token.opEQ: - case Token.opEQEQ: match = (propertyValue == comparisonValue); break; case Token.opNE: @@ -3894,7 +3894,6 @@ String comparisonValue) throws ScriptException { switch (tokOperator) { case Token.opEQ: - case Token.opEQEQ: case Token.opNE: return (TextFormat.isMatch(propertyValue, comparisonValue, true, true) == (tokOperator == Token.opEQ)); default: @@ -3915,7 +3914,6 @@ case Token.opGT: return propertyFloat > comparisonFloat; case Token.opEQ: - case Token.opEQEQ: return propertyFloat == comparisonFloat; case Token.opNE: return propertyFloat != comparisonFloat; @@ -4192,14 +4190,14 @@ int tok = (i < 0 ? Token.varray : getToken(i++).tok); switch (tok) { case Token.varray: - ScriptVariable v = (ScriptVariable) theToken; - if (nPoints >= 0 && v.objects.size() != nPoints) + ArrayList<ScriptVariable> v = ((ScriptVariable) theToken).getList(); + if (nPoints >= 0 && v.size() != nPoints) error(ERROR_invalidArgument); - nPoints = v.objects.size(); + nPoints = v.size(); if (points == null) points = new Point3f[nPoints]; for (int j = 0; j < nPoints; j++) - if ((points[j] = ScriptVariable.ptValue(v.objects.get(j))) == null) + if ((points[j] = ScriptVariable.ptValue(v.get(j))) == null) error(ERROR_invalidArgument); return points; case Token.spacebeforesquare: @@ -5720,7 +5718,7 @@ } if (Token.tokAttr(tokAt(j), Token.misc) || getContextVariableAsVariable(key) != null) { - if (bsIn == null && !isMinusMinus && getToken(++j).tok != Token.opEQ && theTok != Token.opEQEQ) + if (bsIn == null && !isMinusMinus && getToken(++j).tok != Token.opEQ) error(ERROR_invalidArgument); if (bsIn == null) { if (isMinusMinus) @@ -5950,7 +5948,6 @@ if (tv == null) tv = (v == null ? ScriptVariable.intVariable(0) : v); t.value = tv.value; - t.objects = tv.objects; t.intValue = tv.intValue; t.tok = tv.tok; gotoCmd(null); @@ -6574,10 +6571,10 @@ error(ERROR_invalidArgument); isQuaternion = true; data1 = ScriptMathProcessor - .getQuaternionArray(((ScriptVariable)theToken).objects); + .getQuaternionArray(((ScriptVariable)theToken).getList()); getToken(++i); data2 = ScriptMathProcessor - .getQuaternionArray(((ScriptVariable)theToken).objects); + .getQuaternionArray(((ScriptVariable)theToken).getList()); if (vQuatSets == null) vQuatSets = new ArrayList<Object[]>(); vQuatSets.add(new Object[] { data1, data2 }); @@ -9646,10 +9643,10 @@ private Quaternion getQuaternionParameter(int i) throws ScriptException { if (tokAt(i) == Token.varray) { - ScriptVariable sv = (ScriptVariable) getToken(i); + ArrayList<ScriptVariable> sv = ((ScriptVariable) getToken(i)).getList(); Point4f p4 = null; - if (sv.objects.size() == 0 - || (p4 = ScriptVariable.pt4Value(sv.objects.get(0))) == null) + if (sv.size() == 0 + || (p4 = ScriptVariable.pt4Value(sv.get(0))) == null) error(ERROR_invalidArgument); return new Quaternion(p4); } @@ -9663,7 +9660,7 @@ case Token.varray: List<Point3f> data = new ArrayList<Point3f>(); Point3f pt; - ArrayList<ScriptVariable> pts = ((ScriptVariable) t).objects; + ArrayList<ScriptVariable> pts = ((ScriptVariable) t).getList(); for (int j = 0; j < pts.size(); j++) if ((pt = ScriptVariable.ptValue(pts.get(j))) != null) data.add(pt); @@ -12136,9 +12133,9 @@ // a[...][...].xxx = // var a[...][...].xxx = - int pt = (tok2 == Token.opEQ || tok2 == Token.opEQEQ ? 3 + int pt = (tok2 == Token.opEQ ? 3 // set x = ... - : setType == '=' && !key.equals("return") && tok2 != Token.opEQ && tok2 != Token.opEQEQ ? 0 + : setType == '=' && !key.equals("return") && tok2 != Token.opEQ ? 0 // {c}.xxx = // {...}.xxx = // {{...}[n]}.xxx = @@ -12738,7 +12735,6 @@ BitSet bs = null; String propertyName = ""; int tokProperty = Token.nada; - boolean isEqEq = (setType == '#'); boolean isArrayItem = (setType == '['); boolean settingProperty = false; boolean isExpression = false; @@ -12797,7 +12793,7 @@ int nParam = v.size() / 2; for (int i = 0; i < nParam; i++) { boolean isLast = (i + 1 == nParam); - ScriptVariable vv = (v).get(i * 2); + ScriptVariable vv = v.get(i * 2); // stack is selector [ selector [ selector [ ... VALUE if (t.tok == Token.bitset) { t.tok = Token.hash; @@ -12815,20 +12811,21 @@ int ipt = ScriptVariable.iValue(vv); switch (t.tok) { case Token.varray: - if (ipt > t.objects.size() || isLast) + ArrayList<ScriptVariable> list = t.getList(); + if (ipt > list.size() || isLast) break; if (ipt <= 0) - ipt = t.objects.size() + ipt; + ipt = list.size() + ipt; if (--ipt < 0) ipt = 0; - t = t.objects.get(ipt); + t = list.get(ipt); continue; case Token.matrix3f: case Token.matrix4f: // check for row/column replacement int dim = (t.tok == Token.matrix3f ? 3 : 4); if (nParam == 1 && Math.abs(ipt) >= 1 && Math.abs(ipt) <= dim - && tnew.tok == Token.varray && tnew.objects.size() == dim) + && tnew.tok == Token.varray && tnew.getList().size() == dim) break; if (nParam == 2) { int ipt2 = ScriptVariable.iValue(v.get(2)); @@ -12871,7 +12868,7 @@ } if (isUserVariable) { - t.set(tv, !isEqEq); + t.set(tv, false); return; } @@ -14230,7 +14227,7 @@ int nVertices = 0; int nTriangles = 0; Point3f[] points = null; - ScriptVariable vpolygons = null; + List<ScriptVariable> vpolygons = null; if (isArrayParameter(++i)) { points = getPointArray(i, -1); nVertices = points.length; @@ -14240,14 +14237,17 @@ for (int j = 0; j < nVertices; j++) points[j] = centerParameter(++iToken); } - switch (tokAt(++iToken)) { + switch (getToken(++iToken).tok) { case Token.matrix3f: case Token.matrix4f: + ScriptVariable sv = new ScriptVariable(theToken); + sv.toArray(); + vpolygons = sv.getList(); + nTriangles = vpolygons.size(); + break; case Token.varray: - vpolygons = (ScriptVariable) getToken(iToken); - if (theTok != Token.varray) - vpolygons.toArray(); - nTriangles = vpolygons.objects.size(); + vpolygons = ((ScriptVariable) theToken).getList(); + nTriangles = vpolygons.size(); break; default: nTriangles = Math.max(0, intParameter(iToken)); @@ -14255,7 +14255,7 @@ int[][] polygons = new int[nTriangles][]; for (int j = 0; j < nTriangles; j++) { float[] f = (vpolygons == null ? floatParameterSet(++iToken, 3, 4) - : ScriptVariable.flistValue(vpolygons.objects.get(j), 0)); + : ScriptVariable.flistValue(vpolygons.get(j), 0)); if (f.length < 3 || f.length > 4) error(ERROR_invalidArgument); polygons[j] = new int[] { (int) f[0], (int) f[1], (int) f[2], Modified: trunk/Jmol/src/org/jmol/script/ScriptFunction.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptFunction.java 2011-01-23 01:19:30 UTC (rev 15019) +++ trunk/Jmol/src/org/jmol/script/ScriptFunction.java 2011-01-23 01:20:13 UTC (rev 15020) @@ -98,7 +98,7 @@ ScriptVariable local = contextVariables.get(names.get(i).toLowerCase()); if (local.tok != Token.varray) // TODO: list type? continue; - global.objects = local.objects; + global.value = local.value; } } Modified: trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java 2011-01-23 01:19:30 UTC (rev 15019) +++ trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java 2011-01-23 01:20:13 UTC (rev 15020) @@ -66,7 +66,7 @@ /** * Reverse Polish Notation Engine for IF, SET, and %{...} -- Bob Hanson * 2/16/2007 Just a (not so simple?) RPN processor that can handle boolean, - * int, float, String, Point3f, and BitSet + * int, float, String, Point3f, BitSet, Array, Hashtable, Matrix3f, Matrix4f * * ha...@st... * @@ -109,6 +109,7 @@ Logger.info("initialize RPN"); } + @SuppressWarnings("unchecked") ScriptVariable getResult(boolean allowUnderflow) throws ScriptException { boolean isOK = true; @@ -131,7 +132,7 @@ x = ScriptVariable.selectItem(x); if (asBitSet && x.tok == Token.varray) - x = new ScriptVariable(Token.bitset, Escape.unEscapeBitSetArray(x.objects, false)); + x = new ScriptVariable(Token.bitset, ScriptVariable.unEscapeBitSetArray((ArrayList<ScriptVariable>)x.value, false)); return x; } } @@ -519,7 +520,7 @@ oPt--; if (oPt < 0) return true; - if (isOpFunc(oStack[oPt]) && !evaluateFunction()) + if (isOpFunc(oStack[oPt]) && !evaluateFunction(0)) return false; skipping = (ifPt >= 0 && ifStack[ifPt] == 'X'); return true; @@ -535,7 +536,7 @@ if (squareCount-- <= 0 || oPt < 0) return false; if (oStack[oPt].tok == Token.array) - return evaluateFunction(); + return evaluateFunction(Token.leftsquare); oPt--; return true; case Token.propselector: @@ -552,7 +553,7 @@ break; case Token.opAnd: case Token.opOr: - if (!wasSyntaxCheck && xStack[xPt].tok != Token.bitset) { + if (!wasSyntaxCheck && xStack[xPt].tok != Token.bitset && xStack[xPt].tok != Token.varray) { // check to see if we need to evaluate the second operand or not // if not, then set this to syntax check in order to skip :) // Jmol 12.0.4, Jmol 12.1.2 @@ -566,7 +567,6 @@ wasX = false; break; case Token.opEQ: - case Token.opEQEQ: if (squareCount == 0) equalCount++; wasX = false; @@ -583,7 +583,7 @@ if (op.tok == Token.propselector && (op.intValue & ~Token.minmaxmask) == Token.function && op.intValue != Token.function) { - return evaluateFunction(); + return evaluateFunction(0); } return true; } @@ -634,11 +634,12 @@ return v; } - private boolean evaluateFunction() throws ScriptException { + private boolean evaluateFunction(int tok) throws ScriptException { Token op = oStack[oPt--]; // for .xxx or .xxx() functions // we store the token in the intValue field of the propselector token - int tok = (op.tok == Token.propselector ? op.intValue & ~Token.minmaxmask + if (tok == 0) + tok = (op.tok == Token.propselector ? op.intValue & ~Token.minmaxmask : op.tok); int nParamMax = Token.getMaxMathParams(tok); // note - this is NINE for @@ -673,7 +674,8 @@ case Token.sub: return evaluateList(op.intValue, args); case Token.array: - return evaluateArray(args); + case Token.leftsquare: + return evaluateArray(args, tok == Token.leftsquare); case Token.axisangle: case Token.quaternion: return evaluateQuaternion(args, tok); @@ -942,9 +944,10 @@ if (isListf) { data = (float[]) x1.value; } else { - data = new float[x1.objects.size()]; - for (int i = x1.objects.size(); --i >= 0; ) - data[i] = ScriptVariable.fValue(x1.objects.get(i)); + ArrayList<ScriptVariable> list = x1.getList(); + data = new float[list.size()]; + for (int i = list.size(); --i >= 0; ) + data[i] = ScriptVariable.fValue(list.get(i)); } int nbins = (int) ((f1 - f0) / df + 0.01f); int[] array = new int[nbins]; @@ -1602,12 +1605,13 @@ boolean isScalar = (x2.tok != Token.varray && ScriptVariable.sValue(x2) .indexOf("\n") < 0); - float[] list1; - float[] list2; - + float[] list1 = null; + float[] list2 = null; + ArrayList<ScriptVariable> alist1 = x1.getList(); + ArrayList<ScriptVariable> alist2 = x2.getList(); + if (x1.tok == Token.varray) { - list1 = null; - len = x1.objects.size(); + len = alist1.size(); } else { sList1 = (TextFormat.split((String) x1.value, "\n")); list1 = new float[len = sList1.length]; @@ -1616,22 +1620,22 @@ if (isAll) { float sum = 0f; - if (x1.tok == Token.varray) + if (x1.tok == Token.varray) { for (int i = len; --i >= 0;) - sum += ScriptVariable.fValue(x1.objects.get(i)); - else + sum += ScriptVariable.fValue(alist1.get(i)); + } else { for (int i = len; --i >= 0;) sum += list1[i]; + } return addX(sum); } ScriptVariable scalar = null; if (isScalar) { - list2 = null; scalar = x2; } else if (x2.tok == Token.varray) { - list2 = null; + len = Math.min(list1.length, alist2.size()); } else { sList2 = TextFormat.split((String) x2.value, "\n"); list2 = new float[sList2.length]; @@ -1659,7 +1663,7 @@ for (int i = 0; i < len; i++) { if (x1.tok == Token.varray) - addX(x1.objects.get(i)); + addX(alist1.get(i)); else if (Float.isNaN(list1[i])) addX(ScriptVariable.unescapePointOrBitsetAsVariable(sList1[i])); else @@ -1668,7 +1672,7 @@ if (isScalar) addX(scalar); else if (x2.tok == Token.varray) - addX(x2.objects.get(i)); + addX(alist2.get(i)); else if (Float.isNaN(list2[i])) addX(ScriptVariable.unescapePointOrBitsetAsVariable(sList2[i])); else @@ -1724,24 +1728,26 @@ } - private boolean evaluateArray(ScriptVariable[] args) { + private boolean evaluateArray(ScriptVariable[] args, boolean allowMatrix) { int len = args.length; - if (len == 4 || len == 3) { + if (allowMatrix && (len == 4 || len == 3)) { boolean isMatrix = true; for (int i = 0; i < len && isMatrix; i++) - isMatrix = (args[i].tok == Token.varray && args[i].objects.size() == len); + isMatrix = (args[i].tok == Token.varray && args[i].getList().size() == len); if (isMatrix) { float[] m = new float[len * len]; int pt = 0; - for (int i = 0; i < len && isMatrix; i++) + for (int i = 0; i < len && isMatrix; i++) { + ArrayList<ScriptVariable> list = args[i].getList(); for (int j = 0; j < len; j++) { - float x = ScriptVariable.fValue(args[i].objects.get(j)); + float x = ScriptVariable.fValue(list.get(j)); if (Float.isNaN(x)) { isMatrix = false; break; } m[pt++] = x; } + } if (isMatrix) { if (len == 3) return addX(new Matrix3f(m)); @@ -1859,7 +1865,7 @@ case 1: default: if (tok == Token.quaternion && args[0].tok == Token.varray) { - Quaternion[] data1 = getQuaternionArray(args[0].objects); + Quaternion[] data1 = getQuaternionArray(args[0].getList()); Object mean = Quaternion.sphereMean(data1, null, 0.0001f); q = (mean instanceof Quaternion ? (Quaternion) mean : null); break; @@ -1881,8 +1887,8 @@ case 2: if (tok == Token.quaternion) { if (args[0].tok == Token.varray && args[1].tok == Token.varray) { - Quaternion[] data1 = getQuaternionArray(args[0].objects); - Quaternion[] data2 = getQuaternionArray(args[1].objects); + Quaternion[] data1 = getQuaternionArray(args[0].getList()); + Quaternion[] data2 = getQuaternionArray(args[1].getList()); qs = Quaternion.div(data2, data1, nMax, isRelative); break; } @@ -2423,7 +2429,7 @@ // check for a[3][2] if (isArrayItem && squareCount == 0 && equalCount == 1 && oPt < 0 - && (op.tok == Token.opEQ || op.tok == Token.opEQEQ)) { + && (op.tok == Token.opEQ)) { return true; } @@ -2560,6 +2566,8 @@ bs.or(ScriptVariable.bsSelect(x2)); return addX(bs); } + if (x1.tok == Token.varray) + return addX(ScriptVariable.concatList(x1, x2, false)); return addX(ScriptVariable.bValue(x1) || ScriptVariable.bValue(x2)); case Token.opXor: if (x1.tok == Token.bitset && x2.tok == Token.bitset) { @@ -2584,7 +2592,6 @@ case Token.opLT: return addX(ScriptVariable.fValue(x1) < ScriptVariable.fValue(x2)); case Token.opEQ: - case Token.opEQEQ: return addX(ScriptVariable.areEqual(x1, x2)); case Token.opNE: if (x1.tok == Token.string && x2.tok == Token.string) @@ -2602,7 +2609,7 @@ } case Token.plus: if (x1.tok == Token.varray || x2.tok == Token.varray) - return addX(ScriptVariable.concatList(x1, x2)); + return addX(ScriptVariable.concatList(x1, x2, true)); switch (x1.tok) { default: return addX(ScriptVariable.fValue(x1) + ScriptVariable.fValue(x2)); @@ -3060,13 +3067,13 @@ if (op.intValue == Token.min || op.intValue == Token.max || op.intValue == Token.average || op.intValue == Token.stddev || op.intValue == Token.sum || op.intValue == Token.sum2) { - return addX(getMinMax(x2.objects, op.intValue)); + return addX(getMinMax(x2.getList(), op.intValue)); } if (op.intValue == Token.sort || op.intValue == Token.reverse) return addX(x2.sortOrReverse(op.intValue == Token.reverse ? Integer.MIN_VALUE : 1)); - ScriptVariable[] list2 = new ScriptVariable[x2.objects.size()]; + ScriptVariable[] list2 = new ScriptVariable[x2.getList().size()]; for (int i = 0; i < list2.length; i++) { - Object v = ScriptVariable.unescapePointOrBitsetAsVariable(x2.objects.get(i)); + Object v = ScriptVariable.unescapePointOrBitsetAsVariable(x2.getList().get(i)); if (!(v instanceof ScriptVariable) || !getPointOrBitsetOperation(op, (ScriptVariable) v)) return false; Modified: trunk/Jmol/src/org/jmol/script/ScriptVariable.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptVariable.java 2011-01-23 01:19:30 UTC (rev 15019) +++ trunk/Jmol/src/org/jmol/script/ScriptVariable.java 2011-01-23 01:20:13 UTC (rev 15020) @@ -62,7 +62,6 @@ private int flags = ~FLAG_CANINCREMENT & FLAG_LOCALVAR; String name; - ArrayList<ScriptVariable> objects; public ScriptVariable() { tok = string; @@ -95,8 +94,6 @@ tok = x.tok; intValue = x.intValue; value = x.value; - if (tok == varray) - objects = ((ScriptVariable) x).objects; } static public String typeOf(ScriptVariable x) { @@ -144,7 +141,7 @@ case string: return ((String) x.value).length(); case varray: - return x.intValue == Integer.MAX_VALUE ? ((ScriptVariable)x).objects.size() + return x.intValue == Integer.MAX_VALUE ? ((ScriptVariable)x).getList().size() : sizeOf(selectItem(x)); case hash: return ((Map<String, ScriptVariable>) x.value).size(); @@ -183,7 +180,7 @@ /** * @param x * @return a ScriptVariable of the input type, or if x is null, then a new ScriptVariable, - * or, if the type is not found, null + * or, if the type is not found, a string version */ @SuppressWarnings("unchecked") public static ScriptVariable getVariable(Object x) { @@ -254,59 +251,62 @@ // all the rest are stored as list // at least for now, still saving as a string, // but ultimately, that should not be necessary - - ScriptVariable sv = null; + ArrayList<ScriptVariable> objects = null; + if (x instanceof List) { + // will be turned into list + List<Object> v = (List<Object>) x; + int len = v.size(); + if (len > 0 && v.get(0) instanceof ScriptVariable) + return new ScriptVariable(varray, v); + objects = new ArrayList<ScriptVariable>(); + for (int i = 0; i < len; i++) + objects.add(getVariable(v.get(i))); + return new ScriptVariable(varray, objects); + } if (x instanceof ScriptVariable[]) { objects = new ArrayList<ScriptVariable>(); ScriptVariable[] v = (ScriptVariable[]) x; - objects = new ArrayList<ScriptVariable>(); + objects = new ArrayList<ScriptVariable>(); for (int i = 0; i < v.length; i++) objects.add(v[i]); - sv = new ScriptVariable(varray); - } else if (x instanceof String[]) { + return new ScriptVariable(varray, objects); + } + if (x instanceof String[]) { String[] s = (String[]) x; objects = new ArrayList<ScriptVariable>(); for (int i = 0; i < s.length; i++) objects.add(getVariable(s[i])); - sv = new ScriptVariable(varray); - } if (x instanceof int[]) { + return new ScriptVariable(varray, objects); + } + if (x instanceof int[]) { int[] ix = (int[]) x; objects = new ArrayList<ScriptVariable>(); for (int i = 0; i < ix.length; i++) objects.add(getVariable(Integer.valueOf(ix[i]))); - sv = new ScriptVariable(varray); - } else if (x instanceof int[][]) { - int[][] ix = (int[][]) x; - objects = new ArrayList<ScriptVariable>(); - for (int i = 0; i < ix.length; i++) - objects.add(getVariable(ix[i])); - sv = new ScriptVariable(varray); - } else if (x instanceof float[]) { + return new ScriptVariable(varray, objects); + } + if (x instanceof float[]) { float[] f = (float[]) x; objects = new ArrayList<ScriptVariable>(); for (int i = 0; i < f.length; i++) objects.add(getVariable(Float.valueOf(f[i]))); - sv = new ScriptVariable(varray); - } else if (x instanceof double[]) { + return new ScriptVariable(varray, objects); + } + if (x instanceof double[]) { double[] f = (double[]) x; objects = new ArrayList<ScriptVariable>(); for (int i = 0; i < f.length; i++) objects.add(getVariable(Float.valueOf((float) f[i]))); - sv = new ScriptVariable(varray); - } else if (x instanceof List) { - // will be turned into list - List<Object> v = (List<Object>) x; - int len = v.size(); + return new ScriptVariable(varray, objects); + } + if (x instanceof int[][]) { + int[][] ix = (int[][]) x; objects = new ArrayList<ScriptVariable>(); - for (int i = 0; i < len; i++) - objects.add(getVariable(v.get(i))); - sv = new ScriptVariable(varray); + for (int i = 0; i < ix.length; i++) + objects.add(getVariable(ix[i])); + return new ScriptVariable(varray, objects); } - if (sv != null) { - sv.objects = objects; - return sv; - } return new ScriptVariable(string, Escape.toReadable(x)); } @@ -327,7 +327,6 @@ intValue = v.intValue; tok = v.tok; value = v.value; - objects = v.objects; if (asCopy) { switch (tok) { case hash: @@ -335,10 +334,11 @@ (Map<String, ScriptVariable>) v.value); break; case varray: - value = null; - objects = new ArrayList<ScriptVariable>(); - for (int i = 0; i < v.objects.size(); i++) - objects.add(v.objects.get(i)); + ArrayList<ScriptVariable> o2 = new ArrayList<ScriptVariable>(); + ArrayList<ScriptVariable> o1 = v.getList(); + for (int i = 0; i < o1.size(); i++) + o2.add(o1.get(i)); + value = o2; break; } } @@ -422,8 +422,6 @@ return Boolean.FALSE; case integer: return Integer.valueOf(x.intValue); - case varray: - return x.objects; default: return x.value; } @@ -516,7 +514,7 @@ case varray: int i = x.intValue; if (i == Integer.MAX_VALUE) - return ((ScriptVariable)x).objects.size(); + return ((ScriptVariable)x).getList().size(); case string: return toFloat(sValue(x)); case bitset: @@ -540,7 +538,7 @@ public static String sValue(Token x) { StringBuffer sb; - Map<Object,Boolean> map; + Map<Object, Boolean> map; if (x == null) return ""; int i; @@ -563,15 +561,17 @@ return Escape.escape(bsSelect(x), !(x.value instanceof BondSet)); case varray: case hash: - ScriptVariable vx = (ScriptVariable)x; - i = vx.intValue; - if (i <= 0) - i = vx.objects.size() - i; - if (i != Integer.MAX_VALUE) - return (i < 1 || i > vx.objects.size() ? "" : sValue(vx.objects.get(i - 1))); + if (x.tok == Token.varray) { + ArrayList<ScriptVariable> sv = ((ScriptVariable) x).getList(); + i = x.intValue; + if (i <= 0) + i = sv.size() - i; + if (i != Integer.MAX_VALUE) + return (i < 1 || i > sv.size() ? "" : sValue(sv.get(i - 1))); + } sb = new StringBuffer(); - map = new Hashtable<Object,Boolean>(); - sValueArray(sb, vx, map, 0, false); + map = new Hashtable<Object, Boolean>(); + sValueArray(sb, (ScriptVariable) x, map, 0, false); return sb.toString(); case string: String s = (String) x.value; @@ -636,10 +636,11 @@ map.put(vx, Boolean.TRUE); if (isEscaped) sb.append("["); - for (int i = 0; i < vx.objects.size(); i++) { + ArrayList<ScriptVariable> sx = vx.getList(); + for (int i = 0; i < sx.size(); i++) { if (isEscaped && i > 0) sb.append(","); - ScriptVariable sv = vx.objects.get(i); + ScriptVariable sv = sx.get(i); sValueArray(sb, sv, map, level + 1, isEscaped); if (!isEscaped) sb.append("\n"); @@ -688,24 +689,32 @@ return Parser.parseFloatStrict(s); } - public static ScriptVariable concatList(ScriptVariable x1, ScriptVariable x2) { - int pt = 0; - if (x1.tok == varray && x2.tok == varray) { - ArrayList<ScriptVariable> vlist = new ArrayList<ScriptVariable>(x1.objects.size() + x2.objects.size()); - for (int i = 0; i < x1.objects.size(); i++) - vlist.add(x1.objects.get(i)); - for (int i = 0; i < x2.objects.size(); i++) - vlist.add(x2.objects.get(i)); - return getVariable(vlist); + public static ScriptVariable concatList(ScriptVariable x1, ScriptVariable x2, + boolean asNew) { + ArrayList<ScriptVariable> v1 = x1.getList(); + ArrayList<ScriptVariable> v2 = x2.getList(); + if (!asNew) { + if (v2 == null) + v1.add(new ScriptVariable(x2)); + else + for (int i = 0; i < v2.size(); i++) + v1.add(v2.get(i)); + return x1; } - String[] list1 = TextFormat.split(sValue(x1), "\n"); - String[] list2 = TextFormat.split(sValue(x2), "\n"); - String[] list = new String[list1.length + list2.length]; - for (int i = 0; i < list1.length; i++) - list[pt++] = list1[i]; - for (int i = 0; i < list2.length; i++) - list[pt++] = list2[i]; - return getVariable(list); + ArrayList<ScriptVariable> vlist = new ArrayList<ScriptVariable>( + (v1 == null ? 1 : v1.size()) + (v2 == null ? 1 : v2.size())); + + if (v1 == null) + vlist.add(x1); + else + for (int i = 0; i < v1.size(); i++) + vlist.add(v1.get(i)); + if (v2 == null) + vlist.add(x2); + else + for (int i = 0; i < v2.size(); i++) + vlist.add(v2.get(i)); + return getVariable(vlist); } public static BitSet bsSelect(Token x) { @@ -769,8 +778,6 @@ if (i2 == Integer.MIN_VALUE) i2 = i1; ScriptVariable v = new ScriptVariable(tokenIn.tok, i2, tokenIn.value); - if (tokenIn.tok == varray) - v.objects = ((ScriptVariable)tokenIn).objects; return v; } int len = 0; @@ -791,7 +798,7 @@ tokenOut.value = bs; break; case varray: - len = ((ScriptVariable)tokenIn).objects.size(); + len = ((ScriptVariable)tokenIn).getList().size(); break; case string: s = (String) tokenIn.value; @@ -882,12 +889,13 @@ if (i1 < 1 || i1 > len || i2 > len) return new ScriptVariable(string, ""); if (i2 == i1) - return ((ScriptVariable) tokenIn).objects.get(i1 - 1); - ArrayList<ScriptVariable> objects = new ArrayList<ScriptVariable>(); + return ((ScriptVariable) tokenIn).getList().get(i1 - 1); + ArrayList<ScriptVariable> o2 = new ArrayList<ScriptVariable>(); + ArrayList<ScriptVariable> o1 = ((ScriptVariable) tokenIn).getList(); n = i2 - i1 + 1; for (int i = 0; i < n; i++) - objects.add(new ScriptVariable(((ScriptVariable) tokenIn).objects.get(i + i1 - 1))); - tokenOut.objects = objects; + o2.add(new ScriptVariable(o1.get(i + i1 - 1))); + tokenOut.value = o2; break; } return tokenOut; @@ -914,10 +922,11 @@ } if (selector != 0 && Math.abs(selector) <= len && var.tok == varray) { - if (var.objects.size() == len) { + ArrayList<ScriptVariable> sv = var.getList(); + if (sv.size() == len) { float[] data = new float[len]; for (int i = 0; i < len; i++) - data[i] = fValue(var.objects.get(i)); + data[i] = fValue(sv.get(i)); if (selector > 0) { if (tok == matrix3f) ((Matrix3f) value).setRow(selector - 1, data); @@ -946,16 +955,16 @@ + str.substring(selector + 1); return true; case varray: - len = objects.size(); + len = getList().size(); if (selector <= 0) selector = len + selector; if (--selector < 0) selector = 0; if (len <= selector) { for (int i = len; i <= selector; i++) - objects.add(getVariable("")); + getList().add(getVariable("")); } - objects.set(selector, var); + getList().set(selector, var); return true; } return false; @@ -1052,9 +1061,10 @@ Object[] of = new Object[] { vd, vf, ve, null, null}; if (var.tok != varray) return sprintf(strFormat, var, of, vd, vf, ve, getS, getP); - String[] list2 = new String[var.objects.size()]; - for (int i = 0; i < var.objects.size(); i++) - list2[i] = sprintf(strFormat, var.objects.get(i), of, vd, vf, ve, getS, getP); + ArrayList<ScriptVariable> sv = var.getList(); + String[] list2 = new String[sv.size()]; + for (int i = 0; i < list2.length; i++) + list2[i] = sprintf(strFormat, sv.get(i), of, vd, vf, ve, getS, getP); return list2; } @@ -1107,12 +1117,18 @@ return super.toString() + "[" + name + "] index =" + index + " hashcode=" + hashCode(); } + @SuppressWarnings("unchecked") public static BitSet getBitSet(ScriptVariable x, boolean allowNull) { switch (x.tok) { case bitset: return bsSelect(x); case varray: - return Escape.unEscapeBitSetArray(x.objects, allowNull); + BitSet bs = new BitSet(); + ArrayList<ScriptVariable> sv = (ArrayList<ScriptVariable>) x.value; + for (int i = 0; i < sv.size(); i++) + if (!sv.get(i).unEscapeBitSetArray(bs) && allowNull) + return null; + return bs; } return (allowNull ? null : new BitSet()); } @@ -1137,20 +1153,30 @@ } public int compare(ScriptVariable x, ScriptVariable y) { - if (x.tok != y.tok) - return 0; + if (x.tok != y.tok) { + if (x.tok == Token.decimal || x.tok == Token.integer + || y.tok == Token.decimal || y.tok == Token.integer) { + float fx = fValue(x); + float fy = fValue(y); + return (fx < fy ? -1 : fx > fy ? 1 : 0); + } + if (x.tok == Token.string || y.tok == Token.string) + return sValue(x).compareTo(sValue(y)); + } switch (x.tok) { case string: - return sValue(y).compareTo(sValue(x)); + return sValue(x).compareTo(sValue(y)); case varray: - if (x.objects.size() != y.objects.size()) - return 0; + ArrayList<ScriptVariable> sx = x.getList(); + ArrayList<ScriptVariable> sy = y.getList(); + if (sx.size() != sy.size()) + return (sx.size() < sy.size() ? -1 : 1); int iPt = arrayPt; if (iPt < 0) - iPt += x.objects.size(); - if (iPt < 0 || iPt >= x.objects.size()) + iPt += sx.size(); + if (iPt < 0 || iPt >= sx.size()) return 0; - return compare(x.objects.get(iPt), y.objects.get(iPt)); + return compare(sx.get(iPt), sy.get(iPt)); default: float fx = fValue(x); float fy = fValue(y); @@ -1161,27 +1187,25 @@ /** * - * @param arrayPt 1-based + * @param arrayPt 1-based or Integer.MIN_VALUE to reverse * @return sorted or reversed array */ public ScriptVariable sortOrReverse(int arrayPt) { - if (tok != varray) + ArrayList<ScriptVariable> x = getList(); + if (x == null || x.size() < 2) return this; - ScriptVariable x = new ScriptVariable(); - x.set(this, true); - if (x.objects.size() < 2) { - // just copy it - } else if (arrayPt == Integer.MIN_VALUE) { - int n = x.objects.size(); + if (arrayPt == Integer.MIN_VALUE) { + // reverse + int n = x.size(); for (int i = 0; i < n; i++) { - ScriptVariable v = x.objects.get(i); - x.objects.set(i, x.objects.get(--n)); - x.objects.set(n, v); + ScriptVariable v = x.get(i); + x.set(i, x.get(--n)); + x.set(n, v); } } else { - Collections.sort(x.objects, new Sort(--arrayPt)); + Collections.sort(getList(), new Sort(--arrayPt)); } - return x; + return this; } public boolean unEscapeBitSetArray(BitSet bs) { @@ -1199,27 +1223,34 @@ return false; } + public static BitSet unEscapeBitSetArray(ArrayList<ScriptVariable> x, boolean allowNull) { + BitSet bs = new BitSet(); + for (int i = 0; i < x.size(); i++) + if (!x.get(i).unEscapeBitSetArray(bs) && allowNull) + return null; + return bs; + } + public static String[] listValue(Token x) { - if (x.tok == varray) { - ScriptVariable sv = (ScriptVariable) x; - String[] list = new String[sv.objects.size()]; - for (int i = sv.objects.size(); --i >= 0;) - list[i] = sValue(sv.objects.get(i)); - return list; - } - return new String[] { sValue(x) }; + if (x.tok != varray) + return new String[] { sValue(x) }; + ArrayList<ScriptVariable> sv = ((ScriptVariable) x).getList(); + String[] list = new String[sv.size()]; + for (int i = sv.size(); --i >= 0;) + list[i] = sValue(sv.get(i)); + return list; } public static float[] flistValue(Token x, int nMin) { if (x.tok != varray) return new float[] { fValue(x) }; + ArrayList<ScriptVariable> sv = ((ScriptVariable) x).getList(); float[] list; - ScriptVariable sv = (ScriptVariable) x; - list = new float[Math.max(nMin, sv.objects.size())]; + list = new float[Math.max(nMin, sv.size())]; if (nMin == 0) nMin = list.length; - for (int i = Math.min(sv.objects.size(), nMin); --i >= 0;) - list[i] = fValue(sv.objects.get(i)); + for (int i = Math.min(sv.size(), nMin); --i >= 0;) + list[i] = fValue(sv.get(i)); return list; } @@ -1240,15 +1271,16 @@ return; } tok = varray; - objects = new ArrayList<ScriptVariable>(dim); + ArrayList<ScriptVariable> o2 = new ArrayList<ScriptVariable>(dim); for (int i = 0; i < dim; i++) { float[] a = new float[dim]; if (m3 == null) m4.getRow(i, a); else m3.getRow(i, a); - objects.set(i,getVariable(a)); - } + o2.set(i,getVariable(a)); + } + value = o2; } @SuppressWarnings("unchecked") @@ -1256,4 +1288,8 @@ return (tok == hash ? ((Map<String, ScriptVariable>) value).get(key) : null); } + @SuppressWarnings("unchecked") + public ArrayList<ScriptVariable> getList() { + return (tok == varray ? (ArrayList<ScriptVariable>) value : null); + } } Modified: trunk/Jmol/src/org/jmol/script/Token.java =================================================================== --- trunk/Jmol/src/org/jmol/script/Token.java 2011-01-23 01:19:30 UTC (rev 15019) +++ trunk/Jmol/src/org/jmol/script/Token.java 2011-01-23 01:20:13 UTC (rev 15020) @@ -468,7 +468,6 @@ final static int opLE = 2 | comparator | 9 << 4; final static int opLT = 3 | comparator | 9 << 4; public final static int opEQ = 4 | comparator | 9 << 4; - public final static int opEQEQ = 5 | comparator | 9 << 4; final static int opNE = 6 | comparator | 9 << 4; final static int minus = 0 | mathop | 10 << 4; @@ -1246,7 +1245,6 @@ final static Token tokenCoordinateEnd = tokenRightBrace; final static Token tokenColon = new Token(colon, ':'); final static Token tokenSet = new Token(set, '=', ""); - final static Token tokenSetEqEq = new Token(set, '#', ""); final static Token tokenSetArray = new Token(set, '[', ""); final static Token tokenSetProperty = new Token(set, '.', ""); final static Token tokenSetVar = new Token(set, '=', "var"); @@ -1414,7 +1412,7 @@ ">=", new Token(opGE), ">", new Token(opGT), "=", tokenEquals, - "==", new Token(opEQEQ), + "==", null, "!=", new Token(opNE), "<>", null, "within", new Token(within), @@ -1561,6 +1559,7 @@ "rama", null, "refresh", new Token(refresh), "reset", new Token(reset), + "unset", null, "restore", new Token(restore), "restrict", new Token(restrict), "return", new Token(returncmd), Modified: trunk/Jmol/src/org/jmol/shape/FontLineShapeRenderer.java =================================================================== --- trunk/Jmol/src/org/jmol/shape/FontLineShapeRenderer.java 2011-01-23 01:19:30 UTC (rev 15019) +++ trunk/Jmol/src/org/jmol/shape/FontLineShapeRenderer.java 2011-01-23 01:20:13 UTC (rev 15020) @@ -124,12 +124,13 @@ if (dx == 0) return; + /* boolean isOut = true; if (dx < 0) { isOut = false; dx = -dx; } - + */ if (g3d.isAntialiased()) length *= 2; // perpendicular to line on screen: @@ -189,8 +190,8 @@ //float ty = vectorT2.y * ((ptA.screenY + ptB.screenY) / 2 - pt2.y); //if (tx + ty < -0.1) //vectorT2.scale(-1); - if (!isOut) - vectorT2.scale(-1); + //if (!isOut) + //vectorT2.scale(-1); boolean horizontal = (Math.abs(vectorT2.x / vectorT2.y) < 0.2); boolean centerX = horizontal; boolean centerY = !horizontal; Modified: trunk/Jmol/src/org/jmol/shapesurface/Isosurface.java =================================================================== --- trunk/Jmol/src/org/jmol/shapesurface/Isosurface.java 2011-01-23 01:19:30 UTC (rev 15019) +++ trunk/Jmol/src/org/jmol/shapesurface/Isosurface.java 2011-01-23 01:20:13 UTC (rev 15020) @@ -1049,7 +1049,7 @@ //viewer.setPropertyColorScheme(schemeName, sg.getParams().colorSchemeTranslucent, false); thisMesh.isColorSolid = false; thisMesh.colorDensity = jvxlData.colorDensity; - thisMesh.colorEncoder = sg.getParams().colorEncoder; + thisMesh.colorEncoder = sg.getColorEncoder(); thisMesh.getContours(); if (thisMesh.jvxlData.jvxlPlane != null) allowContourLines = false; Modified: trunk/Jmol/src/org/jmol/util/Escape.java =================================================================== --- trunk/Jmol/src/org/jmol/util/Escape.java 2011-01-23 01:19:30 UTC (rev 15019) +++ trunk/Jmol/src/org/jmol/util/Escape.java 2011-01-23 01:20:13 UTC (rev 15020) @@ -470,38 +470,11 @@ } public static String escape(Matrix3f m3) { - StringBuilder sb = new StringBuilder(); - sb.append("[[").append(m3.m00).append(",") - .append(m3.m01).append(",") - .append(m3.m02).append("]") - .append(",[").append(m3.m10).append(",") - .append(m3.m11).append(",") - .append(m3.m12).append("]") - .append(",[").append(m3.m20).append(",") - .append(m3.m21).append(",") - .append(m3.m22).append("]]"); - return sb.toString(); + return m3.toString(); } public static String escape(Matrix4f m4) { - StringBuilder sb = new StringBuilder(); - sb.append("[[").append(m4.m00).append(",") - .append(m4.m01).append(",") - .append(m4.m02).append(",") - .append(m4.m03).append("]") - .append(",[").append(m4.m10).append(",") - .append(m4.m11).append(",") - .append(m4.m12).append(",") - .append(m4.m13).append("]") - .append(",[").append(m4.m20).append(",") - .append(m4.m21).append(",") - .append(m4.m22).append(",") - .append(m4.m23).append("]") - .append(",[").append(m4.m30).append(",") - .append(m4.m31).append(",") - .append(m4.m32).append(",") - .append(m4.m33).append("]]"); - return sb.toString(); + return (m4.toString()); } public static String escape(Map<String, Object> ht) { @@ -859,25 +832,4 @@ } return array; } - - @SuppressWarnings("unchecked") - public static BitSet unEscapeBitSetArray(Object o, boolean allowNull) { - BitSet bs = new BitSet(); - if (o instanceof ArrayList<?>) { - ArrayList<ScriptVariable> sv = (ArrayList<ScriptVariable>) o; - for (int i = 0; i < sv.size(); i++) - if (!sv.get(i).unEscapeBitSetArray(bs) && allowNull) - return null; - } else if (o instanceof String[]) { - String[] list = (String[]) o; - for (int i = 0; i < list.length; i++) { - BitSet bs1 = unescapeBitset(list[i]); - if (bs1 != null) - bs.or(bs1); - else if (allowNull) - return null; - } - } - return bs; - } } Modified: trunk/Jmol/src/org/jmol/viewer/ColorManager.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/ColorManager.java 2011-01-23 01:19:30 UTC (rev 15019) +++ trunk/Jmol/src/org/jmol/viewer/ColorManager.java 2011-01-23 01:20:13 UTC (rev 15020) @@ -142,7 +142,7 @@ case JmolConstants.PALETTE_NONE: case JmolConstants.PALETTE_CPK: // Note that CPK colors can be changed based upon user preference - // therefore, a changable colix is allocated in this case + // therefore, a changeable colix is allocated in this case id = atom.getAtomicAndIsotopeNumber(); if (id < Elements.elementNumberMax) return g3d.getChangeableColix(id, argbsCpk[id]); Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2011-01-23 01:19:30 UTC (rev 15019) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2011-01-23 01:20:13 UTC (rev 15020) @@ -3,8 +3,42 @@ version=12.1.32_dev -# code: ScriptVariable[]objects --> ArrayList<ScriptVariable>objects +# bug fix: If a script such as "test.spt" creates a function +# test(), then the next implicit script command "test.spt" will fail +# bug fix: implicit script command XXXX.xxx loses case of filename +# +# code: ScriptVariable simplified +# -- ScriptVariable[]objects --> (ArrayList<ScriptVariable>)value +# new feature: <array1> | x +# -- IN PLACE concatenation +# -- array1 will be appended to +# -- if x is an array of length n, then n elements will be added +# -- works as a |= b +# -- to append a full array as one element, use a |= [x] +# -- to append with creating a NEW array, use a + x or a + [x] instead +# bug fix: array appending appends string values + +# new feature: "unset" command same as "reset" +# -- for example: +# a = array([1,2,3],[4,5,6],[7,8,9]) +# y = a[3] +# unset a +# show variables +# y = [7,8,9]; +# -- just looks better for variables +# -- good to use this if just a small part of a large array +# or hashtable is wanted and the rest can be discarded +# new feature: sort/reverse does array sorting IN PLACE, not by copying +# -- for example: +# y = x.sort +# x is sorted, and y is a copy of that +# -- still need x = x.sort in general, because "x.sort" is not a command +# new feature: array assignment is always by reference, as for JavaScript and Java +# -- y = x[3], if x[3] = [3, 4, 5], assigns y to [3, 4, 5], so if later +# one uses y[4] = "new", then at that point x[3] = [3, 4, 5, "new"] +# -- y == x[3] distinction removed + # new feature: x = intersection(plane, plane) # new feature: x = intersection(pt, plane) (i.e. line perp to plane through pt) # new feature: x = intersection(ptLine, vLine, plane) @@ -44,7 +78,7 @@ # x = (a[1])[2]; if ((a[1])[2] == 3).... # because in general a[1][2] means "array a, elements 1 through 2" # -- for a matrix, you can use a[1][2] anywhere -- this is a difference between matrices and arrays -# new feature: y == x[3] (double "=" in context of assignment) +# new feature: y == x[3] (double "=" in context of assignment) (removed in 12.1.32) # -- y is now an alias for x[3], not a copy # -- allows, for example: # y = x[3]; y[2] = 6; This was sent by the SourceForge.net collaborative d... [truncated message content] |