| [bcf653] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
| [0aa122] | 4 |  * Copyright (C)  2010-2012 University of Bonn. All rights reserved.
 | 
|---|
| [5aaa43] | 5 |  * Copyright (C)  2013 Frederik Heber. All rights reserved.
 | 
|---|
| [94d5ac6] | 6 |  * 
 | 
|---|
 | 7 |  *
 | 
|---|
 | 8 |  *   This file is part of MoleCuilder.
 | 
|---|
 | 9 |  *
 | 
|---|
 | 10 |  *    MoleCuilder is free software: you can redistribute it and/or modify
 | 
|---|
 | 11 |  *    it under the terms of the GNU General Public License as published by
 | 
|---|
 | 12 |  *    the Free Software Foundation, either version 2 of the License, or
 | 
|---|
 | 13 |  *    (at your option) any later version.
 | 
|---|
 | 14 |  *
 | 
|---|
 | 15 |  *    MoleCuilder is distributed in the hope that it will be useful,
 | 
|---|
 | 16 |  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
 | 17 |  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
 | 18 |  *    GNU General Public License for more details.
 | 
|---|
 | 19 |  *
 | 
|---|
 | 20 |  *    You should have received a copy of the GNU General Public License
 | 
|---|
 | 21 |  *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
 | 
|---|
| [bcf653] | 22 |  */
 | 
|---|
 | 23 | 
 | 
|---|
| [5d1611] | 24 | /*
 | 
|---|
 | 25 |  * World.cpp
 | 
|---|
 | 26 |  *
 | 
|---|
 | 27 |  *  Created on: Feb 3, 2010
 | 
|---|
 | 28 |  *      Author: crueger
 | 
|---|
 | 29 |  */
 | 
|---|
 | 30 | 
 | 
|---|
| [bf3817] | 31 | // include config.h
 | 
|---|
 | 32 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 33 | #include <config.h>
 | 
|---|
 | 34 | #endif
 | 
|---|
 | 35 | 
 | 
|---|
| [ad011c] | 36 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| [112b09] | 37 | 
 | 
|---|
| [5d1611] | 38 | #include "World.hpp"
 | 
|---|
 | 39 | 
 | 
|---|
| [90c4280] | 40 | #include <functional>
 | 
|---|
| [5d1611] | 41 | 
 | 
|---|
| [3139b2] | 42 | #include "Actions/ActionTrait.hpp"
 | 
|---|
| [d297a3] | 43 | #include "Actions/ManipulateAtomsProcess.hpp"
 | 
|---|
| [6f0841] | 44 | #include "Atom/atom.hpp"
 | 
|---|
| [d297a3] | 45 | #include "Box.hpp"
 | 
|---|
 | 46 | #include "CodePatterns/Assert.hpp"
 | 
|---|
| [8e1f7af] | 47 | #include "config.hpp"
 | 
|---|
| [fc1b24] | 48 | #include "Descriptors/AtomDescriptor.hpp"
 | 
|---|
| [865a945] | 49 | #include "Descriptors/AtomDescriptor_impl.hpp"
 | 
|---|
| [ebc499] | 50 | #include "Descriptors/AtomSelectionDescriptor.hpp"
 | 
|---|
| [1c51c8] | 51 | #include "Descriptors/MoleculeDescriptor.hpp"
 | 
|---|
 | 52 | #include "Descriptors/MoleculeDescriptor_impl.hpp"
 | 
|---|
| [ebc499] | 53 | #include "Descriptors/MoleculeSelectionDescriptor.hpp"
 | 
|---|
| [feb5d0] | 54 | #include "Descriptors/SelectiveConstIterator_impl.hpp"
 | 
|---|
| [6e97e5] | 55 | #include "Descriptors/SelectiveIterator_impl.hpp"
 | 
|---|
| [42127c] | 56 | #include "Element/periodentafel.hpp"
 | 
|---|
| [98dbee] | 57 | #include "Fragmentation/Homology/HomologyContainer.hpp"
 | 
|---|
| [3139b2] | 58 | #include "Graph/BondGraph.hpp"
 | 
|---|
| [4b8630] | 59 | #include "Graph/DepthFirstSearchAnalysis.hpp"
 | 
|---|
| [e4fe8d] | 60 | #include "Helpers/defs.hpp"
 | 
|---|
| [d297a3] | 61 | #include "LinearAlgebra/RealSpaceMatrix.hpp"
 | 
|---|
| [4834f4] | 62 | #include "LinkedCell/LinkedCell_Controller.hpp"
 | 
|---|
 | 63 | #include "LinkedCell/PointCloudAdaptor.hpp"
 | 
|---|
| [d297a3] | 64 | #include "molecule.hpp"
 | 
|---|
| [42127c] | 65 | #include "MoleculeListClass.hpp"
 | 
|---|
| [ab26c3] | 66 | #include "Thermostats/ThermoStatContainer.hpp"
 | 
|---|
| [d297a3] | 67 | #include "WorldTime.hpp"
 | 
|---|
| [d346b6] | 68 | 
 | 
|---|
| [3e4fb6] | 69 | #include "IdPool_impl.hpp"
 | 
|---|
 | 70 | 
 | 
|---|
| [4834f4] | 71 | #include "CodePatterns/IteratorAdaptors.hpp"
 | 
|---|
| [ad011c] | 72 | #include "CodePatterns/Singleton_impl.hpp"
 | 
|---|
| [02ce36] | 73 | #include "CodePatterns/Observer/Channels.hpp"
 | 
|---|
 | 74 | #include "CodePatterns/Observer/ObservedContainer_impl.hpp"
 | 
|---|
| [23b547] | 75 | 
 | 
|---|
| [ce7fdc] | 76 | using namespace MoleCuilder;
 | 
|---|
| [4d9c01] | 77 | 
 | 
|---|
| [7188b1] | 78 | /******************************* Notifications ************************/
 | 
|---|
 | 79 | 
 | 
|---|
 | 80 | 
 | 
|---|
 | 81 | atom* World::_lastchangedatom = NULL;
 | 
|---|
 | 82 | molecule* World::_lastchangedmol = NULL;
 | 
|---|
 | 83 | 
 | 
|---|
| [5d1611] | 84 | /******************************* getter and setter ************************/
 | 
|---|
| [f71baf] | 85 | periodentafel *&World::getPeriode()
 | 
|---|
 | 86 | {
 | 
|---|
| [5d1611] | 87 |   return periode;
 | 
|---|
 | 88 | }
 | 
|---|
 | 89 | 
 | 
|---|
| [f71baf] | 90 | BondGraph *&World::getBondGraph()
 | 
|---|
 | 91 | {
 | 
|---|
 | 92 |   return BG;
 | 
|---|
 | 93 | }
 | 
|---|
 | 94 | 
 | 
|---|
| [98dbee] | 95 | HomologyContainer &World::getHomologies()
 | 
|---|
 | 96 | {
 | 
|---|
 | 97 |   return *homologies;
 | 
|---|
 | 98 | }
 | 
|---|
 | 99 | 
 | 
|---|
 | 100 | void World::resetHomologies(HomologyContainer *&_homologies)
 | 
|---|
 | 101 | {
 | 
|---|
 | 102 |   HomologyContainer *oldhomologies = homologies;
 | 
|---|
 | 103 | 
 | 
|---|
 | 104 |   // install new instance, resetting given pointer
 | 
|---|
 | 105 |   homologies = _homologies;
 | 
|---|
 | 106 |   _homologies = NULL;
 | 
|---|
 | 107 | 
 | 
|---|
 | 108 |   // delete old instance which also informs all observers
 | 
|---|
 | 109 |   delete oldhomologies;
 | 
|---|
 | 110 | }
 | 
|---|
 | 111 | 
 | 
|---|
| [f71baf] | 112 | void World::setBondGraph(BondGraph *_BG){
 | 
|---|
 | 113 |   delete (BG);
 | 
|---|
 | 114 |   BG = _BG;
 | 
|---|
 | 115 | }
 | 
|---|
 | 116 | 
 | 
|---|
| [8e1f7af] | 117 | config *&World::getConfig(){
 | 
|---|
 | 118 |   return configuration;
 | 
|---|
 | 119 | }
 | 
|---|
 | 120 | 
 | 
|---|
| [1c51c8] | 121 | // Atoms
 | 
|---|
 | 122 | 
 | 
|---|
| [7a1ce5] | 123 | atom* World::getAtom(AtomDescriptor descriptor){
 | 
|---|
| [fc1b24] | 124 |   return descriptor.find();
 | 
|---|
 | 125 | }
 | 
|---|
 | 126 | 
 | 
|---|
| [4d72e4] | 127 | World::AtomComposite World::getAllAtoms(AtomDescriptor descriptor){
 | 
|---|
| [fc1b24] | 128 |   return descriptor.findAll();
 | 
|---|
 | 129 | }
 | 
|---|
 | 130 | 
 | 
|---|
| [4d72e4] | 131 | World::AtomComposite World::getAllAtoms(){
 | 
|---|
| [0e2a47] | 132 |   return getAllAtoms(AllAtoms());
 | 
|---|
 | 133 | }
 | 
|---|
 | 134 | 
 | 
|---|
| [354859] | 135 | int World::numAtoms(){
 | 
|---|
 | 136 |   return atoms.size();
 | 
|---|
 | 137 | }
 | 
|---|
 | 138 | 
 | 
|---|
| [1c51c8] | 139 | // Molecules
 | 
|---|
 | 140 | 
 | 
|---|
 | 141 | molecule *World::getMolecule(MoleculeDescriptor descriptor){
 | 
|---|
 | 142 |   return descriptor.find();
 | 
|---|
 | 143 | }
 | 
|---|
 | 144 | 
 | 
|---|
 | 145 | std::vector<molecule*> World::getAllMolecules(MoleculeDescriptor descriptor){
 | 
|---|
 | 146 |   return descriptor.findAll();
 | 
|---|
 | 147 | }
 | 
|---|
 | 148 | 
 | 
|---|
| [97ebf8] | 149 | std::vector<molecule*> World::getAllMolecules(){
 | 
|---|
 | 150 |   return getAllMolecules(AllMolecules());
 | 
|---|
 | 151 | }
 | 
|---|
 | 152 | 
 | 
|---|
| [354859] | 153 | int World::numMolecules(){
 | 
|---|
 | 154 |   return molecules_deprecated->ListOfMolecules.size();
 | 
|---|
 | 155 | }
 | 
|---|
 | 156 | 
 | 
|---|
| [5f612ee] | 157 | // system
 | 
|---|
 | 158 | 
 | 
|---|
| [84c494] | 159 | Box& World::getDomain() {
 | 
|---|
 | 160 |   return *cell_size;
 | 
|---|
 | 161 | }
 | 
|---|
 | 162 | 
 | 
|---|
| [cca9ef] | 163 | void World::setDomain(const RealSpaceMatrix &mat){
 | 
|---|
| [be97a8] | 164 |   OBSERVE;
 | 
|---|
| [84c494] | 165 |   *cell_size = mat;
 | 
|---|
| [5f612ee] | 166 | }
 | 
|---|
 | 167 | 
 | 
|---|
 | 168 | void World::setDomain(double * matrix)
 | 
|---|
 | 169 | {
 | 
|---|
| [b9c847] | 170 |   OBSERVE;
 | 
|---|
| [cca9ef] | 171 |   RealSpaceMatrix M = ReturnFullMatrixforSymmetric(matrix);
 | 
|---|
| [84c494] | 172 |   cell_size->setM(M);
 | 
|---|
| [5f612ee] | 173 | }
 | 
|---|
 | 174 | 
 | 
|---|
| [03abd0] | 175 | LinkedCell::LinkedCell_View World::getLinkedCell(double distance)
 | 
|---|
| [4834f4] | 176 | {
 | 
|---|
| [d067e35] | 177 |   ASSERT( distance >= 0,
 | 
|---|
| [03abd0] | 178 |       "World::getLinkedCell() - distance is not positive.");
 | 
|---|
 | 179 |   if (distance < 1.) {
 | 
|---|
 | 180 |     ELOG(2, "Linked cell grid with length less than 1. is very memory-intense!");
 | 
|---|
 | 181 |     distance = 1.;
 | 
|---|
 | 182 |   }
 | 
|---|
| [4834f4] | 183 |   // we have to grope past the ObservedContainer mechanism and transmorph the map
 | 
|---|
 | 184 |   // into a traversable list for the adaptor
 | 
|---|
 | 185 |   PointCloudAdaptor< AtomSet::set_t, MapValueIterator<AtomSet::set_t::iterator> > atomset(
 | 
|---|
 | 186 |       &(atoms.getContent()),
 | 
|---|
 | 187 |       std::string("WorldsAtoms"));
 | 
|---|
 | 188 |   return LCcontroller->getView(distance, atomset);
 | 
|---|
 | 189 | }
 | 
|---|
 | 190 | 
 | 
|---|
| [2a8731] | 191 | const unsigned World::getTime() const
 | 
|---|
 | 192 | {
 | 
|---|
 | 193 |   return WorldTime::getTime();
 | 
|---|
 | 194 | }
 | 
|---|
 | 195 | 
 | 
|---|
| [388ddd] | 196 | bool areBondsPresent(const unsigned int _step)
 | 
|---|
 | 197 | {
 | 
|---|
 | 198 |   bool status = false;
 | 
|---|
 | 199 | 
 | 
|---|
 | 200 |   for (World::AtomConstIterator iter = const_cast<const World &>(World::getInstance()).getAtomIter();
 | 
|---|
 | 201 |       (!status) && (iter != const_cast<const World &>(World::getInstance()).atomEnd()); ++iter) {
 | 
|---|
 | 202 |     const atom * const Walker = *iter;
 | 
|---|
 | 203 |     status |= !Walker->getListOfBondsAtStep(_step).empty();
 | 
|---|
 | 204 |   }
 | 
|---|
 | 205 | 
 | 
|---|
 | 206 |   return status;
 | 
|---|
 | 207 | }
 | 
|---|
 | 208 | 
 | 
|---|
 | 209 | void copyBondgraph(const unsigned int _srcstep, const unsigned int _deststep)
 | 
|---|
 | 210 | {
 | 
|---|
 | 211 |   // gather all bonds from _srcstep
 | 
|---|
 | 212 |   std::set<bond *> SetOfBonds;
 | 
|---|
 | 213 |   for (World::AtomConstIterator iter = const_cast<const World &>(World::getInstance()).getAtomIter();
 | 
|---|
 | 214 |       iter != const_cast<const World &>(World::getInstance()).atomEnd(); ++iter) {
 | 
|---|
 | 215 |     const atom * const Walker = *iter;
 | 
|---|
 | 216 |     const BondList bonds = Walker->getListOfBondsAtStep(_srcstep);
 | 
|---|
 | 217 |     BOOST_FOREACH( bond::ptr bondptr, bonds) {
 | 
|---|
 | 218 |       SetOfBonds.insert(bondptr.get());
 | 
|---|
 | 219 |     }
 | 
|---|
 | 220 |   }
 | 
|---|
 | 221 |   LOG(4, "DEBUG: We gathered " << SetOfBonds.size() << " bonds in total.");
 | 
|---|
 | 222 | 
 | 
|---|
 | 223 |   // copy bond to new time step
 | 
|---|
 | 224 |   for (std::set<bond *>::const_iterator bonditer = SetOfBonds.begin();
 | 
|---|
 | 225 |       bonditer != SetOfBonds.end(); ++bonditer) {
 | 
|---|
 | 226 |     const atom * const Walker = (*bonditer)->leftatom;
 | 
|---|
 | 227 |     const atom * const OtherWalker = (*bonditer)->rightatom;
 | 
|---|
 | 228 |     const_cast<atom *>(Walker)->addBond(_deststep, const_cast<atom *>(OtherWalker));
 | 
|---|
 | 229 |   }
 | 
|---|
 | 230 | }
 | 
|---|
 | 231 | 
 | 
|---|
| [d297a3] | 232 | void World::setTime(const unsigned int _step)
 | 
|---|
 | 233 | {
 | 
|---|
| [76163d] | 234 |   if (_step != WorldTime::getTime()) {
 | 
|---|
| [388ddd] | 235 |     const unsigned int oldstep = WorldTime::getTime();
 | 
|---|
| [76163d] | 236 |     // set new time
 | 
|---|
| [040a5c] | 237 |     WorldTime::getInstance().setTime(_step);
 | 
|---|
| [4b8630] | 238 |     // TODO: removed when BondGraph creates the adjacency
 | 
|---|
 | 239 |     // 1. remove all of World's molecules
 | 
|---|
 | 240 |     for (MoleculeIterator iter = getMoleculeIter();
 | 
|---|
 | 241 |         getMoleculeIter() != moleculeEnd();
 | 
|---|
 | 242 |         iter = getMoleculeIter()) {
 | 
|---|
 | 243 |       getMolecules()->erase(*iter);
 | 
|---|
 | 244 |       destroyMolecule(*iter);
 | 
|---|
 | 245 |     }
 | 
|---|
| [388ddd] | 246 |     // 2. copy bond graph
 | 
|---|
 | 247 |     if (!areBondsPresent(_step)) {
 | 
|---|
 | 248 | //      AtomComposite Set = getAllAtoms();
 | 
|---|
 | 249 | //      BG->cleanAdjacencyList(Set);
 | 
|---|
 | 250 |       copyBondgraph(oldstep, _step);
 | 
|---|
 | 251 |     }
 | 
|---|
| [4b8630] | 252 | 
 | 
|---|
 | 253 |     // 3. scan for connected subgraphs => molecules
 | 
|---|
 | 254 |     DepthFirstSearchAnalysis DFS;
 | 
|---|
 | 255 |     DFS();
 | 
|---|
 | 256 |     DFS.UpdateMoleculeStructure();
 | 
|---|
| [76163d] | 257 |   }
 | 
|---|
| [d297a3] | 258 | }
 | 
|---|
 | 259 | 
 | 
|---|
| [387b36] | 260 | std::string World::getDefaultName() {
 | 
|---|
| [5f612ee] | 261 |   return defaultName;
 | 
|---|
 | 262 | }
 | 
|---|
 | 263 | 
 | 
|---|
| [387b36] | 264 | void World::setDefaultName(std::string name)
 | 
|---|
| [5f612ee] | 265 | {
 | 
|---|
| [be97a8] | 266 |   OBSERVE;
 | 
|---|
| [387b36] | 267 |   defaultName = name;
 | 
|---|
| [5f612ee] | 268 | };
 | 
|---|
 | 269 | 
 | 
|---|
| [43dad6] | 270 | class ThermoStatContainer * World::getThermostats()
 | 
|---|
 | 271 | {
 | 
|---|
 | 272 |   return Thermostats;
 | 
|---|
 | 273 | }
 | 
|---|
 | 274 | 
 | 
|---|
 | 275 | 
 | 
|---|
| [e4b5de] | 276 | int World::getExitFlag() {
 | 
|---|
 | 277 |   return ExitFlag;
 | 
|---|
 | 278 | }
 | 
|---|
 | 279 | 
 | 
|---|
 | 280 | void World::setExitFlag(int flag) {
 | 
|---|
 | 281 |   if (ExitFlag < flag)
 | 
|---|
 | 282 |     ExitFlag = flag;
 | 
|---|
 | 283 | }
 | 
|---|
| [5f612ee] | 284 | 
 | 
|---|
| [afb47f] | 285 | /******************** Methods to change World state *********************/
 | 
|---|
 | 286 | 
 | 
|---|
| [354859] | 287 | molecule* World::createMolecule(){
 | 
|---|
 | 288 |   OBSERVE;
 | 
|---|
 | 289 |   molecule *mol = NULL;
 | 
|---|
| [cbc5fb] | 290 |   mol = NewMolecule();
 | 
|---|
| [3e4fb6] | 291 |   moleculeId_t id = moleculeIdPool.getNextId();
 | 
|---|
| [127a8e] | 292 |   ASSERT(!molecules.count(id),"proposed id did not specify an unused ID");
 | 
|---|
 | 293 |   mol->setId(id);
 | 
|---|
| [244d26] | 294 |   // store the molecule by ID
 | 
|---|
| [cbc5fb] | 295 |   molecules[mol->getId()] = mol;
 | 
|---|
| [354859] | 296 |   mol->signOn(this);
 | 
|---|
| [7188b1] | 297 |   _lastchangedmol = mol;
 | 
|---|
 | 298 |   NOTIFY(MoleculeInserted);
 | 
|---|
| [354859] | 299 |   return mol;
 | 
|---|
 | 300 | }
 | 
|---|
 | 301 | 
 | 
|---|
| [cbc5fb] | 302 | void World::destroyMolecule(molecule* mol){
 | 
|---|
 | 303 |   OBSERVE;
 | 
|---|
| [fa7989] | 304 |   ASSERT(mol,"Molecule that was meant to be destroyed did not exist");
 | 
|---|
| [cbc5fb] | 305 |   destroyMolecule(mol->getId());
 | 
|---|
 | 306 | }
 | 
|---|
 | 307 | 
 | 
|---|
 | 308 | void World::destroyMolecule(moleculeId_t id){
 | 
|---|
 | 309 |   molecule *mol = molecules[id];
 | 
|---|
| [6d574a] | 310 |   ASSERT(mol,"Molecule id that was meant to be destroyed did not exist");
 | 
|---|
| [38f991] | 311 |   // give notice about immediate removal
 | 
|---|
 | 312 |   {
 | 
|---|
 | 313 |     OBSERVE;
 | 
|---|
 | 314 |     _lastchangedmol = mol;
 | 
|---|
 | 315 |     NOTIFY(MoleculeRemoved);
 | 
|---|
 | 316 |   }
 | 
|---|
| [7d82a5] | 317 |   mol->signOff(this);
 | 
|---|
| [cbc5fb] | 318 |   DeleteMolecule(mol);
 | 
|---|
| [38f991] | 319 |   if (isMoleculeSelected(id))
 | 
|---|
 | 320 |     selectedMolecules.erase(id);
 | 
|---|
| [cbc5fb] | 321 |   molecules.erase(id);
 | 
|---|
| [3e4fb6] | 322 |   moleculeIdPool.releaseId(id);
 | 
|---|
| [cbc5fb] | 323 | }
 | 
|---|
 | 324 | 
 | 
|---|
| [46d958] | 325 | atom *World::createAtom(){
 | 
|---|
 | 326 |   OBSERVE;
 | 
|---|
| [3e4fb6] | 327 |   atomId_t id = atomIdPool.getNextId();
 | 
|---|
| [127a8e] | 328 |   ASSERT(!atoms.count(id),"proposed id did not specify an unused ID");
 | 
|---|
| [88d586] | 329 |   atom *res = NewAtom(id);
 | 
|---|
| [46d958] | 330 |   res->setWorld(this);
 | 
|---|
| [244d26] | 331 |   // store the atom by ID
 | 
|---|
| [46d958] | 332 |   atoms[res->getId()] = res;
 | 
|---|
| [7188b1] | 333 |   _lastchangedatom = res;
 | 
|---|
 | 334 |   NOTIFY(AtomInserted);
 | 
|---|
| [46d958] | 335 |   return res;
 | 
|---|
 | 336 | }
 | 
|---|
 | 337 | 
 | 
|---|
| [5f612ee] | 338 | 
 | 
|---|
| [46d958] | 339 | int World::registerAtom(atom *atom){
 | 
|---|
 | 340 |   OBSERVE;
 | 
|---|
| [3e4fb6] | 341 |   atomId_t id = atomIdPool.getNextId();
 | 
|---|
| [88d586] | 342 |   atom->setId(id);
 | 
|---|
| [46d958] | 343 |   atom->setWorld(this);
 | 
|---|
 | 344 |   atoms[atom->getId()] = atom;
 | 
|---|
| [65d7ca] | 345 |   _lastchangedatom = atom;
 | 
|---|
 | 346 |   NOTIFY(AtomInserted);
 | 
|---|
| [46d958] | 347 |   return atom->getId();
 | 
|---|
 | 348 | }
 | 
|---|
 | 349 | 
 | 
|---|
 | 350 | void World::destroyAtom(atom* atom){
 | 
|---|
 | 351 |   int id = atom->getId();
 | 
|---|
 | 352 |   destroyAtom(id);
 | 
|---|
 | 353 | }
 | 
|---|
 | 354 | 
 | 
