1 |
< |
/* |
1 |
> |
/* |
2 |
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
|
* |
4 |
|
* The University of Notre Dame grants you ("Licensee") a |
38 |
|
* University of Notre Dame has been advised of the possibility of |
39 |
|
* such damages. |
40 |
|
*/ |
41 |
< |
|
41 |
> |
#include "selection/SelectionManager.hpp" |
42 |
|
#include "visitors/OtherVisitor.hpp" |
43 |
|
#include "primitives/DirectionalAtom.hpp" |
44 |
|
#include "primitives/RigidBody.hpp" |
45 |
|
#include "primitives/Molecule.hpp" |
46 |
|
#include "brains/SimInfo.hpp" |
47 |
|
namespace oopse { |
48 |
– |
|
49 |
– |
//----------------------------------------------------------------------------// |
50 |
– |
void IgnoreVisitor::visit(Atom *atom) { |
51 |
– |
if (isIgnoreType(atom->getType())) |
52 |
– |
internalVisit(atom); |
53 |
– |
} |
54 |
– |
|
55 |
– |
void IgnoreVisitor::visit(DirectionalAtom *datom) { |
56 |
– |
if (isIgnoreType(datom->getType())) |
57 |
– |
internalVisit(datom); |
58 |
– |
} |
59 |
– |
|
60 |
– |
void IgnoreVisitor::visit(RigidBody *rb) { |
61 |
– |
std::vector<Atom *> myAtoms; |
62 |
– |
std::vector<Atom *>::iterator atomIter; |
63 |
– |
AtomInfo * atomInfo; |
64 |
– |
|
65 |
– |
if (isIgnoreType(rb->getType())) { |
66 |
– |
internalVisit(rb); |
67 |
– |
|
68 |
– |
myAtoms = rb->getAtoms(); |
69 |
– |
|
70 |
– |
for( atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter ) |
71 |
– |
internalVisit(*atomIter); |
72 |
– |
} |
73 |
– |
} |
74 |
– |
|
75 |
– |
bool IgnoreVisitor::isIgnoreType(const std::string&name) { |
76 |
– |
return itList.find(name) != itList.end() ? true : false; |
77 |
– |
} |
78 |
– |
|
79 |
– |
void IgnoreVisitor::internalVisit(StuntDouble *sd) { |
80 |
– |
GenericData *data; |
81 |
– |
data = sd->getPropertyByName("IGNORE"); |
82 |
– |
|
83 |
– |
//if this stuntdoulbe is already marked as ignore just skip it |
84 |
– |
if (data == NULL) { |
85 |
– |
data = new GenericData; |
86 |
– |
data->setID("IGNORE"); |
87 |
– |
sd->addProperty(data); |
88 |
– |
} |
89 |
– |
} |
90 |
– |
|
91 |
– |
const std::string IgnoreVisitor::toString() { |
92 |
– |
char buffer[65535]; |
93 |
– |
std::string result; |
94 |
– |
std::set<std::string>::iterator i; |
95 |
– |
|
96 |
– |
sprintf(buffer, |
97 |
– |
"------------------------------------------------------------------\n"); |
98 |
– |
result += buffer; |
48 |
|
|
100 |
– |
sprintf(buffer, "Visitor name: %s\n", visitorName.c_str()); |
101 |
– |
result += buffer; |
102 |
– |
|
103 |
– |
sprintf(buffer, "Visitor Description: ignore stuntdoubles\n"); |
104 |
– |
result += buffer; |
105 |
– |
|
106 |
– |
//print the ignore type list |
107 |
– |
sprintf(buffer, "Ignore type list contains below types:\n"); |
108 |
– |
result += buffer; |
109 |
– |
|
110 |
– |
for( i = itList.begin(); i != itList.end(); ++i ) { |
111 |
– |
sprintf(buffer, "%s\t", i->c_str()); |
112 |
– |
result += buffer; |
113 |
– |
} |
114 |
– |
|
115 |
– |
sprintf(buffer, "\n"); |
116 |
– |
result += buffer; |
117 |
– |
|
118 |
– |
sprintf(buffer, |
119 |
– |
"------------------------------------------------------------------\n"); |
120 |
– |
result += buffer; |
121 |
– |
|
122 |
– |
return result; |
123 |
– |
} |
124 |
– |
|
125 |
– |
//----------------------------------------------------------------------------// |
126 |
– |
|
49 |
|
void WrappingVisitor::visit(Atom *atom) { |
50 |
|
internalVisit(atom); |
51 |
|
} |
217 |
|
|
218 |
|
//----------------------------------------------------------------------------// |
219 |
|
|
220 |
< |
XYZVisitor::XYZVisitor(SimInfo *info, bool printDipole) : |
221 |
< |
BaseVisitor() { |
220 |
> |
XYZVisitor::XYZVisitor(SimInfo *info) : |
221 |
> |
BaseVisitor(), seleMan(info), evaluator(info){ |
222 |
|
this->info = info; |
223 |
|
visitorName = "XYZVisitor"; |
224 |
< |
this->printDipole = printDipole; |
224 |
> |
|
225 |
> |
evaluator.loadScriptString("select all"); |
226 |
> |
|
227 |
> |
if (!evaluator.isDynamic()) { |
228 |
> |
seleMan.setSelectionSet(evaluator.evaluate()); |
229 |
> |
} |
230 |
> |
|
231 |
|
} |
232 |
+ |
|
233 |
+ |
XYZVisitor::XYZVisitor(SimInfo *info, const std::string& script) : |
234 |
+ |
BaseVisitor(), seleMan(info), evaluator(info) { |
235 |
+ |
this->info = info; |
236 |
+ |
visitorName = "XYZVisitor"; |
237 |
+ |
|
238 |
+ |
evaluator.loadScriptString(script); |
239 |
|
|
240 |
+ |
if (!evaluator.isDynamic()) { |
241 |
+ |
seleMan.setSelectionSet(evaluator.evaluate()); |
242 |
+ |
} |
243 |
+ |
|
244 |
+ |
} |
245 |
+ |
|
246 |
|
void XYZVisitor::visit(Atom *atom) { |
247 |
< |
if (!isIgnore(atom)) |
247 |
> |
if (isSelected(atom)) |
248 |
|
internalVisit(atom); |
249 |
|
} |
250 |
|
|
251 |
|
void XYZVisitor::visit(DirectionalAtom *datom) { |
252 |
< |
if (!isIgnore(datom)) |
252 |
> |
if (isSelected(datom)) |
253 |
|
internalVisit(datom); |
254 |
|
} |
255 |
|
|
256 |
|
void XYZVisitor::visit(RigidBody *rb) { |
257 |
< |
if (!isIgnore(rb)) |
257 |
> |
if (isSelected(rb)) |
258 |
|
internalVisit(rb); |
259 |
|
} |
260 |
|
|
261 |
+ |
void XYZVisitor::update() { |
262 |
+ |
//if dynamic, we need to re-evaluate the selection |
263 |
+ |
if (evaluator.isDynamic()) { |
264 |
+ |
seleMan.setSelectionSet(evaluator.evaluate()); |
265 |
+ |
} |
266 |
+ |
} |
267 |
+ |
|
268 |
|
void XYZVisitor::internalVisit(StuntDouble *sd) { |
269 |
|
GenericData * data; |
270 |
|
AtomData * atomData; |
285 |
|
|
286 |
|
for( atomInfo = atomData->beginAtomInfo(i); atomInfo; |
287 |
|
atomInfo = atomData->nextAtomInfo(i) ) { |
288 |
< |
if (printDipole) |
289 |
< |
sprintf(buffer, |
290 |
< |
"%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f", |
291 |
< |
atomInfo->AtomType.c_str(), |
292 |
< |
atomInfo->pos[0], |
293 |
< |
atomInfo->pos[1], |
294 |
< |
atomInfo->pos[2], |
295 |
< |
atomInfo->dipole[0], |
296 |
< |
atomInfo->dipole[1], |
349 |
< |
atomInfo->dipole[2]); else |
350 |
< |
sprintf(buffer, "%s%15.8f%15.8f%15.8f", |
351 |
< |
atomInfo->AtomType.c_str(), atomInfo->pos[0], |
352 |
< |
atomInfo->pos[1], atomInfo->pos[2]); |
353 |
< |
|
288 |
> |
sprintf(buffer, |
289 |
> |
"%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f", |
290 |
> |
atomInfo->atomTypeName.c_str(), |
291 |
> |
atomInfo->pos[0], |
292 |
> |
atomInfo->pos[1], |
293 |
> |
atomInfo->pos[2], |
294 |
> |
atomInfo->dipole[0], |
295 |
> |
atomInfo->dipole[1], |
296 |
> |
atomInfo->dipole[2]); |
297 |
|
frame.push_back(buffer); |
298 |
|
} |
299 |
|
} |
300 |
|
|
301 |
< |
bool XYZVisitor::isIgnore(StuntDouble *sd) { |
302 |
< |
GenericData *data; |
360 |
< |
|
361 |
< |
data = sd->getPropertyByName("IGNORE"); |
362 |
< |
return data == NULL ? false : true; |
301 |
> |
bool XYZVisitor::isSelected(StuntDouble *sd) { |
302 |
> |
return seleMan.isSelected(sd); |
303 |
|
} |
304 |
|
|
305 |
|
void XYZVisitor::writeFrame(std::ostream &outStream) { |
405 |
|
} |
406 |
|
|
407 |
|
const std::string PrepareVisitor::toString() { |
408 |
< |
char buffer[65535]; |
409 |
< |
std::string result; |
410 |
< |
|
411 |
< |
sprintf(buffer, |
412 |
< |
"------------------------------------------------------------------\n"); |
413 |
< |
result += buffer; |
414 |
< |
|
415 |
< |
sprintf(buffer, "Visitor name: %s", visitorName.c_str()); |
416 |
< |
result += buffer; |
417 |
< |
|
418 |
< |
sprintf(buffer, |
419 |
< |
"Visitor Description: prepare for operation of other vistors\n"); |
420 |
< |
result += buffer; |
421 |
< |
|
422 |
< |
sprintf(buffer, |
423 |
< |
"------------------------------------------------------------------\n"); |
424 |
< |
result += buffer; |
425 |
< |
|
426 |
< |
return result; |
408 |
> |
char buffer[65535]; |
409 |
> |
std::string result; |
410 |
> |
|
411 |
> |
sprintf(buffer, |
412 |
> |
"------------------------------------------------------------------\n"); |
413 |
> |
result += buffer; |
414 |
> |
|
415 |
> |
sprintf(buffer, "Visitor name: %s", visitorName.c_str()); |
416 |
> |
result += buffer; |
417 |
> |
|
418 |
> |
sprintf(buffer, |
419 |
> |
"Visitor Description: prepare for operation of other vistors\n"); |
420 |
> |
result += buffer; |
421 |
> |
|
422 |
> |
sprintf(buffer, |
423 |
> |
"------------------------------------------------------------------\n"); |
424 |
> |
result += buffer; |
425 |
> |
|
426 |
> |
return result; |
427 |
|
} |
428 |
|
|
429 |
|
//----------------------------------------------------------------------------// |
463 |
|
continue; |
464 |
|
|
465 |
|
for( atomInfo = atomData->beginAtomInfo(i); atomInfo; |
466 |
< |
atomInfo = atomData->nextAtomInfo(i) ) { |
467 |
< |
replaceType(atomInfo->AtomType); |
466 |
> |
atomInfo = atomData->nextAtomInfo(i) ) { |
467 |
> |
atomInfo->atomTypeName = trimmedName(atomInfo->atomTypeName); |
468 |
|
} //end for(atomInfo) |
469 |
|
} //end for(atomIter) |
470 |
|
} //end if (waterTypeList.find(rbName) != waterTypeList.end()) |
471 |
|
} |
472 |
|
|
473 |
< |
void WaterTypeVisitor::replaceType(std::string&atomType) { |
474 |
< |
atomType = atomType.substr(0, atomType.find('_')); |
475 |
< |
} |
473 |
> |
std::string WaterTypeVisitor::trimmedName(const std::string&atomTypeName) { |
474 |
> |
return atomTypeName.substr(0, atomTypeName.find('_')); |
475 |
> |
} |
476 |
|
|
477 |
|
const std::string WaterTypeVisitor::toString() { |
478 |
|
char buffer[65535]; |