| [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"
 | 
|---|
| [c1d837] | 50 | #include "Descriptors/AtomIdDescriptor.hpp"
 | 
|---|
| [ebc499] | 51 | #include "Descriptors/AtomSelectionDescriptor.hpp"
 | 
|---|
| [1c51c8] | 52 | #include "Descriptors/MoleculeDescriptor.hpp"
 | 
|---|
 | 53 | #include "Descriptors/MoleculeDescriptor_impl.hpp"
 | 
|---|
| [c1d837] | 54 | #include "Descriptors/MoleculeIdDescriptor.hpp"
 | 
|---|
| [ebc499] | 55 | #include "Descriptors/MoleculeSelectionDescriptor.hpp"
 | 
|---|
| [feb5d0] | 56 | #include "Descriptors/SelectiveConstIterator_impl.hpp"
 | 
|---|
| [6e97e5] | 57 | #include "Descriptors/SelectiveIterator_impl.hpp"
 | 
|---|
| [42127c] | 58 | #include "Element/periodentafel.hpp"
 | 
|---|
| [98dbee] | 59 | #include "Fragmentation/Homology/HomologyContainer.hpp"
 | 
|---|
| [3139b2] | 60 | #include "Graph/BondGraph.hpp"
 | 
|---|
| [4b8630] | 61 | #include "Graph/DepthFirstSearchAnalysis.hpp"
 | 
|---|
| [e4fe8d] | 62 | #include "Helpers/defs.hpp"
 | 
|---|
| [d297a3] | 63 | #include "LinearAlgebra/RealSpaceMatrix.hpp"
 | 
|---|
| [4834f4] | 64 | #include "LinkedCell/LinkedCell_Controller.hpp"
 | 
|---|
 | 65 | #include "LinkedCell/PointCloudAdaptor.hpp"
 | 
|---|
| [d297a3] | 66 | #include "molecule.hpp"
 | 
|---|
| [ab26c3] | 67 | #include "Thermostats/ThermoStatContainer.hpp"
 | 
|---|
| [d297a3] | 68 | #include "WorldTime.hpp"
 | 
|---|
| [d346b6] | 69 | 
 | 
|---|
| [3e4fb6] | 70 | #include "IdPool_impl.hpp"
 | 
|---|
 | 71 | 
 | 
|---|
| [4834f4] | 72 | #include "CodePatterns/IteratorAdaptors.hpp"
 | 
|---|
| [ad011c] | 73 | #include "CodePatterns/Singleton_impl.hpp"
 | 
|---|
| [02ce36] | 74 | #include "CodePatterns/Observer/Channels.hpp"
 | 
|---|
 | 75 | #include "CodePatterns/Observer/ObservedContainer_impl.hpp"
 | 
|---|
| [23b547] | 76 | 
 | 
|---|
| [ce7fdc] | 77 | using namespace MoleCuilder;
 | 
|---|
| [4d9c01] | 78 | 
 | 
|---|
| [7188b1] | 79 | /******************************* Notifications ************************/
 | 
|---|
 | 80 | 
 | 
|---|
 | 81 | 
 | 
|---|
 | 82 | atom* World::_lastchangedatom = NULL;
 | 
|---|
| [fb95a5] | 83 | atomId_t World::_lastchangedatomid = -1;
 | 
|---|
| [7188b1] | 84 | molecule* World::_lastchangedmol = NULL;
 | 
|---|
| [fb95a5] | 85 | moleculeId_t World::_lastchangedmolid = -1;
 | 
|---|
| [7188b1] | 86 | 
 | 
|---|
| [5d1611] | 87 | /******************************* getter and setter ************************/
 | 
|---|
| [f71baf] | 88 | periodentafel *&World::getPeriode()
 | 
|---|
 | 89 | {
 | 
|---|
| [5d1611] | 90 |   return periode;
 | 
|---|
 | 91 | }
 | 
|---|
 | 92 | 
 | 
|---|
| [f71baf] | 93 | BondGraph *&World::getBondGraph()
 | 
|---|
 | 94 | {
 | 
|---|
 | 95 |   return BG;
 | 
|---|
 | 96 | }
 | 
|---|
 | 97 | 
 | 
|---|
| [98dbee] | 98 | HomologyContainer &World::getHomologies()
 | 
|---|
 | 99 | {
 | 
|---|
 | 100 |   return *homologies;
 | 
|---|
 | 101 | }
 | 
|---|
 | 102 | 
 | 
|---|
 | 103 | void World::resetHomologies(HomologyContainer *&_homologies)
 | 
|---|
 | 104 | {
 | 
|---|
 | 105 |   HomologyContainer *oldhomologies = homologies;
 | 
|---|
 | 106 | 
 | 
|---|
 | 107 |   // install new instance, resetting given pointer
 | 
|---|
 | 108 |   homologies = _homologies;
 | 
|---|
 | 109 |   _homologies = NULL;
 | 
|---|
 | 110 | 
 | 
|---|
 | 111 |   // delete old instance which also informs all observers
 | 
|---|
 | 112 |   delete oldhomologies;
 | 
|---|
 | 113 | }
 | 
|---|
 | 114 | 
 | 
|---|
| [f71baf] | 115 | void World::setBondGraph(BondGraph *_BG){
 | 
|---|
 | 116 |   delete (BG);
 | 
|---|
 | 117 |   BG = _BG;
 | 
|---|
 | 118 | }
 | 
|---|
 | 119 | 
 | 
|---|
| [8e1f7af] | 120 | config *&World::getConfig(){
 | 
|---|
 | 121 |   return configuration;
 | 
|---|
 | 122 | }
 | 
|---|
 | 123 | 
 | 
|---|
| [1c51c8] | 124 | // Atoms
 | 
|---|
 | 125 | 
 | 
|---|
| [7a1ce5] | 126 | atom* World::getAtom(AtomDescriptor descriptor){
 | 
|---|
| [fc1b24] | 127 |   return descriptor.find();
 | 
|---|
 | 128 | }
 | 
|---|
 | 129 | 
 | 
|---|
| [795c0f] | 130 | const atom* World::getAtom(AtomDescriptor descriptor) const{
 | 
|---|
 | 131 |   return const_cast<const AtomDescriptor &>(descriptor).find();
 | 
|---|
 | 132 | }
 | 
|---|
 | 133 | 
 | 
|---|
| [4d72e4] | 134 | World::AtomComposite World::getAllAtoms(AtomDescriptor descriptor){
 | 
|---|
| [fc1b24] | 135 |   return descriptor.findAll();
 | 
|---|
 | 136 | }
 | 
|---|
 | 137 | 
 | 
|---|
| [795c0f] | 138 | World::ConstAtomComposite World::getAllAtoms(AtomDescriptor descriptor) const {
 | 
|---|
 | 139 |   return const_cast<const AtomDescriptor &>(descriptor).findAll();
 | 
|---|
 | 140 | }
 | 
|---|
 | 141 | 
 | 
|---|
| [4d72e4] | 142 | World::AtomComposite World::getAllAtoms(){
 | 
|---|
| [0e2a47] | 143 |   return getAllAtoms(AllAtoms());
 | 
|---|
 | 144 | }
 | 
|---|
 | 145 | 
 | 
|---|
| [795c0f] | 146 | World::ConstAtomComposite World::getAllAtoms() const {
 | 
|---|
 | 147 |   return getAllAtoms(AllAtoms());
 | 
|---|
 | 148 | }
 | 
|---|
 | 149 | 
 | 
|---|
 | 150 | int World::numAtoms() const {
 | 
|---|
| [354859] | 151 |   return atoms.size();
 | 
|---|
 | 152 | }
 | 
|---|
 | 153 | 
 | 
|---|
| [1c51c8] | 154 | // Molecules
 | 
|---|
 | 155 | 
 | 
|---|
 | 156 | molecule *World::getMolecule(MoleculeDescriptor descriptor){
 | 
|---|
 | 157 |   return descriptor.find();
 | 
|---|
 | 158 | }
 | 
|---|
 | 159 | 
 | 
|---|
| [97445f] | 160 | const molecule *World::getMolecule(MoleculeDescriptor descriptor) const {
 | 
|---|
 | 161 |   return const_cast<const MoleculeDescriptor &>(descriptor).find();
 | 
|---|
 | 162 | }
 | 
|---|
 | 163 | 
 | 
|---|
| [1c51c8] | 164 | std::vector<molecule*> World::getAllMolecules(MoleculeDescriptor descriptor){
 | 
|---|
 | 165 |   return descriptor.findAll();
 | 
|---|
 | 166 | }
 | 
|---|
 | 167 | 
 | 
|---|
| [97445f] | 168 | std::vector<const molecule*> World::getAllMolecules(MoleculeDescriptor descriptor) const {
 | 
|---|
 | 169 |   return const_cast<const MoleculeDescriptor &>(descriptor).findAll();
 | 
|---|
 | 170 | }
 | 
|---|
 | 171 | 
 | 
|---|
| [97ebf8] | 172 | std::vector<molecule*> World::getAllMolecules(){
 | 
|---|
 | 173 |   return getAllMolecules(AllMolecules());
 | 
|---|
 | 174 | }
 | 
|---|
 | 175 | 
 | 
|---|
| [97445f] | 176 | std::vector<const molecule*> World::getAllMolecules() const {
 | 
|---|
 | 177 |   return getAllMolecules(AllMolecules());
 | 
|---|
 | 178 | }
 | 
|---|
 | 179 | 
 | 
|---|
 | 180 | int World::numMolecules() const {
 | 
|---|
| [2affd1] | 181 |   return molecules.size();
 | 
|---|
| [354859] | 182 | }
 | 
|---|
 | 183 | 
 | 
|---|
| [5f612ee] | 184 | // system
 | 
|---|
 | 185 | 
 | 
|---|
| [84c494] | 186 | Box& World::getDomain() {
 | 
|---|
 | 187 |   return *cell_size;
 | 
|---|
 | 188 | }
 | 
|---|
 | 189 | 
 | 
|---|
| [cca9ef] | 190 | void World::setDomain(const RealSpaceMatrix &mat){
 | 
|---|
| [be97a8] | 191 |   OBSERVE;
 | 
|---|
| [84c494] | 192 |   *cell_size = mat;
 | 
|---|
| [5f612ee] | 193 | }
 | 
|---|
 | 194 | 
 | 
|---|
 | 195 | void World::setDomain(double * matrix)
 | 
|---|
 | 196 | {
 | 
|---|
| [b9c847] | 197 |   OBSERVE;
 | 
|---|
| [cca9ef] | 198 |   RealSpaceMatrix M = ReturnFullMatrixforSymmetric(matrix);
 | 
|---|
| [84c494] | 199 |   cell_size->setM(M);
 | 
|---|
| [5f612ee] | 200 | }
 | 
|---|
 | 201 | 
 | 
|---|
| [03abd0] | 202 | LinkedCell::LinkedCell_View World::getLinkedCell(double distance)
 | 
|---|
| [4834f4] | 203 | {
 | 
|---|
| [d067e35] | 204 |   ASSERT( distance >= 0,
 | 
|---|
| [03abd0] | 205 |       "World::getLinkedCell() - distance is not positive.");
 | 
|---|
 | 206 |   if (distance < 1.) {
 | 
|---|
 | 207 |     ELOG(2, "Linked cell grid with length less than 1. is very memory-intense!");
 | 
|---|
 | 208 |     distance = 1.;
 | 
|---|
 | 209 |   }
 | 
|---|
| [4834f4] | 210 |   // we have to grope past the ObservedContainer mechanism and transmorph the map
 | 
|---|
 | 211 |   // into a traversable list for the adaptor
 | 
|---|
 | 212 |   PointCloudAdaptor< AtomSet::set_t, MapValueIterator<AtomSet::set_t::iterator> > atomset(
 | 
|---|
 | 213 |       &(atoms.getContent()),
 | 
|---|
 | 214 |       std::string("WorldsAtoms"));
 | 
|---|
 | 215 |   return LCcontroller->getView(distance, atomset);
 | 
|---|
 | 216 | }
 | 
|---|
 | 217 | 
 | 
|---|
| [2a8731] | 218 | const unsigned World::getTime() const
 | 
|---|
 | 219 | {
 | 
|---|
 | 220 |   return WorldTime::getTime();
 | 
|---|
 | 221 | }
 | 
|---|
 | 222 | 
 | 
|---|
| [388ddd] | 223 | bool areBondsPresent(const unsigned int _step)
 | 
|---|
 | 224 | {
 | 
|---|
 | 225 |   bool status = false;
 | 
|---|
 | 226 | 
 | 
|---|
 | 227 |   for (World::AtomConstIterator iter = const_cast<const World &>(World::getInstance()).getAtomIter();
 | 
|---|
 | 228 |       (!status) && (iter != const_cast<const World &>(World::getInstance()).atomEnd()); ++iter) {
 | 
|---|
 | 229 |     const atom * const Walker = *iter;
 | 
|---|
 | 230 |     status |= !Walker->getListOfBondsAtStep(_step).empty();
 | 
|---|
 | 231 |   }
 | 
|---|
 | 232 | 
 | 
|---|
 | 233 |   return status;
 | 
|---|
 | 234 | }
 | 
|---|
 | 235 | 
 | 
|---|
 | 236 | void copyBondgraph(const unsigned int _srcstep, const unsigned int _deststep)
 | 
|---|
 | 237 | {
 | 
|---|
 | 238 |   // gather all bonds from _srcstep
 | 
|---|
 | 239 |   std::set<bond *> SetOfBonds;
 | 
|---|
 | 240 |   for (World::AtomConstIterator iter = const_cast<const World &>(World::getInstance()).getAtomIter();
 | 
|---|
 | 241 |       iter != const_cast<const World &>(World::getInstance()).atomEnd(); ++iter) {
 | 
|---|
 | 242 |     const atom * const Walker = *iter;
 | 
|---|
 | 243 |     const BondList bonds = Walker->getListOfBondsAtStep(_srcstep);
 | 
|---|
 | 244 |     BOOST_FOREACH( bond::ptr bondptr, bonds) {
 | 
|---|
 | 245 |       SetOfBonds.insert(bondptr.get());
 | 
|---|
 | 246 |     }
 | 
|---|
 | 247 |   }
 | 
|---|
 | 248 |   LOG(4, "DEBUG: We gathered " << SetOfBonds.size() << " bonds in total.");
 | 
|---|
 | 249 | 
 | 
|---|
 | 250 |   // copy bond to new time step
 | 
|---|
 | 251 |   for (std::set<bond *>::const_iterator bonditer = SetOfBonds.begin();
 | 
|---|
 | 252 |       bonditer != SetOfBonds.end(); ++bonditer) {
 | 
|---|
 | 253 |     const atom * const Walker = (*bonditer)->leftatom;
 | 
|---|
 | 254 |     const atom * const OtherWalker = (*bonditer)->rightatom;
 | 
|---|
| [0763ce] | 255 |     bond::ptr const _bond =
 | 
|---|
 | 256 |         const_cast<atom *>(Walker)->addBond(_deststep, const_cast<atom *>(OtherWalker));
 | 
|---|
 | 257 |     _bond->setDegree((*bonditer)->getDegree());
 | 
|---|
| [388ddd] | 258 |   }
 | 
|---|
 | 259 | }
 | 
|---|
 | 260 | 
 | 
|---|
| [d297a3] | 261 | void World::setTime(const unsigned int _step)
 | 
|---|
 | 262 | {
 | 
|---|
| [76163d] | 263 |   if (_step != WorldTime::getTime()) {
 | 
|---|
| [388ddd] | 264 |     const unsigned int oldstep = WorldTime::getTime();
 | 
|---|
| [46ce1c] | 265 | 
 | 
|---|
 | 266 |     // 1. copy bond graph (such not each addBond causes GUI update)
 | 
|---|
 | 267 |     if (!areBondsPresent(_step)) {
 | 
|---|
 | 268 | //      AtomComposite Set = getAllAtoms();
 | 
|---|
 | 269 | //      BG->cleanAdjacencyList(Set);
 | 
|---|
 | 270 |       copyBondgraph(oldstep, _step);
 | 
|---|
 | 271 |     }
 | 
|---|
 | 272 | 
 | 
|---|
 | 273 |     // 2. set new time
 | 
|---|
| [040a5c] | 274 |     WorldTime::getInstance().setTime(_step);
 | 
|---|
| [46ce1c] | 275 | 
 | 
|---|
 | 276 |     // 4. scan for connected subgraphs => molecules
 | 
|---|
| [4b8630] | 277 |     DepthFirstSearchAnalysis DFS;
 | 
|---|
 | 278 |     DFS();
 | 
|---|
 | 279 |     DFS.UpdateMoleculeStructure();
 | 
|---|
| [76163d] | 280 |   }
 | 
|---|
| [d297a3] | 281 | }
 | 
|---|
 | 282 | 
 | 
|---|
| [387b36] | 283 | std::string World::getDefaultName() {
 | 
|---|
| [5f612ee] | 284 |   return defaultName;
 | 
|---|
 | 285 | }
 | 
|---|
 | 286 | 
 | 
|---|
| [387b36] | 287 | void World::setDefaultName(std::string name)
 | 
|---|
| [5f612ee] | 288 | {
 | 
|---|
| [be97a8] | 289 |   OBSERVE;
 | 
|---|
| [387b36] | 290 |   defaultName = name;
 | 
|---|
| [5f612ee] | 291 | };
 | 
|---|
 | 292 | 
 | 
|---|
| [43dad6] | 293 | class ThermoStatContainer * World::getThermostats()
 | 
|---|
 | 294 | {
 | 
|---|
 | 295 |   return Thermostats;
 | 
|---|
 | 296 | }
 | 
|---|
 | 297 | 
 | 
|---|
 | 298 | 
 | 
|---|
| [e4b5de] | 299 | int World::getExitFlag() {
 | 
|---|
 | 300 |   return ExitFlag;
 | 
|---|
 | 301 | }
 | 
|---|
 | 302 | 
 | 
|---|
 | 303 | void World::setExitFlag(int flag) {
 | 
|---|
 | 304 |   if (ExitFlag < flag)
 | 
|---|
 | 305 |     ExitFlag = flag;
 | 
|---|
 | 306 | }
 | 
|---|
| [5f612ee] | 307 | 
 | 
|---|
| [afb47f] | 308 | /******************** Methods to change World state *********************/
 | 
|---|
 | 309 | 
 | 
|---|
| [354859] | 310 | molecule* World::createMolecule(){
 | 
|---|
 | 311 |   OBSERVE;
 | 
|---|
 | 312 |   molecule *mol = NULL;
 | 
|---|
| [cbc5fb] | 313 |   mol = NewMolecule();
 | 
|---|
| [3e4fb6] | 314 |   moleculeId_t id = moleculeIdPool.getNextId();
 | 
|---|
| [127a8e] | 315 |   ASSERT(!molecules.count(id),"proposed id did not specify an unused ID");
 | 
|---|
 | 316 |   mol->setId(id);
 | 
|---|
| [244d26] | 317 |   // store the molecule by ID
 | 
|---|
| [cbc5fb] | 318 |   molecules[mol->getId()] = mol;
 | 
|---|
| [7188b1] | 319 |   _lastchangedmol = mol;
 | 
|---|
| [fb95a5] | 320 |   _lastchangedmolid = mol->getId();
 | 
|---|
| [7188b1] | 321 |   NOTIFY(MoleculeInserted);
 | 
|---|
| [354859] | 322 |   return mol;
 | 
|---|
 | 323 | }
 | 
|---|
 | 324 | 
 | 
|---|
| [5cf341] | 325 | molecule* World::recreateMolecule(const moleculeId_t &_id)
 | 
|---|
 | 326 | {
 | 
|---|
 | 327 |   molecule *mol = NULL;
 | 
|---|
 | 328 |   if (!molecules.count(_id)) {
 | 
|---|
 | 329 |     OBSERVE;
 | 
|---|
 | 330 |     mol = NewMolecule();
 | 
|---|
 | 331 |     mol->setId(_id);
 | 
|---|
 | 332 |     // store the molecule by ID
 | 
|---|
 | 333 |     molecules[mol->getId()] = mol;
 | 
|---|
 | 334 |     _lastchangedmol = mol;
 | 
|---|
 | 335 |     _lastchangedmolid = mol->getId();
 | 
|---|
 | 336 |     NOTIFY(MoleculeInserted);
 | 
|---|
 | 337 |   }
 | 
|---|
 | 338 |   return mol;
 | 
|---|
 | 339 | }
 | 
|---|
 | 340 | 
 | 
|---|
| [cbc5fb] | 341 | void World::destroyMolecule(molecule* mol){
 | 
|---|
| [fa7989] | 342 |   ASSERT(mol,"Molecule that was meant to be destroyed did not exist");
 | 
|---|
| [cbc5fb] | 343 |   destroyMolecule(mol->getId());
 | 
|---|
 | 344 | }
 | 
|---|
 | 345 | 
 | 
|---|
 | 346 | void World::destroyMolecule(moleculeId_t id){
 | 
|---|
 | 347 |   molecule *mol = molecules[id];
 | 
|---|
| [6d574a] | 348 |   ASSERT(mol,"Molecule id that was meant to be destroyed did not exist");
 | 
|---|
| [38f991] | 349 |   // give notice about immediate removal
 | 
|---|
 | 350 |   {
 | 
|---|
 | 351 |     OBSERVE;
 | 
|---|
 | 352 |     _lastchangedmol = mol;
 | 
|---|
| [fb95a5] | 353 |     _lastchangedmolid = mol->getId();
 | 
|---|
| [38f991] | 354 |     NOTIFY(MoleculeRemoved);
 | 
|---|
 | 355 |   }
 | 
|---|
| [4965d9f] | 356 |   if (isMoleculeSelected(id)) {
 | 
|---|
| [38f991] | 357 |     selectedMolecules.erase(id);
 | 
|---|
| [4965d9f] | 358 |     NOTIFY(SelectionChanged);
 | 
|---|
 | 359 |   }
 | 
|---|
| [f02b53] | 360 |   DeleteMolecule(mol);
 | 
|---|
| [7eec64] | 361 |   molecules.erase(id);
 | 
|---|
| [3e4fb6] | 362 |   moleculeIdPool.releaseId(id);
 | 
|---|
| [cbc5fb] | 363 | }
 | 
|---|
 | 364 | 
 | 
|---|
| [46d958] | 365 | atom *World::createAtom(){
 | 
|---|
 | 366 |   OBSERVE;
 | 
|---|
| [3e4fb6] | 367 |   atomId_t id = atomIdPool.getNextId();
 | 
|---|
| [127a8e] | 368 |   ASSERT(!atoms.count(id),"proposed id did not specify an unused ID");
 | 
|---|
| [88d586] | 369 |   atom *res = NewAtom(id);
 | 
|---|
| [46d958] | 370 |   res->setWorld(this);
 | 
|---|
| [244d26] | 371 |   // store the atom by ID
 | 
|---|
| [46d958] | 372 |   atoms[res->getId()] = res;
 | 
|---|
| [7188b1] | 373 |   _lastchangedatom = res;
 | 
|---|
| [fb95a5] | 374 |   _lastchangedatomid = res->getId();
 | 
|---|
| [7188b1] | 375 |   NOTIFY(AtomInserted);
 | 
|---|
| [46d958] | 376 |   return res;
 | 
|---|
 | 377 | }
 | 
|---|
 | 378 | 
 | 
|---|
| [5cf341] | 379 | atom *World::recreateAtom(const atomId_t _id){
 | 
|---|
 | 380 |   if (!atoms.count(_id)) {
 | 
|---|
 | 381 |     OBSERVE;
 | 
|---|
 | 382 |     atom *res = NewAtom(_id);
 | 
|---|
 | 383 |     res->setWorld(this);
 | 
|---|
 | 384 |     // store the atom by ID
 | 
|---|
 | 385 |     atoms[res->getId()] = res;
 | 
|---|
 | 386 |     _lastchangedatom = res;
 | 
|---|
 | 387 |     _lastchangedatomid = res->getId();
 | 
|---|
 | 388 |     NOTIFY(AtomInserted);
 | 
|---|
 | 389 |     return res;
 | 
|---|
 | 390 |   } else
 | 
|---|
 | 391 |     return NULL;
 | 
|---|
 | 392 | }
 | 
|---|
 | 393 | 
 | 
|---|
| [5f612ee] | 394 | 
 | 
|---|
| [46d958] | 395 | int World::registerAtom(atom *atom){
 | 
|---|
 | 396 |   OBSERVE;
 | 
|---|
| [3e4fb6] | 397 |   atomId_t id = atomIdPool.getNextId();
 | 
|---|
| [88d586] | 398 |   atom->setId(id);
 | 
|---|
| [46d958] | 399 |   atom->setWorld(this);
 | 
|---|
 | 400 |   atoms[atom->getId()] = atom;
 | 
|---|
| [65d7ca] | 401 |   _lastchangedatom = atom;
 | 
|---|
| [fb95a5] | 402 |   _lastchangedatomid = atom->getId();
 | 
|---|
| [65d7ca] | 403 |   NOTIFY(AtomInserted);
 | 
|---|
| [46d958] | 404 |   return atom->getId();
 | 
|---|
 | 405 | }
 | 
|---|
 | 406 | 
 | 
|---|
 | 407 | void World::destroyAtom(atom* atom){
 | 
|---|
 | 408 |   int id = atom->getId();
 | 
|---|
 | 409 |   destroyAtom(id);
 | 
|---|
 | 410 | }
 | 
|---|
 | 411 | 
 | 
|---|
| [cbc5fb] | 412 | void World::destroyAtom(atomId_t id) {
 | 
|---|
| [46d958] | 413 |   atom *atom = atoms[id];
 | 
|---|
| [6d574a] | 414 |   ASSERT(atom,"Atom ID that was meant to be destroyed did not exist");
 | 
|---|
| [ab4a33] | 415 |   // give notice about immediate removal
 | 
|---|
 | 416 |   {
 | 
|---|
 | 417 |     OBSERVE;
 | 
|---|
 | 418 |     _lastchangedatom = atom;
 | 
|---|
| [fb95a5] | 419 |     _lastchangedatomid = atom->getId();
 | 
|---|
| [ab4a33] | 420 |     NOTIFY(AtomRemoved);
 | 
|---|
 | 421 |   }
 | 
|---|
| [a7aebd] | 422 |   // check if it's the last atom
 | 
|---|
| [270bdf] | 423 |   molecule *_mol = const_cast<molecule *>(atom->getMolecule());
 | 
|---|
| [cad383] | 424 |   if ((_mol == NULL) || (_mol->getAtomCount() > 1))
 | 
|---|
| [a7aebd] | 425 |     _mol = NULL;
 | 
|---|
| [4965d9f] | 426 |   if (isAtomSelected(id)) {
 | 
|---|
| [38f991] | 427 |     selectedAtoms.erase(id);
 | 
|---|
| [4965d9f] | 428 |     NOTIFY(SelectionChanged);
 | 
|---|
 | 429 |   }
 | 
|---|
| [f02b53] | 430 |   DeleteAtom(atom);
 | 
|---|
| [59e7996] | 431 |   atoms.erase(id);
 | 
|---|
| [3e4fb6] | 432 |   atomIdPool.releaseId(id);
 | 
|---|
| [a7aebd] | 433 |   // remove molecule if empty
 | 
|---|
 | 434 |   if (_mol != NULL)
 | 
|---|
 | 435 |     destroyMolecule(_mol);
 | 
|---|
| [88d586] | 436 | }
 | 
|---|
 | 437 | 
 | 
|---|
 | 438 | bool World::changeAtomId(atomId_t oldId, atomId_t newId, atom* target){
 | 
|---|
 | 439 |   OBSERVE;
 | 
|---|
 | 440 |   // in case this call did not originate from inside the atom, we redirect it,
 | 
|---|
 | 441 |   // to also let it know that it has changed
 | 
|---|
 | 442 |   if(!target){
 | 
|---|
 | 443 |     target = atoms[oldId];
 | 
|---|
| [6d574a] | 444 |     ASSERT(target,"Atom with that ID not found");
 | 
|---|
| [88d586] | 445 |     return target->changeId(newId);
 | 
|---|
 | 446 |   }
 | 
|---|
 | 447 |   else{
 | 
|---|
| [3e4fb6] | 448 |     if(atomIdPool.reserveId(newId)){
 | 
|---|
| [88d586] | 449 |       atoms.erase(oldId);
 | 
|---|
 | 450 |       atoms.insert(pair<atomId_t,atom*>(newId,target));
 | 
|---|
 | 451 |       return true;
 | 
|---|
 | 452 |     }
 | 
|---|
 | 453 |     else{
 | 
|---|
 | 454 |       return false;
 | 
|---|
 | 455 |     }
 | 
|---|
 | 456 |   }
 | 
|---|
| [46d958] | 457 | }
 | 
|---|
 | 458 | 
 | 
|---|
| [a7a087] | 459 | bool World::changeMoleculeId(moleculeId_t oldId, moleculeId_t newId, molecule* target){
 | 
|---|
 | 460 |   OBSERVE;
 | 
|---|
 | 461 |   // in case this call did not originate from inside the atom, we redirect it,
 | 
|---|
 | 462 |   // to also let it know that it has changed
 | 
|---|
 | 463 |   if(!target){
 | 
|---|
 | 464 |     target = molecules[oldId];
 | 
|---|
 | 465 |     ASSERT(target,"Molecule with that ID not found");
 | 
|---|
 | 466 |     return target->changeId(newId);
 | 
|---|
 | 467 |   }
 | 
|---|
 | 468 |   else{
 | 
|---|
| [3e4fb6] | 469 |     if(moleculeIdPool.reserveId(newId)){
 | 
|---|
| [a7a087] | 470 |       molecules.erase(oldId);
 | 
|---|
 | 471 |       molecules.insert(pair<moleculeId_t,molecule*>(newId,target));
 | 
|---|
 | 472 |       return true;
 | 
|---|
 | 473 |     }
 | 
|---|
 | 474 |     else{
 | 
|---|
 | 475 |       return false;
 | 
|---|
 | 476 |     }
 | 
|---|
 | 477 |   }
 | 
|---|
 | 478 | }
 | 
|---|
 | 479 | 
 | 
|---|
| [7c4e29] | 480 | ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){
 | 
|---|
| [3139b2] | 481 |   ActionTrait manipulateTrait(name);
 | 
|---|
| [126867] | 482 |   return new ManipulateAtomsProcess(op, descr,manipulateTrait);
 | 
|---|
| [7c4e29] | 483 | }
 | 
|---|
 | 484 | 
 | 
|---|
| [0e2a47] | 485 | ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name){
 | 
|---|
 | 486 |   return manipulateAtoms(op,name,AllAtoms());
 | 
|---|
 | 487 | }
 | 
|---|
 | 488 | 
 | 
|---|
| [afb47f] | 489 | /********************* Internal Change methods for double Callback and Observer mechanism ********/
 | 
|---|
 | 490 | 
 | 
|---|
 | 491 | void World::doManipulate(ManipulateAtomsProcess *proc){
 | 
|---|
 | 492 |   proc->signOn(this);
 | 
|---|
 | 493 |   {
 | 
|---|
 | 494 |     OBSERVE;
 | 
|---|
 | 495 |     proc->doManipulate(this);
 | 
|---|
 | 496 |   }
 | 
|---|
 | 497 |   proc->signOff(this);
 | 
|---|
 | 498 | }
 | 
|---|
| [865a945] | 499 | /******************************* Iterators ********************************/
 | 
|---|
 | 500 | 
 | 
|---|
| [fa0b18] | 501 | // external parts with observers
 | 
|---|
 | 502 | 
 | 
|---|
| [feb5d0] | 503 | CONSTRUCT_SELECTIVE_ITERATOR(atom*,World::AtomSet,AtomDescriptor)
 | 
|---|
 | 504 | 
 | 
|---|
 | 505 | CONSTRUCT_SELECTIVE_CONST_ITERATOR(atom*,World::AtomSet,AtomDescriptor)
 | 
|---|
| [6e97e5] | 506 | 
 | 
|---|
| [fa0b18] | 507 | World::AtomIterator
 | 
|---|
 | 508 | World::getAtomIter(AtomDescriptor descr){
 | 
|---|
 | 509 |     return AtomIterator(descr,atoms);
 | 
|---|
 | 510 | }
 | 
|---|
| [865a945] | 511 | 
 | 
|---|
| [feb5d0] | 512 | World::AtomConstIterator
 | 
|---|
 | 513 | World::getAtomIter(AtomDescriptor descr) const{
 | 
|---|
 | 514 |     return AtomConstIterator(descr,atoms);
 | 
|---|
 | 515 | }
 | 
|---|
 | 516 | 
 | 
|---|
| [fa0b18] | 517 | World::AtomIterator
 | 
|---|
 | 518 | World::getAtomIter(){
 | 
|---|
 | 519 |     return AtomIterator(AllAtoms(),atoms);
 | 
|---|
| [865a945] | 520 | }
 | 
|---|
| [354859] | 521 | 
 | 
|---|
| [feb5d0] | 522 | World::AtomConstIterator
 | 
|---|
 | 523 | World::getAtomIter() const{
 | 
|---|
 | 524 |     return AtomConstIterator(AllAtoms(),atoms);
 | 
|---|
 | 525 | }
 | 
|---|
 | 526 | 
 | 
|---|
| [fa0b18] | 527 | World::AtomIterator
 | 
|---|
 | 528 | World::atomEnd(){
 | 
|---|
| [6e97e5] | 529 |   return AtomIterator(AllAtoms(),atoms,atoms.end());
 | 
|---|
| [7c4e29] | 530 | }
 | 
|---|
 | 531 | 
 | 
|---|
| [feb5d0] | 532 | World::AtomConstIterator
 | 
|---|
 | 533 | World::atomEnd() const{
 | 
|---|
 | 534 |   return AtomConstIterator(AllAtoms(),atoms,atoms.end());
 | 
|---|
 | 535 | }
 | 
|---|
 | 536 | 
 | 
|---|
 | 537 | CONSTRUCT_SELECTIVE_ITERATOR(molecule*,World::MoleculeSet,MoleculeDescriptor)
 | 
|---|
 | 538 | 
 | 
|---|
 | 539 | CONSTRUCT_SELECTIVE_CONST_ITERATOR(molecule*,World::MoleculeSet,MoleculeDescriptor)
 | 
|---|
| [6e97e5] | 540 | 
 | 
|---|
| [5d880e] | 541 | World::MoleculeIterator
 | 
|---|
 | 542 | World::getMoleculeIter(MoleculeDescriptor descr){
 | 
|---|
 | 543 |     return MoleculeIterator(descr,molecules);
 | 
|---|
 | 544 | }
 | 
|---|
 | 545 | 
 | 
|---|
| [feb5d0] | 546 | World::MoleculeConstIterator
 | 
|---|
 | 547 | World::getMoleculeIter(MoleculeDescriptor descr) const{
 | 
|---|
 | 548 |     return MoleculeConstIterator(descr,molecules);
 | 
|---|
 | 549 | }
 | 
|---|
 | 550 | 
 | 
|---|
| [5d880e] | 551 | World::MoleculeIterator
 | 
|---|
 | 552 | World::getMoleculeIter(){
 | 
|---|
 | 553 |     return MoleculeIterator(AllMolecules(),molecules);
 | 
|---|
| [1c51c8] | 554 | }
 | 
|---|
 | 555 | 
 | 
|---|
| [feb5d0] | 556 | World::MoleculeConstIterator
 | 
|---|
 | 557 | World::getMoleculeIter() const{
 | 
|---|
 | 558 |     return MoleculeConstIterator(AllMolecules(),molecules);
 | 
|---|
 | 559 | }
 | 
|---|
 | 560 | 
 | 
|---|
| [5d880e] | 561 | World::MoleculeIterator
 | 
|---|
 | 562 | World::moleculeEnd(){
 | 
|---|
| [6e97e5] | 563 |   return MoleculeIterator(AllMolecules(),molecules,molecules.end());
 | 
|---|
| [1c51c8] | 564 | }
 | 
|---|
 | 565 | 
 | 
|---|
| [feb5d0] | 566 | World::MoleculeConstIterator
 | 
|---|
 | 567 | World::moleculeEnd() const{
 | 
|---|
 | 568 |   return MoleculeConstIterator(AllMolecules(),molecules,molecules.end());
 | 
|---|
 | 569 | }
 | 
|---|
 | 570 | 
 | 
|---|
| [fa0b18] | 571 | // Internal parts, without observers
 | 
|---|
 | 572 | 
 | 
|---|
 | 573 | // Build the AtomIterator from template
 | 
|---|
 | 574 | CONSTRUCT_SELECTIVE_ITERATOR(atom*,World::AtomSet::set_t,AtomDescriptor);
 | 
|---|
 | 575 | 
 | 
|---|
 | 576 | 
 | 
|---|
 | 577 | World::internal_AtomIterator
 | 
|---|
 | 578 | World::getAtomIter_internal(AtomDescriptor descr){
 | 
|---|
 | 579 |   return internal_AtomIterator(descr,atoms.getContent());
 | 
|---|
 | 580 | }
 | 
|---|
 | 581 | 
 | 
|---|
 | 582 | World::internal_AtomIterator
 | 
|---|
 | 583 | World::atomEnd_internal(){
 | 
|---|
 | 584 |   return internal_AtomIterator(AllAtoms(),atoms.getContent(),atoms.end_internal());
 | 
|---|
 | 585 | }
 | 
|---|
 | 586 | 
 | 
|---|
| [6e97e5] | 587 | // build the MoleculeIterator from template
 | 
|---|
| [e3d865] | 588 | CONSTRUCT_SELECTIVE_ITERATOR(molecule*,World::MoleculeSet::set_t,MoleculeDescriptor);
 | 
|---|
| [6e97e5] | 589 | 
 | 
|---|
| [e3d865] | 590 | World::internal_MoleculeIterator World::getMoleculeIter_internal(MoleculeDescriptor descr){
 | 
|---|
 | 591 |   return internal_MoleculeIterator(descr,molecules.getContent());
 | 
|---|
| [1c51c8] | 592 | }
 | 
|---|
 | 593 | 
 | 
|---|
| [e3d865] | 594 | World::internal_MoleculeIterator World::moleculeEnd_internal(){
 | 
|---|
 | 595 |   return internal_MoleculeIterator(AllMolecules(),molecules.getContent(),molecules.end_internal());
 | 
|---|
| [1c51c8] | 596 | }
 | 
|---|
 | 597 | 
 | 
|---|
| [90c4280] | 598 | /************************** Selection of Atoms and molecules ******************/
 | 
|---|
 | 599 | 
 | 
|---|
| [7f1865d] | 600 | // translate type's selection member functions to overloaded with specific type
 | 
|---|
 | 601 | 
 | 
|---|
 | 602 | template <class T>
 | 
|---|
 | 603 | void World::selectVectorOfInstances(const typename T::iterator _begin, const typename T::iterator _end)
 | 
|---|
 | 604 | {
 | 
|---|
 | 605 |   std::for_each(_begin,_end,
 | 
|---|
 | 606 |       boost::bind(&World::selectInstance<typename T::value_type::second_type>,
 | 
|---|
 | 607 |           boost::bind(_take<typename T::value_type::second_type,typename T::value_type>::get, _1)));
 | 
|---|
 | 608 | }
 | 
|---|
 | 609 | 
 | 
|---|
 | 610 | template <class T>
 | 
|---|
 | 611 | void World::unselectVectorOfInstances(const typename  T::iterator _begin, const typename T::iterator _end)
 | 
|---|
 | 612 | {
 | 
|---|
 | 613 |   std::for_each(_begin,_end,
 | 
|---|
 | 614 |       boost::bind(&World::unselectInstance<typename T::value_type::second_type>,
 | 
|---|
 | 615 |           boost::bind(_take<typename T::value_type::second_type,typename T::value_type>::get, _1)));
 | 
|---|
 | 616 | }
 | 
|---|
 | 617 | 
 | 
|---|
| [90c4280] | 618 | // Atoms
 | 
|---|
 | 619 | 
 | 
|---|
 | 620 | void World::clearAtomSelection(){
 | 
|---|
| [69643a] | 621 |   OBSERVE;
 | 
|---|
 | 622 |   NOTIFY(SelectionChanged);
 | 
|---|
| [7f1865d] | 623 |   unselectVectorOfInstances<AtomSet>(selectedAtoms.begin(), selectedAtoms.end());
 | 
|---|
| [90c4280] | 624 |   selectedAtoms.clear();
 | 
|---|
 | 625 | }
 | 
|---|
 | 626 | 
 | 
|---|
| [ebc499] | 627 | void World::invertAtomSelection(){
 | 
|---|
 | 628 |   // get all atoms not selected
 | 
|---|
 | 629 |   AtomComposite invertedSelection(getAllAtoms());
 | 
|---|
 | 630 |   bool (World::*predicate)(const atom*) const = &World::isSelected; // needed for type resolution of overloaded function
 | 
|---|
 | 631 |   AtomComposite::iterator iter =
 | 
|---|
 | 632 |       std::remove_if(invertedSelection.begin(), invertedSelection.end(),
 | 
|---|
 | 633 |           std::bind1st(std::mem_fun(predicate), this));
 | 
|---|
 | 634 |   invertedSelection.erase(iter, invertedSelection.end());
 | 
|---|
 | 635 |   // apply new selection
 | 
|---|
| [7f1865d] | 636 |   unselectVectorOfInstances<AtomSet>(selectedAtoms.begin(), selectedAtoms.end());
 | 
|---|
| [ebc499] | 637 |   selectedAtoms.clear();
 | 
|---|
 | 638 |   void (World::*selector)(const atom*) = &World::selectAtom; // needed for type resolution of overloaded function
 | 
|---|
 | 639 |   std::for_each(invertedSelection.begin(),invertedSelection.end(),
 | 
|---|
 | 640 |       std::bind1st(std::mem_fun(selector),this)); // func is select... see above
 | 
|---|
 | 641 | }
 | 
|---|
 | 642 | 
 | 
|---|
| [cad383] | 643 | void World::popAtomSelection(){
 | 
|---|
 | 644 |   OBSERVE;
 | 
|---|
 | 645 |   NOTIFY(SelectionChanged);
 | 
|---|
| [c1d837] | 646 |   const atomIdsVector_t atomids = selectedAtoms_Stack.top();
 | 
|---|
 | 647 |   boost::function<void (const atomId_t)> IdSelector =
 | 
|---|
 | 648 |       boost::bind(static_cast<void (World::*)(const atomId_t)>(&World::selectAtom), this, _1);
 | 
|---|
| [7f1865d] | 649 |   unselectVectorOfInstances<AtomSet>(selectedAtoms.begin(), selectedAtoms.end());
 | 
|---|
| [c1d837] | 650 |   selectedAtoms.clear();
 | 
|---|
 | 651 |   std::for_each(atomids.begin(),atomids.end(), IdSelector);
 | 
|---|
| [cad383] | 652 |   selectedAtoms_Stack.pop();
 | 
|---|
 | 653 | }
 | 
|---|
 | 654 | 
 | 
|---|
 | 655 | void World::pushAtomSelection(){
 | 
|---|
 | 656 |   OBSERVE;
 | 
|---|
 | 657 |   NOTIFY(SelectionChanged);
 | 
|---|
| [c1d837] | 658 |   atomIdsVector_t atomids(countSelectedAtoms(), (atomId_t)-1);
 | 
|---|
 | 659 |   std::copy(
 | 
|---|
 | 660 |       MapKeyIterator<AtomSelectionConstIterator>(beginAtomSelection()),
 | 
|---|
 | 661 |       MapKeyIterator<AtomSelectionConstIterator>(endAtomSelection()),
 | 
|---|
 | 662 |       atomids.begin());
 | 
|---|
 | 663 |   selectedAtoms_Stack.push( atomids );
 | 
|---|
| [7f1865d] | 664 |   unselectVectorOfInstances<AtomSet>(selectedAtoms.begin(), selectedAtoms.end());
 | 
|---|
| [cad383] | 665 |   selectedAtoms.clear();
 | 
|---|
 | 666 | }
 | 
|---|
 | 667 | 
 | 
|---|
| [e4afb4] | 668 | void World::selectAtom(const atom *_atom){
 | 
|---|
| [69643a] | 669 |   OBSERVE;
 | 
|---|
 | 670 |   NOTIFY(SelectionChanged);
 | 
|---|
| [e4afb4] | 671 |   // atom * is unchanged in this function, but we do store entity as changeable
 | 
|---|
 | 672 |   ASSERT(_atom,"Invalid pointer in selection of atom");
 | 
|---|
| [7f1865d] | 673 |   selectAtom(_atom->getId());
 | 
|---|
| [90c4280] | 674 | }
 | 
|---|
 | 675 | 
 | 
|---|
| [e4afb4] | 676 | void World::selectAtom(const atomId_t id){
 | 
|---|
| [69643a] | 677 |   OBSERVE;
 | 
|---|
 | 678 |   NOTIFY(SelectionChanged);
 | 
|---|
| [90c4280] | 679 |   ASSERT(atoms.count(id),"Atom Id selected that was not in the world");
 | 
|---|
 | 680 |   selectedAtoms[id]=atoms[id];
 | 
|---|
| [7f1865d] | 681 |   atoms[id]->select();
 | 
|---|
| [90c4280] | 682 | }
 | 
|---|
 | 683 | 
 | 
|---|
 | 684 | void World::selectAllAtoms(AtomDescriptor descr){
 | 
|---|
| [69643a] | 685 |   OBSERVE;
 | 
|---|
 | 686 |   NOTIFY(SelectionChanged);
 | 
|---|
| [90c4280] | 687 |   internal_AtomIterator begin = getAtomIter_internal(descr);
 | 
|---|
 | 688 |   internal_AtomIterator end = atomEnd_internal();
 | 
|---|
| [e4afb4] | 689 |   void (World::*func)(const atom*) = &World::selectAtom; // needed for type resolution of overloaded function
 | 
|---|
| [90c4280] | 690 |   for_each(begin,end,bind1st(mem_fun(func),this)); // func is select... see above
 | 
|---|
 | 691 | }
 | 
|---|
 | 692 | 
 | 
|---|
| [e4afb4] | 693 | void World::selectAtomsOfMolecule(const molecule *_mol){
 | 
|---|
| [69643a] | 694 |   OBSERVE;
 | 
|---|
 | 695 |   NOTIFY(SelectionChanged);
 | 
|---|
| [90c4280] | 696 |   ASSERT(_mol,"Invalid pointer to molecule in selection of Atoms of Molecule");
 | 
|---|
 | 697 |   // need to make it const to get the fast iterators
 | 
|---|
 | 698 |   const molecule *mol = _mol;
 | 
|---|
| [e4afb4] | 699 |   void (World::*func)(const atom*) = &World::selectAtom; // needed for type resolution of overloaded function
 | 
|---|
| [90c4280] | 700 |   for_each(mol->begin(),mol->end(),bind1st(mem_fun(func),this)); // func is select... see above
 | 
|---|
 | 701 | }
 | 
|---|
 | 702 | 
 | 
|---|
| [e4afb4] | 703 | void World::selectAtomsOfMolecule(const moleculeId_t id){
 | 
|---|
| [69643a] | 704 |   OBSERVE;
 | 
|---|
 | 705 |   NOTIFY(SelectionChanged);
 | 
|---|
| [90c4280] | 706 |   ASSERT(molecules.count(id),"No molecule with the given id upon Selection of atoms from molecule");
 | 
|---|
 | 707 |   selectAtomsOfMolecule(molecules[id]);
 | 
|---|
 | 708 | }
 | 
|---|
 | 709 | 
 | 
|---|
| [e4afb4] | 710 | void World::unselectAtom(const atom *_atom){
 | 
|---|
| [69643a] | 711 |   OBSERVE;
 | 
|---|
 | 712 |   NOTIFY(SelectionChanged);
 | 
|---|
| [e4afb4] | 713 |   ASSERT(_atom,"Invalid pointer in unselection of atom");
 | 
|---|
 | 714 |   unselectAtom(_atom->getId());
 | 
|---|
| [61d655e] | 715 | }
 | 
|---|
 | 716 | 
 | 