|---|
| [cbc5fb] | 355 | void World::destroyAtom(atomId_t id) {
 | 
|---|
| [46d958] | 356 |   atom *atom = atoms[id];
 | 
|---|
| [6d574a] | 357 |   ASSERT(atom,"Atom ID that was meant to be destroyed did not exist");
 | 
|---|
| [ab4a33] | 358 |   // give notice about immediate removal
 | 
|---|
 | 359 |   {
 | 
|---|
 | 360 |     OBSERVE;
 | 
|---|
 | 361 |     _lastchangedatom = atom;
 | 
|---|
 | 362 |     NOTIFY(AtomRemoved);
 | 
|---|
 | 363 |   }
 | 
|---|
| [46d958] | 364 |   DeleteAtom(atom);
 | 
|---|
| [38f991] | 365 |   if (isAtomSelected(id))
 | 
|---|
 | 366 |     selectedAtoms.erase(id);
 | 
|---|
| [46d958] | 367 |   atoms.erase(id);
 | 
|---|
| [3e4fb6] | 368 |   atomIdPool.releaseId(id);
 | 
|---|
| [88d586] | 369 | }
 | 
|---|
 | 370 | 
 | 
|---|
 | 371 | bool World::changeAtomId(atomId_t oldId, atomId_t newId, atom* target){
 | 
|---|
 | 372 |   OBSERVE;
 | 
|---|
 | 373 |   // in case this call did not originate from inside the atom, we redirect it,
 | 
|---|
 | 374 |   // to also let it know that it has changed
 | 
|---|
 | 375 |   if(!target){
 | 
|---|
 | 376 |     target = atoms[oldId];
 | 
|---|
| [6d574a] | 377 |     ASSERT(target,"Atom with that ID not found");
 | 
|---|
| [88d586] | 378 |     return target->changeId(newId);
 | 
|---|
 | 379 |   }
 | 
|---|
 | 380 |   else{
 | 
|---|
| [3e4fb6] | 381 |     if(atomIdPool.reserveId(newId)){
 | 
|---|
| [88d586] | 382 |       atoms.erase(oldId);
 | 
|---|
 | 383 |       atoms.insert(pair<atomId_t,atom*>(newId,target));
 | 
|---|
 | 384 |       return true;
 | 
|---|
 | 385 |     }
 | 
|---|
 | 386 |     else{
 | 
|---|
 | 387 |       return false;
 | 
|---|
 | 388 |     }
 | 
|---|
 | 389 |   }
 | 
|---|
| [46d958] | 390 | }
 | 
|---|
 | 391 | 
 | 
|---|
| [a7a087] | 392 | bool World::changeMoleculeId(moleculeId_t oldId, moleculeId_t newId, molecule* target){
 | 
|---|
 | 393 |   OBSERVE;
 | 
|---|
 | 394 |   // in case this call did not originate from inside the atom, we redirect it,
 | 
|---|
 | 395 |   // to also let it know that it has changed
 | 
|---|
 | 396 |   if(!target){
 | 
|---|
 | 397 |     target = molecules[oldId];
 | 
|---|
 | 398 |     ASSERT(target,"Molecule with that ID not found");
 | 
|---|
 | 399 |     return target->changeId(newId);
 | 
|---|
 | 400 |   }
 | 
|---|
 | 401 |   else{
 | 
|---|
| [3e4fb6] | 402 |     if(moleculeIdPool.reserveId(newId)){
 | 
|---|
| [a7a087] | 403 |       molecules.erase(oldId);
 | 
|---|
 | 404 |       molecules.insert(pair<moleculeId_t,molecule*>(newId,target));
 | 
|---|
 | 405 |       return true;
 | 
|---|
 | 406 |     }
 | 
|---|
 | 407 |     else{
 | 
|---|
 | 408 |       return false;
 | 
|---|
 | 409 |     }
 | 
|---|
 | 410 |   }
 | 
|---|
 | 411 | }
 | 
|---|
 | 412 | 
 | 
|---|
| [7c4e29] | 413 | ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){
 | 
|---|
| [3139b2] | 414 |   ActionTrait manipulateTrait(name);
 | 
|---|
| [126867] | 415 |   return new ManipulateAtomsProcess(op, descr,manipulateTrait);
 | 
|---|
| [7c4e29] | 416 | }
 | 
|---|
 | 417 | 
 | 
|---|
| [0e2a47] | 418 | ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name){
 | 
|---|
 | 419 |   return manipulateAtoms(op,name,AllAtoms());
 | 
|---|
 | 420 | }
 | 
|---|
 | 421 | 
 | 
|---|
| [afb47f] | 422 | /********************* Internal Change methods for double Callback and Observer mechanism ********/
 | 
|---|
 | 423 | 
 | 
|---|
 | 424 | void World::doManipulate(ManipulateAtomsProcess *proc){
 | 
|---|
 | 425 |   proc->signOn(this);
 | 
|---|
 | 426 |   {
 | 
|---|
 | 427 |     OBSERVE;
 | 
|---|
 | 428 |     proc->doManipulate(this);
 | 
|---|
 | 429 |   }
 | 
|---|
 | 430 |   proc->signOff(this);
 | 
|---|
 | 431 | }
 | 
|---|
| [865a945] | 432 | /******************************* Iterators ********************************/
 | 
|---|
 | 433 | 
 | 
|---|
| [fa0b18] | 434 | // external parts with observers
 | 
|---|
 | 435 | 
 | 
|---|
| [feb5d0] | 436 | CONSTRUCT_SELECTIVE_ITERATOR(atom*,World::AtomSet,AtomDescriptor)
 | 
|---|
 | 437 | 
 | 
|---|
 | 438 | CONSTRUCT_SELECTIVE_CONST_ITERATOR(atom*,World::AtomSet,AtomDescriptor)
 | 
|---|
| [6e97e5] | 439 | 
 | 
|---|
| [fa0b18] | 440 | World::AtomIterator
 | 
|---|
 | 441 | World::getAtomIter(AtomDescriptor descr){
 | 
|---|
 | 442 |     return AtomIterator(descr,atoms);
 | 
|---|
 | 443 | }
 | 
|---|
| [865a945] | 444 | 
 | 
|---|
| [feb5d0] | 445 | World::AtomConstIterator
 | 
|---|
 | 446 | World::getAtomIter(AtomDescriptor descr) const{
 | 
|---|
 | 447 |     return AtomConstIterator(descr,atoms);
 | 
|---|
 | 448 | }
 | 
|---|
 | 449 | 
 | 
|---|
| [fa0b18] | 450 | World::AtomIterator
 | 
|---|
 | 451 | World::getAtomIter(){
 | 
|---|
 | 452 |     return AtomIterator(AllAtoms(),atoms);
 | 
|---|
| [865a945] | 453 | }
 | 
|---|
| [354859] | 454 | 
 | 
|---|
| [feb5d0] | 455 | World::AtomConstIterator
 | 
|---|
 | 456 | World::getAtomIter() const{
 | 
|---|
 | 457 |     return AtomConstIterator(AllAtoms(),atoms);
 | 
|---|
 | 458 | }
 | 
|---|
 | 459 | 
 | 
|---|
| [fa0b18] | 460 | World::AtomIterator
 | 
|---|
 | 461 | World::atomEnd(){
 | 
|---|
| [6e97e5] | 462 |   return AtomIterator(AllAtoms(),atoms,atoms.end());
 | 
|---|
| [7c4e29] | 463 | }
 | 
|---|
 | 464 | 
 | 
|---|
| [feb5d0] | 465 | World::AtomConstIterator
 | 
|---|
 | 466 | World::atomEnd() const{
 | 
|---|
 | 467 |   return AtomConstIterator(AllAtoms(),atoms,atoms.end());
 | 
|---|
 | 468 | }
 | 
|---|
 | 469 | 
 | 
|---|
 | 470 | CONSTRUCT_SELECTIVE_ITERATOR(molecule*,World::MoleculeSet,MoleculeDescriptor)
 | 
|---|
 | 471 | 
 | 
|---|
 | 472 | CONSTRUCT_SELECTIVE_CONST_ITERATOR(molecule*,World::MoleculeSet,MoleculeDescriptor)
 | 
|---|
| [6e97e5] | 473 | 
 | 
|---|
| [5d880e] | 474 | World::MoleculeIterator
 | 
|---|
 | 475 | World::getMoleculeIter(MoleculeDescriptor descr){
 | 
|---|
 | 476 |     return MoleculeIterator(descr,molecules);
 | 
|---|
 | 477 | }
 | 
