source: src/Actions/Action_impl_pre.hpp@ c38826

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

Huge refactoring: Introduction of Traits to Actions.

This change is really big but the introduction of the Trait concept (at least
in its current light form) is so fundamental that lots of pieces had to be
changed in order to get everything working.

The main point why it was necessary to add these traits in the first place was
to comfortably allow for adding extension of Actions information-wise, i.e.
with stuff that is only important for the QtUI, such as icons, or tooltips, ...
This extra information should not be stored with Action itself, as it has
nothing to do with the workings of the Action. And neither should it get
stored with some blown-out-of-proportions MapOfActions class ...

The gist of the change is as follows:

  • OptionTrait contains the token, description, shortform and type of an option, such as ("position", "position in space, none, typeid(Vector)).
  • ActionTrait is the derived form for actions where additionally MenuPosition and MenuName are stored (and probably more to come for the GUI), also we have a set of OptionTrait instances, one for each option of the Action.
  • Action then contains this ActionTrait, specialized for each Action.
  • the preprocessor macros have been enhanced to gather all this information from the .def files.
  • MapOfActions is gone. Completely. Most of its use was to store this extra information and the ValueStorage part now is just in class ValueStorage.
  • ValueStorage is no more an interface to MapOfActions but as the name says a (type-safe) ValueStorage.

Listing the (remaining) changes in alphabetical order of the class:

  • Action
    • member value ::name dropped, ::getName() uses ActionTraits::getName()
    • new define NODEFAULT which is used in paramdefaults in .def files
    • all derived actions classes such as Process, Calculations, MakroAction,... have been adapated to use the ActionTrait concept as well.
  • ActionHistory
    • extraced RedoAction and UndoAction, shifted implementation into their own object files and they use .def files as well (i.e. streamlined with method used for other actions)
  • MenuDescription
    • contain information on Menus such as name, ...
    • new unit test checks for consistency
  • molecule
    • const member functions: Copy(), Output() and OutputBonds()
  • OptionRegistry
    • new registry class for options only
    • we want the same type throughout the code for each token, e.g. "position"
    • the registry containts checks for consistency
  • OptionTrait
    • default values are specified in paramdefaults, none are given by NODEFAULT
    • introduced default for translate-atoms, point-correlation, pair-correlation
  • Registry pattern
    • new unit test, but only sceleton code so far
  • ...Query, also ...Pipe
    • atoms, molecule and elements are now all const
    • also ValueStorage's signatures all have const therein
  • ValueStorage
    • set/queryCurrentValue from MapOfActions
    • at times VectorValue has been in .def files where Vector was in the signature. This is cleared. Such stuff is only present for e.g. BoxVector being queried as a Vector. But this is a feature and intended.
  • World
    • most of the (un)selection functions now work on const atoms and molecules
    • in one case we need a const_cast to remove this, but this is intentional, as the vector of selected atoms stores non-const pointers and this is ok.

There is only one test which had to be changed slightly because a specific
option token as "position" must now have the same type everywhere, e.g. always
Vector.

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