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