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