source: src/Actions/UndoRedoHelpers.hpp@ 91c409

Candidate_v1.7.0 stable
Last change on this file since 91c409 was 9782e20, checked in by Frederik Heber <frederik.heber@…>, 20 months ago

BondifyAction: added undo/redo.

  • DOC: fixed small typo in Action's explanation.
  • TEST: added regression test (also undo/redo).
  • Property mode set to 100644
File size: 5.4 KB
Line 
1/*
2 * UndoRedoHelpers.hpp
3 *
4 * Created on: Apr 5, 2012
5 * Author: heber
6 */
7
8#ifndef UNDOREDOHELPERS_HPP_
9#define UNDOREDOHELPERS_HPP_
10
11
12// include config.h
13#ifdef HAVE_CONFIG_H
14#include <config.h>
15#endif
16
17#include <vector>
18
19#include "Atom/AtomicInfo.hpp"
20#include "Bond/BondInfo.hpp"
21#include "WorldTime.hpp"
22
23namespace MoleCuilder {
24
25 /** Adds removed atoms back to the world whose state is stored as AtomicInfo.
26 *
27 * @param atoms vector of atomicInfo
28 * @return restoral was successful, at least atom could not be restored.
29 */
30 bool AddAtomsFromAtomicInfo(const std::vector<AtomicInfo> &atoms);
31
32 /** Adds removed molecules with their atoms back to the world.
33 *
34 * @param mol_atoms map of molecules with ids and their atoms as AtomicInfo
35 * \return true - restoral was successful, at least one atom or molecule could not be restored
36 */
37 bool AddMoleculesFromAtomicInfo(std::map< moleculeId_t, std::vector<AtomicInfo> > &mol_atoms);
38
39 /** Removes atoms whose state information is stored as AtomicInfo.
40 *
41 * @param atoms vector of atomicInfo
42 */
43 void RemoveAtomsFromAtomicInfo(std::vector<AtomicInfo> &atoms);
44
45 /** Stores the required bond information in for all \a atoms in \a bonds.
46 *
47 * @param atoms atoms whose bonds to store
48 * @param bonds vector with bond information on return
49 */
50 void StoreBondInformationFromAtoms(
51 const std::vector<const atom*> &atoms,
52 std::vector<BondInfo> &bonds);
53
54 /** Recreates bonds from information stored in \a bonds.
55 *
56 * @param bonds bond state information
57 * @return true - all bonds restored, false - at least one bond could not be restored
58 */
59 bool AddBondsFromBondInfo(const std::vector< BondInfo > &bonds);
60
61 /** Removes bonds from information stored in \a bonds.
62 *
63 * @param bonds bond state information
64 * @return true - all bonds removed, false - at least one bond could not be removed
65 */
66 bool RemoveBondsFromBondInfo(const std::vector< BondInfo > &bonds);
67
68 /** Sets atoms to state information stored as AtomicInfo.
69 *
70 * @param movedatoms vector of atomicInfo
71 * @param _step set state information for given world time
72 */
73 void SetAtomsFromAtomicInfo(
74 const std::vector<AtomicInfo> &_movedatoms,
75 const unsigned int _step = WorldTime::getTime());
76
77 /** Selects all atoms inside the given vector
78 *
79 * @param movedatoms vector of atomicInfo
80 */
81 void SelectAtomsFromAtomicInfo(const std::vector<AtomicInfo> &_movedatoms);
82
83 /** Helper function to allow setting arbitrary atom vectorial information via some
84 * \a setter function.
85 *
86 * @param movedatoms atoms whose info to change
87 * @param MovedToVector vector with old vectorial information
88 */
89 void ResetByFunction(
90 const std::vector<AtomicInfo> &movedatoms,
91 const std::vector<Vector> &MovedToVector,
92 boost::function<void(atom *, const Vector&)> &setter);
93
94 /** Sets the atoms whose id is stored in given AtomicInfo in \a movedatoms
95 * to position in \a MovedToVector.
96 *
97 * @param movedatoms atoms whose position to change
98 * @param MovedToVector vector with old positions
99 */
100 void ResetAtomPosition(const std::vector<AtomicInfo> &movedatoms, const std::vector<Vector> &MovedToVector);
101
102 /** Sets the atoms whose id is stored in given AtomicInfo in \a movedatoms
103 * to position in \a MovedToVector.
104 *
105 * @param movedatoms atoms whose position to change
106 * @param VelocityVector vector with old velocities
107 */
108 void ResetAtomVelocity(const std::vector<AtomicInfo> &movedatoms, const std::vector<Vector> &VelocityVector);
109
110 /** Sets the atoms whose id is stored in given AtomicInfo in \a movedatoms
111 * to position in \a MovedToVector.
112 *
113 * @param movedatoms atoms whose position to change
114 * @param ForceVector vector with old forces
115 */
116 void ResetAtomForce(const std::vector<AtomicInfo> &movedatoms, const std::vector<Vector> &ForceVector);
117
118 /** Remove all molecules identified by their ids given in \a ids.
119 *
120 * @param ids vector of molecular ids to remove
121 */
122 void RemoveMoleculesWithAtomsByIds(const std::vector<moleculeId_t> &ids);
123
124 /** Removes the time steps in given interval for all \a movedatoms.
125 *
126 * @param movedatoms atoms whose steps in [\a _firststep, \a _laststep] in time to remove
127 * @param _firststep first step in interval to be removed
128 * @param _laststep last step in interval to be removed
129 */
130 void removeSteps(
131 const std::vector<atomId_t> &movedatoms,
132 const unsigned int _firststep,
133 const unsigned int _laststep);
134
135 /** Adds another time step to all \a movedatoms.
136 *
137 * Note that the time step is initialized to zero.
138 *
139 * @param _ids atoms whose last step in time to remove
140 * @param _step which trajectory to insert/assign
141 */
142 void addNewStep(const std::vector<atomId_t> &_ids, const unsigned int _step);
143
144 /** Adds another time step to all \a movedatoms.
145 *
146 * Note that the time step is initialized to zero. This gives you a chance
147 * to set the time step and call setAtomsFromAtomicInfo() yourself.
148 *
149 * @param _movedatoms atoms whose last step in time to remove
150 * @param _step which trajectory to insert/assign
151 */
152 void addNewStep(const std::vector<AtomicInfo> &_movedatoms, const unsigned int _step);
153
154 /** Helper function to extract id information from vector of AtomicInfo.
155 *
156 * @param movedatoms atoms whose ids to extract
157 */
158 std::vector<atomId_t> getIdsFromAtomicInfo(const std::vector<AtomicInfo> &movedatoms);
159}
160
161
162
163#endif /* UNDOREDOHELPERS_HPP_ */
Note: See TracBrowser for help on using the repository browser.