--- trunk/src/selection/SelectionEvaluator.cpp 2005/02/01 22:49:23 278 +++ trunk/src/selection/SelectionEvaluator.cpp 2005/02/03 14:04:59 282 @@ -61,15 +61,15 @@ void SelectionEvaluator::clearState() { void SelectionEvaluator::clearState() { for (int i = scriptLevelMax; --i >= 0; ) - stack[i] = null; + stack[i].clear(); scriptLevel = 0; error = false; - errorMessage = null; + errorMessage = ""; } bool SelectionEvaluator::loadScriptString(const std::string& script) { clearState(); - return loadScript(null, script); + return loadScript("", script); } bool SelectionEvaluator::loadScriptFile(const std::string& filename) { @@ -77,18 +77,21 @@ bool SelectionEvaluator::loadScriptFile(const std::str return loadScriptFileInternal(filename); } +bool SelectionEvaluator::loadScriptFileInternal(const string & filename) { +} + void SelectionEvaluator::instructionDispatchLoop(){ - while ( pc < aatoken.length) { + while ( pc < aatoken.size()) { statement = aatoken[pc++]; - statementLength = statement.length; + statementLength = statement.size(); Token token = statement[0]; switch (token.tok) { - case Token.define: + case Token::define: define(); break; - case Token.select: + case Token::select: select(); break; default: @@ -98,36 +101,7 @@ void SelectionEvaluator::instructionDispatchLoop(){ } } - void SelectionEvaluator::predefine(String script) { - if (compiler.compile("#predefine", script)) { - Token [][] aatoken = compiler.getAatokenCompiled(); - if (aatoken.length != 1) { - viewer.scriptStatus("predefinition does not have exactly 1 command:" - + script); - return; - } - Token[] statement = aatoken[0]; - if (statement.length > 2) { - int tok = statement[1].tok; - if (tok == Token.identifier || - (tok & Token.predefinedset) == Token.predefinedset) { - String variable = (String)statement[1].value; - variables.put(variable, statement); - } else { - viewer.scriptStatus("invalid variable name:" + script); - } - } else { - viewer.scriptStatus("bad predefinition length:" + script); - } - } else { - viewer.scriptStatus("predefined set compile error:" + script + - "\ncompile error:" + compiler.getErrorMessage()); - } - } - - - - BitSet SelectionEvaluator::expression(Token[] code, int pcStart) throws ScriptException { + BitSet SelectionEvaluator::expression(std::vector& code, int pcStart) { int numberOfAtoms = viewer.getAtomCount(); BitSet bs; BitSet[] stack = new BitSet[10]; @@ -135,56 +109,60 @@ void SelectionEvaluator::instructionDispatchLoop(){ for (int pc = pcStart; ; ++pc) { Token instruction = code[pc]; - if (logMessages) - viewer.scriptStatus("instruction=" + instruction); + switch (instruction.tok) { - case Token.expressionBegin: + case Token::expressionBegin: break; - case Token.expressionEnd: - break expression_loop; - case Token.all: + case Token::expressionEnd: + break; + case Token::all: bs = stack[sp++] = new BitSet(numberOfAtoms); for (int i = numberOfAtoms; --i >= 0; ) bs.set(i); break; - case Token.none: + case Token::none: stack[sp++] = new BitSet(); break; - case Token.opOr: + case Token::opOr: bs = stack[--sp]; stack[sp-1].or(bs); break; - case Token.opAnd: + case Token::opAnd: bs = stack[--sp]; stack[sp-1].and(bs); break; - case Token.opNot: + case Token::opNot: bs = stack[sp - 1]; notSet(bs); break; - case Token.within: + case Token::within: bs = stack[sp - 1]; stack[sp - 1] = new BitSet(); withinInstruction(instruction, bs, stack[sp - 1]); break; - case Token.selected: + case Token::selected: stack[sp++] = copyBitSet(viewer.getSelectionSet()); break; - case Token.y: - case Token.amino: - case Token.backbone: - case Token.solvent: - case Token.identifier: - case Token.sidechain: - case Token.surface: - stack[sp++] = lookupIdentifierValue((String)instruction.value); + case Token::name: + break; - case Token.opLT: - case Token.opLE: - case Token.opGE: - case Token.opGT: - case Token.opEQ: - case Token.opNE: + case Token::index: + + break; + case Token::molname: + + break; + case Token::molindex: + break; + case Token::identifier: + stack[sp++] = lookupIdentifierValue((std::string)instruction.value); + break; + case Token::opLT: + case Token::opLE: + case Token::opGE: + case Token::opGT: + case Token::opEQ: + case Token::opNE: bs = stack[sp++] = new BitSet(); comparatorInstruction(instruction, bs); break; @@ -209,58 +187,36 @@ void SelectionEvaluator::instructionDispatchLoop(){ for (int i = 0; i < numberOfAtoms; ++i) { Atom atom = frame.getAtomAt(i); switch (property) { - case Token.atomno: - propertyValue = atom.getAtomNumber(); + case Token::mass: + //propertyValue = atom.getAtomNumber(); break; - case Token.elemno: - propertyValue = atom.getElementNumber(); + case Token::charge: + break; - case Token.temperature: - propertyValue = atom.getBfactor100(); - if (propertyValue < 0) - continue; - propertyValue /= 100; + case Token::dipole: + break; - case Token._atomID: - propertyValue = atom.getSpecialAtomID(); - if (propertyValue < 0) - continue; - break; - case Token._structure: - propertyValue = getProteinStructureType(atom); - if (propertyValue == -1) - continue; - break; - case Token.radius: - propertyValue = atom.getRasMolRadius(); - break; - case Token._bondedcount: - propertyValue = atom.getCovalentBondCount(); - break; - case Token.model: - propertyValue = atom.getModelTagNumber(); - break; default: unrecognizedAtomProperty(property); } - boolean match = false; + bool match = false; switch (comparator) { - case Token.opLT: + case Token::opLT: match = propertyValue < comparisonValue; break; - case Token.opLE: + case Token::opLE: match = propertyValue <= comparisonValue; break; - case Token.opGE: + case Token::opGE: match = propertyValue >= comparisonValue; break; - case Token.opGT: + case Token::opGT: match = propertyValue > comparisonValue; break; - case Token.opEQ: + case Token::opEQ: match = propertyValue == comparisonValue; break; - case Token.opNE: + case Token::opNE: match = propertyValue != comparisonValue; break; } @@ -269,17 +225,18 @@ void SelectionEvaluator::instructionDispatchLoop(){ } } -void SelectionEvaluator::withinInstruction(Token instruction, BitSet bs, BitSet bsResult) +void SelectionEvaluator::withinInstruction(const Token& instruction, BitSet& bs, BitSet& bsResult) - Object withinSpec = instruction.value; - if (withinSpec instanceof Float) { - withinDistance(((Float)withinSpec).floatValue(), bs, bsResult); + boost::any withinSpec = instruction.value; + if (withinSpec.type() == typeid(float)){ + withinDistance(boost::any_cast(withinSpec), bs, bsResult); return; } + evalError("Unrecognized within parameter:" + withinSpec); } - void SelectionEvaluator::withinDistance(float distance, BitSet bs, BitSet bsResult) { + void SelectionEvaluator::withinDistance(float distance, const BitSet& bs, const BitSet& bsResult) { Frame frame = viewer.getFrame(); for (int i = frame.getAtomCount(); --i >= 0; ) { if (bs.get(i)) { @@ -292,29 +249,65 @@ void SelectionEvaluator::withinInstruction(Token instr } } - void SelectionEvaluator::define() throws ScriptException { - String variable = (String)statement[1].value; - variables.put(variable, (expression(statement, 2))); + void SelectionEvaluator::define() { + assert(statement.size() >= 3); + + std::string variable = boost::any_cast(statement[1].value); + + variables.insert(std::make_pair(variable, expression(statement, 2))); } } - void SelectionEvaluator::predefine(Token[] statement) { - String variable = (String)statement[1].value; - variables.put(variable, statement); - } +/** @todo */ +void SelectionEvaluator::predefine(const std::string& script) { - void SelectionEvaluator::select(){ - // NOTE this is called by restrict() - if (statementLength == 1) { - viewer.selectAll(); - if (!viewer.getRasmolHydrogenSetting()) - viewer.excludeSelectionSet(getHydrogenSet()); - if (!viewer.getRasmolHeteroSetting()) - viewer.excludeSelectionSet(getHeteroSet()); + if (compiler.compile("#predefine", script)) { + std::vector > aatoken = compiler.getAatokenCompiled(); + if (aatoken.size() != 1) { + evalError("predefinition does not have exactly 1 command:" + + script); + return; + } + std::vector statement = aatoken[0]; + if (statement.size() > 2) { + int tok = statement[1].tok; + if (tok == Token::identifier || (tok & Token::predefinedset) == Token::predefinedset) { + std::string variable = (std::string)statement[1].value; + variables.insert(std::make_pair(variable, statement)); + + } else { + evalError("invalid variable name:" + script); + } + }else { + evalError("bad predefinition length:" + script); + } + + } else { - viewer.setSelectionSet(expression(statement, 1)); + evalError("predefined set compile error:" + script + + "\ncompile error:" + compiler.getErrorMessage()); } - viewer.scriptStatus("" + viewer.getSelectionCount() + " atoms selected"); - } - - } \ No newline at end of file + +} + +void SelectionEvaluator::select(){ + viewer.setSelectionSet(expression(statement, 1)); +} + +BitSet SelectionEvaluator::lookupValue(const std::string& variable){ + + std::map::iterator i = variables.find(variable); + + if (i != variables.end()) { + if (i->second.type() == typeid(BitSet)) { + return boost::any_cast(i->second); + } else if (i->second.type() == typeid(std::vector)){ + BitSet bs = expression(boost::any_cast(i->second), 2); + i->second = bs; /**@todo fixme */ + return bs; + } + } + +} + +}