| 1 | /*
|
|---|
| 2 | * World.hpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: Feb 3, 2010
|
|---|
| 5 | * Author: crueger
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #ifndef WORLD_HPP_
|
|---|
| 9 | #define WORLD_HPP_
|
|---|
| 10 |
|
|---|
| 11 | // include config.h
|
|---|
| 12 | #ifdef HAVE_CONFIG_H
|
|---|
| 13 | #include <config.h>
|
|---|
| 14 | #endif
|
|---|
| 15 |
|
|---|
| 16 | /*********************************************** includes ***********************************/
|
|---|
| 17 |
|
|---|
| 18 | #include <string>
|
|---|
| 19 | #include <map>
|
|---|
| 20 | #include <vector>
|
|---|
| 21 | #include <set>
|
|---|
| 22 | #include <stack>
|
|---|
| 23 | #include <boost/thread.hpp>
|
|---|
| 24 | #include <boost/shared_ptr.hpp>
|
|---|
| 25 |
|
|---|
| 26 | #include "Actions/ActionTrait.hpp"
|
|---|
| 27 | #include "Atom/AtomSet.hpp"
|
|---|
| 28 | #include "Descriptors/SelectiveConstIterator.hpp"
|
|---|
| 29 | #include "Descriptors/SelectiveIterator.hpp"
|
|---|
| 30 | #include "CodePatterns/Observer/Observable.hpp"
|
|---|
| 31 | #include "CodePatterns/Observer/Observer.hpp"
|
|---|
| 32 | #include "CodePatterns/Cacheable.hpp"
|
|---|
| 33 | #include "CodePatterns/Singleton.hpp"
|
|---|
| 34 | #include "CodePatterns/Observer/ObservedContainer.hpp"
|
|---|
| 35 | #include "CodePatterns/Range.hpp"
|
|---|
| 36 | #include "IdPool_policy.hpp"
|
|---|
| 37 | #include "IdPool.hpp"
|
|---|
| 38 | #include "LinkedCell/LinkedCell_View.hpp"
|
|---|
| 39 | #include "types.hpp"
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 | // forward declarations
|
|---|
| 43 | class atom;
|
|---|
| 44 | class AtomDescriptor;
|
|---|
| 45 | class AtomDescriptor_impl;
|
|---|
| 46 | class BondGraph;
|
|---|
| 47 | class Box;
|
|---|
| 48 | class config;
|
|---|
| 49 | class HomologyContainer;
|
|---|
| 50 | class RealSpaceMatrix;
|
|---|
| 51 | class molecule;
|
|---|
| 52 | class MoleculeDescriptor;
|
|---|
| 53 | class MoleculeDescriptor_impl;
|
|---|
| 54 | class MoleculeListClass;
|
|---|
| 55 | class periodentafel;
|
|---|
| 56 | class ThermoStatContainer;
|
|---|
| 57 |
|
|---|
| 58 | namespace LinkedCell {
|
|---|
| 59 | class LinkedCell_Controller;
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | namespace MoleCuilder {
|
|---|
| 63 | class ManipulateAtomsProcess;
|
|---|
| 64 | template<typename T> class AtomsCalculation;
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | /****************************************** forward declarations *****************************/
|
|---|
| 68 |
|
|---|
| 69 | /********************************************** Class World *******************************/
|
|---|
| 70 |
|
|---|
| 71 | namespace detail {
|
|---|
| 72 | template <class T> const T* lastChanged()
|
|---|
| 73 | {
|
|---|
| 74 | ASSERT(0, "detail::lastChanged() - only specializations may be used.");
|
|---|
| 75 | return NULL;
|
|---|
| 76 | }
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | class World : public Singleton<World>, public Observable
|
|---|
| 80 | {
|
|---|
| 81 |
|
|---|
| 82 | // Make access to constructor and destructor possible from inside the singleton
|
|---|
| 83 | friend class Singleton<World>;
|
|---|
| 84 |
|
|---|
| 85 | // necessary for coupling with descriptors
|
|---|
| 86 | friend class AtomDescriptor_impl;
|
|---|
| 87 | friend class AtomDescriptor;
|
|---|
| 88 | friend class MoleculeDescriptor_impl;
|
|---|
| 89 | friend class MoleculeDescriptor;
|
|---|
| 90 | // coupling with descriptors over selection
|
|---|
| 91 | friend class AtomSelectionDescriptor_impl;
|
|---|
| 92 | friend class AtomOfMoleculeSelectionDescriptor_impl;
|
|---|
| 93 | friend class AtomOrderDescriptor_impl;
|
|---|
| 94 | friend class MoleculeOfAtomSelectionDescriptor_impl;
|
|---|
| 95 | friend class MoleculeOrderDescriptor_impl;
|
|---|
| 96 | friend class MoleculeSelectionDescriptor_impl;
|
|---|
| 97 |
|
|---|
| 98 | // Actions, calculations etc associated with the World
|
|---|
| 99 | friend class MoleCuilder::ManipulateAtomsProcess;
|
|---|
| 100 | template<typename> friend class MoleCuilder::AtomsCalculation;
|
|---|
| 101 | public:
|
|---|
| 102 | // some typedefs for the CONSTRUCT_... macros (no "," allows in a single parameter name)
|
|---|
| 103 | typedef std::map<atomId_t,atom*> AtomSTLSet;
|
|---|
| 104 | typedef std::map<moleculeId_t,molecule*> MoleculeSTLSet;
|
|---|
| 105 |
|
|---|
| 106 | // Types for Atom and Molecule structures
|
|---|
| 107 | typedef ObservedContainer< AtomSTLSet, UnobservedIterator<AtomSTLSet> > AtomSet;
|
|---|
| 108 | typedef ObservedContainer< MoleculeSTLSet, UnobservedIterator<MoleculeSTLSet> > MoleculeSet;
|
|---|
| 109 |
|
|---|
| 110 | typedef ATOMSET(std::vector) AtomComposite;
|
|---|
| 111 | typedef CONSTATOMSET(std::vector) ConstAtomComposite;
|
|---|
| 112 |
|
|---|
| 113 | /******* Notifications *******/
|
|---|
| 114 |
|
|---|
| 115 | //!> enumeration of present notification types: only insertion/removal of atoms or molecules
|
|---|
| 116 | enum NotificationType {
|
|---|
| 117 | AtomInserted,
|
|---|
| 118 | AtomRemoved,
|
|---|
| 119 | MoleculeInserted,
|
|---|
| 120 | MoleculeRemoved,
|
|---|
| 121 | SelectionChanged,
|
|---|
| 122 | NotificationType_MAX
|
|---|
| 123 | };
|
|---|
| 124 |
|
|---|
| 125 | //>! access to last changed element (atom or molecule)
|
|---|
| 126 | template <class T> const T* lastChanged() const
|
|---|
| 127 | { return detail::lastChanged<T>(); }
|
|---|
| 128 |
|
|---|
| 129 | const atomId_t lastChangedAtomId() const
|
|---|
| 130 | { return _lastchangedatomid; }
|
|---|
| 131 |
|
|---|
| 132 | const moleculeId_t lastChangedMolId() const
|
|---|
| 133 | { return _lastchangedmolid; }
|
|---|
| 134 |
|
|---|
| 135 | /***** getter and setter *****/
|
|---|
| 136 | // reference to pointer is used for legacy reason... reference will be removed latter to keep encapsulation of World object
|
|---|
| 137 | /**
|
|---|
| 138 | * returns the periodentafel for the world.
|
|---|
| 139 | */
|
|---|
| 140 | periodentafel *&getPeriode();
|
|---|
| 141 |
|
|---|
| 142 | /** Returns the BondGraph for the World.
|
|---|
| 143 | *
|
|---|
| 144 | * @return reference to BondGraph
|
|---|
| 145 | */
|
|---|
| 146 | BondGraph *&getBondGraph();
|
|---|
| 147 |
|
|---|
| 148 | /** Sets the World's BondGraph.
|
|---|
| 149 | *
|
|---|
| 150 | * @param _BG new BondGraph
|
|---|
| 151 | */
|
|---|
| 152 | void setBondGraph(BondGraph *_BG);
|
|---|
| 153 |
|
|---|
| 154 | /** Getter for homology container.
|
|---|
| 155 | *
|
|---|
| 156 | * \return const reference to homology container.
|
|---|
| 157 | */
|
|---|
| 158 | HomologyContainer &getHomologies();
|
|---|
| 159 |
|
|---|
| 160 | /** Setter for homology container.
|
|---|
| 161 | *
|
|---|
| 162 | * \param homologies reference to homologies, set to NULL
|
|---|
| 163 | */
|
|---|
| 164 | void resetHomologies(HomologyContainer *&homologies);
|
|---|
| 165 |
|
|---|
| 166 | /**
|
|---|
| 167 | * returns the configuration for the world.
|
|---|
| 168 | */
|
|---|
| 169 | config *&getConfig();
|
|---|
| 170 |
|
|---|
| 171 | /** Returns a notification_ptr for a specific type.
|
|---|
| 172 | *
|
|---|
| 173 | * @param type request type
|
|---|
| 174 | * @return reference to instance
|
|---|
| 175 | */
|
|---|
| 176 | Notification_ptr getNotification(enum NotificationType type) const;
|
|---|
| 177 |
|
|---|
| 178 | /**
|
|---|
| 179 | * returns the first atom that matches a given descriptor.
|
|---|
| 180 | * Do not rely on ordering for descriptors that match more than one atom.
|
|---|
| 181 | */
|
|---|
| 182 | atom* getAtom(AtomDescriptor descriptor);
|
|---|
| 183 |
|
|---|
| 184 | /**
|
|---|
| 185 | * returns the first atom that matches a given descriptor.
|
|---|
| 186 | * Do not rely on ordering for descriptors that match more than one atom.
|
|---|
| 187 | */
|
|---|
| 188 | const atom* getAtom(AtomDescriptor descriptor) const;
|
|---|
| 189 |
|
|---|
| 190 | /**
|
|---|
| 191 | * returns a vector containing all atoms that match a given descriptor
|
|---|
| 192 | */
|
|---|
| 193 | AtomComposite getAllAtoms(AtomDescriptor descriptor);
|
|---|
| 194 |
|
|---|
| 195 | /**
|
|---|
| 196 | * returns a vector containing all atoms that match a given descriptor
|
|---|
| 197 | */
|
|---|
| 198 | ConstAtomComposite getAllAtoms(AtomDescriptor descriptor) const;
|
|---|
| 199 |
|
|---|
| 200 | /**
|
|---|
| 201 | * returns a vector containing all atoms that match a given descriptor
|
|---|
| 202 | */
|
|---|
| 203 | AtomComposite getAllAtoms();
|
|---|
| 204 |
|
|---|
| 205 | /**
|
|---|
| 206 | * returns a vector containing all atoms that match a given descriptor
|
|---|
| 207 | */
|
|---|
| 208 | ConstAtomComposite getAllAtoms() const;
|
|---|
| 209 |
|
|---|
| 210 | /**
|
|---|
| 211 | * returns a calculation that calls a given function on all atoms matching a descriptor.
|
|---|
| 212 | * the calculation is not called at this point and can be used as an action, i.e. be stored in
|
|---|
| 213 | * menus, be kept around for later use etc.
|
|---|
| 214 | */
|
|---|
| 215 | template<typename T> MoleCuilder::AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,const MoleCuilder::ActionTrait &_trait,AtomDescriptor);
|
|---|
| 216 | template<typename T> MoleCuilder::AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,const MoleCuilder::ActionTrait &_trait);
|
|---|
| 217 |
|
|---|
| 218 | /**
|
|---|
| 219 | * get the number of atoms in the World
|
|---|
| 220 | */
|
|---|
| 221 | int numAtoms() const;
|
|---|
| 222 |
|
|---|
| 223 | /**
|
|---|
| 224 | * returns the first molecule that matches a given descriptor.
|
|---|
| 225 | * Do not rely on ordering for descriptors that match more than one molecule.
|
|---|
| 226 | */
|
|---|
| 227 | molecule *getMolecule(MoleculeDescriptor descriptor);
|
|---|
| 228 |
|
|---|
| 229 | /**
|
|---|
| 230 | * returns the first molecule that matches a given descriptor.
|
|---|
| 231 | * Do not rely on ordering for descriptors that match more than one molecule.
|
|---|
| 232 | */
|
|---|
| 233 | const molecule *getMolecule(MoleculeDescriptor descriptor) const;
|
|---|
| 234 |
|
|---|
| 235 | /**
|
|---|
| 236 | * returns a vector containing all molecules that match a given descriptor
|
|---|
| 237 | */
|
|---|
| 238 | std::vector<molecule*> getAllMolecules(MoleculeDescriptor descriptor);
|
|---|
| 239 |
|
|---|
| 240 | /**
|
|---|
| 241 | * returns a vector containing all molecules that match a given descriptor
|
|---|
| 242 | */
|
|---|
| 243 | std::vector<const molecule*> getAllMolecules(MoleculeDescriptor descriptor) const;
|
|---|
| 244 |
|
|---|
| 245 | /**
|
|---|
| 246 | * returns a vector containing all molecules that match a given descriptor
|
|---|
| 247 | */
|
|---|
| 248 | std::vector<molecule*> getAllMolecules();
|
|---|
| 249 | /**
|
|---|
| 250 | * returns a vector containing all molecules that match a given descriptor
|
|---|
| 251 | */
|
|---|
| 252 | std::vector<const molecule*> getAllMolecules() const;
|
|---|
| 253 |
|
|---|
| 254 | /**
|
|---|
| 255 | * get the number of molecules in the World
|
|---|
| 256 | */
|
|---|
| 257 | int numMolecules() const;
|
|---|
| 258 |
|
|---|
| 259 | /**
|
|---|
| 260 | * get the domain size as a symmetric matrix (6 components)
|
|---|
| 261 | */
|
|---|
| 262 | Box& getDomain();
|
|---|
| 263 |
|
|---|
| 264 | /**
|
|---|
| 265 | * Set the domain size from a matrix object
|
|---|
| 266 | *
|
|---|
| 267 | * Matrix needs to be symmetric
|
|---|
| 268 | */
|
|---|
| 269 | void setDomain(const RealSpaceMatrix &mat);
|
|---|
| 270 |
|
|---|
| 271 | /**
|
|---|
| 272 | * set the domain size as a symmetric matrix (6 components)
|
|---|
| 273 | */
|
|---|
| 274 | void setDomain(double * matrix);
|
|---|
| 275 |
|
|---|
| 276 | /** Returns a LinkedCell structure for obtaining neighbors quickly.
|
|---|
| 277 | *
|
|---|
| 278 | * @param distance desired linked cell edge length
|
|---|
| 279 | * @return view of restricted underlying LinkedCell_Model
|
|---|
| 280 | */
|
|---|
| 281 | LinkedCell::LinkedCell_View getLinkedCell(const double distance);
|
|---|
| 282 |
|
|---|
| 283 | /**
|
|---|
| 284 | * set the current time of the world.
|
|---|
| 285 | *
|
|---|
| 286 | * @param _step time step to set to
|
|---|
| 287 | */
|
|---|
| 288 | void setTime(const unsigned int _step);
|
|---|
| 289 |
|
|---|
| 290 | /**
|
|---|
| 291 | * get the current time of the world.
|
|---|
| 292 | *
|
|---|
| 293 | * @return current time step
|
|---|
| 294 | */
|
|---|
| 295 | const unsigned getTime() const;
|
|---|
| 296 |
|
|---|
| 297 | /**
|
|---|
| 298 | * get the default name
|
|---|
| 299 | */
|
|---|
| 300 | std::string getDefaultName();
|
|---|
| 301 |
|
|---|
| 302 | /**
|
|---|
| 303 | * set the default name
|
|---|
| 304 | */
|
|---|
| 305 | void setDefaultName(std::string name);
|
|---|
| 306 |
|
|---|
| 307 | /**
|
|---|
| 308 | * get pointer to World's ThermoStatContainer
|
|---|
| 309 | */
|
|---|
| 310 | ThermoStatContainer * getThermostats();
|
|---|
| 311 |
|
|---|
| 312 | /*
|
|---|
| 313 | * get the ExitFlag
|
|---|
| 314 | */
|
|---|
| 315 | int getExitFlag();
|
|---|
| 316 |
|
|---|
| 317 | /*
|
|---|
| 318 | * set the ExitFlag
|
|---|
| 319 | */
|
|---|
| 320 | void setExitFlag(int flag);
|
|---|
| 321 |
|
|---|
| 322 | /***** Methods to work with the World *****/
|
|---|
| 323 |
|
|---|
| 324 | /**
|
|---|
| 325 | * create a new molecule. This method should be used whenever any kind of molecule is needed. Assigns a unique
|
|---|
| 326 | * ID to the molecule and stores it in the World for later retrieval. Do not create molecules directly.
|
|---|
| 327 | */
|
|---|
| 328 | molecule *createMolecule();
|
|---|
| 329 |
|
|---|
| 330 | /**
|
|---|
| 331 | * Recreate a destroyed molecule.
|
|---|
| 332 | * This method assigns the molecule the specified \a _id. It returns NULL of the
|
|---|
| 333 | * id could not be assigned.
|
|---|
| 334 | */
|
|---|
| 335 | molecule *recreateMolecule(const moleculeId_t &_id);
|
|---|
| 336 |
|
|---|
| 337 | void destroyMolecule(molecule*);
|
|---|
| 338 | void destroyMolecule(moleculeId_t);
|
|---|
| 339 |
|
|---|
| 340 | /**
|
|---|
| 341 | * Create a new atom. This method should be used whenever any atom is needed. Assigns a unique ID and stores
|
|---|
| 342 | * the atom in the World. If the atom is not destroyed it will automatically be destroyed when the world ends.
|
|---|
| 343 | */
|
|---|
| 344 | atom *createAtom();
|
|---|
| 345 |
|
|---|
| 346 | /**
|
|---|
| 347 | * Recreate an atom after it was destroyed.
|
|---|
| 348 | * This method assigns the atom the specified \a _id. It returns NULL of the
|
|---|
| 349 | * id could not be assigned.
|
|---|
| 350 | */
|
|---|
| 351 | atom *recreateAtom(const atomId_t _id);
|
|---|
| 352 |
|
|---|
| 353 | /**
|
|---|
| 354 | * Registers a Atom unknown to world. Needed in some rare cases, e.g. when cloning atoms, or in some unittests.
|
|---|
| 355 | * Do not re-register Atoms already known to the world since this will cause double-frees.
|
|---|
| 356 | */
|
|---|
| 357 | int registerAtom(atom*);
|
|---|
| 358 |
|
|---|
| 359 | /**
|
|---|
| 360 | * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on
|
|---|
| 361 | * atom directly since this will leave the pointer inside the world.
|
|---|
| 362 | */
|
|---|
| 363 | void destroyAtom(atom*);
|
|---|
| 364 |
|
|---|
| 365 | /**
|
|---|
| 366 | * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on
|
|---|
| 367 | * atom directly since this will leave the pointer inside the world.
|
|---|
| 368 | */
|
|---|
| 369 | void destroyAtom(atomId_t);
|
|---|
| 370 |
|
|---|
| 371 | /**
|
|---|
| 372 | * used when changing an atom Id.
|
|---|
| 373 | * Unless you are calling this method from inside an atom don't fiddle with the third parameter.
|
|---|
| 374 | *
|
|---|
| 375 | * Return value indicates whether the change could be done or not.
|
|---|
| 376 | */
|
|---|
| 377 | bool changeAtomId(atomId_t oldId, atomId_t newId, atom* target=0);
|
|---|
| 378 |
|
|---|
| 379 | /**
|
|---|
| 380 | * used when changing an molecule Id.
|
|---|
| 381 | * Unless you are calling this method from inside an molecule don't fiddle with the third parameter.
|
|---|
| 382 | *
|
|---|
| 383 | * Return value indicates whether the change could be done or not.
|
|---|
| 384 | */
|
|---|
| 385 | bool changeMoleculeId(moleculeId_t oldId, moleculeId_t newId, molecule* target=0);
|
|---|
| 386 |
|
|---|
| 387 | /**
|
|---|
| 388 | * Produces a process that calls a function on all Atoms matching a given descriptor. The process is not
|
|---|
| 389 | * called at this time, so it can be passed around, stored inside menuItems etc.
|
|---|
| 390 | */
|
|---|
| 391 | MoleCuilder::ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string,AtomDescriptor);
|
|---|
| 392 | MoleCuilder::ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string);
|
|---|
| 393 |
|
|---|
| 394 | /****
|
|---|
| 395 | * Iterators to use internal data structures
|
|---|
| 396 | * All these iterators are observed to track changes.
|
|---|
| 397 | * There is a corresponding protected section with unobserved iterators,
|
|---|
| 398 | * which can be used internally when the extra speed is needed
|
|---|
| 399 | */
|
|---|
| 400 |
|
|---|
| 401 | typedef SelectiveIterator<atom*,AtomSet,AtomDescriptor> AtomIterator;
|
|---|
| 402 | typedef SelectiveConstIterator<atom*,AtomSet,AtomDescriptor> AtomConstIterator;
|
|---|
| 403 |
|
|---|
| 404 | /**
|
|---|
| 405 | * returns an iterator over all Atoms matching a given descriptor.
|
|---|
| 406 | * This iterator is observed, so don't keep it around unnecessary to
|
|---|
| 407 | * avoid unintended blocking.
|
|---|
| 408 | */
|
|---|
| 409 | AtomIterator getAtomIter(AtomDescriptor descr);
|
|---|
| 410 | AtomConstIterator getAtomIter(AtomDescriptor descr) const;
|
|---|
| 411 | AtomIterator getAtomIter();
|
|---|
| 412 | AtomConstIterator getAtomIter() const;
|
|---|
| 413 |
|
|---|
| 414 | AtomIterator atomEnd();
|
|---|
| 415 | AtomConstIterator atomEnd() const;
|
|---|
| 416 |
|
|---|
| 417 | typedef SelectiveIterator<molecule*,MoleculeSet,MoleculeDescriptor> MoleculeIterator;
|
|---|
| 418 | typedef SelectiveConstIterator<molecule*,MoleculeSet,MoleculeDescriptor> MoleculeConstIterator;
|
|---|
| 419 |
|
|---|
| 420 | /**
|
|---|
| 421 | * returns an iterator over all Molecules matching a given descriptor.
|
|---|
| 422 | * This iterator is observed, so don't keep it around unnecessary to
|
|---|
| 423 | * avoid unintended blocking.
|
|---|
| 424 | */
|
|---|
| 425 | MoleculeIterator getMoleculeIter(MoleculeDescriptor descr);
|
|---|
| 426 | MoleculeConstIterator getMoleculeIter(MoleculeDescriptor descr) const;
|
|---|
| 427 | MoleculeIterator getMoleculeIter();
|
|---|
| 428 | MoleculeConstIterator getMoleculeIter() const;
|
|---|
| 429 |
|
|---|
| 430 | MoleculeIterator moleculeEnd();
|
|---|
| 431 | MoleculeConstIterator moleculeEnd() const;
|
|---|
| 432 |
|
|---|
| 433 | /******** Selections of molecules and Atoms *************/
|
|---|
| 434 | void clearAtomSelection();
|
|---|
| 435 | void invertAtomSelection();
|
|---|
| 436 | void popAtomSelection();
|
|---|
| 437 | void pushAtomSelection();
|
|---|
| 438 | void selectAtom(const atom*);
|
|---|
| 439 | void selectAtom(const atomId_t);
|
|---|
| 440 | void selectAllAtoms(AtomDescriptor);
|
|---|
| 441 | void selectAtomsOfMolecule(const molecule*);
|
|---|
| 442 | void selectAtomsOfMolecule(const moleculeId_t);
|
|---|
| 443 | void unselectAtom(const atom*);
|
|---|
| 444 | void unselectAtom(const atomId_t);
|
|---|
| 445 | void unselectAllAtoms(AtomDescriptor);
|
|---|
| 446 | void unselectAtomsOfMolecule(const molecule*);
|
|---|
| 447 | void unselectAtomsOfMolecule(const moleculeId_t);
|
|---|
| 448 | size_t countSelectedAtoms() const;
|
|---|
| 449 | bool isSelected(const atom *_atom) const;
|
|---|
| 450 | bool isAtomSelected(const atomId_t no) const;
|
|---|
| 451 | std::vector<atom *> getSelectedAtoms();
|
|---|
| 452 | std::vector<const atom *> getSelectedAtoms() const;
|
|---|
| 453 | std::vector<atomId_t> getSelectedAtomIds() const;
|
|---|
| 454 |
|
|---|
| 455 | void clearMoleculeSelection();
|
|---|
| 456 | void invertMoleculeSelection();
|
|---|
| 457 | void popMoleculeSelection();
|
|---|
| 458 | void pushMoleculeSelection();
|
|---|
| 459 | void selectMolecule(const molecule*);
|
|---|
| 460 | void selectMolecule(const moleculeId_t);
|
|---|
| 461 | void selectAllMolecules(MoleculeDescriptor);
|
|---|
| 462 | void selectMoleculeOfAtom(const atom*);
|
|---|
| 463 | void selectMoleculeOfAtom(const atomId_t);
|
|---|
| 464 | void unselectMolecule(const molecule*);
|
|---|
| 465 | void unselectMolecule(const moleculeId_t);
|
|---|
| 466 | void unselectAllMolecules(MoleculeDescriptor);
|
|---|
| 467 | void unselectMoleculeOfAtom(const atom*);
|
|---|
| 468 | void unselectMoleculeOfAtom(const atomId_t);
|
|---|
| 469 | size_t countSelectedMolecules() const;
|
|---|
| 470 | bool isSelected(const molecule *_mol) const;
|
|---|
| 471 | bool isMoleculeSelected(const moleculeId_t no) const;
|
|---|
| 472 | std::vector<molecule *> getSelectedMolecules();
|
|---|
| 473 | std::vector<const molecule *> getSelectedMolecules() const;
|
|---|
| 474 | std::vector<moleculeId_t> getSelectedMoleculeIds() const;
|
|---|
| 475 |
|
|---|
| 476 | /******************** Iterators to selections *****************/
|
|---|
| 477 | typedef AtomSet::iterator AtomSelectionIterator;
|
|---|
| 478 | AtomSelectionIterator beginAtomSelection();
|
|---|
| 479 | AtomSelectionIterator endAtomSelection();
|
|---|
| 480 | typedef AtomSet::const_iterator AtomSelectionConstIterator;
|
|---|
| 481 | AtomSelectionConstIterator beginAtomSelection() const;
|
|---|
| 482 | AtomSelectionConstIterator endAtomSelection() const;
|
|---|
| 483 |
|
|---|
| 484 | typedef MoleculeSet::iterator MoleculeSelectionIterator;
|
|---|
| 485 | MoleculeSelectionIterator beginMoleculeSelection();
|
|---|
| 486 | MoleculeSelectionIterator endMoleculeSelection();
|
|---|
| 487 | typedef MoleculeSet::const_iterator MoleculeSelectionConstIterator;
|
|---|
| 488 | MoleculeSelectionConstIterator beginMoleculeSelection() const;
|
|---|
| 489 | MoleculeSelectionConstIterator endMoleculeSelection() const;
|
|---|
| 490 |
|
|---|
| 491 | protected:
|
|---|
| 492 | /****
|
|---|
| 493 | * Iterators to use internal data structures
|
|---|
| 494 | * All these iterators are unobserved for speed reasons.
|
|---|
| 495 | * There is a corresponding public section to these methods,
|
|---|
| 496 | * which produce observed iterators.*/
|
|---|
| 497 |
|
|---|
| 498 | // Atoms
|
|---|
| 499 | typedef SelectiveIterator<atom*,AtomSet::set_t,AtomDescriptor> internal_AtomIterator;
|
|---|
| 500 |
|
|---|
| 501 | /**
|
|---|
| 502 | * returns an iterator over all Atoms matching a given descriptor.
|
|---|
| 503 | * used for internal purposes, like AtomProcesses and AtomCalculations.
|
|---|
| 504 | */
|
|---|
| 505 | internal_AtomIterator getAtomIter_internal(AtomDescriptor descr);
|
|---|
| 506 |
|
|---|
| 507 | /**
|
|---|
| 508 | * returns an iterator to the end of the AtomSet. Due to overloading this iterator
|
|---|
| 509 | * can be compared to iterators produced by getAtomIter (see the mis-matching types).
|
|---|
| 510 | * Thus it can be used to detect when such an iterator is at the end of the list.
|
|---|
| 511 | * used for internal purposes, like AtomProcesses and AtomCalculations.
|
|---|
| 512 | */
|
|---|
| 513 | internal_AtomIterator atomEnd_internal();
|
|---|
| 514 |
|
|---|
| 515 | // Molecules
|
|---|
| 516 | typedef SelectiveIterator<molecule*,MoleculeSet::set_t,MoleculeDescriptor> internal_MoleculeIterator;
|
|---|
| 517 |
|
|---|
| 518 |
|
|---|
| 519 | /**
|
|---|
| 520 | * returns an iterator over all Molecules matching a given descriptor.
|
|---|
| 521 | * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
|
|---|
| 522 | */
|
|---|
| 523 | internal_MoleculeIterator getMoleculeIter_internal(MoleculeDescriptor descr);
|
|---|
| 524 |
|
|---|
| 525 | /**
|
|---|
| 526 | * returns an iterator to the end of the MoleculeSet. Due to overloading this iterator
|
|---|
| 527 | * can be compared to iterators produced by getMoleculeIter (see the mis-matching types).
|
|---|
| 528 | * Thus it can be used to detect when such an iterator is at the end of the list.
|
|---|
| 529 | * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
|
|---|
| 530 | */
|
|---|
| 531 | internal_MoleculeIterator moleculeEnd_internal();
|
|---|
| 532 |
|
|---|
| 533 |
|
|---|
| 534 | /******* Internal manipulation routines for double callback and Observer mechanism ******/
|
|---|
| 535 | void doManipulate(MoleCuilder::ManipulateAtomsProcess *);
|
|---|
| 536 |
|
|---|
| 537 | private:
|
|---|
| 538 | /** Helper to access atom::select() and molecule::select() only by type.
|
|---|
| 539 | *
|
|---|
| 540 | */
|
|---|
| 541 | template <class T>
|
|---|
| 542 | static void selectInstance(T _instance)
|
|---|
| 543 | { _instance->select(); }
|
|---|
| 544 |
|
|---|
| 545 | /** Helper to access atom::unselect() and molecule::unselect() only by type.
|
|---|
| 546 | *
|
|---|
| 547 | */
|
|---|
| 548 | template <class T>
|
|---|
| 549 | static void unselectInstance(T _instance)
|
|---|
| 550 | { _instance->unselect(); }
|
|---|
| 551 |
|
|---|
| 552 | /** Forward declaration of a helper function for selecting a vector of instances.
|
|---|
| 553 | *
|
|---|
| 554 | * \note only implemented inside World.
|
|---|
| 555 | *
|
|---|
| 556 | */
|
|---|
| 557 | template <class T>
|
|---|
| 558 | void selectVectorOfInstances(const typename T::iterator _begin, const typename T::iterator _end);
|
|---|
| 559 |
|
|---|
| 560 | /** Forward declaration of a helper function for unselecting a vector of instances.
|
|---|
| 561 | *
|
|---|
| 562 | * \note only implemented inside World.
|
|---|
| 563 | *
|
|---|
| 564 | */
|
|---|
| 565 | template <class T>
|
|---|
| 566 | void unselectVectorOfInstances(const typename T::iterator _begin, const typename T::iterator _end);
|
|---|
| 567 |
|
|---|
| 568 | private:
|
|---|
| 569 |
|
|---|
| 570 | friend const atom *detail::lastChanged<atom>();
|
|---|
| 571 | friend const molecule *detail::lastChanged<molecule>();
|
|---|
| 572 | static atom *_lastchangedatom;
|
|---|
| 573 | static atomId_t _lastchangedatomid;
|
|---|
| 574 | static molecule*_lastchangedmol;
|
|---|
| 575 | static moleculeId_t _lastchangedmolid;
|
|---|
| 576 |
|
|---|
| 577 | BondGraph *BG;
|
|---|
| 578 | periodentafel *periode;
|
|---|
| 579 | config *configuration;
|
|---|
| 580 | HomologyContainer *homologies;
|
|---|
| 581 | Box *cell_size;
|
|---|
| 582 | LinkedCell::LinkedCell_Controller *LCcontroller;
|
|---|
| 583 | std::string defaultName;
|
|---|
| 584 | class ThermoStatContainer *Thermostats;
|
|---|
| 585 | int ExitFlag;
|
|---|
| 586 | private:
|
|---|
| 587 |
|
|---|
| 588 | AtomSet atoms;
|
|---|
| 589 | AtomSet selectedAtoms;
|
|---|
| 590 | typedef std::vector<atomId_t> atomIdsVector_t;
|
|---|
| 591 | std::stack<atomIdsVector_t> selectedAtoms_Stack;
|
|---|
| 592 | /**
|
|---|
| 593 | * stores the pool for all available AtomIds below currAtomId
|
|---|
| 594 | *
|
|---|
| 595 | * The pool contains ranges of free ids in the form [bottom,top).
|
|---|
| 596 | */
|
|---|
| 597 | IdPool<atomId_t, uniqueId> atomIdPool;
|
|---|
| 598 |
|
|---|
| 599 | MoleculeSet molecules;
|
|---|
| 600 | MoleculeSet selectedMolecules;
|
|---|
| 601 | typedef std::vector<moleculeId_t> moleculeIdsVector_t;
|
|---|
| 602 | std::stack<moleculeIdsVector_t> selectedMolecules_Stack;
|
|---|
| 603 | /**
|
|---|
| 604 | * stores the pool for all available AtomIds below currAtomId
|
|---|
| 605 | *
|
|---|
| 606 | * The pool contains ranges of free ids in the form [bottom,top).
|
|---|
| 607 | */
|
|---|
| 608 | IdPool<moleculeId_t, continuousId> moleculeIdPool;
|
|---|
| 609 |
|
|---|
| 610 | private:
|
|---|
| 611 | /**
|
|---|
| 612 | * private constructor to ensure creation of the world using
|
|---|
| 613 | * the singleton pattern.
|
|---|
| 614 | */
|
|---|
| 615 | World();
|
|---|
| 616 |
|
|---|
| 617 | /**
|
|---|
| 618 | * private destructor to ensure destruction of the world using the
|
|---|
| 619 | * singleton pattern.
|
|---|
| 620 | */
|
|---|
| 621 | virtual ~World();
|
|---|
| 622 |
|
|---|
| 623 | /*****
|
|---|
| 624 | * some legacy stuff that is include for now but will be removed later
|
|---|
| 625 | *****/
|
|---|
| 626 | public:
|
|---|
| 627 | MoleculeListClass *&getMolecules();
|
|---|
| 628 |
|
|---|
| 629 | private:
|
|---|
| 630 | MoleculeListClass *molecules_deprecated;
|
|---|
| 631 | };
|
|---|
| 632 |
|
|---|
| 633 | /** Externalized stuff as member functions cannot be specialized without
|
|---|
| 634 | * specializing the class, too.
|
|---|
| 635 | */
|
|---|
| 636 | namespace detail {
|
|---|
| 637 | template <> inline const atom* lastChanged<atom>() { return World::_lastchangedatom; }
|
|---|
| 638 | template <> inline const molecule* lastChanged<molecule>() { return World::_lastchangedmol; }
|
|---|
| 639 | }
|
|---|
| 640 |
|
|---|
| 641 |
|
|---|
| 642 | #endif /* WORLD_HPP_ */
|
|---|