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