From: <ha...@us...> - 2009-08-30 19:46:22
|
Revision: 11407 http://jmol.svn.sourceforge.net/jmol/?rev=11407&view=rev Author: hansonr Date: 2009-08-30 19:46:09 +0000 (Sun, 30 Aug 2009) Log Message: ----------- version=11.9.2_dev # new feature: getProperty command allows "xxx.yyy.zzz[3]" notation, in quotes: # getProperty "auxiliaryInfo.models[1].symmetryOperations" Modified Paths: -------------- trunk/Jmol/src/org/jmol/viewer/Jmol.properties trunk/Jmol/src/org/jmol/viewer/PropertyManager.java trunk/Jmol/src/org/jmol/viewer/ScriptEvaluator.java trunk/Jmol/src/org/jmol/viewer/ScriptMathProcessor.java trunk/Jmol/src/org/jmol/viewer/ScriptVariable.java Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2009-08-30 17:16:50 UTC (rev 11406) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2009-08-30 19:46:09 UTC (rev 11407) @@ -3,6 +3,8 @@ version=11.9.2_dev +# new feature: getProperty command allows "xxx.yyy.zzz[3]" notation, in quotes: +# getProperty "auxiliaryInfo.models[1].symmetryOperations" # bug fix: animation direction -1 not functional # bug fix: script lines 1-3 not functional Modified: trunk/Jmol/src/org/jmol/viewer/PropertyManager.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/PropertyManager.java 2009-08-30 17:16:50 UTC (rev 11406) +++ trunk/Jmol/src/org/jmol/viewer/PropertyManager.java 2009-08-30 19:46:09 UTC (rev 11407) @@ -31,6 +31,7 @@ import org.jmol.util.Escape; import org.jmol.util.Logger; +import org.jmol.util.Parser; import org.jmol.util.TextFormat; /** @@ -153,7 +154,12 @@ static Object getProperty(Viewer viewer, String returnType, String infoType, Object paramInfo) { if (propertyTypes.length != PROP_COUNT * 3) Logger.warn("propertyTypes is not the right length: " + propertyTypes.length + " != " + PROP_COUNT * 3); - Object info = getPropertyAsObject(viewer, infoType, paramInfo, returnType); + Object info; + if (infoType.indexOf(".") >= 0) { + info = getModelProperty(viewer, infoType, paramInfo); + } else { + info = getPropertyAsObject(viewer, infoType, paramInfo, returnType); + } if (returnType == null) return info; boolean requestedReadable = returnType.equalsIgnoreCase("readable"); @@ -167,6 +173,23 @@ return info; } + static Object getModelProperty(Viewer viewer, String propertyName, Object propertyValue) { + propertyName = propertyName.replace(']', ' ').replace('[', ' ').replace( + '.', ' '); + propertyName = TextFormat.simpleReplace(propertyName, " ", " "); + String[] names = TextFormat.split(TextFormat.trim(propertyName, " "), " "); + ScriptVariable[] args = new ScriptVariable[names.length]; + propertyName = names[0]; + int n; + for (int i = 1; i < names.length; i++) { + if ((n = Parser.parseInt(names[i])) != Integer.MIN_VALUE) + args[i] = new ScriptVariable(Token.integer, n); + else + args[i] = new ScriptVariable(Token.string, names[i]); + } + return extractProperty(getProperty(viewer, null, propertyName, propertyValue), args, 1); + } + static Object extractProperty(Object property, ScriptVariable[] args, int ptr) { if (ptr >= args.length) return property; Modified: trunk/Jmol/src/org/jmol/viewer/ScriptEvaluator.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/ScriptEvaluator.java 2009-08-30 17:16:50 UTC (rev 11406) +++ trunk/Jmol/src/org/jmol/viewer/ScriptEvaluator.java 2009-08-30 19:46:09 UTC (rev 11407) @@ -5548,12 +5548,16 @@ return; String retValue = ""; String property = optParameterAsString(1); + String name = property; + if (name.indexOf(".") >= 0) + name = name.substring(0, name.indexOf(".")); + int propertyID = PropertyManager.getPropertyNumber(name); String param = optParameterAsString(2); int tok = tokAt(2); BitSet bs = (tok == Token.expressionBegin || tok == Token.bitset ? expression(2) : null); - int propertyID = PropertyManager.getPropertyNumber(property); if (property.length() > 0 && propertyID < 0) { + // no such property property = ""; // produces a list from Property Manager param = ""; } else if (propertyID >= 0 && statementLength < 3) { @@ -5567,7 +5571,7 @@ param += parameterAsString(i); } retValue = (String) viewer.getProperty("readable", property, - (bs == null ? (Object) param : (Object) bs)); + (bs == null ? (Object) param : (Object) bs)); showString(retValue); } Modified: trunk/Jmol/src/org/jmol/viewer/ScriptMathProcessor.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/ScriptMathProcessor.java 2009-08-30 17:16:50 UTC (rev 11406) +++ trunk/Jmol/src/org/jmol/viewer/ScriptMathProcessor.java 2009-08-30 19:46:09 UTC (rev 11407) @@ -969,53 +969,11 @@ && PropertyManager.acceptsStringParameter(propertyName) ? args[pt++].value : (Object) ""); } - if (args.length == pt && propertyName.indexOf(".") >= 0 - || propertyName.indexOf("[") >= 0) { - propertyName = propertyName.replace(']', ' ').replace('[', ' ').replace( - '.', ' '); - propertyName = TextFormat.simpleReplace(propertyName, " ", " "); - String[] names = TextFormat - .split(TextFormat.trim(propertyName, " "), " "); - if (names.length > 0) { - args = new ScriptVariable[names.length]; - propertyName = names[0]; - int n; - for (int i = 1; i < names.length; i++) { - if ((n = Parser.parseInt(names[i])) != Integer.MIN_VALUE) - args[i] = new ScriptVariable(Token.integer, n); - else - args[i] = new ScriptVariable(Token.string, names[i]); - } - pt = 1; - } - } Object property = viewer.getProperty(null, propertyName, propertyValue); if (pt < args.length) property = PropertyManager.extractProperty(property, args, pt); - if (property instanceof String) - return addX(property); - if (property instanceof Integer) - return addX(property); - if (property instanceof Float) - return addX(property); - if (property instanceof Point3f) - return addX(property); - if (property instanceof Vector3f) - return addX(new Point3f((Vector3f) property)); - if (property instanceof Vector) { - Vector v = (Vector) property; - int len = v.size(); - String[] list = new String[len]; - for (int i = 0; i < len; i++) { - Object o = v.elementAt(i); - if (o instanceof String) - list[i] = (String) o; - else - list[i] = Escape.toReadable(o); - } - return addX(list); - } - return addX(Escape.toReadable(property)); + return addX(ScriptVariable.isVariableType(property) ? property : Escape + .toReadable(property)); } private boolean evaluatePoint(ScriptVariable[] args) { Modified: trunk/Jmol/src/org/jmol/viewer/ScriptVariable.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/ScriptVariable.java 2009-08-30 17:16:50 UTC (rev 11406) +++ trunk/Jmol/src/org/jmol/viewer/ScriptVariable.java 2009-08-30 19:46:09 UTC (rev 11407) @@ -25,6 +25,7 @@ package org.jmol.viewer; import java.util.BitSet; +import java.util.Vector; import javax.vecmath.Point3f; import javax.vecmath.Point4f; @@ -109,6 +110,13 @@ return new ScriptVariable(integer, ((Integer) x).intValue()); if (x instanceof Float) return new ScriptVariable(decimal, x); + if (x instanceof int[]) { + int[] ix = (int[]) x; + String[] s = new String[ix.length]; + for (int i = ix.length; --i >= 0; ) + s[i] = "" + ix[i]; + return new ScriptVariable(list, s); + } if (x instanceof float[]) { float[] f = (float[]) x; String[] s = new String[f.length]; @@ -139,9 +147,41 @@ return new ScriptVariable(bitset, x); if (x instanceof Quaternion) return new ScriptVariable(point4f, ((Quaternion)x).toPoint4f()); + if (x instanceof Vector) { + Vector v = (Vector) x; + int len = v.size(); + String[] list = new String[len]; + for (int i = 0; i < len; i++) { + Object o = v.elementAt(i); + if (o instanceof String) + list[i] = (String) o; + else + list[i] = Escape.toReadable(o); + } + return getVariable(list); + } return null; } + static boolean isVariableType(Object x) { + return (x instanceof ScriptVariable + || x instanceof BitSet + || x instanceof Boolean + || x instanceof Float + || x instanceof Integer + || x instanceof Point3f + || x instanceof Point4f + || x instanceof Quaternion + || x instanceof String + || x instanceof Vector + || x instanceof Vector3f + || x instanceof double[] + || x instanceof float[] + || x instanceof Float[] + || x instanceof int[] + || x instanceof String[]); + } + ScriptVariable set(ScriptVariable v) { index = v.index; intValue = v.intValue; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |