Changes in / [d26fb7:2f429e]


Ignore:
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/AtomAction/AddAction.cpp

    rd26fb7 r2f429e  
    5555#include "Action_impl_pre.hpp"
    5656/** =========== define the function ====================== */
    57 
    58 atom * getNewAtom(const AtomAddAction::AtomAddParameters &_params)
    59 {
    60   atom * first = World::getInstance().createAtom();
    61   first->setType(_params.elemental.get());
    62   first->setPosition(_params.position.get());
    63 
    64   return first;
    65 }
    66 
    67 std::vector<atomId_t> createAtoms(
    68     const AtomAddAction::AtomAddParameters &_params,
    69     std::vector<molecule *> &_molecules)
    70 {
    71   std::vector<atomId_t> ids;
    72   if (!_molecules.empty()) {
    73     if (_molecules.size() == 1) {
    74         atom *first = getNewAtom(_params);
    75         molecule *mol = *_molecules.begin();
    76         LOG(1, "Adding new atom with element " << first->getType()->getName()
    77             << " at " << (first->getPosition()) << " to selected molecule "
    78             << mol->getName()+".");
    79         mol->AddAtom(first);
    80       ids.push_back(first->getId());
    81     }
    82   } else {
    83     atom *first = getNewAtom(_params);
    84     molecule *mol = World::getInstance().createMolecule();
    85     mol->setName("none");
    86     mol->AddAtom(first);
    87     LOG(1, "Adding new atom with element " << first->getType()->getName()
    88         << " at " << (first->getPosition()) << " to new molecule.");
    89     ids.push_back(first->getId());
    90   }
    91 
    92   return ids;
    93 }
    94 
    9557ActionState::ptr AtomAddAction::performCall() {
    9658  // execute action
    97   std::vector<molecule *> molecules = World::getInstance().getSelectedMolecules();
    98   std::vector<atomId_t> ids = createAtoms(params, molecules);
    99 
    100   if (molecules.size() > 1)
    101      return Action::failure;
    102   else
    103     return ActionState::ptr(new AtomAddState(ids, params));
     59  atom * first = World::getInstance().createAtom();
     60  first->setType(params.elemental.get());
     61  first->setPosition(params.position.get());
     62  LOG(1, "Adding new atom with element " << first->getType()->getName() << " at " << (first->getPosition()) << ".");
     63  // TODO: remove when all of World's atoms are stored.
     64  std::vector<molecule *> molecules = World::getInstance().getAllMolecules();
     65  if (!molecules.empty()) {
     66    std::vector<molecule *>::iterator iter = molecules.begin();
     67    (*iter)->AddAtom(first);
     68  }
     69  return ActionState::ptr(new AtomAddState(first->getId(), params));
    10470}
    10571
     
    10773  AtomAddState *state = assert_cast<AtomAddState*>(_state.get());
    10874
    109   for (std::vector<atomId_t>::const_iterator iter = state->ids.begin();
    110       iter != state->ids.end(); ++iter) {
    111     LOG(1, "Removing atom with id " << *iter << ".");
    112     World::getInstance().destroyAtom(*iter);
    113   }
     75  LOG(1, "Removing atom with id " << state->id << ".");
     76  World::getInstance().destroyAtom(state->id);
    11477
    11578  return ActionState::ptr(_state);
     
    11982  AtomAddState *state = assert_cast<AtomAddState*>(_state.get());
    12083
    121   std::vector<molecule *> molecules = World::getInstance().getSelectedMolecules();
    122   std::vector<atomId_t> newids = createAtoms(params, molecules);
     84  atom * first = World::getInstance().createAtom();
     85  first->setType(state->params.elemental.get());
     86  first->setPosition(state->params.position.get());
     87  LOG(1, "Re-adding new atom with element " << state->params.elemental.get()->getName() << " at " << state->params.position.get() << ".");
     88  // TODO: remove when all of World's atoms are stored.
     89  std::vector<molecule *> molecules = World::getInstance().getAllMolecules();
     90  if (!molecules.empty()) {
     91    std::vector<molecule *>::iterator iter = molecules.begin();
     92    (*iter)->AddAtom(first);
     93  }
     94  if (first->getId() != state->id)
     95    if (!first->changeId(state->id)) {
     96      STATUS("Could not change atom id "+toString(first->getId())+"->"+toString(state->id)+".");
     97      return Action::failure;
     98    }
    12399
    124   if (newids.size() != state->ids.size()) {
    125     STATUS("Could not recreate all atoms after undo.");
    126     for (std::vector<atomId_t>::const_iterator iter = newids.begin(); iter != newids.end();++iter)
    127       World::getInstance().destroyAtom(*iter);
    128     return Action::failure;
    129   }
    130 
    131   std::vector<atomId_t>::const_iterator newiter = newids.begin();
    132   std::vector<atomId_t>::const_iterator olditer = state->ids.begin();
    133   bool status=true;
    134   for (; newiter != newids.end(); ++newiter, ++olditer) {
    135     atom * first = World::getInstance().getAtom(AtomById(*newiter));
    136     ASSERT( first != NULL,
    137         "AtomAddAction::performRedo() - re-created atom not present?");
    138     if (first->getId() != *olditer)
    139       if (!first->changeId(*olditer)) {
    140         STATUS("Could not change atom id "+toString(first->getId())+"->"+toString(*olditer)+".");
    141         // remove all created atoms
    142         for (std::vector<atomId_t>::const_iterator iter = state->ids.begin(); iter != olditer;++iter)
    143           World::getInstance().destroyAtom(*iter);
    144         olditer = state->ids.end();
    145         for (std::vector<atomId_t>::const_iterator iter = newiter; iter != newids.end();++iter)
    146           World::getInstance().destroyAtom(*iter);
    147         status = false;
    148         break;
    149       }
    150   }
    151   ASSERT( olditer == state->ids.end(),
    152       "AtomAddAction::performRedo() - after all unequal amount of ids in new and old?");
    153 
    154   if (!status) {
    155     return Action::failure;
    156   } else
    157     return ActionState::ptr(_state);
     100  return ActionState::ptr(_state);
    158101}
    159102
  • src/Actions/AtomAction/AddAction.def

    rd26fb7 r2f429e  
    2727(BoxVectorValidator())
    2828
    29 #define statetypes (std::vector<atomId_t>)
    30 #define statereferences (ids)
     29#define statetypes (const atomId_t)
     30#define statereferences (id)
    3131
    3232// some defines for all the names, you may use ACTION, STATE and PARAMS
  • src/Atom/atom.cpp

    rd26fb7 r2f429e  
    264264  // first we move ourselves in the world
    265265  // the world lets us know if that succeeded
    266   atomId_t oldid = id;
    267266  if(world->changeAtomId(id,newId,this)){
    268267    OBSERVE;
    269268    id = newId;
    270     if (mol != NULL)
    271       mol->changeAtomId(oldid, newId);
    272269    NOTIFY(IndexChanged);
    273270    return true;
  • src/Graph/BondGraph.hpp

    rd26fb7 r2f429e  
    221221              neighboriter != ListOfNeighbors.end();
    222222              ++neighboriter) {
    223             const atom * const OtherWalker = dynamic_cast<const atom *>(*neighboriter);
    224             ASSERT(OtherWalker != NULL,
    225                 "BondGraph::CreateAdjacency() - TesselPoint "
    226                 +(*neighboriter)->getName()+" that was not an atom retrieved from LinkedList");
    227             if (OtherWalker->getId() > Walker->getId()) {  // just to not add bonds from both sides
     223            if ((*neighboriter) > Walker) {  // just to not add bonds from both sides
     224              const atom * const OtherWalker = dynamic_cast<const atom *>(*neighboriter);
     225              ASSERT(OtherWalker != NULL,
     226                  "BondGraph::CreateAdjacency() - TesselPoint "
     227                  +(*neighboriter)->getName()+" that was not an atom retrieved from LinkedList");
    228228              LOG(4, "INFO: Current other atom is " << *OtherWalker << ".");
    229229
     
    245245              }
    246246            } else {
    247               LOG(4, "REJECT: Not Adding: Wrong order.");
     247              LOG(5, "REJECT: Not Adding: Wrong order.");
    248248            }
    249249          }
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.cpp

    rd26fb7 r2f429e  
    8585const Observable::channels_t GLMoleculeObject_molecule::AtomsChannels(getAtomsChannels());
    8686const Observable::channels_t GLMoleculeObject_molecule::HullChannels(getAllAtomicChangesChannels());
    87 const Observable::channels_t GLMoleculeObject_molecule::BoundingBoxChannels(1, molecule::BoundingBoxChanged);
     87const Observable::channels_t GLMoleculeObject_molecule::BoundingBoxChannels(getAllAtomicChangesChannels());
    8888const Observable::channels_t GLMoleculeObject_molecule::IndexChannels(1, molecule::IndexChanged);
    8989const Observable::channels_t GLMoleculeObject_molecule::NameChannels(1, molecule::MoleculeNameChanged);
     
    403403}
    404404
    405 molecule::BoundingBoxInfo GLMoleculeObject_molecule::initBoundingBox() const
    406 {
    407   molecule::BoundingBoxInfo info;
     405GLMoleculeObject_molecule::BoundingBoxInfo GLMoleculeObject_molecule::initBoundingBox() const
     406{
     407  BoundingBoxInfo info;
    408408  info.position = zeroVec;
    409409  info.radius = 0.;
     
    411411}
    412412
    413 molecule::BoundingBoxInfo GLMoleculeObject_molecule::updateBoundingBox() const
    414 {
    415   molecule::BoundingBoxInfo info = BoundingBox.get();
     413GLMoleculeObject_molecule::BoundingBoxInfo GLMoleculeObject_molecule::updateBoundingBox() const
     414{
     415  BoundingBoxInfo info = BoundingBox.get();
    416416  const molecule * const _molecule = getMolecule(MolIndex.get());
    417417  if (_molecule != NULL) {
     
    472472void GLMoleculeObject_molecule::resetBoundingBox()
    473473{
    474   molecule::BoundingBoxInfo info = BoundingBox.get();
     474  BoundingBoxInfo info = BoundingBox.get();
    475475  setPosition(QVector3D(info.position[0], info.position[1], info.position[2]));
    476476  setScale(info.radius + 0.3); // getBoundingSphere() only sees atoms as points, so make the box a bit bigger
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.hpp

    rd26fb7 r2f429e  
    2424#include "GLMoleculeObject_bond.hpp"
    2525
    26 #include "molecule.hpp"
    27 
    2826class atom;
    2927class bond;
    3028class GLMoleculeObject_atom;
    3129class GLWorldScene;
     30class molecule;
    3231
    3332class GLMoleculeObject_molecule : public GLMoleculeObject, public Observer
     
    110109  typedef std::set<atomId_t> atoms_t;
    111110
    112   molecule::BoundingBoxInfo initBoundingBox() const;
     111  /** Structure for the required information on the bounding box.
     112   *
     113   */
     114  struct BoundingBoxInfo {
     115    //!> position of center
     116    Vector position;
     117    //!> radius of sphere
     118    double radius;
     119  };
     120
     121  /** Structure for the required information on the tesselation hull.
     122   *
     123   */
     124  struct TesselationHullInfo {
     125  };
     126
     127  BoundingBoxInfo initBoundingBox() const;
    113128
    114129  QGeometryData updateTesselationHull() const;
    115   molecule::BoundingBoxInfo updateBoundingBox() const;
     130  BoundingBoxInfo updateBoundingBox() const;
    116131  atoms_t updateAtoms();
    117132  moleculeId_t updateIndex() const;
     
    138153  boost::function<std::string ()> MolNameUpdater;
    139154  boost::function<QGeometryData ()> TesselationHullUpdater;
    140   boost::function<molecule::BoundingBoxInfo ()> BoundingBoxUpdater;
     155  boost::function<BoundingBoxInfo ()> BoundingBoxUpdater;
    141156  boost::function<atoms_t ()> PresentAtomsUpdater;
    142157
     
    148163  Cacheable<QGeometryData> TesselationHull;
    149164  //!> contains newest version of the bounding box on request
    150   ObservedValue<molecule::BoundingBoxInfo> BoundingBox;
     165  ObservedValue<BoundingBoxInfo> BoundingBox;
    151166  //!> contains the current live set of atoms for the molecule
    152167  ObservedValue<atoms_t> PresentAtoms;
  • src/World.cpp

    rd26fb7 r2f429e  
    396396  if (isAtomSelected(id))
    397397    selectedAtoms.erase(id);
     398  atoms.erase(id);
    398399  DeleteAtom(atom);
    399   atoms.erase(id);
    400400  atomIdPool.releaseId(id);
    401401  // remove molecule if empty
  • src/molecule.cpp

    rd26fb7 r2f429e  
    3636
    3737#include <algorithm>
    38 #include <boost/assign.hpp>
    3938#include <boost/bind.hpp>
    4039#include <boost/foreach.hpp>
     
    5150#include "CodePatterns/enumeration.hpp"
    5251#include "CodePatterns/Log.hpp"
    53 #include "CodePatterns/Observer/Observable.hpp"
    5452#include "CodePatterns/Observer/Notification.hpp"
    5553#include "config.hpp"
     
    6967#include "WorldTime.hpp"
    7068
    71 using namespace boost::assign;
    72 
    73 // static entities
    74 static Observable::channels_t getBoundingBoxChannels()
    75 {
    76   Observable::channels_t channels;
    77   channels += molecule::AtomInserted, molecule::AtomRemoved, molecule::AtomMoved;
    78   return channels;
    79 }
    8069
    8170/************************************* Functions for class molecule *********************************/
     
    9483  BondCount(this,boost::bind(&molecule::doCountBonds,this),"BondCount"),
    9584  atomIdPool(1, 20, 100),
    96   BoundingBoxSweepingAxis(std::vector<AtomDistanceMap_t>(NDIM)),
    9785  _lastchangedatomid(-1),
    9886  last_atom(0)
     
    10492    OurChannel->addChannel(type);
    10593
    106   // cannot initialize in initializer body as then channels have not been setup yet
    107   BoundingBox.reset(
    108       new Cacheable<BoundingBoxInfo>(
    109           this, boost::bind(&molecule::updateBoundingBox, boost::cref(this)), "molecule_BoundingBox", getBoundingBoxChannels()));
    110 
    11194  strcpy(name,World::getInstance().getDefaultName().c_str());
    112 }
     95};
    11396
    11497molecule *NewMolecule(){
     
    187170}
    188171
    189 bool molecule::changeAtomId(int oldId, int newId)
    190 {
    191   OBSERVE;
    192   if ((!atomIds.contains( oldId )) || (atomIds.contains( newId )))
    193     return false;
    194   atomIds.erase( oldId );
    195   atomIds.insert( newId );
    196   // also update BoundingBoxSweepingAxis
    197   for (int i=0;i<NDIM;++i) {
    198     AtomDistanceMap_t::left_iterator iter = BoundingBoxSweepingAxis[i].left.find(oldId);
    199     ASSERT(iter != BoundingBoxSweepingAxis[i].left.end(),
    200         "molecule::changeAtomId() - could not find atom "+toString(oldId)
    201         +" in BoundingBoxSweepingAxis.");
    202     const double component = iter->second;
    203     BoundingBoxSweepingAxis[i].left.erase(iter);
    204     BoundingBoxSweepingAxis[i].left.insert( std::make_pair(newId, component) );
    205   }
    206   return true;
    207 }
    208 
    209172bool molecule::changeId(moleculeId_t newId){
    210173  // first we move ourselves in the world
     
    264227  atomIds.erase( _atom->getId() );
    265228  {
    266     BoundingBoxInfo oldinfo = updateBoundingBox();
    267     for (int i=0;i<NDIM;++i)
    268       BoundingBoxSweepingAxis[i].left.erase( _atom->getId() );
    269     BoundingBoxInfo newinfo = updateBoundingBox();
    270     if (oldinfo != newinfo)
    271       NOTIFY(BoundingBoxChanged);
    272   }
    273   {
    274229    NOTIFY(AtomNrChanged);
    275230    atomIdPool.releaseId(_atom->getNr());
     
    285240molecule::const_iterator molecule::erase( atom * key )
    286241{
     242  OBSERVE;
     243  {
     244    _lastchangedatomid = key->getId();
     245    NOTIFY(AtomRemoved);
     246  }
    287247  const_iterator iter = const_cast<const molecule &>(*this).find(key);
    288   if (iter != const_cast<const molecule &>(*this).end())
    289     return erase(iter);
    290   else
    291     return iter;
     248  if (iter != const_cast<const molecule &>(*this).end()){
     249    ++iter;
     250    atomIds.erase( key->getId() );
     251    {
     252      NOTIFY(AtomNrChanged);
     253      atomIdPool.releaseId(key->getNr());
     254      LocalToGlobalId.erase(key->getNr());
     255      key->setNr(-1);
     256    }
     257    NOTIFY(FormulaChanged);
     258    formula-=key->getType();
     259    key->removeFromMolecule();
     260  }
     261  return iter;
    292262}
    293263
     
    299269  std::pair<iterator,bool> res = atomIds.insert(key->getId());
    300270  if (res.second) { // push atom if went well
    301     {
    302       BoundingBoxInfo oldinfo = updateBoundingBox();
    303       for (int i=0;i<NDIM;++i)
    304         BoundingBoxSweepingAxis[i].left.insert( std::make_pair(key->getId(), key->getPosition()[i]));
    305       BoundingBoxInfo newinfo = updateBoundingBox();
    306       if (oldinfo != newinfo)
    307         NOTIFY(BoundingBoxChanged);
    308     }
    309271    NOTIFY(AtomNrChanged);
    310272    key->setNr(atomIdPool.getNextId());
     
    10761038}
    10771039
    1078 molecule::BoundingBoxInfo molecule::updateBoundingBox() const
    1079 {
    1080   BoundingBoxInfo info;
    1081   Vector min = zeroVec;
    1082   Vector max = zeroVec;
    1083   for (int i=0;i<NDIM;++i) {
    1084     if (!BoundingBoxSweepingAxis[i].right.empty()) {
    1085       min[i] = BoundingBoxSweepingAxis[i].right.begin()->first;
    1086       max[i] = BoundingBoxSweepingAxis[i].right.rbegin()->first;
    1087     }
    1088   }
    1089   info.radius = (.5*(max-min)).Norm();
    1090   info.position = .5*(max+min);
    1091   return info;
    1092 }
    1093 
    1094 molecule::BoundingBoxInfo molecule::getBoundingBox() const
    1095 {
    1096   return **BoundingBox;
    1097 }
    1098 
    10991040void molecule::update(Observable *publisher)
    11001041{
     
    11161057        // emit others about one of our atoms moved
    11171058        _lastchangedatomid = _atom->getId();
    1118         // update entry in map
    1119         BoundingBoxInfo oldinfo = updateBoundingBox();
    1120         for (int i=0;i<NDIM;++i) {
    1121           AtomDistanceMap_t::left_iterator iter = BoundingBoxSweepingAxis[i].left.find(_atom->getId());
    1122           ASSERT(iter != BoundingBoxSweepingAxis[i].left.end(),
    1123               "molecule::recieveNotification() - could not find atom "+toString(_atom->getId())
    1124               +" in BoundingBoxSweepingAxis.");
    1125           BoundingBoxSweepingAxis[i].left.erase(iter);
    1126           BoundingBoxSweepingAxis[i].left.insert(
    1127               std::make_pair(_atom->getId(), _atom->getPosition()[i]) );
    1128         }
    1129         BoundingBoxInfo newinfo = updateBoundingBox();
    11301059        OBSERVE;
    11311060        NOTIFY(AtomMoved);
    1132         if (oldinfo != newinfo)
    1133           NOTIFY(BoundingBoxChanged);
    11341061        break;
    11351062      }
  • src/molecule.hpp

    rd26fb7 r2f429e  
    2222
    2323#include <string>
    24 
    25 #include <boost/bimap/bimap.hpp>
    26 #include <boost/bimap/unordered_set_of.hpp>
    27 #include <boost/bimap/multiset_of.hpp>
    28 #include <boost/optional.hpp>
    29 #include <boost/shared_ptr.hpp>
    3024
    3125#include "AtomIdSet.hpp"
     
    121115    MoleculeNameChanged,
    122116    IndexChanged,
    123     BoundingBoxChanged,
    124117    AboutToBeRemoved,
    125118    NotificationType_MAX
     
    245238  bool changeAtomNr(int oldNr, int newNr, atom* target=0);
    246239
    247   friend bool atom::changeId(atomId_t newId);
    248   /**
    249    * used when changing an ParticleInfo::Id.
    250    * Note that this number is global (and the molecule uses it to know which atoms belong to it)
    251    *
    252    * @param oldId old Id
    253    * @param newId new Id to set
    254    * @return indicates wether the change could be done or not.
    255    */
    256   bool changeAtomId(int oldId, int newId);
    257 
    258240  /** Updates the internal lookup fro local to global indices.
    259241   *
     
    278260
    279261public:
    280 
    281   /** Structure for the required information on the bounding box.
    282    *
    283    */
    284   struct BoundingBoxInfo {
    285     //!> position of center
    286     Vector position;
    287     //!> radius of sphere
    288     double radius;
    289 
    290     /** Equivalence operator for bounding box.
    291      *
    292      * \return true - both bounding boxes have same position and radius
    293      */
    294     bool operator==(const BoundingBoxInfo &_other) const
    295     {  return (radius == _other.radius) && (position == _other.position); }
    296 
    297     /** Inequivalence operator for bounding box.
    298      *
    299      * \return true - bounding boxes have either different positions or different radii or both
    300      */
    301     bool operator!=(const BoundingBoxInfo &_other) const
    302     { return !(*this == _other); }
    303   };
    304 
    305 private:
    306 
    307   /** Returns the current bounding box.
    308    *
    309    * \return Shape with center and extension of box
    310    */
    311   BoundingBoxInfo updateBoundingBox() const;
    312 
    313   // stuff for keeping bounding box up-to-date efficiently
    314 
    315   //!> Cacheable for the bounding box, ptr such that
    316   boost::shared_ptr< Cacheable<BoundingBoxInfo> > BoundingBox;
    317   /** Bimap storing atomic ids and the component per axis.
    318    *
    319    * We need a bimap in order to have the components sorted and be able to
    320    * access max and min values in linear time and also access the ids in
    321    * constant time in order to update the map, when atoms move, are inserted,
    322    * or removed.
    323    */
    324   typedef boost::bimaps::bimap<
    325           boost::bimaps::unordered_set_of< atomId_t >,
    326           boost::bimaps::multiset_of< double, std::greater<double> >
    327       > AtomDistanceMap_t;
    328   std::vector<AtomDistanceMap_t> BoundingBoxSweepingAxis;
    329 
    330 public:
    331 
    332   /** Returns the current bounding box of this molecule.
    333    *
    334    * \return bounding box info with center and radius
    335    */
    336   BoundingBoxInfo getBoundingBox() const;
    337262
    338263  /** Function to create a bounding spherical shape for the currently associated atoms.
  • tests/regression/Atoms/Add/post/test.pdb

    rd26fb7 r2f429e  
    11REMARK created by molecuilder on Wed Feb  2 18:06:07 2011
    2 ATOM      1 H01 0non 01         10.000  10.000  10.000  0.00  0.00           H 0
     2ATOM      1 H01 0-   00         10.000  10.000  10.000  0.00  0.00           H 0
    33END
Note: See TracChangeset for help on using the changeset viewer.