|---|
 | 478 | 
 | 
|---|
| [feb5d0] | 479 | World::MoleculeConstIterator
 | 
|---|
 | 480 | World::getMoleculeIter(MoleculeDescriptor descr) const{
 | 
|---|
 | 481 |     return MoleculeConstIterator(descr,molecules);
 | 
|---|
 | 482 | }
 | 
|---|
 | 483 | 
 | 
|---|
| [5d880e] | 484 | World::MoleculeIterator
 | 
|---|
 | 485 | World::getMoleculeIter(){
 | 
|---|
 | 486 |     return MoleculeIterator(AllMolecules(),molecules);
 | 
|---|
| [1c51c8] | 487 | }
 | 
|---|
 | 488 | 
 | 
|---|
| [feb5d0] | 489 | World::MoleculeConstIterator
 | 
|---|
 | 490 | World::getMoleculeIter() const{
 | 
|---|
 | 491 |     return MoleculeConstIterator(AllMolecules(),molecules);
 | 
|---|
 | 492 | }
 | 
|---|
 | 493 | 
 | 
|---|
| [5d880e] | 494 | World::MoleculeIterator
 | 
|---|
 | 495 | World::moleculeEnd(){
 | 
|---|
| [6e97e5] | 496 |   return MoleculeIterator(AllMolecules(),molecules,molecules.end());
 | 
|---|
| [1c51c8] | 497 | }
 | 
|---|
 | 498 | 
 | 
|---|
| [feb5d0] | 499 | World::MoleculeConstIterator
 | 
|---|
 | 500 | World::moleculeEnd() const{
 | 
|---|
 | 501 |   return MoleculeConstIterator(AllMolecules(),molecules,molecules.end());
 | 
|---|
 | 502 | }
 | 
|---|
 | 503 | 
 | 
|---|
| [fa0b18] | 504 | // Internal parts, without observers
 | 
|---|
 | 505 | 
 | 
|---|
 | 506 | // Build the AtomIterator from template
 | 
|---|
 | 507 | CONSTRUCT_SELECTIVE_ITERATOR(atom*,World::AtomSet::set_t,AtomDescriptor);
 | 
|---|
 | 508 | 
 | 
|---|
 | 509 | 
 | 
|---|
 | 510 | World::internal_AtomIterator
 | 
|---|
 | 511 | World::getAtomIter_internal(AtomDescriptor descr){
 | 
|---|
 | 512 |   return internal_AtomIterator(descr,atoms.getContent());
 | 
|---|
 | 513 | }
 | 
|---|
 | 514 | 
 | 
|---|
 | 515 | World::internal_AtomIterator
 | 
|---|
 | 516 | World::atomEnd_internal(){
 | 
|---|
 | 517 |   return internal_AtomIterator(AllAtoms(),atoms.getContent(),atoms.end_internal());
 | 
|---|
 | 518 | }
 | 
|---|
 | 519 | 
 | 
|---|
| [6e97e5] | 520 | // build the MoleculeIterator from template
 | 
|---|
| [e3d865] | 521 | CONSTRUCT_SELECTIVE_ITERATOR(molecule*,World::MoleculeSet::set_t,MoleculeDescriptor);
 | 
|---|
| [6e97e5] | 522 | 
 | 
|---|
| [e3d865] | 523 | World::internal_MoleculeIterator World::getMoleculeIter_internal(MoleculeDescriptor descr){
 | 
|---|
 | 524 |   return internal_MoleculeIterator(descr,molecules.getContent());
 | 
|---|
| [1c51c8] | 525 | }
 | 
|---|
 | 526 | 
 | 
|---|
| [e3d865] | 527 | World::internal_MoleculeIterator World::moleculeEnd_internal(){
 | 
|---|
 | 528 |   return internal_MoleculeIterator(AllMolecules(),molecules.getContent(),molecules.end_internal());
 | 
|---|
| [1c51c8] | 529 | }
 | 
|---|
 | 530 | 
 | 
|---|
| [90c4280] | 531 | /************************** Selection of Atoms and molecules ******************/
 | 
|---|
 | 532 | 
 | 
|---|
 | 533 | // Atoms
 | 
|---|
 | 534 | 
 | 
|---|
 | 535 | void World::clearAtomSelection(){
 | 
|---|
| [69643a] | 536 |   OBSERVE;
 | 
|---|
 | 537 |   NOTIFY(SelectionChanged);
 | 
|---|
| [90c4280] | 538 |   selectedAtoms.clear();
 | 
|---|
 | 539 | }
 | 
|---|
 | 540 | 
 | 
|---|
| [ebc499] | 541 | void World::invertAtomSelection(){
 | 
|---|
 | 542 |   // get all atoms not selected
 | 
|---|
 | 543 |   AtomComposite invertedSelection(getAllAtoms());
 | 
|---|
 | 544 |   bool (World::*predicate)(const atom*) const = &World::isSelected; // needed for type resolution of overloaded function
 | 
|---|
 | 545 |   AtomComposite::iterator iter =
 | 
|---|
 | 546 |       std::remove_if(invertedSelection.begin(), invertedSelection.end(),
 | 
|---|
 | 547 |           std::bind1st(std::mem_fun(predicate), this));
 | 
|---|
 | 548 |   invertedSelection.erase(iter, invertedSelection.end());
 | 
|---|
 | 549 |   // apply new selection
 | 
|---|
 | 550 |   selectedAtoms.clear();
 | 
|---|
 | 551 |   void (World::*selector)(const atom*) = &World::selectAtom; // needed for type resolution of overloaded function
 | 
|---|
 | 552 |   std::for_each(invertedSelection.begin(),invertedSelection.end(),
 | 
|---|
 | 553 |       std::bind1st(std::mem_fun(selector),this)); // func is select... see above
 | 
|---|
 | 554 | }
 | 
|---|
 | 555 | 
 | 
|---|
| [e4afb4] | 556 | void World::selectAtom(const atom *_atom){
 | 
|---|
| [69643a] | 557 |   OBSERVE;
 | 
|---|
 | 558 |   NOTIFY(SelectionChanged);
 | 
|---|
| [e4afb4] | 559 |   // atom * is unchanged in this function, but we do store entity as changeable
 | 
|---|
 | 560 |   ASSERT(_atom,"Invalid pointer in selection of atom");
 | 
|---|
 | 561 |   selectedAtoms[_atom->getId()]=const_cast<atom *>(_atom);
 | 
|---|
| [90c4280] | 562 | }
 | 
|---|
 | 563 | 
 | 
|---|
| [e4afb4] | 564 | void World::selectAtom(const atomId_t id){
 | 
|---|
| [69643a] | 565 |   OBSERVE;
 | 
|---|
 | 566 |   NOTIFY(SelectionChanged);
 | 
|---|
| [90c4280] | 567 |   ASSERT(atoms.count(id),"Atom Id selected that was not in the world");
 | 
|---|
 | 568 |   selectedAtoms[id]=atoms[id];
 | 
|---|
 | 569 | }
 | 
|---|
 | 570 | 
 | 
|---|
 | 571 | void World::selectAllAtoms(AtomDescriptor descr){
 | 
|---|
| [69643a] | 572 |   OBSERVE;
 | 
|---|
 | 573 |   NOTIFY(SelectionChanged);
 | 
|---|
| [90c4280] | 574 |   internal_AtomIterator begin = getAtomIter_internal(descr);
 | 
|---|
 | 575 |   internal_AtomIterator end = atomEnd_internal();
 | 
|---|
| [e4afb4] | 576 |   void (World::*func)(const atom*) = &World::selectAtom; // needed for type resolution of overloaded function
 | 
|---|
| [90c4280] | 577 |   for_each(begin,end,bind1st(mem_fun(func),this)); // func is select... see above
 | 
|---|
 | 578 | }
 | 
|---|
 | 579 | 
 | 
|---|
| [e4afb4] | 580 | void World::selectAtomsOfMolecule(const molecule *_mol){
 | 
|---|
| [69643a] | 581 |   OBSERVE;
 | 
|---|
 | 582 |   NOTIFY(SelectionChanged);
 | 
|---|
| [90c4280] | 583 |   ASSERT(_mol,"Invalid pointer to molecule in selection of Atoms of Molecule");
 | 
|---|
 | 584 |   // need to make it const to get the fast iterators
 | 
|---|
 | 585 |   const molecule *mol = _mol;
 | 
|---|
| [e4afb4] | 586 |   void (World::*func)(const atom*) = &World::selectAtom; // needed for type resolution of overloaded function
 | 
|---|
| [90c4280] | 587 |   for_each(mol->begin(),mol->end(),bind1st(mem_fun(func),this)); // func is select... see above
 | 
|---|
 | 588 | }
 | 
|---|
 | 589 | 
 | 
|---|
| [e4afb4] | 590 | void World::selectAtomsOfMolecule(const moleculeId_t id){
 | 
|---|
| [69643a] | 591 |   OBSERVE;
 | 
|---|
 | 592 |   NOTIFY(SelectionChanged);
 | 
|---|
| [90c4280] | 593 |   ASSERT(molecules.count(id),"No molecule with the given id upon Selection of atoms from molecule");
 | 
|---|
 | 594 |   selectAtomsOfMolecule(molecules[id]);
 | 
|---|
 | 595 | }
 | 
|---|
 | 596 | 
 | 
|---|
| [e4afb4] | 597 | void World::unselectAtom(const atom *_atom){
 | 
|---|
| [69643a] | 598 |   OBSERVE;
 | 
|---|
 | 599 |   NOTIFY(SelectionChanged);
 | 
|---|
| [e4afb4] | 600 |   ASSERT(_atom,"Invalid pointer in unselection of atom");
 | 
|---|
 | 601 |   unselectAtom(_atom->getId());
 | 
|---|
| [61d655e] | 602 | }
 | 
|---|
 | 603 | 
 | 
|---|
| [e4afb4] | 604 | void World::unselectAtom(const atomId_t id){
 | 
|---|
| [69643a] | 605 |   OBSERVE;
 | 
|---|
 | 606 |   NOTIFY(SelectionChanged);
 | 
|---|
| [61d655e] | 607 |   ASSERT(atoms.count(id),"Atom Id unselected that was not in the world");
 | 
|---|
 | 608 |   selectedAtoms.erase(id);
 | 
|---|
 | 609 | }
 | 
|---|
 | 610 | 
 | 
|---|
 | 611 | void World::unselectAllAtoms(AtomDescriptor descr){
 | 
|---|
| [69643a] | 612 |   OBSERVE;
 | 
|---|
 | 613 |   NOTIFY(SelectionChanged);
 | 
|---|
| [61d655e] | 614 |   internal_AtomIterator begin = getAtomIter_internal(descr);
 | 
|---|
 | 615 |   internal_AtomIterator end = atomEnd_internal();
 | 
|---|
| [e4afb4] | 616 |   void (World::*func)(const atom*) = &World::unselectAtom; // needed for type resolution of overloaded function
 | 
|---|
| [61d655e] | 617 |   for_each(begin,end,bind1st(mem_fun(func),this)); // func is unselect... see above
 | 
|---|
 | 618 | }
 | 
|---|
 | 619 | 
 | 
|---|
| [e4afb4] | 620 | void World::unselectAtomsOfMolecule(const molecule *_mol){
 | 
|---|
| [69643a] | 621 |   OBSERVE;
 | 
|---|
 | 622 |   NOTIFY(SelectionChanged);
 | 
|---|
| [61d655e] | 623 |   ASSERT(_mol,"Invalid pointer to molecule in selection of Atoms of Molecule");
 | 
|---|
 | 624 |   // need to make it const to get the fast iterators
 | 
|---|
 | 625 |   const molecule *mol = _mol;
 | 
|---|
| [e4afb4] | 626 |   void (World::*func)(const atom*) = &World::unselectAtom; // needed for type resolution of overloaded function
 | 
|---|
| [992bd5] | 627 |   for_each(mol->begin(),mol->end(),bind1st(mem_fun(func),this)); // func is unselect... see above
 | 
|---|
| [61d655e] | 628 | }
 | 
|---|
 | 629 | 
 | 
|---|
| [e4afb4] | 630 | void World::unselectAtomsOfMolecule(const moleculeId_t id){
 | 
|---|
| [69643a] | 631 |   OBSERVE;
 | 
|---|
 | 632 |   NOTIFY(SelectionChanged);
 | 
|---|
| [61d655e] | 633 |   ASSERT(molecules.count(id),"No molecule with the given id upon Selection of atoms from molecule");
 | 
|---|
 | 634 |   unselectAtomsOfMolecule(molecules[id]);
 | 
|---|
 | 635 | }
 | 
|---|
 | 636 | 
 | 
|---|
| [e472eab] | 637 | size_t World::countSelectedAtoms() const {
 | 
|---|
| [eacc3b] | 638 |   size_t count = 0;
 | 
|---|
| [e472eab] | 639 |   for (AtomSet::const_iterator iter = selectedAtoms.begin(); iter != selectedAtoms.end(); ++iter)
 | 
|---|
| [eacc3b] | 640 |     count++;
 | 
|---|
 | 641 |   return count;
 | 
|---|
 | 642 | }
 | 
|---|
 | 643 | 
 | 
|---|
| [e4afb4] | 644 | bool World::isSelected(const atom *_atom) const {
 | 
|---|
| [89643d] | 645 |   return isAtomSelected(_atom->getId());
 | 
|---|
 | 646 | }
 | 
|---|
 | 647 | 
 | 
|---|
 | 648 | bool World::isAtomSelected(const atomId_t no) const {
 | 
|---|
 | 649 |   return selectedAtoms.find(no) != selectedAtoms.end();
 | 
|---|
| [e0e156] | 650 | }
 | 
|---|
 | 651 | 
 | 
|---|
| [e472eab] | 652 | const std::vector<atom *> World::getSelectedAtoms() const {
 | 
|---|
 | 653 |   std::vector<atom *> returnAtoms;
 | 
|---|
 | 654 |   returnAtoms.resize(countSelectedAtoms());
 | 
|---|
 | 655 |   int count = 0;
 | 
|---|
 | 656 |   for (AtomSet::const_iterator iter = selectedAtoms.begin(); iter != selectedAtoms.end(); ++iter)
 | 
|---|
 | 657 |     returnAtoms[count++] = iter->second;
 | 
|---|
 | 658 |   return returnAtoms;
 | 
|---|
 | 659 | }
 | 
|---|
 | 660 | 
 | 
|---|
 | 661 | 
 | 
|---|
| [90c4280] | 662 | // Molecules
 | 
|---|
 | 663 | 
 | 
|---|
 | 664 | void World::clearMoleculeSelection(){
 | 
|---|
| [69643a] | 665 |   OBSERVE;
 | 
|---|
 | 666 |   NOTIFY(SelectionChanged);
 | 
|---|
| [90c4280] | 667 |   selectedMolecules.clear();
 | 
|---|
 | 668 | }
 | 
|---|
 | 669 | 
 | 
|---|
| [ebc499] | 670 | void World::invertMoleculeSelection(){
 | 
|---|
 | 671 |   // get all molecules not selected
 | 
|---|
 | 672 |   typedef std::vector<molecule *> MoleculeVector_t;
 | 
|---|
 | 673 |   MoleculeVector_t invertedSelection(getAllMolecules());
 | 
|---|
 | 674 |   bool (World::*predicate)(const molecule*) const = &World::isSelected; // needed for type resolution of overloaded function
 | 
|---|
 | 675 |   MoleculeVector_t::iterator iter =
 | 
|---|
 | 676 |       std::remove_if(invertedSelection.begin(), invertedSelection.end(),
 | 
|---|
 | 677 |           std::bind1st(std::mem_fun(predicate), this));
 | 
|---|
 | 678 |   invertedSelection.erase(iter, invertedSelection.end());
 | 
|---|
 | 679 |   // apply new selection
 | 
|---|
 | 680 |   selectedMolecules.clear();
 | 
|---|
 | 681 |   void (World::*selector)(const molecule*) = &World::selectMolecule; // needed for type resolution of overloaded function
 | 
|---|
 | 682 |   std::for_each(invertedSelection.begin(),invertedSelection.end(),
 | 
|---|
 | 683 |       std::bind1st(std::mem_fun(selector),this)); // func is select... see above
 | 
|---|
 | 684 | }
 | 
|---|
 | 685 | 
 | 
