source: src/Actions/Action.hpp@ d628da

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since d628da was 3139b2, checked in by Frederik Heber <heber@…>, 13 years ago

Renamed ActionTrait and ActionTraits.

  • the specialized Trait contains multiple OptionTraits, hence is now called ActionTrait_s_, where its base class (that just has the OptionTrait for itself) is called ActionTrait.
  • This caused many changes in other Action related files.
  • Property mode set to 100644
File size: 7.9 KB
Line 
1/*
2 * Action.hpp
3 *
4 * Created on: Dec 8, 2009
5 * Author: crueger
6 */
7
8#ifndef ACTION_HPP_
9#define ACTION_HPP_
10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16#include <string>
17#include <boost/shared_ptr.hpp>
18
19/** Used in .def files in paramdefaults define to set that no default value exists.
20 * We define NODEFAULT here, as it is used in .def files and needs to be present
21 * before these are included.
22 */
23#define NODEFAULT ""
24
25// forward declaration
26
27namespace MoleCuilder {
28 class ActionState;
29 class ActionSequence;
30}
31class Dialog;
32
33#include "Actions/ActionTrait.hpp"
34
35
36namespace MoleCuilder {
37
38/**
39 * Base class for all actions.
40 *
41 * Actions describe something that has to be done.
42 * Actions can be passed around, stored, performed and undone (Command-Pattern).
43 */
44class Action
45{
46friend class ActionSequence;
47friend class ActionHistory;
48public:
49
50 enum QueryOptions {Interactive, NonInteractive};
51
52 /**
53 * This type is used to store pointers to ActionStates while allowing multiple ownership
54 */
55 typedef boost::shared_ptr<ActionState> state_ptr;
56
57 /**
58 * Standard constructor of Action Base class
59 *
60 * All Actions need to have a name. The second flag indicates, whether the action should
61 * be registered with the ActionRegistry. If the Action is registered the name of the
62 * Action needs to be unique for all Actions that are registered.
63 *
64 * \note NO reference for \a _Traits as we do have to copy it, otherwise _Traits would have
65 * to be present throughout the program's run.
66 *
67 * \param Traits information class to this action
68 * \param _doRegister whether to register with ActionRegistry
69 */
70 Action(const ActionTrait &_Traits, bool _doRegister=true);
71 virtual ~Action();
72
73 /**
74 * This method is used to call an action. The basic operations for the Action
75 * are carried out and if necessary/possible the Action is added to the History
76 * to allow for undo of this action.
77 *
78 * If the call needs to undone you have to use the History, to avoid destroying
79 * invariants used by the History.
80 *
81 * Note that this call can be Interactive (i.e. a dialog will ask the user for
82 * necessary information) and NonInteractive (i.e. the information will have to
83 * be present already within the ValueStorage class or else a MissingArgumentException
84 * is thrown)
85 */
86 void call(enum QueryOptions state = Interactive);
87
88 /**
89 * This method provides a flag that indicates if an undo mechanism is implemented
90 * for this Action. If this is true, and this action was called last, you can
91 * use the History to undo this action.
92 */
93 virtual bool canUndo()=0;
94
95 /**
96 * This method provides a flag, that indicates if the Action changes the state of
97 * the application in a way that needs to be undone for the History to work.
98 *
99 * If this is false the Action will not be added to the History upon calling. However
100 * Actions called before this one will still be available for undo.
101 */
102 virtual bool shouldUndo()=0;
103
104 /**
105 * Indicates whether the Action can do it's work at the moment. If this
106 * is false calling the action will result in a no-op.
107 */
108 virtual bool isActive();
109
110 /**
111 * Returns the name of the Action.
112 */
113 const std::string getName() const;
114
115 /**
116 * returns a detailed help message.
117 */
118 const std::string help() const;
119
120 /**
121 * Traits resemble all necessary information that "surrounds" an action, such as
122 * its name (for ActionRegistry and as ref from string to instance and vice versa),
123 * which menu, which position, what parameters, their types, if it is itself a
124 * parameter and so on ...
125 *
126 * Note that is important that we do not use a reference here. We want to copy the
127 * information in the Action's constructor and have it contained herein. Hence, we
128 * also have our own copy constructor for ActionTrait. Information should be
129 * encapsulated in the Action, no more references to the outside than absolutely
130 * necessary.
131 */
132 const ActionTrait Traits;
133
134 /** Removes the static entities Action::success and Action::failure.
135 * This is only to be called on the program's exit, i.e. in cleanUp(),
136 * as these static entities are used throughout all Actions.
137 */
138 static void removeStaticStateEntities();
139
140protected:
141 /**
142 * This method is called by the History, when an undo is performed. It is
143 * provided with the corresponding state produced by the performCall or
144 * performRedo method and needs to provide a state that can be used for redo.
145 */
146 state_ptr undo(state_ptr);
147
148 /**
149 * This method is called by the Histor, when a redo is performed. It is
150 * provided with the corresponding state produced by the undo method and
151 * needs to produce a State that can then be used for another undo.
152 */
153 state_ptr redo(state_ptr);
154
155 /**
156 * This special state can be used to indicate that the Action was successfull
157 * without providing a special state. Use this if your Action does not need
158 * a speciallized state.
159 */
160 static state_ptr success;
161
162 /**
163 * This special state can be returned, to indicate that the action could not do it's
164 * work, was abborted by the user etc. If you return this state make sure to transactionize
165 * your Actions and unroll the complete transaction before this is returned.
166 */
167 static state_ptr failure;
168
169 /**
170 * This creates the dialog requesting the information needed for this action from the user
171 * via means of the user interface.
172 */
173 Dialog * createDialog();
174
175 /** Virtual function that starts the timer.
176 *
177 */
178 virtual void startTimer() const {};
179
180 /** Virtual function that ends the timer.
181 *
182 */
183 virtual void endTimer() const {};
184
185private:
186
187 /**
188 * This is called internally before the Action::performCall(). It initializes the
189 * necessary ActionParameters by retrieving the values from ValueStorage.
190 */
191 virtual void getParametersfromValueStorage()=0;
192
193 /**
194 * This is called internally before the action is processed. This adds necessary queries
195 * to a given dialog to obtain parameters for the user for processing the action accordingly.
196 * The dialog will be given to the user before Action::performCall() is initiated, values
197 * are transfered via ValueStorage.
198 */
199 virtual Dialog * fillDialog(Dialog*)=0;
200
201 /**
202 * This is called internally when the call is being done. Implement this method to do the actual
203 * work of the Action. Implement this in your Derived classes. Needs to return a state that can be
204 * used to undo the action.
205 */
206 virtual state_ptr performCall()=0;
207
208 /**
209 * This is called internally when the undo process is chosen. This Method should use the state
210 * produced by the performCall method to return the state of the application to the state
211 * it had before the Action.
212 */
213 virtual state_ptr performUndo(state_ptr)=0;
214
215 /**
216 * This is called internally when the redo process is chosen. This method shoudl use the state
217 * produced by the performUndo method to return the application to the state it should have after
218 * the action.
219 *
220 * Often this method can be implement to re-use the performCall method. However if user interaction
221 * or further parameters are needed, those should be taken from the state and not query the user
222 * again.
223 */
224 virtual state_ptr performRedo(state_ptr)=0;
225};
226
227/**
228 * This class can be used by actions to save the state.
229 *
230 * It is implementing a memento pattern. The base class is completely empty,
231 * since no general state internals can be given. The Action performing
232 * the Undo should downcast to the apropriate type.
233 */
234class ActionState{
235public:
236 ActionState(){}
237 virtual ~ActionState(){}
238};
239
240/**
241 * This class can be used by actions to contain parameters.
242 *
243 * The base class is completely empty, since no general parameters can be given. The
244 * Action performing the function should construct its own parameter class derived
245 * from it.
246 */
247class ActionParameters{
248public:
249 ActionParameters(){}
250 virtual ~ActionParameters(){}
251};
252
253}
254
255#endif /* ACTION_HPP_ */
Note: See TracBrowser for help on using the repository browser.