|---|
| [e4afb4] | 717 | void World::unselectAtom(const atomId_t id){
 | 
|---|
| [69643a] | 718 |   OBSERVE;
 | 
|---|
 | 719 |   NOTIFY(SelectionChanged);
 | 
|---|
| [61d655e] | 720 |   ASSERT(atoms.count(id),"Atom Id unselected that was not in the world");
 | 
|---|
| [7f1865d] | 721 |   atoms[id]->unselect();
 | 
|---|
| [61d655e] | 722 |   selectedAtoms.erase(id);
 | 
|---|
 | 723 | }
 | 
|---|
 | 724 | 
 | 
|---|
 | 725 | void World::unselectAllAtoms(AtomDescriptor descr){
 | 
|---|
| [69643a] | 726 |   OBSERVE;
 | 
|---|
 | 727 |   NOTIFY(SelectionChanged);
 | 
|---|
| [61d655e] | 728 |   internal_AtomIterator begin = getAtomIter_internal(descr);
 | 
|---|
 | 729 |   internal_AtomIterator end = atomEnd_internal();
 | 
|---|
| [e4afb4] | 730 |   void (World::*func)(const atom*) = &World::unselectAtom; // needed for type resolution of overloaded function
 | 
|---|
| [61d655e] | 731 |   for_each(begin,end,bind1st(mem_fun(func),this)); // func is unselect... see above
 | 
|---|
 | 732 | }
 | 
|---|
 | 733 | 
 | 
|---|
| [e4afb4] | 734 | void World::unselectAtomsOfMolecule(const molecule *_mol){
 | 
|---|
| [69643a] | 735 |   OBSERVE;
 | 
|---|
 | 736 |   NOTIFY(SelectionChanged);
 | 
|---|
| [61d655e] | 737 |   ASSERT(_mol,"Invalid pointer to molecule in selection of Atoms of Molecule");
 | 
|---|
 | 738 |   // need to make it const to get the fast iterators
 | 
|---|
 | 739 |   const molecule *mol = _mol;
 | 
|---|
| [e4afb4] | 740 |   void (World::*func)(const atom*) = &World::unselectAtom; // needed for type resolution of overloaded function
 | 
|---|
| [992bd5] | 741 |   for_each(mol->begin(),mol->end(),bind1st(mem_fun(func),this)); // func is unselect... see above
 | 
|---|
| [61d655e] | 742 | }
 | 
|---|
 | 743 | 
 | 
|---|
| [e4afb4] | 744 | void World::unselectAtomsOfMolecule(const moleculeId_t id){
 | 
|---|
| [69643a] | 745 |   OBSERVE;
 | 
|---|
 | 746 |   NOTIFY(SelectionChanged);
 | 
|---|
| [61d655e] | 747 |   ASSERT(molecules.count(id),"No molecule with the given id upon Selection of atoms from molecule");
 | 
|---|
 | 748 |   unselectAtomsOfMolecule(molecules[id]);
 | 
|---|
 | 749 | }
 | 
|---|
 | 750 | 
 | 
|---|
| [e472eab] | 751 | size_t World::countSelectedAtoms() const {
 | 
|---|
| [eacc3b] | 752 |   size_t count = 0;
 | 
|---|
| [e472eab] | 753 |   for (AtomSet::const_iterator iter = selectedAtoms.begin(); iter != selectedAtoms.end(); ++iter)
 | 
|---|
| [eacc3b] | 754 |     count++;
 | 
|---|
 | 755 |   return count;
 | 
|---|
 | 756 | }
 | 
|---|
 | 757 | 
 | 
|---|
| [e4afb4] | 758 | bool World::isSelected(const atom *_atom) const {
 | 
|---|
| [7f1865d] | 759 |   const bool status = isAtomSelected(_atom->getId());
 | 
|---|
 | 760 |    ASSERT( status == _atom->selected,
 | 
|---|
 | 761 |       "World::isSelected() - mismatch between selection state in atom "+
 | 
|---|
 | 762 |       toString(_atom->getId())+" and World.");
 | 
|---|
 | 763 |   return status;
 | 
|---|
| [89643d] | 764 | }
 | 
|---|
 | 765 | 
 | 
|---|
 | 766 | bool World::isAtomSelected(const atomId_t no) const {
 | 
|---|
 | 767 |   return selectedAtoms.find(no) != selectedAtoms.end();
 | 
|---|
| [e0e156] | 768 | }
 | 
|---|
 | 769 | 
 | 
|---|
| [99db9b] | 770 | std::vector<atom *> World::getSelectedAtoms() {
 | 
|---|
| [e472eab] | 771 |   std::vector<atom *> returnAtoms;
 | 
|---|
| [99db9b] | 772 |   std::transform(
 | 
|---|
 | 773 |       selectedAtoms.begin(),
 | 
|---|
 | 774 |       selectedAtoms.end(),
 | 
|---|
 | 775 |       back_inserter(returnAtoms),
 | 
|---|
 | 776 |       _take<atom*,World::AtomSet::value_type>::get);
 | 
|---|
 | 777 |   return returnAtoms;
 | 
|---|
 | 778 | }
 | 
|---|
 | 779 | 
 | 
|---|
 | 780 | std::vector<const atom *> World::getSelectedAtoms() const {
 | 
|---|
 | 781 |   std::vector<const atom *> returnAtoms;
 | 
|---|
 | 782 |   std::transform(
 | 
|---|
 | 783 |       selectedAtoms.begin(),
 | 
|---|
 | 784 |       selectedAtoms.end(),
 | 
|---|
 | 785 |       back_inserter(returnAtoms),
 | 
|---|
 | 786 |       _take<atom*,World::AtomSet::value_type>::get);
 | 
|---|
| [e472eab] | 787 |   return returnAtoms;
 | 
|---|
 | 788 | }
 | 
|---|
 | 789 | 
 | 
|---|
| [143263] | 790 | std::vector<atomId_t> World::getSelectedAtomIds() const {
 | 
|---|
 | 791 |   std::vector<atomId_t> returnAtomIds;
 | 
|---|
 | 792 |   std::transform(
 | 
|---|
 | 793 |       selectedAtoms.begin(),
 | 
|---|
 | 794 |       selectedAtoms.end(),
 | 
|---|
 | 795 |       back_inserter(returnAtomIds),
 | 
|---|
 | 796 |       _take<atom*,World::AtomSet::value_type>::getKey);
 | 
|---|
 | 797 |   return returnAtomIds;
 | 
|---|
 | 798 | }
 | 
|---|
| [e472eab] | 799 | 
 | 
|---|
| [90c4280] | 800 | // Molecules
 | 
|---|
 | 801 | 
 | 
|---|
 | 802 | void World::clearMoleculeSelection(){
 | 
|---|
| [69643a] | 803 |   OBSERVE;
 | 
|---|
 | 804 |   NOTIFY(SelectionChanged);
 | 
|---|
| [7f1865d] | 805 |   unselectVectorOfInstances<MoleculeSet>(selectedMolecules.begin(), selectedMolecules.end());
 | 
|---|
| [90c4280] | 806 |   selectedMolecules.clear();
 | 
|---|
 | 807 | }
 | 
|---|
 | 808 | 
 | 
|---|
| [ebc499] | 809 | void World::invertMoleculeSelection(){
 | 
|---|
 | 810 |   // get all molecules not selected
 | 
|---|
 | 811 |   typedef std::vector<molecule *> MoleculeVector_t;
 | 
|---|
 | 812 |   MoleculeVector_t invertedSelection(getAllMolecules());
 | 
|---|
 | 813 |   bool (World::*predicate)(const molecule*) const = &World::isSelected; // needed for type resolution of overloaded function
 | 
|---|
 | 814 |   MoleculeVector_t::iterator iter =
 | 
|---|
 | 815 |       std::remove_if(invertedSelection.begin(), invertedSelection.end(),
 | 
|---|
 | 816 |           std::bind1st(std::mem_fun(predicate), this));
 | 
|---|
 | 817 |   invertedSelection.erase(iter, invertedSelection.end());
 | 
|---|
 | 818 |   // apply new selection
 | 
|---|
| [7f1865d] | 819 |   unselectVectorOfInstances<MoleculeSet>(selectedMolecules.begin(), selectedMolecules.end());
 | 
|---|
| [ebc499] | 820 |   selectedMolecules.clear();
 | 
|---|
 | 821 |   void (World::*selector)(const molecule*) = &World::selectMolecule; // needed for type resolution of overloaded function
 | 
|---|
 | 822 |   std::for_each(invertedSelection.begin(),invertedSelection.end(),
 | 
|---|
 | 823 |       std::bind1st(std::mem_fun(selector),this)); // func is select... see above
 | 
|---|
 | 824 | }
 | 
|---|
 | 825 | 
 | 
|---|
| [cad383] | 826 | void World::popMoleculeSelection(){
 | 
|---|
 | 827 |   OBSERVE;
 | 
|---|
 | 828 |   NOTIFY(SelectionChanged);
 | 
|---|
| [c1d837] | 829 |   const moleculeIdsVector_t moleculeids = selectedMolecules_Stack.top();
 | 
|---|
 | 830 |   boost::function<void (const moleculeId_t)> IdSelector =
 | 
|---|
 | 831 |       boost::bind(static_cast<void (World::*)(const moleculeId_t)>(&World::selectMolecule), this, _1);
 | 
|---|
| [7f1865d] | 832 |   unselectVectorOfInstances<MoleculeSet>(selectedMolecules.begin(), selectedMolecules.end());
 | 
|---|
| [c1d837] | 833 |   selectedMolecules.clear();
 | 
|---|
 | 834 |   std::for_each(moleculeids.begin(),moleculeids.end(), IdSelector);
 | 
|---|
| [cad383] | 835 |   selectedMolecules_Stack.pop();
 | 
|---|
 | 836 | }
 | 
