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