ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/StuntDouble.cpp
(Generate patch)

Comparing trunk/OOPSE/libmdtools/StuntDouble.cpp (file contents):
Revision 1097 by gezelter, Mon Apr 12 20:32:20 2004 UTC vs.
Revision 1452 by tim, Mon Aug 23 15:11:36 2004 UTC

# Line 25 | Line 25
25  
26   */
27  
28 + StuntDouble::~StuntDouble(){
29 +  map<string, GenericData*>::iterator iter;
30 +
31 +  for(iter = properties.begin(); iter != properties.end(); ++iter ){
32 +    delete iter->second;
33 +    properties.erase(iter);
34 +  }
35 +    
36 + }
37 +
38   int StuntDouble::getObjType(){
39    return objType;
40   }
# Line 128 | Line 138 | void StuntDouble::setVel(double vel[3]){
138   }
139  
140   void StuntDouble::setVel(double vel[3]){
141 +
142    switch (objType)
143      {
144      case OT_ATOM :
# Line 146 | Line 157 | void StuntDouble::setVel(double vel[3]){
157      }  
158   }
159  
160 + void StuntDouble::setFrc(double frc[3]){
161 +
162 +  switch (objType)
163 +    {
164 +    case OT_ATOM :
165 +    case OT_DATOM:      
166 +      ((Atom*)this)->setFrc(frc);
167 +      break;
168 +    case OT_RIGIDBODY:
169 +      ((RigidBody*)this)->setFrc(frc);
170 +      break;      
171 +    default:
172 +      sprintf( painCave.errMsg,
173 +               "Unrecognized ObjType (%d) in StuntDouble::setFrc.\n",
174 +               objType );
175 +      painCave.isFatal = 1;
176 +      simError();    
177 +    }  
178 + }
179 +
180   void StuntDouble::addFrc(double frc[3]){
181    switch (objType)
182      {
# Line 271 | Line 302 | void StuntDouble::setJ(double j[3]){
302        painCave.isFatal = 1;
303        simError();    
304      }
305 + }
306 +
307 + void StuntDouble::getQ(double q[4] ){
308 +  switch (objType)
309 +    {
310 +    case OT_ATOM:
311 +      sprintf( painCave.errMsg,
312 +               "StuntDouble::getJ was called for a regular atom.\n"
313 +               "\tRegular Atoms don't have angular momentum.  Be smarter.\n");
314 +      painCave.isFatal = 0;
315 +      simError();
316 +      // Return zeros.
317 +      q[0] = 0;
318 +      q[1] = 0;
319 +      q[2] = 0;
320 +      q[3] = 0;
321 +      break;
322 +    case OT_DATOM:
323 +      ((DirectionalAtom*)this)->getQ(q);
324 +    break;
325 +    case OT_RIGIDBODY:
326 +      ((RigidBody*)this)->getQ(q);
327 +    break;
328 +    default:
329 +      sprintf( painCave.errMsg,
330 +               "Unrecognized ObjType (%d) in StuntDouble::getJ.\n",
331 +               objType );
332 +      painCave.isFatal = 1;
333 +      simError();    
334 +  }
335   }
336  
337 + void StuntDouble::setQ(double q[4] ){
338 +  switch (objType)
339 +    {
340 +    case OT_ATOM:
341 +      sprintf( painCave.errMsg,
342 +               "StuntDouble::setJ was called for a regular atom.\n"
343 +               "\tRegular Atoms don't have angular momentum.  Be smarter.\n");
344 +      painCave.isFatal = 1;
345 +      simError();
346 +      break;
347 +    case OT_DATOM:
348 +      ((DirectionalAtom*)this)->setJ(q);
349 +    break;
350 +    case OT_RIGIDBODY:
351 +      ((RigidBody*)this)->setJ(q);
352 +    break;
353 +    default:
354 +      sprintf( painCave.errMsg,
355 +               "Unrecognized ObjType (%d) in StuntDouble::setJ.\n",
356 +               objType );
357 +      painCave.isFatal = 1;
358 +      simError();    
359 +    }
360 + }
361   void StuntDouble::getTrq(double trq[3]){
362    switch (objType)
363      {
# Line 302 | Line 387 | void StuntDouble::getTrq(double trq[3]){
387    }
388   }
389  
390 + void StuntDouble::setTrq(double trq[3]){
391 +  switch (objType)
392 +    {
393 +    case OT_ATOM:
394 +      sprintf( painCave.errMsg,
395 +               "StuntDouble::setTrq was called for a regular atom.\n"
396 +               "\tRegular Atoms don't have torques.  Be smarter.\n");
397 +      painCave.isFatal = 1;
398 +      simError();
399 +      break;
400 +    case OT_DATOM:
401 +      ((DirectionalAtom*)this)->setTrq(trq);
402 +    break;
403 +    case OT_RIGIDBODY:
404 +      ((RigidBody*)this)->setTrq(trq);
405 +    break;
406 +    default:
407 +      sprintf( painCave.errMsg,
408 +               "Unrecognized ObjType (%d) in StuntDouble::addTrq.\n",
409 +               objType );
410 +      painCave.isFatal = 1;
411 +      simError();    
412 +    }
413 + }
414 +
415   void StuntDouble::addTrq(double trq[3]){
416    switch (objType)
417      {
# Line 463 | Line 573 | void StuntDouble::getEulerAngles(double eulers[3]){
573      default:
574        sprintf( painCave.errMsg,
575                 "Unrecognized ObjType (%d) in StuntDouble::getEulerAngles.\n",
576 +               objType );
577 +      painCave.isFatal = 1;
578 +      simError();    
579 +  }
580 + }
581 +
582 + double StuntDouble::getZangle(){
583 +  switch (objType)
584 +    {
585 +    case OT_ATOM:
586 +      sprintf( painCave.errMsg,
587 +               "StuntDouble::getZangle was called for a regular atom.\n"
588 +               "\tRegular Atoms don't have zAngles.  Be smarter.\n");
589 +      painCave.isFatal = 0;
590 +      simError();
591 +      // Return zeros.
592 +      return 0;
593 +      break;
594 +    case OT_DATOM:
595 +      return ((DirectionalAtom*)this)->getZangle();
596 +    break;
597 +    case OT_RIGIDBODY:
598 +      return ((RigidBody*)this)->getZangle();
599 +    break;
600 +    default:
601 +      sprintf( painCave.errMsg,
602 +               "Unrecognized ObjType (%d) in StuntDouble::getZangle.\n",
603                 objType );
604        painCave.isFatal = 1;
605 +      simError();    
606 +      return 0;
607 +  }
608 + }
609 +
610 + void StuntDouble::setZangle(double zAngle){
611 +  switch (objType)
612 +    {
613 +    case OT_ATOM:
614 +      sprintf( painCave.errMsg,
615 +               "StuntDouble::setZangle was called for a regular atom.\n"
616 +               "\tRegular Atoms don't have zAngles.  Be smarter.\n");
617 +      painCave.isFatal = 1;
618 +      simError();
619 +      break;
620 +    case OT_DATOM:
621 +      ((DirectionalAtom*)this)->setZangle(zAngle);
622 +    break;
623 +    case OT_RIGIDBODY:
624 +      ((RigidBody*)this)->setZangle(zAngle);
625 +    break;
626 +    default:
627 +      sprintf( painCave.errMsg,
628 +               "Unrecognized ObjType (%d) in StuntDouble::setZangle.\n",
629 +               objType );
630 +      painCave.isFatal = 1;
631        simError();    
632 +    }
633 + }
634 +
635 + void StuntDouble::addZangle(double zAngle){
636 +  switch (objType)
637 +    {
638 +    case OT_ATOM:
639 +      sprintf( painCave.errMsg,
640 +               "StuntDouble::addZangle was called for a regular atom.\n"
641 +               "\tRegular Atoms don't have zAngles.  Be smarter.\n");
642 +      painCave.isFatal = 1;
643 +      simError();
644 +      break;
645 +    case OT_DATOM:
646 +      ((DirectionalAtom*)this)->addZangle(zAngle);
647 +    break;
648 +    case OT_RIGIDBODY:
649 +      ((RigidBody*)this)->addZangle(zAngle);
650 +    break;
651 +    default:
652 +      sprintf( painCave.errMsg,
653 +               "Unrecognized ObjType (%d) in StuntDouble::addZangle.\n",
654 +               objType );
655 +      painCave.isFatal = 1;
656 +      simError();    
657 +    }
658 + }
659 +
660 + void StuntDouble::addProperty(GenericData* data){
661 +  map<string, GenericData*>::iterator result;
662 +  result = properties.find(data->getID());
663 +  
664 +  //we can't simply use  properties[prop->getID()] = prop,
665 +  //it will cause memory leak if we already contain a propery which has the same name of prop
666 +  
667 +  if(result != properties.end()){
668 +    delete (*result).second;
669 +    (*result).second = data;      
670    }
671 +  else
672 +    properties[data->getID()] = data;
673 +
674 +  
675   }
676 + void StuntDouble::removeProperty(const string& propName){
677 +  map<string, GenericData*>::iterator result;
678 +    
679 +  result = properties.find(propName);
680 +  
681 +  if(result != properties.end()){
682 +    delete result->second;
683 +    properties.erase(result);
684 +    
685 +  }
686 +  
687 + }
688 + GenericData* StuntDouble::getProperty(const string& propName){
689 +  map<string, GenericData*>::iterator result;
690 +  
691 +  
692 +  result = properties.find(propName);
693 +  
694 +  if(result != properties.end())
695 +    return (*result).second;  
696 +  else  
697 +    return NULL;    
698 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines