| 40 |
|
*/ |
| 41 |
|
#include "selection/NameFinder.hpp" |
| 42 |
|
#include "utils/wildcards.hpp" |
| 43 |
+ |
#include "utils/StringTokenizer.hpp" |
| 44 |
+ |
#include "primitives/Molecule.hpp" |
| 45 |
|
namespace oopse { |
| 46 |
|
|
| 47 |
|
TreeNode::~TreeNode(){ |
| 54 |
|
|
| 55 |
|
|
| 56 |
|
NameFinder::NameFinder(SimInfo* info) : info_(info), root_(NULL){ |
| 57 |
< |
nStuntDouble_ = info_->getNGlobalAtoms() + info_->getNGlobalRigidBodies() |
| 57 |
> |
nStuntDouble_ = info_->getNGlobalAtoms() + info_->getNGlobalRigidBodies(); |
| 58 |
|
loadNames(); |
| 59 |
|
} |
| 60 |
|
|
| 74 |
|
RigidBody* rb; |
| 75 |
|
|
| 76 |
|
root_ = new TreeNode; |
| 77 |
< |
root_->bs.resize(nStuntDobule_); |
| 77 |
> |
root_->bs.resize(nStuntDouble_); |
| 78 |
|
root_->bs.setAll(); // |
| 79 |
|
|
| 80 |
|
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
| 87 |
|
currentMolNode->name = molName; |
| 88 |
|
currentMolNode->bs.resize(nStuntDouble_); |
| 89 |
|
}else { |
| 90 |
< |
currentMolNode = i->second; |
| 90 |
> |
currentMolNode = foundIter->second; |
| 91 |
|
} |
| 92 |
|
|
| 93 |
|
for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
| 139 |
|
|
| 140 |
|
} |
| 141 |
|
|
| 140 |
– |
std::map<std::string, TreeNode*>::iterator i; |
| 141 |
– |
for( i = root_->children.begin(); i != ; ++i){ |
| 142 |
– |
i->bs = |
| 143 |
– |
} |
| 142 |
|
} |
| 143 |
|
|
| 144 |
|
bool NameFinder::match(const std::string& name, BitSet& bs){ |
| 145 |
|
|
| 146 |
< |
bool error = true; |
| 146 |
> |
bool hasError = false; |
| 147 |
|
StringTokenizer tokenizer(name, "."); |
| 148 |
|
|
| 149 |
|
std::vector<std::string> names; |
| 159 |
|
//if all molecules are selected, we don't need to do the matching, just set all of the bits |
| 160 |
|
bs.setAll(); |
| 161 |
|
} else{ |
| 162 |
< |
matchMolecule(name[0]); |
| 163 |
< |
matchStuntDouble("*", names[0]); |
| 162 |
> |
matchMolecule(names[0], bs); |
| 163 |
> |
matchStuntDouble("*", names[0], bs); |
| 164 |
|
} |
| 165 |
|
|
| 166 |
|
break; |
| 167 |
|
case 2: |
| 168 |
|
//could be molecule.*(include atoms and rigidbodies) or rigidbody.*(atoms belong to rigidbody) |
| 169 |
|
matchRigidAtoms("*", names[0], names[1], bs); |
| 170 |
< |
matchStuntDouble(names[0], names[1]); |
| 170 |
> |
matchStuntDouble(names[0], names[1], bs); |
| 171 |
|
|
| 172 |
|
break; |
| 173 |
|
case 3: |
| 174 |
|
//must be molecule.rigidbody.* |
| 175 |
< |
matchRigidAtoms(names[0], names[1], names[2], bs) |
| 175 |
> |
matchRigidAtoms(names[0], names[1], names[2], bs); |
| 176 |
|
break; |
| 177 |
< |
default: |
| 177 |
> |
default: |
| 178 |
> |
hasError = true; |
| 179 |
|
break; |
| 180 |
|
} |
| 181 |
|
|
| 182 |
< |
return matched; |
| 182 |
> |
return hasError; |
| 183 |
|
} |
| 184 |
|
|
| 185 |
|
void NameFinder::matchMolecule(const std::string& molName, BitSet& bs) { |
| 186 |
|
std::vector<TreeNode*> molNodes = getMatchedChildren(root_, molName); |
| 187 |
|
std::vector<TreeNode*>::iterator i; |
| 188 |
|
for( i = molNodes.begin(); i != molNodes.end(); ++i ) { |
| 189 |
< |
bs |= i->bs; |
| 189 |
> |
bs |= (*i)->bs; |
| 190 |
|
} |
| 191 |
|
} |
| 192 |
|
|
| 197 |
|
std::vector<TreeNode*> sdNodes = getMatchedChildren(*i, sdName); |
| 198 |
|
std::vector<TreeNode*>::iterator j; |
| 199 |
|
for (j = sdNodes.begin(); j != sdNodes.end(); ++j) { |
| 200 |
< |
bs |= j->bs; |
| 200 |
> |
bs |= (*j)->bs; |
| 201 |
|
} |
| 202 |
|
} |
| 203 |
|
|
| 213 |
|
std::vector<TreeNode*> rbAtomNodes = getMatchedChildren(*j, rbAtomName); |
| 214 |
|
std::vector<TreeNode*>::iterator k; |
| 215 |
|
for(k = rbAtomNodes.begin(); k != rbAtomNodes.end(); ++k){ |
| 216 |
< |
bs |= k->bs; |
| 216 |
> |
bs |= (*k)->bs; |
| 217 |
|
} |
| 218 |
|
} |
| 219 |
|
} |