|---|
| [e4afb4] | 686 | void World::selectMolecule(const molecule *_mol){
 | 
|---|
| [69643a] | 687 |   OBSERVE;
 | 
|---|
 | 688 |   NOTIFY(SelectionChanged);
 | 
|---|
| [e4afb4] | 689 |   // molecule * is unchanged in this function, but we do store entity as changeable
 | 
|---|
 | 690 |   ASSERT(_mol,"Invalid pointer to molecule in selection");
 | 
|---|
 | 691 |   selectedMolecules[_mol->getId()]=const_cast<molecule *>(_mol);
 | 
|---|
| [90c4280] | 692 | }
 | 
|---|
 | 693 | 
 | 
|---|
| [e4afb4] | 694 | void World::selectMolecule(const moleculeId_t id){
 | 
|---|
| [69643a] | 695 |   OBSERVE;
 | 
|---|
 | 696 |   NOTIFY(SelectionChanged);
 | 
|---|
| [90c4280] | 697 |   ASSERT(molecules.count(id),"Molecule Id selected that was not in the world");
 | 
|---|
 | 698 |   selectedMolecules[id]=molecules[id];
 | 
|---|
 | 699 | }
 | 
|---|
 | 700 | 
 | 
|---|
| [e472eab] | 701 | void World::selectAllMolecules(MoleculeDescriptor descr){
 | 
|---|
| [69643a] | 702 |   OBSERVE;
 | 
|---|
 | 703 |   NOTIFY(SelectionChanged);
 | 
|---|
| [90c4280] | 704 |   internal_MoleculeIterator begin = getMoleculeIter_internal(descr);
 | 
|---|
 | 705 |   internal_MoleculeIterator end = moleculeEnd_internal();
 | 
|---|
| [e4afb4] | 706 |   void (World::*func)(const molecule*) = &World::selectMolecule; // needed for type resolution of overloaded function
 | 
|---|
| [90c4280] | 707 |   for_each(begin,end,bind1st(mem_fun(func),this)); // func is select... see above
 | 
|---|
 | 708 | }
 | 
|---|
 | 709 | 
 | 
|---|
| [e4afb4] | 710 | void World::selectMoleculeOfAtom(const atom *_atom){
 | 
|---|
| [69643a] | 711 |   OBSERVE;
 | 
|---|
 | 712 |   NOTIFY(SelectionChanged);
 | 
|---|
| [e4afb4] | 713 |   ASSERT(_atom,"Invalid atom pointer in selection of MoleculeOfAtom");
 | 
|---|
 | 714 |   molecule *mol=_atom->getMolecule();
 | 
|---|
| [90c4280] | 715 |   // the atom might not be part of a molecule
 | 
|---|
 | 716 |   if(mol){
 | 
|---|
 | 717 |     selectMolecule(mol);
 | 
|---|
 | 718 |   }
 | 
|---|
 | 719 | }
 | 
|---|
 | 720 | 
 | 
|---|
| [e4afb4] | 721 | void World::selectMoleculeOfAtom(const atomId_t id){
 | 
|---|
| [69643a] | 722 |   OBSERVE;
 | 
|---|
 | 723 |   NOTIFY(SelectionChanged);
 | 
|---|
| [90c4280] | 724 |   ASSERT(atoms.count(id),"No such atom with given ID in selection of Molecules of Atom");\
 | 
|---|
 | 725 |   selectMoleculeOfAtom(atoms[id]);
 | 
|---|
 | 726 | }
 | 
|---|
 | 727 | 
 | 
|---|
| [e4afb4] | 728 | void World::unselectMolecule(const molecule *_mol){
 | 
|---|
| [69643a] | 729 |   OBSERVE;
 | 
|---|
 | 730 |   NOTIFY(SelectionChanged);
 | 
|---|
| [e4afb4] | 731 |   ASSERT(_mol,"invalid pointer in unselection of molecule");
 | 
|---|
 | 732 |   unselectMolecule(_mol->getId());
 | 
|---|
| [61d655e] | 733 | }
 | 
|---|
 | 734 | 
 | 
|---|
| [e4afb4] | 735 | void World::unselectMolecule(const moleculeId_t id){
 | 
|---|
| [69643a] | 736 |   OBSERVE;
 | 
|---|
 | 737 |   NOTIFY(SelectionChanged);
 | 
|---|
| [61d655e] | 738 |   ASSERT(molecules.count(id),"No such molecule with ID in unselection");
 | 
|---|
 | 739 |   selectedMolecules.erase(id);
 | 
|---|
 | 740 | }
 | 
|---|
 | 741 | 
 | 
|---|
| [e472eab] | 742 | void World::unselectAllMolecules(MoleculeDescriptor descr){
 | 
|---|
| [69643a] | 743 |   OBSERVE;
 | 
|---|
 | 744 |   NOTIFY(SelectionChanged);
 | 
|---|
| [61d655e] | 745 |   internal_MoleculeIterator begin = getMoleculeIter_internal(descr);
 | 
|---|
 | 746 |   internal_MoleculeIterator end = moleculeEnd_internal();
 | 
|---|
| [e4afb4] | 747 |   void (World::*func)(const molecule*) = &World::unselectMolecule; // needed for type resolution of overloaded function
 | 
|---|
| [61d655e] | 748 |   for_each(begin,end,bind1st(mem_fun(func),this)); // func is unselect... see above
 | 
|---|
 | 749 | }
 | 
|---|
 | 750 | 
 | 
|---|
| [e4afb4] | 751 | void World::unselectMoleculeOfAtom(const atom *_atom){
 | 
|---|
| [69643a] | 752 |   OBSERVE;
 | 
|---|
 | 753 |   NOTIFY(SelectionChanged);
 | 
|---|
| [e4afb4] | 754 |   ASSERT(_atom,"Invalid atom pointer in selection of MoleculeOfAtom");
 | 
|---|
 | 755 |   molecule *mol=_atom->getMolecule();
 | 
|---|
| [61d655e] | 756 |   // the atom might not be part of a molecule
 | 
|---|
 | 757 |   if(mol){
 | 
|---|
 | 758 |     unselectMolecule(mol);
 | 
|---|
 | 759 |   }
 | 
|---|
 | 760 | }
 | 
|---|
 | 761 | 
 | 
|---|
| [e4afb4] | 762 | void World::unselectMoleculeOfAtom(const atomId_t id){
 | 
|---|
| [69643a] | 763 |   OBSERVE;
 | 
|---|
 | 764 |   NOTIFY(SelectionChanged);
 | 
|---|
| [61d655e] | 765 |   ASSERT(atoms.count(id),"No such atom with given ID in selection of Molecules of Atom");\
 | 
|---|
 | 766 |   unselectMoleculeOfAtom(atoms[id]);
 | 
|---|
 | 767 | }
 | 
|---|
 | 768 | 
 | 
|---|
| [e472eab] | 769 | size_t World::countSelectedMolecules() const {
 | 
|---|
| [eacc3b] | 770 |   size_t count = 0;
 | 
|---|
| [e472eab] | 771 |   for (MoleculeSet::const_iterator iter = selectedMolecules.begin(); iter != selectedMolecules.end(); ++iter)
 | 
|---|
| [eacc3b] | 772 |     count++;
 | 
|---|
 | 773 |   return count;
 | 
|---|
 | 774 | }
 | 
|---|
 | 775 | 
 | 
|---|
| [e4afb4] | 776 | bool World::isSelected(const molecule *_mol) const {
 | 
|---|
| [89643d] | 777 |   return isMoleculeSelected(_mol->getId());
 | 
|---|
 | 778 | }
 | 
|---|
 | 779 | 
 | 
|---|
 | 780 | bool World::isMoleculeSelected(const moleculeId_t no) const {
 | 
|---|
 | 781 |   return selectedMolecules.find(no) != selectedMolecules.end();
 | 
|---|
| [e0e156] | 782 | }
 | 
|---|
 | 783 | 
 | 
|---|
| [e472eab] | 784 | const std::vector<molecule *> World::getSelectedMolecules() const {
 | 
|---|
 | 785 |   std::vector<molecule *> returnMolecules;
 | 
|---|
 | 786 |   returnMolecules.resize(countSelectedMolecules());
 | 
|---|
 | 787 |   int count = 0;
 | 
|---|
 | 788 |   for (MoleculeSet::const_iterator iter = selectedMolecules.begin(); iter != selectedMolecules.end(); ++iter)
 | 
|---|
 | 789 |     returnMolecules[count++] = iter->second;
 | 
|---|
 | 790 |   return returnMolecules;
 | 
|---|
 | 791 | }
 | 
