--- trunk/src/selection/NameFinder.cpp 2005/02/04 22:39:26 288 +++ trunk/src/selection/NameFinder.cpp 2005/04/05 23:09:48 452 @@ -42,6 +42,7 @@ #include "utils/wildcards.hpp" #include "utils/StringTokenizer.hpp" #include "primitives/Molecule.hpp" +#include "utils/StringUtils.hpp" namespace oopse { TreeNode::~TreeNode(){ @@ -140,19 +141,24 @@ BitSet NameFinder::match(const std::string& name){ switch(size) { case 1 : //could be molecule name, atom name and rigidbody name - if (names[0] == "*"){ - //if all molecules are selected, we don't need to do the matching, just set all of the bits - bs.setAll(); - } else{ - matchMolecule(names[0], bs); - matchStuntDouble("*", names[0], bs); - } + matchMolecule(names[0], bs); + matchStuntDouble("*", names[0], bs); break; case 2: //could be molecule.*(include atoms and rigidbodies) or rigidbody.*(atoms belong to rigidbody) - matchRigidAtoms("*", names[0], names[1], bs); - matchStuntDouble(names[0], names[1], bs); + + if (!isInteger(names[1])){ + matchRigidAtoms("*", names[0], names[1], bs); + matchStuntDouble(names[0], names[1], bs); + } else { + int internalIndex = lexi_cast(names[1]); + if (internalIndex < 0) { + std::cerr << names[0] << ". " << names[1] << " is an invalid name" << std::endl; + } else { + matchInternalIndex(names[0], internalIndex, bs); + } + } break; case 3: @@ -222,4 +228,40 @@ bool NameFinder::isMatched(const std::string& str, con return Wildcard::wildcardfit (wildcard.c_str(), str.c_str()); } + +void NameFinder::matchInternalIndex(const std::string& name, int internalIndex, BitSet& bs){ + + std::map::iterator foundIter; + SimInfo::MoleculeIterator mi; + Molecule* mol; + + for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { + + if (isMatched(mol->getMoleculeName(), name) ) { + int natoms = mol->getNAtoms(); + int nrigidbodies = mol->getNRigidBodies(); + if (internalIndex >= natoms + nrigidbodies) { + continue; + } else if (internalIndex < natoms) { + bs.setBitOn(mol->getAtomAt(internalIndex)->getGlobalIndex()); + continue; + } else if ( internalIndex < natoms + nrigidbodies) { + bs.setBitOn(mol->getRigidBodyAt(internalIndex - natoms)->getGlobalIndex()); + } + } + + } + } + + bool NameFinder::isInteger(const std::string str) { + for(int i =0; i < str.size(); ++i){ + if (!std::isdigit(str[i])) { + return false; + } + } + + return true; + } + +}