Class ScriptEval

    • Field Detail

      • iProcess

        private static int iProcess
      • isJS

        public boolean isJS
      • scriptDelayThread

        private JmolThread scriptDelayThread
      • fileLoadThread

        private JmolThread fileLoadThread
      • allowJSThreads

        private boolean allowJSThreads
      • isFuncReturn

        private boolean isFuncReturn
      • historyDisabled

        public boolean historyDisabled
      • debugScript

        private boolean debugScript
      • isCmdLine_C_Option

        private boolean isCmdLine_C_Option
      • isCmdLine_c_or_C_Option

        private boolean isCmdLine_c_or_C_Option
      • listCommands

        private boolean listCommands
      • tQuiet

        public boolean tQuiet
      • executionStopped

        private boolean executionStopped
      • executionPaused

        private boolean executionPaused
      • executionStepping

        private boolean executionStepping
      • executing

        private boolean executing
      • timeBeginExecution

        private long timeBeginExecution
      • timeEndExecution

        private long timeEndExecution
      • mustResumeEval

        private boolean mustResumeEval
      • currentThread

        private java.lang.Thread currentThread
      • outputBuffer

        public javajs.util.SB outputBuffer
      • contextPath

        private java.lang.String contextPath
      • scriptFileName

        public java.lang.String scriptFileName
      • functionName

        public java.lang.String functionName
      • isStateScript

        public boolean isStateScript
      • scriptLevel

        public int scriptLevel
      • commandHistoryLevelMax

        public static int commandHistoryLevelMax
      • contextDepthMax

        private static int contextDepthMax
      • scriptReportingLevel

        private static int scriptReportingLevel
      • aatoken

        public T[][] aatoken
      • lineNumbers

        private short[] lineNumbers
      • lineIndices

        private int[][] lineIndices
      • script

        private java.lang.String script
      • scriptExtensions

        private java.lang.String scriptExtensions
      • pc

        public int pc
      • thisCommand

        public java.lang.String thisCommand
      • fullCommand

        public java.lang.String fullCommand
      • lineEnd

        private int lineEnd
      • pcEnd

        private int pcEnd
      • forceNoAddHydrogens

        private boolean forceNoAddHydrogens
      • pcResume

        public int pcResume
      • isEmbedded

        private boolean isEmbedded
    • Constructor Detail

      • ScriptEval

        public ScriptEval()
    • Method Detail

      • getAllowJSThreads

        public boolean getAllowJSThreads()
      • setAllowJSThreads

        public void setAllowJSThreads​(boolean b)
      • doReport

        public boolean doReport()
      • isStateScript

        public boolean isStateScript()
      • setStatic

        public int setStatic​(int tok,
                             int ival)
        set a static variable, with checking for range
      • getScript

        public java.lang.String getScript()
      • setCompiler

        public void setCompiler()
      • compileScriptString

        public boolean compileScriptString​(java.lang.String script,
                                           boolean tQuiet)
      • compileScriptFile

        public boolean compileScriptFile​(java.lang.String filename,
                                         boolean tQuiet)
      • evaluateCompiledScript

        public void evaluateCompiledScript​(boolean isCmdLine_c_or_C_Option,
                                           boolean isCmdLine_C_Option,
                                           boolean historyDisabled,
                                           boolean listCommands,
                                           javajs.util.SB outputBuffer,
                                           boolean allowThreads)
      • useThreads

        public boolean useThreads()
      • executeCommands

        private void executeCommands​(boolean isTry,
                                     boolean reportCompletion)
      • resumeEval

        public void resumeEval​(java.lang.Object sco)
        From dispatchCommands and JmolThread resumeEval. After throwing a ScriptInterruption, all statements following the current one are lost. When a JavaScript timeout returns from a DELAY, MOVE, MOVETO, or other sleep-requiring command, it is the ScriptContext that contains all have to worry about this, because the current thread is just put to sleep, not stopped, but in JavaScript, where we only have one thread, we need to manage this more carefully. We re-enter the halted script here, using a saved script context. The program counter is incremented to skip the initiating statement, and all parent contexts up the line are set with mustResumeEval = true.
        Parameters:
        sc -
      • resumeViewer

        private void resumeViewer​(java.lang.String why)
      • runScriptBuffer

        public void runScriptBuffer​(java.lang.String script,
                                    javajs.util.SB outputBuffer,
                                    boolean isFuncReturn)
                             throws ScriptException
        runs a script immediately and sends selected output to a provided SB
        Parameters:
        outputBuffer -
        script -
        Throws:
        ScriptException
      • checkScriptSilent

        public ScriptContext checkScriptSilent​(java.lang.String script)
        a method for just checking a script
        Parameters:
        script -
        Returns:
        a ScriptContext that indicates errors and provides a tokenized version of the script that has passed all syntax checking, both in the compiler and the evaluator
      • getContextTrace

        static javajs.util.SB getContextTrace​(Viewer vwr,
                                              ScriptContext sc,
                                              javajs.util.SB sb,
                                              boolean isTop)
      • setDebugging

        public void setDebugging()
      • haltExecution

        public void haltExecution()
      • pauseExecution

        public void pauseExecution​(boolean withDelay)
      • stepPausedExecution

        public void stepPausedExecution()
      • resumePausedExecution

        public void resumePausedExecution()
      • isExecuting

        public boolean isExecuting()
      • isPaused

        public boolean isPaused()
      • isStepping

        public boolean isStepping()
      • isStopped

        public boolean isStopped()
      • getNextStatement

        public java.lang.String getNextStatement()
        when paused, indicates what statement will be next
        Returns:
        a string indicating the statement
      • getCommand

        private java.lang.String getCommand​(int pc,
                                            boolean allThisLine,
                                            boolean addSemi)
        used for recall of commands in the application console
        Parameters:
        pc -
        allThisLine -
        addSemi -
        Returns:
        a string representation of the command
      • logDebugScript

        private void logDebugScript​(T[] st,
                                    int ifLevel)
      • evaluateExpression

        public java.lang.Object evaluateExpression​(java.lang.Object expr,
                                                   boolean asVariable,
                                                   boolean compileOnly)
        a general-use method to evaluate a "SET" type expression.
        Parameters:
        asVariable -
        expr -
        Returns:
        an object of one of the following types: Boolean, Integer, Float, String, Point3f, BitSet
      • runBufferedSafely

        public void runBufferedSafely​(java.lang.String script,
                                      javajs.util.SB outputBuffer)
      • runUserAction

        public static SV runUserAction​(java.lang.String functionName,
                                       java.lang.Object[] params,
                                       Viewer vwr)
      • evaluate

        private java.lang.Object evaluate​(java.lang.Object expr,
                                          boolean asVariable,
                                          boolean compileOnly)
      • checkSelect

        public boolean checkSelect​(java.util.Map<java.lang.String,​SV> h,
                                   T[] where)
        Check a map for a WHERE phrase
      • getAtomBitSet

        public javajs.util.BS getAtomBitSet​(java.lang.Object atomExpression)
        A general method to evaluate a string representing an atom set. Excepts one atom expression or one per line as "OR". Excepts "()" as "none".
        Parameters:
        atomExpression -
        Returns:
        is a bitset indicating the selected atoms
      • compileScript

        public boolean compileScript​(java.lang.String filename,
                                     java.lang.String strScript,
                                     boolean debugCompiler)
      • fixScriptPath

        private java.lang.String fixScriptPath​(java.lang.String strScript,
                                               java.lang.String filename)
      • setScriptExtensions

        private int setScriptExtensions()
      • compileScriptFileInternal

        private boolean compileScriptFileInternal​(java.lang.String filename,
                                                  java.lang.String localPath,
                                                  java.lang.String remotePath,
                                                  java.lang.String scriptPath)
      • evalFunctionFloat

        public float evalFunctionFloat​(java.lang.Object func,
                                       java.lang.Object params,
                                       float[] values)
      • breakAt

        private void breakAt​(int pt)
      • restoreFunction

        private void restoreFunction​(JmolScriptFunction f,
                                     javajs.util.Lst<SV> params,
                                     SV tokenAtom)
                              throws ScriptException
        note that functions requiring motion cannot be run in JavaScript
        Parameters:
        f -
        params -
        tokenAtom -
        Throws:
        ScriptException
      • clearDefinedVariableAtomSets

        public void clearDefinedVariableAtomSets()
      • defineSets

        private void defineSets()
        support for @xxx or define xxx commands
      • defineAtomSet

        private void defineAtomSet​(java.lang.String script)
      • deleteAtomsInVariables

        public void deleteAtomsInVariables​(javajs.util.BS bsDeleted)
      • clearState

        private void clearState​(boolean tQuiet)
      • pushContextDown

        public void pushContextDown​(java.lang.String why)
      • pushContext2

        private void pushContext2​(ContextToken token,
                                  java.lang.String why)
      • getScriptContext

        public ScriptContext getScriptContext​(java.lang.String why)
      • popContext

        void popContext​(boolean isFlowCommand,
                        boolean statementOnly)
      • restoreScriptContext

        public void restoreScriptContext​(ScriptContext context,
                                         boolean isPopContext,
                                         boolean isFlowCommand,
                                         boolean statementOnly)
      • setException

        public void setException​(ScriptException sx,
                                 java.lang.String msg,
                                 java.lang.String untranslated)
      • statementAsString

        public static java.lang.String statementAsString​(Viewer vwr,
                                                         T[] statement,
                                                         int iTok,
                                                         boolean doLogMessages)
      • setObjectPropSafe

        public java.lang.String setObjectPropSafe​(java.lang.String id,
                                                  int tokCommand)
        called by Viewer in setting up a PyMOL scene.
      • setAtomProp

        protected void setAtomProp​(java.lang.String prop,
                                   java.lang.Object value,
                                   javajs.util.BS bs)
      • restrictSelected

        public void restrictSelected​(boolean isBond,
                                     boolean doInvert)
      • showString

        public void showString​(java.lang.String str)
      • showStringPrint

        public void showStringPrint​(java.lang.String s,
                                    boolean mustDo)
        Specified by:
        showStringPrint in class ScriptError
      • report

        public void report​(java.lang.String s,
                           boolean isError)
      • appendBuffer

        private void appendBuffer​(java.lang.String str,
                                  boolean mustDo)
      • addProcess

        private void addProcess​(javajs.util.Lst<T[]> vProcess,
                                int pc,
                                int pt)
      • checkContinue

        private boolean checkContinue()
                               throws ScriptException
        checks to see if there is a pause condition, during which commands can still be issued, but with the ! first.
        Returns:
        false if there was a problem
        Throws:
        ScriptException
      • delayScript

        public void delayScript​(int millis)
      • isCommandDisplayable

        private boolean isCommandDisplayable​(int i)
        provides support for the script editor
        Parameters:
        i -
        Returns:
        true if displayable
      • loadFileResourceAsync

        public void loadFileResourceAsync​(java.lang.String fileName)
                                   throws ScriptException
        load a static file asynchronously
        Throws:
        ScriptException
      • loadFileAsync

        public java.lang.String loadFileAsync​(java.lang.String prefix,
                                              java.lang.String filename,
                                              int i,
                                              boolean doClear)
                                       throws ScriptException
        Allows asynchronous file loading from the LOAD or SCRIPT command. Saves the context, initiates a FileLoadThread instance. When the file loading completes, the file data (sans filename) is saved in the FileManager cache under cache://localLoad_xxxxx. Context is resumed at this command in the script, and the file is then retrieved from the cache. Only run from JSmol/HTML5 when vwr.isJS; Incompatibilities: LOAD and SCRIPT commands, load() function only; only one "?" per LOAD command
        Parameters:
        prefix -
        filename - or null if end of LOAD command and now just clearing out cache
        i -
        doClear - ensures only one file is in the cache for a given type
        Returns:
        cached file name if it exists
        Throws:
        ScriptException
      • logLoadInfo

        private void logLoadInfo​(java.lang.String msg)
      • notifyResumeStatus

        public void notifyResumeStatus()
      • stopScriptThreads

        public void stopScriptThreads()
      • getErrorLineMessage2

        public java.lang.String getErrorLineMessage2()
      • dispatchCommands

        public boolean dispatchCommands​(boolean isSpt,
                                        boolean fromFunc,
                                        boolean isTry)
                                 throws ScriptException
        Parameters:
        isSpt -
        fromFunc -
        isTry -
        Returns:
        false only when still working through resumeEval
        Throws:
        ScriptException
      • checkFileExists

        public java.lang.String checkFileExists​(java.lang.String prefix,
                                                boolean isAsync,
                                                java.lang.String filename,
                                                int i,
                                                boolean doClear)
                                         throws ScriptException
        Throws:
        ScriptException
      • addFilterAttribute

        private void addFilterAttribute​(java.util.Map<java.lang.String,​java.lang.Object> htParams,
                                        java.lang.String filter,
                                        java.lang.String key)
      • addLoadData

        private int addLoadData​(javajs.util.SB loadScript,
                                java.lang.String key,
                                java.util.Map<java.lang.String,​java.lang.Object> htParams,
                                int i)
                         throws ScriptException
        Throws:
        ScriptException
      • loadPNGJVar

        private void loadPNGJVar​(java.lang.String varName,
                                 java.lang.Object o,
                                 java.util.Map<java.lang.String,​java.lang.Object> htParams)
                          throws ScriptException
        Throws:
        ScriptException
      • getLoadFilesList

        private java.lang.String getLoadFilesList​(int i,
                                                  javajs.util.SB loadScript,
                                                  javajs.util.SB sOptions,
                                                  java.util.Map<java.lang.String,​java.lang.Object> htParams,
                                                  javajs.util.Lst<java.lang.String> fNames)
                                           throws ScriptException
        Throws:
        ScriptException
      • isLoadOption

        private boolean isLoadOption​(int tok)
      • getLoadModelIndex

        private int getLoadModelIndex​(int i,
                                      javajs.util.SB sOptions,
                                      java.util.Map<java.lang.String,​java.lang.Object> htParams)
                               throws ScriptException
        Throws:
        ScriptException
      • finalizeLoad

        private void finalizeLoad​(boolean isAppend,
                                  boolean appendNew,
                                  boolean isConcat,
                                  boolean doOrient,
                                  int nFiles,
                                  int ac0,
                                  int modelCount0)
                           throws ScriptException
        Throws:
        ScriptException
      • cmdModel

        private void cmdModel​(int offset)
                       throws ScriptException
        ONE difference between FRAME and MODEL: model 1 sets model NAMED one in the case of PDB frame 1 always sets the first model
        Parameters:
        offset - will be 2 for "anim frame ..."
        Throws:
        ScriptException
      • isAtomExpression

        public boolean isAtomExpression​(int i)
      • resetError

        private void resetError()
      • cmdScript

        public void cmdScript​(int tok,
                              java.lang.String filename,
                              java.lang.String theScript)
                       throws ScriptException
        Throws:
        ScriptException
      • saveContext

        private ScriptContext saveContext​(java.lang.String saveName)
      • setCurrentCagePts

        public void setCurrentCagePts​(javajs.util.T3[] originABC,
                                      java.lang.String name)
      • expandFloatArray

        public int[] expandFloatArray​(float[] a,
                                      int min)
                               throws ScriptException
        Accepts a float array and expands [1 -3] to [1 2 3], for example.
        Parameters:
        a -
        min -
        Returns:
        int array
        Throws:
        ScriptException
      • getObjectBoundingBox

        private javajs.util.P3[] getObjectBoundingBox​(java.lang.String id)
      • getObjectCenter

        protected javajs.util.P3 getObjectCenter​(java.lang.String axisID,
                                                 int index,
                                                 int modelIndex)
      • getPlaneForObject

        protected javajs.util.P4 getPlaneForObject​(java.lang.String id,
                                                   javajs.util.V3 vAB)
      • getQuaternionArray

        public javajs.util.Quat[] getQuaternionArray​(java.lang.Object quaternionOrSVData,
                                                     int itype)
      • getSettingStr

        private java.lang.String getSettingStr​(int pt,
                                               boolean isJmolSet)
                                        throws ScriptException
        Accept an unquoted string if there is just one parameter regardless of its type. In other words, these commands cannot accept a variable name by itself.
        Parameters:
        pt -
        isJmolSet -
        Returns:
        string parameter
        Throws:
        ScriptException
      • getShapeProperty

        public java.lang.Object getShapeProperty​(int shapeType,
                                                 java.lang.String propertyName)
      • getShapePropertyData

        public boolean getShapePropertyData​(int shapeType,
                                            java.lang.String propertyName,
                                            java.lang.Object[] data)
      • setElementColor

        private boolean setElementColor​(java.lang.String str,
                                        int argb)
      • setMeshDisplayProperty

        public boolean setMeshDisplayProperty​(int shape,
                                              int i,
                                              int tok)
                                       throws ScriptException
        Parameters:
        shape -
        i -
        tok -
        Returns:
        true if successful
        Throws:
        ScriptException
      • setObjectArgb

        private void setObjectArgb​(java.lang.String str,
                                   int argb)
      • setObjectMad10

        public void setObjectMad10​(int iShape,
                                   java.lang.String name,
                                   int mad10)
      • setObjectProp

        private java.lang.String setObjectProp​(java.lang.String id,
                                               int tokCommand,
                                               int ptColor)
                                        throws ScriptException
        Throws:
        ScriptException
      • setShapeProperty

        public void setShapeProperty​(int shapeType,
                                     java.lang.String propertyName,
                                     java.lang.Object propertyValue)
      • setShapePropertyBs

        public void setShapePropertyBs​(int iShape,
                                       java.lang.String propertyName,
                                       java.lang.Object propertyValue,
                                       javajs.util.BS bs)
      • setShapeSize

        private void setShapeSize​(int shapeType,
                                  RadiusData rd)
      • setShapeSizeBs

        public void setShapeSizeBs​(int shapeType,
                                   int size,
                                   javajs.util.BS bs)
      • setShapeTranslucency

        public void setShapeTranslucency​(int shapeType,
                                         java.lang.String prefix,
                                         java.lang.String translucency,
                                         float translucentLevel,
                                         javajs.util.BS bs)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object