--- trunk/OOPSE-4/src/visitors/OtherVisitor.cpp 2005/01/12 22:41:40 1930 +++ trunk/OOPSE-4/src/visitors/OtherVisitor.cpp 2005/03/09 17:30:29 2097 @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. * * The University of Notre Dame grants you ("Licensee") a @@ -38,92 +38,14 @@ * University of Notre Dame has been advised of the possibility of * such damages. */ - +#include "selection/SelectionManager.hpp" #include "visitors/OtherVisitor.hpp" #include "primitives/DirectionalAtom.hpp" #include "primitives/RigidBody.hpp" #include "primitives/Molecule.hpp" #include "brains/SimInfo.hpp" namespace oopse { - -//----------------------------------------------------------------------------// -void IgnoreVisitor::visit(Atom *atom) { - if (isIgnoreType(atom->getType())) - internalVisit(atom); -} - -void IgnoreVisitor::visit(DirectionalAtom *datom) { - if (isIgnoreType(datom->getType())) - internalVisit(datom); -} - -void IgnoreVisitor::visit(RigidBody *rb) { - std::vector myAtoms; - std::vector::iterator atomIter; - AtomInfo * atomInfo; - - if (isIgnoreType(rb->getType())) { - internalVisit(rb); - - myAtoms = rb->getAtoms(); - - for( atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter ) - internalVisit(*atomIter); - } -} - -bool IgnoreVisitor::isIgnoreType(const std::string&name) { -return itList.find(name) != itList.end() ? true : false; -} - -void IgnoreVisitor::internalVisit(StuntDouble *sd) { - GenericData *data; - data = sd->getPropertyByName("IGNORE"); - - //if this stuntdoulbe is already marked as ignore just skip it - if (data == NULL) { - data = new GenericData; - data->setID("IGNORE"); - sd->addProperty(data); - } -} - -const std::string IgnoreVisitor::toString() { - char buffer[65535]; - std::string result; - std::set::iterator i; - - sprintf(buffer, - "------------------------------------------------------------------\n"); - result += buffer; - sprintf(buffer, "Visitor name: %s\n", visitorName.c_str()); - result += buffer; - - sprintf(buffer, "Visitor Description: ignore stuntdoubles\n"); - result += buffer; - - //print the ignore type list - sprintf(buffer, "Ignore type list contains below types:\n"); - result += buffer; - - for( i = itList.begin(); i != itList.end(); ++i ) { - sprintf(buffer, "%s\t", i->c_str()); - result += buffer; - } - - sprintf(buffer, "\n"); - result += buffer; - - sprintf(buffer, - "------------------------------------------------------------------\n"); - result += buffer; - - return result; -} - -//----------------------------------------------------------------------------// - void WrappingVisitor::visit(Atom *atom) { internalVisit(atom); } @@ -295,28 +217,54 @@ XYZVisitor::XYZVisitor(SimInfo *info, bool printDipole //----------------------------------------------------------------------------// -XYZVisitor::XYZVisitor(SimInfo *info, bool printDipole) : - BaseVisitor() { +XYZVisitor::XYZVisitor(SimInfo *info) : + BaseVisitor(), seleMan(info), evaluator(info){ this->info = info; visitorName = "XYZVisitor"; - this->printDipole = printDipole; + + evaluator.loadScriptString("select all"); + + if (!evaluator.isDynamic()) { + seleMan.setSelectionSet(evaluator.evaluate()); + } + } + +XYZVisitor::XYZVisitor(SimInfo *info, const std::string& script) : + BaseVisitor(), seleMan(info), evaluator(info) { + this->info = info; + visitorName = "XYZVisitor"; + + evaluator.loadScriptString(script); + if (!evaluator.isDynamic()) { + seleMan.setSelectionSet(evaluator.evaluate()); + } + +} + void XYZVisitor::visit(Atom *atom) { - if (!isIgnore(atom)) + if (isSelected(atom)) internalVisit(atom); } void XYZVisitor::visit(DirectionalAtom *datom) { - if (!isIgnore(datom)) + if (isSelected(datom)) internalVisit(datom); } void XYZVisitor::visit(RigidBody *rb) { - if (!isIgnore(rb)) + if (isSelected(rb)) internalVisit(rb); } +void XYZVisitor::update() { + //if dynamic, we need to re-evaluate the selection + if (evaluator.isDynamic()) { + seleMan.setSelectionSet(evaluator.evaluate()); + } +} + void XYZVisitor::internalVisit(StuntDouble *sd) { GenericData * data; AtomData * atomData; @@ -337,29 +285,21 @@ void XYZVisitor::internalVisit(StuntDouble *sd) { for( atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i) ) { - if (printDipole) - sprintf(buffer, - "%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f", - atomInfo->AtomType.c_str(), - atomInfo->pos[0], - atomInfo->pos[1], - atomInfo->pos[2], - atomInfo->dipole[0], - atomInfo->dipole[1], - atomInfo->dipole[2]); else - sprintf(buffer, "%s%15.8f%15.8f%15.8f", - atomInfo->AtomType.c_str(), atomInfo->pos[0], - atomInfo->pos[1], atomInfo->pos[2]); - + sprintf(buffer, + "%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f", + atomInfo->atomTypeName.c_str(), + atomInfo->pos[0], + atomInfo->pos[1], + atomInfo->pos[2], + atomInfo->dipole[0], + atomInfo->dipole[1], + atomInfo->dipole[2]); frame.push_back(buffer); } } -bool XYZVisitor::isIgnore(StuntDouble *sd) { - GenericData *data; - - data = sd->getPropertyByName("IGNORE"); - return data == NULL ? false : true; +bool XYZVisitor::isSelected(StuntDouble *sd) { + return seleMan.isSelected(sd); } void XYZVisitor::writeFrame(std::ostream &outStream) { @@ -465,25 +405,25 @@ const std::string PrepareVisitor::toString() { } const std::string PrepareVisitor::toString() { - char buffer[65535]; - std::string result; - - sprintf(buffer, - "------------------------------------------------------------------\n"); - result += buffer; - - sprintf(buffer, "Visitor name: %s", visitorName.c_str()); - result += buffer; - - sprintf(buffer, - "Visitor Description: prepare for operation of other vistors\n"); - result += buffer; - - sprintf(buffer, - "------------------------------------------------------------------\n"); - result += buffer; - - return result; + char buffer[65535]; + std::string result; + + sprintf(buffer, + "------------------------------------------------------------------\n"); + result += buffer; + + sprintf(buffer, "Visitor name: %s", visitorName.c_str()); + result += buffer; + + sprintf(buffer, + "Visitor Description: prepare for operation of other vistors\n"); + result += buffer; + + sprintf(buffer, + "------------------------------------------------------------------\n"); + result += buffer; + + return result; } //----------------------------------------------------------------------------// @@ -523,16 +463,16 @@ void WaterTypeVisitor::visit(RigidBody *rb) { continue; for( atomInfo = atomData->beginAtomInfo(i); atomInfo; - atomInfo = atomData->nextAtomInfo(i) ) { - replaceType(atomInfo->AtomType); + atomInfo = atomData->nextAtomInfo(i) ) { + atomInfo->atomTypeName = trimmedName(atomInfo->atomTypeName); } //end for(atomInfo) } //end for(atomIter) } //end if (waterTypeList.find(rbName) != waterTypeList.end()) } -void WaterTypeVisitor::replaceType(std::string&atomType) { -atomType = atomType.substr(0, atomType.find('_')); -} + std::string WaterTypeVisitor::trimmedName(const std::string&atomTypeName) { + return atomTypeName.substr(0, atomTypeName.find('_')); + } const std::string WaterTypeVisitor::toString() { char buffer[65535];