Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule.cpp

    r833b15 ra7aebd  
    4949#include "CodePatterns/enumeration.hpp"
    5050#include "CodePatterns/Log.hpp"
     51#include "CodePatterns/Observer/Notification.hpp"
    5152#include "config.hpp"
    5253#include "Descriptors/AtomIdDescriptor.hpp"
     
    146147  OBSERVE;
    147148  if(atomIdPool.reserveId(newNr)){
     149    _lastchangedatom = target;
    148150    NOTIFY(AtomNrChanged);
    149151    if (oldNr != -1)  // -1 is reserved and indicates no number
     
    207209{
    208210  OBSERVE;
    209   NOTIFY(AtomRemoved);
    210211  const_iterator iter = loc;
    211212  ++iter;
    212213  atom * const _atom = const_cast<atom *>(*loc);
     214  {
     215    _lastchangedatom = _atom;
     216    NOTIFY(AtomRemoved);
     217  }
    213218  atomIds.erase( _atom->getId() );
    214219  {
     
    226231{
    227232  OBSERVE;
    228   NOTIFY(AtomRemoved);
     233  {
     234    _lastchangedatom = key;
     235    NOTIFY(AtomRemoved);
     236  }
    229237  const_iterator iter = find(key);
    230238  if (iter != end()){
     
    247255  OBSERVE;
    248256  NOTIFY(AtomInserted);
     257  _lastchangedatom = key;
    249258  std::pair<iterator,bool> res = atomIds.insert(key->getId());
    250259  if (res.second) { // push atom if went well
     
    637646/** Destroys all atoms inside this molecule.
    638647 */
    639 void molecule::removeAtomsinMolecule()
     648void removeAtomsinMolecule(molecule *&_mol)
    640649{
    641650  // remove each atom from world
    642   for(iterator AtomRunner = begin(); !empty(); AtomRunner = begin())
     651  for(molecule::iterator AtomRunner = _mol->begin(); !_mol->empty(); AtomRunner = _mol->begin())
    643652    World::getInstance().destroyAtom(*AtomRunner);
     653  // make sure that pointer os not usable
     654  _mol = NULL;
    644655};
    645656
     
    974985    for(const_iterator iter = begin(); iter != end(); ++iter)
    975986      center += (*iter)->getPosition();
    976     center *= 1./(double)size();
     987    if (begin() != end())
     988      center *= 1./(double)size();
    977989    for(const_iterator iter = begin(); iter != end(); ++iter) {
    978990      const Vector &position = (*iter)->getPosition();
     
    9951007}
    9961008
     1009void molecule::update(Observable *publisher)
     1010{
     1011  ASSERT(0, "molecule::update() - did not sign on for any general updates.");
     1012}
     1013
     1014void molecule::recieveNotification(Observable *publisher, Notification_ptr notification)
     1015{
     1016  const atom * const _atom = dynamic_cast<atom *>(publisher);
     1017  if ((_atom != NULL) && containsAtom(_atom)) {
     1018#ifdef LOG_OBSERVER
     1019    observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(static_cast<Observer *>(this))
     1020          << " received notification from atom " << _atom->getId() << " for channel "
     1021          << notification->getChannelNo() << ".";
     1022#endif
     1023    switch (notification->getChannelNo()) {
     1024      case AtomObservable::PositionChanged:
     1025      {
     1026        // emit others about one of our atoms moved
     1027        _lastchangedatom = const_cast<atom *>(_atom);
     1028        OBSERVE;
     1029        NOTIFY(AtomMoved);
     1030        break;
     1031      }
     1032      default:
     1033        ASSERT( 0, "molecule::recieveNotification() - we did not sign up for channel "
     1034            +toString(notification->getChannelNo()));
     1035        break;
     1036    }
     1037  }
     1038}
     1039
     1040void molecule::subjectKilled(Observable *publisher)
     1041{
     1042  // do nothing, atom does it all
     1043}
     1044
     1045
    9971046// construct idpool
    9981047CONSTRUCT_IDPOOL(atomId_t, continuousId)
Note: See TracChangeset for help on using the changeset viewer.