| 77 | 
  | 
    return loadScriptFileInternal(filename); | 
| 78 | 
  | 
} | 
| 79 | 
  | 
 | 
| 80 | 
+ | 
bool SelectionEvaluator::loadScriptFileInternal(const  string & filename) { | 
| 81 | 
  | 
 | 
| 82 | 
+ | 
} | 
| 83 | 
+ | 
 | 
| 84 | 
  | 
void SelectionEvaluator::instructionDispatchLoop(){ | 
| 85 | 
  | 
 | 
| 86 | 
  | 
    while ( pc < aatoken.size()) { | 
| 100 | 
  | 
        } | 
| 101 | 
  | 
    } | 
| 102 | 
  | 
} | 
| 100 | 
– | 
 | 
| 101 | 
– | 
  void SelectionEvaluator::predefine(const std::string& script) { | 
| 102 | 
– | 
    if (compiler.compile("#predefine", script)) { | 
| 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 | 
– | 
 | 
| 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 | 
– | 
          std::string variable = (std::string)statement[1].value; | 
| 117 | 
– | 
          variables.put(variable, statement); | 
| 118 | 
– | 
        } else { | 
| 119 | 
– | 
          viewer.scriptStatus("invalid variable name:" + script); | 
| 120 | 
– | 
        } | 
| 121 | 
– | 
      } else { | 
| 122 | 
– | 
        viewer.scriptStatus("bad predefinition length:" + script); | 
| 123 | 
– | 
      } | 
| 124 | 
– | 
    } else { | 
| 125 | 
– | 
      viewer.scriptStatus("predefined set compile error:" + script + | 
| 126 | 
– | 
                          "\ncompile error:" + compiler.getErrorMessage()); | 
| 127 | 
– | 
    } | 
| 128 | 
– | 
  } | 
| 103 | 
  | 
 | 
| 130 | 
– | 
 | 
| 131 | 
– | 
 | 
| 104 | 
  | 
  BitSet SelectionEvaluator::expression(std::vector<Token>& code, int pcStart) { | 
| 105 | 
  | 
    int numberOfAtoms = viewer.getAtomCount(); | 
| 106 | 
  | 
    BitSet bs; | 
| 109 | 
  | 
 | 
| 110 | 
  | 
    for (int pc = pcStart; ; ++pc) { | 
| 111 | 
  | 
      Token instruction = code[pc]; | 
| 112 | 
< | 
      if (logMessages) | 
| 141 | 
< | 
        viewer.scriptStatus("instruction=" + instruction); | 
| 112 | 
> | 
 | 
| 113 | 
  | 
      switch (instruction.tok) { | 
| 114 | 
  | 
      case Token::expressionBegin: | 
| 115 | 
  | 
        break; | 
| 116 | 
  | 
      case Token::expressionEnd: | 
| 117 | 
< | 
        break expression_loop; | 
| 117 | 
> | 
        break; | 
| 118 | 
  | 
      case Token::all: | 
| 119 | 
  | 
        bs = stack[sp++] = new BitSet(numberOfAtoms); | 
| 120 | 
  | 
        for (int i = numberOfAtoms; --i >= 0; ) | 
| 228 | 
  | 
void SelectionEvaluator::withinInstruction(const Token& instruction, BitSet& bs, BitSet& bsResult) | 
| 229 | 
  | 
 | 
| 230 | 
  | 
    boost::any withinSpec = instruction.value; | 
| 231 | 
< | 
    if (withinSpec instanceof Float) { | 
| 232 | 
< | 
        withinDistance(((Float)withinSpec).floatValue(), bs, bsResult); | 
| 231 | 
> | 
    if (withinSpec.type() == typeid(float)){ | 
| 232 | 
> | 
        withinDistance(boost::any_cast<float>(withinSpec), bs, bsResult); | 
| 233 | 
  | 
        return; | 
| 234 | 
  | 
    } | 
| 235 | 
+ | 
     | 
| 236 | 
  | 
    evalError("Unrecognized within parameter:" + withinSpec); | 
| 237 | 
  | 
} | 
| 238 | 
  | 
 | 
| 239 | 
< | 
  void SelectionEvaluator::withinDistance(float distance, BitSet bs, BitSet bsResult) { | 
| 239 | 
> | 
  void SelectionEvaluator::withinDistance(float distance, const BitSet& bs, const BitSet& bsResult) { | 
| 240 | 
  | 
    Frame frame = viewer.getFrame(); | 
| 241 | 
  | 
    for (int i = frame.getAtomCount(); --i >= 0; ) { | 
| 242 | 
  | 
      if (bs.get(i)) { | 
| 250 | 
  | 
  } | 
| 251 | 
  | 
 | 
| 252 | 
  | 
  void SelectionEvaluator::define() { | 
| 253 | 
< | 
    std::string variable = (std::string)statement[1].value; | 
| 253 | 
> | 
    assert(statement.size() >= 3); | 
| 254 | 
> | 
 | 
| 255 | 
> | 
    std::string variable = boost::any_cast<std::string>(statement[1].value); | 
| 256 | 
> | 
     | 
| 257 | 
  | 
    variables.insert(std::make_pair(variable, expression(statement, 2))); | 
| 258 | 
  | 
  } | 
| 259 | 
  | 
} | 
| 260 | 
  | 
 | 
| 261 | 
< | 
  void SelectionEvaluator::predefine(Token[] statement) { | 
| 262 | 
< | 
    std::string variable = (std::string)statement[1].value; | 
| 288 | 
< | 
    variables.put(variable, statement); | 
| 289 | 
< | 
  } | 
| 261 | 
> | 
/** @todo */ | 
| 262 | 
> | 
void SelectionEvaluator::predefine(const std::string& script) { | 
| 263 | 
  | 
 | 
| 264 | 
< | 
  void SelectionEvaluator::select(){ | 
| 265 | 
< | 
      viewer.setSelectionSet(expression(statement, 1)); | 
| 266 | 
< | 
  } | 
| 267 | 
< | 
   | 
| 268 | 
< | 
  } | 
| 264 | 
> | 
    if (compiler.compile("#predefine", script)) { | 
| 265 | 
> | 
        std::vector<std::vector<Token> > aatoken = compiler.getAatokenCompiled(); | 
| 266 | 
> | 
        if (aatoken.size() != 1) { | 
| 267 | 
> | 
            evalError("predefinition does not have exactly 1 command:" | 
| 268 | 
> | 
                + script); | 
| 269 | 
> | 
            return; | 
| 270 | 
> | 
        } | 
| 271 | 
> | 
        std::vector<Token> statement = aatoken[0]; | 
| 272 | 
> | 
        if (statement.size() > 2) { | 
| 273 | 
> | 
            int tok = statement[1].tok; | 
| 274 | 
> | 
            if (tok == Token::identifier || (tok & Token::predefinedset) == Token::predefinedset) { | 
| 275 | 
> | 
                std::string variable = (std::string)statement[1].value; | 
| 276 | 
> | 
                variables.insert(std::make_pair(variable, statement)); | 
| 277 | 
> | 
 | 
| 278 | 
> | 
            } else { | 
| 279 | 
> | 
                evalError("invalid variable name:" + script); | 
| 280 | 
> | 
            } | 
| 281 | 
> | 
        }else { | 
| 282 | 
> | 
            evalError("bad predefinition length:" + script); | 
| 283 | 
> | 
        } | 
| 284 | 
> | 
 | 
| 285 | 
> | 
         | 
| 286 | 
> | 
    } else { | 
| 287 | 
> | 
        evalError("predefined set compile error:" + script + | 
| 288 | 
> | 
          "\ncompile error:" + compiler.getErrorMessage()); | 
| 289 | 
> | 
    } | 
| 290 | 
> | 
 | 
| 291 | 
> | 
} | 
| 292 | 
> | 
 | 
| 293 | 
> | 
void SelectionEvaluator::select(){ | 
| 294 | 
> | 
    viewer.setSelectionSet(expression(statement, 1)); | 
| 295 | 
> | 
} | 
| 296 | 
> | 
 | 
| 297 | 
> | 
BitSet SelectionEvaluator::lookupValue(const std::string& variable){ | 
| 298 | 
> | 
 | 
| 299 | 
> | 
    std::map<std::string, boost::any>::iterator i = variables.find(variable); | 
| 300 | 
> | 
 | 
| 301 | 
> | 
    if (i != variables.end()) { | 
| 302 | 
> | 
        if (i->second.type() == typeid(BitSet)) { | 
| 303 | 
> | 
            return boost::any_cast<BitSet>(i->second); | 
| 304 | 
> | 
        } else if (i->second.type() ==  typeid(std::vector<Token>)){ | 
| 305 | 
> | 
            BitSet bs = expression(boost::any_cast(i->second), 2); | 
| 306 | 
> | 
            i->second =  bs; /**@todo fixme */ | 
| 307 | 
> | 
            return bs; | 
| 308 | 
> | 
        } | 
| 309 | 
> | 
    } | 
| 310 | 
> | 
 | 
| 311 | 
> | 
} | 
| 312 | 
> | 
 | 
| 313 | 
> | 
} |