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