source: src/Actions/Action_impl_pre.hpp@ ce7fdc

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 ce7fdc was ce7fdc, checked in by Frederik Heber <heber@…>, 13 years ago

HUGE: All Action-related codes resides now in namespace MoleCuilder.

  • removed all namespace std in Actions..., replaced by MoleCuilder.
  • Property mode set to 100644
File size: 7.7 KB
Line 
1/*
2 * Action_impl.hpp
3 *
4 * Created on: Aug 25, 2010
5 * Author: heber
6 */
7
8/** These macros define the following functions, necessary but repetitive for
9 * every Action:
10 * -# Dialog* fillDialog()
11 * -# action command (e.g. AnalysisMolecularVolume() )
12 * -# void getParametersfromValuStorage()
13 * -# struct Action...Parameters
14 *
15 * For this, the user has the define the following values, each with
16 * parenthesis, for the values/parameters the action needs
17 * -# paramtypes, e.g. (int)(double)
18 * -# paramtokens, e.g. ("Z")("length")
19 * -# paramreferences, e.g. (Z)(length)
20 * and for additional values/parameters to save in the state
21 * -# statetypes, e.g. (int)(double)
22 * -# statereferences, e.g. (Z)(length)
23 * and the name and category of the action
24 * -# CATEGORY, e.g. Analysis
25 * -# ACTIONNAME, e.g. MolecularVolume
26 */
27
28// include config.h
29#ifdef HAVE_CONFIG_H
30#include <config.h>
31#endif
32
33#include <boost/preprocessor/cat.hpp>
34#include <boost/preprocessor/expand.hpp>
35#include <boost/preprocessor/comparison/equal.hpp>
36#include <boost/preprocessor/comparison/not_equal.hpp>
37#include <boost/preprocessor/control/if.hpp>
38#include <boost/preprocessor/debug/assert.hpp>
39#include <boost/preprocessor/iteration/local.hpp>
40#include <boost/preprocessor/punctuation/comma_if.hpp>
41#include <boost/preprocessor/repetition/repeat.hpp>
42#include <boost/preprocessor/seq/elem.hpp>
43#include <boost/preprocessor/seq/push_back.hpp>
44#include <boost/preprocessor/seq/seq.hpp>
45#include <boost/preprocessor/seq/size.hpp>
46#include <boost/preprocessor/seq/transform.hpp>
47
48// some derived names: if CATEGORY is not given, we don't prefix with it
49#ifdef CATEGORY
50#define ACTION BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Action))
51#define COMMAND BOOST_PP_CAT(CATEGORY, ACTIONNAME)
52#define STATE BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, State))
53#define PARAMS BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Parameters))
54#else
55#define ACTION BOOST_PP_CAT(ACTIONNAME, Action)
56#define COMMAND ACTIONNAME
57#define STATE BOOST_PP_CAT(ACTIONNAME, State)
58#define PARAMS BOOST_PP_CAT(ACTIONNAME, Parameters)
59#endif
60#define INSTANCE BOOST_PP_CAT(this_, BOOST_PP_CAT(ACTIONNAME, _instance))
61
62// check if no lists given
63#ifndef paramtypes
64#define MAXPARAMTYPES 0
65#else
66#define MAXPARAMTYPES BOOST_PP_SEQ_SIZE(paramtypes)
67#endif
68#ifndef statetypes
69#define MAXSTATETYPES 0
70#else
71#define MAXSTATETYPES BOOST_PP_SEQ_SIZE(statetypes)
72#endif
73
74// check user has given name and category
75#ifndef ACTIONNAME
76ERROR: No "ACTIONNAME" defined in: __FILE__
77#endif
78
79// calculate numbers and check whether all have same size
80#ifdef paramtokens
81BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramtokens)),\
82 ERROR: There are not the same number of "paramtokens" and "paramtypes" in: __FILE__ \
83)
84#endif
85#ifdef paramreferences
86BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramreferences)),\
87 ERROR: There are not the same number of "paramtokens" and "paramreferences" in: __FILE__ \
88)
89#endif
90
91#ifdef statetypes
92BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXSTATETYPES, BOOST_PP_SEQ_SIZE(statereferences)),\
93 ERROR: There are not the same number of "statetypes" and "statereferences" in: __FILE__ \
94)
95#endif
96
97// print a list of type ref followed by a separator, i.e. "int i;"
98#define initialiser_print(z,n,initialiserlist) \
99 BOOST_PP_SEQ_ELEM(n, initialiserlist) \
100 (BOOST_PP_CAT(_, BOOST_PP_SEQ_ELEM(n, initialiserlist))),
101
102// print a list of ref(_ref) followed by a separator, i.e. "id(_id),"
103#define type_print(z,n,TYPELIST, VARLIST, separator) \
104 BOOST_PP_SEQ_ELEM(n, TYPELIST) \
105 BOOST_PP_SEQ_ELEM(n, VARLIST)\
106 separator
107
108// print a list of type ref followed, i.e. "int i, double position"
109#define type_list(z,n,TYPELIST,VARLIST) \
110 BOOST_PP_COMMA_IF(n)\
111 BOOST_PP_SEQ_ELEM(n, TYPELIST) \
112 BOOST_PP_SEQ_ELEM(n, VARLIST)
113
114// prints dialog->query calls for paramtypes with tokens
115#define dialog_print(z,n,unused) \
116 dialog->query<\
117 BOOST_PP_SEQ_ELEM(n, paramtypes)\
118 >(\
119 BOOST_PP_SEQ_ELEM(n, paramtokens)\
120 , Traits.getDescription()\
121 );
122
123// prints set/queryCurrentValue (command) for paramreferences and paramtokens
124#define value_print(z,n,command, prefix) \
125 ValueStorage::getInstance(). command (\
126 BOOST_PP_SEQ_ELEM(n, paramtokens)\
127 , \
128 prefix\
129 BOOST_PP_SEQ_ELEM(n, paramreferences)\
130 );
131
132#include "Actions/ActionRegistry.hpp"
133#include "UIElements/Dialog.hpp"
134
135#ifdef paramtokens
136#define statenecessary 1
137#endif
138#ifndef statetokens
139#define statenecessary 1
140#endif
141
142namespace MoleCuilder {
143
144// =========== memento to remember the state when undoing ===========
145#ifdef statenecessary
146class STATE : public ActionState {
147public:
148 STATE(
149#if defined statetypes && defined statereferences // if we have parameters, we have to add "_" before each reference and add the params as the last one
150#define OP(s,data,elem) BOOST_PP_CAT(data, elem) // OP to add "_"
151#define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, BOOST_PP_SEQ_PUSH_BACK(statetypes, const ACTION::PARAMS &), BOOST_PP_SEQ_TRANSFORM(OP, _, BOOST_PP_SEQ_PUSH_BACK(statereferences, params)))
152#else /// if not, params is only list
153#define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, (const ACTION::PARAMS &), (_params))
154#endif
155#define BOOST_PP_LOCAL_LIMITS (0, MAXSTATETYPES)
156#include BOOST_PP_LOCAL_ITERATE()
157) :
158#if defined statetypes && defined statereferences // do we have parameters at all?
159BOOST_PP_REPEAT(MAXSTATETYPES, initialiser_print, statereferences)
160#endif
161params(_params)
162 {}
163
164#if defined statetypes && defined statereferences // do we have parameters at all?
165#define BOOST_PP_LOCAL_MACRO(n) type_print(~, n, statetypes, statereferences, ;)
166#define BOOST_PP_LOCAL_LIMITS (0, MAXSTATETYPES-1)
167#include BOOST_PP_LOCAL_ITERATE()
168#endif
169 ACTION::PARAMS params;
170};
171#endif /* statenecessary */
172
173// (const) prototype to be placed into the ActionRegistry (must be deleted by registry itself)
174const ACTION *INSTANCE = new ACTION();
175
176// =========== constructor ===========
177ACTION::ACTION () :
178 Action(ActionTrait<ACTION>())
179{}
180
181// =========== destructor ===========
182ACTION::~ACTION ()
183{
184 //std::cout << "Action ACTION is being destroyed." << std::endl;
185}
186
187// =========== fill a dialog ===========
188Dialog* ACTION::fillDialog(Dialog *dialog) {
189 ASSERT(dialog,"No Dialog given when filling actionname's dialog");
190#if BOOST_PP_EQUAL(MAXPARAMTYPES,0)
191 dialog->queryEmpty(TOKEN, Traits.getDescription());
192#else
193#define BOOST_PP_LOCAL_MACRO(n) dialog_print(~, n, ~)
194#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
195#include BOOST_PP_LOCAL_ITERATE()
196#endif
197 return dialog;
198};
199
200// =========== command for calling action directly ===========
201#if defined paramtypes && defined paramreferences
202void COMMAND(
203#define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, paramtypes, paramreferences)
204#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
205#include BOOST_PP_LOCAL_ITERATE()
206)
207#else
208void COMMAND()
209#endif
210{
211 ACTION::PARAMS params;
212 Action *ToCall = ActionRegistry::getInstance().getActionByName( TOKEN ); //->clone(params);
213#if BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
214#define BOOST_PP_LOCAL_MACRO(n) value_print(~, n, setCurrentValue, )
215#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
216#include BOOST_PP_LOCAL_ITERATE()
217#endif
218 ToCall->call(Action::NonInteractive);
219};
220
221// =========== obtain parameters from Storage, used by performCall() ===========
222void ACTION::getParametersfromValueStorage() {
223#if BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
224#define BOOST_PP_LOCAL_MACRO(n) value_print(~, n, queryCurrentValue, params.)
225#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
226#include BOOST_PP_LOCAL_ITERATE()
227#endif
228};
229
230}
231
232// free up defines
233#undef paramtypes
234#undef paramtokens
235#undef paramreferences
236#undef MAXPARAMTYPES
237#undef statetypes
238#undef statereferences
239#undef MAXSTATETYPES
240
241#undef ACTION
242#undef COMMAND
243#undef PARAMS
244#undef STATE
245#undef INSTANCE
246
247#undef ACTIONNAME
248#undef CATEGORY
249#undef TOKEN
Note: See TracBrowser for help on using the repository browser.