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