--- trunk/OOPSE/libmdtools/StuntDouble.cpp 2004/04/12 20:32:20 1097 +++ trunk/OOPSE/libmdtools/StuntDouble.cpp 2004/06/04 21:00:20 1250 @@ -25,6 +25,16 @@ int StuntDouble::getObjType(){ */ +StuntDouble::~StuntDouble(){ + map::iterator iter; + + for(iter = properties.begin(); iter != properties.end(); ++iter ){ + delete iter->second; + properties.erase(iter); + } + +} + int StuntDouble::getObjType(){ return objType; } @@ -273,6 +283,60 @@ void StuntDouble::getTrq(double trq[3]){ } } +void StuntDouble::getQ(double q[4] ){ + switch (objType) + { + case OT_ATOM: + sprintf( painCave.errMsg, + "StuntDouble::getJ was called for a regular atom.\n" + "\tRegular Atoms don't have angular momentum. Be smarter.\n"); + painCave.isFatal = 0; + simError(); + // Return zeros. + q[0] = 0; + q[1] = 0; + q[2] = 0; + q[3] = 0; + break; + case OT_DATOM: + ((DirectionalAtom*)this)->getQ(q); + break; + case OT_RIGIDBODY: + ((RigidBody*)this)->getQ(q); + break; + default: + sprintf( painCave.errMsg, + "Unrecognized ObjType (%d) in StuntDouble::getJ.\n", + objType ); + painCave.isFatal = 1; + simError(); + } +} + +void StuntDouble::setQ(double q[4] ){ + switch (objType) + { + case OT_ATOM: + sprintf( painCave.errMsg, + "StuntDouble::setJ was called for a regular atom.\n" + "\tRegular Atoms don't have angular momentum. Be smarter.\n"); + painCave.isFatal = 1; + simError(); + break; + case OT_DATOM: + ((DirectionalAtom*)this)->setJ(q); + break; + case OT_RIGIDBODY: + ((RigidBody*)this)->setJ(q); + break; + default: + sprintf( painCave.errMsg, + "Unrecognized ObjType (%d) in StuntDouble::setJ.\n", + objType ); + painCave.isFatal = 1; + simError(); + } +} void StuntDouble::getTrq(double trq[3]){ switch (objType) { @@ -463,8 +527,126 @@ void StuntDouble::getEulerAngles(double eulers[3]){ default: sprintf( painCave.errMsg, "Unrecognized ObjType (%d) in StuntDouble::getEulerAngles.\n", + objType ); + painCave.isFatal = 1; + simError(); + } +} + +double StuntDouble::getZangle(){ + switch (objType) + { + case OT_ATOM: + sprintf( painCave.errMsg, + "StuntDouble::getZangle was called for a regular atom.\n" + "\tRegular Atoms don't have zAngles. Be smarter.\n"); + painCave.isFatal = 0; + simError(); + // Return zeros. + return 0; + break; + case OT_DATOM: + return ((DirectionalAtom*)this)->getZangle(); + break; + case OT_RIGIDBODY: + return ((RigidBody*)this)->getZangle(); + break; + default: + sprintf( painCave.errMsg, + "Unrecognized ObjType (%d) in StuntDouble::getZangle.\n", + objType ); + painCave.isFatal = 1; + simError(); + return 0; + } +} + +void StuntDouble::setZangle(double zAngle){ + switch (objType) + { + case OT_ATOM: + sprintf( painCave.errMsg, + "StuntDouble::setZangle was called for a regular atom.\n" + "\tRegular Atoms don't have zAngles. Be smarter.\n"); + painCave.isFatal = 1; + simError(); + break; + case OT_DATOM: + ((DirectionalAtom*)this)->setZangle(zAngle); + break; + case OT_RIGIDBODY: + ((RigidBody*)this)->setZangle(zAngle); + break; + default: + sprintf( painCave.errMsg, + "Unrecognized ObjType (%d) in StuntDouble::setZangle.\n", objType ); painCave.isFatal = 1; simError(); + } +} + +void StuntDouble::addZangle(double zAngle){ + switch (objType) + { + case OT_ATOM: + sprintf( painCave.errMsg, + "StuntDouble::addZangle was called for a regular atom.\n" + "\tRegular Atoms don't have zAngles. Be smarter.\n"); + painCave.isFatal = 1; + simError(); + break; + case OT_DATOM: + ((DirectionalAtom*)this)->addZangle(zAngle); + break; + case OT_RIGIDBODY: + ((RigidBody*)this)->addZangle(zAngle); + break; + default: + sprintf( painCave.errMsg, + "Unrecognized ObjType (%d) in StuntDouble::addZangle.\n", + objType ); + painCave.isFatal = 1; + simError(); + } +} + +void StuntDouble::addProperty(GenericData* data){ + map::iterator result; + result = properties.find(data->getID()); + + //we can't simply use properties[prop->getID()] = prop, + //it will cause memory leak if we already contain a propery which has the same name of prop + + if(result != properties.end()){ + delete (*result).second; + (*result).second = data; } + else + properties[data->getID()] = data; + + } +void StuntDouble::removeProperty(const string& propName){ + map::iterator result; + + result = properties.find(propName); + + if(result != properties.end()){ + delete result->second; + properties.erase(result); + + } + +} +GenericData* StuntDouble::getProperty(const string& propName){ + map::iterator result; + + + result = properties.find(propName); + + if(result != properties.end()) + return (*result).second; + else + return NULL; +}