From: <ha...@us...> - 2007-04-11 15:34:29
|
Revision: 7375 http://svn.sourceforge.net/jmol/?rev=7375&view=rev Author: hansonr Date: 2007-04-11 08:34:27 -0700 (Wed, 11 Apr 2007) Log Message: ----------- 11.1.28 -- sealed and delivered -- adds javascript() and script() functions and javascript command Modified Paths: -------------- trunk/Jmol/src/org/jmol/viewer/Eval.java trunk/Jmol/src/org/jmol/viewer/JmolConstants.java trunk/Jmol/src/org/jmol/viewer/Token.java trunk/Jmol/src/org/jmol/viewer/Viewer.java Modified: trunk/Jmol/src/org/jmol/viewer/Eval.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Eval.java 2007-04-11 02:35:47 UTC (rev 7374) +++ trunk/Jmol/src/org/jmol/viewer/Eval.java 2007-04-11 15:34:27 UTC (rev 7375) @@ -52,6 +52,7 @@ int lineEnd = Integer.MAX_VALUE; int iToken; int ifs[]; + StringBuffer outputBuffer; } class BondSet extends BitSet { @@ -107,6 +108,8 @@ boolean logMessages = false; boolean debugScript = false; boolean fileOpenCheck = true; + + StringBuffer outputBuffer; Eval(Viewer viewer) { compiler = new Compiler(viewer); @@ -205,7 +208,7 @@ } catch (ScriptException e) { error = true; setErrorMessage(e.toString()); - viewer.scriptStatus(errorMessage); + scriptStatus(errorMessage); } timeEndExecution = System.currentTimeMillis(); fileOpenCheck = tempOpen; @@ -245,6 +248,15 @@ popContext(); } + void runScript(String script, StringBuffer outputBuffer) throws ScriptException { + //a = script("xxxx") + pushContext(); + this.outputBuffer = outputBuffer; + if (loadScript(null, script)) + instructionDispatchLoop(false); + popContext(); + } + void pushContext() throws ScriptException { if (scriptLevel == scriptLevelMax) evalError(GT._("too many script levels")); @@ -261,6 +273,7 @@ context.pcEnd = pcEnd; context.iToken = iToken; context.ifs = ifs; + context.outputBuffer = outputBuffer; stack[scriptLevel++] = context; if (isScriptCheck) Logger.info("-->>-------------".substring(0, scriptLevel + 5) + filename); @@ -285,6 +298,7 @@ pcEnd = context.pcEnd; iToken = context.iToken; ifs = context.ifs; + outputBuffer = context.outputBuffer; } boolean loadScript(String filename, String script) { @@ -585,7 +599,7 @@ } pc++; if (error) - viewer.scriptStatus(errorMessage); + scriptStatus(errorMessage); pauseExecution(); } } @@ -803,7 +817,8 @@ rotate(false, false); break; case Token.script: - script(); + case Token.javascript: + script(token.tok == Token.javascript); break; case Token.history: history(1); @@ -2989,7 +3004,7 @@ operation, atomSets[0], atomSets[1], bsBonds, isBonds); if (isDelete) { if (!(tQuiet || scriptLevel > scriptReportingLevel)) - viewer.scriptStatus(GT._("{0} connections deleted", n)); + scriptStatus(GT._("{0} connections deleted", n)); return; } if (isColorOrRadius) { @@ -3011,7 +3026,7 @@ viewer.selectBonds(null); } if (!(tQuiet || scriptLevel > scriptReportingLevel)) - viewer.scriptStatus(GT._("{0} connections modified or created", n)); + scriptStatus(GT._("{0} connections modified or created", n)); } void getProperty() throws ScriptException { @@ -3430,11 +3445,20 @@ if (isSyntaxCheck) return; String s = viewer.formatText(text); - Logger.warn(s); + if (outputBuffer == null) + Logger.warn(s); if (!s.startsWith("_")) - viewer.scriptStatus(s); + scriptStatus(s); } + void scriptStatus(String s) { + if (outputBuffer != null) { + outputBuffer.append(s); + return; + } + viewer.scriptStatus(s); + } + void pause() throws ScriptException { pauseExecution(); String msg = optParameterAsString(1); @@ -3598,7 +3622,7 @@ if (errMsg != null && !isScriptCheck) evalError(errMsg); if (logMessages) - viewer.scriptStatus("Successfully loaded:" + filename); + scriptStatus("Successfully loaded:" + filename); String defaultScript = viewer.getDefaultLoadScript(); String msg = ""; if (defaultScript.length() > 0) @@ -4077,8 +4101,13 @@ "getSpinAxis:" + axisID); } - void script() throws ScriptException { + void script(boolean isJavaScript) throws ScriptException { // token allows for only 1 or 2 parameters + if (isJavaScript) { + if (!isSyntaxCheck) + viewer.eval(parameterAsString(1)); + return; + } if (getToken(1).tok != Token.string) filenameExpected(); int lineNumber = 0; @@ -4724,7 +4753,7 @@ if (isSyntaxCheck) return; int n = viewer.autoHbond(null); - viewer.scriptStatus(GT._("{0} hydrogen bonds", n)); + scriptStatus(GT._("{0} hydrogen bonds", n)); return; } setShapeSize(JmolConstants.SHAPE_HSTICKS, getMadParameter()); @@ -6922,7 +6951,7 @@ height = viewer.getScreenHeight(); } viewer.createImage(fileName, data, quality, width, height); - viewer.scriptStatus("type=" + type + "; file=" + scriptStatus("type=" + type + "; file=" + (fileName == null ? "CLIPBOARD" : fileName) + (len >= 0 ? "; length=" + len : "") + (isImage ? "; width=" + width + "; height=" + height : "")); @@ -7187,7 +7216,10 @@ void showString(String str) { if (isSyntaxCheck) return; - viewer.showString(str); + if (outputBuffer != null) + outputBuffer.append(str); + else + viewer.showString(str); } String getIsosurfaceJvxl() { @@ -9197,6 +9229,9 @@ return evaluateData(args); case Token.load: return evaluateLoad(args); + case Token.script: + case Token.javascript: + return evaluateScript(args, tok == Token.javascript); case Token.within: return evaluateWithin(args); case Token.distance: @@ -9394,6 +9429,21 @@ return addX(viewer.getFileAsString(Token.sValue(args[0]))); } + boolean evaluateScript(Token[] args, boolean isJavaScript) + throws ScriptException { + //System.out.println("eval load"); + if (args.length != 1) + return false; + if (isSyntaxCheck) + return addX(""); + String s = Token.sValue(args[0]); + if (isJavaScript) + return addX(viewer.eval(s)); + StringBuffer sb = new StringBuffer(); + runScript(s, sb); + return addX(sb.toString()); + } + boolean evaluateData(Token[] args) throws ScriptException { //System.out.println("eval data"); if (args.length == 0 || args.length > 2) Modified: trunk/Jmol/src/org/jmol/viewer/JmolConstants.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/JmolConstants.java 2007-04-11 02:35:47 UTC (rev 7374) +++ trunk/Jmol/src/org/jmol/viewer/JmolConstants.java 2007-04-11 15:34:27 UTC (rev 7375) @@ -41,6 +41,13 @@ * 11.1.28 + adds + + a = script("some script command") + a = javascript("some javascript") + + putting output into a from commands such as "show" or "getProperty", for instance. + reinstates tempManager properly. adds support for CAChe CSF files with MOPAC (AM1, PM3, etc.), Modified: trunk/Jmol/src/org/jmol/viewer/Token.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Token.java 2007-04-11 02:35:47 UTC (rev 7374) +++ trunk/Jmol/src/org/jmol/viewer/Token.java 2007-04-11 15:34:27 UTC (rev 7375) @@ -84,7 +84,7 @@ final static int command = (1 << 8); final static int expressionCommand = (1 << 9); // expression command final static int embeddedExpression= (1 << 10); // embedded expression - final static int specialstring = (1 << 11); // echo, label + final static int specialstring = (1 << 11); // echo, label, javascript //generally, the minus sign is used to denote atom ranges // this property is used for the commands which allow negative integers final static int negnums = (1 << 12); @@ -140,7 +140,7 @@ final static int ribbon = command | 26; final static int rotate = command | 27 | coordOrSet; final static int save = command | 28; - final static int script = command | 29; +// final static int script = command | 29; with mathfunc final static int select = command | 30 | expressionCommand; final static int set = command | 31 | negnums | embeddedExpression | colorparam; final static int show = command | 32; @@ -330,6 +330,8 @@ final static int find = 2 | mathfunc | mathproperty | 1 << 3; final static int load = 3 | mathfunc | 1 << 3 | command | negnums; final static int substructure = 4 | mathfunc | 1 << 3; + final static int script = 5 | mathfunc | 1 << 3 | command; + final static int javascript = 6 | mathfunc | 1 << 3 | command | specialstring; final static int distance = 1 | mathfunc | mathproperty | 2 << 3; final static int data = 2 | mathfunc | 2 << 3 | command; @@ -775,6 +777,7 @@ "save", new Token(save, maxArg3), "script", new Token(script, varArgCount), "source", null, + "javascript", new Token(javascript, 1), "select", new Token(select, varArgCount), "set", new Token(set, varArgCount), "show", new Token(show, maxArg2), Modified: trunk/Jmol/src/org/jmol/viewer/Viewer.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Viewer.java 2007-04-11 02:35:47 UTC (rev 7374) +++ trunk/Jmol/src/org/jmol/viewer/Viewer.java 2007-04-11 15:34:27 UTC (rev 7375) @@ -1562,7 +1562,7 @@ bMax = runtime.maxMemory(); } catch (Exception e) { } - Logger.error("ZAP memory inuse, total, free, max: " + (bTotal - bFree) + Logger.debug("ZAP memory inuse, total, free, max: " + (bTotal - bFree) + " " + bTotal + " " + bFree + " " + bMax); if (notify) setStatusFileLoaded(0, null, null, null, null, null); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |