| [bcf653] | 1 | /* | 
|---|
|  | 2 | * Project: MoleCuilder | 
|---|
|  | 3 | * Description: creates and alters molecular systems | 
|---|
|  | 4 | * Copyright (C)  2010 University of Bonn. All rights reserved. | 
|---|
|  | 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 |  | 
|---|
| [112b09] | 20 | #include "Helpers/MemDebug.hpp" | 
|---|
|  | 21 |  | 
|---|
| [5d1611] | 22 | #include "World.hpp" | 
|---|
|  | 23 |  | 
|---|
| [90c4280] | 24 | #include <functional> | 
|---|
| [5d1611] | 25 |  | 
|---|
| [d346b6] | 26 | #include "atom.hpp" | 
|---|
| [8e1f7af] | 27 | #include "config.hpp" | 
|---|
| [354859] | 28 | #include "molecule.hpp" | 
|---|
|  | 29 | #include "periodentafel.hpp" | 
|---|
| [43dad6] | 30 | #include "ThermoStatContainer.hpp" | 
|---|
| [fc1b24] | 31 | #include "Descriptors/AtomDescriptor.hpp" | 
|---|
| [865a945] | 32 | #include "Descriptors/AtomDescriptor_impl.hpp" | 
|---|
| [1c51c8] | 33 | #include "Descriptors/MoleculeDescriptor.hpp" | 
|---|
|  | 34 | #include "Descriptors/MoleculeDescriptor_impl.hpp" | 
|---|
| [6e97e5] | 35 | #include "Descriptors/SelectiveIterator_impl.hpp" | 
|---|
| [e4afb4] | 36 | #include "Actions/ActionTraits.hpp" | 
|---|
| [7c4e29] | 37 | #include "Actions/ManipulateAtomsProcess.hpp" | 
|---|
| [6d574a] | 38 | #include "Helpers/Assert.hpp" | 
|---|
| [84c494] | 39 | #include "Box.hpp" | 
|---|
| [cca9ef] | 40 | #include "LinearAlgebra/RealSpaceMatrix.hpp" | 
|---|
| [127a8e] | 41 | #include "defs.hpp" | 
|---|
| [d346b6] | 42 |  | 
|---|
| [23b547] | 43 | #include "Patterns/Singleton_impl.hpp" | 
|---|
| [90c4280] | 44 | #include "Patterns/ObservedContainer_impl.hpp" | 
|---|
| [23b547] | 45 |  | 
|---|
| [d346b6] | 46 | using namespace std; | 
|---|
| [4d9c01] | 47 |  | 
|---|
| [11e206] | 48 | const unsigned int MAX_POOL_FRAGMENTATION=20; | 
|---|
|  | 49 | const unsigned int MAX_FRAGMENTATION_SKIPS=100; | 
|---|
|  | 50 |  | 
|---|
| [5d1611] | 51 | /******************************* getter and setter ************************/ | 
|---|
| [354859] | 52 | periodentafel *&World::getPeriode(){ | 
|---|
| [5d1611] | 53 | return periode; | 
|---|
|  | 54 | } | 
|---|
|  | 55 |  | 
|---|
| [8e1f7af] | 56 | config *&World::getConfig(){ | 
|---|
|  | 57 | return configuration; | 
|---|
|  | 58 | } | 
|---|
|  | 59 |  | 
|---|
| [1c51c8] | 60 | // Atoms | 
|---|
|  | 61 |  | 
|---|
| [7a1ce5] | 62 | atom* World::getAtom(AtomDescriptor descriptor){ | 
|---|
| [fc1b24] | 63 | return descriptor.find(); | 
|---|
|  | 64 | } | 
|---|
|  | 65 |  | 
|---|
| [4d72e4] | 66 | World::AtomComposite World::getAllAtoms(AtomDescriptor descriptor){ | 
|---|
| [fc1b24] | 67 | return descriptor.findAll(); | 
|---|
|  | 68 | } | 
|---|
|  | 69 |  | 
|---|
| [4d72e4] | 70 | World::AtomComposite World::getAllAtoms(){ | 
|---|
| [0e2a47] | 71 | return getAllAtoms(AllAtoms()); | 
|---|
|  | 72 | } | 
|---|
|  | 73 |  | 
|---|
| [354859] | 74 | int World::numAtoms(){ | 
|---|
|  | 75 | return atoms.size(); | 
|---|
|  | 76 | } | 
|---|
|  | 77 |  | 
|---|
| [1c51c8] | 78 | // Molecules | 
|---|
|  | 79 |  | 
|---|
|  | 80 | molecule *World::getMolecule(MoleculeDescriptor descriptor){ | 
|---|
|  | 81 | return descriptor.find(); | 
|---|
|  | 82 | } | 
|---|
|  | 83 |  | 
|---|
|  | 84 | std::vector<molecule*> World::getAllMolecules(MoleculeDescriptor descriptor){ | 
|---|
|  | 85 | return descriptor.findAll(); | 
|---|
|  | 86 | } | 
|---|
|  | 87 |  | 
|---|
| [97ebf8] | 88 | std::vector<molecule*> World::getAllMolecules(){ | 
|---|
|  | 89 | return getAllMolecules(AllMolecules()); | 
|---|
|  | 90 | } | 
|---|
|  | 91 |  | 
|---|
| [354859] | 92 | int World::numMolecules(){ | 
|---|
|  | 93 | return molecules_deprecated->ListOfMolecules.size(); | 
|---|
|  | 94 | } | 
|---|
|  | 95 |  | 
|---|
| [5f612ee] | 96 | // system | 
|---|
|  | 97 |  | 
|---|
| [84c494] | 98 | Box& World::getDomain() { | 
|---|
|  | 99 | return *cell_size; | 
|---|
|  | 100 | } | 
|---|
|  | 101 |  | 
|---|
| [cca9ef] | 102 | void World::setDomain(const RealSpaceMatrix &mat){ | 
|---|
| [be97a8] | 103 | OBSERVE; | 
|---|
| [84c494] | 104 | *cell_size = mat; | 
|---|
| [5f612ee] | 105 | } | 
|---|
|  | 106 |  | 
|---|
|  | 107 | void World::setDomain(double * matrix) | 
|---|
|  | 108 | { | 
|---|
| [b9c847] | 109 | OBSERVE; | 
|---|
| [cca9ef] | 110 | RealSpaceMatrix M = ReturnFullMatrixforSymmetric(matrix); | 
|---|
| [84c494] | 111 | cell_size->setM(M); | 
|---|
| [5f612ee] | 112 | } | 
|---|
|  | 113 |  | 
|---|
| [387b36] | 114 | std::string World::getDefaultName() { | 
|---|
| [5f612ee] | 115 | return defaultName; | 
|---|
|  | 116 | } | 
|---|
|  | 117 |  | 
|---|
| [387b36] | 118 | void World::setDefaultName(std::string name) | 
|---|
| [5f612ee] | 119 | { | 
|---|
| [be97a8] | 120 | OBSERVE; | 
|---|
| [387b36] | 121 | defaultName = name; | 
|---|
| [5f612ee] | 122 | }; | 
|---|
|  | 123 |  | 
|---|
| [43dad6] | 124 | class ThermoStatContainer * World::getThermostats() | 
|---|
|  | 125 | { | 
|---|
|  | 126 | return Thermostats; | 
|---|
|  | 127 | } | 
|---|
|  | 128 |  | 
|---|
|  | 129 |  | 
|---|
| [e4b5de] | 130 | int World::getExitFlag() { | 
|---|
|  | 131 | return ExitFlag; | 
|---|
|  | 132 | } | 
|---|
|  | 133 |  | 
|---|
|  | 134 | void World::setExitFlag(int flag) { | 
|---|
|  | 135 | if (ExitFlag < flag) | 
|---|
|  | 136 | ExitFlag = flag; | 
|---|
|  | 137 | } | 
|---|
| [5f612ee] | 138 |  | 
|---|
| [afb47f] | 139 | /******************** Methods to change World state *********************/ | 
|---|
|  | 140 |  | 
|---|
| [354859] | 141 | molecule* World::createMolecule(){ | 
|---|
|  | 142 | OBSERVE; | 
|---|
|  | 143 | molecule *mol = NULL; | 
|---|
| [cbc5fb] | 144 | mol = NewMolecule(); | 
|---|
| [127a8e] | 145 | moleculeId_t id = getNextMoleculeId(); | 
|---|
|  | 146 | ASSERT(!molecules.count(id),"proposed id did not specify an unused ID"); | 
|---|
|  | 147 | mol->setId(id); | 
|---|
| [244d26] | 148 | // store the molecule by ID | 
|---|
| [cbc5fb] | 149 | molecules[mol->getId()] = mol; | 
|---|
| [354859] | 150 | mol->signOn(this); | 
|---|
|  | 151 | return mol; | 
|---|
|  | 152 | } | 
|---|
|  | 153 |  | 
|---|
| [cbc5fb] | 154 | void World::destroyMolecule(molecule* mol){ | 
|---|
|  | 155 | OBSERVE; | 
|---|
| [fa7989] | 156 | ASSERT(mol,"Molecule that was meant to be destroyed did not exist"); | 
|---|
| [cbc5fb] | 157 | destroyMolecule(mol->getId()); | 
|---|
|  | 158 | } | 
|---|
|  | 159 |  | 
|---|
|  | 160 | void World::destroyMolecule(moleculeId_t id){ | 
|---|
|  | 161 | OBSERVE; | 
|---|
|  | 162 | molecule *mol = molecules[id]; | 
|---|
| [6d574a] | 163 | ASSERT(mol,"Molecule id that was meant to be destroyed did not exist"); | 
|---|
| [cbc5fb] | 164 | DeleteMolecule(mol); | 
|---|
|  | 165 | molecules.erase(id); | 
|---|
| [127a8e] | 166 | releaseMoleculeId(id); | 
|---|
| [cbc5fb] | 167 | } | 
|---|
|  | 168 |  | 
|---|
| [46d958] | 169 | atom *World::createAtom(){ | 
|---|
|  | 170 | OBSERVE; | 
|---|
| [88d586] | 171 | atomId_t id = getNextAtomId(); | 
|---|
| [127a8e] | 172 | ASSERT(!atoms.count(id),"proposed id did not specify an unused ID"); | 
|---|
| [88d586] | 173 | atom *res = NewAtom(id); | 
|---|
| [46d958] | 174 | res->setWorld(this); | 
|---|
| [244d26] | 175 | // store the atom by ID | 
|---|
| [46d958] | 176 | atoms[res->getId()] = res; | 
|---|
|  | 177 | return res; | 
|---|
|  | 178 | } | 
|---|
|  | 179 |  | 
|---|
| [5f612ee] | 180 |  | 
|---|
| [46d958] | 181 | int World::registerAtom(atom *atom){ | 
|---|
|  | 182 | OBSERVE; | 
|---|
| [88d586] | 183 | atomId_t id = getNextAtomId(); | 
|---|
|  | 184 | atom->setId(id); | 
|---|
| [46d958] | 185 | atom->setWorld(this); | 
|---|
|  | 186 | atoms[atom->getId()] = atom; | 
|---|
|  | 187 | return atom->getId(); | 
|---|
|  | 188 | } | 
|---|
|  | 189 |  | 
|---|
|  | 190 | void World::destroyAtom(atom* atom){ | 
|---|
|  | 191 | OBSERVE; | 
|---|
|  | 192 | int id = atom->getId(); | 
|---|
|  | 193 | destroyAtom(id); | 
|---|
|  | 194 | } | 
|---|
|  | 195 |  | 
|---|
| [cbc5fb] | 196 | void World::destroyAtom(atomId_t id) { | 
|---|
| [46d958] | 197 | OBSERVE; | 
|---|
|  | 198 | atom *atom = atoms[id]; | 
|---|
| [6d574a] | 199 | ASSERT(atom,"Atom ID that was meant to be destroyed did not exist"); | 
|---|
| [46d958] | 200 | DeleteAtom(atom); | 
|---|
|  | 201 | atoms.erase(id); | 
|---|
| [88d586] | 202 | releaseAtomId(id); | 
|---|
|  | 203 | } | 
|---|
|  | 204 |  | 
|---|
|  | 205 | bool World::changeAtomId(atomId_t oldId, atomId_t newId, atom* target){ | 
|---|
|  | 206 | OBSERVE; | 
|---|
|  | 207 | // in case this call did not originate from inside the atom, we redirect it, | 
|---|
|  | 208 | // to also let it know that it has changed | 
|---|
|  | 209 | if(!target){ | 
|---|
|  | 210 | target = atoms[oldId]; | 
|---|
| [6d574a] | 211 | ASSERT(target,"Atom with that ID not found"); | 
|---|
| [88d586] | 212 | return target->changeId(newId); | 
|---|
|  | 213 | } | 
|---|
|  | 214 | else{ | 
|---|
|  | 215 | if(reserveAtomId(newId)){ | 
|---|
|  | 216 | atoms.erase(oldId); | 
|---|
|  | 217 | atoms.insert(pair<atomId_t,atom*>(newId,target)); | 
|---|
|  | 218 | return true; | 
|---|
|  | 219 | } | 
|---|
|  | 220 | else{ | 
|---|
|  | 221 | return false; | 
|---|
|  | 222 | } | 
|---|
|  | 223 | } | 
|---|
| [46d958] | 224 | } | 
|---|
|  | 225 |  | 
|---|
| [a7a087] | 226 | bool World::changeMoleculeId(moleculeId_t oldId, moleculeId_t newId, molecule* target){ | 
|---|
|  | 227 | OBSERVE; | 
|---|
|  | 228 | // in case this call did not originate from inside the atom, we redirect it, | 
|---|
|  | 229 | // to also let it know that it has changed | 
|---|
|  | 230 | if(!target){ | 
|---|
|  | 231 | target = molecules[oldId]; | 
|---|
|  | 232 | ASSERT(target,"Molecule with that ID not found"); | 
|---|
|  | 233 | return target->changeId(newId); | 
|---|
|  | 234 | } | 
|---|
|  | 235 | else{ | 
|---|
|  | 236 | if(reserveMoleculeId(newId)){ | 
|---|
|  | 237 | molecules.erase(oldId); | 
|---|
|  | 238 | molecules.insert(pair<moleculeId_t,molecule*>(newId,target)); | 
|---|
|  | 239 | return true; | 
|---|
|  | 240 | } | 
|---|
|  | 241 | else{ | 
|---|
|  | 242 | return false; | 
|---|
|  | 243 | } | 
|---|
|  | 244 | } | 
|---|
|  | 245 | } | 
|---|
|  | 246 |  | 
|---|
| [7c4e29] | 247 | ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){ | 
|---|
| [e4afb4] | 248 | ActionTraits manipulateTrait(name); | 
|---|
|  | 249 | return new ManipulateAtomsProcess(op, descr,manipulateTrait,false); | 
|---|
| [7c4e29] | 250 | } | 
|---|
|  | 251 |  | 
|---|
| [0e2a47] | 252 | ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name){ | 
|---|
|  | 253 | return manipulateAtoms(op,name,AllAtoms()); | 
|---|
|  | 254 | } | 
|---|
|  | 255 |  | 
|---|
| [afb47f] | 256 | /********************* Internal Change methods for double Callback and Observer mechanism ********/ | 
|---|
|  | 257 |  | 
|---|
|  | 258 | void World::doManipulate(ManipulateAtomsProcess *proc){ | 
|---|
|  | 259 | proc->signOn(this); | 
|---|
|  | 260 | { | 
|---|
|  | 261 | OBSERVE; | 
|---|
|  | 262 | proc->doManipulate(this); | 
|---|
|  | 263 | } | 
|---|
|  | 264 | proc->signOff(this); | 
|---|
|  | 265 | } | 
|---|
| [88d586] | 266 | /******************************* IDManagement *****************************/ | 
|---|
|  | 267 |  | 
|---|
| [57adc7] | 268 | // Atoms | 
|---|
|  | 269 |  | 
|---|
| [88d586] | 270 | atomId_t World::getNextAtomId(){ | 
|---|
| [127a8e] | 271 | // try to find an Id in the pool; | 
|---|
|  | 272 | if(!atomIdPool.empty()){ | 
|---|
|  | 273 | atomIdPool_t::iterator iter=atomIdPool.begin(); | 
|---|
|  | 274 | atomId_t id = iter->first; | 
|---|
| [dc11c9] | 275 | range<atomId_t> newRange = makeRange(id+1,iter->last); | 
|---|
| [127a8e] | 276 | // we wont use this iterator anymore, so we don't care about invalidating | 
|---|
|  | 277 | atomIdPool.erase(iter); | 
|---|
| [dc11c9] | 278 | if(newRange.first<newRange.last){ | 
|---|
| [127a8e] | 279 | atomIdPool.insert(newRange); | 
|---|
|  | 280 | } | 
|---|
| [23b547] | 281 | return id; | 
|---|
| [88d586] | 282 | } | 
|---|
| [127a8e] | 283 | // Nothing in the pool... we are out of luck | 
|---|
|  | 284 | return currAtomId++; | 
|---|
| [88d586] | 285 | } | 
|---|
|  | 286 |  | 
|---|
|  | 287 | void World::releaseAtomId(atomId_t id){ | 
|---|
| [dc11c9] | 288 | atomIdPool.insert(makeRange(id,id+1)); | 
|---|
| [127a8e] | 289 | defragAtomIdPool(); | 
|---|
| [88d586] | 290 | } | 
|---|
| [afb47f] | 291 |  | 
|---|
| [88d586] | 292 | bool World::reserveAtomId(atomId_t id){ | 
|---|
|  | 293 | if(id>=currAtomId ){ | 
|---|
| [dc11c9] | 294 | range<atomId_t> newRange = makeRange(currAtomId,id); | 
|---|
|  | 295 | if(newRange.first<newRange.last){ | 
|---|
| [127a8e] | 296 | atomIdPool.insert(newRange); | 
|---|
| [88d586] | 297 | } | 
|---|
|  | 298 | currAtomId=id+1; | 
|---|
| [127a8e] | 299 | defragAtomIdPool(); | 
|---|
| [88d586] | 300 | return true; | 
|---|
|  | 301 | } | 
|---|
| [127a8e] | 302 | // look for a range that matches the request | 
|---|
|  | 303 | for(atomIdPool_t::iterator iter=atomIdPool.begin();iter!=atomIdPool.end();++iter){ | 
|---|
| [dc11c9] | 304 | if(iter->isBefore(id)){ | 
|---|
|  | 305 | // we have covered all available ranges... nothing to be found here | 
|---|
| [127a8e] | 306 | break; | 
|---|
|  | 307 | } | 
|---|
|  | 308 | // no need to check first, since it has to be <=id, since otherwise we would have broken out | 
|---|
| [dc11c9] | 309 | if(!iter->isBeyond(id)){ | 
|---|
| [127a8e] | 310 | // we found a matching range... get the id from this range | 
|---|
|  | 311 |  | 
|---|
|  | 312 | // split up this range at the point of id | 
|---|
| [dc11c9] | 313 | range<atomId_t> bottomRange = makeRange(iter->first,id); | 
|---|
|  | 314 | range<atomId_t> topRange = makeRange(id+1,iter->last); | 
|---|
| [127a8e] | 315 | // remove this range | 
|---|
|  | 316 | atomIdPool.erase(iter); | 
|---|
| [dc11c9] | 317 | if(bottomRange.first<bottomRange.last){ | 
|---|
| [127a8e] | 318 | atomIdPool.insert(bottomRange); | 
|---|
|  | 319 | } | 
|---|
| [dc11c9] | 320 | if(topRange.first<topRange.last){ | 
|---|
| [127a8e] | 321 | atomIdPool.insert(topRange); | 
|---|
|  | 322 | } | 
|---|
|  | 323 | defragAtomIdPool(); | 
|---|
|  | 324 | return true; | 
|---|
|  | 325 | } | 
|---|
| [88d586] | 326 | } | 
|---|
| [127a8e] | 327 | // this ID could not be reserved | 
|---|
|  | 328 | return false; | 
|---|
|  | 329 | } | 
|---|
|  | 330 |  | 
|---|
|  | 331 | void World::defragAtomIdPool(){ | 
|---|
|  | 332 | // check if the situation is bad enough to make defragging neccessary | 
|---|
|  | 333 | if((numAtomDefragSkips<MAX_FRAGMENTATION_SKIPS) && | 
|---|
|  | 334 | (atomIdPool.size()<lastAtomPoolSize+MAX_POOL_FRAGMENTATION)){ | 
|---|
|  | 335 | ++numAtomDefragSkips; | 
|---|
|  | 336 | return; | 
|---|
|  | 337 | } | 
|---|
|  | 338 | for(atomIdPool_t::iterator iter = atomIdPool.begin();iter!=atomIdPool.end();){ | 
|---|
|  | 339 | // see if this range is adjacent to the next one | 
|---|
|  | 340 | atomIdPool_t::iterator next = iter; | 
|---|
|  | 341 | next++; | 
|---|
| [dc11c9] | 342 | if(next!=atomIdPool.end() && (next->first==iter->last)){ | 
|---|
| [127a8e] | 343 | // merge the two ranges | 
|---|
| [dc11c9] | 344 | range<atomId_t> newRange = makeRange(iter->first,next->last); | 
|---|
| [127a8e] | 345 | atomIdPool.erase(iter); | 
|---|
|  | 346 | atomIdPool.erase(next); | 
|---|
|  | 347 | pair<atomIdPool_t::iterator,bool> res = atomIdPool.insert(newRange); | 
|---|
|  | 348 | ASSERT(res.second,"Id-Pool was confused"); | 
|---|
|  | 349 | iter=res.first; | 
|---|
|  | 350 | continue; | 
|---|
|  | 351 | } | 
|---|
|  | 352 | ++iter; | 
|---|
|  | 353 | } | 
|---|
|  | 354 | if(!atomIdPool.empty()){ | 
|---|
|  | 355 | // check if the last range is at the border | 
|---|
|  | 356 | atomIdPool_t::iterator iter = atomIdPool.end(); | 
|---|
|  | 357 | iter--; | 
|---|
| [dc11c9] | 358 | if(iter->last==currAtomId){ | 
|---|
| [127a8e] | 359 | currAtomId=iter->first; | 
|---|
|  | 360 | atomIdPool.erase(iter); | 
|---|
|  | 361 | } | 
|---|
| [88d586] | 362 | } | 
|---|
| [127a8e] | 363 | lastAtomPoolSize=atomIdPool.size(); | 
|---|
|  | 364 | numAtomDefragSkips=0; | 
|---|
| [88d586] | 365 | } | 
|---|
| [57adc7] | 366 |  | 
|---|
|  | 367 | // Molecules | 
|---|
|  | 368 |  | 
|---|
| [127a8e] | 369 | moleculeId_t World::getNextMoleculeId(){ | 
|---|
|  | 370 | // try to find an Id in the pool; | 
|---|
|  | 371 | if(!moleculeIdPool.empty()){ | 
|---|
|  | 372 | moleculeIdPool_t::iterator iter=moleculeIdPool.begin(); | 
|---|
|  | 373 | moleculeId_t id = iter->first; | 
|---|
| [dc11c9] | 374 | range<moleculeId_t> newRange = makeRange(id+1,iter->last); | 
|---|
| [127a8e] | 375 | // we wont use this iterator anymore, so we don't care about invalidating | 
|---|
|  | 376 | moleculeIdPool.erase(iter); | 
|---|
| [dc11c9] | 377 | if(newRange.first<newRange.last){ | 
|---|
| [127a8e] | 378 | moleculeIdPool.insert(newRange); | 
|---|
|  | 379 | } | 
|---|
|  | 380 | return id; | 
|---|
|  | 381 | } | 
|---|
|  | 382 | // Nothing in the pool... we are out of luck | 
|---|
|  | 383 | return currMoleculeId++; | 
|---|
|  | 384 | } | 
|---|
|  | 385 |  | 
|---|
|  | 386 | void World::releaseMoleculeId(moleculeId_t id){ | 
|---|
| [dc11c9] | 387 | moleculeIdPool.insert(makeRange(id,id+1)); | 
|---|
| [127a8e] | 388 | defragMoleculeIdPool(); | 
|---|
|  | 389 | } | 
|---|
|  | 390 |  | 
|---|
|  | 391 | bool World::reserveMoleculeId(moleculeId_t id){ | 
|---|
|  | 392 | if(id>=currMoleculeId ){ | 
|---|
| [dc11c9] | 393 | range<moleculeId_t> newRange = makeRange(currMoleculeId,id); | 
|---|
|  | 394 | if(newRange.first<newRange.last){ | 
|---|
| [127a8e] | 395 | moleculeIdPool.insert(newRange); | 
|---|
|  | 396 | } | 
|---|
|  | 397 | currMoleculeId=id+1; | 
|---|
|  | 398 | defragMoleculeIdPool(); | 
|---|
|  | 399 | return true; | 
|---|
|  | 400 | } | 
|---|
|  | 401 | // look for a range that matches the request | 
|---|
|  | 402 | for(moleculeIdPool_t::iterator iter=moleculeIdPool.begin();iter!=moleculeIdPool.end();++iter){ | 
|---|
| [dc11c9] | 403 | if(iter->isBefore(id)){ | 
|---|
| [127a8e] | 404 | // we have coverd all available ranges... nothing to be found here | 
|---|
|  | 405 | break; | 
|---|
|  | 406 | } | 
|---|
|  | 407 | // no need to check first, since it has to be <=id, since otherwise we would have broken out | 
|---|
| [dc11c9] | 408 | if(!iter->isBeyond(id)){ | 
|---|
| [127a8e] | 409 | // we found a matching range... get the id from this range | 
|---|
|  | 410 |  | 
|---|
|  | 411 | // split up this range at the point of id | 
|---|
| [dc11c9] | 412 | range<moleculeId_t> bottomRange = makeRange(iter->first,id); | 
|---|
|  | 413 | range<moleculeId_t> topRange = makeRange(id+1,iter->last); | 
|---|
| [127a8e] | 414 | // remove this range | 
|---|
|  | 415 | moleculeIdPool.erase(iter); | 
|---|
| [dc11c9] | 416 | if(bottomRange.first<bottomRange.last){ | 
|---|
| [127a8e] | 417 | moleculeIdPool.insert(bottomRange); | 
|---|
|  | 418 | } | 
|---|
| [dc11c9] | 419 | if(topRange.first<topRange.last){ | 
|---|
| [127a8e] | 420 | moleculeIdPool.insert(topRange); | 
|---|
|  | 421 | } | 
|---|
|  | 422 | defragMoleculeIdPool(); | 
|---|
|  | 423 | return true; | 
|---|
|  | 424 | } | 
|---|
|  | 425 | } | 
|---|
|  | 426 | // this ID could not be reserved | 
|---|
|  | 427 | return false; | 
|---|
|  | 428 | } | 
|---|
|  | 429 |  | 
|---|
|  | 430 | void World::defragMoleculeIdPool(){ | 
|---|
|  | 431 | // check if the situation is bad enough to make defragging neccessary | 
|---|
|  | 432 | if((numMoleculeDefragSkips<MAX_FRAGMENTATION_SKIPS) && | 
|---|
|  | 433 | (moleculeIdPool.size()<lastMoleculePoolSize+MAX_POOL_FRAGMENTATION)){ | 
|---|
|  | 434 | ++numMoleculeDefragSkips; | 
|---|
|  | 435 | return; | 
|---|
|  | 436 | } | 
|---|
|  | 437 | for(moleculeIdPool_t::iterator iter = moleculeIdPool.begin();iter!=moleculeIdPool.end();){ | 
|---|
|  | 438 | // see if this range is adjacent to the next one | 
|---|
|  | 439 | moleculeIdPool_t::iterator next = iter; | 
|---|
|  | 440 | next++; | 
|---|
| [dc11c9] | 441 | if(next!=moleculeIdPool.end() && (next->first==iter->last)){ | 
|---|
| [127a8e] | 442 | // merge the two ranges | 
|---|
| [dc11c9] | 443 | range<moleculeId_t> newRange = makeRange(iter->first,next->last); | 
|---|
| [127a8e] | 444 | moleculeIdPool.erase(iter); | 
|---|
|  | 445 | moleculeIdPool.erase(next); | 
|---|
|  | 446 | pair<moleculeIdPool_t::iterator,bool> res = moleculeIdPool.insert(newRange); | 
|---|
|  | 447 | ASSERT(res.second,"Id-Pool was confused"); | 
|---|
|  | 448 | iter=res.first; | 
|---|
|  | 449 | continue; | 
|---|
|  | 450 | } | 
|---|
|  | 451 | ++iter; | 
|---|
|  | 452 | } | 
|---|
|  | 453 | if(!moleculeIdPool.empty()){ | 
|---|
|  | 454 | // check if the last range is at the border | 
|---|
|  | 455 | moleculeIdPool_t::iterator iter = moleculeIdPool.end(); | 
|---|
|  | 456 | iter--; | 
|---|
| [dc11c9] | 457 | if(iter->last==currMoleculeId){ | 
|---|
| [127a8e] | 458 | currMoleculeId=iter->first; | 
|---|
|  | 459 | moleculeIdPool.erase(iter); | 
|---|
|  | 460 | } | 
|---|
|  | 461 | } | 
|---|
|  | 462 | lastMoleculePoolSize=moleculeIdPool.size(); | 
|---|
|  | 463 | numMoleculeDefragSkips=0; | 
|---|
|  | 464 | } | 
|---|
|  | 465 |  | 
|---|
| [865a945] | 466 | /******************************* Iterators ********************************/ | 
|---|
|  | 467 |  | 
|---|
| [fa0b18] | 468 | // external parts with observers | 
|---|
|  | 469 |  | 
|---|
| [6e97e5] | 470 | CONSTRUCT_SELECTIVE_ITERATOR(atom*,World::AtomSet,AtomDescriptor); | 
|---|
|  | 471 |  | 
|---|
| [fa0b18] | 472 | World::AtomIterator | 
|---|
|  | 473 | World::getAtomIter(AtomDescriptor descr){ | 
|---|
|  | 474 | return AtomIterator(descr,atoms); | 
|---|
|  | 475 | } | 
|---|
| [865a945] | 476 |  | 
|---|
| [fa0b18] | 477 | World::AtomIterator | 
|---|
|  | 478 | World::getAtomIter(){ | 
|---|
|  | 479 | return AtomIterator(AllAtoms(),atoms); | 
|---|
| [865a945] | 480 | } | 
|---|
| [354859] | 481 |  | 
|---|
| [fa0b18] | 482 | World::AtomIterator | 
|---|
|  | 483 | World::atomEnd(){ | 
|---|
| [6e97e5] | 484 | return AtomIterator(AllAtoms(),atoms,atoms.end()); | 
|---|
| [7c4e29] | 485 | } | 
|---|
|  | 486 |  | 
|---|
| [6e97e5] | 487 | CONSTRUCT_SELECTIVE_ITERATOR(molecule*,World::MoleculeSet,MoleculeDescriptor); | 
|---|
|  | 488 |  | 
|---|
| [5d880e] | 489 | World::MoleculeIterator | 
|---|
|  | 490 | World::getMoleculeIter(MoleculeDescriptor descr){ | 
|---|
|  | 491 | return MoleculeIterator(descr,molecules); | 
|---|
|  | 492 | } | 
|---|
|  | 493 |  | 
|---|
|  | 494 | World::MoleculeIterator | 
|---|
|  | 495 | World::getMoleculeIter(){ | 
|---|
|  | 496 | return MoleculeIterator(AllMolecules(),molecules); | 
|---|
| [1c51c8] | 497 | } | 
|---|
|  | 498 |  | 
|---|
| [5d880e] | 499 | World::MoleculeIterator | 
|---|
|  | 500 | World::moleculeEnd(){ | 
|---|
| [6e97e5] | 501 | return MoleculeIterator(AllMolecules(),molecules,molecules.end()); | 
|---|
| [1c51c8] | 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(){ | 
|---|
|  | 536 | selectedAtoms.clear(); | 
|---|
|  | 537 | } | 
|---|
|  | 538 |  | 
|---|
| [e4afb4] | 539 | void World::selectAtom(const atom *_atom){ | 
|---|
|  | 540 | // atom * is unchanged in this function, but we do store entity as changeable | 
|---|
|  | 541 | ASSERT(_atom,"Invalid pointer in selection of atom"); | 
|---|
|  | 542 | selectedAtoms[_atom->getId()]=const_cast<atom *>(_atom); | 
|---|
| [90c4280] | 543 | } | 
|---|
|  | 544 |  | 
|---|
| [e4afb4] | 545 | void World::selectAtom(const atomId_t id){ | 
|---|
| [90c4280] | 546 | ASSERT(atoms.count(id),"Atom Id selected that was not in the world"); | 
|---|
|  | 547 | selectedAtoms[id]=atoms[id]; | 
|---|
|  | 548 | } | 
|---|
|  | 549 |  | 
|---|
|  | 550 | void World::selectAllAtoms(AtomDescriptor descr){ | 
|---|
|  | 551 | internal_AtomIterator begin = getAtomIter_internal(descr); | 
|---|
|  | 552 | internal_AtomIterator end = atomEnd_internal(); | 
|---|
| [e4afb4] | 553 | void (World::*func)(const atom*) = &World::selectAtom; // needed for type resolution of overloaded function | 
|---|
| [90c4280] | 554 | for_each(begin,end,bind1st(mem_fun(func),this)); // func is select... see above | 
|---|
|  | 555 | } | 
|---|
|  | 556 |  | 
|---|
| [e4afb4] | 557 | void World::selectAtomsOfMolecule(const molecule *_mol){ | 
|---|
| [90c4280] | 558 | ASSERT(_mol,"Invalid pointer to molecule in selection of Atoms of Molecule"); | 
|---|
|  | 559 | // need to make it const to get the fast iterators | 
|---|
|  | 560 | const molecule *mol = _mol; | 
|---|
| [e4afb4] | 561 | void (World::*func)(const atom*) = &World::selectAtom; // needed for type resolution of overloaded function | 
|---|
| [90c4280] | 562 | for_each(mol->begin(),mol->end(),bind1st(mem_fun(func),this)); // func is select... see above | 
|---|
|  | 563 | } | 
|---|
|  | 564 |  | 
|---|
| [e4afb4] | 565 | void World::selectAtomsOfMolecule(const moleculeId_t id){ | 
|---|
| [90c4280] | 566 | ASSERT(molecules.count(id),"No molecule with the given id upon Selection of atoms from molecule"); | 
|---|
|  | 567 | selectAtomsOfMolecule(molecules[id]); | 
|---|
|  | 568 | } | 
|---|
|  | 569 |  | 
|---|
| [e4afb4] | 570 | void World::unselectAtom(const atom *_atom){ | 
|---|
|  | 571 | ASSERT(_atom,"Invalid pointer in unselection of atom"); | 
|---|
|  | 572 | unselectAtom(_atom->getId()); | 
|---|
| [61d655e] | 573 | } | 
|---|
|  | 574 |  | 
|---|
| [e4afb4] | 575 | void World::unselectAtom(const atomId_t id){ | 
|---|
| [61d655e] | 576 | ASSERT(atoms.count(id),"Atom Id unselected that was not in the world"); | 
|---|
|  | 577 | selectedAtoms.erase(id); | 
|---|
|  | 578 | } | 
|---|
|  | 579 |  | 
|---|
|  | 580 | void World::unselectAllAtoms(AtomDescriptor descr){ | 
|---|
|  | 581 | internal_AtomIterator begin = getAtomIter_internal(descr); | 
|---|
|  | 582 | internal_AtomIterator end = atomEnd_internal(); | 
|---|
| [e4afb4] | 583 | void (World::*func)(const atom*) = &World::unselectAtom; // needed for type resolution of overloaded function | 
|---|
| [61d655e] | 584 | for_each(begin,end,bind1st(mem_fun(func),this)); // func is unselect... see above | 
|---|
|  | 585 | } | 
|---|
|  | 586 |  | 
|---|
| [e4afb4] | 587 | void World::unselectAtomsOfMolecule(const molecule *_mol){ | 
|---|
| [61d655e] | 588 | ASSERT(_mol,"Invalid pointer to molecule in selection of Atoms of Molecule"); | 
|---|
|  | 589 | // need to make it const to get the fast iterators | 
|---|
|  | 590 | const molecule *mol = _mol; | 
|---|
| [e4afb4] | 591 | void (World::*func)(const atom*) = &World::unselectAtom; // needed for type resolution of overloaded function | 
|---|
| [61d655e] | 592 | for_each(mol->begin(),mol->end(),bind1st(mem_fun(func),this)); // func is unsselect... see above | 
|---|
|  | 593 | } | 
|---|
|  | 594 |  | 
|---|
| [e4afb4] | 595 | void World::unselectAtomsOfMolecule(const moleculeId_t id){ | 
|---|
| [61d655e] | 596 | ASSERT(molecules.count(id),"No molecule with the given id upon Selection of atoms from molecule"); | 
|---|
|  | 597 | unselectAtomsOfMolecule(molecules[id]); | 
|---|
|  | 598 | } | 
|---|
|  | 599 |  | 
|---|
| [e472eab] | 600 | size_t World::countSelectedAtoms() const { | 
|---|
| [eacc3b] | 601 | size_t count = 0; | 
|---|
| [e472eab] | 602 | for (AtomSet::const_iterator iter = selectedAtoms.begin(); iter != selectedAtoms.end(); ++iter) | 
|---|
| [eacc3b] | 603 | count++; | 
|---|
|  | 604 | return count; | 
|---|
|  | 605 | } | 
|---|
|  | 606 |  | 
|---|
| [e4afb4] | 607 | bool World::isSelected(const atom *_atom) const { | 
|---|
|  | 608 | return selectedAtoms.find(_atom->getId()) != selectedAtoms.end(); | 
|---|
| [e0e156] | 609 | } | 
|---|
|  | 610 |  | 
|---|
| [e472eab] | 611 | const std::vector<atom *> World::getSelectedAtoms() const { | 
|---|
|  | 612 | std::vector<atom *> returnAtoms; | 
|---|
|  | 613 | returnAtoms.resize(countSelectedAtoms()); | 
|---|
|  | 614 | int count = 0; | 
|---|
|  | 615 | for (AtomSet::const_iterator iter = selectedAtoms.begin(); iter != selectedAtoms.end(); ++iter) | 
|---|
|  | 616 | returnAtoms[count++] = iter->second; | 
|---|
|  | 617 | return returnAtoms; | 
|---|
|  | 618 | } | 
|---|
|  | 619 |  | 
|---|
|  | 620 |  | 
|---|
| [90c4280] | 621 | // Molecules | 
|---|
|  | 622 |  | 
|---|
|  | 623 | void World::clearMoleculeSelection(){ | 
|---|
|  | 624 | selectedMolecules.clear(); | 
|---|
|  | 625 | } | 
|---|
|  | 626 |  | 
|---|
| [e4afb4] | 627 | void World::selectMolecule(const molecule *_mol){ | 
|---|
|  | 628 | // molecule * is unchanged in this function, but we do store entity as changeable | 
|---|
|  | 629 | ASSERT(_mol,"Invalid pointer to molecule in selection"); | 
|---|
|  | 630 | selectedMolecules[_mol->getId()]=const_cast<molecule *>(_mol); | 
|---|
| [90c4280] | 631 | } | 
|---|
|  | 632 |  | 
|---|
| [e4afb4] | 633 | void World::selectMolecule(const moleculeId_t id){ | 
|---|
| [90c4280] | 634 | ASSERT(molecules.count(id),"Molecule Id selected that was not in the world"); | 
|---|
|  | 635 | selectedMolecules[id]=molecules[id]; | 
|---|
|  | 636 | } | 
|---|
|  | 637 |  | 
|---|
| [e472eab] | 638 | void World::selectAllMolecules(MoleculeDescriptor descr){ | 
|---|
| [90c4280] | 639 | internal_MoleculeIterator begin = getMoleculeIter_internal(descr); | 
|---|
|  | 640 | internal_MoleculeIterator end = moleculeEnd_internal(); | 
|---|
| [e4afb4] | 641 | void (World::*func)(const molecule*) = &World::selectMolecule; // needed for type resolution of overloaded function | 
|---|
| [90c4280] | 642 | for_each(begin,end,bind1st(mem_fun(func),this)); // func is select... see above | 
|---|
|  | 643 | } | 
|---|
|  | 644 |  | 
|---|
| [e4afb4] | 645 | void World::selectMoleculeOfAtom(const atom *_atom){ | 
|---|
|  | 646 | ASSERT(_atom,"Invalid atom pointer in selection of MoleculeOfAtom"); | 
|---|
|  | 647 | molecule *mol=_atom->getMolecule(); | 
|---|
| [90c4280] | 648 | // the atom might not be part of a molecule | 
|---|
|  | 649 | if(mol){ | 
|---|
|  | 650 | selectMolecule(mol); | 
|---|
|  | 651 | } | 
|---|
|  | 652 | } | 
|---|
|  | 653 |  | 
|---|
| [e4afb4] | 654 | void World::selectMoleculeOfAtom(const atomId_t id){ | 
|---|
| [90c4280] | 655 | ASSERT(atoms.count(id),"No such atom with given ID in selection of Molecules of Atom");\ | 
|---|
|  | 656 | selectMoleculeOfAtom(atoms[id]); | 
|---|
|  | 657 | } | 
|---|
|  | 658 |  | 
|---|
| [e4afb4] | 659 | void World::unselectMolecule(const molecule *_mol){ | 
|---|
|  | 660 | ASSERT(_mol,"invalid pointer in unselection of molecule"); | 
|---|
|  | 661 | unselectMolecule(_mol->getId()); | 
|---|
| [61d655e] | 662 | } | 
|---|
|  | 663 |  | 
|---|
| [e4afb4] | 664 | void World::unselectMolecule(const moleculeId_t id){ | 
|---|
| [61d655e] | 665 | ASSERT(molecules.count(id),"No such molecule with ID in unselection"); | 
|---|
|  | 666 | selectedMolecules.erase(id); | 
|---|
|  | 667 | } | 
|---|
|  | 668 |  | 
|---|
| [e472eab] | 669 | void World::unselectAllMolecules(MoleculeDescriptor descr){ | 
|---|
| [61d655e] | 670 | internal_MoleculeIterator begin = getMoleculeIter_internal(descr); | 
|---|
|  | 671 | internal_MoleculeIterator end = moleculeEnd_internal(); | 
|---|
| [e4afb4] | 672 | void (World::*func)(const molecule*) = &World::unselectMolecule; // needed for type resolution of overloaded function | 
|---|
| [61d655e] | 673 | for_each(begin,end,bind1st(mem_fun(func),this)); // func is unselect... see above | 
|---|
|  | 674 | } | 
|---|
|  | 675 |  | 
|---|
| [e4afb4] | 676 | void World::unselectMoleculeOfAtom(const atom *_atom){ | 
|---|
|  | 677 | ASSERT(_atom,"Invalid atom pointer in selection of MoleculeOfAtom"); | 
|---|
|  | 678 | molecule *mol=_atom->getMolecule(); | 
|---|
| [61d655e] | 679 | // the atom might not be part of a molecule | 
|---|
|  | 680 | if(mol){ | 
|---|
|  | 681 | unselectMolecule(mol); | 
|---|
|  | 682 | } | 
|---|
|  | 683 | } | 
|---|
|  | 684 |  | 
|---|
| [e4afb4] | 685 | void World::unselectMoleculeOfAtom(const atomId_t id){ | 
|---|
| [61d655e] | 686 | ASSERT(atoms.count(id),"No such atom with given ID in selection of Molecules of Atom");\ | 
|---|
|  | 687 | unselectMoleculeOfAtom(atoms[id]); | 
|---|
|  | 688 | } | 
|---|
|  | 689 |  | 
|---|
| [e472eab] | 690 | size_t World::countSelectedMolecules() const { | 
|---|
| [eacc3b] | 691 | size_t count = 0; | 
|---|
| [e472eab] | 692 | for (MoleculeSet::const_iterator iter = selectedMolecules.begin(); iter != selectedMolecules.end(); ++iter) | 
|---|
| [eacc3b] | 693 | count++; | 
|---|
|  | 694 | return count; | 
|---|
|  | 695 | } | 
|---|
|  | 696 |  | 
|---|
| [e4afb4] | 697 | bool World::isSelected(const molecule *_mol) const { | 
|---|
|  | 698 | return selectedMolecules.find(_mol->getId()) != selectedMolecules.end(); | 
|---|
| [e0e156] | 699 | } | 
|---|
|  | 700 |  | 
|---|
| [e472eab] | 701 | const std::vector<molecule *> World::getSelectedMolecules() const { | 
|---|
|  | 702 | std::vector<molecule *> returnMolecules; | 
|---|
|  | 703 | returnMolecules.resize(countSelectedMolecules()); | 
|---|
|  | 704 | int count = 0; | 
|---|
|  | 705 | for (MoleculeSet::const_iterator iter = selectedMolecules.begin(); iter != selectedMolecules.end(); ++iter) | 
|---|
|  | 706 | returnMolecules[count++] = iter->second; | 
|---|
|  | 707 | return returnMolecules; | 
|---|
|  | 708 | } | 
|---|
|  | 709 |  | 
|---|
| [3839e5] | 710 | /******************* Iterators over Selection *****************************/ | 
|---|
|  | 711 | World::AtomSelectionIterator World::beginAtomSelection(){ | 
|---|
|  | 712 | return selectedAtoms.begin(); | 
|---|
|  | 713 | } | 
|---|
|  | 714 |  | 
|---|
|  | 715 | World::AtomSelectionIterator World::endAtomSelection(){ | 
|---|
|  | 716 | return selectedAtoms.end(); | 
|---|
|  | 717 | } | 
|---|
|  | 718 |  | 
|---|
|  | 719 |  | 
|---|
|  | 720 | World::MoleculeSelectionIterator World::beginMoleculeSelection(){ | 
|---|
|  | 721 | return selectedMolecules.begin(); | 
|---|
|  | 722 | } | 
|---|
|  | 723 |  | 
|---|
|  | 724 | World::MoleculeSelectionIterator World::endMoleculeSelection(){ | 
|---|
|  | 725 | return selectedMolecules.end(); | 
|---|
|  | 726 | } | 
|---|
|  | 727 |  | 
|---|
| [5d1611] | 728 | /******************************* Singleton Stuff **************************/ | 
|---|
|  | 729 |  | 
|---|
| [7a1ce5] | 730 | World::World() : | 
|---|
| [cd5047] | 731 | Observable("World"), | 
|---|
| [354859] | 732 | periode(new periodentafel), | 
|---|
| [8e1f7af] | 733 | configuration(new config), | 
|---|
| [43dad6] | 734 | Thermostats(new ThermoStatContainer), | 
|---|
| [e4b5de] | 735 | ExitFlag(0), | 
|---|
| [fa0b18] | 736 | atoms(this), | 
|---|
| [90c4280] | 737 | selectedAtoms(this), | 
|---|
| [24a5e0] | 738 | currAtomId(0), | 
|---|
| [127a8e] | 739 | lastAtomPoolSize(0), | 
|---|
|  | 740 | numAtomDefragSkips(0), | 
|---|
| [51be2a] | 741 | molecules(this), | 
|---|
| [90c4280] | 742 | selectedMolecules(this), | 
|---|
| [24a5e0] | 743 | currMoleculeId(0), | 
|---|
| [654394] | 744 | lastMoleculePoolSize(0), | 
|---|
|  | 745 | numMoleculeDefragSkips(0), | 
|---|
| [24a5e0] | 746 | molecules_deprecated(new MoleculeListClass(this)) | 
|---|
| [7dad10] | 747 | { | 
|---|
| [84c494] | 748 | cell_size = new Box; | 
|---|
| [cca9ef] | 749 | RealSpaceMatrix domain; | 
|---|
| [84c494] | 750 | domain.at(0,0) = 20; | 
|---|
|  | 751 | domain.at(1,1) = 20; | 
|---|
|  | 752 | domain.at(2,2) = 20; | 
|---|
|  | 753 | cell_size->setM(domain); | 
|---|
| [387b36] | 754 | defaultName = "none"; | 
|---|
| [7dad10] | 755 | molecules_deprecated->signOn(this); | 
|---|
|  | 756 | } | 
|---|
| [5d1611] | 757 |  | 
|---|
|  | 758 | World::~World() | 
|---|
| [354859] | 759 | { | 
|---|
| [028c2e] | 760 | molecules_deprecated->signOff(this); | 
|---|
| [84c494] | 761 | delete cell_size; | 
|---|
| [46d958] | 762 | delete molecules_deprecated; | 
|---|
| [cbc5fb] | 763 | MoleculeSet::iterator molIter; | 
|---|
|  | 764 | for(molIter=molecules.begin();molIter!=molecules.end();++molIter){ | 
|---|
|  | 765 | DeleteMolecule((*molIter).second); | 
|---|
|  | 766 | } | 
|---|
|  | 767 | molecules.clear(); | 
|---|
|  | 768 | AtomSet::iterator atIter; | 
|---|
|  | 769 | for(atIter=atoms.begin();atIter!=atoms.end();++atIter){ | 
|---|
|  | 770 | DeleteAtom((*atIter).second); | 
|---|
| [46d958] | 771 | } | 
|---|
|  | 772 | atoms.clear(); | 
|---|
| [6cb9c76] | 773 | delete periode; | 
|---|
|  | 774 | delete configuration; | 
|---|
|  | 775 | delete Thermostats; | 
|---|
| [354859] | 776 | } | 
|---|
| [5d1611] | 777 |  | 
|---|
| [23b547] | 778 | // Explicit instantiation of the singleton mechanism at this point | 
|---|
| [5d1611] | 779 |  | 
|---|
| [23b547] | 780 | CONSTRUCT_SINGLETON(World) | 
|---|
| [5d1611] | 781 |  | 
|---|
| [5f1d5b8] | 782 | CONSTRUCT_OBSERVEDCONTAINER(World::AtomSTLSet) | 
|---|
|  | 783 |  | 
|---|
|  | 784 | CONSTRUCT_OBSERVEDCONTAINER(World::MoleculeSTLSet) | 
|---|
|  | 785 |  | 
|---|
| [5d1611] | 786 | /******************************* deprecated Legacy Stuff ***********************/ | 
|---|
|  | 787 |  | 
|---|
| [354859] | 788 | MoleculeListClass *&World::getMolecules() { | 
|---|
|  | 789 | return molecules_deprecated; | 
|---|
| [5d1611] | 790 | } | 
|---|