|---|
 | 792 | 
 | 
|---|
| [3839e5] | 793 | /******************* Iterators over Selection *****************************/
 | 
|---|
 | 794 | World::AtomSelectionIterator World::beginAtomSelection(){
 | 
|---|
 | 795 |   return selectedAtoms.begin();
 | 
|---|
 | 796 | }
 | 
|---|
 | 797 | 
 | 
|---|
 | 798 | World::AtomSelectionIterator World::endAtomSelection(){
 | 
|---|
 | 799 |   return selectedAtoms.end();
 | 
|---|
 | 800 | }
 | 
|---|
 | 801 | 
 | 
|---|
| [38f991] | 802 | World::AtomSelectionConstIterator World::beginAtomSelection() const{
 | 
|---|
 | 803 |   return selectedAtoms.begin();
 | 
|---|
 | 804 | }
 | 
|---|
 | 805 | 
 | 
|---|
 | 806 | World::AtomSelectionConstIterator World::endAtomSelection() const{
 | 
|---|
 | 807 |   return selectedAtoms.end();
 | 
|---|
 | 808 | }
 | 
|---|
 | 809 | 
 | 
|---|
| [3839e5] | 810 | 
 | 
|---|
 | 811 | World::MoleculeSelectionIterator World::beginMoleculeSelection(){
 | 
|---|
 | 812 |   return selectedMolecules.begin();
 | 
|---|
 | 813 | }
 | 
|---|
 | 814 | 
 | 
|---|
 | 815 | World::MoleculeSelectionIterator World::endMoleculeSelection(){
 | 
|---|
 | 816 |   return selectedMolecules.end();
 | 
|---|
 | 817 | }
 | 
|---|
 | 818 | 
 | 
|---|
| [38f991] | 819 | World::MoleculeSelectionConstIterator World::beginMoleculeSelection() const{
 | 
|---|
 | 820 |   return selectedMolecules.begin();
 | 
|---|
 | 821 | }
 | 
|---|
 | 822 | 
 | 
|---|
 | 823 | World::MoleculeSelectionConstIterator World::endMoleculeSelection() const{
 | 
|---|
 | 824 |   return selectedMolecules.end();
 | 
|---|
 | 825 | }
 | 
|---|
 | 826 | 
 | 
|---|
| [5d1611] | 827 | /******************************* Singleton Stuff **************************/
 | 
|---|
 | 828 | 
 | 
|---|
| [7a1ce5] | 829 | World::World() :
 | 
|---|
| [cd5047] | 830 |     Observable("World"),
 | 
|---|
| [f71baf] | 831 |     BG(new BondGraph(true)),  // assume Angstroem for the moment
 | 
|---|
| [4ae823] | 832 |     periode(new periodentafel(true)),
 | 
|---|
| [8e1f7af] | 833 |     configuration(new config),
 | 
|---|
| [98dbee] | 834 |     homologies(new HomologyContainer()),
 | 
|---|
| [43dad6] | 835 |     Thermostats(new ThermoStatContainer),
 | 
|---|
| [e4b5de] | 836 |     ExitFlag(0),
 | 
|---|
| [fa0b18] | 837 |     atoms(this),
 | 
|---|
| [90c4280] | 838 |     selectedAtoms(this),
 | 
|---|
| [3e4fb6] | 839 |     atomIdPool(0, 20, 100),
 | 
|---|
| [51be2a] | 840 |     molecules(this),
 | 
|---|
| [90c4280] | 841 |     selectedMolecules(this),
 | 
|---|
| [3e4fb6] | 842 |     moleculeIdPool(0, 20,100),
 | 
|---|
| [24a5e0] | 843 |     molecules_deprecated(new MoleculeListClass(this))
 | 
|---|
| [7dad10] | 844 | {
 | 
|---|
| [84c494] | 845 |   cell_size = new Box;
 | 
|---|
| [cca9ef] | 846 |   RealSpaceMatrix domain;
 | 
|---|
| [84c494] | 847 |   domain.at(0,0) = 20;
 | 
|---|
 | 848 |   domain.at(1,1) = 20;
 | 
|---|
 | 849 |   domain.at(2,2) = 20;
 | 
|---|
 | 850 |   cell_size->setM(domain);
 | 
|---|
| [4834f4] | 851 |   LCcontroller = new LinkedCell::LinkedCell_Controller(*cell_size);
 | 
|---|
| [387b36] | 852 |   defaultName = "none";
 | 
|---|
| [02ce36] | 853 |   Channels *OurChannel = new Channels;
 | 
|---|
| [708277] | 854 |   NotificationChannels.insert( std::make_pair( static_cast<Observable *>(this), OurChannel) );
 | 
|---|
| [7188b1] | 855 |   for (size_t type = 0; type < (size_t)NotificationType_MAX; ++type)
 | 
|---|
| [02ce36] | 856 |     OurChannel->addChannel(type);
 | 
|---|
| [7dad10] | 857 |   molecules_deprecated->signOn(this);
 | 
|---|
 | 858 | }
 | 
|---|
| [5d1611] | 859 | 
 | 
|---|
 | 860 | World::~World()
 | 
|---|
| [354859] | 861 | {
 | 
|---|
| [028c2e] | 862 |   molecules_deprecated->signOff(this);
 | 
|---|
| [4834f4] | 863 |   delete LCcontroller;
 | 
|---|
| [84c494] | 864 |   delete cell_size;
 | 
|---|
| [46d958] | 865 |   delete molecules_deprecated;
 | 
|---|
| [cbc5fb] | 866 |   MoleculeSet::iterator molIter;
 | 
|---|
 | 867 |   for(molIter=molecules.begin();molIter!=molecules.end();++molIter){
 | 
|---|
 | 868 |     DeleteMolecule((*molIter).second);
 | 
|---|
 | 869 |   }
 | 
|---|
 | 870 |   molecules.clear();
 | 
|---|
 | 871 |   AtomSet::iterator atIter;
 | 
|---|
 | 872 |   for(atIter=atoms.begin();atIter!=atoms.end();++atIter){
 | 
|---|
 | 873 |     DeleteAtom((*atIter).second);
 | 
|---|
| [46d958] | 874 |   }
 | 
|---|
 | 875 |   atoms.clear();
 | 
|---|
| [7188b1] | 876 | 
 | 
|---|
| [f71baf] | 877 |   delete BG;
 | 
|---|
| [6cb9c76] | 878 |   delete periode;
 | 
|---|
 | 879 |   delete configuration;
 | 
|---|
 | 880 |   delete Thermostats;
 | 
|---|
| [09f615] | 881 |   delete homologies;
 | 
|---|
| [354859] | 882 | }
 | 
|---|
| [5d1611] | 883 | 
 | 
|---|
| [23b547] | 884 | // Explicit instantiation of the singleton mechanism at this point
 | 
|---|
| [5d1611] | 885 | 
 | 
|---|
| [3e4fb6] | 886 | // moleculeId_t und atomId_t sind gleicher Basistyp, deswegen nur einen von beiden konstruieren
 | 
|---|
| [b97a60] | 887 | CONSTRUCT_IDPOOL(atomId_t, uniqueId)
 | 
|---|
 | 888 | CONSTRUCT_IDPOOL(moleculeId_t, continuousId)
 | 
|---|
| [3e4fb6] | 889 | 
 | 
|---|
| [23b547] | 890 | CONSTRUCT_SINGLETON(World)
 | 
|---|
| [5d1611] | 891 | 
 | 
|---|
| [5f1d5b8] | 892 | CONSTRUCT_OBSERVEDCONTAINER(World::AtomSTLSet)
 | 
|---|
 | 893 | 
 | 
|---|
 | 894 | CONSTRUCT_OBSERVEDCONTAINER(World::MoleculeSTLSet)
 | 
|---|
 | 895 | 
 | 
|---|
| [5d1611] | 896 | /******************************* deprecated Legacy Stuff ***********************/
 | 
|---|
 | 897 | 
 | 
|---|
| [354859] | 898 | MoleculeListClass *&World::getMolecules() {
 | 
|---|
 | 899 |   return molecules_deprecated;
 | 
|---|
| [5d1611] | 900 | }
 | 
|---|