61 |
|
|
62 |
|
void SelectionEvaluator::clearState() { |
63 |
|
for (int i = scriptLevelMax; --i >= 0; ) |
64 |
< |
stack[i] = null; |
64 |
> |
stack[i].clear(); |
65 |
|
scriptLevel = 0; |
66 |
|
error = false; |
67 |
< |
errorMessage = null; |
67 |
> |
errorMessage = ""; |
68 |
|
} |
69 |
|
|
70 |
|
bool SelectionEvaluator::loadScriptString(const std::string& script) { |
71 |
|
clearState(); |
72 |
< |
return loadScript(null, script); |
72 |
> |
return loadScript("", script); |
73 |
|
} |
74 |
|
|
75 |
|
bool SelectionEvaluator::loadScriptFile(const std::string& filename) { |
80 |
|
|
81 |
|
void SelectionEvaluator::instructionDispatchLoop(){ |
82 |
|
|
83 |
< |
while ( pc < aatoken.length) { |
83 |
> |
while ( pc < aatoken.size()) { |
84 |
|
statement = aatoken[pc++]; |
85 |
< |
statementLength = statement.length; |
85 |
> |
statementLength = statement.size(); |
86 |
|
Token token = statement[0]; |
87 |
|
switch (token.tok) { |
88 |
< |
case Token.define: |
88 |
> |
case Token::define: |
89 |
|
define(); |
90 |
|
break; |
91 |
< |
case Token.select: |
91 |
> |
case Token::select: |
92 |
|
select(); |
93 |
|
break; |
94 |
|
default: |
98 |
|
} |
99 |
|
} |
100 |
|
|
101 |
< |
void SelectionEvaluator::predefine(String script) { |
101 |
> |
void SelectionEvaluator::predefine(const std::string& script) { |
102 |
|
if (compiler.compile("#predefine", script)) { |
103 |
< |
Token [][] aatoken = compiler.getAatokenCompiled(); |
104 |
< |
if (aatoken.length != 1) { |
103 |
> |
std::vector<std::vector<Token> > aatoken = compiler.getAatokenCompiled(); |
104 |
> |
if (aatoken.size() != 1) { |
105 |
|
viewer.scriptStatus("predefinition does not have exactly 1 command:" |
106 |
|
+ script); |
107 |
|
return; |
108 |
|
} |
109 |
< |
Token[] statement = aatoken[0]; |
110 |
< |
if (statement.length > 2) { |
109 |
> |
|
110 |
> |
std::vector<Token> statement = aatoken[0]; |
111 |
> |
|
112 |
> |
if (statement.size() > 2) { |
113 |
|
int tok = statement[1].tok; |
114 |
< |
if (tok == Token.identifier || |
115 |
< |
(tok & Token.predefinedset) == Token.predefinedset) { |
116 |
< |
String variable = (String)statement[1].value; |
114 |
> |
if (tok == Token::identifier || |
115 |
> |
(tok & Token::predefinedset) == Token::predefinedset) { |
116 |
> |
std::string variable = (std::string)statement[1].value; |
117 |
|
variables.put(variable, statement); |
118 |
|
} else { |
119 |
|
viewer.scriptStatus("invalid variable name:" + script); |
129 |
|
|
130 |
|
|
131 |
|
|
132 |
< |
BitSet SelectionEvaluator::expression(Token[] code, int pcStart) throws ScriptException { |
132 |
> |
BitSet SelectionEvaluator::expression(std::vector<Token>& code, int pcStart) { |
133 |
|
int numberOfAtoms = viewer.getAtomCount(); |
134 |
|
BitSet bs; |
135 |
|
BitSet[] stack = new BitSet[10]; |
140 |
|
if (logMessages) |
141 |
|
viewer.scriptStatus("instruction=" + instruction); |
142 |
|
switch (instruction.tok) { |
143 |
< |
case Token.expressionBegin: |
143 |
> |
case Token::expressionBegin: |
144 |
|
break; |
145 |
< |
case Token.expressionEnd: |
145 |
> |
case Token::expressionEnd: |
146 |
|
break expression_loop; |
147 |
< |
case Token.all: |
147 |
> |
case Token::all: |
148 |
|
bs = stack[sp++] = new BitSet(numberOfAtoms); |
149 |
|
for (int i = numberOfAtoms; --i >= 0; ) |
150 |
|
bs.set(i); |
151 |
|
break; |
152 |
< |
case Token.none: |
152 |
> |
case Token::none: |
153 |
|
stack[sp++] = new BitSet(); |
154 |
|
break; |
155 |
< |
case Token.opOr: |
155 |
> |
case Token::opOr: |
156 |
|
bs = stack[--sp]; |
157 |
|
stack[sp-1].or(bs); |
158 |
|
break; |
159 |
< |
case Token.opAnd: |
159 |
> |
case Token::opAnd: |
160 |
|
bs = stack[--sp]; |
161 |
|
stack[sp-1].and(bs); |
162 |
|
break; |
163 |
< |
case Token.opNot: |
163 |
> |
case Token::opNot: |
164 |
|
bs = stack[sp - 1]; |
165 |
|
notSet(bs); |
166 |
|
break; |
167 |
< |
case Token.within: |
167 |
> |
case Token::within: |
168 |
|
bs = stack[sp - 1]; |
169 |
|
stack[sp - 1] = new BitSet(); |
170 |
|
withinInstruction(instruction, bs, stack[sp - 1]); |
171 |
|
break; |
172 |
< |
case Token.selected: |
172 |
> |
case Token::selected: |
173 |
|
stack[sp++] = copyBitSet(viewer.getSelectionSet()); |
174 |
|
break; |
175 |
< |
case Token.y: |
176 |
< |
case Token.amino: |
175 |
< |
case Token.backbone: |
176 |
< |
case Token.solvent: |
177 |
< |
case Token.identifier: |
178 |
< |
case Token.sidechain: |
179 |
< |
case Token.surface: |
180 |
< |
stack[sp++] = lookupIdentifierValue((String)instruction.value); |
175 |
> |
case Token::name: |
176 |
> |
|
177 |
|
break; |
178 |
< |
case Token.opLT: |
179 |
< |
case Token.opLE: |
180 |
< |
case Token.opGE: |
181 |
< |
case Token.opGT: |
182 |
< |
case Token.opEQ: |
183 |
< |
case Token.opNE: |
178 |
> |
case Token::index: |
179 |
> |
|
180 |
> |
break; |
181 |
> |
case Token::molname: |
182 |
> |
|
183 |
> |
break; |
184 |
> |
case Token::molindex: |
185 |
> |
break; |
186 |
> |
case Token::identifier: |
187 |
> |
stack[sp++] = lookupIdentifierValue((std::string)instruction.value); |
188 |
> |
break; |
189 |
> |
case Token::opLT: |
190 |
> |
case Token::opLE: |
191 |
> |
case Token::opGE: |
192 |
> |
case Token::opGT: |
193 |
> |
case Token::opEQ: |
194 |
> |
case Token::opNE: |
195 |
|
bs = stack[sp++] = new BitSet(); |
196 |
|
comparatorInstruction(instruction, bs); |
197 |
|
break; |
216 |
|
for (int i = 0; i < numberOfAtoms; ++i) { |
217 |
|
Atom atom = frame.getAtomAt(i); |
218 |
|
switch (property) { |
219 |
< |
case Token.atomno: |
220 |
< |
propertyValue = atom.getAtomNumber(); |
219 |
> |
case Token::mass: |
220 |
> |
//propertyValue = atom.getAtomNumber(); |
221 |
|
break; |
222 |
< |
case Token.elemno: |
223 |
< |
propertyValue = atom.getElementNumber(); |
222 |
> |
case Token::charge: |
223 |
> |
|
224 |
|
break; |
225 |
< |
case Token.temperature: |
226 |
< |
propertyValue = atom.getBfactor100(); |
220 |
< |
if (propertyValue < 0) |
221 |
< |
continue; |
222 |
< |
propertyValue /= 100; |
225 |
> |
case Token::dipole: |
226 |
> |
|
227 |
|
break; |
224 |
– |
case Token._atomID: |
225 |
– |
propertyValue = atom.getSpecialAtomID(); |
226 |
– |
if (propertyValue < 0) |
227 |
– |
continue; |
228 |
– |
break; |
229 |
– |
case Token._structure: |
230 |
– |
propertyValue = getProteinStructureType(atom); |
231 |
– |
if (propertyValue == -1) |
232 |
– |
continue; |
233 |
– |
break; |
234 |
– |
case Token.radius: |
235 |
– |
propertyValue = atom.getRasMolRadius(); |
236 |
– |
break; |
237 |
– |
case Token._bondedcount: |
238 |
– |
propertyValue = atom.getCovalentBondCount(); |
239 |
– |
break; |
240 |
– |
case Token.model: |
241 |
– |
propertyValue = atom.getModelTagNumber(); |
242 |
– |
break; |
228 |
|
default: |
229 |
|
unrecognizedAtomProperty(property); |
230 |
|
} |
231 |
< |
boolean match = false; |
231 |
> |
bool match = false; |
232 |
|
switch (comparator) { |
233 |
< |
case Token.opLT: |
233 |
> |
case Token::opLT: |
234 |
|
match = propertyValue < comparisonValue; |
235 |
|
break; |
236 |
< |
case Token.opLE: |
236 |
> |
case Token::opLE: |
237 |
|
match = propertyValue <= comparisonValue; |
238 |
|
break; |
239 |
< |
case Token.opGE: |
239 |
> |
case Token::opGE: |
240 |
|
match = propertyValue >= comparisonValue; |
241 |
|
break; |
242 |
< |
case Token.opGT: |
242 |
> |
case Token::opGT: |
243 |
|
match = propertyValue > comparisonValue; |
244 |
|
break; |
245 |
< |
case Token.opEQ: |
245 |
> |
case Token::opEQ: |
246 |
|
match = propertyValue == comparisonValue; |
247 |
|
break; |
248 |
< |
case Token.opNE: |
248 |
> |
case Token::opNE: |
249 |
|
match = propertyValue != comparisonValue; |
250 |
|
break; |
251 |
|
} |
254 |
|
} |
255 |
|
} |
256 |
|
|
257 |
< |
void SelectionEvaluator::withinInstruction(Token instruction, BitSet bs, BitSet bsResult) |
257 |
> |
void SelectionEvaluator::withinInstruction(const Token& instruction, BitSet& bs, BitSet& bsResult) |
258 |
|
|
259 |
< |
Object withinSpec = instruction.value; |
259 |
> |
boost::any withinSpec = instruction.value; |
260 |
|
if (withinSpec instanceof Float) { |
261 |
|
withinDistance(((Float)withinSpec).floatValue(), bs, bsResult); |
262 |
|
return; |
277 |
|
} |
278 |
|
} |
279 |
|
|
280 |
< |
void SelectionEvaluator::define() throws ScriptException { |
281 |
< |
String variable = (String)statement[1].value; |
282 |
< |
variables.put(variable, (expression(statement, 2))); |
280 |
> |
void SelectionEvaluator::define() { |
281 |
> |
std::string variable = (std::string)statement[1].value; |
282 |
> |
variables.insert(std::make_pair(variable, expression(statement, 2))); |
283 |
|
} |
284 |
|
} |
285 |
|
|
286 |
|
void SelectionEvaluator::predefine(Token[] statement) { |
287 |
< |
String variable = (String)statement[1].value; |
287 |
> |
std::string variable = (std::string)statement[1].value; |
288 |
|
variables.put(variable, statement); |
289 |
|
} |
290 |
|
|
291 |
|
void SelectionEvaluator::select(){ |
307 |
– |
// NOTE this is called by restrict() |
308 |
– |
if (statementLength == 1) { |
309 |
– |
viewer.selectAll(); |
310 |
– |
if (!viewer.getRasmolHydrogenSetting()) |
311 |
– |
viewer.excludeSelectionSet(getHydrogenSet()); |
312 |
– |
if (!viewer.getRasmolHeteroSetting()) |
313 |
– |
viewer.excludeSelectionSet(getHeteroSet()); |
314 |
– |
} else { |
292 |
|
viewer.setSelectionSet(expression(statement, 1)); |
316 |
– |
} |
317 |
– |
viewer.scriptStatus("" + viewer.getSelectionCount() + " atoms selected"); |
293 |
|
} |
294 |
|
|
295 |
|
} |