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