| [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" | 
|---|
| [d297a3] | 44 | #include "Box.hpp" | 
|---|
|  | 45 | #include "CodePatterns/Assert.hpp" | 
|---|
| [8e1f7af] | 46 | #include "config.hpp" | 
|---|
| [fc1b24] | 47 | #include "Descriptors/AtomDescriptor.hpp" | 
|---|
| [865a945] | 48 | #include "Descriptors/AtomDescriptor_impl.hpp" | 
|---|
| [ebc499] | 49 | #include "Descriptors/AtomSelectionDescriptor.hpp" | 
|---|
| [1c51c8] | 50 | #include "Descriptors/MoleculeDescriptor.hpp" | 
|---|
|  | 51 | #include "Descriptors/MoleculeDescriptor_impl.hpp" | 
|---|
| [ebc499] | 52 | #include "Descriptors/MoleculeSelectionDescriptor.hpp" | 
|---|
| [feb5d0] | 53 | #include "Descriptors/SelectiveConstIterator_impl.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 |  | 
|---|
| [03abd0] | 156 | LinkedCell::LinkedCell_View World::getLinkedCell(double distance) | 
|---|
| [4834f4] | 157 | { | 
|---|
| [03abd0] | 158 | ASSERT( distance > 0, | 
|---|
|  | 159 | "World::getLinkedCell() - distance is not positive."); | 
|---|
|  | 160 | if (distance < 1.) { | 
|---|
|  | 161 | ELOG(2, "Linked cell grid with length less than 1. is very memory-intense!"); | 
|---|
|  | 162 | distance = 1.; | 
|---|
|  | 163 | } | 
|---|
| [4834f4] | 164 | // we have to grope past the ObservedContainer mechanism and transmorph the map | 
|---|
|  | 165 | // into a traversable list for the adaptor | 
|---|
|  | 166 | PointCloudAdaptor< AtomSet::set_t, MapValueIterator<AtomSet::set_t::iterator> > atomset( | 
|---|
|  | 167 | &(atoms.getContent()), | 
|---|
|  | 168 | std::string("WorldsAtoms")); | 
|---|
|  | 169 | return LCcontroller->getView(distance, atomset); | 
|---|
|  | 170 | } | 
|---|
|  | 171 |  | 
|---|
| [d297a3] | 172 | void World::setTime(const unsigned int _step) | 
|---|
|  | 173 | { | 
|---|
| [76163d] | 174 | if (_step != WorldTime::getTime()) { | 
|---|
|  | 175 | // set new time | 
|---|
| [040a5c] | 176 | WorldTime::getInstance().setTime(_step); | 
|---|
| [4b8630] | 177 | // TODO: removed when BondGraph creates the adjacency | 
|---|
|  | 178 | // 1. remove all of World's molecules | 
|---|
|  | 179 | for (MoleculeIterator iter = getMoleculeIter(); | 
|---|
|  | 180 | getMoleculeIter() != moleculeEnd(); | 
|---|
|  | 181 | iter = getMoleculeIter()) { | 
|---|
|  | 182 | getMolecules()->erase(*iter); | 
|---|
|  | 183 | destroyMolecule(*iter); | 
|---|
|  | 184 | } | 
|---|
|  | 185 | // 2. (re-)create bondgraph | 
|---|
|  | 186 | AtomComposite Set = getAllAtoms(); | 
|---|
|  | 187 | BG->CreateAdjacency(Set); | 
|---|
|  | 188 |  | 
|---|
|  | 189 | // 3. scan for connected subgraphs => molecules | 
|---|
|  | 190 | DepthFirstSearchAnalysis DFS; | 
|---|
|  | 191 | DFS(); | 
|---|
|  | 192 | DFS.UpdateMoleculeStructure(); | 
|---|
| [76163d] | 193 | } | 
|---|
| [d297a3] | 194 | } | 
|---|
|  | 195 |  | 
|---|
| [387b36] | 196 | std::string World::getDefaultName() { | 
|---|
| [5f612ee] | 197 | return defaultName; | 
|---|
|  | 198 | } | 
|---|
|  | 199 |  | 
|---|
| [387b36] | 200 | void World::setDefaultName(std::string name) | 
|---|
| [5f612ee] | 201 | { | 
|---|
| [be97a8] | 202 | OBSERVE; | 
|---|
| [387b36] | 203 | defaultName = name; | 
|---|
| [5f612ee] | 204 | }; | 
|---|
|  | 205 |  | 
|---|
| [43dad6] | 206 | class ThermoStatContainer * World::getThermostats() | 
|---|
|  | 207 | { | 
|---|
|  | 208 | return Thermostats; | 
|---|
|  | 209 | } | 
|---|
|  | 210 |  | 
|---|
|  | 211 |  | 
|---|
| [e4b5de] | 212 | int World::getExitFlag() { | 
|---|
|  | 213 | return ExitFlag; | 
|---|
|  | 214 | } | 
|---|
|  | 215 |  | 
|---|
|  | 216 | void World::setExitFlag(int flag) { | 
|---|
|  | 217 | if (ExitFlag < flag) | 
|---|
|  | 218 | ExitFlag = flag; | 
|---|
|  | 219 | } | 
|---|
| [5f612ee] | 220 |  | 
|---|
| [afb47f] | 221 | /******************** Methods to change World state *********************/ | 
|---|
|  | 222 |  | 
|---|
| [354859] | 223 | molecule* World::createMolecule(){ | 
|---|
|  | 224 | OBSERVE; | 
|---|
|  | 225 | molecule *mol = NULL; | 
|---|
| [cbc5fb] | 226 | mol = NewMolecule(); | 
|---|
| [3e4fb6] | 227 | moleculeId_t id = moleculeIdPool.getNextId(); | 
|---|
| [127a8e] | 228 | ASSERT(!molecules.count(id),"proposed id did not specify an unused ID"); | 
|---|
|  | 229 | mol->setId(id); | 
|---|
| [244d26] | 230 | // store the molecule by ID | 
|---|
| [cbc5fb] | 231 | molecules[mol->getId()] = mol; | 
|---|
| [354859] | 232 | mol->signOn(this); | 
|---|
| [7188b1] | 233 | _lastchangedmol = mol; | 
|---|
|  | 234 | NOTIFY(MoleculeInserted); | 
|---|
| [354859] | 235 | return mol; | 
|---|
|  | 236 | } | 
|---|
|  | 237 |  | 
|---|
| [cbc5fb] | 238 | void World::destroyMolecule(molecule* mol){ | 
|---|
|  | 239 | OBSERVE; | 
|---|
| [fa7989] | 240 | ASSERT(mol,"Molecule that was meant to be destroyed did not exist"); | 
|---|
| [cbc5fb] | 241 | destroyMolecule(mol->getId()); | 
|---|
|  | 242 | } | 
|---|
|  | 243 |  | 
|---|
|  | 244 | void World::destroyMolecule(moleculeId_t id){ | 
|---|
|  | 245 | molecule *mol = molecules[id]; | 
|---|
| [6d574a] | 246 | ASSERT(mol,"Molecule id that was meant to be destroyed did not exist"); | 
|---|
| [38f991] | 247 | // give notice about immediate removal | 
|---|
|  | 248 | { | 
|---|
|  | 249 | OBSERVE; | 
|---|
|  | 250 | _lastchangedmol = mol; | 
|---|
|  | 251 | NOTIFY(MoleculeRemoved); | 
|---|
|  | 252 | } | 
|---|
| [7d82a5] | 253 | mol->signOff(this); | 
|---|
| [cbc5fb] | 254 | DeleteMolecule(mol); | 
|---|
| [38f991] | 255 | if (isMoleculeSelected(id)) | 
|---|
|  | 256 | selectedMolecules.erase(id); | 
|---|
| [cbc5fb] | 257 | molecules.erase(id); | 
|---|
| [3e4fb6] | 258 | moleculeIdPool.releaseId(id); | 
|---|
| [cbc5fb] | 259 | } | 
|---|
|  | 260 |  | 
|---|
| [46d958] | 261 | atom *World::createAtom(){ | 
|---|
|  | 262 | OBSERVE; | 
|---|
| [3e4fb6] | 263 | atomId_t id = atomIdPool.getNextId(); | 
|---|
| [127a8e] | 264 | ASSERT(!atoms.count(id),"proposed id did not specify an unused ID"); | 
|---|
| [88d586] | 265 | atom *res = NewAtom(id); | 
|---|
| [46d958] | 266 | res->setWorld(this); | 
|---|
| [244d26] | 267 | // store the atom by ID | 
|---|
| [46d958] | 268 | atoms[res->getId()] = res; | 
|---|
| [7188b1] | 269 | _lastchangedatom = res; | 
|---|
|  | 270 | NOTIFY(AtomInserted); | 
|---|
| [46d958] | 271 | return res; | 
|---|
|  | 272 | } | 
|---|
|  | 273 |  | 
|---|
| [5f612ee] | 274 |  | 
|---|
| [46d958] | 275 | int World::registerAtom(atom *atom){ | 
|---|
|  | 276 | OBSERVE; | 
|---|
| [3e4fb6] | 277 | atomId_t id = atomIdPool.getNextId(); | 
|---|
| [88d586] | 278 | atom->setId(id); | 
|---|
| [46d958] | 279 | atom->setWorld(this); | 
|---|
|  | 280 | atoms[atom->getId()] = atom; | 
|---|
| [65d7ca] | 281 | _lastchangedatom = atom; | 
|---|
|  | 282 | NOTIFY(AtomInserted); | 
|---|
| [46d958] | 283 | return atom->getId(); | 
|---|
|  | 284 | } | 
|---|
|  | 285 |  | 
|---|
|  | 286 | void World::destroyAtom(atom* atom){ | 
|---|
|  | 287 | int id = atom->getId(); | 
|---|
|  | 288 | destroyAtom(id); | 
|---|
|  | 289 | } | 
|---|
|  | 290 |  | 
|---|
| [cbc5fb] | 291 | void World::destroyAtom(atomId_t id) { | 
|---|
| [46d958] | 292 | atom *atom = atoms[id]; | 
|---|
| [6d574a] | 293 | ASSERT(atom,"Atom ID that was meant to be destroyed did not exist"); | 
|---|
| [ab4a33] | 294 | // give notice about immediate removal | 
|---|
|  | 295 | { | 
|---|
|  | 296 | OBSERVE; | 
|---|
|  | 297 | _lastchangedatom = atom; | 
|---|
|  | 298 | NOTIFY(AtomRemoved); | 
|---|
|  | 299 | } | 
|---|
| [46d958] | 300 | DeleteAtom(atom); | 
|---|
| [38f991] | 301 | if (isAtomSelected(id)) | 
|---|
|  | 302 | selectedAtoms.erase(id); | 
|---|
| [46d958] | 303 | atoms.erase(id); | 
|---|
| [3e4fb6] | 304 | atomIdPool.releaseId(id); | 
|---|
| [88d586] | 305 | } | 
|---|
|  | 306 |  | 
|---|
|  | 307 | bool World::changeAtomId(atomId_t oldId, atomId_t newId, atom* target){ | 
|---|
|  | 308 | OBSERVE; | 
|---|
|  | 309 | // in case this call did not originate from inside the atom, we redirect it, | 
|---|
|  | 310 | // to also let it know that it has changed | 
|---|
|  | 311 | if(!target){ | 
|---|
|  | 312 | target = atoms[oldId]; | 
|---|
| [6d574a] | 313 | ASSERT(target,"Atom with that ID not found"); | 
|---|
| [88d586] | 314 | return target->changeId(newId); | 
|---|
|  | 315 | } | 
|---|
|  | 316 | else{ | 
|---|
| [3e4fb6] | 317 | if(atomIdPool.reserveId(newId)){ | 
|---|
| [88d586] | 318 | atoms.erase(oldId); | 
|---|
|  | 319 | atoms.insert(pair<atomId_t,atom*>(newId,target)); | 
|---|
|  | 320 | return true; | 
|---|
|  | 321 | } | 
|---|
|  | 322 | else{ | 
|---|
|  | 323 | return false; | 
|---|
|  | 324 | } | 
|---|
|  | 325 | } | 
|---|
| [46d958] | 326 | } | 
|---|
|  | 327 |  | 
|---|
| [a7a087] | 328 | bool World::changeMoleculeId(moleculeId_t oldId, moleculeId_t newId, molecule* target){ | 
|---|
|  | 329 | OBSERVE; | 
|---|
|  | 330 | // in case this call did not originate from inside the atom, we redirect it, | 
|---|
|  | 331 | // to also let it know that it has changed | 
|---|
|  | 332 | if(!target){ | 
|---|
|  | 333 | target = molecules[oldId]; | 
|---|
|  | 334 | ASSERT(target,"Molecule with that ID not found"); | 
|---|
|  | 335 | return target->changeId(newId); | 
|---|
|  | 336 | } | 
|---|
|  | 337 | else{ | 
|---|
| [3e4fb6] | 338 | if(moleculeIdPool.reserveId(newId)){ | 
|---|
| [a7a087] | 339 | molecules.erase(oldId); | 
|---|
|  | 340 | molecules.insert(pair<moleculeId_t,molecule*>(newId,target)); | 
|---|
|  | 341 | return true; | 
|---|
|  | 342 | } | 
|---|
|  | 343 | else{ | 
|---|
|  | 344 | return false; | 
|---|
|  | 345 | } | 
|---|
|  | 346 | } | 
|---|
|  | 347 | } | 
|---|
|  | 348 |  | 
|---|
| [7c4e29] | 349 | ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){ | 
|---|
| [3139b2] | 350 | ActionTrait manipulateTrait(name); | 
|---|
| [e4afb4] | 351 | return new ManipulateAtomsProcess(op, descr,manipulateTrait,false); | 
|---|
| [7c4e29] | 352 | } | 
|---|
|  | 353 |  | 
|---|
| [0e2a47] | 354 | ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name){ | 
|---|
|  | 355 | return manipulateAtoms(op,name,AllAtoms()); | 
|---|
|  | 356 | } | 
|---|
|  | 357 |  | 
|---|
| [afb47f] | 358 | /********************* Internal Change methods for double Callback and Observer mechanism ********/ | 
|---|
|  | 359 |  | 
|---|
|  | 360 | void World::doManipulate(ManipulateAtomsProcess *proc){ | 
|---|
|  | 361 | proc->signOn(this); | 
|---|
|  | 362 | { | 
|---|
|  | 363 | OBSERVE; | 
|---|
|  | 364 | proc->doManipulate(this); | 
|---|
|  | 365 | } | 
|---|
|  | 366 | proc->signOff(this); | 
|---|
|  | 367 | } | 
|---|
| [865a945] | 368 | /******************************* Iterators ********************************/ | 
|---|
|  | 369 |  | 
|---|
| [fa0b18] | 370 | // external parts with observers | 
|---|
|  | 371 |  | 
|---|
| [feb5d0] | 372 | CONSTRUCT_SELECTIVE_ITERATOR(atom*,World::AtomSet,AtomDescriptor) | 
|---|
|  | 373 |  | 
|---|
|  | 374 | CONSTRUCT_SELECTIVE_CONST_ITERATOR(atom*,World::AtomSet,AtomDescriptor) | 
|---|
| [6e97e5] | 375 |  | 
|---|
| [fa0b18] | 376 | World::AtomIterator | 
|---|
|  | 377 | World::getAtomIter(AtomDescriptor descr){ | 
|---|
|  | 378 | return AtomIterator(descr,atoms); | 
|---|
|  | 379 | } | 
|---|
| [865a945] | 380 |  | 
|---|
| [feb5d0] | 381 | World::AtomConstIterator | 
|---|
|  | 382 | World::getAtomIter(AtomDescriptor descr) const{ | 
|---|
|  | 383 | return AtomConstIterator(descr,atoms); | 
|---|
|  | 384 | } | 
|---|
|  | 385 |  | 
|---|
| [fa0b18] | 386 | World::AtomIterator | 
|---|
|  | 387 | World::getAtomIter(){ | 
|---|
|  | 388 | return AtomIterator(AllAtoms(),atoms); | 
|---|
| [865a945] | 389 | } | 
|---|
| [354859] | 390 |  | 
|---|
| [feb5d0] | 391 | World::AtomConstIterator | 
|---|
|  | 392 | World::getAtomIter() const{ | 
|---|
|  | 393 | return AtomConstIterator(AllAtoms(),atoms); | 
|---|
|  | 394 | } | 
|---|
|  | 395 |  | 
|---|
| [fa0b18] | 396 | World::AtomIterator | 
|---|
|  | 397 | World::atomEnd(){ | 
|---|
| [6e97e5] | 398 | return AtomIterator(AllAtoms(),atoms,atoms.end()); | 
|---|
| [7c4e29] | 399 | } | 
|---|
|  | 400 |  | 
|---|
| [feb5d0] | 401 | World::AtomConstIterator | 
|---|
|  | 402 | World::atomEnd() const{ | 
|---|
|  | 403 | return AtomConstIterator(AllAtoms(),atoms,atoms.end()); | 
|---|
|  | 404 | } | 
|---|
|  | 405 |  | 
|---|
|  | 406 | CONSTRUCT_SELECTIVE_ITERATOR(molecule*,World::MoleculeSet,MoleculeDescriptor) | 
|---|
|  | 407 |  | 
|---|
|  | 408 | CONSTRUCT_SELECTIVE_CONST_ITERATOR(molecule*,World::MoleculeSet,MoleculeDescriptor) | 
|---|
| [6e97e5] | 409 |  | 
|---|
| [5d880e] | 410 | World::MoleculeIterator | 
|---|
|  | 411 | World::getMoleculeIter(MoleculeDescriptor descr){ | 
|---|
|  | 412 | return MoleculeIterator(descr,molecules); | 
|---|
|  | 413 | } | 
|---|
|  | 414 |  | 
|---|
| [feb5d0] | 415 | World::MoleculeConstIterator | 
|---|
|  | 416 | World::getMoleculeIter(MoleculeDescriptor descr) const{ | 
|---|
|  | 417 | return MoleculeConstIterator(descr,molecules); | 
|---|
|  | 418 | } | 
|---|
|  | 419 |  | 
|---|
| [5d880e] | 420 | World::MoleculeIterator | 
|---|
|  | 421 | World::getMoleculeIter(){ | 
|---|
|  | 422 | return MoleculeIterator(AllMolecules(),molecules); | 
|---|
| [1c51c8] | 423 | } | 
|---|
|  | 424 |  | 
|---|
| [feb5d0] | 425 | World::MoleculeConstIterator | 
|---|
|  | 426 | World::getMoleculeIter() const{ | 
|---|
|  | 427 | return MoleculeConstIterator(AllMolecules(),molecules); | 
|---|
|  | 428 | } | 
|---|
|  | 429 |  | 
|---|
| [5d880e] | 430 | World::MoleculeIterator | 
|---|
|  | 431 | World::moleculeEnd(){ | 
|---|
| [6e97e5] | 432 | return MoleculeIterator(AllMolecules(),molecules,molecules.end()); | 
|---|
| [1c51c8] | 433 | } | 
|---|
|  | 434 |  | 
|---|
| [feb5d0] | 435 | World::MoleculeConstIterator | 
|---|
|  | 436 | World::moleculeEnd() const{ | 
|---|
|  | 437 | return MoleculeConstIterator(AllMolecules(),molecules,molecules.end()); | 
|---|
|  | 438 | } | 
|---|
|  | 439 |  | 
|---|
| [fa0b18] | 440 | // Internal parts, without observers | 
|---|
|  | 441 |  | 
|---|
|  | 442 | // Build the AtomIterator from template | 
|---|
|  | 443 | CONSTRUCT_SELECTIVE_ITERATOR(atom*,World::AtomSet::set_t,AtomDescriptor); | 
|---|
|  | 444 |  | 
|---|
|  | 445 |  | 
|---|
|  | 446 | World::internal_AtomIterator | 
|---|
|  | 447 | World::getAtomIter_internal(AtomDescriptor descr){ | 
|---|
|  | 448 | return internal_AtomIterator(descr,atoms.getContent()); | 
|---|
|  | 449 | } | 
|---|
|  | 450 |  | 
|---|
|  | 451 | World::internal_AtomIterator | 
|---|
|  | 452 | World::atomEnd_internal(){ | 
|---|
|  | 453 | return internal_AtomIterator(AllAtoms(),atoms.getContent(),atoms.end_internal()); | 
|---|
|  | 454 | } | 
|---|
|  | 455 |  | 
|---|
| [6e97e5] | 456 | // build the MoleculeIterator from template | 
|---|
| [e3d865] | 457 | CONSTRUCT_SELECTIVE_ITERATOR(molecule*,World::MoleculeSet::set_t,MoleculeDescriptor); | 
|---|
| [6e97e5] | 458 |  | 
|---|
| [e3d865] | 459 | World::internal_MoleculeIterator World::getMoleculeIter_internal(MoleculeDescriptor descr){ | 
|---|
|  | 460 | return internal_MoleculeIterator(descr,molecules.getContent()); | 
|---|
| [1c51c8] | 461 | } | 
|---|
|  | 462 |  | 
|---|
| [e3d865] | 463 | World::internal_MoleculeIterator World::moleculeEnd_internal(){ | 
|---|
|  | 464 | return internal_MoleculeIterator(AllMolecules(),molecules.getContent(),molecules.end_internal()); | 
|---|
| [1c51c8] | 465 | } | 
|---|
|  | 466 |  | 
|---|
| [90c4280] | 467 | /************************** Selection of Atoms and molecules ******************/ | 
|---|
|  | 468 |  | 
|---|
|  | 469 | // Atoms | 
|---|
|  | 470 |  | 
|---|
|  | 471 | void World::clearAtomSelection(){ | 
|---|
| [69643a] | 472 | OBSERVE; | 
|---|
|  | 473 | NOTIFY(SelectionChanged); | 
|---|
| [90c4280] | 474 | selectedAtoms.clear(); | 
|---|
|  | 475 | } | 
|---|
|  | 476 |  | 
|---|
| [ebc499] | 477 | void World::invertAtomSelection(){ | 
|---|
|  | 478 | // get all atoms not selected | 
|---|
|  | 479 | AtomComposite invertedSelection(getAllAtoms()); | 
|---|
|  | 480 | bool (World::*predicate)(const atom*) const = &World::isSelected; // needed for type resolution of overloaded function | 
|---|
|  | 481 | AtomComposite::iterator iter = | 
|---|
|  | 482 | std::remove_if(invertedSelection.begin(), invertedSelection.end(), | 
|---|
|  | 483 | std::bind1st(std::mem_fun(predicate), this)); | 
|---|
|  | 484 | invertedSelection.erase(iter, invertedSelection.end()); | 
|---|
|  | 485 | // apply new selection | 
|---|
|  | 486 | selectedAtoms.clear(); | 
|---|
|  | 487 | void (World::*selector)(const atom*) = &World::selectAtom; // needed for type resolution of overloaded function | 
|---|
|  | 488 | std::for_each(invertedSelection.begin(),invertedSelection.end(), | 
|---|
|  | 489 | std::bind1st(std::mem_fun(selector),this)); // func is select... see above | 
|---|
|  | 490 | } | 
|---|
|  | 491 |  | 
|---|
| [e4afb4] | 492 | void World::selectAtom(const atom *_atom){ | 
|---|
| [69643a] | 493 | OBSERVE; | 
|---|
|  | 494 | NOTIFY(SelectionChanged); | 
|---|
| [e4afb4] | 495 | // atom * is unchanged in this function, but we do store entity as changeable | 
|---|
|  | 496 | ASSERT(_atom,"Invalid pointer in selection of atom"); | 
|---|
|  | 497 | selectedAtoms[_atom->getId()]=const_cast<atom *>(_atom); | 
|---|
| [90c4280] | 498 | } | 
|---|
|  | 499 |  | 
|---|
| [e4afb4] | 500 | void World::selectAtom(const atomId_t id){ | 
|---|
| [69643a] | 501 | OBSERVE; | 
|---|
|  | 502 | NOTIFY(SelectionChanged); | 
|---|
| [90c4280] | 503 | ASSERT(atoms.count(id),"Atom Id selected that was not in the world"); | 
|---|
|  | 504 | selectedAtoms[id]=atoms[id]; | 
|---|
|  | 505 | } | 
|---|
|  | 506 |  | 
|---|
|  | 507 | void World::selectAllAtoms(AtomDescriptor descr){ | 
|---|
| [69643a] | 508 | OBSERVE; | 
|---|
|  | 509 | NOTIFY(SelectionChanged); | 
|---|
| [90c4280] | 510 | internal_AtomIterator begin = getAtomIter_internal(descr); | 
|---|
|  | 511 | internal_AtomIterator end = atomEnd_internal(); | 
|---|
| [e4afb4] | 512 | void (World::*func)(const atom*) = &World::selectAtom; // needed for type resolution of overloaded function | 
|---|
| [90c4280] | 513 | for_each(begin,end,bind1st(mem_fun(func),this)); // func is select... see above | 
|---|
|  | 514 | } | 
|---|
|  | 515 |  | 
|---|
| [e4afb4] | 516 | void World::selectAtomsOfMolecule(const molecule *_mol){ | 
|---|
| [69643a] | 517 | OBSERVE; | 
|---|
|  | 518 | NOTIFY(SelectionChanged); | 
|---|
| [90c4280] | 519 | ASSERT(_mol,"Invalid pointer to molecule in selection of Atoms of Molecule"); | 
|---|
|  | 520 | // need to make it const to get the fast iterators | 
|---|
|  | 521 | const molecule *mol = _mol; | 
|---|
| [e4afb4] | 522 | void (World::*func)(const atom*) = &World::selectAtom; // needed for type resolution of overloaded function | 
|---|
| [90c4280] | 523 | for_each(mol->begin(),mol->end(),bind1st(mem_fun(func),this)); // func is select... see above | 
|---|
|  | 524 | } | 
|---|
|  | 525 |  | 
|---|
| [e4afb4] | 526 | void World::selectAtomsOfMolecule(const moleculeId_t id){ | 
|---|
| [69643a] | 527 | OBSERVE; | 
|---|
|  | 528 | NOTIFY(SelectionChanged); | 
|---|
| [90c4280] | 529 | ASSERT(molecules.count(id),"No molecule with the given id upon Selection of atoms from molecule"); | 
|---|
|  | 530 | selectAtomsOfMolecule(molecules[id]); | 
|---|
|  | 531 | } | 
|---|
|  | 532 |  | 
|---|
| [e4afb4] | 533 | void World::unselectAtom(const atom *_atom){ | 
|---|
| [69643a] | 534 | OBSERVE; | 
|---|
|  | 535 | NOTIFY(SelectionChanged); | 
|---|
| [e4afb4] | 536 | ASSERT(_atom,"Invalid pointer in unselection of atom"); | 
|---|
|  | 537 | unselectAtom(_atom->getId()); | 
|---|
| [61d655e] | 538 | } | 
|---|
|  | 539 |  | 
|---|
| [e4afb4] | 540 | void World::unselectAtom(const atomId_t id){ | 
|---|
| [69643a] | 541 | OBSERVE; | 
|---|
|  | 542 | NOTIFY(SelectionChanged); | 
|---|
| [61d655e] | 543 | ASSERT(atoms.count(id),"Atom Id unselected that was not in the world"); | 
|---|
|  | 544 | selectedAtoms.erase(id); | 
|---|
|  | 545 | } | 
|---|
|  | 546 |  | 
|---|
|  | 547 | void World::unselectAllAtoms(AtomDescriptor descr){ | 
|---|
| [69643a] | 548 | OBSERVE; | 
|---|
|  | 549 | NOTIFY(SelectionChanged); | 
|---|
| [61d655e] | 550 | internal_AtomIterator begin = getAtomIter_internal(descr); | 
|---|
|  | 551 | internal_AtomIterator end = atomEnd_internal(); | 
|---|
| [e4afb4] | 552 | void (World::*func)(const atom*) = &World::unselectAtom; // needed for type resolution of overloaded function | 
|---|
| [61d655e] | 553 | for_each(begin,end,bind1st(mem_fun(func),this)); // func is unselect... see above | 
|---|
|  | 554 | } | 
|---|
|  | 555 |  | 
|---|
| [e4afb4] | 556 | void World::unselectAtomsOfMolecule(const molecule *_mol){ | 
|---|
| [69643a] | 557 | OBSERVE; | 
|---|
|  | 558 | NOTIFY(SelectionChanged); | 
|---|
| [61d655e] | 559 | ASSERT(_mol,"Invalid pointer to molecule in selection of Atoms of Molecule"); | 
|---|
|  | 560 | // need to make it const to get the fast iterators | 
|---|
|  | 561 | const molecule *mol = _mol; | 
|---|
| [e4afb4] | 562 | void (World::*func)(const atom*) = &World::unselectAtom; // needed for type resolution of overloaded function | 
|---|
| [992bd5] | 563 | for_each(mol->begin(),mol->end(),bind1st(mem_fun(func),this)); // func is unselect... see above | 
|---|
| [61d655e] | 564 | } | 
|---|
|  | 565 |  | 
|---|
| [e4afb4] | 566 | void World::unselectAtomsOfMolecule(const moleculeId_t id){ | 
|---|
| [69643a] | 567 | OBSERVE; | 
|---|
|  | 568 | NOTIFY(SelectionChanged); | 
|---|
| [61d655e] | 569 | ASSERT(molecules.count(id),"No molecule with the given id upon Selection of atoms from molecule"); | 
|---|
|  | 570 | unselectAtomsOfMolecule(molecules[id]); | 
|---|
|  | 571 | } | 
|---|
|  | 572 |  | 
|---|
| [e472eab] | 573 | size_t World::countSelectedAtoms() const { | 
|---|
| [eacc3b] | 574 | size_t count = 0; | 
|---|
| [e472eab] | 575 | for (AtomSet::const_iterator iter = selectedAtoms.begin(); iter != selectedAtoms.end(); ++iter) | 
|---|
| [eacc3b] | 576 | count++; | 
|---|
|  | 577 | return count; | 
|---|
|  | 578 | } | 
|---|
|  | 579 |  | 
|---|
| [e4afb4] | 580 | bool World::isSelected(const atom *_atom) const { | 
|---|
| [89643d] | 581 | return isAtomSelected(_atom->getId()); | 
|---|
|  | 582 | } | 
|---|
|  | 583 |  | 
|---|
|  | 584 | bool World::isAtomSelected(const atomId_t no) const { | 
|---|
|  | 585 | return selectedAtoms.find(no) != selectedAtoms.end(); | 
|---|
| [e0e156] | 586 | } | 
|---|
|  | 587 |  | 
|---|
| [e472eab] | 588 | const std::vector<atom *> World::getSelectedAtoms() const { | 
|---|
|  | 589 | std::vector<atom *> returnAtoms; | 
|---|
|  | 590 | returnAtoms.resize(countSelectedAtoms()); | 
|---|
|  | 591 | int count = 0; | 
|---|
|  | 592 | for (AtomSet::const_iterator iter = selectedAtoms.begin(); iter != selectedAtoms.end(); ++iter) | 
|---|
|  | 593 | returnAtoms[count++] = iter->second; | 
|---|
|  | 594 | return returnAtoms; | 
|---|
|  | 595 | } | 
|---|
|  | 596 |  | 
|---|
|  | 597 |  | 
|---|
| [90c4280] | 598 | // Molecules | 
|---|
|  | 599 |  | 
|---|
|  | 600 | void World::clearMoleculeSelection(){ | 
|---|
| [69643a] | 601 | OBSERVE; | 
|---|
|  | 602 | NOTIFY(SelectionChanged); | 
|---|
| [90c4280] | 603 | selectedMolecules.clear(); | 
|---|
|  | 604 | } | 
|---|
|  | 605 |  | 
|---|
| [ebc499] | 606 | void World::invertMoleculeSelection(){ | 
|---|
|  | 607 | // get all molecules not selected | 
|---|
|  | 608 | typedef std::vector<molecule *> MoleculeVector_t; | 
|---|
|  | 609 | MoleculeVector_t invertedSelection(getAllMolecules()); | 
|---|
|  | 610 | bool (World::*predicate)(const molecule*) const = &World::isSelected; // needed for type resolution of overloaded function | 
|---|
|  | 611 | MoleculeVector_t::iterator iter = | 
|---|
|  | 612 | std::remove_if(invertedSelection.begin(), invertedSelection.end(), | 
|---|
|  | 613 | std::bind1st(std::mem_fun(predicate), this)); | 
|---|
|  | 614 | invertedSelection.erase(iter, invertedSelection.end()); | 
|---|
|  | 615 | // apply new selection | 
|---|
|  | 616 | selectedMolecules.clear(); | 
|---|
|  | 617 | void (World::*selector)(const molecule*) = &World::selectMolecule; // needed for type resolution of overloaded function | 
|---|
|  | 618 | std::for_each(invertedSelection.begin(),invertedSelection.end(), | 
|---|
|  | 619 | std::bind1st(std::mem_fun(selector),this)); // func is select... see above | 
|---|
|  | 620 | } | 
|---|
|  | 621 |  | 
|---|
| [e4afb4] | 622 | void World::selectMolecule(const molecule *_mol){ | 
|---|
| [69643a] | 623 | OBSERVE; | 
|---|
|  | 624 | NOTIFY(SelectionChanged); | 
|---|
| [e4afb4] | 625 | // molecule * is unchanged in this function, but we do store entity as changeable | 
|---|
|  | 626 | ASSERT(_mol,"Invalid pointer to molecule in selection"); | 
|---|
|  | 627 | selectedMolecules[_mol->getId()]=const_cast<molecule *>(_mol); | 
|---|
| [90c4280] | 628 | } | 
|---|
|  | 629 |  | 
|---|
| [e4afb4] | 630 | void World::selectMolecule(const moleculeId_t id){ | 
|---|
| [69643a] | 631 | OBSERVE; | 
|---|
|  | 632 | NOTIFY(SelectionChanged); | 
|---|
| [90c4280] | 633 | ASSERT(molecules.count(id),"Molecule Id selected that was not in the world"); | 
|---|
|  | 634 | selectedMolecules[id]=molecules[id]; | 
|---|
|  | 635 | } | 
|---|
|  | 636 |  | 
|---|
| [e472eab] | 637 | void World::selectAllMolecules(MoleculeDescriptor descr){ | 
|---|
| [69643a] | 638 | OBSERVE; | 
|---|
|  | 639 | NOTIFY(SelectionChanged); | 
|---|
| [90c4280] | 640 | internal_MoleculeIterator begin = getMoleculeIter_internal(descr); | 
|---|
|  | 641 | internal_MoleculeIterator end = moleculeEnd_internal(); | 
|---|
| [e4afb4] | 642 | void (World::*func)(const molecule*) = &World::selectMolecule; // needed for type resolution of overloaded function | 
|---|
| [90c4280] | 643 | for_each(begin,end,bind1st(mem_fun(func),this)); // func is select... see above | 
|---|
|  | 644 | } | 
|---|
|  | 645 |  | 
|---|
| [e4afb4] | 646 | void World::selectMoleculeOfAtom(const atom *_atom){ | 
|---|
| [69643a] | 647 | OBSERVE; | 
|---|
|  | 648 | NOTIFY(SelectionChanged); | 
|---|
| [e4afb4] | 649 | ASSERT(_atom,"Invalid atom pointer in selection of MoleculeOfAtom"); | 
|---|
|  | 650 | molecule *mol=_atom->getMolecule(); | 
|---|
| [90c4280] | 651 | // the atom might not be part of a molecule | 
|---|
|  | 652 | if(mol){ | 
|---|
|  | 653 | selectMolecule(mol); | 
|---|
|  | 654 | } | 
|---|
|  | 655 | } | 
|---|
|  | 656 |  | 
|---|
| [e4afb4] | 657 | void World::selectMoleculeOfAtom(const atomId_t id){ | 
|---|
| [69643a] | 658 | OBSERVE; | 
|---|
|  | 659 | NOTIFY(SelectionChanged); | 
|---|
| [90c4280] | 660 | ASSERT(atoms.count(id),"No such atom with given ID in selection of Molecules of Atom");\ | 
|---|
|  | 661 | selectMoleculeOfAtom(atoms[id]); | 
|---|
|  | 662 | } | 
|---|
|  | 663 |  | 
|---|
| [e4afb4] | 664 | void World::unselectMolecule(const molecule *_mol){ | 
|---|
| [69643a] | 665 | OBSERVE; | 
|---|
|  | 666 | NOTIFY(SelectionChanged); | 
|---|
| [e4afb4] | 667 | ASSERT(_mol,"invalid pointer in unselection of molecule"); | 
|---|
|  | 668 | unselectMolecule(_mol->getId()); | 
|---|
| [61d655e] | 669 | } | 
|---|
|  | 670 |  | 
|---|
| [e4afb4] | 671 | void World::unselectMolecule(const moleculeId_t id){ | 
|---|
| [69643a] | 672 | OBSERVE; | 
|---|
|  | 673 | NOTIFY(SelectionChanged); | 
|---|
| [61d655e] | 674 | ASSERT(molecules.count(id),"No such molecule with ID in unselection"); | 
|---|
|  | 675 | selectedMolecules.erase(id); | 
|---|
|  | 676 | } | 
|---|
|  | 677 |  | 
|---|
| [e472eab] | 678 | void World::unselectAllMolecules(MoleculeDescriptor descr){ | 
|---|
| [69643a] | 679 | OBSERVE; | 
|---|
|  | 680 | NOTIFY(SelectionChanged); | 
|---|
| [61d655e] | 681 | internal_MoleculeIterator begin = getMoleculeIter_internal(descr); | 
|---|
|  | 682 | internal_MoleculeIterator end = moleculeEnd_internal(); | 
|---|
| [e4afb4] | 683 | void (World::*func)(const molecule*) = &World::unselectMolecule; // needed for type resolution of overloaded function | 
|---|
| [61d655e] | 684 | for_each(begin,end,bind1st(mem_fun(func),this)); // func is unselect... see above | 
|---|
|  | 685 | } | 
|---|
|  | 686 |  | 
|---|
| [e4afb4] | 687 | void World::unselectMoleculeOfAtom(const atom *_atom){ | 
|---|
| [69643a] | 688 | OBSERVE; | 
|---|
|  | 689 | NOTIFY(SelectionChanged); | 
|---|
| [e4afb4] | 690 | ASSERT(_atom,"Invalid atom pointer in selection of MoleculeOfAtom"); | 
|---|
|  | 691 | molecule *mol=_atom->getMolecule(); | 
|---|
| [61d655e] | 692 | // the atom might not be part of a molecule | 
|---|
|  | 693 | if(mol){ | 
|---|
|  | 694 | unselectMolecule(mol); | 
|---|
|  | 695 | } | 
|---|
|  | 696 | } | 
|---|
|  | 697 |  | 
|---|
| [e4afb4] | 698 | void World::unselectMoleculeOfAtom(const atomId_t id){ | 
|---|
| [69643a] | 699 | OBSERVE; | 
|---|
|  | 700 | NOTIFY(SelectionChanged); | 
|---|
| [61d655e] | 701 | ASSERT(atoms.count(id),"No such atom with given ID in selection of Molecules of Atom");\ | 
|---|
|  | 702 | unselectMoleculeOfAtom(atoms[id]); | 
|---|
|  | 703 | } | 
|---|
|  | 704 |  | 
|---|
| [e472eab] | 705 | size_t World::countSelectedMolecules() const { | 
|---|
| [eacc3b] | 706 | size_t count = 0; | 
|---|
| [e472eab] | 707 | for (MoleculeSet::const_iterator iter = selectedMolecules.begin(); iter != selectedMolecules.end(); ++iter) | 
|---|
| [eacc3b] | 708 | count++; | 
|---|
|  | 709 | return count; | 
|---|
|  | 710 | } | 
|---|
|  | 711 |  | 
|---|
| [e4afb4] | 712 | bool World::isSelected(const molecule *_mol) const { | 
|---|
| [89643d] | 713 | return isMoleculeSelected(_mol->getId()); | 
|---|
|  | 714 | } | 
|---|
|  | 715 |  | 
|---|
|  | 716 | bool World::isMoleculeSelected(const moleculeId_t no) const { | 
|---|
|  | 717 | return selectedMolecules.find(no) != selectedMolecules.end(); | 
|---|
| [e0e156] | 718 | } | 
|---|
|  | 719 |  | 
|---|
| [e472eab] | 720 | const std::vector<molecule *> World::getSelectedMolecules() const { | 
|---|
|  | 721 | std::vector<molecule *> returnMolecules; | 
|---|
|  | 722 | returnMolecules.resize(countSelectedMolecules()); | 
|---|
|  | 723 | int count = 0; | 
|---|
|  | 724 | for (MoleculeSet::const_iterator iter = selectedMolecules.begin(); iter != selectedMolecules.end(); ++iter) | 
|---|
|  | 725 | returnMolecules[count++] = iter->second; | 
|---|
|  | 726 | return returnMolecules; | 
|---|
|  | 727 | } | 
|---|
|  | 728 |  | 
|---|
| [3839e5] | 729 | /******************* Iterators over Selection *****************************/ | 
|---|
|  | 730 | World::AtomSelectionIterator World::beginAtomSelection(){ | 
|---|
|  | 731 | return selectedAtoms.begin(); | 
|---|
|  | 732 | } | 
|---|
|  | 733 |  | 
|---|
|  | 734 | World::AtomSelectionIterator World::endAtomSelection(){ | 
|---|
|  | 735 | return selectedAtoms.end(); | 
|---|
|  | 736 | } | 
|---|
|  | 737 |  | 
|---|
| [38f991] | 738 | World::AtomSelectionConstIterator World::beginAtomSelection() const{ | 
|---|
|  | 739 | return selectedAtoms.begin(); | 
|---|
|  | 740 | } | 
|---|
|  | 741 |  | 
|---|
|  | 742 | World::AtomSelectionConstIterator World::endAtomSelection() const{ | 
|---|
|  | 743 | return selectedAtoms.end(); | 
|---|
|  | 744 | } | 
|---|
|  | 745 |  | 
|---|
| [3839e5] | 746 |  | 
|---|
|  | 747 | World::MoleculeSelectionIterator World::beginMoleculeSelection(){ | 
|---|
|  | 748 | return selectedMolecules.begin(); | 
|---|
|  | 749 | } | 
|---|
|  | 750 |  | 
|---|
|  | 751 | World::MoleculeSelectionIterator World::endMoleculeSelection(){ | 
|---|
|  | 752 | return selectedMolecules.end(); | 
|---|
|  | 753 | } | 
|---|
|  | 754 |  | 
|---|
| [38f991] | 755 | World::MoleculeSelectionConstIterator World::beginMoleculeSelection() const{ | 
|---|
|  | 756 | return selectedMolecules.begin(); | 
|---|
|  | 757 | } | 
|---|
|  | 758 |  | 
|---|
|  | 759 | World::MoleculeSelectionConstIterator World::endMoleculeSelection() const{ | 
|---|
|  | 760 | return selectedMolecules.end(); | 
|---|
|  | 761 | } | 
|---|
|  | 762 |  | 
|---|
| [5d1611] | 763 | /******************************* Singleton Stuff **************************/ | 
|---|
|  | 764 |  | 
|---|
| [7a1ce5] | 765 | World::World() : | 
|---|
| [cd5047] | 766 | Observable("World"), | 
|---|
| [f71baf] | 767 | BG(new BondGraph(true)),  // assume Angstroem for the moment | 
|---|
| [4ae823] | 768 | periode(new periodentafel(true)), | 
|---|
| [8e1f7af] | 769 | configuration(new config), | 
|---|
| [43dad6] | 770 | Thermostats(new ThermoStatContainer), | 
|---|
| [e4b5de] | 771 | ExitFlag(0), | 
|---|
| [fa0b18] | 772 | atoms(this), | 
|---|
| [90c4280] | 773 | selectedAtoms(this), | 
|---|
| [3e4fb6] | 774 | atomIdPool(0, 20, 100), | 
|---|
| [51be2a] | 775 | molecules(this), | 
|---|
| [90c4280] | 776 | selectedMolecules(this), | 
|---|
| [3e4fb6] | 777 | moleculeIdPool(0, 20,100), | 
|---|
| [24a5e0] | 778 | molecules_deprecated(new MoleculeListClass(this)) | 
|---|
| [7dad10] | 779 | { | 
|---|
| [84c494] | 780 | cell_size = new Box; | 
|---|
| [cca9ef] | 781 | RealSpaceMatrix domain; | 
|---|
| [84c494] | 782 | domain.at(0,0) = 20; | 
|---|
|  | 783 | domain.at(1,1) = 20; | 
|---|
|  | 784 | domain.at(2,2) = 20; | 
|---|
|  | 785 | cell_size->setM(domain); | 
|---|
| [4834f4] | 786 | LCcontroller = new LinkedCell::LinkedCell_Controller(*cell_size); | 
|---|
| [387b36] | 787 | defaultName = "none"; | 
|---|
| [02ce36] | 788 | Channels *OurChannel = new Channels; | 
|---|
| [708277] | 789 | NotificationChannels.insert( std::make_pair( static_cast<Observable *>(this), OurChannel) ); | 
|---|
| [7188b1] | 790 | for (size_t type = 0; type < (size_t)NotificationType_MAX; ++type) | 
|---|
| [02ce36] | 791 | OurChannel->addChannel(type); | 
|---|
| [7dad10] | 792 | molecules_deprecated->signOn(this); | 
|---|
|  | 793 | } | 
|---|
| [5d1611] | 794 |  | 
|---|
|  | 795 | World::~World() | 
|---|
| [354859] | 796 | { | 
|---|
| [028c2e] | 797 | molecules_deprecated->signOff(this); | 
|---|
| [4834f4] | 798 | delete LCcontroller; | 
|---|
| [84c494] | 799 | delete cell_size; | 
|---|
| [46d958] | 800 | delete molecules_deprecated; | 
|---|
| [cbc5fb] | 801 | MoleculeSet::iterator molIter; | 
|---|
|  | 802 | for(molIter=molecules.begin();molIter!=molecules.end();++molIter){ | 
|---|
|  | 803 | DeleteMolecule((*molIter).second); | 
|---|
|  | 804 | } | 
|---|
|  | 805 | molecules.clear(); | 
|---|
|  | 806 | AtomSet::iterator atIter; | 
|---|
|  | 807 | for(atIter=atoms.begin();atIter!=atoms.end();++atIter){ | 
|---|
|  | 808 | DeleteAtom((*atIter).second); | 
|---|
| [46d958] | 809 | } | 
|---|
|  | 810 | atoms.clear(); | 
|---|
| [7188b1] | 811 |  | 
|---|
| [f71baf] | 812 | delete BG; | 
|---|
| [6cb9c76] | 813 | delete periode; | 
|---|
|  | 814 | delete configuration; | 
|---|
|  | 815 | delete Thermostats; | 
|---|
| [354859] | 816 | } | 
|---|
| [5d1611] | 817 |  | 
|---|
| [23b547] | 818 | // Explicit instantiation of the singleton mechanism at this point | 
|---|
| [5d1611] | 819 |  | 
|---|
| [3e4fb6] | 820 | // moleculeId_t und atomId_t sind gleicher Basistyp, deswegen nur einen von beiden konstruieren | 
|---|
| [b97a60] | 821 | CONSTRUCT_IDPOOL(atomId_t, uniqueId) | 
|---|
|  | 822 | CONSTRUCT_IDPOOL(moleculeId_t, continuousId) | 
|---|
| [3e4fb6] | 823 |  | 
|---|
| [23b547] | 824 | CONSTRUCT_SINGLETON(World) | 
|---|
| [5d1611] | 825 |  | 
|---|
| [5f1d5b8] | 826 | CONSTRUCT_OBSERVEDCONTAINER(World::AtomSTLSet) | 
|---|
|  | 827 |  | 
|---|
|  | 828 | CONSTRUCT_OBSERVEDCONTAINER(World::MoleculeSTLSet) | 
|---|
|  | 829 |  | 
|---|
| [5d1611] | 830 | /******************************* deprecated Legacy Stuff ***********************/ | 
|---|
|  | 831 |  | 
|---|
| [354859] | 832 | MoleculeListClass *&World::getMolecules() { | 
|---|
|  | 833 | return molecules_deprecated; | 
|---|
| [5d1611] | 834 | } | 
|---|