|---|
 | 837 | 
 | 
|---|
 | 838 | void World::pushMoleculeSelection(){
 | 
|---|
 | 839 |   OBSERVE;
 | 
|---|
 | 840 |   NOTIFY(SelectionChanged);
 | 
|---|
| [c1d837] | 841 |   moleculeIdsVector_t moleculeids(countSelectedMolecules(), (moleculeId_t)-1);
 | 
|---|
 | 842 |   boost::function<moleculeId_t (const molecule*)> IdRetriever =
 | 
|---|
 | 843 |       boost::bind(&molecule::getId, _1);
 | 
|---|
 | 844 |   std::copy(
 | 
|---|
 | 845 |       MapKeyIterator<MoleculeSelectionConstIterator>(beginMoleculeSelection()),
 | 
|---|
 | 846 |       MapKeyIterator<MoleculeSelectionConstIterator>(endMoleculeSelection()),
 | 
|---|
 | 847 |       moleculeids.begin());
 | 
|---|
 | 848 |   selectedMolecules_Stack.push( moleculeids );
 | 
|---|
| [7f1865d] | 849 |   unselectVectorOfInstances<MoleculeSet>(selectedMolecules.begin(), selectedMolecules.end());
 | 
|---|
| [cad383] | 850 |   selectedMolecules.clear();
 | 
|---|
 | 851 | }
 | 
|---|
 | 852 | 
 | 
|---|
| [e4afb4] | 853 | void World::selectMolecule(const molecule *_mol){
 | 
|---|
| [69643a] | 854 |   OBSERVE;
 | 
|---|
 | 855 |   NOTIFY(SelectionChanged);
 | 
|---|
| [e4afb4] | 856 |   // molecule * is unchanged in this function, but we do store entity as changeable
 | 
|---|
 | 857 |   ASSERT(_mol,"Invalid pointer to molecule in selection");
 | 
|---|
| [7f1865d] | 858 |   selectMolecule(_mol->getId());
 | 
|---|
| [90c4280] | 859 | }
 | 
|---|
 | 860 | 
 | 
|---|
| [e4afb4] | 861 | void World::selectMolecule(const moleculeId_t id){
 | 
|---|
| [69643a] | 862 |   OBSERVE;
 | 
|---|
 | 863 |   NOTIFY(SelectionChanged);
 | 
|---|
| [90c4280] | 864 |   ASSERT(molecules.count(id),"Molecule Id selected that was not in the world");
 | 
|---|
| [7f1865d] | 865 |   molecules[id]->select();
 | 
|---|
| [90c4280] | 866 |   selectedMolecules[id]=molecules[id];
 | 
|---|
 | 867 | }
 | 
|---|
 | 868 | 
 | 
|---|
| [e472eab] | 869 | void World::selectAllMolecules(MoleculeDescriptor descr){
 | 
|---|
| [69643a] | 870 |   OBSERVE;
 | 
|---|
 | 871 |   NOTIFY(SelectionChanged);
 | 
|---|
| [90c4280] | 872 |   internal_MoleculeIterator begin = getMoleculeIter_internal(descr);
 | 
|---|
 | 873 |   internal_MoleculeIterator end = moleculeEnd_internal();
 | 
|---|
| [e4afb4] | 874 |   void (World::*func)(const molecule*) = &World::selectMolecule; // needed for type resolution of overloaded function
 | 
|---|
| [90c4280] | 875 |   for_each(begin,end,bind1st(mem_fun(func),this)); // func is select... see above
 | 
|---|
 | 876 | }
 | 
|---|
 | 877 | 
 | 
|---|
| [e4afb4] | 878 | void World::selectMoleculeOfAtom(const atom *_atom){
 | 
|---|
| [69643a] | 879 |   OBSERVE;
 | 
|---|
 | 880 |   NOTIFY(SelectionChanged);
 | 
|---|
| [e4afb4] | 881 |   ASSERT(_atom,"Invalid atom pointer in selection of MoleculeOfAtom");
 | 
|---|
| [270bdf] | 882 |   const molecule *mol=_atom->getMolecule();
 | 
|---|
| [90c4280] | 883 |   // the atom might not be part of a molecule
 | 
|---|
 | 884 |   if(mol){
 | 
|---|
 | 885 |     selectMolecule(mol);
 | 
|---|
 | 886 |   }
 | 
|---|
 | 887 | }
 | 
|---|
 | 888 | 
 | 
|---|
| [e4afb4] | 889 | void World::selectMoleculeOfAtom(const atomId_t id){
 | 
|---|
| [69643a] | 890 |   OBSERVE;
 | 
|---|
 | 891 |   NOTIFY(SelectionChanged);
 | 
|---|
| [90c4280] | 892 |   ASSERT(atoms.count(id),"No such atom with given ID in selection of Molecules of Atom");\
 | 
|---|
 | 893 |   selectMoleculeOfAtom(atoms[id]);
 | 
|---|
 | 894 | }
 | 
|---|
 | 895 | 
 | 
|---|
| [e4afb4] | 896 | void World::unselectMolecule(const molecule *_mol){
 | 
|---|
| [69643a] | 897 |   OBSERVE;
 | 
|---|
 | 898 |   NOTIFY(SelectionChanged);
 | 
|---|
| [e4afb4] | 899 |   ASSERT(_mol,"invalid pointer in unselection of molecule");
 | 
|---|
 | 900 |   unselectMolecule(_mol->getId());
 | 
|---|
| [61d655e] | 901 | }
 | 
|---|
 | 902 | 
 | 
|---|
| [e4afb4] | 903 | void World::unselectMolecule(const moleculeId_t id){
 | 
|---|
| [69643a] | 904 |   OBSERVE;
 | 
|---|
 | 905 |   NOTIFY(SelectionChanged);
 | 
|---|
| [61d655e] | 906 |   ASSERT(molecules.count(id),"No such molecule with ID in unselection");
 | 
|---|
| [7f1865d] | 907 |   molecules[id]->unselect();
 | 
|---|
| [61d655e] | 908 |   selectedMolecules.erase(id);
 | 
|---|
 | 909 | }
 | 
|---|
 | 910 | 
 | 
|---|
| [e472eab] | 911 | void World::unselectAllMolecules(MoleculeDescriptor descr){
 | 
|---|
| [69643a] | 912 |   OBSERVE;
 | 
|---|
 | 913 |   NOTIFY(SelectionChanged);
 | 
|---|
| [61d655e] | 914 |   internal_MoleculeIterator begin = getMoleculeIter_internal(descr);
 | 
|---|
 | 915 |   internal_MoleculeIterator end = moleculeEnd_internal();
 | 
|---|
| [e4afb4] | 916 |   void (World::*func)(const molecule*) = &World::unselectMolecule; // needed for type resolution of overloaded function
 | 
|---|
| [61d655e] | 917 |   for_each(begin,end,bind1st(mem_fun(func),this)); // func is unselect... see above
 | 
|---|
 | 918 | }
 | 
|---|
 | 919 | 
 | 
|---|
| [e4afb4] | 920 | void World::unselectMoleculeOfAtom(const atom *_atom){
 | 
|---|
| [69643a] | 921 |   OBSERVE;
 | 
|---|
 | 922 |   NOTIFY(SelectionChanged);
 | 
|---|
| [e4afb4] | 923 |   ASSERT(_atom,"Invalid atom pointer in selection of MoleculeOfAtom");
 | 
|---|
| [270bdf] | 924 |   const molecule *mol=_atom->getMolecule();
 | 
|---|
| [61d655e] | 925 |   // the atom might not be part of a molecule
 | 
|---|
 | 926 |   if(mol){
 | 
|---|
 | 927 |     unselectMolecule(mol);
 | 
|---|
 | 928 |   }
 | 
|---|
 | 929 | }
 | 
|---|
 | 930 | 
 | 
|---|
| [e4afb4] | 931 | void World::unselectMoleculeOfAtom(const atomId_t id){
 | 
|---|
| [69643a] | 932 |   OBSERVE;
 | 
|---|
 | 933 |   NOTIFY(SelectionChanged);
 | 
|---|
| [61d655e] | 934 |   ASSERT(atoms.count(id),"No such atom with given ID in selection of Molecules of Atom");\
 | 
|---|
 | 935 |   unselectMoleculeOfAtom(atoms[id]);
 | 
|---|
 | 936 | }
 | 
|---|
 | 937 | 
 | 
|---|
| [e472eab] | 938 | size_t World::countSelectedMolecules() const {
 | 
|---|
| [eacc3b] | 939 |   size_t count = 0;
 | 
|---|
| [e472eab] | 940 |   for (MoleculeSet::const_iterator iter = selectedMolecules.begin(); iter != selectedMolecules.end(); ++iter)
 | 
|---|
| [eacc3b] | 941 |     count++;
 | 
|---|
 | 942 |   return count;
 | 
|---|
 | 943 | }
 | 
|---|
 | 944 | 
 | 
|---|
| [e4afb4] | 945 | bool World::isSelected(const molecule *_mol) const {
 | 
|---|
| [7f1865d] | 946 |   const bool status = isMoleculeSelected(_mol->getId());
 | 
|---|
 | 947 |   ASSERT( status == _mol->selected,
 | 
|---|
 | 948 |       "World::isSelected() - mismatch in selection status between mol "+
 | 
|---|
 | 949 |       toString(_mol->getId())+" and World.");
 | 
|---|
 | 950 |   return status;
 | 
|---|
| [89643d] | 951 | }
 | 
|---|
 | 952 | 
 | 
|---|
 | 953 | bool World::isMoleculeSelected(const moleculeId_t no) const {
 | 
|---|
 | 954 |   return selectedMolecules.find(no) != selectedMolecules.end();
 | 
|---|
| [e0e156] | 955 | }
 | 
|---|
 | 956 | 
 | 
|---|
| [97445f] | 957 | std::vector<molecule *> World::getSelectedMolecules() {
 | 
|---|
| [e472eab] | 958 |   std::vector<molecule *> returnMolecules;
 | 
|---|
| [97445f] | 959 |   std::transform(
 | 
|---|
 | 960 |       selectedMolecules.begin(),
 | 
|---|
 | 961 |       selectedMolecules.end(),
 | 
|---|
 | 962 |       back_inserter(returnMolecules),
 | 
|---|
 | 963 |       _take<molecule*,World::MoleculeSet::value_type>::get);
 | 
|---|
 | 964 |   return returnMolecules;
 | 
|---|
 | 965 | }
 | 
|---|
 | 966 | 
 | 
|---|
 | 967 | std::vector<const molecule *> World::getSelectedMolecules() const {
 | 
|---|
 | 968 |   std::vector<const molecule *> returnMolecules;
 | 
|---|
 | 969 |   std::transform(
 | 
|---|
 | 970 |       selectedMolecules.begin(),
 | 
|---|
 | 971 |       selectedMolecules.end(),
 | 
|---|
 | 972 |       back_inserter(returnMolecules),
 | 
|---|
 | 973 |       _take<molecule*,World::MoleculeSet::value_type>::get);
 | 
|---|
| [e472eab] | 974 |   return returnMolecules;
 | 
|---|
 | 975 | }
 | 
|---|
 | 976 | 
 | 
|---|
| [143263] | 977 | std::vector<moleculeId_t> World::getSelectedMoleculeIds() const {
 | 
|---|
 | 978 |   std::vector<moleculeId_t> returnMoleculeIds;
 | 
|---|
 | 979 |   std::transform(
 | 
|---|
 | 980 |       selectedMolecules.begin(),
 | 
|---|
 | 981 |       selectedMolecules.end(),
 | 
|---|
 | 982 |       back_inserter(returnMoleculeIds),
 | 
|---|
 | 983 |       _take<molecule*,World::MoleculeSet::value_type>::getKey);
 | 
|---|
 | 984 |   return returnMoleculeIds;
 | 
|---|
 | 985 | }
 | 
|---|
 | 986 | 
 | 
|---|
| [3839e5] | 987 | /******************* Iterators over Selection *****************************/
 | 
|---|
 | 988 | World::AtomSelectionIterator World::beginAtomSelection(){
 | 
|---|
 | 989 |   return selectedAtoms.begin();
 | 
|---|
 | 990 | }
 | 
|---|
 | 991 | 
 | 
|---|
 | 992 | World::AtomSelectionIterator World::endAtomSelection(){
 | 
|---|
 | 993 |   return selectedAtoms.end();
 | 
|---|
 | 994 | }
 | 
|---|
 | 995 | 
 | 
|---|
| [38f991] | 996 | World::AtomSelectionConstIterator World::beginAtomSelection() const{
 | 
|---|
 | 997 |   return selectedAtoms.begin();
 | 
|---|
 | 998 | }
 | 
|---|
 | 999 | 
 | 
|---|
 | 1000 | World::AtomSelectionConstIterator World::endAtomSelection() const{
 | 
|---|
 | 1001 |   return selectedAtoms.end();
 | 
|---|
 | 1002 | }
 | 
|---|
 | 1003 | 
 | 
|---|
| [3839e5] | 1004 | 
 | 
|---|
 | 1005 | World::MoleculeSelectionIterator World::beginMoleculeSelection(){
 | 
|---|
 | 1006 |   return selectedMolecules.begin();
 | 
|---|
 | 1007 | }
 | 
|---|
 | 1008 | 
 | 
|---|
 | 1009 | World::MoleculeSelectionIterator World::endMoleculeSelection(){
 | 
|---|
 | 1010 |   return selectedMolecules.end();
 | 
|---|
 | 1011 | }
 | 
|---|
 | 1012 | 
 | 
|---|
| [38f991] | 1013 | World::MoleculeSelectionConstIterator World::beginMoleculeSelection() const{
 | 
|---|
 | 1014 |   return selectedMolecules.begin();
 | 
|---|
 | 1015 | }
 | 
|---|
 | 1016 | 
 | 
|---|
 | 1017 | World::MoleculeSelectionConstIterator World::endMoleculeSelection() const{
 | 
|---|
 | 1018 |   return selectedMolecules.end();
 | 
|---|
 | 1019 | }
 | 
|---|
 | 1020 | 
 | 
|---|
| [5d1611] | 1021 | /******************************* Singleton Stuff **************************/
 | 
|---|
 | 1022 | 
 | 
|---|
| [7a1ce5] | 1023 | World::World() :
 | 
|---|
| [cd5047] | 1024 |     Observable("World"),
 | 
|---|
| [f71baf] | 1025 |     BG(new BondGraph(true)),  // assume Angstroem for the moment
 | 
|---|
| [4ae823] | 1026 |     periode(new periodentafel(true)),
 | 
|---|
| [8e1f7af] | 1027 |     configuration(new config),
 | 
|---|
| [98dbee] | 1028 |     homologies(new HomologyContainer()),
 | 
|---|
| [43dad6] | 1029 |     Thermostats(new ThermoStatContainer),
 | 
|---|
| [e4b5de] | 1030 |     ExitFlag(0),
 | 
|---|
| [fa0b18] | 1031 |     atoms(this),
 | 
|---|
| [90c4280] | 1032 |     selectedAtoms(this),
 | 
|---|
| [3e4fb6] | 1033 |     atomIdPool(0, 20, 100),
 | 
|---|
| [51be2a] | 1034 |     molecules(this),
 | 
|---|
| [90c4280] | 1035 |     selectedMolecules(this),
 | 
|---|
| [2affd1] | 1036 |     moleculeIdPool(0, 20,100)
 | 
|---|
| [7dad10] | 1037 | {
 | 
|---|
| [84c494] | 1038 |   cell_size = new Box;
 | 
|---|
| [cca9ef] | 1039 |   RealSpaceMatrix domain;
 | 
|---|
| [84c494] | 1040 |   domain.at(0,0) = 20;
 | 
|---|
 | 1041 |   domain.at(1,1) = 20;
 | 
|---|
 | 1042 |   domain.at(2,2) = 20;
 | 
|---|
 | 1043 |   cell_size->setM(domain);
 | 
|---|
| [4834f4] | 1044 |   LCcontroller = new LinkedCell::LinkedCell_Controller(*cell_size);
 | 
|---|
| [387b36] | 1045 |   defaultName = "none";
 | 
|---|
| [02ce36] | 1046 |   Channels *OurChannel = new Channels;
 | 
|---|
| [574d377] | 1047 |   Observable::insertNotificationChannel( std::make_pair( static_cast<Observable *>(this), OurChannel) );
 | 
|---|
| [7188b1] | 1048 |   for (size_t type = 0; type < (size_t)NotificationType_MAX; ++type)
 | 
|---|
| [02ce36] | 1049 |     OurChannel->addChannel(type);
 | 
|---|
| [7dad10] | 1050 | }
 | 
|---|
| [5d1611] | 1051 | 
 | 
|---|
 | 1052 | World::~World()
 | 
|---|
| [354859] | 1053 | {
 | 
|---|
| [4834f4] | 1054 |   delete LCcontroller;
 | 
|---|
| [84c494] | 1055 |   delete cell_size;
 | 
|---|
| [cbc5fb] | 1056 |   MoleculeSet::iterator molIter;
 | 
|---|
 | 1057 |   for(molIter=molecules.begin();molIter!=molecules.end();++molIter){
 | 
|---|
 | 1058 |     DeleteMolecule((*molIter).second);
 | 
|---|
 | 1059 |   }
 | 
|---|
 | 1060 |   molecules.clear();
 | 
|---|
 | 1061 |   AtomSet::iterator atIter;
 | 
|---|
 | 1062 |   for(atIter=atoms.begin();atIter!=atoms.end();++atIter){
 | 
|---|
 | 1063 |     DeleteAtom((*atIter).second);
 | 
|---|
| [46d958] | 1064 |   }
 | 
|---|
 | 1065 |   atoms.clear();
 | 
|---|
| [7188b1] | 1066 | 
 | 
|---|
| [f71baf] | 1067 |   delete BG;
 | 
|---|
| [6cb9c76] | 1068 |   delete periode;
 | 
|---|
 | 1069 |   delete configuration;
 | 
|---|
 | 1070 |   delete Thermostats;
 | 
|---|
| [09f615] | 1071 |   delete homologies;
 | 
|---|
| [354859] | 1072 | }
 | 
|---|
| [5d1611] | 1073 | 
 | 
|---|
| [23b547] | 1074 | // Explicit instantiation of the singleton mechanism at this point
 | 
|---|
| [5d1611] | 1075 | 
 | 
|---|
| [3e4fb6] | 1076 | // moleculeId_t und atomId_t sind gleicher Basistyp, deswegen nur einen von beiden konstruieren
 | 
|---|
| [b97a60] | 1077 | CONSTRUCT_IDPOOL(atomId_t, uniqueId)
 | 
|---|
 | 1078 | CONSTRUCT_IDPOOL(moleculeId_t, continuousId)
 | 
|---|
| [3e4fb6] | 1079 | 
 | 
|---|
| [23b547] | 1080 | CONSTRUCT_SINGLETON(World)
 | 
|---|
| [5d1611] | 1081 | 
 | 
|---|
| [e2c2b1] | 1082 | CONSTRUCT_OBSERVEDCONTAINER(World::AtomSTLSet, UnobservedIterator<World::AtomSTLSet> )
 | 
|---|
| [5f1d5b8] | 1083 | 
 | 
|---|
| [e2c2b1] | 1084 | CONSTRUCT_OBSERVEDCONTAINER(World::MoleculeSTLSet, UnobservedIterator<World::MoleculeSTLSet> )
 | 
|---|